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

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,40 @@
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.handleInjectGlobal = void 0;
7
+ const typescript_1 = __importDefault(require("typescript"));
8
+ const isImportedFromStyling_1 = require("./isImportedFromStyling");
9
+ const parseObjectToStaticValue_1 = require("./parseObjectToStaticValue");
10
+ const createStyleObjectNode_1 = require("./createStyleObjectNode");
11
+ const parseNodeToStaticValue_1 = require("./parseNodeToStaticValue");
12
+ const handleInjectGlobal = (node, context) => {
13
+ const { checker } = context;
14
+ if (typescript_1.default.isTaggedTemplateExpression(node) &&
15
+ typescript_1.default.isIdentifier(node.tag) &&
16
+ node.tag.text === 'injectGlobal' &&
17
+ (0, isImportedFromStyling_1.isImportedFromStyling)(node.tag, checker)) {
18
+ const styleObj = (0, parseNodeToStaticValue_1.parseNodeToStaticValue)(node.template, context).toString();
19
+ return typescript_1.default.factory.createCallExpression(node.tag, undefined, [
20
+ createStyleReplacementNode(node, styleObj, context),
21
+ ]);
22
+ }
23
+ if (typescript_1.default.isCallExpression(node) &&
24
+ typescript_1.default.isIdentifier(node.expression) &&
25
+ node.expression.text === 'injectGlobal' &&
26
+ (0, isImportedFromStyling_1.isImportedFromStyling)(node.expression, checker)) {
27
+ if (typescript_1.default.isObjectLiteralExpression(node.arguments[0])) {
28
+ const styleObj = (0, parseObjectToStaticValue_1.parseObjectToStaticValue)(node.arguments[0], context);
29
+ return typescript_1.default.factory.updateCallExpression(node, node.expression, undefined, [
30
+ createStyleReplacementNode(node, styleObj, context),
31
+ ]);
32
+ }
33
+ }
34
+ return;
35
+ };
36
+ exports.handleInjectGlobal = handleInjectGlobal;
37
+ function createStyleReplacementNode(node, styleObj, context) {
38
+ const serialized = (0, createStyleObjectNode_1.serializeStyles)(node, styleObj, '%s', context);
39
+ return (0, createStyleObjectNode_1.createStyleObjectNode)(serialized.styles, serialized.name);
40
+ }
@@ -0,0 +1,3 @@
1
+ import { NodeTransformer } from './types';
2
+ export declare const handleKeyframes: NodeTransformer;
3
+ //# sourceMappingURL=handleKeyframes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handleKeyframes.d.ts","sourceRoot":"","sources":["../../../../lib/utils/handleKeyframes.ts"],"names":[],"mappings":"AAEA,OAAO,EAAoB,eAAe,EAAqB,MAAM,SAAS,CAAC;AAO/E,eAAO,MAAM,eAAe,EAAE,eAoC7B,CAAC"}
@@ -0,0 +1,48 @@
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.handleKeyframes = void 0;
7
+ const typescript_1 = __importDefault(require("typescript"));
8
+ const parseNodeToStaticValue_1 = require("./parseNodeToStaticValue");
9
+ const getVarName_1 = require("./getVarName");
10
+ const createStyleObjectNode_1 = require("./createStyleObjectNode");
11
+ const isImportedFromStyling_1 = require("./isImportedFromStyling");
12
+ const parseObjectToStaticValue_1 = require("./parseObjectToStaticValue");
13
+ const handleKeyframes = (node, context) => {
14
+ const { checker } = context;
15
+ // keyframes`css`
16
+ if (typescript_1.default.isTaggedTemplateExpression(node) &&
17
+ typescript_1.default.isIdentifier(node.tag) &&
18
+ node.tag.text === 'keyframes' &&
19
+ (0, isImportedFromStyling_1.isImportedFromStyling)(node.tag, checker)) {
20
+ // parseNodeToStaticValue can parse templates. Pass it through there to get a single static string
21
+ const styleObj = (0, parseNodeToStaticValue_1.parseNodeToStaticValue)(node.template, context).toString();
22
+ const identifierName = (0, getVarName_1.getVarName)(node);
23
+ return typescript_1.default.factory.createCallExpression(node.tag, undefined, [
24
+ createStyleReplacementNode(node, styleObj, identifierName, context),
25
+ ]);
26
+ }
27
+ // keyframes({})
28
+ if (typescript_1.default.isCallExpression(node) &&
29
+ typescript_1.default.isIdentifier(node.expression) &&
30
+ node.expression.text === 'keyframes' &&
31
+ (0, isImportedFromStyling_1.isImportedFromStyling)(node.expression, checker)) {
32
+ if (typescript_1.default.isObjectLiteralExpression(node.arguments[0])) {
33
+ const styleObj = (0, parseObjectToStaticValue_1.parseObjectToStaticValue)(node.arguments[0], context);
34
+ const identifierName = (0, getVarName_1.getVarName)(node);
35
+ return typescript_1.default.factory.updateCallExpression(node, node.expression, undefined, [
36
+ createStyleReplacementNode(node, styleObj, identifierName, context),
37
+ ]);
38
+ }
39
+ }
40
+ return;
41
+ };
42
+ exports.handleKeyframes = handleKeyframes;
43
+ function createStyleReplacementNode(node, styleObj, identifierName, context) {
44
+ const serialized = (0, createStyleObjectNode_1.serializeStyles)(node, styleObj, `@keyframes animation-%n{%s}`, context);
45
+ const animationName = `animation-${serialized.name}`;
46
+ context.names[identifierName] = animationName;
47
+ return (0, createStyleObjectNode_1.createStyleObjectNode)(serialized.styles, serialized.name);
48
+ }
@@ -0,0 +1,2 @@
1
+ export declare const handleParentModifier: import("./types").PropertyTransform;
2
+ //# sourceMappingURL=handleParentModifier.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handleParentModifier.d.ts","sourceRoot":"","sources":["../../../../lib/utils/handleParentModifier.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,oBAAoB,qCAsB/B,CAAC"}
@@ -0,0 +1,26 @@
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.handleParentModifier = void 0;
7
+ const typescript_1 = __importDefault(require("typescript"));
8
+ const canvas_kit_styling_1 = require("@workday/canvas-kit-styling");
9
+ const createPropertyTransform_1 = require("../createPropertyTransform");
10
+ const parseNodeToStaticValue_1 = require("./parseNodeToStaticValue");
11
+ exports.handleParentModifier = (0, createPropertyTransform_1.createPropertyTransform)((node, context) => {
12
+ const { names, extractedNames } = context;
13
+ if (typescript_1.default.isComputedPropertyName(node) &&
14
+ typescript_1.default.isCallExpression(node.expression) &&
15
+ typescript_1.default.isIdentifier(node.expression.expression) &&
16
+ node.expression.expression.text === 'parentModifier') {
17
+ const args = node.expression.arguments.map(arg => (0, parseNodeToStaticValue_1.parseNodeToStaticValue)(arg, context));
18
+ const hash = args[0].toString().replace('css-', 'm');
19
+ // add a mapping from `css-{hash}` to `{hash}` for extraction string replacement
20
+ names[args[0]] = hash;
21
+ // map the `{hash}` to the extracted CSS class name
22
+ extractedNames[hash] = extractedNames[args[0]];
23
+ return (0, canvas_kit_styling_1.parentModifier)(args[0].toString());
24
+ }
25
+ return;
26
+ });
@@ -0,0 +1,2 @@
1
+ export declare const handlePx2Rem: import("./types").PropertyTransform;
2
+ //# sourceMappingURL=handlePx2Rem.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handlePx2Rem.d.ts","sourceRoot":"","sources":["../../../../lib/utils/handlePx2Rem.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,YAAY,qCAevB,CAAC"}
@@ -0,0 +1,19 @@
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.handlePx2Rem = void 0;
7
+ const typescript_1 = __importDefault(require("typescript"));
8
+ const canvas_kit_styling_1 = require("@workday/canvas-kit-styling");
9
+ const createPropertyTransform_1 = require("../createPropertyTransform");
10
+ const parseNodeToStaticValue_1 = require("./parseNodeToStaticValue");
11
+ exports.handlePx2Rem = (0, createPropertyTransform_1.createPropertyTransform)((node, context) => {
12
+ if (typescript_1.default.isCallExpression(node) &&
13
+ typescript_1.default.isIdentifier(node.expression) &&
14
+ node.expression.text === 'px2rem') {
15
+ const args = node.arguments.map(arg => (0, parseNodeToStaticValue_1.parseNodeToStaticValue)(arg, context));
16
+ return (0, canvas_kit_styling_1.px2rem)(parseFloat(args[0]), args[1] ? parseFloat(args[1]) : undefined);
17
+ }
18
+ return;
19
+ });
@@ -0,0 +1,3 @@
1
+ import { TransformerContext } from './types';
2
+ export declare function injectStyles({ styles, cache }: TransformerContext, fileName: string, hash: string, styleOutput: string): void;
3
+ //# sourceMappingURL=injectStyles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"injectStyles.d.ts","sourceRoot":"","sources":["../../../../lib/utils/injectStyles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,kBAAkB,EAAC,MAAM,SAAS,CAAC;AAE3C,wBAAgB,YAAY,CAC1B,EAAC,MAAM,EAAE,KAAK,EAAC,EAAE,kBAAkB,EACnC,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,QAOpB"}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.injectStyles = void 0;
4
+ function injectStyles({ styles, cache }, fileName, hash, styleOutput) {
5
+ if (!cache[hash]) {
6
+ styles[fileName] = styles[fileName] || [];
7
+ styles[fileName].push(styleOutput);
8
+ cache[hash] = styleOutput;
9
+ }
10
+ }
11
+ exports.injectStyles = injectStyles;
@@ -0,0 +1,7 @@
1
+ import ts from 'typescript';
2
+ /**
3
+ * Checks if the node was imported from '@workday/canvas-kit-styling'. This is useful if you want to
4
+ * limit transformation to only styling imports.
5
+ */
6
+ export declare function isImportedFromStyling(node: ts.Node, checker: ts.TypeChecker): boolean;
7
+ //# sourceMappingURL=isImportedFromStyling.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isImportedFromStyling.d.ts","sourceRoot":"","sources":["../../../../lib/utils/isImportedFromStyling.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,CAAC,WAAW,WAc3E"}
@@ -0,0 +1,24 @@
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.isImportedFromStyling = void 0;
7
+ const typescript_1 = __importDefault(require("typescript"));
8
+ /**
9
+ * Checks if the node was imported from '@workday/canvas-kit-styling'. This is useful if you want to
10
+ * limit transformation to only styling imports.
11
+ */
12
+ function isImportedFromStyling(node, checker) {
13
+ var _a;
14
+ const symbol = checker.getSymbolAtLocation(node);
15
+ const declaration = (symbol === null || symbol === void 0 ? void 0 : symbol.valueDeclaration) || ((_a = symbol === null || symbol === void 0 ? void 0 : symbol.declarations) === null || _a === void 0 ? void 0 : _a[0]);
16
+ if (declaration &&
17
+ typescript_1.default.isImportSpecifier(declaration) &&
18
+ typescript_1.default.isStringLiteral(declaration.parent.parent.parent.moduleSpecifier) &&
19
+ declaration.parent.parent.parent.moduleSpecifier.text === '@workday/canvas-kit-styling') {
20
+ return true;
21
+ }
22
+ return false;
23
+ }
24
+ exports.isImportedFromStyling = isImportedFromStyling;
@@ -0,0 +1,11 @@
1
+ import ts from 'typescript';
2
+ import { TransformerContext } from './types';
3
+ /**
4
+ * This is the workhorse of statically analyzing style values
5
+ */
6
+ export declare function parseNodeToStaticValue(node: ts.Node, context: TransformerContext): string | number;
7
+ /**
8
+ * Get a value from an aliased symbol, if it exists. An aliased symbol comes from
9
+ */
10
+ export declare function getValueFromAliasedSymbol(node: ts.Node, varName: string, context: TransformerContext): string | void;
11
+ //# sourceMappingURL=parseNodeToStaticValue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseNodeToStaticValue.d.ts","sourceRoot":"","sources":["../../../../lib/utils/parseNodeToStaticValue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAG5B,OAAO,EAAC,kBAAkB,EAAC,MAAM,SAAS,CAAC;AAQ3C;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,EAAE,CAAC,IAAI,EACb,OAAO,EAAE,kBAAkB,GAC1B,MAAM,GAAG,MAAM,CAyIjB;AA4DD;;GAEG;AACH,wBAAgB,yBAAyB,CACvC,IAAI,EAAE,EAAE,CAAC,IAAI,EACb,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,kBAAkB,GAC1B,MAAM,GAAG,IAAI,CA2Cf"}
@@ -0,0 +1,217 @@
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.getValueFromAliasedSymbol = exports.parseNodeToStaticValue = void 0;
7
+ const typescript_1 = __importDefault(require("typescript"));
8
+ const getErrorMessage_1 = require("./getErrorMessage");
9
+ function handlePropertyTransforms(node, context) {
10
+ return context.propertyTransforms.reduce((result, transformer) => {
11
+ return result || transformer(node, context) || undefined;
12
+ }, undefined);
13
+ }
14
+ /**
15
+ * This is the workhorse of statically analyzing style values
16
+ */
17
+ function parseNodeToStaticValue(node, context) {
18
+ const { checker } = context;
19
+ const value = handlePropertyTransforms(node, context);
20
+ if (value) {
21
+ return value;
22
+ }
23
+ /**
24
+ * String literals like 'red' or empty Template Expressions like `red`
25
+ */
26
+ if (typescript_1.default.isStringLiteral(node) || typescript_1.default.isNoSubstitutionTemplateLiteral(node)) {
27
+ return node.text;
28
+ }
29
+ // 12
30
+ if (typescript_1.default.isNumericLiteral(node)) {
31
+ return parseFloat(node.text);
32
+ }
33
+ // -12
34
+ if (typescript_1.default.isPrefixUnaryExpression(node) &&
35
+ node.operator === typescript_1.default.SyntaxKind.MinusToken &&
36
+ typescript_1.default.isNumericLiteral(node.operand)) {
37
+ return -parseFloat(node.operand.text);
38
+ }
39
+ // undefined
40
+ if (typescript_1.default.isIdentifier(node) && node.text === 'undefined') {
41
+ return 'undefined';
42
+ }
43
+ // a.b
44
+ if (typescript_1.default.isPropertyAccessExpression(node)) {
45
+ getPropertyAccessExpressionText(node);
46
+ const varName = getPropertyAccessExpressionText(node);
47
+ const value = getValueFromProcessedNodes(varName, context) ||
48
+ getValueFromAliasedSymbol(node, varName, context);
49
+ if (value) {
50
+ return value;
51
+ }
52
+ }
53
+ if (typescript_1.default.isComputedPropertyName(node) && typescript_1.default.isIdentifier(node.expression)) {
54
+ const varName = node.expression.text;
55
+ const value = getValueFromProcessedNodes(varName, context) ||
56
+ getValueFromAliasedSymbol(node, varName, context);
57
+ if (value) {
58
+ return value;
59
+ }
60
+ }
61
+ // [a.b]
62
+ if (typescript_1.default.isComputedPropertyName(node) && typescript_1.default.isPropertyAccessExpression(node.expression)) {
63
+ const varName = getPropertyAccessExpressionText(node.expression);
64
+ const value = getValueFromProcessedNodes(varName, context) ||
65
+ getValueFromAliasedSymbol(node, varName, context);
66
+ if (value) {
67
+ return value;
68
+ }
69
+ }
70
+ // [`${a.b} &`]
71
+ if (typescript_1.default.isComputedPropertyName(node) && typescript_1.default.isTemplateExpression(node.expression)) {
72
+ return getStyleValueFromTemplateExpression(node.expression, context);
73
+ }
74
+ /**
75
+ * ```ts
76
+ * `border 1px ${myVars.colors.border}`
77
+ * ```
78
+ */
79
+ if (typescript_1.default.isTemplateExpression(node)) {
80
+ return getStyleValueFromTemplateExpression(node, context);
81
+ }
82
+ /**
83
+ * An Identifier is a simple variable. It may represent a variable, so we'll check it before
84
+ * moving on. This typically happens in stencils.
85
+ */
86
+ if (typescript_1.default.isIdentifier(node)) {
87
+ const value = getValueFromProcessedNodes(node.text, context) ||
88
+ getValueFromAliasedSymbol(node, node.text, context);
89
+ if (value) {
90
+ return value;
91
+ }
92
+ }
93
+ if (typescript_1.default.isElementAccessExpression(node)) {
94
+ const value = parseTypeToStaticValue(checker.getTypeAtLocation(node));
95
+ if (value) {
96
+ return value;
97
+ }
98
+ }
99
+ // If we got here, we cannot statically analyze by the AST alone. We have to check the type of the
100
+ // correct AST Node
101
+ if (typescript_1.default.isIdentifier(node) || typescript_1.default.isPropertyAccessExpression(node)) {
102
+ const value = parseTypeToStaticValue(checker.getTypeAtLocation(node));
103
+ if (value) {
104
+ return value;
105
+ }
106
+ }
107
+ if (typescript_1.default.isComputedPropertyName(node)) {
108
+ const value = parseTypeToStaticValue(checker.getTypeAtLocation(node.expression));
109
+ if (value) {
110
+ return value;
111
+ }
112
+ }
113
+ // we don't know what this is, we need to throw an error
114
+ const type = checker.getTypeAtLocation(node);
115
+ const typeValue = checker.typeToString(type);
116
+ throw new Error(`Unknown type at: "${node.getText()}". Received "${typeValue}"\n${(0, getErrorMessage_1.getErrorMessage)(node, context)}\nFor static analysis of styles, please make sure all types resolve to string or numeric literals. Please use 'const' instead of 'let'. If using an object, cast using "as const" or use an interface with string or numeric literals.`);
117
+ }
118
+ exports.parseNodeToStaticValue = parseNodeToStaticValue;
119
+ function parseTypeToStaticValue(type) {
120
+ if (type.isStringLiteral()) {
121
+ return type.value;
122
+ }
123
+ if (type.isNumberLiteral()) {
124
+ return type.value;
125
+ }
126
+ }
127
+ /**
128
+ * A `PropertyExpression` is an expression with a dot in it. Like `a.b.c`. It may be nested. This
129
+ * function will walk the AST and create a string like `a.b.c` to be passed on to variable name
130
+ * generation. This will be used for CSS variable lookups.
131
+ */
132
+ function getPropertyAccessExpressionText(node) {
133
+ if (typescript_1.default.isIdentifier(node.name)) {
134
+ if (typescript_1.default.isIdentifier(node.expression)) {
135
+ return `${node.expression.text}.${node.name.text}`;
136
+ }
137
+ if (typescript_1.default.isPropertyAccessExpression(node.expression)) {
138
+ return `${getPropertyAccessExpressionText(node.expression)}.${node.name.text}`;
139
+ }
140
+ }
141
+ return '';
142
+ }
143
+ /**
144
+ * Gets a static string value from a template expression. It could recurse.
145
+ */
146
+ function getStyleValueFromTemplateExpression(node, context) {
147
+ if (!node) {
148
+ return '';
149
+ }
150
+ if (typescript_1.default.isTemplateExpression(node)) {
151
+ return (getStyleValueFromTemplateExpression(node.head, context) +
152
+ node.templateSpans.map(value => getStyleValueFromTemplateExpression(value, context)).join(''));
153
+ }
154
+ if (typescript_1.default.isTemplateHead(node) || typescript_1.default.isTemplateTail(node) || typescript_1.default.isTemplateMiddle(node)) {
155
+ return node.text;
156
+ }
157
+ if (typescript_1.default.isTemplateSpan(node)) {
158
+ return (parseNodeToStaticValue(node.expression, context) +
159
+ getStyleValueFromTemplateExpression(node.literal, context));
160
+ }
161
+ return '';
162
+ }
163
+ /**
164
+ * Get a value from an aliased symbol, if it exists. An aliased symbol comes from
165
+ */
166
+ function getValueFromAliasedSymbol(node, varName, context) {
167
+ const { checker, transform } = context;
168
+ let symbolNode;
169
+ if (typescript_1.default.isIdentifier(node)) {
170
+ // base case is the node is an identifier
171
+ symbolNode = node;
172
+ }
173
+ if (typescript_1.default.isPropertyAccessExpression(node) && typescript_1.default.isIdentifier(node.name)) {
174
+ return getValueFromAliasedSymbol(node.expression, varName, context);
175
+ }
176
+ if (typescript_1.default.isComputedPropertyName(node)) {
177
+ return getValueFromAliasedSymbol(node.expression, varName, context);
178
+ }
179
+ if (symbolNode) {
180
+ const symbol = checker.getSymbolAtLocation(symbolNode);
181
+ let declaration;
182
+ if (symbol === null || symbol === void 0 ? void 0 : symbol.valueDeclaration) {
183
+ // If the symbol has a value declaration, we'll use that declaration
184
+ declaration = symbol.valueDeclaration;
185
+ }
186
+ else if (symbol && symbol.getFlags() & typescript_1.default.SymbolFlags.Alias) {
187
+ // If the symbol does not have a value declaration, we'll check if there's a aliased symbol
188
+ // linking to the value declaration.
189
+ declaration = checker.getAliasedSymbol(symbol).valueDeclaration;
190
+ }
191
+ // If there is an aliased symbol and it is a variable declaration, try to resolve the
192
+ if (declaration && hasExpression(declaration)) {
193
+ if (declaration.initializer) {
194
+ // Update the `prefix` to the alias declaration's source file.
195
+ const aliasFileContext = {
196
+ ...context,
197
+ prefix: context.getPrefix(declaration.getSourceFile().fileName),
198
+ };
199
+ transform(declaration.initializer, aliasFileContext);
200
+ return getValueFromProcessedNodes(varName, aliasFileContext);
201
+ }
202
+ }
203
+ }
204
+ }
205
+ exports.getValueFromAliasedSymbol = getValueFromAliasedSymbol;
206
+ function getValueFromProcessedNodes(varName, context) {
207
+ const { names } = context;
208
+ if (context.nameScope && names[`${context.nameScope}${varName}`]) {
209
+ return names[`${context.nameScope}${varName}`];
210
+ }
211
+ if (names[varName]) {
212
+ return names[varName];
213
+ }
214
+ }
215
+ function hasExpression(node) {
216
+ return 'initializer' in node;
217
+ }
@@ -0,0 +1,15 @@
1
+ import ts from 'typescript';
2
+ import { NestedStyleObject, TransformerContext } from './types';
3
+ export declare function parseObjectToStaticValue(node: ts.Node, context: TransformerContext): NestedStyleObject;
4
+ /**
5
+ * If we're here, we have a `ts.Type` that represents a style object. We try to parse a style object
6
+ * from the AST, but we might have something that is more complicated like a function call or an
7
+ * identifier that represents an object. It could be imported from another file.
8
+ */
9
+ export declare function parseStyleObjFromType(type: ts.Type, context: TransformerContext): Record<string, any>;
10
+ /**
11
+ * Wrap all unwrapped CSS Variables. For example, `{padding: '--foo'}` will be replaced with
12
+ * `{padding: 'var(--foo)'}`. It also works on variables in the middle of the property.
13
+ */
14
+ export declare function maybeWrapCSSVariables(input: string | number, names: Record<string, string>): string | number;
15
+ //# sourceMappingURL=parseObjectToStaticValue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseObjectToStaticValue.d.ts","sourceRoot":"","sources":["../../../../lib/utils/parseObjectToStaticValue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAI5B,OAAO,EAAC,iBAAiB,EAAE,kBAAkB,EAAC,MAAM,SAAS,CAAC;AAE9D,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,EAAE,CAAC,IAAI,EACb,OAAO,EAAE,kBAAkB,GAC1B,iBAAiB,CAUnB;AA4GD;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,kBAAkB,uBA+B/E;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,MAAM,GAAG,MAAM,EACtB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC5B,MAAM,GAAG,MAAM,CA4BjB"}
@@ -0,0 +1,168 @@
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.maybeWrapCSSVariables = exports.parseStyleObjFromType = exports.parseObjectToStaticValue = void 0;
7
+ const typescript_1 = __importDefault(require("typescript"));
8
+ const getFallbackVariable_1 = require("./getFallbackVariable");
9
+ const parseNodeToStaticValue_1 = require("./parseNodeToStaticValue");
10
+ function parseObjectToStaticValue(node, context) {
11
+ let styleObj = {};
12
+ if (typescript_1.default.isObjectLiteralExpression(node)) {
13
+ node.properties.forEach(property => {
14
+ styleObj = { ...styleObj, ...parsePropertyToStaticValue(property, context) };
15
+ });
16
+ }
17
+ return wrapStyleObj(styleObj, context);
18
+ }
19
+ exports.parseObjectToStaticValue = parseObjectToStaticValue;
20
+ /**
21
+ * Wrap all values and nested object values with a maybeWrapCSSVariables call
22
+ */
23
+ function wrapStyleObj(styleObj, context) {
24
+ for (const key in styleObj) {
25
+ if (styleObj.hasOwnProperty(key)) {
26
+ const value = styleObj[key];
27
+ if (typeof value === 'object') {
28
+ styleObj[key] = wrapStyleObj(value, context);
29
+ }
30
+ if (typeof value === 'string') {
31
+ styleObj[key] = maybeWrapCSSVariables(value, context.names);
32
+ }
33
+ }
34
+ }
35
+ return styleObj;
36
+ }
37
+ function handleObjectTransforms(node, context) {
38
+ return context.objectTransforms.reduce((result, transformer) => {
39
+ return result || transformer(node, context) || undefined;
40
+ }, undefined);
41
+ }
42
+ function parsePropertyToStaticValue(node, context) {
43
+ const styleObj = {};
44
+ // check to see if there's an object transform for this node
45
+ const obj = handleObjectTransforms(node, context);
46
+ if (obj) {
47
+ return obj;
48
+ }
49
+ // If there's a spread, we're expecting an object to be returned. We'll see if there's an object transform for this node
50
+ if (typescript_1.default.isSpreadAssignment(node)) {
51
+ const obj = handleObjectTransforms(node.expression, context);
52
+ if (obj) {
53
+ return obj;
54
+ }
55
+ }
56
+ // {...{key: 'value'}}
57
+ if (typescript_1.default.isSpreadAssignment(node) && typescript_1.default.isObjectLiteralExpression(node.expression)) {
58
+ // recurse to parse a nested ObjectLiteralExpression
59
+ return parseObjectToStaticValue(node.expression, context);
60
+ }
61
+ // { name: value }
62
+ if (typescript_1.default.isPropertyAssignment(node)) {
63
+ const key = typescript_1.default.isIdentifier(node.name)
64
+ ? node.name.text
65
+ : (0, parseNodeToStaticValue_1.parseNodeToStaticValue)(node.name, context);
66
+ if (key) {
67
+ if (typescript_1.default.isObjectLiteralExpression(node.initializer)) {
68
+ // nested
69
+ styleObj[key] = parseObjectToStaticValue(node.initializer, context);
70
+ }
71
+ else {
72
+ styleObj[key] = (0, parseNodeToStaticValue_1.parseNodeToStaticValue)(node.initializer, context);
73
+ }
74
+ return styleObj;
75
+ }
76
+ }
77
+ // { name: value } (types)
78
+ if (typescript_1.default.isPropertySignature(node)) {
79
+ const key = typescript_1.default.isIdentifier(node.name)
80
+ ? node.name.text
81
+ : (0, parseNodeToStaticValue_1.parseNodeToStaticValue)(node.name, context).toString();
82
+ if (key) {
83
+ if (key.includes('&') || key.startsWith(':')) {
84
+ // nested
85
+ styleObj[key] = parseObjectToStaticValue(node.type, context);
86
+ }
87
+ else {
88
+ styleObj[key] = (0, parseNodeToStaticValue_1.parseNodeToStaticValue)(node.type, context).toString() || '';
89
+ }
90
+ return styleObj;
91
+ }
92
+ }
93
+ // { name }
94
+ if (typescript_1.default.isShorthandPropertyAssignment(node)) {
95
+ const key = node.name.text;
96
+ styleObj[key] = (0, parseNodeToStaticValue_1.parseNodeToStaticValue)(node.name, context).toString() || '';
97
+ return styleObj;
98
+ }
99
+ // { ...value }
100
+ if (typescript_1.default.isSpreadAssignment(node)) {
101
+ // Spread assignments are a bit complicated to use the AST to figure out, so we'll ask the
102
+ // TypeScript type checker.
103
+ const type = context.checker.getTypeAtLocation(node.expression);
104
+ return parseStyleObjFromType(type, context);
105
+ }
106
+ return styleObj;
107
+ }
108
+ /**
109
+ * If we're here, we have a `ts.Type` that represents a style object. We try to parse a style object
110
+ * from the AST, but we might have something that is more complicated like a function call or an
111
+ * identifier that represents an object. It could be imported from another file.
112
+ */
113
+ function parseStyleObjFromType(type, context) {
114
+ const styleObj = {};
115
+ // Gets all the properties of the type object
116
+ return type.getProperties().reduce((result, property) => {
117
+ const declaration = property.valueDeclaration;
118
+ if (!declaration) {
119
+ return result;
120
+ }
121
+ // we might have generics, so we'll use the type of the symbol instead of the type at the
122
+ // declaration. This resolves generics like `T` into literal values if they exist.
123
+ const propType = context.checker.getTypeOfSymbolAtLocation(property, declaration);
124
+ if (propType.isStringLiteral()) {
125
+ // This isn't a component variable, it is a static CSS variable
126
+ result[property.name] = propType.value;
127
+ return result;
128
+ }
129
+ if (propType.isNumberLiteral()) {
130
+ result[property.name] = propType.value;
131
+ return result;
132
+ }
133
+ return {
134
+ ...result,
135
+ ...parsePropertyToStaticValue(declaration, context),
136
+ };
137
+ }, styleObj);
138
+ }
139
+ exports.parseStyleObjFromType = parseStyleObjFromType;
140
+ /**
141
+ * Wrap all unwrapped CSS Variables. For example, `{padding: '--foo'}` will be replaced with
142
+ * `{padding: 'var(--foo)'}`. It also works on variables in the middle of the property.
143
+ */
144
+ function maybeWrapCSSVariables(input, names) {
145
+ if (typeof input === 'number') {
146
+ return input;
147
+ }
148
+ // matches an string starting with `--` that isn't already wrapped in a `var()`. It tries to match
149
+ // any character that isn't a valid separator in CSS
150
+ return input.replace(/([a-z]*[ (]*)(--[^\s;,'})]+)(\){0,1})/gi, (match, prefix, variable, postfix) => {
151
+ // shortcut for var() wrappers that already have a fallback
152
+ if (prefix.startsWith('var(') && postfix !== ')') {
153
+ return match;
154
+ }
155
+ // find a possible fallback
156
+ const fallbackVariable = (0, getFallbackVariable_1.getFallbackVariable)(variable, names);
157
+ const fallback = fallbackVariable
158
+ ? `, ${maybeWrapCSSVariables(fallbackVariable, names)}`
159
+ : '';
160
+ // if this a var wrapper without a fallback
161
+ if (prefix.startsWith('var(') && postfix === ')') {
162
+ return `${prefix}${variable}${fallback}${postfix}`;
163
+ }
164
+ // if this is not a var wrapper at all
165
+ return `${prefix}var(${variable}${fallback})${postfix}`;
166
+ });
167
+ }
168
+ exports.maybeWrapCSSVariables = maybeWrapCSSVariables;
@@ -0,0 +1,3 @@
1
+ import { Middleware } from 'stylis';
2
+ export declare const prettyStringify: Middleware;
3
+ //# sourceMappingURL=stylisFns.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stylisFns.d.ts","sourceRoot":"","sources":["../../../../lib/utils/stylisFns.ts"],"names":[],"mappings":"AAGA,OAAO,EAML,UAAU,EAIX,MAAM,QAAQ,CAAC;AAMhB,eAAO,MAAM,eAAe,EAAE,UAoC7B,CAAC"}