@link-foundation/ui-designer 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/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ This is free and unencumbered software released into the public domain.
2
+
3
+ Anyone is free to copy, modify, publish, use, compile, sell, or
4
+ distribute this software, either in source code form or as a compiled
5
+ binary, for any purpose, commercial or non-commercial, and by any
6
+ means.
7
+
8
+ In jurisdictions that recognize copyright laws, the author or authors
9
+ of this software dedicate any and all copyright interest in the
10
+ software to the public domain. We make this dedication for the benefit
11
+ of the public at large and to the detriment of our heirs and
12
+ successors. We intend this dedication to be an overt act of
13
+ relinquishment in perpetuity of all present and future rights to this
14
+ software under copyright law.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ For more information, please refer to <https://unlicense.org>
package/README.md CHANGED
@@ -1,3 +1,181 @@
1
- # Temporary Holding Version
1
+ # @link-foundation/ui-designer
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A WYSIWYG designer whose docked shell and editable document are Links
4
+ Notation. It reuses ui-components docking and controls, ui-devmode's overlay,
5
+ outline model, policy and typed property grid, ui-store history and ui-core's
6
+ source-preserving editor. No build step is needed.
7
+
8
+ Serve the repository with `node scripts/serve-static.mjs` and open
9
+ `http://127.0.0.1:4173/packages/ui-designer/examples/index.html`.
10
+ The example opens the sample document with comments and executable actions.
11
+
12
+ ```js
13
+ import { mountDesigner } from '@link-foundation/ui-designer';
14
+ import '@link-foundation/ui-components/layout';
15
+ import '@link-foundation/ui-components/layout.css';
16
+ import '@link-foundation/ui-components/controls.css';
17
+ import '@link-foundation/ui-components/editor.css';
18
+ import '@link-foundation/ui-designer/designer.css';
19
+
20
+ const designer = mountDesigner({ root, documentText });
21
+ const source = designer.getText();
22
+ designer.undo();
23
+ designer.redo();
24
+ designer.destroy();
25
+ ```
26
+
27
+ `src/designer.lino` defines the Toolbox/Outline tabs, Canvas, Properties and
28
+ Source docks. `layoutText` can replace that shell while retaining its named
29
+ panels and toolbar actions. `src/layout-text.js` embeds the same document for
30
+ synchronous mounting; a test checks they match. The framework's panel menus
31
+ collapse, restore, close and move panels; separators support pointer and
32
+ keyboard resizing. `Ctrl+F6` cycles panels.
33
+
34
+ `mountDesigner` also accepts `storage` (Web Storage, or `null`), `storageKey`
35
+ (default `link-ui-designer`), `policy` (the ui-devmode policy object or LiNo),
36
+ `catalog`, `snapThreshold` (default 6 CSS pixels), `onAction` and optional
37
+ `trace(event, detail)`. Tracing is off unless supplied. Policy-disabled
38
+ mounts fail; locked elements and their descendants cannot be edited, moved
39
+ or removed through canvas, properties, clipboard or Source. No writable
40
+ policy layers means read-only editing. Run mode dispatches the canvas's
41
+ normal actions to `onAction`; Design mode intercepts clicks to select.
42
+
43
+ The result exposes `store`, `select(id)`, `setMode('design'|'run')` and
44
+ `editSource(text)` as well as `getText`, `undo`, `redo`, and `destroy`.
45
+ Each successful editing gesture is one store transaction. A preview store
46
+ validates the complete change and source patch before the real store changes.
47
+ Undo/redo restore both the document and the exact original source text.
48
+
49
+ The draft is the current document text, persisted after each transaction under
50
+ `<storageKey>.draft`; reload recreates the store from that text. Dock layout is
51
+ saved as LiNo through ui-config's `user` layer under `<storageKey>.user`.
52
+ Unavailable or full storage does not prevent editing. Open uses a file input;
53
+ Save downloads the current `.lino` text; Copy source uses the clipboard (or
54
+ focuses Source with Select All/Copy instructions when clipboard permission is
55
+ unavailable). Fragment
56
+ copy/paste also has an internal clipboard fallback.
57
+
58
+ ## Editing
59
+
60
+ | Action | Pointer | Keyboard |
61
+ | -------------------- | ---------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
62
+ | Select | Click canvas or Outline | Outline arrows, Home/End, Enter/Space |
63
+ | Extend selection | Shift+click range, Ctrl/Cmd+click toggle; drag blank canvas for marquee | Shift+Outline arrows |
64
+ | Insert | Click toolbox or drag into canvas/Outline | Enter on toolbox item inserts into selected container |
65
+ | Move | Drag canvas/Outline; edges indicate flow insertion, centre selects container | Alt+Up/Down reorders siblings; cut/paste reparents |
66
+ | Delete / duplicate | Toolbar | Delete; Ctrl/Cmd+D |
67
+ | Cut / copy / paste | Toolbar | Ctrl/Cmd+X/C/V |
68
+ | Undo / redo | Toolbar | Ctrl/Cmd+Z; Ctrl/Cmd+Shift+Z |
69
+ | Move by pixels | Drag within current container with sibling snap guides | Canvas arrows: 1 px; Shift+arrows: 10 px |
70
+ | Resize explicit size | Drag corner handle | Focus handle; arrows: 1 px, Shift+arrows: 10 px; or edit width/height in Properties |
71
+ | Cancel gesture | — | Escape (pointer cancellation also discards preview) |
72
+ | Save / open | Toolbar | Ctrl/Cmd+S/O |
73
+
74
+ The toolbox derives types, child rules and property types from #34's control
75
+ vocabulary and the layout vocabulary. Entries have names, icons and initial
76
+ text/button defaults. `createCatalog(vocabulary)` returns a customizable Map;
77
+ `canContain(catalog, parentType, childType)` uses its `children` rule (`any`,
78
+ `none` or an array of allowed kinds). Unknown types refuse insertion. Paste
79
+ assigns fresh IDs to every node and remaps reference-typed properties inside
80
+ the fragment. Selected ancestors subsume selected descendants.
81
+
82
+ Pure APIs are exported from the package and the `/commands`, `/selection`,
83
+ `/snap` and `/sync` subpaths. Commands are `insertElement`, `moveElements`,
84
+ `removeElements`, `duplicateElements`, `setProperty`, `copyElements` and
85
+ `pasteElements`. Editing commands return affected IDs and join an existing
86
+ store transaction. Move indexes identify slots before removing the selection.
87
+
88
+ ## Source and geometry
89
+
90
+ Source edits use the official links-notation parser and reconcile named IDs
91
+ and anonymous sibling identities, rather than replacing the whole store.
92
+ Parse errors return `{error: {line, column, message}}`, keep the last valid
93
+ canvas and history, and remain visible in Source. Comment-only edits are
94
+ undoable. Canvas edits use `applyOpsToSource` from ui-core/source so untouched
95
+ text, including comments and whitespace, stays byte-for-byte unchanged.
96
+ Addressed anonymous nodes receive source names derived from their stable store
97
+ IDs; other anonymous nodes remain untouched. The official formatter and source
98
+ index determine those prefixes. Clipboard fragments use the nested form.
99
+
100
+ Source uses the lazy CodeMirror LiNo engine from `ui-components/editor`, with
101
+ syntax highlighting, line numbers and inline diagnostics. Include
102
+ `@link-foundation/ui-components/editor.css` alongside the designer stylesheet.
103
+ Press Escape then Tab to leave the editor; Tab itself indents. Run mode makes
104
+ Source read-only while retaining selection and copying. The mount's `ready`
105
+ promise resolves when Source is initialized.
106
+
107
+ The designer's exported `designerVocabulary()` extends the layout vocabulary
108
+ with `x`/`y` (numbers in CSS pixels) and `width`/`height` (dimensions) on visual
109
+ kinds. Its canvas applies translation and explicit dimensions; these properties
110
+ are preserved in saved LiNo. Windows retain the existing numeric geometry and
111
+ native layout renderer. This is a designer vocabulary extension, recorded
112
+ in `docs/spec/open-questions.md`, pending a core geometry dialect. Flow insertion
113
+ reorders stack/grid children; free movement within a container writes x/y.
114
+
115
+ ## Verification
116
+
117
+ ```sh
118
+ node --test packages/ui-designer/tests/*.test.js
119
+ npx playwright test packages/ui-designer/tests/e2e --workers 1
120
+ npm test
121
+ npm run lint
122
+ npm run format:check
123
+ npm run check:duplication
124
+ ```
125
+
126
+ Browser scenarios cover the four milestones, pointer cancellation, refusal,
127
+ transaction history, keyboard paths, file/clipboard operations and axe WCAG
128
+ 2.2 AA in both light and dark modes. They attach milestone screenshots.
129
+ Set `DESIGNER_SCREENSHOTS=1` when running the Chromium scenarios to refresh
130
+ the four committed milestone screenshots in `docs/screenshots/designer/`.
131
+ All runtime dependencies are existing permissively licensed framework packages;
132
+ the designer adds no third-party runtime library or asset.
133
+
134
+ ## Per-object comments and agent tasks
135
+
136
+ The toolbar's **Comment on UI** opens the same
137
+ [comment panel as dev mode](../ui-devmode/README.md#comment-on-the-ui), initially
138
+ selecting the designer's selected objects. Pick, lasso or use the keyboard
139
+ checkbox list; write or dictate instructions and add one task per object.
140
+ Comment bubbles stay anchored to the canvas while the panel is open. Save,
141
+ resolve/reopen, delete and exchange reviews through validated LiNo.
142
+
143
+ Reviews persist separately under `<storageKey>.comments` using the designer's
144
+ `storage` option. They record exact canonical document versions and an ordered
145
+ comment event history; they do not alter Source, draft text, or document
146
+ undo/redo. Source and canvas edits refresh the review's current/outdated/missing
147
+ indicators. Anonymous objects use stable store IDs in the review snapshot.
148
+ `destroy()` closes the comment panel and stops any active dictation.
149
+
150
+ ## Animation timeline
151
+
152
+ Open the **Timeline** tab beside Source. Animations expand into property lanes;
153
+ recordings have an event lane. The ruler uses milliseconds. Drag the ruler to
154
+ seek the selected animation or recording, and use Play, Pause, Stop and Loop for
155
+ preview. Preview always uses full motion for the edited content. Recording seek
156
+ uses an isolated store; it never creates editing history or changes the source.
157
+
158
+ Click diamonds/events to select, Shift+click to add/remove selection, and drag to
159
+ move. Snapping uses the playhead, other keys/events and a 60 fps frame grid.
160
+ `timelineFps` on `mountDesigner` customizes that grid. Arrow keys move selected
161
+ markers by one frame, Shift+arrows by ten; on the ruler, arrows seek instead.
162
+ Home/End seek to the beginning/end, Space toggles playback, K adds a key/event at
163
+ the playhead, and Delete removes selection. Two keys must remain in each track.
164
+ Every gesture is one undoable source transaction (`Ctrl/Cmd+Z`,
165
+ `Ctrl/Cmd+Shift+Z`). Properties edits the selected value/easing or event action.
166
+ Drag an animation's end handle (or focus it and press arrows) to change duration;
167
+ replacing a duration token requires confirmation. Pass `resolveToken(path)` to
168
+ resolve duration tokens, using the same callback as the animation player.
169
+
170
+ Zoom buttons and Ctrl/Cmd+wheel change the scale; the track area scrolls
171
+ horizontally. The layout is in `src/timeline/timeline.lino`; the runnable example
172
+ is `examples/timeline.html` (serve the repository with
173
+ `node scripts/serve-static.mjs`). Optional `trace` emits `timeline-commit` events
174
+ and stays off by default.
175
+
176
+ The exact midpoint expectation of #57 is blocked by
177
+ [#186](https://github.com/link-foundation/ui/issues/186): the sample's global
178
+ `standard` easing makes the existing player show scale approximately 0.990227 at
179
+ 500 ms, rather than the requested 0.96. The example preserves the original
180
+ animation and player behavior. A visible Playwright FIXME records the unmet
181
+ criterion; other preview, editing and accessibility scenarios run normally.
package/package.json CHANGED
@@ -1,6 +1,43 @@
1
1
  {
2
2
  "name": "@link-foundation/ui-designer",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "LiNo WYSIWYG designer with docked panels, transactional editing and source-preserving two-way sync",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": "./src/index.js",
8
+ "./commands": "./src/commands.js",
9
+ "./selection": "./src/selection.js",
10
+ "./snap": "./src/snap.js",
11
+ "./sync": "./src/sync.js",
12
+ "./designer.css": "./src/designer.css"
13
+ },
14
+ "files": [
15
+ "src/",
16
+ "README.md",
17
+ "LICENSE"
18
+ ],
19
+ "license": "Unlicense",
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/link-foundation/ui.git",
23
+ "directory": "packages/ui-designer"
24
+ },
25
+ "dependencies": {
26
+ "@link-foundation/ui-components": "^0.1.0",
27
+ "@link-foundation/ui-config": "^0.1.0",
28
+ "@link-foundation/ui-core": "^0.1.0",
29
+ "@link-foundation/ui-devmode": "^0.1.0",
30
+ "@link-foundation/ui-dom": "^0.1.0",
31
+ "@link-foundation/ui-store": "^0.1.0",
32
+ "@link-foundation/ui-animation": "^0.1.0"
33
+ },
34
+ "engines": {
35
+ "node": ">=20"
36
+ },
37
+ "publishConfig": {
38
+ "access": "public"
39
+ },
40
+ "devDependencies": {
41
+ "jsdom": "^30.1.3"
42
+ }
43
+ }
package/src/actions.js ADDED
@@ -0,0 +1,195 @@
1
+ /** Shell buttons and shortcuts share the same document commands. */
2
+ import { mountComments } from '@link-foundation/ui-devmode/comments';
3
+ import { isEditableTarget } from '@link-foundation/ui-devmode';
4
+ import {
5
+ moveElements,
6
+ removeElements,
7
+ duplicateElements,
8
+ copyElements,
9
+ pasteElements,
10
+ selectedRoots,
11
+ } from './commands.js';
12
+ import { nudgeElements } from './geometry.js';
13
+ import { insertionParent } from './editing.js';
14
+ import { element, editable } from './dom.js';
15
+
16
+ export function createActions(context) {
17
+ const {
18
+ run,
19
+ store,
20
+ selection,
21
+ session,
22
+ refresh,
23
+ window,
24
+ root,
25
+ document,
26
+ source,
27
+ file,
28
+ report,
29
+ catalog,
30
+ } = context;
31
+ let clipboard = '';
32
+ const selectResult = (ids) => {
33
+ if (ids) {
34
+ selection.replace(ids);
35
+ refresh();
36
+ }
37
+ };
38
+ const commands = {
39
+ comments() {
40
+ if (context.comments) {
41
+ return;
42
+ }
43
+ context.comments = mountComments({
44
+ root: context.canvas,
45
+ tree: store,
46
+ nodeFor: (id) => context.handle.nodeFor(id),
47
+ storage: context.storage,
48
+ storageKey: `${context.storageKey}.comments`,
49
+ trace: context.options.trace,
50
+ onClose() {
51
+ context.comments = null;
52
+ },
53
+ });
54
+ context.comments.select([...selection.ids]);
55
+ },
56
+ mode: () => context.setMode(context.mode() === 'design' ? 'run' : 'design'),
57
+ undo: () => session.undo(),
58
+ redo: () => session.redo(),
59
+ delete: () => run((s) => removeElements(s, selection.ids)),
60
+ duplicate: () =>
61
+ selectResult(run((s) => duplicateElements(s, selection.ids, catalog))),
62
+ async copy() {
63
+ clipboard = copyElements(store, selection.ids);
64
+ try {
65
+ await window.navigator.clipboard?.writeText(clipboard);
66
+ } catch {
67
+ report('Fragment copied inside the designer');
68
+ }
69
+ },
70
+ async cut() {
71
+ await commands.copy();
72
+ commands.delete();
73
+ },
74
+ async paste() {
75
+ let text = clipboard;
76
+ try {
77
+ text = (await window.navigator.clipboard?.readText()) || text;
78
+ } catch {
79
+ /* Internal clipboard remains usable. */
80
+ }
81
+ selectResult(
82
+ run((s) =>
83
+ pasteElements(s, {
84
+ parentId: insertionParent(context),
85
+ text,
86
+ catalog,
87
+ })
88
+ )
89
+ );
90
+ },
91
+ open: () => file.click(),
92
+ save() {
93
+ const url = window.URL.createObjectURL(
94
+ new window.Blob([session.getText()], {
95
+ type: 'text/plain;charset=utf-8',
96
+ })
97
+ );
98
+ const link = element(document, 'a', {
99
+ href: url,
100
+ download: 'document.lino',
101
+ });
102
+ root.append(link);
103
+ link.click();
104
+ link.remove();
105
+ window.setTimeout(() => window.URL.revokeObjectURL(url), 0);
106
+ },
107
+ async 'copy-source'() {
108
+ try {
109
+ await window.navigator.clipboard.writeText(session.getText());
110
+ report('Source copied');
111
+ } catch {
112
+ await source.ready;
113
+ source.focus();
114
+ report('Press Ctrl/Cmd+A, then Ctrl/Cmd+C to copy Source');
115
+ }
116
+ },
117
+ };
118
+ return async (name) => {
119
+ try {
120
+ await commands[name]?.();
121
+ } catch (error) {
122
+ report(error.message);
123
+ }
124
+ };
125
+ }
126
+
127
+ function reorder(event, context, roots) {
128
+ const { store, run, catalog } = context;
129
+ const first = roots[0];
130
+ const parentId = store.parentOf(first);
131
+ if (!roots.every((id) => store.parentOf(id) === parentId)) {
132
+ return;
133
+ }
134
+ const siblings = parentId === null ? store.roots() : store.children(parentId);
135
+ const index =
136
+ event.key === 'ArrowUp'
137
+ ? Math.max(0, store.indexOf(first) - 1)
138
+ : Math.min(siblings.length, store.indexOf(roots.at(-1)) + 2);
139
+ run((s) => moveElements(s, { ids: roots, parentId, index, catalog }));
140
+ }
141
+ const arrowDelta = (key, step) =>
142
+ ({
143
+ ArrowLeft: [-step, 0],
144
+ ArrowRight: [step, 0],
145
+ ArrowUp: [0, -step],
146
+ ArrowDown: [0, step],
147
+ })[key];
148
+
149
+ /** Outline arrows navigate; canvas arrows nudge; Alt+arrows reorder from either. */
150
+ export function keyboard(event, context) {
151
+ if (
152
+ context.source.contains(event.target) ||
153
+ editable(event.target) ||
154
+ isEditableTarget(event.target)
155
+ ) {
156
+ return;
157
+ }
158
+ const key = event.key.toLowerCase();
159
+ const shortcuts = {
160
+ z: event.shiftKey ? 'redo' : 'undo',
161
+ d: 'duplicate',
162
+ c: 'copy',
163
+ x: 'cut',
164
+ v: 'paste',
165
+ s: 'save',
166
+ o: 'open',
167
+ };
168
+ const name =
169
+ event.ctrlKey || event.metaKey
170
+ ? shortcuts[key]
171
+ : ['delete', 'backspace'].includes(key)
172
+ ? 'delete'
173
+ : null;
174
+ if (name) {
175
+ event.preventDefault();
176
+ void context.command(name);
177
+ return;
178
+ }
179
+ const { selection, store, run, canvas } = context;
180
+ const roots = selectedRoots(store, selection.ids);
181
+ if (
182
+ event.altKey &&
183
+ ['ArrowUp', 'ArrowDown'].includes(event.key) &&
184
+ roots.length
185
+ ) {
186
+ event.preventDefault();
187
+ reorder(event, context, roots);
188
+ return;
189
+ }
190
+ const delta = arrowDelta(event.key, event.shiftKey ? 10 : 1);
191
+ if (canvas.contains(event.target) && delta) {
192
+ event.preventDefault();
193
+ run((s) => nudgeElements(s, roots, ...delta));
194
+ }
195
+ }
@@ -0,0 +1,171 @@
1
+ /** Selection overlays, size handles and transient drag decorations. */
2
+ import { createOverlay } from '@link-foundation/ui-devmode/overlay';
3
+ import { isLocked } from '@link-foundation/ui-devmode/model';
4
+ import { property, renderGeometry, resizeElement } from './geometry.js';
5
+ import { element } from './dom.js';
6
+
7
+ export function createCanvasView(context) {
8
+ const {
9
+ root,
10
+ canvas,
11
+ document,
12
+ handle,
13
+ store,
14
+ selection,
15
+ run,
16
+ policy,
17
+ mode,
18
+ } = context;
19
+ const overlay = createOverlay({
20
+ document,
21
+ label: (id, type) => `${id}: ${type}`,
22
+ });
23
+ const decorations = element(document, 'div', {
24
+ class: 'designer-decorations',
25
+ 'aria-hidden': true,
26
+ });
27
+ root.append(decorations);
28
+ let resizeHandle = null;
29
+ function update() {
30
+ renderGeometry(store, handle);
31
+ for (const node of canvas.querySelectorAll('[data-link-id]')) {
32
+ node.toggleAttribute(
33
+ 'data-selected',
34
+ mode() === 'design' && selection.ids.has(handle.idFor(node))
35
+ );
36
+ }
37
+ const id = [...selection.ids].at(-1);
38
+ const node = mode() === 'design' && id ? handle.nodeFor(id) : null;
39
+ overlay.show(
40
+ 'selected',
41
+ node ? { node, id, type: store.get(id).kind } : null
42
+ );
43
+ resizeHandle?.remove();
44
+ resizeHandle = null;
45
+ if (
46
+ node &&
47
+ (property(store, id, 'width') || property(store, id, 'height')) &&
48
+ !isLocked(policy, id, store.parentOf)
49
+ ) {
50
+ const rect = node.getBoundingClientRect();
51
+ resizeHandle = element(document, 'button', {
52
+ class: 'designer-resize',
53
+ 'data-resize': id,
54
+ 'aria-label': `Resize ${id}; arrows change size, Shift changes by 10 pixels`,
55
+ });
56
+ resizeHandle.style.left = `${rect.right - 6}px`;
57
+ resizeHandle.style.top = `${rect.bottom - 6}px`;
58
+ resizeHandle.addEventListener('keydown', (event) => {
59
+ if (
60
+ !['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown'].includes(
61
+ event.key
62
+ )
63
+ ) {
64
+ return;
65
+ }
66
+ event.preventDefault();
67
+ event.stopPropagation();
68
+ const bounds = handle.nodeFor(id).getBoundingClientRect();
69
+ const step = event.shiftKey ? 10 : 1;
70
+ run((s) =>
71
+ resizeElement(
72
+ s,
73
+ id,
74
+ bounds.width +
75
+ (event.key === 'ArrowRight'
76
+ ? step
77
+ : event.key === 'ArrowLeft'
78
+ ? -step
79
+ : 0),
80
+ bounds.height +
81
+ (event.key === 'ArrowDown'
82
+ ? step
83
+ : event.key === 'ArrowUp'
84
+ ? -step
85
+ : 0)
86
+ )
87
+ );
88
+ resizeHandle?.focus();
89
+ });
90
+ root.append(resizeHandle);
91
+ }
92
+ }
93
+
94
+ function clearPreview() {
95
+ decorations.replaceChildren();
96
+ renderGeometry(store, handle);
97
+ }
98
+ function drawBox(rect, className) {
99
+ const box = element(document, 'div', { class: className });
100
+ Object.assign(box.style, {
101
+ left: `${rect.x}px`,
102
+ top: `${rect.y}px`,
103
+ width: `${rect.width}px`,
104
+ height: `${rect.height}px`,
105
+ });
106
+ decorations.append(box);
107
+ return box;
108
+ }
109
+ function showGuides(guides) {
110
+ for (const guide of guides) {
111
+ const box = drawBox(
112
+ guide.axis === 'x'
113
+ ? {
114
+ x: guide.position,
115
+ y: guide.from,
116
+ width: 1,
117
+ height: guide.to - guide.from,
118
+ }
119
+ : {
120
+ x: guide.from,
121
+ y: guide.position,
122
+ width: guide.to - guide.from,
123
+ height: 1,
124
+ },
125
+ 'designer-guide'
126
+ );
127
+ box.dataset.axis = guide.axis;
128
+ }
129
+ }
130
+
131
+ return {
132
+ update,
133
+ clearPreview,
134
+ drawBox,
135
+ showDrop: (drop) => drawDrop(drop, drawBox),
136
+ showGuides,
137
+ clear: () => decorations.replaceChildren(),
138
+ hover(id) {
139
+ const node = id ? handle.nodeFor(id) : null;
140
+ overlay.show(
141
+ 'hover',
142
+ node ? { node, id, type: store.get(id)?.kind } : null
143
+ );
144
+ },
145
+ destroy() {
146
+ overlay.destroy();
147
+ decorations.remove();
148
+ resizeHandle?.remove();
149
+ },
150
+ };
151
+ }
152
+
153
+ function drawDrop(drop, drawBox) {
154
+ if (!drop) {
155
+ return;
156
+ }
157
+ const box = drawBox(
158
+ drop.rect,
159
+ `designer-drop ${drop.valid ? 'allowed' : 'refused'}`
160
+ );
161
+ if (drop.edge) {
162
+ if (drop.horizontal) {
163
+ box.style.left = `${drop.edge === 'after' ? drop.rect.right : drop.rect.left}px`;
164
+ box.style.width = '3px';
165
+ } else {
166
+ box.style.top = `${drop.edge === 'after' ? drop.rect.bottom : drop.rect.top}px`;
167
+ box.style.height = '3px';
168
+ }
169
+ }
170
+ box.dataset.drop = drop.valid ? 'allowed' : 'refused';
171
+ }