coralite 0.38.6 → 0.39.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/dist/lib/coralite-element.d.ts +8 -1
- package/dist/lib/coralite-element.d.ts.map +1 -1
- package/dist/lib/coralite-element.js +7 -11
- package/dist/lib/coralite-element.js.map +2 -2
- package/dist/lib/coralite.d.ts.map +1 -1
- package/dist/lib/index.js +73 -32
- package/dist/lib/index.js.map +3 -3
- package/dist/lib/plugin.js +2 -0
- package/dist/lib/plugin.js.map +2 -2
- package/dist/lib/renderer.d.ts.map +1 -1
- package/dist/lib/script-manager.d.ts.map +1 -1
- package/dist/lib/utils/client/inject.js +2 -0
- package/dist/lib/utils/client/inject.js.map +2 -2
- package/dist/lib/utils/client/runtime.d.ts +3 -1
- package/dist/lib/utils/client/runtime.d.ts.map +1 -1
- package/dist/lib/utils/core.d.ts +10 -0
- package/dist/lib/utils/core.d.ts.map +1 -1
- package/dist/lib/utils/core.js +36 -1
- package/dist/lib/utils/core.js.map +2 -2
- package/dist/lib/utils/errors.d.ts +3 -0
- package/dist/lib/utils/errors.d.ts.map +1 -1
- package/dist/lib/utils/index.js +37 -1
- package/dist/lib/utils/index.js.map +2 -2
- package/dist/types/core.d.ts +5 -0
- package/dist/types/core.d.ts.map +1 -1
- package/llms.txt +1 -0
- package/package.json +1 -1
|
@@ -15,13 +15,14 @@ export function coerce(value: any, type: Function | string): any;
|
|
|
15
15
|
* @param {Array<CoraliteClientPluginBeforeComponentRenderCallback>} [hooks.onBeforeComponentRender] - Hooks to run before render.
|
|
16
16
|
* @param {Array<CoraliteClientPluginAfterComponentRenderCallback>} [hooks.onAfterComponentRender] - Hooks to run after render.
|
|
17
17
|
* @param {Array<CoraliteClientPluginDisconnectedCallback>} [hooks.onDisconnected] - Hooks to run after render.
|
|
18
|
+
* @param {Object|null} [hydrationData=null] - Hydrated data passed from the server.
|
|
18
19
|
* @returns {typeof CoraliteElement} A new CoraliteElement subclass.
|
|
19
20
|
*/
|
|
20
21
|
export function createCoraliteClass(options: CoraliteComponentOptions, contextGetter?: Function | null, hooks?: {
|
|
21
22
|
onBeforeComponentRender?: Array<CoraliteClientPluginBeforeComponentRenderCallback>;
|
|
22
23
|
onAfterComponentRender?: Array<CoraliteClientPluginAfterComponentRenderCallback>;
|
|
23
24
|
onDisconnected?: Array<CoraliteClientPluginDisconnectedCallback>;
|
|
24
|
-
}): typeof CoraliteElement;
|
|
25
|
+
}, hydrationData?: any | null): typeof CoraliteElement;
|
|
25
26
|
/**
|
|
26
27
|
* @typedef {Object} CoraliteComponentOptions
|
|
27
28
|
* @property {string} componentId - The unique identifier for the component.
|
|
@@ -118,6 +119,12 @@ export class CoraliteElement extends HTMLElement {
|
|
|
118
119
|
* @type {CoraliteComponentOptions|null}
|
|
119
120
|
*/
|
|
120
121
|
componentOptions: CoraliteComponentOptions | null;
|
|
122
|
+
/**
|
|
123
|
+
* Hydrated data passed from the server.
|
|
124
|
+
* @type {Object|null}
|
|
125
|
+
* @protected
|
|
126
|
+
*/
|
|
127
|
+
protected _hydrationData: any | null;
|
|
121
128
|
/**
|
|
122
129
|
* Invoked natively when the element is added to the document.
|
|
123
130
|
* Handles the architectural split between Declarative (SSR) and Imperative (JS) components.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coralite-element.d.ts","sourceRoot":"","sources":["../../lib/coralite-element.js"],"names":[],"mappings":"AAwCA;;;;;;GAMG;AACH,8BAJW,GAAG,QACH,WAAS,MAAM,GACb,GAAG,CAmBf;
|
|
1
|
+
{"version":3,"file":"coralite-element.d.ts","sourceRoot":"","sources":["../../lib/coralite-element.js"],"names":[],"mappings":"AAwCA;;;;;;GAMG;AACH,8BAJW,GAAG,QACH,WAAS,MAAM,GACb,GAAG,CAmBf;AAimBD;;;;;;;;;;;GAWG;AACH,6CATW,wBAAwB,kBACxB,WAAS,IAAI,UAErB;IAAyE,uBAAuB,GAAxF,KAAK,CAAC,iDAAiD,CAA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MAAM,GAAC,IAAI,QAWrB;IAED;;;;;;OAMG;IACH,oBA0EC;IAED;;;;;;OAMG;IACH,6BAYC;IAED;;;;;OAKG;IACH,oBAHW,MAAM,EAAE,GACN,IAAI,GAAC,IAAI,CAYrB;IAED;;;;OAIG;IACH,uBAiCC;IAED;;;;OAIG;IACH,wBASC;IAED;;;;;;;OAOG;IACH,mBA2GC;IAED;;;;OAIG;IACH,sBAqCC;IAED;;;;;;OAMG;IACH,cAqCC;CACF;;;;;iBA3lBa,MAAM;;;;mBACN,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uEAhEV,oBAAoB;sEAApB,oBAAoB;8DAApB,oBAAoB"}
|
|
@@ -7,6 +7,7 @@ var CoraliteError = class extends Error {
|
|
|
7
7
|
* @param {string} [options.filePath] - The path to the file where the error occurred.
|
|
8
8
|
* @param {string} [options.instanceId] - The unique ID of the component instance.
|
|
9
9
|
* @param {string} [options.pagePath] - The path to the page being rendered.
|
|
10
|
+
* @param {string} [options.path] - The path to the data property where the error occurred.
|
|
10
11
|
* @param {number} [options.line] - The line number where the error occurred.
|
|
11
12
|
* @param {number} [options.column] - The column number where the error occurred.
|
|
12
13
|
* @param {string} [options.stackFile] - The file name from the stack trace.
|
|
@@ -20,6 +21,7 @@ var CoraliteError = class extends Error {
|
|
|
20
21
|
this.filePath = options.filePath;
|
|
21
22
|
this.instanceId = options.instanceId;
|
|
22
23
|
this.pagePath = options.pagePath;
|
|
24
|
+
this.path = options.path;
|
|
23
25
|
this.line = options.line;
|
|
24
26
|
this.column = options.column;
|
|
25
27
|
this.stackFile = options.stackFile;
|
|
@@ -131,6 +133,7 @@ var CoraliteElement = class extends HTMLElement {
|
|
|
131
133
|
onDisconnected: []
|
|
132
134
|
};
|
|
133
135
|
this.componentOptions = null;
|
|
136
|
+
this._hydrationData = null;
|
|
134
137
|
}
|
|
135
138
|
/**
|
|
136
139
|
* Invoked natively when the element is added to the document.
|
|
@@ -252,16 +255,8 @@ var CoraliteElement = class extends HTMLElement {
|
|
|
252
255
|
const schema = options.attributes?.[camelName] || options.attributes?.[attr.name];
|
|
253
256
|
target[camelName] = schema ? coerce(attr.value, schema.type) : attr.value;
|
|
254
257
|
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
try {
|
|
258
|
-
const allData = JSON.parse(hydrationTag.textContent);
|
|
259
|
-
if (allData[this._instanceId]) {
|
|
260
|
-
Object.assign(target, allData[this._instanceId]);
|
|
261
|
-
}
|
|
262
|
-
} catch {
|
|
263
|
-
console.error("Coralite Element hydration failed:", this._instanceId);
|
|
264
|
-
}
|
|
258
|
+
if (this._hydrationData && this._hydrationData[this._instanceId]) {
|
|
259
|
+
Object.assign(target, this._hydrationData[this._instanceId]);
|
|
265
260
|
}
|
|
266
261
|
for (const hook of this._hooks.onBeforeComponentRender) {
|
|
267
262
|
hook({
|
|
@@ -543,7 +538,7 @@ var CoraliteElement = class extends HTMLElement {
|
|
|
543
538
|
}
|
|
544
539
|
}
|
|
545
540
|
};
|
|
546
|
-
function createCoraliteClass(options, contextGetter = null, hooks = {}) {
|
|
541
|
+
function createCoraliteClass(options, contextGetter = null, hooks = {}, hydrationData = null) {
|
|
547
542
|
return class extends CoraliteElement {
|
|
548
543
|
/**
|
|
549
544
|
* The attributes to observe for changes.
|
|
@@ -564,6 +559,7 @@ function createCoraliteClass(options, contextGetter = null, hooks = {}) {
|
|
|
564
559
|
super();
|
|
565
560
|
this.componentOptions = options;
|
|
566
561
|
this._clientContextGetter = contextGetter;
|
|
562
|
+
this._hydrationData = hydrationData;
|
|
567
563
|
this._hooks = {
|
|
568
564
|
onBeforeComponentRender: hooks.onBeforeComponentRender || [],
|
|
569
565
|
onAfterComponentRender: hooks.onAfterComponentRender || [],
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../lib/utils/errors.js", "../../lib/utils/core.js", "../../lib/utils/client/inject.js", "../../lib/coralite-element.js"],
|
|
4
|
-
"sourcesContent": ["\n/**\n * @import { CoraliteErrorData } from '../../types/index.js'\n */\n\n/**\n * Base error class for all Coralite-related errors.\n */\nexport class CoraliteError extends Error {\n /**\n * @param {string} message - The error message.\n * @param {Object} [options] - Additional options for the error.\n * @param {string} [options.componentId] - The ID of the component where the error occurred.\n * @param {string} [options.filePath] - The path to the file where the error occurred.\n * @param {string} [options.instanceId] - The unique ID of the component instance.\n * @param {string} [options.pagePath] - The path to the page being rendered.\n * @param {number} [options.line] - The line number where the error occurred.\n * @param {number} [options.column] - The column number where the error occurred.\n * @param {string} [options.stackFile] - The file name from the stack trace.\n * @param {Error} [options.cause] - The original error that caused this error.\n */\n constructor (message, options = {}) {\n super(message, options)\n this.name = 'CoraliteError'\n this.isCoraliteError = true\n this.componentId = options.componentId\n this.filePath = options.filePath\n this.instanceId = options.instanceId\n this.pagePath = options.pagePath\n this.line = options.line\n this.column = options.column\n this.stackFile = options.stackFile\n\n // Polyfill cause if necessary (node version differences)\n if (options.cause && !this.cause) {\n this.cause = options.cause\n }\n }\n}\n\n/**\n * Default error handler.\n * @param {CoraliteErrorData} data - The data object containing error details.\n */\nexport function defaultOnError ({ level, message, error }) {\n if (level === 'ERR') {\n if (error) {\n throw error\n }\n throw new CoraliteError(message)\n } else if (level === 'WARN') {\n console.warn(message)\n } else {\n console.log(message)\n }\n}\n\n/**\n * Handles errors using an optional callback or the default handler.\n * @param {Object} options - The options for handling the error.\n * @param {Function} [options.onErrorCallback] - The optional custom error callback function.\n * @param {CoraliteErrorData} options.data - The error data to be handled.\n */\nexport function handleError ({ onErrorCallback, data }) {\n const error = data.error\n if (error && 'isCoraliteError' in error && error.isCoraliteError) {\n const coraliteError = error\n // @ts-ignore\n data.componentId = data.componentId || coraliteError.componentId\n // @ts-ignore\n data.filePath = data.filePath || coraliteError.filePath\n // @ts-ignore\n data.instanceId = data.instanceId || coraliteError.instanceId\n // @ts-ignore\n data.pagePath = data.pagePath || coraliteError.pagePath\n // @ts-ignore\n data.line = data.line || coraliteError.line\n // @ts-ignore\n data.column = data.column || coraliteError.column\n // @ts-ignore\n data.stackFile = data.stackFile || coraliteError.stackFile\n }\n\n if (onErrorCallback) {\n onErrorCallback(data)\n } else {\n defaultOnError(data)\n }\n}\n", "import { CoraliteError } from './errors.js'\n\n/**\n * @import {\n * CoraliteModule,\n * CoraliteComponent,\n * CoraliteComponentResult,\n * } from '../../types/index.js'\n */\n\nconst KEBAB_REGEX = /[-|:]([a-z])/g\n\n/**\n * Converts a kebab-case string to camelCase\n * @param {string} str - The kebab-case string to convert\n * @returns {string} - The camelCase version of the string\n */\nexport function kebabToCamel (str) {\n // replace each dash followed by a letter with the uppercase version of the letter\n return str.replace(KEBAB_REGEX, function (match, letter) {\n return letter.toUpperCase()\n })\n}\n\n/**\n * Converts all keys in an object from kebab-case to camelCase\n * @template T\n * @param {Record<string, T>} object - The object with kebab-case keys\n * @returns {Record<string, T>} - A new object with camelCase keys\n */\nexport function cleanKeys (object) {\n /** @type {Record<string, T>} */\n const result = {}\n\n for (const [key, value] of Object.entries(object)) {\n result[key] = value\n\n const camelKey = kebabToCamel(key)\n if (camelKey !== key) {\n result[camelKey] = value\n }\n }\n\n return result\n}\n\n/**\n * Recursively clones an object or array and normalizes any function state\n * it finds into a string representation that preserves standard function syntax,\n * bypassing ES6 shorthand method serialization issues.\n * @param {any} target - The object or array to normalize.\n * @param {Function} [transform] - Optional transform function for each node.\n * @param {WeakMap} [seen=new WeakMap()] - Map of seen objects to handle circular references.\n * @returns {any} A deeply cloned object with normalized functions.\n */\nexport function normalizeObjectFunctions (target, transform = null, seen = new WeakMap()) {\n if (typeof transform === 'function') {\n const transformed = transform(target)\n if (transformed !== target) {\n return transformed\n }\n }\n\n if (typeof target !== 'object' || target === null) {\n return target\n }\n\n if (seen.has(target)) {\n return seen.get(target)\n }\n\n if (Array.isArray(target)) {\n const arr = []\n seen.set(target, arr)\n for (let i = 0; i < target.length; i++) {\n arr.push(normalizeObjectFunctions(target[i], transform, seen))\n }\n return arr\n }\n\n const obj = {}\n seen.set(target, obj)\n for (const key in target) {\n if (Object.hasOwn(target, key)) {\n if (typeof target[key] === 'function') {\n const normalizedString = normalizeFunction(target[key])\n const originalFunction = target[key]\n\n const wrapper = function () {\n return originalFunction.apply(this, arguments)\n }\n wrapper.toString = () => normalizedString\n obj[key] = wrapper\n } else {\n obj[key] = normalizeObjectFunctions(target[key], transform, seen)\n }\n }\n }\n\n return obj\n}\n\n/**\n * Checks whether the given object is an object and has at least one own key.\n * @param {any} obj - The object to check.\n * @returns {boolean} True if the object is truthy and has keys, otherwise false.\n */\nexport function hasObjectKeys (obj) {\n return obj && typeof obj === 'object' && Object.keys(obj).length > 0\n}\n\n/**\n * Merges two arrays, returning a new array with unique items.\n * Uses JSON.stringify for deep comparison of object elements, preserving object uniqueness correctly.\n * @param {Array<any>} [arr1] - The first array.\n * @param {Array<any>} [arr2] - The second array.\n * @returns {Array<any>} A new array with unique values from both input arrays.\n */\nexport function mergeUniqueObjects (arr1, arr2) {\n const all = [...(arr1 || []), ...(arr2 || [])]\n const seen = new Set()\n return all.filter(item => {\n const key = typeof item === 'object' ? JSON.stringify(item) : item\n if (seen.has(key)) {\n return false\n }\n seen.add(key)\n return true\n })\n}\n\n/**\n * Normalizes function declarations to ensure consistent formatting.\n * Converts shorthand method syntax to full function declarations where needed,\n * while preserving arrow functions and existing full declarations.\n *\n * @param {Function} func - The function to normalize\n * @returns {string} The normalized function string representation\n */\nexport function normalizeFunction (func) {\n const original = func.toString().trim()\n\n const firstBrace = original.indexOf('{')\n const firstArrow = original.indexOf('=>')\n\n const isArrow = firstArrow !== -1 && (firstBrace === -1 || firstArrow < firstBrace)\n\n if (isArrow) {\n return original\n }\n\n // For non-arrows, extract header to check for shorthand\n const header = firstBrace !== -1 ? original.slice(0, firstBrace).trim() : original\n\n const isStandard = header.startsWith('function') || header.startsWith('async function')\n\n if (isStandard) {\n return original\n }\n\n // Handle Method Shorthand\n if (header.startsWith('async ')) {\n if (header.startsWith('async get ') || header.startsWith('async set ')) {\n return original\n }\n\n return original.replace(/^async\\s+([$\\w]+)\\s*\\(/, 'async function(')\n } else {\n if (header.startsWith('get ') || header.startsWith('set ')) {\n return original\n }\n\n return original.replace(/^([$\\w]+)\\s*\\(/, 'function(')\n }\n}\n\n\n/**\n * Recursively clones an AST node and its children, ensuring that\n * inner references (like parents and slots) point to the newly cloned nodes.\n *\n * @param {Map<Object, Object>} nodeMap - A map tracking original nodes to their newly cloned counterparts.\n * @param {Object} node - The current AST node being cloned.\n * @param {Object} [parent] - The parent node reference to assign to the clone.\n * @returns {Object} The newly cloned node.\n */\nexport function cloneNode (nodeMap, node, parent) {\n const newNode = Object.create(Object.getPrototypeOf(node))\n\n // Copy all own enumerable properties\n Object.assign(newNode, node)\n\n if (parent) {\n newNode.parent = parent\n }\n\n if (newNode.attribs) {\n newNode.attribs = { ...newNode.attribs }\n }\n\n // Register in map\n nodeMap.set(node, newNode)\n\n // Recursively clone children\n if (node.children) {\n const children = node.children\n const length = children.length\n const clonedChildren = new Array(length)\n newNode.children = clonedChildren\n\n for (let i = 0; i < length; i++) {\n const clonedChild = cloneNode(nodeMap, children[i], newNode)\n clonedChildren[i] = clonedChild\n if (i > 0) {\n clonedChild.prev = clonedChildren[i - 1]\n clonedChildren[i - 1].next = clonedChild\n }\n }\n }\n\n // Update slot references to point to new cloned nodes\n if (node.slots) {\n const slots = node.slots\n const length = slots.length\n const clonedSlots = new Array(length)\n for (let i = 0; i < length; i++) {\n const slot = slots[i]\n const clonedSlot = { ...slot }\n if (slot.node) {\n const clonedNode = nodeMap.get(slot.node)\n if (clonedNode) {\n clonedSlot.node = clonedNode\n }\n }\n clonedSlots[i] = clonedSlot\n }\n newNode.slots = clonedSlots\n }\n\n // Preserve the enhanced flag without re-running enhanceNode\n Object.defineProperty(newNode, '__coralite_enhanced__', {\n value: true,\n enumerable: false,\n configurable: true\n })\n\n return newNode\n}\n\n/**\n * Creates a shallow copy of a CoraliteModule with a deep clone of its DOM tree (template) and re-linked internal references to enable safe independent mutation.\n *\n * Top-level non-DOM state (id, path, script, isTemplate, lineOffset) are shallow copied. Nested objects within these state (e.g., path) remain shared references. Only DOM-related structures undergo deep cloning and reference re-linking to isolate mutations from the original module.\n *\n * @param {CoraliteModule} originalModule - Module to clone.\n * @returns {CoraliteModule}\n */\nexport function cloneModuleInstance (originalModule) {\n const nodeMap = new Map()\n\n // Clone the main template tree\n const newTemplate = cloneNode(nodeMap, originalModule.template, null)\n\n // Reconstruct the 'values' object\n const newValues = {\n attributes: originalModule.values.attributes.map(item => ({\n ...item,\n element: nodeMap.get(item.element)\n })),\n textNodes: originalModule.values.textNodes.map(item => ({\n ...item,\n textNode: nodeMap.get(item.textNode)\n })),\n refs: originalModule.values.refs.map(item => ({\n ...item,\n element: nodeMap.get(item.element)\n }))\n }\n\n // Reconstruct customElements list\n const newCustomElements = originalModule.customElements.map(el => nodeMap.get(el))\n\n // Reconstruct slotElements\n const newSlotElements = {}\n if (originalModule.slotElements) {\n for (const modId in originalModule.slotElements) {\n newSlotElements[modId] = {}\n const slotGroup = originalModule.slotElements[modId]\n\n for (const slotName in slotGroup) {\n const slotItem = slotGroup[slotName]\n newSlotElements[modId][slotName] = {\n ...slotItem,\n element: nodeMap.get(slotItem.element)\n }\n }\n }\n }\n\n // Return the new module structure\n return {\n ...originalModule,\n template: newTemplate,\n values: newValues,\n customElements: newCustomElements,\n // @ts-ignore\n slotElements: newSlotElements\n }\n}\n\n/**\n * Creates a deep copy of a CoraliteComponent with re-linked internal references to enable safe independent mutation.\n *\n * @param {CoraliteComponent & CoraliteComponentResult} originalDocument - Document to clone.\n * @returns {CoraliteComponent & CoraliteComponentResult}\n */\nexport function cloneComponentInstance (originalDocument) {\n const nodeMap = new Map()\n const newRoot = cloneNode(nodeMap, originalDocument.root, null)\n\n const newCustomElements = originalDocument.customElements.map(el => nodeMap.get(el))\n const newTempElements = originalDocument.tempElements ? originalDocument.tempElements.map(el => nodeMap.get(el)) : []\n const newSkipRenderElements = originalDocument.skipRenderElements ? originalDocument.skipRenderElements.map(el => nodeMap.get(el)) : []\n\n return {\n ...originalDocument,\n state: { ...originalDocument.state },\n root: newRoot,\n customElements: newCustomElements,\n tempElements: newTempElements,\n skipRenderElements: newSkipRenderElements\n }\n}\n\n/**\n * Calculates the DOM path from a node to the root.\n * @param {Object} node - The node to calculate the path for.\n * @param {Object} root - The root node.\n * @returns {Array<number>} An array of indices representing the path.\n */\nexport function getNodePath (node, root) {\n const path = []\n let current = node\n while (current && current !== root) {\n const parent = current.parent\n if (!parent) {\n break\n }\n const index = parent.children.indexOf(current)\n if (index === -1) {\n break\n }\n path.unshift(index)\n current = parent\n }\n return path\n}\n\n/**\n * Generates a hydration map for the client.\n * @param {Array<Object>} templateNodes - The component's template nodes.\n * @param {Object} templateValues - The component's template values.\n * @returns {Object} The hydration map.\n */\nexport function generateHydrationMap (templateNodes, templateValues) {\n const map = {\n texts: [],\n attributes: [],\n refs: []\n }\n\n if (!templateNodes || !templateValues) {\n return map\n }\n\n const root = templateNodes.length > 0 ? templateNodes[0].parent : { children: templateNodes }\n\n if (templateValues.textNodes) {\n for (const item of templateValues.textNodes) {\n if (item.textNode) {\n const isHtml = item.type === 'html'\n const targetNode = isHtml ? item.textNode.parent : item.textNode\n\n map.texts.push({\n path: getNodePath(targetNode, root),\n template: item.textNode.data,\n type: isHtml ? 'html' : 'text'\n })\n }\n }\n }\n\n if (templateValues.attributes) {\n for (const item of templateValues.attributes) {\n if (item.element && item.element.attribs) {\n const originalValue = item.element.attribs[item.name]\n map.attributes.push({\n path: getNodePath(item.element, root),\n name: item.name,\n template: originalValue\n })\n }\n }\n }\n\n if (templateValues.refs) {\n for (const item of templateValues.refs) {\n if (item.element) {\n map.refs.push({\n path: getNodePath(item.element, root),\n name: item.name\n })\n }\n }\n }\n\n return map\n}\n\n/**\n * Recursively adds a component and its dependencies to a tracking object.\n *\n * @param {string} componentId - The ID of the component to add.\n * @param {Object.<string, boolean>} processed - The object tracking processed components.\n * @param {Object.<string, any>} sharedFunctions - The map of shared component functions.\n */\nexport function addComponentAndDependencies (componentId, processed, sharedFunctions) {\n if (!processed[componentId] && sharedFunctions[componentId]) {\n processed[componentId] = true\n\n // Add all dependencies of this component\n const dependencies = sharedFunctions[componentId].components || []\n for (const depId of dependencies) {\n addComponentAndDependencies(depId, processed, sharedFunctions)\n }\n }\n}\n\n/**\n * Recursively clones an AST node and its children, stripping circular references\n * and assigning unique IDs for client-side hydration.\n *\n * @param {Array<Object>} nodes - The nodes to clean.\n * @param {WeakMap} nodeMap - Map to track original nodes to their unique IDs.\n * @param {Object} state - Object containing the current node counter.\n * @returns {Array<Object>|null} The cleaned AST nodes.\n */\nexport function cleanAST (nodes, nodeMap, state) {\n if (!nodes) {\n return null\n }\n\n return nodes.map((node) => {\n const cloned = { ...node }\n // Assign unique ID for token mapping\n const id = state.counter++\n nodeMap.set(node, id)\n cloned._id = id\n\n // Remove circular references\n delete cloned.parent\n delete cloned.prev\n delete cloned.next\n delete cloned.slots\n\n if (cloned.children) {\n cloned.children = cleanAST(cloned.children, nodeMap, state)\n }\n return cloned\n })\n}\n\n/**\n * Cleans the template values object, mapping original node references to unique IDs.\n *\n * @param {Object} values - The values object to clean.\n * @param {WeakMap} nodeMap - Map of original nodes to their unique IDs.\n * @returns {Object|null} The cleaned values object.\n */\nexport function cleanValues (values, nodeMap) {\n if (!values) {\n return null\n }\n\n const result = { ...values }\n\n if (result.attributes) {\n result.attributes = result.attributes.map(item => {\n const cloned = { ...item }\n cloned.elementId = nodeMap.get(item.element)\n delete cloned.element\n return cloned\n })\n }\n\n if (result.textNodes) {\n result.textNodes = result.textNodes.map(item => {\n const cloned = { ...item }\n cloned.textNodeId = nodeMap.get(item.textNode)\n delete cloned.textNode\n return cloned\n })\n }\n\n if (result.refs) {\n result.refs = result.refs.map(item => {\n const cloned = { ...item }\n cloned.elementId = nodeMap.get(item.element)\n delete cloned.element\n return cloned\n })\n }\n return result\n}\n\n/**\n * Safely merges partial plugin updates into the main context object.\n * Deeply merges plain objects and overwrites other types (arrays, primitives, etc.).\n *\n * @param {any} current - The current state object.\n * @param {any} patch - The patch object containing updates.\n * @returns {any} The newly merged state object.\n */\nexport function mergePluginState (current, patch) {\n if (!patch || typeof patch !== 'object') {\n return current\n }\n\n const result = { ...current }\n\n for (const key of Object.keys(patch)) {\n const patchValue = patch[key]\n const currentValue = result[key]\n\n // If both are plain objects, merge them deeply\n if (\n patchValue && typeof patchValue === 'object' && !Array.isArray(patchValue) &&\n currentValue && typeof currentValue === 'object' && !Array.isArray(currentValue)\n ) {\n result[key] = mergePluginState(currentValue, patchValue)\n } else {\n // Otherwise, overwrite (Arrays, strings, numbers, etc.)\n result[key] = patchValue\n }\n }\n\n return result\n}\n\n/**\n * Creates a reactive proxy that triggers a callback on changes.\n * Supports deep reactivity via lazy proxying of nested objects.\n *\n * @param {Object} target - The object to proxy.\n * @param {Function} onChange - Callback triggered when a property is set or deleted.\n * @param {WeakMap} [proxies=new WeakMap()] - Cache for existing proxies to handle circular references and identity.\n * @returns {Proxy} The reactive proxy.\n */\nexport function createReactiveProxy (target, onChange, proxies = new WeakMap()) {\n if (proxies.has(target)) {\n return proxies.get(target)\n }\n\n const handler = {\n get (target, property, receiver) {\n const value = Reflect.get(target, property, receiver)\n if (value !== null && typeof value === 'object' && !(typeof Node !== 'undefined' && value instanceof Node)) {\n return createReactiveProxy(value, onChange, proxies)\n }\n return value\n },\n set (target, property, value, receiver) {\n const oldValue = target[property]\n if (oldValue === value && property in target) {\n return true\n }\n\n const result = Reflect.set(target, property, value, receiver)\n if (result) {\n onChange({\n property,\n value,\n oldValue,\n target\n })\n }\n return result\n },\n deleteProperty (target, property) {\n const hadProperty = Object.prototype.hasOwnProperty.call(target, property)\n const oldValue = target[property]\n const result = Reflect.deleteProperty(target, property)\n if (result && hadProperty) {\n onChange({\n property,\n value: undefined,\n oldValue,\n target,\n deleted: true\n })\n }\n return result\n }\n }\n\n const proxy = new Proxy(target, handler)\n proxies.set(target, proxy)\n return proxy\n}\n\n/**\n * Creates a read-only proxy that throws on mutation attempts.\n * @param {Object} target - The object to proxy.\n * @param {WeakMap} [proxies=new WeakMap()] - Cache for existing proxies.\n * @returns {Proxy} The read-only proxy.\n */\nexport function createReadOnlyProxy (target, proxies = new WeakMap()) {\n if (proxies.has(target)) {\n return proxies.get(target)\n }\n\n const handler = {\n get (target, property, receiver) {\n const value = Reflect.get(target, property, receiver)\n if (value !== null && typeof value === 'object' && !(typeof Node !== 'undefined' && value instanceof Node)) {\n return createReadOnlyProxy(value, proxies)\n }\n return value\n },\n set () {\n throw new CoraliteError('Cannot mutate state inside a getter. State is read-only here.')\n },\n deleteProperty () {\n throw new CoraliteError('Cannot delete state inside a getter. State is read-only here.')\n }\n }\n\n const proxy = new Proxy(target, handler)\n\n proxies.set(target, proxy)\n\n return proxy\n}\n\n/**\n * Defines a Coralite component.\n * On the client, this acts as an identity function for type safety and HRM.\n * @param {Object} options - Component options\n * @returns {Object} The component options\n */\nexport function defineComponent (options) {\n return options\n}\n", "import { defineComponent } from '../core.js'\nimport { definePlugin } from '../../plugin.js'\n\n/**\n * Creates a Coralite element or a standard HTML element.\n * Proxy to window.createCoraliteElement or document.createElement.\n *\n * @param {string} tag - The tag name.\n * @param {Object} [options] - Optional element options.\n * @returns {HTMLElement} The created element.\n */\nexport function createCoraliteElement (tag, options) {\n // @ts-ignore\n if (typeof window !== 'undefined' && window.createCoraliteElement) {\n // @ts-ignore\n return window.createCoraliteElement(tag, options)\n }\n return document.createElement(tag, options)\n}\n\n/**\n * Processes an HTML string for custom elements.\n * Proxy to window.processHTML if available.\n *\n * @param {string} html - The HTML string.\n * @returns {string} The HTML string.\n */\nexport function processHTML (html) {\n // @ts-ignore\n if (typeof window !== 'undefined' && window.processHTML) {\n // @ts-ignore\n return window.processHTML(html)\n }\n return html\n}\n\nexport { defineComponent, definePlugin }\n", "/**\n * @import {\n * CoraliteClientPluginDisconnectedCallback,\n * CoraliteClientPluginAfterComponentRenderCallback,\n * CoraliteClientPluginBeforeComponentRenderCallback\n * } from '../types/plugin.js'\n */\n\nimport { createReadOnlyProxy } from './utils/core.js'\nimport { processHTML } from './utils/client/inject.js'\n\nconst BOOLEAN_ATTRIBUTES = new Set([\n 'allowfullscreen',\n 'async',\n 'autofocus',\n 'autoplay',\n 'checked',\n 'controls',\n 'default',\n 'defer',\n 'disabled',\n 'formnovalidate',\n 'hidden',\n 'inert',\n 'ismap',\n 'itemscope',\n 'loop',\n 'multiple',\n 'muted',\n 'nomodule',\n 'novalidate',\n 'open',\n 'playsinline',\n 'readonly',\n 'required',\n 'reversed',\n 'selected',\n 'truespeed'\n])\n\n/**\n * Coerces a value to a specified type.\n * Supports Number, Boolean, and String.\n * @param {any} value - The value to coerce.\n * @param {Function|string} type - The target type (Constructor or string name).\n * @returns {any} The coerced value.\n */\nexport function coerce (value, type) {\n if (value === null || value === undefined) {\n return value\n }\n if (type === Number || type === 'Number') {\n return Number(value)\n }\n if (type === Boolean || type === 'Boolean') {\n if (value === '') {\n return true\n }\n return value !== 'false' && value !== null\n }\n if (type === String || type === 'String') {\n return String(value)\n }\n return value\n}\n\n/**\n * @typedef {Object} CoraliteComponentOptions\n * @property {string} componentId - The unique identifier for the component.\n * @property {string} [templateHTML] - The raw HTML string for imperative mounting.\n * @property {Object} [defaultValues] - The initial state values extracted from the server data block.\n * @property {Object} [attributes] - Schema for coercing HTML attributes into typed primitives.\n * @property {Object.<string, Function>} [getters] - Pure functions for derived state, supporting Promises.\n * @property {Object.<string, Function>} [slots] - Transformation functions for projected Light DOM.\n * @property {Function} [client] - The client-side controller logic.\n * @property {Object} [hydrationMap] - AST mapping for reactive text nodes, attributes, and refs.\n */\n\n/**\n * Base class for all Coralite custom elements.\n *\n * @augments HTMLElement\n */\nexport class CoraliteElement extends HTMLElement {\n /**\n * Initializes a new instance of the CoraliteElement.\n * Sets up internal state trackers, binding collections, and hook registries.\n */\n constructor () {\n super()\n /**\n * Controls native teardown of event listeners and async fetches upon disconnection.\n * @type {AbortController|null}\n * @protected\n */\n this._abortController = null\n\n /**\n * A globally unique, deterministic identifier (e.g., `my-comp-0`).\n * @type {string|null}\n * @protected\n */\n this._instanceId = null\n\n /**\n * The unified, deeply reactive proxy holding attributes, data, and getters.\n * @type {Object|null}\n * @protected\n */\n this._state = null\n\n /**\n * The collection of DOM nodes mapped to template tokens and attributes.\n * @type {Array<{type: string, node: Node, template?: string, name?: string}>}\n * @protected\n */\n this._bindings = []\n\n /**\n * Flag to prevent multiple synchronous state mutations from triggering multiple DOM paints.\n * @type {boolean}\n * @protected\n */\n this._isUpdatePending = false\n\n /**\n * A unique Symbol generated per render cycle to prevent async getter race conditions.\n * @type {symbol|null}\n * @protected\n */\n this._currentRenderVersion = null\n\n /**\n * @type {MutationObserver|null}\n * @protected\n */\n this._observer = null\n\n /**\n * Hook to fetch globally registered Phase-2 plugin contexts.\n * @type {Function|null}\n * @protected\n */\n this._clientContextGetter = null\n\n /**\n * Tracks AbortControllers specifically for cancelling stale async getters.\n * @type {Object.<string, AbortController>|null}\n * @protected\n */\n this._getterAbortControllers = null\n\n /**\n * Internal lifecycle hooks injected by registered Coralite plugins.\n * @type {{\n * onBeforeComponentRender: Array<CoraliteClientPluginBeforeComponentRenderCallback>,\n * onAfterComponentRender: Array<CoraliteClientPluginAfterComponentRenderCallback>,\n * onDisconnected: Array<CoraliteClientPluginDisconnectedCallback>\n * }}\n * @protected\n */\n this._hooks = {\n onBeforeComponentRender: [],\n onAfterComponentRender: [],\n onDisconnected: []\n }\n\n /**\n * The definition and schema of the component generated by the compiler.\n * @type {CoraliteComponentOptions|null}\n */\n this.componentOptions = null\n }\n\n /**\n * Invoked natively when the element is added to the document.\n * Handles the architectural split between Declarative (SSR) and Imperative (JS) components.\n * Orchestrates template injection, instance ID generation, and state/binding setup.\n */\n connectedCallback () {\n this._abortController = new AbortController()\n\n if (!this.componentOptions) {\n return\n }\n\n // Declarative components receive a data-cid from the server.\n // Imperative components (created via document.createElement) do not.\n const isImperative = !this.hasAttribute('data-cid')\n\n // Imperative Flow: Manually stamp the template and project the Light DOM.\n if (isImperative && this.componentOptions.templateHTML) {\n const originalLightDOM = Array.from(this.childNodes)\n this.innerHTML = processHTML(this.componentOptions.templateHTML)\n\n if (originalLightDOM.length > 0) {\n const slots = this.querySelectorAll('slot')\n slots.forEach(slot => {\n const slotName = slot.getAttribute('name') || 'default'\n const matchingNodes = originalLightDOM.filter(node => {\n // @ts-ignore\n const nodeSlot = (node.getAttribute && node.getAttribute('slot')) || 'default'\n return nodeSlot === slotName\n })\n matchingNodes.forEach(n => slot.appendChild(n))\n })\n }\n }\n\n // Establish the Deterministic Instance ID\n if (this.hasAttribute('data-cid')) {\n this._instanceId = this.getAttribute('data-cid')\n } else {\n // Fallback counter for imperatively created components\n // @ts-ignore\n window.__coralite_instanceCounters = window.__coralite_instanceCounters || {}\n const prefix = this.componentOptions.componentId\n // @ts-ignore\n if (window.__coralite_instanceCounters[prefix] === undefined) {\n // @ts-ignore\n window.__coralite_instanceCounters[prefix] = 0\n }\n // @ts-ignore\n this._instanceId = `${prefix}-${window.__coralite_instanceCounters[prefix]++}`\n }\n\n if (isImperative) {\n this.setAttribute('data-cid', this._instanceId)\n }\n\n this._setupState()\n this._setupBindings()\n this._init(isImperative)\n }\n\n /**\n * Invoked natively when the element is removed from the document.\n * Aborts pending requests and triggers `onDisconnected` plugin hooks\n * to ensure external libraries (e.g., Observers) do not cause memory leaks.\n * @this {any}\n */\n disconnectedCallback () {\n if (this._abortController) {\n this._abortController.abort()\n }\n\n if (!this.componentOptions) {\n return\n }\n\n for (const hook of this._hooks.onDisconnected) {\n hook({\n state: this._state,\n instanceId: this._instanceId,\n componentId: this.componentOptions.componentId,\n element: this,\n options: this.componentOptions\n })\n }\n }\n\n /**\n * Invoked natively when an observed HTML attribute changes.\n * Coerces the raw string value based on the component's attribute schema\n * and synchronizes it into the reactive state proxy.\n * @param {string} name - The kebab-case name of the attribute.\n * @param {string|null} oldVal - The previous value.\n * @param {string|null} newVal - The new value.\n */\n attributeChangedCallback (name, oldVal, newVal) {\n if (!this._state || oldVal === newVal || name === 'data-cid') {\n return\n }\n const camelName = name.replace(/-([a-z])/g, (g) => g[1].toUpperCase())\n const schema = this.componentOptions.attributes?.[camelName] || this.componentOptions.attributes?.[name]\n const value = schema ? coerce(newVal, schema.type) : newVal\n\n this._state[camelName] = value\n }\n\n /**\n * Constructs the unified state object.\n * Merges `defaultValues`, JSON hydration payloads, and DOM attributes.\n * Defines getters (wrapping state in a Read-Only proxy) and applies the final Read/Write Proxy.\n * @this {any}\n * @private\n */\n _setupState () {\n const options = this.componentOptions\n const target = { ...options.defaultValues }\n\n /** @type {Array<{name: string, element: HTMLElement}>} */\n const refs = []\n if (options.hydrationMap && options.hydrationMap.refs) {\n for (const ref of options.hydrationMap.refs) {\n const uniqueRefValue = `${this._instanceId}__${ref.name}`\n\n if (!target[`ref_${ref.name}`]) {\n target[`ref_${ref.name}`] = uniqueRefValue\n }\n\n const node = this.getNodeByPath(ref.path)\n if (node) {\n if (node.setAttribute) {\n node.setAttribute('ref', uniqueRefValue)\n }\n refs.push({\n name: ref.name,\n element: node\n })\n }\n }\n }\n\n // Process initial attributes mapping\n for (const attr of this.attributes) {\n if (attr.name === 'data-cid') {\n continue\n }\n const camelName = attr.name.replace(/-([a-z])/g, (g) => g[1].toUpperCase())\n const schema = options.attributes?.[camelName] || options.attributes?.[attr.name]\n target[camelName] = schema ? coerce(attr.value, schema.type) : attr.value\n }\n\n // Hydrate data() block results from the SSR JSON payload\n const hydrationTag = document.getElementById('__CORALITE_HYDRATION__')\n if (hydrationTag) {\n try {\n const allData = JSON.parse(hydrationTag.textContent)\n if (allData[this._instanceId]) {\n Object.assign(target, allData[this._instanceId])\n }\n } catch {\n console.error('Coralite Element hydration failed:', this._instanceId)\n }\n }\n\n // Trigger Before-Render hooks BEFORE state is proxied, allowing plugins to inject reactive data\n for (const hook of this._hooks.onBeforeComponentRender) {\n hook({\n state: target,\n instanceId: this._instanceId,\n componentId: this.componentOptions.componentId,\n refs,\n element: this,\n options: this.componentOptions\n })\n }\n\n // Define derived state getters with isolation controllers\n this._getterAbortControllers = {}\n for (const [key, getter] of Object.entries(options.getters || {})) {\n Object.defineProperty(target, key, {\n get: () => {\n if (this._getterAbortControllers[key]) {\n this._getterAbortControllers[key].abort()\n }\n this._getterAbortControllers[key] = new AbortController()\n\n // Enforce \"Dual-Proxy\" safety: Getters cannot mutate state\n const roState = createReadOnlyProxy(this._state)\n return getter(roState, { signal: this._getterAbortControllers[key].signal })\n },\n enumerable: true,\n configurable: true\n })\n }\n\n this._state = this._createReactiveProxy(target)\n }\n\n /**\n * Wraps the state target in a reactive Proxy.\n * Intercepts property setters to automatically batch and schedule DOM updates.\n * @param {Object} target - The state dictionary.\n * @returns {Proxy} The reactive state proxy.\n * @private\n */\n _createReactiveProxy (target) {\n const self = this\n return new Proxy(target, {\n set (t, p, v) {\n if (t[p] === v) {\n return true\n }\n t[p] = v\n self._scheduleUpdate()\n return true\n }\n })\n }\n\n /**\n * Traverses the DOM tree using an AST-generated path index array.\n * Allows O(1) element lookups without relying on querySelectors or classes.\n * @param {number[]} path - Array of childNode indices (e.g., `[0, 1, 2]`).\n * @returns {Node|null} The physical DOM node, or null if traversal fails.\n */\n getNodeByPath (path) {\n let node = this\n for (const index of path) {\n if (!node) {\n return null\n }\n // @ts-ignore\n node = node.childNodes[index]\n }\n return node\n }\n\n /**\n * Initializes DOM bindings based on the compiler's hydration map.\n * Caches physical DOM references to text nodes and attributes that contain template tokens.\n * @private\n */\n _setupBindings () {\n this._bindings = []\n const map = this.componentOptions.hydrationMap\n if (!map) {\n return\n }\n\n if (map.texts) {\n for (const item of map.texts) {\n const node = this.getNodeByPath(item.path)\n if (node) {\n this._bindings.push({\n type: item.type || 'text',\n node,\n template: item.template\n })\n }\n }\n }\n\n if (map.attributes) {\n for (const item of map.attributes) {\n const node = this.getNodeByPath(item.path)\n if (node) {\n this._bindings.push({\n type: 'attribute',\n node,\n name: item.name,\n template: item.template\n })\n }\n }\n }\n }\n\n /**\n * Schedules a DOM update in the next microtask queue.\n * This guarantees that multiple synchronous state mutations result in only one render pass.\n * @private\n */\n _scheduleUpdate () {\n if (this._isUpdatePending) {\n return\n }\n this._isUpdatePending = true\n queueMicrotask(() => {\n this._updateDOM()\n this._isUpdatePending = false\n })\n }\n\n /**\n * Performs the physical DOM update and resolves template tokens.\n * **Async Safety:** Implements a Symbol-based locking mechanism (`renderVersion`)\n * to guarantee that if state mutates while an async getter is pending, the stale\n * Promise will be discarded, preventing DOM race conditions.\n * @this {any}\n * @private\n */\n _updateDOM () {\n // Create a unique lock for this specific render cycle\n const renderVersion = Symbol()\n this._currentRenderVersion = renderVersion\n\n // Extract unique tokens to prevent double-reading and accidental aborts\n /** @type {Set<string>} */\n const requiredTokens = new Set()\n for (const binding of this._bindings) {\n binding.template.replace(/\\{\\{\\s*(.+?)\\s*\\}\\}/g, (_, key) => {\n requiredTokens.add(key)\n return ''\n })\n }\n\n const evaluatedTokens = {}\n let hasPromise = false\n\n // Evaluate getters exactly once per render cycle\n for (const key of requiredTokens) {\n let val = this._state[key]\n if (typeof val === 'function') {\n val = val(this._state)\n }\n evaluatedTokens[key] = val\n if (val instanceof Promise) {\n hasPromise = true\n }\n }\n\n // The DOM Mutator Function\n const applyBindings = (tokenValues) => {\n // Race Condition Lock: Abort if a newer render cycle has already begun\n if (this._currentRenderVersion !== renderVersion) {\n return\n }\n\n for (const binding of this._bindings) {\n const hydratedValue = binding.template.replace(/\\{\\{\\s*(.+?)\\s*\\}\\}/g, (_, key) => {\n return tokenValues[key] ?? ''\n })\n\n if (binding.type === 'text') {\n if (binding.node.textContent !== hydratedValue) {\n binding.node.textContent = hydratedValue\n }\n } else if (binding.type === 'html') {\n /** @type {HTMLElement} */\n // @ts-ignore\n const element = binding.node\n\n if (element.innerHTML !== hydratedValue) {\n element.innerHTML = hydratedValue\n }\n } else if (binding.type === 'attribute') {\n /** @type {HTMLElement} */\n // @ts-ignore\n const element = binding.node\n\n if (BOOLEAN_ATTRIBUTES.has(binding.name)) {\n const isFalsy = hydratedValue === '' || hydratedValue === 'false' || hydratedValue === 'null' || hydratedValue === '0' || hydratedValue === 'undefined'\n if (isFalsy) {\n element.removeAttribute(binding.name)\n } else {\n element.setAttribute(binding.name, '')\n }\n } else {\n if (element.getAttribute(binding.name) !== hydratedValue) {\n element.setAttribute(binding.name, hydratedValue)\n }\n }\n }\n }\n\n this._processSlots()\n\n // Trigger After-Render hooks ONLY after the physical DOM is stable\n for (const hook of this._hooks.onAfterComponentRender) {\n hook({\n state: this._state,\n instanceId: this._instanceId,\n componentId: this.componentOptions.componentId,\n element: this,\n options: this.componentOptions\n })\n }\n }\n\n // Await Promises or Apply Synchronously\n if (hasPromise) {\n const keys = Object.keys(evaluatedTokens)\n const promises = keys.map(k => Promise.resolve(evaluatedTokens[k]))\n\n Promise.all(promises).then(resolvedValues => {\n const resolvedMap = {}\n keys.forEach((k, i) => {\n resolvedMap[k] = resolvedValues[i]\n })\n applyBindings(resolvedMap)\n }).catch(e => {\n if (e.name !== 'AbortError') {\n console.error('Coralite Async Getter Error:', e)\n }\n })\n } else {\n applyBindings(evaluatedTokens)\n }\n }\n\n /**\n * Evaluates and projects Light DOM elements into their respective `<slot>` nodes.\n * Invokes component-specific slot transformation functions.\n * @private\n */\n _processSlots () {\n const slots = this.componentOptions.slots\n if (!slots || Object.keys(slots).length === 0) {\n return\n }\n\n const slotElements = this.querySelectorAll('slot')\n slotElements.forEach(slotEl => {\n const slotName = slotEl.getAttribute('name') || 'default'\n const slotFn = slots[slotName]\n\n if (slotFn) {\n // @ts-ignore\n if (!slotEl._originalNodes) {\n // @ts-ignore\n slotEl._originalNodes = Array.from(slotEl.childNodes).map(n => n.cloneNode(true))\n }\n\n // @ts-ignore\n const result = slotFn(slotEl._originalNodes, this._state)\n\n if (result === undefined) {\n return\n }\n\n if (result === null || result === '' || (Array.isArray(result) && result.length === 0)) {\n slotEl.innerHTML = ''\n return\n }\n\n if (typeof result === 'string') {\n slotEl.innerHTML = result\n } else if (Array.isArray(result)) {\n slotEl.replaceChildren(...result)\n }\n }\n })\n }\n\n /**\n * The final initialization pipeline.\n * Injects globally registered client plugins into the local context payload,\n * triggers the initial DOM render, and invokes the user's `script()` logic.\n * @param {boolean} [isImperative=false] - If true, initial render runs synchronously.\n * @private\n */\n async _init (isImperative = false) {\n const self = this\n /**\n * The context payload injected into the user's script block.\n * @type {Object}\n */\n let localContext = {\n instanceId: this._instanceId,\n state: this._state,\n root: this,\n signal: this._abortController.signal,\n refs (id) {\n const refId = self._state[`ref_${id}`]\n if (!refId && typeof refId !== 'string') {\n return null\n }\n return self.querySelector(`[ref=\"${refId}\"]`)\n }\n }\n\n if (typeof this._clientContextGetter === 'function') {\n localContext = await this._clientContextGetter(localContext)\n }\n\n if (isImperative) {\n this._updateDOM()\n } else {\n this._scheduleUpdate()\n }\n\n if (this.componentOptions.client) {\n try {\n this.componentOptions.client(localContext)\n } catch (error) {\n console.error(`Coralite Error: Component \"${this.componentOptions.componentId}\" script failed:`, error)\n }\n }\n }\n}\n\n/**\n * Factory function to create a Coralite element class.\n * It dynamically defines the class, including observed attributes and hook initialization.\n * @param {CoraliteComponentOptions} options - Component options and metadata.\n * @param {Function|null} [contextGetter=null] - Optional function to retrieve client-side plugin context.\n * @param {Object} [hooks={}] - Lifecycle hooks to register.\n * @param {Array<CoraliteClientPluginBeforeComponentRenderCallback>} [hooks.onBeforeComponentRender] - Hooks to run before render.\n * @param {Array<CoraliteClientPluginAfterComponentRenderCallback>} [hooks.onAfterComponentRender] - Hooks to run after render.\n * @param {Array<CoraliteClientPluginDisconnectedCallback>} [hooks.onDisconnected] - Hooks to run after render.\n * @returns {typeof CoraliteElement} A new CoraliteElement subclass.\n */\nexport function createCoraliteClass (options, contextGetter = null, hooks = {}) {\n return class extends CoraliteElement {\n /**\n * The attributes to observe for changes.\n * @returns {string[]} Array of attribute names.\n */\n static get observedAttributes () {\n if (!options.attributes) {\n return []\n }\n return Object.keys(options.attributes).map(key => key.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase()\n )\n }\n\n /**\n * Initializes the dynamic Coralite element.\n */\n constructor () {\n super()\n this.componentOptions = options\n this._clientContextGetter = contextGetter\n this._hooks = {\n onBeforeComponentRender: hooks.onBeforeComponentRender || [],\n onAfterComponentRender: hooks.onAfterComponentRender || [],\n onDisconnected: hooks.onDisconnected || []\n }\n }\n }\n}\n"],
|
|
5
|
-
"mappings": ";AAQO,IAAM,gBAAN,cAA4B,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAavC,YAAa,SAAS,UAAU,CAAC,GAAG;AAClC,UAAM,SAAS,OAAO;AACtB,SAAK,OAAO;AACZ,SAAK,kBAAkB;AACvB,SAAK,cAAc,QAAQ;AAC3B,SAAK,WAAW,QAAQ;AACxB,SAAK,aAAa,QAAQ;AAC1B,SAAK,WAAW,QAAQ;AACxB,SAAK,OAAO,QAAQ;AACpB,SAAK,SAAS,QAAQ;AACtB,SAAK,YAAY,QAAQ;AAGzB,QAAI,QAAQ,SAAS,CAAC,KAAK,OAAO;AAChC,WAAK,QAAQ,QAAQ;AAAA,IACvB;AAAA,EACF;AACF;;;ACkkBO,SAAS,oBAAqB,QAAQ,UAAU,oBAAI,QAAQ,GAAG;AACpE,MAAI,QAAQ,IAAI,MAAM,GAAG;AACvB,WAAO,QAAQ,IAAI,MAAM;AAAA,EAC3B;AAEA,QAAM,UAAU;AAAA,IACd,IAAKA,SAAQ,UAAU,UAAU;AAC/B,YAAM,QAAQ,QAAQ,IAAIA,SAAQ,UAAU,QAAQ;AACpD,UAAI,UAAU,QAAQ,OAAO,UAAU,YAAY,EAAE,OAAO,SAAS,eAAe,iBAAiB,OAAO;AAC1G,eAAO,oBAAoB,OAAO,OAAO;AAAA,MAC3C;AACA,aAAO;AAAA,IACT;AAAA,IACA,MAAO;AACL,YAAM,IAAI,cAAc,+DAA+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uBAAuB;AAC5B,WAAK,SAAS;AAAA,QACZ,yBAAyB,MAAM,2BAA2B,CAAC;AAAA,QAC3D,wBAAwB,MAAM,0BAA0B,CAAC;AAAA,QACzD,gBAAgB,MAAM,kBAAkB,CAAC;AAAA,MAC3C;AAAA,IACF;AAAA,EACF;AACF;",
|
|
4
|
+
"sourcesContent": ["\n/**\n * @import { CoraliteErrorData } from '../../types/index.js'\n */\n\n/**\n * Base error class for all Coralite-related errors.\n */\nexport class CoraliteError extends Error {\n /**\n * @param {string} message - The error message.\n * @param {Object} [options] - Additional options for the error.\n * @param {string} [options.componentId] - The ID of the component where the error occurred.\n * @param {string} [options.filePath] - The path to the file where the error occurred.\n * @param {string} [options.instanceId] - The unique ID of the component instance.\n * @param {string} [options.pagePath] - The path to the page being rendered.\n * @param {string} [options.path] - The path to the data property where the error occurred.\n * @param {number} [options.line] - The line number where the error occurred.\n * @param {number} [options.column] - The column number where the error occurred.\n * @param {string} [options.stackFile] - The file name from the stack trace.\n * @param {Error} [options.cause] - The original error that caused this error.\n */\n constructor (message, options = {}) {\n super(message, options)\n this.name = 'CoraliteError'\n this.isCoraliteError = true\n this.componentId = options.componentId\n this.filePath = options.filePath\n this.instanceId = options.instanceId\n this.pagePath = options.pagePath\n this.path = options.path\n this.line = options.line\n this.column = options.column\n this.stackFile = options.stackFile\n\n // Polyfill cause if necessary (node version differences)\n if (options.cause && !this.cause) {\n this.cause = options.cause\n }\n }\n}\n\n/**\n * Default error handler.\n * @param {CoraliteErrorData} data - The data object containing error details.\n */\nexport function defaultOnError ({ level, message, error }) {\n if (level === 'ERR') {\n if (error) {\n throw error\n }\n throw new CoraliteError(message)\n } else if (level === 'WARN') {\n console.warn(message)\n } else {\n console.log(message)\n }\n}\n\n/**\n * Handles errors using an optional callback or the default handler.\n * @param {Object} options - The options for handling the error.\n * @param {Function} [options.onErrorCallback] - The optional custom error callback function.\n * @param {CoraliteErrorData} options.data - The error data to be handled.\n */\nexport function handleError ({ onErrorCallback, data }) {\n const error = data.error\n if (error && 'isCoraliteError' in error && error.isCoraliteError) {\n const coraliteError = error\n // @ts-ignore\n data.componentId = data.componentId || coraliteError.componentId\n // @ts-ignore\n data.filePath = data.filePath || coraliteError.filePath\n // @ts-ignore\n data.instanceId = data.instanceId || coraliteError.instanceId\n // @ts-ignore\n data.pagePath = data.pagePath || coraliteError.pagePath\n // @ts-ignore\n data.path = data.path || coraliteError.path\n // @ts-ignore\n data.line = data.line || coraliteError.line\n // @ts-ignore\n data.column = data.column || coraliteError.column\n // @ts-ignore\n data.stackFile = data.stackFile || coraliteError.stackFile\n }\n\n if (onErrorCallback) {\n onErrorCallback(data)\n } else {\n defaultOnError(data)\n }\n}\n", "import { CoraliteError } from './errors.js'\n\n/**\n * @import {\n * CoraliteModule,\n * CoraliteComponent,\n * CoraliteComponentResult,\n * } from '../../types/index.js'\n */\n\nconst KEBAB_REGEX = /[-|:]([a-z])/g\n\n/**\n * Converts a kebab-case string to camelCase\n * @param {string} str - The kebab-case string to convert\n * @returns {string} - The camelCase version of the string\n */\nexport function kebabToCamel (str) {\n // replace each dash followed by a letter with the uppercase version of the letter\n return str.replace(KEBAB_REGEX, function (match, letter) {\n return letter.toUpperCase()\n })\n}\n\n/**\n * Converts all keys in an object from kebab-case to camelCase\n * @template T\n * @param {Record<string, T>} object - The object with kebab-case keys\n * @returns {Record<string, T>} - A new object with camelCase keys\n */\nexport function cleanKeys (object) {\n /** @type {Record<string, T>} */\n const result = {}\n\n for (const [key, value] of Object.entries(object)) {\n result[key] = value\n\n const camelKey = kebabToCamel(key)\n if (camelKey !== key) {\n result[camelKey] = value\n }\n }\n\n return result\n}\n\n/**\n * Recursively clones an object or array and normalizes any function state\n * it finds into a string representation that preserves standard function syntax,\n * bypassing ES6 shorthand method serialization issues.\n * @param {any} target - The object or array to normalize.\n * @param {Function} [transform] - Optional transform function for each node.\n * @param {WeakMap} [seen=new WeakMap()] - Map of seen objects to handle circular references.\n * @returns {any} A deeply cloned object with normalized functions.\n */\nexport function normalizeObjectFunctions (target, transform = null, seen = new WeakMap()) {\n if (typeof transform === 'function') {\n const transformed = transform(target)\n if (transformed !== target) {\n return transformed\n }\n }\n\n if (typeof target !== 'object' || target === null) {\n return target\n }\n\n if (seen.has(target)) {\n return seen.get(target)\n }\n\n if (Array.isArray(target)) {\n const arr = []\n seen.set(target, arr)\n for (let i = 0; i < target.length; i++) {\n arr.push(normalizeObjectFunctions(target[i], transform, seen))\n }\n return arr\n }\n\n const obj = {}\n seen.set(target, obj)\n for (const key in target) {\n if (Object.hasOwn(target, key)) {\n if (typeof target[key] === 'function') {\n const normalizedString = normalizeFunction(target[key])\n const originalFunction = target[key]\n\n const wrapper = function () {\n return originalFunction.apply(this, arguments)\n }\n wrapper.toString = () => normalizedString\n obj[key] = wrapper\n } else {\n obj[key] = normalizeObjectFunctions(target[key], transform, seen)\n }\n }\n }\n\n return obj\n}\n\n/**\n * Checks whether the given object is an object and has at least one own key.\n * @param {any} obj - The object to check.\n * @returns {boolean} True if the object is truthy and has keys, otherwise false.\n */\nexport function hasObjectKeys (obj) {\n return obj && typeof obj === 'object' && Object.keys(obj).length > 0\n}\n\n/**\n * Merges two arrays, returning a new array with unique items.\n * Uses JSON.stringify for deep comparison of object elements, preserving object uniqueness correctly.\n * @param {Array<any>} [arr1] - The first array.\n * @param {Array<any>} [arr2] - The second array.\n * @returns {Array<any>} A new array with unique values from both input arrays.\n */\nexport function mergeUniqueObjects (arr1, arr2) {\n const all = [...(arr1 || []), ...(arr2 || [])]\n const seen = new Set()\n return all.filter(item => {\n const key = typeof item === 'object' ? JSON.stringify(item) : item\n if (seen.has(key)) {\n return false\n }\n seen.add(key)\n return true\n })\n}\n\n/**\n * Normalizes function declarations to ensure consistent formatting.\n * Converts shorthand method syntax to full function declarations where needed,\n * while preserving arrow functions and existing full declarations.\n *\n * @param {Function} func - The function to normalize\n * @returns {string} The normalized function string representation\n */\nexport function normalizeFunction (func) {\n const original = func.toString().trim()\n\n const firstBrace = original.indexOf('{')\n const firstArrow = original.indexOf('=>')\n\n const isArrow = firstArrow !== -1 && (firstBrace === -1 || firstArrow < firstBrace)\n\n if (isArrow) {\n return original\n }\n\n // For non-arrows, extract header to check for shorthand\n const header = firstBrace !== -1 ? original.slice(0, firstBrace).trim() : original\n\n const isStandard = header.startsWith('function') || header.startsWith('async function')\n\n if (isStandard) {\n return original\n }\n\n // Handle Method Shorthand\n if (header.startsWith('async ')) {\n if (header.startsWith('async get ') || header.startsWith('async set ')) {\n return original\n }\n\n return original.replace(/^async\\s+([$\\w]+)\\s*\\(/, 'async function(')\n } else {\n if (header.startsWith('get ') || header.startsWith('set ')) {\n return original\n }\n\n return original.replace(/^([$\\w]+)\\s*\\(/, 'function(')\n }\n}\n\n\n/**\n * Recursively clones an AST node and its children, ensuring that\n * inner references (like parents and slots) point to the newly cloned nodes.\n *\n * @param {Map<Object, Object>} nodeMap - A map tracking original nodes to their newly cloned counterparts.\n * @param {Object} node - The current AST node being cloned.\n * @param {Object} [parent] - The parent node reference to assign to the clone.\n * @returns {Object} The newly cloned node.\n */\nexport function cloneNode (nodeMap, node, parent) {\n const newNode = Object.create(Object.getPrototypeOf(node))\n\n // Copy all own enumerable properties\n Object.assign(newNode, node)\n\n if (parent) {\n newNode.parent = parent\n }\n\n if (newNode.attribs) {\n newNode.attribs = { ...newNode.attribs }\n }\n\n // Register in map\n nodeMap.set(node, newNode)\n\n // Recursively clone children\n if (node.children) {\n const children = node.children\n const length = children.length\n const clonedChildren = new Array(length)\n newNode.children = clonedChildren\n\n for (let i = 0; i < length; i++) {\n const clonedChild = cloneNode(nodeMap, children[i], newNode)\n clonedChildren[i] = clonedChild\n if (i > 0) {\n clonedChild.prev = clonedChildren[i - 1]\n clonedChildren[i - 1].next = clonedChild\n }\n }\n }\n\n // Update slot references to point to new cloned nodes\n if (node.slots) {\n const slots = node.slots\n const length = slots.length\n const clonedSlots = new Array(length)\n for (let i = 0; i < length; i++) {\n const slot = slots[i]\n const clonedSlot = { ...slot }\n if (slot.node) {\n const clonedNode = nodeMap.get(slot.node)\n if (clonedNode) {\n clonedSlot.node = clonedNode\n }\n }\n clonedSlots[i] = clonedSlot\n }\n newNode.slots = clonedSlots\n }\n\n // Preserve the enhanced flag without re-running enhanceNode\n Object.defineProperty(newNode, '__coralite_enhanced__', {\n value: true,\n enumerable: false,\n configurable: true\n })\n\n return newNode\n}\n\n/**\n * Creates a shallow copy of a CoraliteModule with a deep clone of its DOM tree (template) and re-linked internal references to enable safe independent mutation.\n *\n * Top-level non-DOM state (id, path, script, isTemplate, lineOffset) are shallow copied. Nested objects within these state (e.g., path) remain shared references. Only DOM-related structures undergo deep cloning and reference re-linking to isolate mutations from the original module.\n *\n * @param {CoraliteModule} originalModule - Module to clone.\n * @returns {CoraliteModule}\n */\nexport function cloneModuleInstance (originalModule) {\n const nodeMap = new Map()\n\n // Clone the main template tree\n const newTemplate = cloneNode(nodeMap, originalModule.template, null)\n\n // Reconstruct the 'values' object\n const newValues = {\n attributes: originalModule.values.attributes.map(item => ({\n ...item,\n element: nodeMap.get(item.element)\n })),\n textNodes: originalModule.values.textNodes.map(item => ({\n ...item,\n textNode: nodeMap.get(item.textNode)\n })),\n refs: originalModule.values.refs.map(item => ({\n ...item,\n element: nodeMap.get(item.element)\n }))\n }\n\n // Reconstruct customElements list\n const newCustomElements = originalModule.customElements.map(el => nodeMap.get(el))\n\n // Reconstruct slotElements\n const newSlotElements = {}\n if (originalModule.slotElements) {\n for (const modId in originalModule.slotElements) {\n newSlotElements[modId] = {}\n const slotGroup = originalModule.slotElements[modId]\n\n for (const slotName in slotGroup) {\n const slotItem = slotGroup[slotName]\n newSlotElements[modId][slotName] = {\n ...slotItem,\n element: nodeMap.get(slotItem.element)\n }\n }\n }\n }\n\n // Return the new module structure\n return {\n ...originalModule,\n template: newTemplate,\n values: newValues,\n customElements: newCustomElements,\n // @ts-ignore\n slotElements: newSlotElements\n }\n}\n\n/**\n * Creates a deep copy of a CoraliteComponent with re-linked internal references to enable safe independent mutation.\n *\n * @param {CoraliteComponent & CoraliteComponentResult} originalDocument - Document to clone.\n * @returns {CoraliteComponent & CoraliteComponentResult}\n */\nexport function cloneComponentInstance (originalDocument) {\n const nodeMap = new Map()\n const newRoot = cloneNode(nodeMap, originalDocument.root, null)\n\n const newCustomElements = originalDocument.customElements.map(el => nodeMap.get(el))\n const newTempElements = originalDocument.tempElements ? originalDocument.tempElements.map(el => nodeMap.get(el)) : []\n const newSkipRenderElements = originalDocument.skipRenderElements ? originalDocument.skipRenderElements.map(el => nodeMap.get(el)) : []\n\n return {\n ...originalDocument,\n state: { ...originalDocument.state },\n root: newRoot,\n customElements: newCustomElements,\n tempElements: newTempElements,\n skipRenderElements: newSkipRenderElements\n }\n}\n\n/**\n * Calculates the DOM path from a node to the root.\n * @param {Object} node - The node to calculate the path for.\n * @param {Object} root - The root node.\n * @returns {Array<number>} An array of indices representing the path.\n */\nexport function getNodePath (node, root) {\n const path = []\n let current = node\n while (current && current !== root) {\n const parent = current.parent\n if (!parent) {\n break\n }\n const index = parent.children.indexOf(current)\n if (index === -1) {\n break\n }\n path.unshift(index)\n current = parent\n }\n return path\n}\n\n/**\n * Generates a hydration map for the client.\n * @param {Array<Object>} templateNodes - The component's template nodes.\n * @param {Object} templateValues - The component's template values.\n * @returns {Object} The hydration map.\n */\nexport function generateHydrationMap (templateNodes, templateValues) {\n const map = {\n texts: [],\n attributes: [],\n refs: []\n }\n\n if (!templateNodes || !templateValues) {\n return map\n }\n\n const root = templateNodes.length > 0 ? templateNodes[0].parent : { children: templateNodes }\n\n if (templateValues.textNodes) {\n for (const item of templateValues.textNodes) {\n if (item.textNode) {\n const isHtml = item.type === 'html'\n const targetNode = isHtml ? item.textNode.parent : item.textNode\n\n map.texts.push({\n path: getNodePath(targetNode, root),\n template: item.textNode.data,\n type: isHtml ? 'html' : 'text'\n })\n }\n }\n }\n\n if (templateValues.attributes) {\n for (const item of templateValues.attributes) {\n if (item.element && item.element.attribs) {\n const originalValue = item.element.attribs[item.name]\n map.attributes.push({\n path: getNodePath(item.element, root),\n name: item.name,\n template: originalValue\n })\n }\n }\n }\n\n if (templateValues.refs) {\n for (const item of templateValues.refs) {\n if (item.element) {\n map.refs.push({\n path: getNodePath(item.element, root),\n name: item.name\n })\n }\n }\n }\n\n return map\n}\n\n/**\n * Recursively adds a component and its dependencies to a tracking object.\n *\n * @param {string} componentId - The ID of the component to add.\n * @param {Object.<string, boolean>} processed - The object tracking processed components.\n * @param {Object.<string, any>} sharedFunctions - The map of shared component functions.\n */\nexport function addComponentAndDependencies (componentId, processed, sharedFunctions) {\n if (!processed[componentId] && sharedFunctions[componentId]) {\n processed[componentId] = true\n\n // Add all dependencies of this component\n const dependencies = sharedFunctions[componentId].components || []\n for (const depId of dependencies) {\n addComponentAndDependencies(depId, processed, sharedFunctions)\n }\n }\n}\n\n/**\n * Recursively clones an AST node and its children, stripping circular references\n * and assigning unique IDs for client-side hydration.\n *\n * @param {Array<Object>} nodes - The nodes to clean.\n * @param {WeakMap} nodeMap - Map to track original nodes to their unique IDs.\n * @param {Object} state - Object containing the current node counter.\n * @returns {Array<Object>|null} The cleaned AST nodes.\n */\nexport function cleanAST (nodes, nodeMap, state) {\n if (!nodes) {\n return null\n }\n\n return nodes.map((node) => {\n const cloned = { ...node }\n // Assign unique ID for token mapping\n const id = state.counter++\n nodeMap.set(node, id)\n cloned._id = id\n\n // Remove circular references\n delete cloned.parent\n delete cloned.prev\n delete cloned.next\n delete cloned.slots\n\n if (cloned.children) {\n cloned.children = cleanAST(cloned.children, nodeMap, state)\n }\n return cloned\n })\n}\n\n/**\n * Cleans the template values object, mapping original node references to unique IDs.\n *\n * @param {Object} values - The values object to clean.\n * @param {WeakMap} nodeMap - Map of original nodes to their unique IDs.\n * @returns {Object|null} The cleaned values object.\n */\nexport function cleanValues (values, nodeMap) {\n if (!values) {\n return null\n }\n\n const result = { ...values }\n\n if (result.attributes) {\n result.attributes = result.attributes.map(item => {\n const cloned = { ...item }\n cloned.elementId = nodeMap.get(item.element)\n delete cloned.element\n return cloned\n })\n }\n\n if (result.textNodes) {\n result.textNodes = result.textNodes.map(item => {\n const cloned = { ...item }\n cloned.textNodeId = nodeMap.get(item.textNode)\n delete cloned.textNode\n return cloned\n })\n }\n\n if (result.refs) {\n result.refs = result.refs.map(item => {\n const cloned = { ...item }\n cloned.elementId = nodeMap.get(item.element)\n delete cloned.element\n return cloned\n })\n }\n return result\n}\n\n/**\n * Safely merges partial plugin updates into the main context object.\n * Deeply merges plain objects and overwrites other types (arrays, primitives, etc.).\n *\n * @param {any} current - The current state object.\n * @param {any} patch - The patch object containing updates.\n * @returns {any} The newly merged state object.\n */\nexport function mergePluginState (current, patch) {\n if (!patch || typeof patch !== 'object') {\n return current\n }\n\n const result = { ...current }\n\n for (const key of Object.keys(patch)) {\n const patchValue = patch[key]\n const currentValue = result[key]\n\n // If both are plain objects, merge them deeply\n if (\n patchValue && typeof patchValue === 'object' && !Array.isArray(patchValue) &&\n currentValue && typeof currentValue === 'object' && !Array.isArray(currentValue)\n ) {\n result[key] = mergePluginState(currentValue, patchValue)\n } else {\n // Otherwise, overwrite (Arrays, strings, numbers, etc.)\n result[key] = patchValue\n }\n }\n\n return result\n}\n\n/**\n * Creates a reactive proxy that triggers a callback on changes.\n * Supports deep reactivity via lazy proxying of nested objects.\n *\n * @param {Object} target - The object to proxy.\n * @param {Function} onChange - Callback triggered when a property is set or deleted.\n * @param {WeakMap} [proxies=new WeakMap()] - Cache for existing proxies to handle circular references and identity.\n * @returns {Proxy} The reactive proxy.\n */\nexport function createReactiveProxy (target, onChange, proxies = new WeakMap()) {\n if (proxies.has(target)) {\n return proxies.get(target)\n }\n\n const handler = {\n get (target, property, receiver) {\n const value = Reflect.get(target, property, receiver)\n if (value !== null && typeof value === 'object' && !(typeof Node !== 'undefined' && value instanceof Node)) {\n return createReactiveProxy(value, onChange, proxies)\n }\n return value\n },\n set (target, property, value, receiver) {\n const oldValue = target[property]\n if (oldValue === value && property in target) {\n return true\n }\n\n const result = Reflect.set(target, property, value, receiver)\n if (result) {\n onChange({\n property,\n value,\n oldValue,\n target\n })\n }\n return result\n },\n deleteProperty (target, property) {\n const hadProperty = Object.prototype.hasOwnProperty.call(target, property)\n const oldValue = target[property]\n const result = Reflect.deleteProperty(target, property)\n if (result && hadProperty) {\n onChange({\n property,\n value: undefined,\n oldValue,\n target,\n deleted: true\n })\n }\n return result\n }\n }\n\n const proxy = new Proxy(target, handler)\n proxies.set(target, proxy)\n return proxy\n}\n\n/**\n * Creates a read-only proxy that throws on mutation attempts.\n * @param {Object} target - The object to proxy.\n * @param {WeakMap} [proxies=new WeakMap()] - Cache for existing proxies.\n * @returns {Proxy} The read-only proxy.\n */\nexport function createReadOnlyProxy (target, proxies = new WeakMap()) {\n if (proxies.has(target)) {\n return proxies.get(target)\n }\n\n const handler = {\n get (target, property, receiver) {\n const value = Reflect.get(target, property, receiver)\n if (value !== null && typeof value === 'object' && !(typeof Node !== 'undefined' && value instanceof Node)) {\n return createReadOnlyProxy(value, proxies)\n }\n return value\n },\n set () {\n throw new CoraliteError('Cannot mutate state inside a getter. State is read-only here.')\n },\n deleteProperty () {\n throw new CoraliteError('Cannot delete state inside a getter. State is read-only here.')\n }\n }\n\n const proxy = new Proxy(target, handler)\n\n proxies.set(target, proxy)\n\n return proxy\n}\n\n/**\n * Defines a Coralite component.\n * On the client, this acts as an identity function for type safety and HRM.\n * @param {Object} options - Component options\n * @returns {Object} The component options\n */\nexport function defineComponent (options) {\n return options\n}\n\n/**\n * Recursively validates that an object contains only serializable data.\n * Throws a CoraliteError if a function is encountered.\n *\n * @param {any} value - The value to validate.\n * @param {string} [path='root'] - The current path in the object (for error reporting).\n * @param {WeakSet} [seen=new WeakSet()] - Set of seen objects to handle circular references.\n * @throws {CoraliteError} If a function is found.\n */\nexport function validateSerializable (value, path = 'root', seen = new WeakSet()) {\n if (value === null || typeof value !== 'object') {\n if (typeof value === 'function') {\n throw new CoraliteError(`Function detected at \"${path}\". The \"server()\" block must only return serializable data (JSON-compatible plus Date, RegExp, Map, Set). Functions are not allowed.`, {\n path\n })\n }\n\n return\n }\n\n if (seen.has(value)) {\n return\n }\n\n seen.add(value)\n\n if (Array.isArray(value)) {\n for (let i = 0; i < value.length; i++) {\n validateSerializable(value[i], `${path}[${i}]`, seen)\n }\n } else if (value instanceof Map) {\n for (const [key, val] of value.entries()) {\n validateSerializable(val, `${path}.get(${JSON.stringify(key)})`, seen)\n }\n } else if (value instanceof Set) {\n let i = 0\n for (const val of value) {\n validateSerializable(val, `${path}.set[${i++}]`, seen)\n }\n } else {\n for (const key of Object.keys(value)) {\n validateSerializable(value[key], `${path}.${key}`, seen)\n }\n }\n}\n", "import { defineComponent } from '../core.js'\nimport { definePlugin } from '../../plugin.js'\n\n/**\n * Creates a Coralite element or a standard HTML element.\n * Proxy to window.createCoraliteElement or document.createElement.\n *\n * @param {string} tag - The tag name.\n * @param {Object} [options] - Optional element options.\n * @returns {HTMLElement} The created element.\n */\nexport function createCoraliteElement (tag, options) {\n // @ts-ignore\n if (typeof window !== 'undefined' && window.createCoraliteElement) {\n // @ts-ignore\n return window.createCoraliteElement(tag, options)\n }\n return document.createElement(tag, options)\n}\n\n/**\n * Processes an HTML string for custom elements.\n * Proxy to window.processHTML if available.\n *\n * @param {string} html - The HTML string.\n * @returns {string} The HTML string.\n */\nexport function processHTML (html) {\n // @ts-ignore\n if (typeof window !== 'undefined' && window.processHTML) {\n // @ts-ignore\n return window.processHTML(html)\n }\n return html\n}\n\nexport { defineComponent, definePlugin }\n", "/**\n * @import {\n * CoraliteClientPluginDisconnectedCallback,\n * CoraliteClientPluginAfterComponentRenderCallback,\n * CoraliteClientPluginBeforeComponentRenderCallback\n * } from '../types/plugin.js'\n */\n\nimport { createReadOnlyProxy } from './utils/core.js'\nimport { processHTML } from './utils/client/inject.js'\n\nconst BOOLEAN_ATTRIBUTES = new Set([\n 'allowfullscreen',\n 'async',\n 'autofocus',\n 'autoplay',\n 'checked',\n 'controls',\n 'default',\n 'defer',\n 'disabled',\n 'formnovalidate',\n 'hidden',\n 'inert',\n 'ismap',\n 'itemscope',\n 'loop',\n 'multiple',\n 'muted',\n 'nomodule',\n 'novalidate',\n 'open',\n 'playsinline',\n 'readonly',\n 'required',\n 'reversed',\n 'selected',\n 'truespeed'\n])\n\n/**\n * Coerces a value to a specified type.\n * Supports Number, Boolean, and String.\n * @param {any} value - The value to coerce.\n * @param {Function|string} type - The target type (Constructor or string name).\n * @returns {any} The coerced value.\n */\nexport function coerce (value, type) {\n if (value === null || value === undefined) {\n return value\n }\n if (type === Number || type === 'Number') {\n return Number(value)\n }\n if (type === Boolean || type === 'Boolean') {\n if (value === '') {\n return true\n }\n return value !== 'false' && value !== null\n }\n if (type === String || type === 'String') {\n return String(value)\n }\n return value\n}\n\n/**\n * @typedef {Object} CoraliteComponentOptions\n * @property {string} componentId - The unique identifier for the component.\n * @property {string} [templateHTML] - The raw HTML string for imperative mounting.\n * @property {Object} [defaultValues] - The initial state values extracted from the server data block.\n * @property {Object} [attributes] - Schema for coercing HTML attributes into typed primitives.\n * @property {Object.<string, Function>} [getters] - Pure functions for derived state, supporting Promises.\n * @property {Object.<string, Function>} [slots] - Transformation functions for projected Light DOM.\n * @property {Function} [client] - The client-side controller logic.\n * @property {Object} [hydrationMap] - AST mapping for reactive text nodes, attributes, and refs.\n */\n\n/**\n * Base class for all Coralite custom elements.\n *\n * @augments HTMLElement\n */\nexport class CoraliteElement extends HTMLElement {\n /**\n * Initializes a new instance of the CoraliteElement.\n * Sets up internal state trackers, binding collections, and hook registries.\n */\n constructor () {\n super()\n /**\n * Controls native teardown of event listeners and async fetches upon disconnection.\n * @type {AbortController|null}\n * @protected\n */\n this._abortController = null\n\n /**\n * A globally unique, deterministic identifier (e.g., `my-comp-0`).\n * @type {string|null}\n * @protected\n */\n this._instanceId = null\n\n /**\n * The unified, deeply reactive proxy holding attributes, data, and getters.\n * @type {Object|null}\n * @protected\n */\n this._state = null\n\n /**\n * The collection of DOM nodes mapped to template tokens and attributes.\n * @type {Array<{type: string, node: Node, template?: string, name?: string}>}\n * @protected\n */\n this._bindings = []\n\n /**\n * Flag to prevent multiple synchronous state mutations from triggering multiple DOM paints.\n * @type {boolean}\n * @protected\n */\n this._isUpdatePending = false\n\n /**\n * A unique Symbol generated per render cycle to prevent async getter race conditions.\n * @type {symbol|null}\n * @protected\n */\n this._currentRenderVersion = null\n\n /**\n * @type {MutationObserver|null}\n * @protected\n */\n this._observer = null\n\n /**\n * Hook to fetch globally registered Phase-2 plugin contexts.\n * @type {Function|null}\n * @protected\n */\n this._clientContextGetter = null\n\n /**\n * Tracks AbortControllers specifically for cancelling stale async getters.\n * @type {Object.<string, AbortController>|null}\n * @protected\n */\n this._getterAbortControllers = null\n\n /**\n * Internal lifecycle hooks injected by registered Coralite plugins.\n * @type {{\n * onBeforeComponentRender: Array<CoraliteClientPluginBeforeComponentRenderCallback>,\n * onAfterComponentRender: Array<CoraliteClientPluginAfterComponentRenderCallback>,\n * onDisconnected: Array<CoraliteClientPluginDisconnectedCallback>\n * }}\n * @protected\n */\n this._hooks = {\n onBeforeComponentRender: [],\n onAfterComponentRender: [],\n onDisconnected: []\n }\n\n /**\n * The definition and schema of the component generated by the compiler.\n * @type {CoraliteComponentOptions|null}\n */\n this.componentOptions = null\n\n /**\n * Hydrated data passed from the server.\n * @type {Object|null}\n * @protected\n */\n this._hydrationData = null\n }\n\n /**\n * Invoked natively when the element is added to the document.\n * Handles the architectural split between Declarative (SSR) and Imperative (JS) components.\n * Orchestrates template injection, instance ID generation, and state/binding setup.\n */\n connectedCallback () {\n this._abortController = new AbortController()\n\n if (!this.componentOptions) {\n return\n }\n\n // Declarative components receive a data-cid from the server.\n // Imperative components (created via document.createElement) do not.\n const isImperative = !this.hasAttribute('data-cid')\n\n // Imperative Flow: Manually stamp the template and project the Light DOM.\n if (isImperative && this.componentOptions.templateHTML) {\n const originalLightDOM = Array.from(this.childNodes)\n this.innerHTML = processHTML(this.componentOptions.templateHTML)\n\n if (originalLightDOM.length > 0) {\n const slots = this.querySelectorAll('slot')\n slots.forEach(slot => {\n const slotName = slot.getAttribute('name') || 'default'\n const matchingNodes = originalLightDOM.filter(node => {\n // @ts-ignore\n const nodeSlot = (node.getAttribute && node.getAttribute('slot')) || 'default'\n return nodeSlot === slotName\n })\n matchingNodes.forEach(n => slot.appendChild(n))\n })\n }\n }\n\n // Establish the Deterministic Instance ID\n if (this.hasAttribute('data-cid')) {\n this._instanceId = this.getAttribute('data-cid')\n } else {\n // Fallback counter for imperatively created components\n // @ts-ignore\n window.__coralite_instanceCounters = window.__coralite_instanceCounters || {}\n const prefix = this.componentOptions.componentId\n // @ts-ignore\n if (window.__coralite_instanceCounters[prefix] === undefined) {\n // @ts-ignore\n window.__coralite_instanceCounters[prefix] = 0\n }\n // @ts-ignore\n this._instanceId = `${prefix}-${window.__coralite_instanceCounters[prefix]++}`\n }\n\n if (isImperative) {\n this.setAttribute('data-cid', this._instanceId)\n }\n\n this._setupState()\n this._setupBindings()\n this._init(isImperative)\n }\n\n /**\n * Invoked natively when the element is removed from the document.\n * Aborts pending requests and triggers `onDisconnected` plugin hooks\n * to ensure external libraries (e.g., Observers) do not cause memory leaks.\n * @this {any}\n */\n disconnectedCallback () {\n if (this._abortController) {\n this._abortController.abort()\n }\n\n if (!this.componentOptions) {\n return\n }\n\n for (const hook of this._hooks.onDisconnected) {\n hook({\n state: this._state,\n instanceId: this._instanceId,\n componentId: this.componentOptions.componentId,\n element: this,\n options: this.componentOptions\n })\n }\n }\n\n /**\n * Invoked natively when an observed HTML attribute changes.\n * Coerces the raw string value based on the component's attribute schema\n * and synchronizes it into the reactive state proxy.\n * @param {string} name - The kebab-case name of the attribute.\n * @param {string|null} oldVal - The previous value.\n * @param {string|null} newVal - The new value.\n */\n attributeChangedCallback (name, oldVal, newVal) {\n if (!this._state || oldVal === newVal || name === 'data-cid') {\n return\n }\n const camelName = name.replace(/-([a-z])/g, (g) => g[1].toUpperCase())\n const schema = this.componentOptions.attributes?.[camelName] || this.componentOptions.attributes?.[name]\n const value = schema ? coerce(newVal, schema.type) : newVal\n\n this._state[camelName] = value\n }\n\n /**\n * Constructs the unified state object.\n * Merges `defaultValues`, JSON hydration payloads, and DOM attributes.\n * Defines getters (wrapping state in a Read-Only proxy) and applies the final Read/Write Proxy.\n * @this {any}\n * @private\n */\n _setupState () {\n const options = this.componentOptions\n const target = { ...options.defaultValues }\n\n /** @type {Array<{name: string, element: HTMLElement}>} */\n const refs = []\n if (options.hydrationMap && options.hydrationMap.refs) {\n for (const ref of options.hydrationMap.refs) {\n const uniqueRefValue = `${this._instanceId}__${ref.name}`\n\n if (!target[`ref_${ref.name}`]) {\n target[`ref_${ref.name}`] = uniqueRefValue\n }\n\n const node = this.getNodeByPath(ref.path)\n if (node) {\n if (node.setAttribute) {\n node.setAttribute('ref', uniqueRefValue)\n }\n refs.push({\n name: ref.name,\n element: node\n })\n }\n }\n }\n\n // Process initial attributes mapping\n for (const attr of this.attributes) {\n if (attr.name === 'data-cid') {\n continue\n }\n const camelName = attr.name.replace(/-([a-z])/g, (g) => g[1].toUpperCase())\n const schema = options.attributes?.[camelName] || options.attributes?.[attr.name]\n target[camelName] = schema ? coerce(attr.value, schema.type) : attr.value\n }\n\n // Hydrate data() block results from the SSR payload\n if (this._hydrationData && this._hydrationData[this._instanceId]) {\n Object.assign(target, this._hydrationData[this._instanceId])\n }\n\n // Trigger Before-Render hooks BEFORE state is proxied, allowing plugins to inject reactive data\n for (const hook of this._hooks.onBeforeComponentRender) {\n hook({\n state: target,\n instanceId: this._instanceId,\n componentId: this.componentOptions.componentId,\n refs,\n element: this,\n options: this.componentOptions\n })\n }\n\n // Define derived state getters with isolation controllers\n this._getterAbortControllers = {}\n for (const [key, getter] of Object.entries(options.getters || {})) {\n Object.defineProperty(target, key, {\n get: () => {\n if (this._getterAbortControllers[key]) {\n this._getterAbortControllers[key].abort()\n }\n this._getterAbortControllers[key] = new AbortController()\n\n // Enforce \"Dual-Proxy\" safety: Getters cannot mutate state\n const roState = createReadOnlyProxy(this._state)\n return getter(roState, { signal: this._getterAbortControllers[key].signal })\n },\n enumerable: true,\n configurable: true\n })\n }\n\n this._state = this._createReactiveProxy(target)\n }\n\n /**\n * Wraps the state target in a reactive Proxy.\n * Intercepts property setters to automatically batch and schedule DOM updates.\n * @param {Object} target - The state dictionary.\n * @returns {Proxy} The reactive state proxy.\n * @private\n */\n _createReactiveProxy (target) {\n const self = this\n return new Proxy(target, {\n set (t, p, v) {\n if (t[p] === v) {\n return true\n }\n t[p] = v\n self._scheduleUpdate()\n return true\n }\n })\n }\n\n /**\n * Traverses the DOM tree using an AST-generated path index array.\n * Allows O(1) element lookups without relying on querySelectors or classes.\n * @param {number[]} path - Array of childNode indices (e.g., `[0, 1, 2]`).\n * @returns {Node|null} The physical DOM node, or null if traversal fails.\n */\n getNodeByPath (path) {\n let node = this\n for (const index of path) {\n if (!node) {\n return null\n }\n // @ts-ignore\n node = node.childNodes[index]\n }\n return node\n }\n\n /**\n * Initializes DOM bindings based on the compiler's hydration map.\n * Caches physical DOM references to text nodes and attributes that contain template tokens.\n * @private\n */\n _setupBindings () {\n this._bindings = []\n const map = this.componentOptions.hydrationMap\n if (!map) {\n return\n }\n\n if (map.texts) {\n for (const item of map.texts) {\n const node = this.getNodeByPath(item.path)\n if (node) {\n this._bindings.push({\n type: item.type || 'text',\n node,\n template: item.template\n })\n }\n }\n }\n\n if (map.attributes) {\n for (const item of map.attributes) {\n const node = this.getNodeByPath(item.path)\n if (node) {\n this._bindings.push({\n type: 'attribute',\n node,\n name: item.name,\n template: item.template\n })\n }\n }\n }\n }\n\n /**\n * Schedules a DOM update in the next microtask queue.\n * This guarantees that multiple synchronous state mutations result in only one render pass.\n * @private\n */\n _scheduleUpdate () {\n if (this._isUpdatePending) {\n return\n }\n this._isUpdatePending = true\n queueMicrotask(() => {\n this._updateDOM()\n this._isUpdatePending = false\n })\n }\n\n /**\n * Performs the physical DOM update and resolves template tokens.\n * **Async Safety:** Implements a Symbol-based locking mechanism (`renderVersion`)\n * to guarantee that if state mutates while an async getter is pending, the stale\n * Promise will be discarded, preventing DOM race conditions.\n * @this {any}\n * @private\n */\n _updateDOM () {\n // Create a unique lock for this specific render cycle\n const renderVersion = Symbol()\n this._currentRenderVersion = renderVersion\n\n // Extract unique tokens to prevent double-reading and accidental aborts\n /** @type {Set<string>} */\n const requiredTokens = new Set()\n for (const binding of this._bindings) {\n binding.template.replace(/\\{\\{\\s*(.+?)\\s*\\}\\}/g, (_, key) => {\n requiredTokens.add(key)\n return ''\n })\n }\n\n const evaluatedTokens = {}\n let hasPromise = false\n\n // Evaluate getters exactly once per render cycle\n for (const key of requiredTokens) {\n let val = this._state[key]\n if (typeof val === 'function') {\n val = val(this._state)\n }\n evaluatedTokens[key] = val\n if (val instanceof Promise) {\n hasPromise = true\n }\n }\n\n // The DOM Mutator Function\n const applyBindings = (tokenValues) => {\n // Race Condition Lock: Abort if a newer render cycle has already begun\n if (this._currentRenderVersion !== renderVersion) {\n return\n }\n\n for (const binding of this._bindings) {\n const hydratedValue = binding.template.replace(/\\{\\{\\s*(.+?)\\s*\\}\\}/g, (_, key) => {\n return tokenValues[key] ?? ''\n })\n\n if (binding.type === 'text') {\n if (binding.node.textContent !== hydratedValue) {\n binding.node.textContent = hydratedValue\n }\n } else if (binding.type === 'html') {\n /** @type {HTMLElement} */\n // @ts-ignore\n const element = binding.node\n\n if (element.innerHTML !== hydratedValue) {\n element.innerHTML = hydratedValue\n }\n } else if (binding.type === 'attribute') {\n /** @type {HTMLElement} */\n // @ts-ignore\n const element = binding.node\n\n if (BOOLEAN_ATTRIBUTES.has(binding.name)) {\n const isFalsy = hydratedValue === '' || hydratedValue === 'false' || hydratedValue === 'null' || hydratedValue === '0' || hydratedValue === 'undefined'\n if (isFalsy) {\n element.removeAttribute(binding.name)\n } else {\n element.setAttribute(binding.name, '')\n }\n } else {\n if (element.getAttribute(binding.name) !== hydratedValue) {\n element.setAttribute(binding.name, hydratedValue)\n }\n }\n }\n }\n\n this._processSlots()\n\n // Trigger After-Render hooks ONLY after the physical DOM is stable\n for (const hook of this._hooks.onAfterComponentRender) {\n hook({\n state: this._state,\n instanceId: this._instanceId,\n componentId: this.componentOptions.componentId,\n element: this,\n options: this.componentOptions\n })\n }\n }\n\n // Await Promises or Apply Synchronously\n if (hasPromise) {\n const keys = Object.keys(evaluatedTokens)\n const promises = keys.map(k => Promise.resolve(evaluatedTokens[k]))\n\n Promise.all(promises).then(resolvedValues => {\n const resolvedMap = {}\n keys.forEach((k, i) => {\n resolvedMap[k] = resolvedValues[i]\n })\n applyBindings(resolvedMap)\n }).catch(e => {\n if (e.name !== 'AbortError') {\n console.error('Coralite Async Getter Error:', e)\n }\n })\n } else {\n applyBindings(evaluatedTokens)\n }\n }\n\n /**\n * Evaluates and projects Light DOM elements into their respective `<slot>` nodes.\n * Invokes component-specific slot transformation functions.\n * @private\n */\n _processSlots () {\n const slots = this.componentOptions.slots\n if (!slots || Object.keys(slots).length === 0) {\n return\n }\n\n const slotElements = this.querySelectorAll('slot')\n slotElements.forEach(slotEl => {\n const slotName = slotEl.getAttribute('name') || 'default'\n const slotFn = slots[slotName]\n\n if (slotFn) {\n // @ts-ignore\n if (!slotEl._originalNodes) {\n // @ts-ignore\n slotEl._originalNodes = Array.from(slotEl.childNodes).map(n => n.cloneNode(true))\n }\n\n // @ts-ignore\n const result = slotFn(slotEl._originalNodes, this._state)\n\n if (result === undefined) {\n return\n }\n\n if (result === null || result === '' || (Array.isArray(result) && result.length === 0)) {\n slotEl.innerHTML = ''\n return\n }\n\n if (typeof result === 'string') {\n slotEl.innerHTML = result\n } else if (Array.isArray(result)) {\n slotEl.replaceChildren(...result)\n }\n }\n })\n }\n\n /**\n * The final initialization pipeline.\n * Injects globally registered client plugins into the local context payload,\n * triggers the initial DOM render, and invokes the user's `script()` logic.\n * @param {boolean} [isImperative=false] - If true, initial render runs synchronously.\n * @private\n */\n async _init (isImperative = false) {\n const self = this\n /**\n * The context payload injected into the user's script block.\n * @type {Object}\n */\n let localContext = {\n instanceId: this._instanceId,\n state: this._state,\n root: this,\n signal: this._abortController.signal,\n refs (id) {\n const refId = self._state[`ref_${id}`]\n if (!refId && typeof refId !== 'string') {\n return null\n }\n return self.querySelector(`[ref=\"${refId}\"]`)\n }\n }\n\n if (typeof this._clientContextGetter === 'function') {\n localContext = await this._clientContextGetter(localContext)\n }\n\n if (isImperative) {\n this._updateDOM()\n } else {\n this._scheduleUpdate()\n }\n\n if (this.componentOptions.client) {\n try {\n this.componentOptions.client(localContext)\n } catch (error) {\n console.error(`Coralite Error: Component \"${this.componentOptions.componentId}\" script failed:`, error)\n }\n }\n }\n}\n\n/**\n * Factory function to create a Coralite element class.\n * It dynamically defines the class, including observed attributes and hook initialization.\n * @param {CoraliteComponentOptions} options - Component options and metadata.\n * @param {Function|null} [contextGetter=null] - Optional function to retrieve client-side plugin context.\n * @param {Object} [hooks={}] - Lifecycle hooks to register.\n * @param {Array<CoraliteClientPluginBeforeComponentRenderCallback>} [hooks.onBeforeComponentRender] - Hooks to run before render.\n * @param {Array<CoraliteClientPluginAfterComponentRenderCallback>} [hooks.onAfterComponentRender] - Hooks to run after render.\n * @param {Array<CoraliteClientPluginDisconnectedCallback>} [hooks.onDisconnected] - Hooks to run after render.\n * @param {Object|null} [hydrationData=null] - Hydrated data passed from the server.\n * @returns {typeof CoraliteElement} A new CoraliteElement subclass.\n */\nexport function createCoraliteClass (options, contextGetter = null, hooks = {}, hydrationData = null) {\n return class extends CoraliteElement {\n /**\n * The attributes to observe for changes.\n * @returns {string[]} Array of attribute names.\n */\n static get observedAttributes () {\n if (!options.attributes) {\n return []\n }\n return Object.keys(options.attributes).map(key => key.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase()\n )\n }\n\n /**\n * Initializes the dynamic Coralite element.\n */\n constructor () {\n super()\n this.componentOptions = options\n this._clientContextGetter = contextGetter\n this._hydrationData = hydrationData\n this._hooks = {\n onBeforeComponentRender: hooks.onBeforeComponentRender || [],\n onAfterComponentR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ceRoot":"","sources":["../../lib/coralite.js"],"names":[],"mappings":"AAwBA;;;;;;;GAOG;AAEH;;;;;GAKG;AACH,2LAHW,cAAc,GACZ,OAAO,CAAC,gBAAgB,CAAC,
|
|
1
|
+
{"version":3,"file":"coralite.d.ts","sourceRoot":"","sources":["../../lib/coralite.js"],"names":[],"mappings":"AAwBA;;;;;;;GAOG;AAEH;;;;;GAKG;AACH,2LAHW,cAAc,GACZ,OAAO,CAAC,gBAAgB,CAAC,CAgXrC;;oCAvXS,mBAAmB;sCAAnB,mBAAmB"}
|
package/dist/lib/index.js
CHANGED
|
@@ -17,6 +17,7 @@ var CoraliteError = class extends Error {
|
|
|
17
17
|
* @param {string} [options.filePath] - The path to the file where the error occurred.
|
|
18
18
|
* @param {string} [options.instanceId] - The unique ID of the component instance.
|
|
19
19
|
* @param {string} [options.pagePath] - The path to the page being rendered.
|
|
20
|
+
* @param {string} [options.path] - The path to the data property where the error occurred.
|
|
20
21
|
* @param {number} [options.line] - The line number where the error occurred.
|
|
21
22
|
* @param {number} [options.column] - The column number where the error occurred.
|
|
22
23
|
* @param {string} [options.stackFile] - The file name from the stack trace.
|
|
@@ -30,6 +31,7 @@ var CoraliteError = class extends Error {
|
|
|
30
31
|
this.filePath = options.filePath;
|
|
31
32
|
this.instanceId = options.instanceId;
|
|
32
33
|
this.pagePath = options.pagePath;
|
|
34
|
+
this.path = options.path;
|
|
33
35
|
this.line = options.line;
|
|
34
36
|
this.column = options.column;
|
|
35
37
|
this.stackFile = options.stackFile;
|
|
@@ -58,6 +60,7 @@ function handleError({ onErrorCallback, data }) {
|
|
|
58
60
|
data.filePath = data.filePath || coraliteError.filePath;
|
|
59
61
|
data.instanceId = data.instanceId || coraliteError.instanceId;
|
|
60
62
|
data.pagePath = data.pagePath || coraliteError.pagePath;
|
|
63
|
+
data.path = data.path || coraliteError.path;
|
|
61
64
|
data.line = data.line || coraliteError.line;
|
|
62
65
|
data.column = data.column || coraliteError.column;
|
|
63
66
|
data.stackFile = data.stackFile || coraliteError.stackFile;
|
|
@@ -2085,6 +2088,38 @@ function createReadOnlyProxy(target, proxies = /* @__PURE__ */ new WeakMap()) {
|
|
|
2085
2088
|
function defineComponent(options) {
|
|
2086
2089
|
return options;
|
|
2087
2090
|
}
|
|
2091
|
+
function validateSerializable(value, path2 = "root", seen = /* @__PURE__ */ new WeakSet()) {
|
|
2092
|
+
if (value === null || typeof value !== "object") {
|
|
2093
|
+
if (typeof value === "function") {
|
|
2094
|
+
throw new CoraliteError(`Function detected at "${path2}". The "server()" block must only return serializable data (JSON-compatible plus Date, RegExp, Map, Set). Functions are not allowed.`, {
|
|
2095
|
+
path: path2
|
|
2096
|
+
});
|
|
2097
|
+
}
|
|
2098
|
+
return;
|
|
2099
|
+
}
|
|
2100
|
+
if (seen.has(value)) {
|
|
2101
|
+
return;
|
|
2102
|
+
}
|
|
2103
|
+
seen.add(value);
|
|
2104
|
+
if (Array.isArray(value)) {
|
|
2105
|
+
for (let i = 0; i < value.length; i++) {
|
|
2106
|
+
validateSerializable(value[i], `${path2}[${i}]`, seen);
|
|
2107
|
+
}
|
|
2108
|
+
} else if (value instanceof Map) {
|
|
2109
|
+
for (const [key, val] of value.entries()) {
|
|
2110
|
+
validateSerializable(val, `${path2}.get(${JSON.stringify(key)})`, seen);
|
|
2111
|
+
}
|
|
2112
|
+
} else if (value instanceof Set) {
|
|
2113
|
+
let i = 0;
|
|
2114
|
+
for (const val of value) {
|
|
2115
|
+
validateSerializable(val, `${path2}.set[${i++}]`, seen);
|
|
2116
|
+
}
|
|
2117
|
+
} else {
|
|
2118
|
+
for (const key of Object.keys(value)) {
|
|
2119
|
+
validateSerializable(value[key], `${path2}.${key}`, seen);
|
|
2120
|
+
}
|
|
2121
|
+
}
|
|
2122
|
+
}
|
|
2088
2123
|
|
|
2089
2124
|
// lib/utils/server/server.js
|
|
2090
2125
|
import { parse as parseJS } from "acorn";
|
|
@@ -2890,7 +2925,7 @@ export default {
|
|
|
2890
2925
|
const index = parseInt(path2.replace(moduleNamespace, ""), 10);
|
|
2891
2926
|
const module = this.scriptModules[index];
|
|
2892
2927
|
let contents = "";
|
|
2893
|
-
const configContent = module.config ? `const pluginConfig = ${
|
|
2928
|
+
const configContent = module.config ? `const pluginConfig = ${serialize(module.config)};` : "const pluginConfig = {};";
|
|
2894
2929
|
contents += configContent + "\n";
|
|
2895
2930
|
const beforeFn = module.onBeforeComponentRender ? normalizeFunction(module.onBeforeComponentRender) : "null";
|
|
2896
2931
|
contents += `export const onBeforeComponentRender = ${beforeFn};
|
|
@@ -2909,7 +2944,7 @@ export default {
|
|
|
2909
2944
|
}
|
|
2910
2945
|
const fn = normalizeFunction(module.context);
|
|
2911
2946
|
const clientConfig = module.client?.config || module.config || {};
|
|
2912
|
-
const configStr =
|
|
2947
|
+
const configStr = serialize(clientConfig);
|
|
2913
2948
|
contents += ` "${clientName}": async (globalContext) => {
|
|
2914
2949
|
`;
|
|
2915
2950
|
contents += ` const fn = ${fn};
|
|
@@ -2926,7 +2961,14 @@ export default {
|
|
|
2926
2961
|
return Reflect.set(target, prop, value);
|
|
2927
2962
|
}
|
|
2928
2963
|
});
|
|
2929
|
-
|
|
2964
|
+
let phase2;
|
|
2965
|
+
try {
|
|
2966
|
+
phase2 = await fn(pluginContext);
|
|
2967
|
+
} catch (e) {
|
|
2968
|
+
console.error('Coralite Plugin Error: Failed to initialize client context for plugin "${clientName}" phase 1:', e);
|
|
2969
|
+
throw e;
|
|
2970
|
+
}
|
|
2971
|
+
|
|
2930
2972
|
if (typeof phase2 !== 'function') {
|
|
2931
2973
|
throw new Error('Coralite Plugin Error: The "context" function of client plugin "${clientName}" must return a function for the second phase (instance context). Received: ' + typeof phase2);
|
|
2932
2974
|
}
|
|
@@ -3450,7 +3492,7 @@ var testingPlugin = definePlugin({
|
|
|
3450
3492
|
|
|
3451
3493
|
// lib/coralite.js
|
|
3452
3494
|
import { mkdir as mkdir3, writeFile as writeFile2 } from "node:fs/promises";
|
|
3453
|
-
import { dirname as dirname7, join as join5, normalize, relative as
|
|
3495
|
+
import { dirname as dirname7, join as join5, normalize, relative as relative4 } from "node:path";
|
|
3454
3496
|
|
|
3455
3497
|
// lib/utils/server/errors.js
|
|
3456
3498
|
import { parse as parseJS3 } from "acorn";
|
|
@@ -4715,10 +4757,11 @@ function createPageHandlers({
|
|
|
4715
4757
|
|
|
4716
4758
|
// lib/renderer.js
|
|
4717
4759
|
import { randomUUID } from "node:crypto";
|
|
4718
|
-
import { dirname as dirname6, join as join4 } from "node:path";
|
|
4760
|
+
import { dirname as dirname6, join as join4, relative as relative3 } from "node:path";
|
|
4719
4761
|
import { availableParallelism as availableParallelism2 } from "node:os";
|
|
4720
|
-
import { readFile as readFile3, writeFile, mkdir as mkdir2, rename } from "node:fs/promises";
|
|
4762
|
+
import { readFile as readFile3, writeFile, mkdir as mkdir2, rename, access as access2 } from "node:fs/promises";
|
|
4721
4763
|
import pLimit2 from "p-limit";
|
|
4764
|
+
import serialize2 from "serialize-javascript";
|
|
4722
4765
|
|
|
4723
4766
|
// lib/utils/server/render.js
|
|
4724
4767
|
function findHeadAndBody(root) {
|
|
@@ -4945,12 +4988,14 @@ function generateClientRuntime({
|
|
|
4945
4988
|
base,
|
|
4946
4989
|
sharedChunkPath,
|
|
4947
4990
|
chunkManifest,
|
|
4948
|
-
declarativeTags = []
|
|
4991
|
+
declarativeTags = [],
|
|
4992
|
+
hydrationData = "{}"
|
|
4949
4993
|
}) {
|
|
4950
4994
|
return `
|
|
4951
4995
|
import { getClientContext, createCoraliteClass, globalClientHooks } from '${base}assets/js/${sharedChunkPath}';
|
|
4952
4996
|
|
|
4953
4997
|
(async () => {
|
|
4998
|
+
const hydrationData = ${hydrationData};
|
|
4954
4999
|
if (!window.__coralite_ready__) {
|
|
4955
5000
|
window.__coralite_ready__ = new Promise(resolve => { window.__coralite_resolve_ready__ = resolve; });
|
|
4956
5001
|
}
|
|
@@ -4996,7 +5041,7 @@ import { getClientContext, createCoraliteClass, globalClientHooks } from '${base
|
|
|
4996
5041
|
document.head.appendChild(style);
|
|
4997
5042
|
}
|
|
4998
5043
|
}
|
|
4999
|
-
customElements.define(id, createCoraliteClass(module.default, getClientContext, globalClientHooks));
|
|
5044
|
+
customElements.define(id, createCoraliteClass(module.default, getClientContext, globalClientHooks, hydrationData));
|
|
5000
5045
|
}
|
|
5001
5046
|
|
|
5002
5047
|
// Upgrade any existing elements that might have been created before the definition was loaded
|
|
@@ -6004,34 +6049,20 @@ function createRenderer({
|
|
|
6004
6049
|
injectReadinessScript(mappedComponent.root, headElement, true);
|
|
6005
6050
|
injectImportMap(mappedComponent.root, headElement, scriptResult.importMap);
|
|
6006
6051
|
const base = normalizedOptions.baseURL.endsWith("/") ? normalizedOptions.baseURL : normalizedOptions.baseURL + "/";
|
|
6007
|
-
const scriptContent = generateClientRuntime({
|
|
6008
|
-
base,
|
|
6009
|
-
sharedChunkPath: scriptResult.manifest["coralite-runtime"],
|
|
6010
|
-
chunkManifest,
|
|
6011
|
-
declarativeTags: Array.from(declarativeTags)
|
|
6012
|
-
});
|
|
6013
6052
|
const hydrationData = {};
|
|
6014
6053
|
for (const [id, instance] of Object.entries(instances)) {
|
|
6015
6054
|
if (instance.state && Object.keys(instance.state).length > 0) {
|
|
6055
|
+
validateSerializable(instance.state, `component "${instance.componentId}" state`);
|
|
6016
6056
|
hydrationData[id] = normalizeObjectFunctions(instance.state, astTransformer);
|
|
6017
6057
|
}
|
|
6018
6058
|
}
|
|
6019
|
-
const
|
|
6020
|
-
|
|
6021
|
-
|
|
6022
|
-
|
|
6023
|
-
|
|
6024
|
-
|
|
6025
|
-
type: "application/json"
|
|
6026
|
-
},
|
|
6027
|
-
children: []
|
|
6059
|
+
const scriptContent = generateClientRuntime({
|
|
6060
|
+
base,
|
|
6061
|
+
sharedChunkPath: scriptResult.manifest["coralite-runtime"],
|
|
6062
|
+
chunkManifest,
|
|
6063
|
+
declarativeTags: Array.from(declarativeTags),
|
|
6064
|
+
hydrationData: serialize2(hydrationData)
|
|
6028
6065
|
});
|
|
6029
|
-
hydrationScriptElement.children.push(createCoraliteTextNode({
|
|
6030
|
-
type: "text",
|
|
6031
|
-
data: JSON.stringify(hydrationData),
|
|
6032
|
-
parent: hydrationScriptElement
|
|
6033
|
-
}));
|
|
6034
|
-
bodyElement.children.push(hydrationScriptElement);
|
|
6035
6066
|
const scriptElement = createCoraliteElement({
|
|
6036
6067
|
type: "tag",
|
|
6037
6068
|
name: "script",
|
|
@@ -6252,6 +6283,15 @@ function createRenderer({
|
|
|
6252
6283
|
};
|
|
6253
6284
|
for (const pageItem of queue) {
|
|
6254
6285
|
let shouldRebuild = false;
|
|
6286
|
+
if (normalizedOptions.output && normalizedOptions.mode === "production") {
|
|
6287
|
+
const relativeDir = relative3(normalizedOptions.path.pages, pageItem.path.dirname);
|
|
6288
|
+
const outFile = join4(normalizedOptions.output, relativeDir, pageItem.path.filename);
|
|
6289
|
+
try {
|
|
6290
|
+
await access2(outFile);
|
|
6291
|
+
} catch {
|
|
6292
|
+
shouldRebuild = true;
|
|
6293
|
+
}
|
|
6294
|
+
}
|
|
6255
6295
|
const componentIds = Object.keys(pageCustomElements).filter((id) => {
|
|
6256
6296
|
const pages = pageCustomElements[id];
|
|
6257
6297
|
if (pages instanceof Set) {
|
|
@@ -6263,7 +6303,7 @@ function createRenderer({
|
|
|
6263
6303
|
shouldRebuild = true;
|
|
6264
6304
|
}
|
|
6265
6305
|
if (pageItem.virtual) {
|
|
6266
|
-
if (pageItem.volatile || !manifest.virtual || !manifest.virtual[pageItem.path.pathname] || String(manifest.virtual[pageItem.path.pathname].cacheKey) !== String(pageItem.cacheKey) || normalizedOptions.mode === "development") {
|
|
6306
|
+
if (shouldRebuild || pageItem.volatile || !manifest.virtual || !manifest.virtual[pageItem.path.pathname] || String(manifest.virtual[pageItem.path.pathname].cacheKey) !== String(pageItem.cacheKey) || normalizedOptions.mode === "development") {
|
|
6267
6307
|
shouldRebuild = true;
|
|
6268
6308
|
} else {
|
|
6269
6309
|
shouldRebuild = false;
|
|
@@ -6620,7 +6660,7 @@ async function createCoralite({
|
|
|
6620
6660
|
const outputDir = app.options.output;
|
|
6621
6661
|
const results = [];
|
|
6622
6662
|
await app.build(savePath, saveOptions, async (result) => {
|
|
6623
|
-
const relativeDir =
|
|
6663
|
+
const relativeDir = relative4(app.options.path.pages, result.path.dirname);
|
|
6624
6664
|
const outDir = join5(outputDir, relativeDir);
|
|
6625
6665
|
const outFile = join5(outDir, result.path.filename);
|
|
6626
6666
|
if (result.status === "skipped") {
|
|
@@ -6879,6 +6919,7 @@ export {
|
|
|
6879
6919
|
removeElements,
|
|
6880
6920
|
replaceToken,
|
|
6881
6921
|
resolvePageQueue,
|
|
6882
|
-
transformCss
|
|
6922
|
+
transformCss,
|
|
6923
|
+
validateSerializable
|
|
6883
6924
|
};
|
|
6884
6925
|
//# sourceMappingURL=index.js.map
|