@ecopages/radiant 0.1.3 → 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.
@@ -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 z};
2
+ export{n as A};
3
3
 
4
- //# debugId=5805D55A877771B664756E2164756E21
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": "5805D55A877771B664756E2164756E21",
8
+ "debugId": "F0F3910DA44047E164756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -1,4 +1,4 @@
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};
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=9EA415FA08EFAFB564756E2164756E21
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": "9EA415FA08EFAFB564756E2164756E21",
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 w};
2
+ export{F as x};
3
3
 
4
- //# debugId=DE26B9616BDA16A964756E2164756E21
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": "DE26B9616BDA16A964756E2164756E21",
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 y};
2
+ export{Z as z};
3
3
 
4
- //# debugId=46B42783AE0479F164756E2164756E21
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": "46B42783AE0479F164756E2164756E21",
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 x};
2
+ export{F as y};
3
3
 
4
- //# debugId=FB594A433F9501A364756E2164756E21
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": "FB594A433F9501A364756E2164756E21",
8
+ "debugId": "7041FB47FE0D07EA64756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -1,10 +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?: unknown;
7
+ defaultValue?: T;
8
8
  };
9
9
  /**
10
10
  * A decorator to define a reactive property.
@@ -15,5 +15,5 @@ type ReactivePropertyOptions = {
15
15
  * @param options.attribute The name of the attribute.
16
16
  * @param options.defaultValue The default value of the property.
17
17
  */
18
- export declare function reactiveProp({ type, attribute, reflect, defaultValue }: ReactivePropertyOptions): (proto: RadiantElement, propertyKey: string) => void;
18
+ export declare function reactiveProp<T = unknown>({ type, attribute, reflect, defaultValue }: ReactivePropertyOptions<T>): (proto: RadiantElement, propertyKey: string) => void;
19
19
  export {};
@@ -1,4 +1,4 @@
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};
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=468472FC8D1DC45B64756E2164756E21
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 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"
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": "+DAwBO,SAAS,CAAY,EAAG,OAAM,YAAW,UAAS,gBAAyC,CAChG,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,IAAI,EACJ,GAAI,IAAS,QACX,EAAe,KAAK,aAAa,CAAY,EAAI,GAAO,MAExD,GAAe,KAAK,aAAa,CAAY,GAAK,GAAgB,EAAoB,CAAI,EAE5F,MAAM,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,GAA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,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"./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};
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=69AA70A160743DF464756E2164756E21
3
+ //# debugId=71830EA449072B8A64756E2164756E21
@@ -4,6 +4,6 @@
4
4
  "sourcesContent": [
5
5
  ],
6
6
  "mappings": "",
7
- "debugId": "69AA70A160743DF464756E2164756E21",
7
+ "debugId": "71830EA449072B8A64756E2164756E21",
8
8
  "names": []
9
9
  }
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
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};
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=79AD598AC002195D64756E2164756E21
3
+ //# debugId=02FD23EB472364E664756E2164756E21
package/dist/index.js.map CHANGED
@@ -4,6 +4,6 @@
4
4
  "sourcesContent": [
5
5
  ],
6
6
  "mappings": "",
7
- "debugId": "79AD598AC002195D64756E2164756E21",
7
+ "debugId": "02FD23EB472364E664756E2164756E21",
8
8
  "names": []
9
9
  }
@@ -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 s};
2
+ export{x as t};
3
3
 
4
- //# debugId=FD6021BDF59E287064756E2164756E21
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": "FD6021BDF59E287064756E2164756E21",
8
+ "debugId": "EF7DCAF38E65FBE864756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -1,3 +1,3 @@
1
- import{r as m} from"./stringify-attribute.js";import{s 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=038A4C13FF1DA81C64756E2164756E21
3
+ //# debugId=C6D6495E47CC38E164756E2164756E21
@@ -4,6 +4,6 @@
4
4
  "sourcesContent": [
5
5
  ],
6
6
  "mappings": "",
7
- "debugId": "038A4C13FF1DA81C64756E2164756E21",
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 r};
2
+ export{t as s};
3
3
 
4
- //# debugId=F99A9E81EBC8051464756E2164756E21
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": "F99A9E81EBC8051464756E2164756E21",
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 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};
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=6FB1DD632F1489BA64756E2164756E21
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 * 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"
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,MAAO,aACJ,SACH,MAAO,SAGX,GAAI,MAAM,QAAQ,CAAY,EAAG,MAAO,QACxC,GAAI,OAAO,UAAU,SAAS,KAAK,CAAY,IAAM,kBAAmB,MAAO,SAS1E,SAAS,CAAmB,CAAC,EAAsC,CACxE,OAAQ,QACD,OACH,MAAO,QACJ,OACH,MAAO,QACJ,QACH,MAAO,WAEP,OAAO,MASb,IAAS,UAAY,CAAC,EAAkB,CACtC,GAAI,CACF,OAAO,KAAK,MAAM,CAAK,QAChB,EAAP,CACA,MAAM,IAAI,UAAU,qBAAqB,IAOpC,UAAY,CAAC,EAAqB,CACzC,UAAW,IAAW,WAAa,MAAM,QAAQ,CAAM,EACrD,OAAO,EAET,MAAM,IAAI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AAO,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{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};
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=2B3B7E70C807028964756E2164756E21
3
+ //# debugId=4C515B2ECFF4666864756E2164756E21
@@ -4,6 +4,6 @@
4
4
  "sourcesContent": [
5
5
  ],
6
6
  "mappings": "",
7
- "debugId": "2B3B7E70C807028964756E2164756E21",
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.3",
3
+ "version": "0.1.4",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/ecopages/radiant.git"