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,212 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/shared/customCss.ts
|
|
3
|
+
const isCssMemberExpression = (node) => {
|
|
4
|
+
if (!node || node.type !== "MemberExpression") return false;
|
|
5
|
+
if (node.object?.type !== "Identifier" || node.object.value !== "$$") return false;
|
|
6
|
+
const property = node.property;
|
|
7
|
+
if (property.type === "Identifier") return property.value === "css";
|
|
8
|
+
if (property.type === "StringLiteral") return property.value === "css";
|
|
9
|
+
return false;
|
|
10
|
+
};
|
|
11
|
+
const isCustomCssCall = (node) => {
|
|
12
|
+
return node.type === "CallExpression" && isCssMemberExpression(node.callee);
|
|
13
|
+
};
|
|
14
|
+
const isCustomCssTag = (node) => {
|
|
15
|
+
return node.type === "TaggedTemplateExpression" && isCssMemberExpression(node.tag);
|
|
16
|
+
};
|
|
17
|
+
const extractTemplateLiteral = (literal) => {
|
|
18
|
+
if (literal.expressions.length) return null;
|
|
19
|
+
const first = literal.quasis[0];
|
|
20
|
+
if (!first) return "";
|
|
21
|
+
return first.cooked ?? first.raw ?? "";
|
|
22
|
+
};
|
|
23
|
+
const parseStaticExpression = (expression) => {
|
|
24
|
+
if (!expression || typeof expression !== "object") return {
|
|
25
|
+
value: null,
|
|
26
|
+
dynamic: true
|
|
27
|
+
};
|
|
28
|
+
switch (expression.type) {
|
|
29
|
+
case "StringLiteral": return {
|
|
30
|
+
value: expression.value,
|
|
31
|
+
dynamic: false
|
|
32
|
+
};
|
|
33
|
+
case "NumericLiteral": return {
|
|
34
|
+
value: expression.value,
|
|
35
|
+
dynamic: false
|
|
36
|
+
};
|
|
37
|
+
case "BooleanLiteral": return {
|
|
38
|
+
value: expression.value,
|
|
39
|
+
dynamic: false
|
|
40
|
+
};
|
|
41
|
+
case "NullLiteral": return {
|
|
42
|
+
value: null,
|
|
43
|
+
dynamic: false
|
|
44
|
+
};
|
|
45
|
+
case "TemplateLiteral": {
|
|
46
|
+
const text = extractTemplateLiteral(expression);
|
|
47
|
+
if (text === null) return {
|
|
48
|
+
value: "",
|
|
49
|
+
dynamic: true
|
|
50
|
+
};
|
|
51
|
+
return {
|
|
52
|
+
value: text,
|
|
53
|
+
dynamic: false
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
case "ArrayExpression": return parseStaticArray(expression);
|
|
57
|
+
case "ObjectExpression": return parseStaticObject(expression);
|
|
58
|
+
case "UnaryExpression": return parseStaticUnary(expression);
|
|
59
|
+
case "ParenthesisExpression": return parseStaticExpression(expression.expression);
|
|
60
|
+
default: return {
|
|
61
|
+
value: null,
|
|
62
|
+
dynamic: true
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
const parseStaticArray = (expression) => {
|
|
67
|
+
const values = [];
|
|
68
|
+
let dynamic = false;
|
|
69
|
+
for (const entry of expression.elements) {
|
|
70
|
+
if (!entry || entry.expression == null) {
|
|
71
|
+
dynamic = true;
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
const parsed = parseStaticExpression(entry.expression);
|
|
75
|
+
dynamic ||= parsed.dynamic;
|
|
76
|
+
values.push(parsed.value);
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
value: values,
|
|
80
|
+
dynamic
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
const parseStaticUnary = (expression) => {
|
|
84
|
+
if (expression.operator !== "-") return {
|
|
85
|
+
value: null,
|
|
86
|
+
dynamic: true
|
|
87
|
+
};
|
|
88
|
+
const parsed = parseStaticExpression(expression.argument);
|
|
89
|
+
if (parsed.dynamic || typeof parsed.value !== "number") return {
|
|
90
|
+
value: null,
|
|
91
|
+
dynamic: true
|
|
92
|
+
};
|
|
93
|
+
return {
|
|
94
|
+
value: -parsed.value,
|
|
95
|
+
dynamic: false
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
const parseStaticObject = (expression) => {
|
|
99
|
+
const value = {};
|
|
100
|
+
let dynamic = false;
|
|
101
|
+
for (const prop of expression.properties) {
|
|
102
|
+
if (prop.type !== "KeyValueProperty") {
|
|
103
|
+
dynamic = true;
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
const { key, value: propValue } = prop;
|
|
107
|
+
if (!key) {
|
|
108
|
+
dynamic = true;
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
let keyName = "";
|
|
112
|
+
switch (key.type) {
|
|
113
|
+
case "Identifier":
|
|
114
|
+
keyName = key.value;
|
|
115
|
+
break;
|
|
116
|
+
case "StringLiteral":
|
|
117
|
+
keyName = key.value;
|
|
118
|
+
break;
|
|
119
|
+
case "NumericLiteral":
|
|
120
|
+
keyName = String(key.value);
|
|
121
|
+
break;
|
|
122
|
+
case "BigIntLiteral":
|
|
123
|
+
keyName = String(key.value);
|
|
124
|
+
break;
|
|
125
|
+
default:
|
|
126
|
+
dynamic = true;
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
const parsed = parseStaticExpression(propValue);
|
|
130
|
+
dynamic ||= parsed.dynamic;
|
|
131
|
+
value[keyName] = parsed.value;
|
|
132
|
+
}
|
|
133
|
+
return {
|
|
134
|
+
value,
|
|
135
|
+
dynamic
|
|
136
|
+
};
|
|
137
|
+
};
|
|
138
|
+
const normalizePropertyName = (api, name) => {
|
|
139
|
+
if (name.startsWith("--")) return name;
|
|
140
|
+
return api.camelCaseToDash ? api.camelCaseToDash(name) : name;
|
|
141
|
+
};
|
|
142
|
+
const resolveNestedSelector = (parent, child) => {
|
|
143
|
+
if (!parent) return child;
|
|
144
|
+
if (child.includes("&")) return child.split("&").join(parent);
|
|
145
|
+
return `${parent} ${child}`;
|
|
146
|
+
};
|
|
147
|
+
const serializeCssObject = (api, value, selector = null) => {
|
|
148
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return "";
|
|
149
|
+
const entries = Object.entries(value);
|
|
150
|
+
if (!entries.length) return "";
|
|
151
|
+
const declarations = [];
|
|
152
|
+
let nested = "";
|
|
153
|
+
for (const [key, entry] of entries) {
|
|
154
|
+
if (entry == null) continue;
|
|
155
|
+
if (typeof entry === "object" && !Array.isArray(entry)) {
|
|
156
|
+
if (key.startsWith("@")) {
|
|
157
|
+
const inner = serializeCssObject(api, entry, selector);
|
|
158
|
+
if (inner.trim()) nested += `${key} { ${inner} }`;
|
|
159
|
+
} else {
|
|
160
|
+
const inner = serializeCssObject(api, entry, resolveNestedSelector(selector, key));
|
|
161
|
+
if (inner.trim()) nested += inner;
|
|
162
|
+
}
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
const propertyName = normalizePropertyName(api, key);
|
|
166
|
+
const propertyValue = api.dictionary?.toValue ? api.dictionary.toValue(entry, propertyName) : entry;
|
|
167
|
+
declarations.push(`${propertyName}: ${propertyValue}`);
|
|
168
|
+
}
|
|
169
|
+
let output = "";
|
|
170
|
+
if (declarations.length) output += `${selector || ":root"} { ${declarations.join("; ")} }`;
|
|
171
|
+
if (nested.trim()) output += output ? `\n${nested}` : nested;
|
|
172
|
+
return output;
|
|
173
|
+
};
|
|
174
|
+
const extractCustomCssText = (expression, api) => {
|
|
175
|
+
if (isCustomCssTag(expression)) {
|
|
176
|
+
const raw = extractTemplateLiteral(expression.template);
|
|
177
|
+
if (raw === null) {
|
|
178
|
+
console.warn("[boss-css] $$.css template literals must be static (no expressions).");
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
181
|
+
return raw;
|
|
182
|
+
}
|
|
183
|
+
if (!isCustomCssCall(expression)) return null;
|
|
184
|
+
if (expression.arguments.length !== 1) {
|
|
185
|
+
console.warn("[boss-css] $$.css expects a single argument.");
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
188
|
+
const arg = expression.arguments[0]?.expression;
|
|
189
|
+
if (!arg) return null;
|
|
190
|
+
if (arg.type === "StringLiteral") return arg.value;
|
|
191
|
+
if (arg.type === "TemplateLiteral") {
|
|
192
|
+
const raw = extractTemplateLiteral(arg);
|
|
193
|
+
if (raw === null) {
|
|
194
|
+
console.warn("[boss-css] $$.css template literals must be static (no expressions).");
|
|
195
|
+
return null;
|
|
196
|
+
}
|
|
197
|
+
return raw;
|
|
198
|
+
}
|
|
199
|
+
if (arg.type === "ObjectExpression") {
|
|
200
|
+
const parsed = parseStaticObject(arg);
|
|
201
|
+
if (parsed.dynamic) {
|
|
202
|
+
console.warn("[boss-css] $$.css object arguments must be static.");
|
|
203
|
+
return null;
|
|
204
|
+
}
|
|
205
|
+
return serializeCssObject(api, parsed.value);
|
|
206
|
+
}
|
|
207
|
+
console.warn("[boss-css] $$.css only accepts string, template literal, or object arguments.");
|
|
208
|
+
return null;
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
//#endregion
|
|
212
|
+
exports.extractCustomCssText = extractCustomCssText;
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
//#region src/shared/customCss.ts
|
|
2
|
+
const isCssMemberExpression = (node) => {
|
|
3
|
+
if (!node || node.type !== "MemberExpression") return false;
|
|
4
|
+
if (node.object?.type !== "Identifier" || node.object.value !== "$$") return false;
|
|
5
|
+
const property = node.property;
|
|
6
|
+
if (property.type === "Identifier") return property.value === "css";
|
|
7
|
+
if (property.type === "StringLiteral") return property.value === "css";
|
|
8
|
+
return false;
|
|
9
|
+
};
|
|
10
|
+
const isCustomCssCall = (node) => {
|
|
11
|
+
return node.type === "CallExpression" && isCssMemberExpression(node.callee);
|
|
12
|
+
};
|
|
13
|
+
const isCustomCssTag = (node) => {
|
|
14
|
+
return node.type === "TaggedTemplateExpression" && isCssMemberExpression(node.tag);
|
|
15
|
+
};
|
|
16
|
+
const extractTemplateLiteral = (literal) => {
|
|
17
|
+
if (literal.expressions.length) return null;
|
|
18
|
+
const first = literal.quasis[0];
|
|
19
|
+
if (!first) return "";
|
|
20
|
+
return first.cooked ?? first.raw ?? "";
|
|
21
|
+
};
|
|
22
|
+
const parseStaticExpression = (expression) => {
|
|
23
|
+
if (!expression || typeof expression !== "object") return {
|
|
24
|
+
value: null,
|
|
25
|
+
dynamic: true
|
|
26
|
+
};
|
|
27
|
+
switch (expression.type) {
|
|
28
|
+
case "StringLiteral": return {
|
|
29
|
+
value: expression.value,
|
|
30
|
+
dynamic: false
|
|
31
|
+
};
|
|
32
|
+
case "NumericLiteral": return {
|
|
33
|
+
value: expression.value,
|
|
34
|
+
dynamic: false
|
|
35
|
+
};
|
|
36
|
+
case "BooleanLiteral": return {
|
|
37
|
+
value: expression.value,
|
|
38
|
+
dynamic: false
|
|
39
|
+
};
|
|
40
|
+
case "NullLiteral": return {
|
|
41
|
+
value: null,
|
|
42
|
+
dynamic: false
|
|
43
|
+
};
|
|
44
|
+
case "TemplateLiteral": {
|
|
45
|
+
const text = extractTemplateLiteral(expression);
|
|
46
|
+
if (text === null) return {
|
|
47
|
+
value: "",
|
|
48
|
+
dynamic: true
|
|
49
|
+
};
|
|
50
|
+
return {
|
|
51
|
+
value: text,
|
|
52
|
+
dynamic: false
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
case "ArrayExpression": return parseStaticArray(expression);
|
|
56
|
+
case "ObjectExpression": return parseStaticObject(expression);
|
|
57
|
+
case "UnaryExpression": return parseStaticUnary(expression);
|
|
58
|
+
case "ParenthesisExpression": return parseStaticExpression(expression.expression);
|
|
59
|
+
default: return {
|
|
60
|
+
value: null,
|
|
61
|
+
dynamic: true
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
const parseStaticArray = (expression) => {
|
|
66
|
+
const values = [];
|
|
67
|
+
let dynamic = false;
|
|
68
|
+
for (const entry of expression.elements) {
|
|
69
|
+
if (!entry || entry.expression == null) {
|
|
70
|
+
dynamic = true;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
const parsed = parseStaticExpression(entry.expression);
|
|
74
|
+
dynamic ||= parsed.dynamic;
|
|
75
|
+
values.push(parsed.value);
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
value: values,
|
|
79
|
+
dynamic
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
const parseStaticUnary = (expression) => {
|
|
83
|
+
if (expression.operator !== "-") return {
|
|
84
|
+
value: null,
|
|
85
|
+
dynamic: true
|
|
86
|
+
};
|
|
87
|
+
const parsed = parseStaticExpression(expression.argument);
|
|
88
|
+
if (parsed.dynamic || typeof parsed.value !== "number") return {
|
|
89
|
+
value: null,
|
|
90
|
+
dynamic: true
|
|
91
|
+
};
|
|
92
|
+
return {
|
|
93
|
+
value: -parsed.value,
|
|
94
|
+
dynamic: false
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
const parseStaticObject = (expression) => {
|
|
98
|
+
const value = {};
|
|
99
|
+
let dynamic = false;
|
|
100
|
+
for (const prop of expression.properties) {
|
|
101
|
+
if (prop.type !== "KeyValueProperty") {
|
|
102
|
+
dynamic = true;
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
const { key, value: propValue } = prop;
|
|
106
|
+
if (!key) {
|
|
107
|
+
dynamic = true;
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
let keyName = "";
|
|
111
|
+
switch (key.type) {
|
|
112
|
+
case "Identifier":
|
|
113
|
+
keyName = key.value;
|
|
114
|
+
break;
|
|
115
|
+
case "StringLiteral":
|
|
116
|
+
keyName = key.value;
|
|
117
|
+
break;
|
|
118
|
+
case "NumericLiteral":
|
|
119
|
+
keyName = String(key.value);
|
|
120
|
+
break;
|
|
121
|
+
case "BigIntLiteral":
|
|
122
|
+
keyName = String(key.value);
|
|
123
|
+
break;
|
|
124
|
+
default:
|
|
125
|
+
dynamic = true;
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
const parsed = parseStaticExpression(propValue);
|
|
129
|
+
dynamic ||= parsed.dynamic;
|
|
130
|
+
value[keyName] = parsed.value;
|
|
131
|
+
}
|
|
132
|
+
return {
|
|
133
|
+
value,
|
|
134
|
+
dynamic
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
const normalizePropertyName = (api, name) => {
|
|
138
|
+
if (name.startsWith("--")) return name;
|
|
139
|
+
return api.camelCaseToDash ? api.camelCaseToDash(name) : name;
|
|
140
|
+
};
|
|
141
|
+
const resolveNestedSelector = (parent, child) => {
|
|
142
|
+
if (!parent) return child;
|
|
143
|
+
if (child.includes("&")) return child.split("&").join(parent);
|
|
144
|
+
return `${parent} ${child}`;
|
|
145
|
+
};
|
|
146
|
+
const serializeCssObject = (api, value, selector = null) => {
|
|
147
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return "";
|
|
148
|
+
const entries = Object.entries(value);
|
|
149
|
+
if (!entries.length) return "";
|
|
150
|
+
const declarations = [];
|
|
151
|
+
let nested = "";
|
|
152
|
+
for (const [key, entry] of entries) {
|
|
153
|
+
if (entry == null) continue;
|
|
154
|
+
if (typeof entry === "object" && !Array.isArray(entry)) {
|
|
155
|
+
if (key.startsWith("@")) {
|
|
156
|
+
const inner = serializeCssObject(api, entry, selector);
|
|
157
|
+
if (inner.trim()) nested += `${key} { ${inner} }`;
|
|
158
|
+
} else {
|
|
159
|
+
const inner = serializeCssObject(api, entry, resolveNestedSelector(selector, key));
|
|
160
|
+
if (inner.trim()) nested += inner;
|
|
161
|
+
}
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
const propertyName = normalizePropertyName(api, key);
|
|
165
|
+
const propertyValue = api.dictionary?.toValue ? api.dictionary.toValue(entry, propertyName) : entry;
|
|
166
|
+
declarations.push(`${propertyName}: ${propertyValue}`);
|
|
167
|
+
}
|
|
168
|
+
let output = "";
|
|
169
|
+
if (declarations.length) output += `${selector || ":root"} { ${declarations.join("; ")} }`;
|
|
170
|
+
if (nested.trim()) output += output ? `\n${nested}` : nested;
|
|
171
|
+
return output;
|
|
172
|
+
};
|
|
173
|
+
const extractCustomCssText = (expression, api) => {
|
|
174
|
+
if (isCustomCssTag(expression)) {
|
|
175
|
+
const raw = extractTemplateLiteral(expression.template);
|
|
176
|
+
if (raw === null) {
|
|
177
|
+
console.warn("[boss-css] $$.css template literals must be static (no expressions).");
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
return raw;
|
|
181
|
+
}
|
|
182
|
+
if (!isCustomCssCall(expression)) return null;
|
|
183
|
+
if (expression.arguments.length !== 1) {
|
|
184
|
+
console.warn("[boss-css] $$.css expects a single argument.");
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
const arg = expression.arguments[0]?.expression;
|
|
188
|
+
if (!arg) return null;
|
|
189
|
+
if (arg.type === "StringLiteral") return arg.value;
|
|
190
|
+
if (arg.type === "TemplateLiteral") {
|
|
191
|
+
const raw = extractTemplateLiteral(arg);
|
|
192
|
+
if (raw === null) {
|
|
193
|
+
console.warn("[boss-css] $$.css template literals must be static (no expressions).");
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
return raw;
|
|
197
|
+
}
|
|
198
|
+
if (arg.type === "ObjectExpression") {
|
|
199
|
+
const parsed = parseStaticObject(arg);
|
|
200
|
+
if (parsed.dynamic) {
|
|
201
|
+
console.warn("[boss-css] $$.css object arguments must be static.");
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
return serializeCssObject(api, parsed.value);
|
|
205
|
+
}
|
|
206
|
+
console.warn("[boss-css] $$.css only accepts string, template literal, or object arguments.");
|
|
207
|
+
return null;
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
//#endregion
|
|
211
|
+
export { extractCustomCssText };
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/shared/debug.ts
|
|
3
|
+
const truthyValues = new Set([
|
|
4
|
+
"1",
|
|
5
|
+
"true",
|
|
6
|
+
"yes",
|
|
7
|
+
"on"
|
|
8
|
+
]);
|
|
9
|
+
const falsyValues = new Set([
|
|
10
|
+
"0",
|
|
11
|
+
"false",
|
|
12
|
+
"no",
|
|
13
|
+
"off"
|
|
14
|
+
]);
|
|
15
|
+
const normalizeDebugValue = (value) => {
|
|
16
|
+
if (value === void 0 || value === null) return void 0;
|
|
17
|
+
if (typeof value === "boolean") return value;
|
|
18
|
+
if (typeof value === "number") return value > 0;
|
|
19
|
+
if (typeof value !== "string") return void 0;
|
|
20
|
+
const trimmed = value.trim();
|
|
21
|
+
if (!trimmed) return void 0;
|
|
22
|
+
const lowered = trimmed.toLowerCase();
|
|
23
|
+
if (truthyValues.has(lowered)) return true;
|
|
24
|
+
if (falsyValues.has(lowered)) return false;
|
|
25
|
+
return trimmed;
|
|
26
|
+
};
|
|
27
|
+
const readLocalStorageDebug = () => {
|
|
28
|
+
if (typeof localStorage === "undefined") return void 0;
|
|
29
|
+
try {
|
|
30
|
+
return normalizeDebugValue(localStorage.getItem("BOSS_DEBUG"));
|
|
31
|
+
} catch {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const readGlobalDebug = () => {
|
|
36
|
+
if (typeof globalThis === "undefined") return void 0;
|
|
37
|
+
return normalizeDebugValue(globalThis.BOSS_DEBUG);
|
|
38
|
+
};
|
|
39
|
+
const readEnvDebug = () => {
|
|
40
|
+
if (typeof process === "undefined" || !process.env) return void 0;
|
|
41
|
+
return normalizeDebugValue(process.env.BOSS_DEBUG);
|
|
42
|
+
};
|
|
43
|
+
const resolveDebugValue = (explicit) => {
|
|
44
|
+
if (explicit !== void 0) return explicit;
|
|
45
|
+
const fromStorage = readLocalStorageDebug();
|
|
46
|
+
if (fromStorage !== void 0) return fromStorage;
|
|
47
|
+
const fromGlobal = readGlobalDebug();
|
|
48
|
+
if (fromGlobal !== void 0) return fromGlobal;
|
|
49
|
+
return readEnvDebug();
|
|
50
|
+
};
|
|
51
|
+
const escapeRegexp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
52
|
+
const createDebugMatcher = (debug) => {
|
|
53
|
+
if (debug === true) return () => true;
|
|
54
|
+
if (!debug || debug === false) return () => false;
|
|
55
|
+
const rawPatterns = debug.split(/[\s,]+/).map((pattern) => pattern.trim()).filter(Boolean);
|
|
56
|
+
if (!rawPatterns.length) return () => false;
|
|
57
|
+
const includes = [];
|
|
58
|
+
const excludes = [];
|
|
59
|
+
for (const pattern of rawPatterns) {
|
|
60
|
+
const isExclude = pattern.startsWith("-");
|
|
61
|
+
const raw = isExclude ? pattern.slice(1) : pattern;
|
|
62
|
+
if (!raw) continue;
|
|
63
|
+
const regex = /* @__PURE__ */ new RegExp(`^${escapeRegexp(raw).replace(/\\\*/g, ".*?")}$`);
|
|
64
|
+
if (isExclude) excludes.push(regex);
|
|
65
|
+
else includes.push(regex);
|
|
66
|
+
}
|
|
67
|
+
return (namespace) => {
|
|
68
|
+
if (excludes.some((regex) => regex.test(namespace))) return false;
|
|
69
|
+
if (!includes.length) return false;
|
|
70
|
+
return includes.some((regex) => regex.test(namespace));
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
//#endregion
|
|
75
|
+
exports.createDebugMatcher = createDebugMatcher;
|
|
76
|
+
exports.resolveDebugValue = resolveDebugValue;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
//#region src/shared/debug.ts
|
|
2
|
+
const truthyValues = new Set([
|
|
3
|
+
"1",
|
|
4
|
+
"true",
|
|
5
|
+
"yes",
|
|
6
|
+
"on"
|
|
7
|
+
]);
|
|
8
|
+
const falsyValues = new Set([
|
|
9
|
+
"0",
|
|
10
|
+
"false",
|
|
11
|
+
"no",
|
|
12
|
+
"off"
|
|
13
|
+
]);
|
|
14
|
+
const normalizeDebugValue = (value) => {
|
|
15
|
+
if (value === void 0 || value === null) return void 0;
|
|
16
|
+
if (typeof value === "boolean") return value;
|
|
17
|
+
if (typeof value === "number") return value > 0;
|
|
18
|
+
if (typeof value !== "string") return void 0;
|
|
19
|
+
const trimmed = value.trim();
|
|
20
|
+
if (!trimmed) return void 0;
|
|
21
|
+
const lowered = trimmed.toLowerCase();
|
|
22
|
+
if (truthyValues.has(lowered)) return true;
|
|
23
|
+
if (falsyValues.has(lowered)) return false;
|
|
24
|
+
return trimmed;
|
|
25
|
+
};
|
|
26
|
+
const readLocalStorageDebug = () => {
|
|
27
|
+
if (typeof localStorage === "undefined") return void 0;
|
|
28
|
+
try {
|
|
29
|
+
return normalizeDebugValue(localStorage.getItem("BOSS_DEBUG"));
|
|
30
|
+
} catch {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
const readGlobalDebug = () => {
|
|
35
|
+
if (typeof globalThis === "undefined") return void 0;
|
|
36
|
+
return normalizeDebugValue(globalThis.BOSS_DEBUG);
|
|
37
|
+
};
|
|
38
|
+
const readEnvDebug = () => {
|
|
39
|
+
if (typeof process === "undefined" || !process.env) return void 0;
|
|
40
|
+
return normalizeDebugValue(process.env.BOSS_DEBUG);
|
|
41
|
+
};
|
|
42
|
+
const resolveDebugValue = (explicit) => {
|
|
43
|
+
if (explicit !== void 0) return explicit;
|
|
44
|
+
const fromStorage = readLocalStorageDebug();
|
|
45
|
+
if (fromStorage !== void 0) return fromStorage;
|
|
46
|
+
const fromGlobal = readGlobalDebug();
|
|
47
|
+
if (fromGlobal !== void 0) return fromGlobal;
|
|
48
|
+
return readEnvDebug();
|
|
49
|
+
};
|
|
50
|
+
const escapeRegexp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
51
|
+
const createDebugMatcher = (debug) => {
|
|
52
|
+
if (debug === true) return () => true;
|
|
53
|
+
if (!debug || debug === false) return () => false;
|
|
54
|
+
const rawPatterns = debug.split(/[\s,]+/).map((pattern) => pattern.trim()).filter(Boolean);
|
|
55
|
+
if (!rawPatterns.length) return () => false;
|
|
56
|
+
const includes = [];
|
|
57
|
+
const excludes = [];
|
|
58
|
+
for (const pattern of rawPatterns) {
|
|
59
|
+
const isExclude = pattern.startsWith("-");
|
|
60
|
+
const raw = isExclude ? pattern.slice(1) : pattern;
|
|
61
|
+
if (!raw) continue;
|
|
62
|
+
const regex = /* @__PURE__ */ new RegExp(`^${escapeRegexp(raw).replace(/\\\*/g, ".*?")}$`);
|
|
63
|
+
if (isExclude) excludes.push(regex);
|
|
64
|
+
else includes.push(regex);
|
|
65
|
+
}
|
|
66
|
+
return (namespace) => {
|
|
67
|
+
if (excludes.some((regex) => regex.test(namespace))) return false;
|
|
68
|
+
if (!includes.length) return false;
|
|
69
|
+
return includes.some((regex) => regex.test(namespace));
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
//#endregion
|
|
74
|
+
export { createDebugMatcher, resolveDebugValue };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let fast_glob = require("fast-glob");
|
|
3
|
+
fast_glob = require_rolldown_runtime.__toESM(fast_glob);
|
|
4
|
+
|
|
5
|
+
//#region src/shared/file.ts
|
|
6
|
+
const DEFAULT_IGNORE = [
|
|
7
|
+
"**/node_modules/**",
|
|
8
|
+
"**/.bo$$/**",
|
|
9
|
+
"**/dist/**"
|
|
10
|
+
];
|
|
11
|
+
const resolveContentPaths = async (content) => {
|
|
12
|
+
return (0, fast_glob.default)(content, {
|
|
13
|
+
onlyFiles: false,
|
|
14
|
+
absolute: true,
|
|
15
|
+
cwd: process.cwd(),
|
|
16
|
+
ignore: DEFAULT_IGNORE
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
21
|
+
exports.resolveContentPaths = resolveContentPaths;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import fg from "fast-glob";
|
|
2
|
+
|
|
3
|
+
//#region src/shared/file.ts
|
|
4
|
+
const DEFAULT_IGNORE = [
|
|
5
|
+
"**/node_modules/**",
|
|
6
|
+
"**/.bo$$/**",
|
|
7
|
+
"**/dist/**"
|
|
8
|
+
];
|
|
9
|
+
const resolveContentPaths = async (content) => {
|
|
10
|
+
return fg(content, {
|
|
11
|
+
onlyFiles: false,
|
|
12
|
+
absolute: true,
|
|
13
|
+
cwd: process.cwd(),
|
|
14
|
+
ignore: DEFAULT_IGNORE
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
export { resolveContentPaths };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/shared/framework.ts
|
|
3
|
+
const getClassNameProp = (framework) => {
|
|
4
|
+
if (!framework || typeof framework === "string") return "className";
|
|
5
|
+
if ("className" in framework && framework.className) return framework.className;
|
|
6
|
+
return "className";
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
//#endregion
|
|
10
|
+
exports.getClassNameProp = getClassNameProp;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region src/shared/framework.ts
|
|
2
|
+
const getClassNameProp = (framework) => {
|
|
3
|
+
if (!framework || typeof framework === "string") return "className";
|
|
4
|
+
if ("className" in framework && framework.className) return framework.className;
|
|
5
|
+
return "className";
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
//#endregion
|
|
9
|
+
export { getClassNameProp };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/shared/json.ts
|
|
3
|
+
const stripTrailingCommas = (input) => {
|
|
4
|
+
let output = "";
|
|
5
|
+
let inString = false;
|
|
6
|
+
let stringChar = "";
|
|
7
|
+
let escaped = false;
|
|
8
|
+
for (let index = 0; index < input.length; index += 1) {
|
|
9
|
+
const char = input[index];
|
|
10
|
+
if (inString) {
|
|
11
|
+
output += char;
|
|
12
|
+
if (escaped) {
|
|
13
|
+
escaped = false;
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
if (char === "\\") {
|
|
17
|
+
escaped = true;
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
if (char === stringChar) {
|
|
21
|
+
inString = false;
|
|
22
|
+
stringChar = "";
|
|
23
|
+
}
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
if (char === "\"" || char === "'") {
|
|
27
|
+
inString = true;
|
|
28
|
+
stringChar = char;
|
|
29
|
+
output += char;
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
if (char === ",") {
|
|
33
|
+
let lookahead = index + 1;
|
|
34
|
+
while (lookahead < input.length && /\s/.test(input[lookahead])) lookahead += 1;
|
|
35
|
+
const nextChar = input[lookahead];
|
|
36
|
+
if (nextChar === "}" || nextChar === "]") continue;
|
|
37
|
+
}
|
|
38
|
+
output += char;
|
|
39
|
+
}
|
|
40
|
+
return output;
|
|
41
|
+
};
|
|
42
|
+
const parseJson = (input, options) => {
|
|
43
|
+
try {
|
|
44
|
+
return JSON.parse(input);
|
|
45
|
+
} catch (error) {
|
|
46
|
+
if (!options?.allowTrailingCommas) throw error;
|
|
47
|
+
const stripped = stripTrailingCommas(input);
|
|
48
|
+
if (stripped !== input) try {
|
|
49
|
+
return JSON.parse(stripped);
|
|
50
|
+
} catch {}
|
|
51
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
52
|
+
const fileHint = options?.filePath ? ` in ${options.filePath}` : "";
|
|
53
|
+
throw new Error(`Failed to parse JSON${fileHint}: ${message}`);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
//#endregion
|
|
58
|
+
exports.parseJson = parseJson;
|