@bquery/bquery 1.2.0 → 1.3.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 +501 -427
- package/dist/batch-4LAvfLE7.js +13 -0
- package/dist/batch-4LAvfLE7.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 +36 -0
- 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 +8 -0
- 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/array.d.ts +74 -0
- package/dist/core/utils/array.d.ts.map +1 -0
- package/dist/core/utils/function.d.ts +70 -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-COenAZjD.js +145 -0
- package/dist/core-COenAZjD.js.map +1 -0
- package/dist/core.es.mjs +411 -448
- 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-Dz_ryNuC.js +278 -0
- package/dist/persisted-Dz_ryNuC.js.map +1 -0
- 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 +60 -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 +36 -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-1FBEPAFH.js +272 -0
- package/dist/sanitize-1FBEPAFH.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-DRma3-Kc.js +16 -0
- package/dist/type-guards-DRma3-Kc.js.map +1 -0
- package/dist/untrack-BuEQKH7_.js +6 -0
- package/dist/untrack-BuEQKH7_.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 +368 -267
- package/dist/view.es.mjs.map +1 -1
- package/dist/watch-CXyaBC_9.js +58 -0
- package/dist/watch-CXyaBC_9.js.map +1 -0
- package/package.json +132 -132
- 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 +588 -454
- package/src/core/dom.ts +38 -0
- package/src/core/element.ts +746 -740
- package/src/core/index.ts +43 -0
- package/src/core/utils/array.ts +102 -0
- package/src/core/utils/function.ts +110 -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/reactive/batch.ts +22 -0
- package/src/reactive/computed.ts +92 -0
- package/src/reactive/core.ts +93 -0
- package/src/reactive/effect.ts +43 -0
- package/src/reactive/index.ts +23 -22
- package/src/reactive/internals.ts +105 -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 +343 -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 +274 -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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component.es.mjs","sources":["../src/component/index.ts"],"sourcesContent":["/**\r\n * Minimal Web Component helper for building custom elements.\r\n *\r\n * This module provides a declarative API for defining Web Components\r\n * without complex build steps. Features include:\r\n * - Type-safe props with automatic attribute coercion\r\n * - Reactive state management\r\n * - Shadow DOM encapsulation with scoped styles\r\n * - Lifecycle hooks (connected, disconnected)\r\n * - Event emission helpers\r\n *\r\n * @module bquery/component\r\n *\r\n * @example\r\n * ```ts\r\n * import { component, html } from 'bquery/component';\r\n *\r\n * component('user-card', {\r\n * props: {\r\n * username: { type: String, required: true },\r\n * avatar: { type: String, default: '/default-avatar.png' },\r\n * },\r\n * styles: `\r\n * .card { padding: 1rem; border: 1px solid #ccc; }\r\n * `,\r\n * render({ props }) {\r\n * return html`\r\n * <div class=\"card\">\r\n * <img src=\"${props.avatar}\" alt=\"${props.username}\" />\r\n * <h3>${props.username}</h3>\r\n * </div>\r\n * `;\r\n * },\r\n * });\r\n * ```\r\n */\r\n\r\n/**\r\n * Defines a single prop's type and configuration.\r\n *\r\n * @template T - The TypeScript type of the prop value\r\n *\r\n * @example\r\n * ```ts\r\n * const myProp: PropDefinition<number> = {\r\n * type: Number,\r\n * required: false,\r\n * default: 0,\r\n * };\r\n * ```\r\n */\r\nexport type PropDefinition<T = unknown> = {\r\n /** Constructor or converter function for the prop type */\r\n type:\r\n | StringConstructor\r\n | NumberConstructor\r\n | BooleanConstructor\r\n | ObjectConstructor\r\n | ArrayConstructor\r\n | { new (value: unknown): T }\r\n | ((value: unknown) => T);\r\n /** Whether the prop must be provided */\r\n required?: boolean;\r\n /** Default value when prop is not provided */\r\n default?: T;\r\n /** Optional validator function to validate prop values */\r\n validator?: (value: T) => boolean;\r\n};\r\n\r\n/**\r\n * Complete component definition including props, state, styles, and lifecycle.\r\n *\r\n * @template TProps - Type of the component's props\r\n */\r\nexport type ComponentDefinition<TProps extends Record<string, unknown> = Record<string, unknown>> =\r\n {\r\n /** Prop definitions with types and defaults */\r\n props?: Record<keyof TProps, PropDefinition>;\r\n /** Initial internal state */\r\n state?: Record<string, unknown>;\r\n /** CSS styles scoped to the component's shadow DOM */\r\n styles?: string;\r\n /** Lifecycle hook called before the component mounts (before first render) */\r\n beforeMount?: () => void;\r\n /** Lifecycle hook called when component is added to DOM */\r\n connected?: () => void;\r\n /** Lifecycle hook called when component is removed from DOM */\r\n disconnected?: () => void;\r\n /** Lifecycle hook called before an update render; return false to prevent */\r\n beforeUpdate?: (props: TProps) => boolean | void;\r\n /** Lifecycle hook called after reactive updates trigger a render */\r\n updated?: () => void;\r\n /** Error handler for errors during rendering or lifecycle */\r\n onError?: (error: Error) => void;\r\n /** Render function returning HTML string */\r\n render: (context: {\r\n props: TProps;\r\n state: Record<string, unknown>;\r\n emit: (event: string, detail?: unknown) => void;\r\n }) => string;\r\n };\r\n\r\n/**\r\n * Coerces a string attribute value into a typed prop value.\r\n * Supports String, Number, Boolean, Object, Array, and custom converters.\r\n *\r\n * @internal\r\n * @template T - The target type\r\n * @param rawValue - The raw string value from the attribute\r\n * @param config - The prop definition with type information\r\n * @returns The coerced value of type T\r\n */\r\nconst coercePropValue = <T>(rawValue: string, config: PropDefinition<T>): T => {\r\n const { type } = config;\r\n\r\n if (type === String) return rawValue as T;\r\n\r\n if (type === Number) {\r\n const parsed = Number(rawValue);\r\n return (Number.isNaN(parsed) ? rawValue : parsed) as T;\r\n }\r\n\r\n if (type === Boolean) {\r\n const normalized = rawValue.trim().toLowerCase();\r\n if (normalized === '' || normalized === 'true' || normalized === '1') {\r\n return true as T;\r\n }\r\n if (normalized === 'false' || normalized === '0') {\r\n return false as T;\r\n }\r\n return Boolean(rawValue) as T;\r\n }\r\n\r\n if (type === Object || type === Array) {\r\n try {\r\n return JSON.parse(rawValue) as T;\r\n } catch {\r\n return rawValue as T;\r\n }\r\n }\r\n\r\n if (typeof type === 'function') {\r\n const callable = type as (value: unknown) => T;\r\n const constructable = type as new (value: unknown) => T;\r\n try {\r\n return callable(rawValue);\r\n } catch {\r\n return new constructable(rawValue);\r\n }\r\n }\r\n\r\n return rawValue as T;\r\n};\r\n\r\n/**\r\n * Tagged template literal for creating HTML strings.\r\n *\r\n * This function handles interpolation of values into HTML templates,\r\n * converting null/undefined to empty strings.\r\n *\r\n * @param strings - Template literal string parts\r\n * @param values - Interpolated values\r\n * @returns Combined HTML string\r\n *\r\n * @example\r\n * ```ts\r\n * const name = 'World';\r\n * const greeting = html`<h1>Hello, ${name}!</h1>`;\r\n * // Result: '<h1>Hello, World!</h1>'\r\n * ```\r\n */\r\nexport const html = (strings: TemplateStringsArray, ...values: unknown[]): string => {\r\n return strings.reduce((acc, part, index) => `${acc}${part}${values[index] ?? ''}`, '');\r\n};\r\n\r\n/**\r\n * Escapes HTML entities in interpolated values for XSS prevention.\r\n * Use this when you need to safely embed user content in templates.\r\n *\r\n * @param strings - Template literal string parts\r\n * @param values - Interpolated values to escape\r\n * @returns Combined HTML string with escaped values\r\n *\r\n * @example\r\n * ```ts\r\n * const userInput = '<script>alert(\"xss\")</script>';\r\n * const safe = safeHtml`<div>${userInput}</div>`;\r\n * // Result: '<div><script>alert(\"xss\")</script></div>'\r\n * ```\r\n */\r\nexport const safeHtml = (strings: TemplateStringsArray, ...values: unknown[]): string => {\r\n const escapeMap: Record<string, string> = {\r\n '&': '&',\r\n '<': '<',\r\n '>': '>',\r\n '\"': '"',\r\n \"'\": ''',\r\n '`': '`',\r\n };\r\n\r\n const escape = (value: unknown): string => {\r\n const str = String(value ?? '');\r\n return str.replace(/[&<>\"'`]/g, (char) => escapeMap[char]);\r\n };\r\n\r\n return strings.reduce((acc, part, index) => `${acc}${part}${escape(values[index])}`, '');\r\n};\r\n\r\n/**\r\n * Defines and registers a custom Web Component.\r\n *\r\n * This function creates a new custom element with the given tag name\r\n * and configuration. The component uses Shadow DOM for encapsulation\r\n * and automatically re-renders when observed attributes change.\r\n *\r\n * @template TProps - Type of the component's props\r\n * @param tagName - The custom element tag name (must contain a hyphen)\r\n * @param definition - The component configuration\r\n *\r\n * @example\r\n * ```ts\r\n * component('counter-button', {\r\n * props: {\r\n * start: { type: Number, default: 0 },\r\n * },\r\n * state: { count: 0 },\r\n * styles: `\r\n * button { padding: 0.5rem 1rem; }\r\n * `,\r\n * connected() {\r\n * console.log('Counter mounted');\r\n * },\r\n * render({ props, state, emit }) {\r\n * return html`\r\n * <button onclick=\"this.getRootNode().host.increment()\">\r\n * Count: ${state.count}\r\n * </button>\r\n * `;\r\n * },\r\n * });\r\n * ```\r\n */\r\nexport const component = <TProps extends Record<string, unknown>>(\r\n tagName: string,\r\n definition: ComponentDefinition<TProps>\r\n): void => {\r\n /**\r\n * Internal Web Component class created for each component definition.\r\n * @internal\r\n */\r\n class BQueryComponent extends HTMLElement {\r\n /** Internal state object for the component */\r\n private readonly state = { ...(definition.state ?? {}) };\r\n /** Typed props object populated from attributes */\r\n private props = {} as TProps;\r\n\r\n constructor() {\r\n super();\r\n this.attachShadow({ mode: 'open' });\r\n this.syncProps();\r\n }\r\n\r\n /**\r\n * Returns the list of attributes to observe for changes.\r\n */\r\n static get observedAttributes(): string[] {\r\n return Object.keys(definition.props ?? {});\r\n }\r\n\r\n /**\r\n * Called when the element is added to the DOM.\r\n */\r\n connectedCallback(): void {\r\n try {\r\n definition.beforeMount?.call(this);\r\n definition.connected?.call(this);\r\n this.render();\r\n } catch (error) {\r\n this.handleError(error as Error);\r\n }\r\n }\r\n\r\n /**\r\n * Called when the element is removed from the DOM.\r\n */\r\n disconnectedCallback(): void {\r\n try {\r\n definition.disconnected?.call(this);\r\n } catch (error) {\r\n this.handleError(error as Error);\r\n }\r\n }\r\n\r\n /**\r\n * Called when an observed attribute changes.\r\n */\r\n attributeChangedCallback(): void {\r\n try {\r\n this.syncProps();\r\n this.render(true);\r\n } catch (error) {\r\n this.handleError(error as Error);\r\n }\r\n }\r\n\r\n /**\r\n * Handles errors during component lifecycle.\r\n * @internal\r\n */\r\n private handleError(error: Error): void {\r\n if (definition.onError) {\r\n definition.onError.call(this, error);\r\n } else {\r\n console.error(`bQuery component error in <${tagName}>:`, error);\r\n }\r\n }\r\n\r\n /**\r\n * Updates a state property and triggers a re-render.\r\n *\r\n * @param key - The state property key\r\n * @param value - The new value\r\n */\r\n setState(key: string, value: unknown): void {\r\n this.state[key] = value;\r\n this.render(true);\r\n }\r\n\r\n /**\r\n * Gets a state property value.\r\n *\r\n * @param key - The state property key\r\n * @returns The current value\r\n */\r\n getState<T = unknown>(key: string): T {\r\n return this.state[key] as T;\r\n }\r\n\r\n /**\r\n * Synchronizes props from attributes.\r\n * @internal\r\n */\r\n private syncProps(): void {\r\n const props = definition.props ?? {};\r\n for (const [key, config] of Object.entries(props) as [string, PropDefinition][]) {\r\n const attrValue = this.getAttribute(key);\r\n let value: unknown;\r\n\r\n if (attrValue == null) {\r\n if (config.required && config.default === undefined) {\r\n throw new Error(`bQuery component: missing required prop \"${key}\"`);\r\n }\r\n value = config.default ?? undefined;\r\n } else {\r\n value = coercePropValue(attrValue, config);\r\n }\r\n\r\n // Validate the prop value if a validator is provided\r\n if (config.validator && value !== undefined) {\r\n const isValid = config.validator(value);\r\n if (!isValid) {\r\n throw new Error(\r\n `bQuery component: validation failed for prop \"${key}\" with value ${JSON.stringify(value)}`\r\n );\r\n }\r\n }\r\n\r\n (this.props as Record<string, unknown>)[key] = value;\r\n }\r\n }\r\n\r\n /**\r\n * Renders the component to its shadow root.\r\n * @internal\r\n */\r\n private render(triggerUpdated = false): void {\r\n try {\r\n // Check beforeUpdate hook if this is an update\r\n if (triggerUpdated && definition.beforeUpdate) {\r\n const shouldUpdate = definition.beforeUpdate.call(this, this.props);\r\n if (shouldUpdate === false) return;\r\n }\r\n\r\n /**\r\n * Emits a custom event from the component.\r\n */\r\n const emit = (event: string, detail?: unknown): void => {\r\n this.dispatchEvent(new CustomEvent(event, { detail, bubbles: true, composed: true }));\r\n };\r\n\r\n if (!this.shadowRoot) return;\r\n\r\n const markup = definition.render({\r\n props: this.props,\r\n state: this.state,\r\n emit,\r\n });\r\n\r\n const styles = definition.styles ? `<style>${definition.styles}</style>` : '';\r\n this.shadowRoot.innerHTML = `${styles}${markup}`;\r\n\r\n if (triggerUpdated) {\r\n definition.updated?.call(this);\r\n }\r\n } catch (error) {\r\n this.handleError(error as Error);\r\n }\r\n }\r\n }\r\n\r\n if (!customElements.get(tagName)) {\r\n customElements.define(tagName, BQueryComponent);\r\n }\r\n};\r\n"],"names":["coercePropValue","rawValue","config","type","parsed","normalized","callable","constructable","html","strings","values","acc","part","index","safeHtml","escapeMap","escape","value","char","component","tagName","definition","BQueryComponent","error","key","props","attrValue","triggerUpdated","emit","event","detail","markup","styles"],"mappings":"AAgHA,MAAMA,IAAkB,CAAIC,GAAkBC,MAAiC;AAC7E,QAAM,EAAE,MAAAC,MAASD;AAEjB,MAAIC,MAAS,OAAQ,QAAOF;AAE5B,MAAIE,MA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;AACd,aAAK,YAAYA,CAAc;AAAA,MACjC;AAAA,IACF;AAAA,EAAA;AAGF,EAAK,eAAe,IAAIH,CAAO,KAC7B,eAAe,OAAOA,GAASE,CAAe;AAElD;"}
|
|
1
|
+
{"version":3,"file":"component.es.mjs","sources":["../src/component/props.ts","../src/component/component.ts","../src/component/html.ts"],"sourcesContent":["/**\n * Prop coercion utilities.\n *\n * @module bquery/component\n */\n\nimport type { PropDefinition } from './types';\n\n/**\n * Coerces a string attribute value into a typed prop value.\n * Supports String, Number, Boolean, Object, Array, and custom converters.\n *\n * @internal\n * @template T - The target type\n * @param rawValue - The raw string value from the attribute\n * @param config - The prop definition with type information\n * @returns The coerced value of type T\n */\nexport const coercePropValue = <T>(rawValue: string, config: PropDefinition<T>): T => {\n const { type } = config;\n\n if (type === String) return rawValue as T;\n\n if (type === Number) {\n return Number(rawValue) as T;\n }\n\n if (type === Boolean) {\n const normalized = rawValue.trim().toLowerCase();\n if (normalized === '' || normalized === 'true' || normalized === '1') {\n return true as T;\n }\n if (normalized === 'false' || normalized === '0') {\n return false as T;\n }\n return Boolean(rawValue) as T;\n }\n\n if (type === Object || type === Array) {\n try {\n return JSON.parse(rawValue) as T;\n } catch {\n return rawValue as T;\n }\n }\n\n if (typeof type === 'function') {\n const callable = type as (value: unknown) => T;\n const constructable = type as new (value: unknown) => T;\n\n // Explicit construct mode takes precedence\n if (config.construct === true) {\n return Reflect.construct(constructable, [rawValue]) as T;\n }\n if (config.construct === false) {\n return callable(rawValue);\n }\n\n // Auto-detect: Check if type is constructable\n // A function is considered constructable if:\n // 1. It has a prototype with properties beyond just constructor, OR\n // 2. Its prototype.constructor is not itself (inherited), OR\n // 3. It's a class (toString starts with \"class\")\n const hasPrototype = type.prototype !== undefined && type.prototype !== null;\n const prototypeProps = hasPrototype ? Object.getOwnPropertyNames(type.prototype) : [];\n const hasPrototypeMethods = prototypeProps.length > 1;\n const hasInheritedConstructor = hasPrototype && type.prototype.constructor !== type;\n const isClassSyntax = /^class\\s/.test(Function.prototype.toString.call(type));\n\n const isConstructable = hasPrototypeMethods || hasInheritedConstructor || isClassSyntax;\n\n // For constructable types (e.g. Date, custom classes), prefer `new` to avoid\n // silent wrong-type returns (Date() returns string, new Date() returns Date)\n if (isConstructable) {\n try {\n return Reflect.construct(constructable, [rawValue]) as T;\n } catch {\n // Fall back to calling as function if construction fails\n return callable(rawValue);\n }\n }\n\n // For non-constructable types (arrow functions, plain functions), call directly\n // but fall back to constructor if result is undefined (common for function constructors)\n try {\n const result = callable(rawValue);\n\n // If calling without `new` returned undefined and the function has a prototype,\n // it's likely a function constructor that should be called with `new`\n if (result === undefined && hasPrototype) {\n try {\n return Reflect.construct(constructable, [rawValue]) as T;\n } catch {\n // Construction also failed, return the undefined\n return result as T;\n }\n }\n\n return result as T;\n } catch (error) {\n // Fall back to constructor if error indicates 'new' is required\n const isNewRequired =\n error instanceof TypeError &&\n /cannot be invoked without 'new'|is not a function/i.test(error.message);\n\n if (isNewRequired) {\n return Reflect.construct(constructable, [rawValue]) as T;\n }\n\n // Rethrow original error for non-constructable converters\n throw error;\n }\n }\n\n return rawValue as T;\n};\n","/**\n * Web Component factory and registry.\n *\n * @module bquery/component\n */\n\nimport { sanitizeHtml } from '../security/sanitize';\nimport { coercePropValue } from './props';\nimport type { ComponentDefinition, PropDefinition } from './types';\n\n/**\n * Creates a custom element class for a component definition.\n *\n * This is useful when you want to extend or register the class manually\n * (e.g. with different tag names in tests or custom registries).\n *\n * @template TProps - Type of the component's props\n * @param tagName - The custom element tag name (used for diagnostics)\n * @param definition - The component configuration\n */\nexport const defineComponent = <TProps extends Record<string, unknown>>(\n tagName: string,\n definition: ComponentDefinition<TProps>\n): typeof HTMLElement => {\n class BQueryComponent extends HTMLElement {\n /** Internal state object for the component */\n private readonly state = { ...(definition.state ?? {}) };\n /** Typed props object populated from attributes */\n private props = {} as TProps;\n /** Tracks missing required props for validation during connectedCallback */\n private missingRequiredProps = new Set<string>();\n /** Tracks whether the component has completed its initial mount */\n private hasMounted = false;\n\n constructor() {\n super();\n this.attachShadow({ mode: 'open' });\n this.syncProps();\n }\n\n /**\n * Returns the list of attributes to observe for changes.\n */\n static get observedAttributes(): string[] {\n return Object.keys(definition.props ?? {});\n }\n\n /**\n * Called when the element is added to the DOM.\n */\n connectedCallback(): void {\n try {\n // Defer initial render until all required props are present\n // This allows attributes to be set after element creation\n if (this.missingRequiredProps.size > 0) {\n // Component will mount once all required props are satisfied\n // via attributeChangedCallback\n return;\n }\n this.mount();\n } catch (error) {\n this.handleError(error as Error);\n }\n }\n\n /**\n * Performs the initial mount of the component.\n * Called when the element is connected and all required props are present.\n * @internal\n */\n private mount(): void {\n if (this.hasMounted) return;\n definition.beforeMount?.call(this);\n definition.connected?.call(this);\n this.render();\n this.hasMounted = true;\n }\n\n /**\n * Called when the element is removed from the DOM.\n */\n disconnectedCallback(): void {\n try {\n definition.disconnected?.call(this);\n } catch (error) {\n this.handleError(error as Error);\n }\n }\n\n /**\n * Called when an observed attribute changes.\n */\n attributeChangedCallback(\n _name: string,\n _oldValue: string | null,\n _newValue: string | null\n ): void {\n try {\n this.syncProps();\n\n if (this.hasMounted) {\n // Component already mounted - trigger update render\n this.render(true);\n } else if (this.isConnected && this.missingRequiredProps.size === 0) {\n // All required props are now satisfied and element is connected\n // Trigger the deferred initial mount\n this.mount();\n }\n } catch (error) {\n this.handleError(error as Error);\n }\n }\n\n /**\n * Handles errors during component lifecycle.\n * @internal\n */\n private handleError(error: Error): void {\n if (definition.onError) {\n definition.onError.call(this, error);\n } else {\n console.error(`bQuery component error in <${tagName}>:`, error);\n }\n }\n\n /**\n * Updates a state property and triggers a re-render.\n *\n * @param key - The state property key\n * @param value - The new value\n */\n setState(key: string, value: unknown): void {\n this.state[key] = value;\n this.render(true);\n }\n\n /**\n * Gets a state property value.\n *\n * @param key - The state property key\n * @returns The current value\n */\n getState<T = unknown>(key: string): T {\n return this.state[key] as T;\n }\n\n /**\n * Synchronizes props from attributes.\n * @internal\n */\n private syncProps(): void {\n const props = definition.props ?? {};\n for (const [key, config] of Object.entries(props) as [string, PropDefinition][]) {\n const attrValue = this.getAttribute(key);\n let value: unknown;\n\n if (attrValue == null) {\n if (config.required && config.default === undefined) {\n // Mark as missing instead of throwing - validate during connectedCallback\n this.missingRequiredProps.add(key);\n value = undefined;\n } else {\n value = config.default ?? undefined;\n }\n } else {\n // Attribute is present, remove from missing set if it was there\n if (this.missingRequiredProps.has(key)) {\n this.missingRequiredProps.delete(key);\n }\n value = coercePropValue(attrValue, config);\n }\n\n if (config.validator && value !== undefined) {\n const isValid = config.validator(value);\n if (!isValid) {\n throw new Error(\n `bQuery component: validation failed for prop \"${key}\" with value ${JSON.stringify(value)}`\n );\n }\n }\n\n (this.props as Record<string, unknown>)[key] = value;\n }\n }\n\n /**\n * Renders the component to its shadow root.\n * @internal\n */\n private render(triggerUpdated = false): void {\n try {\n if (triggerUpdated && definition.beforeUpdate) {\n const shouldUpdate = definition.beforeUpdate.call(this, this.props);\n if (shouldUpdate === false) return;\n }\n\n const emit = (event: string, detail?: unknown): void => {\n this.dispatchEvent(new CustomEvent(event, { detail, bubbles: true, composed: true }));\n };\n\n if (!this.shadowRoot) return;\n\n const markup = definition.render({\n props: this.props,\n state: this.state,\n emit,\n });\n\n const sanitizedMarkup = sanitizeHtml(markup);\n this.shadowRoot.innerHTML = sanitizedMarkup;\n\n if (definition.styles) {\n const styleElement = document.createElement('style');\n styleElement.textContent = definition.styles;\n this.shadowRoot.prepend(styleElement);\n }\n\n if (triggerUpdated) {\n definition.updated?.call(this);\n }\n } catch (error) {\n this.handleError(error as Error);\n }\n }\n }\n\n return BQueryComponent;\n};\n\n/**\n * Defines and registers a custom Web Component.\n *\n * This function creates a new custom element with the given tag name\n * and configuration. The component uses Shadow DOM for encapsulation\n * and automatically re-renders when observed attributes change.\n *\n * @template TProps - Type of the component's props\n * @param tagName - The custom element tag name (must contain a hyphen)\n * @param definition - The component configuration\n *\n * @example\n * ```ts\n * component('counter-button', {\n * props: {\n * start: { type: Number, default: 0 },\n * },\n * state: { count: 0 },\n * styles: `\n * button { padding: 0.5rem 1rem; }\n * `,\n * connected() {\n * // Use event delegation on shadow root so handler survives re-renders\n * const handleClick = (event: Event) => {\n * const target = event.target as HTMLElement | null;\n * if (target?.matches('button')) {\n * this.setState('count', (this.getState('count') as number) + 1);\n * }\n * };\n * this.shadowRoot?.addEventListener('click', handleClick);\n * // Store handler for cleanup\n * (this as any)._handleClick = handleClick;\n * },\n * disconnected() {\n * // Clean up event listener to prevent memory leaks\n * const handleClick = (this as any)._handleClick;\n * if (handleClick) {\n * this.shadowRoot?.removeEventListener('click', handleClick);\n * }\n * },\n * render({ props, state }) {\n * return html`\n * <button>\n * Count: ${state.count}\n * </button>\n * `;\n * },\n * });\n * ```\n */\nexport const component = <TProps extends Record<string, unknown>>(\n tagName: string,\n definition: ComponentDefinition<TProps>\n): void => {\n const elementClass = defineComponent(tagName, definition);\n\n if (!customElements.get(tagName)) {\n customElements.define(tagName, elementClass);\n }\n};\n","/**\n * Tagged template literal for creating HTML strings.\n *\n * This function handles interpolation of values into HTML templates,\n * converting null/undefined to empty strings.\n *\n * @param strings - Template literal string parts\n * @param values - Interpolated values\n * @returns Combined HTML string\n *\n * @example\n * ```ts\n * const name = 'World';\n * const greeting = html`<h1>Hello, ${name}!</h1>`;\n * // Result: '<h1>Hello, World!</h1>'\n * ```\n */\nexport const html = (strings: TemplateStringsArray, ...values: unknown[]): string => {\n return strings.reduce((acc, part, index) => `${acc}${part}${values[index] ?? ''}`, '');\n};\n\n/**\n * Escapes HTML entities in interpolated values for XSS prevention.\n * Use this when you need to safely embed user content in templates.\n *\n * @param strings - Template literal string parts\n * @param values - Interpolated values to escape\n * @returns Combined HTML string with escaped values\n *\n * @example\n * ```ts\n * const userInput = '<script>alert(\"xss\")</script>';\n * const safe = safeHtml`<div>${userInput}</div>`;\n * // Result: '<div><script>alert(\"xss\")</script></div>'\n * ```\n */\nexport const safeHtml = (strings: TemplateStringsArray, ...values: unknown[]): string => {\n const escapeMap: Record<string, string> = {\n '&': '&',\n '<': '<',\n '>': '>',\n '\"': '"',\n \"'\": ''',\n '`': '`',\n };\n\n const escape = (value: unknown): string => {\n const str = String(value ?? '');\n return str.replace(/[&<>\"'`]/g, (char) => escapeMap[char]);\n };\n\n return strings.reduce((acc, part, index) => `${acc}${part}${escape(values[index])}`, '');\n};\n"],"names":["coercePropValue","rawValue","config","type","normalized","callable","constructable","hasPrototype","hasPrototypeMethods","hasInheritedConstructor","isClassSyntax","result","error","defineComponent","tagName","definition","BQueryComponent","_name","_oldValue","_newValue","key","value","props","attrValue","triggerUpdated","emit","event","detail","markup","sanitizedMarkup","sanitizeHtml","styleElement","component","elementClass","html","strings","values","acc","part","index","safeHtml","escapeMap","escape","char"],"mappings":";AAkBO,MAAMA,IAAkB,CAAIC,GAAkBC,MAAiC;AACpF,QAAM,EAAE,MAAAC,MAASD;AAEjB,MAAIC,MAAS,OAAQ,QAAOF;AAE5B,MAAIE,MAAS;AACX,WAAO,OAAOF,CAAQ;AAGxB,MAAIE,MAAS,SAAS;AACpB,UAAMC,IAAaH,EAAS,KAAA,EAAO,YAAA;AACnC,WAAIG,MAAe,MAAMA,MAAe,UAAUA,MAAe,MACxD,KAELA,MAAe,WAAWA,MAAe,MACpC,KAEF,EAAQH;AAAA,EACjB;AAEA,MAAIE,MAAS,UAAUA,MAAS;AAC9B,QAAI;AACF,aAAO,KAAK,MAAMF,CAAQ;AAAA,IAC5B,QAAQ;AACN,aAAOA;AAAA,IACT;AAGF,MAAI,OAAOE,KAAS,YAAY;AAC9B,UAAME,IAAWF,GACXG,IAAgBH;AAGtB,QAAID,EAAO,cAAc;AACvB,aAAO,QAAQ,UAAUI,GAAe,CAACL,CAAQ,CAAC;AAEpD,QAAIC,EAAO,cAAc;AACvB,aAAOG,EAASJ,CAAQ;AAQ1B,UAAMM,IAAeJ,EAAK,cAAc,UAAaA,EAAK,cAAc,MAElEK,KADiBD,IAAe,OAAO,oBAAoBJ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A,EAAA;AAGF,SAAOI;AACT,GAoDagB,IAAY,CACvBlB,GACAC,MACS;AACT,QAAMkB,IAAepB,EAAgBC,GAASC,CAAU;AAExD,EAAK,eAAe,IAAID,CAAO,KAC7B,eAAe,OAAOA,GAASmB,CAAY;AAE/C,GC/QaC,IAAO,CAACC,MAAkCC,MAC9CD,EAAQ,OAAO,CAACE,GAAKC,GAAMC,MAAU,GAAGF,CAAG,GAAGC,CAAI,GAAGF,EAAOG,CAAK,KAAK,EAAE,IAAI,EAAE,GAkB1EC,IAAW,CAACL,MAAkCC,MAA8B;AACvF,QAAMK,IAAoC;AAAA,IACxC,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,EAAA,GAGDC,IAAS,CAACrB,MACF,OAAOA,KAAS,EAAE,EACnB,QAAQ,aAAa,CAACsB,MAASF,EAAUE,CAAI,CAAC;AAG3D,SAAOR,EAAQ,OAAO,CAACE,GAAKC,GAAMC,MAAU,GAAGF,CAAG,GAAGC,CAAI,GAAGI,EAAON,EAAOG,CAAK,CAAC,CAAC,IAAI,EAAE;AACzF;"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type InsertableContent } from './dom';
|
|
1
2
|
import { BQueryElement } from './element';
|
|
2
3
|
/**
|
|
3
4
|
* Wrapper for multiple DOM elements.
|
|
@@ -114,6 +115,8 @@ export declare class BQueryCollection {
|
|
|
114
115
|
* @returns The instance for method chaining
|
|
115
116
|
*/
|
|
116
117
|
removeAttr(name: string): this;
|
|
118
|
+
/** Toggle an attribute on all elements. */
|
|
119
|
+
toggleAttr(name: string, force?: boolean): this;
|
|
117
120
|
/**
|
|
118
121
|
* Sets text content on all elements or gets from first.
|
|
119
122
|
*
|
|
@@ -136,6 +139,14 @@ export declare class BQueryCollection {
|
|
|
136
139
|
* @warning Bypasses XSS protection
|
|
137
140
|
*/
|
|
138
141
|
htmlUnsafe(value: string): this;
|
|
142
|
+
/** Append content to all elements. */
|
|
143
|
+
append(content: InsertableContent): this;
|
|
144
|
+
/** Prepend content to all elements. */
|
|
145
|
+
prepend(content: InsertableContent): this;
|
|
146
|
+
/** Insert content before all elements. */
|
|
147
|
+
before(content: InsertableContent): this;
|
|
148
|
+
/** Insert content after all elements. */
|
|
149
|
+
after(content: InsertableContent): this;
|
|
139
150
|
/**
|
|
140
151
|
* Applies CSS styles to all elements.
|
|
141
152
|
*
|
|
@@ -144,6 +155,29 @@ export declare class BQueryCollection {
|
|
|
144
155
|
* @returns The instance for method chaining
|
|
145
156
|
*/
|
|
146
157
|
css(property: string | Record<string, string>, value?: string): this;
|
|
158
|
+
/** Wrap each element with a wrapper element or tag. */
|
|
159
|
+
wrap(wrapper: string | Element): this;
|
|
160
|
+
/**
|
|
161
|
+
* Remove the parent element of each element, keeping the elements in place.
|
|
162
|
+
*
|
|
163
|
+
* **Important**: This method unwraps ALL children of each parent element,
|
|
164
|
+
* not just the elements in the collection. If you call `unwrap()` on a
|
|
165
|
+
* collection containing only some children of a parent, all siblings will
|
|
166
|
+
* also be unwrapped. This behavior is consistent with jQuery's `.unwrap()`.
|
|
167
|
+
*
|
|
168
|
+
* @returns The collection for chaining
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* ```ts
|
|
172
|
+
* // HTML: <div><section><span>A</span><span>B</span></section></div>
|
|
173
|
+
* const spans = $$('span');
|
|
174
|
+
* spans.unwrap(); // Removes <section>, both spans move to <div>
|
|
175
|
+
* // Result: <div><span>A</span><span>B</span></div>
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
unwrap(): this;
|
|
179
|
+
/** Replace each element with provided content. */
|
|
180
|
+
replaceWith(content: string | Element): BQueryCollection;
|
|
147
181
|
/**
|
|
148
182
|
* Shows all elements.
|
|
149
183
|
*
|
|
@@ -240,5 +274,7 @@ export declare class BQueryCollection {
|
|
|
240
274
|
* @returns The instance for method chaining
|
|
241
275
|
*/
|
|
242
276
|
empty(): this;
|
|
277
|
+
/** @internal */
|
|
278
|
+
private insertAll;
|
|
243
279
|
}
|
|
244
280
|
//# sourceMappingURL=collection.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collection.d.ts","sourceRoot":"","sources":["../../src/core/collection.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"collection.d.ts","sourceRoot":"","sources":["../../src/core/collection.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,iBAAiB,EACvB,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAM1C;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,gBAAgB;aAgBC,QAAQ,EAAE,OAAO,EAAE;IAf/C;;;;;OAKG;IACH,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAG9B;IAEJ;;;OAGG;gBACyB,QAAQ,EAAE,OAAO,EAAE;IAE/C;;OAEG;IACH,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED;;;OAGG;IACH,OAAO,CAAC,KAAK;IAIb;;;;;OAKG;IACH,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS;IAK5C;;;;OAIG;IACH,OAAO,IAAI,aAAa,GAAG,SAAS;IAIpC;;;;OAIG;IACH,MAAM,IAAI,aAAa,GAAG,SAAS;IAInC;;;;;OAKG;IACH,IAAI,CAAC,QAAQ,EAAE,CAAC,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI;IAOrE;;;;;OAKG;IACH,GAAG,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,KAAK,CAAC,GAAG,CAAC,EAAE;IAI7D;;;;;OAKG;IACH,MAAM,CAAC,SAAS,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,GAAG,gBAAgB;IAI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I,IAAI;IAKd;;;;OAIG;IACH,KAAK,IAAI,IAAI;IAOb,gBAAgB;IAChB,OAAO,CAAC,SAAS;CAiBlB"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type InsertableContent = string | Element | Element[];
|
|
2
|
+
export declare const sanitizeContent: (html: string) => string;
|
|
3
|
+
export declare const setHtml: (element: Element, html: string) => void;
|
|
4
|
+
export declare const createElementFromHtml: (html: string) => Element;
|
|
5
|
+
export declare const insertContent: (target: Element, content: InsertableContent, position: InsertPosition) => void;
|
|
6
|
+
//# sourceMappingURL=dom.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dom.d.ts","sourceRoot":"","sources":["../../src/core/dom.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,EAAE,CAAC;AAE7D,eAAO,MAAM,eAAe,GAAI,MAAM,MAAM,KAAG,MAA4B,CAAC;AAE5E,eAAO,MAAM,OAAO,GAAI,SAAS,OAAO,EAAE,MAAM,MAAM,KAAG,IAExD,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAAI,MAAM,MAAM,KAAG,OAIpD,CAAC;AAEF,eAAO,MAAM,aAAa,GACxB,QAAQ,OAAO,EACf,SAAS,iBAAiB,EAC1B,UAAU,cAAc,KACvB,IAgBF,CAAC"}
|
package/dist/core/element.d.ts
CHANGED
|
@@ -29,6 +29,10 @@ export declare class BQueryElement {
|
|
|
29
29
|
toggleClass(className: string, force?: boolean): this;
|
|
30
30
|
/** Get or set an attribute. */
|
|
31
31
|
attr(name: string, value?: string): string | this;
|
|
32
|
+
/** Remove an attribute. */
|
|
33
|
+
removeAttr(name: string): this;
|
|
34
|
+
/** Toggle an attribute on/off. */
|
|
35
|
+
toggleAttr(name: string, force?: boolean): this;
|
|
32
36
|
/** Get or set a property. */
|
|
33
37
|
prop<T extends keyof Element>(name: T, value?: Element[T]): Element[T] | this;
|
|
34
38
|
/** Read or write data attributes in camelCase. */
|
|
@@ -121,6 +125,10 @@ export declare class BQueryElement {
|
|
|
121
125
|
* Removes the parent element, keeping this element in its place.
|
|
122
126
|
* Essentially the opposite of wrap().
|
|
123
127
|
*
|
|
128
|
+
* **Important**: This method only moves the current element out of its parent
|
|
129
|
+
* before removing the parent. Any sibling elements will be removed along with
|
|
130
|
+
* the parent. For unwrapping multiple siblings, use a collection: `$$(siblings).unwrap()`.
|
|
131
|
+
*
|
|
124
132
|
* @returns The instance for method chaining
|
|
125
133
|
*
|
|
126
134
|
* @example
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"element.d.ts","sourceRoot":"","sources":["../../src/core/element.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"element.d.ts","sourceRoot":"","sources":["../../src/core/element.ts"],"names":[],"mappings":"AA2BA,qBAAa,aAAa;IAYZ,OAAO,CAAC,QAAQ,CAAC,OAAO;IAXpC;;;;OAIG;IACH,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAA2D;IAE7F;;;OAGG;gBAC0B,OAAO,EAAE,OAAO;IAE7C;;;OAGG;IACH,IAAI,GAAG,IAAI,OAAO,CAEjB;IAED;;;OAGG;IACH,IAAI,IAAI,IAAI,OAAO,CAElB;IAED,+BAA+B;IAC/B,QAAQ,CAAC,GAAG,UAAU,EAAE,MAAM,EAAE,GAAG,IAAI;IAKvC,kCAAkC;IAClC,WAAW,CAAC,GAAG,UAAU,EAAE,MAAM,EAAE,GAAG,IAAI;IAK1C,8BAA8B;IAC9B,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,GAAG,IAAI;IAKrD,+BAA+B;IAC/B,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAQjD,2BAA2B;IAC3B,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAK9B,kCAAkC;IAClC,UAAU,C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ueryCollection } from './collection';
|
|
|
2
2
|
export { BQueryElement } from './element';
|
|
3
3
|
export { $, $$ } from './selector';
|
|
4
4
|
export { utils } from './utils';
|
|
5
|
+
export { chunk, compact, ensureArray, flatten, unique, debounce, noop, once, throttle, isEmpty, parseJson, sleep, uid, clamp, inRange, randomInt, toNumber, clone, hasOwn, isPlainObject, merge, omit, pick, capitalize, escapeRegExp, slugify, toCamelCase, toKebabCase, truncate, isArray, isBoolean, isCollection, isDate, isElement, isFunction, isNumber, isObject, isPromise, isString, } from './utils';
|
|
5
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/core/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,CAAC,EAAE,EAAE,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,CAAC,EAAE,EAAE,EAAE,MAAM,YAAY,CAAC;AAEnC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,OAAO,EACL,KAAK,EACL,OAAO,EACP,WAAW,EACX,OAAO,EACP,MAAM,EACN,QAAQ,EACR,IAAI,EACJ,IAAI,EACJ,QAAQ,EACR,OAAO,EACP,SAAS,EACT,KAAK,EACL,GAAG,EACH,KAAK,EACL,OAAO,EACP,SAAS,EACT,QAAQ,EACR,KAAK,EACL,MAAM,EACN,aAAa,EACb,KAAK,EACL,IAAI,EACJ,IAAI,EACJ,UAAU,EACV,YAAY,EACZ,OAAO,EACP,WAAW,EACX,WAAW,EACX,QAAQ,EACR,OAAO,EACP,SAAS,EACT,YAAY,EACZ,MAAM,EACN,SAAS,EACT,UAAU,EACV,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,QAAQ,GACT,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Array-focused utility helpers.
|
|
3
|
+
*
|
|
4
|
+
* @module bquery/core/utils/array
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Ensures the input is always returned as an array.
|
|
8
|
+
*
|
|
9
|
+
* @template T - The item type
|
|
10
|
+
* @param value - A single value, array, or nullish value
|
|
11
|
+
* @returns An array (empty if nullish)
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* ensureArray('a'); // ['a']
|
|
16
|
+
* ensureArray(['a', 'b']); // ['a', 'b']
|
|
17
|
+
* ensureArray(null); // []
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare function ensureArray<T>(value: T | T[] | null | undefined): T[];
|
|
21
|
+
/**
|
|
22
|
+
* Removes duplicate entries from an array.
|
|
23
|
+
*
|
|
24
|
+
* @template T - The item type
|
|
25
|
+
* @param items - The array to deduplicate
|
|
26
|
+
* @returns A new array with unique items
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* unique([1, 2, 2, 3]); // [1, 2, 3]
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare function unique<T>(items: T[]): T[];
|
|
34
|
+
/**
|
|
35
|
+
* Splits an array into chunks of a given size.
|
|
36
|
+
*
|
|
37
|
+
* @template T - The item type
|
|
38
|
+
* @param items - The array to chunk
|
|
39
|
+
* @param size - The maximum size of each chunk
|
|
40
|
+
* @returns An array of chunks
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* chunk([1, 2, 3, 4, 5], 2); // [[1,2],[3,4],[5]]
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare function chunk<T>(items: T[], size: number): T[][];
|
|
48
|
+
/**
|
|
49
|
+
* Removes falsy values from an array.
|
|
50
|
+
*
|
|
51
|
+
* @template T - The item type
|
|
52
|
+
* @param items - The array to compact
|
|
53
|
+
* @returns A new array without falsy values
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* compact([0, 1, '', 'ok', null]); // [1, 'ok']
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export declare function compact<T>(items: Array<T | null | undefined | false | 0 | ''>): T[];
|
|
61
|
+
/**
|
|
62
|
+
* Flattens a single level of nested arrays.
|
|
63
|
+
*
|
|
64
|
+
* @template T - The item type
|
|
65
|
+
* @param items - The array to flatten
|
|
66
|
+
* @returns A new flattened array
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* flatten([1, [2, 3], 4]); // [1, 2, 3, 4]
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export declare function flatten<T>(items: Array<T | T[]>): T[];
|
|
74
|
+
//# sourceMappingURL=array.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array.d.ts","sourceRoot":"","sources":["../../../src/core/utils/array.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;;;;GAaG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,EAAE,GAAG,IAAI,GAAG,SAAS,GAAG,CAAC,EAAE,CAGrE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,CAEzC;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,EAAE,EAAE,CAOxD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,GAAG,KAAK,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,CAEnF;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAUrD"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Function-focused utility helpers.
|
|
3
|
+
*
|
|
4
|
+
* @module bquery/core/utils/function
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Creates a debounced function that delays execution until after
|
|
8
|
+
* the specified delay has elapsed since the last call.
|
|
9
|
+
*
|
|
10
|
+
* @template TArgs - The argument types of the function
|
|
11
|
+
* @param fn - The function to debounce
|
|
12
|
+
* @param delayMs - Delay in milliseconds
|
|
13
|
+
* @returns A debounced version of the function
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* const search = debounce((query: string) => {
|
|
18
|
+
* console.log('Searching:', query);
|
|
19
|
+
* }, 300);
|
|
20
|
+
*
|
|
21
|
+
* search('h');
|
|
22
|
+
* search('he');
|
|
23
|
+
* search('hello'); // Only this call executes after 300ms
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare function debounce<TArgs extends unknown[]>(fn: (...args: TArgs) => void, delayMs: number): (...args: TArgs) => void;
|
|
27
|
+
/**
|
|
28
|
+
* Creates a throttled function that runs at most once per interval.
|
|
29
|
+
*
|
|
30
|
+
* @template TArgs - The argument types of the function
|
|
31
|
+
* @param fn - The function to throttle
|
|
32
|
+
* @param intervalMs - Minimum interval between calls in milliseconds
|
|
33
|
+
* @returns A throttled version of the function
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* const handleScroll = throttle(() => {
|
|
38
|
+
* console.log('Scroll position:', window.scrollY);
|
|
39
|
+
* }, 100);
|
|
40
|
+
*
|
|
41
|
+
* window.addEventListener('scroll', handleScroll);
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare function throttle<TArgs extends unknown[]>(fn: (...args: TArgs) => void, intervalMs: number): (...args: TArgs) => void;
|
|
45
|
+
/**
|
|
46
|
+
* Ensures a function only runs once. Subsequent calls return the first result.
|
|
47
|
+
*
|
|
48
|
+
* @template TArgs - The argument types of the function
|
|
49
|
+
* @template TResult - The return type of the function
|
|
50
|
+
* @param fn - The function to wrap
|
|
51
|
+
* @returns A function that only runs once
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* const init = once(() => ({ ready: true }));
|
|
56
|
+
* init();
|
|
57
|
+
* init(); // only runs once
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export declare function once<TArgs extends unknown[], TResult>(fn: (...args: TArgs) => TResult): (...args: TArgs) => TResult;
|
|
61
|
+
/**
|
|
62
|
+
* A no-operation function.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* noop();
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export declare function noop(): void;
|
|
70
|
+
//# sourceMappingURL=function.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"function.d.ts","sourceRoot":"","sources":["../../../src/core/utils/function.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,QAAQ,CAAC,KAAK,SAAS,OAAO,EAAE,EAC9C,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,IAAI,EAC5B,OAAO,EAAE,MAAM,GACd,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,IAAI,CAQ1B;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,QAAQ,CAAC,KAAK,SAAS,OAAO,EAAE,EAC9C,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,IAAI,EAC5B,UAAU,EAAE,MAAM,GACjB,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,IAAI,CAS1B;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,IAAI,CAAC,KAAK,SAAS,OAAO,EAAE,EAAE,OAAO,EACnD,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,OAAO,GAC9B,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,OAAO,CAU7B;AAED;;;;;;;GAOG;AACH,wBAAgB,IAAI,IAAI,IAAI,CAE3B"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility helpers used across the framework.
|
|
3
|
+
* These are intentionally small and framework-agnostic to keep the core tiny.
|
|
4
|
+
*
|
|
5
|
+
* @module bquery/core/utils
|
|
6
|
+
*/
|
|
7
|
+
export * from './array';
|
|
8
|
+
export * from './function';
|
|
9
|
+
export * from './misc';
|
|
10
|
+
export * from './number';
|
|
11
|
+
export * from './object';
|
|
12
|
+
export * from './string';
|
|
13
|
+
export * from './type-guards';
|
|
14
|
+
import { chunk, compact, ensureArray, flatten, unique } from './array';
|
|
15
|
+
import { debounce, noop, once, throttle } from './function';
|
|
16
|
+
import { isEmpty, parseJson, sleep, uid } from './misc';
|
|
17
|
+
import { clamp, inRange, randomInt, toNumber } from './number';
|
|
18
|
+
import { clone, hasOwn, isPlainObject, merge, omit, pick } from './object';
|
|
19
|
+
import { capitalize, escapeRegExp, slugify, toCamelCase, toKebabCase, truncate } from './string';
|
|
20
|
+
import { isArray, isBoolean, isCollection, isDate, isElement, isFunction, isNumber, isObject, isPromise, isString } from './type-guards';
|
|
21
|
+
/**
|
|
22
|
+
* Utility object containing common helper functions.
|
|
23
|
+
* All utilities are designed to be tree-shakeable and have zero dependencies.
|
|
24
|
+
*
|
|
25
|
+
* Note: `isPrototypePollutionKey` is intentionally excluded from this namespace
|
|
26
|
+
* as it is an internal security helper. It remains available as a named export
|
|
27
|
+
* for internal framework use.
|
|
28
|
+
*/
|
|
29
|
+
export declare const utils: {
|
|
30
|
+
clone: typeof clone;
|
|
31
|
+
merge: typeof merge;
|
|
32
|
+
pick: typeof pick;
|
|
33
|
+
omit: typeof omit;
|
|
34
|
+
hasOwn: typeof hasOwn;
|
|
35
|
+
debounce: typeof debounce;
|
|
36
|
+
throttle: typeof throttle;
|
|
37
|
+
once: typeof once;
|
|
38
|
+
noop: typeof noop;
|
|
39
|
+
uid: typeof uid;
|
|
40
|
+
isElement: typeof isElement;
|
|
41
|
+
isCollection: typeof isCollection;
|
|
42
|
+
isEmpty: typeof isEmpty;
|
|
43
|
+
isPlainObject: typeof isPlainObject;
|
|
44
|
+
isFunction: typeof isFunction;
|
|
45
|
+
isString: typeof isString;
|
|
46
|
+
isNumber: typeof isNumber;
|
|
47
|
+
isBoolean: typeof isBoolean;
|
|
48
|
+
isArray: typeof isArray;
|
|
49
|
+
isDate: typeof isDate;
|
|
50
|
+
isPromise: typeof isPromise;
|
|
51
|
+
isObject: typeof isObject;
|
|
52
|
+
parseJson: typeof parseJson;
|
|
53
|
+
sleep: typeof sleep;
|
|
54
|
+
randomInt: typeof randomInt;
|
|
55
|
+
clamp: typeof clamp;
|
|
56
|
+
inRange: typeof inRange;
|
|
57
|
+
toNumber: typeof toNumber;
|
|
58
|
+
capitalize: typeof capitalize;
|
|
59
|
+
toKebabCase: typeof toKebabCase;
|
|
60
|
+
toCamelCase: typeof toCamelCase;
|
|
61
|
+
truncate: typeof truncate;
|
|
62
|
+
slugify: typeof slugify;
|
|
63
|
+
escapeRegExp: typeof escapeRegExp;
|
|
64
|
+
ensureArray: typeof ensureArray;
|
|
65
|
+
unique: typeof unique;
|
|
66
|
+
chunk: typeof chunk;
|
|
67
|
+
compact: typeof compact;
|
|
68
|
+
flatten: typeof flatten;
|
|
69
|
+
};
|
|
70
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/utils/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAE9B,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACvE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC5D,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AACxD,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAC/D,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAC3E,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACjG,OAAO,EACL,OAAO,EACP,SAAS,EACT,YAAY,EACZ,MAAM,EACN,SAAS,EACT,UAAU,EACV,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,QAAQ,EACT,MAAM,eAAe,CAAC;AAEvB;;;;;;;GAOG;AACH,eAAO,MAAM,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwCjB,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Miscellaneous utility helpers.
|
|
3
|
+
*
|
|
4
|
+
* @module bquery/core/utils/misc
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Creates a stable unique ID for DOM usage.
|
|
8
|
+
*
|
|
9
|
+
* @param prefix - Optional prefix for the ID (default: 'bQuery')
|
|
10
|
+
* @returns A unique identifier string
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* const id = uid('modal'); // 'modal_x7k2m9p'
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare function uid(prefix?: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* Delays execution for a specified number of milliseconds.
|
|
20
|
+
*
|
|
21
|
+
* @param ms - Milliseconds to delay
|
|
22
|
+
* @returns A promise that resolves after the delay
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* await sleep(1000); // Wait 1 second
|
|
27
|
+
* console.log('Done!');
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare function sleep(ms: number): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Safely parses a JSON string, returning a default value on error.
|
|
33
|
+
*
|
|
34
|
+
* @template T - The expected type of the parsed value
|
|
35
|
+
* @param json - The JSON string to parse
|
|
36
|
+
* @param fallback - The default value if parsing fails
|
|
37
|
+
* @returns The parsed value or the fallback
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* parseJson('{"name":"bQuery"}', {}); // { name: 'bQuery' }
|
|
42
|
+
* parseJson('invalid', {}); // {}
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare function parseJson<T>(json: string, fallback: T): T;
|
|
46
|
+
/**
|
|
47
|
+
* Checks for emptiness across common value types.
|
|
48
|
+
*
|
|
49
|
+
* @param value - The value to check
|
|
50
|
+
* @returns True if the value is empty (null, undefined, empty string, empty array, or empty object)
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* isEmpty(''); // true
|
|
55
|
+
* isEmpty([]); // true
|
|
56
|
+
* isEmpty({}); // true
|
|
57
|
+
* isEmpty(null); // true
|
|
58
|
+
* isEmpty('hello'); // false
|
|
59
|
+
* isEmpty([1, 2]); // false
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export declare function isEmpty(value: unknown): boolean;
|
|
63
|
+
//# sourceMappingURL=misc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"misc.d.ts","sourceRoot":"","sources":["../../../src/core/utils/misc.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;GAUG;AACH,wBAAgB,GAAG,CAAC,MAAM,SAAW,GAAG,MAAM,CAE7C;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE/C;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,CAAC,CAMzD;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAM/C"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Number-focused utility helpers.
|
|
3
|
+
*
|
|
4
|
+
* @module bquery/core/utils/number
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Generates a random integer between min and max (inclusive).
|
|
8
|
+
*
|
|
9
|
+
* @param min - Minimum value
|
|
10
|
+
* @param max - Maximum value
|
|
11
|
+
* @returns A random integer in the range [min, max]
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* const roll = randomInt(1, 6); // Random dice roll
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function randomInt(min: number, max: number): number;
|
|
19
|
+
/**
|
|
20
|
+
* Clamps a number between a minimum and maximum value.
|
|
21
|
+
*
|
|
22
|
+
* @param value - The value to clamp
|
|
23
|
+
* @param min - Minimum value
|
|
24
|
+
* @param max - Maximum value
|
|
25
|
+
* @returns The clamped value
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* clamp(150, 0, 100); // 100
|
|
30
|
+
* clamp(-10, 0, 100); // 0
|
|
31
|
+
* clamp(50, 0, 100); // 50
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare function clamp(value: number, min: number, max: number): number;
|
|
35
|
+
/**
|
|
36
|
+
* Checks if a number is within a range.
|
|
37
|
+
*
|
|
38
|
+
* @param value - The value to check
|
|
39
|
+
* @param min - Minimum value
|
|
40
|
+
* @param max - Maximum value
|
|
41
|
+
* @param inclusive - Whether the range is inclusive (default: true)
|
|
42
|
+
* @returns True if the value is within the range
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* inRange(5, 1, 10); // true
|
|
47
|
+
* inRange(10, 1, 10, false); // false
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export declare function inRange(value: number, min: number, max: number, inclusive?: boolean): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Converts a value to a number with a fallback on NaN.
|
|
53
|
+
*
|
|
54
|
+
* @param value - The value to convert
|
|
55
|
+
* @param fallback - The fallback value if conversion fails (default: 0)
|
|
56
|
+
* @returns The parsed number or the fallback
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* toNumber('42'); // 42
|
|
61
|
+
* toNumber('nope', 10); // 10
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export declare function toNumber(value: unknown, fallback?: number): number;
|
|
65
|
+
//# sourceMappingURL=number.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"number.d.ts","sourceRoot":"","sources":["../../../src/core/utils/number.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;;GAWG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAE1D;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAErE;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,SAAS,UAAO,GAAG,OAAO,CAG1F;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,SAAI,GAAG,MAAM,CAG7D"}
|