@wix/origami-site-runtime 1.0.10 → 1.0.12
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wix/origami-site-runtime",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.12",
|
|
4
4
|
"description": "Vite development and build helpers for wix-import static sites",
|
|
5
5
|
"main": "./src/index.js",
|
|
6
6
|
"files": [
|
|
@@ -65,5 +65,5 @@
|
|
|
65
65
|
"./default-error-404": "./src/default-error-404.jsx"
|
|
66
66
|
},
|
|
67
67
|
"type": "module",
|
|
68
|
-
"falconPackageHash": "
|
|
68
|
+
"falconPackageHash": "2e7b7eab8ba52e6afa27dfa363e20a634506137bd61591f8bf6015a3"
|
|
69
69
|
}
|
package/src/cssPlugins/index.js
CHANGED
|
@@ -7,13 +7,15 @@
|
|
|
7
7
|
// stage guarantees a plugin sees. The order matters once: mixin bodies are copied into their calling rules before
|
|
8
8
|
// layout routes declarations to wrappers and SPX converts calls using the browser's active settings. stack-children
|
|
9
9
|
// only checks, and runs between mixins and layout: it needs the mixins' declarations and the stack rules as authored,
|
|
10
|
-
// before layout compiles them away.
|
|
10
|
+
// before layout compiles them away. presets runs after mixins too, so a `--preset` a mixin body carries is moved
|
|
11
|
+
// like an authored one. fonts only checks the theme's font tokens, as authored.
|
|
11
12
|
//
|
|
12
13
|
// `@layer` needs no plugin: cascade layers have been in every browser since March 2022.
|
|
13
14
|
|
|
14
15
|
import { customMediaPlugin } from './customMedia.js'
|
|
15
16
|
import { fontsPlugin } from './fonts.js'
|
|
16
17
|
import { mixinsPlugin } from './mixins.js'
|
|
18
|
+
import { presetsPlugin } from './presets.js'
|
|
17
19
|
import { layoutPlugin } from './layout/index.js'
|
|
18
20
|
import { spxPlugin } from './spx/index.js'
|
|
19
21
|
import { stackChildrenPlugin } from './stackChildren.js'
|
|
@@ -24,6 +26,7 @@ export const cssPlugins = Object.freeze([
|
|
|
24
26
|
fontsPlugin,
|
|
25
27
|
mixinsPlugin,
|
|
26
28
|
stackChildrenPlugin,
|
|
29
|
+
presetsPlugin,
|
|
27
30
|
layoutPlugin,
|
|
28
31
|
spxPlugin,
|
|
29
32
|
])
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// A preset is set on the component's own rule (`#id` or `.id`): `--preset` for the component, `--preset-{key}` for
|
|
2
|
+
// its ref element `key` (as listed in the wrapper's `REF_ELEMENTS`). An element nested deeper is reached the same way,
|
|
3
|
+
// from the rule of the element it sits in: `.id .{parent} { --preset-{key}: … }`. The wrapper reads
|
|
4
|
+
// `--preset` off the presets-wrapper classes it renders (see the origami-component-usage skill), so each declaration
|
|
5
|
+
// moves there, as `--preset` in a rule of its own: `.{id}-presets-wrapper`, or `{selector} .{key}-presets-wrapper` so
|
|
6
|
+
// an inner element's preset reaches that instance only. A rule that does not start at a component is left as authored.
|
|
7
|
+
//
|
|
8
|
+
// A preset on a component selector that can't be mapped is reported as a warning and left as authored rather than failing the
|
|
9
|
+
// build: exported sites still carry presets in the older shape, and they must keep building until they are migrated.
|
|
10
|
+
|
|
11
|
+
import postcss from 'postcss'
|
|
12
|
+
|
|
13
|
+
const PRESET = /^--preset(?:-([\w-]+))?$/
|
|
14
|
+
const COMPONENT = /^[#.]([\w-]+)$/
|
|
15
|
+
const WRAPPER = '-presets-wrapper'
|
|
16
|
+
|
|
17
|
+
/** Where a preset on `selector` goes: undefined when `selector` does not start at a component, null when it can't go. */
|
|
18
|
+
const target = (selector, key) => {
|
|
19
|
+
const [first] = selector.split(/\s+/, 1)
|
|
20
|
+
const id = COMPONENT.exec(first)?.[1]
|
|
21
|
+
if (id === undefined || id.endsWith(WRAPPER)) return undefined
|
|
22
|
+
if (key !== undefined) return `${selector} .${key}${WRAPPER}`
|
|
23
|
+
return selector === first ? `.${id}${WRAPPER}` : null
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** @type {import('../transform/types.js').CssTransformPlugin} */
|
|
27
|
+
export const presetsPlugin = {
|
|
28
|
+
name: 'presets',
|
|
29
|
+
order: 13,
|
|
30
|
+
transform(root, context) {
|
|
31
|
+
/** @type {import('postcss').Declaration[]} */
|
|
32
|
+
const declarations = []
|
|
33
|
+
root.walkDecls(PRESET, declaration => {
|
|
34
|
+
if (declaration.parent?.type === 'rule') declarations.push(declaration)
|
|
35
|
+
})
|
|
36
|
+
// Last first: each moved declaration lands right after its outermost rule, so source order is kept.
|
|
37
|
+
for (const declaration of declarations.reverse()) {
|
|
38
|
+
const rule = /** @type {import('postcss').Rule} */ (declaration.parent)
|
|
39
|
+
// The outermost rule, and the full selectors resolved as CSS Nesting does.
|
|
40
|
+
let outer = rule
|
|
41
|
+
let selectors = rule.selectors
|
|
42
|
+
while (outer.parent?.type === 'rule') {
|
|
43
|
+
outer = /** @type {import('postcss').Rule} */ (outer.parent)
|
|
44
|
+
const inner = selectors
|
|
45
|
+
selectors = outer.selectors.flatMap(parent =>
|
|
46
|
+
inner.map(selector => (selector.includes('&') ? selector.replaceAll('&', parent) : `${parent} ${selector}`))
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
const targets = selectors.map(selector => target(selector, PRESET.exec(declaration.prop)?.[1]))
|
|
50
|
+
if (targets.every(selector => selector === undefined)) continue
|
|
51
|
+
if (!targets.every(Boolean)) {
|
|
52
|
+
context.warn?.(
|
|
53
|
+
declaration,
|
|
54
|
+
`presets: ${context.relativePath ?? context.filePath}: ` +
|
|
55
|
+
`${declaration.prop} on "${selectors.join(', ')}": set --preset on #id or .id alone, ` +
|
|
56
|
+
`and an inner element's as --preset-{key} on the rule of the element it sits in. Left as authored.`
|
|
57
|
+
)
|
|
58
|
+
continue
|
|
59
|
+
}
|
|
60
|
+
declaration.prop = '--preset'
|
|
61
|
+
const presetRule = postcss.rule({ selector: targets.join(', ') })
|
|
62
|
+
if (rule.source) presetRule.source = rule.source
|
|
63
|
+
outer.after(presetRule.append(declaration))
|
|
64
|
+
// Drop the rules the move left empty, from the declaration's own up to the outermost.
|
|
65
|
+
for (let node = rule; !node.nodes.length; ) {
|
|
66
|
+
const parent = node.parent
|
|
67
|
+
node.remove()
|
|
68
|
+
if (node === outer) break
|
|
69
|
+
node = /** @type {import('postcss').Rule} */ (parent)
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
}
|
|
@@ -46,8 +46,11 @@ export const createCssPostcssPlugin = ({ selectPlugins, contextFor, failures })
|
|
|
46
46
|
declared.add(file)
|
|
47
47
|
result.messages.push({ type: 'dependency', plugin: 'wix-import-css-transform', file, parent: from })
|
|
48
48
|
}
|
|
49
|
+
// A plugin reports a problem that need not stop the build as a PostCSS warning, which Vite prints with the
|
|
50
|
+
// node's code frame.
|
|
51
|
+
const warn = (node, text) => node.warn(result, text)
|
|
49
52
|
try {
|
|
50
|
-
runCssPlugins({ plugins, root, context: { ...fileContext, addDependency } })
|
|
53
|
+
runCssPlugins({ plugins, root, context: { ...fileContext, addDependency, warn } })
|
|
51
54
|
failures?.delete(from)
|
|
52
55
|
} catch (error) {
|
|
53
56
|
failures?.set(from, declared)
|
package/src/transform/types.js
CHANGED
|
@@ -36,10 +36,12 @@
|
|
|
36
36
|
* }} CssTransformPlugin
|
|
37
37
|
*
|
|
38
38
|
* @typedef {TransformContext & {
|
|
39
|
-
* addDependency?: (file: string) => void
|
|
39
|
+
* addDependency?: (file: string) => void,
|
|
40
|
+
* warn?: (node: import('postcss').Node, text: string) => void
|
|
40
41
|
* }} CssTransformContext
|
|
41
42
|
* `addDependency` declares a file the plugin read besides the stylesheet, so the bundler re-runs the
|
|
42
|
-
* stylesheet when it changes.
|
|
43
|
+
* stylesheet when it changes. `warn` reports a problem at `node` without failing the run, as a PostCSS
|
|
44
|
+
* warning on the stylesheet's result. Both are absent when no bundler drives the run.
|
|
43
45
|
*/
|
|
44
46
|
|
|
45
47
|
export {}
|