@picked/vite-plugin-picked 0.0.1-dev.1787537193674 → 0.0.1-dev.1787788898336

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
@@ -11,18 +11,25 @@ function b(e, t) {
11
11
  }
12
12
  //#endregion
13
13
  //#region src/launcher.ts
14
- var x;
15
- function S(e) {
16
- let t = JSON.stringify(e), n = e.length > 0 ? e.map((e) => `
14
+ var x, S = ["true", "false"], C = "false";
15
+ function w(e) {
16
+ let t = e.variants;
17
+ return !t || t.length === 0 ? S : t.map((e) => String(e.value));
18
+ }
19
+ function T(e) {
20
+ let t = w(e), n = Math.max(0, t.findIndex((e) => e !== C));
21
+ return t.map((e, t) => `<option value="${O(e)}"${t === n ? " selected" : ""}>${D(e)}</option>`).join("");
22
+ }
23
+ function E(e) {
24
+ let t = JSON.stringify(e).replaceAll("<", String.raw`\u003c`), n = e.length > 0 ? e.map((e) => `
17
25
  <div class="feature-row">
18
26
  <label>
19
- <input type="checkbox" data-feature-id="${w(e.id)}" checked>
20
- <span class="feature-name">${C(e.name)}</span>
21
- <span class="feature-id">${C(e.id)}</span>
27
+ <input type="checkbox" data-feature-id="${O(e.id)}" checked>
28
+ <span class="feature-name">${D(e.name)}</span>
29
+ <span class="feature-id">${D(e.id)}</span>
22
30
  </label>
23
- <select data-value-for="${w(e.id)}">
24
- <option value="true" selected>true</option>
25
- <option value="false">false</option>
31
+ <select data-value-for="${O(e.id)}">
32
+ ${T(e)}
26
33
  </select>
27
34
  </div>`).join("") : "<p class=\"text no-features\">No features configured for this project.</p>";
28
35
  return String.raw(x ||= b([
@@ -35,46 +42,46 @@ function S(e) {
35
42
  ";\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>"
36
43
  ]), n, t);
37
44
  }
38
- function C(e) {
45
+ function D(e) {
39
46
  return e.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll("\"", "&quot;");
40
47
  }
41
- function w(e) {
48
+ function O(e) {
42
49
  return e.replaceAll("&", "&amp;").replaceAll("\"", "&quot;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
43
50
  }
44
51
  //#endregion
45
52
  //#region src/log.ts
46
- var T = "picked", ee = "\x1B[0m";
53
+ var k = "picked", ee = "\x1B[0m";
47
54
  function te() {
48
55
  let e = process.env.NO_COLOR;
49
56
  return e === "1" || e === "true";
50
57
  }
51
- function E(e) {
58
+ function A(e) {
52
59
  return (t) => te() ? t : `${e}${t}${ee}`;
53
60
  }
54
- var D = [
61
+ var j = [
55
62
  "debug",
56
63
  "info",
57
64
  "warn",
58
65
  "error",
59
66
  "silent"
60
- ], O = {
67
+ ], M = {
61
68
  debug: {
62
- color: E("\x1B[2m"),
69
+ color: A("\x1B[2m"),
63
70
  log: console.debug,
64
71
  enabled: !1
65
72
  },
66
73
  info: {
67
- color: E("\x1B[36m"),
74
+ color: A("\x1B[36m"),
68
75
  log: console.log,
69
76
  enabled: !0
70
77
  },
71
78
  warn: {
72
- color: E("\x1B[33m"),
79
+ color: A("\x1B[33m"),
73
80
  log: console.warn,
74
81
  enabled: !0
75
82
  },
76
83
  error: {
77
- color: E("\x1B[31m"),
84
+ color: A("\x1B[31m"),
78
85
  log: console.error,
79
86
  enabled: !0
80
87
  },
@@ -84,51 +91,51 @@ var D = [
84
91
  }
85
92
  };
86
93
  function ne(e, t) {
87
- return `${(/* @__PURE__ */ new Date()).toLocaleTimeString()} [${t ? `${T}:${t}` : T}] ${e}`;
94
+ return `${(/* @__PURE__ */ new Date()).toLocaleTimeString()} [${t ? `${k}:${t}` : k}] ${e}`;
88
95
  }
89
- function k(e, t, n, r) {
96
+ function N(e, t, n, r) {
90
97
  if (!e.enabled) return;
91
98
  let i = ne(t, r);
92
99
  e.log(e.color ? e.color(i) : i), n !== void 0 && e.log(n);
93
100
  }
94
- function A(e) {
95
- let t = O[e], n = /* @__PURE__ */ new Set();
101
+ function P(e) {
102
+ let t = M[e], n = /* @__PURE__ */ new Set();
96
103
  return Object.assign((e, n, r) => {
97
- k(t, e, n, r);
104
+ N(t, e, n, r);
98
105
  }, { once(e, r, i) {
99
- !t.enabled || n.has(e) || (n.add(e), k(t, e, r, i));
106
+ !t.enabled || n.has(e) || (n.add(e), N(t, e, r, i));
100
107
  } });
101
108
  }
102
109
  function re(e) {
103
- let t = D.indexOf(e);
110
+ let t = j.indexOf(e);
104
111
  if (t === -1) {
105
- k(O.error, `invalid log level: ${e}`);
112
+ N(M.error, `invalid log level: ${e}`);
106
113
  return;
107
114
  }
108
- for (let [e, n] of D.entries()) O[n].enabled = e >= t;
115
+ for (let [e, n] of j.entries()) M[n].enabled = e >= t;
109
116
  }
110
- var j = E("\x1B[34m"), M = E("\x1B[36m");
111
- function ie() {
117
+ var F = A("\x1B[34m"), ie = A("\x1B[36m");
118
+ function ae() {
112
119
  let e = [
113
- ` ${j("_")} ${M("_")} _ _ _`,
114
- `${j("(_)")} ${M("(_)")} _ __(_)__| |_____ __| |`,
115
- ` ${j("_")} ${j("_")} | '_ \\ / _| / / -_) _\` |`,
116
- `${j("(_)")} ${j("(_)")} | .__/_\\__|_\\_\\___\\__,_|`,
120
+ ` ${F("_")} ${ie("_")} _ _ _`,
121
+ `${F("(_)")} ${ie("(_)")} _ __(_)__| |_____ __| |`,
122
+ ` ${F("_")} ${F("_")} | '_ \\ / _| / / -_) _\` |`,
123
+ `${F("(_)")} ${F("(_)")} | .__/_\\__|_\\_\\___\\__,_|`,
117
124
  " |_|\n "
118
125
  ];
119
126
  console.log(e.join("\n"));
120
127
  }
121
- var N = {
122
- banner: ie,
123
- debug: A("debug"),
124
- info: A("info"),
125
- warn: A("warn"),
126
- error: A("error"),
128
+ var I = {
129
+ banner: ae,
130
+ debug: P("debug"),
131
+ info: P("info"),
132
+ warn: P("warn"),
133
+ error: P("error"),
127
134
  setLevel: re
128
135
  };
129
136
  //#endregion
130
137
  //#region src/middleware.ts
131
- function ae(e) {
138
+ function oe(e) {
132
139
  return (t, n, r) => {
133
140
  if (t.method !== "GET") {
134
141
  r();
@@ -145,28 +152,28 @@ function ae(e) {
145
152
  }
146
153
  //#endregion
147
154
  //#region src/gitignore.ts
148
- var P = ".picked/";
149
- async function oe(n, r) {
155
+ var L = ".picked/";
156
+ async function se(n, r) {
150
157
  if (r) return;
151
158
  let i = t(n, ".gitignore");
152
159
  if (!e(i)) {
153
- await h(i, `${P}
160
+ await h(i, `${L}
154
161
  `);
155
162
  return;
156
163
  }
157
164
  let a = await m(i, "utf8");
158
- if (se(a)) return;
159
- let o = `${a.length > 0 && !a.endsWith("\n") ? "\n" : ""}${P}
165
+ if (ce(a)) return;
166
+ let o = `${a.length > 0 && !a.endsWith("\n") ? "\n" : ""}${L}
160
167
  `;
161
168
  await f(i, o);
162
169
  }
163
- function se(e) {
164
- return e.split(/\r?\n/).map((e) => e.trim()).some((e) => e === P || e === ".picked");
170
+ function ce(e) {
171
+ return e.split(/\r?\n/).map((e) => e.trim()).some((e) => e === L || e === ".picked");
165
172
  }
166
173
  //#endregion
167
174
  //#region src/retry.ts
168
- var F = 6, ce = 5e3;
169
- function I(e) {
175
+ var R = 6, le = 5e3;
176
+ function z(e) {
170
177
  let t;
171
178
  try {
172
179
  t = new URL(e).hostname;
@@ -175,12 +182,12 @@ function I(e) {
175
182
  }
176
183
  return t === "localhost" || t === "127.0.0.1" || t === "::1" || t === "[::1]" || t !== "api.picked.app" && t.endsWith(".picked.app");
177
184
  }
178
- function le(e) {
185
+ function ue(e) {
179
186
  return new Promise((t) => {
180
187
  setTimeout(t, e);
181
188
  });
182
189
  }
183
- async function L(e, t) {
190
+ async function B(e, t) {
184
191
  let n = null, r = null;
185
192
  try {
186
193
  n = await e();
@@ -188,9 +195,9 @@ async function L(e, t) {
188
195
  r = e;
189
196
  }
190
197
  if (n !== null) return n;
191
- for (let i = 1; i <= F; i++) {
192
- let a = ce * 2 ** (i - 1);
193
- t(i, F, a), await le(a), r = null;
198
+ for (let i = 1; i <= R; i++) {
199
+ let a = le * 2 ** (i - 1);
200
+ t(i, R, a), await ue(a), r = null;
194
201
  try {
195
202
  n = await e();
196
203
  } catch (e) {
@@ -203,13 +210,20 @@ async function L(e, t) {
203
210
  }
204
211
  //#endregion
205
212
  //#region src/util.ts
206
- function R(e) {
213
+ function V(e) {
207
214
  return Array.isArray(e) ? e : [];
208
215
  }
216
+ function de(e) {
217
+ let t = e.variants, n = (t ?? []).reduce((e, t) => e + t.weight, 0);
218
+ return !t || t.length === 0 || n === 0 ? `${e.weight.toString()}%` : t.map((e) => {
219
+ let t = Math.round(100 * e.weight / n);
220
+ return `${String(e.value)} ${t.toString()}%`;
221
+ }).join(", ");
222
+ }
209
223
  //#endregion
210
224
  //#region src/prefetch.ts
211
- var z = 2;
212
- function B(e) {
225
+ var H = 2;
226
+ function U(e) {
213
227
  let n = t(e, ".picked");
214
228
  return {
215
229
  pickedDir: n,
@@ -218,50 +232,50 @@ function B(e) {
218
232
  experiencesDir: t(n, "experiences")
219
233
  };
220
234
  }
221
- async function ue(t) {
235
+ async function fe(t) {
222
236
  if (!e(t)) return null;
223
237
  try {
224
238
  let e = await m(t, "utf8"), n = JSON.parse(e);
225
- return de(n) ? n : null;
239
+ return pe(n) ? n : null;
226
240
  } catch {
227
241
  return null;
228
242
  }
229
243
  }
230
- function de(e) {
244
+ function pe(e) {
231
245
  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));
232
246
  }
233
- function V(e) {
247
+ function me(e) {
234
248
  let t = /* @__PURE__ */ new Set();
235
- for (let n of R(e.steps)) n.layoutContentId && t.add(n.id);
249
+ for (let n of V(e.steps)) n.layoutContentId && t.add(n.id);
236
250
  if (t.size === 0) return [];
237
251
  let n = [];
238
- for (let r of R(e.experiences)) R(r.nodes).some((e) => e.type === "step" && t.has(e.stepId)) && n.push(r.id);
252
+ for (let r of V(e.experiences)) V(r.nodes).some((e) => e.type === "step" && t.has(e.stepId)) && n.push(r.id);
239
253
  return n;
240
254
  }
241
- async function H(n) {
242
- let { apiUrl: r, projectId: i, projectRoot: a, headers: o, previewToken: s, reuseWhenUnchanged: c = !0 } = n, l = B(a), u = await fe(r, i, o, s), d = V(u);
255
+ async function he(n) {
256
+ let { apiUrl: r, projectId: i, projectRoot: a, headers: o, previewToken: s, reuseWhenUnchanged: c = !0 } = n, l = U(a), u = await ge(r, i, o, s), d = me(u);
243
257
  if (await p(l.experiencesDir, { recursive: !0 }), await h(l.projectConfigPath, JSON.stringify(u, null, 2)), c) {
244
- let t = await ue(l.manifestPath);
245
- if (t?.version === z && t.projectVersionId === u.versionId && t.workspaceId === u.workspaceId) {
246
- let n = U(l, d);
258
+ let t = await fe(l.manifestPath);
259
+ if (t?.version === H && t.projectVersionId === u.versionId && t.workspaceId === u.workspaceId) {
260
+ let n = W(l, d);
247
261
  if (Object.values(n).every((t) => e(t))) return {
248
262
  config: u,
249
263
  manifest: t,
250
264
  experienceContentPaths: n
251
265
  };
252
- N.info("a manifest-referenced content file is missing; refetching every experience");
266
+ I.info("a manifest-referenced content file is missing; refetching every experience");
253
267
  }
254
268
  }
255
269
  let f = (/* @__PURE__ */ new Date()).toISOString(), m = [];
256
270
  for (let e of d) {
257
- let n = await pe(r, i, e, o, s), a = t(l.experiencesDir, `${e}.json`);
271
+ let n = await _e(r, i, e, o, s), a = t(l.experiencesDir, `${e}.json`);
258
272
  await h(a, JSON.stringify(n, null, 2)), m.push({
259
273
  id: e,
260
274
  fetchedAt: f
261
275
  });
262
276
  }
263
277
  let g = {
264
- version: z,
278
+ version: H,
265
279
  fetchedAt: f,
266
280
  projectVersionId: u.versionId,
267
281
  workspaceId: u.workspaceId,
@@ -271,30 +285,30 @@ async function H(n) {
271
285
  return await h(l.manifestPath, JSON.stringify(g, null, 2)), {
272
286
  config: u,
273
287
  manifest: g,
274
- experienceContentPaths: U(l, d)
288
+ experienceContentPaths: W(l, d)
275
289
  };
276
290
  }
277
- function U(e, n) {
291
+ function W(e, n) {
278
292
  let r = {};
279
293
  for (let i of n) r[i] = t(e.experiencesDir, `${i}.json`);
280
294
  return r;
281
295
  }
282
- async function fe(e, t, n, r) {
296
+ async function ge(e, t, n, r) {
283
297
  let i = () => a(e, t, {
284
298
  headers: n,
285
299
  previewToken: r
286
300
  }), o;
287
301
  try {
288
- o = I(e) ? await L(i, (e, t, n) => {
289
- N.info(`project config not ready, retrying in ${(n / 1e3).toString()}s (${e.toString()}/${t.toString()})`);
302
+ o = z(e) ? await B(i, (e, t, n) => {
303
+ I.info(`project config not ready, retrying in ${(n / 1e3).toString()}s (${e.toString()}/${t.toString()})`);
290
304
  }) : await i();
291
305
  } catch (n) {
292
- throw Error(`[picked] Build-time fetch of project config failed for "${t}" at ${e}: ${W(n)}`);
306
+ throw Error(`[picked] Build-time fetch of project config failed for "${t}" at ${e}: ${G(n)}`);
293
307
  }
294
308
  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.`);
295
309
  return o;
296
310
  }
297
- async function pe(e, t, n, r, a) {
311
+ async function _e(e, t, n, r, a) {
298
312
  let o;
299
313
  try {
300
314
  o = await i(e, t, n, {
@@ -302,12 +316,12 @@ async function pe(e, t, n, r, a) {
302
316
  previewToken: a
303
317
  });
304
318
  } catch (t) {
305
- throw Error(`[picked] Build-time fetch of content for experience "${n}" failed at ${e}: ${W(t)}`);
319
+ throw Error(`[picked] Build-time fetch of content for experience "${n}" failed at ${e}: ${G(t)}`);
306
320
  }
307
321
  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.`);
308
322
  return o;
309
323
  }
310
- function W(e) {
324
+ function G(e) {
311
325
  if (e instanceof Error) return e.message;
312
326
  if (typeof e == "string") return e;
313
327
  try {
@@ -318,12 +332,12 @@ function W(e) {
318
332
  }
319
333
  //#endregion
320
334
  //#region src/telemetry.ts
321
- var me = "https://production.otel.picked.app/v1/traces", he = /* @__PURE__ */ new Set(["resolveId", "load"]);
322
- function ge(e = v()) {
335
+ var ve = /* @__PURE__ */ new Set(["resolveId", "load"]);
336
+ function ye(e = v()) {
323
337
  let t = g(), n = Date.now(), r = [], i = /* @__PURE__ */ new Map();
324
338
  return {
325
339
  record: (n, a) => {
326
- if (he.has(n)) {
340
+ if (ve.has(n)) {
327
341
  let e = i.get(n) ?? {
328
342
  calls: 0,
329
343
  totalMs: 0
@@ -366,7 +380,6 @@ function ge(e = v()) {
366
380
  });
367
381
  try {
368
382
  let e = _({
369
- endpoint: me,
370
383
  resource: { "service.name": "picked-vite-plugin" },
371
384
  headers: { "Picked-Telemetry": "vite-plugin" },
372
385
  maxBatchSize: r.length
@@ -377,39 +390,39 @@ function ge(e = v()) {
377
390
  }
378
391
  };
379
392
  }
380
- function _e(e) {
393
+ function be(e) {
381
394
  return typeof e == "object" && !!e && "then" in e;
382
395
  }
383
- function G(e, t, n) {
396
+ function K(e, t, n) {
384
397
  return function(...r) {
385
398
  let i = performance.now(), a = () => {
386
399
  n.record(e, performance.now() - i);
387
400
  }, o = t.apply(this, r);
388
- return _e(o) ? Promise.resolve(o).then(a, a) : a(), o;
401
+ return be(o) ? Promise.resolve(o).then(a, a) : a(), o;
389
402
  };
390
403
  }
391
- function K(e) {
404
+ function q(e) {
392
405
  return typeof e == "function";
393
406
  }
394
- function ve(e, t) {
407
+ function xe(e, t) {
395
408
  if (!e) return t;
396
409
  for (let [n, r] of Object.entries(t)) if (n !== "name") {
397
- if (K(r)) {
398
- Reflect.set(t, n, G(n, r, e));
410
+ if (q(r)) {
411
+ Reflect.set(t, n, K(n, r, e));
399
412
  continue;
400
413
  }
401
- typeof r == "object" && r && "handler" in r && K(r.handler) && Reflect.set(r, "handler", G(n, r.handler, e));
414
+ typeof r == "object" && r && "handler" in r && q(r.handler) && Reflect.set(r, "handler", K(n, r.handler, e));
402
415
  }
403
416
  return t;
404
417
  }
405
418
  //#endregion
406
419
  //#region src/virtual-module/api.ts
407
- function ye() {
420
+ function Se() {
408
421
  return "export const manifestMetadata = {\n mode: 'api',\n fetchedAt: null,\n projectVersionId: null,\n workspaceId: null,\n}\n";
409
422
  }
410
423
  //#endregion
411
424
  //#region src/virtual-module/build.ts
412
- function be(e) {
425
+ function Ce(e) {
413
426
  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");
414
427
  return `import { registerPickedBundle } from '@picked/client/plugins/dynamic-experiences'
415
428
  import projectConfigJson from ${i(t)}
@@ -439,7 +452,7 @@ registerPickedBundle({ projectConfig, experienceContent, manifestMetadata })
439
452
  }
440
453
  //#endregion
441
454
  //#region src/virtual-module/dev.ts
442
- function xe(e) {
455
+ function we(e) {
443
456
  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" : "";
444
457
  return `${a}
445
458
 
@@ -465,10 +478,10 @@ ${s}`;
465
478
  }
466
479
  //#endregion
467
480
  //#region src/index.ts
468
- var Se = 5;
469
- function q(e, t, n) {
481
+ var Te = 5;
482
+ function J(e, t, n) {
470
483
  if (t.length === 0) return;
471
- if (t.length > Se) {
484
+ if (t.length > Te) {
472
485
  console.log(`\n ${e}: ${t.length.toString()} loaded\n`);
473
486
  return;
474
487
  }
@@ -483,10 +496,10 @@ function q(e, t, n) {
483
496
  ""
484
497
  ].join("\n"));
485
498
  }
486
- function Ce(e, t) {
499
+ function Ee(e, t) {
487
500
  t.length !== 0 && console.log(`\n ${e}: ${t.length.toString()} loaded\n`);
488
501
  }
489
- var we = [
502
+ var De = [
490
503
  {
491
504
  header: "Name",
492
505
  value: (e) => e.name
@@ -500,14 +513,14 @@ var we = [
500
513
  value: (e) => e.enabled ? "\x1B[32m enabled\x1B[0m" : "\x1B[2mdisabled\x1B[0m"
501
514
  },
502
515
  {
503
- header: "Weight",
504
- value: (e) => `${e.weight.toString()}%`.padStart(6)
516
+ header: "Split",
517
+ value: (e) => de(e)
505
518
  },
506
519
  {
507
520
  header: "Ver",
508
521
  value: (e) => `v${e.version.toString()}`
509
522
  }
510
- ], Te = [
523
+ ], Oe = [
511
524
  {
512
525
  header: "Name",
513
526
  value: (e) => e.name
@@ -528,7 +541,7 @@ var we = [
528
541
  header: "Targets",
529
542
  value: (e) => e.targets.length.toString()
530
543
  }
531
- ], Ee = [
544
+ ], ke = [
532
545
  {
533
546
  header: "Name",
534
547
  value: (e) => e.name
@@ -541,7 +554,7 @@ var we = [
541
554
  header: "Fields",
542
555
  value: (e) => (e.fieldIds?.length ?? 0).toString()
543
556
  }
544
- ], De = [
557
+ ], Ae = [
545
558
  {
546
559
  header: "Name",
547
560
  value: (e) => e.name
@@ -558,41 +571,41 @@ var we = [
558
571
  header: "Required",
559
572
  value: (e) => e.required ? "yes" : "no"
560
573
  }
561
- ], Oe = [{
574
+ ], je = [{
562
575
  header: "Name",
563
576
  value: (e) => e.name
564
577
  }, {
565
578
  header: "Key",
566
579
  value: (e) => e.key
567
580
  }];
568
- function ke() {
569
- return "0.0.1-dev.1787537193674";
581
+ function Me() {
582
+ return "0.0.1-dev.1787788898336";
570
583
  }
571
- var Ae = "https://api.picked.app", J = "virtual:picked/data", Y = `\0${J}`;
572
- function X(e) {
573
- for (let t of Object.values(e)) if (t.type === "chunk" && t.moduleIds.includes(Y)) return t.fileName;
584
+ var Ne = "https://api.picked.app", Y = "virtual:picked/data", X = `\0${Y}`;
585
+ function Pe(e) {
586
+ for (let t of Object.values(e)) if (t.type === "chunk" && t.moduleIds.includes(X)) return t.fileName;
574
587
  }
575
- function je(e, t) {
588
+ function Fe(e, t) {
576
589
  return e === "" || e.endsWith("/") ? `${e}${t}` : `${e}/${t}`;
577
590
  }
578
- async function Me(e) {
591
+ async function Ie(e) {
579
592
  try {
580
593
  let t = await o({
581
594
  config: e,
582
595
  onWarn: (e) => {
583
- N.warn(e);
596
+ I.warn(e);
584
597
  }
585
598
  });
586
- N.info(`generated types at ${t.typesOutput}`);
599
+ I.info(`generated types at ${t.typesOutput}`);
587
600
  } catch (e) {
588
601
  let t = e instanceof Error ? e.message : String(e);
589
602
  throw Error(`type generation failed: ${t}. Fix the schema source, or set \`generateTypes: false\` on the picked plugin to skip it.`);
590
603
  }
591
604
  }
592
- function Ne(e, t, n) {
605
+ function Le(e, t, n) {
593
606
  return e && c(t, n) ? e : null;
594
607
  }
595
- async function Pe(e, t) {
608
+ async function Re(e, t) {
596
609
  let n = await d(e, t);
597
610
  if (!n) throw Error("picked.config.{ts,js,json} is required. Add a picked.config.ts with projectId and apiUrl.");
598
611
  return n;
@@ -600,59 +613,59 @@ async function Pe(e, t) {
600
613
  function Z(e, t, n) {
601
614
  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.`);
602
615
  }
603
- function Fe(e) {
616
+ function ze(e) {
604
617
  let t = [];
605
618
  if (e.projectId !== void 0 && t.push("`projectId`"), e.apiUrl !== void 0 && t.push("`apiUrl`"), t.length === 0) return;
606
619
  let n = t.length > 1;
607
- N.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.`);
620
+ I.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.`);
608
621
  }
609
- async function Ie(e, t) {
622
+ async function Be(e, t) {
610
623
  let n = await u(e);
611
- n && n.projectId !== t && N.warn(`using project "${t}" (picked.config default: "${n.projectId}") — run 'picked status' to inspect`);
624
+ n && n.projectId !== t && I.warn(`using project "${t}" (picked.config default: "${n.projectId}") — run 'picked status' to inspect`);
612
625
  }
613
626
  var Q = /* @__PURE__ */ new Map();
614
- function Le(e, t, n) {
627
+ function Ve(e, t, n) {
615
628
  return JSON.stringify([
616
629
  e,
617
630
  t,
618
631
  n
619
632
  ]);
620
633
  }
621
- function Re(t = {}) {
622
- let i = t.mode ?? "bundle", o = t.generateTypes ?? !0, s = [], c = process.cwd(), d = "serve", f = "/", p = null, m = !1, h, g, _ = null, v = l() ? null : ge();
623
- return ve(v, {
634
+ function He(t = {}) {
635
+ let i = t.mode ?? "bundle", o = t.generateTypes ?? !0, s = [], c = process.cwd(), d = "serve", f = "/", p = null, m = !1, h, g, _ = null, v = l() ? null : ye();
636
+ return xe(v, {
624
637
  name: "picked",
625
638
  config: async (l, f) => {
626
639
  d = f.command, c = l.root === void 0 ? process.cwd() : n(process.cwd(), l.root);
627
640
  let { projectId: y, apiUrl: b } = t, x = await u(c);
628
- Z("projectId", y, x?.projectId), Z("apiUrl", b, x?.apiUrl), Fe({
641
+ Z("projectId", y, x?.projectId), Z("apiUrl", b, x?.apiUrl), ze({
629
642
  projectId: y,
630
643
  apiUrl: b
631
- }), p = await Pe(c, {
644
+ }), p = await Re(c, {
632
645
  projectId: y,
633
646
  apiUrl: b
634
647
  });
635
648
  let { projectId: S, apiUrl: C, previewToken: w } = p;
636
- v = Ne(v, p, t.telemetry), N.banner(), o && !m && (m = !0, await Me(p)), C !== Ae && N.warn(`using custom API URL: ${C}`), await Ie(c, S);
637
- let T = r("vite-plugin", ke());
638
- if (i === "api") N.debug("mode is 'api': skipping the project-config prefetch");
649
+ v = Le(v, p, t.telemetry), I.banner(), o && !m && (m = !0, await Ie(p)), C !== Ne && I.warn(`using custom API URL: ${C}`), await Be(c, S);
650
+ let T = r("vite-plugin", Me());
651
+ if (i === "api") I.debug("mode is 'api': skipping the project-config prefetch");
639
652
  else if (f.command === "build") {
640
- let t = Le(C, S, c);
653
+ let t = Ve(C, S, c);
641
654
  h = t;
642
655
  let n = Q.get(t);
643
656
  n === void 0 && (n = (async () => {
644
- N.info(`prefetching project config + content for "${S}"`);
645
- let t = B(c), n = e(t.pickedDir), r = performance.now(), i = await H({
657
+ I.info(`prefetching project config + content for "${S}"`);
658
+ let t = U(c), n = e(t.pickedDir), r = performance.now(), i = await he({
646
659
  apiUrl: C,
647
660
  projectId: S,
648
661
  projectRoot: c,
649
662
  headers: T,
650
663
  previewToken: w ?? void 0
651
664
  }), a = (performance.now() - r).toFixed(0);
652
- await oe(c, n);
665
+ await se(c, n);
653
666
  let o = i.config;
654
667
  return $(o, a), {
655
- virtualSource: be({
668
+ virtualSource: Ce({
656
669
  projectConfigPath: t.projectConfigPath,
657
670
  experienceContentPaths: i.experienceContentPaths,
658
671
  manifestMetadata: {
@@ -662,21 +675,21 @@ function Re(t = {}) {
662
675
  workspaceId: i.manifest.workspaceId
663
676
  }
664
677
  }),
665
- features: R(o.features)
678
+ features: V(o.features)
666
679
  };
667
680
  })(), n.catch(() => Q.delete(t)), Q.set(t, n));
668
681
  let r = await n;
669
682
  g = r.virtualSource, s = r.features;
670
- } else if (f.mode === "production") N.debug("skipping the dev project-config fetch for a production serve resolution");
683
+ } else if (f.mode === "production") I.debug("skipping the dev project-config fetch for a production serve resolution");
671
684
  else {
672
- N.info(`fetching project config for "${S}" (dev)`);
685
+ I.info(`fetching project config for "${S}" (dev)`);
673
686
  let e = performance.now(), t = () => a(C, S, {
674
687
  headers: T,
675
688
  previewToken: w ?? void 0
676
- }), n = I(C) ? await L(t, (e, t, n) => {
677
- N.info(`local API not ready, retrying in ${(n / 1e3).toString()}s (${e.toString()}/${t.toString()})`);
689
+ }), n = z(C) ? await B(t, (e, t, n) => {
690
+ I.info(`local API not ready, retrying in ${(n / 1e3).toString()}s (${e.toString()}/${t.toString()})`);
678
691
  }) : await t(), r = (performance.now() - e).toFixed(0);
679
- _ = n, n ? (s = R(n.features), $(n, r)) : N.warn(`failed to fetch project config for "${S}" (${r}ms)`);
692
+ _ = n, n ? (s = V(n.features), $(n, r)) : I.warn(`failed to fetch project config for "${S}" (${r}ms)`);
680
693
  }
681
694
  },
682
695
  configResolved(e) {
@@ -693,9 +706,9 @@ function Re(t = {}) {
693
706
  order: "post",
694
707
  handler(e, t) {
695
708
  if (i === "api" || t.bundle === void 0) return;
696
- let n = X(t.bundle);
709
+ let n = Pe(t.bundle);
697
710
  if (n === void 0) return;
698
- let r = je(f, n);
711
+ let r = Fe(f, n);
699
712
  if (!e.includes(`"${r}"`)) return [{
700
713
  tag: "link",
701
714
  attrs: {
@@ -708,14 +721,14 @@ function Re(t = {}) {
708
721
  }
709
722
  },
710
723
  resolveId(e) {
711
- if (e === J) return Y;
724
+ if (e === Y) return X;
712
725
  },
713
726
  load(e) {
714
- if (e === Y) {
715
- if (i === "api") return ye();
727
+ if (e === X) {
728
+ if (i === "api") return Se();
716
729
  if (d === "build") return g;
717
730
  if (!p) throw Error("picked plugin config hook must run before virtual module load");
718
- return xe({
731
+ return we({
719
732
  apiUrl: p.apiUrl,
720
733
  projectId: p.projectId,
721
734
  projectConfig: _,
@@ -725,7 +738,7 @@ function Re(t = {}) {
725
738
  },
726
739
  configureServer(e) {
727
740
  if (t.disableLauncher) return;
728
- e.middlewares.use(ae(() => S(s)));
741
+ e.middlewares.use(oe(() => E(s)));
729
742
  let n = e.printUrls.bind(e);
730
743
  e.printUrls = () => {
731
744
  let t = e.resolvedUrls?.local[0];
@@ -741,13 +754,13 @@ function Re(t = {}) {
741
754
  handler(e, n) {
742
755
  if (!t.disableLauncher) {
743
756
  if ("index.html" in n) {
744
- N.debug("index.html came from the build; skipping the launcher page");
757
+ I.debug("index.html came from the build; skipping the launcher page");
745
758
  return;
746
759
  }
747
760
  this.emitFile({
748
761
  type: "asset",
749
762
  fileName: "index.html",
750
- source: S(s)
763
+ source: E(s)
751
764
  });
752
765
  }
753
766
  }
@@ -755,7 +768,7 @@ function Re(t = {}) {
755
768
  });
756
769
  }
757
770
  function $(e, t) {
758
- 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 = [
771
+ let n = V(e.features), r = V(e.experiences), i = V(e.steps), a = V(e.fields), o = V(e.conditions), s = V(e.actions), c = JSON.stringify(e).length, l = [
759
772
  `${n.length.toString()} features`,
760
773
  `${r.length.toString()} experiences`,
761
774
  `${i.length.toString()} steps`,
@@ -763,7 +776,7 @@ function $(e, t) {
763
776
  `${o.length.toString()} conditions`,
764
777
  `${s.length.toString()} actions`
765
778
  ].join(", ");
766
- N.info(`fetched config in ${t}ms (${l})`), q("Features", n, we), q("Experiences", r, Te), q("Steps", i, Ee), q("Fields", a, De), q("Conditions", o, Oe), Ce("Actions", s), N.debug(`config size: ${c.toString()} bytes`);
779
+ I.info(`fetched config in ${t}ms (${l})`), J("Features", n, De), J("Experiences", r, Oe), J("Steps", i, ke), J("Fields", a, Ae), J("Conditions", o, je), Ee("Actions", s), I.debug(`config size: ${c.toString()} bytes`);
767
780
  }
768
781
  //#endregion
769
- export { Re as picked };
782
+ export { He as picked };