@picked/vite-plugin-picked 0.0.1-dev.1795137316505 → 0.0.1-dev.1795567554153

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
@@ -1,38 +1,38 @@
1
1
  import { existsSync as e } from "node:fs";
2
2
  import { join as t, resolve as n } from "node:path";
3
- import { createClientHeaders as r, fetchExperienceContent as i, fetchProject as a } from "@picked/delivery-api-client";
4
- import { generate as o } from "@picked/typegen";
5
- import { SNAPSHOT_FILENAME as s, detectHostEnvironment as c, hasProject as l, isTelemetryEnabled as u, isTelemetryForcedOffByEnvironment as d, loadPickedConfig as f, loadResolvedPickedConfig as p, requireSnapshot as m, resolveSnapshotPath as h } from "@picked/config";
6
- import { appendFile as g, mkdir as _, readFile as v, writeFile as y } from "node:fs/promises";
7
- import { createSpanId as b, createTelemetryEmitter as x, createTraceId as S, toUnixNano as C } from "@picked/telemetry";
3
+ import { createClientHeaders as r, fetchExperienceContent as i, fetchProject as a, splitProjectConfig as o } from "@picked/delivery-api-client";
4
+ import { generate as s } from "@picked/typegen";
5
+ import { SNAPSHOT_FILENAME as c, detectHostEnvironment as l, hasProject as u, isTelemetryEnabled as d, isTelemetryForcedOffByEnvironment as f, loadPickedConfig as p, loadResolvedPickedConfig as m, requireSnapshot as h, resolveSnapshotPath as g } from "@picked/config";
6
+ import { appendFile as _, mkdir as v, readFile as y, rm as b, writeFile as x } from "node:fs/promises";
7
+ import { createSpanId as S, createTelemetryEmitter as C, createTraceId as w, toUnixNano as T } from "@picked/telemetry";
8
8
  //#region \0@oxc-project+runtime@0.154.0/helpers/esm/taggedTemplateLiteral.js
9
- function w(e, t) {
9
+ function E(e, t) {
10
10
  return t ||= e.slice(0), Object.freeze(Object.defineProperties(e, { raw: { value: Object.freeze(t) } }));
11
11
  }
12
12
  //#endregion
13
13
  //#region src/launcher.ts
14
- var ee, te = ["true", "false"], ne = "false";
15
- function re(e) {
14
+ var D, ee = ["true", "false"], te = "false";
15
+ function ne(e) {
16
16
  let t = e.variants;
17
- return !t || t.length === 0 ? te : t.map((e) => String(e.value));
17
+ return !t || t.length === 0 ? ee : t.map((e) => String(e.value));
18
18
  }
19
- function ie(e) {
20
- let t = re(e), n = Math.max(0, t.findIndex((e) => e !== ne));
21
- return t.map((e, t) => `<option value="${D(e)}"${t === n ? " selected" : ""}>${E(e)}</option>`).join("");
19
+ function re(e) {
20
+ let t = ne(e), n = Math.max(0, t.findIndex((e) => e !== te));
21
+ return t.map((e, t) => `<option value="${A(e)}"${t === n ? " selected" : ""}>${k(e)}</option>`).join("");
22
22
  }
23
- function T(e) {
23
+ function O(e) {
24
24
  let t = JSON.stringify(e).replaceAll("<", String.raw`\u003c`), n = e.length > 0 ? e.map((e) => `
25
25
  <div class="feature-row">
26
26
  <label>
27
- <input type="checkbox" data-feature-id="${D(e.id)}" checked>
28
- <span class="feature-name">${E(e.name)}</span>
29
- <span class="feature-id">${E(e.id)}</span>
27
+ <input type="checkbox" data-feature-id="${A(e.id)}" checked>
28
+ <span class="feature-name">${k(e.name)}</span>
29
+ <span class="feature-id">${k(e.id)}</span>
30
30
  </label>
31
- <select data-value-for="${D(e.id)}">
32
- ${ie(e)}
31
+ <select data-value-for="${A(e.id)}">
32
+ ${re(e)}
33
33
  </select>
34
34
  </div>`).join("") : "<p class=\"text no-features\">No features configured for this project.</p>";
35
- return String.raw(ee ||= w([
35
+ return String.raw(D ||= E([
36
36
  "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <meta name=\"robots\" content=\"noindex, nofollow\">\n <title>Picked</title>\n <style>\n main {\n position: fixed;\n top: 0;\n right: 0;\n bottom: 0;\n left: 0;\n display: grid;\n align-items: center;\n justify-content: center;\n font-family: monospace;\n color: #4A4A4A\n }\n\n .wrap {\n padding-left: 1.5rem;\n padding-right: 1.5rem;\n max-width: 480px;\n width: 100%;\n }\n\n .title {\n font-size: 1.125rem;\n font-weight: 700;\n margin-bottom: 0;\n }\n\n .text {\n margin-top: .5rem;\n font-size: .875rem\n }\n\n .text a {\n color: #4A4A4A;\n text-decoration: none;\n }\n\n .text a:hover {\n cursor: pointer;\n text-decoration: underline\n }\n\n .preview-form {\n margin-top: 2rem;\n display: flex;\n flex-direction: column;\n gap: 0.5rem;\n }\n\n .preview-input {\n padding: 0.5rem;\n border: 1px solid #4A4A4A;\n border-radius: 0;\n font-family: monospace;\n }\n\n .preview-button {\n padding: 0.5rem;\n background: #4A4A4A;\n color: white;\n border: none;\n border-radius: 0;\n cursor: pointer;\n font-family: monospace;\n }\n\n .preview-button:hover {\n opacity: 0.9;\n }\n\n .buttons {\n display: grid;\n gap: 0.5em;\n grid-template-columns: 1fr 1fr;\n }\n\n #copy-status {\n font-size: 1em;\n text-align: right;\n margin-top: 0.5em;\n }\n\n .features-section {\n margin-top: 1.5rem;\n }\n\n .features-label {\n font-weight: 700;\n font-size: .875rem;\n margin-bottom: 0.5rem;\n }\n\n .feature-row {\n display: flex;\n align-items: center;\n justify-content: space-between;\n gap: 0.5rem;\n padding: 0.25rem 0;\n }\n\n .feature-row label {\n display: flex;\n align-items: center;\n gap: 0.5rem;\n cursor: pointer;\n min-width: 0;\n flex: 1;\n }\n\n .feature-name {\n font-size: .875rem;\n }\n\n .feature-id {\n font-size: .75rem;\n color: #888;\n }\n\n .feature-row select {\n font-family: monospace;\n font-size: .75rem;\n padding: 0.125rem 0.25rem;\n border: 1px solid #4A4A4A;\n border-radius: 0;\n background: white;\n flex-shrink: 0;\n }\n\n .no-features {\n color: #888;\n font-style: italic;\n }\n\n .url-history {\n margin-top: 0.5rem;\n font-size: .75rem;\n }\n\n .url-history-item {\n display: flex;\n align-items: center;\n gap: 0.25rem;\n padding: 0.125rem 0;\n }\n\n .url-history-item button {\n background: none;\n border: none;\n cursor: pointer;\n font-family: monospace;\n font-size: .75rem;\n color: #888;\n padding: 0;\n }\n\n .url-history-item button.url-link {\n color: #4A4A4A;\n text-decoration: none;\n text-align: left;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n flex: 1;\n min-width: 0;\n }\n\n .url-history-item button.url-link:hover {\n text-decoration: underline;\n }\n\n .url-history-item button.url-delete:hover {\n color: #b71c1c;\n }\n\n @media (min-width: 640px) {\n .title {\n font-size: 1.25rem\n }\n\n .text {\n font-size: 1rem\n }\n }\n </style>\n</head>\n<body>\n\n<main>\n <div class=\"wrap\">\n <p class=\"title\">Picked</p>\n <p class=\"text\">\n Learn more at\n <a href=\"https://picked.app\">\n https://picked.app\n </a>\n </p>\n <div class=\"preview-form\">\n <input type=\"text\" id=\"url-input\" pattern=\"^(https?://)?.+\" placeholder=\"Enter preview URL\" required\n class=\"preview-input\">\n <div id=\"url-history\" class=\"url-history\"></div>\n <div class=\"features-section\">\n <p class=\"features-label\">Features</p>\n ",
37
37
  "\n </div>\n <div class=\"buttons\">\n <button type=\"button\" class=\"preview-button\" id=\"copy-btn\">Copy</button>\n <button type=\"button\" class=\"preview-button\" id=\"preview-btn\">Preview</button>\n </div>\n <p class=\"text\" id=\"copy-status\" aria-live=\"polite\" style=\"visibility:hidden;\">\n &nbsp;\n </p>\n </div>\n </div>\n\n <script>\n var FEATURES = ",
38
38
  ";\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>"
@@ -42,46 +42,46 @@ function T(e) {
42
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>"
43
43
  ]), n, t);
44
44
  }
45
- function E(e) {
45
+ function k(e) {
46
46
  return e.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll("\"", "&quot;");
47
47
  }
48
- function D(e) {
48
+ function A(e) {
49
49
  return e.replaceAll("&", "&amp;").replaceAll("\"", "&quot;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
50
50
  }
51
51
  //#endregion
52
52
  //#region src/log.ts
53
- var O = "picked", ae = "\x1B[0m";
54
- function oe() {
53
+ var j = "picked", ie = "\x1B[0m";
54
+ function ae() {
55
55
  let e = process.env.NO_COLOR;
56
56
  return e === "1" || e === "true";
57
57
  }
58
- function k(e) {
59
- return (t) => oe() ? t : `${e}${t}${ae}`;
58
+ function M(e) {
59
+ return (t) => ae() ? t : `${e}${t}${ie}`;
60
60
  }
61
- var se = [
61
+ var oe = [
62
62
  "debug",
63
63
  "info",
64
64
  "warn",
65
65
  "error",
66
66
  "silent"
67
- ], A = {
67
+ ], N = {
68
68
  debug: {
69
- color: k("\x1B[2m"),
69
+ color: M("\x1B[2m"),
70
70
  log: console.debug,
71
71
  enabled: !1
72
72
  },
73
73
  info: {
74
- color: k("\x1B[36m"),
74
+ color: M("\x1B[36m"),
75
75
  log: console.log,
76
76
  enabled: !0
77
77
  },
78
78
  warn: {
79
- color: k("\x1B[33m"),
79
+ color: M("\x1B[33m"),
80
80
  log: console.warn,
81
81
  enabled: !0
82
82
  },
83
83
  error: {
84
- color: k("\x1B[31m"),
84
+ color: M("\x1B[31m"),
85
85
  log: console.error,
86
86
  enabled: !0
87
87
  },
@@ -90,49 +90,49 @@ var se = [
90
90
  enabled: !1
91
91
  }
92
92
  };
93
- function ce(e, t) {
94
- return `${(/* @__PURE__ */ new Date()).toLocaleTimeString()} [${t ? `${O}:${t}` : O}] ${e}`;
93
+ function se(e, t) {
94
+ return `${(/* @__PURE__ */ new Date()).toLocaleTimeString()} [${t ? `${j}:${t}` : j}] ${e}`;
95
95
  }
96
- function j(e, t, n, r) {
96
+ function P(e, t, n, r) {
97
97
  if (!e.enabled) return;
98
- let i = ce(t, r);
98
+ let i = se(t, r);
99
99
  e.log(e.color ? e.color(i) : i), n !== void 0 && e.log(n);
100
100
  }
101
- function M(e) {
102
- let t = A[e], n = /* @__PURE__ */ new Set();
101
+ function F(e) {
102
+ let t = N[e], n = /* @__PURE__ */ new Set();
103
103
  return Object.assign((e, n, r) => {
104
- j(t, e, n, r);
104
+ P(t, e, n, r);
105
105
  }, { once(e, r, i) {
106
- t.enabled && !n.has(e) && (n.add(e), j(t, e, r, i));
106
+ t.enabled && !n.has(e) && (n.add(e), P(t, e, r, i));
107
107
  } });
108
108
  }
109
- function le(e) {
110
- let t = se.indexOf(e);
111
- if (t === -1) j(A.error, `invalid log level: ${e}`);
112
- else for (let [e, n] of se.entries()) A[n].enabled = e >= t;
109
+ function ce(e) {
110
+ let t = oe.indexOf(e);
111
+ if (t === -1) P(N.error, `invalid log level: ${e}`);
112
+ else for (let [e, n] of oe.entries()) N[n].enabled = e >= t;
113
113
  }
114
- var N = k("\x1B[34m"), P = k("\x1B[36m");
115
- function ue() {
114
+ var I = M("\x1B[34m"), L = M("\x1B[36m");
115
+ function le() {
116
116
  let e = [
117
- ` ${N("_")} ${P("_")} _ _ _`,
118
- `${N("(_)")} ${P("(_)")} _ __(_)__| |_____ __| |`,
119
- ` ${N("_")} ${N("_")} | '_ \\ / _| / / -_) _\` |`,
120
- `${N("(_)")} ${N("(_)")} | .__/_\\__|_\\_\\___\\__,_|`,
117
+ ` ${I("_")} ${L("_")} _ _ _`,
118
+ `${I("(_)")} ${L("(_)")} _ __(_)__| |_____ __| |`,
119
+ ` ${I("_")} ${I("_")} | '_ \\ / _| / / -_) _\` |`,
120
+ `${I("(_)")} ${I("(_)")} | .__/_\\__|_\\_\\___\\__,_|`,
121
121
  " |_|\n "
122
122
  ];
123
123
  console.log(e.join("\n"));
124
124
  }
125
- var F = {
126
- banner: ue,
127
- debug: M("debug"),
128
- info: M("info"),
129
- warn: M("warn"),
130
- error: M("error"),
131
- setLevel: le
125
+ var R = {
126
+ banner: le,
127
+ debug: F("debug"),
128
+ info: F("info"),
129
+ warn: F("warn"),
130
+ error: F("error"),
131
+ setLevel: ce
132
132
  };
133
133
  //#endregion
134
134
  //#region src/middleware.ts
135
- function de(e) {
135
+ function ue(e) {
136
136
  return (t, n, r) => {
137
137
  if (t.method !== "GET") {
138
138
  r();
@@ -149,28 +149,28 @@ function de(e) {
149
149
  }
150
150
  //#endregion
151
151
  //#region src/gitignore.ts
152
- var I = ".picked/";
153
- async function fe(n, r) {
152
+ var z = ".picked/";
153
+ async function de(n, r) {
154
154
  if (r) return;
155
155
  let i = t(n, ".gitignore");
156
156
  if (!e(i)) {
157
- await y(i, `${I}
157
+ await x(i, `${z}
158
158
  `);
159
159
  return;
160
160
  }
161
- let a = await v(i, "utf8");
162
- if (pe(a)) return;
163
- let o = `${a.length > 0 && !a.endsWith("\n") ? "\n" : ""}${I}
161
+ let a = await y(i, "utf8");
162
+ if (fe(a)) return;
163
+ let o = `${a.length > 0 && !a.endsWith("\n") ? "\n" : ""}${z}
164
164
  `;
165
- await g(i, o);
165
+ await _(i, o);
166
166
  }
167
- function pe(e) {
168
- return e.split(/\r?\n/).map((e) => e.trim()).some((e) => e === I || e === ".picked");
167
+ function fe(e) {
168
+ return e.split(/\r?\n/).map((e) => e.trim()).some((e) => e === z || e === ".picked");
169
169
  }
170
170
  //#endregion
171
171
  //#region src/retry.ts
172
- var L = 6, me = 5e3;
173
- function R(e) {
172
+ var B = 6, pe = 5e3;
173
+ function V(e) {
174
174
  let t;
175
175
  try {
176
176
  t = new URL(e).hostname;
@@ -179,12 +179,12 @@ function R(e) {
179
179
  }
180
180
  return t === "localhost" || t === "127.0.0.1" || t === "::1" || t === "[::1]" ? !0 : t === "api.picked.app" ? !1 : t.endsWith(".picked.app") || t.endsWith(".picked-dev.app");
181
181
  }
182
- function he(e) {
182
+ function me(e) {
183
183
  return new Promise((t) => {
184
184
  setTimeout(t, e);
185
185
  });
186
186
  }
187
- async function z(e, t) {
187
+ async function H(e, t) {
188
188
  let n = null, r = null;
189
189
  try {
190
190
  n = await e();
@@ -192,9 +192,9 @@ async function z(e, t) {
192
192
  r = e;
193
193
  }
194
194
  if (n !== null) return n;
195
- for (let i = 1; i <= L; i++) {
196
- let a = me * 2 ** (i - 1);
197
- t(i, L, a), await he(a), r = null;
195
+ for (let i = 1; i <= B; i++) {
196
+ let a = pe * 2 ** (i - 1);
197
+ t(i, B, a), await me(a), r = null;
198
198
  try {
199
199
  n = await e();
200
200
  } catch (e) {
@@ -207,10 +207,10 @@ async function z(e, t) {
207
207
  }
208
208
  //#endregion
209
209
  //#region src/util.ts
210
- function B(e) {
210
+ function U(e) {
211
211
  return Array.isArray(e) ? e : [];
212
212
  }
213
- function ge(e) {
213
+ function he(e) {
214
214
  let t = e.variants, n = (t ?? []).reduce((e, t) => e + t.weight, 0);
215
215
  return !t || t.length === 0 || n === 0 ? `${e.weight.toString()}%` : t.map((e) => {
216
216
  let t = Math.round(100 * e.weight / n);
@@ -219,73 +219,92 @@ function ge(e) {
219
219
  }
220
220
  //#endregion
221
221
  //#region src/prefetch.ts
222
- var V = 2;
223
- function H(e) {
222
+ var W = 2;
223
+ function G(e) {
224
224
  let n = t(e, ".picked");
225
225
  return {
226
226
  pickedDir: n,
227
227
  manifestPath: t(n, "manifest.json"),
228
228
  projectConfigPath: t(n, "project-config.json"),
229
+ projectManifestPath: t(n, "project-manifest.json"),
230
+ flowsDir: t(n, "flows"),
229
231
  experiencesDir: t(n, "experiences")
230
232
  };
231
233
  }
232
- async function _e(t) {
234
+ async function ge(t) {
233
235
  if (!e(t)) return null;
234
236
  try {
235
- let e = await v(t, "utf8"), n = JSON.parse(e);
236
- return ve(n) ? n : null;
237
+ let e = await y(t, "utf8"), n = JSON.parse(e);
238
+ return _e(n) ? n : null;
237
239
  } catch {
238
240
  return null;
239
241
  }
240
242
  }
241
- function ve(e) {
243
+ function _e(e) {
242
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));
243
245
  }
244
- function ye(e) {
246
+ function ve(e) {
245
247
  let t = /* @__PURE__ */ new Set();
246
- for (let n of B(e.steps)) n.layoutContentId && t.add(n.id);
248
+ for (let n of U(e.steps)) n.layoutContentId && t.add(n.id);
247
249
  if (t.size === 0) return [];
248
250
  let n = [];
249
- for (let r of B(e.experiences)) B(r.nodes).some((e) => e.type === "step" && t.has(e.stepId)) && n.push(r.id);
251
+ for (let r of U(e.experiences)) U(r.nodes).some((e) => e.type === "step" && t.has(e.stepId)) && n.push(r.id);
250
252
  return n;
251
253
  }
252
- async function be(n) {
253
- let { apiUrl: r, projectId: i, projectRoot: a, headers: o, previewToken: s, reuseWhenUnchanged: c = !0 } = n, l = H(a), u = await xe(r, i, o, s), d = ye(u);
254
- if (await _(l.experiencesDir, { recursive: !0 }), await y(l.projectConfigPath, JSON.stringify(u, null, 2)), c) {
255
- let t = await _e(l.manifestPath);
256
- if (t?.version === V && t.projectVersionId === u.versionId && t.workspaceId === u.workspaceId) {
257
- let n = U(l, d);
254
+ async function ye(n) {
255
+ let { apiUrl: r, projectId: i, projectRoot: a, headers: o, previewToken: s, reuseWhenUnchanged: c = !0, configLoading: l = "full" } = n, u = G(a), d = await xe(r, i, o, s), f = ve(d);
256
+ await v(u.experiencesDir, { recursive: !0 }), await x(u.projectConfigPath, JSON.stringify(d, null, 2));
257
+ let p = l === "manifest" ? await be(u, d) : {};
258
+ if (c) {
259
+ let t = await ge(u.manifestPath);
260
+ if (t?.version === W && t.projectVersionId === d.versionId && t.workspaceId === d.workspaceId) {
261
+ let n = K(u, f);
258
262
  if (Object.values(n).every((t) => e(t))) return {
259
- config: u,
263
+ config: d,
260
264
  manifest: t,
261
- experienceContentPaths: n
265
+ experienceContentPaths: n,
266
+ experienceFlowPaths: p
262
267
  };
263
- F.info("a manifest-referenced content file is missing; refetching every experience");
268
+ R.info("a manifest-referenced content file is missing; refetching every experience");
264
269
  }
265
270
  }
266
- let f = (/* @__PURE__ */ new Date()).toISOString(), p = [];
267
- for (let e of d) {
268
- let n = await Se(r, i, e, o, s), a = t(l.experiencesDir, `${e}.json`);
269
- await y(a, JSON.stringify(n, null, 2)), p.push({
271
+ let m = (/* @__PURE__ */ new Date()).toISOString(), h = [];
272
+ for (let e of f) {
273
+ let n = await Se(r, i, e, o, s), a = t(u.experiencesDir, `${e}.json`);
274
+ await x(a, JSON.stringify(n, null, 2)), h.push({
270
275
  id: e,
271
- fetchedAt: f
276
+ fetchedAt: m
272
277
  });
273
278
  }
274
- let m = {
275
- version: V,
276
- fetchedAt: f,
277
- projectVersionId: u.versionId,
278
- workspaceId: u.workspaceId,
279
- projectId: u.id,
280
- experiences: p
279
+ let g = {
280
+ version: W,
281
+ fetchedAt: m,
282
+ projectVersionId: d.versionId,
283
+ workspaceId: d.workspaceId,
284
+ projectId: d.id,
285
+ experiences: h
281
286
  };
282
- return await y(l.manifestPath, JSON.stringify(m, null, 2)), {
283
- config: u,
284
- manifest: m,
285
- experienceContentPaths: U(l, d)
287
+ return await x(u.manifestPath, JSON.stringify(g, null, 2)), {
288
+ config: d,
289
+ manifest: g,
290
+ experienceContentPaths: K(u, f),
291
+ experienceFlowPaths: p
286
292
  };
287
293
  }
288
- function U(e, n) {
294
+ async function be(e, n) {
295
+ let { manifest: r, flows: i } = o(n);
296
+ await x(e.projectManifestPath, JSON.stringify(r, null, 2)), await b(e.flowsDir, {
297
+ recursive: !0,
298
+ force: !0
299
+ }), await v(e.flowsDir, { recursive: !0 });
300
+ let a = {};
301
+ for (let [n, r] of i) {
302
+ let i = t(e.flowsDir, `${n}.json`);
303
+ await x(i, JSON.stringify(r, null, 2)), a[n] = i;
304
+ }
305
+ return a;
306
+ }
307
+ function K(e, n) {
289
308
  let r = {};
290
309
  for (let i of n) r[i] = t(e.experiencesDir, `${i}.json`);
291
310
  return r;
@@ -296,11 +315,11 @@ async function xe(e, t, n, r) {
296
315
  previewToken: r
297
316
  }), o;
298
317
  try {
299
- o = R(e) ? await z(i, (e, t, n) => {
300
- F.info(`project config not ready, retrying in ${(n / 1e3).toString()}s (${e.toString()}/${t.toString()})`);
318
+ o = V(e) ? await H(i, (e, t, n) => {
319
+ R.info(`project config not ready, retrying in ${(n / 1e3).toString()}s (${e.toString()}/${t.toString()})`);
301
320
  }) : await i();
302
321
  } catch (n) {
303
- throw Error(`[picked] Build-time fetch of project config failed for "${t}" at ${e}: ${W(n)}`);
322
+ throw Error(`[picked] Build-time fetch of project config failed for "${t}" at ${e}: ${q(n)}`);
304
323
  }
305
324
  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.`);
306
325
  return o;
@@ -313,12 +332,12 @@ async function Se(e, t, n, r, a) {
313
332
  previewToken: a
314
333
  });
315
334
  } catch (t) {
316
- throw Error(`[picked] Build-time fetch of content for experience "${n}" failed at ${e}: ${W(t)}`);
335
+ throw Error(`[picked] Build-time fetch of content for experience "${n}" failed at ${e}: ${q(t)}`);
317
336
  }
318
337
  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.`);
319
338
  return o;
320
339
  }
321
- function W(e) {
340
+ function q(e) {
322
341
  if (e instanceof Error) return e.message;
323
342
  if (typeof e == "string") return e;
324
343
  try {
@@ -330,8 +349,8 @@ function W(e) {
330
349
  //#endregion
331
350
  //#region src/telemetry.ts
332
351
  var Ce = /* @__PURE__ */ new Set(["resolveId", "load"]);
333
- function we(e = S()) {
334
- let t = b(), n = Date.now(), r = [], i = /* @__PURE__ */ new Map();
352
+ function we(e = w()) {
353
+ let t = S(), n = Date.now(), r = [], i = /* @__PURE__ */ new Map();
335
354
  return {
336
355
  record: (n, a) => {
337
356
  if (Ce.has(n)) {
@@ -349,10 +368,10 @@ function we(e = S()) {
349
368
  r.push({
350
369
  name: `picked.vite.${n}`,
351
370
  traceId: e,
352
- spanId: b(),
371
+ spanId: S(),
353
372
  parentSpanId: t,
354
- startTimeUnixNano: C(o - a),
355
- endTimeUnixNano: C(o),
373
+ startTimeUnixNano: T(o - a),
374
+ endTimeUnixNano: T(o),
356
375
  attributes: { "picked.vite.hook": n },
357
376
  status: "ok"
358
377
  });
@@ -360,13 +379,13 @@ function we(e = S()) {
360
379
  flush: async (a) => {
361
380
  let o = {};
362
381
  for (let [e, t] of i) o[`picked.vite.${e}.calls`] = t.calls, o[`picked.vite.${e}.total_ms`] = Math.round(t.totalMs);
363
- let s = c();
382
+ let s = l();
364
383
  r.push({
365
384
  name: "picked.vite.build",
366
385
  traceId: e,
367
386
  spanId: t,
368
- startTimeUnixNano: C(n),
369
- endTimeUnixNano: C(Date.now()),
387
+ startTimeUnixNano: T(n),
388
+ endTimeUnixNano: T(Date.now()),
370
389
  attributes: {
371
390
  "picked.env.provider": s.provider,
372
391
  "picked.env.ci": s.ci,
@@ -376,7 +395,7 @@ function we(e = S()) {
376
395
  status: "ok"
377
396
  });
378
397
  try {
379
- let e = x({
398
+ let e = C({
380
399
  resource: { "service.name": "picked-vite-plugin" },
381
400
  headers: { "Picked-Telemetry": "vite-plugin" },
382
401
  maxBatchSize: r.length
@@ -390,7 +409,7 @@ function we(e = S()) {
390
409
  function Te(e) {
391
410
  return typeof e == "object" && !!e && "then" in e;
392
411
  }
393
- function G(e, t, n) {
412
+ function J(e, t, n) {
394
413
  return function(...r) {
395
414
  let i = performance.now(), a = () => {
396
415
  n.record(e, performance.now() - i);
@@ -398,12 +417,12 @@ function G(e, t, n) {
398
417
  return Te(o) ? Promise.resolve(o).then(a, a) : a(), o;
399
418
  };
400
419
  }
401
- function K(e) {
420
+ function Y(e) {
402
421
  return typeof e == "function";
403
422
  }
404
423
  function Ee(e, t) {
405
424
  if (!e) return t;
406
- for (let [n, r] of Object.entries(t)) n !== "name" && (K(r) ? Reflect.set(t, n, G(n, r, e)) : typeof r == "object" && r && "handler" in r && K(r.handler) && Reflect.set(r, "handler", G(n, r.handler, e)));
425
+ for (let [n, r] of Object.entries(t)) n !== "name" && (Y(r) ? Reflect.set(t, n, J(n, r, e)) : typeof r == "object" && r && "handler" in r && Y(r.handler) && Reflect.set(r, "handler", J(n, r.handler, e)));
407
426
  return t;
408
427
  }
409
428
  //#endregion
@@ -441,9 +460,66 @@ export const manifestMetadata = ${JSON.stringify(r)}
441
460
  registerPickedBundle({ projectConfig, experienceContent, manifestMetadata })
442
461
  `;
443
462
  }
463
+ function ke(e) {
464
+ return Object.entries(e).map(([e, t]) => ` ${JSON.stringify(e)}: () => import(${JSON.stringify(t)}).then((m) => m.default ?? m),`).join("\n");
465
+ }
466
+ function Ae(e) {
467
+ let { projectManifestPath: t, experienceFlowPaths: n, experienceContentPaths: r, manifestMetadata: i } = e;
468
+ return `import { registerPickedBundle } from '@picked/client/plugins/dynamic-experiences'
469
+ import projectManifestJson from ${JSON.stringify(t)}
470
+
471
+ const flowImporters = {
472
+ ${ke(n)}
473
+ }
474
+
475
+ const experienceImporters = {
476
+ ${ke(r)}
477
+ }
478
+
479
+ /**
480
+ * Loads one lazily imported JSON file for an experience, or resolves \`null\` when it has none.
481
+ */
482
+ async function importFor(importers, experience) {
483
+ const id = typeof experience === 'string' ? experience : experience?.id
484
+ if (!id || !Object.hasOwn(importers, id)) return null
485
+ try {
486
+ return await importers[id]()
487
+ } catch {
488
+ return null
489
+ }
490
+ }
491
+
492
+ export const projectManifest = projectManifestJson
493
+
494
+ export async function experienceFlow(experience) {
495
+ return importFor(flowImporters, experience)
496
+ }
497
+
498
+ export async function experienceContent(experience, _options) {
499
+ return importFor(experienceImporters, experience)
500
+ }
501
+
502
+ export const manifestMetadata = ${JSON.stringify(i)}
503
+
504
+ registerPickedBundle({ projectManifest, experienceFlow, experienceContent, manifestMetadata })
505
+ `;
506
+ }
507
+ //#endregion
508
+ //#region src/virtual-module/flow.ts
509
+ var je = "virtual:picked/data/flow/";
510
+ function Me(e) {
511
+ return e.experiences.map((e, t) => {
512
+ let n = JSON.stringify(je + t.toString());
513
+ return ` ${JSON.stringify(e.id)}: () => import(${n}).then((m) => m.default),`;
514
+ }).join("\n");
515
+ }
516
+ function Ne(e, t) {
517
+ let n = e && /^\d+$/.test(t) ? e.experiences[Number(t)] : void 0, r = e && n ? o(e).flows.get(n.id) ?? null : null;
518
+ return `export default ${JSON.stringify(r)}\n`;
519
+ }
444
520
  //#endregion
445
521
  //#region src/virtual-module/dev.ts
446
- function ke(e) {
522
+ function Pe(e) {
447
523
  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" : "";
448
524
  return `${a}
449
525
 
@@ -467,12 +543,46 @@ export const manifestMetadata = {
467
543
  }
468
544
  ${s}`;
469
545
  }
546
+ function Fe(e) {
547
+ let { apiUrl: t, projectId: n, projectConfig: r, previewToken: i } = e, a = r ? o(r) : null, s = a ? "import { fetchExperienceContent, registerPickedBundle } from '@picked/client/plugins/dynamic-experiences'" : "import { fetchProjectManifest, fetchExperienceFlow, fetchExperienceContent } from '@picked/client/plugins/dynamic-experiences'", c = a ? `export const projectManifest = ${JSON.stringify(a.manifest)}` : "export const projectManifest = await fetchProjectManifest(apiUrl, projectId, { previewToken: previewToken ?? undefined })", l = r ? `const flowImporters = {
548
+ ${Me(r)}
549
+ }
550
+
551
+ export async function experienceFlow(experience) {
552
+ const id = typeof experience === 'string' ? experience : experience?.id
553
+ if (!id || !Object.hasOwn(flowImporters, id)) return null
554
+ return await flowImporters[id]()
555
+ }` : "export async function experienceFlow(experience) {\n if (!projectManifest || !experience?.id) return null\n return await fetchExperienceFlow(\n apiUrl,\n projectId,\n { experienceId: experience.id, versionId: previewToken ? null : projectManifest.versionId },\n { previewToken: previewToken ?? undefined },\n )\n}", u = a ? "\nregisterPickedBundle({ projectManifest, experienceFlow, experienceContent, manifestMetadata })\n" : "";
556
+ return `${s}
557
+
558
+ const apiUrl = ${JSON.stringify(t)}
559
+ const projectId = ${JSON.stringify(n)}
560
+ const previewToken = ${JSON.stringify(i ?? null)}
561
+
562
+ ${c}
563
+
564
+ ${l}
565
+
566
+ export async function experienceContent(experience, options) {
567
+ const id = typeof experience === 'string' ? experience : experience?.id
568
+ if (!id) return null
569
+ return await fetchExperienceContent(apiUrl, projectId, id, { previewToken: previewToken ?? undefined, ...options })
570
+ }
571
+
572
+ export const manifestMetadata = {
573
+ mode: 'dev',
574
+ fetchedAt: null,
575
+ projectVersionId: projectManifest?.versionId ?? null,
576
+ workspaceId: projectManifest?.workspaceId ?? null,
577
+ }
578
+ ${u}`;
579
+ }
470
580
  //#endregion
471
581
  //#region src/virtual-module/snapshot.ts
472
- var q = "virtual:picked/data/experience/";
473
- function Ae(e) {
582
+ var X = "virtual:picked/data/experience/";
583
+ function Ie(e) {
474
584
  let t = Object.keys(e.experiences).map((e, t) => {
475
- let n = JSON.stringify(q + t.toString());
585
+ let n = JSON.stringify(X + t.toString());
476
586
  return ` ${JSON.stringify(e)}: () => import(${n}).then((m) => m.default),`;
477
587
  }).join("\n"), n = {
478
588
  mode: "snapshot",
@@ -500,16 +610,57 @@ export const manifestMetadata = ${JSON.stringify(n)}
500
610
  registerPickedBundle({ projectConfig, experienceContent, manifestMetadata })
501
611
  `;
502
612
  }
503
- function je(e, t) {
613
+ function Le(e, t) {
504
614
  let n = /^\d+$/.test(t) ? Object.keys(e.experiences)[Number(t)] : void 0, r = n === void 0 ? null : e.experiences[n] ?? null;
505
615
  return `export default ${JSON.stringify(r)}\n`;
506
616
  }
617
+ function Re(e) {
618
+ let t = Object.keys(e.experiences).map((e, t) => {
619
+ let n = JSON.stringify(X + t.toString());
620
+ return ` ${JSON.stringify(e)}: () => import(${n}).then((m) => m.default),`;
621
+ }).join("\n"), n = Me(e.projectConfig), r = {
622
+ mode: "snapshot",
623
+ fetchedAt: null,
624
+ projectVersionId: e.projectVersionId,
625
+ workspaceId: e.workspaceId
626
+ };
627
+ return `import { registerPickedBundle } from '@picked/client/plugins/dynamic-experiences'
628
+
629
+ const experienceImporters = {
630
+ ${t}
631
+ }
632
+
633
+ const flowImporters = {
634
+ ${n}
635
+ }
636
+
637
+ export const projectManifest = ${JSON.stringify(o(e.projectConfig).manifest)}
638
+
639
+ export async function experienceFlow(experience) {
640
+ const id = typeof experience === 'string' ? experience : experience?.id
641
+ if (!id) return null
642
+ if (!Object.hasOwn(flowImporters, id)) return null
643
+ return await flowImporters[id]()
644
+ }
645
+
646
+ export async function experienceContent(experience, _options) {
647
+ const id = typeof experience === 'string' ? experience : experience?.id
648
+ if (!id) return null
649
+ if (!Object.hasOwn(experienceImporters, id)) return null
650
+ return await experienceImporters[id]()
651
+ }
652
+
653
+ export const manifestMetadata = ${JSON.stringify(r)}
654
+
655
+ registerPickedBundle({ projectManifest, experienceFlow, experienceContent, manifestMetadata })
656
+ `;
657
+ }
507
658
  //#endregion
508
659
  //#region src/index.ts
509
- var Me = 5;
510
- function J(e, t, n) {
660
+ var ze = 5;
661
+ function Z(e, t, n) {
511
662
  if (t.length === 0) return;
512
- if (t.length > Me) {
663
+ if (t.length > ze) {
513
664
  console.log(`\n ${e}: ${t.length.toString()} loaded\n`);
514
665
  return;
515
666
  }
@@ -524,10 +675,10 @@ function J(e, t, n) {
524
675
  ""
525
676
  ].join("\n"));
526
677
  }
527
- function Ne(e, t) {
678
+ function Be(e, t) {
528
679
  t.length !== 0 && console.log(`\n ${e}: ${t.length.toString()} loaded\n`);
529
680
  }
530
- var Pe = [
681
+ var Ve = [
531
682
  {
532
683
  header: "Name",
533
684
  value: (e) => e.name
@@ -542,13 +693,13 @@ var Pe = [
542
693
  },
543
694
  {
544
695
  header: "Split",
545
- value: (e) => ge(e)
696
+ value: (e) => he(e)
546
697
  },
547
698
  {
548
699
  header: "Ver",
549
700
  value: (e) => `v${e.version.toString()}`
550
701
  }
551
- ], Fe = [
702
+ ], He = [
552
703
  {
553
704
  header: "Name",
554
705
  value: (e) => e.name
@@ -569,7 +720,7 @@ var Pe = [
569
720
  header: "Targets",
570
721
  value: (e) => e.targets.length.toString()
571
722
  }
572
- ], Ie = [
723
+ ], Ue = [
573
724
  {
574
725
  header: "Name",
575
726
  value: (e) => e.name
@@ -582,7 +733,7 @@ var Pe = [
582
733
  header: "Fields",
583
734
  value: (e) => (e.fieldIds?.length ?? 0).toString()
584
735
  }
585
- ], Le = [
736
+ ], We = [
586
737
  {
587
738
  header: "Name",
588
739
  value: (e) => e.name
@@ -599,166 +750,177 @@ var Pe = [
599
750
  header: "Required",
600
751
  value: (e) => e.required ? "yes" : "no"
601
752
  }
602
- ], Re = [{
753
+ ], Ge = [{
603
754
  header: "Name",
604
755
  value: (e) => e.name
605
756
  }, {
606
757
  header: "Key",
607
758
  value: (e) => e.key
608
759
  }];
609
- function ze() {
610
- return "0.0.1-dev.1795137316505";
760
+ function Ke() {
761
+ return "0.0.1-dev.1795567554153";
611
762
  }
612
- var Be = "https://api.picked.app", Y = "virtual:picked/data", X = `\0${Y}`, Ve = `\0${q}`;
613
- function He(e) {
614
- for (let t of Object.values(e)) if (t.type === "chunk" && t.moduleIds.includes(X)) return t.fileName;
763
+ var qe = "https://api.picked.app", Je = "virtual:picked/data", Ye = `\0${Je}`, Xe = `\0${X}`, Ze = `\0${je}`;
764
+ function Qe(e) {
765
+ for (let t of Object.values(e)) if (t.type === "chunk" && t.moduleIds.includes(Ye)) return t.fileName;
615
766
  }
616
- function Ue(e, t) {
767
+ function $e(e, t) {
617
768
  return e === "" || e.endsWith("/") ? `${e}${t}` : `${e}/${t}`;
618
769
  }
619
- async function We(e) {
770
+ async function et(e) {
620
771
  try {
621
- let t = await o({
772
+ let t = await s({
622
773
  config: e,
623
774
  onWarn: (e) => {
624
- F.warn(e);
775
+ R.warn(e);
625
776
  }
626
777
  });
627
- F.info(`generated types at ${t.typesOutput}`);
778
+ R.info(`generated types at ${t.typesOutput}`);
628
779
  } catch (e) {
629
780
  let t = e instanceof Error ? e.message : String(e);
630
781
  throw Error(`type generation failed: ${t}. Fix the schema source, or set \`generateTypes: false\` on the picked plugin to skip it.`);
631
782
  }
632
783
  }
633
- function Ge(e, t, n) {
634
- return e && u(t, n) ? e : null;
784
+ function tt(e, t, n) {
785
+ return e && d(t, n) ? e : null;
635
786
  }
636
- async function Ke(e, t) {
637
- let n = await p(e, t);
787
+ async function nt(e, t) {
788
+ let n = await m(e, t);
638
789
  if (!n) throw Error("picked.config.{ts,js,json} is required. Add a picked.config.ts with projectId and apiUrl.");
639
790
  return n;
640
791
  }
641
- function Z(e, t, n, r) {
792
+ function Q(e, t, n, r) {
642
793
  if (t === void 0 || n === void 0 || t === n) return;
643
794
  let i = r === void 0 ? `picked.config says "${n}"` : `picked.config \`${r}\` is "${n}"`;
644
795
  throw Error(`picked plugin option \`${e}\` is "${t}", and ${i}. Remove the plugin option; picked.config is the one place this belongs.`);
645
796
  }
646
- async function qe(e) {
647
- let t = await f(e);
648
- return t && l(t) ? t : null;
797
+ async function rt(e) {
798
+ let t = await p(e);
799
+ return t && u(t) ? t : null;
649
800
  }
650
- function Je(e) {
651
- e.data !== void 0 && F.warn("picked plugin option `mode` is deprecated, and a future release drops it. Set `data` in picked.config instead, which the CLI and the type generator read from too.");
801
+ function it(e) {
802
+ e.data !== void 0 && R.warn("picked plugin option `mode` is deprecated, and a future release drops it. Set `data` in picked.config instead, which the CLI and the type generator read from too.");
652
803
  let t = [];
653
804
  if (e.projectId !== void 0 && t.push("`projectId`"), e.apiUrl !== void 0 && t.push("`apiUrl`"), t.length === 0) return;
654
805
  let n = t.length > 1;
655
- F.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.`);
806
+ R.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.`);
656
807
  }
657
- async function Ye(e, t) {
658
- let n = await qe(e);
659
- n && n.projectId !== t && F.warn(`using project "${t}" (picked.config default: "${n.projectId}") — run 'picked status' to inspect`);
808
+ async function at(e, t) {
809
+ let n = await rt(e);
810
+ n && n.projectId !== t && R.warn(`using project "${t}" (picked.config default: "${n.projectId}") — run 'picked status' to inspect`);
660
811
  }
661
- async function Xe(e, t) {
662
- let n = await qe(e);
663
- return Z("projectId", t.projectId, n?.projectId), Z("apiUrl", t.apiUrl, n?.apiUrl), Z("mode", t.data, n?.data, "data"), Je(t), Ke(e, t);
812
+ async function ot(e, t) {
813
+ let n = await rt(e);
814
+ return Q("projectId", t.projectId, n?.projectId), Q("apiUrl", t.apiUrl, n?.apiUrl), Q("mode", t.data, n?.data, "data"), it(t), nt(e, t);
664
815
  }
665
- async function Ze(t) {
666
- if (t.data !== "snapshot") return e(h(t.projectRoot)) && F.warn(`${s} is ignored: the data mode in force is '${t.data}'. Set \`data: 'snapshot'\` in picked.config to build from it, or delete it.`), null;
667
- let n = await m(t);
668
- return F.info(`serving ${s}: project "${n.projectId}", version ${n.projectVersionId ?? "none (preview)"} — run \`picked pull\` to refresh`), n.source === "preview" ? F.warn(`${s} holds preview data, so this run serves unpublished content. Run \`picked pull\` against the published workspace before you release.`) : t.source === "preview" && F.warn(`the preview workspace in force is not read: ${s} holds published data. Run \`picked pull --allow-preview\` to serve the preview.`), n;
816
+ async function st(t) {
817
+ if (t.data !== "snapshot") return e(g(t.projectRoot)) && R.warn(`${c} is ignored: the data mode in force is '${t.data}'. Set \`data: 'snapshot'\` in picked.config to build from it, or delete it.`), null;
818
+ let n = await h(t);
819
+ return R.info(`serving ${c}: project "${n.projectId}", version ${n.projectVersionId ?? "none (preview)"} — run \`picked pull\` to refresh`), n.source === "preview" ? R.warn(`${c} holds preview data, so this run serves unpublished content. Run \`picked pull\` against the published workspace before you release.`) : t.source === "preview" && R.warn(`the preview workspace in force is not read: ${c} holds published data. Run \`picked pull --allow-preview\` to serve the preview.`), n;
669
820
  }
670
- async function Qe(e, t, n, r) {
821
+ async function ct(e, t, n, r) {
671
822
  let i = () => a(e, t, {
672
823
  headers: n,
673
824
  previewToken: r ?? void 0
674
825
  });
675
- return R(e) ? z(i, (e, t, n) => {
676
- F.info(`local API not ready, retrying in ${(n / 1e3).toString()}s (${e.toString()}/${t.toString()})`);
826
+ return V(e) ? H(i, (e, t, n) => {
827
+ R.info(`local API not ready, retrying in ${(n / 1e3).toString()}s (${e.toString()}/${t.toString()})`);
677
828
  }) : i();
678
829
  }
679
- var Q = /* @__PURE__ */ new Map();
680
- function $e(e, t, n) {
830
+ var $ = /* @__PURE__ */ new Map();
831
+ function lt(e, t, n) {
681
832
  return JSON.stringify([
682
833
  e,
683
834
  t,
684
835
  n
685
836
  ]);
686
837
  }
687
- function et(t = {}) {
688
- let i = t.mode, a = i ?? "bundle", o = null, c = t.generateTypes ?? !0, l = [], u = process.cwd(), f = "serve", p = "/", g = null, _ = !1, v, y, b = null, x = d() ? null : we();
689
- return Ee(x, {
838
+ function ut(t = {}) {
839
+ let i = t.mode, a = i ?? "bundle", o = null, s = t.generateTypes ?? !0, l = [], u = process.cwd(), d = "serve", p = "/", m = null, _ = !1, v, y, b = null, x = (e, t) => a === "snapshot" && o && m ? (e.addWatchFile(g(m.projectRoot)), Ne(o.projectConfig, t)) : Ne(b, t), S = f() ? null : we();
840
+ return Ee(S, {
690
841
  name: "picked",
691
- config: async (s, d) => {
692
- f = d.command, u = s.root === void 0 ? process.cwd() : n(process.cwd(), s.root);
693
- let { projectId: p, apiUrl: m } = t;
694
- g = await Xe(u, {
842
+ config: async (c, f) => {
843
+ d = f.command, u = c.root === void 0 ? process.cwd() : n(process.cwd(), c.root);
844
+ let { projectId: p, apiUrl: h } = t;
845
+ m = await ot(u, {
695
846
  projectId: p,
696
- apiUrl: m,
847
+ apiUrl: h,
697
848
  data: i
698
849
  });
699
- let { projectId: h, apiUrl: S, previewToken: C } = g;
700
- if (a = g.data, x = Ge(x, g, t.telemetry), F.banner(), o = await Ze(g), o && (l = B(o.projectConfig.features)), c && !_ && (_ = !0, await We(g)), a === "snapshot") return;
701
- S !== Be && F.warn(`using custom API URL: ${S}`), await Ye(u, h);
702
- let w = r("vite-plugin", ze());
703
- if (a === "api") F.debug("data is 'api': skipping the project-config prefetch");
704
- else if (d.command === "build") {
705
- let t = $e(S, h, u);
850
+ let { projectId: g, apiUrl: x, previewToken: C, configLoading: w } = m;
851
+ if (a = m.data, S = tt(S, m, t.telemetry), R.banner(), o = await st(m), o && (l = U(o.projectConfig.features)), s && !_ && (_ = !0, await et(m)), a === "snapshot") return;
852
+ x !== qe && R.warn(`using custom API URL: ${x}`), await at(u, g);
853
+ let T = r("vite-plugin", Ke()), E = new Set(Object.keys(T).map((e) => e.toLowerCase())), D = {
854
+ ...Object.fromEntries(Object.entries(t.customHeaders ?? {}).filter(([e]) => !E.has(e.toLowerCase()))),
855
+ ...T
856
+ };
857
+ if (a === "api") R.debug("data is 'api': skipping the project-config prefetch");
858
+ else if (f.command === "build") {
859
+ let t = lt(x, g, u);
706
860
  v = t;
707
- let n = Q.get(t);
861
+ let n = $.get(t);
708
862
  n === void 0 && (n = (async () => {
709
- F.info(`prefetching project config + content for "${h}"`);
710
- let t = H(u), n = e(t.pickedDir), r = performance.now(), i = await be({
711
- apiUrl: S,
712
- projectId: h,
863
+ R.info(`prefetching project config + content for "${g}"`);
864
+ let t = G(u), n = e(t.pickedDir), r = performance.now(), i = await ye({
865
+ apiUrl: x,
866
+ projectId: g,
713
867
  projectRoot: u,
714
- headers: w,
715
- previewToken: C ?? void 0
868
+ headers: D,
869
+ previewToken: C ?? void 0,
870
+ configLoading: w
716
871
  }), a = (performance.now() - r).toFixed(0);
717
- await fe(u, n);
872
+ await de(u, n);
718
873
  let o = i.config;
719
- return $(o, a), {
720
- virtualSource: Oe({
874
+ dt(o, a);
875
+ let s = {
876
+ mode: "build",
877
+ fetchedAt: i.manifest.fetchedAt,
878
+ projectVersionId: i.manifest.projectVersionId,
879
+ workspaceId: i.manifest.workspaceId
880
+ };
881
+ return {
882
+ virtualSource: w === "manifest" ? Ae({
883
+ projectManifestPath: t.projectManifestPath,
884
+ experienceFlowPaths: i.experienceFlowPaths,
885
+ experienceContentPaths: i.experienceContentPaths,
886
+ manifestMetadata: s
887
+ }) : Oe({
721
888
  projectConfigPath: t.projectConfigPath,
722
889
  experienceContentPaths: i.experienceContentPaths,
723
- manifestMetadata: {
724
- mode: "build",
725
- fetchedAt: i.manifest.fetchedAt,
726
- projectVersionId: i.manifest.projectVersionId,
727
- workspaceId: i.manifest.workspaceId
728
- }
890
+ manifestMetadata: s
729
891
  }),
730
- features: B(o.features)
892
+ features: U(o.features)
731
893
  };
732
- })(), n.catch(() => Q.delete(t)), Q.set(t, n));
894
+ })(), n.catch(() => $.delete(t)), $.set(t, n));
733
895
  let r = await n;
734
896
  y = r.virtualSource, l = r.features;
735
- } else if (d.mode === "production") F.debug("skipping the dev project-config fetch for a production serve resolution");
897
+ } else if (f.mode === "production") R.debug("skipping the dev project-config fetch for a production serve resolution");
736
898
  else {
737
- F.info(`fetching project config for "${h}" (dev)`);
738
- let e = performance.now(), t = await Qe(S, h, w, C), n = (performance.now() - e).toFixed(0);
739
- b = t, t ? (l = B(t.features), $(t, n)) : F.warn(`failed to fetch project config for "${h}" (${n}ms)`);
899
+ R.info(`fetching project config for "${g}" (dev)`);
900
+ let e = performance.now(), t = await ct(x, g, D, C), n = (performance.now() - e).toFixed(0);
901
+ b = t, t ? (l = U(t.features), dt(t, n)) : R.warn(`failed to fetch project config for "${g}" (${n}ms)`);
740
902
  }
741
903
  },
742
904
  configResolved(e) {
743
905
  p = e.base;
744
906
  },
745
907
  async buildStart() {
746
- a === "snapshot" && g && f === "build" && (o = await m(g));
908
+ a === "snapshot" && m && d === "build" && (o = await h(m));
747
909
  },
748
910
  closeBundle() {
749
- v !== void 0 && Q.delete(v), x?.flush({
750
- "picked.vite.command": f,
911
+ v !== void 0 && $.delete(v), S?.flush({
912
+ "picked.vite.command": d,
751
913
  "picked.data.mode": a,
752
- "picked.source": g?.source ?? "unknown"
914
+ "picked.source": m?.source ?? "unknown"
753
915
  });
754
916
  },
755
917
  transformIndexHtml: {
756
918
  order: "post",
757
919
  handler(e, t) {
758
920
  if (a === "api" || t.bundle === void 0) return;
759
- let n = He(t.bundle);
921
+ let n = Qe(t.bundle);
760
922
  if (n === void 0) return;
761
- let r = Ue(p, n);
923
+ let r = $e(p, n);
762
924
  if (!e.includes(`"${r}"`)) return [{
763
925
  tag: "link",
764
926
  attrs: {
@@ -771,35 +933,36 @@ function et(t = {}) {
771
933
  }
772
934
  },
773
935
  resolveId(e) {
774
- if (e === Y || e.startsWith("virtual:picked/data/experience/")) return `\0${e}`;
936
+ if (e === Je || e.startsWith("virtual:picked/data/experience/") || e.startsWith("virtual:picked/data/flow/")) return `\0${e}`;
775
937
  },
776
938
  load(e) {
777
- if (e.startsWith(Ve) && o && g) return this.addWatchFile(h(g.projectRoot)), je(o, e.slice(Ve.length));
778
- if (e === X) {
779
- if (a === "api") return De();
780
- if (a === "snapshot") {
781
- if (!o || !g) throw Error("picked plugin config hook must run before virtual module load");
782
- return this.addWatchFile(h(g.projectRoot)), Ae(o);
783
- }
784
- if (f === "build") return y;
785
- if (!g) throw Error("picked plugin config hook must run before virtual module load");
786
- return ke({
787
- apiUrl: g.apiUrl,
788
- projectId: g.projectId,
789
- projectConfig: b,
790
- previewToken: g.previewToken ?? void 0
791
- });
939
+ if (e.startsWith(Ze)) return x(this, e.slice(Ze.length));
940
+ if (e.startsWith(Xe) && o && m) return this.addWatchFile(g(m.projectRoot)), Le(o, e.slice(Xe.length));
941
+ if (e !== Ye) return;
942
+ if (a === "api") return De();
943
+ if (a === "snapshot") {
944
+ if (!o || !m) throw Error("picked plugin config hook must run before virtual module load");
945
+ return this.addWatchFile(g(m.projectRoot)), m.configLoading === "manifest" ? Re(o) : Ie(o);
792
946
  }
947
+ if (d === "build") return y;
948
+ if (!m) throw Error("picked plugin config hook must run before virtual module load");
949
+ let t = {
950
+ apiUrl: m.apiUrl,
951
+ projectId: m.projectId,
952
+ projectConfig: b,
953
+ previewToken: m.previewToken ?? void 0
954
+ };
955
+ return m.configLoading === "manifest" ? Fe(t) : Pe(t);
793
956
  },
794
957
  configureServer(e) {
795
- if (a === "snapshot" && g) {
796
- let t = h(g.projectRoot), n = (n) => {
797
- n === t && (F.info(`${s} changed; restarting the dev server`), e.restart());
958
+ if (a === "snapshot" && m) {
959
+ let t = g(m.projectRoot), n = (n) => {
960
+ n === t && (R.info(`${c} changed; restarting the dev server`), e.restart());
798
961
  };
799
962
  e.watcher.add(t), e.watcher.on("add", n), e.watcher.on("change", n), e.watcher.on("unlink", n);
800
963
  }
801
964
  if (t.disableLauncher) return;
802
- e.middlewares.use(de(() => T(l)));
965
+ e.middlewares.use(ue(() => O(l)));
803
966
  let n = e.printUrls.bind(e);
804
967
  e.printUrls = () => {
805
968
  let t = e.resolvedUrls?.local[0];
@@ -813,17 +976,17 @@ function et(t = {}) {
813
976
  generateBundle: {
814
977
  order: "post",
815
978
  handler(e, n) {
816
- t.disableLauncher || ("index.html" in n ? F.debug("index.html came from the build; skipping the launcher page") : this.emitFile({
979
+ t.disableLauncher || ("index.html" in n ? R.debug("index.html came from the build; skipping the launcher page") : this.emitFile({
817
980
  type: "asset",
818
981
  fileName: "index.html",
819
- source: T(l)
982
+ source: O(l)
820
983
  }));
821
984
  }
822
985
  }
823
986
  });
824
987
  }
825
- function $(e, t) {
826
- let n = B(e.features), r = B(e.experiences), i = B(e.steps), a = B(e.fields), o = B(e.conditions), s = B(e.actions), c = JSON.stringify(e).length, l = [
988
+ function dt(e, t) {
989
+ let n = U(e.features), r = U(e.experiences), i = U(e.steps), a = U(e.fields), o = U(e.conditions), s = U(e.actions), c = JSON.stringify(e).length, l = [
827
990
  `${n.length.toString()} features`,
828
991
  `${r.length.toString()} experiences`,
829
992
  `${i.length.toString()} steps`,
@@ -831,7 +994,7 @@ function $(e, t) {
831
994
  `${o.length.toString()} conditions`,
832
995
  `${s.length.toString()} actions`
833
996
  ].join(", ");
834
- F.info(`fetched config in ${t}ms (${l})`), J("Features", n, Pe), J("Experiences", r, Fe), J("Steps", i, Ie), J("Fields", a, Le), J("Conditions", o, Re), Ne("Actions", s), F.debug(`config size: ${c.toString()} bytes`);
997
+ R.info(`fetched config in ${t}ms (${l})`), Z("Features", n, Ve), Z("Experiences", r, He), Z("Steps", i, Ue), Z("Fields", a, We), Z("Conditions", o, Ge), Be("Actions", s), R.debug(`config size: ${c.toString()} bytes`);
835
998
  }
836
999
  //#endregion
837
- export { et as picked };
1000
+ export { ut as picked };