@stacksjs/stx 0.2.111 → 0.2.113

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.
@@ -14,9 +14,6 @@
14
14
  * @returns Processed template with scoped styles
15
15
  */
16
16
  export declare function processScopedStyles(template: string, filePath: string): ScopedStyleResult;
17
- /**
18
- * Result of processing scoped styles in a template
19
- */
20
17
  export declare interface ScopedStyleResult {
21
18
  html: string
22
19
  hasScoped: boolean
@@ -1,14 +1,15 @@
1
1
  import { generateComponentId, scopeCss } from "./web-components/css-scoping.js";
2
+ const SCOPED_STYLE_ATTR = String.raw`(?<![\w-])scoped(?![\w-])`, SCOPED_STYLE_PROBE = new RegExp(`<style\\s+[^>]*${SCOPED_STYLE_ATTR}`, "i");
2
3
  export function processScopedStyles(template, filePath) {
3
- if (!/<style\s+[^>]*\bscoped\b/i.test(template))
4
+ if (!SCOPED_STYLE_PROBE.test(template))
4
5
  return { html: template, hasScoped: !1 };
5
6
  const componentId = generateComponentId(filePath), scopeAttr = `data-v-${componentId}`;
6
7
  let output = template;
7
- const scopedStyleRegex = /<style\s+([^>]*\bscoped\b[^>]*)>([\s\S]*?)<\/style>/gi;
8
+ const scopedStyleRegex = new RegExp(`<style\\s+([^>]*${SCOPED_STYLE_ATTR}[^>]*)>([\\s\\S]*?)</style>`, "gi");
8
9
  let hasScoped = !1;
9
10
  output = output.replace(scopedStyleRegex, (_match, attrs, cssContent) => {
10
11
  hasScoped = !0;
11
- const scopedCss = scopeCssWithAttribute(cssContent, scopeAttr), cleanAttrs = attrs.replace(/\bscoped\b/gi, "").trim(), attrStr = cleanAttrs ? ` ${cleanAttrs}` : "";
12
+ const scopedCss = scopeCssWithAttribute(cssContent, scopeAttr), cleanAttrs = attrs.replace(new RegExp(SCOPED_STYLE_ATTR, "gi"), "").trim(), attrStr = cleanAttrs ? ` ${cleanAttrs}` : "";
12
13
  return `<style data-stx-scoped="${componentId}"${attrStr}>${scopedCss}</style>`;
13
14
  });
14
15
  if (!hasScoped)
@@ -396,7 +396,7 @@ export async function extractVariables(scriptContent, context, filePath, options
396
396
  removeEventListener: () => {}
397
397
  }, mockConsole = console;
398
398
  try {
399
- const convertedScript = convertToCommonJS(jsContent, filePath), propsKeys = new Set(Object.keys(propsObj)), filteredContextKeys = Object.keys(context).filter((key) => !propsKeys.has(key) && key !== "props"), filteredContextValues = filteredContextKeys.map((key) => context[key]), jsReserved = new Set([
399
+ const convertedScript = convertToCommonJS(jsContent, filePath), propsKeys = new Set(Object.keys(propsObj)), isIdentifier = (key) => /^[a-z_$][\w$]*$/i.test(key), filteredContextKeys = Object.keys(context).filter((key) => !propsKeys.has(key) && key !== "props" && isIdentifier(key)), filteredContextValues = filteredContextKeys.map((key) => context[key]), jsReserved = new Set([
400
400
  "break",
401
401
  "case",
402
402
  "catch",
@@ -137,9 +137,42 @@ function scopeSelector(selector, componentId, prefix, preserveHost) {
137
137
  }
138
138
  const fullPrefix = prefix ? `${prefix} .${componentId}` : `.${componentId}`;
139
139
  scopedSelectors.push(`${fullPrefix} ${sel}`);
140
+ const rootScoped = scopeFirstCompound(sel, componentId);
141
+ if (rootScoped)
142
+ scopedSelectors.push(prefix ? `${prefix} ${rootScoped}` : rootScoped);
140
143
  }
141
144
  return scopedSelectors.join(", ");
142
145
  }
146
+ function scopeFirstCompound(selector, componentId) {
147
+ let depth = 0, end = selector.length;
148
+ for (let i = 0;i < selector.length; i++) {
149
+ const ch = selector[i];
150
+ if (ch === "[" || ch === "(")
151
+ depth++;
152
+ else if (ch === "]" || ch === ")")
153
+ depth--;
154
+ else if (depth === 0 && (ch === " " || ch === ">" || ch === "+" || ch === "~")) {
155
+ end = i;
156
+ break;
157
+ }
158
+ }
159
+ const compound = selector.slice(0, end), rest = selector.slice(end);
160
+ if (!compound)
161
+ return "";
162
+ let insertAt = compound.length, pdepth = 0;
163
+ for (let i = 0;i < compound.length; i++) {
164
+ const ch = compound[i];
165
+ if (ch === "[" || ch === "(")
166
+ pdepth++;
167
+ else if (ch === "]" || ch === ")")
168
+ pdepth--;
169
+ else if (depth === 0 && pdepth === 0 && ch === ":") {
170
+ insertAt = i;
171
+ break;
172
+ }
173
+ }
174
+ return `${compound.slice(0, insertAt)}.${componentId}${compound.slice(insertAt)}${rest}`;
175
+ }
143
176
  export function extractStyleFromTemplate(template) {
144
177
  const styleMatch = template.match(/<style\b[^>]*>([\s\S]*?)<\/style>/i), css = styleMatch ? styleMatch[1] : "", templateWithoutStyle = styleMatch ? template.replace(/<style\b[^>]*>[\s\S]*?<\/style>/i, "") : template;
145
178
  return { css, templateWithoutStyle };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/stx",
3
3
  "type": "module",
4
- "version": "0.2.111",
4
+ "version": "0.2.113",
5
5
  "description": "A performant UI Framework. Powered by Bun.",
6
6
  "author": "Chris Breuer <chris@stacksjs.org>",
7
7
  "license": "MIT",
@@ -115,18 +115,18 @@
115
115
  "typecheck": "bun tsc -p tsconfig.src.json --noEmit"
116
116
  },
117
117
  "dependencies": {
118
- "@cwcss/crosswind": "^0.2.6",
118
+ "@cwcss/crosswind": "^0.2.12",
119
119
  "@stacksjs/clapp": "^0.2.0",
120
- "@stacksjs/sanitizer": "0.2.111",
120
+ "@stacksjs/sanitizer": "0.2.113",
121
121
  "@stacksjs/ts-i18n": "^0.1.11",
122
- "bun-plugin-stx": "0.2.111",
122
+ "bun-plugin-stx": "0.2.113",
123
123
  "bunfig": "^0.15.15",
124
- "stx-router": "0.2.111",
124
+ "stx-router": "0.2.113",
125
125
  "ts-broadcasting": "^0.0.9",
126
126
  "ts-images": "^0.1.9",
127
127
  "ts-syntax-highlighter": "^0.2.1"
128
128
  },
129
129
  "optionalDependencies": {
130
- "@stacksjs/desktop": "0.2.111"
130
+ "@stacksjs/desktop": "0.2.113"
131
131
  }
132
132
  }