@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,131 @@
|
|
|
1
|
+
/** Subscribe to committed state without adding browser history entries. */
|
|
2
|
+
export function syncNetworkUrl(
|
|
3
|
+
presentation,
|
|
4
|
+
{
|
|
5
|
+
window: win = globalThis.window,
|
|
6
|
+
root = win.document,
|
|
7
|
+
urlFor,
|
|
8
|
+
delay = 400,
|
|
9
|
+
setTimer = win.setTimeout.bind(win),
|
|
10
|
+
clearTimer = win.clearTimeout.bind(win),
|
|
11
|
+
debug,
|
|
12
|
+
} = {}
|
|
13
|
+
) {
|
|
14
|
+
if (typeof urlFor !== 'function') {
|
|
15
|
+
throw new TypeError('urlFor must serialize a presentation snapshot');
|
|
16
|
+
}
|
|
17
|
+
let timer;
|
|
18
|
+
let pending;
|
|
19
|
+
let failures = 0;
|
|
20
|
+
let disposed = false;
|
|
21
|
+
const held = new Set();
|
|
22
|
+
const listen = (target, name, fn) => {
|
|
23
|
+
target.addEventListener(name, fn, true);
|
|
24
|
+
return () => target.removeEventListener(name, fn, true);
|
|
25
|
+
};
|
|
26
|
+
const cancel = () => {
|
|
27
|
+
clearTimer(timer);
|
|
28
|
+
timer = undefined;
|
|
29
|
+
};
|
|
30
|
+
function schedule(ms = delay) {
|
|
31
|
+
cancel();
|
|
32
|
+
if (!disposed && pending && held.size === 0) {
|
|
33
|
+
timer = setTimer(write, ms);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function write() {
|
|
37
|
+
timer = undefined;
|
|
38
|
+
if (disposed || !pending || held.size) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
const url = urlFor(pending, win.location.href);
|
|
43
|
+
win.history.replaceState(win.history.state, '', String(url));
|
|
44
|
+
pending = undefined;
|
|
45
|
+
failures = 0;
|
|
46
|
+
debug?.('network-url:commit');
|
|
47
|
+
} catch (error) {
|
|
48
|
+
failures += 1;
|
|
49
|
+
debug?.('network-url:error', { name: error.name, failures });
|
|
50
|
+
if (failures < 5) {
|
|
51
|
+
schedule(1000 * 2 ** (failures - 1));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const interactive = (event) =>
|
|
56
|
+
(event.composedPath?.() ?? [event.target]).some((node) =>
|
|
57
|
+
node?.matches?.('input[type="range"], input[type="color"]')
|
|
58
|
+
);
|
|
59
|
+
const down = (id, event) => {
|
|
60
|
+
if (interactive(event)) {
|
|
61
|
+
held.add(id);
|
|
62
|
+
cancel();
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
const up = (id) => {
|
|
66
|
+
if (held.delete(id) && !held.size) {
|
|
67
|
+
schedule();
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
const sliderKeys = new Set([
|
|
71
|
+
'ArrowLeft',
|
|
72
|
+
'ArrowRight',
|
|
73
|
+
'ArrowUp',
|
|
74
|
+
'ArrowDown',
|
|
75
|
+
'Home',
|
|
76
|
+
'End',
|
|
77
|
+
'PageUp',
|
|
78
|
+
'PageDown',
|
|
79
|
+
]);
|
|
80
|
+
const cleanup = [
|
|
81
|
+
listen(root, 'pointerdown', (e) => down(`pointer:${e.pointerId}`, e)),
|
|
82
|
+
listen(win, 'pointerup', (e) => up(`pointer:${e.pointerId}`)),
|
|
83
|
+
listen(win, 'pointercancel', (e) => up(`pointer:${e.pointerId}`)),
|
|
84
|
+
listen(root, 'touchstart', (e) => {
|
|
85
|
+
for (const touch of e.changedTouches) {
|
|
86
|
+
down(`touch:${touch.identifier}`, e);
|
|
87
|
+
}
|
|
88
|
+
}),
|
|
89
|
+
...['touchend', 'touchcancel'].map((name) =>
|
|
90
|
+
listen(win, name, (e) => {
|
|
91
|
+
for (const touch of e.changedTouches) {
|
|
92
|
+
up(`touch:${touch.identifier}`);
|
|
93
|
+
}
|
|
94
|
+
})
|
|
95
|
+
),
|
|
96
|
+
listen(root, 'keydown', (e) => {
|
|
97
|
+
if (sliderKeys.has(e.key)) {
|
|
98
|
+
down(`key:${e.key}`, e);
|
|
99
|
+
}
|
|
100
|
+
}),
|
|
101
|
+
listen(win, 'keyup', (e) => up(`key:${e.key}`)),
|
|
102
|
+
listen(root, 'change', (e) => {
|
|
103
|
+
if (interactive(e) && e.target.type === 'color') {
|
|
104
|
+
held.clear();
|
|
105
|
+
schedule();
|
|
106
|
+
}
|
|
107
|
+
}),
|
|
108
|
+
listen(win, 'blur', () => {
|
|
109
|
+
held.clear();
|
|
110
|
+
schedule();
|
|
111
|
+
}),
|
|
112
|
+
presentation.subscribe((state) => {
|
|
113
|
+
pending = state;
|
|
114
|
+
failures = 0;
|
|
115
|
+
schedule();
|
|
116
|
+
}),
|
|
117
|
+
];
|
|
118
|
+
return {
|
|
119
|
+
flush: () => {
|
|
120
|
+
cancel();
|
|
121
|
+
write();
|
|
122
|
+
},
|
|
123
|
+
dispose() {
|
|
124
|
+
disposed = true;
|
|
125
|
+
cancel();
|
|
126
|
+
cleanup.forEach((fn) => fn());
|
|
127
|
+
held.clear();
|
|
128
|
+
pending = undefined;
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { networkNeighbours } from './network-model.js';
|
|
2
|
+
|
|
3
|
+
/** Resolve the closest centre/point for both SVG and Canvas, in world space. */
|
|
4
|
+
export function hitNetwork(node, state, event) {
|
|
5
|
+
const rect = node.getBoundingClientRect();
|
|
6
|
+
const view = node.view;
|
|
7
|
+
const at = {
|
|
8
|
+
x: (event.clientX - rect.left - view.x) / view.k,
|
|
9
|
+
y: (event.clientY - rect.top - view.y) / view.k,
|
|
10
|
+
};
|
|
11
|
+
let found = null,
|
|
12
|
+
distance = 16 / view.k;
|
|
13
|
+
for (const [id, point] of state.positions) {
|
|
14
|
+
const d = Math.hypot(at.x - point.x, at.y - point.y);
|
|
15
|
+
if (d < distance) {
|
|
16
|
+
distance = d;
|
|
17
|
+
found = id;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return { id: found, at };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function selectNetwork(node, state, id, additive = false) {
|
|
24
|
+
if (!additive) {
|
|
25
|
+
state.selected.clear();
|
|
26
|
+
}
|
|
27
|
+
if (id !== null) {
|
|
28
|
+
if (additive && state.selected.has(id)) {
|
|
29
|
+
state.selected.delete(id);
|
|
30
|
+
} else {
|
|
31
|
+
state.selected.add(id);
|
|
32
|
+
}
|
|
33
|
+
state.focused = id;
|
|
34
|
+
}
|
|
35
|
+
const text =
|
|
36
|
+
id === null
|
|
37
|
+
? 'No selection'
|
|
38
|
+
: state.network.links.has(id)
|
|
39
|
+
? `Link ${id} from ${state.network.links.get(id).source} to ${state.network.links.get(id).target}`
|
|
40
|
+
: `Point ${id}`;
|
|
41
|
+
state.status.textContent = text;
|
|
42
|
+
node.setAttribute('aria-label', `Links network. ${text}`);
|
|
43
|
+
node.dispatchEvent(
|
|
44
|
+
new state.win.CustomEvent('selectionchange', {
|
|
45
|
+
detail: { ids: [...state.selected] },
|
|
46
|
+
bubbles: true,
|
|
47
|
+
composed: true,
|
|
48
|
+
})
|
|
49
|
+
);
|
|
50
|
+
node.dispatchEvent(
|
|
51
|
+
new state.win.CustomEvent('ui-select', {
|
|
52
|
+
detail: {
|
|
53
|
+
item: state.network.links.get(id) ?? state.network.points.get(id),
|
|
54
|
+
ids: [...state.selected],
|
|
55
|
+
},
|
|
56
|
+
bubbles: true,
|
|
57
|
+
composed: true,
|
|
58
|
+
})
|
|
59
|
+
);
|
|
60
|
+
node.requestDraw();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function networkAction(node, state, type, originalEvent) {
|
|
64
|
+
if (type === 'activate') {
|
|
65
|
+
networkAction(node, state, 'ui-activate', originalEvent);
|
|
66
|
+
}
|
|
67
|
+
node.dispatchEvent(
|
|
68
|
+
new state.win.CustomEvent(type, {
|
|
69
|
+
detail: {
|
|
70
|
+
id: state.focused,
|
|
71
|
+
item:
|
|
72
|
+
state.network.links.get(state.focused) ??
|
|
73
|
+
state.network.points.get(state.focused),
|
|
74
|
+
originalEvent,
|
|
75
|
+
},
|
|
76
|
+
bubbles: true,
|
|
77
|
+
composed: true,
|
|
78
|
+
})
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function directionalNeighbour(node, state, event) {
|
|
83
|
+
const direction = {
|
|
84
|
+
ArrowLeft: [-1, 0],
|
|
85
|
+
ArrowRight: [1, 0],
|
|
86
|
+
ArrowUp: [0, -1],
|
|
87
|
+
ArrowDown: [0, 1],
|
|
88
|
+
}[event.key];
|
|
89
|
+
if (!direction) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
event.preventDefault();
|
|
93
|
+
if (event.altKey) {
|
|
94
|
+
state.zoom.panBy(-direction[0] * 30, -direction[1] * 30);
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
if (state.focused === null) {
|
|
98
|
+
selectNetwork(node, state, state.positions.keys().next().value ?? null);
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
const origin = state.positions.get(state.focused);
|
|
102
|
+
if (!origin) {
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
let best = null,
|
|
106
|
+
distance = Infinity;
|
|
107
|
+
for (const id of networkNeighbours(state.network, state.focused)) {
|
|
108
|
+
const p = state.positions.get(id);
|
|
109
|
+
if (!p) {
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
const dx = p.x - origin.x,
|
|
113
|
+
dy = p.y - origin.y;
|
|
114
|
+
const d = Math.hypot(dx, dy);
|
|
115
|
+
if (dx * direction[0] + dy * direction[1] > 0 && d < distance) {
|
|
116
|
+
best = id;
|
|
117
|
+
distance = d;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (best !== null) {
|
|
121
|
+
selectNetwork(node, state, best, event.shiftKey);
|
|
122
|
+
}
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function keyNetwork(node, state, event) {
|
|
127
|
+
if (event.ctrlKey || event.metaKey) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
if (directionalNeighbour(node, state, event)) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
const actions = {
|
|
134
|
+
Enter: () => networkAction(node, state, 'activate', event),
|
|
135
|
+
Escape: () => selectNetwork(node, state, null),
|
|
136
|
+
'+': () => state.zoom.zoomBy(1.25),
|
|
137
|
+
'=': () => state.zoom.zoomBy(1.25),
|
|
138
|
+
'-': () => state.zoom.zoomBy(0.8),
|
|
139
|
+
0: () => state.zoom.reset(),
|
|
140
|
+
Home: () =>
|
|
141
|
+
selectNetwork(node, state, state.positions.keys().next().value ?? null),
|
|
142
|
+
F10: () => {
|
|
143
|
+
if (event.shiftKey) {
|
|
144
|
+
networkAction(node, state, 'networkcontextmenu', event);
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
if (Object.hasOwn(actions, event.key)) {
|
|
149
|
+
event.preventDefault();
|
|
150
|
+
actions[event.key]();
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export function connectNetworkInteraction(node, state, listen) {
|
|
155
|
+
listen(node, 'keydown', (event) => keyNetwork(node, state, event));
|
|
156
|
+
listen(node, 'pointerdown', (event) => {
|
|
157
|
+
if (event.button !== 0) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
const hit = hitNetwork(node, state, event);
|
|
161
|
+
if (hit.id === null) {
|
|
162
|
+
state.panning = true;
|
|
163
|
+
state.hovered = null;
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
// These listeners are installed before zoom-pan. Stop the point drag
|
|
167
|
+
// reaching its pan handler while keeping background pan and pinch local.
|
|
168
|
+
event.stopImmediatePropagation();
|
|
169
|
+
node.focus();
|
|
170
|
+
node.setPointerCapture?.(event.pointerId);
|
|
171
|
+
state.drag = { id: hit.id, start: hit.at, moved: false };
|
|
172
|
+
});
|
|
173
|
+
listen(node, 'pointermove', (event) => {
|
|
174
|
+
if (state.panning) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
const hit = hitNetwork(node, state, event);
|
|
178
|
+
if (state.drag) {
|
|
179
|
+
event.stopImmediatePropagation();
|
|
180
|
+
const { id, start } = state.drag;
|
|
181
|
+
if (
|
|
182
|
+
Math.hypot(hit.at.x - start.x, hit.at.y - start.y) < 2 &&
|
|
183
|
+
!state.drag.moved
|
|
184
|
+
) {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
state.drag.moved = true;
|
|
188
|
+
state.positions.set(id, hit.at);
|
|
189
|
+
state.pins.set(id, hit.at);
|
|
190
|
+
state.runner?.cancel('layout');
|
|
191
|
+
state.shapesDirty = true;
|
|
192
|
+
node.requestDraw();
|
|
193
|
+
} else if (state.hovered !== hit.id) {
|
|
194
|
+
state.hovered = hit.id;
|
|
195
|
+
node.requestDraw();
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
const end = (event) => {
|
|
199
|
+
state.panning = false;
|
|
200
|
+
if (!state.drag) {
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
event.stopImmediatePropagation();
|
|
204
|
+
const { id, moved } = state.drag;
|
|
205
|
+
state.drag = null;
|
|
206
|
+
if (node.hasPointerCapture?.(event.pointerId)) {
|
|
207
|
+
node.releasePointerCapture(event.pointerId);
|
|
208
|
+
}
|
|
209
|
+
if (!moved && event.type === 'pointerup') {
|
|
210
|
+
selectNetwork(node, state, id, event.shiftKey);
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
for (const type of ['pointerup', 'pointercancel', 'lostpointercapture']) {
|
|
214
|
+
listen(node, type, end);
|
|
215
|
+
}
|
|
216
|
+
listen(node, 'pointerleave', () => {
|
|
217
|
+
state.hovered = null;
|
|
218
|
+
node.requestDraw();
|
|
219
|
+
});
|
|
220
|
+
listen(node, 'contextmenu', (event) => {
|
|
221
|
+
const { id } = hitNetwork(node, state, event);
|
|
222
|
+
if (id !== null) {
|
|
223
|
+
state.focused = id;
|
|
224
|
+
}
|
|
225
|
+
event.preventDefault();
|
|
226
|
+
networkAction(node, state, 'networkcontextmenu', event);
|
|
227
|
+
});
|
|
228
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/** A network keeps link IDs distinct from implicit endpoint point IDs. */
|
|
2
|
+
export function buildNetwork(input) {
|
|
3
|
+
const links = new Map();
|
|
4
|
+
const points = new Map();
|
|
5
|
+
const seen = new Set();
|
|
6
|
+
for (const value of input) {
|
|
7
|
+
if (value.id === 0 || value.id === '0' || seen.has(value.id)) {
|
|
8
|
+
throw new TypeError(`Duplicate or reserved link ID: ${value.id}`);
|
|
9
|
+
}
|
|
10
|
+
seen.add(value.id);
|
|
11
|
+
if (value.kind === 'point' || value.kind === 'value') {
|
|
12
|
+
points.set(value.id, { ...value });
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
links.set(value.id, {
|
|
16
|
+
...value,
|
|
17
|
+
source: free(value.source),
|
|
18
|
+
target: free(value.target),
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
for (const link of links.values()) {
|
|
22
|
+
for (const id of [link.source, link.target]) {
|
|
23
|
+
if (id !== 0 && !links.has(id) && !points.has(id)) {
|
|
24
|
+
points.set(id, { id });
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return { points, links };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const free = (id) => (id === null || id === undefined || id === '0' ? 0 : id);
|
|
32
|
+
|
|
33
|
+
/** All layout vertices, including the centre anchor of every link. */
|
|
34
|
+
export function networkIds(network) {
|
|
35
|
+
const ids = new Set();
|
|
36
|
+
for (const link of network.links.values()) {
|
|
37
|
+
if (network.points.has(link.source)) {
|
|
38
|
+
ids.add(link.source);
|
|
39
|
+
}
|
|
40
|
+
ids.add(link.id);
|
|
41
|
+
if (network.points.has(link.target)) {
|
|
42
|
+
ids.add(link.target);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
for (const id of network.points.keys()) {
|
|
46
|
+
ids.add(id);
|
|
47
|
+
}
|
|
48
|
+
return [...ids];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Incidence edges: links are also vertices, allowing cycles and self-reference. */
|
|
52
|
+
export function networkEdges(network) {
|
|
53
|
+
const edges = [];
|
|
54
|
+
for (const link of network.links.values()) {
|
|
55
|
+
for (const end of ['source', 'target']) {
|
|
56
|
+
if (link[end] !== 0) {
|
|
57
|
+
edges.push({ source: link.id, target: link[end] });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return edges;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Immediate neighbours in the incidence graph, stable in input order. */
|
|
65
|
+
export function networkNeighbours(network, id) {
|
|
66
|
+
const neighbours = new Set();
|
|
67
|
+
for (const edge of networkEdges(network)) {
|
|
68
|
+
if (edge.source === id) {
|
|
69
|
+
neighbours.add(edge.target);
|
|
70
|
+
}
|
|
71
|
+
if (edge.target === id) {
|
|
72
|
+
neighbours.add(edge.source);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
neighbours.delete(id);
|
|
76
|
+
return [...neighbours];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Include explicit value/isolated points when sending a network to a worker. */
|
|
80
|
+
export function networkInput(network) {
|
|
81
|
+
return [
|
|
82
|
+
...network.links.values(),
|
|
83
|
+
...[...network.points.values()].filter((point) => point.kind),
|
|
84
|
+
];
|
|
85
|
+
}
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import { networkToSvg } from './export.js';
|
|
2
|
+
import {
|
|
3
|
+
drawNetworkCanvas,
|
|
4
|
+
networkShapes,
|
|
5
|
+
networkItemSvg,
|
|
6
|
+
networkPointSvg,
|
|
7
|
+
networkLabels,
|
|
8
|
+
networkDefs,
|
|
9
|
+
networkLabelSvg,
|
|
10
|
+
highlightIds,
|
|
11
|
+
} from './network-scene.js';
|
|
12
|
+
import { linkColors, colorVariables } from './tokens.js';
|
|
13
|
+
|
|
14
|
+
export function networkStyle(node, state) {
|
|
15
|
+
const dark =
|
|
16
|
+
node.getAttribute('theme') === 'dark' ||
|
|
17
|
+
(!node.hasAttribute('theme') &&
|
|
18
|
+
state.win.matchMedia?.('(prefers-color-scheme: dark)').matches);
|
|
19
|
+
const mode = dark ? 'dark' : 'light';
|
|
20
|
+
if (!state.colors.has(mode)) {
|
|
21
|
+
state.colors.set(mode, linkColors({ mode }));
|
|
22
|
+
}
|
|
23
|
+
const colors = { ...state.colors.get(mode) };
|
|
24
|
+
const computed = state.win.getComputedStyle(node);
|
|
25
|
+
for (const [role, variable] of Object.entries(colorVariables())) {
|
|
26
|
+
const value = computed.getPropertyValue(variable).trim();
|
|
27
|
+
if (value) {
|
|
28
|
+
colors[role] = value;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
width: node.clientWidth || 640,
|
|
33
|
+
height: node.clientHeight || 400,
|
|
34
|
+
colors,
|
|
35
|
+
view: node.view,
|
|
36
|
+
labels: { minZoom: state.config.minZoom },
|
|
37
|
+
selected: [...state.selected],
|
|
38
|
+
hovered: state.hovered,
|
|
39
|
+
style: node.getAttribute('style-mode') ?? state.config.style,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const sameMarkup = (node, markup) => node?.outerHTML === markup;
|
|
44
|
+
|
|
45
|
+
/** Patch only changed items. Stable IDs preserve every unaffected DOM node. */
|
|
46
|
+
function patchItems(group, records, markup) {
|
|
47
|
+
const existing = new Map(
|
|
48
|
+
[...group.children].map((el) => [
|
|
49
|
+
el.getAttribute('data-id') ?? el.getAttribute('data-point'),
|
|
50
|
+
el,
|
|
51
|
+
])
|
|
52
|
+
);
|
|
53
|
+
for (const [id, record] of records) {
|
|
54
|
+
const key = String(id);
|
|
55
|
+
const old = existing.get(key);
|
|
56
|
+
const html = markup(id, record);
|
|
57
|
+
existing.delete(key);
|
|
58
|
+
if (sameMarkup(old, html)) {
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
const template = group.ownerDocument.createElementNS(
|
|
62
|
+
'http://www.w3.org/2000/svg',
|
|
63
|
+
'svg'
|
|
64
|
+
);
|
|
65
|
+
template.innerHTML = html;
|
|
66
|
+
const next = template.firstElementChild;
|
|
67
|
+
if (old) {
|
|
68
|
+
old.replaceWith(next);
|
|
69
|
+
} else {
|
|
70
|
+
group.append(next);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
for (const old of existing.values()) {
|
|
74
|
+
old.remove();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function drawSvg(node, state, style) {
|
|
79
|
+
const { surface, network, positions, shapes } = state;
|
|
80
|
+
const svg = surface.querySelector('svg');
|
|
81
|
+
if (!svg || state.resetSurface) {
|
|
82
|
+
surface.innerHTML = networkToSvg(network, positions, { ...style, shapes });
|
|
83
|
+
state.resetSurface = false;
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const set = (element, key, value) => {
|
|
87
|
+
if (element.getAttribute(key) !== String(value)) {
|
|
88
|
+
element.setAttribute(key, value);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
set(svg, 'width', style.width);
|
|
92
|
+
set(svg, 'height', style.height);
|
|
93
|
+
set(svg, 'viewBox', `0 0 ${style.width} ${style.height}`);
|
|
94
|
+
const background = svg.querySelector('rect');
|
|
95
|
+
set(background, 'width', style.width);
|
|
96
|
+
set(background, 'height', style.height);
|
|
97
|
+
set(background, 'fill', style.colors.background);
|
|
98
|
+
const defs = svg.querySelector('defs');
|
|
99
|
+
const markers = networkDefs(style.colors);
|
|
100
|
+
if (defs.innerHTML !== markers) {
|
|
101
|
+
defs.innerHTML = markers;
|
|
102
|
+
}
|
|
103
|
+
const v = style.view;
|
|
104
|
+
set(
|
|
105
|
+
svg.querySelector('[data-part="view"]'),
|
|
106
|
+
'transform',
|
|
107
|
+
`translate(${v.x} ${v.y}) scale(${v.k})`
|
|
108
|
+
);
|
|
109
|
+
const highlighted = highlightIds(network, state.hovered);
|
|
110
|
+
patchItems(svg.querySelector('[data-part="items"]'), shapes, (id, shape) =>
|
|
111
|
+
networkItemSvg(
|
|
112
|
+
shape,
|
|
113
|
+
positions,
|
|
114
|
+
style.colors,
|
|
115
|
+
state.selected.has(id),
|
|
116
|
+
highlighted.has(id)
|
|
117
|
+
)
|
|
118
|
+
);
|
|
119
|
+
patchItems(svg.querySelector('[data-part="points"]'), network.points, (id) =>
|
|
120
|
+
networkPointSvg(
|
|
121
|
+
id,
|
|
122
|
+
positions.get(id),
|
|
123
|
+
style.colors,
|
|
124
|
+
state.selected.has(id),
|
|
125
|
+
highlighted.has(id)
|
|
126
|
+
)
|
|
127
|
+
);
|
|
128
|
+
const labels = svg.querySelector('[data-part="labels"]');
|
|
129
|
+
const content = networkLabels(
|
|
130
|
+
network,
|
|
131
|
+
positions,
|
|
132
|
+
v.k,
|
|
133
|
+
style.labels,
|
|
134
|
+
style.selected
|
|
135
|
+
)
|
|
136
|
+
.map((label) => networkLabelSvg(label, style.colors))
|
|
137
|
+
.join('');
|
|
138
|
+
if (labels.innerHTML !== content) {
|
|
139
|
+
labels.innerHTML = content;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** Rasterize a static world tile so pan only moves a cached bitmap.
|
|
144
|
+
* Zoom, geometry, labels, selection and colours invalidate it. Tile dimensions
|
|
145
|
+
* stay within 4096 pixels per side to bound memory on large viewports.
|
|
146
|
+
*/
|
|
147
|
+
function canvasTile(node, state, style) {
|
|
148
|
+
const key = JSON.stringify([
|
|
149
|
+
style.colors,
|
|
150
|
+
style.view.k,
|
|
151
|
+
style.selected,
|
|
152
|
+
style.hovered,
|
|
153
|
+
style.labels,
|
|
154
|
+
]);
|
|
155
|
+
if (state.tile?.shapes === state.shapes && state.tile.key === key) {
|
|
156
|
+
return state.tile;
|
|
157
|
+
}
|
|
158
|
+
let minX = 0,
|
|
159
|
+
minY = 0,
|
|
160
|
+
maxX = style.width,
|
|
161
|
+
maxY = style.height;
|
|
162
|
+
for (const shape of state.shapes.values()) {
|
|
163
|
+
for (const point of shape.geometry.points) {
|
|
164
|
+
minX = Math.min(minX, point.x - 64);
|
|
165
|
+
minY = Math.min(minY, point.y - 64);
|
|
166
|
+
maxX = Math.max(maxX, point.x + 128);
|
|
167
|
+
maxY = Math.max(maxY, point.y + 64);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
const width = maxX - minX,
|
|
171
|
+
height = maxY - minY;
|
|
172
|
+
const resolution = Math.min(
|
|
173
|
+
(state.win.devicePixelRatio || 1) * style.view.k,
|
|
174
|
+
4096 / width,
|
|
175
|
+
4096 / height
|
|
176
|
+
);
|
|
177
|
+
const canvas = state.win.document.createElement('canvas');
|
|
178
|
+
canvas.width = Math.ceil(width * resolution);
|
|
179
|
+
canvas.height = Math.ceil(height * resolution);
|
|
180
|
+
drawNetworkCanvas(
|
|
181
|
+
canvas.getContext('2d'),
|
|
182
|
+
state.shapes,
|
|
183
|
+
state.network,
|
|
184
|
+
state.positions,
|
|
185
|
+
{
|
|
186
|
+
...style,
|
|
187
|
+
width,
|
|
188
|
+
height,
|
|
189
|
+
view: { x: -minX, y: -minY, k: 1 },
|
|
190
|
+
pixelRatio: resolution,
|
|
191
|
+
labels: {
|
|
192
|
+
minZoom: style.labels.minZoom / style.view.k,
|
|
193
|
+
padding: 2 / style.view.k,
|
|
194
|
+
},
|
|
195
|
+
Path2D: state.win.Path2D,
|
|
196
|
+
}
|
|
197
|
+
);
|
|
198
|
+
state.tile = { key, shapes: state.shapes, canvas, minX, minY, width, height };
|
|
199
|
+
return state.tile;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export function drawNetwork(node, state) {
|
|
203
|
+
const style = networkStyle(node, state);
|
|
204
|
+
if (state.presentation) {
|
|
205
|
+
if (!state.presentation.snapshot().frame) {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
const svg = state.presentation.toSvg();
|
|
209
|
+
if (state.surface.innerHTML !== svg) {
|
|
210
|
+
state.surface.innerHTML = svg;
|
|
211
|
+
}
|
|
212
|
+
state.drawn = {
|
|
213
|
+
renderer: 'svg',
|
|
214
|
+
links: state.network.links.size,
|
|
215
|
+
view: style.view,
|
|
216
|
+
};
|
|
217
|
+
node.dispatchEvent(
|
|
218
|
+
new state.win.CustomEvent('networkdraw', { detail: state.drawn })
|
|
219
|
+
);
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
if (state.shapesDirty) {
|
|
223
|
+
state.shapes = networkShapes(
|
|
224
|
+
state.network,
|
|
225
|
+
state.positions,
|
|
226
|
+
style.style,
|
|
227
|
+
state.shapes
|
|
228
|
+
);
|
|
229
|
+
state.shapesDirty = false;
|
|
230
|
+
}
|
|
231
|
+
const renderer = state.network.links.size > 2000 ? 'canvas' : 'svg';
|
|
232
|
+
if (renderer === 'svg') {
|
|
233
|
+
drawSvg(node, state, style);
|
|
234
|
+
} else {
|
|
235
|
+
let canvas = state.surface.querySelector('canvas');
|
|
236
|
+
if (!canvas) {
|
|
237
|
+
canvas = state.win.document.createElement('canvas');
|
|
238
|
+
state.surface.replaceChildren(canvas);
|
|
239
|
+
}
|
|
240
|
+
const ratio = state.win.devicePixelRatio || 1;
|
|
241
|
+
if (canvas.width !== style.width * ratio) {
|
|
242
|
+
canvas.width = style.width * ratio;
|
|
243
|
+
}
|
|
244
|
+
if (canvas.height !== style.height * ratio) {
|
|
245
|
+
canvas.height = style.height * ratio;
|
|
246
|
+
}
|
|
247
|
+
const tile = canvasTile(node, state, style);
|
|
248
|
+
const ctx = canvas.getContext('2d');
|
|
249
|
+
ctx.setTransform(ratio, 0, 0, ratio, 0, 0);
|
|
250
|
+
ctx.fillStyle = style.colors.background;
|
|
251
|
+
ctx.fillRect(0, 0, style.width, style.height);
|
|
252
|
+
ctx.transform(style.view.k, 0, 0, style.view.k, style.view.x, style.view.y);
|
|
253
|
+
ctx.drawImage(tile.canvas, tile.minX, tile.minY, tile.width, tile.height);
|
|
254
|
+
}
|
|
255
|
+
state.drawn = { renderer, links: state.network.links.size, view: style.view };
|
|
256
|
+
node.dispatchEvent(
|
|
257
|
+
new state.win.CustomEvent('networkdraw', { detail: state.drawn })
|
|
258
|
+
);
|
|
259
|
+
}
|