@wix/site-service-interactions 1.0.34 → 1.0.36
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/cjs/build/implementations/coreInteractions.js +38 -10
- package/cjs/build/implementations/coreInteractions.js.map +1 -1
- package/cjs/build/implementations/v2/BundledInteractions.d.ts +8 -0
- package/cjs/build/implementations/v2/BundledInteractions.js +69 -0
- package/cjs/build/implementations/v2/BundledInteractions.js.map +1 -0
- package/cjs/build/implementations/v2/ConfigStyleSheet.d.ts +17 -0
- package/cjs/build/implementations/v2/{ClickTriggerStyleSheet.js → ConfigStyleSheet.js} +8 -7
- package/cjs/build/implementations/v2/ConfigStyleSheet.js.map +1 -0
- package/cjs/build/implementations/v2/InteractionsScriptElement.d.ts +1 -1
- package/cjs/build/implementations/v2/InteractionsScriptElement.js +3 -3
- package/cjs/build/implementations/v2/InteractionsScriptElement.js.map +1 -1
- package/cjs/build/implementations/v2/backgroundScrollCss.d.ts +2 -0
- package/cjs/build/implementations/v2/backgroundScrollCss.js +169 -0
- package/cjs/build/implementations/v2/backgroundScrollCss.js.map +1 -0
- package/cjs/build/implementations/v2/configCss.d.ts +2 -0
- package/cjs/build/implementations/v2/configCss.js +11 -6
- package/cjs/build/implementations/v2/configCss.js.map +1 -1
- package/dist/implementations/coreInteractions.js +39 -11
- package/dist/implementations/coreInteractions.js.map +1 -1
- package/dist/implementations/v2/BundledInteractions.d.ts +8 -0
- package/dist/implementations/v2/BundledInteractions.js +32 -0
- package/dist/implementations/v2/BundledInteractions.js.map +1 -0
- package/dist/implementations/v2/ConfigStyleSheet.d.ts +17 -0
- package/dist/implementations/v2/{ClickTriggerStyleSheet.js → ConfigStyleSheet.js} +6 -5
- package/dist/implementations/v2/ConfigStyleSheet.js.map +1 -0
- package/dist/implementations/v2/InteractionsScriptElement.d.ts +1 -1
- package/dist/implementations/v2/InteractionsScriptElement.js +3 -3
- package/dist/implementations/v2/InteractionsScriptElement.js.map +1 -1
- package/dist/implementations/v2/backgroundScrollCss.d.ts +2 -0
- package/dist/implementations/v2/backgroundScrollCss.js +165 -0
- package/dist/implementations/v2/backgroundScrollCss.js.map +1 -0
- package/dist/implementations/v2/configCss.d.ts +2 -0
- package/dist/implementations/v2/configCss.js +8 -3
- package/dist/implementations/v2/configCss.js.map +1 -1
- package/package.json +2 -2
- package/src/implementations/coreInteractions.ts +48 -11
- package/src/implementations/v2/BundledInteractions.tsx +36 -0
- package/src/implementations/v2/{ClickTriggerStyleSheet.tsx → ConfigStyleSheet.tsx} +5 -4
- package/src/implementations/v2/InteractionsScriptElement.tsx +3 -3
- package/src/implementations/v2/backgroundScrollCss.ts +208 -0
- package/src/implementations/v2/configCss.ts +9 -3
- package/cjs/build/implementations/v2/ClickTriggerStyleSheet.d.ts +0 -16
- package/cjs/build/implementations/v2/ClickTriggerStyleSheet.js.map +0 -1
- package/dist/implementations/v2/ClickTriggerStyleSheet.d.ts +0 -16
- package/dist/implementations/v2/ClickTriggerStyleSheet.js.map +0 -1
|
@@ -11,14 +11,18 @@ import { HeadContentType } from '@wix/site-service-head-appender/types';
|
|
|
11
11
|
import { ProvideComponentServiceDefinition } from '@wix/services-manager-react/core-services/provide-component';
|
|
12
12
|
import { createInteractionsScriptElement } from './InteractionsScriptElement';
|
|
13
13
|
import { createV2InteractionsScriptElement } from './v2/InteractionsScriptElement';
|
|
14
|
+
import { createBundledV2Interactions } from './v2/BundledInteractions';
|
|
14
15
|
import { getV2ConfigCss } from './v2/configCss';
|
|
15
16
|
import { getV2ConfigStyleHeadContent } from './v2/configStyleHeadContent';
|
|
16
17
|
import { getClickTriggerCss } from './v2/clickTriggerCss';
|
|
18
|
+
import { getBackgroundScrollCss } from './v2/backgroundScrollCss';
|
|
17
19
|
import { getV2ModulePreloadHeadContent } from './v2/interactionsScriptContent';
|
|
18
20
|
import { getAuthoredStylesCss } from './v2/authoredStyles';
|
|
19
|
-
import { getInteractConfigEntries, getInteractiveKeys, getResolvedConfigEntries, resolveInteractKeyConflicts, } from './configEntries';
|
|
21
|
+
import { getInteractConfigEntries, getInteractiveKeys, getResolvedConfigEntries, REACTIONS_NAMESPACE, resolveInteractKeyConflicts, } from './configEntries';
|
|
20
22
|
/** An entry without interactions contributes CSS only; nothing has to load Interact for it. */
|
|
21
23
|
const getRuntimeConfigs = (entries) => entries.map(({ interact }) => interact).filter(({ interactions }) => interactions.length > 0);
|
|
24
|
+
/** Only the reactions entry plays background scroll presets; experiences don't support them yet. */
|
|
25
|
+
const getBackgroundCss = ({ namespace, interact }) => namespace === REACTIONS_NAMESPACE ? getBackgroundScrollCss(interact) : '';
|
|
22
26
|
const initInteract = (entries, isReducedMotion) => {
|
|
23
27
|
const runtimeConfigs = getRuntimeConfigs(entries);
|
|
24
28
|
// v1 registers its interact-element on create, and a tag can only be defined once: starting it for
|
|
@@ -39,12 +43,16 @@ const initInteract = (entries, isReducedMotion) => {
|
|
|
39
43
|
Interact.create(config);
|
|
40
44
|
}
|
|
41
45
|
};
|
|
42
|
-
const
|
|
46
|
+
const getV2Css = (entries) => {
|
|
43
47
|
const generatedCss = entries
|
|
44
|
-
.
|
|
48
|
+
.flatMap((entry) => [getV2ConfigCss(entry.interact), getBackgroundCss(entry)])
|
|
49
|
+
.map((css) => css.trim())
|
|
45
50
|
.filter(Boolean)
|
|
46
51
|
.join('\n');
|
|
47
|
-
|
|
52
|
+
return [getAuthoredStylesCss(entries).trim(), generatedCss].filter(Boolean).join('\n');
|
|
53
|
+
};
|
|
54
|
+
const getV2HeadContent = (entries) => {
|
|
55
|
+
const css = getV2Css(entries);
|
|
48
56
|
return ((getRuntimeConfigs(entries).length ? getV2ModulePreloadHeadContent() : '') +
|
|
49
57
|
(css ? getV2ConfigStyleHeadContent(css) : ''));
|
|
50
58
|
};
|
|
@@ -67,8 +75,20 @@ const initRuntime = (entries, isReducedMotion, getService, useV2) => {
|
|
|
67
75
|
addTopComponent(createInteractionsScriptElement(runtimeConfigs[0], isReducedMotion, pageId));
|
|
68
76
|
return;
|
|
69
77
|
}
|
|
70
|
-
|
|
71
|
-
|
|
78
|
+
// The server sends these with the generated CSS; the client adopts whatever it did not send.
|
|
79
|
+
const configCss = entries
|
|
80
|
+
.flatMap((entry) => [getClickTriggerCss(entry.interact), getBackgroundCss(entry)])
|
|
81
|
+
.map((css) => css.trim())
|
|
82
|
+
.filter(Boolean);
|
|
83
|
+
addTopComponent(createV2InteractionsScriptElement(runtimeConfigs, isReducedMotion, pageId, configCss));
|
|
84
|
+
};
|
|
85
|
+
/** In place of `initRuntime`'s loader, on the same pages: the bundled runtime, with the server's head CSS rendered with the page. */
|
|
86
|
+
const initBundledRuntime = (entries, isReducedMotion, getService) => {
|
|
87
|
+
const runtimeConfigs = getRuntimeConfigs(entries);
|
|
88
|
+
if (!runtimeConfigs.length || !getService(PagesDefinition).currentPageId()) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
getService(ProvideComponentServiceDefinition).addTopComponent(createBundledV2Interactions(runtimeConfigs, isReducedMotion, getV2Css(entries)));
|
|
72
92
|
};
|
|
73
93
|
const getInteractiveComps = (entries) => {
|
|
74
94
|
const keys = new Set();
|
|
@@ -85,10 +105,15 @@ export const coreInteractions = ({ version, ...config }, getService) => {
|
|
|
85
105
|
// aliasing on those paths so named reaction effects remain resolvable.
|
|
86
106
|
const entries = resolveInteractKeyConflicts((useV2 ? getResolvedConfigEntries : getInteractConfigEntries)(config));
|
|
87
107
|
if (useV2) {
|
|
88
|
-
//
|
|
89
|
-
//
|
|
90
|
-
|
|
91
|
-
|
|
108
|
+
// The editor renders pages only in the browser, so it gets no server head: it renders that CSS with the page and
|
|
109
|
+
// runs the runtime it bundles, rather than a loader that imports it from the CDN after the page has painted
|
|
110
|
+
if (process.env.PACKAGE_NAME === 'thunderbolt-ds') {
|
|
111
|
+
initBundledRuntime(entries, isReducedMotion, getService);
|
|
112
|
+
}
|
|
113
|
+
else if (!process.env.browser) {
|
|
114
|
+
// Both belong in the head: the preload links only help while the document is still parsing,
|
|
115
|
+
// and the generated CSS hides elements before their entrance effect, so it has to apply
|
|
116
|
+
// before the body renders.
|
|
92
117
|
const headContent = getV2HeadContent(entries);
|
|
93
118
|
// GENERAL rather than setHead's AFTER_SECURITY default: thunderbolt only reads the
|
|
94
119
|
// after-security bucket on its SEO path, so the default drops this on every normal
|
|
@@ -96,8 +121,11 @@ export const coreInteractions = ({ version, ...config }, getService) => {
|
|
|
96
121
|
if (headContent) {
|
|
97
122
|
getService(HeadAppenderDefinition).setHead(headContent, HeadContentType.GENERAL);
|
|
98
123
|
}
|
|
124
|
+
initRuntime(entries, isReducedMotion, getService, true);
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
initRuntime(entries, isReducedMotion, getService, true);
|
|
99
128
|
}
|
|
100
|
-
initRuntime(entries, isReducedMotion, getService, true);
|
|
101
129
|
}
|
|
102
130
|
else if (isOpen('specs.thunderbolt.interactionsInSsr')) {
|
|
103
131
|
// Emits the config and loader scripts. Works in both environments: SSR serves markup the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coreInteractions.js","sourceRoot":"","sources":["../../src/implementations/coreInteractions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAE3C,OAAO,EAAE,oBAAoB,EAAE,MAAM,0CAA0C,CAAA;AAC/E,OAAO,EAAE,qBAAqB,EAAE,MAAM,0CAA0C,CAAA;AAChF,+FAA+F;AAC/F,+FAA+F;AAC/F,+FAA+F;AAC/F,kFAAkF;AAClF,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAA;AACtE,OAAO,EAAE,sBAAsB,EAAE,MAAM,4CAA4C,CAAA;AACnF,OAAO,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAA;AACvE,OAAO,EAAE,iCAAiC,EAAE,MAAM,6DAA6D,CAAA;AAG/G,OAAO,EAAE,+BAA+B,EAAE,MAAM,6BAA6B,CAAA;AAC7E,OAAO,EAAE,i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E,UAAU,EAAE,IAAI,CAAC,CAAA;QACxD,CAAC;aAAM,CAAC;YACP,WAAW,CAAC,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,IAAI,CAAC,CAAA;QACxD,CAAC;IACF,CAAC;SAAM,IAAI,MAAM,CAAC,qCAAqC,CAAC,EAAE,CAAC;QAC1D,yFAAyF;QACzF,2FAA2F;QAC3F,sFAAsF;QACtF,iFAAiF;QACjF,WAAW,CAAC,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,KAAK,CAAC,CAAA;IACzD,CAAC;SAAM,CAAC;QACP,YAAY,CAAC,OAAO,EAAE,eAAe,CAAC,CAAA;IACvC,CAAC;IAED,OAAO;QACN,gBAAgB,EAAE,mBAAmB,CAAC,OAAO,CAAC;KAC9C,CAAA;AACF,CAAC,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { FunctionComponent } from 'react';
|
|
2
|
+
import type { InteractConfig } from '../../definition';
|
|
3
|
+
/**
|
|
4
|
+
* The page's interactions with the bundled runtime, for the editor, which renders pages only in the browser: the CSS
|
|
5
|
+
* the server would send in the head renders with the page, so its first paint already animates, and the instances are
|
|
6
|
+
* the page's own.
|
|
7
|
+
*/
|
|
8
|
+
export declare const createBundledV2Interactions: (configs: InteractConfig[], isReducedMotion: boolean, css: string) => FunctionComponent;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import React, { useEffect } from 'react';
|
|
2
|
+
import { Interact } from './configCss';
|
|
3
|
+
/**
|
|
4
|
+
* The page's interactions with the bundled runtime, for the editor, which renders pages only in the browser: the CSS
|
|
5
|
+
* the server would send in the head renders with the page, so its first paint already animates, and the instances are
|
|
6
|
+
* the page's own.
|
|
7
|
+
*/
|
|
8
|
+
export const createBundledV2Interactions = (configs, isReducedMotion, css) => () => {
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
Interact.forceReducedMotion = isReducedMotion;
|
|
11
|
+
Interact.setup({
|
|
12
|
+
scrollOptionsGetter: () => document.getElementById('site-root'),
|
|
13
|
+
allowA11yTriggers: true,
|
|
14
|
+
viewEnter: {
|
|
15
|
+
useSafeViewEnter: true,
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
// The editor's config can be mid-edit: a config that fails is skipped rather than taking the page down with it
|
|
19
|
+
const instances = configs.flatMap((config) => {
|
|
20
|
+
try {
|
|
21
|
+
return [Interact.create(config)];
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
console.error('Failed running an interactions config', error);
|
|
25
|
+
return [];
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
return () => instances.forEach((instance) => instance.destroy());
|
|
29
|
+
}, []);
|
|
30
|
+
return React.createElement("style", null, css);
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=BundledInteractions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BundledInteractions.js","sourceRoot":"","sources":["../../../src/implementations/v2/BundledInteractions.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAGxC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAEtC;;;;GAIG;AACH,MAAM,CAAC,MAAM,2BAA2B,GACvC,CAAC,OAAyB,EAAE,eAAwB,EAAE,GAAW,EAAqB,EAAE,CACxF,GAAG,EAAE;IACJ,SAAS,CAAC,GAAG,EAAE;QACd,QAAQ,CAAC,kBAAkB,GAAG,eAAe,CAAA;QAC7C,QAAQ,CAAC,KAAK,CAAC;YACd,mBAAmB,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,cAAc,CAAC,WAAW,CAAC;YAC/D,iBAAiB,EAAE,IAAI;YACvB,SAAS,EAAE;gBACV,gBAAgB,EAAE,IAAI;aACtB;SACD,CAAC,CAAA;QACF,+GAA+G;QAC/G,MAAM,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;YAC5C,IAAI,CAAC;gBACJ,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAA;YACjC,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBAChB,OAAO,CAAC,KAAK,CAAC,uCAAuC,EAAE,KAAK,CAAC,CAAA;gBAC7D,OAAO,EAAE,CAAA;YACV,CAAC;QACF,CAAC,CAAC,CAAA;QACF,OAAO,GAAG,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAA;IACjE,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,OAAO,mCAAQ,GAAG,CAAS,CAAA;AAC5B,CAAC,CAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { FunctionComponent } from 'react';
|
|
2
|
+
type StyleSheetDocument = Pick<Document, 'adoptedStyleSheets' | 'querySelectorAll'>;
|
|
3
|
+
/**
|
|
4
|
+
* Adopts the rules the server did not already send as a constructable stylesheet, and returns a
|
|
5
|
+
* function that removes that sheet again.
|
|
6
|
+
*/
|
|
7
|
+
export declare const adoptMissingStyleSheet: (rules: Array<string>, document?: StyleSheetDocument | undefined) => () => void;
|
|
8
|
+
/**
|
|
9
|
+
* The server sends the rules it derives from the config (click-trigger cursors, background scroll
|
|
10
|
+
* sizing) in the head only for what it rendered, so content rendered on the client (client-side
|
|
11
|
+
* navigation, password-protected / members-only pages, a host that renders only on the client) never
|
|
12
|
+
* gets them. Adopt the missing ones while the page is mounted and remove them when navigating away.
|
|
13
|
+
*/
|
|
14
|
+
export declare const ConfigStyleSheet: FunctionComponent<{
|
|
15
|
+
rules: Array<string>;
|
|
16
|
+
}>;
|
|
17
|
+
export {};
|
|
@@ -24,12 +24,13 @@ export const adoptMissingStyleSheet = (rules, document = globalThis.document) =>
|
|
|
24
24
|
};
|
|
25
25
|
};
|
|
26
26
|
/**
|
|
27
|
-
* The server sends the
|
|
28
|
-
*
|
|
29
|
-
*
|
|
27
|
+
* The server sends the rules it derives from the config (click-trigger cursors, background scroll
|
|
28
|
+
* sizing) in the head only for what it rendered, so content rendered on the client (client-side
|
|
29
|
+
* navigation, password-protected / members-only pages, a host that renders only on the client) never
|
|
30
|
+
* gets them. Adopt the missing ones while the page is mounted and remove them when navigating away.
|
|
30
31
|
*/
|
|
31
|
-
export const
|
|
32
|
+
export const ConfigStyleSheet = ({ rules }) => {
|
|
32
33
|
useEffect(() => adoptMissingStyleSheet(rules), [rules]);
|
|
33
34
|
return null;
|
|
34
35
|
};
|
|
35
|
-
//# sourceMappingURL=
|
|
36
|
+
//# sourceMappingURL=ConfigStyleSheet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConfigStyleSheet.js","sourceRoot":"","sources":["../../../src/implementations/v2/ConfigStyleSheet.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAEjC,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAI9D,MAAM,oBAAoB,GAAG,CAAC,QAA4B,EAAU,EAAE,CACrE,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,gBAAgB,CAAC,SAAS,mBAAmB,GAAG,CAAC,CAAC;KACpE,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,WAAW,IAAI,EAAE,CAAC;KACvC,IAAI,CAAC,IAAI,CAAC,CAAA;AAEb;;;GAGG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CACrC,KAAoB,EACpB,QAAQ,GAAmC,UAAU,CAAC,QAAQ,EAC7D,EAAE;IACH,IAAI,CAAC,QAAQ,EAAE,kBAAkB,EAAE,CAAC;QACnC,OAAO,GAAG,EAAE,GAAE,CAAC,CAAA;IAChB,CAAC;IAED,MAAM,iBAAiB,GAAG,oBAAoB,CAAC,QAAQ,CAAC,CAAA;IACxD,MAAM,GAAG,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,iBAAiB,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAChF,IAAI,CAAC,GAAG,EAAE,CAAC;QACV,OAAO,GAAG,EAAE,GAAE,CAAC,CAAA;IAChB,CAAC;IAED,MAAM,KAAK,GAAG,IAAI,aAAa,EAAE,CAAA;IACjC,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC,CAAA;IACtB,QAAQ,CAAC,kBAAkB,GAAG,CAAC,GAAG,QAAQ,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAA;IAErE,OAAO,GAAG,EAAE;QACX,QAAQ,CAAC,kBAAkB,GAAG,QAAQ,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,KAAK,KAAK,CAAC,CAAA;IACjG,CAAC,CAAA;AACF,CAAC,CAAA;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAgD,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE;IAC1F,SAAS,CAAC,GAAG,EAAE,CAAC,sBAAsB,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAA;IAEvD,OAAO,IAAI,CAAA;AACZ,CAAC,CAAA"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { FunctionComponent } from 'react';
|
|
2
2
|
import type { InteractConfig } from '@wix/interact';
|
|
3
|
-
export declare const createV2InteractionsScriptElement: (config: InteractConfig | InteractConfig[], isReducedMotion: boolean, pageId: string,
|
|
3
|
+
export declare const createV2InteractionsScriptElement: (config: InteractConfig | InteractConfig[], isReducedMotion: boolean, pageId: string, configCss?: Array<string>) => FunctionComponent;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { reviveScriptElement } from '../reviveScriptElement';
|
|
3
|
-
import {
|
|
3
|
+
import { ConfigStyleSheet } from './ConfigStyleSheet';
|
|
4
4
|
import { getV2InteractionsScriptContent } from './interactionsScriptContent';
|
|
5
5
|
const DANGEROUSLY_SET_INNER_HTML = ['dangerously', 'Set', 'Inner', 'HTML'];
|
|
6
6
|
/**
|
|
@@ -8,7 +8,7 @@ const DANGEROUSLY_SET_INNER_HTML = ['dangerously', 'Set', 'Inner', 'HTML'];
|
|
|
8
8
|
* element early. `\u003c` is valid JSON that `JSON.parse` reads back as `<`.
|
|
9
9
|
*/
|
|
10
10
|
const serializeConfigForScriptElement = (config) => JSON.stringify(config).replace(/</g, '\\u003c');
|
|
11
|
-
export const createV2InteractionsScriptElement = (config, isReducedMotion, pageId,
|
|
11
|
+
export const createV2InteractionsScriptElement = (config, isReducedMotion, pageId, configCss = []) => () => {
|
|
12
12
|
// This ID is also interpolated into raw module-script text. Percent-encoding removes
|
|
13
13
|
// script delimiters and template-literal syntax while keeping the ID deterministic.
|
|
14
14
|
const safePageId = encodeURIComponent(pageId);
|
|
@@ -23,6 +23,6 @@ export const createV2InteractionsScriptElement = (config, isReducedMotion, pageI
|
|
|
23
23
|
return (React.createElement(React.Fragment, null,
|
|
24
24
|
React.createElement("script", { type: "application/json", id: configId, ...configProps }),
|
|
25
25
|
React.createElement("script", { type: "module", id: `interactions-loader-${safePageId}`, ref: reviveScriptElement, ...loaderProps }),
|
|
26
|
-
|
|
26
|
+
configCss.length > 0 && React.createElement(ConfigStyleSheet, { rules: configCss })));
|
|
27
27
|
};
|
|
28
28
|
//# sourceMappingURL=InteractionsScriptElement.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InteractionsScriptElement.js","sourceRoot":"","sources":["../../../src/implementations/v2/InteractionsScriptElement.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAA;AAC5D,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"InteractionsScriptElement.js","source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,IAAI,EAAC,QAAQ,EAAC,EAAE,EAAE,uBAAuB,UAAU,EAAE,EAAE,GAAG,EAAE,mBAAmB,KAAM,WAAW,GAAI;QAC3G,SAAS,CAAC,MAAM,GAAG,CAAC,IAAI,oBAAC,gBAAgB,IAAC,KAAK,EAAE,SAAS,GAAI,CAC7D,CACH,CAAA;AACF,CAAC,CAAA"}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { LEGACY_PREFIX } from './motionPresets';
|
|
2
|
+
const BG_SKEW_ANGLE = 20;
|
|
3
|
+
const BG_ROTATE_ANGLE = 22;
|
|
4
|
+
const BG_PAN_SPEED = 0.2;
|
|
5
|
+
const IMAGE_PARALLAX_SPEED = 1.5;
|
|
6
|
+
// Mimics `position: fixed` with sticky positioning, which keeps working inside a transform or an overflow.
|
|
7
|
+
const FIXED_MEDIA_STYLE = {
|
|
8
|
+
'will-change': 'var(--motion-bgreveal-will-change)',
|
|
9
|
+
height: 'calc(100% + 200lvh)',
|
|
10
|
+
'margin-top': '-100lvh',
|
|
11
|
+
overflow: 'clip',
|
|
12
|
+
// a media rendered as a background image needs its own stacking context in some browsers
|
|
13
|
+
isolation: 'isolate',
|
|
14
|
+
};
|
|
15
|
+
const FIXED_IMG_STYLE = {
|
|
16
|
+
position: 'sticky',
|
|
17
|
+
height: 'max(100lvh, calc(100% - 200lvh))',
|
|
18
|
+
width: '100%',
|
|
19
|
+
top: '0px',
|
|
20
|
+
'margin-bottom': 'calc(100lvh - max(100lvh, var(--motion-comp-height, 100%)))',
|
|
21
|
+
display: 'block',
|
|
22
|
+
padding: '0px',
|
|
23
|
+
};
|
|
24
|
+
const FILL_STYLE = { height: '100%', width: '100%', position: 'absolute' };
|
|
25
|
+
// Firefox breaks the sticky imitation without it, https://bugzilla.mozilla.org/show_bug.cgi?id=1791232. It only
|
|
26
|
+
// defines the variable the fixed media style reads, so it is always rendered.
|
|
27
|
+
const FIREFOX_CSS = '@supports (-moz-appearance: none) {\nbody {\n--motion-bgreveal-will-change: transform;\n}\n}';
|
|
28
|
+
const toRadians = (degrees) => (degrees * Math.PI) / 180;
|
|
29
|
+
const numberParam = (namedEffect, name, fallback) => typeof namedEffect[name] === 'number' && namedEffect[name] ? namedEffect[name] : fallback;
|
|
30
|
+
const isFixedStyle = (namedEffect) => (namedEffect.type === 'BgZoom' && namedEffect.direction === 'in') ||
|
|
31
|
+
['BgReveal', 'BgParallax', 'BgFake3D'].includes(namedEffect.type);
|
|
32
|
+
const MEDIA_STYLES = {
|
|
33
|
+
BgParallax: () => FIXED_MEDIA_STYLE,
|
|
34
|
+
BgReveal: () => FIXED_MEDIA_STYLE,
|
|
35
|
+
BgFake3D: () => FIXED_MEDIA_STYLE,
|
|
36
|
+
BgSkew: (namedEffect) => {
|
|
37
|
+
const tan = Math.tan(toRadians(numberParam(namedEffect, 'angle', BG_SKEW_ANGLE)));
|
|
38
|
+
return { 'padding-bottom': `${(100 * tan).toFixed(3)}%`, 'margin-top': `${(-50 * tan).toFixed(3)}%` };
|
|
39
|
+
},
|
|
40
|
+
BgRotate: (namedEffect) => {
|
|
41
|
+
const angle = toRadians(numberParam(namedEffect, 'angle', BG_ROTATE_ANGLE));
|
|
42
|
+
const cos = (100 * Math.cos(angle)).toFixed(3);
|
|
43
|
+
const sin = (100 * Math.sin(angle)).toFixed(3);
|
|
44
|
+
return {
|
|
45
|
+
width: `max(100%, calc(${cos}cqw + ${sin}cqh))`,
|
|
46
|
+
height: `max(100%, calc(${sin}cqw + ${cos}cqh))`,
|
|
47
|
+
translate: 'calc(50cqw - 50%) calc(50cqh - 50%)',
|
|
48
|
+
};
|
|
49
|
+
},
|
|
50
|
+
BgPan: (namedEffect) => {
|
|
51
|
+
const speed = numberParam(namedEffect, 'speed', BG_PAN_SPEED);
|
|
52
|
+
return { position: 'relative', width: `${100 * (1 + speed)}%`, left: `-${50 * speed}%` };
|
|
53
|
+
},
|
|
54
|
+
BgZoom: (namedEffect) => isFixedStyle(namedEffect)
|
|
55
|
+
? FIXED_MEDIA_STYLE
|
|
56
|
+
: { position: 'relative', width: '115%', height: '115%', left: '-7.5%', top: '-7.5%' },
|
|
57
|
+
ImageParallax: (namedEffect) => ({
|
|
58
|
+
height: `${100 * numberParam(namedEffect, 'speed', IMAGE_PARALLAX_SPEED)}%`,
|
|
59
|
+
position: 'relative',
|
|
60
|
+
}),
|
|
61
|
+
};
|
|
62
|
+
const IMG_STYLES = {
|
|
63
|
+
BgParallax: () => FIXED_IMG_STYLE,
|
|
64
|
+
BgReveal: () => FIXED_IMG_STYLE,
|
|
65
|
+
BgFake3D: () => FIXED_IMG_STYLE,
|
|
66
|
+
BgZoom: (namedEffect) => (isFixedStyle(namedEffect) ? FIXED_IMG_STYLE : {}),
|
|
67
|
+
BgSkew: () => FILL_STYLE,
|
|
68
|
+
ImageParallax: () => FILL_STYLE,
|
|
69
|
+
};
|
|
70
|
+
const BACKGROUND_SCROLL_EFFECTS = new Set([
|
|
71
|
+
'BgCloseUp',
|
|
72
|
+
'BgFade',
|
|
73
|
+
'BgFadeBack',
|
|
74
|
+
'BgPullBack',
|
|
75
|
+
...Object.keys(MEDIA_STYLES),
|
|
76
|
+
...Object.keys(IMG_STYLES),
|
|
77
|
+
]);
|
|
78
|
+
const escapeCssAttr = (value) => value.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
|
|
79
|
+
const rule = (selector, style) => `${selector} {\n${Object.entries(style)
|
|
80
|
+
.map(([property, value]) => `${property}: ${value};`)
|
|
81
|
+
.join('\n')}\n}`;
|
|
82
|
+
/**
|
|
83
|
+
* Keys are comp paths, so the last segment is the comp id. A part carries `<PART> <comp id>`, and a repeated
|
|
84
|
+
* comp's id carries its item, `<comp id>__<item>`, on the root and on its parts alike.
|
|
85
|
+
*/
|
|
86
|
+
const getSelectors = (key, selectorConditions) => {
|
|
87
|
+
const compId = escapeCssAttr(key.slice(key.lastIndexOf('/') + 1));
|
|
88
|
+
const root = `:is([id="${compId}"], [id^="${compId}__"])${selectorConditions}`;
|
|
89
|
+
const part = (name) => `:is([data-motion-part="${name} ${compId}"], [data-motion-part^="${name} ${compId}__"])`;
|
|
90
|
+
// Every part is matched under the root, as Thunderbolt does, so a root that is itself the layer is not matched.
|
|
91
|
+
return {
|
|
92
|
+
layer: `${root} ${part('BG_LAYER')}`,
|
|
93
|
+
media: `${root} ${part('BG_MEDIA')}`,
|
|
94
|
+
image: `${root}:not([data-show-canvas]) ${part('BG_IMG')}, ${root}[data-has-alpha="true"] canvas`,
|
|
95
|
+
imageXMedia: `${root}[data-testid="imageX"] ${part('BG_MEDIA')}`,
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
const getEffectRules = (namedEffect, key, selectorConditions) => {
|
|
99
|
+
const selectors = getSelectors(key, selectorConditions);
|
|
100
|
+
const mediaStyle = MEDIA_STYLES[namedEffect.type]?.(namedEffect);
|
|
101
|
+
const imgStyle = IMG_STYLES[namedEffect.type]?.(namedEffect);
|
|
102
|
+
const isRotate = namedEffect.type === 'BgRotate';
|
|
103
|
+
const rules = [
|
|
104
|
+
...(mediaStyle ? [rule(selectors.media, mediaStyle)] : []),
|
|
105
|
+
...(imgStyle && Object.keys(imgStyle).length ? [rule(selectors.image, imgStyle)] : []),
|
|
106
|
+
rule(selectors.layer, { overflow: 'clip', contain: 'layout', ...(isRotate && { 'container-type': 'size' }) }),
|
|
107
|
+
];
|
|
108
|
+
if (isRotate) {
|
|
109
|
+
const angle = toRadians(numberParam(namedEffect, 'angle', BG_ROTATE_ANGLE));
|
|
110
|
+
const grow = (100 * (Math.sqrt(1 + Math.tan(angle) ** 2) - 1)).toFixed(3);
|
|
111
|
+
const sin = (100 * Math.sin(angle)).toFixed(3);
|
|
112
|
+
rules.push(`@container (min-aspect-ratio: ${Math.tan(Math.PI / 2 - angle).toFixed(3)}) {\n${rule(selectors.media, {
|
|
113
|
+
width: `calc(100% + min(${grow}%, ${sin}cqh))`,
|
|
114
|
+
})}\n}`, `@container (max-aspect-ratio: ${Math.tan(angle).toFixed(3)}) {\n${rule(selectors.media, {
|
|
115
|
+
height: `calc(100% + min(${grow}%, ${sin}cqw))`,
|
|
116
|
+
})}\n}`);
|
|
117
|
+
}
|
|
118
|
+
else if (isFixedStyle(namedEffect)) {
|
|
119
|
+
// Safari has a bug like Firefox's for an ImageX media; a transform solves it
|
|
120
|
+
rules.push(rule(selectors.imageXMedia, { transform: 'translate3d(0,0,0)' }));
|
|
121
|
+
}
|
|
122
|
+
return rules;
|
|
123
|
+
};
|
|
124
|
+
const getConditions = (interact, conditionIds) => {
|
|
125
|
+
const conditions = [...new Set(conditionIds)]
|
|
126
|
+
.map((id) => interact.conditions?.[id])
|
|
127
|
+
.filter((condition) => Boolean(condition?.predicate));
|
|
128
|
+
const predicatesOf = (type) => conditions.filter((condition) => condition.type === type).map(({ predicate }) => predicate);
|
|
129
|
+
const media = predicatesOf('media');
|
|
130
|
+
return {
|
|
131
|
+
media: media.length ? `(${media.join(') and (')})` : '',
|
|
132
|
+
selector: predicatesOf('selector')
|
|
133
|
+
.map((predicate) => `:is(${predicate})`)
|
|
134
|
+
.join(''),
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
const toMediaBlock = ([media, rules]) => media ? `@media ${media} {\n${[...rules].join('\n')}\n}` : [...rules].join('\n');
|
|
138
|
+
export const getBackgroundScrollCss = (interact) => {
|
|
139
|
+
const rulesByMedia = new Map();
|
|
140
|
+
for (const interaction of interact.interactions) {
|
|
141
|
+
// sequences don't play scrub animations, so a background scroll preset is only ever an interaction's effect
|
|
142
|
+
for (const inlineEffect of interaction.effects ?? []) {
|
|
143
|
+
// an effectId points at interact.effects; the inline fields override it, as interact reads them
|
|
144
|
+
const effect = {
|
|
145
|
+
...(inlineEffect.effectId ? interact.effects?.[inlineEffect.effectId] : undefined),
|
|
146
|
+
...inlineEffect,
|
|
147
|
+
};
|
|
148
|
+
const { namedEffect } = effect;
|
|
149
|
+
const key = effect.key ?? interaction.key;
|
|
150
|
+
const type = namedEffect?.type?.startsWith(LEGACY_PREFIX)
|
|
151
|
+
? namedEffect.type.slice(LEGACY_PREFIX.length)
|
|
152
|
+
: undefined;
|
|
153
|
+
if (!namedEffect || !type || !BACKGROUND_SCROLL_EFFECTS.has(type) || !key) {
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
const params = { ...namedEffect, type };
|
|
157
|
+
const conditions = getConditions(interact, [...(interaction.conditions ?? []), ...(effect.conditions ?? [])]);
|
|
158
|
+
const rules = rulesByMedia.get(conditions.media) ?? new Set();
|
|
159
|
+
getEffectRules(params, key, conditions.selector).forEach((css) => rules.add(css));
|
|
160
|
+
rulesByMedia.set(conditions.media, rules);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return `@media (prefers-reduced-motion: no-preference) {\n${[...[...rulesByMedia].map(toMediaBlock), FIREFOX_CSS].join('\n')}\n}`;
|
|
164
|
+
};
|
|
165
|
+
//# sourceMappingURL=backgroundScrollCss.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backgroundScrollCss.js","sourceRoot":"","sources":["../../../src/implementations/v2/backgroundScrollCss.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAa/C,MAAM,aAAa,GAAG,EAAE,CAAA;AACxB,MAAM,eAAe,GAAG,EAAE,CAAA;AAC1B,MAAM,YAAY,GAAG,GAAG,CAAA;AACxB,MAAM,oBAAoB,GAAG,GAAG,CAAA;AAEhC,2GAA2G;AAC3G,MAAM,iBAAiB,GAAU;IAChC,aAAa,EAAE,oCAAoC;IACnD,MAAM,EAAE,qBAAqB;IAC7B,YAAY,EAAE,SAAS;IACvB,QAAQ,EAAE,MAAM;IAChB,yFAAyF;IACzF,SAAS,EAAE,SAAS;CACpB,CAAA;AAED,MAAM,eAAe,GAAU;IAC9B,QAAQ,EAAE,QAAQ;IAClB,MAAM,EAAE,kCAAkC;IAC1C,KAAK,EAAE,MAAM;IACb,GAAG,EAAE,KAAK;IACV,eAAe,EA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G,EAAE,GAAG,WAAW,EAAE,IAAI,EAAE,CAAA;YACvC,MAAM,UAAU,GAAG,aAAa,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,WAAW,CAAC,UAAU,IAAI,EAAE,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC,CAAC,CAAA;YAC7G,MAAM,KAAK,GAAG,YAAY,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,IAAI,GAAG,EAAU,CAAA;YACrE,cAAc,CAAC,MAAM,EAAE,GAAG,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAA;YACjF,YAAY,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;QAC1C,CAAC;IACF,CAAC;IAED,OAAO,qDAAqD,CAAC,GAAG,CAAC,GAAG,YAAY,CAAC,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,WAAW,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAA;AAClI,CAAC,CAAA"}
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import * as allLegacyPresets from '@wix/wix-motion-presets';
|
|
2
2
|
import * as allPresets from '@wix/motion-presets';
|
|
3
|
-
|
|
3
|
+
// Through the namespace: web.js only re-exports the core and installs `Interact.defineInteractElement`, which
|
|
4
|
+
// `Interact.create` needs to run on `<interact-element>`. With named imports, a bundler that trusts the package's
|
|
5
|
+
// `sideEffects: false` links them past web.js to the core and drops it.
|
|
6
|
+
import * as interactWeb from '@wix/interact/web';
|
|
4
7
|
import { getClickTriggerCss } from './clickTriggerCss';
|
|
5
8
|
import { LEGACY_PREFIX } from './motionPresets';
|
|
9
|
+
const { generate } = interactWeb;
|
|
10
|
+
export const { Interact } = interactWeb;
|
|
6
11
|
const isEffectModule = (value) => typeof value === 'object' && value !== null && 'web' in value && 'getNames' in value;
|
|
7
12
|
const getPresetModules = (namespace, prefix = '') => Object.fromEntries(Object.entries(namespace)
|
|
8
13
|
.filter(([, value]) => isEffectModule(value))
|
|
@@ -15,8 +20,8 @@ export const motionPresets = {
|
|
|
15
20
|
...getPresetModules(allPresets),
|
|
16
21
|
...getPresetModules(allLegacyPresets, LEGACY_PREFIX),
|
|
17
22
|
};
|
|
18
|
-
// Interact's registry is process-global.
|
|
19
|
-
//
|
|
23
|
+
// Interact's registry is process-global. Only the server's bundle and the editor's pull this module in (`process.env`
|
|
24
|
+
// DCE), so both namespaces are registered once per Node process or document.
|
|
20
25
|
Interact.registerEffects(motionPresets);
|
|
21
26
|
/** Emit animation FOUC CSS and click-trigger cursor rules. */
|
|
22
27
|
export const getV2ConfigCss = (config) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configCss.js","sourceRoot":"","sources":["../../../src/implementations/v2/configCss.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,gBAAgB,MAAM,yBAAyB,CAAA;AAC3D,OAAO,KAAK,UAAU,MAAM,qBAAqB,CAAA;AACjD,
|
|
1
|
+
{"version":3,"file":"configCss.js","sourceRoot":"","sources":["../../../src/implementations/v2/configCss.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,gBAAgB,MAAM,yBAAyB,CAAA;AAC3D,OAAO,KAAK,UAAU,MAAM,qBAAqB,CAAA;AACjD,8GAA8G;AAC9G,kHAAkH;AAClH,wEAAwE;AACxE,OAAO,KAAK,WAAW,MAAM,mBAAmB,CAAA;AAEhD,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAE/C,MAAM,EAAE,QAAQ,EAAE,GAAG,WAAW,CAAA;AAChC,MAAM,CAAC,MAAM,EAAE,QAAQ,EAAE,GAAG,WAAW,CAAA;AAUvC,MAAM,cAAc,GAAG,CAAC,KA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|
3
|
+
"version": "1.0.36",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -97,5 +97,5 @@
|
|
|
97
97
|
]
|
|
98
98
|
}
|
|
99
99
|
},
|
|
100
|
-
"falconPackageHash": "
|
|
100
|
+
"falconPackageHash": "44bf1ad483f5a1d88eedcc4d152542211de72016d53130d7a1460b2d"
|
|
101
101
|
}
|
|
@@ -14,15 +14,18 @@ import type { ServicesManager } from '@wix/services-manager/types'
|
|
|
14
14
|
import type { InteractConfig, InteractConfigEntry, IInteractionsServiceConfig } from '../definition'
|
|
15
15
|
import { createInteractionsScriptElement } from './InteractionsScriptElement'
|
|
16
16
|
import { createV2InteractionsScriptElement } from './v2/InteractionsScriptElement'
|
|
17
|
+
import { createBundledV2Interactions } from './v2/BundledInteractions'
|
|
17
18
|
import { getV2ConfigCss } from './v2/configCss'
|
|
18
19
|
import { getV2ConfigStyleHeadContent } from './v2/configStyleHeadContent'
|
|
19
20
|
import { getClickTriggerCss } from './v2/clickTriggerCss'
|
|
21
|
+
import { getBackgroundScrollCss } from './v2/backgroundScrollCss'
|
|
20
22
|
import { getV2ModulePreloadHeadContent } from './v2/interactionsScriptContent'
|
|
21
23
|
import { getAuthoredStylesCss } from './v2/authoredStyles'
|
|
22
24
|
import {
|
|
23
25
|
getInteractConfigEntries,
|
|
24
26
|
getInteractiveKeys,
|
|
25
27
|
getResolvedConfigEntries,
|
|
28
|
+
REACTIONS_NAMESPACE,
|
|
26
29
|
resolveInteractKeyConflicts,
|
|
27
30
|
} from './configEntries'
|
|
28
31
|
|
|
@@ -30,6 +33,10 @@ import {
|
|
|
30
33
|
const getRuntimeConfigs = (entries: InteractConfigEntry[]): InteractConfig[] =>
|
|
31
34
|
entries.map(({ interact }) => interact).filter(({ interactions }) => interactions.length > 0)
|
|
32
35
|
|
|
36
|
+
/** Only the reactions entry plays background scroll presets; experiences don't support them yet. */
|
|
37
|
+
const getBackgroundCss = ({ namespace, interact }: InteractConfigEntry): string =>
|
|
38
|
+
namespace === REACTIONS_NAMESPACE ? getBackgroundScrollCss(interact) : ''
|
|
39
|
+
|
|
33
40
|
const initInteract = (entries: InteractConfigEntry[], isReducedMotion: boolean) => {
|
|
34
41
|
const runtimeConfigs = getRuntimeConfigs(entries)
|
|
35
42
|
// v1 registers its interact-element on create, and a tag can only be defined once: starting it for
|
|
@@ -51,12 +58,17 @@ const initInteract = (entries: InteractConfigEntry[], isReducedMotion: boolean)
|
|
|
51
58
|
}
|
|
52
59
|
}
|
|
53
60
|
|
|
54
|
-
const
|
|
61
|
+
const getV2Css = (entries: InteractConfigEntry[]): string => {
|
|
55
62
|
const generatedCss = entries
|
|
56
|
-
.
|
|
63
|
+
.flatMap((entry) => [getV2ConfigCss(entry.interact), getBackgroundCss(entry)])
|
|
64
|
+
.map((css) => css.trim())
|
|
57
65
|
.filter(Boolean)
|
|
58
66
|
.join('\n')
|
|
59
|
-
|
|
67
|
+
return [getAuthoredStylesCss(entries).trim(), generatedCss].filter(Boolean).join('\n')
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const getV2HeadContent = (entries: InteractConfigEntry[]): string => {
|
|
71
|
+
const css = getV2Css(entries)
|
|
60
72
|
|
|
61
73
|
return (
|
|
62
74
|
(getRuntimeConfigs(entries).length ? getV2ModulePreloadHeadContent() : '') +
|
|
@@ -92,8 +104,28 @@ const initRuntime = (
|
|
|
92
104
|
return
|
|
93
105
|
}
|
|
94
106
|
|
|
95
|
-
|
|
96
|
-
|
|
107
|
+
// The server sends these with the generated CSS; the client adopts whatever it did not send.
|
|
108
|
+
const configCss = entries
|
|
109
|
+
.flatMap((entry) => [getClickTriggerCss(entry.interact), getBackgroundCss(entry)])
|
|
110
|
+
.map((css) => css.trim())
|
|
111
|
+
.filter(Boolean)
|
|
112
|
+
addTopComponent(createV2InteractionsScriptElement(runtimeConfigs, isReducedMotion, pageId, configCss))
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** In place of `initRuntime`'s loader, on the same pages: the bundled runtime, with the server's head CSS rendered with the page. */
|
|
116
|
+
const initBundledRuntime = (
|
|
117
|
+
entries: InteractConfigEntry[],
|
|
118
|
+
isReducedMotion: boolean,
|
|
119
|
+
getService: ServicesManager['getService']
|
|
120
|
+
) => {
|
|
121
|
+
const runtimeConfigs = getRuntimeConfigs(entries)
|
|
122
|
+
if (!runtimeConfigs.length || !getService(PagesDefinition).currentPageId()) {
|
|
123
|
+
return
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
getService(ProvideComponentServiceDefinition).addTopComponent(
|
|
127
|
+
createBundledV2Interactions(runtimeConfigs, isReducedMotion, getV2Css(entries))
|
|
128
|
+
)
|
|
97
129
|
}
|
|
98
130
|
|
|
99
131
|
const getInteractiveComps = (entries: InteractConfigEntry[]): Set<string> => {
|
|
@@ -116,10 +148,14 @@ export const coreInteractions = (
|
|
|
116
148
|
const entries = resolveInteractKeyConflicts((useV2 ? getResolvedConfigEntries : getInteractConfigEntries)(config))
|
|
117
149
|
|
|
118
150
|
if (useV2) {
|
|
119
|
-
//
|
|
120
|
-
//
|
|
121
|
-
|
|
122
|
-
|
|
151
|
+
// The editor renders pages only in the browser, so it gets no server head: it renders that CSS with the page and
|
|
152
|
+
// runs the runtime it bundles, rather than a loader that imports it from the CDN after the page has painted
|
|
153
|
+
if (process.env.PACKAGE_NAME === 'thunderbolt-ds') {
|
|
154
|
+
initBundledRuntime(entries, isReducedMotion, getService)
|
|
155
|
+
} else if (!process.env.browser) {
|
|
156
|
+
// Both belong in the head: the preload links only help while the document is still parsing,
|
|
157
|
+
// and the generated CSS hides elements before their entrance effect, so it has to apply
|
|
158
|
+
// before the body renders.
|
|
123
159
|
const headContent = getV2HeadContent(entries)
|
|
124
160
|
// GENERAL rather than setHead's AFTER_SECURITY default: thunderbolt only reads the
|
|
125
161
|
// after-security bucket on its SEO path, so the default drops this on every normal
|
|
@@ -127,9 +163,10 @@ export const coreInteractions = (
|
|
|
127
163
|
if (headContent) {
|
|
128
164
|
getService(HeadAppenderDefinition).setHead(headContent, HeadContentType.GENERAL)
|
|
129
165
|
}
|
|
166
|
+
initRuntime(entries, isReducedMotion, getService, true)
|
|
167
|
+
} else {
|
|
168
|
+
initRuntime(entries, isReducedMotion, getService, true)
|
|
130
169
|
}
|
|
131
|
-
|
|
132
|
-
initRuntime(entries, isReducedMotion, getService, true)
|
|
133
170
|
} else if (isOpen('specs.thunderbolt.interactionsInSsr')) {
|
|
134
171
|
// Emits the config and loader scripts. Works in both environments: SSR serves markup the
|
|
135
172
|
// parser executes, and on the client the loader's ref revives it into a script that runs —
|