@homekynd/hk-embed-sdk 0.0.4 → 0.0.6

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.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react"),n="http://localhost:3000";async function y(s,e){try{const t=await fetch(`${n}/api/v1/company/generate-token`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({api_secret:s,id:e})}),a=await t.json();if(t.ok)return a.token;console.error("Error fetching token: please confirm your API Secret and Client ID",a)}catch(t){console.error("Fetch error:",t)}}const R={root:"/company",renders:"/renders",spaces:"/spaces"};class g{container;iframe;currentToken;created=!1;constructor(e){const{container:t}=e;if(!t)throw new Error("Container element is required");this.container=t,this.create(e)}async create(e){if(this.created)return;const{clientId:t,apiKey:a,path:c="root",width:i="100%",height:h="100%",enablePathSync:m=!0}=e,d=new URL(window.location.href),o=d.searchParams.get("ifpath")||R[c],p=n.endsWith("/")?n:n+"/",w=o.startsWith("/")?o.substring(1):o,f=new URL(w,p),u=await y(a,t);this.currentToken=u,u&&f.searchParams.set("token",u);const r=document.createElement("iframe");return r.src=f.toString(),r.style.border="0",r.style.width=isNaN(Number(i))?i:`${i}px`,r.style.height=isNaN(Number(h))?h:`${h}px`,console.log("applying user styles/sizing"),this.iframe=r,r.onload=()=>{this.currentToken&&this.sendMessage({type:"SET_TOKEN",token:this.currentToken})},this.container.innerHTML="",this.container.appendChild(r),m&&(d.searchParams.set("ifpath",o),window.history.replaceState({},"",d.toString())),this.setupMessageHandling(),this.created=!0,{sendMessage:this.sendMessage.bind(this),onMessage:this.onMessage.bind(this)}}setupMessageHandling(){window.addEventListener("message",e=>{e.data?.type==="ROUTE_CHANGE"&&this.onRouteChange(e.data.path)})}onRouteChange(e){this.inputParentRoute(e),this.inputIframeRoute(e)}inputParentRoute(e){const t=new URL(window.location.href);t.searchParams.set("ifpath",e),window.history.replaceState({},"",t.toString())}inputIframeRoute(e){if(!this.iframe)return;const t=new URL(this.iframe.src),a=n.endsWith("/")?n:n+"/",c=e.startsWith("/")?e.substring(1):e,i=new URL(c,a);t.pathname!==i.pathname&&(this.iframe.src=i.toString())}sendMessage(e){if(this.iframe?.contentWindow){const t=new URL(n).origin;this.iframe.contentWindow.postMessage(e,t)}}onMessage(e){window.addEventListener("message",t=>{e(t.data)})}}const b=s=>{const e=l.useRef(null),t=l.useRef(null);return l.useLayoutEffect(()=>(e.current&&!t.current&&(t.current=new g({...s,container:e.current})),()=>{t.current=null}),[s]),React.createElement("div",{ref:e,style:s.style})};exports.HKEmbed=g;exports.HKReactEmbed=b;
1
+ "use strict";var k=Object.defineProperty,U=Object.defineProperties;var L=Object.getOwnPropertyDescriptors;var E=Object.getOwnPropertySymbols;var T=Object.prototype.hasOwnProperty,H=Object.prototype.propertyIsEnumerable;var w=(n,e,t)=>e in n?k(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,R=(n,e)=>{for(var t in e||(e={}))T.call(e,t)&&w(n,t,e[t]);if(E)for(var t of E(e))H.call(e,t)&&w(n,t,e[t]);return n},b=(n,e)=>U(n,L(e));var f=(n,e,t)=>w(n,typeof e!="symbol"?e+"":e,t);var y=(n,e,t)=>new Promise((r,o)=>{var s=a=>{try{h(t.next(a))}catch(l){o(l)}},u=a=>{try{h(t.throw(a))}catch(l){o(l)}},h=a=>a.done?r(a.value):Promise.resolve(a.value).then(s,u);h((t=t.apply(n,e)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("react"),c="https://staging.homekynd.com/";function I(n,e){return y(this,null,function*(){try{const t=yield fetch(`${c}/api/v1/company/generate-token`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({api_secret:n,id:e})}),r=yield t.json();if(t.ok)return r.token;console.error("Error fetching token: please confirm your API Secret and Client ID",r)}catch(t){console.error("Fetch error:",t)}})}const N={root:"/company",renders:"/renders",spaces:"/spaces"};class P{constructor(e){f(this,"container");f(this,"iframe");f(this,"currentToken");f(this,"created",!1);const{container:t}=e;if(!t)throw new Error("Container element is required");this.container=t,this.create(e)}create(e){return y(this,null,function*(){if(this.created)return;const{clientId:t,apiKey:r,path:o="root",width:s="100%",height:u="100%",enablePathSync:h=!0}=e,a=new URL(window.location.href),m=a.searchParams.get("ifpath")||N[o],S=c.endsWith("/")?c:c+"/",M=m.startsWith("/")?m.substring(1):m,p=new URL(M,S),g=yield I(r,t);this.currentToken=g,g&&p.searchParams.set("token",g);const d=document.createElement("iframe");return d.src=p.toString(),d.style.border="0",d.style.width=isNaN(Number(s))?s:`${s}px`,d.style.height=isNaN(Number(u))?u:`${u}px`,this.iframe=d,d.onload=()=>{this.currentToken&&this.sendMessage({type:"SET_TOKEN",token:this.currentToken})},this.container.innerHTML="",this.container.appendChild(d),h&&(a.searchParams.set("ifpath",m),window.history.replaceState({},"",a.toString())),this.setupMessageHandling(),this.created=!0,{sendMessage:this.sendMessage.bind(this),onMessage:this.onMessage.bind(this)}})}setupMessageHandling(){window.addEventListener("message",e=>{var t;((t=e.data)==null?void 0:t.type)==="ROUTE_CHANGE"&&this.onRouteChange(e.data.path)})}onRouteChange(e){this.inputParentRoute(e),this.inputIframeRoute(e)}inputParentRoute(e){const t=new URL(window.location.href);t.searchParams.set("ifpath",e),window.history.replaceState({},"",t.toString())}inputIframeRoute(e){if(!this.iframe)return;const t=new URL(this.iframe.src),r=c.endsWith("/")?c:c+"/",o=e.startsWith("/")?e.substring(1):e,s=new URL(o,r);t.pathname!==s.pathname&&(this.iframe.src=s.toString())}sendMessage(e){var t;if((t=this.iframe)!=null&&t.contentWindow){const r=new URL(c).origin;this.iframe.contentWindow.postMessage(e,r)}}onMessage(e){window.addEventListener("message",t=>{e(t.data)})}}const v=n=>{const e=i.useRef(null),t=i.useRef(null),[r,o]=i.useState(!1),s=i.useMemo(()=>n,[n.clientId,n.apiKey,n.path,n.width,n.height,n.enablePathSync]);return i.useEffect(()=>{o(!0)},[]),(typeof window!="undefined"?i.useLayoutEffect:i.useEffect)(()=>{if(!(!r||typeof window=="undefined")){if(e.current&&!t.current)try{t.current=new P(b(R({},s),{container:e.current}))}catch(h){console.error("Error creating HKEmbed:",h)}return()=>{t.current&&(t.current=null)}}},[s,r]),r?i.createElement("div",{ref:e,style:n.style}):i.createElement("div",{ref:e,style:n.style})};exports.HKEmbed=P;exports.HKReactEmbed=v;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { JSX } from 'react/jsx-runtime';
1
+ import { default as default_2 } from 'react';
2
2
 
3
3
  export declare type GenericMessageObject = any;
4
4
 
@@ -44,6 +44,6 @@ export declare type HKPath = Record<HKPathKey, string>;
44
44
 
45
45
  export declare type HKPathKey = "root" | "renders" | "spaces";
46
46
 
47
- export declare const HKReactEmbed: (options: HKEmbedConfigReact) => JSX.Element;
47
+ export declare const HKReactEmbed: default_2.FC<HKEmbedConfigReact>;
48
48
 
49
49
  export { }
package/dist/index.js CHANGED
@@ -1,64 +1,98 @@
1
- import { useRef as f, useLayoutEffect as w } from "react";
2
- const n = "http://localhost:3000";
3
- async function y(s, e) {
4
- try {
5
- const t = await fetch(`${n}/api/v1/company/generate-token`, {
6
- method: "POST",
7
- headers: {
8
- "Content-Type": "application/json"
9
- },
10
- body: JSON.stringify({ api_secret: s, id: e })
11
- }), a = await t.json();
12
- if (t.ok)
13
- return a.token;
14
- console.error(
15
- "Error fetching token: please confirm your API Secret and Client ID",
16
- a
17
- );
18
- } catch (t) {
19
- console.error("Fetch error:", t);
20
- }
1
+ var U = Object.defineProperty, L = Object.defineProperties;
2
+ var T = Object.getOwnPropertyDescriptors;
3
+ var E = Object.getOwnPropertySymbols;
4
+ var I = Object.prototype.hasOwnProperty, N = Object.prototype.propertyIsEnumerable;
5
+ var g = (n, e, t) => e in n ? U(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t, R = (n, e) => {
6
+ for (var t in e || (e = {}))
7
+ I.call(e, t) && g(n, t, e[t]);
8
+ if (E)
9
+ for (var t of E(e))
10
+ N.call(e, t) && g(n, t, e[t]);
11
+ return n;
12
+ }, b = (n, e) => L(n, T(e));
13
+ var u = (n, e, t) => g(n, typeof e != "symbol" ? e + "" : e, t);
14
+ var w = (n, e, t) => new Promise((r, i) => {
15
+ var s = (a) => {
16
+ try {
17
+ c(t.next(a));
18
+ } catch (f) {
19
+ i(f);
20
+ }
21
+ }, d = (a) => {
22
+ try {
23
+ c(t.throw(a));
24
+ } catch (f) {
25
+ i(f);
26
+ }
27
+ }, c = (a) => a.done ? r(a.value) : Promise.resolve(a.value).then(s, d);
28
+ c((t = t.apply(n, e)).next());
29
+ });
30
+ import p, { useRef as P, useMemo as v, useEffect as k, useLayoutEffect as C } from "react";
31
+ const o = "https://staging.homekynd.com/";
32
+ function H(n, e) {
33
+ return w(this, null, function* () {
34
+ try {
35
+ const t = yield fetch(`${o}/api/v1/company/generate-token`, {
36
+ method: "POST",
37
+ headers: {
38
+ "Content-Type": "application/json"
39
+ },
40
+ body: JSON.stringify({ api_secret: n, id: e })
41
+ }), r = yield t.json();
42
+ if (t.ok)
43
+ return r.token;
44
+ console.error(
45
+ "Error fetching token: please confirm your API Secret and Client ID",
46
+ r
47
+ );
48
+ } catch (t) {
49
+ console.error("Fetch error:", t);
50
+ }
51
+ });
21
52
  }
22
- const R = {
53
+ const K = {
23
54
  root: "/company",
24
55
  renders: "/renders",
25
56
  spaces: "/spaces"
26
57
  };
27
- class b {
28
- container;
29
- iframe;
30
- currentToken;
31
- created = !1;
58
+ class O {
32
59
  constructor(e) {
60
+ u(this, "container");
61
+ u(this, "iframe");
62
+ u(this, "currentToken");
63
+ u(this, "created", !1);
33
64
  const { container: t } = e;
34
65
  if (!t) throw new Error("Container element is required");
35
66
  this.container = t, this.create(e);
36
67
  }
37
- async create(e) {
38
- if (this.created) return;
39
- const {
40
- clientId: t,
41
- apiKey: a,
42
- path: c = "root",
43
- width: i = "100%",
44
- height: h = "100%",
45
- enablePathSync: g = !0
46
- } = e, d = new URL(window.location.href), o = d.searchParams.get("ifpath") || R[c], m = n.endsWith("/") ? n : n + "/", p = o.startsWith("/") ? o.substring(1) : o, l = new URL(p, m), u = await y(a, t);
47
- this.currentToken = u, u && l.searchParams.set("token", u);
48
- const r = document.createElement("iframe");
49
- return r.src = l.toString(), r.style.border = "0", r.style.width = isNaN(Number(i)) ? i : `${i}px`, r.style.height = isNaN(Number(h)) ? h : `${h}px`, console.log("applying user styles/sizing"), this.iframe = r, r.onload = () => {
50
- this.currentToken && this.sendMessage({
51
- type: "SET_TOKEN",
52
- token: this.currentToken
53
- });
54
- }, this.container.innerHTML = "", this.container.appendChild(r), g && (d.searchParams.set("ifpath", o), window.history.replaceState({}, "", d.toString())), this.setupMessageHandling(), this.created = !0, {
55
- sendMessage: this.sendMessage.bind(this),
56
- onMessage: this.onMessage.bind(this)
57
- };
68
+ create(e) {
69
+ return w(this, null, function* () {
70
+ if (this.created) return;
71
+ const {
72
+ clientId: t,
73
+ apiKey: r,
74
+ path: i = "root",
75
+ width: s = "100%",
76
+ height: d = "100%",
77
+ enablePathSync: c = !0
78
+ } = e, a = new URL(window.location.href), l = a.searchParams.get("ifpath") || K[i], M = o.endsWith("/") ? o : o + "/", S = l.startsWith("/") ? l.substring(1) : l, y = new URL(S, M), m = yield H(r, t);
79
+ this.currentToken = m, m && y.searchParams.set("token", m);
80
+ const h = document.createElement("iframe");
81
+ return h.src = y.toString(), h.style.border = "0", h.style.width = isNaN(Number(s)) ? s : `${s}px`, h.style.height = isNaN(Number(d)) ? d : `${d}px`, this.iframe = h, h.onload = () => {
82
+ this.currentToken && this.sendMessage({
83
+ type: "SET_TOKEN",
84
+ token: this.currentToken
85
+ });
86
+ }, this.container.innerHTML = "", this.container.appendChild(h), c && (a.searchParams.set("ifpath", l), window.history.replaceState({}, "", a.toString())), this.setupMessageHandling(), this.created = !0, {
87
+ sendMessage: this.sendMessage.bind(this),
88
+ onMessage: this.onMessage.bind(this)
89
+ };
90
+ });
58
91
  }
59
92
  setupMessageHandling() {
60
93
  window.addEventListener("message", (e) => {
61
- e.data?.type === "ROUTE_CHANGE" && this.onRouteChange(e.data.path);
94
+ var t;
95
+ ((t = e.data) == null ? void 0 : t.type) === "ROUTE_CHANGE" && this.onRouteChange(e.data.path);
62
96
  });
63
97
  }
64
98
  onRouteChange(e) {
@@ -70,13 +104,14 @@ class b {
70
104
  }
71
105
  inputIframeRoute(e) {
72
106
  if (!this.iframe) return;
73
- const t = new URL(this.iframe.src), a = n.endsWith("/") ? n : n + "/", c = e.startsWith("/") ? e.substring(1) : e, i = new URL(c, a);
74
- t.pathname !== i.pathname && (this.iframe.src = i.toString());
107
+ const t = new URL(this.iframe.src), r = o.endsWith("/") ? o : o + "/", i = e.startsWith("/") ? e.substring(1) : e, s = new URL(i, r);
108
+ t.pathname !== s.pathname && (this.iframe.src = s.toString());
75
109
  }
76
110
  sendMessage(e) {
77
- if (this.iframe?.contentWindow) {
78
- const t = new URL(n).origin;
79
- this.iframe.contentWindow.postMessage(e, t);
111
+ var t;
112
+ if ((t = this.iframe) != null && t.contentWindow) {
113
+ const r = new URL(o).origin;
114
+ this.iframe.contentWindow.postMessage(e, r);
80
115
  }
81
116
  }
82
117
  onMessage(e) {
@@ -85,16 +120,37 @@ class b {
85
120
  });
86
121
  }
87
122
  }
88
- const U = (s) => {
89
- const e = f(null), t = f(null);
90
- return w(() => (e.current && !t.current && (t.current = new b({
91
- ...s,
92
- container: e.current
93
- })), () => {
94
- t.current = null;
95
- }), [s]), /* @__PURE__ */ React.createElement("div", { ref: e, style: s.style });
123
+ const x = (n) => {
124
+ const e = P(null), t = P(null), [r, i] = p.useState(!1), s = v(
125
+ () => n,
126
+ [
127
+ n.clientId,
128
+ n.apiKey,
129
+ n.path,
130
+ n.width,
131
+ n.height,
132
+ n.enablePathSync
133
+ ]
134
+ );
135
+ return k(() => {
136
+ i(!0);
137
+ }, []), (typeof window != "undefined" ? C : k)(() => {
138
+ if (!(!r || typeof window == "undefined")) {
139
+ if (e.current && !t.current)
140
+ try {
141
+ t.current = new O(b(R({}, s), {
142
+ container: e.current
143
+ }));
144
+ } catch (c) {
145
+ console.error("Error creating HKEmbed:", c);
146
+ }
147
+ return () => {
148
+ t.current && (t.current = null);
149
+ };
150
+ }
151
+ }, [s, r]), r ? /* @__PURE__ */ p.createElement("div", { ref: e, style: n.style }) : /* @__PURE__ */ p.createElement("div", { ref: e, style: n.style });
96
152
  };
97
153
  export {
98
- b as HKEmbed,
99
- U as HKReactEmbed
154
+ O as HKEmbed,
155
+ x as HKReactEmbed
100
156
  };
package/package.json CHANGED
@@ -1,12 +1,10 @@
1
1
  {
2
2
  "name": "@homekynd/hk-embed-sdk",
3
3
  "private": false,
4
- "version": "0.0.4",
4
+ "version": "0.0.6",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
7
7
  "module": "dist/index.js",
8
- "unpkg": "dist/hk-embed.iife.js",
9
- "jsdelivr": "dist/hk-embed.iife.js",
10
8
  "types": "dist/index.d.ts",
11
9
  "exports": {
12
10
  ".": {
@@ -36,17 +34,17 @@
36
34
  "**/*": "prettier --write --ignore-unknown"
37
35
  },
38
36
  "peerDependencies": {
39
- "react": "^17.0.0 || ^18.0.0 || ^19.0.0",
40
- "react-dom": "^17.0.0 || ^18.0.0 || ^19.0.0"
37
+ "react": ">=16.8.0",
38
+ "react-dom": ">=16.8.0"
41
39
  },
42
40
  "devDependencies": {
43
41
  "vite-plugin-dts": "^4.5.4",
44
- "react": "^19.1.1",
45
- "react-dom": "^19.1.1",
42
+ "react": "^18.3.1",
43
+ "react-dom": "^18.3.1",
46
44
  "@eslint/js": "^9.33.0",
47
45
  "@types/node": "^24.3.0",
48
- "@types/react": "^19.1.10",
49
- "@types/react-dom": "^19.1.7",
46
+ "@types/react": "^18.3.17",
47
+ "@types/react-dom": "^18.3.0",
50
48
  "@vitejs/plugin-react": "^5.0.0",
51
49
  "eslint": "^9.33.0",
52
50
  "eslint-plugin-react-hooks": "^5.2.0",
@@ -1 +0,0 @@
1
- var HKEmbed=(function(o,h){"use strict";const n="http://localhost:3000";async function p(s,e){try{const t=await fetch(`${n}/api/v1/company/generate-token`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({api_secret:s,id:e})}),a=await t.json();if(t.ok)return a.token;console.error("Error fetching token: please confirm your API Secret and Client ID",a)}catch(t){console.error("Fetch error:",t)}}const w={root:"/company",renders:"/renders",spaces:"/spaces"};class g{container;iframe;currentToken;created=!1;constructor(e){const{container:t}=e;if(!t)throw new Error("Container element is required");this.container=t,this.create(e)}async create(e){if(this.created)return;const{clientId:t,apiKey:a,path:d="root",width:i="100%",height:u="100%",enablePathSync:R=!0}=e,l=new URL(window.location.href),c=l.searchParams.get("ifpath")||w[d],b=n.endsWith("/")?n:n+"/",E=c.startsWith("/")?c.substring(1):c,m=new URL(E,b),f=await p(a,t);this.currentToken=f,f&&m.searchParams.set("token",f);const r=document.createElement("iframe");return r.src=m.toString(),r.style.border="0",r.style.width=isNaN(Number(i))?i:`${i}px`,r.style.height=isNaN(Number(u))?u:`${u}px`,console.log("applying user styles/sizing"),this.iframe=r,r.onload=()=>{this.currentToken&&this.sendMessage({type:"SET_TOKEN",token:this.currentToken})},this.container.innerHTML="",this.container.appendChild(r),R&&(l.searchParams.set("ifpath",c),window.history.replaceState({},"",l.toString())),this.setupMessageHandling(),this.created=!0,{sendMessage:this.sendMessage.bind(this),onMessage:this.onMessage.bind(this)}}setupMessageHandling(){window.addEventListener("message",e=>{e.data?.type==="ROUTE_CHANGE"&&this.onRouteChange(e.data.path)})}onRouteChange(e){this.inputParentRoute(e),this.inputIframeRoute(e)}inputParentRoute(e){const t=new URL(window.location.href);t.searchParams.set("ifpath",e),window.history.replaceState({},"",t.toString())}inputIframeRoute(e){if(!this.iframe)return;const t=new URL(this.iframe.src),a=n.endsWith("/")?n:n+"/",d=e.startsWith("/")?e.substring(1):e,i=new URL(d,a);t.pathname!==i.pathname&&(this.iframe.src=i.toString())}sendMessage(e){if(this.iframe?.contentWindow){const t=new URL(n).origin;this.iframe.contentWindow.postMessage(e,t)}}onMessage(e){window.addEventListener("message",t=>{e(t.data)})}}const y=s=>{const e=h.useRef(null),t=h.useRef(null);return h.useLayoutEffect(()=>(e.current&&!t.current&&(t.current=new g({...s,container:e.current})),()=>{t.current=null}),[s]),React.createElement("div",{ref:e,style:s.style})};return o.HKEmbed=g,o.HKReactEmbed=y,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"}),o})({},React);
@@ -1 +0,0 @@
1
- (function(n,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],r):(n=typeof globalThis<"u"?globalThis:n||self,r(n.HKEmbed={},n.React))})(this,(function(n,r){"use strict";const s="http://localhost:3000";async function g(a,e){try{const t=await fetch(`${s}/api/v1/company/generate-token`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({api_secret:a,id:e})}),o=await t.json();if(t.ok)return o.token;console.error("Error fetching token: please confirm your API Secret and Client ID",o)}catch(t){console.error("Fetch error:",t)}}const w={root:"/company",renders:"/renders",spaces:"/spaces"};class m{container;iframe;currentToken;created=!1;constructor(e){const{container:t}=e;if(!t)throw new Error("Container element is required");this.container=t,this.create(e)}async create(e){if(this.created)return;const{clientId:t,apiKey:o,path:d="root",width:c="100%",height:u="100%",enablePathSync:R=!0}=e,f=new URL(window.location.href),h=f.searchParams.get("ifpath")||w[d],b=s.endsWith("/")?s:s+"/",E=h.startsWith("/")?h.substring(1):h,p=new URL(E,b),l=await g(o,t);this.currentToken=l,l&&p.searchParams.set("token",l);const i=document.createElement("iframe");return i.src=p.toString(),i.style.border="0",i.style.width=isNaN(Number(c))?c:`${c}px`,i.style.height=isNaN(Number(u))?u:`${u}px`,console.log("applying user styles/sizing"),this.iframe=i,i.onload=()=>{this.currentToken&&this.sendMessage({type:"SET_TOKEN",token:this.currentToken})},this.container.innerHTML="",this.container.appendChild(i),R&&(f.searchParams.set("ifpath",h),window.history.replaceState({},"",f.toString())),this.setupMessageHandling(),this.created=!0,{sendMessage:this.sendMessage.bind(this),onMessage:this.onMessage.bind(this)}}setupMessageHandling(){window.addEventListener("message",e=>{e.data?.type==="ROUTE_CHANGE"&&this.onRouteChange(e.data.path)})}onRouteChange(e){this.inputParentRoute(e),this.inputIframeRoute(e)}inputParentRoute(e){const t=new URL(window.location.href);t.searchParams.set("ifpath",e),window.history.replaceState({},"",t.toString())}inputIframeRoute(e){if(!this.iframe)return;const t=new URL(this.iframe.src),o=s.endsWith("/")?s:s+"/",d=e.startsWith("/")?e.substring(1):e,c=new URL(d,o);t.pathname!==c.pathname&&(this.iframe.src=c.toString())}sendMessage(e){if(this.iframe?.contentWindow){const t=new URL(s).origin;this.iframe.contentWindow.postMessage(e,t)}}onMessage(e){window.addEventListener("message",t=>{e(t.data)})}}const y=a=>{const e=r.useRef(null),t=r.useRef(null);return r.useLayoutEffect(()=>(e.current&&!t.current&&(t.current=new m({...a,container:e.current})),()=>{t.current=null}),[a]),React.createElement("div",{ref:e,style:a.style})};n.HKEmbed=m,n.HKReactEmbed=y,Object.defineProperty(n,Symbol.toStringTag,{value:"Module"})}));