@plumeria/utils 18.3.18 → 18.4.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/dist/index.d.ts +2 -0
- package/dist/index.js +4 -1
- package/dist/propertyPolicy.d.ts +16 -0
- package/dist/propertyPolicy.js +151 -0
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -15,3 +15,5 @@ export type { ReferenceIdentifiers } from './references';
|
|
|
15
15
|
export { collectReferenceIdentifiers } from './references';
|
|
16
16
|
export { profiling, mark, measure, tally, timed, timedAsync } from './profiler';
|
|
17
17
|
export { DEFAULT_STYLE_PROP } from './constants';
|
|
18
|
+
export type { PropertyPolicy, PropertyPolicyOptions } from './propertyPolicy';
|
|
19
|
+
export { resolvePropertyPolicy, assertPropertyPolicy } from './propertyPolicy';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DEFAULT_STYLE_PROP = exports.timedAsync = exports.timed = exports.tally = exports.measure = exports.mark = exports.profiling = exports.collectReferenceIdentifiers = exports.getLeadingCommentLength = exports.processVariants = exports.optimizer = exports.resolveImportPath = exports.themeHashOf = exports.getStateWeights = exports.getPseudoElement = exports.getSpecificity = exports.getStyleRecords = exports.resolveThemeSelector = exports.resolveComponentKey = exports.resolveExport = exports.getFileDependencies = exports.resolveFileError = exports.scanAll = exports.deepMerge = exports.extractOndemandStyles = exports.getRootIdentifier = exports.t = exports.traverse = exports.collectLocalConsts = exports.objectExpressionToObject = void 0;
|
|
3
|
+
exports.assertPropertyPolicy = exports.resolvePropertyPolicy = exports.DEFAULT_STYLE_PROP = exports.timedAsync = exports.timed = exports.tally = exports.measure = exports.mark = exports.profiling = exports.collectReferenceIdentifiers = exports.getLeadingCommentLength = exports.processVariants = exports.optimizer = exports.resolveImportPath = exports.themeHashOf = exports.getStateWeights = exports.getPseudoElement = exports.getSpecificity = exports.getStyleRecords = exports.resolveThemeSelector = exports.resolveComponentKey = exports.resolveExport = exports.getFileDependencies = exports.resolveFileError = exports.scanAll = exports.deepMerge = exports.extractOndemandStyles = exports.getRootIdentifier = exports.t = exports.traverse = exports.collectLocalConsts = exports.objectExpressionToObject = void 0;
|
|
4
4
|
var parser_1 = require("./parser");
|
|
5
5
|
Object.defineProperty(exports, "objectExpressionToObject", { enumerable: true, get: function () { return parser_1.objectExpressionToObject; } });
|
|
6
6
|
Object.defineProperty(exports, "collectLocalConsts", { enumerable: true, get: function () { return parser_1.collectLocalConsts; } });
|
|
@@ -43,3 +43,6 @@ Object.defineProperty(exports, "timed", { enumerable: true, get: function () { r
|
|
|
43
43
|
Object.defineProperty(exports, "timedAsync", { enumerable: true, get: function () { return profiler_1.timedAsync; } });
|
|
44
44
|
var constants_1 = require("./constants");
|
|
45
45
|
Object.defineProperty(exports, "DEFAULT_STYLE_PROP", { enumerable: true, get: function () { return constants_1.DEFAULT_STYLE_PROP; } });
|
|
46
|
+
var propertyPolicy_1 = require("./propertyPolicy");
|
|
47
|
+
Object.defineProperty(exports, "resolvePropertyPolicy", { enumerable: true, get: function () { return propertyPolicy_1.resolvePropertyPolicy; } });
|
|
48
|
+
Object.defineProperty(exports, "assertPropertyPolicy", { enumerable: true, get: function () { return propertyPolicy_1.assertPropertyPolicy; } });
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Module } from '@swc/core';
|
|
2
|
+
import type { PropertySpelling } from 'zss-engine';
|
|
3
|
+
export interface PropertyPolicyOptions {
|
|
4
|
+
withoutLogicalProperties?: boolean | {
|
|
5
|
+
sizes?: boolean;
|
|
6
|
+
};
|
|
7
|
+
withoutPhysicalProperties?: boolean | {
|
|
8
|
+
sizes?: boolean;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export interface PropertyPolicy {
|
|
12
|
+
reject: PropertySpelling;
|
|
13
|
+
includeAxes: boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare const resolvePropertyPolicy: (options: PropertyPolicyOptions) => PropertyPolicy | undefined;
|
|
16
|
+
export declare const assertPropertyPolicy: (ast: Module, policy: PropertyPolicy | undefined, resourcePath: string) => void;
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.assertPropertyPolicy = exports.resolvePropertyPolicy = void 0;
|
|
37
|
+
const path = __importStar(require("path"));
|
|
38
|
+
const zss_engine_1 = require("zss-engine");
|
|
39
|
+
const parser_1 = require("./parser");
|
|
40
|
+
const STYLE_APIS = ['create', 'keyframes', 'viewTransition'];
|
|
41
|
+
const MESSAGES = {
|
|
42
|
+
physical: (name, counterpart) => `'${name}' is the physical name of this property. Write it as '${counterpart}', which follows the writing mode.`,
|
|
43
|
+
logical: (name, counterpart) => `'${name}' is the logical name of this property. This project is written in physical properties; use '${counterpart}'.`,
|
|
44
|
+
};
|
|
45
|
+
const isEnabled = (option) => option === true || (typeof option === 'object' && option !== null);
|
|
46
|
+
const axesOf = (option) => typeof option === 'object' && option !== null
|
|
47
|
+
? (option.sizes ?? false)
|
|
48
|
+
: false;
|
|
49
|
+
const resolvePropertyPolicy = (options) => {
|
|
50
|
+
const withoutLogical = isEnabled(options.withoutLogicalProperties);
|
|
51
|
+
const withoutPhysical = isEnabled(options.withoutPhysicalProperties);
|
|
52
|
+
if (withoutLogical && withoutPhysical)
|
|
53
|
+
throw new Error(`[plumeria] withoutLogicalProperties and withoutPhysicalProperties contradict each other. Enable only the one this project writes against.`);
|
|
54
|
+
if (withoutLogical)
|
|
55
|
+
return {
|
|
56
|
+
reject: 'logical',
|
|
57
|
+
includeAxes: axesOf(options.withoutLogicalProperties),
|
|
58
|
+
};
|
|
59
|
+
if (withoutPhysical)
|
|
60
|
+
return {
|
|
61
|
+
reject: 'physical',
|
|
62
|
+
includeAxes: axesOf(options.withoutPhysicalProperties),
|
|
63
|
+
};
|
|
64
|
+
return undefined;
|
|
65
|
+
};
|
|
66
|
+
exports.resolvePropertyPolicy = resolvePropertyPolicy;
|
|
67
|
+
const assertPropertyPolicy = (ast, policy, resourcePath) => {
|
|
68
|
+
if (!policy)
|
|
69
|
+
return;
|
|
70
|
+
const plumeriaAliases = {};
|
|
71
|
+
const styleObjectOf = (node) => {
|
|
72
|
+
if (parser_1.t.isObjectExpression(node))
|
|
73
|
+
return node;
|
|
74
|
+
if (parser_1.t.isArrowFunctionExpression(node) || parser_1.t.isFunctionExpression(node)) {
|
|
75
|
+
const body = node.body;
|
|
76
|
+
if (parser_1.t.isObjectExpression(body))
|
|
77
|
+
return body;
|
|
78
|
+
if (parser_1.t.isParenthesisExpression(body))
|
|
79
|
+
return styleObjectOf(body.expression);
|
|
80
|
+
}
|
|
81
|
+
return undefined;
|
|
82
|
+
};
|
|
83
|
+
const nameOf = (key) => {
|
|
84
|
+
if (parser_1.t.isIdentifier(key) || parser_1.t.isStringLiteral(key))
|
|
85
|
+
return key.value;
|
|
86
|
+
return '';
|
|
87
|
+
};
|
|
88
|
+
const check = (node) => {
|
|
89
|
+
node.properties.forEach((prop) => {
|
|
90
|
+
if (!parser_1.t.isObjectProperty(prop))
|
|
91
|
+
return;
|
|
92
|
+
const nested = styleObjectOf(prop.value);
|
|
93
|
+
if (nested) {
|
|
94
|
+
check(nested);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
const name = nameOf(prop.key);
|
|
98
|
+
if (!name)
|
|
99
|
+
return;
|
|
100
|
+
const kebab = (0, zss_engine_1.camelToKebabCase)(name);
|
|
101
|
+
if ((0, zss_engine_1.spellingOf)(kebab, policy.includeAxes) !== policy.reject)
|
|
102
|
+
return;
|
|
103
|
+
const counterpart = (0, zss_engine_1.kebabToCamelCase)((0, zss_engine_1.counterpartOf)(kebab));
|
|
104
|
+
throw new Error(`[plumeria] ${MESSAGES[policy.reject](name, counterpart)} (${path.basename(resourcePath)})`);
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
(0, parser_1.traverse)(ast, {
|
|
108
|
+
ImportDeclaration({ node }) {
|
|
109
|
+
if (node.source.value !== '@plumeria/core')
|
|
110
|
+
return;
|
|
111
|
+
node.specifiers.forEach((specifier) => {
|
|
112
|
+
if (specifier.type === 'ImportNamespaceSpecifier' ||
|
|
113
|
+
specifier.type === 'ImportDefaultSpecifier') {
|
|
114
|
+
plumeriaAliases[specifier.local.value] = 'NAMESPACE';
|
|
115
|
+
}
|
|
116
|
+
else if (specifier.type === 'ImportSpecifier') {
|
|
117
|
+
plumeriaAliases[specifier.local.value] = specifier.imported
|
|
118
|
+
? specifier.imported.value
|
|
119
|
+
: specifier.local.value;
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
},
|
|
123
|
+
CallExpression({ node }) {
|
|
124
|
+
const callee = node.callee;
|
|
125
|
+
let apiName;
|
|
126
|
+
if (parser_1.t.isMemberExpression(callee) &&
|
|
127
|
+
parser_1.t.isIdentifier(callee.object) &&
|
|
128
|
+
parser_1.t.isIdentifier(callee.property)) {
|
|
129
|
+
if (plumeriaAliases[callee.object.value] === 'NAMESPACE')
|
|
130
|
+
apiName = callee.property.value;
|
|
131
|
+
}
|
|
132
|
+
else if (parser_1.t.isIdentifier(callee)) {
|
|
133
|
+
apiName = plumeriaAliases[callee.value];
|
|
134
|
+
}
|
|
135
|
+
if (!apiName || !STYLE_APIS.includes(apiName))
|
|
136
|
+
return;
|
|
137
|
+
node.arguments.forEach(({ expression }) => {
|
|
138
|
+
if (!parser_1.t.isObjectExpression(expression))
|
|
139
|
+
return;
|
|
140
|
+
expression.properties.forEach((prop) => {
|
|
141
|
+
if (!parser_1.t.isObjectProperty(prop))
|
|
142
|
+
return;
|
|
143
|
+
const style = styleObjectOf(prop.value);
|
|
144
|
+
if (style)
|
|
145
|
+
check(style);
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
};
|
|
151
|
+
exports.assertPropertyPolicy = assertPropertyPolicy;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plumeria/utils",
|
|
3
|
-
"version": "18.
|
|
3
|
+
"version": "18.4.0",
|
|
4
4
|
"description": "Plumeria Utils",
|
|
5
5
|
"author": "Refirst 11",
|
|
6
6
|
"license": "MIT",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"@swc/core": "1.15.47",
|
|
26
26
|
"lightningcss": "^1.32.0",
|
|
27
27
|
"postcss": "8.5.26",
|
|
28
|
-
"zss-engine": "2.
|
|
28
|
+
"zss-engine": "2.8.0"
|
|
29
29
|
},
|
|
30
30
|
"publishConfig": {
|
|
31
31
|
"access": "public",
|