anentrypoint-design 0.0.105 → 0.0.107
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/247420.js +113 -15
- package/package.json +1 -1
- package/src/page-html.js +182 -15
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "anentrypoint-design",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.107",
|
|
4
4
|
"description": "247420 design system SDK — webjsx + modified ripple-ui, single-file ESM bundle for reproducible use of the AnEntrypoint design.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/247420.js",
|
package/src/page-html.js
CHANGED
|
@@ -1,27 +1,194 @@
|
|
|
1
|
-
//
|
|
2
|
-
// using the SDK
|
|
1
|
+
// Static-site page HTML renderer. Emits a thin SDK-shell document that mounts
|
|
2
|
+
// the page using the SDK's own kit components (Hero, Section, Panel, Row, etc.)
|
|
3
|
+
// — the kit is the single source of truth for visual design; this file only
|
|
4
|
+
// declares the data shape and the mount entry point.
|
|
5
|
+
//
|
|
6
|
+
// Consumer contract:
|
|
7
|
+
// renderPageHtml({
|
|
8
|
+
// title, slug, siteName,
|
|
9
|
+
// navItems: [[label, href], ...], // hrefs are joined with basePath
|
|
10
|
+
// basePath: '/freddie/', // prefix for relative nav hrefs
|
|
11
|
+
// hero: { heading, body, accent, badges, ctas },
|
|
12
|
+
// sections: [{ id, name, lede, body, features: [{name, desc, benefit}] }, ...],
|
|
13
|
+
// examples: [{ label, desc, href }, ...],
|
|
14
|
+
// body: markdown-string,
|
|
15
|
+
// theme: 'auto' | 'light' | 'ink',
|
|
16
|
+
// cssHref, headExtra,
|
|
17
|
+
// })
|
|
3
18
|
|
|
4
|
-
|
|
19
|
+
export function escape(s) {
|
|
20
|
+
return String(s).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function inlineMd(s) {
|
|
24
|
+
return s
|
|
25
|
+
.replace(/`([^`]+)`/g, '<code>$1</code>')
|
|
26
|
+
.replace(/\*\*([^*]+)\*\*/g, '<strong>$1</strong>')
|
|
27
|
+
.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '<a href="$2">$1</a>');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function renderMarkdown(md) {
|
|
31
|
+
const lines = String(md || '').split('\n');
|
|
32
|
+
const out = [];
|
|
33
|
+
let inCode = false, inList = false;
|
|
34
|
+
for (const line of lines) {
|
|
35
|
+
if (line.startsWith('```')) { if (inCode) { out.push('</pre>'); inCode = false; } else { out.push('<pre>'); inCode = true; } continue; }
|
|
36
|
+
if (inCode) { out.push(escape(line)); continue; }
|
|
37
|
+
if (line.startsWith('# ')) out.push(`<h1>${escape(line.slice(2))}</h1>`);
|
|
38
|
+
else if (line.startsWith('## ')) out.push(`<h2>${escape(line.slice(3))}</h2>`);
|
|
39
|
+
else if (line.startsWith('### ')) out.push(`<h3>${escape(line.slice(4))}</h3>`);
|
|
40
|
+
else if (line.startsWith('- ')) { if (!inList) { out.push('<ul>'); inList = true; } out.push(`<li>${inlineMd(escape(line.slice(2)))}</li>`); }
|
|
41
|
+
else { if (inList) { out.push('</ul>'); inList = false; } if (line.trim()) out.push(`<p>${inlineMd(escape(line))}</p>`); }
|
|
42
|
+
}
|
|
43
|
+
if (inList) out.push('</ul>');
|
|
44
|
+
if (inCode) out.push('</pre>');
|
|
45
|
+
return out.join('\n');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Join a basePath prefix to a nav href. Absolute URLs and hash links pass
|
|
49
|
+
// through unchanged; leading-slash paths get the prefix.
|
|
50
|
+
function joinHref(basePath, href) {
|
|
51
|
+
if (!href) return '#';
|
|
52
|
+
const h = String(href);
|
|
53
|
+
if (/^([a-z]+:|#|\/\/)/i.test(h)) return h;
|
|
54
|
+
if (!basePath) return h;
|
|
55
|
+
const base = basePath.replace(/\/+$/, '');
|
|
56
|
+
if (h.startsWith('/')) return base + h;
|
|
57
|
+
return base + '/' + h.replace(/^\.?\//, '');
|
|
58
|
+
}
|
|
5
59
|
|
|
6
|
-
export function renderPageHtml({
|
|
60
|
+
export function renderPageHtml({
|
|
61
|
+
title = '247420', slug = 'index', siteName = '247420',
|
|
62
|
+
navItems = [], basePath = '',
|
|
63
|
+
hero, sections, examples, body,
|
|
64
|
+
theme = 'auto', cssHref, headExtra = ''
|
|
65
|
+
} = {}) {
|
|
7
66
|
const cssLink = cssHref
|
|
8
67
|
? `<link rel="stylesheet" href="${cssHref}">`
|
|
9
68
|
: `<link rel="stylesheet" href="https://unpkg.com/anentrypoint-design@latest/dist/247420.css">`;
|
|
69
|
+
|
|
70
|
+
// Resolve nav hrefs server-side against basePath. Client receives final URLs.
|
|
71
|
+
const navResolved = (Array.isArray(navItems) ? navItems : []).map(([label, href]) =>
|
|
72
|
+
[label, joinHref(basePath, href)]
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
// Data the client mount needs. Markdown body is parsed server-side into
|
|
76
|
+
// HTML so the client can innerHTML it inside a Section.
|
|
77
|
+
const pageData = {
|
|
78
|
+
title, slug, siteName, navItems: navResolved, theme,
|
|
79
|
+
hero: hero || null,
|
|
80
|
+
sections: Array.isArray(sections) ? sections : [],
|
|
81
|
+
examples: Array.isArray(examples) ? examples : [],
|
|
82
|
+
bodyHtml: body ? renderMarkdown(body) : '',
|
|
83
|
+
};
|
|
84
|
+
|
|
10
85
|
return `<!doctype html>
|
|
11
|
-
<html lang="en" class="
|
|
86
|
+
<html lang="en" class="ds-247420" data-theme="${theme}">
|
|
12
87
|
<head>
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
88
|
+
<meta charset="utf-8">
|
|
89
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
90
|
+
<title>${escape(title)} — ${escape(siteName)}</title>
|
|
91
|
+
${cssLink}
|
|
92
|
+
<script type="importmap">
|
|
93
|
+
{ "imports": { "anentrypoint-design": "https://unpkg.com/anentrypoint-design@latest/dist/247420.js" } }
|
|
94
|
+
</script>
|
|
95
|
+
<style>
|
|
96
|
+
.app-stage { max-width: 1100px; margin: 0 auto; padding: 24px; display: grid; gap: 24px }
|
|
97
|
+
.page-body h1 { margin-top: 0 } .page-body h2 { margin-top: 32px } .page-body h3 { margin-top: 24px }
|
|
98
|
+
.page-body pre { margin: 12px 0; background: var(--panel-2); padding: 12px; border-radius: 8px; overflow-x: auto }
|
|
99
|
+
</style>
|
|
100
|
+
<script id="__site__" type="application/json">${JSON.stringify(pageData).replace(/</g, '\\u003c')}</script>
|
|
101
|
+
${headExtra}
|
|
18
102
|
</head>
|
|
19
103
|
<body>
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
104
|
+
<div id="app"></div>
|
|
105
|
+
<script type="module">
|
|
106
|
+
import { mount, components as C, h } from 'anentrypoint-design';
|
|
107
|
+
const data = JSON.parse(document.getElementById('__site__').textContent);
|
|
108
|
+
const RAILS = ['rail-green', 'rail-purple', 'rail-mascot', 'rail-sun', 'rail-flame', 'rail-sky'];
|
|
109
|
+
|
|
110
|
+
function heroNode(hero) {
|
|
111
|
+
if (!hero) return null;
|
|
112
|
+
return C.Hero({
|
|
113
|
+
eyebrow: hero.eyebrow,
|
|
114
|
+
title: hero.heading || hero.title || data.title,
|
|
115
|
+
body: hero.body || hero.subheading || '',
|
|
116
|
+
accent: hero.accent,
|
|
117
|
+
badge: Array.isArray(hero.badges) && hero.badges[0] ? hero.badges[0].label : undefined,
|
|
118
|
+
actions: Array.isArray(hero.ctas) ? hero.ctas.map(c => ({ label: c.label || c.cta || 'go', href: c.href || '#' })) : [],
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function sectionNode(sec, idx) {
|
|
123
|
+
const rail = RAILS[idx % RAILS.length];
|
|
124
|
+
const features = sec.features || sec.items || [];
|
|
125
|
+
const rows = features.map((f, i) => h('div', { key: i, class: 'row ' + rail },
|
|
126
|
+
h('span', { class: 'title' }, f.name),
|
|
127
|
+
f.desc ? h('div', { class: 'sub', innerHTML: f.desc.replace(/\`([^\`]+)\`/g, '<code>$1</code>') }) : null,
|
|
128
|
+
f.benefit ? h('div', { class: 'row-benefit' }, f.benefit) : null,
|
|
129
|
+
));
|
|
130
|
+
return C.Section({
|
|
131
|
+
title: sec.name || sec.title || sec.id,
|
|
132
|
+
children: [
|
|
133
|
+
sec.lede ? h('p', { class: 'ds-lede' }, sec.lede) : null,
|
|
134
|
+
...rows,
|
|
135
|
+
sec.body && sec.body.length >= 240 ? h('div', { class: 'page-body', innerHTML: __md(sec.body) }) : null,
|
|
136
|
+
].filter(Boolean),
|
|
137
|
+
});
|
|
23
138
|
}
|
|
24
139
|
|
|
25
|
-
function
|
|
26
|
-
|
|
140
|
+
function examplesNode(examples) {
|
|
141
|
+
if (!examples || !examples.length) return null;
|
|
142
|
+
return C.Section({
|
|
143
|
+
title: 'explore',
|
|
144
|
+
children: examples.map((e, i) => {
|
|
145
|
+
const rail = RAILS[(i + 1) % RAILS.length];
|
|
146
|
+
return h('a', { key: i, class: 'row ' + rail, href: e.href || '#' },
|
|
147
|
+
h('span', { class: 'code' }, String(i + 1).padStart(2, '0')),
|
|
148
|
+
h('span', { class: 'title' }, e.label || e.name || e.href),
|
|
149
|
+
e.desc ? h('span', { class: 'meta dim' }, ' — ' + e.desc) : null,
|
|
150
|
+
h('span', { class: 'ds-row-arrow' }, '↗'),
|
|
151
|
+
);
|
|
152
|
+
}),
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// minimal client-side markdown renderer matching server-side renderer (idempotent for already-html bodies)
|
|
157
|
+
function __md(md) {
|
|
158
|
+
const lines = String(md || '').split('\\n');
|
|
159
|
+
const out = []; let inCode = false, inList = false;
|
|
160
|
+
const esc = (s) => String(s).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
161
|
+
const inl = (s) => s.replace(/\`([^\`]+)\`/g, '<code>$1</code>').replace(/\\*\\*([^*]+)\\*\\*/g, '<strong>$1</strong>').replace(/\\[([^\\]]+)\\]\\(([^)]+)\\)/g, '<a href="$2">$1</a>');
|
|
162
|
+
for (const line of lines) {
|
|
163
|
+
if (line.startsWith('\`\`\`')) { if (inCode) { out.push('</pre>'); inCode = false; } else { out.push('<pre>'); inCode = true; } continue; }
|
|
164
|
+
if (inCode) { out.push(esc(line)); continue; }
|
|
165
|
+
if (line.startsWith('# ')) out.push('<h1>' + esc(line.slice(2)) + '</h1>');
|
|
166
|
+
else if (line.startsWith('## ')) out.push('<h2>' + esc(line.slice(3)) + '</h2>');
|
|
167
|
+
else if (line.startsWith('### ')) out.push('<h3>' + esc(line.slice(4)) + '</h3>');
|
|
168
|
+
else if (line.startsWith('- ')) { if (!inList) { out.push('<ul>'); inList = true; } out.push('<li>' + inl(esc(line.slice(2))) + '</li>'); }
|
|
169
|
+
else { if (inList) { out.push('</ul>'); inList = false; } if (line.trim()) out.push('<p>' + inl(esc(line)) + '</p>'); }
|
|
170
|
+
}
|
|
171
|
+
if (inList) out.push('</ul>');
|
|
172
|
+
if (inCode) out.push('</pre>');
|
|
173
|
+
return out.join('\\n');
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const bodyNode = data.bodyHtml ? C.Section({ children: h('div', { class: 'page-body', innerHTML: data.bodyHtml }) }) : null;
|
|
177
|
+
|
|
178
|
+
const mainChildren = [
|
|
179
|
+
heroNode(data.hero),
|
|
180
|
+
...data.sections.map(sectionNode),
|
|
181
|
+
examplesNode(data.examples),
|
|
182
|
+
bodyNode,
|
|
183
|
+
].filter(Boolean);
|
|
184
|
+
|
|
185
|
+
mount(document.getElementById('app'), () => C.AppShell({
|
|
186
|
+
topbar: C.Topbar({ brand: data.siteName, items: data.navItems, active: data.title }),
|
|
187
|
+
crumb: C.Crumb({ leaf: data.title }),
|
|
188
|
+
main: h('div', { class: 'app-stage' }, ...mainChildren),
|
|
189
|
+
status: C.Status({ left: [data.siteName.toLowerCase(), data.slug], right: ['live'] }),
|
|
190
|
+
}));
|
|
191
|
+
</script>
|
|
192
|
+
</body>
|
|
193
|
+
</html>`;
|
|
27
194
|
}
|