@workday/canvas-kit-styling-transform 13.2.1 → 13.2.2

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 (216) hide show
  1. package/dist/commonjs/index.d.ts +14 -0
  2. package/dist/commonjs/index.d.ts.map +1 -0
  3. package/dist/commonjs/index.js +28 -0
  4. package/dist/commonjs/lib/createObjectTransform.d.ts +10 -0
  5. package/dist/commonjs/lib/createObjectTransform.d.ts.map +1 -0
  6. package/dist/commonjs/lib/createObjectTransform.js +14 -0
  7. package/dist/commonjs/lib/createPropertyTransform.d.ts +7 -0
  8. package/dist/commonjs/lib/createPropertyTransform.d.ts.map +1 -0
  9. package/dist/commonjs/lib/createPropertyTransform.js +11 -0
  10. package/dist/commonjs/lib/createTypeScriptWatchProgram.d.ts +16 -0
  11. package/dist/commonjs/lib/createTypeScriptWatchProgram.d.ts.map +1 -0
  12. package/dist/commonjs/lib/createTypeScriptWatchProgram.js +45 -0
  13. package/dist/commonjs/lib/styleTransform.d.ts +23 -0
  14. package/dist/commonjs/lib/styleTransform.d.ts.map +1 -0
  15. package/dist/commonjs/lib/styleTransform.js +131 -0
  16. package/dist/commonjs/lib/utils/createStyleObjectNode.d.ts +35 -0
  17. package/dist/commonjs/lib/utils/createStyleObjectNode.d.ts.map +1 -0
  18. package/dist/commonjs/lib/utils/createStyleObjectNode.js +84 -0
  19. package/dist/commonjs/lib/utils/getCssVariables.d.ts +4 -0
  20. package/dist/commonjs/lib/utils/getCssVariables.d.ts.map +1 -0
  21. package/dist/commonjs/lib/utils/getCssVariables.js +31 -0
  22. package/dist/commonjs/lib/utils/getErrorMessage.d.ts +16 -0
  23. package/dist/commonjs/lib/utils/getErrorMessage.d.ts.map +1 -0
  24. package/dist/commonjs/lib/utils/getErrorMessage.js +45 -0
  25. package/dist/commonjs/lib/utils/getFallbackVariable.d.ts +9 -0
  26. package/dist/commonjs/lib/utils/getFallbackVariable.d.ts.map +1 -0
  27. package/dist/commonjs/lib/utils/getFallbackVariable.js +30 -0
  28. package/dist/commonjs/lib/utils/getHash.d.ts +4 -0
  29. package/dist/commonjs/lib/utils/getHash.d.ts.map +1 -0
  30. package/dist/commonjs/lib/utils/getHash.js +16 -0
  31. package/dist/commonjs/lib/utils/getVarName.d.ts +17 -0
  32. package/dist/commonjs/lib/utils/getVarName.d.ts.map +1 -0
  33. package/dist/commonjs/lib/utils/getVarName.js +34 -0
  34. package/dist/commonjs/lib/utils/handleCalc.d.ts +2 -0
  35. package/dist/commonjs/lib/utils/handleCalc.d.ts.map +1 -0
  36. package/dist/commonjs/lib/utils/handleCalc.js +33 -0
  37. package/dist/commonjs/lib/utils/handleCreateStencil.d.ts +7 -0
  38. package/dist/commonjs/lib/utils/handleCreateStencil.d.ts.map +1 -0
  39. package/dist/commonjs/lib/utils/handleCreateStencil.js +309 -0
  40. package/dist/commonjs/lib/utils/handleCreateStyles.d.ts +3 -0
  41. package/dist/commonjs/lib/utils/handleCreateStyles.d.ts.map +1 -0
  42. package/dist/commonjs/lib/utils/handleCreateStyles.js +86 -0
  43. package/dist/commonjs/lib/utils/handleCreateVars.d.ts +3 -0
  44. package/dist/commonjs/lib/utils/handleCreateVars.d.ts.map +1 -0
  45. package/dist/commonjs/lib/utils/handleCreateVars.js +65 -0
  46. package/dist/commonjs/lib/utils/handleCssVar.d.ts +2 -0
  47. package/dist/commonjs/lib/utils/handleCssVar.d.ts.map +1 -0
  48. package/dist/commonjs/lib/utils/handleCssVar.js +19 -0
  49. package/dist/commonjs/lib/utils/handleInjectGlobal.d.ts +3 -0
  50. package/dist/commonjs/lib/utils/handleInjectGlobal.d.ts.map +1 -0
  51. package/dist/commonjs/lib/utils/handleInjectGlobal.js +40 -0
  52. package/dist/commonjs/lib/utils/handleKeyframes.d.ts +3 -0
  53. package/dist/commonjs/lib/utils/handleKeyframes.d.ts.map +1 -0
  54. package/dist/commonjs/lib/utils/handleKeyframes.js +48 -0
  55. package/dist/commonjs/lib/utils/handleParentModifier.d.ts +2 -0
  56. package/dist/commonjs/lib/utils/handleParentModifier.d.ts.map +1 -0
  57. package/dist/commonjs/lib/utils/handleParentModifier.js +26 -0
  58. package/dist/commonjs/lib/utils/handlePx2Rem.d.ts +2 -0
  59. package/dist/commonjs/lib/utils/handlePx2Rem.d.ts.map +1 -0
  60. package/dist/commonjs/lib/utils/handlePx2Rem.js +19 -0
  61. package/dist/commonjs/lib/utils/injectStyles.d.ts +3 -0
  62. package/dist/commonjs/lib/utils/injectStyles.d.ts.map +1 -0
  63. package/dist/commonjs/lib/utils/injectStyles.js +11 -0
  64. package/dist/commonjs/lib/utils/isImportedFromStyling.d.ts +7 -0
  65. package/dist/commonjs/lib/utils/isImportedFromStyling.d.ts.map +1 -0
  66. package/dist/commonjs/lib/utils/isImportedFromStyling.js +24 -0
  67. package/dist/commonjs/lib/utils/parseNodeToStaticValue.d.ts +11 -0
  68. package/dist/commonjs/lib/utils/parseNodeToStaticValue.d.ts.map +1 -0
  69. package/dist/commonjs/lib/utils/parseNodeToStaticValue.js +217 -0
  70. package/dist/commonjs/lib/utils/parseObjectToStaticValue.d.ts +15 -0
  71. package/dist/commonjs/lib/utils/parseObjectToStaticValue.d.ts.map +1 -0
  72. package/dist/commonjs/lib/utils/parseObjectToStaticValue.js +168 -0
  73. package/dist/commonjs/lib/utils/stylisFns.d.ts +3 -0
  74. package/dist/commonjs/lib/utils/stylisFns.d.ts.map +1 -0
  75. package/dist/commonjs/lib/utils/stylisFns.js +45 -0
  76. package/dist/commonjs/lib/utils/types.d.ts +210 -0
  77. package/dist/commonjs/lib/utils/types.d.ts.map +1 -0
  78. package/dist/commonjs/lib/utils/types.js +2 -0
  79. package/dist/commonjs/lib/webpack-loader.d.ts +7 -0
  80. package/dist/commonjs/lib/webpack-loader.d.ts.map +1 -0
  81. package/dist/commonjs/lib/webpack-loader.js +21 -0
  82. package/dist/commonjs/lib/webpackPlugin.d.ts +31 -0
  83. package/dist/commonjs/lib/webpackPlugin.d.ts.map +1 -0
  84. package/dist/commonjs/lib/webpackPlugin.js +38 -0
  85. package/dist/commonjs/spec/createProgramFromSource.d.ts +8 -0
  86. package/dist/commonjs/spec/createProgramFromSource.d.ts.map +1 -0
  87. package/dist/commonjs/spec/createProgramFromSource.js +111 -0
  88. package/dist/commonjs/spec/findNodes.d.ts +3 -0
  89. package/dist/commonjs/spec/findNodes.d.ts.map +1 -0
  90. package/dist/commonjs/spec/findNodes.js +33 -0
  91. package/dist/commonjs/testing.d.ts +4 -0
  92. package/dist/commonjs/testing.d.ts.map +1 -0
  93. package/dist/commonjs/testing.js +11 -0
  94. package/dist/es6/index.d.ts +14 -0
  95. package/dist/es6/index.d.ts.map +1 -0
  96. package/dist/es6/index.js +14 -0
  97. package/dist/es6/lib/createObjectTransform.d.ts +10 -0
  98. package/dist/es6/lib/createObjectTransform.d.ts.map +1 -0
  99. package/dist/es6/lib/createObjectTransform.js +10 -0
  100. package/dist/es6/lib/createPropertyTransform.d.ts +7 -0
  101. package/dist/es6/lib/createPropertyTransform.d.ts.map +1 -0
  102. package/dist/es6/lib/createPropertyTransform.js +7 -0
  103. package/dist/es6/lib/createTypeScriptWatchProgram.d.ts +16 -0
  104. package/dist/es6/lib/createTypeScriptWatchProgram.d.ts.map +1 -0
  105. package/dist/es6/lib/createTypeScriptWatchProgram.js +36 -0
  106. package/dist/es6/lib/styleTransform.d.ts +23 -0
  107. package/dist/es6/lib/styleTransform.d.ts.map +1 -0
  108. package/dist/es6/lib/styleTransform.js +120 -0
  109. package/dist/es6/lib/utils/createStyleObjectNode.d.ts +35 -0
  110. package/dist/es6/lib/utils/createStyleObjectNode.d.ts.map +1 -0
  111. package/dist/es6/lib/utils/createStyleObjectNode.js +74 -0
  112. package/dist/es6/lib/utils/getCssVariables.d.ts +4 -0
  113. package/dist/es6/lib/utils/getCssVariables.d.ts.map +1 -0
  114. package/dist/es6/lib/utils/getCssVariables.js +26 -0
  115. package/dist/es6/lib/utils/getErrorMessage.d.ts +16 -0
  116. package/dist/es6/lib/utils/getErrorMessage.d.ts.map +1 -0
  117. package/dist/es6/lib/utils/getErrorMessage.js +41 -0
  118. package/dist/es6/lib/utils/getFallbackVariable.d.ts +9 -0
  119. package/dist/es6/lib/utils/getFallbackVariable.d.ts.map +1 -0
  120. package/dist/es6/lib/utils/getFallbackVariable.js +26 -0
  121. package/dist/es6/lib/utils/getHash.d.ts +4 -0
  122. package/dist/es6/lib/utils/getHash.d.ts.map +1 -0
  123. package/dist/es6/lib/utils/getHash.js +9 -0
  124. package/dist/es6/lib/utils/getVarName.d.ts +17 -0
  125. package/dist/es6/lib/utils/getVarName.d.ts.map +1 -0
  126. package/dist/es6/lib/utils/getVarName.js +27 -0
  127. package/dist/es6/lib/utils/handleCalc.d.ts +2 -0
  128. package/dist/es6/lib/utils/handleCalc.d.ts.map +1 -0
  129. package/dist/es6/lib/utils/handleCalc.js +27 -0
  130. package/dist/es6/lib/utils/handleCreateStencil.d.ts +7 -0
  131. package/dist/es6/lib/utils/handleCreateStencil.d.ts.map +1 -0
  132. package/dist/es6/lib/utils/handleCreateStencil.js +301 -0
  133. package/dist/es6/lib/utils/handleCreateStyles.d.ts +3 -0
  134. package/dist/es6/lib/utils/handleCreateStyles.d.ts.map +1 -0
  135. package/dist/es6/lib/utils/handleCreateStyles.js +79 -0
  136. package/dist/es6/lib/utils/handleCreateVars.d.ts +3 -0
  137. package/dist/es6/lib/utils/handleCreateVars.d.ts.map +1 -0
  138. package/dist/es6/lib/utils/handleCreateVars.js +58 -0
  139. package/dist/es6/lib/utils/handleCssVar.d.ts +2 -0
  140. package/dist/es6/lib/utils/handleCssVar.d.ts.map +1 -0
  141. package/dist/es6/lib/utils/handleCssVar.js +13 -0
  142. package/dist/es6/lib/utils/handleInjectGlobal.d.ts +3 -0
  143. package/dist/es6/lib/utils/handleInjectGlobal.d.ts.map +1 -0
  144. package/dist/es6/lib/utils/handleInjectGlobal.js +33 -0
  145. package/dist/es6/lib/utils/handleKeyframes.d.ts +3 -0
  146. package/dist/es6/lib/utils/handleKeyframes.d.ts.map +1 -0
  147. package/dist/es6/lib/utils/handleKeyframes.js +41 -0
  148. package/dist/es6/lib/utils/handleParentModifier.d.ts +2 -0
  149. package/dist/es6/lib/utils/handleParentModifier.d.ts.map +1 -0
  150. package/dist/es6/lib/utils/handleParentModifier.js +20 -0
  151. package/dist/es6/lib/utils/handlePx2Rem.d.ts +2 -0
  152. package/dist/es6/lib/utils/handlePx2Rem.d.ts.map +1 -0
  153. package/dist/es6/lib/utils/handlePx2Rem.js +13 -0
  154. package/dist/es6/lib/utils/injectStyles.d.ts +3 -0
  155. package/dist/es6/lib/utils/injectStyles.d.ts.map +1 -0
  156. package/dist/es6/lib/utils/injectStyles.js +7 -0
  157. package/dist/es6/lib/utils/isImportedFromStyling.d.ts +7 -0
  158. package/dist/es6/lib/utils/isImportedFromStyling.d.ts.map +1 -0
  159. package/dist/es6/lib/utils/isImportedFromStyling.js +17 -0
  160. package/dist/es6/lib/utils/parseNodeToStaticValue.d.ts +11 -0
  161. package/dist/es6/lib/utils/parseNodeToStaticValue.d.ts.map +1 -0
  162. package/dist/es6/lib/utils/parseNodeToStaticValue.js +209 -0
  163. package/dist/es6/lib/utils/parseObjectToStaticValue.d.ts +15 -0
  164. package/dist/es6/lib/utils/parseObjectToStaticValue.d.ts.map +1 -0
  165. package/dist/es6/lib/utils/parseObjectToStaticValue.js +159 -0
  166. package/dist/es6/lib/utils/stylisFns.d.ts +3 -0
  167. package/dist/es6/lib/utils/stylisFns.d.ts.map +1 -0
  168. package/dist/es6/lib/utils/stylisFns.js +41 -0
  169. package/dist/es6/lib/utils/types.d.ts +210 -0
  170. package/dist/es6/lib/utils/types.d.ts.map +1 -0
  171. package/dist/es6/lib/utils/types.js +1 -0
  172. package/dist/es6/lib/webpack-loader.d.ts +7 -0
  173. package/dist/es6/lib/webpack-loader.d.ts.map +1 -0
  174. package/dist/es6/lib/webpack-loader.js +15 -0
  175. package/dist/es6/lib/webpackPlugin.d.ts +31 -0
  176. package/dist/es6/lib/webpackPlugin.d.ts.map +1 -0
  177. package/dist/es6/lib/webpackPlugin.js +31 -0
  178. package/dist/es6/spec/createProgramFromSource.d.ts +8 -0
  179. package/dist/es6/spec/createProgramFromSource.d.ts.map +1 -0
  180. package/dist/es6/spec/createProgramFromSource.js +81 -0
  181. package/dist/es6/spec/findNodes.d.ts +3 -0
  182. package/dist/es6/spec/findNodes.d.ts.map +1 -0
  183. package/dist/es6/spec/findNodes.js +26 -0
  184. package/dist/es6/testing.d.ts +4 -0
  185. package/dist/es6/testing.d.ts.map +1 -0
  186. package/dist/es6/testing.js +3 -0
  187. package/index.ts +19 -0
  188. package/lib/createObjectTransform.ts +12 -0
  189. package/lib/createPropertyTransform.ts +9 -0
  190. package/lib/createTypeScriptWatchProgram.ts +52 -0
  191. package/lib/styleTransform.ts +169 -0
  192. package/lib/utils/createStyleObjectNode.ts +105 -0
  193. package/lib/utils/getCssVariables.ts +36 -0
  194. package/lib/utils/getErrorMessage.ts +57 -0
  195. package/lib/utils/getFallbackVariable.ts +34 -0
  196. package/lib/utils/getHash.ts +13 -0
  197. package/lib/utils/getVarName.ts +32 -0
  198. package/lib/utils/handleCalc.ts +33 -0
  199. package/lib/utils/handleCreateStencil.ts +442 -0
  200. package/lib/utils/handleCreateStyles.ts +97 -0
  201. package/lib/utils/handleCreateVars.ts +90 -0
  202. package/lib/utils/handleCssVar.ts +19 -0
  203. package/lib/utils/handleInjectGlobal.ts +51 -0
  204. package/lib/utils/handleKeyframes.ts +60 -0
  205. package/lib/utils/handleParentModifier.ts +29 -0
  206. package/lib/utils/handlePx2Rem.ts +22 -0
  207. package/lib/utils/injectStyles.ts +14 -0
  208. package/lib/utils/isImportedFromStyling.ts +21 -0
  209. package/lib/utils/parseNodeToStaticValue.ts +281 -0
  210. package/lib/utils/parseObjectToStaticValue.ts +201 -0
  211. package/lib/utils/stylisFns.ts +56 -0
  212. package/lib/utils/types.ts +223 -0
  213. package/lib/webpack-loader.ts +28 -0
  214. package/lib/webpackPlugin.ts +69 -0
  215. package/package.json +19 -14
  216. package/index.js +0 -22
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.prettyStringify = void 0;
4
+ /* eslint-disable no-param-reassign */
5
+ /* eslint-disable no-fallthrough */
6
+ /* eslint-disable default-case */
7
+ const stylis_1 = require("stylis");
8
+ function strlen(input) {
9
+ return input.length;
10
+ }
11
+ const prettyStringify = (element, index, children, callback) => {
12
+ switch (element.type) {
13
+ case stylis_1.LAYER:
14
+ if (element.children.length) {
15
+ break;
16
+ }
17
+ case stylis_1.IMPORT:
18
+ case stylis_1.DECLARATION:
19
+ return (element.return =
20
+ element.return ||
21
+ ' ' + element.value.replace(':', ': ') + (index === children.length - 1 ? '' : '\n'));
22
+ case stylis_1.COMMENT:
23
+ return `${element.value}\n`;
24
+ case stylis_1.KEYFRAMES:
25
+ return ((element.return =
26
+ element.value +
27
+ ' {\n' +
28
+ (0, stylis_1.serialize)(element.children, callback)
29
+ .split('\n')
30
+ .map(i => ` ${i}`)
31
+ .join('\n') +
32
+ '}').replace(/\s\s\}$/, '}') + '\n');
33
+ case stylis_1.RULESET:
34
+ if (!strlen((element.value = element.props.join(', ')))) {
35
+ return '';
36
+ }
37
+ }
38
+ const childStr = (0, stylis_1.serialize)(element.children, callback);
39
+ if (childStr) {
40
+ element.return = `${element.value} {\n${childStr}\n}\n\n`;
41
+ return element.return;
42
+ }
43
+ return '';
44
+ };
45
+ exports.prettyStringify = prettyStringify;
@@ -0,0 +1,210 @@
1
+ import ts from 'typescript';
2
+ export type TransformerContext = {
3
+ checker: ts.TypeChecker;
4
+ prefix: string;
5
+ getPrefix: (path: string) => string;
6
+ /**
7
+ * Name and value pairs for things that cannot be statically resolved via the type system. The
8
+ * name is resolved via `getPropertyAccessExpressionText` and the value can be anything. It should
9
+ * be whatever you want the runtime value to be, which is usually a hash. For example:
10
+ *
11
+ * ```ts
12
+ * const myVars = createVars('color');
13
+ *
14
+ * color: myVars.color
15
+ * ```
16
+ *
17
+ * The type of `myVars.color` is `string`, but both in runtime and transpile time, the
18
+ * `myVars.color` is resolved to a hard value. The `names` cache is a lookup to that value. The
19
+ * `names` cache does not track the AST of `color`, so `const {color} = myVars` will not work. The
20
+ * key comes from `getPropertyAccessExpressionText` which replaces `.` with `-`.
21
+ */
22
+ names: Record<string, string>;
23
+ /**
24
+ * Extracted names is a mapping from `names` to a value that will be output to CSS. If you add an
25
+ * entry to `names`, add an entry to `extractedNames` where the `key` of `extractedNames` is the
26
+ * `value` of `names`.
27
+ *
28
+ * For example:
29
+ * ```ts
30
+ * // names
31
+ * { "myVars.foo": "--css-12345" },
32
+ * // extractedNames
33
+ * { "--css-12345": "--css-my-vars-foo" }
34
+ * ```
35
+ *
36
+ * The value in `names` will be used for transformation of TypeScript files into JavaScript files.
37
+ * The `extractedNames` will be used for the output CSS files.
38
+ */
39
+ extractedNames: Record<string, string>;
40
+ /**
41
+ * Variable scoping allows for a variable lookup to match a predefined scope. For example, in
42
+ * stencils, the `base` config can take a function with the locally defined variable names.
43
+ *
44
+ * ```ts
45
+ * const myStencil = createStencil({
46
+ * vars: {color: 'red'},
47
+ * base({color}) {
48
+ * return {
49
+ * [color]: 'blue'
50
+ * }
51
+ * }
52
+ * })
53
+ * ```
54
+ *
55
+ * In this case, a name lookup would fail because there's no global name named `color`. There's a
56
+ * global name named `my-color` which is the fully-qualified name. The stencil parser will add
57
+ * `my-` as a name scoping when processing style attributes for name lookup purposes.
58
+ */
59
+ nameScope?: string;
60
+ /**
61
+ * All styles will be collected here. These styles will then be flushed out to CSS files according
62
+ * to the `getFileName` function.
63
+ */
64
+ styles: StylesOutput;
65
+ /**
66
+ * The cache is for idempotent style inserts. Styles are hashed based on file name and position in
67
+ * the file.
68
+ */
69
+ cache: Record<string, string>;
70
+ getFileName: (path: string) => string;
71
+ objectTransforms: ObjectTransform[];
72
+ propertyTransforms: PropertyTransform[];
73
+ fileName: string;
74
+ transform: NodeTransformer;
75
+ extractCSS: boolean;
76
+ seed: string;
77
+ };
78
+ export type NestedStyleObject = {
79
+ [key: string]: number | string | NestedStyleObject;
80
+ };
81
+ /**
82
+ * Transformer function type. A transformer will be called by the TypeScript AST transformer visitor
83
+ * from the bottom of the tree to the top (inside-out/leaf first, root last). If a transformer knows
84
+ * how to handle the AST node, a node should be returned. Even if no transformation is desired,
85
+ * returning a node shortcuts processing. The visitor will call all NodeTransformers until a match
86
+ * is met.
87
+ */
88
+ export type NodeTransformer = (node: ts.Node, context: TransformerContext) => ts.Node | void;
89
+ /**
90
+ * Used to collect styles. The format will be:
91
+ *
92
+ * ```js
93
+ * {
94
+ * '/absolute/file/name': [
95
+ * '.styles-1 { ... }'
96
+ * ]
97
+ * }
98
+ * ```
99
+ */
100
+ export type StylesOutput = Record<string, string[]>;
101
+ export interface Config {
102
+ /**
103
+ * The prefix for all CSS class names and variables. This should be something short and
104
+ * distinguish your CSS class names from others on the page.
105
+ */
106
+ prefix?: string;
107
+ /**
108
+ * If you wish to automatically include CSS variable fallbacks, you can provide paths to CSS files
109
+ * that contain CSS variables. Fallbacks are useful if you expect your CSS to be loaded in an
110
+ * environment that might not include these CSS files. An example might be Storybook or other dev
111
+ * environments where you want your CSS to look good even in these environments. Fallbacks make
112
+ * bigger files because fallbacks are embedded.
113
+ *
114
+ * For example:
115
+ * ```ts
116
+ * const myComponent = createStyles({
117
+ * color: '--primary-color-100'
118
+ * })
119
+ * ```
120
+ *
121
+ * If you provide a fallback file that defines `--primary-color-100`, the fallback will be
122
+ * inlined:
123
+ * ```css
124
+ * // without
125
+ * .my-component{color:var(--primary-color-100);}
126
+ *
127
+ * // with fallback
128
+ * .my-component{color:var(--primary-color-100,#0000ff);}
129
+ * ```
130
+ *
131
+ * The benefit is your CSS will work even without the files that define all your global CSS
132
+ * variables.
133
+ */
134
+ fallbackFiles?: string[];
135
+ /**
136
+ * Optional additional transforms. A transform takes an AST node and optionally returns a new AST
137
+ * node. This is useful if your source files use custom utility functions. The style
138
+ * transformation process must receive static strings while reading your source files. The base
139
+ * transformers handle all style utilities provided by `@workday/canvas-kit-styling`, but you may
140
+ * use more. The transformer makes use of TypeScript's type checker to extract a static types out
141
+ * of variables, but will throw errors if it finds a generic type like `string` or `number`. If
142
+ * you get these errors and the error points to a function, maybe you need an additional
143
+ * transformer to understand the code. Some simple examples from `@workday/canvas-kit-styling` are
144
+ * `px2rem` and `calc.*`. Those have special handlers that are allowed to return new AST nodes
145
+ * that can be further processed. You can return `NumericLiteral`, `StringLiteral`, or
146
+ * `TemplateExpression` AST nodes. You can see `handlePx2Rem` and `handleCalc` transformers as
147
+ * examples as well as associated tests.
148
+ *
149
+ * Transforms are called using the visitor pattern. The order is innermost to outermost of the
150
+ * AST. This means if you have a special utility function used to return a style property, it will
151
+ * be called before the `createStyles` or `createStencils` is called.
152
+ *
153
+ * https://ts-ast-viewer.com/#code/MYewdgzgLgBAtgTwMIjgB3AUzLAvDYAJ0wEMpMBlKBAG0wgAoBvAKBhjRIBMuBLMAOYAuGAMxQACtz6CGAcgAeNOQEoWAXxVA
154
+ * ```ts
155
+ * const myComponent = createStyles({
156
+ * padding: getPadding('xl')
157
+ * })
158
+ * ```
159
+ *
160
+ * In this example, your transform will be called with `'xl'`, `getPadding`, the `padding`
161
+ * PropertyAssignment, `createStyles`, then variable declarations for `myComponent`. You must
162
+ * create your own filters for each AST node so you only transform the correct nodes. You can
163
+ * visit ts-ast-viewer.com to see the AST and types. You can also use the factory creator to
164
+ * return new AST.
165
+ */
166
+ additionalTransforms?: NodeTransformer[];
167
+ /**
168
+ * Should the CSS be statically extracted into CSS files? If `true`, CSS files will be created
169
+ * according to the `getFileName` configuration. If `getFileName` is not defined, a CSS file will
170
+ * be created with the same name as the source file with a `.css` extension.
171
+ */
172
+ extractCSS?: boolean;
173
+ /**
174
+ * This will be called every time a style or keyframe needs to be injected into extracted style
175
+ * files. By default, the file name will be the current file with the `.tsx` replaced with a
176
+ * `.css`. If you wish to move or combine styles into a file, provide a custom `getFileName`. You
177
+ * can return the same file path for multiple sources. If the same file is used (maybe always
178
+ * returning `index.css`), new styles will be appended to the end of the file.
179
+ */
180
+ getFileName?: (path: string) => string;
181
+ /**
182
+ * Object transforms take an AST node that represents a style object and turn it into a
183
+ * `NestedStyleObject` or return `void`. If an object transform returns an object, transformation
184
+ * parsing stops on that node. If `void` is returned, processing continues using
185
+ * `parseObjectToStaticValue`. These transforms are useful if you have custom utility functions
186
+ * that are not statically parsable by the static styling transformer.
187
+ */
188
+ objectTransforms?: ObjectTransform[];
189
+ /**
190
+ * Property transforms take an AST node that represents a style property value and turn it into a
191
+ * static string. The transform is static and will generate a CSS style string for injection
192
+ * directly into the browser (or CSS file). A string is the only valid return type. Returning
193
+ * `void` instructs the transform to move on to other transforms. Returning a string will
194
+ * short-circuit other property transforms or the default property transform.
195
+ */
196
+ propertyTransforms?: PropertyTransform[];
197
+ /**
198
+ * Optional function for getting a prefix given a file path. This is useful if you want to have a
199
+ * different prefix for each module in a monorepo.
200
+ */
201
+ getPrefix?: (path: string) => string;
202
+ /**
203
+ * Optional seed for the hash. This can be useful if you want each build to have a different hash.
204
+ * If you provide the same seed, the same hash will be generated for every style.
205
+ */
206
+ seed?: string;
207
+ }
208
+ export type ObjectTransform = (node: ts.Node, context: TransformerContext) => NestedStyleObject | void;
209
+ export type PropertyTransform = (node: ts.Node, context: TransformerContext) => string | void;
210
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../lib/utils/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,MAAM,MAAM,kBAAkB,GAAG;IAC/B,OAAO,EAAE,EAAE,CAAC,WAAW,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;IACpC;;;;;;;;;;;;;;;OAeG;IACH,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B;;;;;;;;;;;;;;;OAeG;IACH,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACvC;;;;;;;;;;;;;;;;;;OAkBG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,MAAM,EAAE,YAAY,CAAC;IACrB;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,WAAW,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;IACtC,gBAAgB,EAAE,eAAe,EAAE,CAAC;IACpC,kBAAkB,EAAE,iBAAiB,EAAE,CAAC;IACxC,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,eAAe,CAAC;IAC3B,UAAU,EAAE,OAAO,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,iBAAiB,CAAA;CAAC,CAAC;AAErF;;;;;;GAMG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,kBAAkB,KAAK,EAAE,CAAC,IAAI,GAAG,IAAI,CAAC;AAE7F;;;;;;;;;;GAUG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;AAEpD,MAAM,WAAW,MAAM;IACrB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACH,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACH,oBAAoB,CAAC,EAAE,eAAe,EAAE,CAAC;IAEzC;;;;OAIG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IAErB;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;IAEvC;;;;;;OAMG;IACH,gBAAgB,CAAC,EAAE,eAAe,EAAE,CAAC;IAErC;;;;;;OAMG;IACH,kBAAkB,CAAC,EAAE,iBAAiB,EAAE,CAAC;IAEzC;;;OAGG;IACH,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;IAErC;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,MAAM,eAAe,GAAG,CAC5B,IAAI,EAAE,EAAE,CAAC,IAAI,EACb,OAAO,EAAE,kBAAkB,KACxB,iBAAiB,GAAG,IAAI,CAAC;AAE9B,MAAM,MAAM,iBAAiB,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,kBAAkB,KAAK,MAAM,GAAG,IAAI,CAAC"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,7 @@
1
+ interface LoaderContext {
2
+ getOptions: () => ReturnType<import('./webpackPlugin').StylingWebpackPlugin['getLoaderOptions']>;
3
+ resourcePath: string;
4
+ }
5
+ export default function typescriptLoaderWithTransformers(this: LoaderContext, source: string): string;
6
+ export {};
7
+ //# sourceMappingURL=webpack-loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webpack-loader.d.ts","sourceRoot":"","sources":["../../../lib/webpack-loader.ts"],"names":[],"mappings":"AAEA,UAAU,aAAa;IACrB,UAAU,EAAE,MAAM,UAAU,CAAC,OAAO,iBAAiB,EAAE,oBAAoB,CAAC,kBAAkB,CAAC,CAAC,CAAC;IACjG,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,CAAC,OAAO,UAAU,gCAAgC,CAAC,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,UAoB3F"}
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const typescript_1 = __importDefault(require("typescript"));
7
+ function typescriptLoaderWithTransformers(source) {
8
+ const { builderProgram, transformers, postTransform } = this.getOptions();
9
+ const id = this.resourcePath;
10
+ const program = builderProgram.getProgram();
11
+ const sourceFile = program.getSourceFile(id);
12
+ if (!sourceFile) {
13
+ return source;
14
+ }
15
+ const printer = typescript_1.default.createPrinter(program.getCompilerOptions());
16
+ const transformed = printer.printFile(typescript_1.default
17
+ .transform(sourceFile, transformers, program.getCompilerOptions())
18
+ .transformed.find(s => s.fileName === id) || sourceFile);
19
+ return (postTransform === null || postTransform === void 0 ? void 0 : postTransform(transformed, id)) || transformed;
20
+ }
21
+ exports.default = typescriptLoaderWithTransformers;
@@ -0,0 +1,31 @@
1
+ import ts from 'typescript';
2
+ type Transformer = (program: ts.Program) => ts.TransformerFactory<ts.SourceFile>;
3
+ interface PluginConfig {
4
+ tsconfigPath: string;
5
+ /**
6
+ * Optional list of transformers. The default is running the styleTransformer. If you wish to run
7
+ * additional transformers, you can pass them in here.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * new StylingWebpackPlugin({
12
+ * tsconfigPath: './tsconfig.json',
13
+ * transformers: [styleTransformer, myTransformer],
14
+ * })
15
+ * ```
16
+ */
17
+ transformers?: (undefined | Transformer)[];
18
+ postTransform?: (code: string, id: string) => string | undefined;
19
+ }
20
+ export declare class StylingWebpackPlugin {
21
+ private compilerOptions;
22
+ builderProgram: ts.BuilderProgram;
23
+ transformers: ts.TransformerFactory<ts.SourceFile>[];
24
+ postTransform?: (code: string, id: string) => string | undefined;
25
+ close: () => void;
26
+ constructor(config: PluginConfig);
27
+ getLoaderOptions(): this;
28
+ apply(compiler: import('webpack').Compiler): void;
29
+ }
30
+ export {};
31
+ //# sourceMappingURL=webpackPlugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webpackPlugin.d.ts","sourceRoot":"","sources":["../../../lib/webpackPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAK5B,KAAK,WAAW,GAAG,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,KAAK,EAAE,CAAC,kBAAkB,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC;AAIjF,UAAU,YAAY;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB;;;;;;;;;;;OAWG;IACH,YAAY,CAAC,EAAE,CAAC,SAAS,GAAG,WAAW,CAAC,EAAE,CAAC;IAE3C,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;CAClE;AAED,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,eAAe,CAAqB;IACrC,cAAc,EAAG,EAAE,CAAC,cAAc,CAAC;IACnC,YAAY,EAAG,EAAE,CAAC,kBAAkB,CAAC,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC;IACtD,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;IACjE,KAAK,EAAE,MAAM,IAAI,CAAC;gBAEb,MAAM,EAAE,YAAY;IAoBhC,gBAAgB;IAIhB,KAAK,CAAC,QAAQ,EAAE,OAAO,SAAS,EAAE,QAAQ;CAS3C"}
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.StylingWebpackPlugin = void 0;
7
+ const createTypeScriptWatchProgram_1 = require("./createTypeScriptWatchProgram");
8
+ const styleTransform_1 = __importDefault(require("./styleTransform"));
9
+ const pluginName = 'StylingWebpackPlugin';
10
+ class StylingWebpackPlugin {
11
+ constructor(config) {
12
+ var _a;
13
+ const tsconfigPath = (_a = config.tsconfigPath) !== null && _a !== void 0 ? _a : './tsconfig.json';
14
+ this.compilerOptions = (0, createTypeScriptWatchProgram_1.getCompilerOptions)(tsconfigPath);
15
+ const [_builderProgram, close] = (0, createTypeScriptWatchProgram_1.startWatch)(this.compilerOptions, tsconfigPath, (builderProgram) => {
16
+ var _a;
17
+ this.builderProgram = builderProgram;
18
+ this.transformers = ((_a = config.transformers) !== null && _a !== void 0 ? _a : [styleTransform_1.default])
19
+ .filter(t => t !== undefined)
20
+ .map(t => t(this.builderProgram.getProgram()));
21
+ });
22
+ this.close = close;
23
+ this.postTransform = config.postTransform;
24
+ }
25
+ getLoaderOptions() {
26
+ return this;
27
+ }
28
+ apply(compiler) {
29
+ // We must close down the watch program when the compiler shuts down. This doesn't happen
30
+ // automatically when using the watch program and the watch will shut down from a SIGINT. When a
31
+ // webpack production build is initiated, the shutdown signifies the build is complete and we
32
+ // need to end the watch program.
33
+ compiler.hooks.shutdown.tap(pluginName, () => {
34
+ this.close();
35
+ });
36
+ }
37
+ }
38
+ exports.StylingWebpackPlugin = StylingWebpackPlugin;
@@ -0,0 +1,8 @@
1
+ import * as ts from 'typescript';
2
+ export declare function createProgramFromSource(source: string): ts.Program;
3
+ export declare function createProgramFromSource(filename: string, source: string): ts.Program;
4
+ export declare function createProgramFromSource(sources: {
5
+ filename: string;
6
+ source: string;
7
+ }[]): ts.Program;
8
+ //# sourceMappingURL=createProgramFromSource.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createProgramFromSource.d.ts","sourceRoot":"","sources":["../../../spec/createProgramFromSource.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAwCjC,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,MAAM,GAAG,EAAE,CAAC,OAAO,CAAC;AACpE,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,EAAE,CAAC,OAAO,CAAC;AACtF,wBAAgB,uBAAuB,CAAC,OAAO,EAAE;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAC,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC"}
@@ -0,0 +1,111 @@
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.createProgramFromSource = void 0;
30
+ const ts = __importStar(require("typescript"));
31
+ const path_1 = __importDefault(require("path"));
32
+ const common_tags_1 = require("common-tags");
33
+ function getConfig() {
34
+ const tsconfigPath = ts.findConfigFile('.', ts.sys.fileExists) || '';
35
+ const basePath = path_1.default.dirname(tsconfigPath);
36
+ const { config } = ts.readConfigFile(tsconfigPath, ts.sys.readFile);
37
+ const { options } = ts.parseJsonConfigFileContent(config, ts.sys, basePath, {}, tsconfigPath);
38
+ return options;
39
+ }
40
+ const styleSource = `
41
+ export type CsVarsMap<T extends string, ID extends string | never> = [ID] extends [never]
42
+ ? Record<T, string>
43
+ : {[K in T]: \`--\${ID}-\${K}\`};
44
+
45
+ export type CsVars<T extends string, ID extends string | never> = CsVarsMap<T, ID> & {
46
+ (input: Partial<Record<T, string>>): Record<T, string>;
47
+ };
48
+ export function createVars<T extends string, ID extends string>(input: {
49
+ id: ID;
50
+ args: T[];
51
+ }): CsVars<T, ID>;
52
+ export function createVars<T extends string>(...args: T[]): CsVars<T, never>;
53
+ export function createVars<T extends string, ID extends string>(...args: T[]): CsVars<T, ID>;
54
+ export function cssVar(input: string): string;
55
+ export function createStyles(...args: any[]): string;
56
+ `;
57
+ function getLocalFileName(sources, name) {
58
+ var _a;
59
+ return (_a = sources.find(file => file.filename === name.replace(path_1.default.resolve(__dirname, '../../..') + '/', ''))) === null || _a === void 0 ? void 0 : _a.filename;
60
+ }
61
+ function createProgramFromSource(...args) {
62
+ let sources;
63
+ if (args.length === 2) {
64
+ sources = [{ filename: args[0], source: args[1] }];
65
+ }
66
+ else if (typeof args[0] === 'string') {
67
+ sources = [{ filename: 'test.ts', source: args[0] }];
68
+ }
69
+ else {
70
+ sources = args[0];
71
+ }
72
+ const sourceFiles = sources.map(({ filename, source }) => {
73
+ return ts.createSourceFile(filename, (0, common_tags_1.stripIndent)(source), ts.ScriptTarget.Latest);
74
+ });
75
+ sourceFiles.push(ts.createSourceFile('node_modules/@workday/canvas-kit-styling/index.ts', styleSource, ts.ScriptTarget.Latest));
76
+ const config = getConfig();
77
+ const customCompilerHost = {
78
+ getSourceFile: (name, languageVersion) => {
79
+ // Get the file from our mock list, but read source lib files
80
+ const mockedFile = sourceFiles.find(s => s.fileName === getLocalFileName(sources, name));
81
+ if (mockedFile) {
82
+ return mockedFile;
83
+ }
84
+ if (name.startsWith('lib')) {
85
+ return ts.createSourceFile(name, ts.sys.readFile(`node_modules/typescript/lib/${name}`), languageVersion);
86
+ }
87
+ const fileContents = ts.sys.readFile(name);
88
+ if (fileContents) {
89
+ return ts.createSourceFile(name, fileContents, languageVersion);
90
+ }
91
+ return undefined;
92
+ },
93
+ // eslint-disable-next-line no-empty-function
94
+ writeFile: () => { },
95
+ getDefaultLibFileName: () => 'lib.d.ts',
96
+ useCaseSensitiveFileNames: () => ts.sys.useCaseSensitiveFileNames,
97
+ getCanonicalFileName: fileName => ts.sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase(),
98
+ getCurrentDirectory: () => ts.sys.getCurrentDirectory(),
99
+ getNewLine: () => ts.sys.newLine,
100
+ getDirectories: path => ts.sys.getDirectories(path),
101
+ // This should be kept up to date with getSourceFile()
102
+ fileExists: fileName => {
103
+ return (sourceFiles.some(s => s.fileName === getLocalFileName(sources, fileName)) ||
104
+ ts.sys.fileExists(fileName));
105
+ },
106
+ readFile: fileName => ts.sys.readFile(fileName),
107
+ };
108
+ const program = ts.createProgram(sources.map(s => s.filename), config, customCompilerHost);
109
+ return program;
110
+ }
111
+ exports.createProgramFromSource = createProgramFromSource;
@@ -0,0 +1,3 @@
1
+ import ts from 'typescript';
2
+ export declare function findNodes<N extends (node: ts.Node) => boolean>(node: ts.Node, name?: string, predicate?: N): (N extends (node: any) => node is infer S ? S[] : ts.Node[]) | undefined;
3
+ //# sourceMappingURL=findNodes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"findNodes.d.ts","sourceRoot":"","sources":["../../../spec/findNodes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAU5B,wBAAgB,SAAS,CAAC,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,OAAO,EAC5D,IAAI,EAAE,EAAE,CAAC,IAAI,EACb,IAAI,GAAE,MAAW,EACjB,SAAS,CAAC,EAAE,CAAC,GACZ,CAAC,CAAC,SAAS,CAAC,IAAI,EAAE,GAAG,KAAK,IAAI,IAAI,MAAM,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,SAAS,CAoB1E"}
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.findNodes = void 0;
7
+ const typescript_1 = __importDefault(require("typescript"));
8
+ function matchesName(node, name) {
9
+ var _a, _b;
10
+ return ((typescript_1.default.isIdentifier(node) && node.text === name) ||
11
+ ((_a = node === null || node === void 0 ? void 0 : node.name) === null || _a === void 0 ? void 0 : _a.text) === name || // declarations
12
+ ((_b = node === null || node === void 0 ? void 0 : node.expression) === null || _b === void 0 ? void 0 : _b.text) // expressions
13
+ );
14
+ }
15
+ function findNodes(node, name = '', predicate) {
16
+ const nodes = [];
17
+ if (!node) {
18
+ return nodes;
19
+ }
20
+ if ((predicate ? predicate(node) : true) && (name ? matchesName(node, name) : true)) {
21
+ nodes.push(node);
22
+ }
23
+ node.forEachChild(child => {
24
+ // The AST doesn't have parent nodes, but they are required for testing purposes.
25
+ child.parent = node;
26
+ const childNodes = findNodes(child, name, predicate);
27
+ if (childNodes) {
28
+ nodes.push(...childNodes);
29
+ }
30
+ });
31
+ return nodes;
32
+ }
33
+ exports.findNodes = findNodes;
@@ -0,0 +1,4 @@
1
+ export { createProgramFromSource } from './spec/createProgramFromSource';
2
+ export { transform, _reset, withDefaultContext } from './lib/styleTransform';
3
+ export { findNodes } from './spec/findNodes';
4
+ //# sourceMappingURL=testing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../../testing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,uBAAuB,EAAC,MAAM,gCAAgC,CAAC;AACvE,OAAO,EAAC,SAAS,EAAE,MAAM,EAAE,kBAAkB,EAAC,MAAM,sBAAsB,CAAC;AAC3E,OAAO,EAAC,SAAS,EAAC,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.findNodes = exports.withDefaultContext = exports._reset = exports.transform = exports.createProgramFromSource = void 0;
4
+ var createProgramFromSource_1 = require("./spec/createProgramFromSource");
5
+ Object.defineProperty(exports, "createProgramFromSource", { enumerable: true, get: function () { return createProgramFromSource_1.createProgramFromSource; } });
6
+ var styleTransform_1 = require("./lib/styleTransform");
7
+ Object.defineProperty(exports, "transform", { enumerable: true, get: function () { return styleTransform_1.transform; } });
8
+ Object.defineProperty(exports, "_reset", { enumerable: true, get: function () { return styleTransform_1._reset; } });
9
+ Object.defineProperty(exports, "withDefaultContext", { enumerable: true, get: function () { return styleTransform_1.withDefaultContext; } });
10
+ var findNodes_1 = require("./spec/findNodes");
11
+ Object.defineProperty(exports, "findNodes", { enumerable: true, get: function () { return findNodes_1.findNodes; } });
@@ -0,0 +1,14 @@
1
+ import styleTransformer from './lib/styleTransform';
2
+ import type { Config } from './lib/utils/types';
3
+ export type * from './lib/utils/types';
4
+ export { parseNodeToStaticValue } from './lib/utils/parseNodeToStaticValue';
5
+ export { parseObjectToStaticValue } from './lib/utils/parseObjectToStaticValue';
6
+ export { createObjectTransform } from './lib/createObjectTransform';
7
+ export { createPropertyTransform } from './lib/createPropertyTransform';
8
+ export { styleTransformer };
9
+ export { withDefaultContext } from './lib/styleTransform';
10
+ export { getClassName } from './lib/utils/handleCreateStencil';
11
+ export { StylingWebpackPlugin } from './lib/webpackPlugin';
12
+ export default styleTransformer;
13
+ export declare function createConfig(config: Config): Config;
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../index.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,MAAM,sBAAsB,CAAC;AACpD,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,mBAAmB,CAAC;AAE9C,mBAAmB,mBAAmB,CAAC;AACvC,OAAO,EAAC,sBAAsB,EAAC,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAC,wBAAwB,EAAC,MAAM,sCAAsC,CAAC;AAC9E,OAAO,EAAC,qBAAqB,EAAC,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAC,uBAAuB,EAAC,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAC,gBAAgB,EAAC,CAAC;AAC1B,OAAO,EAAC,kBAAkB,EAAC,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAC,YAAY,EAAC,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EAAC,oBAAoB,EAAC,MAAM,qBAAqB,CAAC;AAGzD,eAAe,gBAAgB,CAAC;AAEhC,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEnD"}
@@ -0,0 +1,14 @@
1
+ import styleTransformer from './lib/styleTransform';
2
+ export { parseNodeToStaticValue } from './lib/utils/parseNodeToStaticValue';
3
+ export { parseObjectToStaticValue } from './lib/utils/parseObjectToStaticValue';
4
+ export { createObjectTransform } from './lib/createObjectTransform';
5
+ export { createPropertyTransform } from './lib/createPropertyTransform';
6
+ export { styleTransformer };
7
+ export { withDefaultContext } from './lib/styleTransform';
8
+ export { getClassName } from './lib/utils/handleCreateStencil';
9
+ export { StylingWebpackPlugin } from './lib/webpackPlugin';
10
+ // be compatible with ts-patch which expects a default export
11
+ export default styleTransformer;
12
+ export function createConfig(config) {
13
+ return config;
14
+ }
@@ -0,0 +1,10 @@
1
+ import { ObjectTransform } from './utils/types';
2
+ /**
3
+ * Object transforms take an AST node that represents a style object and turn it into a
4
+ * `NestedStyleObject` or return `void`. If an object transform returns an object, transformation
5
+ * parsing stops on that node. If `void` is returned, processing continues using
6
+ * `parseObjectToStaticValue`. These transforms are useful if you have custom utility functions
7
+ * that are not statically parsable by the static styling transformer.
8
+ */
9
+ export declare function createObjectTransform(transformFn: ObjectTransform): ObjectTransform;
10
+ //# sourceMappingURL=createObjectTransform.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createObjectTransform.d.ts","sourceRoot":"","sources":["../../../lib/createObjectTransform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAC,MAAM,eAAe,CAAC;AAE9C;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,WAAW,EAAE,eAAe,GAAG,eAAe,CAEnF"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Object transforms take an AST node that represents a style object and turn it into a
3
+ * `NestedStyleObject` or return `void`. If an object transform returns an object, transformation
4
+ * parsing stops on that node. If `void` is returned, processing continues using
5
+ * `parseObjectToStaticValue`. These transforms are useful if you have custom utility functions
6
+ * that are not statically parsable by the static styling transformer.
7
+ */
8
+ export function createObjectTransform(transformFn) {
9
+ return transformFn;
10
+ }
@@ -0,0 +1,7 @@
1
+ import { PropertyTransform } from './utils/types';
2
+ /**
3
+ * A property transform takes a style property node and will return a string. You can use
4
+ * `parseNodeToStaticValue` to help you process properties that might be inputs to a function.
5
+ */
6
+ export declare function createPropertyTransform(transformFn: PropertyTransform): PropertyTransform;
7
+ //# sourceMappingURL=createPropertyTransform.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createPropertyTransform.d.ts","sourceRoot":"","sources":["../../../lib/createPropertyTransform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,iBAAiB,EAAC,MAAM,eAAe,CAAC;AAEhD;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,WAAW,EAAE,iBAAiB,GAAG,iBAAiB,CAEzF"}