rosetack 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/deploy/cloudflare/functions/[[path]].ts +61 -0
  2. package/deploy/cloudflare/wrangler.toml +14 -0
  3. package/deploy/k8s/rosetack.yaml +107 -0
  4. package/deploy/netlify/functions/rosetack.ts +38 -0
  5. package/deploy/netlify.toml +17 -0
  6. package/devtools/devtools.html +7 -0
  7. package/devtools/devtools.js +1 -0
  8. package/devtools/manifest.json +8 -0
  9. package/devtools/panel.html +28 -0
  10. package/devtools/panel.js +54 -0
  11. package/dist-cli/compiler.mjs +1346 -492
  12. package/dist-cli/edge.mjs +152 -41
  13. package/dist-cli/rosetack.mjs +1974 -606
  14. package/dist-cli/runtime.mjs +205 -40
  15. package/dist-cli/test.mjs +1425 -508
  16. package/package.json +4 -3
  17. package/src/FRAMEWORK_VERSION +1 -1
  18. package/src/cli/edge.ts +76 -61
  19. package/src/cli/index.ts +516 -293
  20. package/src/cli/prompt.ts +130 -0
  21. package/src/cli/shell.ts +113 -65
  22. package/src/cli/test.ts +9 -70
  23. package/src/compiler/errors.ts +74 -0
  24. package/src/compiler/index.ts +1514 -839
  25. package/src/runtime/index.ts +255 -150
  26. package/src/types/rosetack.d.ts +18 -59
  27. package/templates/admin/package.json +14 -0
  28. package/templates/admin/rosetack.config.js +1 -0
  29. package/templates/admin/src/pages/_middleware.rose +33 -0
  30. package/templates/admin/src/pages/api/items.rose +37 -0
  31. package/templates/admin/src/pages/api/login.rose +25 -0
  32. package/templates/admin/src/pages/index.rose +79 -0
  33. package/templates/api/package.json +14 -0
  34. package/templates/api/rosetack.config.js +1 -0
  35. package/templates/api/src/pages/api/health.rose +7 -0
  36. package/templates/api/src/pages/api/items.rose +46 -0
  37. package/templates/api/src/pages/api/login.rose +24 -0
  38. package/templates/api/src/pages/index.rose +25 -0
  39. package/templates/blog/package.json +14 -0
  40. package/templates/blog/rosetack.config.js +1 -0
  41. package/templates/blog/src/pages/404.rose +2 -0
  42. package/templates/blog/src/pages/_layout.rose +42 -0
  43. package/templates/blog/src/pages/_middleware.rose +74 -0
  44. package/templates/blog/src/pages/admin.rose +85 -0
  45. package/templates/blog/src/pages/api/login.rose +46 -0
  46. package/templates/blog/src/pages/api/posts/[id].rose +37 -0
  47. package/templates/blog/src/pages/api/posts.rose +72 -0
  48. package/templates/blog/src/pages/index.rose +31 -0
  49. package/templates/blog/src/pages/post/[id].rose +36 -0
  50. package/templates/site/package.json +14 -0
  51. package/templates/site/rosetack.config.js +1 -0
  52. package/templates/site/src/pages/404.rose +2 -0
  53. package/templates/site/src/pages/_layout.rose +40 -0
  54. package/templates/site/src/pages/about.rose +6 -0
  55. package/templates/site/src/pages/index.rose +13 -0
  56. package/templates/site/src/pages/pricing.rose +8 -0
@@ -8,6 +8,7 @@ function entry(key, initial) {
8
8
  return e;
9
9
  }
10
10
  function state(key, initial) {
11
+ ownerKeys()?.add(key);
11
12
  const e = entry(key, initial);
12
13
  const getter = () => {
13
14
  if (currentEffect) e.subs.add(currentEffect);
@@ -28,6 +29,44 @@ function setState(key, value) {
28
29
  e.subs.forEach((fn) => fn());
29
30
  }
30
31
  var cleanups = /* @__PURE__ */ new Set();
32
+ var fxOwner = null;
33
+ var fxByOwner = /* @__PURE__ */ new WeakMap();
34
+ var keysByOwner = /* @__PURE__ */ new WeakMap();
35
+ var fxSet = () => {
36
+ if (!fxOwner) return cleanups;
37
+ let s = fxByOwner.get(fxOwner);
38
+ if (!s) {
39
+ s = /* @__PURE__ */ new Set();
40
+ fxByOwner.set(fxOwner, s);
41
+ }
42
+ return s;
43
+ };
44
+ var ownerKeys = () => {
45
+ if (!fxOwner) return null;
46
+ let s = keysByOwner.get(fxOwner);
47
+ if (!s) {
48
+ s = /* @__PURE__ */ new Set();
49
+ keysByOwner.set(fxOwner, s);
50
+ }
51
+ return s;
52
+ };
53
+ function setFxOwner(container) {
54
+ fxOwner = container;
55
+ }
56
+ function resetContainerFx(container) {
57
+ const set = fxByOwner.get(container);
58
+ if (set) {
59
+ set.forEach((fn) => fn());
60
+ fxByOwner.delete(container);
61
+ }
62
+ const keys = keysByOwner.get(container);
63
+ if (keys) {
64
+ keys.forEach((k) => signalMap.delete(k));
65
+ keysByOwner.delete(container);
66
+ }
67
+ dataCache.clear();
68
+ pendingDeltas.clear();
69
+ }
31
70
  function effect(fn) {
32
71
  const wrapped = () => {
33
72
  try {
@@ -41,9 +80,9 @@ function effect(fn) {
41
80
  currentEffect = prev;
42
81
  const cleanup = () => {
43
82
  signalMap.forEach((e) => e.subs.delete(wrapped));
44
- cleanups.delete(cleanup);
83
+ fxSet().delete(cleanup);
45
84
  };
46
- cleanups.add(cleanup);
85
+ fxSet().add(cleanup);
47
86
  return cleanup;
48
87
  }
49
88
  var ESC_MAP = {
@@ -58,32 +97,31 @@ function esc(v) {
58
97
  }
59
98
  function textMark(closes, fn, pair, arg) {
60
99
  const i = closes.push(fn) - 1;
61
- return `<!--\u27E6m:${i}\u27E7-->` + esc(closes[i](arg)) + (pair ? `<!--\u27E6/m:${i}\u27E7-->` : "");
100
+ return `<!--\u27E6m:${i}\u27E7-->` + esc(fn(arg)) + (pair ? `<!--\u27E6/m:${i}\u27E7-->` : "");
62
101
  }
63
102
  function attrMark(closes, fn, name, arg) {
64
103
  const i = closes.push(fn) - 1;
65
- return `${name}="${esc(closes[i](arg))}" data-b="${i}:${name}"`;
104
+ return `${name}="${esc(fn(arg))}" data-b="${i}:${name}"`;
66
105
  }
67
106
  function ifMark(closes, cond, fn, scope) {
68
- const i = closes.length;
69
107
  let snap = null;
70
- closes.push(() => {
71
- if (!cond()) return null;
108
+ const i = closes.push(() => {
109
+ if (!cond()) {
110
+ snap = null;
111
+ return null;
112
+ }
72
113
  if (!snap) {
73
- const c = [];
74
- snap = { html: String(fn(scope, c)), closes: c };
114
+ snap = { html: String(fn(scope, closes)), closes };
75
115
  }
76
116
  return snap;
77
- });
117
+ }) - 1;
78
118
  const r = closes[i]();
79
119
  return `<!--\u27E6i:${i}\u27E7-->` + (r ? r.html : "") + `<!--\u27E6/i:${i}\u27E7-->`;
80
120
  }
81
121
  function eachMark(closes, items, fn) {
82
- const i = closes.length;
83
- closes.push(() => items().map((v) => {
84
- const c = [];
85
- return { html: String(fn(v, c)), closes: c, scope: v };
86
- }));
122
+ const i = closes.push(() => items().map((v) => {
123
+ return { html: String(fn(v, closes)), closes, scope: v };
124
+ })) - 1;
87
125
  let h = `<!--\u27E6l:${i}\u27E7-->`;
88
126
  for (const r of closes[i]()) h += r.html;
89
127
  return h + `<!--\u27E6/l:${i}\u27E7-->`;
@@ -92,6 +130,19 @@ function headMark(closes, fn) {
92
130
  const i = closes.push(fn) - 1;
93
131
  return `<!--\u27E6h:${i}\u27E7-->` + fn() + `<!--\u27E6/h:${i}\u27E7-->`;
94
132
  }
133
+ function rawMark(closes, fn, arg) {
134
+ const i = closes.push((s) => ({ html: String(fn(s) ?? ""), closes })) - 1;
135
+ const r = closes[i](arg);
136
+ return `<!--\u27E6i:${i}\u27E7-->` + r.html + `<!--\u27E6/i:${i}\u27E7-->`;
137
+ }
138
+ function slotBlockMark(closes, hit) {
139
+ if (!hit) return "";
140
+ const i = closes.push(() => {
141
+ if (!hit) return null;
142
+ return { html: String(hit.fn(hit.o, closes)), closes, scope: hit.o };
143
+ }) - 1;
144
+ return `<!--\u27E6i:${i}\u27E7-->` + String(hit.fn(hit.o, closes)) + `<!--\u27E6/i:${i}\u27E7-->`;
145
+ }
95
146
  var MARK_RE = /^\u27e6([milh]):(\d+)\u27e7$/;
96
147
  var END_RE = /^\u27e6\/([milh]):(\d+)\u27e7$/;
97
148
  var wired = /* @__PURE__ */ new WeakSet();
@@ -104,6 +155,7 @@ var HEAD_ATTR = "data-rosetack-head";
104
155
  var handlers = globalThis.__rosetack_handlers ??= {};
105
156
  function applyHead(html) {
106
157
  const seen = /* @__PURE__ */ new Set();
158
+ const positional = /* @__PURE__ */ new Map();
107
159
  const frag = tpl(html);
108
160
  const title = frag.querySelector("title");
109
161
  if (title) {
@@ -117,9 +169,16 @@ function applyHead(html) {
117
169
  for (const el of Array.from(document.head.querySelectorAll(`[${HEAD_ATTR}]`))) el.remove();
118
170
  for (const el of Array.from(frag.children)) {
119
171
  if (el.tagName === "TITLE") continue;
120
- const key = el.getAttribute("name") ?? el.getAttribute("property") ?? el.getAttribute("rel") ?? el.getAttribute("charset");
121
- if (!key) continue;
122
- const managed = `${el.tagName.toLowerCase()}:${key}`;
172
+ const tag = el.tagName.toLowerCase();
173
+ const identity = el.getAttribute("name") ?? el.getAttribute("property") ?? el.getAttribute("rel") ?? el.getAttribute("charset");
174
+ let managed;
175
+ if (identity) managed = `${tag}:${identity}`;
176
+ else if (el.id) managed = `${tag}:${el.id}`;
177
+ else {
178
+ const n = positional.get(tag) ?? 0;
179
+ positional.set(tag, n + 1);
180
+ managed = `${tag}:#${n}`;
181
+ }
123
182
  if (seen.has(managed)) continue;
124
183
  seen.add(managed);
125
184
  el.setAttribute(HEAD_ATTR, managed);
@@ -142,17 +201,35 @@ function wire(root, closes, scope) {
142
201
  const walker = document.createTreeWalker(holder, NodeFilter.SHOW_COMMENT);
143
202
  while (walker.nextNode()) comments.push(walker.currentNode);
144
203
  const nested = /* @__PURE__ */ new Set();
204
+ const headPair = /* @__PURE__ */ new Set();
205
+ const open = [];
145
206
  for (let i = 0; i < comments.length; i++) {
146
207
  const m = (comments[i].nodeValue ?? "").match(MARK_RE);
147
- if (!m || m[1] !== "i" && m[1] !== "l") continue;
148
- for (let j = i + 1; j < comments.length; j++) {
149
- const em = (comments[j].nodeValue ?? "").match(END_RE);
150
- if (em && em[1] === m[1] && +em[2] === +m[2]) {
151
- for (let k = i + 1; k < j; k++) nested.add(comments[k]);
208
+ if (m && (m[1] === "i" || m[1] === "l" || m[1] === "h")) {
209
+ open.push(i);
210
+ continue;
211
+ }
212
+ const em = (comments[i].nodeValue ?? "").match(END_RE);
213
+ if (!em) continue;
214
+ const key = em[1] + em[2];
215
+ let at = -1;
216
+ for (let k = open.length - 1; k >= 0; k--) {
217
+ const om2 = (comments[open[k]].nodeValue ?? "").match(MARK_RE);
218
+ if (om2[1] + om2[2] === key) {
219
+ at = k;
152
220
  break;
153
221
  }
154
222
  }
223
+ if (at < 0) continue;
224
+ const om = (comments[open[at]].nodeValue ?? "").match(MARK_RE);
225
+ if (om[1] === "h") {
226
+ headPair.add(comments[open[at]]);
227
+ headPair.add(comments[i]);
228
+ }
229
+ for (let k = open[at] + 1; k < i; k++) nested.add(comments[k]);
230
+ open.length = at;
155
231
  }
232
+ for (const c of headPair) nested.delete(c);
156
233
  const ends = /* @__PURE__ */ new Map();
157
234
  for (const c of comments) {
158
235
  if (nested.has(c)) continue;
@@ -160,13 +237,15 @@ function wire(root, closes, scope) {
160
237
  if (m) ends.set(+m[2], c);
161
238
  }
162
239
  const headBlocks = [];
240
+ const ownsHead = root === document.getElementById("app");
163
241
  for (const c of comments) {
164
242
  if (nested.has(c) || wired.has(c) || !c.parentNode) continue;
165
- wired.add(c);
166
243
  const m = (c.nodeValue ?? "").match(MARK_RE);
167
244
  if (!m) continue;
168
245
  const kind = m[1];
169
246
  const idx = +m[2];
247
+ if (kind === "h" && !ownsHead) continue;
248
+ wired.add(c);
170
249
  if (kind === "h") {
171
250
  const end = ends.get(idx);
172
251
  if (!end) continue;
@@ -209,7 +288,10 @@ function wire(root, closes, scope) {
209
288
  st.__st = void 0;
210
289
  }
211
290
  const r = closes[idx](scope);
212
- if (!r) return;
291
+ if (!r) {
292
+ st.__ever = true;
293
+ return;
294
+ }
213
295
  let frag;
214
296
  if (st.__ever) {
215
297
  frag = tpl(r.html);
@@ -226,7 +308,7 @@ function wire(root, closes, scope) {
226
308
  const disp = wire(frag, r.closes, r.scope ?? scope);
227
309
  const nodes = Array.from(frag.childNodes);
228
310
  const parent = anchor.parentNode;
229
- for (const nd of nodes) parent.insertBefore(nd, anchor.nextSibling);
311
+ for (const nd of nodes) parent.insertBefore(nd, end);
230
312
  st.__st = { nodes, disp };
231
313
  });
232
314
  } else {
@@ -257,19 +339,21 @@ function wire(root, closes, scope) {
257
339
  });
258
340
  }
259
341
  }
260
- if (headBlocks.length > 0) {
261
- const blocks = headBlocks;
262
- weff(() => {
263
- let html = "";
264
- for (const b of blocks) html += String(closes[b.idx](scope));
265
- applyHead(html);
266
- });
267
- for (const b of blocks) {
268
- b.nodes.forEach((nd) => nd.remove());
269
- b.start.remove();
270
- b.end.remove();
271
- }
272
- } else if (root.nodeType !== 11) clearHead();
342
+ if (root === document.getElementById("app")) {
343
+ if (headBlocks.length > 0) {
344
+ const blocks = headBlocks;
345
+ weff(() => {
346
+ let html = "";
347
+ for (const b of blocks) html += String(closes[b.idx](scope));
348
+ applyHead(html);
349
+ });
350
+ for (const b of blocks) {
351
+ b.nodes.forEach((nd) => nd.remove());
352
+ b.start.remove();
353
+ b.end.remove();
354
+ }
355
+ } else if (root.nodeType !== 11) clearHead();
356
+ }
273
357
  const els = holder.querySelectorAll("[data-b]");
274
358
  els.forEach((el) => {
275
359
  const spec = el.getAttribute("data-b");
@@ -305,6 +389,23 @@ function clearRequestState() {
305
389
  dataCache.clear();
306
390
  pendingDeltas.clear();
307
391
  }
392
+ var requestQuery = {};
393
+ var prefetchOverride = null;
394
+ function $query() {
395
+ if (prefetchOverride) return prefetchOverride;
396
+ if (typeof location === "undefined") return requestQuery;
397
+ const q = {};
398
+ new URLSearchParams(location.search).forEach((v, k) => {
399
+ q[k] = v;
400
+ });
401
+ return q;
402
+ }
403
+ function setRequestQuery(q) {
404
+ requestQuery = q;
405
+ }
406
+ function setPrefetchOverride(q) {
407
+ prefetchOverride = q;
408
+ }
308
409
  var requestContext = {};
309
410
  function getContext() {
310
411
  return requestContext;
@@ -378,7 +479,7 @@ function flushMounts() {
378
479
  for (const fn of q) fn();
379
480
  }
380
481
  function onCleanup(fn) {
381
- cleanups.add(fn);
482
+ fxSet().add(fn);
382
483
  }
383
484
  function adoptCleanups(fns) {
384
485
  for (const fn of fns) cleanups.add(fn);
@@ -420,6 +521,26 @@ function bestLocale(header) {
420
521
  }
421
522
  return null;
422
523
  }
524
+ var RoseRedirect = class extends Error {
525
+ constructor(path, status = 307) {
526
+ super(`redirect to ${path}`);
527
+ this.path = path;
528
+ this.status = status;
529
+ }
530
+ __rosetack = "redirect";
531
+ };
532
+ var RoseNotFound = class extends Error {
533
+ __rosetack = "notFound";
534
+ constructor() {
535
+ super("notFound()");
536
+ }
537
+ };
538
+ function redirect(path, status = 307) {
539
+ throw new RoseRedirect(path, status);
540
+ }
541
+ function notFound() {
542
+ throw new RoseNotFound();
543
+ }
423
544
  var RTL_RE = /^(ar|fa|he|ur|ps|sd|ug|yi|ckb|dv|ks|prs|haz|mzn|nqo)/;
424
545
  function localeDir(lang) {
425
546
  return RTL_RE.test(lang) ? "rtl" : "";
@@ -559,6 +680,38 @@ function $sessionCookie(name, value, opts = {}) {
559
680
  secure || sameSite === "None" ? "Secure" : ""
560
681
  ].filter(Boolean).join("; ");
561
682
  }
683
+ function reportVitals() {
684
+ if (typeof window === "undefined" || typeof performance === "undefined") return;
685
+ const live = {};
686
+ window.__rosetack_vitals = live;
687
+ const send = (name, value) => {
688
+ live[name] = value;
689
+ window.dispatchEvent(new CustomEvent("rosetack:vitals", { detail: { name, value, route: location.pathname } }));
690
+ };
691
+ const nav = performance.getEntriesByType?.("navigation")?.[0];
692
+ if (nav) send("ttfb", Math.round(nav.responseStart));
693
+ const paints = performance.getEntriesByType?.("paint") ?? [];
694
+ const fcp = paints.find((p) => p.name === "first-contentful-paint");
695
+ if (fcp) send("fcp", Math.round(fcp.startTime));
696
+ const PO = window.PerformanceObserver;
697
+ if (!PO) return;
698
+ let cls = 0;
699
+ let inp = 0;
700
+ const flush = () => {
701
+ if (cls) send("cls", Math.round(cls * 1e3) / 1e3);
702
+ if (inp) send("inp", Math.round(inp));
703
+ };
704
+ document.addEventListener("visibilitychange", () => {
705
+ if (document.visibilityState === "hidden") flush();
706
+ });
707
+ new PO((list) => {
708
+ for (const e of list.getEntries()) {
709
+ if (e.entryType === "layout-shift" && !e.hadRecentInput) cls += e.value ?? 0;
710
+ if (e.entryType === "event" && e.interactionId) inp = Math.max(inp, e.duration ?? 0);
711
+ if (e.entryType === "largest-contentful-paint") send("lcp", Math.round(e.startTime));
712
+ }
713
+ }).observe({ entryTypes: ["layout-shift", "event", "largest-contentful-paint"] });
714
+ }
562
715
  export {
563
716
  $actionError,
564
717
  $actionErrorOrThrow,
@@ -568,10 +721,13 @@ export {
568
721
  $data,
569
722
  $merge,
570
723
  $prepend,
724
+ $query,
571
725
  $sessionCookie,
572
726
  $store,
573
727
  $t,
574
728
  ActionError,
729
+ RoseNotFound,
730
+ RoseRedirect,
575
731
  StateDelta,
576
732
  adoptCleanups,
577
733
  applyHead,
@@ -598,20 +754,29 @@ export {
598
754
  loadLocale,
599
755
  localeDir,
600
756
  localeList,
757
+ notFound,
601
758
  onCleanup,
602
759
  onMount,
760
+ rawMark,
761
+ redirect,
603
762
  refresh,
763
+ reportVitals,
764
+ resetContainerFx,
604
765
  resetEffects,
605
766
  resetRequestContext,
606
767
  restoreState,
607
768
  resumeState,
608
769
  serializeState,
770
+ setFxOwner,
609
771
  setLocalePacks,
610
772
  setLocales,
773
+ setPrefetchOverride,
611
774
  setRefreshHook,
775
+ setRequestQuery,
612
776
  setState,
613
777
  setStateDelta,
614
778
  setStoreTransport,
779
+ slotBlockMark,
615
780
  state,
616
781
  textMark,
617
782
  tpl,