vevet 3.16.0 → 3.18.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.
Files changed (96) hide show
  1. package/README.md +5 -1
  2. package/lib/cjs/Application/events/createOnPageLoad/index.js +36 -0
  3. package/lib/cjs/Application/events/createOnPageLoad/index.js.map +1 -0
  4. package/lib/cjs/Application/events/createOnPageLoad/types.js.map +1 -0
  5. package/lib/cjs/Application/events/createViewport/index.js +144 -0
  6. package/lib/cjs/Application/events/createViewport/index.js.map +1 -0
  7. package/lib/cjs/Application/events/createViewport/types.js.map +1 -0
  8. package/lib/cjs/Application/index.js +13 -13
  9. package/lib/cjs/Application/index.js.map +1 -1
  10. package/lib/cjs/base/Callbacks/index.js +37 -22
  11. package/lib/cjs/base/Callbacks/index.js.map +1 -1
  12. package/lib/cjs/base/Module/index.js +1 -1
  13. package/lib/cjs/base/Module/index.js.map +1 -1
  14. package/lib/cjs/base/MutableProps/index.js +1 -1
  15. package/lib/cjs/base/MutableProps/index.js.map +1 -1
  16. package/lib/cjs/utils/listeners/onResize.js +1 -3
  17. package/lib/cjs/utils/listeners/onResize.js.map +1 -1
  18. package/lib/cjs/version.js +1 -1
  19. package/lib/esm/Application/events/createOnPageLoad/index.js +32 -0
  20. package/lib/esm/Application/events/createOnPageLoad/index.js.map +1 -0
  21. package/lib/esm/Application/events/createOnPageLoad/types.js.map +1 -0
  22. package/lib/esm/Application/events/createViewport/index.js +140 -0
  23. package/lib/esm/Application/events/createViewport/index.js.map +1 -0
  24. package/lib/esm/Application/events/createViewport/types.js.map +1 -0
  25. package/lib/esm/Application/index.js +9 -9
  26. package/lib/esm/Application/index.js.map +1 -1
  27. package/lib/esm/base/Callbacks/index.js +37 -21
  28. package/lib/esm/base/Callbacks/index.js.map +1 -1
  29. package/lib/esm/base/Module/index.js +1 -1
  30. package/lib/esm/base/Module/index.js.map +1 -1
  31. package/lib/esm/base/MutableProps/index.js +1 -1
  32. package/lib/esm/base/MutableProps/index.js.map +1 -1
  33. package/lib/esm/utils/listeners/onResize.js +1 -1
  34. package/lib/esm/utils/listeners/onResize.js.map +1 -1
  35. package/lib/esm/version.js +1 -1
  36. package/lib/types/Application/events/createOnPageLoad/index.d.ts +5 -0
  37. package/lib/types/Application/events/createOnPageLoad/index.d.ts.map +1 -0
  38. package/lib/types/Application/events/createOnPageLoad/types.d.ts +5 -0
  39. package/lib/types/Application/events/createOnPageLoad/types.d.ts.map +1 -0
  40. package/lib/types/Application/events/createViewport/index.d.ts +20 -0
  41. package/lib/types/Application/events/createViewport/index.d.ts.map +1 -0
  42. package/lib/types/Application/events/createViewport/types.d.ts.map +1 -0
  43. package/lib/types/Application/index.d.ts +21 -7
  44. package/lib/types/Application/index.d.ts.map +1 -1
  45. package/lib/types/base/Callbacks/index.d.ts +37 -18
  46. package/lib/types/base/Callbacks/index.d.ts.map +1 -1
  47. package/lib/types/base/Module/index.d.ts +2 -2
  48. package/lib/types/base/Module/index.d.ts.map +1 -1
  49. package/lib/types/utils/listeners/onResize.d.ts +1 -1
  50. package/lib/types/utils/listeners/onResize.d.ts.map +1 -1
  51. package/lib/types/version.d.ts +1 -1
  52. package/package.json +4 -4
  53. package/src/Application/events/.eslintrc +5 -0
  54. package/src/Application/events/createOnPageLoad/index.ts +43 -0
  55. package/src/Application/events/createOnPageLoad/types.ts +5 -0
  56. package/src/Application/events/createViewport/index.ts +165 -0
  57. package/src/Application/events/{Viewport → createViewport}/stories/index.tsx +1 -1
  58. package/src/Application/index.ts +13 -13
  59. package/src/Application/stories/index.tsx +6 -8
  60. package/src/base/Callbacks/index.ts +38 -24
  61. package/src/base/Callbacks/stories/index.tsx +29 -34
  62. package/src/base/Module/index.ts +3 -3
  63. package/src/base/MutableProps/index.ts +1 -1
  64. package/src/utils/listeners/onResize.ts +4 -3
  65. package/src/version.ts +1 -1
  66. package/lib/cjs/Application/events/PageLoad/index.js +0 -84
  67. package/lib/cjs/Application/events/PageLoad/index.js.map +0 -1
  68. package/lib/cjs/Application/events/PageLoad/types.js.map +0 -1
  69. package/lib/cjs/Application/events/Viewport/index.js +0 -263
  70. package/lib/cjs/Application/events/Viewport/index.js.map +0 -1
  71. package/lib/cjs/Application/events/Viewport/types.js.map +0 -1
  72. package/lib/esm/Application/events/PageLoad/index.js +0 -55
  73. package/lib/esm/Application/events/PageLoad/index.js.map +0 -1
  74. package/lib/esm/Application/events/PageLoad/types.js.map +0 -1
  75. package/lib/esm/Application/events/Viewport/index.js +0 -188
  76. package/lib/esm/Application/events/Viewport/index.js.map +0 -1
  77. package/lib/esm/Application/events/Viewport/types.js.map +0 -1
  78. package/lib/types/Application/events/PageLoad/index.d.ts +0 -25
  79. package/lib/types/Application/events/PageLoad/index.d.ts.map +0 -1
  80. package/lib/types/Application/events/PageLoad/types.d.ts +0 -7
  81. package/lib/types/Application/events/PageLoad/types.d.ts.map +0 -1
  82. package/lib/types/Application/events/Viewport/index.d.ts +0 -55
  83. package/lib/types/Application/events/Viewport/index.d.ts.map +0 -1
  84. package/lib/types/Application/events/Viewport/types.d.ts.map +0 -1
  85. package/src/Application/events/PageLoad/index.ts +0 -82
  86. package/src/Application/events/PageLoad/stories/index.stories.tsx +0 -13
  87. package/src/Application/events/PageLoad/stories/index.tsx +0 -16
  88. package/src/Application/events/PageLoad/types.ts +0 -7
  89. package/src/Application/events/Viewport/index.ts +0 -242
  90. /package/lib/cjs/Application/events/{PageLoad → createOnPageLoad}/types.js +0 -0
  91. /package/lib/cjs/Application/events/{Viewport → createViewport}/types.js +0 -0
  92. /package/lib/esm/Application/events/{PageLoad → createOnPageLoad}/types.js +0 -0
  93. /package/lib/esm/Application/events/{Viewport → createViewport}/types.js +0 -0
  94. /package/lib/types/Application/events/{Viewport → createViewport}/types.d.ts +0 -0
  95. /package/src/Application/events/{Viewport → createViewport}/stories/index.stories.tsx +0 -0
  96. /package/src/Application/events/{Viewport → createViewport}/types.ts +0 -0
@@ -1,7 +0,0 @@
1
- import { NCallbacks } from '../../../base/Callbacks/types';
2
- export declare namespace NPageLoad {
3
- interface ICallbacksTypes extends NCallbacks.ITypes {
4
- loaded: undefined;
5
- }
6
- }
7
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../src/Application/events/PageLoad/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEpD,yBAAiB,SAAS,CAAC;IACzB,UAAiB,eAAgB,SAAQ,UAAU,CAAC,MAAM;QACxD,MAAM,EAAE,SAAS,CAAC;KACnB;CACF"}
@@ -1,55 +0,0 @@
1
- import { Callbacks } from '../../../base/Callbacks';
2
- import { NViewport } from './types';
3
- export type { NViewport };
4
- /**
5
- * Callbacks on window resize
6
- */
7
- export declare class Viewport extends Callbacks<NViewport.ICallbacksTypes> {
8
- private _width;
9
- get width(): number;
10
- private _height;
11
- get height(): number;
12
- get radius(): number;
13
- /** VW value */
14
- get vw(): number;
15
- /** VH value */
16
- get vh(): number;
17
- /** VR value (viewport radius / 100) */
18
- get vr(): number;
19
- /** Width greater than height */
20
- get isLandscape(): boolean;
21
- /** Width less than height */
22
- get isPortrait(): boolean;
23
- /** Is desktop size */
24
- get isDesktop(): boolean;
25
- /** Is tablet size */
26
- get isTablet(): boolean;
27
- /** Is phone size */
28
- get isPhone(): boolean;
29
- /**
30
- * Device pixel ratio
31
- */
32
- get dpr(): number;
33
- /**
34
- * Device pixel ratio. For non-mobile devices it is always 1.
35
- */
36
- get lowerDesktopDpr(): number;
37
- private _resizeTimeout?;
38
- private _resizeListener?;
39
- constructor();
40
- protected _init(): void;
41
- /** Set events on resize */
42
- private _setEvents;
43
- /** Set viewport values */
44
- private _updateValues;
45
- /** Change classes of the document element */
46
- private _updateClassNames;
47
- /** Change breakpoint classes of the document element */
48
- private _updateBreakpointClassNames;
49
- /** Update CSS vars */
50
- private _updateCSSVars;
51
- /** Launch callbacks on resize. */
52
- private _onResize;
53
- destroy(): void;
54
- }
55
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/Application/events/Viewport/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAiC,SAAS,EAAE,MAAM,SAAS,CAAC;AAGnE,YAAY,EAAE,SAAS,EAAE,CAAC;AAE1B;;GAEG;AACH,qBAAa,QAAS,SAAQ,SAAS,CAAC,SAAS,CAAC,eAAe,CAAC;IAChE,OAAO,CAAC,MAAM,CAAS;IAEvB,IAAI,KAAK,WAER;IAED,OAAO,CAAC,OAAO,CAAS;IAExB,IAAI,MAAM,WAET;IAED,IAAI,MAAM,WAET;IAED,eAAe;IACf,IAAI,EAAE,WAEL;IAED,eAAe;IACf,IAAI,EAAE,WAEL;IAED,uCAAuC;IACvC,IAAI,EAAE,WAEL;IAED,gCAAgC;IAChC,IAAI,WAAW,YAEd;IAED,6BAA6B;IAC7B,IAAI,UAAU,YAEb;IAED,sBAAsB;IACtB,IAAI,SAAS,YAEZ;IAED,qBAAqB;IACrB,IAAI,QAAQ,YAIX;IAED,oBAAoB;IACpB,IAAI,OAAO,YAEV;IAED;;OAEG;IACH,IAAI,GAAG,WAEN;IAED;;OAEG;IACH,IAAI,eAAe,WAMlB;IAED,OAAO,CAAC,cAAc,CAAC,CAAiB;IAExC,OAAO,CAAC,eAAe,CAAC,CAAoB;;IAW5C,SAAS,CAAC,KAAK;IAMf,2BAA2B;IAC3B,OAAO,CAAC,UAAU;IAclB,0BAA0B;IAC1B,OAAO,CAAC,aAAa;IAkBrB,6CAA6C;IAC7C,OAAO,CAAC,iBAAiB;IAmCzB,wDAAwD;IACxD,OAAO,CAAC,2BAA2B;IAYnC,sBAAsB;IACtB,OAAO,CAAC,cAAc;IAQtB,kCAAkC;IAClC,OAAO,CAAC,SAAS;IAiCV,OAAO;CASf"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../src/Application/events/Viewport/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEpD,yBAAiB,SAAS,CAAC;IACzB;;OAEG;IACH,UAAiB,QAAQ;QACvB,cAAc,EAAE,OAAO,CAAC;QACxB,eAAe,EAAE,OAAO,CAAC;QACzB,oBAAoB,EAAE,OAAO,CAAC;KAC/B;IAED;;OAEG;IACH,UAAiB,eAAgB,SAAQ,UAAU,CAAC,MAAM;QACxD;;WAEG;QACH,KAAK,EAAE,QAAQ,CAAC;QAChB;;WAEG;QACH,MAAM,EAAE,QAAQ,CAAC;QACjB;;WAEG;QACH,IAAI,EAAE,QAAQ,CAAC;QACf;;WAEG;QACH,SAAS,EAAE,QAAQ,CAAC;QACpB;;WAEG;QACH,UAAU,EAAE,QAAQ,CAAC;QACrB;;WAEG;QACH,GAAG,EAAE,QAAQ,CAAC;KACf;CACF;AAED,0BAA0B;AAC1B,oBAAY,UAAU;IACpB,OAAO,YAAY;IACnB,MAAM,WAAW;IACjB,KAAK,UAAU;CAChB;AAED,wBAAwB;AACxB,oBAAY,iBAAiB;IAC3B,SAAS,cAAc;IACvB,QAAQ,aAAa;CACtB"}
@@ -1,82 +0,0 @@
1
- import { IAddEventListener, addEventListener } from 'vevet-dom';
2
- import { Callbacks } from '@/base/Callbacks';
3
- import { NPageLoad } from './types';
4
- import { getApp } from '@/utils/internal/getApp';
5
-
6
- export type { NPageLoad };
7
-
8
- /**
9
- * Callbacks on page loaded
10
- */
11
- export class PageLoad extends Callbacks<NPageLoad.ICallbacksTypes> {
12
- /** The page is loaded */
13
- private _isLoaded: boolean;
14
-
15
- /** The page is loaded */
16
- get isLoaded() {
17
- return this._isLoaded;
18
- }
19
-
20
- private _loadListener?: IAddEventListener;
21
-
22
- constructor() {
23
- super(false);
24
-
25
- this._isLoaded = false;
26
-
27
- this._init();
28
- }
29
-
30
- protected _init() {
31
- super._init();
32
-
33
- this._setEvents();
34
- }
35
-
36
- protected _setEvents() {
37
- if (document.readyState === 'complete') {
38
- this._handleLoaded();
39
-
40
- return;
41
- }
42
-
43
- this._loadListener = addEventListener(window, 'load', () =>
44
- this._handleLoaded(),
45
- );
46
- }
47
-
48
- /** Callback on page loaded */
49
- protected _handleLoaded() {
50
- const app = getApp();
51
- const { prefix } = app;
52
-
53
- this._isLoaded = true;
54
-
55
- app.html.classList.remove(`${prefix}loading`);
56
- app.body.classList.remove(`${prefix}loading`);
57
-
58
- app.html.classList.add(`${prefix}loaded`);
59
-
60
- this.tbt('loaded', undefined);
61
- }
62
-
63
- /**
64
- * Add a callback on page load.
65
- * If the page is already loaded, the callback will be immediately triggered.
66
- */
67
- public onLoad(callback: () => void) {
68
- if (this.isLoaded) {
69
- callback();
70
-
71
- return undefined;
72
- }
73
-
74
- return this.add('loaded', callback.bind(this));
75
- }
76
-
77
- public destroy() {
78
- super.destroy();
79
-
80
- this._loadListener?.remove();
81
- }
82
- }
@@ -1,13 +0,0 @@
1
- import type { StoryObj, Meta } from '@storybook/react';
2
- import { Component } from '.';
3
-
4
- type TComponent = typeof Component;
5
-
6
- const meta: Meta<TComponent> = {
7
- title: 'Application/PageLoad',
8
- component: Component,
9
- };
10
-
11
- export default meta;
12
-
13
- export const Default: StoryObj<TComponent> = {};
@@ -1,16 +0,0 @@
1
- import React, { FC, useEffect, useState } from 'react';
2
- import { vevet } from '@/src/vevet';
3
-
4
- export const Component: FC = () => {
5
- const [isLoaded, setIsLoaded] = useState(false);
6
-
7
- useEffect(() => {
8
- const onLoad = vevet.pageLoad.onLoad(() => {
9
- setIsLoaded(true);
10
- });
11
-
12
- return () => onLoad?.remove();
13
- }, []);
14
-
15
- return <div>isLoaded: {String(isLoaded)}</div>;
16
- };
@@ -1,7 +0,0 @@
1
- import { NCallbacks } from '@/base/Callbacks/types';
2
-
3
- export namespace NPageLoad {
4
- export interface ICallbacksTypes extends NCallbacks.ITypes {
5
- loaded: undefined;
6
- }
7
- }
@@ -1,242 +0,0 @@
1
- import { IAddEventListener, addEventListener } from 'vevet-dom';
2
- import { Callbacks } from '@/base/Callbacks';
3
- import { EOrientationTypes, ESizeTypes, NViewport } from './types';
4
- import { getApp } from '@/utils/internal/getApp';
5
-
6
- export type { NViewport };
7
-
8
- /**
9
- * Callbacks on window resize
10
- */
11
- export class Viewport extends Callbacks<NViewport.ICallbacksTypes> {
12
- private _width: number;
13
-
14
- get width() {
15
- return this._width;
16
- }
17
-
18
- private _height: number;
19
-
20
- get height() {
21
- return this._height;
22
- }
23
-
24
- get radius() {
25
- return Math.sqrt(this.width ** 2 + this.height ** 2) / 2;
26
- }
27
-
28
- /** VW value */
29
- get vw() {
30
- return this.width / 100;
31
- }
32
-
33
- /** VH value */
34
- get vh() {
35
- return this.height / 100;
36
- }
37
-
38
- /** VR value (viewport radius / 100) */
39
- get vr() {
40
- return this.radius / 100;
41
- }
42
-
43
- /** Width greater than height */
44
- get isLandscape() {
45
- return this.width > this.height;
46
- }
47
-
48
- /** Width less than height */
49
- get isPortrait() {
50
- return this.width < this.height;
51
- }
52
-
53
- /** Is desktop size */
54
- get isDesktop() {
55
- return this.width > getApp().props.tablet;
56
- }
57
-
58
- /** Is tablet size */
59
- get isTablet() {
60
- return (
61
- this.width <= getApp().props.tablet && this.width > getApp().props.phone
62
- );
63
- }
64
-
65
- /** Is phone size */
66
- get isPhone() {
67
- return this.width <= getApp().props.phone;
68
- }
69
-
70
- /**
71
- * Device pixel ratio
72
- */
73
- get dpr() {
74
- return window.devicePixelRatio;
75
- }
76
-
77
- /**
78
- * Device pixel ratio. For non-mobile devices it is always 1.
79
- */
80
- get lowerDesktopDpr() {
81
- if (getApp().isDesktop) {
82
- return 1;
83
- }
84
-
85
- return this.dpr;
86
- }
87
-
88
- private _resizeTimeout?: NodeJS.Timeout;
89
-
90
- private _resizeListener?: IAddEventListener;
91
-
92
- constructor() {
93
- super(false);
94
-
95
- this._width = 0;
96
- this._height = 0;
97
-
98
- this._init();
99
- }
100
-
101
- protected _init() {
102
- this._updateValues();
103
-
104
- this._setEvents();
105
- }
106
-
107
- /** Set events on resize */
108
- private _setEvents() {
109
- this._resizeListener = addEventListener(window, 'resize', () => {
110
- if (this._resizeTimeout) {
111
- clearTimeout(this._resizeTimeout);
112
- this._resizeTimeout = undefined;
113
- }
114
-
115
- this._resizeTimeout = setTimeout(() => {
116
- this._onResize();
117
- this._resizeTimeout = undefined;
118
- }, getApp().props.resizeDebounce);
119
- });
120
- }
121
-
122
- /** Set viewport values */
123
- private _updateValues() {
124
- const { html, props } = getApp();
125
-
126
- // get width
127
- const width =
128
- props.widthDetection === 'boundingRect'
129
- ? parseFloat(html.getBoundingClientRect().width.toFixed(3))
130
- : html.clientWidth;
131
-
132
- // set sizes
133
- this._width = width;
134
- this._height = html.clientHeight;
135
-
136
- // update states
137
- this._updateClassNames();
138
- this._updateCSSVars();
139
- }
140
-
141
- /** Change classes of the document element */
142
- private _updateClassNames() {
143
- const viewportSizeTypes: ESizeTypes[] = [
144
- ESizeTypes.Desktop,
145
- ESizeTypes.Tablet,
146
- ESizeTypes.Phone,
147
- ];
148
-
149
- if (this.isDesktop) {
150
- this._updateBreakpointClassNames(ESizeTypes.Desktop, viewportSizeTypes);
151
- } else if (this.isTablet) {
152
- this._updateBreakpointClassNames(ESizeTypes.Tablet, viewportSizeTypes);
153
- } else {
154
- this._updateBreakpointClassNames(ESizeTypes.Phone, viewportSizeTypes);
155
- }
156
-
157
- const orientationTypes: EOrientationTypes[] = [
158
- EOrientationTypes.Landscape,
159
- EOrientationTypes.Portrait,
160
- ];
161
-
162
- if (this.isLandscape) {
163
- this._updateBreakpointClassNames(
164
- EOrientationTypes.Landscape,
165
- orientationTypes,
166
- );
167
- } else if (this.isPortrait) {
168
- this._updateBreakpointClassNames(
169
- EOrientationTypes.Portrait,
170
- orientationTypes,
171
- );
172
- } else {
173
- this._updateBreakpointClassNames('', orientationTypes);
174
- }
175
- }
176
-
177
- /** Change breakpoint classes of the document element */
178
- private _updateBreakpointClassNames(activeType: string, types: string[]) {
179
- const { html, prefix } = getApp();
180
-
181
- types.forEach((type) => {
182
- if (type === activeType) {
183
- html.classList.add(`${prefix}viewport-${type}`);
184
- } else {
185
- html.classList.remove(`${prefix}viewport-${type}`);
186
- }
187
- });
188
- }
189
-
190
- /** Update CSS vars */
191
- private _updateCSSVars() {
192
- const { html } = getApp();
193
-
194
- html.style.setProperty('--vw', `${this.vw}px`);
195
- html.style.setProperty('--vh', `${this.vh}px`);
196
- html.style.setProperty('--vr', `${this.vr}px`);
197
- }
198
-
199
- /** Launch callbacks on resize. */
200
- private _onResize() {
201
- const { _width: prevWidth, _height: prevHeight } = this;
202
-
203
- this._updateValues();
204
-
205
- const { width, height } = this;
206
-
207
- // get changes in viewport
208
- const changes: NViewport.IChanges = {
209
- isWidthChanged: width !== prevWidth,
210
- isHeightChanged: height !== prevHeight,
211
- isOrientationChanged: width > height !== prevWidth > prevHeight,
212
- };
213
-
214
- if (width !== prevWidth && height === prevHeight) {
215
- this.tbt('widthOnly', changes);
216
- }
217
- if (height !== prevHeight && width === prevWidth) {
218
- this.tbt('heightOnly', changes);
219
- }
220
- if (width !== prevWidth && height !== prevHeight) {
221
- this.tbt('both', changes);
222
- }
223
- if (width !== prevWidth) {
224
- this.tbt('width', changes);
225
- }
226
- if (height !== prevHeight) {
227
- this.tbt('height', changes);
228
- }
229
-
230
- this.tbt('any', changes);
231
- }
232
-
233
- public destroy() {
234
- super.destroy();
235
-
236
- if (this._resizeTimeout) {
237
- clearTimeout(this._resizeTimeout);
238
- }
239
-
240
- this._resizeListener?.remove();
241
- }
242
- }