@link-foundation/ui-components 0.0.0-stage → 0.0.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,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `renderLinkSvg(geometry, style)`: one link as SVG text. The output only
|
|
3
|
+
* depends on the arguments (numbers are rounded, attributes are written in
|
|
4
|
+
* a fixed order), so two calls give the same string. The marker shapes come
|
|
5
|
+
* from `markers.js`, as for the Canvas renderer.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { fmt, pathToSvgD } from './geometry.js';
|
|
9
|
+
import {
|
|
10
|
+
escapeAttribute,
|
|
11
|
+
getMarker,
|
|
12
|
+
markerElementId,
|
|
13
|
+
svgMarkerDefs,
|
|
14
|
+
} from './markers.js';
|
|
15
|
+
import { buildScene } from './scene.js';
|
|
16
|
+
|
|
17
|
+
/** The SVG path data of a list of line segments. */
|
|
18
|
+
const segmentsD = (segments) =>
|
|
19
|
+
segments
|
|
20
|
+
.map((s) => `M ${fmt(s.x1)} ${fmt(s.y1)} L ${fmt(s.x2)} ${fmt(s.y2)}`)
|
|
21
|
+
.join(' ');
|
|
22
|
+
|
|
23
|
+
const attr = (value) => escapeAttribute(value);
|
|
24
|
+
|
|
25
|
+
function gridSvg(grid) {
|
|
26
|
+
if (grid === null) {
|
|
27
|
+
return '';
|
|
28
|
+
}
|
|
29
|
+
const part = (segments, color, width, name) =>
|
|
30
|
+
segments.length === 0
|
|
31
|
+
? ''
|
|
32
|
+
: `<path data-part="grid-${name}" d="${segmentsD(segments)}" fill="none" stroke="${attr(color)}" stroke-width="${fmt(width)}"/>`;
|
|
33
|
+
return [
|
|
34
|
+
part(grid.minor, grid.minorColor, grid.minorWidth, 'minor'),
|
|
35
|
+
part(grid.major, grid.majorColor, grid.majorWidth, 'major'),
|
|
36
|
+
].join('');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function blueprintSvg(blueprint) {
|
|
40
|
+
if (blueprint === null) {
|
|
41
|
+
return '';
|
|
42
|
+
}
|
|
43
|
+
const dash = blueprint.dash.join(' ');
|
|
44
|
+
const guide = blueprint.guide.points
|
|
45
|
+
.map((p) => `${fmt(p.x)},${fmt(p.y)}`)
|
|
46
|
+
.join(' ');
|
|
47
|
+
const circles = blueprint.points
|
|
48
|
+
.map(
|
|
49
|
+
(p) =>
|
|
50
|
+
`<circle data-role="${p.role}" cx="${fmt(p.at.x)}" cy="${fmt(p.at.y)}" r="${fmt(blueprint.radius)}" fill="none" stroke="${attr(p.color)}" stroke-width="${fmt(blueprint.strokeWidth)}" stroke-dasharray="${dash}"/>`
|
|
51
|
+
)
|
|
52
|
+
.join('');
|
|
53
|
+
return (
|
|
54
|
+
`<g data-part="blueprint"><polyline data-part="guide" points="${guide}" fill="none" ` +
|
|
55
|
+
`stroke="${attr(blueprint.guide.color)}" stroke-width="${fmt(blueprint.guide.width)}" stroke-dasharray="${dash}"/>${circles}</g>`
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** The `marker-start`/`marker-end` attributes of the line. */
|
|
60
|
+
function markerAttributes(ends, prefix) {
|
|
61
|
+
return ends
|
|
62
|
+
.map(({ end, shape }) => {
|
|
63
|
+
const marker = getMarker(shape);
|
|
64
|
+
if (marker === undefined || marker.path === '') {
|
|
65
|
+
return '';
|
|
66
|
+
}
|
|
67
|
+
const name = end === 'source' ? 'marker-start' : 'marker-end';
|
|
68
|
+
return ` ${name}="url(#${attr(markerElementId(prefix, end, marker.id))})"`;
|
|
69
|
+
})
|
|
70
|
+
.join('');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* The marker shape ids a scene draws (in source, target order), the same
|
|
75
|
+
* list `drawLinkCanvas` returns.
|
|
76
|
+
* @param {ReturnType<typeof buildScene>} scene
|
|
77
|
+
* @returns {string[]}
|
|
78
|
+
*/
|
|
79
|
+
export const drawnMarkers = (scene) =>
|
|
80
|
+
scene.ends
|
|
81
|
+
.map(({ shape }) => getMarker(shape))
|
|
82
|
+
.filter((m) => m !== undefined && m.path !== '')
|
|
83
|
+
.map((m) => m.id);
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* One link as an SVG document fragment (`<svg>…</svg>`).
|
|
87
|
+
* @param {import('./geometry.js').LinkGeometry} geometry
|
|
88
|
+
* @param {import('./scene.js').LinkStyle} style
|
|
89
|
+
* @returns {string}
|
|
90
|
+
*/
|
|
91
|
+
export function renderLinkSvg(geometry, style) {
|
|
92
|
+
const scene = buildScene(geometry, style);
|
|
93
|
+
const prefix = style.idPrefix ?? 'link';
|
|
94
|
+
const { width, height, view } = scene;
|
|
95
|
+
const ends = Object.fromEntries(scene.ends.map((e) => [e.end, e.shape]));
|
|
96
|
+
const colors = Object.fromEntries(scene.ends.map((e) => [e.end, e.color]));
|
|
97
|
+
const used = drawnMarkers(scene).join(' ');
|
|
98
|
+
const line = [
|
|
99
|
+
`<path data-part="line" d="${pathToSvgD(scene.line.path)}" fill="none"`,
|
|
100
|
+
`stroke="${attr(scene.line.color)}" stroke-width="${fmt(scene.line.width)}"`,
|
|
101
|
+
`stroke-linecap="butt" stroke-linejoin="round"${markerAttributes(scene.ends, prefix)}/>`,
|
|
102
|
+
].join(' ');
|
|
103
|
+
const svg = [
|
|
104
|
+
`<svg xmlns="http://www.w3.org/2000/svg" width="${fmt(width)}" height="${fmt(height)}"`,
|
|
105
|
+
`viewBox="0 0 ${fmt(width)} ${fmt(height)}" aria-hidden="true" focusable="false"`,
|
|
106
|
+
`data-markers="${used}">`,
|
|
107
|
+
].join(' ');
|
|
108
|
+
return [
|
|
109
|
+
svg,
|
|
110
|
+
`<defs>${svgMarkerDefs(ends, colors, { idPrefix: prefix })}</defs>`,
|
|
111
|
+
`<rect data-part="background" width="${fmt(width)}" height="${fmt(height)}" fill="${attr(scene.background)}"/>`,
|
|
112
|
+
`<g data-part="view" transform="translate(${fmt(view.x, 4)} ${fmt(view.y, 4)}) scale(${fmt(view.k, 6)})">`,
|
|
113
|
+
gridSvg(scene.grid),
|
|
114
|
+
line,
|
|
115
|
+
blueprintSvg(scene.blueprint),
|
|
116
|
+
'</g></svg>',
|
|
117
|
+
].join('');
|
|
118
|
+
}
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a link view draws, worked out once for both renderers: the view
|
|
3
|
+
* transform, the grid lines in the visible area, the line, the two marker
|
|
4
|
+
* ends and the blueprint points. The SVG and the Canvas renderer each turn
|
|
5
|
+
* the same scene into their own output, so they draw the same picture.
|
|
6
|
+
*
|
|
7
|
+
* Sizes follow links-visuals: the line is 0.085 of the grid step wide, the
|
|
8
|
+
* blueprint circles have a radius of 0.17 of the grid step, and the grid has
|
|
9
|
+
* a major line every step and a minor line every half step.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { endAngles, pathBounds } from './geometry.js';
|
|
13
|
+
|
|
14
|
+
/** The grid step in world units. */
|
|
15
|
+
export const GRID_SPACING = 20;
|
|
16
|
+
|
|
17
|
+
/** The line width as a fraction of the grid step (links-visuals). */
|
|
18
|
+
export const STROKE_FRACTION = 0.085;
|
|
19
|
+
|
|
20
|
+
/** The blueprint circle radius as a fraction of the grid step. */
|
|
21
|
+
export const RADIUS_FRACTION = 0.17;
|
|
22
|
+
|
|
23
|
+
/** The dash pattern of the blueprint circles and guide (world units). */
|
|
24
|
+
export const BLUEPRINT_DASH = Object.freeze([4, 2]);
|
|
25
|
+
|
|
26
|
+
/** Grid lines closer than this on screen (pixels) are left out. */
|
|
27
|
+
const MIN_GRID_PIXELS = 4;
|
|
28
|
+
|
|
29
|
+
/** The most grid lines drawn in one direction. */
|
|
30
|
+
const MAX_GRID_LINES = 4000;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @typedef {{x: number, y: number, k: number}} View screen = world · k +
|
|
34
|
+
* (x, y)
|
|
35
|
+
* @typedef {{x1: number, y1: number, x2: number, y2: number}} Segment
|
|
36
|
+
* @typedef {object} LinkStyle
|
|
37
|
+
* @property {number} width in CSS pixels
|
|
38
|
+
* @property {number} height
|
|
39
|
+
* @property {View} [view] default: identity
|
|
40
|
+
* @property {Readonly<Record<string, string>>} colors from `linkColors`
|
|
41
|
+
* @property {{source?: string, target?: string}} [ends] marker shapes
|
|
42
|
+
* @property {boolean} [blueprint]
|
|
43
|
+
* @property {boolean} [grid]
|
|
44
|
+
* @property {number} [gridSpacing]
|
|
45
|
+
* @property {number} [lineWidth] world units (default from the grid step)
|
|
46
|
+
* @property {string} [idPrefix] makes the SVG marker ids unique
|
|
47
|
+
* @property {number} [pixelRatio] canvas pixels per CSS pixel
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
/** The lines of one grid direction inside [min, max]. */
|
|
51
|
+
function gridValues(min, max, step) {
|
|
52
|
+
const first = Math.ceil(min / step);
|
|
53
|
+
const last = Math.floor(max / step);
|
|
54
|
+
const values = [];
|
|
55
|
+
for (let i = first; i <= last && values.length < MAX_GRID_LINES; i += 1) {
|
|
56
|
+
values.push(i);
|
|
57
|
+
}
|
|
58
|
+
return values;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The grid lines in the visible world rectangle: major lines every step,
|
|
63
|
+
* minor lines every half step in between.
|
|
64
|
+
* @param {{minX: number, minY: number, maxX: number, maxY: number}} area
|
|
65
|
+
* @param {number} spacing
|
|
66
|
+
* @param {number} k the zoom, to drop lines that would be too dense
|
|
67
|
+
* @returns {{minor: Segment[], major: Segment[]}}
|
|
68
|
+
*/
|
|
69
|
+
export function gridLines(area, spacing, k) {
|
|
70
|
+
const half = spacing / 2;
|
|
71
|
+
const minor = [];
|
|
72
|
+
const major = [];
|
|
73
|
+
if (half * k < MIN_GRID_PIXELS && spacing * k < MIN_GRID_PIXELS) {
|
|
74
|
+
return { minor, major };
|
|
75
|
+
}
|
|
76
|
+
const withMinor = half * k >= MIN_GRID_PIXELS;
|
|
77
|
+
for (const i of gridValues(area.minX, area.maxX, half)) {
|
|
78
|
+
const x = i * half;
|
|
79
|
+
const list = i % 2 === 0 ? major : minor;
|
|
80
|
+
if (list === major || withMinor) {
|
|
81
|
+
list.push({ x1: x, y1: area.minY, x2: x, y2: area.maxY });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
for (const i of gridValues(area.minY, area.maxY, half)) {
|
|
85
|
+
const y = i * half;
|
|
86
|
+
const list = i % 2 === 0 ? major : minor;
|
|
87
|
+
if (list === major || withMinor) {
|
|
88
|
+
list.push({ x1: area.minX, y1: y, x2: area.maxX, y2: y });
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return { minor, major };
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** The world rectangle a view shows in a `width × height` viewport. */
|
|
95
|
+
export function visibleArea(view, width, height) {
|
|
96
|
+
return {
|
|
97
|
+
minX: -view.x / view.k,
|
|
98
|
+
minY: -view.y / view.k,
|
|
99
|
+
maxX: (width - view.x) / view.k,
|
|
100
|
+
maxY: (height - view.y) / view.k,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** The colour of each blueprint point (links-visuals roles). */
|
|
105
|
+
function pointColor(index, count, colors) {
|
|
106
|
+
if (index === 0) {
|
|
107
|
+
return colors.blueprintStart;
|
|
108
|
+
}
|
|
109
|
+
if (index === count - 1) {
|
|
110
|
+
return colors.blueprintEnd;
|
|
111
|
+
}
|
|
112
|
+
if (index === (count - 1) / 2) {
|
|
113
|
+
return colors.blueprintCenter;
|
|
114
|
+
}
|
|
115
|
+
return colors.blueprintPoint;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** The role of each blueprint point, for tests and data attributes. */
|
|
119
|
+
function pointRole(index, count) {
|
|
120
|
+
if (index === 0) {
|
|
121
|
+
return 'start';
|
|
122
|
+
}
|
|
123
|
+
if (index === count - 1) {
|
|
124
|
+
return 'end';
|
|
125
|
+
}
|
|
126
|
+
return index === (count - 1) / 2 ? 'center' : 'point';
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* The scene of one link.
|
|
131
|
+
* @param {import('./geometry.js').LinkGeometry} geometry
|
|
132
|
+
* @param {LinkStyle} style
|
|
133
|
+
*/
|
|
134
|
+
export function buildScene(geometry, style) {
|
|
135
|
+
const spacing = style.gridSpacing ?? GRID_SPACING;
|
|
136
|
+
const view = style.view ?? { x: 0, y: 0, k: 1 };
|
|
137
|
+
const colors = style.colors;
|
|
138
|
+
const lineWidth = style.lineWidth ?? STROKE_FRACTION * spacing;
|
|
139
|
+
const angles = endAngles(geometry.path);
|
|
140
|
+
const ends = { source: 'bar', target: 'arrow', ...style.ends };
|
|
141
|
+
const count = geometry.points.length;
|
|
142
|
+
return {
|
|
143
|
+
width: style.width,
|
|
144
|
+
height: style.height,
|
|
145
|
+
view,
|
|
146
|
+
background: colors.background,
|
|
147
|
+
grid:
|
|
148
|
+
style.grid === true
|
|
149
|
+
? {
|
|
150
|
+
...gridLines(
|
|
151
|
+
visibleArea(view, style.width, style.height),
|
|
152
|
+
spacing,
|
|
153
|
+
view.k
|
|
154
|
+
),
|
|
155
|
+
minorColor: colors.gridMinor,
|
|
156
|
+
majorColor: colors.gridMajor,
|
|
157
|
+
minorWidth: 0.5,
|
|
158
|
+
majorWidth: 1,
|
|
159
|
+
}
|
|
160
|
+
: null,
|
|
161
|
+
line: { path: geometry.path, width: lineWidth, color: colors.line },
|
|
162
|
+
ends: [
|
|
163
|
+
{
|
|
164
|
+
end: 'source',
|
|
165
|
+
shape: ends.source,
|
|
166
|
+
at: geometry.path[0]?.p0 ?? geometry.source,
|
|
167
|
+
angle: angles.start,
|
|
168
|
+
color: colors.source,
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
end: 'target',
|
|
172
|
+
shape: ends.target,
|
|
173
|
+
at: geometry.path.at(-1)?.p3 ?? geometry.target,
|
|
174
|
+
angle: angles.end,
|
|
175
|
+
color: colors.target,
|
|
176
|
+
},
|
|
177
|
+
],
|
|
178
|
+
blueprint:
|
|
179
|
+
style.blueprint === true
|
|
180
|
+
? {
|
|
181
|
+
radius: RADIUS_FRACTION * spacing,
|
|
182
|
+
strokeWidth: 1,
|
|
183
|
+
dash: BLUEPRINT_DASH,
|
|
184
|
+
guide: {
|
|
185
|
+
points: geometry.points,
|
|
186
|
+
color: colors.blueprintGuide,
|
|
187
|
+
width: 0.5,
|
|
188
|
+
},
|
|
189
|
+
points: geometry.points.map((at, i) => ({
|
|
190
|
+
at,
|
|
191
|
+
role: pointRole(i, count),
|
|
192
|
+
color: pointColor(i, count, colors),
|
|
193
|
+
})),
|
|
194
|
+
}
|
|
195
|
+
: null,
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* The world bounds of what a link draws, with room for its markers and
|
|
201
|
+
* blueprint circles.
|
|
202
|
+
* @param {import('./geometry.js').LinkGeometry} geometry
|
|
203
|
+
* @param {{gridSpacing?: number}} [options]
|
|
204
|
+
*/
|
|
205
|
+
export function sceneBounds(geometry, { gridSpacing = GRID_SPACING } = {}) {
|
|
206
|
+
const b = pathBounds(geometry.path);
|
|
207
|
+
const pad = gridSpacing * 1.5;
|
|
208
|
+
return {
|
|
209
|
+
minX: b.minX - pad,
|
|
210
|
+
minY: b.minY - pad,
|
|
211
|
+
maxX: b.maxX + pad,
|
|
212
|
+
maxY: b.maxY + pad,
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* The view that fits world bounds into a viewport, centred.
|
|
218
|
+
* @param {{minX: number, minY: number, maxX: number, maxY: number}} bounds
|
|
219
|
+
* @param {number} width
|
|
220
|
+
* @param {number} height
|
|
221
|
+
* @param {{min?: number, max?: number}} [limits] zoom limits
|
|
222
|
+
* @returns {View}
|
|
223
|
+
*/
|
|
224
|
+
export function fitView(bounds, width, height, { min = 0.1, max = 20 } = {}) {
|
|
225
|
+
const bw = Math.max(1e-9, bounds.maxX - bounds.minX);
|
|
226
|
+
const bh = Math.max(1e-9, bounds.maxY - bounds.minY);
|
|
227
|
+
const k = Math.min(max, Math.max(min, Math.min(width / bw, height / bh)));
|
|
228
|
+
return {
|
|
229
|
+
x: width / 2 - ((bounds.minX + bounds.maxX) / 2) * k,
|
|
230
|
+
y: height / 2 - ((bounds.minY + bounds.maxY) / 2) * k,
|
|
231
|
+
k,
|
|
232
|
+
};
|
|
233
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wrap a solver in a cancellable job. A supplied worker entry must install the
|
|
3
|
+
* same solver with installSolverWorker. Without a worker URL or Worker support,
|
|
4
|
+
* invoke the solver on this thread; synchronous CPU work cannot be interrupted.
|
|
5
|
+
* Each worker handles exactly one request and is terminated on every exit path.
|
|
6
|
+
*
|
|
7
|
+
* @template Result
|
|
8
|
+
* @param {function(Array, object, {signal: AbortSignal}): Result | Promise<Result>} solve
|
|
9
|
+
* @param {{workerUrl?: string | URL, Worker?: typeof globalThis.Worker}} [configuration]
|
|
10
|
+
*/
|
|
11
|
+
export function createSolverJob(solve, configuration = {}) {
|
|
12
|
+
const Worker = Object.hasOwn(configuration, 'Worker')
|
|
13
|
+
? configuration.Worker
|
|
14
|
+
: globalThis.Worker;
|
|
15
|
+
return (links, options = {}, { signal } = {}) =>
|
|
16
|
+
new Promise((resolve, reject) => {
|
|
17
|
+
let worker;
|
|
18
|
+
let finished = false;
|
|
19
|
+
const finish = (error, result) => {
|
|
20
|
+
if (finished) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
finished = true;
|
|
24
|
+
signal?.removeEventListener('abort', abort);
|
|
25
|
+
if (worker) {
|
|
26
|
+
worker.removeEventListener('message', message);
|
|
27
|
+
worker.removeEventListener('error', failure);
|
|
28
|
+
worker.removeEventListener('messageerror', failure);
|
|
29
|
+
worker.terminate();
|
|
30
|
+
}
|
|
31
|
+
if (error) {
|
|
32
|
+
reject(error);
|
|
33
|
+
} else {
|
|
34
|
+
resolve(result);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
const fail = (error) =>
|
|
38
|
+
finish(error instanceof Error ? error : new Error(String(error)));
|
|
39
|
+
const abort = () =>
|
|
40
|
+
finish(
|
|
41
|
+
Object.assign(new Error('Solver cancelled'), { name: 'AbortError' })
|
|
42
|
+
);
|
|
43
|
+
const failure = (event) =>
|
|
44
|
+
finish(new Error(event.message || 'Solver worker failed'));
|
|
45
|
+
const message = ({ data }) => {
|
|
46
|
+
if (data?.error) {
|
|
47
|
+
finish(
|
|
48
|
+
Object.assign(new Error(data.error.message), {
|
|
49
|
+
name: data.error.name,
|
|
50
|
+
})
|
|
51
|
+
);
|
|
52
|
+
} else if (data && Object.hasOwn(data, 'result')) {
|
|
53
|
+
finish(null, data.result);
|
|
54
|
+
} else {
|
|
55
|
+
finish(new Error('Invalid solver worker response'));
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
if (signal?.aborted) {
|
|
59
|
+
abort();
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
signal?.addEventListener('abort', abort, { once: true });
|
|
63
|
+
try {
|
|
64
|
+
// Match structured-clone isolation in both execution modes. AbortSignal
|
|
65
|
+
// is a local control channel and is never sent through postMessage.
|
|
66
|
+
const input = globalThis.structuredClone({ links, options });
|
|
67
|
+
if (Worker && configuration.workerUrl) {
|
|
68
|
+
worker = new Worker(configuration.workerUrl, { type: 'module' });
|
|
69
|
+
worker.addEventListener('message', message);
|
|
70
|
+
worker.addEventListener('error', failure);
|
|
71
|
+
worker.addEventListener('messageerror', failure);
|
|
72
|
+
worker.postMessage(input);
|
|
73
|
+
} else {
|
|
74
|
+
Promise.resolve(
|
|
75
|
+
solve(input.links, input.options, {
|
|
76
|
+
signal: signal ?? new AbortController().signal,
|
|
77
|
+
})
|
|
78
|
+
).then(
|
|
79
|
+
(result) => finish(null, result),
|
|
80
|
+
(error) => fail(error)
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
} catch (error) {
|
|
84
|
+
fail(error);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Install in a module worker entry that imports the actual solver. */
|
|
90
|
+
export function installSolverWorker(scope, solve) {
|
|
91
|
+
scope.addEventListener('message', async ({ data }) => {
|
|
92
|
+
try {
|
|
93
|
+
const result = await solve(data.links, data.options, {
|
|
94
|
+
signal: new AbortController().signal,
|
|
95
|
+
});
|
|
96
|
+
scope.postMessage({ result });
|
|
97
|
+
} catch (error) {
|
|
98
|
+
scope.postMessage({
|
|
99
|
+
error: {
|
|
100
|
+
name: error?.name || 'Error',
|
|
101
|
+
message: error?.message || String(error),
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The colours of a link view, as ui-tokens design tokens written in Links
|
|
3
|
+
* Notation (`color.link.*`), with a `dark` mode. The renderers take every
|
|
4
|
+
* colour from here (or from the `--color-link-*` CSS custom properties that
|
|
5
|
+
* override these tokens on a page), never from their own code.
|
|
6
|
+
*
|
|
7
|
+
* The blueprint colours follow links-visuals: the start point green, the end
|
|
8
|
+
* red, the centre black (the line colour in dark mode) and the other points
|
|
9
|
+
* blue, all at least 3:1 against the background (WCAG 2.2, 1.4.11).
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { values } from '@link-foundation/ui-core';
|
|
13
|
+
import {
|
|
14
|
+
cssVariable,
|
|
15
|
+
readTokens,
|
|
16
|
+
resolveTokens,
|
|
17
|
+
} from '@link-foundation/ui-tokens';
|
|
18
|
+
|
|
19
|
+
/** The token set of a link view (`link-view` theme), light and dark. */
|
|
20
|
+
export const LINK_TOKENS = `link-view: theme
|
|
21
|
+
token color.link.background '#E0F7FA'
|
|
22
|
+
description 'Behind the link and the grid.'
|
|
23
|
+
token color.link.line '#263238'
|
|
24
|
+
description 'The line of a link.'
|
|
25
|
+
token color.link.source
|
|
26
|
+
token color.link.line
|
|
27
|
+
description 'The marker at the source end.'
|
|
28
|
+
token color.link.target
|
|
29
|
+
token color.link.line
|
|
30
|
+
description 'The marker at the target end.'
|
|
31
|
+
token color.link.grid.minor '#FFFFFF80'
|
|
32
|
+
description 'The grid lines every half step.'
|
|
33
|
+
token color.link.grid.major '#FFFFFFCC'
|
|
34
|
+
description 'The grid lines every step.'
|
|
35
|
+
token color.link.blueprint.start '#2E7D32'
|
|
36
|
+
description 'The first blueprint point.'
|
|
37
|
+
token color.link.blueprint.end '#C62828'
|
|
38
|
+
description 'The last blueprint point.'
|
|
39
|
+
token color.link.blueprint.center '#000000'
|
|
40
|
+
description 'The blueprint point at the centre.'
|
|
41
|
+
token color.link.blueprint.point '#1565C0'
|
|
42
|
+
description 'The other blueprint points.'
|
|
43
|
+
token color.link.blueprint.guide '#1565C0'
|
|
44
|
+
description 'The dashed guide through the points.'
|
|
45
|
+
token color.link.focus '#1565C0'
|
|
46
|
+
description 'The focus ring of a link view.'
|
|
47
|
+
mode dark
|
|
48
|
+
token color.link.background '#0B1F24'
|
|
49
|
+
token color.link.line '#ECEFF1'
|
|
50
|
+
token color.link.grid.minor '#FFFFFF1F'
|
|
51
|
+
token color.link.grid.major '#FFFFFF47'
|
|
52
|
+
token color.link.blueprint.start '#81C784'
|
|
53
|
+
token color.link.blueprint.end '#EF9A9A'
|
|
54
|
+
token color.link.blueprint.center
|
|
55
|
+
token color.link.line
|
|
56
|
+
token color.link.blueprint.point '#64B5F6'
|
|
57
|
+
token color.link.blueprint.guide '#64B5F6'
|
|
58
|
+
token color.link.focus '#90CAF9'`;
|
|
59
|
+
|
|
60
|
+
/** The token path of each colour role the renderers use. */
|
|
61
|
+
export const COLOR_TOKENS = Object.freeze({
|
|
62
|
+
background: 'color.link.background',
|
|
63
|
+
line: 'color.link.line',
|
|
64
|
+
source: 'color.link.source',
|
|
65
|
+
target: 'color.link.target',
|
|
66
|
+
gridMinor: 'color.link.grid.minor',
|
|
67
|
+
gridMajor: 'color.link.grid.major',
|
|
68
|
+
blueprintStart: 'color.link.blueprint.start',
|
|
69
|
+
blueprintEnd: 'color.link.blueprint.end',
|
|
70
|
+
blueprintCenter: 'color.link.blueprint.center',
|
|
71
|
+
blueprintPoint: 'color.link.blueprint.point',
|
|
72
|
+
blueprintGuide: 'color.link.blueprint.guide',
|
|
73
|
+
focus: 'color.link.focus',
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* @typedef {Readonly<Record<keyof typeof COLOR_TOKENS, string>>} LinkColors
|
|
78
|
+
*/
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* The colours of a link view in a mode, as CSS colour text.
|
|
82
|
+
* @param {{mode?: 'light'|'dark'|null, tokens?: string}} [options] `tokens`
|
|
83
|
+
* replaces the built-in token set (it must define the `link-view` theme)
|
|
84
|
+
* @returns {LinkColors}
|
|
85
|
+
*/
|
|
86
|
+
export function linkColors({ mode = null, tokens = LINK_TOKENS } = {}) {
|
|
87
|
+
const { sets } = readTokens(tokens);
|
|
88
|
+
const resolved = resolveTokens(sets, 'link-view', {
|
|
89
|
+
mode: mode === 'light' ? null : mode,
|
|
90
|
+
});
|
|
91
|
+
const colors = {};
|
|
92
|
+
for (const [role, path] of Object.entries(COLOR_TOKENS)) {
|
|
93
|
+
const token = resolved.get(path);
|
|
94
|
+
if (token === undefined || token.type !== 'color') {
|
|
95
|
+
throw new Error(`linkColors: the token ${path} is not a colour`);
|
|
96
|
+
}
|
|
97
|
+
colors[role] = values.colorCss(token.value);
|
|
98
|
+
}
|
|
99
|
+
return Object.freeze(colors);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* The CSS custom property of each colour role (`--color-link-line`), the
|
|
104
|
+
* names ui-tokens `toCss` writes for the tokens.
|
|
105
|
+
* @param {string} [prefix]
|
|
106
|
+
* @returns {Readonly<Record<string, string>>}
|
|
107
|
+
*/
|
|
108
|
+
export function colorVariables(prefix = '') {
|
|
109
|
+
const names = {};
|
|
110
|
+
for (const [role, path] of Object.entries(COLOR_TOKENS)) {
|
|
111
|
+
names[role] = cssVariable(path, prefix);
|
|
112
|
+
}
|
|
113
|
+
return Object.freeze(names);
|
|
114
|
+
}
|