@master/css-engine 2.0.0-rc.70

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 (68) hide show
  1. package/README.md +57 -0
  2. package/dist/animation-rule.d.ts +12 -0
  3. package/dist/animation-rule.mjs +38 -0
  4. package/dist/common.d.ts +40 -0
  5. package/dist/common.mjs +114 -0
  6. package/dist/compile-manifest.d.ts +54 -0
  7. package/dist/compile-manifest.mjs +451 -0
  8. package/dist/compiler.d.ts +32 -0
  9. package/dist/compiler.mjs +38 -0
  10. package/dist/core.d.ts +141 -0
  11. package/dist/core.mjs +848 -0
  12. package/dist/emitted-globals.d.ts +4 -0
  13. package/dist/emitted-globals.mjs +1 -0
  14. package/dist/hydration-manifest.d.ts +4 -0
  15. package/dist/hydration-manifest.mjs +61 -0
  16. package/dist/index.d.ts +22 -0
  17. package/dist/index.mjs +15 -0
  18. package/dist/key-aliases.d.ts +4 -0
  19. package/dist/key-aliases.mjs +95 -0
  20. package/dist/layer.d.ts +17 -0
  21. package/dist/layer.mjs +78 -0
  22. package/dist/namespaces.d.ts +5 -0
  23. package/dist/namespaces.mjs +28 -0
  24. package/dist/native-value-namespaces.d.ts +9 -0
  25. package/dist/native-value-namespaces.mjs +346 -0
  26. package/dist/non-layer.d.ts +12 -0
  27. package/dist/non-layer.mjs +53 -0
  28. package/dist/rule.d.ts +7 -0
  29. package/dist/rule.mjs +14 -0
  30. package/dist/theme-layer.d.ts +21 -0
  31. package/dist/theme-layer.mjs +52 -0
  32. package/dist/utility-layer.d.ts +10 -0
  33. package/dist/utility-layer.mjs +118 -0
  34. package/dist/utility.d.ts +102 -0
  35. package/dist/utility.mjs +1263 -0
  36. package/dist/utils/collect-animation-names.d.ts +10 -0
  37. package/dist/utils/collect-animation-names.mjs +61 -0
  38. package/dist/utils/collect-variable-names.d.ts +3 -0
  39. package/dist/utils/collect-variable-names.mjs +18 -0
  40. package/dist/utils/compare-rule-priority.d.ts +14 -0
  41. package/dist/utils/compare-rule-priority.mjs +136 -0
  42. package/dist/utils/css-variables.d.ts +12 -0
  43. package/dist/utils/css-variables.mjs +197 -0
  44. package/dist/utils/find-native-css-rule-index.d.ts +1 -0
  45. package/dist/utils/find-native-css-rule-index.mjs +10 -0
  46. package/dist/utils/generate-at.d.ts +2 -0
  47. package/dist/utils/generate-at.mjs +32 -0
  48. package/dist/utils/generate-selector.d.ts +2 -0
  49. package/dist/utils/generate-selector.mjs +48 -0
  50. package/dist/utils/natural-compare.d.ts +2 -0
  51. package/dist/utils/natural-compare.mjs +6 -0
  52. package/dist/utils/parse-at.d.ts +44 -0
  53. package/dist/utils/parse-at.mjs +179 -0
  54. package/dist/utils/parse-pair.d.ts +8 -0
  55. package/dist/utils/parse-pair.mjs +46 -0
  56. package/dist/utils/parse-selector.d.ts +19 -0
  57. package/dist/utils/parse-selector.mjs +124 -0
  58. package/dist/utils/parse-value.d.ts +2 -0
  59. package/dist/utils/parse-value.mjs +37 -0
  60. package/dist/utils/replace-char-outside-quotes.d.ts +1 -0
  61. package/dist/utils/replace-char-outside-quotes.mjs +19 -0
  62. package/dist/utils/split-char-outside-quotes.d.ts +1 -0
  63. package/dist/utils/split-char-outside-quotes.mjs +27 -0
  64. package/dist/utils/wrap-at-rules.d.ts +1 -0
  65. package/dist/utils/wrap-at-rules.mjs +10 -0
  66. package/dist/variable-rule.d.ts +26 -0
  67. package/dist/variable-rule.mjs +105 -0
  68. package/package.json +1 -0
@@ -0,0 +1,4 @@
1
+ export interface MasterCSSEmittedGlobals {
2
+ variables?: Record<string, number>;
3
+ animations?: Record<string, number>;
4
+ }
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,4 @@
1
+ import type MasterCSS from './core';
2
+ import type { MasterCSSHydrationManifest } from '@master/css-schema/hydration-manifest';
3
+ export default function createHydrationManifest(css: MasterCSS): MasterCSSHydrationManifest;
4
+ export type { MasterCSSGeneratedRuleIR, MasterCSSHydrationManifest } from '@master/css-schema/hydration-manifest';
@@ -0,0 +1,61 @@
1
+ import { Utility } from './utility.mjs';
2
+ import { getRuleSortTier } from './utils/compare-rule-priority.mjs';
3
+
4
+ function serializeRule(className, rule) {
5
+ const nodes = rule.nodes?.map((node)=>({
6
+ text: node.text
7
+ }));
8
+ return {
9
+ className,
10
+ key: rule.key,
11
+ layer: rule.layerName,
12
+ type: rule.type,
13
+ sortTier: getRuleSortTier(rule),
14
+ priority: {
15
+ ...rule.priority.features?.length ? {
16
+ features: rule.priority.features.map((feature)=>[
17
+ ...feature
18
+ ])
19
+ } : {},
20
+ selector: rule.priority.selector
21
+ },
22
+ text: rule.text,
23
+ ...nodes?.length ? {
24
+ nodes
25
+ } : {},
26
+ selectorText: rule.selectorText,
27
+ ...rule.variableNames?.size ? {
28
+ variableNames: [
29
+ ...rule.variableNames
30
+ ]
31
+ } : {},
32
+ ...rule.animationNames?.size ? {
33
+ animationNames: [
34
+ ...rule.animationNames
35
+ ]
36
+ } : {}
37
+ };
38
+ }
39
+ function createHydrationManifest(css) {
40
+ const classNameByRule = new WeakMap();
41
+ for (const [className, rules] of css.classUtilities){
42
+ for (const rule of rules){
43
+ classNameByRule.set(rule, className);
44
+ }
45
+ }
46
+ const hydrationManifest = {
47
+ version: 1,
48
+ rules: []
49
+ };
50
+ for (const layer of css.getUtilityLayers()){
51
+ for (const rule of layer.rules){
52
+ if (!(rule instanceof Utility)) continue;
53
+ const className = classNameByRule.get(rule);
54
+ if (!className) continue;
55
+ hydrationManifest.rules.push(serializeRule(className, rule));
56
+ }
57
+ }
58
+ return hydrationManifest;
59
+ }
60
+
61
+ export { createHydrationManifest as default };
@@ -0,0 +1,22 @@
1
+ export { default as MasterCSS, default } from './core';
2
+ export type { CompiledUtility, MasterCSSCreateOptions, MasterCSSOptions, NativeCSSDeclaration, NativeCSSDeclarationMatcher } from './core';
3
+ export { Rule } from './rule';
4
+ export { default as Layer } from './layer';
5
+ export { default as ThemeLayer } from './theme-layer';
6
+ export { default as UtilityLayer } from './utility-layer';
7
+ export { default as NonLayer } from './non-layer';
8
+ export { default as VariableRule } from './variable-rule';
9
+ export { default as AnimationRule } from './animation-rule';
10
+ export { default as compareRulePriority } from './utils/compare-rule-priority';
11
+ export { default as createHydrationManifest } from './hydration-manifest';
12
+ export { collectAnimationNamesFromDeclaration } from './utils/collect-animation-names';
13
+ export { builtinKeyAliases } from './key-aliases';
14
+ export type { MasterCSSBuiltinKeyAliases } from './key-aliases';
15
+ export { builtinNamespaces, builtinNamespaceRef, builtinNamespaceSet } from './namespaces';
16
+ export type { MasterCSSBuiltinNamespace, MasterCSSBuiltinNamespaceRef } from './namespaces';
17
+ export { builtinNativeValueNamespaces } from './native-value-namespaces';
18
+ export type { MasterCSSBuiltinNativeValueNamespace, MasterCSSBuiltinNativeValueNamespaces } from './native-value-namespaces';
19
+ export * from '@master/css-schema/manifest';
20
+ export type * from './emitted-globals';
21
+ export type { Utility as GeneratedRule } from './utility';
22
+ export type { MasterCSSGeneratedRuleIR, MasterCSSHydrationManifest } from '@master/css-schema/hydration-manifest';
package/dist/index.mjs ADDED
@@ -0,0 +1,15 @@
1
+ export { default as MasterCSS, default } from './core.mjs';
2
+ export { Rule } from './rule.mjs';
3
+ export { default as Layer } from './layer.mjs';
4
+ export { default as ThemeLayer } from './theme-layer.mjs';
5
+ export { default as UtilityLayer } from './utility-layer.mjs';
6
+ export { default as NonLayer } from './non-layer.mjs';
7
+ export { default as VariableRule } from './variable-rule.mjs';
8
+ export { default as AnimationRule } from './animation-rule.mjs';
9
+ export { default as compareRulePriority } from './utils/compare-rule-priority.mjs';
10
+ export { default as createHydrationManifest } from './hydration-manifest.mjs';
11
+ export { collectAnimationNamesFromDeclaration } from './utils/collect-animation-names.mjs';
12
+ export { builtinKeyAliases } from './key-aliases.mjs';
13
+ export { builtinNamespaceRef, builtinNamespaceSet, builtinNamespaces } from './namespaces.mjs';
14
+ export { builtinNativeValueNamespaces } from './native-value-namespaces.mjs';
15
+ export * from '@master/css-schema/manifest';
@@ -0,0 +1,4 @@
1
+ export type MasterCSSBuiltinKeyAliases = Readonly<Record<string, string>>;
2
+ declare const keyAliases: MasterCSSBuiltinKeyAliases;
3
+ export default keyAliases;
4
+ export { keyAliases as builtinKeyAliases };
@@ -0,0 +1,95 @@
1
+ const keyAliases = Object.freeze({
2
+ 'fg': 'color',
3
+ 'bg': 'background',
4
+ 'gap-x': 'column-gap',
5
+ 'gap-y': 'row-gap',
6
+ 'grid-col': 'grid-column',
7
+ 'grid-col-end': 'grid-column-end',
8
+ 'grid-col-start': 'grid-column-start',
9
+ 'b': 'border',
10
+ 'bb': 'border-bottom',
11
+ 'bl': 'border-left',
12
+ 'br': 'border-right',
13
+ 'bt': 'border-top',
14
+ 'bx': 'border-inline',
15
+ 'by': 'border-block',
16
+ 'h': 'height',
17
+ 'ix': 'inset-inline',
18
+ 'ixe': 'inset-inline-end',
19
+ 'ixs': 'inset-inline-start',
20
+ 'iy': 'inset-block',
21
+ 'iye': 'inset-block-end',
22
+ 'iys': 'inset-block-start',
23
+ 'leading': 'line-height',
24
+ 'm': 'margin',
25
+ 'max': 'max-size',
26
+ 'max-h': 'max-height',
27
+ 'max-size-x': 'max-inline-size',
28
+ 'max-size-y': 'max-block-size',
29
+ 'max-w': 'max-width',
30
+ 'mb': 'margin-bottom',
31
+ 'min': 'min-size',
32
+ 'min-h': 'min-height',
33
+ 'min-size-x': 'min-inline-size',
34
+ 'min-size-y': 'min-block-size',
35
+ 'min-w': 'min-width',
36
+ 'ml': 'margin-left',
37
+ 'mr': 'margin-right',
38
+ 'mt': 'margin-top',
39
+ 'mx': 'margin-inline',
40
+ 'mxe': 'margin-inline-end',
41
+ 'mxs': 'margin-inline-start',
42
+ 'my': 'margin-block',
43
+ 'mye': 'margin-block-end',
44
+ 'mys': 'margin-block-start',
45
+ 'p': 'padding',
46
+ 'pb': 'padding-bottom',
47
+ 'pl': 'padding-left',
48
+ 'pr': 'padding-right',
49
+ 'pt': 'padding-top',
50
+ 'px': 'padding-inline',
51
+ 'pxe': 'padding-inline-end',
52
+ 'pxs': 'padding-inline-start',
53
+ 'py': 'padding-block',
54
+ 'pye': 'padding-block-end',
55
+ 'pys': 'padding-block-start',
56
+ 'r': 'border-radius',
57
+ 'rbl': 'border-bottom-left-radius',
58
+ 'rbr': 'border-bottom-right-radius',
59
+ 'rtl': 'border-top-left-radius',
60
+ 'rtr': 'border-top-right-radius',
61
+ 'scroll-m': 'scroll-margin',
62
+ 'scroll-mb': 'scroll-margin-bottom',
63
+ 'scroll-ml': 'scroll-margin-left',
64
+ 'scroll-mr': 'scroll-margin-right',
65
+ 'scroll-mt': 'scroll-margin-top',
66
+ 'scroll-mx': 'scroll-margin-inline',
67
+ 'scroll-mxe': 'scroll-margin-inline-end',
68
+ 'scroll-mxs': 'scroll-margin-inline-start',
69
+ 'scroll-my': 'scroll-margin-block',
70
+ 'scroll-mye': 'scroll-margin-block-end',
71
+ 'scroll-mys': 'scroll-margin-block-start',
72
+ 'scroll-p': 'scroll-padding',
73
+ 'scroll-pb': 'scroll-padding-bottom',
74
+ 'scroll-pl': 'scroll-padding-left',
75
+ 'scroll-pr': 'scroll-padding-right',
76
+ 'scroll-pt': 'scroll-padding-top',
77
+ 'scroll-px': 'scroll-padding-inline',
78
+ 'scroll-pxe': 'scroll-padding-inline-end',
79
+ 'scroll-pxs': 'scroll-padding-inline-start',
80
+ 'scroll-py': 'scroll-padding-block',
81
+ 'scroll-pye': 'scroll-padding-block-end',
82
+ 'scroll-pys': 'scroll-padding-block-start',
83
+ 'shadow': 'box-shadow',
84
+ 'size-x': 'inline-size',
85
+ 'size-y': 'block-size',
86
+ 'line-clamp': '-webkit-line-clamp',
87
+ 'text-fill-color': '-webkit-text-fill-color',
88
+ 'text-stroke-color': '-webkit-text-stroke-color',
89
+ 'text-stroke-width': '-webkit-text-stroke-width',
90
+ 'tracking': 'letter-spacing',
91
+ 'w': 'width',
92
+ 'z': 'z-index'
93
+ });
94
+
95
+ export { keyAliases as builtinKeyAliases, keyAliases as default };
@@ -0,0 +1,17 @@
1
+ import { Rule } from './rule';
2
+ import MasterCSS from './core';
3
+ import VariableRule from './variable-rule';
4
+ export default class Layer {
5
+ name: string;
6
+ css: MasterCSS;
7
+ readonly rules: (Rule | VariableRule)[];
8
+ readonly tokenCounts: Map<string, number>;
9
+ constructor(name: string, css: MasterCSS);
10
+ attach(): void;
11
+ detach(): void;
12
+ get(key: string): Rule | VariableRule | undefined;
13
+ insert(rule: Rule | VariableRule, index?: number): number | undefined;
14
+ delete(key: string): Rule | VariableRule | undefined;
15
+ reset(): void;
16
+ get text(): string;
17
+ }
package/dist/layer.mjs ADDED
@@ -0,0 +1,78 @@
1
+ const ruleMaps = new WeakMap();
2
+ function getRuleMap(layer) {
3
+ let ruleMap = ruleMaps.get(layer);
4
+ if (!ruleMap) {
5
+ ruleMap = new Map();
6
+ ruleMaps.set(layer, ruleMap);
7
+ }
8
+ return ruleMap;
9
+ }
10
+ function syncRuleMap(layer) {
11
+ const ruleMap = getRuleMap(layer);
12
+ if (ruleMap.size !== layer.rules.length) {
13
+ ruleMap.clear();
14
+ for (const rule of layer.rules){
15
+ ruleMap.set(rule.key, rule);
16
+ }
17
+ }
18
+ return ruleMap;
19
+ }
20
+ class Layer {
21
+ name;
22
+ css;
23
+ rules = [];
24
+ tokenCounts = new Map();
25
+ constructor(name, css){
26
+ this.name = name;
27
+ this.css = css;
28
+ }
29
+ attach() {
30
+ this.css.rules.push(this);
31
+ }
32
+ detach() {
33
+ this.css.rules.splice(this.css.rules.indexOf(this), 1);
34
+ }
35
+ get(key) {
36
+ return syncRuleMap(this).get(key);
37
+ }
38
+ insert(rule, index = this.rules.length) {
39
+ const ruleMap = syncRuleMap(this);
40
+ if (ruleMap.has(rule.key)) return;
41
+ this.rules.splice(index, 0, rule);
42
+ ruleMap.set(rule.key, rule);
43
+ // should attach after inserting, because this.text is possibly empty
44
+ if (!this.css.rules.includes(this)) {
45
+ this.attach();
46
+ }
47
+ return index;
48
+ }
49
+ delete(key) {
50
+ const ruleMap = syncRuleMap(this);
51
+ const deletedRule = ruleMap.get(key);
52
+ if (!deletedRule) return;
53
+ const index = this.rules.indexOf(deletedRule);
54
+ if (index === -1) return;
55
+ this.rules.splice(index, 1);
56
+ ruleMap.delete(key);
57
+ if (this.rules.length === 0) {
58
+ this.detach();
59
+ }
60
+ return deletedRule;
61
+ }
62
+ reset() {
63
+ this.rules.length = 0;
64
+ const indexOfLayer = this.css.rules.indexOf(this);
65
+ if (indexOfLayer !== -1) {
66
+ this.css.rules.splice(indexOfLayer, 1);
67
+ }
68
+ this.tokenCounts.clear();
69
+ getRuleMap(this).clear();
70
+ }
71
+ get text() {
72
+ const ruleText = this.rules.map(({ text })=>text).join('');
73
+ if (!ruleText) return '';
74
+ return '@layer ' + this.name + '{' + ruleText + '}';
75
+ }
76
+ }
77
+
78
+ export { Layer as default };
@@ -0,0 +1,5 @@
1
+ export declare const builtinNamespaces: readonly ["animate", "breakpoint", "color", "color-line", "color-text", "container", "content", "duration", "easing", "font", "font-family", "font-feature", "font-size", "font-weight", "leading", "order", "radius", "shadow", "spacing", "tracking"];
2
+ export type MasterCSSBuiltinNamespace = typeof builtinNamespaces[number];
3
+ export type MasterCSSBuiltinNamespaceRef = `~${MasterCSSBuiltinNamespace}` | `=${MasterCSSBuiltinNamespace}`;
4
+ export declare function builtinNamespaceRef(namespace: MasterCSSBuiltinNamespace, exact?: boolean): MasterCSSBuiltinNamespaceRef;
5
+ export declare const builtinNamespaceSet: ReadonlySet<string>;
@@ -0,0 +1,28 @@
1
+ const builtinNamespaces = Object.freeze([
2
+ 'animate',
3
+ 'breakpoint',
4
+ 'color',
5
+ 'color-line',
6
+ 'color-text',
7
+ 'container',
8
+ 'content',
9
+ 'duration',
10
+ 'easing',
11
+ 'font',
12
+ 'font-family',
13
+ 'font-feature',
14
+ 'font-size',
15
+ 'font-weight',
16
+ 'leading',
17
+ 'order',
18
+ 'radius',
19
+ 'shadow',
20
+ 'spacing',
21
+ 'tracking'
22
+ ]);
23
+ function builtinNamespaceRef(namespace, exact = false) {
24
+ return `${exact ? '=' : '~'}${namespace}`;
25
+ }
26
+ const builtinNamespaceSet = new Set(builtinNamespaces);
27
+
28
+ export { builtinNamespaceRef, builtinNamespaceSet, builtinNamespaces };
@@ -0,0 +1,9 @@
1
+ import { type MasterCSSBuiltinNamespaceRef } from './namespaces';
2
+ export interface MasterCSSBuiltinNativeValueNamespace {
3
+ readonly properties: readonly string[];
4
+ readonly variableAliasRefs: readonly MasterCSSBuiltinNamespaceRef[];
5
+ }
6
+ export type MasterCSSBuiltinNativeValueNamespaces = readonly MasterCSSBuiltinNativeValueNamespace[];
7
+ declare const nativeValueNamespaces: MasterCSSBuiltinNativeValueNamespaces;
8
+ export default nativeValueNamespaces;
9
+ export { nativeValueNamespaces as builtinNativeValueNamespaces };