@gxpl/sdk 0.0.12 → 0.0.14

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 (55) hide show
  1. package/lib/sdk/Client/Client.d.ts +3 -7
  2. package/lib/sdk/Client/Client.js +9 -38
  3. package/lib/sdk/schemas/project/Project.schema.d.ts +28 -57
  4. package/lib/sdk/schemas/project/Project.schema.js +7 -10
  5. package/lib/sdk/transitions/transitionMachine.d.ts +616 -0
  6. package/lib/sdk/transitions/transitionMachine.js +258 -0
  7. package/lib/sdk/transitions/utils/findRelation.d.ts +2 -0
  8. package/lib/sdk/transitions/utils/findRelation.js +10 -0
  9. package/lib/sdk/transitions/utils/getAvailableTransitions.d.ts +7 -0
  10. package/lib/sdk/transitions/utils/getAvailableTransitions.js +12 -0
  11. package/lib/sdk/transitions/utils/getAxis.d.ts +2 -0
  12. package/lib/sdk/transitions/utils/getAxis.js +6 -0
  13. package/lib/sdk/transitions/utils/getDeltaAndProgress.d.ts +11 -0
  14. package/lib/sdk/transitions/utils/getDeltaAndProgress.js +13 -0
  15. package/lib/sdk/transitions/utils/getScenesOnEnd.d.ts +21 -0
  16. package/lib/sdk/transitions/utils/getScenesOnEnd.js +30 -0
  17. package/lib/sdk/transitions/utils/getScenesOnInit.d.ts +6 -0
  18. package/lib/sdk/transitions/utils/getScenesOnInit.js +20 -0
  19. package/lib/sdk/transitions/utils/getScenesOnInstantTransition.d.ts +2 -0
  20. package/lib/sdk/transitions/utils/getScenesOnInstantTransition.js +38 -0
  21. package/lib/sdk/transitions/utils/getScenesOnProgressUpdate.d.ts +26 -0
  22. package/lib/sdk/transitions/utils/getScenesOnProgressUpdate.js +15 -0
  23. package/lib/sdk/transitions/utils/getScenesOnStart.d.ts +21 -0
  24. package/lib/sdk/transitions/utils/getScenesOnStart.js +52 -0
  25. package/lib/sdk/transitions/utils/isActiveSwipeTransition.d.ts +2 -0
  26. package/lib/sdk/transitions/utils/isActiveSwipeTransition.js +12 -0
  27. package/lib/sdk/transitions/utils/isOverThreshold.d.ts +1 -0
  28. package/lib/sdk/transitions/utils/isOverThreshold.js +6 -0
  29. package/lib/sdk/transitions/utils/isTransitionSuccess.d.ts +2 -0
  30. package/lib/sdk/transitions/utils/isTransitionSuccess.js +15 -0
  31. package/lib/sdk/transitions/utils/normalizeOpacity.d.ts +1 -0
  32. package/lib/sdk/transitions/utils/normalizeOpacity.js +8 -0
  33. package/lib/sdk/transitions/utils/types.d.ts +49 -0
  34. package/lib/sdk/transitions/utils/types.js +2 -0
  35. package/lib/sdk/types/project/Page.d.ts +0 -7
  36. package/lib/sdk/types/project/Project.d.ts +2 -0
  37. package/lib/sdk/types/project/Relation.d.ts +8 -0
  38. package/lib/sdk/types/project/Relation.js +2 -0
  39. package/lib/sdk-nextjs/components/Article.d.ts +9 -2
  40. package/lib/sdk-nextjs/components/Article.js +8 -5
  41. package/lib/sdk-nextjs/components/ArticleWrapper.d.ts +12 -1
  42. package/lib/sdk-nextjs/components/ArticleWrapper.js +155 -2
  43. package/lib/sdk-nextjs/components/Head.d.ts +0 -2
  44. package/lib/sdk-nextjs/components/Head.js +2 -1
  45. package/lib/sdk-nextjs/components/Page.d.ts +4 -7
  46. package/lib/sdk-nextjs/components/Page.js +13 -7
  47. package/lib/sdk-nextjs/components/Scenes/Scenes.d.ts +11 -0
  48. package/lib/sdk-nextjs/components/Scenes/Scenes.js +16 -0
  49. package/lib/sdk-nextjs/components/items/Item.js +2 -2
  50. package/lib/sdk-nextjs/components/items/RectangleItem/RectangleItem.js +3 -3
  51. package/lib/sdk-nextjs/provider/CntrlSdkContext.d.ts +2 -2
  52. package/lib/sdk-nextjs/provider/CntrlSdkContext.js +4 -2
  53. package/lib/sdk-nextjs/provider/TransitionMachineContext.d.ts +2186 -0
  54. package/lib/sdk-nextjs/provider/TransitionMachineContext.js +6 -0
  55. package/package.json +3 -1
@@ -0,0 +1,258 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.transitionMachine = void 0;
4
+ const xstate_1 = require("xstate");
5
+ const getScenesOnInit_1 = require("./utils/getScenesOnInit");
6
+ const getAvailableTransitions_1 = require("./utils/getAvailableTransitions");
7
+ const findRelation_1 = require("./utils/findRelation");
8
+ const isTransitionSuccess_1 = require("./utils/isTransitionSuccess");
9
+ const getScenesOnStart_1 = require("./utils/getScenesOnStart");
10
+ const getScenesOnProgressUpdate_1 = require("./utils/getScenesOnProgressUpdate");
11
+ const getScenesOnEnd_1 = require("./utils/getScenesOnEnd");
12
+ const getScenesOnInstantTransition_1 = require("./utils/getScenesOnInstantTransition");
13
+ const isActiveSwipeTransition_1 = require("./utils/isActiveSwipeTransition");
14
+ const getDeltaAndProgress_1 = require("./utils/getDeltaAndProgress");
15
+ const SWIPE_SUCCESS_THRESHOLD = 130;
16
+ exports.transitionMachine = (0, xstate_1.setup)({
17
+ types: {
18
+ input: {},
19
+ context: {},
20
+ events: {},
21
+ },
22
+ actors: {
23
+ waitForNextFrame: (0, xstate_1.fromPromise)(() => {
24
+ return new Promise((resolve) => {
25
+ requestAnimationFrame(() => {
26
+ resolve();
27
+ });
28
+ });
29
+ }),
30
+ },
31
+ }).createMachine({
32
+ /** @xstate-layout N4IgpgJg5mDOIC5QBcBOBDAdrAlsnA9pgHToDG+AbmAMQDKA6gJIAKAogPosBKbLAgrwDaABgC6iUAAcCufEUkgAHogBMqgOzEAHAEZdAVm0BmPSIMBOCxoBsAGhABPRABZdx4iI2qLLi9o1jHw0RYwBfMIc0LDlCEnIqWgAVbn4AOTomJKYAeTSOFKYAcSK2blEJJBAZWIUqlQRVGwMdA10rYw19AxttbQdnRpEbYg1-awsRdWMejQMIqIxsPDjiKVQwKXRUHEwoemZ2DjokwSSKxRqVutAGm31PDSftCxnQgyCB13dHnz8AoLWUILEDRZbyEjrTbbXb7RisTgAYXSiLYABkLlUrhDFA0ZhZiKp3ETOkEXF57E5EEFdMQgi9jC5tEYmT0QWDaiQOddMLCDgiuNwckVeHQ6BwAKosAAi-CSbEx0lkPNxiA0LhcxBcIXxIn0IRsGi+CBpdNUL2abimnQs7KWnOI3IhfPhRzYaWliuqypx9UQ-i0vhCUx6TMZRqpCDcHi8PnaNIMGuadpiPOIu1gyCwyA4TrifIgRDA6cwlAIAGti3miCXM9nc-aebCELsy2R0BCKl7sXFVQhbC1VC5TCILLo+pox8bVCJtISrKELG1jCINaoU+DVrAwMhkAAbF1sJJJNGcd2e8SXH29v0IaxaYzGQ0WVSddpdXTG4mjUcuV+BDU-3mEFMAICA4EUatMCvTk+26HR2nUSZVysSlBhcQdfxnbQ-10JkiQ3B0EhwagYJVW9dBsDw9BfHwRBQiw0LUHxRjmRMbHuHoDDGGxCLTKEth2PYyN9W5XENYhdD1Npmnce5R2NYcRhQtp1Q4ywTHCSJQUbCFHV0-NhKxa8bmURBtD1OlhmMfR6OMVDjEUp9PD8VSXHU-wtMWVM9IzLNMBzKDYREm8xIQAxZ1GGxWQXVQPg46dhkJNjGKXEkZ3XbSoOIbddwPIylVgiipJaQwIsfSx7N0Wxp1fYhosNYYXgMf9tF4iIwiAA */
33
+ id: 'transition',
34
+ initial: 'active',
35
+ context: ({ input }) => {
36
+ const { scenes, startScene, relations } = input;
37
+ const transitionScenes = (0, getScenesOnInit_1.getScenesOnInit)(startScene, scenes);
38
+ const availableTransitions = (0, getAvailableTransitions_1.getAvailableTransitions)(startScene, relations);
39
+ return {
40
+ input,
41
+ transitionReady: availableTransitions,
42
+ transition: null,
43
+ scenes: transitionScenes
44
+ };
45
+ },
46
+ states: {
47
+ active: {
48
+ on: {
49
+ SWIPE_PREPARE: {
50
+ target: 'preparing',
51
+ actions: (0, xstate_1.assign)({
52
+ transition: ({ event }) => {
53
+ return {
54
+ stage: 'preparing',
55
+ startX: event.touchData.startX,
56
+ startY: event.touchData.startY,
57
+ };
58
+ }
59
+ })
60
+ },
61
+ TRANSITION_TRIGGER: {
62
+ target: 'instant_transitioning',
63
+ actions: (0, xstate_1.assign)({
64
+ transition: ({ context, event }) => {
65
+ const { scenes } = context;
66
+ const { to, transition } = event;
67
+ const activeScene = scenes[0];
68
+ if (!activeScene) {
69
+ throw new Error('Active scene not found');
70
+ }
71
+ const from = activeScene.id;
72
+ return Object.assign(Object.assign({ stage: 'active', from,
73
+ to }, (transition === 'slide' ? { direction: event.direction } : {})), { type: transition });
74
+ },
75
+ scenes: ({ context, event }) => {
76
+ const { scenes } = context;
77
+ const activeScene = scenes[0];
78
+ if (!activeScene) {
79
+ throw new Error('Active scene not found');
80
+ }
81
+ const { to, transition } = event;
82
+ const newScenes = transition === 'slide'
83
+ ? (0, getScenesOnStart_1.getScenesOnSlideStart)({ from: activeScene.id, to }, { x: 0, y: 0 }, event.direction)
84
+ : (0, getScenesOnStart_1.getScenesOnFadeStart)({ from: activeScene.id, to }, 0);
85
+ return newScenes;
86
+ }
87
+ })
88
+ }
89
+ },
90
+ },
91
+ preparing: {
92
+ on: {
93
+ SWIPE_START: {
94
+ target: 'transitioning',
95
+ actions: (0, xstate_1.assign)({
96
+ transition: ({ context, event }) => {
97
+ const { direction } = event;
98
+ const { input, transition, scenes } = context;
99
+ const activeScene = scenes[0];
100
+ if (!activeScene)
101
+ return null;
102
+ const relation = (0, findRelation_1.findRelation)(input.relations, activeScene.id, direction);
103
+ if (!transition || !('startX' in transition) || !('startY' in transition))
104
+ return null;
105
+ return {
106
+ stage: 'active',
107
+ type: relation.type,
108
+ from: relation.from,
109
+ to: relation.to,
110
+ direction,
111
+ startX: transition === null || transition === void 0 ? void 0 : transition.startX,
112
+ startY: transition === null || transition === void 0 ? void 0 : transition.startY,
113
+ currentX: event.touchData.x,
114
+ currentY: event.touchData.y,
115
+ };
116
+ },
117
+ scenes: ({ context, event }) => {
118
+ const { direction } = event;
119
+ const { input, transition, scenes } = context;
120
+ const activeScene = scenes[0];
121
+ if (!activeScene)
122
+ return context.scenes;
123
+ const relation = (0, findRelation_1.findRelation)(input.relations, activeScene.id, direction);
124
+ if (!transition || !('startX' in transition) || !('startY' in transition))
125
+ return context.scenes;
126
+ const start = { x: transition.startX, y: transition.startY };
127
+ const { deltaX, deltaY, progress } = (0, getDeltaAndProgress_1.getDeltaAndProgress)(event.touchData, start, direction);
128
+ const newScenes = relation.type === 'slide'
129
+ ? (0, getScenesOnStart_1.getScenesOnSlideStart)(relation, { x: deltaX, y: deltaY }, direction)
130
+ : (0, getScenesOnStart_1.getScenesOnFadeStart)(relation, progress);
131
+ return newScenes;
132
+ }
133
+ })
134
+ },
135
+ SWIPE_CANCEL: {
136
+ target: 'active',
137
+ actions: (0, xstate_1.assign)({
138
+ transition: null
139
+ })
140
+ }
141
+ }
142
+ },
143
+ transitioning: {
144
+ on: {
145
+ SWIPE_PROGRESS_UPDATE: {
146
+ actions: (0, xstate_1.assign)({
147
+ transition: ({ context, event }) => {
148
+ const { transition } = context;
149
+ if (!transition || transition.stage !== 'active')
150
+ return null;
151
+ return Object.assign(Object.assign({}, transition), { stage: 'active', currentX: event.touchData.x, currentY: event.touchData.y });
152
+ },
153
+ scenes: ({ context, event }) => {
154
+ const { transition, scenes } = context;
155
+ if (!(0, isActiveSwipeTransition_1.isActiveSwipeTransition)(transition))
156
+ return scenes;
157
+ const start = { x: transition.startX, y: transition.startY };
158
+ const { deltaX, deltaY, progress } = (0, getDeltaAndProgress_1.getDeltaAndProgress)(event.touchData, start, transition.direction);
159
+ const newScenes = transition.type === 'slide'
160
+ ? (0, getScenesOnProgressUpdate_1.getScenesOnSlideProgressUpdate)(scenes, { x: deltaX, y: deltaY })
161
+ : (0, getScenesOnProgressUpdate_1.getScenesOnFadeProgressUpdate)(scenes, transition.to, progress);
162
+ return newScenes;
163
+ }
164
+ })
165
+ },
166
+ SWIPE_END: {
167
+ target: 'settling',
168
+ actions: (0, xstate_1.assign)({
169
+ transition: ({ context }) => {
170
+ const { transition } = context;
171
+ if (!(0, isActiveSwipeTransition_1.isActiveSwipeTransition)(transition))
172
+ return null;
173
+ const transitionSuccess = (0, isTransitionSuccess_1.isTransitionSuccess)(transition, SWIPE_SUCCESS_THRESHOLD);
174
+ return {
175
+ stage: 'settling',
176
+ success: transitionSuccess,
177
+ type: transition.type,
178
+ from: transition.from,
179
+ to: transition.to,
180
+ };
181
+ },
182
+ scenes: ({ context }) => {
183
+ const { transition, scenes } = context;
184
+ if (!(0, isActiveSwipeTransition_1.isActiveSwipeTransition)(transition))
185
+ return scenes;
186
+ const { type } = transition;
187
+ const transitionSuccess = (0, isTransitionSuccess_1.isTransitionSuccess)(transition, SWIPE_SUCCESS_THRESHOLD);
188
+ const newScenes = type === 'slide'
189
+ ? (0, getScenesOnEnd_1.getScenesOnSlideEnd)(scenes, transition, transitionSuccess)
190
+ : (0, getScenesOnEnd_1.getScenesOnFadeEnd)(scenes);
191
+ return newScenes;
192
+ },
193
+ })
194
+ }
195
+ }
196
+ },
197
+ instant_transitioning: {
198
+ invoke: {
199
+ src: 'waitForNextFrame',
200
+ onDone: {
201
+ target: 'settling',
202
+ actions: (0, xstate_1.assign)({
203
+ scenes: ({ context }) => {
204
+ const { transition, scenes } = context;
205
+ if (!transition || transition.stage !== 'active' || !('type' in transition)) {
206
+ return scenes;
207
+ }
208
+ return (0, getScenesOnInstantTransition_1.getScenesOnInstantTransition)(scenes, transition);
209
+ },
210
+ transition: ({ context }) => {
211
+ const { transition } = context;
212
+ if (!transition || transition.stage !== 'active' || !('type' in transition)) {
213
+ return null;
214
+ }
215
+ return {
216
+ stage: 'settling',
217
+ success: true,
218
+ type: transition.type,
219
+ from: transition.from,
220
+ to: transition.to,
221
+ };
222
+ }
223
+ })
224
+ }
225
+ }
226
+ },
227
+ settling: {
228
+ on: {
229
+ SETTLE_END: {
230
+ target: 'active',
231
+ actions: (0, xstate_1.assign)({
232
+ transition: null,
233
+ scenes: ({ context }) => {
234
+ const { transition, scenes } = context;
235
+ if (!transition || transition.stage !== 'settling')
236
+ return scenes;
237
+ const activeScene = scenes.find((s) => {
238
+ const next = transition.success ? transition.to : transition.from;
239
+ return s.id === next;
240
+ });
241
+ if (!activeScene)
242
+ return scenes;
243
+ return [activeScene];
244
+ },
245
+ transitionReady: ({ context }) => {
246
+ const { transition, input: { relations } } = context;
247
+ if (!transition || transition.stage !== 'settling')
248
+ return context.transitionReady;
249
+ const next = transition.success ? transition.to : transition.from;
250
+ const availableTransitions = (0, getAvailableTransitions_1.getAvailableTransitions)(next, relations);
251
+ return availableTransitions;
252
+ }
253
+ })
254
+ }
255
+ }
256
+ }
257
+ },
258
+ });
@@ -0,0 +1,2 @@
1
+ import type { Direction, Relation } from './types';
2
+ export declare function findRelation(relations: Relation[], from: string, direction: Direction): Relation;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.findRelation = findRelation;
4
+ function findRelation(relations, from, direction) {
5
+ const relation = relations.find((r) => r.from === from && r.direction === direction);
6
+ if (!relation) {
7
+ throw new Error(`Relation not found for direction: "${direction}".`);
8
+ }
9
+ return relation;
10
+ }
@@ -0,0 +1,7 @@
1
+ import type { Relation } from './types';
2
+ export declare function getAvailableTransitions(scene: string, relations: Relation[]): {
3
+ north: boolean;
4
+ east: boolean;
5
+ south: boolean;
6
+ west: boolean;
7
+ };
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAvailableTransitions = getAvailableTransitions;
4
+ function getAvailableTransitions(scene, relations) {
5
+ const availableTransitions = {
6
+ north: relations.some((r) => r.from === scene && r.direction === 'north'),
7
+ east: relations.some((r) => r.from === scene && r.direction === 'east'),
8
+ south: relations.some((r) => r.from === scene && r.direction === 'south'),
9
+ west: relations.some((r) => r.from === scene && r.direction === 'west')
10
+ };
11
+ return availableTransitions;
12
+ }
@@ -0,0 +1,2 @@
1
+ import type { Direction } from './types';
2
+ export declare function getAxis(direction: Direction): "horizontal" | "vertical";
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAxis = getAxis;
4
+ function getAxis(direction) {
5
+ return direction === 'east' || direction === 'west' ? 'horizontal' : 'vertical';
6
+ }
@@ -0,0 +1,11 @@
1
+ import type { Direction } from './types';
2
+ export declare function getDeltaAndProgress(current: Delta, start: Delta, direction: Direction): {
3
+ deltaX: number;
4
+ deltaY: number;
5
+ progress: number;
6
+ };
7
+ type Delta = {
8
+ x: number;
9
+ y: number;
10
+ };
11
+ export {};
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDeltaAndProgress = getDeltaAndProgress;
4
+ const getAxis_1 = require("./getAxis");
5
+ function getDeltaAndProgress(current, start, direction) {
6
+ const axis = (0, getAxis_1.getAxis)(direction);
7
+ const deltaX = axis === 'horizontal' ? current.x - start.x : 0;
8
+ const deltaY = axis === 'vertical' ? current.y - start.y : 0;
9
+ const progress = axis === 'horizontal'
10
+ ? Math.abs(deltaX) / window.innerWidth
11
+ : Math.abs(deltaY) / window.innerHeight;
12
+ return { deltaX, deltaY, progress };
13
+ }
@@ -0,0 +1,21 @@
1
+ import type { ActiveTransition, TransitionScene } from './types';
2
+ export declare function getScenesOnSlideEnd(scenes: TransitionScene[], transition: ActiveTransition, success: boolean): {
3
+ styles: {
4
+ x: number;
5
+ y: number;
6
+ startX: number;
7
+ startY: number;
8
+ opacity: number;
9
+ };
10
+ id: string;
11
+ }[];
12
+ export declare function getScenesOnFadeEnd(scenes: TransitionScene[]): {
13
+ styles: {
14
+ opacity: number;
15
+ startX: number;
16
+ startY: number;
17
+ x: number;
18
+ y: number;
19
+ };
20
+ id: string;
21
+ }[];
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getScenesOnSlideEnd = getScenesOnSlideEnd;
4
+ exports.getScenesOnFadeEnd = getScenesOnFadeEnd;
5
+ function getScenesOnSlideEnd(scenes, transition, success) {
6
+ const { from, to, direction } = transition;
7
+ return scenes.map((s) => {
8
+ const isNextActiveScene = success ? s.id === to : s.id === from;
9
+ let prevElX = 0;
10
+ if (direction === 'east') {
11
+ prevElX = success ? -window.innerWidth : window.innerWidth;
12
+ }
13
+ else if (direction === 'west') {
14
+ prevElX = success ? window.innerWidth : -window.innerWidth;
15
+ }
16
+ let prevElY = 0;
17
+ if (direction === 'north') {
18
+ prevElY = success ? window.innerHeight : -window.innerHeight;
19
+ }
20
+ else if (direction === 'south') {
21
+ prevElY = success ? -window.innerHeight : window.innerHeight;
22
+ }
23
+ return Object.assign(Object.assign({}, s), { styles: Object.assign(Object.assign({}, s.styles), { x: isNextActiveScene ? 0 : prevElX, y: isNextActiveScene ? 0 : prevElY }) });
24
+ });
25
+ }
26
+ function getScenesOnFadeEnd(scenes) {
27
+ return scenes.map((s) => {
28
+ return Object.assign(Object.assign({}, s), { styles: Object.assign(Object.assign({}, s.styles), { opacity: 1 }) });
29
+ });
30
+ }
@@ -0,0 +1,6 @@
1
+ import type { TransitionScene } from './types';
2
+ export declare function getScenesOnInit(startScene: string, scenes: Scene[]): TransitionScene[];
3
+ type Scene = {
4
+ id: string;
5
+ };
6
+ export {};
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getScenesOnInit = getScenesOnInit;
4
+ function getScenesOnInit(startScene, scenes) {
5
+ const initialScene = scenes.find((scene) => scene.id === startScene);
6
+ if (!initialScene) {
7
+ throw new Error(`Initial scene not found: ${startScene}`);
8
+ }
9
+ const transitionScene = {
10
+ id: initialScene.id,
11
+ styles: {
12
+ startX: 0,
13
+ startY: 0,
14
+ x: 0,
15
+ y: 0,
16
+ opacity: 1
17
+ }
18
+ };
19
+ return [transitionScene];
20
+ }
@@ -0,0 +1,2 @@
1
+ import type { InstantTransition, TransitionScene } from './types';
2
+ export declare function getScenesOnInstantTransition(scenes: TransitionScene[], transition: InstantTransition): TransitionScene[];
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getScenesOnInstantTransition = getScenesOnInstantTransition;
4
+ function getScenesOnInstantTransition(scenes, transition) {
5
+ const { type, to, direction } = transition;
6
+ if (type === 'slide' && direction) {
7
+ return getScenesOnInstantSlideTransition(scenes, to, direction);
8
+ }
9
+ else if (type === 'fade') {
10
+ return getScenesOnInstantFadeTransition(scenes);
11
+ }
12
+ return scenes;
13
+ }
14
+ function getScenesOnInstantSlideTransition(scenes, to, direction) {
15
+ let fromFinalX = 0;
16
+ let fromFinalY = 0;
17
+ if (direction === 'east') {
18
+ fromFinalX = -window.innerWidth;
19
+ }
20
+ else if (direction === 'west') {
21
+ fromFinalX = window.innerWidth;
22
+ }
23
+ else if (direction === 'north') {
24
+ fromFinalY = window.innerHeight;
25
+ }
26
+ else if (direction === 'south') {
27
+ fromFinalY = -window.innerHeight;
28
+ }
29
+ return scenes.map((scene) => {
30
+ const isToScene = scene.id === to;
31
+ return Object.assign(Object.assign({}, scene), { styles: Object.assign(Object.assign({}, scene.styles), { x: isToScene ? 0 : fromFinalX, y: isToScene ? 0 : fromFinalY }) });
32
+ });
33
+ }
34
+ function getScenesOnInstantFadeTransition(scenes) {
35
+ return scenes.map((scene) => {
36
+ return Object.assign(Object.assign({}, scene), { styles: Object.assign(Object.assign({}, scene.styles), { opacity: 1 }) });
37
+ });
38
+ }
@@ -0,0 +1,26 @@
1
+ import type { TransitionScene } from './types';
2
+ export declare function getScenesOnSlideProgressUpdate(scenes: TransitionScene[], delta: Delta): {
3
+ styles: {
4
+ x: number;
5
+ y: number;
6
+ startX: number;
7
+ startY: number;
8
+ opacity: number;
9
+ };
10
+ id: string;
11
+ }[];
12
+ export declare function getScenesOnFadeProgressUpdate(scenes: TransitionScene[], to: string, progress: number): {
13
+ styles: {
14
+ opacity: number;
15
+ startX: number;
16
+ startY: number;
17
+ x: number;
18
+ y: number;
19
+ };
20
+ id: string;
21
+ }[];
22
+ type Delta = {
23
+ x: number;
24
+ y: number;
25
+ };
26
+ export {};
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getScenesOnSlideProgressUpdate = getScenesOnSlideProgressUpdate;
4
+ exports.getScenesOnFadeProgressUpdate = getScenesOnFadeProgressUpdate;
5
+ const normalizeOpacity_1 = require("./normalizeOpacity");
6
+ function getScenesOnSlideProgressUpdate(scenes, delta) {
7
+ return scenes.map((scene) => (Object.assign(Object.assign({}, scene), { styles: Object.assign(Object.assign({}, scene.styles), { x: scene.styles.startX + delta.x, y: scene.styles.startY + delta.y }) })));
8
+ }
9
+ function getScenesOnFadeProgressUpdate(scenes, to, progress) {
10
+ return scenes.map((scene) => {
11
+ const isNextScene = scene.id === to;
12
+ const value = isNextScene ? progress : 1;
13
+ return Object.assign(Object.assign({}, scene), { styles: Object.assign(Object.assign({}, scene.styles), { opacity: (0, normalizeOpacity_1.normalizeOpacity)(value) }) });
14
+ });
15
+ }
@@ -0,0 +1,21 @@
1
+ import type { Direction, TransitionScene } from './types';
2
+ export declare function getScenesOnFadeStart({ from, to }: FromTo, progress: number): {
3
+ id: string;
4
+ styles: {
5
+ opacity: number;
6
+ startX: number;
7
+ startY: number;
8
+ x: number;
9
+ y: number;
10
+ };
11
+ }[];
12
+ export declare function getScenesOnSlideStart({ from, to }: FromTo, delta: Delta, direction: Direction): TransitionScene[];
13
+ type Delta = {
14
+ x: number;
15
+ y: number;
16
+ };
17
+ type FromTo = {
18
+ from: string;
19
+ to: string;
20
+ };
21
+ export {};
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getScenesOnFadeStart = getScenesOnFadeStart;
4
+ exports.getScenesOnSlideStart = getScenesOnSlideStart;
5
+ const getAxis_1 = require("./getAxis");
6
+ const normalizeOpacity_1 = require("./normalizeOpacity");
7
+ function getScenesOnFadeStart({ from, to }, progress) {
8
+ const common = {
9
+ startX: 0,
10
+ startY: 0,
11
+ x: 0,
12
+ y: 0
13
+ };
14
+ const sceneFrom = {
15
+ id: from,
16
+ styles: Object.assign(Object.assign({}, common), { opacity: 1 })
17
+ };
18
+ const sceneTo = {
19
+ id: to,
20
+ styles: Object.assign(Object.assign({}, common), { opacity: (0, normalizeOpacity_1.normalizeOpacity)(progress) })
21
+ };
22
+ return [sceneFrom, sceneTo];
23
+ }
24
+ function getScenesOnSlideStart({ from, to }, delta, direction) {
25
+ const common = {
26
+ opacity: 1,
27
+ };
28
+ const sceneFrom = {
29
+ id: from,
30
+ styles: Object.assign(Object.assign({}, common), { startX: 0, startY: 0, x: delta.x, y: delta.y })
31
+ };
32
+ const startX = getNextSceneSlideStartX(direction);
33
+ const startY = getNextSceneSlideStartY(direction);
34
+ const sceneTo = {
35
+ id: to,
36
+ styles: Object.assign(Object.assign({}, common), { startX,
37
+ startY, x: startX + delta.x, y: startY + delta.y })
38
+ };
39
+ return [sceneFrom, sceneTo];
40
+ }
41
+ function getNextSceneSlideStartX(direction) {
42
+ const axis = (0, getAxis_1.getAxis)(direction);
43
+ if (axis !== 'horizontal')
44
+ return 0;
45
+ return direction === 'east' ? window.innerWidth : -window.innerWidth;
46
+ }
47
+ function getNextSceneSlideStartY(direction) {
48
+ const axis = (0, getAxis_1.getAxis)(direction);
49
+ if (axis !== 'vertical')
50
+ return 0;
51
+ return direction === 'north' ? -window.innerHeight : window.innerHeight;
52
+ }
@@ -0,0 +1,2 @@
1
+ import type { ActiveTransition, Transition } from './types';
2
+ export declare function isActiveSwipeTransition(transition: Transition | null): transition is ActiveTransition;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isActiveSwipeTransition = isActiveSwipeTransition;
4
+ function isActiveSwipeTransition(transition) {
5
+ return transition !== null
6
+ && transition.stage === 'active'
7
+ && 'startX' in transition
8
+ && 'startY' in transition
9
+ && 'currentX' in transition
10
+ && 'currentY' in transition
11
+ && 'direction' in transition;
12
+ }
@@ -0,0 +1 @@
1
+ export declare function isOverThreshold(delta: number, threshold: number): boolean;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isOverThreshold = isOverThreshold;
4
+ function isOverThreshold(delta, threshold) {
5
+ return Math.abs(delta) > threshold;
6
+ }
@@ -0,0 +1,2 @@
1
+ import type { ActiveTransition } from './types';
2
+ export declare function isTransitionSuccess(transition: ActiveTransition, threshold: number): boolean;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isTransitionSuccess = isTransitionSuccess;
4
+ const getAxis_1 = require("./getAxis");
5
+ const isOverThreshold_1 = require("./isOverThreshold");
6
+ function isTransitionSuccess(transition, threshold) {
7
+ const { currentX, startX, currentY, startY, direction } = transition;
8
+ const deltaX = currentX - startX;
9
+ const deltaY = currentY - startY;
10
+ const axis = (0, getAxis_1.getAxis)(direction);
11
+ const transitionSuccess = axis === 'horizontal'
12
+ ? (0, isOverThreshold_1.isOverThreshold)(deltaX, threshold)
13
+ : (0, isOverThreshold_1.isOverThreshold)(deltaY, threshold);
14
+ return transitionSuccess;
15
+ }
@@ -0,0 +1 @@
1
+ export declare function normalizeOpacity(value: number): number;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeOpacity = normalizeOpacity;
4
+ // normalize opacity to ensure that the value is within CSS acceptable range
5
+ // and tune the range slightly to make sure transitionEnd gets fired
6
+ function normalizeOpacity(value) {
7
+ return Math.max(0.01, Math.min(0.99, value));
8
+ }