@ecopages/radiant 0.1.1 → 0.1.3

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 (51) 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.d.ts +2 -16
  22. package/dist/decorators/event.js +3 -3
  23. package/dist/decorators/event.js.map +3 -3
  24. package/dist/decorators/on-updated.js +2 -2
  25. package/dist/decorators/on-updated.js.map +1 -1
  26. package/dist/decorators/query.js +2 -2
  27. package/dist/decorators/query.js.map +1 -1
  28. package/dist/decorators/reactive-field.js +2 -2
  29. package/dist/decorators/reactive-field.js.map +1 -1
  30. package/dist/decorators/reactive-prop.d.ts +3 -1
  31. package/dist/decorators/reactive-prop.js +3 -3
  32. package/dist/decorators/reactive-prop.js.map +3 -3
  33. package/dist/decorators.js +2 -2
  34. package/dist/decorators.js.map +1 -1
  35. package/dist/index.js +2 -2
  36. package/dist/index.js.map +1 -1
  37. package/dist/mixins/index.js +2 -2
  38. package/dist/mixins/index.js.map +1 -1
  39. package/dist/mixins/with-kita.js +2 -2
  40. package/dist/mixins/with-kita.js.map +1 -1
  41. package/dist/tools/event-emitter.js +2 -2
  42. package/dist/tools/event-emitter.js.map +1 -1
  43. package/dist/tools/index.js +2 -2
  44. package/dist/tools/index.js.map +1 -1
  45. package/dist/tools/stringify-attribute.js +2 -2
  46. package/dist/tools/stringify-attribute.js.map +1 -1
  47. package/dist/utils/attribute-utils.js +3 -3
  48. package/dist/utils/attribute-utils.js.map +3 -3
  49. package/dist/utils/index.js +2 -2
  50. package/dist/utils/index.js.map +1 -1
  51. 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,aAExD,EAAe,IACT,GAAgB,CAAC,KAClB,CACL,MAEA,GAAe,GAKrB,KA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
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 z};
3
3
 
4
- //# debugId=5553715EE2D28D9F64756E2164756E21
4
+ //# debugId=5805D55A877771B664756E2164756E21
@@ -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": "5805D55A877771B664756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -1,22 +1,8 @@
1
1
  import { type EventEmitterConfig } from '../tools/event-emitter';
2
2
  /**
3
- * A decorator that creates an EventEmitter on the target element.
3
+ * Decorator that attaches an EventEmitter to the class field property.
4
4
  * The EventEmitter can be used to dispatch custom events from the target element.
5
- *
6
- * @param {EventEmitterConfig} eventConfig - The configuration for the EventEmitter.
7
- * This includes the event type, and optionally, whether the event should bubble and whether it should be composed.
8
- *
9
- * @returns {EventEmitter} - An EventEmitter instance that can be used to dispatch events from the target element.
10
- * The returned EventEmitter is read-only and cannot be reconfigured after it's created.
11
- *
12
- * @example
13
- * // Use the `event` decorator to create an EventEmitter for a custom event
14
- * @event({ type: 'my-event', bubbles: true, composed: true })
15
- * myEventEmitter!: EventEmitter;
16
- *
17
- * // Later, you can use the EventEmitter to dispatch the custom event
18
- * this.myEventEmitter.emit({ detail: { message: 'Hello, world!' } });
19
- *
5
+ * @param eventConfig Configuration for the event emitter.
20
6
  * @see {@link EventEmitter} for more details about how the EventEmitter works.
21
7
  */
22
8
  export declare function event(eventConfig: EventEmitterConfig): (target: any, propertyKey: string) => void;
@@ -1,4 +1,4 @@
1
- import{z as q} from"../tools/event-emitter.js";function F(z){return(B,j)=>{Object.defineProperty(B,j,{get(){return Object.defineProperty(this,j,{value:new q(this,z),writable:!1,configurable:!1}),this[j]},configurable:!0})}}export{F as event};
2
- export{F as q};
1
+ import{s 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 u};
3
3
 
4
- //# debugId=409F58217AE1B81664756E2164756E21
4
+ //# debugId=9EA415FA08EFAFB564756E2164756E21
@@ -2,9 +2,9 @@
2
2
  "version": 3,
3
3
  "sources": ["../src/decorators/event.ts"],
4
4
  "sourcesContent": [
5
- "import { EventEmitter, type EventEmitterConfig } from '@/tools/event-emitter';\n\n/**\n * A decorator that creates an EventEmitter on the target element.\n * The EventEmitter can be used to dispatch custom events from the target element.\n *\n * @param {EventEmitterConfig} eventConfig - The configuration for the EventEmitter.\n * This includes the event type, and optionally, whether the event should bubble and whether it should be composed.\n *\n * @returns {EventEmitter} - An EventEmitter instance that can be used to dispatch events from the target element.\n * The returned EventEmitter is read-only and cannot be reconfigured after it's created.\n *\n * @example\n * // Use the `event` decorator to create an EventEmitter for a custom event\n * @event({ type: 'my-event', bubbles: true, composed: true })\n * myEventEmitter!: EventEmitter;\n *\n * // Later, you can use the EventEmitter to dispatch the custom event\n * this.myEventEmitter.emit({ detail: { message: 'Hello, world!' } });\n *\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 Object.defineProperty(target, propertyKey, {\n get() {\n Object.defineProperty(this, propertyKey, {\n value: new EventEmitter(this, eventConfig),\n writable: false,\n configurable: false,\n });\n return this[propertyKey];\n },\n configurable: true,\n });\n };\n}\n"
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
- "mappings": "+CAsBO,SAAS,CAAK,CAAC,EAAiC,CACrD,MAAO,CAAC,EAAa,IAAwB,CAC3C,OAAO,eAAe,EAAQ,EAAa,CACzC,GAAG,EAAG,CAMJ,OALA,OAAO,eAAe,KAAM,EAAa,CACvC,MAAO,IAAI,EAAa,KAAM,CAAW,EACzC,SAAU,GACV,aAAc,EAChB,CAAC,EACM,KAAK,IAEd,aAAc,EAChB,CAAC",
8
- "debugId": "409F58217AE1B81664756E2164756E21",
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": "9EA415FA08EFAFB564756E2164756E21",
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 w};
3
3
 
4
- //# debugId=83C62EF757FAD75A64756E2164756E21
4
+ //# debugId=DE26B9616BDA16A964756E2164756E21
@@ -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": "DE26B9616BDA16A964756E2164756E21",
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 y};
3
3
 
4
- //# debugId=DA1551DD9026892F64756E2164756E21
4
+ //# debugId=46B42783AE0479F164756E2164756E21
@@ -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": "46B42783AE0479F164756E2164756E21",
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 x};
3
3
 
4
- //# debugId=E25A78AC1BDA8ED264756E2164756E21
4
+ //# debugId=FB594A433F9501A364756E2164756E21
@@ -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": "FB594A433F9501A364756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -4,6 +4,7 @@ type ReactivePropertyOptions = {
4
4
  type: AttributeTypeConstant;
5
5
  reflect?: boolean;
6
6
  attribute?: string;
7
+ defaultValue?: unknown;
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({ type, attribute, reflect, defaultValue }: ReactivePropertyOptions): (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 I,p as J,q as L} from"../utils/attribute-utils.js";function Q({type:q,attribute:M,reflect:N,defaultValue:G}){return(H,z)=>{const k=new WeakMap,C=`__${z}`,D=M??z;Object.defineProperty(H,C,{get:function(){if(!k.has(this)){let j;if(q===Boolean)j=this.hasAttribute(D)?!0:G;else j=this.getAttribute(D)??G??I(q);const B=J(j,q);k.set(this,B)}return k.get(this)},set:function(j){const B=k.get(this);if(B===j)return;if(k.set(this,j),N)this.setAttribute(D,L(j,q));this.updated(z,B,j)},enumerable:!0,configurable:!0}),Object.defineProperty(H,z,{get:function(){return this[C]},set:function(j){this[C]=j},enumerable:!0,configurable:!0})}}export{Q as reactiveProp};
2
+ export{Q as v};
3
3
 
4
- //# debugId=E37B640AAF8C9EAF64756E2164756E21
4
+ //# debugId=468472FC8D1DC45B64756E2164756E21
@@ -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 readAttributeValue,\n writeAttributeValue,\n} from '@/utils/attribute-utils';\n\ntype ReactivePropertyOptions = {\n type: AttributeTypeConstant;\n reflect?: boolean;\n attribute?: string;\n defaultValue?: unknown;\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({ type, attribute, reflect, defaultValue }: 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 let initialValue: any;\n if (type === Boolean) {\n initialValue = this.hasAttribute(attributeKey) ? true : defaultValue;\n } else {\n initialValue = this.getAttribute(attributeKey) ?? defaultValue ?? defaultValueForType(type);\n }\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"
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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debugId": "468472FC8D1DC45B64756E2164756E21",
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{t as c} from"./decorators/on-event.js";import{u as b} from"./decorators/event.js";import{v as h} from"./decorators/reactive-prop.js";import{w as d} from"./decorators/on-updated.js";import{x as i} from"./decorators/reactive-field.js";import{y as g} from"./decorators/query.js";import{z 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=69AA70A160743DF464756E2164756E21
@@ -4,6 +4,6 @@
4
4
  "sourcesContent": [
5
5
  ],
6
6
  "mappings": "",
7
- "debugId": "62676F432361940564756E2164756E21",
7
+ "debugId": "69AA70A160743DF464756E2164756E21",
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 u} from"./context/create-context.js";import"./context/index.js";import{c as A,d as B} from"./context/context-provider.js";import"./context/types.js";import{e as v,f as w,g as y,h as z} from"./context/events.js";import{i as D} from"./context/decorators/consume-context.js";import{j as E} from"./context/decorators/context-selector.js";import"./mixins/index.js";import{k as F} from"./mixins/with-kita.js";import{l as C} 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} from"./utils/attribute-utils.js";import"./tools/index.js";import{r as G} from"./tools/stringify-attribute.js";import{s as b} from"./tools/event-emitter.js";import{t as d} from"./decorators/on-event.js";import{u as c} from"./decorators/event.js";import{v as q} from"./decorators/reactive-prop.js";import{w as g} from"./decorators/on-updated.js";import{x as s} from"./decorators/reactive-field.js";import{y as h} from"./decorators/query.js";import{z as a} from"./decorators/custom-element.js";export{n as writeAttributeValue,G as stringifyAttribute,l as readAttributeValue,q as reactiveProp,s as reactiveField,h as query,C as provideContext,j as parseAttributeTypeDefault,i as parseAttributeTypeConstant,g as onUpdated,d as onEvent,c as event,k as defaultValueForType,a as customElement,u as createContext,E as contextSelector,D as consumeContext,F as WithKita,x as RadiantElement,A as HYDRATE_ATTRIBUTE,b as EventEmitter,z as ContextSubscriptionRequestEvent,w as ContextRequestEvent,B as ContextProvider,y as ContextOnMountEvent,v as ContextEventsTypes};
2
2
 
3
- //# debugId=88BA9A2F79C6FAA664756E2164756E21
3
+ //# debugId=79AD598AC002195D64756E2164756E21
package/dist/index.js.map CHANGED
@@ -4,6 +4,6 @@
4
4
  "sourcesContent": [
5
5
  ],
6
6
  "mappings": "",
7
- "debugId": "88BA9A2F79C6FAA664756E2164756E21",
7
+ "debugId": "79AD598AC002195D64756E2164756E21",
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 s};
3
3
 
4
- //# debugId=2A51D44F7E2A76D164756E2164756E21
4
+ //# debugId=FD6021BDF59E287064756E2164756E21
@@ -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": "FD6021BDF59E287064756E2164756E21",
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{r as m} from"./stringify-attribute.js";import{s as f} from"./event-emitter.js";export{m as stringifyAttribute,f as EventEmitter};
2
2
 
3
- //# debugId=AA69C8C1038FF46C64756E2164756E21
3
+ //# debugId=038A4C13FF1DA81C64756E2164756E21
@@ -4,6 +4,6 @@
4
4
  "sourcesContent": [
5
5
  ],
6
6
  "mappings": "",
7
- "debugId": "AA69C8C1038FF46C64756E2164756E21",
7
+ "debugId": "038A4C13FF1DA81C64756E2164756E21",
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 r};
3
3
 
4
- //# debugId=D372CAE24874BD2564756E2164756E21
4
+ //# debugId=F99A9E81EBC8051464756E2164756E21
@@ -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": "F99A9E81EBC8051464756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -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 M(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 P(q){switch(q){case Number:return 0;case String:return"";case Boolean:return!1;default:return null}}var B=function(q){try{return JSON.parse(q)}catch(x){throw new TypeError("Invalid JSON string")}},H=function(q){if(typeof q==="object"&&!Array.isArray(q))return q;throw new TypeError("Parsed value is not a valid object")},F=function(q){return JSON.stringify(q)},L=function(q){return`${q}`};function Q(q,x){const z=G(x);if(!z)throw new TypeError(`[radiant-element] Unknown type "${x}"`);return K[z](q)}function R(q,x){const z=G(x);if(!z)throw new TypeError(`[radiant-element] Unknown type "${x}"`);return(D[z]||D.default)(q)}var K={array(q){if(Array.isArray(q))return q;const x=B(q);if(!Array.isArray(x))throw new TypeError(`Expected an array but got a value of type "${typeof x}"`);return x},boolean(q){if(typeof q==="boolean")return q;return!(q==="0"||String(q).toLowerCase()==="false")},number(q){if(typeof q==="number")return q;const x=Number(q.replace(/_/g,""));if(Number.isNaN(x))throw new TypeError(`Expected a number but got "${q}"`);return x},object(q){if(typeof q==="string"){const x=B(q);return H(x)}if(typeof q==="object"&&!Array.isArray(q))return q;throw new TypeError(`Expected an object but got a value of type "${typeof q}"`)},string(q){return q}},D={default:L,array:F,object:F};export{R as writeAttributeValue,Q as readAttributeValue,M as parseAttributeTypeDefault,G as parseAttributeTypeConstant,P as defaultValueForType};
2
+ export{G as m,M as n,P as o,Q as p,R as q};
3
3
 
4
- //# debugId=CBA306F898870D1D64756E2164756E21
4
+ //# debugId=6FB1DD632F1489BA64756E2164756E21
@@ -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 * Utility function to ensure the parsed object is not an array\n */\nfunction ensureObject(parsed: any): object {\n if (typeof parsed === 'object' && !Array.isArray(parsed)) {\n return parsed;\n }\n throw new TypeError('Parsed value is not a valid object');\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[]): unknown[] {\n if (Array.isArray(value)) return value;\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): boolean {\n if (typeof value === 'boolean') return value;\n return !(value === '0' || String(value).toLowerCase() === 'false');\n },\n\n number(value: string | number): number {\n if (typeof value === 'number') return value;\n const number = Number(value.replace(/_/g, ''));\n if (Number.isNaN(number)) {\n throw new TypeError(`Expected a number but got \"${value}\"`);\n }\n return number;\n },\n\n object(value: string | object): object {\n if (typeof value === 'string') {\n const parsedObject = parseJSON<object>(value);\n return ensureObject(parsedObject);\n }\n if (typeof value === 'object' && !Array.isArray(value)) {\n return value;\n }\n throw new TypeError(`Expected an object but got a value of type \"${typeof value}\"`);\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"
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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AAK,CAAC,EAAsC,CAC1C,GAAI,MAAM,QAAQ,CAAK,EAAG,OAAO,EACjC,MAAM,EAAQ,EAAqB,CAAK,EACxC,IAAK,MAAM,QAAQ,CAAK,EACtB,MAAM,IAAI,UAAU,qDAAqD,IAAQ,EAEnF,OAAO,GAGT,OAAO,CAAC,EAAkC,CACxC,UAAW,IAAU,UAAW,OAAO,EACvC,QAAS,IAAU,KAAO,OAAO,CAAK,EAAE,YAAY,IAAM,UAG5D,MAAM,CAAC,EAAgC,CACrC,UAAW,IAAU,SAAU,OAAO,EACtC,MAAM,EAAS,OAAO,EAAM,QAAQ,KAAM,EAAE,CAAC,EAC7C,GAAI,OAAO,MAAM,CAAM,EACrB,MAAM,IAAI,UAAU,8BAA8B,IAAQ,EAE5D,OAAO,GAGT,MAAM,CAAC,EAAgC,CACrC,UAAW,IAAU,SAAU,CAC7B,MAAM,EAAe,EAAkB,CAAK,EAC5C,OAAO,EAAa,CAAY,EAElC,UAAW,IAAU,WAAa,MAAM,QAAQ,CAAK,EACnD,OAAO,EAET,MAAM,IAAI,UAAU,sDAAsD,IAAQ,GAGpF,MAAM,CAAC,EAAuB,CAC5B,OAAO,EAEX,EAQM,EAAsC,CAC1C,QAAS,EACT,MAAO,EACP,OAAQ,CACV",
8
+ "debugId": "6FB1DD632F1489BA64756E2164756E21",
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} from"./attribute-utils.js";export{t as writeAttributeValue,p as readAttributeValue,f as parseAttributeTypeDefault,e as parseAttributeTypeConstant,m as defaultValueForType};
2
2
 
3
- //# debugId=935141D5A098762464756E2164756E21
3
+ //# debugId=2B3B7E70C807028964756E2164756E21
@@ -4,6 +4,6 @@
4
4
  "sourcesContent": [
5
5
  ],
6
6
  "mappings": "",
7
- "debugId": "935141D5A098762464756E2164756E21",
7
+ "debugId": "2B3B7E70C807028964756E2164756E21",
8
8
  "names": []
9
9
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ecopages/radiant",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/ecopages/radiant.git"