windrunner 1.1.2 → 1.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.esm.js CHANGED
@@ -1354,29 +1354,70 @@ var config_default = configOptions;
1354
1354
  function isFunction(fn) {
1355
1355
  return fn && {}.toString.call(fn) === "[object Function]";
1356
1356
  }
1357
+ var configCache = /* @__PURE__ */ new WeakMap();
1358
+ var defaultContextCache = null;
1359
+ function createLazyTheme(userTheme = {}, userThemeExtend = {}) {
1360
+ const resolved = /* @__PURE__ */ new Map();
1361
+ const defaultTheme = config_default.theme;
1362
+ return new Proxy({}, {
1363
+ get(_, key) {
1364
+ if (resolved.has(key)) {
1365
+ return resolved.get(key);
1366
+ }
1367
+ let value = Object.prototype.hasOwnProperty.call(userTheme, key) ? userTheme[key] : defaultTheme[key];
1368
+ if (isFunction(value)) {
1369
+ value = value({
1370
+ theme: (keyRef) => {
1371
+ if (resolved.has(keyRef)) return resolved.get(keyRef);
1372
+ return createLazyTheme(userTheme, userThemeExtend)[keyRef];
1373
+ }
1374
+ });
1375
+ }
1376
+ if (userThemeExtend[key]) {
1377
+ value = Object.assign({}, value, userThemeExtend[key]);
1378
+ }
1379
+ resolved.set(key, value);
1380
+ return value;
1381
+ },
1382
+ has(_, key) {
1383
+ return key in defaultTheme || key in userTheme;
1384
+ },
1385
+ ownKeys(_) {
1386
+ return [.../* @__PURE__ */ new Set([...Object.keys(defaultTheme), ...Object.keys(userTheme)])];
1387
+ },
1388
+ getOwnPropertyDescriptor(_, key) {
1389
+ if (key in defaultTheme || key in userTheme) {
1390
+ return {
1391
+ enumerable: true,
1392
+ configurable: true
1393
+ };
1394
+ }
1395
+ }
1396
+ });
1397
+ }
1357
1398
  function getConfigOptions(options = {}, pluginKeys = []) {
1399
+ if (!options || typeof options === "object" && Object.keys(options).length === 0) {
1400
+ if (!defaultContextCache) {
1401
+ defaultContextCache = {
1402
+ ...config_default,
1403
+ theme: createLazyTheme({}, {})
1404
+ };
1405
+ }
1406
+ return defaultContextCache;
1407
+ }
1408
+ if (configCache.has(options)) {
1409
+ return configCache.get(options);
1410
+ }
1358
1411
  const { theme: theme2 = {} } = options;
1359
1412
  const { extend: themeExtend = {} } = theme2;
1360
- const newTheme = {};
1361
- const themeKeys = Object.keys(config_default.theme);
1362
- themeKeys.forEach((key) => {
1363
- newTheme[key] = Object.prototype.hasOwnProperty.call(theme2, key) ? theme2[key] : config_default.theme[key];
1364
- });
1365
- themeKeys.forEach((key) => {
1366
- if (isFunction(newTheme[key])) {
1367
- newTheme[key] = newTheme[key]({
1368
- theme: (keyRef) => newTheme[keyRef]
1369
- });
1370
- }
1371
- if (themeExtend[key]) {
1372
- newTheme[key] = Object.assign({}, newTheme[key], themeExtend[key]);
1373
- }
1374
- });
1375
- return {
1413
+ const lazyTheme = createLazyTheme(theme2, themeExtend);
1414
+ const config = {
1376
1415
  ...config_default,
1377
1416
  ...options,
1378
- theme: newTheme
1417
+ theme: lazyTheme
1379
1418
  };
1419
+ configCache.set(options, config);
1420
+ return config;
1380
1421
  }
1381
1422
 
1382
1423
  // src/constants.js
@@ -1460,112 +1501,93 @@ function escapeCssIdentifier(value) {
1460
1501
  }
1461
1502
  function appendImportant(declaration, isImportant) {
1462
1503
  if (!isImportant) return declaration;
1463
- const entries = declaration.split(";").map((item) => item.trim()).filter(Boolean).map((item) => item.includes("!important") ? item : `${item} !important`);
1464
- return `${entries.join("; ")};`;
1504
+ return declaration.replace(/([^;{}]+);/g, (match, decl) => {
1505
+ const trimmed = decl.trim();
1506
+ if (!trimmed || trimmed.includes("!important")) return match;
1507
+ return `${trimmed} !important;`;
1508
+ });
1465
1509
  }
1466
1510
  function splitByVariantDelimiter(token) {
1467
1511
  const parts = [];
1468
- let current = "";
1512
+ let start = 0;
1469
1513
  let bracketDepth = 0;
1470
1514
  for (let i = 0; i < token.length; i += 1) {
1471
1515
  const char = token[i];
1472
- if (char === "[") bracketDepth += 1;
1473
- if (char === "]") bracketDepth = Math.max(0, bracketDepth - 1);
1474
- if (char === ":" && bracketDepth === 0) {
1475
- parts.push(current);
1476
- current = "";
1477
- } else {
1478
- current += char;
1516
+ if (char === "[") {
1517
+ bracketDepth += 1;
1518
+ } else if (char === "]") {
1519
+ bracketDepth = Math.max(0, bracketDepth - 1);
1520
+ } else if (char === ":" && bracketDepth === 0) {
1521
+ parts.push(token.slice(start, i));
1522
+ start = i + 1;
1479
1523
  }
1480
1524
  }
1481
- if (current) parts.push(current);
1525
+ parts.push(token.slice(start));
1482
1526
  return parts;
1483
1527
  }
1484
1528
 
1485
1529
  // src/maps/layout.maps.js
1530
+ function createSimpleMap(prop, values, keyMap = {}) {
1531
+ const map = {};
1532
+ values.forEach((value) => {
1533
+ const key = keyMap[value] || value;
1534
+ map[key] = `${prop}: ${value};`;
1535
+ });
1536
+ return map;
1537
+ }
1486
1538
  var DISPLAY_MAP = {
1487
- block: "display: block;",
1488
- inline: "display: inline;",
1489
- "inline-block": "display: inline-block;",
1490
- flex: "display: flex;",
1491
- "inline-flex": "display: inline-flex;",
1492
- grid: "display: grid;",
1493
- "inline-grid": "display: inline-grid;",
1494
- hidden: "display: none;",
1495
- contents: "display: contents;",
1496
- "flow-root": "display: flow-root;",
1497
- "list-item": "display: list-item;",
1498
- table: "display: table;",
1499
- "inline-table": "display: inline-table;",
1500
- "table-caption": "display: table-caption;",
1501
- "table-cell": "display: table-cell;",
1502
- "table-column": "display: table-column;",
1503
- "table-column-group": "display: table-column-group;",
1504
- "table-footer-group": "display: table-footer-group;",
1505
- "table-header-group": "display: table-header-group;",
1506
- "table-row-group": "display: table-row-group;",
1507
- "table-row": "display: table-row;"
1508
- };
1509
- var POSITION_MAP = {
1510
- static: "position: static;",
1511
- fixed: "position: fixed;",
1512
- absolute: "position: absolute;",
1513
- relative: "position: relative;",
1514
- sticky: "position: sticky;"
1539
+ ...createSimpleMap("display", [
1540
+ "block",
1541
+ "inline",
1542
+ "inline-block",
1543
+ "flex",
1544
+ "inline-flex",
1545
+ "grid",
1546
+ "inline-grid",
1547
+ "contents",
1548
+ "flow-root",
1549
+ "list-item",
1550
+ "table",
1551
+ "inline-table",
1552
+ "table-caption",
1553
+ "table-cell",
1554
+ "table-column",
1555
+ "table-column-group",
1556
+ "table-footer-group",
1557
+ "table-header-group",
1558
+ "table-row-group",
1559
+ "table-row"
1560
+ ]),
1561
+ hidden: "display: none;"
1562
+ // Special case
1515
1563
  };
1564
+ var POSITION_MAP = createSimpleMap("position", [
1565
+ "static",
1566
+ "fixed",
1567
+ "absolute",
1568
+ "relative",
1569
+ "sticky"
1570
+ ]);
1516
1571
  var VISIBILITY_MAP = {
1517
- visible: "visibility: visible;",
1518
- invisible: "visibility: hidden;",
1519
- collapse: "visibility: collapse;"
1520
- };
1521
- var OVERFLOW_MAP = {
1522
- auto: "overflow: auto;",
1523
- hidden: "overflow: hidden;",
1524
- clip: "overflow: clip;",
1525
- visible: "overflow: visible;",
1526
- scroll: "overflow: scroll;"
1527
- };
1528
- var OVERFLOW_X_MAP = {
1529
- auto: "overflow-x: auto;",
1530
- hidden: "overflow-x: hidden;",
1531
- clip: "overflow-x: clip;",
1532
- visible: "overflow-x: visible;",
1533
- scroll: "overflow-x: scroll;"
1534
- };
1535
- var OVERFLOW_Y_MAP = {
1536
- auto: "overflow-y: auto;",
1537
- hidden: "overflow-y: hidden;",
1538
- clip: "overflow-y: clip;",
1539
- visible: "overflow-y: visible;",
1540
- scroll: "overflow-y: scroll;"
1541
- };
1542
- var OVERSCROLL_MAP = {
1543
- auto: "overscroll-behavior: auto;",
1544
- contain: "overscroll-behavior: contain;",
1545
- none: "overscroll-behavior: none;"
1546
- };
1547
- var OVERSCROLL_X_MAP = {
1548
- auto: "overscroll-behavior-x: auto;",
1549
- contain: "overscroll-behavior-x: contain;",
1550
- none: "overscroll-behavior-x: none;"
1551
- };
1552
- var OVERSCROLL_Y_MAP = {
1553
- auto: "overscroll-behavior-y: auto;",
1554
- contain: "overscroll-behavior-y: contain;",
1555
- none: "overscroll-behavior-y: none;"
1572
+ ...createSimpleMap("visibility", ["visible", "collapse"]),
1573
+ invisible: "visibility: hidden;"
1574
+ // Key differs from value
1556
1575
  };
1576
+ var OVERFLOW_VALUES = ["auto", "hidden", "clip", "visible", "scroll"];
1577
+ var OVERFLOW_MAP = createSimpleMap("overflow", OVERFLOW_VALUES);
1578
+ var OVERFLOW_X_MAP = createSimpleMap("overflow-x", OVERFLOW_VALUES);
1579
+ var OVERFLOW_Y_MAP = createSimpleMap("overflow-y", OVERFLOW_VALUES);
1580
+ var OVERSCROLL_VALUES = ["auto", "contain", "none"];
1581
+ var OVERSCROLL_MAP = createSimpleMap("overscroll-behavior", OVERSCROLL_VALUES);
1582
+ var OVERSCROLL_X_MAP = createSimpleMap("overscroll-behavior-x", OVERSCROLL_VALUES);
1583
+ var OVERSCROLL_Y_MAP = createSimpleMap("overscroll-behavior-y", OVERSCROLL_VALUES);
1557
1584
  var FLOAT_MAP = {
1558
- left: "float: left;",
1559
- right: "float: right;",
1560
- none: "float: none;",
1585
+ ...createSimpleMap("float", ["left", "right", "none"]),
1561
1586
  start: "float: inline-start;",
1562
1587
  end: "float: inline-end;"
1563
1588
  };
1564
1589
  var CLEAR_MAP = {
1565
- left: "clear: left;",
1566
- right: "clear: right;",
1567
- both: "clear: both;",
1568
- none: "clear: none;",
1590
+ ...createSimpleMap("clear", ["left", "right", "both", "none"]),
1569
1591
  start: "clear: inline-start;",
1570
1592
  end: "clear: inline-end;"
1571
1593
  };
@@ -1573,13 +1595,13 @@ var ISOLATION_MAP = {
1573
1595
  isolate: "isolation: isolate;",
1574
1596
  "isolation-auto": "isolation: auto;"
1575
1597
  };
1576
- var OBJECT_FIT_MAP = {
1577
- contain: "object-fit: contain;",
1578
- cover: "object-fit: cover;",
1579
- fill: "object-fit: fill;",
1580
- none: "object-fit: none;",
1581
- "scale-down": "object-fit: scale-down;"
1582
- };
1598
+ var OBJECT_FIT_MAP = createSimpleMap("object-fit", [
1599
+ "contain",
1600
+ "cover",
1601
+ "fill",
1602
+ "none",
1603
+ "scale-down"
1604
+ ]);
1583
1605
  var TRANSFORM_STYLE_MAP = {
1584
1606
  "transform-style-flat": "transform-style: flat;",
1585
1607
  "transform-style-3d": "transform-style: preserve-3d;",
@@ -1597,81 +1619,64 @@ var BOX_SIZING_MAP = {
1597
1619
  border: "box-sizing: border-box;",
1598
1620
  content: "box-sizing: content-box;"
1599
1621
  };
1622
+ var BREAK_AFTER_BEFORE_VALUES = [
1623
+ "auto",
1624
+ "avoid",
1625
+ "avoid-page",
1626
+ "avoid-column",
1627
+ "page",
1628
+ "left",
1629
+ "right",
1630
+ "recto",
1631
+ "verso"
1632
+ ];
1600
1633
  var BREAK_AFTER_MAP = {
1601
- auto: "break-after: auto;",
1602
- avoid: "break-after: avoid;",
1603
- "avoid-page": "break-after: avoid-page;",
1604
- "avoid-column": "break-after: avoid-column;",
1605
- page: "break-after: page;",
1606
- all: "break-after: all;",
1607
- left: "break-after: left;",
1608
- right: "break-after: right;",
1609
- recto: "break-after: recto;",
1610
- verso: "break-after: verso;"
1611
- };
1612
- var BREAK_BEFORE_MAP = {
1613
- auto: "break-before: auto;",
1614
- avoid: "break-before: avoid;",
1615
- "avoid-page": "break-before: avoid-page;",
1616
- "avoid-column": "break-before: avoid-column;",
1617
- page: "break-before: page;",
1618
- left: "break-before: left;",
1619
- right: "break-before: right;",
1620
- recto: "break-before: recto;",
1621
- verso: "break-before: verso;"
1622
- };
1623
- var BREAK_INSIDE_MAP = {
1624
- auto: "break-inside: auto;",
1625
- avoid: "break-inside: avoid;",
1626
- "avoid-page": "break-inside: avoid-page;",
1627
- "avoid-column": "break-inside: avoid-column;"
1628
- };
1629
- var BOX_DECORATION_BREAK_MAP = {
1630
- slice: "box-decoration-break: slice;",
1631
- clone: "box-decoration-break: clone;"
1632
- };
1633
- var HYPHENS_MAP = {
1634
- none: "hyphens: none;",
1635
- manual: "hyphens: manual;",
1636
- auto: "hyphens: auto;"
1637
- };
1638
- var COLOR_SCHEME_MAP = {
1639
- light: "color-scheme: light;",
1640
- dark: "color-scheme: dark;",
1641
- normal: "color-scheme: normal;"
1642
- };
1643
- var SCROLLBAR_COLOR_MAP = {
1644
- auto: "scrollbar-color: auto;",
1645
- transparent: "scrollbar-color: transparent;",
1646
- current: "scrollbar-color: currentColor;"
1647
- };
1648
- var SCROLLBAR_WIDTH_MAP = {
1649
- auto: "scrollbar-width: auto;",
1650
- thin: "scrollbar-width: thin;",
1651
- none: "scrollbar-width: none;"
1634
+ ...createSimpleMap("break-after", BREAK_AFTER_BEFORE_VALUES),
1635
+ all: "break-after: all;"
1652
1636
  };
1637
+ var BREAK_BEFORE_MAP = createSimpleMap("break-before", BREAK_AFTER_BEFORE_VALUES);
1638
+ var BREAK_INSIDE_MAP = createSimpleMap("break-inside", [
1639
+ "auto",
1640
+ "avoid",
1641
+ "avoid-page",
1642
+ "avoid-column"
1643
+ ]);
1644
+ var BOX_DECORATION_BREAK_MAP = createSimpleMap("box-decoration-break", [
1645
+ "slice",
1646
+ "clone"
1647
+ ]);
1648
+ var HYPHENS_MAP = createSimpleMap("hyphens", ["none", "manual", "auto"]);
1649
+ var COLOR_SCHEME_MAP = createSimpleMap("color-scheme", [
1650
+ "light",
1651
+ "dark",
1652
+ "normal"
1653
+ ]);
1654
+ var SCROLLBAR_COLOR_MAP = createSimpleMap("scrollbar-color", [
1655
+ "auto",
1656
+ "transparent",
1657
+ "current"
1658
+ ]);
1659
+ var SCROLLBAR_WIDTH_MAP = createSimpleMap("scrollbar-width", [
1660
+ "auto",
1661
+ "thin",
1662
+ "none"
1663
+ ]);
1653
1664
  var SCROLLBAR_GUTTER_MAP = {
1654
1665
  auto: "scrollbar-gutter: auto;",
1655
1666
  stable: "scrollbar-gutter: stable;",
1656
1667
  "stable-both-edges": "scrollbar-gutter: stable both-edges;",
1657
1668
  "both-edges": "scrollbar-gutter: both-edges;"
1658
1669
  };
1659
- var TABLE_LAYOUT_MAP = {
1660
- auto: "table-layout: auto;",
1661
- fixed: "table-layout: fixed;"
1662
- };
1663
- var CAPTION_SIDE_MAP = {
1664
- top: "caption-side: top;",
1665
- bottom: "caption-side: bottom;"
1666
- };
1667
- var BORDER_COLLAPSE_MAP = {
1668
- collapse: "border-collapse: collapse;",
1669
- separate: "border-collapse: separate;"
1670
- };
1671
- var SCROLL_BEHAVIOR_MAP = {
1672
- auto: "scroll-behavior: auto;",
1673
- smooth: "scroll-behavior: smooth;"
1674
- };
1670
+ var TABLE_LAYOUT_MAP = createSimpleMap("table-layout", ["auto", "fixed"]);
1671
+ var CAPTION_SIDE_MAP = createSimpleMap("caption-side", ["top", "bottom"]);
1672
+ var BORDER_COLLAPSE_MAP = createSimpleMap("border-collapse", [
1673
+ "collapse",
1674
+ "separate"
1675
+ ]);
1676
+ var SCROLL_BEHAVIOR_MAP = createSimpleMap("scroll-behavior", [
1677
+ "auto",
1678
+ "smooth"
1679
+ ]);
1675
1680
  var SIDE_PROPS = {
1676
1681
  "": [""],
1677
1682
  t: ["-top"],
@@ -1702,71 +1707,69 @@ var ROUNDED_PROPS = {
1702
1707
  };
1703
1708
 
1704
1709
  // src/maps/interactivity.maps.js
1705
- var CURSOR_MAP = {
1706
- auto: "cursor: auto;",
1707
- default: "cursor: default;",
1708
- pointer: "cursor: pointer;",
1709
- wait: "cursor: wait;",
1710
- text: "cursor: text;",
1711
- move: "cursor: move;",
1712
- help: "cursor: help;",
1713
- "not-allowed": "cursor: not-allowed;",
1714
- none: "cursor: none;",
1715
- "context-menu": "cursor: context-menu;",
1716
- progress: "cursor: progress;",
1717
- cell: "cursor: cell;",
1718
- crosshair: "cursor: crosshair;",
1719
- "vertical-text": "cursor: vertical-text;",
1720
- alias: "cursor: alias;",
1721
- copy: "cursor: copy;",
1722
- "no-drop": "cursor: no-drop;",
1723
- grab: "cursor: grab;",
1724
- grabbing: "cursor: grabbing;",
1725
- "all-scroll": "cursor: all-scroll;",
1726
- "zoom-in": "cursor: zoom-in;",
1727
- "zoom-out": "cursor: zoom-out;"
1728
- };
1729
- var POINTER_EVENTS_MAP = {
1730
- none: "pointer-events: none;",
1731
- auto: "pointer-events: auto;"
1732
- };
1733
- var USER_SELECT_MAP = {
1734
- none: "user-select: none;",
1735
- text: "user-select: text;",
1736
- all: "user-select: all;",
1737
- auto: "user-select: auto;"
1738
- };
1739
- var APPEARANCE_MAP = {
1740
- none: "appearance: none;",
1741
- auto: "appearance: auto;"
1742
- };
1743
- var TOUCH_ACTION_MAP = {
1744
- auto: "touch-action: auto;",
1745
- none: "touch-action: none;",
1746
- "pan-x": "touch-action: pan-x;",
1747
- "pan-left": "touch-action: pan-left;",
1748
- "pan-right": "touch-action: pan-right;",
1749
- "pan-y": "touch-action: pan-y;",
1750
- "pan-up": "touch-action: pan-up;",
1751
- "pan-down": "touch-action: pan-down;",
1752
- "pinch-zoom": "touch-action: pinch-zoom;",
1753
- manipulation: "touch-action: manipulation;"
1754
- };
1710
+ function createSimpleMap2(prop, values) {
1711
+ const map = {};
1712
+ values.forEach((value) => {
1713
+ map[value] = `${prop}: ${value};`;
1714
+ });
1715
+ return map;
1716
+ }
1717
+ var CURSOR_MAP = createSimpleMap2("cursor", [
1718
+ "auto",
1719
+ "default",
1720
+ "pointer",
1721
+ "wait",
1722
+ "text",
1723
+ "move",
1724
+ "help",
1725
+ "not-allowed",
1726
+ "none",
1727
+ "context-menu",
1728
+ "progress",
1729
+ "cell",
1730
+ "crosshair",
1731
+ "vertical-text",
1732
+ "alias",
1733
+ "copy",
1734
+ "no-drop",
1735
+ "grab",
1736
+ "grabbing",
1737
+ "all-scroll",
1738
+ "zoom-in",
1739
+ "zoom-out"
1740
+ ]);
1741
+ var POINTER_EVENTS_MAP = createSimpleMap2("pointer-events", ["none", "auto"]);
1742
+ var USER_SELECT_MAP = createSimpleMap2("user-select", [
1743
+ "none",
1744
+ "text",
1745
+ "all",
1746
+ "auto"
1747
+ ]);
1748
+ var APPEARANCE_MAP = createSimpleMap2("appearance", ["none", "auto"]);
1749
+ var TOUCH_ACTION_MAP = createSimpleMap2("touch-action", [
1750
+ "auto",
1751
+ "none",
1752
+ "pan-x",
1753
+ "pan-left",
1754
+ "pan-right",
1755
+ "pan-y",
1756
+ "pan-up",
1757
+ "pan-down",
1758
+ "pinch-zoom",
1759
+ "manipulation"
1760
+ ]);
1755
1761
  var OUTLINE_STYLE_MAP = {
1756
1762
  none: "outline: 2px solid transparent; outline-offset: 2px;",
1757
- solid: "outline-style: solid;",
1758
- dashed: "outline-style: dashed;",
1759
- dotted: "outline-style: dotted;",
1760
- double: "outline-style: double;"
1761
- };
1762
- var BORDER_STYLE_MAP = {
1763
- solid: "border-style: solid;",
1764
- dashed: "border-style: dashed;",
1765
- dotted: "border-style: dotted;",
1766
- double: "border-style: double;",
1767
- hidden: "border-style: hidden;",
1768
- none: "border-style: none;"
1763
+ ...createSimpleMap2("outline-style", ["solid", "dashed", "dotted", "double"])
1769
1764
  };
1765
+ var BORDER_STYLE_MAP = createSimpleMap2("border-style", [
1766
+ "solid",
1767
+ "dashed",
1768
+ "dotted",
1769
+ "double",
1770
+ "hidden",
1771
+ "none"
1772
+ ]);
1770
1773
  var TRANSITION_PROPERTY_MAP = {
1771
1774
  none: "none",
1772
1775
  all: "all",
@@ -3219,7 +3222,8 @@ function buildDivideDeclaration(baseToken, theme2) {
3219
3222
  // src/plugins.js
3220
3223
  var PluginRegistry = class {
3221
3224
  constructor() {
3222
- this.utilities = /* @__PURE__ */ new Map();
3225
+ this.exactUtilities = /* @__PURE__ */ new Map();
3226
+ this.regexUtilities = [];
3223
3227
  this.variants = /* @__PURE__ */ new Map();
3224
3228
  }
3225
3229
  /**
@@ -3228,7 +3232,11 @@ var PluginRegistry = class {
3228
3232
  * @param {Function|string} handler - Function that returns CSS or CSS string
3229
3233
  */
3230
3234
  addUtility(pattern, handler) {
3231
- this.utilities.set(pattern, handler);
3235
+ if (pattern instanceof RegExp) {
3236
+ this.regexUtilities.push([pattern, handler]);
3237
+ } else {
3238
+ this.exactUtilities.set(pattern, handler);
3239
+ }
3232
3240
  }
3233
3241
  /**
3234
3242
  * Register multiple utilities at once
@@ -3258,18 +3266,22 @@ var PluginRegistry = class {
3258
3266
  }
3259
3267
  /**
3260
3268
  * Check if a token matches any custom utility pattern
3269
+ * Optimized: O(1) fast path for exact matches, O(n) only for regex patterns
3261
3270
  * @param {string} token - The base token to match
3262
3271
  * @returns {Object|null} - { handler, match } or null
3263
3272
  */
3264
3273
  matchUtility(token) {
3265
- for (const [pattern, handler] of this.utilities) {
3266
- if (pattern instanceof RegExp) {
3267
- const match = pattern.exec(token);
3268
- if (match) {
3269
- return { handler, match };
3270
- }
3271
- } else if (pattern === token) {
3272
- return { handler, match: [token] };
3274
+ if (this.exactUtilities.has(token)) {
3275
+ return {
3276
+ handler: this.exactUtilities.get(token),
3277
+ match: [token]
3278
+ };
3279
+ }
3280
+ for (let i = 0; i < this.regexUtilities.length; i += 1) {
3281
+ const [pattern, handler] = this.regexUtilities[i];
3282
+ const match = pattern.exec(token);
3283
+ if (match) {
3284
+ return { handler, match };
3273
3285
  }
3274
3286
  }
3275
3287
  return null;
@@ -3286,7 +3298,10 @@ var PluginRegistry = class {
3286
3298
  * Get all registered utility patterns (for debugging)
3287
3299
  */
3288
3300
  getUtilities() {
3289
- return Array.from(this.utilities.keys());
3301
+ return [
3302
+ ...Array.from(this.exactUtilities.keys()),
3303
+ ...this.regexUtilities.map(([pattern]) => pattern)
3304
+ ];
3290
3305
  }
3291
3306
  /**
3292
3307
  * Get all registered variant names (for debugging)
@@ -3298,7 +3313,8 @@ var PluginRegistry = class {
3298
3313
  * Clear all registered plugins
3299
3314
  */
3300
3315
  clear() {
3301
- this.utilities.clear();
3316
+ this.exactUtilities.clear();
3317
+ this.regexUtilities = [];
3302
3318
  this.variants.clear();
3303
3319
  }
3304
3320
  };
@@ -3503,8 +3519,26 @@ function extractPrefix(token) {
3503
3519
  }
3504
3520
  return prefix;
3505
3521
  }
3522
+ var UNKNOWN_PREFIX_CACHE = /* @__PURE__ */ new Set();
3523
+ var MAX_UNKNOWN_CACHE_SIZE = 500;
3506
3524
  function checkAllBuilders(baseToken, theme2) {
3507
- return buildLayoutDeclaration(baseToken, theme2) || buildPositionInsetDeclaration(baseToken, theme2) || buildSpacingDeclaration(baseToken, theme2) || buildSpaceBetweenDeclaration(baseToken, theme2) || buildGapDeclaration(baseToken, theme2) || buildDimensionDeclaration(baseToken, theme2) || buildFlexGridDeclaration(baseToken, theme2) || buildBorderDeclaration(baseToken, theme2) || buildBorderRadiusDeclaration(baseToken, theme2) || buildBorderSpacingDeclaration(baseToken, theme2) || buildDivideDeclaration(baseToken, theme2) || buildOpacityDeclaration(baseToken, theme2) || buildShadowDeclaration(baseToken, theme2) || buildInsetShadowDeclaration(baseToken, theme2) || buildInsetRingDeclaration(baseToken, theme2) || buildRingDeclaration(baseToken, theme2) || buildRingOffsetDeclaration(baseToken, theme2) || buildTextShadowDeclaration(baseToken, theme2) || buildTransitionDeclaration(baseToken) || buildTransformDeclaration(baseToken, theme2) || buildFilterDeclaration(baseToken, theme2) || buildBackgroundDeclaration(baseToken, theme2) || buildGradientDeclaration(baseToken, theme2) || buildColorDeclaration(baseToken, theme2) || buildTypographyDeclaration(baseToken, theme2) || buildBlendingDeclaration(baseToken) || buildInteractivityDeclaration(baseToken, theme2) || buildAnimationDeclaration(baseToken) || buildMaskDeclaration(baseToken) || buildContainerQueryDeclaration(baseToken) || buildScrollSnapDeclaration(baseToken) || buildAccessibilityDeclaration(baseToken) || buildZoomDeclaration(baseToken, theme2) || buildForcedColorDeclaration(baseToken);
3525
+ const prefix = extractPrefix(baseToken);
3526
+ if (UNKNOWN_PREFIX_CACHE.has(prefix)) {
3527
+ return void 0;
3528
+ }
3529
+ const result = buildLayoutDeclaration(baseToken, theme2) || buildPositionInsetDeclaration(baseToken, theme2) || buildSpacingDeclaration(baseToken, theme2) || buildSpaceBetweenDeclaration(baseToken, theme2) || buildGapDeclaration(baseToken, theme2) || buildDimensionDeclaration(baseToken, theme2) || buildFlexGridDeclaration(baseToken, theme2) || buildBorderDeclaration(baseToken, theme2) || buildBorderRadiusDeclaration(baseToken, theme2) || buildBorderSpacingDeclaration(baseToken, theme2) || buildDivideDeclaration(baseToken, theme2) || buildOpacityDeclaration(baseToken, theme2) || buildShadowDeclaration(baseToken, theme2) || buildInsetShadowDeclaration(baseToken, theme2) || buildInsetRingDeclaration(baseToken, theme2) || buildRingDeclaration(baseToken, theme2) || buildRingOffsetDeclaration(baseToken, theme2) || buildTextShadowDeclaration(baseToken, theme2) || buildTransitionDeclaration(baseToken) || buildTransformDeclaration(baseToken, theme2) || buildFilterDeclaration(baseToken, theme2) || buildBackgroundDeclaration(baseToken, theme2) || buildGradientDeclaration(baseToken, theme2) || buildColorDeclaration(baseToken, theme2) || buildTypographyDeclaration(baseToken, theme2) || buildBlendingDeclaration(baseToken) || buildInteractivityDeclaration(baseToken, theme2) || buildAnimationDeclaration(baseToken) || buildMaskDeclaration(baseToken) || buildContainerQueryDeclaration(baseToken) || buildScrollSnapDeclaration(baseToken) || buildAccessibilityDeclaration(baseToken) || buildZoomDeclaration(baseToken, theme2) || buildForcedColorDeclaration(baseToken);
3530
+ if (!result && prefix) {
3531
+ if (UNKNOWN_PREFIX_CACHE.size >= MAX_UNKNOWN_CACHE_SIZE) {
3532
+ const toRemove = Math.floor(MAX_UNKNOWN_CACHE_SIZE / 2);
3533
+ const iterator = UNKNOWN_PREFIX_CACHE.values();
3534
+ for (let i = 0; i < toRemove; i += 1) {
3535
+ const value = iterator.next().value;
3536
+ if (value) UNKNOWN_PREFIX_CACHE.delete(value);
3537
+ }
3538
+ }
3539
+ UNKNOWN_PREFIX_CACHE.add(prefix);
3540
+ }
3541
+ return result;
3508
3542
  }
3509
3543
  function compileBaseToken(baseToken, theme2, pluginRegistry) {
3510
3544
  if (pluginRegistry) {
@@ -3748,6 +3782,30 @@ function compileRuntimeClassNameWithContext(className, context) {
3748
3782
  function compileClass(className, options = {}) {
3749
3783
  return compileRuntimeClassNameWithContext(className, resolveRuntimeContext(options));
3750
3784
  }
3785
+ function compileCriticalCss(classNames, options = {}) {
3786
+ const classList = typeof classNames === "string" ? classNames.split(/\s+/).filter(Boolean) : Array.isArray(classNames) ? classNames.flatMap(
3787
+ (str) => typeof str === "string" ? str.split(/\s+/).filter(Boolean) : []
3788
+ ) : [];
3789
+ const context = resolveRuntimeContext(options);
3790
+ const cssRules = /* @__PURE__ */ new Set();
3791
+ classList.forEach((className) => {
3792
+ const css = compileRuntimeClassNameWithContext(className, context);
3793
+ if (css) {
3794
+ cssRules.add(css);
3795
+ }
3796
+ });
3797
+ return Array.from(cssRules).join("\n");
3798
+ }
3799
+ function extractClassNames(html) {
3800
+ const classSet = /* @__PURE__ */ new Set();
3801
+ const classRegex = /class(?:Name)?=["']([^"']+)["']/g;
3802
+ let match;
3803
+ while ((match = classRegex.exec(html)) !== null) {
3804
+ const classes = match[1].split(/\s+/).filter(Boolean);
3805
+ classes.forEach((cls) => classSet.add(cls));
3806
+ }
3807
+ return Array.from(classSet);
3808
+ }
3751
3809
 
3752
3810
  // src/preflight.js
3753
3811
  var preflight = `
@@ -3895,7 +3953,16 @@ function createWindrunner(options = {}) {
3895
3953
  const cssRule = compileWithCache(className);
3896
3954
  if (!cssRule) {
3897
3955
  ensureCompatStyle();
3898
- if (onError) onError(className);
3956
+ if (onError) {
3957
+ const parsed = parseClass(className, context.screens, context.containers);
3958
+ const errorContext = {
3959
+ reason: parsed ? "unknown-utility" : "parse-error",
3960
+ baseToken: parsed ? parsed.baseToken : className,
3961
+ variants: parsed ? parsed.variants : void 0,
3962
+ details: parsed ? `Could not compile utility "${parsed.baseToken}"${parsed.variants.length ? ` with variants: ${parsed.variants.join(", ")}` : ""}` : `Failed to parse class name "${className}"`
3963
+ };
3964
+ onError(className, errorContext);
3965
+ }
3899
3966
  } else {
3900
3967
  insertRule(cssRule);
3901
3968
  if (onCompile) onCompile(className, cssRule);
@@ -3919,9 +3986,39 @@ function createWindrunner(options = {}) {
3919
3986
  };
3920
3987
  const scan = (root = document) => {
3921
3988
  if (typeof document !== "object" || !root) return;
3922
- if (root.nodeType === 1) processElementTree(root);
3989
+ const startTime = typeof performance !== "undefined" ? performance.now() : Date.now();
3990
+ const scannedElements = /* @__PURE__ */ new Set();
3991
+ const foundClasses = /* @__PURE__ */ new Set();
3992
+ const initialRuleCount = insertedRules.size;
3993
+ if (root.nodeType === 1) {
3994
+ processElementTree(root);
3995
+ if (root.classList) {
3996
+ scannedElements.add(root);
3997
+ root.classList.forEach((cls) => foundClasses.add(cls));
3998
+ }
3999
+ }
3923
4000
  const elements = root.querySelectorAll ? root.querySelectorAll("[class]") : [];
3924
- elements.forEach((element) => processElement(element));
4001
+ elements.forEach((element) => {
4002
+ processElement(element);
4003
+ scannedElements.add(element);
4004
+ if (element.classList) {
4005
+ element.classList.forEach((cls) => foundClasses.add(cls));
4006
+ }
4007
+ });
4008
+ if (typeof options.onScanComplete === "function") {
4009
+ const endTime = typeof performance !== "undefined" ? performance.now() : Date.now();
4010
+ const stats = {
4011
+ elementCount: scannedElements.size,
4012
+ classCount: foundClasses.size,
4013
+ ruleCount: insertedRules.size - initialRuleCount,
4014
+ duration: endTime - startTime
4015
+ };
4016
+ if (typeof requestAnimationFrame === "function") {
4017
+ requestAnimationFrame(() => options.onScanComplete(stats));
4018
+ } else {
4019
+ setTimeout(() => options.onScanComplete(stats), 0);
4020
+ }
4021
+ }
3925
4022
  };
3926
4023
  const flushQueue = () => {
3927
4024
  scheduled = false;
@@ -3954,12 +4051,18 @@ function createWindrunner(options = {}) {
3954
4051
  });
3955
4052
  scheduleFlush();
3956
4053
  });
3957
- observer.observe(root, {
3958
- childList: true,
3959
- subtree: true,
3960
- attributes: true,
3961
- attributeFilter: ["class"]
3962
- });
4054
+ const observerConfig = options.observerOptions || {};
4055
+ const finalConfig = {
4056
+ childList: observerConfig.childList !== false,
4057
+ // default: true
4058
+ subtree: observerConfig.subtree !== false,
4059
+ // default: true
4060
+ attributes: observerConfig.attributes !== false,
4061
+ // default: true
4062
+ attributeFilter: observerConfig.attributeFilter || ["class"]
4063
+ // default: ["class"]
4064
+ };
4065
+ observer.observe(root, finalConfig);
3963
4066
  };
3964
4067
  const disconnect = () => {
3965
4068
  pendingElements.clear();
@@ -4036,10 +4139,13 @@ function windrunner(options = {}) {
4036
4139
  }
4037
4140
  export {
4038
4141
  compileClass,
4142
+ compileCriticalCss,
4039
4143
  createWindrunner,
4040
4144
  defineResponsiveUtilities,
4041
4145
  defineUtilities,
4146
+ extractClassNames,
4042
4147
  parseClass,
4043
4148
  plugin,
4044
4149
  windrunner
4045
4150
  };
4151
+ //# sourceMappingURL=index.esm.js.map