@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.
Files changed (81) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +43 -0
  3. package/dist/context/context-provider.d.ts +79 -0
  4. package/dist/context/context-provider.js +5 -0
  5. package/dist/context/context-provider.js.map +10 -0
  6. package/dist/context/create-context.d.ts +6 -0
  7. package/dist/context/create-context.js +5 -0
  8. package/dist/context/create-context.js.map +10 -0
  9. package/dist/context/decorators/consume-context.d.ts +8 -0
  10. package/dist/context/decorators/consume-context.js +5 -0
  11. package/dist/context/decorators/consume-context.js.map +10 -0
  12. package/dist/context/decorators/context-selector.d.ts +16 -0
  13. package/dist/context/decorators/context-selector.js +5 -0
  14. package/dist/context/decorators/context-selector.js.map +10 -0
  15. package/dist/context/decorators/provide-context.d.ts +15 -0
  16. package/dist/context/decorators/provide-context.js +5 -0
  17. package/dist/context/decorators/provide-context.js.map +10 -0
  18. package/dist/context/events.d.ts +82 -0
  19. package/dist/context/events.js +5 -0
  20. package/dist/context/events.js.map +10 -0
  21. package/dist/context/index.d.ts +7 -0
  22. package/dist/context/index.js +4 -0
  23. package/dist/context/index.js.map +9 -0
  24. package/dist/context/types.d.ts +23 -0
  25. package/dist/context/types.js +3 -0
  26. package/dist/context/types.js.map +9 -0
  27. package/dist/core/index.d.ts +1 -0
  28. package/dist/core/index.js +4 -0
  29. package/dist/core/index.js.map +9 -0
  30. package/dist/core/radiant-element.d.ts +81 -0
  31. package/dist/core/radiant-element.js +5 -0
  32. package/dist/core/radiant-element.js.map +10 -0
  33. package/dist/decorators/custom-element.d.ts +5 -0
  34. package/dist/decorators/custom-element.js +5 -0
  35. package/dist/decorators/custom-element.js.map +10 -0
  36. package/dist/decorators/event.d.ts +22 -0
  37. package/dist/decorators/event.js +5 -0
  38. package/dist/decorators/event.js.map +10 -0
  39. package/dist/decorators/on-event.d.ts +22 -0
  40. package/dist/decorators/on-event.js +5 -0
  41. package/dist/decorators/on-event.js.map +10 -0
  42. package/dist/decorators/on-updated.d.ts +6 -0
  43. package/dist/decorators/on-updated.js +5 -0
  44. package/dist/decorators/on-updated.js.map +10 -0
  45. package/dist/decorators/query.d.ts +29 -0
  46. package/dist/decorators/query.js +5 -0
  47. package/dist/decorators/query.js.map +10 -0
  48. package/dist/decorators/reactive-field.d.ts +10 -0
  49. package/dist/decorators/reactive-field.js +5 -0
  50. package/dist/decorators/reactive-field.js.map +10 -0
  51. package/dist/decorators/reactive-prop.d.ts +17 -0
  52. package/dist/decorators/reactive-prop.js +5 -0
  53. package/dist/decorators/reactive-prop.js.map +10 -0
  54. package/dist/decorators.d.ts +7 -0
  55. package/dist/decorators.js +4 -0
  56. package/dist/decorators.js.map +9 -0
  57. package/dist/index.d.ts +6 -0
  58. package/dist/index.js +4 -0
  59. package/dist/index.js.map +9 -0
  60. package/dist/mixins/index.d.ts +1 -0
  61. package/dist/mixins/index.js +4 -0
  62. package/dist/mixins/index.js.map +9 -0
  63. package/dist/mixins/with-kita.d.ts +15 -0
  64. package/dist/mixins/with-kita.js +5 -0
  65. package/dist/mixins/with-kita.js.map +10 -0
  66. package/dist/tools/event-emitter.d.ts +29 -0
  67. package/dist/tools/event-emitter.js +5 -0
  68. package/dist/tools/event-emitter.js.map +10 -0
  69. package/dist/tools/index.d.ts +2 -0
  70. package/dist/tools/index.js +4 -0
  71. package/dist/tools/index.js.map +9 -0
  72. package/dist/tools/stringify-attribute.d.ts +11 -0
  73. package/dist/tools/stringify-attribute.js +5 -0
  74. package/dist/tools/stringify-attribute.js.map +10 -0
  75. package/dist/utils/attribute-utils.d.ts +40 -0
  76. package/dist/utils/attribute-utils.js +5 -0
  77. package/dist/utils/attribute-utils.js.map +10 -0
  78. package/dist/utils/index.d.ts +1 -0
  79. package/dist/utils/index.js +4 -0
  80. package/dist/utils/index.js.map +9 -0
  81. package/package.json +128 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Andrea Zanenghi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Radiant
2
+
3
+ Radiant is a minimalist web component library designed for simplicity and flexibility.
4
+
5
+ It leverages the light DOM, allowing components to be styled and manipulated with standard CSS and JavaScript, unlike traditional web components that use the shadow DOM.
6
+
7
+ This approach deviates from conventional [web component best practices](https://web.dev/articles/custom-elements-best-practices), offering a trade-off for a more streamlined development experience.
8
+
9
+ Ideal for any kind of projects, Radiant provides a lightweight alternative to full web components implementations, reducing unnecessary overhead.
10
+
11
+ ## How to install it
12
+
13
+ ```sh
14
+ bun install @ecopages/radiant
15
+ ```
16
+
17
+ ## Import Structure
18
+
19
+ | Folder/Module | Description |
20
+ | ----------------------------- | --------------------------------------- |
21
+ | `./` | Contains all modules. |
22
+ | `./context` | Contains all modules related to contex. |
23
+ | `./context/create-context` | Module for creating context. |
24
+ | `./context/context-provider` | Module for providing context. |
25
+ | `./context/consume-context` | Module for consuming context. |
26
+ | `./context/provide-context` | Module for providing context. |
27
+ | `./context/context-selector` | Module for selecting context. |
28
+ | `./core` | Contains all core elements |
29
+ | `./core/radiant-element` | Module for the Radiant Element. |
30
+ | `./decorators` | Contains decorator modules. |
31
+ | `./decorators/custom-element` | Decorator for custom elements. |
32
+ | `./decorators/event` | Decorator for events. |
33
+ | `./decorators/on-event` | Decorator for event handlers. |
34
+ | `./decorators/on-updated` | Decorator for update handlers. |
35
+ | `./decorators/query` | Decorator for querying elements. |
36
+ | `./decorators/reactive-field` | Decorator for reactive fields. |
37
+ | `./decorators/reactive-prop` | Decorator for reactive properties. |
38
+ | `./mixins` | Contains mixin modules. |
39
+ | `./mixins/with-kita` | Mixin for Kita functionality. |
40
+ | `./tools` | Contains utility modules. |
41
+ | `./tools/stringify-attribute` | Utility for stringifying attributes. |
42
+ | `./tools/event-emitter` | Utility for emitting events. |
43
+ | `./utils` | Contains additional utility modules. |
@@ -0,0 +1,79 @@
1
+ import type { RadiantElement } from '../core/radiant-element';
2
+ import { type AttributeTypeConstant } from '../utils/attribute-utils';
3
+ import { type ContextSubscription } from './events';
4
+ import type { Context, ContextType, UnknownContext } from './types';
5
+ type ContextProviderOptions<T extends UnknownContext> = {
6
+ context: UnknownContext;
7
+ initialValue?: T['__context__'];
8
+ hydrate?: AttributeTypeConstant;
9
+ };
10
+ export declare const HYDRATE_ATTRIBUTE = "hydrate-context";
11
+ /**
12
+ * Represents a context provider that allows setting and getting the context,
13
+ * as well as subscribing to context updates.
14
+ *
15
+ * @template T - The type of the context.
16
+ */
17
+ export interface IContextProvider<T extends Context<unknown, unknown>> {
18
+ /**
19
+ * Sets the context with the provided update and invokes the optional callback function.
20
+ *
21
+ * @param update - The partial update to be applied to the context.
22
+ * @param callback - An optional callback function that receives the updated context.
23
+ */
24
+ setContext: (update: Partial<ContextType<T>>, callback?: (context: ContextType<T>) => void) => void;
25
+ /**
26
+ * Gets the current context.
27
+ *
28
+ * @returns The current context.
29
+ */
30
+ getContext: () => ContextType<T>;
31
+ /**
32
+ * Subscribes to context updates.
33
+ *
34
+ * @param subscription - The subscription object that defines the callback function to be invoked on context updates.
35
+ */
36
+ subscribe: (subscription: ContextSubscription<T>) => void;
37
+ }
38
+ /**
39
+ * It creates a context provider that allows setting and getting the context,
40
+ * It will also be in charge of notifying the subscribers when the context changes.
41
+ *
42
+ * @template T - The type of the context.
43
+ * @implements IContextProvider
44
+ *
45
+ * @example
46
+ * ```ts
47
+ * export class MyElement extends RadiantElement {
48
+ * provider = new ContextProvider<typeof myContext>(this, {
49
+ * context: myContext,
50
+ * initialValue: {
51
+ * value: 'Hello World',
52
+ * },
53
+ * });
54
+ * ```
55
+ */
56
+ export declare class ContextProvider<T extends Context<unknown, unknown>> implements IContextProvider<T> {
57
+ private host;
58
+ private context;
59
+ private value;
60
+ subscriptions: ContextSubscription<T>[];
61
+ /**
62
+ * Creates a new instance of the ContextProvider.
63
+ *
64
+ * @param host - The host element that will contain the context provider.
65
+ * @param options - The options to configure the context provider.
66
+ */
67
+ constructor(host: RadiantElement, options: ContextProviderOptions<T>);
68
+ setContext: (update: Partial<ContextType<T>>, callback?: (context: ContextType<T>) => void) => void;
69
+ getContext: () => ContextType<T>;
70
+ subscribe: ({ select, callback }: ContextSubscription<T>) => void;
71
+ private isObject;
72
+ private notifySubscribers;
73
+ private sendSubscriptionUpdate;
74
+ private handleSubscriptionRequest;
75
+ private onSubscriptionRequest;
76
+ private onContextRequest;
77
+ private registerEvents;
78
+ }
79
+ export {};
@@ -0,0 +1,5 @@
1
+ // @bun
2
+ import{e as N} from"../utils/attribute-utils.js";import{r as J,t as K} from"./events.js";var L="hydrate-context";class W{host;context;value;subscriptions=[];constructor(j,q){this.host=j,this.context=q.context;let z=q.initialValue;if(q.hydrate){const G=this.host.getAttribute(L);if(G){const F=N(G,q.hydrate);if(this.host.removeAttribute(L),q.hydrate===Object&&this.isObject(F)&&(this.isObject(z)||typeof z==="undefined"))z={...z??{},...F};else z=F}}this.value=z,this.registerEvents(),this.host.dispatchEvent(new K(this.context))}setContext=(j,q)=>{if(typeof this.value==="object"){const z={...this.value};if(this.value={...this.value,...j},q)q(this.value);this.notifySubscribers(this.value,z)}};getContext=()=>{return this.value};subscribe=({select:j,callback:q})=>{this.subscriptions.push({select:j,callback:q})};isObject(j){return typeof j==="object"&&!Array.isArray(j)&&j!==null}notifySubscribers=(j,q)=>{for(let z of this.subscriptions){if(!z.select)return this.sendSubscriptionUpdate(z,j);const G=z.select(j),F=z.select(q);if(G!==F)this.sendSubscriptionUpdate(z,j)}};sendSubscriptionUpdate=({select:j,callback:q},z)=>{if(!j)q(z);else q(j(z))};handleSubscriptionRequest=({select:j,callback:q,subscribe:z})=>{if(z)this.subscribe({select:j,callback:q});if(!this.value)return;if(j)q(j(this.value));else q(this.value)};onSubscriptionRequest=(j)=>{const{context:q,callback:z,subscribe:G,select:F,target:Q}=j;if(q!==this.context)return;j.stopPropagation(),Q.dispatchEvent(new K(this.context)),this.handleSubscriptionRequest({select:F,callback:z,subscribe:G})};onContextRequest=(j)=>{const{context:q,callback:z}=j;if(q!==this.context)return;j.stopPropagation(),z(this)};registerEvents=()=>{this.host.addEventListener(J.SUBSCRIPTION_REQUEST,this.onSubscriptionRequest),this.host.addEventListener(J.CONTEXT_REQUEST,this.onContextRequest)}}export{L as HYDRATE_ATTRIBUTE,W as ContextProvider};
3
+ export{L as p,W as q};
4
+
5
+ //# debugId=FE10FBA4E7E3258E64756e2164756e21
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/context/context-provider.ts"],
4
+ "sourcesContent": [
5
+ "import type { RadiantElement } from '@/core/radiant-element';\nimport { type AttributeTypeConstant, readAttributeValue } from '@/utils/attribute-utils';\nimport {\n ContextEventsTypes,\n ContextOnMountEvent,\n type ContextRequestEvent,\n type ContextSubscription,\n type ContextSubscriptionRequestEvent,\n} from './events';\nimport type { Context, ContextType, UnknownContext } from './types';\n\ntype ContextProviderOptions<T extends UnknownContext> = {\n context: UnknownContext;\n initialValue?: T['__context__'];\n hydrate?: AttributeTypeConstant;\n};\n\nexport const HYDRATE_ATTRIBUTE = 'hydrate-context';\n\n/**\n * Represents a context provider that allows setting and getting the context,\n * as well as subscribing to context updates.\n *\n * @template T - The type of the context.\n */\nexport interface IContextProvider<T extends Context<unknown, unknown>> {\n /**\n * Sets the context with the provided update and invokes the optional callback function.\n *\n * @param update - The partial update to be applied to the context.\n * @param callback - An optional callback function that receives the updated context.\n */\n setContext: (update: Partial<ContextType<T>>, callback?: (context: ContextType<T>) => void) => void;\n\n /**\n * Gets the current context.\n *\n * @returns The current context.\n */\n getContext: () => ContextType<T>;\n\n /**\n * Subscribes to context updates.\n *\n * @param subscription - The subscription object that defines the callback function to be invoked on context updates.\n */\n subscribe: (subscription: ContextSubscription<T>) => void;\n}\n\n/**\n * It creates a context provider that allows setting and getting the context,\n * It will also be in charge of notifying the subscribers when the context changes.\n *\n * @template T - The type of the context.\n * @implements IContextProvider\n *\n * @example\n * ```ts\n * export class MyElement extends RadiantElement {\n * provider = new ContextProvider<typeof myContext>(this, {\n * context: myContext,\n * initialValue: {\n * value: 'Hello World',\n * },\n * });\n * ```\n */\nexport class ContextProvider<T extends Context<unknown, unknown>> implements IContextProvider<T> {\n private host: RadiantElement;\n private context: UnknownContext;\n private value: ContextType<T> | undefined;\n subscriptions: ContextSubscription<T>[] = [];\n\n /**\n * Creates a new instance of the ContextProvider.\n *\n * @param host - The host element that will contain the context provider.\n * @param options - The options to configure the context provider.\n */\n constructor(host: RadiantElement, options: ContextProviderOptions<T>) {\n this.host = host;\n this.context = options.context;\n let contextValue: T['__context__'] | undefined = options.initialValue;\n\n if (options.hydrate) {\n const hydrationValue = this.host.getAttribute(HYDRATE_ATTRIBUTE);\n\n if (hydrationValue) {\n const parsedHydrationValue = readAttributeValue(hydrationValue, options.hydrate) as ContextType<T>;\n this.host.removeAttribute(HYDRATE_ATTRIBUTE);\n\n if (\n options.hydrate === Object &&\n this.isObject(parsedHydrationValue) &&\n (this.isObject(contextValue) || typeof contextValue === 'undefined')\n ) {\n contextValue = {\n ...(contextValue ?? {}),\n ...parsedHydrationValue,\n };\n } else {\n contextValue = parsedHydrationValue;\n }\n }\n }\n\n this.value = contextValue as ContextType<T>;\n\n this.registerEvents();\n this.host.dispatchEvent(new ContextOnMountEvent(this.context));\n }\n\n setContext = (update: Partial<ContextType<T>>, callback?: (context: ContextType<T>) => void) => {\n if (typeof this.value === 'object') {\n const oldContext = { ...this.value };\n this.value = { ...this.value, ...update };\n if (callback) callback(this.value);\n this.notifySubscribers(this.value, oldContext);\n }\n };\n\n getContext = () => {\n return this.value as ContextType<T>;\n };\n\n subscribe = ({ select, callback }: ContextSubscription<T>) => {\n this.subscriptions.push({ select, callback });\n };\n\n private isObject(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && !Array.isArray(value) && value !== null;\n }\n\n private notifySubscribers = (newContext: ContextType<T>, prevContext: ContextType<T>) => {\n for (const sub of this.subscriptions) {\n if (!sub.select) return this.sendSubscriptionUpdate(sub, newContext);\n const newSelected = sub.select(newContext);\n const prevSelected = sub.select(prevContext);\n if (newSelected !== prevSelected) {\n this.sendSubscriptionUpdate(sub, newContext);\n }\n }\n };\n\n private sendSubscriptionUpdate = ({ select, callback }: ContextSubscription<T>, context: ContextType<T>) => {\n if (!select) callback(context);\n else callback(select(context));\n };\n\n private handleSubscriptionRequest = ({\n select,\n callback,\n subscribe,\n }: {\n select?: ContextSubscription<T>['select'];\n callback: ContextSubscription<T>['callback'];\n subscribe?: boolean;\n }) => {\n if (subscribe) this.subscribe({ select, callback });\n\n if (!this.value) return;\n\n if (select) {\n callback(select(this.value));\n } else {\n callback(this.value as ContextType<T>);\n }\n };\n\n private onSubscriptionRequest = (event: ContextSubscriptionRequestEvent<UnknownContext>) => {\n const { context, callback, subscribe, select, target } = event;\n if (context !== this.context) return;\n\n event.stopPropagation();\n\n (target as HTMLElement).dispatchEvent(new ContextOnMountEvent(this.context));\n\n this.handleSubscriptionRequest({ select, callback, subscribe });\n };\n\n private onContextRequest = (event: ContextRequestEvent<UnknownContext>) => {\n const { context, callback } = event;\n if (context !== this.context) return;\n event.stopPropagation();\n callback(this);\n };\n\n private registerEvents = () => {\n this.host.addEventListener(ContextEventsTypes.SUBSCRIPTION_REQUEST, this.onSubscriptionRequest);\n this.host.addEventListener(ContextEventsTypes.CONTEXT_REQUEST, this.onContextRequest);\n };\n}\n"
6
+ ],
7
+ "mappings": ";AAiBO,IAAM,EAAoB,kBAkD1B,MAAM,CAAoF,CACvF,KACA,QACA,MACR,cAA0C,CAAC,EAQ3C,WAAW,CAAC,EAAsB,EAAoC,CACpE,KAAK,KAAO,EACZ,KAAK,QAAU,EAAQ,QACvB,IAAI,EAA6C,EAAQ,aAEzD,GAAI,EAAQ,QAAS,CACnB,MAAM,EAAiB,KAAK,KAAK,aAAa,CAAiB,EAE/D,GAAI,EAAgB,CAClB,MAAM,EAAuB,EAAmB,EAAgB,EAAQ,OAAO,EAG/E,GAFA,KAAK,KAAK,gBAAgB,CAAiB,EAGzC,EAAQ,UAAY,QACpB,KAAK,SAAS,CAAoB,IACjC,KAAK,SAAS,CAAY,UAAY,IAAiB,aAExD,EAAe,IACT,GAAgB,CAAC,KAClB,CACL,MAEA,GAAe,GAKrB,KAAK,MAAQ,EAEb,KAAK,eAAe,EACpB,KAAK,KAAK,cAAc,IAAI,EAAoB,KAAK,OAAO,CAAC,EAG/D,WAAa,CAAC,EAAiC,IAAiD,CAC9F,UAAW,KAAK,QAAU,SAAU,CAClC,MAAM,EAAa,IAAK,KAAK,KAAM,EAEnC,GADA,KAAK,MAAQ,IAAK,KAAK,SAAU,CAAO,EACpC,EAAU,EAAS,KAAK,KAAK,EACjC,KAAK,kBAAkB,KAAK,MAAO,CAAU,IAIjD,WAAa,IAAM,CACjB,OAAO,KAAK,OAGd,UAAY,EAAG,SAAQ,cAAuC,CAC5D,KAAK,cAAc,KAAK,CAAE,SAAQ,UAAS,CAAC,GAGtC,QAAQ,CAAC,EAAkD,CACjE,cAAc,IAAU,WAAa,MAAM,QAAQ,CAAK,GAAK,IAAU,KAGjE,kBAAoB,CAAC,EAA4B,IAAgC,CACvF,QAAW,KAAO,KAAK,cAAe,CACpC,IAAK,EAAI,OAAQ,OAAO,KAAK,uBAAuB,EAAK,CAAU,EACnE,MAAM,EAAc,EAAI,OAAO,CAAU,EACnC,EAAe,EAAI,OAAO,CAAW,EAC3C,GAAI,IAAgB,EAClB,KAAK,uBAAuB,EAAK,CAAU,IAKzC,uBAAyB,EAAG,SAAQ,YAAoC,IAA4B,CAC1G,IAAK,EAAQ,EAAS,CAAO,MACxB,GAAS,EAAO,CAAO,CAAC,GAGvB,0BAA4B,EAClC,SACA,WACA,eAKI,CACJ,GAAI,EAAW,KAAK,UAAU,CAAE,SAAQ,UAAS,CAAC,EAElD,IAAK,KAAK,MAAO,OAEjB,GAAI,EACF,EAAS,EAAO,KAAK,KAAK,CAAC,MAE3B,GAAS,KAAK,KAAuB,GAIjC,sBAAwB,CAAC,IAA2D,CAC1F,MAAQ,UAAS,WAAU,YAAW,SAAQ,UAAW,EACzD,GAAI,IAAY,KAAK,QAAS,OAE9B,EAAM,gBAAgB,EAErB,EAAuB,cAAc,IAAI,EAAoB,KAAK,OAAO,CAAC,EAE3E,KAAK,0BAA0B,CAAE,SAAQ,WAAU,WAAU,CAAC,GAGxD,iBAAmB,CAAC,IAA+C,CACzE,MAAQ,UAAS,YAAa,EAC9B,GAAI,IAAY,KAAK,QAAS,OAC9B,EAAM,gBAAgB,EACtB,EAAS,IAAI,GAGP,eAAiB,IAAM,CAC7B,KAAK,KAAK,iBAAiB,EAAmB,qBAAsB,KAAK,qBAAqB,EAC9F,KAAK,KAAK,iBAAiB,EAAmB,gBAAiB,KAAK,gBAAgB,EAExF",
8
+ "debugId": "FE10FBA4E7E3258E64756e2164756e21",
9
+ "names": []
10
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * A function which creates a Context value object
3
+ */
4
+ export declare const createContext: <ValueType>(key: unknown) => {
5
+ __context__: ValueType;
6
+ };
@@ -0,0 +1,5 @@
1
+ // @bun
2
+ var g=(d)=>d;export{g as createContext};
3
+ export{g as o};
4
+
5
+ //# debugId=F8452AD93E80293D64756e2164756e21
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/context/create-context.ts"],
4
+ "sourcesContent": [
5
+ "import type { Context } from './types';\n\n/**\n * A function which creates a Context value object\n */\nexport const createContext = <ValueType>(key: unknown) => key as Context<typeof key, ValueType>;\n"
6
+ ],
7
+ "mappings": ";AAKO,IAAM,EAAgB,CAAY,IAAiB",
8
+ "debugId": "F8452AD93E80293D64756e2164756e21",
9
+ "names": []
10
+ }
@@ -0,0 +1,8 @@
1
+ import type { UnknownContext } from '../../context/types';
2
+ import type { RadiantElement } from '../../core/radiant-element';
3
+ /**
4
+ * A decorator to provide a context to the target element.
5
+ * @param contextToProvide
6
+ * @returns
7
+ */
8
+ export declare function consumeContext(contextToProvide: UnknownContext): (proto: RadiantElement, propertyKey: string) => void;
@@ -0,0 +1,5 @@
1
+ // @bun
2
+ import{s as w} from"../events.js";function G(f){return(j,z)=>{const B=j.connectedCallback;j.connectedCallback=function(){B.call(this),this.dispatchEvent(new w(f,(D)=>{this[z]=D,this.connectedContextCallback(f)}))}}}export{G as consumeContext};
3
+ export{G as w};
4
+
5
+ //# debugId=1A6E04A48DB54F1464756e2164756e21
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/context/decorators/consume-context.ts"],
4
+ "sourcesContent": [
5
+ "import { ContextRequestEvent } from '@/context/events';\nimport type { UnknownContext } from '@/context/types';\nimport type { RadiantElement } from '@/core/radiant-element';\n\n/**\n * A decorator to provide a context to the target element.\n * @param contextToProvide\n * @returns\n */\nexport function consumeContext(contextToProvide: UnknownContext) {\n return (proto: RadiantElement, propertyKey: string) => {\n const originalConnectedCallback = proto.connectedCallback;\n\n proto.connectedCallback = function (this: RadiantElement) {\n originalConnectedCallback.call(this);\n this.dispatchEvent(\n new ContextRequestEvent(contextToProvide, (context) => {\n (this as any)[propertyKey] = context;\n this.connectedContextCallback(contextToProvide);\n }),\n );\n };\n };\n}\n"
6
+ ],
7
+ "mappings": ";AASO,SAAS,CAAc,CAAC,EAAkC,CAC/D,MAAO,CAAC,EAAuB,IAAwB,CACrD,MAAM,EAA4B,EAAM,kBAExC,EAAM,0BAA6B,EAAuB,CACxD,EAA0B,KAAK,IAAI,EACnC,KAAK,cACH,IAAI,EAAoB,EAAkB,CAAC,IAAY,CACrD,AAAC,KAAa,GAAe,EAC7B,KAAK,yBAAyB,CAAgB,EAC/C,CACH",
8
+ "debugId": "1A6E04A48DB54F1464756e2164756e21",
9
+ "names": []
10
+ }
@@ -0,0 +1,16 @@
1
+ import type { Context, UnknownContext } from '../../context/types';
2
+ import type { RadiantElement } from '../../core/radiant-element';
3
+ type SubscribeToContextOptions<T extends UnknownContext> = {
4
+ context: T;
5
+ select?: (context: T['__context__']) => unknown;
6
+ subscribe?: boolean;
7
+ };
8
+ /**
9
+ * A decorator to subscribe to a context selector.
10
+ * @param context The context to subscribe to.
11
+ * @param selector The selector to subscribe to. If not provided, the whole context will be subscribed to.
12
+ * @param subscribe @default true Whether to subscribe or unsubscribe. Optional.
13
+ * @returns
14
+ */
15
+ export declare function contextSelector<T extends Context<unknown, unknown>>({ context, select, subscribe, }: SubscribeToContextOptions<T>): (proto: RadiantElement, _: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
16
+ export {};
@@ -0,0 +1,5 @@
1
+ // @bun
2
+ import{u as B} from"../events.js";function P({context:D,select:F,subscribe:G=!0}){return(y,K,j)=>{const z=j.value,H=y.connectedCallback;return y.connectedCallback=function(){H.call(this),this.dispatchEvent(new B(D,z.bind(this),F,G))},j.value=function(...J){return z.apply(this,J)},j}}export{P as contextSelector};
3
+ export{P as v};
4
+
5
+ //# debugId=AE94B44A98968FC164756e2164756e21
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/context/decorators/context-selector.ts"],
4
+ "sourcesContent": [
5
+ "import { ContextSubscriptionRequestEvent } from '@/context/events';\nimport type { Context, ContextType, UnknownContext } from '@/context/types';\nimport type { RadiantElement } from '@/core/radiant-element';\n\ntype ArgsType<T extends UnknownContext> = SubscribeToContextOptions<T>['select'] extends (...args: any[]) => infer R\n ? R\n : ContextType<T>;\n\ntype SubscribeToContextOptions<T extends UnknownContext> = {\n context: T;\n select?: (context: T['__context__']) => unknown;\n subscribe?: boolean;\n};\n/**\n * A decorator to subscribe to a context selector.\n * @param context The context to subscribe to.\n * @param selector The selector to subscribe to. If not provided, the whole context will be subscribed to.\n * @param subscribe @default true Whether to subscribe or unsubscribe. Optional.\n * @returns\n */\nexport function contextSelector<T extends Context<unknown, unknown>>({\n context,\n select,\n subscribe = true,\n}: SubscribeToContextOptions<T>) {\n return (proto: RadiantElement, _: string, descriptor: PropertyDescriptor) => {\n const originalMethod = descriptor.value;\n const originalConnectedCallback = proto.connectedCallback;\n\n proto.connectedCallback = function (this: RadiantElement) {\n originalConnectedCallback.call(this);\n\n this.dispatchEvent(new ContextSubscriptionRequestEvent(context, originalMethod.bind(this), select, subscribe));\n };\n\n descriptor.value = function (...args: ArgsType<T>[]) {\n const result = originalMethod.apply(this, args);\n return result;\n };\n\n return descriptor;\n };\n}\n"
6
+ ],
7
+ "mappings": ";AAoBO,SAAS,CAAoD,EAClE,UACA,SACA,YAAY,IACmB,CAC/B,MAAO,CAAC,EAAuB,EAAW,IAAmC,CAC3E,MAAM,EAAiB,EAAW,MAC5B,EAA4B,EAAM,kBAaxC,OAXA,EAAM,0BAA6B,EAAuB,CACxD,EAA0B,KAAK,IAAI,EAEnC,KAAK,cAAc,IAAI,EAAgC,EAAS,EAAe,KAAK,IAAI,EAAG,EAAQ,CAAS,CAAC,GAG/G,EAAW,cAAiB,IAAI,EAAqB,CAEnD,OADe,EAAe,MAAM,KAAM,CAAI,GAIzC",
8
+ "debugId": "AE94B44A98968FC164756e2164756e21",
9
+ "names": []
10
+ }
@@ -0,0 +1,15 @@
1
+ import type { UnknownContext } from '../../context/types';
2
+ import type { RadiantElement } from '../../core/radiant-element';
3
+ import type { AttributeTypeConstant } from '../../utils/attribute-utils';
4
+ type CreateContextOptions<T extends UnknownContext> = {
5
+ context: T;
6
+ initialValue?: T['__context__'];
7
+ hydrate?: AttributeTypeConstant;
8
+ };
9
+ /**
10
+ * A decorator to provide a context to the target element.
11
+ * @param contextToProvide
12
+ * @returns
13
+ */
14
+ export declare function provideContext<T extends UnknownContext>({ context, initialValue, hydrate }: CreateContextOptions<T>): (proto: RadiantElement, propertyKey: string) => void;
15
+ export {};
@@ -0,0 +1,5 @@
1
+ // @bun
2
+ import"../../utils/attribute-utils.js";import{q} from"../context-provider.js";import"../events.js";function F({context:f,initialValue:w,hydrate:z}){return(j,B)=>{const D=j.connectedCallback;j.connectedCallback=function(){D.call(this),this[B]=new q(this,{context:f,initialValue:w,hydrate:z}),this.connectedContextCallback(f)}}}export{F as provideContext};
3
+ export{F as x};
4
+
5
+ //# debugId=F099552890D552B964756e2164756e21
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/context/decorators/provide-context.ts"],
4
+ "sourcesContent": [
5
+ "import { ContextProvider } from '@/context/context-provider';\nimport type { UnknownContext } from '@/context/types';\nimport type { RadiantElement } from '@/core/radiant-element';\nimport type { AttributeTypeConstant } from '@/utils/attribute-utils';\n\ntype CreateContextOptions<T extends UnknownContext> = {\n context: T;\n initialValue?: T['__context__'];\n hydrate?: AttributeTypeConstant;\n};\n\n/**\n * A decorator to provide a context to the target element.\n * @param contextToProvide\n * @returns\n */\nexport function provideContext<T extends UnknownContext>({ context, initialValue, hydrate }: CreateContextOptions<T>) {\n return (proto: RadiantElement, propertyKey: string) => {\n const originalConnectedCallback = proto.connectedCallback;\n\n proto.connectedCallback = function (this: RadiantElement) {\n originalConnectedCallback.call(this);\n (this as any)[propertyKey] = new ContextProvider<T>(this, { context, initialValue, hydrate });\n this.connectedContextCallback(context);\n };\n };\n}\n"
6
+ ],
7
+ "mappings": ";AAgBO,SAAS,CAAwC,EAAG,UAAS,eAAc,WAAoC,CACpH,MAAO,CAAC,EAAuB,IAAwB,CACrD,MAAM,EAA4B,EAAM,kBAExC,EAAM,0BAA6B,EAAuB,CACxD,EAA0B,KAAK,IAAI,EAClC,KAAa,GAAe,IAAI,EAAmB,KAAM,CAAE,UAAS,eAAc,SAAQ,CAAC,EAC5F,KAAK,yBAAyB,CAAO",
8
+ "debugId": "F099552890D552B964756e2164756e21",
9
+ "names": []
10
+ }
@@ -0,0 +1,82 @@
1
+ import type { Context, ContextCallback, ContextType, UnknownContext } from './types';
2
+ /**
3
+ * List of events which can be emitted by a context provider or requester.
4
+ */
5
+ export declare enum ContextEventsTypes {
6
+ SUBSCRIPTION_REQUEST = "context--subscription-request",
7
+ CONTEXT_REQUEST = "context-request",
8
+ ON_MOUNT = "context--on-mount"
9
+ }
10
+ /**
11
+ * An event fired by a context requester to signal it desires a named context.
12
+ *
13
+ * A provider should inspect the `context` property of the event to determine if it has a value that can
14
+ * satisfy the request, calling the `callback` with the requested value if so.
15
+ *
16
+ * If the requested context event contains a truthy `subscribe` value, then a provider can call the callback
17
+ * multiple times if the value is changed, if this is the case the provider should pass an `unsubscribe`
18
+ * function to the callback which requesters can invoke to indicate they no longer wish to receive these updates.
19
+ */
20
+ export declare class ContextRequestEvent<T extends UnknownContext> extends Event {
21
+ readonly context: T;
22
+ readonly callback: ContextCallback<ContextType<T>>;
23
+ readonly subscribe?: boolean | undefined;
24
+ constructor(context: T, callback: ContextCallback<ContextType<T>>, subscribe?: boolean | undefined);
25
+ }
26
+ /**
27
+ * A type which represents a subscription to a context value.
28
+ */
29
+ export type ContextSubscription<T extends UnknownContext> = {
30
+ select?: (context: ContextType<T>) => unknown;
31
+ callback: (value: unknown) => void;
32
+ };
33
+ /**
34
+ * An event fired by a context provider to signal that a context value has been mounted and is available for consumption.
35
+ */
36
+ export declare class ContextOnMountEvent extends CustomEvent<{
37
+ context: UnknownContext;
38
+ }> {
39
+ constructor(context: UnknownContext);
40
+ }
41
+ /**
42
+ * An event fired by a context requester to signal it desires a named context.
43
+ *
44
+ * A provider should inspect the `context` property of the event to determine if it has a value that can
45
+ * satisfy the request, calling the `callback` with the requested value if so.
46
+ *
47
+ * If the requested context event contains a truthy `subscribe` value, then a provider can call the callback
48
+ * multiple times if the value is changed, if this is the case the provider should pass an `unsubscribe`
49
+ * function to the callback which requesters can invoke to indicate they no longer wish to receive these updates.
50
+ *
51
+ * It accepts a `selector` property which can be used to request a specific property of the context value.
52
+ */
53
+ export declare class ContextSubscriptionRequestEvent<T extends UnknownContext> extends Event {
54
+ readonly context: T;
55
+ readonly callback: (value: ContextType<T> | {
56
+ [K in keyof ContextType<T>]: ContextType<T>[K];
57
+ }) => void;
58
+ readonly select?: ((context: ContextType<T>) => unknown) | undefined;
59
+ readonly subscribe?: boolean | undefined;
60
+ constructor(context: T, callback: (value: ContextType<T> | {
61
+ [K in keyof ContextType<T>]: ContextType<T>[K];
62
+ }) => void, select?: ((context: ContextType<T>) => unknown) | undefined, subscribe?: boolean | undefined);
63
+ }
64
+ declare global {
65
+ interface HTMLElementEventMap {
66
+ /**
67
+ * A 'context-request-subscription' event can be emitted by any element which desires
68
+ * a context value to be injected by an external provider.
69
+ */
70
+ [ContextEventsTypes.SUBSCRIPTION_REQUEST]: ContextSubscriptionRequestEvent<UnknownContext>;
71
+ /**
72
+ * A context-request-provider event can be emitted by a context requester to signal
73
+ * that it desires a context value to be provided by a context provider.
74
+ */
75
+ [ContextEventsTypes.CONTEXT_REQUEST]: ContextRequestEvent<Context<unknown, unknown>>;
76
+ /**
77
+ * A 'context-mount' event can be emitted by a context provider to signal
78
+ * that a context value has been mounted and is available for consumption.
79
+ */
80
+ [ContextEventsTypes.ON_MOUNT]: ContextOnMountEvent;
81
+ }
82
+ }
@@ -0,0 +1,5 @@
1
+ // @bun
2
+ var k;(function(j){j["SUBSCRIPTION_REQUEST"]="context--subscription-request";j["CONTEXT_REQUEST"]="context-request";j["ON_MOUNT"]="context--on-mount"})(k||(k={}));class B extends Event{q;w;z;constructor(q,w,z){super(k.CONTEXT_REQUEST,{bubbles:!0,composed:!0});this.context=q;this.callback=w;this.subscribe=z}}class D extends CustomEvent{constructor(q){super(k.ON_MOUNT,{detail:{context:q},bubbles:!0,composed:!0})}}class F extends Event{q;w;z;j;constructor(q,w,z,j){super(k.SUBSCRIPTION_REQUEST,{bubbles:!0,composed:!0});this.context=q;this.callback=w;this.select=z;this.subscribe=j}}export{F as ContextSubscriptionRequestEvent,B as ContextRequestEvent,D as ContextOnMountEvent,k as ContextEventsTypes};
3
+ export{k as r,B as s,D as t,F as u};
4
+
5
+ //# debugId=15733A88DF2B29D264756e2164756e21
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/context/events.ts"],
4
+ "sourcesContent": [
5
+ "import type { Context, ContextCallback, ContextType, UnknownContext } from './types';\n\n/**\n * List of events which can be emitted by a context provider or requester.\n */\nexport enum ContextEventsTypes {\n SUBSCRIPTION_REQUEST = 'context--subscription-request',\n CONTEXT_REQUEST = 'context-request',\n ON_MOUNT = 'context--on-mount',\n}\n\n/**\n * An event fired by a context requester to signal it desires a named context.\n *\n * A provider should inspect the `context` property of the event to determine if it has a value that can\n * satisfy the request, calling the `callback` with the requested value if so.\n *\n * If the requested context event contains a truthy `subscribe` value, then a provider can call the callback\n * multiple times if the value is changed, if this is the case the provider should pass an `unsubscribe`\n * function to the callback which requesters can invoke to indicate they no longer wish to receive these updates.\n */\nexport class ContextRequestEvent<T extends UnknownContext> extends Event {\n public constructor(\n public readonly context: T,\n public readonly callback: ContextCallback<ContextType<T>>,\n public readonly subscribe?: boolean,\n ) {\n super(ContextEventsTypes.CONTEXT_REQUEST, { bubbles: true, composed: true });\n }\n}\n\n/**\n * A type which represents a subscription to a context value.\n */\nexport type ContextSubscription<T extends UnknownContext> = {\n select?: (context: ContextType<T>) => unknown;\n callback: (value: unknown) => void;\n};\n\n/**\n * An event fired by a context provider to signal that a context value has been mounted and is available for consumption.\n */\nexport class ContextOnMountEvent extends CustomEvent<{ context: UnknownContext }> {\n public constructor(context: UnknownContext) {\n super(ContextEventsTypes.ON_MOUNT, {\n detail: { context },\n bubbles: true,\n composed: true,\n });\n }\n}\n\n/**\n * An event fired by a context requester to signal it desires a named context.\n *\n * A provider should inspect the `context` property of the event to determine if it has a value that can\n * satisfy the request, calling the `callback` with the requested value if so.\n *\n * If the requested context event contains a truthy `subscribe` value, then a provider can call the callback\n * multiple times if the value is changed, if this is the case the provider should pass an `unsubscribe`\n * function to the callback which requesters can invoke to indicate they no longer wish to receive these updates.\n *\n * It accepts a `selector` property which can be used to request a specific property of the context value.\n */\nexport class ContextSubscriptionRequestEvent<T extends UnknownContext> extends Event {\n public constructor(\n public readonly context: T,\n public readonly callback: (value: ContextType<T> | { [K in keyof ContextType<T>]: ContextType<T>[K] }) => void,\n public readonly select?: (context: ContextType<T>) => unknown,\n public readonly subscribe?: boolean,\n ) {\n super(ContextEventsTypes.SUBSCRIPTION_REQUEST, {\n bubbles: true,\n composed: true,\n });\n }\n}\n\ndeclare global {\n interface HTMLElementEventMap {\n /**\n * A 'context-request-subscription' event can be emitted by any element which desires\n * a context value to be injected by an external provider.\n */\n [ContextEventsTypes.SUBSCRIPTION_REQUEST]: ContextSubscriptionRequestEvent<UnknownContext>;\n /**\n * A context-request-provider event can be emitted by a context requester to signal\n * that it desires a context value to be provided by a context provider.\n */\n [ContextEventsTypes.CONTEXT_REQUEST]: ContextRequestEvent<Context<unknown, unknown>>;\n /**\n * A 'context-mount' event can be emitted by a context provider to signal\n * that a context value has been mounted and is available for consumption.\n */\n [ContextEventsTypes.ON_MOUNT]: ContextOnMountEvent;\n }\n}\n"
6
+ ],
7
+ "mappings": ";AAKO,IAAK,EAAL,UAAK,EAAL,CACL,0BAAuB,gCACvB,qBAAkB,kBAClB,cAAW,sBAHD,WAgBL,MAAM,UAAsD,KAAM,CAErD,EACA,EACA,EAHX,WAAW,CACA,EACA,EACA,EAChB,CACA,MAAM,EAAmB,gBAAiB,CAAE,QAAS,GAAM,SAAU,EAAK,CAAC,EAJ3D,eACA,gBACA,iBAIpB,CAaO,MAAM,UAA4B,WAAyC,CACzE,WAAW,CAAC,EAAyB,CAC1C,MAAM,EAAmB,SAAU,CACjC,OAAQ,CAAE,SAAQ,EAClB,QAAS,GACT,SAAU,EACZ,CAAC,EAEL,CAcO,MAAM,UAAkE,KAAM,CAEjE,EACA,EACA,EACA,EAJX,WAAW,CACA,EACA,EACA,EACA,EAChB,CACA,MAAM,EAAmB,qBAAsB,CAC7C,QAAS,GACT,SAAU,EACZ,CAAC,EARe,eACA,gBACA,cACA,iBAOpB",
8
+ "debugId": "15733A88DF2B29D264756e2164756e21",
9
+ "names": []
10
+ }
@@ -0,0 +1,7 @@
1
+ export * from './create-context';
2
+ export * from './context-provider';
3
+ export * from './events';
4
+ export * from './decorators/provide-context';
5
+ export * from './decorators/consume-context';
6
+ export * from './decorators/context-selector';
7
+ export * from './types';
@@ -0,0 +1,4 @@
1
+ // @bun
2
+ import"../utils/attribute-utils.js";import{o as a} from"./create-context.js";import{p as h,q as i} from"./context-provider.js";import"./types.js";import{r as b,s as c,t as d,u as g} from"./events.js";import{v as l} from"./decorators/context-selector.js";import{w as k} from"./decorators/consume-context.js";import{x as j} from"./decorators/provide-context.js";export{j as provideContext,a as createContext,l as contextSelector,k as consumeContext,h as HYDRATE_ATTRIBUTE,g as ContextSubscriptionRequestEvent,c as ContextRequestEvent,i as ContextProvider,d as ContextOnMountEvent,b as ContextEventsTypes};
3
+
4
+ //# debugId=A6D9A0F3C0C4945E64756e2164756e21
@@ -0,0 +1,9 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [
5
+ ],
6
+ "mappings": "",
7
+ "debugId": "A6D9A0F3C0C4945E64756e2164756e21",
8
+ "names": []
9
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * A context key.
3
+ *
4
+ * A context key can be any type of object, including strings and symbols. The
5
+ * Context type brands the key type with the `__context__` property that
6
+ * carries the type of the value the context references.
7
+ */
8
+ export type Context<KeyType, ValueType> = KeyType & {
9
+ __context__: ValueType;
10
+ };
11
+ /**
12
+ * An unknown context type
13
+ */
14
+ export type UnknownContext = Context<unknown, unknown>;
15
+ /**
16
+ * A helper type which can extract a Context value type from a Context type
17
+ */
18
+ export type ContextType<T extends UnknownContext> = T extends Context<infer _, infer V> ? V : never;
19
+ /**
20
+ * A callback which is provided by a context requester and is called with the value satisfying the request.
21
+ * This callback can be called multiple times by context providers as the requested value is changed.
22
+ */
23
+ export type ContextCallback<ValueType> = (value: ValueType, unsubscribe?: () => void) => void;
@@ -0,0 +1,3 @@
1
+ // @bun
2
+
3
+ //# debugId=54FB8063F25A011864756e2164756e21
@@ -0,0 +1,9 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [
5
+ ],
6
+ "mappings": "",
7
+ "debugId": "54FB8063F25A011864756e2164756e21",
8
+ "names": []
9
+ }
@@ -0,0 +1 @@
1
+ export * from './radiant-element';
@@ -0,0 +1,4 @@
1
+ // @bun
2
+ import{n as e} from"./radiant-element.js";export{e as RadiantElement};
3
+
4
+ //# debugId=8B19A1A5300BFC3764756e2164756e21
@@ -0,0 +1,9 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [
5
+ ],
6
+ "mappings": "",
7
+ "debugId": "8B19A1A5300BFC3764756e2164756e21",
8
+ "names": []
9
+ }
@@ -0,0 +1,81 @@
1
+ import type { UnknownContext } from '../context/types';
2
+ export type RenderInsertPosition = 'replace' | 'beforebegin' | 'afterbegin' | 'beforeend' | 'afterend';
3
+ /**
4
+ * Represents a Radiant element event listener.
5
+ */
6
+ export type RadiantElementEventListener = {
7
+ selector: string;
8
+ type: string;
9
+ listener: EventListener;
10
+ id: string;
11
+ options?: AddEventListenerOptions;
12
+ };
13
+ /**
14
+ * Represents an interface for a Radiant element.
15
+ */
16
+ export interface IRadiantElement {
17
+ /**
18
+ * Called when a property of the element is updated.
19
+ * @param changedProperty - The name of the changed property.
20
+ * @param oldValue - The old value of the property.
21
+ * @param newValue - The new value of the property.
22
+ */
23
+ updated(changedProperty: string, oldValue: unknown, newValue: unknown): void;
24
+ /**
25
+ * Subscribes to a Radiant element event.
26
+ * @param event - The event listener to subscribe to.
27
+ */
28
+ subscribeEvent(event: RadiantElementEventListener): void;
29
+ /**
30
+ * Subscribes to multiple Radiant element events.
31
+ * @param events - The array of event listeners to subscribe to.
32
+ */
33
+ subscribeEvents(events: RadiantElementEventListener[]): void;
34
+ /**
35
+ * Unsubscribes from a Radiant element event.
36
+ * @param id - The ID of the event listener to unsubscribe from.
37
+ */
38
+ unsubscribeEvent(id: string): void;
39
+ /**
40
+ * Removes all subscribed events from the Radiant element.
41
+ */
42
+ removeAllSubscribedEvents(): void;
43
+ /**
44
+ * Renders a template into the specified target element.
45
+ * @param options - The rendering options.
46
+ * @param options.target - The target element to render the template into.
47
+ * @param options.template - The template string to render.
48
+ * @param options.insert - The position to insert the rendered template. (optional)
49
+ */
50
+ renderTemplate(options: {
51
+ target: HTMLElement;
52
+ template: string;
53
+ insert?: RenderInsertPosition;
54
+ }): void;
55
+ /**
56
+ * Called when the Radiant element is connected to a context.
57
+ * @param context - The connected context.
58
+ */
59
+ connectedContextCallback(context: UnknownContext): void;
60
+ }
61
+ /**
62
+ * A base class for creating custom elements with reactive properties and event subscriptions.
63
+ * @extends HTMLElement
64
+ * @implements IRadiantElement
65
+ */
66
+ export declare class RadiantElement extends HTMLElement implements IRadiantElement {
67
+ private eventSubscriptions;
68
+ connectedCallback(): void;
69
+ connectedContextCallback(_contextName: UnknownContext): void;
70
+ disconnectedCallback(): void;
71
+ updated(_changedProperty: string, _oldValue: unknown, _value: unknown): void;
72
+ renderTemplate({ target, template, insert, }: {
73
+ target: HTMLElement;
74
+ template: string;
75
+ insert?: RenderInsertPosition;
76
+ }): void;
77
+ subscribeEvents(events: RadiantElementEventListener[]): void;
78
+ subscribeEvent(eventConfig: RadiantElementEventListener): void;
79
+ unsubscribeEvent(id: string): void;
80
+ removeAllSubscribedEvents(): void;
81
+ }
@@ -0,0 +1,5 @@
1
+ // @bun
2
+ class y extends HTMLElement{constructor(){super(...arguments)}eventSubscriptions=new Map;connectedCallback(){}connectedContextCallback(j){}disconnectedCallback(){this.removeAllSubscribedEvents()}updated(j,k,q){}renderTemplate({target:j=this,template:k,insert:q="replace"}){switch(q){case"replace":j.innerHTML=k;break;case"beforeend":j.insertAdjacentHTML("beforeend",k);break;case"afterbegin":j.insertAdjacentHTML("afterbegin",k);break}}subscribeEvents(j){for(let k of j)this.subscribeEvent(k)}subscribeEvent(j){const k=(q)=>{if(q.target&&q.target.matches(j.selector))j.listener.call(this,q)};this.addEventListener(j.type,k,j.options),this.eventSubscriptions.set(j.id,{...j,listener:k})}unsubscribeEvent(j){const k=this.eventSubscriptions.get(j);if(k)this.removeEventListener(k.type,k.listener,k.options),this.eventSubscriptions.delete(j)}removeAllSubscribedEvents(){for(let j of this.eventSubscriptions.values())this.removeEventListener(j.type,j.listener,j.options);this.eventSubscriptions.clear()}}export{y as RadiantElement};
3
+ export{y as n};
4
+
5
+ //# debugId=DE3DCE13F0E22E4A64756e2164756e21
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/core/radiant-element.ts"],
4
+ "sourcesContent": [
5
+ "import type { UnknownContext } from '@/context/types';\n\nexport type RenderInsertPosition = 'replace' | 'beforebegin' | 'afterbegin' | 'beforeend' | 'afterend';\n\n/**\n * Represents a Radiant element event listener.\n */\nexport type RadiantElementEventListener = {\n selector: string;\n type: string;\n listener: EventListener;\n id: string;\n options?: AddEventListenerOptions;\n};\n\n/**\n * Represents an interface for a Radiant element.\n */\nexport interface IRadiantElement {\n /**\n * Called when a property of the element is updated.\n * @param changedProperty - The name of the changed property.\n * @param oldValue - The old value of the property.\n * @param newValue - The new value of the property.\n */\n updated(changedProperty: string, oldValue: unknown, newValue: unknown): void;\n\n /**\n * Subscribes to a Radiant element event.\n * @param event - The event listener to subscribe to.\n */\n subscribeEvent(event: RadiantElementEventListener): void;\n\n /**\n * Subscribes to multiple Radiant element events.\n * @param events - The array of event listeners to subscribe to.\n */\n subscribeEvents(events: RadiantElementEventListener[]): void;\n\n /**\n * Unsubscribes from a Radiant element event.\n * @param id - The ID of the event listener to unsubscribe from.\n */\n unsubscribeEvent(id: string): void;\n\n /**\n * Removes all subscribed events from the Radiant element.\n */\n removeAllSubscribedEvents(): void;\n\n /**\n * Renders a template into the specified target element.\n * @param options - The rendering options.\n * @param options.target - The target element to render the template into.\n * @param options.template - The template string to render.\n * @param options.insert - The position to insert the rendered template. (optional)\n */\n renderTemplate(options: {\n target: HTMLElement;\n template: string;\n insert?: RenderInsertPosition;\n }): void;\n\n /**\n * Called when the Radiant element is connected to a context.\n * @param context - The connected context.\n */\n connectedContextCallback(context: UnknownContext): void;\n}\n\n/**\n * A base class for creating custom elements with reactive properties and event subscriptions.\n * @extends HTMLElement\n * @implements IRadiantElement\n */\nexport class RadiantElement extends HTMLElement implements IRadiantElement {\n private eventSubscriptions = new Map<string, RadiantElementEventListener>();\n\n connectedCallback() {}\n\n connectedContextCallback(_contextName: UnknownContext): void {}\n\n disconnectedCallback() {\n this.removeAllSubscribedEvents();\n }\n\n updated(_changedProperty: string, _oldValue: unknown, _value: unknown) {}\n\n renderTemplate({\n target = this,\n template,\n insert = 'replace',\n }: {\n target: HTMLElement;\n template: string;\n insert?: RenderInsertPosition;\n }) {\n switch (insert) {\n case 'replace':\n target.innerHTML = template;\n break;\n case 'beforeend':\n target.insertAdjacentHTML('beforeend', template);\n break;\n case 'afterbegin':\n target.insertAdjacentHTML('afterbegin', template);\n break;\n }\n }\n\n public subscribeEvents(events: RadiantElementEventListener[]): void {\n for (const event of events) {\n this.subscribeEvent(event);\n }\n }\n\n public subscribeEvent(eventConfig: RadiantElementEventListener): void {\n const delegatedListener = (delegatedEvent: Event) => {\n if (delegatedEvent.target && (delegatedEvent.target as Element).matches(eventConfig.selector)) {\n eventConfig.listener.call(this, delegatedEvent);\n }\n };\n\n this.addEventListener(eventConfig.type, delegatedListener, eventConfig.options);\n this.eventSubscriptions.set(eventConfig.id, { ...eventConfig, listener: delegatedListener });\n }\n\n public unsubscribeEvent(id: string): void {\n const eventSubscription = this.eventSubscriptions.get(id);\n if (eventSubscription) {\n this.removeEventListener(eventSubscription.type, eventSubscription.listener, eventSubscription.options);\n this.eventSubscriptions.delete(id);\n }\n }\n\n public removeAllSubscribedEvents(): void {\n for (const eventSubscription of this.eventSubscriptions.values()) {\n this.removeEventListener(eventSubscription.type, eventSubscription.listener, eventSubscription.options);\n }\n this.eventSubscriptions.clear();\n }\n}\n"
6
+ ],
7
+ "mappings": ";AA2EO,MAAM,UAAuB,WAAuC,CAApE,kCACG,mBAAqB,IAAI,IAEjC,iBAAiB,EAAG,EAEpB,wBAAwB,CAAC,EAAoC,EAE7D,oBAAoB,EAAG,CACrB,KAAK,0BAA0B,EAGjC,OAAO,CAAC,EAA0B,EAAoB,EAAiB,EAEvE,cAAc,EACZ,SAAS,KACT,WACA,SAAS,WAKR,CACD,OAAQ,OACD,UACH,EAAO,UAAY,EACnB,UACG,YACH,EAAO,mBAAmB,YAAa,CAAQ,EAC/C,UACG,aACH,EAAO,mBAAmB,aAAc,CAAQ,EAChD,OAIC,eAAe,CAAC,EAA6C,CAClE,QAAW,KAAS,EAClB,KAAK,eAAe,CAAK,EAItB,cAAc,CAAC,EAAgD,CACpE,MAAM,EAAoB,CAAC,IAA0B,CACnD,GAAI,EAAe,QAAW,EAAe,OAAmB,QAAQ,EAAY,QAAQ,EAC1F,EAAY,SAAS,KAAK,KAAM,CAAc,GAIlD,KAAK,iBAAiB,EAAY,KAAM,EAAmB,EAAY,OAAO,EAC9E,KAAK,mBAAmB,IAAI,EAAY,GAAI,IAAK,EAAa,SAAU,CAAkB,CAAC,EAGtF,gBAAgB,CAAC,EAAkB,CACxC,MAAM,EAAoB,KAAK,mBAAmB,IAAI,CAAE,EACxD,GAAI,EACF,KAAK,oBAAoB,EAAkB,KAAM,EAAkB,SAAU,EAAkB,OAAO,EACtG,KAAK,mBAAmB,OAAO,CAAE,EAI9B,yBAAyB,EAAS,CACvC,QAAW,KAAqB,KAAK,mBAAmB,OAAO,EAC7D,KAAK,oBAAoB,EAAkB,KAAM,EAAkB,SAAU,EAAkB,OAAO,EAExG,KAAK,mBAAmB,MAAM,EAElC",
8
+ "debugId": "DE3DCE13F0E22E4A64756e2164756e21",
9
+ "names": []
10
+ }