zss-engine 0.2.9 → 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.
Files changed (45) hide show
  1. package/dist/build-12x-B3dvmUcg.mjs +52 -0
  2. package/dist/build-12x-C7vH1H69.js +54 -0
  3. package/dist/index.js +236 -30
  4. package/dist/index.mjs +225 -8
  5. package/package.json +5 -7
  6. package/types/index.d.ts +130 -8
  7. package/dist/types/common/css-properties.js +0 -2
  8. package/dist/types/common/css-properties.mjs +0 -1
  9. package/dist/types/common/css-property.js +0 -2
  10. package/dist/types/common/css-property.mjs +0 -1
  11. package/dist/types/index.js +0 -21
  12. package/dist/types/index.mjs +0 -5
  13. package/dist/types/main/create.js +0 -2
  14. package/dist/types/main/create.mjs +0 -1
  15. package/dist/types/main/global.js +0 -2
  16. package/dist/types/main/global.mjs +0 -1
  17. package/dist/types/main/vars.js +0 -2
  18. package/dist/types/main/vars.mjs +0 -1
  19. package/dist/utils/build.js +0 -27
  20. package/dist/utils/build.mjs +0 -23
  21. package/dist/utils/hash.js +0 -34
  22. package/dist/utils/hash.mjs +0 -31
  23. package/dist/utils/helper.js +0 -21
  24. package/dist/utils/helper.mjs +0 -16
  25. package/dist/utils/inject-client-css.js +0 -51
  26. package/dist/utils/inject-client-css.mjs +0 -47
  27. package/dist/utils/inject-client-global-css.js +0 -18
  28. package/dist/utils/inject-client-global-css.mjs +0 -15
  29. package/dist/utils/inject-server-css.js +0 -11
  30. package/dist/utils/inject-server-css.mjs +0 -7
  31. package/dist/utils/transpiler.js +0 -125
  32. package/dist/utils/transpiler.mjs +0 -122
  33. package/types/types/common/css-properties.d.ts +0 -46
  34. package/types/types/common/css-property.d.ts +0 -5
  35. package/types/types/index.d.ts +0 -5
  36. package/types/types/main/create.d.ts +0 -10
  37. package/types/types/main/global.d.ts +0 -45
  38. package/types/types/main/vars.d.ts +0 -10
  39. package/types/utils/build.d.ts +0 -1
  40. package/types/utils/hash.d.ts +0 -2
  41. package/types/utils/helper.d.ts +0 -6
  42. package/types/utils/inject-client-css.d.ts +0 -2
  43. package/types/utils/inject-client-global-css.d.ts +0 -1
  44. package/types/utils/inject-server-css.d.ts +0 -2
  45. package/types/utils/transpiler.d.ts +0 -4
@@ -1,122 +0,0 @@
1
- import { camelToKebabCase, applyCssValue } from '..';
2
- const createKeyframes = (property, content) => {
3
- let keyframesRules = `${property} {\n`;
4
- for (const key in content) {
5
- if (Object.prototype.hasOwnProperty.call(content, key)) {
6
- const keyframeValue = content[key];
7
- keyframesRules += ` ${key} {\n`;
8
- for (const prop in keyframeValue) {
9
- if (Object.prototype.hasOwnProperty.call(keyframeValue, prop)) {
10
- const CSSProp = camelToKebabCase(prop);
11
- const value = keyframeValue[prop];
12
- if (typeof value === 'string' || typeof value === 'number') {
13
- const applyValue = applyCssValue(value, CSSProp);
14
- keyframesRules += ` ${CSSProp}: ${applyValue};\n`;
15
- }
16
- }
17
- }
18
- keyframesRules += ` }\n`;
19
- }
20
- }
21
- keyframesRules += `}\n`;
22
- return keyframesRules;
23
- };
24
- export function transpiler(object, base36Hash, core) {
25
- let styleSheet = '';
26
- const mediaQueries = [];
27
- const classNameType = (property) => {
28
- return core === '--global' ? property : `.${property}_${base36Hash}`;
29
- };
30
- const rules = (indent, rulesValue, property) => {
31
- if (typeof property !== 'string')
32
- return '';
33
- const value = rulesValue[property];
34
- const cssProp = camelToKebabCase(property);
35
- return `${indent}${cssProp}: ${value};\n`;
36
- };
37
- const stringConverter = (className, properties, indentLevel = 0) => {
38
- const classSelector = {};
39
- const indent = ''.repeat(indentLevel);
40
- const innerIndent = ' '.repeat(indentLevel + 1);
41
- let cssRule = '';
42
- for (const property in properties) {
43
- if (Object.prototype.hasOwnProperty.call(properties, property)) {
44
- const value = properties[property];
45
- if (typeof value === 'string' || typeof value === 'number') {
46
- let CSSProp = camelToKebabCase(property);
47
- if (property.startsWith('ms')) {
48
- CSSProp = `-${CSSProp}`;
49
- }
50
- const applyValue = applyCssValue(value, CSSProp);
51
- cssRule += ` ${CSSProp}: ${applyValue};\n`;
52
- }
53
- else if (!property.startsWith('@')) {
54
- const kebabPseudoSelector = camelToKebabCase(property.replace('&', ''));
55
- const styles = stringConverter(className + kebabPseudoSelector, value, indentLevel);
56
- Object.assign(classSelector, styles);
57
- }
58
- else if (property.startsWith('@media') || property.startsWith('@container')) {
59
- const mediaRule = property;
60
- let nestedRules = '';
61
- let regularRules = '';
62
- for (const mediaProp in value) {
63
- if (Object.prototype.hasOwnProperty.call(value, mediaProp)) {
64
- const mediaValue = value[mediaProp];
65
- const isColon = mediaProp.startsWith(':');
66
- const isAnd = mediaProp.startsWith('&');
67
- if (isColon || isAnd) {
68
- const kebabMediaProp = camelToKebabCase(mediaProp.replace('&', ''));
69
- let pseudoClassRule = '';
70
- if (typeof mediaValue === 'object' && mediaValue !== null) {
71
- for (const pseudoProp in mediaValue) {
72
- if (Object.prototype.hasOwnProperty.call(mediaValue, pseudoProp)) {
73
- const CSSProp = camelToKebabCase(pseudoProp);
74
- const applyValue = applyCssValue(mediaValue[pseudoProp], CSSProp);
75
- pseudoClassRule += rules(innerIndent + ' ', { [pseudoProp]: applyValue }, pseudoProp);
76
- }
77
- }
78
- }
79
- nestedRules += `${innerIndent}${className}${kebabMediaProp} {\n${pseudoClassRule}${innerIndent}}\n`;
80
- }
81
- else {
82
- const CSSProp = camelToKebabCase(mediaProp);
83
- const applyValue = applyCssValue(mediaValue, CSSProp);
84
- regularRules += rules(innerIndent + ' ', { [mediaProp]: applyValue }, mediaProp);
85
- }
86
- }
87
- }
88
- if (regularRules) {
89
- mediaQueries.push({
90
- media: mediaRule,
91
- css: `${mediaRule} {\n${innerIndent}${className} {\n${regularRules} }\n${nestedRules}${indent}}${indent}\n`,
92
- });
93
- }
94
- else {
95
- mediaQueries.push({
96
- media: mediaRule,
97
- css: `${mediaRule} {\n${nestedRules}${indent}}\n`,
98
- });
99
- }
100
- }
101
- }
102
- }
103
- classSelector[className] = cssRule;
104
- return classSelector;
105
- };
106
- for (const property in object) {
107
- if (property.startsWith('@keyframes')) {
108
- const keyframesContent = object[property];
109
- styleSheet += createKeyframes(property, keyframesContent);
110
- }
111
- const classSelectors = stringConverter(classNameType(property), object[property], 1);
112
- for (const selector in classSelectors) {
113
- if (!selector.startsWith('@keyframes') && classSelectors[selector]) {
114
- styleSheet += selector + ' {\n' + classSelectors[selector] + '}\n';
115
- }
116
- }
117
- }
118
- mediaQueries.forEach(({ css }) => {
119
- styleSheet += css;
120
- });
121
- return { styleSheet };
122
- }
@@ -1,46 +0,0 @@
1
- import type { CSSVariableValue } 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 CSSProperties = {
9
- [K in keyof CSSTypeProperties]: ExcludeMozInitial<CSSTypeProperties[K]>;
10
- };
11
- type BaseCSSProperties = {
12
- [K in keyof CSSProperties]: CSSProperties[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 CustomProperties = CommonProperties | ColonType | AndStringType | MediaQueryType;
46
- export {};
@@ -1,5 +0,0 @@
1
- type PropertyValue = string | number | PropertyType;
2
- export type PropertyType = {
3
- [key: string]: PropertyValue;
4
- };
5
- export {};
@@ -1,5 +0,0 @@
1
- export * from './common/css-properties';
2
- export * from './common/css-property';
3
- export * from './main/create';
4
- export * from './main/global';
5
- export * from './main/vars';
@@ -1,10 +0,0 @@
1
- import type { CustomProperties } from '../common/css-properties';
2
- export type CreateStyle<T> = {
3
- readonly [K in keyof T]: T[K] extends CustomProperties ? CustomProperties : T[K];
4
- };
5
- export type ClassesStyle = {
6
- [key: string]: CustomProperties;
7
- };
8
- export type ReturnType<T> = {
9
- [key in keyof T]: string;
10
- };
@@ -1,45 +0,0 @@
1
- import type { CustomProperties, MediaQuery } from '../common/css-properties';
2
- type JSXType = keyof HTMLElementTagNameMap | '*' | ':root';
3
- type HTMLType = {
4
- [K in JSXType]: CustomProperties;
5
- };
6
- type ClassName = `.${string}`;
7
- type ClassNameType = {
8
- [K in ClassName]: CustomProperties;
9
- };
10
- type Attribute = `${string}[${string}]${string}`;
11
- type AttributeType = {
12
- [K in Attribute]: CustomProperties;
13
- };
14
- type Consecutive = `${JSXType} ${string}`;
15
- type ConsecutiveType = {
16
- [K in Consecutive]: CustomProperties;
17
- };
18
- type PseudoClass = `${JSXType}:${string}`;
19
- type PseudoClassType = {
20
- [K in PseudoClass]: CustomProperties;
21
- };
22
- type PseudoElement = `::${string}`;
23
- type PseudoElementType = {
24
- [K in PseudoElement]: CustomProperties;
25
- };
26
- type KeyframeSelector = 'from' | 'to' | `${number}%`;
27
- export type KeyframesDefinition = {
28
- [K in KeyframeSelector]?: CustomProperties;
29
- };
30
- type KeyframesType = {
31
- [K in `@keyframes ${string}`]: KeyframesDefinition;
32
- };
33
- type MediaQueryHTMLType = {
34
- [K in MediaQuery]: CustomHTMLType;
35
- };
36
- export type CustomHTMLType =
37
- | HTMLType
38
- | ClassNameType
39
- | AttributeType
40
- | ConsecutiveType
41
- | PseudoClassType
42
- | PseudoElementType
43
- | KeyframesType
44
- | MediaQueryHTMLType;
45
- export {};
@@ -1,10 +0,0 @@
1
- export type VarsDefinition = Record<string, string | number | Record<string, string | number>>;
2
- type CSSVariableKey = `--${string}`;
3
- export type CSSVariableValue = `var(${CSSVariableKey})`;
4
- type CSSVariableProperties = {
5
- [key: CSSVariableKey]: string | number;
6
- };
7
- export type VarsTransformed = {
8
- [key: string]: CSSVariableProperties;
9
- };
10
- export {};
@@ -1 +0,0 @@
1
- export declare const build: (styleSheet: string, filePath: string, global?: string) => Promise<void>;
@@ -1,2 +0,0 @@
1
- import { ClassesStyle, KeyframesDefinition, VarsDefinition } from '..';
2
- export declare function genBase36Hash(object: ClassesStyle | KeyframesDefinition | VarsDefinition, n: number): string;
@@ -1,6 +0,0 @@
1
- export declare const isServer: boolean;
2
- export declare const isDevelopment: boolean;
3
- export declare const isDevAndTest: boolean;
4
- export declare const isDevServer: boolean;
5
- export declare const applyCssValue: (value: string | number, cssProp: string) => string;
6
- export declare const camelToKebabCase: (property: string) => string;
@@ -1,2 +0,0 @@
1
- export declare function createStyleElement(hash: string): HTMLStyleElement | null;
2
- export declare function injectClientCSS(hash: string, sheet: string): void;
@@ -1 +0,0 @@
1
- export declare function injectClientGlobalCSS(sheet: string, scoped: string): void;
@@ -1,2 +0,0 @@
1
- export declare function injectServerCSS(hash: string, sheet: string): void;
2
- export declare function getServerCSS(): string;
@@ -1,4 +0,0 @@
1
- import type { ClassesStyle, CustomHTMLType, VarsDefinition } from '..';
2
- export declare function transpiler(object: ClassesStyle | CustomHTMLType | VarsDefinition, base36Hash?: string, core?: string): {
3
- styleSheet: string;
4
- };