@workday/canvas-kit-styling-transform 10.3.2 → 10.3.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 (123) hide show
  1. package/index.ts +5 -0
  2. package/package.json +6 -14
  3. package/testing.ts +3 -0
  4. package/dist/commonjs/index.d.ts +0 -3
  5. package/dist/commonjs/index.d.ts.map +0 -1
  6. package/dist/commonjs/index.js +0 -7
  7. package/dist/commonjs/lib/styleTransform.d.ts +0 -23
  8. package/dist/commonjs/lib/styleTransform.d.ts.map +0 -1
  9. package/dist/commonjs/lib/styleTransform.js +0 -103
  10. package/dist/commonjs/lib/utils/createStyleObjectNode.d.ts +0 -18
  11. package/dist/commonjs/lib/utils/createStyleObjectNode.d.ts.map +0 -1
  12. package/dist/commonjs/lib/utils/createStyleObjectNode.js +0 -47
  13. package/dist/commonjs/lib/utils/getCssVariables.d.ts +0 -4
  14. package/dist/commonjs/lib/utils/getCssVariables.d.ts.map +0 -1
  15. package/dist/commonjs/lib/utils/getCssVariables.js +0 -31
  16. package/dist/commonjs/lib/utils/getErrorMessage.d.ts +0 -15
  17. package/dist/commonjs/lib/utils/getErrorMessage.d.ts.map +0 -1
  18. package/dist/commonjs/lib/utils/getErrorMessage.js +0 -45
  19. package/dist/commonjs/lib/utils/getFallbackVariable.d.ts +0 -9
  20. package/dist/commonjs/lib/utils/getFallbackVariable.d.ts.map +0 -1
  21. package/dist/commonjs/lib/utils/getFallbackVariable.js +0 -30
  22. package/dist/commonjs/lib/utils/getVarName.d.ts +0 -17
  23. package/dist/commonjs/lib/utils/getVarName.d.ts.map +0 -1
  24. package/dist/commonjs/lib/utils/getVarName.js +0 -33
  25. package/dist/commonjs/lib/utils/handleCalc.d.ts +0 -19
  26. package/dist/commonjs/lib/utils/handleCalc.d.ts.map +0 -1
  27. package/dist/commonjs/lib/utils/handleCalc.js +0 -62
  28. package/dist/commonjs/lib/utils/handleCreateStencil.d.ts +0 -6
  29. package/dist/commonjs/lib/utils/handleCreateStencil.d.ts.map +0 -1
  30. package/dist/commonjs/lib/utils/handleCreateStencil.js +0 -203
  31. package/dist/commonjs/lib/utils/handleCreateStyles.d.ts +0 -3
  32. package/dist/commonjs/lib/utils/handleCreateStyles.d.ts.map +0 -1
  33. package/dist/commonjs/lib/utils/handleCreateStyles.js +0 -110
  34. package/dist/commonjs/lib/utils/handleCreateVars.d.ts +0 -3
  35. package/dist/commonjs/lib/utils/handleCreateVars.d.ts.map +0 -1
  36. package/dist/commonjs/lib/utils/handleCreateVars.js +0 -34
  37. package/dist/commonjs/lib/utils/handleCssVar.d.ts +0 -12
  38. package/dist/commonjs/lib/utils/handleCssVar.d.ts.map +0 -1
  39. package/dist/commonjs/lib/utils/handleCssVar.js +0 -33
  40. package/dist/commonjs/lib/utils/handleFocusRing.d.ts +0 -3
  41. package/dist/commonjs/lib/utils/handleFocusRing.d.ts.map +0 -1
  42. package/dist/commonjs/lib/utils/handleFocusRing.js +0 -83
  43. package/dist/commonjs/lib/utils/handleKeyframes.d.ts +0 -3
  44. package/dist/commonjs/lib/utils/handleKeyframes.d.ts.map +0 -1
  45. package/dist/commonjs/lib/utils/handleKeyframes.js +0 -47
  46. package/dist/commonjs/lib/utils/handlePx2Rem.d.ts +0 -6
  47. package/dist/commonjs/lib/utils/handlePx2Rem.d.ts.map +0 -1
  48. package/dist/commonjs/lib/utils/handlePx2Rem.js +0 -26
  49. package/dist/commonjs/lib/utils/isImportedFromStyling.d.ts +0 -7
  50. package/dist/commonjs/lib/utils/isImportedFromStyling.d.ts.map +0 -1
  51. package/dist/commonjs/lib/utils/isImportedFromStyling.js +0 -23
  52. package/dist/commonjs/lib/utils/makeEmotionSafe.d.ts +0 -7
  53. package/dist/commonjs/lib/utils/makeEmotionSafe.d.ts.map +0 -1
  54. package/dist/commonjs/lib/utils/makeEmotionSafe.js +0 -15
  55. package/dist/commonjs/lib/utils/parseNodeToStaticValue.d.ts +0 -7
  56. package/dist/commonjs/lib/utils/parseNodeToStaticValue.d.ts.map +0 -1
  57. package/dist/commonjs/lib/utils/parseNodeToStaticValue.js +0 -149
  58. package/dist/commonjs/lib/utils/parseObjectToStaticValue.d.ts +0 -13
  59. package/dist/commonjs/lib/utils/parseObjectToStaticValue.d.ts.map +0 -1
  60. package/dist/commonjs/lib/utils/parseObjectToStaticValue.js +0 -118
  61. package/dist/commonjs/lib/utils/types.d.ts +0 -16
  62. package/dist/commonjs/lib/utils/types.d.ts.map +0 -1
  63. package/dist/commonjs/lib/utils/types.js +0 -2
  64. package/dist/es6/index.d.ts +0 -3
  65. package/dist/es6/index.d.ts.map +0 -1
  66. package/dist/es6/index.js +0 -2
  67. package/dist/es6/lib/styleTransform.d.ts +0 -23
  68. package/dist/es6/lib/styleTransform.d.ts.map +0 -1
  69. package/dist/es6/lib/styleTransform.js +0 -94
  70. package/dist/es6/lib/utils/createStyleObjectNode.d.ts +0 -18
  71. package/dist/es6/lib/utils/createStyleObjectNode.d.ts.map +0 -1
  72. package/dist/es6/lib/utils/createStyleObjectNode.js +0 -39
  73. package/dist/es6/lib/utils/getCssVariables.d.ts +0 -4
  74. package/dist/es6/lib/utils/getCssVariables.d.ts.map +0 -1
  75. package/dist/es6/lib/utils/getCssVariables.js +0 -26
  76. package/dist/es6/lib/utils/getErrorMessage.d.ts +0 -15
  77. package/dist/es6/lib/utils/getErrorMessage.d.ts.map +0 -1
  78. package/dist/es6/lib/utils/getErrorMessage.js +0 -41
  79. package/dist/es6/lib/utils/getFallbackVariable.d.ts +0 -9
  80. package/dist/es6/lib/utils/getFallbackVariable.d.ts.map +0 -1
  81. package/dist/es6/lib/utils/getFallbackVariable.js +0 -26
  82. package/dist/es6/lib/utils/getVarName.d.ts +0 -17
  83. package/dist/es6/lib/utils/getVarName.d.ts.map +0 -1
  84. package/dist/es6/lib/utils/getVarName.js +0 -26
  85. package/dist/es6/lib/utils/handleCalc.d.ts +0 -19
  86. package/dist/es6/lib/utils/handleCalc.d.ts.map +0 -1
  87. package/dist/es6/lib/utils/handleCalc.js +0 -55
  88. package/dist/es6/lib/utils/handleCreateStencil.d.ts +0 -6
  89. package/dist/es6/lib/utils/handleCreateStencil.d.ts.map +0 -1
  90. package/dist/es6/lib/utils/handleCreateStencil.js +0 -196
  91. package/dist/es6/lib/utils/handleCreateStyles.d.ts +0 -3
  92. package/dist/es6/lib/utils/handleCreateStyles.d.ts.map +0 -1
  93. package/dist/es6/lib/utils/handleCreateStyles.js +0 -103
  94. package/dist/es6/lib/utils/handleCreateVars.d.ts +0 -3
  95. package/dist/es6/lib/utils/handleCreateVars.d.ts.map +0 -1
  96. package/dist/es6/lib/utils/handleCreateVars.js +0 -27
  97. package/dist/es6/lib/utils/handleCssVar.d.ts +0 -12
  98. package/dist/es6/lib/utils/handleCssVar.d.ts.map +0 -1
  99. package/dist/es6/lib/utils/handleCssVar.js +0 -26
  100. package/dist/es6/lib/utils/handleFocusRing.d.ts +0 -3
  101. package/dist/es6/lib/utils/handleFocusRing.d.ts.map +0 -1
  102. package/dist/es6/lib/utils/handleFocusRing.js +0 -76
  103. package/dist/es6/lib/utils/handleKeyframes.d.ts +0 -3
  104. package/dist/es6/lib/utils/handleKeyframes.d.ts.map +0 -1
  105. package/dist/es6/lib/utils/handleKeyframes.js +0 -40
  106. package/dist/es6/lib/utils/handlePx2Rem.d.ts +0 -6
  107. package/dist/es6/lib/utils/handlePx2Rem.d.ts.map +0 -1
  108. package/dist/es6/lib/utils/handlePx2Rem.js +0 -19
  109. package/dist/es6/lib/utils/isImportedFromStyling.d.ts +0 -7
  110. package/dist/es6/lib/utils/isImportedFromStyling.d.ts.map +0 -1
  111. package/dist/es6/lib/utils/isImportedFromStyling.js +0 -16
  112. package/dist/es6/lib/utils/makeEmotionSafe.d.ts +0 -7
  113. package/dist/es6/lib/utils/makeEmotionSafe.d.ts.map +0 -1
  114. package/dist/es6/lib/utils/makeEmotionSafe.js +0 -11
  115. package/dist/es6/lib/utils/parseNodeToStaticValue.d.ts +0 -7
  116. package/dist/es6/lib/utils/parseNodeToStaticValue.d.ts.map +0 -1
  117. package/dist/es6/lib/utils/parseNodeToStaticValue.js +0 -142
  118. package/dist/es6/lib/utils/parseObjectToStaticValue.d.ts +0 -13
  119. package/dist/es6/lib/utils/parseObjectToStaticValue.d.ts.map +0 -1
  120. package/dist/es6/lib/utils/parseObjectToStaticValue.js +0 -110
  121. package/dist/es6/lib/utils/types.d.ts +0 -16
  122. package/dist/es6/lib/utils/types.d.ts.map +0 -1
  123. package/dist/es6/lib/utils/types.js +0 -1
package/index.ts CHANGED
@@ -1,3 +1,8 @@
1
1
  import styleTransformer from './lib/styleTransform';
2
+ export {Config} from './lib/utils/types';
3
+ export {parseNodeToStaticValue} from './lib/utils/parseNodeToStaticValue';
4
+ export {parseObjectToStaticValue} from './lib/utils/parseObjectToStaticValue';
5
+ export {createObjectTransform} from './lib/createObjectTransform';
6
+ export {createPropertyTransform} from './lib/createPropertyTransform';
2
7
 
3
8
  export default styleTransformer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@workday/canvas-kit-styling-transform",
3
- "version": "10.3.2",
3
+ "version": "10.3.3",
4
4
  "description": "The custom CSS in JS solution that takes JS styles and turns them into static CSS",
5
5
  "author": "Workday, Inc. (https://www.workday.com)",
6
6
  "license": "Apache-2.0",
@@ -18,18 +18,11 @@
18
18
  "*/lib/*",
19
19
  "*/index.ts",
20
20
  "dist/",
21
- "index.ts"
21
+ "index.ts",
22
+ "testing.ts"
22
23
  ],
23
24
  "scripts": {
24
- "watch": "yarn build:es6 -w",
25
- "test": "echo \"Error: no test specified\" && exit 1",
26
- "clean": "rimraf dist && rimraf .build-info && mkdirp dist",
27
- "build:cjs": "tsc -p tsconfig.cjs.json",
28
- "build:es6": "tsc -p tsconfig.es6.json",
29
- "build:rebuild": "npm-run-all clean build",
30
- "build": "npm-run-all --parallel build:cjs build:es6",
31
- "depcheck": "node ../../utils/check-dependencies-exist.js",
32
- "typecheck:src": "tsc -p . --noEmit --incremental false"
25
+ "test": "echo \"Error: no test specified\" && exit 1"
33
26
  },
34
27
  "keywords": [
35
28
  "canvas",
@@ -41,13 +34,12 @@
41
34
  ],
42
35
  "dependencies": {
43
36
  "@emotion/serialize": "^1.0.2",
44
- "@workday/canvas-kit-styling": "^10.3.2",
45
- "@workday/canvas-tokens-web": "^1.0.0",
37
+ "@workday/canvas-kit-styling": "^10.3.3",
46
38
  "stylis": "4.0.13",
47
39
  "typescript": "4.2"
48
40
  },
49
41
  "devDependencies": {
50
42
  "common-tags": "^1.8.0"
51
43
  },
52
- "gitHead": "07021e74cb126d51459bb4046b3760bf2573a007"
44
+ "gitHead": "6ea048938f61ad4a8f72a537185f9317e5332769"
53
45
  }
package/testing.ts ADDED
@@ -0,0 +1,3 @@
1
+ export {createProgramFromSource} from './spec/createProgramFromSource';
2
+ export {transform, _reset, withDefaultContext} from './lib/styleTransform';
3
+ export {findNodes} from './spec/findNodes';
@@ -1,3 +0,0 @@
1
- import styleTransformer from './lib/styleTransform';
2
- export default styleTransformer;
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../index.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,MAAM,sBAAsB,CAAC;AAEpD,eAAe,gBAAgB,CAAC"}
@@ -1,7 +0,0 @@
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 styleTransform_1 = __importDefault(require("./lib/styleTransform"));
7
- exports.default = styleTransform_1.default;
@@ -1,23 +0,0 @@
1
- import ts from 'typescript';
2
- import { NodeTransformer, TransformerContext } from './utils/types';
3
- export declare type NestedStyleObject = {
4
- [key: string]: string | NestedStyleObject;
5
- };
6
- export interface StyleTransformerOptions {
7
- prefix: string;
8
- variables: TransformerContext['variables'];
9
- keyframes: TransformerContext['keyframes'];
10
- fallbackFiles?: string[];
11
- transformers?: NodeTransformer[];
12
- }
13
- /**
14
- * The reset is used in tests and should not be called normally.
15
- */
16
- export declare function _reset(): void;
17
- export default function styleTransformer(program: ts.Program, { variables, fallbackFiles, transformers, ...transformContext }?: Partial<StyleTransformerOptions>): ts.TransformerFactory<ts.SourceFile>;
18
- /**
19
- * This function is useful for tests or a custom build. The `styleTransformer` function is used by
20
- * the https://www.npmjs.com/package/ttypescript package.
21
- */
22
- export declare function transform(program: ts.Program, fileName: string, options?: Partial<StyleTransformerOptions>): string;
23
- //# sourceMappingURL=styleTransform.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"styleTransform.d.ts","sourceRoot":"","sources":["../../../lib/styleTransform.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,YAAY,CAAC;AAW5B,OAAO,EAAC,eAAe,EAAE,kBAAkB,EAAC,MAAM,eAAe,CAAC;AAGlE,oBAAY,iBAAiB,GAAG;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,iBAAiB,CAAA;CAAC,CAAC;AAE5E,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,kBAAkB,CAAC,WAAW,CAAC,CAAC;IAC3C,SAAS,EAAE,kBAAkB,CAAC,WAAW,CAAC,CAAC;IAC3C,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,YAAY,CAAC,EAAE,eAAe,EAAE,CAAC;CAClC;AAMD;;GAEG;AACH,wBAAgB,MAAM,SAIrB;AAgBD,MAAM,CAAC,OAAO,UAAU,gBAAgB,CACtC,OAAO,EAAE,EAAE,CAAC,OAAO,EACnB,EACE,SAAc,EACd,aAAkB,EAClB,YAAkC,EAClC,GAAG,gBAAgB,EACpB,GAAE,OAAO,CAAC,uBAAuB,CAKjC,GACA,EAAE,CAAC,kBAAkB,CAAC,EAAE,CAAC,UAAU,CAAC,CAsCtC;AAED;;;GAGG;AACH,wBAAgB,SAAS,CACvB,OAAO,EAAE,EAAE,CAAC,OAAO,EACnB,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,OAAO,CAAC,uBAAuB,CAAC,UAY3C"}
@@ -1,103 +0,0 @@
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.transform = exports._reset = void 0;
7
- /// <reference types="node" />
8
- const typescript_1 = __importDefault(require("typescript"));
9
- const node_path_1 = __importDefault(require("node:path"));
10
- const getCssVariables_1 = require("./utils/getCssVariables");
11
- const handleCreateVars_1 = require("./utils/handleCreateVars");
12
- const handleCreateStyles_1 = require("./utils/handleCreateStyles");
13
- const handleCreateStencil_1 = require("./utils/handleCreateStencil");
14
- const handleCalc_1 = require("./utils/handleCalc");
15
- const handlePx2Rem_1 = require("./utils/handlePx2Rem");
16
- const handleFocusRing_1 = require("./utils/handleFocusRing");
17
- const handleCssVar_1 = require("./utils/handleCssVar");
18
- const handleKeyframes_1 = require("./utils/handleKeyframes");
19
- let vars = {};
20
- let keyframes = {};
21
- let loadedFallbacks = false;
22
- /**
23
- * The reset is used in tests and should not be called normally.
24
- */
25
- function _reset() {
26
- vars = {};
27
- keyframes = {};
28
- loadedFallbacks = false;
29
- }
30
- exports._reset = _reset;
31
- /**
32
- * Optional list of transformers. Useful to override for tests
33
- */
34
- const defaultTransformers = [
35
- handleCssVar_1.handleCssVar,
36
- handleFocusRing_1.handleFocusRing,
37
- handleCalc_1.handleCalc,
38
- handlePx2Rem_1.handlePx2Rem,
39
- handleKeyframes_1.handleKeyframes,
40
- handleCreateVars_1.handleCreateVars,
41
- handleCreateStyles_1.handleCreateStyles,
42
- handleCreateStencil_1.handleCreateStencil,
43
- ];
44
- function styleTransformer(program, { variables = {}, fallbackFiles = [], transformers = defaultTransformers, ...transformContext } = {
45
- prefix: 'css',
46
- variables: {},
47
- keyframes: {},
48
- transformers: defaultTransformers,
49
- }) {
50
- if (!loadedFallbacks) {
51
- const files = fallbackFiles
52
- .filter(file => file) // don't process empty files
53
- .map(file => {
54
- // Find the fully-qualified path name. This could error which should give "module not found" errors
55
- return file.startsWith('.') ? node_path_1.default.resolve(process.cwd(), file) : require.resolve(file);
56
- })
57
- .map(file => {
58
- console.log(`Loading CSS variable fallback file: ${file}`);
59
- return typescript_1.default.sys.readFile(file) || '';
60
- });
61
- const fallbackVars = getCssVariables_1.getVariablesFromFiles(files);
62
- console.log(`Found ${Object.keys(fallbackVars).length} variables.`);
63
- // eslint-disable-next-line no-param-reassign
64
- vars = { ...variables, ...fallbackVars };
65
- loadedFallbacks = true;
66
- }
67
- const checker = program.getTypeChecker();
68
- return context => {
69
- const visit = node => {
70
- // eslint-disable-next-line no-param-reassign
71
- node = typescript_1.default.visitEachChild(node, visit, context);
72
- return handleTransformers(node, {
73
- checker,
74
- prefix: 'css',
75
- variables: vars,
76
- keyframes,
77
- ...transformContext,
78
- })(transformers);
79
- };
80
- return node => typescript_1.default.visitNode(node, visit);
81
- };
82
- }
83
- exports.default = styleTransformer;
84
- /**
85
- * This function is useful for tests or a custom build. The `styleTransformer` function is used by
86
- * the https://www.npmjs.com/package/ttypescript package.
87
- */
88
- function transform(program, fileName, options) {
89
- const source = program.getSourceFile(fileName) || typescript_1.default.createSourceFile(fileName, '', typescript_1.default.ScriptTarget.ES2019);
90
- const printer = typescript_1.default.createPrinter();
91
- return printer.printFile(typescript_1.default
92
- .transform(source, [styleTransformer(program, options)])
93
- .transformed.find(s => s.fileName === fileName) || source);
94
- }
95
- exports.transform = transform;
96
- const handleTransformers = (node, context) => (transformers) => {
97
- return (transformers.reduce((result, transformer) => {
98
- if (result) {
99
- return result;
100
- }
101
- return transformer(node, context);
102
- }, undefined) || node);
103
- };
@@ -1,18 +0,0 @@
1
- import ts from 'typescript';
2
- import { NestedStyleObject } from './parseObjectToStaticValue';
3
- /**
4
- * Creates an AST node representation of the passed in `styleObj`, but in the format of `{name:
5
- * string, styles: serializedStyles}`. The `name` is hard-coded here to work with both server-side
6
- * and client-side style injection. This results in a stable style key for Emotion while also
7
- * optimizing style serialization.
8
- *
9
- * If `name` is provided, the name will be whatever `name` is, replacing "{hash}" with the hash
10
- * created via `serializeStyles`. For example: 'animation-{hash}' will be converted into
11
- * 'animation-abc123'
12
- */
13
- export declare function createStyleObjectNode(styleObj: NestedStyleObject | string, name?: string): ts.ObjectLiteralExpression;
14
- /**
15
- * Returns the name created by `createStyleObjectNode`
16
- */
17
- export declare function getStaticCssClassName(node: ts.Node): string;
18
- //# sourceMappingURL=createStyleObjectNode.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createStyleObjectNode.d.ts","sourceRoot":"","sources":["../../../../lib/utils/createStyleObjectNode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAK5B,OAAO,EAAC,iBAAiB,EAAC,MAAM,4BAA4B,CAAC;AAE7D;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,iBAAiB,GAAG,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,8BAuBxF;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,MAAM,CAS3D"}
@@ -1,47 +0,0 @@
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.getStaticCssClassName = exports.createStyleObjectNode = void 0;
7
- const typescript_1 = __importDefault(require("typescript"));
8
- const serialize_1 = require("@emotion/serialize");
9
- const canvas_kit_styling_1 = require("@workday/canvas-kit-styling");
10
- /**
11
- * Creates an AST node representation of the passed in `styleObj`, but in the format of `{name:
12
- * string, styles: serializedStyles}`. The `name` is hard-coded here to work with both server-side
13
- * and client-side style injection. This results in a stable style key for Emotion while also
14
- * optimizing style serialization.
15
- *
16
- * If `name` is provided, the name will be whatever `name` is, replacing "{hash}" with the hash
17
- * created via `serializeStyles`. For example: 'animation-{hash}' will be converted into
18
- * 'animation-abc123'
19
- */
20
- function createStyleObjectNode(styleObj, name) {
21
- const serialized = serialize_1.serializeStyles([styleObj]);
22
- const styleText = serialized.styles;
23
- const styleExpression = typescript_1.default.factory.createStringLiteral(styleText);
24
- // create an emotion-optimized object: https://github.com/emotion-js/emotion/blob/f3b268f7c52103979402da919c9c0dd3f9e0e189/packages/serialize/src/index.js#L315-L322
25
- // Looks like: `{name: $hash, styles: $styleText }`
26
- return typescript_1.default.factory.createObjectLiteralExpression([
27
- typescript_1.default.factory.createPropertyAssignment(typescript_1.default.factory.createIdentifier('name'),
28
- // TODO - we may need this to be a static variable for the CSS package
29
- typescript_1.default.factory.createStringLiteral(name ? name.replace('{hash}', serialized.name) : canvas_kit_styling_1.generateUniqueId()) // We might be using values that are resolved at runtime, but should still be static. We're only supporting the `cs` function running once per file, so a stable id based on a hash is not necessary
30
- ),
31
- typescript_1.default.factory.createPropertyAssignment(typescript_1.default.factory.createIdentifier('styles'), styleExpression // In the future we can extract CSS from here by running the `stylis` compiler directly. Emotion does this here: https://github.com/emotion-js/emotion/blob/f3b268f7c52103979402da919c9c0dd3f9e0e189/packages/cache/src/index.js#L188-L245
32
- ),
33
- ], false);
34
- }
35
- exports.createStyleObjectNode = createStyleObjectNode;
36
- /**
37
- * Returns the name created by `createStyleObjectNode`
38
- */
39
- function getStaticCssClassName(node) {
40
- if (typescript_1.default.isObjectLiteralExpression(node) &&
41
- typescript_1.default.isPropertyAssignment(node.properties[0]) &&
42
- typescript_1.default.isStringLiteral(node.properties[0].initializer)) {
43
- return node.properties[0].initializer.text;
44
- }
45
- return '';
46
- }
47
- exports.getStaticCssClassName = getStaticCssClassName;
@@ -1,4 +0,0 @@
1
- import { Element } from 'stylis';
2
- export declare function getVariablesFromFiles(files: string[]): Record<string, string>;
3
- export declare function extractVariables(blocks: Element[] | string, variables?: Record<string, string>): Record<string, string>;
4
- //# sourceMappingURL=getCssVariables.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getCssVariables.d.ts","sourceRoot":"","sources":["../../../../lib/utils/getCssVariables.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,OAAO,EAAC,MAAM,QAAQ,CAAC;AAExC,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAK7E;AAED,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,EAC1B,SAAS,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GACrC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAuBxB"}
@@ -1,31 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.extractVariables = exports.getVariablesFromFiles = void 0;
4
- const stylis_1 = require("stylis");
5
- function getVariablesFromFiles(files) {
6
- return files.reduce((result, file) => {
7
- extractVariables(stylis_1.compile(file));
8
- return { ...result, ...extractVariables(stylis_1.compile(file)) };
9
- }, {});
10
- }
11
- exports.getVariablesFromFiles = getVariablesFromFiles;
12
- function extractVariables(blocks, variables = {}) {
13
- if (typeof blocks === 'string') {
14
- return variables;
15
- }
16
- return blocks
17
- .filter(block => block.type === 'rule')
18
- .reduce((result, rule) => {
19
- if (Array.isArray(rule.children)) {
20
- rule.children.forEach(child => {
21
- if (typeof child.props === 'string' &&
22
- child.props.startsWith('--') &&
23
- typeof child.children === 'string') {
24
- result[child.props] = child.children;
25
- }
26
- });
27
- }
28
- return result;
29
- }, { ...variables });
30
- }
31
- exports.extractVariables = extractVariables;
@@ -1,15 +0,0 @@
1
- import ts from 'typescript';
2
- /**
3
- * Creates an error message around a node. It will look something like:
4
- *
5
- * ```
6
- * Unknown type at: "fontSize".
7
- * File: test.ts, Line: 6, Character: 17.
8
- * const styles = createStyles({
9
- * fontSize: fontSize
10
- * ========
11
- * })
12
- * ```
13
- */
14
- export declare function getErrorMessage(node: ts.Node): string;
15
- //# sourceMappingURL=getErrorMessage.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getErrorMessage.d.ts","sourceRoot":"","sources":["../../../../lib/utils/getErrorMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,UAuC5C"}
@@ -1,45 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getErrorMessage = void 0;
4
- /**
5
- * Creates an error message around a node. It will look something like:
6
- *
7
- * ```
8
- * Unknown type at: "fontSize".
9
- * File: test.ts, Line: 6, Character: 17.
10
- * const styles = createStyles({
11
- * fontSize: fontSize
12
- * ========
13
- * })
14
- * ```
15
- */
16
- function getErrorMessage(node) {
17
- const sourceFile = node.getSourceFile();
18
- const { line } = node.getSourceFile().getLineAndCharacterOfPosition(node.pos);
19
- const lineStarts = sourceFile.getLineStarts();
20
- const lineStartIndex = lineStarts.findIndex(s => s >= node.pos) - 1;
21
- // get a whole line's text given a lineStarts index
22
- function getLine(sourceFile, startIndex) {
23
- const lineStarts = sourceFile.getLineStarts();
24
- return sourceFile.text.substring(lineStarts[Math.max(0, startIndex)], startIndex + 1 >= lineStarts.length ? undefined : lineStarts[startIndex + 1]);
25
- }
26
- // Create a full context message with source code and highlighting
27
- const lineBefore = getLine(sourceFile, lineStartIndex - 1);
28
- const lineCurrent = getLine(sourceFile, lineStartIndex);
29
- const lineAfter = getLine(sourceFile, lineStartIndex + 1);
30
- const highlightedLine = ''
31
- .padStart(node.getStart() - lineStarts[lineStartIndex], ' ')
32
- .padEnd(node.getStart() - lineStarts[lineStartIndex] + node.getWidth(), '=') + '\n';
33
- /** This should look something like:
34
- * ```
35
- * const styles = createStyles({
36
- * fontSize: fontSize
37
- * ========
38
- * })
39
- * ```
40
- */
41
- const fullContext = lineBefore + lineCurrent + highlightedLine + lineAfter;
42
- const character = node.getStart() - lineStarts[lineStartIndex];
43
- return `File: ${sourceFile.fileName}:${line + 1}:${character}.\n${fullContext}`;
44
- }
45
- exports.getErrorMessage = getErrorMessage;
@@ -1,9 +0,0 @@
1
- /**
2
- * Looks for a variable value that doesn't include a fallback and automatically adds one if found in
3
- * the current cache of variables. This allows fallbacks to be automatically included in
4
- * environments without the variables defined. This is most useful for Storybook or other sandboxes
5
- * that may not have CSS Variables defined. The fallbacks will allow the UI to look correct without
6
- * additional setup. Fallbacks come from the `fallbackFiles` transform configuration.
7
- */
8
- export declare function getFallbackVariable(variableName: string, variables: Record<string, string>): string | undefined;
9
- //# sourceMappingURL=getFallbackVariable.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getFallbackVariable.d.ts","sourceRoot":"","sources":["../../../../lib/utils/getFallbackVariable.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,YAAY,EAAE,MAAM,EACpB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAChC,MAAM,GAAG,SAAS,CAuBpB"}
@@ -1,30 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getFallbackVariable = void 0;
4
- /**
5
- * Looks for a variable value that doesn't include a fallback and automatically adds one if found in
6
- * the current cache of variables. This allows fallbacks to be automatically included in
7
- * environments without the variables defined. This is most useful for Storybook or other sandboxes
8
- * that may not have CSS Variables defined. The fallbacks will allow the UI to look correct without
9
- * additional setup. Fallbacks come from the `fallbackFiles` transform configuration.
10
- */
11
- function getFallbackVariable(variableName, variables) {
12
- const variable = variableName.includes('var(') ? variableName : variables[variableName];
13
- if (variable && variable.includes('var(')) {
14
- return variable.replace(/(var\(([A-Za-z0-9\-_]+)\))/, (
15
- /** matched substring "var(--var-name)" */ _,
16
- /** the full match of the first group "var(--var-name)" */ varMatch,
17
- /** the variable name - match of the second group "--var-name" */ cssVarName) => {
18
- const value = variables[cssVarName];
19
- if (value && value.startsWith('var')) {
20
- return getFallbackVariable(value, variables);
21
- }
22
- return value || varMatch;
23
- });
24
- }
25
- if (variable) {
26
- return variable;
27
- }
28
- return;
29
- }
30
- exports.getFallbackVariable = getFallbackVariable;
@@ -1,17 +0,0 @@
1
- import ts from 'typescript';
2
- /**
3
- * This function returns a calculated name of a node by walking up the AST and looking for nodes
4
- * with a `name` property that has an `Identifier` node type. The result is dash-case. This is
5
- * useful for automatically generating variable names based on a TS file.
6
- *
7
- * In the following example, the `baz` node would have a name of `foo-bar-baz`.
8
- * ```ts
9
- * const foo = {
10
- * bar: {
11
- * baz: ''
12
- * }
13
- * }
14
- * ```
15
- */
16
- export declare function getVarName(node: ts.Node, parts?: string[]): string;
17
- //# sourceMappingURL=getVarName.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getVarName.d.ts","sourceRoot":"","sources":["../../../../lib/utils/getVarName.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B;;;;;;;;;;;;;GAaG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,KAAK,GAAE,MAAM,EAAO,GAAG,MAAM,CAYtE"}
@@ -1,33 +0,0 @@
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.getVarName = void 0;
7
- const typescript_1 = __importDefault(require("typescript"));
8
- /**
9
- * This function returns a calculated name of a node by walking up the AST and looking for nodes
10
- * with a `name` property that has an `Identifier` node type. The result is dash-case. This is
11
- * useful for automatically generating variable names based on a TS file.
12
- *
13
- * In the following example, the `baz` node would have a name of `foo-bar-baz`.
14
- * ```ts
15
- * const foo = {
16
- * bar: {
17
- * baz: ''
18
- * }
19
- * }
20
- * ```
21
- */
22
- function getVarName(node, parts = []) {
23
- // base case. Join all the parts
24
- if (!node.parent || node.kind === typescript_1.default.SyntaxKind.VariableStatement) {
25
- return parts.join('-');
26
- }
27
- // Any node with a `name` property that is an identifier can add to the var name
28
- if (node.name && typescript_1.default.isIdentifier(node.name)) {
29
- return getVarName(node.parent, [node.name.text, ...parts]);
30
- }
31
- return getVarName(node.parent, parts);
32
- }
33
- exports.getVarName = getVarName;
@@ -1,19 +0,0 @@
1
- import { NodeTransformer } from './types';
2
- /**
3
- * Handle all instances of `calc.*()` statically. It converts `calc.*` call expressions to template
4
- * string literals. The transformer will then transform the template literal into static values.
5
- *
6
- * ```ts
7
- * // in
8
- * calc.add('80%', '2px')
9
- *
10
- * // out
11
- * `calc(${'80%'} + ${'2px'})`
12
- * ```
13
- *
14
- * A template literal is used because the values might be Identifiers, PropertyAccessExpressions,
15
- * etc. The transform can handle template string literals with different spans, so we'll convert to
16
- * those as an intermediate step.
17
- */
18
- export declare const handleCalc: NodeTransformer;
19
- //# sourceMappingURL=handleCalc.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"handleCalc.d.ts","sourceRoot":"","sources":["../../../../lib/utils/handleCalc.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,eAAe,EAAC,MAAM,SAAS,CAAC;AAExC;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,UAAU,EAAE,eA+BxB,CAAC"}
@@ -1,62 +0,0 @@
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.handleCalc = void 0;
7
- const typescript_1 = __importDefault(require("typescript"));
8
- const isImportedFromStyling_1 = require("./isImportedFromStyling");
9
- /**
10
- * Handle all instances of `calc.*()` statically. It converts `calc.*` call expressions to template
11
- * string literals. The transformer will then transform the template literal into static values.
12
- *
13
- * ```ts
14
- * // in
15
- * calc.add('80%', '2px')
16
- *
17
- * // out
18
- * `calc(${'80%'} + ${'2px'})`
19
- * ```
20
- *
21
- * A template literal is used because the values might be Identifiers, PropertyAccessExpressions,
22
- * etc. The transform can handle template string literals with different spans, so we'll convert to
23
- * those as an intermediate step.
24
- */
25
- const handleCalc = (node, context) => {
26
- if (typescript_1.default.isCallExpression(node) &&
27
- typescript_1.default.isPropertyAccessExpression(node.expression) &&
28
- typescript_1.default.isIdentifier(node.expression.expression) &&
29
- node.expression.expression.text === 'calc' &&
30
- typescript_1.default.isIdentifier(node.expression.name) &&
31
- isImportedFromStyling_1.isImportedFromStyling(node.expression.expression, context.checker)) {
32
- if (node.expression.name.text === 'add') {
33
- return replaceWithTemplateString(node.arguments[0], node.arguments[1], ' + ');
34
- }
35
- if (node.expression.name.text === 'subtract') {
36
- return replaceWithTemplateString(node.arguments[0], node.arguments[1], ' - ');
37
- }
38
- if (node.expression.name.text === 'multiply') {
39
- return replaceWithTemplateString(node.arguments[0], node.arguments[1], ' * ');
40
- }
41
- if (node.expression.name.text === 'divide') {
42
- return replaceWithTemplateString(node.arguments[0], node.arguments[1], ' / ');
43
- }
44
- if (node.expression.name.text === 'negate') {
45
- return replaceWithTemplateString(node.arguments[0], typescript_1.default.factory.createStringLiteral('-1'), ' * ');
46
- }
47
- }
48
- return;
49
- };
50
- exports.handleCalc = handleCalc;
51
- /**
52
- * Creates a template literal of the calculation result.
53
- */
54
- function replaceWithTemplateString(value1, value2, binder) {
55
- if (typescript_1.default.isStringLiteral(value1) && typescript_1.default.isStringLiteral(value2)) {
56
- return typescript_1.default.factory.createStringLiteral(`calc(${value1.text}${binder}${value2.text})`);
57
- }
58
- return typescript_1.default.factory.createTemplateExpression(typescript_1.default.factory.createTemplateHead('calc('), [
59
- typescript_1.default.factory.createTemplateSpan(value1, typescript_1.default.factory.createTemplateMiddle(binder)),
60
- typescript_1.default.factory.createTemplateSpan(value2, typescript_1.default.factory.createTemplateTail(')')),
61
- ]);
62
- }
@@ -1,6 +0,0 @@
1
- import { NodeTransformer } from './types';
2
- /**
3
- * Handle all arguments of the CallExpression `createStencil()`
4
- */
5
- export declare const handleCreateStencil: NodeTransformer;
6
- //# sourceMappingURL=handleCreateStencil.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"handleCreateStencil.d.ts","sourceRoot":"","sources":["../../../../lib/utils/handleCreateStencil.ts"],"names":[],"mappings":"AASA,OAAO,EAAC,eAAe,EAAqB,MAAM,SAAS,CAAC;AAG5D;;GAEG;AACH,eAAO,MAAM,mBAAmB,EAAE,eAqLjC,CAAC"}