ghostcn 1.2.0 → 1.4.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 (58) hide show
  1. package/README.md +16 -244
  2. package/dist/commands/add.d.ts +6 -1
  3. package/dist/commands/add.js +121 -83
  4. package/dist/commands/diff.d.ts +5 -0
  5. package/dist/commands/diff.js +54 -0
  6. package/dist/commands/playground.d.ts +3 -0
  7. package/dist/commands/playground.js +29 -0
  8. package/dist/index.js +18 -3
  9. package/dist/registry/components/alert.json +62 -0
  10. package/dist/registry/components/archive-header.json +57 -0
  11. package/dist/registry/components/author-card.json +23 -2
  12. package/dist/registry/components/author-list.json +55 -0
  13. package/dist/registry/components/badge.json +51 -0
  14. package/dist/registry/components/button.json +74 -0
  15. package/dist/registry/components/card.json +70 -0
  16. package/dist/registry/components/featured-posts.json +18 -1
  17. package/dist/registry/components/input.json +94 -0
  18. package/dist/registry/components/member-cta.json +15 -1
  19. package/dist/registry/components/newsletter-form.json +23 -2
  20. package/dist/registry/components/pagination.json +12 -1
  21. package/dist/registry/components/post-card.json +25 -2
  22. package/dist/registry/components/post-grid.json +54 -0
  23. package/dist/registry/components/post-header.json +18 -1
  24. package/dist/registry/components/post-navigation.json +41 -0
  25. package/dist/registry/components/pricing-table.json +31 -2
  26. package/dist/registry/components/related-posts.json +53 -0
  27. package/dist/registry/components/site-footer.json +15 -1
  28. package/dist/registry/components/site-header.json +16 -1
  29. package/dist/registry/components/table-of-contents.json +47 -0
  30. package/dist/registry/components/tag-grid.json +64 -0
  31. package/dist/registry/components/tag-list.json +38 -0
  32. package/dist/registry/index.json +131 -0
  33. package/dist/templates/playground/index.html +5 -0
  34. package/dist/templates/playground/playground.css +18 -0
  35. package/dist/templates/playground/playground.js +71 -0
  36. package/dist/templates/playground/preview.css +5 -0
  37. package/dist/templates/playground/preview.js +12 -0
  38. package/dist/templates/theme-tools.mjs +1 -1
  39. package/dist/utils/component-diff.d.ts +18 -0
  40. package/dist/utils/component-diff.js +93 -0
  41. package/dist/utils/component-files.d.ts +9 -0
  42. package/dist/utils/component-files.js +48 -0
  43. package/dist/utils/component-history.d.ts +11 -0
  44. package/dist/utils/component-history.js +47 -0
  45. package/dist/utils/component-installer.d.ts +2 -0
  46. package/dist/utils/component-installer.js +34 -37
  47. package/dist/utils/component-plan.d.ts +7 -0
  48. package/dist/utils/component-plan.js +43 -0
  49. package/dist/utils/playground-server.d.ts +9 -0
  50. package/dist/utils/playground-server.js +189 -0
  51. package/dist/utils/preview-renderer.d.ts +143 -0
  52. package/dist/utils/preview-renderer.js +70 -0
  53. package/dist/utils/registry.d.ts +7 -0
  54. package/dist/utils/registry.js +12 -18
  55. package/dist/utils/theme-files.d.ts +2 -0
  56. package/dist/utils/theme-files.js +41 -3
  57. package/dist/utils/theme-scaffold.js +14 -1
  58. package/package.json +4 -4
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "table-of-contents",
3
+ "type": "components:content",
4
+ "description": "Progressively enhanced h2/h3 navigation with collision-safe anchors and keyboard focus.",
5
+ "dependencies": [],
6
+ "ghost_version": ">=5.0.0",
7
+ "files": [
8
+ {
9
+ "name": "table-of-contents.hbs",
10
+ "type": "partial",
11
+ "target": "partials/components/table-of-contents.hbs",
12
+ "content": "{{!-- Styling parameters: class, titleClass, listClass --}}\n{{#with this as |ghostcnStyles|}}\n{{!-- add manages the deferred script in default.hbs. Set contentSelector for existing themes. --}}\n<nav class=\"ghcn-toc{{#if ghostcnStyles.class}} {{ghostcnStyles.class}}{{/if}}\" data-ghcn-toc data-toc-content=\"{{#if contentSelector}}{{contentSelector}}{{else}}.ghcn-article-content{{/if}}\" data-link-class=\"{{linkClass}}\" aria-label=\"On this page\" hidden>\n <h2 class=\"ghcn-toc__title{{#if ghostcnStyles.titleClass}} {{ghostcnStyles.titleClass}}{{/if}}\">{{#if heading}}{{heading}}{{else}}On this page{{/if}}</h2>\n <ol class=\"ghcn-toc__list{{#if ghostcnStyles.listClass}} {{ghostcnStyles.listClass}}{{/if}}\" data-toc-list></ol>\n</nav>\n{{/with}}"
13
+ },
14
+ {
15
+ "name": "table-of-contents.css",
16
+ "type": "style",
17
+ "target": "assets/css/components/table-of-contents.css",
18
+ "content": "\n.ghcn-toc { padding: 1.25em; margin-block: 1.5em; background: var(--card); color: var(--card-foreground); border: 1px solid var(--border); border-radius: var(--radius); }\n.ghcn-toc[hidden] { display: none; }\n.ghcn-toc__title { margin: 0 0 .75em; font-size: 1em; font-weight: 600; }\n.ghcn-toc__list { padding-left: 1.25em; margin: 0; }\n.ghcn-toc__item { padding-block: .25em; }\n.ghcn-toc__item--nested { margin-left: 1em; }\n.ghcn-toc__link { color: inherit; text-decoration: none; overflow-wrap: anywhere; }\n.ghcn-toc__link:hover { text-decoration: underline; }\n.ghcn-toc__link:focus-visible { outline: 2px solid var(--ring); outline-offset: 3px; }\n"
19
+ },
20
+ {
21
+ "name": "table-of-contents.js",
22
+ "type": "js",
23
+ "target": "assets/js/components/table-of-contents.js",
24
+ "content": "/* ghostcn table of contents: no dependencies, no HTML injection, repeat-safe. */\n(() => {\n const init = () => {\n document.querySelectorAll('[data-ghcn-toc]').forEach(nav => {\n if (nav.dataset.ghcnTocReady) return;\n let content;\n try { content = document.querySelector(nav.dataset.tocContent); } catch { return; }\n if (!content) return;\n // Editor card UI titles are not article sections (e.g. signup or product headings).\n const headings = [...content.querySelectorAll('h2, h3')].filter(h => h.textContent.trim() && !h.closest('.kg-card'));\n if (headings.length < 2) return;\n const list = nav.querySelector('[data-toc-list]');\n if (!list) return;\n const used = new Set([...document.querySelectorAll('[id]')].map(el => el.id));\n headings.forEach((heading, index) => {\n if (!heading.id) {\n const base = 'ghcn-' + (heading.textContent.toLowerCase().normalize('NFKD').replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '') || 'section-' + (index + 1));\n let id = base, suffix = 2;\n while (used.has(id)) id = base + '-' + suffix++;\n heading.id = id; used.add(id);\n }\n const item = document.createElement('li');\n item.className = 'ghcn-toc__item' + (heading.tagName === 'H3' ? ' ghcn-toc__item--nested' : '');\n const link = document.createElement('a');\n link.className = 'ghcn-toc__link';\n if (nav.dataset.linkClass) nav.dataset.linkClass.split(/\\s+/).filter(Boolean).forEach(value => link.classList.add(value));\n link.href = '#' + encodeURIComponent(heading.id);\n link.textContent = heading.textContent.trim();\n link.addEventListener('click', event => {\n if (event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;\n event.preventDefault();\n heading.scrollIntoView({ behavior: 'auto', block: 'start' });\n if (!heading.hasAttribute('tabindex')) {\n heading.setAttribute('tabindex', '-1');\n heading.addEventListener('blur', () => heading.removeAttribute('tabindex'), { once: true });\n }\n heading.focus({ preventScroll: true });\n try { history.replaceState(null, '', '#' + encodeURIComponent(heading.id)); } catch {}\n });\n item.append(link); list.append(item);\n });\n nav.dataset.ghcnTocReady = 'true'; nav.hidden = false;\n });\n };\n if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', init, { once: true }); else init();\n})();"
25
+ }
26
+ ],
27
+ "gscan": {
28
+ "rules_satisfied": [
29
+ "GS010-PJ-VALID"
30
+ ],
31
+ "notes": "Uses native Ghost post data and optional progressive enhancement."
32
+ },
33
+ "styleSlots": {
34
+ "class": [
35
+ ".ghcn-toc"
36
+ ],
37
+ "titleClass": [
38
+ ".ghcn-toc__title"
39
+ ],
40
+ "listClass": [
41
+ ".ghcn-toc__list"
42
+ ],
43
+ "linkClass": [
44
+ ".ghcn-toc__link"
45
+ ]
46
+ }
47
+ }
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "tag-grid",
3
+ "type": "components:content",
4
+ "description": "Public tag archive links composed from card and button primitives.",
5
+ "dependencies": [
6
+ "card",
7
+ "button"
8
+ ],
9
+ "ghost_version": ">=5.0.0",
10
+ "parameters": {
11
+ "heading": {
12
+ "description": "Optional section heading."
13
+ },
14
+ "emptyText": {
15
+ "description": "Optional message when no content is available; otherwise render nothing."
16
+ },
17
+ "cardVariant": {
18
+ "description": "Variant forwarded to each card.",
19
+ "options": [
20
+ "default",
21
+ "secondary",
22
+ "outline"
23
+ ],
24
+ "default": "default"
25
+ }
26
+ },
27
+ "files": [
28
+ {
29
+ "name": "tag-grid.hbs",
30
+ "type": "partial",
31
+ "target": "partials/components/tag-grid.hbs",
32
+ "content": "{{!-- Styling parameters: class, titleClass, gridClass --}}\n{{#with this as |ghostcnStyles|}}\n{{#get \"tags\" filter=\"visibility:public\" limit=\"100\" include=\"count.posts\"}}\n{{#if tags}}<section class=\"ghcn-tag-grid{{#if ghostcnStyles.class}} {{ghostcnStyles.class}}{{/if}}\" aria-label=\"Topics\">\n {{#if ghostcnStyles.heading}}<h2 class=\"ghcn-tag-grid__title{{#if ghostcnStyles.titleClass}} {{ghostcnStyles.titleClass}}{{/if}}\">{{ghostcnStyles.heading}}</h2>{{/if}}\n <div class=\"ghcn-tag-grid__grid{{#if ghostcnStyles.gridClass}} {{ghostcnStyles.gridClass}}{{/if}}\">{{#foreach tags visibility=\"public\"}}\n {{#> \"components/card\" heading=name description=description class=ghostcnStyles.cardClass titleClass=ghostcnStyles.cardTitleClass descriptionClass=ghostcnStyles.descriptionClass variant=ghostcnStyles.cardVariant}}\n {{> \"components/button\" href=url text=\"Explore topic\" variant=\"outline\" size=\"sm\" class=ghostcnStyles.buttonClass}}\n {{/components/card}}\n {{/foreach}}</div>\n</section>{{else}}{{#if ghostcnStyles.emptyText}}<section class=\"ghcn-tag-grid{{#if ghostcnStyles.class}} {{ghostcnStyles.class}}{{/if}}\"><p class=\"ghcn-tag-grid__empty\">{{ghostcnStyles.emptyText}}</p></section>{{/if}}{{/if}}\n{{/get}}\n{{/with}}"
33
+ },
34
+ {
35
+ "name": "tag-grid.css",
36
+ "type": "style",
37
+ "target": "assets/css/components/tag-grid.css",
38
+ "content": ".ghcn-tag-grid { font-size: 16px; color: var(--foreground); margin-block: 2em; }\n.ghcn-tag-grid__title { font-size: 1.5em; line-height: 1.25; margin: 0 0 1em; }\n.ghcn-tag-grid__grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 1.5em; }\n.ghcn-tag-grid__grid > * { min-width: 0; }\n.ghcn-tag-grid__empty { color: var(--muted-foreground); }\n@media(max-width:900px) { .ghcn-tag-grid__grid { grid-template-columns: repeat(2,minmax(0,1fr)); } }\n@media(max-width:620px) { .ghcn-tag-grid__grid { grid-template-columns: 1fr; } }"
39
+ }
40
+ ],
41
+ "styleSlots": {
42
+ "class": [
43
+ ".ghcn-tag-grid"
44
+ ],
45
+ "titleClass": [
46
+ ".ghcn-tag-grid__title"
47
+ ],
48
+ "gridClass": [
49
+ ".ghcn-tag-grid__grid"
50
+ ],
51
+ "cardClass": [
52
+ ".ghcn-ui-card"
53
+ ],
54
+ "cardTitleClass": [
55
+ ".ghcn-ui-card__title"
56
+ ],
57
+ "descriptionClass": [
58
+ ".ghcn-ui-card__description"
59
+ ],
60
+ "buttonClass": [
61
+ ".ghcn-ui-button"
62
+ ]
63
+ }
64
+ }
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "tag-list",
3
+ "type": "components:content",
4
+ "description": "Linked public tags for the current post, omitting internal tags and empty tag lists.",
5
+ "dependencies": [],
6
+ "ghost_version": ">=5.0.0",
7
+ "files": [
8
+ {
9
+ "name": "tag-list.hbs",
10
+ "type": "partial",
11
+ "target": "partials/components/tag-list.hbs",
12
+ "content": "{{!-- Styling parameters: class, listClass, linkClass --}}\n{{#with this as |ghostcnStyles|}}\n{{!-- Use inside {{#post}}; Ghost foreach filters internal tags. --}}\n{{#foreach tags visibility=\"public\"}}{{#if @first}}<nav class=\"ghcn-tag-list{{#if ghostcnStyles.class}} {{ghostcnStyles.class}}{{/if}}\" aria-label=\"Post tags\"><ul class=\"ghcn-tag-list__items{{#if ghostcnStyles.listClass}} {{ghostcnStyles.listClass}}{{/if}}\">{{/if}}<li><a class=\"ghcn-tag-list__link{{#if ghostcnStyles.linkClass}} {{ghostcnStyles.linkClass}}{{/if}}\" href=\"{{url}}\">{{name}}</a></li>{{#if @last}}</ul></nav>{{/if}}{{/foreach}}\n{{/with}}"
13
+ },
14
+ {
15
+ "name": "tag-list.css",
16
+ "type": "style",
17
+ "target": "assets/css/components/tag-list.css",
18
+ "content": "\n.ghcn-tag-list { margin-block: 1.5em; }\n.ghcn-tag-list__items { display: flex; flex-wrap: wrap; gap: .5em; list-style: none; padding: 0; margin: 0; }\n.ghcn-tag-list__link { display: block; padding: .375em .875em; background: var(--muted); color: var(--foreground); border: 1px solid var(--border); border-radius: 999px; font-size: .875em; text-decoration: none; }\n.ghcn-tag-list__link:hover { background: var(--secondary); text-decoration: underline; }\n.ghcn-tag-list__link:focus-visible { outline: 2px solid var(--ring); outline-offset: 3px; }\n"
19
+ }
20
+ ],
21
+ "gscan": {
22
+ "rules_satisfied": [
23
+ "GS010-PJ-VALID"
24
+ ],
25
+ "notes": "Uses native Ghost post data and optional progressive enhancement."
26
+ },
27
+ "styleSlots": {
28
+ "class": [
29
+ ".ghcn-tag-list"
30
+ ],
31
+ "listClass": [
32
+ ".ghcn-tag-list__items"
33
+ ],
34
+ "linkClass": [
35
+ ".ghcn-tag-list__link"
36
+ ]
37
+ }
38
+ }
@@ -98,5 +98,136 @@
98
98
  "member-cta.hbs",
99
99
  "member-cta.css"
100
100
  ]
101
+ },
102
+ {
103
+ "name": "related-posts",
104
+ "description": "Related reading from the same primary tag, excluding the current post; recent posts when untagged.",
105
+ "category": "components:content",
106
+ "ghost_version": ">=5.0.0",
107
+ "files": [
108
+ "related-posts.hbs",
109
+ "related-posts.css"
110
+ ]
111
+ },
112
+ {
113
+ "name": "post-navigation",
114
+ "description": "Accessible chronological previous/next post links, with no dead links at either end.",
115
+ "category": "components:content",
116
+ "ghost_version": ">=5.0.0",
117
+ "files": [
118
+ "post-navigation.hbs",
119
+ "post-navigation.css"
120
+ ]
121
+ },
122
+ {
123
+ "name": "table-of-contents",
124
+ "description": "Progressively enhanced h2/h3 navigation with collision-safe anchors and keyboard focus.",
125
+ "category": "components:content",
126
+ "ghost_version": ">=5.0.0",
127
+ "files": [
128
+ "table-of-contents.hbs",
129
+ "table-of-contents.css",
130
+ "table-of-contents.js"
131
+ ]
132
+ },
133
+ {
134
+ "name": "tag-list",
135
+ "description": "Linked public tags for the current post, omitting internal tags and empty tag lists.",
136
+ "category": "components:content",
137
+ "ghost_version": ">=5.0.0",
138
+ "files": [
139
+ "tag-list.hbs",
140
+ "tag-list.css"
141
+ ]
142
+ },
143
+ {
144
+ "name": "button",
145
+ "description": "A native button or link with variants, sizes and per-instance classes.",
146
+ "category": "components:ui",
147
+ "ghost_version": ">=5.0.0",
148
+ "files": [
149
+ "button.hbs",
150
+ "button.css"
151
+ ]
152
+ },
153
+ {
154
+ "name": "card",
155
+ "description": "A composable content card with optional heading, description and footer.",
156
+ "category": "components:ui",
157
+ "ghost_version": ">=5.0.0",
158
+ "files": [
159
+ "card.hbs",
160
+ "card.css"
161
+ ]
162
+ },
163
+ {
164
+ "name": "badge",
165
+ "description": "A small non-interactive label with variants and sizes.",
166
+ "category": "components:ui",
167
+ "ghost_version": ">=5.0.0",
168
+ "files": [
169
+ "badge.hbs",
170
+ "badge.css"
171
+ ]
172
+ },
173
+ {
174
+ "name": "input",
175
+ "description": "An accessible labeled native input, with optional hint and invalid/disabled states.",
176
+ "category": "components:ui",
177
+ "ghost_version": ">=5.0.0",
178
+ "files": [
179
+ "input.hbs",
180
+ "input.css"
181
+ ]
182
+ },
183
+ {
184
+ "name": "alert",
185
+ "description": "An accessible status message with an optional urgent announcement.",
186
+ "category": "components:ui",
187
+ "ghost_version": ">=5.0.0",
188
+ "files": [
189
+ "alert.hbs",
190
+ "alert.css"
191
+ ]
192
+ },
193
+ {
194
+ "name": "post-grid",
195
+ "description": "A responsive grid using post-card; pass posts from a loop, archive or get query.",
196
+ "category": "components:content",
197
+ "ghost_version": ">=5.0.0",
198
+ "files": [
199
+ "post-grid.hbs",
200
+ "post-grid.css"
201
+ ]
202
+ },
203
+ {
204
+ "name": "author-list",
205
+ "description": "Publication authors rendered with reusable author cards.",
206
+ "category": "components:content",
207
+ "ghost_version": ">=5.0.0",
208
+ "files": [
209
+ "author-list.hbs",
210
+ "author-list.css"
211
+ ]
212
+ },
213
+ {
214
+ "name": "tag-grid",
215
+ "description": "Public tag archive links composed from card and button primitives.",
216
+ "category": "components:content",
217
+ "ghost_version": ">=5.0.0",
218
+ "files": [
219
+ "tag-grid.hbs",
220
+ "tag-grid.css"
221
+ ]
222
+ },
223
+ {
224
+ "name": "archive-header",
225
+ "description": "A reusable tag or author archive heading with an optional badge and image.",
226
+ "category": "components:content",
227
+ "ghost_version": ">=5.0.0",
228
+ "files": [
229
+ "archive-header.hbs",
230
+ "archive-header.css"
231
+ ]
101
232
  }
102
233
  ]
@@ -0,0 +1,5 @@
1
+ <!doctype html>
2
+ <html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Ghostcn playground</title><link rel="stylesheet" href="/playground.css"><script defer src="/playground.js"></script></head>
3
+ <body><header><p class="eyebrow">LOCAL COMPONENT PLAYGROUND</p><h1>Build it your way.</h1><p>Installed theme files. Synthetic content. No emails, payments or Ghost settings changes.</p></header>
4
+ <main><aside aria-label="Preview controls"><label>Component<select id="component"></select></label><p id="description"></p><label>Theme<select id="scheme"><option value="light">Light</option><option value="dark">Dark</option><option value="auto">Auto</option></select></label><label>Member state<select id="state"><option value="visitor">Visitor</option><option value="free">Free member</option><option value="paid">Paid member</option><option value="disabled">Membership disabled</option><option value="invite">Invite only</option><option value="restricted">Self-signup restricted</option></select></label><div id="parameters"></div><button id="reload" type="button">Reload preview</button><p id="status" role="status"></p></aside>
5
+ <section aria-label="Component preview"><iframe id="preview" title="Installed component preview" sandbox="allow-scripts"></iframe><h2>Use in your template</h2><pre><code id="usage"></code></pre><p>Classes only preview if your CSS defines them. For Tailwind, put utilities in a scanned .hbs file and keep <code>npm run dev</code> running. Verify real data, editor cards and member behavior in Ghost.</p><p>Preview changes are temporary. Copy the usage into your theme to keep them.</p></section></main></body></html>
@@ -0,0 +1,18 @@
1
+ :root { color-scheme: light dark; font-family: ui-sans-serif, system-ui, sans-serif; background: #101419; color: #e8edf2; }
2
+ * { box-sizing: border-box; }
3
+ body { margin: 0; }
4
+ header { padding: 32px; border-bottom: 1px solid #34414e; }
5
+ .eyebrow { font-size: 12px; letter-spacing: .12em; color: #a0bdcf; }
6
+ h1 { margin: 8px 0; font-size: clamp(28px,4vw,42px); }
7
+ p { line-height: 1.6; }
8
+ main { display: grid; grid-template-columns: minmax(240px,320px) minmax(0,1fr); }
9
+ aside { padding: 24px; border-right: 1px solid #34414e; }
10
+ section { min-width: 0; padding: 24px; }
11
+ label { display: grid; gap: 8px; margin-bottom: 18px; font-size: 14px; }
12
+ input, select, button { font: inherit; width: 100%; min-width: 0; padding: 10px; border-radius: 6px; border: 1px solid #516475; color: #e8edf2; background: #1d2731; }
13
+ button { cursor: pointer; }
14
+ input:focus-visible, select:focus-visible, button:focus-visible { outline: 2px solid #bca1f8; outline-offset: 3px; }
15
+ label small, #description { color: #a0bdcf; }
16
+ iframe { width: 100%; height: 650px; border: 1px solid #516475; border-radius: 8px; background: #fff; }
17
+ pre { white-space: pre-wrap; overflow-wrap: anywhere; background: #1d2731; padding: 20px; border-radius: 8px; }
18
+ @media(max-width:760px) { main { grid-template-columns: 1fr; } aside { border-right: 0; border-bottom: 1px solid #34414e; } header, aside, section { padding: 20px; } }
@@ -0,0 +1,71 @@
1
+ const component = document.querySelector('#component');
2
+ const parameters = document.querySelector('#parameters');
3
+ const status = document.querySelector('#status');
4
+ const controls = new Map();
5
+ let catalog = [], revision, busy = false;
6
+ const current = () => catalog.find(item => item.name === component.value);
7
+ function render() {
8
+ const item = current();
9
+ if (!item) return;
10
+ const query = new URLSearchParams({ scheme: document.querySelector('#scheme').value, state: document.querySelector('#state').value });
11
+ const args = [];
12
+ for (const [name, input] of controls) {
13
+ query.set(name, input.value);
14
+ if (input.value) args.push(`${name}=${['disabled','required','invalid','urgent'].includes(name) ? input.value : JSON.stringify(input.value)}`);
15
+ }
16
+ document.querySelector('#preview').src = `/preview/${item.name}?${query}`;
17
+ const context = item.name === 'author-card' ? ' primary_author' : item.name === 'pagination' ? ' pagination' : '';
18
+ document.querySelector('#usage').textContent = `{{> "${item.partial}"${context}${args.map(arg => `\n ${arg}`).join('')}\n}}`;
19
+ }
20
+ function selectComponent() {
21
+ controls.clear(); parameters.replaceChildren();
22
+ const item = current();
23
+ if (!item) { status.textContent = 'No components installed. Run ghostcn add button (or another component), then reload.'; return; }
24
+ document.querySelector('#description').textContent = item.description;
25
+ const definitions = { ...item.parameters, ...Object.fromEntries(Object.keys(item.styleSlots).map(key => [key, { description: key === 'class' ? 'Root classes for this instance.' : `Classes for ${item.styleSlots[key].join(', ')}.` }])) };
26
+ for (const [name, definition] of Object.entries(definitions)) {
27
+ const boolean = ['disabled','required','invalid','urgent'].includes(name);
28
+ const label = document.createElement('label'); label.append(document.createTextNode(name));
29
+ const input = document.createElement(definition.options || boolean ? 'select' : 'input');
30
+ input.name = name;
31
+ if (input.tagName === 'SELECT') for (const value of boolean ? ['false','true'] : definition.options) { const option = document.createElement('option'); option.value = value; option.textContent = value; input.append(option); }
32
+ input.value = item.defaults[name] || definition.default || (boolean ? 'false' : '');
33
+ const help = document.createElement('small'); help.textContent = definition.description;
34
+ label.append(input, help); parameters.append(label); controls.set(name, input);
35
+ input.addEventListener('change', render);
36
+ }
37
+ status.textContent = 'Read-only preview. Your files have not been changed.';
38
+ render();
39
+ }
40
+ async function loadCatalog() {
41
+ const selected = component.value;
42
+ const response = await fetch('/catalog');
43
+ if (!response.ok) throw new Error('Cannot read installed components.');
44
+ catalog = (await response.json()).components;
45
+ component.replaceChildren();
46
+ for (const item of catalog) { const option = document.createElement('option'); option.value = item.name; option.textContent = item.name; component.append(option); }
47
+ if (catalog.some(item => item.name === selected)) component.value = selected;
48
+ selectComponent();
49
+ }
50
+ component.addEventListener('change', selectComponent);
51
+ document.querySelector('#scheme').addEventListener('change', render);
52
+ document.querySelector('#state').addEventListener('change', render);
53
+ document.querySelector('#reload').addEventListener('click', render);
54
+ loadCatalog().catch(error => { status.textContent = error.message; });
55
+ setInterval(async () => {
56
+ if (busy) return;
57
+ busy = true;
58
+ try {
59
+ const response = await fetch('/revision');
60
+ if (!response.ok) throw new Error('Cannot watch theme files.');
61
+ const next = (await response.json()).revision;
62
+ if (revision && next !== revision) {
63
+ const fresh = await (await fetch('/catalog')).json();
64
+ if (fresh.components.map(item => item.name).join(',') !== catalog.map(item => item.name).join(',')) await loadCatalog();
65
+ else render();
66
+ status.textContent = 'Reloaded after a theme file changed.';
67
+ }
68
+ revision = next;
69
+ } catch (error) { status.textContent = `${error.message} Check the playground terminal.`; }
70
+ finally { busy = false; }
71
+ }, 1000);
@@ -0,0 +1,5 @@
1
+ /* Only the preview shell, never component defaults. */
2
+ body { margin: 0; background: var(--background); color: var(--foreground); font: 16px/1.5 ui-sans-serif,system-ui,sans-serif; }
3
+ .playground-preview { padding: 24px; overflow-wrap: anywhere; }
4
+ #preview-feedback { font-size: 14px; color: var(--muted-foreground); margin-top: 16px; }
5
+ #preview-feedback:empty { display: none; }
@@ -0,0 +1,12 @@
1
+ // Sandbox interactions never navigate, submit email, or open Ghost Portal.
2
+ document.addEventListener('submit', event => { event.preventDefault(); document.querySelector('#preview-feedback').textContent = 'Demo only. No email was sent or stored.'; });
3
+ document.addEventListener('click', event => {
4
+ const element = event.target.closest('a,button');
5
+ if (!element || element.closest('[data-ghcn-toc]')) return;
6
+ event.preventDefault();
7
+ if (element.type === 'submit') {
8
+ document.querySelector('#preview-feedback').textContent = 'Demo only. No email was sent or stored.';
9
+ return;
10
+ }
11
+ document.querySelector('#preview-feedback').textContent = element.getAttribute('aria-disabled') === 'true' || element.disabled ? 'This action is disabled.' : 'Demo action. Test navigation, search and Portal on your Ghost publication.';
12
+ });
@@ -56,7 +56,7 @@ export function inspectTheme(themeRoot) {
56
56
  for (const match of source.matchAll(/\{\{asset\s+["']([^"']+)["']/g)) {
57
57
  if (!exists(`assets/${match[1]}`)) errors.push(`${file}: missing asset ${match[1]} (run your build)`);
58
58
  }
59
- for (const match of source.matchAll(/\{\{>\s*["']([^"']+)["']/g)) {
59
+ for (const match of source.matchAll(/\{\{(?:#>|>)\s*["']([^"']+)["']/g)) {
60
60
  if (!exists(`partials/${match[1]}.hbs`)) errors.push(`${file}: missing partial ${match[1]}`);
61
61
  }
62
62
  }
@@ -0,0 +1,18 @@
1
+ import { ComponentManifest } from './registry';
2
+ import { GhostcnConfig } from './theme-project';
3
+ export type FileStatus = 'unchanged' | 'upstream-changed' | 'locally-modified' | 'conflict' | 'missing' | 'untracked' | 'removed-upstream';
4
+ export interface FileComparison {
5
+ path: string;
6
+ status: FileStatus;
7
+ baseline?: string;
8
+ local?: string;
9
+ incoming?: string;
10
+ }
11
+ export declare function comparisonManifest(name: string, latest: boolean): Promise<ComponentManifest>;
12
+ export declare function compareComponent(themeRoot: string, config: GhostcnConfig, manifest: ComponentManifest): {
13
+ name: string;
14
+ installedRevision: string;
15
+ incomingRevision: string;
16
+ files: FileComparison[];
17
+ };
18
+ export declare function unifiedDiff(before: string | undefined, after: string | undefined, label: string): string;
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.comparisonManifest = comparisonManifest;
7
+ exports.compareComponent = compareComponent;
8
+ exports.unifiedDiff = unifiedDiff;
9
+ const fs_1 = __importDefault(require("fs"));
10
+ const registry_1 = require("./registry");
11
+ const component_files_1 = require("./component-files");
12
+ const component_history_1 = require("./component-history");
13
+ async function comparisonManifest(name, latest) {
14
+ name = (0, registry_1.sanitizeComponentName)(name);
15
+ if (!latest) {
16
+ const manifest = await (0, registry_1.getComponent)(name);
17
+ if (!manifest)
18
+ throw new Error(`Component "${name}" was not found.`);
19
+ return manifest;
20
+ }
21
+ // A latest comparison must never silently fall back to a stale bundled registry.
22
+ const base = process.env.GHOST_UI_REGISTRY_URL || registry_1.DEFAULT_REGISTRY_URL;
23
+ const url = new URL(`${base.replace(/\/$/, '')}/components/${name}.json`);
24
+ if (!['http:', 'https:'].includes(url.protocol) || url.username || url.password)
25
+ throw new Error('Invalid registry URL.');
26
+ const manifest = await (0, registry_1.fetchRegistryJson)(url.href, 10000);
27
+ if (manifest.name !== name || !Array.isArray(manifest.files))
28
+ throw new Error('Registry returned an invalid component manifest.');
29
+ return manifest;
30
+ }
31
+ function compareComponent(themeRoot, config, manifest) {
32
+ const files = (0, component_files_1.componentFiles)(themeRoot, config, manifest);
33
+ const saved = (0, component_history_1.readHistory)(themeRoot).components[manifest.name];
34
+ const incoming = Object.fromEntries(files.map(file => [file.relative, file.content]));
35
+ const paths = [...new Set([...Object.keys(incoming), ...Object.keys(saved?.files || {})])].sort();
36
+ const comparisons = paths.map(relative => {
37
+ const target = (0, component_files_1.safeThemePath)(themeRoot, relative);
38
+ const baseline = saved?.files[relative];
39
+ const local = fs_1.default.existsSync(target) ? fs_1.default.readFileSync(target, 'utf8') : undefined;
40
+ const next = incoming[relative];
41
+ let status;
42
+ if (next === undefined)
43
+ status = 'removed-upstream';
44
+ else if (local === undefined)
45
+ status = 'missing';
46
+ else if (local === next)
47
+ status = 'unchanged';
48
+ else if (baseline === undefined)
49
+ status = 'untracked';
50
+ else if (baseline === next)
51
+ status = 'locally-modified';
52
+ else if (baseline === local)
53
+ status = 'upstream-changed';
54
+ else
55
+ status = 'conflict';
56
+ return { path: relative, status, baseline, local, incoming: next };
57
+ });
58
+ return { name: manifest.name, installedRevision: saved?.revision, incomingRevision: (0, component_history_1.revision)(incoming), files: comparisons };
59
+ }
60
+ // Complete line diff with bounded memory. Large files remain reviewable as replacement hunks.
61
+ function unifiedDiff(before, after, label) {
62
+ if (before === after)
63
+ return '';
64
+ const split = (value) => value?.replace(/\r\n/g, '\n').match(/[^\n]*\n|[^\n]+$/g) || [];
65
+ const a = split(before);
66
+ const b = split(after);
67
+ const lines = [`--- ${label} (local)`, `+++ ${label} (registry)`, `@@ -${a.length ? 1 : 0},${a.length} +${b.length ? 1 : 0},${b.length} @@`];
68
+ const emit = (prefix, value) => {
69
+ lines.push(prefix + (value.endsWith('\n') ? value.slice(0, -1) : value));
70
+ if (!value.endsWith('\n'))
71
+ lines.push('\');
72
+ };
73
+ if (a.length * b.length > 1_000_000) {
74
+ a.forEach(value => emit('-', value));
75
+ b.forEach(value => emit('+', value));
76
+ return lines.join('\n');
77
+ }
78
+ const width = b.length + 1;
79
+ const matrix = new Uint32Array((a.length + 1) * width);
80
+ for (let i = a.length - 1; i >= 0; i--)
81
+ for (let j = b.length - 1; j >= 0; j--)
82
+ matrix[i * width + j] = a[i] === b[j] ? 1 + matrix[(i + 1) * width + j + 1] : Math.max(matrix[(i + 1) * width + j], matrix[i * width + j + 1]);
83
+ let i = 0, j = 0;
84
+ while (i < a.length || j < b.length) {
85
+ if (i < a.length && j < b.length && a[i] === b[j])
86
+ emit(' ', a[i++]), j++;
87
+ else if (i < a.length && (j === b.length || matrix[(i + 1) * width + j] >= matrix[i * width + j + 1]))
88
+ emit('-', a[i++]);
89
+ else
90
+ emit('+', b[j++]);
91
+ }
92
+ return lines.join('\n');
93
+ }
@@ -0,0 +1,9 @@
1
+ import { ComponentManifest } from './registry';
2
+ import { GhostcnConfig } from './theme-project';
3
+ export { safeThemePath } from './theme-files';
4
+ export declare function componentPartialName(config: GhostcnConfig, name: string): string;
5
+ export declare function componentFiles(themeRoot: string, config: GhostcnConfig, manifest: ComponentManifest): {
6
+ relative: string;
7
+ target: string;
8
+ content: string;
9
+ }[];
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.safeThemePath = void 0;
7
+ exports.componentPartialName = componentPartialName;
8
+ exports.componentFiles = componentFiles;
9
+ const path_1 = __importDefault(require("path"));
10
+ const fs_1 = __importDefault(require("fs"));
11
+ const theme_files_1 = require("./theme-files");
12
+ const styles_1 = require("./styles");
13
+ var theme_files_2 = require("./theme-files");
14
+ Object.defineProperty(exports, "safeThemePath", { enumerable: true, get: function () { return theme_files_2.safeThemePath; } });
15
+ function componentPartialName(config, name) {
16
+ const directory = path_1.default.posix.normalize((config.aliases?.partials || 'partials/components').replace(/\\/g, '/'));
17
+ if (directory !== 'partials' && !directory.startsWith('partials/'))
18
+ throw new Error('Component partials must live under partials/ for Ghost to load them.');
19
+ return [directory.slice('partials'.length).replace(/^\//, ''), name].filter(Boolean).join('/');
20
+ }
21
+ function aliasedPartial(content, config) {
22
+ // Rewrite only static component invocations, including partial blocks and their closing tags.
23
+ // Shared by diff and install: incoming content and saved baselines use identical aliasing.
24
+ return content.replace(/(\{\{(?:#>|>|\/)\s*)(["']?)components\/([a-z0-9-]+)(\2)(?=[\s}])/g, (_all, prefix, quote, name) => `${prefix}${quote}${componentPartialName(config, name)}${quote}`);
25
+ }
26
+ // Shared by installation and read-only comparisons so aliases and CSS layers cannot drift.
27
+ function componentFiles(themeRoot, config, manifest) {
28
+ const targets = new Set();
29
+ return manifest.files.map(file => {
30
+ if (path_1.default.basename(file.name) !== file.name || /[\\/]/.test(file.name))
31
+ throw new Error('Unsafe component file name.');
32
+ const aliases = { partial: config.aliases?.partials || 'partials/components', style: config.aliases?.styles || 'assets/css/components', js: config.aliases?.js || 'assets/js/components' };
33
+ if (!['partial', 'style', 'js'].includes(file.type) || typeof file.content !== 'string')
34
+ throw new Error('Invalid component file.');
35
+ const relative = file.placement === 'theme' ? file.target : path_1.default.join(aliases[file.type], file.name);
36
+ if (!relative)
37
+ throw new Error('Missing component target.');
38
+ const target = (0, theme_files_1.safeThemePath)(themeRoot, relative);
39
+ if (fs_1.default.existsSync(target) && !fs_1.default.statSync(target).isFile())
40
+ throw new Error('Component target must be a file, not a directory.');
41
+ if (file.type === 'style' || file.type === 'js')
42
+ (0, theme_files_1.toGhostAssetPath)(relative);
43
+ if (targets.has(target))
44
+ throw new Error('Duplicate component target.');
45
+ targets.add(target);
46
+ return { relative: path_1.default.relative(path_1.default.resolve(themeRoot), target).replace(/\\/g, '/'), target, content: file.type === 'style' ? (0, styles_1.componentCss)(file.content, config.style) : file.type === 'partial' ? aliasedPartial(file.content, config) : file.content };
47
+ });
48
+ }
@@ -0,0 +1,11 @@
1
+ export interface InstalledComponent {
2
+ revision: string;
3
+ files: Record<string, string>;
4
+ }
5
+ export interface ComponentHistory {
6
+ schema: 1;
7
+ components: Record<string, InstalledComponent>;
8
+ }
9
+ export declare function revision(files: Record<string, string>): string;
10
+ export declare function readHistory(themeRoot: string): ComponentHistory;
11
+ export declare function recordInstalledFiles(themeRoot: string, name: string, files: Record<string, string>): void;