@wyw-in-js/processor-utils 1.0.5 → 2.0.0-alpha.0
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/esm/BaseProcessor.js +47 -68
- package/esm/BaseProcessor.js.map +1 -1
- package/esm/TaggedTemplateProcessor.js +32 -41
- package/esm/TaggedTemplateProcessor.js.map +1 -1
- package/esm/ast.js +72 -0
- package/esm/ast.js.map +1 -0
- package/esm/diagnostics.js +4 -0
- package/esm/diagnostics.js.map +1 -0
- package/esm/index.js +9 -7
- package/esm/index.js.map +1 -1
- package/esm/types.js +1 -1
- package/esm/types.js.map +1 -1
- package/esm/utils/buildSlug.js +2 -2
- package/esm/utils/buildSlug.js.map +1 -1
- package/esm/utils/getClassNameAndSlug.js +38 -41
- package/esm/utils/getClassNameAndSlug.js.map +1 -1
- package/esm/utils/getVariableName.js +7 -10
- package/esm/utils/getVariableName.js.map +1 -1
- package/esm/utils/stripLines.js +9 -11
- package/esm/utils/stripLines.js.map +1 -1
- package/esm/utils/templateProcessor.js +98 -118
- package/esm/utils/templateProcessor.js.map +1 -1
- package/esm/utils/throwIfInvalid.js +11 -12
- package/esm/utils/throwIfInvalid.js.map +1 -1
- package/esm/utils/toCSS.js +34 -43
- package/esm/utils/toCSS.js.map +1 -1
- package/esm/utils/toValidCSSIdentifier.js +2 -2
- package/esm/utils/toValidCSSIdentifier.js.map +1 -1
- package/esm/utils/types.js +1 -1
- package/esm/utils/types.js.map +1 -1
- package/esm/utils/units.js +79 -61
- package/esm/utils/units.js.map +1 -1
- package/esm/utils/validateParams.js +29 -39
- package/esm/utils/validateParams.js.map +1 -1
- package/package.json +15 -15
- package/types/BaseProcessor.d.ts +7 -13
- package/types/BaseProcessor.js +18 -20
- package/types/TaggedTemplateProcessor.d.ts +1 -1
- package/types/TaggedTemplateProcessor.js +9 -16
- package/types/ast.d.ts +95 -0
- package/types/ast.js +80 -0
- package/types/diagnostics.d.ts +9 -0
- package/types/diagnostics.js +3 -0
- package/types/index.d.ts +5 -1
- package/types/index.js +8 -29
- package/types/types.d.ts +9 -1
- package/types/types.js +1 -2
- package/types/utils/buildSlug.js +1 -4
- package/types/utils/getClassNameAndSlug.js +15 -18
- package/types/utils/getVariableName.js +1 -4
- package/types/utils/stripLines.js +1 -4
- package/types/utils/templateProcessor.d.ts +1 -1
- package/types/utils/templateProcessor.js +16 -55
- package/types/utils/throwIfInvalid.js +1 -3
- package/types/utils/toCSS.js +8 -13
- package/types/utils/toValidCSSIdentifier.js +1 -4
- package/types/utils/types.d.ts +4 -2
- package/types/utils/types.js +1 -2
- package/types/utils/units.js +2 -5
- package/types/utils/validateParams.js +2 -6
- package/lib/BaseProcessor.js +0 -78
- package/lib/BaseProcessor.js.map +0 -1
- package/lib/TaggedTemplateProcessor.js +0 -51
- package/lib/TaggedTemplateProcessor.js.map +0 -1
- package/lib/index.js +0 -67
- package/lib/index.js.map +0 -1
- package/lib/types.js +0 -2
- package/lib/types.js.map +0 -1
- package/lib/utils/buildSlug.js +0 -12
- package/lib/utils/buildSlug.js.map +0 -1
- package/lib/utils/getClassNameAndSlug.js +0 -50
- package/lib/utils/getClassNameAndSlug.js.map +0 -1
- package/lib/utils/getVariableName.js +0 -18
- package/lib/utils/getVariableName.js.map +0 -1
- package/lib/utils/stripLines.js +0 -22
- package/lib/utils/stripLines.js.map +0 -1
- package/lib/utils/templateProcessor.js +0 -129
- package/lib/utils/templateProcessor.js.map +0 -1
- package/lib/utils/throwIfInvalid.js +0 -35
- package/lib/utils/throwIfInvalid.js.map +0 -1
- package/lib/utils/toCSS.js +0 -58
- package/lib/utils/toCSS.js.map +0 -1
- package/lib/utils/toValidCSSIdentifier.js +0 -10
- package/lib/utils/toValidCSSIdentifier.js.map +0 -1
- package/lib/utils/types.js +0 -2
- package/lib/utils/types.js.map +0 -1
- package/lib/utils/units.js +0 -71
- package/lib/utils/units.js.map +0 -1
- package/lib/utils/validateParams.js +0 -54
- package/lib/utils/validateParams.js.map +0 -1
|
@@ -1,44 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const buildSlug_1 = require("./buildSlug");
|
|
7
|
-
const toValidCSSIdentifier_1 = require("./toValidCSSIdentifier");
|
|
8
|
-
function getClassNameAndSlug(displayName, idx, options, context) {
|
|
1
|
+
import { basename, dirname, extname, relative, sep, posix } from 'path';
|
|
2
|
+
import { logger, slugify } from '@wyw-in-js/shared';
|
|
3
|
+
import { buildSlug } from './buildSlug';
|
|
4
|
+
import { toValidCSSIdentifier } from './toValidCSSIdentifier';
|
|
5
|
+
export default function getClassNameAndSlug(displayName, idx, options, context) {
|
|
9
6
|
const relativeFilename = (context.root && context.filename
|
|
10
|
-
?
|
|
11
|
-
: context.filename ?? 'unknown').replace(/\\/g,
|
|
7
|
+
? relative(context.root, context.filename)
|
|
8
|
+
: context.filename ?? 'unknown').replace(/\\/g, posix.sep);
|
|
12
9
|
// Custom properties need to start with a letter, so we prefix the slug
|
|
13
10
|
// Also use append the index of the class to the filename for uniqueness in the file
|
|
14
|
-
const slug =
|
|
11
|
+
const slug = toValidCSSIdentifier(`${displayName.charAt(0).toLowerCase()}${slugify(`${relativeFilename}:${idx}`)}`);
|
|
15
12
|
// Collect some useful replacement patterns from the filename
|
|
16
13
|
// Available variables for the square brackets used in `classNameSlug` options
|
|
17
|
-
const ext =
|
|
14
|
+
const ext = extname(relativeFilename);
|
|
18
15
|
const slugVars = {
|
|
19
16
|
hash: slug,
|
|
20
17
|
title: displayName,
|
|
21
18
|
index: idx,
|
|
22
19
|
file: relativeFilename,
|
|
23
20
|
ext,
|
|
24
|
-
name:
|
|
25
|
-
dir:
|
|
21
|
+
name: basename(relativeFilename, ext),
|
|
22
|
+
dir: dirname(relativeFilename).split(sep).pop(),
|
|
26
23
|
};
|
|
27
24
|
let className = options.displayName
|
|
28
|
-
? `${
|
|
25
|
+
? `${toValidCSSIdentifier(displayName)}_${slug}`
|
|
29
26
|
: slug;
|
|
30
27
|
// The className can be defined by the user either as fn or a string
|
|
31
28
|
if (typeof options.classNameSlug === 'function') {
|
|
32
29
|
try {
|
|
33
|
-
className =
|
|
30
|
+
className = toValidCSSIdentifier(options.classNameSlug(slug, displayName, slugVars));
|
|
34
31
|
}
|
|
35
32
|
catch {
|
|
36
33
|
throw new Error('classNameSlug option must return a string');
|
|
37
34
|
}
|
|
38
35
|
}
|
|
39
36
|
if (typeof options.classNameSlug === 'string') {
|
|
40
|
-
className =
|
|
37
|
+
className = toValidCSSIdentifier(buildSlug(options.classNameSlug, slugVars));
|
|
41
38
|
}
|
|
42
|
-
|
|
39
|
+
logger.extend('template-parse:generated-meta')(`slug: ${slug}, displayName: ${displayName}, className: ${className}`);
|
|
43
40
|
return { className, slug };
|
|
44
41
|
}
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getVariableName = getVariableName;
|
|
4
|
-
function getVariableName(varId, rawVariableName) {
|
|
1
|
+
export function getVariableName(varId, rawVariableName) {
|
|
5
2
|
switch (rawVariableName) {
|
|
6
3
|
case 'raw':
|
|
7
4
|
return varId;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = stripLines;
|
|
4
1
|
// Stripping away the new lines ensures that we preserve line numbers
|
|
5
2
|
// This is useful in case of tools such as the stylelint pre-processor
|
|
6
3
|
// This should be safe because strings cannot contain newline: https://www.w3.org/TR/CSS2/syndata.html#strings
|
|
7
|
-
function stripLines(loc, text) {
|
|
4
|
+
export default function stripLines(loc, text) {
|
|
8
5
|
let result = String(text)
|
|
9
6
|
.replace(/[\r\n]+/g, ' ')
|
|
10
7
|
.trim();
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
* This file handles transforming template literals to class names or styled components and generates CSS content.
|
|
3
3
|
* It uses CSS code from template literals and evaluated values of lazy dependencies stored in ValueCache.
|
|
4
4
|
*/
|
|
5
|
-
import type { TemplateElement } from '@babel/types';
|
|
6
5
|
import type { ExpressionValue, Replacements } from '@wyw-in-js/shared';
|
|
7
6
|
import type { TaggedTemplateProcessor } from '../TaggedTemplateProcessor';
|
|
7
|
+
import type { TemplateElement } from '../ast';
|
|
8
8
|
import type { ValueCache, Rules } from '../types';
|
|
9
9
|
import type { IOptions } from './types';
|
|
10
10
|
export default function templateProcessor(tagProcessor: TaggedTemplateProcessor, [...template]: (TemplateElement | ExpressionValue)[], valueCache: ValueCache, variableNameConfig: IOptions['variableNameConfig'] | undefined): [rules: Rules, sourceMapReplacements: Replacements] | null;
|
|
@@ -1,56 +1,17 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/* eslint-disable no-continue */
|
|
3
2
|
/**
|
|
4
3
|
* This file handles transforming template literals to class names or styled components and generates CSS content.
|
|
5
4
|
* It uses CSS code from template literals and evaluated values of lazy dependencies stored in ValueCache.
|
|
6
5
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
Object.defineProperty(o, k2, desc);
|
|
14
|
-
}) : (function(o, m, k, k2) {
|
|
15
|
-
if (k2 === undefined) k2 = k;
|
|
16
|
-
o[k2] = m[k];
|
|
17
|
-
}));
|
|
18
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
19
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
20
|
-
}) : function(o, v) {
|
|
21
|
-
o["default"] = v;
|
|
22
|
-
});
|
|
23
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
24
|
-
var ownKeys = function(o) {
|
|
25
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
26
|
-
var ar = [];
|
|
27
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
28
|
-
return ar;
|
|
29
|
-
};
|
|
30
|
-
return ownKeys(o);
|
|
31
|
-
};
|
|
32
|
-
return function (mod) {
|
|
33
|
-
if (mod && mod.__esModule) return mod;
|
|
34
|
-
var result = {};
|
|
35
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
36
|
-
__setModuleDefault(result, mod);
|
|
37
|
-
return result;
|
|
38
|
-
};
|
|
39
|
-
})();
|
|
40
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
41
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
42
|
-
};
|
|
43
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
|
-
exports.default = templateProcessor;
|
|
45
|
-
const shared_1 = require("@wyw-in-js/shared");
|
|
46
|
-
const getVariableName_1 = require("./getVariableName");
|
|
47
|
-
const stripLines_1 = __importDefault(require("./stripLines"));
|
|
48
|
-
const throwIfInvalid_1 = __importDefault(require("./throwIfInvalid"));
|
|
49
|
-
const toCSS_1 = __importStar(require("./toCSS"));
|
|
50
|
-
const units_1 = require("./units");
|
|
6
|
+
import { hasEvalMeta, ValueType } from '@wyw-in-js/shared';
|
|
7
|
+
import { getVariableName } from './getVariableName';
|
|
8
|
+
import stripLines from './stripLines';
|
|
9
|
+
import throwIfInvalid from './throwIfInvalid';
|
|
10
|
+
import toCSS, { isCSSable } from './toCSS';
|
|
11
|
+
import { units } from './units';
|
|
51
12
|
// Match any valid CSS unit not immediately followed by an alphanumeric character or underscore.
|
|
52
|
-
const unitRegex = new RegExp(`^(?:${
|
|
53
|
-
function templateProcessor(tagProcessor, [...template], valueCache, variableNameConfig) {
|
|
13
|
+
const unitRegex = new RegExp(`^(?:${units.join('|')})(?![a-zA-Z0-9_])`);
|
|
14
|
+
export default function templateProcessor(tagProcessor, [...template], valueCache, variableNameConfig) {
|
|
54
15
|
const sourceMapReplacements = [];
|
|
55
16
|
// Check if the variable is referenced anywhere for basic DCE
|
|
56
17
|
// Only works when it's assigned to a variable
|
|
@@ -79,7 +40,7 @@ function templateProcessor(tagProcessor, [...template], valueCache, variableName
|
|
|
79
40
|
};
|
|
80
41
|
const value = 'value' in item ? item.value : valueCache.get(item.ex.name);
|
|
81
42
|
// Is it props based interpolation?
|
|
82
|
-
if (item.kind ===
|
|
43
|
+
if (item.kind === ValueType.FUNCTION || typeof value === 'function') {
|
|
83
44
|
// Check if previous expression was a CSS variable that we replaced
|
|
84
45
|
// If it has a unit after it, we need to move the unit into the interpolation
|
|
85
46
|
// e.g. `var(--size)px` should actually be `var(--size)`
|
|
@@ -92,12 +53,12 @@ function templateProcessor(tagProcessor, [...template], valueCache, variableName
|
|
|
92
53
|
template.shift();
|
|
93
54
|
const [unit] = matches;
|
|
94
55
|
const varId = tagProcessor.addInterpolation(item.ex, cssText, item.source, unit);
|
|
95
|
-
cssText +=
|
|
56
|
+
cssText += getVariableName(varId, variableNameConfig);
|
|
96
57
|
cssText += next.value.cooked?.substring(unit?.length ?? 0) ?? '';
|
|
97
58
|
}
|
|
98
59
|
else {
|
|
99
60
|
const varId = tagProcessor.addInterpolation(item.ex, cssText, item.source);
|
|
100
|
-
cssText +=
|
|
61
|
+
cssText += getVariableName(varId, variableNameConfig);
|
|
101
62
|
}
|
|
102
63
|
}
|
|
103
64
|
catch (e) {
|
|
@@ -108,24 +69,24 @@ function templateProcessor(tagProcessor, [...template], valueCache, variableName
|
|
|
108
69
|
}
|
|
109
70
|
}
|
|
110
71
|
else {
|
|
111
|
-
(
|
|
72
|
+
throwIfInvalid(tagProcessor.isValidValue.bind(tagProcessor), value, item, item.source);
|
|
112
73
|
if (value !== undefined && typeof value !== 'function') {
|
|
113
74
|
// Skip the blank string instead of throw ing an error
|
|
114
75
|
if (value === '') {
|
|
115
76
|
continue;
|
|
116
77
|
}
|
|
117
|
-
if (
|
|
78
|
+
if (hasEvalMeta(value)) {
|
|
118
79
|
// If it's a React component wrapped in styled, get the class name
|
|
119
80
|
// Useful for interpolating components
|
|
120
81
|
cssText += `.${value.__wyw_meta.className}`;
|
|
121
82
|
}
|
|
122
|
-
else if (
|
|
83
|
+
else if (isCSSable(value)) {
|
|
123
84
|
// If it's a plain object or an array, convert it to a CSS string
|
|
124
|
-
cssText += (
|
|
85
|
+
cssText += stripLines(loc, toCSS(value));
|
|
125
86
|
}
|
|
126
87
|
else {
|
|
127
88
|
// For anything else, assume it'll be stringified
|
|
128
|
-
cssText += (
|
|
89
|
+
cssText += stripLines(loc, value);
|
|
129
90
|
}
|
|
130
91
|
sourceMapReplacements.push({
|
|
131
92
|
original: loc,
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
1
|
const isLikeError = (value) => typeof value === 'object' &&
|
|
4
2
|
value !== null &&
|
|
5
3
|
'stack' in value &&
|
|
@@ -29,4 +27,4 @@ function throwIfInvalid(checker, value, ex, source) {
|
|
|
29
27
|
const stringified = typeof value === 'object' ? JSON.stringify(value) : String(value);
|
|
30
28
|
throw ex.buildCodeFrameError(`The expression evaluated to '${stringified}', which is probably a mistake. If you want it to be inserted into CSS, explicitly cast or transform the value to a string, e.g. - 'String(${source})'.`);
|
|
31
29
|
}
|
|
32
|
-
|
|
30
|
+
export default throwIfInvalid;
|
package/types/utils/toCSS.js
CHANGED
|
@@ -1,27 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.isCSSable = void 0;
|
|
4
|
-
exports.default = toCSS;
|
|
5
|
-
const shared_1 = require("@wyw-in-js/shared");
|
|
6
|
-
const units_1 = require("./units");
|
|
1
|
+
import { isBoxedPrimitive } from '@wyw-in-js/shared';
|
|
2
|
+
import { unitless } from './units';
|
|
7
3
|
const isCSSPropertyValue = (o) => {
|
|
8
|
-
return (
|
|
4
|
+
return (isBoxedPrimitive(o) ||
|
|
9
5
|
typeof o === 'string' ||
|
|
10
6
|
(typeof o === 'number' && Number.isFinite(o)));
|
|
11
7
|
};
|
|
12
|
-
const isCSSable = (o) => {
|
|
8
|
+
export const isCSSable = (o) => {
|
|
13
9
|
if (isCSSPropertyValue(o)) {
|
|
14
10
|
return true;
|
|
15
11
|
}
|
|
16
12
|
if (Array.isArray(o)) {
|
|
17
|
-
return o.every(
|
|
13
|
+
return o.every(isCSSable);
|
|
18
14
|
}
|
|
19
15
|
if (typeof o === 'object') {
|
|
20
|
-
return o !== null && Object.values(o).every(
|
|
16
|
+
return o !== null && Object.values(o).every(isCSSable);
|
|
21
17
|
}
|
|
22
18
|
return false;
|
|
23
19
|
};
|
|
24
|
-
exports.isCSSable = isCSSable;
|
|
25
20
|
const hyphenate = (s) => {
|
|
26
21
|
if (s.startsWith('--')) {
|
|
27
22
|
// It's a custom property which is already well formatted.
|
|
@@ -35,7 +30,7 @@ const hyphenate = (s) => {
|
|
|
35
30
|
};
|
|
36
31
|
// Some tools such as polished.js output JS objects
|
|
37
32
|
// To support them transparently, we convert JS objects to CSS strings
|
|
38
|
-
function toCSS(o) {
|
|
33
|
+
export default function toCSS(o) {
|
|
39
34
|
if (Array.isArray(o)) {
|
|
40
35
|
return o.map(toCSS).join('\n');
|
|
41
36
|
}
|
|
@@ -53,7 +48,7 @@ function toCSS(o) {
|
|
|
53
48
|
return `${hyphenate(key)}: ${typeof value === 'number' &&
|
|
54
49
|
value !== 0 &&
|
|
55
50
|
// Strip vendor prefixes when checking if the value is unitless
|
|
56
|
-
!(key.replace(/^(Webkit|Moz|O|ms)([A-Z])(.+)$/, (match, p1, p2, p3) => `${p2.toLowerCase()}${p3}`) in
|
|
51
|
+
!(key.replace(/^(Webkit|Moz|O|ms)([A-Z])(.+)$/, (match, p1, p2, p3) => `${p2.toLowerCase()}${p3}`) in unitless)
|
|
57
52
|
? `${value}px`
|
|
58
53
|
: value};`;
|
|
59
54
|
})
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toValidCSSIdentifier = toValidCSSIdentifier;
|
|
4
|
-
function toValidCSSIdentifier(s) {
|
|
1
|
+
export function toValidCSSIdentifier(s) {
|
|
5
2
|
return s.replace(/[^-_a-z0-9\u00A0-\uFFFF]/gi, '_').replace(/^\d/, '_');
|
|
6
3
|
}
|
package/types/utils/types.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { TransformOptions } from '@babel/core';
|
|
2
1
|
import type { ClassNameFn, VariableNameFn } from '@wyw-in-js/shared';
|
|
3
2
|
export interface IOptions {
|
|
4
3
|
classNameSlug?: string | ClassNameFn;
|
|
@@ -7,4 +6,7 @@ export interface IOptions {
|
|
|
7
6
|
variableNameConfig?: 'var' | 'dashes' | 'raw';
|
|
8
7
|
variableNameSlug?: string | VariableNameFn;
|
|
9
8
|
}
|
|
10
|
-
export type IFileContext =
|
|
9
|
+
export type IFileContext = {
|
|
10
|
+
filename?: string | null;
|
|
11
|
+
root?: string | null;
|
|
12
|
+
};
|
package/types/utils/types.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/types/utils/units.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.unitless = exports.units = void 0;
|
|
4
1
|
// https://www.w3.org/TR/css-values-4/
|
|
5
|
-
|
|
2
|
+
export const units = [
|
|
6
3
|
// font relative lengths
|
|
7
4
|
'em',
|
|
8
5
|
'ex',
|
|
@@ -48,7 +45,7 @@ exports.units = [
|
|
|
48
45
|
// percentages
|
|
49
46
|
'%',
|
|
50
47
|
];
|
|
51
|
-
|
|
48
|
+
export const unitless = {
|
|
52
49
|
animationIterationCount: true,
|
|
53
50
|
borderImageOutset: true,
|
|
54
51
|
borderImageSlice: true,
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isValidParams = isValidParams;
|
|
4
|
-
exports.validateParams = validateParams;
|
|
5
|
-
function isValidParams(params, constraints) {
|
|
1
|
+
export function isValidParams(params, constraints) {
|
|
6
2
|
const length = Math.max(params.length, constraints.length);
|
|
7
3
|
for (let i = 0; i < length; i++) {
|
|
8
4
|
if (params[i] === undefined || constraints[i] === undefined) {
|
|
@@ -28,7 +24,7 @@ function isValidParams(params, constraints) {
|
|
|
28
24
|
}
|
|
29
25
|
return true;
|
|
30
26
|
}
|
|
31
|
-
function validateParams(params, constraints, messageOrError) {
|
|
27
|
+
export function validateParams(params, constraints, messageOrError) {
|
|
32
28
|
if (!isValidParams(params, constraints)) {
|
|
33
29
|
if (typeof messageOrError === 'string') {
|
|
34
30
|
throw new Error(messageOrError);
|
package/lib/BaseProcessor.js
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.BaseProcessor = void 0;
|
|
7
|
-
var _generator = _interopRequireDefault(require("@babel/generator"));
|
|
8
|
-
var _shared = require("@wyw-in-js/shared");
|
|
9
|
-
var _getClassNameAndSlug = _interopRequireDefault(require("./utils/getClassNameAndSlug"));
|
|
10
|
-
var _toCSS = require("./utils/toCSS");
|
|
11
|
-
var _validateParams = require("./utils/validateParams");
|
|
12
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
-
/* eslint-disable class-methods-use-this */
|
|
14
|
-
|
|
15
|
-
class BaseProcessor {
|
|
16
|
-
static SKIP = Symbol('skip');
|
|
17
|
-
artifacts = [];
|
|
18
|
-
dependencies = [];
|
|
19
|
-
interpolations = [];
|
|
20
|
-
constructor(params, tagSource, astService, location, replacer, displayName, isReferenced, idx, options, context) {
|
|
21
|
-
this.tagSource = tagSource;
|
|
22
|
-
this.astService = astService;
|
|
23
|
-
this.location = location;
|
|
24
|
-
this.replacer = replacer;
|
|
25
|
-
this.displayName = displayName;
|
|
26
|
-
this.isReferenced = isReferenced;
|
|
27
|
-
this.idx = idx;
|
|
28
|
-
this.options = options;
|
|
29
|
-
this.context = context;
|
|
30
|
-
(0, _validateParams.validateParams)(params, ['callee'], 'Unknown error: a callee param is not specified');
|
|
31
|
-
const {
|
|
32
|
-
className,
|
|
33
|
-
slug
|
|
34
|
-
} = (0, _getClassNameAndSlug.default)(this.displayName, this.idx, this.options, this.context);
|
|
35
|
-
this.className = className;
|
|
36
|
-
this.slug = slug;
|
|
37
|
-
[[, this.callee]] = params;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* A replacement for tag referenced in a template literal.
|
|
42
|
-
*/
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* A replacement for the tag in evaluation time.
|
|
46
|
-
* For example, `css` tag will be replaced with its className,
|
|
47
|
-
* whereas `styled` tag will be replaced with an object with metadata.
|
|
48
|
-
*/
|
|
49
|
-
|
|
50
|
-
isValidValue(value) {
|
|
51
|
-
return typeof value === 'function' || (0, _toCSS.isCSSable)(value) || (0, _shared.hasEvalMeta)(value);
|
|
52
|
-
}
|
|
53
|
-
toString() {
|
|
54
|
-
return this.tagSourceCode();
|
|
55
|
-
}
|
|
56
|
-
tagSourceCode() {
|
|
57
|
-
if (this.callee.type === 'Identifier') {
|
|
58
|
-
return this.callee.name;
|
|
59
|
-
}
|
|
60
|
-
return (0, _generator.default)(this.callee).code;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Perform a replacement for the tag in evaluation time.
|
|
65
|
-
* For example, `css` tag will be replaced with its className,
|
|
66
|
-
* whereas `styled` tag will be replaced with an object with metadata.
|
|
67
|
-
*/
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Perform a replacement for the tag with its runtime version.
|
|
71
|
-
* For example, `css` tag will be replaced with its className,
|
|
72
|
-
* whereas `styled` tag will be replaced with a component.
|
|
73
|
-
* If some parts require evaluated data for render,
|
|
74
|
-
* they will be replaced with placeholders.
|
|
75
|
-
*/
|
|
76
|
-
}
|
|
77
|
-
exports.BaseProcessor = BaseProcessor;
|
|
78
|
-
//# sourceMappingURL=BaseProcessor.js.map
|
package/lib/BaseProcessor.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BaseProcessor.js","names":["_generator","_interopRequireDefault","require","_shared","_getClassNameAndSlug","_toCSS","_validateParams","e","__esModule","default","BaseProcessor","SKIP","Symbol","artifacts","dependencies","interpolations","constructor","params","tagSource","astService","location","replacer","displayName","isReferenced","idx","options","context","validateParams","className","slug","getClassNameAndSlug","callee","isValidValue","value","isCSSable","hasEvalMeta","toString","tagSourceCode","type","name","generator","code","exports"],"sources":["../src/BaseProcessor.ts"],"sourcesContent":["/* eslint-disable class-methods-use-this */\nimport type { NodePath, types as t } from '@babel/core';\nimport generator from '@babel/generator';\nimport type {\n Expression,\n Identifier,\n SourceLocation,\n MemberExpression,\n} from '@babel/types';\n\nimport type { Artifact, ExpressionValue } from '@wyw-in-js/shared';\nimport { hasEvalMeta } from '@wyw-in-js/shared';\n\nimport type { IInterpolation, Params, Value, ValueCache } from './types';\nimport getClassNameAndSlug from './utils/getClassNameAndSlug';\nimport { isCSSable } from './utils/toCSS';\nimport type { IFileContext, IOptions } from './utils/types';\nimport { validateParams } from './utils/validateParams';\n\nexport { Expression };\n\nexport type ProcessorParams = ConstructorParameters<typeof BaseProcessor>;\nexport type TailProcessorParams = ProcessorParams extends [Params, ...infer T]\n ? T\n : never;\n\nexport type TagSource = {\n imported: string;\n source: string;\n};\n\nexport abstract class BaseProcessor {\n public static SKIP = Symbol('skip');\n\n public readonly artifacts: Artifact[] = [];\n\n public readonly className: string;\n\n public readonly dependencies: ExpressionValue[] = [];\n\n public interpolations: IInterpolation[] = [];\n\n public readonly slug: string;\n\n protected callee: Identifier | MemberExpression;\n\n protected evaluated:\n | Record<'dependencies' | 'expression', Value[]>\n | undefined;\n\n public constructor(\n params: Params,\n public tagSource: TagSource,\n protected readonly astService: typeof t & {\n addDefaultImport: (source: string, nameHint?: string) => Identifier;\n addNamedImport: (\n name: string,\n source: string,\n nameHint?: string\n ) => Identifier;\n },\n public readonly location: SourceLocation | null,\n protected readonly replacer: (\n replacement: Expression | ((tagPath: NodePath) => Expression),\n isPure: boolean\n ) => void,\n public readonly displayName: string,\n public readonly isReferenced: boolean,\n protected readonly idx: number,\n protected readonly options: IOptions,\n protected readonly context: IFileContext\n ) {\n validateParams(\n params,\n ['callee'],\n 'Unknown error: a callee param is not specified'\n );\n\n const { className, slug } = getClassNameAndSlug(\n this.displayName,\n this.idx,\n this.options,\n this.context\n );\n\n this.className = className;\n this.slug = slug;\n\n [[, this.callee]] = params;\n }\n\n /**\n * A replacement for tag referenced in a template literal.\n */\n public abstract get asSelector(): string;\n\n /**\n * A replacement for the tag in evaluation time.\n * For example, `css` tag will be replaced with its className,\n * whereas `styled` tag will be replaced with an object with metadata.\n */\n public abstract get value(): Expression;\n\n public isValidValue(value: unknown): value is Value {\n return (\n typeof value === 'function' || isCSSable(value) || hasEvalMeta(value)\n );\n }\n\n public toString(): string {\n return this.tagSourceCode();\n }\n\n protected tagSourceCode(): string {\n if (this.callee.type === 'Identifier') {\n return this.callee.name;\n }\n\n return generator(this.callee).code;\n }\n\n public abstract build(values: ValueCache): void;\n\n /**\n * Perform a replacement for the tag in evaluation time.\n * For example, `css` tag will be replaced with its className,\n * whereas `styled` tag will be replaced with an object with metadata.\n */\n public abstract doEvaltimeReplacement(): void;\n\n /**\n * Perform a replacement for the tag with its runtime version.\n * For example, `css` tag will be replaced with its className,\n * whereas `styled` tag will be replaced with a component.\n * If some parts require evaluated data for render,\n * they will be replaced with placeholders.\n */\n public abstract doRuntimeReplacement(): void;\n}\n"],"mappings":";;;;;;AAEA,IAAAA,UAAA,GAAAC,sBAAA,CAAAC,OAAA;AASA,IAAAC,OAAA,GAAAD,OAAA;AAGA,IAAAE,oBAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AAEA,IAAAI,eAAA,GAAAJ,OAAA;AAAwD,SAAAD,uBAAAM,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAjBxD;;AA+BO,MAAeG,aAAa,CAAC;EAClC,OAAcC,IAAI,GAAGC,MAAM,CAAC,MAAM,CAAC;EAEnBC,SAAS,GAAe,EAAE;EAI1BC,YAAY,GAAsB,EAAE;EAE7CC,cAAc,GAAqB,EAAE;EAUrCC,WAAWA,CAChBC,MAAc,EACPC,SAAoB,EACRC,UAOlB,EACeC,QAA+B,EAC5BC,QAGV,EACOC,WAAmB,EACnBC,YAAqB,EAClBC,GAAW,EACXC,OAAiB,EACjBC,OAAqB,EACxC;IAAA,KAnBOR,SAAoB,GAApBA,SAAoB;IAAA,KACRC,UAOlB,GAPkBA,UAOlB;IAAA,KACeC,QAA+B,GAA/BA,QAA+B;IAAA,KAC5BC,QAGV,GAHUA,QAGV;IAAA,KACOC,WAAmB,GAAnBA,WAAmB;IAAA,KACnBC,YAAqB,GAArBA,YAAqB;IAAA,KAClBC,GAAW,GAAXA,GAAW;IAAA,KACXC,OAAiB,GAAjBA,OAAiB;IAAA,KACjBC,OAAqB,GAArBA,OAAqB;IAExC,IAAAC,8BAAc,EACZV,MAAM,EACN,CAAC,QAAQ,CAAC,EACV,gDACF,CAAC;IAED,MAAM;MAAEW,SAAS;MAAEC;IAAK,CAAC,GAAG,IAAAC,4BAAmB,EAC7C,IAAI,CAACR,WAAW,EAChB,IAAI,CAACE,GAAG,EACR,IAAI,CAACC,OAAO,EACZ,IAAI,CAACC,OACP,CAAC;IAED,IAAI,CAACE,SAAS,GAAGA,SAAS;IAC1B,IAAI,CAACC,IAAI,GAAGA,IAAI;IAEhB,CAAC,GAAG,IAAI,CAACE,MAAM,CAAC,CAAC,GAAGd,MAAM;EAC5B;;EAEA;AACF;AACA;;EAGE;AACF;AACA;AACA;AACA;;EAGSe,YAAYA,CAACC,KAAc,EAAkB;IAClD,OACE,OAAOA,KAAK,KAAK,UAAU,IAAI,IAAAC,gBAAS,EAACD,KAAK,CAAC,IAAI,IAAAE,mBAAW,EAACF,KAAK,CAAC;EAEzE;EAEOG,QAAQA,CAAA,EAAW;IACxB,OAAO,IAAI,CAACC,aAAa,CAAC,CAAC;EAC7B;EAEUA,aAAaA,CAAA,EAAW;IAChC,IAAI,IAAI,CAACN,MAAM,CAACO,IAAI,KAAK,YAAY,EAAE;MACrC,OAAO,IAAI,CAACP,MAAM,CAACQ,IAAI;IACzB;IAEA,OAAO,IAAAC,kBAAS,EAAC,IAAI,CAACT,MAAM,CAAC,CAACU,IAAI;EACpC;;EAIA;AACF;AACA;AACA;AACA;;EAGE;AACF;AACA;AACA;AACA;AACA;AACA;AAEA;AAACC,OAAA,CAAAhC,aAAA,GAAAA,aAAA","ignoreList":[]}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.TaggedTemplateProcessor = void 0;
|
|
7
|
-
var _shared = require("@wyw-in-js/shared");
|
|
8
|
-
var _BaseProcessor = require("./BaseProcessor");
|
|
9
|
-
var _templateProcessor = _interopRequireDefault(require("./utils/templateProcessor"));
|
|
10
|
-
var _validateParams = require("./utils/validateParams");
|
|
11
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
-
class TaggedTemplateProcessor extends _BaseProcessor.BaseProcessor {
|
|
13
|
-
#template;
|
|
14
|
-
constructor(params, ...args) {
|
|
15
|
-
// Should have at least two params and the first one should be a callee.
|
|
16
|
-
(0, _validateParams.validateParams)(params, ['callee', '...'], TaggedTemplateProcessor.SKIP);
|
|
17
|
-
(0, _validateParams.validateParams)(params, ['callee', 'template'], 'Invalid usage of template tag');
|
|
18
|
-
const [tag, [, template]] = params;
|
|
19
|
-
super([tag], ...args);
|
|
20
|
-
template.forEach(element => {
|
|
21
|
-
if ('kind' in element && element.kind !== _shared.ValueType.FUNCTION) {
|
|
22
|
-
this.dependencies.push(element);
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
this.#template = template;
|
|
26
|
-
}
|
|
27
|
-
build(values) {
|
|
28
|
-
if (this.artifacts.length > 0) {
|
|
29
|
-
// FIXME: why it was called twice?
|
|
30
|
-
throw new Error('Tag is already built');
|
|
31
|
-
}
|
|
32
|
-
const artifact = (0, _templateProcessor.default)(this, this.#template, values, this.options.variableNameConfig);
|
|
33
|
-
if (artifact) {
|
|
34
|
-
this.artifacts.push(['css', artifact]);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
toString() {
|
|
38
|
-
return `${super.toString()}\`…\``;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* It is called for each resolved expression in a template literal.
|
|
43
|
-
* @param node
|
|
44
|
-
* @param precedingCss
|
|
45
|
-
* @param source
|
|
46
|
-
* @param unit
|
|
47
|
-
* @return chunk of CSS that should be added to extracted CSS
|
|
48
|
-
*/
|
|
49
|
-
}
|
|
50
|
-
exports.TaggedTemplateProcessor = TaggedTemplateProcessor;
|
|
51
|
-
//# sourceMappingURL=TaggedTemplateProcessor.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TaggedTemplateProcessor.js","names":["_shared","require","_BaseProcessor","_templateProcessor","_interopRequireDefault","_validateParams","e","__esModule","default","TaggedTemplateProcessor","BaseProcessor","template","constructor","params","args","validateParams","SKIP","tag","forEach","element","kind","ValueType","FUNCTION","dependencies","push","build","values","artifacts","length","Error","artifact","templateProcessor","options","variableNameConfig","toString","exports"],"sources":["../src/TaggedTemplateProcessor.ts"],"sourcesContent":["import type { TemplateElement, Expression, SourceLocation } from '@babel/types';\n\nimport type { ExpressionValue } from '@wyw-in-js/shared';\nimport { ValueType } from '@wyw-in-js/shared';\n\nimport type { TailProcessorParams } from './BaseProcessor';\nimport { BaseProcessor } from './BaseProcessor';\nimport type { ValueCache, Rules, Params } from './types';\nimport templateProcessor from './utils/templateProcessor';\nimport { validateParams } from './utils/validateParams';\n\nexport abstract class TaggedTemplateProcessor extends BaseProcessor {\n readonly #template: (TemplateElement | ExpressionValue)[];\n\n protected constructor(params: Params, ...args: TailProcessorParams) {\n // Should have at least two params and the first one should be a callee.\n validateParams(params, ['callee', '...'], TaggedTemplateProcessor.SKIP);\n\n validateParams(\n params,\n ['callee', 'template'],\n 'Invalid usage of template tag'\n );\n const [tag, [, template]] = params;\n\n super([tag], ...args);\n\n template.forEach((element) => {\n if ('kind' in element && element.kind !== ValueType.FUNCTION) {\n this.dependencies.push(element);\n }\n });\n\n this.#template = template;\n }\n\n public override build(values: ValueCache) {\n if (this.artifacts.length > 0) {\n // FIXME: why it was called twice?\n throw new Error('Tag is already built');\n }\n\n const artifact = templateProcessor(\n this,\n this.#template,\n values,\n this.options.variableNameConfig\n );\n if (artifact) {\n this.artifacts.push(['css', artifact]);\n }\n }\n\n public override toString(): string {\n return `${super.toString()}\\`…\\``;\n }\n\n /**\n * It is called for each resolved expression in a template literal.\n * @param node\n * @param precedingCss\n * @param source\n * @param unit\n * @return chunk of CSS that should be added to extracted CSS\n */\n public abstract addInterpolation(\n node: Expression,\n precedingCss: string,\n source: string,\n unit?: string\n ): string;\n\n public abstract extractRules(\n valueCache: ValueCache,\n cssText: string,\n loc?: SourceLocation | null\n ): Rules;\n}\n"],"mappings":";;;;;;AAGA,IAAAA,OAAA,GAAAC,OAAA;AAGA,IAAAC,cAAA,GAAAD,OAAA;AAEA,IAAAE,kBAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,eAAA,GAAAJ,OAAA;AAAwD,SAAAG,uBAAAE,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAEjD,MAAeG,uBAAuB,SAASC,4BAAa,CAAC;EACzD,CAACC,QAAQ;EAERC,WAAWA,CAACC,MAAc,EAAE,GAAGC,IAAyB,EAAE;IAClE;IACA,IAAAC,8BAAc,EAACF,MAAM,EAAE,CAAC,QAAQ,EAAE,KAAK,CAAC,EAAEJ,uBAAuB,CAACO,IAAI,CAAC;IAEvE,IAAAD,8BAAc,EACZF,MAAM,EACN,CAAC,QAAQ,EAAE,UAAU,CAAC,EACtB,+BACF,CAAC;IACD,MAAM,CAACI,GAAG,EAAE,GAAGN,QAAQ,CAAC,CAAC,GAAGE,MAAM;IAElC,KAAK,CAAC,CAACI,GAAG,CAAC,EAAE,GAAGH,IAAI,CAAC;IAErBH,QAAQ,CAACO,OAAO,CAAEC,OAAO,IAAK;MAC5B,IAAI,MAAM,IAAIA,OAAO,IAAIA,OAAO,CAACC,IAAI,KAAKC,iBAAS,CAACC,QAAQ,EAAE;QAC5D,IAAI,CAACC,YAAY,CAACC,IAAI,CAACL,OAAO,CAAC;MACjC;IACF,CAAC,CAAC;IAEF,IAAI,CAAC,CAACR,QAAQ,GAAGA,QAAQ;EAC3B;EAEgBc,KAAKA,CAACC,MAAkB,EAAE;IACxC,IAAI,IAAI,CAACC,SAAS,CAACC,MAAM,GAAG,CAAC,EAAE;MAC7B;MACA,MAAM,IAAIC,KAAK,CAAC,sBAAsB,CAAC;IACzC;IAEA,MAAMC,QAAQ,GAAG,IAAAC,0BAAiB,EAChC,IAAI,EACJ,IAAI,CAAC,CAACpB,QAAQ,EACde,MAAM,EACN,IAAI,CAACM,OAAO,CAACC,kBACf,CAAC;IACD,IAAIH,QAAQ,EAAE;MACZ,IAAI,CAACH,SAAS,CAACH,IAAI,CAAC,CAAC,KAAK,EAAEM,QAAQ,CAAC,CAAC;IACxC;EACF;EAEgBI,QAAQA,CAAA,EAAW;IACjC,OAAO,GAAG,KAAK,CAACA,QAAQ,CAAC,CAAC,OAAO;EACnC;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AAaA;AAACC,OAAA,CAAA1B,uBAAA,GAAAA,uBAAA","ignoreList":[]}
|
package/lib/index.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
var _exportNames = {
|
|
7
|
-
BaseProcessor: true,
|
|
8
|
-
buildSlug: true,
|
|
9
|
-
isValidParams: true,
|
|
10
|
-
validateParams: true,
|
|
11
|
-
TaggedTemplateProcessor: true,
|
|
12
|
-
toValidCSSIdentifier: true
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "BaseProcessor", {
|
|
15
|
-
enumerable: true,
|
|
16
|
-
get: function () {
|
|
17
|
-
return _BaseProcessor.BaseProcessor;
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
Object.defineProperty(exports, "TaggedTemplateProcessor", {
|
|
21
|
-
enumerable: true,
|
|
22
|
-
get: function () {
|
|
23
|
-
return _TaggedTemplateProcessor.TaggedTemplateProcessor;
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
Object.defineProperty(exports, "buildSlug", {
|
|
27
|
-
enumerable: true,
|
|
28
|
-
get: function () {
|
|
29
|
-
return _buildSlug.buildSlug;
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
Object.defineProperty(exports, "isValidParams", {
|
|
33
|
-
enumerable: true,
|
|
34
|
-
get: function () {
|
|
35
|
-
return _validateParams.isValidParams;
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
Object.defineProperty(exports, "toValidCSSIdentifier", {
|
|
39
|
-
enumerable: true,
|
|
40
|
-
get: function () {
|
|
41
|
-
return _toValidCSSIdentifier.toValidCSSIdentifier;
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
Object.defineProperty(exports, "validateParams", {
|
|
45
|
-
enumerable: true,
|
|
46
|
-
get: function () {
|
|
47
|
-
return _validateParams.validateParams;
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
var _BaseProcessor = require("./BaseProcessor");
|
|
51
|
-
var _types = require("./types");
|
|
52
|
-
Object.keys(_types).forEach(function (key) {
|
|
53
|
-
if (key === "default" || key === "__esModule") return;
|
|
54
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
55
|
-
if (key in exports && exports[key] === _types[key]) return;
|
|
56
|
-
Object.defineProperty(exports, key, {
|
|
57
|
-
enumerable: true,
|
|
58
|
-
get: function () {
|
|
59
|
-
return _types[key];
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
var _buildSlug = require("./utils/buildSlug");
|
|
64
|
-
var _validateParams = require("./utils/validateParams");
|
|
65
|
-
var _TaggedTemplateProcessor = require("./TaggedTemplateProcessor");
|
|
66
|
-
var _toValidCSSIdentifier = require("./utils/toValidCSSIdentifier");
|
|
67
|
-
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_BaseProcessor","require","_types","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_buildSlug","_validateParams","_TaggedTemplateProcessor","_toValidCSSIdentifier"],"sources":["../src/index.ts"],"sourcesContent":["export { BaseProcessor } from './BaseProcessor';\nexport type {\n Expression,\n TagSource,\n ProcessorParams,\n TailProcessorParams,\n} from './BaseProcessor';\nexport * from './types';\nexport { buildSlug } from './utils/buildSlug';\nexport type { IOptions, IFileContext } from './utils/types';\nexport { isValidParams, validateParams } from './utils/validateParams';\nexport type { MapParams, ParamConstraints } from './utils/validateParams';\nexport { TaggedTemplateProcessor } from './TaggedTemplateProcessor';\nexport { toValidCSSIdentifier } from './utils/toValidCSSIdentifier';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,cAAA,GAAAC,OAAA;AAOA,IAAAC,MAAA,GAAAD,OAAA;AAAAE,MAAA,CAAAC,IAAA,CAAAF,MAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAJ,MAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAZ,MAAA,CAAAI,GAAA;IAAA;EAAA;AAAA;AACA,IAAAS,UAAA,GAAAd,OAAA;AAEA,IAAAe,eAAA,GAAAf,OAAA;AAEA,IAAAgB,wBAAA,GAAAhB,OAAA;AACA,IAAAiB,qBAAA,GAAAjB,OAAA","ignoreList":[]}
|
package/lib/types.js
DELETED
package/lib/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../src/types.ts"],"sourcesContent":["import type {\n Expression,\n Identifier,\n TemplateElement,\n MemberExpression,\n} from '@babel/types';\n\nimport type { ExpressionValue, Location, WYWEvalMeta } from '@wyw-in-js/shared';\n\nexport type CSSPropertyValue = string | number;\n\nexport type ObjectWithSelectors = {\n [key: string]:\n | ObjectWithSelectors\n | CSSPropertyValue\n | (ObjectWithSelectors | CSSPropertyValue)[];\n};\n\nexport type CSSable = ObjectWithSelectors[string];\n\nexport type Value = (() => void) | WYWEvalMeta | CSSable;\n\nexport type ValueCache = Map<string | number | boolean | null, unknown>;\n\nexport interface ICSSRule {\n atom?: boolean;\n className: string;\n cssText: string;\n displayName: string;\n start: Location | null | undefined;\n}\n\nexport interface IInterpolation {\n id: string;\n node: Expression;\n source: string;\n unit: string;\n}\n\nexport type Rules = Record<string, ICSSRule>;\n\nexport type CalleeParam = readonly ['callee', Identifier | MemberExpression];\nexport type CallParam = readonly ['call', ...ExpressionValue[]];\nexport type MemberParam = readonly ['member', string];\nexport type TemplateParam = readonly [\n 'template',\n (TemplateElement | ExpressionValue)[],\n];\n\nexport type Param = CalleeParam | CallParam | MemberParam | TemplateParam;\nexport type Params = readonly Param[];\n"],"mappings":"","ignoreList":[]}
|
package/lib/utils/buildSlug.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.buildSlug = buildSlug;
|
|
7
|
-
const PLACEHOLDER = /\[(.*?)]/g;
|
|
8
|
-
const isValidArgName = (key, args) => key in args;
|
|
9
|
-
function buildSlug(pattern, args) {
|
|
10
|
-
return pattern.replace(PLACEHOLDER, (_, name) => isValidArgName(name, args) ? args[name].toString() : '');
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=buildSlug.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"buildSlug.js","names":["PLACEHOLDER","isValidArgName","key","args","buildSlug","pattern","replace","_","name","toString"],"sources":["../../src/utils/buildSlug.ts"],"sourcesContent":["const PLACEHOLDER = /\\[(.*?)]/g;\n\nconst isValidArgName = <TArgs extends Record<string, { toString(): string }>>(\n key: string | number | symbol,\n args: TArgs\n): key is keyof TArgs => key in args;\n\nexport function buildSlug<TArgs extends Record<string, { toString(): string }>>(\n pattern: string,\n args: TArgs\n) {\n return pattern.replace(PLACEHOLDER, (_, name: string) =>\n isValidArgName(name, args) ? args[name].toString() : ''\n );\n}\n"],"mappings":";;;;;;AAAA,MAAMA,WAAW,GAAG,WAAW;AAE/B,MAAMC,cAAc,GAAGA,CACrBC,GAA6B,EAC7BC,IAAW,KACYD,GAAG,IAAIC,IAAI;AAE7B,SAASC,SAASA,CACvBC,OAAe,EACfF,IAAW,EACX;EACA,OAAOE,OAAO,CAACC,OAAO,CAACN,WAAW,EAAE,CAACO,CAAC,EAAEC,IAAY,KAClDP,cAAc,CAACO,IAAI,EAAEL,IAAI,CAAC,GAAGA,IAAI,CAACK,IAAI,CAAC,CAACC,QAAQ,CAAC,CAAC,GAAG,EACvD,CAAC;AACH","ignoreList":[]}
|