@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,215 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The icon registry: named icon sets, each a source that resolves a name
|
|
3
|
+
* to icon data and lists the asset records of what it can supply.
|
|
4
|
+
*
|
|
5
|
+
* The own set (`own`, CC0-1.0, assets/icons/own/) is always registered; a
|
|
6
|
+
* name that a set lacks falls back to the own set and then to a
|
|
7
|
+
* placeholder, so an icon never renders as nothing.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { DEFAULT_ICON_SET, MIRROR_IN_RTL } from './names.js';
|
|
11
|
+
import OWN_ICONS from './own-icons.js';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @typedef {object} AssetRecord an asset record of assets/assets.lino
|
|
15
|
+
* (scripts/lib/asset-records.mjs), as plain data
|
|
16
|
+
* @property {string} id
|
|
17
|
+
* @property {string} kind
|
|
18
|
+
* @property {string[]} files
|
|
19
|
+
* @property {string} license an SPDX expression
|
|
20
|
+
* @property {string} copyright `none` for our own public-domain icons
|
|
21
|
+
* @property {string} [source]
|
|
22
|
+
* @property {string} [notice]
|
|
23
|
+
* @property {'required'|'none'} [attribution]
|
|
24
|
+
* @property {string} [attributionText]
|
|
25
|
+
* @property {'yes'|'no'} [modified]
|
|
26
|
+
*
|
|
27
|
+
* @typedef {object} IconData
|
|
28
|
+
* @property {string} [title] library accessible name
|
|
29
|
+
* @property {string} viewBox
|
|
30
|
+
* @property {string} body SVG markup drawn in currentColor
|
|
31
|
+
* @property {boolean} mirrorInRtl flip horizontally in right-to-left text
|
|
32
|
+
* @property {AssetRecord|undefined} record the licence record of the icon
|
|
33
|
+
*
|
|
34
|
+
* @typedef {object} IconSource
|
|
35
|
+
* @property {(name: string) => Promise<IconData|undefined>} resolve
|
|
36
|
+
* @property {() => AssetRecord[]} records
|
|
37
|
+
*
|
|
38
|
+
* @typedef {string | {set?: string, name: string}} IconRef `close`,
|
|
39
|
+
* `lucide:check` or `{set: 'lucide', name: 'check'}`
|
|
40
|
+
*
|
|
41
|
+
* @typedef {object} StaticIconModule a module written by
|
|
42
|
+
* scripts/build-icons.mjs (`dist/icons/<set>.js`)
|
|
43
|
+
* @property {string} set
|
|
44
|
+
* @property {Record<string, {viewBox: string, body: string,
|
|
45
|
+
* mirrorInRtl?: boolean, record: string}>} icons
|
|
46
|
+
* @property {AssetRecord[]} records
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
/** Our own CC0-1.0 placeholder: a dashed square with a question mark. */
|
|
50
|
+
export const PLACEHOLDER_ICON = Object.freeze({
|
|
51
|
+
viewBox: '0 0 24 24',
|
|
52
|
+
body: '<g fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2" stroke-dasharray="3 3"/><path d="M9.5 9.5a2.5 2.5 0 1 1 3.5 2.3c-.6.3-1 .9-1 1.6V14M12 17h.01"/></g>',
|
|
53
|
+
mirrorInRtl: false,
|
|
54
|
+
record: undefined,
|
|
55
|
+
placeholder: true,
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
/** @type {Map<string, IconSource>} */
|
|
59
|
+
const sets = new Map();
|
|
60
|
+
/** @type {Set<(set: string) => void>} */
|
|
61
|
+
const listeners = new Set();
|
|
62
|
+
|
|
63
|
+
const checkSource = (set, source) => {
|
|
64
|
+
if (typeof set !== 'string' || set === '') {
|
|
65
|
+
throw new TypeError('registerIconSet: the set name must be a string');
|
|
66
|
+
}
|
|
67
|
+
if (
|
|
68
|
+
typeof source?.resolve !== 'function' ||
|
|
69
|
+
typeof source?.records !== 'function'
|
|
70
|
+
) {
|
|
71
|
+
throw new TypeError(
|
|
72
|
+
`registerIconSet(${set}): the source needs resolve(name) and records()`
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Register (or replace) an icon set. Rendered `ui-icon` elements of the
|
|
79
|
+
* set update. Each set keeps one source: registering a set again replaces
|
|
80
|
+
* the earlier source.
|
|
81
|
+
* @param {string} set
|
|
82
|
+
* @param {IconSource} source
|
|
83
|
+
* @returns {() => void} unregister the source again
|
|
84
|
+
*/
|
|
85
|
+
export function registerIconSet(set, source) {
|
|
86
|
+
checkSource(set, source);
|
|
87
|
+
sets.set(set, source);
|
|
88
|
+
listeners.forEach((listener) => listener(set));
|
|
89
|
+
return () => {
|
|
90
|
+
if (sets.get(set) !== source) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
// The own set is always there: unregistering a replacement restores it.
|
|
94
|
+
if (set === DEFAULT_ICON_SET) {
|
|
95
|
+
sets.set(set, OWN_SOURCE);
|
|
96
|
+
} else {
|
|
97
|
+
sets.delete(set);
|
|
98
|
+
}
|
|
99
|
+
listeners.forEach((listener) => listener(set));
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** The names of the registered sets. */
|
|
104
|
+
export const iconSets = () => [...sets.keys()];
|
|
105
|
+
|
|
106
|
+
/** The source registered for a set. */
|
|
107
|
+
export const getIconSet = (set) => sets.get(set);
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Call `listener(set)` whenever a set is registered or removed.
|
|
111
|
+
* @param {(set: string) => void} listener
|
|
112
|
+
* @returns {() => void} stop listening
|
|
113
|
+
*/
|
|
114
|
+
export function onIconSetsChange(listener) {
|
|
115
|
+
listeners.add(listener);
|
|
116
|
+
return () => listeners.delete(listener);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Split a reference into set and name (`lucide:check`, `{name, set}`).
|
|
121
|
+
* @param {IconRef} ref
|
|
122
|
+
* @returns {{set: string, name: string}}
|
|
123
|
+
*/
|
|
124
|
+
export function parseIconRef(ref) {
|
|
125
|
+
if (typeof ref === 'string') {
|
|
126
|
+
const colon = ref.indexOf(':');
|
|
127
|
+
return colon === -1
|
|
128
|
+
? { set: DEFAULT_ICON_SET, name: ref }
|
|
129
|
+
: { set: ref.slice(0, colon), name: ref.slice(colon + 1) };
|
|
130
|
+
}
|
|
131
|
+
return { set: ref?.set || DEFAULT_ICON_SET, name: String(ref?.name ?? '') };
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
async function tryResolve(set, name) {
|
|
135
|
+
const source = sets.get(set);
|
|
136
|
+
if (source === undefined || name === '') {
|
|
137
|
+
return undefined;
|
|
138
|
+
}
|
|
139
|
+
try {
|
|
140
|
+
return await source.resolve(name);
|
|
141
|
+
} catch {
|
|
142
|
+
return undefined;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Resolve an icon: the named set, then the own set, then the placeholder.
|
|
148
|
+
* Brand marks skip the own set so a missing brand never becomes a UI glyph.
|
|
149
|
+
* @param {IconRef} ref
|
|
150
|
+
* @returns {Promise<IconData & {set: string, name: string,
|
|
151
|
+
* placeholder?: boolean}>} `set` is the set that supplied the icon
|
|
152
|
+
*/
|
|
153
|
+
export async function resolveIcon(ref) {
|
|
154
|
+
const { set, name } = parseIconRef(ref);
|
|
155
|
+
const order =
|
|
156
|
+
set === DEFAULT_ICON_SET || set === 'brand'
|
|
157
|
+
? [set]
|
|
158
|
+
: [set, DEFAULT_ICON_SET];
|
|
159
|
+
if (set === 'brand' && !sets.has(set)) {
|
|
160
|
+
console.warn(
|
|
161
|
+
`brand:${name} could not be loaded: brand set is not registered`
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
for (const candidate of order) {
|
|
165
|
+
const icon = await tryResolve(candidate, name);
|
|
166
|
+
if (icon !== undefined) {
|
|
167
|
+
return { ...icon, set: candidate, name };
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return { ...PLACEHOLDER_ICON, set: DEFAULT_ICON_SET, name };
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* The asset records of every registered set (or of the given sets).
|
|
175
|
+
* @param {string[]} [only]
|
|
176
|
+
* @returns {AssetRecord[]}
|
|
177
|
+
*/
|
|
178
|
+
export function iconRecords(only) {
|
|
179
|
+
return [...sets.entries()]
|
|
180
|
+
.filter(([set]) => only === undefined || only.includes(set))
|
|
181
|
+
.flatMap(([, source]) => source.records());
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* A source over a module written by scripts/build-icons.mjs; the icons
|
|
186
|
+
* need no network or package at run time.
|
|
187
|
+
* @param {StaticIconModule} module
|
|
188
|
+
* @returns {IconSource}
|
|
189
|
+
*/
|
|
190
|
+
export function createStaticSource(module) {
|
|
191
|
+
const records = new Map(module.records.map((r) => [r.id, r]));
|
|
192
|
+
return Object.freeze({
|
|
193
|
+
resolve(name) {
|
|
194
|
+
const icon = Object.hasOwn(module.icons, name)
|
|
195
|
+
? module.icons[name]
|
|
196
|
+
: undefined;
|
|
197
|
+
return Promise.resolve(
|
|
198
|
+
icon === undefined
|
|
199
|
+
? undefined
|
|
200
|
+
: {
|
|
201
|
+
...(icon.title ? { title: icon.title } : {}),
|
|
202
|
+
viewBox: icon.viewBox,
|
|
203
|
+
body: icon.body,
|
|
204
|
+
mirrorInRtl: icon.mirrorInRtl ?? MIRROR_IN_RTL.has(name),
|
|
205
|
+
record: records.get(icon.record),
|
|
206
|
+
}
|
|
207
|
+
);
|
|
208
|
+
},
|
|
209
|
+
records: () => [...records.values()],
|
|
210
|
+
names: () => Object.keys(module.icons),
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const OWN_SOURCE = createStaticSource(OWN_ICONS);
|
|
215
|
+
registerIconSet(DEFAULT_ICON_SET, OWN_SOURCE);
|
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `ui-icon` element and the `icon` kind of the ui-dom renderer.
|
|
3
|
+
*
|
|
4
|
+
* <ui-icon name="close"></ui-icon> decorative
|
|
5
|
+
* <ui-icon set="lucide" name="check" label="Done"></ui-icon>
|
|
6
|
+
*
|
|
7
|
+
* (icon close) Links Notation
|
|
8
|
+
* (ok: icon (set lucide) (name check) (label 'Done'))
|
|
9
|
+
*
|
|
10
|
+
* Without a label the icon is decorative (`aria-hidden="true"`); with a
|
|
11
|
+
* label it is an image with that accessible name (`role="img"`). It draws
|
|
12
|
+
* in `currentColor`, so it follows the text colour, and it is 1.5em square
|
|
13
|
+
* unless `--ui-icon-size` says otherwise. Icons that point in the reading
|
|
14
|
+
* direction (or any icon with `mirror="true"`) flip in right-to-left text.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { defaultVocabulary, loadVocabulary } from '@link-foundation/ui-core';
|
|
18
|
+
import { defineKind } from '@link-foundation/ui-dom';
|
|
19
|
+
import {
|
|
20
|
+
onIconSetsChange,
|
|
21
|
+
parseIconRef,
|
|
22
|
+
resolveIcon,
|
|
23
|
+
} from './icon-registry.js';
|
|
24
|
+
import { iconToSvg } from './svg.js';
|
|
25
|
+
import { applyPresentation } from './presentation.js';
|
|
26
|
+
|
|
27
|
+
export const ICON_TAG = 'ui-icon';
|
|
28
|
+
|
|
29
|
+
/** The attributes of `ui-icon`, which are also the properties of `icon`. */
|
|
30
|
+
export const ICON_ATTRIBUTES = Object.freeze([
|
|
31
|
+
'name',
|
|
32
|
+
'set',
|
|
33
|
+
'label',
|
|
34
|
+
'mirror',
|
|
35
|
+
'fill',
|
|
36
|
+
'stroke-width',
|
|
37
|
+
'size',
|
|
38
|
+
]);
|
|
39
|
+
|
|
40
|
+
export const ICON_CSS = `${ICON_TAG} {
|
|
41
|
+
display: inline-block;
|
|
42
|
+
flex: none;
|
|
43
|
+
inline-size: var(--ui-icon-size, 1.5em);
|
|
44
|
+
block-size: var(--ui-icon-size, 1.5em);
|
|
45
|
+
line-height: 0;
|
|
46
|
+
vertical-align: -0.25em;
|
|
47
|
+
color: inherit;
|
|
48
|
+
}
|
|
49
|
+
${ICON_TAG} > svg {
|
|
50
|
+
display: block;
|
|
51
|
+
inline-size: 100%;
|
|
52
|
+
block-size: 100%;
|
|
53
|
+
overflow: visible;
|
|
54
|
+
}
|
|
55
|
+
${ICON_TAG}[data-mirror]:dir(rtl) > svg {
|
|
56
|
+
transform: scaleX(-1);
|
|
57
|
+
}
|
|
58
|
+
[dir='rtl'] ${ICON_TAG}[data-mirror] > svg {
|
|
59
|
+
transform: scaleX(-1);
|
|
60
|
+
}
|
|
61
|
+
[dir='ltr'] ${ICON_TAG}[data-mirror] > svg {
|
|
62
|
+
transform: none;
|
|
63
|
+
}
|
|
64
|
+
`;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* The `icon` kind for the ui-core vocabulary. `ui-dialect/0` has no icon
|
|
68
|
+
* kind yet (docs/spec/open-questions.md, "Icon element kind"): parse with
|
|
69
|
+
* `iconVocabulary()` to read `(icon close)`.
|
|
70
|
+
*/
|
|
71
|
+
export const ICON_KIND_TEXT = `icon: kind
|
|
72
|
+
description 'An icon of a registered icon set; decorative unless it has a label.'
|
|
73
|
+
positional name
|
|
74
|
+
property name string
|
|
75
|
+
property set string
|
|
76
|
+
property label string
|
|
77
|
+
property mirror
|
|
78
|
+
enum true false
|
|
79
|
+
property fill string
|
|
80
|
+
property stroke-width string
|
|
81
|
+
property size string
|
|
82
|
+
property note string multi
|
|
83
|
+
children none`;
|
|
84
|
+
|
|
85
|
+
let vocabulary;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* The ui-dialect/0 vocabulary plus the `icon` kind, for ui-core `parse`
|
|
89
|
+
* and ui-dom `mountDocument` (`parseOptions: {vocabulary}`).
|
|
90
|
+
* @returns {import('@link-foundation/ui-core').Vocabulary}
|
|
91
|
+
*/
|
|
92
|
+
export function iconVocabulary() {
|
|
93
|
+
if (vocabulary === undefined) {
|
|
94
|
+
const base = defaultVocabulary();
|
|
95
|
+
const icon = loadVocabulary(ICON_KIND_TEXT);
|
|
96
|
+
vocabulary = Object.freeze({
|
|
97
|
+
...base,
|
|
98
|
+
kinds: new Map([...base.kinds, ...icon.kinds]),
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
return vocabulary;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Roots (documents, shadow roots) that already have the icon CSS. */
|
|
105
|
+
const styled = new WeakSet();
|
|
106
|
+
|
|
107
|
+
/** Add ICON_CSS to the root of a node, once per root. */
|
|
108
|
+
function styleRoot(node) {
|
|
109
|
+
const root = node.getRootNode();
|
|
110
|
+
if (styled.has(root) || (root.nodeType !== 9 && root.nodeType !== 11)) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
styled.add(root);
|
|
114
|
+
const win = node.ownerDocument.defaultView;
|
|
115
|
+
if (
|
|
116
|
+
Array.isArray(root.adoptedStyleSheets) &&
|
|
117
|
+
typeof win?.CSSStyleSheet?.prototype?.replaceSync === 'function'
|
|
118
|
+
) {
|
|
119
|
+
const sheet = new win.CSSStyleSheet();
|
|
120
|
+
sheet.replaceSync(ICON_CSS);
|
|
121
|
+
root.adoptedStyleSheets = [...root.adoptedStyleSheets, sheet];
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
const style = node.ownerDocument.createElement('style');
|
|
125
|
+
style.setAttribute('data-ui-icon', '');
|
|
126
|
+
style.textContent = ICON_CSS;
|
|
127
|
+
const parent =
|
|
128
|
+
root.nodeType === 9 ? (root.head ?? root.documentElement) : root;
|
|
129
|
+
parent.insertBefore(style, parent.firstChild);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** Drop scripts, foreign content and event handlers from icon markup. */
|
|
133
|
+
function sanitize(svg) {
|
|
134
|
+
for (const node of svg.querySelectorAll('script, foreignObject')) {
|
|
135
|
+
node.remove();
|
|
136
|
+
}
|
|
137
|
+
for (const node of [svg, ...svg.querySelectorAll('*')]) {
|
|
138
|
+
for (const { name, value } of [...node.attributes]) {
|
|
139
|
+
if (
|
|
140
|
+
name.startsWith('on') ||
|
|
141
|
+
(name.endsWith('href') && !value.trim().startsWith('#'))
|
|
142
|
+
) {
|
|
143
|
+
node.removeAttribute(name);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return svg;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** Parse icon data into an `<svg>` element of the document. */
|
|
151
|
+
function svgElement(document, icon) {
|
|
152
|
+
const template = document.createElement('template');
|
|
153
|
+
template.innerHTML = iconToSvg(icon, {
|
|
154
|
+
'aria-hidden': 'true',
|
|
155
|
+
focusable: 'false',
|
|
156
|
+
});
|
|
157
|
+
return sanitize(template.content.firstElementChild);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** Whether the icon flips in right-to-left text. */
|
|
161
|
+
function mirrors(element, icon) {
|
|
162
|
+
const mirror = element.getAttribute('mirror');
|
|
163
|
+
if (mirror === null) {
|
|
164
|
+
return icon.mirrorInRtl === true;
|
|
165
|
+
}
|
|
166
|
+
return mirror !== 'false';
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* The `ui-icon` class of a window.
|
|
171
|
+
* @param {Window} win
|
|
172
|
+
*/
|
|
173
|
+
function createIconClass(win) {
|
|
174
|
+
return class UiIcon extends win.HTMLElement {
|
|
175
|
+
static get observedAttributes() {
|
|
176
|
+
return ICON_ATTRIBUTES;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
#token = 0;
|
|
180
|
+
#unlisten = undefined;
|
|
181
|
+
#ready = Promise.resolve(undefined);
|
|
182
|
+
#icon = undefined;
|
|
183
|
+
#sizeBefore = undefined;
|
|
184
|
+
|
|
185
|
+
/** The icon data shown now (after `ready`). */
|
|
186
|
+
get icon() {
|
|
187
|
+
return this.#icon;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** Settles with the icon data when the drawing is up to date. */
|
|
191
|
+
get ready() {
|
|
192
|
+
return this.#ready;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
connectedCallback() {
|
|
196
|
+
styleRoot(this);
|
|
197
|
+
this.#applyLabel();
|
|
198
|
+
this.#unlisten ??= onIconSetsChange((set) => {
|
|
199
|
+
const wanted = parseIconRef({
|
|
200
|
+
set: this.getAttribute('set') ?? undefined,
|
|
201
|
+
name: '',
|
|
202
|
+
}).set;
|
|
203
|
+
if (set === wanted || set === this.#icon?.set) {
|
|
204
|
+
this.#render();
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
this.#render();
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
disconnectedCallback() {
|
|
211
|
+
this.#unlisten?.();
|
|
212
|
+
this.#unlisten = undefined;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
attributeChangedCallback(name, before, after) {
|
|
216
|
+
if (!this.isConnected || before === after) {
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
if (name === 'label') {
|
|
220
|
+
this.#applyLabel();
|
|
221
|
+
} else if (name === 'mirror' && this.#icon !== undefined) {
|
|
222
|
+
this.toggleAttribute('data-mirror', mirrors(this, this.#icon));
|
|
223
|
+
} else {
|
|
224
|
+
this.#render();
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/** Decorative without a label, an image named by the label with one. */
|
|
229
|
+
#applyLabel() {
|
|
230
|
+
const value = this.getAttribute('label')?.trim();
|
|
231
|
+
const label =
|
|
232
|
+
value === 'true'
|
|
233
|
+
? (this.#icon?.title ?? this.#icon?.name)
|
|
234
|
+
: value === 'false'
|
|
235
|
+
? ''
|
|
236
|
+
: value;
|
|
237
|
+
if (label) {
|
|
238
|
+
this.setAttribute('role', 'img');
|
|
239
|
+
this.setAttribute('aria-label', label);
|
|
240
|
+
this.removeAttribute('aria-hidden');
|
|
241
|
+
} else {
|
|
242
|
+
this.setAttribute('aria-hidden', 'true');
|
|
243
|
+
this.removeAttribute('role');
|
|
244
|
+
this.removeAttribute('aria-label');
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
#render() {
|
|
249
|
+
const token = (this.#token += 1);
|
|
250
|
+
const ref = {
|
|
251
|
+
set: this.getAttribute('set') ?? undefined,
|
|
252
|
+
name: this.getAttribute('name') ?? '',
|
|
253
|
+
};
|
|
254
|
+
this.#ready = resolveIcon(ref).then((icon) => {
|
|
255
|
+
if (token !== this.#token) {
|
|
256
|
+
return this.#icon;
|
|
257
|
+
}
|
|
258
|
+
this.#icon = icon;
|
|
259
|
+
const svg = svgElement(this.ownerDocument, icon);
|
|
260
|
+
const size = applyPresentation(this, svg);
|
|
261
|
+
if (this.#sizeBefore !== undefined) {
|
|
262
|
+
const { value, priority } = this.#sizeBefore;
|
|
263
|
+
if (value) {
|
|
264
|
+
this.style.setProperty('--ui-icon-size', value, priority);
|
|
265
|
+
} else {
|
|
266
|
+
this.style.removeProperty('--ui-icon-size');
|
|
267
|
+
}
|
|
268
|
+
this.#sizeBefore = undefined;
|
|
269
|
+
}
|
|
270
|
+
if (size !== undefined) {
|
|
271
|
+
this.#sizeBefore = {
|
|
272
|
+
value: this.style.getPropertyValue('--ui-icon-size'),
|
|
273
|
+
priority: this.style.getPropertyPriority('--ui-icon-size'),
|
|
274
|
+
};
|
|
275
|
+
this.style.setProperty('--ui-icon-size', size);
|
|
276
|
+
}
|
|
277
|
+
this.replaceChildren(svg);
|
|
278
|
+
this.#applyLabel();
|
|
279
|
+
this.setAttribute('data-icon-set', icon.set);
|
|
280
|
+
this.toggleAttribute('data-placeholder', icon.placeholder === true);
|
|
281
|
+
this.toggleAttribute('data-mirror', mirrors(this, icon));
|
|
282
|
+
return icon;
|
|
283
|
+
});
|
|
284
|
+
return this.#ready;
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Define `ui-icon` in a window (once). In a browser this happens on
|
|
291
|
+
* import; call it for another window (jsdom) before rendering there.
|
|
292
|
+
* @param {Window|undefined} [win]
|
|
293
|
+
* @returns {CustomElementConstructor|undefined} the class, or undefined
|
|
294
|
+
* without custom elements
|
|
295
|
+
*/
|
|
296
|
+
export function defineIconElement(win = globalThis.window) {
|
|
297
|
+
const registry = win?.customElements;
|
|
298
|
+
if (registry === undefined) {
|
|
299
|
+
return undefined;
|
|
300
|
+
}
|
|
301
|
+
const existing = registry.get(ICON_TAG);
|
|
302
|
+
if (existing !== undefined) {
|
|
303
|
+
return existing;
|
|
304
|
+
}
|
|
305
|
+
const UiIcon = createIconClass(win);
|
|
306
|
+
registry.define(ICON_TAG, UiIcon);
|
|
307
|
+
return UiIcon;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/** The single text value of a property of a ui-dom element model. */
|
|
311
|
+
function atom(el, name) {
|
|
312
|
+
const values = el.props.get(name);
|
|
313
|
+
return values?.length === 1 && typeof values[0] === 'string'
|
|
314
|
+
? values[0]
|
|
315
|
+
: undefined;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/** The attribute values of an `icon` element model. */
|
|
319
|
+
export function iconAttributes(el) {
|
|
320
|
+
const positional = el.positional?.[0];
|
|
321
|
+
return {
|
|
322
|
+
name:
|
|
323
|
+
atom(el, 'name') ??
|
|
324
|
+
(typeof positional === 'string' ? positional : undefined),
|
|
325
|
+
set: atom(el, 'set'),
|
|
326
|
+
label: atom(el, 'label'),
|
|
327
|
+
mirror: atom(el, 'mirror'),
|
|
328
|
+
fill: atom(el, 'fill'),
|
|
329
|
+
'stroke-width': atom(el, 'stroke-width'),
|
|
330
|
+
size: atom(el, 'size'),
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
defineKind('icon', {
|
|
335
|
+
tag: ICON_TAG,
|
|
336
|
+
childrenSlot: null,
|
|
337
|
+
create(el, ctx) {
|
|
338
|
+
defineIconElement(ctx.document.defaultView ?? undefined);
|
|
339
|
+
return ctx.document.createElement(ICON_TAG);
|
|
340
|
+
},
|
|
341
|
+
update(node, el, changed, ctx) {
|
|
342
|
+
const attributes = iconAttributes(el);
|
|
343
|
+
if (attributes.name === undefined) {
|
|
344
|
+
ctx.diagnostic('missing-icon-name', 'warning', { property: 'name' });
|
|
345
|
+
}
|
|
346
|
+
for (const [name, value] of Object.entries(attributes)) {
|
|
347
|
+
if (value === undefined) {
|
|
348
|
+
node.removeAttribute(name);
|
|
349
|
+
} else if (node.getAttribute(name) !== value) {
|
|
350
|
+
node.setAttribute(name, value);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
},
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
defineIconElement();
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
export interface AssetRecord {
|
|
2
|
+
id: string;
|
|
3
|
+
kind: string;
|
|
4
|
+
files: string[];
|
|
5
|
+
/** An SPDX expression. */
|
|
6
|
+
license: string;
|
|
7
|
+
/** `none` for our own public-domain icons. */
|
|
8
|
+
copyright: string;
|
|
9
|
+
source?: string;
|
|
10
|
+
notice?: string;
|
|
11
|
+
attribution?: 'required' | 'none';
|
|
12
|
+
attributionText?: string;
|
|
13
|
+
modified?: 'yes' | 'no';
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface IconData {
|
|
17
|
+
/** Library title, used by label=true. */
|
|
18
|
+
title?: string;
|
|
19
|
+
viewBox: string;
|
|
20
|
+
/** SVG markup drawn in currentColor. */
|
|
21
|
+
body: string;
|
|
22
|
+
/** Flip horizontally in right-to-left text. */
|
|
23
|
+
mirrorInRtl: boolean;
|
|
24
|
+
record: AssetRecord | undefined;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface ResolvedIcon extends IconData {
|
|
28
|
+
/** The set that supplied the icon. */
|
|
29
|
+
set: string;
|
|
30
|
+
name: string;
|
|
31
|
+
placeholder?: boolean;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface IconSource {
|
|
35
|
+
resolve(name: string): Promise<IconData | undefined>;
|
|
36
|
+
records(): AssetRecord[];
|
|
37
|
+
names?(): string[];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** `close`, `lucide:check` or `{set: 'lucide', name: 'check'}`. */
|
|
41
|
+
export type IconRef = string | { set?: string; name: string };
|
|
42
|
+
|
|
43
|
+
/** A module written by scripts/build-icons.mjs (`dist/icons/<set>.js`). */
|
|
44
|
+
export interface StaticIconModule {
|
|
45
|
+
set: string;
|
|
46
|
+
icons: Record<
|
|
47
|
+
string,
|
|
48
|
+
{
|
|
49
|
+
viewBox: string;
|
|
50
|
+
body: string;
|
|
51
|
+
title?: string;
|
|
52
|
+
mirrorInRtl?: boolean;
|
|
53
|
+
record: string;
|
|
54
|
+
}
|
|
55
|
+
>;
|
|
56
|
+
records: AssetRecord[];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export const PLACEHOLDER_ICON: Readonly<
|
|
60
|
+
IconData & { record: undefined; placeholder: true }
|
|
61
|
+
>;
|
|
62
|
+
export function registerIconSet(set: string, source: IconSource): () => void;
|
|
63
|
+
export function iconSets(): string[];
|
|
64
|
+
export function getIconSet(set: string): IconSource | undefined;
|
|
65
|
+
export function onIconSetsChange(listener: (set: string) => void): () => void;
|
|
66
|
+
export function parseIconRef(ref: IconRef): { set: string; name: string };
|
|
67
|
+
export function resolveIcon(ref: IconRef): Promise<ResolvedIcon>;
|
|
68
|
+
export function iconRecords(only?: string[]): AssetRecord[];
|
|
69
|
+
export function createStaticSource(
|
|
70
|
+
module: StaticIconModule
|
|
71
|
+
): Readonly<IconSource & { names(): string[] }>;
|
|
72
|
+
|
|
73
|
+
export const DEFAULT_ICON_SET: 'own';
|
|
74
|
+
export const ICON_NAMES: readonly string[];
|
|
75
|
+
export const MIRROR_IN_RTL: ReadonlySet<string>;
|
|
76
|
+
|
|
77
|
+
export function splitSvg(
|
|
78
|
+
text: string,
|
|
79
|
+
options?: { defaults?: Record<string, string> }
|
|
80
|
+
): { viewBox: string; body: string; title?: string };
|
|
81
|
+
export function iconToSvg(
|
|
82
|
+
icon: { viewBox: string; body: string },
|
|
83
|
+
attributes?: Record<string, string>
|
|
84
|
+
): string;
|
|
85
|
+
export function iconNodeToSvg(node: unknown, root?: unknown): string;
|
|
86
|
+
|
|
87
|
+
export const ICON_TAG: 'ui-icon';
|
|
88
|
+
export const ICON_ATTRIBUTES: readonly [
|
|
89
|
+
'name',
|
|
90
|
+
'set',
|
|
91
|
+
'label',
|
|
92
|
+
'mirror',
|
|
93
|
+
'fill',
|
|
94
|
+
'stroke-width',
|
|
95
|
+
'size',
|
|
96
|
+
];
|
|
97
|
+
export const ICON_CSS: string;
|
|
98
|
+
export const ICON_KIND_TEXT: string;
|
|
99
|
+
/** The ui-dialect/0 vocabulary plus the `icon` kind. */
|
|
100
|
+
export function iconVocabulary(): unknown;
|
|
101
|
+
export function defineIconElement(
|
|
102
|
+
win?: Window
|
|
103
|
+
): CustomElementConstructor | undefined;
|
|
104
|
+
export function iconAttributes(el: {
|
|
105
|
+
props: Map<string, unknown[]>;
|
|
106
|
+
positional?: unknown[];
|
|
107
|
+
}): {
|
|
108
|
+
name: string | undefined;
|
|
109
|
+
set: string | undefined;
|
|
110
|
+
label: string | undefined;
|
|
111
|
+
mirror: string | undefined;
|
|
112
|
+
fill: string | undefined;
|
|
113
|
+
'stroke-width': string | undefined;
|
|
114
|
+
size: string | undefined;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
/** The `ui-icon` element. */
|
|
118
|
+
export interface UiIconElement extends HTMLElement {
|
|
119
|
+
/** The icon data shown now (after `ready`). */
|
|
120
|
+
readonly icon: ResolvedIcon | undefined;
|
|
121
|
+
/** Settles with the icon data when the drawing is up to date. */
|
|
122
|
+
readonly ready: Promise<ResolvedIcon | undefined>;
|
|
123
|
+
}
|