@vnejs/plugins.canvas.clip 0.1.1
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/const/const.js +1 -0
- package/const/events.js +4 -0
- package/const/params.js +4 -0
- package/index.js +9 -0
- package/modules/clip.js +32 -0
- package/package.json +17 -0
package/const/const.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const EXEC_ACTIONS = { SET: "set", UNSET: "unset" };
|
package/const/events.js
ADDED
package/const/params.js
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { regPlugin } from "@vnejs/shared";
|
|
2
|
+
|
|
3
|
+
import * as constants from "./const/const";
|
|
4
|
+
import { SUBSCRIBE_EVENTS } from "./const/events";
|
|
5
|
+
import * as params from "./const/params";
|
|
6
|
+
|
|
7
|
+
import { LayerClip } from "./modules/clip";
|
|
8
|
+
|
|
9
|
+
regPlugin("LAYER_CLIP", { constants, events: SUBSCRIBE_EVENTS, params }, [LayerClip]);
|
package/modules/clip.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Module } from "@vnejs/module";
|
|
2
|
+
|
|
3
|
+
export class LayerClip extends Module {
|
|
4
|
+
name = "layer.clip";
|
|
5
|
+
|
|
6
|
+
subscribe = () => {
|
|
7
|
+
this.on(this.EVENTS.LAYER_CLIP.SET, this.onClipSet);
|
|
8
|
+
this.on(this.EVENTS.LAYER_CLIP.UNSET, this.onClipUnset);
|
|
9
|
+
|
|
10
|
+
this.on(this.EVENTS.STATE.SET, this.onStateSet);
|
|
11
|
+
this.on(this.EVENTS.STATE.CLEAR, this.onStateClear);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
onClipSet = async ({ layer = "", value = "", name = "", duration = 0, args = [] } = {}) => {
|
|
15
|
+
this.state[layer] = value || this.PARAMS.LAYER_CLIP.CLIPS[name](...args);
|
|
16
|
+
|
|
17
|
+
return this.emitLayerPropsUpdate(layer, this.state[layer], duration);
|
|
18
|
+
};
|
|
19
|
+
onClipUnset = async ({ layer = "", duration = 0 } = {}) => {
|
|
20
|
+
delete this.state[layer];
|
|
21
|
+
|
|
22
|
+
return this.emitLayerPropsUpdate(layer, "", duration);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
onStateSet = async ({ [this.name]: state = {} } = {}) => {
|
|
26
|
+
await Promise.all(Object.keys(this.state).map((layer) => this.emit(this.EVENTS.LAYER_CLIP.UNSET, { layer, duration: 0 })));
|
|
27
|
+
await Promise.all(Object.keys(state).map((layer) => this.emit(this.EVENTS.LAYER_CLIP.SET, { layer, value: state[layer], duration: 0 })));
|
|
28
|
+
};
|
|
29
|
+
onStateClear = () => Promise.all(Object.keys(this.state).map((layer) => this.emit(this.EVENTS.LAYER_CLIP.UNSET, { layer, duration: 0 })));
|
|
30
|
+
|
|
31
|
+
emitLayerPropsUpdate = (layer, clip, duration) => this.emit(this.EVENTS.LAYER.PROPS_UPDATE, { layer, props: { clip }, duration });
|
|
32
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vnejs/plugins.canvas.clip",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
7
|
+
"publish:major:plugin": "npm run publish:major",
|
|
8
|
+
"publish:minor:plugin": "npm run publish:minor",
|
|
9
|
+
"publish:patch:plugin": "npm run publish:patch",
|
|
10
|
+
"publish:major": "npm version major && npm publish --access public",
|
|
11
|
+
"publish:minor": "npm version minor && npm publish --access public",
|
|
12
|
+
"publish:patch": "npm version patch && npm publish --access public"
|
|
13
|
+
},
|
|
14
|
+
"author": "",
|
|
15
|
+
"license": "ISC",
|
|
16
|
+
"description": ""
|
|
17
|
+
}
|