@weasel-js/text-tools 0.0.0-stage → 1.19.1
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/LICENSE +21 -0
- package/README.md +37 -2
- package/dist/index.d.ts +578 -0
- package/dist/index.js +1137 -0
- package/dist/index.js.map +1 -0
- package/package.json +69 -4
package/dist/index.js
ADDED
|
@@ -0,0 +1,1137 @@
|
|
|
1
|
+
import { DEFAULT_TEXT_FILL, isTextData, measureTextBounds, textEngineGeneration, textLineBoxes, textClusters, TextOutlinesError, loadTextOutlines, textFitScale, DEFAULT_TEXT_STYLE, pointInTextPose, caretIndexAt, textToPathsByPaint, textToPath, runsToPlainText } from '@weasel-js/text';
|
|
2
|
+
import { shapePropertiesSchema, styleOptionLeaves, shapeToolOptions, toolSet, effectSourceFor, arrivalBounds, strokeOutsetPerAxis, inkReach, nodeMemo, PAINT_SLOT, paintsPose, defineTool, INSERT_DRAG_MODS, INSERT_REPOSITION_BINDING, insertBindingBehaviors, noteFontRead, withInheritedPaint, strokeCovers, toolOptionPaint, NodeOutlineError, registerPaintStandIn, asNodeId, shownLookup, scenePaintedPoseOf, defaultDrawOne, findMountedCanvas, inheritedPaintIn, nodesAsShown, sceneDerivedPathOf, worldToLocal, targetTransformOf, indexedCandidates, AUTO_POSE_DESCRIPTOR, derivedPartsOf, viewPreset } from '@weasel-js/core';
|
|
3
|
+
import { defineAction, ActionDisabledReason, isBody, shareToolOptions, withToolOptionDefault, layoutBoxOf } from '@weasel-js/routing';
|
|
4
|
+
import { depOf, anchorUnder } from '@weasel-js/path-tools';
|
|
5
|
+
import { useState, useLayoutEffect, useMemo, useRef, useEffect, useCallback } from 'react';
|
|
6
|
+
import { useLatest, isDev } from '@weasel-js/react';
|
|
7
|
+
import { useDepSource } from '@weasel-js/routing/react';
|
|
8
|
+
import { unionRects, transformPath, PATH_M, PATH_L, PATH_Z, poseFrameOf, meanScale, pathContainsPoint, boundsOfPath } from '@weasel-js/geom';
|
|
9
|
+
import { faceGeneration } from '@weasel-js/font';
|
|
10
|
+
import { textCommandFromPose, commandFill, dropShadowLayers } from '@weasel-js/renderer';
|
|
11
|
+
import { resolveStroke, resolveFill, INHERIT, rgbaToHex, isSolidPaint, mixOklab, parseColor, resolveScreenLength } from '@weasel-js/paint';
|
|
12
|
+
import { useTextEdit } from '@weasel-js/text-dom';
|
|
13
|
+
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
14
|
+
import { decimal } from '@weasel-js/quantity';
|
|
15
|
+
import { cursorFor } from '@weasel-js/cursor';
|
|
16
|
+
import { pickPreset, movePreset, resizePreset, editPreset } from '@weasel-js/editing';
|
|
17
|
+
|
|
18
|
+
// src/presets.ts
|
|
19
|
+
function textUnder(deps, world) {
|
|
20
|
+
const scene = deps?.scene;
|
|
21
|
+
if (!world || !scene || !deps?.textEdit || !depOf(deps)) return null;
|
|
22
|
+
const under = deps.nodeAtPoint?.(world);
|
|
23
|
+
if (!under) return null;
|
|
24
|
+
const text = effectSourceFor(scene, under, "items");
|
|
25
|
+
if (text === null || scene.isLocked(text) || anchorUnder(deps, world) !== -1) return null;
|
|
26
|
+
const data = scene.get(text)?.data;
|
|
27
|
+
return { id: String(text), length: isTextData(data) ? data.text.length : 0 };
|
|
28
|
+
}
|
|
29
|
+
var editEffectTextAction = defineAction({
|
|
30
|
+
id: "editEffectText",
|
|
31
|
+
label: "Edit text along the path",
|
|
32
|
+
// On the effect's body, so it outranks the untargeted anchor click; an anchor under the pointer gives the click back.
|
|
33
|
+
defaultBinding: [{ spec: { kind: "click", target: { kindOf: isBody }, mods: {} }, opts: { id: "editEffectText.click" } }],
|
|
34
|
+
eligible: { capability: "edits-anchors" },
|
|
35
|
+
requires: ["textEdit", "nodeAtPoint", "scene", "editAnchors", "view", "kitSettings"],
|
|
36
|
+
invoker: {
|
|
37
|
+
timing: "immediate",
|
|
38
|
+
run(deps, params) {
|
|
39
|
+
const hit = textUnder(deps, params?.world);
|
|
40
|
+
if (hit) deps.textEdit?.startEdit(hit.id, { caret: hit.length });
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
enabled: (deps, at) => textUnder(deps, at) ? true : ActionDisabledReason.NotApplicable
|
|
44
|
+
});
|
|
45
|
+
var editTextAtAction = defineAction({
|
|
46
|
+
id: "editTextAt",
|
|
47
|
+
label: "Edit text here",
|
|
48
|
+
defaultBinding: [{
|
|
49
|
+
spec: { kind: "doubleClick", target: { kindOf: isBody } },
|
|
50
|
+
opts: { id: "editTextAt.doubleClick" }
|
|
51
|
+
}],
|
|
52
|
+
eligible: { mode: "normal" },
|
|
53
|
+
requires: ["textEdit", "hitAt"],
|
|
54
|
+
invoker: {
|
|
55
|
+
timing: "immediate",
|
|
56
|
+
run: (deps, params) => {
|
|
57
|
+
const world = params?.world;
|
|
58
|
+
const hit = world ? deps.textEdit?.textAt(world) : null;
|
|
59
|
+
if (hit) deps.textEdit.startEdit(hit.id, { caret: hit.caret });
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
enabled: (deps, at) => {
|
|
63
|
+
if (!at || deps?.hitAt?.(at)?.doubleClick) return ActionDisabledReason.NotApplicable;
|
|
64
|
+
return deps?.textEdit?.textAt(at) ? true : ActionDisabledReason.NotApplicable;
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
// src/actions/enterTextEdit.ts
|
|
69
|
+
var enterTextEditAction = {
|
|
70
|
+
id: "enterTextEdit",
|
|
71
|
+
label: "Enter text edit",
|
|
72
|
+
eligible: { mode: "normal" },
|
|
73
|
+
requires: ["textEdit", "operands"],
|
|
74
|
+
invoker: {
|
|
75
|
+
timing: "immediate",
|
|
76
|
+
run: (deps) => {
|
|
77
|
+
const sel = deps.operands?.get() ?? [];
|
|
78
|
+
if (sel.length !== 1) return;
|
|
79
|
+
const id = sel[0];
|
|
80
|
+
const textEdit = deps.textEdit;
|
|
81
|
+
if (!textEdit) return;
|
|
82
|
+
if (textEdit.isTextNode && !textEdit.isTextNode(id)) return;
|
|
83
|
+
textEdit.startEdit(id);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
function drawOneEditing(editingId, base = defaultDrawOne) {
|
|
88
|
+
return (node, pose, view, ctx) => {
|
|
89
|
+
const out = base(node, pose, view, ctx);
|
|
90
|
+
return node.id === editingId ? withoutText(out) : out;
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function withoutText(cmds) {
|
|
94
|
+
const out = [];
|
|
95
|
+
for (const c of cmds) {
|
|
96
|
+
if (c.kind === "text") continue;
|
|
97
|
+
if (c.kind !== "group") {
|
|
98
|
+
out.push(c);
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
const children = withoutText(c.children);
|
|
102
|
+
if (children.length > 0) out.push({ ...c, children });
|
|
103
|
+
}
|
|
104
|
+
return out;
|
|
105
|
+
}
|
|
106
|
+
function textEffectItems(data, pose) {
|
|
107
|
+
noteFontRead();
|
|
108
|
+
let clusters;
|
|
109
|
+
try {
|
|
110
|
+
clusters = textClusters(data, { width: pose.width });
|
|
111
|
+
} catch (err) {
|
|
112
|
+
if (!(err instanceof TextOutlinesError)) throw err;
|
|
113
|
+
loadTextOutlines(data).catch(() => {
|
|
114
|
+
});
|
|
115
|
+
return [];
|
|
116
|
+
}
|
|
117
|
+
const k = scaleOf(pose);
|
|
118
|
+
const grow = k === 1 ? null : [k, 0, 0, k, 0, 0];
|
|
119
|
+
return clusters.map((c) => ({
|
|
120
|
+
length: c.advance * k,
|
|
121
|
+
middle: c.middle * k,
|
|
122
|
+
parts: c.paths.map((p) => ({
|
|
123
|
+
path: grow === null ? p.path : transformPath(p.path, grow),
|
|
124
|
+
fill: p.fill,
|
|
125
|
+
stroke: p.stroke ?? null
|
|
126
|
+
})),
|
|
127
|
+
bands: c.rules.map((r) => ({
|
|
128
|
+
x0: r.x0 * k,
|
|
129
|
+
x1: r.x1 * k,
|
|
130
|
+
y0: r.y0 * k,
|
|
131
|
+
y1: r.y1 * k,
|
|
132
|
+
fill: r.fill,
|
|
133
|
+
stroke: r.stroke ?? null
|
|
134
|
+
}))
|
|
135
|
+
}));
|
|
136
|
+
}
|
|
137
|
+
function scaleOf(pose) {
|
|
138
|
+
const m = poseFrameOf(pose);
|
|
139
|
+
return m === null ? 1 : Math.sqrt(Math.abs(m[0] * m[3] - m[1] * m[2]));
|
|
140
|
+
}
|
|
141
|
+
function textOutlineOf(d, box, inherited) {
|
|
142
|
+
const { text, runs, style, verticalAlign, fit, fill, stroke } = withInheritedPaint(d, inherited);
|
|
143
|
+
const data = { text, runs, style, verticalAlign, fit, fill, stroke };
|
|
144
|
+
return {
|
|
145
|
+
stroked: strokeCovers(stroke) || !!runs?.some((r) => strokeCovers(r.stroke)),
|
|
146
|
+
path: () => outlined(() => textToPath(data, box)),
|
|
147
|
+
parts: () => outlined(() => textToPathsByPaint(data, box)),
|
|
148
|
+
load: () => loadTextOutlines(data)
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
function outlined(build) {
|
|
152
|
+
try {
|
|
153
|
+
return build();
|
|
154
|
+
} catch (err) {
|
|
155
|
+
if (!(err instanceof TextOutlinesError)) throw err;
|
|
156
|
+
throw new NodeOutlineError(err.message, {
|
|
157
|
+
summary: `Text in "${err.family}" can't be converted to outlines`,
|
|
158
|
+
pending: err.reason === "outlines-loading",
|
|
159
|
+
cause: err
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
var BLACK = [0, 0, 0, 1];
|
|
164
|
+
function edgeColor(background, shade) {
|
|
165
|
+
const paint = background.paint;
|
|
166
|
+
if (paint === void 0 || !isSolidPaint(paint)) return null;
|
|
167
|
+
return rgbaToHex(mixOklab(BLACK, parseColor(paint.color), Math.min(1, Math.max(0, shade))));
|
|
168
|
+
}
|
|
169
|
+
function textFrameOf(d, box) {
|
|
170
|
+
const bg = resolveFill(d.background);
|
|
171
|
+
if (!bg) return { shadow: null, edge: null };
|
|
172
|
+
return { shadow: shadowOf(d.shadow, box), edge: edgeOf(d.edge, bg, box) };
|
|
173
|
+
}
|
|
174
|
+
function shadowOf(s, box) {
|
|
175
|
+
if (!s || !(s.alpha > 0)) return null;
|
|
176
|
+
const { paths, alpha } = dropShadowLayers(box, 0, s);
|
|
177
|
+
return { paths, color: rgbaToHex([0, 0, 0, Math.min(1, s.alpha)]), opacity: alpha };
|
|
178
|
+
}
|
|
179
|
+
function edgeOf(edge, bg, box) {
|
|
180
|
+
if (!edge || !(edge.width > 0)) return null;
|
|
181
|
+
const color = edgeColor(bg, edge.shade);
|
|
182
|
+
if (color === null) return null;
|
|
183
|
+
const w = Math.min(edge.width, box.width / 2, box.height / 2);
|
|
184
|
+
return {
|
|
185
|
+
path: { kind: "rect", x: box.x + w / 2, y: box.y + w / 2, width: box.width - w, height: box.height - w },
|
|
186
|
+
color,
|
|
187
|
+
width: w
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
function textShadowBox(d, box) {
|
|
191
|
+
const s = d.shadow;
|
|
192
|
+
if (!s || !(s.alpha > 0) || !resolveFill(d.background)) return null;
|
|
193
|
+
const e = Math.max(0, s.blur) / 2;
|
|
194
|
+
return { x: box.x + s.x - e, y: box.y + s.y - e, width: box.width + 2 * e, height: box.height + 2 * e };
|
|
195
|
+
}
|
|
196
|
+
function clippedToBox(cmd, box) {
|
|
197
|
+
return {
|
|
198
|
+
kind: "group",
|
|
199
|
+
clip: { kind: "rect", x: box.x, y: box.y, width: box.width, height: box.height },
|
|
200
|
+
children: [cmd]
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
function textBoxOf(d, p) {
|
|
204
|
+
const pad = Math.max(0, d.padding ?? 0);
|
|
205
|
+
const px = Math.min(pad, p.width / 2);
|
|
206
|
+
const py = Math.min(pad, p.height / 2);
|
|
207
|
+
return { x: p.x + px, y: p.y + py, width: p.width - 2 * px, height: p.height - 2 * py };
|
|
208
|
+
}
|
|
209
|
+
function textPoseOf(d, p, inherited) {
|
|
210
|
+
return {
|
|
211
|
+
...textBoxOf(d, p),
|
|
212
|
+
text: d.text,
|
|
213
|
+
runs: d.runs,
|
|
214
|
+
style: d.style,
|
|
215
|
+
fill: d.fill === INHERIT ? resolveFill(d.fill, inherited?.fill) : d.fill,
|
|
216
|
+
stroke: resolveStroke(d.stroke, inherited?.stroke) ?? void 0,
|
|
217
|
+
verticalAlign: d.verticalAlign,
|
|
218
|
+
fit: d.fit
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
var TEXT_PAINTER = {
|
|
222
|
+
id: "kit:text",
|
|
223
|
+
snapsToBox: true,
|
|
224
|
+
matches: (node) => {
|
|
225
|
+
if (!paintsPose(node.pose)) return false;
|
|
226
|
+
const d = node.data;
|
|
227
|
+
return d?.text != null;
|
|
228
|
+
},
|
|
229
|
+
// Memoized because the renderer's layout cache keys on the `ResolvedRun[]` array
|
|
230
|
+
// identity: a fresh runs array per frame would leave that cache missing on every
|
|
231
|
+
// draw. Both resolvers are pure style merging — no font reads — so `(data, pose)` is
|
|
232
|
+
// the whole key, with the view scale beside it for `{ px }` text. See PAINT_SLOT.
|
|
233
|
+
paint: (node, pose, ctx) => {
|
|
234
|
+
const d = node.data;
|
|
235
|
+
const inherited = ctx?.inherited;
|
|
236
|
+
const scale = textLayoutScale(d, ctx?.scale);
|
|
237
|
+
if (scale === 1) return nodeMemo(node, PAINT_SLOT, pose, () => paintText(d, pose, inherited, 1), inherited);
|
|
238
|
+
const held = nodeMemo(
|
|
239
|
+
node,
|
|
240
|
+
SCREEN_PAINT_SLOT,
|
|
241
|
+
pose,
|
|
242
|
+
() => ({ scale, inherited, cmds: paintText(d, pose, inherited, scale) })
|
|
243
|
+
);
|
|
244
|
+
if (held.scale !== scale || held.inherited !== inherited) {
|
|
245
|
+
held.scale = scale;
|
|
246
|
+
held.inherited = inherited;
|
|
247
|
+
held.cmds = paintText(d, pose, inherited, scale);
|
|
248
|
+
}
|
|
249
|
+
return held.cmds;
|
|
250
|
+
},
|
|
251
|
+
// The pose is a layout box, not a bounding box: the union of the line boxes is what
|
|
252
|
+
// the node actually covers, so picking, lasso, and clipping stop grabbing blank space.
|
|
253
|
+
//
|
|
254
|
+
// `null` rather than an empty path when there are no non-blank lines: a caller
|
|
255
|
+
// reading "no silhouette" falls back to the pose rect, which keeps an empty text
|
|
256
|
+
// node pickable.
|
|
257
|
+
//
|
|
258
|
+
// A background is ink across the whole box, so a node with one is its box.
|
|
259
|
+
// A clipped node's lines are cut to the box, as they are drawn.
|
|
260
|
+
silhouette: (node, pose, ctx) => {
|
|
261
|
+
const d = node.data;
|
|
262
|
+
if (resolveFill(d.background)) {
|
|
263
|
+
return { kind: "rect", x: pose.x, y: pose.y, width: pose.width, height: pose.height };
|
|
264
|
+
}
|
|
265
|
+
const lines = textLineBoxes(textPoseOf(d, pose), { scale: textLayoutScale(d, ctx?.scale) });
|
|
266
|
+
const boxes = d.overflow === "clip" ? cutRects(lines, pose) : lines;
|
|
267
|
+
if (boxes.length === 0) return null;
|
|
268
|
+
return rectsToPath(boxes);
|
|
269
|
+
},
|
|
270
|
+
// `filled` is unconditional, `data.fill: null` included: the silhouette above is line
|
|
271
|
+
// boxes, not glyph ink, so reporting outline-only text as unfilled would leave it
|
|
272
|
+
// grabbable within a stroke width of a box edge and nowhere near the letters.
|
|
273
|
+
ink: (node, _pose, ctx) => {
|
|
274
|
+
const d = node.data;
|
|
275
|
+
return { filled: true, ...inkReach(resolveStroke(d.stroke, ctx?.inherited?.stroke), ctx?.scale) };
|
|
276
|
+
},
|
|
277
|
+
drawnBounds: (node, pose, ctx) => {
|
|
278
|
+
const d = node.data;
|
|
279
|
+
const stroke = resolveStroke(d.stroke, ctx?.inherited?.stroke);
|
|
280
|
+
const lines = stroke ? strokedLinesBox(pose, textLineBoxes(textPoseOf(d, pose, ctx?.inherited), { scale: textLayoutScale(d, ctx?.scale) }), strokeOutsetPerAxis(stroke, ctx)) : null;
|
|
281
|
+
const shadow = textShadowBox(d, pose);
|
|
282
|
+
return shadow ? unionRects([lines ?? pose, shadow]) : lines;
|
|
283
|
+
},
|
|
284
|
+
outline: (node, pose, ctx) => {
|
|
285
|
+
const d = node.data;
|
|
286
|
+
return textOutlineOf(d, { ...pose, ...textBoxOf(d, pose) }, ctx?.inherited);
|
|
287
|
+
},
|
|
288
|
+
// Line boxes and glyphs follow the faces and the registered layout engines.
|
|
289
|
+
geometryGeneration: () => faceGeneration() + textEngineGeneration(),
|
|
290
|
+
silhouetteKey: (node, ctx) => textLayoutScale(node.data, ctx?.scale),
|
|
291
|
+
effectItems: (node, pose) => textEffectItems(node.data, pose)
|
|
292
|
+
};
|
|
293
|
+
function textLayoutScale(d, scale) {
|
|
294
|
+
if (scale === void 0 || scale === 1) return 1;
|
|
295
|
+
const sized = (s) => typeof s?.fontSize === "object" || typeof s?.letterSpacing === "object";
|
|
296
|
+
return sized(d.style) || (d.runs?.some(sized) ?? false) ? scale : 1;
|
|
297
|
+
}
|
|
298
|
+
var SCREEN_PAINT_SLOT = "shape:paint:text-screen";
|
|
299
|
+
function paintText(d, pose, inherited, scale) {
|
|
300
|
+
const laid = textCommandFromPose(textPoseOf(d, pose, inherited), scale);
|
|
301
|
+
const text = d.overflow === "clip" ? clippedToBox(laid, pose) : laid;
|
|
302
|
+
const bg = resolveFill(d.background);
|
|
303
|
+
if (!bg) return [text];
|
|
304
|
+
const fill = commandFill(bg, pose);
|
|
305
|
+
const { shadow, edge } = textFrameOf(d, pose);
|
|
306
|
+
const out = [];
|
|
307
|
+
if (shadow) {
|
|
308
|
+
const paint = { paint: { kind: "solid", color: shadow.color } };
|
|
309
|
+
out.push({ kind: "group", alpha: shadow.opacity, children: shadow.paths.map((path) => ({ kind: "path", path, fill: paint })) });
|
|
310
|
+
}
|
|
311
|
+
out.push({ kind: "path", path: { kind: "rect", x: pose.x, y: pose.y, width: pose.width, height: pose.height }, ...fill ? { fill } : {} });
|
|
312
|
+
if (edge) out.push({ kind: "path", path: edge.path, stroke: { paint: { kind: "solid", color: edge.color }, width: edge.width } });
|
|
313
|
+
out.push(text);
|
|
314
|
+
return out;
|
|
315
|
+
}
|
|
316
|
+
function cutRects(rects, box) {
|
|
317
|
+
const out = [];
|
|
318
|
+
for (const r of rects) {
|
|
319
|
+
const x0 = Math.max(r.x, box.x);
|
|
320
|
+
const y0 = Math.max(r.y, box.y);
|
|
321
|
+
const x1 = Math.min(r.x + r.width, box.x + box.width);
|
|
322
|
+
const y1 = Math.min(r.y + r.height, box.y + box.height);
|
|
323
|
+
if (x1 > x0 && y1 > y0) out.push({ x: x0, y: y0, width: x1 - x0, height: y1 - y0 });
|
|
324
|
+
}
|
|
325
|
+
return out;
|
|
326
|
+
}
|
|
327
|
+
function strokedLinesBox(pose, lines, reach) {
|
|
328
|
+
if (!(reach.x > 0 || reach.y > 0)) return null;
|
|
329
|
+
let x0 = pose.x, y0 = pose.y, x1 = pose.x + pose.width, y1 = pose.y + pose.height;
|
|
330
|
+
for (const l of lines) {
|
|
331
|
+
const lx0 = Math.max(l.x, pose.x), ly0 = Math.max(l.y, pose.y);
|
|
332
|
+
const lx1 = Math.min(l.x + l.width, pose.x + pose.width), ly1 = Math.min(l.y + l.height, pose.y + pose.height);
|
|
333
|
+
if (lx1 <= lx0 || ly1 <= ly0) continue;
|
|
334
|
+
x0 = Math.min(x0, lx0 - reach.x);
|
|
335
|
+
y0 = Math.min(y0, ly0 - reach.y);
|
|
336
|
+
x1 = Math.max(x1, lx1 + reach.x);
|
|
337
|
+
y1 = Math.max(y1, ly1 + reach.y);
|
|
338
|
+
}
|
|
339
|
+
return { x: x0, y: y0, width: x1 - x0, height: y1 - y0 };
|
|
340
|
+
}
|
|
341
|
+
function rectsToPath(rects) {
|
|
342
|
+
const commands = new Uint8Array(rects.length * 6);
|
|
343
|
+
const coords = new Float32Array(rects.length * 10);
|
|
344
|
+
let ci = 0;
|
|
345
|
+
let cmd = 0;
|
|
346
|
+
for (const r of rects) {
|
|
347
|
+
const { x, y, width: w, height: h } = r;
|
|
348
|
+
commands[cmd++] = PATH_M;
|
|
349
|
+
coords[ci++] = x;
|
|
350
|
+
coords[ci++] = y;
|
|
351
|
+
commands[cmd++] = PATH_L;
|
|
352
|
+
coords[ci++] = x + w;
|
|
353
|
+
coords[ci++] = y;
|
|
354
|
+
commands[cmd++] = PATH_L;
|
|
355
|
+
coords[ci++] = x + w;
|
|
356
|
+
coords[ci++] = y + h;
|
|
357
|
+
commands[cmd++] = PATH_L;
|
|
358
|
+
coords[ci++] = x;
|
|
359
|
+
coords[ci++] = y + h;
|
|
360
|
+
commands[cmd++] = PATH_L;
|
|
361
|
+
coords[ci++] = x;
|
|
362
|
+
coords[ci++] = y;
|
|
363
|
+
commands[cmd++] = PATH_Z;
|
|
364
|
+
}
|
|
365
|
+
return { kind: "polygon", commands, coords, fillRule: "nonzero" };
|
|
366
|
+
}
|
|
367
|
+
function textHitAt(scene, read, cx, cy) {
|
|
368
|
+
const order = indexedOrderAt(scene, cx, cy) ?? nodesAsShown(scene.overrides, scene.renderOrderNodes());
|
|
369
|
+
const shown = shownLookup(scene);
|
|
370
|
+
const paintedPoseOf = scenePaintedPoseOf(scene);
|
|
371
|
+
const derivedPathOf = sceneDerivedPathOf(scene);
|
|
372
|
+
for (let i = order.length - 1; i >= 0; i--) {
|
|
373
|
+
const node = order[i];
|
|
374
|
+
if (scene.isLocked(node.id) || scene.isHidden(node.id)) continue;
|
|
375
|
+
if (!read.isText(node.data)) {
|
|
376
|
+
const source = effectSourceFor(scene, node.id, "items");
|
|
377
|
+
const text = source === null || scene.isLocked(source) ? void 0 : shown.get(source);
|
|
378
|
+
if (text === void 0 || !read.isText(text.data)) continue;
|
|
379
|
+
const path = derivedPathOf(node);
|
|
380
|
+
if (path !== null && onAGlyph(path, cx, cy)) return { id: String(source), caret: read.text(text.data).length };
|
|
381
|
+
continue;
|
|
382
|
+
}
|
|
383
|
+
const at = paintedPoseOf(node);
|
|
384
|
+
const p = worldToLocal(targetTransformOf(at), cx, cy);
|
|
385
|
+
if (!p) continue;
|
|
386
|
+
const pose = {
|
|
387
|
+
...textBoxOf({ padding: read.padding(node.data) }, at),
|
|
388
|
+
text: read.text(node.data),
|
|
389
|
+
runs: read.runs(node.data),
|
|
390
|
+
style: read.style(node.data),
|
|
391
|
+
verticalAlign: read.verticalAlign(node.data),
|
|
392
|
+
fit: read.fit?.(node.data)
|
|
393
|
+
};
|
|
394
|
+
const box = { x: at.x, y: at.y, width: at.width, height: at.height };
|
|
395
|
+
if (!pointInTextPose(p.x, p.y, { ...pose, ...box })) continue;
|
|
396
|
+
return { id: String(node.id), caret: caretIndexAt(p.x, p.y, pose) };
|
|
397
|
+
}
|
|
398
|
+
return null;
|
|
399
|
+
}
|
|
400
|
+
function indexedOrderAt(scene, cx, cy) {
|
|
401
|
+
const broad = { box: { x: cx, y: cy, width: 0, height: 0 } };
|
|
402
|
+
const found = indexedCandidates(scene, AUTO_POSE_DESCRIPTOR, () => broad);
|
|
403
|
+
return found;
|
|
404
|
+
}
|
|
405
|
+
function onAGlyph(path, x, y) {
|
|
406
|
+
const parts = derivedPartsOf(path);
|
|
407
|
+
if (parts === void 0) return pathContainsPoint(path, x, y);
|
|
408
|
+
return parts.some(({ path: part }) => {
|
|
409
|
+
const b = boundsOfPath(part);
|
|
410
|
+
return x >= b.x && x <= b.x + b.width && y >= b.y && y <= b.y + b.height;
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
var editors = /* @__PURE__ */ new Map();
|
|
414
|
+
function registerHostTextEditor(container, scene, dep) {
|
|
415
|
+
const key = /* @__PURE__ */ Symbol("textEditor");
|
|
416
|
+
editors.set(key, { container, scene, dep });
|
|
417
|
+
const standIn = registerPaintStandIn(scene, container, withoutText);
|
|
418
|
+
return {
|
|
419
|
+
setEditing(id) {
|
|
420
|
+
if (editors.has(key)) standIn.show(id);
|
|
421
|
+
},
|
|
422
|
+
dispose() {
|
|
423
|
+
editors.delete(key);
|
|
424
|
+
standIn.dispose();
|
|
425
|
+
}
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
function hostTextEditorHolds(el) {
|
|
429
|
+
for (const e of editors.values()) if (e.container.contains(el)) return true;
|
|
430
|
+
return false;
|
|
431
|
+
}
|
|
432
|
+
function hostTextEditDep(el, scene) {
|
|
433
|
+
for (const e of editors.values()) if (e.scene === scene && e.container.contains(el)) return e.dep;
|
|
434
|
+
return null;
|
|
435
|
+
}
|
|
436
|
+
function textEditJoin(id) {
|
|
437
|
+
return { coalesceKey: `textEdit:${id}` };
|
|
438
|
+
}
|
|
439
|
+
function editedData(data, edit, { setText, setRuns, setStyle }) {
|
|
440
|
+
let next = setText ? setText(data, edit.text) : { ...data, text: edit.text };
|
|
441
|
+
if (edit.runs) next = setRuns ? setRuns(next, [...edit.runs]) : { ...next, runs: edit.runs };
|
|
442
|
+
if (edit.style) next = setStyle ? setStyle(next, edit.style) : { ...next, style: edit.style };
|
|
443
|
+
return next;
|
|
444
|
+
}
|
|
445
|
+
function sceneTextDrafts(sceneRef, optsRef) {
|
|
446
|
+
let held = null;
|
|
447
|
+
const release = (id) => {
|
|
448
|
+
if (held?.id !== id) return;
|
|
449
|
+
held.hold.drop();
|
|
450
|
+
held = null;
|
|
451
|
+
};
|
|
452
|
+
return {
|
|
453
|
+
draft: (id, draft) => {
|
|
454
|
+
const scene = sceneRef.current;
|
|
455
|
+
if (scene.get(asNodeId(id)) === void 0) return;
|
|
456
|
+
if (held !== null && (held.id !== id || held.scene !== scene)) release(held.id);
|
|
457
|
+
held ??= { id, scene, hold: scene.overrides.hold() };
|
|
458
|
+
const opts = optsRef.current;
|
|
459
|
+
held.hold.show([[asNodeId(id), { data: (stored) => editedData(stored, draft, opts) }]]);
|
|
460
|
+
},
|
|
461
|
+
commit: (id, data) => {
|
|
462
|
+
const scene = sceneRef.current;
|
|
463
|
+
scene.batch("Edit text", () => scene.update(asNodeId(id), { data }), textEditJoin(id));
|
|
464
|
+
release(id);
|
|
465
|
+
},
|
|
466
|
+
end: release,
|
|
467
|
+
close: () => {
|
|
468
|
+
if (held !== null) release(held.id);
|
|
469
|
+
}
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
function screenPoseOf(d, painted, read, view, origin) {
|
|
473
|
+
const inset = textBoxOf({ padding: read.padding(d) }, painted);
|
|
474
|
+
const box = screenBoxOf({ ...painted, ...inset }, view, origin);
|
|
475
|
+
const style = read.style(d);
|
|
476
|
+
const runs = read.runs(d);
|
|
477
|
+
const scale = textLayoutScale({ style, runs }, view ? meanScale(view.scale) : void 0);
|
|
478
|
+
const k = textFitScale({
|
|
479
|
+
...inset,
|
|
480
|
+
text: read.text(d),
|
|
481
|
+
runs,
|
|
482
|
+
style,
|
|
483
|
+
verticalAlign: read.verticalAlign(d),
|
|
484
|
+
fit: read.fit?.(d)
|
|
485
|
+
}, scale);
|
|
486
|
+
const clip = read.overflow(d) === "clip" ? clipToBox(inset, painted) : null;
|
|
487
|
+
return {
|
|
488
|
+
...box,
|
|
489
|
+
width: box.width / k,
|
|
490
|
+
height: box.height / k,
|
|
491
|
+
zoom: box.zoom * k,
|
|
492
|
+
fontSize: resolveScreenLength(style?.fontSize ?? DEFAULT_TEXT_STYLE.fontSize, scale),
|
|
493
|
+
pxScale: scale,
|
|
494
|
+
verticalAlign: read.verticalAlign(d),
|
|
495
|
+
...clip ? { clip: { top: clip.top / k, left: clip.left / k, bottom: clip.bottom / k, right: clip.right / k } } : {}
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
function clipToBox(inner, box) {
|
|
499
|
+
return {
|
|
500
|
+
top: inner.y - box.y,
|
|
501
|
+
left: inner.x - box.x,
|
|
502
|
+
bottom: box.y + box.height - (inner.y + inner.height),
|
|
503
|
+
right: box.x + box.width - (inner.x + inner.width)
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
function screenBoxOf(pose, view, origin) {
|
|
507
|
+
const zoom = view ? view.scale.x : 1;
|
|
508
|
+
const zoomY = view ? view.scale.y : 1;
|
|
509
|
+
const cx = (origin?.x ?? 0) + (pose.x + pose.width / 2 - (view?.x ?? 0)) * zoom;
|
|
510
|
+
const cy = (origin?.y ?? 0) + (pose.y + pose.height / 2 - (view?.y ?? 0)) * zoomY;
|
|
511
|
+
return {
|
|
512
|
+
x: cx - pose.width * zoom / 2,
|
|
513
|
+
y: cy - pose.height * zoom / 2,
|
|
514
|
+
width: pose.width,
|
|
515
|
+
height: pose.height,
|
|
516
|
+
zoom,
|
|
517
|
+
frame: frameLinearOf(pose, zoomY / zoom)
|
|
518
|
+
};
|
|
519
|
+
}
|
|
520
|
+
function frameLinearOf(pose, stretch) {
|
|
521
|
+
const m = poseFrameOf(pose);
|
|
522
|
+
if (!m && stretch === 1) return void 0;
|
|
523
|
+
const [a, b, c, d] = m ?? [1, 0, 0, 1];
|
|
524
|
+
return [a, b * stretch, c, d * stretch];
|
|
525
|
+
}
|
|
526
|
+
function resolveView(view) {
|
|
527
|
+
return typeof view === "function" ? view() : view;
|
|
528
|
+
}
|
|
529
|
+
function projectionsOf(opts) {
|
|
530
|
+
return {
|
|
531
|
+
isText: (data) => opts.current.isText ? opts.current.isText(data) : isTextData(data),
|
|
532
|
+
text: (data) => opts.current.getText ? opts.current.getText(data) : data.text ?? "",
|
|
533
|
+
style: (data) => opts.current.getStyle ? opts.current.getStyle(data) : data.style,
|
|
534
|
+
runs: (data) => opts.current.getRuns ? opts.current.getRuns(data) : data.runs,
|
|
535
|
+
verticalAlign: (data) => opts.current.getVerticalAlign ? opts.current.getVerticalAlign(data) : data.verticalAlign,
|
|
536
|
+
padding: (data) => opts.current.getPadding ? opts.current.getPadding(data) : data.padding,
|
|
537
|
+
overflow: (data) => opts.current.getOverflow ? opts.current.getOverflow(data) : data.overflow,
|
|
538
|
+
fit: (data) => opts.current.getFit ? opts.current.getFit(data) : data.fit
|
|
539
|
+
};
|
|
540
|
+
}
|
|
541
|
+
function useSceneTextEdit(scene, container, options = {}) {
|
|
542
|
+
const host = useRef(null);
|
|
543
|
+
const edit = useSceneTextEditor(scene, container, options);
|
|
544
|
+
const editRef = useLatest(edit);
|
|
545
|
+
useEffect(() => {
|
|
546
|
+
if (!container) return void 0;
|
|
547
|
+
const handle = registerHostTextEditor(container, scene, {
|
|
548
|
+
startEdit: (id, opts) => editRef.current.startEdit(id, opts),
|
|
549
|
+
textAt: (at) => editRef.current.textAt(at),
|
|
550
|
+
isTextNode: (id) => editRef.current.isTextNode(id)
|
|
551
|
+
});
|
|
552
|
+
host.current = handle;
|
|
553
|
+
return () => {
|
|
554
|
+
handle.dispose();
|
|
555
|
+
if (host.current === handle) host.current = null;
|
|
556
|
+
};
|
|
557
|
+
}, [container, scene, editRef]);
|
|
558
|
+
useEffect(() => {
|
|
559
|
+
host.current?.setEditing(edit.editingId);
|
|
560
|
+
}, [edit.editingId, container, scene]);
|
|
561
|
+
return edit;
|
|
562
|
+
}
|
|
563
|
+
function useSceneTextEditor(scene, container, options = {}, canvas = () => null) {
|
|
564
|
+
const sceneRef = useLatest(scene);
|
|
565
|
+
const optsRef = useLatest(options);
|
|
566
|
+
const containerRef = useLatest(container);
|
|
567
|
+
const canvasRef = useLatest(canvas);
|
|
568
|
+
const drafts = useMemo(() => sceneTextDrafts(sceneRef, optsRef), [sceneRef, optsRef]);
|
|
569
|
+
useEffect(() => () => drafts.close(), [drafts]);
|
|
570
|
+
const surface = () => {
|
|
571
|
+
const root = containerRef.current;
|
|
572
|
+
const canvas2 = root ? findMountedCanvas(root, canvasRef.current()) : null;
|
|
573
|
+
if (!root || !canvas2) return null;
|
|
574
|
+
const a = layoutBoxOf(canvas2.element);
|
|
575
|
+
const b = layoutBoxOf(root);
|
|
576
|
+
return {
|
|
577
|
+
canvas: canvas2,
|
|
578
|
+
box: {
|
|
579
|
+
x: (a.left - b.left) / b.scale.x - root.clientLeft + root.scrollLeft,
|
|
580
|
+
y: (a.top - b.top) / b.scale.y - root.clientTop + root.scrollTop,
|
|
581
|
+
width: a.width,
|
|
582
|
+
height: a.height
|
|
583
|
+
}
|
|
584
|
+
};
|
|
585
|
+
};
|
|
586
|
+
const read = useMemo(() => projectionsOf(optsRef), [optsRef]);
|
|
587
|
+
const edit = useTextEdit({
|
|
588
|
+
container,
|
|
589
|
+
isEditorChrome: (el) => optsRef.current.isEditorChrome?.(el) ?? false,
|
|
590
|
+
escape: options.escape,
|
|
591
|
+
fontHold: options.fontHold,
|
|
592
|
+
onStart: (id) => optsRef.current.onStart?.(id),
|
|
593
|
+
onEnd: (id) => {
|
|
594
|
+
drafts.end(id);
|
|
595
|
+
optsRef.current.onEnd?.(id);
|
|
596
|
+
sceneRef.current.history.seal();
|
|
597
|
+
},
|
|
598
|
+
onDraft: drafts.draft,
|
|
599
|
+
getText: (id) => {
|
|
600
|
+
const node = sceneRef.current.get(asNodeId(id));
|
|
601
|
+
return node ? read.text(node.data) : "";
|
|
602
|
+
},
|
|
603
|
+
getStyle: (id) => {
|
|
604
|
+
const node = sceneRef.current.get(asNodeId(id));
|
|
605
|
+
return node ? read.style(node.data) : void 0;
|
|
606
|
+
},
|
|
607
|
+
getPaint: (id) => {
|
|
608
|
+
const node = sceneRef.current.get(asNodeId(id));
|
|
609
|
+
if (!node) return void 0;
|
|
610
|
+
const get = optsRef.current.getPaint;
|
|
611
|
+
return get ? get(node.data) : shownTextPaint(sceneRef.current, node);
|
|
612
|
+
},
|
|
613
|
+
getScreenPose: (id) => {
|
|
614
|
+
const scene2 = sceneRef.current;
|
|
615
|
+
const node = shownLookup(scene2).get(asNodeId(id));
|
|
616
|
+
if (!node) return null;
|
|
617
|
+
const at = surface();
|
|
618
|
+
const view = resolveView(optsRef.current.view) ?? at?.canvas.getView();
|
|
619
|
+
return screenPoseOf(node.data, scenePaintedPoseOf(scene2)(node), read, view, at?.box);
|
|
620
|
+
},
|
|
621
|
+
getClipRect: () => surface()?.box ?? null,
|
|
622
|
+
getRuns: (id) => {
|
|
623
|
+
const node = sceneRef.current.get(asNodeId(id));
|
|
624
|
+
return node ? read.runs(node.data) : void 0;
|
|
625
|
+
},
|
|
626
|
+
commit: (id, { text, runs, style }) => {
|
|
627
|
+
const nid = asNodeId(id);
|
|
628
|
+
const node = sceneRef.current.get(nid);
|
|
629
|
+
if (!node || sceneRef.current.isLocked(nid)) return;
|
|
630
|
+
drafts.commit(id, editedData(node.data, { text, runs, style }, optsRef.current));
|
|
631
|
+
}
|
|
632
|
+
});
|
|
633
|
+
const textAt = useCallback(
|
|
634
|
+
(at) => textHitAt(sceneRef.current, read, at.x, at.y),
|
|
635
|
+
[read, sceneRef]
|
|
636
|
+
);
|
|
637
|
+
const isTextNode = useCallback((id) => {
|
|
638
|
+
const node = sceneRef.current.get(asNodeId(id));
|
|
639
|
+
return node !== void 0 && read.isText(node.data);
|
|
640
|
+
}, [read, sceneRef]);
|
|
641
|
+
const drawOne = useMemo(() => drawOneEditing(edit.editingId), [edit.editingId]);
|
|
642
|
+
return { ...edit, textAt, isTextNode, drawOne };
|
|
643
|
+
}
|
|
644
|
+
function shownTextPaint(scene, node) {
|
|
645
|
+
const { fill, stroke } = withInheritedPaint(node.data, inheritedPaintIn(scene, node));
|
|
646
|
+
return { fill, stroke };
|
|
647
|
+
}
|
|
648
|
+
function useTextEditDepSource(scene) {
|
|
649
|
+
const sceneRef = useLatest(scene);
|
|
650
|
+
useDepSource("textEdit", () => {
|
|
651
|
+
const sc = sceneRef.current;
|
|
652
|
+
return {
|
|
653
|
+
startEdit(_id, _opts) {
|
|
654
|
+
if (isDev()) {
|
|
655
|
+
console.warn(
|
|
656
|
+
'weasel textEditDep: startEdit called but this canvas has no text editor: it was given createTextPreset({ editor: false }), or a host useSceneTextEdit holds it without publishing the "textEdit" dep. Publish it with useDepSource("textEdit", ...) from inside <SceneCanvas>.'
|
|
657
|
+
);
|
|
658
|
+
}
|
|
659
|
+
},
|
|
660
|
+
textAt: () => null,
|
|
661
|
+
isTextNode(id) {
|
|
662
|
+
return isTextData(sc.get(id)?.data);
|
|
663
|
+
}
|
|
664
|
+
};
|
|
665
|
+
});
|
|
666
|
+
}
|
|
667
|
+
function useDefaultTextEditor(scene, elementRef, config, on) {
|
|
668
|
+
const [element, setElement] = useState(null);
|
|
669
|
+
useLayoutEffect(() => {
|
|
670
|
+
if (elementRef.current !== element) setElement(elementRef.current);
|
|
671
|
+
});
|
|
672
|
+
const live = on && config !== false;
|
|
673
|
+
const container = live && element ? element.offsetParent ?? element.parentElement : null;
|
|
674
|
+
const elRef = useLatest(element);
|
|
675
|
+
const edit = useSceneTextEditor(
|
|
676
|
+
scene,
|
|
677
|
+
container,
|
|
678
|
+
config || {},
|
|
679
|
+
() => elRef.current
|
|
680
|
+
);
|
|
681
|
+
const editRef = useLatest(edit);
|
|
682
|
+
const dep = useMemo(() => ({
|
|
683
|
+
startEdit: (id, opts) => editRef.current.startEdit(id, opts),
|
|
684
|
+
textAt: (at) => editRef.current.textAt(at),
|
|
685
|
+
isTextNode: (id) => editRef.current.isTextNode(id)
|
|
686
|
+
}), [editRef]);
|
|
687
|
+
const yields = useMemo(() => () => {
|
|
688
|
+
const el = elRef.current;
|
|
689
|
+
return el === null || hostTextEditorHolds(el);
|
|
690
|
+
}, [elRef]);
|
|
691
|
+
const sceneRef = useLatest(scene);
|
|
692
|
+
const host = useMemo(() => () => {
|
|
693
|
+
const el = elRef.current;
|
|
694
|
+
return el === null ? null : hostTextEditDep(el, sceneRef.current);
|
|
695
|
+
}, [elRef, sceneRef]);
|
|
696
|
+
return { edit, container, dep, element: container ? element : null, yields, host };
|
|
697
|
+
}
|
|
698
|
+
function DefaultTextEditDep({ editor }) {
|
|
699
|
+
const { dep, element, yields, host } = editor;
|
|
700
|
+
useDepSource("textEdit", (below) => {
|
|
701
|
+
if (element && !yields()) return dep;
|
|
702
|
+
return host() ?? below();
|
|
703
|
+
});
|
|
704
|
+
return null;
|
|
705
|
+
}
|
|
706
|
+
function useEditingStandIn(scene, editor) {
|
|
707
|
+
const within = editor.container;
|
|
708
|
+
const editing = editor.edit.editingId;
|
|
709
|
+
const editingRef = useLatest(editing);
|
|
710
|
+
const standIn = useRef(null);
|
|
711
|
+
useEffect(() => {
|
|
712
|
+
if (!within) return void 0;
|
|
713
|
+
const held = registerPaintStandIn(scene, within, withoutText);
|
|
714
|
+
held.show(editingRef.current);
|
|
715
|
+
standIn.current = held;
|
|
716
|
+
return () => {
|
|
717
|
+
held.dispose();
|
|
718
|
+
standIn.current = null;
|
|
719
|
+
};
|
|
720
|
+
}, [scene, within, editingRef]);
|
|
721
|
+
useEffect(() => {
|
|
722
|
+
standIn.current?.show(editing);
|
|
723
|
+
}, [editing]);
|
|
724
|
+
}
|
|
725
|
+
function TextEditStub({ scene }) {
|
|
726
|
+
useTextEditDepSource(scene);
|
|
727
|
+
return null;
|
|
728
|
+
}
|
|
729
|
+
function canvasTextEditor(config) {
|
|
730
|
+
function CanvasTextEditor({ scene, canvasRef, paintsInto }) {
|
|
731
|
+
const editor = useDefaultTextEditor(scene, canvasRef, config, !paintsInto);
|
|
732
|
+
useEditingStandIn(scene, editor);
|
|
733
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
734
|
+
/* @__PURE__ */ jsx(TextEditStub, { scene }),
|
|
735
|
+
/* @__PURE__ */ jsx(DefaultTextEditDep, { editor })
|
|
736
|
+
] });
|
|
737
|
+
}
|
|
738
|
+
return CanvasTextEditor;
|
|
739
|
+
}
|
|
740
|
+
function createTextHandler(opts = {}) {
|
|
741
|
+
const measure = opts.measure ?? ((text) => measureTextBounds(text));
|
|
742
|
+
return {
|
|
743
|
+
id: "text-tools:text",
|
|
744
|
+
match: (item) => item.kind === "string" && item.mime === "text/plain",
|
|
745
|
+
types: ["text/plain"],
|
|
746
|
+
priority: -110,
|
|
747
|
+
handle(items, ctx) {
|
|
748
|
+
if ((ctx.items ?? items).some((it) => it.kind === "file")) return;
|
|
749
|
+
let index = 0;
|
|
750
|
+
for (const item of items) {
|
|
751
|
+
if (item.kind !== "string") continue;
|
|
752
|
+
const text = item.text.replace(/\r\n?/g, "\n").replace(/\n+$/, "");
|
|
753
|
+
if (text.trim() === "") continue;
|
|
754
|
+
ctx.insert.commit(arrivalBounds(ctx, measure(text), index), { kind: "text", text });
|
|
755
|
+
index++;
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
};
|
|
759
|
+
}
|
|
760
|
+
var textContentHandler = createTextHandler();
|
|
761
|
+
function typeIn(data) {
|
|
762
|
+
if (data.text !== "") return { data };
|
|
763
|
+
return {
|
|
764
|
+
data,
|
|
765
|
+
batch: textEditJoin,
|
|
766
|
+
inserted: (id, deps) => deps.get("textEdit")?.startEdit(id, { caret: 0 })
|
|
767
|
+
};
|
|
768
|
+
}
|
|
769
|
+
var textNodeFactory = (_bounds, extras) => {
|
|
770
|
+
const e = extras;
|
|
771
|
+
const fill = e.style?.fill;
|
|
772
|
+
return typeIn({ text: e.text ?? "", fill: fill === void 0 ? DEFAULT_TEXT_FILL : fill && { paint: fill } });
|
|
773
|
+
};
|
|
774
|
+
var TWO_PLACES = decimal({ maxPlaces: 2, grouping: false });
|
|
775
|
+
var italicEncoding = {
|
|
776
|
+
read: (stored) => stored === "italic",
|
|
777
|
+
write: (on) => on ? "italic" : void 0
|
|
778
|
+
};
|
|
779
|
+
var overflowEncoding = {
|
|
780
|
+
read: (stored) => stored === "clip",
|
|
781
|
+
write: (on) => on ? "clip" : void 0
|
|
782
|
+
};
|
|
783
|
+
var fitEncoding = {
|
|
784
|
+
read: (stored) => stored === "shrink",
|
|
785
|
+
write: (on) => on ? "shrink" : void 0
|
|
786
|
+
};
|
|
787
|
+
var BACKGROUND_LEAF = {
|
|
788
|
+
kind: "object",
|
|
789
|
+
block: true,
|
|
790
|
+
name: "Background",
|
|
791
|
+
description: "Paint behind the text, over the whole box.",
|
|
792
|
+
default: { paint: { kind: "solid", color: "#ffffffff" } },
|
|
793
|
+
children: {
|
|
794
|
+
paint: { kind: "paint", name: "Background", description: "Paint behind the text.", default: { kind: "solid", color: "#ffffffff" }, alpha: true, block: true }
|
|
795
|
+
}
|
|
796
|
+
};
|
|
797
|
+
var CONTENT = {
|
|
798
|
+
name: "Content",
|
|
799
|
+
members: {
|
|
800
|
+
// `block`: the content is the section, so a 64px label column
|
|
801
|
+
// reading "Text" inside a section reading "Text" is one word
|
|
802
|
+
// twice and a narrower field for the sake of it.
|
|
803
|
+
"data.text": { kind: "string", name: "Text", description: "Text content.", absentIsDefault: true, default: "", block: true }
|
|
804
|
+
}
|
|
805
|
+
};
|
|
806
|
+
var TYPOGRAPHY = {
|
|
807
|
+
// Headless: `Character` and `Paragraph` carry the labels, and a
|
|
808
|
+
// `Typography` heading over them names nothing a reader can't
|
|
809
|
+
// already see.
|
|
810
|
+
name: "",
|
|
811
|
+
members: {
|
|
812
|
+
// One object leaf, not a row of siblings addressing into it:
|
|
813
|
+
// `data.style` is a `TextStyle`, and its character and
|
|
814
|
+
// paragraph fields are one value that reads as two lists.
|
|
815
|
+
// The groups head those lists and contribute nothing to the
|
|
816
|
+
// path — a field inside one is still a field of the style.
|
|
817
|
+
"data.style": {
|
|
818
|
+
kind: "object",
|
|
819
|
+
name: "Style",
|
|
820
|
+
description: "Typography for the whole node. Its color is the node's own `data.fill`, in Appearance.",
|
|
821
|
+
default: {},
|
|
822
|
+
absentIsDefault: true,
|
|
823
|
+
block: true,
|
|
824
|
+
children: {
|
|
825
|
+
character: {
|
|
826
|
+
name: "Character",
|
|
827
|
+
members: {
|
|
828
|
+
fontFamily: { kind: "font-family", name: "Font", description: "Registered font family.", absentIsDefault: true, default: "sans-serif" },
|
|
829
|
+
fontSize: { kind: "number", display: TWO_PLACES, name: "Size", description: "Font size, world units.", absentIsDefault: true, default: 16, min: 1, step: 1, pair: { with: "data.style.fontWeight", label: "Size / weight" } },
|
|
830
|
+
fontWeight: { kind: "font-weight", name: "Weight", description: "Font weight, from the faces the family has.", absentIsDefault: true, default: 400 },
|
|
831
|
+
// One row of segments, the strip every text editor
|
|
832
|
+
// draws: the slant, the three rules, then the two
|
|
833
|
+
// scripts. Italic is a flag here although the field
|
|
834
|
+
// is `fontStyle`, whose only other value is upright.
|
|
835
|
+
fontStyle: { kind: "boolean", name: "Italic", description: "Set the text in its italic face.", default: false, control: "toggle", icon: (
|
|
836
|
+
/* @icon */
|
|
837
|
+
"core:italic"
|
|
838
|
+
), short: ["I"], pair: { with: ["data.style.underline", "data.style.strikethrough", "data.style.overline", "data.style.script"], label: "Style" }, encoding: italicEncoding },
|
|
839
|
+
underline: { kind: "boolean", name: "Underline", description: "Underline the text.", absentIsDefault: true, default: false, control: "toggle", icon: (
|
|
840
|
+
/* @icon */
|
|
841
|
+
"core:underline"
|
|
842
|
+
), short: ["U"] },
|
|
843
|
+
strikethrough: { kind: "boolean", name: "Strikethrough", description: "Strike through the text.", absentIsDefault: true, default: false, control: "toggle", icon: (
|
|
844
|
+
/* @icon */
|
|
845
|
+
"core:strikethrough"
|
|
846
|
+
), short: ["S"] },
|
|
847
|
+
overline: { kind: "boolean", name: "Overline", description: "Rule the text above its ascent.", absentIsDefault: true, default: false, control: "toggle", icon: (
|
|
848
|
+
/* @icon */
|
|
849
|
+
"core:overline"
|
|
850
|
+
), short: ["O"] },
|
|
851
|
+
script: { kind: "enum", name: "Script", description: "Set the text smaller and raised or lowered, on the line it would otherwise hold.", default: void 0, control: "toggle", clearable: true, options: [{ value: "super", label: "Superscript", icon: (
|
|
852
|
+
/* @icon */
|
|
853
|
+
"core:superscript"
|
|
854
|
+
) }, { value: "sub", label: "Subscript", icon: (
|
|
855
|
+
/* @icon */
|
|
856
|
+
"core:subscript"
|
|
857
|
+
) }] },
|
|
858
|
+
letterSpacing: { kind: "number", display: TWO_PLACES, name: "Tracking", description: "Extra advance per glyph, world units.", absentIsDefault: true, default: 0, step: 0.1 },
|
|
859
|
+
textTransform: { kind: "enum", name: "Case", description: "Draw the text in capitals, lowercase or title case. The text itself is unchanged.", absentIsDefault: true, default: "none", control: "toggle", options: [{ value: "none", label: "None", short: ["\u2013"] }, { value: "uppercase", label: "Uppercase", short: ["AA"] }, { value: "lowercase", label: "Lowercase", short: ["aa"] }, { value: "capitalize", label: "Capitalize", short: ["Aa"] }] },
|
|
860
|
+
fontVariantCaps: { kind: "enum", name: "Small caps", description: "Draw lowercase letters as smaller capitals. The text itself is unchanged.", absentIsDefault: true, default: "normal", control: "toggle", options: [{ value: "normal", label: "Normal", short: ["\u2013"] }, { value: "small-caps", label: "Small caps", short: ["Sc"] }] },
|
|
861
|
+
lang: { kind: "string", name: "Language", description: "A BCP 47 tag, such as sr or ur, that picks the forms a font draws for that language. Empty means none.", default: "" }
|
|
862
|
+
}
|
|
863
|
+
},
|
|
864
|
+
paragraph: {
|
|
865
|
+
name: "Paragraph",
|
|
866
|
+
members: {
|
|
867
|
+
lineHeight: { kind: "number", display: TWO_PLACES, name: "Leading", description: "Line height as a multiple of font size.", absentIsDefault: true, default: 1.2, min: 0.5, step: 0.1 },
|
|
868
|
+
wrap: { kind: "boolean", name: "Wrap", description: "Break lines between words at the box width.", absentIsDefault: true, default: false, control: "switch" },
|
|
869
|
+
tabSize: { kind: "number", display: TWO_PLACES, name: "Tab size", description: "Distance between tab stops, in spaces.", absentIsDefault: true, default: 8, min: 1, step: 1 },
|
|
870
|
+
direction: { kind: "enum", name: "Direction", description: "Reading direction. Auto takes each paragraph's from its first strong character.", absentIsDefault: true, default: "auto", control: "toggle", options: [{ value: "auto", label: "Auto", short: ["Auto"] }, { value: "ltr", label: "Left to right", short: ["LTR"] }, { value: "rtl", label: "Right to left", short: ["RTL"] }] },
|
|
871
|
+
// Last, so the box's vertical alignment — a field of
|
|
872
|
+
// the node rather than of its style — follows it.
|
|
873
|
+
align: { kind: "enum", name: "Align", description: "Horizontal alignment.", absentIsDefault: true, default: "left", control: "toggle", options: [{ value: "left", label: "Left", icon: (
|
|
874
|
+
/* @icon */
|
|
875
|
+
"core:textAlignLeft"
|
|
876
|
+
) }, { value: "center", label: "Center", icon: (
|
|
877
|
+
/* @icon */
|
|
878
|
+
"core:textAlignCenter"
|
|
879
|
+
) }, { value: "right", label: "Right", icon: (
|
|
880
|
+
/* @icon */
|
|
881
|
+
"core:textAlignRight"
|
|
882
|
+
) }, { value: "justify", label: "Justify", icon: (
|
|
883
|
+
/* @icon */
|
|
884
|
+
"core:textAlignJustify"
|
|
885
|
+
) }, { value: "start", label: "Start", icon: (
|
|
886
|
+
/* @icon */
|
|
887
|
+
"core:textAlignStart"
|
|
888
|
+
) }, { value: "end", label: "End", icon: (
|
|
889
|
+
/* @icon */
|
|
890
|
+
"core:textAlignEnd"
|
|
891
|
+
) }] }
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
},
|
|
896
|
+
"data.padding": { kind: "number", display: TWO_PLACES, measure: "length", name: "Padding", description: "Inset from the box to the text on every side, world units.", absentIsDefault: true, default: 0, min: 0, step: 1 },
|
|
897
|
+
"data.verticalAlign": { kind: "enum", name: "Vertical", description: "Where the lines sit in the box's height.", absentIsDefault: true, default: "top", control: "toggle", options: [{ value: "top", label: "Top", icon: (
|
|
898
|
+
/* @icon */
|
|
899
|
+
"core:textAlignTop"
|
|
900
|
+
) }, { value: "center", label: "Middle", icon: (
|
|
901
|
+
/* @icon */
|
|
902
|
+
"core:textAlignMiddle"
|
|
903
|
+
) }, { value: "bottom", label: "Bottom", icon: (
|
|
904
|
+
/* @icon */
|
|
905
|
+
"core:textAlignBottom"
|
|
906
|
+
) }] },
|
|
907
|
+
"data.overflow": { kind: "boolean", name: "Clip", description: "Cut the text at the box's edge instead of drawing it past.", default: false, control: "switch", encoding: overflowEncoding },
|
|
908
|
+
"data.fit": { kind: "boolean", name: "Shrink to fit", description: "Set the text smaller, never larger, until its lines fit the box.", default: false, control: "switch", encoding: fitEncoding }
|
|
909
|
+
}
|
|
910
|
+
};
|
|
911
|
+
var TEXT_PROPERTIES = {
|
|
912
|
+
name: "text",
|
|
913
|
+
schema: shapePropertiesSchema({
|
|
914
|
+
// What the node *is* outranks how it is painted: a text node's copy is the first thing an editor reaches for.
|
|
915
|
+
lead: { content: CONTENT },
|
|
916
|
+
appearance: { "data.background": BACKGROUND_LEAF },
|
|
917
|
+
trail: { text: TYPOGRAPHY }
|
|
918
|
+
})
|
|
919
|
+
};
|
|
920
|
+
var optionFill = (option, fallback) => option === void 0 ? fallback : option && { paint: option };
|
|
921
|
+
var STICKY_DEFAULTS = {
|
|
922
|
+
background: { paint: { kind: "solid", color: "#fff1a6ff" } },
|
|
923
|
+
fill: DEFAULT_TEXT_FILL,
|
|
924
|
+
padding: 12,
|
|
925
|
+
style: { fontSize: 18, align: "center", wrap: true },
|
|
926
|
+
verticalAlign: "center",
|
|
927
|
+
overflow: "clip",
|
|
928
|
+
edge: { width: 1, shade: 0.18 },
|
|
929
|
+
shadow: { x: 0, y: 2, blur: 6, alpha: 0.18 },
|
|
930
|
+
// One line of the default type inside the default padding.
|
|
931
|
+
minSize: { width: 48, height: 48 },
|
|
932
|
+
size: { width: 160, height: 160 }
|
|
933
|
+
};
|
|
934
|
+
function stickyData(look) {
|
|
935
|
+
return {
|
|
936
|
+
text: look.text ?? "",
|
|
937
|
+
background: optionFill(look.paper, look.background ?? STICKY_DEFAULTS.background),
|
|
938
|
+
padding: look.padding ?? STICKY_DEFAULTS.padding,
|
|
939
|
+
style: look.style ?? STICKY_DEFAULTS.style,
|
|
940
|
+
verticalAlign: look.verticalAlign ?? STICKY_DEFAULTS.verticalAlign,
|
|
941
|
+
overflow: look.overflow ?? STICKY_DEFAULTS.overflow,
|
|
942
|
+
edge: look.edge ?? STICKY_DEFAULTS.edge,
|
|
943
|
+
shadow: look.shadow ?? STICKY_DEFAULTS.shadow,
|
|
944
|
+
minSize: look.minSize ?? STICKY_DEFAULTS.minSize,
|
|
945
|
+
fill: optionFill(look.ink, look.fill ?? STICKY_DEFAULTS.fill)
|
|
946
|
+
};
|
|
947
|
+
}
|
|
948
|
+
var stickyNodeFactory = (_bounds, extras) => typeIn(stickyData(extras));
|
|
949
|
+
var STICKY_TOOL_OPTIONS = {
|
|
950
|
+
actionId: ["insert", "place"],
|
|
951
|
+
prefs: {
|
|
952
|
+
name: "Sticky note",
|
|
953
|
+
as: "bar",
|
|
954
|
+
children: {
|
|
955
|
+
paper: { ...styleOptionLeaves({ fill: STICKY_DEFAULTS.background.paint }, ["fill"]).fill, name: "Paper", description: "What a new note is painted on." },
|
|
956
|
+
ink: { ...styleOptionLeaves({ fill: STICKY_DEFAULTS.fill.paint }, ["fill"]).fill, name: "Ink", description: "What a new note\u2019s text is set in." }
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
};
|
|
960
|
+
function createStickyTool(options = {}) {
|
|
961
|
+
const {
|
|
962
|
+
behaviors,
|
|
963
|
+
size = STICKY_DEFAULTS.size,
|
|
964
|
+
minSize = STICKY_DEFAULTS.minSize,
|
|
965
|
+
background,
|
|
966
|
+
fill,
|
|
967
|
+
padding,
|
|
968
|
+
style,
|
|
969
|
+
verticalAlign,
|
|
970
|
+
overflow,
|
|
971
|
+
edge,
|
|
972
|
+
shadow,
|
|
973
|
+
share
|
|
974
|
+
} = options;
|
|
975
|
+
{
|
|
976
|
+
const color = (paint) => paint === void 0 ? void 0 : toolOptionPaint(paint);
|
|
977
|
+
const toolOptions = withToolOptionDefault(
|
|
978
|
+
withToolOptionDefault(shareToolOptions(STICKY_TOOL_OPTIONS, share), "paper", color(background?.paint)),
|
|
979
|
+
"ink",
|
|
980
|
+
color(fill?.paint)
|
|
981
|
+
);
|
|
982
|
+
const look = {
|
|
983
|
+
kind: "sticky",
|
|
984
|
+
minSize,
|
|
985
|
+
...padding !== void 0 ? { padding } : {},
|
|
986
|
+
...style !== void 0 ? { style } : {},
|
|
987
|
+
...verticalAlign !== void 0 ? { verticalAlign } : {},
|
|
988
|
+
...overflow !== void 0 ? { overflow } : {},
|
|
989
|
+
...edge !== void 0 ? { edge } : {},
|
|
990
|
+
...shadow !== void 0 ? { shadow } : {}
|
|
991
|
+
};
|
|
992
|
+
return defineTool({
|
|
993
|
+
id: "sticky",
|
|
994
|
+
keybinding: { key: "S" },
|
|
995
|
+
capabilities: ["creates-text"],
|
|
996
|
+
hookName: "useStickyTool",
|
|
997
|
+
options: toolOptions,
|
|
998
|
+
cursor: cursorFor("crosshair", { mark: "rect", fallback: "crosshair" }),
|
|
999
|
+
presentation: {
|
|
1000
|
+
label: "Sticky note",
|
|
1001
|
+
icon: (
|
|
1002
|
+
/* @icon */
|
|
1003
|
+
"core:sticky"
|
|
1004
|
+
),
|
|
1005
|
+
group: "type"
|
|
1006
|
+
},
|
|
1007
|
+
bindings: [
|
|
1008
|
+
{ spec: { kind: "drag", mods: INSERT_DRAG_MODS }, actionId: "insert", opts: { id: "sticky.drag", params: look, ...insertBindingBehaviors(behaviors) } },
|
|
1009
|
+
{ spec: { kind: "click" }, actionId: "place", opts: { id: "sticky.click", params: { ...look, size } } },
|
|
1010
|
+
{ spec: { kind: "click", target: "selected-body" }, actionId: "enterTextEdit", opts: { id: "sticky.editText" } },
|
|
1011
|
+
INSERT_REPOSITION_BINDING
|
|
1012
|
+
]
|
|
1013
|
+
});
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
function useStickyTool(options = {}) {
|
|
1017
|
+
const {
|
|
1018
|
+
behaviors,
|
|
1019
|
+
size,
|
|
1020
|
+
minSize,
|
|
1021
|
+
background,
|
|
1022
|
+
fill,
|
|
1023
|
+
padding,
|
|
1024
|
+
style,
|
|
1025
|
+
verticalAlign,
|
|
1026
|
+
overflow,
|
|
1027
|
+
edge,
|
|
1028
|
+
shadow,
|
|
1029
|
+
share
|
|
1030
|
+
} = options;
|
|
1031
|
+
return useMemo(
|
|
1032
|
+
() => createStickyTool({ behaviors, size, minSize, background, fill, padding, style, verticalAlign, overflow, edge, shadow, share }),
|
|
1033
|
+
[behaviors, size, minSize, background, fill, padding, style, verticalAlign, overflow, edge, shadow, share]
|
|
1034
|
+
);
|
|
1035
|
+
}
|
|
1036
|
+
var PRESENTATION = {
|
|
1037
|
+
label: "Text",
|
|
1038
|
+
icon: (
|
|
1039
|
+
/* @icon */
|
|
1040
|
+
"core:text"
|
|
1041
|
+
),
|
|
1042
|
+
group: "type"
|
|
1043
|
+
};
|
|
1044
|
+
var TEXT_TOOL_OPTIONS = shareToolOptions(shapeToolOptions({
|
|
1045
|
+
actionId: "insert",
|
|
1046
|
+
name: "Text",
|
|
1047
|
+
keys: ["fill"],
|
|
1048
|
+
style: { fill: DEFAULT_TEXT_FILL.paint }
|
|
1049
|
+
}), { fill: "textFill" });
|
|
1050
|
+
function createTextTool(options = {}) {
|
|
1051
|
+
const { behaviors, share } = options;
|
|
1052
|
+
return defineTool({
|
|
1053
|
+
id: "text",
|
|
1054
|
+
keybinding: { key: "T" },
|
|
1055
|
+
capabilities: ["creates-text"],
|
|
1056
|
+
hookName: "useTextTool",
|
|
1057
|
+
options: shareToolOptions(TEXT_TOOL_OPTIONS, share),
|
|
1058
|
+
cursor: "text",
|
|
1059
|
+
presentation: PRESENTATION,
|
|
1060
|
+
bindings: [
|
|
1061
|
+
{ spec: { kind: "drag", mods: INSERT_DRAG_MODS }, actionId: "insert", opts: { id: "text.drag", params: { kind: "text" }, ...insertBindingBehaviors(behaviors) } },
|
|
1062
|
+
{ spec: { kind: "click", target: "selected-body" }, actionId: "enterTextEdit", opts: { id: "text.editText" } },
|
|
1063
|
+
INSERT_REPOSITION_BINDING
|
|
1064
|
+
]
|
|
1065
|
+
});
|
|
1066
|
+
}
|
|
1067
|
+
function useTextTool(options = {}) {
|
|
1068
|
+
const { behaviors, share } = options;
|
|
1069
|
+
return useMemo(() => createTextTool({ behaviors, share }), [behaviors, share]);
|
|
1070
|
+
}
|
|
1071
|
+
var textNodeRouting = {
|
|
1072
|
+
name: "text",
|
|
1073
|
+
matches: (data, node) => node?.kind !== "group" && isTextData(data)
|
|
1074
|
+
};
|
|
1075
|
+
function createTextPreset(options = {}) {
|
|
1076
|
+
return {
|
|
1077
|
+
id: "text",
|
|
1078
|
+
label: "Text",
|
|
1079
|
+
shapes: [TEXT_PAINTER],
|
|
1080
|
+
routing: [textNodeRouting],
|
|
1081
|
+
properties: [TEXT_PROPERTIES],
|
|
1082
|
+
insertNodeFactories: { text: textNodeFactory, sticky: stickyNodeFactory },
|
|
1083
|
+
actions: [enterTextEditAction, editTextAtAction, editEffectTextAction],
|
|
1084
|
+
components: [canvasTextEditor(options.editor)],
|
|
1085
|
+
contentHandlers: [textContentHandler]
|
|
1086
|
+
};
|
|
1087
|
+
}
|
|
1088
|
+
var textPreset = createTextPreset();
|
|
1089
|
+
function createTextToolsPreset(options = {}) {
|
|
1090
|
+
const { behaviors, share, sticky, text = textPreset } = options;
|
|
1091
|
+
return {
|
|
1092
|
+
id: "tools:text",
|
|
1093
|
+
label: "Text tools",
|
|
1094
|
+
tools: [createTextTool({ behaviors, share }), createStickyTool({ ...sticky, behaviors, share })],
|
|
1095
|
+
includes: [text]
|
|
1096
|
+
};
|
|
1097
|
+
}
|
|
1098
|
+
var textToolsPreset = createTextToolsPreset();
|
|
1099
|
+
var whiteboardPreset = {
|
|
1100
|
+
id: "whiteboard",
|
|
1101
|
+
label: "Whiteboard",
|
|
1102
|
+
includes: [viewPreset, pickPreset, movePreset, resizePreset, editPreset, textToolsPreset]
|
|
1103
|
+
};
|
|
1104
|
+
var TEXT_TOOLS = toolSet("type", ["text", "sticky"], { label: "Type" });
|
|
1105
|
+
var WHITEBOARD_TOOLS = toolSet("whiteboard", ["text", "sticky"], { label: "Whiteboard" });
|
|
1106
|
+
function useTextToolsTools(options = {}) {
|
|
1107
|
+
const text = useTextTool({ behaviors: options.behaviors, share: options.share });
|
|
1108
|
+
const sticky = useStickyTool(options);
|
|
1109
|
+
return useMemo(() => ({ text, sticky }), [text, sticky]);
|
|
1110
|
+
}
|
|
1111
|
+
function createTextLayer(opts) {
|
|
1112
|
+
const { id = "text", label = "Text", getTexts, getPose, isHidden, clipToBounds = false } = opts;
|
|
1113
|
+
return {
|
|
1114
|
+
id,
|
|
1115
|
+
label,
|
|
1116
|
+
draw: (_data, view) => {
|
|
1117
|
+
const scale = meanScale(view.scale);
|
|
1118
|
+
const children = [];
|
|
1119
|
+
for (const node of getTexts()) {
|
|
1120
|
+
if (isHidden?.(node)) continue;
|
|
1121
|
+
const pose = getPose(node);
|
|
1122
|
+
if (pose.runs && pose.runs.length > 0 && runsToPlainText(pose.runs) !== pose.text) {
|
|
1123
|
+
throw new Error(
|
|
1124
|
+
`weasel createTextLayer: TextPose invariant violated \u2014 runsToPlainText(runs) !== text. Either omit \`runs\` or keep it synchronized with \`text\`.`
|
|
1125
|
+
);
|
|
1126
|
+
}
|
|
1127
|
+
const textCmd = textCommandFromPose(pose, scale);
|
|
1128
|
+
children.push(clipToBounds ? clippedToBox(textCmd, pose) : textCmd);
|
|
1129
|
+
}
|
|
1130
|
+
return children;
|
|
1131
|
+
}
|
|
1132
|
+
};
|
|
1133
|
+
}
|
|
1134
|
+
|
|
1135
|
+
export { STICKY_DEFAULTS, STICKY_TOOL_OPTIONS, TEXT_PAINTER, TEXT_PROPERTIES, TEXT_TOOLS, TEXT_TOOL_OPTIONS, WHITEBOARD_TOOLS, createStickyTool, createTextHandler, createTextLayer, createTextPreset, createTextTool, createTextToolsPreset, drawOneEditing, edgeColor, editEffectTextAction, editTextAtAction, enterTextEditAction, stickyData, stickyNodeFactory, textBoxOf, textContentHandler, textEditJoin, textEffectItems, textFrameOf, textLayoutScale, textNodeFactory, textNodeRouting, textOutlineOf, textPoseOf, textPreset, textToolsPreset, useSceneTextEdit, useStickyTool, useTextTool, useTextToolsTools, whiteboardPreset, withoutText };
|
|
1136
|
+
//# sourceMappingURL=index.js.map
|
|
1137
|
+
//# sourceMappingURL=index.js.map
|