@wix/site-service-interactions 1.0.13 → 1.0.15

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.
Files changed (69) hide show
  1. package/cjs/build/definition/index.js.map +1 -1
  2. package/cjs/build/implementations/InteractionsScriptElement.js.map +1 -1
  3. package/cjs/build/implementations/configEntries.js +4 -6
  4. package/cjs/build/implementations/configEntries.js.map +1 -1
  5. package/cjs/build/implementations/coreInteractions.js +1 -1
  6. package/cjs/build/implementations/coreInteractions.js.map +1 -1
  7. package/cjs/build/implementations/interactions.js +1 -1
  8. package/cjs/build/implementations/interactions.js.map +1 -1
  9. package/cjs/build/implementations/interactionsExternal.js +1 -1
  10. package/cjs/build/implementations/interactionsExternal.js.map +1 -1
  11. package/cjs/build/implementations/interactionsService.js.map +1 -1
  12. package/cjs/build/implementations/reviveScriptElement.js.map +1 -1
  13. package/cjs/build/implementations/v2/InteractionsScriptElement.js.map +1 -1
  14. package/cjs/build/implementations/v2/authoredStyles.js +6 -11
  15. package/cjs/build/implementations/v2/authoredStyles.js.map +1 -1
  16. package/cjs/build/implementations/v2/cdnUrls.js.map +1 -1
  17. package/cjs/build/implementations/v2/clickTriggerCss.js +1 -1
  18. package/cjs/build/implementations/v2/clickTriggerCss.js.map +1 -1
  19. package/cjs/build/implementations/v2/configCss.js.map +1 -1
  20. package/cjs/build/implementations/v2/configStyleHeadContent.js.map +1 -1
  21. package/cjs/build/implementations/v2/interactionsScriptContent.js +2 -2
  22. package/cjs/build/implementations/v2/interactionsScriptContent.js.map +1 -1
  23. package/cjs/build/implementations/v2/motionPresets.js +1 -1
  24. package/cjs/build/implementations/v2/motionPresets.js.map +1 -1
  25. package/cjs/package.json +1 -1
  26. package/definition/package.json +1 -1
  27. package/dist/definition/index.js.map +1 -1
  28. package/dist/implementations/InteractionsScriptElement.js.map +1 -1
  29. package/dist/implementations/configEntries.js +4 -6
  30. package/dist/implementations/configEntries.js.map +1 -1
  31. package/dist/implementations/coreInteractions.js +1 -1
  32. package/dist/implementations/coreInteractions.js.map +1 -1
  33. package/dist/implementations/interactions.js +1 -1
  34. package/dist/implementations/interactions.js.map +1 -1
  35. package/dist/implementations/interactionsExternal.js +1 -1
  36. package/dist/implementations/interactionsExternal.js.map +1 -1
  37. package/dist/implementations/interactionsService.js.map +1 -1
  38. package/dist/implementations/reviveScriptElement.js.map +1 -1
  39. package/dist/implementations/v2/InteractionsScriptElement.js.map +1 -1
  40. package/dist/implementations/v2/authoredStyles.js +6 -11
  41. package/dist/implementations/v2/authoredStyles.js.map +1 -1
  42. package/dist/implementations/v2/cdnUrls.js.map +1 -1
  43. package/dist/implementations/v2/clickTriggerCss.js +1 -1
  44. package/dist/implementations/v2/clickTriggerCss.js.map +1 -1
  45. package/dist/implementations/v2/configCss.js.map +1 -1
  46. package/dist/implementations/v2/configStyleHeadContent.js.map +1 -1
  47. package/dist/implementations/v2/interactionsScriptContent.js +2 -2
  48. package/dist/implementations/v2/interactionsScriptContent.js.map +1 -1
  49. package/dist/implementations/v2/motionPresets.js +1 -1
  50. package/dist/implementations/v2/motionPresets.js.map +1 -1
  51. package/implementations/package.json +1 -1
  52. package/package.json +22 -22
  53. package/src/definition/index.ts +11 -11
  54. package/src/implementations/InteractionsScriptElement.tsx +16 -16
  55. package/src/implementations/configEntries.ts +61 -63
  56. package/src/implementations/coreInteractions.ts +86 -86
  57. package/src/implementations/interactions.ts +8 -8
  58. package/src/implementations/interactionsExternal.ts +11 -11
  59. package/src/implementations/interactionsService.ts +8 -8
  60. package/src/implementations/reviveScriptElement.ts +8 -8
  61. package/src/implementations/v2/InteractionsScriptElement.tsx +21 -26
  62. package/src/implementations/v2/authoredStyles.ts +74 -79
  63. package/src/implementations/v2/cdnUrls.ts +1 -1
  64. package/src/implementations/v2/clickTriggerCss.ts +25 -25
  65. package/src/implementations/v2/configCss.ts +3 -3
  66. package/src/implementations/v2/configStyleHeadContent.ts +3 -3
  67. package/src/implementations/v2/interactionsScriptContent.ts +31 -31
  68. package/src/implementations/v2/motionPresets.ts +27 -27
  69. package/types/package.json +1 -1
@@ -7,9 +7,9 @@ const STYLE_END_TAG = /<\/style(?=[\t\n\f\r />])/i
7
7
  const SCRIPT_LIKE = /<script/gi
8
8
 
9
9
  const sanitizeCssForStyleElement = (css: string): string => {
10
- const styleEndTagIndex = css.search(STYLE_END_TAG)
11
- const withoutStyleBreakout = styleEndTagIndex === -1 ? css : css.slice(0, styleEndTagIndex)
12
- return withoutStyleBreakout.replace(SCRIPT_LIKE, '\\3c script')
10
+ const styleEndTagIndex = css.search(STYLE_END_TAG)
11
+ const withoutStyleBreakout = styleEndTagIndex === -1 ? css : css.slice(0, styleEndTagIndex)
12
+ return withoutStyleBreakout.replace(SCRIPT_LIKE, '\\3c script')
13
13
  }
14
14
 
15
15
  export const getV2ConfigStyleHeadContent = (css: string): string => `<style>${sanitizeCssForStyleElement(css)}</style>`
@@ -11,36 +11,36 @@ const MODULE_IMPORT_URLS = [INTERACT_V2_IMPORT_URL, LEGACY_WIX_MOTION_PRESETS_IM
11
11
  * would download each module twice.
12
12
  */
13
13
  export const getV2ModulePreloadHeadContent = (): string =>
14
- MODULE_IMPORT_URLS.map(url => `<link rel="modulepreload" href="${url}">`).join('')
14
+ MODULE_IMPORT_URLS.map((url) => `<link rel="modulepreload" href="${url}">`).join('')
15
15
 
16
16
  export const getV2InteractionsScriptContent = (configId: string, isReducedMotion: boolean): string =>
17
- [
18
- `const configElement = document.getElementById(\`${configId}\`)`,
19
- 'if (configElement) {',
20
- ' const parsedConfig = JSON.parse(configElement.textContent)',
21
- ' const configs = Array.isArray(parsedConfig) ? parsedConfig : [parsedConfig]',
22
- ' const [{ Interact }, legacyPresets, presets] = await Promise.all([',
23
- ...MODULE_IMPORT_URLS.map(url => ` import(\`${url}\`),`),
24
- ' ])',
25
- // Reactions configs carry the prefix on their named effect types, so the two packages can
26
- // both export a preset under the same name without one shadowing the other.
27
- ' const aliasedLegacyPresets = {}',
28
- ' for (const name of Object.keys(legacyPresets)) {',
29
- ` aliasedLegacyPresets[\`${LEGACY_PREFIX}\` + name] = legacyPresets[name]`,
30
- ' }',
31
- ' Interact.registerEffects({ ...presets, ...aliasedLegacyPresets })',
32
- ` Interact.forceReducedMotion = ${isReducedMotion}`,
33
- ' Interact.setup({',
34
- ' scrollOptionsGetter: function () {',
35
- ' return document.getElementById(`site-root`)',
36
- ' },',
37
- ' allowA11yTriggers: true,',
38
- ' viewEnter: {',
39
- ' useSafeViewEnter: true,',
40
- ' },',
41
- ' })',
42
- ' for (const config of configs) {',
43
- ' Interact.create(config)',
44
- ' }',
45
- '}',
46
- ].join('\n')
17
+ [
18
+ `const configElement = document.getElementById(\`${configId}\`)`,
19
+ 'if (configElement) {',
20
+ ' const parsedConfig = JSON.parse(configElement.textContent)',
21
+ ' const configs = Array.isArray(parsedConfig) ? parsedConfig : [parsedConfig]',
22
+ ' const [{ Interact }, legacyPresets, presets] = await Promise.all([',
23
+ ...MODULE_IMPORT_URLS.map((url) => ` import(\`${url}\`),`),
24
+ ' ])',
25
+ // Reactions configs carry the prefix on their named effect types, so the two packages can
26
+ // both export a preset under the same name without one shadowing the other.
27
+ ' const aliasedLegacyPresets = {}',
28
+ ' for (const name of Object.keys(legacyPresets)) {',
29
+ ` aliasedLegacyPresets[\`${LEGACY_PREFIX}\` + name] = legacyPresets[name]`,
30
+ ' }',
31
+ ' Interact.registerEffects({ ...presets, ...aliasedLegacyPresets })',
32
+ ` Interact.forceReducedMotion = ${isReducedMotion}`,
33
+ ' Interact.setup({',
34
+ ' scrollOptionsGetter: function () {',
35
+ ' return document.getElementById(`site-root`)',
36
+ ' },',
37
+ ' allowA11yTriggers: true,',
38
+ ' viewEnter: {',
39
+ ' useSafeViewEnter: true,',
40
+ ' },',
41
+ ' })',
42
+ ' for (const config of configs) {',
43
+ ' Interact.create(config)',
44
+ ' }',
45
+ '}',
46
+ ].join('\n')
@@ -3,9 +3,9 @@ import * as allPresets from '@wix/motion-presets'
3
3
  import type { Effect, EffectRef, InteractConfig } from '@wix/interact-v2'
4
4
 
5
5
  type EffectModule = {
6
- web: unknown
7
- style?: unknown
8
- getNames: unknown
6
+ web: unknown
7
+ style?: unknown
8
+ getNames: unknown
9
9
  }
10
10
 
11
11
  type NamedEffect = { type: string } & Record<string, unknown>
@@ -13,48 +13,48 @@ type NamedEffect = { type: string } & Record<string, unknown>
13
13
  export const LEGACY_PREFIX = 'LEGACY_'
14
14
 
15
15
  const isEffectModule = (value: unknown): value is EffectModule =>
16
- typeof value === 'object' && value !== null && 'web' in value && 'getNames' in value
16
+ typeof value === 'object' && value !== null && 'web' in value && 'getNames' in value
17
17
 
18
18
  const getPresetModules = (namespace: object, prefix: string = ''): Record<string, EffectModule> =>
19
- Object.fromEntries(
20
- Object.entries(namespace)
21
- .filter(([, value]) => isEffectModule(value))
22
- .map(([name, value]) => [`${prefix}${name}`, value as EffectModule])
23
- )
19
+ Object.fromEntries(
20
+ Object.entries(namespace)
21
+ .filter(([, value]) => isEffectModule(value))
22
+ .map(([name, value]) => [`${prefix}${name}`, value as EffectModule])
23
+ )
24
24
 
25
25
  /**
26
26
  * Both preset packages under one registry, mirroring what the client loader registers. The legacy
27
27
  * names carry the prefix so a preset published by both packages doesn't shadow its counterpart.
28
28
  */
29
29
  export const motionPresets: Record<string, EffectModule> = {
30
- ...getPresetModules(allPresets),
31
- ...getPresetModules(allLegacyPresets, LEGACY_PREFIX),
30
+ ...getPresetModules(allPresets),
31
+ ...getPresetModules(allLegacyPresets, LEGACY_PREFIX),
32
32
  }
33
33
 
34
34
  const aliasEffect = <T extends object>(effect: T): T => {
35
- const { namedEffect } = effect as { namedEffect?: NamedEffect }
36
- if (!namedEffect?.type) {
37
- return effect
38
- }
39
- return { ...effect, namedEffect: { ...namedEffect, type: `${LEGACY_PREFIX}${namedEffect.type}` } }
35
+ const { namedEffect } = effect as { namedEffect?: NamedEffect }
36
+ if (!namedEffect?.type) {
37
+ return effect
38
+ }
39
+ return { ...effect, namedEffect: { ...namedEffect, type: `${LEGACY_PREFIX}${namedEffect.type}` } }
40
40
  }
41
41
 
42
42
  const aliasSequence = <T extends object>(sequence: T): T => {
43
- const { effects } = sequence as { effects?: (Effect | EffectRef)[] }
44
- return effects ? { ...sequence, effects: effects.map(aliasEffect) } : sequence
43
+ const { effects } = sequence as { effects?: (Effect | EffectRef)[] }
44
+ return effects ? { ...sequence, effects: effects.map(aliasEffect) } : sequence
45
45
  }
46
46
 
47
47
  const mapRecord = <T>(record: Record<string, T>, map: (value: T) => T): Record<string, T> =>
48
- Object.fromEntries(Object.entries(record).map(([key, value]) => [key, map(value)]))
48
+ Object.fromEntries(Object.entries(record).map(([key, value]) => [key, map(value)]))
49
49
 
50
50
  // 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.
51
51
  export const aliasLegacyNamedEffects = (interact: InteractConfig): InteractConfig => ({
52
- ...interact,
53
- ...(interact.effects && { effects: mapRecord(interact.effects, aliasEffect) }),
54
- ...(interact.sequences && { sequences: mapRecord(interact.sequences, aliasSequence) }),
55
- interactions: interact.interactions.map(interaction => ({
56
- ...interaction,
57
- ...(interaction.effects && { effects: interaction.effects.map(aliasEffect) }),
58
- ...(interaction.sequences && { sequences: interaction.sequences.map(aliasSequence) }),
59
- })),
52
+ ...interact,
53
+ ...(interact.effects && { effects: mapRecord(interact.effects, aliasEffect) }),
54
+ ...(interact.sequences && { sequences: mapRecord(interact.sequences, aliasSequence) }),
55
+ interactions: interact.interactions.map((interaction) => ({
56
+ ...interaction,
57
+ ...(interaction.effects && { effects: interaction.effects.map(aliasEffect) }),
58
+ ...(interaction.sequences && { sequences: interaction.sequences.map(aliasSequence) }),
59
+ })),
60
60
  })
@@ -1,3 +1,3 @@
1
1
  {
2
- "main": "../cjs/build/types/index.js"
2
+ "main": "../cjs/build/types/index.js"
3
3
  }