@oh-just-another/renderer-canvas 0.58.1 → 0.60.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/CHANGELOG.md +78 -0
- package/README.md +63 -15
- package/dist/.tsbuildinfo +1 -1
- package/dist/canvas-target.d.ts +6 -1
- package/dist/canvas-target.d.ts.map +1 -1
- package/dist/canvas-target.js +18 -5
- package/dist/canvas-target.js.map +1 -1
- package/dist/constants.d.ts +81 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +81 -0
- package/dist/constants.js.map +1 -1
- package/dist/hi-dpi.d.ts +21 -13
- package/dist/hi-dpi.d.ts.map +1 -1
- package/dist/hi-dpi.js +28 -33
- package/dist/hi-dpi.js.map +1 -1
- package/dist/image-source.d.ts +11 -0
- package/dist/image-source.d.ts.map +1 -1
- package/dist/image-source.js +20 -0
- package/dist/image-source.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -12
- package/dist/index.js.map +1 -1
- package/dist/layered-canvas.d.ts +7 -1
- package/dist/layered-canvas.d.ts.map +1 -1
- package/dist/layered-canvas.js +6 -3
- package/dist/layered-canvas.js.map +1 -1
- package/dist/layered-surface.d.ts +16 -0
- package/dist/layered-surface.d.ts.map +1 -1
- package/dist/layered-surface.js +53 -15
- package/dist/layered-surface.js.map +1 -1
- package/dist/recording-target.d.ts +85 -25
- package/dist/recording-target.d.ts.map +1 -1
- package/dist/recording-target.js +250 -50
- package/dist/recording-target.js.map +1 -1
- package/dist/render-worker.js +16 -3
- package/dist/render-worker.js.map +1 -1
- package/dist/tile-compositor.d.ts +43 -1
- package/dist/tile-compositor.d.ts.map +1 -1
- package/dist/tile-compositor.js +48 -5
- package/dist/tile-compositor.js.map +1 -1
- package/dist/webgl-helpers.d.ts +7 -0
- package/dist/webgl-helpers.d.ts.map +1 -0
- package/dist/webgl-helpers.js +32 -0
- package/dist/webgl-helpers.js.map +1 -0
- package/dist/webgl2-curve.d.ts +11 -0
- package/dist/webgl2-curve.d.ts.map +1 -1
- package/dist/webgl2-curve.js +151 -68
- package/dist/webgl2-curve.js.map +1 -1
- package/dist/webgl2-ellipse.d.ts +0 -27
- package/dist/webgl2-ellipse.d.ts.map +1 -1
- package/dist/webgl2-ellipse.js +21 -47
- package/dist/webgl2-ellipse.js.map +1 -1
- package/dist/webgl2-msdf-text.d.ts +14 -0
- package/dist/webgl2-msdf-text.d.ts.map +1 -1
- package/dist/webgl2-msdf-text.js +84 -36
- package/dist/webgl2-msdf-text.js.map +1 -1
- package/dist/webgl2-rect-batch.d.ts +81 -0
- package/dist/webgl2-rect-batch.d.ts.map +1 -0
- package/dist/webgl2-rect-batch.js +201 -0
- package/dist/webgl2-rect-batch.js.map +1 -0
- package/dist/webgl2-stroke.d.ts +6 -30
- package/dist/webgl2-stroke.d.ts.map +1 -1
- package/dist/webgl2-stroke.js +17 -30
- package/dist/webgl2-stroke.js.map +1 -1
- package/dist/webgl2-target.d.ts +74 -8
- package/dist/webgl2-target.d.ts.map +1 -1
- package/dist/webgl2-target.js +356 -257
- package/dist/webgl2-target.js.map +1 -1
- package/package.json +10 -8
package/dist/canvas-target.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { resolveBundledFamily } from "@oh-just-another/fonts";
|
|
2
|
+
import { intrinsicImageSize, isDrawableImageSource, warnSkippedImage } from "./image-source.js";
|
|
2
3
|
/**
|
|
3
4
|
* Wraps a `CanvasRenderingContext2D` (or compatible OffscreenCanvas context)
|
|
4
5
|
* as a backend-agnostic `RenderTarget`. Coordinates passed to the target are
|
|
@@ -64,10 +65,12 @@ export class Canvas2DTarget {
|
|
|
64
65
|
this.ctx.setLineDash(dash ? [...dash] : []);
|
|
65
66
|
}
|
|
66
67
|
setFont(fontFamily, fontSize, options) {
|
|
67
|
-
// CSS font shorthand order: `<style> <weight> <size> <family>`.
|
|
68
|
+
// CSS font shorthand order: `<style> <weight> <size> <family>`. Draw with
|
|
69
|
+
// the bundled face that backs the requested family (matching the WebGL2
|
|
70
|
+
// MSDF path), falling back to the original stack until it has loaded.
|
|
68
71
|
const style = options?.style === "italic" ? "italic " : "";
|
|
69
72
|
const weight = options?.weight === "bold" ? "bold " : "";
|
|
70
|
-
this.ctx.font = `${style}${weight}${fontSize}px ${fontFamily}`;
|
|
73
|
+
this.ctx.font = `${style}${weight}${fontSize}px "${resolveBundledFamily(fontFamily)}", ${fontFamily}`;
|
|
71
74
|
}
|
|
72
75
|
setTextAlign(align) {
|
|
73
76
|
this.ctx.textAlign = align === "center" ? "center" : align;
|
|
@@ -147,10 +150,10 @@ export class Canvas2DTarget {
|
|
|
147
150
|
return { width: m.width };
|
|
148
151
|
}
|
|
149
152
|
// --- Images ---
|
|
150
|
-
drawImage(image, dx, dy, dw, dh, _dynamic) {
|
|
153
|
+
drawImage(image, dx, dy, dw, dh, _dynamic, crop) {
|
|
151
154
|
// `_dynamic` ignored — Canvas2D reads the source element live on
|
|
152
155
|
// every drawImage, so animated GIF / video frames are picked up
|
|
153
|
-
// automatically as long as the host re-renders
|
|
156
|
+
// automatically as long as the host re-renders.
|
|
154
157
|
void _dynamic;
|
|
155
158
|
// Guard against non-drawable handles. A restored scene carries
|
|
156
159
|
// either a string `src` (dead blob: URL) OR a `metadata.image`
|
|
@@ -162,6 +165,16 @@ export class Canvas2DTarget {
|
|
|
162
165
|
warnSkippedImage(image);
|
|
163
166
|
return;
|
|
164
167
|
}
|
|
168
|
+
// Cropped draw: map the normalised source rect to pixels and use the
|
|
169
|
+
// 9-argument form. Falls back to the whole image when the intrinsic
|
|
170
|
+
// size is unknown (crop can't be resolved).
|
|
171
|
+
if (crop && (crop.x !== 0 || crop.y !== 0 || crop.width !== 1 || crop.height !== 1)) {
|
|
172
|
+
const size = intrinsicImageSize(image);
|
|
173
|
+
if (size) {
|
|
174
|
+
this.ctx.drawImage(image, crop.x * size.width, crop.y * size.height, crop.width * size.width, crop.height * size.height, dx, dy, dw, dh);
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
165
178
|
this.ctx.drawImage(image, dx, dy, dw, dh);
|
|
166
179
|
}
|
|
167
180
|
// --- Surface control ---
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"canvas-target.js","sourceRoot":"","sources":["../src/canvas-target.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"canvas-target.js","sourceRoot":"","sources":["../src/canvas-target.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAEhG;;;;;;;;GAQG;AACH,MAAM,OAAO,cAAc;IACR,GAAG,CAA2B;IACvC,MAAM,CAAS;IACf,OAAO,CAAS;IACxB;;;;;OAKG;IACK,GAAG,CAAS;IAEpB;;;;OAIG;IACH,YAAY,GAA6B,EAAE,KAAa,EAAE,MAAc,EAAE,GAAG,GAAG,CAAC;QAC/E,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,CAAC;IAED,IAAI,IAAI;QACN,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC;IACtD,CAAC;IAED;sEACkE;IAClE,MAAM,CAAC,KAAa,EAAE,MAAc,EAAE,GAAY;QAChD,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,GAAG,KAAK,SAAS;YAAE,IAAI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;QACV,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;CACF"}
|
package/dist/constants.d.ts
CHANGED
|
@@ -34,6 +34,27 @@ export declare const LARGE_SCENE_WORKER_THRESHOLD = 50000;
|
|
|
34
34
|
* text renders through an atlas, without an OffscreenCanvas round-trip.
|
|
35
35
|
*/
|
|
36
36
|
export declare const WEBGL2_TEXT_BITMAP_CACHE_CAP = 256;
|
|
37
|
+
/**
|
|
38
|
+
* LRU cap on the offscreen image cache shared by `RecordingTarget`
|
|
39
|
+
* (main thread, identity → id) and the render worker (id → ImageBitmap).
|
|
40
|
+
*
|
|
41
|
+
* The offscreen backend re-renders every frame so animated GIF / video
|
|
42
|
+
* frames are picked up; without this cache each frame re-posts (clones)
|
|
43
|
+
* every drawn `ImageBitmap` across the worker boundary. With it, a bitmap
|
|
44
|
+
* is shipped once under a stable id and later referenced by id alone —
|
|
45
|
+
* the GIF adapter returns the same cached bitmap for a frame held across
|
|
46
|
+
* several rAF ticks, so the per-tick redraw costs one tiny command.
|
|
47
|
+
*
|
|
48
|
+
* Both sides keep an LRU of identical capacity, so they evict the same
|
|
49
|
+
* id in lockstep (the command stream drives both in the same order);
|
|
50
|
+
* the worker also closes the evicted bitmap clone to release memory.
|
|
51
|
+
*
|
|
52
|
+
* 64 — a scene rarely has more than 10-20 distinct images in flight at
|
|
53
|
+
* once; a 3-6x margin covers a short GIF loop's frames without thrashing.
|
|
54
|
+
* On overflow the coldest image is dropped; its next draw re-ships the
|
|
55
|
+
* bitmap (one extra clone) and re-inserts.
|
|
56
|
+
*/
|
|
57
|
+
export declare const OFFSCREEN_IMAGE_CACHE_CAP = 64;
|
|
37
58
|
/**
|
|
38
59
|
* LRU cap on `WebGL2Target.textures` — image-source to WebGLTexture
|
|
39
60
|
* cache used by `drawImage`. Each entry holds a GPU texture
|
|
@@ -49,4 +70,64 @@ export declare const WEBGL2_TEXT_BITMAP_CACHE_CAP = 256;
|
|
|
49
70
|
* cost).
|
|
50
71
|
*/
|
|
51
72
|
export declare const WEBGL2_IMAGE_TEXTURE_CACHE_CAP = 64;
|
|
73
|
+
/**
|
|
74
|
+
* Cap applied to `window.devicePixelRatio` when sizing canvas bitmaps
|
|
75
|
+
* (`setupHiDpi`, `createLayeredSurface`). Mobile / hi-end displays report
|
|
76
|
+
* DPR 3–4; rendering the full ratio quadruples-to-sixteenfolds the pixel
|
|
77
|
+
* fill cost per layer for visual gains that are imperceptible in a
|
|
78
|
+
* diagram editor (thin strokes, flat fills). Capping at 2 keeps bitmap
|
|
79
|
+
* memory and raster time bounded — text and hairlines render very
|
|
80
|
+
* slightly softer on DPR-3 devices. Range: 1–4; hosts needing exact
|
|
81
|
+
* native sharpness can raise it via `CreateLayeredSurfaceOptions.maxDpr`
|
|
82
|
+
* or by passing an explicit `dpr` to `setupHiDpi`.
|
|
83
|
+
*/
|
|
84
|
+
export declare const MAX_DEVICE_PIXEL_RATIO = 2;
|
|
85
|
+
/**
|
|
86
|
+
* LRU cap on the Loop-Blinn triangulation cache in `webgl2-curve.ts`.
|
|
87
|
+
* Keyed by curve control-point content (renderers emit paths in
|
|
88
|
+
* element-local coordinates, so identical geometry — e.g. every
|
|
89
|
+
* same-size rounded rect — shares one entry, and pan / zoom / drag
|
|
90
|
+
* never invalidate it: the transform is applied in the vertex shader).
|
|
91
|
+
*
|
|
92
|
+
* Each entry stores the packed positions + uvs plus the key floats —
|
|
93
|
+
* a rounded rect (4 triangles) is ≈ 500 bytes, so the cap bounds the
|
|
94
|
+
* cache at a few MB worst-case. On overflow the least-recently-drawn
|
|
95
|
+
* geometry is evicted and re-triangulated on next draw (cheap, no GPU
|
|
96
|
+
* resources involved). Range: 512–16384.
|
|
97
|
+
*/
|
|
98
|
+
export declare const WEBGL2_CURVE_TRIANGULATION_CACHE_CAP = 4096;
|
|
99
|
+
/**
|
|
100
|
+
* Lower bound on the polygon approximation of an ellipse. Keeps small
|
|
101
|
+
* ellipses from collapsing to a coarse hexagon at far zoom. Range: 12–48.
|
|
102
|
+
*/
|
|
103
|
+
export declare const ELLIPSE_MIN_SEGMENTS = 24;
|
|
104
|
+
/**
|
|
105
|
+
* Upper bound on the polygon approximation of an ellipse. Caps GPU work
|
|
106
|
+
* for huge ellipses where extra segments yield invisible pixel-error
|
|
107
|
+
* improvement. Range: 256–1024.
|
|
108
|
+
*/
|
|
109
|
+
export declare const ELLIPSE_MAX_SEGMENTS = 512;
|
|
110
|
+
/**
|
|
111
|
+
* Initial per-target capacity, in instances, of the sharp-rect instance
|
|
112
|
+
* batcher (`webgl2-rect-batch.ts` `RectBatch`). One frame's worth of
|
|
113
|
+
* same-run rect fills packs into this without a grow; capacity doubles
|
|
114
|
+
* on demand and never shrinks. 256 covers typical grid / background
|
|
115
|
+
* scenes at ~10 KB (40 bytes/instance). Range: 64–4096.
|
|
116
|
+
*/
|
|
117
|
+
export declare const INITIAL_RECT_BATCH_INSTANCES = 256;
|
|
118
|
+
/**
|
|
119
|
+
* LRU cap on the per-atlas MSDF run-width memo (`webgl2-msdf-text.ts`).
|
|
120
|
+
* The em-width of a text run (Σ advance/unitsPerEm) is immutable once its
|
|
121
|
+
* glyphs are cached, so it is memoized keyed by `(fontId, text)`: a
|
|
122
|
+
* repeat `measureText`, or a `measureText` after the same string was
|
|
123
|
+
* drawn, returns in O(1) instead of re-walking the codepoints. Caret
|
|
124
|
+
* positioning and selection geometry call `measureText` on the same
|
|
125
|
+
* label many times per frame, so the hit rate is high.
|
|
126
|
+
*
|
|
127
|
+
* Each entry is a single number keyed by the run string — cheap. 1024
|
|
128
|
+
* covers a large editing session's distinct labels with margin; on
|
|
129
|
+
* overflow the least-recently-measured run is evicted and re-walked on
|
|
130
|
+
* next measure (cheap, no GPU resources). Range: 256–8192.
|
|
131
|
+
*/
|
|
132
|
+
export declare const WEBGL2_MSDF_RUN_WIDTH_CACHE_CAP = 1024;
|
|
52
133
|
//# sourceMappingURL=constants.d.ts.map
|
package/dist/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;;;;GASG;AACH,eAAO,MAAM,4BAA4B,QAAS,CAAC;AAEnD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,4BAA4B,MAAM,CAAC;AAEhD;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,8BAA8B,KAAK,CAAC"}
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;;;;GASG;AACH,eAAO,MAAM,4BAA4B,QAAS,CAAC;AAEnD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,4BAA4B,MAAM,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,yBAAyB,KAAK,CAAC;AAE5C;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,8BAA8B,KAAK,CAAC;AAEjD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,sBAAsB,IAAI,CAAC;AAExC;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,oCAAoC,OAAO,CAAC;AAEzD;;;GAGG;AACH,eAAO,MAAM,oBAAoB,KAAK,CAAC;AAEvC;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,MAAM,CAAC;AAExC;;;;;;GAMG;AACH,eAAO,MAAM,4BAA4B,MAAM,CAAC;AAEhD;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,+BAA+B,OAAO,CAAC"}
|
package/dist/constants.js
CHANGED
|
@@ -34,6 +34,27 @@ export const LARGE_SCENE_WORKER_THRESHOLD = 50_000;
|
|
|
34
34
|
* text renders through an atlas, without an OffscreenCanvas round-trip.
|
|
35
35
|
*/
|
|
36
36
|
export const WEBGL2_TEXT_BITMAP_CACHE_CAP = 256;
|
|
37
|
+
/**
|
|
38
|
+
* LRU cap on the offscreen image cache shared by `RecordingTarget`
|
|
39
|
+
* (main thread, identity → id) and the render worker (id → ImageBitmap).
|
|
40
|
+
*
|
|
41
|
+
* The offscreen backend re-renders every frame so animated GIF / video
|
|
42
|
+
* frames are picked up; without this cache each frame re-posts (clones)
|
|
43
|
+
* every drawn `ImageBitmap` across the worker boundary. With it, a bitmap
|
|
44
|
+
* is shipped once under a stable id and later referenced by id alone —
|
|
45
|
+
* the GIF adapter returns the same cached bitmap for a frame held across
|
|
46
|
+
* several rAF ticks, so the per-tick redraw costs one tiny command.
|
|
47
|
+
*
|
|
48
|
+
* Both sides keep an LRU of identical capacity, so they evict the same
|
|
49
|
+
* id in lockstep (the command stream drives both in the same order);
|
|
50
|
+
* the worker also closes the evicted bitmap clone to release memory.
|
|
51
|
+
*
|
|
52
|
+
* 64 — a scene rarely has more than 10-20 distinct images in flight at
|
|
53
|
+
* once; a 3-6x margin covers a short GIF loop's frames without thrashing.
|
|
54
|
+
* On overflow the coldest image is dropped; its next draw re-ships the
|
|
55
|
+
* bitmap (one extra clone) and re-inserts.
|
|
56
|
+
*/
|
|
57
|
+
export const OFFSCREEN_IMAGE_CACHE_CAP = 64;
|
|
37
58
|
/**
|
|
38
59
|
* LRU cap on `WebGL2Target.textures` — image-source to WebGLTexture
|
|
39
60
|
* cache used by `drawImage`. Each entry holds a GPU texture
|
|
@@ -49,4 +70,64 @@ export const WEBGL2_TEXT_BITMAP_CACHE_CAP = 256;
|
|
|
49
70
|
* cost).
|
|
50
71
|
*/
|
|
51
72
|
export const WEBGL2_IMAGE_TEXTURE_CACHE_CAP = 64;
|
|
73
|
+
/**
|
|
74
|
+
* Cap applied to `window.devicePixelRatio` when sizing canvas bitmaps
|
|
75
|
+
* (`setupHiDpi`, `createLayeredSurface`). Mobile / hi-end displays report
|
|
76
|
+
* DPR 3–4; rendering the full ratio quadruples-to-sixteenfolds the pixel
|
|
77
|
+
* fill cost per layer for visual gains that are imperceptible in a
|
|
78
|
+
* diagram editor (thin strokes, flat fills). Capping at 2 keeps bitmap
|
|
79
|
+
* memory and raster time bounded — text and hairlines render very
|
|
80
|
+
* slightly softer on DPR-3 devices. Range: 1–4; hosts needing exact
|
|
81
|
+
* native sharpness can raise it via `CreateLayeredSurfaceOptions.maxDpr`
|
|
82
|
+
* or by passing an explicit `dpr` to `setupHiDpi`.
|
|
83
|
+
*/
|
|
84
|
+
export const MAX_DEVICE_PIXEL_RATIO = 2;
|
|
85
|
+
/**
|
|
86
|
+
* LRU cap on the Loop-Blinn triangulation cache in `webgl2-curve.ts`.
|
|
87
|
+
* Keyed by curve control-point content (renderers emit paths in
|
|
88
|
+
* element-local coordinates, so identical geometry — e.g. every
|
|
89
|
+
* same-size rounded rect — shares one entry, and pan / zoom / drag
|
|
90
|
+
* never invalidate it: the transform is applied in the vertex shader).
|
|
91
|
+
*
|
|
92
|
+
* Each entry stores the packed positions + uvs plus the key floats —
|
|
93
|
+
* a rounded rect (4 triangles) is ≈ 500 bytes, so the cap bounds the
|
|
94
|
+
* cache at a few MB worst-case. On overflow the least-recently-drawn
|
|
95
|
+
* geometry is evicted and re-triangulated on next draw (cheap, no GPU
|
|
96
|
+
* resources involved). Range: 512–16384.
|
|
97
|
+
*/
|
|
98
|
+
export const WEBGL2_CURVE_TRIANGULATION_CACHE_CAP = 4096;
|
|
99
|
+
/**
|
|
100
|
+
* Lower bound on the polygon approximation of an ellipse. Keeps small
|
|
101
|
+
* ellipses from collapsing to a coarse hexagon at far zoom. Range: 12–48.
|
|
102
|
+
*/
|
|
103
|
+
export const ELLIPSE_MIN_SEGMENTS = 24;
|
|
104
|
+
/**
|
|
105
|
+
* Upper bound on the polygon approximation of an ellipse. Caps GPU work
|
|
106
|
+
* for huge ellipses where extra segments yield invisible pixel-error
|
|
107
|
+
* improvement. Range: 256–1024.
|
|
108
|
+
*/
|
|
109
|
+
export const ELLIPSE_MAX_SEGMENTS = 512;
|
|
110
|
+
/**
|
|
111
|
+
* Initial per-target capacity, in instances, of the sharp-rect instance
|
|
112
|
+
* batcher (`webgl2-rect-batch.ts` `RectBatch`). One frame's worth of
|
|
113
|
+
* same-run rect fills packs into this without a grow; capacity doubles
|
|
114
|
+
* on demand and never shrinks. 256 covers typical grid / background
|
|
115
|
+
* scenes at ~10 KB (40 bytes/instance). Range: 64–4096.
|
|
116
|
+
*/
|
|
117
|
+
export const INITIAL_RECT_BATCH_INSTANCES = 256;
|
|
118
|
+
/**
|
|
119
|
+
* LRU cap on the per-atlas MSDF run-width memo (`webgl2-msdf-text.ts`).
|
|
120
|
+
* The em-width of a text run (Σ advance/unitsPerEm) is immutable once its
|
|
121
|
+
* glyphs are cached, so it is memoized keyed by `(fontId, text)`: a
|
|
122
|
+
* repeat `measureText`, or a `measureText` after the same string was
|
|
123
|
+
* drawn, returns in O(1) instead of re-walking the codepoints. Caret
|
|
124
|
+
* positioning and selection geometry call `measureText` on the same
|
|
125
|
+
* label many times per frame, so the hit rate is high.
|
|
126
|
+
*
|
|
127
|
+
* Each entry is a single number keyed by the run string — cheap. 1024
|
|
128
|
+
* covers a large editing session's distinct labels with margin; on
|
|
129
|
+
* overflow the least-recently-measured run is evicted and re-walked on
|
|
130
|
+
* next measure (cheap, no GPU resources). Range: 256–8192.
|
|
131
|
+
*/
|
|
132
|
+
export const WEBGL2_MSDF_RUN_WIDTH_CACHE_CAP = 1024;
|
|
52
133
|
//# sourceMappingURL=constants.js.map
|
package/dist/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,MAAM,CAAC;AAEnD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,GAAG,CAAC;AAEhD;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG,EAAE,CAAC"}
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,MAAM,CAAC;AAEnD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,GAAG,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,EAAE,CAAC;AAE5C;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG,EAAE,CAAC;AAEjD;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC;AAExC;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,oCAAoC,GAAG,IAAI,CAAC;AAEzD;;;GAGG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,EAAE,CAAC;AAEvC;;;;GAIG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAG,CAAC;AAExC;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,GAAG,CAAC;AAEhD;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,+BAA+B,GAAG,IAAI,CAAC"}
|
package/dist/hi-dpi.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Configures a `<canvas>` for hi-DPI rendering. Sets the bitmap size to
|
|
3
|
-
* `width * dpr` × `height * dpr`, the CSS size to `width` × `height`, and
|
|
4
|
-
* context transform to `scale(dpr, dpr)`
|
|
5
|
-
* CSS pixels. Returns the DPR used so
|
|
3
|
+
* `width * dpr` × `height * dpr`, the CSS size to `width` × `height`, and
|
|
4
|
+
* (when `setupContext` is true) the 2D context transform to `scale(dpr, dpr)`
|
|
5
|
+
* so subsequent draw calls operate in CSS pixels. Returns the DPR used so
|
|
6
|
+
* callers can recompute on monitor changes.
|
|
6
7
|
*
|
|
7
8
|
* IDEMPOTENT: assigning `canvas.width` / `canvas.height` resets both
|
|
8
9
|
* the bitmap AND the context transform — even when the new value equals
|
|
@@ -10,17 +11,24 @@
|
|
|
10
11
|
* the same size on attach; without the guard each tick would wipe the
|
|
11
12
|
* existing canvas content. We early-return when bitmap + CSS size +
|
|
12
13
|
* DPR are already exactly right.
|
|
14
|
+
*
|
|
15
|
+
* `setupContext` (default `true`): when `false`, skips the `getContext("2d")`
|
|
16
|
+
* + `setTransform` step for canvases destined for a non-2D context (WebGL2,
|
|
17
|
+
* WebGPU). `HTMLCanvasElement` only ever yields one *kind* of context, so
|
|
18
|
+
* touching `2d` on a canvas headed for `webgl2` poisons the slot and every
|
|
19
|
+
* subsequent `getContext("webgl2")` returns null. Use `false` for the WebGL2
|
|
20
|
+
* main canvas in `WebGL2LayeredSurface`; its viewport is set inside
|
|
21
|
+
* `WebGL2Target` after the GL context is obtained.
|
|
22
|
+
*
|
|
23
|
+
* The default `dpr` is `window.devicePixelRatio` capped at
|
|
24
|
+
* `MAX_DEVICE_PIXEL_RATIO` (see constants.ts). An explicit `dpr` argument
|
|
25
|
+
* is honoured as-is — pass the raw ratio to opt out of the cap.
|
|
13
26
|
*/
|
|
14
|
-
export declare const setupHiDpi: (canvas: HTMLCanvasElement, width: number, height: number, dpr?: number) => number;
|
|
27
|
+
export declare const setupHiDpi: (canvas: HTMLCanvasElement, width: number, height: number, dpr?: number, setupContext?: boolean) => number;
|
|
15
28
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* one *kind* of context, so touching `2d` on a canvas destined for
|
|
20
|
-
* `webgl2` poisons the slot and every subsequent `getContext("webgl2")`
|
|
21
|
-
* returns null. Use this for the WebGL2 main canvas in
|
|
22
|
-
* `WebGL2LayeredSurface`; the WebGL2 viewport is set inside
|
|
23
|
-
* `WebGL2Target` after the GL context is obtained.
|
|
29
|
+
* The live `window.devicePixelRatio` clamped to `maxDpr` (SSR-safe:
|
|
30
|
+
* resolves to 1 when there is no `window`). Callers that re-read the DPR
|
|
31
|
+
* on resize (monitor changes) go through this instead of the raw ratio.
|
|
24
32
|
*/
|
|
25
|
-
export declare const
|
|
33
|
+
export declare const cappedDpr: (maxDpr?: number) => number;
|
|
26
34
|
//# sourceMappingURL=hi-dpi.d.ts.map
|
package/dist/hi-dpi.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hi-dpi.d.ts","sourceRoot":"","sources":["../src/hi-dpi.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"hi-dpi.d.ts","sourceRoot":"","sources":["../src/hi-dpi.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,UAAU,GACrB,QAAQ,iBAAiB,EACzB,OAAO,MAAM,EACb,QAAQ,MAAM,EACd,MAAK,MAAoB,EACzB,sBAAmB,KAClB,MAuBF,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,SAAS,GAAI,SAAQ,MAA+B,KAAG,MACgB,CAAC"}
|
package/dist/hi-dpi.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { MAX_DEVICE_PIXEL_RATIO } from "./constants.js";
|
|
1
2
|
/**
|
|
2
3
|
* Configures a `<canvas>` for hi-DPI rendering. Sets the bitmap size to
|
|
3
|
-
* `width * dpr` × `height * dpr`, the CSS size to `width` × `height`, and
|
|
4
|
-
* context transform to `scale(dpr, dpr)`
|
|
5
|
-
* CSS pixels. Returns the DPR used so
|
|
4
|
+
* `width * dpr` × `height * dpr`, the CSS size to `width` × `height`, and
|
|
5
|
+
* (when `setupContext` is true) the 2D context transform to `scale(dpr, dpr)`
|
|
6
|
+
* so subsequent draw calls operate in CSS pixels. Returns the DPR used so
|
|
7
|
+
* callers can recompute on monitor changes.
|
|
6
8
|
*
|
|
7
9
|
* IDEMPOTENT: assigning `canvas.width` / `canvas.height` resets both
|
|
8
10
|
* the bitmap AND the context transform — even when the new value equals
|
|
@@ -10,8 +12,20 @@
|
|
|
10
12
|
* the same size on attach; without the guard each tick would wipe the
|
|
11
13
|
* existing canvas content. We early-return when bitmap + CSS size +
|
|
12
14
|
* DPR are already exactly right.
|
|
15
|
+
*
|
|
16
|
+
* `setupContext` (default `true`): when `false`, skips the `getContext("2d")`
|
|
17
|
+
* + `setTransform` step for canvases destined for a non-2D context (WebGL2,
|
|
18
|
+
* WebGPU). `HTMLCanvasElement` only ever yields one *kind* of context, so
|
|
19
|
+
* touching `2d` on a canvas headed for `webgl2` poisons the slot and every
|
|
20
|
+
* subsequent `getContext("webgl2")` returns null. Use `false` for the WebGL2
|
|
21
|
+
* main canvas in `WebGL2LayeredSurface`; its viewport is set inside
|
|
22
|
+
* `WebGL2Target` after the GL context is obtained.
|
|
23
|
+
*
|
|
24
|
+
* The default `dpr` is `window.devicePixelRatio` capped at
|
|
25
|
+
* `MAX_DEVICE_PIXEL_RATIO` (see constants.ts). An explicit `dpr` argument
|
|
26
|
+
* is honoured as-is — pass the raw ratio to opt out of the cap.
|
|
13
27
|
*/
|
|
14
|
-
export const setupHiDpi = (canvas, width, height, dpr =
|
|
28
|
+
export const setupHiDpi = (canvas, width, height, dpr = cappedDpr(), setupContext = true) => {
|
|
15
29
|
const targetW = Math.round(width * dpr);
|
|
16
30
|
const targetH = Math.round(height * dpr);
|
|
17
31
|
const cssW = `${width}px`;
|
|
@@ -26,37 +40,18 @@ export const setupHiDpi = (canvas, width, height, dpr = window.devicePixelRatio
|
|
|
26
40
|
canvas.height = targetH;
|
|
27
41
|
canvas.style.width = cssW;
|
|
28
42
|
canvas.style.height = cssH;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
43
|
+
if (setupContext) {
|
|
44
|
+
const ctx = canvas.getContext("2d");
|
|
45
|
+
if (!ctx)
|
|
46
|
+
throw new Error("Failed to obtain 2D context");
|
|
47
|
+
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
48
|
+
}
|
|
33
49
|
return dpr;
|
|
34
50
|
};
|
|
35
51
|
/**
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* one *kind* of context, so touching `2d` on a canvas destined for
|
|
40
|
-
* `webgl2` poisons the slot and every subsequent `getContext("webgl2")`
|
|
41
|
-
* returns null. Use this for the WebGL2 main canvas in
|
|
42
|
-
* `WebGL2LayeredSurface`; the WebGL2 viewport is set inside
|
|
43
|
-
* `WebGL2Target` after the GL context is obtained.
|
|
52
|
+
* The live `window.devicePixelRatio` clamped to `maxDpr` (SSR-safe:
|
|
53
|
+
* resolves to 1 when there is no `window`). Callers that re-read the DPR
|
|
54
|
+
* on resize (monitor changes) go through this instead of the raw ratio.
|
|
44
55
|
*/
|
|
45
|
-
export const
|
|
46
|
-
const targetW = Math.round(width * dpr);
|
|
47
|
-
const targetH = Math.round(height * dpr);
|
|
48
|
-
const cssW = `${width}px`;
|
|
49
|
-
const cssH = `${height}px`;
|
|
50
|
-
if (canvas.width === targetW &&
|
|
51
|
-
canvas.height === targetH &&
|
|
52
|
-
canvas.style.width === cssW &&
|
|
53
|
-
canvas.style.height === cssH) {
|
|
54
|
-
return dpr;
|
|
55
|
-
}
|
|
56
|
-
canvas.width = targetW;
|
|
57
|
-
canvas.height = targetH;
|
|
58
|
-
canvas.style.width = cssW;
|
|
59
|
-
canvas.style.height = cssH;
|
|
60
|
-
return dpr;
|
|
61
|
-
};
|
|
56
|
+
export const cappedDpr = (maxDpr = MAX_DEVICE_PIXEL_RATIO) => Math.min(typeof window !== "undefined" ? window.devicePixelRatio || 1 : 1, maxDpr);
|
|
62
57
|
//# sourceMappingURL=hi-dpi.js.map
|
package/dist/hi-dpi.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hi-dpi.js","sourceRoot":"","sources":["../src/hi-dpi.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":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zC,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,SAAiB,sBAAsB,EAAU,EAAE,CAC3E,IAAI,CAAC,GAAG,CAAC,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,gBAAgB,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC"}
|
package/dist/image-source.d.ts
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
1
|
export declare const isDrawableImageSource: (value: unknown) => value is CanvasImageSource;
|
|
2
|
+
/**
|
|
3
|
+
* Intrinsic pixel size of a drawable image source, or `null` when it can't be
|
|
4
|
+
* determined. Handles the differing width/height accessors of the DOM image
|
|
5
|
+
* types (`naturalWidth` for `<img>`, `videoWidth` for `<video>`, plain
|
|
6
|
+
* `width`/`height` for bitmaps / canvases). Needed to turn a normalised crop
|
|
7
|
+
* (fractions) into a pixel source rectangle for `ctx.drawImage`.
|
|
8
|
+
*/
|
|
9
|
+
export declare const intrinsicImageSize: (source: CanvasImageSource) => {
|
|
10
|
+
readonly width: number;
|
|
11
|
+
readonly height: number;
|
|
12
|
+
} | null;
|
|
2
13
|
export declare const warnSkippedImage: (value: unknown) => void;
|
|
3
14
|
//# sourceMappingURL=image-source.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"image-source.d.ts","sourceRoot":"","sources":["../src/image-source.ts"],"names":[],"mappings":"AA2BA,eAAO,MAAM,qBAAqB,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,iBAa/D,CAAC;AAUF,eAAO,MAAM,gBAAgB,GAAI,OAAO,OAAO,KAAG,IAoBjD,CAAC"}
|
|
1
|
+
{"version":3,"file":"image-source.d.ts","sourceRoot":"","sources":["../src/image-source.ts"],"names":[],"mappings":"AA2BA,eAAO,MAAM,qBAAqB,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,iBAa/D,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,GAC7B,QAAQ,iBAAiB,KACxB;IAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,IAmBxD,CAAC;AAUF,eAAO,MAAM,gBAAgB,GAAI,OAAO,OAAO,KAAG,IAoBjD,CAAC"}
|
package/dist/image-source.js
CHANGED
|
@@ -37,6 +37,26 @@ export const isDrawableImageSource = (value) => {
|
|
|
37
37
|
}
|
|
38
38
|
return false;
|
|
39
39
|
};
|
|
40
|
+
/**
|
|
41
|
+
* Intrinsic pixel size of a drawable image source, or `null` when it can't be
|
|
42
|
+
* determined. Handles the differing width/height accessors of the DOM image
|
|
43
|
+
* types (`naturalWidth` for `<img>`, `videoWidth` for `<video>`, plain
|
|
44
|
+
* `width`/`height` for bitmaps / canvases). Needed to turn a normalised crop
|
|
45
|
+
* (fractions) into a pixel source rectangle for `ctx.drawImage`.
|
|
46
|
+
*/
|
|
47
|
+
export const intrinsicImageSize = (source) => {
|
|
48
|
+
const s = source;
|
|
49
|
+
if (typeof s.naturalWidth === "number" && s.naturalWidth > 0) {
|
|
50
|
+
return { width: s.naturalWidth, height: s.naturalHeight ?? s.naturalWidth };
|
|
51
|
+
}
|
|
52
|
+
if (typeof s.videoWidth === "number" && s.videoWidth > 0) {
|
|
53
|
+
return { width: s.videoWidth, height: s.videoHeight ?? s.videoWidth };
|
|
54
|
+
}
|
|
55
|
+
if (typeof s.width === "number" && s.width > 0 && typeof s.height === "number") {
|
|
56
|
+
return { width: s.width, height: s.height };
|
|
57
|
+
}
|
|
58
|
+
return null;
|
|
59
|
+
};
|
|
40
60
|
/**
|
|
41
61
|
* Warn (once per distinct kind) when an image draw is skipped because
|
|
42
62
|
* the handle isn't drawable. Throttled by a module-level `Set` so a
|
package/dist/image-source.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":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1,8 @@
|
|
|
1
1
|
export { Canvas2DTarget } from "./canvas-target.js";
|
|
2
2
|
export { Canvas2DTextShaper } from "./canvas-text-shaper.js";
|
|
3
|
-
export { WebGL2Target } from "./webgl2-target.js";
|
|
3
|
+
export { WebGL2Target, type WebGL2TargetOptions } from "./webgl2-target.js";
|
|
4
4
|
export { renderViaTiles, type RenderViaTilesOptions } from "./tile-compositor.js";
|
|
5
|
-
export { setupHiDpi } from "./hi-dpi.js";
|
|
5
|
+
export { setupHiDpi, cappedDpr } from "./hi-dpi.js";
|
|
6
6
|
export { LayeredCanvas, type LayeredCanvasOptions } from "./layered-canvas.js";
|
|
7
7
|
export { supportsOffscreenCanvas, createOffscreenCanvas2DTarget, transferCanvasToWorker, } from "./offscreen.js";
|
|
8
8
|
export { createRenderWorker } from "./worker-factory.js";
|
|
@@ -10,7 +10,7 @@ export { WorkerPool, LayerWorkerPool } from "@oh-just-another/renderer-workers";
|
|
|
10
10
|
export { RecordingTarget, replayCommands, type RenderCommand } from "./recording-target.js";
|
|
11
11
|
export { createLayeredSurface, createLayeredSurfaceWithFallback, type LayeredSurface, type RendererBackend, type CreateLayeredSurfaceOptions, } from "./layered-surface.js";
|
|
12
12
|
export { isWebGPUAvailable, isWebGL2Available, pickAvailableBackend } from "./webgpu-detect.js";
|
|
13
|
-
export { LARGE_SCENE_WORKER_THRESHOLD } from "./constants.js";
|
|
13
|
+
export { LARGE_SCENE_WORKER_THRESHOLD, MAX_DEVICE_PIXEL_RATIO } from "./constants.js";
|
|
14
14
|
export { installBuiltinRenderers, wrapText } from "@oh-just-another/renderer-core";
|
|
15
15
|
export type { WrapOptions, WrappedLine } from "@oh-just-another/renderer-core";
|
|
16
16
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,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E,MAAM,gCAAgC,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -2,24 +2,18 @@ export { Canvas2DTarget } from "./canvas-target.js";
|
|
|
2
2
|
export { Canvas2DTextShaper } from "./canvas-text-shaper.js";
|
|
3
3
|
export { WebGL2Target } from "./webgl2-target.js";
|
|
4
4
|
export { renderViaTiles } from "./tile-compositor.js";
|
|
5
|
-
export { setupHiDpi } from "./hi-dpi.js";
|
|
5
|
+
export { setupHiDpi, cappedDpr } from "./hi-dpi.js";
|
|
6
6
|
export { LayeredCanvas } from "./layered-canvas.js";
|
|
7
7
|
export { supportsOffscreenCanvas, createOffscreenCanvas2DTarget, transferCanvasToWorker, } from "./offscreen.js";
|
|
8
8
|
export { createRenderWorker } from "./worker-factory.js";
|
|
9
|
-
// WorkerPool / LayerWorkerPool live in @oh-just-another/renderer-workers
|
|
10
|
-
// (backend-neutral primitives don't belong in the Canvas-specific package).
|
|
11
|
-
// Re-export to keep existing imports working.
|
|
12
9
|
export { WorkerPool, LayerWorkerPool } from "@oh-just-another/renderer-workers";
|
|
13
10
|
export { RecordingTarget, replayCommands } from "./recording-target.js";
|
|
14
11
|
export { createLayeredSurface, createLayeredSurfaceWithFallback, } from "./layered-surface.js";
|
|
15
12
|
export { isWebGPUAvailable, isWebGL2Available, pickAvailableBackend } from "./webgpu-detect.js";
|
|
16
|
-
export { LARGE_SCENE_WORKER_THRESHOLD } from "./constants.js";
|
|
17
|
-
// `installBuiltinRenderers` and `wrapText` live in
|
|
18
|
-
// `@oh-just-another/renderer-core` so the SVG / headless backends can share them.
|
|
19
|
-
// These re-exports keep existing imports working.
|
|
13
|
+
export { LARGE_SCENE_WORKER_THRESHOLD, MAX_DEVICE_PIXEL_RATIO } from "./constants.js";
|
|
20
14
|
export { installBuiltinRenderers, wrapText } from "@oh-just-another/renderer-core";
|
|
21
|
-
// `installBuiltinRenderers()` must be called once before
|
|
22
|
-
//
|
|
23
|
-
//
|
|
24
|
-
//
|
|
15
|
+
// `installBuiltinRenderers()` must be called once before built-in shapes
|
|
16
|
+
// can be drawn. It is not auto-invoked so this package stays
|
|
17
|
+
// `sideEffects: false` and tree-shakeable. Hosts typically call it in
|
|
18
|
+
// their entry file.
|
|
25
19
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,YAAY,EAA4B,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EAAE,cAAc,EAA8B,MAAM,sBAAsB,CAAC;AAClF,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,aAAa,EAA6B,MAAM,qBAAqB,CAAC;AAC/E,OAAO,EACL,uBAAuB,EACvB,6BAA6B,EAC7B,sBAAsB,GACvB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AAChF,OAAO,EAAE,eAAe,EAAE,cAAc,EAAsB,MAAM,uBAAuB,CAAC;AAC5F,OAAO,EACL,oBAAoB,EACpB,gCAAgC,GAIjC,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAChG,OAAO,EAAE,4BAA4B,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAEtF,OAAO,EAAE,uBAAuB,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAC;AAGnF,yEAAyE;AACzE,6DAA6D;AAC7D,sEAAsE;AACtE,oBAAoB"}
|
package/dist/layered-canvas.d.ts
CHANGED
|
@@ -3,8 +3,13 @@ import { Canvas2DTarget } from "./canvas-target.js";
|
|
|
3
3
|
export interface LayeredCanvasOptions {
|
|
4
4
|
/** Subset of layers to create. Defaults to all three. */
|
|
5
5
|
readonly layers?: readonly LayerName[];
|
|
6
|
-
/** Override `window.devicePixelRatio`. */
|
|
6
|
+
/** Override `window.devicePixelRatio`. Takes precedence over `maxDpr`. */
|
|
7
7
|
readonly dpr?: number;
|
|
8
|
+
/**
|
|
9
|
+
* Cap applied to the live `window.devicePixelRatio` on create and every
|
|
10
|
+
* resize. Defaults to `MAX_DEVICE_PIXEL_RATIO`. Ignored when `dpr` is set.
|
|
11
|
+
*/
|
|
12
|
+
readonly maxDpr?: number;
|
|
8
13
|
}
|
|
9
14
|
/**
|
|
10
15
|
* Manages one stacked `<canvas>` per layer. The background canvas sits at the
|
|
@@ -22,6 +27,7 @@ export declare class LayeredCanvas {
|
|
|
22
27
|
private width;
|
|
23
28
|
private height;
|
|
24
29
|
private dprOverride;
|
|
30
|
+
private readonly maxDpr;
|
|
25
31
|
constructor(host: HTMLElement, width: number, height: number, options?: LayeredCanvasOptions);
|
|
26
32
|
/** Get the target for a layer. Throws if the layer was not created. */
|
|
27
33
|
get(name: LayerName): Canvas2DTarget;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"layered-canvas.d.ts","sourceRoot":"","sources":["../src/layered-canvas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAC7E,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"layered-canvas.d.ts","sourceRoot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