@bquery/bquery 1.4.0 → 1.6.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 +586 -527
- package/dist/component/component.d.ts +13 -5
- package/dist/component/component.d.ts.map +1 -1
- package/dist/component/html.d.ts +40 -3
- package/dist/component/html.d.ts.map +1 -1
- package/dist/component/index.d.ts +4 -2
- 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 +132 -13
- package/dist/component/types.d.ts.map +1 -1
- package/dist/component-BEQgt5hl.js +600 -0
- package/dist/component-BEQgt5hl.js.map +1 -0
- package/dist/component.es.mjs +7 -184
- package/dist/config-DRmZZno3.js +40 -0
- package/dist/config-DRmZZno3.js.map +1 -0
- package/dist/core-BGQJVw0-.js +35 -0
- package/dist/core-BGQJVw0-.js.map +1 -0
- package/dist/core-CCEabVHl.js +648 -0
- package/dist/core-CCEabVHl.js.map +1 -0
- package/dist/core.es.mjs +45 -1261
- package/dist/effect-AFRW_Plg.js +84 -0
- package/dist/effect-AFRW_Plg.js.map +1 -0
- package/dist/full.d.ts +8 -8
- package/dist/full.d.ts.map +1 -1
- package/dist/full.es.mjs +101 -91
- 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 +147 -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-D9TcHxOF.js +415 -0
- package/dist/motion-D9TcHxOF.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-Dr9b6fsq.js +362 -0
- package/dist/platform-Dr9b6fsq.js.map +1 -0
- package/dist/platform.es.mjs +11 -248
- package/dist/reactive/async-data.d.ts +114 -0
- package/dist/reactive/async-data.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/signal.d.ts +2 -0
- package/dist/reactive/signal.d.ts.map +1 -1
- package/dist/reactive-DSkct0dO.js +254 -0
- package/dist/reactive-DSkct0dO.js.map +1 -0
- package/dist/reactive.es.mjs +18 -32
- package/dist/router-CbDhl8rS.js +188 -0
- package/dist/router-CbDhl8rS.js.map +1 -0
- package/dist/router.es.mjs +11 -200
- package/dist/sanitize-Bs2dkMby.js +313 -0
- package/dist/sanitize-Bs2dkMby.js.map +1 -0
- package/dist/security/constants.d.ts.map +1 -1
- package/dist/security/index.d.ts +4 -2
- package/dist/security/index.d.ts.map +1 -1
- package/dist/security/sanitize.d.ts +4 -1
- package/dist/security/sanitize.d.ts.map +1 -1
- package/dist/security/trusted-html.d.ts +53 -0
- package/dist/security/trusted-html.d.ts.map +1 -0
- package/dist/security.es.mjs +11 -56
- package/dist/store/define-store.d.ts +1 -1
- package/dist/store/define-store.d.ts.map +1 -1
- package/dist/store/mapping.d.ts +1 -1
- package/dist/store/mapping.d.ts.map +1 -1
- package/dist/store/persisted.d.ts +1 -1
- package/dist/store/persisted.d.ts.map +1 -1
- package/dist/store/types.d.ts +2 -2
- package/dist/store/types.d.ts.map +1 -1
- package/dist/store/watch.d.ts +1 -1
- package/dist/store/watch.d.ts.map +1 -1
- package/dist/store-BwDvI45q.js +263 -0
- package/dist/store-BwDvI45q.js.map +1 -0
- package/dist/store.es.mjs +12 -25
- package/dist/storybook/index.d.ts +37 -0
- package/dist/storybook/index.d.ts.map +1 -0
- package/dist/storybook.es.mjs +151 -0
- package/dist/storybook.es.mjs.map +1 -0
- package/dist/untrack-B0rVscTc.js +7 -0
- package/dist/untrack-B0rVscTc.js.map +1 -0
- package/dist/view-C70lA3vf.js +397 -0
- package/dist/view-C70lA3vf.js.map +1 -0
- package/dist/view.es.mjs +11 -430
- package/package.json +141 -132
- package/src/component/component.ts +524 -289
- package/src/component/html.ts +153 -53
- package/src/component/index.ts +50 -40
- package/src/component/library.ts +518 -0
- package/src/component/types.ts +256 -85
- package/src/core/collection.ts +628 -628
- package/src/core/element.ts +774 -774
- package/src/core/index.ts +48 -48
- package/src/core/utils/function.ts +151 -151
- package/src/full.ts +229 -187
- package/src/motion/animate.ts +113 -113
- package/src/motion/flip.ts +176 -176
- package/src/motion/scroll.ts +57 -57
- package/src/motion/spring.ts +150 -150
- package/src/motion/timeline.ts +246 -246
- package/src/motion/transition.ts +97 -51
- package/src/motion/types.ts +11 -1
- 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 +21 -0
- package/src/platform/meta.ts +168 -0
- package/src/platform/storage.ts +215 -215
- package/src/reactive/async-data.ts +486 -0
- package/src/reactive/core.ts +114 -114
- package/src/reactive/effect.ts +54 -54
- package/src/reactive/index.ts +15 -1
- package/src/reactive/internals.ts +122 -122
- package/src/reactive/signal.ts +9 -0
- package/src/security/constants.ts +3 -1
- package/src/security/index.ts +17 -10
- package/src/security/sanitize-core.ts +364 -364
- package/src/security/sanitize.ts +70 -66
- package/src/security/trusted-html.ts +71 -0
- package/src/store/define-store.ts +49 -48
- package/src/store/mapping.ts +74 -73
- package/src/store/persisted.ts +62 -61
- package/src/store/types.ts +92 -94
- package/src/store/watch.ts +53 -52
- package/src/storybook/index.ts +479 -0
- package/src/view/evaluate.ts +290 -290
- package/dist/batch-x7b2eZST.js +0 -13
- package/dist/batch-x7b2eZST.js.map +0 -1
- package/dist/component.es.mjs.map +0 -1
- package/dist/core-BhpuvPhy.js +0 -170
- package/dist/core-BhpuvPhy.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-DHoi3uEs.js +0 -278
- package/dist/persisted-DHoi3uEs.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-Cxvxa-DX.js +0 -283
- package/dist/sanitize-Cxvxa-DX.js.map +0 -1
- package/dist/security.es.mjs.map +0 -1
- package/dist/store.es.mjs.map +0 -1
- package/dist/type-guards-BdKlYYlS.js +0 -32
- package/dist/type-guards-BdKlYYlS.js.map +0 -1
- package/dist/untrack-DNnnqdlR.js +0 -6
- package/dist/untrack-DNnnqdlR.js.map +0 -1
- package/dist/view.es.mjs.map +0 -1
- package/dist/watch-DXXv3iAI.js +0 -58
- package/dist/watch-DXXv3iAI.js.map +0 -1
package/src/component/html.ts
CHANGED
|
@@ -1,53 +1,153 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
'
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
1
|
+
import {
|
|
2
|
+
isTrustedHtml,
|
|
3
|
+
type SanitizedHtml,
|
|
4
|
+
toSanitizedHtml,
|
|
5
|
+
unwrapTrustedHtml,
|
|
6
|
+
} from '../security/trusted-html';
|
|
7
|
+
const BOOLEAN_ATTRIBUTE_MARKER: unique symbol = Symbol('bquery.booleanAttribute');
|
|
8
|
+
const BOOLEAN_ATTRIBUTE_NAME = /^[^\0-\x20"'/>=]+$/;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Public shape of a boolean HTML attribute created by {@link bool}.
|
|
12
|
+
*
|
|
13
|
+
* This type is returned from {@link bool} and can be interpolated into
|
|
14
|
+
* {@link html} / {@link safeHtml} templates to conditionally include or omit
|
|
15
|
+
* an attribute by name. The internal marker property used for runtime checks
|
|
16
|
+
* remains private and is not part of the public API.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const disabled = bool('disabled', isDisabled);
|
|
21
|
+
* const button = html`<button ${disabled}>Click</button>`;
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export interface BooleanAttribute {
|
|
25
|
+
readonly enabled: boolean;
|
|
26
|
+
readonly name: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
interface BooleanAttributeValue extends BooleanAttribute {
|
|
30
|
+
readonly [BOOLEAN_ATTRIBUTE_MARKER]: true;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const isBooleanAttributeValue = (value: unknown): value is BooleanAttributeValue => {
|
|
34
|
+
if (typeof value !== 'object' || value === null) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const candidate = value as Partial<BooleanAttributeValue>;
|
|
39
|
+
return (
|
|
40
|
+
candidate[BOOLEAN_ATTRIBUTE_MARKER] === true &&
|
|
41
|
+
typeof candidate.enabled === 'boolean' &&
|
|
42
|
+
typeof candidate.name === 'string'
|
|
43
|
+
);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const stringifyTemplateValue = (value: unknown): string => {
|
|
47
|
+
if (isBooleanAttributeValue(value)) {
|
|
48
|
+
return value.enabled ? value.name : '';
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return String(value ?? '');
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const escapeMap: Record<string, string> = {
|
|
55
|
+
'&': '&',
|
|
56
|
+
'<': '<',
|
|
57
|
+
'>': '>',
|
|
58
|
+
'"': '"',
|
|
59
|
+
"'": ''',
|
|
60
|
+
'`': '`',
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const escapeTemplateValue = (value: unknown): string => {
|
|
64
|
+
if (isBooleanAttributeValue(value)) {
|
|
65
|
+
return value.enabled ? value.name : '';
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return stringifyTemplateValue(value).replace(/[&<>"'`]/g, (char) => escapeMap[char]);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Creates a boolean-attribute marker for the {@link html} and {@link safeHtml} template tags.
|
|
73
|
+
*
|
|
74
|
+
* When the condition is truthy, the attribute name is rendered without a value.
|
|
75
|
+
* When the condition is falsy, an empty string is rendered and any surrounding
|
|
76
|
+
* template-literal whitespace is preserved.
|
|
77
|
+
*
|
|
78
|
+
* @param name - HTML attribute name to emit
|
|
79
|
+
* @param enabled - Whether the boolean attribute should be present
|
|
80
|
+
* @returns Internal marker consumed by template tags
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```ts
|
|
84
|
+
* html`<button ${bool('disabled', isDisabled)}>Save</button>`;
|
|
85
|
+
* // Result when isDisabled = true: '<button disabled>Save</button>'
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
export const bool = (name: string, enabled: unknown): BooleanAttribute => {
|
|
89
|
+
if (!BOOLEAN_ATTRIBUTE_NAME.test(name)) {
|
|
90
|
+
throw new TypeError(`Invalid boolean attribute name: ${name}`);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const attribute: BooleanAttributeValue = {
|
|
94
|
+
[BOOLEAN_ATTRIBUTE_MARKER]: true,
|
|
95
|
+
enabled: Boolean(enabled),
|
|
96
|
+
name,
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
return Object.freeze(attribute);
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Tagged template literal for creating HTML strings.
|
|
104
|
+
*
|
|
105
|
+
* This function handles interpolation of values into HTML templates,
|
|
106
|
+
* converting null/undefined to empty strings.
|
|
107
|
+
*
|
|
108
|
+
* @param strings - Template literal string parts
|
|
109
|
+
* @param values - Interpolated values
|
|
110
|
+
* @returns Combined HTML string
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```ts
|
|
114
|
+
* const name = 'World';
|
|
115
|
+
* const greeting = html`<h1>Hello, ${name}!</h1>`;
|
|
116
|
+
* // Result: '<h1>Hello, World!</h1>'
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
export const html = (strings: TemplateStringsArray, ...values: unknown[]): string => {
|
|
120
|
+
return strings.reduce((acc, part, index) => `${acc}${part}${stringifyTemplateValue(values[index])}`, '');
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Escapes HTML entities in interpolated values for XSS prevention.
|
|
125
|
+
* Use this when you need to safely embed user content in templates.
|
|
126
|
+
*
|
|
127
|
+
* @param strings - Template literal string parts
|
|
128
|
+
* @param values - Interpolated values to escape
|
|
129
|
+
* @returns Branded escaped HTML string safe for bQuery template composition
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```ts
|
|
133
|
+
* const userInput = '<script>alert("xss")</script>';
|
|
134
|
+
* const safe = safeHtml`<div>${userInput}</div>`;
|
|
135
|
+
* // Result: '<div><script>alert("xss")</script></div>'
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
export const safeHtml = (
|
|
139
|
+
strings: TemplateStringsArray,
|
|
140
|
+
...values: unknown[]
|
|
141
|
+
): SanitizedHtml => {
|
|
142
|
+
const escape = (value: unknown): string => {
|
|
143
|
+
if (isTrustedHtml(value)) return unwrapTrustedHtml(value);
|
|
144
|
+
return escapeTemplateValue(value);
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
return toSanitizedHtml(
|
|
148
|
+
strings.reduce(
|
|
149
|
+
(acc, part, index) => `${acc}${part}${index < values.length ? escape(values[index]) : ''}`,
|
|
150
|
+
''
|
|
151
|
+
)
|
|
152
|
+
);
|
|
153
|
+
};
|
package/src/component/index.ts
CHANGED
|
@@ -1,40 +1,50 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Minimal Web Component helper for building custom elements.
|
|
3
|
-
*
|
|
4
|
-
* This module provides a declarative API for defining Web Components
|
|
5
|
-
* without complex build steps. Features include:
|
|
6
|
-
* - Type-safe props with automatic attribute coercion
|
|
7
|
-
* - Reactive state management
|
|
8
|
-
* - Shadow DOM encapsulation with scoped styles
|
|
9
|
-
* - Lifecycle hooks (connected, disconnected)
|
|
10
|
-
* - Event emission helpers
|
|
11
|
-
*
|
|
12
|
-
* @module bquery/component
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```ts
|
|
16
|
-
* import { component, html } from 'bquery/component';
|
|
17
|
-
*
|
|
18
|
-
* component('user-card', {
|
|
19
|
-
* props: {
|
|
20
|
-
* username: { type: String, required: true },
|
|
21
|
-
* avatar: { type: String, default: '/default-avatar.png' },
|
|
22
|
-
* },
|
|
23
|
-
* styles: `
|
|
24
|
-
* .card { padding: 1rem; border: 1px solid #ccc; }
|
|
25
|
-
* `,
|
|
26
|
-
* render({ props }) {
|
|
27
|
-
* return html`
|
|
28
|
-
* <div class="card">
|
|
29
|
-
* <img src="${props.avatar}" alt="${props.username}" />
|
|
30
|
-
* <h3>${props.username}</h3>
|
|
31
|
-
* </div>
|
|
32
|
-
* `;
|
|
33
|
-
* },
|
|
34
|
-
* });
|
|
35
|
-
* ```
|
|
36
|
-
*/
|
|
37
|
-
|
|
38
|
-
export { component, defineComponent } from './component';
|
|
39
|
-
export { html, safeHtml } from './html';
|
|
40
|
-
export
|
|
1
|
+
/**
|
|
2
|
+
* Minimal Web Component helper for building custom elements.
|
|
3
|
+
*
|
|
4
|
+
* This module provides a declarative API for defining Web Components
|
|
5
|
+
* without complex build steps. Features include:
|
|
6
|
+
* - Type-safe props with automatic attribute coercion
|
|
7
|
+
* - Reactive state management
|
|
8
|
+
* - Shadow DOM encapsulation with scoped styles
|
|
9
|
+
* - Lifecycle hooks (connected, disconnected)
|
|
10
|
+
* - Event emission helpers
|
|
11
|
+
*
|
|
12
|
+
* @module bquery/component
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* import { component, html } from 'bquery/component';
|
|
17
|
+
*
|
|
18
|
+
* component('user-card', {
|
|
19
|
+
* props: {
|
|
20
|
+
* username: { type: String, required: true },
|
|
21
|
+
* avatar: { type: String, default: '/default-avatar.png' },
|
|
22
|
+
* },
|
|
23
|
+
* styles: `
|
|
24
|
+
* .card { padding: 1rem; border: 1px solid #ccc; }
|
|
25
|
+
* `,
|
|
26
|
+
* render({ props }) {
|
|
27
|
+
* return html`
|
|
28
|
+
* <div class="card">
|
|
29
|
+
* <img src="${props.avatar}" alt="${props.username}" />
|
|
30
|
+
* <h3>${props.username}</h3>
|
|
31
|
+
* </div>
|
|
32
|
+
* `;
|
|
33
|
+
* },
|
|
34
|
+
* });
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
export { component, defineComponent } from './component';
|
|
39
|
+
export { bool, html, safeHtml } from './html';
|
|
40
|
+
export { registerDefaultComponents } from './library';
|
|
41
|
+
export type { DefaultComponentLibraryOptions, RegisteredDefaultComponents } from './library';
|
|
42
|
+
export type {
|
|
43
|
+
AttributeChange,
|
|
44
|
+
ComponentDefinition,
|
|
45
|
+
ComponentRenderContext,
|
|
46
|
+
ComponentStateKey,
|
|
47
|
+
ComponentSignalLike,
|
|
48
|
+
ComponentSignals,
|
|
49
|
+
PropDefinition,
|
|
50
|
+
} from './types';
|