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,234 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let _swc_core = require("@swc/core");
|
|
3
|
+
_swc_core = require_rolldown_runtime.__toESM(_swc_core);
|
|
4
|
+
|
|
5
|
+
//#region src/parser/jsx/extractProps.ts
|
|
6
|
+
async function extractPropTrees(codes) {
|
|
7
|
+
if (!codes.length) return [];
|
|
8
|
+
if (codes.length === 1) return [await extractPropTreeFromCode(codes[0])];
|
|
9
|
+
const normalizedCodes = codes.map(normalizeCode);
|
|
10
|
+
const { body } = await _swc_core.default.parse(normalizedCodes.join(";\n"), {
|
|
11
|
+
syntax: "typescript",
|
|
12
|
+
tsx: true,
|
|
13
|
+
isModule: false
|
|
14
|
+
});
|
|
15
|
+
const expressions = body.filter((node) => node.type === "ExpressionStatement").map((node) => node.expression);
|
|
16
|
+
if (expressions.length !== normalizedCodes.length) return Promise.all(normalizedCodes.map(extractPropTreeFromCode));
|
|
17
|
+
return expressions.map(extractPropTreeFromExpression);
|
|
18
|
+
}
|
|
19
|
+
const normalizeCode = (code) => {
|
|
20
|
+
return code.replace(/(.)>$/, (_, char) => char === "/" ? "/>" : `${char}/>`);
|
|
21
|
+
};
|
|
22
|
+
const extractPropTreeFromCode = async (code) => {
|
|
23
|
+
const { body } = await _swc_core.default.parse(normalizeCode(code), {
|
|
24
|
+
syntax: "typescript",
|
|
25
|
+
tsx: true,
|
|
26
|
+
isModule: false
|
|
27
|
+
});
|
|
28
|
+
const statement = body.find((node) => node.type === "ExpressionStatement");
|
|
29
|
+
if (!statement) return {};
|
|
30
|
+
return extractPropTreeFromExpression(statement.expression);
|
|
31
|
+
};
|
|
32
|
+
const getAttributeName = (name) => {
|
|
33
|
+
if (!name) return null;
|
|
34
|
+
if (name.type === "Identifier") return name.value;
|
|
35
|
+
if (name.type === "JSXNamespacedName") return `${name.namespace.value}:${name.name.value}`;
|
|
36
|
+
return null;
|
|
37
|
+
};
|
|
38
|
+
const extractPropTreeFromExpression = (expression) => {
|
|
39
|
+
if (expression.type === "AssignmentExpression") {
|
|
40
|
+
const right = expression.right;
|
|
41
|
+
let objectExpression = null;
|
|
42
|
+
if (right.type === "CallExpression" && right.arguments.length === 1) {
|
|
43
|
+
const callee = right.callee;
|
|
44
|
+
if (callee.type === "MemberExpression" && callee.object?.type === "Identifier" && callee.object.value === "$$" && callee.property?.type === "Identifier" && callee.property.value === "$") objectExpression = right.arguments[0].expression;
|
|
45
|
+
}
|
|
46
|
+
if (objectExpression?.type === "ObjectExpression") return extractObjectProps(objectExpression);
|
|
47
|
+
return {};
|
|
48
|
+
}
|
|
49
|
+
if (expression.type === "CallExpression" && expression.arguments.length === 1) {
|
|
50
|
+
const callee = expression.callee;
|
|
51
|
+
if (callee.type === "MemberExpression" && callee.object?.type === "Identifier" && callee.object.value === "$$" && callee.property?.type === "Identifier" && callee.property.value === "$") {
|
|
52
|
+
const arg = expression.arguments[0]?.expression;
|
|
53
|
+
if (arg?.type === "ObjectExpression") return extractObjectProps(arg);
|
|
54
|
+
}
|
|
55
|
+
return {};
|
|
56
|
+
}
|
|
57
|
+
return expression.opening.attributes.reduce((acc, { name, value }) => {
|
|
58
|
+
const propName = getAttributeName(name);
|
|
59
|
+
if (!propName) return acc;
|
|
60
|
+
acc[propName] = getValue(value);
|
|
61
|
+
return acc;
|
|
62
|
+
}, {});
|
|
63
|
+
};
|
|
64
|
+
const extractObjectProps = (objectExpression) => {
|
|
65
|
+
return objectExpression.properties.reduce((acc, prop) => {
|
|
66
|
+
if (prop.type === "KeyValueProperty") {
|
|
67
|
+
const key = prop.key.type === "Identifier" ? prop.key.value : prop.key.value;
|
|
68
|
+
acc[key] = getValue(prop.value);
|
|
69
|
+
return acc;
|
|
70
|
+
}
|
|
71
|
+
if (prop.type === "Identifier") {
|
|
72
|
+
acc[prop.value] = getValue(prop);
|
|
73
|
+
return acc;
|
|
74
|
+
}
|
|
75
|
+
return acc;
|
|
76
|
+
}, {});
|
|
77
|
+
};
|
|
78
|
+
const getValue = (value) => {
|
|
79
|
+
if (value === null) return {
|
|
80
|
+
dynamic: false,
|
|
81
|
+
value: true
|
|
82
|
+
};
|
|
83
|
+
else if (value.type === "JSXExpressionContainer") return getValue(value.expression);
|
|
84
|
+
else if (value.type === "NumericLiteral") return {
|
|
85
|
+
dynamic: false,
|
|
86
|
+
value: value.value
|
|
87
|
+
};
|
|
88
|
+
else if (value.type === "StringLiteral") return {
|
|
89
|
+
dynamic: false,
|
|
90
|
+
value: value.value
|
|
91
|
+
};
|
|
92
|
+
else if (value.type === "BooleanLiteral") return {
|
|
93
|
+
dynamic: false,
|
|
94
|
+
value: value.value
|
|
95
|
+
};
|
|
96
|
+
else if (value.type === "BinaryExpression") return {
|
|
97
|
+
ast: value,
|
|
98
|
+
dynamic: true,
|
|
99
|
+
value: null
|
|
100
|
+
};
|
|
101
|
+
else if (value.type === "ArrayExpression") return reconstructArray(value.elements);
|
|
102
|
+
else if (value.type === "TemplateLiteral") return {
|
|
103
|
+
dynamic: !!value.expressions.length,
|
|
104
|
+
value: value.quasis[0]?.raw ?? value.quasis[0]?.cooked ?? ""
|
|
105
|
+
};
|
|
106
|
+
else if (value.type === "ArrowFunctionExpression" || value.type === "FunctionExpression") return {
|
|
107
|
+
ast: structuredClone(value),
|
|
108
|
+
dynamic: true,
|
|
109
|
+
isFn: true,
|
|
110
|
+
value: null
|
|
111
|
+
};
|
|
112
|
+
else if (value.type === "ObjectExpression") return reconstructObject(value.properties);
|
|
113
|
+
else return {
|
|
114
|
+
ast: structuredClone(value),
|
|
115
|
+
code: printCode(value),
|
|
116
|
+
dynamic: true,
|
|
117
|
+
value: null
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
function printCode(expression) {
|
|
121
|
+
return _swc_core.default.printSync({
|
|
122
|
+
type: "Module",
|
|
123
|
+
body: [{
|
|
124
|
+
type: "ExpressionStatement",
|
|
125
|
+
expression,
|
|
126
|
+
span: {
|
|
127
|
+
start: 0,
|
|
128
|
+
end: 0,
|
|
129
|
+
ctxt: 0
|
|
130
|
+
}
|
|
131
|
+
}],
|
|
132
|
+
interpreter: null,
|
|
133
|
+
span: {
|
|
134
|
+
start: 0,
|
|
135
|
+
end: 0,
|
|
136
|
+
ctxt: 0
|
|
137
|
+
}
|
|
138
|
+
}).code.replace(/;\s$/, "");
|
|
139
|
+
}
|
|
140
|
+
function reconstructObject(properties) {
|
|
141
|
+
let dynamic = false;
|
|
142
|
+
return {
|
|
143
|
+
value: properties.reduce((acc, { key, value }) => {
|
|
144
|
+
switch (value.type) {
|
|
145
|
+
case "StringLiteral":
|
|
146
|
+
case "NumericLiteral":
|
|
147
|
+
case "TemplateLiteral":
|
|
148
|
+
case "BooleanLiteral": {
|
|
149
|
+
const v = getValue(value);
|
|
150
|
+
dynamic = dynamic || v.dynamic;
|
|
151
|
+
acc[key.value] = v;
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
case "ObjectExpression": {
|
|
155
|
+
const reconstructed = reconstructObject(value.properties);
|
|
156
|
+
dynamic = dynamic || reconstructed.dynamic;
|
|
157
|
+
acc[key.value] = reconstructed;
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
case "ArrayExpression": {
|
|
161
|
+
const reconstructed = reconstructArray(value.elements);
|
|
162
|
+
dynamic = dynamic || reconstructed.dynamic;
|
|
163
|
+
acc[key.value] = reconstructed;
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
case "ArrowFunctionExpression":
|
|
167
|
+
case "FunctionExpression": {
|
|
168
|
+
const v = getValue(value);
|
|
169
|
+
dynamic = dynamic || v.dynamic;
|
|
170
|
+
acc[key.value] = v;
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
173
|
+
default:
|
|
174
|
+
dynamic = true;
|
|
175
|
+
acc[key.value] = {
|
|
176
|
+
dynamic: true,
|
|
177
|
+
value: null,
|
|
178
|
+
ast: structuredClone(value),
|
|
179
|
+
code: printCode(value)
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
return acc;
|
|
183
|
+
}, {}),
|
|
184
|
+
dynamic
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
function reconstructArray(elements) {
|
|
188
|
+
let dynamic = false;
|
|
189
|
+
return {
|
|
190
|
+
value: elements.reduce((acc, { expression: value }) => {
|
|
191
|
+
switch (value.type) {
|
|
192
|
+
case "StringLiteral":
|
|
193
|
+
case "NumericLiteral":
|
|
194
|
+
case "TemplateLiteral":
|
|
195
|
+
case "BooleanLiteral": {
|
|
196
|
+
const v = getValue(value);
|
|
197
|
+
dynamic = dynamic || v.dynamic;
|
|
198
|
+
acc.push(v);
|
|
199
|
+
break;
|
|
200
|
+
}
|
|
201
|
+
case "ObjectExpression": {
|
|
202
|
+
const reconstructed = reconstructObject(value.properties);
|
|
203
|
+
dynamic = dynamic || reconstructed.dynamic;
|
|
204
|
+
acc.push(reconstructed);
|
|
205
|
+
break;
|
|
206
|
+
}
|
|
207
|
+
case "ArrayExpression": {
|
|
208
|
+
const reconstructed = reconstructArray(value.elements);
|
|
209
|
+
dynamic = dynamic || reconstructed.dynamic;
|
|
210
|
+
acc.push(reconstructed);
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
213
|
+
case "ArrowFunctionExpression":
|
|
214
|
+
case "FunctionExpression": {
|
|
215
|
+
const v = getValue(value);
|
|
216
|
+
dynamic = dynamic || v.dynamic;
|
|
217
|
+
acc.push(v);
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
default:
|
|
221
|
+
dynamic = true;
|
|
222
|
+
acc.push({
|
|
223
|
+
dynamic: true,
|
|
224
|
+
value: null
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
return acc;
|
|
228
|
+
}, []),
|
|
229
|
+
dynamic
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
//#endregion
|
|
234
|
+
exports.extractPropTrees = extractPropTrees;
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import swc from "@swc/core";
|
|
2
|
+
|
|
3
|
+
//#region src/parser/jsx/extractProps.ts
|
|
4
|
+
async function extractPropTrees(codes) {
|
|
5
|
+
if (!codes.length) return [];
|
|
6
|
+
if (codes.length === 1) return [await extractPropTreeFromCode(codes[0])];
|
|
7
|
+
const normalizedCodes = codes.map(normalizeCode);
|
|
8
|
+
const { body } = await swc.parse(normalizedCodes.join(";\n"), {
|
|
9
|
+
syntax: "typescript",
|
|
10
|
+
tsx: true,
|
|
11
|
+
isModule: false
|
|
12
|
+
});
|
|
13
|
+
const expressions = body.filter((node) => node.type === "ExpressionStatement").map((node) => node.expression);
|
|
14
|
+
if (expressions.length !== normalizedCodes.length) return Promise.all(normalizedCodes.map(extractPropTreeFromCode));
|
|
15
|
+
return expressions.map(extractPropTreeFromExpression);
|
|
16
|
+
}
|
|
17
|
+
const normalizeCode = (code) => {
|
|
18
|
+
return code.replace(/(.)>$/, (_, char) => char === "/" ? "/>" : `${char}/>`);
|
|
19
|
+
};
|
|
20
|
+
const extractPropTreeFromCode = async (code) => {
|
|
21
|
+
const { body } = await swc.parse(normalizeCode(code), {
|
|
22
|
+
syntax: "typescript",
|
|
23
|
+
tsx: true,
|
|
24
|
+
isModule: false
|
|
25
|
+
});
|
|
26
|
+
const statement = body.find((node) => node.type === "ExpressionStatement");
|
|
27
|
+
if (!statement) return {};
|
|
28
|
+
return extractPropTreeFromExpression(statement.expression);
|
|
29
|
+
};
|
|
30
|
+
const getAttributeName = (name) => {
|
|
31
|
+
if (!name) return null;
|
|
32
|
+
if (name.type === "Identifier") return name.value;
|
|
33
|
+
if (name.type === "JSXNamespacedName") return `${name.namespace.value}:${name.name.value}`;
|
|
34
|
+
return null;
|
|
35
|
+
};
|
|
36
|
+
const extractPropTreeFromExpression = (expression) => {
|
|
37
|
+
if (expression.type === "AssignmentExpression") {
|
|
38
|
+
const right = expression.right;
|
|
39
|
+
let objectExpression = null;
|
|
40
|
+
if (right.type === "CallExpression" && right.arguments.length === 1) {
|
|
41
|
+
const callee = right.callee;
|
|
42
|
+
if (callee.type === "MemberExpression" && callee.object?.type === "Identifier" && callee.object.value === "$$" && callee.property?.type === "Identifier" && callee.property.value === "$") objectExpression = right.arguments[0].expression;
|
|
43
|
+
}
|
|
44
|
+
if (objectExpression?.type === "ObjectExpression") return extractObjectProps(objectExpression);
|
|
45
|
+
return {};
|
|
46
|
+
}
|
|
47
|
+
if (expression.type === "CallExpression" && expression.arguments.length === 1) {
|
|
48
|
+
const callee = expression.callee;
|
|
49
|
+
if (callee.type === "MemberExpression" && callee.object?.type === "Identifier" && callee.object.value === "$$" && callee.property?.type === "Identifier" && callee.property.value === "$") {
|
|
50
|
+
const arg = expression.arguments[0]?.expression;
|
|
51
|
+
if (arg?.type === "ObjectExpression") return extractObjectProps(arg);
|
|
52
|
+
}
|
|
53
|
+
return {};
|
|
54
|
+
}
|
|
55
|
+
return expression.opening.attributes.reduce((acc, { name, value }) => {
|
|
56
|
+
const propName = getAttributeName(name);
|
|
57
|
+
if (!propName) return acc;
|
|
58
|
+
acc[propName] = getValue(value);
|
|
59
|
+
return acc;
|
|
60
|
+
}, {});
|
|
61
|
+
};
|
|
62
|
+
const extractObjectProps = (objectExpression) => {
|
|
63
|
+
return objectExpression.properties.reduce((acc, prop) => {
|
|
64
|
+
if (prop.type === "KeyValueProperty") {
|
|
65
|
+
const key = prop.key.type === "Identifier" ? prop.key.value : prop.key.value;
|
|
66
|
+
acc[key] = getValue(prop.value);
|
|
67
|
+
return acc;
|
|
68
|
+
}
|
|
69
|
+
if (prop.type === "Identifier") {
|
|
70
|
+
acc[prop.value] = getValue(prop);
|
|
71
|
+
return acc;
|
|
72
|
+
}
|
|
73
|
+
return acc;
|
|
74
|
+
}, {});
|
|
75
|
+
};
|
|
76
|
+
const getValue = (value) => {
|
|
77
|
+
if (value === null) return {
|
|
78
|
+
dynamic: false,
|
|
79
|
+
value: true
|
|
80
|
+
};
|
|
81
|
+
else if (value.type === "JSXExpressionContainer") return getValue(value.expression);
|
|
82
|
+
else if (value.type === "NumericLiteral") return {
|
|
83
|
+
dynamic: false,
|
|
84
|
+
value: value.value
|
|
85
|
+
};
|
|
86
|
+
else if (value.type === "StringLiteral") return {
|
|
87
|
+
dynamic: false,
|
|
88
|
+
value: value.value
|
|
89
|
+
};
|
|
90
|
+
else if (value.type === "BooleanLiteral") return {
|
|
91
|
+
dynamic: false,
|
|
92
|
+
value: value.value
|
|
93
|
+
};
|
|
94
|
+
else if (value.type === "BinaryExpression") return {
|
|
95
|
+
ast: value,
|
|
96
|
+
dynamic: true,
|
|
97
|
+
value: null
|
|
98
|
+
};
|
|
99
|
+
else if (value.type === "ArrayExpression") return reconstructArray(value.elements);
|
|
100
|
+
else if (value.type === "TemplateLiteral") return {
|
|
101
|
+
dynamic: !!value.expressions.length,
|
|
102
|
+
value: value.quasis[0]?.raw ?? value.quasis[0]?.cooked ?? ""
|
|
103
|
+
};
|
|
104
|
+
else if (value.type === "ArrowFunctionExpression" || value.type === "FunctionExpression") return {
|
|
105
|
+
ast: structuredClone(value),
|
|
106
|
+
dynamic: true,
|
|
107
|
+
isFn: true,
|
|
108
|
+
value: null
|
|
109
|
+
};
|
|
110
|
+
else if (value.type === "ObjectExpression") return reconstructObject(value.properties);
|
|
111
|
+
else return {
|
|
112
|
+
ast: structuredClone(value),
|
|
113
|
+
code: printCode(value),
|
|
114
|
+
dynamic: true,
|
|
115
|
+
value: null
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
function printCode(expression) {
|
|
119
|
+
return swc.printSync({
|
|
120
|
+
type: "Module",
|
|
121
|
+
body: [{
|
|
122
|
+
type: "ExpressionStatement",
|
|
123
|
+
expression,
|
|
124
|
+
span: {
|
|
125
|
+
start: 0,
|
|
126
|
+
end: 0,
|
|
127
|
+
ctxt: 0
|
|
128
|
+
}
|
|
129
|
+
}],
|
|
130
|
+
interpreter: null,
|
|
131
|
+
span: {
|
|
132
|
+
start: 0,
|
|
133
|
+
end: 0,
|
|
134
|
+
ctxt: 0
|
|
135
|
+
}
|
|
136
|
+
}).code.replace(/;\s$/, "");
|
|
137
|
+
}
|
|
138
|
+
function reconstructObject(properties) {
|
|
139
|
+
let dynamic = false;
|
|
140
|
+
return {
|
|
141
|
+
value: properties.reduce((acc, { key, value }) => {
|
|
142
|
+
switch (value.type) {
|
|
143
|
+
case "StringLiteral":
|
|
144
|
+
case "NumericLiteral":
|
|
145
|
+
case "TemplateLiteral":
|
|
146
|
+
case "BooleanLiteral": {
|
|
147
|
+
const v = getValue(value);
|
|
148
|
+
dynamic = dynamic || v.dynamic;
|
|
149
|
+
acc[key.value] = v;
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
case "ObjectExpression": {
|
|
153
|
+
const reconstructed = reconstructObject(value.properties);
|
|
154
|
+
dynamic = dynamic || reconstructed.dynamic;
|
|
155
|
+
acc[key.value] = reconstructed;
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
case "ArrayExpression": {
|
|
159
|
+
const reconstructed = reconstructArray(value.elements);
|
|
160
|
+
dynamic = dynamic || reconstructed.dynamic;
|
|
161
|
+
acc[key.value] = reconstructed;
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
case "ArrowFunctionExpression":
|
|
165
|
+
case "FunctionExpression": {
|
|
166
|
+
const v = getValue(value);
|
|
167
|
+
dynamic = dynamic || v.dynamic;
|
|
168
|
+
acc[key.value] = v;
|
|
169
|
+
break;
|
|
170
|
+
}
|
|
171
|
+
default:
|
|
172
|
+
dynamic = true;
|
|
173
|
+
acc[key.value] = {
|
|
174
|
+
dynamic: true,
|
|
175
|
+
value: null,
|
|
176
|
+
ast: structuredClone(value),
|
|
177
|
+
code: printCode(value)
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
return acc;
|
|
181
|
+
}, {}),
|
|
182
|
+
dynamic
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
function reconstructArray(elements) {
|
|
186
|
+
let dynamic = false;
|
|
187
|
+
return {
|
|
188
|
+
value: elements.reduce((acc, { expression: value }) => {
|
|
189
|
+
switch (value.type) {
|
|
190
|
+
case "StringLiteral":
|
|
191
|
+
case "NumericLiteral":
|
|
192
|
+
case "TemplateLiteral":
|
|
193
|
+
case "BooleanLiteral": {
|
|
194
|
+
const v = getValue(value);
|
|
195
|
+
dynamic = dynamic || v.dynamic;
|
|
196
|
+
acc.push(v);
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
case "ObjectExpression": {
|
|
200
|
+
const reconstructed = reconstructObject(value.properties);
|
|
201
|
+
dynamic = dynamic || reconstructed.dynamic;
|
|
202
|
+
acc.push(reconstructed);
|
|
203
|
+
break;
|
|
204
|
+
}
|
|
205
|
+
case "ArrayExpression": {
|
|
206
|
+
const reconstructed = reconstructArray(value.elements);
|
|
207
|
+
dynamic = dynamic || reconstructed.dynamic;
|
|
208
|
+
acc.push(reconstructed);
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
211
|
+
case "ArrowFunctionExpression":
|
|
212
|
+
case "FunctionExpression": {
|
|
213
|
+
const v = getValue(value);
|
|
214
|
+
dynamic = dynamic || v.dynamic;
|
|
215
|
+
acc.push(v);
|
|
216
|
+
break;
|
|
217
|
+
}
|
|
218
|
+
default:
|
|
219
|
+
dynamic = true;
|
|
220
|
+
acc.push({
|
|
221
|
+
dynamic: true,
|
|
222
|
+
value: null
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
return acc;
|
|
226
|
+
}, []),
|
|
227
|
+
dynamic
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
//#endregion
|
|
232
|
+
export { extractPropTrees };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let _boss_css_document_create_element = require("@boss-css/document-create-element");
|
|
3
|
+
_boss_css_document_create_element = require_rolldown_runtime.__toESM(_boss_css_document_create_element);
|
|
4
|
+
|
|
5
|
+
//#region src/parser/jsx/isDOMProp.ts
|
|
6
|
+
const cache = {};
|
|
7
|
+
function isDOMProp(tag, prop) {
|
|
8
|
+
const tagEntry = cache[tag] ??= {};
|
|
9
|
+
if (prop in tagEntry) return tagEntry[prop];
|
|
10
|
+
tagEntry.$el ??= (0, _boss_css_document_create_element.default)(tag);
|
|
11
|
+
const element = tagEntry.$el;
|
|
12
|
+
if ((tagEntry[prop] = prop in element || prop.toLowerCase() in element) && typeof element[prop] === "function") tagEntry[prop] = false;
|
|
13
|
+
return tagEntry[prop];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
17
|
+
exports.default = isDOMProp;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import createElement from "@boss-css/document-create-element";
|
|
2
|
+
|
|
3
|
+
//#region src/parser/jsx/isDOMProp.ts
|
|
4
|
+
const cache = {};
|
|
5
|
+
function isDOMProp(tag, prop) {
|
|
6
|
+
const tagEntry = cache[tag] ??= {};
|
|
7
|
+
if (prop in tagEntry) return tagEntry[prop];
|
|
8
|
+
tagEntry.$el ??= createElement(tag);
|
|
9
|
+
const element = tagEntry.$el;
|
|
10
|
+
if ((tagEntry[prop] = prop in element || prop.toLowerCase() in element) && typeof element[prop] === "function") tagEntry[prop] = false;
|
|
11
|
+
return tagEntry[prop];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
export { isDOMProp as default };
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_api_browser = require('../../api/browser.cjs');
|
|
3
|
+
const require_merge_index = require('../../merge/index.cjs');
|
|
4
|
+
const require_cx_index = require('../../cx/index.cjs');
|
|
5
|
+
let react = require("react");
|
|
6
|
+
let react_native = require("react-native");
|
|
7
|
+
|
|
8
|
+
//#region src/parser/jsx/native.ts
|
|
9
|
+
const nativeComponents = {
|
|
10
|
+
ActivityIndicator: react_native.ActivityIndicator,
|
|
11
|
+
FlatList: react_native.FlatList,
|
|
12
|
+
Image: react_native.Image,
|
|
13
|
+
Modal: react_native.Modal,
|
|
14
|
+
Pressable: react_native.Pressable,
|
|
15
|
+
SafeAreaView: react_native.SafeAreaView,
|
|
16
|
+
ScrollView: react_native.ScrollView,
|
|
17
|
+
SectionList: react_native.SectionList,
|
|
18
|
+
Switch: react_native.Switch,
|
|
19
|
+
Text: react_native.Text,
|
|
20
|
+
TextInput: react_native.TextInput,
|
|
21
|
+
TouchableHighlight: react_native.TouchableHighlight,
|
|
22
|
+
TouchableOpacity: react_native.TouchableOpacity,
|
|
23
|
+
TouchableWithoutFeedback: react_native.TouchableWithoutFeedback,
|
|
24
|
+
View: react_native.View
|
|
25
|
+
};
|
|
26
|
+
const registry = /* @__PURE__ */ new Map();
|
|
27
|
+
const resolveComponent = (tag) => {
|
|
28
|
+
if (!tag) return react_native.View;
|
|
29
|
+
if (typeof tag === "string") return nativeComponents[tag] ?? react_native.View;
|
|
30
|
+
return tag;
|
|
31
|
+
};
|
|
32
|
+
const getApi = () => {
|
|
33
|
+
if (!require_api_browser.api) throw new Error("Boss runtime API is not initialized.");
|
|
34
|
+
return require_api_browser.api;
|
|
35
|
+
};
|
|
36
|
+
function createComponent(tag) {
|
|
37
|
+
if (registry.has(tag)) return registry.get(tag);
|
|
38
|
+
const Component = (0, react.forwardRef)((props, ref) => {
|
|
39
|
+
return (0, react.createElement)(resolveComponent(tag), {
|
|
40
|
+
...props,
|
|
41
|
+
ref
|
|
42
|
+
}, props.children);
|
|
43
|
+
});
|
|
44
|
+
registry.set(tag, Component);
|
|
45
|
+
return Component;
|
|
46
|
+
}
|
|
47
|
+
const getDisplayName = (tag) => {
|
|
48
|
+
if (typeof tag === "string") return tag;
|
|
49
|
+
return tag?.displayName || tag?.name || "Component";
|
|
50
|
+
};
|
|
51
|
+
function factory(tag) {
|
|
52
|
+
return function $$(props, ref) {
|
|
53
|
+
if (tag || ref !== void 0) {
|
|
54
|
+
let tagName = tag;
|
|
55
|
+
const { children, as, ...rest } = props ?? {};
|
|
56
|
+
const resolvedTag = (typeof as === "string" ? as : void 0) || tagName || "View";
|
|
57
|
+
const displayName = getDisplayName(resolvedTag);
|
|
58
|
+
const Component = createComponent(resolvedTag);
|
|
59
|
+
Component.displayName = displayName ? "$$." + displayName : "$$";
|
|
60
|
+
const output = {};
|
|
61
|
+
getApi().trigger("onBrowserObjectStart", {
|
|
62
|
+
input: rest,
|
|
63
|
+
tag: resolvedTag,
|
|
64
|
+
output
|
|
65
|
+
});
|
|
66
|
+
return (0, react.createElement)(Component, output, children);
|
|
67
|
+
}
|
|
68
|
+
return props;
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
const defaultElement = factory("View");
|
|
72
|
+
defaultElement.displayName = "$$";
|
|
73
|
+
defaultElement.merge = require_merge_index.merge;
|
|
74
|
+
defaultElement.cx = require_cx_index.cx;
|
|
75
|
+
defaultElement.cv = require_cx_index.cv;
|
|
76
|
+
defaultElement.scv = require_cx_index.scv;
|
|
77
|
+
defaultElement.sv = require_cx_index.sv;
|
|
78
|
+
defaultElement.css = () => {};
|
|
79
|
+
defaultElement.$ = (input) => input;
|
|
80
|
+
const propIgnoreList = new Set([
|
|
81
|
+
"getDefaultProps",
|
|
82
|
+
"defaultProps",
|
|
83
|
+
"getDerivedStateFromProps",
|
|
84
|
+
"getChildContext",
|
|
85
|
+
"contextTypes",
|
|
86
|
+
"contextType",
|
|
87
|
+
"childContextTypes",
|
|
88
|
+
"propTypes",
|
|
89
|
+
"PropTypes"
|
|
90
|
+
]);
|
|
91
|
+
const proxy = new Proxy(defaultElement, {
|
|
92
|
+
get(target, prop) {
|
|
93
|
+
if (typeof prop === "symbol" || propIgnoreList.has(prop)) return void 0;
|
|
94
|
+
const targetRecord = target;
|
|
95
|
+
return targetRecord[prop] ||= factory(prop);
|
|
96
|
+
},
|
|
97
|
+
set(target, prop, value) {
|
|
98
|
+
if (typeof prop !== "string") return true;
|
|
99
|
+
const targetRecord = target;
|
|
100
|
+
targetRecord[prop] = typeof prop === "string" && /^[A-Z]/.test(prop) ? (props) => factory(value?.as || "View")({
|
|
101
|
+
...value,
|
|
102
|
+
...props
|
|
103
|
+
}) : value;
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
//#endregion
|
|
109
|
+
exports.factory = factory;
|
|
110
|
+
exports.proxy = proxy;
|