chaincss 2.4.0 → 2.4.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/dist/browser.js CHANGED
@@ -254,16 +254,18 @@ var macros = {
254
254
  relative: (v, c) => handlePosition("relative", v, c),
255
255
  // --- Shapes & Content ---
256
256
  circle: (v, c) => {
257
- c.width = v;
258
- c.height = v;
257
+ const val = typeof v === "number" ? `${v}px` : v;
258
+ c.width = val;
259
+ c.height = val;
259
260
  c.borderRadius = "50%";
260
261
  c.display = "flex";
261
262
  c.alignItems = "center";
262
263
  c.justifyContent = "center";
263
264
  },
264
265
  square: (v, c) => {
265
- c.width = v;
266
- c.height = v;
266
+ const val = typeof v === "number" ? `${v}px` : v;
267
+ c.width = val;
268
+ c.height = val;
267
269
  c.display = "flex";
268
270
  c.alignItems = "center";
269
271
  c.justifyContent = "center";
package/dist/cli/index.js CHANGED
@@ -276,11 +276,27 @@ function compileToCSS(styleObject, options = {}) {
276
276
  ...properties
277
277
  } = styleObject;
278
278
  const effectiveSelector = selectors?.join(", ") || scope;
279
- const mainDeclarations = compileDeclarations(properties, indent, options);
279
+ const pseudoClasses = {};
280
+ const regularProps = {};
281
+ for (const [key, value] of Object.entries(properties)) {
282
+ if (key.startsWith("&:")) {
283
+ pseudoClasses[key.substring(1)] = value;
284
+ } else if (!key.startsWith("_")) {
285
+ regularProps[key] = value;
286
+ }
287
+ }
288
+ const mainDeclarations = compileDeclarations(regularProps, indent, options);
280
289
  if (mainDeclarations.length > 0 && effectiveSelector) {
281
290
  const source = options.sourceMap && options.sourceFile ? `/* ${options.sourceFile} */${newline}` : "";
282
291
  parts.push(`${source}${effectiveSelector} {${newline}${mainDeclarations.join(newline)}${newline}}`);
283
292
  }
293
+ for (const [pseudo, pseudoStyles] of Object.entries(pseudoClasses)) {
294
+ const pseudoSelector = `${effectiveSelector}${pseudo}`;
295
+ const pseudoDeclarations = compileDeclarations(pseudoStyles, indent, options);
296
+ if (pseudoDeclarations.length > 0) {
297
+ parts.push(`${pseudoSelector} {${newline}${pseudoDeclarations.join(newline)}${newline}}`);
298
+ }
299
+ }
284
300
  for (const rule of _atRules) {
285
301
  const compiled = compileAtRule(rule, effectiveSelector, indent, newline, options);
286
302
  if (compiled) parts.push(compiled);
@@ -300,21 +316,15 @@ function compileDeclarations(properties, indent, options) {
300
316
  for (const [prop, value] of Object.entries(properties)) {
301
317
  if (prop.startsWith("_")) continue;
302
318
  if (typeof value === "function") continue;
303
- if (prop.startsWith("&:")) {
304
- const pseudo = prop.substring(1);
305
- const pseudoLines = compileDeclarations(value, indent + indent, options);
306
- if (pseudoLines.length > 0) {
307
- lines.push(`${indent}${pseudo} {`);
308
- lines.push(...pseudoLines);
309
- lines.push(`${indent}}`);
310
- }
311
- continue;
312
- }
313
319
  if (typeof value === "object" && value !== null && !Array.isArray(value)) {
314
320
  continue;
315
321
  }
316
322
  const cssProp = camelToKebab(prop);
317
- lines.push(`${indent}${cssProp}: ${value};`);
323
+ let finalValue = value;
324
+ if (typeof value === "number" && ["width", "height", "min-width", "max-width", "min-height", "max-height"].includes(cssProp)) {
325
+ finalValue = value + "px";
326
+ }
327
+ lines.push(`${indent}${cssProp}: ${finalValue};`);
318
328
  }
319
329
  return lines;
320
330
  }
@@ -278,16 +278,18 @@ var macros = {
278
278
  relative: (v, c) => handlePosition("relative", v, c),
279
279
  // --- Shapes & Content ---
280
280
  circle: (v, c) => {
281
- c.width = v;
282
- c.height = v;
281
+ const val = typeof v === "number" ? `${v}px` : v;
282
+ c.width = val;
283
+ c.height = val;
283
284
  c.borderRadius = "50%";
284
285
  c.display = "flex";
285
286
  c.alignItems = "center";
286
287
  c.justifyContent = "center";
287
288
  },
288
289
  square: (v, c) => {
289
- c.width = v;
290
- c.height = v;
290
+ const val = typeof v === "number" ? `${v}px` : v;
291
+ c.width = val;
292
+ c.height = val;
291
293
  c.display = "flex";
292
294
  c.alignItems = "center";
293
295
  c.justifyContent = "center";
@@ -1592,11 +1594,27 @@ function compileToCSS(styleObject, options = {}) {
1592
1594
  ...properties
1593
1595
  } = styleObject;
1594
1596
  const effectiveSelector = selectors?.join(", ") || scope;
1595
- const mainDeclarations = compileDeclarations(properties, indent, options);
1597
+ const pseudoClasses = {};
1598
+ const regularProps = {};
1599
+ for (const [key, value] of Object.entries(properties)) {
1600
+ if (key.startsWith("&:")) {
1601
+ pseudoClasses[key.substring(1)] = value;
1602
+ } else if (!key.startsWith("_")) {
1603
+ regularProps[key] = value;
1604
+ }
1605
+ }
1606
+ const mainDeclarations = compileDeclarations(regularProps, indent, options);
1596
1607
  if (mainDeclarations.length > 0 && effectiveSelector) {
1597
1608
  const source = options.sourceMap && options.sourceFile ? `/* ${options.sourceFile} */${newline}` : "";
1598
1609
  parts.push(`${source}${effectiveSelector} {${newline}${mainDeclarations.join(newline)}${newline}}`);
1599
1610
  }
1611
+ for (const [pseudo, pseudoStyles] of Object.entries(pseudoClasses)) {
1612
+ const pseudoSelector = `${effectiveSelector}${pseudo}`;
1613
+ const pseudoDeclarations = compileDeclarations(pseudoStyles, indent, options);
1614
+ if (pseudoDeclarations.length > 0) {
1615
+ parts.push(`${pseudoSelector} {${newline}${pseudoDeclarations.join(newline)}${newline}}`);
1616
+ }
1617
+ }
1600
1618
  for (const rule of _atRules) {
1601
1619
  const compiled = compileAtRule(rule, effectiveSelector, indent, newline, options);
1602
1620
  if (compiled) parts.push(compiled);
@@ -1616,21 +1634,15 @@ function compileDeclarations(properties, indent, options) {
1616
1634
  for (const [prop, value] of Object.entries(properties)) {
1617
1635
  if (prop.startsWith("_")) continue;
1618
1636
  if (typeof value === "function") continue;
1619
- if (prop.startsWith("&:")) {
1620
- const pseudo = prop.substring(1);
1621
- const pseudoLines = compileDeclarations(value, indent + indent, options);
1622
- if (pseudoLines.length > 0) {
1623
- lines.push(`${indent}${pseudo} {`);
1624
- lines.push(...pseudoLines);
1625
- lines.push(`${indent}}`);
1626
- }
1627
- continue;
1628
- }
1629
1637
  if (typeof value === "object" && value !== null && !Array.isArray(value)) {
1630
1638
  continue;
1631
1639
  }
1632
1640
  const cssProp = camelToKebab(prop);
1633
- lines.push(`${indent}${cssProp}: ${value};`);
1641
+ let finalValue = value;
1642
+ if (typeof value === "number" && ["width", "height", "min-width", "max-width", "min-height", "max-height"].includes(cssProp)) {
1643
+ finalValue = value + "px";
1644
+ }
1645
+ lines.push(`${indent}${cssProp}: ${finalValue};`);
1634
1646
  }
1635
1647
  return lines;
1636
1648
  }
package/dist/index.js CHANGED
@@ -237,16 +237,18 @@ var macros = {
237
237
  relative: (v, c) => handlePosition("relative", v, c),
238
238
  // --- Shapes & Content ---
239
239
  circle: (v, c) => {
240
- c.width = v;
241
- c.height = v;
240
+ const val = typeof v === "number" ? `${v}px` : v;
241
+ c.width = val;
242
+ c.height = val;
242
243
  c.borderRadius = "50%";
243
244
  c.display = "flex";
244
245
  c.alignItems = "center";
245
246
  c.justifyContent = "center";
246
247
  },
247
248
  square: (v, c) => {
248
- c.width = v;
249
- c.height = v;
249
+ const val = typeof v === "number" ? `${v}px` : v;
250
+ c.width = val;
251
+ c.height = val;
250
252
  c.display = "flex";
251
253
  c.alignItems = "center";
252
254
  c.justifyContent = "center";
@@ -1525,11 +1527,27 @@ function compileToCSS(styleObject, options = {}) {
1525
1527
  ...properties
1526
1528
  } = styleObject;
1527
1529
  const effectiveSelector = selectors?.join(", ") || scope;
1528
- const mainDeclarations = compileDeclarations(properties, indent, options);
1530
+ const pseudoClasses = {};
1531
+ const regularProps = {};
1532
+ for (const [key, value] of Object.entries(properties)) {
1533
+ if (key.startsWith("&:")) {
1534
+ pseudoClasses[key.substring(1)] = value;
1535
+ } else if (!key.startsWith("_")) {
1536
+ regularProps[key] = value;
1537
+ }
1538
+ }
1539
+ const mainDeclarations = compileDeclarations(regularProps, indent, options);
1529
1540
  if (mainDeclarations.length > 0 && effectiveSelector) {
1530
1541
  const source = options.sourceMap && options.sourceFile ? `/* ${options.sourceFile} */${newline}` : "";
1531
1542
  parts.push(`${source}${effectiveSelector} {${newline}${mainDeclarations.join(newline)}${newline}}`);
1532
1543
  }
1544
+ for (const [pseudo, pseudoStyles] of Object.entries(pseudoClasses)) {
1545
+ const pseudoSelector = `${effectiveSelector}${pseudo}`;
1546
+ const pseudoDeclarations = compileDeclarations(pseudoStyles, indent, options);
1547
+ if (pseudoDeclarations.length > 0) {
1548
+ parts.push(`${pseudoSelector} {${newline}${pseudoDeclarations.join(newline)}${newline}}`);
1549
+ }
1550
+ }
1533
1551
  for (const rule of _atRules) {
1534
1552
  const compiled = compileAtRule(rule, effectiveSelector, indent, newline, options);
1535
1553
  if (compiled) parts.push(compiled);
@@ -1549,21 +1567,15 @@ function compileDeclarations(properties, indent, options) {
1549
1567
  for (const [prop, value] of Object.entries(properties)) {
1550
1568
  if (prop.startsWith("_")) continue;
1551
1569
  if (typeof value === "function") continue;
1552
- if (prop.startsWith("&:")) {
1553
- const pseudo = prop.substring(1);
1554
- const pseudoLines = compileDeclarations(value, indent + indent, options);
1555
- if (pseudoLines.length > 0) {
1556
- lines.push(`${indent}${pseudo} {`);
1557
- lines.push(...pseudoLines);
1558
- lines.push(`${indent}}`);
1559
- }
1560
- continue;
1561
- }
1562
1570
  if (typeof value === "object" && value !== null && !Array.isArray(value)) {
1563
1571
  continue;
1564
1572
  }
1565
1573
  const cssProp = camelToKebab(prop);
1566
- lines.push(`${indent}${cssProp}: ${value};`);
1574
+ let finalValue = value;
1575
+ if (typeof value === "number" && ["width", "height", "min-width", "max-width", "min-height", "max-height"].includes(cssProp)) {
1576
+ finalValue = value + "px";
1577
+ }
1578
+ lines.push(`${indent}${cssProp}: ${finalValue};`);
1567
1579
  }
1568
1580
  return lines;
1569
1581
  }
@@ -0,0 +1,2 @@
1
+ import type { Plugin } from 'vite';
2
+ export declare function chainCSSPlugin(): Plugin;
@@ -1,13 +1,5 @@
1
1
  import { Plugin } from 'vite';
2
2
  export interface ChainCSSPluginOptions {
3
- atomic?: boolean;
4
- minify?: boolean;
5
3
  verbose?: boolean;
6
- hmr?: boolean;
7
- injectGlobal?: boolean;
8
- cssOutput?: string;
9
- manifestOutput?: string;
10
- include?: string[];
11
- exclude?: string[];
12
4
  }
13
5
  export default function chaincssPlugin(options?: ChainCSSPluginOptions): Plugin;