@workday/canvas-kit-styling-transform 13.2.0 → 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.
- package/dist/commonjs/index.d.ts +14 -0
- package/dist/commonjs/index.d.ts.map +1 -0
- package/dist/commonjs/index.js +28 -0
- package/dist/commonjs/lib/createObjectTransform.d.ts +10 -0
- package/dist/commonjs/lib/createObjectTransform.d.ts.map +1 -0
- package/dist/commonjs/lib/createObjectTransform.js +14 -0
- package/dist/commonjs/lib/createPropertyTransform.d.ts +7 -0
- package/dist/commonjs/lib/createPropertyTransform.d.ts.map +1 -0
- package/dist/commonjs/lib/createPropertyTransform.js +11 -0
- package/dist/commonjs/lib/createTypeScriptWatchProgram.d.ts +16 -0
- package/dist/commonjs/lib/createTypeScriptWatchProgram.d.ts.map +1 -0
- package/dist/commonjs/lib/createTypeScriptWatchProgram.js +45 -0
- package/dist/commonjs/lib/styleTransform.d.ts +23 -0
- package/dist/commonjs/lib/styleTransform.d.ts.map +1 -0
- package/dist/commonjs/lib/styleTransform.js +131 -0
- package/dist/commonjs/lib/utils/createStyleObjectNode.d.ts +35 -0
- package/dist/commonjs/lib/utils/createStyleObjectNode.d.ts.map +1 -0
- package/dist/commonjs/lib/utils/createStyleObjectNode.js +84 -0
- package/dist/commonjs/lib/utils/getCssVariables.d.ts +4 -0
- package/dist/commonjs/lib/utils/getCssVariables.d.ts.map +1 -0
- package/dist/commonjs/lib/utils/getCssVariables.js +31 -0
- package/dist/commonjs/lib/utils/getErrorMessage.d.ts +16 -0
- package/dist/commonjs/lib/utils/getErrorMessage.d.ts.map +1 -0
- package/dist/commonjs/lib/utils/getErrorMessage.js +45 -0
- package/dist/commonjs/lib/utils/getFallbackVariable.d.ts +9 -0
- package/dist/commonjs/lib/utils/getFallbackVariable.d.ts.map +1 -0
- package/dist/commonjs/lib/utils/getFallbackVariable.js +30 -0
- package/dist/commonjs/lib/utils/getHash.d.ts +4 -0
- package/dist/commonjs/lib/utils/getHash.d.ts.map +1 -0
- package/dist/commonjs/lib/utils/getHash.js +16 -0
- package/dist/commonjs/lib/utils/getVarName.d.ts +17 -0
- package/dist/commonjs/lib/utils/getVarName.d.ts.map +1 -0
- package/dist/commonjs/lib/utils/getVarName.js +34 -0
- package/dist/commonjs/lib/utils/handleCalc.d.ts +2 -0
- package/dist/commonjs/lib/utils/handleCalc.d.ts.map +1 -0
- package/dist/commonjs/lib/utils/handleCalc.js +33 -0
- package/dist/commonjs/lib/utils/handleCreateStencil.d.ts +7 -0
- package/dist/commonjs/lib/utils/handleCreateStencil.d.ts.map +1 -0
- package/dist/commonjs/lib/utils/handleCreateStencil.js +309 -0
- package/dist/commonjs/lib/utils/handleCreateStyles.d.ts +3 -0
- package/dist/commonjs/lib/utils/handleCreateStyles.d.ts.map +1 -0
- package/dist/commonjs/lib/utils/handleCreateStyles.js +86 -0
- package/dist/commonjs/lib/utils/handleCreateVars.d.ts +3 -0
- package/dist/commonjs/lib/utils/handleCreateVars.d.ts.map +1 -0
- package/dist/commonjs/lib/utils/handleCreateVars.js +65 -0
- package/dist/commonjs/lib/utils/handleCssVar.d.ts +2 -0
- package/dist/commonjs/lib/utils/handleCssVar.d.ts.map +1 -0
- package/dist/commonjs/lib/utils/handleCssVar.js +19 -0
- package/dist/commonjs/lib/utils/handleInjectGlobal.d.ts +3 -0
- package/dist/commonjs/lib/utils/handleInjectGlobal.d.ts.map +1 -0
- package/dist/commonjs/lib/utils/handleInjectGlobal.js +40 -0
- package/dist/commonjs/lib/utils/handleKeyframes.d.ts +3 -0
- package/dist/commonjs/lib/utils/handleKeyframes.d.ts.map +1 -0
- package/dist/commonjs/lib/utils/handleKeyframes.js +48 -0
- package/dist/commonjs/lib/utils/handleParentModifier.d.ts +2 -0
- package/dist/commonjs/lib/utils/handleParentModifier.d.ts.map +1 -0
- package/dist/commonjs/lib/utils/handleParentModifier.js +26 -0
- package/dist/commonjs/lib/utils/handlePx2Rem.d.ts +2 -0
- package/dist/commonjs/lib/utils/handlePx2Rem.d.ts.map +1 -0
- package/dist/commonjs/lib/utils/handlePx2Rem.js +19 -0
- package/dist/commonjs/lib/utils/injectStyles.d.ts +3 -0
- package/dist/commonjs/lib/utils/injectStyles.d.ts.map +1 -0
- package/dist/commonjs/lib/utils/injectStyles.js +11 -0
- package/dist/commonjs/lib/utils/isImportedFromStyling.d.ts +7 -0
- package/dist/commonjs/lib/utils/isImportedFromStyling.d.ts.map +1 -0
- package/dist/commonjs/lib/utils/isImportedFromStyling.js +24 -0
- package/dist/commonjs/lib/utils/parseNodeToStaticValue.d.ts +11 -0
- package/dist/commonjs/lib/utils/parseNodeToStaticValue.d.ts.map +1 -0
- package/dist/commonjs/lib/utils/parseNodeToStaticValue.js +217 -0
- package/dist/commonjs/lib/utils/parseObjectToStaticValue.d.ts +15 -0
- package/dist/commonjs/lib/utils/parseObjectToStaticValue.d.ts.map +1 -0
- package/dist/commonjs/lib/utils/parseObjectToStaticValue.js +168 -0
- package/dist/commonjs/lib/utils/stylisFns.d.ts +3 -0
- package/dist/commonjs/lib/utils/stylisFns.d.ts.map +1 -0
- package/dist/commonjs/lib/utils/stylisFns.js +45 -0
- package/dist/commonjs/lib/utils/types.d.ts +210 -0
- package/dist/commonjs/lib/utils/types.d.ts.map +1 -0
- package/dist/commonjs/lib/utils/types.js +2 -0
- package/dist/commonjs/lib/webpack-loader.d.ts +7 -0
- package/dist/commonjs/lib/webpack-loader.d.ts.map +1 -0
- package/dist/commonjs/lib/webpack-loader.js +21 -0
- package/dist/commonjs/lib/webpackPlugin.d.ts +31 -0
- package/dist/commonjs/lib/webpackPlugin.d.ts.map +1 -0
- package/dist/commonjs/lib/webpackPlugin.js +38 -0
- package/dist/commonjs/spec/createProgramFromSource.d.ts +8 -0
- package/dist/commonjs/spec/createProgramFromSource.d.ts.map +1 -0
- package/dist/commonjs/spec/createProgramFromSource.js +111 -0
- package/dist/commonjs/spec/findNodes.d.ts +3 -0
- package/dist/commonjs/spec/findNodes.d.ts.map +1 -0
- package/dist/commonjs/spec/findNodes.js +33 -0
- package/dist/commonjs/testing.d.ts +4 -0
- package/dist/commonjs/testing.d.ts.map +1 -0
- package/dist/commonjs/testing.js +11 -0
- package/dist/es6/index.d.ts +14 -0
- package/dist/es6/index.d.ts.map +1 -0
- package/dist/es6/index.js +14 -0
- package/dist/es6/lib/createObjectTransform.d.ts +10 -0
- package/dist/es6/lib/createObjectTransform.d.ts.map +1 -0
- package/dist/es6/lib/createObjectTransform.js +10 -0
- package/dist/es6/lib/createPropertyTransform.d.ts +7 -0
- package/dist/es6/lib/createPropertyTransform.d.ts.map +1 -0
- package/dist/es6/lib/createPropertyTransform.js +7 -0
- package/dist/es6/lib/createTypeScriptWatchProgram.d.ts +16 -0
- package/dist/es6/lib/createTypeScriptWatchProgram.d.ts.map +1 -0
- package/dist/es6/lib/createTypeScriptWatchProgram.js +36 -0
- package/dist/es6/lib/styleTransform.d.ts +23 -0
- package/dist/es6/lib/styleTransform.d.ts.map +1 -0
- package/dist/es6/lib/styleTransform.js +120 -0
- package/dist/es6/lib/utils/createStyleObjectNode.d.ts +35 -0
- package/dist/es6/lib/utils/createStyleObjectNode.d.ts.map +1 -0
- package/dist/es6/lib/utils/createStyleObjectNode.js +74 -0
- package/dist/es6/lib/utils/getCssVariables.d.ts +4 -0
- package/dist/es6/lib/utils/getCssVariables.d.ts.map +1 -0
- package/dist/es6/lib/utils/getCssVariables.js +26 -0
- package/dist/es6/lib/utils/getErrorMessage.d.ts +16 -0
- package/dist/es6/lib/utils/getErrorMessage.d.ts.map +1 -0
- package/dist/es6/lib/utils/getErrorMessage.js +41 -0
- package/dist/es6/lib/utils/getFallbackVariable.d.ts +9 -0
- package/dist/es6/lib/utils/getFallbackVariable.d.ts.map +1 -0
- package/dist/es6/lib/utils/getFallbackVariable.js +26 -0
- package/dist/es6/lib/utils/getHash.d.ts +4 -0
- package/dist/es6/lib/utils/getHash.d.ts.map +1 -0
- package/dist/es6/lib/utils/getHash.js +9 -0
- package/dist/es6/lib/utils/getVarName.d.ts +17 -0
- package/dist/es6/lib/utils/getVarName.d.ts.map +1 -0
- package/dist/es6/lib/utils/getVarName.js +27 -0
- package/dist/es6/lib/utils/handleCalc.d.ts +2 -0
- package/dist/es6/lib/utils/handleCalc.d.ts.map +1 -0
- package/dist/es6/lib/utils/handleCalc.js +27 -0
- package/dist/es6/lib/utils/handleCreateStencil.d.ts +7 -0
- package/dist/es6/lib/utils/handleCreateStencil.d.ts.map +1 -0
- package/dist/es6/lib/utils/handleCreateStencil.js +301 -0
- package/dist/es6/lib/utils/handleCreateStyles.d.ts +3 -0
- package/dist/es6/lib/utils/handleCreateStyles.d.ts.map +1 -0
- package/dist/es6/lib/utils/handleCreateStyles.js +79 -0
- package/dist/es6/lib/utils/handleCreateVars.d.ts +3 -0
- package/dist/es6/lib/utils/handleCreateVars.d.ts.map +1 -0
- package/dist/es6/lib/utils/handleCreateVars.js +58 -0
- package/dist/es6/lib/utils/handleCssVar.d.ts +2 -0
- package/dist/es6/lib/utils/handleCssVar.d.ts.map +1 -0
- package/dist/es6/lib/utils/handleCssVar.js +13 -0
- package/dist/es6/lib/utils/handleInjectGlobal.d.ts +3 -0
- package/dist/es6/lib/utils/handleInjectGlobal.d.ts.map +1 -0
- package/dist/es6/lib/utils/handleInjectGlobal.js +33 -0
- package/dist/es6/lib/utils/handleKeyframes.d.ts +3 -0
- package/dist/es6/lib/utils/handleKeyframes.d.ts.map +1 -0
- package/dist/es6/lib/utils/handleKeyframes.js +41 -0
- package/dist/es6/lib/utils/handleParentModifier.d.ts +2 -0
- package/dist/es6/lib/utils/handleParentModifier.d.ts.map +1 -0
- package/dist/es6/lib/utils/handleParentModifier.js +20 -0
- package/dist/es6/lib/utils/handlePx2Rem.d.ts +2 -0
- package/dist/es6/lib/utils/handlePx2Rem.d.ts.map +1 -0
- package/dist/es6/lib/utils/handlePx2Rem.js +13 -0
- package/dist/es6/lib/utils/injectStyles.d.ts +3 -0
- package/dist/es6/lib/utils/injectStyles.d.ts.map +1 -0
- package/dist/es6/lib/utils/injectStyles.js +7 -0
- package/dist/es6/lib/utils/isImportedFromStyling.d.ts +7 -0
- package/dist/es6/lib/utils/isImportedFromStyling.d.ts.map +1 -0
- package/dist/es6/lib/utils/isImportedFromStyling.js +17 -0
- package/dist/es6/lib/utils/parseNodeToStaticValue.d.ts +11 -0
- package/dist/es6/lib/utils/parseNodeToStaticValue.d.ts.map +1 -0
- package/dist/es6/lib/utils/parseNodeToStaticValue.js +209 -0
- package/dist/es6/lib/utils/parseObjectToStaticValue.d.ts +15 -0
- package/dist/es6/lib/utils/parseObjectToStaticValue.d.ts.map +1 -0
- package/dist/es6/lib/utils/parseObjectToStaticValue.js +159 -0
- package/dist/es6/lib/utils/stylisFns.d.ts +3 -0
- package/dist/es6/lib/utils/stylisFns.d.ts.map +1 -0
- package/dist/es6/lib/utils/stylisFns.js +41 -0
- package/dist/es6/lib/utils/types.d.ts +210 -0
- package/dist/es6/lib/utils/types.d.ts.map +1 -0
- package/dist/es6/lib/utils/types.js +1 -0
- package/dist/es6/lib/webpack-loader.d.ts +7 -0
- package/dist/es6/lib/webpack-loader.d.ts.map +1 -0
- package/dist/es6/lib/webpack-loader.js +15 -0
- package/dist/es6/lib/webpackPlugin.d.ts +31 -0
- package/dist/es6/lib/webpackPlugin.d.ts.map +1 -0
- package/dist/es6/lib/webpackPlugin.js +31 -0
- package/dist/es6/spec/createProgramFromSource.d.ts +8 -0
- package/dist/es6/spec/createProgramFromSource.d.ts.map +1 -0
- package/dist/es6/spec/createProgramFromSource.js +81 -0
- package/dist/es6/spec/findNodes.d.ts +3 -0
- package/dist/es6/spec/findNodes.d.ts.map +1 -0
- package/dist/es6/spec/findNodes.js +26 -0
- package/dist/es6/testing.d.ts +4 -0
- package/dist/es6/testing.d.ts.map +1 -0
- package/dist/es6/testing.js +3 -0
- package/index.ts +19 -0
- package/lib/createObjectTransform.ts +12 -0
- package/lib/createPropertyTransform.ts +9 -0
- package/lib/createTypeScriptWatchProgram.ts +52 -0
- package/lib/styleTransform.ts +169 -0
- package/lib/utils/createStyleObjectNode.ts +105 -0
- package/lib/utils/getCssVariables.ts +36 -0
- package/lib/utils/getErrorMessage.ts +57 -0
- package/lib/utils/getFallbackVariable.ts +34 -0
- package/lib/utils/getHash.ts +13 -0
- package/lib/utils/getVarName.ts +32 -0
- package/lib/utils/handleCalc.ts +33 -0
- package/lib/utils/handleCreateStencil.ts +442 -0
- package/lib/utils/handleCreateStyles.ts +97 -0
- package/lib/utils/handleCreateVars.ts +90 -0
- package/lib/utils/handleCssVar.ts +19 -0
- package/lib/utils/handleInjectGlobal.ts +51 -0
- package/lib/utils/handleKeyframes.ts +60 -0
- package/lib/utils/handleParentModifier.ts +29 -0
- package/lib/utils/handlePx2Rem.ts +22 -0
- package/lib/utils/injectStyles.ts +14 -0
- package/lib/utils/isImportedFromStyling.ts +21 -0
- package/lib/utils/parseNodeToStaticValue.ts +281 -0
- package/lib/utils/parseObjectToStaticValue.ts +201 -0
- package/lib/utils/stylisFns.ts +56 -0
- package/lib/utils/types.ts +223 -0
- package/lib/webpack-loader.ts +28 -0
- package/lib/webpackPlugin.ts +69 -0
- package/package.json +19 -14
- package/index.js +0 -22
|
@@ -0,0 +1,16 @@
|
|
|
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.getHash = void 0;
|
|
7
|
+
const node_crypto_1 = __importDefault(require("node:crypto"));
|
|
8
|
+
function getHash(node, context) {
|
|
9
|
+
const fileName = context.getFileName(node.getSourceFile().fileName);
|
|
10
|
+
return node_crypto_1.default
|
|
11
|
+
.createHash('md5')
|
|
12
|
+
.update(fileName + node.pos) // file name + position should be unique and repeatable
|
|
13
|
+
.digest('hex')
|
|
14
|
+
.substring(0, 6);
|
|
15
|
+
}
|
|
16
|
+
exports.getHash = getHash;
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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,CAetE"}
|
|
@@ -0,0 +1,34 @@
|
|
|
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 &&
|
|
29
|
+
(typescript_1.default.isIdentifier(node.name) || typescript_1.default.isStringLiteral(node.name))) {
|
|
30
|
+
return getVarName(node.parent, [node.name.text, ...parts]);
|
|
31
|
+
}
|
|
32
|
+
return getVarName(node.parent, parts);
|
|
33
|
+
}
|
|
34
|
+
exports.getVarName = getVarName;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handleCalc.d.ts","sourceRoot":"","sources":["../../../../lib/utils/handleCalc.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,UAAU,qCA0BrB,CAAC"}
|
|
@@ -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.handleCalc = 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.handleCalc = (0, createPropertyTransform_1.createPropertyTransform)((node, context) => {
|
|
12
|
+
if (typescript_1.default.isCallExpression(node) &&
|
|
13
|
+
typescript_1.default.isPropertyAccessExpression(node.expression) &&
|
|
14
|
+
typescript_1.default.isIdentifier(node.expression.expression) &&
|
|
15
|
+
node.expression.expression.text === 'calc' &&
|
|
16
|
+
typescript_1.default.isIdentifier(node.expression.name)) {
|
|
17
|
+
function toStaticValue(node) {
|
|
18
|
+
return (0, parseNodeToStaticValue_1.parseNodeToStaticValue)(node, context);
|
|
19
|
+
}
|
|
20
|
+
const args = node.arguments;
|
|
21
|
+
const method = node.expression.name.text;
|
|
22
|
+
if (method === 'add' || method === 'subtract') {
|
|
23
|
+
return canvas_kit_styling_1.calc[method](toStaticValue(args[0]).toString(), toStaticValue(args[1]).toString());
|
|
24
|
+
}
|
|
25
|
+
if (method === 'multiply' || method === 'divide') {
|
|
26
|
+
return canvas_kit_styling_1.calc[method](toStaticValue(args[0]).toString(), toStaticValue(args[1]));
|
|
27
|
+
}
|
|
28
|
+
if (method === 'negate') {
|
|
29
|
+
return canvas_kit_styling_1.calc.negate(toStaticValue(args[0]).toString());
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return;
|
|
33
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { NodeTransformer, TransformerContext } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Handle all arguments of the CallExpression `createStencil()`
|
|
4
|
+
*/
|
|
5
|
+
export declare const handleCreateStencil: NodeTransformer;
|
|
6
|
+
export declare function getClassName(name: string, { prefix }: TransformerContext): string;
|
|
7
|
+
//# sourceMappingURL=handleCreateStencil.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handleCreateStencil.d.ts","sourceRoot":"","sources":["../../../../lib/utils/handleCreateStencil.ts"],"names":[],"mappings":"AAQA,OAAO,EAAoB,eAAe,EAAE,kBAAkB,EAAC,MAAM,SAAS,CAAC;AAI/E;;GAEG;AACH,eAAO,MAAM,mBAAmB,EAAE,eAwTjC,CAAC;AAuFF,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,EAAC,MAAM,EAAC,EAAE,kBAAkB,GAAG,MAAM,CAW/E"}
|
|
@@ -0,0 +1,309 @@
|
|
|
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.getClassName = exports.handleCreateStencil = void 0;
|
|
7
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
8
|
+
const canvas_kit_styling_1 = require("@workday/canvas-kit-styling");
|
|
9
|
+
const getVarName_1 = require("./getVarName");
|
|
10
|
+
const parseObjectToStaticValue_1 = require("./parseObjectToStaticValue");
|
|
11
|
+
const createStyleObjectNode_1 = require("./createStyleObjectNode");
|
|
12
|
+
const parseNodeToStaticValue_1 = require("./parseNodeToStaticValue");
|
|
13
|
+
const isImportedFromStyling_1 = require("./isImportedFromStyling");
|
|
14
|
+
const getHash_1 = require("./getHash");
|
|
15
|
+
/**
|
|
16
|
+
* Handle all arguments of the CallExpression `createStencil()`
|
|
17
|
+
*/
|
|
18
|
+
const handleCreateStencil = (node, context) => {
|
|
19
|
+
const { checker, names, extractedNames } = context;
|
|
20
|
+
/**
|
|
21
|
+
* This will match whenever a `createStencil()` call expression is encountered. It will loop
|
|
22
|
+
* over all the config to extract variables and styles.
|
|
23
|
+
*
|
|
24
|
+
*/
|
|
25
|
+
if (typescript_1.default.isCallExpression(node) &&
|
|
26
|
+
typescript_1.default.isIdentifier(node.expression) &&
|
|
27
|
+
node.expression.text === 'createStencil' &&
|
|
28
|
+
(0, isImportedFromStyling_1.isImportedFromStyling)(node.expression, checker)) {
|
|
29
|
+
const config = node.arguments[0];
|
|
30
|
+
// We need to keep track of stencil variables and values to automatically merge into the base
|
|
31
|
+
// styles
|
|
32
|
+
const stencilVariables = {};
|
|
33
|
+
// Stencil name is the variable name
|
|
34
|
+
const stencilName = (0, getVarName_1.getVarName)(node.expression);
|
|
35
|
+
const stencilHash = (0, getHash_1.getHash)(node, context);
|
|
36
|
+
if (typescript_1.default.isObjectLiteralExpression(config)) {
|
|
37
|
+
config.properties.forEach(property => {
|
|
38
|
+
if (typescript_1.default.isPropertyAssignment(property) &&
|
|
39
|
+
property.name &&
|
|
40
|
+
typescript_1.default.isIdentifier(property.name) &&
|
|
41
|
+
property.name.text === 'extends' &&
|
|
42
|
+
typescript_1.default.isIdentifier(property.initializer)) {
|
|
43
|
+
const className = getClassName(property.initializer.text, context);
|
|
44
|
+
const extendsStencilName = property.initializer.text;
|
|
45
|
+
if (!Object.values(context.styles).some(fileStyles => {
|
|
46
|
+
return fileStyles.some(rule => rule.includes(`.${className}`));
|
|
47
|
+
})) {
|
|
48
|
+
// Process the extended stencil since those styles haven't been processed yet
|
|
49
|
+
(0, parseNodeToStaticValue_1.getValueFromAliasedSymbol)(property.initializer, '', context);
|
|
50
|
+
}
|
|
51
|
+
// attach all variables from extends stencil
|
|
52
|
+
Object.keys(names).forEach(key => {
|
|
53
|
+
if (key.startsWith(`${extendsStencilName}.`)) {
|
|
54
|
+
// We want to copy a new entry into variables that is the extended stencil with the same variable name as the base variable name
|
|
55
|
+
names[key.replace(extendsStencilName, stencilName)] = names[key];
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
// get variables first
|
|
61
|
+
const varsConfig = config.properties.find(property => {
|
|
62
|
+
return (property.name &&
|
|
63
|
+
typescript_1.default.isIdentifier(property.name) &&
|
|
64
|
+
property.name.text === 'vars' &&
|
|
65
|
+
typescript_1.default.isPropertyAssignment(property));
|
|
66
|
+
});
|
|
67
|
+
function extractNames(node) {
|
|
68
|
+
if (typescript_1.default.isPropertyAssignment(node) && typescript_1.default.isIdentifier(node.name)) {
|
|
69
|
+
if (typescript_1.default.isObjectLiteralExpression(node.initializer)) {
|
|
70
|
+
return node.initializer.properties.map(extractNames);
|
|
71
|
+
}
|
|
72
|
+
const varName = (0, getVarName_1.getVarName)(node.name);
|
|
73
|
+
const varValue = `--${getClassName(varName, context)}`;
|
|
74
|
+
names[varName] = `--${node.name.text}-${(0, canvas_kit_styling_1.slugify)(stencilName).replace('-stencil', '')}-${stencilHash}`;
|
|
75
|
+
names[node.name.text] = names[varName];
|
|
76
|
+
extractedNames[names[varName]] = varValue;
|
|
77
|
+
// Evaluate the variable defaults
|
|
78
|
+
const value = (0, parseNodeToStaticValue_1.parseNodeToStaticValue)(node.initializer, context).toString();
|
|
79
|
+
if (value) {
|
|
80
|
+
// Only add the stencil variable if there's a value. An empty string means no default.
|
|
81
|
+
stencilVariables[names[varName]] = String((0, parseObjectToStaticValue_1.maybeWrapCSSVariables)(value, names));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (varsConfig && typescript_1.default.isObjectLiteralExpression(varsConfig.initializer)) {
|
|
86
|
+
varsConfig.initializer.properties.forEach(variable => {
|
|
87
|
+
extractNames(variable);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
const configProperties = config.properties.map((property, index, properties) => {
|
|
91
|
+
if (property.name && typescript_1.default.isIdentifier(property.name)) {
|
|
92
|
+
// base config object
|
|
93
|
+
if (property.name.text === 'base') {
|
|
94
|
+
const styleObj = parseStyleBlock(property, context, stencilName);
|
|
95
|
+
if (styleObj) {
|
|
96
|
+
const initializer = createStyleReplacementNode(property, {
|
|
97
|
+
...stencilVariables,
|
|
98
|
+
boxSizing: 'border-box',
|
|
99
|
+
...styleObj,
|
|
100
|
+
}, getClassName((0, getVarName_1.getVarName)(property.name), context), context);
|
|
101
|
+
return updateStyleProperty(property, initializer);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
// modifiers config object
|
|
105
|
+
if (property.name.text === 'modifiers' &&
|
|
106
|
+
typescript_1.default.isPropertyAssignment(property) &&
|
|
107
|
+
typescript_1.default.isObjectLiteralExpression(property.initializer)) {
|
|
108
|
+
// modifier key
|
|
109
|
+
return typescript_1.default.factory.updatePropertyAssignment(property, property.name, typescript_1.default.factory.updateObjectLiteralExpression(property.initializer, property.initializer.properties.map(modifierProperty => {
|
|
110
|
+
if (typescript_1.default.isPropertyAssignment(modifierProperty) &&
|
|
111
|
+
modifierProperty.name &&
|
|
112
|
+
typescript_1.default.isIdentifier(modifierProperty.name) &&
|
|
113
|
+
typescript_1.default.isObjectLiteralExpression(modifierProperty.initializer)) {
|
|
114
|
+
// modifier value
|
|
115
|
+
return typescript_1.default.factory.updatePropertyAssignment(modifierProperty, modifierProperty.name, typescript_1.default.factory.updateObjectLiteralExpression(modifierProperty.initializer, modifierProperty.initializer.properties.map(modifier => {
|
|
116
|
+
const styleObj = parseStyleBlock(modifier, context, getClassName(stencilName, context));
|
|
117
|
+
if (styleObj && modifier.name) {
|
|
118
|
+
const stencilClassName = getClassName(stencilName, context);
|
|
119
|
+
const fullModifierName = getClassName((0, getVarName_1.getVarName)(modifier.name), context);
|
|
120
|
+
const className = `${stencilClassName}.${fullModifierName.replace(`${stencilClassName}--`, '')}`;
|
|
121
|
+
const initializer = createStyleReplacementNode(modifier, styleObj, className, context);
|
|
122
|
+
return updateStyleProperty(modifier, initializer);
|
|
123
|
+
}
|
|
124
|
+
return modifier;
|
|
125
|
+
})));
|
|
126
|
+
}
|
|
127
|
+
return property;
|
|
128
|
+
})));
|
|
129
|
+
}
|
|
130
|
+
// compound config array
|
|
131
|
+
/**
|
|
132
|
+
* Compound config array. It looks like:
|
|
133
|
+
*
|
|
134
|
+
* ```ts
|
|
135
|
+
* compound: [
|
|
136
|
+
* {
|
|
137
|
+
* modifiers: { size: 'large', iconPosition: 'start' },
|
|
138
|
+
* styles: { padding: 20 }
|
|
139
|
+
* }
|
|
140
|
+
* ]
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
if (property.name.text === 'compound' &&
|
|
144
|
+
typescript_1.default.isPropertyAssignment(property) &&
|
|
145
|
+
typescript_1.default.isArrayLiteralExpression(property.initializer)) {
|
|
146
|
+
return typescript_1.default.factory.updatePropertyAssignment(property, property.name, typescript_1.default.factory.updateArrayLiteralExpression(property.initializer, property.initializer.elements.map(element => {
|
|
147
|
+
if (typescript_1.default.isObjectLiteralExpression(element)) {
|
|
148
|
+
const selectors = [];
|
|
149
|
+
selectors.push(`.${getClassName(stencilName, context)}`);
|
|
150
|
+
return typescript_1.default.factory.updateObjectLiteralExpression(element, element.properties.map((compoundProperty, index, compoundProperties) => {
|
|
151
|
+
/**
|
|
152
|
+
* If the property is `modifiers`, we want to extract selectors from it. For
|
|
153
|
+
* example,
|
|
154
|
+
*
|
|
155
|
+
* ```ts
|
|
156
|
+
* const button = createStencil({
|
|
157
|
+
* // other config
|
|
158
|
+
* compound: {
|
|
159
|
+
* modifiers: { size: 'large', inverse: true },
|
|
160
|
+
* styles: {}
|
|
161
|
+
* }
|
|
162
|
+
* })
|
|
163
|
+
* ```
|
|
164
|
+
*
|
|
165
|
+
* After this, `selectors` should contain ['.button--size-large',
|
|
166
|
+
* '.button--inverse']
|
|
167
|
+
*/
|
|
168
|
+
if (compoundProperty.name &&
|
|
169
|
+
typescript_1.default.isIdentifier(compoundProperty.name) &&
|
|
170
|
+
compoundProperty.name.text === 'modifiers' &&
|
|
171
|
+
typescript_1.default.isPropertyAssignment(compoundProperty) &&
|
|
172
|
+
typescript_1.default.isObjectLiteralExpression(compoundProperty.initializer)) {
|
|
173
|
+
compoundProperty.initializer.properties.forEach(modifier => {
|
|
174
|
+
if (typescript_1.default.isPropertyAssignment(modifier)) {
|
|
175
|
+
let className = '';
|
|
176
|
+
if (typescript_1.default.isIdentifier(modifier.name)) {
|
|
177
|
+
className = (0, canvas_kit_styling_1.slugify)(modifier.name.text);
|
|
178
|
+
}
|
|
179
|
+
// The initializer should either be the `true` keyword or a string
|
|
180
|
+
// literal. We don't add `-true` to the name.
|
|
181
|
+
if (typescript_1.default.isStringLiteral(modifier.initializer)) {
|
|
182
|
+
className += `-${modifier.initializer.text}`;
|
|
183
|
+
}
|
|
184
|
+
selectors.push(className);
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
return compoundProperty;
|
|
188
|
+
}
|
|
189
|
+
// styles key
|
|
190
|
+
if (compoundProperty.name &&
|
|
191
|
+
typescript_1.default.isIdentifier(compoundProperty.name) &&
|
|
192
|
+
compoundProperty.name.text === 'styles') {
|
|
193
|
+
const styleObj = parseStyleBlock(compoundProperty, context, stencilName);
|
|
194
|
+
if (styleObj) {
|
|
195
|
+
// We need to inject compound style selectors into a file. We'll compound the
|
|
196
|
+
// selectors with multiple class names. This will increase specificity of compound
|
|
197
|
+
// selectors. This will be harder to override and we don't increase specificity in
|
|
198
|
+
// the runtime implementation, but runtime creates an extra CSS class name that
|
|
199
|
+
// isn't known to anyone. It seems unreasonable to expect CSS users to remember to
|
|
200
|
+
// add compound modifier class names. We'll make it so it is easier to author
|
|
201
|
+
// components in CSS and let them sort the specificity issues.
|
|
202
|
+
const serialized = (0, createStyleObjectNode_1.serializeStyles)(compoundProperty, styleObj, `${selectors.join('.')}{%s}`, context);
|
|
203
|
+
const initializer = (0, createStyleObjectNode_1.createStyleObjectNode)(serialized.styles, serialized.name);
|
|
204
|
+
return updateStyleProperty(compoundProperty, initializer);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return compoundProperty;
|
|
208
|
+
}));
|
|
209
|
+
}
|
|
210
|
+
return element;
|
|
211
|
+
})));
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return property;
|
|
215
|
+
});
|
|
216
|
+
return typescript_1.default.factory.updateCallExpression(node, node.expression, undefined, [
|
|
217
|
+
typescript_1.default.factory.updateObjectLiteralExpression(config, configProperties),
|
|
218
|
+
typescript_1.default.factory.createStringLiteral(`${(0, canvas_kit_styling_1.slugify)(stencilName).replace('-stencil', '')}-${stencilHash}`),
|
|
219
|
+
]);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return;
|
|
223
|
+
};
|
|
224
|
+
exports.handleCreateStencil = handleCreateStencil;
|
|
225
|
+
/**
|
|
226
|
+
* A style block is a `base`, `modifier`, or `compoundModifier` style block. It could be an ObjectLiteralExpression,
|
|
227
|
+
* an ArrowFunction, MethodDeclaration, etc.
|
|
228
|
+
*/
|
|
229
|
+
function parseStyleBlock(property, context, stencilName) {
|
|
230
|
+
let styleObj;
|
|
231
|
+
if (typescript_1.default.isPropertyAssignment(property)) {
|
|
232
|
+
if (typescript_1.default.isObjectLiteralExpression(property.initializer)) {
|
|
233
|
+
styleObj = (0, parseObjectToStaticValue_1.parseObjectToStaticValue)(property.initializer, {
|
|
234
|
+
...context,
|
|
235
|
+
nameScope: `${stencilName}.vars.`,
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
if (isFunctionLikeDeclaration(property.initializer)) {
|
|
239
|
+
const returnNode = getReturnStatement(property.initializer);
|
|
240
|
+
if (returnNode) {
|
|
241
|
+
styleObj = (0, parseObjectToStaticValue_1.parseObjectToStaticValue)(returnNode, {
|
|
242
|
+
...context,
|
|
243
|
+
nameScope: `${stencilName}.vars.`,
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
if (isFunctionLikeDeclaration(property)) {
|
|
249
|
+
const returnNode = getReturnStatement(property);
|
|
250
|
+
if (returnNode) {
|
|
251
|
+
styleObj = (0, parseObjectToStaticValue_1.parseObjectToStaticValue)(returnNode, {
|
|
252
|
+
...context,
|
|
253
|
+
nameScope: `${stencilName}.vars.`,
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return styleObj;
|
|
258
|
+
}
|
|
259
|
+
function getReturnStatement(node) {
|
|
260
|
+
if (node.body && typescript_1.default.isParenthesizedExpression(node.body)) {
|
|
261
|
+
return node.body.expression;
|
|
262
|
+
}
|
|
263
|
+
if (node.body && typescript_1.default.isBlock(node.body)) {
|
|
264
|
+
let returnNode;
|
|
265
|
+
// look for the return statement. It must be a top-level statement in the block
|
|
266
|
+
node.body.statements.forEach(statement => {
|
|
267
|
+
// () => { return {} }
|
|
268
|
+
if (typescript_1.default.isReturnStatement(statement)) {
|
|
269
|
+
returnNode = statement.expression;
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
return returnNode;
|
|
273
|
+
}
|
|
274
|
+
return undefined;
|
|
275
|
+
}
|
|
276
|
+
function isFunctionLikeDeclaration(node) {
|
|
277
|
+
return node.hasOwnProperty('body');
|
|
278
|
+
}
|
|
279
|
+
function createStyleReplacementNode(node, styleObj, className, context) {
|
|
280
|
+
const { names, extractedNames } = context;
|
|
281
|
+
const serialized = (0, createStyleObjectNode_1.serializeStyles)(node, styleObj, `.${className}{%s}`, context);
|
|
282
|
+
const varName = (0, getVarName_1.getVarName)(node);
|
|
283
|
+
const value = `css-${serialized.name}`;
|
|
284
|
+
names[varName] = value;
|
|
285
|
+
extractedNames[value] = getClassName(varName, context);
|
|
286
|
+
return (0, createStyleObjectNode_1.createStyleObjectNode)(serialized.styles, serialized.name);
|
|
287
|
+
}
|
|
288
|
+
function getClassName(name, { prefix }) {
|
|
289
|
+
return (`${prefix}-` +
|
|
290
|
+
(0, canvas_kit_styling_1.slugify)(name)
|
|
291
|
+
.replace('-vars', '')
|
|
292
|
+
.replace('-stencil', '')
|
|
293
|
+
.replace('-base', '')
|
|
294
|
+
.replace('-modifiers', '-')
|
|
295
|
+
.replace('-true', '')
|
|
296
|
+
.replace('-compound', ''));
|
|
297
|
+
}
|
|
298
|
+
exports.getClassName = getClassName;
|
|
299
|
+
/**
|
|
300
|
+
* If the property is a `PropertyAssignment`, use the TypeScript factory updater to maximize
|
|
301
|
+
* sourcemap use. Otherwise, return a new property assignment. For example, a Stencil could be using
|
|
302
|
+
* a `MethodDeclaration` which means we return a different node type: `base({color}) {}`
|
|
303
|
+
*/
|
|
304
|
+
function updateStyleProperty(property, initializer) {
|
|
305
|
+
if (typescript_1.default.isPropertyAssignment(property)) {
|
|
306
|
+
return typescript_1.default.factory.updatePropertyAssignment(property, property.name, initializer);
|
|
307
|
+
}
|
|
308
|
+
return typescript_1.default.factory.createPropertyAssignment(property.name, initializer);
|
|
309
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handleCreateStyles.d.ts","sourceRoot":"","sources":["../../../../lib/utils/handleCreateStyles.ts"],"names":[],"mappings":"AAIA,OAAO,EAAoB,eAAe,EAAqB,MAAM,SAAS,CAAC;AAK/E,eAAO,MAAM,kBAAkB,EAAE,eA4EhC,CAAC"}
|
|
@@ -0,0 +1,86 @@
|
|
|
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.handleCreateStyles = void 0;
|
|
7
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
8
|
+
const parseObjectToStaticValue_1 = require("./parseObjectToStaticValue");
|
|
9
|
+
const createStyleObjectNode_1 = require("./createStyleObjectNode");
|
|
10
|
+
const isImportedFromStyling_1 = require("./isImportedFromStyling");
|
|
11
|
+
const getVarName_1 = require("./getVarName");
|
|
12
|
+
const canvas_kit_styling_1 = require("@workday/canvas-kit-styling");
|
|
13
|
+
const handleCreateStyles = (node, context) => {
|
|
14
|
+
const { checker, prefix } = context;
|
|
15
|
+
/**
|
|
16
|
+
* Check if the node is a call expression that looks like:
|
|
17
|
+
*
|
|
18
|
+
* ```ts
|
|
19
|
+
* createStyles({
|
|
20
|
+
* // properties
|
|
21
|
+
* })
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* It will also make sure the `createStyles` function was imported from
|
|
25
|
+
* `@workday/canvas-kit-styling` to ensure we don't rewrite the AST of code we don't own.
|
|
26
|
+
*
|
|
27
|
+
* This transformation will pre-serialize the style objects and turn them into strings for
|
|
28
|
+
* faster runtime processing in Emotion. The following is an example of the transformation.
|
|
29
|
+
*
|
|
30
|
+
* ```ts
|
|
31
|
+
* // before transformation
|
|
32
|
+
* const myStyles = createStyles({
|
|
33
|
+
* fontSize: '1rem'
|
|
34
|
+
* })
|
|
35
|
+
*
|
|
36
|
+
* // after transformation
|
|
37
|
+
* const myStyles = createStyles({
|
|
38
|
+
* name: 'abc123',
|
|
39
|
+
* styles: 'font-size: 1rem;'
|
|
40
|
+
* })
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* The after transformation already serialized the styles and goes through a shortcut process
|
|
44
|
+
* in `@emotion/css` where only the Emotion cache is checked and styles are inserted if the
|
|
45
|
+
* cache key wasn't found.
|
|
46
|
+
*/
|
|
47
|
+
if (typescript_1.default.isCallExpression(node) &&
|
|
48
|
+
typescript_1.default.isIdentifier(node.expression) &&
|
|
49
|
+
node.expression.text === 'createStyles' &&
|
|
50
|
+
(0, isImportedFromStyling_1.isImportedFromStyling)(node.expression, checker) &&
|
|
51
|
+
node.arguments.length > 0) {
|
|
52
|
+
const cssClassName = `${prefix}-${(0, canvas_kit_styling_1.slugify)((0, getVarName_1.getVarName)(node.expression))
|
|
53
|
+
.replace('-styles', '')
|
|
54
|
+
.replace('-modifiers', '-')
|
|
55
|
+
.replace('-true', '')}`;
|
|
56
|
+
const newArguments = [...node.arguments].map(arg => {
|
|
57
|
+
// An `ObjectLiteralExpression` is an object like `{foo:'bar'}`:
|
|
58
|
+
// https://ts-ast-viewer.com/#code/MYewdgzgLgBFCmBbADjAvDA3gKBjAZiCAFwwDkARgIYBOZ2AvkA
|
|
59
|
+
if (typescript_1.default.isObjectLiteralExpression(arg)) {
|
|
60
|
+
const styleObj = (0, parseObjectToStaticValue_1.parseObjectToStaticValue)(arg, context);
|
|
61
|
+
return createStyleReplacementNode(node, styleObj, cssClassName, context);
|
|
62
|
+
}
|
|
63
|
+
// An Identifier is a variable. It could come from anywhere - imports, earlier
|
|
64
|
+
// assignments, etc. The easiest thing to do is to ask the TypeScript type checker what
|
|
65
|
+
// the type representation is and go from there.
|
|
66
|
+
if (typescript_1.default.isIdentifier(arg)) {
|
|
67
|
+
const type = checker.getTypeAtLocation(arg);
|
|
68
|
+
// `createStyles` accepts strings as class names. If the class name is
|
|
69
|
+
if (type.isStringLiteral() || type.getFlags() & typescript_1.default.TypeFlags.String) {
|
|
70
|
+
return arg;
|
|
71
|
+
}
|
|
72
|
+
// The type must be a object
|
|
73
|
+
const styleObj = (0, parseObjectToStaticValue_1.parseStyleObjFromType)(type, context);
|
|
74
|
+
return createStyleReplacementNode(node, styleObj, cssClassName, context);
|
|
75
|
+
}
|
|
76
|
+
return arg;
|
|
77
|
+
});
|
|
78
|
+
return typescript_1.default.factory.updateCallExpression(node, node.expression, [], newArguments);
|
|
79
|
+
}
|
|
80
|
+
return;
|
|
81
|
+
};
|
|
82
|
+
exports.handleCreateStyles = handleCreateStyles;
|
|
83
|
+
function createStyleReplacementNode(node, styleObj, className, context) {
|
|
84
|
+
const serialized = (0, createStyleObjectNode_1.serializeStyles)(node, styleObj, `.${className}{%s}`, context);
|
|
85
|
+
return (0, createStyleObjectNode_1.createStyleObjectNode)(serialized.styles, serialized.name);
|
|
86
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handleCreateVars.d.ts","sourceRoot":"","sources":["../../../../lib/utils/handleCreateVars.ts"],"names":[],"mappings":"AAKA,OAAO,EAAC,eAAe,EAAqB,MAAM,SAAS,CAAC;AAG5D,eAAO,MAAM,gBAAgB,EAAE,eA+D9B,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
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.handleCreateVars = void 0;
|
|
7
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
8
|
+
const canvas_kit_styling_1 = require("@workday/canvas-kit-styling");
|
|
9
|
+
const getVarName_1 = require("./getVarName");
|
|
10
|
+
const getHash_1 = require("./getHash");
|
|
11
|
+
const handleCreateVars = (node, context) => {
|
|
12
|
+
/**
|
|
13
|
+
* This will create a variable
|
|
14
|
+
*/
|
|
15
|
+
if (typescript_1.default.isCallExpression(node) &&
|
|
16
|
+
typescript_1.default.isIdentifier(node.expression) &&
|
|
17
|
+
node.expression.text === 'createVars') {
|
|
18
|
+
const { id, vars } = addNames(node, context);
|
|
19
|
+
return typescript_1.default.factory.updateCallExpression(node, node.expression, [], [
|
|
20
|
+
typescript_1.default.factory.createObjectLiteralExpression([
|
|
21
|
+
typescript_1.default.factory.createPropertyAssignment(typescript_1.default.factory.createIdentifier('id'), typescript_1.default.factory.createStringLiteral(id)),
|
|
22
|
+
typescript_1.default.factory.createPropertyAssignment(typescript_1.default.factory.createIdentifier('args'), typescript_1.default.factory.createArrayLiteralExpression(vars.map(val => typescript_1.default.factory.createStringLiteral(val)), false)),
|
|
23
|
+
], false),
|
|
24
|
+
]);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Check to see if this node is an ObjectLiteralExpression with properties with `createVars`
|
|
28
|
+
* values.
|
|
29
|
+
*
|
|
30
|
+
* ```ts
|
|
31
|
+
* const foo = {
|
|
32
|
+
* bar: createVars('color')
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* This happens when names are imported from other files. We don't need to transform this, but
|
|
37
|
+
* we'll need to add names for property parsing.
|
|
38
|
+
*/
|
|
39
|
+
if (typescript_1.default.isObjectLiteralExpression(node)) {
|
|
40
|
+
node.properties.forEach(property => {
|
|
41
|
+
if (typescript_1.default.isPropertyAssignment(property) &&
|
|
42
|
+
typescript_1.default.isCallExpression(property.initializer) &&
|
|
43
|
+
typescript_1.default.isIdentifier(property.initializer.expression) &&
|
|
44
|
+
property.initializer.expression.text === 'createVars') {
|
|
45
|
+
addNames(property.initializer, context);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
return;
|
|
50
|
+
};
|
|
51
|
+
exports.handleCreateVars = handleCreateVars;
|
|
52
|
+
function addNames(node, context) {
|
|
53
|
+
const { prefix, names, extractedNames } = context;
|
|
54
|
+
const hash = (0, getHash_1.getHash)(node, context);
|
|
55
|
+
const varNamePrefix = (0, getVarName_1.getVarName)(node);
|
|
56
|
+
const vars = node.arguments
|
|
57
|
+
.map(arg => typescript_1.default.isStringLiteral(arg) && arg.text)
|
|
58
|
+
.filter(Boolean);
|
|
59
|
+
vars.forEach(v => {
|
|
60
|
+
const varName = `${varNamePrefix}.${v}`;
|
|
61
|
+
names[varName] = `--${v}-${hash}`;
|
|
62
|
+
extractedNames[names[varName]] = `--${prefix}-${(0, canvas_kit_styling_1.slugify)(varName).replace('-vars', '')}`;
|
|
63
|
+
});
|
|
64
|
+
return { id: hash, vars };
|
|
65
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handleCssVar.d.ts","sourceRoot":"","sources":["../../../../lib/utils/handleCssVar.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,YAAY,qCAYvB,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.handleCssVar = 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.handleCssVar = (0, createPropertyTransform_1.createPropertyTransform)((node, context) => {
|
|
12
|
+
if (typescript_1.default.isCallExpression(node) &&
|
|
13
|
+
typescript_1.default.isIdentifier(node.expression) &&
|
|
14
|
+
node.expression.text === 'cssVar') {
|
|
15
|
+
const args = node.arguments.map(arg => (0, parseNodeToStaticValue_1.parseNodeToStaticValue)(arg, context));
|
|
16
|
+
return (0, canvas_kit_styling_1.cssVar)(args[0], args[1] || context.names[args[0]]);
|
|
17
|
+
}
|
|
18
|
+
return;
|
|
19
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handleInjectGlobal.d.ts","sourceRoot":"","sources":["../../../../lib/utils/handleInjectGlobal.ts"],"names":[],"mappings":"AAKA,OAAO,EAAoB,eAAe,EAAqB,MAAM,SAAS,CAAC;AAG/E,eAAO,MAAM,kBAAkB,EAAE,eAgChC,CAAC"}
|