@getforma/core 1.0.4 → 1.0.5

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.d.cts CHANGED
@@ -653,6 +653,30 @@ declare function createErrorBoundary(tryFn: () => Node, catchFn: (error: Error,
653
653
  */
654
654
  declare function createSuspense(fallback: () => Node, children: () => Node): DocumentFragment;
655
655
 
656
+ /**
657
+ * Forma DOM - Template
658
+ *
659
+ * Runtime helper for compiled template output. Memoizes template parsing
660
+ * so that each unique HTML string is parsed once and then cloned per use.
661
+ *
662
+ * The returned node should be cloned via `.cloneNode(true)` before use
663
+ * in component instances.
664
+ */
665
+ /**
666
+ * Create a reusable template node from an HTML string.
667
+ *
668
+ * The returned node is a cached prototype. Callers must call
669
+ * `.cloneNode(true)` to get a unique DOM tree for each component instance.
670
+ */
671
+ declare function template(html: string): Node;
672
+ /**
673
+ * Create a reusable template DocumentFragment from an HTML string.
674
+ *
675
+ * Used when the template has multiple root nodes. The returned fragment
676
+ * is a cached prototype; callers must call `.cloneNode(true)`.
677
+ */
678
+ declare function templateMany(html: string): DocumentFragment;
679
+
656
680
  /**
657
681
  * Hydrate an SSR island in-place. Runs the component in hydration mode so
658
682
  * h() returns descriptors, then walks the descriptor tree against the SSR DOM
@@ -991,4 +1015,4 @@ declare function onResize(el: HTMLElement, handler: (entry: ResizeObserverEntry)
991
1015
  declare function onIntersect(el: HTMLElement, handler: (entry: IntersectionObserverEntry) => void, options?: IntersectionObserverInit): () => void;
992
1016
  declare function onMutation(el: HTMLElement, handler: (mutations: MutationRecord[]) => void, options?: MutationObserverInit): () => void;
993
1017
 
994
- export { $, $$, type CleanupFn, type ComponentDef, type Context, type CreateListOptions, type Dispatch, type ErrorHandler, type EventBus, Fragment, type HistoryControls, type IslandHydrateFn, type KeyOptions, type ListTransitionHooks, type PersistOptions, type ReconcileResult, type Ref, type SetupFn, SignalGetter, type StoreSetter, type SwitchCase, activateIslands, addClass, batch, children, cleanup, closest, createBus, createComputed, createContext, createEffect, createErrorBoundary, createHistory, createList, createMemo, createPortal, createReducer, createRef, createRoot, createShow, createStore, createSuspense, createSwitch, createText, deactivateAllIslands, deactivateIsland, defineComponent, delegate, disposeComponent, fragment, h, hydrateIsland, inject, mount, nextSibling, on, onCleanup, onError, onIntersect, onKey, onMount, onMutation, onResize, onUnmount, parent, persist, prevSibling, provide, reconcileList, removeClass, setAttr, setHTMLUnsafe, setStyle, setText, siblings, toggleClass, trackDisposer, unprovide, untrack };
1018
+ export { $, $$, type CleanupFn, type ComponentDef, type Context, type CreateListOptions, type Dispatch, type ErrorHandler, type EventBus, Fragment, type HistoryControls, type IslandHydrateFn, type KeyOptions, type ListTransitionHooks, type PersistOptions, type ReconcileResult, type Ref, type SetupFn, SignalGetter, type StoreSetter, type SwitchCase, activateIslands, addClass, batch, children, cleanup, closest, createBus, createComputed, createContext, createEffect, createErrorBoundary, createHistory, createList, createMemo, createPortal, createReducer, createRef, createRoot, createShow, createStore, createSuspense, createSwitch, createText, deactivateAllIslands, deactivateIsland, defineComponent, delegate, disposeComponent, fragment, h, hydrateIsland, inject, mount, nextSibling, on, onCleanup, onError, onIntersect, onKey, onMount, onMutation, onResize, onUnmount, parent, persist, prevSibling, provide, reconcileList, removeClass, setAttr, setHTMLUnsafe, setStyle, setText, siblings, template, templateMany, toggleClass, trackDisposer, unprovide, untrack };
package/dist/index.d.ts CHANGED
@@ -653,6 +653,30 @@ declare function createErrorBoundary(tryFn: () => Node, catchFn: (error: Error,
653
653
  */
654
654
  declare function createSuspense(fallback: () => Node, children: () => Node): DocumentFragment;
655
655
 
656
+ /**
657
+ * Forma DOM - Template
658
+ *
659
+ * Runtime helper for compiled template output. Memoizes template parsing
660
+ * so that each unique HTML string is parsed once and then cloned per use.
661
+ *
662
+ * The returned node should be cloned via `.cloneNode(true)` before use
663
+ * in component instances.
664
+ */
665
+ /**
666
+ * Create a reusable template node from an HTML string.
667
+ *
668
+ * The returned node is a cached prototype. Callers must call
669
+ * `.cloneNode(true)` to get a unique DOM tree for each component instance.
670
+ */
671
+ declare function template(html: string): Node;
672
+ /**
673
+ * Create a reusable template DocumentFragment from an HTML string.
674
+ *
675
+ * Used when the template has multiple root nodes. The returned fragment
676
+ * is a cached prototype; callers must call `.cloneNode(true)`.
677
+ */
678
+ declare function templateMany(html: string): DocumentFragment;
679
+
656
680
  /**
657
681
  * Hydrate an SSR island in-place. Runs the component in hydration mode so
658
682
  * h() returns descriptors, then walks the descriptor tree against the SSR DOM
@@ -991,4 +1015,4 @@ declare function onResize(el: HTMLElement, handler: (entry: ResizeObserverEntry)
991
1015
  declare function onIntersect(el: HTMLElement, handler: (entry: IntersectionObserverEntry) => void, options?: IntersectionObserverInit): () => void;
992
1016
  declare function onMutation(el: HTMLElement, handler: (mutations: MutationRecord[]) => void, options?: MutationObserverInit): () => void;
993
1017
 
994
- export { $, $$, type CleanupFn, type ComponentDef, type Context, type CreateListOptions, type Dispatch, type ErrorHandler, type EventBus, Fragment, type HistoryControls, type IslandHydrateFn, type KeyOptions, type ListTransitionHooks, type PersistOptions, type ReconcileResult, type Ref, type SetupFn, SignalGetter, type StoreSetter, type SwitchCase, activateIslands, addClass, batch, children, cleanup, closest, createBus, createComputed, createContext, createEffect, createErrorBoundary, createHistory, createList, createMemo, createPortal, createReducer, createRef, createRoot, createShow, createStore, createSuspense, createSwitch, createText, deactivateAllIslands, deactivateIsland, defineComponent, delegate, disposeComponent, fragment, h, hydrateIsland, inject, mount, nextSibling, on, onCleanup, onError, onIntersect, onKey, onMount, onMutation, onResize, onUnmount, parent, persist, prevSibling, provide, reconcileList, removeClass, setAttr, setHTMLUnsafe, setStyle, setText, siblings, toggleClass, trackDisposer, unprovide, untrack };
1018
+ export { $, $$, type CleanupFn, type ComponentDef, type Context, type CreateListOptions, type Dispatch, type ErrorHandler, type EventBus, Fragment, type HistoryControls, type IslandHydrateFn, type KeyOptions, type ListTransitionHooks, type PersistOptions, type ReconcileResult, type Ref, type SetupFn, SignalGetter, type StoreSetter, type SwitchCase, activateIslands, addClass, batch, children, cleanup, closest, createBus, createComputed, createContext, createEffect, createErrorBoundary, createHistory, createList, createMemo, createPortal, createReducer, createRef, createRoot, createShow, createStore, createSuspense, createSwitch, createText, deactivateAllIslands, deactivateIsland, defineComponent, delegate, disposeComponent, fragment, h, hydrateIsland, inject, mount, nextSibling, on, onCleanup, onError, onIntersect, onKey, onMount, onMutation, onResize, onUnmount, parent, persist, prevSibling, provide, reconcileList, removeClass, setAttr, setHTMLUnsafe, setStyle, setText, siblings, template, templateMany, toggleClass, trackDisposer, unprovide, untrack };
package/dist/index.js CHANGED
@@ -53,7 +53,7 @@ function createSwitch(value, cases, fallback) {
53
53
  const fragment2 = document.createDocumentFragment();
54
54
  fragment2.appendChild(startMarker);
55
55
  fragment2.appendChild(endMarker);
56
- const cache = /* @__PURE__ */ new Map();
56
+ const cache2 = /* @__PURE__ */ new Map();
57
57
  let currentNode = null;
58
58
  let currentMatch = UNSET;
59
59
  const switchDispose = internalEffect(() => {
@@ -88,7 +88,7 @@ function createSwitch(value, cases, fallback) {
88
88
  }
89
89
  const matchedCase = cases.find((c) => c.match === val);
90
90
  if (matchedCase) {
91
- let entry = cache.get(val);
91
+ let entry = cache2.get(val);
92
92
  if (!entry) {
93
93
  let branchDispose;
94
94
  const node = createRoot((dispose) => {
@@ -96,7 +96,7 @@ function createSwitch(value, cases, fallback) {
96
96
  return untrack(() => matchedCase.render());
97
97
  });
98
98
  entry = { node, dispose: branchDispose };
99
- cache.set(val, entry);
99
+ cache2.set(val, entry);
100
100
  if (DEBUG) console.log("[forma:switch] rendered new branch for", String(val), "\u2192", node.nodeName, "type", node.nodeType);
101
101
  } else {
102
102
  if (DEBUG) console.log("[forma:switch] reusing cached branch for", String(val), "\u2192", entry.node.nodeName, "type", entry.node.nodeType, "childNodes", entry.node.childNodes?.length);
@@ -113,10 +113,10 @@ function createSwitch(value, cases, fallback) {
113
113
  });
114
114
  fragment2.__switchDispose = () => {
115
115
  switchDispose();
116
- for (const entry of cache.values()) {
116
+ for (const entry of cache2.values()) {
117
117
  entry.dispose();
118
118
  }
119
- cache.clear();
119
+ cache2.clear();
120
120
  };
121
121
  return fragment2;
122
122
  }
@@ -220,6 +220,29 @@ function createSuspense(fallback, children2) {
220
220
  return fragment2;
221
221
  }
222
222
 
223
+ // src/dom/template.ts
224
+ var cache = /* @__PURE__ */ new Map();
225
+ function template(html) {
226
+ let node = cache.get(html);
227
+ if (!node) {
228
+ const tpl = document.createElement("template");
229
+ tpl.innerHTML = html;
230
+ node = tpl.content.firstChild;
231
+ cache.set(html, node);
232
+ }
233
+ return node;
234
+ }
235
+ function templateMany(html) {
236
+ let node = cache.get(html);
237
+ if (!node) {
238
+ const tpl = document.createElement("template");
239
+ tpl.innerHTML = html;
240
+ node = tpl.content;
241
+ cache.set(html, node);
242
+ }
243
+ return node.cloneNode(true);
244
+ }
245
+
223
246
  // src/dom/activate.ts
224
247
  var FORBIDDEN_PROP_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
225
248
  function sanitizeProps(obj) {
@@ -992,6 +1015,6 @@ function onMutation(el, handler, options) {
992
1015
  };
993
1016
  }
994
1017
 
995
- export { $, $$, activateIslands, addClass, children, closest, createBus, createContext, createErrorBoundary, createHistory, createPortal, createStore, createSuspense, createSwitch, createText, deactivateAllIslands, deactivateIsland, defineComponent, delegate, disposeComponent, inject, mount, nextSibling, onIntersect, onKey, onMount, onMutation, onResize, onUnmount, parent, persist, prevSibling, provide, removeClass, setAttr, setHTMLUnsafe, setStyle, setText, siblings, toggleClass, trackDisposer, unprovide };
1018
+ export { $, $$, activateIslands, addClass, children, closest, createBus, createContext, createErrorBoundary, createHistory, createPortal, createStore, createSuspense, createSwitch, createText, deactivateAllIslands, deactivateIsland, defineComponent, delegate, disposeComponent, inject, mount, nextSibling, onIntersect, onKey, onMount, onMutation, onResize, onUnmount, parent, persist, prevSibling, provide, removeClass, setAttr, setHTMLUnsafe, setStyle, setText, siblings, template, templateMany, toggleClass, trackDisposer, unprovide };
996
1019
  //# sourceMappingURL=index.js.map
997
1020
  //# sourceMappingURL=index.js.map