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

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 = "https://production.otel.picked.app/v1/traces", ye = /* @__PURE__ */ new Set(["resolveId", "load"]);
336
+ function be(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 (ye.has(n)) {
327
341
  let e = i.get(n) ?? {
328
342
  calls: 0,
329
343
  totalMs: 0
@@ -366,7 +380,7 @@ function ge(e = v()) {
366
380
  });
367
381
  try {
368
382
  let e = _({
369
- endpoint: me,
383
+ endpoint: ve,
370
384
  resource: { "service.name": "picked-vite-plugin" },
371
385
  headers: { "Picked-Telemetry": "vite-plugin" },
372
386
  maxBatchSize: r.length
@@ -377,39 +391,39 @@ function ge(e = v()) {
377
391
  }
378
392
  };
379
393
  }
380
- function _e(e) {
394
+ function xe(e) {
381
395
  return typeof e == "object" && !!e && "then" in e;
382
396
  }
383
- function G(e, t, n) {
397
+ function K(e, t, n) {
384
398
  return function(...r) {
385
399
  let i = performance.now(), a = () => {
386
400
  n.record(e, performance.now() - i);
387
401
  }, o = t.apply(this, r);
388
- return _e(o) ? Promise.resolve(o).then(a, a) : a(), o;
402
+ return xe(o) ? Promise.resolve(o).then(a, a) : a(), o;
389
403
  };
390
404
  }
391
- function K(e) {
405
+ function q(e) {
392
406
  return typeof e == "function";
393
407
  }
394
- function ve(e, t) {
408
+ function Se(e, t) {
395
409
  if (!e) return t;
396
410
  for (let [n, r] of Object.entries(t)) if (n !== "name") {
397
- if (K(r)) {
398
- Reflect.set(t, n, G(n, r, e));
411
+ if (q(r)) {
412
+ Reflect.set(t, n, K(n, r, e));
399
413
  continue;
400
414
  }
401
- typeof r == "object" && r && "handler" in r && K(r.handler) && Reflect.set(r, "handler", G(n, r.handler, e));
415
+ typeof r == "object" && r && "handler" in r && q(r.handler) && Reflect.set(r, "handler", K(n, r.handler, e));
402
416
  }
403
417
  return t;
404
418
  }
405
419
  //#endregion
406
420
  //#region src/virtual-module/api.ts
407
- function ye() {
421
+ function Ce() {
408
422
  return "export const manifestMetadata = {\n mode: 'api',\n fetchedAt: null,\n projectVersionId: null,\n workspaceId: null,\n}\n";
409
423
  }
410
424
  //#endregion
411
425
  //#region src/virtual-module/build.ts
412
- function be(e) {
426
+ function we(e) {
413
427
  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
428
  return `import { registerPickedBundle } from '@picked/client/plugins/dynamic-experiences'
415
429
  import projectConfigJson from ${i(t)}
@@ -439,7 +453,7 @@ registerPickedBundle({ projectConfig, experienceContent, manifestMetadata })
439
453
  }
440
454
  //#endregion
441
455
  //#region src/virtual-module/dev.ts
442
- function xe(e) {
456
+ function Te(e) {
443
457
  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
458
  return `${a}
445
459
 
@@ -465,10 +479,10 @@ ${s}`;
465
479
  }
466
480
  //#endregion
467
481
  //#region src/index.ts
468
- var Se = 5;
469
- function q(e, t, n) {
482
+ var Ee = 5;
483
+ function J(e, t, n) {
470
484
  if (t.length === 0) return;
471
- if (t.length > Se) {
485
+ if (t.length > Ee) {
472
486
  console.log(`\n ${e}: ${t.length.toString()} loaded\n`);
473
487
  return;
474
488
  }
@@ -483,10 +497,10 @@ function q(e, t, n) {
483
497
  ""
484
498
  ].join("\n"));
485
499
  }
486
- function Ce(e, t) {
500
+ function De(e, t) {
487
501
  t.length !== 0 && console.log(`\n ${e}: ${t.length.toString()} loaded\n`);
488
502
  }
489
- var we = [
503
+ var Oe = [
490
504
  {
491
505
  header: "Name",
492
506
  value: (e) => e.name
@@ -500,14 +514,14 @@ var we = [
500
514
  value: (e) => e.enabled ? "\x1B[32m enabled\x1B[0m" : "\x1B[2mdisabled\x1B[0m"
501
515
  },
502
516
  {
503
- header: "Weight",
504
- value: (e) => `${e.weight.toString()}%`.padStart(6)
517
+ header: "Split",
518
+ value: (e) => de(e)
505
519
  },
506
520
  {
507
521
  header: "Ver",
508
522
  value: (e) => `v${e.version.toString()}`
509
523
  }
510
- ], Te = [
524
+ ], ke = [
511
525
  {
512
526
  header: "Name",
513
527
  value: (e) => e.name
@@ -528,7 +542,7 @@ var we = [
528
542
  header: "Targets",
529
543
  value: (e) => e.targets.length.toString()
530
544
  }
531
- ], Ee = [
545
+ ], Ae = [
532
546
  {
533
547
  header: "Name",
534
548
  value: (e) => e.name
@@ -541,7 +555,7 @@ var we = [
541
555
  header: "Fields",
542
556
  value: (e) => (e.fieldIds?.length ?? 0).toString()
543
557
  }
544
- ], De = [
558
+ ], je = [
545
559
  {
546
560
  header: "Name",
547
561
  value: (e) => e.name
@@ -558,41 +572,41 @@ var we = [
558
572
  header: "Required",
559
573
  value: (e) => e.required ? "yes" : "no"
560
574
  }
561
- ], Oe = [{
575
+ ], Me = [{
562
576
  header: "Name",
563
577
  value: (e) => e.name
564
578
  }, {
565
579
  header: "Key",
566
580
  value: (e) => e.key
567
581
  }];
568
- function ke() {
569
- return "0.0.1-dev.1787537193674";
582
+ function Ne() {
583
+ return "0.0.1-dev.1787543060859";
570
584
  }
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;
585
+ var Pe = "https://api.picked.app", Y = "virtual:picked/data", X = `\0${Y}`;
586
+ function Fe(e) {
587
+ for (let t of Object.values(e)) if (t.type === "chunk" && t.moduleIds.includes(X)) return t.fileName;
574
588
  }
575
- function je(e, t) {
589
+ function Ie(e, t) {
576
590
  return e === "" || e.endsWith("/") ? `${e}${t}` : `${e}/${t}`;
577
591
  }
578
- async function Me(e) {
592
+ async function Le(e) {
579
593
  try {
580
594
  let t = await o({
581
595
  config: e,
582
596
  onWarn: (e) => {
583
- N.warn(e);
597
+ I.warn(e);
584
598
  }
585
599
  });
586
- N.info(`generated types at ${t.typesOutput}`);
600
+ I.info(`generated types at ${t.typesOutput}`);
587
601
  } catch (e) {
588
602
  let t = e instanceof Error ? e.message : String(e);
589
603
  throw Error(`type generation failed: ${t}. Fix the schema source, or set \`generateTypes: false\` on the picked plugin to skip it.`);
590
604
  }
591
605
  }
592
- function Ne(e, t, n) {
606
+ function Re(e, t, n) {
593
607
  return e && c(t, n) ? e : null;
594
608
  }
595
- async function Pe(e, t) {
609
+ async function ze(e, t) {
596
610
  let n = await d(e, t);
597
611
  if (!n) throw Error("picked.config.{ts,js,json} is required. Add a picked.config.ts with projectId and apiUrl.");
598
612
  return n;
@@ -600,59 +614,59 @@ async function Pe(e, t) {
600
614
  function Z(e, t, n) {
601
615
  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
616
  }
603
- function Fe(e) {
617
+ function Be(e) {
604
618
  let t = [];
605
619
  if (e.projectId !== void 0 && t.push("`projectId`"), e.apiUrl !== void 0 && t.push("`apiUrl`"), t.length === 0) return;
606
620
  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.`);
621
+ 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
622
  }
609
- async function Ie(e, t) {
623
+ async function Ve(e, t) {
610
624
  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`);
625
+ n && n.projectId !== t && I.warn(`using project "${t}" (picked.config default: "${n.projectId}") — run 'picked status' to inspect`);
612
626
  }
613
627
  var Q = /* @__PURE__ */ new Map();
614
- function Le(e, t, n) {
628
+ function He(e, t, n) {
615
629
  return JSON.stringify([
616
630
  e,
617
631
  t,
618
632
  n
619
633
  ]);
620
634
  }
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, {
635
+ function Ue(t = {}) {
636
+ 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 : be();
637
+ return Se(v, {
624
638
  name: "picked",
625
639
  config: async (l, f) => {
626
640
  d = f.command, c = l.root === void 0 ? process.cwd() : n(process.cwd(), l.root);
627
641
  let { projectId: y, apiUrl: b } = t, x = await u(c);
628
- Z("projectId", y, x?.projectId), Z("apiUrl", b, x?.apiUrl), Fe({
642
+ Z("projectId", y, x?.projectId), Z("apiUrl", b, x?.apiUrl), Be({
629
643
  projectId: y,
630
644
  apiUrl: b
631
- }), p = await Pe(c, {
645
+ }), p = await ze(c, {
632
646
  projectId: y,
633
647
  apiUrl: b
634
648
  });
635
649
  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");
650
+ v = Re(v, p, t.telemetry), I.banner(), o && !m && (m = !0, await Le(p)), C !== Pe && I.warn(`using custom API URL: ${C}`), await Ve(c, S);
651
+ let T = r("vite-plugin", Ne());
652
+ if (i === "api") I.debug("mode is 'api': skipping the project-config prefetch");
639
653
  else if (f.command === "build") {
640
- let t = Le(C, S, c);
654
+ let t = He(C, S, c);
641
655
  h = t;
642
656
  let n = Q.get(t);
643
657
  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({
658
+ I.info(`prefetching project config + content for "${S}"`);
659
+ let t = U(c), n = e(t.pickedDir), r = performance.now(), i = await he({
646
660
  apiUrl: C,
647
661
  projectId: S,
648
662
  projectRoot: c,
649
663
  headers: T,
650
664
  previewToken: w ?? void 0
651
665
  }), a = (performance.now() - r).toFixed(0);
652
- await oe(c, n);
666
+ await se(c, n);
653
667
  let o = i.config;
654
668
  return $(o, a), {
655
- virtualSource: be({
669
+ virtualSource: we({
656
670
  projectConfigPath: t.projectConfigPath,
657
671
  experienceContentPaths: i.experienceContentPaths,
658
672
  manifestMetadata: {
@@ -662,21 +676,21 @@ function Re(t = {}) {
662
676
  workspaceId: i.manifest.workspaceId
663
677
  }
664
678
  }),
665
- features: R(o.features)
679
+ features: V(o.features)
666
680
  };
667
681
  })(), n.catch(() => Q.delete(t)), Q.set(t, n));
668
682
  let r = await n;
669
683
  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");
684
+ } else if (f.mode === "production") I.debug("skipping the dev project-config fetch for a production serve resolution");
671
685
  else {
672
- N.info(`fetching project config for "${S}" (dev)`);
686
+ I.info(`fetching project config for "${S}" (dev)`);
673
687
  let e = performance.now(), t = () => a(C, S, {
674
688
  headers: T,
675
689
  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()})`);
690
+ }), n = z(C) ? await B(t, (e, t, n) => {
691
+ I.info(`local API not ready, retrying in ${(n / 1e3).toString()}s (${e.toString()}/${t.toString()})`);
678
692
  }) : 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)`);
693
+ _ = n, n ? (s = V(n.features), $(n, r)) : I.warn(`failed to fetch project config for "${S}" (${r}ms)`);
680
694
  }
681
695
  },
682
696
  configResolved(e) {
@@ -693,9 +707,9 @@ function Re(t = {}) {
693
707
  order: "post",
694
708
  handler(e, t) {
695
709
  if (i === "api" || t.bundle === void 0) return;
696
- let n = X(t.bundle);
710
+ let n = Fe(t.bundle);
697
711
  if (n === void 0) return;
698
- let r = je(f, n);
712
+ let r = Ie(f, n);
699
713
  if (!e.includes(`"${r}"`)) return [{
700
714
  tag: "link",
701
715
  attrs: {
@@ -708,14 +722,14 @@ function Re(t = {}) {
708
722
  }
709
723
  },
710
724
  resolveId(e) {
711
- if (e === J) return Y;
725
+ if (e === Y) return X;
712
726
  },
713
727
  load(e) {
714
- if (e === Y) {
715
- if (i === "api") return ye();
728
+ if (e === X) {
729
+ if (i === "api") return Ce();
716
730
  if (d === "build") return g;
717
731
  if (!p) throw Error("picked plugin config hook must run before virtual module load");
718
- return xe({
732
+ return Te({
719
733
  apiUrl: p.apiUrl,
720
734
  projectId: p.projectId,
721
735
  projectConfig: _,
@@ -725,7 +739,7 @@ function Re(t = {}) {
725
739
  },
726
740
  configureServer(e) {
727
741
  if (t.disableLauncher) return;
728
- e.middlewares.use(ae(() => S(s)));
742
+ e.middlewares.use(oe(() => E(s)));
729
743
  let n = e.printUrls.bind(e);
730
744
  e.printUrls = () => {
731
745
  let t = e.resolvedUrls?.local[0];
@@ -741,13 +755,13 @@ function Re(t = {}) {
741
755
  handler(e, n) {
742
756
  if (!t.disableLauncher) {
743
757
  if ("index.html" in n) {
744
- N.debug("index.html came from the build; skipping the launcher page");
758
+ I.debug("index.html came from the build; skipping the launcher page");
745
759
  return;
746
760
  }
747
761
  this.emitFile({
748
762
  type: "asset",
749
763
  fileName: "index.html",
750
- source: S(s)
764
+ source: E(s)
751
765
  });
752
766
  }
753
767
  }
@@ -755,7 +769,7 @@ function Re(t = {}) {
755
769
  });
756
770
  }
757
771
  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 = [
772
+ 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
773
  `${n.length.toString()} features`,
760
774
  `${r.length.toString()} experiences`,
761
775
  `${i.length.toString()} steps`,
@@ -763,7 +777,7 @@ function $(e, t) {
763
777
  `${o.length.toString()} conditions`,
764
778
  `${s.length.toString()} actions`
765
779
  ].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`);
780
+ I.info(`fetched config in ${t}ms (${l})`), J("Features", n, Oe), J("Experiences", r, ke), J("Steps", i, Ae), J("Fields", a, je), J("Conditions", o, Me), De("Actions", s), I.debug(`config size: ${c.toString()} bytes`);
767
781
  }
768
782
  //#endregion
769
- export { Re as picked };
783
+ export { Ue as picked };