@picked/vite-plugin-picked 0.0.75 → 0.0.76-next.1

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/esm/index.js CHANGED
@@ -10,18 +10,25 @@ function p(e, t) {
10
10
  }
11
11
  //#endregion
12
12
  //#region src/launcher.ts
13
- var m;
14
- function h(e) {
15
- let t = JSON.stringify(e), n = e.length > 0 ? e.map((e) => `
13
+ var m, h = ["true", "false"], g = "false";
14
+ function _(e) {
15
+ let t = e.variants;
16
+ return !t || t.length === 0 ? h : t.map((e) => String(e.value));
17
+ }
18
+ function v(e) {
19
+ let t = _(e), n = Math.max(0, t.findIndex((e) => e !== g));
20
+ return t.map((e, t) => `<option value="${x(e)}"${t === n ? " selected" : ""}>${b(e)}</option>`).join("");
21
+ }
22
+ function y(e) {
23
+ let t = JSON.stringify(e).replaceAll("<", String.raw`\u003c`), n = e.length > 0 ? e.map((e) => `
16
24
  <div class="feature-row">
17
25
  <label>
18
- <input type="checkbox" data-feature-id="${_(e.id)}" checked>
19
- <span class="feature-name">${g(e.name)}</span>
20
- <span class="feature-id">${g(e.id)}</span>
26
+ <input type="checkbox" data-feature-id="${x(e.id)}" checked>
27
+ <span class="feature-name">${b(e.name)}</span>
28
+ <span class="feature-id">${b(e.id)}</span>
21
29
  </label>
22
- <select data-value-for="${_(e.id)}">
23
- <option value="true" selected>true</option>
24
- <option value="false">false</option>
30
+ <select data-value-for="${x(e.id)}">
31
+ ${v(e)}
25
32
  </select>
26
33
  </div>`).join("") : "<p class=\"text no-features\">No features configured for this project.</p>";
27
34
  return String.raw(m ||= p([
@@ -34,46 +41,46 @@ function h(e) {
34
41
  ";\n var STORAGE_KEY_URL = 'picked-launcher-url';\n var STORAGE_KEY_HISTORY = 'picked-launcher-history';\n var STORAGE_KEY_SELECTIONS = 'picked-launcher-selections';\n\n function getUrlInput() {\n return document.getElementById('url-input');\n }\n\n // URL history\n function getHistory() {\n try {\n var raw = localStorage.getItem(STORAGE_KEY_HISTORY);\n if (!raw) return [];\n var parsed = JSON.parse(raw);\n return Array.isArray(parsed) ? parsed : [];\n } catch (e) {\n return [];\n }\n }\n\n function saveHistory(history) {\n localStorage.setItem(STORAGE_KEY_HISTORY, JSON.stringify(history));\n }\n\n function addToHistory(url) {\n var history = getHistory().filter(function(h) { return h !== url; });\n history.unshift(url);\n if (history.length > 10) history = history.slice(0, 10);\n saveHistory(history);\n renderHistory();\n }\n\n function removeFromHistory(url) {\n var history = getHistory().filter(function(h) { return h !== url; });\n saveHistory(history);\n renderHistory();\n }\n\n function renderHistory() {\n var container = document.getElementById('url-history');\n if (!container) return;\n var history = getHistory();\n if (history.length === 0) {\n container.innerHTML = '';\n return;\n }\n container.innerHTML = history.map(function(url) {\n return '<div class=\"url-history-item\">' +\n '<button type=\"button\" class=\"url-link\" data-history-url=\"' + escapeAttr(url) + '\">' + escapeHtml(url) + '</button>' +\n '<button type=\"button\" class=\"url-delete\" data-history-delete=\"' + escapeAttr(url) + '\">x</button>' +\n '</div>';\n }).join('');\n }\n\n // Feature selection persistence\n function getSelections() {\n try {\n var raw = localStorage.getItem(STORAGE_KEY_SELECTIONS);\n if (!raw) return {};\n var parsed = JSON.parse(raw);\n return typeof parsed === 'object' && parsed !== null ? parsed : {};\n } catch (e) {\n return {};\n }\n }\n\n function saveSelections() {\n var selections = {};\n FEATURES.forEach(function(f) {\n var checkbox = document.querySelector('input[data-feature-id=\"' + f.id + '\"]');\n var select = document.querySelector('select[data-value-for=\"' + f.id + '\"]');\n if (checkbox && select) {\n selections[f.id] = { checked: checkbox.checked, value: select.value };\n }\n });\n localStorage.setItem(STORAGE_KEY_SELECTIONS, JSON.stringify(selections));\n }\n\n function restoreSelections() {\n var selections = getSelections();\n FEATURES.forEach(function(f) {\n var saved = selections[f.id];\n if (!saved) return;\n var checkbox = document.querySelector('input[data-feature-id=\"' + f.id + '\"]');\n var select = document.querySelector('select[data-value-for=\"' + f.id + '\"]');\n if (checkbox) checkbox.checked = saved.checked;\n if (select) select.value = saved.value;\n });\n }\n\n function escapeHtml(str) {\n var div = document.createElement('div');\n div.textContent = str;\n return div.innerHTML;\n }\n\n function escapeAttr(str) {\n return str.replace(/&/g, '&amp;').replace(/\"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');\n }\n\n function buildTargetUrl(inputValue) {\n var value = inputValue;\n if (!value.startsWith('http://') && !value.startsWith('https://')) {\n value = 'https://' + value;\n }\n var hostname = window.location.hostname;\n var subdomain = hostname.split('.').length > 2 ? hostname.split('.')[0] : '';\n var target = value;\n var sep = target.includes('?') ? '&' : '?';\n if (subdomain) {\n target = target + sep + 'cvly_env=' + encodeURIComponent(subdomain);\n sep = '&';\n }\n FEATURES.forEach(function(f) {\n var checkbox = document.querySelector('input[data-feature-id=\"' + f.id + '\"]');\n var select = document.querySelector('select[data-value-for=\"' + f.id + '\"]');\n if (checkbox && checkbox.checked && select) {\n target = target + sep + 'picked-feature=' + encodeURIComponent(f.id + ':' + select.value);\n sep = '&';\n }\n });\n return target;\n }\n\n function showCopyStatus(message, success) {\n var el = document.getElementById('copy-status');\n if (!el) return;\n el.textContent = message;\n el.style.visibility = 'visible';\n el.style.color = success ? '#2e7d32' : '#b71c1c';\n setTimeout(function() {\n el.style.visibility = 'hidden';\n }, 2000);\n }\n\n // Init\n window.addEventListener('load', function() {\n var input = getUrlInput();\n var savedUrl = localStorage.getItem(STORAGE_KEY_URL);\n if (savedUrl && input) {\n input.value = savedUrl;\n }\n renderHistory();\n restoreSelections();\n });\n\n // Delegate click events\n document.addEventListener('click', function(e) {\n var target = e.target;\n\n // History URL click\n var historyUrl = target.getAttribute('data-history-url');\n if (historyUrl) {\n var input = getUrlInput();\n if (input) input.value = historyUrl;\n return;\n }\n\n // History delete click\n var deleteUrl = target.getAttribute('data-history-delete');\n if (deleteUrl) {\n removeFromHistory(deleteUrl);\n return;\n }\n });\n\n // Feature change persistence\n document.addEventListener('change', function(e) {\n var target = e.target;\n if (target.getAttribute('data-feature-id') || target.getAttribute('data-value-for')) {\n saveSelections();\n }\n });\n\n // Copy button\n document.getElementById('copy-btn').addEventListener('click', function() {\n var input = getUrlInput();\n if (!input || !input.value) return;\n localStorage.setItem(STORAGE_KEY_URL, input.value);\n addToHistory(input.value);\n saveSelections();\n var target = buildTargetUrl(input.value);\n navigator.clipboard.writeText(target).then(function() {\n showCopyStatus('Preview URL copied to clipboard', true);\n });\n });\n\n // Preview button\n document.getElementById('preview-btn').addEventListener('click', function() {\n var input = getUrlInput();\n if (!input || !input.value) return;\n localStorage.setItem(STORAGE_KEY_URL, input.value);\n addToHistory(input.value);\n saveSelections();\n var target = buildTargetUrl(input.value);\n window.location.href = target;\n });\n <\/script>\n</main>\n</body>\n</html>"
35
42
  ]), n, t);
36
43
  }
37
- function g(e) {
44
+ function b(e) {
38
45
  return e.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll("\"", "&quot;");
39
46
  }
40
- function _(e) {
47
+ function x(e) {
41
48
  return e.replaceAll("&", "&amp;").replaceAll("\"", "&quot;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
42
49
  }
43
50
  //#endregion
44
51
  //#region src/log.ts
45
- var v = "picked", y = "\x1B[0m";
46
- function b() {
52
+ var S = "picked", C = "\x1B[0m";
53
+ function w() {
47
54
  let e = process.env.NO_COLOR;
48
55
  return e === "1" || e === "true";
49
56
  }
50
- function x(e) {
51
- return (t) => b() ? t : `${e}${t}${y}`;
57
+ function T(e) {
58
+ return (t) => w() ? t : `${e}${t}${C}`;
52
59
  }
53
- var S = [
60
+ var E = [
54
61
  "debug",
55
62
  "info",
56
63
  "warn",
57
64
  "error",
58
65
  "silent"
59
- ], C = {
66
+ ], D = {
60
67
  debug: {
61
- color: x("\x1B[2m"),
68
+ color: T("\x1B[2m"),
62
69
  log: console.debug,
63
70
  enabled: !1
64
71
  },
65
72
  info: {
66
- color: x("\x1B[36m"),
73
+ color: T("\x1B[36m"),
67
74
  log: console.log,
68
75
  enabled: !0
69
76
  },
70
77
  warn: {
71
- color: x("\x1B[33m"),
78
+ color: T("\x1B[33m"),
72
79
  log: console.warn,
73
80
  enabled: !0
74
81
  },
75
82
  error: {
76
- color: x("\x1B[31m"),
83
+ color: T("\x1B[31m"),
77
84
  log: console.error,
78
85
  enabled: !0
79
86
  },
@@ -82,52 +89,52 @@ var S = [
82
89
  enabled: !1
83
90
  }
84
91
  };
85
- function w(e, t) {
86
- return `${(/* @__PURE__ */ new Date()).toLocaleTimeString()} [${t ? `${v}:${t}` : v}] ${e}`;
92
+ function ee(e, t) {
93
+ return `${(/* @__PURE__ */ new Date()).toLocaleTimeString()} [${t ? `${S}:${t}` : S}] ${e}`;
87
94
  }
88
- function T(e, t, n, r) {
95
+ function O(e, t, n, r) {
89
96
  if (!e.enabled) return;
90
- let i = w(t, r);
97
+ let i = ee(t, r);
91
98
  e.log(e.color ? e.color(i) : i), n !== void 0 && e.log(n);
92
99
  }
93
- function E(e) {
94
- let t = C[e], n = /* @__PURE__ */ new Set();
100
+ function k(e) {
101
+ let t = D[e], n = /* @__PURE__ */ new Set();
95
102
  return Object.assign((e, n, r) => {
96
- T(t, e, n, r);
103
+ O(t, e, n, r);
97
104
  }, { once(e, r, i) {
98
- !t.enabled || n.has(e) || (n.add(e), T(t, e, r, i));
105
+ !t.enabled || n.has(e) || (n.add(e), O(t, e, r, i));
99
106
  } });
100
107
  }
101
- function D(e) {
102
- let t = S.indexOf(e);
108
+ function te(e) {
109
+ let t = E.indexOf(e);
103
110
  if (t === -1) {
104
- T(C.error, `invalid log level: ${e}`);
111
+ O(D.error, `invalid log level: ${e}`);
105
112
  return;
106
113
  }
107
- for (let [e, n] of S.entries()) C[n].enabled = e >= t;
114
+ for (let [e, n] of E.entries()) D[n].enabled = e >= t;
108
115
  }
109
- var O = x("\x1B[34m"), k = x("\x1B[36m");
110
- function A() {
116
+ var A = T("\x1B[34m"), j = T("\x1B[36m");
117
+ function ne() {
111
118
  let e = [
112
- ` ${O("_")} ${k("_")} _ _ _`,
113
- `${O("(_)")} ${k("(_)")} _ __(_)__| |_____ __| |`,
114
- ` ${O("_")} ${O("_")} | '_ \\ / _| / / -_) _\` |`,
115
- `${O("(_)")} ${O("(_)")} | .__/_\\__|_\\_\\___\\__,_|`,
119
+ ` ${A("_")} ${j("_")} _ _ _`,
120
+ `${A("(_)")} ${j("(_)")} _ __(_)__| |_____ __| |`,
121
+ ` ${A("_")} ${A("_")} | '_ \\ / _| / / -_) _\` |`,
122
+ `${A("(_)")} ${A("(_)")} | .__/_\\__|_\\_\\___\\__,_|`,
116
123
  " |_|\n "
117
124
  ];
118
125
  console.log(e.join("\n"));
119
126
  }
120
- var j = {
121
- banner: A,
122
- debug: E("debug"),
123
- info: E("info"),
124
- warn: E("warn"),
125
- error: E("error"),
126
- setLevel: D
127
+ var M = {
128
+ banner: ne,
129
+ debug: k("debug"),
130
+ info: k("info"),
131
+ warn: k("warn"),
132
+ error: k("error"),
133
+ setLevel: te
127
134
  };
128
135
  //#endregion
129
136
  //#region src/middleware.ts
130
- function ee(e) {
137
+ function re(e) {
131
138
  return (t, n, r) => {
132
139
  if (t.method !== "GET") {
133
140
  r();
@@ -144,28 +151,28 @@ function ee(e) {
144
151
  }
145
152
  //#endregion
146
153
  //#region src/gitignore.ts
147
- var M = ".picked/";
148
- async function te(n, r) {
154
+ var N = ".picked/";
155
+ async function ie(n, r) {
149
156
  if (r) return;
150
157
  let i = t(n, ".gitignore");
151
158
  if (!e(i)) {
152
- await f(i, `${M}
159
+ await f(i, `${N}
153
160
  `);
154
161
  return;
155
162
  }
156
163
  let a = await d(i, "utf8");
157
- if (ne(a)) return;
158
- let o = `${a.length > 0 && !a.endsWith("\n") ? "\n" : ""}${M}
164
+ if (P(a)) return;
165
+ let o = `${a.length > 0 && !a.endsWith("\n") ? "\n" : ""}${N}
159
166
  `;
160
167
  await l(i, o);
161
168
  }
162
- function ne(e) {
163
- return e.split(/\r?\n/).map((e) => e.trim()).some((e) => e === M || e === ".picked");
169
+ function P(e) {
170
+ return e.split(/\r?\n/).map((e) => e.trim()).some((e) => e === N || e === ".picked");
164
171
  }
165
172
  //#endregion
166
173
  //#region src/retry.ts
167
- var N = 6, re = 5e3;
168
- function P(e) {
174
+ var F = 6, ae = 5e3;
175
+ function I(e) {
169
176
  let t;
170
177
  try {
171
178
  t = new URL(e).hostname;
@@ -174,12 +181,12 @@ function P(e) {
174
181
  }
175
182
  return t === "localhost" || t === "127.0.0.1" || t === "::1" || t === "[::1]" || t !== "api.picked.app" && t.endsWith(".picked.app");
176
183
  }
177
- function ie(e) {
184
+ function oe(e) {
178
185
  return new Promise((t) => {
179
186
  setTimeout(t, e);
180
187
  });
181
188
  }
182
- async function F(e, t) {
189
+ async function L(e, t) {
183
190
  let n = null, r = null;
184
191
  try {
185
192
  n = await e();
@@ -187,9 +194,9 @@ async function F(e, t) {
187
194
  r = e;
188
195
  }
189
196
  if (n !== null) return n;
190
- for (let i = 1; i <= N; i++) {
191
- let a = re * 2 ** (i - 1);
192
- t(i, N, a), await ie(a), r = null;
197
+ for (let i = 1; i <= F; i++) {
198
+ let a = ae * 2 ** (i - 1);
199
+ t(i, F, a), await oe(a), r = null;
193
200
  try {
194
201
  n = await e();
195
202
  } catch (e) {
@@ -202,13 +209,20 @@ async function F(e, t) {
202
209
  }
203
210
  //#endregion
204
211
  //#region src/util.ts
205
- function I(e) {
212
+ function R(e) {
206
213
  return Array.isArray(e) ? e : [];
207
214
  }
215
+ function se(e) {
216
+ let t = e.variants, n = (t ?? []).reduce((e, t) => e + t.weight, 0);
217
+ return !t || t.length === 0 || n === 0 ? `${e.weight.toString()}%` : t.map((e) => {
218
+ let t = Math.round(100 * e.weight / n);
219
+ return `${String(e.value)} ${t.toString()}%`;
220
+ }).join(", ");
221
+ }
208
222
  //#endregion
209
223
  //#region src/prefetch.ts
210
- var L = 2;
211
- function R(e) {
224
+ var z = 2;
225
+ function B(e) {
212
226
  let n = t(e, ".picked");
213
227
  return {
214
228
  pickedDir: n,
@@ -217,50 +231,50 @@ function R(e) {
217
231
  experiencesDir: t(n, "experiences")
218
232
  };
219
233
  }
220
- async function ae(t) {
234
+ async function ce(t) {
221
235
  if (!e(t)) return null;
222
236
  try {
223
237
  let e = await d(t, "utf8"), n = JSON.parse(e);
224
- return oe(n) ? n : null;
238
+ return V(n) ? n : null;
225
239
  } catch {
226
240
  return null;
227
241
  }
228
242
  }
229
- function oe(e) {
243
+ function V(e) {
230
244
  return !(typeof e != "object" || !e || !("version" in e) || typeof e.version != "number" || !("projectVersionId" in e) || typeof e.projectVersionId != "string" || !("workspaceId" in e) || typeof e.workspaceId != "string" || !("experiences" in e) || !Array.isArray(e.experiences));
231
245
  }
232
- function z(e) {
246
+ function H(e) {
233
247
  let t = /* @__PURE__ */ new Set();
234
- for (let n of I(e.steps)) n.layoutContentId && t.add(n.id);
248
+ for (let n of R(e.steps)) n.layoutContentId && t.add(n.id);
235
249
  if (t.size === 0) return [];
236
250
  let n = [];
237
- for (let r of I(e.experiences)) I(r.nodes).some((e) => e.type === "step" && t.has(e.stepId)) && n.push(r.id);
251
+ for (let r of R(e.experiences)) R(r.nodes).some((e) => e.type === "step" && t.has(e.stepId)) && n.push(r.id);
238
252
  return n;
239
253
  }
240
- async function B(n) {
241
- let { apiUrl: r, projectId: i, projectRoot: a, headers: o, previewToken: s, reuseWhenUnchanged: c = !0 } = n, l = R(a), d = await H(r, i, o, s), p = z(d);
254
+ async function U(n) {
255
+ let { apiUrl: r, projectId: i, projectRoot: a, headers: o, previewToken: s, reuseWhenUnchanged: c = !0 } = n, l = B(a), d = await G(r, i, o, s), p = H(d);
242
256
  if (await u(l.experiencesDir, { recursive: !0 }), await f(l.projectConfigPath, JSON.stringify(d, null, 2)), c) {
243
- let t = await ae(l.manifestPath);
244
- if (t?.version === L && t.projectVersionId === d.versionId && t.workspaceId === d.workspaceId) {
245
- let n = V(l, p);
257
+ let t = await ce(l.manifestPath);
258
+ if (t?.version === z && t.projectVersionId === d.versionId && t.workspaceId === d.workspaceId) {
259
+ let n = W(l, p);
246
260
  if (Object.values(n).every((t) => e(t))) return {
247
261
  config: d,
248
262
  manifest: t,
249
263
  experienceContentPaths: n
250
264
  };
251
- j.info("a manifest-referenced content file is missing; refetching every experience");
265
+ M.info("a manifest-referenced content file is missing; refetching every experience");
252
266
  }
253
267
  }
254
268
  let m = (/* @__PURE__ */ new Date()).toISOString(), h = [];
255
269
  for (let e of p) {
256
- let n = await U(r, i, e, o, s), a = t(l.experiencesDir, `${e}.json`);
270
+ let n = await le(r, i, e, o, s), a = t(l.experiencesDir, `${e}.json`);
257
271
  await f(a, JSON.stringify(n, null, 2)), h.push({
258
272
  id: e,
259
273
  fetchedAt: m
260
274
  });
261
275
  }
262
276
  let g = {
263
- version: L,
277
+ version: z,
264
278
  fetchedAt: m,
265
279
  projectVersionId: d.versionId,
266
280
  workspaceId: d.workspaceId,
@@ -270,30 +284,30 @@ async function B(n) {
270
284
  return await f(l.manifestPath, JSON.stringify(g, null, 2)), {
271
285
  config: d,
272
286
  manifest: g,
273
- experienceContentPaths: V(l, p)
287
+ experienceContentPaths: W(l, p)
274
288
  };
275
289
  }
276
- function V(e, n) {
290
+ function W(e, n) {
277
291
  let r = {};
278
292
  for (let i of n) r[i] = t(e.experiencesDir, `${i}.json`);
279
293
  return r;
280
294
  }
281
- async function H(e, t, n, r) {
295
+ async function G(e, t, n, r) {
282
296
  let i = () => a(e, t, {
283
297
  headers: n,
284
298
  previewToken: r
285
299
  }), o;
286
300
  try {
287
- o = P(e) ? await F(i, (e, t, n) => {
288
- j.info(`project config not ready, retrying in ${(n / 1e3).toString()}s (${e.toString()}/${t.toString()})`);
301
+ o = I(e) ? await L(i, (e, t, n) => {
302
+ M.info(`project config not ready, retrying in ${(n / 1e3).toString()}s (${e.toString()}/${t.toString()})`);
289
303
  }) : await i();
290
304
  } catch (n) {
291
- throw Error(`[picked] Build-time fetch of project config failed for "${t}" at ${e}: ${W(n)}`);
305
+ throw Error(`[picked] Build-time fetch of project config failed for "${t}" at ${e}: ${K(n)}`);
292
306
  }
293
307
  if (!o) throw Error(`[picked] Build-time fetch of project config returned no usable response for "${t}" at ${e}. Confirm the API is reachable and the project ID is correct.`);
294
308
  return o;
295
309
  }
296
- async function U(e, t, n, r, a) {
310
+ async function le(e, t, n, r, a) {
297
311
  let o;
298
312
  try {
299
313
  o = await i(e, t, n, {
@@ -301,12 +315,12 @@ async function U(e, t, n, r, a) {
301
315
  previewToken: a
302
316
  });
303
317
  } catch (t) {
304
- throw Error(`[picked] Build-time fetch of content for experience "${n}" failed at ${e}: ${W(t)}`);
318
+ throw Error(`[picked] Build-time fetch of content for experience "${n}" failed at ${e}: ${K(t)}`);
305
319
  }
306
320
  if (!o) throw Error(`[picked] Build-time fetch of content for experience "${n}" returned no usable response. Confirm the experience id exists and the API is reachable.`);
307
321
  return o;
308
322
  }
309
- function W(e) {
323
+ function K(e) {
310
324
  if (e instanceof Error) return e.message;
311
325
  if (typeof e == "string") return e;
312
326
  try {
@@ -317,12 +331,12 @@ function W(e) {
317
331
  }
318
332
  //#endregion
319
333
  //#region src/virtual-module/api.ts
320
- function G() {
334
+ function q() {
321
335
  return "export const manifestMetadata = {\n mode: 'api',\n fetchedAt: null,\n projectVersionId: null,\n workspaceId: null,\n}\n";
322
336
  }
323
337
  //#endregion
324
338
  //#region src/virtual-module/build.ts
325
- function K(e) {
339
+ function ue(e) {
326
340
  let { projectConfigPath: t, experienceContentPaths: n, manifestMetadata: r } = e, i = (e) => JSON.stringify(e), a = Object.entries(n).map(([e, t]) => ` ${JSON.stringify(e)}: () => import(${i(t)}).then((m) => m.default ?? m),`).join("\n");
327
341
  return `import { registerPickedBundle } from '@picked/client/plugins/dynamic-experiences'
328
342
  import projectConfigJson from ${i(t)}
@@ -352,7 +366,7 @@ registerPickedBundle({ projectConfig, experienceContent, manifestMetadata })
352
366
  }
353
367
  //#endregion
354
368
  //#region src/virtual-module/dev.ts
355
- function se(e) {
369
+ function de(e) {
356
370
  let { apiUrl: t, projectId: n, projectConfig: r, previewToken: i } = e, a = r ? "import { fetchExperienceContent, registerPickedBundle } from '@picked/client/plugins/dynamic-experiences'" : "import { fetchProject, fetchExperienceContent } from '@picked/client/plugins/dynamic-experiences'", o = r ? `export const projectConfig = ${JSON.stringify(r)}` : "export const projectConfig = await fetchProject(apiUrl, projectId, { previewToken: previewToken ?? undefined })", s = r ? "\nregisterPickedBundle({ projectConfig, experienceContent, manifestMetadata })\n" : "";
357
371
  return `${a}
358
372
 
@@ -378,10 +392,10 @@ ${s}`;
378
392
  }
379
393
  //#endregion
380
394
  //#region src/index.ts
381
- var q = 5;
395
+ var fe = 5;
382
396
  function J(e, t, n) {
383
397
  if (t.length === 0) return;
384
- if (t.length > q) {
398
+ if (t.length > fe) {
385
399
  console.log(`\n ${e}: ${t.length.toString()} loaded\n`);
386
400
  return;
387
401
  }
@@ -396,10 +410,10 @@ function J(e, t, n) {
396
410
  ""
397
411
  ].join("\n"));
398
412
  }
399
- function ce(e, t) {
413
+ function pe(e, t) {
400
414
  t.length !== 0 && console.log(`\n ${e}: ${t.length.toString()} loaded\n`);
401
415
  }
402
- var le = [
416
+ var me = [
403
417
  {
404
418
  header: "Name",
405
419
  value: (e) => e.name
@@ -413,14 +427,14 @@ var le = [
413
427
  value: (e) => e.enabled ? "\x1B[32m enabled\x1B[0m" : "\x1B[2mdisabled\x1B[0m"
414
428
  },
415
429
  {
416
- header: "Weight",
417
- value: (e) => `${e.weight.toString()}%`.padStart(6)
430
+ header: "Split",
431
+ value: (e) => se(e)
418
432
  },
419
433
  {
420
434
  header: "Ver",
421
435
  value: (e) => `v${e.version.toString()}`
422
436
  }
423
- ], ue = [
437
+ ], he = [
424
438
  {
425
439
  header: "Name",
426
440
  value: (e) => e.name
@@ -441,7 +455,7 @@ var le = [
441
455
  header: "Targets",
442
456
  value: (e) => e.targets.length.toString()
443
457
  }
444
- ], de = [
458
+ ], ge = [
445
459
  {
446
460
  header: "Name",
447
461
  value: (e) => e.name
@@ -454,7 +468,7 @@ var le = [
454
468
  header: "Fields",
455
469
  value: (e) => (e.fieldIds?.length ?? 0).toString()
456
470
  }
457
- ], fe = [
471
+ ], _e = [
458
472
  {
459
473
  header: "Name",
460
474
  value: (e) => e.name
@@ -471,38 +485,38 @@ var le = [
471
485
  header: "Required",
472
486
  value: (e) => e.required ? "yes" : "no"
473
487
  }
474
- ], pe = [{
488
+ ], ve = [{
475
489
  header: "Name",
476
490
  value: (e) => e.name
477
491
  }, {
478
492
  header: "Key",
479
493
  value: (e) => e.key
480
494
  }];
481
- function me() {
482
- return "0.0.75";
495
+ function ye() {
496
+ return "0.0.76-next.1";
483
497
  }
484
- var he = "https://api.picked.app", Y = "virtual:picked/data", X = `\0${Y}`;
485
- function ge(e) {
498
+ var be = "https://api.picked.app", Y = "virtual:picked/data", X = `\0${Y}`;
499
+ function xe(e) {
486
500
  for (let t of Object.values(e)) if (t.type === "chunk" && t.moduleIds.includes(X)) return t.fileName;
487
501
  }
488
- function _e(e, t) {
502
+ function Se(e, t) {
489
503
  return e === "" || e.endsWith("/") ? `${e}${t}` : `${e}/${t}`;
490
504
  }
491
- async function ve(e) {
505
+ async function Ce(e) {
492
506
  try {
493
507
  let t = await o({
494
508
  config: e,
495
509
  onWarn: (e) => {
496
- j.warn(e);
510
+ M.warn(e);
497
511
  }
498
512
  });
499
- j.info(`generated types at ${t.typesOutput}`);
513
+ M.info(`generated types at ${t.typesOutput}`);
500
514
  } catch (e) {
501
515
  let t = e instanceof Error ? e.message : String(e);
502
516
  throw Error(`type generation failed: ${t}. Fix the schema source, or set \`generateTypes: false\` on the picked plugin to skip it.`);
503
517
  }
504
518
  }
505
- async function ye(e, t) {
519
+ async function we(e, t) {
506
520
  let n = await c(e, t);
507
521
  if (!n) throw Error("picked.config.{ts,js,json} is required. Add a picked.config.ts with projectId and apiUrl.");
508
522
  return n;
@@ -510,59 +524,59 @@ async function ye(e, t) {
510
524
  function Z(e, t, n) {
511
525
  if (t !== void 0 && n !== void 0 && t !== n) throw Error(`picked plugin option \`${e}\` is "${t}", and picked.config says "${n}". Remove the plugin option; picked.config is the one place this belongs.`);
512
526
  }
513
- function be(e) {
527
+ function Te(e) {
514
528
  let t = [];
515
529
  if (e.projectId !== void 0 && t.push("`projectId`"), e.apiUrl !== void 0 && t.push("`apiUrl`"), t.length === 0) return;
516
530
  let n = t.length > 1;
517
- j.warn(`picked plugin option${n ? "s" : ""} ${t.join(" and ")} ${n ? "are" : "is"} deprecated, and a future release drops ${n ? "them" : "it"}. Move ${n ? "them" : "it"} to picked.config, which the CLI and the type generator read from too.`);
531
+ M.warn(`picked plugin option${n ? "s" : ""} ${t.join(" and ")} ${n ? "are" : "is"} deprecated, and a future release drops ${n ? "them" : "it"}. Move ${n ? "them" : "it"} to picked.config, which the CLI and the type generator read from too.`);
518
532
  }
519
- async function xe(e, t) {
533
+ async function Ee(e, t) {
520
534
  let n = await s(e);
521
- n && n.projectId !== t && j.warn(`using project "${t}" (picked.config default: "${n.projectId}") — run 'picked status' to inspect`);
535
+ n && n.projectId !== t && M.warn(`using project "${t}" (picked.config default: "${n.projectId}") — run 'picked status' to inspect`);
522
536
  }
523
537
  var Q = /* @__PURE__ */ new Map();
524
- function Se(e, t, n) {
538
+ function De(e, t, n) {
525
539
  return JSON.stringify([
526
540
  e,
527
541
  t,
528
542
  n
529
543
  ]);
530
544
  }
531
- function Ce(t = {}) {
532
- let i = t.mode ?? "bundle", o = t.generateTypes ?? !0, c = [], l = process.cwd(), u = "serve", d = "/", f = null, p = !1, m, g, _ = null;
545
+ function Oe(t = {}) {
546
+ let i = t.mode ?? "bundle", o = t.generateTypes ?? !0, c = [], l = process.cwd(), u = "serve", d = "/", f = null, p = !1, m, h, g = null;
533
547
  return {
534
548
  name: "picked",
535
- config: async (d, h) => {
536
- u = h.command, l = d.root === void 0 ? process.cwd() : n(process.cwd(), d.root);
549
+ config: async (d, _) => {
550
+ u = _.command, l = d.root === void 0 ? process.cwd() : n(process.cwd(), d.root);
537
551
  let { projectId: v, apiUrl: y } = t, b = await s(l);
538
- Z("projectId", v, b?.projectId), Z("apiUrl", y, b?.apiUrl), be({
552
+ Z("projectId", v, b?.projectId), Z("apiUrl", y, b?.apiUrl), Te({
539
553
  projectId: v,
540
554
  apiUrl: y
541
- }), f = await ye(l, {
555
+ }), f = await we(l, {
542
556
  projectId: v,
543
557
  apiUrl: y
544
558
  });
545
559
  let { projectId: x, apiUrl: S, previewToken: C } = f;
546
- j.banner(), o && !p && (p = !0, await ve(f)), S !== he && j.warn(`using custom API URL: ${S}`), await xe(l, x);
547
- let w = r("vite-plugin", me());
548
- if (i === "api") j.debug("mode is 'api': skipping the project-config prefetch");
549
- else if (h.command === "build") {
550
- let t = Se(S, x, l);
560
+ M.banner(), o && !p && (p = !0, await Ce(f)), S !== be && M.warn(`using custom API URL: ${S}`), await Ee(l, x);
561
+ let w = r("vite-plugin", ye());
562
+ if (i === "api") M.debug("mode is 'api': skipping the project-config prefetch");
563
+ else if (_.command === "build") {
564
+ let t = De(S, x, l);
551
565
  m = t;
552
566
  let n = Q.get(t);
553
567
  n === void 0 && (n = (async () => {
554
- j.info(`prefetching project config + content for "${x}"`);
555
- let t = R(l), n = e(t.pickedDir), r = performance.now(), i = await B({
568
+ M.info(`prefetching project config + content for "${x}"`);
569
+ let t = B(l), n = e(t.pickedDir), r = performance.now(), i = await U({
556
570
  apiUrl: S,
557
571
  projectId: x,
558
572
  projectRoot: l,
559
573
  headers: w,
560
574
  previewToken: C ?? void 0
561
575
  }), a = (performance.now() - r).toFixed(0);
562
- await te(l, n);
576
+ await ie(l, n);
563
577
  let o = i.config;
564
578
  return $(o, a), {
565
- virtualSource: K({
579
+ virtualSource: ue({
566
580
  projectConfigPath: t.projectConfigPath,
567
581
  experienceContentPaths: i.experienceContentPaths,
568
582
  manifestMetadata: {
@@ -572,21 +586,21 @@ function Ce(t = {}) {
572
586
  workspaceId: i.manifest.workspaceId
573
587
  }
574
588
  }),
575
- features: I(o.features)
589
+ features: R(o.features)
576
590
  };
577
591
  })(), n.catch(() => Q.delete(t)), Q.set(t, n));
578
592
  let r = await n;
579
- g = r.virtualSource, c = r.features;
580
- } else if (h.mode === "production") j.debug("skipping the dev project-config fetch for a production serve resolution");
593
+ h = r.virtualSource, c = r.features;
594
+ } else if (_.mode === "production") M.debug("skipping the dev project-config fetch for a production serve resolution");
581
595
  else {
582
- j.info(`fetching project config for "${x}" (dev)`);
596
+ M.info(`fetching project config for "${x}" (dev)`);
583
597
  let e = performance.now(), t = () => a(S, x, {
584
598
  headers: w,
585
599
  previewToken: C ?? void 0
586
- }), n = P(S) ? await F(t, (e, t, n) => {
587
- j.info(`local API not ready, retrying in ${(n / 1e3).toString()}s (${e.toString()}/${t.toString()})`);
600
+ }), n = I(S) ? await L(t, (e, t, n) => {
601
+ M.info(`local API not ready, retrying in ${(n / 1e3).toString()}s (${e.toString()}/${t.toString()})`);
588
602
  }) : await t(), r = (performance.now() - e).toFixed(0);
589
- _ = n, n ? (c = I(n.features), $(n, r)) : j.warn(`failed to fetch project config for "${x}" (${r}ms)`);
603
+ g = n, n ? (c = R(n.features), $(n, r)) : M.warn(`failed to fetch project config for "${x}" (${r}ms)`);
590
604
  }
591
605
  },
592
606
  configResolved(e) {
@@ -599,9 +613,9 @@ function Ce(t = {}) {
599
613
  order: "post",
600
614
  handler(e, t) {
601
615
  if (i === "api" || t.bundle === void 0) return;
602
- let n = ge(t.bundle);
616
+ let n = xe(t.bundle);
603
617
  if (n === void 0) return;
604
- let r = _e(d, n);
618
+ let r = Se(d, n);
605
619
  if (!e.includes(`"${r}"`)) return [{
606
620
  tag: "link",
607
621
  attrs: {
@@ -618,20 +632,20 @@ function Ce(t = {}) {
618
632
  },
619
633
  load(e) {
620
634
  if (e === X) {
621
- if (i === "api") return G();
622
- if (u === "build") return g;
635
+ if (i === "api") return q();
636
+ if (u === "build") return h;
623
637
  if (!f) throw Error("picked plugin config hook must run before virtual module load");
624
- return se({
638
+ return de({
625
639
  apiUrl: f.apiUrl,
626
640
  projectId: f.projectId,
627
- projectConfig: _,
641
+ projectConfig: g,
628
642
  previewToken: f.previewToken ?? void 0
629
643
  });
630
644
  }
631
645
  },
632
646
  configureServer(e) {
633
647
  if (t.disableLauncher) return;
634
- e.middlewares.use(ee(() => h(c)));
648
+ e.middlewares.use(re(() => y(c)));
635
649
  let n = e.printUrls.bind(e);
636
650
  e.printUrls = () => {
637
651
  let t = e.resolvedUrls?.local[0];
@@ -647,13 +661,13 @@ function Ce(t = {}) {
647
661
  handler(e, n) {
648
662
  if (!t.disableLauncher) {
649
663
  if ("index.html" in n) {
650
- j.debug("index.html came from the build; skipping the launcher page");
664
+ M.debug("index.html came from the build; skipping the launcher page");
651
665
  return;
652
666
  }
653
667
  this.emitFile({
654
668
  type: "asset",
655
669
  fileName: "index.html",
656
- source: h(c)
670
+ source: y(c)
657
671
  });
658
672
  }
659
673
  }
@@ -661,7 +675,7 @@ function Ce(t = {}) {
661
675
  };
662
676
  }
663
677
  function $(e, t) {
664
- let n = I(e.features), r = I(e.experiences), i = I(e.steps), a = I(e.fields), o = I(e.conditions), s = I(e.actions), c = JSON.stringify(e).length, l = [
678
+ let n = R(e.features), r = R(e.experiences), i = R(e.steps), a = R(e.fields), o = R(e.conditions), s = R(e.actions), c = JSON.stringify(e).length, l = [
665
679
  `${n.length.toString()} features`,
666
680
  `${r.length.toString()} experiences`,
667
681
  `${i.length.toString()} steps`,
@@ -669,7 +683,7 @@ function $(e, t) {
669
683
  `${o.length.toString()} conditions`,
670
684
  `${s.length.toString()} actions`
671
685
  ].join(", ");
672
- j.info(`fetched config in ${t}ms (${l})`), J("Features", n, le), J("Experiences", r, ue), J("Steps", i, de), J("Fields", a, fe), J("Conditions", o, pe), ce("Actions", s), j.debug(`config size: ${c.toString()} bytes`);
686
+ M.info(`fetched config in ${t}ms (${l})`), J("Features", n, me), J("Experiences", r, he), J("Steps", i, ge), J("Fields", a, _e), J("Conditions", o, ve), pe("Actions", s), M.debug(`config size: ${c.toString()} bytes`);
673
687
  }
674
688
  //#endregion
675
- export { Ce as picked };
689
+ export { Oe as picked };