@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,496 @@
|
|
|
1
|
+
/* global URL */
|
|
2
|
+
import { defineKind } from '@link-foundation/ui-dom';
|
|
3
|
+
import { createAnimator } from './animator.js';
|
|
4
|
+
import { createZoomPan } from './zoom-pan.js';
|
|
5
|
+
import { buildNetwork, networkIds, networkInput } from './network-model.js';
|
|
6
|
+
import { circle } from './layouts/circle.js';
|
|
7
|
+
import { NETWORK_LAYOUTS } from './layouts/index.js';
|
|
8
|
+
import { createLayoutRunner } from './create-layout-runner.js';
|
|
9
|
+
import { drawNetwork, networkStyle } from './network-renderer.js';
|
|
10
|
+
import {
|
|
11
|
+
connectNetworkInteraction,
|
|
12
|
+
selectNetwork,
|
|
13
|
+
} from './network-interaction.js';
|
|
14
|
+
import {
|
|
15
|
+
storeNetworkLink,
|
|
16
|
+
storeNetworkLinks,
|
|
17
|
+
readNetworkSource,
|
|
18
|
+
readNetworkRaw,
|
|
19
|
+
networkRaw,
|
|
20
|
+
} from './network-source.js';
|
|
21
|
+
import { networkToSvg, networkToPng } from './export.js';
|
|
22
|
+
|
|
23
|
+
export const LINKS_NETWORK_TAG = 'links-network';
|
|
24
|
+
|
|
25
|
+
const CSS = `:host { display:block; position:relative; width:640px; height:400px; overflow:hidden; touch-action:none; contain:content; }
|
|
26
|
+
:host(:focus-visible) { outline:2px solid var(--color-link-focus, currentColor); outline-offset:2px; }
|
|
27
|
+
.surface, svg, canvas { width:100%; height:100%; display:block; }
|
|
28
|
+
.status { position:absolute; width:1px; height:1px; overflow:hidden; clip-path:inset(50%); }
|
|
29
|
+
:host([hidden]) { display:none; }`;
|
|
30
|
+
|
|
31
|
+
function makeState(node, win, options) {
|
|
32
|
+
const root = node.attachShadow({ mode: 'open' });
|
|
33
|
+
const style = win.document.createElement('style');
|
|
34
|
+
style.textContent = CSS;
|
|
35
|
+
const surface = win.document.createElement('div');
|
|
36
|
+
surface.className = 'surface';
|
|
37
|
+
const status = win.document.createElement('div');
|
|
38
|
+
status.className = 'status';
|
|
39
|
+
status.setAttribute('role', 'status');
|
|
40
|
+
root.append(style, surface, status);
|
|
41
|
+
return {
|
|
42
|
+
win,
|
|
43
|
+
options,
|
|
44
|
+
surface,
|
|
45
|
+
status,
|
|
46
|
+
network: buildNetwork([]),
|
|
47
|
+
positions: new Map(),
|
|
48
|
+
pins: new Map(),
|
|
49
|
+
selected: new Set(),
|
|
50
|
+
focused: null,
|
|
51
|
+
hovered: null,
|
|
52
|
+
drag: null,
|
|
53
|
+
shapes: new Map(),
|
|
54
|
+
shapesDirty: true,
|
|
55
|
+
resetSurface: true,
|
|
56
|
+
colors: new Map(),
|
|
57
|
+
config: { layout: 'circle', style: 'glyph', minZoom: 0.6 },
|
|
58
|
+
cleanup: [],
|
|
59
|
+
store: null,
|
|
60
|
+
unsubscribe: null,
|
|
61
|
+
animator: null,
|
|
62
|
+
runner: null,
|
|
63
|
+
zoom: null,
|
|
64
|
+
drawn: null,
|
|
65
|
+
presentation: null,
|
|
66
|
+
unsubscribePresentation: null,
|
|
67
|
+
diagnostics: [],
|
|
68
|
+
ready: Promise.resolve(),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function updateNetwork(node, state, links, preserve = false) {
|
|
73
|
+
state.network = buildNetwork(links);
|
|
74
|
+
const ids = new Set(networkIds(state.network));
|
|
75
|
+
if (!preserve) {
|
|
76
|
+
state.positions.clear();
|
|
77
|
+
}
|
|
78
|
+
for (const id of state.positions.keys()) {
|
|
79
|
+
if (!ids.has(id)) {
|
|
80
|
+
state.positions.delete(id);
|
|
81
|
+
state.pins.delete(id);
|
|
82
|
+
state.selected.delete(id);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
// New vertices are placed without moving existing ones, then an explicit
|
|
86
|
+
// layout change can rearrange the complete network in a worker.
|
|
87
|
+
const initial = circle(state.network, {
|
|
88
|
+
width: node.clientWidth || 640,
|
|
89
|
+
height: node.clientHeight || 400,
|
|
90
|
+
});
|
|
91
|
+
for (const id of ids) {
|
|
92
|
+
if (!state.positions.has(id)) {
|
|
93
|
+
state.positions.set(id, initial.get(id));
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
for (const collection of [state.pins, state.selected]) {
|
|
97
|
+
for (const id of collection.keys()) {
|
|
98
|
+
if (!ids.has(id)) {
|
|
99
|
+
collection.delete(id);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (!ids.has(state.focused)) {
|
|
104
|
+
state.focused = null;
|
|
105
|
+
}
|
|
106
|
+
state.shapesDirty = true;
|
|
107
|
+
node.requestDraw();
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function subscribeNetwork(node, state) {
|
|
111
|
+
state.unsubscribe?.();
|
|
112
|
+
state.unsubscribe = null;
|
|
113
|
+
if (!node.isConnected || !state.store) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
state.unsubscribe = state.store.subscribe((events) => {
|
|
117
|
+
const links = new Map(state.network.links);
|
|
118
|
+
for (const event of events) {
|
|
119
|
+
if (event.type === 'rename') {
|
|
120
|
+
links.delete(event.before);
|
|
121
|
+
}
|
|
122
|
+
const link = storeNetworkLink(state.store, event.id);
|
|
123
|
+
if (link) {
|
|
124
|
+
links.set(event.id, link);
|
|
125
|
+
} else {
|
|
126
|
+
links.delete(event.id);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
state.runner?.cancel('layout');
|
|
130
|
+
updateNetwork(node, state, links.values(), true);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function requestLayout(node, state) {
|
|
135
|
+
if (state.presentation) {
|
|
136
|
+
return Promise.resolve();
|
|
137
|
+
}
|
|
138
|
+
if (!state.animator) {
|
|
139
|
+
return Promise.resolve();
|
|
140
|
+
}
|
|
141
|
+
const layout = node.getAttribute('layout') ?? state.config.layout;
|
|
142
|
+
const job = {
|
|
143
|
+
layout,
|
|
144
|
+
links: networkInput(state.network),
|
|
145
|
+
options: {
|
|
146
|
+
width: node.clientWidth || 640,
|
|
147
|
+
height: node.clientHeight || 400,
|
|
148
|
+
pins: [...state.pins],
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
const apply = (result) => {
|
|
152
|
+
if (state.presentation) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
state.diagnostics = state.diagnostics.filter((d) => d.code);
|
|
156
|
+
state.positions = result.positions;
|
|
157
|
+
for (const [id, point] of state.pins) {
|
|
158
|
+
if (state.positions.has(id)) {
|
|
159
|
+
state.positions.set(id, point);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
state.shapesDirty = true;
|
|
163
|
+
node.requestDraw();
|
|
164
|
+
node.dispatchEvent(
|
|
165
|
+
new state.win.CustomEvent('layoutend', { detail: { layout } })
|
|
166
|
+
);
|
|
167
|
+
};
|
|
168
|
+
const task = !Object.hasOwn(NETWORK_LAYOUTS, layout)
|
|
169
|
+
? Promise.reject(new TypeError(`Unknown layout: ${layout}`))
|
|
170
|
+
: state.runner
|
|
171
|
+
? state.runner.run('layout', job)
|
|
172
|
+
: Promise.resolve().then(() => ({
|
|
173
|
+
positions: NETWORK_LAYOUTS[layout](state.network, job.options),
|
|
174
|
+
}));
|
|
175
|
+
return networkReady(node, state, task.then(apply));
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function networkReady(node, state, task) {
|
|
179
|
+
state.ready = task.catch((error) => {
|
|
180
|
+
if (error.name === 'AbortError') {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
state.diagnostics = [{ severity: 'error', message: error.message }];
|
|
184
|
+
node.dispatchEvent(
|
|
185
|
+
new state.win.CustomEvent('layouterror', { detail: error })
|
|
186
|
+
);
|
|
187
|
+
throw error;
|
|
188
|
+
});
|
|
189
|
+
// Attribute changes also start jobs; report failures via layouterror and
|
|
190
|
+
// diagnostics even if the caller does not await `ready`.
|
|
191
|
+
state.ready.catch(() => {});
|
|
192
|
+
return state.ready;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function presentationReady(node, state, input) {
|
|
196
|
+
const task = input
|
|
197
|
+
? state.presentation.update(input)
|
|
198
|
+
: state.presentation.solve();
|
|
199
|
+
return networkReady(node, state, task);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function connectNetwork(node, state) {
|
|
203
|
+
if (state.animator) {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
node.setAttribute('role', 'application');
|
|
207
|
+
node.setAttribute('tabindex', '0');
|
|
208
|
+
node.setAttribute(
|
|
209
|
+
'aria-label',
|
|
210
|
+
node.getAttribute('label') ?? 'Links network'
|
|
211
|
+
);
|
|
212
|
+
node.setAttribute(
|
|
213
|
+
'aria-keyshortcuts',
|
|
214
|
+
'ArrowUp ArrowDown ArrowLeft ArrowRight Enter Escape Home + - 0 Shift+F10 Alt+ArrowUp Alt+ArrowDown Alt+ArrowLeft Alt+ArrowRight'
|
|
215
|
+
);
|
|
216
|
+
const listen = (target, type, fn) => {
|
|
217
|
+
target.addEventListener(type, fn);
|
|
218
|
+
state.cleanup.push(() => target.removeEventListener(type, fn));
|
|
219
|
+
};
|
|
220
|
+
state.animator = createAnimator({
|
|
221
|
+
raf: (fn) => state.win.requestAnimationFrame(fn),
|
|
222
|
+
caf: (id) => state.win.cancelAnimationFrame(id),
|
|
223
|
+
reducedMotion: () =>
|
|
224
|
+
state.win.matchMedia?.('(prefers-reduced-motion: reduce)').matches ===
|
|
225
|
+
true,
|
|
226
|
+
...state.options.animator,
|
|
227
|
+
});
|
|
228
|
+
connectNetworkInteraction(node, state, listen);
|
|
229
|
+
state.zoom = createZoomPan(node, { onChange: () => node.requestDraw() });
|
|
230
|
+
if (
|
|
231
|
+
state.options.worker !== false &&
|
|
232
|
+
(state.options.createWorker || state.win.Worker)
|
|
233
|
+
) {
|
|
234
|
+
state.runner = createLayoutRunner({
|
|
235
|
+
createWorker:
|
|
236
|
+
state.options.createWorker ??
|
|
237
|
+
(() =>
|
|
238
|
+
new state.win.Worker(
|
|
239
|
+
new URL('../../dist/network-layout.worker.mjs', import.meta.url),
|
|
240
|
+
{ type: 'module' }
|
|
241
|
+
)),
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
if (state.win.ResizeObserver) {
|
|
245
|
+
const observer = new state.win.ResizeObserver(() => node.requestDraw());
|
|
246
|
+
observer.observe(node);
|
|
247
|
+
state.cleanup.push(() => observer.disconnect());
|
|
248
|
+
}
|
|
249
|
+
const scheme = state.win.matchMedia?.('(prefers-color-scheme: dark)');
|
|
250
|
+
if (scheme?.addEventListener) {
|
|
251
|
+
listen(scheme, 'change', () => {
|
|
252
|
+
state.resetSurface = true;
|
|
253
|
+
node.requestDraw();
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
if (state.presentation) {
|
|
257
|
+
setPresentation(node, state, state.presentation);
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
if (state.store) {
|
|
261
|
+
updateNetwork(node, state, storeNetworkLinks(state.store));
|
|
262
|
+
subscribeNetwork(node, state);
|
|
263
|
+
} else if (node.hasAttribute('lino') || node.textContent.trim()) {
|
|
264
|
+
readSource(node, state);
|
|
265
|
+
}
|
|
266
|
+
requestLayout(node, state);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function readSource(node, state) {
|
|
270
|
+
const read = readNetworkSource(node.getAttribute('lino') ?? node.textContent);
|
|
271
|
+
state.config = read;
|
|
272
|
+
state.diagnostics = read.diagnostics;
|
|
273
|
+
updateNetwork(node, state, read.links);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
function disconnectNetwork(s) {
|
|
277
|
+
s.unsubscribe?.();
|
|
278
|
+
s.unsubscribe = null;
|
|
279
|
+
s.unsubscribePresentation?.();
|
|
280
|
+
s.unsubscribePresentation = null;
|
|
281
|
+
s.runner?.dispose();
|
|
282
|
+
s.runner = null;
|
|
283
|
+
s.zoom?.destroy();
|
|
284
|
+
s.zoom = null;
|
|
285
|
+
s.animator?.destroy();
|
|
286
|
+
s.animator = null;
|
|
287
|
+
s.cleanup.forEach((fn) => fn());
|
|
288
|
+
s.cleanup = [];
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
function setPresentation(node, s, presentation) {
|
|
292
|
+
if (presentation && s.store) {
|
|
293
|
+
throw new Error('Detach the store before assigning a presentation');
|
|
294
|
+
}
|
|
295
|
+
s.unsubscribePresentation?.();
|
|
296
|
+
s.unsubscribePresentation = null;
|
|
297
|
+
s.presentation = presentation;
|
|
298
|
+
s.runner?.cancel('layout');
|
|
299
|
+
const apply = (snapshot) => {
|
|
300
|
+
if (!snapshot.frame) {
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
s.diagnostics = [];
|
|
304
|
+
s.network = buildNetwork(snapshot.input.items);
|
|
305
|
+
s.positions = new Map(snapshot.frame.positions);
|
|
306
|
+
s.pins = new Map(snapshot.frame.pins);
|
|
307
|
+
s.shapesDirty = true;
|
|
308
|
+
s.resetSurface = true;
|
|
309
|
+
node.requestDraw();
|
|
310
|
+
};
|
|
311
|
+
if (presentation) {
|
|
312
|
+
s.unsubscribePresentation = presentation.subscribe(apply);
|
|
313
|
+
apply(presentation.snapshot());
|
|
314
|
+
} else {
|
|
315
|
+
s.resetSurface = true;
|
|
316
|
+
node.requestDraw();
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
/** Explicit definition; importing the package is safe without a DOM. */
|
|
320
|
+
export function defineLinksNetwork(win = globalThis.window, options = {}) {
|
|
321
|
+
const tag = options.tag ?? LINKS_NETWORK_TAG;
|
|
322
|
+
if (win.customElements.get(tag)) {
|
|
323
|
+
return win.customElements.get(tag);
|
|
324
|
+
}
|
|
325
|
+
class LinksNetwork extends win.HTMLElement {
|
|
326
|
+
#state;
|
|
327
|
+
static get observedAttributes() {
|
|
328
|
+
return ['lino', 'layout', 'style-mode', 'theme', 'label'];
|
|
329
|
+
}
|
|
330
|
+
constructor() {
|
|
331
|
+
super();
|
|
332
|
+
this.#state = makeState(this, win, options);
|
|
333
|
+
}
|
|
334
|
+
connectedCallback() {
|
|
335
|
+
connectNetwork(this, this.#state);
|
|
336
|
+
}
|
|
337
|
+
disconnectedCallback() {
|
|
338
|
+
disconnectNetwork(this.#state);
|
|
339
|
+
}
|
|
340
|
+
attributeChangedCallback(name) {
|
|
341
|
+
const s = this.#state;
|
|
342
|
+
if (!this.isConnected) {
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
if (s.presentation) {
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
if (name === 'lino') {
|
|
349
|
+
readSource(this, s);
|
|
350
|
+
}
|
|
351
|
+
s.resetSurface = true;
|
|
352
|
+
s.shapesDirty = true;
|
|
353
|
+
if (name === 'layout' || name === 'lino') {
|
|
354
|
+
requestLayout(this, s);
|
|
355
|
+
} else {
|
|
356
|
+
this.requestDraw();
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
/** Host-supplied geometry/export backend. The host owns its lifetime. */
|
|
360
|
+
get presentation() {
|
|
361
|
+
return this.#state.presentation;
|
|
362
|
+
}
|
|
363
|
+
set presentation(presentation) {
|
|
364
|
+
setPresentation(this, this.#state, presentation);
|
|
365
|
+
}
|
|
366
|
+
get items() {
|
|
367
|
+
return [...this.#state.network.links.values()];
|
|
368
|
+
}
|
|
369
|
+
set items(links) {
|
|
370
|
+
if (this.#state.presentation) {
|
|
371
|
+
presentationReady(this, this.#state, { items: [...links] });
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
updateNetwork(this, this.#state, links);
|
|
375
|
+
requestLayout(this, this.#state);
|
|
376
|
+
}
|
|
377
|
+
get store() {
|
|
378
|
+
return this.#state.store;
|
|
379
|
+
}
|
|
380
|
+
set store(store) {
|
|
381
|
+
if (this.#state.presentation) {
|
|
382
|
+
throw new Error('Detach presentation before binding a store');
|
|
383
|
+
}
|
|
384
|
+
const s = this.#state;
|
|
385
|
+
s.unsubscribe?.();
|
|
386
|
+
s.store = store;
|
|
387
|
+
updateNetwork(this, s, store ? storeNetworkLinks(store) : []);
|
|
388
|
+
subscribeNetwork(this, s);
|
|
389
|
+
requestLayout(this, s);
|
|
390
|
+
}
|
|
391
|
+
set links(value) {
|
|
392
|
+
if (this.#state.presentation) {
|
|
393
|
+
throw new Error('Update the presentation input instead');
|
|
394
|
+
}
|
|
395
|
+
const s = this.#state;
|
|
396
|
+
s.config = readNetworkRaw(value.raw);
|
|
397
|
+
updateNetwork(this, s, s.config.links);
|
|
398
|
+
requestLayout(this, s);
|
|
399
|
+
}
|
|
400
|
+
get network() {
|
|
401
|
+
return this.#state.network;
|
|
402
|
+
}
|
|
403
|
+
get positions() {
|
|
404
|
+
return new Map(this.#state.positions);
|
|
405
|
+
}
|
|
406
|
+
set positions(positions) {
|
|
407
|
+
if (this.#state.presentation) {
|
|
408
|
+
throw new Error('Presentation provider owns positions');
|
|
409
|
+
}
|
|
410
|
+
this.#state.positions = new Map(positions);
|
|
411
|
+
this.#state.shapesDirty = true;
|
|
412
|
+
this.requestDraw();
|
|
413
|
+
}
|
|
414
|
+
get pins() {
|
|
415
|
+
return new Map(this.#state.pins);
|
|
416
|
+
}
|
|
417
|
+
get selection() {
|
|
418
|
+
return [...this.#state.selected];
|
|
419
|
+
}
|
|
420
|
+
select(id, additive = false) {
|
|
421
|
+
selectNetwork(this, this.#state, id, additive);
|
|
422
|
+
}
|
|
423
|
+
get ready() {
|
|
424
|
+
return this.#state.ready;
|
|
425
|
+
}
|
|
426
|
+
get diagnostics() {
|
|
427
|
+
return [...this.#state.diagnostics];
|
|
428
|
+
}
|
|
429
|
+
get view() {
|
|
430
|
+
return this.#state.zoom?.get() ?? { x: 0, y: 0, k: 1 };
|
|
431
|
+
}
|
|
432
|
+
set view(view) {
|
|
433
|
+
this.#state.zoom?.set(view);
|
|
434
|
+
}
|
|
435
|
+
get drawn() {
|
|
436
|
+
return this.#state.drawn;
|
|
437
|
+
}
|
|
438
|
+
layout() {
|
|
439
|
+
if (this.#state.presentation) {
|
|
440
|
+
return presentationReady(this, this.#state);
|
|
441
|
+
}
|
|
442
|
+
return requestLayout(this, this.#state);
|
|
443
|
+
}
|
|
444
|
+
requestDraw() {
|
|
445
|
+
this.#state.animator?.start('draw', () => {
|
|
446
|
+
drawNetwork(this, this.#state);
|
|
447
|
+
return false;
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
toSvg() {
|
|
451
|
+
if (this.#state.presentation) {
|
|
452
|
+
return this.#state.presentation.toSvg();
|
|
453
|
+
}
|
|
454
|
+
return networkToSvg(
|
|
455
|
+
this.#state.network,
|
|
456
|
+
this.#state.positions,
|
|
457
|
+
networkStyle(this, this.#state)
|
|
458
|
+
);
|
|
459
|
+
}
|
|
460
|
+
toPng(scale = 1) {
|
|
461
|
+
return this.#state.presentation
|
|
462
|
+
? this.#state.presentation.toRaster('image/png', { scale })
|
|
463
|
+
: networkToPng(this.toSvg(), scale);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
win.customElements.define(tag, LinksNetwork);
|
|
467
|
+
return LinksNetwork;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
export function linksNetworkKind({ tag = LINKS_NETWORK_TAG } = {}) {
|
|
471
|
+
const update = (node, el, ctx) => {
|
|
472
|
+
node.links = { raw: networkRaw(el, ctx.children?.() ?? []) };
|
|
473
|
+
const store = ctx.options?.networkStore;
|
|
474
|
+
if (store?.subscribe) {
|
|
475
|
+
node.store = store;
|
|
476
|
+
}
|
|
477
|
+
};
|
|
478
|
+
return {
|
|
479
|
+
tag,
|
|
480
|
+
childrenSlot: null,
|
|
481
|
+
create(el, ctx) {
|
|
482
|
+
const node = ctx.document.createElement(tag);
|
|
483
|
+
update(node, el, ctx);
|
|
484
|
+
return node;
|
|
485
|
+
},
|
|
486
|
+
update: (node, el, changed, ctx) => update(node, el, ctx),
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
export function registerLinksNetworkKind(
|
|
491
|
+
win = globalThis.window,
|
|
492
|
+
options = {}
|
|
493
|
+
) {
|
|
494
|
+
defineLinksNetwork(win, options);
|
|
495
|
+
return defineKind('links-network', linksNetworkKind(options));
|
|
496
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/** Source annotations only: structure always comes from the official parser. */
|
|
2
|
+
import { Link, stripComments } from 'links-notation';
|
|
3
|
+
import { formatLinks } from '@link-foundation/ui-core';
|
|
4
|
+
import { scanDelimiters } from '@link-foundation/ui-core/source';
|
|
5
|
+
|
|
6
|
+
/** Locate references in parser traversal order; comments keep their offsets. */
|
|
7
|
+
export function sourceReferences(text) {
|
|
8
|
+
const { tokens } = scanDelimiters(stripComments(text));
|
|
9
|
+
return tokens.flatMap((token, index) =>
|
|
10
|
+
token.type === 'reference'
|
|
11
|
+
? [{ ...token, definition: tokens[index + 1]?.type === 'colon' }]
|
|
12
|
+
: []
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Locate physical lines, including breaks inside quoted values, in one pass. */
|
|
17
|
+
function positionLocator(text) {
|
|
18
|
+
const starts = [0];
|
|
19
|
+
for (let i = 0; i < text.length; i++) {
|
|
20
|
+
if (text[i] === '\r') {
|
|
21
|
+
if (text[i + 1] === '\n') {
|
|
22
|
+
i++;
|
|
23
|
+
}
|
|
24
|
+
starts.push(i + 1);
|
|
25
|
+
} else if (text[i] === '\n') {
|
|
26
|
+
starts.push(i + 1);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return (offset) => {
|
|
30
|
+
let low = 0;
|
|
31
|
+
let high = starts.length;
|
|
32
|
+
while (low + 1 < high) {
|
|
33
|
+
const middle = Math.floor((low + high) / 2);
|
|
34
|
+
if (starts[middle] <= offset) {
|
|
35
|
+
low = middle;
|
|
36
|
+
} else {
|
|
37
|
+
high = middle;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return { line: low + 1, column: offset - starts[low] + 1 };
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Attach lexical quoting and positions without interpreting LiNo structure. */
|
|
45
|
+
export function annotateLinks(links, text) {
|
|
46
|
+
const references = sourceReferences(text);
|
|
47
|
+
const tokens = scanDelimiters(stripComments(text)).tokens.filter(
|
|
48
|
+
(token) => token.type !== 'break'
|
|
49
|
+
);
|
|
50
|
+
const empty = tokens.filter(
|
|
51
|
+
(token, i) => token.type === 'open' && tokens[i + 1]?.type === 'close'
|
|
52
|
+
);
|
|
53
|
+
const position = positionLocator(text);
|
|
54
|
+
let emptyIndex = 0;
|
|
55
|
+
let index = 0;
|
|
56
|
+
const positions = new WeakMap();
|
|
57
|
+
const visit = (link) => {
|
|
58
|
+
const token = references[index];
|
|
59
|
+
const node = { id: link.id, values: [] };
|
|
60
|
+
const offset =
|
|
61
|
+
link.id === null && link.values.length === 0
|
|
62
|
+
? empty[emptyIndex++]?.start
|
|
63
|
+
: token?.start;
|
|
64
|
+
positions.set(node, position(offset ?? text.length));
|
|
65
|
+
if (link.id !== null) {
|
|
66
|
+
index++;
|
|
67
|
+
if (token?.definition) {
|
|
68
|
+
node.definition = true;
|
|
69
|
+
} else if (
|
|
70
|
+
token?.quoted ||
|
|
71
|
+
text.slice(token?.start, token?.end) !== link.id
|
|
72
|
+
) {
|
|
73
|
+
node.quote = text.slice(token.start, token.end);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
node.values = link.values.map(visit);
|
|
77
|
+
return node;
|
|
78
|
+
};
|
|
79
|
+
return { roots: links.map(visit), positions };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Write nested LiNo with ui-core, retaining value quoting the parser discards. */
|
|
83
|
+
export function formatNetworkRoots(roots) {
|
|
84
|
+
const references = [];
|
|
85
|
+
const toLink = (node) => {
|
|
86
|
+
if (node.id === null && node.values.length === 0) {
|
|
87
|
+
references.push({ empty: true }, { placeholder: true });
|
|
88
|
+
return new Link('@empty', [new Link('@empty-value')]);
|
|
89
|
+
}
|
|
90
|
+
if (node.id !== null) {
|
|
91
|
+
references.push(node);
|
|
92
|
+
}
|
|
93
|
+
return new Link(node.id, node.values.map(toLink));
|
|
94
|
+
};
|
|
95
|
+
const text = formatLinks(roots.map(toLink));
|
|
96
|
+
const tokens = sourceReferences(text);
|
|
97
|
+
const chunks = [];
|
|
98
|
+
let cursor = 0;
|
|
99
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
100
|
+
const token = tokens[i];
|
|
101
|
+
const node = references[i];
|
|
102
|
+
if (node.empty) {
|
|
103
|
+
let start = token.start;
|
|
104
|
+
let end = tokens[++i].end;
|
|
105
|
+
if (text[start - 1] === '(' && text[end] === ')') {
|
|
106
|
+
start--;
|
|
107
|
+
end++;
|
|
108
|
+
}
|
|
109
|
+
chunks.push(text.slice(cursor, start), '()');
|
|
110
|
+
cursor = end;
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
let replacement = node.quote ?? text.slice(token.start, token.end);
|
|
114
|
+
if (node.definition && !node.values.length && !token.definition) {
|
|
115
|
+
replacement = `(${replacement}:)`;
|
|
116
|
+
}
|
|
117
|
+
chunks.push(text.slice(cursor, token.start), replacement);
|
|
118
|
+
cursor = token.end;
|
|
119
|
+
}
|
|
120
|
+
chunks.push(text.slice(cursor));
|
|
121
|
+
return chunks.join('');
|
|
122
|
+
}
|