@vnejs/plugins.core.system 0.0.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/events.js +13 -0
- package/index.js +9 -0
- package/modules/file.js +36 -0
- package/modules/resize.js +37 -0
- package/modules/system.js +21 -0
- package/package.json +18 -0
package/const/events.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export const SUBSCRIBE_EVENTS = {
|
|
2
|
+
STARTED: "vne:system:started",
|
|
3
|
+
|
|
4
|
+
RESIZE: "vne:system:resize",
|
|
5
|
+
RELOAD: "vne:system:reload",
|
|
6
|
+
FULLSCREEN: "vne:system:fullscreen",
|
|
7
|
+
|
|
8
|
+
CLOSE: "vne:system:close",
|
|
9
|
+
CLOSE_BEFORE: "vne:system:close_before",
|
|
10
|
+
|
|
11
|
+
FILE_LOAD: "vne:file:load",
|
|
12
|
+
FILE_READ: "vne:file:read",
|
|
13
|
+
};
|
package/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { regPlugin } from "@vnejs/shared";
|
|
2
|
+
|
|
3
|
+
import { SUBSCRIBE_EVENTS } from "./const/events";
|
|
4
|
+
|
|
5
|
+
import { File } from "./modules/file";
|
|
6
|
+
import { Resize } from "./modules/resize";
|
|
7
|
+
import { System } from "./modules/system";
|
|
8
|
+
|
|
9
|
+
regPlugin("SYSTEM", { events: SUBSCRIBE_EVENTS }, [File, Resize, System]);
|
package/modules/file.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Module } from "@vnejs/module";
|
|
2
|
+
|
|
3
|
+
export class File extends Module {
|
|
4
|
+
name = "file";
|
|
5
|
+
|
|
6
|
+
subscribe = () => {
|
|
7
|
+
this.on(this.EVENTS.SYSTEM.FILE_LOAD, this.onFileLoad);
|
|
8
|
+
this.on(this.EVENTS.SYSTEM.FILE_READ, this.onFileRead);
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
onFileLoad = ({ obj, name } = {}) => {
|
|
12
|
+
const dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(obj));
|
|
13
|
+
const objectLink = document.createElement("a");
|
|
14
|
+
objectLink.style.display = "none";
|
|
15
|
+
objectLink.setAttribute("href", dataStr);
|
|
16
|
+
objectLink.setAttribute("download", name + ".json");
|
|
17
|
+
document.body.appendChild(objectLink);
|
|
18
|
+
objectLink.click();
|
|
19
|
+
objectLink.remove();
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
onFileRead = () =>
|
|
23
|
+
new Promise((resolve) => {
|
|
24
|
+
const fileInput = document.createElement("input");
|
|
25
|
+
fileInput.style.display = "none";
|
|
26
|
+
fileInput.setAttribute("type", "file");
|
|
27
|
+
fileInput.setAttribute("accept", ".json");
|
|
28
|
+
fileInput.onchange = async () => {
|
|
29
|
+
const textJson = await fileInput.files[0].text();
|
|
30
|
+
fileInput.remove();
|
|
31
|
+
resolve(JSON.parse(textJson));
|
|
32
|
+
};
|
|
33
|
+
document.body.appendChild(fileInput);
|
|
34
|
+
fileInput.click();
|
|
35
|
+
});
|
|
36
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Module } from "@vnejs/module";
|
|
2
|
+
|
|
3
|
+
const WIDTHS = [
|
|
4
|
+
3840, 3520, 3200, 2880, 2560, 2400, 2160, 2048, 1920, 1680, 1600, 1440, 1336, 1366, 1280, 1152, 1136, 1024, 960, 854,
|
|
5
|
+
640,
|
|
6
|
+
];
|
|
7
|
+
const HEIGHTS = [
|
|
8
|
+
2160, 1980, 1800, 1620, 1600, 1440, 1350, 1200, 1152, 1080, 1050, 900, 810, 800, 768, 720, 640, 576, 540, 480, 360,
|
|
9
|
+
];
|
|
10
|
+
|
|
11
|
+
export class Resize extends Module {
|
|
12
|
+
name = "resize";
|
|
13
|
+
rootElement = document.body;
|
|
14
|
+
subscribe = () => {
|
|
15
|
+
this.on(this.EVENTS.SYSTEM.RESIZE, this.onResize);
|
|
16
|
+
};
|
|
17
|
+
init = async () => {
|
|
18
|
+
const debounceFunc = await this.emitOne(this.EVENTS.VENDORS.DEBOUNCE, { func: this.emitResize, wait: 250 });
|
|
19
|
+
window.addEventListener("resize", debounceFunc);
|
|
20
|
+
await this.emitResize();
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
onResize = () => {
|
|
24
|
+
WIDTHS.forEach(this.setWidths);
|
|
25
|
+
HEIGHTS.forEach(this.setHeights);
|
|
26
|
+
|
|
27
|
+
// Баг в иос связанный с 100vh
|
|
28
|
+
document.documentElement.style.setProperty("--app-height", `${window.innerHeight}px`);
|
|
29
|
+
document.documentElement.style.setProperty("--app-width", `${window.innerWidth}px`);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
emitResize = () => this.emit(this.EVENTS.SYSTEM.RESIZE);
|
|
33
|
+
|
|
34
|
+
setWidths = (width) => this.setClassName(window.innerWidth < width, `width_${width}`);
|
|
35
|
+
setHeights = (height) => this.setClassName(window.innerHeight < height, `height_${height}`);
|
|
36
|
+
setClassName = (condition, className) => this.rootElement.classList.toggle(className, condition);
|
|
37
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Module } from "@vnejs/module";
|
|
2
|
+
|
|
3
|
+
export class System extends Module {
|
|
4
|
+
name = "system";
|
|
5
|
+
|
|
6
|
+
subscribe = () => {
|
|
7
|
+
this.on(this.EVENTS.SYSTEM.CLOSE, this.onClose);
|
|
8
|
+
this.on(this.EVENTS.SYSTEM.RELOAD, this.onReload);
|
|
9
|
+
this.on(this.EVENTS.SYSTEM.FULLSCREEN, this.onFullScreen);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
onClose = async () => {
|
|
13
|
+
await this.emit(this.EVENTS.SYSTEM.CLOSE_BEFORE);
|
|
14
|
+
window.close();
|
|
15
|
+
};
|
|
16
|
+
onReload = async () => {
|
|
17
|
+
await this.emit(this.EVENTS.SYSTEM.CLOSE_BEFORE);
|
|
18
|
+
window.location.reload();
|
|
19
|
+
};
|
|
20
|
+
onFullScreen = () => (document.fullscreenElement ? document.exitFullscreen() : document.body.requestFullscreen());
|
|
21
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vnejs/plugins.core.system",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
7
|
+
"publish:major": "npm version major && npm publish --access public",
|
|
8
|
+
"publish:minor": "npm version minor && npm publish --access public",
|
|
9
|
+
"publish:patch": "npm version patch && npm publish --access public"
|
|
10
|
+
},
|
|
11
|
+
"author": "",
|
|
12
|
+
"license": "ISC",
|
|
13
|
+
"description": "",
|
|
14
|
+
"peerDependencies": {
|
|
15
|
+
"@vnejs/shared": "*",
|
|
16
|
+
"@vnejs/module": "*"
|
|
17
|
+
}
|
|
18
|
+
}
|