@wix/validation-infra 0.0.0-stage → 0.5.1
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/README.md +192 -2
- package/dist/constants.d.ts +29 -0
- package/dist/constants.js +45 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +13 -0
- package/dist/package-readers/constants.d.ts +6 -0
- package/dist/package-readers/constants.js +6 -0
- package/dist/package-readers/index.d.ts +1 -0
- package/dist/package-readers/index.js +1 -0
- package/dist/package-readers/read-from-files.d.ts +6 -0
- package/dist/package-readers/read-from-files.js +76 -0
- package/dist/package-readers/types.d.ts +7 -0
- package/dist/package-readers/types.js +1 -0
- package/dist/package-readers/utils.d.ts +4 -0
- package/dist/package-readers/utils.js +15 -0
- package/dist/page-model/build-page-model.d.ts +3 -0
- package/dist/page-model/build-page-model.js +12 -0
- package/dist/page-model/connect-css.d.ts +3 -0
- package/dist/page-model/connect-css.js +43 -0
- package/dist/page-model/constants.d.ts +17 -0
- package/dist/page-model/constants.js +17 -0
- package/dist/page-model/css-selectors.d.ts +2 -0
- package/dist/page-model/css-selectors.js +7 -0
- package/dist/page-model/index.d.ts +4 -0
- package/dist/page-model/index.js +4 -0
- package/dist/page-model/pages.d.ts +2 -0
- package/dist/page-model/pages.js +18 -0
- package/dist/page-model/read-css.d.ts +4 -0
- package/dist/page-model/read-css.js +98 -0
- package/dist/page-model/read-structure.d.ts +3 -0
- package/dist/page-model/read-structure.js +59 -0
- package/dist/page-model/read-theme.d.ts +6 -0
- package/dist/page-model/read-theme.js +14 -0
- package/dist/page-model/types.d.ts +92 -0
- package/dist/page-model/types.js +1 -0
- package/dist/page-model/utils.d.ts +16 -0
- package/dist/page-model/utils.js +29 -0
- package/dist/project-model/index.d.ts +5 -0
- package/dist/project-model/index.js +5 -0
- package/dist/project-model/menu-files.d.ts +4 -0
- package/dist/project-model/menu-files.js +14 -0
- package/dist/project-model/package-json.d.ts +5 -0
- package/dist/project-model/package-json.js +27 -0
- package/dist/project-model/popups.d.ts +4 -0
- package/dist/project-model/popups.js +12 -0
- package/dist/project-model/project-model.d.ts +4 -0
- package/dist/project-model/project-model.js +14 -0
- package/dist/project-model/types.d.ts +20 -0
- package/dist/project-model/types.js +2 -0
- package/dist/rules/index.d.ts +4 -0
- package/dist/rules/index.js +5 -0
- package/dist/rules/project/define-project-rule.d.ts +5 -0
- package/dist/rules/project/define-project-rule.js +4 -0
- package/dist/rules/project/index.d.ts +2 -0
- package/dist/rules/project/index.js +2 -0
- package/dist/rules/project/types.d.ts +16 -0
- package/dist/rules/project/types.js +1 -0
- package/dist/rules/site-app/define-rule.d.ts +5 -0
- package/dist/rules/site-app/define-rule.js +4 -0
- package/dist/rules/site-app/index.d.ts +2 -0
- package/dist/rules/site-app/index.js +1 -0
- package/dist/rules/site-app/types.d.ts +26 -0
- package/dist/rules/site-app/types.js +1 -0
- package/dist/rules/site-code/define-site-code-rule.d.ts +5 -0
- package/dist/rules/site-code/define-site-code-rule.js +4 -0
- package/dist/rules/site-code/index.d.ts +2 -0
- package/dist/rules/site-code/index.js +2 -0
- package/dist/rules/site-code/types.d.ts +11 -0
- package/dist/rules/site-code/types.js +1 -0
- package/dist/rules/types.d.ts +13 -0
- package/dist/rules/types.js +3 -0
- package/dist/rules-adapter/eslint/index.d.ts +1 -0
- package/dist/rules-adapter/eslint/index.js +1 -0
- package/dist/rules-adapter/eslint/types.d.ts +5 -0
- package/dist/rules-adapter/eslint/types.js +1 -0
- package/dist/rules-adapter/index.d.ts +2 -0
- package/dist/rules-adapter/index.js +2 -0
- package/dist/rules-adapter/types.d.ts +16 -0
- package/dist/rules-adapter/types.js +1 -0
- package/dist/rules-adapter/utils.d.ts +7 -0
- package/dist/rules-adapter/utils.js +20 -0
- package/dist/rules-api/component-catalog.d.ts +8 -0
- package/dist/rules-api/component-catalog.js +28 -0
- package/dist/rules-api/constants.d.ts +7 -0
- package/dist/rules-api/constants.js +7 -0
- package/dist/rules-api/index.d.ts +18 -0
- package/dist/rules-api/index.js +14 -0
- package/dist/rules-api/report.d.ts +8 -0
- package/dist/rules-api/report.js +13 -0
- package/dist/rules-api/rules-api.d.ts +13 -0
- package/dist/rules-api/rules-api.js +139 -0
- package/dist/rules-api/types.d.ts +141 -0
- package/dist/rules-api/types.js +1 -0
- package/dist/rules-api/utils.d.ts +14 -0
- package/dist/rules-api/utils.js +27 -0
- package/dist/shared/constants.d.ts +188 -0
- package/dist/shared/constants.js +242 -0
- package/dist/shared/css-variables.d.ts +9 -0
- package/dist/shared/css-variables.js +38 -0
- package/dist/shared/css.d.ts +78 -0
- package/dist/shared/css.js +426 -0
- package/dist/shared/element-match.d.ts +16 -0
- package/dist/shared/element-match.js +72 -0
- package/dist/shared/font-weights.d.ts +2 -0
- package/dist/shared/font-weights.js +551 -0
- package/dist/shared/index.d.ts +16 -0
- package/dist/shared/index.js +15 -0
- package/dist/shared/interactions-config.d.ts +15 -0
- package/dist/shared/interactions-config.js +120 -0
- package/dist/shared/links.d.ts +21 -0
- package/dist/shared/links.js +93 -0
- package/dist/shared/posix-path.d.ts +8 -0
- package/dist/shared/posix-path.js +27 -0
- package/dist/shared/site-files-tree-mapping.d.ts +40 -0
- package/dist/shared/site-files-tree-mapping.js +41 -0
- package/dist/shared/site-folders.d.ts +3 -0
- package/dist/shared/site-folders.js +17 -0
- package/dist/shared/site-media.d.ts +3 -0
- package/dist/shared/site-media.js +11 -0
- package/dist/shared/syntax-tree.d.ts +4 -0
- package/dist/shared/syntax-tree.js +30 -0
- package/dist/shared/transformation-values.d.ts +22 -0
- package/dist/shared/transformation-values.js +74 -0
- package/dist/shared/types.d.ts +477 -0
- package/dist/shared/types.js +1 -0
- package/dist/shared/utils.d.ts +155 -0
- package/dist/shared/utils.js +553 -0
- package/dist/shared/wrapper-contract.d.ts +31 -0
- package/dist/shared/wrapper-contract.js +157 -0
- package/dist/shared/wrapper-image-props.d.ts +3 -0
- package/dist/shared/wrapper-image-props.js +75 -0
- package/dist/site-code-model/constants.d.ts +107 -0
- package/dist/site-code-model/constants.js +102 -0
- package/dist/site-code-model/index.d.ts +3 -0
- package/dist/site-code-model/index.js +4 -0
- package/dist/site-code-model/manifest-values.d.ts +15 -0
- package/dist/site-code-model/manifest-values.js +88 -0
- package/dist/site-code-model/read-module.d.ts +4 -0
- package/dist/site-code-model/read-module.js +267 -0
- package/dist/site-code-model/read-site-code-model.d.ts +9 -0
- package/dist/site-code-model/read-site-code-model.js +42 -0
- package/dist/site-code-model/source-locations.d.ts +5 -0
- package/dist/site-code-model/source-locations.js +95 -0
- package/dist/site-code-model/types.d.ts +102 -0
- package/dist/site-code-model/types.js +1 -0
- package/dist/testing.d.ts +24 -0
- package/dist/testing.js +61 -0
- package/dist/types.d.ts +95 -0
- package/dist/types.js +1 -0
- package/dist/validate.d.ts +7 -0
- package/dist/validate.js +180 -0
- package/package.json +59 -3
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// Reading a unit's servicesConfigs/interactions.ts (a page's, a popup's, a global component's): the state transitions it writes, as the
|
|
2
|
+
// import reads them (converter 139d8ca63a: effects.ts withTransitionOf, :353; stateStyles.ts stateStyleOf), and the components they style.
|
|
3
|
+
import { parse } from '@typescript-eslint/parser';
|
|
4
|
+
import { COMPONENT_SELECTOR, DESCENDANT_SELECTOR } from "./constants.js";
|
|
5
|
+
import { INTERACTIONS_CONFIG, SITE_SRC } from "./site-files-tree-mapping.js";
|
|
6
|
+
import { getKey, getProperties, getProperty } from "./utils.js";
|
|
7
|
+
/** The component that owns the state an effect names by its `effectId`, so the one its `effects` entry styles: the one its selector names,
|
|
8
|
+
* a plain `.comp-x` (the effect's selector, else its interaction's), else its `key`, else its interaction's (converter 0.111.0
|
|
9
|
+
* bindings/kindlessStates.ts stateOwnersOf; interactions-config reads it too). An inline effect's own transition styles its `key` instead
|
|
10
|
+
* (effects.ts targetOf). */
|
|
11
|
+
export function getStateOwner(effect, interaction) {
|
|
12
|
+
const selector = effect.selector ?? interaction.selector;
|
|
13
|
+
return (selector === undefined ? undefined : COMPONENT_SELECTOR.exec(selector)?.[1]) ?? effect.key ?? interaction.key;
|
|
14
|
+
}
|
|
15
|
+
/** A unit's interactions.ts, from the site root; not one the build generates. */
|
|
16
|
+
export const isInteractionsConfig = (file) => file.startsWith(`${SITE_SRC}/`) && file.endsWith(`/${INTERACTIONS_CONFIG}`) && !file.includes('/_generated/');
|
|
17
|
+
/** Every state transition the file writes, in file order: an effect's `transition.styleProperties`, else its `transitionProperties`, as the
|
|
18
|
+
* import takes `transition` first. An inline effect's `transitionProperties` is left out when its `effectId`'s entry in `effects` writes a
|
|
19
|
+
* `transition`, which the import takes instead (resolvedEffectOf, :364). A style property whose name or value isn't a string literal (a
|
|
20
|
+
* variable, a call, a template literal) is left out. Throws when the file doesn't parse. */
|
|
21
|
+
export function readStateTransitions(text) {
|
|
22
|
+
const found = [];
|
|
23
|
+
const entriesWithTransition = new Set();
|
|
24
|
+
const keysByEffectId = new Map();
|
|
25
|
+
const visit = (node, key, interaction) => {
|
|
26
|
+
if (Array.isArray(node))
|
|
27
|
+
return node.forEach((child) => visit(child, null, interaction));
|
|
28
|
+
if (!isNode(node))
|
|
29
|
+
return;
|
|
30
|
+
if (node.type === 'ObjectExpression') {
|
|
31
|
+
const object = node;
|
|
32
|
+
getEntriesWithTransition(object).forEach((id) => entriesWithTransition.add(id));
|
|
33
|
+
addEffectKey(object, keysByEffectId, interaction);
|
|
34
|
+
const transition = getStateTransition(object, key, interaction);
|
|
35
|
+
if (transition)
|
|
36
|
+
found.push(transition);
|
|
37
|
+
if (getProperty(object, 'effects')?.value.type === 'ArrayExpression') {
|
|
38
|
+
const own = getComponentFields(object);
|
|
39
|
+
interaction = { key: own.key ?? interaction.key, selector: own.selector };
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
for (const [field, child] of Object.entries(node)) {
|
|
43
|
+
if (field === 'loc' || field === 'range')
|
|
44
|
+
continue;
|
|
45
|
+
visit(child, node.type === 'Property' && field === 'value' ? getKey(node) : null, interaction);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
visit(parse(text, { loc: true, range: true }), null, { key: undefined, selector: undefined });
|
|
49
|
+
return found
|
|
50
|
+
.filter(({ overlays }) => overlays === undefined || !entriesWithTransition.has(overlays))
|
|
51
|
+
.map(({ transition, key, isEntry }) => ({ ...transition, targets: [...new Set([...(key === null ? [] : [key]), ...(isEntry ? (keysByEffectId.get(transition.stateId) ?? []) : [])])] }));
|
|
52
|
+
}
|
|
53
|
+
/** readStateTransitions of a file that may be missing; none when it is, or when it doesn't parse, which the site's build and typecheck report. */
|
|
54
|
+
export function getStateTransitions(text) {
|
|
55
|
+
if (text === undefined)
|
|
56
|
+
return [];
|
|
57
|
+
try {
|
|
58
|
+
return readStateTransitions(text);
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
return [];
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/** An object's `key` and `selector`, when each is a string. */
|
|
65
|
+
const getComponentFields = (object) => ({
|
|
66
|
+
key: getString(getProperty(object, 'key')?.value) ?? undefined,
|
|
67
|
+
selector: getString(getProperty(object, 'selector')?.value) ?? undefined,
|
|
68
|
+
});
|
|
69
|
+
/** The component an inline effect's own transition styles: its selector's descendant (the state style lands on it,
|
|
70
|
+
* descendantStates.ts descendantStyleOf; its `key` is the owner), else its own `key`, else its interaction's (effects.ts targetOf). */
|
|
71
|
+
function getEffectTarget(effect, interaction) {
|
|
72
|
+
const { key, selector } = getComponentFields(effect);
|
|
73
|
+
return (selector === undefined ? undefined : DESCENDANT_SELECTOR.exec(selector)?.[2]) ?? key ?? interaction.key ?? null;
|
|
74
|
+
}
|
|
75
|
+
/** The owner of the state an inline effect plays (getStateOwner) under its `effectId`: `{ key: 'comp-card', effectId: 'variants-open' }` →
|
|
76
|
+
* 'variants-open': 'comp-card'. A descendant's state effect owns no state (stateOwnersOf skips it). */
|
|
77
|
+
function addEffectKey(effect, keysByEffectId, interaction) {
|
|
78
|
+
const fields = getComponentFields(effect);
|
|
79
|
+
const effectId = getString(getProperty(effect, 'effectId')?.value);
|
|
80
|
+
if (effectId === null || (fields.selector !== undefined && DESCENDANT_SELECTOR.test(fields.selector)))
|
|
81
|
+
return;
|
|
82
|
+
const owner = getStateOwner(fields, interaction);
|
|
83
|
+
if (owner !== undefined)
|
|
84
|
+
keysByEffectId.set(effectId, (keysByEffectId.get(effectId) ?? new Set()).add(owner));
|
|
85
|
+
}
|
|
86
|
+
/** The ids of the config's `effects` entries that write a `transition`; none when the object has no `effects` object. */
|
|
87
|
+
function getEntriesWithTransition(config) {
|
|
88
|
+
const effects = getProperty(config, 'effects')?.value;
|
|
89
|
+
if (effects?.type !== 'ObjectExpression')
|
|
90
|
+
return [];
|
|
91
|
+
return getProperties(effects).flatMap((entry) => {
|
|
92
|
+
const id = getKey(entry);
|
|
93
|
+
return id !== null && entry.value.type === 'ObjectExpression' && getProperty(entry.value, 'transition')?.value.type === 'ObjectExpression' ? [id] : [];
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
/** The effect's state transition, or undefined when it writes none. One read from an inline effect's `transitionProperties` names the
|
|
97
|
+
* `effectId` whose entry it overlays. */
|
|
98
|
+
function getStateTransition(effect, key, interaction) {
|
|
99
|
+
const transition = getProperty(effect, 'transition')?.value;
|
|
100
|
+
const inTransition = transition?.type === 'ObjectExpression';
|
|
101
|
+
const list = inTransition ? getProperty(transition, 'styleProperties')?.value : getProperty(effect, 'transitionProperties')?.value;
|
|
102
|
+
if (list?.type !== 'ArrayExpression')
|
|
103
|
+
return undefined;
|
|
104
|
+
const effectId = getString(getProperty(effect, 'effectId')?.value);
|
|
105
|
+
const stateId = effectId ?? key;
|
|
106
|
+
if (stateId === null)
|
|
107
|
+
return undefined;
|
|
108
|
+
const properties = list.elements.flatMap((element) => (element?.type === 'ObjectExpression' ? getStyleProperty(element) : []));
|
|
109
|
+
const ownKey = effectId === null ? getString(getProperty(effect, 'key')?.value) : getEffectTarget(effect, interaction);
|
|
110
|
+
return { transition: { stateId, line: effect.loc.start.line, properties }, overlays: inTransition || effectId === null ? undefined : effectId, key: ownKey, isEntry: effectId === null };
|
|
111
|
+
}
|
|
112
|
+
/** `{ name: 'transform', value: 'none' }` → its name, value and the value's line; none when either isn't a string. */
|
|
113
|
+
function getStyleProperty(entry) {
|
|
114
|
+
const value = getProperty(entry, 'value')?.value;
|
|
115
|
+
const [name, written] = [getString(getProperty(entry, 'name')?.value), getString(value)];
|
|
116
|
+
return name === null || written === null || !value ? [] : [{ name, value: written, line: value.loc.start.line }];
|
|
117
|
+
}
|
|
118
|
+
/** 'a' → 'a'; null for anything else, a template literal too, which the import doesn't read as a value (astValue.ts astToJsonAt). */
|
|
119
|
+
const getString = (node) => (node?.type === 'Literal' && typeof node.value === 'string' ? node.value : null);
|
|
120
|
+
const isNode = (value) => typeof value === 'object' && value !== null && typeof value.type === 'string';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { JSXElement, ObjectExpression, DataValuesReader, DataLink, RebuiltLink, AnchorLink } from './types.ts';
|
|
2
|
+
/** Each link in the value, walking it as rebuildDataValue does: a typeless link, and each <a> of a rich text. An object's
|
|
3
|
+
* string `label` names the links below it. */
|
|
4
|
+
export declare function findDataLinks(value: unknown, label?: string): DataLink[];
|
|
5
|
+
/** What rebuildRichText does with one <a> (projectData.ts:284-316): it rebuilds a link from an href, the `href` attribute or, with
|
|
6
|
+
* none, a `data-link` object's `href` when it has no `type`; it keeps the anchor as it is with a typed `data-link` or a `dataquery`;
|
|
7
|
+
* and it refuses any other, "Builder.RichText link has no href". */
|
|
8
|
+
export declare function getAnchorLink(anchor: Readonly<Record<string, string | undefined>>): AnchorLink;
|
|
9
|
+
/** The href a link is rebuilt from, when there is one. */
|
|
10
|
+
export declare const getAnchorHref: (link: AnchorLink) => string | undefined;
|
|
11
|
+
/** Each <a> of a rich text's html, as rebuildRichText takes it. */
|
|
12
|
+
export declare const readAnchorLinks: (html: string) => AnchorLink[];
|
|
13
|
+
/** A link the import rebuilds in a component's code, with the attribute it is in (null in an argument's data item, which is rebuilt in any attribute). */
|
|
14
|
+
/** Each link the import rebuilds in a component's values (projectData.ts rebuildDataValue, rebuildDataRefs): in its data attributes, its elementProps
|
|
15
|
+
* entries' data keys and each argument's data item. Not in `data` or an entry's `data`, and not in a raw() or any other call: the import stores
|
|
16
|
+
* those as they are. */
|
|
17
|
+
export declare function getRebuiltLinks(element: JSXElement, reader: DataValuesReader): RebuiltLink[];
|
|
18
|
+
/** A rich text written in the code: its `type` is RICH_TEXT_TYPE and its `html` a string. */
|
|
19
|
+
export declare const isRichTextObject: (object: ObjectExpression) => boolean;
|
|
20
|
+
/** The parsed text; undefined when it isn't JSON. */
|
|
21
|
+
export declare function parseJson(text: string): unknown;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// The links of a data value, as the converter rebuilds them (projectData.ts rebuildDataValue): a typeless link,
|
|
2
|
+
// `{ href, target?, rel?, pageRole? }`, and each <a> of a rich text's html (rebuildRichText). It doesn't look inside either.
|
|
3
|
+
// Converter 0.111 (945389c, projectData.ts:298 rebuildRichText): an <a> with no href in quotes is rebuilt from its data-link's href, when the
|
|
4
|
+
// data-link is an object with a string href and no string type. getAnchorLink reads what rebuildRichText does with one <a> (converter 0.111.1).
|
|
5
|
+
import { bare, getDataAttributes, getDataItemArguments, getDataValue, getDocumentIdentifier, getElementPropsEntries, getEntryDataKeys, getExpression, getKey, getName, getProperties, getProperty, getStoredData, isRecord, } from "./utils.js";
|
|
6
|
+
import { A_TAG, LINK_HTML_ATTRIBUTE, LINK_KEYS, RICH_TEXT_TYPE } from "./constants.js";
|
|
7
|
+
import { unescapeHtml } from "./css.js";
|
|
8
|
+
/** Each link in the value, walking it as rebuildDataValue does: a typeless link, and each <a> of a rich text. An object's
|
|
9
|
+
* string `label` names the links below it. */
|
|
10
|
+
export function findDataLinks(value, label) {
|
|
11
|
+
if (Array.isArray(value))
|
|
12
|
+
return value.flatMap((entry) => findDataLinks(entry, label));
|
|
13
|
+
if (!isRecord(value))
|
|
14
|
+
return [];
|
|
15
|
+
if (value.type === RICH_TEXT_TYPE && typeof value.html === 'string')
|
|
16
|
+
return readAnchors(value.html).map((anchor) => ({ label, href: getAnchorHref(getAnchorLink(anchor)), anchor }));
|
|
17
|
+
if (isTypelessLink(value))
|
|
18
|
+
return [{ label, href: value.href }];
|
|
19
|
+
const own = typeof value.label === 'string' ? value.label : label;
|
|
20
|
+
return Object.values(value).flatMap((nested) => findDataLinks(nested, own));
|
|
21
|
+
}
|
|
22
|
+
/** A link the converter rebuilds from its href: no type, a string href, only link keys (projectData.ts isTypelessLink). */
|
|
23
|
+
function isTypelessLink(value) {
|
|
24
|
+
return value.type === undefined && typeof value.href === 'string' && Object.keys(value).every((key) => LINK_KEYS.includes(key));
|
|
25
|
+
}
|
|
26
|
+
/** What rebuildRichText does with one <a> (projectData.ts:284-316): it rebuilds a link from an href, the `href` attribute or, with
|
|
27
|
+
* none, a `data-link` object's `href` when it has no `type`; it keeps the anchor as it is with a typed `data-link` or a `dataquery`;
|
|
28
|
+
* and it refuses any other, "Builder.RichText link has no href". */
|
|
29
|
+
export function getAnchorLink(anchor) {
|
|
30
|
+
if (anchor['data-link'] !== undefined && anchor.href === undefined) {
|
|
31
|
+
const link = parseJson(anchor['data-link']);
|
|
32
|
+
if (isRecord(link) && typeof link.type === 'string')
|
|
33
|
+
return 'kept';
|
|
34
|
+
if (isRecord(link) && typeof link.href === 'string')
|
|
35
|
+
return { href: link.href };
|
|
36
|
+
}
|
|
37
|
+
if (anchor.href !== undefined)
|
|
38
|
+
return { href: anchor.href };
|
|
39
|
+
return anchor.dataquery === undefined ? 'no_href' : 'kept';
|
|
40
|
+
}
|
|
41
|
+
/** The href a link is rebuilt from, when there is one. */
|
|
42
|
+
export const getAnchorHref = (link) => (typeof link === 'object' ? link.href : undefined);
|
|
43
|
+
/** Each <a> of a rich text's html, as rebuildRichText takes it. */
|
|
44
|
+
export const readAnchorLinks = (html) => readAnchors(html).map(getAnchorLink);
|
|
45
|
+
/** Each <a> of the html: its attributes in quotes, unescaped as the converter reads them (lodash unescape). */
|
|
46
|
+
function readAnchors(html) {
|
|
47
|
+
return [...html.matchAll(A_TAG)].map(([, attributes]) => Object.fromEntries([...attributes.matchAll(LINK_HTML_ATTRIBUTE)].map(([, key, double, single]) => [key, unescapeHtml(double ?? single ?? '')])));
|
|
48
|
+
}
|
|
49
|
+
// ── in a structure file's code ──
|
|
50
|
+
/** A link the import rebuilds in a component's code, with the attribute it is in (null in an argument's data item, which is rebuilt in any attribute). */
|
|
51
|
+
/** Each link the import rebuilds in a component's values (projectData.ts rebuildDataValue, rebuildDataRefs): in its data attributes, its elementProps
|
|
52
|
+
* entries' data keys and each argument's data item. Not in `data` or an entry's `data`, and not in a raw() or any other call: the import stores
|
|
53
|
+
* those as they are. */
|
|
54
|
+
export function getRebuiltLinks(element, reader) {
|
|
55
|
+
const values = getDataAttributes(element, reader)
|
|
56
|
+
.map((attribute) => ({ attribute: getName(attribute), value: getStoredData(getExpression(attribute)) }))
|
|
57
|
+
.filter(({ value }) => Boolean(value));
|
|
58
|
+
for (const { entry } of getElementPropsEntries(element)) {
|
|
59
|
+
values.push(...getEntryDataKeys(entry).filter((property) => getKey(property) !== '_id').map((property) => ({ attribute: 'elementProps', value: property.value })));
|
|
60
|
+
}
|
|
61
|
+
values.push(...getDataItemArguments(element, reader).map(({ node }) => ({ attribute: null, value: node })));
|
|
62
|
+
return values.flatMap(({ attribute, value }) => getLinkObjects(value, reader).map((link) => ({ attribute, link })));
|
|
63
|
+
}
|
|
64
|
+
/** What rebuildDataValue rebuilds as links in a value: a link object, or a rich text's html. It doesn't look inside either. */
|
|
65
|
+
function getLinkObjects(node, reader) {
|
|
66
|
+
const value = bare(node);
|
|
67
|
+
if (value.type === 'ArrayExpression')
|
|
68
|
+
return value.elements.flatMap((element) => (element && element.type !== 'SpreadElement' ? getLinkObjects(element, reader) : []));
|
|
69
|
+
if (value.type !== 'ObjectExpression')
|
|
70
|
+
return [];
|
|
71
|
+
if (isRichTextObject(value) || isLinkObject(value, reader))
|
|
72
|
+
return [value];
|
|
73
|
+
return getProperties(value).flatMap((property) => getLinkObjects(property.value, reader));
|
|
74
|
+
}
|
|
75
|
+
/** A rich text written in the code: its `type` is RICH_TEXT_TYPE and its `html` a string. */
|
|
76
|
+
export const isRichTextObject = (object) => getDataValue(getProperty(object, 'type')?.value ?? null) === RICH_TEXT_TYPE && typeof getDataValue(getProperty(object, 'html')?.value ?? null) === 'string';
|
|
77
|
+
/** A typeless link written in the code: only link keys, and an href that is a string or a document's url. */
|
|
78
|
+
function isLinkObject(object, reader) {
|
|
79
|
+
const properties = getProperties(object);
|
|
80
|
+
if (properties.length !== object.properties.length || !properties.every((property) => LINK_KEYS.includes(getKey(property) ?? '')))
|
|
81
|
+
return false;
|
|
82
|
+
const href = getProperty(object, 'href')?.value;
|
|
83
|
+
return href !== undefined && (typeof getDataValue(href) === 'string' || getDocumentIdentifier(bare(href), reader) !== null);
|
|
84
|
+
}
|
|
85
|
+
/** The parsed text; undefined when it isn't JSON. */
|
|
86
|
+
export function parseJson(text) {
|
|
87
|
+
try {
|
|
88
|
+
return JSON.parse(text);
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** A path from the site root that stays inside the site: no leading /, no .. segment. */
|
|
2
|
+
export declare const isSitePath: (file: string) => boolean;
|
|
3
|
+
export declare const dirname: (file: string) => string;
|
|
4
|
+
export declare const basename: (file: string) => string;
|
|
5
|
+
/** join('a/b', '../c') → 'a/c'. Resolves `.` and `..`; a `..` past the start stays as is. */
|
|
6
|
+
export declare function join(...parts: string[]): string;
|
|
7
|
+
/** relative('a/b/c', 'a/x') → '../../x'. */
|
|
8
|
+
export declare function relative(from: string, to: string): string;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// Site paths are always posix, from the site root: the path operations the rules need, with no Node.
|
|
2
|
+
/** A path from the site root that stays inside the site: no leading /, no .. segment. */
|
|
3
|
+
export const isSitePath = (file) => !file.startsWith('/') && !file.split('/').includes('..');
|
|
4
|
+
export const dirname = (file) => (file.includes('/') ? file.slice(0, file.lastIndexOf('/')) : '.');
|
|
5
|
+
export const basename = (file) => file.slice(file.lastIndexOf('/') + 1);
|
|
6
|
+
/** join('a/b', '../c') → 'a/c'. Resolves `.` and `..`; a `..` past the start stays as is. */
|
|
7
|
+
export function join(...parts) {
|
|
8
|
+
const out = [];
|
|
9
|
+
for (const segment of parts.join('/').split('/')) {
|
|
10
|
+
if (segment === '' || segment === '.')
|
|
11
|
+
continue;
|
|
12
|
+
if (segment === '..' && out.length && out.at(-1) !== '..')
|
|
13
|
+
out.pop();
|
|
14
|
+
else
|
|
15
|
+
out.push(segment);
|
|
16
|
+
}
|
|
17
|
+
return out.join('/') || '.';
|
|
18
|
+
}
|
|
19
|
+
/** relative('a/b/c', 'a/x') → '../../x'. */
|
|
20
|
+
export function relative(from, to) {
|
|
21
|
+
const a = join(from).split('/').filter((s) => s !== '.');
|
|
22
|
+
const b = join(to).split('/').filter((s) => s !== '.');
|
|
23
|
+
let i = 0;
|
|
24
|
+
while (i < a.length && i < b.length && a[i] === b[i])
|
|
25
|
+
i++;
|
|
26
|
+
return [...Array(a.length - i).fill('..'), ...b.slice(i)].join('/') || '.';
|
|
27
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/** The workspace packages: the site and its site code, the only two the import sends. */
|
|
2
|
+
export declare const WORKSPACE_PACKAGES = "packages";
|
|
3
|
+
/** The site package (@site/site-app): what the import reads the site from. */
|
|
4
|
+
export declare const SITE_APP = "packages/site-app";
|
|
5
|
+
/** The site code (@site/site-code), when the site has one: the site's own Wix CLI app, which the import uploads whole. */
|
|
6
|
+
export declare const SITE_CODE = "packages/site-code";
|
|
7
|
+
/** The site package's manifest: its dependencies, scripts and `origami` (adapter, layout). */
|
|
8
|
+
export declare const SITE_PACKAGE_JSON = "packages/site-app/package.json";
|
|
9
|
+
export declare const SITE_SRC = "packages/site-app/src";
|
|
10
|
+
/** The site code's own files: its components, contexts and function libraries. Everything outside it the export copied from the Wix app as is. */
|
|
11
|
+
export declare const SITE_CODE_SRC = "packages/site-code/src";
|
|
12
|
+
/** An extension of the site code, under SITE_CODE_SRC: the export reads every one, registered in extensions.ts or not. */
|
|
13
|
+
export declare const EXTENSION_FILE: RegExp;
|
|
14
|
+
/** A component's manifest as `wix generate manifest` writes it from the React code; import-site rewrites it before the upload. */
|
|
15
|
+
export declare const GENERATED_FILE: RegExp;
|
|
16
|
+
/** Beside a component's generated file, the three files `wix generate manifest` writes it from: the props type and
|
|
17
|
+
* `defaultProps` (its `data`), the CSS module (its `cssProperties` and their defaults), and the React file (its
|
|
18
|
+
* `selector` and `elements`, from the class names). A JavaScript component (`<name>.jsx`) has no props file: its
|
|
19
|
+
* props (a JSDoc type) and `defaultProps` are in the React file. */
|
|
20
|
+
export declare const PROPS_FILE_SUFFIX = ".props.ts";
|
|
21
|
+
export declare const STYLES_FILE_SUFFIX = ".module.css";
|
|
22
|
+
export declare const COMPONENT_FILE_SUFFIXES: readonly string[];
|
|
23
|
+
/** One page per folder; routes can be nested (about-us/team). */
|
|
24
|
+
export declare const PAGES_FOLDER = "packages/site-app/src/pages";
|
|
25
|
+
/** One popup per folder, directly under it (popups have no url, so no nesting). */
|
|
26
|
+
export declare const POPUPS_FOLDER = "packages/site-app/src/popups";
|
|
27
|
+
/** What every page shares: the global components, the menus, the theme. */
|
|
28
|
+
export declare const GLOBAL_FOLDER = "packages/site-app/src/global";
|
|
29
|
+
/** Inside src/: one global component per folder (the header, the footer, any other shared section). A page imports one from here. */
|
|
30
|
+
export declare const GLOBAL_COMPONENTS = "global/components";
|
|
31
|
+
export declare const GLOBAL_COMPONENTS_FOLDER = "packages/site-app/src/global/components";
|
|
32
|
+
/** Inside src/: one file per menu. A page imports a menu from here (`global/menus/<menu id>`). */
|
|
33
|
+
export declare const GLOBAL_MENUS = "global/menus";
|
|
34
|
+
export declare const THEME_FILE = "packages/site-app/src/global/themes/theme.css";
|
|
35
|
+
/** The site component catalog the export writes: the components, context providers and function libraries of the site's apps. */
|
|
36
|
+
export declare const COMPONENT_CATALOG_FILE = "packages/site-app/site-component-catalog.json";
|
|
37
|
+
/** Inside a page's, a popup's or a global component's folder: its interactions (the converter's servicesConfigs). */
|
|
38
|
+
export declare const INTERACTIONS_CONFIG = "servicesConfigs/interactions.ts";
|
|
39
|
+
/** The site's menu item files. */
|
|
40
|
+
export declare const GLOBAL_MENUS_FOLDER = "packages/site-app/src/global/menus";
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Where things sit in the exported site, from the site's root. The one place that knows its folders (docs/export-site-tree.md).
|
|
2
|
+
/** The workspace packages: the site and its site code, the only two the import sends. */
|
|
3
|
+
export const WORKSPACE_PACKAGES = 'packages';
|
|
4
|
+
/** The site package (@site/site-app): what the import reads the site from. */
|
|
5
|
+
export const SITE_APP = `${WORKSPACE_PACKAGES}/site-app`;
|
|
6
|
+
/** The site code (@site/site-code), when the site has one: the site's own Wix CLI app, which the import uploads whole. */
|
|
7
|
+
export const SITE_CODE = `${WORKSPACE_PACKAGES}/site-code`;
|
|
8
|
+
/** The site package's manifest: its dependencies, scripts and `origami` (adapter, layout). */
|
|
9
|
+
export const SITE_PACKAGE_JSON = `${SITE_APP}/package.json`;
|
|
10
|
+
export const SITE_SRC = `${SITE_APP}/src`;
|
|
11
|
+
/** The site code's own files: its components, contexts and function libraries. Everything outside it the export copied from the Wix app as is. */
|
|
12
|
+
export const SITE_CODE_SRC = `${SITE_CODE}/src`;
|
|
13
|
+
/** An extension of the site code, under SITE_CODE_SRC: the export reads every one, registered in extensions.ts or not. */
|
|
14
|
+
export const EXTENSION_FILE = /\.extension\.[cm]?[jt]sx?$/;
|
|
15
|
+
/** A component's manifest as `wix generate manifest` writes it from the React code; import-site rewrites it before the upload. */
|
|
16
|
+
export const GENERATED_FILE = /\.generated\.[cm]?[jt]sx?$/;
|
|
17
|
+
/** Beside a component's generated file, the three files `wix generate manifest` writes it from: the props type and
|
|
18
|
+
* `defaultProps` (its `data`), the CSS module (its `cssProperties` and their defaults), and the React file (its
|
|
19
|
+
* `selector` and `elements`, from the class names). A JavaScript component (`<name>.jsx`) has no props file: its
|
|
20
|
+
* props (a JSDoc type) and `defaultProps` are in the React file. */
|
|
21
|
+
export const PROPS_FILE_SUFFIX = '.props.ts';
|
|
22
|
+
export const STYLES_FILE_SUFFIX = '.module.css';
|
|
23
|
+
export const COMPONENT_FILE_SUFFIXES = ['.tsx', '.jsx'];
|
|
24
|
+
/** One page per folder; routes can be nested (about-us/team). */
|
|
25
|
+
export const PAGES_FOLDER = `${SITE_SRC}/pages`;
|
|
26
|
+
/** One popup per folder, directly under it (popups have no url, so no nesting). */
|
|
27
|
+
export const POPUPS_FOLDER = `${SITE_SRC}/popups`;
|
|
28
|
+
/** What every page shares: the global components, the menus, the theme. */
|
|
29
|
+
export const GLOBAL_FOLDER = `${SITE_SRC}/global`;
|
|
30
|
+
/** Inside src/: one global component per folder (the header, the footer, any other shared section). A page imports one from here. */
|
|
31
|
+
export const GLOBAL_COMPONENTS = 'global/components';
|
|
32
|
+
export const GLOBAL_COMPONENTS_FOLDER = `${SITE_SRC}/${GLOBAL_COMPONENTS}`;
|
|
33
|
+
/** Inside src/: one file per menu. A page imports a menu from here (`global/menus/<menu id>`). */
|
|
34
|
+
export const GLOBAL_MENUS = 'global/menus';
|
|
35
|
+
export const THEME_FILE = `${GLOBAL_FOLDER}/themes/theme.css`;
|
|
36
|
+
/** The site component catalog the export writes: the components, context providers and function libraries of the site's apps. */
|
|
37
|
+
export const COMPONENT_CATALOG_FILE = `${SITE_APP}/site-component-catalog.json`;
|
|
38
|
+
/** Inside a page's, a popup's or a global component's folder: its interactions (the converter's servicesConfigs). */
|
|
39
|
+
export const INTERACTIONS_CONFIG = 'servicesConfigs/interactions.ts';
|
|
40
|
+
/** The site's menu item files. */
|
|
41
|
+
export const GLOBAL_MENUS_FOLDER = `${SITE_SRC}/${GLOBAL_MENUS}`;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { FolderEntry } from '@wix/origami-types';
|
|
2
|
+
/** A folder's files and folders by its path from src/ ('pages/about'), as `readdir` lists them; nothing for a folder with no file under it. */
|
|
3
|
+
export declare function createSrcReaddir(files: readonly string[]): (path: string) => FolderEntry[];
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { SITE_SRC } from "./site-files-tree-mapping.js";
|
|
2
|
+
/** A folder's files and folders by its path from src/ ('pages/about'), as `readdir` lists them; nothing for a folder with no file under it. */
|
|
3
|
+
export function createSrcReaddir(files) {
|
|
4
|
+
const folders = new Map();
|
|
5
|
+
for (const file of files) {
|
|
6
|
+
if (!file.startsWith(`${SITE_SRC}/`))
|
|
7
|
+
continue;
|
|
8
|
+
const segments = file.slice(SITE_SRC.length + 1).split('/');
|
|
9
|
+
for (let depth = 0; depth < segments.length; depth++) {
|
|
10
|
+
const folder = segments.slice(0, depth).join('/');
|
|
11
|
+
const entries = folders.get(folder) ?? new Map();
|
|
12
|
+
entries.set(segments[depth], depth < segments.length - 1);
|
|
13
|
+
folders.set(folder, entries);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return (path) => [...(folders.get(path) ?? [])].map(([name, isFolder]) => ({ name, isFile: () => !isFolder, isDirectory: () => isFolder }));
|
|
17
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { REMOTE_MEDIA } from "./constants.js";
|
|
2
|
+
import { SITE_APP } from "./site-files-tree-mapping.js";
|
|
3
|
+
import { dirname, join } from "./posix-path.js";
|
|
4
|
+
/** Remote URLs and files beside the page or in public need uploading; all paths stay site-relative. */
|
|
5
|
+
export function isOutsideWixMedia(uri, jsxFile, readFile) {
|
|
6
|
+
if (REMOTE_MEDIA.test(uri))
|
|
7
|
+
return true;
|
|
8
|
+
const file = uri.replace(/^\/+/, '');
|
|
9
|
+
return [dirname(jsxFile), `${SITE_APP}/public`].map(base => join(base, file))
|
|
10
|
+
.some(candidate => candidate.startsWith(`${SITE_APP}/`) && readFile(candidate) !== undefined);
|
|
11
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { AstNode, Source } from './types.ts';
|
|
2
|
+
/** Calls visit(node, ancestors) for every node. Skips `parent`, which ESLint's syntax tree has (the parser's alone doesn't). */
|
|
3
|
+
export declare function walk(node: AstNode, ancestors: AstNode[], visit: (node: AstNode, ancestors: AstNode[]) => void): void;
|
|
4
|
+
export declare function createSourceReader(text: string): Source;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const isAstNode = (value) => typeof value?.type === 'string';
|
|
2
|
+
/** Calls visit(node, ancestors) for every node. Skips `parent`, which ESLint's syntax tree has (the parser's alone doesn't). */
|
|
3
|
+
export function walk(node, ancestors, visit) {
|
|
4
|
+
visit(node, ancestors);
|
|
5
|
+
ancestors.push(node);
|
|
6
|
+
for (const [key, value] of Object.entries(node)) {
|
|
7
|
+
if (key === 'parent')
|
|
8
|
+
continue;
|
|
9
|
+
for (const child of Array.isArray(value) ? value : [value])
|
|
10
|
+
if (isAstNode(child))
|
|
11
|
+
walk(child, ancestors, visit);
|
|
12
|
+
}
|
|
13
|
+
ancestors.pop();
|
|
14
|
+
}
|
|
15
|
+
export function createSourceReader(text) {
|
|
16
|
+
const lineStarts = [0];
|
|
17
|
+
for (let i = 0; i < text.length; i++)
|
|
18
|
+
if (text[i] === '\n')
|
|
19
|
+
lineStarts.push(i + 1);
|
|
20
|
+
const position = (offset) => {
|
|
21
|
+
let line = 0;
|
|
22
|
+
while (line + 1 < lineStarts.length && lineStarts[line + 1] <= offset)
|
|
23
|
+
line++;
|
|
24
|
+
return { line: line + 1, column: offset - lineStarts[line] };
|
|
25
|
+
};
|
|
26
|
+
return {
|
|
27
|
+
code: (node) => text.slice(...node.range).replace(/\s+/g, ' ').trim(),
|
|
28
|
+
loc: (node) => ({ start: position(node.range[0]), end: position(node.range[1]) }),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { CssFunction, Quantity } from './types.ts';
|
|
2
|
+
/** The import reads `--spx(12)` as `12spx` before it reads a value, only with a leading digit and no spaces (spxTransformer.ts:13
|
|
3
|
+
* REVERSE_SPX_PATTERN). */
|
|
4
|
+
export declare const restoreSpx: (value: string) => string;
|
|
5
|
+
/** The value as a number and its unit, or undefined when it isn't one (`center`, `+1`, `calc(…)`, `1e999`). */
|
|
6
|
+
export declare function getQuantity(css: string): Quantity | undefined;
|
|
7
|
+
/** `none` as no function, or a list of functions of comma-separated numbers, `name(a, b) name(c)`, nothing inside them (cssFunctionsOf,
|
|
8
|
+
* :220). Undefined when the value is neither, or a value isn't a number. */
|
|
9
|
+
export declare function getCssFunctions(css: string): CssFunction[] | undefined;
|
|
10
|
+
/** `none`, or translate, scale, rotate and skewX skewY, each at most once and in that order, skewX and skewY together (transformOfCss,
|
|
11
|
+
* :243). An empty value is no function, so it passes too. */
|
|
12
|
+
export declare function isTransform(css: string): boolean;
|
|
13
|
+
/** One or two lengths, `<x> <y>` (originOfCss, :286). */
|
|
14
|
+
export declare function isTransformOrigin(css: string): boolean;
|
|
15
|
+
/** All three of opacity(<n>%) grayscale(<n>%) blur(<n>px), in that order, one value each (filterOfCss, :267). */
|
|
16
|
+
export declare function isFilter(css: string): boolean;
|
|
17
|
+
/** Any plain number: the import clamps it to 0–1 (opacityOfCss, :297). */
|
|
18
|
+
export declare function isOpacity(css: string): boolean;
|
|
19
|
+
/** `hidden` or `visible` (opacityOfCss, :297: HIDDEN_BY_VISIBILITY). */
|
|
20
|
+
export declare const isVisibility: (css: string) => boolean;
|
|
21
|
+
/** A zLayer's z-index, written as Z_INDEXES writes it (zLayerOf, :154): `01` and `1.0` are none. */
|
|
22
|
+
export declare const isZIndex: (css: string) => boolean;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// Reading a transformation's value (transform, transform-origin, filter, opacity, visibility, z-index) as the import reads it:
|
|
2
|
+
// converter 139d8ca63a, src/interactions/tables/transformations.ts (the line of each function in its comment). The converter stops the
|
|
3
|
+
// import where a reader here says no. Rules import them from rules-api/index.ts.
|
|
4
|
+
import { ANGLE_UNITS, CSS_FUNCTION, CSS_FUNCTION_LIST, FILTER_UNITS, LENGTH_UNITS, QUANTITY, Z_INDEXES } from "./constants.js";
|
|
5
|
+
/** The import reads `--spx(12)` as `12spx` before it reads a value, only with a leading digit and no spaces (spxTransformer.ts:13
|
|
6
|
+
* REVERSE_SPX_PATTERN). */
|
|
7
|
+
export const restoreSpx = (value) => value.replace(/--spx\((-?\d+(?:\.\d+)?)\)/g, '$1spx');
|
|
8
|
+
/** The value as a number and its unit, or undefined when it isn't one (`center`, `+1`, `calc(…)`, `1e999`). */
|
|
9
|
+
export function getQuantity(css) {
|
|
10
|
+
const [, value, unit] = QUANTITY.exec(css.trim()) ?? [];
|
|
11
|
+
return value !== undefined && Number.isFinite(Number(value)) ? { value: Number(value), unit: unit.toLowerCase() } : undefined;
|
|
12
|
+
}
|
|
13
|
+
/** `none` as no function, or a list of functions of comma-separated numbers, `name(a, b) name(c)`, nothing inside them (cssFunctionsOf,
|
|
14
|
+
* :220). Undefined when the value is neither, or a value isn't a number. */
|
|
15
|
+
export function getCssFunctions(css) {
|
|
16
|
+
if (css.trim() === 'none')
|
|
17
|
+
return [];
|
|
18
|
+
if (!CSS_FUNCTION_LIST.test(css))
|
|
19
|
+
return undefined;
|
|
20
|
+
const functions = [];
|
|
21
|
+
for (const [, name, args] of css.matchAll(CSS_FUNCTION)) {
|
|
22
|
+
const quantities = args.split(',').map(getQuantity);
|
|
23
|
+
if (!quantities.every((quantity) => quantity !== undefined))
|
|
24
|
+
return undefined;
|
|
25
|
+
functions.push({ name: name.toLowerCase(), args: quantities });
|
|
26
|
+
}
|
|
27
|
+
return functions;
|
|
28
|
+
}
|
|
29
|
+
const isLength = ({ value, unit }) => (value === 0 && unit === '') || LENGTH_UNITS.includes(unit);
|
|
30
|
+
const isAngle = ({ unit }) => ANGLE_UNITS.includes(unit);
|
|
31
|
+
const isPlainNumber = ({ unit }) => unit === '';
|
|
32
|
+
/** An x and an optional y (pointOfCss, :109). */
|
|
33
|
+
const isPoint = (args, isAxis) => args.length <= 2 && args.every(isAxis);
|
|
34
|
+
/** The transform functions in the order the import reads them, skewX and skewY as one pair (TRANSFORM_FUNCTIONS, :122), and what each
|
|
35
|
+
* one's values are (argsOfFunctions, :235: one value in each of skewX and skewY). */
|
|
36
|
+
const TRANSFORM_FUNCTIONS = [
|
|
37
|
+
{ names: ['translate'], reads: (args) => isPoint(args, isLength) },
|
|
38
|
+
{ names: ['scale'], reads: (args) => isPoint(args, isPlainNumber) },
|
|
39
|
+
{ names: ['rotate'], reads: (args) => args.length === 1 && isAngle(args[0]) },
|
|
40
|
+
{ names: ['skewx', 'skewy'], reads: (args) => args.length === 1 && isAngle(args[0]) },
|
|
41
|
+
];
|
|
42
|
+
/** `none`, or translate, scale, rotate and skewX skewY, each at most once and in that order, skewX and skewY together (transformOfCss,
|
|
43
|
+
* :243). An empty value is no function, so it passes too. */
|
|
44
|
+
export function isTransform(css) {
|
|
45
|
+
const functions = getCssFunctions(css);
|
|
46
|
+
if (!functions)
|
|
47
|
+
return false;
|
|
48
|
+
const names = functions.map(({ name }) => name);
|
|
49
|
+
const presentFunctions = TRANSFORM_FUNCTIONS.filter((transformFunction) => names.includes(transformFunction.names[0]));
|
|
50
|
+
if (presentFunctions.flatMap((transformFunction) => transformFunction.names).join(' ') !== names.join(' '))
|
|
51
|
+
return false;
|
|
52
|
+
return functions.every(({ name, args }) => presentFunctions.find((transformFunction) => transformFunction.names.includes(name)).reads(args));
|
|
53
|
+
}
|
|
54
|
+
/** One or two lengths, `<x> <y>` (originOfCss, :286). */
|
|
55
|
+
export function isTransformOrigin(css) {
|
|
56
|
+
const quantities = css.trim().split(/\s+/).map(getQuantity);
|
|
57
|
+
return quantities.every((quantity) => quantity !== undefined) && isPoint(quantities, isLength);
|
|
58
|
+
}
|
|
59
|
+
/** All three of opacity(<n>%) grayscale(<n>%) blur(<n>px), in that order, one value each (filterOfCss, :267). */
|
|
60
|
+
export function isFilter(css) {
|
|
61
|
+
const functions = getCssFunctions(css);
|
|
62
|
+
if (!functions || functions.map(({ name }) => name).join(' ') !== Object.keys(FILTER_UNITS).join(' '))
|
|
63
|
+
return false;
|
|
64
|
+
return functions.every(({ name, args }) => args.length === 1 && args[0].unit === FILTER_UNITS[name]);
|
|
65
|
+
}
|
|
66
|
+
/** Any plain number: the import clamps it to 0–1 (opacityOfCss, :297). */
|
|
67
|
+
export function isOpacity(css) {
|
|
68
|
+
const quantity = getQuantity(css);
|
|
69
|
+
return quantity !== undefined && isPlainNumber(quantity);
|
|
70
|
+
}
|
|
71
|
+
/** `hidden` or `visible` (opacityOfCss, :297: HIDDEN_BY_VISIBILITY). */
|
|
72
|
+
export const isVisibility = (css) => ['hidden', 'visible'].includes(css.trim());
|
|
73
|
+
/** A zLayer's z-index, written as Z_INDEXES writes it (zLayerOf, :154): `01` and `1.0` are none. */
|
|
74
|
+
export const isZIndex = (css) => Z_INDEXES.includes(css.trim());
|