Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@embedpdf/models

Package Overview
Dependencies
Maintainers
1
Versions
84
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@embedpdf/models - npm Package Compare versions

Comparing version
1.0.6
to
1.0.7
+209
-3
dist/index.cjs

@@ -66,4 +66,8 @@ "use strict";

compareSearchTarget: () => compareSearchTarget,
dateToPdfDate: () => dateToPdfDate,
ignore: () => ignore,
pdfAlphaColorToWebAlphaColor: () => pdfAlphaColorToWebAlphaColor,
pdfDateToDate: () => pdfDateToDate,
quadToRect: () => quadToRect,
rectToQuad: () => rectToQuad,
restoreOffset: () => restoreOffset,

@@ -84,3 +88,4 @@ restorePosition: () => restorePosition,

transformSize: () => transformSize,
unionFlags: () => unionFlags
unionFlags: () => unionFlags,
webAlphaColorToPdfAlphaColor: () => webAlphaColorToPdfAlphaColor
});

@@ -149,2 +154,10 @@ module.exports = __toCommonJS(index_exports);

}
function rectToQuad(r) {
return {
p1: { x: r.origin.x, y: r.origin.y },
p2: { x: r.origin.x + r.size.width, y: r.origin.y },
p3: { x: r.origin.x + r.size.width, y: r.origin.y + r.size.height },
p4: { x: r.origin.x, y: r.origin.y + r.size.height }
};
}
function rotatePosition(containerSize, position, rotation) {

@@ -473,3 +486,3 @@ let x = position.x;

};
var Task = class {
var Task = class _Task {
constructor() {

@@ -620,2 +633,144 @@ this.state = {

}
/**
* Static method to wait for all tasks to resolve
* Returns a new task that resolves with an array of all results
* Rejects immediately if any task fails
*
* @param tasks - array of tasks to wait for
* @returns new task that resolves when all input tasks resolve
* @public
*/
static all(tasks) {
const combinedTask = new _Task();
if (tasks.length === 0) {
combinedTask.resolve([]);
return combinedTask;
}
const results = new Array(tasks.length);
let resolvedCount = 0;
let isSettled = false;
tasks.forEach((task, index) => {
task.wait(
(result) => {
if (isSettled) return;
results[index] = result;
resolvedCount++;
if (resolvedCount === tasks.length) {
isSettled = true;
combinedTask.resolve(results);
}
},
(error) => {
if (isSettled) return;
isSettled = true;
if (error.type === "abort") {
combinedTask.abort(error.reason);
} else {
combinedTask.reject(error.reason);
}
}
);
});
return combinedTask;
}
/**
* Static method to wait for all tasks to settle (resolve, reject, or abort)
* Always resolves with an array of settlement results
*
* @param tasks - array of tasks to wait for
* @returns new task that resolves when all input tasks settle
* @public
*/
static allSettled(tasks) {
const combinedTask = new _Task();
if (tasks.length === 0) {
combinedTask.resolve([]);
return combinedTask;
}
const results = new Array(tasks.length);
let settledCount = 0;
tasks.forEach((task, index) => {
task.wait(
(result) => {
results[index] = { status: "resolved", value: result };
settledCount++;
if (settledCount === tasks.length) {
combinedTask.resolve(results);
}
},
(error) => {
results[index] = {
status: error.type === "abort" ? "aborted" : "rejected",
reason: error.reason
};
settledCount++;
if (settledCount === tasks.length) {
combinedTask.resolve(results);
}
}
);
});
return combinedTask;
}
/**
* Static method that resolves/rejects with the first task that settles
*
* @param tasks - array of tasks to race
* @returns new task that settles with the first input task that settles
* @public
*/
static race(tasks) {
const combinedTask = new _Task();
if (tasks.length === 0) {
combinedTask.reject("No tasks provided");
return combinedTask;
}
let isSettled = false;
tasks.forEach((task) => {
task.wait(
(result) => {
if (isSettled) return;
isSettled = true;
combinedTask.resolve(result);
},
(error) => {
if (isSettled) return;
isSettled = true;
if (error.type === "abort") {
combinedTask.abort(error.reason);
} else {
combinedTask.reject(error.reason);
}
}
);
});
return combinedTask;
}
/**
* Utility to track progress of multiple tasks
*
* @param tasks - array of tasks to track
* @param onProgress - callback called when any task completes
* @returns new task that resolves when all input tasks resolve
* @public
*/
static withProgress(tasks, onProgress) {
const combinedTask = _Task.all(tasks);
if (onProgress) {
let completedCount = 0;
tasks.forEach((task) => {
task.wait(
() => {
completedCount++;
onProgress(completedCount, tasks.length);
},
() => {
completedCount++;
onProgress(completedCount, tasks.length);
}
);
});
}
return combinedTask;
}
};

@@ -921,2 +1076,48 @@

// src/color.ts
function pdfAlphaColorToWebAlphaColor(c) {
const clamp = (n) => Math.max(0, Math.min(255, n));
const toHex = (n) => clamp(n).toString(16).padStart(2, "0");
const color = `#${toHex(c.red)}${toHex(c.green)}${toHex(c.blue)}`;
const opacity = clamp(c.alpha) / 255;
return { color, opacity };
}
function webAlphaColorToPdfAlphaColor({ color, opacity }) {
if (/^#?[0-9a-f]{3}$/i.test(color)) {
color = color.replace(/^#?([0-9a-f])([0-9a-f])([0-9a-f])$/i, "#$1$1$2$2$3$3").toLowerCase();
}
const [, r, g, b] = /^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(color) ?? (() => {
throw new Error(`Invalid hex colour: \u201C${color}\u201D`);
})();
const clamp = (n, hi = 255) => Math.max(0, Math.min(hi, n));
return {
red: parseInt(r, 16),
green: parseInt(g, 16),
blue: parseInt(b, 16),
alpha: clamp(Math.round(opacity * 255))
};
}
// src/date.ts
function pdfDateToDate(pdf) {
if (!pdf?.startsWith("D:") || pdf.length < 16) return;
const y = +pdf.slice(2, 6);
const mo = +pdf.slice(6, 8) - 1;
const d = +pdf.slice(8, 10);
const H = +pdf.slice(10, 12);
const M = +pdf.slice(12, 14);
const S = +pdf.slice(14, 16);
return new Date(Date.UTC(y, mo, d, H, M, S));
}
function dateToPdfDate(date = /* @__PURE__ */ new Date()) {
const z = (n, len = 2) => n.toString().padStart(len, "0");
const YYYY = date.getUTCFullYear();
const MM = z(date.getUTCMonth() + 1);
const DD = z(date.getUTCDate());
const HH = z(date.getUTCHours());
const mm = z(date.getUTCMinutes());
const SS = z(date.getUTCSeconds());
return `D:${YYYY}${MM}${DD}${HH}${mm}${SS}`;
}
// src/index.ts

@@ -970,4 +1171,8 @@ function ignore() {

compareSearchTarget,
dateToPdfDate,
ignore,
pdfAlphaColorToWebAlphaColor,
pdfDateToDate,
quadToRect,
rectToQuad,
restoreOffset,

@@ -988,4 +1193,5 @@ restorePosition,

transformSize,
unionFlags
unionFlags,
webAlphaColorToPdfAlphaColor
});
//# sourceMappingURL=index.cjs.map

@@ -124,2 +124,10 @@ /**

/**
* Convert rectangle to quadrilateral
* @param r - rectangle
* @returns quadrilateral
*
* @public
*/
declare function rectToQuad(r: Rect): Quad;
/**
* Rotate the container and calculate the new position for a point

@@ -416,3 +424,24 @@ * in specified position

interface WebAlphaColor {
color: string;
opacity: number;
}
/**
* Convert a {@link PdfAlphaColor} to a CSS-style colour definition.
*
* @param c - the colour coming from PDFium (0-255 per channel)
* @returns
* hex – #RRGGBB (no alpha channel)
* opacity – 0-1 float suitable for CSS `opacity`/`rgba()`
*/
declare function pdfAlphaColorToWebAlphaColor(c: PdfAlphaColor): WebAlphaColor;
/**
* Convert a CSS hex colour + opacity back into {@link PdfAlphaColor}
*
* @param hex - #RGB, #RRGGBB, or #rrggbb
* @param opacity - 0-1 float (values outside clamp automatically)
*/
declare function webAlphaColorToPdfAlphaColor({ color, opacity }: WebAlphaColor): PdfAlphaColor;
/**
* Stage of task

@@ -479,2 +508,17 @@ *

};
/**
* Result type for allSettled
*
* @public
*/
type TaskSettledResult<R, D> = {
status: 'resolved';
value: R;
} | {
status: 'rejected';
reason: D;
} | {
status: 'aborted';
reason: D;
};
declare class TaskAbortedError<D> extends Error {

@@ -538,2 +582,44 @@ constructor(reason: D);

fail(error: TaskError<D>): void;
/**
* Static method to wait for all tasks to resolve
* Returns a new task that resolves with an array of all results
* Rejects immediately if any task fails
*
* @param tasks - array of tasks to wait for
* @returns new task that resolves when all input tasks resolve
* @public
*/
static all<R extends readonly Task<any, any>[]>(tasks: R): Task<{
[K in keyof R]: R[K] extends Task<infer U, any> ? U : never;
}, any>;
/**
* Static method to wait for all tasks to settle (resolve, reject, or abort)
* Always resolves with an array of settlement results
*
* @param tasks - array of tasks to wait for
* @returns new task that resolves when all input tasks settle
* @public
*/
static allSettled<R extends readonly Task<any, any>[]>(tasks: R): Task<{
[K in keyof R]: R[K] extends Task<infer U, infer E> ? TaskSettledResult<U, E> : never;
}, never>;
/**
* Static method that resolves/rejects with the first task that settles
*
* @param tasks - array of tasks to race
* @returns new task that settles with the first input task that settles
* @public
*/
static race<R extends readonly Task<any, any>[]>(tasks: R): Task<R[number] extends Task<infer U, any> ? U : never, R[number] extends Task<any, infer E> ? E : never>;
/**
* Utility to track progress of multiple tasks
*
* @param tasks - array of tasks to track
* @param onProgress - callback called when any task completes
* @returns new task that resolves when all input tasks resolve
* @public
*/
static withProgress<R extends readonly Task<any, any>[]>(tasks: R, onProgress?: (completed: number, total: number) => void): Task<{
[K in keyof R]: R[K] extends Task<infer U, any> ? U : never;
}, any>;
}

@@ -1054,3 +1140,3 @@ /**

*/
modified?: string;
modified?: Date;
/**

@@ -1061,6 +1147,2 @@ * Sub type of annotation

/**
* Status of pdf annotation
*/
status: PdfAnnotationObjectStatus;
/**
* The index of page that this annotation belong to

@@ -1077,14 +1159,2 @@ */

rect: Rect;
/**
* Related popup annotation
*/
popup?: PdfPopupAnnoObject | undefined;
/**
* Appearences of annotation
*/
appearances: {
normal: string;
rollover: string;
down: string;
};
}

@@ -1107,2 +1177,6 @@ /**

open: boolean;
/**
* In reply to id
*/
inReplyToId?: number;
}

@@ -1139,6 +1213,10 @@ /**

/**
* Color of the text
* color of text annotation
*/
color: PdfAlphaColor;
color?: string;
/**
* opacity of text annotation
*/
opacity?: number;
/**
* In reply to id

@@ -1392,6 +1470,14 @@ */

/**
* color of highlight area
* Text contents of the highlight annotation
*/
color?: PdfAlphaColor;
contents?: string;
/**
* color of highlight annotation
*/
color?: string;
/**
* opacity of highlight annotation
*/
opacity?: number;
/**
* quads of highlight area

@@ -1548,2 +1634,18 @@ */

type: PdfAnnotationSubtype.SQUIGGLY;
/**
* Text contents of the highlight annotation
*/
contents?: string;
/**
* color of strike out annotation
*/
color?: string;
/**
* opacity of strike out annotation
*/
opacity?: number;
/**
* quads of highlight area
*/
segmentRects: Rect[];
}

@@ -1558,2 +1660,18 @@ /**

type: PdfAnnotationSubtype.UNDERLINE;
/**
* Text contents of the highlight annotation
*/
contents?: string;
/**
* color of strike out annotation
*/
color?: string;
/**
* opacity of strike out annotation
*/
opacity?: number;
/**
* quads of highlight area
*/
segmentRects: Rect[];
}

@@ -1568,2 +1686,18 @@ /**

type: PdfAnnotationSubtype.STRIKEOUT;
/**
* Text contents of the strike out annotation
*/
contents?: string;
/**
* color of strike out annotation
*/
color?: string;
/**
* opacity of strike out annotation
*/
opacity?: number;
/**
* quads of highlight area
*/
segmentRects: Rect[];
}

@@ -2125,2 +2259,12 @@ /**

/**
* Change the visible colour (and opacity) of an existing annotation.
* @param doc - pdf document
* @param page - pdf page
* @param annotation - the annotation to recolour
* @param colour - RGBA color values (0-255 per channel)
* @param which - 0 = stroke/fill colour (PDFium's "colourType" param)
* @returns task that indicates whether the operation succeeded
*/
updateAnnotationColor: (doc: PdfDocumentObject, page: PdfPageObject, annotation: PdfAnnotationObjectBase, color: WebAlphaColor, which?: number) => PdfTask<boolean>;
/**
* Create a annotation on specified page

@@ -2132,4 +2276,12 @@ * @param doc - pdf document

*/
createPageAnnotation: (doc: PdfDocumentObject, page: PdfPageObject, annotation: PdfAnnotationObject) => PdfTask<boolean>;
createPageAnnotation: (doc: PdfDocumentObject, page: PdfPageObject, annotation: PdfAnnotationObject) => PdfTask<number>;
/**
* Update a annotation on specified page
* @param doc - pdf document
* @param page - pdf page
* @param annotation - new annotations
* @returns task that indicates whether the operation succeeded
*/
updatePageAnnotation: (doc: PdfDocumentObject, page: PdfPageObject, annotation: PdfAnnotationObject) => PdfTask<boolean>;
/**
* Transform the annotation

@@ -2297,2 +2449,19 @@ * @param doc - pdf document

/**
* Parse a PDF date string **D:YYYYMMDDHHmmSSOHH'mm'** to ISO-8601.
*
* Returns `undefined` if the input is malformed.
*
* @public
*/
declare function pdfDateToDate(pdf?: string): Date | undefined;
/**
* Convert a date to a PDF date string
* @param date - date to convert
* @returns PDF date string
*
* @public
*/
declare function dateToPdfDate(date?: Date): string;
/**
* Library contains the common definitions of data types and logic

@@ -2314,2 +2483,2 @@ *

export { AllLogger, AppearanceMode, type Box, ConsoleLogger, type FormFieldValue, type ImageConversionTypes, LevelLogger, LogLevel, type Logger, MatchFlag, NoopLogger, PDF_FORM_FIELD_FLAG, PDF_FORM_FIELD_TYPE, type PageTextSlice, type PdfActionObject, PdfActionType, type PdfAlphaColor, type PdfAnnotationObject, type PdfAnnotationObjectBase, PdfAnnotationObjectStatus, PdfAnnotationState, PdfAnnotationStateModel, PdfAnnotationSubtype, PdfAnnotationSubtypeName, type PdfAnnotationTransformation, type PdfAttachmentObject, PdfBomOrZwnbsp, type PdfBookmarkObject, type PdfBookmarksObject, type PdfCaretAnnoObject, type PdfCircleAnnoObject, type PdfDestinationObject, type PdfDocumentObject, type PdfEngine, type PdfEngineError, PdfEngineFeature, type PdfEngineMethodArgs, type PdfEngineMethodName, type PdfEngineMethodReturnType, PdfEngineOperation, PdfErrorCode, type PdfErrorReason, type PdfFile, type PdfFileAttachmentAnnoObject, type PdfFileContent, type PdfFileLoader, type PdfFileUrl, type PdfFileWithoutContent, type PdfFormObject, type PdfFreeTextAnnoObject, type PdfGlyphObject, type PdfGlyphSlim, type PdfHighlightAnnoObject, type PdfImage, type PdfImageObject, type PdfInkAnnoObject, type PdfInkListObject, type PdfLineAnnoObject, type PdfLinkAnnoObject, type PdfLinkTarget, type PdfMetadataObject, PdfNonCharacterFFFE, PdfNonCharacterFFFF, PdfPageFlattenFlag, PdfPageFlattenResult, type PdfPageGeometry, type PdfPageObject, PdfPageObjectType, type PdfPageObjectWithRotatedSize, type PdfPathObject, PdfPermission, type PdfPolygonAnnoObject, type PdfPolylineAnnoObject, type PdfPopupAnnoObject, type PdfRenderOptions, type PdfRun, type PdfSegmentObject, PdfSegmentObjectType, type PdfSignatureObject, PdfSoftHyphenMarker, type PdfSquareAnnoObject, type PdfSquigglyAnnoObject, type PdfStampAnnoObject, type PdfStampAnnoObjectContents, type PdfStrikeOutAnnoObject, type PdfSupportedAnnoObject, type PdfTask, PdfTaskHelper, type PdfTextAnnoObject, type PdfTextRectObject, type PdfTransformMatrix, type PdfUnderlineAnnoObject, type PdfUnsupportedAnnoObject, PdfUnwantedTextMarkers, PdfUnwantedTextRegex, type PdfUrlOptions, type PdfWidgetAnnoField, type PdfWidgetAnnoObject, type PdfWidgetAnnoOption, PdfWordJoiner, PdfZeroWidthSpace, PdfZoomMode, PerfLogger, type Position, type Quad, type Rect, type RejectedCallback, type ResolvedCallback, Rotation, type SearchAllPagesResult, type SearchResult, type SearchTarget, type Size, Task, TaskAbortedError, type TaskError, TaskRejectedError, type TaskReturn, TaskStage, type TaskState, type TextContext, boundingRect, calculateAngle, calculateDegree, compareSearchTarget, ignore, quadToRect, restoreOffset, restorePosition, restoreRect, rotatePosition, rotateRect, scalePosition, scaleRect, stripPdfUnwantedMarkers, swap, toIntPos, toIntRect, toIntSize, transformPosition, transformRect, transformSize, unionFlags };
export { AllLogger, AppearanceMode, type Box, ConsoleLogger, type FormFieldValue, type ImageConversionTypes, LevelLogger, LogLevel, type Logger, MatchFlag, NoopLogger, PDF_FORM_FIELD_FLAG, PDF_FORM_FIELD_TYPE, type PageTextSlice, type PdfActionObject, PdfActionType, type PdfAlphaColor, type PdfAnnotationObject, type PdfAnnotationObjectBase, PdfAnnotationObjectStatus, PdfAnnotationState, PdfAnnotationStateModel, PdfAnnotationSubtype, PdfAnnotationSubtypeName, type PdfAnnotationTransformation, type PdfAttachmentObject, PdfBomOrZwnbsp, type PdfBookmarkObject, type PdfBookmarksObject, type PdfCaretAnnoObject, type PdfCircleAnnoObject, type PdfDestinationObject, type PdfDocumentObject, type PdfEngine, type PdfEngineError, PdfEngineFeature, type PdfEngineMethodArgs, type PdfEngineMethodName, type PdfEngineMethodReturnType, PdfEngineOperation, PdfErrorCode, type PdfErrorReason, type PdfFile, type PdfFileAttachmentAnnoObject, type PdfFileContent, type PdfFileLoader, type PdfFileUrl, type PdfFileWithoutContent, type PdfFormObject, type PdfFreeTextAnnoObject, type PdfGlyphObject, type PdfGlyphSlim, type PdfHighlightAnnoObject, type PdfImage, type PdfImageObject, type PdfInkAnnoObject, type PdfInkListObject, type PdfLineAnnoObject, type PdfLinkAnnoObject, type PdfLinkTarget, type PdfMetadataObject, PdfNonCharacterFFFE, PdfNonCharacterFFFF, PdfPageFlattenFlag, PdfPageFlattenResult, type PdfPageGeometry, type PdfPageObject, PdfPageObjectType, type PdfPageObjectWithRotatedSize, type PdfPathObject, PdfPermission, type PdfPolygonAnnoObject, type PdfPolylineAnnoObject, type PdfPopupAnnoObject, type PdfRenderOptions, type PdfRun, type PdfSegmentObject, PdfSegmentObjectType, type PdfSignatureObject, PdfSoftHyphenMarker, type PdfSquareAnnoObject, type PdfSquigglyAnnoObject, type PdfStampAnnoObject, type PdfStampAnnoObjectContents, type PdfStrikeOutAnnoObject, type PdfSupportedAnnoObject, type PdfTask, PdfTaskHelper, type PdfTextAnnoObject, type PdfTextRectObject, type PdfTransformMatrix, type PdfUnderlineAnnoObject, type PdfUnsupportedAnnoObject, PdfUnwantedTextMarkers, PdfUnwantedTextRegex, type PdfUrlOptions, type PdfWidgetAnnoField, type PdfWidgetAnnoObject, type PdfWidgetAnnoOption, PdfWordJoiner, PdfZeroWidthSpace, PdfZoomMode, PerfLogger, type Position, type Quad, type Rect, type RejectedCallback, type ResolvedCallback, Rotation, type SearchAllPagesResult, type SearchResult, type SearchTarget, type Size, Task, TaskAbortedError, type TaskError, TaskRejectedError, type TaskReturn, type TaskSettledResult, TaskStage, type TaskState, type TextContext, type WebAlphaColor, boundingRect, calculateAngle, calculateDegree, compareSearchTarget, dateToPdfDate, ignore, pdfAlphaColorToWebAlphaColor, pdfDateToDate, quadToRect, rectToQuad, restoreOffset, restorePosition, restoreRect, rotatePosition, rotateRect, scalePosition, scaleRect, stripPdfUnwantedMarkers, swap, toIntPos, toIntRect, toIntSize, transformPosition, transformRect, transformSize, unionFlags, webAlphaColorToPdfAlphaColor };

@@ -124,2 +124,10 @@ /**

/**
* Convert rectangle to quadrilateral
* @param r - rectangle
* @returns quadrilateral
*
* @public
*/
declare function rectToQuad(r: Rect): Quad;
/**
* Rotate the container and calculate the new position for a point

@@ -416,3 +424,24 @@ * in specified position

interface WebAlphaColor {
color: string;
opacity: number;
}
/**
* Convert a {@link PdfAlphaColor} to a CSS-style colour definition.
*
* @param c - the colour coming from PDFium (0-255 per channel)
* @returns
* hex – #RRGGBB (no alpha channel)
* opacity – 0-1 float suitable for CSS `opacity`/`rgba()`
*/
declare function pdfAlphaColorToWebAlphaColor(c: PdfAlphaColor): WebAlphaColor;
/**
* Convert a CSS hex colour + opacity back into {@link PdfAlphaColor}
*
* @param hex - #RGB, #RRGGBB, or #rrggbb
* @param opacity - 0-1 float (values outside clamp automatically)
*/
declare function webAlphaColorToPdfAlphaColor({ color, opacity }: WebAlphaColor): PdfAlphaColor;
/**
* Stage of task

@@ -479,2 +508,17 @@ *

};
/**
* Result type for allSettled
*
* @public
*/
type TaskSettledResult<R, D> = {
status: 'resolved';
value: R;
} | {
status: 'rejected';
reason: D;
} | {
status: 'aborted';
reason: D;
};
declare class TaskAbortedError<D> extends Error {

@@ -538,2 +582,44 @@ constructor(reason: D);

fail(error: TaskError<D>): void;
/**
* Static method to wait for all tasks to resolve
* Returns a new task that resolves with an array of all results
* Rejects immediately if any task fails
*
* @param tasks - array of tasks to wait for
* @returns new task that resolves when all input tasks resolve
* @public
*/
static all<R extends readonly Task<any, any>[]>(tasks: R): Task<{
[K in keyof R]: R[K] extends Task<infer U, any> ? U : never;
}, any>;
/**
* Static method to wait for all tasks to settle (resolve, reject, or abort)
* Always resolves with an array of settlement results
*
* @param tasks - array of tasks to wait for
* @returns new task that resolves when all input tasks settle
* @public
*/
static allSettled<R extends readonly Task<any, any>[]>(tasks: R): Task<{
[K in keyof R]: R[K] extends Task<infer U, infer E> ? TaskSettledResult<U, E> : never;
}, never>;
/**
* Static method that resolves/rejects with the first task that settles
*
* @param tasks - array of tasks to race
* @returns new task that settles with the first input task that settles
* @public
*/
static race<R extends readonly Task<any, any>[]>(tasks: R): Task<R[number] extends Task<infer U, any> ? U : never, R[number] extends Task<any, infer E> ? E : never>;
/**
* Utility to track progress of multiple tasks
*
* @param tasks - array of tasks to track
* @param onProgress - callback called when any task completes
* @returns new task that resolves when all input tasks resolve
* @public
*/
static withProgress<R extends readonly Task<any, any>[]>(tasks: R, onProgress?: (completed: number, total: number) => void): Task<{
[K in keyof R]: R[K] extends Task<infer U, any> ? U : never;
}, any>;
}

@@ -1054,3 +1140,3 @@ /**

*/
modified?: string;
modified?: Date;
/**

@@ -1061,6 +1147,2 @@ * Sub type of annotation

/**
* Status of pdf annotation
*/
status: PdfAnnotationObjectStatus;
/**
* The index of page that this annotation belong to

@@ -1077,14 +1159,2 @@ */

rect: Rect;
/**
* Related popup annotation
*/
popup?: PdfPopupAnnoObject | undefined;
/**
* Appearences of annotation
*/
appearances: {
normal: string;
rollover: string;
down: string;
};
}

@@ -1107,2 +1177,6 @@ /**

open: boolean;
/**
* In reply to id
*/
inReplyToId?: number;
}

@@ -1139,6 +1213,10 @@ /**

/**
* Color of the text
* color of text annotation
*/
color: PdfAlphaColor;
color?: string;
/**
* opacity of text annotation
*/
opacity?: number;
/**
* In reply to id

@@ -1392,6 +1470,14 @@ */

/**
* color of highlight area
* Text contents of the highlight annotation
*/
color?: PdfAlphaColor;
contents?: string;
/**
* color of highlight annotation
*/
color?: string;
/**
* opacity of highlight annotation
*/
opacity?: number;
/**
* quads of highlight area

@@ -1548,2 +1634,18 @@ */

type: PdfAnnotationSubtype.SQUIGGLY;
/**
* Text contents of the highlight annotation
*/
contents?: string;
/**
* color of strike out annotation
*/
color?: string;
/**
* opacity of strike out annotation
*/
opacity?: number;
/**
* quads of highlight area
*/
segmentRects: Rect[];
}

@@ -1558,2 +1660,18 @@ /**

type: PdfAnnotationSubtype.UNDERLINE;
/**
* Text contents of the highlight annotation
*/
contents?: string;
/**
* color of strike out annotation
*/
color?: string;
/**
* opacity of strike out annotation
*/
opacity?: number;
/**
* quads of highlight area
*/
segmentRects: Rect[];
}

@@ -1568,2 +1686,18 @@ /**

type: PdfAnnotationSubtype.STRIKEOUT;
/**
* Text contents of the strike out annotation
*/
contents?: string;
/**
* color of strike out annotation
*/
color?: string;
/**
* opacity of strike out annotation
*/
opacity?: number;
/**
* quads of highlight area
*/
segmentRects: Rect[];
}

@@ -2125,2 +2259,12 @@ /**

/**
* Change the visible colour (and opacity) of an existing annotation.
* @param doc - pdf document
* @param page - pdf page
* @param annotation - the annotation to recolour
* @param colour - RGBA color values (0-255 per channel)
* @param which - 0 = stroke/fill colour (PDFium's "colourType" param)
* @returns task that indicates whether the operation succeeded
*/
updateAnnotationColor: (doc: PdfDocumentObject, page: PdfPageObject, annotation: PdfAnnotationObjectBase, color: WebAlphaColor, which?: number) => PdfTask<boolean>;
/**
* Create a annotation on specified page

@@ -2132,4 +2276,12 @@ * @param doc - pdf document

*/
createPageAnnotation: (doc: PdfDocumentObject, page: PdfPageObject, annotation: PdfAnnotationObject) => PdfTask<boolean>;
createPageAnnotation: (doc: PdfDocumentObject, page: PdfPageObject, annotation: PdfAnnotationObject) => PdfTask<number>;
/**
* Update a annotation on specified page
* @param doc - pdf document
* @param page - pdf page
* @param annotation - new annotations
* @returns task that indicates whether the operation succeeded
*/
updatePageAnnotation: (doc: PdfDocumentObject, page: PdfPageObject, annotation: PdfAnnotationObject) => PdfTask<boolean>;
/**
* Transform the annotation

@@ -2297,2 +2449,19 @@ * @param doc - pdf document

/**
* Parse a PDF date string **D:YYYYMMDDHHmmSSOHH'mm'** to ISO-8601.
*
* Returns `undefined` if the input is malformed.
*
* @public
*/
declare function pdfDateToDate(pdf?: string): Date | undefined;
/**
* Convert a date to a PDF date string
* @param date - date to convert
* @returns PDF date string
*
* @public
*/
declare function dateToPdfDate(date?: Date): string;
/**
* Library contains the common definitions of data types and logic

@@ -2314,2 +2483,2 @@ *

export { AllLogger, AppearanceMode, type Box, ConsoleLogger, type FormFieldValue, type ImageConversionTypes, LevelLogger, LogLevel, type Logger, MatchFlag, NoopLogger, PDF_FORM_FIELD_FLAG, PDF_FORM_FIELD_TYPE, type PageTextSlice, type PdfActionObject, PdfActionType, type PdfAlphaColor, type PdfAnnotationObject, type PdfAnnotationObjectBase, PdfAnnotationObjectStatus, PdfAnnotationState, PdfAnnotationStateModel, PdfAnnotationSubtype, PdfAnnotationSubtypeName, type PdfAnnotationTransformation, type PdfAttachmentObject, PdfBomOrZwnbsp, type PdfBookmarkObject, type PdfBookmarksObject, type PdfCaretAnnoObject, type PdfCircleAnnoObject, type PdfDestinationObject, type PdfDocumentObject, type PdfEngine, type PdfEngineError, PdfEngineFeature, type PdfEngineMethodArgs, type PdfEngineMethodName, type PdfEngineMethodReturnType, PdfEngineOperation, PdfErrorCode, type PdfErrorReason, type PdfFile, type PdfFileAttachmentAnnoObject, type PdfFileContent, type PdfFileLoader, type PdfFileUrl, type PdfFileWithoutContent, type PdfFormObject, type PdfFreeTextAnnoObject, type PdfGlyphObject, type PdfGlyphSlim, type PdfHighlightAnnoObject, type PdfImage, type PdfImageObject, type PdfInkAnnoObject, type PdfInkListObject, type PdfLineAnnoObject, type PdfLinkAnnoObject, type PdfLinkTarget, type PdfMetadataObject, PdfNonCharacterFFFE, PdfNonCharacterFFFF, PdfPageFlattenFlag, PdfPageFlattenResult, type PdfPageGeometry, type PdfPageObject, PdfPageObjectType, type PdfPageObjectWithRotatedSize, type PdfPathObject, PdfPermission, type PdfPolygonAnnoObject, type PdfPolylineAnnoObject, type PdfPopupAnnoObject, type PdfRenderOptions, type PdfRun, type PdfSegmentObject, PdfSegmentObjectType, type PdfSignatureObject, PdfSoftHyphenMarker, type PdfSquareAnnoObject, type PdfSquigglyAnnoObject, type PdfStampAnnoObject, type PdfStampAnnoObjectContents, type PdfStrikeOutAnnoObject, type PdfSupportedAnnoObject, type PdfTask, PdfTaskHelper, type PdfTextAnnoObject, type PdfTextRectObject, type PdfTransformMatrix, type PdfUnderlineAnnoObject, type PdfUnsupportedAnnoObject, PdfUnwantedTextMarkers, PdfUnwantedTextRegex, type PdfUrlOptions, type PdfWidgetAnnoField, type PdfWidgetAnnoObject, type PdfWidgetAnnoOption, PdfWordJoiner, PdfZeroWidthSpace, PdfZoomMode, PerfLogger, type Position, type Quad, type Rect, type RejectedCallback, type ResolvedCallback, Rotation, type SearchAllPagesResult, type SearchResult, type SearchTarget, type Size, Task, TaskAbortedError, type TaskError, TaskRejectedError, type TaskReturn, TaskStage, type TaskState, type TextContext, boundingRect, calculateAngle, calculateDegree, compareSearchTarget, ignore, quadToRect, restoreOffset, restorePosition, restoreRect, rotatePosition, rotateRect, scalePosition, scaleRect, stripPdfUnwantedMarkers, swap, toIntPos, toIntRect, toIntSize, transformPosition, transformRect, transformSize, unionFlags };
export { AllLogger, AppearanceMode, type Box, ConsoleLogger, type FormFieldValue, type ImageConversionTypes, LevelLogger, LogLevel, type Logger, MatchFlag, NoopLogger, PDF_FORM_FIELD_FLAG, PDF_FORM_FIELD_TYPE, type PageTextSlice, type PdfActionObject, PdfActionType, type PdfAlphaColor, type PdfAnnotationObject, type PdfAnnotationObjectBase, PdfAnnotationObjectStatus, PdfAnnotationState, PdfAnnotationStateModel, PdfAnnotationSubtype, PdfAnnotationSubtypeName, type PdfAnnotationTransformation, type PdfAttachmentObject, PdfBomOrZwnbsp, type PdfBookmarkObject, type PdfBookmarksObject, type PdfCaretAnnoObject, type PdfCircleAnnoObject, type PdfDestinationObject, type PdfDocumentObject, type PdfEngine, type PdfEngineError, PdfEngineFeature, type PdfEngineMethodArgs, type PdfEngineMethodName, type PdfEngineMethodReturnType, PdfEngineOperation, PdfErrorCode, type PdfErrorReason, type PdfFile, type PdfFileAttachmentAnnoObject, type PdfFileContent, type PdfFileLoader, type PdfFileUrl, type PdfFileWithoutContent, type PdfFormObject, type PdfFreeTextAnnoObject, type PdfGlyphObject, type PdfGlyphSlim, type PdfHighlightAnnoObject, type PdfImage, type PdfImageObject, type PdfInkAnnoObject, type PdfInkListObject, type PdfLineAnnoObject, type PdfLinkAnnoObject, type PdfLinkTarget, type PdfMetadataObject, PdfNonCharacterFFFE, PdfNonCharacterFFFF, PdfPageFlattenFlag, PdfPageFlattenResult, type PdfPageGeometry, type PdfPageObject, PdfPageObjectType, type PdfPageObjectWithRotatedSize, type PdfPathObject, PdfPermission, type PdfPolygonAnnoObject, type PdfPolylineAnnoObject, type PdfPopupAnnoObject, type PdfRenderOptions, type PdfRun, type PdfSegmentObject, PdfSegmentObjectType, type PdfSignatureObject, PdfSoftHyphenMarker, type PdfSquareAnnoObject, type PdfSquigglyAnnoObject, type PdfStampAnnoObject, type PdfStampAnnoObjectContents, type PdfStrikeOutAnnoObject, type PdfSupportedAnnoObject, type PdfTask, PdfTaskHelper, type PdfTextAnnoObject, type PdfTextRectObject, type PdfTransformMatrix, type PdfUnderlineAnnoObject, type PdfUnsupportedAnnoObject, PdfUnwantedTextMarkers, PdfUnwantedTextRegex, type PdfUrlOptions, type PdfWidgetAnnoField, type PdfWidgetAnnoObject, type PdfWidgetAnnoOption, PdfWordJoiner, PdfZeroWidthSpace, PdfZoomMode, PerfLogger, type Position, type Quad, type Rect, type RejectedCallback, type ResolvedCallback, Rotation, type SearchAllPagesResult, type SearchResult, type SearchTarget, type Size, Task, TaskAbortedError, type TaskError, TaskRejectedError, type TaskReturn, type TaskSettledResult, TaskStage, type TaskState, type TextContext, type WebAlphaColor, boundingRect, calculateAngle, calculateDegree, compareSearchTarget, dateToPdfDate, ignore, pdfAlphaColorToWebAlphaColor, pdfDateToDate, quadToRect, rectToQuad, restoreOffset, restorePosition, restoreRect, rotatePosition, rotateRect, scalePosition, scaleRect, stripPdfUnwantedMarkers, swap, toIntPos, toIntRect, toIntSize, transformPosition, transformRect, transformSize, unionFlags, webAlphaColorToPdfAlphaColor };

@@ -61,2 +61,10 @@ // src/geometry.ts

}
function rectToQuad(r) {
return {
p1: { x: r.origin.x, y: r.origin.y },
p2: { x: r.origin.x + r.size.width, y: r.origin.y },
p3: { x: r.origin.x + r.size.width, y: r.origin.y + r.size.height },
p4: { x: r.origin.x, y: r.origin.y + r.size.height }
};
}
function rotatePosition(containerSize, position, rotation) {

@@ -385,3 +393,3 @@ let x = position.x;

};
var Task = class {
var Task = class _Task {
constructor() {

@@ -532,2 +540,144 @@ this.state = {

}
/**
* Static method to wait for all tasks to resolve
* Returns a new task that resolves with an array of all results
* Rejects immediately if any task fails
*
* @param tasks - array of tasks to wait for
* @returns new task that resolves when all input tasks resolve
* @public
*/
static all(tasks) {
const combinedTask = new _Task();
if (tasks.length === 0) {
combinedTask.resolve([]);
return combinedTask;
}
const results = new Array(tasks.length);
let resolvedCount = 0;
let isSettled = false;
tasks.forEach((task, index) => {
task.wait(
(result) => {
if (isSettled) return;
results[index] = result;
resolvedCount++;
if (resolvedCount === tasks.length) {
isSettled = true;
combinedTask.resolve(results);
}
},
(error) => {
if (isSettled) return;
isSettled = true;
if (error.type === "abort") {
combinedTask.abort(error.reason);
} else {
combinedTask.reject(error.reason);
}
}
);
});
return combinedTask;
}
/**
* Static method to wait for all tasks to settle (resolve, reject, or abort)
* Always resolves with an array of settlement results
*
* @param tasks - array of tasks to wait for
* @returns new task that resolves when all input tasks settle
* @public
*/
static allSettled(tasks) {
const combinedTask = new _Task();
if (tasks.length === 0) {
combinedTask.resolve([]);
return combinedTask;
}
const results = new Array(tasks.length);
let settledCount = 0;
tasks.forEach((task, index) => {
task.wait(
(result) => {
results[index] = { status: "resolved", value: result };
settledCount++;
if (settledCount === tasks.length) {
combinedTask.resolve(results);
}
},
(error) => {
results[index] = {
status: error.type === "abort" ? "aborted" : "rejected",
reason: error.reason
};
settledCount++;
if (settledCount === tasks.length) {
combinedTask.resolve(results);
}
}
);
});
return combinedTask;
}
/**
* Static method that resolves/rejects with the first task that settles
*
* @param tasks - array of tasks to race
* @returns new task that settles with the first input task that settles
* @public
*/
static race(tasks) {
const combinedTask = new _Task();
if (tasks.length === 0) {
combinedTask.reject("No tasks provided");
return combinedTask;
}
let isSettled = false;
tasks.forEach((task) => {
task.wait(
(result) => {
if (isSettled) return;
isSettled = true;
combinedTask.resolve(result);
},
(error) => {
if (isSettled) return;
isSettled = true;
if (error.type === "abort") {
combinedTask.abort(error.reason);
} else {
combinedTask.reject(error.reason);
}
}
);
});
return combinedTask;
}
/**
* Utility to track progress of multiple tasks
*
* @param tasks - array of tasks to track
* @param onProgress - callback called when any task completes
* @returns new task that resolves when all input tasks resolve
* @public
*/
static withProgress(tasks, onProgress) {
const combinedTask = _Task.all(tasks);
if (onProgress) {
let completedCount = 0;
tasks.forEach((task) => {
task.wait(
() => {
completedCount++;
onProgress(completedCount, tasks.length);
},
() => {
completedCount++;
onProgress(completedCount, tasks.length);
}
);
});
}
return combinedTask;
}
};

@@ -833,2 +983,48 @@

// src/color.ts
function pdfAlphaColorToWebAlphaColor(c) {
const clamp = (n) => Math.max(0, Math.min(255, n));
const toHex = (n) => clamp(n).toString(16).padStart(2, "0");
const color = `#${toHex(c.red)}${toHex(c.green)}${toHex(c.blue)}`;
const opacity = clamp(c.alpha) / 255;
return { color, opacity };
}
function webAlphaColorToPdfAlphaColor({ color, opacity }) {
if (/^#?[0-9a-f]{3}$/i.test(color)) {
color = color.replace(/^#?([0-9a-f])([0-9a-f])([0-9a-f])$/i, "#$1$1$2$2$3$3").toLowerCase();
}
const [, r, g, b] = /^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(color) ?? (() => {
throw new Error(`Invalid hex colour: \u201C${color}\u201D`);
})();
const clamp = (n, hi = 255) => Math.max(0, Math.min(hi, n));
return {
red: parseInt(r, 16),
green: parseInt(g, 16),
blue: parseInt(b, 16),
alpha: clamp(Math.round(opacity * 255))
};
}
// src/date.ts
function pdfDateToDate(pdf) {
if (!pdf?.startsWith("D:") || pdf.length < 16) return;
const y = +pdf.slice(2, 6);
const mo = +pdf.slice(6, 8) - 1;
const d = +pdf.slice(8, 10);
const H = +pdf.slice(10, 12);
const M = +pdf.slice(12, 14);
const S = +pdf.slice(14, 16);
return new Date(Date.UTC(y, mo, d, H, M, S));
}
function dateToPdfDate(date = /* @__PURE__ */ new Date()) {
const z = (n, len = 2) => n.toString().padStart(len, "0");
const YYYY = date.getUTCFullYear();
const MM = z(date.getUTCMonth() + 1);
const DD = z(date.getUTCDate());
const HH = z(date.getUTCHours());
const mm = z(date.getUTCMinutes());
const SS = z(date.getUTCSeconds());
return `D:${YYYY}${MM}${DD}${HH}${mm}${SS}`;
}
// src/index.ts

@@ -881,4 +1077,8 @@ function ignore() {

compareSearchTarget,
dateToPdfDate,
ignore,
pdfAlphaColorToWebAlphaColor,
pdfDateToDate,
quadToRect,
rectToQuad,
restoreOffset,

@@ -899,4 +1099,5 @@ restorePosition,

transformSize,
unionFlags
unionFlags,
webAlphaColorToPdfAlphaColor
};
//# sourceMappingURL=index.js.map
+1
-1
{
"name": "@embedpdf/models",
"version": "1.0.6",
"version": "1.0.7",
"private": false,

@@ -5,0 +5,0 @@ "description": "Shared type definitions, data models, and utility helpers (geometry, tasks, logging, PDF primitives) that underpin every package in the EmbedPDF ecosystem.",

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display