zss-engine 0.2.37 → 0.2.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist/cjs/index.js +22 -0
  2. package/dist/cjs/types/common/css-properties.js +2 -0
  3. package/dist/cjs/types/common/css-property.js +2 -0
  4. package/dist/cjs/types/main/create.js +2 -0
  5. package/dist/cjs/types/main/global.js +2 -0
  6. package/dist/cjs/types/main/vars.js +2 -0
  7. package/dist/cjs/utils/build.js +27 -0
  8. package/dist/cjs/utils/hash.js +34 -0
  9. package/dist/cjs/utils/helper.js +27 -0
  10. package/dist/cjs/utils/inject-client-css.js +51 -0
  11. package/dist/cjs/utils/inject-client-global-css.js +18 -0
  12. package/dist/cjs/utils/inject-server-css.js +11 -0
  13. package/dist/cjs/utils/transpiler.js +125 -0
  14. package/dist/esm/index.js +8 -0
  15. package/dist/esm/types/common/css-properties.js +1 -0
  16. package/dist/esm/types/common/css-property.js +1 -0
  17. package/dist/esm/types/main/create.js +1 -0
  18. package/dist/esm/types/main/global.js +1 -0
  19. package/dist/esm/types/main/vars.js +1 -0
  20. package/dist/esm/utils/build.js +23 -0
  21. package/dist/esm/utils/hash.js +31 -0
  22. package/dist/esm/utils/helper.js +22 -0
  23. package/dist/esm/utils/inject-client-css.js +47 -0
  24. package/dist/esm/utils/inject-client-global-css.js +15 -0
  25. package/dist/esm/utils/inject-server-css.js +7 -0
  26. package/dist/esm/utils/transpiler.js +122 -0
  27. package/package.json +12 -9
  28. package/types/index.d.ts +12 -0
  29. package/types/types/common/css-properties.d.ts +46 -0
  30. package/types/types/common/css-property.d.ts +5 -0
  31. package/types/types/main/create.d.ts +10 -0
  32. package/types/types/main/global.d.ts +37 -0
  33. package/types/types/main/vars.d.ts +8 -0
  34. package/types/utils/build.d.ts +1 -0
  35. package/types/utils/hash.d.ts +2 -0
  36. package/types/utils/helper.d.ts +5 -0
  37. package/types/utils/inject-client-css.d.ts +2 -0
  38. package/types/utils/inject-client-global-css.d.ts +1 -0
  39. package/types/utils/inject-server-css.d.ts +2 -0
  40. package/types/utils/transpiler.d.ts +4 -0
  41. package/dist/index.d.ts +0 -111
  42. package/dist/index.js +0 -258
  43. package/dist/index.mjs +0 -247
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zss-engine",
3
- "version": "0.2.37",
3
+ "version": "0.2.39",
4
4
  "description": "Zero-runtime StyleSheet Engine",
5
5
  "keywords": [
6
6
  "zero-runtime",
@@ -15,19 +15,22 @@
15
15
  "exports": {
16
16
  "./package.json": "./package.json",
17
17
  ".": {
18
- "types": "./dist/index.d.ts",
19
- "import": "./dist/index.mjs",
20
- "default": "./dist/index.js"
18
+ "types": "./types/index.d.ts",
19
+ "import": "./dist/esm/index.js",
20
+ "default": "./dist/cjs/index.js"
21
21
  }
22
22
  },
23
- "main": "dist/index.js",
24
- "module": "dist/index.mjs",
23
+ "main": "dist/cjs/index.js",
24
+ "module": "dist/esm/index.js",
25
25
  "types": "types/index.d.ts",
26
26
  "files": [
27
- "dist/"
27
+ "dist/",
28
+ "types/"
28
29
  ],
29
30
  "scripts": {
30
- "build": "tsdown",
31
+ "build": "rimraf dist types && pnpm esm && pnpm cjs",
32
+ "cjs": "tsc --project tsconfig.cjs.json",
33
+ "esm": "tsc --project tsconfig.esm.json",
31
34
  "test": "jest"
32
35
  },
33
36
  "dependencies": {
@@ -38,8 +41,8 @@
38
41
  "@types/node": "^22.13.10",
39
42
  "jest": "^29.7.0",
40
43
  "jest-environment-jsdom": "^29.7.0",
44
+ "rimraf": "^6.0.1",
41
45
  "ts-jest": "^29.2.6",
42
- "tsdown": "^0.11.12",
43
46
  "typescript": "^5.8.2"
44
47
  }
45
48
  }
@@ -0,0 +1,12 @@
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';
@@ -0,0 +1,46 @@
1
+ import type { CSSVariableValue, CSSVariableProperty } from '../main/vars';
2
+ import type { Properties, Property } from 'csstype';
3
+ type ColorValue = Exclude<Property.Color, '-moz-initial'> | (string & {});
4
+ type CSSColorProperty = Exclude<ColorValue, SystemColorKeyword>;
5
+ type SystemColorKeyword = 'ActiveBorder' | 'ActiveCaption' | 'AppWorkspace' | 'Background' | 'ButtonFace' | 'ButtonHighlight' | 'ButtonShadow' | 'ButtonText' | 'CaptionText' | 'GrayText' | 'Highlight' | 'HighlightText' | 'InactiveBorder' | 'InactiveCaption' | 'InactiveCaptionText' | 'InfoBackground' | 'InfoText' | 'Menu' | 'MenuText' | 'Scrollbar' | 'ThreeDDarkShadow' | 'ThreeDFace' | 'ThreeDHighlight' | 'ThreeDLightShadow' | 'ThreeDShadow' | 'Window' | 'WindowFrame' | 'WindowText';
6
+ type ExcludeMozInitial<T> = Exclude<T, '-moz-initial'>;
7
+ type CSSTypeProperties = Properties<number | (string & {})>;
8
+ type CustomProperties = {
9
+ [K in keyof CSSTypeProperties]: ExcludeMozInitial<CSSTypeProperties[K]>;
10
+ };
11
+ type BaseCSSProperties = {
12
+ [K in keyof CustomProperties]: CustomProperties[K] | CSSVariableValue;
13
+ };
14
+ interface CommonProperties extends BaseCSSProperties {
15
+ accentColor?: CSSColorProperty;
16
+ color?: CSSColorProperty;
17
+ borderLeftColor?: CSSColorProperty;
18
+ borderRightColor?: CSSColorProperty;
19
+ borderTopColor?: CSSColorProperty;
20
+ borderBottomColor?: CSSColorProperty;
21
+ borderBlockColor?: CSSColorProperty;
22
+ borderBlockStartColor?: CSSColorProperty;
23
+ borderBlockEndColor?: CSSColorProperty;
24
+ borderInlineColor?: CSSColorProperty;
25
+ borderInlineStartColor?: CSSColorProperty;
26
+ borderInlineEndColor?: CSSColorProperty;
27
+ backgroundColor?: CSSColorProperty;
28
+ outlineColor?: CSSColorProperty;
29
+ textDecorationColor?: CSSColorProperty;
30
+ caretColor?: CSSColorProperty;
31
+ columnRuleColor?: CSSColorProperty;
32
+ }
33
+ type AndString = `&${string}`;
34
+ type AndStringType = {
35
+ [key in AndString]: CommonProperties;
36
+ };
37
+ type Colon = `:${string}`;
38
+ type ColonType = {
39
+ [key in Colon]: CommonProperties;
40
+ };
41
+ export type MediaQuery = `@media ${string}`;
42
+ type MediaQueryType = {
43
+ [K in MediaQuery]: CommonProperties | ColonType | AndStringType;
44
+ };
45
+ export type CSSProperties = CommonProperties | ColonType | CSSVariableProperty | AndStringType | MediaQueryType;
46
+ export {};
@@ -0,0 +1,5 @@
1
+ type PropertyValue = string | number | PropertyType;
2
+ export type PropertyType = {
3
+ [key: string]: PropertyValue;
4
+ };
5
+ export {};
@@ -0,0 +1,10 @@
1
+ import type { CSSProperties } from '../common/css-properties';
2
+ export type CreateStyleType<T> = {
3
+ readonly [K in keyof T]: T[K] extends CSSProperties ? CSSProperties : T[K];
4
+ };
5
+ export type CreateStyle = {
6
+ [key: string]: CSSProperties;
7
+ };
8
+ export type ReturnType<T> = {
9
+ [key in keyof T]: string;
10
+ };
@@ -0,0 +1,37 @@
1
+ import type { CSSProperties, MediaQuery } from '../common/css-properties';
2
+ type JSXType = keyof HTMLElementTagNameMap | '*' | ':root';
3
+ type HTMLType = {
4
+ [K in JSXType]: CSSProperties;
5
+ };
6
+ type ClassName = `.${string}`;
7
+ type ClassNameType = {
8
+ [K in ClassName]: CSSProperties;
9
+ };
10
+ type Attribute = `${string}[${string}]${string}`;
11
+ type AttributeType = {
12
+ [K in Attribute]: CSSProperties;
13
+ };
14
+ type Consecutive = `${JSXType} ${string}`;
15
+ type ConsecutiveType = {
16
+ [K in Consecutive]: CSSProperties;
17
+ };
18
+ type PseudoClass = `${JSXType}:${string}`;
19
+ type PseudoClassType = {
20
+ [K in PseudoClass]: CSSProperties;
21
+ };
22
+ type PseudoElement = `::${string}`;
23
+ type PseudoElementType = {
24
+ [K in PseudoElement]: CSSProperties;
25
+ };
26
+ type KeyframeSelector = 'from' | 'to' | `${number}%`;
27
+ export type CreateKeyframes = {
28
+ [K in KeyframeSelector]?: CSSProperties;
29
+ };
30
+ type KeyframesType = {
31
+ [K in `@keyframes ${string}`]: CreateKeyframes;
32
+ };
33
+ type MediaQueryHTMLType = {
34
+ [K in MediaQuery]: CSSHTML;
35
+ };
36
+ export type CSSHTML = HTMLType | ClassNameType | AttributeType | ConsecutiveType | PseudoClassType | PseudoElementType | KeyframesType | MediaQueryHTMLType;
37
+ export {};
@@ -0,0 +1,8 @@
1
+ type CSSVariableKey = `--${string}`;
2
+ export type CSSVariableValue = `var(${CSSVariableKey})`;
3
+ export type CSSVariableProperty = {
4
+ [key: CSSVariableKey]: string | number;
5
+ };
6
+ export type CreateVars = Record<string, string | number>;
7
+ export type CreateTheme = Record<string, Record<string, string | number>>;
8
+ export {};
@@ -0,0 +1 @@
1
+ export declare const build: (styleSheet: string, filePath: string, global?: string) => Promise<void>;
@@ -0,0 +1,2 @@
1
+ import { CreateStyle, CreateKeyframes } from '../index.js';
2
+ export declare function genBase36Hash(object: CreateStyle | CreateKeyframes, n: number): string;
@@ -0,0 +1,5 @@
1
+ export declare const isServer: boolean;
2
+ export declare const isDevelopment: boolean;
3
+ export declare const isDevAndTest: boolean;
4
+ export declare const applyCssValue: (value: string | number, cssProp: string) => string;
5
+ export declare const camelToKebabCase: (property: string) => string;
@@ -0,0 +1,2 @@
1
+ export declare function createStyleElement(hash: string): HTMLStyleElement | null;
2
+ export declare function injectClientCSS(hash: string, sheet: string): void;
@@ -0,0 +1 @@
1
+ export declare function injectClientGlobalCSS(sheet: string): void;
@@ -0,0 +1,2 @@
1
+ export declare function injectServerCSS(hash: string, sheet: string): void;
2
+ export declare function getServerCSS(): string;
@@ -0,0 +1,4 @@
1
+ import type { CSSHTML } from '../index.js';
2
+ export declare function transpiler(object: CSSHTML, base36Hash?: string, core?: string): {
3
+ styleSheet: string;
4
+ };
package/dist/index.d.ts DELETED
@@ -1,111 +0,0 @@
1
- import { Properties, Property } from "csstype";
2
-
3
- //#region src/types/main/vars.d.ts
4
- type CSSVariableKey = `--${string}`;
5
- type CSSVariableValue = `var(${CSSVariableKey})`;
6
- type CSSVariableProperty = {
7
- [key: CSSVariableKey]: string | number;
8
- };
9
- type CreateVars = Record<string, string | number>;
10
- type CreateTheme = Record<string, Record<string, string | number>>;
11
-
12
- //#endregion
13
- //#region src/types/common/css-properties.d.ts
14
- type ColorValue = Exclude<Property.Color, '-moz-initial'> | (string & {});
15
- type CSSColorProperty = Exclude<ColorValue, SystemColorKeyword>;
16
- type SystemColorKeyword = 'ActiveBorder' | 'ActiveCaption' | 'AppWorkspace' | 'Background' | 'ButtonFace' | 'ButtonHighlight' | 'ButtonShadow' | 'ButtonText' | 'CaptionText' | 'GrayText' | 'Highlight' | 'HighlightText' | 'InactiveBorder' | 'InactiveCaption' | 'InactiveCaptionText' | 'InfoBackground' | 'InfoText' | 'Menu' | 'MenuText' | 'Scrollbar' | 'ThreeDDarkShadow' | 'ThreeDFace' | 'ThreeDHighlight' | 'ThreeDLightShadow' | 'ThreeDShadow' | 'Window' | 'WindowFrame' | 'WindowText';
17
- type ExcludeMozInitial<T> = Exclude<T, '-moz-initial'>;
18
- type CSSTypeProperties = Properties<number | (string & {})>;
19
- type CustomProperties = { [K in keyof CSSTypeProperties]: ExcludeMozInitial<CSSTypeProperties[K]> };
20
- type BaseCSSProperties = { [K in keyof CustomProperties]: CustomProperties[K] | CSSVariableValue };
21
- interface CommonProperties extends BaseCSSProperties {
22
- accentColor?: CSSColorProperty;
23
- color?: CSSColorProperty;
24
- borderLeftColor?: CSSColorProperty;
25
- borderRightColor?: CSSColorProperty;
26
- borderTopColor?: CSSColorProperty;
27
- borderBottomColor?: CSSColorProperty;
28
- borderBlockColor?: CSSColorProperty;
29
- borderBlockStartColor?: CSSColorProperty;
30
- borderBlockEndColor?: CSSColorProperty;
31
- borderInlineColor?: CSSColorProperty;
32
- borderInlineStartColor?: CSSColorProperty;
33
- borderInlineEndColor?: CSSColorProperty;
34
- backgroundColor?: CSSColorProperty;
35
- outlineColor?: CSSColorProperty;
36
- textDecorationColor?: CSSColorProperty;
37
- caretColor?: CSSColorProperty;
38
- columnRuleColor?: CSSColorProperty;
39
- }
40
- type AndString = `&${string}`;
41
- type AndStringType = { [key in AndString]: CommonProperties };
42
- type Colon = `:${string}`;
43
- type ColonType = { [key in Colon]: CommonProperties };
44
- type MediaQuery = `@media ${string}`;
45
- type MediaQueryType = { [K in MediaQuery]: CommonProperties | ColonType | AndStringType };
46
- type CSSProperties = CommonProperties | ColonType | CSSVariableProperty | AndStringType | MediaQueryType;
47
-
48
- //#endregion
49
- //#region src/types/main/create.d.ts
50
- type CreateStyleType<T> = { readonly [K in keyof T]: T[K] extends CSSProperties ? CSSProperties : T[K] };
51
- type CreateStyle = {
52
- [key: string]: CSSProperties;
53
- };
54
- type ReturnType<T> = { [key in keyof T]: string };
55
-
56
- //#endregion
57
- //#region src/types/main/global.d.ts
58
- type JSXType = keyof HTMLElementTagNameMap | '*' | ':root';
59
- type HTMLType = { [K in JSXType]: CSSProperties };
60
- type ClassName = `.${string}`;
61
- type ClassNameType = { [K in ClassName]: CSSProperties };
62
- type Attribute = `${string}[${string}]${string}`;
63
- type AttributeType = { [K in Attribute]: CSSProperties };
64
- type Consecutive = `${JSXType} ${string}`;
65
- type ConsecutiveType = { [K in Consecutive]: CSSProperties };
66
- type PseudoClass = `${JSXType}:${string}`;
67
- type PseudoClassType = { [K in PseudoClass]: CSSProperties };
68
- type PseudoElement = `::${string}`;
69
- type PseudoElementType = { [K in PseudoElement]: CSSProperties };
70
- type KeyframeSelector = 'from' | 'to' | `${number}%`;
71
- type CreateKeyframes = { [K in KeyframeSelector]?: CSSProperties };
72
- type KeyframesType = { [K in `@keyframes ${string}`]: CreateKeyframes };
73
- type MediaQueryHTMLType = { [K in MediaQuery]: CSSHTML };
74
- type CSSHTML = HTMLType | ClassNameType | AttributeType | ConsecutiveType | PseudoClassType | PseudoElementType | KeyframesType | MediaQueryHTMLType;
75
-
76
- //#endregion
77
- //#region src/utils/helper.d.ts
78
- declare const isServer: boolean;
79
- declare const isDevelopment: boolean;
80
- declare const isDevAndTest: boolean;
81
- declare const camelToKebabCase: (property: string) => string;
82
-
83
- //#endregion
84
- //#region src/utils/hash.d.ts
85
- declare function genBase36Hash(object: CreateStyle | CreateKeyframes, n: number): string;
86
-
87
- //#endregion
88
- //#region src/utils/transpiler.d.ts
89
- declare function transpiler(object: CSSHTML, base36Hash?: string, core?: string): {
90
- styleSheet: string;
91
- };
92
-
93
- //#endregion
94
- //#region src/utils/build.d.ts
95
- declare const build: (styleSheet: string, filePath: string, global?: string) => Promise<void>;
96
-
97
- //#endregion
98
- //#region src/utils/inject-client-css.d.ts
99
- declare function injectClientCSS(hash: string, sheet: string): void;
100
-
101
- //#endregion
102
- //#region src/utils/inject-client-global-css.d.ts
103
- declare function injectClientGlobalCSS(sheet: string): void;
104
-
105
- //#endregion
106
- //#region src/utils/inject-server-css.d.ts
107
- declare function injectServerCSS(hash: string, sheet: string): void;
108
- declare function getServerCSS(): string;
109
-
110
- //#endregion
111
- export { CSSHTML, CSSProperties, CreateKeyframes, CreateStyle, CreateStyleType, CreateTheme, CreateVars, ReturnType, build, camelToKebabCase, genBase36Hash, getServerCSS, injectClientCSS, injectClientGlobalCSS, injectServerCSS, isDevAndTest, isDevelopment, isServer, transpiler };
package/dist/index.js DELETED
@@ -1,258 +0,0 @@
1
-
2
- //#region src/utils/helper.ts
3
- const isWindowDefined = typeof window !== "undefined";
4
- const isDocumentDefined = typeof document !== "undefined";
5
- const isServer = !isWindowDefined || !isDocumentDefined;
6
- const isDevelopment = process.env.NODE_ENV === "development";
7
- const isDevAndTest = process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test";
8
- const exception = [
9
- "line-height",
10
- "font-weight",
11
- "opacity",
12
- "scale",
13
- "z-index",
14
- "column-count",
15
- "order",
16
- "orphans",
17
- "widows"
18
- ];
19
- const applyCssValue = (value, cssProp) => {
20
- if (typeof value === "number") return exception.includes(cssProp) ? value.toString() : value + "px";
21
- return value;
22
- };
23
- const camelToKebabCase = (property) => {
24
- if (/^(ms|Moz|Webkit)/.test(property)) property = "-" + property;
25
- return property.replace(/([A-Z]+)([0-9]+)/g, "$1$2").replace(/([a-z0-9])([A-Z])/g, "$1-$2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1-$2").toLowerCase();
26
- };
27
-
28
- //#endregion
29
- //#region src/utils/hash.ts
30
- const chars = "abcdefghijklmnopqrstuvwxyz0123456789";
31
- function simpleHash(str) {
32
- let hash = 0;
33
- for (let i = 0; i < str.length; i++) {
34
- const char = str.charCodeAt(i);
35
- hash = (hash << 5) - hash + char;
36
- }
37
- return Math.abs(hash);
38
- }
39
- function encodeBase36(num) {
40
- let result = "";
41
- do {
42
- result = chars[num % 36] + result;
43
- num = Math.floor(num / 36);
44
- } while (num > 0);
45
- return result;
46
- }
47
- function getStartingChar(hash) {
48
- const chars$1 = "abcdefghijklmnopqrstuvwxyz";
49
- return chars$1[hash % chars$1.length];
50
- }
51
- function genBase36Hash(object, n) {
52
- const serialized = JSON.stringify(object);
53
- const hash = simpleHash(serialized);
54
- let base36Hash = encodeBase36(hash);
55
- const startingChar = getStartingChar(hash);
56
- while (base36Hash.length < n - 1) base36Hash = chars[hash % chars.length] + base36Hash;
57
- return startingChar + base36Hash.slice(0, n - 1);
58
- }
59
-
60
- //#endregion
61
- //#region src/utils/transpiler.ts
62
- const createKeyframes = (property, content) => {
63
- let keyframesRules = `${property} {\n`;
64
- for (const key in content) if (Object.prototype.hasOwnProperty.call(content, key)) {
65
- const keyframeValue = content[key];
66
- keyframesRules += ` ${key} {\n`;
67
- for (const prop in keyframeValue) if (Object.prototype.hasOwnProperty.call(keyframeValue, prop)) {
68
- const CSSProp = camelToKebabCase(prop);
69
- const value = keyframeValue[prop];
70
- if (typeof value === "string" || typeof value === "number") {
71
- const applyValue = applyCssValue(value, CSSProp);
72
- keyframesRules += ` ${CSSProp}: ${applyValue};\n`;
73
- }
74
- }
75
- keyframesRules += ` }\n`;
76
- }
77
- keyframesRules += `}\n`;
78
- return keyframesRules;
79
- };
80
- function transpiler(object, base36Hash, core) {
81
- let styleSheet = "";
82
- const mediaQueries = [];
83
- const classNameType = (property) => {
84
- return core === "--global" ? property : `.${property}_${base36Hash}`;
85
- };
86
- const rules = (indent, rulesValue, property) => {
87
- if (typeof property !== "string") return "";
88
- const value = rulesValue[property];
89
- const cssProp = camelToKebabCase(property);
90
- return `${indent}${cssProp}: ${value};\n`;
91
- };
92
- const stringConverter = (className, properties, indentLevel = 0) => {
93
- const classSelector = {};
94
- const indent = "".repeat(indentLevel);
95
- const innerIndent = " ".repeat(indentLevel + 1);
96
- let cssRule = "";
97
- for (const property in properties) if (Object.prototype.hasOwnProperty.call(properties, property)) {
98
- const value = properties[property];
99
- if (typeof value === "string" || typeof value === "number") {
100
- let CSSProp = camelToKebabCase(property);
101
- if (property.startsWith("ms")) CSSProp = `-${CSSProp}`;
102
- const applyValue = applyCssValue(value, CSSProp);
103
- cssRule += ` ${CSSProp}: ${applyValue};\n`;
104
- } else if (!property.startsWith("@")) {
105
- const kebabPseudoSelector = camelToKebabCase(property.replace("&", ""));
106
- const styles = stringConverter(className + kebabPseudoSelector, value, indentLevel);
107
- Object.assign(classSelector, styles);
108
- } else if (property.startsWith("@media") || property.startsWith("@container")) {
109
- const mediaRule = property;
110
- let nestedRules = "";
111
- let regularRules = "";
112
- for (const mediaProp in value) if (Object.prototype.hasOwnProperty.call(value, mediaProp)) {
113
- const mediaValue = value[mediaProp];
114
- const isColon = mediaProp.startsWith(":");
115
- const isAnd = mediaProp.startsWith("&");
116
- if (isColon || isAnd) {
117
- const kebabMediaProp = camelToKebabCase(mediaProp.replace("&", ""));
118
- let pseudoClassRule = "";
119
- if (typeof mediaValue === "object" && mediaValue !== null) {
120
- for (const pseudoProp in mediaValue) if (Object.prototype.hasOwnProperty.call(mediaValue, pseudoProp)) {
121
- const CSSProp = camelToKebabCase(pseudoProp);
122
- const applyValue = applyCssValue(mediaValue[pseudoProp], CSSProp);
123
- pseudoClassRule += rules(innerIndent + " ", { [pseudoProp]: applyValue }, pseudoProp);
124
- }
125
- }
126
- nestedRules += `${innerIndent}${className}${kebabMediaProp} {\n${pseudoClassRule}${innerIndent}}\n`;
127
- } else {
128
- const CSSProp = camelToKebabCase(mediaProp);
129
- const applyValue = applyCssValue(mediaValue, CSSProp);
130
- regularRules += rules(innerIndent + " ", { [mediaProp]: applyValue }, mediaProp);
131
- }
132
- }
133
- if (regularRules) mediaQueries.push({
134
- media: mediaRule,
135
- css: `${mediaRule} {\n${innerIndent}${className} {\n${regularRules} }\n${nestedRules}${indent}}${indent}\n`
136
- });
137
- else mediaQueries.push({
138
- media: mediaRule,
139
- css: `${mediaRule} {\n${nestedRules}${indent}}\n`
140
- });
141
- }
142
- }
143
- classSelector[className] = cssRule;
144
- return classSelector;
145
- };
146
- for (const property in object) {
147
- if (property.startsWith("@keyframes")) {
148
- const keyframesContent = object[property];
149
- styleSheet += createKeyframes(property, keyframesContent);
150
- }
151
- const classSelectors = stringConverter(classNameType(property), object[property], 1);
152
- for (const selector in classSelectors) if (!selector.startsWith("@keyframes") && classSelectors[selector]) styleSheet += selector + " {\n" + classSelectors[selector] + "}\n";
153
- }
154
- mediaQueries.forEach(({ css }) => {
155
- styleSheet += css;
156
- });
157
- return { styleSheet };
158
- }
159
-
160
- //#endregion
161
- //#region src/utils/build.ts
162
- const build = async (styleSheet, filePath, global) => {
163
- if (!isServer) return;
164
- const fs = await import("fs");
165
- const { styleText } = await import("util");
166
- const message = global === "--global" ? styleText("underline", `✅Generated global CSS\n\n`) : styleText("underline", `✅Generated create CSS\n\n`);
167
- try {
168
- if (fs.existsSync(filePath)) {
169
- const cssData = fs.readFileSync(filePath, "utf-8");
170
- if (!cssData.includes(styleSheet)) {
171
- fs.appendFileSync(filePath, styleSheet, "utf-8");
172
- if (process.argv.includes("--view")) console.log(message + styleSheet);
173
- }
174
- }
175
- return;
176
- } catch (error) {
177
- console.error("Error writing to file:", error);
178
- }
179
- };
180
-
181
- //#endregion
182
- //#region src/utils/inject-client-css.ts
183
- const styleSheets$1 = {};
184
- const hashCache = {};
185
- function createStyleElement(hash) {
186
- if (document.getElementById(hash)) return null;
187
- const styleElement = document.createElement("style");
188
- styleElement.setAttribute("id", hash);
189
- styleElement.setAttribute("type", "text/css");
190
- styleSheets$1[hash] = styleElement;
191
- document.head.appendChild(styleElement);
192
- return styleSheets$1[hash];
193
- }
194
- function injectClientCSS(hash, sheet) {
195
- if (isServer) return;
196
- requestAnimationFrame(() => {
197
- styleCleanUp();
198
- });
199
- hashCache[hash] = hash;
200
- const styleElement = createStyleElement(hash);
201
- if (styleElement == null) return;
202
- styleElement.textContent = sheet;
203
- }
204
- function styleCleanUp() {
205
- requestAnimationFrame(() => {
206
- for (const hash in hashCache) {
207
- const classElements = document.querySelectorAll(`[class*="${hash}"]`);
208
- if (classElements.length === 0) removeStyleElement(hashCache[hash]);
209
- }
210
- });
211
- }
212
- function removeStyleElement(hash) {
213
- if (styleSheets$1[hash]) {
214
- delete styleSheets$1[hash];
215
- if (hashCache.hasOwnProperty.call(hashCache, hash)) delete hashCache[hash];
216
- const styleElement = document.getElementById(hash);
217
- if (styleElement) document.head.removeChild(styleElement);
218
- }
219
- }
220
-
221
- //#endregion
222
- //#region src/utils/inject-client-global-css.ts
223
- function injectClientGlobalCSS(sheet) {
224
- if (isServer) return;
225
- const existingStyleElement = document.querySelector(`[data-scope="global"]`);
226
- if (existingStyleElement instanceof HTMLStyleElement) {
227
- existingStyleElement.textContent += sheet;
228
- return;
229
- }
230
- const styleElement = document.createElement("style");
231
- styleElement.setAttribute("data-scope", "global");
232
- styleElement.setAttribute("type", "text/css");
233
- styleElement.textContent = sheet;
234
- document.head.appendChild(styleElement);
235
- }
236
-
237
- //#endregion
238
- //#region src/utils/inject-server-css.ts
239
- const styleSheets = {};
240
- function injectServerCSS(hash, sheet) {
241
- styleSheets[hash] = sheet;
242
- }
243
- function getServerCSS() {
244
- return Object.values(styleSheets).join("\n");
245
- }
246
-
247
- //#endregion
248
- exports.build = build;
249
- exports.camelToKebabCase = camelToKebabCase;
250
- exports.genBase36Hash = genBase36Hash;
251
- exports.getServerCSS = getServerCSS;
252
- exports.injectClientCSS = injectClientCSS;
253
- exports.injectClientGlobalCSS = injectClientGlobalCSS;
254
- exports.injectServerCSS = injectServerCSS;
255
- exports.isDevAndTest = isDevAndTest;
256
- exports.isDevelopment = isDevelopment;
257
- exports.isServer = isServer;
258
- exports.transpiler = transpiler;