@lincyaw/web 0.0.0-stage → 1.0.0-rc.0

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.
@@ -0,0 +1,71 @@
1
+ import { componentErrors, presmiumReport } from '@lincyaw/host'
2
+ import type { NavigationPosition } from '@lincyaw/host'
3
+ import { irBlocks, PREVIEW_REVISION, startPreviewAgent, stepKeys, stepTrail } from '@lincyaw/kernel'
4
+ import type { PreviewAgent } from '@lincyaw/kernel'
5
+ import type { FollowAnchor, Viewer } from '@lincyaw/viewer'
6
+ import type { Ref } from 'vue'
7
+ import { nextTick, watch } from 'vue'
8
+ import { createViewerNavigation } from './host.ts'
9
+
10
+ export interface WebPreviewOptions {
11
+ origins: string[]
12
+ document: string
13
+ }
14
+
15
+ export interface WebPreviewPage {
16
+ viewer: Viewer
17
+ dark: Ref<boolean>
18
+ }
19
+
20
+ export function startWebPreview(page: WebPreviewPage, options: WebPreviewOptions): void {
21
+ const { viewer, dark } = page
22
+ const navigation = createViewerNavigation(viewer)
23
+ const revision = () => {
24
+ const value = viewer.doc.value.meta[PREVIEW_REVISION]
25
+ return typeof value === 'string' ? value : undefined
26
+ }
27
+ const blockStep = (section: string, block: string) => {
28
+ const found = viewer.section(section)
29
+ return found ? [...irBlocks(found.blocks)].find(b => b.id === block)?.at : undefined
30
+ }
31
+ const agent: PreviewAgent | undefined = startPreviewAgent({
32
+ renderer: 'web',
33
+ document: options.document,
34
+ origins: options.origins,
35
+ revision,
36
+ position() {
37
+ const { section, step, trail, view } = navigation.position.value as NavigationPosition & FollowAnchor
38
+ return section === undefined ? undefined : { section, step, trail: trail ?? [], ...view ? { view } : {} }
39
+ },
40
+ go: ({ section, step, trail, view }) => navigation.go({ slide: 0, step: step ?? 0, section, ...trail ? { trail } : {}, ...view ? { view } : {} }),
41
+ reveal: ({ section, block }) => viewer.show({ section, step: (block && blockStep(section, block)) || 0 }),
42
+ setDark(value) {
43
+ dark.value = value
44
+ },
45
+ stepOf({ section, block }) {
46
+ const step = blockStep(section, block)
47
+ const found = viewer.section(section)
48
+ return step === undefined || !found ? undefined : { step, trail: stepTrail(stepKeys(found), step) }
49
+ },
50
+ })
51
+ if (!agent) return
52
+ watch(() => navigation.position.value, () => agent.moved())
53
+ watch(revision, () => void nextTick(() => requestAnimationFrame(() => agent.updated())))
54
+ watchProblems(agent)
55
+ }
56
+
57
+ function watchProblems(agent: PreviewAgent): void {
58
+ const told = new Set<string>()
59
+ watch(() => [presmiumReport()?.plugins ?? [], componentErrors()] as const, ([plugins, errors]) => {
60
+ const problems = [
61
+ ...plugins.filter(p => p.status === 'failed' || p.status === 'disabled').map(p => ({ level: p.status === 'failed' ? 'error' as const : 'warning' as const, plugin: p.id, message: p.reason ?? p.status })),
62
+ ...errors.map(e => ({ level: 'error' as const, plugin: e.component, message: e.message })),
63
+ ]
64
+ for (const problem of problems) {
65
+ const key = JSON.stringify(problem)
66
+ if (told.has(key)) continue
67
+ told.add(key)
68
+ agent.report(problem)
69
+ }
70
+ }, { immediate: true })
71
+ }
@@ -0,0 +1,427 @@
1
+ :root {
2
+ --vp-font-family-base: var(--pm-font-sans);
3
+ --vp-font-family-mono: var(--pm-font-mono);
4
+
5
+ --vp-c-bg: var(--pm-color-bg);
6
+ --vp-c-bg-alt: var(--pm-color-sunk);
7
+ --vp-c-bg-elv: var(--pm-color-surface);
8
+ --vp-c-bg-soft: var(--pm-color-sunk);
9
+ --vp-c-text-1: var(--pm-color-ink);
10
+ --vp-c-text-2: var(--pm-color-muted);
11
+ --vp-c-text-3: var(--pm-color-muted);
12
+ --vp-c-border: var(--pm-color-line-strong);
13
+ --vp-c-divider: var(--pm-color-line);
14
+ --vp-c-gutter: var(--pm-color-line);
15
+
16
+ --vp-c-brand-1: var(--pm-color-accent);
17
+ --vp-c-brand-2: color-mix(in srgb, var(--pm-color-accent) 88%, var(--pm-color-ink));
18
+ --vp-c-brand-3: var(--pm-color-accent);
19
+ --vp-c-brand-soft: var(--pm-color-accent-soft);
20
+ --vp-c-tip-1: var(--pm-color-accent);
21
+ --vp-c-tip-soft: var(--pm-color-accent-soft);
22
+ --vp-c-success-1: var(--pm-color-ok);
23
+ --vp-c-success-soft: var(--pm-color-ok-soft);
24
+ --vp-c-warning-1: var(--pm-color-warn);
25
+ --vp-c-warning-soft: var(--pm-color-warn-soft);
26
+ --vp-c-danger-1: var(--pm-color-danger);
27
+ --vp-c-danger-soft: var(--pm-color-danger-soft);
28
+ --vp-c-default-soft: var(--pm-color-sunk);
29
+
30
+ --vp-code-color: var(--pm-color-ink);
31
+ --vp-code-bg: var(--pm-color-sunk);
32
+ --vp-code-block-bg: var(--pm-color-code);
33
+ --vp-code-copy-code-bg: var(--pm-color-surface);
34
+ --vp-code-line-highlight-color: var(--pm-color-selected);
35
+
36
+ --vp-nav-bg-color: var(--pm-color-bg);
37
+ --vp-sidebar-bg-color: var(--pm-color-bg);
38
+ --vp-local-search-bg: var(--pm-color-bg);
39
+ --vp-local-search-result-bg: var(--pm-color-surface);
40
+ --vp-local-search-highlight-bg: var(--pm-color-accent);
41
+ --vp-local-search-highlight-text: var(--pm-color-on-accent);
42
+ }
43
+
44
+ html {
45
+ font-size: 100%;
46
+ }
47
+
48
+ body {
49
+ font-size: 1rem;
50
+ }
51
+
52
+ .vp-doc .pm-block--markdown,
53
+ .vp-doc .pm-section__title,
54
+ .vp-doc .pm-section :is(h1, h2, h3, h4) {
55
+ font-family: var(--pm-font-serif);
56
+ }
57
+
58
+ .vp-doc .pm-block--markdown {
59
+ font-size: var(--pm-text-reading);
60
+ line-height: var(--pm-leading-reading);
61
+ }
62
+
63
+ .vp-doc .pm-block--markdown :is(code, pre, kbd) {
64
+ font-family: var(--pm-font-mono);
65
+ }
66
+
67
+ .vp-doc .pm-section :is(h1, h2, h3, h4) {
68
+ font-weight: 600;
69
+ letter-spacing: normal;
70
+ line-height: var(--pm-leading-tight);
71
+ }
72
+
73
+ .vp-doc a {
74
+ text-underline-offset: 2px;
75
+ }
76
+
77
+ .vp-doc .pm-section h1 {
78
+ font-size: 2rem;
79
+ }
80
+
81
+ .vp-doc .pm-section h2 {
82
+ font-size: 1.5rem;
83
+ }
84
+
85
+ .vp-doc .pm-section h3 {
86
+ font-size: 1.25rem;
87
+ }
88
+
89
+ .vp-doc .pm-section :is(h4, h5, h6) {
90
+ font-size: 1.0625rem;
91
+ }
92
+
93
+ .vp-doc :is(strong, b, th),
94
+ .pm-present :is(strong, b),
95
+ .pm-presenter :is(strong, b) {
96
+ font-synthesis: weight style;
97
+ }
98
+
99
+ .pm-view-menu:focus-visible,
100
+ .pm-block :is(button, input, select, textarea, summary, [tabindex]):focus-visible,
101
+ .pm-present :is(button, input, select, textarea, summary):focus-visible,
102
+ .pm-presenter :is(button, input, select, textarea, summary):focus-visible,
103
+ .pm-toolbar :is(button, input, select, textarea, a):focus-visible {
104
+ outline: 2px solid var(--vp-c-brand-1);
105
+ outline-offset: 2px;
106
+ }
107
+
108
+ .VPNavBar .container > .title {
109
+ flex-shrink: 1;
110
+ min-width: 0;
111
+ }
112
+
113
+ .VPNavBarTitle,
114
+ .VPNavBarTitle a.title {
115
+ min-width: 0;
116
+ max-width: 100%;
117
+ }
118
+
119
+ .VPNavBarTitle a.title > span {
120
+ min-width: 0;
121
+ overflow: hidden;
122
+ text-overflow: ellipsis;
123
+ white-space: nowrap;
124
+ }
125
+
126
+ .VPNavBarTitle a.title {
127
+ font-family: var(--pm-font-serif);
128
+ font-weight: 600;
129
+ }
130
+
131
+ .VPSidebarItem.level-1 > .item .text {
132
+ font-weight: 600;
133
+ }
134
+
135
+ .pm-section {
136
+ scroll-margin-top: calc(var(--vp-nav-height) + 1rem);
137
+ }
138
+
139
+ .vp-doc .pm-section__title {
140
+ margin-top: 0;
141
+ padding-top: 0;
142
+ border-top: none;
143
+ }
144
+
145
+ .vp-doc .pm-section + .pm-section {
146
+ padding-top: 1.5rem;
147
+ border-top: 1px solid var(--vp-c-divider);
148
+ }
149
+
150
+ .vp-doc .pm-block div[class*='language-'] {
151
+ margin-left: 0;
152
+ margin-right: 0;
153
+ }
154
+
155
+ .vp-doc .pm-open-slides {
156
+ display: inline-flex;
157
+ gap: 0.25em;
158
+ align-items: center;
159
+ margin-left: 0.5em;
160
+ padding: 0 0.5em;
161
+ border: 1px solid var(--vp-c-divider);
162
+ border-radius: 999px;
163
+ color: var(--vp-c-text-2);
164
+ font-family: var(--pm-font-sans);
165
+ font-size: 0.8125rem;
166
+ font-weight: 500;
167
+ letter-spacing: normal;
168
+ line-height: 1.75;
169
+ text-decoration: none;
170
+ vertical-align: middle;
171
+ white-space: nowrap;
172
+ }
173
+
174
+ .vp-doc .pm-open-slides::after {
175
+ content: attr(data-label);
176
+ }
177
+
178
+ .vp-doc .pm-open-slides:hover {
179
+ border-color: var(--vp-c-brand-1);
180
+ color: var(--vp-c-brand-1);
181
+ }
182
+
183
+ .pm-view-menu {
184
+ margin-left: 0.5rem;
185
+ padding: 0.25rem 0.5rem;
186
+ border: 1px solid var(--pm-color-line-strong);
187
+ border-radius: var(--pm-radius-control);
188
+ background: var(--pm-color-surface);
189
+ color: var(--pm-color-ink);
190
+ font-family: var(--pm-font-sans);
191
+ font-size: var(--pm-text-sm);
192
+ cursor: pointer;
193
+ }
194
+
195
+ @supports (appearance: base-select) {
196
+ .pm-view-menu,
197
+ .pm-view-menu::picker(select) {
198
+ appearance: base-select;
199
+ }
200
+
201
+ .pm-view-menu {
202
+ display: inline-flex;
203
+ align-items: center;
204
+ gap: 0.375rem;
205
+ padding-inline: 0.625rem 0.5rem;
206
+ }
207
+
208
+ .pm-view-menu:hover {
209
+ background: var(--pm-color-sunk);
210
+ }
211
+
212
+ .pm-view-menu::picker-icon {
213
+ content: '';
214
+ width: 0.875rem;
215
+ height: 0.875rem;
216
+ background: currentColor;
217
+ mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") center / contain no-repeat;
218
+ transition: rotate 0.15s;
219
+ }
220
+
221
+ .pm-view-menu:open::picker-icon {
222
+ rotate: 180deg;
223
+ }
224
+
225
+ .pm-view-menu::picker(select) {
226
+ margin-block: 6px;
227
+ padding: var(--pm-space-1);
228
+ border: 1px solid var(--pm-color-line);
229
+ border-radius: var(--pm-radius-control);
230
+ background: var(--pm-color-surface);
231
+ color: var(--pm-color-ink);
232
+ box-shadow: var(--pm-shadow-float);
233
+ }
234
+
235
+ .pm-view-menu option {
236
+ gap: var(--pm-space-2);
237
+ padding: 0.375rem 0.625rem;
238
+ border-radius: var(--pm-radius-small);
239
+ font-family: var(--pm-font-sans);
240
+ font-size: var(--pm-text-sm);
241
+ cursor: pointer;
242
+ }
243
+
244
+ .pm-view-menu option:hover,
245
+ .pm-view-menu option:focus-visible {
246
+ background: var(--pm-color-sunk);
247
+ outline: none;
248
+ }
249
+
250
+ .pm-view-menu option:checked {
251
+ color: var(--pm-color-accent);
252
+ font-weight: 600;
253
+ }
254
+ }
255
+
256
+ .pm-view-menu--screen,
257
+ .pm-toolbar--screen {
258
+ margin: 1rem 0 0;
259
+ }
260
+
261
+ .pm-toolbar--screen {
262
+ flex-wrap: wrap;
263
+ }
264
+
265
+ .pm-toolbar--bar {
266
+ margin-inline-start: 0.75rem;
267
+ }
268
+
269
+ @media (max-width: 767px) {
270
+ .pm-view-menu--bar,
271
+ .pm-toolbar--bar {
272
+ display: none !important;
273
+ }
274
+ }
275
+
276
+ @media (min-width: 768px) {
277
+ .pm-view-menu--screen,
278
+ .pm-toolbar--screen {
279
+ display: none !important;
280
+ }
281
+ }
282
+
283
+ .pm-present,
284
+ .pm-presenter {
285
+ z-index: calc(var(--vp-z-index-local-nav, 32) + 100);
286
+ }
287
+
288
+ html.pm-presenting {
289
+ --pm-cue-z: calc(var(--vp-z-index-local-nav, 32) + 101);
290
+ }
291
+
292
+ .pm-site-link {
293
+ display: inline-flex;
294
+ align-items: center;
295
+ gap: var(--pm-space-1);
296
+ margin-left: 0.75rem;
297
+ padding: 0.25rem 0.625rem;
298
+ border: 1px solid var(--pm-color-line);
299
+ border-radius: var(--pm-radius-control);
300
+ color: var(--pm-color-ink);
301
+ font-family: var(--pm-font-sans);
302
+ font-size: var(--pm-text-sm);
303
+ font-weight: 500;
304
+ white-space: nowrap;
305
+ }
306
+
307
+ .pm-site-link:hover {
308
+ border-color: var(--pm-color-accent);
309
+ color: var(--pm-color-accent);
310
+ }
311
+
312
+ .pm-site-home {
313
+ display: flex;
314
+ flex-direction: column;
315
+ gap: var(--pm-space-8);
316
+ margin: 0 auto;
317
+ max-width: 69rem;
318
+ padding: var(--pm-space-8) 0 var(--pm-space-10);
319
+ }
320
+
321
+ .pm-site-home__title {
322
+ margin: 0;
323
+ font-family: var(--pm-font-serif);
324
+ font-size: var(--pm-text-display);
325
+ font-weight: 600;
326
+ line-height: var(--pm-leading-tight);
327
+ }
328
+
329
+ .pm-site-home__section {
330
+ display: grid;
331
+ gap: var(--pm-space-4);
332
+ }
333
+
334
+ .pm-site-home__filters {
335
+ display: flex;
336
+ flex-wrap: wrap;
337
+ align-items: center;
338
+ gap: var(--pm-space-3);
339
+ }
340
+
341
+ .pm-site-home__filters > .pm-ui-heading {
342
+ margin-right: auto;
343
+ }
344
+
345
+ .pm-site-home__search-box {
346
+ flex: 1 1 15rem;
347
+ max-width: 24rem;
348
+ }
349
+
350
+ .pm-site-home__tags {
351
+ flex-wrap: wrap;
352
+ }
353
+
354
+ .pm-site-home__grid {
355
+ display: grid;
356
+ grid-template-columns: repeat(auto-fill, minmax(min(18rem, 100%), 1fr));
357
+ gap: var(--pm-space-4);
358
+ }
359
+
360
+ .pm-site-home__documents {
361
+ display: contents;
362
+ margin: 0;
363
+ padding: 0;
364
+ list-style: none;
365
+ }
366
+
367
+ .pm-site-home__empty {
368
+ grid-column: 1 / -1;
369
+ }
370
+
371
+ .pm-site-home__document {
372
+ gap: var(--pm-space-3);
373
+ margin: 0;
374
+ }
375
+
376
+ .pm-site-home__link {
377
+ color: var(--pm-color-ink);
378
+ font-family: var(--pm-font-serif);
379
+ font-size: var(--pm-text-title);
380
+ font-weight: 600;
381
+ line-height: 1.3;
382
+ text-decoration: none;
383
+ }
384
+
385
+ .pm-site-home__link::after {
386
+ content: '';
387
+ position: absolute;
388
+ inset: 0;
389
+ border-radius: inherit;
390
+ }
391
+
392
+ .pm-site-home__link:hover {
393
+ color: var(--pm-color-accent);
394
+ }
395
+
396
+ .pm-site-home__link:focus-visible {
397
+ outline: none;
398
+ }
399
+
400
+ .pm-site-home__description {
401
+ margin: 0;
402
+ color: var(--pm-color-muted);
403
+ }
404
+
405
+ .pm-site-footer {
406
+ margin-top: 2rem;
407
+ padding-top: 1.5rem;
408
+ border-top: 1px solid var(--vp-c-gutter);
409
+ text-align: center;
410
+ font-size: 14px;
411
+ line-height: 24px;
412
+ color: var(--vp-c-text-2);
413
+ }
414
+
415
+ .pm-site-footer p {
416
+ margin: 0;
417
+ }
418
+
419
+ .pm-site-footer a {
420
+ text-decoration: underline;
421
+ text-underline-offset: 2px;
422
+ transition: color 0.25s;
423
+ }
424
+
425
+ .pm-site-footer a:hover {
426
+ color: var(--vp-c-text-1);
427
+ }