@vnejs/plugins.canvas.child.bg 0.2.2 → 0.2.4

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.
@@ -17,11 +17,13 @@ export class LayerBgChange extends ModuleCore {
17
17
  await this.emit(this.EVENTS.LAYER_BG.STATE_UPDATE, { id: realId, name, args: clonedArgs });
18
18
  if (!duration || this.shared.viewForceAnimationSources.isNotEmpty())
19
19
  return this.emitChildChange(layer, realId, 0, { ...changeArgs, transition: 0 });
20
+ const durationMs = Number(duration);
20
21
  const { resolve: skipResolve, promise: skipPromise } = createPromiseResolve();
22
+ await this.emitChildChange(layer, realId, 0, { transition: durationMs });
21
23
  return this.emit(this.EVENTS.INTERACT.PUSH_POP, {
22
24
  key: `${this.name}_${layer}_${name}`,
23
25
  skipHandler: () => void this.emit(this.EVENTS.LAYER.UPDATE_FORCE, { layer })?.then(skipResolve),
24
- handler: () => Promise.race([this.emitChildChange(layer, realId, Number(duration), { ...changeArgs, transition: duration }), skipPromise]),
26
+ handler: () => Promise.race([this.emitChildChange(layer, realId, durationMs, { ...changeArgs, transition: durationMs }), skipPromise]),
25
27
  });
26
28
  };
27
29
  getBgId = async (id, layer) => {
@@ -22,9 +22,7 @@ export class LayerBgHide extends ModuleCore {
22
22
  };
23
23
  getTransitionProps = (transition, duration) => {
24
24
  const transitions = this.PARAMS.LAYER_BG.TRANSITIONS_HIDE;
25
- return transitions[transition]
26
- ? transitions[transition](duration)
27
- : transitions.opacity(duration);
25
+ return transitions[transition] ? transitions[transition](duration) : transitions.opacity(duration);
28
26
  };
29
27
  emitStateRm = (id) => this.emit(this.EVENTS.LAYER_BG.STATE_RM, { id });
30
28
  }
@@ -28,13 +28,14 @@ export class LayerBgShow extends ModuleCore {
28
28
  await this.emit(this.EVENTS.INTERACT.POP, { key });
29
29
  }
30
30
  if (shouldHideOldImages)
31
- return Promise.all([...oldChildsId.map((childId) => this.emitStateRm(childId)), this.emit(this.EVENTS.LAYER.CHILDS_RM, { layer, childsIds: oldChildsId })]);
31
+ return Promise.all([
32
+ ...oldChildsId.map((childId) => this.emitStateRm(childId)),
33
+ this.emit(this.EVENTS.LAYER.CHILDS_RM, { layer, childsIds: oldChildsId }),
34
+ ]);
32
35
  };
33
36
  getTransitionProps = (transition, duration) => {
34
37
  const transitions = this.PARAMS.LAYER_BG.TRANSITIONS_SHOW;
35
- return transitions[transition]
36
- ? transitions[transition](duration)
37
- : transitions.opacity(duration);
38
+ return transitions[transition] ? transitions[transition](duration) : transitions.opacity(duration);
38
39
  };
39
40
  emitStateRm = (id) => this.emit(this.EVENTS.LAYER_BG.STATE_RM, { id });
40
41
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.canvas.child.bg",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -28,12 +28,15 @@ export class LayerBgChange extends ModuleCore<BgPluginEvents, BgPluginConstants,
28
28
 
29
29
  if (!duration || this.shared.viewForceAnimationSources.isNotEmpty()) return this.emitChildChange(layer, realId, 0, { ...changeArgs, transition: 0 });
30
30
 
31
+ const durationMs = Number(duration);
31
32
  const { resolve: skipResolve, promise: skipPromise } = createPromiseResolve();
32
33
 
34
+ await this.emitChildChange(layer, realId, 0, { transition: durationMs });
35
+
33
36
  return this.emit(this.EVENTS.INTERACT.PUSH_POP, {
34
37
  key: `${this.name}_${layer}_${name}`,
35
38
  skipHandler: () => void this.emit(this.EVENTS.LAYER.UPDATE_FORCE, { layer })?.then(skipResolve),
36
- handler: () => Promise.race([this.emitChildChange(layer, realId, Number(duration), { ...changeArgs, transition: duration }), skipPromise]),
39
+ handler: () => Promise.race([this.emitChildChange(layer, realId, durationMs, { ...changeArgs, transition: durationMs }), skipPromise]),
37
40
  });
38
41
  };
39
42
 
@@ -33,9 +33,7 @@ export class LayerBgHide extends ModuleCore<BgPluginEvents, BgPluginConstants, B
33
33
  getTransitionProps = (transition: string, duration: number): TransitionProps => {
34
34
  const transitions = this.PARAMS.LAYER_BG.TRANSITIONS_HIDE;
35
35
 
36
- return transitions[transition as keyof typeof transitions]
37
- ? transitions[transition as keyof typeof transitions](duration)
38
- : transitions.opacity(duration);
36
+ return transitions[transition as keyof typeof transitions] ? transitions[transition as keyof typeof transitions](duration) : transitions.opacity(duration);
39
37
  };
40
38
 
41
39
  emitStateRm = (id: string) => this.emit(this.EVENTS.LAYER_BG.STATE_RM, { id });
@@ -40,15 +40,16 @@ export class LayerBgShow extends ModuleCore<BgPluginEvents, BgPluginConstants, B
40
40
  }
41
41
 
42
42
  if (shouldHideOldImages)
43
- return Promise.all([...oldChildsId.map((childId) => this.emitStateRm(childId)), this.emit(this.EVENTS.LAYER.CHILDS_RM, { layer, childsIds: oldChildsId })]);
43
+ return Promise.all([
44
+ ...oldChildsId.map((childId) => this.emitStateRm(childId)),
45
+ this.emit(this.EVENTS.LAYER.CHILDS_RM, { layer, childsIds: oldChildsId }),
46
+ ]);
44
47
  };
45
48
 
46
49
  getTransitionProps = (transition: string, duration: number): TransitionProps => {
47
50
  const transitions = this.PARAMS.LAYER_BG.TRANSITIONS_SHOW;
48
51
 
49
- return transitions[transition as keyof typeof transitions]
50
- ? transitions[transition as keyof typeof transitions](duration)
51
- : transitions.opacity(duration);
52
+ return transitions[transition as keyof typeof transitions] ? transitions[transition as keyof typeof transitions](duration) : transitions.opacity(duration);
52
53
  };
53
54
 
54
55
  emitStateRm = (id: string) => this.emit(this.EVENTS.LAYER_BG.STATE_RM, { id });
@@ -87,8 +87,7 @@ export class LayerBgState extends ModuleCore<BgPluginEvents, BgPluginConstants,
87
87
 
88
88
  preloadState = (state: BgState) => Promise.all(state.bgs.map(this.emitBgSrcGet));
89
89
 
90
- cloneBgAndChangeWithNewId = async (bg: BgRecord, id: string) =>
91
- this.emitEventWithBg({ ...(await this.emitClone<BgRecord>(bg)), id }, this.emitBgChange);
90
+ cloneBgAndChangeWithNewId = async (bg: BgRecord, id: string) => this.emitEventWithBg({ ...(await this.emitClone<BgRecord>(bg)), id }, this.emitBgChange);
92
91
 
93
92
  cloneBgAndChange = async (bg: BgRecord) => this.emitEventWithBg(await this.emitClone<BgRecord>(bg), this.emitBgChange);
94
93
 
@@ -0,0 +1,51 @@
1
+ import { beforeEach, describe, expect, it } from "vitest";
2
+
3
+ import { SUBSCRIBE_EVENTS as INTERACT_EVENTS } from "@vnejs/contracts.core.interact";
4
+ import { spyEvent, stubEvent } from "@vnejs/test-utils";
5
+
6
+ import { LayerBgChange } from "../modules/change.js";
7
+ import { createBgTestModule, LAYER_EVENTS, registerBgPluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
8
+
9
+ describe("LayerBgChange", () => {
10
+ beforeEach(() => {
11
+ registerBgPluginVne();
12
+ });
13
+
14
+ it("CHANGE without duration swaps src in one CHILD_CHANGE with transition 0", async () => {
15
+ const { observer } = createBgTestModule(LayerBgChange);
16
+ const childChange = spyEvent(observer, LAYER_EVENTS.CHILD_CHANGE);
17
+
18
+ await observer.emit(SUBSCRIBE_EVENTS.CHANGE, { id: "bg-1", name: "hero", layer: "bl" });
19
+
20
+ expect(childChange).toHaveBeenCalledOnce();
21
+ expect(childChange.mock.calls[0][0]).toMatchObject({
22
+ layer: "bl",
23
+ childId: "bg-1",
24
+ duration: 0,
25
+ props: { src: "hero.png", transition: 0 },
26
+ });
27
+ });
28
+
29
+ it("CHANGE with duration enables transition before swapping src", async () => {
30
+ const { observer } = createBgTestModule(LayerBgChange);
31
+ const childChange = spyEvent(observer, LAYER_EVENTS.CHILD_CHANGE);
32
+
33
+ stubEvent(observer, INTERACT_EVENTS.PUSH_POP, async ({ handler }: { handler?: () => unknown } = {}) => handler?.());
34
+
35
+ await observer.emit(SUBSCRIBE_EVENTS.CHANGE, { id: "bg-1", name: "hero", layer: "bl", duration: 300 });
36
+
37
+ expect(childChange).toHaveBeenCalledTimes(2);
38
+ expect(childChange.mock.calls[0][0]).toMatchObject({
39
+ layer: "bl",
40
+ childId: "bg-1",
41
+ duration: 0,
42
+ props: { transition: 300 },
43
+ });
44
+ expect(childChange.mock.calls[1][0]).toMatchObject({
45
+ layer: "bl",
46
+ childId: "bg-1",
47
+ duration: 300,
48
+ props: { src: "hero.png", transition: 300 },
49
+ });
50
+ });
51
+ });
@@ -8,14 +8,7 @@ import {
8
8
  } from "@vnejs/contracts.canvas.layer";
9
9
  import { CONSTANTS, PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/contracts.canvas.child.bg";
10
10
  import { SourcesSet } from "@vnejs/sources-set";
11
- import {
12
- createTestModule as baseCreateTestModule,
13
- registerCoreVne,
14
- registerVnePlugin,
15
- stubEvent,
16
- stubSilentEvent,
17
- stubVendorEvents,
18
- } from "@vnejs/test-utils";
11
+ import { createTestModule as baseCreateTestModule, registerCoreVne, registerVnePlugin, stubEvent, stubSilentEvent, stubVendorEvents } from "@vnejs/test-utils";
19
12
 
20
13
  export const registerBgPluginVne = () => {
21
14
  registerCoreVne();
package/tsconfig.json CHANGED
@@ -4,12 +4,6 @@
4
4
  "rootDir": "src",
5
5
  "outDir": "dist"
6
6
  },
7
- "include": [
8
- "src/**/*.ts"
9
- ],
10
- "exclude": [
11
- "dist",
12
- "node_modules",
13
- "src/tests"
14
- ]
7
+ "include": ["src/**/*.ts"],
8
+ "exclude": ["dist", "node_modules", "src/tests"]
15
9
  }