@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.
- 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,14 @@
|
|
|
1
|
+
import styleTransformer from './lib/styleTransform';
|
|
2
|
+
import type { Config } from './lib/utils/types';
|
|
3
|
+
export type * from './lib/utils/types';
|
|
4
|
+
export { parseNodeToStaticValue } from './lib/utils/parseNodeToStaticValue';
|
|
5
|
+
export { parseObjectToStaticValue } from './lib/utils/parseObjectToStaticValue';
|
|
6
|
+
export { createObjectTransform } from './lib/createObjectTransform';
|
|
7
|
+
export { createPropertyTransform } from './lib/createPropertyTransform';
|
|
8
|
+
export { styleTransformer };
|
|
9
|
+
export { withDefaultContext } from './lib/styleTransform';
|
|
10
|
+
export { getClassName } from './lib/utils/handleCreateStencil';
|
|
11
|
+
export { StylingWebpackPlugin } from './lib/webpackPlugin';
|
|
12
|
+
export default styleTransformer;
|
|
13
|
+
export declare function createConfig(config: Config): Config;
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../index.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,MAAM,sBAAsB,CAAC;AACpD,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,mBAAmB,CAAC;AAE9C,mBAAmB,mBAAmB,CAAC;AACvC,OAAO,EAAC,sBAAsB,EAAC,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAC,wBAAwB,EAAC,MAAM,sCAAsC,CAAC;AAC9E,OAAO,EAAC,qBAAqB,EAAC,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAC,uBAAuB,EAAC,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAC,gBAAgB,EAAC,CAAC;AAC1B,OAAO,EAAC,kBAAkB,EAAC,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAC,YAAY,EAAC,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EAAC,oBAAoB,EAAC,MAAM,qBAAqB,CAAC;AAGzD,eAAe,gBAAgB,CAAC;AAEhC,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEnD"}
|
|
@@ -0,0 +1,28 @@
|
|
|
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.createConfig = exports.StylingWebpackPlugin = exports.getClassName = exports.withDefaultContext = exports.styleTransformer = exports.createPropertyTransform = exports.createObjectTransform = exports.parseObjectToStaticValue = exports.parseNodeToStaticValue = void 0;
|
|
7
|
+
const styleTransform_1 = __importDefault(require("./lib/styleTransform"));
|
|
8
|
+
exports.styleTransformer = styleTransform_1.default;
|
|
9
|
+
var parseNodeToStaticValue_1 = require("./lib/utils/parseNodeToStaticValue");
|
|
10
|
+
Object.defineProperty(exports, "parseNodeToStaticValue", { enumerable: true, get: function () { return parseNodeToStaticValue_1.parseNodeToStaticValue; } });
|
|
11
|
+
var parseObjectToStaticValue_1 = require("./lib/utils/parseObjectToStaticValue");
|
|
12
|
+
Object.defineProperty(exports, "parseObjectToStaticValue", { enumerable: true, get: function () { return parseObjectToStaticValue_1.parseObjectToStaticValue; } });
|
|
13
|
+
var createObjectTransform_1 = require("./lib/createObjectTransform");
|
|
14
|
+
Object.defineProperty(exports, "createObjectTransform", { enumerable: true, get: function () { return createObjectTransform_1.createObjectTransform; } });
|
|
15
|
+
var createPropertyTransform_1 = require("./lib/createPropertyTransform");
|
|
16
|
+
Object.defineProperty(exports, "createPropertyTransform", { enumerable: true, get: function () { return createPropertyTransform_1.createPropertyTransform; } });
|
|
17
|
+
var styleTransform_2 = require("./lib/styleTransform");
|
|
18
|
+
Object.defineProperty(exports, "withDefaultContext", { enumerable: true, get: function () { return styleTransform_2.withDefaultContext; } });
|
|
19
|
+
var handleCreateStencil_1 = require("./lib/utils/handleCreateStencil");
|
|
20
|
+
Object.defineProperty(exports, "getClassName", { enumerable: true, get: function () { return handleCreateStencil_1.getClassName; } });
|
|
21
|
+
var webpackPlugin_1 = require("./lib/webpackPlugin");
|
|
22
|
+
Object.defineProperty(exports, "StylingWebpackPlugin", { enumerable: true, get: function () { return webpackPlugin_1.StylingWebpackPlugin; } });
|
|
23
|
+
// be compatible with ts-patch which expects a default export
|
|
24
|
+
exports.default = styleTransform_1.default;
|
|
25
|
+
function createConfig(config) {
|
|
26
|
+
return config;
|
|
27
|
+
}
|
|
28
|
+
exports.createConfig = createConfig;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ObjectTransform } from './utils/types';
|
|
2
|
+
/**
|
|
3
|
+
* Object transforms take an AST node that represents a style object and turn it into a
|
|
4
|
+
* `NestedStyleObject` or return `void`. If an object transform returns an object, transformation
|
|
5
|
+
* parsing stops on that node. If `void` is returned, processing continues using
|
|
6
|
+
* `parseObjectToStaticValue`. These transforms are useful if you have custom utility functions
|
|
7
|
+
* that are not statically parsable by the static styling transformer.
|
|
8
|
+
*/
|
|
9
|
+
export declare function createObjectTransform(transformFn: ObjectTransform): ObjectTransform;
|
|
10
|
+
//# sourceMappingURL=createObjectTransform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createObjectTransform.d.ts","sourceRoot":"","sources":["../../../lib/createObjectTransform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAC,MAAM,eAAe,CAAC;AAE9C;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,WAAW,EAAE,eAAe,GAAG,eAAe,CAEnF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createObjectTransform = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Object transforms take an AST node that represents a style object and turn it into a
|
|
6
|
+
* `NestedStyleObject` or return `void`. If an object transform returns an object, transformation
|
|
7
|
+
* parsing stops on that node. If `void` is returned, processing continues using
|
|
8
|
+
* `parseObjectToStaticValue`. These transforms are useful if you have custom utility functions
|
|
9
|
+
* that are not statically parsable by the static styling transformer.
|
|
10
|
+
*/
|
|
11
|
+
function createObjectTransform(transformFn) {
|
|
12
|
+
return transformFn;
|
|
13
|
+
}
|
|
14
|
+
exports.createObjectTransform = createObjectTransform;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { PropertyTransform } from './utils/types';
|
|
2
|
+
/**
|
|
3
|
+
* A property transform takes a style property node and will return a string. You can use
|
|
4
|
+
* `parseNodeToStaticValue` to help you process properties that might be inputs to a function.
|
|
5
|
+
*/
|
|
6
|
+
export declare function createPropertyTransform(transformFn: PropertyTransform): PropertyTransform;
|
|
7
|
+
//# sourceMappingURL=createPropertyTransform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createPropertyTransform.d.ts","sourceRoot":"","sources":["../../../lib/createPropertyTransform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,iBAAiB,EAAC,MAAM,eAAe,CAAC;AAEhD;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,WAAW,EAAE,iBAAiB,GAAG,iBAAiB,CAEzF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createPropertyTransform = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* A property transform takes a style property node and will return a string. You can use
|
|
6
|
+
* `parseNodeToStaticValue` to help you process properties that might be inputs to a function.
|
|
7
|
+
*/
|
|
8
|
+
function createPropertyTransform(transformFn) {
|
|
9
|
+
return transformFn;
|
|
10
|
+
}
|
|
11
|
+
exports.createPropertyTransform = createPropertyTransform;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
/** Get the contents of the tsconfig in the system */
|
|
3
|
+
export declare function getTSConfigFile(tsconfigPath: string): ts.ParsedCommandLine;
|
|
4
|
+
export declare const getCompilerOptions: (tsconfigPath: string) => ts.CompilerOptions;
|
|
5
|
+
/**
|
|
6
|
+
* Create a watch program for TypeScript with transformers. It watches the specified
|
|
7
|
+
* tsconfigPath for changes and updates the program when changes are detected.
|
|
8
|
+
*
|
|
9
|
+
* @param compilerOptions - The compiler options to use.
|
|
10
|
+
* @param tsconfigPath - The path to the tsconfig file.
|
|
11
|
+
* @param onProgramCreatedOrUpdated - A callback function
|
|
12
|
+
* that is called when the program is created or updated.
|
|
13
|
+
* @returns
|
|
14
|
+
*/
|
|
15
|
+
export declare const startWatch: (compilerOptions: ts.CompilerOptions, tsconfigPath: string, onProgramCreatedOrUpdated: (program: ts.BuilderProgram) => void) => [ts.BuilderProgram, () => void];
|
|
16
|
+
//# sourceMappingURL=createTypeScriptWatchProgram.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createTypeScriptWatchProgram.d.ts","sourceRoot":"","sources":["../../../lib/createTypeScriptWatchProgram.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,qDAAqD;AACrD,wBAAgB,eAAe,CAAC,YAAY,EAAE,MAAM,wBAKnD;AAED,eAAO,MAAM,kBAAkB,iBAAkB,MAAM,uBAWtD,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,UAAU,oBACJ,GAAG,eAAe,gBACrB,MAAM,uCACiB,GAAG,cAAc,KAAK,IAAI,KAC9D,CAAC,GAAG,cAAc,EAAE,MAAM,IAAI,CAahC,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
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.startWatch = exports.getCompilerOptions = exports.getTSConfigFile = void 0;
|
|
7
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
9
|
+
/** Get the contents of the tsconfig in the system */
|
|
10
|
+
function getTSConfigFile(tsconfigPath) {
|
|
11
|
+
const basePath = node_path_1.default.dirname(tsconfigPath);
|
|
12
|
+
const configFile = typescript_1.default.readConfigFile(tsconfigPath, typescript_1.default.sys.readFile);
|
|
13
|
+
return typescript_1.default.parseJsonConfigFileContent(configFile.config, typescript_1.default.sys, basePath, {}, tsconfigPath);
|
|
14
|
+
}
|
|
15
|
+
exports.getTSConfigFile = getTSConfigFile;
|
|
16
|
+
const getCompilerOptions = (tsconfigPath) => {
|
|
17
|
+
let compilerOptions = {
|
|
18
|
+
jsx: typescript_1.default.JsxEmit.React,
|
|
19
|
+
module: typescript_1.default.ModuleKind.CommonJS,
|
|
20
|
+
target: typescript_1.default.ScriptTarget.Latest,
|
|
21
|
+
};
|
|
22
|
+
const { options: tsOptions } = getTSConfigFile(tsconfigPath);
|
|
23
|
+
compilerOptions = { ...compilerOptions, ...tsOptions };
|
|
24
|
+
return compilerOptions;
|
|
25
|
+
};
|
|
26
|
+
exports.getCompilerOptions = getCompilerOptions;
|
|
27
|
+
/**
|
|
28
|
+
* Create a watch program for TypeScript with transformers. It watches the specified
|
|
29
|
+
* tsconfigPath for changes and updates the program when changes are detected.
|
|
30
|
+
*
|
|
31
|
+
* @param compilerOptions - The compiler options to use.
|
|
32
|
+
* @param tsconfigPath - The path to the tsconfig file.
|
|
33
|
+
* @param onProgramCreatedOrUpdated - A callback function
|
|
34
|
+
* that is called when the program is created or updated.
|
|
35
|
+
* @returns
|
|
36
|
+
*/
|
|
37
|
+
const startWatch = (compilerOptions, tsconfigPath, onProgramCreatedOrUpdated) => {
|
|
38
|
+
const host = typescript_1.default.createWatchCompilerHost(tsconfigPath, compilerOptions, typescript_1.default.sys, typescript_1.default.createSemanticDiagnosticsBuilderProgram);
|
|
39
|
+
host.afterProgramCreate = builderProgram => {
|
|
40
|
+
onProgramCreatedOrUpdated(builderProgram);
|
|
41
|
+
};
|
|
42
|
+
const watch = typescript_1.default.createWatchProgram(host);
|
|
43
|
+
return [watch.getProgram(), watch.close];
|
|
44
|
+
};
|
|
45
|
+
exports.startWatch = startWatch;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import { NodeTransformer, TransformerContext } from './utils/types';
|
|
3
|
+
export type NestedStyleObject = {
|
|
4
|
+
[key: string]: string | NestedStyleObject;
|
|
5
|
+
};
|
|
6
|
+
export interface StyleTransformerOptions extends TransformerContext {
|
|
7
|
+
fallbackFiles?: string[];
|
|
8
|
+
transformers?: NodeTransformer[];
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The reset is used in tests and should not be called normally.
|
|
12
|
+
*/
|
|
13
|
+
export declare function _reset(): void;
|
|
14
|
+
export default styleTransformer;
|
|
15
|
+
export declare function styleTransformer(program: ts.Program, { fallbackFiles, ...options }?: Partial<StyleTransformerOptions>): ts.TransformerFactory<ts.SourceFile>;
|
|
16
|
+
export declare function withDefaultContext(checker: ts.TypeChecker, { transformers, ...input }?: Partial<StyleTransformerOptions>): TransformerContext;
|
|
17
|
+
/**
|
|
18
|
+
* This function is useful for tests or a custom build. The `styleTransformer` function is used by
|
|
19
|
+
* the https://www.npmjs.com/package/ts-patch package.
|
|
20
|
+
*/
|
|
21
|
+
export declare function transform(program: ts.Program, fileName?: string, options?: Partial<StyleTransformerOptions>): string;
|
|
22
|
+
export declare function getConfig(basePath?: string): string | undefined;
|
|
23
|
+
//# sourceMappingURL=styleTransform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"styleTransform.d.ts","sourceRoot":"","sources":["../../../lib/styleTransform.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,YAAY,CAAC;AAY5B,OAAO,EAAC,eAAe,EAAmB,kBAAkB,EAAC,MAAM,eAAe,CAAC;AAEnF,MAAM,MAAM,iBAAiB,GAAG;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,iBAAiB,CAAA;CAAC,CAAC;AAE5E,MAAM,WAAW,uBAAwB,SAAQ,kBAAkB;IACjE,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,YAAY,CAAC,EAAE,eAAe,EAAE,CAAC;CAClC;AAQD;;GAEG;AACH,wBAAgB,MAAM,SAMrB;AAYD,eAAe,gBAAgB,CAAC;AAChC,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,EAAE,CAAC,OAAO,EACnB,EAAC,aAAkB,EAAE,GAAG,OAAO,EAAC,GAAE,OAAO,CAAC,uBAAuB,CAAM,GACtE,EAAE,CAAC,kBAAkB,CAAC,EAAE,CAAC,UAAU,CAAC,CAsDtC;AAED,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,EAAE,CAAC,WAAW,EACvB,EAAC,YAAY,EAAE,GAAG,KAAK,EAAC,GAAE,OAAO,CAAC,uBAAuB,CAAM,GAC9D,kBAAkB,CAmBpB;AAED;;;GAGG;AACH,wBAAgB,SAAS,CACvB,OAAO,EAAE,EAAE,CAAC,OAAO,EACnB,QAAQ,SAAY,EACpB,OAAO,CAAC,EAAE,OAAO,CAAC,uBAAuB,CAAC,UAa3C;AAUD,wBAAgB,SAAS,CAAC,QAAQ,SAAM,sBAIvC"}
|
|
@@ -0,0 +1,131 @@
|
|
|
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.getConfig = exports.transform = exports.withDefaultContext = exports.styleTransformer = exports._reset = void 0;
|
|
7
|
+
/// <reference types="node" />
|
|
8
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
10
|
+
const getCssVariables_1 = require("./utils/getCssVariables");
|
|
11
|
+
const handleCalc_1 = require("./utils/handleCalc");
|
|
12
|
+
const handleCreateStencil_1 = require("./utils/handleCreateStencil");
|
|
13
|
+
const handleCreateStyles_1 = require("./utils/handleCreateStyles");
|
|
14
|
+
const handleCreateVars_1 = require("./utils/handleCreateVars");
|
|
15
|
+
const handleCssVar_1 = require("./utils/handleCssVar");
|
|
16
|
+
const handleInjectGlobal_1 = require("./utils/handleInjectGlobal");
|
|
17
|
+
const handleKeyframes_1 = require("./utils/handleKeyframes");
|
|
18
|
+
const handleParentModifier_1 = require("./utils/handleParentModifier");
|
|
19
|
+
const handlePx2Rem_1 = require("./utils/handlePx2Rem");
|
|
20
|
+
let vars = {};
|
|
21
|
+
let extractedNames = {};
|
|
22
|
+
let styles = {};
|
|
23
|
+
let cache = {};
|
|
24
|
+
let loadedFallbacks = false;
|
|
25
|
+
/**
|
|
26
|
+
* The reset is used in tests and should not be called normally.
|
|
27
|
+
*/
|
|
28
|
+
function _reset() {
|
|
29
|
+
vars = {};
|
|
30
|
+
extractedNames = {};
|
|
31
|
+
styles = {};
|
|
32
|
+
cache = {};
|
|
33
|
+
loadedFallbacks = false;
|
|
34
|
+
}
|
|
35
|
+
exports._reset = _reset;
|
|
36
|
+
/**
|
|
37
|
+
* Optional list of transformers. Useful to override for tests
|
|
38
|
+
*/
|
|
39
|
+
const defaultTransformers = [
|
|
40
|
+
handleKeyframes_1.handleKeyframes,
|
|
41
|
+
handleCreateVars_1.handleCreateVars,
|
|
42
|
+
handleCreateStyles_1.handleCreateStyles,
|
|
43
|
+
handleCreateStencil_1.handleCreateStencil,
|
|
44
|
+
handleInjectGlobal_1.handleInjectGlobal,
|
|
45
|
+
];
|
|
46
|
+
exports.default = styleTransformer;
|
|
47
|
+
function styleTransformer(program, { fallbackFiles = [], ...options } = {}) {
|
|
48
|
+
const { names, ...transformContext } = withDefaultContext(program.getTypeChecker(), options);
|
|
49
|
+
if (!loadedFallbacks) {
|
|
50
|
+
const files = fallbackFiles
|
|
51
|
+
.filter(file => file) // don't process empty files
|
|
52
|
+
.map(file => {
|
|
53
|
+
// Find the fully-qualified path name. This could error which should give "module not found" errors
|
|
54
|
+
return file.startsWith('.') ? node_path_1.default.resolve(process.cwd(), file) : require.resolve(file);
|
|
55
|
+
})
|
|
56
|
+
.map(file => {
|
|
57
|
+
console.log(`Loading CSS variable fallback file: ${file}`);
|
|
58
|
+
return typescript_1.default.sys.readFile(file) || '';
|
|
59
|
+
});
|
|
60
|
+
const fallbackVars = (0, getCssVariables_1.getVariablesFromFiles)(files);
|
|
61
|
+
console.log(`Found ${Object.keys(fallbackVars).length} variables.`);
|
|
62
|
+
// eslint-disable-next-line guard-for-in
|
|
63
|
+
for (const key in fallbackVars) {
|
|
64
|
+
names[key] = fallbackVars[key];
|
|
65
|
+
}
|
|
66
|
+
loadedFallbacks = true;
|
|
67
|
+
}
|
|
68
|
+
return context => {
|
|
69
|
+
const visit = node => {
|
|
70
|
+
var _a;
|
|
71
|
+
if (!transformContext.fileName) {
|
|
72
|
+
transformContext.fileName = (_a = node.getSourceFile()) === null || _a === void 0 ? void 0 : _a.fileName;
|
|
73
|
+
transformContext.prefix = transformContext.getPrefix(transformContext.fileName);
|
|
74
|
+
}
|
|
75
|
+
if (typescript_1.default.isSourceFile(node) &&
|
|
76
|
+
node.fileName !== 'test.ts' &&
|
|
77
|
+
transformContext.styles[transformContext.getFileName(node.fileName)] &&
|
|
78
|
+
transformContext.extractCSS) {
|
|
79
|
+
typescript_1.default.sys.writeFile(transformContext.getFileName(transformContext.getFileName(node.fileName)), (transformContext.styles[transformContext.getFileName(node.fileName)] || []).join('\n'));
|
|
80
|
+
}
|
|
81
|
+
const newNode = transformContext.transform(node, {
|
|
82
|
+
names,
|
|
83
|
+
...transformContext,
|
|
84
|
+
});
|
|
85
|
+
return newNode || typescript_1.default.visitEachChild(node, visit, context);
|
|
86
|
+
};
|
|
87
|
+
return (node => typescript_1.default.visitNode(node, visit));
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
exports.styleTransformer = styleTransformer;
|
|
91
|
+
function withDefaultContext(checker, { transformers, ...input } = {}) {
|
|
92
|
+
return {
|
|
93
|
+
prefix: 'css',
|
|
94
|
+
getPrefix: path => input.prefix || 'css',
|
|
95
|
+
names: vars,
|
|
96
|
+
extractedNames,
|
|
97
|
+
styles,
|
|
98
|
+
cache,
|
|
99
|
+
checker,
|
|
100
|
+
seed: '',
|
|
101
|
+
extractCSS: false,
|
|
102
|
+
getFileName: path => path.replace(/\.tsx?/, '.css'),
|
|
103
|
+
objectTransforms: [],
|
|
104
|
+
transform: handleTransformers(transformers || defaultTransformers),
|
|
105
|
+
...input,
|
|
106
|
+
propertyTransforms: [handleCalc_1.handleCalc, handlePx2Rem_1.handlePx2Rem, handleCssVar_1.handleCssVar, handleParentModifier_1.handleParentModifier].concat(input.propertyTransforms || []),
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
exports.withDefaultContext = withDefaultContext;
|
|
110
|
+
/**
|
|
111
|
+
* This function is useful for tests or a custom build. The `styleTransformer` function is used by
|
|
112
|
+
* the https://www.npmjs.com/package/ts-patch package.
|
|
113
|
+
*/
|
|
114
|
+
function transform(program, fileName = 'test.ts', options) {
|
|
115
|
+
const source = program.getSourceFile(fileName) || typescript_1.default.createSourceFile(fileName, '', typescript_1.default.ScriptTarget.ES2019);
|
|
116
|
+
const printer = typescript_1.default.createPrinter();
|
|
117
|
+
const transformers = [styleTransformer(program, options)];
|
|
118
|
+
return printer.printFile(typescript_1.default.transform(source, transformers).transformed.find(s => s.fileName === source.fileName) ||
|
|
119
|
+
source);
|
|
120
|
+
}
|
|
121
|
+
exports.transform = transform;
|
|
122
|
+
const handleTransformers = (transformers) => (node, context) => {
|
|
123
|
+
return transformers.reduce((result, transformer) => {
|
|
124
|
+
return result || transformer(node, context);
|
|
125
|
+
}, undefined);
|
|
126
|
+
};
|
|
127
|
+
function getConfig(basePath = '.') {
|
|
128
|
+
const tsconfigPath = typescript_1.default.findConfigFile(basePath, typescript_1.default.sys.fileExists, 'styling.config.ts');
|
|
129
|
+
return tsconfigPath;
|
|
130
|
+
}
|
|
131
|
+
exports.getConfig = getConfig;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import { NestedStyleObject, TransformerContext } from './types';
|
|
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(styles: string, name?: string): ts.ObjectLiteralExpression;
|
|
14
|
+
/**
|
|
15
|
+
* Compiles CSS using stylis. Emotion's `serializeStyles` creates an unwrapped string for cache
|
|
16
|
+
* storage and it often needs to be wrapped by a CSS selector or `@keyframes`. This function does
|
|
17
|
+
* this the same way Emotion does it internally.
|
|
18
|
+
*/
|
|
19
|
+
export declare function compileCSS(input: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* Serialize styles and put them to style output. The styles will be serialized via Emotion. Returns
|
|
22
|
+
* the serialized styles.
|
|
23
|
+
* @param node
|
|
24
|
+
* @param input
|
|
25
|
+
* @param template The template for creating styles for static CSS. There are two placeholders: `%n`
|
|
26
|
+
* represents the hash name while `%s` represents the string styles.
|
|
27
|
+
* @param context
|
|
28
|
+
* @returns
|
|
29
|
+
*/
|
|
30
|
+
export declare function serializeStyles(node: ts.Node, input: NestedStyleObject | string, template: string, context: TransformerContext): import("@emotion/utils").SerializedStyles;
|
|
31
|
+
/**
|
|
32
|
+
* Generate a deterministic hash that is unique to the seed +
|
|
33
|
+
*/
|
|
34
|
+
export declare function getHash(node: ts.Node, context: TransformerContext): string;
|
|
35
|
+
//# sourceMappingURL=createStyleObjectNode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createStyleObjectNode.d.ts","sourceRoot":"","sources":["../../../../lib/utils/createStyleObjectNode.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,YAAY,CAAC;AAK5B,OAAO,EAAC,iBAAiB,EAAE,kBAAkB,EAAC,MAAM,SAAS,CAAC;AAE9D;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,8BAkBlE;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,EAAE,CAAC,IAAI,EACb,KAAK,EAAE,iBAAiB,GAAG,MAAM,EACjC,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,kBAAkB,6CA8B5B;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,kBAAkB,UAMjE"}
|
|
@@ -0,0 +1,84 @@
|
|
|
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 = exports.serializeStyles = exports.compileCSS = exports.createStyleObjectNode = void 0;
|
|
7
|
+
const serialize_1 = require("@emotion/serialize");
|
|
8
|
+
const node_crypto_1 = __importDefault(require("node:crypto"));
|
|
9
|
+
const stylis_1 = require("stylis");
|
|
10
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
11
|
+
const canvas_kit_styling_1 = require("@workday/canvas-kit-styling");
|
|
12
|
+
const stylisFns_1 = require("./stylisFns");
|
|
13
|
+
/**
|
|
14
|
+
* Creates an AST node representation of the passed in `styleObj`, but in the format of `{name:
|
|
15
|
+
* string, styles: serializedStyles}`. The `name` is hard-coded here to work with both server-side
|
|
16
|
+
* and client-side style injection. This results in a stable style key for Emotion while also
|
|
17
|
+
* optimizing style serialization.
|
|
18
|
+
*
|
|
19
|
+
* If `name` is provided, the name will be whatever `name` is, replacing "{hash}" with the hash
|
|
20
|
+
* created via `serializeStyles`. For example: 'animation-{hash}' will be converted into
|
|
21
|
+
* 'animation-abc123'
|
|
22
|
+
*/
|
|
23
|
+
function createStyleObjectNode(styles, name) {
|
|
24
|
+
const styleExpression = typescript_1.default.factory.createStringLiteral(styles);
|
|
25
|
+
// create an emotion-optimized object: https://github.com/emotion-js/emotion/blob/f3b268f7c52103979402da919c9c0dd3f9e0e189/packages/serialize/src/index.js#L315-L322
|
|
26
|
+
// Looks like: `{name: $hash, styles: $styleText }`
|
|
27
|
+
return typescript_1.default.factory.createObjectLiteralExpression([
|
|
28
|
+
typescript_1.default.factory.createPropertyAssignment(typescript_1.default.factory.createIdentifier('name'), typescript_1.default.factory.createStringLiteral(name || (0, 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
|
|
29
|
+
),
|
|
30
|
+
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
|
|
31
|
+
),
|
|
32
|
+
], false);
|
|
33
|
+
}
|
|
34
|
+
exports.createStyleObjectNode = createStyleObjectNode;
|
|
35
|
+
/**
|
|
36
|
+
* Compiles CSS using stylis. Emotion's `serializeStyles` creates an unwrapped string for cache
|
|
37
|
+
* storage and it often needs to be wrapped by a CSS selector or `@keyframes`. This function does
|
|
38
|
+
* this the same way Emotion does it internally.
|
|
39
|
+
*/
|
|
40
|
+
function compileCSS(input) {
|
|
41
|
+
return (0, stylis_1.serialize)((0, stylis_1.compile)(input), stylisFns_1.prettyStringify);
|
|
42
|
+
}
|
|
43
|
+
exports.compileCSS = compileCSS;
|
|
44
|
+
/**
|
|
45
|
+
* Serialize styles and put them to style output. The styles will be serialized via Emotion. Returns
|
|
46
|
+
* the serialized styles.
|
|
47
|
+
* @param node
|
|
48
|
+
* @param input
|
|
49
|
+
* @param template The template for creating styles for static CSS. There are two placeholders: `%n`
|
|
50
|
+
* represents the hash name while `%s` represents the string styles.
|
|
51
|
+
* @param context
|
|
52
|
+
* @returns
|
|
53
|
+
*/
|
|
54
|
+
function serializeStyles(node, input, template, context) {
|
|
55
|
+
const { getFileName, styles, cache, names, extractedNames } = context;
|
|
56
|
+
const fileName = getFileName(node.getSourceFile().fileName);
|
|
57
|
+
const serialized = (0, serialize_1.serializeStyles)([input]);
|
|
58
|
+
const hash = getHash(node, context);
|
|
59
|
+
serialized.name = hash;
|
|
60
|
+
if (!cache[hash]) {
|
|
61
|
+
const styleOutput = compileCSS(template.replace('%s', serialized.styles).replace('%n', serialized.name));
|
|
62
|
+
let extractedStyleOutput = styleOutput;
|
|
63
|
+
for (const key in names) {
|
|
64
|
+
if (extractedNames[names[key]]) {
|
|
65
|
+
// @ts-ignore replaceAll was added in es2021, but our lib versions don't go past es2019. replaceAll is available in node 15+
|
|
66
|
+
extractedStyleOutput = extractedStyleOutput.replaceAll(names[key], extractedNames[names[key]]);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
styles[fileName] = styles[fileName] || [];
|
|
70
|
+
styles[fileName].push(extractedStyleOutput);
|
|
71
|
+
cache[hash] = styleOutput;
|
|
72
|
+
}
|
|
73
|
+
return serialized;
|
|
74
|
+
}
|
|
75
|
+
exports.serializeStyles = serializeStyles;
|
|
76
|
+
/**
|
|
77
|
+
* Generate a deterministic hash that is unique to the seed +
|
|
78
|
+
*/
|
|
79
|
+
function getHash(node, context) {
|
|
80
|
+
const content = context.seed + node.getStart() + node.getEnd();
|
|
81
|
+
// Convert content to a sha256 hash and then convert to a base36 number for better compression
|
|
82
|
+
return Number(`0x${node_crypto_1.default.createHash('sha256').update(content).digest('hex').slice(0, 7)}`).toString(36);
|
|
83
|
+
}
|
|
84
|
+
exports.getHash = getHash;
|
|
@@ -0,0 +1,4 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,31 @@
|
|
|
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((0, stylis_1.compile)(file));
|
|
8
|
+
return { ...result, ...extractVariables((0, 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;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import { TransformerContext } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Creates an error message around a node. It will look something like:
|
|
5
|
+
*
|
|
6
|
+
* ```
|
|
7
|
+
* Unknown type at: "fontSize".
|
|
8
|
+
* File: test.ts, Line: 6, Character: 17.
|
|
9
|
+
* const styles = createStyles({
|
|
10
|
+
* fontSize: fontSize
|
|
11
|
+
* ========
|
|
12
|
+
* })
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare function getErrorMessage(node: ts.Node, context: TransformerContext): string;
|
|
16
|
+
//# sourceMappingURL=getErrorMessage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getErrorMessage.d.ts","sourceRoot":"","sources":["../../../../lib/utils/getErrorMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAC,kBAAkB,EAAC,MAAM,SAAS,CAAC;AAE3C;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,kBAAkB,UAyCzE"}
|
|
@@ -0,0 +1,45 @@
|
|
|
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, context) {
|
|
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}\nOriginal File: ${context.fileName}`;
|
|
44
|
+
}
|
|
45
|
+
exports.getErrorMessage = getErrorMessage;
|
|
@@ -0,0 +1,9 @@
|
|
|
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 names. This allows fallbacks to be automatically included in environments
|
|
4
|
+
* without the names defined. This is most useful for Storybook or other sandboxes that may not have
|
|
5
|
+
* CSS Variables defined. The fallbacks will allow the UI to look correct without additional setup.
|
|
6
|
+
* Fallbacks come from the `fallbackFiles` transform configuration.
|
|
7
|
+
*/
|
|
8
|
+
export declare function getFallbackVariable(variableName: string, names: Record<string, string>): string | undefined;
|
|
9
|
+
//# sourceMappingURL=getFallbackVariable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC5B,MAAM,GAAG,SAAS,CAuBpB"}
|
|
@@ -0,0 +1,30 @@
|
|
|
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 names. This allows fallbacks to be automatically included in environments
|
|
7
|
+
* without the names defined. This is most useful for Storybook or other sandboxes that may not have
|
|
8
|
+
* CSS Variables defined. The fallbacks will allow the UI to look correct without additional setup.
|
|
9
|
+
* Fallbacks come from the `fallbackFiles` transform configuration.
|
|
10
|
+
*/
|
|
11
|
+
function getFallbackVariable(variableName, names) {
|
|
12
|
+
const variable = variableName.includes('var(') ? variableName : names[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 = names[cssVarName];
|
|
19
|
+
if (value && value.startsWith('var')) {
|
|
20
|
+
return getFallbackVariable(value, names);
|
|
21
|
+
}
|
|
22
|
+
return value || varMatch;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
if (variable) {
|
|
26
|
+
return variable;
|
|
27
|
+
}
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
exports.getFallbackVariable = getFallbackVariable;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getHash.d.ts","sourceRoot":"","sources":["../../../../lib/utils/getHash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAG5B,OAAO,EAAC,kBAAkB,EAAC,MAAM,SAAS,CAAC;AAE3C,wBAAgB,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,kBAAkB,UAOjE"}
|