katanakit-js 2.2.1 → 2.12.9
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/README.md +72 -437
- package/dist/adapters/astro/astro.service.d.ts +103 -15
- package/dist/adapters/astro/astro.service.d.ts.map +1 -1
- package/dist/adapters/astro/astro.service.js +145 -75
- package/dist/adapters/astro/astro.service.js.map +1 -1
- package/dist/adapters/astro/index.d.ts +1 -1
- package/dist/adapters/astro/index.d.ts.map +1 -1
- package/dist/adapters/astro/index.js +1 -1
- package/dist/adapters/astro/index.js.map +1 -1
- package/dist/adapters/astro/rss.service.d.ts +85 -105
- package/dist/adapters/astro/rss.service.d.ts.map +1 -1
- package/dist/adapters/astro/rss.service.js +172 -168
- package/dist/adapters/astro/rss.service.js.map +1 -1
- package/dist/adapters/astro/seo.service.d.ts +10 -0
- package/dist/adapters/astro/seo.service.d.ts.map +1 -0
- package/dist/adapters/astro/seo.service.js +3 -0
- package/dist/adapters/astro/seo.service.js.map +1 -0
- package/dist/adapters/express/app.d.ts +30 -1
- package/dist/adapters/express/app.d.ts.map +1 -1
- package/dist/adapters/express/app.js +31 -3
- package/dist/adapters/express/app.js.map +1 -1
- package/dist/adapters/express/index.d.ts +2 -2
- package/dist/adapters/express/index.d.ts.map +1 -1
- package/dist/adapters/express/index.js +2 -2
- package/dist/adapters/express/index.js.map +1 -1
- package/dist/adapters/express/main.js +2 -2
- package/dist/adapters/express/main.js.map +1 -1
- package/dist/adapters/express/products.controller.d.ts +67 -8
- package/dist/adapters/express/products.controller.d.ts.map +1 -1
- package/dist/adapters/express/products.controller.js +105 -49
- package/dist/adapters/express/products.controller.js.map +1 -1
- package/dist/adapters/express/server.d.ts +37 -13
- package/dist/adapters/express/server.d.ts.map +1 -1
- package/dist/adapters/express/server.js +118 -53
- package/dist/adapters/express/server.js.map +1 -1
- package/dist/adapters/nuxt/nuxt.service.d.ts +8 -6
- package/dist/adapters/nuxt/nuxt.service.d.ts.map +1 -1
- package/dist/adapters/nuxt/nuxt.service.js +34 -10
- package/dist/adapters/nuxt/nuxt.service.js.map +1 -1
- package/dist/adapters/vue/vue.service.d.ts +5 -2
- package/dist/adapters/vue/vue.service.d.ts.map +1 -1
- package/dist/adapters/vue/vue.service.js +41 -7
- package/dist/adapters/vue/vue.service.js.map +1 -1
- package/dist/config/index.d.ts +2 -1
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +1 -1
- package/dist/config/index.js.map +1 -1
- package/dist/config/seo-meta.types.d.ts +177 -0
- package/dist/config/seo-meta.types.d.ts.map +1 -0
- package/dist/config/seo-meta.types.js +11 -0
- package/dist/config/seo-meta.types.js.map +1 -0
- package/dist/config/seo.service.d.ts +41 -58
- package/dist/config/seo.service.d.ts.map +1 -1
- package/dist/config/seo.service.js +468 -136
- package/dist/config/seo.service.js.map +1 -1
- package/dist/config/site.config.d.ts +10 -50
- package/dist/config/site.config.d.ts.map +1 -1
- package/dist/config/site.config.js +8 -36
- package/dist/config/site.config.js.map +1 -1
- package/dist/core/index.d.ts +1 -3
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +1 -3
- package/dist/core/index.js.map +1 -1
- package/dist/core/services/dates.service.d.ts +149 -22
- package/dist/core/services/dates.service.d.ts.map +1 -1
- package/dist/core/services/dates.service.js +201 -54
- package/dist/core/services/dates.service.js.map +1 -1
- package/dist/core/services/error.service.d.ts +32 -20
- package/dist/core/services/error.service.d.ts.map +1 -1
- package/dist/core/services/error.service.js +44 -32
- package/dist/core/services/error.service.js.map +1 -1
- package/dist/core/services/formatter.service.d.ts +245 -35
- package/dist/core/services/formatter.service.d.ts.map +1 -1
- package/dist/core/services/formatter.service.js +281 -57
- package/dist/core/services/formatter.service.js.map +1 -1
- package/dist/core/services/generator.service.d.ts +115 -26
- package/dist/core/services/generator.service.d.ts.map +1 -1
- package/dist/core/services/generator.service.js +191 -56
- package/dist/core/services/generator.service.js.map +1 -1
- package/dist/core/services/geometry.service.d.ts +369 -39
- package/dist/core/services/geometry.service.d.ts.map +1 -1
- package/dist/core/services/geometry.service.js +424 -66
- package/dist/core/services/geometry.service.js.map +1 -1
- package/dist/core/services/http.service.d.ts +244 -21
- package/dist/core/services/http.service.d.ts.map +1 -1
- package/dist/core/services/http.service.js +419 -98
- package/dist/core/services/http.service.js.map +1 -1
- package/dist/core/services/logger.service.d.ts +95 -29
- package/dist/core/services/logger.service.d.ts.map +1 -1
- package/dist/core/services/logger.service.js +167 -41
- package/dist/core/services/logger.service.js.map +1 -1
- package/dist/core/services/reactive.service.d.ts +146 -19
- package/dist/core/services/reactive.service.d.ts.map +1 -1
- package/dist/core/services/reactive.service.js +278 -137
- package/dist/core/services/reactive.service.js.map +1 -1
- package/dist/core/services/timing.service.d.ts +142 -20
- package/dist/core/services/timing.service.d.ts.map +1 -1
- package/dist/core/services/timing.service.js +324 -185
- package/dist/core/services/timing.service.js.map +1 -1
- package/dist/core/services/utils.service.d.ts +228 -43
- package/dist/core/services/utils.service.d.ts.map +1 -1
- package/dist/core/services/utils.service.js +305 -125
- package/dist/core/services/utils.service.js.map +1 -1
- package/dist/infrastructure/dom/dom.service.d.ts +307 -44
- package/dist/infrastructure/dom/dom.service.d.ts.map +1 -1
- package/dist/infrastructure/dom/dom.service.js +408 -129
- package/dist/infrastructure/dom/dom.service.js.map +1 -1
- package/dist/infrastructure/index.d.ts +0 -3
- package/dist/infrastructure/index.d.ts.map +1 -1
- package/dist/infrastructure/index.js +0 -3
- package/dist/infrastructure/index.js.map +1 -1
- package/dist/infrastructure/observer/observer.service.d.ts +124 -31
- package/dist/infrastructure/observer/observer.service.d.ts.map +1 -1
- package/dist/infrastructure/observer/observer.service.js +227 -131
- package/dist/infrastructure/observer/observer.service.js.map +1 -1
- package/dist/infrastructure/sensors/sensors.service.d.ts +154 -22
- package/dist/infrastructure/sensors/sensors.service.d.ts.map +1 -1
- package/dist/infrastructure/sensors/sensors.service.js +264 -112
- package/dist/infrastructure/sensors/sensors.service.js.map +1 -1
- package/dist/infrastructure/storage/storage.service.d.ts +123 -45
- package/dist/infrastructure/storage/storage.service.d.ts.map +1 -1
- package/dist/infrastructure/storage/storage.service.js +236 -66
- package/dist/infrastructure/storage/storage.service.js.map +1 -1
- package/dist/infrastructure/theme/theme.service.d.ts +93 -29
- package/dist/infrastructure/theme/theme.service.d.ts.map +1 -1
- package/dist/infrastructure/theme/theme.service.js +198 -96
- package/dist/infrastructure/theme/theme.service.js.map +1 -1
- package/dist/infrastructure/viewport/viewport.service.d.ts +233 -35
- package/dist/infrastructure/viewport/viewport.service.d.ts.map +1 -1
- package/dist/infrastructure/viewport/viewport.service.js +358 -139
- package/dist/infrastructure/viewport/viewport.service.js.map +1 -1
- package/dist/infrastructure/worker/worker.service.d.ts +84 -38
- package/dist/infrastructure/worker/worker.service.d.ts.map +1 -1
- package/dist/infrastructure/worker/worker.service.js +234 -133
- package/dist/infrastructure/worker/worker.service.js.map +1 -1
- package/dist/prisma/index.d.ts +2 -0
- package/dist/prisma/index.d.ts.map +1 -0
- package/dist/prisma/index.js +2 -0
- package/dist/prisma/index.js.map +1 -0
- package/dist/prisma/schema.json +11 -33
- package/dist/prisma/use-prisma.d.ts +68 -0
- package/dist/prisma/use-prisma.d.ts.map +1 -0
- package/dist/prisma/use-prisma.js +82 -0
- package/dist/prisma/use-prisma.js.map +1 -0
- package/dist/types/index.d.ts +20 -12
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +124 -125
- package/CHANGELOG.md +0 -101
|
@@ -1,145 +1,364 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// Internal helpers
|
|
3
|
+
// ============================================================
|
|
1
4
|
/**
|
|
2
|
-
*
|
|
5
|
+
* Checks whether the code is running in a browser environment.
|
|
6
|
+
*
|
|
7
|
+
* @returns `true` if both `window` and `document` are defined.
|
|
3
8
|
*/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
9
|
+
function isBrowser() {
|
|
10
|
+
return typeof window !== "undefined" && typeof document !== "undefined";
|
|
11
|
+
}
|
|
12
|
+
// ============================================================
|
|
13
|
+
// Module-level state (temporary title)
|
|
14
|
+
// ============================================================
|
|
15
|
+
let tempTitleTimer;
|
|
16
|
+
let tempTitleOriginal;
|
|
17
|
+
// ============================================================
|
|
18
|
+
// Public API
|
|
19
|
+
// ============================================================
|
|
20
|
+
/**
|
|
21
|
+
* Returns the current viewport dimensions.
|
|
22
|
+
*
|
|
23
|
+
* @returns A {@link ViewportSize} object with `width` and `height` (or `{0, 0}` in SSR).
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* const { width, height } = useGetViewportSize();
|
|
28
|
+
* if (width < 768) { /* mobile */ }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export const useGetViewportSize = () => {
|
|
32
|
+
if (!isBrowser())
|
|
33
|
+
return { width: 0, height: 0 };
|
|
34
|
+
return { width: window.innerWidth, height: window.innerHeight };
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Tests a CSS media query against the current viewport.
|
|
38
|
+
*
|
|
39
|
+
* @param query - A CSS media query string (e.g. `"(min-width: 768px)"`).
|
|
40
|
+
* @returns `true` if the query matches.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* if (useMatchesMedia("(prefers-reduced-motion: reduce)")) {
|
|
45
|
+
* // disable animations
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export const useMatchesMedia = (query) => {
|
|
50
|
+
if (!isBrowser() || !window.matchMedia)
|
|
51
|
+
return false;
|
|
52
|
+
return window.matchMedia(query).matches;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Checks whether the user prefers reduced motion.
|
|
56
|
+
*
|
|
57
|
+
* @returns `true` if `prefers-reduced-motion: reduce` is active.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts
|
|
61
|
+
* const smooth = !usePrefersReducedMotion();
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export const usePrefersReducedMotion = () => useMatchesMedia("(prefers-reduced-motion: reduce)");
|
|
65
|
+
/**
|
|
66
|
+
* Checks whether the user's OS prefers dark mode.
|
|
67
|
+
*
|
|
68
|
+
* @returns `true` if `prefers-color-scheme: dark` is active.
|
|
69
|
+
*/
|
|
70
|
+
export const usePrefersDarkMode = () => useMatchesMedia("(prefers-color-scheme: dark)");
|
|
71
|
+
/**
|
|
72
|
+
* Returns the current vertical scroll position.
|
|
73
|
+
*
|
|
74
|
+
* @returns `window.scrollY` or `0` in SSR.
|
|
75
|
+
*/
|
|
76
|
+
export const useGetScrollY = () => (isBrowser() ? window.scrollY : 0);
|
|
77
|
+
/**
|
|
78
|
+
* Returns the current horizontal scroll position.
|
|
79
|
+
*
|
|
80
|
+
* @returns `window.scrollX` or `0` in SSR.
|
|
81
|
+
*/
|
|
82
|
+
export const useGetScrollX = () => (isBrowser() ? window.scrollX : 0);
|
|
83
|
+
/**
|
|
84
|
+
* Returns the current scroll position as `{ x, y }`.
|
|
85
|
+
*
|
|
86
|
+
* @returns A {@link ScrollPosition} object.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```ts
|
|
90
|
+
* const { x, y } = useGetScrollPosition();
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
export const useGetScrollPosition = () => ({
|
|
94
|
+
x: useGetScrollX(),
|
|
95
|
+
y: useGetScrollY(),
|
|
96
|
+
});
|
|
97
|
+
/**
|
|
98
|
+
* Returns the vertical scroll progress as a value between `0` (top) and `1` (bottom).
|
|
99
|
+
*
|
|
100
|
+
* @returns A number in `[0, 1]`.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```ts
|
|
104
|
+
* const progress = useGetScrollProgress();
|
|
105
|
+
* progressBar.style.width = `${progress * 100}%`;
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
export const useGetScrollProgress = () => {
|
|
109
|
+
if (!isBrowser())
|
|
110
|
+
return 0;
|
|
111
|
+
const scrollHeight = document.documentElement.scrollHeight - window.innerHeight;
|
|
112
|
+
if (scrollHeight <= 0)
|
|
113
|
+
return 0;
|
|
114
|
+
return Math.min(1, Math.max(0, window.scrollY / scrollHeight));
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* Checks whether the page is scrolled to (or near) the top.
|
|
118
|
+
*
|
|
119
|
+
* @param threshold - Pixel tolerance (default: `0`).
|
|
120
|
+
* @returns `true` if `scrollY <= threshold`.
|
|
121
|
+
*/
|
|
122
|
+
export const useIsAtTop = (threshold = 0) => useGetScrollY() <= threshold;
|
|
123
|
+
/**
|
|
124
|
+
* Checks whether the page is scrolled to (or near) the bottom.
|
|
125
|
+
*
|
|
126
|
+
* @param threshold - Pixel tolerance from the bottom (default: `50`).
|
|
127
|
+
* @returns `true` if within `threshold` pixels of the bottom.
|
|
128
|
+
*/
|
|
129
|
+
export const useIsAtBottom = (threshold = 50) => {
|
|
130
|
+
if (!isBrowser())
|
|
131
|
+
return false;
|
|
132
|
+
const scrollHeight = document.documentElement.scrollHeight;
|
|
133
|
+
return window.scrollY + window.innerHeight >= scrollHeight - threshold;
|
|
134
|
+
};
|
|
135
|
+
/**
|
|
136
|
+
* Scrolls the window to a specific position, respecting `prefers-reduced-motion`.
|
|
137
|
+
*
|
|
138
|
+
* @param x - Horizontal scroll target (default: `0`).
|
|
139
|
+
* @param y - Vertical scroll target (default: `0`).
|
|
140
|
+
* @param behavior - Scroll behavior (default: `"smooth"`).
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* ```ts
|
|
144
|
+
* useScrollTo(0, 500); // scroll to 500px from top
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
export const useScrollTo = (x = 0, y = 0, behavior = "smooth") => {
|
|
148
|
+
if (!isBrowser())
|
|
149
|
+
return;
|
|
150
|
+
const finalBehavior = usePrefersReducedMotion() ? "auto" : behavior;
|
|
151
|
+
window.scrollTo({ top: y, left: x, behavior: finalBehavior });
|
|
152
|
+
};
|
|
153
|
+
/**
|
|
154
|
+
* Scrolls to the top of the page.
|
|
155
|
+
*
|
|
156
|
+
* @param smooth - Whether to use smooth scrolling (default: `true`).
|
|
157
|
+
*/
|
|
158
|
+
export const useScrollToTop = (smooth = true) => {
|
|
159
|
+
if (!isBrowser())
|
|
160
|
+
return;
|
|
161
|
+
const behavior = smooth && !usePrefersReducedMotion() ? "smooth" : "auto";
|
|
162
|
+
window.scrollTo({ top: 0, behavior });
|
|
163
|
+
};
|
|
164
|
+
/**
|
|
165
|
+
* Scrolls to the bottom of the page.
|
|
166
|
+
*
|
|
167
|
+
* @param smooth - Whether to use smooth scrolling (default: `true`).
|
|
168
|
+
*/
|
|
169
|
+
export const useScrollToBottom = (smooth = true) => {
|
|
170
|
+
if (!isBrowser())
|
|
171
|
+
return;
|
|
172
|
+
const behavior = smooth && !usePrefersReducedMotion() ? "smooth" : "auto";
|
|
173
|
+
const scrollHeight = document.documentElement.scrollHeight;
|
|
174
|
+
window.scrollTo({ top: scrollHeight, behavior });
|
|
175
|
+
};
|
|
176
|
+
/**
|
|
177
|
+
* Scrolls an element into view.
|
|
178
|
+
*
|
|
179
|
+
* @param target - An HTMLElement or a CSS selector string.
|
|
180
|
+
* @param options - Scroll options (`behavior`, `block`, `inline`).
|
|
181
|
+
* @returns `true` if the element was found and scrolled to.
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* ```ts
|
|
185
|
+
* useScrollToElement("#section-2", { behavior: "smooth", block: "start" });
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
188
|
+
export const useScrollToElement = (target, options = {}) => {
|
|
189
|
+
if (!isBrowser())
|
|
190
|
+
return false;
|
|
191
|
+
const element = typeof target === "string" ? document.querySelector(target) : target;
|
|
192
|
+
if (!element)
|
|
193
|
+
return false;
|
|
194
|
+
const behavior = usePrefersReducedMotion()
|
|
195
|
+
? "auto"
|
|
196
|
+
: (options.behavior ?? "smooth");
|
|
197
|
+
element.scrollIntoView({
|
|
198
|
+
behavior,
|
|
199
|
+
block: options.block ?? "start",
|
|
200
|
+
inline: options.inline ?? "nearest",
|
|
31
201
|
});
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
202
|
+
return true;
|
|
203
|
+
};
|
|
204
|
+
/**
|
|
205
|
+
* Triggers the browser print dialog.
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* ```ts
|
|
209
|
+
* usePrintPage();
|
|
210
|
+
* ```
|
|
211
|
+
*/
|
|
212
|
+
export const usePrintPage = () => {
|
|
213
|
+
if (isBrowser())
|
|
214
|
+
window.print();
|
|
215
|
+
};
|
|
216
|
+
/**
|
|
217
|
+
* Focuses an element.
|
|
218
|
+
*
|
|
219
|
+
* @param target - An HTMLElement or a CSS selector string.
|
|
220
|
+
* @returns `true` if the element was found and focused.
|
|
221
|
+
*
|
|
222
|
+
* @example
|
|
223
|
+
* ```ts
|
|
224
|
+
* useFocusElement("#search-input");
|
|
225
|
+
* ```
|
|
226
|
+
*/
|
|
227
|
+
export const useFocusElement = (target) => {
|
|
228
|
+
if (!isBrowser())
|
|
229
|
+
return false;
|
|
230
|
+
const element = typeof target === "string" ? document.querySelector(target) : target;
|
|
231
|
+
if (!element)
|
|
232
|
+
return false;
|
|
233
|
+
element.focus();
|
|
234
|
+
return true;
|
|
235
|
+
};
|
|
236
|
+
/**
|
|
237
|
+
* Removes focus from the currently active element.
|
|
238
|
+
*/
|
|
239
|
+
export const useBlurActiveElement = () => {
|
|
240
|
+
if (!isBrowser())
|
|
241
|
+
return;
|
|
242
|
+
document.activeElement?.blur();
|
|
243
|
+
};
|
|
244
|
+
/**
|
|
245
|
+
* Returns the currently focused element.
|
|
246
|
+
*
|
|
247
|
+
* @returns The active element, or `null` in SSR.
|
|
248
|
+
*/
|
|
249
|
+
export const useGetActiveElement = () => isBrowser() ? document.activeElement : null;
|
|
250
|
+
/**
|
|
251
|
+
* Requests fullscreen on the given element (or the document root).
|
|
252
|
+
*
|
|
253
|
+
* @param target - The element to make fullscreen (defaults to `document.documentElement`).
|
|
254
|
+
* @throws {Error} If fullscreen is not supported.
|
|
255
|
+
*
|
|
256
|
+
* @example
|
|
257
|
+
* ```ts
|
|
258
|
+
* await useRequestFullscreen(videoElement);
|
|
259
|
+
* ```
|
|
260
|
+
*/
|
|
261
|
+
export const useRequestFullscreen = async (target) => {
|
|
262
|
+
if (!isBrowser() || !document.fullscreenEnabled) {
|
|
263
|
+
throw new Error("Fullscreen not supported");
|
|
264
|
+
}
|
|
265
|
+
const element = target ?? document.documentElement;
|
|
266
|
+
await element.requestFullscreen();
|
|
267
|
+
};
|
|
268
|
+
/**
|
|
269
|
+
* Exits fullscreen mode.
|
|
270
|
+
*/
|
|
271
|
+
export const useExitFullscreen = async () => {
|
|
272
|
+
if (!isBrowser() || !document.fullscreenElement)
|
|
273
|
+
return;
|
|
274
|
+
await document.exitFullscreen();
|
|
275
|
+
};
|
|
276
|
+
/**
|
|
277
|
+
* Checks whether the document is currently in fullscreen mode.
|
|
278
|
+
*
|
|
279
|
+
* @returns `true` if fullscreen is active.
|
|
280
|
+
*/
|
|
281
|
+
export const useIsFullscreen = () => isBrowser() && !!document.fullscreenElement;
|
|
282
|
+
/**
|
|
283
|
+
* Checks whether the document tab is currently visible.
|
|
284
|
+
*
|
|
285
|
+
* @returns `true` if `document.visibilityState === "visible"`.
|
|
286
|
+
*/
|
|
287
|
+
export const useIsDocumentVisible = () => {
|
|
288
|
+
if (!isBrowser())
|
|
93
289
|
return true;
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
290
|
+
return document.visibilityState === "visible";
|
|
291
|
+
};
|
|
292
|
+
/**
|
|
293
|
+
* Registers a callback for document visibility changes.
|
|
294
|
+
*
|
|
295
|
+
* @param callback - Called with `true` when visible, `false` when hidden.
|
|
296
|
+
* @returns A cleanup function that removes the listener.
|
|
297
|
+
*
|
|
298
|
+
* @example
|
|
299
|
+
* ```ts
|
|
300
|
+
* const off = useOnVisibilityChange((visible) => {
|
|
301
|
+
* if (visible) resumePolling();
|
|
302
|
+
* else pausePolling();
|
|
303
|
+
* });
|
|
304
|
+
* ```
|
|
305
|
+
*/
|
|
306
|
+
export const useOnVisibilityChange = (callback) => {
|
|
307
|
+
if (!isBrowser())
|
|
308
|
+
return () => { };
|
|
309
|
+
const handler = () => callback(useIsDocumentVisible());
|
|
310
|
+
document.addEventListener("visibilitychange", handler);
|
|
311
|
+
return () => document.removeEventListener("visibilitychange", handler);
|
|
312
|
+
};
|
|
313
|
+
/**
|
|
314
|
+
* Returns the current document title.
|
|
315
|
+
*
|
|
316
|
+
* @returns The title string, or `""` in SSR.
|
|
317
|
+
*/
|
|
318
|
+
export const useGetTitle = () => (isBrowser() ? document.title : "");
|
|
319
|
+
/**
|
|
320
|
+
* Sets the document title.
|
|
321
|
+
*
|
|
322
|
+
* @param title - The new title.
|
|
323
|
+
*
|
|
324
|
+
* @example
|
|
325
|
+
* ```ts
|
|
326
|
+
* useSetTitle("My Page");
|
|
327
|
+
* ```
|
|
328
|
+
*/
|
|
329
|
+
export const useSetTitle = (title) => {
|
|
330
|
+
if (isBrowser())
|
|
331
|
+
document.title = title;
|
|
332
|
+
};
|
|
333
|
+
/**
|
|
334
|
+
* Temporarily changes the document title, restoring the original after `durationMs`.
|
|
335
|
+
*
|
|
336
|
+
* @param tempTitle - The temporary title to display.
|
|
337
|
+
* @param durationMs - How long to show it (default: `3000`).
|
|
338
|
+
*
|
|
339
|
+
* @example
|
|
340
|
+
* ```ts
|
|
341
|
+
* useSetTempTitle("(2) New messages!", 5000);
|
|
342
|
+
* // title reverts after 5 seconds
|
|
343
|
+
* ```
|
|
344
|
+
*/
|
|
345
|
+
export const useSetTempTitle = (tempTitle, durationMs = 3000) => {
|
|
346
|
+
if (!isBrowser())
|
|
347
|
+
return;
|
|
348
|
+
if (tempTitleTimer !== undefined) {
|
|
349
|
+
clearTimeout(tempTitleTimer);
|
|
350
|
+
tempTitleTimer = undefined;
|
|
351
|
+
}
|
|
352
|
+
if (tempTitleOriginal === undefined) {
|
|
353
|
+
tempTitleOriginal = document.title;
|
|
354
|
+
}
|
|
355
|
+
document.title = tempTitle;
|
|
356
|
+
tempTitleTimer = setTimeout(() => {
|
|
357
|
+
if (document.title === tempTitle && tempTitleOriginal !== undefined) {
|
|
358
|
+
document.title = tempTitleOriginal;
|
|
104
359
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
if (!this.isBrowser() || !document.fullscreenElement)
|
|
110
|
-
return;
|
|
111
|
-
await document.exitFullscreen();
|
|
112
|
-
};
|
|
113
|
-
useIsFullscreen = () => this.isBrowser() && !!document.fullscreenElement;
|
|
114
|
-
useIsDocumentVisible = () => {
|
|
115
|
-
if (!this.isBrowser())
|
|
116
|
-
return true;
|
|
117
|
-
return document.visibilityState === "visible";
|
|
118
|
-
};
|
|
119
|
-
useOnVisibilityChange = (callback) => {
|
|
120
|
-
if (!this.isBrowser())
|
|
121
|
-
return () => { };
|
|
122
|
-
const handler = () => callback(this.useIsDocumentVisible());
|
|
123
|
-
document.addEventListener("visibilitychange", handler);
|
|
124
|
-
return () => document.removeEventListener("visibilitychange", handler);
|
|
125
|
-
};
|
|
126
|
-
useGetTitle = () => (this.isBrowser() ? document.title : "");
|
|
127
|
-
useSetTitle = (title) => {
|
|
128
|
-
if (this.isBrowser())
|
|
129
|
-
document.title = title;
|
|
130
|
-
};
|
|
131
|
-
useSetTempTitle = (tempTitle, durationMs = 3000) => {
|
|
132
|
-
if (!this.isBrowser())
|
|
133
|
-
return;
|
|
134
|
-
const original = document.title;
|
|
135
|
-
document.title = tempTitle;
|
|
136
|
-
setTimeout(() => {
|
|
137
|
-
if (document.title === tempTitle) {
|
|
138
|
-
document.title = original;
|
|
139
|
-
}
|
|
140
|
-
}, durationMs);
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
// Singleton instance and destructured exports.
|
|
144
|
-
export const { useGetViewportSize, useMatchesMedia, usePrefersReducedMotion, usePrefersDarkMode, useGetScrollY, useGetScrollX, useGetScrollPosition, useGetScrollProgress, useIsAtTop, useIsAtBottom, useScrollTo, useScrollToTop, useScrollToBottom, useScrollToElement, usePrintPage, useFocusElement, useBlurActiveElement, useGetActiveElement, useRequestFullscreen, useExitFullscreen, useIsFullscreen, useIsDocumentVisible, useOnVisibilityChange, useGetTitle, useSetTitle, useSetTempTitle, } = ViewportService.getInstance();
|
|
360
|
+
tempTitleOriginal = undefined;
|
|
361
|
+
tempTitleTimer = undefined;
|
|
362
|
+
}, durationMs);
|
|
363
|
+
};
|
|
145
364
|
//# sourceMappingURL=viewport.service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"viewport.service.js","sourceRoot":"","sources":["../../../src/infrastructure/viewport/viewport.service.ts"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"viewport.service.js","sourceRoot":"","sources":["../../../src/infrastructure/viewport/viewport.service.ts"],"names":[],"mappings":"AAEA,+DAA+D;AAC/D,mBAAmB;AACnB,+DAA+D;AAE/D;;;;GAIG;AACH,SAAS,SAAS;IACjB,OAAO,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,QAAQ,KAAK,WAAW,CAAC;AACzE,CAAC;AAED,+DAA+D;AAC/D,uCAAuC;AACvC,+DAA+D;AAE/D,IAAI,cAAyD,CAAC;AAC9D,IAAI,iBAAqC,CAAC;AAE1C,+DAA+D;AAC/D,aAAa;AACb,+DAA+D;AAE/D;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAiB,EAAE;IACpD,IAAI,CAAC,SAAS,EAAE;QAAE,OAAO,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC;IACjD,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,CAAC,WAAW,EAAE,CAAC;AACjE,CAAC,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,KAAa,EAAW,EAAE;IACzD,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,MAAM,CA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