@tempots/client 0.0.3 → 0.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/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("@tempots/core"),h=require("@tempots/dom");function g(o,e,t={}){const{providers:n={},removeMarkers:i=!0}=t,r=N(e),s=new f.DisposalScope,d=new a(e.ownerDocument,e,void 0,n,r,0),c=f.withScope(s,()=>o.render(d));return i&&y(e),(l=!1)=>{s.dispose(),c(l)}}function N(o){const e=new Map;return o.querySelectorAll(`[${h.HYDRATION_ID_ATTR}]`).forEach(n=>{const i=n.getAttribute(h.HYDRATION_ID_ATTR);i&&e.set(i,n)}),e}function y(o){o.querySelectorAll(`[${h.HYDRATION_ID_ATTR}]`).forEach(t=>{t.removeAttribute(h.HYDRATION_ID_ATTR),t.removeAttribute("data-tts-node")})}class a{constructor(e,t,n,i,r,s){this.document=e,this.element=t,this.reference=n,this.providers=i,this.hydrationMap=r,this.childIndex=s}makeChildElement=(e,t)=>{const n=this.element.children;for(let r=this.childIndex;r<n.length;r++){const s=n[r];if(s.tagName.toLowerCase()===e.toLowerCase())return this.childIndex=r+1,new a(this.document,s,void 0,this.providers,this.hydrationMap,0)}console.warn(`Hydration mismatch: could not find element <${e}> in container`);const i=t!==void 0?this.document.createElementNS(t,e):this.document.createElement(e);return this.appendOrInsert(i),new a(this.document,i,void 0,this.providers,this.hydrationMap,0)};makeChildText=e=>{const t=this.element.childNodes;for(let i=this.childIndex;i<t.length;i++){const r=t[i];if(r.nodeType===Node.TEXT_NODE)return this.childIndex=i+1,r.textContent!==e&&(r.textContent=e),new a(this.document,this.element,r,this.providers,this.hydrationMap,this.childIndex)}const n=this.document.createTextNode(e);return this.appendOrInsert(n),new a(this.document,this.element,n,this.providers,this.hydrationMap,this.childIndex)};setText=e=>{this.reference&&(this.reference.nodeValue=e)};getText=()=>this.reference?.nodeValue??this.element.textContent??"";makeRef=()=>{const e=this.element.childNodes;for(let n=this.childIndex;n<e.length;n++){const i=e[n];if(i.nodeType===Node.TEXT_NODE&&(i.textContent===""||i.textContent===null))return this.childIndex=n+1,new a(this.document,this.element,i,this.providers,this.hydrationMap,this.childIndex)}const t=this.document.createTextNode("");return this.appendOrInsert(t),new a(this.document,this.element,t,this.providers,this.hydrationMap,this.childIndex)};makeMarker=()=>this.makeRef();makePortal=e=>{const t=typeof e=="string"?this.document.querySelector(e):e;if(t==null)throw new Error(`Cannot find element by selector for portal: ${e}`);return new a(this.document,t,void 0,this.providers,this.hydrationMap,0)};appendOrInsert=e=>{this.reference===void 0?this.element.appendChild(e):this.element.insertBefore(e,this.reference)};setProvider=(e,t,n)=>new a(this.document,this.element,this.reference,{...this.providers,[e]:[t,n]},this.hydrationMap,this.childIndex);getProvider=e=>{if(this.providers[e]===void 0)throw new Error(`Provider not found: ${String(e)}`);const[t,n]=this.providers[e];return{value:t,onUse:n}};clear=e=>{e&&(this.reference!==void 0?this.reference.parentNode?.removeChild(this.reference):this.element.parentNode?.removeChild(this.element))};addClasses=e=>{this.element.classList.add(...e)};removeClasses=e=>{this.element.classList.remove(...e)};getClasses=()=>Array.from(this.element.classList);on=(e,t,n)=>{const i=r=>t(r,this);return this.element.addEventListener(e,i,n),r=>{r&&this.element.removeEventListener(e,i,n)}};isBrowserDOM=()=>!1;isBrowser=()=>!0;isHeadlessDOM=()=>!1;isHeadless=()=>!1;setStyle=(e,t)=>{this.element.style[e]=t};getStyle=e=>this.element.style[e];makeAccessors=e=>{const t=this.element;return{get:()=>t[e],set:n=>{t[e]=n}}};moveRangeBefore=(e,t,n)=>{const i=e.reference,r=t.reference,s=n.reference,d=this.element;let c=i;for(;c!==null;){const l=c.nextSibling;if(d.insertBefore(c,s),c===r)break;c=l}};removeRange=(e,t)=>{const n=e.reference,i=t.reference,r=this.element;let s=n;for(;s!==null;){const d=s.nextSibling;if(r.removeChild(s),s===i)break;s=d}};removeAllBefore(e){const t=e.reference,n=this.element;if(!n.firstChild||n.firstChild===t)return;const i=this.document.createRange();i.setStartBefore(n.firstChild),i.setEndBefore(t),i.deleteContents()}_detachedParent=null;_detachedNext=null;detach(){const e=this.element;e.parentNode&&(this._detachedParent=e.parentNode,this._detachedNext=e.nextSibling,e.remove())}reattach(){this._detachedParent&&(this._detachedParent.insertBefore(this.element,this._detachedNext),this._detachedParent=null,this._detachedNext=null)}}const u="data-tempo-island",I="data-tempo-hydrate",S="data-tempo-options";function A(o,e,t,n={}){o.innerHTML="";const i=new h.BrowserContext(o.ownerDocument,o,void 0,n.providers??{}),r=new f.DisposalScope,s=f.withScope(r,()=>e(t).render(i));return(d=!1)=>{r.dispose(),s(d)}}function x(o,e,t){if(e==="immediate")return t(),()=>{};if(e==="idle")if("requestIdleCallback"in window){const n=requestIdleCallback(t);return()=>cancelIdleCallback(n)}else{const n=setTimeout(t,1);return()=>clearTimeout(n)}if(e==="visible"){const n=new IntersectionObserver(i=>{for(const r of i)if(r.isIntersecting){n.disconnect(),t();break}},{rootMargin:"50px"});return n.observe(o),()=>n.disconnect()}if(typeof e=="object"&&"media"in e){const n=window.matchMedia(e.media);if(n.matches)return t(),()=>{};const i=r=>{r.matches&&(n.removeEventListener("change",i),t())};return n.addEventListener("change",i),()=>n.removeEventListener("change",i)}return t(),()=>{}}function D(o){return!o||o==="immediate"||o==="load"?"immediate":o==="idle"?"idle":o==="visible"?"visible":o.startsWith("media:")?{media:o.slice(6).trim()}:"immediate"}function T(o,e={}){const t=[];return document.querySelectorAll(`[${u}]`).forEach(i=>{const r=i,s=r.getAttribute(u);if(!s){console.warn("[Tempo Islands] Element missing island name:",r);return}const d=o[s];if(!d){console.warn(`[Tempo Islands] Component "${s}" not found in registry`);return}const c=r.getAttribute(S);let l={};if(c)try{l=JSON.parse(c)}catch(p){console.warn(`[Tempo Islands] Failed to parse options for "${s}":`,p)}const m=r.getAttribute(I),v=D(m),w=x(r,v,()=>{const p=A(r,d,l,e);t.push(p),r.removeAttribute(u),r.removeAttribute(I),r.removeAttribute(S)});t.push(w)}),()=>{t.forEach(i=>i())}}function R(o,e={},t="visible"){const n=typeof t=="object"?`media:${t.media}`:t;return[{name:u,value:o},{name:S,value:JSON.stringify(e)},{name:I,value:n}]}function b(o){const{app:e,islands:t,container:n="#app",providers:i={},debug:r=!1}=o,s=r?m=>console.log(`[Tempo] ${m}`):()=>{},d=typeof n=="string"?document.querySelector(n):n;if(!d)return console.error(`[Tempo] Could not find container: ${typeof n=="string"?n:"(element)"}`),()=>{};const c=d.querySelector(`[${u}]`)!==null;let l;if(c)s("SSR mode: Initializing islands..."),l=T(t,{providers:i}),s("Islands initialized! Static content stays static.");else if(e){s("Client-only mode: Rendering app...");const m=new h.BrowserContext(document,d,void 0,i),v=new f.DisposalScope,w=f.withScope(v,()=>e().render(m)),p=T(t,{providers:i});l=()=>{p(),v.dispose(),w(!0)},s("App rendered and islands initialized!")}else s("No SSR content detected, initializing islands only..."),l=T(t,{providers:i});return l}Object.defineProperty(exports,"HYDRATION_ID_ATTR",{enumerable:!0,get:()=>h.HYDRATION_ID_ATTR});exports.HydrationContext=a;exports.ISLAND_ATTR=u;exports.ISLAND_HYDRATE_ATTR=I;exports.ISLAND_OPTIONS_ATTR=S;exports.hydrate=g;exports.hydrateIsland=A;exports.initIslands=T;exports.islandMarker=R;exports.startClient=b;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("@tempots/core"),h=require("@tempots/dom");function g(o,e,t={}){const{providers:n={},removeMarkers:i=!0}=t,r=N(e),s=new f.DisposalScope,d=new a(e.ownerDocument,e,void 0,n,r,0),c=f.withScope(s,()=>o.render(d));return i&&y(e),(l=!1)=>{s.dispose(),c(l)}}function N(o){const e=new Map;return o.querySelectorAll(`[${h.HYDRATION_ID_ATTR}]`).forEach(n=>{const i=n.getAttribute(h.HYDRATION_ID_ATTR);i&&e.set(i,n)}),e}function y(o){o.querySelectorAll(`[${h.HYDRATION_ID_ATTR}]`).forEach(t=>{t.removeAttribute(h.HYDRATION_ID_ATTR),t.removeAttribute("data-tts-node")})}class a{constructor(e,t,n,i,r,s){this.document=e,this.element=t,this.reference=n,this.providers=i,this.hydrationMap=r,this.childIndex=s}makeChildElement=(e,t)=>{const n=this.element.children;for(let r=this.childIndex;r<n.length;r++){const s=n[r];if(s.tagName.toLowerCase()===e.toLowerCase())return this.childIndex=r+1,new a(this.document,s,void 0,this.providers,this.hydrationMap,0)}console.warn(`Hydration mismatch: could not find element <${e}> in container`);const i=t!==void 0?this.document.createElementNS(t,e):this.document.createElement(e);return this.appendOrInsert(i),new a(this.document,i,void 0,this.providers,this.hydrationMap,0)};makeChildText=e=>{const t=this.element.childNodes;for(let i=this.childIndex;i<t.length;i++){const r=t[i];if(r.nodeType===Node.TEXT_NODE)return this.childIndex=i+1,r.textContent!==e&&(r.textContent=e),new a(this.document,this.element,r,this.providers,this.hydrationMap,this.childIndex)}const n=this.document.createTextNode(e);return this.appendOrInsert(n),new a(this.document,this.element,n,this.providers,this.hydrationMap,this.childIndex)};setText=e=>{this.reference&&(this.reference.nodeValue=e)};getText=()=>this.reference?.nodeValue??this.element.textContent??"";makeRef=()=>{const e=this.element.childNodes;for(let n=this.childIndex;n<e.length;n++){const i=e[n];if(i.nodeType===Node.TEXT_NODE&&(i.textContent===""||i.textContent===null))return this.childIndex=n+1,new a(this.document,this.element,i,this.providers,this.hydrationMap,this.childIndex)}const t=this.document.createTextNode("");return this.appendOrInsert(t),new a(this.document,this.element,t,this.providers,this.hydrationMap,this.childIndex)};makeMarker=()=>this.makeRef();makePortal=e=>{const t=typeof e=="string"?this.document.querySelector(e):e;if(t==null)throw new Error(`Cannot find element by selector for portal: ${e}`);return new a(this.document,t,void 0,this.providers,this.hydrationMap,0)};appendOrInsert=e=>{this.reference===void 0?this.element.appendChild(e):this.element.insertBefore(e,this.reference)};setProvider=(e,t,n)=>new a(this.document,this.element,this.reference,{...this.providers,[e]:[t,n]},this.hydrationMap,this.childIndex);getProvider=e=>{if(this.providers[e]===void 0)throw new Error(`Provider not found: ${String(e)}`);const[t,n]=this.providers[e];return{value:t,onUse:n}};tryGetProvider=e=>{if(this.providers[e]===void 0)return;const[t,n]=this.providers[e];return{value:t,onUse:n}};clear=e=>{e&&(this.reference!==void 0?this.reference.parentNode?.removeChild(this.reference):this.element.parentNode?.removeChild(this.element))};addClasses=e=>{this.element.classList.add(...e)};removeClasses=e=>{this.element.classList.remove(...e)};getClasses=()=>Array.from(this.element.classList);on=(e,t,n)=>{const i=r=>t(r,this);return this.element.addEventListener(e,i,n),r=>{r&&this.element.removeEventListener(e,i,n)}};isBrowserDOM=()=>!1;isBrowser=()=>!0;isHeadlessDOM=()=>!1;isHeadless=()=>!1;setStyle=(e,t)=>{this.element.style[e]=t};getStyle=e=>this.element.style[e];makeAccessors=e=>{const t=this.element;return{get:()=>t[e],set:n=>{t[e]=n}}};moveRangeBefore=(e,t,n)=>{const i=e.reference,r=t.reference,s=n.reference,d=this.element;let c=i;for(;c!==null;){const l=c.nextSibling;if(d.insertBefore(c,s),c===r)break;c=l}};removeRange=(e,t)=>{const n=e.reference,i=t.reference,r=this.element;let s=n;for(;s!==null;){const d=s.nextSibling;if(r.removeChild(s),s===i)break;s=d}};removeAllBefore(e){const t=e.reference,n=this.element;if(!n.firstChild||n.firstChild===t)return;const i=this.document.createRange();i.setStartBefore(n.firstChild),i.setEndBefore(t),i.deleteContents()}_detachedParent=null;_detachedNext=null;detach(){const e=this.element;e.parentNode&&(this._detachedParent=e.parentNode,this._detachedNext=e.nextSibling,e.remove())}reattach(){this._detachedParent&&(this._detachedParent.insertBefore(this.element,this._detachedNext),this._detachedParent=null,this._detachedNext=null)}}const u="data-tempo-island",I="data-tempo-hydrate",S="data-tempo-options";function A(o,e,t,n={}){o.innerHTML="";const i=new h.BrowserContext(o.ownerDocument,o,void 0,n.providers??{}),r=new f.DisposalScope,s=f.withScope(r,()=>e(t).render(i));return(d=!1)=>{r.dispose(),s(d)}}function x(o,e,t){if(e==="immediate")return t(),()=>{};if(e==="idle")if("requestIdleCallback"in window){const n=requestIdleCallback(t);return()=>cancelIdleCallback(n)}else{const n=setTimeout(t,1);return()=>clearTimeout(n)}if(e==="visible"){const n=new IntersectionObserver(i=>{for(const r of i)if(r.isIntersecting){n.disconnect(),t();break}},{rootMargin:"50px"});return n.observe(o),()=>n.disconnect()}if(typeof e=="object"&&"media"in e){const n=window.matchMedia(e.media);if(n.matches)return t(),()=>{};const i=r=>{r.matches&&(n.removeEventListener("change",i),t())};return n.addEventListener("change",i),()=>n.removeEventListener("change",i)}return t(),()=>{}}function D(o){return!o||o==="immediate"||o==="load"?"immediate":o==="idle"?"idle":o==="visible"?"visible":o.startsWith("media:")?{media:o.slice(6).trim()}:"immediate"}function T(o,e={}){const t=[];return document.querySelectorAll(`[${u}]`).forEach(i=>{const r=i,s=r.getAttribute(u);if(!s){console.warn("[Tempo Islands] Element missing island name:",r);return}const d=o[s];if(!d){console.warn(`[Tempo Islands] Component "${s}" not found in registry`);return}const c=r.getAttribute(S);let l={};if(c)try{l=JSON.parse(c)}catch(p){console.warn(`[Tempo Islands] Failed to parse options for "${s}":`,p)}const m=r.getAttribute(I),v=D(m),w=x(r,v,()=>{const p=A(r,d,l,e);t.push(p),r.removeAttribute(u),r.removeAttribute(I),r.removeAttribute(S)});t.push(w)}),()=>{t.forEach(i=>i())}}function R(o,e={},t="visible"){const n=typeof t=="object"?`media:${t.media}`:t;return[{name:u,value:o},{name:S,value:JSON.stringify(e)},{name:I,value:n}]}function b(o){const{app:e,islands:t,container:n="#app",providers:i={},debug:r=!1}=o,s=r?m=>console.log(`[Tempo] ${m}`):()=>{},d=typeof n=="string"?document.querySelector(n):n;if(!d)return console.error(`[Tempo] Could not find container: ${typeof n=="string"?n:"(element)"}`),()=>{};const c=d.querySelector(`[${u}]`)!==null;let l;if(c)s("SSR mode: Initializing islands..."),l=T(t,{providers:i}),s("Islands initialized! Static content stays static.");else if(e){s("Client-only mode: Rendering app...");const m=new h.BrowserContext(document,d,void 0,i),v=new f.DisposalScope,w=f.withScope(v,()=>e().render(m)),p=T(t,{providers:i});l=()=>{p(),v.dispose(),w(!0)},s("App rendered and islands initialized!")}else s("No SSR content detected, initializing islands only..."),l=T(t,{providers:i});return l}Object.defineProperty(exports,"HYDRATION_ID_ATTR",{enumerable:!0,get:()=>h.HYDRATION_ID_ATTR});exports.HydrationContext=a;exports.ISLAND_ATTR=u;exports.ISLAND_HYDRATE_ATTR=I;exports.ISLAND_OPTIONS_ATTR=S;exports.hydrate=g;exports.hydrateIsland=A;exports.initIslands=T;exports.islandMarker=R;exports.startClient=b;
package/index.d.ts CHANGED
@@ -77,6 +77,10 @@ export declare class HydrationContext implements DOMContext {
77
77
  value: T;
78
78
  onUse: (() => void) | undefined;
79
79
  };
80
+ readonly tryGetProvider: <T>(mark: ProviderMark<T>) => {
81
+ value: T;
82
+ onUse?: () => void;
83
+ } | undefined;
80
84
  readonly clear: (removeTree: boolean) => void;
81
85
  readonly addClasses: (tokens: string[]) => void;
82
86
  readonly removeClasses: (tokens: string[]) => void;
package/index.js CHANGED
@@ -147,6 +147,12 @@ class a {
147
147
  const [t, n] = this.providers[e];
148
148
  return { value: t, onUse: n };
149
149
  };
150
+ tryGetProvider = (e) => {
151
+ if (this.providers[e] === void 0)
152
+ return;
153
+ const [t, n] = this.providers[e];
154
+ return { value: t, onUse: n };
155
+ };
150
156
  clear = (e) => {
151
157
  e && (this.reference !== void 0 ? this.reference.parentNode?.removeChild(this.reference) : this.element.parentNode?.removeChild(this.element));
152
158
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tempots/client",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "type": "module",
5
5
  "main": "./index.cjs",
6
6
  "module": "./index.js",
@@ -34,7 +34,7 @@
34
34
  "url": "git+https://github.com/fponticelli/tempots.git"
35
35
  },
36
36
  "peerDependencies": {
37
- "@tempots/core": "^3.0.0",
38
- "@tempots/dom": "^37.0.0"
37
+ "@tempots/core": "^3.2.1",
38
+ "@tempots/dom": "^37.4.1"
39
39
  }
40
40
  }