zss-engine 0.2.8 → 0.2.10
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/build-12x-B3dvmUcg.mjs +52 -0
- package/dist/build-12x-C7vH1H69.js +54 -0
- package/dist/index.js +236 -30
- package/dist/index.mjs +225 -8
- package/package.json +10 -8
- package/types/index.d.ts +130 -8
- package/dist/types/common/css-properties.js +0 -2
- package/dist/types/common/css-properties.mjs +0 -1
- package/dist/types/common/css-property.js +0 -2
- package/dist/types/common/css-property.mjs +0 -1
- package/dist/types/index.js +0 -21
- package/dist/types/index.mjs +0 -5
- package/dist/types/main/create.js +0 -2
- package/dist/types/main/create.mjs +0 -1
- package/dist/types/main/global.js +0 -2
- package/dist/types/main/global.mjs +0 -1
- package/dist/types/main/vars.js +0 -2
- package/dist/types/main/vars.mjs +0 -1
- package/dist/utils/build.js +0 -27
- package/dist/utils/build.mjs +0 -23
- package/dist/utils/hash.js +0 -34
- package/dist/utils/hash.mjs +0 -31
- package/dist/utils/helper.js +0 -21
- package/dist/utils/helper.mjs +0 -16
- package/dist/utils/inject-client-css.js +0 -51
- package/dist/utils/inject-client-css.mjs +0 -47
- package/dist/utils/inject-client-global-css.js +0 -18
- package/dist/utils/inject-client-global-css.mjs +0 -15
- package/dist/utils/inject-server-css.js +0 -11
- package/dist/utils/inject-server-css.mjs +0 -7
- package/dist/utils/transpiler.js +0 -125
- package/dist/utils/transpiler.mjs +0 -122
- package/types/types/common/css-properties.d.ts +0 -46
- package/types/types/common/css-property.d.ts +0 -5
- package/types/types/index.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 -10
- package/types/utils/build.d.ts +0 -1
- package/types/utils/hash.d.ts +0 -2
- package/types/utils/helper.d.ts +0 -6
- 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/types/index.d.ts
CHANGED
|
@@ -1,8 +1,130 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { Properties, Property } from 'csstype';
|
|
2
|
+
|
|
3
|
+
type VarsDefinition = Record<string, string | number | Record<string, string | number>>;
|
|
4
|
+
type CSSVariableKey = `--${string}`;
|
|
5
|
+
type CSSVariableValue = `var(${CSSVariableKey})`;
|
|
6
|
+
type CSSVariableProperties = {
|
|
7
|
+
[key: CSSVariableKey]: string | number;
|
|
8
|
+
};
|
|
9
|
+
type VarsTransformed = {
|
|
10
|
+
[key: string]: CSSVariableProperties;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
type ColorValue = Exclude<Property.Color, '-moz-initial'> | (string & {});
|
|
14
|
+
type CSSColorProperty = Exclude<ColorValue, SystemColorKeyword>;
|
|
15
|
+
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';
|
|
16
|
+
type ExcludeMozInitial<T> = Exclude<T, '-moz-initial'>;
|
|
17
|
+
type CSSTypeProperties = Properties<number | (string & {})>;
|
|
18
|
+
type CSSProperties = {
|
|
19
|
+
[K in keyof CSSTypeProperties]: ExcludeMozInitial<CSSTypeProperties[K]>;
|
|
20
|
+
};
|
|
21
|
+
type BaseCSSProperties = {
|
|
22
|
+
[K in keyof CSSProperties]: CSSProperties[K] | CSSVariableValue;
|
|
23
|
+
};
|
|
24
|
+
interface CommonProperties extends BaseCSSProperties {
|
|
25
|
+
accentColor?: CSSColorProperty;
|
|
26
|
+
color?: CSSColorProperty;
|
|
27
|
+
borderLeftColor?: CSSColorProperty;
|
|
28
|
+
borderRightColor?: CSSColorProperty;
|
|
29
|
+
borderTopColor?: CSSColorProperty;
|
|
30
|
+
borderBottomColor?: CSSColorProperty;
|
|
31
|
+
borderBlockColor?: CSSColorProperty;
|
|
32
|
+
borderBlockStartColor?: CSSColorProperty;
|
|
33
|
+
borderBlockEndColor?: CSSColorProperty;
|
|
34
|
+
borderInlineColor?: CSSColorProperty;
|
|
35
|
+
borderInlineStartColor?: CSSColorProperty;
|
|
36
|
+
borderInlineEndColor?: CSSColorProperty;
|
|
37
|
+
backgroundColor?: CSSColorProperty;
|
|
38
|
+
outlineColor?: CSSColorProperty;
|
|
39
|
+
textDecorationColor?: CSSColorProperty;
|
|
40
|
+
caretColor?: CSSColorProperty;
|
|
41
|
+
columnRuleColor?: CSSColorProperty;
|
|
42
|
+
}
|
|
43
|
+
type AndString = `&${string}`;
|
|
44
|
+
type AndStringType = {
|
|
45
|
+
[key in AndString]: CommonProperties;
|
|
46
|
+
};
|
|
47
|
+
type Colon = `:${string}`;
|
|
48
|
+
type ColonType = {
|
|
49
|
+
[key in Colon]: CommonProperties;
|
|
50
|
+
};
|
|
51
|
+
type MediaQuery = `@media ${string}`;
|
|
52
|
+
type MediaQueryType = {
|
|
53
|
+
[K in MediaQuery]: CommonProperties | ColonType | AndStringType;
|
|
54
|
+
};
|
|
55
|
+
type CustomProperties = CommonProperties | ColonType | AndStringType | MediaQueryType;
|
|
56
|
+
|
|
57
|
+
type PropertyValue = string | number | PropertyType;
|
|
58
|
+
type PropertyType = {
|
|
59
|
+
[key: string]: PropertyValue;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
type CreateStyle<T> = {
|
|
63
|
+
readonly [K in keyof T]: T[K] extends CustomProperties ? CustomProperties : T[K];
|
|
64
|
+
};
|
|
65
|
+
type ClassesStyle = {
|
|
66
|
+
[key: string]: CustomProperties;
|
|
67
|
+
};
|
|
68
|
+
type ReturnType<T> = {
|
|
69
|
+
[key in keyof T]: string;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
type JSXType = keyof HTMLElementTagNameMap | '*' | ':root';
|
|
73
|
+
type HTMLType = {
|
|
74
|
+
[K in JSXType]: CustomProperties;
|
|
75
|
+
};
|
|
76
|
+
type ClassName = `.${string}`;
|
|
77
|
+
type ClassNameType = {
|
|
78
|
+
[K in ClassName]: CustomProperties;
|
|
79
|
+
};
|
|
80
|
+
type Attribute = `${string}[${string}]${string}`;
|
|
81
|
+
type AttributeType = {
|
|
82
|
+
[K in Attribute]: CustomProperties;
|
|
83
|
+
};
|
|
84
|
+
type Consecutive = `${JSXType} ${string}`;
|
|
85
|
+
type ConsecutiveType = {
|
|
86
|
+
[K in Consecutive]: CustomProperties;
|
|
87
|
+
};
|
|
88
|
+
type PseudoClass = `${JSXType}:${string}`;
|
|
89
|
+
type PseudoClassType = {
|
|
90
|
+
[K in PseudoClass]: CustomProperties;
|
|
91
|
+
};
|
|
92
|
+
type PseudoElement = `::${string}`;
|
|
93
|
+
type PseudoElementType = {
|
|
94
|
+
[K in PseudoElement]: CustomProperties;
|
|
95
|
+
};
|
|
96
|
+
type KeyframeSelector = 'from' | 'to' | `${number}%`;
|
|
97
|
+
type KeyframesDefinition = {
|
|
98
|
+
[K in KeyframeSelector]?: CustomProperties;
|
|
99
|
+
};
|
|
100
|
+
type KeyframesType = {
|
|
101
|
+
[K in `@keyframes ${string}`]: KeyframesDefinition;
|
|
102
|
+
};
|
|
103
|
+
type MediaQueryHTMLType = {
|
|
104
|
+
[K in MediaQuery]: CustomHTMLType;
|
|
105
|
+
};
|
|
106
|
+
type CustomHTMLType = HTMLType | ClassNameType | AttributeType | ConsecutiveType | PseudoClassType | PseudoElementType | KeyframesType | MediaQueryHTMLType;
|
|
107
|
+
|
|
108
|
+
declare const isServer: boolean;
|
|
109
|
+
declare const isDevelopment: boolean;
|
|
110
|
+
declare const isDevAndTest: boolean;
|
|
111
|
+
declare const isDevServer: boolean;
|
|
112
|
+
declare const applyCssValue: (value: string | number, cssProp: string) => string;
|
|
113
|
+
declare const camelToKebabCase: (property: string) => string;
|
|
114
|
+
|
|
115
|
+
declare function genBase36Hash(object: ClassesStyle | KeyframesDefinition | VarsDefinition, n: number): string;
|
|
116
|
+
|
|
117
|
+
declare function injectClientCSS(hash: string, sheet: string): void;
|
|
118
|
+
|
|
119
|
+
declare function injectClientGlobalCSS(sheet: string, scoped: string): void;
|
|
120
|
+
|
|
121
|
+
declare function injectServerCSS(hash: string, sheet: string): void;
|
|
122
|
+
declare function getServerCSS(): string;
|
|
123
|
+
|
|
124
|
+
declare const build: (styleSheet: string, filePath: string, global?: string) => Promise<void>;
|
|
125
|
+
|
|
126
|
+
declare function transpiler(object: ClassesStyle | CustomHTMLType | VarsDefinition, base36Hash?: string, core?: string): {
|
|
127
|
+
styleSheet: string;
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
export { type CSSVariableValue, type ClassesStyle, type CreateStyle, type CustomHTMLType, type CustomProperties, type KeyframesDefinition, type MediaQuery, type PropertyType, type ReturnType, type VarsDefinition, type VarsTransformed, applyCssValue, build, camelToKebabCase, genBase36Hash, getServerCSS, injectClientCSS, injectClientGlobalCSS, injectServerCSS, isDevAndTest, isDevServer, isDevelopment, isServer, transpiler };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/types/index.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
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
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/types/main/vars.js
DELETED
package/dist/types/main/vars.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/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_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
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
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
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/utils/hash.mjs
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/utils/helper.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,16 +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
|
-
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,51 +0,0 @@
|
|
|
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,47 +0,0 @@
|
|
|
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,18 +0,0 @@
|
|
|
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,15 +0,0 @@
|
|
|
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,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
|
-
}
|
package/dist/utils/transpiler.js
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
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
|
-
}
|