@inkbar/core 0.5.0 → 0.7.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/README.md +111 -1
- package/dist/dom.d.mts +597 -40
- package/dist/dom.d.mts.map +1 -1
- package/dist/dom.mjs +2154 -436
- package/dist/dom.mjs.map +1 -1
- package/dist/index.d.mts +16 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +181 -25
- package/dist/index.mjs.map +1 -1
- package/dist/{signatures-BwaXi7C8.d.mts → signatures-CalOktkf.d.mts} +148 -13
- package/dist/signatures-CalOktkf.d.mts.map +1 -0
- package/dist/{signatures-CMapTKrC.mjs → signatures-Do_l2IlM.mjs} +882 -56
- package/dist/signatures-Do_l2IlM.mjs.map +1 -0
- package/package.json +4 -3
- package/dist/signatures-BwaXi7C8.d.mts.map +0 -1
- package/dist/signatures-CMapTKrC.mjs.map +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as
|
|
1
|
+
import { $ as RecordChange, $t as PolySchema, A as SearchHit, An as quadFromRect, At as FreeTextSchema, B as exportAnnotations, Bn as unionRects, Bt as LineAnnotation, C as DocumentInfo, Cn as Quad, Ct as AnnotationSchema, D as OpenOptions, Dn as invertMatrix, Dt as ExportedAnnotationSchema, E as InkStatus, En as approxEqual, Et as ExportedAnnotation, F as InkError, Fn as rectFromQuad, Ft as GLOSS_SCHEMA_ID, G as AnnotationChange, Gt as LoupeSchema, H as History, Ht as LineEndingSchema, I as InkErrorCode, In as rectFromQuads, It as GLOSS_VERSION, J as StoreMode, Jt as NoteAnnotation, K as AnnotationEdit, Kt as MaskAnnotation, L as isInkError, Ln as rectsIntersect, Lt as IMAGE_DATA_URL, M as SearchResults, Mn as quadsFromRect, Mt as FreeTextStyleSchema, N as TextContent, Nn as rectContainsPoint, Nt as GLOSS_FORMAT, O as openDocument, On as multiplyMatrix, Ot as ForeignAnnotation, P as TextItem, Pn as rectFromPoints, Pt as GLOSS_MEDIA_TYPE, Q as RecordBase, Qt as PolyAnnotation, R as ImportOptions, Rn as translateQuad, Rt as InkAnnotation, S as createToolStyle, Sn as Point, St as AnnotationPatch, T as InkDocument, Tn as applyMatrix, Tt as CircleSchema, U as PluginHistory, Ut as LineSchema, V as importAnnotations, Vt as LineEnding, W as createHistory, Wt as LoupeAnnotation, X as createAnnotationStore, Xt as NoteSchema, Y as StoreOptions, Yt as NoteIconSchema, Z as deriveRect, Zt as PointSchema, _ as StyleGroup, _n as writable, _t as Annotation, a as SignatureStore, an as RedactSchema, at as EmbeddedTarget, b as ToolStyle, bn as PdfAssets, bt as AnnotationInput, c as createInkTemplate, cn as SquareSchema, ct as importedId, d as createSignatureLibrary, dn as TextMarkupAnnotation, dt as Fringe, en as PolygonSchema, et as RecordStore, f as normaliseInk, fn as TextMarkupSchema, ft as FringeSchema, g as ScopedToolStyle, gn as readonly, gt as staticDefaults, h as STYLE_GROUPS, hn as derived, ht as normalizeColor, i as SignatureOptions, in as RedactAnnotation, it as EmbeddedSummary, j as SearchOptions, jn as quadsFromFlat, jt as FreeTextStyle, k as DocumentSource, kn as pointsFromFlat, kt as FreeTextAnnotation, l as createLocalSignatureStore, ln as StampAnnotation, lt as pdfColorToHex, m as CurrentStyle, mn as Writable, mt as cssVariableDefaults, n as SIGNATURE_INK_WIDTH, nn as QuadSchema, nt as createRecordStore, o as SignatureTemplate, on as ShapeAnnotation, ot as SUPPORTED_SUBTYPES, p as placeSignature, pn as Readable, pt as AnnotationDefaults, q as AnnotationStore, qt as MaskSchema, r as SignatureLibrary, rn as RectSchema, rt as EmbeddedFieldPatch, s as createImageTemplate, sn as ShapeSchema, st as importEmbeddedPage, t as DEFAULT_SIGNATURE_WIDTH, tn as PolylineSchema, tt as RecordStoreOptions, u as createMemorySignatureStore, un as StampSchema, ut as summarise, v as StyleKey, vn as PageInfo, vt as AnnotationDocument, w as DocumentStatus, wn as Rect, wt as AnnotationType, x as ToolStyleDeps, xn as Matrix, xt as AnnotationOfType, y as StyleProps, yn as PageRotation, yt as AnnotationDocumentSchema, z as ImportResult, zn as translateRect, zt as InkSchema } from "./signatures-CalOktkf.mjs";
|
|
2
2
|
import { INTENTS, LINE_ENDINGS, NOTE_ICONS, PDF_NAME } from "gloss-format";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
//#region src/model/events.d.ts
|
|
@@ -72,8 +72,15 @@ interface SnapshotHistoryOptions {
|
|
|
72
72
|
* framework calls `observe` whenever the host's list changes; every change is a step. Undo and
|
|
73
73
|
* redo propose an earlier list through `apply` and move the stacks only once the host applies
|
|
74
74
|
* it. `canUndo` and `canRedo` report stack sizes; the framework ANDs them with its own flag.
|
|
75
|
+
*
|
|
76
|
+
* Tracked record stores belong to their plugins, not the host, so a step also snapshots each of
|
|
77
|
+
* them. Undo and redo put records back at once (`replaceAll(list, 'history')`) and propose the
|
|
78
|
+
* annotations as above; a step whose annotations did not change moves the stacks at once. A
|
|
79
|
+
* record change outside a batch opens one, so the change and the host's list that follows in
|
|
80
|
+
* the same macrotask are one step. A record store's `reset` takes its records out of every step
|
|
81
|
+
* and drops the steps left with nothing to undo; the others still undo and redo, as in History.
|
|
75
82
|
*/
|
|
76
|
-
interface SnapshotHistory {
|
|
83
|
+
interface SnapshotHistory extends PluginHistory {
|
|
77
84
|
readonly canUndo: Readable<boolean>;
|
|
78
85
|
readonly canRedo: Readable<boolean>;
|
|
79
86
|
undo(): void;
|
|
@@ -101,6 +108,12 @@ interface SnapshotHistory {
|
|
|
101
108
|
* supported.
|
|
102
109
|
*/
|
|
103
110
|
batch(fn: () => void): void;
|
|
111
|
+
/**
|
|
112
|
+
* Runs the reactions for each of the store's user edits inside a batch, so what they change
|
|
113
|
+
* joins the edit's step. Undo and redo reach the store as a `replace`, which reacts to nothing.
|
|
114
|
+
* The binding attaches each opened document's store. Returns a function that detaches it.
|
|
115
|
+
*/
|
|
116
|
+
attach(store: AnnotationStore): () => void;
|
|
104
117
|
}
|
|
105
118
|
export declare function createSnapshotHistory(opts: SnapshotHistoryOptions): SnapshotHistory;
|
|
106
119
|
//#endregion
|
|
@@ -177,5 +190,5 @@ export declare function recogniseStroke(points: readonly Point[]): {
|
|
|
177
190
|
/** The @inkbar/core version, from its package.json. */
|
|
178
191
|
export declare const version: string;
|
|
179
192
|
//#endregion
|
|
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 };
|
|
193
|
+
export { Annotation, AnnotationChange, AnnotationDefaults, AnnotationDocument, AnnotationDocumentSchema, AnnotationEdit, 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, PluginHistory, Point, PointSchema, PolyAnnotation, PolySchema, PolygonSchema, PolylineSchema, Quad, QuadSchema, Readable, type Recognised, RecordBase, RecordChange, RecordStore, RecordStoreOptions, Rect, RectSchema, RedactAnnotation, RedactSchema, SIGNATURE_INK_WIDTH, STYLE_GROUPS, SUPPORTED_SUBTYPES, type ScopedToolStyle, type SearchHit, type SearchOptions, type SearchResults, 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, createRecordStore, createSignatureLibrary, createToolStyle, cssVariableDefaults, deriveRect, derived, exportAnnotations, importAnnotations, importEmbeddedPage, importedId, invertMatrix, isInkError, multiplyMatrix, normaliseInk, normalizeColor, openDocument, pdfColorToHex, placeSignature, pointsFromFlat, quadFromRect, quadsFromFlat, quadsFromRect, readonly, rectContainsPoint, rectFromPoints, rectFromQuad, rectFromQuads, rectsIntersect, staticDefaults, summarise, translateQuad, translateRect, unionRects, writable };
|
|
181
194
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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;;;
|
|
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;;;UCpM9B;;EAEf,QAAQ,MAAM;;EAEd;;EAEA;;;;;;;;;;;;;;;UAgBe,wBAAwB;WAC9B,SAAS;WACT,SAAS;EAClB;EACA;EACA;;;;;;EAMA,QAAQ,eAAe;;;;;;;;;;;;;;;;EAgBvB,MAAM;;;;;;EAMN,OAAO,OAAO;;wBAcA,sBAAsB,MAAM,yBAAyB;;;;KCxEzD,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,5 +1,6 @@
|
|
|
1
|
-
import { $ as
|
|
1
|
+
import { $ as exportAnnotations, $t as createRecordStore, A as styleGroupOf, At as QuadSchema, C as repliesTo, Ct as MaskSchema, D as STYLE_GROUPS, Dt as PolySchema, E as withoutReplies, Et as PointSchema, F as typesInGroup, Ft as StampSchema, Gt as PDF_NAME, Ht as INTENTS, It as TextMarkupSchema, Jt as parsePdfDate, Kt as isKnown, Lt as FringeSchema, M as styleGroupsOf, Mt as RedactSchema, N as supportedProps, Nt as ShapeSchema, O as createToolStyle, Ot as PolygonSchema, P as toFields, Pt as SquareSchema, Q as deriveRect, Qt as mergeLineRects, S as isThreadRoot, St as LoupeSchema, T as threadRoot, Tt as NoteSchema, Ut as LINE_ENDINGS, Wt as NOTE_ICONS, Xt as normalizeColor, Y as openDocument, Yt as cssVariableDefaults, Z as createAnnotationStore, Zt as staticDefaults, _n as translateRect, _t as GLOSS_VERSION, a as createLocalSignatureStore, an as invertMatrix, at as importedId, b as isAbandonedNote, bn as InkError, bt as LineEndingSchema, c as normaliseInk, cn as quadFromRect, ct as AnnotationDocumentSchema, d as recogniseStroke, dn as rectContainsPoint, dt as ExportedAnnotationSchema, en as derived, et as importAnnotations, fn as rectFromPoints, ft as FreeTextSchema, gn as translateQuad, gt as GLOSS_SCHEMA_ID, hn as rectsIntersect, ht as GLOSS_MEDIA_TYPE, i as createInkTemplate, in as approxEqual, it as importEmbeddedPage, j as styleGroupOfType, jt as RectSchema, k as fromAnnotation, kt as PolylineSchema, l as placeSignature, ln as quadsFromFlat, lt as AnnotationSchema, mn as rectFromQuads, mt as GLOSS_FORMAT, n as SIGNATURE_INK_WIDTH, nn as writable, nt as isProduction, o as createMemorySignatureStore, on as multiplyMatrix, ot as pdfColorToHex, pn as rectFromQuad, pt as FreeTextStyleSchema, qt as pdfNameSet, r as createImageTemplate, rn as applyMatrix, rt as SUPPORTED_SUBTYPES, s as createSignatureLibrary, sn as pointsFromFlat, st as summarise, t as DEFAULT_SIGNATURE_WIDTH, tn as readonly, tt as createHistory, u as RECOGNISE_THRESHOLD, un as quadsFromRect, ut as CircleSchema, vn as unionRects, vt as IMAGE_DATA_URL, w as threadOf, wt as NoteIconSchema, x as isReply, xn as isInkError, xt as LineSchema, yn as Emitter, yt as InkSchema } from "./signatures-Do_l2IlM.mjs";
|
|
2
2
|
//#region src/model/annotations/snapshot-history.ts
|
|
3
|
+
const noop = () => {};
|
|
3
4
|
function createSnapshotHistory(opts) {
|
|
4
5
|
const limit = Math.max(1, opts.limit ?? 200);
|
|
5
6
|
const past = writable([]);
|
|
@@ -10,27 +11,99 @@ function createSnapshotHistory(opts) {
|
|
|
10
11
|
/** Open `batch` calls, and whether the batch is waiting out the task for late observes. */
|
|
11
12
|
let depth = 0;
|
|
12
13
|
let settling = null;
|
|
13
|
-
/** The
|
|
14
|
+
/** The state when the outermost batch opened; `undefined` while no list has been seen. */
|
|
14
15
|
let from;
|
|
16
|
+
/** Each tracked store with its list as of the last change history saw. */
|
|
17
|
+
const tracked = /* @__PURE__ */ new Map();
|
|
18
|
+
const reactions = /* @__PURE__ */ new Set();
|
|
19
|
+
/** Each attached store with its `edit` unsubscribe. */
|
|
20
|
+
const attached = /* @__PURE__ */ new Map();
|
|
21
|
+
/** Set while undo or redo puts records back, so those changes are not steps. */
|
|
22
|
+
let replaying = false;
|
|
23
|
+
function records() {
|
|
24
|
+
return new Map([...tracked].map(([s, t]) => [s, t.previous]));
|
|
25
|
+
}
|
|
26
|
+
function state() {
|
|
27
|
+
return current === void 0 ? void 0 : {
|
|
28
|
+
annotations: current,
|
|
29
|
+
records: records()
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function push(step) {
|
|
33
|
+
past.set([...past.get(), step].slice(-limit));
|
|
34
|
+
future.set([]);
|
|
35
|
+
}
|
|
36
|
+
/** Moves the stacks for an undo or redo that has landed; `prev` is the state it left. */
|
|
37
|
+
function move(kind, prev) {
|
|
38
|
+
if (kind === "undo") {
|
|
39
|
+
past.set(past.get().slice(0, -1));
|
|
40
|
+
future.set([...future.get(), prev]);
|
|
41
|
+
} else {
|
|
42
|
+
future.set(future.get().slice(0, -1));
|
|
43
|
+
past.set([...past.get(), prev]);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* After `store`'s reset: drops the steps that changed nothing but `store`, and gives every
|
|
48
|
+
* remaining snapshot its new `list`, so undo and redo leave its records alone while a step
|
|
49
|
+
* that also changed annotations or another store still undoes those, as in History. `was` is
|
|
50
|
+
* its list just before the reset. Undo targets lose the snapshot before a dropped step, redo
|
|
51
|
+
* targets the one after it.
|
|
52
|
+
*/
|
|
53
|
+
function dropSteps(store, was, list) {
|
|
54
|
+
const now = current && {
|
|
55
|
+
annotations: current,
|
|
56
|
+
records: records().set(store, was)
|
|
57
|
+
};
|
|
58
|
+
/** Whether the step from `a` to `b` changed only this store, so nothing is left of it. */
|
|
59
|
+
const onlyStore = (a, b) => {
|
|
60
|
+
if (!b) return false;
|
|
61
|
+
const x = a.records.get(store);
|
|
62
|
+
const y = b.records.get(store);
|
|
63
|
+
if (x === void 0 || y === void 0 || sameRecords(x, y)) return false;
|
|
64
|
+
if (!sameList(a.annotations, b.annotations)) return false;
|
|
65
|
+
return [...a.records].every(([s, list]) => s === store || sameRecords(list, b.records.get(s) ?? list));
|
|
66
|
+
};
|
|
67
|
+
const renewed = /* @__PURE__ */ new Map();
|
|
68
|
+
const renew = (step) => {
|
|
69
|
+
const next = step.records.has(store) ? {
|
|
70
|
+
...step,
|
|
71
|
+
records: new Map(step.records).set(store, list)
|
|
72
|
+
} : step;
|
|
73
|
+
renewed.set(step, next);
|
|
74
|
+
return next;
|
|
75
|
+
};
|
|
76
|
+
const p = past.get();
|
|
77
|
+
past.set(p.filter((step, i) => !onlyStore(step, p[i + 1] ?? now)).map(renew));
|
|
78
|
+
const f = future.get();
|
|
79
|
+
future.set(f.filter((step, i) => !onlyStore(step, f[i + 1] ?? now)).map(renew));
|
|
80
|
+
const target = pending && renewed.get(pending.target);
|
|
81
|
+
pending = pending && target ? {
|
|
82
|
+
...pending,
|
|
83
|
+
target,
|
|
84
|
+
records: new Map(pending.records).set(store, list)
|
|
85
|
+
} : null;
|
|
86
|
+
}
|
|
87
|
+
/** Opens the outermost batch from the current state. */
|
|
88
|
+
function open() {
|
|
89
|
+
if (settling !== null) endBatch();
|
|
90
|
+
pending = null;
|
|
91
|
+
from = state();
|
|
92
|
+
}
|
|
15
93
|
function endBatch() {
|
|
16
94
|
if (settling !== null) clearTimeout(settling);
|
|
17
95
|
settling = null;
|
|
18
96
|
const start = from;
|
|
19
97
|
from = void 0;
|
|
20
|
-
if (!opts.enabled() || !start || !current
|
|
21
|
-
|
|
22
|
-
future.set([]);
|
|
98
|
+
if (!opts.enabled() || !start || !current) return;
|
|
99
|
+
if (!(sameList(current, start.annotations) && [...start.records].every(([s, list]) => sameRecords(list, tracked.get(s)?.previous ?? list)))) push(start);
|
|
23
100
|
}
|
|
24
101
|
function batch(fn) {
|
|
25
102
|
if (!opts.enabled()) {
|
|
26
103
|
fn();
|
|
27
104
|
return;
|
|
28
105
|
}
|
|
29
|
-
if (depth === 0)
|
|
30
|
-
if (settling !== null) endBatch();
|
|
31
|
-
pending = null;
|
|
32
|
-
from = current;
|
|
33
|
-
}
|
|
106
|
+
if (depth === 0) open();
|
|
34
107
|
depth++;
|
|
35
108
|
try {
|
|
36
109
|
const result = fn();
|
|
@@ -60,26 +133,82 @@ function createSnapshotHistory(opts) {
|
|
|
60
133
|
if (sameList(next, prev)) return;
|
|
61
134
|
const step = pending;
|
|
62
135
|
pending = null;
|
|
63
|
-
if (step && sameList(next, step.target)) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
future.set(future.get().slice(0, -1));
|
|
69
|
-
past.set([...past.get(), prev]);
|
|
70
|
-
}
|
|
136
|
+
if (step && sameList(next, step.target.annotations)) {
|
|
137
|
+
move(step.kind, {
|
|
138
|
+
annotations: prev,
|
|
139
|
+
records: step.records
|
|
140
|
+
});
|
|
71
141
|
return;
|
|
72
142
|
}
|
|
73
|
-
|
|
74
|
-
|
|
143
|
+
push({
|
|
144
|
+
annotations: prev,
|
|
145
|
+
records: records()
|
|
146
|
+
});
|
|
75
147
|
}
|
|
76
148
|
function propose(kind, target) {
|
|
77
149
|
if (!opts.enabled() || !target) return;
|
|
150
|
+
const before = pending && pending.kind === kind && pending.target === target ? pending.records : records();
|
|
151
|
+
replaying = true;
|
|
152
|
+
try {
|
|
153
|
+
for (const [s, list] of target.records) {
|
|
154
|
+
const t = tracked.get(s);
|
|
155
|
+
if (t && !sameRecords(t.previous, list)) s.replaceAll([...list], "history");
|
|
156
|
+
}
|
|
157
|
+
} finally {
|
|
158
|
+
replaying = false;
|
|
159
|
+
}
|
|
160
|
+
if (current !== void 0 && sameList(current, target.annotations)) {
|
|
161
|
+
move(kind, {
|
|
162
|
+
annotations: current,
|
|
163
|
+
records: before
|
|
164
|
+
});
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
78
167
|
pending = {
|
|
79
168
|
kind,
|
|
80
|
-
target
|
|
169
|
+
target,
|
|
170
|
+
records: before
|
|
171
|
+
};
|
|
172
|
+
opts.apply(clone(target.annotations));
|
|
173
|
+
}
|
|
174
|
+
function track(store) {
|
|
175
|
+
if (tracked.has(store)) return noop;
|
|
176
|
+
const unsubscribe = store.on("change", (change) => {
|
|
177
|
+
const t = tracked.get(store);
|
|
178
|
+
if (!t) return;
|
|
179
|
+
const list = store.list.get();
|
|
180
|
+
if (replaying || change.kind === "replace" && change.reason === "history") {
|
|
181
|
+
t.previous = list;
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
if (!opts.enabled()) {
|
|
185
|
+
t.previous = list;
|
|
186
|
+
if (past.get().length > 0 || future.get().length > 0 || pending) clear();
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
if (change.kind === "replace") {
|
|
190
|
+
dropSteps(store, t.previous, list);
|
|
191
|
+
t.previous = list;
|
|
192
|
+
from?.records.set(store, list);
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
if (from === void 0 && depth === 0 && current !== void 0) {
|
|
196
|
+
open();
|
|
197
|
+
settling = setTimeout(endBatch, 0);
|
|
198
|
+
}
|
|
199
|
+
t.previous = list;
|
|
200
|
+
});
|
|
201
|
+
tracked.set(store, {
|
|
202
|
+
previous: store.list.get(),
|
|
203
|
+
unsubscribe
|
|
204
|
+
});
|
|
205
|
+
from?.records.set(store, store.list.get());
|
|
206
|
+
return () => {
|
|
207
|
+
if (tracked.get(store)?.unsubscribe !== unsubscribe) return;
|
|
208
|
+
unsubscribe();
|
|
209
|
+
tracked.delete(store);
|
|
210
|
+
from?.records.delete(store);
|
|
81
211
|
};
|
|
82
|
-
opts.apply(clone(target));
|
|
83
212
|
}
|
|
84
213
|
return {
|
|
85
214
|
canUndo: derived(past, (p) => p.length > 0),
|
|
@@ -94,9 +223,36 @@ function createSnapshotHistory(opts) {
|
|
|
94
223
|
},
|
|
95
224
|
clear,
|
|
96
225
|
observe,
|
|
97
|
-
batch
|
|
226
|
+
batch,
|
|
227
|
+
track,
|
|
228
|
+
react(fn) {
|
|
229
|
+
const run = (edit) => fn(edit);
|
|
230
|
+
reactions.add(run);
|
|
231
|
+
return () => {
|
|
232
|
+
reactions.delete(run);
|
|
233
|
+
};
|
|
234
|
+
},
|
|
235
|
+
attach(store) {
|
|
236
|
+
if (attached.has(store)) return noop;
|
|
237
|
+
const off = store.on("edit", (edit) => {
|
|
238
|
+
if (reactions.size === 0) return;
|
|
239
|
+
batch(() => {
|
|
240
|
+
for (const fn of [...reactions]) fn(edit);
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
attached.set(store, off);
|
|
244
|
+
return () => {
|
|
245
|
+
if (attached.get(store) !== off) return;
|
|
246
|
+
attached.delete(store);
|
|
247
|
+
off();
|
|
248
|
+
};
|
|
249
|
+
}
|
|
98
250
|
};
|
|
99
251
|
}
|
|
252
|
+
/** The same records in the same order; records are frozen, so identity is enough. */
|
|
253
|
+
function sameRecords(a, b) {
|
|
254
|
+
return a === b || a.length === b.length && a.every((x, i) => x === b[i]);
|
|
255
|
+
}
|
|
100
256
|
function snapshot(list) {
|
|
101
257
|
return list === void 0 ? void 0 : clone(list);
|
|
102
258
|
}
|
|
@@ -129,8 +285,8 @@ function presentKeys(o) {
|
|
|
129
285
|
//#endregion
|
|
130
286
|
//#region src/index.ts
|
|
131
287
|
/** The @inkbar/core version, from its package.json. */
|
|
132
|
-
const version = "0.
|
|
288
|
+
const version = "0.7.0";
|
|
133
289
|
//#endregion
|
|
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 };
|
|
290
|
+
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, createRecordStore, 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, quadsFromRect, readonly, recogniseStroke, rectContainsPoint, rectFromPoints, rectFromQuad, rectFromQuads, rectsIntersect, repliesTo, staticDefaults, styleGroupOf, styleGroupOfType, styleGroupsOf, summarise, supportedProps, threadOf, threadRoot, toFields, translateQuad, translateRect, typesInGroup, unionRects, version, withoutReplies, writable };
|
|
135
291
|
|
|
136
292
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -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 {\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,CAA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AC7B,OAAO,KAAK,MAAM,KAAK,UAAU,KAAK,CAAC;AACzC;;AAGA,SAAS,SAAS,GAA0B,GAAmC;CAC7E,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,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 { RecordBase, RecordStore } from '../records'\nimport type { PluginHistory } from './history'\nimport type { AnnotationEdit, AnnotationStore } from './store'\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 *\n * Tracked record stores belong to their plugins, not the host, so a step also snapshots each of\n * them. Undo and redo put records back at once (`replaceAll(list, 'history')`) and propose the\n * annotations as above; a step whose annotations did not change moves the stacks at once. A\n * record change outside a batch opens one, so the change and the host's list that follows in\n * the same macrotask are one step. A record store's `reset` takes its records out of every step\n * and drops the steps left with nothing to undo; the others still undo and redo, as in History.\n */\nexport interface SnapshotHistory extends PluginHistory {\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 * Runs the reactions for each of the store's user edits inside a batch, so what they change\n * joins the edit's step. Undo and redo reach the store as a `replace`, which reacts to nothing.\n * The binding attaches each opened document's store. Returns a function that detaches it.\n */\n attach(store: AnnotationStore): () => void\n}\n\ntype Records = Map<RecordStore<RecordBase>, readonly RecordBase[]>\n/** The host's list and each tracked store's list at one point. */\ninterface Snapshot {\n annotations: readonly Annotation[]\n records: Records\n}\n/** An undo or redo waiting for the host, with the records as they stood before it. */\ntype Pending = { kind: 'undo' | 'redo'; target: Snapshot; records: Records }\n\nconst noop = () => {}\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: readonly Annotation[] | 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 state when the outermost batch opened; `undefined` while no list has been seen. */\n let from: Snapshot | undefined\n /** Each tracked store with its list as of the last change history saw. */\n const tracked = new Map<\n RecordStore<RecordBase>,\n { previous: readonly RecordBase[]; unsubscribe: () => void }\n >()\n const reactions = new Set<(edit: AnnotationEdit) => void>()\n /** Each attached store with its `edit` unsubscribe. */\n const attached = new Map<AnnotationStore, () => void>()\n /** Set while undo or redo puts records back, so those changes are not steps. */\n let replaying = false\n\n function records(): Records {\n return new Map([...tracked].map(([s, t]) => [s, t.previous]))\n }\n\n function state(): Snapshot | undefined {\n return current === undefined\n ? undefined\n : { annotations: current, records: records() }\n }\n\n function push(step: Snapshot): void {\n past.set([...past.get(), step].slice(-limit))\n future.set([])\n }\n\n /** Moves the stacks for an undo or redo that has landed; `prev` is the state it left. */\n function move(kind: Pending['kind'], prev: Snapshot): void {\n if (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 }\n\n /**\n * After `store`'s reset: drops the steps that changed nothing but `store`, and gives every\n * remaining snapshot its new `list`, so undo and redo leave its records alone while a step\n * that also changed annotations or another store still undoes those, as in History. `was` is\n * its list just before the reset. Undo targets lose the snapshot before a dropped step, redo\n * targets the one after it.\n */\n function dropSteps(\n store: RecordStore<RecordBase>,\n was: readonly RecordBase[],\n list: readonly RecordBase[]\n ): void {\n // The state now, with the store's list from before the reset.\n const now = current && { annotations: current, records: records().set(store, was) }\n /** Whether the step from `a` to `b` changed only this store, so nothing is left of it. */\n const onlyStore = (a: Snapshot, b: Snapshot | undefined) => {\n if (!b) return false\n const x = a.records.get(store)\n const y = b.records.get(store)\n if (x === undefined || y === undefined || sameRecords(x, y)) return false\n if (!sameList(a.annotations, b.annotations)) return false\n return [...a.records].every(\n ([s, list]) => s === store || sameRecords(list, b.records.get(s) ?? list)\n )\n }\n const renewed = new Map<Snapshot, Snapshot>()\n const renew = (step: Snapshot): Snapshot => {\n const next = step.records.has(store)\n ? { ...step, records: new Map(step.records).set(store, list) }\n : step\n renewed.set(step, next)\n return next\n }\n // Oldest first, then the state now: each undo target is the snapshot before a step.\n const p = past.get()\n past.set(p.filter((step, i) => !onlyStore(step, p[i + 1] ?? now)).map(renew))\n // Next redo last: each redo target is the snapshot after a step.\n const f = future.get()\n future.set(f.filter((step, i) => !onlyStore(step, f[i + 1] ?? now)).map(renew))\n // An undo or redo in flight still lands when its target survived.\n const target = pending && renewed.get(pending.target)\n pending =\n pending && target\n ? { ...pending, target, records: new Map(pending.records).set(store, list) }\n : null\n }\n\n /** Opens the outermost batch from the current state. */\n function open(): void {\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 = state()\n }\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) return\n const unchanged =\n sameList(current, start.annotations) &&\n [...start.records].every(([s, list]) =>\n sameRecords(list, tracked.get(s)?.previous ?? list)\n )\n if (!unchanged) push(start)\n }\n\n function batch(fn: () => void): void {\n if (!opts.enabled()) {\n fn()\n return\n }\n if (depth === 0) open()\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.annotations)) {\n move(step.kind, { annotations: prev, records: step.records })\n return\n }\n push({ annotations: prev, records: records() })\n }\n\n function propose(kind: Pending['kind'], target: Snapshot | undefined): void {\n if (!opts.enabled() || !target) return\n // The same undo or redo again before the host applies: the records were already put back,\n // so the state it leaves is the one the first call saw.\n const before =\n pending && pending.kind === kind && pending.target === target\n ? pending.records\n : records()\n replaying = true\n try {\n // Stores no longer tracked keep their records.\n for (const [s, list] of target.records) {\n const t = tracked.get(s)\n if (t && !sameRecords(t.previous, list)) s.replaceAll([...list], 'history')\n }\n } finally {\n replaying = false\n }\n // Nothing for the host to apply: the step moves now.\n if (current !== undefined && sameList(current, target.annotations)) {\n move(kind, { annotations: current, records: before })\n return\n }\n pending = { kind, target, records: before }\n opts.apply(clone(target.annotations) as Annotation[])\n }\n\n function track(store: RecordStore<RecordBase>): () => void {\n if (tracked.has(store)) return noop\n const unsubscribe = store.on('change', (change) => {\n const t = tracked.get(store)\n if (!t) return\n const list = store.list.get()\n // Our own replays (and any other history replace) never become steps.\n if (replaying || (change.kind === 'replace' && change.reason === 'history')) {\n t.previous = list\n return\n }\n if (!opts.enabled()) {\n t.previous = list\n // As in `observe`: steps taken while disabled would leave the stacks stale.\n if (past.get().length > 0 || future.get().length > 0 || pending) clear()\n return\n }\n if (change.kind === 'replace') {\n // A reset starts the store over, so no older step holding its records can be replayed.\n dropSteps(store, t.previous, list)\n t.previous = list\n from?.records.set(store, list)\n return\n }\n // On its own, a change opens a batch from the state before it, which waits out the task\n // for the host's list.\n if (from === undefined && depth === 0 && current !== undefined) {\n open()\n settling = setTimeout(endBatch, 0)\n }\n t.previous = list\n })\n tracked.set(store, { previous: store.list.get(), unsubscribe })\n // Tracked inside an open batch: the batch covers it from here.\n from?.records.set(store, store.list.get())\n return () => {\n if (tracked.get(store)?.unsubscribe !== unsubscribe) return\n unsubscribe()\n tracked.delete(store)\n from?.records.delete(store)\n }\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 track,\n react(fn) {\n // Wrapped, so the same function added twice runs twice and each handle removes its own.\n const run = (edit: AnnotationEdit) => fn(edit)\n reactions.add(run)\n return () => {\n reactions.delete(run)\n }\n },\n attach(store) {\n if (attached.has(store)) return noop\n const off = store.on('edit', (edit) => {\n if (reactions.size === 0) return\n batch(() => {\n for (const fn of [...reactions]) fn(edit)\n })\n })\n attached.set(store, off)\n // An old handle never detaches a later attachment of the same store.\n return () => {\n if (attached.get(store) !== off) return\n attached.delete(store)\n off()\n }\n },\n }\n}\n\n/** The same records in the same order; records are frozen, so identity is enough. */\nfunction sameRecords(a: readonly RecordBase[], b: readonly RecordBase[]): boolean {\n return a === b || (a.length === b.length && a.every((x, i) => x === b[i]))\n}\n\nfunction snapshot(\n list: readonly Annotation[] | undefined\n): readonly Annotation[] | 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 * from './model/records'\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 { SearchHit, SearchOptions, SearchResults } from './model/search'\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":";;AA2EA,MAAM,aAAa,CAAC;AAEpB,SAAgB,sBAAsB,MAA+C;CACnF,MAAM,QAAQ,KAAK,IAAI,GAAG,KAAK,SAAS,GAA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