@daasboard/editor 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.
Files changed (83) hide show
  1. package/LICENSE +5 -0
  2. package/README.md +6 -2
  3. package/dist/camera/CameraInput.d.ts +106 -0
  4. package/dist/camera/CameraInput.js +398 -0
  5. package/dist/clipboard/ObjectClipboard.d.ts +40 -0
  6. package/dist/clipboard/ObjectClipboard.js +243 -0
  7. package/dist/clipboard/PasteCommitError.d.ts +4 -0
  8. package/dist/clipboard/PasteCommitError.js +7 -0
  9. package/dist/clipboard/carrier.d.ts +5 -0
  10. package/dist/clipboard/carrier.js +59 -0
  11. package/dist/clipboard/objects.d.ts +21 -0
  12. package/dist/clipboard/objects.js +362 -0
  13. package/dist/clipboard/placement.d.ts +11 -0
  14. package/dist/clipboard/placement.js +21 -0
  15. package/dist/clipboard/systemImages.d.ts +1 -0
  16. package/dist/clipboard/systemImages.js +24 -0
  17. package/dist/index.d.ts +23 -0
  18. package/dist/index.js +22 -0
  19. package/dist/input/TouchInput.d.ts +159 -0
  20. package/dist/input/TouchInput.js +656 -0
  21. package/dist/input/visiblePart.d.ts +8 -0
  22. package/dist/input/visiblePart.js +15 -0
  23. package/dist/interaction/InteractionLayer.d.ts +83 -0
  24. package/dist/interaction/InteractionLayer.js +520 -0
  25. package/dist/props/PropertyController.d.ts +130 -0
  26. package/dist/props/PropertyController.js +1448 -0
  27. package/dist/props/PropertyRegistry.d.ts +38 -0
  28. package/dist/props/PropertyRegistry.js +21 -0
  29. package/dist/props/builtinProperties.d.ts +23 -0
  30. package/dist/props/builtinProperties.js +350 -0
  31. package/dist/props/defaults.d.ts +6 -0
  32. package/dist/props/defaults.js +29 -0
  33. package/dist/selection/SelectionModel.d.ts +25 -0
  34. package/dist/selection/SelectionModel.js +79 -0
  35. package/dist/text/CanvasEditorView.d.ts +99 -0
  36. package/dist/text/CanvasEditorView.js +308 -0
  37. package/dist/text/InputSink.d.ts +157 -0
  38. package/dist/text/InputSink.js +841 -0
  39. package/dist/text/TextEditSession.d.ts +173 -0
  40. package/dist/text/TextEditSession.js +1328 -0
  41. package/dist/text/clipboard.d.ts +11 -0
  42. package/dist/text/clipboard.js +489 -0
  43. package/dist/text/commands.d.ts +48 -0
  44. package/dist/text/commands.js +329 -0
  45. package/dist/text/contextMirror.d.ts +51 -0
  46. package/dist/text/contextMirror.js +292 -0
  47. package/dist/text/flat.d.ts +35 -0
  48. package/dist/text/flat.js +556 -0
  49. package/dist/text/graphemes.d.ts +16 -0
  50. package/dist/text/graphemes.js +219 -0
  51. package/dist/text/index.d.ts +13 -0
  52. package/dist/text/index.js +13 -0
  53. package/dist/text/inputReducer.d.ts +24 -0
  54. package/dist/text/inputReducer.js +44 -0
  55. package/dist/text/keymap.d.ts +17 -0
  56. package/dist/text/keymap.js +148 -0
  57. package/dist/text/schema.d.ts +12 -0
  58. package/dist/text/schema.js +44 -0
  59. package/dist/text/sessionFocus.d.ts +20 -0
  60. package/dist/text/sessionFocus.js +51 -0
  61. package/dist/text/types.d.ts +114 -0
  62. package/dist/text/types.js +1 -0
  63. package/dist/tools/CreateTool.d.ts +78 -0
  64. package/dist/tools/CreateTool.js +258 -0
  65. package/dist/tools/SelectTool.d.ts +155 -0
  66. package/dist/tools/SelectTool.js +808 -0
  67. package/dist/tools/ToolManager.d.ts +63 -0
  68. package/dist/tools/ToolManager.js +146 -0
  69. package/dist/tools/connectorEndpoints.d.ts +17 -0
  70. package/dist/tools/connectorEndpoints.js +53 -0
  71. package/dist/tools/frameRotation.d.ts +8 -0
  72. package/dist/tools/frameRotation.js +66 -0
  73. package/dist/tools/gradientHandles.d.ts +67 -0
  74. package/dist/tools/gradientHandles.js +110 -0
  75. package/dist/tools/presetPaths.d.ts +5 -0
  76. package/dist/tools/presetPaths.js +49 -0
  77. package/dist/tools/snapResize.d.ts +7 -0
  78. package/dist/tools/snapResize.js +65 -0
  79. package/dist/tools/snapping.d.ts +30 -0
  80. package/dist/tools/snapping.js +280 -0
  81. package/dist/tools/transform.d.ts +52 -0
  82. package/dist/tools/transform.js +277 -0
  83. package/package.json +36 -3
@@ -0,0 +1,38 @@
1
+ import type { SceneObject, TextParagraphContent, TextRunContent } from "@daasboard/render-core";
2
+ import type { PropPath, Transaction } from "@daasboard/doc";
3
+ export type PropType = "number" | "color" | "paint" | "paints" | "enum" | "boolean" | "string" | "font" | "embed";
4
+ export interface PropertyDescriptor<T = unknown> {
5
+ key: string;
6
+ label: string;
7
+ type: PropType;
8
+ group: string;
9
+ appliesTo(o: SceneObject): boolean;
10
+ read(o: SceneObject): T | undefined;
11
+ path?: PropPath;
12
+ write?(tx: Transaction, o: SceneObject, value: T): void;
13
+ previewPatch?(value: T, o: SceneObject): Record<PropPath, unknown>;
14
+ rotationUnit?: "degrees" | "radians";
15
+ multi?: "each" | "bounds";
16
+ textMark?: string;
17
+ markRead?(markValue: unknown, o: SceneObject): T;
18
+ markWrite?(value: T, o: SceneObject): unknown;
19
+ clearsText?: {
20
+ run: Exclude<keyof TextRunContent, "text">;
21
+ } | {
22
+ para: Exclude<keyof TextParagraphContent, "runs">;
23
+ };
24
+ options?: readonly string[];
25
+ min?: number;
26
+ max?: number;
27
+ step?: number;
28
+ unit?: string;
29
+ default?: T;
30
+ }
31
+ export declare class PropertyRegistry {
32
+ private map;
33
+ register<T>(d: PropertyDescriptor<T>): this;
34
+ get(key: string): PropertyDescriptor | undefined;
35
+ all(): PropertyDescriptor[];
36
+ forObjects(objs: readonly SceneObject[]): PropertyDescriptor[];
37
+ toJSON(): Array<Omit<PropertyDescriptor, "appliesTo" | "read" | "write" | "previewPatch">>;
38
+ }
@@ -0,0 +1,21 @@
1
+ export class PropertyRegistry {
2
+ map = new Map();
3
+ register(d) {
4
+ this.map.set(d.key, d);
5
+ return this;
6
+ }
7
+ get(key) {
8
+ return this.map.get(key);
9
+ }
10
+ all() {
11
+ return [...this.map.values()];
12
+ }
13
+ forObjects(objs) {
14
+ if (objs.length === 0)
15
+ return [];
16
+ return this.all().filter((d) => objs.every((o) => d.appliesTo(o)));
17
+ }
18
+ toJSON() {
19
+ return this.all().map(({ appliesTo: _a, read: _r, write: _w, previewPatch: _p, ...rest }) => rest);
20
+ }
21
+ }
@@ -0,0 +1,23 @@
1
+ import { type SceneObject } from "@daasboard/render-core";
2
+ import { PropertyRegistry, type PropertyDescriptor } from "./PropertyRegistry.js";
3
+ export declare const canHaveText: (o: SceneObject) => boolean;
4
+ export declare function aggregateMembers(d: PropertyDescriptor | undefined): readonly string[] | undefined;
5
+ export interface PropertyReadState {
6
+ readonly key: string;
7
+ readonly read: PropertyDescriptor["read"];
8
+ readonly appliesTo: PropertyDescriptor["appliesTo"];
9
+ readonly path: PropertyDescriptor["path"];
10
+ readonly multi: PropertyDescriptor["multi"];
11
+ readonly textMark: PropertyDescriptor["textMark"];
12
+ readonly markRead: PropertyDescriptor["markRead"];
13
+ readonly markWrite: PropertyDescriptor["markWrite"];
14
+ readonly write: PropertyDescriptor["write"];
15
+ readonly previewPatch: PropertyDescriptor["previewPatch"];
16
+ readonly rotationUnit: PropertyDescriptor["rotationUnit"];
17
+ readonly clearsRun: string | undefined;
18
+ readonly clearsPara: string | undefined;
19
+ readonly deps: readonly string[] | undefined;
20
+ }
21
+ export declare function readDescriptorState(d: PropertyDescriptor): PropertyReadState;
22
+ export declare function builtinReadDependencies(d: PropertyDescriptor): readonly string[] | undefined;
23
+ export declare function builtinProperties(): PropertyRegistry;
@@ -0,0 +1,350 @@
1
+ import { openPathEnds } from "@daasboard/render-core";
2
+ import { PropertyRegistry } from "./PropertyRegistry.js";
3
+ const MAX_INDENT = 8;
4
+ const textRuns = (o) => (o.text ? o.text.paragraphs.flatMap((p) => p.runs).filter((r) => r.text.length > 0) : []);
5
+ const unchanged = () => null;
6
+ function formatDelta(t, run, para) {
7
+ const delta = [];
8
+ let plain = 0;
9
+ const retain = (n, attributes) => {
10
+ if (n <= 0)
11
+ return;
12
+ if (!attributes) {
13
+ plain += n;
14
+ return;
15
+ }
16
+ if (plain)
17
+ delta.push({ retain: plain });
18
+ plain = 0;
19
+ delta.push({ retain: n, attributes });
20
+ };
21
+ for (const p of t.paragraphs) {
22
+ for (const r of p.runs)
23
+ retain(r.text.length, run(r));
24
+ retain(1, para(p));
25
+ }
26
+ return delta.length ? delta : null;
27
+ }
28
+ function formatText(tx, o, run, para) {
29
+ if (!o.text)
30
+ return;
31
+ const delta = formatDelta(o.text, run, para);
32
+ if (delta)
33
+ tx.editText(o.id, delta);
34
+ }
35
+ const isShape = (o) => o.kind !== "connector" && o.kind !== "group";
36
+ const hasLineEnds = (o) => o.kind === "connector" || o.kind === "path";
37
+ const hasOpenStroke = (o) => o.kind === "connector" || (o.kind === "path" && !!openPathEnds(o.path ?? []));
38
+ const CORNERS = ["radiusTopLeft", "radiusTopRight", "radiusBottomRight", "radiusBottomLeft"];
39
+ const PADDINGS = ["paddingTop", "paddingRight", "paddingBottom", "paddingLeft"];
40
+ function commonValue(o, keys, fallback) {
41
+ const values = keys.map((k) => o.style[k] ?? fallback);
42
+ return values.every((v) => v === values[0]) ? values[0] : undefined;
43
+ }
44
+ const writeAll = (keys) => (tx, o, value) => {
45
+ for (const k of keys)
46
+ tx.set(o.id, `style.${k}`, value);
47
+ };
48
+ const previewAll = (keys) => (value) => Object.fromEntries(keys.map((key) => [`style.${key}`, value]));
49
+ const normalizedFills = (paints) => paints.length > 1 ? paints : paints[0];
50
+ const ARROW_STYLES = ["none", "arrow", "triangle", "triangle-open", "triangle-skinny", "circle", "circle-open", "diamond", "diamond-open", "square", "square-open", "bar", "crow"];
51
+ const DASHES = { solid: undefined, dash: [9, 4], longDash: [17, 8], shortDash: [3, 1], dot: [1, 1], dashDot: [9, 4, 2, 4], dashDotDot: [9, 4, 2, 4, 2, 4] };
52
+ const dashName = (dash) => (dash === undefined ? "solid" : (Object.keys(DASHES).find((k) => JSON.stringify(DASHES[k]) === JSON.stringify(dash)) ?? "custom"));
53
+ function writeTextStyle(styleKey, clears) {
54
+ return (tx, o, value) => {
55
+ tx.set(o.id, `style.${styleKey}`, value);
56
+ if ("run" in clears)
57
+ formatText(tx, o, (r) => (r[clears.run] !== undefined ? { [clears.run]: null } : null), unchanged);
58
+ else
59
+ formatText(tx, o, unchanged, (p) => (p[clears.para] !== undefined ? { [clears.para]: null } : null));
60
+ };
61
+ }
62
+ const textKey = (styleKey, clears) => ({ write: writeTextStyle(styleKey, clears), clearsText: clears });
63
+ const EMBED_KEYS = new Set(["url", "embedUrl", "title", "icon", "preview"]);
64
+ function embedValue(v) {
65
+ if (!v || typeof v !== "object" || Array.isArray(v))
66
+ return undefined;
67
+ const r = v;
68
+ if (typeof r.url !== "string" || !r.url)
69
+ return undefined;
70
+ if (Object.keys(r).some((k) => !EMBED_KEYS.has(k)))
71
+ return undefined;
72
+ if (r.embedUrl !== undefined && typeof r.embedUrl !== "string")
73
+ return undefined;
74
+ if (r.title !== undefined && typeof r.title !== "string")
75
+ return undefined;
76
+ const out = {};
77
+ for (const k of EMBED_KEYS)
78
+ if (r[k] !== undefined)
79
+ out[k] = r[k];
80
+ return out;
81
+ }
82
+ const hasFill = (o) => o.kind === "rect" || o.kind === "ellipse" || o.kind === "sticky" || o.kind === "frame" || o.kind === "section" || o.kind === "text" || o.kind === "path" || o.kind === "embed";
83
+ const hasRadius = (o) => o.kind === "rect" || o.kind === "sticky" || o.kind === "frame" || o.kind === "section" || o.kind === "embed";
84
+ const hasStroke = (o) => o.kind !== "group" && o.kind !== "image";
85
+ const hasSides = (o) => o.kind === "rect" || o.kind === "sticky" || o.kind === "frame" || o.kind === "section";
86
+ const movable = (o) => isShape(o) && !o.locked;
87
+ export const canHaveText = (o) => o.kind !== "connector" && o.kind !== "group" && o.kind !== "image" && o.kind !== "embed" && o.kind !== "instance";
88
+ const hasText = canHaveText;
89
+ const AGGREGATES = new WeakMap();
90
+ export function aggregateMembers(d) {
91
+ return d && AGGREGATES.get(d);
92
+ }
93
+ const BUILTIN_READS = new WeakMap();
94
+ const READ_STATES = new WeakMap();
95
+ function sameReadState(d, s, run, para) {
96
+ return d.key === s.key && d.read === s.read && d.appliesTo === s.appliesTo && d.path === s.path
97
+ && d.multi === s.multi && d.textMark === s.textMark && d.markRead === s.markRead
98
+ && d.markWrite === s.markWrite && d.write === s.write && d.previewPatch === s.previewPatch
99
+ && d.rotationUnit === s.rotationUnit && run === s.clearsRun && para === s.clearsPara;
100
+ }
101
+ function readState(d, run, para, deps) {
102
+ return Object.freeze({
103
+ key: d.key, read: d.read, appliesTo: d.appliesTo, path: d.path, multi: d.multi,
104
+ textMark: d.textMark, markRead: d.markRead, markWrite: d.markWrite, write: d.write,
105
+ previewPatch: d.previewPatch, rotationUnit: d.rotationUnit, clearsRun: run, clearsPara: para, deps,
106
+ });
107
+ }
108
+ export function readDescriptorState(d) {
109
+ const clear = d.clearsText;
110
+ const run = clear && "run" in clear ? clear.run : undefined;
111
+ const para = clear && "para" in clear ? clear.para : undefined;
112
+ const current = READ_STATES.get(d);
113
+ if (current && sameReadState(d, current, run, para))
114
+ return current;
115
+ const original = BUILTIN_READS.get(d);
116
+ const next = original && sameReadState(d, original, run, para) ? original : readState(d, run, para);
117
+ READ_STATES.set(d, next);
118
+ return next;
119
+ }
120
+ export function builtinReadDependencies(d) {
121
+ return readDescriptorState(d).deps;
122
+ }
123
+ function rememberBuiltinRead(d) {
124
+ let paths;
125
+ switch (d.key) {
126
+ case "x":
127
+ case "y":
128
+ case "w":
129
+ case "h":
130
+ paths = ["x", "y", "w", "h", "rot", "hidden", "kind"];
131
+ break;
132
+ case "rotation":
133
+ paths = ["rot"];
134
+ break;
135
+ case "locked":
136
+ case "hidden":
137
+ case "embed":
138
+ paths = [d.key];
139
+ break;
140
+ case "fills":
141
+ paths = ["style.fill"];
142
+ break;
143
+ case "radius":
144
+ paths = CORNERS.map((key) => `style.${key}`);
145
+ break;
146
+ case "padding":
147
+ paths = PADDINGS.map((key) => `style.${key}`);
148
+ break;
149
+ case "dash":
150
+ paths = ["style.dash"];
151
+ break;
152
+ case "lineEnd":
153
+ paths = ["style.lineEnd", "kind"];
154
+ break;
155
+ case "bold":
156
+ paths = ["text", "style.fontWeight"];
157
+ break;
158
+ case "italic":
159
+ case "underline":
160
+ case "strike":
161
+ paths = ["text", `style.${d.key}`];
162
+ break;
163
+ case "textAlign":
164
+ paths = ["text", "style.align"];
165
+ break;
166
+ case "list":
167
+ case "checked":
168
+ case "indent":
169
+ paths = ["text"];
170
+ break;
171
+ case "link":
172
+ paths = [];
173
+ break;
174
+ default: if (d.path)
175
+ paths = [d.path];
176
+ }
177
+ if (paths) {
178
+ const clear = d.clearsText;
179
+ const state = readState(d, clear && "run" in clear ? clear.run : undefined, clear && "para" in clear ? clear.para : undefined, Object.freeze(paths));
180
+ BUILTIN_READS.set(d, state);
181
+ READ_STATES.set(d, state);
182
+ }
183
+ }
184
+ export function builtinProperties() {
185
+ const r = new PropertyRegistry();
186
+ const geom = (key, label, multi) => ({
187
+ key,
188
+ label,
189
+ type: "number",
190
+ group: "geometry",
191
+ appliesTo: movable,
192
+ read: (o) => o[key],
193
+ path: key,
194
+ multi,
195
+ step: 1,
196
+ unit: "px",
197
+ });
198
+ r.register(geom("x", "X", "bounds"));
199
+ r.register(geom("y", "Y", "bounds"));
200
+ r.register(geom("w", "Width", "bounds"));
201
+ r.register(geom("h", "Height", "bounds"));
202
+ r.register({
203
+ key: "rotation",
204
+ label: "Rotation",
205
+ type: "number",
206
+ group: "geometry",
207
+ appliesTo: movable,
208
+ read: (o) => Math.round((o.rot * 180) / Math.PI * 10) / 10,
209
+ write: (tx, o, deg) => tx.set(o.id, "rot", (deg * Math.PI) / 180),
210
+ rotationUnit: "degrees",
211
+ min: -360,
212
+ max: 360,
213
+ step: 1,
214
+ unit: "deg",
215
+ });
216
+ r.register({ key: "name", label: "Name", type: "string", group: "object", appliesTo: () => true, read: (o) => o.name ?? "", path: "name" });
217
+ r.register({ key: "locked", label: "Locked", type: "boolean", group: "object", appliesTo: isShape, read: (o) => !!o.locked, write: (tx, o, v) => tx.set(o.id, "locked", v ? true : undefined) });
218
+ r.register({ key: "hidden", label: "Hidden", type: "boolean", group: "object", appliesTo: () => true, read: (o) => !!o.hidden, write: (tx, o, v) => tx.set(o.id, "hidden", v ? true : undefined) });
219
+ r.register({ key: "embed", label: "Link", type: "embed", group: "embed", appliesTo: (o) => o.kind === "embed", read: (o) => o.embed, write: (tx, o, v) => {
220
+ const e = embedValue(v);
221
+ if (e)
222
+ tx.set(o.id, "embed", e);
223
+ } });
224
+ r.register({ key: "fill", label: "Fill", type: "paint", group: "fill", appliesTo: hasFill, read: (o) => (Array.isArray(o.style.fill) ? undefined : o.style.fill ?? undefined), path: "style.fill", write: (tx, o, value) => tx.set(o.id, "style.fill", value ?? undefined), previewPatch: (value) => ({ "style.fill": value ?? undefined }) });
225
+ r.register({ key: "fills", label: "Fill layers", type: "paints", group: "fill", appliesTo: hasFill, read: (o) => (Array.isArray(o.style.fill) ? o.style.fill : o.style.fill == null ? [] : [o.style.fill]), write: (tx, o, paints) => tx.set(o.id, "style.fill", normalizedFills(paints)), previewPatch: (paints) => ({ "style.fill": normalizedFills(paints) }) });
226
+ r.register({ key: "opacity", label: "Opacity", type: "number", group: "fill", appliesTo: isShape, read: (o) => o.style.opacity ?? 1, path: "style.opacity", min: 0, max: 1, step: 0.05 });
227
+ r.register({ key: "stroke", label: "Stroke", type: "color", group: "stroke", appliesTo: hasStroke, read: (o) => o.style.stroke, path: "style.stroke" });
228
+ r.register({ key: "strokeWidth", label: "Stroke width", type: "number", group: "stroke", appliesTo: hasStroke, read: (o) => o.style.strokeWidth ?? 1, path: "style.strokeWidth", min: 0, max: 50, step: 0.5, unit: "px" });
229
+ r.register({ key: "strokeAlign", label: "Stroke align", type: "enum", group: "stroke", appliesTo: hasFill, read: (o) => o.style.strokeAlign ?? "center", path: "style.strokeAlign", options: ["center", "inside", "outside"] });
230
+ r.register({ key: "dash", label: "Line pattern", type: "enum", group: "stroke", appliesTo: hasStroke, read: (o) => dashName(o.style.dash), write: (tx, o, name) => tx.set(o.id, "style.dash", DASHES[name]), options: Object.keys(DASHES) });
231
+ r.register({ key: "strokeCapStart", label: "Start cap", type: "enum", group: "stroke", appliesTo: hasOpenStroke, read: (o) => o.style.strokeCapStart ?? "butt", path: "style.strokeCapStart", options: ["butt", "round", "square"] });
232
+ r.register({ key: "strokeCapEnd", label: "End cap", type: "enum", group: "stroke", appliesTo: hasOpenStroke, read: (o) => o.style.strokeCapEnd ?? "butt", path: "style.strokeCapEnd", options: ["butt", "round", "square"] });
233
+ r.register({ key: "strokeJoin", label: "Stroke join", type: "enum", group: "stroke", appliesTo: hasStroke, read: (o) => o.style.strokeJoin ?? "miter", path: "style.strokeJoin", options: ["miter", "round", "bevel"] });
234
+ for (const [key, label] of [["strokeTop", "Stroke top"], ["strokeRight", "Stroke right"], ["strokeBottom", "Stroke bottom"], ["strokeLeft", "Stroke left"]]) {
235
+ r.register({ key, label, type: "boolean", group: "stroke", appliesTo: hasSides, read: (o) => o.style[key] !== false, path: `style.${key}` });
236
+ }
237
+ r.register({ key: "radius", label: "Corner radius", type: "number", group: "fill", appliesTo: hasRadius, read: (o) => commonValue(o, CORNERS, 0), write: writeAll(CORNERS), previewPatch: previewAll(CORNERS), min: 0, max: 200, step: 1, unit: "px" });
238
+ AGGREGATES.set(r.get("radius"), CORNERS);
239
+ for (const [key, label] of [["radiusTopLeft", "Top left radius"], ["radiusTopRight", "Top right radius"], ["radiusBottomRight", "Bottom right radius"], ["radiusBottomLeft", "Bottom left radius"]]) {
240
+ r.register({ key, label, type: "number", group: "fill", appliesTo: hasRadius, read: (o) => o.style[key] ?? 0, path: `style.${key}`, min: 0, max: 200, step: 1, unit: "px" });
241
+ }
242
+ r.register({ key: "shadowOn", label: "Shadow", type: "boolean", group: "effects", appliesTo: isShape, read: (o) => o.style.shadowOn ?? false, path: "style.shadowOn" });
243
+ r.register({ key: "shadowColor", label: "Shadow color", type: "color", group: "effects", appliesTo: isShape, read: (o) => o.style.shadowColor ?? "#00000059", path: "style.shadowColor" });
244
+ r.register({ key: "shadowX", label: "Shadow x", type: "number", group: "effects", appliesTo: isShape, read: (o) => o.style.shadowX ?? 5, path: "style.shadowX", step: 1, unit: "px" });
245
+ r.register({ key: "shadowY", label: "Shadow y", type: "number", group: "effects", appliesTo: isShape, read: (o) => o.style.shadowY ?? 5, path: "style.shadowY", step: 1, unit: "px" });
246
+ r.register({ key: "shadowBlur", label: "Shadow blur", type: "number", group: "effects", appliesTo: isShape, read: (o) => o.style.shadowBlur ?? 3.39, path: "style.shadowBlur", min: 0, max: 100, step: 0.5 });
247
+ r.register({ key: "shadowSpread", label: "Shadow spread", type: "number", group: "effects", appliesTo: isShape, read: (o) => o.style.shadowSpread ?? 0, path: "style.shadowSpread", step: 1, unit: "px" });
248
+ r.register({ key: "lineStart", label: "Start arrow", type: "enum", group: "stroke", appliesTo: hasLineEnds, read: (o) => o.style.lineStart ?? "none", path: "style.lineStart", options: ARROW_STYLES });
249
+ r.register({ key: "lineEnd", label: "End arrow", type: "enum", group: "stroke", appliesTo: hasLineEnds, read: (o) => o.style.lineEnd ?? (o.kind === "connector" ? "arrow" : "none"), path: "style.lineEnd", options: ARROW_STYLES });
250
+ r.register({ key: "fontFamily", label: "Font", type: "font", group: "text", appliesTo: hasText, read: (o) => o.style.fontFamily ?? "Inter", path: "style.fontFamily", ...textKey("fontFamily", { run: "family" }), textMark: "family" });
251
+ r.register({ key: "fontSize", label: "Size", type: "number", group: "text", appliesTo: hasText, read: (o) => o.style.fontSize ?? 14, path: "style.fontSize", ...textKey("fontSize", { run: "size" }), min: 4, max: 400, step: 1, unit: "px", textMark: "size" });
252
+ r.register({ key: "fontWeight", label: "Weight", type: "number", group: "text", appliesTo: hasText, read: (o) => o.style.fontWeight ?? 400, path: "style.fontWeight", ...textKey("fontWeight", { run: "weight" }), min: 100, max: 900, step: 100, textMark: "weight" });
253
+ r.register({ key: "textColor", label: "Text color", type: "color", group: "text", appliesTo: hasText, read: (o) => o.style.color ?? "#1a1a1a", path: "style.color", ...textKey("color", { run: "color" }), textMark: "color" });
254
+ r.register({ key: "textAlign", label: "Align", type: "enum", group: "text", appliesTo: hasText, read: (o) => o.text?.paragraphs[0]?.align ?? o.style.align ?? "left", path: "style.align", ...textKey("align", { para: "align" }), options: ["left", "center", "right", "justify"], textMark: "align" });
255
+ r.register({ key: "letterSpacing", label: "Letter spacing", type: "number", group: "text", appliesTo: hasText, read: (o) => o.style.letterSpacing ?? 0, path: "style.letterSpacing", ...textKey("letterSpacing", { run: "letterSpacing" }), step: 0.5, unit: "px", textMark: "letterSpacing" });
256
+ r.register({ key: "textCase", label: "Text case", type: "enum", group: "text", appliesTo: hasText, read: (o) => o.style.textCase ?? "none", path: "style.textCase", ...textKey("textCase", { run: "textCase" }), options: ["none", "upper", "lower"], textMark: "textCase" });
257
+ r.register({ key: "lineHeight", label: "Line height", type: "number", group: "text", appliesTo: hasText, read: (o) => o.style.lineHeight ?? 1.4, path: "style.lineHeight", ...textKey("lineHeight", { para: "lineHeight" }), min: 0.5, max: 4, step: 0.1, textMark: "lineHeight" });
258
+ r.register({ key: "padding", label: "Padding", type: "number", group: "text", appliesTo: hasText, read: (o) => commonValue(o, PADDINGS, 8), write: writeAll(PADDINGS), previewPatch: previewAll(PADDINGS), min: 0, max: 200, step: 1, unit: "px" });
259
+ AGGREGATES.set(r.get("padding"), PADDINGS);
260
+ for (const [key, label] of [["paddingTop", "Top padding"], ["paddingRight", "Right padding"], ["paddingBottom", "Bottom padding"], ["paddingLeft", "Left padding"]]) {
261
+ r.register({ key, label, type: "number", group: "text", appliesTo: hasText, read: (o) => o.style[key] ?? 8, path: `style.${key}`, min: 0, max: 200, step: 1, unit: "px" });
262
+ }
263
+ const effectiveWeight = (o, r) => r.weight ?? o.style.fontWeight ?? 400;
264
+ r.register({
265
+ key: "bold",
266
+ label: "Bold",
267
+ type: "boolean",
268
+ group: "text",
269
+ appliesTo: hasText,
270
+ read: (o) => {
271
+ const runs = textRuns(o);
272
+ return runs.length > 0 ? runs.every((r) => effectiveWeight(o, r) >= 600) : (o.style.fontWeight ?? 400) >= 600;
273
+ },
274
+ write: (tx, o, value) => writeTextStyle("fontWeight", { run: "weight" })(tx, o, value ? 700 : 400),
275
+ textMark: "weight",
276
+ markRead: (w) => typeof w === "number" && w >= 600,
277
+ markWrite: (on) => (on ? 700 : 400),
278
+ });
279
+ const boolMark = (key, label) => ({
280
+ key,
281
+ label,
282
+ type: "boolean",
283
+ group: "text",
284
+ appliesTo: hasText,
285
+ read: (o) => {
286
+ const runs = textRuns(o);
287
+ const base = o.style[key] ?? false;
288
+ return runs.length > 0 ? runs.every((r) => r[key] ?? base) : base;
289
+ },
290
+ write: (tx, o, value) => writeTextStyle(key, { run: key })(tx, o, value || undefined),
291
+ textMark: key,
292
+ });
293
+ r.register(boolMark("italic", "Italic"));
294
+ r.register(boolMark("underline", "Underline"));
295
+ r.register(boolMark("strike", "Strikethrough"));
296
+ r.register({
297
+ key: "list",
298
+ label: "List",
299
+ type: "enum",
300
+ group: "text",
301
+ appliesTo: hasText,
302
+ read: (o) => o.text?.paragraphs[0]?.list ?? "none",
303
+ write: (tx, o, value) => {
304
+ const list = value === "bullet" || value === "number" || value === "task" ? value : undefined;
305
+ formatText(tx, o, unchanged, (p) => {
306
+ const f = {};
307
+ if (p.list !== list)
308
+ f.list = list ?? null;
309
+ if (list !== "task" && p.checked !== undefined)
310
+ f.checked = null;
311
+ return Object.keys(f).length ? f : null;
312
+ });
313
+ },
314
+ options: ["none", "bullet", "number", "task"],
315
+ textMark: "list",
316
+ });
317
+ r.register({
318
+ key: "checked",
319
+ label: "Checked",
320
+ type: "boolean",
321
+ group: "text",
322
+ appliesTo: (o) => hasText(o) && (o.text?.paragraphs.some((p) => p.list === "task") ?? false),
323
+ read: (o) => o.text?.paragraphs.find((p) => p.list === "task")?.checked ?? false,
324
+ write: (tx, o, value) => formatText(tx, o, unchanged, (p) => (p.list === "task" && !!p.checked !== value ? { checked: value ? true : null } : null)),
325
+ textMark: "checked",
326
+ });
327
+ r.register({
328
+ key: "indent",
329
+ label: "Indent",
330
+ type: "number",
331
+ group: "text",
332
+ appliesTo: hasText,
333
+ read: (o) => o.text?.paragraphs[0]?.indent ?? 0,
334
+ write: (tx, o, value) => {
335
+ const indent = Math.max(0, Math.min(MAX_INDENT, Math.round(value)));
336
+ formatText(tx, o, unchanged, (p) => ((p.indent ?? 0) !== indent ? { indent: indent || null } : null));
337
+ },
338
+ min: 0,
339
+ max: MAX_INDENT,
340
+ step: 1,
341
+ textMark: "indent",
342
+ });
343
+ r.register({ key: "link", label: "Link", type: "string", group: "text", appliesTo: hasText, read: () => undefined, textMark: "link" });
344
+ r.register({ key: "valign", label: "Vertical align", type: "enum", group: "text", appliesTo: hasText, read: (o) => o.style.valign ?? "top", path: "style.valign", options: ["top", "middle", "bottom"] });
345
+ r.register({ key: "route", label: "Route", type: "enum", group: "connector", appliesTo: (o) => o.kind === "connector", read: (o) => o.conn?.route, path: "conn.route", options: ["straight", "ortho", "curve"] });
346
+ r.register({ key: "bendRadius", label: "Bend radius", type: "number", group: "connector", appliesTo: (o) => o.kind === "connector", read: (o) => o.style.bendRadius ?? 0, path: "style.bendRadius", min: 0, max: 50, step: 1, unit: "px" });
347
+ for (const d of r.all())
348
+ rememberBuiltinRead(d);
349
+ return r;
350
+ }
@@ -0,0 +1,6 @@
1
+ import type { ObjectKind, Style } from "@daasboard/render-core";
2
+ export declare function defaultStyle(kind: ObjectKind): Style;
3
+ export declare function defaultSize(kind: ObjectKind): {
4
+ w: number;
5
+ h: number;
6
+ };
@@ -0,0 +1,29 @@
1
+ const LABEL_FONT = { fontFamily: "Inter", fontSize: 14 };
2
+ const TEXT_COLOR = "#1f2937";
3
+ const corners = (r) => ({ radiusTopLeft: r, radiusTopRight: r, radiusBottomRight: r, radiusBottomLeft: r });
4
+ const padding = (p) => ({ paddingTop: p, paddingRight: p, paddingBottom: p, paddingLeft: p });
5
+ const STYLES = {
6
+ rect: { fill: "#bfdbfe", stroke: "#1e3a8a", strokeWidth: 1, ...corners(6), ...LABEL_FONT, color: TEXT_COLOR, ...padding(6), align: "center", valign: "middle" },
7
+ ellipse: { fill: "#bbf7d0", stroke: "#14532d", strokeWidth: 1, ...LABEL_FONT, color: TEXT_COLOR, ...padding(6), align: "center", valign: "middle" },
8
+ path: { fill: "#bfdbfe", stroke: "#1e3a8a", strokeWidth: 1, ...LABEL_FONT, color: TEXT_COLOR, ...padding(6), align: "center", valign: "middle" },
9
+ sticky: { fill: "#fde68a", stroke: "#92400e", strokeWidth: 1, ...corners(2), shadowOn: true, shadowX: 0, shadowY: 2, shadowBlur: 6, shadowSpread: 0, shadowColor: "#00000033", fontFamily: "Inter", fontSize: 13, color: TEXT_COLOR, ...padding(12), align: "left", valign: "top" },
10
+ text: { fontFamily: "Inter", fontSize: 16, color: TEXT_COLOR, ...padding(4), align: "left", valign: "top" },
11
+ frame: { fill: "#fafafa", stroke: "#d4d4d8", strokeWidth: 1, ...corners(8), ...LABEL_FONT, color: "#52525b", ...padding(8), align: "left", valign: "top" },
12
+ section: { fill: "#f1f5f9", stroke: "#cbd5e1", strokeWidth: 1, ...corners(8), ...LABEL_FONT, color: "#52525b", ...padding(8), align: "left", valign: "top" },
13
+ connector: { stroke: "#374151", strokeWidth: 2, lineStart: "none", lineEnd: "arrow" },
14
+ embed: { fill: "#ffffff", stroke: "#d4d4d8", strokeWidth: 1, ...corners(6), ...LABEL_FONT, color: TEXT_COLOR, ...padding(8), align: "left", valign: "top" },
15
+ };
16
+ export function defaultStyle(kind) {
17
+ return { ...(STYLES[kind] ?? {}) };
18
+ }
19
+ const SIZES = {
20
+ sticky: { w: 160, h: 160 },
21
+ embed: { w: 240, h: 160 },
22
+ text: { w: 200, h: 40 },
23
+ frame: { w: 400, h: 300 },
24
+ section: { w: 400, h: 300 },
25
+ };
26
+ export function defaultSize(kind) {
27
+ const s = SIZES[kind];
28
+ return s ? { ...s } : { w: 120, h: 80 };
29
+ }
@@ -0,0 +1,25 @@
1
+ import type { DocumentAdapter } from "@daasboard/doc";
2
+ export interface TextRange {
3
+ objectId: string;
4
+ from: number;
5
+ to: number;
6
+ }
7
+ export declare class SelectionModel {
8
+ private set_;
9
+ private text_;
10
+ private listeners;
11
+ get ids(): ReadonlySet<string>;
12
+ get size(): number;
13
+ get textRange(): TextRange | null;
14
+ has(id: string): boolean;
15
+ toArray(): string[];
16
+ set(ids: Iterable<string>): void;
17
+ add(ids: Iterable<string>): void;
18
+ remove(ids: Iterable<string>): void;
19
+ toggle(id: string): void;
20
+ clear(): void;
21
+ setTextRange(r: TextRange | null): void;
22
+ onChange(l: () => void): () => void;
23
+ private emit;
24
+ }
25
+ export declare function keepSelectionInDocument(selection: SelectionModel, doc: DocumentAdapter): () => void;
@@ -0,0 +1,79 @@
1
+ export class SelectionModel {
2
+ set_ = new Set();
3
+ text_ = null;
4
+ listeners = new Set();
5
+ get ids() {
6
+ return this.set_;
7
+ }
8
+ get size() {
9
+ return this.set_.size;
10
+ }
11
+ get textRange() {
12
+ return this.text_;
13
+ }
14
+ has(id) {
15
+ return this.set_.has(id);
16
+ }
17
+ toArray() {
18
+ return [...this.set_];
19
+ }
20
+ set(ids) {
21
+ this.set_ = new Set(ids);
22
+ this.text_ = null;
23
+ this.emit();
24
+ }
25
+ add(ids) {
26
+ for (const id of ids)
27
+ this.set_.add(id);
28
+ this.emit();
29
+ }
30
+ remove(ids) {
31
+ let changed = false;
32
+ for (const id of ids)
33
+ if (this.set_.delete(id))
34
+ changed = true;
35
+ if (this.text_ && !this.set_.has(this.text_.objectId)) {
36
+ this.text_ = null;
37
+ changed = true;
38
+ }
39
+ if (changed)
40
+ this.emit();
41
+ }
42
+ toggle(id) {
43
+ if (this.set_.has(id))
44
+ this.set_.delete(id);
45
+ else
46
+ this.set_.add(id);
47
+ this.emit();
48
+ }
49
+ clear() {
50
+ if (this.set_.size === 0 && !this.text_)
51
+ return;
52
+ this.set_.clear();
53
+ this.text_ = null;
54
+ this.emit();
55
+ }
56
+ setTextRange(r) {
57
+ this.text_ = r;
58
+ if (r)
59
+ this.set_ = new Set([r.objectId]);
60
+ this.emit();
61
+ }
62
+ onChange(l) {
63
+ this.listeners.add(l);
64
+ return () => this.listeners.delete(l);
65
+ }
66
+ emit() {
67
+ for (const l of this.listeners)
68
+ l();
69
+ }
70
+ }
71
+ export function keepSelectionInDocument(selection, doc) {
72
+ return doc.subscribe(() => {
73
+ if (selection.size === 0)
74
+ return;
75
+ const gone = selection.toArray().filter((id) => !doc.get(id));
76
+ if (gone.length)
77
+ selection.remove(gone);
78
+ });
79
+ }