zss-engine 0.2.76 → 0.2.78

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/cjs/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hasWebpackPlugin = exports.injectClientGlobalCSS = exports.injectClientCSS = exports.applyCssValue = exports.camelToKebabCase = exports.build = exports.processAtomicProps = exports.splitAtomicAndNested = exports.transpileAtomic = exports.transpile = exports.genBase36Hash = exports.isTestingDevelopment = exports.isDevelopment = exports.isServer = void 0;
3
+ exports.isHashInStyleSheets = exports.injectClientGlobalCSS = exports.injectClientCSS = exports.applyCssValue = exports.camelToKebabCase = exports.build = exports.processAtomicProps = exports.splitAtomicAndNested = exports.transpileAtomic = exports.transpile = exports.genBase36Hash = exports.isTestingDevelopment = exports.isDevelopment = exports.isServer = void 0;
4
4
  var helper_js_1 = require("./utils/helper.js");
5
5
  Object.defineProperty(exports, "isServer", { enumerable: true, get: function () { return helper_js_1.isServer; } });
6
6
  Object.defineProperty(exports, "isDevelopment", { enumerable: true, get: function () { return helper_js_1.isDevelopment; } });
@@ -23,5 +23,5 @@ var inject_client_css_js_1 = require("./utils/inject-client-css.js");
23
23
  Object.defineProperty(exports, "injectClientCSS", { enumerable: true, get: function () { return inject_client_css_js_1.injectClientCSS; } });
24
24
  var inject_client_global_css_js_1 = require("./utils/inject-client-global-css.js");
25
25
  Object.defineProperty(exports, "injectClientGlobalCSS", { enumerable: true, get: function () { return inject_client_global_css_js_1.injectClientGlobalCSS; } });
26
- var has_webpack_plugin_1 = require("./utils/has-webpack-plugin");
27
- Object.defineProperty(exports, "hasWebpackPlugin", { enumerable: true, get: function () { return has_webpack_plugin_1.hasWebpackPlugin; } });
26
+ var is_hash_in_style_sheets_js_1 = require("./utils/is-hash-in-style-sheets.js");
27
+ Object.defineProperty(exports, "isHashInStyleSheets", { enumerable: true, get: function () { return is_hash_in_style_sheets_js_1.isHashInStyleSheets; } });
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isHashInStyleSheets = isHashInStyleSheets;
4
+ function isHashInStyleSheets(hash) {
5
+ const sheets = Array.from(document.styleSheets);
6
+ function checkRule(rule) {
7
+ if (rule instanceof CSSStyleRule && rule.selectorText) {
8
+ return hasHashInSelector(rule.selectorText, hash);
9
+ }
10
+ if (rule instanceof CSSMediaRule) {
11
+ return Array.from(rule.cssRules).some(checkRule);
12
+ }
13
+ if (rule instanceof CSSContainerRule) {
14
+ return Array.from(rule.cssRules).some(checkRule);
15
+ }
16
+ if (rule instanceof CSSSupportsRule) {
17
+ return Array.from(rule.cssRules).some(checkRule);
18
+ }
19
+ if ('cssRules' in rule && rule.cssRules) {
20
+ return Array.from(rule.cssRules).some(checkRule);
21
+ }
22
+ return false;
23
+ }
24
+ function hasHashInSelector(selectorText, hash) {
25
+ const selectors = selectorText.split(',').map(s => s.trim());
26
+ return selectors.some(selector => {
27
+ const classPattern = new RegExp(`\\.${escapeRegExp(hash)}(?![\\w-])`);
28
+ return classPattern.test(selector);
29
+ });
30
+ }
31
+ function escapeRegExp(string) {
32
+ return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
33
+ }
34
+ return sheets.some(sheet => {
35
+ try {
36
+ return Array.from(sheet.cssRules).some(checkRule);
37
+ }
38
+ catch (_err) {
39
+ return false;
40
+ }
41
+ });
42
+ }
package/dist/esm/index.js CHANGED
@@ -7,4 +7,4 @@ export { build } from './utils/build.js';
7
7
  export { camelToKebabCase, applyCssValue } from './utils/helper.js';
8
8
  export { injectClientCSS } from './utils/inject-client-css.js';
9
9
  export { injectClientGlobalCSS } from './utils/inject-client-global-css.js';
10
- export { hasWebpackPlugin } from './utils/has-webpack-plugin';
10
+ export { isHashInStyleSheets } from './utils/is-hash-in-style-sheets.js';
@@ -0,0 +1,39 @@
1
+ export function isHashInStyleSheets(hash) {
2
+ const sheets = Array.from(document.styleSheets);
3
+ function checkRule(rule) {
4
+ if (rule instanceof CSSStyleRule && rule.selectorText) {
5
+ return hasHashInSelector(rule.selectorText, hash);
6
+ }
7
+ if (rule instanceof CSSMediaRule) {
8
+ return Array.from(rule.cssRules).some(checkRule);
9
+ }
10
+ if (rule instanceof CSSContainerRule) {
11
+ return Array.from(rule.cssRules).some(checkRule);
12
+ }
13
+ if (rule instanceof CSSSupportsRule) {
14
+ return Array.from(rule.cssRules).some(checkRule);
15
+ }
16
+ if ('cssRules' in rule && rule.cssRules) {
17
+ return Array.from(rule.cssRules).some(checkRule);
18
+ }
19
+ return false;
20
+ }
21
+ function hasHashInSelector(selectorText, hash) {
22
+ const selectors = selectorText.split(',').map(s => s.trim());
23
+ return selectors.some(selector => {
24
+ const classPattern = new RegExp(`\\.${escapeRegExp(hash)}(?![\\w-])`);
25
+ return classPattern.test(selector);
26
+ });
27
+ }
28
+ function escapeRegExp(string) {
29
+ return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
30
+ }
31
+ return sheets.some(sheet => {
32
+ try {
33
+ return Array.from(sheet.cssRules).some(checkRule);
34
+ }
35
+ catch (_err) {
36
+ return false;
37
+ }
38
+ });
39
+ }
@@ -11,4 +11,4 @@ export { build } from './utils/build.js';
11
11
  export { camelToKebabCase, applyCssValue } from './utils/helper.js';
12
12
  export { injectClientCSS } from './utils/inject-client-css.js';
13
13
  export { injectClientGlobalCSS } from './utils/inject-client-global-css.js';
14
- export { hasWebpackPlugin } from './utils/has-webpack-plugin';
14
+ export { isHashInStyleSheets } from './utils/is-hash-in-style-sheets.js';
@@ -0,0 +1 @@
1
+ export declare function isHashInStyleSheets(hash: string): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zss-engine",
3
- "version": "0.2.76",
3
+ "version": "0.2.78",
4
4
  "description": "Zero-runtime StyleSheet Engine",
5
5
  "keywords": [
6
6
  "zero-runtime",
@@ -1,37 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.hasWebpackPlugin = hasWebpackPlugin;
7
- const fs_1 = __importDefault(require("fs"));
8
- const path_1 = __importDefault(require("path"));
9
- function findPnpmPath(arg1, arg2) {
10
- const pnpmPath = path_1.default.join(process.cwd(), 'node_modules/.pnpm');
11
- const pnpmDir = fs_1.default.readdirSync(pnpmPath).find(dir => dir.startsWith(arg1));
12
- if (!pnpmDir) {
13
- throw new Error(`Could not find ${arg1} package in pnpm directory`);
14
- }
15
- return path_1.default.join(pnpmPath, pnpmDir, arg2);
16
- }
17
- function hasWebpackPlugin() {
18
- try {
19
- const isPnpm = fs_1.default.existsSync(path_1.default.join(process.cwd(), 'node_modules/.pnpm'));
20
- if (isPnpm) {
21
- try {
22
- const webpackPluginPath = findPnpmPath('@plumeria+webpack-plugin@', 'node_modules/@plumeria/webpack-plugin');
23
- return fs_1.default.existsSync(webpackPluginPath);
24
- }
25
- catch {
26
- return false;
27
- }
28
- }
29
- else {
30
- const webpackPluginPath = path_1.default.join(process.cwd(), 'node_modules/@plumeria/webpack-plugin');
31
- return fs_1.default.existsSync(webpackPluginPath);
32
- }
33
- }
34
- catch {
35
- return false;
36
- }
37
- }
@@ -1,31 +0,0 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
- function findPnpmPath(arg1, arg2) {
4
- const pnpmPath = path.join(process.cwd(), 'node_modules/.pnpm');
5
- const pnpmDir = fs.readdirSync(pnpmPath).find(dir => dir.startsWith(arg1));
6
- if (!pnpmDir) {
7
- throw new Error(`Could not find ${arg1} package in pnpm directory`);
8
- }
9
- return path.join(pnpmPath, pnpmDir, arg2);
10
- }
11
- export function hasWebpackPlugin() {
12
- try {
13
- const isPnpm = fs.existsSync(path.join(process.cwd(), 'node_modules/.pnpm'));
14
- if (isPnpm) {
15
- try {
16
- const webpackPluginPath = findPnpmPath('@plumeria+webpack-plugin@', 'node_modules/@plumeria/webpack-plugin');
17
- return fs.existsSync(webpackPluginPath);
18
- }
19
- catch {
20
- return false;
21
- }
22
- }
23
- else {
24
- const webpackPluginPath = path.join(process.cwd(), 'node_modules/@plumeria/webpack-plugin');
25
- return fs.existsSync(webpackPluginPath);
26
- }
27
- }
28
- catch {
29
- return false;
30
- }
31
- }
@@ -1 +0,0 @@
1
- export declare function hasWebpackPlugin(): boolean;