@ecopages/radiant 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +43 -0
- package/dist/context/context-provider.d.ts +79 -0
- package/dist/context/context-provider.js +5 -0
- package/dist/context/context-provider.js.map +10 -0
- package/dist/context/create-context.d.ts +6 -0
- package/dist/context/create-context.js +5 -0
- package/dist/context/create-context.js.map +10 -0
- package/dist/context/decorators/consume-context.d.ts +8 -0
- package/dist/context/decorators/consume-context.js +5 -0
- package/dist/context/decorators/consume-context.js.map +10 -0
- package/dist/context/decorators/context-selector.d.ts +16 -0
- package/dist/context/decorators/context-selector.js +5 -0
- package/dist/context/decorators/context-selector.js.map +10 -0
- package/dist/context/decorators/provide-context.d.ts +15 -0
- package/dist/context/decorators/provide-context.js +5 -0
- package/dist/context/decorators/provide-context.js.map +10 -0
- package/dist/context/events.d.ts +82 -0
- package/dist/context/events.js +5 -0
- package/dist/context/events.js.map +10 -0
- package/dist/context/index.d.ts +7 -0
- package/dist/context/index.js +4 -0
- package/dist/context/index.js.map +9 -0
- package/dist/context/types.d.ts +23 -0
- package/dist/context/types.js +3 -0
- package/dist/context/types.js.map +9 -0
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.js +4 -0
- package/dist/core/index.js.map +9 -0
- package/dist/core/radiant-element.d.ts +81 -0
- package/dist/core/radiant-element.js +5 -0
- package/dist/core/radiant-element.js.map +10 -0
- package/dist/decorators/custom-element.d.ts +5 -0
- package/dist/decorators/custom-element.js +5 -0
- package/dist/decorators/custom-element.js.map +10 -0
- package/dist/decorators/event.d.ts +22 -0
- package/dist/decorators/event.js +5 -0
- package/dist/decorators/event.js.map +10 -0
- package/dist/decorators/on-event.d.ts +22 -0
- package/dist/decorators/on-event.js +5 -0
- package/dist/decorators/on-event.js.map +10 -0
- package/dist/decorators/on-updated.d.ts +6 -0
- package/dist/decorators/on-updated.js +5 -0
- package/dist/decorators/on-updated.js.map +10 -0
- package/dist/decorators/query.d.ts +29 -0
- package/dist/decorators/query.js +5 -0
- package/dist/decorators/query.js.map +10 -0
- package/dist/decorators/reactive-field.d.ts +10 -0
- package/dist/decorators/reactive-field.js +5 -0
- package/dist/decorators/reactive-field.js.map +10 -0
- package/dist/decorators/reactive-prop.d.ts +17 -0
- package/dist/decorators/reactive-prop.js +5 -0
- package/dist/decorators/reactive-prop.js.map +10 -0
- package/dist/decorators.d.ts +7 -0
- package/dist/decorators.js +4 -0
- package/dist/decorators.js.map +9 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +9 -0
- package/dist/mixins/index.d.ts +1 -0
- package/dist/mixins/index.js +4 -0
- package/dist/mixins/index.js.map +9 -0
- package/dist/mixins/with-kita.d.ts +15 -0
- package/dist/mixins/with-kita.js +5 -0
- package/dist/mixins/with-kita.js.map +10 -0
- package/dist/tools/event-emitter.d.ts +29 -0
- package/dist/tools/event-emitter.js +5 -0
- package/dist/tools/event-emitter.js.map +10 -0
- package/dist/tools/index.d.ts +2 -0
- package/dist/tools/index.js +4 -0
- package/dist/tools/index.js.map +9 -0
- package/dist/tools/stringify-attribute.d.ts +11 -0
- package/dist/tools/stringify-attribute.js +5 -0
- package/dist/tools/stringify-attribute.js.map +10 -0
- package/dist/utils/attribute-utils.d.ts +40 -0
- package/dist/utils/attribute-utils.js +5 -0
- package/dist/utils/attribute-utils.js.map +10 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +4 -0
- package/dist/utils/index.js.map +9 -0
- package/package.json +128 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/decorators/custom-element.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/**\n * Registers a web component with the given name on the global `window.customElements` registry.\n * @param name selector name.\n */\nexport function customElement(name: string) {\n return (target: CustomElementConstructor) => {\n if (!globalThis.window) return;\n if (!window.customElements.get(name)) {\n window.customElements.define(name, target);\n }\n };\n}\n"
|
|
6
|
+
],
|
|
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": "CB8527BB8C9A079164756e2164756e21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type EventEmitterConfig } from '../tools/event-emitter';
|
|
2
|
+
/**
|
|
3
|
+
* A decorator that creates an EventEmitter on the target element.
|
|
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
|
+
*
|
|
20
|
+
* @see {@link EventEmitter} for more details about how the EventEmitter works.
|
|
21
|
+
*/
|
|
22
|
+
export declare function event(eventConfig: EventEmitterConfig): (target: any, propertyKey: string) => void;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
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};
|
|
3
|
+
export{F as m};
|
|
4
|
+
|
|
5
|
+
//# debugId=8F2237CEA4E2E00264756e2164756e21
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/decorators/event.ts"],
|
|
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"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";AAsBO,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": "8F2237CEA4E2E00264756e2164756e21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { RadiantElement, RadiantElementEventListener } from '../core/radiant-element';
|
|
2
|
+
type OnEventConfig = Pick<RadiantElementEventListener, 'type' | 'options'> & ({
|
|
3
|
+
selector: string;
|
|
4
|
+
} | {
|
|
5
|
+
ref: string;
|
|
6
|
+
});
|
|
7
|
+
/**
|
|
8
|
+
* A decorator to subscribe to an event on the target element.
|
|
9
|
+
* The event listener will be automatically unsubscribed when the element is disconnected.
|
|
10
|
+
*
|
|
11
|
+
* Note: This decorator uses event delegation, which means it relies on event bubbling.
|
|
12
|
+
* Therefore, it will not work with events that do not bubble, such as `focus`, `blur`, `load`, `unload`, `scroll`, etc.
|
|
13
|
+
* For focus and blur events, consider using `focusin` and `focusout` which are similar but do bubble.
|
|
14
|
+
*
|
|
15
|
+
* @param eventConfig The event configuration.
|
|
16
|
+
* @param eventConfig.selectors The CSS selector(s) of the target element(s).
|
|
17
|
+
* @param eventConfig.ref The data-ref attribute of the target element.
|
|
18
|
+
* @param eventConfig.type The type of the event to listen for.
|
|
19
|
+
* @param eventConfig.options Optional. An options object that specifies characteristics about the event listener.
|
|
20
|
+
*/
|
|
21
|
+
export declare function onEvent(eventConfig: OnEventConfig): (proto: RadiantElement, _: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
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};
|
|
3
|
+
export{J as i};
|
|
4
|
+
|
|
5
|
+
//# debugId=28C191BD4F0C131764756e2164756e21
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/decorators/on-event.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
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
|
+
],
|
|
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": "28C191BD4F0C131764756e2164756e21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { RadiantElement } from '../core/radiant-element';
|
|
2
|
+
/**
|
|
3
|
+
* A decorator to subscribe to an updated callback when a reactive field or property changes.
|
|
4
|
+
* @param eventConfig The event configuration.
|
|
5
|
+
*/
|
|
6
|
+
export declare function onUpdated(key: string): (proto: RadiantElement, propName: string) => void;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/decorators/on-updated.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
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
|
+
],
|
|
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": "B74CF50A2973140B64756e2164756e21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
type BaseQueryConfig = {
|
|
2
|
+
all?: boolean;
|
|
3
|
+
};
|
|
4
|
+
export type QueryConfig = BaseQueryConfig & ({
|
|
5
|
+
selector: string;
|
|
6
|
+
} | {
|
|
7
|
+
ref: string;
|
|
8
|
+
});
|
|
9
|
+
/**
|
|
10
|
+
* A decorator to query by CSS selector or data-ref attribute.
|
|
11
|
+
* By default it queries for the first element that matches the selector, but it can be configured to query for all elements.
|
|
12
|
+
*
|
|
13
|
+
* @param {QueryConfig} options - The configuration object for the query.
|
|
14
|
+
* @param {boolean} [options.all] - A flag to query for all elements that match the selector. Defaults to `false`.
|
|
15
|
+
* @param {string} [options.selector] - A CSS selector to match elements against. This property is mutually exclusive with `options.ref`.
|
|
16
|
+
* @param {string} [options.ref] - A reference to an element. This property is mutually exclusive with `options.selector`.
|
|
17
|
+
*
|
|
18
|
+
* @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.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* class MyElement extends HTMLElement {
|
|
22
|
+
* @query({ selector: '.my-class' })
|
|
23
|
+
* myElement;
|
|
24
|
+
* }
|
|
25
|
+
*
|
|
26
|
+
* // Now, `myElement` will return the first element in the light DOM of `MyElement` that matches the selector '.my-class'.
|
|
27
|
+
*/
|
|
28
|
+
export declare function query(options: QueryConfig): (proto: unknown, propertyKey: string | symbol) => void;
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
function R(k){return(G,I)=>{Object.defineProperty(G,I,{get:function(){const z="selector"in k?k.selector:`[data-ref="${k.ref}"]`;return k.all?this.querySelectorAll(z):this.querySelector(z)},enumerable:!0,configurable:!0})}}export{R as query};
|
|
3
|
+
export{R as k};
|
|
4
|
+
|
|
5
|
+
//# debugId=11F0B25F681690CF64756e2164756e21
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/decorators/query.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"type BaseQueryConfig = {\n all?: boolean;\n};\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 {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(options: QueryConfig) {\n return (proto: unknown, propertyKey: string | symbol) => {\n const getter = function (this: Element) {\n const selector = 'selector' in options ? options.selector : `[data-ref=\"${options.ref}\"]`;\n const query = options.all ? this.querySelectorAll(selector) : this.querySelector(selector);\n return query;\n };\n\n Object.defineProperty(proto, propertyKey, {\n get: getter,\n enumerable: true,\n configurable: true,\n });\n };\n}\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";AAiCO,SAAS,CAAK,CAAC,EAAsB,CAC1C,MAAO,CAAC,EAAgB,IAAiC,CAOvD,OAAO,eAAe,EAAO,EAAa,CACxC,YAPsB,EAAgB,CACtC,MAAM,EAAW,aAAc,EAAU,EAAQ,SAAW,cAAc,EAAQ,QAElF,OADc,EAAQ,IAAM,KAAK,iBAAiB,CAAQ,EAAI,KAAK,cAAc,CAAQ,GAMzF,WAAY,GACZ,aAAc,EAChB,CAAC",
|
|
8
|
+
"debugId": "11F0B25F681690CF64756e2164756e21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { RadiantElement } from '../core/radiant-element';
|
|
2
|
+
/**
|
|
3
|
+
* A decorator to define a reactive field.
|
|
4
|
+
* Every time the property changes, the `updated` method will be called.
|
|
5
|
+
* Due the fact the value is always undefined before the first update,
|
|
6
|
+
* we are adding a `isDefined` WeakSet to track if the property has been defined.
|
|
7
|
+
* @param target The target element.
|
|
8
|
+
* @param propertyKey The property key.
|
|
9
|
+
*/
|
|
10
|
+
export declare function reactiveField(proto: RadiantElement, propertyKey: string): void;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
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};
|
|
3
|
+
export{F as g};
|
|
4
|
+
|
|
5
|
+
//# debugId=703981F78FB08FB164756e2164756e21
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/decorators/reactive-field.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
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
|
+
],
|
|
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": "703981F78FB08FB164756e2164756e21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { RadiantElement } from '../core/radiant-element';
|
|
2
|
+
import { type AttributeTypeConstant } from '../utils/attribute-utils';
|
|
3
|
+
type ReactivePropertyOptions = {
|
|
4
|
+
type: AttributeTypeConstant;
|
|
5
|
+
reflect?: boolean;
|
|
6
|
+
attribute?: string;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* A decorator to define a reactive property.
|
|
10
|
+
* Every time the property changes, the `updated` method will be called.
|
|
11
|
+
* @param options The options for the reactive property.
|
|
12
|
+
* @param options.type The type of the property value.
|
|
13
|
+
* @param options.reflect Whether to reflect the property to the attribute.
|
|
14
|
+
* @param options.attribute The name of the attribute.
|
|
15
|
+
*/
|
|
16
|
+
export declare function reactiveProp({ type, attribute, reflect }: ReactivePropertyOptions): (proto: RadiantElement, propertyKey: string) => void;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{d as H,e as I,f 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};
|
|
3
|
+
export{O as a};
|
|
4
|
+
|
|
5
|
+
//# debugId=94DDE419B09F637D64756e2164756e21
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/decorators/reactive-prop.ts"],
|
|
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"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";AAsBO,SAAS,CAAY,EAAG,OAAM,YAAW,WAAoC,CAClF,MAAO,CAAC,EAAuB,IAAwB,CACrD,MAAM,EAAiB,IAAI,QACrB,EAAsB,KAAK,IAC3B,EAAe,GAAa,EAElC,OAAO,eAAe,EAAO,EAAqB,CAChD,YAAc,EAAG,CACf,IAAK,EAAe,IAAI,IAAI,EAAG,CAC7B,MAAM,EAAe,KAAK,aAAa,CAAY,GAAK,EAAoB,CAAI,EAC1E,EAAQ,EAAmB,EAAc,CAAI,EACnD,EAAe,IAAI,KAAM,CAAK,EAEhC,OAAO,EAAe,IAAI,IAAI,GAEhC,YAAc,CAAC,EAAkB,CAC/B,MAAM,EAAW,EAAe,IAAI,IAAI,EACxC,GAAI,IAAa,EAAU,OAE3B,GADA,EAAe,IAAI,KAAM,CAAQ,EAC7B,EAAS,KAAK,aAAa,EAAc,EAAoB,EAAU,CAAI,CAAC,EAChF,KAAK,QAAQ,EAAa,EAAU,CAAQ,GAE9C,WAAY,GACZ,aAAc,EAChB,CAAC,EAED,OAAO,eAAe,EAAO,EAAa,CACxC,YAAc,EAAG,CACf,OAAO,KAAK,IAEd,YAAc,CAAC,EAAkB,CAC/B,KAAK,GAAuB,GAE9B,WAAY,GACZ,aAAc,EAChB,CAAC",
|
|
8
|
+
"debugId": "94DDE419B09F637D64756e2164756e21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from './decorators/custom-element';
|
|
2
|
+
export * from './decorators/event';
|
|
3
|
+
export * from './decorators/on-event';
|
|
4
|
+
export * from './decorators/on-updated';
|
|
5
|
+
export * from './decorators/query';
|
|
6
|
+
export * from './decorators/reactive-prop';
|
|
7
|
+
export * from './decorators/reactive-field';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{a as h} from"./decorators/reactive-prop.js";import"./utils/attribute-utils.js";import{g as i} from"./decorators/reactive-field.js";import{h as d} from"./decorators/on-updated.js";import{i as c} from"./decorators/on-event.js";import{j as a} from"./decorators/custom-element.js";import{k as g} from"./decorators/query.js";import{m as b} from"./decorators/event.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};
|
|
3
|
+
|
|
4
|
+
//# debugId=1EFF26869AB4123764756e2164756e21
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import"./decorators.js";import"./utils/index.js";import{a as n} from"./decorators/reactive-prop.js";import{b as h,c as i,d as j,e as k,f as l} from"./utils/attribute-utils.js";import{g as q} from"./decorators/reactive-field.js";import{h as d} from"./decorators/on-updated.js";import{i as c} from"./decorators/on-event.js";import{j as x} from"./decorators/custom-element.js";import{k as g} from"./decorators/query.js";import"./mixins/index.js";import{l as F} from"./mixins/with-kita.js";import{m as b} from"./decorators/event.js";import"./core/index.js";import{n as s} from"./core/radiant-element.js";import{o as u} from"./context/create-context.js";import{p as A,q as B} from"./context/context-provider.js";import"./context/types.js";import"./context/index.js";import{r as v,s as w,t as y,u as z} from"./context/events.js";import{v as E} from"./context/decorators/context-selector.js";import{w as D} from"./context/decorators/consume-context.js";import{x as C} from"./context/decorators/provide-context.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};
|
|
3
|
+
|
|
4
|
+
//# debugId=E23E3FCBB8E5F83864756e2164756e21
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './with-kita';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { RadiantElement, RenderInsertPosition } from '../core/radiant-element';
|
|
2
|
+
type Constructor<T> = new (...args: any[]) => T;
|
|
3
|
+
type WithKitaRenderTemplateProps = {
|
|
4
|
+
target: HTMLElement;
|
|
5
|
+
template: JSX.Element | string;
|
|
6
|
+
insert?: RenderInsertPosition;
|
|
7
|
+
};
|
|
8
|
+
interface WithKitaMixin {
|
|
9
|
+
renderTemplate: (props: WithKitaRenderTemplateProps) => Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* A mixin that provides a method to render a JSX template into an HTMLElement.
|
|
13
|
+
*/
|
|
14
|
+
export declare function WithKita<T extends Constructor<RadiantElement>>(Base: T): T & Constructor<WithKitaMixin>;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
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};
|
|
3
|
+
export{u as l};
|
|
4
|
+
|
|
5
|
+
//# debugId=96B6374E9E67AF7864756e2164756e21
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/mixins/with-kita.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import type { RadiantElement, RenderInsertPosition } from '@/core/radiant-element';\n\ntype Constructor<T> = new (...args: any[]) => T;\n\ntype WithKitaRenderTemplateProps = {\n target: HTMLElement;\n template: JSX.Element | string;\n insert?: RenderInsertPosition;\n};\n\ninterface WithKitaMixin {\n renderTemplate: (props: WithKitaRenderTemplateProps) => Promise<void>;\n}\n\n/**\n * A mixin that provides a method to render a JSX template into an HTMLElement.\n */\nexport function WithKita<T extends Constructor<RadiantElement>>(Base: T): T & Constructor<WithKitaMixin> {\n return class extends Base implements WithKitaMixin {\n override async renderTemplate({ target = this, template, insert = 'replace' }: WithKitaRenderTemplateProps) {\n const safeTemplate = typeof template !== 'string' ? template.toString() : template;\n switch (insert) {\n case 'replace':\n target.innerHTML = safeTemplate;\n break;\n case 'beforeend':\n target.insertAdjacentHTML('beforeend', safeTemplate);\n break;\n case 'afterbegin':\n target.insertAdjacentHTML('afterbegin', safeTemplate);\n break;\n }\n }\n } as T & Constructor<WithKitaMixin>;\n}\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";AAiBO,SAAS,CAA+C,CAAC,EAAyC,CACvG,OAAO,cAAc,CAA8B,MAClC,eAAc,EAAG,SAAS,KAAM,WAAU,SAAS,WAA0C,CAC1G,MAAM,SAAsB,IAAa,SAAW,EAAS,SAAS,EAAI,EAC1E,OAAQ,OACD,UACH,EAAO,UAAY,EACnB,UACG,YACH,EAAO,mBAAmB,YAAa,CAAY,EACnD,UACG,aACH,EAAO,mBAAmB,aAAc,CAAY,EACpD,OAGR",
|
|
8
|
+
"debugId": "96B6374E9E67AF7864756e2164756e21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { RadiantElement } from '..';
|
|
2
|
+
export interface EventEmitterConfig {
|
|
3
|
+
name: string;
|
|
4
|
+
bubbles?: boolean;
|
|
5
|
+
cancelable?: boolean;
|
|
6
|
+
composed?: boolean;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* A generic event emitter class that allows emitting custom events.
|
|
10
|
+
*
|
|
11
|
+
* @template T - The type of the event detail.
|
|
12
|
+
*/
|
|
13
|
+
export declare class EventEmitter<T = unknown> {
|
|
14
|
+
private host;
|
|
15
|
+
private eventConfig;
|
|
16
|
+
/**
|
|
17
|
+
* Constructs a new instance of the EventEmitter class.
|
|
18
|
+
*
|
|
19
|
+
* @param host - The host element on which the events will be dispatched.
|
|
20
|
+
* @param eventConfig - The configuration for the event.
|
|
21
|
+
*/
|
|
22
|
+
constructor(host: RadiantElement, eventConfig: EventEmitterConfig);
|
|
23
|
+
/**
|
|
24
|
+
* Emits a custom event with the specified detail.
|
|
25
|
+
*
|
|
26
|
+
* @param detail - The detail object to be passed along with the event.
|
|
27
|
+
*/
|
|
28
|
+
emit(detail?: T): void;
|
|
29
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
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};
|
|
3
|
+
export{x as z};
|
|
4
|
+
|
|
5
|
+
//# debugId=F974E105925CFC8564756e2164756e21
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/tools/event-emitter.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import type { RadiantElement } from '..';\n\nexport interface EventEmitterConfig {\n name: string;\n bubbles?: boolean;\n cancelable?: boolean;\n composed?: boolean;\n}\n\n/**\n * A generic event emitter class that allows emitting custom events.\n *\n * @template T - The type of the event detail.\n */\nexport class EventEmitter<T = unknown> {\n private host: RadiantElement;\n private eventConfig: EventEmitterConfig;\n\n /**\n * Constructs a new instance of the EventEmitter class.\n *\n * @param host - The host element on which the events will be dispatched.\n * @param eventConfig - The configuration for the event.\n */\n constructor(host: RadiantElement, eventConfig: EventEmitterConfig) {\n this.host = host;\n this.eventConfig = eventConfig;\n }\n\n /**\n * Emits a custom event with the specified detail.\n *\n * @param detail - The detail object to be passed along with the event.\n */\n emit(detail?: T) {\n const event = new CustomEvent(this.eventConfig.name, {\n detail: detail,\n bubbles: this.eventConfig.bubbles,\n cancelable: this.eventConfig.cancelable,\n composed: this.eventConfig.composed,\n });\n this.host.dispatchEvent(event);\n }\n}\n"
|
|
6
|
+
],
|
|
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": "F974E105925CFC8564756e2164756e21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts the given value to a JSON string representation.
|
|
3
|
+
* This can be very handy for passing complex objects as attributes.
|
|
4
|
+
*
|
|
5
|
+
* @param value - The value to be converted.
|
|
6
|
+
* @returns The JSON string representation of the value.
|
|
7
|
+
* @template T - The type of the value.
|
|
8
|
+
*
|
|
9
|
+
* @example <my-app class="radiant-todo" hydrate-context={stringifyAttribute<MyType>(context)}>
|
|
10
|
+
*/
|
|
11
|
+
export declare function stringifyAttribute<T>(value: T): T;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/tools/stringify-attribute.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
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
|
+
],
|
|
7
|
+
"mappings": ";AAUO,SAAS,CAAqB,CAAC,EAAa,CACjD,OAAO,KAAK,UAAU,CAAK",
|
|
8
|
+
"debugId": "1ACD622798F1744E64756e2164756e21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export type AttributeTypeConstant = typeof Array | typeof Boolean | typeof Number | typeof Object | typeof String;
|
|
2
|
+
export type AttributeTypeDefault = Array<unknown> | boolean | number | Record<string, unknown> | string;
|
|
3
|
+
/**
|
|
4
|
+
* Parses the given attribute type constant and returns its corresponding string representation.
|
|
5
|
+
*
|
|
6
|
+
* @param constant - The attribute type constant to parse.
|
|
7
|
+
* @returns The string representation of the attribute type constant.
|
|
8
|
+
*/
|
|
9
|
+
export declare function parseAttributeTypeConstant(constant?: AttributeTypeConstant): "array" | "boolean" | "number" | "object" | "string" | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* Parses the attribute type default value and returns its type as a string.
|
|
12
|
+
*
|
|
13
|
+
* @param defaultValue - The default value of the attribute type.
|
|
14
|
+
* @returns The type of the default value as a string.
|
|
15
|
+
*/
|
|
16
|
+
export declare function parseAttributeTypeDefault(defaultValue?: AttributeTypeDefault): "array" | "boolean" | "number" | "object" | "string" | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* Returns the default value for a given attribute type.
|
|
19
|
+
*
|
|
20
|
+
* @param type - The attribute type constant.
|
|
21
|
+
* @returns The default value for the specified attribute type.
|
|
22
|
+
*/
|
|
23
|
+
export declare function defaultValueForType(type: AttributeTypeConstant): unknown;
|
|
24
|
+
/**
|
|
25
|
+
* Reads the attribute value based on the provided type.
|
|
26
|
+
* @param value - The attribute value to be read.
|
|
27
|
+
* @param type - The type of the attribute.
|
|
28
|
+
* @returns The parsed attribute value.
|
|
29
|
+
* @throws {TypeError} If the provided type is unknown.
|
|
30
|
+
*/
|
|
31
|
+
export declare function readAttributeValue(value: string, type: AttributeTypeConstant): string | number | boolean | object | unknown[];
|
|
32
|
+
/**
|
|
33
|
+
* Writes the attribute value based on the provided type.
|
|
34
|
+
*
|
|
35
|
+
* @param value - The value to be written.
|
|
36
|
+
* @param type - The type of the attribute.
|
|
37
|
+
* @returns The written attribute value.
|
|
38
|
+
* @throws {TypeError} If the provided type is unknown.
|
|
39
|
+
*/
|
|
40
|
+
export declare function writeAttributeValue(value: unknown, type: AttributeTypeConstant): string;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
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};
|
|
3
|
+
export{H as b,B as c,M as d,P as e,Q as f};
|
|
4
|
+
|
|
5
|
+
//# debugId=5864A33A5A8C348864756e2164756e21
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/utils/attribute-utils.ts"],
|
|
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"
|
|
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,OAAO,OACJ,OACH,MAAO,QACJ,QACH,MAAO,WAEP,OAAO,MAyDb,IAAS,UAAS,CAAC,EAAgB,CACjC,OAAO,KAAK,UAAU,CAAK,GAGpB,UAAW,CAAC,EAAgB,CACnC,MAAO,GAAG,KAUL,SAAS,CAAkB,CAAC,EAAe,EAA6B,CAC7E,MAAM,EAAa,EAA2B,CAAI,EAClD,IAAK,EAAY,MAAM,IAAI,UAAU,mCAAmC,IAAO,EAC/E,OAAO,EAAQ,GAAY,CAAK,EAW3B,SAAS,CAAmB,CAAC,EAAgB,EAA6B,CAC/E,MAAM,EAAa,EAA2B,CAAI,EAClD,IAAK,EAAY,MAAM,IAAI,UAAU,mCAAmC,IAAO,EAC/E,OAAQ,EAAQ,IAAe,EAAQ,SAAS,CAAK,EAhFvD,IAAM,EAAsC,CAC1C,KAAK,CAAC,EAA0B,CAC9B,MAAM,EAAQ,KAAK,MAAM,CAAK,EAC9B,IAAK,MAAM,QAAQ,CAAK,EACtB,MAAM,IAAI,UACR,yDAAyD,eAAmB,EAA0B,CAAK,IAC7G,EAEF,OAAO,GAGT,OAAO,CAAC,EAAwB,CAC9B,QAAS,IAAU,KAAO,OAAO,CAAK,EAAE,YAAY,IAAM,UAG5D,MAAM,CAAC,EAAuB,CAC5B,OAAO,OAAO,EAAM,QAAQ,KAAM,EAAE,CAAC,GAGvC,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": "5864A33A5A8C348864756e2164756e21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './attribute-utils';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{b as e,c as f,d as m,e as p,f as t} from"./attribute-utils.js";export{t as writeAttributeValue,p as readAttributeValue,f as parseAttributeTypeDefault,e as parseAttributeTypeConstant,m as defaultValueForType};
|
|
3
|
+
|
|
4
|
+
//# debugId=A3D40DD3E276E47A64756e2164756e21
|