@zsherman/canvas 0.0.0-stage → 0.1.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 +7 -0
- package/LICENSE +373 -0
- package/README.md +15 -2
- package/THIRD_PARTY_NOTICES.md +117 -0
- package/dist/dom/canvas/assets.js +89 -0
- package/dist/dom/canvas/board-store.js +56 -0
- package/dist/dom/canvas/canvas-actions.js +78 -0
- package/dist/dom/canvas/canvas-board.js +557 -0
- package/dist/dom/canvas/canvas-board.styles.js +110 -0
- package/dist/dom/canvas/canvas-chrome.js +1167 -0
- package/dist/dom/canvas/canvas-chrome.styles.js +220 -0
- package/dist/dom/canvas/canvas-comments.js +950 -0
- package/dist/dom/canvas/canvas-comments.styles.js +231 -0
- package/dist/dom/canvas/canvas-context.js +196 -0
- package/dist/dom/canvas/canvas-controller.js +697 -0
- package/dist/dom/canvas/canvas-cursor-chat.js +120 -0
- package/dist/dom/canvas/canvas-cursor-chat.styles.js +55 -0
- package/dist/dom/canvas/canvas-menus.js +276 -0
- package/dist/dom/canvas/canvas-menus.styles.js +7 -0
- package/dist/dom/canvas/canvas-style-bar.js +930 -0
- package/dist/dom/canvas/canvas-style-bar.styles.js +52 -0
- package/dist/dom/canvas/canvas-surface.js +1353 -0
- package/dist/dom/canvas/canvas-surface.styles.js +345 -0
- package/dist/dom/canvas/canvas-tool-rail.js +406 -0
- package/dist/dom/canvas/canvas-tool-rail.styles.js +20 -0
- package/dist/dom/canvas/comments.js +58 -0
- package/dist/dom/canvas/equality.js +13 -0
- package/dist/dom/canvas/export-png.js +496 -0
- package/dist/dom/canvas/gesture-machine.js +91 -0
- package/dist/dom/canvas/handlers.js +18 -0
- package/dist/dom/canvas/index.js +9 -0
- package/dist/dom/canvas/input.js +85 -0
- package/dist/dom/canvas/instant.js +28 -0
- package/dist/dom/canvas/kernel.js +39 -0
- package/dist/dom/canvas/motion.js +686 -0
- package/dist/dom/canvas/palette.js +165 -0
- package/dist/dom/canvas/random-id.js +15 -0
- package/dist/dom/canvas/scene-renderer.js +559 -0
- package/dist/dom/canvas/scene.styles.js +7 -0
- package/dist/dom/canvas/surface-model.js +324 -0
- package/dist/dom/canvas/uploads.js +294 -0
- package/dist/dom/index.js +9 -0
- package/dist/dom/kernel/actions.js +455 -0
- package/dist/dom/kernel/board.js +856 -0
- package/dist/dom/kernel/claims.js +40 -0
- package/dist/dom/kernel/clipboard.js +30 -0
- package/dist/dom/kernel/constants.js +210 -0
- package/dist/dom/kernel/contract.js +0 -0
- package/dist/dom/kernel/decode.js +85 -0
- package/dist/dom/kernel/editor.js +2077 -0
- package/dist/dom/kernel/errors.js +82 -0
- package/dist/dom/kernel/fonts/inter.js +7924 -0
- package/dist/dom/kernel/fractional-index.js +54 -0
- package/dist/dom/kernel/geometry.js +123 -0
- package/dist/dom/kernel/hit-test.js +156 -0
- package/dist/dom/kernel/index.js +22 -0
- package/dist/dom/kernel/inspect.js +116 -0
- package/dist/dom/kernel/kernel.js +251 -0
- package/dist/dom/kernel/outline.js +64 -0
- package/dist/dom/kernel/plan.js +1370 -0
- package/dist/dom/kernel/rev.js +173 -0
- package/dist/dom/kernel/scene.js +580 -0
- package/dist/dom/kernel/schema.js +1109 -0
- package/dist/dom/kernel/snap.js +258 -0
- package/dist/dom/kernel/svg.js +148 -0
- package/dist/dom/kernel/text.js +142 -0
- package/dist/solid/canvas/assets.jsx +89 -0
- package/dist/solid/canvas/board-store.jsx +56 -0
- package/dist/solid/canvas/canvas-actions.jsx +78 -0
- package/dist/solid/canvas/canvas-board.jsx +326 -0
- package/dist/solid/canvas/canvas-board.styles.jsx +110 -0
- package/dist/solid/canvas/canvas-chrome.jsx +612 -0
- package/dist/solid/canvas/canvas-chrome.styles.jsx +220 -0
- package/dist/solid/canvas/canvas-comments.jsx +435 -0
- package/dist/solid/canvas/canvas-comments.styles.jsx +231 -0
- package/dist/solid/canvas/canvas-context.jsx +174 -0
- package/dist/solid/canvas/canvas-controller.jsx +697 -0
- package/dist/solid/canvas/canvas-cursor-chat.jsx +87 -0
- package/dist/solid/canvas/canvas-cursor-chat.styles.jsx +55 -0
- package/dist/solid/canvas/canvas-menus.jsx +223 -0
- package/dist/solid/canvas/canvas-menus.styles.jsx +7 -0
- package/dist/solid/canvas/canvas-style-bar.jsx +486 -0
- package/dist/solid/canvas/canvas-style-bar.styles.jsx +52 -0
- package/dist/solid/canvas/canvas-surface.jsx +681 -0
- package/dist/solid/canvas/canvas-surface.styles.jsx +345 -0
- package/dist/solid/canvas/canvas-tool-rail.jsx +195 -0
- package/dist/solid/canvas/canvas-tool-rail.styles.jsx +20 -0
- package/dist/solid/canvas/comments.jsx +58 -0
- package/dist/solid/canvas/equality.jsx +13 -0
- package/dist/solid/canvas/export-png.jsx +496 -0
- package/dist/solid/canvas/gesture-machine.jsx +91 -0
- package/dist/solid/canvas/handlers.jsx +18 -0
- package/dist/solid/canvas/index.jsx +9 -0
- package/dist/solid/canvas/input.jsx +85 -0
- package/dist/solid/canvas/instant.jsx +28 -0
- package/dist/solid/canvas/kernel.jsx +39 -0
- package/dist/solid/canvas/motion.jsx +686 -0
- package/dist/solid/canvas/palette.jsx +165 -0
- package/dist/solid/canvas/random-id.jsx +15 -0
- package/dist/solid/canvas/scene-renderer.jsx +559 -0
- package/dist/solid/canvas/scene.styles.jsx +7 -0
- package/dist/solid/canvas/surface-model.jsx +324 -0
- package/dist/solid/canvas/uploads.jsx +294 -0
- package/dist/solid/index.jsx +9 -0
- package/dist/solid/kernel/actions.jsx +455 -0
- package/dist/solid/kernel/board.jsx +856 -0
- package/dist/solid/kernel/claims.jsx +40 -0
- package/dist/solid/kernel/clipboard.jsx +30 -0
- package/dist/solid/kernel/constants.jsx +210 -0
- package/dist/solid/kernel/contract.jsx +0 -0
- package/dist/solid/kernel/decode.jsx +85 -0
- package/dist/solid/kernel/editor.jsx +2077 -0
- package/dist/solid/kernel/errors.jsx +82 -0
- package/dist/solid/kernel/fonts/inter.jsx +7924 -0
- package/dist/solid/kernel/fractional-index.jsx +54 -0
- package/dist/solid/kernel/geometry.jsx +123 -0
- package/dist/solid/kernel/hit-test.jsx +156 -0
- package/dist/solid/kernel/index.jsx +22 -0
- package/dist/solid/kernel/inspect.jsx +116 -0
- package/dist/solid/kernel/kernel.jsx +251 -0
- package/dist/solid/kernel/outline.jsx +64 -0
- package/dist/solid/kernel/plan.jsx +1370 -0
- package/dist/solid/kernel/rev.jsx +173 -0
- package/dist/solid/kernel/scene.jsx +580 -0
- package/dist/solid/kernel/schema.jsx +1109 -0
- package/dist/solid/kernel/snap.jsx +258 -0
- package/dist/solid/kernel/svg.jsx +148 -0
- package/dist/solid/kernel/text.jsx +142 -0
- package/dist/styles.css +1 -0
- package/dist/types/canvas/assets.d.ts +111 -0
- package/dist/types/canvas/board-store.d.ts +86 -0
- package/dist/types/canvas/canvas-actions.d.ts +21 -0
- package/dist/types/canvas/canvas-board.d.ts +53 -0
- package/dist/types/canvas/canvas-board.styles.d.ts +94 -0
- package/dist/types/canvas/canvas-chrome.d.ts +109 -0
- package/dist/types/canvas/canvas-chrome.styles.d.ts +193 -0
- package/dist/types/canvas/canvas-comments.d.ts +20 -0
- package/dist/types/canvas/canvas-comments.styles.d.ts +208 -0
- package/dist/types/canvas/canvas-context.d.ts +104 -0
- package/dist/types/canvas/canvas-controller.d.ts +159 -0
- package/dist/types/canvas/canvas-cursor-chat.d.ts +13 -0
- package/dist/types/canvas/canvas-cursor-chat.styles.d.ts +54 -0
- package/dist/types/canvas/canvas-menus.d.ts +21 -0
- package/dist/types/canvas/canvas-menus.styles.d.ts +6 -0
- package/dist/types/canvas/canvas-style-bar.d.ts +19 -0
- package/dist/types/canvas/canvas-style-bar.styles.d.ts +43 -0
- package/dist/types/canvas/canvas-surface.d.ts +15 -0
- package/dist/types/canvas/canvas-surface.styles.d.ts +313 -0
- package/dist/types/canvas/canvas-tool-rail.d.ts +41 -0
- package/dist/types/canvas/canvas-tool-rail.styles.d.ts +15 -0
- package/dist/types/canvas/comments.d.ts +106 -0
- package/dist/types/canvas/equality.d.ts +4 -0
- package/dist/types/canvas/export-png.d.ts +77 -0
- package/dist/types/canvas/gesture-machine.d.ts +46 -0
- package/dist/types/canvas/handlers.d.ts +7 -0
- package/dist/types/canvas/index.d.ts +18 -0
- package/dist/types/canvas/input.d.ts +63 -0
- package/dist/types/canvas/instant.d.ts +13 -0
- package/dist/types/canvas/kernel.d.ts +27 -0
- package/dist/types/canvas/motion.d.ts +72 -0
- package/dist/types/canvas/palette.d.ts +46 -0
- package/dist/types/canvas/random-id.d.ts +6 -0
- package/dist/types/canvas/scene-renderer.d.ts +27 -0
- package/dist/types/canvas/scene.styles.d.ts +4 -0
- package/dist/types/canvas/surface-model.d.ts +113 -0
- package/dist/types/canvas/uploads.d.ts +58 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/kernel/actions.d.ts +19 -0
- package/dist/types/kernel/board.d.ts +137 -0
- package/dist/types/kernel/claims.d.ts +29 -0
- package/dist/types/kernel/clipboard.d.ts +10 -0
- package/dist/types/kernel/constants.d.ts +195 -0
- package/dist/types/kernel/contract.d.ts +1533 -0
- package/dist/types/kernel/decode.d.ts +60 -0
- package/dist/types/kernel/editor.d.ts +12 -0
- package/dist/types/kernel/errors.d.ts +11 -0
- package/dist/types/kernel/fractional-index.d.ts +7 -0
- package/dist/types/kernel/geometry.d.ts +42 -0
- package/dist/types/kernel/hit-test.d.ts +16 -0
- package/dist/types/kernel/index.d.ts +8 -0
- package/dist/types/kernel/inspect.d.ts +6 -0
- package/dist/types/kernel/kernel.d.ts +6 -0
- package/dist/types/kernel/outline.d.ts +4 -0
- package/dist/types/kernel/plan.d.ts +20 -0
- package/dist/types/kernel/rev.d.ts +21 -0
- package/dist/types/kernel/scene.d.ts +16 -0
- package/dist/types/kernel/schema.d.ts +3436 -0
- package/dist/types/kernel/snap.d.ts +41 -0
- package/dist/types/kernel/svg.d.ts +3 -0
- package/dist/types/kernel/text.d.ts +21 -0
- package/docs/api.json +207 -0
- package/docs/canvas.md +444 -0
- package/docs/kernel.md +108 -0
- package/docs/llms.txt +41 -0
- package/docs/search-index.json +52 -0
- package/package.json +55 -4
|
@@ -0,0 +1,496 @@
|
|
|
1
|
+
import { widthStep } from "./assets.jsx";
|
|
2
|
+
import { instantLabel } from "./instant.jsx";
|
|
3
|
+
import { expectOk } from "./kernel.jsx";
|
|
4
|
+
import { resolvePalette, withHexColors } from "./palette.jsx";
|
|
5
|
+
// src/canvas/export-png.ts
|
|
6
|
+
/**
|
|
7
|
+
* A board as a PNG, drawn in the browser: the kernel's SVG of every shape,
|
|
8
|
+
* in the theme the board sits in, with its text font and pictures inlined so
|
|
9
|
+
* the SVG draws on its own, then rasterized through an `<img>` and a
|
|
10
|
+
* `<canvas>`. Presence, selections, drafts, pending proposals and the
|
|
11
|
+
* board's chrome are never drawn.
|
|
12
|
+
*/
|
|
13
|
+
/** Board units of margin around the shapes. */
|
|
14
|
+
const PADDING = 32;
|
|
15
|
+
/** Output pixels per board unit when the limits allow it. */
|
|
16
|
+
const PREFERRED_SCALE = 2;
|
|
17
|
+
/** The longest side, in pixels: the safe canvas side across browsers. */
|
|
18
|
+
const MAX_SIDE = 4096;
|
|
19
|
+
/** The most pixels, under Safari's 16,777,216-pixel canvas limit. */
|
|
20
|
+
const MAX_AREA = 16e6;
|
|
21
|
+
/** How long an image the host is still resolving may take before it draws as missing. */
|
|
22
|
+
const PENDING_IMAGE_MS = 8e3;
|
|
23
|
+
/**
|
|
24
|
+
* How many pictures are fetched and decoded at once. Over HTTP/2 a browser
|
|
25
|
+
* sends every request together, and a board of 150 screenshots would ask
|
|
26
|
+
* the file host for all of them at the same moment.
|
|
27
|
+
*/
|
|
28
|
+
const PICTURE_FETCHES = 6;
|
|
29
|
+
/** Data URL types `kernel.toSvg` takes; any other picture is redrawn as PNG. */
|
|
30
|
+
const RASTER_TYPES = /* @__PURE__ */ new Set([
|
|
31
|
+
"image/avif",
|
|
32
|
+
"image/gif",
|
|
33
|
+
"image/jpeg",
|
|
34
|
+
"image/png",
|
|
35
|
+
"image/webp"
|
|
36
|
+
]);
|
|
37
|
+
/** Generic families after the board's font, for when its file can't be fetched. */
|
|
38
|
+
const FALLBACK_FONTS = "system-ui, -apple-system, \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, sans-serif";
|
|
39
|
+
/**
|
|
40
|
+
* The output size for board bounds: twice the board's size when that fits,
|
|
41
|
+
* otherwise as large as a canvas every browser draws, keeping the aspect.
|
|
42
|
+
*/
|
|
43
|
+
function exportSize(bounds) {
|
|
44
|
+
const w = Math.max(bounds.w, 1);
|
|
45
|
+
const h = Math.max(bounds.h, 1);
|
|
46
|
+
const scale = Math.min(PREFERRED_SCALE, MAX_SIDE / Math.max(w, h), Math.sqrt(MAX_AREA / (w * h)));
|
|
47
|
+
return {
|
|
48
|
+
height: Math.max(1, Math.min(MAX_SIDE, Math.floor(h * scale))),
|
|
49
|
+
scale,
|
|
50
|
+
width: Math.max(1, Math.min(MAX_SIDE, Math.floor(w * scale)))
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/** Characters no file system takes, and control characters. */
|
|
54
|
+
const UNSAFE_FILE_CHARACTERS = /[\u0000-\u001f\u007f<>:"/\\|?*]+/g;
|
|
55
|
+
/** Names Windows reserves for devices, with or without an extension. */
|
|
56
|
+
const RESERVED_NAMES = /^(con|prn|aux|nul|com\d|lpt\d)$/i;
|
|
57
|
+
/**
|
|
58
|
+
* A file name for a board's PNG: its title without characters file
|
|
59
|
+
* systems refuse, or "canvas".
|
|
60
|
+
*/
|
|
61
|
+
function boardFileName(title) {
|
|
62
|
+
const base = (title ?? "").replace(UNSAFE_FILE_CHARACTERS, " ").replace(/\s+/g, " ").trim().replace(/^[.\s]+|[.\s]+$/g, "").slice(0, 120).trim();
|
|
63
|
+
return `${base === "" || RESERVED_NAMES.test(base) ? "canvas" : base}.png`;
|
|
64
|
+
}
|
|
65
|
+
/** Whether an item is part of the board itself, not someone's activity or a proposal. */
|
|
66
|
+
function onBoard(item) {
|
|
67
|
+
return item.key.startsWith("shape/");
|
|
68
|
+
}
|
|
69
|
+
/** Every coordinate pair in a path's data; the kernel writes absolute commands. */
|
|
70
|
+
function pathPoints(d) {
|
|
71
|
+
const numbers = (d.match(/-?\d*\.?\d+(?:e[-+]?\d+)?/gi) ?? []).map(Number);
|
|
72
|
+
const points = [];
|
|
73
|
+
for (let index = 0; index + 1 < numbers.length; index += 2) points.push({
|
|
74
|
+
x: numbers[index] ?? 0,
|
|
75
|
+
y: numbers[index + 1] ?? 0
|
|
76
|
+
});
|
|
77
|
+
return points;
|
|
78
|
+
}
|
|
79
|
+
/** The joint bounds of what a scene draws, or null when it draws nothing. */
|
|
80
|
+
function sceneBounds(items) {
|
|
81
|
+
let left = Number.POSITIVE_INFINITY;
|
|
82
|
+
let top = Number.POSITIVE_INFINITY;
|
|
83
|
+
let right = Number.NEGATIVE_INFINITY;
|
|
84
|
+
let bottom = Number.NEGATIVE_INFINITY;
|
|
85
|
+
const add = (x, y, margin) => {
|
|
86
|
+
left = Math.min(left, x - margin);
|
|
87
|
+
top = Math.min(top, y - margin);
|
|
88
|
+
right = Math.max(right, x + margin);
|
|
89
|
+
bottom = Math.max(bottom, y + margin);
|
|
90
|
+
};
|
|
91
|
+
for (const item of items) {
|
|
92
|
+
if ("box" in item) {
|
|
93
|
+
add(item.box.x, item.box.y, 0);
|
|
94
|
+
add(item.box.x + item.box.w, item.box.y + item.box.h, 0);
|
|
95
|
+
}
|
|
96
|
+
if (item._tag === "Path") {
|
|
97
|
+
const heads = item.start !== "none" || item.end !== "none";
|
|
98
|
+
const margin = item.width * (heads ? 8 : .5);
|
|
99
|
+
for (const point of pathPoints(item.d)) add(point.x, point.y, margin);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (!Number.isFinite(left)) return null;
|
|
103
|
+
return {
|
|
104
|
+
h: bottom - top,
|
|
105
|
+
w: right - left,
|
|
106
|
+
x: left,
|
|
107
|
+
y: top
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
/** The board's shapes as one scene, framed with a margin, or null for an empty board. */
|
|
111
|
+
function boardScene(canvas, board) {
|
|
112
|
+
if (board.shapes.length === 0) return null;
|
|
113
|
+
let left = Number.POSITIVE_INFINITY;
|
|
114
|
+
let top = Number.POSITIVE_INFINITY;
|
|
115
|
+
let right = Number.NEGATIVE_INFINITY;
|
|
116
|
+
let bottom = Number.NEGATIVE_INFINITY;
|
|
117
|
+
for (const row of board.shapes) {
|
|
118
|
+
left = Math.min(left, row.x, row.x + row.w);
|
|
119
|
+
top = Math.min(top, row.y, row.y + row.h);
|
|
120
|
+
right = Math.max(right, row.x, row.x + row.w);
|
|
121
|
+
bottom = Math.max(bottom, row.y, row.y + row.h);
|
|
122
|
+
}
|
|
123
|
+
const reach = Math.max(right - left, bottom - top, 1e3);
|
|
124
|
+
const items = expectOk(canvas.kernel.scene(board, {
|
|
125
|
+
h: bottom - top + 2 * reach,
|
|
126
|
+
viewer: "export",
|
|
127
|
+
w: right - left + 2 * reach,
|
|
128
|
+
x: left - reach,
|
|
129
|
+
y: top - reach,
|
|
130
|
+
zoom: 1
|
|
131
|
+
}, [], null)).items.filter(onBoard);
|
|
132
|
+
const bounds = sceneBounds(items);
|
|
133
|
+
if (bounds === null) return null;
|
|
134
|
+
return {
|
|
135
|
+
box: {
|
|
136
|
+
h: bounds.h + 64,
|
|
137
|
+
w: bounds.w + 64,
|
|
138
|
+
x: bounds.x - PADDING,
|
|
139
|
+
y: bounds.y - PADDING
|
|
140
|
+
},
|
|
141
|
+
items,
|
|
142
|
+
zoom: 1
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
const unquote = (value) => value.trim().replace(/^["']|["']$/g, "");
|
|
146
|
+
/** The page's `@font-face` rules, in style sheets the page may read. */
|
|
147
|
+
function pageFontFaces() {
|
|
148
|
+
const faces = [];
|
|
149
|
+
const visit = (rules, base) => {
|
|
150
|
+
for (const rule of rules) if (rule instanceof CSSImportRule) {
|
|
151
|
+
const sheet = rule.styleSheet;
|
|
152
|
+
if (sheet !== null) visit(readRules(sheet), sheet.href ?? base);
|
|
153
|
+
} else if (rule instanceof CSSFontFaceRule) {
|
|
154
|
+
const style = rule.style;
|
|
155
|
+
if (/italic|oblique/.test(style.getPropertyValue("font-style"))) continue;
|
|
156
|
+
const source = /url\((["']?)(.*?)\1\)\s*(?:format\((["']?)(.*?)\3\))?/.exec(style.getPropertyValue("src"));
|
|
157
|
+
if (source?.[2] === void 0) continue;
|
|
158
|
+
faces.push({
|
|
159
|
+
family: unquote(style.getPropertyValue("font-family")),
|
|
160
|
+
format: source[4] ?? null,
|
|
161
|
+
unicodeRange: style.getPropertyValue("unicode-range").trim(),
|
|
162
|
+
url: new URL(source[2], base).href,
|
|
163
|
+
weight: style.getPropertyValue("font-weight").trim()
|
|
164
|
+
});
|
|
165
|
+
} else if ("cssRules" in rule && rule.cssRules instanceof CSSRuleList) visit(rule.cssRules, base);
|
|
166
|
+
};
|
|
167
|
+
for (const sheet of document.styleSheets) visit(readRules(sheet), sheet.href ?? document.baseURI);
|
|
168
|
+
return faces;
|
|
169
|
+
}
|
|
170
|
+
/** A sheet's rules; a cross-origin sheet without CORS has none to read. */
|
|
171
|
+
function readRules(sheet) {
|
|
172
|
+
try {
|
|
173
|
+
return sheet.cssRules;
|
|
174
|
+
} catch {
|
|
175
|
+
return [];
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
/** Whether a `unicode-range` covers any of the code points; no range covers all. */
|
|
179
|
+
function covers(range, codePoints) {
|
|
180
|
+
if (range === "") return true;
|
|
181
|
+
return range.split(",").some((part) => {
|
|
182
|
+
const [low = "", high = low] = part.trim().replace(/^u\+/i, "").split("-");
|
|
183
|
+
const from = Number.parseInt(low.replaceAll("?", "0"), 16);
|
|
184
|
+
const to = Number.parseInt((high === low ? low.replaceAll("?", "F") : high).replaceAll("?", "F"), 16);
|
|
185
|
+
for (const point of codePoints) if (point >= from && point <= to) return true;
|
|
186
|
+
return false;
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
const fontFiles = /* @__PURE__ */ new Map();
|
|
190
|
+
/** A font file as a data URL, fetched once per page; null when it can't be. */
|
|
191
|
+
function fontFile(url) {
|
|
192
|
+
let file = fontFiles.get(url);
|
|
193
|
+
if (file === void 0) {
|
|
194
|
+
file = fetchDataUrl(url).catch(() => null);
|
|
195
|
+
fontFiles.set(url, file);
|
|
196
|
+
file.then((loaded) => {
|
|
197
|
+
if (loaded === null) fontFiles.delete(url);
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
return file;
|
|
201
|
+
}
|
|
202
|
+
async function fetchBlob(url, credentials = "same-origin") {
|
|
203
|
+
const response = await fetch(url, {
|
|
204
|
+
credentials,
|
|
205
|
+
mode: "cors"
|
|
206
|
+
});
|
|
207
|
+
if (!response.ok) throw new Error(`${url} answered ${response.status}`);
|
|
208
|
+
return response.blob();
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* A board picture's file. The board shows it through an `<img>`, which
|
|
212
|
+
* sends the viewer's cookies to another origin; a private file host needs
|
|
213
|
+
* them here too, so the fetch sends them. A host that answers any origin
|
|
214
|
+
* (`*`) refuses a fetch with credentials, so that one is tried without.
|
|
215
|
+
*/
|
|
216
|
+
function fetchPicture(url) {
|
|
217
|
+
return fetchBlob(url, "include").catch(() => fetchBlob(url));
|
|
218
|
+
}
|
|
219
|
+
async function fetchDataUrl(url) {
|
|
220
|
+
return dataUrlOf(await fetchBlob(url));
|
|
221
|
+
}
|
|
222
|
+
/** A file's media type without parameters, in lower case. */
|
|
223
|
+
function typeOf(blob) {
|
|
224
|
+
return blob.type.split(";")[0]?.trim().toLowerCase() ?? "";
|
|
225
|
+
}
|
|
226
|
+
/** A file as a base64 `data:` URL of its own type. */
|
|
227
|
+
async function dataUrlOf(blob, type = typeOf(blob)) {
|
|
228
|
+
const bytes = new Uint8Array(await blob.arrayBuffer());
|
|
229
|
+
let binary = "";
|
|
230
|
+
for (let index = 0; index < bytes.length; index += 32768) binary += String.fromCharCode(...bytes.subarray(index, index + 32768));
|
|
231
|
+
return `data:${type || "application/octet-stream"};base64,${btoa(binary)}`;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* CSS for the SVG: the board's text fonts as embedded `@font-face` rules,
|
|
235
|
+
* for the characters it uses, and then system fonts, since an SVG drawn
|
|
236
|
+
* through `<img>` can't use the page's fonts.
|
|
237
|
+
*/
|
|
238
|
+
async function fontCss(scene) {
|
|
239
|
+
const families = /* @__PURE__ */ new Set();
|
|
240
|
+
const codePoints = /* @__PURE__ */ new Set();
|
|
241
|
+
for (const item of scene.items) {
|
|
242
|
+
if (item._tag !== "TextLines") continue;
|
|
243
|
+
for (const family of item.font.families) families.add(family);
|
|
244
|
+
for (const line of item.lines) for (const character of line.text) codePoints.add(character.codePointAt(0) ?? 0);
|
|
245
|
+
}
|
|
246
|
+
if (families.size === 0) return "";
|
|
247
|
+
const faces = pageFontFaces().filter((face) => families.has(face.family) && covers(face.unicodeRange, codePoints));
|
|
248
|
+
const rules = await Promise.all(faces.map(async (face) => {
|
|
249
|
+
const file = await fontFile(face.url);
|
|
250
|
+
if (file === null) return "";
|
|
251
|
+
return [
|
|
252
|
+
"@font-face{",
|
|
253
|
+
`font-family:${JSON.stringify(face.family)};`,
|
|
254
|
+
`src:url(${JSON.stringify(file)})${face.format === null ? "" : ` format(${JSON.stringify(face.format)})`};`,
|
|
255
|
+
face.weight === "" ? "" : `font-weight:${face.weight};`,
|
|
256
|
+
face.unicodeRange === "" ? "" : `unicode-range:${face.unicodeRange};`,
|
|
257
|
+
"}"
|
|
258
|
+
].join("");
|
|
259
|
+
}));
|
|
260
|
+
const stack = [...families].map((family) => JSON.stringify(family));
|
|
261
|
+
return `${rules.join("")}text{font-family:${stack.join(",")},${FALLBACK_FONTS}}`;
|
|
262
|
+
}
|
|
263
|
+
/** An asset's source once the host has one, or null when it fails or takes too long. */
|
|
264
|
+
function readySource(assets, asset, width) {
|
|
265
|
+
const read = () => assets.resolve(asset, { width: widthStep(width) });
|
|
266
|
+
const first = read();
|
|
267
|
+
if (first.status !== "pending" || assets.subscribe === void 0) return Promise.resolve(first.status === "ready" ? first.src : null);
|
|
268
|
+
const subscribe = assets.subscribe;
|
|
269
|
+
return new Promise((resolve) => {
|
|
270
|
+
const finish = (src) => {
|
|
271
|
+
clearTimeout(timer);
|
|
272
|
+
unsubscribe();
|
|
273
|
+
resolve(src);
|
|
274
|
+
};
|
|
275
|
+
const timer = setTimeout(() => finish(null), PENDING_IMAGE_MS);
|
|
276
|
+
const unsubscribe = subscribe(() => {
|
|
277
|
+
const source = read();
|
|
278
|
+
if (source.status !== "pending") finish(source.status === "ready" ? source.src : null);
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
/** Loads an image from a URL the page may draw. */
|
|
283
|
+
function loadImage(src) {
|
|
284
|
+
return new Promise((resolve, reject) => {
|
|
285
|
+
const image = new Image();
|
|
286
|
+
image.decoding = "sync";
|
|
287
|
+
image.onload = () => resolve(image);
|
|
288
|
+
image.onerror = () => reject(/* @__PURE__ */ new Error("The image could not be decoded."));
|
|
289
|
+
image.src = src;
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
/** A canvas's pixels as a PNG, or as a JPEG for a photo. */
|
|
293
|
+
function encodeCanvas(canvas, type = "image/png") {
|
|
294
|
+
return new Promise((resolve, reject) => canvas.toBlob((blob) => blob === null ? reject(/* @__PURE__ */ new Error("The canvas could not be encoded.")) : resolve(blob), type, .92));
|
|
295
|
+
}
|
|
296
|
+
function drawnSize(box, scale) {
|
|
297
|
+
const side = (units) => Math.max(1, Math.min(MAX_SIDE, Math.ceil(units * scale)));
|
|
298
|
+
return {
|
|
299
|
+
height: side(box.h),
|
|
300
|
+
width: side(box.w)
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
/** A decoded picture drawn at `size`, as a PNG or a JPEG. */
|
|
304
|
+
async function drawnDataUrl(image, size, type) {
|
|
305
|
+
const drawing = document.createElement("canvas");
|
|
306
|
+
drawing.width = size.width;
|
|
307
|
+
drawing.height = size.height;
|
|
308
|
+
const context = drawing.getContext("2d");
|
|
309
|
+
if (context === null) throw new Error("The browser can't draw a canvas.");
|
|
310
|
+
context.imageSmoothingQuality = "high";
|
|
311
|
+
context.drawImage(image, 0, 0, size.width, size.height);
|
|
312
|
+
return dataUrlOf(await encodeCanvas(drawing, type));
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* A picture as a data URL `kernel.toSvg` takes, no larger than it is drawn:
|
|
316
|
+
* a raster file that fits as it is, a larger one scaled down, and anything
|
|
317
|
+
* else, such as an SVG, drawn to a PNG. Full-size files would make one SVG
|
|
318
|
+
* as large as every file together, tens of megabytes on a board of
|
|
319
|
+
* screenshots, for a PNG at most 4096 pixels wide.
|
|
320
|
+
*/
|
|
321
|
+
async function pictureDataUrl(src, size) {
|
|
322
|
+
const blob = await fetchPicture(src);
|
|
323
|
+
const type = typeOf(blob);
|
|
324
|
+
if (!RASTER_TYPES.has(type)) {
|
|
325
|
+
const url = URL.createObjectURL(blob);
|
|
326
|
+
try {
|
|
327
|
+
return await drawnDataUrl(await loadImage(url), size, "image/png");
|
|
328
|
+
} finally {
|
|
329
|
+
URL.revokeObjectURL(url);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
const bitmap = await createImageBitmap(blob);
|
|
333
|
+
try {
|
|
334
|
+
if (bitmap.width <= size.width && bitmap.height <= size.height) return await dataUrlOf(blob);
|
|
335
|
+
return await drawnDataUrl(bitmap, size, type === "image/jpeg" ? "image/jpeg" : "image/png");
|
|
336
|
+
} finally {
|
|
337
|
+
bitmap.close();
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* `work` on each item, at most `limit` at a time, with the results in the
|
|
342
|
+
* items' order.
|
|
343
|
+
*/
|
|
344
|
+
async function mapLimited(items, limit, work) {
|
|
345
|
+
const results = [];
|
|
346
|
+
const queue = items.entries();
|
|
347
|
+
const worker = async () => {
|
|
348
|
+
for (const [index, item] of queue) results[index] = await work(item);
|
|
349
|
+
};
|
|
350
|
+
await Promise.all(Array.from({ length: Math.min(limit, items.length) }, worker));
|
|
351
|
+
return results;
|
|
352
|
+
}
|
|
353
|
+
/** Below this width in board units the board's tile drops its words. */
|
|
354
|
+
const PLACEHOLDER_WORDS_MIN_WIDTH = 120;
|
|
355
|
+
/**
|
|
356
|
+
* The tile the board draws for an image it can't show: muted, with a
|
|
357
|
+
* dashed hairline and "Image unavailable", as a PNG at the size it shows.
|
|
358
|
+
*/
|
|
359
|
+
async function placeholderDataUrl(colors, box, scale) {
|
|
360
|
+
const drawing = document.createElement("canvas");
|
|
361
|
+
drawing.width = Math.max(1, Math.min(MAX_SIDE, Math.round(box.w * scale)));
|
|
362
|
+
drawing.height = Math.max(1, Math.min(MAX_SIDE, Math.round(box.h * scale)));
|
|
363
|
+
const context = drawing.getContext("2d");
|
|
364
|
+
if (context !== null) {
|
|
365
|
+
context.fillStyle = colors.fill;
|
|
366
|
+
context.fillRect(0, 0, drawing.width, drawing.height);
|
|
367
|
+
context.strokeStyle = colors.stroke;
|
|
368
|
+
context.lineWidth = scale;
|
|
369
|
+
context.setLineDash([4 * scale, 4 * scale]);
|
|
370
|
+
context.strokeRect(scale / 2, scale / 2, drawing.width - scale, drawing.height - scale);
|
|
371
|
+
if (box.w >= PLACEHOLDER_WORDS_MIN_WIDTH) {
|
|
372
|
+
context.fillStyle = colors.text;
|
|
373
|
+
context.font = `${16 * scale}px "Inter Variable", ${FALLBACK_FONTS}`;
|
|
374
|
+
context.textAlign = "center";
|
|
375
|
+
context.textBaseline = "middle";
|
|
376
|
+
context.fillText("Image unavailable", drawing.width / 2, drawing.height / 2);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
return dataUrlOf(await encodeCanvas(drawing));
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Each picture on the board as a data URL, so the SVG holds it and the
|
|
383
|
+
* canvas stays readable. A picture the host can't give, or that can't be
|
|
384
|
+
* fetched with CORS, draws as the board's "Image unavailable" tile and is
|
|
385
|
+
* named in `missing`.
|
|
386
|
+
*
|
|
387
|
+
* Every source is asked for in one turn, so a host that batches its answers
|
|
388
|
+
* sends one request, and only an answer the host never gives times out.
|
|
389
|
+
* Files are then fetched a few at a time, however long that takes.
|
|
390
|
+
*/
|
|
391
|
+
async function pictureUrls(scene, assets, scale, placeholder) {
|
|
392
|
+
const largest = /* @__PURE__ */ new Map();
|
|
393
|
+
for (const item of scene.items) {
|
|
394
|
+
if (item._tag !== "Image") continue;
|
|
395
|
+
const seen = largest.get(item.asset);
|
|
396
|
+
if (seen === void 0 || item.box.w > seen.w) largest.set(item.asset, item.box);
|
|
397
|
+
}
|
|
398
|
+
const entries = await mapLimited([...largest].map(([asset, box]) => {
|
|
399
|
+
const size = drawnSize(box, scale);
|
|
400
|
+
return {
|
|
401
|
+
asset,
|
|
402
|
+
box,
|
|
403
|
+
size,
|
|
404
|
+
source: assets === void 0 ? Promise.resolve(null) : readySource(assets, asset, size.width)
|
|
405
|
+
};
|
|
406
|
+
}), PICTURE_FETCHES, async ({ asset, box, size, source }) => {
|
|
407
|
+
const src = await source;
|
|
408
|
+
const picture = src === null ? null : await pictureDataUrl(src, size).catch(() => null);
|
|
409
|
+
return {
|
|
410
|
+
asset,
|
|
411
|
+
missing: picture === null,
|
|
412
|
+
url: picture ?? await placeholder(box)
|
|
413
|
+
};
|
|
414
|
+
});
|
|
415
|
+
return {
|
|
416
|
+
missing: entries.filter((entry) => entry.missing).map(({ asset }) => asset),
|
|
417
|
+
urls: Object.fromEntries(entries.map(({ asset, url }) => [asset, url]))
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* The kernel's SVG of a scene at an output size, with CSS added: `width` and
|
|
422
|
+
* `height` set the pixels it draws at, so no browser scales a bitmap.
|
|
423
|
+
*/
|
|
424
|
+
function exportSvg(canvas, scene, palette, pictures, size, css) {
|
|
425
|
+
const source = expectOk(canvas.kernel.toSvg(scene, palette, pictures, { formatInstant: instantLabel }));
|
|
426
|
+
const document = new DOMParser().parseFromString(source, "image/svg+xml");
|
|
427
|
+
const svg = document.documentElement;
|
|
428
|
+
svg.setAttribute("width", String(size.width));
|
|
429
|
+
svg.setAttribute("height", String(size.height));
|
|
430
|
+
svg.setAttribute("preserveAspectRatio", "none");
|
|
431
|
+
if (css !== "") {
|
|
432
|
+
const style = document.createElementNS("http://www.w3.org/2000/svg", "style");
|
|
433
|
+
style.textContent = css;
|
|
434
|
+
svg.prepend(style);
|
|
435
|
+
}
|
|
436
|
+
return new XMLSerializer().serializeToString(document);
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* Draws every shape on a board to a PNG in the browser, in the theme
|
|
440
|
+
* `element` sits in, on that theme's background. Rejects for an empty
|
|
441
|
+
* board or when the browser can't draw it.
|
|
442
|
+
*/
|
|
443
|
+
async function exportBoardPng(options) {
|
|
444
|
+
return (await drawBoardPng(options)).png;
|
|
445
|
+
}
|
|
446
|
+
async function drawBoardPng({ assets, board, canvas, element = document.body }) {
|
|
447
|
+
const scene = boardScene(canvas, board);
|
|
448
|
+
if (scene === null) throw new Error("The board has no shapes to export.");
|
|
449
|
+
const size = exportSize(scene.box);
|
|
450
|
+
const palette = resolvePalette(element);
|
|
451
|
+
const placeholder = withHexColors(element, (hex) => ({
|
|
452
|
+
fill: hex("var(--sui-surface-muted)"),
|
|
453
|
+
stroke: hex("var(--sui-border)"),
|
|
454
|
+
text: hex("var(--sui-text-muted)")
|
|
455
|
+
}));
|
|
456
|
+
const [pictures, css] = await Promise.all([pictureUrls(scene, assets, size.scale, (box) => placeholderDataUrl(placeholder, box, size.scale)), fontCss(scene)]);
|
|
457
|
+
const svg = exportSvg(canvas, scene, palette, pictures.urls, size, css);
|
|
458
|
+
const url = URL.createObjectURL(new Blob([svg], { type: "image/svg+xml;charset=utf-8" }));
|
|
459
|
+
try {
|
|
460
|
+
const image = await loadImage(url);
|
|
461
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
462
|
+
const drawing = document.createElement("canvas");
|
|
463
|
+
drawing.width = size.width;
|
|
464
|
+
drawing.height = size.height;
|
|
465
|
+
const context = drawing.getContext("2d");
|
|
466
|
+
if (context === null) throw new Error("The browser can't draw a canvas.");
|
|
467
|
+
context.fillStyle = palette.background;
|
|
468
|
+
context.fillRect(0, 0, size.width, size.height);
|
|
469
|
+
context.drawImage(image, 0, 0, size.width, size.height);
|
|
470
|
+
return {
|
|
471
|
+
missingPictures: pictures.missing.length,
|
|
472
|
+
png: await encodeCanvas(drawing)
|
|
473
|
+
};
|
|
474
|
+
} finally {
|
|
475
|
+
URL.revokeObjectURL(url);
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
/**
|
|
479
|
+
* Exports a board as `exportBoardPng` does and downloads it as
|
|
480
|
+
* `<title>.png`, or `canvas.png` without a title. Resolves with how many
|
|
481
|
+
* pictures the file shows as "Image unavailable".
|
|
482
|
+
*/
|
|
483
|
+
async function downloadBoardPng({ title, ...options }) {
|
|
484
|
+
const { missingPictures, png } = await drawBoardPng(options);
|
|
485
|
+
const url = URL.createObjectURL(png);
|
|
486
|
+
const link = document.createElement("a");
|
|
487
|
+
link.href = url;
|
|
488
|
+
link.download = boardFileName(title);
|
|
489
|
+
link.rel = "noopener";
|
|
490
|
+
document.body.append(link);
|
|
491
|
+
link.click();
|
|
492
|
+
link.remove();
|
|
493
|
+
setTimeout(() => URL.revokeObjectURL(url), 3e4);
|
|
494
|
+
return { missingPictures };
|
|
495
|
+
}
|
|
496
|
+
export { boardFileName, boardScene, downloadBoardPng, exportBoardPng, exportSize, exportSvg, pictureUrls };
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// src/canvas/gesture-machine.ts
|
|
2
|
+
const distance = (a, b) => Math.hypot(a.x - b.x, a.y - b.y);
|
|
3
|
+
const middle = (a, b) => ({
|
|
4
|
+
x: (a.x + b.x) / 2,
|
|
5
|
+
y: (a.y + b.y) / 2
|
|
6
|
+
});
|
|
7
|
+
/**
|
|
8
|
+
* Sorts touch from the pen and the mouse.
|
|
9
|
+
*
|
|
10
|
+
* - A mouse and a pen always go to the editor.
|
|
11
|
+
* - One finger draws and selects, until a pen is used. From then on, with a
|
|
12
|
+
* tool that leaves marks, a finger pans and only the pen draws, so a hand
|
|
13
|
+
* resting on the screen leaves no marks; with Select and Hand a finger
|
|
14
|
+
* still selects, drags and pans.
|
|
15
|
+
* - Two fingers pan and pinch-zoom; a second finger cancels what the first
|
|
16
|
+
* one started.
|
|
17
|
+
* - While a pen is down, touches are ignored.
|
|
18
|
+
*/
|
|
19
|
+
function createGestureMachine(handlers) {
|
|
20
|
+
const touches = /* @__PURE__ */ new Map();
|
|
21
|
+
/** The touch the editor is following, if any. */
|
|
22
|
+
let drawing = null;
|
|
23
|
+
let penSeen = false;
|
|
24
|
+
let penDown = false;
|
|
25
|
+
function down(id, kind, point) {
|
|
26
|
+
if (kind !== "touch") {
|
|
27
|
+
if (kind === "pen") {
|
|
28
|
+
penSeen = true;
|
|
29
|
+
penDown = true;
|
|
30
|
+
if (drawing !== null) {
|
|
31
|
+
handlers.cancel();
|
|
32
|
+
drawing = null;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return "forward";
|
|
36
|
+
}
|
|
37
|
+
if (penDown) return "absorb";
|
|
38
|
+
touches.set(id, point);
|
|
39
|
+
if (touches.size === 1 && !(penSeen && handlers.marks())) {
|
|
40
|
+
drawing = id;
|
|
41
|
+
return "forward";
|
|
42
|
+
}
|
|
43
|
+
if (drawing !== null) {
|
|
44
|
+
handlers.cancel();
|
|
45
|
+
drawing = null;
|
|
46
|
+
}
|
|
47
|
+
return "absorb";
|
|
48
|
+
}
|
|
49
|
+
function move(id, kind, point) {
|
|
50
|
+
if (kind !== "touch") return "forward";
|
|
51
|
+
const previous = touches.get(id);
|
|
52
|
+
if (previous === void 0) return "absorb";
|
|
53
|
+
if (drawing === id) {
|
|
54
|
+
touches.set(id, point);
|
|
55
|
+
return "forward";
|
|
56
|
+
}
|
|
57
|
+
const [, partner] = [...touches].filter(([other]) => other !== id)[0] ?? [];
|
|
58
|
+
if (partner === void 0) handlers.pan(previous.x - point.x, previous.y - point.y);
|
|
59
|
+
else {
|
|
60
|
+
const before = middle(previous, partner);
|
|
61
|
+
const after = middle(point, partner);
|
|
62
|
+
handlers.pan(before.x - after.x, before.y - after.y);
|
|
63
|
+
const spread = distance(previous, partner);
|
|
64
|
+
if (spread > 0) handlers.zoom(after, distance(point, partner) / spread);
|
|
65
|
+
}
|
|
66
|
+
touches.set(id, point);
|
|
67
|
+
return "absorb";
|
|
68
|
+
}
|
|
69
|
+
function up(id, kind) {
|
|
70
|
+
if (kind !== "touch") {
|
|
71
|
+
if (kind === "pen") penDown = false;
|
|
72
|
+
return "forward";
|
|
73
|
+
}
|
|
74
|
+
if (!touches.delete(id)) return "absorb";
|
|
75
|
+
if (drawing === id) {
|
|
76
|
+
drawing = null;
|
|
77
|
+
return "forward";
|
|
78
|
+
}
|
|
79
|
+
return "absorb";
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
/** Pointer cancel or lost capture: forget the pointer. */
|
|
83
|
+
cancel(id, kind) {
|
|
84
|
+
return up(id, kind);
|
|
85
|
+
},
|
|
86
|
+
down,
|
|
87
|
+
move,
|
|
88
|
+
up
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
export { createGestureMachine };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// src/canvas/handlers.ts
|
|
2
|
+
/**
|
|
3
|
+
* Calls an app's JSX event handler for an event the board also handles: Solid's handler forms are a
|
|
4
|
+
* function or a `[handler, data]` pair.
|
|
5
|
+
*/
|
|
6
|
+
function call(handler, event) {
|
|
7
|
+
callWith(handler, event);
|
|
8
|
+
}
|
|
9
|
+
/** Hands an element to an app's `ref`: a function, or an array of them (a ref spread from another part). */
|
|
10
|
+
function assignRef(ref, element) {
|
|
11
|
+
if (typeof ref === "function") ref(element);
|
|
12
|
+
else if (Array.isArray(ref)) for (const each of ref) assignRef(each, element);
|
|
13
|
+
}
|
|
14
|
+
function callWith(handler, event) {
|
|
15
|
+
if (typeof handler === "function") handler(event);
|
|
16
|
+
else if (Array.isArray(handler) && typeof handler[0] === "function") handler[0](handler[1], event);
|
|
17
|
+
}
|
|
18
|
+
export { assignRef, call };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { createMemoryBoardStore } from "./board-store.jsx";
|
|
2
|
+
import { CanvasBoard } from "./canvas-board.jsx";
|
|
3
|
+
import { CanvasStatus } from "./canvas-chrome.jsx";
|
|
4
|
+
import { CanvasProvider, useCanvas, useCanvasCommands, useCanvasKernel } from "./canvas-context.jsx";
|
|
5
|
+
import { CanvasSurface } from "./canvas-surface.jsx";
|
|
6
|
+
import { boardFileName, downloadBoardPng, exportBoardPng } from "./export-png.jsx";
|
|
7
|
+
import { loadCanvasKernel } from "./kernel.jsx";
|
|
8
|
+
import { resolvePalette } from "./palette.jsx";
|
|
9
|
+
export { CanvasBoard, CanvasProvider, CanvasStatus, CanvasSurface, boardFileName, createMemoryBoardStore, downloadBoardPng, exportBoardPng, loadCanvasKernel, resolvePalette, useCanvas, useCanvasCommands, useCanvasKernel };
|