@plexui/styles 0.1.34 → 0.1.36

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.
Files changed (50) hide show
  1. package/dist/es/components/Accordion/Accordion.module.css +12 -1
  2. package/dist/es/components/Alert/Alert.module.css +101 -0
  3. package/dist/es/components/Badge/Badge.module.css +37 -0
  4. package/dist/es/components/Breadcrumb/Breadcrumb.module.css +29 -0
  5. package/dist/es/components/Button/Button.module.css +53 -0
  6. package/dist/es/components/Button/NavigationButton.module.css +17 -0
  7. package/dist/es/components/ButtonGroup/ButtonGroup.module.css +227 -20
  8. package/dist/es/components/Card/Card.module.css +9 -0
  9. package/dist/es/components/CodeBlock/CodeBlock.module.css +14 -1
  10. package/dist/es/components/ColorPicker/ColorPicker.module.css +19 -1
  11. package/dist/es/components/DatePicker/Calendar.module.css +262 -2
  12. package/dist/es/components/DatePicker/CalendarNavigationIcon.module.css +10 -0
  13. package/dist/es/components/DateRangePicker/Calendar.module.css +207 -3
  14. package/dist/es/components/DateRangePicker/Trigger.module.css +17 -2
  15. package/dist/es/components/Dialog/Dialog.module.css +660 -13
  16. package/dist/es/components/EmptyMessage/EmptyMessage.module.css +21 -0
  17. package/dist/es/components/Field/Field.module.css +387 -2
  18. package/dist/es/components/FieldGroup/FieldGroup.module.css +129 -3
  19. package/dist/es/components/FileUpload/FileUpload.module.css +74 -1
  20. package/dist/es/components/FloatingLabelInput/FloatingLabelInput.module.css +19 -1
  21. package/dist/es/components/FloatingLabelSelect/FloatingLabelSelect.module.css +12 -1
  22. package/dist/es/components/IndexBar/IndexBar.module.css +146 -0
  23. package/dist/es/components/Input/Input.module.css +129 -1
  24. package/dist/es/components/MarkdownEditor/MarkdownEditor.module.css +18 -0
  25. package/dist/es/components/Menu/Menu.module.css +324 -7
  26. package/dist/es/components/OTPInput/OTPInput.module.css +6 -1
  27. package/dist/es/components/Page/Page.module.css +302 -10
  28. package/dist/es/components/PhoneLayout/PhoneLayout.module.css +10 -0
  29. package/dist/es/components/Popover/Popover.module.css +7 -0
  30. package/dist/es/components/Select/Select.module.css +148 -0
  31. package/dist/es/components/SelectControl/SelectControl.module.css +113 -1
  32. package/dist/es/components/Sidebar/Sidebar.module.css +354 -20
  33. package/dist/es/components/Slider/Slider.module.css +80 -0
  34. package/dist/es/components/SwipeActions/SwipeActions.module.css +166 -0
  35. package/dist/es/components/Switch/Switch.module.css +59 -4
  36. package/dist/es/components/TabBar/TabBar.module.css +255 -10
  37. package/dist/es/components/Tabs/Tabs.module.css +166 -1
  38. package/dist/es/components/TagInput/TagInput.module.css +50 -9
  39. package/dist/es/components/Textarea/Textarea.module.css +6 -0
  40. package/dist/es/components/Tip/Tip.module.css +456 -0
  41. package/dist/es/components/Toast/Toast.module.css +148 -5
  42. package/dist/es/components/Toolbar/Toolbar.module.css +642 -3
  43. package/dist/es/styles/mobile-materials.css +103 -8
  44. package/dist/es/styles/mobile-surfaces.css +43 -0
  45. package/dist/es/styles/touch.css +619 -9
  46. package/dist/es/styles/variables-components.css +125 -5
  47. package/package.json +1 -1
  48. package/postcss/parseLightDark.mjs +20 -2
  49. package/postcss/phoneLayoutScope.mjs +139 -0
  50. 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
- --toolbar-bottom-padding-bottom: max(16px, calc(var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)) - 2px));
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
- --toolbar-search-gutter: 11px;
445
- --toolbar-search-icon-gap: 4px;
446
- --toolbar-search-icon-size: 26px;
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
- --tab-bar-minimized-padding-top: 26px;
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plexui/styles",
3
- "version": "0.1.34",
3
+ "version": "0.1.36",
4
4
  "description": "Framework-agnostic CSS for Plex UI: design tokens, globals and component styles",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -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.map((s) => `:where([data-theme="light"]) ${s}`))
156
- darkParts.push(...otherSelectors.map((s) => `:where([data-theme="dark"]) ${s}`))
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,139 @@
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
+ // The theme of the light and dark mixins (mixins.mjs), set on the root or on a part of the page
19
+ const THEME_COMPOUND = /^:where\(\[data-theme=(?:"(?:light|dark)"|'(?:light|dark)'|light|dark)\]\)(?=\s)/
20
+
21
+ /** Splits on commas outside parentheses and brackets. */
22
+ const splitList = (value) => {
23
+ const parts = []
24
+ let depth = 0
25
+ let start = 0
26
+ for (let index = 0; index < value.length; index++) {
27
+ const char = value[index]
28
+ if (char === "(" || char === "[") depth++
29
+ else if (char === ")" || char === "]") depth--
30
+ else if (char === "," && depth === 0) {
31
+ parts.push(value.slice(start, index).trim())
32
+ start = index + 1
33
+ }
34
+ }
35
+ parts.push(value.slice(start).trim())
36
+ return parts.filter(Boolean)
37
+ }
38
+
39
+ /**
40
+ * What the copy of a media rule keeps of its queries once the phone condition is taken out: `true` for none (the
41
+ * copy applies whenever the scope does), the remaining conditions, or `null` when no query is a phone one.
42
+ * @param {string} params
43
+ * @returns {true | string | null}
44
+ */
45
+ export const phoneCondition = (params) => {
46
+ const kept = []
47
+ for (const query of splitList(params)) {
48
+ const features = query.split(/\s+and\s+/i).map((part) => part.trim())
49
+ if (!features.some((feature) => PHONE_FEATURE.test(feature))) continue
50
+ const rest = features.filter((feature) => !PHONE_FEATURE.test(feature) && !MEDIA_TYPE.test(feature))
51
+ if (rest.some((feature) => /width/i.test(feature))) continue // another width range: not known inside a frame
52
+ if (!rest.length) return true
53
+ kept.push(rest.join(" and "))
54
+ }
55
+ return kept.length ? kept.join(", ") : null
56
+ }
57
+
58
+ /** @param {string} params */
59
+ export const isDesktopMedia = (params) =>
60
+ splitList(params).every((query) => query.split(/\s+and\s+/i).some((feature) => DESKTOP_FEATURE.test(feature.trim())))
61
+
62
+ /**
63
+ * The selector for elements inside the scope: after a leading `:root`, `html` or `body` (and what it carries), so
64
+ * tokens set on the root are set on the scope instead, or before the selector. A rule of one theme (the dark and
65
+ * light mixins) applies in the scope whether the theme is set outside it, as on the root, or inside it.
66
+ * @param {string} selector
67
+ */
68
+ export const scopeSelector = (selector) => {
69
+ const root = ROOT_COMPOUND.exec(selector)
70
+ if (root) {
71
+ const rest = selector.slice(root[0].length).trim()
72
+ return `${root[0]} :where(${PHONE_SCOPE})${rest ? ` ${rest}` : ""}`
73
+ }
74
+ const theme = THEME_COMPOUND.exec(selector)
75
+ if (theme) return `${theme[0]} :where(${PHONE_SCOPE}) ${selector.slice(theme[0].length).trim()}, :where(${PHONE_SCOPE}) ${selector}`
76
+ return `:where(${PHONE_SCOPE}) ${selector}`
77
+ }
78
+
79
+ /**
80
+ * The selector for elements outside the scope: its subject (before any pseudo-element) is not the scope or in it.
81
+ * @param {string} selector
82
+ */
83
+ export const unscopeSelector = (selector) => {
84
+ const exclusion = `:not(:where(${PHONE_SCOPE}, ${PHONE_SCOPE} *))`
85
+ const pseudo = selector.search(/::[\w-]+(?:\([^)]*\))?$/)
86
+ return pseudo === -1 ? `${selector}${exclusion}` : `${selector.slice(0, pseudo)}${exclusion}${selector.slice(pseudo)}`
87
+ }
88
+
89
+ const inKeyframes = (rule) => {
90
+ for (let node = rule.parent; node; node = node.parent) {
91
+ if (node.type === "atrule" && /keyframes$/i.test(node.name)) return true
92
+ }
93
+ return false
94
+ }
95
+
96
+ /** @type {import('postcss').PluginCreator<void>} */
97
+ export default function phoneLayoutScope() {
98
+ return {
99
+ postcssPlugin: "plexui/components/postcss-phone-layout-scope",
100
+ OnceExit(root, { AtRule }) {
101
+ /** @type {import('postcss').AtRule[]} */
102
+ const media = []
103
+ root.walkAtRules("media", (rule) => {
104
+ media.push(rule)
105
+ })
106
+ for (const rule of media) {
107
+ // A phone rule inside another phone rule is copied with its outer one
108
+ let outer = rule.parent
109
+ let nested = false
110
+ for (; outer; outer = outer.parent) {
111
+ if (outer.type === "atrule" && outer.name === "media" && phoneCondition(outer.params) !== null) nested = true
112
+ }
113
+ const condition = phoneCondition(rule.params)
114
+ if (condition !== null && !nested) {
115
+ const copy = rule.clone()
116
+ copy.walkRules((inner) => {
117
+ if (inKeyframes(inner)) return
118
+ inner.selectors = inner.selectors.map(scopeSelector)
119
+ })
120
+ // A media rule nested in the phone one is copied whole; its own phone condition, if any, is the scope's
121
+ copy.walkAtRules("media", (inner) => {
122
+ const innerCondition = phoneCondition(inner.params)
123
+ if (innerCondition === true) inner.replaceWith(inner.nodes ?? [])
124
+ else if (innerCondition !== null) inner.params = innerCondition
125
+ })
126
+ if (condition === true) rule.after(copy.nodes ?? [])
127
+ else rule.after(new AtRule({ name: "media", params: condition, nodes: copy.nodes ?? [] }))
128
+ } else if (isDesktopMedia(rule.params)) {
129
+ rule.walkRules((inner) => {
130
+ if (inKeyframes(inner)) return
131
+ inner.selectors = inner.selectors.map(unscopeSelector)
132
+ })
133
+ }
134
+ }
135
+ },
136
+ }
137
+ }
138
+
139
+ phoneLayoutScope.postcss = true
@@ -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(),