@vnejs/plugins.canvas.child.fill 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.
- package/dist/modules/state.d.ts +5 -5
- package/dist/modules/state.js +9 -9
- package/package.json +1 -1
- package/src/modules/state.ts +12 -17
package/dist/modules/state.d.ts
CHANGED
|
@@ -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
|
}
|
package/dist/modules/state.js
CHANGED
|
@@ -12,15 +12,15 @@ 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
|
-
const clonedState =
|
|
23
|
+
const clonedState = structuredClone(this.getStateSlice(payload));
|
|
24
24
|
const oldFillsByLayer = this.state.fills.reduce(this.getFillsByLayerFromState, {});
|
|
25
25
|
const newFillsByLayer = clonedState.fills.reduce(this.getFillsByLayerFromState, {});
|
|
26
26
|
const [promises, uniqLayers, oldLayers, newLayers] = [
|
|
@@ -46,17 +46,18 @@ 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));
|
|
52
56
|
this.shared.viewForceAnimationSources.rm(`${this.name}.clear`);
|
|
53
57
|
};
|
|
54
|
-
cloneFillAndChange = async (fill) => this.emitEventWithFill(
|
|
55
|
-
cloneFillAndHide = async (fill) => this.emitEventWithFill(
|
|
56
|
-
cloneFillAndShow = async (fill) => this.emitEventWithFill(
|
|
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);
|
|
58
|
+
cloneFillAndChange = async (fill) => this.emitEventWithFill(structuredClone(fill), this.emitFillChange);
|
|
59
|
+
cloneFillAndHide = async (fill) => this.emitEventWithFill(structuredClone(fill), this.emitFillHide);
|
|
60
|
+
cloneFillAndShow = async (fill) => this.emitEventWithFill(structuredClone(fill), this.emitFillShow);
|
|
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
package/src/modules/state.ts
CHANGED
|
@@ -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,10 +30,8 @@ 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
|
-
const clonedState =
|
|
34
|
+
const clonedState = structuredClone(this.getStateSlice(payload));
|
|
35
35
|
|
|
36
36
|
const oldFillsByLayer = this.state.fills.reduce(this.getFillsByLayerFromState, {} as Record<string, FillRecord[]>);
|
|
37
37
|
const newFillsByLayer = clonedState.fills.reduce(this.getFillsByLayerFromState, {} as Record<string, FillRecord[]>);
|
|
@@ -65,30 +65,25 @@ export class LayerFillState extends ModuleCore<FillPluginEvents, FillPluginConst
|
|
|
65
65
|
|
|
66
66
|
onStateClear = () => this.clearState();
|
|
67
67
|
|
|
68
|
-
|
|
69
|
-
this.shared.viewForceAnimationSources.add(`${this.name}.clear`);
|
|
70
|
-
await Promise.all(this.state.fills.map(this.cloneFillAndHide));
|
|
71
|
-
this.shared.viewForceAnimationSources.rm(`${this.name}.clear`);
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
cloneFillAndChange = async (fill: FillRecord) => this.emitEventWithFill(await this.emitClone<FillRecord>(fill), this.emitFillChange);
|
|
75
|
-
|
|
76
|
-
cloneFillAndHide = async (fill: FillRecord) => this.emitEventWithFill(await this.emitClone<FillRecord>(fill), this.emitFillHide);
|
|
77
|
-
|
|
78
|
-
cloneFillAndShow = async (fill: FillRecord) => this.emitEventWithFill(await this.emitClone<FillRecord>(fill), this.emitFillShow);
|
|
68
|
+
getDefaultState = (): FillState => ({ fills: [] });
|
|
79
69
|
|
|
80
70
|
emitFillChange = (fill: FillRecord) => this.emit(this.EVENTS.LAYER_FILL.CHANGE, { ...fill, duration: 0 });
|
|
81
71
|
emitFillHide = (fill: FillRecord) => this.emit(this.EVENTS.LAYER_FILL.HIDE, fill);
|
|
82
72
|
emitFillShow = (fill: FillRecord) => this.emit(this.EVENTS.LAYER_FILL.SHOW, fill);
|
|
83
73
|
|
|
74
|
+
clearState = async () => {
|
|
75
|
+
this.shared.viewForceAnimationSources.add(`${this.name}.clear`);
|
|
76
|
+
await Promise.all(this.state.fills.map(this.cloneFillAndHide));
|
|
77
|
+
this.shared.viewForceAnimationSources.rm(`${this.name}.clear`);
|
|
78
|
+
};
|
|
79
|
+
cloneFillAndChange = async (fill: FillRecord) => this.emitEventWithFill(structuredClone(fill), this.emitFillChange);
|
|
80
|
+
cloneFillAndHide = async (fill: FillRecord) => this.emitEventWithFill(structuredClone(fill), this.emitFillHide);
|
|
81
|
+
cloneFillAndShow = async (fill: FillRecord) => this.emitEventWithFill(structuredClone(fill), this.emitFillShow);
|
|
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
|
}
|