@behavioral-agentic-design-system/core 0.47.0 → 0.49.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/package.json +1 -1
- package/scripts/build-tokens.cjs +24 -3
- package/scripts/ux-smoke.mjs +5 -1
- package/src/api/save-tokens.ts +170 -24
- package/src/app/layout.tsx +12 -1
- package/src/app/preview/components/page.tsx +114 -18
- package/src/app/preview/global-font-client.tsx +2 -0
- package/src/app/providers.tsx +2 -0
- package/src/app/shell.tsx +50 -156
- package/src/components/customize/brand-mark-section.tsx +65 -95
- package/src/components/customize/font-pickers.tsx +25 -2
- package/src/components/customize/save-bar.tsx +120 -7
- package/src/components/customize/theme-io.tsx +62 -21
- package/src/components/customize-tab.tsx +3 -1
- package/src/components/home-recent.tsx +58 -25
- package/src/components/motion/reveal.tsx +168 -12
- package/src/components/studio/control-panel.tsx +98 -19
- package/src/components/studio/import-theme-dialog.tsx +167 -0
- package/src/components/studio/tokens-panel.tsx +215 -0
- package/src/components/studio/types.ts +5 -2
- package/src/components/studio/use-studio-tweaks.ts +36 -4
- package/src/components/studio/use-token-edits.ts +160 -0
- package/src/components/ui/number-field.tsx +390 -0
- package/src/components/ui/toggle-tip.tsx +38 -29
- package/src/data/component-added.json +4 -0
- package/src/data/component-stories.json +1214 -0
- package/src/data/docs-index.ts +7 -2
- package/src/data/hidden-views.ts +22 -0
- package/src/data/history.json +51 -51
- package/src/data/sticker-sheet.json +1918 -1808
- package/src/fonts/Figtree-OFL.txt +93 -0
- package/src/fonts/figtree-latin-ext-wght-normal.woff2 +0 -0
- package/src/fonts/figtree-latin-wght-italic.woff2 +0 -0
- package/src/fonts/figtree-latin-wght-normal.woff2 +0 -0
- package/src/fonts-cdn.css +3 -1
- package/src/fonts.css +44 -0
- package/src/hooks/use-global-heading-font.ts +104 -0
- package/src/hooks/use-global-sans-font.ts +8 -3
- package/src/hooks/use-global-theme.ts +2 -2
- package/src/hooks/use-token-overrides.ts +62 -14
- package/src/lib/css-color.ts +42 -0
- package/src/lib/storybook-url.ts +28 -0
- package/src/lib/theme-editor.ts +7 -1
- package/src/lib/theme-import.ts +99 -0
- package/src/lib/theme-transition.ts +93 -0
- package/src/lib/token-list.ts +133 -0
- package/src/lib/token-value.ts +31 -0
- package/src/stories/Accordion.stories.tsx +1 -1
- package/src/stories/Affix.stories.tsx +1 -1
- package/src/stories/AiBadge.stories.tsx +1 -1
- package/src/stories/Alert.stories.tsx +1 -1
- package/src/stories/AlertDialog.stories.tsx +1 -1
- package/src/stories/AngleSlider.stories.tsx +1 -1
- package/src/stories/AnnouncementBar.stories.tsx +2 -2
- package/src/stories/AspectRatio.stories.tsx +1 -1
- package/src/stories/Attachment.stories.tsx +1 -1
- package/src/stories/Autocomplete.stories.tsx +1 -1
- package/src/stories/Avatar.stories.tsx +1 -1
- package/src/stories/Badge.stories.tsx +1 -1
- package/src/stories/Blockquote.stories.tsx +1 -1
- package/src/stories/Burger.stories.tsx +1 -1
- package/src/stories/Button.stories.tsx +1 -1
- package/src/stories/ButtonGroup.stories.tsx +1 -1
- package/src/stories/Calendar.stories.tsx +1 -1
- package/src/stories/Callout.stories.tsx +1 -1
- package/src/stories/Canvas.stories.tsx +1 -1
- package/src/stories/Card.stories.tsx +1 -1
- package/src/stories/Carousel.stories.tsx +1 -1
- package/src/stories/Cascader.stories.tsx +1 -1
- package/src/stories/Chart.stories.tsx +1 -1
- package/src/stories/ChatBubble.stories.tsx +1 -1
- package/src/stories/ChatMarker.stories.tsx +1 -1
- package/src/stories/Checkbox.stories.tsx +1 -1
- package/src/stories/CheckboxCard.stories.tsx +1 -1
- package/src/stories/CheckboxGroup.stories.tsx +2 -1
- package/src/stories/Chip.stories.tsx +1 -1
- package/src/stories/CircularProgress.stories.tsx +1 -1
- package/src/stories/Clipboard.stories.tsx +1 -1
- package/src/stories/CloseButton.stories.tsx +1 -1
- package/src/stories/Code.stories.tsx +1 -1
- package/src/stories/Collapsible.stories.tsx +1 -1
- package/src/stories/ColorPicker.stories.tsx +1 -1
- package/src/stories/ColorSwatch.stories.tsx +1 -1
- package/src/stories/Combobox.stories.tsx +1 -1
- package/src/stories/Container.stories.tsx +1 -1
- package/src/stories/ContextMenu.stories.tsx +1 -1
- package/src/stories/CopyButton.stories.tsx +1 -1
- package/src/stories/DataList.stories.tsx +1 -1
- package/src/stories/DataTable.stories.tsx +1 -1
- package/src/stories/DateField.stories.tsx +1 -1
- package/src/stories/DatePicker.stories.tsx +1 -1
- package/src/stories/DateRangePicker.stories.tsx +1 -1
- package/src/stories/Dialog.stories.tsx +1 -1
- package/src/stories/Drawer.stories.tsx +1 -1
- package/src/stories/DropdownMenu.stories.tsx +1 -1
- package/src/stories/Editable.stories.tsx +1 -1
- package/src/stories/EmptyState.stories.tsx +1 -1
- package/src/stories/FacetedFilter.stories.tsx +1 -1
- package/src/stories/Field.stories.tsx +1 -1
- package/src/stories/Fieldset.stories.tsx +1 -1
- package/src/stories/FileButton.stories.tsx +1 -1
- package/src/stories/FileUpload.stories.tsx +1 -1
- package/src/stories/FloatLabel.stories.tsx +1 -1
- package/src/stories/FloatingActionButton.stories.tsx +1 -1
- package/src/stories/FloatingIndicator.stories.tsx +1 -1
- package/src/stories/FloatingPanel.stories.tsx +1 -1
- package/src/stories/FocusTrap.stories.tsx +1 -1
- package/src/stories/FormatByte.stories.tsx +1 -1
- package/src/stories/FormatDate.stories.tsx +1 -1
- package/src/stories/FormatNumber.stories.tsx +1 -1
- package/src/stories/FormatRelativeTime.stories.tsx +1 -1
- package/src/stories/GaugeChart.stories.tsx +1 -1
- package/src/stories/Grid.stories.tsx +1 -1
- package/src/stories/Heatmap.stories.tsx +1 -1
- package/src/stories/Highlight.stories.tsx +1 -1
- package/src/stories/HoverCard.stories.tsx +1 -1
- package/src/stories/Icon.stories.tsx +1 -1
- package/src/stories/Image.stories.tsx +1 -1
- package/src/stories/Indicator.stories.tsx +1 -1
- package/src/stories/InfiniteScroll.stories.tsx +1 -1
- package/src/stories/InlineEdit.stories.tsx +1 -1
- package/src/stories/Input.stories.tsx +1 -1
- package/src/stories/InputClearButton.stories.tsx +1 -1
- package/src/stories/InputGroup.stories.tsx +1 -1
- package/src/stories/JsonInput.stories.tsx +1 -1
- package/src/stories/Kbd.stories.tsx +1 -1
- package/src/stories/KeyboardShortcut.stories.tsx +1 -1
- package/src/stories/Label.stories.tsx +1 -1
- package/src/stories/List.stories.tsx +1 -1
- package/src/stories/Listbox.stories.tsx +1 -1
- package/src/stories/LoadingDots.stories.tsx +1 -1
- package/src/stories/LoadingOverlay.stories.tsx +1 -1
- package/src/stories/Mark.stories.tsx +1 -1
- package/src/stories/MarkdownPreview.stories.tsx +1 -1
- package/src/stories/Marquee.stories.tsx +1 -1
- package/src/stories/Masonry.stories.tsx +1 -1
- package/src/stories/Meter.stories.tsx +1 -1
- package/src/stories/MonthPicker.stories.tsx +1 -1
- package/src/stories/MotionToggle.stories.tsx +1 -1
- package/src/stories/MultiSelect.stories.tsx +1 -1
- package/src/stories/NativeSelect.stories.tsx +1 -1
- package/src/stories/NavigationProgress.stories.tsx +1 -1
- package/src/stories/Notification.stories.tsx +1 -1
- package/src/stories/NumberField.stories.tsx +214 -0
- package/src/stories/NumberInput.stories.tsx +1 -1
- package/src/stories/OtpInput.stories.tsx +1 -1
- package/src/stories/Overlay.stories.tsx +1 -1
- package/src/stories/PageHeader.stories.tsx +1 -1
- package/src/stories/PasswordInput.stories.tsx +1 -1
- package/src/stories/PasswordStrengthInput.stories.tsx +1 -1
- package/src/stories/PhoneInput.stories.tsx +1 -1
- package/src/stories/Pill.stories.tsx +1 -1
- package/src/stories/PinInput.stories.tsx +1 -1
- package/src/stories/Popover.stories.tsx +1 -1
- package/src/stories/Portal.stories.tsx +1 -1
- package/src/stories/Presence.stories.tsx +1 -1
- package/src/stories/Progress.stories.tsx +1 -1
- package/src/stories/ProgressStack.stories.tsx +1 -1
- package/src/stories/Prose.stories.tsx +1 -1
- package/src/stories/QrCode.stories.tsx +1 -1
- package/src/stories/Questionnaire.stories.tsx +1 -1
- package/src/stories/RadioGroup.stories.tsx +1 -1
- package/src/stories/RatingGroup.stories.tsx +1 -1
- package/src/stories/Resizable.stories.tsx +1 -1
- package/src/stories/Result.stories.tsx +1 -1
- package/src/stories/Reveal.stories.tsx +1 -1
- package/src/stories/RollingNumber.stories.tsx +1 -1
- package/src/stories/ScrollArea.stories.tsx +1 -1
- package/src/stories/ScrollProgress.stories.tsx +1 -1
- package/src/stories/SearchInput.stories.tsx +1 -1
- package/src/stories/SegmentedControl.stories.tsx +1 -1
- package/src/stories/Select.stories.tsx +1 -1
- package/src/stories/Separator.stories.tsx +1 -1
- package/src/stories/Sheet.stories.tsx +1 -1
- package/src/stories/SignaturePad.stories.tsx +1 -1
- package/src/stories/SimpleGrid.stories.tsx +1 -1
- package/src/stories/Skeleton.stories.tsx +1 -1
- package/src/stories/SkeletonTable.stories.tsx +1 -1
- package/src/stories/Slider.stories.tsx +1 -1
- package/src/stories/Snackbar.stories.tsx +1 -1
- package/src/stories/Sonner.stories.tsx +1 -1
- package/src/stories/SortableList.stories.tsx +1 -1
- package/src/stories/Sparkline.stories.tsx +1 -1
- package/src/stories/Spinner.stories.tsx +1 -1
- package/src/stories/Spoiler.stories.tsx +1 -1
- package/src/stories/Squircle.stories.tsx +1 -1
- package/src/stories/Stack.stories.tsx +1 -1
- package/src/stories/StatusBadge.stories.tsx +1 -1
- package/src/stories/Switch.stories.tsx +1 -1
- package/src/stories/Table.stories.tsx +1 -1
- package/src/stories/Tag.stories.tsx +1 -1
- package/src/stories/TagsInput.stories.tsx +1 -1
- package/src/stories/Text.stories.tsx +1 -1
- package/src/stories/Textarea.stories.tsx +1 -1
- package/src/stories/ThemeIcon.stories.tsx +1 -1
- package/src/stories/TimePicker.stories.tsx +1 -1
- package/src/stories/Timeline.stories.tsx +1 -1
- package/src/stories/Timer.stories.tsx +1 -1
- package/src/stories/Toggle.stories.tsx +1 -1
- package/src/stories/ToggleGroup.stories.tsx +1 -1
- package/src/stories/ToggleTip.stories.tsx +106 -1
- package/src/stories/Tooltip.stories.tsx +56 -1
- package/src/stories/TransferList.stories.tsx +1 -1
- package/src/stories/TreeSelect.stories.tsx +1 -1
- package/src/stories/TypingIndicator.stories.tsx +1 -1
- package/src/stories/VisuallyHidden.stories.tsx +1 -1
- package/src/stories/Watermark.stories.tsx +1 -1
- package/src/stories/WeekPicker.stories.tsx +1 -1
- package/src/stories/WordRotate.stories.tsx +1 -1
- package/src/stories/YearPicker.stories.tsx +1 -1
- package/src/stories/story-groups.json +216 -223
- package/src/styles.css +20 -3
- package/src/tokens.default.json +6 -1
- package/src/tokens.json +7 -2
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
Copyright 2022 The Figtree Project Authors (https://github.com/erikdkennedy/figtree) Figtree-Italic[wght].ttf: Copyright 2022 The Figtree Project Authors (https://github.com/erikdkennedy/figtree)
|
|
2
|
+
|
|
3
|
+
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
|
4
|
+
This license is copied below, and is also available with a FAQ at:
|
|
5
|
+
http://scripts.sil.org/OFL
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
-----------------------------------------------------------
|
|
9
|
+
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
|
10
|
+
-----------------------------------------------------------
|
|
11
|
+
|
|
12
|
+
PREAMBLE
|
|
13
|
+
The goals of the Open Font License (OFL) are to stimulate worldwide
|
|
14
|
+
development of collaborative font projects, to support the font creation
|
|
15
|
+
efforts of academic and linguistic communities, and to provide a free and
|
|
16
|
+
open framework in which fonts may be shared and improved in partnership
|
|
17
|
+
with others.
|
|
18
|
+
|
|
19
|
+
The OFL allows the licensed fonts to be used, studied, modified and
|
|
20
|
+
redistributed freely as long as they are not sold by themselves. The
|
|
21
|
+
fonts, including any derivative works, can be bundled, embedded,
|
|
22
|
+
redistributed and/or sold with any software provided that any reserved
|
|
23
|
+
names are not used by derivative works. The fonts and derivatives,
|
|
24
|
+
however, cannot be released under any other type of license. The
|
|
25
|
+
requirement for fonts to remain under this license does not apply
|
|
26
|
+
to any document created using the fonts or their derivatives.
|
|
27
|
+
|
|
28
|
+
DEFINITIONS
|
|
29
|
+
"Font Software" refers to the set of files released by the Copyright
|
|
30
|
+
Holder(s) under this license and clearly marked as such. This may
|
|
31
|
+
include source files, build scripts and documentation.
|
|
32
|
+
|
|
33
|
+
"Reserved Font Name" refers to any names specified as such after the
|
|
34
|
+
copyright statement(s).
|
|
35
|
+
|
|
36
|
+
"Original Version" refers to the collection of Font Software components as
|
|
37
|
+
distributed by the Copyright Holder(s).
|
|
38
|
+
|
|
39
|
+
"Modified Version" refers to any derivative made by adding to, deleting,
|
|
40
|
+
or substituting -- in part or in whole -- any of the components of the
|
|
41
|
+
Original Version, by changing formats or by porting the Font Software to a
|
|
42
|
+
new environment.
|
|
43
|
+
|
|
44
|
+
"Author" refers to any designer, engineer, programmer, technical
|
|
45
|
+
writer or other person who contributed to the Font Software.
|
|
46
|
+
|
|
47
|
+
PERMISSION & CONDITIONS
|
|
48
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
49
|
+
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
|
50
|
+
redistribute, and sell modified and unmodified copies of the Font
|
|
51
|
+
Software, subject to the following conditions:
|
|
52
|
+
|
|
53
|
+
1) Neither the Font Software nor any of its individual components,
|
|
54
|
+
in Original or Modified Versions, may be sold by itself.
|
|
55
|
+
|
|
56
|
+
2) Original or Modified Versions of the Font Software may be bundled,
|
|
57
|
+
redistributed and/or sold with any software, provided that each copy
|
|
58
|
+
contains the above copyright notice and this license. These can be
|
|
59
|
+
included either as stand-alone text files, human-readable headers or
|
|
60
|
+
in the appropriate machine-readable metadata fields within text or
|
|
61
|
+
binary files as long as those fields can be easily viewed by the user.
|
|
62
|
+
|
|
63
|
+
3) No Modified Version of the Font Software may use the Reserved Font
|
|
64
|
+
Name(s) unless explicit written permission is granted by the corresponding
|
|
65
|
+
Copyright Holder. This restriction only applies to the primary font name as
|
|
66
|
+
presented to the users.
|
|
67
|
+
|
|
68
|
+
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
|
69
|
+
Software shall not be used to promote, endorse or advertise any
|
|
70
|
+
Modified Version, except to acknowledge the contribution(s) of the
|
|
71
|
+
Copyright Holder(s) and the Author(s) or with their explicit written
|
|
72
|
+
permission.
|
|
73
|
+
|
|
74
|
+
5) The Font Software, modified or unmodified, in part or in whole,
|
|
75
|
+
must be distributed entirely under this license, and must not be
|
|
76
|
+
distributed under any other license. The requirement for fonts to
|
|
77
|
+
remain under this license does not apply to any document created
|
|
78
|
+
using the Font Software.
|
|
79
|
+
|
|
80
|
+
TERMINATION
|
|
81
|
+
This license becomes null and void if any of the above conditions are
|
|
82
|
+
not met.
|
|
83
|
+
|
|
84
|
+
DISCLAIMER
|
|
85
|
+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
86
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
|
87
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
|
88
|
+
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
|
89
|
+
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
90
|
+
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
|
91
|
+
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
92
|
+
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
|
93
|
+
OTHER DEALINGS IN THE FONT SOFTWARE.
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/src/fonts-cdn.css
CHANGED
|
@@ -17,9 +17,11 @@
|
|
|
17
17
|
* the local @font-face rules in fonts.css win over it either way.
|
|
18
18
|
*
|
|
19
19
|
* Inter Variable leads as the default sans; Atkinson Hyperlegible stays as
|
|
20
|
-
* the accessibility-preserving secondary.
|
|
20
|
+
* the accessibility-preserving secondary. Figtree is the heading face
|
|
21
|
+
* (--font-heading), so this path keeps headings off the system UI font.
|
|
21
22
|
*
|
|
22
23
|
* This file must contain NO rules of its own — a single rule here would make
|
|
23
24
|
* the @import statements below invalid for anyone importing it. */
|
|
24
25
|
@import url('https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap');
|
|
25
26
|
@import url('https://fonts.googleapis.com/css2?family=Atkinson+Hyperlegible:wght@400;700&display=swap');
|
|
27
|
+
@import url('https://fonts.googleapis.com/css2?family=Figtree:ital,wght@0,300..900;1,300..900&display=swap');
|
package/src/fonts.css
CHANGED
|
@@ -97,3 +97,47 @@
|
|
|
97
97
|
font-style: italic;
|
|
98
98
|
font-display: swap;
|
|
99
99
|
}
|
|
100
|
+
|
|
101
|
+
/* ============================================================
|
|
102
|
+
* Atkinson Hyperlegible Sans, the proper name for the face above.
|
|
103
|
+
* Same woff2 files as 'Hyperlegible Sans' (the Braille Institute / Atkinson
|
|
104
|
+
* face), declared again under the name the body token leads with so the
|
|
105
|
+
* computed font says what it is. No new binaries. SIL OFL 1.1.
|
|
106
|
+
* ============================================================ */
|
|
107
|
+
@font-face { font-family: 'Atkinson Hyperlegible Sans'; src: url('/fonts/HyperlegibleSans-Regular.woff2') format('woff2'); font-weight: 400; font-style: normal; font-display: swap; }
|
|
108
|
+
@font-face { font-family: 'Atkinson Hyperlegible Sans'; src: url('/fonts/HyperlegibleSans-Italic.woff2') format('woff2'); font-weight: 400; font-style: italic; font-display: swap; }
|
|
109
|
+
@font-face { font-family: 'Atkinson Hyperlegible Sans'; src: url('/fonts/HyperlegibleSans-Medium.woff2') format('woff2'); font-weight: 500; font-style: normal; font-display: swap; }
|
|
110
|
+
@font-face { font-family: 'Atkinson Hyperlegible Sans'; src: url('/fonts/HyperlegibleSans-MediumItalic.woff2') format('woff2'); font-weight: 500; font-style: italic; font-display: swap; }
|
|
111
|
+
@font-face { font-family: 'Atkinson Hyperlegible Sans'; src: url('/fonts/HyperlegibleSans-Bold.woff2') format('woff2'); font-weight: 700; font-style: normal; font-display: swap; }
|
|
112
|
+
@font-face { font-family: 'Atkinson Hyperlegible Sans'; src: url('/fonts/HyperlegibleSans-BoldItalic.woff2') format('woff2'); font-weight: 700; font-style: italic; font-display: swap; }
|
|
113
|
+
|
|
114
|
+
/* ============================================================
|
|
115
|
+
* Figtree, the heading face (SIL OFL 1.1), VARIABLE.
|
|
116
|
+
* Self-hosted from @fontsource-variable/figtree 5.3.0 (wght 300-900), latin
|
|
117
|
+
* and latin-ext for upright, latin for italic. Leads --font-heading and is
|
|
118
|
+
* applied to h1 to h6 by styles.css. No Google Fonts request at runtime.
|
|
119
|
+
* ============================================================ */
|
|
120
|
+
@font-face {
|
|
121
|
+
font-family: 'Figtree';
|
|
122
|
+
src: url('/fonts/figtree-latin-ext-wght-normal.woff2') format('woff2');
|
|
123
|
+
font-weight: 300 900;
|
|
124
|
+
font-style: normal;
|
|
125
|
+
font-display: swap;
|
|
126
|
+
unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF;
|
|
127
|
+
}
|
|
128
|
+
@font-face {
|
|
129
|
+
font-family: 'Figtree';
|
|
130
|
+
src: url('/fonts/figtree-latin-wght-normal.woff2') format('woff2');
|
|
131
|
+
font-weight: 300 900;
|
|
132
|
+
font-style: normal;
|
|
133
|
+
font-display: swap;
|
|
134
|
+
unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD;
|
|
135
|
+
}
|
|
136
|
+
@font-face {
|
|
137
|
+
font-family: 'Figtree';
|
|
138
|
+
src: url('/fonts/figtree-latin-wght-italic.woff2') format('woff2');
|
|
139
|
+
font-weight: 300 900;
|
|
140
|
+
font-style: italic;
|
|
141
|
+
font-display: swap;
|
|
142
|
+
unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD;
|
|
143
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useCallback, useEffect, useState } from "react";
|
|
4
|
+
import { brand } from "@/brand.config";
|
|
5
|
+
|
|
6
|
+
export type HeadingFontOption = { label: string; stack: string };
|
|
7
|
+
|
|
8
|
+
// Curated, self-hosted faces only. Figtree and Atkinson Hyperlegible Sans ship
|
|
9
|
+
// as woff2 in fonts.css; Inter ships there too; Lora and Source Serif come from
|
|
10
|
+
// next/font in the showcase app (their stacks fall back to the family name).
|
|
11
|
+
// No Google Fonts request happens at runtime for any of them.
|
|
12
|
+
const BASE_HEADING_FONTS: Record<string, HeadingFontOption> = {
|
|
13
|
+
figtree: {
|
|
14
|
+
label: "Figtree",
|
|
15
|
+
stack: "'Figtree', 'Atkinson Hyperlegible Sans', 'Hyperlegible Sans', ui-sans-serif, sans-serif, system-ui",
|
|
16
|
+
},
|
|
17
|
+
hyperlegible: {
|
|
18
|
+
label: "Atkinson Hyperlegible Sans",
|
|
19
|
+
stack: "'Atkinson Hyperlegible Sans', 'Hyperlegible Sans', ui-sans-serif, sans-serif, system-ui",
|
|
20
|
+
},
|
|
21
|
+
inter: {
|
|
22
|
+
label: "Inter",
|
|
23
|
+
stack: "var(--font-inter, 'Inter'), 'Inter', ui-sans-serif, sans-serif, system-ui",
|
|
24
|
+
},
|
|
25
|
+
lora: {
|
|
26
|
+
label: "Lora",
|
|
27
|
+
stack: "var(--font-lora, 'Lora'), 'Lora', Georgia, ui-serif, serif",
|
|
28
|
+
},
|
|
29
|
+
"source-serif": {
|
|
30
|
+
label: "Source Serif",
|
|
31
|
+
stack: "var(--font-source-serif, 'Source Serif 4'), 'Source Serif 4', Georgia, ui-serif, serif",
|
|
32
|
+
},
|
|
33
|
+
system: {
|
|
34
|
+
label: "System UI",
|
|
35
|
+
stack: "ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif",
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// Brand fonts declared in brand.config.ts come first, like the sans picker.
|
|
40
|
+
const HEADING_BRAND_FONTS = brand.fonts.filter((f) => (f.kind ?? "sans") === "sans");
|
|
41
|
+
export const HEADING_FONT_OPTIONS: Record<string, HeadingFontOption> = {
|
|
42
|
+
...Object.fromEntries(HEADING_BRAND_FONTS.map((f) => [f.id, { label: f.label, stack: f.stack }])),
|
|
43
|
+
...BASE_HEADING_FONTS,
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export type HeadingFontKey = string;
|
|
47
|
+
|
|
48
|
+
import { storageKey, readMigrated } from "@behavioral-agentic-design-system/core/lib/storage";
|
|
49
|
+
|
|
50
|
+
const STORAGE_KEY = storageKey("headingFont");
|
|
51
|
+
// A fork's shipped default (brand.config -> defaults.headingFont) wins, like the sans hook; otherwise Figtree.
|
|
52
|
+
const FORK_HEADING = brand.defaults?.headingFont;
|
|
53
|
+
export const DEFAULT_HEADING_FONT: HeadingFontKey =
|
|
54
|
+
FORK_HEADING && FORK_HEADING in HEADING_FONT_OPTIONS ? FORK_HEADING : "figtree";
|
|
55
|
+
|
|
56
|
+
function isValidKey(value: string | null): value is HeadingFontKey {
|
|
57
|
+
return !!value && value in HEADING_FONT_OPTIONS;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function applyFont(key: HeadingFontKey) {
|
|
61
|
+
if (typeof document === "undefined") return;
|
|
62
|
+
document.documentElement.style.setProperty("--font-heading", HEADING_FONT_OPTIONS[key].stack);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Cross-iframe heading font selector, the twin of useGlobalSansFont. Persists
|
|
67
|
+
* the choice in localStorage so every same-origin preview iframe stays in sync
|
|
68
|
+
* through the `storage` event, and sets --font-heading on :root. h1 to h6
|
|
69
|
+
* read that variable (see styles.css), so body text is untouched.
|
|
70
|
+
*/
|
|
71
|
+
export function useGlobalHeadingFont() {
|
|
72
|
+
const [font, setFontState] = useState<HeadingFontKey>(DEFAULT_HEADING_FONT);
|
|
73
|
+
|
|
74
|
+
useEffect(() => {
|
|
75
|
+
if (typeof window === "undefined") return;
|
|
76
|
+
const stored = readMigrated("headingFont");
|
|
77
|
+
const next = isValidKey(stored) ? stored : DEFAULT_HEADING_FONT;
|
|
78
|
+
setFontState(next);
|
|
79
|
+
applyFont(next);
|
|
80
|
+
}, []);
|
|
81
|
+
|
|
82
|
+
useEffect(() => {
|
|
83
|
+
if (typeof window === "undefined") return;
|
|
84
|
+
const onStorage = (e: StorageEvent) => {
|
|
85
|
+
if (e.key !== STORAGE_KEY) return;
|
|
86
|
+
const next = isValidKey(e.newValue) ? e.newValue : DEFAULT_HEADING_FONT;
|
|
87
|
+
setFontState(next);
|
|
88
|
+
applyFont(next);
|
|
89
|
+
};
|
|
90
|
+
window.addEventListener("storage", onStorage);
|
|
91
|
+
return () => window.removeEventListener("storage", onStorage);
|
|
92
|
+
}, []);
|
|
93
|
+
|
|
94
|
+
const setFont = useCallback((next: HeadingFontKey) => {
|
|
95
|
+
if (!isValidKey(next)) return;
|
|
96
|
+
setFontState(next);
|
|
97
|
+
applyFont(next);
|
|
98
|
+
if (typeof window !== "undefined") {
|
|
99
|
+
window.localStorage.setItem(STORAGE_KEY, next);
|
|
100
|
+
}
|
|
101
|
+
}, []);
|
|
102
|
+
|
|
103
|
+
return { font, setFont };
|
|
104
|
+
}
|
|
@@ -13,12 +13,17 @@ type SansFontOption = {
|
|
|
13
13
|
// which kills FOUT. The literal family names stay as fallbacks for environments
|
|
14
14
|
// where next/font isn't loaded (e.g. consumers of the npm package).
|
|
15
15
|
const BASE_SANS_FONTS: Record<string, SansFontOption> = {
|
|
16
|
+
// Key stays "hyperlegible" so choices saved before the rename still resolve.
|
|
16
17
|
hyperlegible: {
|
|
17
|
-
label: "Hyperlegible Sans",
|
|
18
|
-
stack: "'Hyperlegible Sans', ui-sans-serif, sans-serif, system-ui",
|
|
18
|
+
label: "Atkinson Hyperlegible Sans",
|
|
19
|
+
stack: "'Atkinson Hyperlegible Sans', 'Hyperlegible Sans', ui-sans-serif, sans-serif, system-ui",
|
|
20
|
+
},
|
|
21
|
+
figtree: {
|
|
22
|
+
label: "Figtree",
|
|
23
|
+
stack: "'Figtree', 'Atkinson Hyperlegible Sans', ui-sans-serif, sans-serif, system-ui",
|
|
19
24
|
},
|
|
20
25
|
atkinson: {
|
|
21
|
-
label: "Atkinson Hyperlegible",
|
|
26
|
+
label: "Atkinson Hyperlegible (Google build)",
|
|
22
27
|
stack: "var(--font-atkinson), 'Atkinson Hyperlegible', ui-sans-serif, sans-serif, system-ui",
|
|
23
28
|
},
|
|
24
29
|
inter: {
|
|
@@ -137,9 +137,9 @@ export function exportThemeCss(): string {
|
|
|
137
137
|
if (!(rule instanceof CSSStyleRule)) continue;
|
|
138
138
|
const selector = rule.selectorText;
|
|
139
139
|
const target =
|
|
140
|
-
selector === ":root"
|
|
140
|
+
selector === ":root" || selector === ":root:not(.dark)"
|
|
141
141
|
? lightVars
|
|
142
|
-
: selector === ".dark"
|
|
142
|
+
: selector === ".dark" || selector === ":root.dark"
|
|
143
143
|
? darkVars
|
|
144
144
|
: null;
|
|
145
145
|
if (!target) continue;
|
|
@@ -7,9 +7,12 @@ import {
|
|
|
7
7
|
THEME_EDITOR_STORAGE_KEY,
|
|
8
8
|
} from "@behavioral-agentic-design-system/core/lib/theme-editor";
|
|
9
9
|
|
|
10
|
+
import { PRIMITIVE_COLORS, TOKEN_ROWS } from "@behavioral-agentic-design-system/core/lib/token-list";
|
|
10
11
|
import { storageKey, readMigrated } from "@behavioral-agentic-design-system/core/lib/storage";
|
|
12
|
+
import { checkTokenValue } from "@behavioral-agentic-design-system/core/lib/token-value";
|
|
11
13
|
|
|
12
14
|
const STORAGE_KEY = storageKey("tokenOverrides");
|
|
15
|
+
export const OVERRIDES_EVENT = "bads:token-overrides";
|
|
13
16
|
|
|
14
17
|
type Overrides = Record<string, string>;
|
|
15
18
|
|
|
@@ -18,8 +21,16 @@ function read(): Overrides {
|
|
|
18
21
|
try {
|
|
19
22
|
const raw = readMigrated("tokenOverrides");
|
|
20
23
|
if (!raw) return {};
|
|
21
|
-
const parsed = JSON.parse(raw) as
|
|
22
|
-
|
|
24
|
+
const parsed = JSON.parse(raw) as unknown;
|
|
25
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return {};
|
|
26
|
+
// localStorage is editable by anything on this origin, and these values end up in a <style> element. Keep only
|
|
27
|
+
// entries with a CSS variable name and a value the Studio would have accepted; drop the rest without a word.
|
|
28
|
+
const clean: Overrides = {};
|
|
29
|
+
for (const [key, value] of Object.entries(parsed)) {
|
|
30
|
+
if (!/^(dark:)?--[A-Za-z0-9_-]+$/.test(key) || typeof value !== "string") continue;
|
|
31
|
+
if (checkTokenValue(value).ok) clean[key] = value.trim();
|
|
32
|
+
}
|
|
33
|
+
return clean;
|
|
23
34
|
} catch {
|
|
24
35
|
return {};
|
|
25
36
|
}
|
|
@@ -28,15 +39,47 @@ function read(): Overrides {
|
|
|
28
39
|
function write(overrides: Overrides) {
|
|
29
40
|
if (typeof window === "undefined") return;
|
|
30
41
|
window.localStorage.setItem(STORAGE_KEY, JSON.stringify(overrides));
|
|
42
|
+
// The storage event only reaches other windows. Tell hook instances in this one (the Studio's token list and
|
|
43
|
+
// its Tweak panel each mount the hook) to re-read.
|
|
44
|
+
queueMicrotask(() => window.dispatchEvent(new Event(OVERRIDES_EVENT)));
|
|
31
45
|
}
|
|
32
46
|
|
|
47
|
+
export const OVERRIDE_STYLE_ID = "bads-token-overrides";
|
|
48
|
+
/** A key with this prefix is a dark-mode value: `dark:--background`. A bare key is the light (root) value. */
|
|
49
|
+
/** CSS variables that exist in both modes (theme roles). Every other override applies to both modes as one value. */
|
|
50
|
+
const MODE_VARS = new Set(TOKEN_ROWS.filter((r) => r.dark !== undefined && r.cssVar).map((r) => r.cssVar!));
|
|
51
|
+
|
|
52
|
+
export const DARK_PREFIX = "dark:";
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Overrides are written into one <style> element, not inline, so light and dark can differ: `:root { }` carries
|
|
56
|
+
* the bare keys and a later `.dark { }` carries the `dark:` keys. (Inline on <html> would beat `.dark` and make
|
|
57
|
+
* every edit apply to both modes.) Hooks that still set inline variables (brand color, radius, fonts) win over
|
|
58
|
+
* this sheet by design: those controls own their variables.
|
|
59
|
+
*/
|
|
33
60
|
function applyAll(overrides: Overrides) {
|
|
34
61
|
if (typeof document === "undefined") return;
|
|
35
62
|
applyThemeEditorState(readStoredThemeEditorState());
|
|
36
|
-
|
|
63
|
+
// The palette is always declared, so a role can alias it with var(--primitive-<family>-<step>).
|
|
64
|
+
const palette = PRIMITIVE_COLORS.map((r) => ` ${r.cssVar}: ${r.value};`);
|
|
65
|
+
const light: string[] = [];
|
|
66
|
+
const dark: string[] = [];
|
|
37
67
|
for (const [variable, value] of Object.entries(overrides)) {
|
|
38
|
-
|
|
68
|
+
if (variable.startsWith(DARK_PREFIX)) dark.push(` ${variable.slice(DARK_PREFIX.length)}: ${value};`);
|
|
69
|
+
else if (MODE_VARS.has(variable)) light.push(` ${variable}: ${value};`);
|
|
70
|
+
else palette.push(` ${variable}: ${value};`);
|
|
71
|
+
}
|
|
72
|
+
let style = document.getElementById(OVERRIDE_STYLE_ID) as HTMLStyleElement | null;
|
|
73
|
+
if (!style) {
|
|
74
|
+
style = document.createElement("style");
|
|
75
|
+
style.id = OVERRIDE_STYLE_ID;
|
|
39
76
|
}
|
|
77
|
+
// `:root:not(.dark)` and `:root.dark` are mutually exclusive, so the light block can never win in dark mode.
|
|
78
|
+
// Plain `:root` and `.dark` tie on specificity, and this sheet is last, so a light-only override used to
|
|
79
|
+
// overwrite the dark value of the same token.
|
|
80
|
+
style.textContent = `:root {\n${palette.join("\n")}\n}\n:root:not(.dark) {\n${light.join("\n")}\n}\n:root.dark {\n${dark.join("\n")}\n}`;
|
|
81
|
+
// Re-append so it stays the last sheet, which is what lets it win ties with the generated theme.
|
|
82
|
+
document.head.appendChild(style);
|
|
40
83
|
}
|
|
41
84
|
|
|
42
85
|
/**
|
|
@@ -67,17 +110,20 @@ export function useTokenOverrides() {
|
|
|
67
110
|
setOverrides(next);
|
|
68
111
|
applyAll(next);
|
|
69
112
|
};
|
|
113
|
+
const onLocal = () => setOverrides(read());
|
|
70
114
|
window.addEventListener("storage", onStorage);
|
|
71
|
-
|
|
115
|
+
window.addEventListener(OVERRIDES_EVENT, onLocal);
|
|
116
|
+
return () => {
|
|
117
|
+
window.removeEventListener("storage", onStorage);
|
|
118
|
+
window.removeEventListener(OVERRIDES_EVENT, onLocal);
|
|
119
|
+
};
|
|
72
120
|
}, []);
|
|
73
121
|
|
|
74
122
|
const set = useCallback((variable: string, value: string) => {
|
|
75
123
|
setOverrides((prev) => {
|
|
76
124
|
const next = { ...prev, [variable]: value };
|
|
77
125
|
write(next);
|
|
78
|
-
|
|
79
|
-
document.documentElement.style.setProperty(variable, value);
|
|
80
|
-
}
|
|
126
|
+
applyAll(next);
|
|
81
127
|
return next;
|
|
82
128
|
});
|
|
83
129
|
}, []);
|
|
@@ -87,14 +133,16 @@ export function useTokenOverrides() {
|
|
|
87
133
|
const next = { ...prev };
|
|
88
134
|
delete next[variable];
|
|
89
135
|
write(next);
|
|
90
|
-
|
|
91
|
-
// we can clear the inline override so the cascade resumes.
|
|
92
|
-
if (typeof document !== "undefined") {
|
|
93
|
-
document.documentElement.style.removeProperty(variable);
|
|
94
|
-
}
|
|
136
|
+
applyAll(next);
|
|
95
137
|
return next;
|
|
96
138
|
});
|
|
97
139
|
}, []);
|
|
98
140
|
|
|
99
|
-
|
|
141
|
+
const clear = useCallback(() => {
|
|
142
|
+
write({});
|
|
143
|
+
setOverrides({});
|
|
144
|
+
applyAll({});
|
|
145
|
+
}, []);
|
|
146
|
+
|
|
147
|
+
return { overrides, updateOverride: set, remove, clear };
|
|
100
148
|
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Any CSS colour the browser can parse (oklch, hsl, rgb, hex, named) to #RRGGBB, or null when it is not a colour.
|
|
3
|
+
* A DOM probe does the colour-space maths, so there is no conversion code to keep right.
|
|
4
|
+
*/
|
|
5
|
+
const cache = new Map<string, string | null>();
|
|
6
|
+
|
|
7
|
+
export function cssColorToHex(value: string): string | null {
|
|
8
|
+
if (typeof document === "undefined") return null;
|
|
9
|
+
if (cache.has(value)) return cache.get(value) ?? null;
|
|
10
|
+
const out = probe(value);
|
|
11
|
+
cache.set(value, out);
|
|
12
|
+
return out;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
let ctx: CanvasRenderingContext2D | null | undefined;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Canvas does the conversion: whatever syntax the browser accepts (hex, rgb, hsl, oklch, color-mix, named) is
|
|
19
|
+
* rasterised to one pixel and read back as sRGB. Reading getComputedStyle().color instead returns oklch() or
|
|
20
|
+
* color(srgb ...) text in current Chrome, which a rgb() regex cannot parse.
|
|
21
|
+
*/
|
|
22
|
+
function probe(value: string): string | null {
|
|
23
|
+
if (ctx === undefined) {
|
|
24
|
+
const canvas = document.createElement("canvas");
|
|
25
|
+
canvas.width = canvas.height = 1;
|
|
26
|
+
ctx = canvas.getContext("2d", { willReadFrequently: true });
|
|
27
|
+
}
|
|
28
|
+
if (!ctx) return null;
|
|
29
|
+
// An unparseable fillStyle is ignored, so a value that survives two different sentinels is a colour.
|
|
30
|
+
const read = (sentinel: string) => {
|
|
31
|
+
ctx!.fillStyle = sentinel;
|
|
32
|
+
ctx!.fillStyle = value;
|
|
33
|
+
return ctx!.fillStyle;
|
|
34
|
+
};
|
|
35
|
+
if (read("#010203") === "#010203" && read("#040506") === "#040506") return null;
|
|
36
|
+
ctx.clearRect(0, 0, 1, 1);
|
|
37
|
+
ctx.fillStyle = value;
|
|
38
|
+
ctx.fillRect(0, 0, 1, 1);
|
|
39
|
+
const [r, g, b] = ctx.getImageData(0, 0, 1, 1).data;
|
|
40
|
+
const hex = (n: number) => n.toString(16).padStart(2, "0").toUpperCase();
|
|
41
|
+
return `#${hex(r)}${hex(g)}${hex(b)}`;
|
|
42
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where this deploy's Storybook lives, and the address of one page inside it.
|
|
3
|
+
*
|
|
4
|
+
* One source for the Storybook rail link and the Home tab's "Recently added" links, so they cannot point at
|
|
5
|
+
* different Storybooks. In dev it is the local server (localhost:6080). In production the static build is served
|
|
6
|
+
* same-origin at /storybook/<commit-sha>/index.html (see vercel-build and next.config.js); the sha is inlined
|
|
7
|
+
* through NEXT_PUBLIC_STORYBOOK_VERSION. A fork points elsewhere with NEXT_PUBLIC_STORYBOOK_URL, and sets it to ""
|
|
8
|
+
* to say it has no Storybook, in which case this returns "".
|
|
9
|
+
*/
|
|
10
|
+
export function storybookBaseUrl(): string {
|
|
11
|
+
const isDev = process.env.NODE_ENV !== "production";
|
|
12
|
+
return (
|
|
13
|
+
process.env.NEXT_PUBLIC_STORYBOOK_URL ??
|
|
14
|
+
(isDev
|
|
15
|
+
? "http://localhost:6080"
|
|
16
|
+
: `/storybook/${process.env.NEXT_PUBLIC_STORYBOOK_VERSION || "dev"}/index.html`)
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export type StoryRef = { id: string; kind: "docs" | "story" };
|
|
21
|
+
|
|
22
|
+
/** The address of one docs page or story, or "" when this deploy has no Storybook. */
|
|
23
|
+
export function storybookPageUrl(ref: StoryRef): string {
|
|
24
|
+
const base = storybookBaseUrl();
|
|
25
|
+
if (!base) return "";
|
|
26
|
+
const sep = base.includes("?") ? "&" : "?";
|
|
27
|
+
return `${base}${sep}path=/${ref.kind}/${ref.id}`;
|
|
28
|
+
}
|
package/src/lib/theme-editor.ts
CHANGED
|
@@ -59,6 +59,8 @@ export type ThemeColorKey = (typeof THEME_COLOR_KEYS)[number];
|
|
|
59
59
|
|
|
60
60
|
export type ThemeEditorCommon = {
|
|
61
61
|
fontSans: string;
|
|
62
|
+
/** Optional so exports and saved states from before the heading token still load. */
|
|
63
|
+
fontHeading?: string;
|
|
62
64
|
fontSerif: string;
|
|
63
65
|
fontMono: string;
|
|
64
66
|
radius: string;
|
|
@@ -75,7 +77,7 @@ type TokenRecord = Record<string, { $value?: string }>;
|
|
|
75
77
|
|
|
76
78
|
const tokenData = tokens as {
|
|
77
79
|
theme: { light: TokenRecord; dark: TokenRecord };
|
|
78
|
-
fontFamily: { sans: { $value: string }; serif: { $value: string }; mono: { $value: string } };
|
|
80
|
+
fontFamily: { sans: { $value: string }; heading?: { $value: string }; serif: { $value: string }; mono: { $value: string } };
|
|
79
81
|
borderRadius: { lg: { $value: string } };
|
|
80
82
|
};
|
|
81
83
|
|
|
@@ -90,6 +92,7 @@ export const DEFAULT_THEME_EDITOR_STATE: ThemeEditorState = {
|
|
|
90
92
|
dark: readThemeMode("dark"),
|
|
91
93
|
common: {
|
|
92
94
|
fontSans: tokenData.fontFamily.sans.$value,
|
|
95
|
+
fontHeading: tokenData.fontFamily.heading?.$value,
|
|
93
96
|
fontSerif: tokenData.fontFamily.serif.$value,
|
|
94
97
|
fontMono: tokenData.fontFamily.mono.$value,
|
|
95
98
|
radius: tokenData.borderRadius.lg.$value,
|
|
@@ -144,6 +147,7 @@ function emitVariables(values: Record<string, string>) {
|
|
|
144
147
|
export function themeEditorStateToCss(state: ThemeEditorState) {
|
|
145
148
|
const common = {
|
|
146
149
|
"font-sans": state.common.fontSans,
|
|
150
|
+
...(state.common.fontHeading ? { "font-heading": state.common.fontHeading } : {}),
|
|
147
151
|
"font-serif": state.common.fontSerif,
|
|
148
152
|
"font-mono": state.common.fontMono,
|
|
149
153
|
radius: state.common.radius,
|
|
@@ -165,6 +169,7 @@ export function clearManagedInlineThemeProperties(root: HTMLElement) {
|
|
|
165
169
|
}
|
|
166
170
|
|
|
167
171
|
root.style.removeProperty("--font-sans");
|
|
172
|
+
root.style.removeProperty("--font-heading");
|
|
168
173
|
root.style.removeProperty("--font-serif");
|
|
169
174
|
root.style.removeProperty("--font-mono");
|
|
170
175
|
root.style.removeProperty("--radius");
|
|
@@ -199,6 +204,7 @@ export function parseCssToThemeEditorState(css: string): ThemeEditorState {
|
|
|
199
204
|
if (COLOR_KEY_SET.has(key)) {
|
|
200
205
|
next.light[key as ThemeColorKey] = value;
|
|
201
206
|
} else if (key === "font-sans") next.common.fontSans = value;
|
|
207
|
+
else if (key === "font-heading") next.common.fontHeading = value;
|
|
202
208
|
else if (key === "font-serif") next.common.fontSerif = value;
|
|
203
209
|
else if (key === "font-mono") next.common.fontMono = value;
|
|
204
210
|
else if (key === "radius") next.common.radius = value;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads a theme the Studio can import. Pure parsing, no state: the dialog decides what each entry maps to.
|
|
3
|
+
*
|
|
4
|
+
* Accepted:
|
|
5
|
+
* CSS custom properties `:root { --background: ... }` and `.dark { ... }` blocks, the shape shadcn/ui and
|
|
6
|
+
* tweakcn export. Comments are ignored. Other selectors are ignored.
|
|
7
|
+
* tokens.json this repo's file, or a slice of it: `{ "theme": { "light": { "primary": { "$value": ... } },
|
|
8
|
+
* "dark": { ... } } }`, plus any other token path, e.g. `color.primitive.blue.600`.
|
|
9
|
+
* light/dark JSON `{ "light": { "background": "oklch(...)" }, "dark": { ... } }`, the flat shape tweakcn
|
|
10
|
+
* and shadcn theme generators produce. `--` prefixes on the keys are fine.
|
|
11
|
+
* Not accepted: Tokens Studio or Figma variable exports (different structure), SCSS, Tailwind config.
|
|
12
|
+
*/
|
|
13
|
+
export type ThemeEntry = {
|
|
14
|
+
/** CSS variable name without the leading dashes (`background`), or a dotted token path (`color.primitive.blue.600`). */
|
|
15
|
+
name: string;
|
|
16
|
+
mode: "light" | "dark";
|
|
17
|
+
value: string;
|
|
18
|
+
from: "css" | "json";
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export type ParsedTheme = { format: "css" | "json" | null; entries: ThemeEntry[]; error?: string };
|
|
22
|
+
|
|
23
|
+
function parseCss(text: string): ThemeEntry[] {
|
|
24
|
+
const stripped = text.replace(/\/\*[\s\S]*?\*\//g, "");
|
|
25
|
+
const out: ThemeEntry[] = [];
|
|
26
|
+
const blockRe = /([^{}]+)\{([^{}]*)\}/g;
|
|
27
|
+
let m: RegExpExecArray | null;
|
|
28
|
+
while ((m = blockRe.exec(stripped)) !== null) {
|
|
29
|
+
const selector = m[1].trim();
|
|
30
|
+
const mode: "light" | "dark" | null = /^(:root|html)$/i.test(selector) ? "light" : /(^|[\s,])(\.dark|html\.dark|:root\.dark)\b/i.test(selector) ? "dark" : null;
|
|
31
|
+
if (!mode) continue;
|
|
32
|
+
for (const decl of m[2].split(";")) {
|
|
33
|
+
const t = decl.trim();
|
|
34
|
+
if (!t.startsWith("--")) continue;
|
|
35
|
+
const i = t.indexOf(":");
|
|
36
|
+
if (i < 0) continue;
|
|
37
|
+
const name = t.slice(2, i).trim();
|
|
38
|
+
const value = t.slice(i + 1).trim();
|
|
39
|
+
if (name && value) out.push({ name, mode, value, from: "css" });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return out;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const isObj = (v: unknown): v is Record<string, unknown> => !!v && typeof v === "object" && !Array.isArray(v);
|
|
46
|
+
const leafValue = (v: unknown): string | null => (isObj(v) && "$value" in v ? String(v.$value) : typeof v === "string" || typeof v === "number" ? String(v) : null);
|
|
47
|
+
|
|
48
|
+
function parseJson(data: unknown): ThemeEntry[] {
|
|
49
|
+
if (!isObj(data)) return [];
|
|
50
|
+
const out: ThemeEntry[] = [];
|
|
51
|
+
const modes = (rec: unknown, mode: "light" | "dark") => {
|
|
52
|
+
if (!isObj(rec)) return;
|
|
53
|
+
for (const [k, v] of Object.entries(rec)) {
|
|
54
|
+
const value = leafValue(v);
|
|
55
|
+
if (value !== null) out.push({ name: k.replace(/^--/, ""), mode, value, from: "json" });
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
const theme = isObj(data.theme) ? data.theme : data;
|
|
59
|
+
if (isObj(theme.light) || isObj(theme.dark)) {
|
|
60
|
+
modes(theme.light, "light");
|
|
61
|
+
modes(theme.dark, "dark");
|
|
62
|
+
}
|
|
63
|
+
// Any other section of tokens.json: walk to leaves and keep the dotted path.
|
|
64
|
+
const walk = (node: unknown, trail: string[]) => {
|
|
65
|
+
if (isObj(node) && "$value" in node) return void out.push({ name: trail.join("."), mode: "light", value: String(node.$value), from: "json" });
|
|
66
|
+
if (isObj(node)) for (const [k, v] of Object.entries(node)) if (!k.startsWith("$")) walk(v, [...trail, k]);
|
|
67
|
+
};
|
|
68
|
+
for (const [k, v] of Object.entries(data)) {
|
|
69
|
+
if (k === "theme" || k === "light" || k === "dark" || k.startsWith("$") || k === "version") continue;
|
|
70
|
+
walk(v, [k]);
|
|
71
|
+
}
|
|
72
|
+
return out;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function parseThemeInput(text: string): ParsedTheme {
|
|
76
|
+
const t = text.trim();
|
|
77
|
+
if (!t) return { format: null, entries: [] };
|
|
78
|
+
if (t.startsWith("{")) {
|
|
79
|
+
let data: unknown;
|
|
80
|
+
try {
|
|
81
|
+
data = JSON.parse(t);
|
|
82
|
+
} catch {
|
|
83
|
+
data = undefined;
|
|
84
|
+
}
|
|
85
|
+
if (data !== undefined) {
|
|
86
|
+
const entries = parseJson(data);
|
|
87
|
+
return entries.length
|
|
88
|
+
? { format: "json", entries }
|
|
89
|
+
: { format: "json", entries: [], error: "That JSON has no theme or token values in a shape the Studio reads." };
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const entries = parseCss(t);
|
|
93
|
+
if (entries.length) return { format: "css", entries };
|
|
94
|
+
return {
|
|
95
|
+
format: null,
|
|
96
|
+
entries: [],
|
|
97
|
+
error: t.startsWith("{") ? "That looks like JSON but does not parse. Check for a trailing comma or a missing quote." : "No CSS variables found. Paste :root and .dark blocks, or a tokens or light/dark JSON file.",
|
|
98
|
+
};
|
|
99
|
+
}
|