@ecopages/radiant 0.1.2 → 0.1.4

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 (53) hide show
  1. package/dist/context/context-provider.js +3 -3
  2. package/dist/context/context-provider.js.map +2 -2
  3. package/dist/context/create-context.js +2 -2
  4. package/dist/context/create-context.js.map +1 -1
  5. package/dist/context/decorators/consume-context.js +3 -3
  6. package/dist/context/decorators/consume-context.js.map +1 -1
  7. package/dist/context/decorators/context-selector.js +3 -3
  8. package/dist/context/decorators/context-selector.js.map +1 -1
  9. package/dist/context/decorators/provide-context.js +3 -3
  10. package/dist/context/decorators/provide-context.js.map +2 -2
  11. package/dist/context/events.js +2 -2
  12. package/dist/context/events.js.map +1 -1
  13. package/dist/context/index.js +2 -2
  14. package/dist/context/index.js.map +1 -1
  15. package/dist/core/index.js +2 -2
  16. package/dist/core/index.js.map +1 -1
  17. package/dist/core/radiant-element.js +2 -2
  18. package/dist/core/radiant-element.js.map +1 -1
  19. package/dist/decorators/custom-element.js +2 -2
  20. package/dist/decorators/custom-element.js.map +1 -1
  21. package/dist/decorators/event.js +3 -3
  22. package/dist/decorators/event.js.map +1 -1
  23. package/dist/decorators/on-event.js +2 -2
  24. package/dist/decorators/on-event.js.map +1 -1
  25. package/dist/decorators/on-updated.js +2 -2
  26. package/dist/decorators/on-updated.js.map +1 -1
  27. package/dist/decorators/query.js +2 -2
  28. package/dist/decorators/query.js.map +1 -1
  29. package/dist/decorators/reactive-field.js +2 -2
  30. package/dist/decorators/reactive-field.js.map +1 -1
  31. package/dist/decorators/reactive-prop.d.ts +4 -2
  32. package/dist/decorators/reactive-prop.js +3 -3
  33. package/dist/decorators/reactive-prop.js.map +3 -3
  34. package/dist/decorators.js +2 -2
  35. package/dist/decorators.js.map +1 -1
  36. package/dist/index.js +2 -2
  37. package/dist/index.js.map +1 -1
  38. package/dist/mixins/index.js +2 -2
  39. package/dist/mixins/index.js.map +1 -1
  40. package/dist/mixins/with-kita.js +2 -2
  41. package/dist/mixins/with-kita.js.map +1 -1
  42. package/dist/tools/event-emitter.js +2 -2
  43. package/dist/tools/event-emitter.js.map +1 -1
  44. package/dist/tools/index.js +2 -2
  45. package/dist/tools/index.js.map +1 -1
  46. package/dist/tools/stringify-attribute.js +2 -2
  47. package/dist/tools/stringify-attribute.js.map +1 -1
  48. package/dist/utils/attribute-utils.d.ts +1 -0
  49. package/dist/utils/attribute-utils.js +3 -3
  50. package/dist/utils/attribute-utils.js.map +3 -3
  51. package/dist/utils/index.js +2 -2
  52. package/dist/utils/index.js.map +1 -1
  53. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- import{d as L} from"../utils/attribute-utils.js";import{k as J} from"./events.js";var K="hydrate-context";class Q{host;context;value;subscriptions=[];constructor(j,q){this.host=j,this.context=q.context;let z=q.initialValue;if(q.hydrate){const G=this.host.getAttribute(K);if(G){const F=L(G,q.hydrate);if(this.host.removeAttribute(K),q.hydrate===Object&&this.isObject(F)&&(this.isObject(z)||typeof z==="undefined"))z={...z??{},...F};else z=F}}this.value=z,this.registerEvents(),this.host.dispatchEvent(new J(this.context))}setContext=(j,q)=>{if(typeof this.value==="object"){const z={...this.value};if(this.value={...this.value,...j},q)q(this.value);this.notifySubscribers(this.value,z)}};getContext=()=>{return this.value};subscribe=({select:j,callback:q})=>{this.subscriptions.push({select:j,callback:q})};isObject(j){return typeof j==="object"&&!Array.isArray(j)&&j!==null}notifySubscribers=(j,q)=>{for(let z of this.subscriptions){if(!z.select)return this.sendSubscriptionUpdate(z,j);const G=z.select(j),F=z.select(q);if(G!==F)this.sendSubscriptionUpdate(z,j)}};sendSubscriptionUpdate=({select:j,callback:q},z)=>{if(!j)q(z);else q(j(z))};handleSubscriptionRequest=({select:j,callback:q,subscribe:z})=>{if(z)this.subscribe({select:j,callback:q});if(!this.value)return;if(j)q(j(this.value));else q(this.value)};onSubscriptionRequest=(j)=>{const{context:q,callback:z,subscribe:G,select:F,target:N}=j;if(q!==this.context)return;j.stopPropagation(),N.dispatchEvent(new J(this.context)),this.handleSubscriptionRequest({select:F,callback:z,subscribe:G})};onContextRequest=(j)=>{const{context:q,callback:z}=j;if(q!==this.context)return;j.stopPropagation(),z(this)};registerEvents=()=>{this.host.addEventListener("context--subscription-request",this.onSubscriptionRequest),this.host.addEventListener("context-request",this.onContextRequest)}}export{K as HYDRATE_ATTRIBUTE,Q as ContextProvider};
2
- export{K as f,Q as g};
1
+ import{g as J} from"./events.js";import{p as L} from"../utils/attribute-utils.js";var K="hydrate-context";class Q{host;context;value;subscriptions=[];constructor(j,q){this.host=j,this.context=q.context;let z=q.initialValue;if(q.hydrate){const G=this.host.getAttribute(K);if(G){const F=L(G,q.hydrate);if(this.host.removeAttribute(K),q.hydrate===Object&&this.isObject(F)&&(this.isObject(z)||typeof z==="undefined"))z={...z??{},...F};else z=F}}this.value=z,this.registerEvents(),this.host.dispatchEvent(new J(this.context))}setContext=(j,q)=>{if(typeof this.value==="object"){const z={...this.value};if(this.value={...this.value,...j},q)q(this.value);this.notifySubscribers(this.value,z)}};getContext=()=>{return this.value};subscribe=({select:j,callback:q})=>{this.subscriptions.push({select:j,callback:q})};isObject(j){return typeof j==="object"&&!Array.isArray(j)&&j!==null}notifySubscribers=(j,q)=>{for(let z of this.subscriptions){if(!z.select)return this.sendSubscriptionUpdate(z,j);const G=z.select(j),F=z.select(q);if(G!==F)this.sendSubscriptionUpdate(z,j)}};sendSubscriptionUpdate=({select:j,callback:q},z)=>{if(!j)q(z);else q(j(z))};handleSubscriptionRequest=({select:j,callback:q,subscribe:z})=>{if(z)this.subscribe({select:j,callback:q});if(!this.value)return;if(j)q(j(this.value));else q(this.value)};onSubscriptionRequest=(j)=>{const{context:q,callback:z,subscribe:G,select:F,target:N}=j;if(q!==this.context)return;j.stopPropagation(),N.dispatchEvent(new J(this.context)),this.handleSubscriptionRequest({select:F,callback:z,subscribe:G})};onContextRequest=(j)=>{const{context:q,callback:z}=j;if(q!==this.context)return;j.stopPropagation(),z(this)};registerEvents=()=>{this.host.addEventListener("context--subscription-request",this.onSubscriptionRequest),this.host.addEventListener("context-request",this.onContextRequest)}}export{K as HYDRATE_ATTRIBUTE,Q as ContextProvider};
2
+ export{K as c,Q as d};
3
3
 
4
- //# debugId=2AD23BF10A75A61164756E2164756E21
4
+ //# debugId=C115CC80C9941C9664756E2164756E21
@@ -4,7 +4,7 @@
4
4
  "sourcesContent": [
5
5
  "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"
6
6
  ],
7
- "mappings": "gGAiBO,VAAM,EAAoB,kBAkD1B,MAAM,CAAoF,CACvF,KACA,QACA,MACR,cAA0C,CAAC,EAQ3C,WAAW,CAAC,EAAsB,EAAoC,CACpE,KAAK,KAAO,EACZ,KAAK,QAAU,EAAQ,QACvB,IAAI,EAA6C,EAAQ,aAEzD,GAAI,EAAQ,QAAS,CACnB,MAAM,EAAiB,KAAK,KAAK,aAAa,CAAiB,EAE/D,GAAI,EAAgB,CAClB,MAAM,EAAuB,EAAmB,EAAgB,EAAQ,OAAO,EAG/E,GAFA,KAAK,KAAK,gBAAgB,CAAiB,EAGzC,EAAQ,UAAY,QACpB,KAAK,SAAS,CAAoB,IACjC,KAAK,SAAS,CAAY,UAAY,IAAiB,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  }
@@ -1,4 +1,4 @@
1
1
  var g=(d)=>d;export{g as createContext};
2
- export{g as h};
2
+ export{g as b};
3
3
 
4
- //# debugId=F7C0EC0BD65C3BFD64756E2164756E21
4
+ //# debugId=800AAE5BBB0FEE2964756E2164756E21
@@ -5,6 +5,6 @@
5
5
  "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"
6
6
  ],
7
7
  "mappings": "AAKO,IAAM,EAAgB,CAAY,IAAiB",
8
- "debugId": "F7C0EC0BD65C3BFD64756E2164756E21",
8
+ "debugId": "800AAE5BBB0FEE2964756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -1,4 +1,4 @@
1
- import{j as w} from"../events.js";function G(f){return(j,z)=>{const B=j.connectedCallback;j.connectedCallback=function(){B.call(this),this.dispatchEvent(new w(f,(D)=>{this[z]=D,this.connectedContextCallback(f)}))}}}export{G as consumeContext};
2
- export{G as o};
1
+ import{f as w} from"../events.js";function G(f){return(j,z)=>{const B=j.connectedCallback;j.connectedCallback=function(){B.call(this),this.dispatchEvent(new w(f,(D)=>{this[z]=D,this.connectedContextCallback(f)}))}}}export{G as consumeContext};
2
+ export{G as i};
3
3
 
4
- //# debugId=C681EE82BDCE370564756E2164756E21
4
+ //# debugId=82A68DC7919F5E1E64756E2164756E21
@@ -5,6 +5,6 @@
5
5
  "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"
6
6
  ],
7
7
  "mappings": "kCASO,SAAS,CAAc,CAAC,EAAkC,CAC/D,MAAO,CAAC,EAAuB,IAAwB,CACrD,MAAM,EAA4B,EAAM,kBAExC,EAAM,0BAA6B,EAAuB,CACxD,EAA0B,KAAK,IAAI,EACnC,KAAK,cACH,IAAI,EAAoB,EAAkB,CAAC,IAAY,CACrD,AAAC,KAAa,GAAe,EAC7B,KAAK,yBAAyB,CAAgB,EAC/C,CACH",
8
- "debugId": "C681EE82BDCE370564756E2164756E21",
8
+ "debugId": "82A68DC7919F5E1E64756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -1,4 +1,4 @@
1
- import{l as B} from"../events.js";function P({context:D,select:F,subscribe:G=!0}){return(y,K,j)=>{const z=j.value,H=y.connectedCallback;return y.connectedCallback=function(){H.call(this),this.dispatchEvent(new B(D,z.bind(this),F,G))},j.value=function(...J){return z.apply(this,J)},j}}export{P as contextSelector};
2
- export{P as n};
1
+ import{h as B} from"../events.js";function P({context:D,select:F,subscribe:G=!0}){return(y,K,j)=>{const z=j.value,H=y.connectedCallback;return y.connectedCallback=function(){H.call(this),this.dispatchEvent(new B(D,z.bind(this),F,G))},j.value=function(...J){return z.apply(this,J)},j}}export{P as contextSelector};
2
+ export{P as j};
3
3
 
4
- //# debugId=B06567375704CE8764756E2164756E21
4
+ //# debugId=0A6A8D4690A9C48664756E2164756E21
@@ -5,6 +5,6 @@
5
5
  "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\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"
6
6
  ],
7
7
  "mappings": "kCAoBO,SAAS,CAAoD,EAClE,UACA,SACA,YAAY,IACmB,CAC/B,MAAO,CAAC,EAAuB,EAAW,IAAmC,CAC3E,MAAM,EAAiB,EAAW,MAC5B,EAA4B,EAAM,kBAaxC,OAXA,EAAM,0BAA6B,EAAuB,CACxD,EAA0B,KAAK,IAAI,EAEnC,KAAK,cAAc,IAAI,EAAgC,EAAS,EAAe,KAAK,IAAI,EAAG,EAAQ,CAAS,CAAC,GAG/G,EAAW,cAAiB,IAAI,EAAqB,CAEnD,OADe,EAAe,MAAM,KAAM,CAAI,GAIzC",
8
- "debugId": "B06567375704CE8764756E2164756E21",
8
+ "debugId": "0A6A8D4690A9C48664756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -1,4 +1,4 @@
1
- import"../../utils/attribute-utils.js";import{g as q} from"../context-provider.js";import"../events.js";function F({context:f,initialValue:w,hydrate:z}){return(j,B)=>{const D=j.connectedCallback;j.connectedCallback=function(){D.call(this),this[B]=new q(this,{context:f,initialValue:w,hydrate:z}),this.connectedContextCallback(f)}}}export{F as provideContext};
2
- export{F as m};
1
+ import{d as q} from"../context-provider.js";import"../events.js";import"../../utils/attribute-utils.js";function F({context:f,initialValue:w,hydrate:z}){return(j,B)=>{const D=j.connectedCallback;j.connectedCallback=function(){D.call(this),this[B]=new q(this,{context:f,initialValue:w,hydrate:z}),this.connectedContextCallback(f)}}}export{F as provideContext};
2
+ export{F as l};
3
3
 
4
- //# debugId=D205F608AED8A9A264756E2164756E21
4
+ //# debugId=5BB8FB961896EBF564756E2164756E21
@@ -4,7 +4,7 @@
4
4
  "sourcesContent": [
5
5
  "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"
6
6
  ],
7
- "mappings": "wHAgBO,MAAS,ZAAwC,EAAG,UAAS,eAAc,WAAoC,CACpH,MAAO,CAAC,EAAuB,IAAwB,CACrD,MAAM,EAA4B,EAAM,kBAExC,EAAM,0BAA6B,EAAuB,CACxD,EAA0B,KAAK,IAAI,EAClC,KAAa,GAAe,IAAI,EAAmB,KAAM,CAAE,UAAS,eAAc,SAAQ,CAAC,EAC5F,KAAK,yBAAyB,CAAO",
8
- "debugId": "D205F608AED8A9A264756E2164756E21",
7
+ "mappings": "gHAgBO,JAAS,MAAwC,EAAG,UAAS,eAAc,WAAoC,CACpH,MAAO,CAAC,EAAuB,IAAwB,CACrD,MAAM,EAA4B,EAAM,kBAExC,EAAM,0BAA6B,EAAuB,CACxD,EAA0B,KAAK,IAAI,EAClC,KAAa,GAAe,IAAI,EAAmB,KAAM,CAAE,UAAS,eAAc,SAAQ,CAAC,EAC5F,KAAK,yBAAyB,CAAO",
8
+ "debugId": "5BB8FB961896EBF564756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -1,4 +1,4 @@
1
1
  var z;((j)=>{j.SUBSCRIPTION_REQUEST="context--subscription-request";j.CONTEXT_REQUEST="context-request";j.ON_MOUNT="context--on-mount"})(z||={});class B extends Event{k;q;w;constructor(k,q,w){super("context-request",{bubbles:!0,composed:!0});this.context=k;this.callback=q;this.subscribe=w}}class D extends CustomEvent{constructor(k){super("context--on-mount",{detail:{context:k},bubbles:!0,composed:!0})}}class F extends Event{k;q;w;j;constructor(k,q,w,j){super("context--subscription-request",{bubbles:!0,composed:!0});this.context=k;this.callback=q;this.select=w;this.subscribe=j}}export{F as ContextSubscriptionRequestEvent,B as ContextRequestEvent,D as ContextOnMountEvent,z as ContextEventsTypes};
2
- export{z as i,B as j,D as k,F as l};
2
+ export{z as e,B as f,D as g,F as h};
3
3
 
4
- //# debugId=C10C928A007AAB2F64756E2164756E21
4
+ //# debugId=26827734C42A2FB664756E2164756E21
@@ -5,6 +5,6 @@
5
5
  "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"
6
6
  ],
7
7
  "mappings": "AAKO,IAAK,EAAL,EAAK,IAAL,CACL,uBAAuB,gCACvB,kBAAkB,kBAClB,WAAW,sBAHD,QAgBL,MAAM,UAAsD,KAAM,CAErD,EACA,EACA,EAHX,WAAW,CACA,EACA,EACA,EAChB,CACA,MAAM,kBAAoC,CAAE,QAAS,GAAM,SAAU,EAAK,CAAC,EAJ3D,eACA,gBACA,iBAIpB,CAaO,MAAM,UAA4B,WAAyC,CACzE,WAAW,CAAC,EAAyB,CAC1C,MAAM,oBAA6B,CACjC,OAAQ,CAAE,SAAQ,EAClB,QAAS,GACT,SAAU,EACZ,CAAC,EAEL,CAcO,MAAM,UAAkE,KAAM,CAEjE,EACA,EACA,EACA,EAJX,WAAW,CACA,EACA,EACA,EACA,EAChB,CACA,MAAM,gCAAyC,CAC7C,QAAS,GACT,SAAU,EACZ,CAAC,EARe,eACA,gBACA,cACA,iBAOpB",
8
- "debugId": "C10C928A007AAB2F64756E2164756E21",
8
+ "debugId": "26827734C42A2FB664756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -1,3 +1,3 @@
1
- import"./types.js";import"../utils/attribute-utils.js";import{f as h,g as i} from"./context-provider.js";import{h as a} from"./create-context.js";import{i as b,j as c,k as d,l as g} from"./events.js";import{m as j} from"./decorators/provide-context.js";import{n as l} from"./decorators/context-selector.js";import{o as k} from"./decorators/consume-context.js";export{j as provideContext,a as createContext,l as contextSelector,k as consumeContext,h as HYDRATE_ATTRIBUTE,g as ContextSubscriptionRequestEvent,c as ContextRequestEvent,i as ContextProvider,d as ContextOnMountEvent,b as ContextEventsTypes};
1
+ import{b as a} from"./create-context.js";import{c as h,d as i} from"./context-provider.js";import"./types.js";import{e as b,f as c,g as d,h as g} from"./events.js";import{i as k} from"./decorators/consume-context.js";import{j as l} from"./decorators/context-selector.js";import{l as j} from"./decorators/provide-context.js";import"../utils/attribute-utils.js";export{j as provideContext,a as createContext,l as contextSelector,k as consumeContext,h as HYDRATE_ATTRIBUTE,g as ContextSubscriptionRequestEvent,c as ContextRequestEvent,i as ContextProvider,d as ContextOnMountEvent,b as ContextEventsTypes};
2
2
 
3
- //# debugId=6C67363F0DF8480564756E2164756E21
3
+ //# debugId=DFE579B22F28188D64756E2164756E21
@@ -4,6 +4,6 @@
4
4
  "sourcesContent": [
5
5
  ],
6
6
  "mappings": "",
7
- "debugId": "6C67363F0DF8480564756E2164756E21",
7
+ "debugId": "DFE579B22F28188D64756E2164756E21",
8
8
  "names": []
9
9
  }
@@ -1,3 +1,3 @@
1
- import{x as e} from"./radiant-element.js";export{e as RadiantElement};
1
+ import{a as e} from"./radiant-element.js";export{e as RadiantElement};
2
2
 
3
- //# debugId=09C9024F4F713D5064756E2164756E21
3
+ //# debugId=4EBA3D653132A3AC64756E2164756E21
@@ -4,6 +4,6 @@
4
4
  "sourcesContent": [
5
5
  ],
6
6
  "mappings": "",
7
- "debugId": "09C9024F4F713D5064756E2164756E21",
7
+ "debugId": "4EBA3D653132A3AC64756E2164756E21",
8
8
  "names": []
9
9
  }
@@ -1,4 +1,4 @@
1
1
  class y extends HTMLElement{eventSubscriptions=new Map;connectedCallback(){}connectedContextCallback(j){}disconnectedCallback(){this.removeAllSubscribedEvents()}updated(j,k,q){}renderTemplate({target:j=this,template:k,insert:q="replace"}){switch(q){case"replace":j.innerHTML=k;break;case"beforeend":j.insertAdjacentHTML("beforeend",k);break;case"afterbegin":j.insertAdjacentHTML("afterbegin",k);break}}subscribeEvents(j){for(let k of j)this.subscribeEvent(k)}subscribeEvent(j){const k=(q)=>{if(q.target&&q.target.matches(j.selector))j.listener.call(this,q)};this.addEventListener(j.type,k,j.options),this.eventSubscriptions.set(j.id,{...j,listener:k})}unsubscribeEvent(j){const k=this.eventSubscriptions.get(j);if(k)this.removeEventListener(k.type,k.listener,k.options),this.eventSubscriptions.delete(j)}removeAllSubscribedEvents(){for(let j of this.eventSubscriptions.values())this.removeEventListener(j.type,j.listener,j.options);this.eventSubscriptions.clear()}}export{y as RadiantElement};
2
- export{y as x};
2
+ export{y as a};
3
3
 
4
- //# debugId=380A559854C1C25A64756E2164756E21
4
+ //# debugId=D8E10820383975BD64756E2164756E21
@@ -5,6 +5,6 @@
5
5
  "import type { UnknownContext } from '@/context/types';\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 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 private eventSubscriptions = new Map<string, RadiantElementEventListener>();\n\n connectedCallback() {}\n\n connectedContextCallback(_contextName: UnknownContext): void {}\n\n disconnectedCallback() {\n this.removeAllSubscribedEvents();\n }\n\n updated(_changedProperty: string, _oldValue: unknown, _value: unknown) {}\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"
6
6
  ],
7
7
  "mappings": "AA2EO,MAAM,UAAuB,WAAuC,CACjE,mBAAqB,IAAI,IAEjC,iBAAiB,EAAG,EAEpB,wBAAwB,CAAC,EAAoC,EAE7D,oBAAoB,EAAG,CACrB,KAAK,0BAA0B,EAGjC,OAAO,CAAC,EAA0B,EAAoB,EAAiB,EAEvE,cAAc,EACZ,SAAS,KACT,WACA,SAAS,WAKR,CACD,OAAQ,OACD,UACH,EAAO,UAAY,EACnB,UACG,YACH,EAAO,mBAAmB,YAAa,CAAQ,EAC/C,UACG,aACH,EAAO,mBAAmB,aAAc,CAAQ,EAChD,OAIC,eAAe,CAAC,EAA6C,CAClE,QAAW,KAAS,EAClB,KAAK,eAAe,CAAK,EAItB,cAAc,CAAC,EAAgD,CACpE,MAAM,EAAoB,CAAC,IAA0B,CACnD,GAAI,EAAe,QAAW,EAAe,OAAmB,QAAQ,EAAY,QAAQ,EAC1F,EAAY,SAAS,KAAK,KAAM,CAAc,GAIlD,KAAK,iBAAiB,EAAY,KAAM,EAAmB,EAAY,OAAO,EAC9E,KAAK,mBAAmB,IAAI,EAAY,GAAI,IAAK,EAAa,SAAU,CAAkB,CAAC,EAGtF,gBAAgB,CAAC,EAAkB,CACxC,MAAM,EAAoB,KAAK,mBAAmB,IAAI,CAAE,EACxD,GAAI,EACF,KAAK,oBAAoB,EAAkB,KAAM,EAAkB,SAAU,EAAkB,OAAO,EACtG,KAAK,mBAAmB,OAAO,CAAE,EAI9B,yBAAyB,EAAS,CACvC,QAAW,KAAqB,KAAK,mBAAmB,OAAO,EAC7D,KAAK,oBAAoB,EAAkB,KAAM,EAAkB,SAAU,EAAkB,OAAO,EAExG,KAAK,mBAAmB,MAAM,EAElC",
8
- "debugId": "380A559854C1C25A64756E2164756E21",
8
+ "debugId": "D8E10820383975BD64756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -1,4 +1,4 @@
1
1
  function n(e){return(t)=>{if(!globalThis.window)return;if(!window.customElements.get(e))window.customElements.define(e,t)}}export{n as customElement};
2
- export{n as v};
2
+ export{n as A};
3
3
 
4
- //# debugId=5553715EE2D28D9F64756E2164756E21
4
+ //# debugId=F0F3910DA44047E164756E2164756E21
@@ -5,6 +5,6 @@
5
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
6
  ],
7
7
  "mappings": "AAIO,SAAS,CAAa,CAAC,EAAc,CAC1C,MAAO,CAAC,IAAqC,CAC3C,IAAK,WAAW,OAAQ,OACxB,IAAK,OAAO,eAAe,IAAI,CAAI,EACjC,OAAO,eAAe,OAAO,EAAM,CAAM",
8
- "debugId": "5553715EE2D28D9F64756E2164756E21",
8
+ "debugId": "F0F3910DA44047E164756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -1,4 +1,4 @@
1
- import{z as F} from"../tools/event-emitter.js";function I(j){return(G,A)=>{if(!A)throw new Error("The propertyKey is missing for the event decorator.");if(!j||!j.name)throw new Error("Invalid eventConfig provided.");const z=Symbol(j.name);Object.defineProperty(G,A,{get(){const x=B.get(this)||new Map;if(!x.has(z))x.set(z,new F(this,j)),B.set(this,x);return x.get(z)}})}}var B=new WeakMap;export{I as event};
2
- export{I as q};
1
+ import{t as F} from"../tools/event-emitter.js";function I(j){return(G,A)=>{if(!A)throw new Error("The propertyKey is missing for the event decorator.");if(!j||!j.name)throw new Error("Invalid eventConfig provided.");const z=Symbol(j.name);Object.defineProperty(G,A,{get(){const x=B.get(this)||new Map;if(!x.has(z))x.set(z,new F(this,j)),B.set(this,x);return x.get(z)}})}}var B=new WeakMap;export{I as event};
2
+ export{I as v};
3
3
 
4
- //# debugId=E335B76426A3F14F64756E2164756E21
4
+ //# debugId=6896B80F0266D83964756E2164756E21
@@ -5,6 +5,6 @@
5
5
  "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"
6
6
  ],
7
7
  "mappings": "+CAUO,SAAS,CAAK,CAAC,EAAiC,CACrD,MAAO,CAAC,EAAa,IAAwB,CAC3C,IAAK,EACH,MAAM,IAAI,MAAM,qDAAqD,EAGvE,IAAK,IAAgB,EAAY,KAC/B,MAAM,IAAI,MAAM,+BAA+B,EAGjD,MAAM,EAAY,OAAO,EAAY,IAAI,EAEzC,OAAO,eAAe,EAAQ,EAAa,CACzC,GAAG,EAAG,CACJ,MAAM,EAAyC,EAAc,IAAI,IAAI,GAAK,IAAI,IAC9E,IAAK,EAAY,IAAI,CAAS,EAC5B,EAAY,IAAI,EAAW,IAAI,EAAa,KAAM,CAAW,CAAC,EAC9D,EAAc,IAAI,KAAM,CAAW,EAGrC,OAAO,EAAY,IAAI,CAAS,EAEpC,CAAC,GA9BL,IAAM,EAAgB,IAAI",
8
- "debugId": "E335B76426A3F14F64756E2164756E21",
8
+ "debugId": "6896B80F0266D83964756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -1,4 +1,4 @@
1
1
  function J(q){return(x,H,z)=>{const D=x.connectedCallback,B="selector"in q?q.selector:`[data-ref="${q.ref}"]`,E=z.value,G=`${q.type}-${B}`;return x.connectedCallback=function(){D.call(this),this.subscribeEvent({id:G,selector:B,type:q.type,listener:E.bind(this),options:q?.options??void 0})},z}}export{J as onEvent};
2
- export{J as t};
2
+ export{J as u};
3
3
 
4
- //# debugId=7C4195112A96444264756E2164756E21
4
+ //# debugId=496D63BE3AE2FFDF64756E2164756E21
@@ -5,6 +5,6 @@
5
5
  "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\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\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 originalConnectedCallback.call(this);\n\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\n return descriptor;\n };\n}\n"
6
6
  ],
7
7
  "mappings": "AA0BO,SAAS,CAAO,CAAC,EAA4B,CAClD,MAAO,CAAC,EAAuB,EAAW,IAAmC,CAC3E,MAAM,EAA4B,EAAM,kBAElC,EAAW,aAAc,EAAc,EAAY,SAAW,cAAc,EAAY,QAExF,EAAiB,EAAW,MAC5B,EAAiB,GAAG,EAAY,QAAQ,IAc9C,OAZA,EAAM,0BAA6B,EAAuB,CACxD,EAA0B,KAAK,IAAI,EAEnC,KAAK,eAAe,CAClB,GAAI,EACJ,SAAU,EACV,KAAM,EAAY,KAClB,SAAU,EAAe,KAAK,IAAI,EAClC,QAAS,GAAa,SAAW,MACnC,CAAC,GAGI",
8
- "debugId": "7C4195112A96444264756E2164756E21",
8
+ "debugId": "496D63BE3AE2FFDF64756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -1,4 +1,4 @@
1
1
  function F(j){return(z,D)=>{const B=z.updated;z.updated=function(E,q,x){if(q===x)return;if(E===j)B.call(this,j,q,x),this[D]();else B.call(this,j,q,x)}}}export{F as onUpdated};
2
- export{F as u};
2
+ export{F as x};
3
3
 
4
- //# debugId=83C62EF757FAD75A64756E2164756E21
4
+ //# debugId=AC42B268BAB39F4664756E2164756E21
@@ -5,6 +5,6 @@
5
5
  "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(key: string) {\n return (proto: RadiantElement, propName: string) => {\n const originalUpdated = proto.updated;\n proto.updated = function (changedProperty: string, oldValue: unknown, newValue: unknown) {\n if (oldValue === newValue) return;\n if (changedProperty === key) {\n originalUpdated.call(this, key, oldValue, newValue);\n (this as any)[propName]();\n } else {\n originalUpdated.call(this, key, oldValue, newValue);\n }\n };\n };\n}\n"
6
6
  ],
7
7
  "mappings": "AAMO,SAAS,CAAS,CAAC,EAAa,CACrC,MAAO,CAAC,EAAuB,IAAqB,CAClD,MAAM,EAAkB,EAAM,QAC9B,EAAM,gBAAmB,CAAC,EAAyB,EAAmB,EAAmB,CACvF,GAAI,IAAa,EAAU,OAC3B,GAAI,IAAoB,EACtB,EAAgB,KAAK,KAAM,EAAK,EAAU,CAAQ,EACjD,KAAa,GAAU,MAExB,GAAgB,KAAK,KAAM,EAAK,EAAU,CAAQ",
8
- "debugId": "83C62EF757FAD75A64756E2164756E21",
8
+ "debugId": "AC42B268BAB39F4664756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -1,4 +1,4 @@
1
1
  function Z({cache:G=!0,...z}){const I=new WeakMap;return(J,W)=>{const X=function(){if(G){const V=I.get(this);if(V!==void 0)return V}const P="selector"in z?z.selector:`[data-ref="${z.ref}"]`,U=z.all?this.querySelectorAll(P):this.querySelector(P);if(G)I.set(this,U);return U},Y=J.connectedCallback;J.connectedCallback=function(){Object.defineProperty(this,W,{get:X,enumerable:!0,configurable:!0}),Y?.call(this)}}}export{Z as query};
2
- export{Z as r};
2
+ export{Z as z};
3
3
 
4
- //# debugId=DA1551DD9026892F64756E2164756E21
4
+ //# debugId=80696C9E4955AA1964756E2164756E21
@@ -5,6 +5,6 @@
5
5
  "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({ cache: shouldBeCached = true, ...options }: QueryConfig) {\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 originalConnectedCallback?.call(this);\n };\n };\n}\n"
6
6
  ],
7
7
  "mappings": "AA4CO,SAAS,CAAK,EAAG,MAAO,EAAiB,MAAS,GAAwB,CAC/E,MAAM,EAAQ,IAAI,QAElB,MAAO,CAAC,EAAuB,IAAiC,CAC9D,MAAM,UAAmB,EAAgB,CACvC,GAAI,EAAgB,CAClB,MAAM,EAAe,EAAM,IAAI,IAAI,EACnC,GAAI,IAAiB,OACnB,OAAO,EAIX,MAAM,EAAW,aAAc,EAAU,EAAQ,SAAW,cAAc,EAAQ,QAC5E,EAAc,EAAQ,IAAM,KAAK,iBAAiB,CAAQ,EAAI,KAAK,cAAc,CAAQ,EAE/F,GAAI,EACF,EAAM,IAAI,KAAM,CAAW,EAG7B,OAAO,GAGH,EAA4B,EAAM,kBAExC,EAAM,0BAA6B,EAAuB,CACxD,OAAO,eAAe,KAAM,EAAa,CACvC,IAAK,EACL,WAAY,GACZ,aAAc,EAChB,CAAC,EACD,GAA2B,KAAK,IAAI",
8
- "debugId": "DA1551DD9026892F64756E2164756E21",
8
+ "debugId": "80696C9E4955AA1964756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -1,4 +1,4 @@
1
1
  function F(C,x){const j=new WeakMap,z=new WeakSet;Object.defineProperty(C,x,{get:function(){return j.get(this)},set:function(q){if(z.has(this)){const B=j.get(this);if(B!==q)j.set(this,q),this.updated(x,B,q)}else j.set(this,q),z.add(this)}})}export{F as reactiveField};
2
- export{F as s};
2
+ export{F as y};
3
3
 
4
- //# debugId=E25A78AC1BDA8ED264756E2164756E21
4
+ //# debugId=7041FB47FE0D07EA64756E2164756E21
@@ -5,6 +5,6 @@
5
5
  "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"
6
6
  ],
7
7
  "mappings": "AAUO,SAAS,CAAa,CAAC,EAAuB,EAAqB,CACxE,MAAM,EAAiB,IAAI,QACrB,EAAY,IAAI,QAEtB,OAAO,eAAe,EAAO,EAAa,CACxC,YAAc,EAAG,CACf,OAAO,EAAe,IAAI,IAAI,GAEhC,YAAc,CAAC,EAAmB,CAChC,GAAI,EAAU,IAAI,IAAI,EAAG,CACvB,MAAM,EAAW,EAAe,IAAI,IAAI,EACxC,GAAI,IAAa,EACf,EAAe,IAAI,KAAM,CAAQ,EACjC,KAAK,QAAQ,EAAa,EAAU,CAAQ,MAG9C,GAAe,IAAI,KAAM,CAAQ,EACjC,EAAU,IAAI,IAAI,EAGxB,CAAC",
8
- "debugId": "E25A78AC1BDA8ED264756E2164756E21",
8
+ "debugId": "7041FB47FE0D07EA64756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -1,9 +1,10 @@
1
1
  import type { RadiantElement } from '../core/radiant-element';
2
2
  import { type AttributeTypeConstant } from '../utils/attribute-utils';
3
- type ReactivePropertyOptions = {
3
+ type ReactivePropertyOptions<T> = {
4
4
  type: AttributeTypeConstant;
5
5
  reflect?: boolean;
6
6
  attribute?: string;
7
+ defaultValue?: T;
7
8
  };
8
9
  /**
9
10
  * A decorator to define a reactive property.
@@ -12,6 +13,7 @@ type ReactivePropertyOptions = {
12
13
  * @param options.type The type of the property value.
13
14
  * @param options.reflect Whether to reflect the property to the attribute.
14
15
  * @param options.attribute The name of the attribute.
16
+ * @param options.defaultValue The default value of the property.
15
17
  */
16
- export declare function reactiveProp({ type, attribute, reflect }: ReactivePropertyOptions): (proto: RadiantElement, propertyKey: string) => void;
18
+ export declare function reactiveProp<T = unknown>({ type, attribute, reflect, defaultValue }: ReactivePropertyOptions<T>): (proto: RadiantElement, propertyKey: string) => void;
17
19
  export {};
@@ -1,4 +1,4 @@
1
- import{c as H,d as I,e as J} from"../utils/attribute-utils.js";function O({type:B,attribute:L,reflect:M}){return(D,q)=>{const k=new WeakMap,C=`__${q}`,G=L??q;Object.defineProperty(D,C,{get:function(){if(!k.has(this)){const j=this.getAttribute(G)??H(B),z=I(j,B);k.set(this,z)}return k.get(this)},set:function(j){const z=k.get(this);if(z===j)return;if(k.set(this,j),M)this.setAttribute(G,J(j,B));this.updated(q,z,j)},enumerable:!0,configurable:!0}),Object.defineProperty(D,q,{get:function(){return this[C]},set:function(j){this[C]=j},enumerable:!0,configurable:!0})}}export{O as reactiveProp};
2
- export{O as w};
1
+ import{o as J,p as L,q as M,r as N} from"../utils/attribute-utils.js";function Y({type:k,attribute:Q,reflect:R,defaultValue:B}){if(B!==void 0&&!N(k,B))throw new Error(`defaultValue does not match the expected type for ${k.name}`);return(H,C)=>{const q=new WeakMap,D=`__${C}`,G=Q??C,S=(j)=>{if(k===Boolean)return j.hasAttribute(G)||B;const z=j.getAttribute(G);return z!==null?L(z,k):B||J(k)};Object.defineProperty(H,D,{get:function(){if(!q.has(this)){const j=S(this);q.set(this,j)}return q.get(this)},set:function(j){const z=q.get(this);if(z===j)return;if(q.set(this,j),R)this.setAttribute(G,M(j,k));this.updated(C,z,j)},enumerable:!0,configurable:!0}),Object.defineProperty(H,C,{get:function(){return this[D]},set:function(j){this[D]=j},enumerable:!0,configurable:!0})}}export{Y as reactiveProp};
2
+ export{Y as w};
3
3
 
4
- //# debugId=E37B640AAF8C9EAF64756E2164756E21
4
+ //# debugId=D94321FDF9DD649064756E2164756E21
@@ -2,9 +2,9 @@
2
2
  "version": 3,
3
3
  "sources": ["../src/decorators/reactive-prop.ts"],
4
4
  "sourcesContent": [
5
- "import type { RadiantElement } from '@/core/radiant-element';\nimport {\n type AttributeTypeConstant,\n defaultValueForType,\n readAttributeValue,\n writeAttributeValue,\n} from '@/utils/attribute-utils';\n\ntype ReactivePropertyOptions = {\n type: AttributeTypeConstant;\n reflect?: boolean;\n attribute?: string;\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 */\nexport function reactiveProp({ type, attribute, reflect }: ReactivePropertyOptions) {\n return (proto: RadiantElement, propertyKey: string) => {\n const originalValues = new WeakMap<WeakKey, unknown>();\n const prefixedPropertyKey = `__${propertyKey}`;\n const attributeKey = attribute ?? propertyKey;\n\n Object.defineProperty(proto, prefixedPropertyKey, {\n get: function () {\n if (!originalValues.has(this)) {\n const initialValue = this.getAttribute(attributeKey) ?? defaultValueForType(type);\n const value = readAttributeValue(initialValue, type);\n originalValues.set(this, value);\n }\n return originalValues.get(this);\n },\n set: function (newValue: string) {\n const oldValue = originalValues.get(this);\n if (oldValue === newValue) return;\n originalValues.set(this, newValue);\n if (reflect) this.setAttribute(attributeKey, writeAttributeValue(newValue, type));\n this.updated(propertyKey, oldValue, newValue);\n },\n enumerable: true,\n configurable: true,\n });\n\n Object.defineProperty(proto, propertyKey, {\n get: function () {\n return this[prefixedPropertyKey];\n },\n set: function (newValue: string) {\n this[prefixedPropertyKey] = newValue;\n },\n enumerable: true,\n configurable: true,\n });\n };\n}\n"
5
+ "import type { 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 (proto: RadiantElement, propertyKey: string) => {\n const originalValues = new WeakMap<WeakKey, unknown>();\n const prefixedPropertyKey = `__${propertyKey}`;\n const attributeKey = attribute ?? propertyKey;\n\n const getInitialValue = (context: RadiantElement) => {\n if (type === Boolean) {\n const hasAttribute = context.hasAttribute(attributeKey);\n return hasAttribute || defaultValue;\n }\n\n const attributeValue = context.getAttribute(attributeKey);\n return attributeValue !== null\n ? readAttributeValue(attributeValue, type)\n : defaultValue || defaultValueForType(type);\n };\n\n Object.defineProperty(proto, prefixedPropertyKey, {\n get: function () {\n if (!originalValues.has(this)) {\n const initialValue = getInitialValue(this);\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) this.setAttribute(attributeKey, writeAttributeValue(newValue, type));\n this.updated(propertyKey, oldValue, newValue);\n },\n enumerable: true,\n configurable: true,\n });\n\n Object.defineProperty(proto, propertyKey, {\n get: function () {\n return this[prefixedPropertyKey];\n },\n set: function (newValue: string) {\n this[prefixedPropertyKey] = newValue;\n },\n enumerable: true,\n configurable: true,\n });\n };\n}\n"
6
6
  ],
7
- "mappings": "+DAsBO,SAAS,CAAY,EAAG,OAAM,YAAW,WAAoC,CAClF,MAAO,CAAC,EAAuB,IAAwB,CACrD,MAAM,EAAiB,IAAI,QACrB,EAAsB,KAAK,IAC3B,EAAe,GAAa,EAElC,OAAO,eAAe,EAAO,EAAqB,CAChD,YAAc,EAAG,CACf,IAAK,EAAe,IAAI,IAAI,EAAG,CAC7B,MAAM,EAAe,KAAK,aAAa,CAAY,GAAK,EAAoB,CAAI,EAC1E,EAAQ,EAAmB,EAAc,CAAI,EACnD,EAAe,IAAI,KAAM,CAAK,EAEhC,OAAO,EAAe,IAAI,IAAI,GAEhC,YAAc,CAAC,EAAkB,CAC/B,MAAM,EAAW,EAAe,IAAI,IAAI,EACxC,GAAI,IAAa,EAAU,OAE3B,GADA,EAAe,IAAI,KAAM,CAAQ,EAC7B,EAAS,KAAK,aAAa,EAAc,EAAoB,EAAU,CAAI,CAAC,EAChF,KAAK,QAAQ,EAAa,EAAU,CAAQ,GAE9C,WAAY,GACZ,aAAc,EAChB,CAAC,EAED,OAAO,eAAe,EAAO,EAAa,CACxC,YAAc,EAAG,CACf,OAAO,KAAK,IAEd,YAAc,CAAC,EAAkB,CAC/B,KAAK,GAAuB,GAE9B,WAAY,GACZ,aAAc,EAChB,CAAC",
8
- "debugId": "E37B640AAF8C9EAF64756E2164756E21",
7
+ "mappings": "sEAyBO,SAAS,CAAyB,EAAG,OAAM,YAAW,UAAS,gBAA4C,CAChH,GAAI,IAAiB,SAAc,EAAc,EAAM,CAAY,EACjE,MAAM,IAAI,MAAM,qDAAqD,EAAK,MAAM,EAGlF,MAAO,CAAC,EAAuB,IAAwB,CACrD,MAAM,EAAiB,IAAI,QACrB,EAAsB,KAAK,IAC3B,EAAe,GAAa,EAE5B,EAAkB,CAAC,IAA4B,CACnD,GAAI,IAAS,QAEX,OADqB,EAAQ,aAAa,CAAY,GAC/B,EAGzB,MAAM,EAAiB,EAAQ,aAAa,CAAY,EACxD,OAAO,IAAmB,KACtB,EAAmB,EAAgB,CAAI,EACvC,GAAgB,EAAoB,CAAI,GAG9C,OAAO,eAAe,EAAO,EAAqB,CAChD,YAAc,EAAG,CACf,IAAK,EAAe,IAAI,IAAI,EAAG,CAC7B,MAAM,EAAe,EAAgB,IAAI,EACzC,EAAe,IAAI,KAAM,CAAY,EAEvC,OAAO,EAAe,IAAI,IAAI,GAEhC,YAAc,CAAC,EAAa,CAC1B,MAAM,EAAW,EAAe,IAAI,IAAI,EACxC,GAAI,IAAa,EAAU,OAE3B,GADA,EAAe,IAAI,KAAM,CAAQ,EAC7B,EAAS,KAAK,aAAa,EAAc,EAAoB,EAAU,CAAI,CAAC,EAChF,KAAK,QAAQ,EAAa,EAAU,CAAQ,GAE9C,WAAY,GACZ,aAAc,EAChB,CAAC,EAED,OAAO,eAAe,EAAO,EAAa,CACxC,YAAc,EAAG,CACf,OAAO,KAAK,IAEd,YAAc,CAAC,EAAkB,CAC/B,KAAK,GAAuB,GAE9B,WAAY,GACZ,aAAc,EAChB,CAAC",
8
+ "debugId": "D94321FDF9DD649064756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -1,3 +1,3 @@
1
- import"./utils/attribute-utils.js";import{q as b} from"./decorators/event.js";import{r as g} from"./decorators/query.js";import{s as i} from"./decorators/reactive-field.js";import{t as c} from"./decorators/on-event.js";import{u as d} from"./decorators/on-updated.js";import{v as a} from"./decorators/custom-element.js";import{w as h} from"./decorators/reactive-prop.js";import"./tools/event-emitter.js";export{h as reactiveProp,i as reactiveField,g as query,d as onUpdated,c as onEvent,b as event,a as customElement};
1
+ import"./utils/attribute-utils.js";import"./tools/event-emitter.js";import{u as c} from"./decorators/on-event.js";import{v as b} from"./decorators/event.js";import{w as h} from"./decorators/reactive-prop.js";import{x as d} from"./decorators/on-updated.js";import{y as i} from"./decorators/reactive-field.js";import{z as g} from"./decorators/query.js";import{A as a} from"./decorators/custom-element.js";export{h as reactiveProp,i as reactiveField,g as query,d as onUpdated,c as onEvent,b as event,a as customElement};
2
2
 
3
- //# debugId=62676F432361940564756E2164756E21
3
+ //# debugId=71830EA449072B8A64756E2164756E21
@@ -4,6 +4,6 @@
4
4
  "sourcesContent": [
5
5
  ],
6
6
  "mappings": "",
7
- "debugId": "62676F432361940564756E2164756E21",
7
+ "debugId": "71830EA449072B8A64756E2164756E21",
8
8
  "names": []
9
9
  }
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- import"./decorators.js";import"./utils/index.js";import"./context/types.js";import{a as h,b as i,c as j,d as k,e as l} from"./utils/attribute-utils.js";import"./context/index.js";import{f as A,g as B} from"./context/context-provider.js";import{h as u} from"./context/create-context.js";import{i as v,j as w,k as y,l as z} from"./context/events.js";import{m as C} from"./context/decorators/provide-context.js";import{n as E} from"./context/decorators/context-selector.js";import"./mixins/index.js";import{o as D} from"./context/decorators/consume-context.js";import{p as F} from"./mixins/with-kita.js";import{q as b} from"./decorators/event.js";import{r as g} from"./decorators/query.js";import{s as q} from"./decorators/reactive-field.js";import{t as c} from"./decorators/on-event.js";import{u as d} from"./decorators/on-updated.js";import{v as x} from"./decorators/custom-element.js";import"./core/index.js";import{w as n} from"./decorators/reactive-prop.js";import{x as s} from"./core/radiant-element.js";import"./tools/index.js";import{y as G} from"./tools/stringify-attribute.js";import{z as a} from"./tools/event-emitter.js";export{l as writeAttributeValue,G as stringifyAttribute,k as readAttributeValue,n as reactiveProp,q as reactiveField,g as query,C as provideContext,i as parseAttributeTypeDefault,h as parseAttributeTypeConstant,d as onUpdated,c as onEvent,b as event,j as defaultValueForType,x as customElement,u as createContext,E as contextSelector,D as consumeContext,F as WithKita,s as RadiantElement,A as HYDRATE_ATTRIBUTE,a as EventEmitter,z as ContextSubscriptionRequestEvent,w as ContextRequestEvent,B as ContextProvider,y as ContextOnMountEvent,v as ContextEventsTypes};
1
+ import"./decorators.js";import"./core/index.js";import{a as x} from"./core/radiant-element.js";import{b as v} from"./context/create-context.js";import"./context/index.js";import{c as B,d as C} from"./context/context-provider.js";import"./context/types.js";import{e as w,f as y,g as z,h as A} from"./context/events.js";import{i as E} from"./context/decorators/consume-context.js";import{j as F} from"./context/decorators/context-selector.js";import"./mixins/index.js";import{k as G} from"./mixins/with-kita.js";import{l as D} from"./context/decorators/provide-context.js";import"./utils/index.js";import{m as i,n as j,o as k,p as l,q as n,r as q} from"./utils/attribute-utils.js";import"./tools/index.js";import{s as H} from"./tools/stringify-attribute.js";import{t as b} from"./tools/event-emitter.js";import{u as d} from"./decorators/on-event.js";import{v as c} from"./decorators/event.js";import{w as s} from"./decorators/reactive-prop.js";import{x as g} from"./decorators/on-updated.js";import{y as u} from"./decorators/reactive-field.js";import{z as h} from"./decorators/query.js";import{A as a} from"./decorators/custom-element.js";export{n as writeAttributeValue,H as stringifyAttribute,l as readAttributeValue,s as reactiveProp,u as reactiveField,h as query,D as provideContext,j as parseAttributeTypeDefault,i as parseAttributeTypeConstant,g as onUpdated,d as onEvent,q as isValueOfType,c as event,k as defaultValueForType,a as customElement,v as createContext,F as contextSelector,E as consumeContext,G as WithKita,x as RadiantElement,B as HYDRATE_ATTRIBUTE,b as EventEmitter,A as ContextSubscriptionRequestEvent,y as ContextRequestEvent,C as ContextProvider,z as ContextOnMountEvent,w as ContextEventsTypes};
2
2
 
3
- //# debugId=88BA9A2F79C6FAA664756E2164756E21
3
+ //# debugId=02FD23EB472364E664756E2164756E21
package/dist/index.js.map CHANGED
@@ -4,6 +4,6 @@
4
4
  "sourcesContent": [
5
5
  ],
6
6
  "mappings": "",
7
- "debugId": "88BA9A2F79C6FAA664756E2164756E21",
7
+ "debugId": "02FD23EB472364E664756E2164756E21",
8
8
  "names": []
9
9
  }
@@ -1,3 +1,3 @@
1
- import{p as e} from"./with-kita.js";export{e as WithKita};
1
+ import{k as e} from"./with-kita.js";export{e as WithKita};
2
2
 
3
- //# debugId=83B3642F7CAD7AD664756E2164756E21
3
+ //# debugId=89A6CBB2FE15B6E364756E2164756E21
@@ -4,6 +4,6 @@
4
4
  "sourcesContent": [
5
5
  ],
6
6
  "mappings": "",
7
- "debugId": "83B3642F7CAD7AD664756E2164756E21",
7
+ "debugId": "89A6CBB2FE15B6E364756E2164756E21",
8
8
  "names": []
9
9
  }
@@ -1,4 +1,4 @@
1
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 p};
2
+ export{u as k};
3
3
 
4
- //# debugId=9CF9FBED31A26F7964756E2164756E21
4
+ //# debugId=4BC44856CCA3A8EF64756E2164756E21
@@ -5,6 +5,6 @@
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
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": "9CF9FBED31A26F7964756E2164756E21",
8
+ "debugId": "4BC44856CCA3A8EF64756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -1,4 +1,4 @@
1
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 z};
2
+ export{x as t};
3
3
 
4
- //# debugId=2A51D44F7E2A76D164756E2164756E21
4
+ //# debugId=EF7DCAF38E65FBE864756E2164756E21
@@ -5,6 +5,6 @@
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
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": "2A51D44F7E2A76D164756E2164756E21",
8
+ "debugId": "EF7DCAF38E65FBE864756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -1,3 +1,3 @@
1
- import{y as m} from"./stringify-attribute.js";import{z as f} from"./event-emitter.js";export{m as stringifyAttribute,f as EventEmitter};
1
+ import{s as m} from"./stringify-attribute.js";import{t as f} from"./event-emitter.js";export{m as stringifyAttribute,f as EventEmitter};
2
2
 
3
- //# debugId=AA69C8C1038FF46C64756E2164756E21
3
+ //# debugId=C6D6495E47CC38E164756E2164756E21
@@ -4,6 +4,6 @@
4
4
  "sourcesContent": [
5
5
  ],
6
6
  "mappings": "",
7
- "debugId": "AA69C8C1038FF46C64756E2164756E21",
7
+ "debugId": "C6D6495E47CC38E164756E2164756E21",
8
8
  "names": []
9
9
  }
@@ -1,4 +1,4 @@
1
1
  function t(e){return JSON.stringify(e)}export{t as stringifyAttribute};
2
- export{t as y};
2
+ export{t as s};
3
3
 
4
- //# debugId=D372CAE24874BD2564756E2164756E21
4
+ //# debugId=55E05DA77FB3A62364756E2164756E21
@@ -5,6 +5,6 @@
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
7
  "mappings": "AAUO,SAAS,CAAqB,CAAC,EAAa,CACjD,OAAO,KAAK,UAAU,CAAK",
8
- "debugId": "D372CAE24874BD2564756E2164756E21",
8
+ "debugId": "55E05DA77FB3A62364756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -38,3 +38,4 @@ export declare function readAttributeValue(value: string, type: AttributeTypeCon
38
38
  * @throws {TypeError} If the provided type is unknown.
39
39
  */
40
40
  export declare function writeAttributeValue(value: unknown, type: AttributeTypeConstant): string;
41
+ export declare function isValueOfType(type: AttributeTypeConstant, defaultValue: unknown): boolean;
@@ -1,4 +1,4 @@
1
- function H(q){switch(q){case Array:return"array";case Boolean:return"boolean";case Number:return"number";case Object:return"object";case String:return"string"}}function B(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 M(q){switch(q){case Number:return 0;case String:return"";case Boolean:return!1;default:return null}}var G=function(q){return JSON.stringify(q)},L=function(q){return`${q}`};function P(q,x){const z=H(x);if(!z)throw new TypeError(`[radiant-element] Unknown type "${x}"`);return K[z](q)}function Q(q,x){const z=H(x);if(!z)throw new TypeError(`[radiant-element] Unknown type "${x}"`);return(F[z]||F.default)(q)}var K={array(q){const x=JSON.parse(q);if(!Array.isArray(x))throw new TypeError(`expected value of type "array" but instead got value "${q}" of type "${B(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 "${B(x)}"`);return x},string(q){return q}},F={default:L,array:G,object:G};export{Q as writeAttributeValue,P as readAttributeValue,B as parseAttributeTypeDefault,H as parseAttributeTypeConstant,M as defaultValueForType};
2
- export{H as a,B as b,M as c,P as d,Q as e};
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};
3
3
 
4
- //# debugId=CBA306F898870D1D64756E2164756E21
4
+ //# debugId=C41935C36D4A3CF764756E2164756E21
@@ -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 * Object containing various reader functions for parsing attribute values.\n */\nconst readers: { [type: string]: Reader } = {\n array(value: string): unknown[] {\n const array = JSON.parse(value);\n if (!Array.isArray(array)) {\n throw new TypeError(\n `expected value of type \"array\" but instead got value \"${value}\" of type \"${parseAttributeTypeDefault(array)}\"`,\n );\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 return Number(value.replace(/_/g, ''));\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"
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"
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,M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c,IAAU,UAGjB,UAAO,CAAC,EAAyC,CACxD,OAAO,MAAM,QAAQ,CAAK,GAGnB,UAAQ,CAAC,EAAiC,CACjD,cAAc,IAAU,WAAa,MAAM,QAAQ,CAAK,GAAK,IAAU,MAMlE,SAAS,CAAa,CAAC,EAA6B,EAAgC,CACzF,OAAQ,QACD,QACH,OAAO,EAAU,CAAY,OAC1B,OACH,OAAO,EAAS,CAAY,OACzB,OACH,OAAO,EAAS,CAAY,OACzB,MACH,OAAO,EAAQ,CAAY,OACxB,OACH,OAAO,EAAS,CAAY,UAE5B,MAAO,IAzHb,IAAM,EAAsC,CAC1C,KAAK,CAAC,EAA0B,CAC9B,MAAM,EAAQ,EAAqB,CAAK,EACxC,IAAK,MAAM,QAAQ,CAAK,EACtB,MAAM,IAAI,UAAU,qDAAqD,IAAQ,EAEnF,OAAO,GAGT,OAAO,CAAC,EAAwB,CAC9B,QAAS,IAAU,KAAO,OAAO,CAAK,EAAE,YAAY,IAAM,UAG5D,MAAM,CAAC,EAAuB,CAE5B,OADe,OAAO,EAAM,QAAQ,KAAM,EAAE,CAAC,GAI/C,MAAM,CAAC,EAAuB,CAC5B,MAAM,EAAS,KAAK,MAAM,CAAK,EAC/B,GAAI,IAAW,aAAe,IAAW,UAAY,MAAM,QAAQ,CAAM,EACvE,MAAM,IAAI,UACR,0DAA0D,eAAmB,EAC3E,CACF,IACF,EAEF,OAAO,GAGT,MAAM,CAAC,EAAuB,CAC5B,OAAO,EAEX,EAQM,EAAsC,CAC1C,QAAS,EACT,MAAO,EACP,OAAQ,CACV",
8
+ "debugId": "C41935C36D4A3CF764756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -1,3 +1,3 @@
1
- import{a as e,b as f,c as m,d as p,e as t} from"./attribute-utils.js";export{t as writeAttributeValue,p as readAttributeValue,f as parseAttributeTypeDefault,e as parseAttributeTypeConstant,m as defaultValueForType};
1
+ import{m as e,n as f,o as m,p,q as t,r as x} from"./attribute-utils.js";export{t as writeAttributeValue,p as readAttributeValue,f as parseAttributeTypeDefault,e as parseAttributeTypeConstant,x as isValueOfType,m as defaultValueForType};
2
2
 
3
- //# debugId=935141D5A098762464756E2164756E21
3
+ //# debugId=4C515B2ECFF4666864756E2164756E21
@@ -4,6 +4,6 @@
4
4
  "sourcesContent": [
5
5
  ],
6
6
  "mappings": "",
7
- "debugId": "935141D5A098762464756E2164756E21",
7
+ "debugId": "4C515B2ECFF4666864756E2164756E21",
8
8
  "names": []
9
9
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ecopages/radiant",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/ecopages/radiant.git"