@open-artifact/slides-core 0.0.0-stage → 0.2.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.
- package/LICENSE +202 -0
- package/NOTICE +5 -0
- package/README.md +5 -2
- package/package.json +36 -4
- package/src/check.d.ts +36 -0
- package/src/check.js +120 -0
- package/src/compile.d.ts +61 -0
- package/src/compile.js +1430 -0
- package/src/css/color.d.ts +37 -0
- package/src/css/color.js +219 -0
- package/src/css/properties.d.ts +87 -0
- package/src/css/properties.js +1045 -0
- package/src/css/selectors.d.ts +84 -0
- package/src/css/selectors.js +336 -0
- package/src/css/sheet.d.ts +68 -0
- package/src/css/sheet.js +282 -0
- package/src/css/values.d.ts +219 -0
- package/src/css/values.js +787 -0
- package/src/deck.d.ts +141 -0
- package/src/deck.js +384 -0
- package/src/edit.d.ts +176 -0
- package/src/edit.js +774 -0
- package/src/icons.d.ts +9 -0
- package/src/icons.js +14 -0
- package/src/ids.d.ts +98 -0
- package/src/ids.js +390 -0
- package/src/index.d.ts +26 -0
- package/src/index.js +26 -0
- package/src/limits.d.ts +157 -0
- package/src/limits.js +137 -0
- package/src/model.d.ts +304 -0
- package/src/model.js +104 -0
- package/src/sections.d.ts +80 -0
- package/src/sections.js +441 -0
- package/src/serialize.d.ts +25 -0
- package/src/serialize.js +302 -0
- package/src/source.d.ts +122 -0
- package/src/source.js +1513 -0
- package/src/templates.d.ts +42 -0
- package/src/templates.js +161 -0
- package/src/text.d.ts +37 -0
- package/src/text.js +163 -0
- package/src/video.d.ts +36 -0
- package/src/video.js +193 -0
- package/src/view-context.d.ts +92 -0
- package/src/view-context.js +156 -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/NOTICE
ADDED
package/README.md
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @open-artifact/slides-core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The Slides artifact model: the slide HTML subset, its compiler and serializer, deck.json, merging, view context and project checks.
|
|
4
|
+
|
|
5
|
+
Part of [Open Artifact](https://github.com/JimLiu/open-artifact): slide decks, design canvases and whiteboards an agent makes
|
|
6
|
+
and you view, edit and comment on in one local page. Source: [`packages/slides-core`](https://github.com/JimLiu/open-artifact/tree/main/packages/slides-core).
|
package/package.json
CHANGED
|
@@ -1,6 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-artifact/slides-core",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "The Slides artifact model: the slide HTML subset, its compiler and serializer, deck.json, merging, view context and project checks.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./src/index.d.ts",
|
|
9
|
+
"default": "./src/index.js"
|
|
10
|
+
},
|
|
11
|
+
"./package.json": "./package.json"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"src",
|
|
15
|
+
"LICENSE",
|
|
16
|
+
"NOTICE"
|
|
17
|
+
],
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@open-artifact/dc": "0.2.0"
|
|
20
|
+
},
|
|
21
|
+
"license": "Apache-2.0",
|
|
22
|
+
"author": {
|
|
23
|
+
"name": "Jim Liu 宝玉",
|
|
24
|
+
"url": "https://github.com/JimLiu"
|
|
25
|
+
},
|
|
26
|
+
"homepage": "https://github.com/JimLiu/open-artifact#readme",
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "git+https://github.com/JimLiu/open-artifact.git",
|
|
30
|
+
"directory": "packages/slides-core"
|
|
31
|
+
},
|
|
32
|
+
"bugs": {
|
|
33
|
+
"url": "https://github.com/JimLiu/open-artifact/issues"
|
|
34
|
+
},
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
}
|
|
38
|
+
}
|
package/src/check.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whole-project checks of a Slides artifact: `deck.json` against the slide
|
|
3
|
+
* files, then every slide file through the compiler. Paths are relative to
|
|
4
|
+
* `project/` (the shape the type server hands over).
|
|
5
|
+
*/
|
|
6
|
+
/** Severity of a project finding (the type server's scale). */
|
|
7
|
+
export type ProjectLevel = 'error' | 'warning' | 'info';
|
|
8
|
+
/** A finding tied to a file under `project/`. */
|
|
9
|
+
export interface ProjectDiagnostic {
|
|
10
|
+
/** Path under `project/`. */
|
|
11
|
+
file: string;
|
|
12
|
+
level: ProjectLevel;
|
|
13
|
+
message: string;
|
|
14
|
+
line?: number;
|
|
15
|
+
}
|
|
16
|
+
/** Options of {@link checkSlidesProject}. */
|
|
17
|
+
export interface CheckOptions {
|
|
18
|
+
/**
|
|
19
|
+
* Whether a referenced binary file exists (`/_blob/<id>` or a path under
|
|
20
|
+
* `project/`). Text files are already in the map; without this callback
|
|
21
|
+
* binary references are not checked.
|
|
22
|
+
*/
|
|
23
|
+
exists?: (ref: string) => boolean;
|
|
24
|
+
/** Report layout lints (contrast, overlap, …) as info. Default true. */
|
|
25
|
+
lints?: boolean;
|
|
26
|
+
}
|
|
27
|
+
/** The index file, relative to `project/`. */
|
|
28
|
+
export declare const DECK_FILE = "deck.json";
|
|
29
|
+
/** A source deck's shared stylesheet, relative to `project/`. */
|
|
30
|
+
export declare const DECK_CSS_FILE = "deck.css";
|
|
31
|
+
/** The slides folder, relative to `project/`. */
|
|
32
|
+
export declare const SLIDES_FOLDER = "slides/";
|
|
33
|
+
/** The slide id of a path under `project/`, or undefined. */
|
|
34
|
+
export declare function slideIdOfFile(path: string): string | undefined;
|
|
35
|
+
/** Checks a project given all of its text files (path under `project/` → content). */
|
|
36
|
+
export declare function checkSlidesProject(files: ReadonlyMap<string, string>, options?: CheckOptions): ProjectDiagnostic[];
|
package/src/check.js
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whole-project checks of a Slides artifact: `deck.json` against the slide
|
|
3
|
+
* files, then every slide file through the compiler. Paths are relative to
|
|
4
|
+
* `project/` (the shape the type server hands over).
|
|
5
|
+
*/
|
|
6
|
+
import { compileSlide } from "./compile.js";
|
|
7
|
+
import { checkDeckIndex, parseDeckIndex, resolveOrder } from "./deck.js";
|
|
8
|
+
import { ID_PATTERN, LIMITS, setSlideSize } from "./limits.js";
|
|
9
|
+
import { createSourceDeck, deckFormatKind, isFlatSlideHtml, NEEDS_FORMAT_KEY, readSourceSlide, slideMarkupMadeFor } from "./source.js";
|
|
10
|
+
/** The index file, relative to `project/`. */
|
|
11
|
+
export const DECK_FILE = 'deck.json';
|
|
12
|
+
/** A source deck's shared stylesheet, relative to `project/`. */
|
|
13
|
+
export const DECK_CSS_FILE = 'deck.css';
|
|
14
|
+
/** The slides folder, relative to `project/`. */
|
|
15
|
+
export const SLIDES_FOLDER = 'slides/';
|
|
16
|
+
/** The slide id of a path under `project/`, or undefined. */
|
|
17
|
+
export function slideIdOfFile(path) {
|
|
18
|
+
if (!path.startsWith(SLIDES_FOLDER) || !path.endsWith('.html'))
|
|
19
|
+
return undefined;
|
|
20
|
+
const id = path.slice(SLIDES_FOLDER.length, -5);
|
|
21
|
+
return ID_PATTERN.test(id) && !id.includes('/') ? id : undefined;
|
|
22
|
+
}
|
|
23
|
+
/** Maps a compiler level onto the project scale. */
|
|
24
|
+
function projectLevel(level) {
|
|
25
|
+
return level === 'error' ? 'error' : level === 'warning' ? 'warning' : 'info';
|
|
26
|
+
}
|
|
27
|
+
/** Checks a project given all of its text files (path under `project/` → content). */
|
|
28
|
+
export function checkSlidesProject(files, options = {}) {
|
|
29
|
+
const out = [];
|
|
30
|
+
const add = (file, level, message, line) => {
|
|
31
|
+
out.push(line === undefined ? { file, level, message } : { file, level, message, line });
|
|
32
|
+
};
|
|
33
|
+
// Slide files: the folder is the source of truth for which slides exist.
|
|
34
|
+
const slideIds = new Set();
|
|
35
|
+
for (const path of files.keys()) {
|
|
36
|
+
if (!path.startsWith(SLIDES_FOLDER))
|
|
37
|
+
continue;
|
|
38
|
+
const id = slideIdOfFile(path);
|
|
39
|
+
if (id)
|
|
40
|
+
slideIds.add(id);
|
|
41
|
+
else if (path.endsWith('.html'))
|
|
42
|
+
add(path, 'warning', `${path} is not a slide: a slide file is slides/<id>.html with an id of 1–64 letters, digits, _ or -`);
|
|
43
|
+
}
|
|
44
|
+
// The index.
|
|
45
|
+
const deckText = files.get(DECK_FILE);
|
|
46
|
+
let index;
|
|
47
|
+
if (deckText === undefined) {
|
|
48
|
+
add(DECK_FILE, 'error', 'project/deck.json is missing.');
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
const parsed = parseDeckIndex(deckText);
|
|
52
|
+
if (parsed.error)
|
|
53
|
+
add(DECK_FILE, 'error', parsed.error);
|
|
54
|
+
else
|
|
55
|
+
index = parsed.index;
|
|
56
|
+
}
|
|
57
|
+
if (index) {
|
|
58
|
+
for (const problem of checkDeckIndex(index, slideIds)) {
|
|
59
|
+
add(DECK_FILE, problem.level === 'note' ? 'info' : problem.level, problem.message.replace(/^project\/deck\.json: /, ''));
|
|
60
|
+
}
|
|
61
|
+
for (const face of Object.values(index.faces)) {
|
|
62
|
+
if (face.src !== undefined && options.exists && !options.exists(face.src))
|
|
63
|
+
add(DECK_FILE, 'warning', `face "${face.family}" src ${face.src} does not exist`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
// A source deck reads its slides against project/deck.css, at the deck's size.
|
|
67
|
+
setSlideSize(index?.size);
|
|
68
|
+
let deck;
|
|
69
|
+
if (index && deckFormatKind(index) === 'source') {
|
|
70
|
+
const css = files.get(DECK_CSS_FILE);
|
|
71
|
+
if (css === undefined)
|
|
72
|
+
add(DECK_FILE, 'error', 'deck.json has a "format" key but project/deck.css is missing: send it with the index.');
|
|
73
|
+
deck = createSourceDeck(css, index.size);
|
|
74
|
+
for (const drop of deck.sheet.drops)
|
|
75
|
+
add(DECK_CSS_FILE, 'warning', drop.what, drop.line);
|
|
76
|
+
}
|
|
77
|
+
else if (files.has(DECK_CSS_FILE)) {
|
|
78
|
+
add(DECK_CSS_FILE, 'info', 'project/deck.css does nothing in a deck without a "format" key.');
|
|
79
|
+
}
|
|
80
|
+
const places = new Map((index ? resolveOrder(index.order, slideIds) : [...slideIds].sort()).map((id, i) => [id, i]));
|
|
81
|
+
// Every slide.
|
|
82
|
+
const faces = index ? Object.values(index.faces).map((face) => face.family) : [];
|
|
83
|
+
let cells = 0;
|
|
84
|
+
const lints = options.lints ?? true;
|
|
85
|
+
for (const id of [...slideIds].sort()) {
|
|
86
|
+
const file = `${SLIDES_FOLDER}${id}.html`;
|
|
87
|
+
const source = files.get(file) ?? '';
|
|
88
|
+
const bytes = new TextEncoder().encode(source).length;
|
|
89
|
+
if (bytes > LIMITS.slideFileBytes) {
|
|
90
|
+
add(file, 'error', `${Math.round(bytes / 1024)} KB — a slide file is at most ${LIMITS.slideFileBytes / 1024} KB`);
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
const sourceSlide = deck !== undefined && !isFlatSlideHtml(source);
|
|
94
|
+
const result = sourceSlide
|
|
95
|
+
? readSourceSlide(source, deck, { id, faces, lints, index: places.get(id) ?? 0 })
|
|
96
|
+
: compileSlide(source, { id, faces, lints });
|
|
97
|
+
if (!deck && index && slideMarkupMadeFor(source) === 'sheet')
|
|
98
|
+
add(file, 'warning', NEEDS_FORMAT_KEY);
|
|
99
|
+
for (const diagnostic of result.diagnostics) {
|
|
100
|
+
if (diagnostic.level === 'lint' && !lints)
|
|
101
|
+
continue;
|
|
102
|
+
add(file, projectLevel(diagnostic.level), diagnostic.message, diagnostic.line);
|
|
103
|
+
}
|
|
104
|
+
if (result.slide.section !== undefined && index) {
|
|
105
|
+
add(file, 'info', `data-section on slide "${id}" is moved into deck.json "sections" on the next open`);
|
|
106
|
+
}
|
|
107
|
+
if (options.exists) {
|
|
108
|
+
for (const ref of result.assets) {
|
|
109
|
+
if (!options.exists(ref))
|
|
110
|
+
add(file, 'warning', `slide "${id}" references ${ref}, which does not exist`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
cells += result.cells;
|
|
114
|
+
}
|
|
115
|
+
if (cells > LIMITS.deckCells)
|
|
116
|
+
add(DECK_FILE, 'error', `${cells} table cells across the deck — at most ${LIMITS.deckCells}`);
|
|
117
|
+
if (slideIds.size === 0 && index)
|
|
118
|
+
add(DECK_FILE, 'info', 'The deck has no slides yet: write project/slides/<id>.html.');
|
|
119
|
+
return out;
|
|
120
|
+
}
|
package/src/compile.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Slide HTML → slide model.
|
|
3
|
+
*
|
|
4
|
+
* The compiler reads one slide file (exactly one `<section>`) and reports what
|
|
5
|
+
* it found at four levels, the contract that lets an agent write the format
|
|
6
|
+
* and the editor keep it:
|
|
7
|
+
*
|
|
8
|
+
* - `error` structure the editor cannot represent (unknown tag, over a
|
|
9
|
+
* limit, malformed markup). The slide is *held*: shown as far
|
|
10
|
+
* as it could be read, never edited or re-saved.
|
|
11
|
+
* - `warning` a repair that changes what is seen (a negative offset
|
|
12
|
+
* clamped, an undeclared font dropped).
|
|
13
|
+
* - `note` an equivalent rewrite (`pt` → `px`, `class` ignored).
|
|
14
|
+
* - `unsupported` a declaration or attribute outside the subset, dropped.
|
|
15
|
+
* - `lint` a layout estimate worth a look (never blocking).
|
|
16
|
+
*/
|
|
17
|
+
import { type Slide } from './model.ts';
|
|
18
|
+
/** Severity of a diagnostic. */
|
|
19
|
+
export type DiagnosticLevel = 'error' | 'warning' | 'note' | 'unsupported' | 'lint';
|
|
20
|
+
/** One finding of the compiler. */
|
|
21
|
+
export interface Diagnostic {
|
|
22
|
+
level: DiagnosticLevel;
|
|
23
|
+
message: string;
|
|
24
|
+
/** 1-based line of the element it is about. */
|
|
25
|
+
line?: number;
|
|
26
|
+
/** 1-based column. */
|
|
27
|
+
column?: number;
|
|
28
|
+
}
|
|
29
|
+
/** Options of {@link compileSlide}. */
|
|
30
|
+
export interface CompileOptions {
|
|
31
|
+
/** The slide id the file name implies; the section's `id` must equal it. */
|
|
32
|
+
id?: string;
|
|
33
|
+
/** Families the deck declares (deck.json `faces`); others heal away. */
|
|
34
|
+
faces?: Iterable<string>;
|
|
35
|
+
/** Skip layout lints (the editor compiles often and shows none). */
|
|
36
|
+
lints?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* The file is a source slide as `readSourceSlide` worked it out: keep each
|
|
39
|
+
* element's `data-open-artifact-src` place on its node (`NodeBase.origin`), take
|
|
40
|
+
* `margin`, and say nothing of the attributes the reader leaves behind.
|
|
41
|
+
*/
|
|
42
|
+
source?: boolean;
|
|
43
|
+
}
|
|
44
|
+
/** What {@link compileSlide} returns. */
|
|
45
|
+
export interface CompileResult {
|
|
46
|
+
/** The slide as far as it could be read (always present). */
|
|
47
|
+
slide: Slide;
|
|
48
|
+
/** True when an error holds the slide read-only. */
|
|
49
|
+
held: boolean;
|
|
50
|
+
diagnostics: Diagnostic[];
|
|
51
|
+
/** Every `/_blob/<id>` and `project/ds/…` path the slide references. */
|
|
52
|
+
assets: string[];
|
|
53
|
+
/** Table cells on the slide (the deck limit adds these up). */
|
|
54
|
+
cells: number;
|
|
55
|
+
}
|
|
56
|
+
/** Reads `Npx` back to a number. */
|
|
57
|
+
export declare function readPx(value: string | undefined): number | undefined;
|
|
58
|
+
/** Compiles one slide file. */
|
|
59
|
+
export declare function compileSlide(source: string, options?: CompileOptions): CompileResult;
|
|
60
|
+
/** The first error, stripped of markup characters, for `slideHeldWhy` (≈ 60 chars). */
|
|
61
|
+
export declare function heldReason(diagnostics: readonly Diagnostic[]): string | undefined;
|