@quillmark/wasm 0.67.0 → 0.69.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.
@@ -531,7 +531,7 @@ export class Quill {
531
531
  *
532
532
  * [`Form::cards`]: quillmark::form::Form::cards
533
533
  * @param {string} card_type
534
- * @returns {any}
534
+ * @returns {FormCard | null}
535
535
  */
536
536
  blankCard(card_type) {
537
537
  try {
@@ -558,7 +558,7 @@ export class Quill {
558
558
  * the schema declares a default) or `"missing"`.
559
559
  *
560
560
  * [`Form::main`]: quillmark::form::Form::main
561
- * @returns {any}
561
+ * @returns {FormCard}
562
562
  */
563
563
  blankMain() {
564
564
  try {
@@ -594,7 +594,7 @@ export class Quill {
594
594
  *
595
595
  * [`Form`]: quillmark::form::Form
596
596
  * @param {Document} doc
597
- * @returns {any}
597
+ * @returns {Form}
598
598
  */
599
599
  form(doc) {
600
600
  try {
@@ -636,7 +636,7 @@ export class Quill {
636
636
  *
637
637
  * Equivalent by value for the lifetime of the handle; the quill is
638
638
  * immutable once constructed.
639
- * @returns {any}
639
+ * @returns {QuillMetadata}
640
640
  */
641
641
  get metadata() {
642
642
  const ret = wasm.quill_metadata(this.__wbg_ptr);
@@ -685,6 +685,19 @@ export class Quill {
685
685
  wasm.__wbindgen_add_to_stack_pointer(16);
686
686
  }
687
687
  }
688
+ /**
689
+ * Whether this quill's backend supports canvas preview.
690
+ *
691
+ * `true` iff `RenderSession.paint` and `RenderSession.pageSize` will
692
+ * succeed for sessions opened by this quill. Use this as a precondition
693
+ * probe before mounting a canvas-based preview UI; the throw on `paint`
694
+ * remains the enforcement contract.
695
+ * @returns {boolean}
696
+ */
697
+ get supportsCanvas() {
698
+ const ret = wasm.quill_supportsCanvas(this.__wbg_ptr);
699
+ return ret !== 0;
700
+ }
688
701
  }
689
702
  if (Symbol.dispose) Quill.prototype[Symbol.dispose] = Quill.prototype.free;
690
703
 
@@ -739,6 +752,21 @@ export class Quillmark {
739
752
  }
740
753
  if (Symbol.dispose) Quillmark.prototype[Symbol.dispose] = Quillmark.prototype.free;
741
754
 
755
+ /**
756
+ * An iterative render handle backed by an immutable compiled snapshot.
757
+ *
758
+ * Created via [`Quill::open`]. Holds the compiled output so that
759
+ * [`RenderSession::render`], [`RenderSession::paint`], and
760
+ * [`RenderSession::page_size`] can be called repeatedly without
761
+ * recompiling.
762
+ *
763
+ * **Empty documents.** A document that compiles to zero pages still
764
+ * produces a valid session (`pageCount === 0`). Iterating
765
+ * `0..pageCount` is then a no-op; calling `paint(ctx, 0)` or
766
+ * `pageSize(0)` throws `"... page index 0 out of range
767
+ * (pageCount=0)"`. Hosts that surface "no pages to preview" UI should
768
+ * branch on `pageCount === 0` rather than on a thrown error.
769
+ */
742
770
  export class RenderSession {
743
771
  static __wrap(ptr) {
744
772
  ptr = ptr >>> 0;
@@ -759,6 +787,9 @@ export class RenderSession {
759
787
  }
760
788
  /**
761
789
  * The backend that produced this session (e.g. `"typst"`).
790
+ *
791
+ * Equal to the `backendId` of the [`Quill`] that opened this session
792
+ * (sessions inherit their quill's backend), so checking either is fine.
762
793
  * @returns {string}
763
794
  */
764
795
  get backendId() {
@@ -791,6 +822,11 @@ export class RenderSession {
791
822
  /**
792
823
  * Page dimensions in Typst points (1 pt = 1/72 inch).
793
824
  *
825
+ * Report-only: the painter sizes the canvas itself based on
826
+ * `PaintOptions`. Exposed for consumers that need page geometry
827
+ * up-front (e.g. to lay out a scrollable list of canvases before
828
+ * any pixels are rendered).
829
+ *
794
830
  * Stable for a given `page` across the session's lifetime — the
795
831
  * compiled document is an immutable snapshot, so callers can cache
796
832
  * results.
@@ -818,41 +854,58 @@ export class RenderSession {
818
854
  /**
819
855
  * Paint `page` into a 2D canvas context.
820
856
  *
821
- * `scale` multiplies Typst's natural 72 ppi (1 pt 1 device pixel at
822
- * `scale = 1`). Typical usage:
823
- * `scale = (window.devicePixelRatio || 1) * userZoom`.
857
+ * Accepts either a `CanvasRenderingContext2D` (main thread) or an
858
+ * `OffscreenCanvasRenderingContext2D` (Worker / off-DOM rasterization).
859
+ * Both dispatch to the same Rust rasterizer; the dispatch happens at
860
+ * the JS boundary so neither context type is privileged.
861
+ *
862
+ * The painter owns `canvas.width` / `canvas.height` and writes them
863
+ * itself; consumers must not. The painter does not touch
864
+ * `canvas.style.*` — that's layout, owned by the consumer (see
865
+ * `PaintResult.layoutWidth` / `layoutHeight`).
824
866
  *
825
- * The caller must size `ctx.canvas` so that
826
- * `canvas.width === round(widthPt * scale)` and `canvas.height ===
827
- * round(heightPt * scale)` *before* calling `paint`. Setting
828
- * `canvas.width` / `canvas.height` clears the backing store, which is
829
- * the recommended way to handle page-to-page transitions; if you
830
- * reuse a canvas without resizing, call
831
- * `ctx.clearRect(0, 0, canvas.width, canvas.height)` first to avoid
832
- * stale pixels showing through transparent regions.
867
+ * `opts.layoutScale` (default 1.0) is layout-space pixels per Typst
868
+ * point and determines the canvas's display-box size. `opts.densityScale`
869
+ * (default 1.0) is the rasterization density multiplier the consumer
870
+ * folds `window.devicePixelRatio`, in-app zoom, and
871
+ * `visualViewport.scale` (pinch-zoom) into. The effective
872
+ * rasterization scale is `layoutScale * densityScale`.
833
873
  *
834
- * `paint` writes into the backing store at origin `(0, 0)` and does
835
- * not clear outside the rendered region.
874
+ * If `layoutScale * densityScale` would exceed the safe backing-store
875
+ * maximum (16384 px per side), `densityScale` is clamped
876
+ * proportionally so the largest dimension fits. The actual
877
+ * backing-store dimensions are reported in the returned
878
+ * `PaintResult` — compare against
879
+ * `round(layoutWidth * densityScale)` to detect clamping.
836
880
  *
837
- * Throws if the backend does not support canvas preview (the message
838
- * includes the resolved `backendId` for debugging), or if `page` is
839
- * out of range.
840
- * @param {CanvasRenderingContext2D} ctx
881
+ * Each call resets the backing store (`paint` is always a full
882
+ * repaint). Consumers do not need to call `clearRect`.
883
+ *
884
+ * Throws when:
885
+ * - the backend does not support canvas preview (message includes the
886
+ * resolved `backendId`),
887
+ * - `page` is out of range,
888
+ * - `ctx` is neither `CanvasRenderingContext2D` nor
889
+ * `OffscreenCanvasRenderingContext2D`,
890
+ * - `opts.layoutScale` or `opts.densityScale` is non-finite or `<= 0`.
891
+ * @param {CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D} ctx
841
892
  * @param {number} page
842
- * @param {number} scale
893
+ * @param {PaintOptions | undefined} opts
894
+ * @returns {PaintResult}
843
895
  */
844
- paint(ctx, page, scale) {
896
+ paint(ctx, page, opts) {
845
897
  try {
846
898
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
847
- wasm.rendersession_paint(retptr, this.__wbg_ptr, addBorrowedObject(ctx), page, scale);
899
+ wasm.rendersession_paint(retptr, this.__wbg_ptr, addHeapObject(ctx), page, addHeapObject(opts));
848
900
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
849
901
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
850
- if (r1) {
851
- throw takeObject(r0);
902
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
903
+ if (r2) {
904
+ throw takeObject(r1);
852
905
  }
906
+ return takeObject(r0);
853
907
  } finally {
854
908
  wasm.__wbindgen_add_to_stack_pointer(16);
855
- heap[stack_pointer++] = undefined;
856
909
  }
857
910
  }
858
911
  /**
@@ -875,6 +928,18 @@ export class RenderSession {
875
928
  wasm.__wbindgen_add_to_stack_pointer(16);
876
929
  }
877
930
  }
931
+ /**
932
+ * Whether this session's backend supports canvas preview.
933
+ *
934
+ * `true` iff [`paint`](Self::paint) and [`page_size`](Self::page_size)
935
+ * will succeed. Equal to `Quill.supportsCanvas` for the quill that
936
+ * opened this session.
937
+ * @returns {boolean}
938
+ */
939
+ get supportsCanvas() {
940
+ const ret = wasm.rendersession_supportsCanvas(this.__wbg_ptr);
941
+ return ret !== 0;
942
+ }
878
943
  /**
879
944
  * Session-level warnings attached at `quill.open(...)` time.
880
945
  *
@@ -997,6 +1062,14 @@ export function __wbg_call_14b169f759b26747() { return handleError(function (arg
997
1062
  const ret = getObject(arg0).call(getObject(arg1));
998
1063
  return addHeapObject(ret);
999
1064
  }, arguments); }
1065
+ export function __wbg_canvas_2c0c6d263d4c52ad(arg0) {
1066
+ const ret = getObject(arg0).canvas;
1067
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
1068
+ }
1069
+ export function __wbg_canvas_374da9f3c5b3dd0e(arg0) {
1070
+ const ret = getObject(arg0).canvas;
1071
+ return addHeapObject(ret);
1072
+ }
1000
1073
  export function __wbg_done_9158f7cc8751ba32(arg0) {
1001
1074
  const ret = getObject(arg0).done;
1002
1075
  return ret;
@@ -1073,6 +1146,16 @@ export function __wbg_instanceof_ArrayBuffer_7c8433c6ed14ffe3(arg0) {
1073
1146
  const ret = result;
1074
1147
  return ret;
1075
1148
  }
1149
+ export function __wbg_instanceof_CanvasRenderingContext2d_24a3fe06e62b98d7(arg0) {
1150
+ let result;
1151
+ try {
1152
+ result = getObject(arg0) instanceof CanvasRenderingContext2D;
1153
+ } catch (_) {
1154
+ result = false;
1155
+ }
1156
+ const ret = result;
1157
+ return ret;
1158
+ }
1076
1159
  export function __wbg_instanceof_Map_1b76fd4635be43eb(arg0) {
1077
1160
  let result;
1078
1161
  try {
@@ -1083,6 +1166,16 @@ export function __wbg_instanceof_Map_1b76fd4635be43eb(arg0) {
1083
1166
  const ret = result;
1084
1167
  return ret;
1085
1168
  }
1169
+ export function __wbg_instanceof_OffscreenCanvasRenderingContext2d_285a274020b4f230(arg0) {
1170
+ let result;
1171
+ try {
1172
+ result = getObject(arg0) instanceof OffscreenCanvasRenderingContext2D;
1173
+ } catch (_) {
1174
+ result = false;
1175
+ }
1176
+ const ret = result;
1177
+ return ret;
1178
+ }
1086
1179
  export function __wbg_instanceof_Uint8Array_152ba1f289edcf3f(arg0) {
1087
1180
  let result;
1088
1181
  try {
@@ -1167,6 +1260,9 @@ export function __wbg_prototypesetcall_a6b02eb00b0f4ce2(arg0, arg1, arg2) {
1167
1260
  export function __wbg_putImageData_c810e62ea70e761d() { return handleError(function (arg0, arg1, arg2, arg3) {
1168
1261
  getObject(arg0).putImageData(getObject(arg1), arg2, arg3);
1169
1262
  }, arguments); }
1263
+ export function __wbg_putImageData_cb4de9afd58963be() { return handleError(function (arg0, arg1, arg2, arg3) {
1264
+ getObject(arg0).putImageData(getObject(arg1), arg2, arg3);
1265
+ }, arguments); }
1170
1266
  export function __wbg_set_022bee52d0b05b19() { return handleError(function (arg0, arg1, arg2) {
1171
1267
  const ret = Reflect.set(getObject(arg0), getObject(arg1), getObject(arg2));
1172
1268
  return ret;
@@ -1184,6 +1280,18 @@ export function __wbg_set_fde2cec06c23692b(arg0, arg1, arg2) {
1184
1280
  const ret = getObject(arg0).set(getObject(arg1), getObject(arg2));
1185
1281
  return addHeapObject(ret);
1186
1282
  }
1283
+ export function __wbg_set_height_24d07d982f176ac6(arg0, arg1) {
1284
+ getObject(arg0).height = arg1 >>> 0;
1285
+ }
1286
+ export function __wbg_set_height_be9b2b920bd68401(arg0, arg1) {
1287
+ getObject(arg0).height = arg1 >>> 0;
1288
+ }
1289
+ export function __wbg_set_width_5cda41d4d06a14dd(arg0, arg1) {
1290
+ getObject(arg0).width = arg1 >>> 0;
1291
+ }
1292
+ export function __wbg_set_width_adc925bca9c5351a(arg0, arg1) {
1293
+ getObject(arg0).width = arg1 >>> 0;
1294
+ }
1187
1295
  export function __wbg_stack_3b0d974bbf31e44f(arg0, arg1) {
1188
1296
  const ret = getObject(arg1).stack;
1189
1297
  const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
@@ -1255,12 +1363,6 @@ function _assertClass(instance, klass) {
1255
1363
  }
1256
1364
  }
1257
1365
 
1258
- function addBorrowedObject(obj) {
1259
- if (stack_pointer == 1) throw new Error('out of js stack');
1260
- heap[--stack_pointer] = obj;
1261
- return stack_pointer;
1262
- }
1263
-
1264
1366
  function debugString(val) {
1265
1367
  // primitive types
1266
1368
  const type = typeof val;
@@ -1427,8 +1529,6 @@ function passStringToWasm0(arg, malloc, realloc) {
1427
1529
  return ptr;
1428
1530
  }
1429
1531
 
1430
- let stack_pointer = 1024;
1431
-
1432
1532
  function takeObject(idx) {
1433
1533
  const ret = getObject(idx);
1434
1534
  dropObject(idx);
Binary file
@@ -35,6 +35,7 @@ export const quill_form: (a: number, b: number, c: number) => void;
35
35
  export const quill_metadata: (a: number) => number;
36
36
  export const quill_open: (a: number, b: number, c: number) => void;
37
37
  export const quill_render: (a: number, b: number, c: number, d: number) => void;
38
+ export const quill_supportsCanvas: (a: number) => number;
38
39
  export const quillmark_new: () => number;
39
40
  export const quillmark_quill: (a: number, b: number, c: number) => void;
40
41
  export const rendersession_backendId: (a: number, b: number) => void;
@@ -42,6 +43,7 @@ export const rendersession_pageCount: (a: number) => number;
42
43
  export const rendersession_pageSize: (a: number, b: number, c: number) => void;
43
44
  export const rendersession_paint: (a: number, b: number, c: number, d: number, e: number) => void;
44
45
  export const rendersession_render: (a: number, b: number, c: number) => void;
46
+ export const rendersession_supportsCanvas: (a: number) => number;
45
47
  export const rendersession_warnings: (a: number) => number;
46
48
  export const lut_inverse_interp16: (a: number, b: number, c: number) => number;
47
49
  export const qcms_profile_precache_output_transform: (a: number) => void;
package/package.json CHANGED
@@ -1,9 +1,12 @@
1
1
  {
2
2
  "name": "@quillmark/wasm",
3
- "version": "0.67.0",
3
+ "version": "0.69.0",
4
4
  "description": "WebAssembly bindings for quillmark",
5
5
  "type": "module",
6
6
  "license": "MIT OR Apache-2.0",
7
+ "engines": {
8
+ "node": ">=24"
9
+ },
7
10
  "repository": {
8
11
  "type": "git",
9
12
  "url": "git+https://github.com/nibsbin/quillmark.git"
@@ -13,20 +16,14 @@
13
16
  "bundler/wasm_bg.js",
14
17
  "bundler/wasm_bg.wasm.d.ts",
15
18
  "bundler/wasm.js",
16
- "bundler/wasm.d.ts",
17
- "node-esm/wasm_bg.wasm",
18
- "node-esm/wasm_bg.js",
19
- "node-esm/wasm_bg.wasm.d.ts",
20
- "node-esm/wasm.js",
21
- "node-esm/wasm.d.ts"
19
+ "bundler/wasm.d.ts"
22
20
  ],
23
- "main": "./node-esm/wasm.js",
21
+ "main": "./bundler/wasm.js",
24
22
  "module": "./bundler/wasm.js",
25
23
  "types": "./bundler/wasm.d.ts",
26
24
  "exports": {
27
25
  ".": {
28
26
  "types": "./bundler/wasm.d.ts",
29
- "node": "./node-esm/wasm.js",
30
27
  "import": "./bundler/wasm.js",
31
28
  "default": "./bundler/wasm.js"
32
29
  }
@@ -34,4 +31,4 @@
34
31
  "sideEffects": [
35
32
  "./bundler/wasm.js"
36
33
  ]
37
- }
34
+ }