@estjs/template 0.0.16-beta.9 → 0.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { getActiveScope, runWithScope, onCleanup, __objRest, createScope, disposeScope, __spreadValues, __async } from './chunk-W5LMSADN.dev.js';
1
+ import { getActiveScope, runWithScope, onCleanup, __objRest, createScope, disposeScope, __async } from './chunk-R6JICOKI.dev.js';
2
2
  import { normalizeClassName, SPREAD_NAME, isObject, warn, startsWith, isSpecialBooleanAttr, isBooleanAttr, includeBooleanAttr, isSymbol, isString, isArray, kebabCase, camelCase, capitalize, HYDRATION_ANCHOR_ATTR, isBrowser, error, isPromise, isFunction, isOn, coerceArray } from '@estjs/shared';
3
3
  import { effect, shallowReactive, isSignal, isComputed, isReactive, signal } from '@estjs/signals';
4
4
 
@@ -1009,6 +1009,91 @@ function createComponent(componentFn, props) {
1009
1009
  }
1010
1010
  return new Component(componentFn, props);
1011
1011
  }
1012
+
1013
+ // src/renderer.ts
1014
+ function template(html) {
1015
+ let node;
1016
+ const create = () => {
1017
+ const template2 = document.createElement("template");
1018
+ template2.innerHTML = html;
1019
+ const firstChild = template2.content.firstChild;
1020
+ if (!firstChild) {
1021
+ throw new Error("Invalid template: empty content");
1022
+ }
1023
+ return firstChild;
1024
+ };
1025
+ return () => (node || (node = create())).cloneNode(true);
1026
+ }
1027
+ function createApp(component, target) {
1028
+ const container = isString(target) ? document.querySelector(target) : target;
1029
+ if (!container) {
1030
+ {
1031
+ warn(`Target element not found: ${target}`);
1032
+ }
1033
+ return;
1034
+ }
1035
+ const existingContent = container.innerHTML;
1036
+ if (existingContent) {
1037
+ {
1038
+ warn(`Target element is not empty, it will be cleared: ${target}`);
1039
+ }
1040
+ container.innerHTML = "";
1041
+ }
1042
+ const scope = createScope();
1043
+ let rootNode;
1044
+ try {
1045
+ runWithScope(scope, () => {
1046
+ const mountedRoot = createComponent(component);
1047
+ if (isComponent(mountedRoot)) {
1048
+ rootNode = mountedRoot;
1049
+ insertNode(container, mountedRoot);
1050
+ }
1051
+ });
1052
+ } catch (error_) {
1053
+ disposeScope(scope);
1054
+ throw error_;
1055
+ }
1056
+ return {
1057
+ root: rootNode,
1058
+ unmount: () => {
1059
+ disposeScope(scope);
1060
+ rootNode == null ? void 0 : rootNode.destroy();
1061
+ }
1062
+ };
1063
+ }
1064
+ function hydrate(component, target) {
1065
+ const container = isString(target) ? document.querySelector(target) : target;
1066
+ if (!container) {
1067
+ {
1068
+ warn(`[essor] hydrate: target element not found: ${target}`);
1069
+ }
1070
+ return;
1071
+ }
1072
+ beginHydration(container);
1073
+ const scope = createScope();
1074
+ let rootNode;
1075
+ try {
1076
+ runWithScope(scope, () => {
1077
+ const mountedRoot = createComponent(component);
1078
+ if (isComponent(mountedRoot)) {
1079
+ rootNode = mountedRoot;
1080
+ insert(container, mountedRoot);
1081
+ }
1082
+ });
1083
+ } catch (error_) {
1084
+ disposeScope(scope);
1085
+ throw error_;
1086
+ } finally {
1087
+ endHydration();
1088
+ }
1089
+ return {
1090
+ root: rootNode,
1091
+ unmount: () => {
1092
+ disposeScope(scope);
1093
+ rootNode == null ? void 0 : rootNode.destroy();
1094
+ }
1095
+ };
1096
+ }
1012
1097
  function provide(key, value) {
1013
1098
  const scope = getActiveScope();
1014
1099
  if (!scope) {
@@ -1041,186 +1126,6 @@ function inject(key, defaultValue) {
1041
1126
  }
1042
1127
  return defaultValue;
1043
1128
  }
1044
-
1045
- // src/renderer.ts
1046
- var VERSION = typeof __VERSION__ === "string" ? __VERSION__ : "";
1047
- var ENFORCE_ORDER = { pre: 0, default: 1, post: 2 };
1048
- function template(html) {
1049
- let node;
1050
- const create = () => {
1051
- const template2 = document.createElement("template");
1052
- template2.innerHTML = html;
1053
- const firstChild = template2.content.firstChild;
1054
- if (!firstChild) {
1055
- throw new Error("Invalid template: empty content");
1056
- }
1057
- return firstChild;
1058
- };
1059
- return () => (node || (node = create())).cloneNode(true);
1060
- }
1061
- function createApp(component, arg) {
1062
- if (isString(arg) || arg instanceof Element) {
1063
- return buildApp(component).mount(arg);
1064
- }
1065
- return buildApp(component, arg);
1066
- }
1067
- function hydrate(component, target) {
1068
- return buildApp(component).hydrate(target);
1069
- }
1070
- function definePlugin(plugin) {
1071
- return plugin;
1072
- }
1073
- function buildApp(component, options) {
1074
- var _a2, _b;
1075
- const plugins = (_a2 = options == null ? void 0 : options.plugins) != null ? _a2 : [];
1076
- const config = __spreadValues({}, (_b = options == null ? void 0 : options.config) != null ? _b : {});
1077
- let mounted = false;
1078
- function mount(target, isHydrate) {
1079
- if (mounted) {
1080
- warn("App is already mounted");
1081
- return;
1082
- }
1083
- mounted = true;
1084
- const container = isString(target) ? document.querySelector(target) : target;
1085
- if (!container) {
1086
- {
1087
- warn(`[essor] ${isHydrate ? "hydrate" : "createApp"}: target element not found: ${target}`);
1088
- }
1089
- return;
1090
- }
1091
- if (!isHydrate && container.innerHTML) {
1092
- warn(`Target element is not empty, it will be cleared: ${target}`);
1093
- container.innerHTML = "";
1094
- }
1095
- const scope = createScope();
1096
- const mountHooks = [];
1097
- const seenNames = /* @__PURE__ */ new Set();
1098
- const seenRefs = /* @__PURE__ */ new Set();
1099
- let activePluginName;
1100
- let root;
1101
- function reportError(error4, info) {
1102
- if (config.errorHandler) config.errorHandler(info, error4);
1103
- else throw error4;
1104
- }
1105
- const ordered = plugins.map((entry, index) => ({ entry, index })).sort((a, b) => {
1106
- var _a3, _b2;
1107
- const pa = ENFORCE_ORDER[(_a3 = normalizePlugin(a.entry).enforce) != null ? _a3 : "default"];
1108
- const pb = ENFORCE_ORDER[(_b2 = normalizePlugin(b.entry).enforce) != null ? _b2 : "default"];
1109
- return pa - pb || a.index - b.index;
1110
- }).map((x) => x.entry);
1111
- function runSetup(plugin, opts) {
1112
- if (seenRefs.has(plugin) || seenNames.has(plugin.name)) {
1113
- warn(`Plugin "${plugin.name}" is already registered, skipping`);
1114
- return;
1115
- }
1116
- seenRefs.add(plugin);
1117
- seenNames.add(plugin.name);
1118
- activePluginName = plugin.name;
1119
- try {
1120
- const result = plugin.setup(ctx, opts);
1121
- if (result instanceof Promise) {
1122
- const pinned = plugin.name;
1123
- return result.catch((error4) => reportError(error4, { phase: "install", plugin: pinned })).finally(() => {
1124
- if (activePluginName === pinned) activePluginName = void 0;
1125
- });
1126
- }
1127
- activePluginName = void 0;
1128
- return result;
1129
- } catch (error4) {
1130
- activePluginName = void 0;
1131
- reportError(error4, { phase: "install", plugin: plugin.name });
1132
- }
1133
- }
1134
- const ctx = {
1135
- provide,
1136
- inject,
1137
- onMount: (fn) => void mountHooks.push(fn),
1138
- onCleanup,
1139
- warn(message) {
1140
- const info = { plugin: activePluginName };
1141
- if (config.warnHandler) config.warnHandler(info, message);
1142
- else warn(message);
1143
- },
1144
- error(message) {
1145
- throw new Error(message);
1146
- },
1147
- config,
1148
- version: VERSION
1149
- };
1150
- function finishMount() {
1151
- if (isHydrate) beginHydration(container);
1152
- try {
1153
- const node = createComponent(component);
1154
- if (isComponent(node)) {
1155
- root = node;
1156
- (isHydrate ? insert : insertNode)(container, node);
1157
- }
1158
- } finally {
1159
- if (isHydrate) endHydration();
1160
- }
1161
- for (const fn of mountHooks) {
1162
- try {
1163
- fn();
1164
- } catch (error4) {
1165
- reportError(error4, { phase: "mount" });
1166
- }
1167
- }
1168
- return {
1169
- root,
1170
- unmount() {
1171
- disposeScope(scope);
1172
- root == null ? void 0 : root.destroy();
1173
- }
1174
- };
1175
- }
1176
- let asyncTail;
1177
- try {
1178
- runWithScope(scope, () => {
1179
- for (const entry of ordered) {
1180
- const [plugin, opts] = unpack(entry);
1181
- if (asyncTail) {
1182
- asyncTail = asyncTail.then(
1183
- () => runWithScope(scope, () => {
1184
- const r = runSetup(plugin, opts);
1185
- return r instanceof Promise ? r : void 0;
1186
- })
1187
- );
1188
- continue;
1189
- }
1190
- const result = runSetup(plugin, opts);
1191
- if (result instanceof Promise) asyncTail = result;
1192
- }
1193
- });
1194
- } catch (error4) {
1195
- disposeScope(scope);
1196
- throw error4;
1197
- }
1198
- if (asyncTail) {
1199
- return asyncTail.then(() => runWithScope(scope, finishMount)).catch((error4) => {
1200
- disposeScope(scope);
1201
- throw error4;
1202
- });
1203
- }
1204
- try {
1205
- return runWithScope(scope, finishMount);
1206
- } catch (error4) {
1207
- disposeScope(scope);
1208
- throw error4;
1209
- }
1210
- }
1211
- const app = {
1212
- config,
1213
- mount: (target) => mount(target, false),
1214
- hydrate: (target) => mount(target, true)
1215
- };
1216
- return app;
1217
- }
1218
- function normalizePlugin(entry) {
1219
- return Array.isArray(entry) ? entry[0] : entry;
1220
- }
1221
- function unpack(entry) {
1222
- return Array.isArray(entry) ? [entry[0], entry[1]] : [entry, void 0];
1223
- }
1224
1129
  function reTargetEvent(e, value) {
1225
1130
  Object.defineProperty(e, "target", {
1226
1131
  configurable: true,
@@ -2869,6 +2774,6 @@ function isTransitionGroup(node) {
2869
2774
  return !!node && !!node[TRANSITION_GROUP_COMPONENT];
2870
2775
  }
2871
2776
 
2872
- export { Component, For, Fragment, Portal, Suspense, Transition, TransitionGroup, addEvent, addEventListener, beginHydration, bindElement, child, clearDelegatedEvents, consumeTeleportAnchor, consumeTeleportBlock, createApp, createComponent, createResource, defineAsyncComponent, definePlugin, delegateEvents, endHydration, getHydrationKey, getRenderedElement, hydrate, hydrationAnchor, hydrationMarker, inject, insert, isComponent, isFragment, isHydrating, isPortal, isSuspense, isTransition, isTransitionGroup, next, normalizeClass, nthChild, omitProps, onDestroy, onMount, onUpdate, patchAttr, patchAttrHydrate, patchClass, patchClassHydrate, patchStyle, patchStyleHydrate, provide, resetHydrationKey, setStyle, template };
2777
+ export { Component, For, Fragment, Portal, Suspense, Transition, TransitionGroup, addEvent, addEventListener, beginHydration, bindElement, child, clearDelegatedEvents, consumeTeleportAnchor, consumeTeleportBlock, createApp, createComponent, createResource, defineAsyncComponent, delegateEvents, endHydration, getHydrationKey, getRenderedElement, hydrate, hydrationAnchor, hydrationMarker, inject, insert, isComponent, isFragment, isHydrating, isPortal, isSuspense, isTransition, isTransitionGroup, next, normalizeClass, nthChild, omitProps, onDestroy, onMount, onUpdate, patchAttr, patchAttrHydrate, patchClass, patchClassHydrate, patchStyle, patchStyleHydrate, provide, resetHydrationKey, setStyle, template };
2873
2778
  //# sourceMappingURL=template.dev.js.map
2874
2779
  //# sourceMappingURL=template.dev.js.map