@quillmark/wasm 0.133.0 → 0.134.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.
@@ -19,7 +19,8 @@ import initCore, { Quill, Document } from '../core/wasm.js';
19
19
  // itself), a `node:fs` read under Node, whose `fetch` rejects `file:` URLs.
20
20
  // Resolution-time, so `node:fs` never enters a browser graph.
21
21
  import { toModuleSource } from '#quillmark-env';
22
- import { importMarkdown, exportMarkdown, normalize, rebase, mapPos, mapMarks } from '../core/wasm.js';
22
+ import { importMarkdown, exportMarkdown, normalize, invert, diff } from '../core/wasm.js';
23
+ import { splitBlock, joinBlocks, deleteRange, indent, outdent, wrap, inheritedMarks, mapPos } from '../core/wasm.js';
23
24
  import { isInline, isPlain } from '../core/wasm.js';
24
25
  import { parseDocPath, formatDocPath, formatDiagnostic } from '../core/wasm.js';
25
26
 
@@ -48,9 +49,16 @@ const CORE_SURFACE = Object.freeze({
48
49
  importMarkdown,
49
50
  exportMarkdown,
50
51
  normalize,
51
- rebase,
52
+ invert,
53
+ diff,
54
+ splitBlock,
55
+ joinBlocks,
56
+ deleteRange,
57
+ indent,
58
+ outdent,
59
+ wrap,
60
+ inheritedMarks,
52
61
  mapPos,
53
- mapMarks,
54
62
  isInline,
55
63
  isPlain,
56
64
  parseDocPath,
@@ -321,50 +329,16 @@ function requireLocalQuill(quill, method) {
321
329
  throw notLocal(quill, method, 'Quill');
322
330
  }
323
331
 
324
- // WELD_KEYS is the rule `Container::same_weld` owns upstream: which `attrs`
325
- // entries two adjacent runs must share for the markdown projection to read them
326
- // as one. `start` is not among them, since CommonMark reads only a list's first
327
- // number — a subset, which is why every container needs its own entry.
328
- //
329
- // Re-spelled here rather than called, because `assignInstances` answers before
330
- // wasm initializes (`prose/canon/BINDINGS.md` § "WebAssembly"). What holds the
331
- // two spellings equal is running the rule, not comparing their sources:
332
- // `runtime.test.js` § "container run boundaries" stamps a pair and re-imports
333
- // it, where `Content::normalize` re-mints against the Rust predicate. A tag the
334
- // table omits welds with nothing, so `tests/known_names_drift.rs` pins that
335
- // every container has an entry.
336
-
337
- const WELD_KEYS = { list_item: ['ordered'], quote: [] };
338
-
339
332
  /**
340
- * @param {import('../core/wasm.js').ContentContainer} a
341
- * @param {import('../core/wasm.js').ContentContainer} b
342
- * @returns {boolean}
343
- */
344
- function weldsWith(a, b) {
345
- // A malformed value welds with nothing: answer rather than throw.
346
- if (typeof a?.container !== 'string' || a.container !== b?.container) return false;
347
- // `hasOwn`, so a tag colliding with an `Object.prototype` member answers
348
- // `false` rather than reaching a function.
349
- if (!Object.hasOwn(WELD_KEYS, a.container)) return false;
350
- return WELD_KEYS[a.container].every((k) => a.attrs?.[k] === b.attrs?.[k]);
351
- }
352
-
353
- /**
354
- * @param {(import('../core/wasm.js').ContentContainer | null)[]} runs
355
- * @returns {(import('../core/wasm.js').ContentContainer | null)[]}
333
+ * Throw unless `quill` and `doc` are both THIS copy's.
334
+ * @param {unknown} quill
335
+ * @param {unknown} doc
336
+ * @param {string} method
337
+ * @returns {void}
356
338
  */
357
- export function assignInstances(runs) {
358
- let prev = null;
359
- return runs.map((run) => {
360
- if (run == null) {
361
- prev = null;
362
- return null;
363
- }
364
- const instance = prev && weldsWith(prev, run) ? 1 - prev.instance : 0;
365
- prev = { ...run, instance };
366
- return prev;
367
- });
339
+ function requireLocalBind(quill, doc, method) {
340
+ requireLocalQuill(quill, method);
341
+ requireLocalDoc(doc, method);
368
342
  }
369
343
 
370
344
  /**
@@ -751,9 +725,6 @@ export class LiveSession {
751
725
  get pageCount() {
752
726
  return this.#inner.pageCount;
753
727
  }
754
- get backendId() {
755
- return this.#inner.backendId;
756
- }
757
728
  get warnings() {
758
729
  return this.#inner.warnings;
759
730
  }
@@ -856,13 +827,22 @@ export class DocumentWriter {
856
827
  * @param {Document} doc the document to mutate, held by reference (not owned)
857
828
  */
858
829
  constructor(quill, doc) {
859
- requireLocalQuill(quill, 'quill.writer(doc)');
860
- requireLocalDoc(doc, 'quill.writer(doc)');
830
+ requireLocalBind(quill, doc, 'quill.writer(doc)');
861
831
  this.#quill = quill;
862
832
  this.#doc = doc;
863
833
  }
864
- get document() {
865
- return this.#doc;
834
+ /**
835
+ * @returns {string}
836
+ */
837
+ hash() {
838
+ return this.#doc._hash(this.#quill);
839
+ }
840
+ /**
841
+ * @param {import('../core/wasm.js').Addr | string} addr
842
+ * @returns {string}
843
+ */
844
+ hashAt(addr) {
845
+ return this.#doc._hashAt(this.#quill, addr);
866
846
  }
867
847
  /**
868
848
  * @param {string} name
@@ -881,25 +861,28 @@ export class DocumentWriter {
881
861
  }
882
862
  /**
883
863
  * @param {string} markdown
864
+ * @param {import('../core/wasm.js').BaseOptions} [opts]
884
865
  * @returns {import('../core/wasm.js').Revised}
885
866
  */
886
- reviseBody(markdown) {
887
- return this.#doc.revise({}, markdown);
867
+ reviseBody(markdown, opts) {
868
+ return this.#doc._revise({}, markdown, opts);
888
869
  }
889
870
  /**
890
871
  * @param {string} name
891
872
  * @param {string} text
873
+ * @param {import('../core/wasm.js').BaseOptions} [opts]
892
874
  * @returns {import('../core/wasm.js').Revised}
893
875
  */
894
- reviseField(name, text) {
895
- return this.#doc._reviseField(this.#quill, name, text);
876
+ reviseField(name, text, opts) {
877
+ return this.#doc._reviseField(this.#quill, name, text, opts);
896
878
  }
897
879
  /**
898
880
  * @param {string} markdown
881
+ * @param {import('../core/wasm.js').BaseOptions} [opts]
899
882
  * @returns {import('../core/wasm.js').DocumentRevised}
900
883
  */
901
- reviseDocument(markdown) {
902
- return this.#doc._reviseDocument(this.#quill, markdown);
884
+ reviseDocument(markdown, opts) {
885
+ return this.#doc._reviseDocument(this.#quill, markdown, opts);
903
886
  }
904
887
  /**
905
888
  * @param {string} kind
@@ -937,20 +920,17 @@ export class CardWriter {
937
920
  * @param {number} index the composable card's index
938
921
  */
939
922
  constructor(quill, doc, index) {
940
- requireLocalQuill(quill, 'writer.card(index)');
941
- requireLocalDoc(doc, 'writer.card(index)');
923
+ requireLocalBind(quill, doc, 'writer.card(index)');
942
924
  this.#quill = quill;
943
925
  this.#doc = doc;
944
926
  this.#index = index;
945
927
  }
946
- get index() {
947
- return this.#index;
948
- }
949
928
  /**
929
+ * @param {string} [field]
950
930
  * @returns {string}
951
931
  */
952
- get kind() {
953
- return this.#doc.card(this.#index).kind;
932
+ hashAt(field) {
933
+ return this.#doc._hashAt(this.#quill, { card: this.#index, field });
954
934
  }
955
935
  /**
956
936
  * @param {string} name
@@ -969,18 +949,20 @@ export class CardWriter {
969
949
  }
970
950
  /**
971
951
  * @param {string} markdown
952
+ * @param {import('../core/wasm.js').BaseOptions} [opts]
972
953
  * @returns {import('../core/wasm.js').Revised}
973
954
  */
974
- reviseBody(markdown) {
975
- return this.#doc.revise({ card: this.#index }, markdown);
955
+ reviseBody(markdown, opts) {
956
+ return this.#doc._revise({ card: this.#index }, markdown, opts);
976
957
  }
977
958
  /**
978
959
  * @param {string} name
979
960
  * @param {string} text
961
+ * @param {import('../core/wasm.js').BaseOptions} [opts]
980
962
  * @returns {import('../core/wasm.js').Revised}
981
963
  */
982
- reviseField(name, text) {
983
- return this.#doc._reviseField(this.#quill, { card: this.#index, field: name }, text);
964
+ reviseField(name, text, opts) {
965
+ return this.#doc._reviseField(this.#quill, { card: this.#index, field: name }, text, opts);
984
966
  }
985
967
  }
986
968
 
@@ -1008,14 +990,10 @@ export class DocumentReader {
1008
990
  * @param {Document} doc the document to read, held by reference (not owned)
1009
991
  */
1010
992
  constructor(quill, doc) {
1011
- requireLocalQuill(quill, 'quill.reader(doc)');
1012
- requireLocalDoc(doc, 'quill.reader(doc)');
993
+ requireLocalBind(quill, doc, 'quill.reader(doc)');
1013
994
  this.#quill = quill;
1014
995
  this.#doc = doc;
1015
996
  }
1016
- get document() {
1017
- return this.#doc;
1018
- }
1019
997
  /**
1020
998
  * @param {import('../core/wasm.js').Addr | string} addr
1021
999
  * @returns {unknown}
@@ -1051,68 +1029,6 @@ export class DocumentReader {
1051
1029
  resolve(today) {
1052
1030
  return this.#quill._resolve(this.#doc, today);
1053
1031
  }
1054
- /**
1055
- * @param {number} index
1056
- * @returns {CardReader}
1057
- */
1058
- card(index) {
1059
- return new CardReader(this.#quill, this.#doc, index);
1060
- }
1061
- }
1062
-
1063
- export class CardReader {
1064
- #quill;
1065
- #doc;
1066
- #index;
1067
- /**
1068
- * @param {Quill} quill the schema source
1069
- * @param {Document} doc the document to read, held by reference (not owned)
1070
- * @param {number} index the composable card's index
1071
- */
1072
- constructor(quill, doc, index) {
1073
- requireLocalQuill(quill, 'reader.card(index)');
1074
- requireLocalDoc(doc, 'reader.card(index)');
1075
- this.#quill = quill;
1076
- this.#doc = doc;
1077
- this.#index = index;
1078
- }
1079
- get index() {
1080
- return this.#index;
1081
- }
1082
- /**
1083
- * @returns {string}
1084
- */
1085
- get kind() {
1086
- return this.#doc.card(this.#index).kind;
1087
- }
1088
- /**
1089
- * @param {string} name
1090
- * @returns {unknown}
1091
- */
1092
- get(name) {
1093
- return this.#doc._readerGet(this.#quill, { card: this.#index, field: name });
1094
- }
1095
- /**
1096
- * @param {string} name
1097
- * @returns {import('../core/wasm.js').Content | undefined}
1098
- */
1099
- getContent(name) {
1100
- return this.#doc._readerGetContent(this.#quill, { card: this.#index, field: name });
1101
- }
1102
- /**
1103
- * @param {string} name
1104
- * @param {import('../core/wasm.js').PathStep[]} path
1105
- * @returns {import('../core/wasm.js').Content | undefined}
1106
- */
1107
- getContentAt(name, path) {
1108
- return this.#doc._readerGetContentAt(this.#quill, { card: this.#index, field: name }, path);
1109
- }
1110
- /**
1111
- * @returns {string}
1112
- */
1113
- bodyMarkdown() {
1114
- return this.#doc._readerGet(this.#quill, { card: this.#index });
1115
- }
1116
1032
  }
1117
1033
 
1118
1034
  // Patched onto the same re-exported `Quill` prototype as `writer`.