@lincyaw/web 0.0.0-stage → 1.0.0-rc.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.
- package/LICENSE +202 -0
- package/README.md +53 -2
- package/package.json +57 -3
- package/src/app/base.css +117 -0
- package/src/app/block-playback.ts +81 -0
- package/src/app/block-report.ts +104 -0
- package/src/app/document-modules.ts +30 -0
- package/src/app/env.d.ts +12 -0
- package/src/app/main.ts +198 -0
- package/src/app/page-app.ts +166 -0
- package/src/app/router.ts +109 -0
- package/src/app/server.ts +32 -0
- package/src/app/site/home.tsx +117 -0
- package/src/app/site/layout.tsx +78 -0
- package/src/app/site/search.tsx +22 -0
- package/src/app/site.css +1416 -0
- package/src/client/document.css +172 -0
- package/src/client/host.ts +22 -0
- package/src/client/preview-frame.ts +152 -0
- package/src/client/runtime.ts +159 -0
- package/src/domain/app-config.ts +89 -0
- package/src/domain/config.ts +107 -0
- package/src/domain/dev-updates.ts +12 -0
- package/src/domain/index.ts +17 -0
- package/src/domain/landing.ts +83 -0
- package/src/domain/links.ts +67 -0
- package/src/domain/messages.ts +116 -0
- package/src/domain/pages.ts +81 -0
- package/src/domain/themes.ts +59 -0
- package/src/domain/workspace-home.ts +12 -0
- package/src/node/client-modules.ts +92 -0
- package/src/node/document-bundle.ts +227 -0
- package/src/node/landing-template.ts +34 -0
- package/src/node/landing.ts +82 -0
- package/src/node/offline.ts +153 -0
- package/src/node/presmium.ts +10 -0
- package/src/node/publish.ts +169 -0
- package/src/node/renderer.ts +108 -0
- package/src/node/site-assets.ts +17 -0
- package/src/node/site-build.ts +297 -0
- package/src/node/site-files.ts +87 -0
- package/src/node/site-model.ts +333 -0
- package/src/node/site-page.ts +82 -0
- package/src/node/site-server.ts +817 -0
- package/src/node/slides.ts +135 -0
- package/src/node/viewer-app.ts +504 -0
- package/src/node/viewer-build.ts +38 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,54 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @lincyaw/web
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Presmium's web renderer: one prebuilt viewer app shows teaching-document pages in `presmium dev`, `presmium serve`, the workbench and a built site. A built site holds the app once and each document as data beside its pages (its IR, search index, own code bundle and published files); its pages are rendered on the server and then hydrated. The site shell is Presmium's own: a page per chapter, navigation, outline, pager, search, translations with a language menu, light and dark, the phone layout, links to the slides, and workspace sites of several documents with a home page, a 404 page and a sitemap. Independent homepages use their own site-page data or a freely designed HTML entry. The slides form is the viewer app's slides page (`@lincyaw/render-slides`).
|
|
4
|
+
|
|
5
|
+
Part of [Presmium](https://github.com/Lincyaw/presmium), which compiles canonical lecture.json teaching documents into web pages, slides, Jupyter notebooks and narrated playback.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
pnpm add -D @lincyaw/cli @lincyaw/web
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
`presmium build` builds it into `dist/web/` when it is installed (or `--to web`); `presmium dev --to web` runs its dev server.
|
|
14
|
+
|
|
15
|
+
## Configuration
|
|
16
|
+
|
|
17
|
+
In `lecture.json`, `metadata.renderers.web`: `base` (the site path), `port` (the dev server), `theme`, `params`, `layout`, and the site shell `nav`, `footer`, `head` and `sitemap`. At a workspace root, the shell options go under `site` in `presmium.workspace.yaml`, with `landing`, `home`, `lang` and `locales.<lang>.title`.
|
|
18
|
+
|
|
19
|
+
Choose the built-in `course`, `docs` or `showcase` theme; `docs` preserves the existing default. Theme parameters select an accent (`blue`, `teal`, `violet`, `amber`), typography (`reading`, `sans`), content width (`comfortable`, `wide`), and an optional `logo` with `logoAlt`. Omit `logoAlt` or set it to an empty string for a decorative logo beside the site title. Document layouts are `article` (default), `landing` and `wide`; `landing` combines all sections into one full-width HTML page. A workspace's theme and brand apply across its documents; each document can choose its own layout.
|
|
20
|
+
|
|
21
|
+
```yaml
|
|
22
|
+
title: My course
|
|
23
|
+
documents: ['*/lecture.json']
|
|
24
|
+
site:
|
|
25
|
+
theme: course
|
|
26
|
+
params:
|
|
27
|
+
accent: teal
|
|
28
|
+
typography: reading
|
|
29
|
+
contentWidth: comfortable
|
|
30
|
+
landing:
|
|
31
|
+
source: ./site/home.json
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
`landing.source` selects an independent site page with a hero and sections, separate from teaching documents. The same page object can be written inline in `landing`. For a freely designed HTML/CSS/JavaScript page, use `landing: { template: './site/home.html' }` instead; Vite bundles that HTML entry and its assets. The template receives reader-facing site data in `script#presmium-site-data` (`schemaVersion`, `title`, `base`, `lang`, `documents`). Teaching content, steps and scripts still belong only in `lecture.json`. Existing `landing: welcome` remains supported: it displays all sections of `welcome/lecture.json` at the site root while keeping that document's normal pages. `home` retains its redirect behavior and cannot be set together with `landing`.
|
|
35
|
+
|
|
36
|
+
For a ready-to-publish workspace:
|
|
37
|
+
|
|
38
|
+
```sh
|
|
39
|
+
presmium new my-site --type site --theme course --title 'My course'
|
|
40
|
+
cd my-site
|
|
41
|
+
pnpm install
|
|
42
|
+
pnpm serve
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
`pnpm build` writes `dist/web/`. The generated GitHub Pages workflow builds and deploys that directory using the repository's Pages base path. The [site theme guide](https://github.com/Lincyaw/presmium/blob/main/docs/site-themes.md) covers parameters, page layouts, standalone documents and deployment.
|
|
46
|
+
|
|
47
|
+
## Documentation
|
|
48
|
+
|
|
49
|
+
- [Author guide](https://github.com/Lincyaw/presmium/blob/main/site/guide/locales/en/lecture.json): media, workspaces and translations
|
|
50
|
+
- [Site themes](https://github.com/Lincyaw/presmium/blob/main/docs/site-themes.md): presets, independent homepages and GitHub Pages
|
|
51
|
+
|
|
52
|
+
## License
|
|
53
|
+
|
|
54
|
+
Apache-2.0
|
package/package.json
CHANGED
|
@@ -1,6 +1,60 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lincyaw/web",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.0.0-rc.1",
|
|
4
|
+
"description": "Presmium's web renderer: one prebuilt viewer that shows the web form in the workbench, in a dev server and as a built site, with search and form switching",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/Lincyaw/presmium.git",
|
|
9
|
+
"directory": "packages/web"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/Lincyaw/presmium/tree/main/packages/web#readme",
|
|
12
|
+
"bugs": "https://github.com/Lincyaw/presmium/issues",
|
|
13
|
+
"keywords": [
|
|
14
|
+
"presmium",
|
|
15
|
+
"renderer"
|
|
16
|
+
],
|
|
17
|
+
"type": "module",
|
|
18
|
+
"engines": {
|
|
19
|
+
"node": ">=22.19"
|
|
20
|
+
},
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public"
|
|
23
|
+
},
|
|
24
|
+
"exports": {
|
|
25
|
+
"./domain": "./src/domain/index.ts",
|
|
26
|
+
"./presmium": "./src/node/presmium.ts",
|
|
27
|
+
"./slides": "./src/node/slides.ts",
|
|
28
|
+
"./package.json": "./package.json"
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"src"
|
|
32
|
+
],
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"escape-html": "1.0.3",
|
|
35
|
+
"http-proxy-3": "2.0.1",
|
|
36
|
+
"katex": "0.18.10",
|
|
37
|
+
"launch-editor": "2.14.1",
|
|
38
|
+
"minisearch": "7.2.0",
|
|
39
|
+
"send": "1.2.1",
|
|
40
|
+
"sitemap": "9.0.1",
|
|
41
|
+
"vite": "8.3.4",
|
|
42
|
+
"react": "18.3.1",
|
|
43
|
+
"react-dom": "18.3.1"
|
|
44
|
+
},
|
|
45
|
+
"peerDependencies": {
|
|
46
|
+
"@lincyaw/host": "^1.0.0-rc.1",
|
|
47
|
+
"@lincyaw/kernel": "^1.0.0-rc.1",
|
|
48
|
+
"@lincyaw/viewer": "^1.0.0-rc.1"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@types/escape-html": "1.0.4",
|
|
52
|
+
"@types/send": "^1.2.1",
|
|
53
|
+
"@types/react": "18.3.28",
|
|
54
|
+
"@types/react-dom": "18.3.7",
|
|
55
|
+
"@lincyaw/host": "1.0.0-rc.1",
|
|
56
|
+
"@lincyaw/kernel": "1.0.0-rc.1",
|
|
57
|
+
"@lincyaw/cli": "1.0.0-rc.1",
|
|
58
|
+
"@lincyaw/viewer": "1.0.0-rc.1"
|
|
59
|
+
}
|
|
6
60
|
}
|
package/src/app/base.css
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/* The viewer app's page: one set of resets for every form, so that components look the same everywhere. */
|
|
2
|
+
|
|
3
|
+
*,
|
|
4
|
+
::before,
|
|
5
|
+
::after {
|
|
6
|
+
box-sizing: border-box;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
html {
|
|
10
|
+
line-height: 1.4;
|
|
11
|
+
font-size: 100%;
|
|
12
|
+
-webkit-text-size-adjust: 100%;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
html.dark {
|
|
16
|
+
color-scheme: dark;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
body {
|
|
20
|
+
margin: 0;
|
|
21
|
+
width: 100%;
|
|
22
|
+
min-height: 100vh;
|
|
23
|
+
background: var(--pm-color-bg);
|
|
24
|
+
color: var(--pm-color-ink);
|
|
25
|
+
font-family: var(--pm-font-sans);
|
|
26
|
+
font-size: 1rem;
|
|
27
|
+
line-height: 1.5rem;
|
|
28
|
+
-webkit-font-smoothing: antialiased;
|
|
29
|
+
text-rendering: optimizeLegibility;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
:is(h1, h2, h3, h4, h5, h6) {
|
|
33
|
+
margin: 0;
|
|
34
|
+
font-size: 1rem;
|
|
35
|
+
font-weight: 400;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
:is(p, blockquote, figure, fieldset) {
|
|
39
|
+
margin: 0;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
:is(ol, ul) {
|
|
43
|
+
margin: 0;
|
|
44
|
+
padding: 0;
|
|
45
|
+
list-style: none;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
a {
|
|
49
|
+
color: inherit;
|
|
50
|
+
text-decoration: inherit;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
:is(strong, b) {
|
|
54
|
+
font-weight: 600;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
:is(pre, code, kbd, samp) {
|
|
58
|
+
font-family: var(--pm-font-mono);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
:is(img, svg, video, canvas, audio, iframe, embed, object) {
|
|
62
|
+
display: block;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
:is(img, video) {
|
|
66
|
+
max-width: 100%;
|
|
67
|
+
height: auto;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
:is(button, input, optgroup, select, textarea) {
|
|
71
|
+
padding: 0;
|
|
72
|
+
border: 0;
|
|
73
|
+
color: inherit;
|
|
74
|
+
line-height: inherit;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
button {
|
|
78
|
+
background-color: transparent;
|
|
79
|
+
background-image: none;
|
|
80
|
+
font-family: inherit;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
:is(button, [role='button']):enabled {
|
|
84
|
+
cursor: pointer;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
table {
|
|
88
|
+
border-collapse: collapse;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
input {
|
|
92
|
+
background-color: transparent;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
textarea {
|
|
96
|
+
resize: vertical;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
fieldset {
|
|
100
|
+
padding: 0;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
:is(h1, h2, h3, h4, h5, h6, li, p) {
|
|
104
|
+
overflow-wrap: break-word;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/* A compiled block widget has its own read-only host, without a page shell. */
|
|
108
|
+
html.pm-block-document,
|
|
109
|
+
.pm-block-document body {
|
|
110
|
+
min-height: 0;
|
|
111
|
+
background: transparent;
|
|
112
|
+
}
|
|
113
|
+
.pm-block-document #app,
|
|
114
|
+
.pm-block-preview {
|
|
115
|
+
width: 100%;
|
|
116
|
+
min-width: 0;
|
|
117
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { presmiumService, PLAYBACK_CONTROL, runtimeRevision } from '@lincyaw/host'
|
|
2
|
+
import type { PlaybackControl } from '@lincyaw/host'
|
|
3
|
+
import { irBlocks, PREVIEW_REVISION, toBlockPreviewPlaybackGranted } from '@lincyaw/kernel'
|
|
4
|
+
import type { BlockPreviewPlaybackCancelled, BlockPreviewPlaybackRequest, IRDocument } from '@lincyaw/kernel'
|
|
5
|
+
import type { Viewer } from '@lincyaw/viewer'
|
|
6
|
+
import type { AppConfig } from '../domain/index.ts'
|
|
7
|
+
|
|
8
|
+
/** Authorise the existing player; this bridge owns no clock or content. */
|
|
9
|
+
export function blockPlaybackGate(config: AppConfig, doc: IRDocument, viewer: Viewer, origin: string | undefined, navigation: () => string | undefined, onGranted: (navigation: string) => void) {
|
|
10
|
+
const random = crypto.getRandomValues(new Uint32Array(2))
|
|
11
|
+
let sequence = (random[0]! & 0x000f_ffff) * 0x1_0000_0000 + random[1]!
|
|
12
|
+
const pending = new Map<number, (error?: Error, navigation?: string) => void>()
|
|
13
|
+
const active = new Map<number, () => void>()
|
|
14
|
+
let disposed = false, armed = false, control: PlaybackControl | undefined
|
|
15
|
+
let stopGate = () => {}, stopRuntime = () => {}
|
|
16
|
+
const revision = doc.meta[PREVIEW_REVISION]
|
|
17
|
+
const abortError = () => new DOMException('Playback cancelled', 'AbortError')
|
|
18
|
+
const cancelled = (request: number) => {
|
|
19
|
+
if (!origin || typeof revision !== 'string') return
|
|
20
|
+
const message: BlockPreviewPlaybackCancelled = { type: 'presmium:block-preview-playback-cancelled', document: config.document, blockId: config.block!, revision, request }
|
|
21
|
+
try { window.parent.postMessage(message, origin) } catch {}
|
|
22
|
+
}
|
|
23
|
+
const cancel = () => {
|
|
24
|
+
for (const finish of [...pending.values()]) finish(abortError())
|
|
25
|
+
for (const release of [...active.values()]) release()
|
|
26
|
+
}
|
|
27
|
+
const authorize = (signal: AbortSignal): Promise<void> => {
|
|
28
|
+
if (disposed || !origin || typeof revision !== 'string' || signal.aborted) return Promise.reject(abortError())
|
|
29
|
+
const position = viewer.position.getSnapshot(), section = viewer.section(position.section)
|
|
30
|
+
const stepId = section?.stepIds?.[position.step], selectedNavigation = navigation()
|
|
31
|
+
if (!section || !stepId || !selectedNavigation || ![...irBlocks(section.blocks)].some(block => block.id === config.block)) return Promise.reject(new Error('The selected preview step is unavailable.'))
|
|
32
|
+
const request = ++sequence
|
|
33
|
+
return new Promise<void>((resolve, reject) => {
|
|
34
|
+
let granted = false
|
|
35
|
+
const abort = () => { if (granted) active.get(request)?.(); else finish(abortError()) }
|
|
36
|
+
const finish = (error?: Error, acceptedNavigation?: string) => {
|
|
37
|
+
if (!pending.delete(request)) return
|
|
38
|
+
clearTimeout(timeout)
|
|
39
|
+
if (error) {
|
|
40
|
+
signal.removeEventListener('abort', abort)
|
|
41
|
+
cancelled(request)
|
|
42
|
+
reject(error)
|
|
43
|
+
} else {
|
|
44
|
+
granted = true
|
|
45
|
+
active.set(request, () => {
|
|
46
|
+
if (!active.delete(request)) return
|
|
47
|
+
signal.removeEventListener('abort', abort)
|
|
48
|
+
cancelled(request)
|
|
49
|
+
})
|
|
50
|
+
onGranted(acceptedNavigation!)
|
|
51
|
+
resolve()
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const timeout = setTimeout(() => finish(new Error('Playback authorization timed out.')), 15_000)
|
|
55
|
+
pending.set(request, finish)
|
|
56
|
+
signal.addEventListener('abort', abort, { once: true })
|
|
57
|
+
const message: BlockPreviewPlaybackRequest = { type: 'presmium:block-preview-playback-request', document: config.document, blockId: config.block!, revision, request, sectionId: section.id, stepId, navigation: selectedNavigation }
|
|
58
|
+
try { window.parent.postMessage(message, origin) } catch { finish(new Error('Playback authorization is unavailable.')) }
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
const attach = () => {
|
|
62
|
+
const next = presmiumService(PLAYBACK_CONTROL)
|
|
63
|
+
if (next === control) return
|
|
64
|
+
stopGate(); cancel(); control = next
|
|
65
|
+
stopGate = next?.setGate(authorize) ?? (() => {})
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
/** An authorised embedded surface always joins the parent's playback focus. */
|
|
69
|
+
enable() {
|
|
70
|
+
if (armed || disposed || !origin || window.parent === window) return
|
|
71
|
+
armed = true
|
|
72
|
+
attach()
|
|
73
|
+
stopRuntime = runtimeRevision.subscribe(attach)
|
|
74
|
+
},
|
|
75
|
+
grant(data: unknown) {
|
|
76
|
+
const value = toBlockPreviewPlaybackGranted(data)
|
|
77
|
+
if (!disposed && value?.document === config.document && value.blockId === config.block && value.revision === revision) pending.get(value.request)?.(value.error === undefined ? undefined : new Error(value.error || 'Playback authorization is unavailable.'), value.navigation)
|
|
78
|
+
},
|
|
79
|
+
dispose() { if (disposed) return; disposed = true; stopRuntime(); stopGate(); cancel() },
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { componentErrors, componentErrorRevision, presmiumService, PLAYBACK_CONTROL, STEP_CLOCK } from '@lincyaw/host'
|
|
2
|
+
import { deckLocale, irBlocks, PREVIEW_REVISION, toBlockPreviewCommand } from '@lincyaw/kernel'
|
|
3
|
+
import type { IRDocument } from '@lincyaw/kernel'
|
|
4
|
+
import type { Viewer } from '@lincyaw/viewer'
|
|
5
|
+
import { WEB_MESSAGES } from '../domain/index.ts'
|
|
6
|
+
import type { AppConfig } from '../domain/index.ts'
|
|
7
|
+
import { blockPlaybackGate } from './block-playback.ts'
|
|
8
|
+
|
|
9
|
+
/** A read-only widget reports snapshot status, geometry and discrete navigation to its authorised parent. */
|
|
10
|
+
export function blockPreviewReporter(config: AppConfig, doc: IRDocument, viewer: Viewer): { ready(): Promise<void>, failed(): void } {
|
|
11
|
+
let origin: string | undefined
|
|
12
|
+
try { const referrer = new URL(document.referrer).origin; if (config.origins.includes(referrer)) origin = referrer } catch {}
|
|
13
|
+
const root = document.getElementById('app')!
|
|
14
|
+
let localPosition = false
|
|
15
|
+
let navigation: string | undefined
|
|
16
|
+
const playback = blockPlaybackGate(config, doc, viewer, origin, () => navigation, accepted => { navigation = accepted; localPosition = true })
|
|
17
|
+
playback.enable()
|
|
18
|
+
let enabled = false, fatal = false, queued = false, disposed = false
|
|
19
|
+
let lastReport: string | undefined
|
|
20
|
+
let stopPosition: (() => void) | undefined
|
|
21
|
+
const failed = () => { fatal = true; send() }
|
|
22
|
+
const send = () => {
|
|
23
|
+
if (!enabled || !origin || window.parent === window || disposed) return
|
|
24
|
+
const unavailable = root.querySelector('[data-status="failed"], [data-status="missing"], .pm-component-missing')
|
|
25
|
+
const error = fatal || unavailable || componentErrors().length > 0
|
|
26
|
+
const loading = root.querySelector('.pm-client-only, [data-status="loading"]')
|
|
27
|
+
const revision = doc.meta[PREVIEW_REVISION], status = error ? 'failed' : loading ? 'loading' : 'ready'
|
|
28
|
+
const height = Math.ceil(root.querySelector('.pm-block-preview')?.getBoundingClientRect().height ?? root.scrollHeight)
|
|
29
|
+
const report = JSON.stringify([revision, status, height])
|
|
30
|
+
if (report === lastReport) return
|
|
31
|
+
lastReport = report
|
|
32
|
+
window.parent.postMessage({ type: 'presmium:block-preview', blockId: config.block, document: config.document, revision, status, height, ...error ? { message: WEB_MESSAGES[deckLocale(config.lang)].blockPreviewFailed } : {} }, origin)
|
|
33
|
+
}
|
|
34
|
+
const changed = () => { if (queued || disposed) return; queued = true; queueMicrotask(() => { queued = false; send() }) }
|
|
35
|
+
const resize = new ResizeObserver(changed)
|
|
36
|
+
const mutations = new MutationObserver(changed)
|
|
37
|
+
resize.observe(root)
|
|
38
|
+
mutations.observe(root, { subtree: true, childList: true, attributes: true, attributeFilter: ['data-status', 'class'] })
|
|
39
|
+
const stopErrors = componentErrorRevision.subscribe(changed)
|
|
40
|
+
const sendPosition = () => {
|
|
41
|
+
if (!enabled || !origin || disposed || fatal || !localPosition || !navigation || window.parent === window) return
|
|
42
|
+
const position = viewer.position.getSnapshot(), section = viewer.section(position.section)
|
|
43
|
+
if (!section || ![...irBlocks(section.blocks)].some(block => block.id === config.block)) return
|
|
44
|
+
const stepId = section.stepIds?.[position.step], revision = doc.meta[PREVIEW_REVISION]
|
|
45
|
+
if (typeof stepId !== 'string' || typeof revision !== 'string') return
|
|
46
|
+
window.parent.postMessage({ type: 'presmium:block-preview-position', document: config.document, blockId: config.block, revision, sectionId: section.id, stepId, navigation }, origin)
|
|
47
|
+
}
|
|
48
|
+
const command = (event: MessageEvent) => {
|
|
49
|
+
if (!enabled || disposed || fatal || !origin || event.source !== window.parent || event.origin !== origin) return
|
|
50
|
+
playback.grant(event.data)
|
|
51
|
+
const value = toBlockPreviewCommand(event.data), revision = doc.meta[PREVIEW_REVISION]
|
|
52
|
+
if (!value || value.type !== 'presmium:block-preview-command' || value.document !== config.document || value.blockId !== config.block || typeof revision !== 'string' || value.revision !== revision) return
|
|
53
|
+
// A draft may name a step not in this older snapshot yet; its author can
|
|
54
|
+
// still pause this exact frame without adopting that target.
|
|
55
|
+
if (value.action === 'pause') {
|
|
56
|
+
localPosition = false
|
|
57
|
+
if (value.navigation) navigation = value.navigation
|
|
58
|
+
playback.enable()
|
|
59
|
+
presmiumService(PLAYBACK_CONTROL)?.pause()
|
|
60
|
+
const section = viewer.section(value.sectionId), step = section?.stepIds?.indexOf(value.stepId) ?? -1
|
|
61
|
+
const current = viewer.position.getSnapshot()
|
|
62
|
+
if (value.navigation && section && step >= 0 && [...irBlocks(section.blocks)].some(block => block.id === config.block)
|
|
63
|
+
&& (current.section !== section.id || current.step !== step)) viewer.show({ section: section.id, step, boundary: 'end' })
|
|
64
|
+
return
|
|
65
|
+
}
|
|
66
|
+
const section = viewer.section(value.sectionId), step = section?.stepIds?.indexOf(value.stepId) ?? -1
|
|
67
|
+
if (!section || step < 0 || ![...irBlocks(section.blocks)].some(block => block.id === config.block)) return
|
|
68
|
+
navigation = value.navigation
|
|
69
|
+
// Acknowledging this frame's accepted position must not seek its active clock.
|
|
70
|
+
if (value.action === 'sync') {
|
|
71
|
+
const current = viewer.position.getSnapshot()
|
|
72
|
+
// Local input may have advanced again while this acknowledgement was in
|
|
73
|
+
// transit. Re-publish that actual cursor under the accepted generation.
|
|
74
|
+
if (current.section !== section.id || current.step !== step) sendPosition()
|
|
75
|
+
return
|
|
76
|
+
}
|
|
77
|
+
// An externally selected step may cause intermediate local React navigation.
|
|
78
|
+
// Only a new local author action or granted clock can publish a new target.
|
|
79
|
+
localPosition = false
|
|
80
|
+
playback.enable()
|
|
81
|
+
presmiumService(PLAYBACK_CONTROL)?.pause()
|
|
82
|
+
viewer.show({ section: section.id, step, boundary: value.at ?? 'end' })
|
|
83
|
+
}
|
|
84
|
+
const localIntent = (event: Event) => { if (event.isTrusted) localPosition = true }
|
|
85
|
+
document.addEventListener('pointerdown', localIntent, true)
|
|
86
|
+
document.addEventListener('keydown', localIntent, true)
|
|
87
|
+
window.addEventListener('message', command)
|
|
88
|
+
window.addEventListener('error', failed)
|
|
89
|
+
window.addEventListener('unhandledrejection', failed)
|
|
90
|
+
window.addEventListener('pagehide', () => { disposed = true; playback.dispose(); resize.disconnect(); mutations.disconnect(); stopErrors(); stopPosition?.(); document.removeEventListener('pointerdown', localIntent, true); document.removeEventListener('keydown', localIntent, true); window.removeEventListener('message', command); window.removeEventListener('error', failed); window.removeEventListener('unhandledrejection', failed) }, { once: true })
|
|
91
|
+
return {
|
|
92
|
+
async ready() {
|
|
93
|
+
await new Promise<void>(done => requestAnimationFrame(() => requestAnimationFrame(() => done())))
|
|
94
|
+
await presmiumService(STEP_CLOCK)?.settled()
|
|
95
|
+
if (disposed) return
|
|
96
|
+
enabled = true
|
|
97
|
+
send()
|
|
98
|
+
// The initial viewer position is only a loading default. Publish subsequent
|
|
99
|
+
// navigation, using the canonical step identity of this block's section.
|
|
100
|
+
stopPosition ??= viewer.position.subscribe(sendPosition)
|
|
101
|
+
},
|
|
102
|
+
failed() { enabled = true; failed() },
|
|
103
|
+
}
|
|
104
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The modules of the document's own bundle that stand for plugins' document modules (`PresmiumNodePlugin.documentModules`):
|
|
3
|
+
* the viewer app is built once for all documents, so a plugin's import of such a module gets a proxy here, which reads
|
|
4
|
+
* the default export the current document's bundle gave.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const current = new Map<string, unknown>()
|
|
8
|
+
|
|
9
|
+
export function setDocumentModules(modules: Record<string, unknown>): void {
|
|
10
|
+
current.clear()
|
|
11
|
+
for (const [id, value] of Object.entries(modules)) current.set(id, value)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const target = (id: string): object => {
|
|
15
|
+
const value = current.get(id)
|
|
16
|
+
return value !== null && typeof value === 'object' ? value : {}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** The default export of document module `id`, as the current document gives it (an object: its keys are read when used). */
|
|
20
|
+
export function documentModule(id: string): unknown {
|
|
21
|
+
return new Proxy({}, {
|
|
22
|
+
get: (_, key) => Reflect.get(target(id), key),
|
|
23
|
+
has: (_, key) => Reflect.has(target(id), key),
|
|
24
|
+
ownKeys: () => Reflect.ownKeys(target(id)),
|
|
25
|
+
getOwnPropertyDescriptor: (_, key) => {
|
|
26
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(target(id), key)
|
|
27
|
+
return descriptor && { ...descriptor, configurable: true }
|
|
28
|
+
},
|
|
29
|
+
})
|
|
30
|
+
}
|