@link-foundation/ui-components 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/CONFIGURATIONS.md +74 -0
- package/ICONS.md +76 -0
- package/LICENSE +24 -0
- package/README.md +1499 -2
- package/bin/lino-network.mjs +71 -0
- package/dist/icons/ATTRIBUTION.md +602 -0
- package/dist/icons/NOTICE.lino +1261 -0
- package/dist/icons/brand.js +31 -0
- package/dist/icons/brand.svg +3 -0
- package/dist/icons/licenses/brand/DISCLAIMER.md +51 -0
- package/dist/icons/licenses/brand/LICENSE.md +30 -0
- package/dist/icons/licenses/lucide/LICENSE +43 -0
- package/dist/icons/licenses/material-symbols/LICENSE +202 -0
- package/dist/icons/licenses/material-symbols/NOTICE +12 -0
- package/dist/icons/licenses/tabler/LICENSE +21 -0
- package/dist/icons/lucide.js +681 -0
- package/dist/icons/lucide.svg +34 -0
- package/dist/icons/material-symbols.js +681 -0
- package/dist/icons/material-symbols.svg +34 -0
- package/dist/icons/own.js +521 -0
- package/dist/icons/own.svg +34 -0
- package/dist/icons/tabler.js +681 -0
- package/dist/icons/tabler.svg +34 -0
- package/dist/network-layout-NOTICE.md +6 -0
- package/dist/network-layout-d3-dispatch-LICENSE.txt +13 -0
- package/dist/network-layout-d3-force-LICENSE.txt +13 -0
- package/dist/network-layout-d3-quadtree-LICENSE.txt +13 -0
- package/dist/network-layout-d3-timer-LICENSE.txt +13 -0
- package/dist/network-layout-dagre-LICENSE.txt +19 -0
- package/dist/network-layout.worker.mjs +2 -0
- package/package.json +246 -4
- package/src/a11y/announce.js +88 -0
- package/src/a11y/bind-machine.js +181 -0
- package/src/a11y/focus.js +169 -0
- package/src/a11y/index.d.ts +89 -0
- package/src/a11y/index.js +19 -0
- package/src/a11y/keys.js +182 -0
- package/src/a11y/roving.js +167 -0
- package/src/a11y/typeahead.js +82 -0
- package/src/behavior/actions.js +235 -0
- package/src/behavior/diagnostics.js +73 -0
- package/src/behavior/dom.d.ts +38 -0
- package/src/behavior/dom.js +420 -0
- package/src/behavior/index.d.ts +211 -0
- package/src/behavior/index.js +29 -0
- package/src/behavior/interpret.js +454 -0
- package/src/behavior/machines/disclosure.lino +46 -0
- package/src/behavior/machines/index.js +91 -0
- package/src/behavior/machines/toggle.lino +25 -0
- package/src/behavior/parse-machine.js +367 -0
- package/src/charts/README.md +78 -0
- package/src/charts/activity-layout.js +350 -0
- package/src/charts/activity-model.js +130 -0
- package/src/charts/activity-validation.js +31 -0
- package/src/charts/chart-model.js +667 -0
- package/src/charts/chart.js +518 -0
- package/src/charts/echarts-adapter.d.ts +23 -0
- package/src/charts/echarts-adapter.js +240 -0
- package/src/charts/element.js +330 -0
- package/src/charts/errors.js +62 -0
- package/src/charts/gauge.js +27 -0
- package/src/charts/index.d.ts +344 -0
- package/src/charts/index.js +59 -0
- package/src/charts/layout.js +542 -0
- package/src/charts/lino.js +158 -0
- package/src/charts/mark-options.js +78 -0
- package/src/charts/read.js +101 -0
- package/src/charts/renderer-features.js +8 -0
- package/src/charts/scales.js +223 -0
- package/src/charts/small-model.js +223 -0
- package/src/charts/small-svg.js +269 -0
- package/src/charts/sparkline.js +27 -0
- package/src/charts/stat-tile.js +37 -0
- package/src/charts/summary.js +193 -0
- package/src/charts/svg-renderer.js +226 -0
- package/src/charts/svg.js +69 -0
- package/src/charts/tag-cloud.js +129 -0
- package/src/charts/tokens.js +171 -0
- package/src/charts/tooltip.js +47 -0
- package/src/charts/values.js +146 -0
- package/src/chat/README.md +142 -0
- package/src/chat/actions.js +75 -0
- package/src/chat/chat-contract.js +95 -0
- package/src/chat/chat-list.js +42 -0
- package/src/chat/chat-model.js +125 -0
- package/src/chat/chat.css +228 -0
- package/src/chat/composer.js +131 -0
- package/src/chat/day-separator.js +12 -0
- package/src/chat/dom.js +33 -0
- package/src/chat/follow.js +49 -0
- package/src/chat/index.d.ts +142 -0
- package/src/chat/index.js +13 -0
- package/src/chat/message-bubble.js +191 -0
- package/src/chat/message-stream.js +331 -0
- package/src/chat/reasoning-trace.js +70 -0
- package/src/chat/selection.js +39 -0
- package/src/chat/skins/bubbles.lino +2 -0
- package/src/chat/skins/cards.lino +4 -0
- package/src/chat/skins/compact.lino +4 -0
- package/src/chat/skins/signal.lino +25 -0
- package/src/chat/skins/t3.lino +25 -0
- package/src/chat/skins/telegram.lino +31 -0
- package/src/chat/skins/whatsapp.lino +25 -0
- package/src/chat/stream-keys.js +57 -0
- package/src/chat/stream-window.js +159 -0
- package/src/chat/vocabulary.js +19 -0
- package/src/controls/accordion.js +160 -0
- package/src/controls/avatar.js +80 -0
- package/src/controls/badge.js +48 -0
- package/src/controls/button-template.js +32 -0
- package/src/controls/button.js +97 -0
- package/src/controls/catalog.lino +84 -0
- package/src/controls/checkbox.js +112 -0
- package/src/controls/chip.js +140 -0
- package/src/controls/choices.js +45 -0
- package/src/controls/color-field.js +217 -0
- package/src/controls/color-popover.js +135 -0
- package/src/controls/color-rgb.js +80 -0
- package/src/controls/color.js +67 -0
- package/src/controls/combobox.js +192 -0
- package/src/controls/dom.js +261 -0
- package/src/controls/icon-button.js +33 -0
- package/src/controls/index.d.ts +163 -0
- package/src/controls/index.js +182 -0
- package/src/controls/kinds-text.js +358 -0
- package/src/controls/kinds.lino +350 -0
- package/src/controls/label.js +52 -0
- package/src/controls/link.js +101 -0
- package/src/controls/listbox.js +144 -0
- package/src/controls/machines/button.lino +20 -0
- package/src/controls/machines/checkbox.lino +17 -0
- package/src/controls/machines/chip.lino +20 -0
- package/src/controls/machines/color-field.lino +23 -0
- package/src/controls/machines/combobox.lino +82 -0
- package/src/controls/machines/icon-button.lino +20 -0
- package/src/controls/machines/index.js +586 -0
- package/src/controls/machines/number-field.lino +71 -0
- package/src/controls/machines/radio-group.lino +17 -0
- package/src/controls/machines/select.lino +122 -0
- package/src/controls/machines/slider.lino +99 -0
- package/src/controls/machines/switch.lino +19 -0
- package/src/controls/machines/text-area.lino +26 -0
- package/src/controls/machines/text-field.lino +26 -0
- package/src/controls/number-field.js +239 -0
- package/src/controls/numeric-keys.js +125 -0
- package/src/controls/option.js +54 -0
- package/src/controls/progress.js +76 -0
- package/src/controls/radio-group.js +234 -0
- package/src/controls/select.js +229 -0
- package/src/controls/slider.js +234 -0
- package/src/controls/stories.js +172 -0
- package/src/controls/styles.css +1060 -0
- package/src/controls/switch.js +95 -0
- package/src/controls/text-area.js +39 -0
- package/src/controls/text-field.js +131 -0
- package/src/controls/vocabulary.js +164 -0
- package/src/data/data.css +95 -0
- package/src/data/index.d.ts +83 -0
- package/src/data/index.js +10 -0
- package/src/data/keyboard.js +189 -0
- package/src/data/list.js +215 -0
- package/src/data/render-data.js +116 -0
- package/src/data/selection-dom.js +39 -0
- package/src/data/selection-model.js +43 -0
- package/src/data/sort-model.js +42 -0
- package/src/data/source.js +45 -0
- package/src/data/table.js +160 -0
- package/src/data/tree-model.js +41 -0
- package/src/data/tree.js +55 -0
- package/src/data/viewport.js +216 -0
- package/src/data/virtual-range.js +92 -0
- package/src/data/vocabulary.js +67 -0
- package/src/diagrams/diagram-model.js +511 -0
- package/src/diagrams/diagram.js +204 -0
- package/src/diagrams/index.d.ts +225 -0
- package/src/diagrams/index.js +48 -0
- package/src/diagrams/layout-dagre.js +164 -0
- package/src/diagrams/layout-plugins.js +131 -0
- package/src/diagrams/mermaid-export.js +232 -0
- package/src/diagrams/mermaid-view.js +229 -0
- package/src/diagrams/svg-diagram.js +215 -0
- package/src/editor/code-editor.js +206 -0
- package/src/editor/documents-model.js +170 -0
- package/src/editor/documents-persistence.js +85 -0
- package/src/editor/editor-engine.js +22 -0
- package/src/editor/editor-ui.js +203 -0
- package/src/editor/editor.css +106 -0
- package/src/editor/engines/codemirror.js +227 -0
- package/src/editor/engines/monaco.js +219 -0
- package/src/editor/index.d.ts +111 -0
- package/src/editor/index.js +14 -0
- package/src/editor/lino-highlight.js +106 -0
- package/src/editor/lino-structure.js +85 -0
- package/src/editor/validate-lino.js +43 -0
- package/src/embed/README.md +161 -0
- package/src/embed/controller.js +223 -0
- package/src/embed/element.js +141 -0
- package/src/embed/index.d.ts +75 -0
- package/src/embed/index.js +9 -0
- package/src/embed/providers/telegram.d.ts +3 -0
- package/src/embed/providers/telegram.js +38 -0
- package/src/embed/providers/vk.d.ts +3 -0
- package/src/embed/providers/vk.js +42 -0
- package/src/embed/providers/x.d.ts +3 -0
- package/src/embed/providers/x.js +31 -0
- package/src/embed/registry.js +35 -0
- package/src/embed/script.js +73 -0
- package/src/embed/view.js +122 -0
- package/src/icons/adapters/lucide.d.ts +15 -0
- package/src/icons/adapters/lucide.js +142 -0
- package/src/icons/adapters/material-symbols.d.ts +13 -0
- package/src/icons/adapters/material-symbols.js +113 -0
- package/src/icons/adapters/shared.d.ts +38 -0
- package/src/icons/adapters/shared.js +157 -0
- package/src/icons/adapters/simple-icons.d.ts +9 -0
- package/src/icons/adapters/simple-icons.js +38 -0
- package/src/icons/adapters/tabler.d.ts +9 -0
- package/src/icons/adapters/tabler.js +86 -0
- package/src/icons/icon-registry.js +215 -0
- package/src/icons/icon.js +356 -0
- package/src/icons/index.d.ts +123 -0
- package/src/icons/index.js +30 -0
- package/src/icons/names.js +51 -0
- package/src/icons/own-icons.js +521 -0
- package/src/icons/presentation.js +55 -0
- package/src/icons/svg.js +136 -0
- package/src/index.d.ts +14 -0
- package/src/index.js +40 -0
- package/src/layout/README.md +102 -0
- package/src/layout/app-shell.js +150 -0
- package/src/layout/catalog.lino +27 -0
- package/src/layout/dock-model.js +576 -0
- package/src/layout/dock-view.js +312 -0
- package/src/layout/dock.js +352 -0
- package/src/layout/dom.js +312 -0
- package/src/layout/grid.js +192 -0
- package/src/layout/index.d.ts +267 -0
- package/src/layout/index.js +60 -0
- package/src/layout/layer-manager.js +120 -0
- package/src/layout/layout.css +760 -0
- package/src/layout/menu.js +141 -0
- package/src/layout/nav-strip.js +174 -0
- package/src/layout/page-links.js +166 -0
- package/src/layout/panel.js +26 -0
- package/src/layout/pref-switches.js +209 -0
- package/src/layout/split-model.js +270 -0
- package/src/layout/split.js +430 -0
- package/src/layout/stack.js +86 -0
- package/src/layout/surfaces.js +119 -0
- package/src/layout/tab-group.js +151 -0
- package/src/layout/tab-strip.js +277 -0
- package/src/layout/vocabulary.js +229 -0
- package/src/layout/window-frame.js +222 -0
- package/src/layout/window.js +146 -0
- package/src/links-view/animator.js +144 -0
- package/src/links-view/configuration-classes.js +150 -0
- package/src/links-view/configuration-model.js +191 -0
- package/src/links-view/configuration-notations.js +230 -0
- package/src/links-view/configurations.d.ts +73 -0
- package/src/links-view/configurations.js +33 -0
- package/src/links-view/create-layout-runner.js +79 -0
- package/src/links-view/doublet-curves.js +239 -0
- package/src/links-view/doublet-layout.js +148 -0
- package/src/links-view/doublet-markers.js +109 -0
- package/src/links-view/doublet-options.js +369 -0
- package/src/links-view/doublet-svg.js +156 -0
- package/src/links-view/doublet.js +230 -0
- package/src/links-view/export.js +146 -0
- package/src/links-view/geometry.js +409 -0
- package/src/links-view/index.d.ts +1029 -0
- package/src/links-view/index.js +140 -0
- package/src/links-view/labels.js +28 -0
- package/src/links-view/layout-worker-entry.mjs +2 -0
- package/src/links-view/layout-worker.js +28 -0
- package/src/links-view/layouts/circle.js +7 -0
- package/src/links-view/layouts/force.js +76 -0
- package/src/links-view/layouts/grid.js +7 -0
- package/src/links-view/layouts/hex.js +8 -0
- package/src/links-view/layouts/index.js +15 -0
- package/src/links-view/layouts/layered.js +29 -0
- package/src/links-view/layouts/regular.js +27 -0
- package/src/links-view/layouts/spiral.js +10 -0
- package/src/links-view/link-view.js +494 -0
- package/src/links-view/links-gallery.js +306 -0
- package/src/links-view/links-network.js +496 -0
- package/src/links-view/lino-network-source.js +122 -0
- package/src/links-view/lino-network.js +233 -0
- package/src/links-view/lino-to-network.js +252 -0
- package/src/links-view/markers.js +192 -0
- package/src/links-view/model.js +233 -0
- package/src/links-view/network-editor/dom.js +36 -0
- package/src/links-view/network-editor/editor.js +202 -0
- package/src/links-view/network-editor/model.js +163 -0
- package/src/links-view/network-editor/options.js +265 -0
- package/src/links-view/network-editor/panels.js +423 -0
- package/src/links-view/network-editor/presets.js +76 -0
- package/src/links-view/network-editor/provider.js +93 -0
- package/src/links-view/network-editor/remap.js +45 -0
- package/src/links-view/network-editor/schema.js +224 -0
- package/src/links-view/network-editor/share.js +232 -0
- package/src/links-view/network-editor/styles.js +19 -0
- package/src/links-view/network-editor/url-sync.js +131 -0
- package/src/links-view/network-interaction.js +228 -0
- package/src/links-view/network-model.js +85 -0
- package/src/links-view/network-renderer.js +259 -0
- package/src/links-view/network-scene.js +245 -0
- package/src/links-view/network-source.js +82 -0
- package/src/links-view/network-vocabulary.js +18 -0
- package/src/links-view/presentation.js +199 -0
- package/src/links-view/render-canvas.js +102 -0
- package/src/links-view/render-svg.js +118 -0
- package/src/links-view/scene.js +233 -0
- package/src/links-view/solver-job.js +106 -0
- package/src/links-view/tokens.js +114 -0
- package/src/links-view/zoom-pan.js +203 -0
- package/src/overlays/catalog.lino +89 -0
- package/src/overlays/context-menu.js +110 -0
- package/src/overlays/dialog.js +117 -0
- package/src/overlays/dom.js +168 -0
- package/src/overlays/drawer.js +8 -0
- package/src/overlays/index.d.ts +80 -0
- package/src/overlays/index.js +25 -0
- package/src/overlays/kinds.lino +137 -0
- package/src/overlays/list-popover.js +129 -0
- package/src/overlays/machines/index.js +71 -0
- package/src/overlays/machines/surface.lino +11 -0
- package/src/overlays/machines/tabs.lino +7 -0
- package/src/overlays/machines/toast.lino +16 -0
- package/src/overlays/machines/tooltip.lino +29 -0
- package/src/overlays/menu.js +240 -0
- package/src/overlays/popover.js +194 -0
- package/src/overlays/position.js +84 -0
- package/src/overlays/radial-geometry.js +38 -0
- package/src/overlays/radial-menu.js +50 -0
- package/src/overlays/styles.css +155 -0
- package/src/overlays/tabs.js +125 -0
- package/src/overlays/toast-queue.js +105 -0
- package/src/overlays/toast.js +163 -0
- package/src/overlays/tooltip.js +110 -0
- package/src/overlays/vocabulary.js +3 -0
- package/src/settings/conditions.js +44 -0
- package/src/settings/control-for.js +62 -0
- package/src/settings/field-control.js +201 -0
- package/src/settings/index.d.ts +201 -0
- package/src/settings/index.js +3 -0
- package/src/settings/messages.js +112 -0
- package/src/settings/miniature.js +26 -0
- package/src/settings/panel-actions.js +234 -0
- package/src/settings/panel-model.js +49 -0
- package/src/settings/panel-refresh.js +56 -0
- package/src/settings/panel-rows.js +200 -0
- package/src/settings/preset-cards.js +43 -0
- package/src/settings/saved-looks.js +227 -0
- package/src/settings/section-layout.js +95 -0
- package/src/settings/section-tabs.js +175 -0
- package/src/settings/settings-panel.js +192 -0
- package/src/settings/settings.css +178 -0
- package/stories/accordion.lino +14 -0
- package/stories/alert-dialog.lino +4 -0
- package/stories/app-bar.lino +10 -0
- package/stories/avatar.lino +7 -0
- package/stories/badge.lino +12 -0
- package/stories/button.lino +17 -0
- package/stories/card.lino +10 -0
- package/stories/checkbox.lino +14 -0
- package/stories/chip.lino +19 -0
- package/stories/color-field.lino +9 -0
- package/stories/combobox.lino +10 -0
- package/stories/container.lino +11 -0
- package/stories/context-menu.lino +15 -0
- package/stories/dialog.lino +16 -0
- package/stories/drawer.lino +12 -0
- package/stories/icon-button.lino +13 -0
- package/stories/label.lino +7 -0
- package/stories/link-cards.lino +9 -0
- package/stories/link.lino +9 -0
- package/stories/menu-item.lino +6 -0
- package/stories/menu-separator.lino +7 -0
- package/stories/menu.lino +30 -0
- package/stories/nav-strip.lino +11 -0
- package/stories/number-field.lino +16 -0
- package/stories/option.lino +10 -0
- package/stories/paper.lino +11 -0
- package/stories/popover.lino +4 -0
- package/stories/pref-switches.lino +4 -0
- package/stories/progress.lino +14 -0
- package/stories/radial-menu.lino +19 -0
- package/stories/radio-group.lino +22 -0
- package/stories/radio.lino +10 -0
- package/stories/section-nav.lino +9 -0
- package/stories/select.lino +16 -0
- package/stories/slider.lino +14 -0
- package/stories/switch.lino +10 -0
- package/stories/tab-panel.lino +7 -0
- package/stories/tab.lino +7 -0
- package/stories/tabs.lino +25 -0
- package/stories/text-area.lino +12 -0
- package/stories/text-field.lino +23 -0
- package/stories/titled-section.lino +7 -0
- package/stories/toast.lino +3 -0
- package/stories/toaster.lino +2 -0
- package/stories/tooltip.lino +3 -0
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The model of a `link-view`: which link it draws and how, read from Links
|
|
3
|
+
* Notation with the ui-core parser (never with regular expressions).
|
|
4
|
+
*
|
|
5
|
+
* ```lino
|
|
6
|
+
* (simple: link-view
|
|
7
|
+
* (link (id 1) (source 1) (target 2))
|
|
8
|
+
* (markers (source bar) (target arrow))
|
|
9
|
+
* (blueprint true)
|
|
10
|
+
* (grid true))
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* A link whose source or target is missing or `0` has a free end; a link
|
|
14
|
+
* whose source and target are the same reference is a self-loop.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { parse } from '@link-foundation/ui-core';
|
|
18
|
+
import { DEFAULT_ENDS, getMarker } from './markers.js';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @typedef {import('@link-foundation/ui-core').RawValue} RawValue
|
|
22
|
+
* @typedef {object} LinkViewModel
|
|
23
|
+
* @property {string|null} name the id of the `link-view` element
|
|
24
|
+
* @property {string|null} id the link id
|
|
25
|
+
* @property {string|null} source the source reference; `null` = free end
|
|
26
|
+
* @property {string|null} target the target reference; `null` = free end
|
|
27
|
+
* @property {{source: string, target: string}} ends marker shapes
|
|
28
|
+
* @property {boolean} blueprint
|
|
29
|
+
* @property {boolean} grid
|
|
30
|
+
* @property {number} bend
|
|
31
|
+
* @property {string|null} label an explicit accessible name
|
|
32
|
+
* @property {boolean} selfLoop
|
|
33
|
+
* @typedef {{code: string, severity: 'error'|'warning', message: string}}
|
|
34
|
+
* ModelDiagnostic
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
/** The marker of a free end when none is given: a cross (nothing there). */
|
|
38
|
+
export const FREE_END_MARKER = 'cross';
|
|
39
|
+
|
|
40
|
+
/** The plain value of a raw value, or `undefined` for a nested link. */
|
|
41
|
+
const plain = (value) => (typeof value === 'string' ? value : undefined);
|
|
42
|
+
|
|
43
|
+
/** `[name, ...values]` of a raw link value; `null` for anything else. */
|
|
44
|
+
function entry(value) {
|
|
45
|
+
if (!Array.isArray(value) || typeof value[0] !== 'string') {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
return { name: value[0], values: value.slice(1) };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** The sub-links of a raw link, by name (the last one of a name wins). */
|
|
52
|
+
function entries(values) {
|
|
53
|
+
const byName = new Map();
|
|
54
|
+
for (const value of values) {
|
|
55
|
+
const e = entry(value);
|
|
56
|
+
if (e !== null) {
|
|
57
|
+
byName.set(e.name, e.values);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return byName;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** A reference: `0`, empty or missing is a free end (`null`). */
|
|
64
|
+
function reference(values) {
|
|
65
|
+
const value = plain(values?.[0]);
|
|
66
|
+
return value === undefined || value === '' || value === '0' ? null : value;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function readBoolean(values, name, report) {
|
|
70
|
+
const value = plain(values?.[0]);
|
|
71
|
+
if (value === undefined) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
if (value !== 'true' && value !== 'false') {
|
|
75
|
+
report(
|
|
76
|
+
'invalid-value',
|
|
77
|
+
'warning',
|
|
78
|
+
`(${name} ${value}) is not true or false`
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
return value === 'true';
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function readBend(values, report) {
|
|
85
|
+
const value = plain(values?.[0]);
|
|
86
|
+
if (value === undefined) {
|
|
87
|
+
return 0;
|
|
88
|
+
}
|
|
89
|
+
const bend = Number(value);
|
|
90
|
+
if (value.trim() === '' || !Number.isFinite(bend)) {
|
|
91
|
+
report('invalid-value', 'warning', `(bend ${value}) is not a number`);
|
|
92
|
+
return 0;
|
|
93
|
+
}
|
|
94
|
+
return bend;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function readEnds(values, free, report) {
|
|
98
|
+
const markers = entries(values ?? []);
|
|
99
|
+
const ends = {};
|
|
100
|
+
for (const end of ['source', 'target']) {
|
|
101
|
+
const fallback = free[end] ? FREE_END_MARKER : DEFAULT_ENDS[end];
|
|
102
|
+
const shape = plain(markers.get(end)?.[0]);
|
|
103
|
+
if (shape !== undefined && getMarker(shape) === undefined) {
|
|
104
|
+
report(
|
|
105
|
+
'unknown-marker',
|
|
106
|
+
'warning',
|
|
107
|
+
`the ${end} marker "${shape}" is not a marker shape`
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
ends[end] =
|
|
111
|
+
shape !== undefined && getMarker(shape) !== undefined ? shape : fallback;
|
|
112
|
+
}
|
|
113
|
+
return ends;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* The model of a `link-view` from its sub-links as raw values (the
|
|
118
|
+
* `unknown` list ui-core gives an element of an unknown kind, or ui-dom
|
|
119
|
+
* gives a kind).
|
|
120
|
+
* @param {readonly RawValue[]} raw
|
|
121
|
+
* @param {{name?: string|null}} [options]
|
|
122
|
+
* @returns {{model: LinkViewModel, diagnostics: ModelDiagnostic[]}}
|
|
123
|
+
*/
|
|
124
|
+
export function readLinkView(raw, { name = null } = {}) {
|
|
125
|
+
const diagnostics = [];
|
|
126
|
+
const report = (code, severity, message) =>
|
|
127
|
+
diagnostics.push({ code, severity, message });
|
|
128
|
+
const props = entries(raw);
|
|
129
|
+
const link = props.get('link');
|
|
130
|
+
if (link === undefined) {
|
|
131
|
+
report('missing-link', 'warning', 'the link-view has no (link ...)');
|
|
132
|
+
}
|
|
133
|
+
const linkProps = entries(link ?? []);
|
|
134
|
+
const id = reference(linkProps.get('id'));
|
|
135
|
+
const source = reference(linkProps.get('source'));
|
|
136
|
+
const target = reference(linkProps.get('target'));
|
|
137
|
+
const free = { source: source === null, target: target === null };
|
|
138
|
+
const label = plain(props.get('label')?.[0]) ?? null;
|
|
139
|
+
return {
|
|
140
|
+
model: Object.freeze({
|
|
141
|
+
name,
|
|
142
|
+
id,
|
|
143
|
+
source,
|
|
144
|
+
target,
|
|
145
|
+
ends: Object.freeze(readEnds(props.get('markers'), free, report)),
|
|
146
|
+
blueprint: readBoolean(props.get('blueprint'), 'blueprint', report),
|
|
147
|
+
grid: readBoolean(props.get('grid'), 'grid', report),
|
|
148
|
+
bend: readBend(props.get('bend'), report),
|
|
149
|
+
label,
|
|
150
|
+
selfLoop: source !== null && source === target,
|
|
151
|
+
}),
|
|
152
|
+
diagnostics,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* The sub-links of an element as raw values: its unknown sub-links plus
|
|
158
|
+
* its children turned back into raw links. ui-core projects a sub-link
|
|
159
|
+
* whose head is a kind of the vocabulary (`(link ...)`, `(label ...)`) as
|
|
160
|
+
* a child element even inside a kind it does not know.
|
|
161
|
+
* @param {{unknown?: readonly RawValue[]}} element
|
|
162
|
+
* @param {ReadonlyArray<{kind: string|null, positional?: readonly RawValue[],
|
|
163
|
+
* properties?: ReadonlyArray<{name: string, values: readonly RawValue[]}>,
|
|
164
|
+
* unknown?: readonly RawValue[]}>} [children]
|
|
165
|
+
* @returns {RawValue[]}
|
|
166
|
+
*/
|
|
167
|
+
export function rawSublinks(element, children = []) {
|
|
168
|
+
return [
|
|
169
|
+
...(element.unknown ?? []),
|
|
170
|
+
...children.map((child) => [
|
|
171
|
+
child.kind,
|
|
172
|
+
...(child.positional ?? []),
|
|
173
|
+
...(child.properties ?? []).map((p) => [p.name, ...p.values]),
|
|
174
|
+
...(child.unknown ?? []),
|
|
175
|
+
]),
|
|
176
|
+
];
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Read the first `link-view` element of a Links Notation text.
|
|
181
|
+
* @param {string} text
|
|
182
|
+
* @returns {{model: LinkViewModel, diagnostics: ModelDiagnostic[]}}
|
|
183
|
+
*/
|
|
184
|
+
export function parseLinkView(text) {
|
|
185
|
+
const document = parse(text, { checks: false });
|
|
186
|
+
const errors = document.diagnostics
|
|
187
|
+
.filter((d) => d.severity === 'error')
|
|
188
|
+
.map((d) => ({ code: d.code, severity: 'error', message: d.message }));
|
|
189
|
+
const root = document.roots.find((r) => r.kind === 'link-view');
|
|
190
|
+
// An unnamed `(link-view ...)` is kept by ui-core as a raw sub-link.
|
|
191
|
+
const unnamed = document.unknown.find(
|
|
192
|
+
(raw) => Array.isArray(raw) && raw[0] === 'link-view'
|
|
193
|
+
);
|
|
194
|
+
if (root === undefined && unnamed !== undefined) {
|
|
195
|
+
const read = readLinkView(unnamed.slice(1));
|
|
196
|
+
return { model: read.model, diagnostics: [...errors, ...read.diagnostics] };
|
|
197
|
+
}
|
|
198
|
+
if (root === undefined) {
|
|
199
|
+
const { model, diagnostics } = readLinkView([]);
|
|
200
|
+
return {
|
|
201
|
+
model,
|
|
202
|
+
diagnostics: [
|
|
203
|
+
...errors,
|
|
204
|
+
{
|
|
205
|
+
code: 'missing-link-view',
|
|
206
|
+
severity: 'error',
|
|
207
|
+
message: 'the text has no link-view element',
|
|
208
|
+
},
|
|
209
|
+
...diagnostics,
|
|
210
|
+
],
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
const read = readLinkView(rawSublinks(root, root.children), {
|
|
214
|
+
name: root.id ?? null,
|
|
215
|
+
});
|
|
216
|
+
return { model: read.model, diagnostics: [...errors, ...read.diagnostics] };
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/** How an end is announced. */
|
|
220
|
+
const endName = (ref) => (ref === null ? 'a free end' : ref);
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* The accessible name of a link view: `Link 1 from 1 to 2`.
|
|
224
|
+
* @param {LinkViewModel} model
|
|
225
|
+
*/
|
|
226
|
+
export function accessibleName(model) {
|
|
227
|
+
if (model.label !== null) {
|
|
228
|
+
return model.label;
|
|
229
|
+
}
|
|
230
|
+
const head = model.id === null ? 'Link' : `Link ${model.id}`;
|
|
231
|
+
const loop = model.selfLoop ? ', a self-loop' : '';
|
|
232
|
+
return `${head} from ${endName(model.source)} to ${endName(model.target)}${loop}`;
|
|
233
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export function element(doc, tag, text, parent) {
|
|
2
|
+
const node = doc.createElement(tag);
|
|
3
|
+
if (text !== undefined) {
|
|
4
|
+
node.textContent = text;
|
|
5
|
+
}
|
|
6
|
+
parent?.append(node);
|
|
7
|
+
return node;
|
|
8
|
+
}
|
|
9
|
+
export function button(doc, parent, label, action) {
|
|
10
|
+
const node = element(doc, 'button', label, parent);
|
|
11
|
+
node.type = 'button';
|
|
12
|
+
node.addEventListener('click', action);
|
|
13
|
+
return node;
|
|
14
|
+
}
|
|
15
|
+
export function field(doc, parent, label, type = 'text') {
|
|
16
|
+
const wrapper = element(doc, 'label', undefined, parent);
|
|
17
|
+
element(doc, 'span', label, wrapper);
|
|
18
|
+
const input = element(
|
|
19
|
+
doc,
|
|
20
|
+
type === 'select' ? 'select' : 'input',
|
|
21
|
+
undefined,
|
|
22
|
+
wrapper
|
|
23
|
+
);
|
|
24
|
+
// Keep feedback and numeric outputs out of the control's accessible name.
|
|
25
|
+
input.setAttribute('aria-label', label);
|
|
26
|
+
if (type !== 'select') {
|
|
27
|
+
input.type = type;
|
|
28
|
+
}
|
|
29
|
+
return input;
|
|
30
|
+
}
|
|
31
|
+
export function choices(doc, select, values) {
|
|
32
|
+
for (const [value, label] of values) {
|
|
33
|
+
const option = element(doc, 'option', label, select);
|
|
34
|
+
option.value = value;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import * as configurations from '../configurations.js';
|
|
2
|
+
import {
|
|
3
|
+
normalize,
|
|
4
|
+
toParams,
|
|
5
|
+
fromParams,
|
|
6
|
+
toOptions,
|
|
7
|
+
fromOptions,
|
|
8
|
+
} from './options.js';
|
|
9
|
+
import { notationPanel, linksPanel, stylePanel } from './panels.js';
|
|
10
|
+
import { createNetworkShare } from './share.js';
|
|
11
|
+
import { syncNetworkUrl } from './url-sync.js';
|
|
12
|
+
import { createEditorModel, presentationPairs } from './model.js';
|
|
13
|
+
import { CSS } from './styles.js';
|
|
14
|
+
import { element, button } from './dom.js';
|
|
15
|
+
|
|
16
|
+
function stateUrl(state, href, win) {
|
|
17
|
+
const url = new win.URL(href);
|
|
18
|
+
for (const key of [...Object.keys(normalize({})), 'gap', 'index']) {
|
|
19
|
+
url.searchParams.delete(key);
|
|
20
|
+
}
|
|
21
|
+
url.searchParams.set('code', state.code);
|
|
22
|
+
for (const [key, value] of toParams(state.options)) {
|
|
23
|
+
url.searchParams.set(key, value);
|
|
24
|
+
}
|
|
25
|
+
return url.href;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** DOM adapter panels for a prepared, host-owned network presentation. */
|
|
29
|
+
export function createNetworkEditor(root, settings = {}) {
|
|
30
|
+
const {
|
|
31
|
+
presentation,
|
|
32
|
+
configurations: config = configurations,
|
|
33
|
+
solve,
|
|
34
|
+
locale = 'en',
|
|
35
|
+
serializeOptions = toOptions,
|
|
36
|
+
readOptions = fromOptions,
|
|
37
|
+
syncUrl = true,
|
|
38
|
+
debug,
|
|
39
|
+
} = settings;
|
|
40
|
+
const doc = root.ownerDocument,
|
|
41
|
+
win = doc.defaultView;
|
|
42
|
+
const container = element(doc, 'div', undefined, root);
|
|
43
|
+
container.className = 'network-editor';
|
|
44
|
+
element(doc, 'style', CSS, container);
|
|
45
|
+
const { live, error } = statusNodes(doc, container);
|
|
46
|
+
let disposed = false,
|
|
47
|
+
pending = Promise.resolve();
|
|
48
|
+
const panels = {};
|
|
49
|
+
const announce = (message, failed = false) => {
|
|
50
|
+
(failed ? error : live).textContent = message;
|
|
51
|
+
if (!failed) {
|
|
52
|
+
error.textContent = '';
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
const run = (action) => {
|
|
56
|
+
try {
|
|
57
|
+
pending = Promise.resolve(action()).catch((failure) => {
|
|
58
|
+
if (!disposed && failure.name !== 'AbortError') {
|
|
59
|
+
announce(failure.message, true);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
} catch (failure) {
|
|
63
|
+
announce(failure.message, true);
|
|
64
|
+
pending = Promise.resolve();
|
|
65
|
+
}
|
|
66
|
+
return pending;
|
|
67
|
+
};
|
|
68
|
+
const model = createEditorModel(presentation, {
|
|
69
|
+
config,
|
|
70
|
+
serializeOptions,
|
|
71
|
+
readOptions,
|
|
72
|
+
onChange(external) {
|
|
73
|
+
panels.notations?.refresh(external);
|
|
74
|
+
panels.cards?.refresh();
|
|
75
|
+
panels.styles?.refresh();
|
|
76
|
+
panels.share?.refresh();
|
|
77
|
+
},
|
|
78
|
+
onBusy(busy) {
|
|
79
|
+
container.setAttribute('aria-busy', String(busy));
|
|
80
|
+
panels.share?.setBusy(busy);
|
|
81
|
+
if (panels.apply) {
|
|
82
|
+
panels.apply.disabled = busy || !solve;
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
const getState = model.snapshot;
|
|
87
|
+
const getCommittedState = () => {
|
|
88
|
+
const state = presentation.snapshot();
|
|
89
|
+
const links = presentationPairs(state);
|
|
90
|
+
return {
|
|
91
|
+
links,
|
|
92
|
+
code: config.encode(links),
|
|
93
|
+
options: normalize(readOptions(state.input.options)),
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
const getUrl = () => stateUrl(getCommittedState(), win.location.href, win);
|
|
97
|
+
const context = {
|
|
98
|
+
doc,
|
|
99
|
+
win,
|
|
100
|
+
config,
|
|
101
|
+
locale,
|
|
102
|
+
id:
|
|
103
|
+
root.id ||
|
|
104
|
+
`network-editor-${doc.querySelectorAll('.network-editor').length}`,
|
|
105
|
+
getState,
|
|
106
|
+
announce,
|
|
107
|
+
run,
|
|
108
|
+
draft: null,
|
|
109
|
+
applyLinks: model.applyLinks,
|
|
110
|
+
changeOptions: model.changeOptions,
|
|
111
|
+
applyStyle: model.applyStyle,
|
|
112
|
+
removeLink: model.removeLink,
|
|
113
|
+
canonicalize: model.canonicalize,
|
|
114
|
+
};
|
|
115
|
+
panels.notations = notationPanel(container, context);
|
|
116
|
+
panels.cards = linksPanel(container, context);
|
|
117
|
+
panels.styles = stylePanel(container, context);
|
|
118
|
+
panels.apply = solverControls(container, model, solve, announce, run);
|
|
119
|
+
panels.share = createNetworkShare(container, {
|
|
120
|
+
presentation,
|
|
121
|
+
getState: getCommittedState,
|
|
122
|
+
getUrl,
|
|
123
|
+
announce,
|
|
124
|
+
window: win,
|
|
125
|
+
});
|
|
126
|
+
panels.share.setBusy(false);
|
|
127
|
+
const urlSync = syncUrl
|
|
128
|
+
? syncNetworkUrl(presentation, {
|
|
129
|
+
window: win,
|
|
130
|
+
root: container,
|
|
131
|
+
debug,
|
|
132
|
+
urlFor: (state, href) =>
|
|
133
|
+
stateUrl(
|
|
134
|
+
{
|
|
135
|
+
code: config.encode(presentationPairs(state)),
|
|
136
|
+
options: readOptions(state.input.options),
|
|
137
|
+
},
|
|
138
|
+
href,
|
|
139
|
+
win
|
|
140
|
+
),
|
|
141
|
+
})
|
|
142
|
+
: null;
|
|
143
|
+
const restoreUrl = () =>
|
|
144
|
+
run(() => {
|
|
145
|
+
const url = new win.URL(win.location.href),
|
|
146
|
+
code = url.searchParams.get('code');
|
|
147
|
+
if (code) {
|
|
148
|
+
return model.restore(config.decode(code), fromParams(url.searchParams));
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
win.addEventListener('popstate', restoreUrl);
|
|
152
|
+
panels.notations.refresh(true);
|
|
153
|
+
panels.cards.refresh();
|
|
154
|
+
panels.styles.refresh();
|
|
155
|
+
return {
|
|
156
|
+
get ready() {
|
|
157
|
+
return pending;
|
|
158
|
+
},
|
|
159
|
+
snapshot: getState,
|
|
160
|
+
updateOptions: model.changeOptions,
|
|
161
|
+
updateLinks: model.applyLinks,
|
|
162
|
+
restoreUrl,
|
|
163
|
+
dispose() {
|
|
164
|
+
disposed = true;
|
|
165
|
+
model.dispose();
|
|
166
|
+
urlSync?.dispose();
|
|
167
|
+
panels.share.dispose();
|
|
168
|
+
panels.styles.dispose();
|
|
169
|
+
win.removeEventListener('popstate', restoreUrl);
|
|
170
|
+
container.remove();
|
|
171
|
+
},
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function statusNodes(doc, container) {
|
|
176
|
+
const live = element(doc, 'p', undefined, container);
|
|
177
|
+
live.setAttribute('role', 'status');
|
|
178
|
+
live.setAttribute('aria-live', 'polite');
|
|
179
|
+
const error = element(doc, 'p', undefined, container);
|
|
180
|
+
error.setAttribute('role', 'alert');
|
|
181
|
+
return { live, error };
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function solverControls(container, model, solve, announce, run) {
|
|
185
|
+
const doc = container.ownerDocument;
|
|
186
|
+
const solverPanel = element(doc, 'fieldset', undefined, container);
|
|
187
|
+
element(doc, 'legend', 'Solver', solverPanel);
|
|
188
|
+
const apply = button(doc, solverPanel, 'Apply', () =>
|
|
189
|
+
run(async () => {
|
|
190
|
+
announce('Solving…');
|
|
191
|
+
const result = await model.solve(solve);
|
|
192
|
+
if (result) {
|
|
193
|
+
announce(`Collisions ${result.before} → ${result.after}`);
|
|
194
|
+
}
|
|
195
|
+
})
|
|
196
|
+
);
|
|
197
|
+
apply.disabled = !solve;
|
|
198
|
+
if (!solve) {
|
|
199
|
+
element(doc, 'p', 'Solver unavailable.', solverPanel);
|
|
200
|
+
}
|
|
201
|
+
return apply;
|
|
202
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { normalize, editOptions } from './options.js';
|
|
2
|
+
import { replaceStyle } from './presets.js';
|
|
3
|
+
import { remapOptions, canonicalMap } from './remap.js';
|
|
4
|
+
|
|
5
|
+
export function presentationPairs(snapshot) {
|
|
6
|
+
const items = snapshot.input.items;
|
|
7
|
+
const result = items.map((item, i) => {
|
|
8
|
+
if (!Array.isArray(item) && String(item.id) !== String(i + 1)) {
|
|
9
|
+
throw new TypeError('Doublet item IDs must be sequential');
|
|
10
|
+
}
|
|
11
|
+
return Array.isArray(item)
|
|
12
|
+
? [...item]
|
|
13
|
+
: [Number(item.source), Number(item.target)];
|
|
14
|
+
});
|
|
15
|
+
if (
|
|
16
|
+
!result.length ||
|
|
17
|
+
!result.every(
|
|
18
|
+
(pair) =>
|
|
19
|
+
pair.length === 2 &&
|
|
20
|
+
pair.every((v) => Number.isInteger(v) && v >= 0 && v <= result.length)
|
|
21
|
+
)
|
|
22
|
+
) {
|
|
23
|
+
throw new TypeError(
|
|
24
|
+
'Prepare a presentation with sequential 1-based doublet items before mounting an editor'
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function createEditorModel(
|
|
31
|
+
presentation,
|
|
32
|
+
{ config, serializeOptions, readOptions, onChange, onBusy }
|
|
33
|
+
) {
|
|
34
|
+
let state = presentation.snapshot();
|
|
35
|
+
let links = presentationPairs(state),
|
|
36
|
+
options = normalize(readOptions(state.input.options));
|
|
37
|
+
let disposed = false,
|
|
38
|
+
revision = 0,
|
|
39
|
+
solver;
|
|
40
|
+
const snapshot = () => ({
|
|
41
|
+
links: globalThis.structuredClone(links),
|
|
42
|
+
options: normalize(options),
|
|
43
|
+
code: config.encode(links),
|
|
44
|
+
});
|
|
45
|
+
const cancel = () => {
|
|
46
|
+
solver?.abort();
|
|
47
|
+
solver = undefined;
|
|
48
|
+
onBusy(false);
|
|
49
|
+
};
|
|
50
|
+
async function commit(nextLinks, nextOptions) {
|
|
51
|
+
if (disposed) {
|
|
52
|
+
throw new Error('Network editor is disposed');
|
|
53
|
+
}
|
|
54
|
+
cancel();
|
|
55
|
+
const job = ++revision;
|
|
56
|
+
links = globalThis.structuredClone(nextLinks);
|
|
57
|
+
options = normalize(nextOptions);
|
|
58
|
+
onChange(false);
|
|
59
|
+
try {
|
|
60
|
+
return await presentation.update({
|
|
61
|
+
items: links.map(([source, target], i) => ({
|
|
62
|
+
id: String(i + 1),
|
|
63
|
+
source: String(source),
|
|
64
|
+
target: String(target),
|
|
65
|
+
})),
|
|
66
|
+
index: String(config.indexOf(links)),
|
|
67
|
+
options: serializeOptions(options),
|
|
68
|
+
});
|
|
69
|
+
} catch (failure) {
|
|
70
|
+
if (!disposed && job === revision) {
|
|
71
|
+
state = presentation.snapshot();
|
|
72
|
+
links = presentationPairs(state);
|
|
73
|
+
options = normalize(readOptions(state.input.options));
|
|
74
|
+
onChange(true);
|
|
75
|
+
}
|
|
76
|
+
throw failure;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
const applyLinks = (next, patch = {}) =>
|
|
80
|
+
commit(
|
|
81
|
+
next,
|
|
82
|
+
editOptions(
|
|
83
|
+
options,
|
|
84
|
+
{ ...patch, frame: null },
|
|
85
|
+
{ countChanged: next.length !== links.length }
|
|
86
|
+
)
|
|
87
|
+
);
|
|
88
|
+
const unsubscribe = presentation.subscribe((nextState) => {
|
|
89
|
+
const next = presentationPairs(nextState);
|
|
90
|
+
const externalNetwork = config.encode(next) !== config.encode(links);
|
|
91
|
+
const external =
|
|
92
|
+
externalNetwork || nextState.input.options !== serializeOptions(options);
|
|
93
|
+
if (external) {
|
|
94
|
+
++revision;
|
|
95
|
+
cancel();
|
|
96
|
+
}
|
|
97
|
+
state = nextState;
|
|
98
|
+
links = next;
|
|
99
|
+
options = normalize(readOptions(state.input.options));
|
|
100
|
+
onChange(externalNetwork);
|
|
101
|
+
});
|
|
102
|
+
return {
|
|
103
|
+
snapshot,
|
|
104
|
+
applyLinks,
|
|
105
|
+
changeOptions: (patch) => commit(links, editOptions(options, patch)),
|
|
106
|
+
applyStyle: (style) => commit(links, replaceStyle(options, style)),
|
|
107
|
+
restore: (next, nextOptions) => commit(next, nextOptions),
|
|
108
|
+
removeLink(k) {
|
|
109
|
+
const result = config.removeLink(links, k);
|
|
110
|
+
return applyLinks(
|
|
111
|
+
result.links,
|
|
112
|
+
remapOptions(options, result.indexMap, result.links.length)
|
|
113
|
+
);
|
|
114
|
+
},
|
|
115
|
+
canonicalize() {
|
|
116
|
+
if (links.length > 7) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
const code = config.canonical(links),
|
|
120
|
+
next = config.decode(code);
|
|
121
|
+
return applyLinks(
|
|
122
|
+
next,
|
|
123
|
+
remapOptions(options, canonicalMap(config, links, code), next.length)
|
|
124
|
+
);
|
|
125
|
+
},
|
|
126
|
+
async solve(callback) {
|
|
127
|
+
cancel();
|
|
128
|
+
solver = new globalThis.AbortController();
|
|
129
|
+
const active = solver,
|
|
130
|
+
job = revision;
|
|
131
|
+
onBusy(true);
|
|
132
|
+
try {
|
|
133
|
+
const result = await callback(
|
|
134
|
+
globalThis.structuredClone(links),
|
|
135
|
+
normalize(options),
|
|
136
|
+
{ signal: active.signal }
|
|
137
|
+
);
|
|
138
|
+
if (disposed || active.signal.aborted || job !== revision) {
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
solver = undefined;
|
|
142
|
+
await commit(links, {
|
|
143
|
+
...options,
|
|
144
|
+
turns: result.turns,
|
|
145
|
+
linkGaps: result.linkGaps,
|
|
146
|
+
frame: result.frame,
|
|
147
|
+
});
|
|
148
|
+
return result;
|
|
149
|
+
} finally {
|
|
150
|
+
if (!disposed && (solver === active || !solver)) {
|
|
151
|
+
solver = undefined;
|
|
152
|
+
onBusy(false);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
dispose() {
|
|
157
|
+
disposed = true;
|
|
158
|
+
++revision;
|
|
159
|
+
cancel();
|
|
160
|
+
unsubscribe();
|
|
161
|
+
},
|
|
162
|
+
};
|
|
163
|
+
}
|