@ecopages/radiant 0.1.4 → 0.1.6

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.
Files changed (62) hide show
  1. package/README.md +2 -0
  2. package/dist/context/context-provider.js +282 -3
  3. package/dist/context/context-provider.js.map +5 -3
  4. package/dist/context/create-context.js +6 -3
  5. package/dist/context/create-context.js.map +2 -2
  6. package/dist/context/decorators/consume-context.js +64 -3
  7. package/dist/context/decorators/consume-context.js.map +4 -3
  8. package/dist/context/decorators/context-selector.js +71 -3
  9. package/dist/context/decorators/context-selector.js.map +5 -4
  10. package/dist/context/decorators/provide-context.js +293 -3
  11. package/dist/context/decorators/provide-context.js.map +6 -3
  12. package/dist/context/events.js +53 -3
  13. package/dist/context/events.js.map +2 -2
  14. package/dist/context/index.js +340 -2
  15. package/dist/context/index.js.map +10 -3
  16. package/dist/context/types.js +1 -1
  17. package/dist/context/types.js.map +1 -1
  18. package/dist/core/index.js +82 -2
  19. package/dist/core/index.js.map +4 -3
  20. package/dist/core/radiant-element.d.ts +21 -1
  21. package/dist/core/radiant-element.js +82 -3
  22. package/dist/core/radiant-element.js.map +3 -3
  23. package/dist/decorators/custom-element.js +14 -3
  24. package/dist/decorators/custom-element.js.map +2 -2
  25. package/dist/decorators/debounce.d.ts +1 -0
  26. package/dist/decorators/debounce.js +21 -0
  27. package/dist/decorators/debounce.js.map +10 -0
  28. package/dist/decorators/event.js +46 -3
  29. package/dist/decorators/event.js.map +4 -3
  30. package/dist/decorators/on-event.d.ts +4 -0
  31. package/dist/decorators/on-event.js +47 -3
  32. package/dist/decorators/on-event.js.map +3 -3
  33. package/dist/decorators/on-updated.d.ts +1 -1
  34. package/dist/decorators/on-updated.js +29 -3
  35. package/dist/decorators/on-updated.js.map +3 -3
  36. package/dist/decorators/query.js +36 -3
  37. package/dist/decorators/query.js.map +3 -3
  38. package/dist/decorators/reactive-field.js +26 -3
  39. package/dist/decorators/reactive-field.js.map +2 -2
  40. package/dist/decorators/reactive-prop.d.ts +1 -1
  41. package/dist/decorators/reactive-prop.js +214 -3
  42. package/dist/decorators/reactive-prop.js.map +5 -4
  43. package/dist/decorators.js +400 -2
  44. package/dist/decorators.js.map +12 -3
  45. package/dist/index.js +719 -2
  46. package/dist/index.js.map +21 -3
  47. package/dist/mixins/index.js +23 -2
  48. package/dist/mixins/index.js.map +4 -3
  49. package/dist/mixins/with-kita.js +23 -3
  50. package/dist/mixins/with-kita.js.map +2 -2
  51. package/dist/tools/event-emitter.js +22 -3
  52. package/dist/tools/event-emitter.js.map +2 -2
  53. package/dist/tools/index.js +28 -2
  54. package/dist/tools/index.js.map +5 -3
  55. package/dist/tools/stringify-attribute.js +8 -3
  56. package/dist/tools/stringify-attribute.js.map +2 -2
  57. package/dist/utils/attribute-utils.d.ts +2 -0
  58. package/dist/utils/attribute-utils.js +137 -3
  59. package/dist/utils/attribute-utils.js.map +3 -3
  60. package/dist/utils/index.js +137 -2
  61. package/dist/utils/index.js.map +4 -3
  62. package/package.json +9 -4
package/dist/index.js.map CHANGED
@@ -1,9 +1,27 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": [],
3
+ "sources": ["../src/decorators/custom-element.ts", "../src/tools/event-emitter.ts", "../src/decorators/event.ts", "../src/decorators/on-event.ts", "../src/decorators/on-updated.ts", "../src/decorators/query.ts", "../src/utils/attribute-utils.ts", "../src/decorators/reactive-prop.ts", "../src/decorators/reactive-field.ts", "../src/core/radiant-element.ts", "../src/context/create-context.ts", "../src/context/events.ts", "../src/context/context-provider.ts", "../src/context/decorators/provide-context.ts", "../src/context/decorators/consume-context.ts", "../src/context/decorators/context-selector.ts", "../src/mixins/with-kita.ts", "../src/tools/stringify-attribute.ts"],
4
4
  "sourcesContent": [
5
+ "/**\n * Registers a web component with the given name on the global `window.customElements` registry.\n * @param name selector name.\n */\nexport function customElement(name: string) {\n return (target: CustomElementConstructor) => {\n if (!globalThis.window) return;\n if (!window.customElements.get(name)) {\n window.customElements.define(name, target);\n }\n };\n}\n",
6
+ "import type { RadiantElement } from '..';\n\nexport interface EventEmitterConfig {\n name: string;\n bubbles?: boolean;\n cancelable?: boolean;\n composed?: boolean;\n}\n\n/**\n * A generic event emitter class that allows emitting custom events.\n *\n * @template T - The type of the event detail.\n */\nexport class EventEmitter<T = unknown> {\n private host: RadiantElement;\n private eventConfig: EventEmitterConfig;\n\n /**\n * Constructs a new instance of the EventEmitter class.\n *\n * @param host - The host element on which the events will be dispatched.\n * @param eventConfig - The configuration for the event.\n */\n constructor(host: RadiantElement, eventConfig: EventEmitterConfig) {\n this.host = host;\n this.eventConfig = eventConfig;\n }\n\n /**\n * Emits a custom event with the specified detail.\n *\n * @param detail - The detail object to be passed along with the event.\n */\n emit(detail?: T) {\n const event = new CustomEvent(this.eventConfig.name, {\n detail: detail,\n bubbles: this.eventConfig.bubbles,\n cancelable: this.eventConfig.cancelable,\n composed: this.eventConfig.composed,\n });\n this.host.dispatchEvent(event);\n }\n}\n",
7
+ "import { EventEmitter, type EventEmitterConfig } from '@/tools/event-emitter';\n\nconst eventEmitters = new WeakMap();\n\n/**\n * Decorator that attaches an EventEmitter to the class field property.\n * The EventEmitter can be used to dispatch custom events from the target element.\n * @param eventConfig Configuration for the event emitter.\n * @see {@link EventEmitter} for more details about how the EventEmitter works.\n */\nexport function event(eventConfig: EventEmitterConfig) {\n return (target: any, propertyKey: string) => {\n if (!propertyKey) {\n throw new Error('The propertyKey is missing for the event decorator.');\n }\n\n if (!eventConfig || !eventConfig.name) {\n throw new Error('Invalid eventConfig provided.');\n }\n\n const uniqueKey = Symbol(eventConfig.name);\n\n Object.defineProperty(target, propertyKey, {\n get() {\n const emittersMap: Map<symbol, EventEmitter> = eventEmitters.get(this) || new Map();\n if (!emittersMap.has(uniqueKey)) {\n emittersMap.set(uniqueKey, new EventEmitter(this, eventConfig));\n eventEmitters.set(this, emittersMap);\n }\n\n return emittersMap.get(uniqueKey);\n },\n });\n };\n}\n",
8
+ "import type { RadiantElement, RadiantElementEventListener } from '@/core/radiant-element';\n\ntype OnEventConfig = Pick<RadiantElementEventListener, 'type' | 'options'> &\n (\n | {\n selector: string;\n }\n | {\n ref: string;\n }\n | {\n window: boolean;\n }\n | {\n document: boolean;\n }\n );\n\n/**\n * A decorator to subscribe to an event on the target element.\n * The event listener will be automatically unsubscribed when the element is disconnected.\n *\n * Note: This decorator uses event delegation, which means it relies on event bubbling.\n * Therefore, it will not work with events that do not bubble, such as `focus`, `blur`, `load`, `unload`, `scroll`, etc.\n * For focus and blur events, consider using `focusin` and `focusout` which are similar but do bubble.\n *\n * @param eventConfig The event configuration.\n * @param eventConfig.selectors The CSS selector(s) of the target element(s).\n * @param eventConfig.ref The data-ref attribute of the target element.\n * @param eventConfig.type The type of the event to listen for.\n * @param eventConfig.options Optional. An options object that specifies characteristics about the event listener.\n */\nexport function onEvent(eventConfig: OnEventConfig) {\n return (proto: RadiantElement, _: string, descriptor: PropertyDescriptor) => {\n const originalConnectedCallback = proto.connectedCallback;\n const originalDisconnectedCallback = proto.disconnectedCallback;\n\n if ('window' in eventConfig) {\n proto.connectedCallback = function (this: RadiantElement) {\n window.addEventListener(eventConfig.type, descriptor.value.bind(this), eventConfig.options);\n originalConnectedCallback.call(this);\n };\n\n proto.disconnectedCallback = function (this: RadiantElement) {\n window.removeEventListener(eventConfig.type, descriptor.value.bind(this), eventConfig.options);\n originalDisconnectedCallback.call(this);\n };\n\n return descriptor;\n }\n\n if ('document' in eventConfig) {\n proto.connectedCallback = function (this: RadiantElement) {\n document.addEventListener(eventConfig.type, descriptor.value.bind(this), eventConfig.options);\n originalConnectedCallback.call(this);\n };\n\n proto.disconnectedCallback = function (this: RadiantElement) {\n document.removeEventListener(eventConfig.type, descriptor.value.bind(this), eventConfig.options);\n originalDisconnectedCallback.call(this);\n };\n\n return descriptor;\n }\n\n const selector = 'selector' in eventConfig ? eventConfig.selector : `[data-ref=\"${eventConfig.ref}\"]`;\n\n const originalMethod = descriptor.value;\n const subscriptionId = `${eventConfig.type}-${selector}`;\n\n proto.connectedCallback = function (this: RadiantElement) {\n this.subscribeEvent({\n id: subscriptionId,\n selector: selector,\n type: eventConfig.type,\n listener: originalMethod.bind(this),\n options: eventConfig?.options ?? undefined,\n });\n\n originalConnectedCallback.call(this);\n };\n\n return descriptor;\n };\n}\n",
9
+ "import type { RadiantElement } from '@/core/radiant-element';\n\n/**\n * A decorator to subscribe to an updated callback when a reactive field or property changes.\n * @param eventConfig The event configuration.\n */\nexport function onUpdated(keyOrKeys: string | string[]) {\n return (proto: RadiantElement, methodName: string) => {\n if (!('updatesRegistry' in proto)) {\n Object.defineProperty(proto, 'updatesRegistry', {\n value: new Map<string, Set<string>>(),\n configurable: true,\n });\n }\n\n const updatesRegistry = proto.updatesRegistry;\n\n if (Array.isArray(keyOrKeys)) {\n for (const key of keyOrKeys) {\n if (!updatesRegistry.has(key)) {\n updatesRegistry.set(key, new Set());\n }\n updatesRegistry.get(key)?.add(methodName);\n }\n } else if (typeof keyOrKeys === 'string') {\n if (!updatesRegistry.has(keyOrKeys)) {\n updatesRegistry.set(keyOrKeys, new Set());\n }\n updatesRegistry.get(keyOrKeys)?.add(methodName);\n }\n };\n}\n",
10
+ "import type { RadiantElement } from '@/core';\n\n/**\n * The base configuration object for the query.\n */\ntype BaseQueryConfig = {\n all?: boolean;\n cache?: boolean;\n};\n\n/**\n * The configuration object for the query.\n * It can be configured to query by CSS selector or data-ref attribute.\n */\nexport type QueryConfig = BaseQueryConfig &\n (\n | {\n selector: string;\n }\n | {\n ref: string;\n }\n );\n\n/**\n * A decorator to query by CSS selector or data-ref attribute.\n * By default it queries for the first element that matches the selector, but it can be configured to query for all elements.\n *\n * @param {QueryConfig} options - The configuration object for the query.\n * @param {boolean} [options.all] - A flag to query for all elements that match the selector. Defaults to `false`.\n * @param {boolean} [options.cache] - A flag to cache the query result. Defaults to `true`.\n * @param {string} [options.selector] - A CSS selector to match elements against. This property is mutually exclusive with `options.ref`.\n * @param {string} [options.ref] - A reference to an element. This property is mutually exclusive with `options.selector`.\n *\n * @returns {Function} A decorator function that, when applied to a class property, will replace it with a getter. The getter will return the result of the query when accessed.\n *\n * @example\n * class MyElement extends HTMLElement {\n * @query({ selector: '.my-class' })\n * myElement;\n * }\n *\n * // Now, `myElement` will return the first element in the light DOM of `MyElement` that matches the selector '.my-class'.\n */\nexport function query({\n cache: shouldBeCached = true,\n ...options\n}: QueryConfig): (proto: RadiantElement, propertyKey: string | symbol) => void {\n const cache = new WeakMap<Element, Element | NodeList | null>();\n\n return (proto: RadiantElement, propertyKey: string | symbol) => {\n const doQuery = function (this: Element) {\n if (shouldBeCached) {\n const cachedResult = cache.get(this);\n if (cachedResult !== undefined) {\n return cachedResult;\n }\n }\n\n const selector = 'selector' in options ? options.selector : `[data-ref=\"${options.ref}\"]`;\n const queryResult = options.all ? this.querySelectorAll(selector) : this.querySelector(selector);\n\n if (shouldBeCached) {\n cache.set(this, queryResult);\n }\n\n return queryResult;\n };\n\n const originalConnectedCallback = proto.connectedCallback;\n\n proto.connectedCallback = function (this: RadiantElement) {\n Object.defineProperty(this, propertyKey, {\n get: doQuery,\n enumerable: true,\n configurable: true,\n });\n\n originalConnectedCallback.call(this);\n };\n };\n}\n",
11
+ "export type AttributeTypeConstant = typeof Array | typeof Boolean | typeof Number | typeof Object | typeof String;\n\nexport type AttributeTypeDefault = Array<unknown> | boolean | number | Record<string, unknown> | string;\n\n/**\n * Parses the given attribute type constant and returns its corresponding string representation.\n *\n * @param constant - The attribute type constant to parse.\n * @returns The string representation of the attribute type constant.\n */\nexport function parseAttributeTypeConstant(constant?: AttributeTypeConstant) {\n switch (constant) {\n case Array:\n return 'array';\n case Boolean:\n return 'boolean';\n case Number:\n return 'number';\n case Object:\n return 'object';\n case String:\n return 'string';\n }\n}\n\n/**\n * Parses the attribute type default value and returns its type as a string.\n *\n * @param defaultValue - The default value of the attribute type.\n * @returns The type of the default value as a string.\n */\nexport function parseAttributeTypeDefault(defaultValue?: AttributeTypeDefault) {\n switch (typeof defaultValue) {\n case 'boolean':\n return 'boolean';\n case 'number':\n return 'number';\n case 'string':\n return 'string';\n }\n\n if (Array.isArray(defaultValue)) return 'array';\n if (Object.prototype.toString.call(defaultValue) === '[object Object]') return 'object';\n}\n\n/**\n * Returns the default value for a given attribute type.\n *\n * @param type - The attribute type constant.\n * @returns The default value for the specified attribute type.\n */\nexport function defaultValueForType(type: AttributeTypeConstant): unknown {\n switch (type) {\n case Number:\n return 0;\n case String:\n return '';\n case Boolean:\n return false;\n default:\n return null;\n }\n}\n\ntype Reader = (value: string) => number | string | boolean | object | unknown[];\n\n/**\n * Utility function to parse a JSON string safely\n */\nfunction parseJSON<T>(value: string): T {\n try {\n return JSON.parse(value);\n } catch (error) {\n throw new TypeError('Invalid JSON string');\n }\n}\n\n/**\n * Object that maps attribute types to reader functions.\n * @type {Object.<string, Reader>}\n */\nconst readers: { [type: string]: Reader } = {\n array(value: string): unknown[] {\n const array = parseJSON<unknown[]>(value);\n if (!Array.isArray(array)) {\n throw new TypeError(`Expected an array but got a value of type \"${typeof array}\"`);\n }\n return array;\n },\n\n boolean(value: string): boolean {\n return !(value === '0' || String(value).toLowerCase() === 'false');\n },\n\n number(value: string): number {\n const number = Number(value.replace(/_/g, ''));\n return number;\n },\n\n object(value: string): object {\n const object = JSON.parse(value);\n if (object === null || typeof object !== 'object' || Array.isArray(object)) {\n throw new TypeError(\n `expected value of type \"object\" but instead got value \"${value}\" of type \"${parseAttributeTypeDefault(\n object,\n )}\"`,\n );\n }\n return object;\n },\n\n string(value: string): string {\n return value;\n },\n};\n\ntype Writer = (value: unknown) => string;\n\n/**\n * Object that maps attribute types to writer functions.\n * @type {Object.<string, Writer>}\n */\nconst writers: { [type: string]: Writer } = {\n default: writeString,\n array: writeJSON,\n object: writeJSON,\n};\n\nfunction writeJSON(value: unknown) {\n return JSON.stringify(value);\n}\n\nfunction writeString(value: unknown) {\n return `${value}`;\n}\n\n/**\n * Reads the attribute value based on the provided type.\n * @param value - The attribute value to be read.\n * @param type - The type of the attribute.\n * @returns The parsed attribute value.\n * @throws {TypeError} If the provided type is unknown.\n */\nexport function readAttributeValue(value: string, type: AttributeTypeConstant) {\n const readerType = parseAttributeTypeConstant(type);\n if (!readerType) throw new TypeError(`[radiant-element] Unknown type \"${type}\"`);\n return readers[readerType](value);\n}\n\nexport type ReadAttributeValueReturnType = ReturnType<typeof readAttributeValue>;\n\n/**\n * Writes the attribute value based on the provided type.\n *\n * @param value - The value to be written.\n * @param type - The type of the attribute.\n * @returns The written attribute value.\n * @throws {TypeError} If the provided type is unknown.\n */\nexport function writeAttributeValue(value: unknown, type: AttributeTypeConstant) {\n const writerType = parseAttributeTypeConstant(type);\n if (!writerType) throw new TypeError(`[radiant-element] Unknown type \"${type}\"`);\n return (writers[writerType] || writers.default)(value);\n}\n\nexport type WriteAttributeValueReturnType = ReturnType<typeof writeAttributeValue>;\n\n/*\n * Type guard functions for each type in AttributeTypeConstant\n */\nfunction isBoolean(value: unknown): value is boolean {\n return typeof value === 'boolean';\n}\n\nfunction isNumber(value: unknown): value is number {\n return typeof value === 'number';\n}\n\nfunction isString(value: unknown): value is string {\n return typeof value === 'string';\n}\n\nfunction isArray(value: unknown): value is Array<unknown> {\n return Array.isArray(value);\n}\n\nfunction isObject(value: unknown): value is object {\n return typeof value === 'object' && !Array.isArray(value) && value !== null;\n}\n\n/*\n * Check function to ensure defaultValue matches the type\n */\nexport function isValueOfType(type: AttributeTypeConstant, defaultValue: unknown): boolean {\n switch (type) {\n case Boolean:\n return isBoolean(defaultValue);\n case Number:\n return isNumber(defaultValue);\n case String:\n return isString(defaultValue);\n case Array:\n return isArray(defaultValue);\n case Object:\n return isObject(defaultValue);\n default:\n return false;\n }\n}\n",
12
+ "import type { PropertyConfig, RadiantElement } from '@/core/radiant-element';\nimport {\n type AttributeTypeConstant,\n defaultValueForType,\n isValueOfType,\n readAttributeValue,\n writeAttributeValue,\n} from '@/utils/attribute-utils';\n\ntype ReactivePropertyOptions<T> = {\n type: AttributeTypeConstant;\n reflect?: boolean;\n attribute?: string;\n defaultValue?: T;\n};\n\n/**\n * A decorator to define a reactive property.\n * Every time the property changes, the `updated` method will be called.\n * @param options The options for the reactive property.\n * @param options.type The type of the property value.\n * @param options.reflect Whether to reflect the property to the attribute.\n * @param options.attribute The name of the attribute.\n * @param options.defaultValue The default value of the property.\n */\nexport function reactiveProp<T = unknown>({ type, attribute, reflect, defaultValue }: ReactivePropertyOptions<T>) {\n if (defaultValue !== undefined && !isValueOfType(type, defaultValue)) {\n throw new Error(`defaultValue does not match the expected type for ${type.name}`);\n }\n\n return (target: RadiantElement, propertyName: string) => {\n const originalValues = new WeakMap<WeakKey, unknown>();\n const attributeKey = attribute ?? propertyName;\n\n if (propertyName in target) {\n throw new Error(`Property \"${propertyName}\" already exists on ${target.constructor.name}`);\n }\n\n const propertyMapping: PropertyConfig = {\n type,\n propertyName,\n attributeKey,\n converter: {\n fromAttribute: (value) => readAttributeValue(value, type),\n toAttribute: (value) => writeAttributeValue(value, type),\n },\n };\n\n addPropertyToMappings(target, propertyMapping);\n\n Object.defineProperty(target, propertyName, {\n get: function () {\n if (!originalValues.has(this)) {\n const initialValue = getInitialValue(this, type, attributeKey, defaultValue as T);\n originalValues.set(this, initialValue);\n }\n return originalValues.get(this);\n },\n set: function (newValue: T) {\n const oldValue = originalValues.get(this);\n if (oldValue === newValue) return;\n originalValues.set(this, newValue);\n if (reflect) {\n const attributeValue = propertyMapping.converter.toAttribute(newValue);\n this.setAttribute(attributeKey, attributeValue);\n }\n this.updated(propertyName, oldValue, newValue);\n },\n enumerable: true,\n configurable: true,\n });\n\n const originalConnectedCallback = target.connectedCallback;\n\n target.connectedCallback = function (this: RadiantElement) {\n originalConnectedCallback.call(this);\n this.updated(propertyName, null, defaultValue);\n };\n\n addObservedAttribute(target, attributeKey);\n };\n}\n\nconst getInitialValue = (\n target: RadiantElement,\n type: AttributeTypeConstant,\n attributeKey: string,\n defaultValue: unknown,\n) => {\n if (type === Boolean) {\n const hasAttribute = target.hasAttribute(attributeKey);\n return hasAttribute || defaultValue;\n }\n\n const attributeValue = target.getAttribute(attributeKey);\n return attributeValue !== null\n ? readAttributeValue(attributeValue, type)\n : defaultValue || (defaultValueForType(type) as typeof defaultValue);\n};\n\nconst addPropertyToMappings = (target: RadiantElement, propertyMapping: PropertyConfig) => {\n if (!('propertyConfigMap' in target)) {\n Object.defineProperty(target, 'propertyConfigMap', {\n value: new Map<string, PropertyConfig>(),\n configurable: true,\n });\n }\n\n target.propertyConfigMap.set(propertyMapping.propertyName, propertyMapping);\n};\n\nfunction addObservedAttribute(target: RadiantElement, attribute: string) {\n const ctor = target.constructor as typeof RadiantElement;\n const existingObservedAttributes = (ctor as any).observedAttributes || [];\n if (!existingObservedAttributes.includes(attribute)) {\n const newObservedAttributes = [...existingObservedAttributes, attribute];\n Object.defineProperty(ctor, 'observedAttributes', {\n get() {\n return newObservedAttributes;\n },\n configurable: true,\n });\n }\n}\n",
13
+ "import type { RadiantElement } from '@/core/radiant-element';\n\n/**\n * A decorator to define a reactive field.\n * Every time the property changes, the `updated` method will be called.\n * Due the fact the value is always undefined before the first update,\n * we are adding a `isDefined` WeakSet to track if the property has been defined.\n * @param target The target element.\n * @param propertyKey The property key.\n */\nexport function reactiveField(proto: RadiantElement, propertyKey: string) {\n const originalValues = new WeakMap<WeakKey, unknown>();\n const isDefined = new WeakSet<WeakKey>();\n\n Object.defineProperty(proto, propertyKey, {\n get: function () {\n return originalValues.get(this);\n },\n set: function (newValue: unknown) {\n if (isDefined.has(this)) {\n const oldValue = originalValues.get(this);\n if (oldValue !== newValue) {\n originalValues.set(this, newValue);\n this.updated(propertyKey, oldValue, newValue);\n }\n } else {\n originalValues.set(this, newValue);\n isDefined.add(this);\n }\n },\n });\n}\n",
14
+ "import type { UnknownContext } from '@/context/types';\nimport type { AttributeTypeConstant, ReadAttributeValueReturnType, WriteAttributeValueReturnType } from '@/utils';\n\n/**\n * Possible positions to insert a rendered template.\n */\nexport type RenderInsertPosition = 'replace' | 'beforebegin' | 'afterbegin' | 'beforeend' | 'afterend';\n\n/**\n * Represents a Radiant element event listener.\n */\nexport type RadiantElementEventListener = {\n selector: string;\n type: string;\n listener: EventListener;\n id: string;\n options?: AddEventListenerOptions;\n};\n\n/**\n * Represents a property metadata object.\n */\nexport interface PropertyConfig {\n type: AttributeTypeConstant;\n propertyName: string;\n attributeKey: string;\n converter: {\n fromAttribute: (value: string) => ReadAttributeValueReturnType;\n toAttribute: (value: any) => WriteAttributeValueReturnType;\n };\n}\n\n/**\n * Represents an interface for a Radiant element.\n */\nexport interface IRadiantElement {\n /**\n * Called when a property of the element is updated.\n * @param changedProperty - The name of the changed property.\n * @param oldValue - The old value of the property.\n * @param newValue - The new value of the property.\n */\n updated(changedProperty: string, oldValue: unknown, newValue: unknown): void;\n\n /**\n * Subscribes to a Radiant element event.\n * @param event - The event listener to subscribe to.\n */\n subscribeEvent(event: RadiantElementEventListener): void;\n\n /**\n * Subscribes to multiple Radiant element events.\n * @param events - The array of event listeners to subscribe to.\n */\n subscribeEvents(events: RadiantElementEventListener[]): void;\n\n /**\n * Unsubscribes from a Radiant element event.\n * @param id - The ID of the event listener to unsubscribe from.\n */\n unsubscribeEvent(id: string): void;\n\n /**\n * Removes all subscribed events from the Radiant element.\n */\n removeAllSubscribedEvents(): void;\n\n /**\n * Renders a template into the specified target element.\n * @param options - The rendering options.\n * @param options.target - The target element to render the template into.\n * @param options.template - The template string to render.\n * @param options.insert - The position to insert the rendered template. (optional)\n */\n renderTemplate(options: {\n target: HTMLElement;\n template: string;\n insert?: RenderInsertPosition;\n }): void;\n\n /**\n * Called when the Radiant element is connected to a context.\n * @param context - The connected context.\n */\n connectedContextCallback(context: UnknownContext): void;\n}\n\n/**\n * A base class for creating custom elements with reactive properties and event subscriptions.\n * @extends HTMLElement\n * @implements IRadiantElement\n */\nexport class RadiantElement extends HTMLElement implements IRadiantElement {\n declare propertyConfigMap: Map<string, PropertyConfig>;\n declare updatesRegistry: Map<string, Set<string>>;\n private eventSubscriptions = new Map<string, RadiantElementEventListener>();\n private elementReady = false;\n\n connectedCallback() {\n this.elementReady = true;\n }\n\n connectedContextCallback(_contextName: UnknownContext): void {}\n\n disconnectedCallback() {\n this.removeAllSubscribedEvents();\n }\n\n updated(changedProperty: string, oldValue: unknown, value: unknown) {\n if (!this.elementReady || !this.updatesRegistry || oldValue === value) return;\n const updates = this.updatesRegistry.get(changedProperty);\n if (updates) {\n for (const update of updates) {\n (this as any)[update]();\n }\n }\n }\n\n attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null) {\n if (oldValue === newValue || !this.elementReady) return;\n\n if (name in this) {\n const config = this.propertyConfigMap.get(name);\n const transformedValue = newValue ? config?.converter.fromAttribute(newValue) : newValue;\n const transformedOldValue = oldValue ? config?.converter.fromAttribute(oldValue) : oldValue;\n (this as RadiantElement & { [key: string]: any })[name] = transformedValue;\n this.updated(name, transformedOldValue, transformedValue);\n }\n }\n\n renderTemplate({\n target = this,\n template,\n insert = 'replace',\n }: {\n target: HTMLElement;\n template: string;\n insert?: RenderInsertPosition;\n }) {\n switch (insert) {\n case 'replace':\n target.innerHTML = template;\n break;\n case 'beforeend':\n target.insertAdjacentHTML('beforeend', template);\n break;\n case 'afterbegin':\n target.insertAdjacentHTML('afterbegin', template);\n break;\n }\n }\n\n public subscribeEvents(events: RadiantElementEventListener[]): void {\n for (const event of events) {\n this.subscribeEvent(event);\n }\n }\n\n public subscribeEvent(eventConfig: RadiantElementEventListener): void {\n const delegatedListener = (delegatedEvent: Event) => {\n if (delegatedEvent.target && (delegatedEvent.target as Element).matches(eventConfig.selector)) {\n eventConfig.listener.call(this, delegatedEvent);\n }\n };\n\n this.addEventListener(eventConfig.type, delegatedListener, eventConfig.options);\n this.eventSubscriptions.set(eventConfig.id, { ...eventConfig, listener: delegatedListener });\n }\n\n public unsubscribeEvent(id: string): void {\n const eventSubscription = this.eventSubscriptions.get(id);\n if (eventSubscription) {\n this.removeEventListener(eventSubscription.type, eventSubscription.listener, eventSubscription.options);\n this.eventSubscriptions.delete(id);\n }\n }\n\n public removeAllSubscribedEvents(): void {\n for (const eventSubscription of this.eventSubscriptions.values()) {\n this.removeEventListener(eventSubscription.type, eventSubscription.listener, eventSubscription.options);\n }\n this.eventSubscriptions.clear();\n }\n}\n",
15
+ "import type { Context } from './types';\n\n/**\n * A function which creates a Context value object\n */\nexport const createContext = <ValueType>(key: unknown) => key as Context<typeof key, ValueType>;\n",
16
+ "import type { Context, ContextCallback, ContextType, UnknownContext } from './types';\n\n/**\n * List of events which can be emitted by a context provider or requester.\n */\nexport enum ContextEventsTypes {\n SUBSCRIPTION_REQUEST = 'context--subscription-request',\n CONTEXT_REQUEST = 'context-request',\n ON_MOUNT = 'context--on-mount',\n}\n\n/**\n * An event fired by a context requester to signal it desires a named context.\n *\n * A provider should inspect the `context` property of the event to determine if it has a value that can\n * satisfy the request, calling the `callback` with the requested value if so.\n *\n * If the requested context event contains a truthy `subscribe` value, then a provider can call the callback\n * multiple times if the value is changed, if this is the case the provider should pass an `unsubscribe`\n * function to the callback which requesters can invoke to indicate they no longer wish to receive these updates.\n */\nexport class ContextRequestEvent<T extends UnknownContext> extends Event {\n public constructor(\n public readonly context: T,\n public readonly callback: ContextCallback<ContextType<T>>,\n public readonly subscribe?: boolean,\n ) {\n super(ContextEventsTypes.CONTEXT_REQUEST, { bubbles: true, composed: true });\n }\n}\n\n/**\n * A type which represents a subscription to a context value.\n */\nexport type ContextSubscription<T extends UnknownContext> = {\n select?: (context: ContextType<T>) => unknown;\n callback: (value: unknown) => void;\n};\n\n/**\n * An event fired by a context provider to signal that a context value has been mounted and is available for consumption.\n */\nexport class ContextOnMountEvent extends CustomEvent<{ context: UnknownContext }> {\n public constructor(context: UnknownContext) {\n super(ContextEventsTypes.ON_MOUNT, {\n detail: { context },\n bubbles: true,\n composed: true,\n });\n }\n}\n\n/**\n * An event fired by a context requester to signal it desires a named context.\n *\n * A provider should inspect the `context` property of the event to determine if it has a value that can\n * satisfy the request, calling the `callback` with the requested value if so.\n *\n * If the requested context event contains a truthy `subscribe` value, then a provider can call the callback\n * multiple times if the value is changed, if this is the case the provider should pass an `unsubscribe`\n * function to the callback which requesters can invoke to indicate they no longer wish to receive these updates.\n *\n * It accepts a `selector` property which can be used to request a specific property of the context value.\n */\nexport class ContextSubscriptionRequestEvent<T extends UnknownContext> extends Event {\n public constructor(\n public readonly context: T,\n public readonly callback: (value: ContextType<T> | { [K in keyof ContextType<T>]: ContextType<T>[K] }) => void,\n public readonly select?: (context: ContextType<T>) => unknown,\n public readonly subscribe?: boolean,\n ) {\n super(ContextEventsTypes.SUBSCRIPTION_REQUEST, {\n bubbles: true,\n composed: true,\n });\n }\n}\n\ndeclare global {\n interface HTMLElementEventMap {\n /**\n * A 'context-request-subscription' event can be emitted by any element which desires\n * a context value to be injected by an external provider.\n */\n [ContextEventsTypes.SUBSCRIPTION_REQUEST]: ContextSubscriptionRequestEvent<UnknownContext>;\n /**\n * A context-request-provider event can be emitted by a context requester to signal\n * that it desires a context value to be provided by a context provider.\n */\n [ContextEventsTypes.CONTEXT_REQUEST]: ContextRequestEvent<Context<unknown, unknown>>;\n /**\n * A 'context-mount' event can be emitted by a context provider to signal\n * that a context value has been mounted and is available for consumption.\n */\n [ContextEventsTypes.ON_MOUNT]: ContextOnMountEvent;\n }\n}\n",
17
+ "import type { RadiantElement } from '@/core/radiant-element';\nimport { type AttributeTypeConstant, readAttributeValue } from '@/utils/attribute-utils';\nimport {\n ContextEventsTypes,\n ContextOnMountEvent,\n type ContextRequestEvent,\n type ContextSubscription,\n type ContextSubscriptionRequestEvent,\n} from './events';\nimport type { Context, ContextType, UnknownContext } from './types';\n\ntype ContextProviderOptions<T extends UnknownContext> = {\n context: UnknownContext;\n initialValue?: T['__context__'];\n hydrate?: AttributeTypeConstant;\n};\n\nexport const HYDRATE_ATTRIBUTE = 'hydrate-context';\n\n/**\n * Represents a context provider that allows setting and getting the context,\n * as well as subscribing to context updates.\n *\n * @template T - The type of the context.\n */\nexport interface IContextProvider<T extends Context<unknown, unknown>> {\n /**\n * Sets the context with the provided update and invokes the optional callback function.\n *\n * @param update - The partial update to be applied to the context.\n * @param callback - An optional callback function that receives the updated context.\n */\n setContext: (update: Partial<ContextType<T>>, callback?: (context: ContextType<T>) => void) => void;\n\n /**\n * Gets the current context.\n *\n * @returns The current context.\n */\n getContext: () => ContextType<T>;\n\n /**\n * Subscribes to context updates.\n *\n * @param subscription - The subscription object that defines the callback function to be invoked on context updates.\n */\n subscribe: (subscription: ContextSubscription<T>) => void;\n}\n\n/**\n * It creates a context provider that allows setting and getting the context,\n * It will also be in charge of notifying the subscribers when the context changes.\n *\n * @template T - The type of the context.\n * @implements IContextProvider\n *\n * @example\n * ```ts\n * export class MyElement extends RadiantElement {\n * provider = new ContextProvider<typeof myContext>(this, {\n * context: myContext,\n * initialValue: {\n * value: 'Hello World',\n * },\n * });\n * ```\n */\nexport class ContextProvider<T extends Context<unknown, unknown>> implements IContextProvider<T> {\n private host: RadiantElement;\n private context: UnknownContext;\n private value: ContextType<T> | undefined;\n subscriptions: ContextSubscription<T>[] = [];\n\n /**\n * Creates a new instance of the ContextProvider.\n *\n * @param host - The host element that will contain the context provider.\n * @param options - The options to configure the context provider.\n */\n constructor(host: RadiantElement, options: ContextProviderOptions<T>) {\n this.host = host;\n this.context = options.context;\n let contextValue: T['__context__'] | undefined = options.initialValue;\n\n if (options.hydrate) {\n const hydrationValue = this.host.getAttribute(HYDRATE_ATTRIBUTE);\n\n if (hydrationValue) {\n const parsedHydrationValue = readAttributeValue(hydrationValue, options.hydrate) as ContextType<T>;\n this.host.removeAttribute(HYDRATE_ATTRIBUTE);\n\n if (\n options.hydrate === Object &&\n this.isObject(parsedHydrationValue) &&\n (this.isObject(contextValue) || typeof contextValue === 'undefined')\n ) {\n contextValue = {\n ...(contextValue ?? {}),\n ...parsedHydrationValue,\n };\n } else {\n contextValue = parsedHydrationValue;\n }\n }\n }\n\n this.value = contextValue as ContextType<T>;\n\n this.registerEvents();\n this.host.dispatchEvent(new ContextOnMountEvent(this.context));\n }\n\n setContext = (update: Partial<ContextType<T>>, callback?: (context: ContextType<T>) => void) => {\n if (typeof this.value === 'object') {\n const oldContext = { ...this.value };\n this.value = { ...this.value, ...update };\n if (callback) callback(this.value);\n this.notifySubscribers(this.value, oldContext);\n }\n };\n\n getContext = () => {\n return this.value as ContextType<T>;\n };\n\n subscribe = ({ select, callback }: ContextSubscription<T>) => {\n this.subscriptions.push({ select, callback });\n };\n\n private isObject(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && !Array.isArray(value) && value !== null;\n }\n\n private notifySubscribers = (newContext: ContextType<T>, prevContext: ContextType<T>) => {\n for (const sub of this.subscriptions) {\n if (!sub.select) return this.sendSubscriptionUpdate(sub, newContext);\n const newSelected = sub.select(newContext);\n const prevSelected = sub.select(prevContext);\n if (newSelected !== prevSelected) {\n this.sendSubscriptionUpdate(sub, newContext);\n }\n }\n };\n\n private sendSubscriptionUpdate = ({ select, callback }: ContextSubscription<T>, context: ContextType<T>) => {\n if (!select) callback(context);\n else callback(select(context));\n };\n\n private handleSubscriptionRequest = ({\n select,\n callback,\n subscribe,\n }: {\n select?: ContextSubscription<T>['select'];\n callback: ContextSubscription<T>['callback'];\n subscribe?: boolean;\n }) => {\n if (subscribe) this.subscribe({ select, callback });\n\n if (!this.value) return;\n\n if (select) {\n callback(select(this.value));\n } else {\n callback(this.value as ContextType<T>);\n }\n };\n\n private onSubscriptionRequest = (event: ContextSubscriptionRequestEvent<UnknownContext>) => {\n const { context, callback, subscribe, select, target } = event;\n if (context !== this.context) return;\n\n event.stopPropagation();\n\n (target as HTMLElement).dispatchEvent(new ContextOnMountEvent(this.context));\n\n this.handleSubscriptionRequest({ select, callback, subscribe });\n };\n\n private onContextRequest = (event: ContextRequestEvent<UnknownContext>) => {\n const { context, callback } = event;\n if (context !== this.context) return;\n event.stopPropagation();\n callback(this);\n };\n\n private registerEvents = () => {\n this.host.addEventListener(ContextEventsTypes.SUBSCRIPTION_REQUEST, this.onSubscriptionRequest);\n this.host.addEventListener(ContextEventsTypes.CONTEXT_REQUEST, this.onContextRequest);\n };\n}\n",
18
+ "import { ContextProvider } from '@/context/context-provider';\nimport type { UnknownContext } from '@/context/types';\nimport type { RadiantElement } from '@/core/radiant-element';\nimport type { AttributeTypeConstant } from '@/utils/attribute-utils';\n\ntype CreateContextOptions<T extends UnknownContext> = {\n context: T;\n initialValue?: T['__context__'];\n hydrate?: AttributeTypeConstant;\n};\n\n/**\n * A decorator to provide a context to the target element.\n * @param contextToProvide\n * @returns\n */\nexport function provideContext<T extends UnknownContext>({ context, initialValue, hydrate }: CreateContextOptions<T>) {\n return (proto: RadiantElement, propertyKey: string) => {\n const originalConnectedCallback = proto.connectedCallback;\n\n proto.connectedCallback = function (this: RadiantElement) {\n originalConnectedCallback.call(this);\n (this as any)[propertyKey] = new ContextProvider<T>(this, { context, initialValue, hydrate });\n this.connectedContextCallback(context);\n };\n };\n}\n",
19
+ "import { ContextRequestEvent } from '@/context/events';\nimport type { UnknownContext } from '@/context/types';\nimport type { RadiantElement } from '@/core/radiant-element';\n\n/**\n * A decorator to provide a context to the target element.\n * @param contextToProvide\n * @returns\n */\nexport function consumeContext(contextToProvide: UnknownContext) {\n return (proto: RadiantElement, propertyKey: string) => {\n const originalConnectedCallback = proto.connectedCallback;\n\n proto.connectedCallback = function (this: RadiantElement) {\n originalConnectedCallback.call(this);\n this.dispatchEvent(\n new ContextRequestEvent(contextToProvide, (context) => {\n (this as any)[propertyKey] = context;\n this.connectedContextCallback(contextToProvide);\n }),\n );\n };\n };\n}\n",
20
+ "import { ContextSubscriptionRequestEvent } from '@/context/events';\nimport type { Context, ContextType, UnknownContext } from '@/context/types';\nimport type { RadiantElement } from '@/core/radiant-element';\n\ntype ArgsType<T extends UnknownContext> = SubscribeToContextOptions<T>['select'] extends (...args: any[]) => infer R\n ? R\n : ContextType<T>;\n\ntype SubscribeToContextOptions<T extends UnknownContext> = {\n context: T;\n select?: (context: T['__context__']) => unknown;\n subscribe?: boolean;\n};\n/**\n * A decorator to subscribe to a context selector.\n * @param context The context to subscribe to.\n * @param selector The selector to subscribe to. If not provided, the whole context will be subscribed to.\n * @param subscribe @default true Whether to subscribe or unsubscribe. Optional.\n * @returns\n */\nexport function contextSelector<T extends Context<unknown, unknown>>({\n context,\n select,\n subscribe = true,\n}: SubscribeToContextOptions<T>) {\n return (proto: RadiantElement, _: string, descriptor: PropertyDescriptor) => {\n const originalMethod = descriptor.value;\n const originalConnectedCallback = proto.connectedCallback;\n\n proto.connectedCallback = function (this: RadiantElement) {\n originalConnectedCallback.call(this);\n this.dispatchEvent(new ContextSubscriptionRequestEvent(context, originalMethod.bind(this), select, subscribe));\n };\n\n descriptor.value = function (...args: ArgsType<T>[]) {\n const result = originalMethod.apply(this, args);\n return result;\n };\n\n return descriptor;\n };\n}\n",
21
+ "import type { RadiantElement, RenderInsertPosition } from '@/core/radiant-element';\n\ntype Constructor<T> = new (...args: any[]) => T;\n\ntype WithKitaRenderTemplateProps = {\n target: HTMLElement;\n template: JSX.Element | string;\n insert?: RenderInsertPosition;\n};\n\ninterface WithKitaMixin {\n renderTemplate: (props: WithKitaRenderTemplateProps) => Promise<void>;\n}\n\n/**\n * A mixin that provides a method to render a JSX template into an HTMLElement.\n */\nexport function WithKita<T extends Constructor<RadiantElement>>(Base: T): T & Constructor<WithKitaMixin> {\n return class extends Base implements WithKitaMixin {\n override async renderTemplate({ target = this, template, insert = 'replace' }: WithKitaRenderTemplateProps) {\n const safeTemplate = typeof template !== 'string' ? template.toString() : template;\n switch (insert) {\n case 'replace':\n target.innerHTML = safeTemplate;\n break;\n case 'beforeend':\n target.insertAdjacentHTML('beforeend', safeTemplate);\n break;\n case 'afterbegin':\n target.insertAdjacentHTML('afterbegin', safeTemplate);\n break;\n }\n }\n } as T & Constructor<WithKitaMixin>;\n}\n",
22
+ "/**\n * Converts the given value to a JSON string representation.\n * This can be very handy for passing complex objects as attributes.\n *\n * @param value - The value to be converted.\n * @returns The JSON string representation of the value.\n * @template T - The type of the value.\n *\n * @example <my-app class=\"radiant-todo\" hydrate-context={stringifyAttribute<MyType>(context)}>\n */\nexport function stringifyAttribute<T>(value: T): T {\n return JSON.stringify(value) as unknown as T;\n}\n"
5
23
  ],
6
- "mappings": "",
7
- "debugId": "02FD23EB472364E664756E2164756E21",
24
+ "mappings": ";AAIO,SAAS,aAAa,CAAC,MAAc;AAC1C,SAAO,CAAC,WAAqC;AAC3C,SAAK,WAAW;AAAQ;AACxB,SAAK,OAAO,eAAe,IAAI,IAAI,GAAG;AACpC,aAAO,eAAe,OAAO,MAAM,MAAM;AAAA,IAC3C;AAAA;AAAA;;;ACKG,MAAM,aAA0B;AAAA,EAC7B;AAAA,EACA;AAAA,EAQR,WAAW,CAAC,MAAsB,aAAiC;AACjE,SAAK,OAAO;AACZ,SAAK,cAAc;AAAA;AAAA,EAQrB,IAAI,CAAC,QAAY;AACf,UAAM,QAAQ,IAAI,YAAY,KAAK,YAAY,MAAM;AAAA,MACnD;AAAA,MACA,SAAS,KAAK,YAAY;AAAA,MAC1B,YAAY,KAAK,YAAY;AAAA,MAC7B,UAAU,KAAK,YAAY;AAAA,IAC7B,CAAC;AACD,SAAK,KAAK,cAAc,KAAK;AAAA;AAEjC;;;ACjCO,SAAS,KAAK,CAAC,aAAiC;AACrD,SAAO,CAAC,QAAa,gBAAwB;AAC3C,SAAK,aAAa;AAChB,YAAM,IAAI,MAAM,qDAAqD;AAAA,IACvE;AAEA,SAAK,gBAAgB,YAAY,MAAM;AACrC,YAAM,IAAI,MAAM,+BAA+B;AAAA,IACjD;AAEA,UAAM,YAAY,OAAO,YAAY,IAAI;AAEzC,WAAO,eAAe,QAAQ,aAAa;AAAA,MACzC,GAAG,GAAG;AACJ,cAAM,cAAyC,cAAc,IAAI,IAAI,KAAK,IAAI;AAC9E,aAAK,YAAY,IAAI,SAAS,GAAG;AAC/B,sBAAY,IAAI,WAAW,IAAI,aAAa,MAAM,WAAW,CAAC;AAC9D,wBAAc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AAI,GAAG,QAAQ,SAAS,CAAC;AAAA;AAG/G,eAAW,gBAAiB,IAAI,MAAqB;AACnD,YAAM,SAAS,eAAe,MAAM,MAAM,IAAI;AAC9C,aAAO;AAAA;AAGT,WAAO;AAAA;AAAA;;ACtBJ,SAAS,QAA+C,CAAC,MAAyC;AACvG,SAAO,cAAc,KAA8B;AAAA,SAClC,eAAc,GAAG,SAAS,MAAM,UAAU,SAAS,aAA0C;AAC1G,YAAM,sBAAsB,aAAa,WAAW,SAAS,SAAS,IAAI;AAC1E,cAAQ;AAAA,aACD;AACH,iBAAO,YAAY;AACnB;AAAA,aACG;AACH,iBAAO,mBAAmB,aAAa,YAAY;AACnD;AAAA,aACG;AACH,iBAAO,mBAAmB,cAAc,YAAY;AACpD;AAAA;AAAA;AAAA,EAGR;AAAA;;ACvBK,SAAS,kBAAqB,CAAC,OAAa;AACjD,SAAO,KAAK,UAAU,KAAK;AAAA;",
25
+ "debugId": "9F8C73D65206CDB164756E2164756E21",
8
26
  "names": []
9
27
  }
@@ -1,3 +1,24 @@
1
- import{k as e} from"./with-kita.js";export{e as WithKita};
1
+ // src/mixins/with-kita.ts
2
+ function WithKita(Base) {
3
+ return class extends Base {
4
+ async renderTemplate({ target = this, template, insert = "replace" }) {
5
+ const safeTemplate = typeof template !== "string" ? template.toString() : template;
6
+ switch (insert) {
7
+ case "replace":
8
+ target.innerHTML = safeTemplate;
9
+ break;
10
+ case "beforeend":
11
+ target.insertAdjacentHTML("beforeend", safeTemplate);
12
+ break;
13
+ case "afterbegin":
14
+ target.insertAdjacentHTML("afterbegin", safeTemplate);
15
+ break;
16
+ }
17
+ }
18
+ };
19
+ }
20
+ export {
21
+ WithKita
22
+ };
2
23
 
3
- //# debugId=89A6CBB2FE15B6E364756E2164756E21
24
+ //# debugId=795A98B05770A30C64756E2164756E21
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": [],
3
+ "sources": ["../src/mixins/with-kita.ts"],
4
4
  "sourcesContent": [
5
+ "import type { RadiantElement, RenderInsertPosition } from '@/core/radiant-element';\n\ntype Constructor<T> = new (...args: any[]) => T;\n\ntype WithKitaRenderTemplateProps = {\n target: HTMLElement;\n template: JSX.Element | string;\n insert?: RenderInsertPosition;\n};\n\ninterface WithKitaMixin {\n renderTemplate: (props: WithKitaRenderTemplateProps) => Promise<void>;\n}\n\n/**\n * A mixin that provides a method to render a JSX template into an HTMLElement.\n */\nexport function WithKita<T extends Constructor<RadiantElement>>(Base: T): T & Constructor<WithKitaMixin> {\n return class extends Base implements WithKitaMixin {\n override async renderTemplate({ target = this, template, insert = 'replace' }: WithKitaRenderTemplateProps) {\n const safeTemplate = typeof template !== 'string' ? template.toString() : template;\n switch (insert) {\n case 'replace':\n target.innerHTML = safeTemplate;\n break;\n case 'beforeend':\n target.insertAdjacentHTML('beforeend', safeTemplate);\n break;\n case 'afterbegin':\n target.insertAdjacentHTML('afterbegin', safeTemplate);\n break;\n }\n }\n } as T & Constructor<WithKitaMixin>;\n}\n"
5
6
  ],
6
- "mappings": "",
7
- "debugId": "89A6CBB2FE15B6E364756E2164756E21",
7
+ "mappings": ";AAiBO,SAAS,QAA+C,CAAC,MAAyC;AACvG,SAAO,cAAc,KAA8B;AAAA,SAClC,eAAc,GAAG,SAAS,MAAM,UAAU,SAAS,aAA0C;AAC1G,YAAM,sBAAsB,aAAa,WAAW,SAAS,SAAS,IAAI;AAC1E,cAAQ;AAAA,aACD;AACH,iBAAO,YAAY;AACnB;AAAA,aACG;AACH,iBAAO,mBAAmB,aAAa,YAAY;AACnD;AAAA,aACG;AACH,iBAAO,mBAAmB,cAAc,YAAY;AACpD;AAAA;AAAA;AAAA,EAGR;AAAA;",
8
+ "debugId": "795A98B05770A30C64756E2164756E21",
8
9
  "names": []
9
10
  }
@@ -1,4 +1,24 @@
1
- function u(k){return class extends k{async renderTemplate({target:b=this,template:c,insert:q="replace"}){const j=typeof c!=="string"?c.toString():c;switch(q){case"replace":b.innerHTML=j;break;case"beforeend":b.insertAdjacentHTML("beforeend",j);break;case"afterbegin":b.insertAdjacentHTML("afterbegin",j);break}}}}export{u as WithKita};
2
- export{u as k};
1
+ // src/mixins/with-kita.ts
2
+ function WithKita(Base) {
3
+ return class extends Base {
4
+ async renderTemplate({ target = this, template, insert = "replace" }) {
5
+ const safeTemplate = typeof template !== "string" ? template.toString() : template;
6
+ switch (insert) {
7
+ case "replace":
8
+ target.innerHTML = safeTemplate;
9
+ break;
10
+ case "beforeend":
11
+ target.insertAdjacentHTML("beforeend", safeTemplate);
12
+ break;
13
+ case "afterbegin":
14
+ target.insertAdjacentHTML("afterbegin", safeTemplate);
15
+ break;
16
+ }
17
+ }
18
+ };
19
+ }
20
+ export {
21
+ WithKita
22
+ };
3
23
 
4
- //# debugId=4BC44856CCA3A8EF64756E2164756E21
24
+ //# debugId=B5494072FE37965064756E2164756E21
@@ -4,7 +4,7 @@
4
4
  "sourcesContent": [
5
5
  "import type { RadiantElement, RenderInsertPosition } from '@/core/radiant-element';\n\ntype Constructor<T> = new (...args: any[]) => T;\n\ntype WithKitaRenderTemplateProps = {\n target: HTMLElement;\n template: JSX.Element | string;\n insert?: RenderInsertPosition;\n};\n\ninterface WithKitaMixin {\n renderTemplate: (props: WithKitaRenderTemplateProps) => Promise<void>;\n}\n\n/**\n * A mixin that provides a method to render a JSX template into an HTMLElement.\n */\nexport function WithKita<T extends Constructor<RadiantElement>>(Base: T): T & Constructor<WithKitaMixin> {\n return class extends Base implements WithKitaMixin {\n override async renderTemplate({ target = this, template, insert = 'replace' }: WithKitaRenderTemplateProps) {\n const safeTemplate = typeof template !== 'string' ? template.toString() : template;\n switch (insert) {\n case 'replace':\n target.innerHTML = safeTemplate;\n break;\n case 'beforeend':\n target.insertAdjacentHTML('beforeend', safeTemplate);\n break;\n case 'afterbegin':\n target.insertAdjacentHTML('afterbegin', safeTemplate);\n break;\n }\n }\n } as T & Constructor<WithKitaMixin>;\n}\n"
6
6
  ],
7
- "mappings": "AAiBO,SAAS,CAA+C,CAAC,EAAyC,CACvG,OAAO,cAAc,CAA8B,MAClC,eAAc,EAAG,SAAS,KAAM,WAAU,SAAS,WAA0C,CAC1G,MAAM,SAAsB,IAAa,SAAW,EAAS,SAAS,EAAI,EAC1E,OAAQ,OACD,UACH,EAAO,UAAY,EACnB,UACG,YACH,EAAO,mBAAmB,YAAa,CAAY,EACnD,UACG,aACH,EAAO,mBAAmB,aAAc,CAAY,EACpD,OAGR",
8
- "debugId": "4BC44856CCA3A8EF64756E2164756E21",
7
+ "mappings": ";AAiBO,SAAS,QAA+C,CAAC,MAAyC;AACvG,SAAO,cAAc,KAA8B;AAAA,SAClC,eAAc,GAAG,SAAS,MAAM,UAAU,SAAS,aAA0C;AAC1G,YAAM,sBAAsB,aAAa,WAAW,SAAS,SAAS,IAAI;AAC1E,cAAQ;AAAA,aACD;AACH,iBAAO,YAAY;AACnB;AAAA,aACG;AACH,iBAAO,mBAAmB,aAAa,YAAY;AACnD;AAAA,aACG;AACH,iBAAO,mBAAmB,cAAc,YAAY;AACpD;AAAA;AAAA;AAAA,EAGR;AAAA;",
8
+ "debugId": "B5494072FE37965064756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -1,4 +1,23 @@
1
- class x{host;eventConfig;constructor(k,q){this.host=k,this.eventConfig=q}emit(k){const q=new CustomEvent(this.eventConfig.name,{detail:k,bubbles:this.eventConfig.bubbles,cancelable:this.eventConfig.cancelable,composed:this.eventConfig.composed});this.host.dispatchEvent(q)}}export{x as EventEmitter};
2
- export{x as t};
1
+ // src/tools/event-emitter.ts
2
+ class EventEmitter {
3
+ host;
4
+ eventConfig;
5
+ constructor(host, eventConfig) {
6
+ this.host = host;
7
+ this.eventConfig = eventConfig;
8
+ }
9
+ emit(detail) {
10
+ const event = new CustomEvent(this.eventConfig.name, {
11
+ detail,
12
+ bubbles: this.eventConfig.bubbles,
13
+ cancelable: this.eventConfig.cancelable,
14
+ composed: this.eventConfig.composed
15
+ });
16
+ this.host.dispatchEvent(event);
17
+ }
18
+ }
19
+ export {
20
+ EventEmitter
21
+ };
3
22
 
4
- //# debugId=EF7DCAF38E65FBE864756E2164756E21
23
+ //# debugId=B011F9EC3CC948C064756E2164756E21
@@ -4,7 +4,7 @@
4
4
  "sourcesContent": [
5
5
  "import type { RadiantElement } from '..';\n\nexport interface EventEmitterConfig {\n name: string;\n bubbles?: boolean;\n cancelable?: boolean;\n composed?: boolean;\n}\n\n/**\n * A generic event emitter class that allows emitting custom events.\n *\n * @template T - The type of the event detail.\n */\nexport class EventEmitter<T = unknown> {\n private host: RadiantElement;\n private eventConfig: EventEmitterConfig;\n\n /**\n * Constructs a new instance of the EventEmitter class.\n *\n * @param host - The host element on which the events will be dispatched.\n * @param eventConfig - The configuration for the event.\n */\n constructor(host: RadiantElement, eventConfig: EventEmitterConfig) {\n this.host = host;\n this.eventConfig = eventConfig;\n }\n\n /**\n * Emits a custom event with the specified detail.\n *\n * @param detail - The detail object to be passed along with the event.\n */\n emit(detail?: T) {\n const event = new CustomEvent(this.eventConfig.name, {\n detail: detail,\n bubbles: this.eventConfig.bubbles,\n cancelable: this.eventConfig.cancelable,\n composed: this.eventConfig.composed,\n });\n this.host.dispatchEvent(event);\n }\n}\n"
6
6
  ],
7
- "mappings": "AAcO,MAAM,CAA0B,CAC7B,KACA,YAQR,WAAW,CAAC,EAAsB,EAAiC,CACjE,KAAK,KAAO,EACZ,KAAK,YAAc,EAQrB,IAAI,CAAC,EAAY,CACf,MAAM,EAAQ,IAAI,YAAY,KAAK,YAAY,KAAM,CACnD,OAAQ,EACR,QAAS,KAAK,YAAY,QAC1B,WAAY,KAAK,YAAY,WAC7B,SAAU,KAAK,YAAY,QAC7B,CAAC,EACD,KAAK,KAAK,cAAc,CAAK,EAEjC",
8
- "debugId": "EF7DCAF38E65FBE864756E2164756E21",
7
+ "mappings": ";AAcO,MAAM,aAA0B;AAAA,EAC7B;AAAA,EACA;AAAA,EAQR,WAAW,CAAC,MAAsB,aAAiC;AACjE,SAAK,OAAO;AACZ,SAAK,cAAc;AAAA;AAAA,EAQrB,IAAI,CAAC,QAAY;AACf,UAAM,QAAQ,IAAI,YAAY,KAAK,YAAY,MAAM;AAAA,MACnD;AAAA,MACA,SAAS,KAAK,YAAY;AAAA,MAC1B,YAAY,KAAK,YAAY;AAAA,MAC7B,UAAU,KAAK,YAAY;AAAA,IAC7B,CAAC;AACD,SAAK,KAAK,cAAc,KAAK;AAAA;AAEjC;",
8
+ "debugId": "B011F9EC3CC948C064756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -1,3 +1,29 @@
1
- import{s as m} from"./stringify-attribute.js";import{t as f} from"./event-emitter.js";export{m as stringifyAttribute,f as EventEmitter};
1
+ // src/tools/event-emitter.ts
2
+ class EventEmitter {
3
+ host;
4
+ eventConfig;
5
+ constructor(host, eventConfig) {
6
+ this.host = host;
7
+ this.eventConfig = eventConfig;
8
+ }
9
+ emit(detail) {
10
+ const event = new CustomEvent(this.eventConfig.name, {
11
+ detail,
12
+ bubbles: this.eventConfig.bubbles,
13
+ cancelable: this.eventConfig.cancelable,
14
+ composed: this.eventConfig.composed
15
+ });
16
+ this.host.dispatchEvent(event);
17
+ }
18
+ }
2
19
 
3
- //# debugId=C6D6495E47CC38E164756E2164756E21
20
+ // src/tools/stringify-attribute.ts
21
+ function stringifyAttribute(value) {
22
+ return JSON.stringify(value);
23
+ }
24
+ export {
25
+ stringifyAttribute,
26
+ EventEmitter
27
+ };
28
+
29
+ //# debugId=AC021311C8305C0D64756E2164756E21
@@ -1,9 +1,11 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": [],
3
+ "sources": ["../src/tools/event-emitter.ts", "../src/tools/stringify-attribute.ts"],
4
4
  "sourcesContent": [
5
+ "import type { RadiantElement } from '..';\n\nexport interface EventEmitterConfig {\n name: string;\n bubbles?: boolean;\n cancelable?: boolean;\n composed?: boolean;\n}\n\n/**\n * A generic event emitter class that allows emitting custom events.\n *\n * @template T - The type of the event detail.\n */\nexport class EventEmitter<T = unknown> {\n private host: RadiantElement;\n private eventConfig: EventEmitterConfig;\n\n /**\n * Constructs a new instance of the EventEmitter class.\n *\n * @param host - The host element on which the events will be dispatched.\n * @param eventConfig - The configuration for the event.\n */\n constructor(host: RadiantElement, eventConfig: EventEmitterConfig) {\n this.host = host;\n this.eventConfig = eventConfig;\n }\n\n /**\n * Emits a custom event with the specified detail.\n *\n * @param detail - The detail object to be passed along with the event.\n */\n emit(detail?: T) {\n const event = new CustomEvent(this.eventConfig.name, {\n detail: detail,\n bubbles: this.eventConfig.bubbles,\n cancelable: this.eventConfig.cancelable,\n composed: this.eventConfig.composed,\n });\n this.host.dispatchEvent(event);\n }\n}\n",
6
+ "/**\n * Converts the given value to a JSON string representation.\n * This can be very handy for passing complex objects as attributes.\n *\n * @param value - The value to be converted.\n * @returns The JSON string representation of the value.\n * @template T - The type of the value.\n *\n * @example <my-app class=\"radiant-todo\" hydrate-context={stringifyAttribute<MyType>(context)}>\n */\nexport function stringifyAttribute<T>(value: T): T {\n return JSON.stringify(value) as unknown as T;\n}\n"
5
7
  ],
6
- "mappings": "",
7
- "debugId": "C6D6495E47CC38E164756E2164756E21",
8
+ "mappings": ";AAcO,MAAM,aAA0B;AAAA,EAC7B;AAAA,EACA;AAAA,EAQR,WAAW,CAAC,MAAsB,aAAiC;AACjE,SAAK,OAAO;AACZ,SAAK,cAAc;AAAA;AAAA,EAQrB,IAAI,CAAC,QAAY;AACf,UAAM,QAAQ,IAAI,YAAY,KAAK,YAAY,MAAM;AAAA,MACnD;AAAA,MACA,SAAS,KAAK,YAAY;AAAA,MAC1B,YAAY,KAAK,YAAY;AAAA,MAC7B,UAAU,KAAK,YAAY;AAAA,IAC7B,CAAC;AACD,SAAK,KAAK,cAAc,KAAK;AAAA;AAEjC;;;ACjCO,SAAS,kBAAqB,CAAC,OAAa;AACjD,SAAO,KAAK,UAAU,KAAK;AAAA;",
9
+ "debugId": "AC021311C8305C0D64756E2164756E21",
8
10
  "names": []
9
11
  }
@@ -1,4 +1,9 @@
1
- function t(e){return JSON.stringify(e)}export{t as stringifyAttribute};
2
- export{t as s};
1
+ // src/tools/stringify-attribute.ts
2
+ function stringifyAttribute(value) {
3
+ return JSON.stringify(value);
4
+ }
5
+ export {
6
+ stringifyAttribute
7
+ };
3
8
 
4
- //# debugId=55E05DA77FB3A62364756E2164756E21
9
+ //# debugId=D048CAC03A51E99A64756E2164756E21
@@ -4,7 +4,7 @@
4
4
  "sourcesContent": [
5
5
  "/**\n * Converts the given value to a JSON string representation.\n * This can be very handy for passing complex objects as attributes.\n *\n * @param value - The value to be converted.\n * @returns The JSON string representation of the value.\n * @template T - The type of the value.\n *\n * @example <my-app class=\"radiant-todo\" hydrate-context={stringifyAttribute<MyType>(context)}>\n */\nexport function stringifyAttribute<T>(value: T): T {\n return JSON.stringify(value) as unknown as T;\n}\n"
6
6
  ],
7
- "mappings": "AAUO,SAAS,CAAqB,CAAC,EAAa,CACjD,OAAO,KAAK,UAAU,CAAK",
8
- "debugId": "55E05DA77FB3A62364756E2164756E21",
7
+ "mappings": ";AAUO,SAAS,kBAAqB,CAAC,OAAa;AACjD,SAAO,KAAK,UAAU,KAAK;AAAA;",
8
+ "debugId": "D048CAC03A51E99A64756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -29,6 +29,7 @@ export declare function defaultValueForType(type: AttributeTypeConstant): unknow
29
29
  * @throws {TypeError} If the provided type is unknown.
30
30
  */
31
31
  export declare function readAttributeValue(value: string, type: AttributeTypeConstant): string | number | boolean | object | unknown[];
32
+ export type ReadAttributeValueReturnType = ReturnType<typeof readAttributeValue>;
32
33
  /**
33
34
  * Writes the attribute value based on the provided type.
34
35
  *
@@ -38,4 +39,5 @@ export declare function readAttributeValue(value: string, type: AttributeTypeCon
38
39
  * @throws {TypeError} If the provided type is unknown.
39
40
  */
40
41
  export declare function writeAttributeValue(value: unknown, type: AttributeTypeConstant): string;
42
+ export type WriteAttributeValueReturnType = ReturnType<typeof writeAttributeValue>;
41
43
  export declare function isValueOfType(type: AttributeTypeConstant, defaultValue: unknown): boolean;
@@ -1,4 +1,138 @@
1
- function G(q){switch(q){case Array:return"array";case Boolean:return"boolean";case Number:return"number";case Object:return"object";case String:return"string"}}function H(q){switch(typeof q){case"boolean":return"boolean";case"number":return"number";case"string":return"string"}if(Array.isArray(q))return"array";if(Object.prototype.toString.call(q)==="[object Object]")return"object"}function W(q){switch(q){case Number:return 0;case String:return"";case Boolean:return!1;default:return null}}var I=function(q){try{return JSON.parse(q)}catch(x){throw new TypeError("Invalid JSON string")}},F=function(q){return JSON.stringify(q)},L=function(q){return`${q}`};function X(q,x){const z=G(x);if(!z)throw new TypeError(`[radiant-element] Unknown type "${x}"`);return K[z](q)}function Y(q,x){const z=G(x);if(!z)throw new TypeError(`[radiant-element] Unknown type "${x}"`);return(E[z]||E.default)(q)}var M=function(q){return typeof q==="boolean"},P=function(q){return typeof q==="number"},Q=function(q){return typeof q==="string"},R=function(q){return Array.isArray(q)},U=function(q){return typeof q==="object"&&!Array.isArray(q)&&q!==null};function Z(q,x){switch(q){case Boolean:return M(x);case Number:return P(x);case String:return Q(x);case Array:return R(x);case Object:return U(x);default:return!1}}var K={array(q){const x=I(q);if(!Array.isArray(x))throw new TypeError(`Expected an array but got a value of type "${typeof x}"`);return x},boolean(q){return!(q==="0"||String(q).toLowerCase()==="false")},number(q){return Number(q.replace(/_/g,""))},object(q){const x=JSON.parse(q);if(x===null||typeof x!=="object"||Array.isArray(x))throw new TypeError(`expected value of type "object" but instead got value "${q}" of type "${H(x)}"`);return x},string(q){return q}},E={default:L,array:F,object:F};export{Y as writeAttributeValue,X as readAttributeValue,H as parseAttributeTypeDefault,G as parseAttributeTypeConstant,Z as isValueOfType,W as defaultValueForType};
2
- export{G as m,H as n,W as o,X as p,Y as q,Z as r};
1
+ // src/utils/attribute-utils.ts
2
+ function parseAttributeTypeConstant(constant) {
3
+ switch (constant) {
4
+ case Array:
5
+ return "array";
6
+ case Boolean:
7
+ return "boolean";
8
+ case Number:
9
+ return "number";
10
+ case Object:
11
+ return "object";
12
+ case String:
13
+ return "string";
14
+ }
15
+ }
16
+ function parseAttributeTypeDefault(defaultValue) {
17
+ switch (typeof defaultValue) {
18
+ case "boolean":
19
+ return "boolean";
20
+ case "number":
21
+ return "number";
22
+ case "string":
23
+ return "string";
24
+ }
25
+ if (Array.isArray(defaultValue))
26
+ return "array";
27
+ if (Object.prototype.toString.call(defaultValue) === "[object Object]")
28
+ return "object";
29
+ }
30
+ function defaultValueForType(type) {
31
+ switch (type) {
32
+ case Number:
33
+ return 0;
34
+ case String:
35
+ return "";
36
+ case Boolean:
37
+ return false;
38
+ default:
39
+ return null;
40
+ }
41
+ }
42
+ function parseJSON(value) {
43
+ try {
44
+ return JSON.parse(value);
45
+ } catch (error) {
46
+ throw new TypeError("Invalid JSON string");
47
+ }
48
+ }
49
+ function writeJSON(value) {
50
+ return JSON.stringify(value);
51
+ }
52
+ function writeString(value) {
53
+ return `${value}`;
54
+ }
55
+ function readAttributeValue(value, type) {
56
+ const readerType = parseAttributeTypeConstant(type);
57
+ if (!readerType)
58
+ throw new TypeError(`[radiant-element] Unknown type "${type}"`);
59
+ return readers[readerType](value);
60
+ }
61
+ function writeAttributeValue(value, type) {
62
+ const writerType = parseAttributeTypeConstant(type);
63
+ if (!writerType)
64
+ throw new TypeError(`[radiant-element] Unknown type "${type}"`);
65
+ return (writers[writerType] || writers.default)(value);
66
+ }
67
+ function isBoolean(value) {
68
+ return typeof value === "boolean";
69
+ }
70
+ function isNumber(value) {
71
+ return typeof value === "number";
72
+ }
73
+ function isString(value) {
74
+ return typeof value === "string";
75
+ }
76
+ function isArray(value) {
77
+ return Array.isArray(value);
78
+ }
79
+ function isObject(value) {
80
+ return typeof value === "object" && !Array.isArray(value) && value !== null;
81
+ }
82
+ function isValueOfType(type, defaultValue) {
83
+ switch (type) {
84
+ case Boolean:
85
+ return isBoolean(defaultValue);
86
+ case Number:
87
+ return isNumber(defaultValue);
88
+ case String:
89
+ return isString(defaultValue);
90
+ case Array:
91
+ return isArray(defaultValue);
92
+ case Object:
93
+ return isObject(defaultValue);
94
+ default:
95
+ return false;
96
+ }
97
+ }
98
+ var readers = {
99
+ array(value) {
100
+ const array = parseJSON(value);
101
+ if (!Array.isArray(array)) {
102
+ throw new TypeError(`Expected an array but got a value of type "${typeof array}"`);
103
+ }
104
+ return array;
105
+ },
106
+ boolean(value) {
107
+ return !(value === "0" || String(value).toLowerCase() === "false");
108
+ },
109
+ number(value) {
110
+ const number = Number(value.replace(/_/g, ""));
111
+ return number;
112
+ },
113
+ object(value) {
114
+ const object = JSON.parse(value);
115
+ if (object === null || typeof object !== "object" || Array.isArray(object)) {
116
+ throw new TypeError(`expected value of type "object" but instead got value "${value}" of type "${parseAttributeTypeDefault(object)}"`);
117
+ }
118
+ return object;
119
+ },
120
+ string(value) {
121
+ return value;
122
+ }
123
+ };
124
+ var writers = {
125
+ default: writeString,
126
+ array: writeJSON,
127
+ object: writeJSON
128
+ };
129
+ export {
130
+ writeAttributeValue,
131
+ readAttributeValue,
132
+ parseAttributeTypeDefault,
133
+ parseAttributeTypeConstant,
134
+ isValueOfType,
135
+ defaultValueForType
136
+ };
3
137
 
4
- //# debugId=C41935C36D4A3CF764756E2164756E21
138
+ //# debugId=5A1021F67887CE1364756E2164756E21
@@ -2,9 +2,9 @@
2
2
  "version": 3,
3
3
  "sources": ["../src/utils/attribute-utils.ts"],
4
4
  "sourcesContent": [
5
- "export type AttributeTypeConstant = typeof Array | typeof Boolean | typeof Number | typeof Object | typeof String;\n\nexport type AttributeTypeDefault = Array<unknown> | boolean | number | Record<string, unknown> | string;\n\n/**\n * Parses the given attribute type constant and returns its corresponding string representation.\n *\n * @param constant - The attribute type constant to parse.\n * @returns The string representation of the attribute type constant.\n */\nexport function parseAttributeTypeConstant(constant?: AttributeTypeConstant) {\n switch (constant) {\n case Array:\n return 'array';\n case Boolean:\n return 'boolean';\n case Number:\n return 'number';\n case Object:\n return 'object';\n case String:\n return 'string';\n }\n}\n\n/**\n * Parses the attribute type default value and returns its type as a string.\n *\n * @param defaultValue - The default value of the attribute type.\n * @returns The type of the default value as a string.\n */\nexport function parseAttributeTypeDefault(defaultValue?: AttributeTypeDefault) {\n switch (typeof defaultValue) {\n case 'boolean':\n return 'boolean';\n case 'number':\n return 'number';\n case 'string':\n return 'string';\n }\n\n if (Array.isArray(defaultValue)) return 'array';\n if (Object.prototype.toString.call(defaultValue) === '[object Object]') return 'object';\n}\n\n/**\n * Returns the default value for a given attribute type.\n *\n * @param type - The attribute type constant.\n * @returns The default value for the specified attribute type.\n */\nexport function defaultValueForType(type: AttributeTypeConstant): unknown {\n switch (type) {\n case Number:\n return 0;\n case String:\n return '';\n case Boolean:\n return false;\n default:\n return null;\n }\n}\n\ntype Reader = (value: string) => number | string | boolean | object | unknown[];\n\n/**\n * Utility function to parse a JSON string safely\n */\nfunction parseJSON<T>(value: string): T {\n try {\n return JSON.parse(value);\n } catch (error) {\n throw new TypeError('Invalid JSON string');\n }\n}\n\n/**\n * Object that maps attribute types to reader functions.\n * @type {Object.<string, Reader>}\n */\nconst readers: { [type: string]: Reader } = {\n array(value: string): unknown[] {\n const array = parseJSON<unknown[]>(value);\n if (!Array.isArray(array)) {\n throw new TypeError(`Expected an array but got a value of type \"${typeof array}\"`);\n }\n return array;\n },\n\n boolean(value: string): boolean {\n return !(value === '0' || String(value).toLowerCase() === 'false');\n },\n\n number(value: string): number {\n const number = Number(value.replace(/_/g, ''));\n return number;\n },\n\n object(value: string): object {\n const object = JSON.parse(value);\n if (object === null || typeof object !== 'object' || Array.isArray(object)) {\n throw new TypeError(\n `expected value of type \"object\" but instead got value \"${value}\" of type \"${parseAttributeTypeDefault(\n object,\n )}\"`,\n );\n }\n return object;\n },\n\n string(value: string): string {\n return value;\n },\n};\n\ntype Writer = (value: unknown) => string;\n\n/**\n * Object that maps attribute types to writer functions.\n * @type {Object.<string, Writer>}\n */\nconst writers: { [type: string]: Writer } = {\n default: writeString,\n array: writeJSON,\n object: writeJSON,\n};\n\nfunction writeJSON(value: unknown) {\n return JSON.stringify(value);\n}\n\nfunction writeString(value: unknown) {\n return `${value}`;\n}\n\n/**\n * Reads the attribute value based on the provided type.\n * @param value - The attribute value to be read.\n * @param type - The type of the attribute.\n * @returns The parsed attribute value.\n * @throws {TypeError} If the provided type is unknown.\n */\nexport function readAttributeValue(value: string, type: AttributeTypeConstant) {\n const readerType = parseAttributeTypeConstant(type);\n if (!readerType) throw new TypeError(`[radiant-element] Unknown type \"${type}\"`);\n return readers[readerType](value);\n}\n\n/**\n * Writes the attribute value based on the provided type.\n *\n * @param value - The value to be written.\n * @param type - The type of the attribute.\n * @returns The written attribute value.\n * @throws {TypeError} If the provided type is unknown.\n */\nexport function writeAttributeValue(value: unknown, type: AttributeTypeConstant) {\n const writerType = parseAttributeTypeConstant(type);\n if (!writerType) throw new TypeError(`[radiant-element] Unknown type \"${type}\"`);\n return (writers[writerType] || writers.default)(value);\n}\n\n/*\n * Type guard functions for each type in AttributeTypeConstant\n */\nfunction isBoolean(value: unknown): value is boolean {\n return typeof value === 'boolean';\n}\n\nfunction isNumber(value: unknown): value is number {\n return typeof value === 'number';\n}\n\nfunction isString(value: unknown): value is string {\n return typeof value === 'string';\n}\n\nfunction isArray(value: unknown): value is Array<unknown> {\n return Array.isArray(value);\n}\n\nfunction isObject(value: unknown): value is object {\n return typeof value === 'object' && !Array.isArray(value) && value !== null;\n}\n\n/*\n * Check function to ensure defaultValue matches the type\n */\nexport function isValueOfType(type: AttributeTypeConstant, defaultValue: unknown): boolean {\n switch (type) {\n case Boolean:\n return isBoolean(defaultValue);\n case Number:\n return isNumber(defaultValue);\n case String:\n return isString(defaultValue);\n case Array:\n return isArray(defaultValue);\n case Object:\n return isObject(defaultValue);\n default:\n return false;\n }\n}\n"
5
+ "export type AttributeTypeConstant = typeof Array | typeof Boolean | typeof Number | typeof Object | typeof String;\n\nexport type AttributeTypeDefault = Array<unknown> | boolean | number | Record<string, unknown> | string;\n\n/**\n * Parses the given attribute type constant and returns its corresponding string representation.\n *\n * @param constant - The attribute type constant to parse.\n * @returns The string representation of the attribute type constant.\n */\nexport function parseAttributeTypeConstant(constant?: AttributeTypeConstant) {\n switch (constant) {\n case Array:\n return 'array';\n case Boolean:\n return 'boolean';\n case Number:\n return 'number';\n case Object:\n return 'object';\n case String:\n return 'string';\n }\n}\n\n/**\n * Parses the attribute type default value and returns its type as a string.\n *\n * @param defaultValue - The default value of the attribute type.\n * @returns The type of the default value as a string.\n */\nexport function parseAttributeTypeDefault(defaultValue?: AttributeTypeDefault) {\n switch (typeof defaultValue) {\n case 'boolean':\n return 'boolean';\n case 'number':\n return 'number';\n case 'string':\n return 'string';\n }\n\n if (Array.isArray(defaultValue)) return 'array';\n if (Object.prototype.toString.call(defaultValue) === '[object Object]') return 'object';\n}\n\n/**\n * Returns the default value for a given attribute type.\n *\n * @param type - The attribute type constant.\n * @returns The default value for the specified attribute type.\n */\nexport function defaultValueForType(type: AttributeTypeConstant): unknown {\n switch (type) {\n case Number:\n return 0;\n case String:\n return '';\n case Boolean:\n return false;\n default:\n return null;\n }\n}\n\ntype Reader = (value: string) => number | string | boolean | object | unknown[];\n\n/**\n * Utility function to parse a JSON string safely\n */\nfunction parseJSON<T>(value: string): T {\n try {\n return JSON.parse(value);\n } catch (error) {\n throw new TypeError('Invalid JSON string');\n }\n}\n\n/**\n * Object that maps attribute types to reader functions.\n * @type {Object.<string, Reader>}\n */\nconst readers: { [type: string]: Reader } = {\n array(value: string): unknown[] {\n const array = parseJSON<unknown[]>(value);\n if (!Array.isArray(array)) {\n throw new TypeError(`Expected an array but got a value of type \"${typeof array}\"`);\n }\n return array;\n },\n\n boolean(value: string): boolean {\n return !(value === '0' || String(value).toLowerCase() === 'false');\n },\n\n number(value: string): number {\n const number = Number(value.replace(/_/g, ''));\n return number;\n },\n\n object(value: string): object {\n const object = JSON.parse(value);\n if (object === null || typeof object !== 'object' || Array.isArray(object)) {\n throw new TypeError(\n `expected value of type \"object\" but instead got value \"${value}\" of type \"${parseAttributeTypeDefault(\n object,\n )}\"`,\n );\n }\n return object;\n },\n\n string(value: string): string {\n return value;\n },\n};\n\ntype Writer = (value: unknown) => string;\n\n/**\n * Object that maps attribute types to writer functions.\n * @type {Object.<string, Writer>}\n */\nconst writers: { [type: string]: Writer } = {\n default: writeString,\n array: writeJSON,\n object: writeJSON,\n};\n\nfunction writeJSON(value: unknown) {\n return JSON.stringify(value);\n}\n\nfunction writeString(value: unknown) {\n return `${value}`;\n}\n\n/**\n * Reads the attribute value based on the provided type.\n * @param value - The attribute value to be read.\n * @param type - The type of the attribute.\n * @returns The parsed attribute value.\n * @throws {TypeError} If the provided type is unknown.\n */\nexport function readAttributeValue(value: string, type: AttributeTypeConstant) {\n const readerType = parseAttributeTypeConstant(type);\n if (!readerType) throw new TypeError(`[radiant-element] Unknown type \"${type}\"`);\n return readers[readerType](value);\n}\n\nexport type ReadAttributeValueReturnType = ReturnType<typeof readAttributeValue>;\n\n/**\n * Writes the attribute value based on the provided type.\n *\n * @param value - The value to be written.\n * @param type - The type of the attribute.\n * @returns The written attribute value.\n * @throws {TypeError} If the provided type is unknown.\n */\nexport function writeAttributeValue(value: unknown, type: AttributeTypeConstant) {\n const writerType = parseAttributeTypeConstant(type);\n if (!writerType) throw new TypeError(`[radiant-element] Unknown type \"${type}\"`);\n return (writers[writerType] || writers.default)(value);\n}\n\nexport type WriteAttributeValueReturnType = ReturnType<typeof writeAttributeValue>;\n\n/*\n * Type guard functions for each type in AttributeTypeConstant\n */\nfunction isBoolean(value: unknown): value is boolean {\n return typeof value === 'boolean';\n}\n\nfunction isNumber(value: unknown): value is number {\n return typeof value === 'number';\n}\n\nfunction isString(value: unknown): value is string {\n return typeof value === 'string';\n}\n\nfunction isArray(value: unknown): value is Array<unknown> {\n return Array.isArray(value);\n}\n\nfunction isObject(value: unknown): value is object {\n return typeof value === 'object' && !Array.isArray(value) && value !== null;\n}\n\n/*\n * Check function to ensure defaultValue matches the type\n */\nexport function isValueOfType(type: AttributeTypeConstant, defaultValue: unknown): boolean {\n switch (type) {\n case Boolean:\n return isBoolean(defaultValue);\n case Number:\n return isNumber(defaultValue);\n case String:\n return isString(defaultValue);\n case Array:\n return isArray(defaultValue);\n case Object:\n return isObject(defaultValue);\n default:\n return false;\n }\n}\n"
6
6
  ],
7
- "mappings": "AAUO,SAAS,CAA0B,CAAC,EAAkC,CAC3E,OAAQ,QACD,MACH,MAAO,aACJ,QACH,MAAO,eACJ,OACH,MAAO,cACJ,OACH,MAAO,cACJ,OACH,MAAO,UAUN,SAAS,CAAyB,CAAC,EAAqC,CAC7E,cAAe,OACR,UACH,MAAO,cACJ,SACH,MAAO,aACJ,SACH,MAAO,SAGX,GAAI,MAAM,QAAQ,CAAY,EAAG,MAAO,QACxC,GAAI,OAAO,UAAU,SAAS,KAAK,CAAY,IAAM,kBAAmB,MAAO,SAS1E,SAAS,CAAmB,CAAC,EAAsC,CACxE,OAAQ,QACD,OACH,MAAO,QACJ,OACH,MAAO,QACJ,QACH,MAAO,WAEP,OAAO,MASb,IAAS,UAAY,CAAC,EAAkB,CACtC,GAAI,CACF,OAAO,KAAK,MAAM,CAAK,QAChB,EAAP,CACA,MAAM,IAAI,UAAU,qBAAqB,IAuDpC,UAAS,CAAC,EAAgB,CACjC,OAAO,KAAK,UAAU,CAAK,GAGpB,UAAW,CAAC,EAAgB,CACnC,MAAO,GAAG,KAUL,SAAS,CAAkB,CAAC,EAAe,EAA6B,CAC7E,MAAM,EAAa,EAA2B,CAAI,EAClD,IAAK,EAAY,MAAM,IAAI,UAAU,mCAAmC,IAAO,EAC/E,OAAO,EAAQ,GAAY,CAAK,EAW3B,SAAS,CAAmB,CAAC,EAAgB,EAA6B,CAC/E,MAAM,EAAa,EAA2B,CAAI,EAClD,IAAK,EAAY,MAAM,IAAI,UAAU,mCAAmC,IAAO,EAC/E,OAAQ,EAAQ,IAAe,EAAQ,SAAS,CAAK,EAMvD,IAAS,UAAS,CAAC,EAAkC,CACnD,cAAc,IAAU,WAGjB,UAAQ,CAAC,E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