@zyncat/ui 0.15.0 → 0.18.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/README.md +32 -202
- package/dist/alert.css +1 -1
- package/dist/alert.js +18 -10
- package/dist/alert.js.map +1 -1
- package/dist/avatar.css +3 -2
- package/dist/badge.css +1 -1
- package/dist/bloom-HV23M4AW.js +81 -0
- package/dist/bloom-HV23M4AW.js.map +1 -0
- package/dist/button.css +38 -31
- package/dist/button.js +4 -1
- package/dist/checkbox.css +1 -1
- package/dist/{chunk-5W5TKANX.js → chunk-2DNKZ57E.js} +3 -3
- package/dist/{chunk-5W5TKANX.js.map → chunk-2DNKZ57E.js.map} +1 -1
- package/dist/chunk-2YGHPQ66.js +16 -0
- package/dist/chunk-2YGHPQ66.js.map +1 -0
- package/dist/{chunk-N2GJEO5Z.js → chunk-6H3IJ752.js} +24 -9
- package/dist/chunk-6H3IJ752.js.map +1 -0
- package/dist/chunk-7NHY2CRA.js +132 -0
- package/dist/chunk-7NHY2CRA.js.map +1 -0
- package/dist/{chunk-PWQVSVXR.js → chunk-AIAPXRCI.js} +20 -19
- package/dist/chunk-AIAPXRCI.js.map +1 -0
- package/dist/{chunk-K45CWVHS.js → chunk-BRKGYLEQ.js} +12 -9
- package/dist/chunk-BRKGYLEQ.js.map +1 -0
- package/dist/{chunk-MDSRZ4QR.js → chunk-C3D32LE3.js} +6 -5
- package/dist/chunk-C3D32LE3.js.map +1 -0
- package/dist/chunk-F2TB3TT6.js +103 -0
- package/dist/chunk-F2TB3TT6.js.map +1 -0
- package/dist/{chunk-FVPNICF4.js → chunk-F64Z42PJ.js} +6 -6
- package/dist/{chunk-FVPNICF4.js.map → chunk-F64Z42PJ.js.map} +1 -1
- package/dist/{chunk-QGVFFT2B.js → chunk-HBWRKEW4.js} +3 -3
- package/dist/{chunk-QGVFFT2B.js.map → chunk-HBWRKEW4.js.map} +1 -1
- package/dist/{chunk-CAXQJSIE.js → chunk-JINATP4N.js} +13 -13
- package/dist/chunk-JINATP4N.js.map +1 -0
- package/dist/chunk-KSAJ6DED.js +16 -0
- package/dist/chunk-KSAJ6DED.js.map +1 -0
- package/dist/{chunk-BH4JFWXQ.js → chunk-M2KGLH2G.js} +19 -16
- package/dist/chunk-M2KGLH2G.js.map +1 -0
- package/dist/{chunk-6X3G4GIM.js → chunk-N43NDSME.js} +3 -3
- package/dist/{chunk-6X3G4GIM.js.map → chunk-N43NDSME.js.map} +1 -1
- package/dist/chunk-NYQQH4R5.js +40 -0
- package/dist/chunk-NYQQH4R5.js.map +1 -0
- package/dist/{chunk-BTF6DAE3.js → chunk-ODRO3KS6.js} +4 -4
- package/dist/{chunk-BTF6DAE3.js.map → chunk-ODRO3KS6.js.map} +1 -1
- package/dist/chunk-PXQBJMPJ.js +50 -0
- package/dist/chunk-PXQBJMPJ.js.map +1 -0
- package/dist/{chunk-GJTHWB6O.js → chunk-QDAN43B6.js} +3 -3
- package/dist/{chunk-GJTHWB6O.js.map → chunk-QDAN43B6.js.map} +1 -1
- package/dist/{chunk-RBSHRRNO.js → chunk-RJENXXTI.js} +5 -5
- package/dist/{chunk-RBSHRRNO.js.map → chunk-RJENXXTI.js.map} +1 -1
- package/dist/chunk-RLNCRDAL.js +89 -0
- package/dist/chunk-RLNCRDAL.js.map +1 -0
- package/dist/{chunk-GOLSYGRA.js → chunk-TBLPZQSI.js} +84 -48
- package/dist/chunk-TBLPZQSI.js.map +1 -0
- package/dist/{chunk-WZUTBJC4.js → chunk-TDHLZY6I.js} +23 -5
- package/dist/chunk-TDHLZY6I.js.map +1 -0
- package/dist/chunk-TP2AC5MQ.js +13 -0
- package/dist/chunk-TP2AC5MQ.js.map +1 -0
- package/dist/chunk-TRPAKUIB.js +196 -0
- package/dist/chunk-TRPAKUIB.js.map +1 -0
- package/dist/{chunk-5X3MJRIM.js → chunk-UKPX3RIP.js} +3 -3
- package/dist/{chunk-5X3MJRIM.js.map → chunk-UKPX3RIP.js.map} +1 -1
- package/dist/{chunk-5GBV45YD.js → chunk-V6QAAOA5.js} +3 -3
- package/dist/{chunk-5GBV45YD.js.map → chunk-V6QAAOA5.js.map} +1 -1
- package/dist/{chunk-FLQVOSFC.js → chunk-VJXP256V.js} +10 -10
- package/dist/chunk-VJXP256V.js.map +1 -0
- package/dist/{chunk-IUQAUBVM.js → chunk-VQFILXQN.js} +5 -5
- package/dist/chunk-VQFILXQN.js.map +1 -0
- package/dist/{chunk-CFRGQJ23.js → chunk-VZXML7EH.js} +4 -4
- package/dist/{chunk-CFRGQJ23.js.map → chunk-VZXML7EH.js.map} +1 -1
- package/dist/{chunk-FEXUS4SV.js → chunk-XKDR22VE.js} +11 -5
- package/dist/chunk-XKDR22VE.js.map +1 -0
- package/dist/cli.js +262 -45
- package/dist/collapse.css +8 -5
- package/dist/confetti.css +3 -3
- package/dist/confetti.js +2 -2
- package/dist/date-field.js +20 -18
- package/dist/date-field.js.map +1 -1
- package/dist/date-picker.css +168 -43
- package/dist/date-range-field.js +42 -27
- package/dist/date-range-field.js.map +1 -1
- package/dist/datetime-field.js +21 -19
- package/dist/datetime-field.js.map +1 -1
- package/dist/dialog.css +4 -3
- package/dist/dialog.js +12 -12
- package/dist/dialog.js.map +1 -1
- package/dist/digit-strip.css +1 -1
- package/dist/dropdown.css +1 -1
- package/dist/dropdown.js +16 -16
- package/dist/dropdown.js.map +1 -1
- package/dist/emoji-picker.js +41 -26
- package/dist/emoji-picker.js.map +1 -1
- package/dist/facebook-feed.css +1 -1
- package/dist/flow-field.css +4 -4
- package/dist/flow-field.js +3 -3
- package/dist/flow-field.js.map +1 -1
- package/dist/glide.js +3 -3
- package/dist/icon.css +1 -1
- package/dist/input.css +7 -4
- package/dist/instagram-feed.css +1 -1
- package/dist/instagram-feed.js +2 -2
- package/dist/lens.css +1 -2
- package/dist/lens.js +2 -2
- package/dist/mcp.js +1 -1
- package/dist/menu-surface.css +1 -1
- package/dist/modal.css +1 -1
- package/dist/modal.js +10 -10
- package/dist/modal.js.map +1 -1
- package/dist/morphing-text.css +2 -2
- package/dist/morphing-text.js +2 -2
- package/dist/motion-devtools.css +77 -2
- package/dist/motion-devtools.js +194 -37
- package/dist/motion-devtools.js.map +1 -1
- package/dist/motion-tokens.js +1 -1
- package/dist/multi-select.js +12 -12
- package/dist/number-field.js +3 -3
- package/dist/odometer.css +1 -1
- package/dist/odometer.js +2 -2
- package/dist/overlay.css +1 -1
- package/dist/pagination.css +1 -1
- package/dist/pagination.js +6 -4
- package/dist/pagination.js.map +1 -1
- package/dist/paint-CJQCM6ZO.js +260 -0
- package/dist/paint-CJQCM6ZO.js.map +1 -0
- package/dist/popover.css +1 -1
- package/dist/popover.js +10 -10
- package/dist/radio-group.css +6 -4
- package/dist/radio-group.js +6 -6
- package/dist/select.css +1 -1
- package/dist/select.js +12 -12
- package/dist/sheet.css +1 -1
- package/dist/sheet.js +9 -9
- package/dist/spinner.css +115 -0
- package/dist/spinner.js +4 -0
- package/dist/spinner.js.map +1 -0
- package/dist/status-badge.js +2 -2
- package/dist/styles.css +1 -1
- package/dist/support-rail.css +76 -238
- package/dist/support-rail.js +99 -107
- package/dist/support-rail.js.map +1 -1
- package/dist/table.css +2 -2
- package/dist/table.js +8 -6
- package/dist/table.js.map +1 -1
- package/dist/tabs.css +10 -14
- package/dist/tabs.js +17 -11
- package/dist/tabs.js.map +1 -1
- package/dist/tag.css +1 -1
- package/dist/tag.js +6 -6
- package/dist/text-field.js +3 -3
- package/dist/textarea.css +1 -1
- package/dist/textarea.js +2 -2
- package/dist/theme-grid.js +11 -0
- package/dist/theme-grid.js.map +1 -0
- package/dist/theme-switcher.css +107 -0
- package/dist/theme-switcher.js +70 -0
- package/dist/theme-switcher.js.map +1 -0
- package/dist/theme-transition-VGLPZDJI.js +346 -0
- package/dist/theme-transition-VGLPZDJI.js.map +1 -0
- package/dist/theme-transition.css +48 -0
- package/dist/theme.js +57 -26
- package/dist/theme.js.map +1 -1
- package/dist/tide-DJZMDAFT.js +57 -0
- package/dist/tide-DJZMDAFT.js.map +1 -0
- package/dist/tiktok.css +2 -3
- package/dist/tiktok.js +2 -2
- package/dist/time-field.js +4 -4
- package/dist/toast.css +2 -14
- package/dist/toast.js +12 -10
- package/dist/toast.js.map +1 -1
- package/dist/toggle-tag.js +2 -2
- package/dist/toggle.css +1 -1
- package/dist/tooltip.css +1 -1
- package/dist/tooltip.js +25 -22
- package/dist/tooltip.js.map +1 -1
- package/dist/trigger.css +1 -1
- package/dist/types/components/composites/date-picker/month-jump.d.ts +11 -0
- package/dist/types/components/composites/theme-switcher/ThemeGrid.d.ts +20 -0
- package/dist/types/components/composites/theme-switcher/ThemeSwitcher.d.ts +24 -0
- package/dist/types/components/compound/support-rail/SupportRail.d.ts +10 -8
- package/dist/types/components/dev/MotionDevtools.d.ts +10 -5
- package/dist/types/components/expressive/theme-transition/bloom.d.ts +2 -0
- package/dist/types/components/expressive/theme-transition/paint.d.ts +2 -0
- package/dist/types/components/expressive/theme-transition/scene.d.ts +24 -0
- package/dist/types/components/expressive/theme-transition/theme-transition.d.ts +19 -0
- package/dist/types/components/expressive/theme-transition/tide.d.ts +2 -0
- package/dist/types/components/internal/hooks/use-press-feedback.d.ts +7 -0
- package/dist/types/components/internal/icon/Icon.d.ts +1 -0
- package/dist/types/components/internal/overlay/layer.d.ts +7 -1
- package/dist/types/components/internal/utils/token-px.d.ts +1 -1
- package/dist/types/components/primitives/button/Button.d.ts +9 -12
- package/dist/types/components/primitives/button/button-style.d.ts +15 -0
- package/dist/types/components/primitives/spinner/Spinner.d.ts +27 -0
- package/dist/types/engine/animate.d.ts +1 -0
- package/dist/types/motion/motion-timing.d.ts +1 -1
- package/dist/types/tokens/component-styles.generated.d.ts +35 -38
- package/dist/types/tokens/motion-tokens.d.ts +5 -3
- package/dist/types/tokens/theme-store.d.ts +47 -0
- package/dist/types/tokens/theme-sync.d.ts +7 -1
- package/dist/types/tokens/theme-tokens.generated.d.ts +125 -115
- package/dist/types/tokens/theme.d.ts +28 -5
- package/dist/typing-lines.css +1 -1
- package/dist/typing-lines.js +2 -2
- package/dist/typing-lines.js.map +1 -1
- package/dist/weight-field.css +2 -2
- package/dist/youtube.css +1 -1
- package/dist/youtube.js +2 -2
- package/package.json +20 -24
- package/skills/zyncat-ui/SKILL.md +1 -1
- package/skills/zyncat-ui/references/components.md +5 -2
- package/skills/zyncat-ui/references/theming.md +31 -23
- package/src/components/composites/alert/Alert.tsx +7 -3
- package/src/components/composites/alert/alert.css +1 -1
- package/src/components/composites/date-picker/calendar-panel.tsx +10 -4
- package/src/components/composites/date-picker/date-picker.css +168 -43
- package/src/components/composites/date-picker/month-jump.tsx +192 -0
- package/src/components/composites/date-picker/range-panel.tsx +20 -5
- package/src/components/composites/dialog/Dialog.tsx +2 -2
- package/src/components/composites/dialog/dialog.css +4 -3
- package/src/components/composites/dropdown/Dropdown.tsx +5 -5
- package/src/components/composites/dropdown/dropdown.css +1 -1
- package/src/components/composites/emoji-picker/react/category-bar.tsx +17 -5
- package/src/components/composites/emoji-picker/scaffold.ts +6 -5
- package/src/components/composites/emoji-picker/styles.css +1 -1
- package/src/components/composites/modal/Modal.tsx +2 -2
- package/src/components/composites/modal/modal.css +1 -1
- package/src/components/composites/pagination/pagination.css +1 -1
- package/src/components/composites/popover/Popover.tsx +5 -5
- package/src/components/composites/popover/popover.css +1 -1
- package/src/components/composites/select/core/menu.tsx +15 -10
- package/src/components/composites/select/select.css +1 -1
- package/src/components/composites/sheet/Sheet.tsx +2 -2
- package/src/components/composites/sheet/sheet.css +1 -1
- package/src/components/composites/table/table.css +2 -2
- package/src/components/composites/tabs/Tabs.tsx +13 -7
- package/src/components/composites/tabs/tabs.css +10 -14
- package/src/components/composites/theme-switcher/ThemeGrid.tsx +133 -0
- package/src/components/composites/theme-switcher/ThemeGrid.usage.md +20 -0
- package/src/components/composites/theme-switcher/ThemeSwitcher.tsx +75 -0
- package/src/components/composites/theme-switcher/ThemeSwitcher.usage.md +21 -0
- package/src/components/composites/theme-switcher/theme-switcher.css +107 -0
- package/src/components/composites/toast/Toast.tsx +2 -1
- package/src/components/composites/toast/toast.css +2 -14
- package/src/components/composites/tooltip/tooltip-host.tsx +19 -17
- package/src/components/composites/tooltip/tooltip.css +1 -1
- package/src/components/compound/support-rail/SupportRail.tsx +116 -128
- package/src/components/compound/support-rail/SupportRail.usage.md +7 -6
- package/src/components/compound/support-rail/support-rail.css +76 -238
- package/src/components/dev/MotionDevtools.tsx +252 -42
- package/src/components/dev/MotionDevtools.usage.md +12 -4
- package/src/components/dev/motion-devtools.css +77 -2
- package/src/components/dev/slowmo-engine.ts +1 -1
- package/src/components/expressive/confetti/confetti.css +3 -3
- package/src/components/expressive/facebook-feed/facebook-feed.css +1 -1
- package/src/components/expressive/flow-field/FlowField.tsx +1 -1
- package/src/components/expressive/flow-field/flow-field.css +4 -4
- package/src/components/expressive/instagram-feed/instagram-feed.css +1 -1
- package/src/components/expressive/lens/lens.css +1 -2
- package/src/components/expressive/morphing-text/morphing-text.css +2 -2
- package/src/components/expressive/odometer/odometer.css +1 -1
- package/src/components/expressive/theme-transition/bloom.ts +88 -0
- package/src/components/expressive/theme-transition/paint.ts +296 -0
- package/src/components/expressive/theme-transition/scene.ts +38 -0
- package/src/components/expressive/theme-transition/theme-transition.css +48 -0
- package/src/components/expressive/theme-transition/theme-transition.ts +423 -0
- package/src/components/expressive/theme-transition/tide.ts +65 -0
- package/src/components/expressive/tiktok/tiktok.css +2 -3
- package/src/components/expressive/typing-lines/TypingLines.tsx +0 -0
- package/src/components/expressive/typing-lines/typing-lines.css +1 -1
- package/src/components/expressive/weight-field/weight-field.css +2 -2
- package/src/components/expressive/youtube/youtube.css +1 -1
- package/src/components/internal/glass/glass.css +1 -1
- package/src/components/internal/hooks/use-press-feedback.ts +52 -0
- package/src/components/internal/icon/Icon.tsx +2 -0
- package/src/components/internal/icon/icon.css +1 -1
- package/src/components/internal/menu/menu-surface.css +1 -1
- package/src/components/internal/overlay/layer.tsx +35 -2
- package/src/components/internal/overlay/overlay.css +1 -1
- package/src/components/internal/overlay/position.ts +2 -2
- package/src/components/internal/overlay/trigger.css +1 -1
- package/src/components/internal/utils/token-px.ts +4 -4
- package/src/components/primitives/avatar/avatar.css +3 -2
- package/src/components/primitives/badge/badge.css +1 -1
- package/src/components/primitives/badge/digit-strip.css +1 -1
- package/src/components/primitives/button/Button.tsx +28 -27
- package/src/components/primitives/button/button-style.ts +28 -0
- package/src/components/primitives/button/button.css +38 -31
- package/src/components/primitives/checkbox/checkbox.css +1 -1
- package/src/components/primitives/collapse/collapse.css +8 -5
- package/src/components/primitives/input/input.css +7 -4
- package/src/components/primitives/radio-group/radio-group.css +6 -4
- package/src/components/primitives/spinner/Spinner.tsx +70 -0
- package/src/components/primitives/spinner/Spinner.usage.md +19 -0
- package/src/components/primitives/spinner/spinner.css +115 -0
- package/src/components/primitives/tag/tag.css +1 -1
- package/src/components/primitives/textarea/textarea.css +1 -1
- package/src/components/primitives/toggle/toggle.css +1 -1
- package/src/engine/animate.ts +10 -2
- package/src/mcp/server.ts +2 -1
- package/src/motion/glide.tsx +9 -6
- package/src/motion/motion-timing.ts +5 -2
- package/src/styles.css +3 -4
- package/src/tokens/base.css +5 -5
- package/src/tokens/color.css +8 -9
- package/src/tokens/component-styles.generated.ts +36 -38
- package/src/tokens/dark.css +8 -13
- package/src/tokens/decisions.css +9 -12
- package/src/tokens/elevation.css +18 -26
- package/src/tokens/glass.css +3 -2
- package/src/tokens/motion-defaults.generated.ts +1 -1
- package/src/tokens/motion-tokens.ts +27 -8
- package/src/tokens/motion.css +9 -9
- package/src/tokens/radius.css +3 -2
- package/src/tokens/reset.css +36 -0
- package/src/tokens/semantic.css +12 -22
- package/src/tokens/spacing.css +1 -1
- package/src/tokens/theme-store.ts +187 -0
- package/src/tokens/theme-sync.tsx +49 -2
- package/src/tokens/theme-tokens.generated.ts +128 -116
- package/src/tokens/theme.tsx +96 -24
- package/src/tokens/theme.usage.md +25 -24
- package/src/tokens/typography.css +4 -3
- package/tailwind.css +8 -14
- package/dist/chunk-6SUHSSOK.js +0 -25
- package/dist/chunk-6SUHSSOK.js.map +0 -1
- package/dist/chunk-BH4JFWXQ.js.map +0 -1
- package/dist/chunk-CAXQJSIE.js.map +0 -1
- package/dist/chunk-FEXUS4SV.js.map +0 -1
- package/dist/chunk-FLQVOSFC.js.map +0 -1
- package/dist/chunk-GOLSYGRA.js.map +0 -1
- package/dist/chunk-IUQAUBVM.js.map +0 -1
- package/dist/chunk-K45CWVHS.js.map +0 -1
- package/dist/chunk-MDSRZ4QR.js.map +0 -1
- package/dist/chunk-N2GJEO5Z.js.map +0 -1
- package/dist/chunk-PWQVSVXR.js.map +0 -1
- package/dist/chunk-UE63OOVG.js +0 -13
- package/dist/chunk-UE63OOVG.js.map +0 -1
- package/dist/chunk-UYSXJ7MH.js +0 -52
- package/dist/chunk-UYSXJ7MH.js.map +0 -1
- package/dist/chunk-WZUTBJC4.js.map +0 -1
- package/src/tokens/fonts.css +0 -1
package/src/tokens/glass.css
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
@layer zyncat.tokens, zyncat.components;
|
|
1
|
+
@layer zyncat.reset, zyncat.tokens, zyncat.components;
|
|
2
2
|
|
|
3
3
|
@layer zyncat.tokens {
|
|
4
4
|
:root {
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
:root,
|
|
14
|
-
[data-theme]
|
|
14
|
+
[data-theme],
|
|
15
|
+
[data-polarity] {
|
|
15
16
|
--glass-sheen: linear-gradient(
|
|
16
17
|
145deg,
|
|
17
18
|
rgb(255 255 255 / calc(0.55 * var(--sheen-strength))) 0%,
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* Generated from the token and component CSS by `scripts/gen-theme.mjs` - `pnpm sync` rebuilds it.
|
|
6
6
|
*/
|
|
7
7
|
export const motionDefaults = {
|
|
8
|
-
duration: { fast: 140, base: 200, slow: 300, slower: 450, slowest: 900, spin:
|
|
8
|
+
duration: { fast: 140, base: 200, slow: 300, slower: 450, slowest: 900, spin: 1000, pulse: 1600 } satisfies Record<
|
|
9
9
|
string,
|
|
10
10
|
number
|
|
11
11
|
>,
|
|
@@ -76,8 +76,8 @@ function build(scales: MotionScales): MotionTokens {
|
|
|
76
76
|
};
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
function
|
|
80
|
-
const cs = getComputedStyle(
|
|
79
|
+
function readFrom(scope: Element): MotionTokens {
|
|
80
|
+
const cs = getComputedStyle(scope);
|
|
81
81
|
const rootFontSize = parseFloat(getComputedStyle(document.documentElement).fontSize) || 16;
|
|
82
82
|
const seconds = (name: string, fallback: number): number => {
|
|
83
83
|
const v = cs.getPropertyValue(name).trim();
|
|
@@ -120,16 +120,35 @@ function replaceInto(target: Record<string, unknown>, next: Record<string, unkno
|
|
|
120
120
|
|
|
121
121
|
const hasDom = typeof document !== 'undefined';
|
|
122
122
|
|
|
123
|
-
|
|
123
|
+
const pageScope = (): Element => document.body ?? document.documentElement;
|
|
124
|
+
|
|
125
|
+
export const UIMotion: MotionTokens = hasDom ? readFrom(pageScope()) : build(DEFAULTS);
|
|
126
|
+
|
|
127
|
+
let generation = 0;
|
|
128
|
+
const scoped = new WeakMap<Element, { generation: number; tokens: MotionTokens }>();
|
|
129
|
+
|
|
130
|
+
export function motionFor(scope?: Element | null): MotionTokens {
|
|
131
|
+
if (!hasDom || !scope) return UIMotion;
|
|
132
|
+
const hit = scoped.get(scope);
|
|
133
|
+
if (hit && hit.generation === generation) return hit.tokens;
|
|
134
|
+
const tokens = readFrom(scope);
|
|
135
|
+
scoped.set(scope, { generation, tokens });
|
|
136
|
+
return tokens;
|
|
137
|
+
}
|
|
124
138
|
|
|
125
139
|
/**
|
|
126
|
-
* Re-reads the motion tokens into `UIMotion` in place
|
|
127
|
-
* a `data-theme`
|
|
128
|
-
* after
|
|
140
|
+
* Re-reads the motion tokens into `UIMotion` in place and drops every scoped read, so every held
|
|
141
|
+
* reference sees the new values. Runs on a `data-theme` or `data-polarity` change, a
|
|
142
|
+
* `prefers-reduced-motion` flip and after `ZyncatTheme` renders; call it yourself after injecting a
|
|
143
|
+
* stylesheet that retimes the `--duration-*` tokens.
|
|
129
144
|
*/
|
|
130
145
|
export function refreshMotionTokens(): MotionTokens {
|
|
146
|
+
generation++;
|
|
131
147
|
if (hasDom)
|
|
132
|
-
replaceInto(
|
|
148
|
+
replaceInto(
|
|
149
|
+
UIMotion as unknown as Record<string, unknown>,
|
|
150
|
+
readFrom(pageScope()) as unknown as Record<string, unknown>,
|
|
151
|
+
);
|
|
133
152
|
return UIMotion;
|
|
134
153
|
}
|
|
135
154
|
|
|
@@ -139,7 +158,7 @@ if (hasDom) {
|
|
|
139
158
|
if (typeof MutationObserver === 'function')
|
|
140
159
|
new MutationObserver(() => refreshMotionTokens()).observe(document.documentElement, {
|
|
141
160
|
attributes: true,
|
|
142
|
-
attributeFilter: ['data-theme'],
|
|
161
|
+
attributeFilter: ['data-theme', 'data-polarity'],
|
|
143
162
|
subtree: true,
|
|
144
163
|
});
|
|
145
164
|
}
|
package/src/tokens/motion.css
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
@layer zyncat.tokens, zyncat.components;
|
|
1
|
+
@layer zyncat.reset, zyncat.tokens, zyncat.components;
|
|
2
2
|
|
|
3
3
|
@layer zyncat.tokens {
|
|
4
4
|
:root {
|
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
--duration-base: 200ms; /* standard element transitions - fades, toggles, badge morphs */
|
|
7
7
|
--duration-slow: 300ms; /* layout-scale movement - Collapse, panel resizes, reordering */
|
|
8
8
|
--duration-slower: 450ms; /* large-surface movement - dialog, sheet, page-scale reveals */
|
|
9
|
-
--duration-slowest: 900ms; /* hero-scale movement - card expansion, container transforms
|
|
10
|
-
--duration-spin:
|
|
11
|
-
--duration-pulse: 1600ms; /* ambient
|
|
9
|
+
--duration-slowest: 900ms; /* hero-scale movement - card expansion, container transforms */
|
|
10
|
+
--duration-spin: 1000ms; /* continuous loaders only, outside the UI-transition scale */
|
|
11
|
+
--duration-pulse: 1600ms; /* ambient breathing, not collapsed under reduced motion */
|
|
12
12
|
|
|
13
13
|
--ease-standard: cubic-bezier(0.2, 0, 0, 1);
|
|
14
14
|
--ease-entrance: cubic-bezier(0.25, 1, 0.4, 1);
|
|
@@ -21,19 +21,19 @@
|
|
|
21
21
|
1
|
|
22
22
|
); /* fast out, soft landing - a persistent element moving to a new target, never enter/exit */
|
|
23
23
|
|
|
24
|
-
--distance-sm: 0.5rem; /* 8px - settling into place
|
|
24
|
+
--distance-sm: 0.5rem; /* 8px - settling into place */
|
|
25
25
|
--distance-md: 1rem; /* 16px - arriving from an adjacent position - page turns, tab panels, paged ranges */
|
|
26
26
|
--distance-lg: 1.5rem; /* 24px - arriving from outside the surface - a toast joining its stack */
|
|
27
27
|
|
|
28
|
-
/* Rest scale -
|
|
29
|
-
surface, so a dialog takes a smaller one than a tag to land at the same perceived distance. */
|
|
28
|
+
/* Rest scale - the same ratio reads as more movement the wider the surface. */
|
|
30
29
|
--scale-panel: 0.98; /* full-width surfaces - dialog, modal, sheet */
|
|
31
30
|
--scale-floating: 0.96; /* floating surfaces - popover, tooltip, menu, toast, alert */
|
|
32
31
|
--scale-chip: 0.9; /* small inline elements - tag, badge, count */
|
|
33
32
|
}
|
|
34
33
|
|
|
35
34
|
:root,
|
|
36
|
-
[data-theme]
|
|
35
|
+
[data-theme],
|
|
36
|
+
[data-polarity] {
|
|
37
37
|
--transition-control:
|
|
38
38
|
color var(--duration-fast) var(--ease-standard), background-color var(--duration-fast) var(--ease-standard),
|
|
39
39
|
border-color var(--duration-fast) var(--ease-standard), box-shadow var(--duration-fast) var(--ease-standard),
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
--duration-slow: 1ms;
|
|
52
52
|
--duration-slower: 1ms;
|
|
53
53
|
--duration-slowest: 1ms;
|
|
54
|
-
--duration-spin:
|
|
54
|
+
--duration-spin: 2000ms; /* slow the loader, never freeze it (1ms = blur) */
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
}
|
package/src/tokens/radius.css
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
@layer zyncat.tokens, zyncat.components;
|
|
1
|
+
@layer zyncat.reset, zyncat.tokens, zyncat.components;
|
|
2
2
|
|
|
3
3
|
@layer zyncat.tokens {
|
|
4
4
|
:root {
|
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
:root,
|
|
9
|
-
[data-theme]
|
|
9
|
+
[data-theme],
|
|
10
|
+
[data-polarity] {
|
|
10
11
|
--radius-sm: calc(var(--radius) * 0.5);
|
|
11
12
|
--radius-md: calc(var(--radius) * 0.75);
|
|
12
13
|
--radius-lg: var(--radius);
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
@layer zyncat.reset, zyncat.tokens, zyncat.components;
|
|
2
|
+
|
|
3
|
+
@layer zyncat.reset {
|
|
4
|
+
/* Not the default: iOS Safari inflates text in landscape without it. */
|
|
5
|
+
html {
|
|
6
|
+
-webkit-text-size-adjust: 100%;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
*,
|
|
10
|
+
*::before,
|
|
11
|
+
*::after {
|
|
12
|
+
box-sizing: border-box;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
body {
|
|
16
|
+
margin: 0;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/* The font shorthand resets every font longhand, the two settings ones included, and Safari
|
|
20
|
+
withholds letter-spacing from controls; each is restated so the control keeps inheriting. */
|
|
21
|
+
button,
|
|
22
|
+
input,
|
|
23
|
+
optgroup,
|
|
24
|
+
select,
|
|
25
|
+
textarea {
|
|
26
|
+
font: inherit;
|
|
27
|
+
font-feature-settings: inherit;
|
|
28
|
+
font-variation-settings: inherit;
|
|
29
|
+
letter-spacing: inherit;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/* Firefox's UA sheet dims placeholders to 0.54. */
|
|
33
|
+
::placeholder {
|
|
34
|
+
opacity: 1;
|
|
35
|
+
}
|
|
36
|
+
}
|
package/src/tokens/semantic.css
CHANGED
|
@@ -1,21 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
Neutral roles are a polarity: light values on `:root, [data-theme='light']`, dark ones in dark.css.
|
|
3
|
-
Derived roles sit on every theme root, so a subtree that repoints a decision re-derives them. */
|
|
4
|
-
|
|
5
|
-
@layer zyncat.tokens, zyncat.components;
|
|
1
|
+
@layer zyncat.reset, zyncat.tokens, zyncat.components;
|
|
6
2
|
|
|
7
3
|
@layer zyncat.tokens {
|
|
8
|
-
:root {
|
|
9
|
-
/* The ink on a hue fill - white in either polarity, since the fills stay mid-lightness on dark. */
|
|
10
|
-
--text-on-accent: var(--gray-0);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
4
|
:root,
|
|
14
|
-
[data-
|
|
5
|
+
[data-polarity='light'] {
|
|
15
6
|
color-scheme: light;
|
|
16
7
|
|
|
17
|
-
/*
|
|
18
|
-
way print separates with rules rather than tint; subtle < muted < inset step one ramp stop apart. */
|
|
8
|
+
/* Canvas, cards and panels share the top of the ramp, separated by hairlines rather than tint. */
|
|
19
9
|
--bg-app: var(--gray-0);
|
|
20
10
|
--bg-surface: var(--gray-0);
|
|
21
11
|
--bg-surface-raised: var(--gray-0);
|
|
@@ -39,9 +29,9 @@
|
|
|
39
29
|
}
|
|
40
30
|
|
|
41
31
|
:root,
|
|
42
|
-
[data-theme]
|
|
43
|
-
|
|
44
|
-
|
|
32
|
+
[data-theme],
|
|
33
|
+
[data-polarity] {
|
|
34
|
+
/* The resting face of a filled control. */
|
|
45
35
|
--accent-fill: var(--accent);
|
|
46
36
|
--accent-lift: oklch(from var(--accent) calc(l + 0.075) calc(c - 0.006) h);
|
|
47
37
|
--accent-hover: oklch(from var(--accent) calc(l - 0.07) calc(c - 0.004) h);
|
|
@@ -52,12 +42,14 @@
|
|
|
52
42
|
--accent-wash: oklch(from var(--accent) l c h / 0.08);
|
|
53
43
|
--text-accent: var(--accent-active);
|
|
54
44
|
|
|
55
|
-
/*
|
|
56
|
-
|
|
45
|
+
/* The ink on a hue fill - the ramp's lightest rung in either polarity. */
|
|
46
|
+
--text-on-accent: var(--gray-0);
|
|
47
|
+
|
|
48
|
+
/* Translucent washes of the ink, never opaque near-whites. */
|
|
57
49
|
--neutral-wash: color-mix(in oklab, var(--text-secondary) 6%, transparent);
|
|
58
50
|
--neutral-wash-press: color-mix(in oklab, var(--text-secondary) 10%, transparent);
|
|
59
51
|
|
|
60
|
-
/*
|
|
52
|
+
/* The accent's hue one step down - repoint it for a hue of its own. */
|
|
61
53
|
--info: var(--accent-hover);
|
|
62
54
|
--info-subtle: oklch(from var(--info) 0.972 0.02 h);
|
|
63
55
|
--info-text: oklch(from var(--info) calc(l - 0.082) calc(c - 0.014) h);
|
|
@@ -71,8 +63,7 @@
|
|
|
71
63
|
--warning-text: oklch(from var(--warning) calc(l - 0.14) calc(c - 0.024) h);
|
|
72
64
|
--warning-wash: oklch(from var(--warning) 0.76 0.14 h / 0.12);
|
|
73
65
|
|
|
74
|
-
/*
|
|
75
|
-
lighter than the --danger ink so white text sits on it; lift is the hover face above that. */
|
|
66
|
+
/* The destructive button's hover face, above --danger-fill. */
|
|
76
67
|
--danger-lift: oklch(from var(--danger) 0.64 0.2 h);
|
|
77
68
|
--danger-fill: oklch(from var(--danger) 0.602 0.196 h);
|
|
78
69
|
--danger-active: oklch(from var(--danger) calc(l - 0.067) calc(c - 0.024) h);
|
|
@@ -81,7 +72,6 @@
|
|
|
81
72
|
--danger-disabled: oklch(from var(--danger) 0.8 0.09 h);
|
|
82
73
|
--danger-wash: oklch(from var(--danger) 0.602 0.196 h / 0.1);
|
|
83
74
|
|
|
84
|
-
/* Per-tone glass tints - alpha kept low so the frost reads through. */
|
|
85
75
|
--glass-tint-neutral: color-mix(in oklab, var(--text-muted) 13%, transparent);
|
|
86
76
|
--glass-tint-info: color-mix(in oklab, var(--info) 17%, transparent);
|
|
87
77
|
--glass-tint-success: color-mix(in oklab, var(--success) 17%, transparent);
|
package/src/tokens/spacing.css
CHANGED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { sharedSlot } from '../shared-slot';
|
|
2
|
+
|
|
3
|
+
export type Polarity = 'light' | 'dark';
|
|
4
|
+
export type PolarityPreference = Polarity | 'system';
|
|
5
|
+
|
|
6
|
+
export interface ThemeState {
|
|
7
|
+
/** The active palette - `default` when no other is named. */
|
|
8
|
+
theme: string;
|
|
9
|
+
/** The stored side, or `system` to follow the OS setting. */
|
|
10
|
+
polarity: PolarityPreference;
|
|
11
|
+
/** The side the page is painted in - `system` resolved through the OS setting. */
|
|
12
|
+
resolvedPolarity: Polarity;
|
|
13
|
+
/** Every palette `ZyncatTheme` declared, `default` first. */
|
|
14
|
+
themes: readonly string[];
|
|
15
|
+
/** Display name per palette - the palette's `name`, else its key title-cased. */
|
|
16
|
+
themeNames: Readonly<Record<string, string>>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface ThemeControls extends ThemeState {
|
|
20
|
+
/** Switch the palette; the side stays. */
|
|
21
|
+
setTheme(theme: string): void;
|
|
22
|
+
/** Pick a side, or `system` to follow the OS setting. */
|
|
23
|
+
setPolarity(polarity: PolarityPreference): void;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type ThemeBootConfig = { key: string; declared: ThemeState };
|
|
27
|
+
|
|
28
|
+
export interface ThemeChange {
|
|
29
|
+
current: ThemeState;
|
|
30
|
+
next: ThemeState;
|
|
31
|
+
origin?: readonly [number, number];
|
|
32
|
+
commit(): void;
|
|
33
|
+
revert(): void;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface ThemePreferenceOptions {
|
|
37
|
+
/** Viewport point the change spreads from - the centre of the pressed control. */
|
|
38
|
+
origin?: readonly [number, number];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export type ThemeTransitionRunner = (change: ThemeChange) => void;
|
|
42
|
+
|
|
43
|
+
export const DEFAULT_THEME = 'default';
|
|
44
|
+
export const THEME_STORAGE_KEY = 'zyncat-theme';
|
|
45
|
+
|
|
46
|
+
/* Serialised with String() into the inline boot script, so it closes over nothing: every name it needs
|
|
47
|
+
arrives in config, and the attribute names and the polarity words stay literal inside it. */
|
|
48
|
+
export function bootTheme(config: ThemeBootConfig, stored?: unknown): Omit<ThemeState, 'themes' | 'themeNames'> {
|
|
49
|
+
let { theme, polarity, themes } = config.declared;
|
|
50
|
+
if (stored === undefined) {
|
|
51
|
+
try {
|
|
52
|
+
stored = JSON.parse(localStorage.getItem(config.key) || 'null');
|
|
53
|
+
/* Named binding, not `catch {}`: the client target downlevels an omitted binding and the server
|
|
54
|
+
target does not, so String(bootTheme) differs and the inline script mismatches on hydration. */
|
|
55
|
+
} catch (error) {}
|
|
56
|
+
}
|
|
57
|
+
const saved = (stored || {}) as { theme?: unknown; polarity?: unknown };
|
|
58
|
+
if (typeof saved.theme === 'string' && themes.includes(saved.theme)) theme = saved.theme;
|
|
59
|
+
if (saved.polarity === 'light' || saved.polarity === 'dark' || saved.polarity === 'system') polarity = saved.polarity;
|
|
60
|
+
const resolvedPolarity: Polarity =
|
|
61
|
+
polarity === 'system' ? (matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light') : polarity;
|
|
62
|
+
const root = document.documentElement;
|
|
63
|
+
if (theme === themes[0]) root.removeAttribute('data-theme');
|
|
64
|
+
else root.setAttribute('data-theme', theme);
|
|
65
|
+
root.setAttribute('data-polarity', resolvedPolarity);
|
|
66
|
+
let meta = document.querySelector('meta[name="theme-color"]') as HTMLMetaElement | null;
|
|
67
|
+
if (!meta) {
|
|
68
|
+
meta = document.head.appendChild(document.createElement('meta'));
|
|
69
|
+
meta.name = 'theme-color';
|
|
70
|
+
meta.setAttribute('data-zyncat-theme-color', '');
|
|
71
|
+
}
|
|
72
|
+
if (meta.hasAttribute('data-zyncat-theme-color')) {
|
|
73
|
+
meta.style.backgroundColor = 'var(--bg-app)';
|
|
74
|
+
const painted = getComputedStyle(meta).backgroundColor;
|
|
75
|
+
meta.style.backgroundColor = '';
|
|
76
|
+
if (painted && painted !== 'rgba(0, 0, 0, 0)') meta.content = painted;
|
|
77
|
+
}
|
|
78
|
+
return { theme, polarity, resolvedPolarity };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const DEFAULT_CONFIG: ThemeBootConfig = {
|
|
82
|
+
key: THEME_STORAGE_KEY,
|
|
83
|
+
declared: {
|
|
84
|
+
theme: DEFAULT_THEME,
|
|
85
|
+
polarity: 'system',
|
|
86
|
+
resolvedPolarity: 'light',
|
|
87
|
+
themes: [DEFAULT_THEME],
|
|
88
|
+
themeNames: { [DEFAULT_THEME]: 'Default' },
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const store = sharedSlot('tokens.theme@1', () => ({
|
|
93
|
+
json: '',
|
|
94
|
+
config: DEFAULT_CONFIG,
|
|
95
|
+
state: null as ThemeState | null,
|
|
96
|
+
attached: false,
|
|
97
|
+
listeners: new Set<() => void>(),
|
|
98
|
+
transition: null as ThemeTransitionRunner | null,
|
|
99
|
+
pending: null as ThemeState | null,
|
|
100
|
+
}));
|
|
101
|
+
|
|
102
|
+
const notify = () => {
|
|
103
|
+
for (const listener of store.listeners) listener();
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export function configureThemeStore(json: string): void {
|
|
107
|
+
if (json === store.json) return;
|
|
108
|
+
store.json = json;
|
|
109
|
+
store.config = JSON.parse(json);
|
|
110
|
+
store.state = null;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function applyTheme(stored?: unknown): void {
|
|
114
|
+
const { themes, themeNames } = store.config.declared;
|
|
115
|
+
store.state = { ...bootTheme(store.config, stored), themes, themeNames };
|
|
116
|
+
notify();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export const getThemeSnapshot = (): ThemeState => store.state ?? store.config.declared;
|
|
120
|
+
export const getThemeTargetSnapshot = (): ThemeState => store.pending ?? getThemeSnapshot();
|
|
121
|
+
export const getServerThemeSnapshot = (): ThemeState => store.config.declared;
|
|
122
|
+
|
|
123
|
+
export function setThemeTransition(runner: ThemeTransitionRunner | null): void {
|
|
124
|
+
store.transition = runner;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const resolvePolarity = (polarity: PolarityPreference): Polarity =>
|
|
128
|
+
polarity === 'system' ? (matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light') : polarity;
|
|
129
|
+
|
|
130
|
+
const persistTheme = (choice: Pick<ThemeState, 'theme' | 'polarity'>) => {
|
|
131
|
+
try {
|
|
132
|
+
localStorage.setItem(store.config.key, JSON.stringify(choice));
|
|
133
|
+
} catch {}
|
|
134
|
+
applyTheme(choice);
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const settlePending = (choice: Pick<ThemeState, 'theme' | 'polarity'>) => {
|
|
138
|
+
if (store.pending && store.pending.theme === choice.theme && store.pending.polarity === choice.polarity) {
|
|
139
|
+
store.pending = null;
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
export function setThemePreference(
|
|
144
|
+
patch: Partial<Pick<ThemeState, 'theme' | 'polarity'>>,
|
|
145
|
+
options: ThemePreferenceOptions = {},
|
|
146
|
+
): void {
|
|
147
|
+
const current = getThemeSnapshot();
|
|
148
|
+
const base = store.pending ?? current;
|
|
149
|
+
const theme = patch.theme && current.themes.includes(patch.theme) ? patch.theme : base.theme;
|
|
150
|
+
const polarity = patch.polarity ?? base.polarity;
|
|
151
|
+
const choice = { theme, polarity };
|
|
152
|
+
if (!store.transition) {
|
|
153
|
+
persistTheme(choice);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
const next: ThemeState = { ...current, theme, polarity, resolvedPolarity: resolvePolarity(polarity) };
|
|
157
|
+
store.pending = next;
|
|
158
|
+
notify();
|
|
159
|
+
store.transition({
|
|
160
|
+
current,
|
|
161
|
+
next,
|
|
162
|
+
origin: options.origin,
|
|
163
|
+
commit: () => {
|
|
164
|
+
settlePending(choice);
|
|
165
|
+
persistTheme(choice);
|
|
166
|
+
},
|
|
167
|
+
revert: () => {
|
|
168
|
+
store.pending = null;
|
|
169
|
+
notify();
|
|
170
|
+
},
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export function subscribeTheme(listener: () => void): () => void {
|
|
175
|
+
store.listeners.add(listener);
|
|
176
|
+
if (!store.attached) {
|
|
177
|
+
store.attached = true;
|
|
178
|
+
matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => {
|
|
179
|
+
if (store.state?.polarity === 'system') applyTheme(store.state);
|
|
180
|
+
});
|
|
181
|
+
window.addEventListener('storage', (event) => {
|
|
182
|
+
if (event.key === null || event.key === store.config.key) applyTheme();
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
if (!store.state) applyTheme();
|
|
186
|
+
return () => store.listeners.delete(listener);
|
|
187
|
+
}
|
|
@@ -1,15 +1,62 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import { useEffect } from 'react';
|
|
3
|
+
import { useEffect, useLayoutEffect, useMemo, useSyncExternalStore } from 'react';
|
|
4
4
|
|
|
5
|
+
import type { ThemeTransitionSetting } from '../components/expressive/theme-transition/theme-transition';
|
|
5
6
|
import { refreshMotionTokens } from './motion-tokens';
|
|
7
|
+
import * as store from './theme-store';
|
|
8
|
+
|
|
9
|
+
const loadThemeTransition = () => import('../components/expressive/theme-transition/theme-transition');
|
|
10
|
+
|
|
11
|
+
const setTheme = (theme: string) => store.setThemePreference({ theme });
|
|
12
|
+
const setPolarity = (polarity: store.PolarityPreference) => store.setThemePreference({ polarity });
|
|
13
|
+
|
|
14
|
+
export function useTheme(): store.ThemeControls {
|
|
15
|
+
const state = useSyncExternalStore(store.subscribeTheme, store.getThemeSnapshot, store.getServerThemeSnapshot);
|
|
16
|
+
return useMemo(() => ({ ...state, setTheme, setPolarity }), [state]);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function useThemeTarget(): store.ThemeState {
|
|
20
|
+
return useSyncExternalStore(store.subscribeTheme, store.getThemeTargetSnapshot, store.getServerThemeSnapshot);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function ThemeSync({
|
|
24
|
+
css,
|
|
25
|
+
config,
|
|
26
|
+
transition,
|
|
27
|
+
}: {
|
|
28
|
+
css: string;
|
|
29
|
+
config: string | null;
|
|
30
|
+
transition?: ThemeTransitionSetting;
|
|
31
|
+
}): null {
|
|
32
|
+
if (config) store.configureThemeStore(config);
|
|
33
|
+
const transitionKey = config && transition ? JSON.stringify(transition) : null;
|
|
34
|
+
|
|
35
|
+
useLayoutEffect(() => {
|
|
36
|
+
if (config) store.applyTheme();
|
|
37
|
+
}, [config]);
|
|
38
|
+
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
if (!transitionKey) return;
|
|
41
|
+
const setting = JSON.parse(transitionKey) as ThemeTransitionSetting;
|
|
42
|
+
let live = true;
|
|
43
|
+
void loadThemeTransition().then((module) => {
|
|
44
|
+
if (!live) return;
|
|
45
|
+
module.preloadThemeTransition(setting);
|
|
46
|
+
store.setThemeTransition((change) => module.runThemeTransition(change, setting));
|
|
47
|
+
});
|
|
48
|
+
return () => {
|
|
49
|
+
live = false;
|
|
50
|
+
store.setThemeTransition(null);
|
|
51
|
+
};
|
|
52
|
+
}, [transitionKey]);
|
|
6
53
|
|
|
7
|
-
export function ThemeSync({ css }: { css: string }): null {
|
|
8
54
|
useEffect(() => {
|
|
9
55
|
refreshMotionTokens();
|
|
10
56
|
return () => {
|
|
11
57
|
refreshMotionTokens();
|
|
12
58
|
};
|
|
13
59
|
}, [css]);
|
|
60
|
+
|
|
14
61
|
return null;
|
|
15
62
|
}
|