@inkbar/core 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,4 +1,5 @@
1
- import { $ as AnnotationDefaults, $t as TextMarkupSchema, A as TextItem, At as LoupeSchema, B as createHistory, Bt as PolylineSchema, C as DocumentInfo, Cn as rectsIntersect, Ct as InkAnnotation, D as OpenOptions, Dt as LineEndingSchema, E as InkStatus, En as unionRects, Et as LineEnding, F as ImportOptions, Ft as NoteSchema, G as createAnnotationStore, Gt as ShapeAnnotation, H as AnnotationStore, Ht as RectSchema, I as ImportResult, It as PointSchema, J as SUPPORTED_SUBTYPES, Jt as StampAnnotation, K as deriveRect, Kt as ShapeSchema, L as exportAnnotations, Lt as PolyAnnotation, M as InkError, Mt as MaskSchema, N as InkErrorCode, Nt as NoteAnnotation, O as openDocument, Ot as LineSchema, P as isInkError, Pt as NoteIconSchema, Q as summarise, Qt as TextMarkupAnnotation, R as importAnnotations, Rt as PolySchema, S as createToolStyle, Sn as rectFromQuad, St as IMAGE_DATA_URL, T as InkDocument, Tn as translateRect, Tt as LineAnnotation, U as StoreMode, Ut as RedactAnnotation, V as AnnotationChange, Vt as QuadSchema, W as StoreOptions, Wt as RedactSchema, X as importedId, Xt as Suggestion, Y as importEmbeddedPage, Yt as StampSchema, Z as pdfColorToHex, Zt as SuggestionSchema, _ as StyleGroup, _n as pointsFromFlat, _t as ForeignAnnotation, a as SignatureStore, an as writable, at as Annotation, b as ToolStyle, bn as rectContainsPoint, bt as FreeTextStyle, c as createInkTemplate, cn as PdfAssets, ct as AnnotationInput, d as createSignatureLibrary, dn as Quad, dt as AnnotationSchema, en as confidenceBucket, et as cssVariableDefaults, f as normaliseInk, fn as Rect, ft as AnnotationType, g as ScopedToolStyle, gn as multiplyMatrix, gt as ExportedAnnotationSchema, h as STYLE_GROUPS, hn as invertMatrix, ht as ExportedAnnotation, i as SignatureOptions, in as readonly, it as ANNOTATION_VERSION, j as DocumentSource, jt as MaskAnnotation, k as TextContent, kt as LoupeAnnotation, l as createLocalSignatureStore, ln as Matrix, lt as AnnotationOfType, m as CurrentStyle, mn as approxEqual, mt as ConfidenceBucket, n as SIGNATURE_INK_WIDTH, nn as Writable, nt as staticDefaults, o as SignatureTemplate, on as PageInfo, ot as AnnotationDocument, p as placeSignature, pn as applyMatrix, pt as CircleSchema, q as EmbeddedSummary, qt as SquareSchema, r as SignatureLibrary, rn as derived, rt as ANNOTATION_FORMAT, s as createImageTemplate, sn as PageRotation, st as AnnotationDocumentSchema, t as DEFAULT_SIGNATURE_WIDTH, tn as Readable, tt as normalizeColor, u as createMemorySignatureStore, un as Point, ut as AnnotationPatch, v as StyleKey, vn as quadFromRect, vt as FreeTextAnnotation, w as DocumentStatus, wn as translateQuad, wt as InkSchema, x as ToolStyleDeps, xn as rectFromPoints, xt as FreeTextStyleSchema, y as StyleProps, yn as quadsFromFlat, yt as FreeTextSchema, z as History, zt as PolygonSchema } from "./signatures-BHYKTwYE.mjs";
1
+ import { $ as pdfColorToHex, $t as StampAnnotation, A as TextItem, At as LineAnnotation, B as createHistory, Bt as NoteSchema, C as DocumentInfo, Cn as rectFromPoints, Ct as GLOSS_FORMAT, D as OpenOptions, Dn as translateRect, Dt as IMAGE_DATA_URL, E as InkStatus, En as translateQuad, Et as GLOSS_VERSION, F as ImportOptions, Ft as LoupeSchema, G as createAnnotationStore, Gt as PolylineSchema, H as AnnotationStore, Ht as PolyAnnotation, I as ImportResult, It as MaskAnnotation, J as EmbeddedSummary, Jt as RedactAnnotation, K as deriveRect, Kt as QuadSchema, L as exportAnnotations, Lt as MaskSchema, M as InkError, Mt as LineEndingSchema, N as InkErrorCode, Nt as LineSchema, O as openDocument, On as unionRects, Ot as InkAnnotation, P as isInkError, Pt as LoupeAnnotation, Q as importedId, Qt as SquareSchema, R as importAnnotations, Rt as NoteAnnotation, S as createToolStyle, Sn as rectContainsPoint, St as FreeTextStyleSchema, T as InkDocument, Tn as rectsIntersect, Tt as GLOSS_SCHEMA_ID, U as StoreMode, Ut as PolySchema, V as AnnotationChange, Vt as PointSchema, W as StoreOptions, Wt as PolygonSchema, X as SUPPORTED_SUBTYPES, Xt as ShapeAnnotation, Y as EmbeddedTarget, Yt as RedactSchema, Z as importEmbeddedPage, Zt as ShapeSchema, _ as StyleGroup, _n as invertMatrix, _t as ExportedAnnotationSchema, a as SignatureStore, an as derived, at as normalizeColor, b as ToolStyle, bn as quadFromRect, bt as FreeTextSchema, c as createInkTemplate, cn as PageInfo, ct as AnnotationDocument, d as createSignatureLibrary, dn as Matrix, dt as AnnotationOfType, en as StampSchema, et as summarise, f as normaliseInk, fn as Point, ft as AnnotationPatch, g as ScopedToolStyle, gn as approxEqual, gt as ExportedAnnotation, h as STYLE_GROUPS, hn as applyMatrix, ht as CircleSchema, i as SignatureOptions, in as Writable, it as cssVariableDefaults, j as DocumentSource, jt as LineEnding, k as TextContent, kt as InkSchema, l as createLocalSignatureStore, ln as PageRotation, lt as AnnotationDocumentSchema, m as CurrentStyle, mn as Rect, mt as AnnotationType, n as SIGNATURE_INK_WIDTH, nn as TextMarkupSchema, nt as FringeSchema, o as SignatureTemplate, on as readonly, ot as staticDefaults, p as placeSignature, pn as Quad, pt as AnnotationSchema, q as EmbeddedFieldPatch, qt as RectSchema, r as SignatureLibrary, rn as Readable, rt as AnnotationDefaults, s as createImageTemplate, sn as writable, st as Annotation, t as DEFAULT_SIGNATURE_WIDTH, tn as TextMarkupAnnotation, tt as Fringe, u as createMemorySignatureStore, un as PdfAssets, ut as AnnotationInput, v as StyleKey, vn as multiplyMatrix, vt as ForeignAnnotation, w as DocumentStatus, wn as rectFromQuad, wt as GLOSS_MEDIA_TYPE, x as ToolStyleDeps, xn as quadsFromFlat, xt as FreeTextStyle, y as StyleProps, yn as pointsFromFlat, yt as FreeTextAnnotation, z as History, zt as NoteIconSchema } from "./signatures-BwaXi7C8.mjs";
2
+ import { INTENTS, LINE_ENDINGS, NOTE_ICONS, PDF_NAME } from "gloss-format";
2
3
  import { z } from "zod";
3
4
  //#region src/model/events.d.ts
4
5
  export type Listener<T> = (payload: T) => void;
@@ -19,36 +20,12 @@ export declare class Emitter<Events extends Record<string, unknown>> {
19
20
  */
20
21
  export declare function mergeLineRects(rects: readonly Rect[], tolerance?: number, gap?: number): Quad[];
21
22
  //#endregion
22
- //#region src/model/annotations/callout.d.ts
23
- /**
24
- * The insets from a free text's `rect` to its text box, in points (PDF `/RD`, XFDF `fringe`,
25
- * both in this order).
26
- */
27
- export declare const FringeSchema: z.ZodObject<{
28
- left: z.ZodNumber;
29
- top: z.ZodNumber;
30
- right: z.ZodNumber;
31
- bottom: z.ZodNumber;
32
- }, z.core.$strip>;
33
- type Fringe = z.infer<typeof FringeSchema>;
34
- //#endregion
35
23
  //#region src/model/annotations/pdf-names.d.ts
36
- /**
37
- * A PDF name: a non-empty run of regular characters, so no whitespace and none of the
38
- * delimiters `( ) < > [ ] { } / %`.
39
- */
40
- export declare const PDF_NAME: RegExp;
41
24
  /**
42
25
  * A set of PDF names Inkbar knows that stays open: any other valid PDF name loads, is kept and
43
26
  * is written back unchanged. The output type keeps autocomplete for the known values.
44
27
  */
45
28
  export declare function pdfNameSet<const K extends readonly [string, ...string[]]>(known: K): z.ZodType<K[number] | (string & {}), K[number] | (string & {})>;
46
- /** Line ending styles (PDF `/LE`). */
47
- export declare const LINE_ENDINGS: readonly ["None", "Square", "Circle", "Diamond", "OpenArrow", "ClosedArrow", "Butt", "ROpenArrow", "RClosedArrow", "Slash"];
48
- /** Note icons (PDF `/Name` on a text annotation). */
49
- export declare const NOTE_ICONS: readonly ["Comment", "Note", "Help", "Insert", "Key", "NewParagraph", "Paragraph"];
50
- /** Annotation intents (PDF `/IT`). */
51
- export declare const INTENTS: readonly ["FreeText", "FreeTextCallout", "FreeTextTypeWriter", "LineArrow", "LineDimension", "PolygonCloud", "PolygonDimension", "PolyLineDimension"];
52
29
  /** True when `v` is one of the values in `list`. */
53
30
  export declare function isKnown<K extends readonly string[]>(list: K, v: string): v is K[number];
54
31
  //#endregion
@@ -127,16 +104,6 @@ interface SnapshotHistory {
127
104
  }
128
105
  export declare function createSnapshotHistory(opts: SnapshotHistoryOptions): SnapshotHistory;
129
106
  //#endregion
130
- //#region src/model/annotations/suggestions.d.ts
131
- /**
132
- * Keeps a suggested redaction as the user's own: `origin` becomes `'user'` and the colour
133
- * goes from the confidence colour to the store's default redaction colour, so an accepted
134
- * mark looks like any other. The suggestion details stay on it. Returns the updated
135
- * annotation, or undefined (changing nothing) when `id` is not a suggested redaction or is
136
- * locked.
137
- */
138
- export declare function acceptSuggestion(store: AnnotationStore, id: string): Annotation | undefined;
139
- //#endregion
140
107
  //#region src/model/annotations/threads.d.ts
141
108
  /** What a thread can hang from: a note, or text markup whose `contents` is its comment. */
142
109
  type ThreadRoot = NoteAnnotation | TextMarkupAnnotation;
@@ -210,5 +177,5 @@ export declare function recogniseStroke(points: readonly Point[]): {
210
177
  /** The @inkbar/core version, from its package.json. */
211
178
  export declare const version: string;
212
179
  //#endregion
213
- export { ANNOTATION_FORMAT, ANNOTATION_VERSION, Annotation, AnnotationChange, AnnotationDefaults, AnnotationDocument, AnnotationDocumentSchema, AnnotationInput, AnnotationOfType, AnnotationPatch, AnnotationSchema, AnnotationStore, AnnotationType, CircleSchema, ConfidenceBucket, type CurrentStyle, DEFAULT_SIGNATURE_WIDTH, type DocumentInfo, type DocumentSource, type DocumentStatus, EmbeddedSummary, ExportedAnnotation, ExportedAnnotationSchema, ForeignAnnotation, FreeTextAnnotation, FreeTextSchema, FreeTextStyle, FreeTextStyleSchema, type Fringe, History, IMAGE_DATA_URL, type ImportOptions, type ImportResult, InkAnnotation, type InkDocument, InkError, InkErrorCode, InkSchema, type InkStatus, LineAnnotation, LineEnding, LineEndingSchema, LineSchema, LoupeAnnotation, LoupeSchema, MaskAnnotation, MaskSchema, Matrix, NoteAnnotation, NoteIconSchema, NoteSchema, type OpenOptions, type PageInfo, type PageRotation, type PdfAssets, Point, PointSchema, PolyAnnotation, PolySchema, PolygonSchema, PolylineSchema, Quad, QuadSchema, Readable, type Recognised, Rect, RectSchema, RedactAnnotation, RedactSchema, SIGNATURE_INK_WIDTH, STYLE_GROUPS, SUPPORTED_SUBTYPES, type ScopedToolStyle, ShapeAnnotation, ShapeSchema, type SignatureLibrary, type SignatureOptions, type SignatureStore, type SignatureTemplate, type SnapshotHistory, type SnapshotHistoryOptions, SquareSchema, StampAnnotation, StampSchema, StoreMode, StoreOptions, type StyleGroup, type StyleKey, type StyleProps, Suggestion, SuggestionSchema, type TextContent, type TextItem, TextMarkupAnnotation, TextMarkupSchema, type ThreadRoot, type ToolStyle, type ToolStyleDeps, Writable, applyMatrix, approxEqual, confidenceBucket, createAnnotationStore, createHistory, createImageTemplate, createInkTemplate, createLocalSignatureStore, createMemorySignatureStore, createSignatureLibrary, createToolStyle, cssVariableDefaults, deriveRect, derived, exportAnnotations, importAnnotations, importEmbeddedPage, importedId, invertMatrix, isInkError, multiplyMatrix, normaliseInk, normalizeColor, openDocument, pdfColorToHex, placeSignature, pointsFromFlat, quadFromRect, quadsFromFlat, readonly, rectContainsPoint, rectFromPoints, rectFromQuad, rectsIntersect, staticDefaults, summarise, translateQuad, translateRect, unionRects, writable };
180
+ export { Annotation, AnnotationChange, AnnotationDefaults, AnnotationDocument, AnnotationDocumentSchema, AnnotationInput, AnnotationOfType, AnnotationPatch, AnnotationSchema, AnnotationStore, AnnotationType, CircleSchema, type CurrentStyle, DEFAULT_SIGNATURE_WIDTH, type DocumentInfo, type DocumentSource, type DocumentStatus, EmbeddedFieldPatch, EmbeddedSummary, EmbeddedTarget, ExportedAnnotation, ExportedAnnotationSchema, ForeignAnnotation, FreeTextAnnotation, FreeTextSchema, FreeTextStyle, FreeTextStyleSchema, type Fringe, FringeSchema, GLOSS_FORMAT, GLOSS_MEDIA_TYPE, GLOSS_SCHEMA_ID, GLOSS_VERSION, History, IMAGE_DATA_URL, INTENTS, type ImportOptions, type ImportResult, InkAnnotation, type InkDocument, InkError, InkErrorCode, InkSchema, type InkStatus, LINE_ENDINGS, LineAnnotation, LineEnding, LineEndingSchema, LineSchema, LoupeAnnotation, LoupeSchema, MaskAnnotation, MaskSchema, Matrix, NOTE_ICONS, NoteAnnotation, NoteIconSchema, NoteSchema, type OpenOptions, PDF_NAME, type PageInfo, type PageRotation, type PdfAssets, Point, PointSchema, PolyAnnotation, PolySchema, PolygonSchema, PolylineSchema, Quad, QuadSchema, Readable, type Recognised, Rect, RectSchema, RedactAnnotation, RedactSchema, SIGNATURE_INK_WIDTH, STYLE_GROUPS, SUPPORTED_SUBTYPES, type ScopedToolStyle, ShapeAnnotation, ShapeSchema, type SignatureLibrary, type SignatureOptions, type SignatureStore, type SignatureTemplate, type SnapshotHistory, type SnapshotHistoryOptions, SquareSchema, StampAnnotation, StampSchema, StoreMode, StoreOptions, type StyleGroup, type StyleKey, type StyleProps, type TextContent, type TextItem, TextMarkupAnnotation, TextMarkupSchema, type ThreadRoot, type ToolStyle, type ToolStyleDeps, Writable, applyMatrix, approxEqual, createAnnotationStore, createHistory, createImageTemplate, createInkTemplate, createLocalSignatureStore, createMemorySignatureStore, createSignatureLibrary, createToolStyle, cssVariableDefaults, deriveRect, derived, exportAnnotations, importAnnotations, importEmbeddedPage, importedId, invertMatrix, isInkError, multiplyMatrix, normaliseInk, normalizeColor, openDocument, pdfColorToHex, placeSignature, pointsFromFlat, quadFromRect, quadsFromFlat, readonly, rectContainsPoint, rectFromPoints, rectFromQuad, rectsIntersect, staticDefaults, summarise, translateQuad, translateRect, unionRects, writable };
214
181
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":["StyleKey"],"sources":["../src/model/events.ts","../src/model/selection.ts","../src/model/annotations/callout.ts","../src/model/annotations/pdf-names.ts","../src/model/annotations/style-map.ts","../src/model/annotations/snapshot-history.ts","../src/model/annotations/suggestions.ts","../src/model/annotations/threads.ts","../src/model/pdf-date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Ac,MAAM,aAAa;;;;;wBAmBzD,gBAAgB,GAAG,YAAY,eAAe;;;;wBC3E9C,aAAa,kCAAkC;;;KCsBnD;EACN;EAAc,OAAO;EAAO,KAAK;;EACjC;EAAe,OAAO;EAAO,KAAK;;EAClC;EAAmB,MAAM;;EACzB;EAAiB,MAAM;;;;EAEvB;EAAiB,UAAU;;;;EAE3B;EAAc,UAAU;;;qBAGjB;;;;;;wBA6dG,gBACd,iBAAiB;EACd,OAAO;EAAY;;;;;qBC7fX"}
1
+ {"version":3,"file":"index.d.mts","names":["StyleKey"],"sources":["../src/model/events.ts","../src/model/selection.ts","../src/model/annotations/pdf-names.ts","../src/model/annotations/style-map.ts","../src/model/annotations/snapshot-history.ts","../src/model/annotations/threads.ts","../src/model/pdf-date.ts","../src/model/recognise.ts","../src/index.ts"],"mappings":";;;;YAAY,SAAS,MAAM,SAAS;qBAEvB,QAAQ,eAAe;UAC1B;EAER,GAAG,gBAAgB,QAAQ,OAAO,GAAG,IAAI,SAAS,OAAO;EAYzD,KAAK,gBAAgB,QAAQ,OAAO,GAAG,SAAS,OAAO;EAMvD;;;;;;;;;;;wBCKc,eACd,gBAAgB,QAChB,oBACA,eACC;;;;;;;wBCvBa,iBAAiB,0CAA0C,OAAO,IAKzE,EAAE,QAAQ,2BAA2B;;wBAI9B,QAAQ,6BAA6B,MAAM,GAAG,YAAY,KAAK;;;KCZ1EA,mBAAiB;;;;;wBAqHN,aACd,GAAG,KAAK;EAAwB;GAChC,MAAMA,aACL;;wBAYa,cACd,GAAG,KAAK;EAAwB;IAC/B;;wBAYa,aAAa,OAAO,aAAa;;wBAKjC,iBAAiB,MAAM,iBAAiB;;wBAKxC,eAAe,MAAM,iBAAiB,YAAYA;;;;;;;wBAuBlD,SAAS,MAAM,gBAAgB,OAAO,aAAa;;wBAmBnD,eAAe,GAAG,aAAa;;;UCvM9B;;EAEf,QAAQ,MAAM;;EAEd;;EAEA;;;;;;;;UASe;WACN,SAAS;WACT,SAAS;EAClB;EACA;EACA;;;;;;EAMA,QAAQ,eAAe;;;;;;;;;;;;;;;;EAgBvB,MAAM;;wBAMQ,sBAAsB,MAAM,yBAAyB;;;;KChDzD,aAAa,iBAAiB;wBAE1B,aAAa,GAAG,aAAa,KAAK;;;;;wBAQlC,QAAQ,GAAG,YAAY,eAAe;;wBAOtC,eAAe,eAAe,eAAe;;wBAM7C,UAAU,eAAe,cAAc,aAAa;;;;;;wBAWpD,WACd,eAAe,cACf,OAAO,aACN;;wBAea,SAAS,eAAe,cAAc,MAAM,aAAa;;;;;wBAmBzD,gBAAgB,GAAG,YAAY,eAAe;;;;wBC3E9C,aAAa,kCAAkC;;;KCsBnD;EACN;EAAc,OAAO;EAAO,KAAK;;EACjC;EAAe,OAAO;EAAO,KAAK;;EAClC;EAAmB,MAAM;;EACzB;EAAiB,MAAM;;;;EAEvB;EAAiB,UAAU;;;;EAE3B;EAAc,UAAU;;;qBAGjB;;;;;;wBA6dG,gBACd,iBAAiB;EACd,OAAO;EAAY;;;;;qBC7fX"}
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { $ as exportAnnotations, $t as derived, A as fromAnnotation, At as RedactSchema, C as repliesTo, Ct as NoteSchema, D as acceptSuggestion, Dt as PolylineSchema, E as withoutReplies, Et as PolygonSchema, F as toFields, Ft as TextMarkupSchema, Gt as PDF_NAME, Ht as INTENTS, I as typesInGroup, It as confidenceBucket, Jt as parsePdfDate, Kt as isKnown, Lt as FringeSchema, M as styleGroupOfType, Mt as SquareSchema, N as styleGroupsOf, Nt as StampSchema, O as STYLE_GROUPS, Ot as QuadSchema, P as supportedProps, Pt as SuggestionSchema, Q as deriveRect, Qt as mergeLineRects, S as isThreadRoot, St as NoteIconSchema, T as threadRoot, Tt as PolySchema, Ut as LINE_ENDINGS, Wt as NOTE_ICONS, X as openDocument, Xt as normalizeColor, Yt as cssVariableDefaults, Z as createAnnotationStore, Zt as staticDefaults, _n as InkError, _t as InkSchema, a as createLocalSignatureStore, an as multiplyMatrix, at as importedId, b as isAbandonedNote, bt as LoupeSchema, c as normaliseInk, cn as quadsFromFlat, ct as ANNOTATION_FORMAT, d as recogniseStroke, dn as rectFromQuad, dt as AnnotationSchema, en as readonly, et as importAnnotations, fn as rectsIntersect, ft as CircleSchema, gn as Emitter, gt as IMAGE_DATA_URL, hn as unionRects, ht as FreeTextStyleSchema, i as createInkTemplate, in as invertMatrix, it as importEmbeddedPage, j as styleGroupOf, jt as ShapeSchema, k as createToolStyle, kt as RectSchema, l as placeSignature, ln as rectContainsPoint, lt as ANNOTATION_VERSION, mn as translateRect, mt as FreeTextSchema, n as SIGNATURE_INK_WIDTH, nn as applyMatrix, nt as isProduction, o as createMemorySignatureStore, on as pointsFromFlat, ot as pdfColorToHex, pn as translateQuad, pt as ExportedAnnotationSchema, qt as pdfNameSet, r as createImageTemplate, rn as approxEqual, rt as SUPPORTED_SUBTYPES, s as createSignatureLibrary, sn as quadFromRect, st as summarise, t as DEFAULT_SIGNATURE_WIDTH, tn as writable, tt as createHistory, u as RECOGNISE_THRESHOLD, un as rectFromPoints, ut as AnnotationDocumentSchema, vn as isInkError, vt as LineEndingSchema, w as threadOf, wt as PointSchema, x as isReply, xt as MaskSchema, yt as LineSchema } from "./signatures-DF2VmNVa.mjs";
1
+ import { $ as importAnnotations, $t as readonly, A as styleGroupOf, At as RectSchema, C as repliesTo, Ct as NoteIconSchema, D as STYLE_GROUPS, Dt as PolygonSchema, E as withoutReplies, Et as PolySchema, F as typesInGroup, Ft as TextMarkupSchema, Gt as isKnown, Ht as LINE_ENDINGS, It as FringeSchema, Jt as cssVariableDefaults, Kt as pdfNameSet, M as styleGroupsOf, Mt as ShapeSchema, N as supportedProps, Nt as SquareSchema, O as createToolStyle, Ot as PolylineSchema, P as toFields, Pt as StampSchema, Q as exportAnnotations, Qt as derived, S as isThreadRoot, St as MaskSchema, T as threadRoot, Tt as PointSchema, Ut as NOTE_ICONS, Vt as INTENTS, Wt as PDF_NAME, X as createAnnotationStore, Xt as staticDefaults, Y as openDocument, Yt as normalizeColor, Z as deriveRect, Zt as mergeLineRects, _n as isInkError, _t as IMAGE_DATA_URL, a as createLocalSignatureStore, an as pointsFromFlat, at as pdfColorToHex, b as isAbandonedNote, bt as LineSchema, c as normaliseInk, cn as rectContainsPoint, ct as AnnotationSchema, d as recogniseStroke, dn as rectsIntersect, dt as FreeTextSchema, en as writable, et as createHistory, fn as translateQuad, ft as FreeTextStyleSchema, gn as InkError, gt as GLOSS_VERSION, hn as Emitter, ht as GLOSS_SCHEMA_ID, i as createInkTemplate, in as multiplyMatrix, it as importedId, j as styleGroupOfType, jt as RedactSchema, k as fromAnnotation, kt as QuadSchema, l as placeSignature, ln as rectFromPoints, lt as CircleSchema, mn as unionRects, mt as GLOSS_MEDIA_TYPE, n as SIGNATURE_INK_WIDTH, nn as approxEqual, nt as SUPPORTED_SUBTYPES, o as createMemorySignatureStore, on as quadFromRect, ot as summarise, pn as translateRect, pt as GLOSS_FORMAT, qt as parsePdfDate, r as createImageTemplate, rn as invertMatrix, rt as importEmbeddedPage, s as createSignatureLibrary, sn as quadsFromFlat, st as AnnotationDocumentSchema, t as DEFAULT_SIGNATURE_WIDTH, tn as applyMatrix, tt as isProduction, u as RECOGNISE_THRESHOLD, un as rectFromQuad, ut as ExportedAnnotationSchema, vt as InkSchema, w as threadOf, wt as NoteSchema, x as isReply, xt as LoupeSchema, yt as LineEndingSchema } from "./signatures-CMapTKrC.mjs";
2
2
  //#region src/model/annotations/snapshot-history.ts
3
3
  function createSnapshotHistory(opts) {
4
4
  const limit = Math.max(1, opts.limit ?? 200);
@@ -129,8 +129,8 @@ function presentKeys(o) {
129
129
  //#endregion
130
130
  //#region src/index.ts
131
131
  /** The @inkbar/core version, from its package.json. */
132
- const version = "0.4.0";
132
+ const version = "0.5.0";
133
133
  //#endregion
134
- export { ANNOTATION_FORMAT, ANNOTATION_VERSION, AnnotationDocumentSchema, AnnotationSchema, CircleSchema, DEFAULT_SIGNATURE_WIDTH, Emitter, ExportedAnnotationSchema, FreeTextSchema, FreeTextStyleSchema, FringeSchema, IMAGE_DATA_URL, INTENTS, InkError, InkSchema, LINE_ENDINGS, LineEndingSchema, LineSchema, LoupeSchema, MaskSchema, NOTE_ICONS, NoteIconSchema, NoteSchema, PDF_NAME, PointSchema, PolySchema, PolygonSchema, PolylineSchema, QuadSchema, RECOGNISE_THRESHOLD, RectSchema, RedactSchema, SIGNATURE_INK_WIDTH, STYLE_GROUPS, SUPPORTED_SUBTYPES, ShapeSchema, SquareSchema, StampSchema, SuggestionSchema, TextMarkupSchema, acceptSuggestion, applyMatrix, approxEqual, confidenceBucket, createAnnotationStore, createHistory, createImageTemplate, createInkTemplate, createLocalSignatureStore, createMemorySignatureStore, createSignatureLibrary, createSnapshotHistory, createToolStyle, cssVariableDefaults, deriveRect, derived, exportAnnotations, fromAnnotation, importAnnotations, importEmbeddedPage, importedId, invertMatrix, isAbandonedNote, isInkError, isKnown, isReply, isThreadRoot, mergeLineRects, multiplyMatrix, normaliseInk, normalizeColor, openDocument, parsePdfDate, pdfColorToHex, pdfNameSet, placeSignature, pointsFromFlat, quadFromRect, quadsFromFlat, readonly, recogniseStroke, rectContainsPoint, rectFromPoints, rectFromQuad, rectsIntersect, repliesTo, staticDefaults, styleGroupOf, styleGroupOfType, styleGroupsOf, summarise, supportedProps, threadOf, threadRoot, toFields, translateQuad, translateRect, typesInGroup, unionRects, version, withoutReplies, writable };
134
+ export { AnnotationDocumentSchema, AnnotationSchema, CircleSchema, DEFAULT_SIGNATURE_WIDTH, Emitter, ExportedAnnotationSchema, FreeTextSchema, FreeTextStyleSchema, FringeSchema, GLOSS_FORMAT, GLOSS_MEDIA_TYPE, GLOSS_SCHEMA_ID, GLOSS_VERSION, IMAGE_DATA_URL, INTENTS, InkError, InkSchema, LINE_ENDINGS, LineEndingSchema, LineSchema, LoupeSchema, MaskSchema, NOTE_ICONS, NoteIconSchema, NoteSchema, PDF_NAME, PointSchema, PolySchema, PolygonSchema, PolylineSchema, QuadSchema, RECOGNISE_THRESHOLD, RectSchema, RedactSchema, SIGNATURE_INK_WIDTH, STYLE_GROUPS, SUPPORTED_SUBTYPES, ShapeSchema, SquareSchema, StampSchema, TextMarkupSchema, applyMatrix, approxEqual, createAnnotationStore, createHistory, createImageTemplate, createInkTemplate, createLocalSignatureStore, createMemorySignatureStore, createSignatureLibrary, createSnapshotHistory, createToolStyle, cssVariableDefaults, deriveRect, derived, exportAnnotations, fromAnnotation, importAnnotations, importEmbeddedPage, importedId, invertMatrix, isAbandonedNote, isInkError, isKnown, isReply, isThreadRoot, mergeLineRects, multiplyMatrix, normaliseInk, normalizeColor, openDocument, parsePdfDate, pdfColorToHex, pdfNameSet, placeSignature, pointsFromFlat, quadFromRect, quadsFromFlat, readonly, recogniseStroke, rectContainsPoint, rectFromPoints, rectFromQuad, rectsIntersect, repliesTo, staticDefaults, styleGroupOf, styleGroupOfType, styleGroupsOf, summarise, supportedProps, threadOf, threadRoot, toFields, translateQuad, translateRect, typesInGroup, unionRects, version, withoutReplies, writable };
135
135
 
136
136
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../src/model/annotations/snapshot-history.ts","../src/index.ts"],"sourcesContent":["import { isProduction } from '../env'\nimport { derived, writable, type Readable } from '../readable'\n\nimport type { Annotation } from './types'\n\nexport interface SnapshotHistoryOptions {\n /** Proposes a list to the host. The step counts once the host applies it (seen by `observe`). */\n apply: (list: Annotation[]) => void\n /** Read on every observed change and every undo or redo. */\n enabled: () => boolean\n /** Steps kept. Default 200. */\n limit?: number | undefined\n}\n\n/**\n * Snapshot undo and redo over a host-owned annotation list, for controlled hosts. The\n * framework calls `observe` whenever the host's list changes; every change is a step. Undo and\n * redo propose an earlier list through `apply` and move the stacks only once the host applies\n * it. `canUndo` and `canRedo` report stack sizes; the framework ANDs them with its own flag.\n */\nexport interface SnapshotHistory {\n readonly canUndo: Readable<boolean>\n readonly canRedo: Readable<boolean>\n undo(): void\n redo(): void\n clear(): void\n /**\n * The host's current list, or `undefined` when the host does not control it. The first list\n * seeds the history; each later list that differs is a step. An `undefined` neither seeds\n * nor records, and the next list after one starts again without a step.\n */\n observe(list: readonly Annotation[] | undefined): void\n /**\n * Runs `fn` and records the host's changes that follow as one step. A framework may hand the\n * host's list back after `fn` returns, one list per proposal, so the batch stays open until\n * the current macrotask ends (`setTimeout(0)`) and then pushes a single step from the list\n * before `fn` to the latest one. Limit: an unrelated change the host makes in that same window\n * is folded into the step. Nested calls join; a throwing `fn` still closes the batch; when\n * history is disabled `fn` only runs. `fn` must be synchronous; a dev build warns when it\n * returns a promise.\n *\n * A batch opened while an earlier one is still settling closes the earlier one first, so the\n * two are two steps. An undo or redo still in flight (proposed, but not yet applied by the\n * host) when a batch opens is dropped: the host's list that follows counts toward the batch.\n * Undo and redo close a settling batch first. Calling `undo()` or `redo()` inside `fn` is not\n * supported.\n */\n batch(fn: () => void): void\n}\n\ntype Snapshot = readonly Annotation[]\ntype Pending = { kind: 'undo' | 'redo'; target: Snapshot }\n\nexport function createSnapshotHistory(opts: SnapshotHistoryOptions): SnapshotHistory {\n const limit = Math.max(1, opts.limit ?? 200)\n const past = writable<Snapshot[]>([])\n const future = writable<Snapshot[]>([])\n let pending: Pending | null = null\n /** Copy of the host's list as of its last change; `undefined` before the first list. */\n let current: Snapshot | undefined\n /** Open `batch` calls, and whether the batch is waiting out the task for late observes. */\n let depth = 0\n let settling: ReturnType<typeof setTimeout> | null = null\n /** The host's list when the outermost batch opened. */\n let from: Snapshot | undefined\n\n function endBatch(): void {\n if (settling !== null) clearTimeout(settling)\n settling = null\n const start = from\n from = undefined\n if (!opts.enabled() || !start || !current || sameList(current, start)) return\n past.set([...past.get(), start].slice(-limit))\n future.set([])\n }\n\n function batch(fn: () => void): void {\n if (!opts.enabled()) {\n fn()\n return\n }\n if (depth === 0) {\n // A batch still settling is closed first, so two batches are two steps.\n if (settling !== null) endBatch()\n // An undo or redo still in flight would be folded into this step; drop it.\n pending = null\n from = current\n }\n depth++\n try {\n const result: unknown = fn()\n if (\n result !== null &&\n typeof result === 'object' &&\n typeof (result as { then?: unknown }).then === 'function' &&\n !isProduction()\n ) {\n console.warn(\n '[inkbar] history.batch(fn): fn returned a promise. Changes after its first await are not part of the batch.'\n )\n }\n } finally {\n depth--\n if (depth === 0) settling = setTimeout(endBatch, 0)\n }\n }\n\n function clear(): void {\n past.set([])\n future.set([])\n pending = null\n from = undefined\n if (settling !== null) clearTimeout(settling)\n settling = null\n }\n\n function observe(next: readonly Annotation[] | undefined): void {\n const prev = current\n current = snapshot(next)\n if (!opts.enabled()) {\n // Steps taken while disabled are unknown to the stacks, which would undo to stale lists.\n if (past.get().length > 0 || future.get().length > 0 || pending) clear()\n return\n }\n // The first list only seeds; there is no step from or to an undefined list.\n if (next === undefined || prev === undefined) return\n // Inside a batch, or while it settles, changes only move `current`; `endBatch` pushes the step.\n if (from !== undefined) return\n // A new array with the same content is not a step, and leaves a pending step alone.\n if (sameList(next, prev)) return\n const step = pending\n pending = null\n if (step && sameList(next, step.target)) {\n if (step.kind === 'undo') {\n past.set(past.get().slice(0, -1))\n future.set([...future.get(), prev])\n } else {\n future.set(future.get().slice(0, -1))\n past.set([...past.get(), prev])\n }\n return\n }\n past.set([...past.get(), prev].slice(-limit))\n future.set([])\n }\n\n function propose(kind: Pending['kind'], target: Snapshot | undefined): void {\n if (!opts.enabled() || !target) return\n pending = { kind, target }\n opts.apply(clone(target) as Annotation[])\n }\n\n return {\n canUndo: derived(past, (p) => p.length > 0),\n canRedo: derived(future, (f) => f.length > 0),\n undo: () => {\n if (from !== undefined && depth === 0) endBatch()\n propose('undo', past.get().at(-1))\n },\n redo: () => {\n if (from !== undefined && depth === 0) endBatch()\n propose('redo', future.get().at(-1))\n },\n clear,\n observe,\n batch,\n }\n}\n\nfunction snapshot(list: readonly Annotation[] | undefined): Snapshot | undefined {\n return list === undefined ? undefined : clone(list)\n}\n\n/** Annotations are JSON values; this also strips framework proxies and `undefined` members. */\nfunction clone<T>(value: T): T {\n return JSON.parse(JSON.stringify(value)) as T\n}\n\n/** Same annotations in the same order, compared by payload; `modifiedAt` may be re-stamped. */\nfunction sameList(a: readonly Annotation[], b: readonly Annotation[]): boolean {\n return a.length === b.length && a.every((x, i) => sameIgnoringModifiedAt(x, b[i]!))\n}\n\nfunction sameIgnoringModifiedAt(a: Annotation, b: Annotation): boolean {\n const { modifiedAt: _a, ...restA } = a\n const { modifiedAt: _b, ...restB } = b\n return deepEqual(restA, restB)\n}\n\n/** Structural equality over JSON values; keys whose value is `undefined` count as absent. */\nfunction deepEqual(a: unknown, b: unknown): boolean {\n if (Object.is(a, b)) return true\n if (typeof a !== 'object' || typeof b !== 'object' || a === null || b === null)\n return false\n if (Array.isArray(a) !== Array.isArray(b)) return false\n const ka = presentKeys(a)\n const kb = presentKeys(b)\n if (ka.length !== kb.length) return false\n return ka.every(\n (k) =>\n kb.includes(k) &&\n deepEqual((a as Record<string, unknown>)[k], (b as Record<string, unknown>)[k])\n )\n}\n\nfunction presentKeys(o: object): string[] {\n return Object.keys(o).filter((k) => (o as Record<string, unknown>)[k] !== undefined)\n}\n","/** Replaced at build time (tsdown) and in tests (vitest) with package.json's version. */\ndeclare const __INKBAR_VERSION__: string\n\n/** The @inkbar/core version, from its package.json. */\nexport const version: string = __INKBAR_VERSION__\n\nexport * from './model/errors'\nexport * from './model/events'\nexport * from './model/geometry'\nexport * from './model/readable'\nexport { mergeLineRects } from './model/selection'\n\nexport { openDocument } from './model/document'\nexport type {\n DocumentInfo,\n DocumentStatus,\n InkDocument,\n InkStatus,\n OpenOptions,\n} from './model/document'\nexport type { DocumentSource } from './model/source'\nexport type { PageInfo, PageRotation } from './model/pages'\nexport type { TextContent, TextItem } from './model/text'\nexport type { PdfAssets } from './pdfjs/types'\nexport * from './model/annotations/types'\nexport { FringeSchema, type Fringe } from './model/annotations/callout'\nexport * from './model/annotations/pdf-names'\nexport * from './model/annotations/defaults'\nexport * from './model/annotations/store'\nexport * from './model/annotations/history'\nexport { createToolStyle, STYLE_GROUPS } from './model/annotations/tool-style'\nexport type {\n CurrentStyle,\n ScopedToolStyle,\n StyleGroup,\n StyleKey,\n StyleProps,\n ToolStyle,\n ToolStyleDeps,\n} from './model/annotations/tool-style'\nexport {\n fromAnnotation,\n styleGroupOf,\n styleGroupOfType,\n styleGroupsOf,\n supportedProps,\n toFields,\n typesInGroup,\n} from './model/annotations/style-map'\nexport { createSnapshotHistory } from './model/annotations/snapshot-history'\nexport type {\n SnapshotHistory,\n SnapshotHistoryOptions,\n} from './model/annotations/snapshot-history'\nexport { acceptSuggestion } from './model/annotations/suggestions'\nexport {\n isAbandonedNote,\n isReply,\n isThreadRoot,\n repliesTo,\n threadOf,\n threadRoot,\n withoutReplies,\n} from './model/annotations/threads'\nexport type { ThreadRoot } from './model/annotations/threads'\nexport * from './model/annotations/embedded'\nexport { parsePdfDate } from './model/pdf-date'\nexport { exportAnnotations, importAnnotations } from './model/annotations/json'\nexport { recogniseStroke, RECOGNISE_THRESHOLD } from './model/recognise'\nexport type { Recognised } from './model/recognise'\nexport type { ImportOptions, ImportResult } from './model/annotations/json'\nexport {\n createImageTemplate,\n createInkTemplate,\n createLocalSignatureStore,\n createMemorySignatureStore,\n createSignatureLibrary,\n DEFAULT_SIGNATURE_WIDTH,\n normaliseInk,\n placeSignature,\n SIGNATURE_INK_WIDTH,\n} from './model/signatures'\nexport type {\n SignatureLibrary,\n SignatureOptions,\n SignatureStore,\n SignatureTemplate,\n} from './model/signatures'\n"],"mappings":";;AAqDA,SAAgB,sBAAsB,MAA+C;CACnF,MAAM,QAAQ,KAAK,IAAI,GAAG,KAAK,SAAS,GAAG;CAC3C,MAAM,OAAO,SAAqB,CAAC,CAAC;CACpC,MAAM,SAAS,SAAqB,CAAC,CAAC;CACtC,IAAI,UAA0B;;CAE9B,IAAI;;CAEJ,IAAI,QAAQ;CACZ,IAAI,WAAiD;;CAErD,IAAI;CAEJ,SAAS,WAAiB;EACxB,IAAI,aAAa,M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,GAAG,MAAM,uBAAuB,GAAG,EAAE,EAAG,CAAC;AACpF;AAEA,SAAS,uBAAuB,GAAe,GAAwB;CACrE,MAAM,EAAE,YAAY,IAAI,GAAG,UAAU;CACrC,MAAM,EAAE,YAAY,IAAI,GAAG,UAAU;CACrC,OAAO,UAAU,OAAO,KAAK;AAC/B;;AAGA,SAAS,UAAU,GAAY,GAAqB;CAClD,IAAI,OAAO,GAAG,GAAG,CAAC,GAAG,OAAO;CAC5B,IAAI,OAAO,MAAM,YAAY,OAAO,MAAM,YAAY,MAAM,QAAQ,MAAM,MACxE,OAAO;CACT,IAAI,MAAM,QAAQ,CAAC,MAAM,MAAM,QAAQ,CAAC,GAAG,OAAO;CAClD,MAAM,KAAK,YAAY,CAAC;CACxB,MAAM,KAAK,YAAY,CAAC;CACxB,IAAI,GAAG,WAAW,GAAG,QAAQ,OAAO;CACpC,OAAO,GAAG,OACP,MACC,GAAG,SAAS,CAAC,KACb,UAAW,EAA8B,IAAK,EAA8B,EAAE,CAClF;AACF;AAEA,SAAS,YAAY,GAAqB;CACxC,OAAO,OAAO,KAAK,CAAC,CAAC,CAAC,QAAQ,MAAO,EAA8B,OAAO,KAAA,CAAS;AACrF;;;;AC3MA,MAAa,UAAA"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/model/annotations/snapshot-history.ts","../src/index.ts"],"sourcesContent":["import { isProduction } from '../env'\nimport { derived, writable, type Readable } from '../readable'\n\nimport type { Annotation } from './types'\n\nexport interface SnapshotHistoryOptions {\n /** Proposes a list to the host. The step counts once the host applies it (seen by `observe`). */\n apply: (list: Annotation[]) => void\n /** Read on every observed change and every undo or redo. */\n enabled: () => boolean\n /** Steps kept. Default 200. */\n limit?: number | undefined\n}\n\n/**\n * Snapshot undo and redo over a host-owned annotation list, for controlled hosts. The\n * framework calls `observe` whenever the host's list changes; every change is a step. Undo and\n * redo propose an earlier list through `apply` and move the stacks only once the host applies\n * it. `canUndo` and `canRedo` report stack sizes; the framework ANDs them with its own flag.\n */\nexport interface SnapshotHistory {\n readonly canUndo: Readable<boolean>\n readonly canRedo: Readable<boolean>\n undo(): void\n redo(): void\n clear(): void\n /**\n * The host's current list, or `undefined` when the host does not control it. The first list\n * seeds the history; each later list that differs is a step. An `undefined` neither seeds\n * nor records, and the next list after one starts again without a step.\n */\n observe(list: readonly Annotation[] | undefined): void\n /**\n * Runs `fn` and records the host's changes that follow as one step. A framework may hand the\n * host's list back after `fn` returns, one list per proposal, so the batch stays open until\n * the current macrotask ends (`setTimeout(0)`) and then pushes a single step from the list\n * before `fn` to the latest one. Limit: an unrelated change the host makes in that same window\n * is folded into the step. Nested calls join; a throwing `fn` still closes the batch; when\n * history is disabled `fn` only runs. `fn` must be synchronous; a dev build warns when it\n * returns a promise.\n *\n * A batch opened while an earlier one is still settling closes the earlier one first, so the\n * two are two steps. An undo or redo still in flight (proposed, but not yet applied by the\n * host) when a batch opens is dropped: the host's list that follows counts toward the batch.\n * Undo and redo close a settling batch first. Calling `undo()` or `redo()` inside `fn` is not\n * supported.\n */\n batch(fn: () => void): void\n}\n\ntype Snapshot = readonly Annotation[]\ntype Pending = { kind: 'undo' | 'redo'; target: Snapshot }\n\nexport function createSnapshotHistory(opts: SnapshotHistoryOptions): SnapshotHistory {\n const limit = Math.max(1, opts.limit ?? 200)\n const past = writable<Snapshot[]>([])\n const future = writable<Snapshot[]>([])\n let pending: Pending | null = null\n /** Copy of the host's list as of its last change; `undefined` before the first list. */\n let current: Snapshot | undefined\n /** Open `batch` calls, and whether the batch is waiting out the task for late observes. */\n let depth = 0\n let settling: ReturnType<typeof setTimeout> | null = null\n /** The host's list when the outermost batch opened. */\n let from: Snapshot | undefined\n\n function endBatch(): void {\n if (settling !== null) clearTimeout(settling)\n settling = null\n const start = from\n from = undefined\n if (!opts.enabled() || !start || !current || sameList(current, start)) return\n past.set([...past.get(), start].slice(-limit))\n future.set([])\n }\n\n function batch(fn: () => void): void {\n if (!opts.enabled()) {\n fn()\n return\n }\n if (depth === 0) {\n // A batch still settling is closed first, so two batches are two steps.\n if (settling !== null) endBatch()\n // An undo or redo still in flight would be folded into this step; drop it.\n pending = null\n from = current\n }\n depth++\n try {\n const result: unknown = fn()\n if (\n result !== null &&\n typeof result === 'object' &&\n typeof (result as { then?: unknown }).then === 'function' &&\n !isProduction()\n ) {\n console.warn(\n '[inkbar] history.batch(fn): fn returned a promise. Changes after its first await are not part of the batch.'\n )\n }\n } finally {\n depth--\n if (depth === 0) settling = setTimeout(endBatch, 0)\n }\n }\n\n function clear(): void {\n past.set([])\n future.set([])\n pending = null\n from = undefined\n if (settling !== null) clearTimeout(settling)\n settling = null\n }\n\n function observe(next: readonly Annotation[] | undefined): void {\n const prev = current\n current = snapshot(next)\n if (!opts.enabled()) {\n // Steps taken while disabled are unknown to the stacks, which would undo to stale lists.\n if (past.get().length > 0 || future.get().length > 0 || pending) clear()\n return\n }\n // The first list only seeds; there is no step from or to an undefined list.\n if (next === undefined || prev === undefined) return\n // Inside a batch, or while it settles, changes only move `current`; `endBatch` pushes the step.\n if (from !== undefined) return\n // A new array with the same content is not a step, and leaves a pending step alone.\n if (sameList(next, prev)) return\n const step = pending\n pending = null\n if (step && sameList(next, step.target)) {\n if (step.kind === 'undo') {\n past.set(past.get().slice(0, -1))\n future.set([...future.get(), prev])\n } else {\n future.set(future.get().slice(0, -1))\n past.set([...past.get(), prev])\n }\n return\n }\n past.set([...past.get(), prev].slice(-limit))\n future.set([])\n }\n\n function propose(kind: Pending['kind'], target: Snapshot | undefined): void {\n if (!opts.enabled() || !target) return\n pending = { kind, target }\n opts.apply(clone(target) as Annotation[])\n }\n\n return {\n canUndo: derived(past, (p) => p.length > 0),\n canRedo: derived(future, (f) => f.length > 0),\n undo: () => {\n if (from !== undefined && depth === 0) endBatch()\n propose('undo', past.get().at(-1))\n },\n redo: () => {\n if (from !== undefined && depth === 0) endBatch()\n propose('redo', future.get().at(-1))\n },\n clear,\n observe,\n batch,\n }\n}\n\nfunction snapshot(list: readonly Annotation[] | undefined): Snapshot | undefined {\n return list === undefined ? undefined : clone(list)\n}\n\n/** Annotations are JSON values; this also strips framework proxies and `undefined` members. */\nfunction clone<T>(value: T): T {\n return JSON.parse(JSON.stringify(value)) as T\n}\n\n/** Same annotations in the same order, compared by payload; `modifiedAt` may be re-stamped. */\nfunction sameList(a: readonly Annotation[], b: readonly Annotation[]): boolean {\n return a.length === b.length && a.every((x, i) => sameIgnoringModifiedAt(x, b[i]!))\n}\n\nfunction sameIgnoringModifiedAt(a: Annotation, b: Annotation): boolean {\n const { modifiedAt: _a, ...restA } = a\n const { modifiedAt: _b, ...restB } = b\n return deepEqual(restA, restB)\n}\n\n/** Structural equality over JSON values; keys whose value is `undefined` count as absent. */\nfunction deepEqual(a: unknown, b: unknown): boolean {\n if (Object.is(a, b)) return true\n if (typeof a !== 'object' || typeof b !== 'object' || a === null || b === null)\n return false\n if (Array.isArray(a) !== Array.isArray(b)) return false\n const ka = presentKeys(a)\n const kb = presentKeys(b)\n if (ka.length !== kb.length) return false\n return ka.every(\n (k) =>\n kb.includes(k) &&\n deepEqual((a as Record<string, unknown>)[k], (b as Record<string, unknown>)[k])\n )\n}\n\nfunction presentKeys(o: object): string[] {\n return Object.keys(o).filter((k) => (o as Record<string, unknown>)[k] !== undefined)\n}\n","/** Replaced at build time (tsdown) and in tests (vitest) with package.json's version. */\ndeclare const __INKBAR_VERSION__: string\n\n/** The @inkbar/core version, from its package.json. */\nexport const version: string = __INKBAR_VERSION__\n\nexport * from './model/errors'\nexport * from './model/events'\nexport * from './model/geometry'\nexport * from './model/readable'\nexport { mergeLineRects } from './model/selection'\n\nexport { openDocument } from './model/document'\nexport type {\n DocumentInfo,\n DocumentStatus,\n InkDocument,\n InkStatus,\n OpenOptions,\n} from './model/document'\nexport type { DocumentSource } from './model/source'\nexport type { PageInfo, PageRotation } from './model/pages'\nexport type { TextContent, TextItem } from './model/text'\nexport type { PdfAssets } from './pdfjs/types'\nexport * from './model/annotations/types'\nexport { FringeSchema, type Fringe } from './model/annotations/callout'\nexport * from './model/annotations/pdf-names'\nexport * from './model/annotations/defaults'\nexport * from './model/annotations/store'\nexport * from './model/annotations/history'\nexport { createToolStyle, STYLE_GROUPS } from './model/annotations/tool-style'\nexport type {\n CurrentStyle,\n ScopedToolStyle,\n StyleGroup,\n StyleKey,\n StyleProps,\n ToolStyle,\n ToolStyleDeps,\n} from './model/annotations/tool-style'\nexport {\n fromAnnotation,\n styleGroupOf,\n styleGroupOfType,\n styleGroupsOf,\n supportedProps,\n toFields,\n typesInGroup,\n} from './model/annotations/style-map'\nexport { createSnapshotHistory } from './model/annotations/snapshot-history'\nexport type {\n SnapshotHistory,\n SnapshotHistoryOptions,\n} from './model/annotations/snapshot-history'\nexport {\n isAbandonedNote,\n isReply,\n isThreadRoot,\n repliesTo,\n threadOf,\n threadRoot,\n withoutReplies,\n} from './model/annotations/threads'\nexport type { ThreadRoot } from './model/annotations/threads'\nexport * from './model/annotations/embedded'\nexport { parsePdfDate } from './model/pdf-date'\nexport { exportAnnotations, importAnnotations } from './model/annotations/json'\nexport { recogniseStroke, RECOGNISE_THRESHOLD } from './model/recognise'\nexport type { Recognised } from './model/recognise'\nexport type { ImportOptions, ImportResult } from './model/annotations/json'\nexport {\n createImageTemplate,\n createInkTemplate,\n createLocalSignatureStore,\n createMemorySignatureStore,\n createSignatureLibrary,\n DEFAULT_SIGNATURE_WIDTH,\n normaliseInk,\n placeSignature,\n SIGNATURE_INK_WIDTH,\n} from './model/signatures'\nexport type {\n SignatureLibrary,\n SignatureOptions,\n SignatureStore,\n SignatureTemplate,\n} from './model/signatures'\n"],"mappings":";;AAqDA,SAAgB,sBAAsB,MAA+C;CACnF,MAAM,QAAQ,KAAK,IAAI,GAAG,KAAK,SAAS,GAAG;CAC3C,MAAM,OAAO,SAAqB,CAAC,CAAC;CACpC,MAAM,SAAS,SAAqB,CAAC,CAAC;CACtC,IAAI,UAA0B;;CAE9B,IAAI;;CAEJ,IAAI,QAAQ;CACZ,IAAI,WAAiD;;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