zss-engine 0.2.5 → 0.2.7
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.js +32 -1
- package/dist/index.mjs +8 -1
- package/dist/types/common/css-properties.js +2 -1
- package/dist/types/common/css-properties.mjs +1 -1
- package/dist/types/common/css-property.js +2 -1
- package/dist/types/common/css-property.mjs +1 -1
- package/dist/types/index.js +21 -1
- package/dist/types/index.mjs +5 -1
- package/dist/types/main/create.js +2 -1
- package/dist/types/main/create.mjs +1 -1
- package/dist/types/main/global.js +2 -1
- package/dist/types/main/global.mjs +1 -1
- package/dist/types/main/vars.js +2 -1
- package/dist/types/main/vars.mjs +1 -1
- package/dist/utils/build.js +27 -1
- package/dist/utils/build.mjs +23 -1
- package/dist/utils/hash.js +34 -1
- package/dist/utils/hash.mjs +31 -1
- package/dist/utils/helper.js +21 -1
- package/dist/utils/helper.mjs +16 -1
- package/dist/utils/inject-client-css.js +51 -1
- package/dist/utils/inject-client-css.mjs +47 -1
- package/dist/utils/inject-client-global-css.js +18 -1
- package/dist/utils/inject-client-global-css.mjs +15 -1
- package/dist/utils/inject-server-css.js +11 -1
- package/dist/utils/inject-server-css.mjs +7 -1
- package/dist/utils/transpiler.js +125 -1
- package/dist/utils/transpiler.mjs +122 -1
- package/package.json +8 -11
- /package/{dist → types}/index.d.ts +0 -0
- /package/{dist → types}/types/common/css-properties.d.ts +0 -0
- /package/{dist → types}/types/common/css-property.d.ts +0 -0
- /package/{dist → types}/types/index.d.ts +0 -0
- /package/{dist → types}/types/main/create.d.ts +0 -0
- /package/{dist → types}/types/main/global.d.ts +0 -0
- /package/{dist → types}/types/main/vars.d.ts +0 -0
- /package/{dist → types}/utils/build.d.ts +0 -0
- /package/{dist → types}/utils/hash.d.ts +0 -0
- /package/{dist → types}/utils/helper.d.ts +0 -0
- /package/{dist → types}/utils/inject-client-css.d.ts +0 -0
- /package/{dist → types}/utils/inject-client-global-css.d.ts +0 -0
- /package/{dist → types}/utils/inject-server-css.d.ts +0 -0
- /package/{dist → types}/utils/transpiler.d.ts +0 -0
package/dist/index.js
CHANGED
|
@@ -1 +1,32 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.transpiler = exports.build = exports.getServerCSS = exports.injectServerCSS = exports.injectClientGlobalCSS = exports.injectClientCSS = exports.genBase36Hash = void 0;
|
|
18
|
+
__exportStar(require("./types"), exports);
|
|
19
|
+
__exportStar(require("./utils/helper"), exports);
|
|
20
|
+
var hash_1 = require("./utils/hash");
|
|
21
|
+
Object.defineProperty(exports, "genBase36Hash", { enumerable: true, get: function () { return hash_1.genBase36Hash; } });
|
|
22
|
+
var inject_client_css_1 = require("./utils/inject-client-css");
|
|
23
|
+
Object.defineProperty(exports, "injectClientCSS", { enumerable: true, get: function () { return inject_client_css_1.injectClientCSS; } });
|
|
24
|
+
var inject_client_global_css_1 = require("./utils/inject-client-global-css");
|
|
25
|
+
Object.defineProperty(exports, "injectClientGlobalCSS", { enumerable: true, get: function () { return inject_client_global_css_1.injectClientGlobalCSS; } });
|
|
26
|
+
var inject_server_css_1 = require("./utils/inject-server-css");
|
|
27
|
+
Object.defineProperty(exports, "injectServerCSS", { enumerable: true, get: function () { return inject_server_css_1.injectServerCSS; } });
|
|
28
|
+
Object.defineProperty(exports, "getServerCSS", { enumerable: true, get: function () { return inject_server_css_1.getServerCSS; } });
|
|
29
|
+
var build_1 = require("./utils/build");
|
|
30
|
+
Object.defineProperty(exports, "build", { enumerable: true, get: function () { return build_1.build; } });
|
|
31
|
+
var transpiler_1 = require("./utils/transpiler");
|
|
32
|
+
Object.defineProperty(exports, "transpiler", { enumerable: true, get: function () { return transpiler_1.transpiler; } });
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1,8 @@
|
|
|
1
|
-
export*from
|
|
1
|
+
export * from './types';
|
|
2
|
+
export * from './utils/helper';
|
|
3
|
+
export { genBase36Hash } from './utils/hash';
|
|
4
|
+
export { injectClientCSS } from './utils/inject-client-css';
|
|
5
|
+
export { injectClientGlobalCSS } from './utils/inject-client-global-css';
|
|
6
|
+
export { injectServerCSS, getServerCSS } from './utils/inject-server-css';
|
|
7
|
+
export { build } from './utils/build';
|
|
8
|
+
export { transpiler } from './utils/transpiler';
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export{};
|
|
1
|
+
export {};
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export{};
|
|
1
|
+
export {};
|
package/dist/types/index.js
CHANGED
|
@@ -1 +1,21 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./common/css-properties"), exports);
|
|
18
|
+
__exportStar(require("./common/css-property"), exports);
|
|
19
|
+
__exportStar(require("./main/create"), exports);
|
|
20
|
+
__exportStar(require("./main/global"), exports);
|
|
21
|
+
__exportStar(require("./main/vars"), exports);
|
package/dist/types/index.mjs
CHANGED
|
@@ -1 +1,5 @@
|
|
|
1
|
-
export*from
|
|
1
|
+
export * from './common/css-properties';
|
|
2
|
+
export * from './common/css-property';
|
|
3
|
+
export * from './main/create';
|
|
4
|
+
export * from './main/global';
|
|
5
|
+
export * from './main/vars';
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export{};
|
|
1
|
+
export {};
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export{};
|
|
1
|
+
export {};
|
package/dist/types/main/vars.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/dist/types/main/vars.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{};
|
|
1
|
+
export {};
|
package/dist/utils/build.js
CHANGED
|
@@ -1 +1,27 @@
|
|
|
1
|
-
|
|
1
|
+
'use server';
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.build = void 0;
|
|
5
|
+
const helper_1 = require("./helper");
|
|
6
|
+
const build = async (styleSheet, filePath, global) => {
|
|
7
|
+
if (!helper_1.isServer)
|
|
8
|
+
return;
|
|
9
|
+
const fs = require('fs');
|
|
10
|
+
const { styleText } = require('util');
|
|
11
|
+
const message = global === '--global' ? styleText('underline', `✅Generated global CSS\n\n`) : styleText('underline', `✅Generated create CSS\n\n`);
|
|
12
|
+
try {
|
|
13
|
+
if (fs.existsSync(filePath)) {
|
|
14
|
+
const cssData = fs.readFileSync(filePath, 'utf-8');
|
|
15
|
+
if (!cssData.includes(styleSheet)) {
|
|
16
|
+
fs.appendFileSync(filePath, styleSheet, 'utf-8');
|
|
17
|
+
if (process.argv.includes('--log'))
|
|
18
|
+
console.log(message + styleSheet);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
console.error('Error writing to file:', error);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
exports.build = build;
|
package/dist/utils/build.mjs
CHANGED
|
@@ -1 +1,23 @@
|
|
|
1
|
-
|
|
1
|
+
'use server';
|
|
2
|
+
import { isServer } from './helper';
|
|
3
|
+
export const build = async (styleSheet, filePath, global) => {
|
|
4
|
+
if (!isServer)
|
|
5
|
+
return;
|
|
6
|
+
const fs = require('fs');
|
|
7
|
+
const { styleText } = require('util');
|
|
8
|
+
const message = global === '--global' ? styleText('underline', `✅Generated global CSS\n\n`) : styleText('underline', `✅Generated create CSS\n\n`);
|
|
9
|
+
try {
|
|
10
|
+
if (fs.existsSync(filePath)) {
|
|
11
|
+
const cssData = fs.readFileSync(filePath, 'utf-8');
|
|
12
|
+
if (!cssData.includes(styleSheet)) {
|
|
13
|
+
fs.appendFileSync(filePath, styleSheet, 'utf-8');
|
|
14
|
+
if (process.argv.includes('--log'))
|
|
15
|
+
console.log(message + styleSheet);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
console.error('Error writing to file:', error);
|
|
22
|
+
}
|
|
23
|
+
};
|
package/dist/utils/hash.js
CHANGED
|
@@ -1 +1,34 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.genBase36Hash = genBase36Hash;
|
|
4
|
+
const chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
|
5
|
+
function simpleHash(str) {
|
|
6
|
+
let hash = 0;
|
|
7
|
+
for (let i = 0; i < str.length; i++) {
|
|
8
|
+
const char = str.charCodeAt(i);
|
|
9
|
+
hash = (hash << 5) - hash + char;
|
|
10
|
+
}
|
|
11
|
+
return Math.abs(hash);
|
|
12
|
+
}
|
|
13
|
+
function encodeBase36(num) {
|
|
14
|
+
let result = '';
|
|
15
|
+
do {
|
|
16
|
+
result = chars[num % 36] + result;
|
|
17
|
+
num = Math.floor(num / 36);
|
|
18
|
+
} while (num > 0);
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
function getStartingChar(hash) {
|
|
22
|
+
const chars = 'abcdefghijklmnopqrstuvwxyz';
|
|
23
|
+
return chars[hash % chars.length];
|
|
24
|
+
}
|
|
25
|
+
function genBase36Hash(object, n) {
|
|
26
|
+
const serialized = JSON.stringify(object);
|
|
27
|
+
const hash = simpleHash(serialized);
|
|
28
|
+
let base36Hash = encodeBase36(hash);
|
|
29
|
+
const startingChar = getStartingChar(hash);
|
|
30
|
+
while (base36Hash.length < n - 1) {
|
|
31
|
+
base36Hash = chars[hash % chars.length] + base36Hash;
|
|
32
|
+
}
|
|
33
|
+
return startingChar + base36Hash.slice(0, n - 1);
|
|
34
|
+
}
|
package/dist/utils/hash.mjs
CHANGED
|
@@ -1 +1,31 @@
|
|
|
1
|
-
const chars
|
|
1
|
+
const chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
|
2
|
+
function simpleHash(str) {
|
|
3
|
+
let hash = 0;
|
|
4
|
+
for (let i = 0; i < str.length; i++) {
|
|
5
|
+
const char = str.charCodeAt(i);
|
|
6
|
+
hash = (hash << 5) - hash + char;
|
|
7
|
+
}
|
|
8
|
+
return Math.abs(hash);
|
|
9
|
+
}
|
|
10
|
+
function encodeBase36(num) {
|
|
11
|
+
let result = '';
|
|
12
|
+
do {
|
|
13
|
+
result = chars[num % 36] + result;
|
|
14
|
+
num = Math.floor(num / 36);
|
|
15
|
+
} while (num > 0);
|
|
16
|
+
return result;
|
|
17
|
+
}
|
|
18
|
+
function getStartingChar(hash) {
|
|
19
|
+
const chars = 'abcdefghijklmnopqrstuvwxyz';
|
|
20
|
+
return chars[hash % chars.length];
|
|
21
|
+
}
|
|
22
|
+
export function genBase36Hash(object, n) {
|
|
23
|
+
const serialized = JSON.stringify(object);
|
|
24
|
+
const hash = simpleHash(serialized);
|
|
25
|
+
let base36Hash = encodeBase36(hash);
|
|
26
|
+
const startingChar = getStartingChar(hash);
|
|
27
|
+
while (base36Hash.length < n - 1) {
|
|
28
|
+
base36Hash = chars[hash % chars.length] + base36Hash;
|
|
29
|
+
}
|
|
30
|
+
return startingChar + base36Hash.slice(0, n - 1);
|
|
31
|
+
}
|
package/dist/utils/helper.js
CHANGED
|
@@ -1 +1,21 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.camelToKebabCase = exports.applyCssValue = exports.isDevServer = exports.isDevAndTest = exports.isDevelopment = exports.isServer = void 0;
|
|
4
|
+
const isWindowDefined = typeof window !== 'undefined';
|
|
5
|
+
const isDocumentDefined = typeof document !== 'undefined';
|
|
6
|
+
exports.isServer = !isWindowDefined || !isDocumentDefined;
|
|
7
|
+
exports.isDevelopment = process.env.NODE_ENV === 'development';
|
|
8
|
+
exports.isDevAndTest = process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test';
|
|
9
|
+
exports.isDevServer = exports.isDevelopment && exports.isServer;
|
|
10
|
+
const exception = ['line-height', 'font-weight', 'opacity', 'scale', 'z-index', 'column-count', 'order', 'orphans', 'widows'];
|
|
11
|
+
const applyCssValue = (value, cssProp) => {
|
|
12
|
+
if (typeof value === 'number') {
|
|
13
|
+
return exception.includes(cssProp) ? value.toString() : value + 'px';
|
|
14
|
+
}
|
|
15
|
+
return value;
|
|
16
|
+
};
|
|
17
|
+
exports.applyCssValue = applyCssValue;
|
|
18
|
+
const camelToKebabCase = (property) => {
|
|
19
|
+
return property.replace(/([A-Z])/g, '-$1').toLowerCase();
|
|
20
|
+
};
|
|
21
|
+
exports.camelToKebabCase = camelToKebabCase;
|
package/dist/utils/helper.mjs
CHANGED
|
@@ -1 +1,16 @@
|
|
|
1
|
-
const isWindowDefined=typeof window!==
|
|
1
|
+
const isWindowDefined = typeof window !== 'undefined';
|
|
2
|
+
const isDocumentDefined = typeof document !== 'undefined';
|
|
3
|
+
export const isServer = !isWindowDefined || !isDocumentDefined;
|
|
4
|
+
export const isDevelopment = process.env.NODE_ENV === 'development';
|
|
5
|
+
export const isDevAndTest = process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test';
|
|
6
|
+
export const isDevServer = isDevelopment && isServer;
|
|
7
|
+
const exception = ['line-height', 'font-weight', 'opacity', 'scale', 'z-index', 'column-count', 'order', 'orphans', 'widows'];
|
|
8
|
+
export const applyCssValue = (value, cssProp) => {
|
|
9
|
+
if (typeof value === 'number') {
|
|
10
|
+
return exception.includes(cssProp) ? value.toString() : value + 'px';
|
|
11
|
+
}
|
|
12
|
+
return value;
|
|
13
|
+
};
|
|
14
|
+
export const camelToKebabCase = (property) => {
|
|
15
|
+
return property.replace(/([A-Z])/g, '-$1').toLowerCase();
|
|
16
|
+
};
|
|
@@ -1 +1,51 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createStyleElement = createStyleElement;
|
|
4
|
+
exports.injectClientCSS = injectClientCSS;
|
|
5
|
+
const __1 = require("..");
|
|
6
|
+
const styleSheets = {};
|
|
7
|
+
const hashCache = {};
|
|
8
|
+
function createStyleElement(hash) {
|
|
9
|
+
if (document.getElementById(hash))
|
|
10
|
+
return null;
|
|
11
|
+
const styleElement = document.createElement('style');
|
|
12
|
+
styleElement.setAttribute('id', hash);
|
|
13
|
+
styleElement.setAttribute('type', 'text/css');
|
|
14
|
+
styleSheets[hash] = styleElement;
|
|
15
|
+
document.head.appendChild(styleElement);
|
|
16
|
+
return styleSheets[hash];
|
|
17
|
+
}
|
|
18
|
+
function injectClientCSS(hash, sheet) {
|
|
19
|
+
if (__1.isServer)
|
|
20
|
+
return;
|
|
21
|
+
requestAnimationFrame(() => {
|
|
22
|
+
styleCleanUp();
|
|
23
|
+
});
|
|
24
|
+
hashCache[hash] = hash;
|
|
25
|
+
const styleElement = createStyleElement(hash);
|
|
26
|
+
if (styleElement == null)
|
|
27
|
+
return;
|
|
28
|
+
styleElement.textContent = sheet;
|
|
29
|
+
}
|
|
30
|
+
function styleCleanUp() {
|
|
31
|
+
requestAnimationFrame(() => {
|
|
32
|
+
for (const hash in hashCache) {
|
|
33
|
+
const classElements = document.querySelectorAll(`[class*="${hash}"]`);
|
|
34
|
+
if (classElements.length === 0) {
|
|
35
|
+
removeStyleElement(hashCache[hash]);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
function removeStyleElement(hash) {
|
|
41
|
+
if (styleSheets[hash]) {
|
|
42
|
+
delete styleSheets[hash];
|
|
43
|
+
if (hashCache.hasOwnProperty.call(hashCache, hash)) {
|
|
44
|
+
delete hashCache[hash];
|
|
45
|
+
}
|
|
46
|
+
const styleElement = document.getElementById(hash);
|
|
47
|
+
if (styleElement) {
|
|
48
|
+
document.head.removeChild(styleElement);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -1 +1,47 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { isServer } from '..';
|
|
2
|
+
const styleSheets = {};
|
|
3
|
+
const hashCache = {};
|
|
4
|
+
export function createStyleElement(hash) {
|
|
5
|
+
if (document.getElementById(hash))
|
|
6
|
+
return null;
|
|
7
|
+
const styleElement = document.createElement('style');
|
|
8
|
+
styleElement.setAttribute('id', hash);
|
|
9
|
+
styleElement.setAttribute('type', 'text/css');
|
|
10
|
+
styleSheets[hash] = styleElement;
|
|
11
|
+
document.head.appendChild(styleElement);
|
|
12
|
+
return styleSheets[hash];
|
|
13
|
+
}
|
|
14
|
+
export function injectClientCSS(hash, sheet) {
|
|
15
|
+
if (isServer)
|
|
16
|
+
return;
|
|
17
|
+
requestAnimationFrame(() => {
|
|
18
|
+
styleCleanUp();
|
|
19
|
+
});
|
|
20
|
+
hashCache[hash] = hash;
|
|
21
|
+
const styleElement = createStyleElement(hash);
|
|
22
|
+
if (styleElement == null)
|
|
23
|
+
return;
|
|
24
|
+
styleElement.textContent = sheet;
|
|
25
|
+
}
|
|
26
|
+
function styleCleanUp() {
|
|
27
|
+
requestAnimationFrame(() => {
|
|
28
|
+
for (const hash in hashCache) {
|
|
29
|
+
const classElements = document.querySelectorAll(`[class*="${hash}"]`);
|
|
30
|
+
if (classElements.length === 0) {
|
|
31
|
+
removeStyleElement(hashCache[hash]);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
function removeStyleElement(hash) {
|
|
37
|
+
if (styleSheets[hash]) {
|
|
38
|
+
delete styleSheets[hash];
|
|
39
|
+
if (hashCache.hasOwnProperty.call(hashCache, hash)) {
|
|
40
|
+
delete hashCache[hash];
|
|
41
|
+
}
|
|
42
|
+
const styleElement = document.getElementById(hash);
|
|
43
|
+
if (styleElement) {
|
|
44
|
+
document.head.removeChild(styleElement);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -1 +1,18 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.injectClientGlobalCSS = injectClientGlobalCSS;
|
|
4
|
+
const __1 = require("..");
|
|
5
|
+
function injectClientGlobalCSS(sheet, scoped) {
|
|
6
|
+
if (__1.isServer)
|
|
7
|
+
return;
|
|
8
|
+
const existingStyleElement = document.querySelector(`[data-scope="${scoped}"]`);
|
|
9
|
+
if (existingStyleElement instanceof HTMLStyleElement) {
|
|
10
|
+
existingStyleElement.textContent += sheet;
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const styleElement = document.createElement('style');
|
|
14
|
+
styleElement.setAttribute('data-scope', scoped);
|
|
15
|
+
styleElement.setAttribute('type', 'text/css');
|
|
16
|
+
styleElement.textContent = sheet;
|
|
17
|
+
document.head.appendChild(styleElement);
|
|
18
|
+
}
|
|
@@ -1 +1,15 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { isServer } from '..';
|
|
2
|
+
export function injectClientGlobalCSS(sheet, scoped) {
|
|
3
|
+
if (isServer)
|
|
4
|
+
return;
|
|
5
|
+
const existingStyleElement = document.querySelector(`[data-scope="${scoped}"]`);
|
|
6
|
+
if (existingStyleElement instanceof HTMLStyleElement) {
|
|
7
|
+
existingStyleElement.textContent += sheet;
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
const styleElement = document.createElement('style');
|
|
11
|
+
styleElement.setAttribute('data-scope', scoped);
|
|
12
|
+
styleElement.setAttribute('type', 'text/css');
|
|
13
|
+
styleElement.textContent = sheet;
|
|
14
|
+
document.head.appendChild(styleElement);
|
|
15
|
+
}
|
|
@@ -1 +1,11 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.injectServerCSS = injectServerCSS;
|
|
4
|
+
exports.getServerCSS = getServerCSS;
|
|
5
|
+
const styleSheets = {};
|
|
6
|
+
function injectServerCSS(hash, sheet) {
|
|
7
|
+
styleSheets[hash] = sheet;
|
|
8
|
+
}
|
|
9
|
+
function getServerCSS() {
|
|
10
|
+
return Object.values(styleSheets).join('\n');
|
|
11
|
+
}
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
const styleSheets
|
|
1
|
+
const styleSheets = {};
|
|
2
|
+
export function injectServerCSS(hash, sheet) {
|
|
3
|
+
styleSheets[hash] = sheet;
|
|
4
|
+
}
|
|
5
|
+
export function getServerCSS() {
|
|
6
|
+
return Object.values(styleSheets).join('\n');
|
|
7
|
+
}
|
package/dist/utils/transpiler.js
CHANGED
|
@@ -1 +1,125 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transpiler = transpiler;
|
|
4
|
+
const __1 = require("..");
|
|
5
|
+
const createKeyframes = (property, content) => {
|
|
6
|
+
let keyframesRules = `${property} {\n`;
|
|
7
|
+
for (const key in content) {
|
|
8
|
+
if (Object.prototype.hasOwnProperty.call(content, key)) {
|
|
9
|
+
const keyframeValue = content[key];
|
|
10
|
+
keyframesRules += ` ${key} {\n`;
|
|
11
|
+
for (const prop in keyframeValue) {
|
|
12
|
+
if (Object.prototype.hasOwnProperty.call(keyframeValue, prop)) {
|
|
13
|
+
const CSSProp = (0, __1.camelToKebabCase)(prop);
|
|
14
|
+
const value = keyframeValue[prop];
|
|
15
|
+
if (typeof value === 'string' || typeof value === 'number') {
|
|
16
|
+
const applyValue = (0, __1.applyCssValue)(value, CSSProp);
|
|
17
|
+
keyframesRules += ` ${CSSProp}: ${applyValue};\n`;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
keyframesRules += ` }\n`;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
keyframesRules += `}\n`;
|
|
25
|
+
return keyframesRules;
|
|
26
|
+
};
|
|
27
|
+
function transpiler(object, base36Hash, core) {
|
|
28
|
+
let styleSheet = '';
|
|
29
|
+
const mediaQueries = [];
|
|
30
|
+
const classNameType = (property) => {
|
|
31
|
+
return core === '--global' ? property : `.${property}_${base36Hash}`;
|
|
32
|
+
};
|
|
33
|
+
const rules = (indent, rulesValue, property) => {
|
|
34
|
+
if (typeof property !== 'string')
|
|
35
|
+
return '';
|
|
36
|
+
const value = rulesValue[property];
|
|
37
|
+
const cssProp = (0, __1.camelToKebabCase)(property);
|
|
38
|
+
return `${indent}${cssProp}: ${value};\n`;
|
|
39
|
+
};
|
|
40
|
+
const stringConverter = (className, properties, indentLevel = 0) => {
|
|
41
|
+
const classSelector = {};
|
|
42
|
+
const indent = ''.repeat(indentLevel);
|
|
43
|
+
const innerIndent = ' '.repeat(indentLevel + 1);
|
|
44
|
+
let cssRule = '';
|
|
45
|
+
for (const property in properties) {
|
|
46
|
+
if (Object.prototype.hasOwnProperty.call(properties, property)) {
|
|
47
|
+
const value = properties[property];
|
|
48
|
+
if (typeof value === 'string' || typeof value === 'number') {
|
|
49
|
+
let CSSProp = (0, __1.camelToKebabCase)(property);
|
|
50
|
+
if (property.startsWith('ms')) {
|
|
51
|
+
CSSProp = `-${CSSProp}`;
|
|
52
|
+
}
|
|
53
|
+
const applyValue = (0, __1.applyCssValue)(value, CSSProp);
|
|
54
|
+
cssRule += ` ${CSSProp}: ${applyValue};\n`;
|
|
55
|
+
}
|
|
56
|
+
else if (!property.startsWith('@')) {
|
|
57
|
+
const kebabPseudoSelector = (0, __1.camelToKebabCase)(property.replace('&', ''));
|
|
58
|
+
const styles = stringConverter(className + kebabPseudoSelector, value, indentLevel);
|
|
59
|
+
Object.assign(classSelector, styles);
|
|
60
|
+
}
|
|
61
|
+
else if (property.startsWith('@media') || property.startsWith('@container')) {
|
|
62
|
+
const mediaRule = property;
|
|
63
|
+
let nestedRules = '';
|
|
64
|
+
let regularRules = '';
|
|
65
|
+
for (const mediaProp in value) {
|
|
66
|
+
if (Object.prototype.hasOwnProperty.call(value, mediaProp)) {
|
|
67
|
+
const mediaValue = value[mediaProp];
|
|
68
|
+
const isColon = mediaProp.startsWith(':');
|
|
69
|
+
const isAnd = mediaProp.startsWith('&');
|
|
70
|
+
if (isColon || isAnd) {
|
|
71
|
+
const kebabMediaProp = (0, __1.camelToKebabCase)(mediaProp.replace('&', ''));
|
|
72
|
+
let pseudoClassRule = '';
|
|
73
|
+
if (typeof mediaValue === 'object' && mediaValue !== null) {
|
|
74
|
+
for (const pseudoProp in mediaValue) {
|
|
75
|
+
if (Object.prototype.hasOwnProperty.call(mediaValue, pseudoProp)) {
|
|
76
|
+
const CSSProp = (0, __1.camelToKebabCase)(pseudoProp);
|
|
77
|
+
const applyValue = (0, __1.applyCssValue)(mediaValue[pseudoProp], CSSProp);
|
|
78
|
+
pseudoClassRule += rules(innerIndent + ' ', { [pseudoProp]: applyValue }, pseudoProp);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
nestedRules += `${innerIndent}${className}${kebabMediaProp} {\n${pseudoClassRule}${innerIndent}}\n`;
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
const CSSProp = (0, __1.camelToKebabCase)(mediaProp);
|
|
86
|
+
const applyValue = (0, __1.applyCssValue)(mediaValue, CSSProp);
|
|
87
|
+
regularRules += rules(innerIndent + ' ', { [mediaProp]: applyValue }, mediaProp);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (regularRules) {
|
|
92
|
+
mediaQueries.push({
|
|
93
|
+
media: mediaRule,
|
|
94
|
+
css: `${mediaRule} {\n${innerIndent}${className} {\n${regularRules} }\n${nestedRules}${indent}}${indent}\n`,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
mediaQueries.push({
|
|
99
|
+
media: mediaRule,
|
|
100
|
+
css: `${mediaRule} {\n${nestedRules}${indent}}\n`,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
classSelector[className] = cssRule;
|
|
107
|
+
return classSelector;
|
|
108
|
+
};
|
|
109
|
+
for (const property in object) {
|
|
110
|
+
if (property.startsWith('@keyframes')) {
|
|
111
|
+
const keyframesContent = object[property];
|
|
112
|
+
styleSheet += createKeyframes(property, keyframesContent);
|
|
113
|
+
}
|
|
114
|
+
const classSelectors = stringConverter(classNameType(property), object[property], 1);
|
|
115
|
+
for (const selector in classSelectors) {
|
|
116
|
+
if (!selector.startsWith('@keyframes') && classSelectors[selector]) {
|
|
117
|
+
styleSheet += selector + ' {\n' + classSelectors[selector] + '}\n';
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
mediaQueries.forEach(({ css }) => {
|
|
122
|
+
styleSheet += css;
|
|
123
|
+
});
|
|
124
|
+
return { styleSheet };
|
|
125
|
+
}
|
|
@@ -1 +1,122 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { camelToKebabCase, applyCssValue } from '..';
|
|
2
|
+
const createKeyframes = (property, content) => {
|
|
3
|
+
let keyframesRules = `${property} {\n`;
|
|
4
|
+
for (const key in content) {
|
|
5
|
+
if (Object.prototype.hasOwnProperty.call(content, key)) {
|
|
6
|
+
const keyframeValue = content[key];
|
|
7
|
+
keyframesRules += ` ${key} {\n`;
|
|
8
|
+
for (const prop in keyframeValue) {
|
|
9
|
+
if (Object.prototype.hasOwnProperty.call(keyframeValue, prop)) {
|
|
10
|
+
const CSSProp = camelToKebabCase(prop);
|
|
11
|
+
const value = keyframeValue[prop];
|
|
12
|
+
if (typeof value === 'string' || typeof value === 'number') {
|
|
13
|
+
const applyValue = applyCssValue(value, CSSProp);
|
|
14
|
+
keyframesRules += ` ${CSSProp}: ${applyValue};\n`;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
keyframesRules += ` }\n`;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
keyframesRules += `}\n`;
|
|
22
|
+
return keyframesRules;
|
|
23
|
+
};
|
|
24
|
+
export function transpiler(object, base36Hash, core) {
|
|
25
|
+
let styleSheet = '';
|
|
26
|
+
const mediaQueries = [];
|
|
27
|
+
const classNameType = (property) => {
|
|
28
|
+
return core === '--global' ? property : `.${property}_${base36Hash}`;
|
|
29
|
+
};
|
|
30
|
+
const rules = (indent, rulesValue, property) => {
|
|
31
|
+
if (typeof property !== 'string')
|
|
32
|
+
return '';
|
|
33
|
+
const value = rulesValue[property];
|
|
34
|
+
const cssProp = camelToKebabCase(property);
|
|
35
|
+
return `${indent}${cssProp}: ${value};\n`;
|
|
36
|
+
};
|
|
37
|
+
const stringConverter = (className, properties, indentLevel = 0) => {
|
|
38
|
+
const classSelector = {};
|
|
39
|
+
const indent = ''.repeat(indentLevel);
|
|
40
|
+
const innerIndent = ' '.repeat(indentLevel + 1);
|
|
41
|
+
let cssRule = '';
|
|
42
|
+
for (const property in properties) {
|
|
43
|
+
if (Object.prototype.hasOwnProperty.call(properties, property)) {
|
|
44
|
+
const value = properties[property];
|
|
45
|
+
if (typeof value === 'string' || typeof value === 'number') {
|
|
46
|
+
let CSSProp = camelToKebabCase(property);
|
|
47
|
+
if (property.startsWith('ms')) {
|
|
48
|
+
CSSProp = `-${CSSProp}`;
|
|
49
|
+
}
|
|
50
|
+
const applyValue = applyCssValue(value, CSSProp);
|
|
51
|
+
cssRule += ` ${CSSProp}: ${applyValue};\n`;
|
|
52
|
+
}
|
|
53
|
+
else if (!property.startsWith('@')) {
|
|
54
|
+
const kebabPseudoSelector = camelToKebabCase(property.replace('&', ''));
|
|
55
|
+
const styles = stringConverter(className + kebabPseudoSelector, value, indentLevel);
|
|
56
|
+
Object.assign(classSelector, styles);
|
|
57
|
+
}
|
|
58
|
+
else if (property.startsWith('@media') || property.startsWith('@container')) {
|
|
59
|
+
const mediaRule = property;
|
|
60
|
+
let nestedRules = '';
|
|
61
|
+
let regularRules = '';
|
|
62
|
+
for (const mediaProp in value) {
|
|
63
|
+
if (Object.prototype.hasOwnProperty.call(value, mediaProp)) {
|
|
64
|
+
const mediaValue = value[mediaProp];
|
|
65
|
+
const isColon = mediaProp.startsWith(':');
|
|
66
|
+
const isAnd = mediaProp.startsWith('&');
|
|
67
|
+
if (isColon || isAnd) {
|
|
68
|
+
const kebabMediaProp = camelToKebabCase(mediaProp.replace('&', ''));
|
|
69
|
+
let pseudoClassRule = '';
|
|
70
|
+
if (typeof mediaValue === 'object' && mediaValue !== null) {
|
|
71
|
+
for (const pseudoProp in mediaValue) {
|
|
72
|
+
if (Object.prototype.hasOwnProperty.call(mediaValue, pseudoProp)) {
|
|
73
|
+
const CSSProp = camelToKebabCase(pseudoProp);
|
|
74
|
+
const applyValue = applyCssValue(mediaValue[pseudoProp], CSSProp);
|
|
75
|
+
pseudoClassRule += rules(innerIndent + ' ', { [pseudoProp]: applyValue }, pseudoProp);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
nestedRules += `${innerIndent}${className}${kebabMediaProp} {\n${pseudoClassRule}${innerIndent}}\n`;
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
const CSSProp = camelToKebabCase(mediaProp);
|
|
83
|
+
const applyValue = applyCssValue(mediaValue, CSSProp);
|
|
84
|
+
regularRules += rules(innerIndent + ' ', { [mediaProp]: applyValue }, mediaProp);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (regularRules) {
|
|
89
|
+
mediaQueries.push({
|
|
90
|
+
media: mediaRule,
|
|
91
|
+
css: `${mediaRule} {\n${innerIndent}${className} {\n${regularRules} }\n${nestedRules}${indent}}${indent}\n`,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
mediaQueries.push({
|
|
96
|
+
media: mediaRule,
|
|
97
|
+
css: `${mediaRule} {\n${nestedRules}${indent}}\n`,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
classSelector[className] = cssRule;
|
|
104
|
+
return classSelector;
|
|
105
|
+
};
|
|
106
|
+
for (const property in object) {
|
|
107
|
+
if (property.startsWith('@keyframes')) {
|
|
108
|
+
const keyframesContent = object[property];
|
|
109
|
+
styleSheet += createKeyframes(property, keyframesContent);
|
|
110
|
+
}
|
|
111
|
+
const classSelectors = stringConverter(classNameType(property), object[property], 1);
|
|
112
|
+
for (const selector in classSelectors) {
|
|
113
|
+
if (!selector.startsWith('@keyframes') && classSelectors[selector]) {
|
|
114
|
+
styleSheet += selector + ' {\n' + classSelectors[selector] + '}\n';
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
mediaQueries.forEach(({ css }) => {
|
|
119
|
+
styleSheet += css;
|
|
120
|
+
});
|
|
121
|
+
return { styleSheet };
|
|
122
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zss-engine",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.7",
|
|
4
4
|
"description": "Zero-runtime Style Sheet Engine",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"zero-runtime",
|
|
@@ -15,33 +15,30 @@
|
|
|
15
15
|
"exports": {
|
|
16
16
|
"./package.json": "./package.json",
|
|
17
17
|
".": {
|
|
18
|
-
"types": "./
|
|
18
|
+
"types": "./types/index.d.ts",
|
|
19
19
|
"import": "./dist/index.mjs",
|
|
20
20
|
"default": "./dist/index.js"
|
|
21
21
|
}
|
|
22
22
|
},
|
|
23
23
|
"main": "dist/index.js",
|
|
24
24
|
"module": "dist/index.mjs",
|
|
25
|
-
"types": "
|
|
25
|
+
"types": "types/index.d.ts",
|
|
26
26
|
"scripts": {
|
|
27
|
-
"build": "pnpm
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"esm": "npx tsc --project tsconfig.esm.json",
|
|
31
|
-
"minify": "for file in $(find dist -name '*.js' -o -name '*.mjs'); do terser \"$file\" -c -m -o \"$file\"; done",
|
|
27
|
+
"build": "pnpm esm && pnpm cjs",
|
|
28
|
+
"cjs": "tsc --project tsconfig.cjs.json",
|
|
29
|
+
"esm": "tsc --project tsconfig.esm.json && node build.esm.js",
|
|
32
30
|
"test": "jest"
|
|
33
31
|
},
|
|
34
32
|
"dependencies": {
|
|
35
33
|
"csstype": "^3.1.3"
|
|
36
34
|
},
|
|
37
35
|
"devDependencies": {
|
|
38
|
-
"@swc/core": "^1.7.42",
|
|
39
|
-
"@swc/jest": "^0.2.37",
|
|
40
36
|
"@types/jest": "^29.5.14",
|
|
41
37
|
"@types/node": "^22.8.5",
|
|
38
|
+
"fast-glob": "^3.3.3",
|
|
42
39
|
"jest": "^29.7.0",
|
|
43
40
|
"jest-environment-jsdom": "^29.7.0",
|
|
44
|
-
"
|
|
41
|
+
"ts-jest": "^29.2.6",
|
|
45
42
|
"typescript": "^5.6.3"
|
|
46
43
|
}
|
|
47
44
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|