@vnejs/plugins.canvas.child.fill 0.2.3 → 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.
@@ -5,19 +5,19 @@ export declare class LayerFillState extends ModuleCore<FillPluginEvents, FillPlu
5
5
  name: string;
6
6
  subscribe: () => void;
7
7
  onFillStateUpdate: ({ id, ...fill }?: FillStateIdPayload) => void;
8
+ onFillStateGet: ({ id }?: FillStateIdPayload) => FillRecord | undefined;
8
9
  onFillStateAdd: ({ id, layer, color }?: FillStateIdPayload) => void;
9
10
  onFillStateRm: ({ id }?: FillStateIdPayload) => void;
10
- onFillStateGet: ({ id }?: FillStateIdPayload) => FillRecord | undefined;
11
11
  onStateSet: (payload: ModuleGlobalStateRegistry) => Promise<void>;
12
12
  onStateClear: () => Promise<void>;
13
+ getDefaultState: () => FillState;
14
+ emitFillChange: (fill: FillRecord) => Promise<import("@vnejs/shared").EmitResults<"vne:layer_fill:change">> | undefined;
15
+ emitFillHide: (fill: FillRecord) => Promise<import("@vnejs/shared").EmitResults<"vne:layer_fill:hide">> | undefined;
16
+ emitFillShow: (fill: FillRecord) => Promise<import("@vnejs/shared").EmitResults<"vne:layer_fill:show">> | undefined;
13
17
  clearState: () => Promise<void>;
14
18
  cloneFillAndChange: (fill: FillRecord) => Promise<unknown>;
15
19
  cloneFillAndHide: (fill: FillRecord) => Promise<unknown>;
16
20
  cloneFillAndShow: (fill: FillRecord) => Promise<unknown>;
17
- emitFillChange: (fill: FillRecord) => Promise<import("@vnejs/shared").EmitResults<"vne:layer_fill:change">> | undefined;
18
- emitFillHide: (fill: FillRecord) => Promise<import("@vnejs/shared").EmitResults<"vne:layer_fill:hide">> | undefined;
19
- emitFillShow: (fill: FillRecord) => Promise<import("@vnejs/shared").EmitResults<"vne:layer_fill:show">> | undefined;
20
21
  emitEventWithFill: (fill: FillRecord, cb: (fill: FillRecord) => unknown) => unknown;
21
22
  getFillsByLayerFromState: (acc: Record<string, FillRecord[]>, fill: FillRecord) => Record<string, FillRecord[]>;
22
- getDefaultState: () => FillState;
23
23
  }
@@ -12,13 +12,13 @@ export class LayerFillState extends ModuleCore {
12
12
  onFillStateUpdate = ({ id, ...fill } = {}) => {
13
13
  this.state.fills = this.state.fills.map((item) => (item.id === id ? { ...item, ...fill } : item));
14
14
  };
15
+ onFillStateGet = ({ id } = {}) => this.state.fills.find((item) => item.id === id);
15
16
  onFillStateAdd = ({ id, layer, color } = {}) => {
16
17
  this.state.fills.push({ id: id, layer, color });
17
18
  };
18
19
  onFillStateRm = ({ id } = {}) => {
19
20
  this.state.fills = this.state.fills.filter((item) => item.id !== id);
20
21
  };
21
- onFillStateGet = ({ id } = {}) => this.state.fills.find((item) => item.id === id);
22
22
  onStateSet = async (payload) => {
23
23
  const clonedState = structuredClone(this.getStateSlice(payload));
24
24
  const oldFillsByLayer = this.state.fills.reduce(this.getFillsByLayerFromState, {});
@@ -46,6 +46,10 @@ export class LayerFillState extends ModuleCore {
46
46
  this.shared.viewForceAnimationSources.rm(`${this.name}.set`);
47
47
  };
48
48
  onStateClear = () => this.clearState();
49
+ getDefaultState = () => ({ fills: [] });
50
+ emitFillChange = (fill) => this.emit(this.EVENTS.LAYER_FILL.CHANGE, { ...fill, duration: 0 });
51
+ emitFillHide = (fill) => this.emit(this.EVENTS.LAYER_FILL.HIDE, fill);
52
+ emitFillShow = (fill) => this.emit(this.EVENTS.LAYER_FILL.SHOW, fill);
49
53
  clearState = async () => {
50
54
  this.shared.viewForceAnimationSources.add(`${this.name}.clear`);
51
55
  await Promise.all(this.state.fills.map(this.cloneFillAndHide));
@@ -54,9 +58,6 @@ export class LayerFillState extends ModuleCore {
54
58
  cloneFillAndChange = async (fill) => this.emitEventWithFill(structuredClone(fill), this.emitFillChange);
55
59
  cloneFillAndHide = async (fill) => this.emitEventWithFill(structuredClone(fill), this.emitFillHide);
56
60
  cloneFillAndShow = async (fill) => this.emitEventWithFill(structuredClone(fill), this.emitFillShow);
57
- emitFillChange = (fill) => this.emit(this.EVENTS.LAYER_FILL.CHANGE, { ...fill, duration: 0 });
58
- emitFillHide = (fill) => this.emit(this.EVENTS.LAYER_FILL.HIDE, fill);
59
- emitFillShow = (fill) => this.emit(this.EVENTS.LAYER_FILL.SHOW, fill);
60
61
  emitEventWithFill = (fill, cb) => cb(fill);
61
62
  getFillsByLayerFromState = (acc, fill) => {
62
63
  if (!acc[fill.layer])
@@ -64,5 +65,4 @@ export class LayerFillState extends ModuleCore {
64
65
  acc[fill.layer].push(fill);
65
66
  return acc;
66
67
  };
67
- getDefaultState = () => ({ fills: [] });
68
68
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.canvas.child.fill",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -20,6 +20,8 @@ export class LayerFillState extends ModuleCore<FillPluginEvents, FillPluginConst
20
20
  this.state.fills = this.state.fills.map((item) => (item.id === id ? { ...item, ...fill } : item));
21
21
  };
22
22
 
23
+ onFillStateGet = ({ id }: FillStateIdPayload = {}) => this.state.fills.find((item) => item.id === id);
24
+
23
25
  onFillStateAdd = ({ id, layer, color }: FillStateIdPayload = {}) => {
24
26
  this.state.fills.push({ id: id!, layer, color });
25
27
  };
@@ -28,8 +30,6 @@ export class LayerFillState extends ModuleCore<FillPluginEvents, FillPluginConst
28
30
  this.state.fills = this.state.fills.filter((item) => item.id !== id);
29
31
  };
30
32
 
31
- onFillStateGet = ({ id }: FillStateIdPayload = {}) => this.state.fills.find((item) => item.id === id);
32
-
33
33
  onStateSet = async (payload: ModuleGlobalStateRegistry) => {
34
34
  const clonedState = structuredClone(this.getStateSlice(payload));
35
35
 
@@ -65,30 +65,25 @@ export class LayerFillState extends ModuleCore<FillPluginEvents, FillPluginConst
65
65
 
66
66
  onStateClear = () => this.clearState();
67
67
 
68
+ getDefaultState = (): FillState => ({ fills: [] });
69
+
70
+ emitFillChange = (fill: FillRecord) => this.emit(this.EVENTS.LAYER_FILL.CHANGE, { ...fill, duration: 0 });
71
+ emitFillHide = (fill: FillRecord) => this.emit(this.EVENTS.LAYER_FILL.HIDE, fill);
72
+ emitFillShow = (fill: FillRecord) => this.emit(this.EVENTS.LAYER_FILL.SHOW, fill);
73
+
68
74
  clearState = async () => {
69
75
  this.shared.viewForceAnimationSources.add(`${this.name}.clear`);
70
76
  await Promise.all(this.state.fills.map(this.cloneFillAndHide));
71
77
  this.shared.viewForceAnimationSources.rm(`${this.name}.clear`);
72
78
  };
73
-
74
79
  cloneFillAndChange = async (fill: FillRecord) => this.emitEventWithFill(structuredClone(fill), this.emitFillChange);
75
-
76
80
  cloneFillAndHide = async (fill: FillRecord) => this.emitEventWithFill(structuredClone(fill), this.emitFillHide);
77
-
78
81
  cloneFillAndShow = async (fill: FillRecord) => this.emitEventWithFill(structuredClone(fill), this.emitFillShow);
79
-
80
- emitFillChange = (fill: FillRecord) => this.emit(this.EVENTS.LAYER_FILL.CHANGE, { ...fill, duration: 0 });
81
- emitFillHide = (fill: FillRecord) => this.emit(this.EVENTS.LAYER_FILL.HIDE, fill);
82
- emitFillShow = (fill: FillRecord) => this.emit(this.EVENTS.LAYER_FILL.SHOW, fill);
83
-
84
82
  emitEventWithFill = (fill: FillRecord, cb: (fill: FillRecord) => unknown) => cb(fill);
85
-
86
83
  getFillsByLayerFromState = (acc: Record<string, FillRecord[]>, fill: FillRecord) => {
87
84
  if (!acc[fill.layer!]) acc[fill.layer!] = [];
88
85
  acc[fill.layer!].push(fill);
89
86
 
90
87
  return acc;
91
88
  };
92
-
93
- getDefaultState = (): FillState => ({ fills: [] });
94
89
  }