@csszyx/compiler 0.1.1 → 0.1.3
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/dist/index.cjs +99 -5
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +99 -5
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -60,10 +60,6 @@ module.exports = __toCommonJS(index_exports);
|
|
|
60
60
|
// src/compiler.ts
|
|
61
61
|
var import_core = require("@csszyx/core");
|
|
62
62
|
|
|
63
|
-
// src/transform.ts
|
|
64
|
-
var babel = __toESM(require("@babel/core"), 1);
|
|
65
|
-
var t = __toESM(require("@babel/types"), 1);
|
|
66
|
-
|
|
67
63
|
// src/property-types.ts
|
|
68
64
|
var PropertyCategory = /* @__PURE__ */ ((PropertyCategory2) => {
|
|
69
65
|
PropertyCategory2[PropertyCategory2["SPACING"] = 0] = "SPACING";
|
|
@@ -230,6 +226,81 @@ function getCSSVariableName(property, variantPrefix) {
|
|
|
230
226
|
return `--_sz-${prop}`;
|
|
231
227
|
}
|
|
232
228
|
|
|
229
|
+
// src/color-validation.ts
|
|
230
|
+
var COLOR_STRING_KEYWORDS = /* @__PURE__ */ new Set([
|
|
231
|
+
"inherit",
|
|
232
|
+
"current",
|
|
233
|
+
"transparent",
|
|
234
|
+
"black",
|
|
235
|
+
"white",
|
|
236
|
+
"none"
|
|
237
|
+
]);
|
|
238
|
+
function isValidColorString(value) {
|
|
239
|
+
if (COLOR_STRING_KEYWORDS.has(value)) {
|
|
240
|
+
return true;
|
|
241
|
+
}
|
|
242
|
+
if (value.startsWith("--")) {
|
|
243
|
+
return true;
|
|
244
|
+
}
|
|
245
|
+
if (value.startsWith("#")) {
|
|
246
|
+
return true;
|
|
247
|
+
}
|
|
248
|
+
if (value.startsWith("[") && value.endsWith("]")) {
|
|
249
|
+
return true;
|
|
250
|
+
}
|
|
251
|
+
if (/^(rgb|hsl|oklch|color|hwb|lab|lch|oklab)\(/.test(value)) {
|
|
252
|
+
return true;
|
|
253
|
+
}
|
|
254
|
+
if (/^[a-zA-Z][a-zA-Z0-9]*(-[a-zA-Z0-9]+)*-\d+$/.test(value)) {
|
|
255
|
+
return true;
|
|
256
|
+
}
|
|
257
|
+
return false;
|
|
258
|
+
}
|
|
259
|
+
function hasSlashOpacity(value) {
|
|
260
|
+
const slashIdx = value.indexOf("/");
|
|
261
|
+
if (slashIdx === -1) {
|
|
262
|
+
return false;
|
|
263
|
+
}
|
|
264
|
+
return slashIdx > 0 && /\d$/.test(value.slice(0, slashIdx));
|
|
265
|
+
}
|
|
266
|
+
function stripInvalidColorStrings(sz) {
|
|
267
|
+
const result = {};
|
|
268
|
+
for (const [key, value] of Object.entries(sz)) {
|
|
269
|
+
if (typeof value === "object" && value !== null && !Array.isArray(value)) {
|
|
270
|
+
result[key] = stripInvalidColorStrings(value);
|
|
271
|
+
continue;
|
|
272
|
+
}
|
|
273
|
+
if (typeof value === "string" && PROPERTY_CATEGORY_MAP[key] === 1 /* COLOR */) {
|
|
274
|
+
const strVal = value.replace(/!$/, "");
|
|
275
|
+
if (hasSlashOpacity(strVal)) {
|
|
276
|
+
if (process.env["NODE_ENV"] !== "production" && typeof window === "undefined") {
|
|
277
|
+
const slashIdx = strVal.indexOf("/");
|
|
278
|
+
const colorPart = strVal.slice(0, slashIdx);
|
|
279
|
+
const opPart = strVal.slice(slashIdx + 1);
|
|
280
|
+
console.warn(
|
|
281
|
+
`[csszyx] "${key}: '${strVal}'" \u2014 string slash opacity is not supported. Use object form: { color: '${colorPart}', op: ${opPart} }.`
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
continue;
|
|
285
|
+
}
|
|
286
|
+
if (!isValidColorString(strVal)) {
|
|
287
|
+
if (process.env["NODE_ENV"] !== "production" && typeof window === "undefined") {
|
|
288
|
+
console.warn(
|
|
289
|
+
`[csszyx] "${key}: '${strVal}'" is not a recognized color value and will be ignored. Use a Tailwind color ("blue-500"), CSS variable ("--my-color"), hex/rgb/hsl ("#ff0000"), or object form ({ color: "blue-500", op: 50 }).`
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
continue;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
result[key] = value;
|
|
296
|
+
}
|
|
297
|
+
return result;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// src/transform.ts
|
|
301
|
+
var babel = __toESM(require("@babel/core"), 1);
|
|
302
|
+
var t = __toESM(require("@babel/types"), 1);
|
|
303
|
+
|
|
233
304
|
// src/transform-core.ts
|
|
234
305
|
var PROPERTY_MAP = {
|
|
235
306
|
// Background
|
|
@@ -1324,6 +1395,28 @@ function transform(szProp, prefix = "", mangleMap) {
|
|
|
1324
1395
|
}
|
|
1325
1396
|
continue;
|
|
1326
1397
|
}
|
|
1398
|
+
if (typeof value === "string" && PROPERTY_CATEGORY_MAP[rawKey] === 1 /* COLOR */) {
|
|
1399
|
+
const strVal = value.replace(/!$/, "");
|
|
1400
|
+
if (hasSlashOpacity(strVal)) {
|
|
1401
|
+
if (process.env["NODE_ENV"] !== "production" && typeof window === "undefined") {
|
|
1402
|
+
const slashIdx = strVal.indexOf("/");
|
|
1403
|
+
const colorPart = strVal.slice(0, slashIdx);
|
|
1404
|
+
const opPart = strVal.slice(slashIdx + 1);
|
|
1405
|
+
console.warn(
|
|
1406
|
+
`[csszyx] "${rawKey}: '${strVal}'" \u2014 string slash opacity is not supported. Use object form: { color: '${colorPart}', op: ${opPart} }.`
|
|
1407
|
+
);
|
|
1408
|
+
}
|
|
1409
|
+
continue;
|
|
1410
|
+
}
|
|
1411
|
+
if (!isValidColorString(strVal)) {
|
|
1412
|
+
if (process.env["NODE_ENV"] !== "production" && typeof window === "undefined") {
|
|
1413
|
+
console.warn(
|
|
1414
|
+
`[csszyx] "${rawKey}: '${strVal}'" is not a recognized color value and will be ignored. Use a Tailwind color ("blue-500"), CSS variable ("--my-color"), hex/rgb/hsl ("#ff0000"), or object form ({ color: "blue-500", op: 50 }).`
|
|
1415
|
+
);
|
|
1416
|
+
}
|
|
1417
|
+
continue;
|
|
1418
|
+
}
|
|
1419
|
+
}
|
|
1327
1420
|
if (typeof value === "object" && !Array.isArray(value)) {
|
|
1328
1421
|
if (rawKey === "group") {
|
|
1329
1422
|
const groupClasses = handleGroupPeer("group", value, prefix);
|
|
@@ -2480,8 +2573,9 @@ var CsszyxCompiler = class _CsszyxCompiler {
|
|
|
2480
2573
|
*/
|
|
2481
2574
|
transform(sz) {
|
|
2482
2575
|
if (this.wasmLoaded) {
|
|
2576
|
+
const cleaned = stripInvalidColorStrings(sz);
|
|
2483
2577
|
try {
|
|
2484
|
-
return (0, import_core.transform_sz)(
|
|
2578
|
+
return (0, import_core.transform_sz)(cleaned);
|
|
2485
2579
|
} catch (error) {
|
|
2486
2580
|
console.warn(
|
|
2487
2581
|
"[csszyx] WASM transformation failed, using JS fallback",
|
package/dist/index.d.cts
CHANGED
|
@@ -876,7 +876,7 @@ interface BackgroundProps {
|
|
|
876
876
|
/** @see https://tailwindcss.com/docs/background-clip */
|
|
877
877
|
bgClip?: 'border' | 'padding' | 'content' | 'text';
|
|
878
878
|
/** @see https://tailwindcss.com/docs/background-color */
|
|
879
|
-
bg?: ColorPropValue
|
|
879
|
+
bg?: ColorPropValue;
|
|
880
880
|
/** @see https://tailwindcss.com/docs/background-origin */
|
|
881
881
|
bgOrigin?: 'border' | 'padding' | 'content';
|
|
882
882
|
/** @see https://tailwindcss.com/docs/background-position */
|
package/dist/index.d.ts
CHANGED
|
@@ -876,7 +876,7 @@ interface BackgroundProps {
|
|
|
876
876
|
/** @see https://tailwindcss.com/docs/background-clip */
|
|
877
877
|
bgClip?: 'border' | 'padding' | 'content' | 'text';
|
|
878
878
|
/** @see https://tailwindcss.com/docs/background-color */
|
|
879
|
-
bg?: ColorPropValue
|
|
879
|
+
bg?: ColorPropValue;
|
|
880
880
|
/** @see https://tailwindcss.com/docs/background-origin */
|
|
881
881
|
bgOrigin?: 'border' | 'padding' | 'content';
|
|
882
882
|
/** @see https://tailwindcss.com/docs/background-position */
|
package/dist/index.js
CHANGED
|
@@ -8,10 +8,6 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
8
8
|
// src/compiler.ts
|
|
9
9
|
import { init, transform_sz, version as getWasmVersion } from "@csszyx/core";
|
|
10
10
|
|
|
11
|
-
// src/transform.ts
|
|
12
|
-
import * as babel from "@babel/core";
|
|
13
|
-
import * as t from "@babel/types";
|
|
14
|
-
|
|
15
11
|
// src/property-types.ts
|
|
16
12
|
var PropertyCategory = /* @__PURE__ */ ((PropertyCategory2) => {
|
|
17
13
|
PropertyCategory2[PropertyCategory2["SPACING"] = 0] = "SPACING";
|
|
@@ -178,6 +174,81 @@ function getCSSVariableName(property, variantPrefix) {
|
|
|
178
174
|
return `--_sz-${prop}`;
|
|
179
175
|
}
|
|
180
176
|
|
|
177
|
+
// src/color-validation.ts
|
|
178
|
+
var COLOR_STRING_KEYWORDS = /* @__PURE__ */ new Set([
|
|
179
|
+
"inherit",
|
|
180
|
+
"current",
|
|
181
|
+
"transparent",
|
|
182
|
+
"black",
|
|
183
|
+
"white",
|
|
184
|
+
"none"
|
|
185
|
+
]);
|
|
186
|
+
function isValidColorString(value) {
|
|
187
|
+
if (COLOR_STRING_KEYWORDS.has(value)) {
|
|
188
|
+
return true;
|
|
189
|
+
}
|
|
190
|
+
if (value.startsWith("--")) {
|
|
191
|
+
return true;
|
|
192
|
+
}
|
|
193
|
+
if (value.startsWith("#")) {
|
|
194
|
+
return true;
|
|
195
|
+
}
|
|
196
|
+
if (value.startsWith("[") && value.endsWith("]")) {
|
|
197
|
+
return true;
|
|
198
|
+
}
|
|
199
|
+
if (/^(rgb|hsl|oklch|color|hwb|lab|lch|oklab)\(/.test(value)) {
|
|
200
|
+
return true;
|
|
201
|
+
}
|
|
202
|
+
if (/^[a-zA-Z][a-zA-Z0-9]*(-[a-zA-Z0-9]+)*-\d+$/.test(value)) {
|
|
203
|
+
return true;
|
|
204
|
+
}
|
|
205
|
+
return false;
|
|
206
|
+
}
|
|
207
|
+
function hasSlashOpacity(value) {
|
|
208
|
+
const slashIdx = value.indexOf("/");
|
|
209
|
+
if (slashIdx === -1) {
|
|
210
|
+
return false;
|
|
211
|
+
}
|
|
212
|
+
return slashIdx > 0 && /\d$/.test(value.slice(0, slashIdx));
|
|
213
|
+
}
|
|
214
|
+
function stripInvalidColorStrings(sz) {
|
|
215
|
+
const result = {};
|
|
216
|
+
for (const [key, value] of Object.entries(sz)) {
|
|
217
|
+
if (typeof value === "object" && value !== null && !Array.isArray(value)) {
|
|
218
|
+
result[key] = stripInvalidColorStrings(value);
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
if (typeof value === "string" && PROPERTY_CATEGORY_MAP[key] === 1 /* COLOR */) {
|
|
222
|
+
const strVal = value.replace(/!$/, "");
|
|
223
|
+
if (hasSlashOpacity(strVal)) {
|
|
224
|
+
if (process.env["NODE_ENV"] !== "production" && typeof window === "undefined") {
|
|
225
|
+
const slashIdx = strVal.indexOf("/");
|
|
226
|
+
const colorPart = strVal.slice(0, slashIdx);
|
|
227
|
+
const opPart = strVal.slice(slashIdx + 1);
|
|
228
|
+
console.warn(
|
|
229
|
+
`[csszyx] "${key}: '${strVal}'" \u2014 string slash opacity is not supported. Use object form: { color: '${colorPart}', op: ${opPart} }.`
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
if (!isValidColorString(strVal)) {
|
|
235
|
+
if (process.env["NODE_ENV"] !== "production" && typeof window === "undefined") {
|
|
236
|
+
console.warn(
|
|
237
|
+
`[csszyx] "${key}: '${strVal}'" is not a recognized color value and will be ignored. Use a Tailwind color ("blue-500"), CSS variable ("--my-color"), hex/rgb/hsl ("#ff0000"), or object form ({ color: "blue-500", op: 50 }).`
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
continue;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
result[key] = value;
|
|
244
|
+
}
|
|
245
|
+
return result;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// src/transform.ts
|
|
249
|
+
import * as babel from "@babel/core";
|
|
250
|
+
import * as t from "@babel/types";
|
|
251
|
+
|
|
181
252
|
// src/transform-core.ts
|
|
182
253
|
var PROPERTY_MAP = {
|
|
183
254
|
// Background
|
|
@@ -1272,6 +1343,28 @@ function transform(szProp, prefix = "", mangleMap) {
|
|
|
1272
1343
|
}
|
|
1273
1344
|
continue;
|
|
1274
1345
|
}
|
|
1346
|
+
if (typeof value === "string" && PROPERTY_CATEGORY_MAP[rawKey] === 1 /* COLOR */) {
|
|
1347
|
+
const strVal = value.replace(/!$/, "");
|
|
1348
|
+
if (hasSlashOpacity(strVal)) {
|
|
1349
|
+
if (process.env["NODE_ENV"] !== "production" && typeof window === "undefined") {
|
|
1350
|
+
const slashIdx = strVal.indexOf("/");
|
|
1351
|
+
const colorPart = strVal.slice(0, slashIdx);
|
|
1352
|
+
const opPart = strVal.slice(slashIdx + 1);
|
|
1353
|
+
console.warn(
|
|
1354
|
+
`[csszyx] "${rawKey}: '${strVal}'" \u2014 string slash opacity is not supported. Use object form: { color: '${colorPart}', op: ${opPart} }.`
|
|
1355
|
+
);
|
|
1356
|
+
}
|
|
1357
|
+
continue;
|
|
1358
|
+
}
|
|
1359
|
+
if (!isValidColorString(strVal)) {
|
|
1360
|
+
if (process.env["NODE_ENV"] !== "production" && typeof window === "undefined") {
|
|
1361
|
+
console.warn(
|
|
1362
|
+
`[csszyx] "${rawKey}: '${strVal}'" is not a recognized color value and will be ignored. Use a Tailwind color ("blue-500"), CSS variable ("--my-color"), hex/rgb/hsl ("#ff0000"), or object form ({ color: "blue-500", op: 50 }).`
|
|
1363
|
+
);
|
|
1364
|
+
}
|
|
1365
|
+
continue;
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1275
1368
|
if (typeof value === "object" && !Array.isArray(value)) {
|
|
1276
1369
|
if (rawKey === "group") {
|
|
1277
1370
|
const groupClasses = handleGroupPeer("group", value, prefix);
|
|
@@ -2428,8 +2521,9 @@ var CsszyxCompiler = class _CsszyxCompiler {
|
|
|
2428
2521
|
*/
|
|
2429
2522
|
transform(sz) {
|
|
2430
2523
|
if (this.wasmLoaded) {
|
|
2524
|
+
const cleaned = stripInvalidColorStrings(sz);
|
|
2431
2525
|
try {
|
|
2432
|
-
return transform_sz(
|
|
2526
|
+
return transform_sz(cleaned);
|
|
2433
2527
|
} catch (error) {
|
|
2434
2528
|
console.warn(
|
|
2435
2529
|
"[csszyx] WASM transformation failed, using JS fallback",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@csszyx/compiler",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Core compiler and transformation logic for csszyx",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"csszyx",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"@babel/core": "^7.23.7",
|
|
39
39
|
"@babel/types": "^7.23.6",
|
|
40
40
|
"@babel/traverse": "^7.23.7",
|
|
41
|
-
"@csszyx/core": "0.1.
|
|
41
|
+
"@csszyx/core": "0.1.3"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@types/babel__core": "^7.20.5",
|