@bquery/bquery 1.2.0 → 1.4.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 +127 -27
- package/dist/batch-x7b2eZST.js +13 -0
- package/dist/batch-x7b2eZST.js.map +1 -0
- package/dist/component/component.d.ts +69 -0
- package/dist/component/component.d.ts.map +1 -0
- package/dist/component/html.d.ts +35 -0
- package/dist/component/html.d.ts.map +1 -0
- package/dist/component/index.d.ts +3 -126
- package/dist/component/index.d.ts.map +1 -1
- package/dist/component/props.d.ts +18 -0
- package/dist/component/props.d.ts.map +1 -0
- package/dist/component/types.d.ts +77 -0
- package/dist/component/types.d.ts.map +1 -0
- package/dist/component.es.mjs +90 -59
- package/dist/component.es.mjs.map +1 -1
- package/dist/core/collection.d.ts +55 -3
- package/dist/core/collection.d.ts.map +1 -1
- package/dist/core/dom.d.ts +6 -0
- package/dist/core/dom.d.ts.map +1 -0
- package/dist/core/element.d.ts +31 -4
- package/dist/core/element.d.ts.map +1 -1
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/utils/array.d.ts +74 -0
- package/dist/core/utils/array.d.ts.map +1 -0
- package/dist/core/utils/function.d.ts +87 -0
- package/dist/core/utils/function.d.ts.map +1 -0
- package/dist/core/utils/index.d.ts +70 -0
- package/dist/core/utils/index.d.ts.map +1 -0
- package/dist/core/utils/misc.d.ts +63 -0
- package/dist/core/utils/misc.d.ts.map +1 -0
- package/dist/core/utils/number.d.ts +65 -0
- package/dist/core/utils/number.d.ts.map +1 -0
- package/dist/core/utils/object.d.ts +133 -0
- package/dist/core/utils/object.d.ts.map +1 -0
- package/dist/core/utils/string.d.ts +80 -0
- package/dist/core/utils/string.d.ts.map +1 -0
- package/dist/core/utils/type-guards.d.ts +79 -0
- package/dist/core/utils/type-guards.d.ts.map +1 -0
- package/dist/core-BhpuvPhy.js +170 -0
- package/dist/core-BhpuvPhy.js.map +1 -0
- package/dist/core.es.mjs +495 -489
- package/dist/core.es.mjs.map +1 -1
- package/dist/full.d.ts +2 -2
- package/dist/full.d.ts.map +1 -1
- package/dist/full.es.mjs +87 -64
- package/dist/full.es.mjs.map +1 -1
- package/dist/full.iife.js +2 -2
- package/dist/full.iife.js.map +1 -1
- package/dist/full.umd.js +2 -2
- package/dist/full.umd.js.map +1 -1
- package/dist/index.es.mjs +138 -68
- package/dist/index.es.mjs.map +1 -1
- package/dist/motion/animate.d.ts +25 -0
- package/dist/motion/animate.d.ts.map +1 -0
- package/dist/motion/easing.d.ts +30 -0
- package/dist/motion/easing.d.ts.map +1 -0
- package/dist/motion/flip.d.ts +55 -0
- package/dist/motion/flip.d.ts.map +1 -0
- package/dist/motion/index.d.ts +11 -138
- package/dist/motion/index.d.ts.map +1 -1
- package/dist/motion/keyframes.d.ts +21 -0
- package/dist/motion/keyframes.d.ts.map +1 -0
- package/dist/motion/reduced-motion.d.ts +12 -0
- package/dist/motion/reduced-motion.d.ts.map +1 -0
- package/dist/motion/scroll.d.ts +15 -0
- package/dist/motion/scroll.d.ts.map +1 -0
- package/dist/motion/spring.d.ts +42 -0
- package/dist/motion/spring.d.ts.map +1 -0
- package/dist/motion/stagger.d.ts +22 -0
- package/dist/motion/stagger.d.ts.map +1 -0
- package/dist/motion/timeline.d.ts +21 -0
- package/dist/motion/timeline.d.ts.map +1 -0
- package/dist/motion/transition.d.ts +22 -0
- package/dist/motion/transition.d.ts.map +1 -0
- package/dist/motion/types.d.ts +182 -0
- package/dist/motion/types.d.ts.map +1 -0
- package/dist/motion.es.mjs +320 -61
- package/dist/motion.es.mjs.map +1 -1
- package/dist/persisted-DHoi3uEs.js +278 -0
- package/dist/persisted-DHoi3uEs.js.map +1 -0
- package/dist/platform/storage.d.ts.map +1 -1
- package/dist/platform.es.mjs +12 -7
- package/dist/platform.es.mjs.map +1 -1
- package/dist/reactive/batch.d.ts +13 -0
- package/dist/reactive/batch.d.ts.map +1 -0
- package/dist/reactive/computed.d.ts +50 -0
- package/dist/reactive/computed.d.ts.map +1 -0
- package/dist/reactive/core.d.ts +72 -0
- package/dist/reactive/core.d.ts.map +1 -0
- package/dist/reactive/effect.d.ts +15 -0
- package/dist/reactive/effect.d.ts.map +1 -0
- package/dist/reactive/index.d.ts +2 -2
- package/dist/reactive/index.d.ts.map +1 -1
- package/dist/reactive/internals.d.ts +42 -0
- package/dist/reactive/internals.d.ts.map +1 -0
- package/dist/reactive/linked.d.ts +36 -0
- package/dist/reactive/linked.d.ts.map +1 -0
- package/dist/reactive/persisted.d.ts +14 -0
- package/dist/reactive/persisted.d.ts.map +1 -0
- package/dist/reactive/readonly.d.ts +26 -0
- package/dist/reactive/readonly.d.ts.map +1 -0
- package/dist/reactive/signal.d.ts +13 -312
- package/dist/reactive/signal.d.ts.map +1 -1
- package/dist/reactive/type-guards.d.ts +20 -0
- package/dist/reactive/type-guards.d.ts.map +1 -0
- package/dist/reactive/untrack.d.ts +29 -0
- package/dist/reactive/untrack.d.ts.map +1 -0
- package/dist/reactive/watch.d.ts +42 -0
- package/dist/reactive/watch.d.ts.map +1 -0
- package/dist/reactive.es.mjs +30 -163
- package/dist/reactive.es.mjs.map +1 -1
- package/dist/router/index.d.ts +6 -252
- package/dist/router/index.d.ts.map +1 -1
- package/dist/router/links.d.ts +44 -0
- package/dist/router/links.d.ts.map +1 -0
- package/dist/router/match.d.ts +20 -0
- package/dist/router/match.d.ts.map +1 -0
- package/dist/router/navigation.d.ts +45 -0
- package/dist/router/navigation.d.ts.map +1 -0
- package/dist/router/query.d.ts +16 -0
- package/dist/router/query.d.ts.map +1 -0
- package/dist/router/router.d.ts +34 -0
- package/dist/router/router.d.ts.map +1 -0
- package/dist/router/state.d.ts +27 -0
- package/dist/router/state.d.ts.map +1 -0
- package/dist/router/types.d.ts +88 -0
- package/dist/router/types.d.ts.map +1 -0
- package/dist/router/utils.d.ts +65 -0
- package/dist/router/utils.d.ts.map +1 -0
- package/dist/router.es.mjs +168 -132
- package/dist/router.es.mjs.map +1 -1
- package/dist/sanitize-Cxvxa-DX.js +283 -0
- package/dist/sanitize-Cxvxa-DX.js.map +1 -0
- package/dist/security/constants.d.ts +42 -0
- package/dist/security/constants.d.ts.map +1 -0
- package/dist/security/csp.d.ts +24 -0
- package/dist/security/csp.d.ts.map +1 -0
- package/dist/security/index.d.ts +4 -2
- package/dist/security/index.d.ts.map +1 -1
- package/dist/security/sanitize-core.d.ts +13 -0
- package/dist/security/sanitize-core.d.ts.map +1 -0
- package/dist/security/sanitize.d.ts +5 -57
- package/dist/security/sanitize.d.ts.map +1 -1
- package/dist/security/trusted-types.d.ts +25 -0
- package/dist/security/trusted-types.d.ts.map +1 -0
- package/dist/security/types.d.ts +36 -0
- package/dist/security/types.d.ts.map +1 -0
- package/dist/security.es.mjs +50 -277
- package/dist/security.es.mjs.map +1 -1
- package/dist/store/create-store.d.ts +15 -0
- package/dist/store/create-store.d.ts.map +1 -0
- package/dist/store/define-store.d.ts +28 -0
- package/dist/store/define-store.d.ts.map +1 -0
- package/dist/store/devtools.d.ts +22 -0
- package/dist/store/devtools.d.ts.map +1 -0
- package/dist/store/index.d.ts +10 -286
- package/dist/store/index.d.ts.map +1 -1
- package/dist/store/mapping.d.ts +28 -0
- package/dist/store/mapping.d.ts.map +1 -0
- package/dist/store/persisted.d.ts +13 -0
- package/dist/store/persisted.d.ts.map +1 -0
- package/dist/store/plugins.d.ts +13 -0
- package/dist/store/plugins.d.ts.map +1 -0
- package/dist/store/registry.d.ts +28 -0
- package/dist/store/registry.d.ts.map +1 -0
- package/dist/store/types.d.ts +71 -0
- package/dist/store/types.d.ts.map +1 -0
- package/dist/store/utils.d.ts +28 -0
- package/dist/store/utils.d.ts.map +1 -0
- package/dist/store/watch.d.ts +23 -0
- package/dist/store/watch.d.ts.map +1 -0
- package/dist/store.es.mjs +22 -224
- package/dist/store.es.mjs.map +1 -1
- package/dist/type-guards-BdKlYYlS.js +32 -0
- package/dist/type-guards-BdKlYYlS.js.map +1 -0
- package/dist/untrack-DNnnqdlR.js +6 -0
- package/dist/untrack-DNnnqdlR.js.map +1 -0
- package/dist/view/directives/bind.d.ts +7 -0
- package/dist/view/directives/bind.d.ts.map +1 -0
- package/dist/view/directives/class.d.ts +8 -0
- package/dist/view/directives/class.d.ts.map +1 -0
- package/dist/view/directives/for.d.ts +23 -0
- package/dist/view/directives/for.d.ts.map +1 -0
- package/dist/view/directives/html.d.ts +7 -0
- package/dist/view/directives/html.d.ts.map +1 -0
- package/dist/view/directives/if.d.ts +7 -0
- package/dist/view/directives/if.d.ts.map +1 -0
- package/dist/view/directives/index.d.ts +12 -0
- package/dist/view/directives/index.d.ts.map +1 -0
- package/dist/view/directives/model.d.ts +7 -0
- package/dist/view/directives/model.d.ts.map +1 -0
- package/dist/view/directives/on.d.ts +7 -0
- package/dist/view/directives/on.d.ts.map +1 -0
- package/dist/view/directives/ref.d.ts +7 -0
- package/dist/view/directives/ref.d.ts.map +1 -0
- package/dist/view/directives/show.d.ts +7 -0
- package/dist/view/directives/show.d.ts.map +1 -0
- package/dist/view/directives/style.d.ts +7 -0
- package/dist/view/directives/style.d.ts.map +1 -0
- package/dist/view/directives/text.d.ts +7 -0
- package/dist/view/directives/text.d.ts.map +1 -0
- package/dist/view/evaluate.d.ts +43 -0
- package/dist/view/evaluate.d.ts.map +1 -0
- package/dist/view/index.d.ts +3 -93
- package/dist/view/index.d.ts.map +1 -1
- package/dist/view/mount.d.ts +69 -0
- package/dist/view/mount.d.ts.map +1 -0
- package/dist/view/process.d.ts +26 -0
- package/dist/view/process.d.ts.map +1 -0
- package/dist/view/types.d.ts +36 -0
- package/dist/view/types.d.ts.map +1 -0
- package/dist/view.es.mjs +358 -251
- package/dist/view.es.mjs.map +1 -1
- package/dist/watch-DXXv3iAI.js +58 -0
- package/dist/watch-DXXv3iAI.js.map +1 -0
- package/package.json +14 -14
- package/src/component/component.ts +289 -0
- package/src/component/html.ts +53 -0
- package/src/component/index.ts +40 -414
- package/src/component/props.ts +116 -0
- package/src/component/types.ts +85 -0
- package/src/core/collection.ts +181 -7
- package/src/core/dom.ts +38 -0
- package/src/core/element.ts +59 -25
- package/src/core/index.ts +48 -4
- package/src/core/utils/array.ts +102 -0
- package/src/core/utils/function.ts +151 -0
- package/src/core/utils/index.ts +83 -0
- package/src/core/utils/misc.ts +82 -0
- package/src/core/utils/number.ts +78 -0
- package/src/core/utils/object.ts +206 -0
- package/src/core/utils/string.ts +112 -0
- package/src/core/utils/type-guards.ts +112 -0
- package/src/full.ts +187 -150
- package/src/index.ts +36 -36
- package/src/motion/animate.ts +113 -0
- package/src/motion/easing.ts +40 -0
- package/src/motion/flip.ts +176 -0
- package/src/motion/index.ts +41 -358
- package/src/motion/keyframes.ts +46 -0
- package/src/motion/reduced-motion.ts +17 -0
- package/src/motion/scroll.ts +57 -0
- package/src/motion/spring.ts +150 -0
- package/src/motion/stagger.ts +43 -0
- package/src/motion/timeline.ts +246 -0
- package/src/motion/transition.ts +51 -0
- package/src/motion/types.ts +198 -0
- package/src/platform/storage.ts +215 -208
- package/src/reactive/batch.ts +22 -0
- package/src/reactive/computed.ts +92 -0
- package/src/reactive/core.ts +114 -0
- package/src/reactive/effect.ts +54 -0
- package/src/reactive/index.ts +23 -22
- package/src/reactive/internals.ts +122 -0
- package/src/reactive/linked.ts +56 -0
- package/src/reactive/persisted.ts +74 -0
- package/src/reactive/readonly.ts +35 -0
- package/src/reactive/signal.ts +20 -520
- package/src/reactive/type-guards.ts +22 -0
- package/src/reactive/untrack.ts +31 -0
- package/src/reactive/watch.ts +73 -0
- package/src/router/index.ts +41 -718
- package/src/router/links.ts +130 -0
- package/src/router/match.ts +106 -0
- package/src/router/navigation.ts +71 -0
- package/src/router/query.ts +35 -0
- package/src/router/router.ts +211 -0
- package/src/router/state.ts +46 -0
- package/src/router/types.ts +93 -0
- package/src/router/utils.ts +116 -0
- package/src/security/constants.ts +209 -0
- package/src/security/csp.ts +77 -0
- package/src/security/index.ts +4 -12
- package/src/security/sanitize-core.ts +364 -0
- package/src/security/sanitize.ts +66 -625
- package/src/security/trusted-types.ts +69 -0
- package/src/security/types.ts +40 -0
- package/src/store/create-store.ts +329 -0
- package/src/store/define-store.ts +48 -0
- package/src/store/devtools.ts +45 -0
- package/src/store/index.ts +22 -848
- package/src/store/mapping.ts +73 -0
- package/src/store/persisted.ts +61 -0
- package/src/store/plugins.ts +32 -0
- package/src/store/registry.ts +51 -0
- package/src/store/types.ts +94 -0
- package/src/store/utils.ts +141 -0
- package/src/store/watch.ts +52 -0
- package/src/view/directives/bind.ts +23 -0
- package/src/view/directives/class.ts +70 -0
- package/src/view/directives/for.ts +275 -0
- package/src/view/directives/html.ts +19 -0
- package/src/view/directives/if.ts +30 -0
- package/src/view/directives/index.ts +11 -0
- package/src/view/directives/model.ts +56 -0
- package/src/view/directives/on.ts +41 -0
- package/src/view/directives/ref.ts +41 -0
- package/src/view/directives/show.ts +26 -0
- package/src/view/directives/style.ts +47 -0
- package/src/view/directives/text.ts +15 -0
- package/src/view/evaluate.ts +290 -0
- package/src/view/index.ts +112 -1041
- package/src/view/mount.ts +200 -0
- package/src/view/process.ts +92 -0
- package/src/view/types.ts +44 -0
- package/dist/core/utils.d.ts +0 -313
- package/dist/core/utils.d.ts.map +0 -1
- package/src/core/utils.ts +0 -444
package/README.md
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
[](https://bundlephobia.com/package/@bquery/bquery)
|
|
15
15
|
[](https://unpkg.com/@bquery/bquery)
|
|
16
16
|
[](https://www.codefactor.io/repository/github/bquery/bquery)
|
|
17
|
+
[](https://www.jsdelivr.com/package/npm/@bquery/bquery)
|
|
17
18
|
|
|
18
19
|
**The jQuery for the modern Web Platform.**
|
|
19
20
|
|
|
@@ -84,30 +85,33 @@ import { $, signal, component } from '@bquery/bquery';
|
|
|
84
85
|
// Core only
|
|
85
86
|
import { $, $$ } from '@bquery/bquery/core';
|
|
86
87
|
|
|
88
|
+
// Core utilities (named exports, tree-shakeable)
|
|
89
|
+
import { debounce, merge, uid, once, utils } from '@bquery/bquery/core';
|
|
90
|
+
|
|
87
91
|
// À la carte (individual modules)
|
|
88
|
-
import { signal, computed, effect } from '@bquery/bquery/reactive';
|
|
89
|
-
import { component, html } from '@bquery/bquery/component';
|
|
90
|
-
import { transition, spring } from '@bquery/bquery/motion';
|
|
92
|
+
import { signal, computed, effect, linkedSignal, persistedSignal } from '@bquery/bquery/reactive';
|
|
93
|
+
import { component, defineComponent, html } from '@bquery/bquery/component';
|
|
94
|
+
import { transition, spring, animate, timeline } from '@bquery/bquery/motion';
|
|
91
95
|
import { sanitize } from '@bquery/bquery/security';
|
|
92
96
|
import { storage, cache } from '@bquery/bquery/platform';
|
|
93
97
|
import { createRouter, navigate } from '@bquery/bquery/router';
|
|
94
|
-
import { createStore } from '@bquery/bquery/store';
|
|
95
|
-
import { mount } from '@bquery/bquery/view';
|
|
98
|
+
import { createStore, defineStore } from '@bquery/bquery/store';
|
|
99
|
+
import { mount, createTemplate } from '@bquery/bquery/view';
|
|
96
100
|
```
|
|
97
101
|
|
|
98
102
|
## Modules at a glance
|
|
99
103
|
|
|
100
|
-
| Module | Description
|
|
101
|
-
| ------------- |
|
|
102
|
-
| **Core** | Selectors, DOM manipulation, events, utilities
|
|
103
|
-
| **Reactive** | `signal`, `computed`, `effect`, `batch`
|
|
104
|
-
| **Component** | Lightweight Web Components with props
|
|
105
|
-
| **Motion** | View transitions, FLIP
|
|
106
|
-
| **Security** | HTML sanitizing, Trusted Types, CSP
|
|
107
|
-
| **Platform** | Storage, cache, notifications, buckets
|
|
108
|
-
| **Router** | SPA routing, navigation guards, history API
|
|
109
|
-
| **Store** | Signal-based state management, persistence
|
|
110
|
-
| **View** | Declarative DOM bindings, directives
|
|
104
|
+
| Module | Description | Size (gzip) |
|
|
105
|
+
| ------------- | -------------------------------------------------- | ----------- |
|
|
106
|
+
| **Core** | Selectors, DOM manipulation, events, utilities | ~11.3 KB |
|
|
107
|
+
| **Reactive** | `signal`, `computed`, `effect`, `batch` | ~0.3 KB |
|
|
108
|
+
| **Component** | Lightweight Web Components with props | ~1.9 KB |
|
|
109
|
+
| **Motion** | View transitions, FLIP, timelines, scroll, springs | ~4.0 KB |
|
|
110
|
+
| **Security** | HTML sanitizing, Trusted Types, CSP | ~0.7 KB |
|
|
111
|
+
| **Platform** | Storage, cache, notifications, buckets | ~2.2 KB |
|
|
112
|
+
| **Router** | SPA routing, navigation guards, history API | ~2.2 KB |
|
|
113
|
+
| **Store** | Signal-based state management, persistence | ~0.3 KB |
|
|
114
|
+
| **View** | Declarative DOM bindings, directives | ~4.3 KB |
|
|
111
115
|
|
|
112
116
|
## Quick examples
|
|
113
117
|
|
|
@@ -129,9 +133,20 @@ $('#list').delegate('click', '.item', (event, target) => {
|
|
|
129
133
|
// Method chaining
|
|
130
134
|
$('#box').addClass('active').css({ opacity: '0.8' }).attr('data-state', 'ready');
|
|
131
135
|
|
|
136
|
+
// CSS getter (computed style)
|
|
137
|
+
const color = $('#box').css('color'); // Returns computed style value
|
|
138
|
+
|
|
139
|
+
// Selector matching
|
|
140
|
+
if ($('#el').is('.active')) {
|
|
141
|
+
console.log('Element is active');
|
|
142
|
+
}
|
|
143
|
+
|
|
132
144
|
// DOM manipulation
|
|
133
|
-
$('#content').wrap('
|
|
134
|
-
$('#
|
|
145
|
+
$('#content').wrap('div');
|
|
146
|
+
$('#content').unwrap(); // Remove parent wrapper
|
|
147
|
+
|
|
148
|
+
// Attribute helpers
|
|
149
|
+
$('#dialog').toggleAttr('open');
|
|
135
150
|
|
|
136
151
|
// Smooth scrolling
|
|
137
152
|
$('#section').scrollTo({ behavior: 'smooth' });
|
|
@@ -142,12 +157,22 @@ const queryString = $('form').serializeString(); // Returns URL-encoded string
|
|
|
142
157
|
|
|
143
158
|
// Collections
|
|
144
159
|
$$('.items').addClass('highlight');
|
|
160
|
+
$$('.items').append('<li class="item">New</li>');
|
|
161
|
+
$$('.container').find('.item').addClass('found'); // Find descendants across collection
|
|
145
162
|
```
|
|
146
163
|
|
|
147
164
|
### Reactive – signals
|
|
148
165
|
|
|
149
166
|
```ts
|
|
150
|
-
import {
|
|
167
|
+
import {
|
|
168
|
+
signal,
|
|
169
|
+
computed,
|
|
170
|
+
effect,
|
|
171
|
+
batch,
|
|
172
|
+
watch,
|
|
173
|
+
readonly,
|
|
174
|
+
linkedSignal,
|
|
175
|
+
} from '@bquery/bquery/reactive';
|
|
151
176
|
|
|
152
177
|
const count = signal(0);
|
|
153
178
|
const doubled = computed(() => count.value * 2);
|
|
@@ -169,12 +194,29 @@ batch(() => {
|
|
|
169
194
|
count.value++;
|
|
170
195
|
count.value++;
|
|
171
196
|
});
|
|
197
|
+
|
|
198
|
+
// Dispose signal (remove all subscribers)
|
|
199
|
+
count.dispose();
|
|
200
|
+
|
|
201
|
+
// Writable computed (linked signal)
|
|
202
|
+
const first = signal('Ada');
|
|
203
|
+
const last = signal('Lovelace');
|
|
204
|
+
const fullName = linkedSignal(
|
|
205
|
+
() => `${first.value} ${last.value}`,
|
|
206
|
+
(next) => {
|
|
207
|
+
const [nextFirst, nextLast] = next.split(' ');
|
|
208
|
+
first.value = nextFirst ?? '';
|
|
209
|
+
last.value = nextLast ?? '';
|
|
210
|
+
}
|
|
211
|
+
);
|
|
212
|
+
|
|
213
|
+
fullName.value = 'Grace Hopper';
|
|
172
214
|
```
|
|
173
215
|
|
|
174
216
|
### Components – Web Components
|
|
175
217
|
|
|
176
218
|
```ts
|
|
177
|
-
import { component, html } from '@bquery/bquery/component';
|
|
219
|
+
import { component, defineComponent, html } from '@bquery/bquery/component';
|
|
178
220
|
|
|
179
221
|
component('user-card', {
|
|
180
222
|
props: {
|
|
@@ -199,18 +241,31 @@ component('user-card', {
|
|
|
199
241
|
return html`<div>Hello ${props.username}</div>`;
|
|
200
242
|
},
|
|
201
243
|
});
|
|
244
|
+
|
|
245
|
+
// Optional: create the class without auto-registration
|
|
246
|
+
const UserCard = defineComponent('user-card', {
|
|
247
|
+
props: { username: { type: String, required: true } },
|
|
248
|
+
render: ({ props }) => html`<div>Hello ${props.username}</div>`,
|
|
249
|
+
});
|
|
250
|
+
customElements.define('user-card', UserCard);
|
|
202
251
|
```
|
|
203
252
|
|
|
204
253
|
### Motion – animations
|
|
205
254
|
|
|
206
255
|
```ts
|
|
207
|
-
import {
|
|
256
|
+
import { animate, keyframePresets, spring, transition } from '@bquery/bquery/motion';
|
|
208
257
|
|
|
209
258
|
// View transitions (with fallback)
|
|
210
259
|
await transition(() => {
|
|
211
260
|
$('#content').text('Updated');
|
|
212
261
|
});
|
|
213
262
|
|
|
263
|
+
// Web Animations helper
|
|
264
|
+
await animate(card, {
|
|
265
|
+
keyframes: keyframePresets.pop(),
|
|
266
|
+
options: { duration: 240, easing: 'ease-out' },
|
|
267
|
+
});
|
|
268
|
+
|
|
214
269
|
// Spring physics
|
|
215
270
|
const x = spring(0, { stiffness: 120, damping: 14 });
|
|
216
271
|
x.onChange((value) => {
|
|
@@ -221,6 +276,8 @@ await x.to(100);
|
|
|
221
276
|
|
|
222
277
|
### Security – sanitizing
|
|
223
278
|
|
|
279
|
+
Internally modularized (sanitize core, Trusted Types, CSP helpers) — the public API remains unchanged. For legacy deep imports, `@bquery/bquery/security/sanitize` also re-exports `generateNonce()` and `isTrustedTypesSupported()`.
|
|
280
|
+
|
|
224
281
|
```ts
|
|
225
282
|
import { sanitize, escapeHtml } from '@bquery/bquery/security';
|
|
226
283
|
|
|
@@ -236,6 +293,12 @@ const urlSafe = sanitize('<a href="java\u200Bscript:alert(1)">click</a>');
|
|
|
236
293
|
// Automatic link security (adds rel="noopener noreferrer" to external/target="_blank" links)
|
|
237
294
|
const secureLink = sanitize('<a href="https://external.com" target="_blank">Link</a>');
|
|
238
295
|
|
|
296
|
+
// srcset validation (per-URL; entire attribute removed if any entry is unsafe)
|
|
297
|
+
const safeSrcset = sanitize('<img srcset="safe.jpg 1x, javascript:alert(1) 2x">'); // <img>
|
|
298
|
+
|
|
299
|
+
// Form action validation (blocks javascript: protocol)
|
|
300
|
+
const safeForm = sanitize('<form action="javascript:alert(1)">...</form>');
|
|
301
|
+
|
|
239
302
|
// Escape for text display
|
|
240
303
|
const escaped = escapeHtml('<script>alert(1)</script>');
|
|
241
304
|
```
|
|
@@ -261,6 +324,8 @@ if (permission === 'granted') {
|
|
|
261
324
|
|
|
262
325
|
### Router – SPA navigation
|
|
263
326
|
|
|
327
|
+
Internally, the router has been split into focused submodules (matching, navigation, state, links, utilities) with no public API changes.
|
|
328
|
+
|
|
264
329
|
```ts
|
|
265
330
|
import { createRouter, navigate, currentRoute } from '@bquery/bquery/router';
|
|
266
331
|
|
|
@@ -297,8 +362,8 @@ effect(() => {
|
|
|
297
362
|
```ts
|
|
298
363
|
import { createStore, createPersistedStore } from '@bquery/bquery/store';
|
|
299
364
|
|
|
300
|
-
//
|
|
301
|
-
const
|
|
365
|
+
// Create a store (returns the store instance directly)
|
|
366
|
+
const counterStore = createStore({
|
|
302
367
|
id: 'counter',
|
|
303
368
|
state: () => ({ count: 0, name: 'Counter' }),
|
|
304
369
|
getters: {
|
|
@@ -315,19 +380,46 @@ const useCounter = createStore({
|
|
|
315
380
|
});
|
|
316
381
|
|
|
317
382
|
// Use the store
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
console.log(counter.doubled); // Reactive getter
|
|
383
|
+
counterStore.increment();
|
|
384
|
+
console.log(counterStore.doubled); // Reactive getter
|
|
321
385
|
|
|
322
386
|
// Persisted store (localStorage)
|
|
323
|
-
const
|
|
387
|
+
const settingsStore = createPersistedStore({
|
|
324
388
|
id: 'settings',
|
|
325
389
|
state: () => ({ theme: 'dark', language: 'en' }),
|
|
326
390
|
});
|
|
391
|
+
|
|
392
|
+
// Factory-style store definition (Pinia-style)
|
|
393
|
+
import { defineStore, mapGetters, watchStore } from '@bquery/bquery/store';
|
|
394
|
+
|
|
395
|
+
const useCounter = defineStore('counter', {
|
|
396
|
+
state: () => ({ count: 0 }),
|
|
397
|
+
getters: {
|
|
398
|
+
doubled: (state) => state.count * 2,
|
|
399
|
+
},
|
|
400
|
+
actions: {
|
|
401
|
+
increment() {
|
|
402
|
+
this.count++;
|
|
403
|
+
},
|
|
404
|
+
},
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
const counter = useCounter();
|
|
408
|
+
const getters = mapGetters(counter, ['doubled']);
|
|
409
|
+
|
|
410
|
+
watchStore(
|
|
411
|
+
counter,
|
|
412
|
+
(state) => state.count,
|
|
413
|
+
(value) => {
|
|
414
|
+
console.log('Count changed:', value, getters.doubled);
|
|
415
|
+
}
|
|
416
|
+
);
|
|
327
417
|
```
|
|
328
418
|
|
|
329
419
|
### View – declarative bindings
|
|
330
420
|
|
|
421
|
+
Internally modularized into focused submodules; the public API remains unchanged.
|
|
422
|
+
|
|
331
423
|
```ts
|
|
332
424
|
import { mount, createTemplate } from '@bquery/bquery/view';
|
|
333
425
|
import { signal } from '@bquery/bquery/reactive';
|
|
@@ -422,6 +514,14 @@ bQuery.js
|
|
|
422
514
|
|
|
423
515
|
See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
|
|
424
516
|
|
|
517
|
+
## AI Agent Support
|
|
518
|
+
|
|
519
|
+
This project provides dedicated context files for AI coding agents:
|
|
520
|
+
|
|
521
|
+
- **[AGENT.md](AGENT.md)** — Architecture, module API reference, coding conventions, common tasks
|
|
522
|
+
- **[llms.txt](llms.txt)** — Compact LLM-optimized project summary
|
|
523
|
+
- **[.github/copilot-instructions.md](.github/copilot-instructions.md)** — GitHub Copilot context
|
|
524
|
+
|
|
425
525
|
## License
|
|
426
526
|
|
|
427
527
|
MIT – See [LICENSE.md](LICENSE.md) for details.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batch-x7b2eZST.js","sources":["../src/reactive/batch.ts"],"sourcesContent":["/**\n * Batched reactive updates.\n */\n\nimport { beginBatch, endBatch } from './internals';\n\n/**\n * Batches multiple signal updates into a single notification cycle.\n *\n * Updates made inside the batch function are deferred until the batch\n * completes, preventing intermediate re-renders and improving performance.\n *\n * @param fn - Function containing multiple signal updates\n */\nexport const batch = (fn: () => void): void => {\n beginBatch();\n try {\n fn();\n } finally {\n endBatch();\n }\n};\n"],"names":["batch","fn","beginBatch","endBatch"],"mappings":";AAcO,MAAMA,IAAQ,CAACC,MAAyB;AAC7C,EAAAC,EAAA;AACA,MAAI;AACF,IAAAD,EAAA;AAAA,EACF,UAAA;AACE,IAAAE,EAAA;AAAA,EACF;AACF;"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Web Component factory and registry.
|
|
3
|
+
*
|
|
4
|
+
* @module bquery/component
|
|
5
|
+
*/
|
|
6
|
+
import type { ComponentDefinition } from './types';
|
|
7
|
+
/**
|
|
8
|
+
* Creates a custom element class for a component definition.
|
|
9
|
+
*
|
|
10
|
+
* This is useful when you want to extend or register the class manually
|
|
11
|
+
* (e.g. with different tag names in tests or custom registries).
|
|
12
|
+
*
|
|
13
|
+
* @template TProps - Type of the component's props
|
|
14
|
+
* @param tagName - The custom element tag name (used for diagnostics)
|
|
15
|
+
* @param definition - The component configuration
|
|
16
|
+
*/
|
|
17
|
+
export declare const defineComponent: <TProps extends Record<string, unknown>>(tagName: string, definition: ComponentDefinition<TProps>) => typeof HTMLElement;
|
|
18
|
+
/**
|
|
19
|
+
* Defines and registers a custom Web Component.
|
|
20
|
+
*
|
|
21
|
+
* This function creates a new custom element with the given tag name
|
|
22
|
+
* and configuration. The component uses Shadow DOM for encapsulation
|
|
23
|
+
* and automatically re-renders when observed attributes change.
|
|
24
|
+
*
|
|
25
|
+
* @template TProps - Type of the component's props
|
|
26
|
+
* @param tagName - The custom element tag name (must contain a hyphen)
|
|
27
|
+
* @param definition - The component configuration
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* component('counter-button', {
|
|
32
|
+
* props: {
|
|
33
|
+
* start: { type: Number, default: 0 },
|
|
34
|
+
* },
|
|
35
|
+
* state: { count: 0 },
|
|
36
|
+
* styles: `
|
|
37
|
+
* button { padding: 0.5rem 1rem; }
|
|
38
|
+
* `,
|
|
39
|
+
* connected() {
|
|
40
|
+
* // Use event delegation on shadow root so handler survives re-renders
|
|
41
|
+
* const handleClick = (event: Event) => {
|
|
42
|
+
* const target = event.target as HTMLElement | null;
|
|
43
|
+
* if (target?.matches('button')) {
|
|
44
|
+
* this.setState('count', (this.getState('count') as number) + 1);
|
|
45
|
+
* }
|
|
46
|
+
* };
|
|
47
|
+
* this.shadowRoot?.addEventListener('click', handleClick);
|
|
48
|
+
* // Store handler for cleanup
|
|
49
|
+
* (this as any)._handleClick = handleClick;
|
|
50
|
+
* },
|
|
51
|
+
* disconnected() {
|
|
52
|
+
* // Clean up event listener to prevent memory leaks
|
|
53
|
+
* const handleClick = (this as any)._handleClick;
|
|
54
|
+
* if (handleClick) {
|
|
55
|
+
* this.shadowRoot?.removeEventListener('click', handleClick);
|
|
56
|
+
* }
|
|
57
|
+
* },
|
|
58
|
+
* render({ props, state }) {
|
|
59
|
+
* return html`
|
|
60
|
+
* <button>
|
|
61
|
+
* Count: ${state.count}
|
|
62
|
+
* </button>
|
|
63
|
+
* `;
|
|
64
|
+
* },
|
|
65
|
+
* });
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export declare const component: <TProps extends Record<string, unknown>>(tagName: string, definition: ComponentDefinition<TProps>) => void;
|
|
69
|
+
//# sourceMappingURL=component.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component.d.ts","sourceRoot":"","sources":["../../src/component/component.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,EAAE,mBAAmB,EAAkB,MAAM,SAAS,CAAC;AAEnE;;;;;;;;;GASG;AACH,eAAO,MAAM,eAAe,GAAI,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACpE,SAAS,MAAM,EACf,YAAY,mBAAmB,CAAC,MAAM,CAAC,KACtC,OAAO,WA4MT,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACH,eAAO,MAAM,SAAS,GAAI,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9D,SAAS,MAAM,EACf,YAAY,mBAAmB,CAAC,MAAM,CAAC,KACtC,IAMF,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tagged template literal for creating HTML strings.
|
|
3
|
+
*
|
|
4
|
+
* This function handles interpolation of values into HTML templates,
|
|
5
|
+
* converting null/undefined to empty strings.
|
|
6
|
+
*
|
|
7
|
+
* @param strings - Template literal string parts
|
|
8
|
+
* @param values - Interpolated values
|
|
9
|
+
* @returns Combined HTML string
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* const name = 'World';
|
|
14
|
+
* const greeting = html`<h1>Hello, ${name}!</h1>`;
|
|
15
|
+
* // Result: '<h1>Hello, World!</h1>'
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare const html: (strings: TemplateStringsArray, ...values: unknown[]) => string;
|
|
19
|
+
/**
|
|
20
|
+
* Escapes HTML entities in interpolated values for XSS prevention.
|
|
21
|
+
* Use this when you need to safely embed user content in templates.
|
|
22
|
+
*
|
|
23
|
+
* @param strings - Template literal string parts
|
|
24
|
+
* @param values - Interpolated values to escape
|
|
25
|
+
* @returns Combined HTML string with escaped values
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* const userInput = '<script>alert("xss")</script>';
|
|
30
|
+
* const safe = safeHtml`<div>${userInput}</div>`;
|
|
31
|
+
* // Result: '<div><script>alert("xss")</script></div>'
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare const safeHtml: (strings: TemplateStringsArray, ...values: unknown[]) => string;
|
|
35
|
+
//# sourceMappingURL=html.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html.d.ts","sourceRoot":"","sources":["../../src/component/html.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,IAAI,GAAI,SAAS,oBAAoB,EAAE,GAAG,QAAQ,OAAO,EAAE,KAAG,MAE1E,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,QAAQ,GAAI,SAAS,oBAAoB,EAAE,GAAG,QAAQ,OAAO,EAAE,KAAG,MAgB9E,CAAC"}
|
|
@@ -34,130 +34,7 @@
|
|
|
34
34
|
* });
|
|
35
35
|
* ```
|
|
36
36
|
*/
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
* @template T - The TypeScript type of the prop value
|
|
41
|
-
*
|
|
42
|
-
* @example
|
|
43
|
-
* ```ts
|
|
44
|
-
* const myProp: PropDefinition<number> = {
|
|
45
|
-
* type: Number,
|
|
46
|
-
* required: false,
|
|
47
|
-
* default: 0,
|
|
48
|
-
* };
|
|
49
|
-
* ```
|
|
50
|
-
*/
|
|
51
|
-
export type PropDefinition<T = unknown> = {
|
|
52
|
-
/** Constructor or converter function for the prop type */
|
|
53
|
-
type: StringConstructor | NumberConstructor | BooleanConstructor | ObjectConstructor | ArrayConstructor | {
|
|
54
|
-
new (value: unknown): T;
|
|
55
|
-
} | ((value: unknown) => T);
|
|
56
|
-
/** Whether the prop must be provided */
|
|
57
|
-
required?: boolean;
|
|
58
|
-
/** Default value when prop is not provided */
|
|
59
|
-
default?: T;
|
|
60
|
-
/** Optional validator function to validate prop values */
|
|
61
|
-
validator?: (value: T) => boolean;
|
|
62
|
-
};
|
|
63
|
-
/**
|
|
64
|
-
* Complete component definition including props, state, styles, and lifecycle.
|
|
65
|
-
*
|
|
66
|
-
* @template TProps - Type of the component's props
|
|
67
|
-
*/
|
|
68
|
-
export type ComponentDefinition<TProps extends Record<string, unknown> = Record<string, unknown>> = {
|
|
69
|
-
/** Prop definitions with types and defaults */
|
|
70
|
-
props?: Record<keyof TProps, PropDefinition>;
|
|
71
|
-
/** Initial internal state */
|
|
72
|
-
state?: Record<string, unknown>;
|
|
73
|
-
/** CSS styles scoped to the component's shadow DOM */
|
|
74
|
-
styles?: string;
|
|
75
|
-
/** Lifecycle hook called before the component mounts (before first render) */
|
|
76
|
-
beforeMount?: () => void;
|
|
77
|
-
/** Lifecycle hook called when component is added to DOM */
|
|
78
|
-
connected?: () => void;
|
|
79
|
-
/** Lifecycle hook called when component is removed from DOM */
|
|
80
|
-
disconnected?: () => void;
|
|
81
|
-
/** Lifecycle hook called before an update render; return false to prevent */
|
|
82
|
-
beforeUpdate?: (props: TProps) => boolean | void;
|
|
83
|
-
/** Lifecycle hook called after reactive updates trigger a render */
|
|
84
|
-
updated?: () => void;
|
|
85
|
-
/** Error handler for errors during rendering or lifecycle */
|
|
86
|
-
onError?: (error: Error) => void;
|
|
87
|
-
/** Render function returning HTML string */
|
|
88
|
-
render: (context: {
|
|
89
|
-
props: TProps;
|
|
90
|
-
state: Record<string, unknown>;
|
|
91
|
-
emit: (event: string, detail?: unknown) => void;
|
|
92
|
-
}) => string;
|
|
93
|
-
};
|
|
94
|
-
/**
|
|
95
|
-
* Tagged template literal for creating HTML strings.
|
|
96
|
-
*
|
|
97
|
-
* This function handles interpolation of values into HTML templates,
|
|
98
|
-
* converting null/undefined to empty strings.
|
|
99
|
-
*
|
|
100
|
-
* @param strings - Template literal string parts
|
|
101
|
-
* @param values - Interpolated values
|
|
102
|
-
* @returns Combined HTML string
|
|
103
|
-
*
|
|
104
|
-
* @example
|
|
105
|
-
* ```ts
|
|
106
|
-
* const name = 'World';
|
|
107
|
-
* const greeting = html`<h1>Hello, ${name}!</h1>`;
|
|
108
|
-
* // Result: '<h1>Hello, World!</h1>'
|
|
109
|
-
* ```
|
|
110
|
-
*/
|
|
111
|
-
export declare const html: (strings: TemplateStringsArray, ...values: unknown[]) => string;
|
|
112
|
-
/**
|
|
113
|
-
* Escapes HTML entities in interpolated values for XSS prevention.
|
|
114
|
-
* Use this when you need to safely embed user content in templates.
|
|
115
|
-
*
|
|
116
|
-
* @param strings - Template literal string parts
|
|
117
|
-
* @param values - Interpolated values to escape
|
|
118
|
-
* @returns Combined HTML string with escaped values
|
|
119
|
-
*
|
|
120
|
-
* @example
|
|
121
|
-
* ```ts
|
|
122
|
-
* const userInput = '<script>alert("xss")</script>';
|
|
123
|
-
* const safe = safeHtml`<div>${userInput}</div>`;
|
|
124
|
-
* // Result: '<div><script>alert("xss")</script></div>'
|
|
125
|
-
* ```
|
|
126
|
-
*/
|
|
127
|
-
export declare const safeHtml: (strings: TemplateStringsArray, ...values: unknown[]) => string;
|
|
128
|
-
/**
|
|
129
|
-
* Defines and registers a custom Web Component.
|
|
130
|
-
*
|
|
131
|
-
* This function creates a new custom element with the given tag name
|
|
132
|
-
* and configuration. The component uses Shadow DOM for encapsulation
|
|
133
|
-
* and automatically re-renders when observed attributes change.
|
|
134
|
-
*
|
|
135
|
-
* @template TProps - Type of the component's props
|
|
136
|
-
* @param tagName - The custom element tag name (must contain a hyphen)
|
|
137
|
-
* @param definition - The component configuration
|
|
138
|
-
*
|
|
139
|
-
* @example
|
|
140
|
-
* ```ts
|
|
141
|
-
* component('counter-button', {
|
|
142
|
-
* props: {
|
|
143
|
-
* start: { type: Number, default: 0 },
|
|
144
|
-
* },
|
|
145
|
-
* state: { count: 0 },
|
|
146
|
-
* styles: `
|
|
147
|
-
* button { padding: 0.5rem 1rem; }
|
|
148
|
-
* `,
|
|
149
|
-
* connected() {
|
|
150
|
-
* console.log('Counter mounted');
|
|
151
|
-
* },
|
|
152
|
-
* render({ props, state, emit }) {
|
|
153
|
-
* return html`
|
|
154
|
-
* <button onclick="this.getRootNode().host.increment()">
|
|
155
|
-
* Count: ${state.count}
|
|
156
|
-
* </button>
|
|
157
|
-
* `;
|
|
158
|
-
* },
|
|
159
|
-
* });
|
|
160
|
-
* ```
|
|
161
|
-
*/
|
|
162
|
-
export declare const component: <TProps extends Record<string, unknown>>(tagName: string, definition: ComponentDefinition<TProps>) => void;
|
|
37
|
+
export { component, defineComponent } from './component';
|
|
38
|
+
export { html, safeHtml } from './html';
|
|
39
|
+
export type { ComponentDefinition, ComponentRenderContext, PropDefinition } from './types';
|
|
163
40
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/component/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/component/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AACxC,YAAY,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prop coercion utilities.
|
|
3
|
+
*
|
|
4
|
+
* @module bquery/component
|
|
5
|
+
*/
|
|
6
|
+
import type { PropDefinition } from './types';
|
|
7
|
+
/**
|
|
8
|
+
* Coerces a string attribute value into a typed prop value.
|
|
9
|
+
* Supports String, Number, Boolean, Object, Array, and custom converters.
|
|
10
|
+
*
|
|
11
|
+
* @internal
|
|
12
|
+
* @template T - The target type
|
|
13
|
+
* @param rawValue - The raw string value from the attribute
|
|
14
|
+
* @param config - The prop definition with type information
|
|
15
|
+
* @returns The coerced value of type T
|
|
16
|
+
*/
|
|
17
|
+
export declare const coercePropValue: <T>(rawValue: string, config: PropDefinition<T>) => T;
|
|
18
|
+
//# sourceMappingURL=props.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"props.d.ts","sourceRoot":"","sources":["../../src/component/props.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C;;;;;;;;;GASG;AACH,eAAO,MAAM,eAAe,GAAI,CAAC,EAAE,UAAU,MAAM,EAAE,QAAQ,cAAc,CAAC,CAAC,CAAC,KAAG,CAiGhF,CAAC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Component types and render context definitions.
|
|
3
|
+
*
|
|
4
|
+
* @module bquery/component
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Defines a single prop's type and configuration.
|
|
8
|
+
*
|
|
9
|
+
* @template T - The TypeScript type of the prop value
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* const myProp: PropDefinition<number> = {
|
|
14
|
+
* type: Number,
|
|
15
|
+
* required: false,
|
|
16
|
+
* default: 0,
|
|
17
|
+
* };
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export type PropDefinition<T = unknown> = {
|
|
21
|
+
/** Constructor or converter function for the prop type */
|
|
22
|
+
type: StringConstructor | NumberConstructor | BooleanConstructor | ObjectConstructor | ArrayConstructor | {
|
|
23
|
+
new (value: unknown): T;
|
|
24
|
+
} | ((value: unknown) => T);
|
|
25
|
+
/** Whether the prop must be provided */
|
|
26
|
+
required?: boolean;
|
|
27
|
+
/** Default value when prop is not provided */
|
|
28
|
+
default?: T;
|
|
29
|
+
/** Optional validator function to validate prop values */
|
|
30
|
+
validator?: (value: T) => boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Explicitly control whether to invoke `type` with `new` (constructor) or as a plain function.
|
|
33
|
+
* - `true`: Always use `new type(value)` (for class constructors, Date, etc.)
|
|
34
|
+
* - `false`: Always call `type(value)` (for converter functions)
|
|
35
|
+
* - `undefined` (default): Auto-detect based on heuristics with fallback
|
|
36
|
+
*/
|
|
37
|
+
construct?: boolean;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Render context passed into a component render function.
|
|
41
|
+
*/
|
|
42
|
+
export type ComponentRenderContext<TProps extends Record<string, unknown>> = {
|
|
43
|
+
/** Typed props object populated from attributes */
|
|
44
|
+
props: TProps;
|
|
45
|
+
/** Internal mutable state object */
|
|
46
|
+
state: Record<string, unknown>;
|
|
47
|
+
/** Emit a custom event from the component */
|
|
48
|
+
emit: (event: string, detail?: unknown) => void;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Complete component definition including props, state, styles, and lifecycle.
|
|
52
|
+
*
|
|
53
|
+
* @template TProps - Type of the component's props
|
|
54
|
+
*/
|
|
55
|
+
export type ComponentDefinition<TProps extends Record<string, unknown> = Record<string, unknown>> = {
|
|
56
|
+
/** Prop definitions with types and defaults */
|
|
57
|
+
props?: Record<keyof TProps, PropDefinition>;
|
|
58
|
+
/** Initial internal state */
|
|
59
|
+
state?: Record<string, unknown>;
|
|
60
|
+
/** CSS styles scoped to the component's shadow DOM */
|
|
61
|
+
styles?: string;
|
|
62
|
+
/** Lifecycle hook called before the component mounts (before first render) */
|
|
63
|
+
beforeMount?: () => void;
|
|
64
|
+
/** Lifecycle hook called when component is added to DOM */
|
|
65
|
+
connected?: () => void;
|
|
66
|
+
/** Lifecycle hook called when component is removed from DOM */
|
|
67
|
+
disconnected?: () => void;
|
|
68
|
+
/** Lifecycle hook called before an update render; return false to prevent */
|
|
69
|
+
beforeUpdate?: (props: TProps) => boolean | void;
|
|
70
|
+
/** Lifecycle hook called after reactive updates trigger a render */
|
|
71
|
+
updated?: () => void;
|
|
72
|
+
/** Error handler for errors during rendering or lifecycle */
|
|
73
|
+
onError?: (error: Error) => void;
|
|
74
|
+
/** Render function returning HTML string */
|
|
75
|
+
render: (context: ComponentRenderContext<TProps>) => string;
|
|
76
|
+
};
|
|
77
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/component/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,cAAc,CAAC,CAAC,GAAG,OAAO,IAAI;IACxC,0DAA0D;IAC1D,IAAI,EACA,iBAAiB,GACjB,iBAAiB,GACjB,kBAAkB,GAClB,iBAAiB,GACjB,gBAAgB,GAChB;QAAE,KAAK,KAAK,EAAE,OAAO,GAAG,CAAC,CAAA;KAAE,GAC3B,CAAC,CAAC,KAAK,EAAE,OAAO,KAAK,CAAC,CAAC,CAAC;IAC5B,wCAAwC;IACxC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,8CAA8C;IAC9C,OAAO,CAAC,EAAE,CAAC,CAAC;IACZ,0DAA0D;IAC1D,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,CAAC;IAClC;;;;;OAKG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,sBAAsB,CAAC,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI;IAC3E,mDAAmD;IACnD,KAAK,EAAE,MAAM,CAAC;IACd,oCAAoC;IACpC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,6CAA6C;IAC7C,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;CACjD,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,CAAC,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAC9F;IACE,+CAA+C;IAC/C,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,MAAM,EAAE,cAAc,CAAC,CAAC;IAC7C,6BAA6B;IAC7B,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,sDAAsD;IACtD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,8EAA8E;IAC9E,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC;IACzB,2DAA2D;IAC3D,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;IACvB,+DAA+D;IAC/D,YAAY,CAAC,EAAE,MAAM,IAAI,CAAC;IAC1B,6EAA6E;IAC7E,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,GAAG,IAAI,CAAC;IACjD,oEAAoE;IACpE,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,6DAA6D;IAC7D,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,4CAA4C;IAC5C,MAAM,EAAE,CAAC,OAAO,EAAE,sBAAsB,CAAC,MAAM,CAAC,KAAK,MAAM,CAAC;CAC7D,CAAC"}
|