@vnejs/plugins.canvas.scale 0.1.1 → 0.1.2
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/index.d.ts +1 -0
- package/dist/index.js +4 -0
- package/dist/modules/scale.d.ts +13 -0
- package/dist/modules/scale.js +25 -0
- package/dist/types.d.ts +6 -0
- package/dist/types.js +1 -0
- package/dist/utils/scale.d.ts +17 -0
- package/dist/utils/scale.js +1 -0
- package/package.json +33 -6
- package/src/index.ts +6 -0
- package/{modules/scale.js → src/modules/scale.ts} +12 -5
- package/src/types.ts +8 -0
- package/src/utils/scale.ts +20 -0
- package/tsconfig.json +9 -0
- package/const/const.js +0 -1
- package/const/events.js +0 -4
- package/index.js +0 -8
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { regPlugin } from "@vnejs/shared";
|
|
2
|
+
import { CONSTANTS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/plugins.canvas.scale.contract";
|
|
3
|
+
import { LayerScale } from "./modules/scale.js";
|
|
4
|
+
regPlugin(PLUGIN_NAME, { constants: CONSTANTS, events: SUBSCRIBE_EVENTS }, [LayerScale]);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Module } from "@vnejs/module";
|
|
2
|
+
import type { ScalePluginConstants, ScalePluginEvents } from "../types.js";
|
|
3
|
+
import type { ScaleSetPayload, ScaleState, ScaleUnsetPayload } from "../utils/scale.js";
|
|
4
|
+
export declare class LayerScale extends Module<ScalePluginEvents, ScalePluginConstants, Record<string, never>, Record<string, never>, ScaleState> {
|
|
5
|
+
name: string;
|
|
6
|
+
subscribe: () => void;
|
|
7
|
+
onScaleSet: ({ layer, value, transformOriginX, transformOriginY, duration }?: ScaleSetPayload) => Promise<unknown[] | undefined>;
|
|
8
|
+
onScaleUnset: ({ layer, duration }?: ScaleUnsetPayload) => Promise<unknown[] | undefined>;
|
|
9
|
+
onStateSet: ({ [this.name]: state }?: Record<string, ScaleState>) => Promise<void>;
|
|
10
|
+
onStateClear: () => Promise<(unknown[] | undefined)[]>;
|
|
11
|
+
emitLayerPropsUpdate: (layer: string, scale: unknown | undefined, transformOriginX: string | undefined, transformOriginY: string | undefined, duration: number) => Promise<unknown[]> | undefined;
|
|
12
|
+
getDefaultState: () => ScaleState;
|
|
13
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Module } from "@vnejs/module";
|
|
2
|
+
export class LayerScale extends Module {
|
|
3
|
+
name = "layer.scale";
|
|
4
|
+
subscribe = () => {
|
|
5
|
+
this.on(this.EVENTS.LAYER_SCALE.SET, this.onScaleSet);
|
|
6
|
+
this.on(this.EVENTS.LAYER_SCALE.UNSET, this.onScaleUnset);
|
|
7
|
+
this.on(this.EVENTS.STATE.SET, this.onStateSet);
|
|
8
|
+
this.on(this.EVENTS.STATE.CLEAR, this.onStateClear);
|
|
9
|
+
};
|
|
10
|
+
onScaleSet = async ({ layer = "", value = "", transformOriginX = "center", transformOriginY = "center", duration = 0 } = {}) => {
|
|
11
|
+
this.state[layer] = { scale: value, transformOriginX, transformOriginY };
|
|
12
|
+
return this.emitLayerPropsUpdate(layer, value, transformOriginX, transformOriginY, duration);
|
|
13
|
+
};
|
|
14
|
+
onScaleUnset = async ({ layer = "", duration = 0 } = {}) => {
|
|
15
|
+
delete this.state[layer];
|
|
16
|
+
return this.emitLayerPropsUpdate(layer, "", "", "", duration);
|
|
17
|
+
};
|
|
18
|
+
onStateSet = async ({ [this.name]: state = {} } = {}) => {
|
|
19
|
+
await Promise.all(Object.keys(this.state).map((layer) => this.emit(this.EVENTS.LAYER_SCALE.UNSET, { layer, duration: 0 })));
|
|
20
|
+
await Promise.all(Object.keys(state).map((layer) => this.emit(this.EVENTS.LAYER_SCALE.SET, { ...state[layer], layer, duration: 0 })));
|
|
21
|
+
};
|
|
22
|
+
onStateClear = () => Promise.all(Object.keys(this.state).map((layer) => this.emit(this.EVENTS.LAYER_SCALE.UNSET, { layer, duration: 0 })));
|
|
23
|
+
emitLayerPropsUpdate = (layer, scale = "", transformOriginX = "", transformOriginY = "", duration) => this.emit(this.EVENTS.LAYER.PROPS_UPDATE, { layer, props: { scale, transformOriginX, transformOriginY }, duration });
|
|
24
|
+
getDefaultState = () => ({});
|
|
25
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { VnePluginConstantsMapRegistry, VnePluginEventsMapRegistry } from "@vnejs/shared";
|
|
2
|
+
import type { Constants, PluginName, SubscribeEvents } from "@vnejs/plugins.canvas.scale.contract";
|
|
3
|
+
import type { PluginName as LayerPluginName, SubscribeEvents as LayerSubscribeEvents } from "@vnejs/plugins.canvas.layer.contract";
|
|
4
|
+
import type { PluginName as StatePluginName, SubscribeEvents as StateSubscribeEvents } from "@vnejs/plugins.core.state.contract";
|
|
5
|
+
export type ScalePluginEvents = VnePluginEventsMapRegistry & Record<PluginName, SubscribeEvents> & Record<LayerPluginName, LayerSubscribeEvents> & Record<StatePluginName, StateSubscribeEvents>;
|
|
6
|
+
export type ScalePluginConstants = VnePluginConstantsMapRegistry & Record<PluginName, Constants>;
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type ScaleLayerState = {
|
|
2
|
+
scale: unknown;
|
|
3
|
+
transformOriginX: string;
|
|
4
|
+
transformOriginY: string;
|
|
5
|
+
};
|
|
6
|
+
export type ScaleState = Record<string, ScaleLayerState>;
|
|
7
|
+
export type ScaleSetPayload = {
|
|
8
|
+
layer?: string;
|
|
9
|
+
value?: unknown;
|
|
10
|
+
transformOriginX?: string;
|
|
11
|
+
transformOriginY?: string;
|
|
12
|
+
duration?: number;
|
|
13
|
+
};
|
|
14
|
+
export type ScaleUnsetPayload = {
|
|
15
|
+
layer?: string;
|
|
16
|
+
duration?: number;
|
|
17
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,17 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vnejs/plugins.canvas.scale",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"require": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"src",
|
|
18
|
+
"tsconfig.json"
|
|
19
|
+
],
|
|
5
20
|
"scripts": {
|
|
6
21
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
22
|
+
"build": "npx @vnejs/monorepo package",
|
|
7
23
|
"publish:major:plugin": "npm run publish:major",
|
|
8
24
|
"publish:minor:plugin": "npm run publish:minor",
|
|
9
25
|
"publish:patch:plugin": "npm run publish:patch",
|
|
10
|
-
"publish:major": "
|
|
11
|
-
"publish:minor": "
|
|
12
|
-
"publish:patch": "
|
|
26
|
+
"publish:major": "npx @vnejs/monorepo publish major --access public",
|
|
27
|
+
"publish:minor": "npx @vnejs/monorepo publish minor --access public",
|
|
28
|
+
"publish:patch": "npx @vnejs/monorepo publish patch --access public"
|
|
13
29
|
},
|
|
14
30
|
"author": "",
|
|
15
31
|
"license": "ISC",
|
|
16
|
-
"
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@vnejs/plugins.canvas.scale.contract": "~0.0.1"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"@vnejs/module": "~0.0.1",
|
|
37
|
+
"@vnejs/plugins.canvas.layer.contract": "~0.0.1",
|
|
38
|
+
"@vnejs/plugins.core.state.contract": "~0.0.1",
|
|
39
|
+
"@vnejs/shared": "~0.0.9"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@vnejs/configs.ts-common": "~0.0.1"
|
|
43
|
+
}
|
|
17
44
|
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { regPlugin } from "@vnejs/shared";
|
|
2
|
+
import { CONSTANTS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/plugins.canvas.scale.contract";
|
|
3
|
+
|
|
4
|
+
import { LayerScale } from "./modules/scale.js";
|
|
5
|
+
|
|
6
|
+
regPlugin(PLUGIN_NAME, { constants: CONSTANTS, events: SUBSCRIBE_EVENTS }, [LayerScale]);
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { Module } from "@vnejs/module";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import type { ScalePluginConstants, ScalePluginEvents } from "../types.js";
|
|
4
|
+
import type { ScaleSetPayload, ScaleState, ScaleUnsetPayload } from "../utils/scale.js";
|
|
5
|
+
|
|
6
|
+
export class LayerScale extends Module<ScalePluginEvents, ScalePluginConstants, Record<string, never>, Record<string, never>, ScaleState> {
|
|
4
7
|
name = "layer.scale";
|
|
5
8
|
|
|
6
9
|
subscribe = () => {
|
|
@@ -11,23 +14,27 @@ export class LayerScale extends Module {
|
|
|
11
14
|
this.on(this.EVENTS.STATE.CLEAR, this.onStateClear);
|
|
12
15
|
};
|
|
13
16
|
|
|
14
|
-
onScaleSet = async ({ layer = "", value = "", transformOriginX = "center", transformOriginY = "center", duration = 0 } = {}) => {
|
|
17
|
+
onScaleSet = async ({ layer = "", value = "", transformOriginX = "center", transformOriginY = "center", duration = 0 }: ScaleSetPayload = {}) => {
|
|
15
18
|
this.state[layer] = { scale: value, transformOriginX, transformOriginY };
|
|
16
19
|
|
|
17
20
|
return this.emitLayerPropsUpdate(layer, value, transformOriginX, transformOriginY, duration);
|
|
18
21
|
};
|
|
19
|
-
|
|
22
|
+
|
|
23
|
+
onScaleUnset = async ({ layer = "", duration = 0 }: ScaleUnsetPayload = {}) => {
|
|
20
24
|
delete this.state[layer];
|
|
21
25
|
|
|
22
26
|
return this.emitLayerPropsUpdate(layer, "", "", "", duration);
|
|
23
27
|
};
|
|
24
28
|
|
|
25
|
-
onStateSet = async ({ [this.name]: state = {} } = {}) => {
|
|
29
|
+
onStateSet = async ({ [this.name]: state = {} }: Record<string, ScaleState> = {}) => {
|
|
26
30
|
await Promise.all(Object.keys(this.state).map((layer) => this.emit(this.EVENTS.LAYER_SCALE.UNSET, { layer, duration: 0 })));
|
|
27
31
|
await Promise.all(Object.keys(state).map((layer) => this.emit(this.EVENTS.LAYER_SCALE.SET, { ...state[layer], layer, duration: 0 })));
|
|
28
32
|
};
|
|
33
|
+
|
|
29
34
|
onStateClear = () => Promise.all(Object.keys(this.state).map((layer) => this.emit(this.EVENTS.LAYER_SCALE.UNSET, { layer, duration: 0 })));
|
|
30
35
|
|
|
31
|
-
emitLayerPropsUpdate = (layer, scale = "", transformOriginX = "", transformOriginY = "", duration) =>
|
|
36
|
+
emitLayerPropsUpdate = (layer: string, scale: unknown = "", transformOriginX = "", transformOriginY = "", duration: number) =>
|
|
32
37
|
this.emit(this.EVENTS.LAYER.PROPS_UPDATE, { layer, props: { scale, transformOriginX, transformOriginY }, duration });
|
|
38
|
+
|
|
39
|
+
getDefaultState = (): ScaleState => ({});
|
|
33
40
|
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { VnePluginConstantsMapRegistry, VnePluginEventsMapRegistry } from "@vnejs/shared";
|
|
2
|
+
import type { Constants, PluginName, SubscribeEvents } from "@vnejs/plugins.canvas.scale.contract";
|
|
3
|
+
import type { PluginName as LayerPluginName, SubscribeEvents as LayerSubscribeEvents } from "@vnejs/plugins.canvas.layer.contract";
|
|
4
|
+
import type { PluginName as StatePluginName, SubscribeEvents as StateSubscribeEvents } from "@vnejs/plugins.core.state.contract";
|
|
5
|
+
|
|
6
|
+
export type ScalePluginEvents = VnePluginEventsMapRegistry & Record<PluginName, SubscribeEvents> & Record<LayerPluginName, LayerSubscribeEvents> & Record<StatePluginName, StateSubscribeEvents>;
|
|
7
|
+
|
|
8
|
+
export type ScalePluginConstants = VnePluginConstantsMapRegistry & Record<PluginName, Constants>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type ScaleLayerState = {
|
|
2
|
+
scale: unknown;
|
|
3
|
+
transformOriginX: string;
|
|
4
|
+
transformOriginY: string;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export type ScaleState = Record<string, ScaleLayerState>;
|
|
8
|
+
|
|
9
|
+
export type ScaleSetPayload = {
|
|
10
|
+
layer?: string;
|
|
11
|
+
value?: unknown;
|
|
12
|
+
transformOriginX?: string;
|
|
13
|
+
transformOriginY?: string;
|
|
14
|
+
duration?: number;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export type ScaleUnsetPayload = {
|
|
18
|
+
layer?: string;
|
|
19
|
+
duration?: number;
|
|
20
|
+
};
|
package/tsconfig.json
ADDED
package/const/const.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const EXEC_ACTIONS = { SET: "set", UNSET: "unset" };
|
package/const/events.js
DELETED
package/index.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { regPlugin } from "@vnejs/shared";
|
|
2
|
-
|
|
3
|
-
import * as constants from "./const/const";
|
|
4
|
-
import { SUBSCRIBE_EVENTS } from "./const/events";
|
|
5
|
-
|
|
6
|
-
import { LayerScale } from "./modules/scale";
|
|
7
|
-
|
|
8
|
-
regPlugin("LAYER_SCALE", { constants, events: SUBSCRIBE_EVENTS }, [LayerScale]);
|