@jcsoftdev/ui 0.2.3 → 0.4.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/CHANGELOG.md +390 -7
- package/README.md +57 -3
- package/bin/ui-theme.mjs +1162 -25
- package/dist/ai/attachment/attachment.js +1 -1
- package/dist/ai/chat-list/group.js +3 -1
- package/dist/ai/conversation/conversation.js +1 -1
- package/dist/ai/internal/use-copy.d.ts +1 -5
- package/dist/ai/internal/use-copy.js +1 -32
- package/dist/ai/markdown/parse.js +59 -17
- package/dist/ai/source/source.js +1 -1
- package/dist/atoms/avatar/avatar.d.ts +13 -3
- package/dist/atoms/avatar/avatar.js +40 -2
- package/dist/atoms/avatar/index.d.ts +1 -1
- package/dist/atoms/avatar/index.js +3 -1
- package/dist/atoms/button/button.d.ts +4 -1
- package/dist/atoms/button/button.js +4 -2
- package/dist/atoms/checkbox/checkbox.d.ts +8 -3
- package/dist/atoms/checkbox/checkbox.js +26 -3
- package/dist/atoms/chip/chip.d.ts +19 -5
- package/dist/atoms/chip/chip.js +34 -5
- package/dist/atoms/chip/index.d.ts +1 -1
- package/dist/atoms/chip/index.js +6 -1
- package/dist/atoms/due-chip/due-chip.d.ts +31 -0
- package/dist/atoms/due-chip/due-chip.js +41 -0
- package/dist/atoms/due-chip/index.d.ts +2 -0
- package/dist/atoms/due-chip/index.js +6 -0
- package/dist/atoms/due-chip/model.d.ts +25 -0
- package/dist/atoms/due-chip/model.js +44 -0
- package/dist/atoms/icon-button/icon-button.d.ts +22 -0
- package/dist/atoms/icon-button/icon-button.js +38 -0
- package/dist/atoms/icon-button/index.d.ts +1 -0
- package/dist/atoms/icon-button/index.js +8 -0
- package/dist/atoms/index.d.ts +5 -0
- package/dist/atoms/index.js +5 -0
- package/dist/atoms/internal/hit-area.d.ts +6 -0
- package/dist/atoms/internal/hit-area.js +4 -0
- package/dist/atoms/kbd/index.d.ts +1 -0
- package/dist/atoms/kbd/index.js +4 -0
- package/dist/atoms/kbd/kbd.d.ts +7 -0
- package/dist/atoms/kbd/kbd.js +17 -0
- package/dist/atoms/radio-group/radio-group.js +6 -2
- package/dist/atoms/seal/index.d.ts +1 -0
- package/dist/atoms/seal/index.js +4 -0
- package/dist/atoms/seal/seal.d.ts +30 -0
- package/dist/atoms/seal/seal.js +71 -0
- package/dist/atoms/spinner/index.d.ts +1 -0
- package/dist/atoms/spinner/index.js +5 -0
- package/dist/atoms/spinner/spinner.d.ts +19 -0
- package/dist/atoms/spinner/spinner.js +31 -0
- package/dist/atoms/status-dot/index.d.ts +1 -1
- package/dist/atoms/status-dot/status-dot.d.ts +4 -2
- package/dist/atoms/status-dot/status-dot.js +5 -1
- package/dist/atoms/switch/switch.js +3 -1
- package/dist/calendar/date-calendar/date-calendar.d.ts +32 -0
- package/dist/calendar/date-calendar/date-calendar.js +189 -0
- package/dist/calendar/date-calendar/index.d.ts +1 -0
- package/dist/calendar/date-calendar/index.js +6 -0
- package/dist/calendar/index.d.ts +1 -0
- package/dist/calendar/index.js +1 -0
- package/dist/calendar/internal/date-utils.d.ts +26 -0
- package/dist/calendar/internal/date-utils.js +95 -1
- package/dist/charts/bar-chart/bar-race-chart.js +1 -0
- package/dist/charts/beeswarm-chart/beeswarm-chart.js +1 -1
- package/dist/charts/chord-chart/chord-chart.js +13 -5
- package/dist/charts/core/cartesian/cartesian-chart.d.ts +1 -1
- package/dist/charts/core/cartesian/cartesian-chart.js +48 -11
- package/dist/charts/core/cartesian/layout.d.ts +6 -1
- package/dist/charts/core/cartesian/layout.js +14 -5
- package/dist/charts/core/cartesian/marks.d.ts +2 -2
- package/dist/charts/core/cartesian/marks.js +1 -1
- package/dist/charts/core/cartesian/types.d.ts +28 -2
- package/dist/charts/core/category-explorer.d.ts +2 -2
- package/dist/charts/core/category-explorer.js +8 -4
- package/dist/charts/core/chart-dock.d.ts +26 -0
- package/dist/charts/core/chart-dock.js +45 -0
- package/dist/charts/core/chart-frame.d.ts +9 -2
- package/dist/charts/core/chart-frame.js +105 -25
- package/dist/charts/core/distribution/explorer.d.ts +5 -2
- package/dist/charts/core/distribution/explorer.js +12 -5
- package/dist/charts/core/distribution/xy-points.js +1 -1
- package/dist/charts/core/index.d.ts +3 -0
- package/dist/charts/core/index.js +3 -0
- package/dist/charts/core/leave-grace.d.ts +11 -0
- package/dist/charts/core/leave-grace.js +26 -0
- package/dist/charts/core/nearest.d.ts +14 -0
- package/dist/charts/core/nearest.js +22 -0
- package/dist/charts/core/plot-overlay.js +9 -3
- package/dist/charts/core/pointer.test-utils.d.ts +38 -0
- package/dist/charts/core/pointer.test-utils.js +123 -0
- package/dist/charts/core/tooltip.d.ts +25 -2
- package/dist/charts/core/tooltip.js +115 -40
- package/dist/charts/core/touch-select.d.ts +20 -0
- package/dist/charts/core/touch-select.js +184 -0
- package/dist/charts/core/types.d.ts +8 -4
- package/dist/charts/core/types.js +5 -0
- package/dist/charts/core/use-index-navigation.d.ts +17 -6
- package/dist/charts/core/use-index-navigation.js +47 -10
- package/dist/charts/donut-chart/donut-chart.d.ts +5 -1
- package/dist/charts/donut-chart/donut-chart.js +40 -1
- package/dist/charts/donut-chart/slice-labels.d.ts +20 -0
- package/dist/charts/donut-chart/slice-labels.js +20 -0
- package/dist/charts/dumbbell-chart/dumbbell-chart.js +6 -3
- package/dist/charts/fill-gauge-chart/fill-gauge-chart.js +1 -0
- package/dist/charts/funnel-chart/funnel-chart.js +2 -1
- package/dist/charts/gauge-chart/gauge-chart.js +2 -1
- package/dist/charts/heatmap-chart/heatmap-chart.d.ts +4 -1
- package/dist/charts/heatmap-chart/heatmap-chart.js +3 -1
- package/dist/charts/heatmap-chart/heatmap-grid.d.ts +4 -1
- package/dist/charts/heatmap-chart/heatmap-grid.js +3 -1
- package/dist/charts/hex-tile-map/hex-tile-map.js +124 -115
- package/dist/charts/hierarchy-morph/hierarchy-morph.js +2 -1
- package/dist/charts/icicle-chart/icicle-chart.js +7 -9
- package/dist/charts/lollipop-chart/lollipop-chart.js +6 -3
- package/dist/charts/maps/geo/map-viewport.js +1 -1
- package/dist/charts/polar-area-chart/polar-area-chart.js +42 -12
- package/dist/charts/progress-units/progress-units.js +1 -0
- package/dist/charts/radar-chart/radar-chart.js +1 -1
- package/dist/charts/radial-bar-chart/radial-bar-chart.js +2 -1
- package/dist/charts/range-area-chart/range-area-chart.js +3 -2
- package/dist/charts/sankey-chart/sankey-chart.js +12 -4
- package/dist/charts/tree-chart/tree-chart.js +1 -0
- package/dist/charts/treemap-chart/treemap-chart.js +2 -7
- package/dist/charts/waterfall-chart/waterfall-chart.js +6 -3
- package/dist/containers/action-bar/action-bar.d.ts +11 -2
- package/dist/containers/action-bar/action-bar.js +4 -1
- package/dist/containers/aside/aside.d.ts +14 -0
- package/dist/containers/aside/aside.js +25 -0
- package/dist/containers/aside/index.d.ts +1 -0
- package/dist/containers/aside/index.js +5 -0
- package/dist/containers/banner/banner.d.ts +4 -1
- package/dist/containers/banner/banner.js +9 -1
- package/dist/containers/card/card.d.ts +21 -3
- package/dist/containers/card/card.js +20 -5
- package/dist/containers/description-list/description-list.d.ts +29 -6
- package/dist/containers/description-list/description-list.js +47 -6
- package/dist/containers/feed/feed.d.ts +23 -0
- package/dist/containers/feed/feed.js +77 -0
- package/dist/containers/feed/index.d.ts +2 -0
- package/dist/containers/feed/index.js +10 -0
- package/dist/containers/feed/model.d.ts +19 -0
- package/dist/containers/feed/model.js +38 -0
- package/dist/containers/grid/grid.d.ts +15 -0
- package/dist/containers/grid/grid.js +24 -0
- package/dist/containers/grid/index.d.ts +1 -0
- package/dist/containers/grid/index.js +4 -0
- package/dist/containers/index.d.ts +9 -0
- package/dist/containers/index.js +9 -0
- package/dist/containers/kpi/kpi.d.ts +60 -7
- package/dist/containers/kpi/kpi.js +142 -28
- package/dist/containers/kpi-group/index.d.ts +1 -1
- package/dist/containers/kpi-group/index.js +3 -1
- package/dist/containers/kpi-group/kpi-group.d.ts +9 -1
- package/dist/containers/kpi-group/kpi-group.js +11 -1
- package/dist/containers/list-detail/index.d.ts +1 -0
- package/dist/containers/list-detail/index.js +20 -0
- package/dist/containers/list-detail/list-detail.d.ts +55 -0
- package/dist/containers/list-detail/list-detail.js +221 -0
- package/dist/containers/note/index.d.ts +1 -0
- package/dist/containers/note/index.js +4 -0
- package/dist/containers/note/note.d.ts +13 -0
- package/dist/containers/note/note.js +27 -0
- package/dist/containers/page/index.d.ts +1 -0
- package/dist/containers/page/index.js +4 -0
- package/dist/containers/page/page.d.ts +7 -0
- package/dist/containers/page/page.js +14 -0
- package/dist/containers/page-header/page-header.d.ts +8 -3
- package/dist/containers/page-header/page-header.js +35 -8
- package/dist/containers/responsive-list/responsive-list.d.ts +1 -1
- package/dist/containers/responsive-list/responsive-list.js +6 -3
- package/dist/containers/section/index.d.ts +1 -0
- package/dist/containers/section/index.js +6 -0
- package/dist/containers/section/section.d.ts +68 -0
- package/dist/containers/section/section.js +198 -0
- package/dist/containers/shortcuts/index.d.ts +1 -0
- package/dist/containers/shortcuts/index.js +8 -0
- package/dist/containers/shortcuts/shortcuts.d.ts +18 -0
- package/dist/containers/shortcuts/shortcuts.js +50 -0
- package/dist/containers/stack/index.d.ts +1 -0
- package/dist/containers/stack/index.js +6 -0
- package/dist/containers/stack/stack.d.ts +15 -0
- package/dist/containers/stack/stack.js +43 -0
- package/dist/containers/table/selection.d.ts +9 -0
- package/dist/containers/table/selection.js +20 -0
- package/dist/containers/table/table.d.ts +66 -4
- package/dist/containers/table/table.js +128 -7
- package/dist/containers/timeline/index.d.ts +1 -1
- package/dist/containers/timeline/index.js +4 -2
- package/dist/containers/timeline/timeline.d.ts +32 -5
- package/dist/containers/timeline/timeline.js +154 -90
- package/dist/forms/chip-group/chip-group.d.ts +54 -0
- package/dist/forms/chip-group/chip-group.js +114 -0
- package/dist/forms/chip-group/index.d.ts +1 -0
- package/dist/forms/chip-group/index.js +6 -0
- package/dist/forms/combobox/combobox.d.ts +60 -0
- package/dist/forms/combobox/combobox.js +281 -0
- package/dist/forms/combobox/index.d.ts +1 -0
- package/dist/forms/combobox/index.js +6 -0
- package/dist/forms/copy-field/copy-field.d.ts +17 -0
- package/dist/forms/copy-field/copy-field.js +72 -0
- package/dist/forms/copy-field/index.d.ts +1 -0
- package/dist/forms/copy-field/index.js +4 -0
- package/dist/forms/date-picker/date-picker.d.ts +40 -0
- package/dist/forms/date-picker/date-picker.js +183 -0
- package/dist/forms/date-picker/date-time-picker.d.ts +43 -0
- package/dist/forms/date-picker/date-time-picker.js +121 -0
- package/dist/forms/date-picker/index.d.ts +2 -0
- package/dist/forms/date-picker/index.js +10 -0
- package/dist/forms/date-picker/model.d.ts +35 -0
- package/dist/forms/date-picker/model.js +83 -0
- package/dist/forms/dropzone/dropzone.d.ts +30 -2
- package/dist/forms/dropzone/dropzone.js +153 -23
- package/dist/forms/emoji-picker/emoji-picker.js +1 -1
- package/dist/forms/field/field.d.ts +16 -10
- package/dist/forms/field/field.js +41 -5
- package/dist/forms/form/form.d.ts +15 -0
- package/dist/forms/form/form.js +29 -0
- package/dist/forms/form/index.d.ts +1 -0
- package/dist/forms/form/index.js +10 -0
- package/dist/forms/index.d.ts +6 -0
- package/dist/forms/index.js +6 -0
- package/dist/forms/input/index.d.ts +1 -1
- package/dist/forms/input/index.js +6 -2
- package/dist/forms/input/input.d.ts +23 -3
- package/dist/forms/input/input.js +78 -7
- package/dist/forms/input-icon/input-icon.d.ts +1 -1
- package/dist/forms/internal/listbox-items.d.ts +18 -0
- package/dist/forms/internal/listbox-items.js +88 -0
- package/dist/forms/internal/listbox.d.ts +44 -0
- package/dist/forms/internal/listbox.js +74 -0
- package/dist/forms/number-stepper/model.d.ts +16 -0
- package/dist/forms/number-stepper/model.js +23 -0
- package/dist/forms/number-stepper/number-stepper.d.ts +36 -6
- package/dist/forms/number-stepper/number-stepper.js +86 -37
- package/dist/forms/select-menu/index.d.ts +1 -0
- package/dist/forms/select-menu/index.js +6 -0
- package/dist/forms/select-menu/select-menu.d.ts +35 -0
- package/dist/forms/select-menu/select-menu.js +230 -0
- package/dist/glass/crystal-map.d.ts +70 -0
- package/dist/glass/crystal-map.js +88 -0
- package/dist/glass/displacement-map.d.ts +117 -0
- package/dist/glass/displacement-map.js +201 -0
- package/dist/glass/index.d.ts +8 -0
- package/dist/glass/index.js +63 -0
- package/dist/glass/lens-crystal.d.ts +29 -0
- package/dist/glass/lens-crystal.js +161 -0
- package/dist/glass/lens-dispersion.d.ts +11 -0
- package/dist/glass/lens-dispersion.js +19 -0
- package/dist/glass/liquid-glass.d.ts +41 -0
- package/dist/glass/liquid-glass.js +256 -0
- package/dist/glass/liquid-motion.d.ts +53 -0
- package/dist/glass/liquid-motion.js +302 -0
- package/dist/glass/liquid-options.d.ts +162 -0
- package/dist/glass/liquid-options.js +179 -0
- package/dist/glass/refraction.d.ts +100 -0
- package/dist/glass/refraction.js +714 -0
- package/dist/glass/specular-map.d.ts +26 -0
- package/dist/glass/specular-map.js +75 -0
- package/dist/glass/spring.d.ts +79 -0
- package/dist/glass/spring.js +58 -0
- package/dist/glass/support.d.ts +13 -0
- package/dist/glass/support.js +14 -0
- package/dist/glass/use-glass-refraction.d.ts +8 -0
- package/dist/glass/use-glass-refraction.js +16 -0
- package/dist/i18n/strings.d.ts +113 -0
- package/dist/i18n/strings.js +70 -2
- package/dist/i18n/ui-strings-provider.d.ts +1 -1
- package/dist/i18n/ui-strings-provider.js +6 -2
- package/dist/icons/index.d.ts +2 -0
- package/dist/icons/index.js +4 -0
- package/dist/icons/key.d.ts +2 -0
- package/dist/icons/key.js +12 -0
- package/dist/icons/webhook.d.ts +2 -0
- package/dist/icons/webhook.js +12 -0
- package/dist/liquid/index.d.ts +3 -0
- package/dist/liquid/index.js +29 -0
- package/dist/navigation/breadcrumbs/breadcrumbs.d.ts +29 -0
- package/dist/navigation/breadcrumbs/breadcrumbs.js +70 -0
- package/dist/navigation/breadcrumbs/index.d.ts +1 -0
- package/dist/navigation/breadcrumbs/index.js +6 -0
- package/dist/navigation/index.d.ts +2 -0
- package/dist/navigation/index.js +2 -0
- package/dist/navigation/segmented/index.d.ts +1 -1
- package/dist/navigation/segmented/model.d.ts +5 -0
- package/dist/navigation/segmented/model.js +6 -0
- package/dist/navigation/segmented/segmented.d.ts +17 -3
- package/dist/navigation/segmented/segmented.js +20 -4
- package/dist/navigation/stepper/index.d.ts +1 -1
- package/dist/navigation/stepper/index.js +3 -1
- package/dist/navigation/stepper/stepper.d.ts +8 -0
- package/dist/navigation/stepper/stepper.js +68 -45
- package/dist/navigation/tabs/index.d.ts +1 -0
- package/dist/navigation/tabs/index.js +6 -0
- package/dist/navigation/tabs/tabs-nav.d.ts +37 -0
- package/dist/navigation/tabs/tabs-nav.js +57 -0
- package/dist/navigation/wizard/index.d.ts +1 -0
- package/dist/navigation/wizard/index.js +6 -0
- package/dist/navigation/wizard/model.d.ts +33 -0
- package/dist/navigation/wizard/model.js +34 -0
- package/dist/navigation/wizard/wizard.d.ts +45 -0
- package/dist/navigation/wizard/wizard.js +169 -0
- package/dist/overlays/alert-dialog/alert-dialog.d.ts +103 -0
- package/dist/overlays/alert-dialog/alert-dialog.js +342 -0
- package/dist/overlays/alert-dialog/index.d.ts +1 -0
- package/dist/overlays/alert-dialog/index.js +26 -0
- package/dist/overlays/context-menu/context-menu.d.ts +9 -1
- package/dist/overlays/context-menu/context-menu.js +4 -1
- package/dist/overlays/dialog/dialog.d.ts +9 -1
- package/dist/overlays/dialog/dialog.js +3 -0
- package/dist/overlays/drawer/drawer.d.ts +9 -1
- package/dist/overlays/drawer/drawer.js +3 -0
- package/dist/overlays/dropdown-menu/dropdown-menu.d.ts +25 -1
- package/dist/overlays/dropdown-menu/dropdown-menu.js +14 -4
- package/dist/overlays/dropdown-menu/index.d.ts +1 -1
- package/dist/overlays/dropdown-menu/index.js +8 -2
- package/dist/overlays/hover-card/hover-card.d.ts +10 -1
- package/dist/overlays/hover-card/hover-card.js +4 -1
- package/dist/overlays/index.d.ts +2 -0
- package/dist/overlays/index.js +2 -0
- package/dist/overlays/popover/popover.d.ts +9 -1
- package/dist/overlays/popover/popover.js +3 -0
- package/dist/overlays/testing/index.d.ts +5 -0
- package/dist/overlays/testing/index.js +4 -0
- package/dist/overlays/toaster/index.d.ts +2 -1
- package/dist/overlays/toaster/index.js +4 -2
- package/dist/overlays/toaster/toast-store.d.ts +6 -2
- package/dist/overlays/toaster/toast.d.ts +3 -0
- package/dist/overlays/toaster/toast.js +3 -0
- package/dist/overlays/toaster/toaster.d.ts +3 -0
- package/dist/overlays/toaster/toaster.js +36 -3
- package/dist/overlays/tooltip/index.d.ts +1 -0
- package/dist/overlays/tooltip/index.js +4 -0
- package/dist/overlays/tooltip/model.d.ts +10 -0
- package/dist/overlays/tooltip/model.js +13 -0
- package/dist/overlays/tooltip/tooltip.d.ts +41 -0
- package/dist/overlays/tooltip/tooltip.js +116 -0
- package/dist/palette/command-palette/command-palette.d.ts +12 -2
- package/dist/palette/command-palette/command-palette.js +5 -0
- package/dist/primitives/command/command.d.ts +3 -2
- package/dist/primitives/command/command.js +2 -0
- package/dist/primitives/menu/menu.js +1 -1
- package/dist/primitives/popper/popper.js +5 -0
- package/dist/primitives/use-dismissable-layer.js +1 -1
- package/dist/rich-text/rich-text-editor.js +94 -8
- package/dist/rich-text/sanitize.js +70 -20
- package/dist/shell/app-shell/app-shell.d.ts +17 -0
- package/dist/shell/app-shell/app-shell.js +44 -4
- package/dist/shell/bottom-nav/bottom-nav.d.ts +34 -0
- package/dist/shell/bottom-nav/bottom-nav.js +124 -0
- package/dist/shell/bottom-nav/index.d.ts +2 -0
- package/dist/shell/bottom-nav/index.js +9 -0
- package/dist/shell/bottom-nav/split.d.ts +11 -0
- package/dist/shell/bottom-nav/split.js +10 -0
- package/dist/shell/sidebar/sidebar.d.ts +16 -2
- package/dist/shell/sidebar/sidebar.js +46 -4
- package/dist/shell/topbar/topbar.d.ts +20 -9
- package/dist/shell/topbar/topbar.js +16 -9
- package/dist/states/empty-state/empty-state.d.ts +3 -1
- package/dist/states/empty-state/empty-state.js +9 -1
- package/dist/states/error-state/error-state.d.ts +8 -1
- package/dist/states/error-state/error-state.js +15 -9
- package/dist/states/index.d.ts +1 -0
- package/dist/states/index.js +1 -0
- package/dist/states/live-status-bar/index.d.ts +1 -0
- package/dist/states/live-status-bar/index.js +6 -0
- package/dist/states/live-status-bar/live-status-bar.d.ts +17 -0
- package/dist/states/live-status-bar/live-status-bar.js +49 -0
- package/dist/states/offline-banner/offline-banner.d.ts +3 -1
- package/dist/states/offline-banner/offline-banner.js +8 -4
- package/dist/states/skeleton/skeleton.d.ts +8 -2
- package/dist/states/skeleton/skeleton.js +44 -2
- package/dist/utils/class-groups.js +17 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/material.d.ts +13 -0
- package/dist/utils/material.js +6 -0
- package/dist/utils/tone.d.ts +8 -0
- package/dist/utils/tone.js +17 -0
- package/dist/utils/use-copy.d.ts +5 -0
- package/dist/utils/use-copy.js +35 -0
- package/icons/svg/key.svg +5 -0
- package/icons/svg/webhook.svg +5 -0
- package/package.json +31 -21
- package/scripts/build-theme.d.mts +22 -0
- package/scripts/build-theme.mjs +248 -5
- package/src/ai/attachment/attachment.tsx +1 -1
- package/src/ai/chat-list/group.ts +3 -1
- package/src/ai/conversation/conversation.tsx +1 -1
- package/src/ai/internal/use-copy.ts +1 -38
- package/src/ai/markdown/parse.ts +74 -17
- package/src/ai/source/source.tsx +1 -1
- package/src/atoms/avatar/avatar.tsx +57 -4
- package/src/atoms/avatar/index.ts +8 -1
- package/src/atoms/button/button.tsx +8 -3
- package/src/atoms/checkbox/checkbox.tsx +33 -4
- package/src/atoms/chip/chip.tsx +55 -8
- package/src/atoms/chip/index.ts +9 -1
- package/src/atoms/due-chip/due-chip.tsx +75 -0
- package/src/atoms/due-chip/index.ts +2 -0
- package/src/atoms/due-chip/model.ts +67 -0
- package/src/atoms/icon-button/icon-button.tsx +58 -0
- package/src/atoms/icon-button/index.ts +6 -0
- package/src/atoms/index.ts +5 -0
- package/src/atoms/internal/hit-area.ts +7 -0
- package/src/atoms/kbd/index.ts +1 -0
- package/src/atoms/kbd/kbd.tsx +20 -0
- package/src/atoms/radio-group/radio-group.tsx +8 -2
- package/src/atoms/seal/index.ts +1 -0
- package/src/atoms/seal/seal.tsx +107 -0
- package/src/atoms/spinner/index.ts +1 -0
- package/src/atoms/spinner/spinner.tsx +49 -0
- package/src/atoms/status-dot/index.ts +1 -0
- package/src/atoms/status-dot/status-dot.tsx +15 -3
- package/src/atoms/switch/switch.tsx +3 -1
- package/src/calendar/date-calendar/date-calendar.tsx +230 -0
- package/src/calendar/date-calendar/index.ts +5 -0
- package/src/calendar/index.ts +1 -0
- package/src/calendar/internal/date-utils.ts +115 -0
- package/src/charts/README.md +21 -0
- package/src/charts/bar-chart/bar-race-chart.tsx +1 -0
- package/src/charts/beeswarm-chart/beeswarm-chart.tsx +1 -1
- package/src/charts/chord-chart/chord-chart.tsx +13 -5
- package/src/charts/core/cartesian/cartesian-chart.tsx +55 -10
- package/src/charts/core/cartesian/layout.ts +29 -10
- package/src/charts/core/cartesian/marks.tsx +3 -3
- package/src/charts/core/cartesian/types.ts +30 -2
- package/src/charts/core/category-explorer.tsx +12 -6
- package/src/charts/core/chart-dock.tsx +68 -0
- package/src/charts/core/chart-frame.tsx +116 -27
- package/src/charts/core/distribution/explorer.tsx +17 -7
- package/src/charts/core/distribution/xy-points.tsx +1 -1
- package/src/charts/core/index.ts +3 -0
- package/src/charts/core/leave-grace.ts +35 -0
- package/src/charts/core/nearest.ts +38 -0
- package/src/charts/core/plot-overlay.tsx +9 -3
- package/src/charts/core/pointer.test-utils.ts +146 -0
- package/src/charts/core/tooltip.tsx +129 -15
- package/src/charts/core/touch-select.ts +250 -0
- package/src/charts/core/types.ts +13 -4
- package/src/charts/core/use-index-navigation.ts +70 -11
- package/src/charts/donut-chart/donut-chart.tsx +53 -3
- package/src/charts/donut-chart/slice-labels.ts +39 -0
- package/src/charts/dumbbell-chart/dumbbell-chart.tsx +8 -3
- package/src/charts/fill-gauge-chart/fill-gauge-chart.tsx +1 -0
- package/src/charts/funnel-chart/funnel-chart.tsx +2 -1
- package/src/charts/gauge-chart/gauge-chart.tsx +2 -1
- package/src/charts/heatmap-chart/heatmap-chart.tsx +5 -0
- package/src/charts/heatmap-chart/heatmap-grid.tsx +5 -1
- package/src/charts/hex-tile-map/hex-tile-map.tsx +6 -1
- package/src/charts/hierarchy-morph/hierarchy-morph.tsx +2 -1
- package/src/charts/icicle-chart/icicle-chart.tsx +8 -9
- package/src/charts/lollipop-chart/lollipop-chart.tsx +8 -3
- package/src/charts/maps/geo/map-viewport.tsx +1 -1
- package/src/charts/polar-area-chart/polar-area-chart.tsx +37 -12
- package/src/charts/progress-units/progress-units.tsx +1 -0
- package/src/charts/radar-chart/radar-chart.tsx +1 -1
- package/src/charts/radial-bar-chart/radial-bar-chart.tsx +2 -1
- package/src/charts/range-area-chart/range-area-chart.tsx +3 -2
- package/src/charts/sankey-chart/sankey-chart.tsx +12 -4
- package/src/charts/tree-chart/tree-chart.tsx +1 -0
- package/src/charts/treemap-chart/treemap-chart.tsx +2 -7
- package/src/charts/waterfall-chart/waterfall-chart.tsx +8 -3
- package/src/containers/action-bar/action-bar.tsx +13 -2
- package/src/containers/aside/aside.tsx +40 -0
- package/src/containers/aside/index.ts +1 -0
- package/src/containers/banner/banner.tsx +18 -1
- package/src/containers/card/card.tsx +43 -4
- package/src/containers/description-list/description-list.tsx +85 -9
- package/src/containers/feed/feed.tsx +99 -0
- package/src/containers/feed/index.ts +8 -0
- package/src/containers/feed/model.ts +54 -0
- package/src/containers/grid/grid.tsx +37 -0
- package/src/containers/grid/index.ts +1 -0
- package/src/containers/index.ts +9 -0
- package/src/containers/kpi/kpi.tsx +231 -38
- package/src/containers/kpi-group/index.ts +7 -1
- package/src/containers/kpi-group/kpi-group.tsx +26 -1
- package/src/containers/list-detail/index.ts +15 -0
- package/src/containers/list-detail/list-detail.tsx +293 -0
- package/src/containers/note/index.ts +1 -0
- package/src/containers/note/note.tsx +38 -0
- package/src/containers/page/index.ts +1 -0
- package/src/containers/page/page.tsx +17 -0
- package/src/containers/page-header/page-header.tsx +38 -8
- package/src/containers/responsive-list/responsive-list.tsx +7 -4
- package/src/containers/section/index.ts +11 -0
- package/src/containers/section/section.tsx +281 -0
- package/src/containers/shortcuts/index.ts +6 -0
- package/src/containers/shortcuts/shortcuts.tsx +92 -0
- package/src/containers/stack/index.ts +7 -0
- package/src/containers/stack/stack.tsx +55 -0
- package/src/containers/table/selection.ts +26 -0
- package/src/containers/table/table.tsx +215 -13
- package/src/containers/timeline/index.ts +3 -0
- package/src/containers/timeline/timeline.tsx +204 -93
- package/src/forms/chip-group/chip-group.tsx +184 -0
- package/src/forms/chip-group/index.ts +8 -0
- package/src/forms/combobox/combobox.tsx +359 -0
- package/src/forms/combobox/index.ts +7 -0
- package/src/forms/copy-field/copy-field.tsx +88 -0
- package/src/forms/copy-field/index.ts +1 -0
- package/src/forms/date-picker/date-picker.tsx +239 -0
- package/src/forms/date-picker/date-time-picker.tsx +178 -0
- package/src/forms/date-picker/index.ts +10 -0
- package/src/forms/date-picker/model.ts +108 -0
- package/src/forms/dropzone/dropzone.tsx +217 -35
- package/src/forms/emoji-picker/emoji-picker.tsx +1 -1
- package/src/forms/field/field.tsx +72 -7
- package/src/forms/form/form.tsx +46 -0
- package/src/forms/form/index.ts +8 -0
- package/src/forms/index.ts +6 -0
- package/src/forms/input/index.ts +8 -1
- package/src/forms/input/input.tsx +103 -7
- package/src/forms/input-icon/input-icon.tsx +1 -1
- package/src/forms/internal/listbox-items.tsx +103 -0
- package/src/forms/internal/listbox.ts +124 -0
- package/src/forms/number-stepper/model.ts +35 -0
- package/src/forms/number-stepper/number-stepper.tsx +132 -42
- package/src/forms/select-menu/index.ts +7 -0
- package/src/forms/select-menu/select-menu.tsx +280 -0
- package/src/glass/crystal-map.ts +150 -0
- package/src/glass/displacement-map.ts +317 -0
- package/src/glass/index.ts +43 -0
- package/src/glass/lens-crystal.ts +226 -0
- package/src/glass/lens-dispersion.ts +34 -0
- package/src/glass/liquid-glass.tsx +371 -0
- package/src/glass/liquid-motion.ts +395 -0
- package/src/glass/liquid-options.ts +306 -0
- package/src/glass/refraction.ts +1010 -0
- package/src/glass/specular-map.ts +95 -0
- package/src/glass/spring.ts +98 -0
- package/src/glass/support.ts +27 -0
- package/src/glass/use-glass-refraction.ts +21 -0
- package/src/i18n/strings.ts +113 -0
- package/src/i18n/ui-strings-provider.tsx +15 -4
- package/src/icons/index.ts +2 -0
- package/src/icons/key.tsx +13 -0
- package/src/icons/webhook.tsx +13 -0
- package/src/liquid/index.ts +24 -0
- package/src/navigation/breadcrumbs/breadcrumbs.tsx +103 -0
- package/src/navigation/breadcrumbs/index.ts +8 -0
- package/src/navigation/index.ts +2 -0
- package/src/navigation/segmented/index.ts +1 -0
- package/src/navigation/segmented/model.ts +11 -0
- package/src/navigation/segmented/segmented.tsx +45 -6
- package/src/navigation/stepper/index.ts +7 -1
- package/src/navigation/stepper/stepper.tsx +41 -5
- package/src/navigation/tabs/index.ts +7 -0
- package/src/navigation/tabs/tabs-nav.tsx +131 -0
- package/src/navigation/wizard/index.ts +7 -0
- package/src/navigation/wizard/model.ts +61 -0
- package/src/navigation/wizard/wizard.tsx +222 -0
- package/src/overlays/alert-dialog/alert-dialog.tsx +486 -0
- package/src/overlays/alert-dialog/index.ts +19 -0
- package/src/overlays/context-menu/context-menu.tsx +11 -1
- package/src/overlays/dialog/dialog.tsx +10 -0
- package/src/overlays/drawer/drawer.tsx +10 -0
- package/src/overlays/dropdown-menu/dropdown-menu.tsx +38 -4
- package/src/overlays/dropdown-menu/index.ts +3 -0
- package/src/overlays/hover-card/hover-card.tsx +12 -1
- package/src/overlays/index.ts +2 -0
- package/src/overlays/popover/popover.tsx +10 -0
- package/src/overlays/testing/index.ts +5 -0
- package/src/overlays/toaster/index.ts +2 -0
- package/src/overlays/toaster/toast-store.ts +6 -2
- package/src/overlays/toaster/toast.ts +6 -0
- package/src/overlays/toaster/toaster.tsx +44 -2
- package/src/overlays/tooltip/index.ts +1 -0
- package/src/overlays/tooltip/model.ts +18 -0
- package/src/overlays/tooltip/tooltip.tsx +166 -0
- package/src/palette/command-palette/command-palette.tsx +15 -1
- package/src/primitives/command/command.tsx +4 -0
- package/src/primitives/menu/menu.tsx +1 -1
- package/src/primitives/popper/popper.tsx +10 -0
- package/src/primitives/use-dismissable-layer.ts +7 -2
- package/src/rich-text/rich-text-editor.tsx +116 -13
- package/src/rich-text/sanitize.ts +94 -23
- package/src/shell/app-shell/app-shell.tsx +60 -4
- package/src/shell/bottom-nav/bottom-nav.tsx +187 -0
- package/src/shell/bottom-nav/index.ts +8 -0
- package/src/shell/bottom-nav/split.ts +20 -0
- package/src/shell/sidebar/sidebar.tsx +51 -5
- package/src/shell/topbar/topbar.tsx +81 -58
- package/src/states/empty-state/empty-state.tsx +11 -1
- package/src/states/error-state/error-state.tsx +23 -8
- package/src/states/index.ts +1 -0
- package/src/states/live-status-bar/index.ts +6 -0
- package/src/states/live-status-bar/live-status-bar.tsx +62 -0
- package/src/states/offline-banner/offline-banner.tsx +13 -5
- package/src/states/skeleton/skeleton.tsx +68 -2
- package/src/utils/class-groups.ts +17 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/material.ts +16 -0
- package/src/utils/tone.ts +29 -0
- package/src/utils/use-copy.ts +38 -0
- package/styles/Theme.kt +64 -3
- package/styles/base.css +51 -0
- package/styles/tailwind.css +836 -0
- package/styles/theme.css +579 -34
- package/styles/tokens.css +788 -15
- package/tokens/default.json +918 -29
- package/scripts/build-theme.d.ts +0 -18
|
@@ -0,0 +1,1010 @@
|
|
|
1
|
+
import {
|
|
2
|
+
bezelFor,
|
|
3
|
+
createDisplacementMap,
|
|
4
|
+
FULL_CAP,
|
|
5
|
+
isWhole,
|
|
6
|
+
type LensCoverage,
|
|
7
|
+
scaleFor,
|
|
8
|
+
VEIL_FLOOR,
|
|
9
|
+
} from "./displacement-map.js";
|
|
10
|
+
import type { CrystalLens } from "./lens-crystal.js";
|
|
11
|
+
import { startLiquidMotion } from "./liquid-motion.js";
|
|
12
|
+
import { LIQUID_DEFAULTS, liquidShadow } from "./liquid-options.js";
|
|
13
|
+
import { createSpecularMap } from "./specular-map.js";
|
|
14
|
+
import { supportsBackdropRefraction } from "./support.js";
|
|
15
|
+
|
|
16
|
+
const SVG_NS = "http://www.w3.org/2000/svg";
|
|
17
|
+
const HOST_ID = "ui-glass-refraction-defs";
|
|
18
|
+
|
|
19
|
+
export interface GlassRefractionOptions {
|
|
20
|
+
/**
|
|
21
|
+
* `scale` of the displacement filter (the source offset at the edge is half of it). Default:
|
|
22
|
+
* `scaleFor()`, the strongest bend that cannot fold back on itself. Above that, stripes
|
|
23
|
+
* behind the glass break into a sawtooth.
|
|
24
|
+
*/
|
|
25
|
+
scale?: number;
|
|
26
|
+
/**
|
|
27
|
+
* Width of the refracting bevel in px; the middle of the surface shows the backdrop
|
|
28
|
+
* undisplaced. Default: 1.2 times the corner radius, between 14 and 56 px and at most 45% of
|
|
29
|
+
* the short side (so a small pill keeps a clear middle).
|
|
30
|
+
*/
|
|
31
|
+
bezel?: number;
|
|
32
|
+
/**
|
|
33
|
+
* `"full"` (default): the lens bends the backdrop over the whole surface, strongest at the rim
|
|
34
|
+
* and gentle but never zero towards the centre, with at most 24 px of offset. `"dome"`: the
|
|
35
|
+
* same with round contours. `"rim"`: only the bevel, the middle shows the backdrop undisplaced.
|
|
36
|
+
* CSS: `--liquid-profile` (older name: `--glass-lens-coverage`). The other `--liquid-*`
|
|
37
|
+
* variables (see `LiquidGlassOptions`) are read live: change them and the lens follows.
|
|
38
|
+
*/
|
|
39
|
+
coverage?: LensCoverage;
|
|
40
|
+
/**
|
|
41
|
+
* Chromatic dispersion: how far apart the red and blue channels are pulled, as a fraction of
|
|
42
|
+
* `scale`. It runs three displacement passes instead of one (about +50% to +100% of the lens
|
|
43
|
+
* cost), so it is off by default (it also paints a colour fringe on hard edges). Pass a number,
|
|
44
|
+
* or set `--glass-lens-dispersion` in CSS, to turn it on; it only applies on surfaces up to
|
|
45
|
+
* 100,000 px squared.
|
|
46
|
+
*/
|
|
47
|
+
dispersion?: number;
|
|
48
|
+
/**
|
|
49
|
+
* Move the legibility veil of a liquid surface into the filter, where it is adaptive (only as
|
|
50
|
+
* strong as the backdrop needs, so the body stays clear over friendly backdrops) and eases off
|
|
51
|
+
* across the rim. Default true; `false` keeps the uniform CSS veil.
|
|
52
|
+
*/
|
|
53
|
+
veil?: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Directional rim light inside the filter: a glint on the walls facing the upper left (and a
|
|
56
|
+
* weaker one opposite) that is the lensed backdrop pushed to a high saturation, a dark contour
|
|
57
|
+
* and a faint inner shadow. Default true.
|
|
58
|
+
*/
|
|
59
|
+
specular?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Motion: the lens materialises when it is first applied (the refraction springs up from
|
|
62
|
+
* nothing), a press deepens it and swells the surface, and `--liquid-interactive: drag` lets the
|
|
63
|
+
* surface be pulled and squashed. Default true; `--liquid-motion: off` turns it off per surface.
|
|
64
|
+
* Never runs under reduced motion, where the lens is not applied at all.
|
|
65
|
+
*/
|
|
66
|
+
animate?: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Read the pointer mode (`--liquid-interactive`) only from the element itself (its inline
|
|
69
|
+
* style, or the value of `data-glass-interactive`), not from a scope or theme above it. The
|
|
70
|
+
* overlay components (dialog, popover, sidebar, drawer) set it, so a page-wide
|
|
71
|
+
* `--liquid-interactive` never makes them pressable or draggable. Default false.
|
|
72
|
+
*/
|
|
73
|
+
ownInteractive?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Only refract while the surface resolves to a liquid material (the `--glass-lens` flag the
|
|
76
|
+
* `liquid` utilities set). This is what the glass components use. Default false.
|
|
77
|
+
*/
|
|
78
|
+
auto?: boolean;
|
|
79
|
+
/**
|
|
80
|
+
* `"auto"` (default) only refracts where {@link supportsBackdropRefraction} is true and the user
|
|
81
|
+
* has not asked for less transparency, more contrast or less motion. `"force"` skips the
|
|
82
|
+
* engine check (never the accessibility ones).
|
|
83
|
+
*/
|
|
84
|
+
refraction?: "auto" | "force";
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Preferences that switch refraction off, live: it comes back when they are cleared. */
|
|
88
|
+
const OFF_QUERIES = [
|
|
89
|
+
"(prefers-reduced-transparency: reduce)",
|
|
90
|
+
"(prefers-contrast: more)",
|
|
91
|
+
"(forced-colors: active)",
|
|
92
|
+
"(prefers-reduced-motion: reduce)",
|
|
93
|
+
];
|
|
94
|
+
/** Changes that can alter the blur the glass utility resolves to. */
|
|
95
|
+
const REBUILD_QUERIES = ["(prefers-color-scheme: dark)"];
|
|
96
|
+
const REBUILD_ATTRIBUTES = ["data-theme", "data-style", "data-density", "data-radius"];
|
|
97
|
+
|
|
98
|
+
/** Surfaces above this area (CSS px squared) keep the plain liquid look: the filter costs per pixel. */
|
|
99
|
+
const MAX_AREA = 640_000;
|
|
100
|
+
/** Largest surface (CSS px squared) that gets chromatic dispersion by default. */
|
|
101
|
+
const DISPERSION_AREA = 100_000;
|
|
102
|
+
/** Lenses alive at once; further surfaces keep the plain liquid look until one is released. */
|
|
103
|
+
const MAX_ACTIVE = 8;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* The maps are smooth fields that `feImage` stretches to the surface, so past 1.5 device pixels per
|
|
107
|
+
* CSS pixel they only cost more: the field is computed per pixel on the main thread. A large surface
|
|
108
|
+
* gets fewer, down to one per CSS pixel, so its map stays near `MAP_PIXELS` whatever the screen.
|
|
109
|
+
*/
|
|
110
|
+
const MAX_MAP_RATIO = 1.5;
|
|
111
|
+
const MAP_PIXELS = 120_000;
|
|
112
|
+
function mapRatio(width: number, height: number, dpr = window.devicePixelRatio || 1): number {
|
|
113
|
+
const room = Math.sqrt(MAP_PIXELS / Math.max(1, width * height));
|
|
114
|
+
return Math.max(1, Math.min(dpr, MAX_MAP_RATIO, room));
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* The specular map is not capped by area: only a thin rim of it is shaded, but the one-pixel
|
|
119
|
+
* contour and the glint are drawn in it, and at one pixel per CSS pixel on a dense screen they
|
|
120
|
+
* come out soft. It keeps the full ratio (up to {@link MAX_MAP_RATIO}) where the refraction map
|
|
121
|
+
* above has dropped to 1.
|
|
122
|
+
*/
|
|
123
|
+
function specularRatio(dpr = window.devicePixelRatio || 1): number {
|
|
124
|
+
return Math.max(1, Math.min(dpr, MAX_MAP_RATIO));
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** Minimum time between two rebuilds of the displacement map of one surface. */
|
|
128
|
+
const REBUILD_MS = 90;
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* The opt-in parts of the lens are their own lazy chunks, imported the first time a surface asks
|
|
132
|
+
* for them: a plain lens never loads the crystal layer or the dispersion passes.
|
|
133
|
+
*/
|
|
134
|
+
const features = {
|
|
135
|
+
crystal: undefined as typeof import("./lens-crystal.js") | undefined,
|
|
136
|
+
dispersion: undefined as typeof import("./lens-dispersion.js") | undefined,
|
|
137
|
+
};
|
|
138
|
+
const loaders = {
|
|
139
|
+
crystal: () => import("./lens-crystal.js"),
|
|
140
|
+
dispersion: () => import("./lens-dispersion.js"),
|
|
141
|
+
};
|
|
142
|
+
const pending = new Map<keyof typeof features, Promise<void>>();
|
|
143
|
+
/** Loads a feature once; resolves when it is there (a failed chunk leaves the plain liquid look). */
|
|
144
|
+
function loadFeature(name: keyof typeof features): Promise<void> {
|
|
145
|
+
let promise = pending.get(name);
|
|
146
|
+
if (!promise) {
|
|
147
|
+
promise = loaders[name]().then(
|
|
148
|
+
(module) => {
|
|
149
|
+
(features as Record<string, unknown>)[name] = module;
|
|
150
|
+
},
|
|
151
|
+
() => {},
|
|
152
|
+
);
|
|
153
|
+
pending.set(name, promise);
|
|
154
|
+
}
|
|
155
|
+
return promise;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
let counter = 0;
|
|
159
|
+
let active = 0;
|
|
160
|
+
/** Surfaces that are eligible but found no free slot; the next one is woken when a slot frees. */
|
|
161
|
+
const waiting = new Set<() => void>();
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Surfaces far outside the viewport give up their slot to visible ones. One observer for all of
|
|
165
|
+
* them; a change of side resyncs that surface.
|
|
166
|
+
*/
|
|
167
|
+
const offscreen = new WeakSet<Element>();
|
|
168
|
+
/** Surfaces the observer reported on at least once: until then a surface takes no slot. */
|
|
169
|
+
const placed = new WeakSet<Element>();
|
|
170
|
+
const resyncs = new WeakMap<Element, () => void>();
|
|
171
|
+
let viewport: IntersectionObserver | undefined;
|
|
172
|
+
function visibility(): IntersectionObserver | undefined {
|
|
173
|
+
if (typeof IntersectionObserver !== "function") return undefined;
|
|
174
|
+
viewport ??= new IntersectionObserver(
|
|
175
|
+
(entries) => {
|
|
176
|
+
for (const { target, isIntersecting } of entries) {
|
|
177
|
+
const first = !placed.has(target);
|
|
178
|
+
placed.add(target);
|
|
179
|
+
if (!first && offscreen.has(target) !== isIntersecting) continue;
|
|
180
|
+
if (isIntersecting) offscreen.delete(target);
|
|
181
|
+
else offscreen.add(target);
|
|
182
|
+
const resync = resyncs.get(target);
|
|
183
|
+
if (resync) schedule(resync);
|
|
184
|
+
}
|
|
185
|
+
},
|
|
186
|
+
{ rootMargin: "50%" },
|
|
187
|
+
);
|
|
188
|
+
return viewport;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Size changes are coalesced into one pass per frame, whatever the number of surfaces. A pass that
|
|
193
|
+
* has used its share of the frame leaves the rest for the next one, so the maps of several surfaces
|
|
194
|
+
* built at once (at load, on a slow phone) are spread over frames instead of one long task. A single
|
|
195
|
+
* task still runs whole: the budget is checked between tasks, not inside one.
|
|
196
|
+
*/
|
|
197
|
+
const dirty = new Set<() => void>();
|
|
198
|
+
let frame = 0;
|
|
199
|
+
const FRAME_BUDGET_MS = 12;
|
|
200
|
+
function flush() {
|
|
201
|
+
frame = 0;
|
|
202
|
+
const batch = [...dirty];
|
|
203
|
+
const started = performance.now();
|
|
204
|
+
let ran = 0;
|
|
205
|
+
for (const task of batch) {
|
|
206
|
+
if (ran > 0 && performance.now() - started > FRAME_BUDGET_MS) break;
|
|
207
|
+
// A task cancelled by an earlier one in this pass (a lens undone) is no longer in the set.
|
|
208
|
+
if (!dirty.delete(task)) continue;
|
|
209
|
+
ran++;
|
|
210
|
+
task();
|
|
211
|
+
}
|
|
212
|
+
// What is left keeps its place at the front, ahead of anything the tasks rescheduled (those are
|
|
213
|
+
// re-added at the end), so a task that always overruns the budget cannot starve the others.
|
|
214
|
+
if (dirty.size && !frame) frame = requestAnimationFrame(flush);
|
|
215
|
+
}
|
|
216
|
+
function schedule(run: () => void) {
|
|
217
|
+
dirty.add(run);
|
|
218
|
+
if (!frame) frame = requestAnimationFrame(flush);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const matches = (query: string) => typeof matchMedia === "function" && matchMedia(query).matches;
|
|
222
|
+
const userWantsLess = () => OFF_QUERIES.some(matches);
|
|
223
|
+
|
|
224
|
+
function host(): SVGSVGElement {
|
|
225
|
+
const existing = document.getElementById(HOST_ID);
|
|
226
|
+
if (existing) return existing as unknown as SVGSVGElement;
|
|
227
|
+
const svg = document.createElementNS(SVG_NS, "svg");
|
|
228
|
+
svg.id = HOST_ID;
|
|
229
|
+
svg.setAttribute("aria-hidden", "true");
|
|
230
|
+
svg.setAttribute("width", "0");
|
|
231
|
+
svg.setAttribute("height", "0");
|
|
232
|
+
svg.style.cssText = "position:absolute;width:0;height:0;pointer-events:none";
|
|
233
|
+
document.body.appendChild(svg);
|
|
234
|
+
return svg;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/** The lens settings the engine reads from `--liquid-*` custom properties. */
|
|
238
|
+
interface LiquidRuntime {
|
|
239
|
+
refraction: number;
|
|
240
|
+
bevel: number | undefined;
|
|
241
|
+
profile: LensCoverage | undefined;
|
|
242
|
+
dispersion: number | undefined;
|
|
243
|
+
specular: number;
|
|
244
|
+
angle: number;
|
|
245
|
+
opacity: number;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
const PROFILES = new Set(["rim", "full", "dome", "crystal"]);
|
|
249
|
+
|
|
250
|
+
function readRuntime(element: HTMLElement): LiquidRuntime {
|
|
251
|
+
const computed = getComputedStyle(element);
|
|
252
|
+
const read = (name: string) => computed.getPropertyValue(name).trim();
|
|
253
|
+
const number = (name: string) => {
|
|
254
|
+
const value = Number.parseFloat(read(name));
|
|
255
|
+
return Number.isFinite(value) ? value : undefined;
|
|
256
|
+
};
|
|
257
|
+
const clamp = (value: number, min: number, max: number) => Math.min(Math.max(value, min), max);
|
|
258
|
+
const profile = read("--liquid-profile") || read("--glass-lens-coverage");
|
|
259
|
+
const dispersion = number("--liquid-dispersion") ?? number("--glass-lens-dispersion");
|
|
260
|
+
return {
|
|
261
|
+
refraction: clamp(number("--liquid-refraction") ?? LIQUID_DEFAULTS.refraction, 0, 2),
|
|
262
|
+
bevel: number("--liquid-bevel"),
|
|
263
|
+
profile: PROFILES.has(profile) ? (profile as LensCoverage) : undefined,
|
|
264
|
+
dispersion: dispersion === undefined ? undefined : clamp(dispersion, 0, 0.2),
|
|
265
|
+
specular: clamp(number("--liquid-specular") ?? LIQUID_DEFAULTS.specular.intensity, 0, 2),
|
|
266
|
+
angle: number("--liquid-specular-angle") ?? LIQUID_DEFAULTS.specular.angle,
|
|
267
|
+
opacity: clamp(number("--liquid-opacity") ?? LIQUID_DEFAULTS.opacity, 0, 1),
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/** Variables whose change must rebuild the filter (the rest is read when the map is rebuilt). */
|
|
272
|
+
const WATCHED_VARS = [
|
|
273
|
+
"--liquid-refraction",
|
|
274
|
+
"--liquid-bevel",
|
|
275
|
+
"--liquid-profile",
|
|
276
|
+
"--glass-lens-coverage",
|
|
277
|
+
"--liquid-dispersion",
|
|
278
|
+
"--glass-lens-dispersion",
|
|
279
|
+
"--liquid-specular",
|
|
280
|
+
"--liquid-specular-angle",
|
|
281
|
+
"--liquid-opacity",
|
|
282
|
+
"--liquid-radius",
|
|
283
|
+
"--liquid-frost",
|
|
284
|
+
"--liquid-saturation",
|
|
285
|
+
"--liquid-brightness",
|
|
286
|
+
"--liquid-motion",
|
|
287
|
+
"--liquid-interactive",
|
|
288
|
+
];
|
|
289
|
+
/** What can change those variables on an element or an ancestor. */
|
|
290
|
+
const CONFIG_ATTRIBUTES = ["style", "class", "data-glass", "data-glass-lens"];
|
|
291
|
+
/** Inline properties the engine and its motion write on the surface itself every so often. */
|
|
292
|
+
const ENGINE_WRITES = new Set([
|
|
293
|
+
"translate",
|
|
294
|
+
"scale",
|
|
295
|
+
"touch-action",
|
|
296
|
+
"backdrop-filter",
|
|
297
|
+
"-webkit-backdrop-filter",
|
|
298
|
+
"--glass-veil",
|
|
299
|
+
"--glass-lens-tint",
|
|
300
|
+
"--liquid-size",
|
|
301
|
+
"--liquid-shadow-auto",
|
|
302
|
+
"position",
|
|
303
|
+
"isolation",
|
|
304
|
+
"overflow",
|
|
305
|
+
"box-shadow",
|
|
306
|
+
"background-image",
|
|
307
|
+
"background-color",
|
|
308
|
+
"--liquid-glow",
|
|
309
|
+
"--liquid-glow-x",
|
|
310
|
+
"--liquid-glow-y",
|
|
311
|
+
"--liquid-rim-auto",
|
|
312
|
+
]);
|
|
313
|
+
|
|
314
|
+
/** A `style` attribute without the declarations the engine writes itself. */
|
|
315
|
+
function authorStyle(text: string | null): string {
|
|
316
|
+
return (text ?? "")
|
|
317
|
+
.split(";")
|
|
318
|
+
.map((declaration) => declaration.trim())
|
|
319
|
+
.filter((declaration) => {
|
|
320
|
+
const name = declaration.slice(0, declaration.indexOf(":")).trim().toLowerCase();
|
|
321
|
+
return declaration !== "" && !ENGINE_WRITES.has(name);
|
|
322
|
+
})
|
|
323
|
+
.join(";");
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/** Who asked for a lens: code (`applyGlassRefraction`) or the page watcher (`<LiquidGlass />`). */
|
|
327
|
+
export type LensOwner = "manual" | "auto";
|
|
328
|
+
|
|
329
|
+
interface Controller {
|
|
330
|
+
/** Adds or updates the owner's claim; returns its release. The manual options win. */
|
|
331
|
+
claim(owner: LensOwner, options: GlassRefractionOptions): () => void;
|
|
332
|
+
/** The computed `backdrop-filter` of the surface without the engine's own inline writes. */
|
|
333
|
+
ownBackdropFilter(): string;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/** One controller per element, so applying twice never stacks a second `url()` filter. */
|
|
337
|
+
const controllers = new WeakMap<HTMLElement, Controller>();
|
|
338
|
+
|
|
339
|
+
function createController(element: HTMLElement): Controller {
|
|
340
|
+
const claims: Partial<Record<LensOwner, GlassRefractionOptions>> = {};
|
|
341
|
+
/** Bumped each time an owner's claim starts, so a release from an earlier claim is a no-op. */
|
|
342
|
+
const generation: Record<LensOwner, number> = { manual: 0, auto: 0 };
|
|
343
|
+
let options: GlassRefractionOptions = {};
|
|
344
|
+
let stopped = false;
|
|
345
|
+
let installed:
|
|
346
|
+
| { filter: SVGFilterElement; observer?: ResizeObserver; cancel: () => void }
|
|
347
|
+
| undefined;
|
|
348
|
+
/**
|
|
349
|
+
* Watches the size of an eligible surface that cannot take a lens for now (hidden, zero-area or
|
|
350
|
+
* too large), so it lenses once its size allows. Created once; only a real size change resyncs.
|
|
351
|
+
*/
|
|
352
|
+
let sizeWatch: ResizeObserver | undefined;
|
|
353
|
+
let sizeSeen = "";
|
|
354
|
+
const sizeKey = () => `${element.offsetWidth}x${element.offsetHeight}`;
|
|
355
|
+
const watchSize = () => {
|
|
356
|
+
if (sizeWatch || typeof ResizeObserver !== "function") return;
|
|
357
|
+
sizeSeen = sizeKey();
|
|
358
|
+
sizeWatch = new ResizeObserver(() => {
|
|
359
|
+
const now = sizeKey();
|
|
360
|
+
if (now === sizeSeen) return;
|
|
361
|
+
sizeSeen = now;
|
|
362
|
+
schedule(sync);
|
|
363
|
+
});
|
|
364
|
+
sizeWatch.observe(element);
|
|
365
|
+
};
|
|
366
|
+
/** The first install of a controller materialises; later ones (theme change) do not. */
|
|
367
|
+
let intro = true;
|
|
368
|
+
const original = element.style.backdropFilter;
|
|
369
|
+
const originalPrefixed = element.style.getPropertyValue("-webkit-backdrop-filter");
|
|
370
|
+
|
|
371
|
+
const flagged = () =>
|
|
372
|
+
!options.auto ||
|
|
373
|
+
(getComputedStyle(element).getPropertyValue("--glass-lens").trim() === "1" &&
|
|
374
|
+
!element.closest('[data-glass-lens="off"]') &&
|
|
375
|
+
getComputedStyle(element).backdropFilter !== "none");
|
|
376
|
+
|
|
377
|
+
const eligible = () =>
|
|
378
|
+
!userWantsLess() &&
|
|
379
|
+
(options.refraction === "force" || supportsBackdropRefraction()) &&
|
|
380
|
+
flagged();
|
|
381
|
+
|
|
382
|
+
/** Hands a freed slot to the first surface that was waiting for one. */
|
|
383
|
+
const wake = () => {
|
|
384
|
+
const next = waiting.values().next().value;
|
|
385
|
+
if (!next) return;
|
|
386
|
+
waiting.delete(next);
|
|
387
|
+
schedule(next);
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
/** The crystal lens lives on a layer that extends past the surface; `undo` puts the surface back. */
|
|
391
|
+
let crystalLens: CrystalLens | undefined;
|
|
392
|
+
|
|
393
|
+
const uninstall = () => {
|
|
394
|
+
if (!installed) return;
|
|
395
|
+
active--;
|
|
396
|
+
installed.observer?.disconnect();
|
|
397
|
+
installed.cancel();
|
|
398
|
+
installed.filter.remove();
|
|
399
|
+
const defs = document.getElementById(HOST_ID);
|
|
400
|
+
if (defs && !defs.querySelector("filter")) defs.remove();
|
|
401
|
+
installed = undefined;
|
|
402
|
+
element.style.backdropFilter = original;
|
|
403
|
+
if (originalPrefixed) element.style.setProperty("-webkit-backdrop-filter", originalPrefixed);
|
|
404
|
+
else element.style.removeProperty("-webkit-backdrop-filter");
|
|
405
|
+
delete element.dataset.glassRefraction;
|
|
406
|
+
crystalLens?.undo();
|
|
407
|
+
crystalLens = undefined;
|
|
408
|
+
element.style.removeProperty("--glass-veil");
|
|
409
|
+
element.style.removeProperty("--glass-lens-tint");
|
|
410
|
+
element.style.removeProperty("--liquid-size");
|
|
411
|
+
element.style.removeProperty("--liquid-shadow-auto");
|
|
412
|
+
};
|
|
413
|
+
|
|
414
|
+
/** `full` (default) bends the whole surface, `dome` is the round variant, `rim` only the bevel. */
|
|
415
|
+
const coverageFor = (): LensCoverage =>
|
|
416
|
+
options.coverage ?? readRuntime(element).profile ?? "full";
|
|
417
|
+
|
|
418
|
+
/** Dispersion is off unless asked for: `dispersion` option, or `--liquid-dispersion` in CSS. */
|
|
419
|
+
const dispersionFor = (area: number) => {
|
|
420
|
+
const asked = options.dispersion ?? readRuntime(element).dispersion ?? 0;
|
|
421
|
+
return area <= DISPERSION_AREA ? asked : 0;
|
|
422
|
+
};
|
|
423
|
+
|
|
424
|
+
const install = () => {
|
|
425
|
+
if (!element.isConnected) return;
|
|
426
|
+
const area = element.offsetWidth * element.offsetHeight;
|
|
427
|
+
if (area === 0 || area > MAX_AREA) {
|
|
428
|
+
// Hidden, empty or too large for the filter: no slot; look again when the size changes.
|
|
429
|
+
watchSize();
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
432
|
+
// Not painted, or far outside the viewport: no slot until that changes (the observers resync
|
|
433
|
+
// it). An automatic lens also waits for the first visibility report, so a surface that turns
|
|
434
|
+
// out to be offscreen never holds a slot for a frame; a lens applied by code starts at once.
|
|
435
|
+
if (getComputedStyle(element).visibility === "hidden") return;
|
|
436
|
+
if (offscreen.has(element) || (viewport && options.auto && !placed.has(element))) return;
|
|
437
|
+
if (active >= MAX_ACTIVE) {
|
|
438
|
+
waiting.add(sync);
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
sizeWatch?.disconnect();
|
|
442
|
+
sizeWatch = undefined;
|
|
443
|
+
const dispersion = dispersionFor(element.offsetWidth * element.offsetHeight);
|
|
444
|
+
const crystal = coverageFor() === "crystal";
|
|
445
|
+
const missing = [
|
|
446
|
+
...(crystal && !features.crystal ? [loadFeature("crystal")] : []),
|
|
447
|
+
...(dispersion > 0 && !features.dispersion ? [loadFeature("dispersion")] : []),
|
|
448
|
+
];
|
|
449
|
+
if (missing.length) {
|
|
450
|
+
// Keep the plain liquid look until the parts this surface needs have loaded.
|
|
451
|
+
Promise.all(missing).then(() => {
|
|
452
|
+
if ((features.crystal || !crystal) && (features.dispersion || dispersion <= 0))
|
|
453
|
+
schedule(sync);
|
|
454
|
+
});
|
|
455
|
+
return;
|
|
456
|
+
}
|
|
457
|
+
const displacers: Array<{ node: Element; factor: number }> = [];
|
|
458
|
+
let baseScale = options.scale ?? 0;
|
|
459
|
+
// The materialise plays only where it can be seen, not in the margin around the viewport.
|
|
460
|
+
const box = element.getBoundingClientRect();
|
|
461
|
+
const inView =
|
|
462
|
+
box.bottom > 0 && box.right > 0 && box.top < innerHeight && box.left < innerWidth;
|
|
463
|
+
let level = options.animate === false || !intro || !inView ? 1 : 0;
|
|
464
|
+
intro = false;
|
|
465
|
+
const applyScale = () => {
|
|
466
|
+
for (const { node: target, factor } of displacers)
|
|
467
|
+
target.setAttribute("scale", String(baseScale * factor * level));
|
|
468
|
+
};
|
|
469
|
+
let specularImage: SVGElement | undefined;
|
|
470
|
+
const id = `ui-glass-lens-${++counter}`;
|
|
471
|
+
const filter = document.createElementNS(SVG_NS, "filter");
|
|
472
|
+
filter.id = id;
|
|
473
|
+
filter.setAttribute("filterUnits", "userSpaceOnUse");
|
|
474
|
+
filter.setAttribute("color-interpolation-filters", "sRGB");
|
|
475
|
+
const node = (name: string, attrs: Record<string, string>) => {
|
|
476
|
+
const created = document.createElementNS(SVG_NS, name);
|
|
477
|
+
for (const [key, value] of Object.entries(attrs)) created.setAttribute(key, value);
|
|
478
|
+
filter.appendChild(created);
|
|
479
|
+
return created;
|
|
480
|
+
};
|
|
481
|
+
const image = node("feImage", { result: "map", preserveAspectRatio: "none" });
|
|
482
|
+
// A minifying lens shows several backdrop pixels per output pixel; without a touch of
|
|
483
|
+
// pre-filtering they alias into sparkle (and into rainbow noise with dispersion).
|
|
484
|
+
if (crystal)
|
|
485
|
+
node("feGaussianBlur", { in: "SourceGraphic", stdDeviation: "0.7", result: "pre" });
|
|
486
|
+
const displace = (channel: string, factor: number) =>
|
|
487
|
+
displacers.push({
|
|
488
|
+
node: node("feDisplacementMap", {
|
|
489
|
+
in: crystal ? "pre" : "SourceGraphic",
|
|
490
|
+
in2: "map",
|
|
491
|
+
scale: "0",
|
|
492
|
+
xChannelSelector: "R",
|
|
493
|
+
yChannelSelector: "G",
|
|
494
|
+
result: channel === "lens" ? "lens" : `d${channel}`,
|
|
495
|
+
}),
|
|
496
|
+
factor,
|
|
497
|
+
});
|
|
498
|
+
if (dispersion > 0 && features.dispersion)
|
|
499
|
+
features.dispersion.addDispersion({ node, displace }, dispersion, crystal);
|
|
500
|
+
else displace("lens", 1);
|
|
501
|
+
// Frosted middle, sharp rim: the blue channel of the map says how soft the backdrop is. The
|
|
502
|
+
// lens is blurred in here (not by the CSS blur, which would soften the rim too) and mixed
|
|
503
|
+
// back with the sharp lens by that weight.
|
|
504
|
+
const computed = getComputedStyle(element);
|
|
505
|
+
const runtime = readRuntime(element);
|
|
506
|
+
element.style.backdropFilter = original;
|
|
507
|
+
const base = getComputedStyle(element).backdropFilter;
|
|
508
|
+
const radius = /blur\(\s*([\d.]+)px\s*\)/.exec(base);
|
|
509
|
+
const rest = !base || base === "none" ? "" : `${base.replace(/blur\([^)]*\)\s*/, "").trim()} `;
|
|
510
|
+
const frosted = radius !== null && Number.parseFloat(radius[1] as string) > 0;
|
|
511
|
+
if (frosted) {
|
|
512
|
+
node("feColorMatrix", {
|
|
513
|
+
in: "map",
|
|
514
|
+
type: "matrix",
|
|
515
|
+
values: "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0",
|
|
516
|
+
result: "soft-weight",
|
|
517
|
+
});
|
|
518
|
+
node("feGaussianBlur", { in: "lens", stdDeviation: radius[1] as string, result: "soft" });
|
|
519
|
+
node("feComposite", { in: "soft", in2: "soft-weight", operator: "in", result: "soft-part" });
|
|
520
|
+
node("feComposite", {
|
|
521
|
+
in: "lens",
|
|
522
|
+
in2: "soft-weight",
|
|
523
|
+
operator: "out",
|
|
524
|
+
result: "sharp-part",
|
|
525
|
+
});
|
|
526
|
+
node("feComposite", {
|
|
527
|
+
in: "soft-part",
|
|
528
|
+
in2: "sharp-part",
|
|
529
|
+
operator: "arithmetic",
|
|
530
|
+
k1: "0",
|
|
531
|
+
k2: "1",
|
|
532
|
+
k3: "1",
|
|
533
|
+
k4: "0",
|
|
534
|
+
result: "mixed",
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
// The veil: the CSS veil is switched off (--glass-veil) and the same colour is flooded over
|
|
538
|
+
// the lens, a little lighter along the rim than under the text.
|
|
539
|
+
const veilColor =
|
|
540
|
+
options.veil === false ? "" : computed.getPropertyValue("--glass-lens-dim").trim();
|
|
541
|
+
const layers = [frosted ? "mixed" : "lens"];
|
|
542
|
+
const parts = /rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)(?:[\s,/]+([\d.]+%?))?/.exec(
|
|
543
|
+
veilColor,
|
|
544
|
+
);
|
|
545
|
+
if (parts) {
|
|
546
|
+
// Adaptive veil: only as strong as the backdrop needs. The lens is blurred wide, its
|
|
547
|
+
// luminance read, and a veil of the ink-contrasting colour is laid down where the backdrop
|
|
548
|
+
// is close to the ink (a light veil over dark areas in the light theme, a dark one over
|
|
549
|
+
// light areas in the dark theme). Over a backdrop that already contrasts with the text
|
|
550
|
+
// there is none, so the body stays clear instead of milky.
|
|
551
|
+
const [r, g, b] = [1, 2, 3].map((n) => Number(parts[n]) / 255) as [number, number, number];
|
|
552
|
+
const alphaPart = parts[4];
|
|
553
|
+
// The CSS value is tuned for the uniform veil of the fallback; the adaptive one needs less.
|
|
554
|
+
const strength =
|
|
555
|
+
0.85 *
|
|
556
|
+
runtime.opacity *
|
|
557
|
+
(alphaPart
|
|
558
|
+
? alphaPart.endsWith("%")
|
|
559
|
+
? Number.parseFloat(alphaPart) / 100
|
|
560
|
+
: Number(alphaPart)
|
|
561
|
+
: 1);
|
|
562
|
+
const lightVeil = (r + g + b) / 3 > 0.5;
|
|
563
|
+
const sign = lightVeil ? -1 : 1;
|
|
564
|
+
const base = lightVeil ? strength : 0;
|
|
565
|
+
if (strength > 0) {
|
|
566
|
+
node("feGaussianBlur", { in: "lens", stdDeviation: "7", result: "regional" });
|
|
567
|
+
node("feColorMatrix", {
|
|
568
|
+
in: "regional",
|
|
569
|
+
type: "matrix",
|
|
570
|
+
values: [
|
|
571
|
+
`0 0 0 0 ${r}`,
|
|
572
|
+
`0 0 0 0 ${g}`,
|
|
573
|
+
`0 0 0 0 ${b}`,
|
|
574
|
+
`${sign * 0.2126 * strength} ${sign * 0.7152 * strength} ${sign * 0.0722 * strength} 0 ${base}`,
|
|
575
|
+
].join(" "),
|
|
576
|
+
result: "adaptive",
|
|
577
|
+
});
|
|
578
|
+
node("feColorMatrix", {
|
|
579
|
+
in: "map",
|
|
580
|
+
type: "matrix",
|
|
581
|
+
values: `0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ${1 - VEIL_FLOOR} 0 ${VEIL_FLOOR}`,
|
|
582
|
+
result: "veil-weight",
|
|
583
|
+
});
|
|
584
|
+
node("feComposite", { in: "adaptive", in2: "veil-weight", operator: "in", result: "veil" });
|
|
585
|
+
layers.push("veil");
|
|
586
|
+
}
|
|
587
|
+
element.style.setProperty("--glass-veil", "transparent");
|
|
588
|
+
element.style.setProperty("--glass-lens-tint", "transparent");
|
|
589
|
+
}
|
|
590
|
+
// Directional rim light from a second map: a dark contour and a faint inner shadow, a glint
|
|
591
|
+
// that is the lensed backdrop itself pushed to a high saturation and brightness (so it takes
|
|
592
|
+
// the colour of what is behind the glass), and a touch of white on top of it.
|
|
593
|
+
const specular = options.specular !== false && runtime.specular > 0;
|
|
594
|
+
if (specular) {
|
|
595
|
+
specularImage = node("feImage", { result: "spec", preserveAspectRatio: "none" });
|
|
596
|
+
node("feColorMatrix", {
|
|
597
|
+
in: "spec",
|
|
598
|
+
type: "matrix",
|
|
599
|
+
values: "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.6 0.4 0 0",
|
|
600
|
+
result: "shade",
|
|
601
|
+
});
|
|
602
|
+
node("feColorMatrix", {
|
|
603
|
+
in: "spec",
|
|
604
|
+
type: "matrix",
|
|
605
|
+
values: `0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ${0.9 * runtime.specular} 0 0 0 0`,
|
|
606
|
+
result: "glint-mask",
|
|
607
|
+
});
|
|
608
|
+
node("feColorMatrix", { in: "lens", type: "saturate", values: "2.5", result: "glint-sat" });
|
|
609
|
+
const bright = node("feComponentTransfer", { in: "glint-sat", result: "glint-bright" });
|
|
610
|
+
for (const channel of ["feFuncR", "feFuncG", "feFuncB"]) {
|
|
611
|
+
const fn = document.createElementNS(SVG_NS, channel);
|
|
612
|
+
fn.setAttribute("type", "linear");
|
|
613
|
+
fn.setAttribute("slope", "1.6");
|
|
614
|
+
fn.setAttribute("intercept", "0.2");
|
|
615
|
+
bright.appendChild(fn);
|
|
616
|
+
}
|
|
617
|
+
node("feComposite", {
|
|
618
|
+
in: "glint-bright",
|
|
619
|
+
in2: "glint-mask",
|
|
620
|
+
operator: "in",
|
|
621
|
+
result: "glint-tint",
|
|
622
|
+
});
|
|
623
|
+
node("feFlood", {
|
|
624
|
+
"flood-color": "white",
|
|
625
|
+
"flood-opacity": "0.8",
|
|
626
|
+
result: "glint-white-flood",
|
|
627
|
+
});
|
|
628
|
+
node("feComposite", {
|
|
629
|
+
in: "glint-white-flood",
|
|
630
|
+
in2: "glint-mask",
|
|
631
|
+
operator: "in",
|
|
632
|
+
result: "glint-white",
|
|
633
|
+
});
|
|
634
|
+
layers.push("shade", "glint-tint", "glint-white");
|
|
635
|
+
}
|
|
636
|
+
if (layers.length > 1 || frosted) {
|
|
637
|
+
const merge = node("feMerge", {});
|
|
638
|
+
for (const input of layers) {
|
|
639
|
+
const mergeNode = document.createElementNS(SVG_NS, "feMergeNode");
|
|
640
|
+
mergeNode.setAttribute("in", input);
|
|
641
|
+
merge.appendChild(mergeNode);
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
host().appendChild(filter);
|
|
645
|
+
|
|
646
|
+
const blur = rest;
|
|
647
|
+
|
|
648
|
+
if (crystal && features.crystal)
|
|
649
|
+
crystalLens = features.crystal.installCrystal({
|
|
650
|
+
element,
|
|
651
|
+
id,
|
|
652
|
+
blur,
|
|
653
|
+
original,
|
|
654
|
+
filter,
|
|
655
|
+
image,
|
|
656
|
+
reinstall: () => schedule(sync),
|
|
657
|
+
resize: () => schedule(update),
|
|
658
|
+
});
|
|
659
|
+
|
|
660
|
+
let key = "";
|
|
661
|
+
let built = 0;
|
|
662
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
663
|
+
const update = () => {
|
|
664
|
+
if (!element.isConnected) return stop();
|
|
665
|
+
// Layout size, not the bounding box: an entrance transform must not rebuild the map.
|
|
666
|
+
const width = element.offsetWidth;
|
|
667
|
+
const height = element.offsetHeight;
|
|
668
|
+
if (!width || !height) return;
|
|
669
|
+
// The budgets are checked on every size, not only at install: a surface that grows past
|
|
670
|
+
// them (a dialog whose content arrives, an entrance that settles) drops the lens or its
|
|
671
|
+
// dispersion, and one that shrinks back under gets it.
|
|
672
|
+
if (width * height > MAX_AREA || dispersionFor(width * height) > 0 !== dispersion > 0)
|
|
673
|
+
return sync();
|
|
674
|
+
const radius = Number.parseFloat(getComputedStyle(element).borderTopLeftRadius) || 0;
|
|
675
|
+
const coverage = coverageFor();
|
|
676
|
+
const settings = readRuntime(element);
|
|
677
|
+
const whole = isWhole(coverage);
|
|
678
|
+
const bezel =
|
|
679
|
+
options.bezel ??
|
|
680
|
+
(whole ? undefined : settings.bevel) ??
|
|
681
|
+
bezelFor(radius, width, height, coverage);
|
|
682
|
+
const cap = whole ? (settings.bevel ?? FULL_CAP) : FULL_CAP;
|
|
683
|
+
const soft = bezelFor(radius, width, height, "rim");
|
|
684
|
+
const dpr = mapRatio(width, height);
|
|
685
|
+
// A bigger piece of glass is thicker: its shadow is deeper (see `liquidShadow`).
|
|
686
|
+
element.style.setProperty(
|
|
687
|
+
"--liquid-size",
|
|
688
|
+
String(
|
|
689
|
+
Math.round(Math.min(Math.max(Math.sqrt(width * height) / 240, 0.7), 1.5) * 100) / 100,
|
|
690
|
+
),
|
|
691
|
+
);
|
|
692
|
+
if (crystalLens) {
|
|
693
|
+
const scale = crystalLens.update(
|
|
694
|
+
width,
|
|
695
|
+
height,
|
|
696
|
+
radius,
|
|
697
|
+
settings.refraction,
|
|
698
|
+
dispersion,
|
|
699
|
+
dpr,
|
|
700
|
+
);
|
|
701
|
+
if (scale === undefined) return;
|
|
702
|
+
built = performance.now();
|
|
703
|
+
baseScale = scale;
|
|
704
|
+
applyScale();
|
|
705
|
+
return;
|
|
706
|
+
}
|
|
707
|
+
const next = [
|
|
708
|
+
width,
|
|
709
|
+
height,
|
|
710
|
+
radius,
|
|
711
|
+
bezel,
|
|
712
|
+
coverage,
|
|
713
|
+
cap,
|
|
714
|
+
Math.min(settings.refraction, 1),
|
|
715
|
+
dpr,
|
|
716
|
+
].join("x");
|
|
717
|
+
if (next === key) return;
|
|
718
|
+
key = next;
|
|
719
|
+
built = performance.now();
|
|
720
|
+
baseScale =
|
|
721
|
+
options.scale ??
|
|
722
|
+
scaleFor(width, height, bezel, coverage, cap) * Math.min(settings.refraction, 1);
|
|
723
|
+
applyScale();
|
|
724
|
+
for (const [target, name, value] of [
|
|
725
|
+
[filter, "x", "0"],
|
|
726
|
+
[filter, "y", "0"],
|
|
727
|
+
[filter, "width", String(width)],
|
|
728
|
+
[filter, "height", String(height)],
|
|
729
|
+
[image, "width", String(width)],
|
|
730
|
+
[image, "height", String(height)],
|
|
731
|
+
] as const)
|
|
732
|
+
target.setAttribute(name, value);
|
|
733
|
+
image.setAttribute(
|
|
734
|
+
"href",
|
|
735
|
+
createDisplacementMap({ width, height, radius, bezel, coverage, soft, cap, dpr }),
|
|
736
|
+
);
|
|
737
|
+
if (specularImage) {
|
|
738
|
+
specularImage.setAttribute("width", String(width));
|
|
739
|
+
specularImage.setAttribute("height", String(height));
|
|
740
|
+
specularImage.setAttribute(
|
|
741
|
+
"href",
|
|
742
|
+
createSpecularMap({
|
|
743
|
+
width,
|
|
744
|
+
height,
|
|
745
|
+
radius,
|
|
746
|
+
dpr: specularRatio(),
|
|
747
|
+
angle: runtime.angle,
|
|
748
|
+
}),
|
|
749
|
+
);
|
|
750
|
+
}
|
|
751
|
+
};
|
|
752
|
+
update();
|
|
753
|
+
const observer =
|
|
754
|
+
typeof ResizeObserver === "function"
|
|
755
|
+
? new ResizeObserver(() => {
|
|
756
|
+
// A removed element is released at once, whatever the throttle below says.
|
|
757
|
+
if (!element.isConnected) return stop();
|
|
758
|
+
// Rebuilding the map costs a few ms: while a surface is being resized, at most
|
|
759
|
+
// about ten rebuilds a second, and the last size always lands.
|
|
760
|
+
const wait = REBUILD_MS - (performance.now() - built);
|
|
761
|
+
if (wait <= 0) return schedule(update);
|
|
762
|
+
if (timer === undefined)
|
|
763
|
+
timer = setTimeout(() => {
|
|
764
|
+
timer = undefined;
|
|
765
|
+
schedule(update);
|
|
766
|
+
}, wait);
|
|
767
|
+
})
|
|
768
|
+
: undefined;
|
|
769
|
+
observer?.observe(element);
|
|
770
|
+
|
|
771
|
+
// Motion (see `./liquid-motion.js`): the lens materialises, a press deepens it, and the
|
|
772
|
+
// pointer modes move the surface. It drives `level`, the multiplier of the filter scale.
|
|
773
|
+
const motion =
|
|
774
|
+
options.animate === false
|
|
775
|
+
? undefined
|
|
776
|
+
: startLiquidMotion(
|
|
777
|
+
element,
|
|
778
|
+
{
|
|
779
|
+
onLevel(next) {
|
|
780
|
+
level = next;
|
|
781
|
+
applyScale();
|
|
782
|
+
},
|
|
783
|
+
},
|
|
784
|
+
{ materialize: level < 1, ownInteractive: options.ownInteractive },
|
|
785
|
+
);
|
|
786
|
+
if (!motion) {
|
|
787
|
+
// No motion (switched off, or not wanted): the lens is at full strength at once.
|
|
788
|
+
level = 1;
|
|
789
|
+
applyScale();
|
|
790
|
+
}
|
|
791
|
+
element.style.setProperty("--liquid-shadow-auto", liquidShadow());
|
|
792
|
+
element.style.backdropFilter = crystal ? "none" : `${blur}url(#${id})`;
|
|
793
|
+
element.style.setProperty("-webkit-backdrop-filter", crystal ? "none" : `${blur}url(#${id})`);
|
|
794
|
+
element.dataset.glassRefraction = "on";
|
|
795
|
+
installed = {
|
|
796
|
+
filter,
|
|
797
|
+
observer,
|
|
798
|
+
cancel: () => {
|
|
799
|
+
clearTimeout(timer);
|
|
800
|
+
timer = undefined;
|
|
801
|
+
dirty.delete(update);
|
|
802
|
+
motion?.dispose();
|
|
803
|
+
},
|
|
804
|
+
};
|
|
805
|
+
active++;
|
|
806
|
+
};
|
|
807
|
+
|
|
808
|
+
/**
|
|
809
|
+
* What the surface's own CSS resolves `backdrop-filter` to. While the lens is on, the inline
|
|
810
|
+
* value is the engine's (a url filter, or `none` for a crystal lens, whose filter is on its
|
|
811
|
+
* layer), so the author's inline value is put back for a moment to read the cascade.
|
|
812
|
+
*/
|
|
813
|
+
const ownBackdropFilter = () => {
|
|
814
|
+
if (!installed) return getComputedStyle(element).backdropFilter;
|
|
815
|
+
const css = element.style.cssText;
|
|
816
|
+
element.style.backdropFilter = original;
|
|
817
|
+
if (originalPrefixed) element.style.setProperty("-webkit-backdrop-filter", originalPrefixed);
|
|
818
|
+
else element.style.removeProperty("-webkit-backdrop-filter");
|
|
819
|
+
const own = getComputedStyle(element).backdropFilter;
|
|
820
|
+
element.style.cssText = css;
|
|
821
|
+
return own;
|
|
822
|
+
};
|
|
823
|
+
|
|
824
|
+
/** Bring the element in line with the current preferences, engine and tokens. */
|
|
825
|
+
function sync() {
|
|
826
|
+
if (stopped) return;
|
|
827
|
+
waiting.delete(sync);
|
|
828
|
+
const was = installed !== undefined;
|
|
829
|
+
uninstall();
|
|
830
|
+
if (eligible()) install();
|
|
831
|
+
if (was && !installed) wake();
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
const lists = [...OFF_QUERIES, ...REBUILD_QUERIES].map((q) => matchMedia(q));
|
|
835
|
+
for (const list of lists) list.addEventListener("change", sync);
|
|
836
|
+
const mutations = typeof MutationObserver === "function" ? new MutationObserver(sync) : undefined;
|
|
837
|
+
mutations?.observe(document.documentElement, {
|
|
838
|
+
attributes: true,
|
|
839
|
+
attributeFilter: REBUILD_ATTRIBUTES,
|
|
840
|
+
});
|
|
841
|
+
|
|
842
|
+
// Live configuration: when an element or an ancestor changes the variables the lens reads (a
|
|
843
|
+
// `style` prop, a preset on `data-glass`), the filter is rebuilt once the values really differ.
|
|
844
|
+
const configKey = () => {
|
|
845
|
+
const computed = getComputedStyle(element);
|
|
846
|
+
return WATCHED_VARS.map((name) =>
|
|
847
|
+
// An overlay's pointer mode is its own: what a scope sets above it does not count.
|
|
848
|
+
name === "--liquid-interactive" && options.ownInteractive
|
|
849
|
+
? element.style.getPropertyValue(name).trim()
|
|
850
|
+
: computed.getPropertyValue(name).trim(),
|
|
851
|
+
)
|
|
852
|
+
.concat(computed.visibility)
|
|
853
|
+
.join("|");
|
|
854
|
+
};
|
|
855
|
+
let configSeen = configKey();
|
|
856
|
+
const refresh = () => {
|
|
857
|
+
if (stopped) return;
|
|
858
|
+
const next = configKey();
|
|
859
|
+
if (next === configSeen) return;
|
|
860
|
+
configSeen = next;
|
|
861
|
+
sync();
|
|
862
|
+
};
|
|
863
|
+
/** The elements whose attributes are watched: the surface and its ancestors. */
|
|
864
|
+
let watched: Element[] = [];
|
|
865
|
+
const chain = () => {
|
|
866
|
+
const nodes: Element[] = [];
|
|
867
|
+
for (let node: Element | null = element; node; node = node.parentElement) nodes.push(node);
|
|
868
|
+
return nodes;
|
|
869
|
+
};
|
|
870
|
+
const sameChain = (nodes: Element[]) =>
|
|
871
|
+
nodes.length === watched.length && nodes.every((node, i) => node === watched[i]);
|
|
872
|
+
let styleSeen = element.getAttribute("style");
|
|
873
|
+
const configObserver =
|
|
874
|
+
typeof MutationObserver === "function"
|
|
875
|
+
? new MutationObserver((records) => {
|
|
876
|
+
let relevant = false;
|
|
877
|
+
for (const record of records) {
|
|
878
|
+
if (record.type === "childList") {
|
|
879
|
+
// Moved to another parent (or an ancestor was): watch the new chain.
|
|
880
|
+
const moved = (nodes: NodeList) => [...nodes].some((node) => node.contains(element));
|
|
881
|
+
if (moved(record.addedNodes) || moved(record.removedNodes)) relevant = true;
|
|
882
|
+
continue;
|
|
883
|
+
}
|
|
884
|
+
// The motion rewrites the surface's own `style` every frame: not a configuration change.
|
|
885
|
+
if (record.target === element && record.attributeName === "style") {
|
|
886
|
+
const now = element.getAttribute("style");
|
|
887
|
+
if (authorStyle(now) === authorStyle(styleSeen)) {
|
|
888
|
+
styleSeen = now;
|
|
889
|
+
continue;
|
|
890
|
+
}
|
|
891
|
+
styleSeen = now;
|
|
892
|
+
}
|
|
893
|
+
relevant = true;
|
|
894
|
+
}
|
|
895
|
+
if (!relevant) return;
|
|
896
|
+
if (!sameChain(chain())) watch();
|
|
897
|
+
schedule(refresh);
|
|
898
|
+
})
|
|
899
|
+
: undefined;
|
|
900
|
+
/** (Re)observe the surface and its ancestors; childList of each catches a move of the chain. */
|
|
901
|
+
function watch() {
|
|
902
|
+
configObserver?.disconnect();
|
|
903
|
+
watched = chain();
|
|
904
|
+
for (const node of watched)
|
|
905
|
+
configObserver?.observe(node, {
|
|
906
|
+
attributes: true,
|
|
907
|
+
attributeFilter: CONFIG_ATTRIBUTES,
|
|
908
|
+
childList: node !== element,
|
|
909
|
+
});
|
|
910
|
+
}
|
|
911
|
+
watch();
|
|
912
|
+
|
|
913
|
+
function stop() {
|
|
914
|
+
if (stopped) return;
|
|
915
|
+
stopped = true;
|
|
916
|
+
for (const list of lists) list.removeEventListener("change", sync);
|
|
917
|
+
configObserver?.disconnect();
|
|
918
|
+
mutations?.disconnect();
|
|
919
|
+
waiting.delete(sync);
|
|
920
|
+
dirty.delete(sync);
|
|
921
|
+
dirty.delete(refresh);
|
|
922
|
+
sizeWatch?.disconnect();
|
|
923
|
+
sizeWatch = undefined;
|
|
924
|
+
viewport?.unobserve(element);
|
|
925
|
+
resyncs.delete(element);
|
|
926
|
+
offscreen.delete(element);
|
|
927
|
+
placed.delete(element);
|
|
928
|
+
const was = installed !== undefined;
|
|
929
|
+
uninstall();
|
|
930
|
+
if (was) wake();
|
|
931
|
+
controllers.delete(element);
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
resyncs.set(element, sync);
|
|
935
|
+
visibility()?.observe(element);
|
|
936
|
+
|
|
937
|
+
const apply = () => {
|
|
938
|
+
const next = claims.manual ?? claims.auto;
|
|
939
|
+
if (!next) return stop();
|
|
940
|
+
options = next;
|
|
941
|
+
configSeen = configKey();
|
|
942
|
+
sync();
|
|
943
|
+
};
|
|
944
|
+
return {
|
|
945
|
+
ownBackdropFilter,
|
|
946
|
+
claim(owner, next) {
|
|
947
|
+
if (!claims[owner]) generation[owner]++;
|
|
948
|
+
const claimed = generation[owner];
|
|
949
|
+
claims[owner] = next;
|
|
950
|
+
apply();
|
|
951
|
+
return () => {
|
|
952
|
+
if (stopped || generation[owner] !== claimed || !claims[owner]) return;
|
|
953
|
+
delete claims[owner];
|
|
954
|
+
apply();
|
|
955
|
+
};
|
|
956
|
+
},
|
|
957
|
+
};
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
/**
|
|
961
|
+
* Opt-in lensing for a glass surface (`glass`, `glass-clear`, `surface-overlay`): bends the
|
|
962
|
+
* backdrop along the rim with an SVG displacement filter and marks the element
|
|
963
|
+
* `data-glass-refraction="on"`.
|
|
964
|
+
*
|
|
965
|
+
* It does nothing, and leaves the plain blur, where the engine cannot paint it. It also follows
|
|
966
|
+
* the user's preferences live: reduced transparency, more contrast, forced colors or reduced
|
|
967
|
+
* motion remove it, and clearing them brings it back. Calling it again on the same element
|
|
968
|
+
* updates the options instead of stacking a second filter. Returns the cleanup function (every
|
|
969
|
+
* returned cleanup ends the same claim). These options win over `<LiquidGlass />` on the same
|
|
970
|
+
* element, and the watcher never stops this lens; after the cleanup, a surface the watcher also
|
|
971
|
+
* lenses keeps its automatic lens. Never on by default: it re-rasterises the
|
|
972
|
+
* backdrop every frame.
|
|
973
|
+
*/
|
|
974
|
+
export function applyGlassRefraction(
|
|
975
|
+
element: HTMLElement,
|
|
976
|
+
options: GlassRefractionOptions = {},
|
|
977
|
+
): () => void {
|
|
978
|
+
return claimLens(element, "manual", options);
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
/**
|
|
982
|
+
* The `backdrop-filter` the surface's own styles resolve to, as if no lens were on it (the engine
|
|
983
|
+
* replaces the inline value, and a crystal lens moves the filter to its layer). It is how the
|
|
984
|
+
* watcher tells a lensed surface that still paints a backdrop from one that merely inherits the
|
|
985
|
+
* `--glass-lens` flag after its own liquid class stopped applying.
|
|
986
|
+
*/
|
|
987
|
+
export function ownBackdropFilter(element: HTMLElement): string {
|
|
988
|
+
return controllers.get(element)?.ownBackdropFilter() ?? getComputedStyle(element).backdropFilter;
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
/**
|
|
992
|
+
* Adds a claim on the element's lens for `owner` and returns its release. One controller per
|
|
993
|
+
* element: the manual options win over the automatic ones, and the lens stops only once every
|
|
994
|
+
* owner released it, so `<LiquidGlass />` never undoes or replaces a lens applied by code. Every
|
|
995
|
+
* release of one owner's claim ends that claim; a release left over from an earlier claim is a
|
|
996
|
+
* no-op.
|
|
997
|
+
*/
|
|
998
|
+
export function claimLens(
|
|
999
|
+
element: HTMLElement,
|
|
1000
|
+
owner: LensOwner,
|
|
1001
|
+
options: GlassRefractionOptions,
|
|
1002
|
+
): () => void {
|
|
1003
|
+
if (typeof document === "undefined" || typeof matchMedia !== "function") return () => {};
|
|
1004
|
+
let controller = controllers.get(element);
|
|
1005
|
+
if (!controller) {
|
|
1006
|
+
controller = createController(element);
|
|
1007
|
+
controllers.set(element, controller);
|
|
1008
|
+
}
|
|
1009
|
+
return controller.claim(owner, options);
|
|
1010
|
+
}
|