zss-engine 0.2.36 → 0.2.37
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.d.ts +111 -0
- package/dist/index.js +258 -0
- package/dist/index.mjs +247 -0
- package/package.json +9 -12
- package/dist/cjs/index.js +0 -22
- package/dist/cjs/types/common/css-properties.js +0 -2
- package/dist/cjs/types/common/css-property.js +0 -2
- package/dist/cjs/types/main/create.js +0 -2
- package/dist/cjs/types/main/global.js +0 -2
- package/dist/cjs/types/main/vars.js +0 -2
- package/dist/cjs/utils/build.js +0 -27
- package/dist/cjs/utils/hash.js +0 -34
- package/dist/cjs/utils/helper.js +0 -27
- package/dist/cjs/utils/inject-client-css.js +0 -51
- package/dist/cjs/utils/inject-client-global-css.js +0 -18
- package/dist/cjs/utils/inject-server-css.js +0 -11
- package/dist/cjs/utils/transpiler.js +0 -125
- package/dist/esm/index.js +0 -8
- package/dist/esm/types/common/css-properties.js +0 -1
- package/dist/esm/types/common/css-property.js +0 -1
- package/dist/esm/types/main/create.js +0 -1
- package/dist/esm/types/main/global.js +0 -1
- package/dist/esm/types/main/vars.js +0 -1
- package/dist/esm/utils/build.js +0 -23
- package/dist/esm/utils/hash.js +0 -31
- package/dist/esm/utils/helper.js +0 -22
- package/dist/esm/utils/inject-client-css.js +0 -47
- package/dist/esm/utils/inject-client-global-css.js +0 -15
- package/dist/esm/utils/inject-server-css.js +0 -7
- package/dist/esm/utils/transpiler.js +0 -122
- package/types/index.d.ts +0 -12
- package/types/types/common/css-properties.d.ts +0 -46
- package/types/types/common/css-property.d.ts +0 -5
- package/types/types/main/create.d.ts +0 -10
- package/types/types/main/global.d.ts +0 -37
- package/types/types/main/vars.d.ts +0 -8
- package/types/utils/build.d.ts +0 -1
- package/types/utils/hash.d.ts +0 -2
- package/types/utils/helper.d.ts +0 -5
- package/types/utils/inject-client-css.d.ts +0 -2
- package/types/utils/inject-client-global-css.d.ts +0 -1
- package/types/utils/inject-server-css.d.ts +0 -2
- package/types/utils/transpiler.d.ts +0 -4
package/dist/cjs/utils/build.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
'use server';
|
|
2
|
-
"use strict";
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.build = void 0;
|
|
5
|
-
const helper_js_1 = require("./helper.js");
|
|
6
|
-
const build = async (styleSheet, filePath, global) => {
|
|
7
|
-
if (!helper_js_1.isServer)
|
|
8
|
-
return;
|
|
9
|
-
const fs = await import('fs');
|
|
10
|
-
const { styleText } = await import('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('--view'))
|
|
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/cjs/utils/hash.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
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/cjs/utils/helper.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.camelToKebabCase = exports.applyCssValue = 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
|
-
const exception = ['line-height', 'font-weight', 'opacity', 'scale', 'z-index', 'column-count', 'order', 'orphans', 'widows'];
|
|
10
|
-
const applyCssValue = (value, cssProp) => {
|
|
11
|
-
if (typeof value === 'number') {
|
|
12
|
-
return exception.includes(cssProp) ? value.toString() : value + 'px';
|
|
13
|
-
}
|
|
14
|
-
return value;
|
|
15
|
-
};
|
|
16
|
-
exports.applyCssValue = applyCssValue;
|
|
17
|
-
const camelToKebabCase = (property) => {
|
|
18
|
-
if (/^(ms|Moz|Webkit)/.test(property)) {
|
|
19
|
-
property = '-' + property;
|
|
20
|
-
}
|
|
21
|
-
return (property
|
|
22
|
-
.replace(/([A-Z]+)([0-9]+)/g, '$1$2')
|
|
23
|
-
.replace(/([a-z0-9])([A-Z])/g, '$1-$2')
|
|
24
|
-
.replace(/([A-Z]+)([A-Z][a-z])/g, '$1-$2')
|
|
25
|
-
.toLowerCase());
|
|
26
|
-
};
|
|
27
|
-
exports.camelToKebabCase = camelToKebabCase;
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createStyleElement = createStyleElement;
|
|
4
|
-
exports.injectClientCSS = injectClientCSS;
|
|
5
|
-
const index_js_1 = require("../index.js");
|
|
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 (index_js_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,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.injectClientGlobalCSS = injectClientGlobalCSS;
|
|
4
|
-
const index_js_1 = require("../index.js");
|
|
5
|
-
function injectClientGlobalCSS(sheet) {
|
|
6
|
-
if (index_js_1.isServer)
|
|
7
|
-
return;
|
|
8
|
-
const existingStyleElement = document.querySelector(`[data-scope="global"]`);
|
|
9
|
-
if (existingStyleElement instanceof HTMLStyleElement) {
|
|
10
|
-
existingStyleElement.textContent += sheet;
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
const styleElement = document.createElement('style');
|
|
14
|
-
styleElement.setAttribute('data-scope', 'global');
|
|
15
|
-
styleElement.setAttribute('type', 'text/css');
|
|
16
|
-
styleElement.textContent = sheet;
|
|
17
|
-
document.head.appendChild(styleElement);
|
|
18
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
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,125 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.transpiler = transpiler;
|
|
4
|
-
const helper_js_1 = require("./helper.js");
|
|
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, helper_js_1.camelToKebabCase)(prop);
|
|
14
|
-
const value = keyframeValue[prop];
|
|
15
|
-
if (typeof value === 'string' || typeof value === 'number') {
|
|
16
|
-
const applyValue = (0, helper_js_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, helper_js_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, helper_js_1.camelToKebabCase)(property);
|
|
50
|
-
if (property.startsWith('ms')) {
|
|
51
|
-
CSSProp = `-${CSSProp}`;
|
|
52
|
-
}
|
|
53
|
-
const applyValue = (0, helper_js_1.applyCssValue)(value, CSSProp);
|
|
54
|
-
cssRule += ` ${CSSProp}: ${applyValue};\n`;
|
|
55
|
-
}
|
|
56
|
-
else if (!property.startsWith('@')) {
|
|
57
|
-
const kebabPseudoSelector = (0, helper_js_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, helper_js_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, helper_js_1.camelToKebabCase)(pseudoProp);
|
|
77
|
-
const applyValue = (0, helper_js_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, helper_js_1.camelToKebabCase)(mediaProp);
|
|
86
|
-
const applyValue = (0, helper_js_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
|
-
}
|
package/dist/esm/index.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export { isServer, isDevelopment, isDevAndTest } from './utils/helper.js';
|
|
2
|
-
export { genBase36Hash } from './utils/hash.js';
|
|
3
|
-
export { transpiler } from './utils/transpiler.js';
|
|
4
|
-
export { build } from './utils/build.js';
|
|
5
|
-
export { camelToKebabCase } from './utils/helper.js';
|
|
6
|
-
export { injectClientCSS } from './utils/inject-client-css.js';
|
|
7
|
-
export { injectClientGlobalCSS } from './utils/inject-client-global-css.js';
|
|
8
|
-
export { injectServerCSS, getServerCSS } from './utils/inject-server-css.js';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/esm/utils/build.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
'use server';
|
|
2
|
-
import { isServer } from './helper.js';
|
|
3
|
-
export const build = async (styleSheet, filePath, global) => {
|
|
4
|
-
if (!isServer)
|
|
5
|
-
return;
|
|
6
|
-
const fs = await import('fs');
|
|
7
|
-
const { styleText } = await import('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('--view'))
|
|
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/esm/utils/hash.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
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/esm/utils/helper.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
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
|
-
const exception = ['line-height', 'font-weight', 'opacity', 'scale', 'z-index', 'column-count', 'order', 'orphans', 'widows'];
|
|
7
|
-
export const applyCssValue = (value, cssProp) => {
|
|
8
|
-
if (typeof value === 'number') {
|
|
9
|
-
return exception.includes(cssProp) ? value.toString() : value + 'px';
|
|
10
|
-
}
|
|
11
|
-
return value;
|
|
12
|
-
};
|
|
13
|
-
export const camelToKebabCase = (property) => {
|
|
14
|
-
if (/^(ms|Moz|Webkit)/.test(property)) {
|
|
15
|
-
property = '-' + property;
|
|
16
|
-
}
|
|
17
|
-
return (property
|
|
18
|
-
.replace(/([A-Z]+)([0-9]+)/g, '$1$2')
|
|
19
|
-
.replace(/([a-z0-9])([A-Z])/g, '$1-$2')
|
|
20
|
-
.replace(/([A-Z]+)([A-Z][a-z])/g, '$1-$2')
|
|
21
|
-
.toLowerCase());
|
|
22
|
-
};
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { isServer } from '../index.js';
|
|
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,15 +0,0 @@
|
|
|
1
|
-
import { isServer } from '../index.js';
|
|
2
|
-
export function injectClientGlobalCSS(sheet) {
|
|
3
|
-
if (isServer)
|
|
4
|
-
return;
|
|
5
|
-
const existingStyleElement = document.querySelector(`[data-scope="global"]`);
|
|
6
|
-
if (existingStyleElement instanceof HTMLStyleElement) {
|
|
7
|
-
existingStyleElement.textContent += sheet;
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
10
|
-
const styleElement = document.createElement('style');
|
|
11
|
-
styleElement.setAttribute('data-scope', 'global');
|
|
12
|
-
styleElement.setAttribute('type', 'text/css');
|
|
13
|
-
styleElement.textContent = sheet;
|
|
14
|
-
document.head.appendChild(styleElement);
|
|
15
|
-
}
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import { camelToKebabCase, applyCssValue } from './helper.js';
|
|
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/types/index.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export type { CSSProperties } from './types/common/css-properties';
|
|
2
|
-
export type { CreateStyleType, ReturnType, CreateStyle } from './types/main/create';
|
|
3
|
-
export type { CSSHTML, CreateKeyframes } from './types/main/global';
|
|
4
|
-
export type { CreateVars, CreateTheme } from './types/main/vars';
|
|
5
|
-
export { isServer, isDevelopment, isDevAndTest } from './utils/helper.js';
|
|
6
|
-
export { genBase36Hash } from './utils/hash.js';
|
|
7
|
-
export { transpiler } from './utils/transpiler.js';
|
|
8
|
-
export { build } from './utils/build.js';
|
|
9
|
-
export { camelToKebabCase } from './utils/helper.js';
|
|
10
|
-
export { injectClientCSS } from './utils/inject-client-css.js';
|
|
11
|
-
export { injectClientGlobalCSS } from './utils/inject-client-global-css.js';
|
|
12
|
-
export { injectServerCSS, getServerCSS } from './utils/inject-server-css.js';
|