@squadbase/vantage 0.2.3 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/README.md +1 -1
  2. package/dist/add-DWNDA57L.js +6 -0
  3. package/dist/add-DWNDA57L.js.map +1 -0
  4. package/dist/build-QP5BL3K7.js +108 -0
  5. package/dist/build-QP5BL3K7.js.map +1 -0
  6. package/dist/check-QPFERQLO.js +38 -0
  7. package/dist/check-QPFERQLO.js.map +1 -0
  8. package/dist/chunk-2KRCGXBY.js +56 -0
  9. package/dist/chunk-2KRCGXBY.js.map +1 -0
  10. package/dist/chunk-BAM33YZ6.js +202 -0
  11. package/dist/chunk-BAM33YZ6.js.map +1 -0
  12. package/dist/chunk-C4MQRWXS.js +81 -0
  13. package/dist/chunk-C4MQRWXS.js.map +1 -0
  14. package/dist/chunk-D4Y5RWJA.js +189 -0
  15. package/dist/chunk-D4Y5RWJA.js.map +1 -0
  16. package/dist/chunk-OFFJ3OL5.js +121 -0
  17. package/dist/chunk-OFFJ3OL5.js.map +1 -0
  18. package/dist/chunk-PSEYFYAP.js +276 -0
  19. package/dist/chunk-PSEYFYAP.js.map +1 -0
  20. package/dist/chunk-R2YYVCGS.js +345 -0
  21. package/dist/chunk-R2YYVCGS.js.map +1 -0
  22. package/dist/chunk-RA6Z3OX3.js +199 -0
  23. package/dist/chunk-RA6Z3OX3.js.map +1 -0
  24. package/dist/chunk-UTEKU3LG.js +267 -0
  25. package/dist/chunk-UTEKU3LG.js.map +1 -0
  26. package/dist/chunk-VXAV2435.js +142 -0
  27. package/dist/chunk-VXAV2435.js.map +1 -0
  28. package/dist/cli.js +24 -1604
  29. package/dist/cli.js.map +1 -1
  30. package/dist/dev-NX3PMYCT.js +55 -0
  31. package/dist/dev-NX3PMYCT.js.map +1 -0
  32. package/dist/docs-M5ZUI25V.js +114 -0
  33. package/dist/docs-M5ZUI25V.js.map +1 -0
  34. package/dist/doctor-N6JMEWKT.js +58 -0
  35. package/dist/doctor-N6JMEWKT.js.map +1 -0
  36. package/dist/index.d.ts +1 -1
  37. package/dist/index.js +1 -1
  38. package/dist/index.js.map +1 -1
  39. package/dist/preview-CLALOEFE.js +49 -0
  40. package/dist/preview-CLALOEFE.js.map +1 -0
  41. package/dist/routes-YI25MKPF.js +119 -0
  42. package/dist/routes-YI25MKPF.js.map +1 -0
  43. package/dist/search-5TYAIQ7C.js +325 -0
  44. package/dist/search-5TYAIQ7C.js.map +1 -0
  45. package/dist/server/node.d.ts +1 -12
  46. package/dist/types-De3mo_hv.d.ts +59 -0
  47. package/dist/upgrade-3P5MBGE6.js +29 -0
  48. package/dist/upgrade-3P5MBGE6.js.map +1 -0
  49. package/dist/vite/index.d.ts +13 -0
  50. package/dist/vite/index.js +5 -1
  51. package/docs/en/changelog.md +82 -0
  52. package/docs/en/cli-reference.md +34 -4
  53. package/docs/en/components.md +2 -1
  54. package/docs/en/getting-started.md +6 -3
  55. package/docs/en/routing.md +27 -1
  56. package/docs/en/ui-and-theming.md +4 -2
  57. package/docs/ja/changelog.md +74 -0
  58. package/docs/ja/cli-reference.md +34 -4
  59. package/docs/ja/components.md +3 -2
  60. package/docs/ja/getting-started.md +6 -3
  61. package/docs/ja/routing.md +26 -1
  62. package/docs/ja/ui-and-theming.md +4 -2
  63. package/package.json +7 -4
  64. package/skills/vantage-add-feature/SKILL.md +14 -5
  65. package/skills/vantage-app/SKILL.md +9 -5
  66. package/templates/AGENTS.md +50 -6
  67. package/dist/chunk-3QKPNWKJ.js +0 -762
  68. package/dist/chunk-3QKPNWKJ.js.map +0 -1
@@ -0,0 +1,142 @@
1
+ import fs from 'fs';
2
+
3
+ // @squadbase/vantage — generated build. Do not edit.
4
+
5
+ function segToRouter(s) {
6
+ if (s.kind === "static") return s.value;
7
+ if (s.kind === "param") return `$${s.name}`;
8
+ return "$";
9
+ }
10
+ function dirToRouterPath(relDir) {
11
+ return relDir.split("/").filter(Boolean).map((token) => {
12
+ const catchall = token.match(/^\[\.\.\.(.+)\]$/);
13
+ if (catchall) return "$";
14
+ const param = token.match(/^\[(.+)\]$/);
15
+ if (param) return `$${param[1]}`;
16
+ return token;
17
+ }).join("/");
18
+ }
19
+ function isAncestorDir(ancestor, dir) {
20
+ if (ancestor === "") return true;
21
+ return dir === ancestor || dir.startsWith(ancestor + "/");
22
+ }
23
+ function isStrictAncestorDir(ancestor, dir) {
24
+ return dir.startsWith(ancestor + "/");
25
+ }
26
+ function depth(dir) {
27
+ return dir === "" ? 0 : dir.split("/").length;
28
+ }
29
+ function extractDefinePageArgs(src) {
30
+ const call = src.match(/\bdefinePage\s*\(/);
31
+ if (!call) return null;
32
+ let i = (call.index ?? 0) + call[0].length;
33
+ while (i < src.length && /\s/.test(src[i])) i++;
34
+ if (src[i] !== "{") return null;
35
+ const start = i;
36
+ let depth2 = 0;
37
+ for (; i < src.length; i++) {
38
+ const c = src[i];
39
+ if (c === "{") depth2++;
40
+ else if (c === "}" && --depth2 === 0) return src.slice(start + 1, i);
41
+ }
42
+ return null;
43
+ }
44
+ function matchStringField(scope, key) {
45
+ const re = new RegExp(
46
+ `\\b${key}\\s*:\\s*(?:"((?:\\\\.|[^"\\\\])*)"|'((?:\\\\.|[^'\\\\])*)'|\`((?:\\\\.|[^\`\\\\])*)\`)`
47
+ );
48
+ const m = scope.match(re);
49
+ if (!m) return void 0;
50
+ return (m[1] ?? m[2] ?? m[3] ?? "").replace(/\\(.)/g, "$1");
51
+ }
52
+ var metaCache = /* @__PURE__ */ new Map();
53
+ function parsePageMeta(src) {
54
+ const args = extractDefinePageArgs(src);
55
+ if (args == null) return {};
56
+ const meta = {};
57
+ const title = matchStringField(args, "title");
58
+ const description = matchStringField(args, "description");
59
+ const navLabel = matchStringField(args, "navLabel");
60
+ if (title) meta.title = title;
61
+ if (description) meta.description = description;
62
+ if (navLabel) meta.navLabel = navLabel;
63
+ return meta;
64
+ }
65
+ function extractPageMeta(absFile) {
66
+ let stat;
67
+ try {
68
+ stat = fs.statSync(absFile);
69
+ } catch {
70
+ return {};
71
+ }
72
+ const hit = metaCache.get(absFile);
73
+ if (hit && hit.mtimeMs === stat.mtimeMs && hit.size === stat.size) return hit.meta;
74
+ let src;
75
+ try {
76
+ src = fs.readFileSync(absFile, "utf8");
77
+ } catch {
78
+ return {};
79
+ }
80
+ const meta = parsePageMeta(src);
81
+ metaCache.set(absFile, { mtimeMs: stat.mtimeMs, size: stat.size, meta });
82
+ return meta;
83
+ }
84
+ function buildRouteTree(model) {
85
+ const rootLayoutRoute = model.layouts.find((l) => l.dir === "") ?? null;
86
+ const nestedLayouts = model.layouts.filter((l) => l.dir !== "").sort((a, b) => depth(a.dir) - depth(b.dir));
87
+ const built = [];
88
+ const dirToId = /* @__PURE__ */ new Map();
89
+ nestedLayouts.forEach((layout, i) => {
90
+ const id = `L${i}`;
91
+ let parent = null;
92
+ for (const cand of built) {
93
+ if (isStrictAncestorDir(cand.dir, layout.dir)) {
94
+ if (!parent || depth(cand.dir) > depth(parent.dir)) parent = { id: cand.id, dir: cand.dir };
95
+ }
96
+ }
97
+ const parentDir = parent ? parent.dir : "";
98
+ const relDir = parentDir === "" ? layout.dir : layout.dir.slice(parentDir.length + 1);
99
+ built.push({
100
+ id,
101
+ dir: layout.dir,
102
+ parentId: parent ? parent.id : null,
103
+ path: dirToRouterPath(relDir),
104
+ file: layout.file
105
+ });
106
+ dirToId.set(layout.dir, id);
107
+ });
108
+ const pages = model.pages.map((page) => {
109
+ let owner = null;
110
+ for (const l of built) {
111
+ if (isAncestorDir(l.dir, page.dir)) {
112
+ if (!owner || depth(l.dir) > depth(owner.dir)) owner = l;
113
+ }
114
+ }
115
+ const ownerSegCount = owner ? depth(owner.dir) : 0;
116
+ const remaining = page.segments.slice(ownerSegCount);
117
+ const index = remaining.length === 0;
118
+ const path = index ? "/" : remaining.map(segToRouter).join("/");
119
+ const meta = extractPageMeta(page.absFile);
120
+ return {
121
+ file: page.file,
122
+ routePath: page.routePath,
123
+ parentLayoutId: owner ? owner.id : null,
124
+ path,
125
+ index,
126
+ ...meta.title ? { title: meta.title } : {},
127
+ ...meta.description ? { description: meta.description } : {},
128
+ ...meta.navLabel ? { navLabel: meta.navLabel } : {}
129
+ };
130
+ });
131
+ return {
132
+ rootLayout: rootLayoutRoute ? rootLayoutRoute.file : null,
133
+ notFound: model.notFound,
134
+ error: model.error,
135
+ layouts: built,
136
+ pages
137
+ };
138
+ }
139
+
140
+ export { buildRouteTree, extractPageMeta };
141
+ //# sourceMappingURL=chunk-VXAV2435.js.map
142
+ //# sourceMappingURL=chunk-VXAV2435.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/core/route-tree.ts"],"names":["depth"],"mappings":";;;;AAmCA,SAAS,YAAY,CAAA,EAAoB;AACvC,EAAA,IAAI,CAAA,CAAE,IAAA,KAAS,QAAA,EAAU,OAAO,CAAA,CAAE,KAAA;AAClC,EAAA,IAAI,EAAE,IAAA,KAAS,OAAA,EAAS,OAAO,CAAA,CAAA,EAAI,EAAE,IAAI,CAAA,CAAA;AACzC,EAAA,OAAO,GAAA;AACT;AAGA,SAAS,gBAAgB,MAAA,EAAwB;AAC/C,EAAA,OAAO,MAAA,CACJ,MAAM,GAAG,CAAA,CACT,OAAO,OAAO,CAAA,CACd,GAAA,CAAI,CAAC,KAAA,KAAU;AACd,IAAA,MAAM,QAAA,GAAW,KAAA,CAAM,KAAA,CAAM,kBAAkB,CAAA;AAC/C,IAAA,IAAI,UAAU,OAAO,GAAA;AACrB,IAAA,MAAM,KAAA,GAAQ,KAAA,CAAM,KAAA,CAAM,YAAY,CAAA;AACtC,IAAA,IAAI,KAAA,EAAO,OAAO,CAAA,CAAA,EAAI,KAAA,CAAM,CAAC,CAAC,CAAA,CAAA;AAC9B,IAAA,OAAO,KAAA;AAAA,EACT,CAAC,CAAA,CACA,IAAA,CAAK,GAAG,CAAA;AACb;AAEA,SAAS,aAAA,CAAc,UAAkB,GAAA,EAAsB;AAC7D,EAAA,IAAI,QAAA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GAAQ,CAAA;AAAA,MACzD;AAAA,IACF;AACA,IAAA,MAAM,aAAA,GAAgB,KAAA,GAAQ,KAAA,CAAM,KAAA,CAAM,GAAG,CAAA,GAAI,CAAA;AACjD,IAAA,MAAM,SAAA,GAAY,IAAA,CAAK,QAAA,CAAS,KAAA,CAAM,aAAa,CAAA;AACnD,IAAA,MAAM,KAAA,GAAQ,UAAU,MAAA,KAAW,CAAA;AACnC,IAAA,MAAM,IAAA,GAAO,QAAQ,GAAA,GAAM,SAAA,CAAU,IAAI,WAAW,CAAA,CAAE,KAAK,GAAG,CAAA;AAC9D,IAAA,MAAM,IAAA,GAAO,eAAA,CAAgB,IAAA,CAAK,OAAO,CAAA;AACzC,IAAA,OAAO;AAAA,MACL,MAAM,IAAA,CAAK,IAAA;AAAA,MACX,WAAW,IAAA,CAAK,SAAA;AAAA,MAChB,cAAA,EAAgB,KAAA,GAAQ,KAAA,CAAM,EAAA,GAAK,IAAA;AAAA,MACnC,IAAA;AAAA,MACA,KAAA;AAAA,MACA,GAAI,KAAK,KAAA,GAAQ,EAAE,OAAO,IAAA,CAAK,KAAA,KAAU,EAAC;AAAA,MAC1C,GAAI,KAAK,WAAA,GAAc,EAAE,aAAa,IAAA,CAAK,WAAA,KAAgB,EAAC;AAAA,MAC5D,GAAI,KAAK,QAAA,GAAW,EAAE,UAAU,IAAA,CAAK,QAAA,KAAa;AAAC,KACrD;AAAA,EACF,CAAC,CAAA;AAED,EAAA,OAAO;AAAA,IACL,UAAA,EAAY,eAAA,GAAkB,eAAA,CAAgB,IAAA,GAAO,IAAA;AAAA,IACrD,UAAU,KAAA,CAAM,QAAA;AAAA,IAChB,OAAO,KAAA,CAAM,KAAA;AAAA,IACb,OAAA,EAAS,KAAA;AAAA,IACT;AAAA,GACF;AACF","file":"chunk-VXAV2435.js","sourcesContent":["import fs from \"node:fs\"\nimport type { RouteModel, Segment } from \"./types\"\n\n/** A layout route (path-bearing) in the built tree. */\nexport interface BuiltLayout {\n id: string\n dir: string\n parentId: string | null\n /** Router path relative to its parent (TanStack `$param` form). */\n path: string\n file: string\n}\n\n/** A page route in the built tree. */\nexport interface BuiltPage {\n file: string\n routePath: string\n parentLayoutId: string | null\n /** Router path relative to parent, or \"/\" for an index route. */\n path: string\n index: boolean\n title?: string\n description?: string\n navLabel?: string\n}\n\n/** The structured route tree emitted for the client runtime. */\nexport interface BuiltTree {\n rootLayout: string | null\n notFound: string | null\n error: string | null\n layouts: BuiltLayout[]\n pages: BuiltPage[]\n}\n\nfunction segToRouter(s: Segment): string {\n if (s.kind === \"static\") return s.value\n if (s.kind === \"param\") return `$${s.name}`\n return \"$\"\n}\n\n/** Convert a relative directory string (may contain `[param]`) to a router path. */\nfunction dirToRouterPath(relDir: string): string {\n return relDir\n .split(\"/\")\n .filter(Boolean)\n .map((token) => {\n const catchall = token.match(/^\\[\\.\\.\\.(.+)\\]$/)\n if (catchall) return \"$\"\n const param = token.match(/^\\[(.+)\\]$/)\n if (param) return `$${param[1]}`\n return token\n })\n .join(\"/\")\n}\n\nfunction isAncestorDir(ancestor: string, dir: string): boolean {\n if (ancestor === \"\") return true\n return dir === ancestor || dir.startsWith(ancestor + \"/\")\n}\n\nfunction isStrictAncestorDir(ancestor: string, dir: string): boolean {\n return dir.startsWith(ancestor + \"/\")\n}\n\nfunction depth(dir: string): number {\n return dir === \"\" ? 0 : dir.split(\"/\").length\n}\n\n/**\n * Extract the argument object body of the first `definePage({ ... })` call\n * using balanced-brace scanning, so nested objects/functions (e.g.\n * `validateSearch: (s) => ({ ... })`) don't truncate the match. Returns null\n * when there is no definePage call — the caller then emits no metadata rather\n * than falling back to the whole file (which would match unrelated `title:`\n * keys in chart/option configs).\n */\nfunction extractDefinePageArgs(src: string): string | null {\n const call = src.match(/\\bdefinePage\\s*\\(/)\n if (!call) return null\n let i = (call.index ?? 0) + call[0].length\n while (i < src.length && /\\s/.test(src[i]!)) i++\n if (src[i] !== \"{\") return null\n const start = i\n let depth = 0\n for (; i < src.length; i++) {\n const c = src[i]\n if (c === \"{\") depth++\n else if (c === \"}\" && --depth === 0) return src.slice(start + 1, i)\n }\n return null\n}\n\n/**\n * Match `key: \"...\"` allowing the value's own quote character to differ and\n * handling escapes, so values containing an apostrophe/quote are not truncated.\n */\nfunction matchStringField(scope: string, key: string): string | undefined {\n const re = new RegExp(\n `\\\\b${key}\\\\s*:\\\\s*(?:\"((?:\\\\\\\\.|[^\"\\\\\\\\])*)\"|'((?:\\\\\\\\.|[^'\\\\\\\\])*)'|\\`((?:\\\\\\\\.|[^\\`\\\\\\\\])*)\\`)`,\n )\n const m = scope.match(re)\n if (!m) return undefined\n return (m[1] ?? m[2] ?? m[3] ?? \"\").replace(/\\\\(.)/g, \"$1\")\n}\n\ninterface PageMeta {\n title?: string\n description?: string\n navLabel?: string\n}\n\n/**\n * Cache keyed on mtime+size. A long-lived dev server regenerates the route tree\n * on every structural change, and re-reading + re-parsing every page module for\n * metadata that almost never changes is pure waste. `statSync` is an order of\n * magnitude cheaper than the read plus the brace scan it feeds.\n */\nconst metaCache = new Map<string, { mtimeMs: number; size: number; meta: PageMeta }>()\n\nfunction parsePageMeta(src: string): PageMeta {\n const args = extractDefinePageArgs(src)\n if (args == null) return {}\n const meta: PageMeta = {}\n const title = matchStringField(args, \"title\")\n const description = matchStringField(args, \"description\")\n const navLabel = matchStringField(args, \"navLabel\")\n if (title) meta.title = title\n if (description) meta.description = description\n if (navLabel) meta.navLabel = navLabel\n return meta\n}\n\n/** Best-effort static extraction of definePage title/description/navLabel. */\nexport function extractPageMeta(absFile: string): PageMeta {\n let stat: fs.Stats\n try {\n stat = fs.statSync(absFile)\n } catch {\n return {}\n }\n const hit = metaCache.get(absFile)\n if (hit && hit.mtimeMs === stat.mtimeMs && hit.size === stat.size) return hit.meta\n\n let src: string\n try {\n src = fs.readFileSync(absFile, \"utf8\")\n } catch {\n return {}\n }\n const meta = parsePageMeta(src)\n metaCache.set(absFile, { mtimeMs: stat.mtimeMs, size: stat.size, meta })\n return meta\n}\n\n/**\n * Build the structured route tree from a scan. Layouts become path-bearing\n * routes; pages attach to the deepest layout that owns their directory.\n */\nexport function buildRouteTree(model: RouteModel): BuiltTree {\n const rootLayoutRoute = model.layouts.find((l) => l.dir === \"\") ?? null\n const nestedLayouts = model.layouts\n .filter((l) => l.dir !== \"\")\n .sort((a, b) => depth(a.dir) - depth(b.dir))\n\n const built: BuiltLayout[] = []\n const dirToId = new Map<string, string>()\n\n nestedLayouts.forEach((layout, i) => {\n const id = `L${i}`\n // Parent = deepest other layout that is a strict ancestor of this dir.\n let parent: { id: string; dir: string } | null = null\n for (const cand of built) {\n if (isStrictAncestorDir(cand.dir, layout.dir)) {\n if (!parent || depth(cand.dir) > depth(parent.dir)) parent = { id: cand.id, dir: cand.dir }\n }\n }\n const parentDir = parent ? parent.dir : \"\"\n const relDir = parentDir === \"\" ? layout.dir : layout.dir.slice(parentDir.length + 1)\n built.push({\n id,\n dir: layout.dir,\n parentId: parent ? parent.id : null,\n path: dirToRouterPath(relDir),\n file: layout.file,\n })\n dirToId.set(layout.dir, id)\n })\n\n const pages: BuiltPage[] = model.pages.map((page) => {\n // Owner = deepest layout whose dir is an ancestor-or-equal of the page dir.\n let owner: BuiltLayout | null = null\n for (const l of built) {\n if (isAncestorDir(l.dir, page.dir)) {\n if (!owner || depth(l.dir) > depth(owner.dir)) owner = l\n }\n }\n const ownerSegCount = owner ? depth(owner.dir) : 0\n const remaining = page.segments.slice(ownerSegCount)\n const index = remaining.length === 0\n const path = index ? \"/\" : remaining.map(segToRouter).join(\"/\")\n const meta = extractPageMeta(page.absFile)\n return {\n file: page.file,\n routePath: page.routePath,\n parentLayoutId: owner ? owner.id : null,\n path,\n index,\n ...(meta.title ? { title: meta.title } : {}),\n ...(meta.description ? { description: meta.description } : {}),\n ...(meta.navLabel ? { navLabel: meta.navLabel } : {}),\n }\n })\n\n return {\n rootLayout: rootLayoutRoute ? rootLayoutRoute.file : null,\n notFound: model.notFound,\n error: model.error,\n layouts: built,\n pages,\n }\n}\n"]}