elit 3.6.6 → 3.6.7

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 (153) hide show
  1. package/Cargo.lock +1 -1
  2. package/Cargo.toml +1 -1
  3. package/dist/build.cjs +421 -331
  4. package/dist/build.d.ts +1 -19
  5. package/dist/build.js +420 -330
  6. package/dist/build.mjs +420 -330
  7. package/dist/chokidar.cjs +219 -182
  8. package/dist/chokidar.d.ts +25 -10
  9. package/dist/chokidar.js +217 -182
  10. package/dist/chokidar.mjs +218 -183
  11. package/dist/cli.cjs +22439 -21563
  12. package/dist/cli.d.ts +19 -37
  13. package/dist/cli.mjs +24113 -23252
  14. package/dist/config.cjs +357 -350
  15. package/dist/config.d.ts +17 -245
  16. package/dist/config.js +520 -515
  17. package/dist/config.mjs +346 -341
  18. package/dist/contracts-BeW9k0yZ.d.ts +54 -0
  19. package/dist/contracts-D7KIS-TK.d.ts +36 -0
  20. package/dist/coverage.cjs +448 -485
  21. package/dist/coverage.d.ts +13 -62
  22. package/dist/coverage.js +447 -484
  23. package/dist/coverage.mjs +447 -484
  24. package/dist/database.cjs +819 -828
  25. package/dist/database.d.ts +8 -24
  26. package/dist/database.js +818 -829
  27. package/dist/database.mjs +818 -829
  28. package/dist/desktop-auto-render.cjs +1700 -1523
  29. package/dist/desktop-auto-render.d.ts +4 -12
  30. package/dist/desktop-auto-render.js +1695 -1518
  31. package/dist/desktop-auto-render.mjs +1696 -1519
  32. package/dist/desktop.cjs +3 -1
  33. package/dist/desktop.d.ts +4 -1
  34. package/dist/desktop.js +1 -1
  35. package/dist/desktop.mjs +1 -1
  36. package/dist/dev-build.cjs +830 -0
  37. package/dist/dev-build.d.ts +53 -0
  38. package/dist/dev-build.js +3318 -0
  39. package/dist/dev-build.mjs +797 -0
  40. package/dist/dom.cjs +717 -591
  41. package/dist/dom.d.ts +2 -17
  42. package/dist/dom.js +714 -588
  43. package/dist/dom.mjs +716 -590
  44. package/dist/el.cjs +62 -52
  45. package/dist/el.d.ts +5 -12
  46. package/dist/el.js +60 -52
  47. package/dist/el.mjs +60 -52
  48. package/dist/fs.cjs +72 -63
  49. package/dist/fs.d.ts +22 -19
  50. package/dist/fs.js +71 -62
  51. package/dist/fs.mjs +71 -62
  52. package/dist/hmr.cjs +40 -14
  53. package/dist/hmr.d.ts +11 -23
  54. package/dist/hmr.js +38 -14
  55. package/dist/hmr.mjs +38 -14
  56. package/dist/http.cjs +251 -99
  57. package/dist/http.d.ts +38 -104
  58. package/dist/http.js +249 -99
  59. package/dist/http.mjs +249 -99
  60. package/dist/https.cjs +524 -228
  61. package/dist/https.d.ts +44 -36
  62. package/dist/https.js +520 -226
  63. package/dist/https.mjs +522 -228
  64. package/dist/index.cjs +7502 -7691
  65. package/dist/index.d.ts +6 -3
  66. package/dist/index.js +7486 -7677
  67. package/dist/index.mjs +7497 -7687
  68. package/dist/mime-types.cjs +10 -4
  69. package/dist/mime-types.d.ts +8 -11
  70. package/dist/mime-types.js +9 -3
  71. package/dist/mime-types.mjs +9 -3
  72. package/dist/native.cjs +8616 -8870
  73. package/dist/native.d.ts +7 -10
  74. package/dist/native.js +8682 -8936
  75. package/dist/native.mjs +8615 -8869
  76. package/dist/path.cjs +83 -77
  77. package/dist/path.d.ts +29 -29
  78. package/dist/path.js +82 -76
  79. package/dist/path.mjs +82 -76
  80. package/dist/pm.cjs +3300 -0
  81. package/dist/pm.d.ts +256 -0
  82. package/dist/pm.js +5638 -0
  83. package/dist/pm.mjs +3196 -0
  84. package/dist/preview-build.cjs +712 -0
  85. package/dist/preview-build.d.ts +59 -0
  86. package/dist/preview-build.js +3194 -0
  87. package/dist/preview-build.mjs +676 -0
  88. package/dist/render-context.cjs +13 -2
  89. package/dist/render-context.d.ts +9 -34
  90. package/dist/render-context.js +11 -2
  91. package/dist/render-context.mjs +11 -2
  92. package/dist/router.cjs +787 -646
  93. package/dist/router.d.ts +8 -14
  94. package/dist/router.js +786 -645
  95. package/dist/router.mjs +786 -645
  96. package/dist/runtime.cjs +1 -1
  97. package/dist/runtime.js +1 -1
  98. package/dist/runtime.mjs +1 -1
  99. package/dist/server.cjs +3254 -2684
  100. package/dist/server.d.ts +47 -5
  101. package/dist/server.js +3427 -2859
  102. package/dist/server.mjs +3397 -2829
  103. package/dist/smtp-server.cjs +16 -3
  104. package/dist/smtp-server.d.ts +12 -26
  105. package/dist/smtp-server.js +18 -5
  106. package/dist/smtp-server.mjs +16 -3
  107. package/dist/state-DvEkDehk.d.ts +195 -0
  108. package/dist/state.cjs +768 -659
  109. package/dist/state.d.ts +11 -71
  110. package/dist/state.js +760 -651
  111. package/dist/state.mjs +767 -658
  112. package/dist/style.cjs +1011 -968
  113. package/dist/style.d.ts +13 -127
  114. package/dist/style.js +1009 -970
  115. package/dist/style.mjs +1011 -971
  116. package/dist/test-reporter.cjs +332 -316
  117. package/dist/test-reporter.d.ts +28 -33
  118. package/dist/test-reporter.js +328 -312
  119. package/dist/test-reporter.mjs +328 -312
  120. package/dist/test-runtime.cjs +927 -968
  121. package/dist/test-runtime.d.ts +24 -99
  122. package/dist/test-runtime.js +922 -965
  123. package/dist/test-runtime.mjs +922 -965
  124. package/dist/test.cjs +4428 -4273
  125. package/dist/test.d.ts +2 -8
  126. package/dist/test.js +4307 -4154
  127. package/dist/test.mjs +4419 -4267
  128. package/dist/types-BONVzPtp.d.ts +59 -0
  129. package/dist/types-BR4wMiVx.d.ts +32 -0
  130. package/dist/types-C4gKykuG.d.ts +23 -0
  131. package/dist/types-CIhpN1-K.d.ts +64 -0
  132. package/dist/types-Ckj8md_j.d.ts +84 -0
  133. package/dist/types-CpjQTAkX.d.ts +24 -0
  134. package/dist/types-D0LjrYjS.d.ts +14 -0
  135. package/dist/types-DAisuVr5.d.ts +75 -0
  136. package/dist/types-tJn88E1N.d.ts +242 -0
  137. package/dist/types.d.ts +50 -237
  138. package/dist/universal.cjs +1 -1
  139. package/dist/universal.d.ts +1 -7
  140. package/dist/universal.js +1 -1
  141. package/dist/universal.mjs +1 -1
  142. package/dist/websocket-XfyK23zD.d.ts +119 -0
  143. package/dist/ws.cjs +129 -108
  144. package/dist/ws.d.ts +21 -131
  145. package/dist/ws.js +128 -109
  146. package/dist/ws.mjs +128 -109
  147. package/dist/wss.cjs +757 -479
  148. package/dist/wss.d.ts +31 -28
  149. package/dist/wss.js +755 -479
  150. package/dist/wss.mjs +758 -482
  151. package/package.json +8 -1
  152. package/vendor/epaint-0.31.1/src/image.rs +418 -0
  153. package/dist/server-uMQvZAll.d.ts +0 -458
package/dist/style.cjs CHANGED
@@ -17,7 +17,7 @@ var __copyProps = (to, from, except, desc) => {
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
 
20
- // src/style.ts
20
+ // src/client/style/index.ts
21
21
  var style_exports = {};
22
22
  __export(style_exports, {
23
23
  CreateStyle: () => CreateStyle,
@@ -65,253 +65,580 @@ __export(style_exports, {
65
65
  nesting: () => nesting,
66
66
  renderStyle: () => renderStyle,
67
67
  resolveClassStyles: () => resolveClassStyles,
68
+ resolveNativeStyles: () => resolveNativeStyles,
68
69
  styles: () => styles,
69
70
  supportsStyle: () => supportsStyle
70
71
  });
71
72
  module.exports = __toCommonJS(style_exports);
72
- var ELIT_SHARED_STYLE_STORE_KEY = "__elitSharedStyleStore__";
73
- function createStyleStore() {
74
- return {
75
- variables: [],
76
- rules: [],
77
- mediaRules: [],
78
- keyframes: [],
79
- fontFaces: [],
80
- imports: [],
81
- containerRules: [],
82
- supportsRules: [],
83
- layerRules: [],
84
- layerOrder: []
85
- };
86
- }
87
- function getSharedStyleStore() {
88
- const globalScope = globalThis;
89
- if (!globalScope[ELIT_SHARED_STYLE_STORE_KEY]) {
90
- globalScope[ELIT_SHARED_STYLE_STORE_KEY] = createStyleStore();
73
+
74
+ // src/client/style/condition-utils.ts
75
+ function splitConditionalClauses(value, operator) {
76
+ const clauses = [];
77
+ let token = "";
78
+ let depth = 0;
79
+ for (let index = 0; index < value.length; index++) {
80
+ const char = value[index];
81
+ if (char === "(") {
82
+ depth += 1;
83
+ } else if (char === ")" && depth > 0) {
84
+ depth -= 1;
85
+ }
86
+ const operatorToken = ` ${operator} `;
87
+ if (depth === 0 && value.slice(index, index + operatorToken.length).toLowerCase() === operatorToken) {
88
+ const trimmed = token.trim();
89
+ if (trimmed) {
90
+ clauses.push(trimmed);
91
+ }
92
+ token = "";
93
+ index += operatorToken.length - 1;
94
+ continue;
95
+ }
96
+ token += char;
91
97
  }
92
- return globalScope[ELIT_SHARED_STYLE_STORE_KEY];
98
+ const trailing = token.trim();
99
+ if (trailing) {
100
+ clauses.push(trailing);
101
+ }
102
+ return clauses;
93
103
  }
94
- var CreateStyle = class {
95
- constructor(store) {
96
- this.variables = [];
97
- this.rules = [];
98
- this.mediaRules = [];
99
- this.keyframes = [];
100
- this.fontFaces = [];
101
- this.imports = [];
102
- this.containerRules = [];
103
- this.supportsRules = [];
104
- this.layerRules = [];
105
- this._layerOrder = [];
106
- this.parsedSelectorChainCache = /* @__PURE__ */ new Map();
107
- if (!store) {
108
- return;
109
- }
110
- this.variables = store.variables;
111
- this.rules = store.rules;
112
- this.mediaRules = store.mediaRules;
113
- this.keyframes = store.keyframes;
114
- this.fontFaces = store.fontFaces;
115
- this.imports = store.imports;
116
- this.containerRules = store.containerRules;
117
- this.supportsRules = store.supportsRules;
118
- this.layerRules = store.layerRules;
119
- this._layerOrder = store.layerOrder;
104
+ function matchesSupportsDeclaration(property, value) {
105
+ const normalizedProperty = property.trim().toLowerCase();
106
+ const normalizedValue = value.trim().toLowerCase();
107
+ const supportedProperties = /* @__PURE__ */ new Set([
108
+ "align-items",
109
+ "background",
110
+ "background-color",
111
+ "backdrop-filter",
112
+ "border",
113
+ "border-radius",
114
+ "box-shadow",
115
+ "color",
116
+ "column-gap",
117
+ "container-name",
118
+ "container-type",
119
+ "display",
120
+ "flex",
121
+ "flex-direction",
122
+ "flex-grow",
123
+ "flex-wrap",
124
+ "font-family",
125
+ "font-size",
126
+ "font-weight",
127
+ "gap",
128
+ "grid-template-columns",
129
+ "height",
130
+ "justify-content",
131
+ "letter-spacing",
132
+ "line-height",
133
+ "margin",
134
+ "margin-bottom",
135
+ "margin-left",
136
+ "margin-right",
137
+ "margin-top",
138
+ "max-height",
139
+ "max-width",
140
+ "min-height",
141
+ "min-width",
142
+ "padding",
143
+ "padding-bottom",
144
+ "padding-end",
145
+ "padding-horizontal",
146
+ "padding-left",
147
+ "padding-right",
148
+ "padding-start",
149
+ "padding-top",
150
+ "padding-vertical",
151
+ "row-gap",
152
+ "text-align",
153
+ "text-decoration",
154
+ "text-transform",
155
+ "width"
156
+ ]);
157
+ if (!supportedProperties.has(normalizedProperty)) {
158
+ return false;
120
159
  }
121
- // CSS Variables
122
- addVar(name, value) {
123
- const cssVar = {
124
- name: name.startsWith("--") ? name : `--${name}`,
125
- value,
126
- toString() {
127
- return `var(${this.name})`;
128
- }
129
- };
130
- this.variables.push(cssVar);
131
- return cssVar;
160
+ if (normalizedProperty === "display") {
161
+ return (/* @__PURE__ */ new Set(["block", "flex", "grid", "inline", "inline-block", "inline-flex", "inline-grid"])).has(normalizedValue);
132
162
  }
133
- var(variable, fallback) {
134
- const varName = typeof variable === "string" ? variable.startsWith("--") ? variable : `--${variable}` : variable.name;
135
- return fallback ? `var(${varName}, ${fallback})` : `var(${varName})`;
163
+ if (normalizedProperty === "backdrop-filter") {
164
+ return /blur\(/.test(normalizedValue);
136
165
  }
137
- // Basic Selectors
138
- addTag(tag, styles2) {
139
- const rule = { selector: tag, styles: styles2, type: "tag" };
140
- this.rules.push(rule);
141
- return rule;
166
+ if (normalizedProperty === "container-type") {
167
+ return (/* @__PURE__ */ new Set(["inline-size", "size"])).has(normalizedValue);
142
168
  }
143
- addClass(name, styles2) {
144
- const selector = name.startsWith(".") ? name : `.${name}`;
145
- const rule = { selector, styles: styles2, type: "class" };
146
- this.rules.push(rule);
147
- return rule;
169
+ return true;
170
+ }
171
+ function matchesSupportsCondition(condition) {
172
+ const normalized = condition.trim().replace(/^\(+|\)+$/g, "").trim();
173
+ if (!normalized) {
174
+ return true;
148
175
  }
149
- addId(name, styles2) {
150
- const selector = name.startsWith("#") ? name : `#${name}`;
151
- const rule = { selector, styles: styles2, type: "id" };
152
- this.rules.push(rule);
153
- return rule;
176
+ if (normalized.toLowerCase().startsWith("not ")) {
177
+ return !matchesSupportsCondition(normalized.slice(4));
154
178
  }
155
- // Pseudo Selectors
156
- addPseudoClass(pseudo, styles2, baseSelector) {
157
- const pseudoClass = pseudo.startsWith(":") ? pseudo : `:${pseudo}`;
158
- const selector = baseSelector ? `${baseSelector}${pseudoClass}` : pseudoClass;
159
- const rule = { selector, styles: styles2, type: "pseudo-class" };
160
- this.rules.push(rule);
161
- return rule;
179
+ const orClauses = splitConditionalClauses(normalized, "or");
180
+ if (orClauses.length > 1) {
181
+ return orClauses.some((clause) => matchesSupportsCondition(clause));
162
182
  }
163
- addPseudoElement(pseudo, styles2, baseSelector) {
164
- const pseudoElement = pseudo.startsWith("::") ? pseudo : `::${pseudo}`;
165
- const selector = baseSelector ? `${baseSelector}${pseudoElement}` : pseudoElement;
166
- const rule = { selector, styles: styles2, type: "pseudo-element" };
167
- this.rules.push(rule);
168
- return rule;
183
+ const andClauses = splitConditionalClauses(normalized, "and");
184
+ if (andClauses.length > 1) {
185
+ return andClauses.every((clause) => matchesSupportsCondition(clause));
169
186
  }
170
- // Attribute Selectors
171
- addAttribute(attr, styles2, baseSelector) {
172
- const attrSelector = attr.startsWith("[") ? attr : `[${attr}]`;
173
- const selector = baseSelector ? `${baseSelector}${attrSelector}` : attrSelector;
174
- const rule = { selector, styles: styles2, type: "attribute" };
175
- this.rules.push(rule);
176
- return rule;
187
+ const declarationMatch = normalized.match(/^([a-z-]+)\s*:\s*(.+)$/i);
188
+ if (!declarationMatch) {
189
+ return false;
177
190
  }
178
- attrEquals(attr, value, styles2, baseSelector) {
179
- return this.addAttribute(`${attr}="${value}"`, styles2, baseSelector);
191
+ return matchesSupportsDeclaration(declarationMatch[1], declarationMatch[2]);
192
+ }
193
+ function findMatchingContainerTarget(ancestors, name) {
194
+ const normalizedName = typeof name === "string" && name.trim() ? name.trim().toLowerCase() : void 0;
195
+ for (let index = ancestors.length - 1; index >= 0; index--) {
196
+ const ancestor = ancestors[index];
197
+ if (!ancestor?.isContainer || ancestor.containerWidth === void 0) {
198
+ continue;
199
+ }
200
+ if (!normalizedName) {
201
+ return ancestor;
202
+ }
203
+ if ((ancestor.containerNames ?? []).includes(normalizedName)) {
204
+ return ancestor;
205
+ }
180
206
  }
181
- attrContainsWord(attr, value, styles2, baseSelector) {
182
- return this.addAttribute(`${attr}~="${value}"`, styles2, baseSelector);
207
+ return void 0;
208
+ }
209
+ function matchesContainerCondition(condition, containerWidth) {
210
+ const normalized = condition.trim().replace(/^\(+|\)+$/g, "").trim().toLowerCase();
211
+ if (!normalized) {
212
+ return true;
183
213
  }
184
- attrStartsWith(attr, value, styles2, baseSelector) {
185
- return this.addAttribute(`${attr}^="${value}"`, styles2, baseSelector);
214
+ if (normalized.startsWith("not ")) {
215
+ return !matchesContainerCondition(normalized.slice(4), containerWidth);
186
216
  }
187
- attrEndsWith(attr, value, styles2, baseSelector) {
188
- return this.addAttribute(`${attr}$="${value}"`, styles2, baseSelector);
217
+ const orClauses = splitConditionalClauses(normalized, "or");
218
+ if (orClauses.length > 1) {
219
+ return orClauses.some((clause) => matchesContainerCondition(clause, containerWidth));
189
220
  }
190
- attrContains(attr, value, styles2, baseSelector) {
191
- return this.addAttribute(`${attr}*="${value}"`, styles2, baseSelector);
221
+ const andClauses = splitConditionalClauses(normalized, "and");
222
+ if (andClauses.length > 1) {
223
+ return andClauses.every((clause) => matchesContainerCondition(clause, containerWidth));
192
224
  }
193
- // Combinator Selectors
194
- descendant(ancestor, descendant2, styles2) {
195
- return this.createAndAddRule(`${ancestor} ${descendant2}`, styles2);
225
+ if (normalized.startsWith("min-width:")) {
226
+ const minWidth = parseMediaLength(normalized.slice("min-width:".length));
227
+ return minWidth !== void 0 && containerWidth >= minWidth;
196
228
  }
197
- child(parent, childSel, styles2) {
198
- return this.createAndAddRule(`${parent} > ${childSel}`, styles2);
229
+ if (normalized.startsWith("max-width:")) {
230
+ const maxWidth = parseMediaLength(normalized.slice("max-width:".length));
231
+ return maxWidth !== void 0 && containerWidth <= maxWidth;
199
232
  }
200
- adjacentSibling(element, sibling, styles2) {
201
- return this.createAndAddRule(`${element} + ${sibling}`, styles2);
233
+ return false;
234
+ }
235
+ function parseMediaLength(value) {
236
+ const match = value.trim().match(/^(-?\d+(?:\.\d+)?)(px|rem|em)?$/i);
237
+ if (!match) {
238
+ return void 0;
202
239
  }
203
- generalSibling(element, sibling, styles2) {
204
- return this.createAndAddRule(`${element} ~ ${sibling}`, styles2);
240
+ const numericValue = Number(match[1]);
241
+ const unit = (match[2] ?? "px").toLowerCase();
242
+ if (unit === "rem" || unit === "em") {
243
+ return numericValue * 16;
205
244
  }
206
- multiple(selectors, styles2) {
207
- return this.createAndAddRule(selectors.join(", "), styles2);
245
+ return numericValue;
246
+ }
247
+ function matchesMediaCondition(condition, options) {
248
+ const normalized = condition.trim().replace(/^\(+|\)+$/g, "").trim().toLowerCase();
249
+ if (!normalized) {
250
+ return true;
208
251
  }
209
- // Nesting (BEM-style)
210
- addName(name, styles2) {
211
- const selector = name.startsWith("--") ? `&${name}` : `&--${name}`;
212
- const rule = { selector, styles: styles2, type: "name" };
213
- return rule;
252
+ if (normalized.startsWith("min-width:")) {
253
+ const minWidth = parseMediaLength(normalized.slice("min-width:".length));
254
+ return minWidth !== void 0 && options.viewportWidth !== void 0 && options.viewportWidth >= minWidth;
214
255
  }
215
- nesting(parentRule, ...childRules) {
216
- parentRule.nested = childRules;
217
- return parentRule;
256
+ if (normalized.startsWith("max-width:")) {
257
+ const maxWidth = parseMediaLength(normalized.slice("max-width:".length));
258
+ return maxWidth !== void 0 && options.viewportWidth !== void 0 && options.viewportWidth <= maxWidth;
218
259
  }
219
- // @keyframes - Animations
220
- keyframe(name, steps) {
221
- const keyframeSteps = Object.entries(steps).map(([step, styles2]) => ({
222
- step: step === "from" ? "from" : step === "to" ? "to" : `${step}%`,
223
- styles: styles2
224
- }));
225
- const kf = { name, steps: keyframeSteps };
226
- this.keyframes.push(kf);
227
- return kf;
260
+ if (normalized === "prefers-color-scheme: dark") {
261
+ return options.colorScheme === "dark";
228
262
  }
229
- keyframeFromTo(name, from, to) {
230
- return this.keyframe(name, { from, to });
263
+ if (normalized === "prefers-color-scheme: light") {
264
+ return (options.colorScheme ?? "light") === "light";
231
265
  }
232
- // @font-face - Custom Fonts
233
- fontFace(options) {
234
- this.fontFaces.push(options);
235
- return options;
266
+ if (normalized === "prefers-reduced-motion: reduce") {
267
+ return options.reducedMotion === true;
236
268
  }
237
- // @import - Import Stylesheets
238
- import(url, mediaQuery) {
239
- const importRule = mediaQuery ? `@import url("${url}") ${mediaQuery};` : `@import url("${url}");`;
240
- this.imports.push(importRule);
241
- return importRule;
269
+ return false;
270
+ }
271
+ function matchesMediaRule(rule, options) {
272
+ const mediaType = options.mediaType ?? "screen";
273
+ if (rule.type && rule.type !== mediaType && rule.type !== "all") {
274
+ return false;
242
275
  }
243
- // @media - Media Queries
244
- media(type, condition, rules) {
245
- const mediaRule = { type, condition, rules: this.rulesToCSSRules(rules) };
246
- this.mediaRules.push(mediaRule);
247
- return mediaRule;
276
+ if (!rule.condition.trim()) {
277
+ return true;
248
278
  }
249
- mediaScreen(condition, rules) {
250
- return this.media("screen", condition, rules);
279
+ return rule.condition.split(/\band\b/i).map((part) => part.trim()).filter(Boolean).every((part) => matchesMediaCondition(part, options));
280
+ }
281
+ function getOrderedLayerNames(layerOrder2, layerRules) {
282
+ const orderedLayerNames = [];
283
+ for (const layerName of layerOrder2) {
284
+ const normalizedName = layerName.trim();
285
+ if (normalizedName && !orderedLayerNames.includes(normalizedName)) {
286
+ orderedLayerNames.push(normalizedName);
287
+ }
251
288
  }
252
- mediaPrint(rules) {
253
- return this.media("print", "", rules);
289
+ for (const layerRule of layerRules) {
290
+ const normalizedName = layerRule.name.trim();
291
+ if (normalizedName && !orderedLayerNames.includes(normalizedName)) {
292
+ orderedLayerNames.push(normalizedName);
293
+ }
254
294
  }
255
- mediaMinWidth(minWidth, rules) {
256
- return this.media("screen", `min-width: ${minWidth}`, rules);
295
+ return orderedLayerNames;
296
+ }
297
+
298
+ // src/client/style/selector-parser.ts
299
+ function splitSelectorList(value) {
300
+ const selectors = [];
301
+ let token = "";
302
+ let attributeDepth = 0;
303
+ let parenthesisDepth = 0;
304
+ let quoted;
305
+ for (let index = 0; index < value.length; index++) {
306
+ const char = value[index];
307
+ if (quoted) {
308
+ token += char;
309
+ if (char === quoted && value[index - 1] !== "\\") {
310
+ quoted = void 0;
311
+ }
312
+ continue;
313
+ }
314
+ if (char === '"' || char === "'") {
315
+ quoted = char;
316
+ token += char;
317
+ continue;
318
+ }
319
+ if (char === "[") {
320
+ attributeDepth += 1;
321
+ token += char;
322
+ continue;
323
+ }
324
+ if (char === "]" && attributeDepth > 0) {
325
+ attributeDepth -= 1;
326
+ token += char;
327
+ continue;
328
+ }
329
+ if (attributeDepth === 0 && char === "(") {
330
+ parenthesisDepth += 1;
331
+ token += char;
332
+ continue;
333
+ }
334
+ if (attributeDepth === 0 && char === ")" && parenthesisDepth > 0) {
335
+ parenthesisDepth -= 1;
336
+ token += char;
337
+ continue;
338
+ }
339
+ if (attributeDepth === 0 && parenthesisDepth === 0 && char === ",") {
340
+ const trimmed = token.trim();
341
+ if (trimmed) {
342
+ selectors.push(trimmed);
343
+ }
344
+ token = "";
345
+ continue;
346
+ }
347
+ token += char;
257
348
  }
258
- mediaMaxWidth(maxWidth, rules) {
259
- return this.media("screen", `max-width: ${maxWidth}`, rules);
349
+ const trailing = token.trim();
350
+ if (trailing) {
351
+ selectors.push(trailing);
260
352
  }
261
- mediaDark(rules) {
262
- const mediaRule = { type: "", condition: "prefers-color-scheme: dark", rules: this.rulesToCSSRules(rules) };
263
- this.mediaRules.push(mediaRule);
264
- return mediaRule;
353
+ return selectors;
354
+ }
355
+ function parsePseudoSelectorToken(token, startIndex) {
356
+ if (token[startIndex] !== ":" || token[startIndex + 1] === ":") {
357
+ return void 0;
265
358
  }
266
- mediaLight(rules) {
267
- const mediaRule = { type: "", condition: "prefers-color-scheme: light", rules: this.rulesToCSSRules(rules) };
268
- this.mediaRules.push(mediaRule);
269
- return mediaRule;
359
+ let cursor = startIndex + 1;
360
+ const nameMatch = token.slice(cursor).match(/^([_a-zA-Z][-_a-zA-Z0-9]*)/);
361
+ if (!nameMatch) {
362
+ return void 0;
270
363
  }
271
- mediaReducedMotion(rules) {
272
- const mediaRule = { type: "", condition: "prefers-reduced-motion: reduce", rules: this.rulesToCSSRules(rules) };
273
- this.mediaRules.push(mediaRule);
274
- return mediaRule;
364
+ const pseudoName = nameMatch[1].toLowerCase();
365
+ cursor += nameMatch[0].length;
366
+ if (token[cursor] !== "(") {
367
+ return { value: pseudoName, nextIndex: cursor };
368
+ }
369
+ const argumentStart = cursor + 1;
370
+ let attributeDepth = 0;
371
+ let parenthesisDepth = 1;
372
+ let quoted;
373
+ cursor += 1;
374
+ while (cursor < token.length) {
375
+ const char = token[cursor];
376
+ if (quoted) {
377
+ if (char === quoted && token[cursor - 1] !== "\\") {
378
+ quoted = void 0;
379
+ }
380
+ cursor += 1;
381
+ continue;
382
+ }
383
+ if (char === '"' || char === "'") {
384
+ quoted = char;
385
+ cursor += 1;
386
+ continue;
387
+ }
388
+ if (char === "[") {
389
+ attributeDepth += 1;
390
+ cursor += 1;
391
+ continue;
392
+ }
393
+ if (char === "]" && attributeDepth > 0) {
394
+ attributeDepth -= 1;
395
+ cursor += 1;
396
+ continue;
397
+ }
398
+ if (attributeDepth === 0 && char === "(") {
399
+ parenthesisDepth += 1;
400
+ cursor += 1;
401
+ continue;
402
+ }
403
+ if (attributeDepth === 0 && char === ")") {
404
+ parenthesisDepth -= 1;
405
+ if (parenthesisDepth === 0) {
406
+ const pseudoArgument = token.slice(argumentStart, cursor).trim();
407
+ return {
408
+ value: pseudoArgument.length > 0 ? `${pseudoName}(${pseudoArgument})` : `${pseudoName}()`,
409
+ nextIndex: cursor + 1
410
+ };
411
+ }
412
+ cursor += 1;
413
+ continue;
414
+ }
415
+ cursor += 1;
275
416
  }
276
- // @container - Container Queries
277
- container(condition, rules, name) {
278
- const containerRule = { name, condition, rules: this.rulesToCSSRules(rules) };
279
- this.containerRules.push(containerRule);
280
- return containerRule;
417
+ return void 0;
418
+ }
419
+ function parseSimpleSelectorToken(token) {
420
+ const trimmed = token.trim();
421
+ if (!trimmed || /[*&]/.test(trimmed)) {
422
+ return void 0;
281
423
  }
282
- addContainer(name, styles2) {
283
- const containerStyles = { ...styles2, containerName: name };
284
- return this.addClass(name, containerStyles);
424
+ let cursor = 0;
425
+ let tagName;
426
+ let idName;
427
+ const classNames = [];
428
+ const attributes = [];
429
+ const pseudoClasses = [];
430
+ const tagMatch = trimmed.slice(cursor).match(/^([_a-zA-Z][-_a-zA-Z0-9]*)/);
431
+ if (tagMatch) {
432
+ tagName = tagMatch[1].toLowerCase();
433
+ cursor += tagMatch[0].length;
434
+ }
435
+ while (cursor < trimmed.length) {
436
+ const char = trimmed[cursor];
437
+ if (char === ".") {
438
+ const classMatch = trimmed.slice(cursor).match(/^\.([_a-zA-Z][-_a-zA-Z0-9]*)/);
439
+ if (!classMatch) {
440
+ return void 0;
441
+ }
442
+ classNames.push(classMatch[1]);
443
+ cursor += classMatch[0].length;
444
+ continue;
445
+ }
446
+ if (char === "#") {
447
+ const idMatch = trimmed.slice(cursor).match(/^#([_a-zA-Z][-_a-zA-Z0-9]*)/);
448
+ if (!idMatch || idName) {
449
+ return void 0;
450
+ }
451
+ idName = idMatch[1];
452
+ cursor += idMatch[0].length;
453
+ continue;
454
+ }
455
+ if (char === "[") {
456
+ const endIndex = trimmed.indexOf("]", cursor + 1);
457
+ if (endIndex === -1) {
458
+ return void 0;
459
+ }
460
+ const rawAttribute = trimmed.slice(cursor + 1, endIndex).trim();
461
+ const attrMatch = rawAttribute.match(/^([_a-zA-Z][-_a-zA-Z0-9]*)(?:\s*(=|~=|\^=|\$=|\*=)\s*(?:"([^"]*)"|'([^']*)'|([^\s"']+)))?$/);
462
+ if (!attrMatch) {
463
+ return void 0;
464
+ }
465
+ attributes.push({
466
+ name: attrMatch[1].toLowerCase(),
467
+ operator: attrMatch[2],
468
+ value: attrMatch[3] ?? attrMatch[4] ?? attrMatch[5]
469
+ });
470
+ cursor = endIndex + 1;
471
+ continue;
472
+ }
473
+ if (char === ":") {
474
+ const pseudoToken = parsePseudoSelectorToken(trimmed, cursor);
475
+ if (!pseudoToken) {
476
+ return void 0;
477
+ }
478
+ pseudoClasses.push(pseudoToken.value);
479
+ cursor = pseudoToken.nextIndex;
480
+ continue;
481
+ }
482
+ return void 0;
285
483
  }
286
- // @supports - Feature Queries
287
- supports(condition, rules) {
288
- const supportsRule = { condition, rules: this.rulesToCSSRules(rules) };
289
- this.supportsRules.push(supportsRule);
290
- return supportsRule;
484
+ if (!tagName && !idName && classNames.length === 0 && attributes.length === 0 && pseudoClasses.length === 0) {
485
+ return void 0;
291
486
  }
292
- // @layer - Cascade Layers
293
- layerOrder(...layers) {
294
- this._layerOrder = layers;
487
+ return { tagName, idName, classNames, attributes, pseudoClasses };
488
+ }
489
+ function extractSupportedSelectorChains(selector, parsedSelectorChainCache) {
490
+ const cached = parsedSelectorChainCache.get(selector);
491
+ if (cached) {
492
+ return cached;
295
493
  }
296
- layer(name, rules) {
297
- const layerRule = { name, rules: this.rulesToCSSRules(rules) };
298
- this.layerRules.push(layerRule);
299
- return layerRule;
494
+ const parsedChains = splitSelectorList(selector).map((segment) => segment.trim()).map((segment) => {
495
+ const chain = [];
496
+ let token = "";
497
+ let combinator = "descendant";
498
+ let invalid = false;
499
+ let attributeDepth = 0;
500
+ let parenthesisDepth = 0;
501
+ let quoted;
502
+ const flushToken = () => {
503
+ const trimmedToken = token.trim();
504
+ token = "";
505
+ if (!trimmedToken || invalid) {
506
+ return;
507
+ }
508
+ const parsed = parseSimpleSelectorToken(trimmedToken);
509
+ if (!parsed) {
510
+ invalid = true;
511
+ return;
512
+ }
513
+ if (chain.length > 0) {
514
+ parsed.combinator = combinator;
515
+ }
516
+ chain.push(parsed);
517
+ combinator = "descendant";
518
+ };
519
+ for (let index = 0; index < segment.length; index++) {
520
+ const char = segment[index];
521
+ if (quoted) {
522
+ token += char;
523
+ if (char === quoted && segment[index - 1] !== "\\") {
524
+ quoted = void 0;
525
+ }
526
+ continue;
527
+ }
528
+ if (char === '"' || char === "'") {
529
+ quoted = char;
530
+ token += char;
531
+ continue;
532
+ }
533
+ if (char === "[") {
534
+ attributeDepth += 1;
535
+ token += char;
536
+ continue;
537
+ }
538
+ if (char === "]") {
539
+ if (attributeDepth > 0) {
540
+ attributeDepth -= 1;
541
+ }
542
+ token += char;
543
+ continue;
544
+ }
545
+ if (attributeDepth === 0 && char === "(") {
546
+ parenthesisDepth += 1;
547
+ token += char;
548
+ continue;
549
+ }
550
+ if (attributeDepth === 0 && char === ")" && parenthesisDepth > 0) {
551
+ parenthesisDepth -= 1;
552
+ token += char;
553
+ continue;
554
+ }
555
+ if (attributeDepth === 0 && parenthesisDepth === 0 && (char === ">" || char === "+" || char === "~")) {
556
+ flushToken();
557
+ if (invalid) {
558
+ break;
559
+ }
560
+ combinator = char === ">" ? "child" : char === "+" ? "adjacent-sibling" : "general-sibling";
561
+ continue;
562
+ }
563
+ if (attributeDepth === 0 && parenthesisDepth === 0 && /\s/.test(char)) {
564
+ flushToken();
565
+ if (invalid) {
566
+ break;
567
+ }
568
+ continue;
569
+ }
570
+ token += char;
571
+ }
572
+ flushToken();
573
+ if (invalid || chain.length === 0) {
574
+ return void 0;
575
+ }
576
+ return chain.some((part) => Boolean(part.tagName) || Boolean(part.idName) || part.classNames.length > 0 || part.attributes.length > 0 || part.pseudoClasses.length > 0) ? chain : void 0;
577
+ }).filter((segment) => Array.isArray(segment) && segment.length > 0);
578
+ parsedSelectorChainCache.set(selector, parsedChains);
579
+ return parsedChains;
580
+ }
581
+
582
+ // src/client/style/native-resolver.ts
583
+ var NativeStyleResolver = class {
584
+ constructor() {
585
+ this.parsedSelectorChainCache = /* @__PURE__ */ new Map();
300
586
  }
301
- // Custom Rules
302
- add(rules) {
303
- const cssRules = Object.entries(rules).map(([selector, styles2]) => {
304
- const rule = { selector, styles: styles2, type: "custom" };
305
- this.rules.push(rule);
306
- return rule;
587
+ resolveNativeStyles(target, ancestors = [], options = {}, context) {
588
+ return this.withNativeTargetNormalizationCache(() => {
589
+ const normalizedTarget = this.normalizeTarget(target);
590
+ if (!normalizedTarget.tagName && (!normalizedTarget.classNames || normalizedTarget.classNames.length === 0)) {
591
+ return {};
592
+ }
593
+ const normalizedAncestors = ancestors.map((ancestor) => this.normalizeTarget(ancestor));
594
+ const resolved = {};
595
+ const applyRules = (rules) => {
596
+ for (const rule of rules) {
597
+ const selectorChains = extractSupportedSelectorChains(rule.selector, this.parsedSelectorChainCache);
598
+ if (selectorChains.length === 0) {
599
+ continue;
600
+ }
601
+ const matches = selectorChains.some((selectorChain) => this.matchesSelectorChain(normalizedTarget, normalizedAncestors, selectorChain));
602
+ if (!matches) {
603
+ continue;
604
+ }
605
+ for (const [property, value] of Object.entries(rule.styles)) {
606
+ resolved[property] = typeof value === "string" ? this.resolveVariableReferences(value, context.variables) : value;
607
+ }
608
+ }
609
+ };
610
+ for (const layerName of getOrderedLayerNames(context.layerOrder, context.layerRules)) {
611
+ for (const layerRule of context.layerRules) {
612
+ if (layerRule.name.trim() === layerName) {
613
+ applyRules(layerRule.rules);
614
+ }
615
+ }
616
+ }
617
+ applyRules(context.rules);
618
+ for (const supportsRule of context.supportsRules) {
619
+ if (matchesSupportsCondition(supportsRule.condition)) {
620
+ applyRules(supportsRule.rules);
621
+ }
622
+ }
623
+ for (const containerRule of context.containerRules) {
624
+ const matchingContainer = findMatchingContainerTarget(normalizedAncestors, containerRule.name);
625
+ if (matchingContainer && this.hasContainerWidth(matchingContainer) && matchesContainerCondition(containerRule.condition, matchingContainer.containerWidth)) {
626
+ applyRules(containerRule.rules);
627
+ }
628
+ }
629
+ for (const mediaRule of context.mediaRules) {
630
+ if (matchesMediaRule(mediaRule, options)) {
631
+ applyRules(mediaRule.rules);
632
+ }
633
+ }
634
+ return resolved;
307
635
  });
308
- return cssRules;
309
636
  }
310
- important(value) {
311
- return `${value} !important`;
637
+ resolveClassStyles(classNames, context) {
638
+ return this.resolveNativeStyles({ classNames }, [], {}, context);
312
639
  }
313
- getVariables() {
314
- return Object.fromEntries(this.variables.map((variable) => [variable.name, variable.value]));
640
+ hasContainerWidth(target) {
641
+ return typeof target.containerWidth === "number" && Number.isFinite(target.containerWidth);
315
642
  }
316
643
  resolveVariableReferences(value, variables) {
317
644
  let resolved = value;
@@ -377,445 +704,7 @@ var CreateStyle = class {
377
704
  return callback();
378
705
  } finally {
379
706
  this.nativeTargetNormalizationCache = previousCache;
380
- }
381
- }
382
- splitConditionalClauses(value, operator) {
383
- const clauses = [];
384
- let token = "";
385
- let depth = 0;
386
- for (let index = 0; index < value.length; index++) {
387
- const char = value[index];
388
- if (char === "(") {
389
- depth += 1;
390
- } else if (char === ")" && depth > 0) {
391
- depth -= 1;
392
- }
393
- const operatorToken = ` ${operator} `;
394
- if (depth === 0 && value.slice(index, index + operatorToken.length).toLowerCase() === operatorToken) {
395
- const trimmed = token.trim();
396
- if (trimmed) {
397
- clauses.push(trimmed);
398
- }
399
- token = "";
400
- index += operatorToken.length - 1;
401
- continue;
402
- }
403
- token += char;
404
- }
405
- const trailing = token.trim();
406
- if (trailing) {
407
- clauses.push(trailing);
408
- }
409
- return clauses;
410
- }
411
- splitSelectorList(value) {
412
- const selectors = [];
413
- let token = "";
414
- let attributeDepth = 0;
415
- let parenthesisDepth = 0;
416
- let quoted;
417
- for (let index = 0; index < value.length; index++) {
418
- const char = value[index];
419
- if (quoted) {
420
- token += char;
421
- if (char === quoted && value[index - 1] !== "\\") {
422
- quoted = void 0;
423
- }
424
- continue;
425
- }
426
- if (char === '"' || char === "'") {
427
- quoted = char;
428
- token += char;
429
- continue;
430
- }
431
- if (char === "[") {
432
- attributeDepth += 1;
433
- token += char;
434
- continue;
435
- }
436
- if (char === "]" && attributeDepth > 0) {
437
- attributeDepth -= 1;
438
- token += char;
439
- continue;
440
- }
441
- if (attributeDepth === 0 && char === "(") {
442
- parenthesisDepth += 1;
443
- token += char;
444
- continue;
445
- }
446
- if (attributeDepth === 0 && char === ")" && parenthesisDepth > 0) {
447
- parenthesisDepth -= 1;
448
- token += char;
449
- continue;
450
- }
451
- if (attributeDepth === 0 && parenthesisDepth === 0 && char === ",") {
452
- const trimmed = token.trim();
453
- if (trimmed) {
454
- selectors.push(trimmed);
455
- }
456
- token = "";
457
- continue;
458
- }
459
- token += char;
460
- }
461
- const trailing = token.trim();
462
- if (trailing) {
463
- selectors.push(trailing);
464
- }
465
- return selectors;
466
- }
467
- parsePseudoSelectorToken(token, startIndex) {
468
- if (token[startIndex] !== ":" || token[startIndex + 1] === ":") {
469
- return void 0;
470
- }
471
- let cursor = startIndex + 1;
472
- const nameMatch = token.slice(cursor).match(/^([_a-zA-Z][-_a-zA-Z0-9]*)/);
473
- if (!nameMatch) {
474
- return void 0;
475
- }
476
- const pseudoName = nameMatch[1].toLowerCase();
477
- cursor += nameMatch[0].length;
478
- if (token[cursor] !== "(") {
479
- return { value: pseudoName, nextIndex: cursor };
480
- }
481
- const argumentStart = cursor + 1;
482
- let attributeDepth = 0;
483
- let parenthesisDepth = 1;
484
- let quoted;
485
- cursor += 1;
486
- while (cursor < token.length) {
487
- const char = token[cursor];
488
- if (quoted) {
489
- if (char === quoted && token[cursor - 1] !== "\\") {
490
- quoted = void 0;
491
- }
492
- cursor += 1;
493
- continue;
494
- }
495
- if (char === '"' || char === "'") {
496
- quoted = char;
497
- cursor += 1;
498
- continue;
499
- }
500
- if (char === "[") {
501
- attributeDepth += 1;
502
- cursor += 1;
503
- continue;
504
- }
505
- if (char === "]" && attributeDepth > 0) {
506
- attributeDepth -= 1;
507
- cursor += 1;
508
- continue;
509
- }
510
- if (attributeDepth === 0 && char === "(") {
511
- parenthesisDepth += 1;
512
- cursor += 1;
513
- continue;
514
- }
515
- if (attributeDepth === 0 && char === ")") {
516
- parenthesisDepth -= 1;
517
- if (parenthesisDepth === 0) {
518
- const pseudoArgument = token.slice(argumentStart, cursor).trim();
519
- return {
520
- value: pseudoArgument.length > 0 ? `${pseudoName}(${pseudoArgument})` : `${pseudoName}()`,
521
- nextIndex: cursor + 1
522
- };
523
- }
524
- cursor += 1;
525
- continue;
526
- }
527
- cursor += 1;
528
- }
529
- return void 0;
530
- }
531
- matchesSupportsDeclaration(property, value) {
532
- const normalizedProperty = property.trim().toLowerCase();
533
- const normalizedValue = value.trim().toLowerCase();
534
- const supportedProperties = /* @__PURE__ */ new Set([
535
- "align-items",
536
- "background",
537
- "background-color",
538
- "backdrop-filter",
539
- "border",
540
- "border-radius",
541
- "box-shadow",
542
- "color",
543
- "column-gap",
544
- "container-name",
545
- "container-type",
546
- "display",
547
- "flex",
548
- "flex-direction",
549
- "flex-grow",
550
- "flex-wrap",
551
- "font-family",
552
- "font-size",
553
- "font-weight",
554
- "gap",
555
- "grid-template-columns",
556
- "height",
557
- "justify-content",
558
- "letter-spacing",
559
- "line-height",
560
- "margin",
561
- "margin-bottom",
562
- "margin-left",
563
- "margin-right",
564
- "margin-top",
565
- "max-height",
566
- "max-width",
567
- "min-height",
568
- "min-width",
569
- "padding",
570
- "padding-bottom",
571
- "padding-end",
572
- "padding-horizontal",
573
- "padding-left",
574
- "padding-right",
575
- "padding-start",
576
- "padding-top",
577
- "padding-vertical",
578
- "row-gap",
579
- "text-align",
580
- "text-decoration",
581
- "text-transform",
582
- "width"
583
- ]);
584
- if (!supportedProperties.has(normalizedProperty)) {
585
- return false;
586
- }
587
- if (normalizedProperty === "display") {
588
- return (/* @__PURE__ */ new Set(["block", "flex", "grid", "inline", "inline-block", "inline-flex", "inline-grid"])).has(normalizedValue);
589
- }
590
- if (normalizedProperty === "backdrop-filter") {
591
- return /blur\(/.test(normalizedValue);
592
- }
593
- if (normalizedProperty === "container-type") {
594
- return (/* @__PURE__ */ new Set(["inline-size", "size"])).has(normalizedValue);
595
- }
596
- return true;
597
- }
598
- matchesSupportsCondition(condition) {
599
- const normalized = condition.trim().replace(/^\(+|\)+$/g, "").trim();
600
- if (!normalized) {
601
- return true;
602
- }
603
- if (normalized.toLowerCase().startsWith("not ")) {
604
- return !this.matchesSupportsCondition(normalized.slice(4));
605
- }
606
- const orClauses = this.splitConditionalClauses(normalized, "or");
607
- if (orClauses.length > 1) {
608
- return orClauses.some((clause) => this.matchesSupportsCondition(clause));
609
- }
610
- const andClauses = this.splitConditionalClauses(normalized, "and");
611
- if (andClauses.length > 1) {
612
- return andClauses.every((clause) => this.matchesSupportsCondition(clause));
613
- }
614
- const declarationMatch = normalized.match(/^([a-z-]+)\s*:\s*(.+)$/i);
615
- if (!declarationMatch) {
616
- return false;
617
- }
618
- return this.matchesSupportsDeclaration(declarationMatch[1], declarationMatch[2]);
619
- }
620
- findMatchingContainerTarget(ancestors, name) {
621
- const normalizedName = typeof name === "string" && name.trim() ? name.trim().toLowerCase() : void 0;
622
- for (let index = ancestors.length - 1; index >= 0; index--) {
623
- const ancestor = ancestors[index];
624
- if (!ancestor?.isContainer || ancestor.containerWidth === void 0) {
625
- continue;
626
- }
627
- if (!normalizedName) {
628
- return ancestor;
629
- }
630
- if ((ancestor.containerNames ?? []).includes(normalizedName)) {
631
- return ancestor;
632
- }
633
- }
634
- return void 0;
635
- }
636
- matchesContainerCondition(condition, containerWidth) {
637
- const normalized = condition.trim().replace(/^\(+|\)+$/g, "").trim().toLowerCase();
638
- if (!normalized) {
639
- return true;
640
- }
641
- if (normalized.startsWith("not ")) {
642
- return !this.matchesContainerCondition(normalized.slice(4), containerWidth);
643
- }
644
- const orClauses = this.splitConditionalClauses(normalized, "or");
645
- if (orClauses.length > 1) {
646
- return orClauses.some((clause) => this.matchesContainerCondition(clause, containerWidth));
647
- }
648
- const andClauses = this.splitConditionalClauses(normalized, "and");
649
- if (andClauses.length > 1) {
650
- return andClauses.every((clause) => this.matchesContainerCondition(clause, containerWidth));
651
- }
652
- if (normalized.startsWith("min-width:")) {
653
- const minWidth = this.parseMediaLength(normalized.slice("min-width:".length));
654
- return minWidth !== void 0 && containerWidth >= minWidth;
655
- }
656
- if (normalized.startsWith("max-width:")) {
657
- const maxWidth = this.parseMediaLength(normalized.slice("max-width:".length));
658
- return maxWidth !== void 0 && containerWidth <= maxWidth;
659
- }
660
- return false;
661
- }
662
- parseSimpleSelectorToken(token) {
663
- const trimmed = token.trim();
664
- if (!trimmed || /[*&]/.test(trimmed)) {
665
- return void 0;
666
- }
667
- let cursor = 0;
668
- let tagName;
669
- let idName;
670
- const classNames = [];
671
- const attributes = [];
672
- const pseudoClasses = [];
673
- const tagMatch = trimmed.slice(cursor).match(/^([_a-zA-Z][-_a-zA-Z0-9]*)/);
674
- if (tagMatch) {
675
- tagName = tagMatch[1].toLowerCase();
676
- cursor += tagMatch[0].length;
677
- }
678
- while (cursor < trimmed.length) {
679
- const char = trimmed[cursor];
680
- if (char === ".") {
681
- const classMatch = trimmed.slice(cursor).match(/^\.([_a-zA-Z][-_a-zA-Z0-9]*)/);
682
- if (!classMatch) {
683
- return void 0;
684
- }
685
- classNames.push(classMatch[1]);
686
- cursor += classMatch[0].length;
687
- continue;
688
- }
689
- if (char === "#") {
690
- const idMatch = trimmed.slice(cursor).match(/^#([_a-zA-Z][-_a-zA-Z0-9]*)/);
691
- if (!idMatch || idName) {
692
- return void 0;
693
- }
694
- idName = idMatch[1];
695
- cursor += idMatch[0].length;
696
- continue;
697
- }
698
- if (char === "[") {
699
- const endIndex = trimmed.indexOf("]", cursor + 1);
700
- if (endIndex === -1) {
701
- return void 0;
702
- }
703
- const rawAttribute = trimmed.slice(cursor + 1, endIndex).trim();
704
- const attrMatch = rawAttribute.match(/^([_a-zA-Z][-_a-zA-Z0-9]*)(?:\s*(=|~=|\^=|\$=|\*=)\s*(?:"([^"]*)"|'([^']*)'|([^\s"']+)))?$/);
705
- if (!attrMatch) {
706
- return void 0;
707
- }
708
- attributes.push({
709
- name: attrMatch[1].toLowerCase(),
710
- operator: attrMatch[2],
711
- value: attrMatch[3] ?? attrMatch[4] ?? attrMatch[5]
712
- });
713
- cursor = endIndex + 1;
714
- continue;
715
- }
716
- if (char === ":") {
717
- const pseudoToken = this.parsePseudoSelectorToken(trimmed, cursor);
718
- if (!pseudoToken) {
719
- return void 0;
720
- }
721
- pseudoClasses.push(pseudoToken.value);
722
- cursor = pseudoToken.nextIndex;
723
- continue;
724
- }
725
- return void 0;
726
- }
727
- if (!tagName && !idName && classNames.length === 0 && attributes.length === 0 && pseudoClasses.length === 0) {
728
- return void 0;
729
- }
730
- return { tagName, idName, classNames, attributes, pseudoClasses };
731
- }
732
- extractSupportedSelectorChains(selector) {
733
- const cached = this.parsedSelectorChainCache.get(selector);
734
- if (cached) {
735
- return cached;
736
- }
737
- const parsedChains = this.splitSelectorList(selector).map((segment) => segment.trim()).map((segment) => {
738
- const chain = [];
739
- let token = "";
740
- let combinator = "descendant";
741
- let invalid = false;
742
- let attributeDepth = 0;
743
- let parenthesisDepth = 0;
744
- let quoted;
745
- const flushToken = () => {
746
- const trimmedToken = token.trim();
747
- token = "";
748
- if (!trimmedToken || invalid) {
749
- return;
750
- }
751
- const parsed = this.parseSimpleSelectorToken(trimmedToken);
752
- if (!parsed) {
753
- invalid = true;
754
- return;
755
- }
756
- if (chain.length > 0) {
757
- parsed.combinator = combinator;
758
- }
759
- chain.push(parsed);
760
- combinator = "descendant";
761
- };
762
- for (let index = 0; index < segment.length; index++) {
763
- const char = segment[index];
764
- if (quoted) {
765
- token += char;
766
- if (char === quoted && segment[index - 1] !== "\\") {
767
- quoted = void 0;
768
- }
769
- continue;
770
- }
771
- if (char === '"' || char === "'") {
772
- quoted = char;
773
- token += char;
774
- continue;
775
- }
776
- if (char === "[") {
777
- attributeDepth += 1;
778
- token += char;
779
- continue;
780
- }
781
- if (char === "]") {
782
- if (attributeDepth > 0) {
783
- attributeDepth -= 1;
784
- }
785
- token += char;
786
- continue;
787
- }
788
- if (attributeDepth === 0 && char === "(") {
789
- parenthesisDepth += 1;
790
- token += char;
791
- continue;
792
- }
793
- if (attributeDepth === 0 && char === ")" && parenthesisDepth > 0) {
794
- parenthesisDepth -= 1;
795
- token += char;
796
- continue;
797
- }
798
- if (attributeDepth === 0 && parenthesisDepth === 0 && (char === ">" || char === "+" || char === "~")) {
799
- flushToken();
800
- if (invalid) break;
801
- combinator = char === ">" ? "child" : char === "+" ? "adjacent-sibling" : "general-sibling";
802
- continue;
803
- }
804
- if (attributeDepth === 0 && parenthesisDepth === 0 && /\s/.test(char)) {
805
- flushToken();
806
- if (invalid) break;
807
- continue;
808
- }
809
- token += char;
810
- }
811
- flushToken();
812
- if (invalid || chain.length === 0) {
813
- return void 0;
814
- }
815
- return chain.some((part) => Boolean(part.tagName) || Boolean(part.idName) || part.classNames.length > 0 || part.attributes.length > 0 || part.pseudoClasses.length > 0) ? chain : void 0;
816
- }).filter((segment) => Array.isArray(segment) && segment.length > 0);
817
- this.parsedSelectorChainCache.set(selector, parsedChains);
818
- return parsedChains;
707
+ }
819
708
  }
820
709
  matchesAttributeSelector(targetValue, selector) {
821
710
  if (selector.operator === void 0) {
@@ -902,13 +791,13 @@ var CreateStyle = class {
902
791
  if (!pseudoArgument) {
903
792
  return false;
904
793
  }
905
- const selectorArguments = this.splitSelectorList(pseudoArgument);
794
+ const selectorArguments = splitSelectorList(pseudoArgument);
906
795
  if (selectorArguments.length === 0) {
907
796
  return false;
908
797
  }
909
798
  const parsedSelectors = [];
910
799
  for (const selectorArgument of selectorArguments) {
911
- const parsedSelector = this.parseSimpleSelectorToken(selectorArgument);
800
+ const parsedSelector = parseSimpleSelectorToken(selectorArgument);
912
801
  if (!parsedSelector) {
913
802
  return false;
914
803
  }
@@ -957,7 +846,7 @@ var CreateStyle = class {
957
846
  return Number.isInteger(n) && n >= 0;
958
847
  }
959
848
  matchesHasPseudoClass(target, pseudoArgument) {
960
- const selectorArguments = this.splitSelectorList(pseudoArgument);
849
+ const selectorArguments = splitSelectorList(pseudoArgument);
961
850
  if (selectorArguments.length === 0) {
962
851
  return false;
963
852
  }
@@ -972,7 +861,7 @@ var CreateStyle = class {
972
861
  if (!scopeRelativeSelector) {
973
862
  return false;
974
863
  }
975
- const selectorChains = this.extractSupportedSelectorChains(scopeRelativeSelector);
864
+ const selectorChains = extractSupportedSelectorChains(scopeRelativeSelector, this.parsedSelectorChainCache);
976
865
  if (selectorChains.length === 0) {
977
866
  return false;
978
867
  }
@@ -1012,356 +901,471 @@ var CreateStyle = class {
1012
901
  const nextAncestors = [...ancestors, target];
1013
902
  return (target.children ?? []).some((child) => this.matchesSelectorChainInSubtree(child, nextAncestors, chain));
1014
903
  }
1015
- matchesSelectorChain(target, ancestors, chain) {
1016
- const initialCursor = {
1017
- target,
1018
- ancestorIndex: ancestors.length - 1,
1019
- previousSiblings: Array.isArray(target.previousSiblings) ? target.previousSiblings : []
1020
- };
1021
- return this.matchesSelectorChainFromCursor(chain, chain.length - 1, ancestors, initialCursor);
904
+ matchesSelectorChain(target, ancestors, chain) {
905
+ const initialCursor = {
906
+ target,
907
+ ancestorIndex: ancestors.length - 1,
908
+ previousSiblings: Array.isArray(target.previousSiblings) ? target.previousSiblings : []
909
+ };
910
+ return this.matchesSelectorChainFromCursor(chain, chain.length - 1, ancestors, initialCursor);
911
+ }
912
+ getAncestorCursor(ancestors, ancestorIndex) {
913
+ if (ancestorIndex < 0 || ancestorIndex >= ancestors.length) {
914
+ return void 0;
915
+ }
916
+ const ancestor = ancestors[ancestorIndex];
917
+ return {
918
+ target: ancestor,
919
+ ancestorIndex: ancestorIndex - 1,
920
+ previousSiblings: Array.isArray(ancestor.previousSiblings) ? ancestor.previousSiblings : []
921
+ };
922
+ }
923
+ matchesSelectorChainFromCursor(chain, chainIndex, ancestors, cursor) {
924
+ if (!this.matchesSelectorPart(cursor.target, chain[chainIndex])) {
925
+ return false;
926
+ }
927
+ if (chainIndex === 0) {
928
+ return true;
929
+ }
930
+ const combinator = chain[chainIndex].combinator ?? "descendant";
931
+ switch (combinator) {
932
+ case "child": {
933
+ const parentCursor = this.getAncestorCursor(ancestors, cursor.ancestorIndex);
934
+ return parentCursor ? this.matchesSelectorChainFromCursor(chain, chainIndex - 1, ancestors, parentCursor) : false;
935
+ }
936
+ case "adjacent-sibling": {
937
+ const siblingIndex = cursor.previousSiblings.length - 1;
938
+ if (siblingIndex < 0) {
939
+ return false;
940
+ }
941
+ return this.matchesSelectorChainFromCursor(chain, chainIndex - 1, ancestors, {
942
+ target: cursor.previousSiblings[siblingIndex],
943
+ ancestorIndex: cursor.ancestorIndex,
944
+ previousSiblings: cursor.previousSiblings.slice(0, siblingIndex)
945
+ });
946
+ }
947
+ case "general-sibling": {
948
+ for (let siblingIndex = cursor.previousSiblings.length - 1; siblingIndex >= 0; siblingIndex--) {
949
+ if (this.matchesSelectorChainFromCursor(chain, chainIndex - 1, ancestors, {
950
+ target: cursor.previousSiblings[siblingIndex],
951
+ ancestorIndex: cursor.ancestorIndex,
952
+ previousSiblings: cursor.previousSiblings.slice(0, siblingIndex)
953
+ })) {
954
+ return true;
955
+ }
956
+ }
957
+ return false;
958
+ }
959
+ case "descendant":
960
+ default: {
961
+ for (let ancestorIndex = cursor.ancestorIndex; ancestorIndex >= 0; ancestorIndex--) {
962
+ const ancestorCursor = this.getAncestorCursor(ancestors, ancestorIndex);
963
+ if (ancestorCursor && this.matchesSelectorChainFromCursor(chain, chainIndex - 1, ancestors, ancestorCursor)) {
964
+ return true;
965
+ }
966
+ }
967
+ return false;
968
+ }
969
+ }
970
+ }
971
+ };
972
+
973
+ // src/client/style/renderer.ts
974
+ function toKebabCase(str) {
975
+ return str.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
976
+ }
977
+ function stylesToString(styles2, indent = " ") {
978
+ return Object.entries(styles2).map(([prop, value]) => {
979
+ const cssValue = typeof value === "object" && value !== null && "name" in value ? `var(${value.name})` : value;
980
+ return `${indent}${toKebabCase(prop)}: ${cssValue};`;
981
+ }).join("\n");
982
+ }
983
+ function renderRule(rule, indent = "") {
984
+ let css = `${indent}${rule.selector} {
985
+ ${stylesToString(rule.styles, indent + " ")}
986
+ `;
987
+ if (rule.nested && rule.nested.length > 0) {
988
+ for (const nestedRule of rule.nested) {
989
+ const nestedSelector = nestedRule.selector.startsWith("&") ? nestedRule.selector.replace(/&/g, rule.selector) : `${rule.selector} ${nestedRule.selector}`;
990
+ css += `
991
+ ${indent}${nestedSelector} {
992
+ ${stylesToString(nestedRule.styles, indent + " ")}
993
+ ${indent}}
994
+ `;
995
+ }
996
+ }
997
+ css += `${indent}}`;
998
+ return css;
999
+ }
1000
+ function renderRulesWithIndent(rules, indent = " ") {
1001
+ return rules.map((rule) => renderRule(rule, indent)).join("\n");
1002
+ }
1003
+ function renderMediaRule(media) {
1004
+ const condition = media.type && media.condition ? `${media.type} and (${media.condition})` : media.type ? media.type : `(${media.condition})`;
1005
+ return `@media ${condition} {
1006
+ ${renderRulesWithIndent(media.rules)}
1007
+ }`;
1008
+ }
1009
+ function renderKeyframes(kf) {
1010
+ let css = `@keyframes ${kf.name} {
1011
+ `;
1012
+ for (const step of kf.steps) {
1013
+ css += ` ${step.step} {
1014
+ ${stylesToString(step.styles, " ")}
1015
+ }
1016
+ `;
1017
+ }
1018
+ css += "}";
1019
+ return css;
1020
+ }
1021
+ function renderFontFace(ff) {
1022
+ let css = "@font-face {\n";
1023
+ css += ` font-family: "${ff.fontFamily}";
1024
+ `;
1025
+ css += ` src: ${ff.src};
1026
+ `;
1027
+ if (ff.fontWeight) css += ` font-weight: ${ff.fontWeight};
1028
+ `;
1029
+ if (ff.fontStyle) css += ` font-style: ${ff.fontStyle};
1030
+ `;
1031
+ if (ff.fontDisplay) css += ` font-display: ${ff.fontDisplay};
1032
+ `;
1033
+ if (ff.unicodeRange) css += ` unicode-range: ${ff.unicodeRange};
1034
+ `;
1035
+ css += "}";
1036
+ return css;
1037
+ }
1038
+ function renderContainerRule(container2) {
1039
+ const nameStr = container2.name ? `${container2.name} ` : "";
1040
+ return `@container ${nameStr}(${container2.condition}) {
1041
+ ${renderRulesWithIndent(container2.rules)}
1042
+ }`;
1043
+ }
1044
+ function renderSupportsRule(supports) {
1045
+ return `@supports (${supports.condition}) {
1046
+ ${renderRulesWithIndent(supports.rules)}
1047
+ }`;
1048
+ }
1049
+ function renderLayerRule(layer2) {
1050
+ return `@layer ${layer2.name} {
1051
+ ${renderRulesWithIndent(layer2.rules)}
1052
+ }`;
1053
+ }
1054
+ function renderStyleSheet(context, ...additionalRules) {
1055
+ const parts = [];
1056
+ if (context.imports.length > 0) {
1057
+ parts.push(context.imports.join("\n"));
1058
+ }
1059
+ if (context.layerOrder.length > 0) {
1060
+ parts.push(`@layer ${context.layerOrder.join(", ")};`);
1061
+ }
1062
+ if (context.variables.length > 0) {
1063
+ const varDeclarations = context.variables.map((variable) => ` ${variable.name}: ${variable.value};`).join("\n");
1064
+ parts.push(`:root {
1065
+ ${varDeclarations}
1066
+ }`);
1067
+ }
1068
+ for (const ff of context.fontFaces) {
1069
+ parts.push(renderFontFace(ff));
1070
+ }
1071
+ for (const kf of context.keyframes) {
1072
+ parts.push(renderKeyframes(kf));
1073
+ }
1074
+ const allRules = [...context.rules];
1075
+ const allMediaRules = [...context.mediaRules];
1076
+ const allKeyframes = [];
1077
+ const allContainerRules = [...context.containerRules];
1078
+ const allSupportsRules = [...context.supportsRules];
1079
+ const allLayerRules = [...context.layerRules];
1080
+ for (const item of additionalRules) {
1081
+ if (!item) {
1082
+ continue;
1083
+ }
1084
+ if (Array.isArray(item)) {
1085
+ allRules.push(...item);
1086
+ } else if ("condition" in item && "rules" in item && !("name" in item && "steps" in item)) {
1087
+ if ("type" in item) {
1088
+ allMediaRules.push(item);
1089
+ } else if ("name" in item && typeof item.name === "string") {
1090
+ allContainerRules.push(item);
1091
+ } else {
1092
+ allSupportsRules.push(item);
1093
+ }
1094
+ } else if ("name" in item && "steps" in item) {
1095
+ allKeyframes.push(item);
1096
+ } else if ("name" in item && "rules" in item) {
1097
+ allLayerRules.push(item);
1098
+ } else {
1099
+ allRules.push(item);
1100
+ }
1101
+ }
1102
+ for (const kf of allKeyframes) {
1103
+ parts.push(renderKeyframes(kf));
1104
+ }
1105
+ for (const layer2 of allLayerRules) {
1106
+ parts.push(renderLayerRule(layer2));
1107
+ }
1108
+ for (const rule of allRules) {
1109
+ parts.push(renderRule(rule));
1110
+ }
1111
+ for (const supports of allSupportsRules) {
1112
+ parts.push(renderSupportsRule(supports));
1113
+ }
1114
+ for (const container2 of allContainerRules) {
1115
+ parts.push(renderContainerRule(container2));
1116
+ }
1117
+ for (const media of allMediaRules) {
1118
+ parts.push(renderMediaRule(media));
1119
+ }
1120
+ return parts.join("\n\n");
1121
+ }
1122
+
1123
+ // src/client/style/store.ts
1124
+ var ELIT_SHARED_STYLE_STORE_KEY = "__elitSharedStyleStore__";
1125
+ function createStyleStore() {
1126
+ return {
1127
+ variables: [],
1128
+ rules: [],
1129
+ mediaRules: [],
1130
+ keyframes: [],
1131
+ fontFaces: [],
1132
+ imports: [],
1133
+ containerRules: [],
1134
+ supportsRules: [],
1135
+ layerRules: [],
1136
+ layerOrder: []
1137
+ };
1138
+ }
1139
+ function getSharedStyleStore() {
1140
+ const globalScope = globalThis;
1141
+ if (!globalScope[ELIT_SHARED_STYLE_STORE_KEY]) {
1142
+ globalScope[ELIT_SHARED_STYLE_STORE_KEY] = createStyleStore();
1143
+ }
1144
+ return globalScope[ELIT_SHARED_STYLE_STORE_KEY];
1145
+ }
1146
+
1147
+ // src/client/style/index.ts
1148
+ var CreateStyle = class {
1149
+ constructor(store) {
1150
+ this.variables = [];
1151
+ this.rules = [];
1152
+ this.mediaRules = [];
1153
+ this.keyframes = [];
1154
+ this.fontFaces = [];
1155
+ this.imports = [];
1156
+ this.containerRules = [];
1157
+ this.supportsRules = [];
1158
+ this.layerRules = [];
1159
+ this._layerOrder = [];
1160
+ this.nativeStyleResolver = new NativeStyleResolver();
1161
+ if (!store) {
1162
+ return;
1163
+ }
1164
+ this.variables = store.variables;
1165
+ this.rules = store.rules;
1166
+ this.mediaRules = store.mediaRules;
1167
+ this.keyframes = store.keyframes;
1168
+ this.fontFaces = store.fontFaces;
1169
+ this.imports = store.imports;
1170
+ this.containerRules = store.containerRules;
1171
+ this.supportsRules = store.supportsRules;
1172
+ this.layerRules = store.layerRules;
1173
+ this._layerOrder = store.layerOrder;
1174
+ }
1175
+ addVar(name, value) {
1176
+ const cssVar = {
1177
+ name: name.startsWith("--") ? name : `--${name}`,
1178
+ value,
1179
+ toString() {
1180
+ return `var(${this.name})`;
1181
+ }
1182
+ };
1183
+ this.variables.push(cssVar);
1184
+ return cssVar;
1185
+ }
1186
+ var(variable, fallback) {
1187
+ const varName = typeof variable === "string" ? variable.startsWith("--") ? variable : `--${variable}` : variable.name;
1188
+ return fallback ? `var(${varName}, ${fallback})` : `var(${varName})`;
1189
+ }
1190
+ addTag(tag, styles2) {
1191
+ const rule = { selector: tag, styles: styles2, type: "tag" };
1192
+ this.rules.push(rule);
1193
+ return rule;
1194
+ }
1195
+ addClass(name, styles2) {
1196
+ const selector = name.startsWith(".") ? name : `.${name}`;
1197
+ const rule = { selector, styles: styles2, type: "class" };
1198
+ this.rules.push(rule);
1199
+ return rule;
1200
+ }
1201
+ addId(name, styles2) {
1202
+ const selector = name.startsWith("#") ? name : `#${name}`;
1203
+ const rule = { selector, styles: styles2, type: "id" };
1204
+ this.rules.push(rule);
1205
+ return rule;
1206
+ }
1207
+ addPseudoClass(pseudo, styles2, baseSelector) {
1208
+ const pseudoClass = pseudo.startsWith(":") ? pseudo : `:${pseudo}`;
1209
+ const selector = baseSelector ? `${baseSelector}${pseudoClass}` : pseudoClass;
1210
+ const rule = { selector, styles: styles2, type: "pseudo-class" };
1211
+ this.rules.push(rule);
1212
+ return rule;
1213
+ }
1214
+ addPseudoElement(pseudo, styles2, baseSelector) {
1215
+ const pseudoElement = pseudo.startsWith("::") ? pseudo : `::${pseudo}`;
1216
+ const selector = baseSelector ? `${baseSelector}${pseudoElement}` : pseudoElement;
1217
+ const rule = { selector, styles: styles2, type: "pseudo-element" };
1218
+ this.rules.push(rule);
1219
+ return rule;
1220
+ }
1221
+ addAttribute(attr, styles2, baseSelector) {
1222
+ const attrSelector = attr.startsWith("[") ? attr : `[${attr}]`;
1223
+ const selector = baseSelector ? `${baseSelector}${attrSelector}` : attrSelector;
1224
+ const rule = { selector, styles: styles2, type: "attribute" };
1225
+ this.rules.push(rule);
1226
+ return rule;
1227
+ }
1228
+ attrEquals(attr, value, styles2, baseSelector) {
1229
+ return this.addAttribute(`${attr}="${value}"`, styles2, baseSelector);
1230
+ }
1231
+ attrContainsWord(attr, value, styles2, baseSelector) {
1232
+ return this.addAttribute(`${attr}~="${value}"`, styles2, baseSelector);
1233
+ }
1234
+ attrStartsWith(attr, value, styles2, baseSelector) {
1235
+ return this.addAttribute(`${attr}^="${value}"`, styles2, baseSelector);
1236
+ }
1237
+ attrEndsWith(attr, value, styles2, baseSelector) {
1238
+ return this.addAttribute(`${attr}$="${value}"`, styles2, baseSelector);
1239
+ }
1240
+ attrContains(attr, value, styles2, baseSelector) {
1241
+ return this.addAttribute(`${attr}*="${value}"`, styles2, baseSelector);
1242
+ }
1243
+ descendant(ancestor, descendant2, styles2) {
1244
+ return this.createAndAddRule(`${ancestor} ${descendant2}`, styles2);
1245
+ }
1246
+ child(parent, childSel, styles2) {
1247
+ return this.createAndAddRule(`${parent} > ${childSel}`, styles2);
1248
+ }
1249
+ adjacentSibling(element, sibling, styles2) {
1250
+ return this.createAndAddRule(`${element} + ${sibling}`, styles2);
1251
+ }
1252
+ generalSibling(element, sibling, styles2) {
1253
+ return this.createAndAddRule(`${element} ~ ${sibling}`, styles2);
1254
+ }
1255
+ multiple(selectors, styles2) {
1256
+ return this.createAndAddRule(selectors.join(", "), styles2);
1257
+ }
1258
+ addName(name, styles2) {
1259
+ const selector = name.startsWith("--") ? `&${name}` : `&--${name}`;
1260
+ return { selector, styles: styles2, type: "name" };
1261
+ }
1262
+ nesting(parentRule, ...childRules) {
1263
+ parentRule.nested = childRules;
1264
+ return parentRule;
1265
+ }
1266
+ keyframe(name, steps) {
1267
+ const keyframeSteps = Object.entries(steps).map(([step, styles2]) => ({
1268
+ step: step === "from" ? "from" : step === "to" ? "to" : `${step}%`,
1269
+ styles: styles2
1270
+ }));
1271
+ const kf = { name, steps: keyframeSteps };
1272
+ this.keyframes.push(kf);
1273
+ return kf;
1022
1274
  }
1023
- getAncestorCursor(ancestors, ancestorIndex) {
1024
- if (ancestorIndex < 0 || ancestorIndex >= ancestors.length) {
1025
- return void 0;
1026
- }
1027
- const ancestor = ancestors[ancestorIndex];
1028
- return {
1029
- target: ancestor,
1030
- ancestorIndex: ancestorIndex - 1,
1031
- previousSiblings: Array.isArray(ancestor.previousSiblings) ? ancestor.previousSiblings : []
1032
- };
1275
+ keyframeFromTo(name, from, to) {
1276
+ return this.keyframe(name, { from, to });
1033
1277
  }
1034
- matchesSelectorChainFromCursor(chain, chainIndex, ancestors, cursor) {
1035
- if (!this.matchesSelectorPart(cursor.target, chain[chainIndex])) {
1036
- return false;
1037
- }
1038
- if (chainIndex === 0) {
1039
- return true;
1040
- }
1041
- const combinator = chain[chainIndex].combinator ?? "descendant";
1042
- switch (combinator) {
1043
- case "child": {
1044
- const parentCursor = this.getAncestorCursor(ancestors, cursor.ancestorIndex);
1045
- return parentCursor ? this.matchesSelectorChainFromCursor(chain, chainIndex - 1, ancestors, parentCursor) : false;
1046
- }
1047
- case "adjacent-sibling": {
1048
- const siblingIndex = cursor.previousSiblings.length - 1;
1049
- if (siblingIndex < 0) {
1050
- return false;
1051
- }
1052
- return this.matchesSelectorChainFromCursor(chain, chainIndex - 1, ancestors, {
1053
- target: cursor.previousSiblings[siblingIndex],
1054
- ancestorIndex: cursor.ancestorIndex,
1055
- previousSiblings: cursor.previousSiblings.slice(0, siblingIndex)
1056
- });
1057
- }
1058
- case "general-sibling": {
1059
- for (let siblingIndex = cursor.previousSiblings.length - 1; siblingIndex >= 0; siblingIndex--) {
1060
- if (this.matchesSelectorChainFromCursor(chain, chainIndex - 1, ancestors, {
1061
- target: cursor.previousSiblings[siblingIndex],
1062
- ancestorIndex: cursor.ancestorIndex,
1063
- previousSiblings: cursor.previousSiblings.slice(0, siblingIndex)
1064
- })) {
1065
- return true;
1066
- }
1067
- }
1068
- return false;
1069
- }
1070
- case "descendant":
1071
- default: {
1072
- for (let ancestorIndex = cursor.ancestorIndex; ancestorIndex >= 0; ancestorIndex--) {
1073
- const ancestorCursor = this.getAncestorCursor(ancestors, ancestorIndex);
1074
- if (ancestorCursor && this.matchesSelectorChainFromCursor(chain, chainIndex - 1, ancestors, ancestorCursor)) {
1075
- return true;
1076
- }
1077
- }
1078
- return false;
1079
- }
1080
- }
1278
+ fontFace(options) {
1279
+ this.fontFaces.push(options);
1280
+ return options;
1081
1281
  }
1082
- parseMediaLength(value) {
1083
- const match = value.trim().match(/^(-?\d+(?:\.\d+)?)(px|rem|em)?$/i);
1084
- if (!match) {
1085
- return void 0;
1086
- }
1087
- const numericValue = Number(match[1]);
1088
- const unit = (match[2] ?? "px").toLowerCase();
1089
- if (unit === "rem" || unit === "em") {
1090
- return numericValue * 16;
1091
- }
1092
- return numericValue;
1282
+ import(url, mediaQuery) {
1283
+ const importRule = mediaQuery ? `@import url("${url}") ${mediaQuery};` : `@import url("${url}");`;
1284
+ this.imports.push(importRule);
1285
+ return importRule;
1093
1286
  }
1094
- matchesMediaCondition(condition, options) {
1095
- const normalized = condition.trim().replace(/^\(+|\)+$/g, "").trim().toLowerCase();
1096
- if (!normalized) {
1097
- return true;
1098
- }
1099
- if (normalized.startsWith("min-width:")) {
1100
- const minWidth = this.parseMediaLength(normalized.slice("min-width:".length));
1101
- return minWidth !== void 0 && options.viewportWidth !== void 0 && options.viewportWidth >= minWidth;
1102
- }
1103
- if (normalized.startsWith("max-width:")) {
1104
- const maxWidth = this.parseMediaLength(normalized.slice("max-width:".length));
1105
- return maxWidth !== void 0 && options.viewportWidth !== void 0 && options.viewportWidth <= maxWidth;
1106
- }
1107
- if (normalized === "prefers-color-scheme: dark") {
1108
- return options.colorScheme === "dark";
1109
- }
1110
- if (normalized === "prefers-color-scheme: light") {
1111
- return (options.colorScheme ?? "light") === "light";
1112
- }
1113
- if (normalized === "prefers-reduced-motion: reduce") {
1114
- return options.reducedMotion === true;
1115
- }
1116
- return false;
1287
+ media(type, condition, rules) {
1288
+ const mediaRule = { type, condition, rules: this.rulesToCSSRules(rules) };
1289
+ this.mediaRules.push(mediaRule);
1290
+ return mediaRule;
1117
1291
  }
1118
- matchesMediaRule(rule, options) {
1119
- const mediaType = options.mediaType ?? "screen";
1120
- if (rule.type && rule.type !== mediaType && rule.type !== "all") {
1121
- return false;
1122
- }
1123
- if (!rule.condition.trim()) {
1124
- return true;
1125
- }
1126
- return rule.condition.split(/\band\b/i).map((part) => part.trim()).filter(Boolean).every((part) => this.matchesMediaCondition(part, options));
1292
+ mediaScreen(condition, rules) {
1293
+ return this.media("screen", condition, rules);
1127
1294
  }
1128
- getOrderedLayerNames() {
1129
- const orderedLayerNames = [];
1130
- for (const layerName of this._layerOrder) {
1131
- const normalizedName = layerName.trim();
1132
- if (normalizedName && !orderedLayerNames.includes(normalizedName)) {
1133
- orderedLayerNames.push(normalizedName);
1134
- }
1135
- }
1136
- for (const layerRule of this.layerRules) {
1137
- const normalizedName = layerRule.name.trim();
1138
- if (normalizedName && !orderedLayerNames.includes(normalizedName)) {
1139
- orderedLayerNames.push(normalizedName);
1140
- }
1141
- }
1142
- return orderedLayerNames;
1295
+ mediaPrint(rules) {
1296
+ return this.media("print", "", rules);
1143
1297
  }
1144
- resolveNativeStyles(target, ancestors = [], options = {}) {
1145
- return this.withNativeTargetNormalizationCache(() => {
1146
- const normalizedTarget = this.normalizeTarget(target);
1147
- if (!normalizedTarget.tagName && (!normalizedTarget.classNames || normalizedTarget.classNames.length === 0)) {
1148
- return {};
1149
- }
1150
- const normalizedAncestors = ancestors.map((ancestor) => this.normalizeTarget(ancestor));
1151
- const variables = this.getVariables();
1152
- const resolved = {};
1153
- const applyRules = (rules) => {
1154
- for (const rule of rules) {
1155
- const selectorChains = this.extractSupportedSelectorChains(rule.selector);
1156
- if (selectorChains.length === 0) {
1157
- continue;
1158
- }
1159
- const matches = selectorChains.some((selectorChain) => this.matchesSelectorChain(normalizedTarget, normalizedAncestors, selectorChain));
1160
- if (!matches) {
1161
- continue;
1162
- }
1163
- for (const [property, value] of Object.entries(rule.styles)) {
1164
- resolved[property] = typeof value === "string" ? this.resolveVariableReferences(value, variables) : value;
1165
- }
1166
- }
1167
- };
1168
- for (const layerName of this.getOrderedLayerNames()) {
1169
- for (const layerRule of this.layerRules) {
1170
- if (layerRule.name.trim() === layerName) {
1171
- applyRules(layerRule.rules);
1172
- }
1173
- }
1174
- }
1175
- applyRules(this.rules);
1176
- for (const supportsRule of this.supportsRules) {
1177
- if (this.matchesSupportsCondition(supportsRule.condition)) {
1178
- applyRules(supportsRule.rules);
1179
- }
1180
- }
1181
- for (const containerRule of this.containerRules) {
1182
- const matchingContainer = this.findMatchingContainerTarget(normalizedAncestors, containerRule.name);
1183
- if (matchingContainer && this.matchesContainerCondition(containerRule.condition, matchingContainer.containerWidth)) {
1184
- applyRules(containerRule.rules);
1185
- }
1186
- }
1187
- for (const mediaRule of this.mediaRules) {
1188
- if (this.matchesMediaRule(mediaRule, options)) {
1189
- applyRules(mediaRule.rules);
1190
- }
1191
- }
1192
- return resolved;
1193
- });
1298
+ mediaMinWidth(minWidth, rules) {
1299
+ return this.media("screen", `min-width: ${minWidth}`, rules);
1194
1300
  }
1195
- resolveClassStyles(classNames) {
1196
- return this.resolveNativeStyles({ classNames });
1301
+ mediaMaxWidth(maxWidth, rules) {
1302
+ return this.media("screen", `max-width: ${maxWidth}`, rules);
1197
1303
  }
1198
- // Utility Methods
1199
- toKebabCase(str) {
1200
- return str.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
1304
+ mediaDark(rules) {
1305
+ const mediaRule = { type: "", condition: "prefers-color-scheme: dark", rules: this.rulesToCSSRules(rules) };
1306
+ this.mediaRules.push(mediaRule);
1307
+ return mediaRule;
1201
1308
  }
1202
- // Helper: Create and add rule (eliminates duplication in combinator selectors)
1203
- createAndAddRule(selector, styles2, type = "custom") {
1204
- const rule = { selector, styles: styles2, type };
1205
- this.rules.push(rule);
1206
- return rule;
1309
+ mediaLight(rules) {
1310
+ const mediaRule = { type: "", condition: "prefers-color-scheme: light", rules: this.rulesToCSSRules(rules) };
1311
+ this.mediaRules.push(mediaRule);
1312
+ return mediaRule;
1207
1313
  }
1208
- // Helper: Convert rules object to CSSRule array (eliminates duplication in media/container/supports/layer)
1209
- rulesToCSSRules(rules) {
1210
- return Object.entries(rules).map(([selector, styles2]) => ({
1211
- selector,
1212
- styles: styles2,
1213
- type: "custom"
1214
- }));
1314
+ mediaReducedMotion(rules) {
1315
+ const mediaRule = { type: "", condition: "prefers-reduced-motion: reduce", rules: this.rulesToCSSRules(rules) };
1316
+ this.mediaRules.push(mediaRule);
1317
+ return mediaRule;
1215
1318
  }
1216
- // Helper: Render rules with indentation (eliminates duplication in render methods)
1217
- renderRulesWithIndent(rules, indent = " ") {
1218
- return rules.map((rule) => this.renderRule(rule, indent)).join("\n");
1319
+ container(condition, rules, name) {
1320
+ const containerRule = { name, condition, rules: this.rulesToCSSRules(rules) };
1321
+ this.containerRules.push(containerRule);
1322
+ return containerRule;
1219
1323
  }
1220
- stylesToString(styles2, indent = " ") {
1221
- return Object.entries(styles2).map(([prop, value]) => {
1222
- const cssValue = typeof value === "object" && value !== null && "name" in value ? `var(${value.name})` : value;
1223
- return `${indent}${this.toKebabCase(prop)}: ${cssValue};`;
1224
- }).join("\n");
1324
+ addContainer(name, styles2) {
1325
+ const containerStyles = { ...styles2, containerName: name };
1326
+ return this.addClass(name, containerStyles);
1225
1327
  }
1226
- renderRule(rule, indent = "") {
1227
- let css = `${indent}${rule.selector} {
1228
- ${this.stylesToString(rule.styles, indent + " ")}
1229
- `;
1230
- if (rule.nested && rule.nested.length > 0) {
1231
- for (const nestedRule of rule.nested) {
1232
- const nestedSelector = nestedRule.selector.startsWith("&") ? nestedRule.selector.replace(/&/g, rule.selector) : `${rule.selector} ${nestedRule.selector}`;
1233
- css += `
1234
- ${indent}${nestedSelector} {
1235
- ${this.stylesToString(nestedRule.styles, indent + " ")}
1236
- ${indent}}
1237
- `;
1238
- }
1239
- }
1240
- css += `${indent}}`;
1241
- return css;
1328
+ supports(condition, rules) {
1329
+ const supportsRule = { condition, rules: this.rulesToCSSRules(rules) };
1330
+ this.supportsRules.push(supportsRule);
1331
+ return supportsRule;
1242
1332
  }
1243
- renderMediaRule(media) {
1244
- const condition = media.type && media.condition ? `${media.type} and (${media.condition})` : media.type ? media.type : `(${media.condition})`;
1245
- return `@media ${condition} {
1246
- ${this.renderRulesWithIndent(media.rules)}
1247
- }`;
1333
+ layerOrder(...layers) {
1334
+ this._layerOrder = layers;
1248
1335
  }
1249
- renderKeyframes(kf) {
1250
- let css = `@keyframes ${kf.name} {
1251
- `;
1252
- for (const step of kf.steps) {
1253
- css += ` ${step.step} {
1254
- ${this.stylesToString(step.styles, " ")}
1255
- }
1256
- `;
1257
- }
1258
- css += "}";
1259
- return css;
1336
+ layer(name, rules) {
1337
+ const layerRule = { name, rules: this.rulesToCSSRules(rules) };
1338
+ this.layerRules.push(layerRule);
1339
+ return layerRule;
1260
1340
  }
1261
- renderFontFace(ff) {
1262
- let css = "@font-face {\n";
1263
- css += ` font-family: "${ff.fontFamily}";
1264
- `;
1265
- css += ` src: ${ff.src};
1266
- `;
1267
- if (ff.fontWeight) css += ` font-weight: ${ff.fontWeight};
1268
- `;
1269
- if (ff.fontStyle) css += ` font-style: ${ff.fontStyle};
1270
- `;
1271
- if (ff.fontDisplay) css += ` font-display: ${ff.fontDisplay};
1272
- `;
1273
- if (ff.unicodeRange) css += ` unicode-range: ${ff.unicodeRange};
1274
- `;
1275
- css += "}";
1276
- return css;
1341
+ add(rules) {
1342
+ return Object.entries(rules).map(([selector, styles2]) => {
1343
+ const rule = { selector, styles: styles2, type: "custom" };
1344
+ this.rules.push(rule);
1345
+ return rule;
1346
+ });
1277
1347
  }
1278
- renderContainerRule(container2) {
1279
- const nameStr = container2.name ? `${container2.name} ` : "";
1280
- return `@container ${nameStr}(${container2.condition}) {
1281
- ${this.renderRulesWithIndent(container2.rules)}
1282
- }`;
1348
+ important(value) {
1349
+ return `${value} !important`;
1283
1350
  }
1284
- renderSupportsRule(supports) {
1285
- return `@supports (${supports.condition}) {
1286
- ${this.renderRulesWithIndent(supports.rules)}
1287
- }`;
1351
+ getVariables() {
1352
+ return Object.fromEntries(this.variables.map((variable) => [variable.name, variable.value]));
1288
1353
  }
1289
- renderLayerRule(layer2) {
1290
- return `@layer ${layer2.name} {
1291
- ${this.renderRulesWithIndent(layer2.rules)}
1292
- }`;
1354
+ resolveNativeStyles(target, ancestors = [], options = {}) {
1355
+ return this.nativeStyleResolver.resolveNativeStyles(target, ancestors, options, this.getResolverContext());
1356
+ }
1357
+ resolveClassStyles(classNames) {
1358
+ return this.nativeStyleResolver.resolveClassStyles(classNames, this.getResolverContext());
1293
1359
  }
1294
- // Render Output
1295
1360
  render(...additionalRules) {
1296
- const parts = [];
1297
- if (this.imports.length > 0) {
1298
- parts.push(this.imports.join("\n"));
1299
- }
1300
- if (this._layerOrder.length > 0) {
1301
- parts.push(`@layer ${this._layerOrder.join(", ")};`);
1302
- }
1303
- if (this.variables.length > 0) {
1304
- const varDeclarations = this.variables.map((v) => ` ${v.name}: ${v.value};`).join("\n");
1305
- parts.push(`:root {
1306
- ${varDeclarations}
1307
- }`);
1308
- }
1309
- for (const ff of this.fontFaces) {
1310
- parts.push(this.renderFontFace(ff));
1311
- }
1312
- for (const kf of this.keyframes) {
1313
- parts.push(this.renderKeyframes(kf));
1314
- }
1315
- const allRules = [...this.rules];
1316
- const allMediaRules = [...this.mediaRules];
1317
- const allKeyframes = [];
1318
- const allContainerRules = [...this.containerRules];
1319
- const allSupportsRules = [...this.supportsRules];
1320
- const allLayerRules = [...this.layerRules];
1321
- for (const item of additionalRules) {
1322
- if (!item) continue;
1323
- if (Array.isArray(item)) {
1324
- allRules.push(...item);
1325
- } else if ("condition" in item && "rules" in item && !("name" in item && "steps" in item)) {
1326
- if ("type" in item) {
1327
- allMediaRules.push(item);
1328
- } else if ("name" in item && typeof item.name === "string") {
1329
- allContainerRules.push(item);
1330
- } else {
1331
- allSupportsRules.push(item);
1332
- }
1333
- } else if ("name" in item && "steps" in item) {
1334
- allKeyframes.push(item);
1335
- } else if ("name" in item && "rules" in item) {
1336
- allLayerRules.push(item);
1337
- } else {
1338
- allRules.push(item);
1339
- }
1340
- }
1341
- for (const kf of allKeyframes) {
1342
- parts.push(this.renderKeyframes(kf));
1343
- }
1344
- for (const layer2 of allLayerRules) {
1345
- parts.push(this.renderLayerRule(layer2));
1346
- }
1347
- for (const rule of allRules) {
1348
- parts.push(this.renderRule(rule));
1349
- }
1350
- for (const supports of allSupportsRules) {
1351
- parts.push(this.renderSupportsRule(supports));
1352
- }
1353
- for (const container2 of allContainerRules) {
1354
- parts.push(this.renderContainerRule(container2));
1355
- }
1356
- for (const media of allMediaRules) {
1357
- parts.push(this.renderMediaRule(media));
1358
- }
1359
- return parts.join("\n\n");
1361
+ return renderStyleSheet(this.getRenderContext(), ...additionalRules);
1360
1362
  }
1361
1363
  inject(styleId) {
1362
1364
  const css = this.render();
1363
1365
  const style = document.createElement("style");
1364
- if (styleId) style.id = styleId;
1366
+ if (styleId) {
1367
+ style.id = styleId;
1368
+ }
1365
1369
  style.textContent = css;
1366
1370
  document.head.appendChild(style);
1367
1371
  return style;
@@ -1378,6 +1382,43 @@ ${varDeclarations}
1378
1382
  this.layerRules.length = 0;
1379
1383
  this._layerOrder.length = 0;
1380
1384
  }
1385
+ getResolverContext() {
1386
+ return {
1387
+ variables: this.getVariables(),
1388
+ rules: this.rules,
1389
+ mediaRules: this.mediaRules,
1390
+ containerRules: this.containerRules,
1391
+ supportsRules: this.supportsRules,
1392
+ layerRules: this.layerRules,
1393
+ layerOrder: this._layerOrder
1394
+ };
1395
+ }
1396
+ getRenderContext() {
1397
+ return {
1398
+ imports: this.imports,
1399
+ layerOrder: this._layerOrder,
1400
+ variables: this.variables,
1401
+ fontFaces: this.fontFaces,
1402
+ keyframes: this.keyframes,
1403
+ rules: this.rules,
1404
+ mediaRules: this.mediaRules,
1405
+ containerRules: this.containerRules,
1406
+ supportsRules: this.supportsRules,
1407
+ layerRules: this.layerRules
1408
+ };
1409
+ }
1410
+ createAndAddRule(selector, styles2, type = "custom") {
1411
+ const rule = { selector, styles: styles2, type };
1412
+ this.rules.push(rule);
1413
+ return rule;
1414
+ }
1415
+ rulesToCSSRules(rules) {
1416
+ return Object.entries(rules).map(([selector, styles2]) => ({
1417
+ selector,
1418
+ styles: styles2,
1419
+ type: "custom"
1420
+ }));
1421
+ }
1381
1422
  };
1382
1423
  var styles = new CreateStyle(getSharedStyleStore());
1383
1424
  var {
@@ -1421,6 +1462,7 @@ var {
1421
1462
  add: addStyle,
1422
1463
  important,
1423
1464
  getVariables: getStyleVariables,
1465
+ resolveNativeStyles,
1424
1466
  resolveClassStyles,
1425
1467
  render: renderStyle,
1426
1468
  inject: injectStyle,
@@ -1473,6 +1515,7 @@ var style_default = styles;
1473
1515
  nesting,
1474
1516
  renderStyle,
1475
1517
  resolveClassStyles,
1518
+ resolveNativeStyles,
1476
1519
  styles,
1477
1520
  supportsStyle
1478
1521
  });