zss-engine 0.2.2 → 0.2.4
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 +1 -8
- package/dist/index.mjs +1 -0
- package/dist/types/common/css-properties.d.ts +1 -1
- package/dist/types/common/css-properties.js +1 -1
- package/dist/types/common/css-properties.mjs +1 -0
- package/dist/types/common/css-property.js +1 -1
- package/dist/types/common/css-property.mjs +1 -0
- package/dist/types/index.js +1 -5
- package/dist/types/index.mjs +1 -0
- package/dist/types/main/create.js +1 -1
- package/dist/types/main/create.mjs +1 -0
- package/dist/types/main/global.js +1 -1
- package/dist/types/main/global.mjs +1 -0
- package/dist/types/main/vars.js +1 -1
- package/dist/types/main/vars.mjs +1 -0
- package/dist/utils/build.js +1 -23
- package/dist/utils/build.mjs +1 -0
- package/dist/utils/hash.js +1 -31
- package/dist/utils/hash.mjs +1 -0
- package/dist/utils/helper.js +1 -16
- package/dist/utils/helper.mjs +1 -0
- package/dist/utils/inject-client-css.js +1 -47
- package/dist/utils/inject-client-css.mjs +1 -0
- package/dist/utils/inject-client-global-css.js +1 -15
- package/dist/utils/inject-client-global-css.mjs +1 -0
- package/dist/utils/inject-server-css.js +1 -7
- package/dist/utils/inject-server-css.mjs +1 -0
- package/dist/utils/transpiler.js +1 -122
- package/dist/utils/transpiler.mjs +1 -0
- package/package.json +26 -2
package/dist/index.js
CHANGED
|
@@ -1,8 +1 @@
|
|
|
1
|
-
|
|
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
|
+
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,r,t,n){void 0===n&&(n=t);var i=Object.getOwnPropertyDescriptor(r,t);i&&!("get"in i?!r.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return r[t]}}),Object.defineProperty(e,n,i)}:function(e,r,t,n){void 0===n&&(n=t),e[n]=r[t]}),__exportStar=this&&this.__exportStar||function(e,r){for(var t in e)"default"===t||Object.prototype.hasOwnProperty.call(r,t)||__createBinding(r,e,t)};Object.defineProperty(exports,"__esModule",{value:!0}),exports.transpiler=exports.build=exports.getServerCSS=exports.injectServerCSS=exports.injectClientGlobalCSS=exports.injectClientCSS=exports.genBase36Hash=void 0,__exportStar(require("./types"),exports),__exportStar(require("./utils/helper"),exports);var hash_1=require("./utils/hash");Object.defineProperty(exports,"genBase36Hash",{enumerable:!0,get:function(){return hash_1.genBase36Hash}});var inject_client_css_1=require("./utils/inject-client-css");Object.defineProperty(exports,"injectClientCSS",{enumerable:!0,get:function(){return inject_client_css_1.injectClientCSS}});var inject_client_global_css_1=require("./utils/inject-client-global-css");Object.defineProperty(exports,"injectClientGlobalCSS",{enumerable:!0,get:function(){return inject_client_global_css_1.injectClientGlobalCSS}});var inject_server_css_1=require("./utils/inject-server-css");Object.defineProperty(exports,"injectServerCSS",{enumerable:!0,get:function(){return inject_server_css_1.injectServerCSS}}),Object.defineProperty(exports,"getServerCSS",{enumerable:!0,get:function(){return inject_server_css_1.getServerCSS}});var build_1=require("./utils/build");Object.defineProperty(exports,"build",{enumerable:!0,get:function(){return build_1.build}});var transpiler_1=require("./utils/transpiler");Object.defineProperty(exports,"transpiler",{enumerable:!0,get:function(){return transpiler_1.transpiler}});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export*from"./types";export*from"./utils/helper";export{genBase36Hash}from"./utils/hash";export{injectClientCSS}from"./utils/inject-client-css";export{injectClientGlobalCSS}from"./utils/inject-client-global-css";export{injectServerCSS,getServerCSS}from"./utils/inject-server-css";export{build}from"./utils/build";export{transpiler}from"./utils/transpiler";
|
|
@@ -40,7 +40,7 @@ type ColonType = {
|
|
|
40
40
|
};
|
|
41
41
|
export type MediaQuery = `@media ${string}`;
|
|
42
42
|
type MediaQueryType = {
|
|
43
|
-
[K in MediaQuery]: CommonProperties | ColonType;
|
|
43
|
+
[K in MediaQuery]: CommonProperties | ColonType | AndStringType;
|
|
44
44
|
};
|
|
45
45
|
export type CustomProperties = CommonProperties | ColonType | AndStringType | MediaQueryType;
|
|
46
46
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{};
|
package/dist/types/index.js
CHANGED
|
@@ -1,5 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export * from './common/css-property';
|
|
3
|
-
export * from './main/create';
|
|
4
|
-
export * from './main/global';
|
|
5
|
-
export * from './main/vars';
|
|
1
|
+
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,r,t,o){void 0===o&&(o=t);var i=Object.getOwnPropertyDescriptor(r,t);i&&!("get"in i?!r.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return r[t]}}),Object.defineProperty(e,o,i)}:function(e,r,t,o){void 0===o&&(o=t),e[o]=r[t]}),__exportStar=this&&this.__exportStar||function(e,r){for(var t in e)"default"===t||Object.prototype.hasOwnProperty.call(r,t)||__createBinding(r,e,t)};Object.defineProperty(exports,"__esModule",{value:!0}),__exportStar(require("./common/css-properties"),exports),__exportStar(require("./common/css-property"),exports),__exportStar(require("./main/create"),exports),__exportStar(require("./main/global"),exports),__exportStar(require("./main/vars"),exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export*from"./common/css-properties";export*from"./common/css-property";export*from"./main/create";export*from"./main/global";export*from"./main/vars";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{};
|
package/dist/types/main/vars.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{};
|
package/dist/utils/build.js
CHANGED
|
@@ -1,23 +1 @@
|
|
|
1
|
-
|
|
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
|
-
};
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.build=void 0;const helper_1=require("./helper"),build=async(e,r,l)=>{if(!helper_1.isServer)return;const t=require("fs"),{styleText:i}=require("util"),n=i("underline","--global"===l?"✅Generated global CSS\n\n":"✅Generated create CSS\n\n");try{if(t.existsSync(r)){t.readFileSync(r,"utf-8").includes(e)||(t.appendFileSync(r,e,"utf-8"),process.argv.includes("--log")&&console.log(n+e))}return}catch(e){console.error("Error writing to file:",e)}};exports.build=build;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{isServer}from"./helper";export const build=async(e,r,n)=>{if(!isServer)return;const t=require("fs"),{styleText:i}=require("util"),l=i("underline","--global"===n?"✅Generated global CSS\n\n":"✅Generated create CSS\n\n");try{if(t.existsSync(r)){t.readFileSync(r,"utf-8").includes(e)||(t.appendFileSync(r,e,"utf-8"),process.argv.includes("--log")&&console.log(l+e))}return}catch(e){console.error("Error writing to file:",e)}};
|
package/dist/utils/hash.js
CHANGED
|
@@ -1,31 +1 @@
|
|
|
1
|
-
const chars =
|
|
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
|
-
}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.genBase36Hash=genBase36Hash;const chars="abcdefghijklmnopqrstuvwxyz0123456789";function simpleHash(e){let t=0;for(let n=0;n<e.length;n++){t=(t<<5)-t+e.charCodeAt(n)}return Math.abs(t)}function encodeBase36(e){let t="";do{t=chars[e%36]+t,e=Math.floor(e/36)}while(e>0);return t}function getStartingChar(e){const t="abcdefghijklmnopqrstuvwxyz";return t[e%26]}function genBase36Hash(e,t){const n=simpleHash(JSON.stringify(e));let s=encodeBase36(n);const r=getStartingChar(n);for(;s.length<t-1;)s=chars[n%chars.length]+s;return r+s.slice(0,t-1)}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const chars="abcdefghijklmnopqrstuvwxyz0123456789";function simpleHash(t){let e=0;for(let n=0;n<t.length;n++){e=(e<<5)-e+t.charCodeAt(n)}return Math.abs(e)}function encodeBase36(t){let e="";do{e=chars[t%36]+e,t=Math.floor(t/36)}while(t>0);return e}function getStartingChar(t){const e="abcdefghijklmnopqrstuvwxyz";return e[t%26]}export function genBase36Hash(t,e){const n=simpleHash(JSON.stringify(t));let r=encodeBase36(n);const s=getStartingChar(n);for(;r.length<e-1;)r=chars[n%36]+r;return s+r.slice(0,e-1)}
|
package/dist/utils/helper.js
CHANGED
|
@@ -1,16 +1 @@
|
|
|
1
|
-
const isWindowDefined
|
|
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
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.camelToKebabCase=exports.applyCssValue=exports.isDevServer=exports.isDevAndTest=exports.isDevelopment=exports.isServer=void 0;const isWindowDefined="undefined"!=typeof window,isDocumentDefined="undefined"!=typeof document;exports.isServer=!isWindowDefined||!isDocumentDefined,exports.isDevelopment="development"===process.env.NODE_ENV,exports.isDevAndTest="development"===process.env.NODE_ENV||"test"===process.env.NODE_ENV,exports.isDevServer=exports.isDevelopment&&exports.isServer;const exception=["line-height","font-weight","opacity","scale","z-index","column-count","order","orphans","widows"],applyCssValue=(e,s)=>"number"==typeof e?exception.includes(s)?e.toString():e+"px":e;exports.applyCssValue=applyCssValue;const camelToKebabCase=e=>e.replace(/([A-Z])/g,"-$1").toLowerCase();exports.camelToKebabCase=camelToKebabCase;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const isWindowDefined="undefined"!=typeof window,isDocumentDefined="undefined"!=typeof document;export const isServer=!isWindowDefined||!isDocumentDefined;export const isDevelopment="development"===process.env.NODE_ENV;export const isDevAndTest="development"===process.env.NODE_ENV||"test"===process.env.NODE_ENV;export const isDevServer=isDevelopment&&isServer;const exception=["line-height","font-weight","opacity","scale","z-index","column-count","order","orphans","widows"];export const applyCssValue=(e,o)=>"number"==typeof e?exception.includes(o)?e.toString():e+"px":e;export const camelToKebabCase=e=>e.replace(/([A-Z])/g,"-$1").toLowerCase();
|
|
@@ -1,47 +1 @@
|
|
|
1
|
-
|
|
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
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.createStyleElement=createStyleElement,exports.injectClientCSS=injectClientCSS;const __1=require(".."),styleSheets={},hashCache={};function createStyleElement(e){if(document.getElementById(e))return null;const t=document.createElement("style");return t.setAttribute("id",e),t.setAttribute("type","text/css"),styleSheets[e]=t,document.head.appendChild(t),styleSheets[e]}function injectClientCSS(e,t){if(__1.isServer)return;requestAnimationFrame((()=>{styleCleanUp()})),hashCache[e]=e;const n=createStyleElement(e);null!=n&&(n.textContent=t)}function styleCleanUp(){requestAnimationFrame((()=>{for(const e in hashCache){0===document.querySelectorAll(`[class*="${e}"]`).length&&removeStyleElement(hashCache[e])}}))}function removeStyleElement(e){if(styleSheets[e]){delete styleSheets[e],hashCache.hasOwnProperty.call(hashCache,e)&&delete hashCache[e];const t=document.getElementById(e);t&&document.head.removeChild(t)}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{isServer}from"..";const styleSheets={},hashCache={};export function createStyleElement(e){if(document.getElementById(e))return null;const t=document.createElement("style");return t.setAttribute("id",e),t.setAttribute("type","text/css"),styleSheets[e]=t,document.head.appendChild(t),styleSheets[e]}export function injectClientCSS(e,t){if(isServer)return;requestAnimationFrame((()=>{styleCleanUp()})),hashCache[e]=e;const n=createStyleElement(e);null!=n&&(n.textContent=t)}function styleCleanUp(){requestAnimationFrame((()=>{for(const e in hashCache){0===document.querySelectorAll(`[class*="${e}"]`).length&&removeStyleElement(hashCache[e])}}))}function removeStyleElement(e){if(styleSheets[e]){delete styleSheets[e],hashCache.hasOwnProperty.call(hashCache,e)&&delete hashCache[e];const t=document.getElementById(e);t&&document.head.removeChild(t)}}
|
|
@@ -1,15 +1 @@
|
|
|
1
|
-
|
|
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
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.injectClientGlobalCSS=injectClientGlobalCSS;const __1=require("..");function injectClientGlobalCSS(e,t){if(__1.isServer)return;const n=document.querySelector(`[data-scope="${t}"]`);if(n instanceof HTMLStyleElement)return void(n.textContent+=e);const o=document.createElement("style");o.setAttribute("data-scope",t),o.setAttribute("type","text/css"),o.textContent=e,document.head.appendChild(o)}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{isServer}from"..";export function injectClientGlobalCSS(t,e){if(isServer)return;const n=document.querySelector(`[data-scope="${e}"]`);if(n instanceof HTMLStyleElement)return void(n.textContent+=t);const o=document.createElement("style");o.setAttribute("data-scope",e),o.setAttribute("type","text/css"),o.textContent=t,document.head.appendChild(o)}
|
|
@@ -1,7 +1 @@
|
|
|
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
|
-
}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.injectServerCSS=injectServerCSS,exports.getServerCSS=getServerCSS;const styleSheets={};function injectServerCSS(e,t){styleSheets[e]=t}function getServerCSS(){return Object.values(styleSheets).join("\n")}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const styleSheets={};export function injectServerCSS(e,t){styleSheets[e]=t}export function getServerCSS(){return Object.values(styleSheets).join("\n")}
|
package/dist/utils/transpiler.js
CHANGED
|
@@ -1,122 +1 @@
|
|
|
1
|
-
|
|
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
|
-
}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.transpiler=transpiler;const __1=require(".."),createKeyframes=(e,t)=>{let s=`${e} {\n`;for(const e in t)if(Object.prototype.hasOwnProperty.call(t,e)){const n=t[e];s+=` ${e} {\n`;for(const e in n)if(Object.prototype.hasOwnProperty.call(n,e)){const t=(0,__1.camelToKebabCase)(e),r=n[e];if("string"==typeof r||"number"==typeof r){s+=` ${t}: ${(0,__1.applyCssValue)(r,t)};\n`}}s+=" }\n"}return s+="}\n",s};function transpiler(e,t,s){let n="";const r=[],a=e=>"--global"===s?e:`.${e}_${t}`,o=(e,t,s)=>{if("string"!=typeof s)return"";const n=t[s];return`${e}${(0,__1.camelToKebabCase)(s)}: ${n};\n`},c=(e,t,s=0)=>{const n={},a="".repeat(s),l=" ".repeat(s+1);let i="";for(const p in t)if(Object.prototype.hasOwnProperty.call(t,p)){const f=t[p];if("string"==typeof f||"number"==typeof f){let e=(0,__1.camelToKebabCase)(p);p.startsWith("ms")&&(e=`-${e}`);i+=` ${e}: ${(0,__1.applyCssValue)(f,e)};\n`}else if(p.startsWith("@")){if(p.startsWith("@media")||p.startsWith("@container")){const t=p;let s="",n="";for(const t in f)if(Object.prototype.hasOwnProperty.call(f,t)){const r=f[t],a=t.startsWith(":"),c=t.startsWith("&");if(a||c){const n=(0,__1.camelToKebabCase)(t.replace("&",""));let a="";if("object"==typeof r&&null!==r)for(const e in r)if(Object.prototype.hasOwnProperty.call(r,e)){const t=(0,__1.camelToKebabCase)(e),s=(0,__1.applyCssValue)(r[e],t);a+=o(l+" ",{[e]:s},e)}s+=`${l}${e}${n} {\n${a}${l}}\n`}else{const e=(0,__1.camelToKebabCase)(t),s=(0,__1.applyCssValue)(r,e);n+=o(l+" ",{[t]:s},t)}}n?r.push({media:t,css:`${t} {\n${l}${e} {\n${n} }\n${s}${a}}${a}\n`}):r.push({media:t,css:`${t} {\n${s}${a}}\n`})}}else{const t=(0,__1.camelToKebabCase)(p.replace("&","")),r=c(e+t,f,s);Object.assign(n,r)}}return n[e]=i,n};for(const t in e){if(t.startsWith("@keyframes")){const s=e[t];n+=createKeyframes(t,s)}const s=c(a(t),e[t],1);for(const e in s)!e.startsWith("@keyframes")&&s[e]&&(n+=e+" {\n"+s[e]+"}\n")}return r.forEach((({css:e})=>{n+=e})),{styleSheet:n}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{camelToKebabCase,applyCssValue}from"..";const createKeyframes=(e,t)=>{let s=`${e} {\n`;for(const e in t)if(Object.prototype.hasOwnProperty.call(t,e)){const a=t[e];s+=` ${e} {\n`;for(const e in a)if(Object.prototype.hasOwnProperty.call(a,e)){const t=camelToKebabCase(e),n=a[e];if("string"==typeof n||"number"==typeof n){s+=` ${t}: ${applyCssValue(n,t)};\n`}}s+=" }\n"}return s+="}\n",s};export function transpiler(e,t,s){let a="";const n=[],o=e=>"--global"===s?e:`.${e}_${t}`,r=(e,t,s)=>{if("string"!=typeof s)return"";const a=t[s];return`${e}${camelToKebabCase(s)}: ${a};\n`},c=(e,t,s=0)=>{const a={},o="".repeat(s),l=" ".repeat(s+1);let p="";for(const i in t)if(Object.prototype.hasOwnProperty.call(t,i)){const f=t[i];if("string"==typeof f||"number"==typeof f){let e=camelToKebabCase(i);i.startsWith("ms")&&(e=`-${e}`);p+=` ${e}: ${applyCssValue(f,e)};\n`}else if(i.startsWith("@")){if(i.startsWith("@media")||i.startsWith("@container")){const t=i;let s="",a="";for(const t in f)if(Object.prototype.hasOwnProperty.call(f,t)){const n=f[t],o=t.startsWith(":"),c=t.startsWith("&");if(o||c){const a=camelToKebabCase(t.replace("&",""));let o="";if("object"==typeof n&&null!==n)for(const e in n)if(Object.prototype.hasOwnProperty.call(n,e)){const t=camelToKebabCase(e),s=applyCssValue(n[e],t);o+=r(l+" ",{[e]:s},e)}s+=`${l}${e}${a} {\n${o}${l}}\n`}else{const e=camelToKebabCase(t),s=applyCssValue(n,e);a+=r(l+" ",{[t]:s},t)}}a?n.push({media:t,css:`${t} {\n${l}${e} {\n${a} }\n${s}${o}}${o}\n`}):n.push({media:t,css:`${t} {\n${s}${o}}\n`})}}else{const t=camelToKebabCase(i.replace("&","")),n=c(e+t,f,s);Object.assign(a,n)}}return a[e]=p,a};for(const t in e){if(t.startsWith("@keyframes")){const s=e[t];a+=createKeyframes(t,s)}const s=c(o(t),e[t],1);for(const e in s)!e.startsWith("@keyframes")&&s[e]&&(a+=e+" {\n"+s[e]+"}\n")}return n.forEach((({css:e})=>{a+=e})),{styleSheet:a}}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zss-engine",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"description": "Zero-runtime Style Sheet Engine",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"zero-runtime",
|
|
@@ -11,13 +11,37 @@
|
|
|
11
11
|
"author": "Refirst",
|
|
12
12
|
"repository": "github:zss-in-js/zss-engine",
|
|
13
13
|
"license": "MIT",
|
|
14
|
+
"sideEffects": false,
|
|
15
|
+
"exports": {
|
|
16
|
+
"./package.json": "./package.json",
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"import": "./dist/index.mjs",
|
|
20
|
+
"default": "./dist/index.js"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
14
23
|
"main": "dist/index.js",
|
|
15
|
-
"
|
|
24
|
+
"module": "dist/index.mjs",
|
|
25
|
+
"types": "dist/index.d.ts",
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "pnpm build:mjs && pnpm cjs && pnpm minify",
|
|
28
|
+
"build:mjs": "pnpm esm && for file in $(find dist -name '*.js'); do mv \"$file\" \"${file%.*}.mjs\"; done",
|
|
29
|
+
"cjs": "npx tsc --project tsconfig.cjs.json",
|
|
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",
|
|
32
|
+
"test": "jest"
|
|
33
|
+
},
|
|
16
34
|
"dependencies": {
|
|
17
35
|
"csstype": "^3.1.3"
|
|
18
36
|
},
|
|
19
37
|
"devDependencies": {
|
|
38
|
+
"@swc/core": "^1.7.42",
|
|
39
|
+
"@swc/jest": "^0.2.37",
|
|
40
|
+
"@types/jest": "^29.5.14",
|
|
20
41
|
"@types/node": "^22.8.5",
|
|
42
|
+
"jest": "^29.7.0",
|
|
43
|
+
"jest-environment-jsdom": "^29.7.0",
|
|
44
|
+
"terser": "^5.39.0",
|
|
21
45
|
"typescript": "^5.6.3"
|
|
22
46
|
}
|
|
23
47
|
}
|