@plumeria/unplugin 13.0.1 → 13.1.0

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.
Files changed (3) hide show
  1. package/dist/core.js +16 -39
  2. package/dist/core.mjs +16 -39
  3. package/package.json +2 -2
package/dist/core.js CHANGED
@@ -41,28 +41,6 @@ const zss_engine_1 = require("zss-engine");
41
41
  const utils_1 = require("@plumeria/utils");
42
42
  exports.TARGET_EXTENSIONS = ['ts', 'tsx', 'js', 'jsx'];
43
43
  exports.EXTENSION_PATTERN = /\.(ts|tsx|js|jsx)$/;
44
- function cleanStaleThemeRules(acc, newSheets) {
45
- const newCss = newSheets.join('');
46
- const hashRegex = /--([a-z0-9]{8})-[a-zA-Z0-9-]+/g;
47
- const hashes = new Set();
48
- let match;
49
- while ((match = hashRegex.exec(newCss)) !== null) {
50
- hashes.add(match[1]);
51
- }
52
- for (const sheet of acc) {
53
- let hasStaleHash = false;
54
- for (const hash of hashes) {
55
- const declRegex = new RegExp(`--${hash}-[a-zA-Z0-9-]+:`);
56
- if (declRegex.test(sheet)) {
57
- hasStaleHash = true;
58
- break;
59
- }
60
- }
61
- if (hasStaleHash && !newSheets.includes(sheet)) {
62
- acc.delete(sheet);
63
- }
64
- }
65
- }
66
44
  const unpluginFactory = (options = {}, unpluginMeta) => {
67
45
  const filter = (0, pluginutils_1.createFilter)(options.include, options.exclude);
68
46
  const cssLookup = new Map();
@@ -1530,24 +1508,23 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
1530
1508
  parts.push(buffer.subarray(offset));
1531
1509
  const transformedSource = Buffer.concat(parts).toString();
1532
1510
  const optInCSS = await (0, utils_1.optimizer)(extractedSheets.join(''));
1533
- if (extractedSheets.length > 0) {
1534
- const baseId = id.replace(exports.EXTENSION_PATTERN, '');
1535
- const cssFilename = `${baseId}.zero.css`;
1536
- const cssId = `/${path.relative(viteRoot, cssFilename).replace(/\\/g, '/')}`;
1537
- if (isDev) {
1538
- if (!devCssSheets.has(cssFilename)) {
1539
- devCssSheets.set(cssFilename, new Set());
1540
- }
1541
- const acc = devCssSheets.get(cssFilename);
1542
- cleanStaleThemeRules(acc, extractedSheets);
1543
- extractedSheets.forEach((sheet) => acc.add(sheet));
1544
- const accCSS = await (0, utils_1.optimizer)(Array.from(acc).join(''));
1545
- cssLookup.set(cssFilename, accCSS);
1511
+ const cssFilename = `${baseId.replace(exports.EXTENSION_PATTERN, '')}.zero.css`;
1512
+ const cssId = `/${path.relative(viteRoot, cssFilename).replace(/\\/g, '/')}`;
1513
+ if (isDev) {
1514
+ if (!devCssSheets.has(cssFilename)) {
1515
+ devCssSheets.set(cssFilename, new Set());
1546
1516
  }
1547
- else {
1548
- cssLookup.set(cssFilename, optInCSS);
1549
- }
1550
- cssFileLookup.set(cssId, cssFilename);
1517
+ const acc = devCssSheets.get(cssFilename);
1518
+ acc.clear();
1519
+ extractedSheets.forEach((sheet) => acc.add(sheet));
1520
+ const accCSS = await (0, utils_1.optimizer)(Array.from(acc).join(''));
1521
+ cssLookup.set(cssFilename, accCSS);
1522
+ }
1523
+ else {
1524
+ cssLookup.set(cssFilename, optInCSS);
1525
+ }
1526
+ cssFileLookup.set(cssId, cssFilename);
1527
+ if (extractedSheets.length > 0) {
1551
1528
  const targetIndex = targets.findIndex((t) => t.id === id);
1552
1529
  if (targetIndex !== -1) {
1553
1530
  targets[targetIndex].dependencies = dependencies;
package/dist/core.mjs CHANGED
@@ -5,28 +5,6 @@ import { applyCssValue, genBase36Hash, exceptionCamelCase, camelToKebabCase, isA
5
5
  import { traverse, getStyleRecords, collectLocalConsts, objectExpressionToObject, t, extractOndemandStyles, deepMerge, scanAll, resolveImportPath, processVariants, getLeadingCommentLength, optimizer, } from '@plumeria/utils';
6
6
  export const TARGET_EXTENSIONS = ['ts', 'tsx', 'js', 'jsx'];
7
7
  export const EXTENSION_PATTERN = /\.(ts|tsx|js|jsx)$/;
8
- function cleanStaleThemeRules(acc, newSheets) {
9
- const newCss = newSheets.join('');
10
- const hashRegex = /--([a-z0-9]{8})-[a-zA-Z0-9-]+/g;
11
- const hashes = new Set();
12
- let match;
13
- while ((match = hashRegex.exec(newCss)) !== null) {
14
- hashes.add(match[1]);
15
- }
16
- for (const sheet of acc) {
17
- let hasStaleHash = false;
18
- for (const hash of hashes) {
19
- const declRegex = new RegExp(`--${hash}-[a-zA-Z0-9-]+:`);
20
- if (declRegex.test(sheet)) {
21
- hasStaleHash = true;
22
- break;
23
- }
24
- }
25
- if (hasStaleHash && !newSheets.includes(sheet)) {
26
- acc.delete(sheet);
27
- }
28
- }
29
- }
30
8
  export const unpluginFactory = (options = {}, unpluginMeta) => {
31
9
  const filter = createFilter(options.include, options.exclude);
32
10
  const cssLookup = new Map();
@@ -1494,24 +1472,23 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
1494
1472
  parts.push(buffer.subarray(offset));
1495
1473
  const transformedSource = Buffer.concat(parts).toString();
1496
1474
  const optInCSS = await optimizer(extractedSheets.join(''));
1497
- if (extractedSheets.length > 0) {
1498
- const baseId = id.replace(EXTENSION_PATTERN, '');
1499
- const cssFilename = `${baseId}.zero.css`;
1500
- const cssId = `/${path.relative(viteRoot, cssFilename).replace(/\\/g, '/')}`;
1501
- if (isDev) {
1502
- if (!devCssSheets.has(cssFilename)) {
1503
- devCssSheets.set(cssFilename, new Set());
1504
- }
1505
- const acc = devCssSheets.get(cssFilename);
1506
- cleanStaleThemeRules(acc, extractedSheets);
1507
- extractedSheets.forEach((sheet) => acc.add(sheet));
1508
- const accCSS = await optimizer(Array.from(acc).join(''));
1509
- cssLookup.set(cssFilename, accCSS);
1510
- }
1511
- else {
1512
- cssLookup.set(cssFilename, optInCSS);
1475
+ const cssFilename = `${baseId.replace(EXTENSION_PATTERN, '')}.zero.css`;
1476
+ const cssId = `/${path.relative(viteRoot, cssFilename).replace(/\\/g, '/')}`;
1477
+ if (isDev) {
1478
+ if (!devCssSheets.has(cssFilename)) {
1479
+ devCssSheets.set(cssFilename, new Set());
1513
1480
  }
1514
- cssFileLookup.set(cssId, cssFilename);
1481
+ const acc = devCssSheets.get(cssFilename);
1482
+ acc.clear();
1483
+ extractedSheets.forEach((sheet) => acc.add(sheet));
1484
+ const accCSS = await optimizer(Array.from(acc).join(''));
1485
+ cssLookup.set(cssFilename, accCSS);
1486
+ }
1487
+ else {
1488
+ cssLookup.set(cssFilename, optInCSS);
1489
+ }
1490
+ cssFileLookup.set(cssId, cssFilename);
1491
+ if (extractedSheets.length > 0) {
1515
1492
  const targetIndex = targets.findIndex((t) => t.id === id);
1516
1493
  if (targetIndex !== -1) {
1517
1494
  targets[targetIndex].dependencies = dependencies;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/unplugin",
3
- "version": "13.0.1",
3
+ "version": "13.1.0",
4
4
  "description": "Universal Plumeria plugin for various build tools",
5
5
  "author": "Refirst 11",
6
6
  "license": "MIT",
@@ -86,7 +86,7 @@
86
86
  ],
87
87
  "dependencies": {
88
88
  "unplugin": "^3.0.0",
89
- "@plumeria/utils": "^13.0.1"
89
+ "@plumeria/utils": "^13.1.0"
90
90
  },
91
91
  "devDependencies": {
92
92
  "@rollup/pluginutils": "^5.4.0",