@bquery/bquery 1.3.0 → 1.5.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/README.md +546 -501
- package/dist/component/component.d.ts.map +1 -1
- package/dist/component/index.d.ts +2 -0
- package/dist/component/index.d.ts.map +1 -1
- package/dist/component/library.d.ts +34 -0
- package/dist/component/library.d.ts.map +1 -0
- package/dist/component/types.d.ts +10 -6
- package/dist/component/types.d.ts.map +1 -1
- package/dist/component-CY5MVoYN.js +531 -0
- package/dist/component-CY5MVoYN.js.map +1 -0
- package/dist/component.es.mjs +6 -184
- package/dist/config-DRmZZno3.js +40 -0
- package/dist/config-DRmZZno3.js.map +1 -0
- package/dist/core/collection.d.ts +19 -3
- package/dist/core/collection.d.ts.map +1 -1
- package/dist/core/element.d.ts +23 -4
- package/dist/core/element.d.ts.map +1 -1
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/utils/function.d.ts +21 -4
- package/dist/core/utils/function.d.ts.map +1 -1
- package/dist/core-CK2Mfpf4.js +648 -0
- package/dist/core-CK2Mfpf4.js.map +1 -0
- package/dist/core-DPdbItcq.js +112 -0
- package/dist/core-DPdbItcq.js.map +1 -0
- package/dist/core.es.mjs +45 -1218
- package/dist/full.d.ts +6 -6
- package/dist/full.d.ts.map +1 -1
- package/dist/full.es.mjs +98 -92
- package/dist/full.iife.js +173 -3
- package/dist/full.iife.js.map +1 -1
- package/dist/full.umd.js +173 -3
- package/dist/full.umd.js.map +1 -1
- package/dist/index.es.mjs +143 -139
- package/dist/motion/transition.d.ts +1 -1
- package/dist/motion/transition.d.ts.map +1 -1
- package/dist/motion/types.d.ts +11 -1
- package/dist/motion/types.d.ts.map +1 -1
- package/dist/motion-C5DRdPnO.js +415 -0
- package/dist/motion-C5DRdPnO.js.map +1 -0
- package/dist/motion.es.mjs +25 -361
- package/dist/object-qGpWr6-J.js +38 -0
- package/dist/object-qGpWr6-J.js.map +1 -0
- package/dist/platform/announcer.d.ts +59 -0
- package/dist/platform/announcer.d.ts.map +1 -0
- package/dist/platform/config.d.ts +92 -0
- package/dist/platform/config.d.ts.map +1 -0
- package/dist/platform/cookies.d.ts +45 -0
- package/dist/platform/cookies.d.ts.map +1 -0
- package/dist/platform/index.d.ts +8 -0
- package/dist/platform/index.d.ts.map +1 -1
- package/dist/platform/meta.d.ts +62 -0
- package/dist/platform/meta.d.ts.map +1 -0
- package/dist/platform/storage.d.ts.map +1 -1
- package/dist/platform-B7JhGBc7.js +361 -0
- package/dist/platform-B7JhGBc7.js.map +1 -0
- package/dist/platform.es.mjs +11 -243
- package/dist/reactive/async-data.d.ts +114 -0
- package/dist/reactive/async-data.d.ts.map +1 -0
- package/dist/reactive/core.d.ts +12 -0
- package/dist/reactive/core.d.ts.map +1 -1
- package/dist/reactive/effect.d.ts.map +1 -1
- package/dist/reactive/index.d.ts +2 -2
- package/dist/reactive/index.d.ts.map +1 -1
- package/dist/reactive/internals.d.ts +6 -0
- package/dist/reactive/internals.d.ts.map +1 -1
- package/dist/reactive/signal.d.ts +2 -0
- package/dist/reactive/signal.d.ts.map +1 -1
- package/dist/reactive-BDya-ia8.js +253 -0
- package/dist/reactive-BDya-ia8.js.map +1 -0
- package/dist/reactive.es.mjs +18 -34
- package/dist/router-CijiICxt.js +188 -0
- package/dist/router-CijiICxt.js.map +1 -0
- package/dist/router.es.mjs +11 -200
- package/dist/sanitize-jyJ2ryE2.js +302 -0
- package/dist/sanitize-jyJ2ryE2.js.map +1 -0
- package/dist/security/constants.d.ts.map +1 -1
- package/dist/security/sanitize-core.d.ts.map +1 -1
- package/dist/security.es.mjs +10 -56
- package/dist/store-CPK9E62U.js +262 -0
- package/dist/store-CPK9E62U.js.map +1 -0
- package/dist/store.es.mjs +12 -25
- package/dist/view/evaluate.d.ts.map +1 -1
- package/dist/view-Cdi0g-qo.js +396 -0
- package/dist/view-Cdi0g-qo.js.map +1 -0
- package/dist/view.es.mjs +10 -424
- package/package.json +136 -132
- package/src/component/component.ts +319 -289
- package/src/component/index.ts +42 -40
- package/src/component/library.ts +504 -0
- package/src/component/types.ts +91 -85
- package/src/core/collection.ts +44 -4
- package/src/core/element.ts +33 -5
- package/src/core/index.ts +1 -0
- package/src/core/utils/function.ts +56 -15
- package/src/full.ts +223 -187
- package/src/motion/transition.ts +97 -51
- package/src/motion/types.ts +208 -198
- package/src/platform/announcer.ts +208 -0
- package/src/platform/config.ts +163 -0
- package/src/platform/cookies.ts +165 -0
- package/src/platform/index.ts +39 -18
- package/src/platform/meta.ts +168 -0
- package/src/platform/storage.ts +8 -1
- package/src/reactive/async-data.ts +486 -0
- package/src/reactive/core.ts +21 -0
- package/src/reactive/effect.ts +18 -7
- package/src/reactive/index.ts +37 -23
- package/src/reactive/internals.ts +18 -1
- package/src/reactive/signal.ts +29 -20
- package/src/security/constants.ts +211 -209
- package/src/security/sanitize-core.ts +22 -1
- package/src/view/evaluate.ts +29 -13
- package/dist/batch-4LAvfLE7.js +0 -13
- package/dist/batch-4LAvfLE7.js.map +0 -1
- package/dist/component.es.mjs.map +0 -1
- package/dist/core-COenAZjD.js +0 -145
- package/dist/core-COenAZjD.js.map +0 -1
- package/dist/core.es.mjs.map +0 -1
- package/dist/full.es.mjs.map +0 -1
- package/dist/index.es.mjs.map +0 -1
- package/dist/motion.es.mjs.map +0 -1
- package/dist/persisted-Dz_ryNuC.js +0 -278
- package/dist/persisted-Dz_ryNuC.js.map +0 -1
- package/dist/platform.es.mjs.map +0 -1
- package/dist/reactive.es.mjs.map +0 -1
- package/dist/router.es.mjs.map +0 -1
- package/dist/sanitize-1FBEPAFH.js +0 -272
- package/dist/sanitize-1FBEPAFH.js.map +0 -1
- package/dist/security.es.mjs.map +0 -1
- package/dist/store.es.mjs.map +0 -1
- package/dist/type-guards-DRma3-Kc.js +0 -16
- package/dist/type-guards-DRma3-Kc.js.map +0 -1
- package/dist/untrack-BuEQKH7_.js +0 -6
- package/dist/untrack-BuEQKH7_.js.map +0 -1
- package/dist/view.es.mjs.map +0 -1
- package/dist/watch-CXyaBC_9.js +0 -58
- package/dist/watch-CXyaBC_9.js.map +0 -1
package/src/full.ts
CHANGED
|
@@ -1,187 +1,223 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* bQuery.js — Full Bundle
|
|
3
|
-
*
|
|
4
|
-
* This is the complete bundle containing all modules for CDN usage.
|
|
5
|
-
* Use this when you want all features without tree-shaking concerns.
|
|
6
|
-
*
|
|
7
|
-
* @module bquery/full
|
|
8
|
-
*
|
|
9
|
-
* @example CDN Usage (ES Modules)
|
|
10
|
-
* ```html
|
|
11
|
-
* <script type="module">
|
|
12
|
-
* import { $, signal, component } from 'https://unpkg.com/bquery@1/dist/full.es.mjs';
|
|
13
|
-
*
|
|
14
|
-
* const count = signal(0);
|
|
15
|
-
* $('#counter').text(count.value);
|
|
16
|
-
* </script>
|
|
17
|
-
* ```
|
|
18
|
-
*
|
|
19
|
-
* @example CDN Usage (UMD/Global)
|
|
20
|
-
* ```html
|
|
21
|
-
* <script src="https://unpkg.com/bquery@1/dist/full.umd.js"></script>
|
|
22
|
-
* <script>
|
|
23
|
-
* const { $, signal } = bQuery;
|
|
24
|
-
* const count = signal(0);
|
|
25
|
-
* </script>
|
|
26
|
-
* ```
|
|
27
|
-
*
|
|
28
|
-
* @example CDN Usage (IIFE)
|
|
29
|
-
* ```html
|
|
30
|
-
* <script src="https://unpkg.com/bquery@1/dist/full.iife.js"></script>
|
|
31
|
-
* <script>
|
|
32
|
-
* // bQuery is available as a global variable
|
|
33
|
-
* const { $, $$ } = bQuery;
|
|
34
|
-
* </script>
|
|
35
|
-
* ```
|
|
36
|
-
*/
|
|
37
|
-
|
|
38
|
-
// ============================================================================
|
|
39
|
-
// Core Module: Selectors, DOM operations, events, utilities
|
|
40
|
-
// ============================================================================
|
|
41
|
-
export { $, $$, BQueryCollection, BQueryElement, utils } from './core/index';
|
|
42
|
-
|
|
43
|
-
// ============================================================================
|
|
44
|
-
// Reactive Module: Signals, computed values, effects, batching
|
|
45
|
-
// ============================================================================
|
|
46
|
-
export {
|
|
47
|
-
Computed,
|
|
48
|
-
Signal,
|
|
49
|
-
batch,
|
|
50
|
-
computed,
|
|
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
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
} from './
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
// ============================================================================
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
1
|
+
/**
|
|
2
|
+
* bQuery.js — Full Bundle
|
|
3
|
+
*
|
|
4
|
+
* This is the complete bundle containing all modules for CDN usage.
|
|
5
|
+
* Use this when you want all features without tree-shaking concerns.
|
|
6
|
+
*
|
|
7
|
+
* @module bquery/full
|
|
8
|
+
*
|
|
9
|
+
* @example CDN Usage (ES Modules)
|
|
10
|
+
* ```html
|
|
11
|
+
* <script type="module">
|
|
12
|
+
* import { $, signal, component } from 'https://unpkg.com/bquery@1/dist/full.es.mjs';
|
|
13
|
+
*
|
|
14
|
+
* const count = signal(0);
|
|
15
|
+
* $('#counter').text(count.value);
|
|
16
|
+
* </script>
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @example CDN Usage (UMD/Global)
|
|
20
|
+
* ```html
|
|
21
|
+
* <script src="https://unpkg.com/bquery@1/dist/full.umd.js"></script>
|
|
22
|
+
* <script>
|
|
23
|
+
* const { $, signal } = bQuery;
|
|
24
|
+
* const count = signal(0);
|
|
25
|
+
* </script>
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @example CDN Usage (IIFE)
|
|
29
|
+
* ```html
|
|
30
|
+
* <script src="https://unpkg.com/bquery@1/dist/full.iife.js"></script>
|
|
31
|
+
* <script>
|
|
32
|
+
* // bQuery is available as a global variable
|
|
33
|
+
* const { $, $$ } = bQuery;
|
|
34
|
+
* </script>
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
// ============================================================================
|
|
39
|
+
// Core Module: Selectors, DOM operations, events, utilities
|
|
40
|
+
// ============================================================================
|
|
41
|
+
export { $, $$, BQueryCollection, BQueryElement, utils } from './core/index';
|
|
42
|
+
|
|
43
|
+
// ============================================================================
|
|
44
|
+
// Reactive Module: Signals, computed values, effects, batching
|
|
45
|
+
// ============================================================================
|
|
46
|
+
export {
|
|
47
|
+
Computed,
|
|
48
|
+
Signal,
|
|
49
|
+
batch,
|
|
50
|
+
computed,
|
|
51
|
+
createUseFetch,
|
|
52
|
+
effect,
|
|
53
|
+
isComputed,
|
|
54
|
+
isSignal,
|
|
55
|
+
linkedSignal,
|
|
56
|
+
persistedSignal,
|
|
57
|
+
readonly,
|
|
58
|
+
signal,
|
|
59
|
+
useAsyncData,
|
|
60
|
+
useFetch,
|
|
61
|
+
untrack,
|
|
62
|
+
watch,
|
|
63
|
+
} from './reactive/index';
|
|
64
|
+
export type {
|
|
65
|
+
AsyncDataState,
|
|
66
|
+
AsyncDataStatus,
|
|
67
|
+
AsyncWatchSource,
|
|
68
|
+
CleanupFn,
|
|
69
|
+
FetchInput,
|
|
70
|
+
LinkedSignal,
|
|
71
|
+
Observer,
|
|
72
|
+
ReadonlySignal,
|
|
73
|
+
UseAsyncDataOptions,
|
|
74
|
+
UseFetchOptions,
|
|
75
|
+
} from './reactive/index';
|
|
76
|
+
|
|
77
|
+
// ============================================================================
|
|
78
|
+
// Component Module: Web Components helper with Shadow DOM
|
|
79
|
+
// ============================================================================
|
|
80
|
+
export { component, html, registerDefaultComponents, safeHtml } from './component/index';
|
|
81
|
+
export type {
|
|
82
|
+
ComponentDefinition,
|
|
83
|
+
DefaultComponentLibraryOptions,
|
|
84
|
+
PropDefinition,
|
|
85
|
+
RegisteredDefaultComponents,
|
|
86
|
+
} from './component/index';
|
|
87
|
+
|
|
88
|
+
// ============================================================================
|
|
89
|
+
// Motion Module: View transitions, FLIP animations, springs
|
|
90
|
+
// ============================================================================
|
|
91
|
+
export {
|
|
92
|
+
animate,
|
|
93
|
+
capturePosition,
|
|
94
|
+
easeInCubic,
|
|
95
|
+
easeInOutCubic,
|
|
96
|
+
easeInOutQuad,
|
|
97
|
+
easeInQuad,
|
|
98
|
+
easeOutBack,
|
|
99
|
+
easeOutCubic,
|
|
100
|
+
easeOutExpo,
|
|
101
|
+
easeOutQuad,
|
|
102
|
+
easingPresets,
|
|
103
|
+
flip,
|
|
104
|
+
flipElements,
|
|
105
|
+
flipList,
|
|
106
|
+
keyframePresets,
|
|
107
|
+
linear,
|
|
108
|
+
prefersReducedMotion,
|
|
109
|
+
scrollAnimate,
|
|
110
|
+
sequence,
|
|
111
|
+
spring,
|
|
112
|
+
springPresets,
|
|
113
|
+
stagger,
|
|
114
|
+
timeline,
|
|
115
|
+
transition,
|
|
116
|
+
} from './motion/index';
|
|
117
|
+
export type {
|
|
118
|
+
AnimateOptions,
|
|
119
|
+
EasingFunction,
|
|
120
|
+
ElementBounds,
|
|
121
|
+
FlipGroupOptions,
|
|
122
|
+
FlipOptions,
|
|
123
|
+
ScrollAnimateCleanup,
|
|
124
|
+
ScrollAnimateOptions,
|
|
125
|
+
SequenceOptions,
|
|
126
|
+
SequenceStep,
|
|
127
|
+
Spring,
|
|
128
|
+
SpringConfig,
|
|
129
|
+
StaggerFunction,
|
|
130
|
+
StaggerOptions,
|
|
131
|
+
TimelineConfig,
|
|
132
|
+
TimelineControls,
|
|
133
|
+
TimelineStep,
|
|
134
|
+
TransitionOptions,
|
|
135
|
+
} from './motion/index';
|
|
136
|
+
|
|
137
|
+
// ============================================================================
|
|
138
|
+
// Security Module: Sanitization, CSP compatibility, Trusted Types
|
|
139
|
+
// ============================================================================
|
|
140
|
+
export {
|
|
141
|
+
createTrustedHtml,
|
|
142
|
+
escapeHtml,
|
|
143
|
+
generateNonce,
|
|
144
|
+
getTrustedTypesPolicy,
|
|
145
|
+
hasCSPDirective,
|
|
146
|
+
isTrustedTypesSupported,
|
|
147
|
+
sanitize,
|
|
148
|
+
sanitizeHtml,
|
|
149
|
+
stripTags,
|
|
150
|
+
} from './security/index';
|
|
151
|
+
export type { SanitizeOptions } from './security/index';
|
|
152
|
+
|
|
153
|
+
// ============================================================================
|
|
154
|
+
// Platform Module: Storage, buckets, notifications, cache
|
|
155
|
+
// ============================================================================
|
|
156
|
+
export {
|
|
157
|
+
buckets,
|
|
158
|
+
cache,
|
|
159
|
+
defineBqueryConfig,
|
|
160
|
+
definePageMeta,
|
|
161
|
+
getBqueryConfig,
|
|
162
|
+
notifications,
|
|
163
|
+
storage,
|
|
164
|
+
useAnnouncer,
|
|
165
|
+
useCookie,
|
|
166
|
+
} from './platform/index';
|
|
167
|
+
export type {
|
|
168
|
+
AnnounceOptions,
|
|
169
|
+
AnnouncerHandle,
|
|
170
|
+
Bucket,
|
|
171
|
+
BqueryConfig,
|
|
172
|
+
CacheHandle,
|
|
173
|
+
IndexedDBOptions,
|
|
174
|
+
NotificationOptions,
|
|
175
|
+
PageMetaDefinition,
|
|
176
|
+
StorageAdapter,
|
|
177
|
+
UseAnnouncerOptions,
|
|
178
|
+
UseCookieOptions,
|
|
179
|
+
} from './platform/index';
|
|
180
|
+
|
|
181
|
+
// ============================================================================
|
|
182
|
+
// Router Module: SPA routing, navigation guards, lazy loading
|
|
183
|
+
// ============================================================================
|
|
184
|
+
export {
|
|
185
|
+
back,
|
|
186
|
+
createRouter,
|
|
187
|
+
currentRoute,
|
|
188
|
+
forward,
|
|
189
|
+
interceptLinks,
|
|
190
|
+
isActive,
|
|
191
|
+
isActiveSignal,
|
|
192
|
+
link,
|
|
193
|
+
navigate,
|
|
194
|
+
resolve,
|
|
195
|
+
} from './router/index';
|
|
196
|
+
export type {
|
|
197
|
+
NavigationGuard,
|
|
198
|
+
Route,
|
|
199
|
+
RouteDefinition,
|
|
200
|
+
Router,
|
|
201
|
+
RouterOptions,
|
|
202
|
+
} from './router/index';
|
|
203
|
+
|
|
204
|
+
// ============================================================================
|
|
205
|
+
// Store Module: Signal-based state management
|
|
206
|
+
// ============================================================================
|
|
207
|
+
export {
|
|
208
|
+
createPersistedStore,
|
|
209
|
+
createStore,
|
|
210
|
+
destroyStore,
|
|
211
|
+
getStore,
|
|
212
|
+
listStores,
|
|
213
|
+
mapActions,
|
|
214
|
+
mapState,
|
|
215
|
+
registerPlugin,
|
|
216
|
+
} from './store/index';
|
|
217
|
+
export type { StateFactory, Store, StoreDefinition, StorePlugin } from './store/index';
|
|
218
|
+
|
|
219
|
+
// ============================================================================
|
|
220
|
+
// View Module: Declarative DOM bindings without compiler
|
|
221
|
+
// ============================================================================
|
|
222
|
+
export { createTemplate, mount } from './view/index';
|
|
223
|
+
export type { BindingContext, MountOptions, View } from './view/index';
|
package/src/motion/transition.ts
CHANGED
|
@@ -1,51 +1,97 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* View transition helpers.
|
|
3
|
-
*
|
|
4
|
-
* @module bquery/motion
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import type { TransitionOptions } from './types';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
1
|
+
/**
|
|
2
|
+
* View transition helpers.
|
|
3
|
+
*
|
|
4
|
+
* @module bquery/motion
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { TransitionOptions } from './types';
|
|
8
|
+
import { prefersReducedMotion } from './reduced-motion';
|
|
9
|
+
import { getBqueryConfig } from '../platform/config';
|
|
10
|
+
|
|
11
|
+
/** Extended document type with View Transitions API */
|
|
12
|
+
type DocumentWithTransition = Document & {
|
|
13
|
+
startViewTransition?: (callback: () => void | Promise<void>) => {
|
|
14
|
+
finished: Promise<void>;
|
|
15
|
+
ready: Promise<void>;
|
|
16
|
+
updateCallbackDone: Promise<void>;
|
|
17
|
+
skipTransition?: () => void;
|
|
18
|
+
types?: {
|
|
19
|
+
add: (type: string) => void;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const sanitizeTokens = (tokens?: string[]): string[] =>
|
|
25
|
+
(tokens ?? []).map((token) => token.trim()).filter((token) => token.length > 0);
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Execute a DOM update with view transition animation.
|
|
29
|
+
* Falls back to immediate update when View Transitions API is unavailable.
|
|
30
|
+
*
|
|
31
|
+
* @param updateOrOptions - Update function or options object
|
|
32
|
+
* @returns Promise that resolves when transition completes
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* await transition(() => {
|
|
37
|
+
* $('#content').text('Updated');
|
|
38
|
+
* });
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export const transition = async (
|
|
42
|
+
updateOrOptions: (() => void | Promise<void>) | TransitionOptions
|
|
43
|
+
): Promise<void> => {
|
|
44
|
+
const config = getBqueryConfig().transitions;
|
|
45
|
+
const options: TransitionOptions =
|
|
46
|
+
typeof updateOrOptions === 'function'
|
|
47
|
+
? {
|
|
48
|
+
update: updateOrOptions,
|
|
49
|
+
classes: config?.classes,
|
|
50
|
+
types: config?.types,
|
|
51
|
+
skipOnReducedMotion: config?.skipOnReducedMotion,
|
|
52
|
+
}
|
|
53
|
+
: {
|
|
54
|
+
...updateOrOptions,
|
|
55
|
+
classes: updateOrOptions.classes ?? config?.classes,
|
|
56
|
+
types: updateOrOptions.types ?? config?.types,
|
|
57
|
+
skipOnReducedMotion: updateOrOptions.skipOnReducedMotion ?? config?.skipOnReducedMotion,
|
|
58
|
+
};
|
|
59
|
+
const update = options.update;
|
|
60
|
+
|
|
61
|
+
// SSR/non-DOM environment fallback
|
|
62
|
+
if (typeof document === 'undefined') {
|
|
63
|
+
await update();
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const doc = document as DocumentWithTransition;
|
|
68
|
+
const root = document.documentElement;
|
|
69
|
+
const classes = sanitizeTokens(options.classes);
|
|
70
|
+
const types = sanitizeTokens(options.types);
|
|
71
|
+
|
|
72
|
+
if (!doc.startViewTransition || (options.skipOnReducedMotion && prefersReducedMotion())) {
|
|
73
|
+
await update();
|
|
74
|
+
options.onFinish?.();
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
classes.forEach((className: string) => root.classList.add(className));
|
|
79
|
+
|
|
80
|
+
try {
|
|
81
|
+
const viewTransition = doc.startViewTransition(() => update());
|
|
82
|
+
const transitionTypes = viewTransition.types;
|
|
83
|
+
|
|
84
|
+
if (transitionTypes) {
|
|
85
|
+
for (const type of types) {
|
|
86
|
+
transitionTypes.add(type);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
await viewTransition.ready;
|
|
91
|
+
options.onReady?.();
|
|
92
|
+
await viewTransition.finished;
|
|
93
|
+
options.onFinish?.();
|
|
94
|
+
} finally {
|
|
95
|
+
classes.forEach((className: string) => root.classList.remove(className));
|
|
96
|
+
}
|
|
97
|
+
};
|