@vnejs/plugins.canvas.clip 0.1.1 → 0.1.3

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.
@@ -0,0 +1 @@
1
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ import { regPlugin } from "@vnejs/shared";
2
+ import { CONSTANTS, PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/plugins.canvas.clip.contract";
3
+ import { LayerClip } from "./modules/clip.js";
4
+ regPlugin(PLUGIN_NAME, { constants: CONSTANTS, events: SUBSCRIBE_EVENTS, params: PARAMS }, [LayerClip]);
@@ -0,0 +1,13 @@
1
+ import { Module } from "@vnejs/module";
2
+ import type { ClipPluginConstants, ClipPluginEvents, ClipPluginParams } from "../types.js";
3
+ import type { ClipSetPayload, ClipState, ClipUnsetPayload } from "../utils/clip.js";
4
+ export declare class LayerClip extends Module<ClipPluginEvents, ClipPluginConstants, Record<string, never>, ClipPluginParams, ClipState> {
5
+ name: string;
6
+ subscribe: () => void;
7
+ onClipSet: ({ layer, value, name, duration, args }?: ClipSetPayload) => Promise<unknown[] | undefined>;
8
+ onClipUnset: ({ layer, duration }?: ClipUnsetPayload) => Promise<unknown[] | undefined>;
9
+ onStateSet: ({ [this.name]: state }?: Record<string, ClipState>) => Promise<void>;
10
+ onStateClear: () => Promise<(unknown[] | undefined)[]>;
11
+ emitLayerPropsUpdate: (layer: string, clip: string, duration: number) => Promise<unknown[]> | undefined;
12
+ getDefaultState: () => ClipState;
13
+ }
@@ -0,0 +1,27 @@
1
+ import { Module } from "@vnejs/module";
2
+ export class LayerClip extends Module {
3
+ name = "layer.clip";
4
+ subscribe = () => {
5
+ this.on(this.EVENTS.LAYER_CLIP.SET, this.onClipSet);
6
+ this.on(this.EVENTS.LAYER_CLIP.UNSET, this.onClipUnset);
7
+ this.on(this.EVENTS.STATE.SET, this.onStateSet);
8
+ this.on(this.EVENTS.STATE.CLEAR, this.onStateClear);
9
+ };
10
+ onClipSet = async ({ layer = "", value = "", name = "", duration = 0, args = [] } = {}) => {
11
+ const clipFn = this.PARAMS.LAYER_CLIP.CLIPS[name];
12
+ const clip = value || (clipFn ? clipFn(...args) : "");
13
+ this.state[layer] = clip;
14
+ return this.emitLayerPropsUpdate(layer, this.state[layer], duration);
15
+ };
16
+ onClipUnset = async ({ layer = "", duration = 0 } = {}) => {
17
+ delete this.state[layer];
18
+ return this.emitLayerPropsUpdate(layer, "", duration);
19
+ };
20
+ onStateSet = async ({ [this.name]: state = {} } = {}) => {
21
+ await Promise.all(Object.keys(this.state).map((layer) => this.emit(this.EVENTS.LAYER_CLIP.UNSET, { layer, duration: 0 })));
22
+ await Promise.all(Object.keys(state).map((layer) => this.emit(this.EVENTS.LAYER_CLIP.SET, { layer, value: state[layer], duration: 0 })));
23
+ };
24
+ onStateClear = () => Promise.all(Object.keys(this.state).map((layer) => this.emit(this.EVENTS.LAYER_CLIP.UNSET, { layer, duration: 0 })));
25
+ emitLayerPropsUpdate = (layer, clip, duration) => this.emit(this.EVENTS.LAYER.PROPS_UPDATE, { layer, props: { clip }, duration });
26
+ getDefaultState = () => ({});
27
+ }
@@ -0,0 +1,7 @@
1
+ import type { VnePluginConstantsMapRegistry, VnePluginEventsMapRegistry, VnePluginParamsMapRegistry } from "@vnejs/shared";
2
+ import type { Constants, Params, PluginName, SubscribeEvents } from "@vnejs/plugins.canvas.clip.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 ClipPluginEvents = VnePluginEventsMapRegistry & Record<PluginName, SubscribeEvents> & Record<LayerPluginName, LayerSubscribeEvents> & Record<StatePluginName, StateSubscribeEvents>;
6
+ export type ClipPluginConstants = VnePluginConstantsMapRegistry & Record<PluginName, Constants>;
7
+ export type ClipPluginParams = VnePluginParamsMapRegistry & Record<PluginName, Params>;
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,12 @@
1
+ export type ClipState = Record<string, string>;
2
+ export type ClipSetPayload = {
3
+ layer?: string;
4
+ value?: string;
5
+ name?: string;
6
+ duration?: number;
7
+ args?: unknown[];
8
+ };
9
+ export type ClipUnsetPayload = {
10
+ layer?: string;
11
+ duration?: number;
12
+ };
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,17 +1,44 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.canvas.clip",
3
- "version": "0.1.1",
4
- "main": "index.js",
3
+ "version": "0.1.3",
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": "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"
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
- "description": ""
32
+ "dependencies": {
33
+ "@vnejs/plugins.canvas.clip.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, PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/plugins.canvas.clip.contract";
3
+
4
+ import { LayerClip } from "./modules/clip.js";
5
+
6
+ regPlugin(PLUGIN_NAME, { constants: CONSTANTS, events: SUBSCRIBE_EVENTS, params: PARAMS }, [LayerClip]);
@@ -1,6 +1,9 @@
1
1
  import { Module } from "@vnejs/module";
2
2
 
3
- export class LayerClip extends Module {
3
+ import type { ClipPluginConstants, ClipPluginEvents, ClipPluginParams } from "../types.js";
4
+ import type { ClipSetPayload, ClipState, ClipUnsetPayload } from "../utils/clip.js";
5
+
6
+ export class LayerClip extends Module<ClipPluginEvents, ClipPluginConstants, Record<string, never>, ClipPluginParams, ClipState> {
4
7
  name = "layer.clip";
5
8
 
6
9
  subscribe = () => {
@@ -11,22 +14,30 @@ export class LayerClip extends Module {
11
14
  this.on(this.EVENTS.STATE.CLEAR, this.onStateClear);
12
15
  };
13
16
 
14
- onClipSet = async ({ layer = "", value = "", name = "", duration = 0, args = [] } = {}) => {
15
- this.state[layer] = value || this.PARAMS.LAYER_CLIP.CLIPS[name](...args);
17
+ onClipSet = async ({ layer = "", value = "", name = "", duration = 0, args = [] }: ClipSetPayload = {}) => {
18
+ const clipFn = this.PARAMS.LAYER_CLIP.CLIPS[name as keyof typeof this.PARAMS.LAYER_CLIP.CLIPS];
19
+ const clip = value || (clipFn ? (clipFn as (...clipArgs: unknown[]) => string)(...args) : "");
20
+
21
+ this.state[layer] = clip!;
16
22
 
17
23
  return this.emitLayerPropsUpdate(layer, this.state[layer], duration);
18
24
  };
19
- onClipUnset = async ({ layer = "", duration = 0 } = {}) => {
25
+
26
+ onClipUnset = async ({ layer = "", duration = 0 }: ClipUnsetPayload = {}) => {
20
27
  delete this.state[layer];
21
28
 
22
29
  return this.emitLayerPropsUpdate(layer, "", duration);
23
30
  };
24
31
 
25
- onStateSet = async ({ [this.name]: state = {} } = {}) => {
32
+ onStateSet = async ({ [this.name]: state = {} }: Record<string, ClipState> = {}) => {
26
33
  await Promise.all(Object.keys(this.state).map((layer) => this.emit(this.EVENTS.LAYER_CLIP.UNSET, { layer, duration: 0 })));
27
34
  await Promise.all(Object.keys(state).map((layer) => this.emit(this.EVENTS.LAYER_CLIP.SET, { layer, value: state[layer], duration: 0 })));
28
35
  };
36
+
29
37
  onStateClear = () => Promise.all(Object.keys(this.state).map((layer) => this.emit(this.EVENTS.LAYER_CLIP.UNSET, { layer, duration: 0 })));
30
38
 
31
- emitLayerPropsUpdate = (layer, clip, duration) => this.emit(this.EVENTS.LAYER.PROPS_UPDATE, { layer, props: { clip }, duration });
39
+ emitLayerPropsUpdate = (layer: string, clip: string, duration: number) =>
40
+ this.emit(this.EVENTS.LAYER.PROPS_UPDATE, { layer, props: { clip }, duration });
41
+
42
+ getDefaultState = (): ClipState => ({});
32
43
  }
package/src/types.ts ADDED
@@ -0,0 +1,10 @@
1
+ import type { VnePluginConstantsMapRegistry, VnePluginEventsMapRegistry, VnePluginParamsMapRegistry } from "@vnejs/shared";
2
+ import type { Constants, Params, PluginName, SubscribeEvents } from "@vnejs/plugins.canvas.clip.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 ClipPluginEvents = VnePluginEventsMapRegistry & Record<PluginName, SubscribeEvents> & Record<LayerPluginName, LayerSubscribeEvents> & Record<StatePluginName, StateSubscribeEvents>;
7
+
8
+ export type ClipPluginConstants = VnePluginConstantsMapRegistry & Record<PluginName, Constants>;
9
+
10
+ export type ClipPluginParams = VnePluginParamsMapRegistry & Record<PluginName, Params>;
@@ -0,0 +1,14 @@
1
+ export type ClipState = Record<string, string>;
2
+
3
+ export type ClipSetPayload = {
4
+ layer?: string;
5
+ value?: string;
6
+ name?: string;
7
+ duration?: number;
8
+ args?: unknown[];
9
+ };
10
+
11
+ export type ClipUnsetPayload = {
12
+ layer?: string;
13
+ duration?: number;
14
+ };
package/tsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "@vnejs/configs.ts-common/tsconfig.json",
3
+ "compilerOptions": {
4
+ "rootDir": "src",
5
+ "outDir": "dist"
6
+ },
7
+ "include": ["src/**/*.ts"],
8
+ "exclude": ["dist", "node_modules"]
9
+ }
package/const/const.js DELETED
@@ -1 +0,0 @@
1
- export const EXEC_ACTIONS = { SET: "set", UNSET: "unset" };
package/const/events.js DELETED
@@ -1,4 +0,0 @@
1
- export const SUBSCRIBE_EVENTS = {
2
- SET: "vne:layer_clip:set",
3
- UNSET: "vne:layer_clip:unset",
4
- };
package/const/params.js DELETED
@@ -1,4 +0,0 @@
1
- export const CLIPS = {
2
- ellipse: (width = 50, height = 50, x = 50, y = 50) => `ellipse(${width}vw ${height}vw at ${x}% ${y}%)`,
3
- circle: (radius = 50, x = 50, y = 50) => `circle(${radius}vw at ${x}% ${y}%)`,
4
- };
package/index.js DELETED
@@ -1,9 +0,0 @@
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]);