@picked/client 0.0.1-dev.1756875690387 → 0.0.1-dev.1762908210565

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.
Files changed (107) hide show
  1. package/dist/cjs/index.js +1 -1
  2. package/dist/cjs/plugins/create-experience/index.js +1 -1
  3. package/dist/cjs/plugins/experience-browser-storage/index.js +1 -0
  4. package/dist/cjs/plugins/history-browser-storage/index.js +1 -0
  5. package/dist/cjs/plugins/responses-browser-storage/index.js +1 -0
  6. package/dist/cjs/plugins/{responses-indexeddb-plugin → responses-indexeddb}/index.js +1 -1
  7. package/dist/cjs/plugins/shopify/index.js +1 -1
  8. package/dist/cjs/plugins/single-page-app/index.js +1 -1
  9. package/dist/cjs/plugins/web-components/index.js +1 -0
  10. package/dist/cjs/plugins/window-object/index.js +1 -1
  11. package/dist/cjs/server/index.js +1 -1
  12. package/dist/esm/index.js +555 -443
  13. package/dist/esm/plugins/create-experience/index.js +172 -103
  14. package/dist/esm/plugins/experience-browser-storage/index.js +39 -0
  15. package/dist/esm/plugins/{history-browserstorage-plugin → history-browser-storage}/index.js +2 -2
  16. package/dist/esm/plugins/responses-browser-storage/index.js +41 -0
  17. package/dist/esm/plugins/{responses-indexeddb-plugin → responses-indexeddb}/index.js +24 -21
  18. package/dist/esm/plugins/shopify/index.js +38 -28
  19. package/dist/esm/plugins/single-page-app/index.js +3 -3
  20. package/dist/esm/plugins/web-components/index.js +21 -0
  21. package/dist/esm/plugins/window-object/index.js +1 -1
  22. package/dist/esm/server/index.js +1 -1
  23. package/dist/experience-instance-CF6m7G83.cjs +1 -0
  24. package/dist/experience-instance-CKru5var.js +781 -0
  25. package/dist/storage-Cb_71y48.js +94 -0
  26. package/dist/storage-DuRlyFaY.cjs +1 -0
  27. package/dist/{supports-BvrzQAVk.js → supports-BjhuLJ8z.js} +27 -11
  28. package/dist/supports-YvpQZxbh.cjs +1 -0
  29. package/dist/types/client.d.ts +26 -0
  30. package/dist/types/client.d.ts.map +1 -1
  31. package/dist/types/entities/action/action.d.ts +15 -0
  32. package/dist/types/entities/action/action.d.ts.map +1 -0
  33. package/dist/types/entities/experience/experience.d.ts +19 -6
  34. package/dist/types/entities/experience/experience.d.ts.map +1 -1
  35. package/dist/types/entities/experience-instance/experience-instance.d.ts +13 -10
  36. package/dist/types/entities/experience-instance/experience-instance.d.ts.map +1 -1
  37. package/dist/types/entities/feature/feature.d.ts +5 -2
  38. package/dist/types/entities/feature/feature.d.ts.map +1 -1
  39. package/dist/types/entities/field/field.d.ts +27 -19
  40. package/dist/types/entities/field/field.d.ts.map +1 -1
  41. package/dist/types/entities/history/history.d.ts.map +1 -1
  42. package/dist/types/entities/predicate/predicate.d.ts +1 -1
  43. package/dist/types/entities/predicate/predicate.d.ts.map +1 -1
  44. package/dist/types/entities/response/response.d.ts +8 -0
  45. package/dist/types/entities/response/response.d.ts.map +1 -1
  46. package/dist/types/exports.d.ts +2 -0
  47. package/dist/types/exports.d.ts.map +1 -1
  48. package/dist/types/picked.d.ts +28 -10
  49. package/dist/types/picked.d.ts.map +1 -1
  50. package/dist/types/plugins/create-experience/create-experience.d.ts +48 -13
  51. package/dist/types/plugins/create-experience/create-experience.d.ts.map +1 -1
  52. package/dist/types/plugins/experience-browser-storage/index.d.ts.map +1 -0
  53. package/dist/types/plugins/experience-browser-storage/plugin.d.ts.map +1 -0
  54. package/dist/types/plugins/history-browser-storage/index.d.ts.map +1 -0
  55. package/dist/types/plugins/history-browser-storage/plugin.d.ts.map +1 -0
  56. package/dist/types/plugins/responses-browser-storage/index.d.ts.map +1 -0
  57. package/dist/types/plugins/responses-browser-storage/plugin.d.ts.map +1 -0
  58. package/dist/types/plugins/responses-indexeddb/index.d.ts.map +1 -0
  59. package/dist/types/plugins/responses-indexeddb/plugin.d.ts.map +1 -0
  60. package/dist/types/plugins/shopify/plugin.d.ts.map +1 -1
  61. package/dist/types/plugins/shopify/utils.d.ts +21 -0
  62. package/dist/types/plugins/shopify/utils.d.ts.map +1 -0
  63. package/dist/types/plugins/web-components/index.d.ts +2 -0
  64. package/dist/types/plugins/web-components/index.d.ts.map +1 -0
  65. package/dist/types/plugins/web-components/plugin.d.ts +3 -0
  66. package/dist/types/plugins/web-components/plugin.d.ts.map +1 -0
  67. package/dist/types/utils/dom.d.ts +5 -5
  68. package/dist/types/utils/dom.d.ts.map +1 -1
  69. package/dist/types/utils/events.d.ts +29 -24
  70. package/dist/types/utils/events.d.ts.map +1 -1
  71. package/dist/types/utils/get-step-fields.d.ts +4 -0
  72. package/dist/types/utils/get-step-fields.d.ts.map +1 -0
  73. package/dist/types/utils/nodes.d.ts +2 -1
  74. package/dist/types/utils/nodes.d.ts.map +1 -1
  75. package/dist/types/utils/storage.d.ts +3 -0
  76. package/dist/types/utils/storage.d.ts.map +1 -1
  77. package/dist/types/utils/supports.d.ts +2 -0
  78. package/dist/types/utils/supports.d.ts.map +1 -1
  79. package/dist/types/utils/user-session.d.ts +5 -0
  80. package/dist/types/utils/user-session.d.ts.map +1 -0
  81. package/package.json +32 -26
  82. package/dist/cjs/plugins/experience-browserstorage-plugin/index.js +0 -1
  83. package/dist/cjs/plugins/history-browserstorage-plugin/index.js +0 -1
  84. package/dist/cjs/plugins/responses-browserstorage-plugin/index.js +0 -1
  85. package/dist/esm/plugins/experience-browserstorage-plugin/index.js +0 -38
  86. package/dist/esm/plugins/responses-browserstorage-plugin/index.js +0 -36
  87. package/dist/experience-instance-6ZKZS7dF.cjs +0 -1
  88. package/dist/experience-instance-BA0EXYg5.js +0 -712
  89. package/dist/storage-BPJwmlva.cjs +0 -1
  90. package/dist/storage-D87xFySf.js +0 -85
  91. package/dist/supports-C0y3-V5V.cjs +0 -1
  92. package/dist/types/plugins/experience-browserstorage-plugin/index.d.ts.map +0 -1
  93. package/dist/types/plugins/experience-browserstorage-plugin/plugin.d.ts.map +0 -1
  94. package/dist/types/plugins/history-browserstorage-plugin/index.d.ts.map +0 -1
  95. package/dist/types/plugins/history-browserstorage-plugin/plugin.d.ts.map +0 -1
  96. package/dist/types/plugins/responses-browserstorage-plugin/index.d.ts.map +0 -1
  97. package/dist/types/plugins/responses-browserstorage-plugin/plugin.d.ts.map +0 -1
  98. package/dist/types/plugins/responses-indexeddb-plugin/index.d.ts.map +0 -1
  99. package/dist/types/plugins/responses-indexeddb-plugin/plugin.d.ts.map +0 -1
  100. /package/dist/types/plugins/{experience-browserstorage-plugin → experience-browser-storage}/index.d.ts +0 -0
  101. /package/dist/types/plugins/{experience-browserstorage-plugin → experience-browser-storage}/plugin.d.ts +0 -0
  102. /package/dist/types/plugins/{history-browserstorage-plugin → history-browser-storage}/index.d.ts +0 -0
  103. /package/dist/types/plugins/{history-browserstorage-plugin → history-browser-storage}/plugin.d.ts +0 -0
  104. /package/dist/types/plugins/{responses-browserstorage-plugin → responses-browser-storage}/index.d.ts +0 -0
  105. /package/dist/types/plugins/{responses-browserstorage-plugin → responses-browser-storage}/plugin.d.ts +0 -0
  106. /package/dist/types/plugins/{responses-indexeddb-plugin → responses-indexeddb}/index.d.ts +0 -0
  107. /package/dist/types/plugins/{responses-indexeddb-plugin → responses-indexeddb}/plugin.d.ts +0 -0
@@ -1,6 +1,6 @@
1
- import { createEffect as u, sample as d } from "effector";
1
+ import { createEffect as d, sample as p } from "effector";
2
2
  const x = "picked";
3
- async function p(r) {
3
+ async function m(r) {
4
4
  const { storeName: o, version: a = 1, keyPath: n = "id" } = r;
5
5
  return new Promise((i, t) => {
6
6
  const s = indexedDB.open(x, a);
@@ -49,48 +49,51 @@ async function S(r, o) {
49
49
  };
50
50
  });
51
51
  }
52
- const l = "responses", m = { storeName: l, keyPath: "fieldId" }, I = () => ({
52
+ const u = "responses", w = { storeName: u, keyPath: "fieldId" }, I = () => ({
53
53
  name: "responses-indexdb-plugin",
54
54
  setup: (r) => {
55
- const o = u(async () => {
56
- const t = await p(m), e = (await g(t, l)).reduce(
57
- (c, { fieldId: w, value: f }) => (c[w] = f, c),
55
+ const o = d(async () => {
56
+ const t = await m(w), e = (await g(t, u)).reduce(
57
+ (c, { fieldId: l, value: f }) => (c[l] = f, c),
58
58
  {}
59
59
  );
60
60
  await r.responses.commit(e);
61
- }), a = u(
61
+ }), a = d(
62
62
  async (t) => {
63
63
  t.forEach((s) => {
64
- p(m).then((e) => {
65
- y(e, l, s);
64
+ m(w).then((e) => {
65
+ y(e, u, s);
66
66
  }).catch((e) => {
67
67
  console.error("Failed to store response in IndexedDB:", e);
68
68
  });
69
69
  });
70
70
  }
71
- ), n = u(async () => {
72
- const t = await p(m);
73
- await S(t, l);
74
- }), i = u(async (t) => {
75
- const s = await p(m);
76
- await b(s, l, t);
71
+ ), n = d(async () => {
72
+ const t = await m(w);
73
+ await S(t, u);
74
+ }), i = d(async (t) => {
75
+ const s = await m(w);
76
+ await b(s, u, t);
77
77
  });
78
- d({
78
+ p({
79
79
  source: r.eventBus,
80
80
  filter: (t) => t.type === "initialized",
81
81
  target: o
82
- }), d({
82
+ }), p({
83
83
  clock: r.responses.listStore,
84
84
  source: { responses: r.responses.listStore, fields: r.fields.listStore },
85
85
  fn: ({ responses: t, fields: s }) => {
86
- const e = s.filter((c) => !c.policies.doNotStoreValue);
87
- return t.filter((c) => e.some((w) => w.id === c.fieldId));
86
+ const e = s.filter((c) => {
87
+ var l;
88
+ return !((l = c.policies) != null && l.doNotStoreValue);
89
+ });
90
+ return t.filter((c) => e.some((l) => l.id === c.fieldId));
88
91
  },
89
92
  target: a
90
- }), d({
93
+ }), p({
91
94
  clock: r.responses.clearAll,
92
95
  target: n
93
- }), d({
96
+ }), p({
94
97
  clock: r.responses.clear,
95
98
  target: i
96
99
  });
@@ -1,3 +1,4 @@
1
+ import { a as p } from "../../../supports-BjhuLJ8z.js";
1
2
  const a = {
2
3
  homepage: /^\/$/,
3
4
  productPage: /(?:^|\/)products\/(?<productHandle>[^/]+)\/?$/,
@@ -11,49 +12,58 @@ const a = {
11
12
  accountWildcard: /^\/account\/.+/,
12
13
  accountLogin: /^\/account\/login(?:\/|$)/,
13
14
  accountRegister: /^\/account\/register(?:\/|$)/
14
- }, n = /^\/collections\/(?<collectionHandle>[^/]+)(?:\/|$)/, c = (e, t) => t ? !!e.exec(t.pathname) : !1, o = (e, t) => {
15
- if (t) {
16
- const p = e.exec(t.pathname);
17
- if (p)
18
- return p[1];
15
+ }, n = /^\/collections\/(?<collectionHandle>[^/]+)(?:\/|$)/, t = (e, o) => o ? !!e.exec(o.pathname) : !1, i = (e, o) => {
16
+ if (o) {
17
+ const c = e.exec(o.pathname);
18
+ if (c)
19
+ return c[1];
19
20
  }
20
- }, g = {
21
+ }, s = {
21
22
  // Pages
22
- "is-page": ({ location: e }) => c(a.page, e),
23
- "get-page-handle": ({ location: e }) => o(a.page, e),
23
+ "is-page": ({ location: e }) => t(a.page, e),
24
+ "get-page-handle": ({ location: e }) => i(a.page, e),
24
25
  // Products
25
- "is-product-page": ({ location: e }) => c(a.productPage, e),
26
- "get-product-handle": ({ location: e }) => o(a.productPage, e),
26
+ "is-product-page": ({ location: e }) => t(a.productPage, e),
27
+ "get-product-handle": ({ location: e }) => i(a.productPage, e),
27
28
  // Collections
28
- "is-collection-page": ({ location: e }) => c(a.collection, e),
29
- "get-collection-handle": ({ location: e }) => o(n, e),
29
+ "is-collection-page": ({ location: e }) => t(a.collection, e),
30
+ "get-collection-handle": ({ location: e }) => i(n, e),
30
31
  // Blogs
31
- "is-blog-page": ({ location: e }) => c(a.blog, e),
32
- "get-blog-handle": ({ location: e }) => o(a.blog, e),
32
+ "is-blog-page": ({ location: e }) => t(a.blog, e),
33
+ "get-blog-handle": ({ location: e }) => i(a.blog, e),
33
34
  // Blog Articles
34
- "is-article-page": ({ location: e }) => c(a.article, e),
35
- "get-article-handle": ({ location: e }) => o(a.article, e),
35
+ "is-article-page": ({ location: e }) => t(a.article, e),
36
+ "get-article-handle": ({ location: e }) => i(a.article, e),
36
37
  // Apps
37
- "is-app-proxy-page": ({ location: e }) => c(a.appProxy, e),
38
- "get-app-proxy-handle": ({ location: e }) => o(a.appProxy, e),
38
+ "is-app-proxy-page": ({ location: e }) => t(a.appProxy, e),
39
+ "get-app-proxy-handle": ({ location: e }) => i(a.appProxy, e),
39
40
  // Account
40
- "is-account-page": ({ location: e }) => c(a.accountWildcard, e),
41
- "is-login-page": ({ location: e }) => c(a.accountLogin, e),
42
- "is-register-page": ({ location: e }) => c(a.accountRegister, e),
41
+ "is-account-page": ({ location: e }) => t(a.accountWildcard, e),
42
+ "is-login-page": ({ location: e }) => t(a.accountLogin, e),
43
+ "is-register-page": ({ location: e }) => t(a.accountRegister, e),
43
44
  // Cart
44
- "is-cart-page": ({ location: e }) => c(a.cart, e),
45
+ "is-cart-page": ({ location: e }) => t(a.cart, e),
45
46
  // Checkout
46
- "is-checkout-page": ({ location: e }) => c(a.checkout, e),
47
+ "is-checkout-page": ({ location: e }) => t(a.checkout, e),
47
48
  // Homepage
48
- "is-homepage": ({ location: e }) => c(a.homepage, e)
49
- }, r = () => ({
49
+ "is-homepage": ({ location: e }) => t(a.homepage, e)
50
+ };
51
+ function r(e) {
52
+ var o, c;
53
+ return typeof ((c = (o = e.Shopify) == null ? void 0 : o.analytics) == null ? void 0 : c.publish) == "function";
54
+ }
55
+ const g = () => ({
50
56
  name: "shopify",
51
57
  setup: (e) => {
52
- Object.entries(g).forEach(([t, p]) => {
53
- e.registerPredicate(`shopify-${t}`, p);
58
+ Object.entries(s).forEach(([o, c]) => {
59
+ e.registerPredicate(`shopify-${o}`, c);
60
+ }), p() && e.eventBus.watch((o) => {
61
+ r(window) && o.type === "session" && window.Shopify.analytics.publish("picked:session", {
62
+ id: o.id
63
+ });
54
64
  });
55
65
  }
56
66
  });
57
67
  export {
58
- r as shopifyPlugin
68
+ g as shopifyPlugin
59
69
  };
@@ -1,8 +1,8 @@
1
- import { a as f, G as c, d as m } from "../../../supports-BvrzQAVk.js";
1
+ import { a as f, G as c, f as m } from "../../../supports-BjhuLJ8z.js";
2
2
  import { p as a } from "../../../object-JwZ58NOH.js";
3
3
  const o = c;
4
4
  let s;
5
- const y = (r) => ({
5
+ const d = (r) => ({
6
6
  name: "single-page-app",
7
7
  setup: (n) => {
8
8
  r.instrumentHistory && f() && h(() => {
@@ -33,5 +33,5 @@ function h(r) {
33
33
  a(o.history, "pushState", n), a(o.history, "replaceState", n);
34
34
  }
35
35
  export {
36
- y as singlePageAppPlugin
36
+ d as singlePageAppPlugin
37
37
  };
@@ -0,0 +1,21 @@
1
+ import { a as s, k as i } from "../../../supports-BjhuLJ8z.js";
2
+ const p = () => ({
3
+ name: "web-components",
4
+ setup: (e) => {
5
+ if (!s() || !i())
6
+ return;
7
+ const n = "picked-root";
8
+ if (window.customElements.get(n))
9
+ return;
10
+ class o extends HTMLElement {
11
+ connectedCallback() {
12
+ const t = this.getAttribute("experience-id");
13
+ e.isReady && t && e.launchExperienceById(t);
14
+ }
15
+ }
16
+ window.customElements.define(n, o);
17
+ }
18
+ });
19
+ export {
20
+ p as webComponentsPlugin
21
+ };
@@ -1,4 +1,4 @@
1
- import { a as i } from "../../../supports-BvrzQAVk.js";
1
+ import { a as i } from "../../../supports-BjhuLJ8z.js";
2
2
  const t = () => ({
3
3
  name: "window",
4
4
  setup: (o) => {
@@ -1,5 +1,5 @@
1
1
  import { createEvent as i, createStore as v, createEffect as C, sample as n, attach as S } from "effector";
2
- import { h as F } from "../../experience-instance-BA0EXYg5.js";
2
+ import { h as F } from "../../experience-instance-CKru5var.js";
3
3
  function R() {
4
4
  let c, p;
5
5
  return {
@@ -0,0 +1 @@
1
+ "use strict";const s=require("effector"),G=require("@withease/factories"),H=require("./supports-YvpQZxbh.cjs"),N=require("./logger-BsmHUUw1.cjs"),mt=require("./object-BbFTsGh3.cjs");function ht(t){return typeof t=="number"&&!isNaN(t)}function R(t){return typeof t=="string"}function E(t){return Array.isArray(t)}function rt(t){return t instanceof Promise}function tt(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)&&Object.keys(t).length===1}function m(t){if(ht(t))return t;const e=parseFloat(`${t}`);return isNaN(e)?0:e}function T(t){return`${t}`}const St={"==":(t,e)=>t==e,"===":(t,e)=>t===e,"!=":(t,e)=>t!=e,"!==":(t,e)=>t!==e,">":(t,e)=>m(t)>m(e),">=":(t,e)=>m(t)>=m(e),"<":(t,e,r)=>{const n=m(t),a=m(e);if(r===void 0)return n<a;const c=m(r);return n<a&&a<c},"<=":(t,e,r)=>{const n=m(t),a=m(e);if(r===void 0)return n<=a;const c=m(r);return n<=a&&a<=c},"!!":async t=>await B(t),"!":async t=>!await B(t),"%":(t,e)=>m(t)%m(e),log:t=>(console.log(t),t),in:(t,e)=>e?R(e)?e.indexOf(T(t))!==-1:E(e)?e.includes(t):!1:!1,cat:(...t)=>t.map(T).join(""),substr:(t,e,r)=>{const n=T(t),a=m(e);if(r===void 0)return n.substr(a);const c=m(r);if(c<0){const o=n.substr(a);return o.substr(0,o.length+c)}return n.substr(a,c)},"+":(...t)=>t.reduce((e,r)=>m(e)+m(r),0),"*":(...t)=>t.reduce((e,r)=>m(e)*m(r),1),"-":(t,e)=>{const r=m(t);return e===void 0?-r:r-m(e)},"/":(t,e)=>m(t)/m(e),min:(...t)=>Math.min(...t.map(m)),max:(...t)=>Math.max(...t.map(m)),merge:(...t)=>t.reduce((e,r)=>E(r)?e.concat(r):e.concat([r]),[]),var(t,e){const r=arguments.length>1?e:null;if(t===""||t==="."||t===null||t===void 0)return this;if(typeof t=="number"&&Array.isArray(this))return t>=0&&t<this.length?this[t]:r;const n=T(t);if(n===""||n===".")return this;const a=n.split(".");let c=this;for(const o of a){if(c==null)return r;if(Array.isArray(c)){const u=parseInt(o,10);isNaN(u)?c=c[o]:c=c[u]}else c=c[o]}return c!==void 0?c:r},async missing(...t){const e=E(t[0])?t[0]:t,r=[];for(const n of e){const a=await g({var:n},this);(a===null||a==="")&&r.push(`${n}`)}return r},async missing_some(t,e){const r=await g({missing:e},this);if(!E(r)||!E(e))return[];const n=r.filter(R);return e.filter(R).length-n.length>=m(t)?[]:n},invoke(t){return typeof t!="function"?null:t()},regexp_matches(t,e){let r=t,n="";if(E(t)){const[c,o]=t;r=c,n=o}return!R(r)||!R(n)?!1:new RegExp(r,n).test(T(e))},throw(t){throw new Error(T(t))}};async function g(t,e){if(!t)return t;if(rt(t))return g(await t,e);if(E(t))return Promise.all(t.map(o=>g(o,e)));if(!tt(t))return t;const r=yt(t);let n=r?t[r]??[]:[];switch(E(n)||(n=[n]),r){case"if":case"?:":for(let o=0;o<n.length-1;o+=2)if(await B(await g(n[o],e)))return g(n[o+1],e);return n.length%2===1?g(n[n.length-1],e):null;case"and":{let o=null;for(const u of n)if(o=await g(u,e),!await B(o))return o;return o}case"or":{let o=null;for(const u of n)if(o=await g(u,e),await B(o))return o;return o}case"map":{const o=await g(n[0],e);return E(o)?await Promise.all(o.map(u=>g(n[1],u))):[]}case"filter":{const o=await g(n[0],e);return E(o)?(await Promise.all(o.map(async p=>{const y=await B(await g(n[1],p));return{item:p,shouldInclude:y}}))).filter(({shouldInclude:p})=>p).map(({item:p})=>p):[]}case"reduce":{const o=await g(n[0],e);if(!E(o))return n.length>2?await g(n[2],e):null;const u=n[1];let y=n.length>2?await g(n[2],e):null;for(const k of o)y=await g(u,{current:k,accumulator:y});return y}case"all":{const o=await g(n[0],e);if(!E(o)||o.length===0)return!1;for(const u of o)if(!await B(await g(n[1],u)))return!1;return!0}case"some":{const o=await g(n[0],e);if(!E(o))return!1;for(const u of o)if(await B(await g(n[1],u)))return!0;return!1}case"none":{const o=await g(n[0],e);if(!E(o))return!0;for(const u of o)if(await B(await g(n[1],u)))return!1;return!0}case"catch":try{return await g(n[0],e)}catch(o){return tt(o)?await g(o,e):n[1]?await g(n[1],o):o instanceof Error?o.message:o}}const a=await Promise.all(n.map(o=>g(o,e))),c=r?St[r]:void 0;if(!c)throw new Error(`Unrecognized operation ${r}`);return c.apply(e,a)}async function B(t){return rt(t)?B(await t):!(Array.isArray(t)&&t.length===0)&&!!t}function yt(t){return Object.keys(t)[0]}function ot(t){return!mt.isEmpty(t)}async function z(t,e,r){const n=t.getStateSnapshot(),a=t.predicates.listStore.getState().reduce((u,p)=>({...u,[p.name]:()=>p.predicate(n)}),{}),c=t.features.listStore.getState().reduce((u,p)=>({...u,[p.id]:async()=>{const{bucket:y}=await p.getBucket();return y}}),{}),o={...r,responses:t.responses.getAllStore.getState(),location:typeof n.location=="object"?{hash:n.location.hash,host:n.location.host,hostname:n.location.hostname,href:n.location.href,origin:n.location.origin,pathname:n.location.pathname,port:n.location.port,protocol:n.location.protocol,search:n.location.search}:void 0,predicates:a,features:c};return await g(e,o)}function wt(t){return!H.supportsWindow()||!H.supportsDocument()?[]:Array.from(window.document.querySelectorAll(t)).filter(e=>e instanceof HTMLElement)}function Et(t){if(!H.supportsShadowRoot())throw new Error("Shadow DOM is not supported in this environment");return t.attachShadow({mode:"closed"})}function Nt(){return new Promise((t,e)=>{if(!H.supportsDocument()){e();return}document.readyState!=="loading"?t():document.addEventListener("readystatechange",()=>t(),{once:!0})})}function It(t,e){const r=new MutationObserver(n=>{document.contains(t)||(r.disconnect(),e())});r.observe(document.body,{childList:!0,subtree:!0})}const j="picked-root",q="picked-target",xt="picked-root";function kt(t,e){return[...t,{selector:`${xt}[experience-id="${e}"]`,placement:"replace"}].flatMap(n=>{const a=wt(n.selector).filter(c=>!At(c,e)&&!it(c,e));return{...n,elements:a}})}function vt(t,e){return t.flatMap(r=>r.elements.map(n=>Ot(n,r.placement,e)))}function bt(t,e){t.classList.add(q),t.classList.add(`${q}-${e}`)}function At(t,e){return e?t.classList.contains(`${q}-${e}`):t.classList.contains(`${q}`)}function it(t,e){return e?t.classList.contains(`${j}-${e}`):t.classList.contains(j)}function Bt(t){const e=document.createElement("div");return e.style.display="block",e.classList.add(j),e.classList.add(`${j}-${t}`),e}function Ot(t,e,r){let n;const a=Bt(r);if(t instanceof Document)n=t.body.appendChild(a);else{switch(e){case"replace":t.replaceWith(a);break;case"before":t.before(a);break;case"after":t.after(a);break;case"prepend":t.prepend(a);break;default:t.append(a);break}n=a}return n}function Ft(t){return t.type==="conditional"}function L(t){return t.type==="step"}function $t(t){return t.type==="experience"}function et(t){return t.type==="origin"}function nt(t){return t.type==="action"}const st=(t,e,r,n,a=new Set)=>a.has(r.id)?[]:(a.add(r.id),L(r)&&!n?[r]:e.filter(o=>o.sourceNodeId===r.id).flatMap(o=>{const u=t.find(p=>p.id===o.destinationNodeId);return u?st(t,e,u,!1,a):[]})),_t=(t,e,r)=>st(t,e,r,!0,new Set),at=(t,e,r,n,a=new Set)=>{if(a.has(r.id))return[-1,-1];a.add(r.id);const c=e.filter(p=>p.sourceNodeId===r.id);if(c.length===0)return[0,0];let o=1/0,u=-1/0;for(const p of c){const y=t.find(M=>M.id===p.destinationNodeId);if(!y)continue;const[k,O]=at(t,e,y,!1,new Set(a));k!==-1&&(o=Math.min(o,k+1),u=Math.max(u,O+1))}return o===1/0?[-1,-1]:[o,u]},Tt=(t,e,r)=>at(t,e,r,!0,new Set),ct=(t,e,r,n=new Set)=>{if(n.has(r.id))return[-1,-1];if(n.add(r.id),r.type==="origin")return[0,0];const a=e.filter(u=>u.destinationNodeId===r.id);if(a.length===0)return[-1,-1];let c=1/0,o=-1/0;for(const u of a){const p=t.find(O=>O.id===u.sourceNodeId);if(!p)continue;const[y,k]=ct(t,e,p,new Set(n));y!==-1&&(c=Math.min(c,y+1),o=Math.max(o,k+1))}return c===1/0?[-1,-1]:[c,o]},Lt=(t,e,r)=>ct(t,e,r,new Set),ut=t=>t.find(r=>r.type==="origin")||null,W=(t,e,r)=>{if(!t)return ut(e);const n=r.find(c=>c.sourceNodeId===t.id);if(!n)return null;const a=e.find(c=>c.id===n.destinationNodeId);return a||null};async function Mt(t,e,r,n){const a=t?"true":"false",c=n.find(o=>o.sourceNodeHandle===a&&o.sourceNodeId===e);return r.find(o=>o.id===(c==null?void 0:c.destinationNodeId))}const X=s.createDomain("experience-instance"),Dt=G.createFactory(({client:t,experience:e,target:r})=>{const n=s.createEvent(),a=s.createEvent(),c=s.createEvent(),o=s.createEvent(),u=s.createEvent(),p=s.createEvent(),y=e.componentStore,k=X.store("transitioning"),O=t.history.entriesStore.map(i=>i.filter(l=>l.experienceId===e.id)),M=O.map(i=>i.filter(l=>L(l.node))),I=O.map(i=>{var l;return((l=i[i.length-1])==null?void 0:l.node)||null}),f=s.combine(e.treeStore,I,({steps:i},l)=>i.find(d=>l&&L(l)&&d.id===l.stepId)||null),h=s.combine(e.treeStore,I,({nodes:i,edges:l},d)=>d?_t(i,l,d):[]),b=s.combine(e.treeStore,I,({nodes:i,edges:l},d)=>d?Lt(i,l,d):[-1,-1]),F=s.combine(e.treeStore,I,({nodes:i,edges:l},d)=>d?Tt(i,l,d):[-1,-1]),$=e.configStore.getState().initializeOpenLogic,A=X.store($===!0),P=s.createApi(A,{open:()=>!0,close:()=>!1,toggle:i=>!i,set:(i,l)=>l}),lt=s.createEffect(async()=>{t.history.back({experienceId:e.id})}),dt=s.attach({source:e.treeStore,effect:async(i,l)=>{const d=i.nodes.find(w=>L(w)&&w.stepId===l);d&&t.history.push({experienceId:e.id,node:d})}}),J=s.attach({source:I,effect:i=>{}}),K=s.attach({source:e.treeStore,effect:async({nodes:i})=>ut(i)}),U=s.attach({source:e.treeStore,effect:async({nodes:i,edges:l},d)=>W(d,i,l)}),V=s.attach({source:e.treeStore,effect:async({nodes:i,edges:l,conditionals:d},w)=>{if(!w)return;const _=d.find(v=>v.id===w.conditionalId);if(!_)return;const x=w.id,S=await z(t,_.condition);return Mt(!!S,x,i,l)}}),Q=s.attach({source:e.treeStore,effect:async({nodes:i,edges:l},d)=>{if(!d||!nt(d))return;const w=d.action;if(!w){N.logger("warn",`Action node ${d.id} has no action name`);return}const _=t.actions.getByName(w).getState();if(!_){N.logger("warn",`Action '${w}' not registered on client`);const x=l.find(S=>S.sourceNodeId===d.id&&S.sourceNodeHandle==="false");return x?i.find(S=>S.id===x.destinationNodeId):null}if(typeof _.action!="function"){N.logger("warn",`Action '${w}' is not a function`);const x=l.find(S=>S.sourceNodeId===d.id&&S.sourceNodeHandle==="false");return x?i.find(S=>S.id===x.destinationNodeId):null}try{N.logger("info",`Executing action: ${w}`),await _.action();const x=l.find(v=>v.sourceNodeId===d.id&&v.sourceNodeHandle==="true");if(!x)return N.logger("warn",`No 'true' edge found for action node ${d.id}`),null;const S=i.find(v=>v.id===x.destinationNodeId);return N.logger("info",`Action '${w}' succeeded, moving to node ${S==null?void 0:S.id}`),S||null}catch(x){N.logger("warn",`Action '${w}' failed:`,x);const S=l.find(C=>C.sourceNodeId===d.id&&C.sourceNodeHandle==="false");if(!S)return N.logger("warn",`No 'false' edge found for action node ${d.id}`),null;const v=i.find(C=>C.id===S.destinationNodeId);return N.logger("info",`Action '${w}' failed, moving to node ${v==null?void 0:v.id}`),v||null}}}),pt=s.createEffect(i=>{if(i)return t.launchExperienceById(i.experienceId)}),Y=s.attach({source:[I,e.treeStore],effect:async([i,{nodes:l,edges:d}])=>W(i,l,d)}),D=s.attach({source:[I,e.treeStore],effect:async([i,{nodes:l,edges:d}])=>W(i,l,d)}),gt=s.createEffect(i=>{t.history.push({experienceId:e.id,node:i})}),Z=s.attach({source:e.configStore,effect:async({initializeOpenLogic:i})=>ot(i)?!!await z(t,i):i??!1});return s.split({source:I,match:i=>i?Ft(i)?"condition":L(i)?"step":$t(i)?"launchExperience":et(i)?"origin":nt(i)?"action":"other":"none",cases:{none:K,origin:U,condition:V,step:J,launchExperience:pt,action:Q,__:s.createEvent()}}),s.sample({clock:[V.doneData,U.doneData,K.doneData,D.doneData,Y.doneData,Q.doneData],filter:Boolean,target:gt}),s.sample({clock:a,target:D}),s.sample({clock:a,source:f,filter:Boolean,target:t.eventBus.prepend(i=>({type:"step_submit",step:i,experience:e}))}),s.sample({clock:D.done,source:f,filter:Boolean,target:t.eventBus.prepend(i=>({type:"step_submit_success",step:i,experience:e}))}),s.sample({clock:D.fail,source:f,filter:Boolean,target:t.eventBus.prepend(i=>({type:"step_submit_error",step:i,experience:e}))}),s.sample({clock:c,target:lt}),s.sample({clock:o,target:dt}),s.sample({source:s.combine([V.pending,U.pending,K.pending,D.pending]),fn:i=>i.some(Boolean)?"transitioning":"ready",target:k}),s.sample({clock:J.doneData,source:f,filter:Boolean,target:t.eventBus.prepend(i=>({type:"step_enter",step:i,experience:e}))}),s.sample({clock:p,target:Z}),s.sample({source:Z.doneData,fn:i=>!!i,target:A}),s.sample({source:I,clock:n,filter:i=>i?et(i):!0,target:Y}),s.sample({source:A,filter:i=>!!i,target:n}),s.sample({source:A,filter:Boolean,target:t.eventBus.prepend(()=>({type:"experience_open",experience:e}))}),s.sample({source:A,filter:i=>!i,target:t.eventBus.prepend(()=>({type:"experience_close",experience:e}))}),s.sample({clock:u,target:[p]}),u(),{id:Math.random().toString(36).substring(7),experienceId:e.id,configStore:e.configStore,target:r,componentStore:y,stateStore:k,isOpenStore:A,open:P.open,close:P.close,toggleOpen:P.toggle,setOpen:P.set,treeStore:e.treeStore,currentNodeStore:I,currentStepStore:f,nextReachableStepNodesStore:h,stepsToOriginStore:b,stepsToLeafStore:F,goToNextStep:a,goToPreviousStep:c,goToStepById:o,stepsHistoryStore:M}});function ft(t){return G.invoke(Dt,t)}const Rt=G.createFactory(({client:t})=>{const e=X.store({}),r=s.createEvent(),n=s.createEvent(),a=s.createEvent(),c=s.createApi(e,{register(f,h){const b=[...f[h.experienceId]??[]];return b.push(h),{...f,[h.experienceId]:b}},unregister(f,h){var $;const b=h.experienceId,F=($=f[b])==null?void 0:$.filter(A=>A!==h);return{...f,[b]:F??[]}}}),o=s.createEffect(({experience:f,target:h})=>ft({client:t,experience:f,target:h})),u=s.createEffect(f=>{c.register(f)}),p=s.createEffect(f=>{f.target&&It(f.target,()=>{a(f)})}),y=s.createEffect(f=>{c.unregister(f)}),k=s.createEffect(f=>{const h=f.componentStore.getState();if(!h){N.logger("warn","No app component registered. Skipping init.");return}const b=h.frameworkStore.getState();if(!b){N.logger("error",`No framework registered for component '${h.name}'. Skipping rendering.`);return}const F=f.target;if(!F){N.logger("error",`No target element registered for experience '${f.experienceId}'. Skipping rendering.`);return}const $=Et(F);try{b.render($,h.component,t,f)}catch(A){N.logger("error",A)}});s.sample({clock:r,target:o}),s.sample({clock:a,target:y}),s.sample({clock:o.doneData,target:[u,p,n]}),s.sample({clock:o.doneData,target:t.eventBus.prepend(f=>({type:"experience_initialized",experienceInstance:f}))}),s.sample({clock:n,target:k});function O(f,h){r({experience:f,target:h})}const M=e.map(f=>Object.values(f).flat());function I(f){return e.map(h=>h[f]||[],{skipVoid:!1})}return{spawn:O,getByExperienceId:I,listStore:M}});function Pt(t){return G.invoke(Rt,t)}exports.createAppHosts=vt;exports.createExperienceInstance=ft;exports.createExperienceInstanceIndex=Pt;exports.domInteractive=Nt;exports.evaluateRuleLogic=z;exports.getTargetElements=kt;exports.isPickedRoot=it;exports.isRulesLogic=ot;exports.isStepNode=L;exports.tagTargetElement=bt;