@terrazzo/plugin-css 2.0.0-alpha.7 → 2.0.0-beta.1

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/CHANGELOG.md CHANGED
@@ -4,6 +4,8 @@
4
4
 
5
5
  ### Minor Changes
6
6
 
7
+ - The `baseSelector`, `baseScheme`, and `modeSelectors` options are marked `@deprecated` for remove in 3.0. The new `permutations` API provides all functionality and then some, and should be migrated to as soon as possible.
8
+
7
9
  - [#530](https://github.com/terrazzoapp/terrazzo/pull/530) [`370ed7b`](https://github.com/terrazzoapp/terrazzo/commit/370ed7b0f578a64824124145d7f4936536b37bb3) Thanks [@drwpow](https://github.com/drwpow)! - ⚠️ Breaking change: lint on plugins no longer runs on individual files, rather, the full set once merged.
8
10
 
9
11
  If your lint plugin is not using the `src` context value, no changes are needed. If it is, you’ll need to instead read from the `sources` array, and look up sources with a token’s `source.loc` filename manually. This change was because lint rules now run on all files in one pass, essentially.
@@ -22,6 +24,12 @@
22
24
 
23
25
  - [#606](https://github.com/terrazzoapp/terrazzo/pull/606) [`1fc1d99`](https://github.com/terrazzoapp/terrazzo/commit/1fc1d99e7156923e86e872e4750b7e28b6292b20) Thanks [@yuheiy](https://github.com/yuheiy)! - Allow partial utility CSS groups configuration
24
26
 
27
+ - [#632](https://github.com/terrazzoapp/terrazzo/pull/632) [`21c61d3`](https://github.com/terrazzoapp/terrazzo/commit/21c61d30c2cb137411deaec673d03cdc14445208) Thanks [@aduth](https://github.com/aduth)! - Fix `transform` option TypeScript type to allow `undefined` or `null` return values
28
+
29
+ - [#636](https://github.com/terrazzoapp/terrazzo/pull/636) Thanks [@geebru](https://github.com/geebru)! - Add missing CSS logical property directions for utility class generation
30
+
31
+ - Thanks [@drwpow](https://github.com/drwpow)! - Improve extended typography property CSS generation
32
+
25
33
  ## 0.10.4
26
34
 
27
35
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -1,8 +1,9 @@
1
- import { BuildHookOptions, Plugin, TokenNormalized, TokenTransformed } from "@terrazzo/parser";
1
+ import { BuildHookOptions, Logger, Plugin, TokenNormalized, TokenTransformed, TransformHookOptions } from "@terrazzo/parser";
2
2
 
3
3
  //#region src/lib.d.ts
4
4
  type UtilityCSSGroup = 'bg' | 'border' | 'font' | 'layout' | 'shadow' | 'text';
5
5
  type UtilityCSSPrefix = 'bg' | 'border' | 'font' | 'gap' | 'm' | 'p' | 'shadow' | 'text';
6
+ declare const PLUGIN_NAME = "@terrazzo/plugin-css";
6
7
  declare const FORMAT_ID = "css";
7
8
  declare const FILE_PREFIX = "/* -------------------------------------------\n * Autogenerated by \u26CB Terrazzo. DO NOT EDIT!\n * ------------------------------------------- */";
8
9
  interface CSSPluginOptions {
@@ -13,12 +14,33 @@ interface CSSPluginOptions {
13
14
  filename?: string;
14
15
  /** Glob patterns to exclude tokens from output */
15
16
  exclude?: string[];
16
- /** Define mode selectors as media queries or CSS classes */
17
+ /**
18
+ * Set the base selector, like ":root" or ":host".
19
+ * @deprecated use permutations instead.
20
+ * @default ":root"
21
+ */
22
+ baseSelector?: string;
23
+ /**
24
+ * Set the color-scheme CSS property for `baseSelector`.
25
+ * @deprecated use permutations instead.
26
+ * @see https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/color-scheme
27
+ * @example "light dark"
28
+ */
29
+ baseScheme?: string;
30
+ /**
31
+ * Build resolver contexts into media queries
32
+ */
33
+ permutations?: Permutation[];
34
+ /**
35
+ * Define mode selectors as media queries or CSS classes
36
+ * @deprecated Migrate to permutations
37
+ */
17
38
  modeSelectors?: ModeSelector[];
18
39
  /** Control the final CSS variable name */
19
40
  variableName?: (token: TokenNormalized) => string;
20
41
  /** Override certain token values */
21
- transform?: (token: TokenNormalized, mode: string) => TokenTransformed['value'];
42
+ transform?: (token: TokenNormalized, /** @deprecated */
43
+ mode?: string) => TokenTransformed['value'] | undefined | null;
22
44
  /** Generate utility CSS from groups */
23
45
  utility?: Partial<Record<UtilityCSSGroup, string[]>>;
24
46
  /**
@@ -31,15 +53,14 @@ interface CSSPluginOptions {
31
53
  * @default false
32
54
  */
33
55
  skipBuild?: boolean;
34
- /**
35
- * Set the base selector, like ":root" or ":host".
36
- * @default ":root"
37
- */
38
- baseSelector?: string;
39
- /**
40
- * Set the color-scheme CSS property for the base selector (e.g.: "light", "dark", "light dark")
41
- */
42
- baseScheme?: string;
56
+ }
57
+ interface Permutation<T extends Record<string, string> = Record<string, string>> {
58
+ /** Generate the final CSS string, wrapping content in the selector(s) of your choice. */
59
+ prepare(css: string): string;
60
+ /** Input for this permutation. */
61
+ input: T;
62
+ /** Provide token(s) to ignore (Note: ignoring tokens that are used as aliases for other tokens could cause visual bugs in generated CSS) */
63
+ ignore?: string[];
43
64
  }
44
65
  interface ModeSelector {
45
66
  /** The name of the mode to match */
@@ -51,34 +72,79 @@ interface ModeSelector {
51
72
  /** Set the color-scheme CSS property for this mode (e.g.: "light", "dark", "light dark") */
52
73
  scheme?: string;
53
74
  }
54
- interface CSSRuleDeclaration {
75
+ interface CSSDeclaration {
76
+ type: 'Declaration';
77
+ property: string;
55
78
  value: string;
56
- description?: string;
79
+ comment?: string;
57
80
  }
58
81
  interface CSSRule {
59
- selectors: string[];
60
- nestedQuery?: string;
61
- declarations: Record<string, CSSRuleDeclaration>;
62
- }
63
- /** Convert CSSRules into a formatted, indented CSS string */
64
- declare function printRules(rules: CSSRule[]): string;
65
- interface GetRuleOptions {
66
- /** Combine a selector with parent selectors (e.g. if adding a @media-query within another selector list) */
67
- parentSelectors?: string[];
82
+ type: 'Rule';
83
+ prelude: string[];
84
+ children: (CSSRule | CSSDeclaration)[];
68
85
  }
86
+ /**
87
+ * Convert CSSRules into a formatted, indented CSS string.
88
+ * The reason we’re using this homemade version instead of something like css-tree is:
89
+ *
90
+ * 1. css-tree doesn’t support comments :(
91
+ * 2. we are only generating PARTIALS, not full CSS (the user controls the
92
+ * wrapper). So with a proper AST, we’d be hacking it a little anyway because
93
+ * we never really have a true, valid, finalized document.
94
+ * 3. we want @terrazzo/plugin-css to run in the browser AND be lean (i.e. don’t
95
+ * load Prettier or 25MB of wasm).
96
+ * 4. we only have to deal with a small subset of CSS—this doesn’t have to be robust
97
+ * by any means (even future additions won’t push the limits of the spec).
98
+ */
99
+ declare function printRules(nodes: (CSSRule | CSSDeclaration)[], {
100
+ indentChar,
101
+ indentLv
102
+ }?: {
103
+ indentChar?: string;
104
+ indentLv?: number;
105
+ }): string;
106
+ /** Internal printer for individual nodes */
107
+ declare function printNode(node: CSSRule | CSSDeclaration, {
108
+ indentChar,
109
+ indentLv
110
+ }: {
111
+ indentChar: string;
112
+ indentLv: number;
113
+ }): string;
114
+ /** Infer indentation preferences from a user-defined wrapping method. */
115
+ declare function getIndentFromPrepare(prepare: (css: string) => string): {
116
+ indentChar: string;
117
+ indentLv: number;
118
+ };
119
+ /** Syntactic sugar over Rule boilerplate */
120
+ declare function rule(prelude: CSSRule['prelude'], children?: CSSRule['children']): CSSRule;
121
+ /** Syntactic sugar over Declaration boilerplate */
122
+ declare function decl(property: CSSDeclaration['property'], value: CSSDeclaration['value'], comment?: CSSDeclaration['comment']): CSSDeclaration;
123
+ /** Does a node list contain a root-level declaration with this property? */
124
+ declare function hasDecl(list: (CSSRule | CSSDeclaration)[], property: string): boolean;
125
+ /** Add a declaration only if it’s unique (note: CSS, by design, allows duplication—it’s how fallbacks happen. Only use this if fallbacks aren’t needed. */
126
+ declare function addDeclUnique(list: (CSSRule | CSSDeclaration)[], declaration: CSSDeclaration): void;
69
127
  //#endregion
70
- //#region src/build/index.d.ts
128
+ //#region src/build.d.ts
71
129
  interface BuildFormatOptions {
130
+ logger: Logger;
72
131
  exclude: CSSPluginOptions['exclude'];
73
132
  getTransforms: BuildHookOptions['getTransforms'];
74
133
  modeSelectors: CSSPluginOptions['modeSelectors'];
134
+ permutations: CSSPluginOptions['permutations'];
75
135
  utility: CSSPluginOptions['utility'];
76
136
  baseSelector: string;
77
137
  baseScheme: CSSPluginOptions['baseScheme'];
78
138
  }
79
139
  //#endregion
140
+ //#region src/transform.d.ts
141
+ interface TransformOptions {
142
+ transform: TransformHookOptions;
143
+ options: CSSPluginOptions;
144
+ }
145
+ //#endregion
80
146
  //#region src/index.d.ts
81
147
  declare function cssPlugin(options?: CSSPluginOptions): Plugin;
82
148
  //#endregion
83
- export { BuildFormatOptions, CSSPluginOptions, CSSRule, CSSRuleDeclaration, FILE_PREFIX, FORMAT_ID, GetRuleOptions, ModeSelector, UtilityCSSGroup, UtilityCSSPrefix, cssPlugin as default, printRules };
149
+ export { BuildFormatOptions, CSSDeclaration, CSSPluginOptions, CSSRule, FILE_PREFIX, FORMAT_ID, ModeSelector, PLUGIN_NAME, Permutation, TransformOptions, UtilityCSSGroup, UtilityCSSPrefix, addDeclUnique, decl, cssPlugin as default, getIndentFromPrepare, hasDecl, printNode, printRules, rule };
84
150
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/lib.ts","../src/build/index.ts","../src/index.ts"],"sourcesContent":[],"mappings":";;;KAEY,eAAA;KAEA,gBAAA;AAFA,cAIC,SAAA,GAJc,KAAA;AAEf,cAIC,WAAA,GAJe,uJAAA;AAEf,UAMI,gBAAA,CANK;EAET;AAIb;;;EAasB,QAAA,CAAA,EAAA,MAAA;EAAkC;EAE7B,OAAA,CAAA,EAAA,MAAA,EAAA;EAAP;EAAR,aAAA,CAAA,EANM,YAMN,EAAA;EAAO;EAsBF,YAAA,CAAA,EAAY,CAAA,KAAA,EA1BJ,eA0BI,EAAA,GAAA,MAAA;EAcZ;EAIA,SAAA,CAAO,EAAA,CAAA,KAAA,EA1CF,eA6CS,EAAA,IAAA,EAAf,MAAM,EAAA,GA7CkC,gBA6ClC,CAAA,OAAA,CAAA;EAIN;EAkEC,OAAA,CAAA,EAjHL,OAiHmB,CAjHX,MAiHW,CAjHJ,eAiHI,EAAA,MAAA,EAAA,CAAA,CAAA;;;;ACnI/B;EACW,SAAA,CAAA,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