@vnejs/plugins.canvas.child.bg 0.2.3 → 0.2.5

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.
@@ -1,10 +1,10 @@
1
1
  import { ModuleCore } from "@vnejs/module.core";
2
+ import type { BgChangePayload } from "@vnejs/contracts.canvas.child.bg";
2
3
  import type { BgPluginConstants, BgPluginEvents, BgPluginParams, BgPluginSettings } from "../types.js";
3
- import type { BgChangePayload } from "../utils/bg.js";
4
4
  export declare class LayerBgChange extends ModuleCore<BgPluginEvents, BgPluginConstants, BgPluginSettings, BgPluginParams> {
5
5
  name: string;
6
6
  subscribe: () => void;
7
- onBgChange: ({ id, name, layer, duration, args }?: BgChangePayload) => Promise<unknown[] | undefined>;
7
+ onBgChange: ({ id, name, layer, duration, args }?: BgChangePayload) => Promise<import("@vnejs/shared").EmitResults<"vne:interact:push_pop"> | undefined>;
8
8
  getBgId: (id: string | undefined, layer: string) => Promise<string>;
9
- emitChildChange: (layer: string, childId: string, duration: number, props: Record<string, unknown>) => Promise<unknown[]> | undefined;
9
+ emitChildChange: (layer: string, childId: string, duration: number, props: Record<string, unknown>) => Promise<import("@vnejs/shared").EmitResults<"vne:layer:child_change">> | undefined;
10
10
  }
@@ -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) => {
@@ -1,10 +1,11 @@
1
1
  import { ModuleCore } from "@vnejs/module.core";
2
2
  import type { BgPluginConstants, BgPluginEvents, BgPluginParams, BgPluginSettings } from "../types.js";
3
- import type { BgHidePayload, TransitionProps } from "../utils/bg.js";
3
+ import type { BgHidePayload } from "@vnejs/contracts.canvas.child.bg";
4
+ import type { TransitionProps } from "../utils/bg.js";
4
5
  export declare class LayerBgHide extends ModuleCore<BgPluginEvents, BgPluginConstants, BgPluginSettings, BgPluginParams> {
5
6
  name: string;
6
7
  subscribe: () => void;
7
8
  onBgHide: ({ layer, transition, duration }?: BgHidePayload) => Promise<void>;
8
9
  getTransitionProps: (transition: string, duration: number) => TransitionProps;
9
- emitStateRm: (id: string) => Promise<unknown[]> | undefined;
10
+ emitStateRm: (id: string) => Promise<import("@vnejs/shared").EmitResults<"vne:layer_bg:state_rm">> | undefined;
10
11
  }
@@ -1,9 +1,9 @@
1
1
  import { ModuleCore } from "@vnejs/module.core";
2
+ import type { BgPreloadPayload } from "@vnejs/contracts.canvas.child.bg";
2
3
  import type { BgPluginConstants, BgPluginEvents, BgPluginParams, BgPluginSettings } from "../types.js";
3
- import type { BgPreloadPayload } from "../utils/bg.js";
4
4
  export declare class LayerBgPreload extends ModuleCore<BgPluginEvents, BgPluginConstants, BgPluginSettings, BgPluginParams> {
5
5
  name: string;
6
6
  subscribe: () => void;
7
- onPreload: ({ name, mediaType, priority, overlays }?: BgPreloadPayload) => Promise<unknown[] | undefined>;
8
- loadMedia: (name: string, args: Record<string, unknown>) => Promise<unknown[]> | undefined;
7
+ onPreload: ({ name, mediaType, priority, overlays }?: BgPreloadPayload) => Promise<(import("@vnejs/shared").EmitResults<"vne:media:load"> | undefined)[] | import("@vnejs/shared").EmitResults<"vne:media:load"> | undefined>;
8
+ loadMedia: (name: string, args: Record<string, unknown>) => Promise<import("@vnejs/shared").EmitResults<"vne:media:load">> | undefined;
9
9
  }
@@ -1,10 +1,11 @@
1
1
  import { ModuleCore } from "@vnejs/module.core";
2
+ import type { BgShowPayload } from "@vnejs/contracts.canvas.child.bg";
2
3
  import type { BgPluginConstants, BgPluginEvents, BgPluginParams, BgPluginSettings } from "../types.js";
3
- import type { BgShowPayload, TransitionProps } from "../utils/bg.js";
4
+ import type { TransitionProps } from "../utils/bg.js";
4
5
  export declare class LayerBgShow extends ModuleCore<BgPluginEvents, BgPluginConstants, BgPluginSettings, BgPluginParams> {
5
6
  name: string;
6
7
  subscribe: () => void;
7
- onBgShow: ({ name, layer, transition, duration, args, hideOldBgsOnShow }?: BgShowPayload) => Promise<[...(unknown[] | undefined)[], unknown[] | undefined] | undefined>;
8
+ onBgShow: ({ name, layer, transition, duration, args, hideOldBgsOnShow }?: BgShowPayload) => Promise<[...(import("@vnejs/shared").EmitResults<"vne:layer_bg:state_rm"> | undefined)[], import("@vnejs/shared").EmitResults<"vne:layer:childs_rm"> | undefined] | undefined>;
8
9
  getTransitionProps: (transition: string, duration: number) => TransitionProps;
9
- emitStateRm: (id: string) => Promise<unknown[]> | undefined;
10
+ emitStateRm: (id: string) => Promise<import("@vnejs/shared").EmitResults<"vne:layer_bg:state_rm">> | undefined;
10
11
  }
@@ -1,6 +1,6 @@
1
1
  import { ModuleCore } from "@vnejs/module.core";
2
+ import type { BgSrcGetPayload } from "@vnejs/contracts.canvas.child.bg";
2
3
  import type { BgPluginConstants, BgPluginEvents, BgPluginParams, BgPluginSettings } from "../types.js";
3
- import type { BgSrcGetPayload } from "../utils/bg.js";
4
4
  export declare class LayerBgStaff extends ModuleCore<BgPluginEvents, BgPluginConstants, BgPluginSettings, BgPluginParams> {
5
5
  name: string;
6
6
  subscribe: () => void;
@@ -1,6 +1,6 @@
1
1
  import { ModuleCore, type ModuleGlobalStateRegistry } from "@vnejs/module.core";
2
2
  import type { BgPluginConstants, BgPluginEvents, BgPluginParams, BgPluginSettings } from "../types.js";
3
- import type { BgRecord, BgState, BgStateIdPayload, BgStateLayerPayload } from "../utils/bg.js";
3
+ import type { BgRecord, BgState, BgStateIdPayload, BgStateLayerPayload } from "@vnejs/contracts.canvas.child.bg";
4
4
  export declare class LayerBgState extends ModuleCore<BgPluginEvents, BgPluginConstants, BgPluginSettings, BgPluginParams, BgState> {
5
5
  name: string;
6
6
  subscribe: () => void;
@@ -11,19 +11,19 @@ export declare class LayerBgState extends ModuleCore<BgPluginEvents, BgPluginCon
11
11
  onBgStateRm: ({ id }?: BgStateIdPayload) => void;
12
12
  onStateSet: (payload: ModuleGlobalStateRegistry) => Promise<void>;
13
13
  onStateClear: () => Promise<void>;
14
- onStatePreload: ({ [this.name]: state }: Record<string, BgState>) => Promise<(unknown[] | undefined)[]>;
14
+ onStatePreload: ({ [this.name]: state }: Record<string, BgState>) => Promise<(import("@vnejs/shared").EmitResults<"vne:layer_bg:src_get"> | undefined)[]>;
15
15
  onMemoryCleared: () => Promise<void>;
16
16
  clearState: () => Promise<void>;
17
- preloadState: (state: BgState) => Promise<(unknown[] | undefined)[]>;
17
+ preloadState: (state: BgState) => Promise<(import("@vnejs/shared").EmitResults<"vne:layer_bg:src_get"> | undefined)[]>;
18
18
  cloneBgAndChangeWithNewId: (bg: BgRecord, id: string) => Promise<unknown>;
19
19
  cloneBgAndChange: (bg: BgRecord) => Promise<unknown>;
20
20
  cloneBgAndHide: (bg: BgRecord) => Promise<unknown>;
21
21
  cloneBgAndShow: (bg: BgRecord) => Promise<unknown>;
22
22
  emitEventWithBg: (bg: BgRecord, cb: (bg: BgRecord) => unknown) => unknown;
23
- emitBgSrcGet: (bg: BgRecord) => Promise<unknown[]> | undefined;
24
- emitBgChange: (bg: BgRecord) => Promise<unknown[]> | undefined;
25
- emitBgHide: (bg: BgRecord) => Promise<unknown[]> | undefined;
26
- emitBgShow: (bg: BgRecord) => Promise<unknown[]> | undefined;
23
+ emitBgSrcGet: (bg: BgRecord) => Promise<import("@vnejs/shared").EmitResults<"vne:layer_bg:src_get">> | undefined;
24
+ emitBgChange: (bg: BgRecord) => Promise<import("@vnejs/shared").EmitResults<"vne:layer_bg:change">> | undefined;
25
+ emitBgHide: (bg: BgRecord) => Promise<import("@vnejs/shared").EmitResults<"vne:layer_bg:hide">> | undefined;
26
+ emitBgShow: (bg: BgRecord) => Promise<import("@vnejs/shared").EmitResults<"vne:layer_bg:show">> | undefined;
27
27
  getBgsByLayerFromState: (acc: Record<string, BgRecord[]>, img: BgRecord) => Record<string, BgRecord[]>;
28
28
  getDefaultState: () => BgState;
29
29
  }
@@ -1,56 +1,5 @@
1
- import type { BgArgs, BgPreloadPayload } from "@vnejs/contracts.canvas.child.bg";
2
- export type { BgArgs, BgPreloadPayload };
3
- export type BgArgsInject = Partial<BgArgs>;
4
- export type BgArgsInjectPayload = {
5
- args?: BgArgs;
6
- };
1
+ import type { BgArgs, BgArgsInject } from "@vnejs/contracts.canvas.child.bg";
7
2
  export declare const applyArgsInjections: (base: BgArgs, injections: BgArgsInject[]) => BgArgs;
8
- export type BgRecord = {
9
- id: string;
10
- name?: string;
11
- layer?: string;
12
- args?: BgArgs;
13
- transition?: string;
14
- duration?: number;
15
- hideOldBgsOnShow?: boolean;
16
- };
17
- export type BgState = {
18
- bgs: BgRecord[];
19
- };
20
- export type BgShowPayload = {
21
- name?: string;
22
- layer?: string;
23
- transition?: string;
24
- duration?: number;
25
- args?: BgArgs;
26
- hideOldBgsOnShow?: boolean;
27
- };
28
- export type BgHidePayload = {
29
- layer?: string;
30
- transition?: string;
31
- duration?: number;
32
- };
33
- export type BgChangePayload = {
34
- id?: string;
35
- name?: string;
36
- layer?: string;
37
- duration?: number;
38
- args?: BgArgs;
39
- };
40
- export type BgSrcGetPayload = {
41
- name?: string;
42
- layer?: string;
43
- args?: BgArgs;
44
- };
45
- export type BgStateLayerPayload = {
46
- layer?: string;
47
- };
48
- export type BgStateIdPayload = {
49
- id?: string;
50
- name?: string;
51
- layer?: string;
52
- args?: BgArgs;
53
- };
54
3
  export type TransitionProps = {
55
4
  initialProps?: Record<string, unknown>;
56
5
  finishProps?: Record<string, unknown>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.canvas.child.bg",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,8 +1,9 @@
1
1
  import { createPromiseResolve } from "@vnejs/helpers";
2
2
  import { ModuleCore } from "@vnejs/module.core";
3
3
 
4
+ import type { BgArgs, BgChangePayload, BgRecord } from "@vnejs/contracts.canvas.child.bg";
5
+
4
6
  import type { BgPluginConstants, BgPluginEvents, BgPluginParams, BgPluginSettings } from "../types.js";
5
- import type { BgArgs, BgChangePayload, BgRecord } from "../utils/bg.js";
6
7
 
7
8
  export class LayerBgChange extends ModuleCore<BgPluginEvents, BgPluginConstants, BgPluginSettings, BgPluginParams> {
8
9
  name = "layer.bg.change";
@@ -28,12 +29,15 @@ export class LayerBgChange extends ModuleCore<BgPluginEvents, BgPluginConstants,
28
29
 
29
30
  if (!duration || this.shared.viewForceAnimationSources.isNotEmpty()) return this.emitChildChange(layer, realId, 0, { ...changeArgs, transition: 0 });
30
31
 
32
+ const durationMs = Number(duration);
31
33
  const { resolve: skipResolve, promise: skipPromise } = createPromiseResolve();
32
34
 
35
+ await this.emitChildChange(layer, realId, 0, { transition: durationMs });
36
+
33
37
  return this.emit(this.EVENTS.INTERACT.PUSH_POP, {
34
38
  key: `${this.name}_${layer}_${name}`,
35
39
  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]),
40
+ handler: () => Promise.race([this.emitChildChange(layer, realId, durationMs, { ...changeArgs, transition: durationMs }), skipPromise]),
37
41
  });
38
42
  };
39
43
 
@@ -2,7 +2,9 @@ import { createPromiseResolve } from "@vnejs/helpers";
2
2
  import { ModuleCore } from "@vnejs/module.core";
3
3
 
4
4
  import type { BgPluginConstants, BgPluginEvents, BgPluginParams, BgPluginSettings } from "../types.js";
5
- import type { BgHidePayload, BgStateIdPayload, TransitionProps } from "../utils/bg.js";
5
+ import type { BgHidePayload, BgStateIdPayload } from "@vnejs/contracts.canvas.child.bg";
6
+
7
+ import type { TransitionProps } from "../utils/bg.js";
6
8
 
7
9
  export class LayerBgHide extends ModuleCore<BgPluginEvents, BgPluginConstants, BgPluginSettings, BgPluginParams> {
8
10
  name = "layer.bg.hide";
@@ -1,7 +1,8 @@
1
1
  import { ModuleCore } from "@vnejs/module.core";
2
2
 
3
+ import type { BgPreloadPayload } from "@vnejs/contracts.canvas.child.bg";
4
+
3
5
  import type { BgPluginConstants, BgPluginEvents, BgPluginParams, BgPluginSettings } from "../types.js";
4
- import type { BgPreloadPayload } from "../utils/bg.js";
5
6
 
6
7
  export class LayerBgPreload extends ModuleCore<BgPluginEvents, BgPluginConstants, BgPluginSettings, BgPluginParams> {
7
8
  name = "layer.bg.preload";
@@ -1,8 +1,10 @@
1
1
  import { createPromiseResolve } from "@vnejs/helpers";
2
2
  import { ModuleCore } from "@vnejs/module.core";
3
3
 
4
+ import type { BgArgs, BgShowPayload, BgStateIdPayload } from "@vnejs/contracts.canvas.child.bg";
5
+
4
6
  import type { BgPluginConstants, BgPluginEvents, BgPluginParams, BgPluginSettings } from "../types.js";
5
- import type { BgArgs, BgShowPayload, BgStateIdPayload, TransitionProps } from "../utils/bg.js";
7
+ import type { TransitionProps } from "../utils/bg.js";
6
8
 
7
9
  export class LayerBgShow extends ModuleCore<BgPluginEvents, BgPluginConstants, BgPluginSettings, BgPluginParams> {
8
10
  name = "layer.bg.show";
@@ -1,7 +1,8 @@
1
1
  import { ModuleCore } from "@vnejs/module.core";
2
2
 
3
+ import type { BgArgs, BgArgsInject, BgSrcGetPayload } from "@vnejs/contracts.canvas.child.bg";
4
+
3
5
  import type { BgPluginConstants, BgPluginEvents, BgPluginParams, BgPluginSettings } from "../types.js";
4
- import type { BgArgs, BgArgsInject, BgSrcGetPayload } from "../utils/bg.js";
5
6
  import { applyArgsInjections } from "../utils/bg.js";
6
7
 
7
8
  const mediaToSrcs = (q: { src: string }) => ({ url: q.src });
@@ -1,7 +1,7 @@
1
1
  import { ModuleCore, type ModuleGlobalStateRegistry } from "@vnejs/module.core";
2
2
 
3
3
  import type { BgPluginConstants, BgPluginEvents, BgPluginParams, BgPluginSettings } from "../types.js";
4
- import type { BgRecord, BgState, BgStateIdPayload, BgStateLayerPayload } from "../utils/bg.js";
4
+ import type { BgRecord, BgState, BgStateIdPayload, BgStateLayerPayload } from "@vnejs/contracts.canvas.child.bg";
5
5
 
6
6
  export class LayerBgState extends ModuleCore<BgPluginEvents, BgPluginConstants, BgPluginSettings, BgPluginParams, BgState> {
7
7
  name = "layer.bg.state";
@@ -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
+ });
package/src/utils/bg.ts CHANGED
@@ -1,12 +1,4 @@
1
- import type { BgArgs, BgPreloadPayload } from "@vnejs/contracts.canvas.child.bg";
2
-
3
- export type { BgArgs, BgPreloadPayload };
4
-
5
- export type BgArgsInject = Partial<BgArgs>;
6
-
7
- export type BgArgsInjectPayload = {
8
- args?: BgArgs;
9
- };
1
+ import type { BgArgs, BgArgsInject } from "@vnejs/contracts.canvas.child.bg";
10
2
 
11
3
  export const applyArgsInjections = (base: BgArgs, injections: BgArgsInject[]): BgArgs =>
12
4
  injections.reduce(
@@ -18,60 +10,6 @@ export const applyArgsInjections = (base: BgArgs, injections: BgArgsInject[]): B
18
10
  base,
19
11
  );
20
12
 
21
- export type BgRecord = {
22
- id: string;
23
- name?: string;
24
- layer?: string;
25
- args?: BgArgs;
26
- transition?: string;
27
- duration?: number;
28
- hideOldBgsOnShow?: boolean;
29
- };
30
-
31
- export type BgState = {
32
- bgs: BgRecord[];
33
- };
34
-
35
- export type BgShowPayload = {
36
- name?: string;
37
- layer?: string;
38
- transition?: string;
39
- duration?: number;
40
- args?: BgArgs;
41
- hideOldBgsOnShow?: boolean;
42
- };
43
-
44
- export type BgHidePayload = {
45
- layer?: string;
46
- transition?: string;
47
- duration?: number;
48
- };
49
-
50
- export type BgChangePayload = {
51
- id?: string;
52
- name?: string;
53
- layer?: string;
54
- duration?: number;
55
- args?: BgArgs;
56
- };
57
-
58
- export type BgSrcGetPayload = {
59
- name?: string;
60
- layer?: string;
61
- args?: BgArgs;
62
- };
63
-
64
- export type BgStateLayerPayload = {
65
- layer?: string;
66
- };
67
-
68
- export type BgStateIdPayload = {
69
- id?: string;
70
- name?: string;
71
- layer?: string;
72
- args?: BgArgs;
73
- };
74
-
75
13
  export type TransitionProps = {
76
14
  initialProps?: Record<string, unknown>;
77
15
  finishProps?: Record<string, unknown>;