@wix/site-service-interactions 1.0.11 → 1.0.13
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/definition/index.d.ts +19 -3
- package/cjs/build/definition/index.js.map +1 -1
- package/cjs/build/implementations/InteractionsScriptElement.d.ts +1 -1
- package/cjs/build/implementations/configEntries.d.ts +13 -0
- package/cjs/build/implementations/configEntries.js +80 -0
- package/cjs/build/implementations/configEntries.js.map +1 -0
- package/cjs/build/implementations/coreInteractions.d.ts +2 -2
- package/cjs/build/implementations/coreInteractions.js +50 -23
- package/cjs/build/implementations/coreInteractions.js.map +1 -1
- package/cjs/build/implementations/interactionsService.d.ts +5 -4
- package/cjs/build/implementations/v2/InteractionsScriptElement.d.ts +2 -2
- package/cjs/build/implementations/v2/InteractionsScriptElement.js.map +1 -1
- package/cjs/build/implementations/v2/authoredStyles.d.ts +2 -0
- package/cjs/build/implementations/v2/authoredStyles.js +95 -0
- package/cjs/build/implementations/v2/authoredStyles.js.map +1 -0
- package/cjs/build/implementations/v2/cdnUrls.d.ts +2 -1
- package/cjs/build/implementations/v2/cdnUrls.js +3 -2
- package/cjs/build/implementations/v2/cdnUrls.js.map +1 -1
- package/cjs/build/implementations/v2/clickTriggerCss.d.ts +1 -1
- package/cjs/build/implementations/v2/configCss.d.ts +1 -1
- package/cjs/build/implementations/v2/configCss.js +3 -36
- package/cjs/build/implementations/v2/configCss.js.map +1 -1
- package/cjs/build/implementations/v2/configStyleHeadContent.js +8 -6
- package/cjs/build/implementations/v2/configStyleHeadContent.js.map +1 -1
- package/cjs/build/implementations/v2/interactionsScriptContent.js +18 -7
- package/cjs/build/implementations/v2/interactionsScriptContent.js.map +1 -1
- package/cjs/build/implementations/v2/motionPresets.d.ts +14 -0
- package/cjs/build/implementations/v2/motionPresets.js +76 -0
- package/cjs/build/implementations/v2/motionPresets.js.map +1 -0
- package/cjs/build/service.d.ts +1 -1
- package/cjs/build/types/index.d.ts +1 -1
- package/dist/definition/index.d.ts +19 -3
- package/dist/definition/index.js.map +1 -1
- package/dist/implementations/InteractionsScriptElement.d.ts +1 -1
- package/dist/implementations/configEntries.d.ts +13 -0
- package/dist/implementations/configEntries.js +73 -0
- package/dist/implementations/configEntries.js.map +1 -0
- package/dist/implementations/coreInteractions.d.ts +2 -2
- package/dist/implementations/coreInteractions.js +50 -23
- package/dist/implementations/coreInteractions.js.map +1 -1
- package/dist/implementations/interactionsService.d.ts +5 -4
- package/dist/implementations/v2/InteractionsScriptElement.d.ts +2 -2
- package/dist/implementations/v2/InteractionsScriptElement.js.map +1 -1
- package/dist/implementations/v2/authoredStyles.d.ts +2 -0
- package/dist/implementations/v2/authoredStyles.js +91 -0
- package/dist/implementations/v2/authoredStyles.js.map +1 -0
- package/dist/implementations/v2/cdnUrls.d.ts +2 -1
- package/dist/implementations/v2/cdnUrls.js +2 -1
- package/dist/implementations/v2/cdnUrls.js.map +1 -1
- package/dist/implementations/v2/clickTriggerCss.d.ts +1 -1
- package/dist/implementations/v2/configCss.d.ts +1 -1
- package/dist/implementations/v2/configCss.js +2 -2
- package/dist/implementations/v2/configCss.js.map +1 -1
- package/dist/implementations/v2/configStyleHeadContent.js +8 -6
- package/dist/implementations/v2/configStyleHeadContent.js.map +1 -1
- package/dist/implementations/v2/interactionsScriptContent.js +19 -8
- package/dist/implementations/v2/interactionsScriptContent.js.map +1 -1
- package/dist/implementations/v2/motionPresets.d.ts +14 -0
- package/dist/implementations/v2/motionPresets.js +39 -0
- package/dist/implementations/v2/motionPresets.js.map +1 -0
- package/dist/service.d.ts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/package.json +6 -4
- package/src/definition/index.ts +19 -2
- package/src/implementations/InteractionsScriptElement.tsx +1 -1
- package/src/implementations/configEntries.ts +105 -0
- package/src/implementations/coreInteractions.ts +64 -30
- package/src/implementations/v2/InteractionsScriptElement.tsx +3 -3
- package/src/implementations/v2/authoredStyles.ts +108 -0
- package/src/implementations/v2/cdnUrls.ts +4 -1
- package/src/implementations/v2/clickTriggerCss.ts +1 -1
- package/src/implementations/v2/configCss.ts +4 -5
- package/src/implementations/v2/configStyleHeadContent.ts +9 -6
- package/src/implementations/v2/interactionsScriptContent.ts +20 -8
- package/src/implementations/v2/motionPresets.ts +60 -0
- package/src/types/index.ts +1 -1
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Head content is a raw HTML string
|
|
3
|
-
* style
|
|
4
|
-
*
|
|
5
|
-
* from the first `<` that could start a tag leaves valid CSS untouched.
|
|
2
|
+
* Head content is a raw HTML string. CSS values may contain tag-like text, but an actual closing
|
|
3
|
+
* style tag still terminates the raw-text element, and HeadAppender rejects `<script` substrings.
|
|
4
|
+
* Keep other CSS intact: drop content after a closing style tag and break script-like sequences.
|
|
6
5
|
*/
|
|
6
|
+
const STYLE_END_TAG = /<\/style(?=[\t\n\f\r />])/i;
|
|
7
|
+
const SCRIPT_LIKE = /<script/gi;
|
|
7
8
|
const sanitizeCssForStyleElement = (css) => {
|
|
8
|
-
const
|
|
9
|
-
|
|
9
|
+
const styleEndTagIndex = css.search(STYLE_END_TAG);
|
|
10
|
+
const withoutStyleBreakout = styleEndTagIndex === -1 ? css : css.slice(0, styleEndTagIndex);
|
|
11
|
+
return withoutStyleBreakout.replace(SCRIPT_LIKE, '\\3c script');
|
|
10
12
|
};
|
|
11
13
|
export const getV2ConfigStyleHeadContent = (css) => `<style>${sanitizeCssForStyleElement(css)}</style>`;
|
|
12
14
|
//# sourceMappingURL=configStyleHeadContent.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configStyleHeadContent.js","sourceRoot":"","sources":["../../../src/implementations/v2/configStyleHeadContent.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"configStyleHeadContent.js","sourceRoot":"","sources":["../../../src/implementations/v2/configStyleHeadContent.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,aAAa,GAAG,4BAA4B,CAAA;AAClD,MAAM,WAAW,GAAG,WAAW,CAAA;AAE/B,MAAM,0BAA0B,GAAG,CAAC,GAAW,EAAU,EAAE;IACvD,MAAM,gBAAgB,GAAG,GAAG,CAAC,MAAM,CAAC,aAAa,CAAC,CAAA;IAClD,MAAM,oBAAoB,GAAG,gBAAgB,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,gBAAgB,CAAC,CAAA;IAC3F,OAAO,oBAAoB,CAAC,OAAO,CAAC,WAAW,EAAE,aAAa,CAAC,CAAA;AACnE,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,GAAW,EAAU,EAAE,CAAC,UAAU,0BAA0B,CAAC,GAAG,CAAC,UAAU,CAAA"}
|
|
@@ -1,20 +1,29 @@
|
|
|
1
|
-
import { INTERACT_V2_IMPORT_URL,
|
|
1
|
+
import { INTERACT_V2_IMPORT_URL, LEGACY_WIX_MOTION_PRESETS_IMPORT_URL, MOTION_PRESETS_IMPORT_URL } from './cdnUrls';
|
|
2
|
+
import { LEGACY_PREFIX } from './motionPresets';
|
|
3
|
+
/** The loader destructures `Promise.all` in this order. */
|
|
4
|
+
const MODULE_IMPORT_URLS = [INTERACT_V2_IMPORT_URL, LEGACY_WIX_MOTION_PRESETS_IMPORT_URL, MOTION_PRESETS_IMPORT_URL];
|
|
2
5
|
/**
|
|
3
6
|
* The loader reaches these modules through dynamic `import()`, which the preload scanner cannot
|
|
4
7
|
* see, so without the links the fetches only start once the loader runs. No `crossorigin`: a bare
|
|
5
8
|
* `modulepreload` fetches with the same credentials mode as a bare `import()`, and a mismatch
|
|
6
9
|
* would download each module twice.
|
|
7
10
|
*/
|
|
8
|
-
export const getV2ModulePreloadHeadContent = () =>
|
|
11
|
+
export const getV2ModulePreloadHeadContent = () => MODULE_IMPORT_URLS.map(url => `<link rel="modulepreload" href="${url}">`).join('');
|
|
9
12
|
export const getV2InteractionsScriptContent = (configId, isReducedMotion) => [
|
|
10
13
|
`const configElement = document.getElementById(\`${configId}\`)`,
|
|
11
14
|
'if (configElement) {',
|
|
12
|
-
' const
|
|
13
|
-
' const
|
|
14
|
-
|
|
15
|
-
` import(\`${
|
|
15
|
+
' const parsedConfig = JSON.parse(configElement.textContent)',
|
|
16
|
+
' const configs = Array.isArray(parsedConfig) ? parsedConfig : [parsedConfig]',
|
|
17
|
+
' const [{ Interact }, legacyPresets, presets] = await Promise.all([',
|
|
18
|
+
...MODULE_IMPORT_URLS.map(url => ` import(\`${url}\`),`),
|
|
16
19
|
' ])',
|
|
17
|
-
|
|
20
|
+
// Reactions configs carry the prefix on their named effect types, so the two packages can
|
|
21
|
+
// both export a preset under the same name without one shadowing the other.
|
|
22
|
+
' const aliasedLegacyPresets = {}',
|
|
23
|
+
' for (const name of Object.keys(legacyPresets)) {',
|
|
24
|
+
` aliasedLegacyPresets[\`${LEGACY_PREFIX}\` + name] = legacyPresets[name]`,
|
|
25
|
+
' }',
|
|
26
|
+
' Interact.registerEffects({ ...presets, ...aliasedLegacyPresets })',
|
|
18
27
|
` Interact.forceReducedMotion = ${isReducedMotion}`,
|
|
19
28
|
' Interact.setup({',
|
|
20
29
|
' scrollOptionsGetter: function () {',
|
|
@@ -25,7 +34,9 @@ export const getV2InteractionsScriptContent = (configId, isReducedMotion) => [
|
|
|
25
34
|
' useSafeViewEnter: true,',
|
|
26
35
|
' },',
|
|
27
36
|
' })',
|
|
28
|
-
'
|
|
37
|
+
' for (const config of configs) {',
|
|
38
|
+
' Interact.create(config)',
|
|
39
|
+
' }',
|
|
29
40
|
'}',
|
|
30
41
|
].join('\n');
|
|
31
42
|
//# sourceMappingURL=interactionsScriptContent.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interactionsScriptContent.js","sourceRoot":"","sources":["../../../src/implementations/v2/interactionsScriptContent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,
|
|
1
|
+
{"version":3,"file":"interactionsScriptContent.js","sourceRoot":"","sources":["../../../src/implementations/v2/interactionsScriptContent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,oCAAoC,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAA;AACnH,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAE/C,2DAA2D;AAC3D,MAAM,kBAAkB,GAAG,CAAC,sBAAsB,EAAE,oCAAoC,EAAE,yBAAyB,CAAC,CAAA;AAEpH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,GAAW,EAAE,CACtD,kBAAkB,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,mCAAmC,GAAG,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;AAEtF,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAAC,QAAgB,EAAE,eAAwB,EAAU,EAAE,CACjG;IACI,mDAAmD,QAAQ,KAAK;IAChE,sBAAsB;IACtB,8DAA8D;IAC9D,+EAA+E;IAC/E,sEAAsE;IACtE,GAAG,kBAAkB,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,gBAAgB,GAAG,MAAM,CAAC;IAC3D,MAAM;IACN,0FAA0F;IAC1F,4EAA4E;IAC5E,mCAAmC;IACnC,oDAAoD;IACpD,8BAA8B,aAAa,kCAAkC;IAC7E,KAAK;IACL,qEAAqE;IACrE,mCAAmC,eAAe,EAAE;IACpD,oBAAoB;IACpB,wCAAwC;IACxC,mDAAmD;IACnD,QAAQ;IACR,8BAA8B;IAC9B,kBAAkB;IAClB,+BAA+B;IAC/B,QAAQ;IACR,MAAM;IACN,mCAAmC;IACnC,6BAA6B;IAC7B,KAAK;IACL,GAAG;CACN,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { InteractConfig } from '@wix/interact-v2';
|
|
2
|
+
type EffectModule = {
|
|
3
|
+
web: unknown;
|
|
4
|
+
style?: unknown;
|
|
5
|
+
getNames: unknown;
|
|
6
|
+
};
|
|
7
|
+
export declare const LEGACY_PREFIX = "LEGACY_";
|
|
8
|
+
/**
|
|
9
|
+
* Both preset packages under one registry, mirroring what the client loader registers. The legacy
|
|
10
|
+
* names carry the prefix so a preset published by both packages doesn't shadow its counterpart.
|
|
11
|
+
*/
|
|
12
|
+
export declare const motionPresets: Record<string, EffectModule>;
|
|
13
|
+
export declare const aliasLegacyNamedEffects: (interact: InteractConfig) => InteractConfig;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import * as allLegacyPresets from '@wix/wix-motion-presets';
|
|
2
|
+
import * as allPresets from '@wix/motion-presets';
|
|
3
|
+
export const LEGACY_PREFIX = 'LEGACY_';
|
|
4
|
+
const isEffectModule = (value) => typeof value === 'object' && value !== null && 'web' in value && 'getNames' in value;
|
|
5
|
+
const getPresetModules = (namespace, prefix = '') => Object.fromEntries(Object.entries(namespace)
|
|
6
|
+
.filter(([, value]) => isEffectModule(value))
|
|
7
|
+
.map(([name, value]) => [`${prefix}${name}`, value]));
|
|
8
|
+
/**
|
|
9
|
+
* Both preset packages under one registry, mirroring what the client loader registers. The legacy
|
|
10
|
+
* names carry the prefix so a preset published by both packages doesn't shadow its counterpart.
|
|
11
|
+
*/
|
|
12
|
+
export const motionPresets = {
|
|
13
|
+
...getPresetModules(allPresets),
|
|
14
|
+
...getPresetModules(allLegacyPresets, LEGACY_PREFIX),
|
|
15
|
+
};
|
|
16
|
+
const aliasEffect = (effect) => {
|
|
17
|
+
const { namedEffect } = effect;
|
|
18
|
+
if (!namedEffect?.type) {
|
|
19
|
+
return effect;
|
|
20
|
+
}
|
|
21
|
+
return { ...effect, namedEffect: { ...namedEffect, type: `${LEGACY_PREFIX}${namedEffect.type}` } };
|
|
22
|
+
};
|
|
23
|
+
const aliasSequence = (sequence) => {
|
|
24
|
+
const { effects } = sequence;
|
|
25
|
+
return effects ? { ...sequence, effects: effects.map(aliasEffect) } : sequence;
|
|
26
|
+
};
|
|
27
|
+
const mapRecord = (record, map) => Object.fromEntries(Object.entries(record).map(([key, value]) => [key, map(value)]));
|
|
28
|
+
// TODO(ameerf): make this implementation simpler without so many copies of the config object. The current implementation is a direct translation of the v1 code, which was written to avoid mutating the config object.
|
|
29
|
+
export const aliasLegacyNamedEffects = (interact) => ({
|
|
30
|
+
...interact,
|
|
31
|
+
...(interact.effects && { effects: mapRecord(interact.effects, aliasEffect) }),
|
|
32
|
+
...(interact.sequences && { sequences: mapRecord(interact.sequences, aliasSequence) }),
|
|
33
|
+
interactions: interact.interactions.map(interaction => ({
|
|
34
|
+
...interaction,
|
|
35
|
+
...(interaction.effects && { effects: interaction.effects.map(aliasEffect) }),
|
|
36
|
+
...(interaction.sequences && { sequences: interaction.sequences.map(aliasSequence) }),
|
|
37
|
+
})),
|
|
38
|
+
});
|
|
39
|
+
//# sourceMappingURL=motionPresets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"motionPresets.js","sourceRoot":"","sources":["../../../src/implementations/v2/motionPresets.ts"],"names":[],"mappings":"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"}
|
package/dist/service.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { InteractionsService } from './implementations/interactionsService';
|
|
2
2
|
export declare const definition: string & {
|
|
3
3
|
__api: import("./definition").IInteractionsService;
|
|
4
|
-
__config: import("
|
|
4
|
+
__config: import("./definition").IInteractionsServiceConfig;
|
|
5
5
|
isServiceDefinition?: boolean;
|
|
6
6
|
} & import("./definition").IInteractionsService;
|
|
7
7
|
export default InteractionsService;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export type { IInteractionsService, IInteractionsServiceConfig, IInteractionsDefinition } from '../definition';
|
|
2
|
-
export type { InteractConfig } from '@wix/interact';
|
|
2
|
+
export type { InteractConfig } from '@wix/interact-v2';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wix/site-service-interactions",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.13",
|
|
4
4
|
"main": "cjs/build/index.js",
|
|
5
5
|
"module": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -44,7 +44,9 @@
|
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@wix/interact": "^1.103.0",
|
|
47
|
-
"@wix/interact-v2": "npm:@wix/interact
|
|
47
|
+
"@wix/interact-v2": "npm:@wix/interact@2.5.14",
|
|
48
|
+
"@wix/motion": "2.1.14",
|
|
49
|
+
"@wix/motion-presets": "1.0.7",
|
|
48
50
|
"@wix/services-manager": "^0.2.20",
|
|
49
51
|
"@wix/services-manager-react": "^0.1.26",
|
|
50
52
|
"@wix/site-service-device-info": "1.0.2",
|
|
@@ -53,7 +55,7 @@
|
|
|
53
55
|
"@wix/site-service-provide-css": "1.0.1",
|
|
54
56
|
"@wix/static-service": "1.0.19",
|
|
55
57
|
"@wix/viewer-service-pages": "1.0.11",
|
|
56
|
-
"@wix/wix-motion-presets": "
|
|
58
|
+
"@wix/wix-motion-presets": "1.2.0"
|
|
57
59
|
},
|
|
58
60
|
"devDependencies": {
|
|
59
61
|
"@types/react": "^18.3.1",
|
|
@@ -94,5 +96,5 @@
|
|
|
94
96
|
]
|
|
95
97
|
}
|
|
96
98
|
},
|
|
97
|
-
"falconPackageHash": "
|
|
99
|
+
"falconPackageHash": "2458872e3235fa01728dec98c1fee7715ee8507f8cde1c6d25d15ed0"
|
|
98
100
|
}
|
package/src/definition/index.ts
CHANGED
|
@@ -1,8 +1,25 @@
|
|
|
1
1
|
import { defineStaticService } from '@wix/static-service'
|
|
2
2
|
import type { StaticServiceDefinition } from '@wix/static-service'
|
|
3
|
-
import type { InteractConfig } from '@wix/interact'
|
|
3
|
+
import type { InteractConfig } from '@wix/interact-v2'
|
|
4
4
|
|
|
5
|
-
export type
|
|
5
|
+
export type { InteractConfig }
|
|
6
|
+
|
|
7
|
+
export type InteractStyleRule = {
|
|
8
|
+
key?: string
|
|
9
|
+
selector?: string
|
|
10
|
+
'@media'?: string
|
|
11
|
+
'@container'?: string
|
|
12
|
+
'@supports'?: string
|
|
13
|
+
properties: Record<string, string>
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type InteractConfigEntry = {
|
|
17
|
+
namespace?: string
|
|
18
|
+
interact: InteractConfig
|
|
19
|
+
styles?: InteractStyleRule[]
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type IInteractionsServiceConfig = InteractConfig | { entries: InteractConfigEntry[] }
|
|
6
23
|
|
|
7
24
|
export interface IInteractionsService {
|
|
8
25
|
hasInteractions: (path: string) => boolean
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
import type { FunctionComponent } from 'react'
|
|
3
|
-
import type { InteractConfig } from '@wix/interact'
|
|
3
|
+
import type { InteractConfig } from '@wix/interact-v2'
|
|
4
4
|
import { getInteractionsScriptContent } from './interactionsScriptContent'
|
|
5
5
|
import { reviveScriptElement } from './reviveScriptElement'
|
|
6
6
|
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type { InteractConfig, InteractConfigEntry, IInteractionsServiceConfig } from '../definition'
|
|
2
|
+
import { aliasLegacyNamedEffects } from './v2/motionPresets'
|
|
3
|
+
|
|
4
|
+
export const REACTIONS_NAMESPACE = 'reactions'
|
|
5
|
+
|
|
6
|
+
type Interaction = InteractConfig['interactions'][number]
|
|
7
|
+
type Sequence = NonNullable<Interaction['sequences']>[number]
|
|
8
|
+
type KeyedEffect = { key?: string; effectId?: string }
|
|
9
|
+
|
|
10
|
+
export const getInteractConfigEntries = (config: IInteractionsServiceConfig): InteractConfigEntry[] =>
|
|
11
|
+
'entries' in config ? config.entries : [{ interact: config, namespace: REACTIONS_NAMESPACE }]
|
|
12
|
+
|
|
13
|
+
export const getResolvedConfigEntries = (config: IInteractionsServiceConfig): InteractConfigEntry[] =>
|
|
14
|
+
getInteractConfigEntries(config).map(entry =>
|
|
15
|
+
entry.namespace === REACTIONS_NAMESPACE
|
|
16
|
+
? { ...entry, interact: aliasLegacyNamedEffects(entry.interact) }
|
|
17
|
+
: entry
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
/** An `effectId` points at `interact.effects`, which is where a reactions effect keeps its key. */
|
|
21
|
+
const resolveEffectKey = (interact: InteractConfig, effect: KeyedEffect): string | undefined =>
|
|
22
|
+
effect.key ?? (effect.effectId ? interact.effects?.[effect.effectId]?.key : undefined)
|
|
23
|
+
|
|
24
|
+
const addEffectKeys = (keys: Set<string>, interact: InteractConfig, effects: readonly KeyedEffect[] = []) => {
|
|
25
|
+
for (const effect of effects) {
|
|
26
|
+
const key = resolveEffectKey(interact, effect)
|
|
27
|
+
if (key) {
|
|
28
|
+
keys.add(key)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** A `sequenceId` reference has no inline effects; resolve it against `interact.sequences`. */
|
|
34
|
+
const getSequenceEffects = (interact: InteractConfig, sequence: Sequence): readonly KeyedEffect[] =>
|
|
35
|
+
'effects' in sequence ? sequence.effects : (interact.sequences?.[sequence.sequenceId]?.effects ?? [])
|
|
36
|
+
|
|
37
|
+
const getInteractionKeys = (interact: InteractConfig, interaction: Interaction): Set<string> => {
|
|
38
|
+
const keys = new Set<string>([interaction.key])
|
|
39
|
+
addEffectKeys(keys, interact, interaction.effects)
|
|
40
|
+
for (const sequence of interaction.sequences ?? []) {
|
|
41
|
+
addEffectKeys(keys, interact, getSequenceEffects(interact, sequence))
|
|
42
|
+
}
|
|
43
|
+
return keys
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const getInteractiveKeys = ({ interact }: InteractConfigEntry): Set<string> => {
|
|
47
|
+
const keys = new Set<string>()
|
|
48
|
+
|
|
49
|
+
for (const interaction of interact.interactions) {
|
|
50
|
+
getInteractionKeys(interact, interaction).forEach(key => keys.add(key))
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return keys
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const dropOverriddenKeys = (entry: InteractConfigEntry, overriddenKeys: Set<string>): InteractConfigEntry => {
|
|
57
|
+
const { interact } = entry
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
...entry,
|
|
61
|
+
interact: {
|
|
62
|
+
...interact,
|
|
63
|
+
interactions: interact.interactions.filter(
|
|
64
|
+
interaction => ![...getInteractionKeys(interact, interaction)].some(key => overriddenKeys.has(key))
|
|
65
|
+
),
|
|
66
|
+
},
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Interact resolves a custom-element key to the first instance containing that key, so a key shared
|
|
72
|
+
* by two entries would silently drop one of them. Experience entries own the keys they declare:
|
|
73
|
+
* whatever they claim is stripped from the reactions entry by dropping whole interactions whose
|
|
74
|
+
* resolved keys overlap. Top-level effect and sequence libraries are left intact. A collision between two
|
|
75
|
+
* experience entries stays an error, since neither of them is authoritative.
|
|
76
|
+
*/
|
|
77
|
+
export const resolveInteractKeyConflicts = (entries: InteractConfigEntry[]): InteractConfigEntry[] => {
|
|
78
|
+
const owners = new Map<string, string>()
|
|
79
|
+
|
|
80
|
+
entries.forEach((entry, index) => {
|
|
81
|
+
if (entry.namespace === REACTIONS_NAMESPACE) {
|
|
82
|
+
return
|
|
83
|
+
}
|
|
84
|
+
const owner = entry.namespace ?? `entry-${index}`
|
|
85
|
+
for (const key of getInteractiveKeys(entry)) {
|
|
86
|
+
const existingOwner = owners.get(key)
|
|
87
|
+
if (existingOwner !== undefined) {
|
|
88
|
+
throw new Error(
|
|
89
|
+
`Interactions config key "${key}" is shared by "${existingOwner}" and "${owner}". ` +
|
|
90
|
+
'Keys must be unique across config entries.'
|
|
91
|
+
)
|
|
92
|
+
}
|
|
93
|
+
owners.set(key, owner)
|
|
94
|
+
}
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
if (!owners.size) {
|
|
98
|
+
return entries
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const overriddenKeys = new Set(owners.keys())
|
|
102
|
+
return entries.map(entry =>
|
|
103
|
+
entry.namespace === REACTIONS_NAMESPACE ? dropOverriddenKeys(entry, overriddenKeys) : entry
|
|
104
|
+
)
|
|
105
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Interact } from '@wix/interact'
|
|
2
|
-
import type { InteractConfig } from '@wix/interact'
|
|
2
|
+
import type { InteractConfig as InteractV1Config } from '@wix/interact'
|
|
3
3
|
import { DeviceInfoDefinition } from '@wix/site-service-device-info/definition'
|
|
4
4
|
import { ExperimentsDefinition } from '@wix/site-service-experiments/definition'
|
|
5
5
|
// Deliberately the deprecated pages service. Thunderbolt registers the site-service-pages page
|
|
@@ -11,13 +11,25 @@ import { HeadAppenderDefinition } from '@wix/site-service-head-appender/definiti
|
|
|
11
11
|
import { HeadContentType } from '@wix/site-service-head-appender/types'
|
|
12
12
|
import { ProvideComponentServiceDefinition } from '@wix/services-manager-react/core-services/provide-component'
|
|
13
13
|
import type { ServicesManager } from '@wix/services-manager/types'
|
|
14
|
+
import type { InteractConfig, InteractConfigEntry, IInteractionsServiceConfig } from '../definition'
|
|
14
15
|
import { createInteractionsScriptElement } from './InteractionsScriptElement'
|
|
15
16
|
import { createV2InteractionsScriptElement } from './v2/InteractionsScriptElement'
|
|
16
17
|
import { getV2ConfigCss } from './v2/configCss'
|
|
17
18
|
import { getV2ConfigStyleHeadContent } from './v2/configStyleHeadContent'
|
|
18
19
|
import { getV2ModulePreloadHeadContent } from './v2/interactionsScriptContent'
|
|
20
|
+
import { getAuthoredStylesCss } from './v2/authoredStyles'
|
|
21
|
+
import {
|
|
22
|
+
getInteractConfigEntries,
|
|
23
|
+
getInteractiveKeys,
|
|
24
|
+
getResolvedConfigEntries,
|
|
25
|
+
resolveInteractKeyConflicts,
|
|
26
|
+
} from './configEntries'
|
|
19
27
|
|
|
20
|
-
|
|
28
|
+
/** An entry without interactions contributes CSS only; nothing has to load Interact for it. */
|
|
29
|
+
const getRuntimeConfigs = (entries: InteractConfigEntry[]): InteractConfig[] =>
|
|
30
|
+
entries.map(({ interact }) => interact).filter(({ interactions }) => interactions.length > 0)
|
|
31
|
+
|
|
32
|
+
const initInteract = (entries: InteractConfigEntry[], isReducedMotion: boolean) => {
|
|
21
33
|
// Bundled runtime is v1. v2 on the client is the CDN loader.
|
|
22
34
|
Interact.forceReducedMotion = isReducedMotion
|
|
23
35
|
Interact.setup({
|
|
@@ -27,16 +39,32 @@ const initInteract = (config: InteractConfig, isReducedMotion: boolean) => {
|
|
|
27
39
|
useSafeViewEnter: true,
|
|
28
40
|
},
|
|
29
41
|
})
|
|
30
|
-
|
|
42
|
+
for (const { interact } of entries) {
|
|
43
|
+
Interact.create(interact as InteractV1Config)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const getV2HeadContent = (entries: InteractConfigEntry[]): string => {
|
|
48
|
+
const generatedCss = entries
|
|
49
|
+
.map(({ interact }) => getV2ConfigCss(interact).trim())
|
|
50
|
+
.filter(Boolean)
|
|
51
|
+
.join('\n')
|
|
52
|
+
const css = [getAuthoredStylesCss(entries).trim(), generatedCss].filter(Boolean).join('\n')
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
(getRuntimeConfigs(entries).length ? getV2ModulePreloadHeadContent() : '') +
|
|
56
|
+
(css ? getV2ConfigStyleHeadContent(css) : '')
|
|
57
|
+
)
|
|
31
58
|
}
|
|
32
59
|
|
|
33
60
|
const initRuntime = (
|
|
34
|
-
|
|
61
|
+
entries: InteractConfigEntry[],
|
|
35
62
|
isReducedMotion: boolean,
|
|
36
63
|
getService: ServicesManager['getService'],
|
|
37
64
|
useV2: boolean
|
|
38
65
|
) => {
|
|
39
|
-
|
|
66
|
+
const runtimeConfigs = getRuntimeConfigs(entries)
|
|
67
|
+
if (!runtimeConfigs.length) {
|
|
40
68
|
return
|
|
41
69
|
}
|
|
42
70
|
|
|
@@ -47,55 +75,61 @@ const initRuntime = (
|
|
|
47
75
|
|
|
48
76
|
const { addTopComponent } = getService(ProvideComponentServiceDefinition)
|
|
49
77
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
78
|
+
if (!useV2) {
|
|
79
|
+
// v1 serializes a single config and has no path for authored-style CSS, so anything beyond
|
|
80
|
+
// that would be silently dropped.
|
|
81
|
+
if (entries.length > 1 || entries.some(({ styles }) => styles?.length)) {
|
|
82
|
+
throw new Error('Multiple interactions config entries and authored styles require Interact v2.')
|
|
83
|
+
}
|
|
84
|
+
addTopComponent(createInteractionsScriptElement(runtimeConfigs[0], isReducedMotion, pageId))
|
|
85
|
+
return
|
|
86
|
+
}
|
|
53
87
|
|
|
54
|
-
addTopComponent(
|
|
88
|
+
addTopComponent(createV2InteractionsScriptElement(runtimeConfigs, isReducedMotion, pageId))
|
|
55
89
|
}
|
|
56
90
|
|
|
57
|
-
const getInteractiveComps = (
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
return acc
|
|
66
|
-
}, new Set<string>())
|
|
91
|
+
const getInteractiveComps = (entries: InteractConfigEntry[]): Set<string> => {
|
|
92
|
+
const keys = new Set<string>()
|
|
93
|
+
for (const entry of entries) {
|
|
94
|
+
getInteractiveKeys(entry).forEach(key => keys.add(key))
|
|
95
|
+
}
|
|
96
|
+
return keys
|
|
97
|
+
}
|
|
67
98
|
|
|
68
|
-
export const coreInteractions = (config:
|
|
99
|
+
export const coreInteractions = (config: IInteractionsServiceConfig, getService: ServicesManager['getService']) => {
|
|
69
100
|
const { reducedMotion: isReducedMotion } = getService(DeviceInfoDefinition)
|
|
70
101
|
const { isOpen } = getService(ExperimentsDefinition)
|
|
102
|
+
const useV2 = isOpen('specs.thunderbolt.vsm_interactions_v2')
|
|
103
|
+
// The v1 runtime has no preset registration and doesn't understand LEGACY_* names; skip
|
|
104
|
+
// aliasing on those paths so named reaction effects remain resolvable.
|
|
105
|
+
const entries = resolveInteractKeyConflicts((useV2 ? getResolvedConfigEntries : getInteractConfigEntries)(config))
|
|
71
106
|
|
|
72
|
-
if (
|
|
107
|
+
if (useV2) {
|
|
73
108
|
// Both belong in the head: the preload links only help while the document is still parsing,
|
|
74
109
|
// and the generated CSS hides elements before their entrance effect, so it has to apply
|
|
75
110
|
// before the body renders.
|
|
76
111
|
if (!process.env.browser) {
|
|
77
|
-
const
|
|
112
|
+
const headContent = getV2HeadContent(entries)
|
|
78
113
|
// GENERAL rather than setHead's AFTER_SECURITY default: thunderbolt only reads the
|
|
79
114
|
// after-security bucket on its SEO path, so the default drops this on every normal
|
|
80
115
|
// request. GENERAL reaches the document as raw markup before `</head>`.
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
)
|
|
116
|
+
if (headContent) {
|
|
117
|
+
getService(HeadAppenderDefinition).setHead(headContent, HeadContentType.GENERAL)
|
|
118
|
+
}
|
|
85
119
|
}
|
|
86
120
|
|
|
87
|
-
initRuntime(
|
|
121
|
+
initRuntime(entries, isReducedMotion, getService, true)
|
|
88
122
|
} else if (isOpen('specs.thunderbolt.interactionsInSsr')) {
|
|
89
123
|
// Emits the config and loader scripts. Works in both environments: SSR serves markup the
|
|
90
124
|
// parser executes, and on the client the loader's ref revives it into a script that runs —
|
|
91
125
|
// which is what pages rendered only on the client (password-protected / members-only,
|
|
92
126
|
// client-side navigation) need, since they never get a server-rendered document.
|
|
93
|
-
initRuntime(
|
|
127
|
+
initRuntime(entries, isReducedMotion, getService, false)
|
|
94
128
|
} else {
|
|
95
|
-
initInteract(
|
|
129
|
+
initInteract(entries, isReducedMotion)
|
|
96
130
|
}
|
|
97
131
|
|
|
98
132
|
return {
|
|
99
|
-
interactiveComps: getInteractiveComps(
|
|
133
|
+
interactiveComps: getInteractiveComps(entries),
|
|
100
134
|
}
|
|
101
135
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
import type { FunctionComponent } from 'react'
|
|
3
|
-
import type { InteractConfig } from '@wix/interact'
|
|
3
|
+
import type { InteractConfig } from '@wix/interact-v2'
|
|
4
4
|
import { reviveScriptElement } from '../reviveScriptElement'
|
|
5
5
|
import { getV2InteractionsScriptContent } from './interactionsScriptContent'
|
|
6
6
|
|
|
@@ -10,11 +10,11 @@ const DANGEROUSLY_SET_INNER_HTML = ['dangerously', 'Set', 'Inner', 'HTML']
|
|
|
10
10
|
* The config is written as raw markup, so a `</script` inside any string value would close the
|
|
11
11
|
* element early. `\u003c` is valid JSON that `JSON.parse` reads back as `<`.
|
|
12
12
|
*/
|
|
13
|
-
const serializeConfigForScriptElement = (config: InteractConfig): string =>
|
|
13
|
+
const serializeConfigForScriptElement = (config: InteractConfig | InteractConfig[]): string =>
|
|
14
14
|
JSON.stringify(config).replace(/</g, '\\u003c')
|
|
15
15
|
|
|
16
16
|
export const createV2InteractionsScriptElement =
|
|
17
|
-
(config: InteractConfig, isReducedMotion: boolean, pageId: string): FunctionComponent =>
|
|
17
|
+
(config: InteractConfig | InteractConfig[], isReducedMotion: boolean, pageId: string): FunctionComponent =>
|
|
18
18
|
() => {
|
|
19
19
|
// This ID is also interpolated into raw module-script text. Percent-encoding removes
|
|
20
20
|
// script delimiters and template-literal syntax while keeping the ID deterministic.
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type { InteractConfigEntry, InteractStyleRule } from '../../definition'
|
|
2
|
+
|
|
3
|
+
const SELECTOR_TOKEN = /"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|[()[\]]|,/g
|
|
4
|
+
|
|
5
|
+
const escapeCssString = (value: string): string =>
|
|
6
|
+
value
|
|
7
|
+
.replace(/\\/g, '\\\\')
|
|
8
|
+
.replace(/"/g, '\\"')
|
|
9
|
+
.replace(/\n/g, '\\a ')
|
|
10
|
+
.replace(/\r/g, '\\d ')
|
|
11
|
+
.replace(/\f/g, '\\c ')
|
|
12
|
+
|
|
13
|
+
const splitSelectorList = (selector: string): string[] => {
|
|
14
|
+
const parts: string[] = []
|
|
15
|
+
let depth = 0
|
|
16
|
+
let start = 0
|
|
17
|
+
|
|
18
|
+
SELECTOR_TOKEN.lastIndex = 0
|
|
19
|
+
for (let match = SELECTOR_TOKEN.exec(selector); match; match = SELECTOR_TOKEN.exec(selector)) {
|
|
20
|
+
const token = match[0]
|
|
21
|
+
if (token === '(' || token === '[') {
|
|
22
|
+
depth++
|
|
23
|
+
} else if (token === ')' || token === ']') {
|
|
24
|
+
depth--
|
|
25
|
+
} else if (token === ',' && depth === 0) {
|
|
26
|
+
parts.push(selector.slice(start, match.index))
|
|
27
|
+
start = match.index + 1
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
parts.push(selector.slice(start))
|
|
32
|
+
return parts.map(part => part.trim()).filter(Boolean)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const indentCssBlock = (css: string): string =>
|
|
36
|
+
css
|
|
37
|
+
.split('\n')
|
|
38
|
+
.map(line => (line ? ` ${line}` : line))
|
|
39
|
+
.join('\n')
|
|
40
|
+
|
|
41
|
+
const renderProperties = (properties: Record<string, string>): string =>
|
|
42
|
+
Object.entries(properties)
|
|
43
|
+
.map(([property, value]) => ` ${property}: ${value};`)
|
|
44
|
+
.join('\n')
|
|
45
|
+
|
|
46
|
+
const wrapWithConditions = (block: string, rule: InteractStyleRule): string => {
|
|
47
|
+
let result = block
|
|
48
|
+
if (rule['@container']) {
|
|
49
|
+
result = `@container ${rule['@container']} {\n${indentCssBlock(result)}\n}`
|
|
50
|
+
}
|
|
51
|
+
if (rule['@media']) {
|
|
52
|
+
result = `@media ${rule['@media']} {\n${indentCssBlock(result)}\n}`
|
|
53
|
+
}
|
|
54
|
+
if (rule['@supports']) {
|
|
55
|
+
result = `@supports ${rule['@supports']} {\n${indentCssBlock(result)}\n}`
|
|
56
|
+
}
|
|
57
|
+
return result
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const buildRuleSelector = (namespace: string, rule: InteractStyleRule): string => {
|
|
61
|
+
const scopeWrapper = `[data-interact-key="${escapeCssString(namespace)}"]`
|
|
62
|
+
const scopeRoot = `${scopeWrapper} > :first-child`
|
|
63
|
+
|
|
64
|
+
if (!rule.key) {
|
|
65
|
+
if (!rule.selector) {
|
|
66
|
+
return scopeRoot
|
|
67
|
+
}
|
|
68
|
+
return splitSelectorList(rule.selector)
|
|
69
|
+
.map(selector => `${scopeRoot} ${selector}`)
|
|
70
|
+
.join(', ')
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const escapedKey = escapeCssString(rule.key)
|
|
74
|
+
const keyWrapper = rule.key === namespace ? scopeWrapper : `${scopeWrapper} [data-interact-key="${escapedKey}"]`
|
|
75
|
+
const keyRoot = `${keyWrapper} > :first-child`
|
|
76
|
+
if (!rule.selector) {
|
|
77
|
+
return keyRoot
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const separator = /^\s/.test(rule.selector) ? ' ' : ''
|
|
81
|
+
return splitSelectorList(rule.selector)
|
|
82
|
+
.map(selector => `${keyRoot}${separator}${selector}`)
|
|
83
|
+
.join(', ')
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const getEntryStylesCss = ({ namespace, styles = [] }: InteractConfigEntry): string => {
|
|
87
|
+
if (!styles.length) {
|
|
88
|
+
return ''
|
|
89
|
+
}
|
|
90
|
+
if (!namespace) {
|
|
91
|
+
throw new Error('Interactions config entries with authored styles must define a namespace.')
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return styles
|
|
95
|
+
.map(rule => {
|
|
96
|
+
const properties = renderProperties(rule.properties)
|
|
97
|
+
if (!properties) {
|
|
98
|
+
return ''
|
|
99
|
+
}
|
|
100
|
+
const block = `${buildRuleSelector(namespace, rule)} {\n${properties}\n}`
|
|
101
|
+
return wrapWithConditions(block, rule)
|
|
102
|
+
})
|
|
103
|
+
.filter(Boolean)
|
|
104
|
+
.join('\n\n')
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export const getAuthoredStylesCss = (entries: InteractConfigEntry[]): string =>
|
|
108
|
+
entries.map(getEntryStylesCss).filter(Boolean).join('\n\n')
|
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
export const INTERACT_V2_IMPORT_URL = 'https://cdn.jsdelivr.net/npm/@wix/interact@2.5.14/dist/es/web.min.js'
|
|
2
2
|
|
|
3
|
-
export const
|
|
3
|
+
export const LEGACY_WIX_MOTION_PRESETS_IMPORT_URL = 'https://cdn.jsdelivr.net/npm/@wix/wix-motion-presets@1.2.0/+esm'
|
|
4
|
+
|
|
5
|
+
export const MOTION_PRESETS_IMPORT_URL =
|
|
6
|
+
'https://cdn.jsdelivr.net/npm/@wix/motion-presets@1.0.7/dist/browser/motion-presets.min.js'
|