@vnejs/plugins.core.system 0.0.1 → 0.1.0

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/index.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ import * as constants from "./const/const";
2
+ import { SUBSCRIBE_EVENTS } from "./const/events";
3
+ import { SETTINGS_KEYS } from "./const/settings";
4
+
5
+ type SubscribeEventsType = typeof SUBSCRIBE_EVENTS;
6
+ type SettingsKeysType = typeof SETTINGS_KEYS;
7
+ type ConstantsType = typeof constants;
8
+
9
+ const PLUGIN_NAME = "SYSTEM";
10
+
11
+ declare global {
12
+ interface EVENTS {
13
+ [PLUGIN_NAME]: SubscribeEventsType;
14
+ }
15
+ }
package/modules/resize.js CHANGED
@@ -1,37 +1,49 @@
1
1
  import { Module } from "@vnejs/module";
2
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
- ];
3
+ const HEIGHT = 2160;
4
+ const WIDTH = 3840;
5
+ const HEIGHT_ARRAY = [];
6
+ const WIDTH_ARRAY = [];
7
+
8
+ const kek = (i, value, arr) => {
9
+ if (value % i === 0) arr.push(i);
10
+ if (value / i < i) {
11
+ const maxLength = arr.length;
12
+
13
+ arr.forEach((_, j) => arr.push(Math.round(value / arr[maxLength - j - 1])));
14
+ arr.push(value);
15
+
16
+ return true;
17
+ }
18
+
19
+ return false;
20
+ };
21
+
22
+ for (let i = 2; ; i++) if (kek(i, HEIGHT, HEIGHT_ARRAY)) break;
23
+ for (let i = 2; ; i++) if (kek(i, WIDTH, WIDTH_ARRAY)) break;
24
+
25
+ const LENGTH_ARRAY = [...new Set([...HEIGHT_ARRAY, ...WIDTH_ARRAY]).values()].sort((i, j) => i - j);
10
26
 
11
27
  export class Resize extends Module {
12
28
  name = "resize";
13
- rootElement = document.body;
29
+
14
30
  subscribe = () => {
15
31
  this.on(this.EVENTS.SYSTEM.RESIZE, this.onResize);
16
32
  };
17
33
  init = async () => {
18
- const debounceFunc = await this.emitOne(this.EVENTS.VENDORS.DEBOUNCE, { func: this.emitResize, wait: 250 });
19
- window.addEventListener("resize", debounceFunc);
34
+ window.addEventListener("resize", this.emitResize);
35
+
20
36
  await this.emitResize();
21
37
  };
22
38
 
23
39
  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`);
40
+ LENGTH_ARRAY.forEach((len) =>
41
+ document.documentElement.style.setProperty(
42
+ `--vne-length-${len}`,
43
+ Math.min(Math.floor((len * window.innerHeight) / HEIGHT), Math.floor((len * window.innerWidth) / WIDTH)),
44
+ ),
45
+ );
30
46
  };
31
47
 
32
48
  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
49
  }
package/modules/system.js CHANGED
@@ -11,10 +11,12 @@ export class System extends Module {
11
11
 
12
12
  onClose = async () => {
13
13
  await this.emit(this.EVENTS.SYSTEM.CLOSE_BEFORE);
14
+
14
15
  window.close();
15
16
  };
16
17
  onReload = async () => {
17
18
  await this.emit(this.EVENTS.SYSTEM.CLOSE_BEFORE);
19
+
18
20
  window.location.reload();
19
21
  };
20
22
  onFullScreen = () => (document.fullscreenElement ? document.exitFullscreen() : document.body.requestFullscreen());
package/package.json CHANGED
@@ -1,9 +1,12 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.core.system",
3
- "version": "0.0.1",
3
+ "version": "0.1.0",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
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",
7
10
  "publish:major": "npm version major && npm publish --access public",
8
11
  "publish:minor": "npm version minor && npm publish --access public",
9
12
  "publish:patch": "npm version patch && npm publish --access public"