@vnejs/plugins.canvas.layer 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 ADDED
@@ -0,0 +1,11 @@
1
+ export const QUALITIES = { UHD: "2160p", QHD: "1440p", FHD: "1080p", HDp: "900p", HD: "720p", qHD: "540p", nHD: "360p" };
2
+
3
+ export const SCREEN_SIZES = {
4
+ [QUALITIES.UHD]: { width: 3840, height: 2160 },
5
+ [QUALITIES.QHD]: { width: 2560, height: 1440 },
6
+ [QUALITIES.FHD]: { width: 1920, height: 1080 },
7
+ [QUALITIES.HDp]: { width: 1600, height: 900 },
8
+ [QUALITIES.HD]: { width: 1280, height: 720 },
9
+ [QUALITIES.qHD]: { width: 960, height: 540 },
10
+ [QUALITIES.nHD]: { width: 640, height: 360 },
11
+ };
@@ -0,0 +1,18 @@
1
+ export const SUBSCRIBE_EVENTS = {
2
+ SHOW: "vne:layer:show",
3
+ HIDE: "vne:layer:hide",
4
+ UPDATE: "vne:layer:update",
5
+ FORCE_UPDATE: "vne:layer:force_update",
6
+
7
+ CHILD_RM: "vne:layer:child_rm",
8
+ CHILDS_RM: "vne:layer:childs_rm",
9
+
10
+ CHILD_ADD: "vne:layer:child_add",
11
+
12
+ CHILD_CHANGE: "vne:layer:child_change",
13
+ CHILDS_CHANGE: "vne:layer:childs_change",
14
+
15
+ CHILD_GET: "vne:layer:child_get",
16
+
17
+ STATE_GET: "vne:layer:state_get",
18
+ };
@@ -0,0 +1 @@
1
+ export const DEFAULT_QUALITY = "1080p";
@@ -0,0 +1,5 @@
1
+ export const SETTINGS_KEYS = {
2
+ WIDTH: "vne:canvas:width",
3
+ HEIGHT: "vne:canvas:height",
4
+ QUALITY: "vne:canvas:quality",
5
+ };
package/index.js ADDED
@@ -0,0 +1,10 @@
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
+ import { SETTINGS_KEYS } from "./const/settings";
7
+
8
+ import { LayerQuality } from "./modules/quality";
9
+
10
+ regPlugin("LAYER", { constants, events: SUBSCRIBE_EVENTS, params, settings: SETTINGS_KEYS }, [LayerQuality]);
@@ -0,0 +1,31 @@
1
+ import { Module } from "@vnejs/module";
2
+
3
+ export class LayerQuality extends Module {
4
+ name = "layer.quality";
5
+
6
+ subscribe = () => {
7
+ this.on(this.EVENTS.SETTINGS.CHANGED, this.onSettingChange);
8
+ };
9
+
10
+ init = async () => {
11
+ const options = Object.values(this.CONST.LAYER.QUALITIES);
12
+
13
+ await this.emit(this.EVENTS.SETTINGS.INIT, { name: this.SETTINGS.LAYER.QUALITY, value: this.PARAMS.LAYER.DEFAULT_QUALITY, options });
14
+
15
+ return this.setNewSizes(this.CONST.LAYER.SCREEN_SIZES[this.shared.settings[this.SETTINGS.LAYER.QUALITY]]);
16
+ };
17
+
18
+ onSettingChange = ({ name, value } = {}) => name === this.SETTINGS.LAYER.QUALITY && this.setNewSizes(this.CONST.LAYER.SCREEN_SIZES[value]);
19
+
20
+ setNewSizes = ({ width, height } = {}) => {
21
+ document.documentElement.style.setProperty("--vne-canvas-width", `${width}px`);
22
+ document.documentElement.style.setProperty("--vne-canvas-height", `${height}px`);
23
+
24
+ return Promise.all([
25
+ this.emit(this.EVENTS.SETTINGS.SET, { name: this.SETTINGS.LAYER.WIDTH, value: width }),
26
+ this.emit(this.EVENTS.SETTINGS.SET, { name: this.SETTINGS.LAYER.HEIGHT, value: height }),
27
+ ]).then(this.emitMemoryClear);
28
+ };
29
+
30
+ emitMemoryClear = () => this.emit(this.EVENTS.MEMORY.CLEAR, { isForceClear: true });
31
+ }
package/package.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "@vnejs/plugins.canvas.layer",
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
+ }