@lostgradient/cinder 0.26.0 → 0.26.2

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 (110) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/components.json +1 -1
  3. package/dist/_internal/chart/chart-utilities.d.ts +1 -1
  4. package/dist/components/alert-dialog/index.js +2 -2
  5. package/dist/components/area-chart/area-chart.css +23 -0
  6. package/dist/components/autocomplete/index.js +2 -2
  7. package/dist/components/bar-chart/bar-chart.css +23 -0
  8. package/dist/components/carousel/index.js +2 -2
  9. package/dist/components/combobox/index.js +2 -2
  10. package/dist/components/command-menu/index.js +2 -2
  11. package/dist/components/command-palette/index.js +2 -2
  12. package/dist/components/confirm-dialog/index.js +2 -2
  13. package/dist/components/context-menu/index.js +2 -2
  14. package/dist/components/date-picker/index.js +2 -2
  15. package/dist/components/date-range-field/index.js +2 -2
  16. package/dist/components/drawer/index.js +2 -2
  17. package/dist/components/dropdown/index.js +2 -2
  18. package/dist/components/dropdown-menu/index.js +2 -2
  19. package/dist/components/focus-trap/index.js +2 -2
  20. package/dist/components/guidance-region/index.css +1 -1
  21. package/dist/components/invocation-rule-builder/index.js +2 -2
  22. package/dist/components/line-chart/line-chart.css +23 -0
  23. package/dist/components/mega-menu/index.js +2 -2
  24. package/dist/components/mega-menu/mega-menu.css +7 -1
  25. package/dist/components/menu-bar/index.js +2 -2
  26. package/dist/components/modal/index.js +2 -2
  27. package/dist/components/navigation-bar/index.js +2 -2
  28. package/dist/components/parameter-field/parameter-field.css +7 -1
  29. package/dist/components/popover/index.js +2 -2
  30. package/dist/components/popover/popover.css +86 -0
  31. package/dist/components/resizable-panels/resizable-panels.css +10 -7
  32. package/dist/components/select/select.css +12 -2
  33. package/dist/components/sidebar/index.js +2 -2
  34. package/dist/components/slider/index.js +2 -2
  35. package/dist/components/slider/slider.css +7 -1
  36. package/dist/components/sortable-list/sortable-list.css +11 -7
  37. package/dist/components/speed-dial/index.js +2 -2
  38. package/dist/components/terminal-output/index.js +2 -2
  39. package/dist/components/terminal-output/terminal-output-parser.d.ts +1 -0
  40. package/dist/index.browser.css +1 -1
  41. package/dist/index.js +4 -4
  42. package/dist/server/components/alert-dialog/index.js +1 -1
  43. package/dist/server/components/autocomplete/index.js +1 -1
  44. package/dist/server/components/carousel/index.js +1 -1
  45. package/dist/server/components/combobox/index.js +1 -1
  46. package/dist/server/components/command-menu/index.js +1 -1
  47. package/dist/server/components/command-palette/index.js +1 -1
  48. package/dist/server/components/confirm-dialog/index.js +1 -1
  49. package/dist/server/components/context-menu/index.js +1 -1
  50. package/dist/server/components/date-picker/index.js +1 -1
  51. package/dist/server/components/date-range-field/index.js +1 -1
  52. package/dist/server/components/drawer/index.js +1 -1
  53. package/dist/server/components/dropdown/index.js +1 -1
  54. package/dist/server/components/dropdown-menu/index.js +1 -1
  55. package/dist/server/components/focus-trap/index.js +1 -1
  56. package/dist/server/components/invocation-rule-builder/index.js +1 -1
  57. package/dist/server/components/mega-menu/index.js +1 -1
  58. package/dist/server/components/menu-bar/index.js +1 -1
  59. package/dist/server/components/modal/index.js +1 -1
  60. package/dist/server/components/navigation-bar/index.js +1 -1
  61. package/dist/server/components/popover/index.js +1 -1
  62. package/dist/server/components/sidebar/index.js +1 -1
  63. package/dist/server/components/slider/index.js +1 -1
  64. package/dist/server/components/speed-dial/index.js +1 -1
  65. package/dist/server/components/terminal-output/index.js +1 -1
  66. package/dist/server/index.js +1 -1
  67. package/dist/server/{index.server-8h5caecr.js → index.server-1dxv84rs.js} +1 -1
  68. package/dist/server/{index.server-bfed6a8a.js → index.server-23726hh9.js} +1 -1
  69. package/dist/server/{index.server-c1746s0z.js → index.server-3ywpedsf.js} +1 -1
  70. package/dist/server/{index.server-y6vtbmyj.js → index.server-468y89tb.js} +1 -1
  71. package/dist/server/{index.server-80qgcjnm.js → index.server-4p0y8zrz.js} +1 -1
  72. package/dist/server/{index.server-99penx1m.js → index.server-7h28mv50.js} +1 -1
  73. package/dist/server/{index.server-vq1k69xt.js → index.server-96m4kera.js} +1 -1
  74. package/dist/server/index.server-9gac00vp.js +4 -0
  75. package/dist/server/{index.server-qgne9v2w.js → index.server-aajmj6rm.js} +1 -1
  76. package/dist/server/{index.server-y298khv4.js → index.server-ad66mjqp.js} +1 -1
  77. package/dist/server/{index.server-a2yhk45s.js → index.server-bvjqpbwk.js} +1 -1
  78. package/dist/server/{index.server-x9f5fqhn.js → index.server-dj8zqjdf.js} +2 -2
  79. package/dist/server/{index.server-na22gwzw.js → index.server-gt00wxxy.js} +1 -1
  80. package/dist/server/{index.server-5s94r0kk.js → index.server-k7x83whv.js} +1 -1
  81. package/dist/server/{index.server-zff2qp1v.js → index.server-m10489y5.js} +1 -1
  82. package/dist/server/{index.server-j52rbk57.js → index.server-p7vvv0cj.js} +1 -1
  83. package/dist/server/{index.server-s9tjs45r.js → index.server-qp53129k.js} +1 -1
  84. package/dist/server/{index.server-3xwvw6w2.js → index.server-setw377k.js} +1 -1
  85. package/dist/server/{index.server-d51wq0ak.js → index.server-sq7vyqnn.js} +1 -1
  86. package/dist/server/{index.server-p423fy4q.js → index.server-tfgwbvy2.js} +1 -1
  87. package/dist/server/{index.server-4gbrpan2.js → index.server-vkhb6g7x.js} +2 -2
  88. package/dist/server/{index.server-tyhta5n3.js → index.server-wd4d7aqx.js} +1 -1
  89. package/dist/server/{index.server-jm89hxfb.js → index.server-yhr56vkb.js} +1 -1
  90. package/dist/utilities/focus.d.ts +3 -1
  91. package/package.json +2 -1
  92. package/src/_internal/chart/chart-utilities.ts +5 -1
  93. package/src/_internal/text-direction-container.ts +21 -11
  94. package/src/_internal/text-direction-css.ts +15 -3
  95. package/src/_internal/text-direction.ts +13 -3
  96. package/src/components/area-chart/area-chart.css +23 -0
  97. package/src/components/bar-chart/bar-chart.css +23 -0
  98. package/src/components/button/button.examples.json +6 -0
  99. package/src/components/hover-card/hover-card.examples.json +11 -4
  100. package/src/components/line-chart/line-chart.css +23 -0
  101. package/src/components/mega-menu/mega-menu.css +7 -1
  102. package/src/components/parameter-field/parameter-field.css +7 -1
  103. package/src/components/popover/popover.css +86 -0
  104. package/src/components/resizable-panels/resizable-panels.css +10 -7
  105. package/src/components/select/select.css +12 -2
  106. package/src/components/slider/slider.css +7 -1
  107. package/src/components/sortable-list/sortable-list.css +11 -7
  108. package/src/components/terminal-output/terminal-output-parser.ts +8 -0
  109. package/src/utilities/focus.ts +21 -8
  110. package/dist/server/index.server-k42t379x.js +0 -4
@@ -36,7 +36,30 @@
36
36
  padding: var(--cinder-space-1) var(--cinder-space-2);
37
37
  }
38
38
 
39
+ /*
40
+ * CIN-603: a toggled-off series is still an ENABLED control (the user
41
+ * presses it to bring the series back), so its `border.control` boundary
42
+ * stays subject to WCAG 1.4.11's 3:1 floor. The previous `opacity: 0.55`
43
+ * lived on the button itself, which multiplied the border's alpha along
44
+ * with everything else (~26% effective, well under the floor). Scoping the
45
+ * dimming to the swatch dot instead leaves the border at `border.control`'s
46
+ * full, undiluted alpha.
47
+ *
48
+ * The label's color sources `--_cinder-chart-muted` (the same chart-local
49
+ * token every other "muted" chart element in this file already uses), not
50
+ * the global `--cinder-text-muted` token -- a consumer-supplied
51
+ * `theme.muted` has to keep reaching this label, or it stops matching the
52
+ * rest of a custom chart theme. Its own default is `currentColor`
53
+ * (`chart-model-utilities`'s `theme?.muted ?? 'currentColor'`), so with no
54
+ * consumer theme the label reads at full, undimmed contrast -- the
55
+ * swatch's own `opacity: 0.55` below is what still marks the series as
56
+ * toggled off.
57
+ */
39
58
  .cinder-line-chart__legend button[aria-pressed='false'] {
59
+ color: var(--_cinder-chart-muted, currentColor);
60
+ }
61
+
62
+ .cinder-line-chart__legend button[aria-pressed='false'] span {
40
63
  opacity: 0.55;
41
64
  }
42
65
 
@@ -44,10 +44,16 @@
44
44
  box-shadow: 0 0 0 var(--cinder-ring-width) var(--cinder-ring-color);
45
45
  }
46
46
 
47
+ /*
48
+ * CIN-603: this track is a persistent state indicator (it shows which item
49
+ * the active-indicator animation is tracking), so it moved from
50
+ * `border.muted` (a 1.4:1 decorative-hairline tier) to `border.control`
51
+ * (the 3:1 functional tier).
52
+ */
47
53
  .cinder-mega-menu__indicator-track {
48
54
  position: relative;
49
55
  height: 2px;
50
- background: var(--cinder-border-muted);
56
+ background: var(--cinder-border);
51
57
  border-radius: var(--cinder-radius-full);
52
58
  overflow: hidden;
53
59
  }
@@ -31,9 +31,15 @@
31
31
  align-items: stretch;
32
32
  }
33
33
 
34
+ /*
35
+ * CIN-603: this rail is a persistent state indicator (it fills the whole
36
+ * body height alongside the editor, not a decorative divider), so it moved
37
+ * from `border.muted` (a 1.4:1 decorative-hairline tier) to
38
+ * `border.control` (the 3:1 functional tier).
39
+ */
34
40
  .cinder-parameter-field__rail {
35
41
  border-radius: var(--cinder-radius-full);
36
- background: var(--cinder-border-muted);
42
+ background: var(--cinder-border);
37
43
  }
38
44
 
39
45
  .cinder-parameter-field[data-cinder-overridden] .cinder-parameter-field__rail {
@@ -82,6 +82,31 @@
82
82
  height: 0;
83
83
  }
84
84
 
85
+ /*
86
+ * CIN-606: `background-clip` defaults to `border-box`, so the PANEL's own
87
+ * `background: var(--cinder-surface-raised)` paints under its translucent
88
+ * `border.control` edge — the panel border always composites over
89
+ * `surface-raised`. The arrow, being a zero-size border-triangle with no
90
+ * background of its own, used to paint its outer (`--cinder-border`)
91
+ * triangle straight onto whatever the popover floats over instead — the
92
+ * same translucent ink composited over a different backdrop than the
93
+ * panel edge, which was invisible while both tokens were opaque and is
94
+ * not now.
95
+ *
96
+ * The fix gives the outer triangle a backdrop rather than changing what
97
+ * the panel does. An element's own background/border always paints
98
+ * before its own `::before`/`::after`, so the three layers are built in
99
+ * that fixed order: this rule (the arrow's OWN border) is now the OPAQUE
100
+ * `surface-raised` backdrop, painted first; `::before` repeats the exact
101
+ * same triangle in the translucent `--cinder-border` ink, composited over
102
+ * that backdrop; `::after` is unchanged, the existing opaque 7px triangle
103
+ * that covers the inner two-thirds and leaves only the outer ~2px rim
104
+ * showing the (now correctly backed) translucent color. The net result:
105
+ * the visible rim composites over `surface-raised` in every placement,
106
+ * matching the panel edge on every backdrop instead of only on
107
+ * `surface-raised` itself.
108
+ */
109
+
85
110
  /* Panel is BELOW trigger - arrow tip points UP.
86
111
  Floating UI's arrow middleware writes `left` directly to center the
87
112
  border-box (offsetWidth=16 because of the 8px L+R borders) on the
@@ -91,6 +116,24 @@
91
116
  /* stylelint-disable csstools/use-logical */
92
117
  border-left: 8px solid transparent;
93
118
  border-right: 8px solid transparent;
119
+ border-bottom: 8px solid var(--cinder-surface-raised);
120
+ /* stylelint-enable csstools/use-logical */
121
+ }
122
+
123
+ .cinder-popover[data-cinder-placement^='bottom'] .cinder-popover__arrow::before {
124
+ content: '';
125
+ position: absolute;
126
+ top: 0;
127
+ /* The containing block for an absolutely positioned pseudo-element of a
128
+ zero-size (width:0/height:0) parent is a POINT at that parent's padding
129
+ edge, not its border-box origin -- and that point is inset from the
130
+ parent's own top-left by the parent's own border widths. This parent's
131
+ border-left is 8px, so `left: 0` here would start 8px right of the
132
+ outer triangle's actual left edge; -8px cancels that inset back to 0. */
133
+ left: -8px;
134
+ /* stylelint-disable csstools/use-logical */
135
+ border-left: 8px solid transparent;
136
+ border-right: 8px solid transparent;
94
137
  border-bottom: 8px solid var(--cinder-border);
95
138
  /* stylelint-enable csstools/use-logical */
96
139
  }
@@ -114,6 +157,20 @@
114
157
  /* stylelint-disable csstools/use-logical */
115
158
  border-left: 8px solid transparent;
116
159
  border-right: 8px solid transparent;
160
+ border-top: 8px solid var(--cinder-surface-raised);
161
+ /* stylelint-enable csstools/use-logical */
162
+ }
163
+
164
+ .cinder-popover[data-cinder-placement^='top'] .cinder-popover__arrow::before {
165
+ content: '';
166
+ position: absolute;
167
+ bottom: 0;
168
+ /* See the bottom-placement `::before` comment above -- the containing
169
+ block's left inset equals this parent's own border-left (8px). */
170
+ left: -8px;
171
+ /* stylelint-disable csstools/use-logical */
172
+ border-left: 8px solid transparent;
173
+ border-right: 8px solid transparent;
117
174
  border-top: 8px solid var(--cinder-border);
118
175
  /* stylelint-enable csstools/use-logical */
119
176
  }
@@ -138,6 +195,22 @@
138
195
  /* stylelint-disable csstools/use-logical */
139
196
  border-top: 8px solid transparent;
140
197
  border-bottom: 8px solid transparent;
198
+ border-right: 8px solid var(--cinder-surface-raised);
199
+ /* stylelint-enable csstools/use-logical */
200
+ }
201
+
202
+ .cinder-popover[data-cinder-placement^='right'] .cinder-popover__arrow::before {
203
+ content: '';
204
+ position: absolute;
205
+ /* Same containing-block inset as the bottom/top `::before` rules above,
206
+ but on the perpendicular axis: this parent's border-top is 8px, so the
207
+ padding-edge point sits 8px below its own border-box top. -8px cancels
208
+ that back to 0. */
209
+ top: -8px;
210
+ left: 0;
211
+ /* stylelint-disable csstools/use-logical */
212
+ border-top: 8px solid transparent;
213
+ border-bottom: 8px solid transparent;
141
214
  border-right: 8px solid var(--cinder-border);
142
215
  /* stylelint-enable csstools/use-logical */
143
216
  }
@@ -161,6 +234,19 @@
161
234
  /* stylelint-disable csstools/use-logical */
162
235
  border-top: 8px solid transparent;
163
236
  border-bottom: 8px solid transparent;
237
+ border-left: 8px solid var(--cinder-surface-raised);
238
+ /* stylelint-enable csstools/use-logical */
239
+ }
240
+
241
+ .cinder-popover[data-cinder-placement^='left'] .cinder-popover__arrow::before {
242
+ content: '';
243
+ position: absolute;
244
+ /* See the right-placement `::before` comment above. */
245
+ top: -8px;
246
+ right: 0;
247
+ /* stylelint-disable csstools/use-logical */
248
+ border-top: 8px solid transparent;
249
+ border-bottom: 8px solid transparent;
164
250
  border-left: 8px solid var(--cinder-border);
165
251
  /* stylelint-enable csstools/use-logical */
166
252
  }
@@ -52,11 +52,20 @@
52
52
  touch-action: none;
53
53
  }
54
54
 
55
+ /*
56
+ * CIN-603: this line is the handle's only visible affordance, so it needs
57
+ * to clear the 3:1 functional floor on its own. It used to sit at
58
+ * `border.strong` (58% alpha) diluted further by `opacity: 0.5` on this
59
+ * rule — a resting effective alpha of ~29%, easy to miss because the tier
60
+ * lives on the PARENT (`.handle`'s `color`) and the opacity on this CHILD.
61
+ * Dropping the opacity leaves the line at `border.strong`'s full,
62
+ * undiluted alpha, which the seam audit's per-tier contrast table already
63
+ * shows clears 3:1 in both arms.
64
+ */
55
65
  .cinder-resizable-panels__handle-line {
56
66
  display: block;
57
67
  border-radius: var(--cinder-radius-full);
58
68
  background: currentColor;
59
- opacity: 0.5;
60
69
  }
61
70
 
62
71
  .cinder-resizable-panels__handle[data-cinder-orientation='horizontal']
@@ -80,12 +89,6 @@
80
89
  transform: translate(-50%, -50%);
81
90
  }
82
91
 
83
- @media (hover: hover) {
84
- .cinder-resizable-panels__handle:hover .cinder-resizable-panels__handle-line {
85
- opacity: 0.9;
86
- }
87
- }
88
-
89
92
  .cinder-resizable-panels__handle:focus-visible {
90
93
  outline: var(--cinder-ring-width) solid transparent;
91
94
  box-shadow: var(--_cinder-focus-ring-shadow);
@@ -93,10 +93,20 @@
93
93
  cursor: not-allowed;
94
94
  }
95
95
 
96
- /* Empty guard — visual indicator when no options are available */
96
+ /*
97
+ * Empty guard — visual indicator when no options are available. Not
98
+ * `disabled` (the field's `disabled` binding stays false here), so the
99
+ * WCAG 1.4.11 3:1 floor still applies: the dashed border is the affordance
100
+ * that carries the "unavailable" meaning, so it must not be diluted.
101
+ * CIN-603: this used to be `opacity: 0.5` on the whole control, which
102
+ * multiplied the base rule's `border.control` boundary down to ~24%
103
+ * effective alpha along with everything else. Dimming the text color
104
+ * instead of the element keeps the dashed border at its tier's full,
105
+ * undiluted alpha.
106
+ */
97
107
  .cinder-select[data-cinder-empty='true'] {
98
108
  border-style: dashed;
99
- opacity: 0.5;
109
+ color: var(--cinder-text-muted);
100
110
  cursor: not-allowed;
101
111
  }
102
112
 
@@ -76,6 +76,13 @@
76
76
  pointer-events: none;
77
77
  }
78
78
 
79
+ /*
80
+ * CIN-603: decorative scale marking, but the `opacity: 0.6` compounding
81
+ * `border.control`'s own alpha down to ~29% was redundant now that
82
+ * `border.control` alone clears the tier's own decorative floor — removed
83
+ * rather than left needlessly fainter for no reason tied to this tick's
84
+ * (non-functional) role.
85
+ */
79
86
  .cinder-slider__tick {
80
87
  position: absolute;
81
88
  top: 50%;
@@ -85,7 +92,6 @@
85
92
  background: var(--cinder-border, currentColor);
86
93
  transform: translate(-50%, -50%);
87
94
  border-radius: var(--cinder-radius-full);
88
- opacity: 0.6;
89
95
  }
90
96
 
91
97
  .cinder-slider__thumb {
@@ -45,10 +45,19 @@
45
45
  * the box model. Adding a border where none exists at rest would shift box
46
46
  * dimensions by 2px on each side, causing layout jitter and skewing the
47
47
  * midpoint geometry used by drop-target calculations.
48
+ *
49
+ * CIN-603: this box has no other visible content — its children are
50
+ * `visibility: hidden` and its own background/box-shadow are already
51
+ * suppressed below — so the element's own `opacity` only ever diluted this
52
+ * outline. That made the drop indicator, the one thing this state exists to
53
+ * convey, read at `border.muted` (a 1.4:1 decorative-hairline tier) further
54
+ * cut to ~40% by element opacity: well under half of `border.muted`'s own
55
+ * already-sub-3:1 weight. Moving to `border.control` (the 3:1 functional
56
+ * tier) and dropping the element opacity — nothing else in this box needs
57
+ * it — puts the indicator at its tier's full, undiluted alpha instead.
48
58
  */
49
59
  .cinder-sortable-item--placeholder {
50
- opacity: 0.4;
51
- outline: 2px dashed var(--cinder-border-muted);
60
+ outline: 2px dashed var(--cinder-border);
52
61
  outline-offset: -1px;
53
62
  border-radius: var(--cinder-radius-md);
54
63
  box-shadow: none;
@@ -79,11 +88,6 @@
79
88
  transform: none;
80
89
  box-shadow: var(--cinder-shadow-lg);
81
90
  }
82
-
83
- :root:not([data-cinder-reduced-motion='false']):not([data-reduced-motion='off'])
84
- .cinder-sortable-item--placeholder {
85
- opacity: 0.6;
86
- }
87
91
  }
88
92
 
89
93
  .cinder-sortable-handle {
@@ -75,6 +75,14 @@ export class TerminalOutputParser {
75
75
  #pending = '';
76
76
  #pendingGrapheme = '';
77
77
 
78
+ // Bun's LCOV coverage counts the constructor JSC synthesizes for a class
79
+ // with private-field initializers as one of the file's functions, but
80
+ // never credits it with a hit even though `new TerminalOutputParser()` is
81
+ // called throughout this file's own tests. An explicit (behavior-identical)
82
+ // empty constructor gets credited normally.
83
+ // eslint-disable-next-line no-useless-constructor -- documented coverage-tool workaround above, not a real no-op constructor
84
+ constructor() {}
85
+
78
86
  reset(): void {
79
87
  this.#lines = [[]];
80
88
  this.#line = 0;
@@ -539,7 +539,9 @@ function isParentNode(node: Node): node is Node & ParentNode {
539
539
  * boundary further out, pairing the enclosing shadow host as the new
540
540
  * anchor, until a plain Document is reached.
541
541
  */
542
- export type ComposedFocusScope = { root: Document | ShadowRoot; anchor: Element };
542
+ type SearchableRoot = Document | DocumentFragment | Element;
543
+
544
+ export type ComposedFocusScope = { root: SearchableRoot; anchor: Element };
543
545
 
544
546
  // Duck-type on `querySelectorAll` rather than `instanceof Document`: a root
545
547
  // node can come from a different realm (another window/iframe, or a host
@@ -547,8 +549,8 @@ export type ComposedFocusScope = { root: Document | ShadowRoot; anchor: Element
547
549
  // constructor at all — happy-dom's test Document does exactly this), where
548
550
  // the constructor identity check fails even though the node is a genuine
549
551
  // searchable document-like root.
550
- function isSearchableRoot(node: Node): node is Document | ShadowRoot {
551
- return 'querySelectorAll' in node;
552
+ function isSearchableRoot(node: Node): node is SearchableRoot {
553
+ return typeof Reflect.get(node, 'querySelectorAll') === 'function';
552
554
  }
553
555
 
554
556
  /**
@@ -562,11 +564,22 @@ function isSearchableRoot(node: Node): node is Document | ShadowRoot {
562
564
  export function* composedFocusScopes(anchor: Element): Generator<ComposedFocusScope> {
563
565
  let referenceNode: Element = anchor;
564
566
  let rootNode: Node = anchor.getRootNode();
565
-
566
- while (isSearchableRoot(rootNode)) {
567
+ // `hasEnclosingShadowHost` gives the loop a reachable exit edge.
568
+ // `isSearchableRoot`'s own condition can never be false here: every node
569
+ // `anchor.getRootNode()` (or a shadow host's `getRootNode()`) can produce —
570
+ // an Element, Document, ShadowRoot, or DocumentFragment — has
571
+ // `querySelectorAll`, so the loop's only real exit is "no enclosing shadow
572
+ // host left," tracked explicitly instead of relying on a condition that
573
+ // can't go false.
574
+ let hasEnclosingShadowHost = true;
575
+
576
+ while (hasEnclosingShadowHost && isSearchableRoot(rootNode)) {
567
577
  yield { root: rootNode, anchor: referenceNode };
568
- if (!(rootNode instanceof ShadowRoot)) return;
569
- referenceNode = rootNode.host;
570
- rootNode = referenceNode.getRootNode();
578
+ const shadowRoot = rootNode instanceof ShadowRoot ? rootNode : null;
579
+ hasEnclosingShadowHost = shadowRoot !== null;
580
+ if (shadowRoot !== null) {
581
+ referenceNode = shadowRoot.host;
582
+ rootNode = referenceNode.getRootNode();
583
+ }
571
584
  }
572
585
  }
@@ -1,4 +0,0 @@
1
- import{styleSheetDeclaresDirection}from"./index.server-r6z0g6rd.js";function parseStyleQuery(conditionText){const start=/style\(\s*(--[\w-]+)\s*:\s*/i.exec(conditionText);if(!start||!start[1])return;let depth=0;for(let index=start.index+start[0].length;index<conditionText.length;index+=1){const character=conditionText[index];if(character==="(")depth+=1;if(character===")"){if(depth===0)return{index:start.index,end:index+1,name:start[1],value:conditionText.slice(start.index+start[0].length,index)};depth-=1}}return}function splitTopLevel(conditionText,operator){const parts=[];let depth=0;let start=0;let index=0;while(index<conditionText.length){const character=conditionText[index];if(character==="("){depth+=1;index+=1;continue}if(character===")"){depth=Math.max(0,depth-1);index+=1;continue}if(depth===0&&conditionText.slice(index,index+operator.length).toLowerCase()===operator&&/\s/.test(conditionText[index-1]??"")&&/\s/.test(conditionText[index+operator.length]??"")){parts.push(conditionText.slice(start,index));index+=operator.length;start=index;continue}index+=1}parts.push(conditionText.slice(start));return parts}function evaluateLogicalContainerCondition(conditionText,width,remSize,inlineSize){if(!isFullyParsedContainerCondition(conditionText))return false;return evaluateParsedLogicalContainerCondition(conditionText,width,remSize,inlineSize)}function evaluateParsedLogicalContainerCondition(conditionText,width,remSize,inlineSize){const orParts=splitTopLevel(conditionText,"or");if(orParts.length>1)return orParts.some((part)=>evaluateParsedLogicalContainerCondition(part,width,remSize,inlineSize));const andParts=splitTopLevel(conditionText,"and");if(andParts.length>1)return andParts.every((part)=>evaluateParsedLogicalContainerCondition(part,width,remSize,inlineSize));const trimmed=conditionText.trim();const unwrapped=unwrapRedundantParentheses(trimmed);if(unwrapped!==trimmed)return evaluateParsedLogicalContainerCondition(unwrapped,width,remSize,inlineSize);const notPrefix=/^not\s+/i.exec(trimmed);if(notPrefix)return!evaluateParsedLogicalContainerCondition(trimmed.slice(notPrefix[0].length),width,remSize,inlineSize);return evaluateContainerSizeConstraints(trimmed,width,remSize,inlineSize)}var containerSizeTermPattern=/^(?:(?:min|max)-(?:width|inline-size)|(?:width|inline-size))\s*:\s*(?:\d+(?:\.\d+)?|\.\d+)(?:px|rem)$/i;var featureFirstRangePattern=/^(?:width|inline-size)\s*(?:>=|>|<=|<)\s*(?:\d+(?:\.\d+)?|\.\d+)(?:px|rem)$/i;var valueFirstRangePattern=/^(?:(?:(?:\d+(?:\.\d+)?|\.\d+)(?:px|rem)\s*(?:<=|<)\s*(?:width|inline-size))(?:\s*(?:<=|<)\s*(?:\d+(?:\.\d+)?|\.\d+)(?:px|rem))?|(?:(?:\d+(?:\.\d+)?|\.\d+)(?:px|rem)\s*(?:>=|>)\s*(?:width|inline-size))(?:\s*(?:>=|>)\s*(?:\d+(?:\.\d+)?|\.\d+)(?:px|rem))?)$/i;function isFullyParsedContainerCondition(conditionText){const trimmed=conditionText.trim();if(!trimmed||!hasBalancedParentheses(trimmed))return false;return parseContainerCondition(trimmed)}function parseContainerCondition(conditionText,isTopLevelCondition=true){const original=conditionText.trim();const trimmed=unwrapRedundantParentheses(original);const wasGrouped=trimmed!==original;const orParts=splitTopLevel(trimmed,"or");const andParts=splitTopLevel(trimmed,"and");if(orParts.length>1&&andParts.length>1)return false;if(orParts.length>1)return orParts.every((part)=>parseContainerCondition(part,false));if(andParts.length>1)return andParts.every((part)=>parseContainerCondition(part,false));const notPrefix=/^not\s+/i.exec(trimmed);if(notPrefix){if(!isTopLevelCondition&&!wasGrouped)return false;const operand=trimmed.slice(notPrefix[0].length).trim();const unwrappedOperand=unwrapRedundantParentheses(operand);return unwrappedOperand!==operand&&parseContainerCondition(operand)}return wasGrouped&&(containerSizeTermPattern.test(trimmed)||featureFirstRangePattern.test(trimmed)||valueFirstRangePattern.test(trimmed))}function hasBalancedParentheses(conditionText){let depth=0;for(const character of conditionText){if(character==="(")depth+=1;if(character===")"){depth-=1;if(depth<0)return false}}return depth===0}function unwrapRedundantParentheses(conditionText){const trimmed=conditionText.trim();if(!trimmed.startsWith("(")||!trimmed.endsWith(")"))return trimmed;const matchingClose=new Map;const openPositions=[];let depth=0;for(let index=0;index<trimmed.length;index+=1){if(trimmed[index]==="("){openPositions.push(index);depth+=1}else if(trimmed[index]===")"){const open=openPositions.pop();if(open===undefined)return trimmed;matchingClose.set(open,index);depth-=1}}if(depth!==0)return trimmed;let start=0;let end=trimmed.length-1;while(start<end&&matchingClose.get(start)===end){start+=1;end-=1;while(/\s/.test(trimmed[start]??""))start+=1;while(/\s/.test(trimmed[end]??""))end-=1}return start===0?trimmed:trimmed.slice(start,end+1).trim()}function hasUnsupportedContainerSizeQuery(conditionText){if(/(?:min-|max-)?(?:height|block-size)\b/i.test(conditionText))return true;if(/\baspect-ratio\b/i.test(conditionText))return true;if(/\borientation\s*:/i.test(conditionText))return true;const featureFirstUnitMatches=conditionText.matchAll(/(?:min-|max-)?(?:width|inline-size)\s*(?:>=|>|<=|<|:)\s*[\d.]+([a-z%]+)/gi);const valueFirstUnitMatches=conditionText.matchAll(/[\d.]+([a-z%]+)\s*(?:>=|>|<=|<)\s*(?:width|inline-size)/gi);return[...featureFirstUnitMatches,...valueFirstUnitMatches].some((match)=>!/^(?:px|rem)$/i.test(match[1]))}function evaluateRangeComparisons(conditionText,width,remSize){const featureFirstPattern=/(?:width|inline-size)\s*(>=|>|<=|<)\s*([\d.]+)(px|rem)/gi;const valueFirstPattern=/([\d.]+)(px|rem)\s*(<=|<|>=|>)\s*(width|inline-size)/gi;const comparisons=[];for(const comparison of conditionText.matchAll(featureFirstPattern)){const operator=comparison[1];const threshold=comparison[2];const unit=comparison[3];if(operator&&threshold&&unit)comparisons.push({operator,threshold,unit})}for(const comparison of conditionText.matchAll(valueFirstPattern)){const threshold=comparison[1];const unit=comparison[2];const operator=comparison[3]==="<="?">=":comparison[3]==="<"?">":comparison[3]===">="?"<=":"<";if(threshold&&unit)comparisons.push({operator,threshold,unit})}if(comparisons.length===0)return;const satisfiesAll=comparisons.every((comparison)=>{const{operator}=comparison;const threshold=Number(comparison.threshold)*(comparison.unit.toLowerCase()==="rem"?remSize:1);if(operator===">=")return width>=threshold;if(operator===">")return width>threshold;if(operator==="<=")return width<=threshold;return width<threshold});return satisfiesAll}function evaluateEqualityComparison(conditionText,width,remSize){const equalityPattern=/(?:^|[\s(])(?:width|inline-size)\s*:\s*([\d.]+)(px|rem)/gi;const comparisons=[...conditionText.matchAll(equalityPattern)];if(comparisons.length===0)return;const satisfiesAll=comparisons.every((comparison)=>{const threshold=Number(comparison[1])*(comparison[2].toLowerCase()==="rem"?remSize:1);return width===threshold});return satisfiesAll}function evaluateContainerSizeConstraints(conditionText,width,remSize,inlineSize=width){const measuredSize=/\binline-size\b/i.test(conditionText)&&!/\bwidth\b/i.test(conditionText)?inlineSize:width;if(/\bwidth\b/i.test(conditionText)&&/\binline-size\b/i.test(conditionText)&&/\band\b/i.test(conditionText)){return conditionText.split(/\s+and\s+/i).every((clause)=>evaluateContainerSizeConstraints(clause,/\binline-size\b/i.test(clause)?inlineSize:width,remSize,inlineSize))}const minimum=/min-(?:width|inline-size)\s*:\s*([\d.]+)(px|rem)/i.exec(conditionText);const maximum=/max-(?:width|inline-size)\s*:\s*([\d.]+)(px|rem)/i.exec(conditionText);const toPixels=(value)=>Number(value[1])*(value[2].toLowerCase()==="rem"?remSize:1);const legacyMatches=(!minimum||measuredSize>=toPixels(minimum))&&(!maximum||measuredSize<=toPixels(maximum));const rangeMatches=evaluateRangeComparisons(conditionText,measuredSize,remSize)??true;const equalityMatches=evaluateEqualityComparison(conditionText,measuredSize,remSize)??true;const hasSizeFeature=/\b(?:width|inline-size)\b/i.test(conditionText);const hasRecognizedRange=/(?:width|inline-size)\s*(?:>=|>|<=|<)\s*[\d.]+(?:px|rem)/i.test(conditionText)||/[\d.]+(?:px|rem)\s*(?:<=|<|>=|>)\s*(?:width|inline-size)/i.test(conditionText);const hasRecognizedEquality=/(?:width|inline-size)\s*:\s*[\d.]+(?:px|rem)/i.test(conditionText);if(hasSizeFeature&&!minimum&&!maximum&&!hasRecognizedRange&&!hasRecognizedEquality)return false;const combinedMatches=legacyMatches&&rangeMatches&&equalityMatches;return/^\s*not\b/i.test(conditionText)?!combinedMatches:combinedMatches}function matchesDirectionStyleRule(element,getParentElement){const styleSheets=new Map;for(const sheet of Array.from(element.ownerDocument.styleSheets))styleSheets.set(sheet,null);for(const sheet of Array.from(element.ownerDocument.adoptedStyleSheets??[]))styleSheets.set(sheet,null);const root=element.getRootNode();if(typeof ShadowRoot!=="undefined"&&root instanceof ShadowRoot){for(const sheet of root.adoptedStyleSheets)styleSheets.set(sheet,root);for(const styleElement of root.querySelectorAll("style")){if(styleElement.sheet)styleSheets.set(styleElement.sheet,root)}for(const linkElement of root.querySelectorAll('link[rel~="stylesheet"]')){if(linkElement.sheet)styleSheets.set(linkElement.sheet,root)}}for(const[sheet,fallbackRoot]of styleSheets){if(!isActiveStyleSheet(sheet))continue;if(!styleSheetDeclaresDirection(sheet))continue;let rules;try{rules=sheet.cssRules}catch{continue}if(matchesDirectionStyleRuleList(element,rules,getParentElement,[],getImplicitScopeRoot(sheet,fallbackRoot,element.ownerDocument.documentElement)))return true}return false}function isActiveStyleSheet(sheet){if(sheet.disabled)return false;const mediaText=sheet.media?.mediaText;if(!mediaText)return true;if(typeof matchMedia!=="function")return true;return matchMedia(mediaText).matches}function getImplicitScopeRoot(sheet,fallbackRoot,documentRoot){const ownerNode=Reflect.get(sheet,"ownerNode");if(!(ownerNode instanceof Element)||ownerNode.localName?.toLowerCase()!=="style"){return typeof ShadowRoot!=="undefined"&&fallbackRoot instanceof ShadowRoot?fallbackRoot:documentRoot}if(ownerNode.parentElement)return ownerNode.parentElement;const root=ownerNode.getRootNode();return typeof ShadowRoot!=="undefined"&&root instanceof ShadowRoot?root:typeof ShadowRoot!=="undefined"&&fallbackRoot instanceof ShadowRoot?fallbackRoot:null}function matchesDirectionStyleRuleCached(element,cache,getParentElement){if(!getParentElement)return false;if(!cache)return matchesDirectionStyleRule(element,getParentElement);const cached=cache.get(element);if(cached!==undefined)return cached;const matched=matchesDirectionStyleRule(element,getParentElement);cache.set(element,matched);return matched}function matchesDirectionStyleRuleList(element,rules,getParentElement,scopes=[],implicitScopeRoot=null){for(const rule of Array.from(rules)){if(Reflect.get(rule,"type")===3){const imported=Reflect.get(rule,"styleSheet");if(imported){try{const importedRules=Reflect.get(imported,"cssRules");if(isCssRuleCollection(importedRules)&&matchesDirectionStyleRuleList(element,importedRules,getParentElement,scopes,implicitScopeRoot))return true}catch{}}continue}if(isCssStyleRule(rule)){if(!rule.style.direction){const nestedRules2=readNestedCssRules(rule);if(nestedRules2&&matchesDirectionStyleRuleList(element,nestedRules2,getParentElement,scopes,implicitScopeRoot))return true;continue}try{const selectorText=resolveNestedSelector(rule);if(selectorText&&matchesScopedSelector(element,selectorText,scopes))return true}catch{continue}}const nestedRules=readNestedCssRules(rule);if(isScopeRule(rule)){const scope=createActiveScope(rule,element,scopes,implicitScopeRoot);if(scope&&nestedRules){if(matchesDirectionStyleRuleList(element,nestedRules,getParentElement,[...scopes,scope],implicitScopeRoot))return true}continue}if(nestedRules&&isConditionalRuleActive(rule,element,getParentElement)&&matchesDirectionStyleRuleList(element,nestedRules,getParentElement,scopes,implicitScopeRoot)){return true}}return false}function readNestedCssRules(rule){if(!("cssRules"in rule))return;try{const nestedRules=Reflect.get(rule,"cssRules");return isCssRuleCollection(nestedRules)?nestedRules:undefined}catch{return}}function isCssRuleCollection(value){if(typeof CSSRuleList!=="undefined"&&value instanceof CSSRuleList)return true;if(Array.isArray(value))return value.every(isCssRule);if(typeof value!=="object"||value===null)return false;const iterator=Reflect.get(value,Symbol.iterator);return typeof iterator==="function"}function isCssRule(value){return typeof value==="object"&&value!==null&&typeof Reflect.get(value,"cssText")==="string"&&typeof Reflect.get(value,"type")==="number"}function isCssStyleRule(rule){return typeof Reflect.get(rule,"selectorText")==="string"&&typeof Reflect.get(rule,"style")==="object"&&Reflect.get(rule,"style")!==null}function resolveNestedSelector(rule){let selector=rule.selectorText.trim();let parentRule=Reflect.get(rule,"parentRule");while(parentRule){if(isCssStyleRule(parentRule)){const parentSelector=parentRule.selectorText.trim();if(!parentSelector)return;selector=combineNestedSelectors(parentSelector,selector);if(!selector)return}parentRule=Reflect.get(parentRule,"parentRule")}return selector}function combineNestedSelectors(parentSelector,nestedSelector){const parentContext=splitSelectorList(parentSelector).length>1?`:is(${parentSelector})`:parentSelector;return splitSelectorList(nestedSelector).map((selector)=>{const resolved=replaceNestingReferences(selector,parentContext);return resolved.replaced?resolved.selector:`${parentContext} ${selector}`}).join(", ")}function replaceNestingReferences(selector,parentContext){let quote;let replaced=false;let resolved="";for(let index=0;index<selector.length;index+=1){const character=selector[index];if(character==="\\"){resolved+=character;if(index+1<selector.length)resolved+=selector[++index];continue}if(quote!==undefined){resolved+=character;if(character===quote)quote=undefined;continue}if(character==='"'||character==="'"){quote=character;resolved+=character;continue}if(character==="&"){resolved+=parentContext;replaced=true;continue}resolved+=character}return{selector:resolved,replaced}}function splitSelectorList(selectorText){const selectors=[];let parenthesesDepth=0;let bracketDepth=0;let quote;let start=0;for(let index=0;index<selectorText.length;index+=1){const character=selectorText[index];if(character==="\\"){index+=1;continue}if(quote!==undefined){if(character===quote)quote=undefined;continue}if(character==='"'||character==="'"){quote=character;continue}if(character==="(")parenthesesDepth+=1;if(character===")")parenthesesDepth=Math.max(0,parenthesesDepth-1);if(character==="[")bracketDepth+=1;if(character==="]")bracketDepth=Math.max(0,bracketDepth-1);if(character===","&&parenthesesDepth===0&&bracketDepth===0){const selector2=selectorText.slice(start,index).trim();if(selector2)selectors.push(selector2);start=index+1}}const selector=selectorText.slice(start).trim();if(selector)selectors.push(selector);return selectors}function isConditionalRuleActive(rule,element,getParentElement){const conditionText=Reflect.get(rule,"conditionText");if(typeof conditionText!=="string"||!conditionText.trim())return true;if(isContainerRule(rule))return isContainerQueryActive(conditionText,element,rule,getParentElement);if(isMediaRule(rule)&&typeof matchMedia==="function"){return matchMedia(conditionText).matches}if(isSupportsRule(rule)&&typeof CSS!=="undefined"&&typeof CSS.supports==="function")return CSS.supports(conditionText);return true}function isScopeRule(rule){if(rule.constructor.name==="CSSScopeRule")return true;const cssText=Reflect.get(rule,"cssText");return typeof cssText==="string"&&/^\s*@scope\b/i.test(cssText)}function createActiveScope(rule,element,parentScopes,implicitScopeRoot){const cssText=Reflect.get(rule,"cssText");if(typeof cssText!=="string")return null;const prelude=parseScopePrelude(cssText);if(!prelude)return null;const roots=findActiveScopeRoots(element,prelude,parentScopes,implicitScopeRoot);return roots===null?null:{roots}}function scopePseudoRootCandidates(parentScopes,implicitScopeRoot){if(parentScopes.length>0)return parentScopes.at(-1).roots;return implicitScopeRoot?[implicitScopeRoot]:[]}function findActiveScopeRoots(element,prelude,parentScopes,implicitScopeRoot){if(!selectorsAreValid(element,prelude.rootSelectors))return null;if(prelude.limitSelectors&&!selectorsAreValid(element,prelude.limitSelectors))return null;if(prelude.rootSelectors.length===0){const candidates=scopePseudoRootCandidates(parentScopes,implicitScopeRoot);const roots2=candidates.length>0?candidates:[implicitScopeRoot??element.ownerDocument.documentElement];return finalizeActiveScopeRoots(roots2.filter((root)=>root.contains(element)),element,prelude,parentScopes)}const scopeRootSelectors=prelude.rootSelectors.filter(hasScopePseudoClass);const ordinaryRootSelectors=prelude.rootSelectors.filter((selector)=>!hasScopePseudoClass(selector));const scopeRootCandidates=scopePseudoRootCandidates(parentScopes,implicitScopeRoot);const roots=[...findRelativeScopeRootMatches(element,scopeRootSelectors,scopeRootCandidates),...findScopeMatches(element,ordinaryRootSelectors)];return finalizeActiveScopeRoots(roots,element,prelude,parentScopes)}function findRelativeScopeRootMatches(element,selectors,scopeRootCandidates){if(selectors.length===0||scopeRootCandidates.length===0)return[];const parentScope={roots:[...scopeRootCandidates]};const hasExactScopeSelector=selectors.some(isExactScopeSelector);const matches=[];let current=element;while(current){const currentElement=current;if(selectors.some((selector)=>matchesScopedSelector(currentElement,selector,[parentScope])))matches.push(currentElement);const parent=currentElement.parentElement;if(parent){current=parent;continue}const root=currentElement.getRootNode();if(typeof ShadowRoot!=="undefined"&&root instanceof ShadowRoot&&hasExactScopeSelector&&scopeRootCandidates.includes(root))matches.push(root);current=null}return matches}function isExactScopeSelector(selector){return selector.trim().toLowerCase()===":scope"}function finalizeActiveScopeRoots(roots,element,prelude,parentScopes){const activeRoots=[];for(const root of roots){if(!isWithinParentScopes(root,parentScopes))continue;if(prelude.limitSelectors&&isWithinScopeLimit(element,root,prelude.limitSelectors)){continue}activeRoots.push(root)}return activeRoots.length===0?null:activeRoots}function selectorsAreValid(element,selectors){try{for(const selector of selectors)element.matches(selector);return true}catch{return false}}function isWithinParentScopes(root,parentScopes){return parentScopes.every((scope)=>scope.roots.some((parentRoot)=>parentRoot.contains(root)))}function isWithinScopeLimit(element,root,limitSelectors){let current=element;while(current){if(current===root)break;if(limitSelectors.some((selector)=>hasScopePseudoClass(selector)?matchesScopedSelector(current,selector,[{roots:[root]}]):matchesSelectorSafely(current,selector)))return true;current=current.parentElement}return false}function matchesSelectorSafely(element,selector){try{return element.matches(selector)}catch{return false}}function normalizeScopeRelativeSelector(selector){return splitSelectorList(selector).map((part)=>{if(!part.includes("&")&&!/^\s*[>+~]/.test(part))return part;const withScopeAlias=replaceNestingReferences(part,":scope").selector;return/^\s*[>+~]/.test(withScopeAlias)?`:scope ${withScopeAlias}`:withScopeAlias}).join(", ")}function matchesScopedSelector(element,selector,scopes){const normalizedSelector=scopes.length>0?normalizeScopeRelativeSelector(selector):selector;return splitSelectorList(normalizedSelector).some((item)=>matchesScopedSelectorItem(element,item,scopes))}function matchesScopedSelectorItem(element,selector,scopes){if(!hasScopePseudoClass(selector))return matchesSelectorSafely(element,selector);if(scopes.length===0)return false;const scope=scopes.at(-1);if(!scope)return false;const outsideContext=splitScopeOutsideContext(selector);const remainderSelector=outsideContext?outsideContext.remainder:selector;for(const root of scope.roots){try{if(outsideContext){if(!(root instanceof Element))continue;if(!matchesOutsideScopeContext(root,outsideContext.before,outsideContext.combinator))continue}if(matchesRemainderAgainstScopeRoot(element,remainderSelector,root))return true}catch{}}return false}function splitScopeOutsideContext(selector){const scopeIndex=findScopePseudoClassIndex(selector,{topLevelOnly:true});if(scopeIndex===null)return null;const beforeRaw=selector.slice(0,scopeIndex);if(!beforeRaw.trim())return null;const trimmedEnd=beforeRaw.replace(/\s+$/,"");const lastCharacter=trimmedEnd.at(-1);if(lastCharacter===">"||lastCharacter==="+"||lastCharacter==="~"){const before2=trimmedEnd.slice(0,-1).trim();return before2?{before:before2,combinator:lastCharacter,remainder:selector.slice(scopeIndex)}:null}if(!/\s$/.test(beforeRaw))return null;const before=trimmedEnd.trim();return before?{before,combinator:" ",remainder:selector.slice(scopeIndex)}:null}function matchesOutsideScopeContext(root,before,combinator){if(combinator===" ")return root.parentElement?.closest(before)!=null;if(combinator===">")return root.parentElement!==null&&matchesSelectorSafely(root.parentElement,before);if(combinator==="+"){const sibling2=root.previousElementSibling;return sibling2!==null&&matchesSelectorSafely(sibling2,before)}let sibling=root.previousElementSibling;while(sibling){if(matchesSelectorSafely(sibling,before))return true;sibling=sibling.previousElementSibling}return false}function matchesRemainderAgainstScopeRoot(element,selector,root){if(root.querySelector(":scope")===root){return Array.from(root.querySelectorAll(selector)).includes(element)}const clone=typeof ShadowRoot!=="undefined"&&root instanceof ShadowRoot?null:root.cloneNode(true);const cloneElement=clone instanceof Element?clone:typeof ShadowRoot!=="undefined"&&root instanceof ShadowRoot?(()=>{const wrapper=root.ownerDocument.createElement("div");wrapper.append(...Array.from(root.children,(child)=>child.cloneNode(true)));return wrapper})():null;if(!cloneElement)return false;const marker="data-cinder-scope-root";const replacedSelector=replaceScopePseudoClass(selector,`[${marker}]`);if(typeof ShadowRoot!=="undefined"&&root instanceof ShadowRoot&&/^\[[^\]]+\][^\s>+~]/.test(replacedSelector))return false;cloneElement.setAttribute(marker,"true");const path=[];let current=element;while(current&&current!==root){const parent=current.parentElement;if(!parent){if(typeof ShadowRoot!=="undefined"&&root instanceof ShadowRoot&&current.getRootNode()===root)path.unshift(Array.prototype.indexOf.call(root.children,current));break}path.unshift(Array.prototype.indexOf.call(parent.children,current));current=parent}if(current!==root&&!(typeof ShadowRoot!=="undefined"&&root instanceof ShadowRoot&&current?.getRootNode()===root))return false;let matchedCloneElement=cloneElement;for(const index of path){const child=matchedCloneElement.children[index];if(!child)break;matchedCloneElement=child}return matchedCloneElement===cloneElement&&cloneElement.matches(replacedSelector)||Array.from(cloneElement.querySelectorAll(replacedSelector)).includes(matchedCloneElement)}function replaceScopePseudoClass(selector,replacement){let result="";let quote=null;let escaped=false;let brackets=0;for(let index=0;index<selector.length;index+=1){const character=selector[index];if(escaped){result+=character;escaped=false;continue}if(character==="\\"){result+=character;escaped=true;continue}if(quote){result+=character;if(character===quote)quote=null;continue}if(character==='"'||character==="'"){result+=character;quote=character;continue}if(character==="["){brackets+=1;result+=character;continue}if(character==="]"){brackets=Math.max(0,brackets-1);result+=character;continue}if(brackets===0&&character===":"&&selector.slice(index+1,index+6).toLowerCase()==="scope"&&!/[\w-]/.test(selector[index+6]??"")){result+=replacement;index+=5;continue}result+=character}return result}function findScopePseudoClassIndex(selector,options={}){let quote=null;let brackets=0;let parentheses=0;let escaped=false;for(let index=0;index<selector.length;index+=1){const character=selector[index];if(escaped){escaped=false;continue}if(character==="\\"){escaped=true;continue}if(quote){if(character===quote)quote=null;continue}if(character==='"'||character==="'"){quote=character;continue}if(character==="["){brackets+=1;continue}if(character==="]"){brackets=Math.max(0,brackets-1);continue}if(character==="("){parentheses+=1;continue}if(character===")"){parentheses=Math.max(0,parentheses-1);continue}if(brackets===0&&(!options.topLevelOnly||parentheses===0)&&character===":"&&selector.slice(index+1,index+6).toLowerCase()==="scope"&&!/[\w-]/.test(selector[index+6]??""))return index}return null}function hasScopePseudoClass(selector){return findScopePseudoClassIndex(selector)!==null}function parseScopePrelude(cssText){const match=/^\s*@scope\b/i.exec(cssText);if(!match)return null;const start=match[0].length;let quote=null;let escaped=false;let parentheses=0;let brackets=0;let end=-1;for(let index=start;index<cssText.length;index+=1){const character=cssText[index];if(escaped){escaped=false;continue}if(character==="\\"){escaped=true;continue}if(quote){if(character===quote)quote=null;continue}if(character==='"'||character==="'")quote=character;else if(character==="(")parentheses+=1;else if(character===")")parentheses-=1;else if(character==="[")brackets+=1;else if(character==="]")brackets-=1;else if(character==="{"&&parentheses===0&&brackets===0){end=index;break}if(parentheses<0||brackets<0)return null}if(end<0||quote||escaped||parentheses!==0||brackets!==0)return null;const prelude=cssText.slice(start,end).trim();const limitIndex=findScopeLimitKeyword(prelude);const rootText=(limitIndex===null?prelude:prelude.slice(0,limitIndex)).trim();const limitText=limitIndex===null?null:prelude.slice(limitIndex+2).trim();const rootSelectorText=unwrapScopeGroup(rootText);if(rootSelectorText===null)return null;const rootSelectors=rootSelectorText?splitScopeSelectors(rootSelectorText):[];if(rootSelectorText&&rootSelectors.length===0)return null;if(limitText===null)return{rootSelectors,limitSelectors:null};const limitSelectorText=unwrapScopeGroup(limitText);if(limitSelectorText===null||!limitSelectorText)return null;const limitSelectors=splitScopeSelectors(limitSelectorText);return limitSelectors.length>0?{rootSelectors,limitSelectors}:null}function findScopeLimitKeyword(prelude){let quote=null;let escaped=false;let parentheses=0;let brackets=0;for(let index=0;index<prelude.length;index+=1){const character=prelude[index];if(escaped){escaped=false;continue}if(character==="\\"){escaped=true;continue}if(quote){if(character===quote)quote=null;continue}if(character==='"'||character==="'")quote=character;else if(character==="(")parentheses+=1;else if(character===")")parentheses-=1;else if(character==="[")brackets+=1;else if(character==="]")brackets-=1;if(parentheses<0||brackets<0)return null;if(parentheses===0&&brackets===0&&prelude.slice(index,index+2).toLowerCase()==="to"&&!/[\w-]/.test(prelude[index-1]??"")&&!/[\w-]/.test(prelude[index+2]??"")){const remainder=prelude.slice(index+2);const opening=remainder.search(/\S/);if(opening>=0&&remainder[opening]==="(")return index}}return null}function unwrapScopeGroup(value){if(!value)return"";if(value[0]!=="(")return value;const end=findScopeGroupEnd(value);if(end<0||value.slice(end+1).trim())return null;return value.slice(1,end).trim()}function findScopeGroupEnd(value){let depth=0;let brackets=0;let quote=null;let escaped=false;for(let index=0;index<value.length;index+=1){const character=value[index];if(escaped){escaped=false;continue}if(character==="\\"){escaped=true;continue}if(quote){if(character===quote)quote=null;continue}if(character==='"'||character==="'")quote=character;else if(character==="[")brackets+=1;else if(character==="]")brackets-=1;else if(character==="("&&brackets===0)depth+=1;else if(character===")"&&brackets===0){depth-=1;if(depth===0)return index}if(brackets<0)return-1}return-1}function findScopeMatches(element,selectors){if(selectors.length===0)return[];const matches=[];let current=element;while(current){const currentElement=current;if(selectors.some((selector)=>matchesSelectorSafely(currentElement,selector)))matches.push(currentElement);current=currentElement.parentElement}return matches}function splitScopeSelectors(value){const selectors=[];let parentheses=0;let brackets=0;let quote=null;let escaped=false;let start=0;for(let index=0;index<value.length;index+=1){const character=value[index];if(escaped){escaped=false;continue}if(character==="\\"){escaped=true;continue}if(quote){if(character===quote)quote=null;continue}if(character==='"'||character==="'")quote=character;else if(character==="(")parentheses+=1;else if(character===")")parentheses-=1;else if(character==="[")brackets+=1;else if(character==="]")brackets-=1;else if(character===","&&parentheses===0&&brackets===0){const selector2=value.slice(start,index).trim();if(!selector2)return[];selectors.push(selector2);start=index+1}if(parentheses<0||brackets<0)return[]}if(escaped||quote||parentheses!==0||brackets!==0)return[];const selector=value.slice(start).trim();if(!selector)return[];selectors.push(selector);return selectors}function resolveContainerQueryText(conditionText,rule,containerName){const containerQuery=Reflect.get(rule,"containerQuery");if(typeof containerQuery==="string")return containerQuery;if(typeof containerName!=="string"||!containerName)return conditionText;if(!conditionText.startsWith(containerName))return conditionText;const rest=conditionText.slice(containerName.length);if(!/^\s/.test(rest))return conditionText;return rest.trimStart()}function isContainerConditionList(value){if(!Array.isArray(value)||value.length===0)return false;return value.every((entry)=>typeof entry==="object"&&entry!==null&&typeof Reflect.get(entry,"name")==="string"&&typeof Reflect.get(entry,"query")==="string")}function isContainerQueryActive(conditionText,element,rule,getParentElement){if(typeof getComputedStyle!=="function")return false;const conditions=Reflect.get(rule,"conditions");if(isContainerConditionList(conditions))return conditions.some((condition)=>isSingleContainerConditionActive(condition.query,condition.name,element,getParentElement));const containerName=Reflect.get(rule,"containerName");const queryText=resolveContainerQueryText(conditionText,rule,containerName);return isSingleContainerConditionActive(queryText,containerName,element,getParentElement)}function isSingleContainerConditionActive(queryText,containerName,element,getParentElement){if(!queryText.trim())return false;const styleQuery=parseStyleQuery(queryText);if(styleQuery){const remainder=(queryText.slice(0,styleQuery.index)+queryText.slice(styleQuery.end)).replace(/^\s*(?:and|or|not)\b/i,"").replace(/^\(|\)$/g,"").trim();if(remainder)return false;let ancestor=getParentElement(element);while(ancestor){if(typeof containerName==="string"&&containerName){const computedStyle=getComputedStyle(ancestor);const name=computedStyle.containerName||computedStyle.getPropertyValue("container-name")||ancestor.style.containerName||ancestor.style.getPropertyValue("container-name");if(!name.split(/\s+/).includes(containerName)){ancestor=getParentElement(ancestor);continue}}const value=getComputedStyle(ancestor).getPropertyValue(styleQuery.name).trim()||ancestor.style.getPropertyValue(styleQuery.name).trim();return/^\s*not\b/i.test(queryText)?value!==styleQuery.value.trim():value===styleQuery.value.trim()}return false}const queriesPhysicalWidth=/(?:^|[\s(])(?:width|min-width|max-width)\s*[:<>=]/i.test(queryText)||/[\d.]+(?:px|rem)\s*(?:<=|<|>=|>)\s*width\b/i.test(queryText);let container=getParentElement(element);while(container){const computedStyle=getComputedStyle(container);const type=computedStyle.containerType||computedStyle.getPropertyValue("container-type")||container.style.containerType||container.style.getPropertyValue("container-type");const name=computedStyle.containerName||computedStyle.getPropertyValue("container-name")||container.style.containerName||container.style.getPropertyValue("container-name");const writingMode2=computedStyle.writingMode||computedStyle.getPropertyValue("writing-mode")||container.style.writingMode||container.style.getPropertyValue("writing-mode");if((typeof containerName!=="string"||!containerName||name.split(/\s+/).includes(containerName))&&type&&type!=="normal"&&!(queriesPhysicalWidth&&/^(?:vertical|sideways)-/i.test(writingMode2)&&type==="inline-size")){break}container=getParentElement(container)}if(!container)return false;const computedContainerStyle=getComputedStyle(container);const readInset=(property,fallbackProperty)=>{const camel=property.replace(/-([a-z])/g,(_,character)=>character.toUpperCase());const fallbackCamel=fallbackProperty.replace(/-([a-z])/g,(_,character)=>character.toUpperCase());const value=Reflect.get(computedContainerStyle,camel)||Reflect.get(container.style,camel)||computedContainerStyle.getPropertyValue(property).trim()||container.style.getPropertyValue(property).trim()||Reflect.get(computedContainerStyle,fallbackCamel)||Reflect.get(container.style,fallbackCamel)||computedContainerStyle.getPropertyValue(fallbackProperty).trim()||container.style.getPropertyValue(fallbackProperty).trim();const parsed=Number.parseFloat(value);return Number.isFinite(parsed)&&parsed>0?parsed:0};const writingMode=computedContainerStyle.writingMode||computedContainerStyle.getPropertyValue("writing-mode")||container.style.writingMode||container.style.getPropertyValue("writing-mode");const usesInlineSize=/(?:inline-size|min-inline-size|max-inline-size)/i.test(queryText);const isVerticalWritingMode=/^(?:vertical|sideways)-/i.test(writingMode);const verticalInlineAxis=usesInlineSize&&isVerticalWritingMode;const physicalInsets=readInset("padding-left","padding-inline-start")+readInset("padding-right","padding-inline-end");const physicalBorders=readInset("border-left-width","border-inline-start-width")+readInset("border-right-width","border-inline-end-width");const inlineInsets=verticalInlineAxis?readInset("padding-inline-start","padding-top")+readInset("padding-inline-end","padding-bottom"):physicalInsets;const inlineBorders=verticalInlineAxis?readInset("border-inline-start-width","border-top-width")+readInset("border-inline-end-width","border-bottom-width"):physicalBorders;const readUsedContentSize=(axis,fallback,insets,borders)=>{const parsed=Number.parseFloat(computedContainerStyle[axis]);if(!Number.isFinite(parsed))return fallback;const boxSizing=computedContainerStyle.boxSizing||container.style.boxSizing;return boxSizing==="border-box"?Math.max(0,parsed-insets-borders):parsed};const physicalClientSize=container.clientWidth;const inlineClientSize=verticalInlineAxis?container.clientHeight:physicalClientSize;const width=Math.max(0,readUsedContentSize("width",physicalClientSize>0?physicalClientSize-physicalInsets:container.offsetWidth-physicalBorders-physicalInsets,physicalInsets,physicalBorders));const inlineSize=Math.max(0,readUsedContentSize(verticalInlineAxis?"height":"width",inlineClientSize>0?inlineClientSize-inlineInsets:(verticalInlineAxis?container.offsetHeight:container.offsetWidth)-inlineBorders-inlineInsets,inlineInsets,inlineBorders));const rootFontSize=Number.parseFloat(getComputedStyle(element.ownerDocument.documentElement).fontSize);const remSize=Number.isFinite(rootFontSize)&&rootFontSize>0?rootFontSize:16;if(hasUnsupportedContainerSizeQuery(queryText))return false;return evaluateLogicalContainerCondition(queryText,width,remSize,inlineSize)}function isContainerRule(rule){if(rule.constructor.name==="CSSContainerRule")return true;if(Reflect.get(rule,"type")!==0)return false;const cssText=Reflect.get(rule,"cssText");return typeof cssText==="string"&&/^\s*@container\b/i.test(cssText)}function isMediaRule(rule){return typeof Reflect.get(rule,"media")==="object"&&Reflect.get(rule,"media")!==null}function isSupportsRule(rule){return rule.constructor.name==="CSSSupportsRule"||Reflect.get(rule,"type")===12}function elementDirectionStyleOverride(element){if(!element)return;if(element.style.direction)return readComputedTextDirection(element);if(!matchesDirectionStyleRuleCached(element,undefined,composedParentElement))return;return readComputedTextDirection(element)}function resolveTextDirection(element,fallback,options){const ignoreElementDirectionAttribute=options?.ignoreElementDirectionAttribute??false;const directionStyleRuleCache=new WeakMap;if(ignoreElementDirectionAttribute&&element){const styledDirection=readComputedTextDirection(element);const rootComputedDirection2=readComputedTextDirection(element.ownerDocument.documentElement);const elementDirectionAttribute=element.getAttribute("dir")?.toLowerCase();const differsFromRootViaStyling=styledDirection!==rootComputedDirection2&&styledDirection!==elementDirectionAttribute;if(styledDirection&&(hasElementDirectionStylingHint(element,directionStyleRuleCache)||differsFromRootViaStyling))return styledDirection}let currentElement=ignoreElementDirectionAttribute?element?composedParentElement(element):null:element??null;let documentDirection;let styledDirectionElement=null;while(currentElement){if(!styledDirectionElement&&currentElement!==currentElement.ownerDocument.documentElement&&(Boolean(currentElement.style.direction)||matchesDirectionStyleRuleCached(currentElement,directionStyleRuleCache,composedParentElement))){styledDirectionElement=currentElement}const direction=currentElement.getAttribute("dir")?.toLowerCase();if(direction==="rtl"||direction==="ltr"){if(typeof getComputedStyle==="function"&&styledDirectionElement){const styledDirection2=getComputedStyle(styledDirectionElement).direction;if(styledDirection2==="rtl"||styledDirection2==="ltr")return styledDirection2}if(currentElement===currentElement.ownerDocument.documentElement){documentDirection=direction;break}return direction}if(direction==="auto"&&typeof getComputedStyle==="function"){const computedDirection2=getComputedStyle(currentElement).direction;if(computedDirection2==="rtl"||computedDirection2==="ltr")return computedDirection2}const styledDirection=currentElement.style.direction;if(!styledDirectionElement&&(styledDirection==="rtl"||styledDirection==="ltr")){styledDirectionElement=currentElement}currentElement=composedParentElement(currentElement)}if(typeof getComputedStyle==="function"&&styledDirectionElement){const direction=getComputedStyle(styledDirectionElement).direction;if(direction==="rtl"||direction==="ltr")return direction}const computedDirection=readComputedTextDirection(element);const rootComputedDirection=readComputedTextDirection(element?.ownerDocument.documentElement);if(!ignoreElementDirectionAttribute&&computedDirection&&computedDirection!==rootComputedDirection)return computedDirection;if(computedDirection&&fallback&&computedDirection!==fallback&&hasDirectionStylingHint(element,false,directionStyleRuleCache)){return computedDirection}if(!fallback&&computedDirection==="rtl")return computedDirection;if(fallback)return fallback;if(documentDirection)return documentDirection;return}function hasElementDirectionStylingHint(element,cache){return Boolean(element.style.direction)||matchesDirectionStyleRuleCached(element,cache,composedParentElement)}function readComputedTextDirection(element){if(!element||typeof getComputedStyle!=="function")return;const direction=getComputedStyle(element).direction;return direction==="rtl"||direction==="ltr"?direction:undefined}function hasDirectionStylingHint(element,includeElement=false,cache){let currentElement=includeElement?element:element?composedParentElement(element):null;while(currentElement&&currentElement!==currentElement.ownerDocument.documentElement){if(currentElement.style.direction)return true;if(matchesDirectionStyleRuleCached(currentElement,cache,composedParentElement))return true;currentElement=composedParentElement(currentElement)}return false}function composedParentElement(element){if(element.parentElement)return element.parentElement;const root=element.getRootNode();return typeof ShadowRoot!=="undefined"&&typeof HTMLElement!=="undefined"&&root instanceof ShadowRoot&&root.host instanceof HTMLElement?root.host:null}function isRightToLeftElement(element){return resolveTextDirection(element)==="rtl"}
2
- export{elementDirectionStyleOverride,resolveTextDirection,isRightToLeftElement};
3
-
4
- //# debugId=88ADDD38E80E9F3164756E2164756E21