@zonsh/ui 0.7.0 → 0.8.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 +37 -3
- package/README.md +1 -2
- package/dist/components/bottom-nav.js +10 -293
- package/dist/components/button.d.ts +2 -1
- package/dist/components/button.js +2 -0
- package/dist/components/radio-group.d.ts +23 -2
- package/dist/components/radio-group.js +62 -4
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/lib/liquid-mark.d.ts +29 -0
- package/dist/lib/liquid-mark.js +327 -0
- package/dist/skills/zon-ui/SKILL.md +4 -4
- package/dist/skills/zon-ui/references/components/button.md +20 -1
- package/dist/skills/zon-ui/references/components/radio-group.md +73 -2
- package/dist/skills/zon-ui/references/components/theme.md +2 -2
- package/dist/sources/audio-player.css +3 -0
- package/dist/sources/bottom-nav.css +1 -0
- package/dist/sources/button.css +3 -0
- package/dist/sources/carousel.css +3 -0
- package/dist/sources/code-block.css +3 -0
- package/dist/sources/conversation.css +3 -0
- package/dist/sources/copy-button.css +3 -0
- package/dist/sources/data-table.css +2 -0
- package/dist/sources/file-drop.css +3 -0
- package/dist/sources/filter-bar.css +2 -0
- package/dist/sources/lightbox.css +2 -0
- package/dist/sources/markdown-editor.css +2 -0
- package/dist/sources/message.css +3 -0
- package/dist/sources/pagination.css +3 -0
- package/dist/sources/pdf-viewer.css +2 -0
- package/dist/sources/radio-group.css +5 -0
- package/dist/sources/response.css +2 -0
- package/dist/sources/scheduler.css +3 -0
- package/dist/sources/sidebar.css +2 -0
- package/dist/sources/site-header.css +3 -0
- package/dist/sources/sortable.css +3 -0
- package/dist/sources/suggestions.css +3 -0
- package/dist/sources/theme.css +3 -0
- package/dist/sources/tool-call.css +3 -0
- package/dist/sources/tour.css +2 -0
- package/dist/sources/video-player.css +2 -0
- package/dist/styles/core.css +16 -13
- package/dist/styles/parts/controls.css +88 -0
- package/dist/vite.d.ts +41 -11
- package/dist/vite.js +78 -23
- package/package.json +1 -1
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
@source "../lib/collapse-row.js";
|
|
21
21
|
@source "../lib/digit-roll.js";
|
|
22
22
|
@source "../lib/form-reset.js";
|
|
23
|
+
@source "../lib/gesture.js";
|
|
23
24
|
@source "../lib/icons.js";
|
|
24
25
|
@source "../lib/logo-geometry.js";
|
|
25
26
|
@source "../lib/merge-refs.js";
|
|
@@ -27,4 +28,5 @@
|
|
|
27
28
|
@source "../lib/number-roll.js";
|
|
28
29
|
@source "../lib/platform.js";
|
|
29
30
|
@source "../lib/portal-container.js";
|
|
31
|
+
@source "../lib/press.js";
|
|
30
32
|
@source "../lib/room.js";
|
|
@@ -24,10 +24,12 @@
|
|
|
24
24
|
@source "../lib/code-theme.js";
|
|
25
25
|
@source "../lib/collapse-row.js";
|
|
26
26
|
@source "../lib/files.js";
|
|
27
|
+
@source "../lib/gesture.js";
|
|
27
28
|
@source "../lib/icons.js";
|
|
28
29
|
@source "../lib/logo-geometry.js";
|
|
29
30
|
@source "../lib/merge-refs.js";
|
|
30
31
|
@source "../lib/motion.js";
|
|
31
32
|
@source "../lib/platform.js";
|
|
32
33
|
@source "../lib/portal-container.js";
|
|
34
|
+
@source "../lib/press.js";
|
|
33
35
|
@source "../lib/room.js";
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
@source "../lib/code-theme.js";
|
|
26
26
|
@source "../lib/collapse-row.js";
|
|
27
27
|
@source "../lib/files.js";
|
|
28
|
+
@source "../lib/gesture.js";
|
|
28
29
|
@source "../lib/glide.js";
|
|
29
30
|
@source "../lib/icons.js";
|
|
30
31
|
@source "../lib/logo-geometry.js";
|
|
@@ -37,5 +38,6 @@
|
|
|
37
38
|
@source "../lib/motion.js";
|
|
38
39
|
@source "../lib/platform.js";
|
|
39
40
|
@source "../lib/portal-container.js";
|
|
41
|
+
@source "../lib/press.js";
|
|
40
42
|
@source "../lib/room.js";
|
|
41
43
|
@source "../lib/scroll-edges.js";
|
package/dist/sources/message.css
CHANGED
|
@@ -9,8 +9,11 @@
|
|
|
9
9
|
@source "../components/tooltip.js";
|
|
10
10
|
@source "../lib/cn.js";
|
|
11
11
|
@source "../lib/collapse-row.js";
|
|
12
|
+
@source "../lib/gesture.js";
|
|
12
13
|
@source "../lib/icons.js";
|
|
13
14
|
@source "../lib/logo-geometry.js";
|
|
14
15
|
@source "../lib/merge-refs.js";
|
|
16
|
+
@source "../lib/motion.js";
|
|
15
17
|
@source "../lib/portal-container.js";
|
|
18
|
+
@source "../lib/press.js";
|
|
16
19
|
@source "../lib/room.js";
|
|
@@ -5,7 +5,10 @@
|
|
|
5
5
|
@source "../components/spinner.js";
|
|
6
6
|
@source "../lib/cn.js";
|
|
7
7
|
@source "../lib/collapse-row.js";
|
|
8
|
+
@source "../lib/gesture.js";
|
|
8
9
|
@source "../lib/glide.js";
|
|
9
10
|
@source "../lib/icons.js";
|
|
10
11
|
@source "../lib/logo-geometry.js";
|
|
11
12
|
@source "../lib/merge-refs.js";
|
|
13
|
+
@source "../lib/motion.js";
|
|
14
|
+
@source "../lib/press.js";
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
@source "../components/tooltip.js";
|
|
18
18
|
@source "../lib/cn.js";
|
|
19
19
|
@source "../lib/collapse-row.js";
|
|
20
|
+
@source "../lib/gesture.js";
|
|
20
21
|
@source "../lib/glide.js";
|
|
21
22
|
@source "../lib/icons.js";
|
|
22
23
|
@source "../lib/logo-geometry.js";
|
|
@@ -26,5 +27,6 @@
|
|
|
26
27
|
@source "../lib/pdf.js";
|
|
27
28
|
@source "../lib/platform.js";
|
|
28
29
|
@source "../lib/portal-container.js";
|
|
30
|
+
@source "../lib/press.js";
|
|
29
31
|
@source "../lib/room.js";
|
|
30
32
|
@source "../lib/scroll-edges.js";
|
|
@@ -2,4 +2,9 @@
|
|
|
2
2
|
@source "../components/radio-group.js";
|
|
3
3
|
@source "../lib/cn.js";
|
|
4
4
|
@source "../lib/form-reset.js";
|
|
5
|
+
@source "../lib/gesture.js";
|
|
6
|
+
@source "../lib/glide.js";
|
|
7
|
+
@source "../lib/liquid-mark.js";
|
|
5
8
|
@source "../lib/merge-refs.js";
|
|
9
|
+
@source "../lib/motion.js";
|
|
10
|
+
@source "../lib/press.js";
|
|
@@ -9,8 +9,10 @@
|
|
|
9
9
|
@source "../lib/code-highlight.js";
|
|
10
10
|
@source "../lib/code-theme.js";
|
|
11
11
|
@source "../lib/collapse-row.js";
|
|
12
|
+
@source "../lib/gesture.js";
|
|
12
13
|
@source "../lib/icons.js";
|
|
13
14
|
@source "../lib/logo-geometry.js";
|
|
14
15
|
@source "../lib/markdown-guard.js";
|
|
15
16
|
@source "../lib/merge-refs.js";
|
|
16
17
|
@source "../lib/motion.js";
|
|
18
|
+
@source "../lib/press.js";
|
|
@@ -32,13 +32,16 @@
|
|
|
32
32
|
@source "../lib/drag.js";
|
|
33
33
|
@source "../lib/field-errors.js";
|
|
34
34
|
@source "../lib/form-reset.js";
|
|
35
|
+
@source "../lib/gesture.js";
|
|
35
36
|
@source "../lib/glide.js";
|
|
36
37
|
@source "../lib/icons.js";
|
|
38
|
+
@source "../lib/liquid-mark.js";
|
|
37
39
|
@source "../lib/logo-geometry.js";
|
|
38
40
|
@source "../lib/merge-refs.js";
|
|
39
41
|
@source "../lib/motion.js";
|
|
40
42
|
@source "../lib/platform.js";
|
|
41
43
|
@source "../lib/portal-container.js";
|
|
44
|
+
@source "../lib/press.js";
|
|
42
45
|
@source "../lib/room.js";
|
|
43
46
|
@source "../lib/scheduler.js";
|
|
44
47
|
@source "../lib/scroll-edges.js";
|
package/dist/sources/sidebar.css
CHANGED
|
@@ -10,10 +10,12 @@
|
|
|
10
10
|
@source "../components/tooltip.js";
|
|
11
11
|
@source "../lib/cn.js";
|
|
12
12
|
@source "../lib/collapse-row.js";
|
|
13
|
+
@source "../lib/gesture.js";
|
|
13
14
|
@source "../lib/icons.js";
|
|
14
15
|
@source "../lib/logo-geometry.js";
|
|
15
16
|
@source "../lib/merge-refs.js";
|
|
16
17
|
@source "../lib/motion.js";
|
|
17
18
|
@source "../lib/platform.js";
|
|
18
19
|
@source "../lib/portal-container.js";
|
|
20
|
+
@source "../lib/press.js";
|
|
19
21
|
@source "../lib/room.js";
|
|
@@ -7,9 +7,12 @@
|
|
|
7
7
|
@source "../components/spinner.js";
|
|
8
8
|
@source "../lib/cn.js";
|
|
9
9
|
@source "../lib/collapse-row.js";
|
|
10
|
+
@source "../lib/gesture.js";
|
|
10
11
|
@source "../lib/glide.js";
|
|
11
12
|
@source "../lib/icons.js";
|
|
12
13
|
@source "../lib/logo-geometry.js";
|
|
13
14
|
@source "../lib/merge-refs.js";
|
|
15
|
+
@source "../lib/motion.js";
|
|
14
16
|
@source "../lib/portal-container.js";
|
|
17
|
+
@source "../lib/press.js";
|
|
15
18
|
@source "../lib/room.js";
|
|
@@ -6,7 +6,10 @@
|
|
|
6
6
|
@source "../lib/cn.js";
|
|
7
7
|
@source "../lib/collapse-row.js";
|
|
8
8
|
@source "../lib/drag.js";
|
|
9
|
+
@source "../lib/gesture.js";
|
|
9
10
|
@source "../lib/icons.js";
|
|
10
11
|
@source "../lib/logo-geometry.js";
|
|
11
12
|
@source "../lib/merge-refs.js";
|
|
13
|
+
@source "../lib/motion.js";
|
|
12
14
|
@source "../lib/portal-container.js";
|
|
15
|
+
@source "../lib/press.js";
|
|
@@ -5,6 +5,9 @@
|
|
|
5
5
|
@source "../components/suggestions.js";
|
|
6
6
|
@source "../lib/cn.js";
|
|
7
7
|
@source "../lib/collapse-row.js";
|
|
8
|
+
@source "../lib/gesture.js";
|
|
8
9
|
@source "../lib/icons.js";
|
|
9
10
|
@source "../lib/logo-geometry.js";
|
|
10
11
|
@source "../lib/merge-refs.js";
|
|
12
|
+
@source "../lib/motion.js";
|
|
13
|
+
@source "../lib/press.js";
|
package/dist/sources/theme.css
CHANGED
|
@@ -5,9 +5,12 @@
|
|
|
5
5
|
@source "../components/theme.js";
|
|
6
6
|
@source "../lib/cn.js";
|
|
7
7
|
@source "../lib/collapse-row.js";
|
|
8
|
+
@source "../lib/gesture.js";
|
|
8
9
|
@source "../lib/icons.js";
|
|
9
10
|
@source "../lib/logo-geometry.js";
|
|
10
11
|
@source "../lib/merge-refs.js";
|
|
12
|
+
@source "../lib/motion.js";
|
|
11
13
|
@source "../lib/portal-container.js";
|
|
14
|
+
@source "../lib/press.js";
|
|
12
15
|
@source "../lib/theme-preset.js";
|
|
13
16
|
@source "../lib/theme-script.js";
|
|
@@ -11,6 +11,9 @@
|
|
|
11
11
|
@source "../lib/code-highlight.js";
|
|
12
12
|
@source "../lib/code-theme.js";
|
|
13
13
|
@source "../lib/collapse-row.js";
|
|
14
|
+
@source "../lib/gesture.js";
|
|
14
15
|
@source "../lib/icons.js";
|
|
15
16
|
@source "../lib/logo-geometry.js";
|
|
16
17
|
@source "../lib/merge-refs.js";
|
|
18
|
+
@source "../lib/motion.js";
|
|
19
|
+
@source "../lib/press.js";
|
package/dist/sources/tour.css
CHANGED
|
@@ -6,9 +6,11 @@
|
|
|
6
6
|
@source "../components/tour.js";
|
|
7
7
|
@source "../lib/cn.js";
|
|
8
8
|
@source "../lib/collapse-row.js";
|
|
9
|
+
@source "../lib/gesture.js";
|
|
9
10
|
@source "../lib/icons.js";
|
|
10
11
|
@source "../lib/logo-geometry.js";
|
|
11
12
|
@source "../lib/merge-refs.js";
|
|
12
13
|
@source "../lib/motion.js";
|
|
13
14
|
@source "../lib/portal-container.js";
|
|
15
|
+
@source "../lib/press.js";
|
|
14
16
|
@source "../lib/room.js";
|
|
@@ -12,10 +12,12 @@
|
|
|
12
12
|
@source "../components/video-player.js";
|
|
13
13
|
@source "../lib/cn.js";
|
|
14
14
|
@source "../lib/collapse-row.js";
|
|
15
|
+
@source "../lib/gesture.js";
|
|
15
16
|
@source "../lib/icons.js";
|
|
16
17
|
@source "../lib/logo-geometry.js";
|
|
17
18
|
@source "../lib/merge-refs.js";
|
|
18
19
|
@source "../lib/motion.js";
|
|
19
20
|
@source "../lib/platform.js";
|
|
20
21
|
@source "../lib/portal-container.js";
|
|
22
|
+
@source "../lib/press.js";
|
|
21
23
|
@source "../lib/room.js";
|
package/dist/styles/core.css
CHANGED
|
@@ -219,42 +219,45 @@
|
|
|
219
219
|
background-color: var(--foreground);
|
|
220
220
|
color: var(--background);
|
|
221
221
|
}
|
|
222
|
-
/* Native scrollbars
|
|
223
|
-
--field-edge thumb on a transparent track, no arrow buttons. Chrome, Edge and Safari
|
|
224
|
-
that from the ::-webkit-scrollbar parts — Chrome ignores them, and draws its own arrows,
|
|
222
|
+
/* Native scrollbars inside the page (tables, overflow-auto panels) echo ScrollArea: a 4px
|
|
223
|
+
round --field-edge thumb on a transparent track, no arrow buttons. Chrome, Edge and Safari
|
|
224
|
+
draw that from the ::-webkit-scrollbar parts — Chrome ignores them, and draws its own arrows,
|
|
225
225
|
once an element sets scrollbar-width or scrollbar-color, so those are left to Firefox,
|
|
226
|
-
which has no arrows. ScrollArea hides all of these and draws its own.
|
|
226
|
+
which has no arrows. ScrollArea hides all of these and draws its own.
|
|
227
|
+
The page's own scrollbar (the root's, and the body's when it scrolls) is left to the browser:
|
|
228
|
+
styled, Chrome and Edge on Windows 11 give up their thin overlay bar for a classic one with a
|
|
229
|
+
gutter down the side, which shows the page ground beside dark full-bleed sections. */
|
|
227
230
|
@supports selector(::-webkit-scrollbar) {
|
|
228
|
-
::-webkit-scrollbar {
|
|
231
|
+
:not(:root, body)::-webkit-scrollbar {
|
|
229
232
|
width: 10px;
|
|
230
233
|
height: 10px;
|
|
231
234
|
}
|
|
232
|
-
::-webkit-scrollbar-track,
|
|
233
|
-
::-webkit-scrollbar-corner {
|
|
235
|
+
:not(:root, body)::-webkit-scrollbar-track,
|
|
236
|
+
:not(:root, body)::-webkit-scrollbar-corner {
|
|
234
237
|
background: transparent;
|
|
235
238
|
}
|
|
236
239
|
/* A rounded scroller sets --scrollbar-inset to its radius, so the bar starts and ends where
|
|
237
240
|
the corners do instead of running over them. */
|
|
238
|
-
::-webkit-scrollbar-track:vertical {
|
|
241
|
+
:not(:root, body)::-webkit-scrollbar-track:vertical {
|
|
239
242
|
margin-block: var(--scrollbar-inset, 0px);
|
|
240
243
|
}
|
|
241
|
-
::-webkit-scrollbar-track:horizontal {
|
|
244
|
+
:not(:root, body)::-webkit-scrollbar-track:horizontal {
|
|
242
245
|
margin-inline: var(--scrollbar-inset, 0px);
|
|
243
246
|
}
|
|
244
|
-
::-webkit-scrollbar-thumb {
|
|
247
|
+
:not(:root, body)::-webkit-scrollbar-thumb {
|
|
245
248
|
border: 3px solid transparent;
|
|
246
249
|
border-radius: 9999px;
|
|
247
250
|
background: var(--field-edge) padding-box;
|
|
248
251
|
}
|
|
249
|
-
::-webkit-scrollbar-thumb:hover {
|
|
252
|
+
:not(:root, body)::-webkit-scrollbar-thumb:hover {
|
|
250
253
|
background-color: var(--control-focus);
|
|
251
254
|
}
|
|
252
|
-
::-webkit-scrollbar-button {
|
|
255
|
+
:not(:root, body)::-webkit-scrollbar-button {
|
|
253
256
|
display: none;
|
|
254
257
|
}
|
|
255
258
|
}
|
|
256
259
|
@supports not selector(::-webkit-scrollbar) {
|
|
257
|
-
|
|
260
|
+
:not(:root, body) {
|
|
258
261
|
scrollbar-width: thin;
|
|
259
262
|
scrollbar-color: var(--field-edge) transparent;
|
|
260
263
|
}
|
|
@@ -785,3 +785,91 @@
|
|
|
785
785
|
border-width: 2px;
|
|
786
786
|
}
|
|
787
787
|
}
|
|
788
|
+
|
|
789
|
+
/* ── RadioGroup capsule ───────────────────────────────────────────────────────
|
|
790
|
+
* The options side by side on the field's track, the checked one on a raised pill that glides, and
|
|
791
|
+
* that swells and follows the finger as a lens when pressed or dragged (lib/liquid-mark.ts), as a
|
|
792
|
+
* capsule BottomNav's. A segment rests in the muted ink; checked, hovered or under the lens, in
|
|
793
|
+
* the full one. */
|
|
794
|
+
|
|
795
|
+
@layer components {
|
|
796
|
+
[data-slot="radio"][data-variant="capsule"] {
|
|
797
|
+
color: var(--control-muted);
|
|
798
|
+
transition: color var(--duration-fade) var(--ease);
|
|
799
|
+
}
|
|
800
|
+
[data-slot="radio"][data-variant="capsule"]:is(
|
|
801
|
+
[aria-checked="true"],
|
|
802
|
+
[data-under],
|
|
803
|
+
[data-pressing],
|
|
804
|
+
:active
|
|
805
|
+
) {
|
|
806
|
+
color: var(--foreground);
|
|
807
|
+
}
|
|
808
|
+
@media (hover: hover) {
|
|
809
|
+
[data-slot="radio"][data-variant="capsule"]:not([data-disabled], [data-readonly]):hover {
|
|
810
|
+
color: var(--foreground);
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
/* Vertical pans still scroll the page; a sideways one drags the pill. No callout on a hold. */
|
|
814
|
+
[data-slot="radio-group"][data-variant="capsule"],
|
|
815
|
+
[data-slot="radio"][data-variant="capsule"] {
|
|
816
|
+
touch-action: pan-y;
|
|
817
|
+
-webkit-touch-callout: none;
|
|
818
|
+
}
|
|
819
|
+
[data-slot="radio-group"][data-dragging] {
|
|
820
|
+
cursor: grabbing;
|
|
821
|
+
}
|
|
822
|
+
/* The lift under the lens, written by its spring each frame (--lens-lift, 0 at rest, 1 swollen). */
|
|
823
|
+
[data-slot="radio-group-indicator"] {
|
|
824
|
+
--lens-lift: 0;
|
|
825
|
+
filter: drop-shadow(
|
|
826
|
+
0 calc(6px * var(--lens-lift)) calc(10px * var(--lens-lift)) rgb(0 0 0 / calc(0.2 * var(--lens-lift)))
|
|
827
|
+
)
|
|
828
|
+
drop-shadow(
|
|
829
|
+
0 calc(2px * var(--lens-lift)) calc(4px * var(--lens-lift)) rgb(0 0 0 / calc(0.1 * var(--lens-lift)))
|
|
830
|
+
);
|
|
831
|
+
}
|
|
832
|
+
/* Pressed, the segment's content presses in and springs back past its size, as a capsule nav's
|
|
833
|
+
icon; under reduced motion only the ink changes. Dragging, the one under the lens swells. */
|
|
834
|
+
[data-slot="radio"][data-variant="capsule"] > [data-slot="radio-label"] {
|
|
835
|
+
transition: scale calc(var(--duration) * 2) var(--ease-pop);
|
|
836
|
+
}
|
|
837
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
838
|
+
[data-slot="radio"][data-variant="capsule"]:not([data-disabled], [data-readonly]):is(
|
|
839
|
+
:active,
|
|
840
|
+
[data-pressing]
|
|
841
|
+
)
|
|
842
|
+
> [data-slot="radio-label"] {
|
|
843
|
+
scale: 0.9;
|
|
844
|
+
transition: scale calc(var(--duration) * 0.6) var(--ease);
|
|
845
|
+
}
|
|
846
|
+
[data-slot="radio-group"][data-dragging][data-dragging]
|
|
847
|
+
[data-slot="radio"][data-under]:not([data-disabled])
|
|
848
|
+
> [data-slot="radio-label"] {
|
|
849
|
+
scale: 1.12;
|
|
850
|
+
}
|
|
851
|
+
[data-slot="radio-group"][data-dragging][data-dragging]
|
|
852
|
+
[data-slot="radio"]:not([data-under])
|
|
853
|
+
> [data-slot="radio-label"] {
|
|
854
|
+
scale: 1;
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
/* Until the pill has measured (server-rendered HTML), the checked segment is raised itself. */
|
|
858
|
+
[data-slot="radio-group"][data-variant="capsule"]:not(
|
|
859
|
+
:has(> [data-slot="radio-group-indicator"][data-visible])
|
|
860
|
+
)
|
|
861
|
+
> [data-slot="radio"][aria-checked="true"] {
|
|
862
|
+
background-color: var(--control-surface);
|
|
863
|
+
background-image: linear-gradient(180deg, var(--control-inner-edge), transparent);
|
|
864
|
+
box-shadow:
|
|
865
|
+
0 0 0 1px var(--control-edge),
|
|
866
|
+
inset 0 1px 0 var(--control-highlight),
|
|
867
|
+
inset 0 0 0 1px var(--control-inner-edge);
|
|
868
|
+
}
|
|
869
|
+
@media (forced-colors: active) {
|
|
870
|
+
[data-slot="radio-group-indicator"] {
|
|
871
|
+
forced-color-adjust: none;
|
|
872
|
+
border: 2px solid Highlight;
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
}
|
package/dist/vite.d.ts
CHANGED
|
@@ -5,8 +5,10 @@
|
|
|
5
5
|
* the right scheme on its first paint without pasting the script by hand; with `preset`, it puts
|
|
6
6
|
* the theme's stylesheet there too, so a brand colour is right on the first paint as well.
|
|
7
7
|
*
|
|
8
|
-
* The fonts
|
|
9
|
-
*
|
|
8
|
+
* The fonts come with `@import "@zonsh/ui/styles.css"`: their @font-face rules and WOFF2 files (from
|
|
9
|
+
* licht), which the bundler copies into the build under hashed names. The browser would find a face
|
|
10
|
+
* only once it has the CSS and has laid out text that needs it, painting a fallback until then, so
|
|
11
|
+
* in a build the plugin also preloads the faces nearly every page sets, by their built names.
|
|
10
12
|
*/
|
|
11
13
|
import { type ThemeInput } from "./lib/theme-preset.js";
|
|
12
14
|
import { type ThemeMode } from "./lib/theme-script.js";
|
|
@@ -24,6 +26,22 @@ export interface ZonThemeScriptOptions {
|
|
|
24
26
|
* A theme it can't read stops the build with the reason.
|
|
25
27
|
*/
|
|
26
28
|
preset?: ThemeInput;
|
|
29
|
+
/**
|
|
30
|
+
* Preload the Licht faces in a build, so the first paint is already in Licht rather than a
|
|
31
|
+
* fallback. Default `true`: Licht Light (headlines), Licht Sans Regular and Medium, Licht Mono
|
|
32
|
+
* Regular. A list names the cuts by file instead (`"LichtSans-SemiBold"`, `"LichtMono-Medium"` …);
|
|
33
|
+
* `false` preloads none. Only cuts in the build are linked; the dev server links none.
|
|
34
|
+
*/
|
|
35
|
+
preloadFonts?: boolean | readonly string[];
|
|
36
|
+
}
|
|
37
|
+
/** The cuts nearly every page sets: headlines, reading copy and controls, labels. */
|
|
38
|
+
export declare const ZON_PRELOAD_FONTS: readonly ["LichtSerif-Light", "LichtSans-Regular", "LichtSans-Medium", "LichtMono-Regular"];
|
|
39
|
+
interface BuiltAsset {
|
|
40
|
+
type: string;
|
|
41
|
+
fileName: string;
|
|
42
|
+
name?: string;
|
|
43
|
+
names?: readonly string[];
|
|
44
|
+
originalFileNames?: readonly string[];
|
|
27
45
|
}
|
|
28
46
|
/**
|
|
29
47
|
* A Vite plugin that inlines the theme's no-flash script in `<head>` (right after
|
|
@@ -41,15 +59,27 @@ export interface ZonThemeScriptOptions {
|
|
|
41
59
|
* export default defineConfig({ plugins: [react(), tailwindcss(), zonThemeScript({ preset })] });
|
|
42
60
|
* ```
|
|
43
61
|
*/
|
|
44
|
-
export declare function zonThemeScript({ preset, ...options }?: ZonThemeScriptOptions): {
|
|
62
|
+
export declare function zonThemeScript({ preset, preloadFonts, ...options }?: ZonThemeScriptOptions): {
|
|
45
63
|
name: string;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
64
|
+
configResolved(config: {
|
|
65
|
+
base: string;
|
|
66
|
+
}): void;
|
|
67
|
+
transformIndexHtml: {
|
|
68
|
+
order: "post";
|
|
69
|
+
handler(html?: string, ctx?: {
|
|
70
|
+
path?: string;
|
|
71
|
+
bundle?: Record<string, BuiltAsset | {
|
|
72
|
+
type: string;
|
|
73
|
+
}>;
|
|
74
|
+
}): {
|
|
75
|
+
html: string;
|
|
76
|
+
tags: {
|
|
77
|
+
tag: string;
|
|
78
|
+
attrs?: Record<string, string | boolean>;
|
|
79
|
+
children: string;
|
|
80
|
+
injectTo: "head" | "head-prepend";
|
|
81
|
+
}[];
|
|
82
|
+
};
|
|
54
83
|
};
|
|
55
84
|
};
|
|
85
|
+
export {};
|
package/dist/vite.js
CHANGED
|
@@ -5,11 +5,39 @@
|
|
|
5
5
|
* the right scheme on its first paint without pasting the script by hand; with `preset`, it puts
|
|
6
6
|
* the theme's stylesheet there too, so a brand colour is right on the first paint as well.
|
|
7
7
|
*
|
|
8
|
-
* The fonts
|
|
9
|
-
*
|
|
8
|
+
* The fonts come with `@import "@zonsh/ui/styles.css"`: their @font-face rules and WOFF2 files (from
|
|
9
|
+
* licht), which the bundler copies into the build under hashed names. The browser would find a face
|
|
10
|
+
* only once it has the CSS and has laid out text that needs it, painting a fallback until then, so
|
|
11
|
+
* in a build the plugin also preloads the faces nearly every page sets, by their built names.
|
|
10
12
|
*/
|
|
11
13
|
import { themeFromPreset } from "./lib/theme-preset.js";
|
|
12
14
|
import { themeScriptFor } from "./lib/theme-script.js";
|
|
15
|
+
/** The cuts nearly every page sets: headlines, reading copy and controls, labels. */
|
|
16
|
+
export const ZON_PRELOAD_FONTS = [
|
|
17
|
+
"LichtSerif-Light",
|
|
18
|
+
"LichtSans-Regular",
|
|
19
|
+
"LichtSans-Medium",
|
|
20
|
+
"LichtMono-Regular",
|
|
21
|
+
];
|
|
22
|
+
/** The built file names of the cuts asked for, in that order, from the bundle Vite is writing. */
|
|
23
|
+
function builtFonts(bundle, cuts) {
|
|
24
|
+
const assets = Object.values(bundle).filter((item) => item.type === "asset" && /\.woff2$/.test(item.fileName));
|
|
25
|
+
const found = [];
|
|
26
|
+
for (const cut of cuts) {
|
|
27
|
+
const file = `${cut}.woff2`;
|
|
28
|
+
const asset = assets.find((a) => [...(a.originalFileNames ?? []), ...(a.names ?? []), a.name ?? ""].some((n) => n.split("/").pop() === file)) ?? assets.find((a) => new RegExp(`(^|/)${cut}-[\\w-]{8}\\.woff2$`).test(a.fileName));
|
|
29
|
+
if (asset && !found.includes(asset.fileName))
|
|
30
|
+
found.push(asset.fileName);
|
|
31
|
+
}
|
|
32
|
+
return found;
|
|
33
|
+
}
|
|
34
|
+
/** A built file's URL from a page at `page` ("/index.html"), with Vite's `base`. */
|
|
35
|
+
function assetHref(base, page, fileName) {
|
|
36
|
+
if (base && !base.startsWith("."))
|
|
37
|
+
return `${base.endsWith("/") ? base : `${base}/`}${fileName}`;
|
|
38
|
+
const depth = page.replace(/^\//, "").split("/").length - 1;
|
|
39
|
+
return `${depth ? "../".repeat(depth) : "./"}${fileName}`;
|
|
40
|
+
}
|
|
13
41
|
/** The `<meta charset>` tag, which must stay within the first 1024 bytes: the script goes after it. */
|
|
14
42
|
const CHARSET = /<meta\s[^>]*\bcharset\s*=[^>]*>/i;
|
|
15
43
|
/**
|
|
@@ -28,35 +56,62 @@ const CHARSET = /<meta\s[^>]*\bcharset\s*=[^>]*>/i;
|
|
|
28
56
|
* export default defineConfig({ plugins: [react(), tailwindcss(), zonThemeScript({ preset })] });
|
|
29
57
|
* ```
|
|
30
58
|
*/
|
|
31
|
-
export function zonThemeScript({ preset, ...options } = {}) {
|
|
59
|
+
export function zonThemeScript({ preset, preloadFonts = true, ...options } = {}) {
|
|
32
60
|
const theme = preset ? themeFromPreset(preset) : null;
|
|
33
61
|
const ground = preset ? themeFromPreset(preset, { format: "hex" }) : null;
|
|
34
62
|
const tone = ground?.light["--background"] && ground.dark["--background"]
|
|
35
63
|
? { light: ground.light["--background"], dark: ground.dark["--background"] }
|
|
36
64
|
: undefined;
|
|
37
65
|
const script = themeScriptFor(options, tone);
|
|
66
|
+
const cuts = preloadFonts === true ? ZON_PRELOAD_FONTS : preloadFonts || [];
|
|
67
|
+
let base = "/";
|
|
38
68
|
return {
|
|
39
69
|
name: "zon-theme-script",
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
70
|
+
configResolved(config) {
|
|
71
|
+
base = config.base;
|
|
72
|
+
},
|
|
73
|
+
// After Vite's own HTML work, when a build has its bundle and the fonts' hashed names.
|
|
74
|
+
transformIndexHtml: {
|
|
75
|
+
order: "post",
|
|
76
|
+
handler(html = "", ctx = {}) {
|
|
77
|
+
const tags = [];
|
|
78
|
+
let out = html;
|
|
79
|
+
// Preloads right after the script, ahead of the stylesheet that names the faces.
|
|
80
|
+
const fonts = ctx.bundle ? builtFonts(ctx.bundle, cuts) : [];
|
|
81
|
+
const page = ctx.path ?? "/index.html";
|
|
82
|
+
const preloads = fonts.map((file) => ({
|
|
83
|
+
tag: "link",
|
|
84
|
+
attrs: {
|
|
85
|
+
rel: "preload",
|
|
86
|
+
as: "font",
|
|
87
|
+
type: "font/woff2",
|
|
88
|
+
href: assetHref(base, page, file),
|
|
89
|
+
crossorigin: true,
|
|
90
|
+
},
|
|
91
|
+
children: "",
|
|
92
|
+
injectTo: "head-prepend",
|
|
93
|
+
}));
|
|
94
|
+
const charset = CHARSET.exec(html);
|
|
95
|
+
if (charset) {
|
|
96
|
+
const at = charset.index + charset[0].length;
|
|
97
|
+
const links = preloads
|
|
98
|
+
.map((l) => `\n <link rel="preload" as="font" type="font/woff2" href="${l.attrs.href}" crossorigin>`)
|
|
99
|
+
.join("");
|
|
100
|
+
out = `${html.slice(0, at)}\n <script>${script}</script>${links}${html.slice(at)}`;
|
|
101
|
+
}
|
|
102
|
+
else
|
|
103
|
+
tags.push({ tag: "script", children: script, injectTo: "head-prepend" }, ...preloads);
|
|
104
|
+
// At the end of <head>: in a build that is after the library's stylesheet link, which it
|
|
105
|
+
// overrides as ThemeProvider's own <style> does once the app runs.
|
|
106
|
+
if (theme)
|
|
107
|
+
tags.push({
|
|
108
|
+
tag: "style",
|
|
109
|
+
attrs: { "data-zon-theme-preset": "" },
|
|
110
|
+
children: theme.css,
|
|
111
|
+
injectTo: "head",
|
|
112
|
+
});
|
|
113
|
+
return { html: out, tags };
|
|
114
|
+
},
|
|
60
115
|
},
|
|
61
116
|
};
|
|
62
117
|
}
|