boss-css 0.0.1 → 0.0.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.
- package/README.md +1 -0
- package/dist/_virtual/rolldown_runtime.cjs +43 -0
- package/dist/_virtual/rolldown_runtime.mjs +20 -0
- package/dist/api/browser.cjs +54 -0
- package/dist/api/browser.mjs +48 -0
- package/dist/api/config.cjs +94 -0
- package/dist/api/config.mjs +91 -0
- package/dist/api/css.cjs +304 -0
- package/dist/api/css.mjs +303 -0
- package/dist/api/dictionary.cjs +218 -0
- package/dist/api/dictionary.mjs +215 -0
- package/dist/api/file/dts.cjs +21 -0
- package/dist/api/file/dts.mjs +21 -0
- package/dist/api/file/file.cjs +123 -0
- package/dist/api/file/file.mjs +120 -0
- package/dist/api/file/js.cjs +118 -0
- package/dist/api/file/js.mjs +116 -0
- package/dist/api/names.cjs +52 -0
- package/dist/api/names.mjs +46 -0
- package/dist/api/noopCss.cjs +37 -0
- package/dist/api/noopCss.mjs +36 -0
- package/dist/api/propTree.cjs +54 -0
- package/dist/api/propTree.mjs +48 -0
- package/dist/api/server.cjs +112 -0
- package/dist/api/server.mjs +106 -0
- package/dist/cli/build.cjs +1 -0
- package/dist/cli/build.mjs +3 -0
- package/dist/cli/index.cjs +30 -0
- package/dist/cli/index.mjs +29 -0
- package/dist/cli/tasks/build.cjs +24 -0
- package/dist/cli/tasks/build.mjs +23 -0
- package/dist/cli/tasks/choose.cjs +47 -0
- package/dist/cli/tasks/choose.mjs +46 -0
- package/dist/cli/tasks/compile.cjs +68 -0
- package/dist/cli/tasks/compile.mjs +67 -0
- package/dist/cli/tasks/dev.cjs +51 -0
- package/dist/cli/tasks/dev.mjs +48 -0
- package/dist/cli/tasks/init.cjs +1835 -0
- package/dist/cli/tasks/init.mjs +1831 -0
- package/dist/cli/tasks/watch.cjs +38 -0
- package/dist/cli/tasks/watch.mjs +37 -0
- package/dist/cli/templates/init.cjs +82 -0
- package/dist/cli/templates/init.mjs +78 -0
- package/dist/cli/types.cjs +13 -0
- package/dist/cli/types.mjs +13 -0
- package/dist/cli/utils.cjs +43 -0
- package/dist/cli/utils.mjs +41 -0
- package/dist/compile/classname-strategy.cjs +79 -0
- package/dist/compile/classname-strategy.mjs +77 -0
- package/dist/compile/classname.cjs +366 -0
- package/dist/compile/classname.mjs +360 -0
- package/dist/compile/index.cjs +238 -0
- package/dist/compile/index.mjs +235 -0
- package/dist/compile/jsx.cjs +803 -0
- package/dist/compile/jsx.mjs +800 -0
- package/dist/compile/prepared.cjs +88 -0
- package/dist/compile/prepared.mjs +87 -0
- package/dist/compile/runtime.cjs +33 -0
- package/dist/compile/runtime.mjs +32 -0
- package/dist/compile/transform.cjs +371 -0
- package/dist/compile/transform.mjs +369 -0
- package/dist/cx/index.cjs +93 -0
- package/dist/cx/index.mjs +85 -0
- package/dist/detect-fw/index.cjs +384 -0
- package/dist/detect-fw/index.mjs +379 -0
- package/dist/dev/client.cjs +39 -0
- package/dist/dev/client.mjs +38 -0
- package/dist/dev/plugin/browser.cjs +11 -0
- package/dist/dev/plugin/browser.mjs +9 -0
- package/dist/dev/plugin/server.cjs +86 -0
- package/dist/dev/plugin/server.mjs +78 -0
- package/dist/dev/port.cjs +46 -0
- package/dist/dev/port.mjs +43 -0
- package/dist/dev/runtime.cjs +28 -0
- package/dist/dev/runtime.mjs +29 -0
- package/dist/dev/server.cjs +808 -0
- package/dist/dev/server.mjs +805 -0
- package/dist/dev/shared.cjs +6 -0
- package/dist/dev/shared.mjs +5 -0
- package/dist/eslint-plugin/index.cjs +66 -0
- package/dist/eslint-plugin/index.mjs +66 -0
- package/dist/eslint-plugin/rules/classnames-only.cjs +68 -0
- package/dist/eslint-plugin/rules/classnames-only.mjs +68 -0
- package/dist/eslint-plugin/rules/format-classnames.cjs +137 -0
- package/dist/eslint-plugin/rules/format-classnames.mjs +136 -0
- package/dist/eslint-plugin/rules/no-unknown-classes.cjs +119 -0
- package/dist/eslint-plugin/rules/no-unknown-classes.mjs +119 -0
- package/dist/eslint-plugin/rules/prefer-classnames.cjs +69 -0
- package/dist/eslint-plugin/rules/prefer-classnames.mjs +69 -0
- package/dist/eslint-plugin/rules/prefer-token-values.cjs +197 -0
- package/dist/eslint-plugin/rules/prefer-token-values.mjs +197 -0
- package/dist/eslint-plugin/rules/props-only.cjs +115 -0
- package/dist/eslint-plugin/rules/props-only.mjs +115 -0
- package/dist/eslint-plugin/rules/redundant-cx.cjs +66 -0
- package/dist/eslint-plugin/rules/redundant-cx.mjs +66 -0
- package/dist/eslint-plugin/rules/require-prop-functions.cjs +130 -0
- package/dist/eslint-plugin/rules/require-prop-functions.mjs +130 -0
- package/dist/eslint-plugin/utils/api.cjs +30 -0
- package/dist/eslint-plugin/utils/api.mjs +29 -0
- package/dist/eslint-plugin/utils/ast.cjs +119 -0
- package/dist/eslint-plugin/utils/ast.mjs +112 -0
- package/dist/eslint-plugin/utils/boss-classes.cjs +185 -0
- package/dist/eslint-plugin/utils/boss-classes.mjs +175 -0
- package/dist/eslint-plugin/utils/defaults.cjs +99 -0
- package/dist/eslint-plugin/utils/defaults.mjs +93 -0
- package/dist/eslint-plugin/utils/format.cjs +20 -0
- package/dist/eslint-plugin/utils/format.mjs +19 -0
- package/dist/eslint-plugin/utils/order.cjs +76 -0
- package/dist/eslint-plugin/utils/order.mjs +76 -0
- package/dist/eslint-plugin/utils/property-order.cjs +449 -0
- package/dist/eslint-plugin/utils/property-order.mjs +448 -0
- package/dist/eslint-plugin/utils/static.cjs +36 -0
- package/dist/eslint-plugin/utils/static.mjs +35 -0
- package/dist/fontsource/directory.cjs +39588 -0
- package/dist/fontsource/directory.mjs +39587 -0
- package/dist/fontsource/server.cjs +291 -0
- package/dist/fontsource/server.mjs +282 -0
- package/dist/index.cjs +10 -0
- package/dist/index.mjs +6 -0
- package/dist/log/browser.cjs +28 -0
- package/dist/log/browser.mjs +28 -0
- package/dist/log/server.cjs +32 -0
- package/dist/log/server.mjs +30 -0
- package/dist/merge/index.cjs +590 -0
- package/dist/merge/index.mjs +586 -0
- package/dist/native/browser.cjs +78 -0
- package/dist/native/browser.mjs +77 -0
- package/dist/native/server.cjs +180 -0
- package/dist/native/server.mjs +176 -0
- package/dist/native/styleTypes.cjs +168 -0
- package/dist/native/styleTypes.mjs +164 -0
- package/dist/parser/classname/server.cjs +239 -0
- package/dist/parser/classname/server.mjs +232 -0
- package/dist/parser/jsx/browser.cjs +66 -0
- package/dist/parser/jsx/browser.mjs +63 -0
- package/dist/parser/jsx/extractCode.cjs +99 -0
- package/dist/parser/jsx/extractCode.mjs +98 -0
- package/dist/parser/jsx/extractPrepared.cjs +123 -0
- package/dist/parser/jsx/extractPrepared.mjs +122 -0
- package/dist/parser/jsx/extractProps.cjs +234 -0
- package/dist/parser/jsx/extractProps.mjs +232 -0
- package/dist/parser/jsx/isDOMProp.cjs +17 -0
- package/dist/parser/jsx/isDOMProp.mjs +15 -0
- package/dist/parser/jsx/native.cjs +110 -0
- package/dist/parser/jsx/native.mjs +108 -0
- package/dist/parser/jsx/runtime.cjs +4 -0
- package/dist/parser/jsx/runtime.mjs +3 -0
- package/dist/parser/jsx/server.cjs +278 -0
- package/dist/parser/jsx/server.mjs +268 -0
- package/dist/postcss/index.cjs +16 -0
- package/dist/postcss/index.mjs +16 -0
- package/dist/prop/at/runtime-only.cjs +90 -0
- package/dist/prop/at/runtime-only.mjs +88 -0
- package/dist/prop/at/server.cjs +282 -0
- package/dist/prop/at/server.mjs +268 -0
- package/dist/prop/at/shared.cjs +153 -0
- package/dist/prop/at/shared.mjs +144 -0
- package/dist/prop/bosswind/browser.cjs +18 -0
- package/dist/prop/bosswind/browser.mjs +16 -0
- package/dist/prop/bosswind/runtime-only.cjs +18 -0
- package/dist/prop/bosswind/runtime-only.mjs +16 -0
- package/dist/prop/bosswind/server.cjs +81 -0
- package/dist/prop/bosswind/server.mjs +72 -0
- package/dist/prop/bosswind/shared.cjs +861 -0
- package/dist/prop/bosswind/shared.mjs +855 -0
- package/dist/prop/bosswind/tailwind-theme.cjs +703 -0
- package/dist/prop/bosswind/tailwind-theme.mjs +702 -0
- package/dist/prop/child/runtime-only.cjs +18 -0
- package/dist/prop/child/runtime-only.mjs +15 -0
- package/dist/prop/child/server.cjs +81 -0
- package/dist/prop/child/server.mjs +72 -0
- package/dist/prop/css/getDtsTemplate.cjs +65 -0
- package/dist/prop/css/getDtsTemplate.mjs +63 -0
- package/dist/prop/css/runtime-only.cjs +14 -0
- package/dist/prop/css/runtime-only.mjs +13 -0
- package/dist/prop/css/server.cjs +99 -0
- package/dist/prop/css/server.mjs +90 -0
- package/dist/prop/pseudo/runtime-only.cjs +23 -0
- package/dist/prop/pseudo/runtime-only.mjs +21 -0
- package/dist/prop/pseudo/server.cjs +91 -0
- package/dist/prop/pseudo/server.mjs +82 -0
- package/dist/prop/pseudo/shared.cjs +61 -0
- package/dist/prop/pseudo/shared.mjs +60 -0
- package/dist/reset/server.cjs +34 -0
- package/dist/reset/server.mjs +26 -0
- package/dist/runtime/index.cjs +119 -0
- package/dist/runtime/index.mjs +118 -0
- package/dist/runtime/preact.cjs +4 -0
- package/dist/runtime/preact.mjs +3 -0
- package/dist/runtime/qwik.cjs +21 -0
- package/dist/runtime/qwik.mjs +18 -0
- package/dist/runtime/react.cjs +4 -0
- package/dist/runtime/react.mjs +3 -0
- package/dist/runtime/solid.cjs +15 -0
- package/dist/runtime/solid.mjs +14 -0
- package/dist/runtime/stencil.cjs +25 -0
- package/dist/runtime/stencil.mjs +21 -0
- package/dist/runtime/style.cjs +14 -0
- package/dist/runtime/style.mjs +13 -0
- package/dist/shared/boundaries.cjs +288 -0
- package/dist/shared/boundaries.mjs +285 -0
- package/dist/shared/customCss.cjs +212 -0
- package/dist/shared/customCss.mjs +211 -0
- package/dist/shared/debug.cjs +76 -0
- package/dist/shared/debug.mjs +74 -0
- package/dist/shared/file.cjs +21 -0
- package/dist/shared/file.mjs +19 -0
- package/dist/shared/framework.cjs +10 -0
- package/dist/shared/framework.mjs +9 -0
- package/dist/shared/json.cjs +58 -0
- package/dist/shared/json.mjs +57 -0
- package/dist/shared/types.cjs +11 -0
- package/dist/shared/types.mjs +10 -0
- package/dist/strategy/classic/runtime-only.cjs +190 -0
- package/dist/strategy/classic/runtime-only.mjs +186 -0
- package/dist/strategy/classname-first/runtime-only.cjs +138 -0
- package/dist/strategy/classname-first/runtime-only.mjs +134 -0
- package/dist/strategy/classname-first/server.cjs +139 -0
- package/dist/strategy/classname-first/server.mjs +133 -0
- package/dist/strategy/classname-only/server.cjs +43 -0
- package/dist/strategy/classname-only/server.mjs +35 -0
- package/dist/strategy/inline-first/browser.cjs +61 -0
- package/dist/strategy/inline-first/browser.mjs +58 -0
- package/dist/strategy/inline-first/runtime-only.cjs +159 -0
- package/dist/strategy/inline-first/runtime-only.mjs +155 -0
- package/dist/strategy/inline-first/server.cjs +92 -0
- package/dist/strategy/inline-first/server.mjs +83 -0
- package/dist/strategy/runtime/runtime-only.cjs +24 -0
- package/dist/strategy/runtime/runtime-only.mjs +22 -0
- package/dist/strategy/runtime/server.cjs +72 -0
- package/dist/strategy/runtime/server.mjs +63 -0
- package/dist/strategy/runtime-only/css.cjs +183 -0
- package/dist/strategy/runtime-only/css.mjs +181 -0
- package/dist/tasks/build.cjs +88 -0
- package/dist/tasks/build.mjs +84 -0
- package/dist/tasks/compile.cjs +12 -0
- package/dist/tasks/compile.mjs +12 -0
- package/dist/tasks/postcss.cjs +116 -0
- package/dist/tasks/postcss.mjs +113 -0
- package/dist/tasks/session.cjs +46 -0
- package/dist/tasks/session.mjs +42 -0
- package/dist/tasks/watch.cjs +102 -0
- package/dist/tasks/watch.mjs +99 -0
- package/dist/transform/cache.cjs +24 -0
- package/dist/transform/cache.mjs +21 -0
- package/dist/transform/processFile.cjs +26 -0
- package/dist/transform/processFile.mjs +24 -0
- package/dist/use/token/browser.cjs +65 -0
- package/dist/use/token/browser.mjs +61 -0
- package/dist/use/token/runtime-only.cjs +245 -0
- package/dist/use/token/runtime-only.mjs +239 -0
- package/dist/use/token/server.cjs +325 -0
- package/dist/use/token/server.mjs +313 -0
- package/dist/use/token/vars.cjs +47 -0
- package/dist/use/token/vars.mjs +46 -0
- package/package.json +300 -4
- package/src/api/config.d.ts +1 -0
- package/src/fontsource/types.d.ts +50 -0
- package/src/packages/document-create-element/createElement.browser.js +3 -0
- package/src/packages/document-create-element/createElement.js +7 -0
- package/src/packages/document-create-element/package.json +17 -0
- package/src/packages/is-css-prop/browser.js +13 -0
- package/src/packages/is-css-prop/index.js +13 -0
- package/src/packages/is-css-prop/package-lock.json +52 -0
- package/src/packages/is-css-prop/package.json +17 -0
- package/src/prop/css/csstype.json +4387 -0
- package/src/prop/css/package.json +3 -0
- package/src/reset/reset.css +259 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { getClassNameProp } from "../../shared/framework.mjs";
|
|
2
|
+
import isDOMProp from "./isDOMProp.mjs";
|
|
3
|
+
import { cx } from "../../cx/index.mjs";
|
|
4
|
+
import isCSSProp from "@boss-css/is-css-prop";
|
|
5
|
+
|
|
6
|
+
//#region src/parser/jsx/browser.ts
|
|
7
|
+
const ignoredProps = new Set([
|
|
8
|
+
"ref",
|
|
9
|
+
"children",
|
|
10
|
+
"dangerouslySetInnerHtml",
|
|
11
|
+
"key"
|
|
12
|
+
]);
|
|
13
|
+
const name = "jsx";
|
|
14
|
+
const onBrowserObjectStart = (api, { input, tag = "div", contexts = [], output = {} }) => {
|
|
15
|
+
const log = api.log.child("runtime").child("jsx");
|
|
16
|
+
log.log("browserObject:start", input, output, contexts);
|
|
17
|
+
if (contexts.length) return;
|
|
18
|
+
const isClassnameFirst = api.strategy === "classname-first";
|
|
19
|
+
const classNameProp = getClassNameProp(api.framework);
|
|
20
|
+
let tokenOverrides = null;
|
|
21
|
+
for (const prop in input) {
|
|
22
|
+
if (prop === "tokens") {
|
|
23
|
+
tokenOverrides = input[prop];
|
|
24
|
+
delete input[prop];
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
if (prop === classNameProp) {
|
|
28
|
+
output[classNameProp] = cx(output[classNameProp], input[prop]);
|
|
29
|
+
delete input[prop];
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
if (prop === "style") {
|
|
33
|
+
const styleValue = input[prop];
|
|
34
|
+
if (styleValue && typeof styleValue === "object" && !Array.isArray(styleValue)) output.style = {
|
|
35
|
+
...output.style ?? {},
|
|
36
|
+
...styleValue
|
|
37
|
+
};
|
|
38
|
+
else if (styleValue !== void 0) output.style = styleValue;
|
|
39
|
+
delete input[prop];
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
if (ignoredProps.has(prop) || isDOMProp(tag, prop)) {
|
|
43
|
+
output[prop] = input[prop];
|
|
44
|
+
delete input[prop];
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
if (typeof input[prop] === "function") {
|
|
48
|
+
if (isClassnameFirst && isCSSProp(tag, prop)) continue;
|
|
49
|
+
input[prop] = input[prop]();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (tokenOverrides && typeof api.tokenVars === "function") {
|
|
53
|
+
const resolved = typeof tokenOverrides === "function" ? tokenOverrides() : tokenOverrides;
|
|
54
|
+
if (resolved && typeof resolved === "object") output.style = {
|
|
55
|
+
...output.style ?? {},
|
|
56
|
+
...api.tokenVars(resolved)
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
log.log("browserObject:end", input, output);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
//#endregion
|
|
63
|
+
export { name, onBrowserObjectStart };
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/parser/jsx/extractCode.ts
|
|
3
|
+
const map = {
|
|
4
|
+
"<": ">",
|
|
5
|
+
"{": "}",
|
|
6
|
+
"[": "]",
|
|
7
|
+
"(": ")",
|
|
8
|
+
"\"": "\"",
|
|
9
|
+
"`": "`",
|
|
10
|
+
"'": "'"
|
|
11
|
+
};
|
|
12
|
+
const openingRegexp = /* @__PURE__ */ new RegExp(`[${Object.keys(map).map((k) => `\\${k}`).join("")}]`);
|
|
13
|
+
const ignoredContexts = {
|
|
14
|
+
"{": true,
|
|
15
|
+
"\"": true,
|
|
16
|
+
"'": true,
|
|
17
|
+
"`": true
|
|
18
|
+
};
|
|
19
|
+
const assignmentRegexp = /^\$\$\.[A-Z]\w*\s*=\s*\$\$\.\$\s*\(/;
|
|
20
|
+
const isAssignment = (code, i) => {
|
|
21
|
+
return assignmentRegexp.test(code.substring(i, i + 120));
|
|
22
|
+
};
|
|
23
|
+
function extractCode(code) {
|
|
24
|
+
const results = [];
|
|
25
|
+
const stack = [];
|
|
26
|
+
let isInside = false;
|
|
27
|
+
let blockStart = -1;
|
|
28
|
+
let currentOpener = "";
|
|
29
|
+
let isIgnored = false;
|
|
30
|
+
let type = null;
|
|
31
|
+
let assignmentStarted = false;
|
|
32
|
+
for (let i = 0; i < code.length; i++) {
|
|
33
|
+
const current = code[i];
|
|
34
|
+
if (!isInside) {
|
|
35
|
+
if (current === "<" && code[i + 1] === "$" && code[i + 2] === "$") {
|
|
36
|
+
isInside = true;
|
|
37
|
+
type = "jsx";
|
|
38
|
+
blockStart = i;
|
|
39
|
+
} else if (current === "$" && code[i + 1] === "$" && code[i + 2] === "." && isAssignment(code, i)) {
|
|
40
|
+
isInside = true;
|
|
41
|
+
type = "assignment";
|
|
42
|
+
blockStart = i;
|
|
43
|
+
} else if (current === "$" && code[i + 1] === "$" && code[i + 2] === "." && code[i + 3] === "$" && code[i + 4] === "(") {
|
|
44
|
+
isInside = true;
|
|
45
|
+
type = "function";
|
|
46
|
+
blockStart = i;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (!isInside) continue;
|
|
50
|
+
if (type === "jsx") {
|
|
51
|
+
if (!isIgnored && openingRegexp.test(current)) {
|
|
52
|
+
stack.push(current);
|
|
53
|
+
currentOpener = current;
|
|
54
|
+
isIgnored = Boolean(ignoredContexts[current]);
|
|
55
|
+
}
|
|
56
|
+
if (current === map[currentOpener]) {
|
|
57
|
+
stack.pop();
|
|
58
|
+
currentOpener = stack.at(-1) || "";
|
|
59
|
+
isIgnored = false;
|
|
60
|
+
}
|
|
61
|
+
if (stack.length === 0) {
|
|
62
|
+
isInside = false;
|
|
63
|
+
results.push(code.slice(blockStart, i + 1));
|
|
64
|
+
blockStart = -1;
|
|
65
|
+
type = null;
|
|
66
|
+
}
|
|
67
|
+
} else if (type === "assignment") {
|
|
68
|
+
if (current === "{" || current === "(") {
|
|
69
|
+
stack.push(current);
|
|
70
|
+
assignmentStarted = true;
|
|
71
|
+
}
|
|
72
|
+
if (current === "}" || current === ")") stack.pop();
|
|
73
|
+
if (stack.length === 0 && assignmentStarted) {
|
|
74
|
+
isInside = false;
|
|
75
|
+
results.push(code.slice(blockStart, i + 1));
|
|
76
|
+
blockStart = -1;
|
|
77
|
+
type = null;
|
|
78
|
+
assignmentStarted = false;
|
|
79
|
+
}
|
|
80
|
+
} else if (type === "function") {
|
|
81
|
+
if (current === "(") {
|
|
82
|
+
stack.push(current);
|
|
83
|
+
assignmentStarted = true;
|
|
84
|
+
}
|
|
85
|
+
if (current === ")") stack.pop();
|
|
86
|
+
if (stack.length === 0 && assignmentStarted) {
|
|
87
|
+
isInside = false;
|
|
88
|
+
results.push(code.slice(blockStart, i + 1));
|
|
89
|
+
blockStart = -1;
|
|
90
|
+
type = null;
|
|
91
|
+
assignmentStarted = false;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return results;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
//#endregion
|
|
99
|
+
exports.extractCode = extractCode;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
//#region src/parser/jsx/extractCode.ts
|
|
2
|
+
const map = {
|
|
3
|
+
"<": ">",
|
|
4
|
+
"{": "}",
|
|
5
|
+
"[": "]",
|
|
6
|
+
"(": ")",
|
|
7
|
+
"\"": "\"",
|
|
8
|
+
"`": "`",
|
|
9
|
+
"'": "'"
|
|
10
|
+
};
|
|
11
|
+
const openingRegexp = /* @__PURE__ */ new RegExp(`[${Object.keys(map).map((k) => `\\${k}`).join("")}]`);
|
|
12
|
+
const ignoredContexts = {
|
|
13
|
+
"{": true,
|
|
14
|
+
"\"": true,
|
|
15
|
+
"'": true,
|
|
16
|
+
"`": true
|
|
17
|
+
};
|
|
18
|
+
const assignmentRegexp = /^\$\$\.[A-Z]\w*\s*=\s*\$\$\.\$\s*\(/;
|
|
19
|
+
const isAssignment = (code, i) => {
|
|
20
|
+
return assignmentRegexp.test(code.substring(i, i + 120));
|
|
21
|
+
};
|
|
22
|
+
function extractCode(code) {
|
|
23
|
+
const results = [];
|
|
24
|
+
const stack = [];
|
|
25
|
+
let isInside = false;
|
|
26
|
+
let blockStart = -1;
|
|
27
|
+
let currentOpener = "";
|
|
28
|
+
let isIgnored = false;
|
|
29
|
+
let type = null;
|
|
30
|
+
let assignmentStarted = false;
|
|
31
|
+
for (let i = 0; i < code.length; i++) {
|
|
32
|
+
const current = code[i];
|
|
33
|
+
if (!isInside) {
|
|
34
|
+
if (current === "<" && code[i + 1] === "$" && code[i + 2] === "$") {
|
|
35
|
+
isInside = true;
|
|
36
|
+
type = "jsx";
|
|
37
|
+
blockStart = i;
|
|
38
|
+
} else if (current === "$" && code[i + 1] === "$" && code[i + 2] === "." && isAssignment(code, i)) {
|
|
39
|
+
isInside = true;
|
|
40
|
+
type = "assignment";
|
|
41
|
+
blockStart = i;
|
|
42
|
+
} else if (current === "$" && code[i + 1] === "$" && code[i + 2] === "." && code[i + 3] === "$" && code[i + 4] === "(") {
|
|
43
|
+
isInside = true;
|
|
44
|
+
type = "function";
|
|
45
|
+
blockStart = i;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (!isInside) continue;
|
|
49
|
+
if (type === "jsx") {
|
|
50
|
+
if (!isIgnored && openingRegexp.test(current)) {
|
|
51
|
+
stack.push(current);
|
|
52
|
+
currentOpener = current;
|
|
53
|
+
isIgnored = Boolean(ignoredContexts[current]);
|
|
54
|
+
}
|
|
55
|
+
if (current === map[currentOpener]) {
|
|
56
|
+
stack.pop();
|
|
57
|
+
currentOpener = stack.at(-1) || "";
|
|
58
|
+
isIgnored = false;
|
|
59
|
+
}
|
|
60
|
+
if (stack.length === 0) {
|
|
61
|
+
isInside = false;
|
|
62
|
+
results.push(code.slice(blockStart, i + 1));
|
|
63
|
+
blockStart = -1;
|
|
64
|
+
type = null;
|
|
65
|
+
}
|
|
66
|
+
} else if (type === "assignment") {
|
|
67
|
+
if (current === "{" || current === "(") {
|
|
68
|
+
stack.push(current);
|
|
69
|
+
assignmentStarted = true;
|
|
70
|
+
}
|
|
71
|
+
if (current === "}" || current === ")") stack.pop();
|
|
72
|
+
if (stack.length === 0 && assignmentStarted) {
|
|
73
|
+
isInside = false;
|
|
74
|
+
results.push(code.slice(blockStart, i + 1));
|
|
75
|
+
blockStart = -1;
|
|
76
|
+
type = null;
|
|
77
|
+
assignmentStarted = false;
|
|
78
|
+
}
|
|
79
|
+
} else if (type === "function") {
|
|
80
|
+
if (current === "(") {
|
|
81
|
+
stack.push(current);
|
|
82
|
+
assignmentStarted = true;
|
|
83
|
+
}
|
|
84
|
+
if (current === ")") stack.pop();
|
|
85
|
+
if (stack.length === 0 && assignmentStarted) {
|
|
86
|
+
isInside = false;
|
|
87
|
+
results.push(code.slice(blockStart, i + 1));
|
|
88
|
+
blockStart = -1;
|
|
89
|
+
type = null;
|
|
90
|
+
assignmentStarted = false;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return results;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
//#endregion
|
|
98
|
+
export { extractCode };
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_extractCode = require('./extractCode.cjs');
|
|
3
|
+
let _swc_core = require("@swc/core");
|
|
4
|
+
|
|
5
|
+
//#region src/parser/jsx/extractPrepared.ts
|
|
6
|
+
const extractPreparedComponents = (content, filePath) => {
|
|
7
|
+
if (!content.includes("$$.")) return [];
|
|
8
|
+
const codes = require_extractCode.extractCode(content).filter((code) => code.trim().startsWith("$$."));
|
|
9
|
+
if (!codes.length) return [];
|
|
10
|
+
const results = [];
|
|
11
|
+
for (const code of codes) {
|
|
12
|
+
let parsed;
|
|
13
|
+
try {
|
|
14
|
+
parsed = (0, _swc_core.parseSync)(code, {
|
|
15
|
+
syntax: "typescript",
|
|
16
|
+
tsx: true,
|
|
17
|
+
isModule: false
|
|
18
|
+
});
|
|
19
|
+
} catch {
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
const statement = parsed.body.find((node) => node.type === "ExpressionStatement");
|
|
23
|
+
if (!statement || statement.type !== "ExpressionStatement") continue;
|
|
24
|
+
const expression = statement.expression;
|
|
25
|
+
if (expression.type !== "AssignmentExpression") continue;
|
|
26
|
+
const prepared = extractPreparedInfo(expression, filePath);
|
|
27
|
+
if (prepared) results.push(prepared);
|
|
28
|
+
}
|
|
29
|
+
return results;
|
|
30
|
+
};
|
|
31
|
+
const extractPreparedInfo = (expression, filePath) => {
|
|
32
|
+
if (!isPreparedAssignment(expression)) return null;
|
|
33
|
+
const name = expression.left.property.value;
|
|
34
|
+
const objectExpression = getPreparedObjectExpression(expression.right);
|
|
35
|
+
if (!objectExpression) return null;
|
|
36
|
+
const { asTag, asDynamic } = extractAsMeta(objectExpression);
|
|
37
|
+
return {
|
|
38
|
+
name,
|
|
39
|
+
asTag,
|
|
40
|
+
asDynamic,
|
|
41
|
+
filePath,
|
|
42
|
+
styles: extractStyleText(objectExpression)
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
const isPreparedAssignment = (expression) => {
|
|
46
|
+
const left = expression.left;
|
|
47
|
+
if (!left || left.type !== "MemberExpression") return false;
|
|
48
|
+
if (left.object?.type !== "Identifier" || left.object.value !== "$$") return false;
|
|
49
|
+
if (left.property?.type !== "Identifier") return false;
|
|
50
|
+
if (!/^[A-Z]/.test(left.property.value)) return false;
|
|
51
|
+
if (expression.operator && expression.operator !== "=") return false;
|
|
52
|
+
return true;
|
|
53
|
+
};
|
|
54
|
+
const getPreparedObjectExpression = (expression) => {
|
|
55
|
+
if (expression.type === "CallExpression" && expression.arguments.length === 1) {
|
|
56
|
+
const callee = expression.callee;
|
|
57
|
+
if (callee.type === "MemberExpression" && callee.object?.type === "Identifier" && callee.object.value === "$$" && callee.property?.type === "Identifier" && callee.property.value === "$") {
|
|
58
|
+
const arg = expression.arguments[0].expression;
|
|
59
|
+
if (arg.type === "ObjectExpression") return arg;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
63
|
+
};
|
|
64
|
+
const extractAsMeta = (objectExpression) => {
|
|
65
|
+
let asTag = null;
|
|
66
|
+
let asDynamic = false;
|
|
67
|
+
for (const prop of objectExpression.properties) {
|
|
68
|
+
if (prop.type !== "KeyValueProperty") continue;
|
|
69
|
+
if (prop.key.type !== "Identifier" && prop.key.type !== "StringLiteral") continue;
|
|
70
|
+
if ((prop.key.type === "Identifier" ? prop.key.value : prop.key.value) !== "as") continue;
|
|
71
|
+
const value = prop.value;
|
|
72
|
+
if (value.type === "StringLiteral") {
|
|
73
|
+
asTag = value.value;
|
|
74
|
+
asDynamic = false;
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
if (value.type === "TemplateLiteral" && value.expressions.length === 0) {
|
|
78
|
+
const first = value.quasis[0];
|
|
79
|
+
asTag = first?.cooked ?? first?.raw ?? "";
|
|
80
|
+
asDynamic = false;
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
asDynamic = true;
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
asTag,
|
|
88
|
+
asDynamic
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
const extractStyleText = (objectExpression) => {
|
|
92
|
+
const filtered = objectExpression.properties.filter((prop) => {
|
|
93
|
+
if (prop.type !== "KeyValueProperty") return true;
|
|
94
|
+
if (prop.key.type !== "Identifier" && prop.key.type !== "StringLiteral") return true;
|
|
95
|
+
return (prop.key.type === "Identifier" ? prop.key.value : prop.key.value) !== "as";
|
|
96
|
+
});
|
|
97
|
+
if (!filtered.length) return void 0;
|
|
98
|
+
const span = {
|
|
99
|
+
start: 0,
|
|
100
|
+
end: 0,
|
|
101
|
+
ctxt: 0
|
|
102
|
+
};
|
|
103
|
+
let text = (0, _swc_core.printSync)({
|
|
104
|
+
type: "Module",
|
|
105
|
+
body: [{
|
|
106
|
+
type: "ExpressionStatement",
|
|
107
|
+
expression: {
|
|
108
|
+
type: "ObjectExpression",
|
|
109
|
+
span: objectExpression.span ?? span,
|
|
110
|
+
properties: filtered
|
|
111
|
+
},
|
|
112
|
+
span
|
|
113
|
+
}],
|
|
114
|
+
interpreter: null,
|
|
115
|
+
span
|
|
116
|
+
}).code;
|
|
117
|
+
text = text.replace(/;\s*$/, "").trim();
|
|
118
|
+
if (text.startsWith("({") && text.endsWith("})")) text = text.slice(1, -1);
|
|
119
|
+
return text.replace(/\s+/g, " ");
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
//#endregion
|
|
123
|
+
exports.extractPreparedComponents = extractPreparedComponents;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { extractCode } from "./extractCode.mjs";
|
|
2
|
+
import { parseSync, printSync } from "@swc/core";
|
|
3
|
+
|
|
4
|
+
//#region src/parser/jsx/extractPrepared.ts
|
|
5
|
+
const extractPreparedComponents = (content, filePath) => {
|
|
6
|
+
if (!content.includes("$$.")) return [];
|
|
7
|
+
const codes = extractCode(content).filter((code) => code.trim().startsWith("$$."));
|
|
8
|
+
if (!codes.length) return [];
|
|
9
|
+
const results = [];
|
|
10
|
+
for (const code of codes) {
|
|
11
|
+
let parsed;
|
|
12
|
+
try {
|
|
13
|
+
parsed = parseSync(code, {
|
|
14
|
+
syntax: "typescript",
|
|
15
|
+
tsx: true,
|
|
16
|
+
isModule: false
|
|
17
|
+
});
|
|
18
|
+
} catch {
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
const statement = parsed.body.find((node) => node.type === "ExpressionStatement");
|
|
22
|
+
if (!statement || statement.type !== "ExpressionStatement") continue;
|
|
23
|
+
const expression = statement.expression;
|
|
24
|
+
if (expression.type !== "AssignmentExpression") continue;
|
|
25
|
+
const prepared = extractPreparedInfo(expression, filePath);
|
|
26
|
+
if (prepared) results.push(prepared);
|
|
27
|
+
}
|
|
28
|
+
return results;
|
|
29
|
+
};
|
|
30
|
+
const extractPreparedInfo = (expression, filePath) => {
|
|
31
|
+
if (!isPreparedAssignment(expression)) return null;
|
|
32
|
+
const name = expression.left.property.value;
|
|
33
|
+
const objectExpression = getPreparedObjectExpression(expression.right);
|
|
34
|
+
if (!objectExpression) return null;
|
|
35
|
+
const { asTag, asDynamic } = extractAsMeta(objectExpression);
|
|
36
|
+
return {
|
|
37
|
+
name,
|
|
38
|
+
asTag,
|
|
39
|
+
asDynamic,
|
|
40
|
+
filePath,
|
|
41
|
+
styles: extractStyleText(objectExpression)
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
const isPreparedAssignment = (expression) => {
|
|
45
|
+
const left = expression.left;
|
|
46
|
+
if (!left || left.type !== "MemberExpression") return false;
|
|
47
|
+
if (left.object?.type !== "Identifier" || left.object.value !== "$$") return false;
|
|
48
|
+
if (left.property?.type !== "Identifier") return false;
|
|
49
|
+
if (!/^[A-Z]/.test(left.property.value)) return false;
|
|
50
|
+
if (expression.operator && expression.operator !== "=") return false;
|
|
51
|
+
return true;
|
|
52
|
+
};
|
|
53
|
+
const getPreparedObjectExpression = (expression) => {
|
|
54
|
+
if (expression.type === "CallExpression" && expression.arguments.length === 1) {
|
|
55
|
+
const callee = expression.callee;
|
|
56
|
+
if (callee.type === "MemberExpression" && callee.object?.type === "Identifier" && callee.object.value === "$$" && callee.property?.type === "Identifier" && callee.property.value === "$") {
|
|
57
|
+
const arg = expression.arguments[0].expression;
|
|
58
|
+
if (arg.type === "ObjectExpression") return arg;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return null;
|
|
62
|
+
};
|
|
63
|
+
const extractAsMeta = (objectExpression) => {
|
|
64
|
+
let asTag = null;
|
|
65
|
+
let asDynamic = false;
|
|
66
|
+
for (const prop of objectExpression.properties) {
|
|
67
|
+
if (prop.type !== "KeyValueProperty") continue;
|
|
68
|
+
if (prop.key.type !== "Identifier" && prop.key.type !== "StringLiteral") continue;
|
|
69
|
+
if ((prop.key.type === "Identifier" ? prop.key.value : prop.key.value) !== "as") continue;
|
|
70
|
+
const value = prop.value;
|
|
71
|
+
if (value.type === "StringLiteral") {
|
|
72
|
+
asTag = value.value;
|
|
73
|
+
asDynamic = false;
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
if (value.type === "TemplateLiteral" && value.expressions.length === 0) {
|
|
77
|
+
const first = value.quasis[0];
|
|
78
|
+
asTag = first?.cooked ?? first?.raw ?? "";
|
|
79
|
+
asDynamic = false;
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
asDynamic = true;
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
asTag,
|
|
87
|
+
asDynamic
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
const extractStyleText = (objectExpression) => {
|
|
91
|
+
const filtered = objectExpression.properties.filter((prop) => {
|
|
92
|
+
if (prop.type !== "KeyValueProperty") return true;
|
|
93
|
+
if (prop.key.type !== "Identifier" && prop.key.type !== "StringLiteral") return true;
|
|
94
|
+
return (prop.key.type === "Identifier" ? prop.key.value : prop.key.value) !== "as";
|
|
95
|
+
});
|
|
96
|
+
if (!filtered.length) return void 0;
|
|
97
|
+
const span = {
|
|
98
|
+
start: 0,
|
|
99
|
+
end: 0,
|
|
100
|
+
ctxt: 0
|
|
101
|
+
};
|
|
102
|
+
let text = printSync({
|
|
103
|
+
type: "Module",
|
|
104
|
+
body: [{
|
|
105
|
+
type: "ExpressionStatement",
|
|
106
|
+
expression: {
|
|
107
|
+
type: "ObjectExpression",
|
|
108
|
+
span: objectExpression.span ?? span,
|
|
109
|
+
properties: filtered
|
|
110
|
+
},
|
|
111
|
+
span
|
|
112
|
+
}],
|
|
113
|
+
interpreter: null,
|
|
114
|
+
span
|
|
115
|
+
}).code;
|
|
116
|
+
text = text.replace(/;\s*$/, "").trim();
|
|
117
|
+
if (text.startsWith("({") && text.endsWith("})")) text = text.slice(1, -1);
|
|
118
|
+
return text.replace(/\s+/g, " ");
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
//#endregion
|
|
122
|
+
export { extractPreparedComponents };
|