@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,76 @@
|
|
|
1
|
+
import { normalize, networkOptionSchema } from './options.js';
|
|
2
|
+
|
|
3
|
+
export const networkSizePresets = Object.freeze(
|
|
4
|
+
[
|
|
5
|
+
[512, 512],
|
|
6
|
+
[1024, 1024],
|
|
7
|
+
[2048, 2048],
|
|
8
|
+
[1080, 1080],
|
|
9
|
+
[1200, 630],
|
|
10
|
+
[1600, 900],
|
|
11
|
+
[1080, 1920],
|
|
12
|
+
].map(Object.freeze)
|
|
13
|
+
);
|
|
14
|
+
/** Looks are framework-owned values; none are copied from a consumer site. */
|
|
15
|
+
export const networkLooks = Object.freeze(
|
|
16
|
+
Object.fromEntries(
|
|
17
|
+
Object.entries({
|
|
18
|
+
card: {
|
|
19
|
+
'background.type': 'solid',
|
|
20
|
+
'background.color': '#e5e7eb',
|
|
21
|
+
'card.opacity': 1,
|
|
22
|
+
'card.radius': 8,
|
|
23
|
+
'card.inset': 6,
|
|
24
|
+
},
|
|
25
|
+
black: {
|
|
26
|
+
'background.type': 'solid',
|
|
27
|
+
'background.color': '#000000',
|
|
28
|
+
color: '#ffffff',
|
|
29
|
+
'caption.color': '#ffffff',
|
|
30
|
+
},
|
|
31
|
+
transparent: { 'background.type': 'transparent' },
|
|
32
|
+
paper: {
|
|
33
|
+
'background.type': 'solid',
|
|
34
|
+
'background.color': '#fffaf0',
|
|
35
|
+
color: '#473c2d',
|
|
36
|
+
'caption.mode': 'pairs',
|
|
37
|
+
},
|
|
38
|
+
blueprint: {
|
|
39
|
+
'background.type': 'solid',
|
|
40
|
+
'background.color': '#102b53',
|
|
41
|
+
color: '#ffffff',
|
|
42
|
+
dash: 'dashed',
|
|
43
|
+
},
|
|
44
|
+
neon: {
|
|
45
|
+
'background.type': 'solid',
|
|
46
|
+
'background.color': '#111827',
|
|
47
|
+
color: '#22ffbb',
|
|
48
|
+
glow: 4,
|
|
49
|
+
},
|
|
50
|
+
social: {
|
|
51
|
+
width: 1200,
|
|
52
|
+
height: 630,
|
|
53
|
+
'background.type': 'linear',
|
|
54
|
+
'card.opacity': 1,
|
|
55
|
+
'card.inset': 6,
|
|
56
|
+
'card.radius': 6,
|
|
57
|
+
},
|
|
58
|
+
}).map(([key, value]) => [key, Object.freeze(value)])
|
|
59
|
+
)
|
|
60
|
+
);
|
|
61
|
+
export function replaceStyle(current, style) {
|
|
62
|
+
const preserved = Object.fromEntries(
|
|
63
|
+
networkOptionSchema
|
|
64
|
+
.filter((f) => ['solver', 'gaps'].includes(f.section))
|
|
65
|
+
.map((f) => [f.key, current[f.key]])
|
|
66
|
+
);
|
|
67
|
+
return normalize({
|
|
68
|
+
...normalize(style),
|
|
69
|
+
...preserved,
|
|
70
|
+
turns: current.turns,
|
|
71
|
+
linkGaps: current.linkGaps,
|
|
72
|
+
linkColors: current.linkColors,
|
|
73
|
+
order: current.order,
|
|
74
|
+
frame: null,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { formatLinks } from '@link-foundation/ui-core';
|
|
2
|
+
import { createDoubletProvider } from '../doublet.js';
|
|
3
|
+
import { normalize, fromOptions } from './options.js';
|
|
4
|
+
import { networkOptionSchema } from './schema.js';
|
|
5
|
+
|
|
6
|
+
/** Translate the editor vocabulary into the built-in renderer's nested LiNo. */
|
|
7
|
+
export function rendererOptions(input, count) {
|
|
8
|
+
const options = normalize(input),
|
|
9
|
+
records = [],
|
|
10
|
+
groups = new Map();
|
|
11
|
+
for (const field of networkOptionSchema) {
|
|
12
|
+
if (
|
|
13
|
+
['solver', 'palette'].includes(field.section) ||
|
|
14
|
+
options[field.key] === field.default
|
|
15
|
+
) {
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
const [group, key] = field.key.split('.');
|
|
19
|
+
const entry = { id: key ?? group, values: [String(options[field.key])] };
|
|
20
|
+
if (!key) {
|
|
21
|
+
records.push(entry);
|
|
22
|
+
} else {
|
|
23
|
+
if (!groups.has(group)) {
|
|
24
|
+
const node = { id: group, values: [] };
|
|
25
|
+
groups.set(group, node);
|
|
26
|
+
records.push(node);
|
|
27
|
+
}
|
|
28
|
+
groups.get(group).values.push(entry);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const gaps = ['startGap', 'endGap', 'middleBefore', 'middleAfter'];
|
|
32
|
+
// These editor keys are represented by the provider's single gaps vector.
|
|
33
|
+
const filtered = records.filter((entry) => !gaps.includes(entry.id));
|
|
34
|
+
if (gaps.some((key) => options[key] !== normalize({})[key])) {
|
|
35
|
+
filtered.push({
|
|
36
|
+
id: 'gaps',
|
|
37
|
+
values: gaps.map((key) => String(options[key])),
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
for (const key of ['frame', 'order']) {
|
|
41
|
+
if (options[key]) {
|
|
42
|
+
filtered.push({ id: key, values: options[key].map(String) });
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
for (let i = 0; i < count; i++) {
|
|
46
|
+
const values = [];
|
|
47
|
+
if (options.turns[i]) {
|
|
48
|
+
values.push({ id: 'turns', values: options.turns[i].map(String) });
|
|
49
|
+
}
|
|
50
|
+
if (options.linkGaps[i]) {
|
|
51
|
+
values.push({
|
|
52
|
+
id: 'gaps',
|
|
53
|
+
values: options.linkGaps[i].map((v) => (v === null ? '~' : String(v))),
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
if (values.length) {
|
|
57
|
+
filtered.push({ values: ['link', String(i + 1), ...values] });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return formatLinks(filtered);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Built-in doublet provider for the editor's full persisted state vocabulary. */
|
|
64
|
+
export function createNetworkEditorProvider(configuration = {}) {
|
|
65
|
+
const provider = createDoubletProvider(configuration);
|
|
66
|
+
return {
|
|
67
|
+
geometry(context) {
|
|
68
|
+
const options = fromOptions(context.input.options);
|
|
69
|
+
const frame = provider.geometry({
|
|
70
|
+
...context,
|
|
71
|
+
input: {
|
|
72
|
+
...context.input,
|
|
73
|
+
options: rendererOptions(options, context.input.items.length),
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
return { ...frame, linkColors: options.linkColors };
|
|
77
|
+
},
|
|
78
|
+
svg(context) {
|
|
79
|
+
let svg = provider.svg(context);
|
|
80
|
+
// The built-in renderer gives every link an identified group. Its paths
|
|
81
|
+
// and markers inherit currentColor, so one group attribute colors both.
|
|
82
|
+
context.frame.linkColors.forEach((color, i) => {
|
|
83
|
+
if (color) {
|
|
84
|
+
svg = svg.replace(
|
|
85
|
+
`<g data-doublet="${i + 1}">`,
|
|
86
|
+
`<g data-doublet="${i + 1}" color="${color}">`
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
return svg;
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export function remapOptions(options, indexMap, count) {
|
|
2
|
+
const remap = (key, fallback) => {
|
|
3
|
+
const output = Array.from({ length: count }, () =>
|
|
4
|
+
globalThis.structuredClone(fallback)
|
|
5
|
+
);
|
|
6
|
+
for (const [oldId, newId] of indexMap) {
|
|
7
|
+
output[newId - 1] = globalThis.structuredClone(
|
|
8
|
+
options[key][oldId - 1] ?? fallback
|
|
9
|
+
);
|
|
10
|
+
}
|
|
11
|
+
return output;
|
|
12
|
+
};
|
|
13
|
+
return {
|
|
14
|
+
turns: remap('turns', [0, 0]),
|
|
15
|
+
linkGaps: remap('linkGaps', [null, null, null, null]),
|
|
16
|
+
linkColors: remap('linkColors', null),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export function canonicalMap(config, links, code) {
|
|
20
|
+
function search(permutation, remaining) {
|
|
21
|
+
if (!remaining.length) {
|
|
22
|
+
return config.encode(config.relabel(links, permutation)) === code
|
|
23
|
+
? permutation
|
|
24
|
+
: null;
|
|
25
|
+
}
|
|
26
|
+
for (const value of remaining) {
|
|
27
|
+
const found = search(
|
|
28
|
+
[...permutation, value],
|
|
29
|
+
remaining.filter((v) => v !== value)
|
|
30
|
+
);
|
|
31
|
+
if (found) {
|
|
32
|
+
return found;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
const permutation = search(
|
|
38
|
+
[],
|
|
39
|
+
links.map((_, i) => i + 1)
|
|
40
|
+
);
|
|
41
|
+
if (!permutation) {
|
|
42
|
+
throw new Error('Canonical adapter returned an unrelated network');
|
|
43
|
+
}
|
|
44
|
+
return new Map(permutation.map((value, i) => [i + 1, value]));
|
|
45
|
+
}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { parseNested } from '@link-foundation/ui-core';
|
|
2
|
+
|
|
3
|
+
/** Canonical editor schema: key type default min max step section availability. */
|
|
4
|
+
export const networkSchemaLino = `
|
|
5
|
+
layout choice auto 'auto circle grid hex spiral dice cards force layered' layout always
|
|
6
|
+
layoutAspect number 1 0.3 3 0.1 layout always
|
|
7
|
+
columns number 0 0 30 1 layout grid
|
|
8
|
+
spread number 1 0 100 0.1 layout always
|
|
9
|
+
rotation number 0 -180 180 1 layout always
|
|
10
|
+
free number 1 0 10 0.1 geometry free
|
|
11
|
+
loop number 1 0 10 0.1 geometry loop
|
|
12
|
+
bulge number 0 -180 180 1 geometry always
|
|
13
|
+
loopBend number 0 -180 180 1 geometry loop
|
|
14
|
+
angles choice fixed 'fixed mirror' geometry referenced
|
|
15
|
+
sourceAngle number 30 -180 180 1 geometry fixed
|
|
16
|
+
targetAngle number 30 -180 180 1 geometry fixed
|
|
17
|
+
tension number 0.4 0 2 0.01 geometry always
|
|
18
|
+
startGap number 0.08 0 1 0.01 gaps always
|
|
19
|
+
endGap number 0.08 0 1 0.01 gaps always
|
|
20
|
+
middleBefore number 0 0 30 0.1 gaps always
|
|
21
|
+
middleAfter number 0 0 30 0.1 gaps always
|
|
22
|
+
padding number 9 0 48 1 geometry always
|
|
23
|
+
strokeWidth number 1 0.5 10 0.1 line always
|
|
24
|
+
color color '#202b3d' line always
|
|
25
|
+
palette choice default 'default custom' palette always
|
|
26
|
+
dash choice solid 'solid dashed dotted dashdot long' line always
|
|
27
|
+
linecap choice round 'butt round square' line always
|
|
28
|
+
opacity number 1 0.1 1 0.01 line always
|
|
29
|
+
glow number 0 0 12 0.1 line always
|
|
30
|
+
arrowJoin choice miter 'miter round bevel' line arrow
|
|
31
|
+
balanceArrows boolean true line arrow
|
|
32
|
+
background.type choice transparent 'transparent solid linear radial' background always
|
|
33
|
+
background.color color '#ffffff' background background
|
|
34
|
+
background.color2 color '#dbeafe' background gradient
|
|
35
|
+
background.angle number 0 -180 180 1 background linear
|
|
36
|
+
card.color color '#ffffff' card card
|
|
37
|
+
card.opacity number 0 0 1 0.01 card always
|
|
38
|
+
card.border choice none 'solid dashed dotted double none' card always
|
|
39
|
+
card.borderColor color '#202b3d' card border
|
|
40
|
+
card.width number 1 0.1 6 0.1 card border
|
|
41
|
+
card.radius number 0 0 50 1 card card
|
|
42
|
+
card.inset number 0 0 30 1 card card
|
|
43
|
+
caption.mode choice none 'none theory pairs number links custom' caption always
|
|
44
|
+
caption.text text '' caption customCaption
|
|
45
|
+
caption.font choice mono 'mono sans serif' caption caption
|
|
46
|
+
caption.size number 5 3 14 0.1 caption caption
|
|
47
|
+
caption.color color '#202b3d' caption caption
|
|
48
|
+
width number 640 64 4096 1 size always
|
|
49
|
+
height number 640 64 4096 1 size always
|
|
50
|
+
clearance number 1 0 10 0.1 solver always
|
|
51
|
+
solveRange number 180 0 180 1 solver always
|
|
52
|
+
solveStep number 1 1 30 1 solver always
|
|
53
|
+
solveGaps boolean true solver always
|
|
54
|
+
solveGapRange number 0.2 0 1 0.01 solver solveGaps
|
|
55
|
+
solveMiddleRange number 0 0 15 0.1 solver solveGaps
|
|
56
|
+
passes number 3 1 10 1 solver always
|
|
57
|
+
debug boolean false solver always
|
|
58
|
+
`;
|
|
59
|
+
|
|
60
|
+
function readField(link) {
|
|
61
|
+
const [key, type, initial, ...rest] = link.values.map((v) => v.id);
|
|
62
|
+
const section = rest.at(-2);
|
|
63
|
+
const availability = rest.at(-1);
|
|
64
|
+
return {
|
|
65
|
+
key,
|
|
66
|
+
type,
|
|
67
|
+
section,
|
|
68
|
+
availability,
|
|
69
|
+
default:
|
|
70
|
+
type === 'number'
|
|
71
|
+
? Number(initial)
|
|
72
|
+
: type === 'boolean'
|
|
73
|
+
? initial === 'true'
|
|
74
|
+
: initial,
|
|
75
|
+
...(type === 'number'
|
|
76
|
+
? { min: Number(rest[0]), max: Number(rest[1]), step: Number(rest[2]) }
|
|
77
|
+
: {}),
|
|
78
|
+
...(type === 'choice' ? { choices: rest[0].split(' ') } : {}),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const markerFields = (part) => {
|
|
83
|
+
const initial = {
|
|
84
|
+
start: ['bar', 2.5, 70, 2.5],
|
|
85
|
+
end: ['arrow', 3.5, 45, 0],
|
|
86
|
+
middle: ['dot', 2, 45, 0],
|
|
87
|
+
}[part];
|
|
88
|
+
return [
|
|
89
|
+
{
|
|
90
|
+
key: 'shape',
|
|
91
|
+
type: 'choice',
|
|
92
|
+
default: initial[0],
|
|
93
|
+
choices: [
|
|
94
|
+
'bar',
|
|
95
|
+
'arrow',
|
|
96
|
+
'triangle',
|
|
97
|
+
'tail',
|
|
98
|
+
'dot',
|
|
99
|
+
'circle',
|
|
100
|
+
'square',
|
|
101
|
+
'diamond',
|
|
102
|
+
'none',
|
|
103
|
+
],
|
|
104
|
+
},
|
|
105
|
+
...[
|
|
106
|
+
['size', initial[1], 0.5, 15, 0.1],
|
|
107
|
+
['angle', initial[2], 5, 85, 1],
|
|
108
|
+
['offset', initial[3], -20, 20, 0.1],
|
|
109
|
+
['across', 0, -20, 20, 0.1],
|
|
110
|
+
['rotation', 0, -180, 180, 1],
|
|
111
|
+
].map(([key, value, min, max, step]) => ({
|
|
112
|
+
key,
|
|
113
|
+
type: 'number',
|
|
114
|
+
default: value,
|
|
115
|
+
min,
|
|
116
|
+
max,
|
|
117
|
+
step,
|
|
118
|
+
})),
|
|
119
|
+
].map((field) => ({
|
|
120
|
+
...field,
|
|
121
|
+
key: `${part}.${field.key}`,
|
|
122
|
+
section: part,
|
|
123
|
+
availability:
|
|
124
|
+
field.key === 'shape' ? 'always' : `marker:${part}:${field.key}`,
|
|
125
|
+
}));
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
export const networkOptionSchema = Object.freeze(
|
|
129
|
+
[
|
|
130
|
+
...parseNested(networkSchemaLino).map(readField),
|
|
131
|
+
...['start', 'end', 'middle'].flatMap(markerFields),
|
|
132
|
+
].map(Object.freeze)
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
/** Whether this control can affect the current network or style. */
|
|
136
|
+
export function optionAvailable(field, links, options) {
|
|
137
|
+
const rule = field.availability;
|
|
138
|
+
const self = links.some((pair, i) => pair.includes(i + 1));
|
|
139
|
+
const referenced = links.some((pair, i) =>
|
|
140
|
+
pair.some((v) => v !== 0 && v !== i + 1)
|
|
141
|
+
);
|
|
142
|
+
const predicates = {
|
|
143
|
+
always: true,
|
|
144
|
+
free: links.some((pair) => pair.includes(0)),
|
|
145
|
+
loop: self,
|
|
146
|
+
referenced,
|
|
147
|
+
fixed: referenced && options.angles === 'fixed',
|
|
148
|
+
grid: ['grid', 'cards'].includes(options.layout),
|
|
149
|
+
circle: options.layout === 'circle',
|
|
150
|
+
background: options['background.type'] !== 'transparent',
|
|
151
|
+
gradient: ['linear', 'radial'].includes(options['background.type']),
|
|
152
|
+
linear: options['background.type'] === 'linear',
|
|
153
|
+
card: options['card.opacity'] > 0 || options['card.border'] !== 'none',
|
|
154
|
+
border: options['card.border'] !== 'none',
|
|
155
|
+
caption: options['caption.mode'] !== 'none',
|
|
156
|
+
customCaption: options['caption.mode'] === 'custom',
|
|
157
|
+
solveGaps: options.solveGaps,
|
|
158
|
+
arrow: ['start', 'end', 'middle'].some((part) =>
|
|
159
|
+
['arrow', 'triangle', 'tail'].includes(options[`${part}.shape`])
|
|
160
|
+
),
|
|
161
|
+
};
|
|
162
|
+
if (!rule.startsWith('marker:')) {
|
|
163
|
+
return predicates[rule] ?? false;
|
|
164
|
+
}
|
|
165
|
+
const [, part, key] = rule.split(':');
|
|
166
|
+
const shape = options[`${part}.shape`];
|
|
167
|
+
if (shape === 'none') {
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
if (key === 'angle') {
|
|
171
|
+
return ['arrow', 'triangle', 'tail'].includes(shape);
|
|
172
|
+
}
|
|
173
|
+
return key !== 'rotation' || !['dot', 'circle'].includes(shape);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** Structured fields are edited by the link cards or supplied by a solver. */
|
|
177
|
+
export const networkOverrideSchema = Object.freeze(
|
|
178
|
+
[
|
|
179
|
+
{
|
|
180
|
+
key: 'turns',
|
|
181
|
+
type: 'per-link-vector',
|
|
182
|
+
min: -180,
|
|
183
|
+
max: 180,
|
|
184
|
+
step: 1,
|
|
185
|
+
default: '0 0',
|
|
186
|
+
section: 'links',
|
|
187
|
+
availability: 'always',
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
key: 'linkGaps',
|
|
191
|
+
type: 'per-link-vector',
|
|
192
|
+
min: '0 0 0 0',
|
|
193
|
+
max: '1 1 30 30',
|
|
194
|
+
step: 0.01,
|
|
195
|
+
default: '~ ~ ~ ~',
|
|
196
|
+
section: 'links',
|
|
197
|
+
availability: 'always',
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
key: 'linkColors',
|
|
201
|
+
type: 'per-link-color',
|
|
202
|
+
default: '~',
|
|
203
|
+
section: 'links',
|
|
204
|
+
availability: 'always',
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
key: 'frame',
|
|
208
|
+
type: 'vector',
|
|
209
|
+
min: '0.000000001 -1000000 -1000000',
|
|
210
|
+
max: '60 1000000 1000000',
|
|
211
|
+
default: '~',
|
|
212
|
+
section: 'geometry',
|
|
213
|
+
availability: 'always',
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
key: 'order',
|
|
217
|
+
type: 'permutation',
|
|
218
|
+
min: 1,
|
|
219
|
+
default: '~',
|
|
220
|
+
section: 'layout',
|
|
221
|
+
availability: 'circle',
|
|
222
|
+
},
|
|
223
|
+
].map(Object.freeze)
|
|
224
|
+
);
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { formatLinks } from '@link-foundation/ui-core';
|
|
2
|
+
import { element, button, field } from './dom.js';
|
|
3
|
+
|
|
4
|
+
export function networkFilename(code, extension) {
|
|
5
|
+
const suffix = `.${extension}`;
|
|
6
|
+
return (
|
|
7
|
+
`links-network-${String(code).replace(/[^\p{L}\p{N}_,;-]/gu, '-')}`.slice(
|
|
8
|
+
0,
|
|
9
|
+
160 - suffix.length
|
|
10
|
+
) + suffix
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
export function networkShareTargets(url, title = 'Links network') {
|
|
14
|
+
const u = encodeURIComponent(url),
|
|
15
|
+
t = encodeURIComponent(title);
|
|
16
|
+
return {
|
|
17
|
+
X: `https://twitter.com/intent/tweet?url=${u}&text=${t}`,
|
|
18
|
+
Telegram: `https://t.me/share/url?url=${u}&text=${t}`,
|
|
19
|
+
VK: `https://vk.com/share.php?url=${u}&title=${t}`,
|
|
20
|
+
Facebook: `https://www.facebook.com/sharer/sharer.php?u=${u}`,
|
|
21
|
+
LinkedIn: `https://www.linkedin.com/sharing/share-offsite/?url=${u}`,
|
|
22
|
+
Reddit: `https://www.reddit.com/submit?url=${u}&title=${t}`,
|
|
23
|
+
Bluesky: `https://bsky.app/intent/compose?text=${t}%20${u}`,
|
|
24
|
+
Mastodon: `https://mastodon.social/share?text=${t}%20${u}`,
|
|
25
|
+
WhatsApp: `https://wa.me/?text=${t}%20${u}`,
|
|
26
|
+
'e-mail': `mailto:?subject=${t}&body=${u}`,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** All export actions use the presentation's captured SVG/raster backend. */
|
|
31
|
+
export function createNetworkShare(
|
|
32
|
+
parent,
|
|
33
|
+
{
|
|
34
|
+
presentation,
|
|
35
|
+
getState,
|
|
36
|
+
getUrl,
|
|
37
|
+
announce,
|
|
38
|
+
window: win = parent.ownerDocument.defaultView,
|
|
39
|
+
}
|
|
40
|
+
) {
|
|
41
|
+
const doc = parent.ownerDocument;
|
|
42
|
+
const panel = element(doc, 'fieldset', undefined, parent);
|
|
43
|
+
element(doc, 'legend', 'Share', panel);
|
|
44
|
+
const urlInput = field(doc, panel, 'Network URL');
|
|
45
|
+
urlInput.readOnly = true;
|
|
46
|
+
const links = targetLinks(doc, panel);
|
|
47
|
+
let busy = false,
|
|
48
|
+
timer,
|
|
49
|
+
prepared,
|
|
50
|
+
generation = 0,
|
|
51
|
+
disposed = false;
|
|
52
|
+
const exports = [];
|
|
53
|
+
const actionButton = (label, action) =>
|
|
54
|
+
button(doc, panel, label, () => {
|
|
55
|
+
try {
|
|
56
|
+
action();
|
|
57
|
+
} catch (error) {
|
|
58
|
+
announce(error.message, true);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
const report = (task) =>
|
|
62
|
+
Promise.resolve(task).then(
|
|
63
|
+
() => announce('Done'),
|
|
64
|
+
(error) => announce(error.message, true)
|
|
65
|
+
);
|
|
66
|
+
const raster = (type) => {
|
|
67
|
+
const options = getState().options;
|
|
68
|
+
return presentation.toRaster(type, {
|
|
69
|
+
width: options.width,
|
|
70
|
+
height: options.height,
|
|
71
|
+
background: options['background.color'],
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
const exportBlob = blobFactory(presentation, getState, win, raster);
|
|
75
|
+
for (const extension of ['svg', 'png', 'jpg', 'webp', 'lino']) {
|
|
76
|
+
exports.push(
|
|
77
|
+
actionButton(
|
|
78
|
+
`Download ${extension === 'jpg' ? 'JPEG' : extension.toUpperCase()}`,
|
|
79
|
+
() => {
|
|
80
|
+
const code = getState().code;
|
|
81
|
+
report(
|
|
82
|
+
exportBlob(extension).then((blob) => {
|
|
83
|
+
const url = win.URL.createObjectURL(blob);
|
|
84
|
+
const anchor = element(doc, 'a', undefined, panel);
|
|
85
|
+
anchor.href = url;
|
|
86
|
+
anchor.download = networkFilename(code, extension);
|
|
87
|
+
anchor.click();
|
|
88
|
+
anchor.remove();
|
|
89
|
+
win.setTimeout(() => win.URL.revokeObjectURL(url), 0);
|
|
90
|
+
})
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
)
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
exports.push(
|
|
97
|
+
actionButton('Copy link', () =>
|
|
98
|
+
report(win.navigator.clipboard.writeText(getUrl()))
|
|
99
|
+
)
|
|
100
|
+
);
|
|
101
|
+
exports.push(
|
|
102
|
+
actionButton('Copy SVG', () =>
|
|
103
|
+
report(win.navigator.clipboard.writeText(presentation.toSvg()))
|
|
104
|
+
)
|
|
105
|
+
);
|
|
106
|
+
const copyImage = actionButton('Copy image', () => {
|
|
107
|
+
// Construct the ClipboardItem in this click's synchronous activation stack.
|
|
108
|
+
try {
|
|
109
|
+
const item = new win.ClipboardItem({ 'image/png': raster('image/png') });
|
|
110
|
+
report(win.navigator.clipboard.write([item]));
|
|
111
|
+
} catch (error) {
|
|
112
|
+
announce(error.message, true);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
exports.push(copyImage);
|
|
116
|
+
const share = actionButton('Share', () =>
|
|
117
|
+
webShare(win, prepared, getUrl(), report, announce)
|
|
118
|
+
);
|
|
119
|
+
exports.push(share);
|
|
120
|
+
function refresh() {
|
|
121
|
+
const url = getUrl();
|
|
122
|
+
urlInput.value = url;
|
|
123
|
+
for (const [name, href] of Object.entries(networkShareTargets(url))) {
|
|
124
|
+
links[name].href = href;
|
|
125
|
+
}
|
|
126
|
+
prepared = undefined;
|
|
127
|
+
const job = ++generation;
|
|
128
|
+
win.clearTimeout(timer);
|
|
129
|
+
if (busy || disposed) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
timer = win.setTimeout(() => {
|
|
133
|
+
const code = getState().code;
|
|
134
|
+
Promise.resolve()
|
|
135
|
+
.then(() => raster('image/png'))
|
|
136
|
+
.then((blob) => {
|
|
137
|
+
if (!disposed && job === generation) {
|
|
138
|
+
prepared = new win.File([blob], networkFilename(code, 'png'), {
|
|
139
|
+
type: 'image/png',
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
})
|
|
143
|
+
.catch((error) => {
|
|
144
|
+
if (job === generation) {
|
|
145
|
+
announce(error.message, true);
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
}, 200);
|
|
149
|
+
}
|
|
150
|
+
return {
|
|
151
|
+
refresh,
|
|
152
|
+
setBusy(value) {
|
|
153
|
+
busy = value;
|
|
154
|
+
for (const node of exports) {
|
|
155
|
+
node.disabled = busy;
|
|
156
|
+
}
|
|
157
|
+
copyImage.disabled =
|
|
158
|
+
busy || !win.ClipboardItem || !win.navigator.clipboard?.write;
|
|
159
|
+
refresh();
|
|
160
|
+
},
|
|
161
|
+
dispose() {
|
|
162
|
+
disposed = true;
|
|
163
|
+
++generation;
|
|
164
|
+
win.clearTimeout(timer);
|
|
165
|
+
panel.remove();
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function blobFactory(presentation, getState, win, raster) {
|
|
171
|
+
return (extension) => {
|
|
172
|
+
if (extension === 'svg') {
|
|
173
|
+
return Promise.resolve(
|
|
174
|
+
new win.Blob([presentation.toSvg()], { type: 'image/svg+xml' })
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
if (extension === 'lino') {
|
|
178
|
+
const lines = formatLinks(
|
|
179
|
+
getState().links.map(([s, t], i) => ({
|
|
180
|
+
id: String(i + 1),
|
|
181
|
+
values: [String(s), String(t)],
|
|
182
|
+
}))
|
|
183
|
+
);
|
|
184
|
+
return Promise.resolve(
|
|
185
|
+
new win.Blob([lines], { type: 'text/plain;charset=utf-8' })
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
return raster(`image/${extension === 'jpg' ? 'jpeg' : extension}`);
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function targetLinks(doc, panel) {
|
|
193
|
+
const targets = element(doc, 'nav', undefined, panel);
|
|
194
|
+
targets.setAttribute('aria-label', 'Share targets');
|
|
195
|
+
return Object.fromEntries(
|
|
196
|
+
Object.keys(networkShareTargets('')).map((name) => {
|
|
197
|
+
const node = element(doc, 'a', name, targets);
|
|
198
|
+
node.target = '_blank';
|
|
199
|
+
node.rel = 'noopener noreferrer';
|
|
200
|
+
return [name, node];
|
|
201
|
+
})
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function webShare(win, prepared, url, report, announce) {
|
|
206
|
+
const payload =
|
|
207
|
+
prepared && win.navigator.canShare?.({ files: [prepared] })
|
|
208
|
+
? { files: [prepared], title: 'Links network', url }
|
|
209
|
+
: { title: 'Links network', url };
|
|
210
|
+
if (!win.navigator.share) {
|
|
211
|
+
report(
|
|
212
|
+
win.navigator.clipboard?.writeText(url) ??
|
|
213
|
+
Promise.reject(new Error('Sharing unavailable'))
|
|
214
|
+
);
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
try {
|
|
218
|
+
report(
|
|
219
|
+
win.navigator.share(payload).catch((error) => {
|
|
220
|
+
if (payload.files && error.name !== 'AbortError') {
|
|
221
|
+
return win.navigator.share({
|
|
222
|
+
title: 'Links network',
|
|
223
|
+
url,
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
throw error;
|
|
227
|
+
})
|
|
228
|
+
);
|
|
229
|
+
} catch (error) {
|
|
230
|
+
announce(error.message, true);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export const CSS = `
|
|
2
|
+
.network-editor {font: 15px/1.5 system-ui,sans-serif;color:var(--network-editor-fg,#18202b);background:var(--network-editor-bg,#fff);padding:1rem;display:grid;gap:1rem}
|
|
3
|
+
.network-editor fieldset {min-width:0;border:1px solid #77818d;border-radius:.5rem;padding:1rem;display:flex;flex-wrap:wrap;gap:.75rem;align-items:start}
|
|
4
|
+
.network-editor legend {font-weight:650;padding:0 .4rem}
|
|
5
|
+
.network-editor label {display:flex;flex-direction:column;gap:.25rem;min-width:10rem;max-width:100%}
|
|
6
|
+
.network-editor input,.network-editor select,.network-editor button {font:inherit;max-width:100%;box-sizing:border-box;min-height:2.5rem}
|
|
7
|
+
.network-editor input:not([type=checkbox]):not([type=color]),.network-editor select {width:100%}
|
|
8
|
+
.network-editor input[type=checkbox] {align-self:start}
|
|
9
|
+
.network-editor button {cursor:pointer;padding:.35rem .7rem}
|
|
10
|
+
.network-editor button:disabled {cursor:default}
|
|
11
|
+
.network-editor :focus-visible {outline:3px solid #235bd6;outline-offset:2px}
|
|
12
|
+
.network-editor [aria-invalid=true] {outline:2px solid #b00020}
|
|
13
|
+
.network-editor [role=alert] {color:#b00020}
|
|
14
|
+
.network-editor nav {display:flex;flex-wrap:wrap;gap:1rem;width:100%}
|
|
15
|
+
.network-editor nav a {color:inherit;text-decoration:underline}
|
|
16
|
+
.network-editor [hidden] {display:none!important}
|
|
17
|
+
.network-editor p {width:100%;margin:0}
|
|
18
|
+
@media(prefers-color-scheme:dark) {.network-editor {--network-editor-fg:#f3f4f6;--network-editor-bg:#151b24;color-scheme:dark}.network-editor [role=alert]{color:#ffb4bd}}
|
|
19
|
+
`;
|