@plexui/styles 0.1.34 → 0.1.35
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/dist/es/components/Accordion/Accordion.module.css +12 -1
- package/dist/es/components/Alert/Alert.module.css +101 -0
- package/dist/es/components/Badge/Badge.module.css +37 -0
- package/dist/es/components/Breadcrumb/Breadcrumb.module.css +29 -0
- package/dist/es/components/Button/Button.module.css +53 -0
- package/dist/es/components/Button/NavigationButton.module.css +17 -0
- package/dist/es/components/ButtonGroup/ButtonGroup.module.css +227 -20
- package/dist/es/components/Card/Card.module.css +9 -0
- package/dist/es/components/CodeBlock/CodeBlock.module.css +14 -1
- package/dist/es/components/ColorPicker/ColorPicker.module.css +19 -1
- package/dist/es/components/DatePicker/Calendar.module.css +262 -2
- package/dist/es/components/DatePicker/CalendarNavigationIcon.module.css +10 -0
- package/dist/es/components/DateRangePicker/Calendar.module.css +207 -3
- package/dist/es/components/DateRangePicker/Trigger.module.css +17 -2
- package/dist/es/components/Dialog/Dialog.module.css +660 -13
- package/dist/es/components/EmptyMessage/EmptyMessage.module.css +21 -0
- package/dist/es/components/Field/Field.module.css +387 -2
- package/dist/es/components/FieldGroup/FieldGroup.module.css +129 -3
- package/dist/es/components/FileUpload/FileUpload.module.css +74 -1
- package/dist/es/components/FloatingLabelInput/FloatingLabelInput.module.css +19 -1
- package/dist/es/components/FloatingLabelSelect/FloatingLabelSelect.module.css +12 -1
- package/dist/es/components/IndexBar/IndexBar.module.css +146 -0
- package/dist/es/components/Input/Input.module.css +129 -1
- package/dist/es/components/MarkdownEditor/MarkdownEditor.module.css +18 -0
- package/dist/es/components/Menu/Menu.module.css +267 -7
- package/dist/es/components/OTPInput/OTPInput.module.css +6 -1
- package/dist/es/components/Page/Page.module.css +302 -10
- package/dist/es/components/PhoneLayout/PhoneLayout.module.css +10 -0
- package/dist/es/components/Popover/Popover.module.css +7 -0
- package/dist/es/components/Select/Select.module.css +148 -0
- package/dist/es/components/SelectControl/SelectControl.module.css +113 -1
- package/dist/es/components/Sidebar/Sidebar.module.css +354 -20
- package/dist/es/components/Slider/Slider.module.css +80 -0
- package/dist/es/components/SwipeActions/SwipeActions.module.css +166 -0
- package/dist/es/components/Switch/Switch.module.css +59 -4
- package/dist/es/components/TabBar/TabBar.module.css +255 -10
- package/dist/es/components/Tabs/Tabs.module.css +166 -1
- package/dist/es/components/TagInput/TagInput.module.css +50 -9
- package/dist/es/components/Textarea/Textarea.module.css +6 -0
- package/dist/es/components/Tip/Tip.module.css +456 -0
- package/dist/es/components/Toast/Toast.module.css +148 -5
- package/dist/es/components/Toolbar/Toolbar.module.css +642 -3
- package/dist/es/styles/mobile-materials.css +94 -5
- package/dist/es/styles/mobile-surfaces.css +43 -0
- package/dist/es/styles/touch.css +618 -8
- package/dist/es/styles/variables-components.css +125 -5
- package/package.json +1 -1
- package/postcss/parseLightDark.mjs +20 -2
- package/postcss/phoneLayoutScope.mjs +134 -0
- package/postcss.config.mjs +3 -0
|
@@ -156,6 +156,20 @@
|
|
|
156
156
|
--button-group-text-border-color: var(--color-border-secondary-outline, var(--color-border));
|
|
157
157
|
--button-group-text-font-size: var(--font-text-sm-size);
|
|
158
158
|
--button-group-text-font-weight: var(--font-weight-medium);
|
|
159
|
+
/* A glass group on a phone (`mobileMaterial="glass"`, or any group in a Toolbar): the Button Group of the iOS 27
|
|
160
|
+
kit (Toolbars 507:25993, _Buttons - 44pt and 48pt, Type=Button Group). A row is the 44pt top bar's capsule,
|
|
161
|
+
160 wide with three symbols: 2 + 44 + 12 + 44 + 12 + 44 + 2, the centers of the kit's 36pt symbols 56 apart
|
|
162
|
+
(padding 6, gap 20). A column is the kit's only vertical one, the 48pt capsule, 48 x 164 with three symbols:
|
|
163
|
+
4 + 48 + 6 + 48 + 6 + 48 + 4 (the kit's padding 10, gap 18 around 36pt symbols). Groups side by side keep the
|
|
164
|
+
10px of the top bar's items. In a Toolbar a group takes the bar's own sizes instead. */
|
|
165
|
+
--button-group-glass-item-size: var(--toolbar-top-item-size);
|
|
166
|
+
--button-group-glass-gap: var(--toolbar-group-gap);
|
|
167
|
+
--button-group-glass-padding: var(--toolbar-group-padding);
|
|
168
|
+
--button-group-glass-vertical-item-size: var(--toolbar-bottom-item-size);
|
|
169
|
+
--button-group-glass-vertical-gap: var(--toolbar-bottom-group-gap);
|
|
170
|
+
--button-group-glass-vertical-padding: var(--toolbar-bottom-group-padding);
|
|
171
|
+
--button-group-glass-nested-gap: var(--toolbar-top-item-gap);
|
|
172
|
+
--button-group-glass-label-gutter: var(--toolbar-label-gutter);
|
|
159
173
|
|
|
160
174
|
/* =============================================
|
|
161
175
|
Accordion
|
|
@@ -296,6 +310,39 @@
|
|
|
296
310
|
--field-group-description-font-size: var(--font-text-sm-size);
|
|
297
311
|
--field-group-description-line-height: var(--font-text-sm-line-height);
|
|
298
312
|
|
|
313
|
+
/* =============================================
|
|
314
|
+
Swipe actions
|
|
315
|
+
============================================= */
|
|
316
|
+
/* Actions behind a row of a list, after the iOS 27 kit Row with Swipe Actions (Lists 550:49969; there is no native
|
|
317
|
+
frame of a swipe): Symbol Only capsules of 60x44 with the symbol in 8px ends; Symbol and Label 84x44 with a 16pt
|
|
318
|
+
symbol 8px before a 13/15 label; Symbol and Label Tall a 60x38 capsule 6px from the top of a row of 68 with a
|
|
319
|
+
13/15 medium label 5px under it. The actions stand 10px apart, 16px from the edge and 10px from the content. A
|
|
320
|
+
17pt symbol draws as a 20px PlexUI icon, a 16pt one as 18px. A longer label widens its capsule past 84 with the
|
|
321
|
+
kit's 4px ends (text 4px in clears the round end of a 44px capsule). The content of a revealed row is a capsule
|
|
322
|
+
of the row's color on the background of the list (SwipeActions.module.css: on a phone the canvas of the Page and
|
|
323
|
+
the fill of a FieldGroup, on a desktop the secondary surface under the surface). */
|
|
324
|
+
--swipe-actions-gap: 10px;
|
|
325
|
+
--swipe-actions-edge-inset: 16px;
|
|
326
|
+
--swipe-actions-content-gap: 10px;
|
|
327
|
+
--swipe-actions-content-radius: 9999px;
|
|
328
|
+
--swipe-actions-action-height: 44px;
|
|
329
|
+
--swipe-actions-action-min-width: 60px;
|
|
330
|
+
--swipe-actions-action-padding-inline: 8px;
|
|
331
|
+
--swipe-actions-icon-size: 20px;
|
|
332
|
+
--swipe-actions-labeled-min-width: 84px;
|
|
333
|
+
--swipe-actions-labeled-padding-inline: 4px;
|
|
334
|
+
--swipe-actions-labeled-icon-size: 18px;
|
|
335
|
+
--swipe-actions-label-gap: 8px;
|
|
336
|
+
--swipe-actions-label-font-size: 13px;
|
|
337
|
+
--swipe-actions-label-line-height: 15px;
|
|
338
|
+
--swipe-actions-label-font-weight: var(--font-weight-normal);
|
|
339
|
+
--swipe-actions-tall-action-height: 38px;
|
|
340
|
+
--swipe-actions-tall-padding-top: 6px;
|
|
341
|
+
--swipe-actions-tall-padding-bottom: 4px;
|
|
342
|
+
--swipe-actions-caption-gap: 5px;
|
|
343
|
+
--swipe-actions-caption-font-weight: var(--font-weight-medium);
|
|
344
|
+
--swipe-actions-duration: 250ms;
|
|
345
|
+
|
|
299
346
|
/* =============================================
|
|
300
347
|
FloatingLabelInput
|
|
301
348
|
============================================= */
|
|
@@ -439,11 +486,20 @@
|
|
|
439
486
|
--toolbar-sheet-padding-top: 16px;
|
|
440
487
|
--toolbar-bottom-padding-top: 4px;
|
|
441
488
|
--toolbar-bottom-fill-padding-top: 12px;
|
|
442
|
-
|
|
489
|
+
/* Native iOS 26 bottom bars (Mail, Contacts, Notes at 430 x 932, IMG_5551, 5737, 5736) stand their 48pt items
|
|
490
|
+
28 above the screen's edge, the 34 home indicator inset less 6. Without an inset (a browser page without
|
|
491
|
+
viewport-fit=cover) they keep 16 to the window's edge. */
|
|
492
|
+
--toolbar-bottom-padding-bottom: max(16px, calc(var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)) - 6px));
|
|
443
493
|
--toolbar-search-padding-bottom: 14px;
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
494
|
+
/* The search field of those bars: the magnifier draws 16.33 of ink with a stroke of 2, 14.0 from the field's
|
|
495
|
+
edge, and "Search" starts at 41.67, set in Regular in the secondary label color (rgb 148 to 150 on the
|
|
496
|
+
glass). SearchSm in a 23.75px box draws that ink: 3.46 of the box lies before it, so the gutter is 10.54. The
|
|
497
|
+
S of "Search" inks 0.95 after its origin in SF Pro 17, so the gap to the text is 6.43 (overlaid on IMG_5737:
|
|
498
|
+
the ink starts at 41.67 and sits on the native baseline within 0.33). */
|
|
499
|
+
--toolbar-search-gutter: 10.54px;
|
|
500
|
+
--toolbar-search-icon-gap: 6.43px;
|
|
501
|
+
--toolbar-search-icon-size: 23.75px;
|
|
502
|
+
--toolbar-search-font-weight: 400;
|
|
447
503
|
--toolbar-flat-opacity: 80%;
|
|
448
504
|
--toolbar-flat-blur: 60px;
|
|
449
505
|
/* The large title starts 21pt under the row of controls in iOS 26 Mail and Freeform (iOS2 IMG_5530, 5531,
|
|
@@ -454,6 +510,9 @@
|
|
|
454
510
|
22 × 20), and native Freeform draws its ellipsis 19.7pt wide with 4pt dots (IMG_5684). A PlexUI icon
|
|
455
511
|
of 26px draws the same: DotsHorizontal 19.5 wide with 4.3px dots (owner 08.11; 24px was small). */
|
|
456
512
|
--toolbar-icon-size: 26px;
|
|
513
|
+
/* A symbol with less ink, as the plus of a Contacts bar: 17.67 of ink with a stroke of 2 (IMG_5737), which
|
|
514
|
+
PlusLg draws in a 23.56px box. A bar button with iconSize="sm" takes it. */
|
|
515
|
+
--toolbar-icon-size-sm: 23.56px;
|
|
457
516
|
--toolbar-label-font-size: 17px;
|
|
458
517
|
--toolbar-label-line-height: 22px;
|
|
459
518
|
--toolbar-label-font-weight: 510;
|
|
@@ -528,6 +587,43 @@
|
|
|
528
587
|
============================================= */
|
|
529
588
|
--popover-radius: var(--radius-xl);
|
|
530
589
|
|
|
590
|
+
/* =============================================
|
|
591
|
+
Tip
|
|
592
|
+
============================================= */
|
|
593
|
+
/* A tip as the TipKit kit draws it (TipKit Community, macOS Mini Tip 118:5175 and iOS Mini Tip 41:1351, the
|
|
594
|
+
same layout on both): 300 wide as a popover, 22 above, 16 at the sides and below (22 below when no action
|
|
595
|
+
shows), the title 17/22 semibold over the description 15/20 4 below it, 22 to the actions, the actions
|
|
596
|
+
side by side 12 apart. Close is a 30 circle 19 from the top and the trailing edge, its glyph about 11pt
|
|
597
|
+
drawn (a 20px X draws 11). A symbol is 34pt in a 44 by 54 frame 6 in from the padding and 12 from the
|
|
598
|
+
text, in the description's color (a 40px icon draws about 34). The arrow of a popover and an annotation is the kit's 47 by 13 curve.
|
|
599
|
+
macOS rounds the tip 20 (iOS: 26, see the phone rules in Tip.module.css). An inline tip on macOS is
|
|
600
|
+
black at 5% (alpha-05); a popover tip takes the PlexUI popover surface, and the kit's iOS popover shadow
|
|
601
|
+
(0 10 30, black at 20%) drawn around the arrow too. */
|
|
602
|
+
--tip-popover-width: 300px;
|
|
603
|
+
--tip-radius: 20px;
|
|
604
|
+
--tip-padding-top: 22px;
|
|
605
|
+
--tip-padding-inline: 16px;
|
|
606
|
+
--tip-padding-bottom: 16px;
|
|
607
|
+
--tip-gap: 22px;
|
|
608
|
+
--tip-title-font-size: 17px;
|
|
609
|
+
--tip-title-line-height: 22px;
|
|
610
|
+
--tip-description-font-size: 15px;
|
|
611
|
+
--tip-description-line-height: 20px;
|
|
612
|
+
--tip-description-gap: 4px;
|
|
613
|
+
--tip-description-color: var(--color-text-secondary);
|
|
614
|
+
--tip-action-gap: 12px;
|
|
615
|
+
--tip-icon-size: 40px;
|
|
616
|
+
--tip-icon-frame-width: 44px;
|
|
617
|
+
--tip-icon-frame-height: 54px;
|
|
618
|
+
--tip-close-size: 30px;
|
|
619
|
+
--tip-close-offset: 19px;
|
|
620
|
+
--tip-close-icon-size: 20px;
|
|
621
|
+
--tip-arrow-width: 47px;
|
|
622
|
+
--tip-arrow-height: 13px;
|
|
623
|
+
--tip-background: var(--alpha-05);
|
|
624
|
+
--tip-popover-background: var(--color-surface-elevated);
|
|
625
|
+
--tip-popover-shadow: 0 10px 30px rgb(0 0 0 / 20%);
|
|
626
|
+
|
|
531
627
|
/* =============================================
|
|
532
628
|
RadioGroup
|
|
533
629
|
============================================= */
|
|
@@ -637,6 +733,24 @@
|
|
|
637
733
|
--context-menu-preview-radius: 30px;
|
|
638
734
|
--context-menu-preview-shadow: 0 0 32px rgb(0 0 0 / 20%);
|
|
639
735
|
|
|
736
|
+
/* =============================================
|
|
737
|
+
Index bar (phone)
|
|
738
|
+
============================================= */
|
|
739
|
+
/* The section index of a phone list, after native iOS Contacts (IMG_5737; 09.11) and the iOS 27 kit (Lists,
|
|
740
|
+
Index Bar 48:56457), which agree: letters of about 11pt (a cap height of 7.7-8pt) 14pt apart (13.8 native),
|
|
741
|
+
in a 16pt column at the trailing edge, centred 8pt from it (7.7 native), in the medium weight of the kit.
|
|
742
|
+
The country list of a sheet (IMG_5491: 15pt apart, 10pt from the edge) is the exception. The kit tints them
|
|
743
|
+
systemBlue; PlexUI draws that tint as info, as it does the prominent toolbar button. The target reaches 30px
|
|
744
|
+
in from the edge (agent: the kit and native frames show no target). A list keeps its margins beside the
|
|
745
|
+
index, whose letters sit in the trailing one (Contacts rows end 16pt from the edge). */
|
|
746
|
+
--index-bar-width: 16px;
|
|
747
|
+
--index-bar-inset-inline-end: 0px;
|
|
748
|
+
--index-bar-font-size: 11px;
|
|
749
|
+
--index-bar-line-height: 14px;
|
|
750
|
+
--index-bar-font-weight: var(--font-weight-medium);
|
|
751
|
+
--index-bar-color: var(--color-text-info);
|
|
752
|
+
--index-bar-target-width: 30px;
|
|
753
|
+
|
|
640
754
|
/* =============================================
|
|
641
755
|
Page control
|
|
642
756
|
============================================= */
|
|
@@ -687,7 +801,11 @@
|
|
|
687
801
|
--tab-bar-gap: 8px;
|
|
688
802
|
--tab-bar-padding-top: 12px;
|
|
689
803
|
--tab-bar-padding-bottom: max(21px, calc(var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)) - 13px));
|
|
690
|
-
|
|
804
|
+
/* Minimized, the circles keep 28px from the sides and the bottom (kit iOS 27, Tab Bar - iPhone 3:70967,
|
|
805
|
+
Minimized=True; 21 in the iOS 26 kit), and the bar keeps its 95px so the Page under it does not move. */
|
|
806
|
+
--tab-bar-minimized-padding-top: 19px;
|
|
807
|
+
--tab-bar-minimized-gutter: 28px;
|
|
808
|
+
--tab-bar-minimized-padding-bottom: max(28px, calc(var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)) - 6px));
|
|
691
809
|
--tab-bar-capsule-padding-block: 4px;
|
|
692
810
|
--tab-bar-capsule-padding-inline: 10px;
|
|
693
811
|
--tab-bar-item-width: 94px;
|
|
@@ -951,6 +1069,7 @@
|
|
|
951
1069
|
--dialog-mobile-scrim: rgb(0 0 0 / 20%);
|
|
952
1070
|
--menu-item-background-color: var(--alpha-08);
|
|
953
1071
|
--modal-backdrop-background: rgb(0 0 0 / 30%);
|
|
1072
|
+
--toolbar-search-placeholder-color: var(--alpha-40);
|
|
954
1073
|
--toolbar-prominent-disabled-background: var(--alpha-12);
|
|
955
1074
|
--toolbar-prominent-disabled-color: var(--gray-0);
|
|
956
1075
|
--toolbar-prominent-shadow: 0 8px 15px rgb(0 0 0 / 2%), 1.25px 0 0 -0.75px rgb(0 0 0 / 12%), -1.25px 0 0 -0.75px rgb(0 0 0 / 12%), inset 0 0.67px 0 rgb(255 255 255 / 35%), inset 0 -0.67px 0 rgb(255 255 255 / 35%);
|
|
@@ -1006,6 +1125,7 @@
|
|
|
1006
1125
|
--dialog-mobile-scrim: rgb(0 0 0 / 50%);
|
|
1007
1126
|
--menu-item-background-color: var(--alpha-10);
|
|
1008
1127
|
--modal-backdrop-background: rgb(0 0 0 / 50%);
|
|
1128
|
+
--toolbar-search-placeholder-color: var(--alpha-60);
|
|
1009
1129
|
--toolbar-prominent-disabled-background: var(--alpha-20);
|
|
1010
1130
|
--toolbar-prominent-disabled-color: var(--alpha-30);
|
|
1011
1131
|
--toolbar-prominent-shadow: 0 8px 15px transparent, 1.25px 0 0 -0.75px rgb(0 0 0 / 12%), -1.25px 0 0 -0.75px rgb(0 0 0 / 12%), inset 0 0.67px 0 rgb(255 255 255 / 35%), inset 0 -0.67px 0 rgb(255 255 255 / 35%);
|
package/package.json
CHANGED
|
@@ -2,6 +2,24 @@ import postcss from "postcss"
|
|
|
2
2
|
import selectorParser from "postcss-selector-parser"
|
|
3
3
|
import valueParser from "postcss-value-parser"
|
|
4
4
|
|
|
5
|
+
// A selector that starts on the root element itself (`html:root`, or `:root` before the phone layout scope)
|
|
6
|
+
const ROOT_COMPOUND = /^(?::root|html)(?:\[[^\]]*\]|:[\w-]+(?:\([^)]*\))?|\.[\w-]+)*(?=$|[\s>+~])/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The selectors for one theme of a rule that is not a bare theme scope. The theme attribute sits on an ancestor, or,
|
|
10
|
+
* for a selector that starts on the root element, on the root itself (no element is above it) or inside it; the root
|
|
11
|
+
* keeps its specificity so the dark rule, emitted after the light one, wins.
|
|
12
|
+
* @param {string} selector
|
|
13
|
+
* @param {"light" | "dark"} theme
|
|
14
|
+
*/
|
|
15
|
+
export const themedSelectors = (selector, theme) => {
|
|
16
|
+
const scope = `:where([data-theme="${theme}"])`
|
|
17
|
+
const root = ROOT_COMPOUND.exec(selector)
|
|
18
|
+
if (!root) return [`${scope} ${selector}`]
|
|
19
|
+
const rest = selector.slice(root[0].length).trim()
|
|
20
|
+
return rest ? [`${root[0]}${scope} ${rest}`, `${root[0]} ${scope} ${rest}`] : [`${root[0]}${scope}`]
|
|
21
|
+
}
|
|
22
|
+
|
|
5
23
|
/** @type {import('postcss').PluginCreator} */
|
|
6
24
|
export default function platformUILightDark() {
|
|
7
25
|
return {
|
|
@@ -152,8 +170,8 @@ export default function platformUILightDark() {
|
|
|
152
170
|
}
|
|
153
171
|
|
|
154
172
|
// Themed nested only for non-simple selectors
|
|
155
|
-
lightParts.push(...otherSelectors.
|
|
156
|
-
darkParts.push(...otherSelectors.
|
|
173
|
+
lightParts.push(...otherSelectors.flatMap((s) => themedSelectors(s, "light")))
|
|
174
|
+
darkParts.push(...otherSelectors.flatMap((s) => themedSelectors(s, "dark")))
|
|
157
175
|
|
|
158
176
|
// Dedupe while preserving order
|
|
159
177
|
const uniq = (arr) => Array.from(new Set(arr))
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A phone layout without a narrow window (plan 176). The rules of the phone media queries (767px and below) also
|
|
5
|
+
* apply inside an element marked `data-plex-layout="phone"` (PhoneLayout, or a dialog laid out as on a phone), and
|
|
6
|
+
* the rules of the desktop queries (768px and up) do not apply there.
|
|
7
|
+
*
|
|
8
|
+
* Runs after postcss-nested, on flat rules. A copy keeps the specificity of its rule (the scope sits in `:where()`),
|
|
9
|
+
* and follows its media rule, so the cascade inside the scope is the one a narrow window has.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export const PHONE_SCOPE = '[data-plex-layout="phone"]'
|
|
13
|
+
|
|
14
|
+
const PHONE_FEATURE = /^\(\s*(?:max-width\s*:\s*767(?:\.98)?px|width\s*<=?\s*767(?:\.98)?px)\s*\)$/i
|
|
15
|
+
const DESKTOP_FEATURE = /^\(\s*(?:min-width\s*:\s*768px|width\s*>=\s*768px)\s*\)$/i
|
|
16
|
+
const MEDIA_TYPE = /^(?:only\s+)?(?:screen|all)$/i
|
|
17
|
+
const ROOT_COMPOUND = /^(?::root|html|body)(?=$|[\s>+~.[:#])((?:\[[^\]]*\]|:[\w-]+(?:\([^)]*\))?|\.[\w-]+)*)/
|
|
18
|
+
|
|
19
|
+
/** Splits on commas outside parentheses and brackets. */
|
|
20
|
+
const splitList = (value) => {
|
|
21
|
+
const parts = []
|
|
22
|
+
let depth = 0
|
|
23
|
+
let start = 0
|
|
24
|
+
for (let index = 0; index < value.length; index++) {
|
|
25
|
+
const char = value[index]
|
|
26
|
+
if (char === "(" || char === "[") depth++
|
|
27
|
+
else if (char === ")" || char === "]") depth--
|
|
28
|
+
else if (char === "," && depth === 0) {
|
|
29
|
+
parts.push(value.slice(start, index).trim())
|
|
30
|
+
start = index + 1
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
parts.push(value.slice(start).trim())
|
|
34
|
+
return parts.filter(Boolean)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* What the copy of a media rule keeps of its queries once the phone condition is taken out: `true` for none (the
|
|
39
|
+
* copy applies whenever the scope does), the remaining conditions, or `null` when no query is a phone one.
|
|
40
|
+
* @param {string} params
|
|
41
|
+
* @returns {true | string | null}
|
|
42
|
+
*/
|
|
43
|
+
export const phoneCondition = (params) => {
|
|
44
|
+
const kept = []
|
|
45
|
+
for (const query of splitList(params)) {
|
|
46
|
+
const features = query.split(/\s+and\s+/i).map((part) => part.trim())
|
|
47
|
+
if (!features.some((feature) => PHONE_FEATURE.test(feature))) continue
|
|
48
|
+
const rest = features.filter((feature) => !PHONE_FEATURE.test(feature) && !MEDIA_TYPE.test(feature))
|
|
49
|
+
if (rest.some((feature) => /width/i.test(feature))) continue // another width range: not known inside a frame
|
|
50
|
+
if (!rest.length) return true
|
|
51
|
+
kept.push(rest.join(" and "))
|
|
52
|
+
}
|
|
53
|
+
return kept.length ? kept.join(", ") : null
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** @param {string} params */
|
|
57
|
+
export const isDesktopMedia = (params) =>
|
|
58
|
+
splitList(params).every((query) => query.split(/\s+and\s+/i).some((feature) => DESKTOP_FEATURE.test(feature.trim())))
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* The selector for elements inside the scope: after a leading `:root`, `html` or `body` (and what it carries), so
|
|
62
|
+
* tokens set on the root are set on the scope instead, or before the selector.
|
|
63
|
+
* @param {string} selector
|
|
64
|
+
*/
|
|
65
|
+
export const scopeSelector = (selector) => {
|
|
66
|
+
const root = ROOT_COMPOUND.exec(selector)
|
|
67
|
+
if (root) {
|
|
68
|
+
const rest = selector.slice(root[0].length).trim()
|
|
69
|
+
return `${root[0]} :where(${PHONE_SCOPE})${rest ? ` ${rest}` : ""}`
|
|
70
|
+
}
|
|
71
|
+
return `:where(${PHONE_SCOPE}) ${selector}`
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* The selector for elements outside the scope: its subject (before any pseudo-element) is not the scope or in it.
|
|
76
|
+
* @param {string} selector
|
|
77
|
+
*/
|
|
78
|
+
export const unscopeSelector = (selector) => {
|
|
79
|
+
const exclusion = `:not(:where(${PHONE_SCOPE}, ${PHONE_SCOPE} *))`
|
|
80
|
+
const pseudo = selector.search(/::[\w-]+(?:\([^)]*\))?$/)
|
|
81
|
+
return pseudo === -1 ? `${selector}${exclusion}` : `${selector.slice(0, pseudo)}${exclusion}${selector.slice(pseudo)}`
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const inKeyframes = (rule) => {
|
|
85
|
+
for (let node = rule.parent; node; node = node.parent) {
|
|
86
|
+
if (node.type === "atrule" && /keyframes$/i.test(node.name)) return true
|
|
87
|
+
}
|
|
88
|
+
return false
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** @type {import('postcss').PluginCreator<void>} */
|
|
92
|
+
export default function phoneLayoutScope() {
|
|
93
|
+
return {
|
|
94
|
+
postcssPlugin: "plexui/components/postcss-phone-layout-scope",
|
|
95
|
+
OnceExit(root, { AtRule }) {
|
|
96
|
+
/** @type {import('postcss').AtRule[]} */
|
|
97
|
+
const media = []
|
|
98
|
+
root.walkAtRules("media", (rule) => {
|
|
99
|
+
media.push(rule)
|
|
100
|
+
})
|
|
101
|
+
for (const rule of media) {
|
|
102
|
+
// A phone rule inside another phone rule is copied with its outer one
|
|
103
|
+
let outer = rule.parent
|
|
104
|
+
let nested = false
|
|
105
|
+
for (; outer; outer = outer.parent) {
|
|
106
|
+
if (outer.type === "atrule" && outer.name === "media" && phoneCondition(outer.params) !== null) nested = true
|
|
107
|
+
}
|
|
108
|
+
const condition = phoneCondition(rule.params)
|
|
109
|
+
if (condition !== null && !nested) {
|
|
110
|
+
const copy = rule.clone()
|
|
111
|
+
copy.walkRules((inner) => {
|
|
112
|
+
if (inKeyframes(inner)) return
|
|
113
|
+
inner.selectors = inner.selectors.map(scopeSelector)
|
|
114
|
+
})
|
|
115
|
+
// A media rule nested in the phone one is copied whole; its own phone condition, if any, is the scope's
|
|
116
|
+
copy.walkAtRules("media", (inner) => {
|
|
117
|
+
const innerCondition = phoneCondition(inner.params)
|
|
118
|
+
if (innerCondition === true) inner.replaceWith(inner.nodes ?? [])
|
|
119
|
+
else if (innerCondition !== null) inner.params = innerCondition
|
|
120
|
+
})
|
|
121
|
+
if (condition === true) rule.after(copy.nodes ?? [])
|
|
122
|
+
else rule.after(new AtRule({ name: "media", params: condition, nodes: copy.nodes ?? [] }))
|
|
123
|
+
} else if (isDesktopMedia(rule.params)) {
|
|
124
|
+
rule.walkRules((inner) => {
|
|
125
|
+
if (inKeyframes(inner)) return
|
|
126
|
+
inner.selectors = inner.selectors.map(unscopeSelector)
|
|
127
|
+
})
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
phoneLayoutScope.postcss = true
|
package/postcss.config.mjs
CHANGED
|
@@ -6,6 +6,7 @@ import platformUIFunctions from "./postcss/functions.mjs"
|
|
|
6
6
|
import injectBreakpoints from "./postcss/injectBreakpoints.mjs"
|
|
7
7
|
import platformUIMixins from "./postcss/mixins.mjs"
|
|
8
8
|
import platformUILightDark from "./postcss/parseLightDark.mjs"
|
|
9
|
+
import phoneLayoutScope from "./postcss/phoneLayoutScope.mjs"
|
|
9
10
|
import wrapModulesInLayer from "./postcss/wrapModulesInLayer.mjs"
|
|
10
11
|
|
|
11
12
|
/**
|
|
@@ -40,6 +41,8 @@ export function platformUIRequiredPlugins(config = {}) {
|
|
|
40
41
|
platformUIFunctions(),
|
|
41
42
|
platformUIMixins({ breakpoints }),
|
|
42
43
|
postcssNested(),
|
|
44
|
+
// Phone rules inside a PhoneLayout too, whatever the window's width (needs the flat rules postcss-nested leaves)
|
|
45
|
+
phoneLayoutScope(),
|
|
43
46
|
// When browser support becomes adequate to use light-dark() directly, remove this plugin.
|
|
44
47
|
platformUILightDark(),
|
|
45
48
|
autoprefixer(),
|