@coherent.js/core 1.0.0-rc.6 → 1.0.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/index.js CHANGED
@@ -505,6 +505,110 @@ function createPerformanceMonitor(options = {}) {
505
505
  }
506
506
  var performanceMonitor = createPerformanceMonitor();
507
507
 
508
+ // src/core/html-utils.js
509
+ function escapeHtml(text) {
510
+ if (typeof text !== "string") return text;
511
+ return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
512
+ }
513
+ function isTrustedContent(value) {
514
+ return Boolean(value) && typeof value === "object" && value.__trusted === true && typeof value.__html === "string";
515
+ }
516
+ function isVoidElement(tagName) {
517
+ if (typeof tagName !== "string") {
518
+ return false;
519
+ }
520
+ const voidElements = /* @__PURE__ */ new Set([
521
+ "area",
522
+ "base",
523
+ "br",
524
+ "col",
525
+ "embed",
526
+ "hr",
527
+ "img",
528
+ "input",
529
+ "link",
530
+ "meta",
531
+ "param",
532
+ "source",
533
+ "track",
534
+ "wbr"
535
+ ]);
536
+ return voidElements.has(tagName.toLowerCase());
537
+ }
538
+ function formatAttributes(props) {
539
+ let formatted = "";
540
+ for (const key in props) {
541
+ if (props.hasOwnProperty(key)) {
542
+ let value = props[key];
543
+ const attributeName = key === "className" ? "class" : key;
544
+ if (typeof value === "function") {
545
+ if (attributeName.startsWith("on")) {
546
+ const actionId = `__coherent_action_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
547
+ const DEBUG = typeof process !== "undefined" && process && process.env && (process.env.COHERENT_DEBUG === "1" || true) || typeof window !== "undefined" && window && window.COHERENT_DEBUG === true;
548
+ if (typeof global !== "undefined") {
549
+ if (!global.__coherentActionRegistry) {
550
+ global.__coherentActionRegistry = {};
551
+ if (DEBUG) console.log("Initialized global action registry");
552
+ }
553
+ global.__coherentActionRegistry[actionId] = value;
554
+ if (DEBUG) console.log(`Added action ${actionId} to global registry, total: ${Object.keys(global.__coherentActionRegistry).length}`);
555
+ if (DEBUG) console.log(`Global registry keys: ${Object.keys(global.__coherentActionRegistry).join(", ")}`);
556
+ if (DEBUG) {
557
+ if (typeof global.__coherentActionRegistryLog === "undefined") {
558
+ global.__coherentActionRegistryLog = [];
559
+ }
560
+ global.__coherentActionRegistryLog.push({
561
+ action: "add",
562
+ actionId,
563
+ timestamp: Date.now(),
564
+ registrySize: Object.keys(global.__coherentActionRegistry).length
565
+ });
566
+ }
567
+ } else if (typeof window !== "undefined") {
568
+ if (!window.__coherentActionRegistry) {
569
+ window.__coherentActionRegistry = {};
570
+ if (DEBUG) console.log("Initialized window action registry");
571
+ }
572
+ window.__coherentActionRegistry[actionId] = value;
573
+ if (DEBUG) console.log(`Added action ${actionId} to window registry, total: ${Object.keys(window.__coherentActionRegistry).length}`);
574
+ if (DEBUG) console.log(`Window registry keys: ${Object.keys(window.__coherentActionRegistry).join(", ")}`);
575
+ }
576
+ const eventType = attributeName.substring(2);
577
+ formatted += ` data-action="${actionId}" data-event="${eventType}"`;
578
+ continue;
579
+ } else {
580
+ try {
581
+ value = value();
582
+ } catch (_error) {
583
+ console.warn(`Error executing function for attribute '${key}':`, {
584
+ _error: _error.message,
585
+ stack: _error.stack,
586
+ attributeKey: key
587
+ });
588
+ value = "";
589
+ }
590
+ }
591
+ }
592
+ if (attributeName === "style" && typeof value === "object" && value !== null) {
593
+ const cssString = Object.entries(value).map(([prop, val]) => {
594
+ const kebabProp = prop.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`);
595
+ return `${kebabProp}: ${val}`;
596
+ }).join("; ");
597
+ formatted += ` ${attributeName}="${escapeHtml(cssString)}"`;
598
+ } else if (value === true) {
599
+ formatted += ` ${attributeName}`;
600
+ } else if (value !== false && value !== null && value !== void 0) {
601
+ formatted += ` ${attributeName}="${escapeHtml(String(value))}"`;
602
+ }
603
+ }
604
+ }
605
+ return formatted.trim();
606
+ }
607
+ function minifyHtml(html, options = {}) {
608
+ if (!options.minify) return html;
609
+ return html.replace(/<!--[\s\S]*?-->/g, "").replace(/\s+/g, " ").replace(/>\s+</g, "><").trim();
610
+ }
611
+
508
612
  // src/core/object-utils.js
509
613
  function deepClone(obj, seen = /* @__PURE__ */ new WeakMap()) {
510
614
  if (obj === null || typeof obj !== "object") {
@@ -1086,13 +1190,15 @@ var FORBIDDEN_CHILDREN = {
1086
1190
  // Links cannot nest
1087
1191
  button: /* @__PURE__ */ new Set(["button", "a", "input", "select", "textarea", "label"]),
1088
1192
  label: /* @__PURE__ */ new Set(["label"]),
1089
- // Table structure restrictions
1090
- thead: /* @__PURE__ */ new Set(["thead", "tbody", "tfoot", "caption", "colgroup", "tr"]),
1193
+ // Table structure restrictions.
1194
+ // thead/tbody/tfoot take "zero or more tr elements", so <tr> is allowed.
1195
+ thead: /* @__PURE__ */ new Set(["thead", "tbody", "tfoot", "caption", "colgroup"]),
1091
1196
  tbody: /* @__PURE__ */ new Set(["thead", "tbody", "tfoot", "caption", "colgroup"]),
1092
1197
  tfoot: /* @__PURE__ */ new Set(["thead", "tbody", "tfoot", "caption", "colgroup"]),
1093
1198
  tr: /* @__PURE__ */ new Set(["tr", "thead", "tbody", "tfoot", "table"]),
1094
- td: /* @__PURE__ */ new Set(["td", "th", "tr", "thead", "tbody", "tfoot", "table"]),
1095
- th: /* @__PURE__ */ new Set(["td", "th", "tr", "thead", "tbody", "tfoot", "table"]),
1199
+ // td/th take flow content, which includes <table> -- nested tables are valid.
1200
+ td: /* @__PURE__ */ new Set(["td", "th", "tr", "thead", "tbody", "tfoot"]),
1201
+ th: /* @__PURE__ */ new Set(["td", "th", "tr", "thead", "tbody", "tfoot"]),
1096
1202
  // Other common restrictions
1097
1203
  select: /* @__PURE__ */ new Set(["select", "input", "textarea"]),
1098
1204
  option: /* @__PURE__ */ new Set(["option", "optgroup"])
@@ -1119,116 +1225,15 @@ function validateNesting(parentTag, childTag, path = "", options = {}) {
1119
1225
  return false;
1120
1226
  }
1121
1227
  var HTMLNestingError = class extends Error {
1122
- constructor(message, context2 = {}) {
1228
+ constructor(message, context = {}) {
1123
1229
  super(message);
1124
1230
  this.name = "HTMLNestingError";
1125
- this.parent = context2.parent;
1126
- this.child = context2.child;
1127
- this.path = context2.path;
1231
+ this.parent = context.parent;
1232
+ this.child = context.child;
1233
+ this.path = context.path;
1128
1234
  }
1129
1235
  };
1130
1236
 
1131
- // src/core/html-utils.js
1132
- function escapeHtml(text) {
1133
- if (typeof text !== "string") return text;
1134
- return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
1135
- }
1136
- function isVoidElement(tagName) {
1137
- if (typeof tagName !== "string") {
1138
- return false;
1139
- }
1140
- const voidElements = /* @__PURE__ */ new Set([
1141
- "area",
1142
- "base",
1143
- "br",
1144
- "col",
1145
- "embed",
1146
- "hr",
1147
- "img",
1148
- "input",
1149
- "link",
1150
- "meta",
1151
- "param",
1152
- "source",
1153
- "track",
1154
- "wbr"
1155
- ]);
1156
- return voidElements.has(tagName.toLowerCase());
1157
- }
1158
- function formatAttributes(props) {
1159
- let formatted = "";
1160
- for (const key in props) {
1161
- if (props.hasOwnProperty(key)) {
1162
- let value = props[key];
1163
- const attributeName = key === "className" ? "class" : key;
1164
- if (typeof value === "function") {
1165
- if (attributeName.startsWith("on")) {
1166
- const actionId = `__coherent_action_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
1167
- const DEBUG = typeof process !== "undefined" && process && process.env && (process.env.COHERENT_DEBUG === "1" || true) || typeof window !== "undefined" && window && window.COHERENT_DEBUG === true;
1168
- if (typeof global !== "undefined") {
1169
- if (!global.__coherentActionRegistry) {
1170
- global.__coherentActionRegistry = {};
1171
- if (DEBUG) console.log("Initialized global action registry");
1172
- }
1173
- global.__coherentActionRegistry[actionId] = value;
1174
- if (DEBUG) console.log(`Added action ${actionId} to global registry, total: ${Object.keys(global.__coherentActionRegistry).length}`);
1175
- if (DEBUG) console.log(`Global registry keys: ${Object.keys(global.__coherentActionRegistry).join(", ")}`);
1176
- if (DEBUG) {
1177
- if (typeof global.__coherentActionRegistryLog === "undefined") {
1178
- global.__coherentActionRegistryLog = [];
1179
- }
1180
- global.__coherentActionRegistryLog.push({
1181
- action: "add",
1182
- actionId,
1183
- timestamp: Date.now(),
1184
- registrySize: Object.keys(global.__coherentActionRegistry).length
1185
- });
1186
- }
1187
- } else if (typeof window !== "undefined") {
1188
- if (!window.__coherentActionRegistry) {
1189
- window.__coherentActionRegistry = {};
1190
- if (DEBUG) console.log("Initialized window action registry");
1191
- }
1192
- window.__coherentActionRegistry[actionId] = value;
1193
- if (DEBUG) console.log(`Added action ${actionId} to window registry, total: ${Object.keys(window.__coherentActionRegistry).length}`);
1194
- if (DEBUG) console.log(`Window registry keys: ${Object.keys(window.__coherentActionRegistry).join(", ")}`);
1195
- }
1196
- const eventType = attributeName.substring(2);
1197
- formatted += ` data-action="${actionId}" data-event="${eventType}"`;
1198
- continue;
1199
- } else {
1200
- try {
1201
- value = value();
1202
- } catch (_error) {
1203
- console.warn(`Error executing function for attribute '${key}':`, {
1204
- _error: _error.message,
1205
- stack: _error.stack,
1206
- attributeKey: key
1207
- });
1208
- value = "";
1209
- }
1210
- }
1211
- }
1212
- if (attributeName === "style" && typeof value === "object" && value !== null) {
1213
- const cssString = Object.entries(value).map(([prop, val]) => {
1214
- const kebabProp = prop.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`);
1215
- return `${kebabProp}: ${val}`;
1216
- }).join("; ");
1217
- formatted += ` ${attributeName}="${escapeHtml(cssString)}"`;
1218
- } else if (value === true) {
1219
- formatted += ` ${attributeName}`;
1220
- } else if (value !== false && value !== null && value !== void 0) {
1221
- formatted += ` ${attributeName}="${escapeHtml(String(value))}"`;
1222
- }
1223
- }
1224
- }
1225
- return formatted.trim();
1226
- }
1227
- function minifyHtml(html, options = {}) {
1228
- if (!options.minify) return html;
1229
- return html.replace(/<!--[\s\S]*?-->/g, "").replace(/\s+/g, " ").replace(/>\s+</g, "><").trim();
1230
- }
1231
-
1232
1237
  // src/performance/cache-manager.js
1233
1238
  function createCacheManager(options = {}) {
1234
1239
  const {
@@ -1272,10 +1277,10 @@ function createCacheManager(options = {}) {
1272
1277
  cleanupInterval.unref();
1273
1278
  }
1274
1279
  }
1275
- function generateCacheKey(component, props = {}, context2 = {}) {
1280
+ function generateCacheKey(component, props = {}, context = {}) {
1276
1281
  const componentStr = typeof component === "function" ? component.name || component.toString() : JSON.stringify(component);
1277
1282
  const propsStr = JSON.stringify(props, Object.keys(props).sort());
1278
- const contextStr = JSON.stringify(context2);
1283
+ const contextStr = JSON.stringify(context);
1279
1284
  const hash = simpleHash(componentStr + propsStr + contextStr);
1280
1285
  return `${extractComponentName(component)}_${hash}`;
1281
1286
  }
@@ -1506,11 +1511,11 @@ var ComponentValidationError = class extends CoherentError {
1506
1511
  }
1507
1512
  };
1508
1513
  var RenderingError = class extends CoherentError {
1509
- constructor(message, component, context2, suggestions = []) {
1514
+ constructor(message, component, context, suggestions = []) {
1510
1515
  super(message, {
1511
1516
  type: "rendering",
1512
1517
  component,
1513
- context: context2,
1518
+ context,
1514
1519
  suggestions: [
1515
1520
  "Check for circular references",
1516
1521
  "Validate component depth",
@@ -1519,8 +1524,8 @@ var RenderingError = class extends CoherentError {
1519
1524
  ]
1520
1525
  });
1521
1526
  this.name = "RenderingError";
1522
- if (context2 && context2.path) {
1523
- this.renderPath = context2.path;
1527
+ if (context && context.path) {
1528
+ this.renderPath = context.path;
1524
1529
  }
1525
1530
  }
1526
1531
  };
@@ -1575,8 +1580,8 @@ var ErrorHandler = class {
1575
1580
  /**
1576
1581
  * Handle and report errors with detailed context
1577
1582
  */
1578
- handle(_error, context2 = {}) {
1579
- const enhancedError = this.enhanceError(_error, context2);
1583
+ handle(_error, context = {}) {
1584
+ const enhancedError = this.enhanceError(_error, context);
1580
1585
  this.addToHistory(enhancedError);
1581
1586
  if (this.options.enableLogging) {
1582
1587
  this.logError(enhancedError);
@@ -1586,50 +1591,50 @@ var ErrorHandler = class {
1586
1591
  /**
1587
1592
  * Enhance existing errors with more context
1588
1593
  */
1589
- enhanceError(_error, context2 = {}) {
1594
+ enhanceError(_error, context = {}) {
1590
1595
  if (_error instanceof CoherentError) {
1591
1596
  return _error;
1592
1597
  }
1593
- const errorType = this.classifyError(_error, context2);
1598
+ const errorType = this.classifyError(_error, context);
1594
1599
  switch (errorType) {
1595
1600
  case "validation":
1596
1601
  return new ComponentValidationError(
1597
1602
  _error.message,
1598
- context2.component,
1599
- this.generateSuggestions(_error, context2)
1603
+ context.component,
1604
+ this.generateSuggestions(_error, context)
1600
1605
  );
1601
1606
  case "rendering":
1602
1607
  return new RenderingError(
1603
1608
  _error.message,
1604
- context2.component,
1605
- context2.renderContext,
1606
- this.generateSuggestions(_error, context2)
1609
+ context.component,
1610
+ context.renderContext,
1611
+ this.generateSuggestions(_error, context)
1607
1612
  );
1608
1613
  case "performance":
1609
1614
  return new PerformanceError(
1610
1615
  _error.message,
1611
- context2.metrics,
1612
- this.generateSuggestions(_error, context2)
1616
+ context.metrics,
1617
+ this.generateSuggestions(_error, context)
1613
1618
  );
1614
1619
  case "state":
1615
1620
  return new StateError(
1616
1621
  _error.message,
1617
- context2.state,
1618
- this.generateSuggestions(_error, context2)
1622
+ context.state,
1623
+ this.generateSuggestions(_error, context)
1619
1624
  );
1620
1625
  default:
1621
1626
  return new CoherentError(_error.message, {
1622
1627
  type: errorType,
1623
- component: context2.component,
1624
- context: context2.context,
1625
- suggestions: this.generateSuggestions(_error, context2)
1628
+ component: context.component,
1629
+ context: context.context,
1630
+ suggestions: this.generateSuggestions(_error, context)
1626
1631
  });
1627
1632
  }
1628
1633
  }
1629
1634
  /**
1630
1635
  * Classify _error type based on message and context
1631
1636
  */
1632
- classifyError(_error, context2) {
1637
+ classifyError(_error, context) {
1633
1638
  const message = _error.message.toLowerCase();
1634
1639
  if (message.includes("invalid") || message.includes("validation") || message.includes("required") || message.includes("type")) {
1635
1640
  return "validation";
@@ -1640,18 +1645,18 @@ var ErrorHandler = class {
1640
1645
  if (message.includes("slow") || message.includes("memory") || message.includes("performance") || message.includes("timeout")) {
1641
1646
  return "performance";
1642
1647
  }
1643
- if (message.includes("state") || message.includes("mutation") || message.includes("store") || context2.state) {
1648
+ if (message.includes("state") || message.includes("mutation") || message.includes("store") || context.state) {
1644
1649
  return "state";
1645
1650
  }
1646
- if (context2.component) return "validation";
1647
- if (context2.renderContext) return "rendering";
1648
- if (context2.metrics) return "performance";
1651
+ if (context.component) return "validation";
1652
+ if (context.renderContext) return "rendering";
1653
+ if (context.metrics) return "performance";
1649
1654
  return "generic";
1650
1655
  }
1651
1656
  /**
1652
1657
  * Generate helpful suggestions based on _error
1653
1658
  */
1654
- generateSuggestions(_error, context2 = {}) {
1659
+ generateSuggestions(_error, context = {}) {
1655
1660
  const suggestions = [];
1656
1661
  const message = _error.message.toLowerCase();
1657
1662
  const patterns = [
@@ -1702,13 +1707,13 @@ var ErrorHandler = class {
1702
1707
  suggestions.push(...patternSuggestions);
1703
1708
  }
1704
1709
  });
1705
- if (context2.component) {
1706
- const componentType = typeof context2.component;
1710
+ if (context.component) {
1711
+ const componentType = typeof context.component;
1707
1712
  if (componentType === "function") {
1708
1713
  suggestions.push("Check function component return value");
1709
- } else if (componentType === "object" && context2.component === null) {
1714
+ } else if (componentType === "object" && context.component === null) {
1710
1715
  suggestions.push("Component is null - ensure proper initialization");
1711
- } else if (Array.isArray(context2.component)) {
1716
+ } else if (Array.isArray(context.component)) {
1712
1717
  suggestions.push("Arrays should contain valid component objects");
1713
1718
  }
1714
1719
  }
@@ -1949,6 +1954,9 @@ var HTMLRenderer = class extends BaseRenderer {
1949
1954
  if (Array.isArray(component) && component.length === 0) {
1950
1955
  return "";
1951
1956
  }
1957
+ if (isTrustedContent(component)) {
1958
+ return component.__html;
1959
+ }
1952
1960
  if (typeof component === "object" && component !== null && !Array.isArray(component)) {
1953
1961
  if (options.seenObjects && options.seenObjects.has(component)) {
1954
1962
  throw new RenderingError(
@@ -2112,10 +2120,14 @@ var HTMLRenderer = class extends BaseRenderer {
2112
2120
  return openingTag;
2113
2121
  }
2114
2122
  if (_rawHtml !== void 0) {
2115
- const rawContent = typeof _rawHtml === "function" ? String(_rawHtml()) : String(_rawHtml);
2123
+ const resolvedHtml = typeof _rawHtml === "function" ? _rawHtml() : _rawHtml;
2124
+ const rawContent = isTrustedContent(resolvedHtml) ? resolvedHtml.__html : String(resolvedHtml);
2116
2125
  const result = `${openingTag}${rawContent}</${tagName}>`;
2117
2126
  return result;
2118
2127
  }
2128
+ if (isTrustedContent(text)) {
2129
+ return `${openingTag}${text.__html}</${tagName}>`;
2130
+ }
2119
2131
  let textContent = "";
2120
2132
  if (text !== void 0) {
2121
2133
  const isScript = tagName === "script";
@@ -2225,6 +2237,7 @@ var Component = class _Component {
2225
2237
  this.rendered = null;
2226
2238
  this.isMounted = false;
2227
2239
  this.isDestroyed = false;
2240
+ this.isHandlingError = false;
2228
2241
  this.hooks = {
2229
2242
  beforeCreate: definition.beforeCreate || (() => {
2230
2243
  }),
@@ -2327,12 +2340,26 @@ var Component = class _Component {
2327
2340
  }
2328
2341
  /**
2329
2342
  * Handle component errors
2343
+ *
2344
+ * @param {Error} _error - The error to handle
2345
+ * @param {string} [context] - Where the error came from, accumulated as it
2346
+ * propagates up so the parent sees the full "Child -> render" trail
2330
2347
  */
2331
- handleError(_error) {
2332
- console.error(`Component Error in ${this.name}:`, _error);
2333
- this.callHook("errorCaptured", _error);
2334
- if (this.parent && this.parent.handleError) {
2335
- this.parent.handleError(_error, `${this.name} -> ${context}`);
2348
+ handleError(_error, context = "") {
2349
+ if (this.isHandlingError) {
2350
+ console.error(`Component Error in ${this.name} (errorCaptured hook):`, _error);
2351
+ return;
2352
+ }
2353
+ this.isHandlingError = true;
2354
+ try {
2355
+ const origin = context ? `${this.name} (${context})` : this.name;
2356
+ console.error(`Component Error in ${origin}:`, _error);
2357
+ this.callHook("errorCaptured", _error);
2358
+ if (this.parent && this.parent.handleError) {
2359
+ this.parent.handleError(_error, context ? `${this.name} -> ${context}` : this.name);
2360
+ }
2361
+ } finally {
2362
+ this.isHandlingError = false;
2336
2363
  }
2337
2364
  }
2338
2365
  /**
@@ -2463,7 +2490,40 @@ function createComponent(definition) {
2463
2490
  render: definition
2464
2491
  };
2465
2492
  }
2466
- return new Component(definition);
2493
+ const instance = new Component(definition);
2494
+ const callable = (props = {}) => instance.render(props);
2495
+ const CHAINABLE = /* @__PURE__ */ new Set(["mount", "update", "destroy"]);
2496
+ return new Proxy(callable, {
2497
+ get(target, key, receiver) {
2498
+ if (key === "clone") {
2499
+ return (overrides = {}) => createComponent({ ...instance.definition, ...overrides });
2500
+ }
2501
+ const value = Reflect.get(instance, key, instance);
2502
+ if (typeof value === "function") {
2503
+ return CHAINABLE.has(key) ? (...args) => {
2504
+ value.apply(instance, args);
2505
+ return receiver;
2506
+ } : value.bind(instance);
2507
+ }
2508
+ return value !== void 0 || Reflect.has(instance, key) ? value : Reflect.get(target, key, receiver);
2509
+ },
2510
+ set(target, key, value) {
2511
+ return Reflect.set(instance, key, value, instance);
2512
+ },
2513
+ has(target, key) {
2514
+ return Reflect.has(instance, key) || Reflect.has(target, key);
2515
+ },
2516
+ deleteProperty(target, key) {
2517
+ return Reflect.deleteProperty(instance, key);
2518
+ },
2519
+ ownKeys() {
2520
+ return Reflect.ownKeys(instance);
2521
+ },
2522
+ getOwnPropertyDescriptor(target, key) {
2523
+ const descriptor = Reflect.getOwnPropertyDescriptor(instance, key);
2524
+ return descriptor ? { ...descriptor, configurable: true } : Reflect.getOwnPropertyDescriptor(target, key);
2525
+ }
2526
+ });
2467
2527
  }
2468
2528
  function defineComponent(definition) {
2469
2529
  const componentFactory = (props) => {
@@ -2488,6 +2548,16 @@ function getComponent(name) {
2488
2548
  function getRegisteredComponents() {
2489
2549
  return new Map(COMPONENT_REGISTRY);
2490
2550
  }
2551
+ function createHOC(enhancer) {
2552
+ return (WrappedComponent) => {
2553
+ return defineComponent({
2554
+ name: `HOC(${WrappedComponent.componentName || "Component"})`,
2555
+ render(props) {
2556
+ return enhancer(WrappedComponent, props);
2557
+ }
2558
+ });
2559
+ };
2560
+ }
2491
2561
  if (performanceMonitor) {
2492
2562
  const originalRender = Component.prototype.render;
2493
2563
  Component.prototype.render = function(...args) {
@@ -2764,6 +2834,24 @@ function memo(fn, options = {}) {
2764
2834
  };
2765
2835
  return memoizedFn;
2766
2836
  }
2837
+ function memoComponent(component, options = {}) {
2838
+ const {
2839
+ propsEqual = shallowEqual,
2840
+ stateEqual = shallowEqual,
2841
+ name = component.name || "AnonymousComponent"
2842
+ } = options;
2843
+ return memo((props = {}, state = {}, context = {}) => {
2844
+ return typeof component === "function" ? component(props, state, context) : component;
2845
+ }, {
2846
+ keyFn: (props, state) => {
2847
+ return `${name}:${JSON.stringify(props)}:${JSON.stringify(state)}`;
2848
+ },
2849
+ compareFn: (a, b) => {
2850
+ return propsEqual(a.props, b.props) && stateEqual(a.state, b.state);
2851
+ },
2852
+ ...options
2853
+ });
2854
+ }
2767
2855
  var LRUCache = class {
2768
2856
  constructor(maxSize = 100, options = {}) {
2769
2857
  this.maxSize = maxSize;
@@ -2865,6 +2953,22 @@ var TTLCache = class {
2865
2953
  return this.cache.size;
2866
2954
  }
2867
2955
  };
2956
+ function shallowEqual(a, b) {
2957
+ if (a === b) return true;
2958
+ if (!a || !b) return false;
2959
+ if (typeof a !== typeof b) return false;
2960
+ if (Array.isArray(a) && Array.isArray(b)) {
2961
+ if (a.length !== b.length) return false;
2962
+ return a.every((item, index) => item === b[index]);
2963
+ }
2964
+ if (typeof a === "object") {
2965
+ const keysA = Object.keys(a);
2966
+ const keysB = Object.keys(b);
2967
+ if (keysA.length !== keysB.length) return false;
2968
+ return keysA.every((key) => a[key] === b[key]);
2969
+ }
2970
+ return false;
2971
+ }
2868
2972
  function withState(initialState = {}, options = {}) {
2869
2973
  const {
2870
2974
  // State options
@@ -2942,21 +3046,21 @@ function withState(initialState = {}, options = {}) {
2942
3046
  onStateChange,
2943
3047
  debug
2944
3048
  });
2945
- function WithStateComponent(props = {}, globalState = {}, context2 = {}) {
3049
+ function WithStateComponent(props = {}, globalState = {}, context = {}) {
2946
3050
  if (!stateContainer.initialized) {
2947
3051
  stateContainer.initialize();
2948
3052
  if (onMount) {
2949
- onMount(stateContainer.getState(), props, context2);
3053
+ onMount(stateContainer.getState(), props, context);
2950
3054
  }
2951
3055
  }
2952
3056
  const currentState = stateContainer.getState();
2953
3057
  let transformedState = currentState;
2954
3058
  if (stateTransform) {
2955
- transformedState = stateTransform(currentState, props, context2);
3059
+ transformedState = stateTransform(currentState, props, context);
2956
3060
  }
2957
3061
  const boundActions = createBoundActions(actions, stateContainer, {
2958
3062
  props,
2959
- context: context2,
3063
+ context,
2960
3064
  supportAsync,
2961
3065
  debug
2962
3066
  });
@@ -3018,7 +3122,7 @@ function withState(initialState = {}, options = {}) {
3018
3122
  props: enhancedProps
3019
3123
  });
3020
3124
  }
3021
- return typeof WrappedComponent === "function" ? WrappedComponent(enhancedProps, globalState, context2) : WrappedComponent;
3125
+ return typeof WrappedComponent === "function" ? WrappedComponent(enhancedProps, globalState, context) : WrappedComponent;
3022
3126
  }
3023
3127
  WithStateComponent.displayName = displayName || `withState(${getComponentName(WrappedComponent)})`;
3024
3128
  WithStateComponent.__isHOC = true;
@@ -3137,7 +3241,7 @@ function createStateContainer(initialState, options) {
3137
3241
  return container;
3138
3242
  }
3139
3243
  function createBoundActions(actions, stateContainer, options) {
3140
- const { props, context: context2, supportAsync, debug } = options;
3244
+ const { props, context, supportAsync, debug } = options;
3141
3245
  const boundActions = {};
3142
3246
  Object.entries(actions).forEach(([actionName, actionCreator]) => {
3143
3247
  boundActions[actionName] = (...args) => {
@@ -3145,7 +3249,7 @@ function createBoundActions(actions, stateContainer, options) {
3145
3249
  const result = actionCreator(
3146
3250
  stateContainer.getState(),
3147
3251
  stateContainer.setState.bind(stateContainer),
3148
- { props, context: context2, args }
3252
+ { props, context, args }
3149
3253
  );
3150
3254
  if (supportAsync && result && typeof result.then === "function") {
3151
3255
  return result.catch((_error) => {
@@ -3205,7 +3309,7 @@ var withStateUtils = {
3205
3309
  }
3206
3310
  return (WrappedComponent) => {
3207
3311
  const sharedContainer = sharedStates.get(sharedKey);
3208
- function SharedStateComponent(props, globalState, context2) {
3312
+ function SharedStateComponent(props, globalState, context) {
3209
3313
  const currentState = sharedContainer.getState();
3210
3314
  const enhancedProps = {
3211
3315
  ...props,
@@ -3213,7 +3317,7 @@ var withStateUtils = {
3213
3317
  setState: sharedContainer.setState.bind(sharedContainer),
3214
3318
  subscribe: sharedContainer.subscribe.bind(sharedContainer)
3215
3319
  };
3216
- return typeof WrappedComponent === "function" ? WrappedComponent(enhancedProps, globalState, context2) : WrappedComponent;
3320
+ return typeof WrappedComponent === "function" ? WrappedComponent(enhancedProps, globalState, context) : WrappedComponent;
3217
3321
  }
3218
3322
  SharedStateComponent.displayName = `withSharedState(${getComponentName(WrappedComponent)})`;
3219
3323
  return SharedStateComponent;
@@ -4039,7 +4143,7 @@ var ComponentCache = class {
4039
4143
  /**
4040
4144
  * Generate cache key from component and props
4041
4145
  */
4042
- generateKey(component, props = {}, context2 = {}) {
4146
+ generateKey(component, props = {}, context = {}) {
4043
4147
  if (typeof component === "string") {
4044
4148
  return `str:${component}`;
4045
4149
  }
@@ -4049,7 +4153,7 @@ var ComponentCache = class {
4049
4153
  if (typeof component === "object" && component !== null) {
4050
4154
  const serialized = this.serializeComponent(component);
4051
4155
  const propsHash = Object.keys(props).length > 0 ? `:${JSON.stringify(props)}` : "";
4052
- const contextHash = Object.keys(context2).length > 0 ? `:${JSON.stringify(context2)}` : "";
4156
+ const contextHash = Object.keys(context).length > 0 ? `:${JSON.stringify(context)}` : "";
4053
4157
  return `obj:${serialized}${propsHash}${contextHash}`;
4054
4158
  }
4055
4159
  return `primitive:${String(component)}`;
@@ -4439,7 +4543,7 @@ function createErrorFallback(options = {}) {
4439
4543
  className = "error-boundary-fallback",
4440
4544
  style = {}
4441
4545
  } = options;
4442
- return function errorFallback(error, errorInfo, context2 = {}) {
4546
+ return function errorFallback(error, errorInfo, context = {}) {
4443
4547
  const children = [
4444
4548
  {
4445
4549
  h2: {
@@ -4464,20 +4568,20 @@ function createErrorFallback(options = {}) {
4464
4568
  }
4465
4569
  });
4466
4570
  }
4467
- if (showReset && context2.reset && !context2.permanent) {
4571
+ if (showReset && context.reset && !context.permanent) {
4468
4572
  children.push({
4469
4573
  button: {
4470
4574
  className: "error-reset-button",
4471
4575
  text: "Try Again",
4472
- onclick: context2.reset
4576
+ onclick: context.reset
4473
4577
  }
4474
4578
  });
4475
4579
  }
4476
- if (context2.errorCount > 1) {
4580
+ if (context.errorCount > 1) {
4477
4581
  children.push({
4478
4582
  p: {
4479
4583
  className: "error-count",
4480
- text: `Error occurred ${context2.errorCount} times`
4584
+ text: `Error occurred ${context.errorCount} times`
4481
4585
  }
4482
4586
  });
4483
4587
  }
@@ -4543,11 +4647,11 @@ var GlobalErrorHandler = class {
4543
4647
  /**
4544
4648
  * Capture an error
4545
4649
  */
4546
- captureError(error, context2 = {}) {
4650
+ captureError(error, context = {}) {
4547
4651
  if (!this.enabled) return;
4548
4652
  const errorEntry = {
4549
4653
  error,
4550
- context: context2,
4654
+ context,
4551
4655
  timestamp: Date.now(),
4552
4656
  stack: error.stack
4553
4657
  };
@@ -4557,7 +4661,7 @@ var GlobalErrorHandler = class {
4557
4661
  }
4558
4662
  if (this.onError) {
4559
4663
  try {
4560
- this.onError(error, context2);
4664
+ this.onError(error, context);
4561
4665
  } catch (callbackError) {
4562
4666
  console.error("Error in global error handler callback:", callbackError);
4563
4667
  }
@@ -4640,11 +4744,11 @@ function isCoherentComponent(obj) {
4640
4744
  const keys = Object.keys(obj);
4641
4745
  return keys.length === 1;
4642
4746
  }
4643
- function createErrorResponse(error, context2 = "rendering") {
4747
+ function createErrorResponse(error, context = "rendering") {
4644
4748
  return {
4645
4749
  error: "Internal Server Error",
4646
4750
  message: error.message,
4647
- context: context2,
4751
+ context,
4648
4752
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
4649
4753
  };
4650
4754
  }
@@ -5769,13 +5873,13 @@ function withEventBus(options = {}) {
5769
5873
  autoCleanup = true
5770
5874
  } = options;
5771
5875
  return function withEventBusHOC(WrappedComponent) {
5772
- function EventBusComponent(props = {}, state = {}, context2 = {}) {
5876
+ function EventBusComponent(props = {}, state = {}, context = {}) {
5773
5877
  const bus = scope ? eventBus.createScope(scope) : eventBus;
5774
5878
  const listenerIds = /* @__PURE__ */ new Map();
5775
5879
  Object.entries(events).forEach(([event, handler]) => {
5776
5880
  const listenerId = bus.on(event, (data, eventName) => {
5777
5881
  if (typeof handler === "function") {
5778
- handler.call(this, data, eventName, { props, state, context: context2 });
5882
+ handler.call(this, data, eventName, { props, state, context });
5779
5883
  }
5780
5884
  });
5781
5885
  listenerIds.set(event, listenerId);
@@ -5783,7 +5887,7 @@ function withEventBus(options = {}) {
5783
5887
  Object.entries(actions).forEach(([action, handler]) => {
5784
5888
  bus.registerAction(action, (actionContext) => {
5785
5889
  if (typeof handler === "function") {
5786
- handler.call(this, actionContext, { props, state, context: context2 });
5890
+ handler.call(this, actionContext, { props, state, context });
5787
5891
  }
5788
5892
  });
5789
5893
  });
@@ -5815,7 +5919,7 @@ function withEventBus(options = {}) {
5815
5919
  registeredActions: Object.keys(actions)
5816
5920
  });
5817
5921
  }
5818
- const result = typeof WrappedComponent === "function" ? WrappedComponent(enhancedProps, state, context2) : WrappedComponent;
5922
+ const result = typeof WrappedComponent === "function" ? WrappedComponent(enhancedProps, state, context) : WrappedComponent;
5819
5923
  if (autoCleanup && result && typeof result === "object") {
5820
5924
  if (result.componentWillUnmount) {
5821
5925
  const originalUnmount = result.componentWillUnmount;
@@ -5856,10 +5960,10 @@ function withEventState(initialState = {}, options = {}) {
5856
5960
  ...events,
5857
5961
  // Add state-aware event handlers
5858
5962
  ...Object.entries(events).reduce((acc, [event, handler]) => {
5859
- acc[event] = function(data, eventName, context2) {
5963
+ acc[event] = function(data, eventName, context) {
5860
5964
  return handler.call(this, data, eventName, {
5861
- ...context2,
5862
- stateUtils: context2.props.stateUtils
5965
+ ...context,
5966
+ stateUtils: context.props.stateUtils
5863
5967
  });
5864
5968
  };
5865
5969
  return acc;
@@ -6298,10 +6402,6 @@ function applyScopeToElement(element, scopeId) {
6298
6402
  }
6299
6403
  return element;
6300
6404
  }
6301
- function escapeHtml2(text) {
6302
- if (typeof text !== "string") return text;
6303
- return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#x27;");
6304
- }
6305
6405
  function dangerouslySetInnerContent(content) {
6306
6406
  return {
6307
6407
  __html: content,
@@ -6417,7 +6517,7 @@ function deepClone2(obj) {
6417
6517
  }
6418
6518
  return cloned;
6419
6519
  }
6420
- var VERSION = true ? "1.0.0-rc.6" : JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).version;
6520
+ var VERSION = true ? "1.0.0" : JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).version;
6421
6521
  var fp = {
6422
6522
  /**
6423
6523
  * Curried map: fp.map(fn)(array)
@@ -6482,12 +6582,13 @@ var coherent = {
6482
6582
  validateComponent: validateComponent2,
6483
6583
  isCoherentObject: isCoherentObject2,
6484
6584
  deepClone: deepClone2,
6485
- escapeHtml: escapeHtml2,
6585
+ escapeHtml,
6486
6586
  performanceMonitor,
6487
6587
  VERSION
6488
6588
  };
6489
6589
  var index_default = coherent;
6490
6590
  export {
6591
+ Component,
6491
6592
  ComponentCache,
6492
6593
  ComponentLifecycle,
6493
6594
  DOMEventIntegration,
@@ -6498,10 +6599,12 @@ export {
6498
6599
  Island,
6499
6600
  LIFECYCLE_PHASES,
6500
6601
  VERSION,
6602
+ cacheManager,
6501
6603
  checkPeerDependencies,
6502
6604
  compose,
6503
6605
  createActionHandlers,
6504
6606
  createAsyncErrorBoundary,
6607
+ createCacheManager,
6505
6608
  createComponent,
6506
6609
  createComponentCache,
6507
6610
  createElement,
@@ -6512,6 +6615,7 @@ export {
6512
6615
  createEventComponent,
6513
6616
  createEventHandlers,
6514
6617
  createGlobalErrorHandler,
6618
+ createHOC,
6515
6619
  createLazyIntegration,
6516
6620
  createLifecycleHooks,
6517
6621
  createStateManager,
@@ -6522,8 +6626,10 @@ export {
6522
6626
  defineComponent,
6523
6627
  emit,
6524
6628
  emitSync,
6629
+ escapeHtml,
6525
6630
  evaluateLazy,
6526
6631
  events_default as eventSystem,
6632
+ formatAttributes,
6527
6633
  fp,
6528
6634
  getComponent,
6529
6635
  getRegisteredComponents,
@@ -6539,9 +6645,12 @@ export {
6539
6645
  isCoherentObject2 as isCoherentObject,
6540
6646
  isLazy,
6541
6647
  isPeerDependencyAvailable,
6648
+ isTrustedContent,
6649
+ isVoidElement,
6542
6650
  lazy,
6543
6651
  componentUtils as lifecycleUtils,
6544
6652
  memo2 as memo,
6653
+ memoComponent,
6545
6654
  memoize,
6546
6655
  normalizeChildren,
6547
6656
  off,