manim-web 0.3.24 → 0.11.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/README.md +5 -1
- package/dist/GLTFLoader-CisHz7tR.js +1381 -0
- package/dist/GLTFLoader-DMbWuMln.js +1381 -0
- package/dist/{MathJaxBundle-xSidSV0E.js → MathJaxBundle-BSrlS0Dh.js} +3338 -3320
- package/dist/OBJLoader-Clh2POv9.js +287 -0
- package/dist/OBJLoader-kkTsEhJf.js +287 -0
- package/dist/animation/Always.d.ts +72 -0
- package/dist/animation/Always.d.ts.map +1 -0
- package/dist/animation/AlwaysRedraw.d.ts +15 -0
- package/dist/animation/AlwaysRedraw.d.ts.map +1 -0
- package/dist/animation/Animation.d.ts +9 -0
- package/dist/animation/Animation.d.ts.map +1 -1
- package/dist/animation/AnimationUtilities.d.ts +25 -0
- package/dist/animation/AnimationUtilities.d.ts.map +1 -1
- package/dist/animation/creation/Create.d.ts +40 -11
- package/dist/animation/creation/Create.d.ts.map +1 -1
- package/dist/animation/transform/PointMorphStrategy.d.ts +6 -0
- package/dist/animation/transform/PointMorphStrategy.d.ts.map +1 -1
- package/dist/animation/transform/Transform.d.ts.map +1 -1
- package/dist/animation/transform/TransformPairing.d.ts +17 -0
- package/dist/animation/transform/TransformPairing.d.ts.map +1 -1
- package/dist/animation/updaters.d.ts +69 -0
- package/dist/animation/updaters.d.ts.map +1 -0
- package/dist/compiler-CfW6eH2M.js +2 -0
- package/dist/constants/index.d.ts +1 -0
- package/dist/constants/index.d.ts.map +1 -1
- package/dist/constants/parity.d.ts +78 -0
- package/dist/constants/parity.d.ts.map +1 -0
- package/dist/core/Mobject.d.ts +48 -3
- package/dist/core/Mobject.d.ts.map +1 -1
- package/dist/core/MobjectTraversal.d.ts +7 -0
- package/dist/core/MobjectTraversal.d.ts.map +1 -1
- package/dist/core/MobjectTypes.d.ts +15 -0
- package/dist/core/MobjectTypes.d.ts.map +1 -1
- package/dist/core/Scene.d.ts +14 -0
- package/dist/core/Scene.d.ts.map +1 -1
- package/dist/core/SpecialThreeDScene.d.ts +64 -0
- package/dist/core/SpecialThreeDScene.d.ts.map +1 -0
- package/dist/core/VMobject.d.ts +143 -0
- package/dist/core/VMobject.d.ts.map +1 -1
- package/dist/core/VMobjectColorGradient.d.ts +20 -0
- package/dist/core/VMobjectColorGradient.d.ts.map +1 -0
- package/dist/core/VMobjectCurveMath.d.ts +128 -0
- package/dist/core/VMobjectCurveMath.d.ts.map +1 -0
- package/dist/core/VMobjectRendering.d.ts +38 -1
- package/dist/core/VMobjectRendering.d.ts.map +1 -1
- package/dist/core/VMobjectRoundCorners.d.ts +37 -0
- package/dist/core/VMobjectRoundCorners.d.ts.map +1 -0
- package/dist/esm-CiMKSfxz.js +1273 -0
- package/dist/export/FrameExporter.d.ts +86 -0
- package/dist/export/FrameExporter.d.ts.map +1 -0
- package/dist/export/GifExporter.d.ts +4 -0
- package/dist/export/GifExporter.d.ts.map +1 -1
- package/dist/export/WebCodecsExporter.d.ts +108 -0
- package/dist/export/WebCodecsExporter.d.ts.map +1 -0
- package/dist/export/index.d.ts +2 -0
- package/dist/export/index.d.ts.map +1 -1
- package/dist/global-compiler-D_nF-JaV.js +8 -0
- package/dist/global-renderer-gyshX_QF.js +8 -0
- package/dist/index.d.ts +29 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/integrations/react.js +17 -16
- package/dist/integrations/vue.js +16 -15
- package/dist/integrations/webcomponent.d.ts +65 -0
- package/dist/integrations/webcomponent.d.ts.map +1 -0
- package/dist/integrations/webcomponent.js +2 -0
- package/dist/manim-web.browser.js +36877 -45066
- package/dist/mobjects/geometry/AngleShapes.d.ts.map +1 -1
- package/dist/mobjects/geometry/ArcPolygon.d.ts +30 -0
- package/dist/mobjects/geometry/ArcPolygon.d.ts.map +1 -1
- package/dist/mobjects/geometry/DashedLine.d.ts.map +1 -1
- package/dist/mobjects/geometry/Label.d.ts +32 -0
- package/dist/mobjects/geometry/Label.d.ts.map +1 -0
- package/dist/mobjects/geometry/index.d.ts +2 -1
- package/dist/mobjects/geometry/index.d.ts.map +1 -1
- package/dist/mobjects/graphing/Axes.d.ts +73 -6
- package/dist/mobjects/graphing/Axes.d.ts.map +1 -1
- package/dist/mobjects/graphing/CoordinateSystem.d.ts +40 -0
- package/dist/mobjects/graphing/CoordinateSystem.d.ts.map +1 -0
- package/dist/mobjects/graphing/axes-calculus.d.ts +79 -0
- package/dist/mobjects/graphing/axes-calculus.d.ts.map +1 -0
- package/dist/mobjects/graphing/index.d.ts +3 -0
- package/dist/mobjects/graphing/index.d.ts.map +1 -1
- package/dist/mobjects/graphing/scale.d.ts +72 -0
- package/dist/mobjects/graphing/scale.d.ts.map +1 -0
- package/dist/mobjects/text/MathJaxRenderer.d.ts +5 -0
- package/dist/mobjects/text/MathJaxRenderer.d.ts.map +1 -1
- package/dist/mobjects/text/MathTex.d.ts +23 -0
- package/dist/mobjects/text/MathTex.d.ts.map +1 -1
- package/dist/mobjects/text/MathTexImage.d.ts.map +1 -1
- package/dist/mobjects/text/Text.d.ts +53 -0
- package/dist/mobjects/text/Text.d.ts.map +1 -1
- package/dist/mobjects/text/Typst.d.ts +113 -0
- package/dist/mobjects/text/Typst.d.ts.map +1 -0
- package/dist/mobjects/text/TypstRenderer.d.ts +57 -0
- package/dist/mobjects/text/TypstRenderer.d.ts.map +1 -0
- package/dist/mobjects/text/index.d.ts +5 -2
- package/dist/mobjects/text/index.d.ts.map +1 -1
- package/dist/mobjects/text/katexStyles.d.ts +5 -0
- package/dist/mobjects/text/katexStyles.d.ts.map +1 -1
- package/dist/mobjects/text/registerFont.d.ts +38 -0
- package/dist/mobjects/text/registerFont.d.ts.map +1 -0
- package/dist/mobjects/text/textStyleRuns.d.ts +111 -0
- package/dist/mobjects/text/textStyleRuns.d.ts.map +1 -0
- package/dist/mobjects/three-d/ModelMobject.d.ts +122 -0
- package/dist/mobjects/three-d/ModelMobject.d.ts.map +1 -0
- package/dist/mobjects/three-d/ThreeDAxes.d.ts +37 -4
- package/dist/mobjects/three-d/ThreeDAxes.d.ts.map +1 -1
- package/dist/mobjects/three-d/threeDVmobUtils.d.ts +25 -0
- package/dist/mobjects/three-d/threeDVmobUtils.d.ts.map +1 -0
- package/dist/mobjects/video/VideoMobject.d.ts +126 -0
- package/dist/mobjects/video/VideoMobject.d.ts.map +1 -0
- package/dist/mobjects/video/index.d.ts +2 -0
- package/dist/mobjects/video/index.d.ts.map +1 -0
- package/dist/mp4-muxer-5DGKGEJk.js +900 -0
- package/dist/player/Player.d.ts +4 -0
- package/dist/player/Player.d.ts.map +1 -1
- package/dist/renderer-DR_79fB0.js +2 -0
- package/dist/{src-Cc3xTIkV.js → src-C817VR8M.js} +10693 -7971
- package/dist/three.core-1aHSpGwp.js +11626 -0
- package/dist/utils/ManimColor.d.ts +163 -0
- package/dist/utils/ManimColor.d.ts.map +1 -0
- package/dist/utils/bezier.d.ts +95 -0
- package/dist/utils/bezier.d.ts.map +1 -0
- package/dist/utils/color.d.ts +99 -0
- package/dist/utils/color.d.ts.map +1 -0
- package/dist/utils/debug.d.ts +36 -0
- package/dist/utils/debug.d.ts.map +1 -0
- package/dist/utils/iterables.d.ts +162 -0
- package/dist/utils/iterables.d.ts.map +1 -0
- package/dist/utils/paths.d.ts +38 -0
- package/dist/utils/paths.d.ts.map +1 -0
- package/dist/utils/simpleFunctions.d.ts +26 -0
- package/dist/utils/simpleFunctions.d.ts.map +1 -0
- package/dist/utils/spaceOps.d.ts +119 -0
- package/dist/utils/spaceOps.d.ts.map +1 -0
- package/dist/utils/unit.d.ts +28 -0
- package/dist/utils/unit.d.ts.map +1 -0
- package/dist/wasm-CIlzm7By.js +76 -0
- package/dist/wasm-pack-shim-B3C4KoWa.js +1688 -0
- package/dist/wasm-pack-shim-BgTFpSvJ.js +911 -0
- package/dist/webcomponent-BS5WnkDO.js +707 -0
- package/dist/webm-muxer-BGY-Mgbp.js +857 -0
- package/package.json +19 -8
|
@@ -0,0 +1,1273 @@
|
|
|
1
|
+
import { a as e, i as t, n, r, t as i } from "./wasm-CIlzm7By.js";
|
|
2
|
+
//#region node_modules/@myriaddreamin/typst.ts/dist/esm/options.init.mjs
|
|
3
|
+
var a = [
|
|
4
|
+
"DejaVuSansMono-Bold.ttf",
|
|
5
|
+
"DejaVuSansMono-BoldOblique.ttf",
|
|
6
|
+
"DejaVuSansMono-Oblique.ttf",
|
|
7
|
+
"DejaVuSansMono.ttf",
|
|
8
|
+
"LibertinusSerif-Bold.otf",
|
|
9
|
+
"LibertinusSerif-BoldItalic.otf",
|
|
10
|
+
"LibertinusSerif-Italic.otf",
|
|
11
|
+
"LibertinusSerif-Regular.otf",
|
|
12
|
+
"LibertinusSerif-Semibold.otf",
|
|
13
|
+
"LibertinusSerif-SemiboldItalic.otf",
|
|
14
|
+
"NewCM10-Bold.otf",
|
|
15
|
+
"NewCM10-BoldItalic.otf",
|
|
16
|
+
"NewCM10-Italic.otf",
|
|
17
|
+
"NewCM10-Regular.otf",
|
|
18
|
+
"NewCMMath-Bold.otf",
|
|
19
|
+
"NewCMMath-Book.otf",
|
|
20
|
+
"NewCMMath-Regular.otf"
|
|
21
|
+
], o = [
|
|
22
|
+
"InriaSerif-Bold.ttf",
|
|
23
|
+
"InriaSerif-BoldItalic.ttf",
|
|
24
|
+
"InriaSerif-Italic.ttf",
|
|
25
|
+
"InriaSerif-Regular.ttf",
|
|
26
|
+
"Roboto-Regular.ttf",
|
|
27
|
+
"NotoSerifCJKsc-Regular.otf"
|
|
28
|
+
], s = ["TwitterColorEmoji.ttf", "NotoColorEmoji-Regular-COLR.subset.ttf"];
|
|
29
|
+
function c() {
|
|
30
|
+
return d([], { assets: !1 });
|
|
31
|
+
}
|
|
32
|
+
function l(e) {
|
|
33
|
+
return d([], e);
|
|
34
|
+
}
|
|
35
|
+
function u(e) {
|
|
36
|
+
let t = [];
|
|
37
|
+
if (e && e?.assets !== !1 && e?.assets?.length && e?.assets?.length > 0) {
|
|
38
|
+
let n = {
|
|
39
|
+
text: "https://cdn.jsdelivr.net/gh/typst/typst-assets@v0.13.1/files/fonts/",
|
|
40
|
+
_: "https://cdn.jsdelivr.net/gh/typst/typst-dev-assets@v0.13.1/files/fonts/"
|
|
41
|
+
}, r = e.assetUrlPrefix ?? n;
|
|
42
|
+
r = typeof r == "string" ? { _: r } : {
|
|
43
|
+
...n,
|
|
44
|
+
...r
|
|
45
|
+
};
|
|
46
|
+
for (let e of Object.keys(r)) {
|
|
47
|
+
let t = r[e];
|
|
48
|
+
t[t.length - 1] !== "/" && (r[e] = t + "/");
|
|
49
|
+
}
|
|
50
|
+
let i = (e, t) => t.map((t) => (r[e] || r._) + t);
|
|
51
|
+
for (let n of e.assets) switch (n) {
|
|
52
|
+
case "text":
|
|
53
|
+
t.push(...i(n, a));
|
|
54
|
+
break;
|
|
55
|
+
case "cjk":
|
|
56
|
+
t.push(...i(n, o));
|
|
57
|
+
break;
|
|
58
|
+
case "emoji":
|
|
59
|
+
t.push(...i(n, s));
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return t;
|
|
64
|
+
}
|
|
65
|
+
function d(e, t) {
|
|
66
|
+
let n = u(t), r = async (r, { ref: i, builder: a }) => {
|
|
67
|
+
t?.fetcher && i.setFetcher(t.fetcher), await i.loadFonts(a, [...e, ...n]);
|
|
68
|
+
};
|
|
69
|
+
return r._preloadRemoteFontOptions = t, r._kind = "fontLoader", r;
|
|
70
|
+
}
|
|
71
|
+
function f(e) {
|
|
72
|
+
return async (t, { builder: n }) => new Promise((t) => {
|
|
73
|
+
n.set_package_registry(e, function(t) {
|
|
74
|
+
return e.resolve(t, this);
|
|
75
|
+
}), t();
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
function p(e) {
|
|
79
|
+
return async (t, n) => {
|
|
80
|
+
if (n.alreadySetAccessModel) throw Error(`already set some assess model before: ${n.alreadySetAccessModel.constructor?.name}(${n.alreadySetAccessModel})`);
|
|
81
|
+
return n.alreadySetAccessModel = e, new Promise((t) => {
|
|
82
|
+
n.builder.set_access_model(e, (t) => {
|
|
83
|
+
let n = e.getMTime(t);
|
|
84
|
+
return n ? n.getTime() : 0;
|
|
85
|
+
}, (t) => e.isFile(t) || !1, (t) => e.getRealPath(t) || t, (t) => e.readAll(t)), t();
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region node_modules/@myriaddreamin/typst.ts/dist/esm/compiler.mjs
|
|
91
|
+
var m;
|
|
92
|
+
(function(e) {
|
|
93
|
+
e[e.vector = 0] = "vector", e[e.pdf = 1] = "pdf", e[e._dummy = 2] = "_dummy";
|
|
94
|
+
})(m ||= {});
|
|
95
|
+
var h = class {
|
|
96
|
+
[r];
|
|
97
|
+
constructor(e) {
|
|
98
|
+
this[r] = e;
|
|
99
|
+
}
|
|
100
|
+
reset() {
|
|
101
|
+
this[r].reset();
|
|
102
|
+
}
|
|
103
|
+
current() {
|
|
104
|
+
return this[r].current();
|
|
105
|
+
}
|
|
106
|
+
setAttachDebugInfo(e) {
|
|
107
|
+
this[r].set_attach_debug_info(e);
|
|
108
|
+
}
|
|
109
|
+
}, g;
|
|
110
|
+
g ||= {};
|
|
111
|
+
function _() {
|
|
112
|
+
return new x();
|
|
113
|
+
}
|
|
114
|
+
var v = class {
|
|
115
|
+
[r];
|
|
116
|
+
constructor(e) {
|
|
117
|
+
this[r] = e;
|
|
118
|
+
}
|
|
119
|
+
compile(e) {
|
|
120
|
+
return this[r].compile(0, w(e?.diagnostics));
|
|
121
|
+
}
|
|
122
|
+
compileHtml(e) {
|
|
123
|
+
return this[r].compile(1, w(e?.diagnostics));
|
|
124
|
+
}
|
|
125
|
+
async query(e) {
|
|
126
|
+
return JSON.parse(this[r].query(0, e.selector, e.field));
|
|
127
|
+
}
|
|
128
|
+
title() {
|
|
129
|
+
return this[r].title(0);
|
|
130
|
+
}
|
|
131
|
+
vector(e) {
|
|
132
|
+
return this[r].get_artifact(0, w(e?.diagnostics)) || {};
|
|
133
|
+
}
|
|
134
|
+
pdf(e) {
|
|
135
|
+
return this[r].get_artifact(1, w(e?.diagnostics)) || {};
|
|
136
|
+
}
|
|
137
|
+
}, y = (e) => new i(async (t) => await e.default(t));
|
|
138
|
+
function b() {
|
|
139
|
+
return new S();
|
|
140
|
+
}
|
|
141
|
+
var x = class {
|
|
142
|
+
fontBuilderJs;
|
|
143
|
+
fontBuilder;
|
|
144
|
+
async init(e) {
|
|
145
|
+
this.fontBuilderJs = await (e?.getWrapper?.() || import("./wasm-pack-shim-BgTFpSvJ.js")), await y(this.fontBuilderJs).init(e?.getModule?.()), this.fontBuilder = new this.fontBuilderJs.TypstFontResolverBuilder();
|
|
146
|
+
}
|
|
147
|
+
async getFontInfo(e) {
|
|
148
|
+
return this.fontBuilder.get_font_info(e);
|
|
149
|
+
}
|
|
150
|
+
async addFontData(e) {
|
|
151
|
+
this.fontBuilder.add_raw_font(e);
|
|
152
|
+
}
|
|
153
|
+
async addLazyFont(e, t) {
|
|
154
|
+
return this.fontBuilder.add_lazy_font(e, t);
|
|
155
|
+
}
|
|
156
|
+
async build(e) {
|
|
157
|
+
let t = await this.fontBuilder.build(), n = await e(t);
|
|
158
|
+
return t.free(), n;
|
|
159
|
+
}
|
|
160
|
+
}, S = class e {
|
|
161
|
+
compiler;
|
|
162
|
+
compilerJs;
|
|
163
|
+
static defaultAssets = ["text"];
|
|
164
|
+
constructor() {}
|
|
165
|
+
async init(n) {
|
|
166
|
+
this.compilerJs = await (n?.getWrapper?.() || import("./wasm-pack-shim-BgTFpSvJ.js"));
|
|
167
|
+
let r = this.compilerJs.TypstCompilerBuilder, i = { ...n || {} }, a = i.beforeBuild ??= [], o = a.some((e) => e._preloadRemoteFontOptions !== void 0), s = a.some((e) => e._preloadRemoteFontOptions?.assets !== void 0), c = a.some((e) => e._preloadRemoteFontOptions?.assets === !1);
|
|
168
|
+
if ((!o || !s && !c) && a.push(d([], { assets: e.defaultAssets })), !a.some((e) => e._kind === "fontLoader")) throw Error("TypstCompiler: no font loader found, please use font loaders, e.g. loadFonts or preloadSystemFonts");
|
|
169
|
+
this.compiler = await t(n, y(this.compilerJs), r, {});
|
|
170
|
+
}
|
|
171
|
+
setFonts(e) {
|
|
172
|
+
this.compiler.set_fonts(e);
|
|
173
|
+
}
|
|
174
|
+
compile(e) {
|
|
175
|
+
return new Promise((t) => {
|
|
176
|
+
let n = this.compiler.snapshot(e.root, e.mainFilePath, C(e.inputs));
|
|
177
|
+
if ("incrementalServer" in e) {
|
|
178
|
+
t(n.incr_compile(e.incrementalServer[r], w(e.diagnostics)));
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
t(n.get_artifact(e.format || m.vector, w(e.diagnostics)));
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
async runWithWorld(e, t) {
|
|
185
|
+
let n = this.compiler.snapshot(e.root, e.mainFilePath, C(e.inputs)), r = await t(new v(n));
|
|
186
|
+
return n.free(), r;
|
|
187
|
+
}
|
|
188
|
+
query(e) {
|
|
189
|
+
return this.runWithWorld(e, async (t) => JSON.parse(await t.query(e)));
|
|
190
|
+
}
|
|
191
|
+
getSemanticTokenLegend() {
|
|
192
|
+
return new Promise((e) => {
|
|
193
|
+
e(this.compiler.get_semantic_token_legend());
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
getSemanticTokens(e) {
|
|
197
|
+
return new Promise((t) => {
|
|
198
|
+
this.compiler.reset(), t(this.compiler.get_semantic_tokens(e.offsetEncoding || "utf-16", e.mainFilePath, e.resultId));
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
async withIncrementalServer(e) {
|
|
202
|
+
let t = new h(this.compiler.create_incr_server());
|
|
203
|
+
try {
|
|
204
|
+
return await e(t);
|
|
205
|
+
} finally {
|
|
206
|
+
t[r].free();
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
async getAst(e) {
|
|
210
|
+
return this.compiler.get_ast(e);
|
|
211
|
+
}
|
|
212
|
+
async reset() {
|
|
213
|
+
await new Promise((e) => {
|
|
214
|
+
this.compiler.reset(), e(void 0);
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
addSource(e, t) {
|
|
218
|
+
if (arguments.length > 2) throw Error("use of addSource(path, source, isMain) is deprecated, please use addSource(path, source) instead");
|
|
219
|
+
this.compiler.add_source(e, t);
|
|
220
|
+
}
|
|
221
|
+
mapShadow(e, t) {
|
|
222
|
+
this.compiler.map_shadow(e, t);
|
|
223
|
+
}
|
|
224
|
+
unmapShadow(e) {
|
|
225
|
+
this.compiler.unmap_shadow(e);
|
|
226
|
+
}
|
|
227
|
+
resetShadow() {
|
|
228
|
+
this.compiler.reset_shadow();
|
|
229
|
+
}
|
|
230
|
+
renderPageToCanvas() {
|
|
231
|
+
throw Error("Please use the api TypstRenderer.renderToCanvas in v0.4.0");
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
b._impl = S;
|
|
235
|
+
function C(e) {
|
|
236
|
+
return e ? Object.entries(e) : void 0;
|
|
237
|
+
}
|
|
238
|
+
function w(e) {
|
|
239
|
+
switch (e) {
|
|
240
|
+
case "none": return 1;
|
|
241
|
+
case "unix": return 2;
|
|
242
|
+
default: return 3;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
//#endregion
|
|
246
|
+
//#region node_modules/@myriaddreamin/typst.ts/dist/esm/render/canvas/view.mjs
|
|
247
|
+
var T = class {
|
|
248
|
+
pageInfos;
|
|
249
|
+
loadPageCount;
|
|
250
|
+
imageScaleFactor;
|
|
251
|
+
container;
|
|
252
|
+
canvasList;
|
|
253
|
+
textLayerList;
|
|
254
|
+
commonList;
|
|
255
|
+
textLayerParentList;
|
|
256
|
+
semanticLayerList;
|
|
257
|
+
constructor(e, t, r) {
|
|
258
|
+
this.pageInfos = e, this.imageScaleFactor = r.pixelPerPt ?? n.PIXEL_PER_PT, t.innerHTML = "", t.style.width = "100%", this.container = t, this.canvasList = Array(this.loadPageCount), this.textLayerList = Array(this.loadPageCount), this.commonList = Array(this.loadPageCount), this.textLayerParentList = Array(this.loadPageCount), this.semanticLayerList = Array(this.loadPageCount);
|
|
259
|
+
let i = (e, n, r) => {
|
|
260
|
+
let i = Math.ceil(n.width) * this.imageScaleFactor, a = Math.ceil(n.height) * this.imageScaleFactor, o = this.canvasList[e] = document.createElement("canvas"), s = this.semanticLayerList[e] = document.createElement("div"), c = this.textLayerList[e] = document.createElement("div"), l = this.textLayerParentList[e] = document.createElement("div");
|
|
261
|
+
if (o.getContext("2d")) {
|
|
262
|
+
let e = document.createElement("div");
|
|
263
|
+
o.width = i, o.height = a, e.appendChild(o), r.appendChild(e), e.style.position = "absolute";
|
|
264
|
+
}
|
|
265
|
+
{
|
|
266
|
+
l.appendChild(c), l.className = "typst-html-semantics";
|
|
267
|
+
let e = t.offsetWidth, i = e / n.width;
|
|
268
|
+
l.style.width = `${e}px`, l.style.height = `${n.height * i}px`, l.style.setProperty("--data-text-width", `${i}px`), l.style.setProperty("--data-text-height", `${i}px`), r.classList.add("typst-page"), r.classList.add("canvas"), r.style.width = `${e}px`, r.style.height = `${a * i}px`, r.style.position = "relative", s.appendChild(l), r.appendChild(s);
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
for (let e = 0; e < this.pageInfos.length; e++) {
|
|
272
|
+
let n = this.pageInfos[e], r;
|
|
273
|
+
r = this.commonList[e] = document.createElement("div"), t.appendChild(r), i(e, n, r);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
resetLayout() {
|
|
277
|
+
for (let e = 0; e < this.pageInfos.length; e++) {
|
|
278
|
+
let t = this.pageInfos[e], n = Math.ceil(t.width) * this.imageScaleFactor, r = Math.ceil(t.height) * this.imageScaleFactor, i = this.canvasList[e].parentElement;
|
|
279
|
+
if (!i) throw Error(`canvasDiv is null for page ${e}, canvas list length ${this.canvasList.length}`);
|
|
280
|
+
let a = this.commonList[e], o = this.textLayerParentList[e], s = this.container.offsetWidth, c = s / n;
|
|
281
|
+
o.style.width = `${s}px`, o.style.height = `${r * c}px`, a.style.width = `${s}px`, a.style.height = `${r * c}px`;
|
|
282
|
+
let l = this.container.offsetWidth / n;
|
|
283
|
+
i.style.transformOrigin = "0px 0px", i.style.transform = `scale(${l})`;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}, E;
|
|
287
|
+
(function(e) {
|
|
288
|
+
e[e.Doc = 0] = "Doc", e[e.Slide = 1] = "Slide";
|
|
289
|
+
})(E ||= {});
|
|
290
|
+
var D = class e {
|
|
291
|
+
hookedElem;
|
|
292
|
+
kModule;
|
|
293
|
+
opts;
|
|
294
|
+
modes = [];
|
|
295
|
+
partialRendering = !0;
|
|
296
|
+
renderMode = "svg";
|
|
297
|
+
r = void 0;
|
|
298
|
+
previewMode = E.Doc;
|
|
299
|
+
isContentPreview = !1;
|
|
300
|
+
isMixinOutline = !1;
|
|
301
|
+
backgroundColor = "black";
|
|
302
|
+
pageColor = "white";
|
|
303
|
+
pixelPerPt = 3;
|
|
304
|
+
retrieveDOMState;
|
|
305
|
+
isRendering = !1;
|
|
306
|
+
moduleInitialized = !1;
|
|
307
|
+
patchQueue = [];
|
|
308
|
+
disposeList = [];
|
|
309
|
+
canvasRenderCToken;
|
|
310
|
+
currentRealScale = 1;
|
|
311
|
+
currentScaleRatio = 1;
|
|
312
|
+
vpTimeout = void 0;
|
|
313
|
+
sampledRenderTime = 0;
|
|
314
|
+
partialRenderPage = 0;
|
|
315
|
+
outline = void 0;
|
|
316
|
+
cursorPosition = void 0;
|
|
317
|
+
cachedDOMState = {
|
|
318
|
+
width: 0,
|
|
319
|
+
height: 0,
|
|
320
|
+
window: {
|
|
321
|
+
innerWidth: 0,
|
|
322
|
+
innerHeight: 0
|
|
323
|
+
},
|
|
324
|
+
boundingRect: {
|
|
325
|
+
left: 0,
|
|
326
|
+
top: 0,
|
|
327
|
+
right: 0
|
|
328
|
+
}
|
|
329
|
+
};
|
|
330
|
+
constructor(e) {
|
|
331
|
+
this.hookedElem = e.hookedElem, this.kModule = e.kModule, this.opts = e || {};
|
|
332
|
+
{
|
|
333
|
+
let { renderMode: t, previewMode: n, isContentPreview: r, retrieveDOMState: i } = e || {};
|
|
334
|
+
this.partialRendering = !1, this.renderMode = t ?? this.renderMode, this.previewMode = n ?? this.previewMode, this.isContentPreview = r || !1, this.retrieveDOMState = i ?? (() => ({
|
|
335
|
+
width: this.hookedElem.offsetWidth,
|
|
336
|
+
height: this.hookedElem.offsetHeight,
|
|
337
|
+
window: {
|
|
338
|
+
innerWidth: window.innerWidth,
|
|
339
|
+
innerHeight: window.innerHeight
|
|
340
|
+
},
|
|
341
|
+
boundingRect: this.hookedElem.getBoundingClientRect()
|
|
342
|
+
})), this.backgroundColor = getComputedStyle(document.documentElement).getPropertyValue("--typst-preview-background-color");
|
|
343
|
+
}
|
|
344
|
+
this.hookedElem.classList.add("hide-scrollbar-x"), this.hookedElem.parentElement?.classList.add("hide-scrollbar-x"), this.previewMode === E.Slide && (this.hookedElem.classList.add("hide-scrollbar-y"), this.hookedElem.parentElement?.classList.add("hide-scrollbar-y")), this.installCtrlWheelHandler();
|
|
345
|
+
}
|
|
346
|
+
reset() {
|
|
347
|
+
this.kModule.reset(), this.moduleInitialized = !1;
|
|
348
|
+
}
|
|
349
|
+
dispose() {
|
|
350
|
+
let e = this.disposeList;
|
|
351
|
+
this.disposeList = [], e.forEach((e) => e());
|
|
352
|
+
}
|
|
353
|
+
static derive(e, t) {
|
|
354
|
+
return [
|
|
355
|
+
"rescale",
|
|
356
|
+
"rerender",
|
|
357
|
+
"postRender"
|
|
358
|
+
].reduce((n, r) => (n[r] = e[`${r}$${t}`].bind(e), console.assert(n[r] !== void 0, `${r}$${t} is undefined`), n), {});
|
|
359
|
+
}
|
|
360
|
+
registerMode(t) {
|
|
361
|
+
let n = e.derive(this, t);
|
|
362
|
+
this.modes.push([t, n]), t === this.renderMode && (this.r = n);
|
|
363
|
+
}
|
|
364
|
+
installCtrlWheelHandler() {
|
|
365
|
+
let e = [
|
|
366
|
+
.1,
|
|
367
|
+
.2,
|
|
368
|
+
.3,
|
|
369
|
+
.4,
|
|
370
|
+
.5,
|
|
371
|
+
.6,
|
|
372
|
+
.7,
|
|
373
|
+
.8,
|
|
374
|
+
.9,
|
|
375
|
+
1,
|
|
376
|
+
1.1,
|
|
377
|
+
1.3,
|
|
378
|
+
1.5,
|
|
379
|
+
1.7,
|
|
380
|
+
1.9,
|
|
381
|
+
2.1,
|
|
382
|
+
2.4,
|
|
383
|
+
2.7,
|
|
384
|
+
3,
|
|
385
|
+
3.3,
|
|
386
|
+
3.7,
|
|
387
|
+
4.1,
|
|
388
|
+
4.6,
|
|
389
|
+
5.1,
|
|
390
|
+
5.7,
|
|
391
|
+
6.3,
|
|
392
|
+
7,
|
|
393
|
+
7.7,
|
|
394
|
+
8.5,
|
|
395
|
+
9.4,
|
|
396
|
+
10
|
|
397
|
+
], t = (t) => {
|
|
398
|
+
if (t.ctrlKey) {
|
|
399
|
+
t.preventDefault(), this.cachedDOMState = this.retrieveDOMState(), window.onresize !== null && (window.onresize = null);
|
|
400
|
+
let n = this.currentScaleRatio;
|
|
401
|
+
if (t.deltaY < 0) {
|
|
402
|
+
if (this.currentScaleRatio >= e.at(-1)) return;
|
|
403
|
+
this.currentScaleRatio = e.filter((e) => e > this.currentScaleRatio).at(0);
|
|
404
|
+
} else if (t.deltaY > 0) {
|
|
405
|
+
if (this.currentScaleRatio <= e.at(0)) return;
|
|
406
|
+
this.currentScaleRatio = e.filter((e) => e < this.currentScaleRatio).at(-1);
|
|
407
|
+
} else return;
|
|
408
|
+
let r = this.currentScaleRatio / n, i = t.pageX * (r - 1), a = t.pageY * (r - 1);
|
|
409
|
+
Math.abs(this.currentScaleRatio - 1) < 1e-5 ? (this.hookedElem.classList.add("hide-scrollbar-x"), this.hookedElem.parentElement?.classList.add("hide-scrollbar-x"), this.previewMode === E.Slide && (this.hookedElem.classList.add("hide-scrollbar-y"), this.hookedElem.parentElement?.classList.add("hide-scrollbar-y"))) : (this.hookedElem.classList.remove("hide-scrollbar-x"), this.hookedElem.parentElement?.classList.remove("hide-scrollbar-x"), this.previewMode === E.Slide && (this.hookedElem.classList.remove("hide-scrollbar-y"), this.hookedElem.parentElement?.classList.remove("hide-scrollbar-y")));
|
|
410
|
+
let o = this.hookedElem.firstElementChild;
|
|
411
|
+
if (o) {
|
|
412
|
+
let e = this.getSvgScaleRatio(), t = Number.parseFloat(o.getAttribute("data-height")), n = Math.ceil(t * e);
|
|
413
|
+
this.hookedElem.style.height = `${n * 2}px`;
|
|
414
|
+
}
|
|
415
|
+
return window.scrollBy(i, a), this.addViewportChange(), !1;
|
|
416
|
+
}
|
|
417
|
+
};
|
|
418
|
+
this.renderMode !== "dom" && (typeof acquireVsCodeApi < "u" ? (window.addEventListener("wheel", t, { passive: !1 }), this.disposeList.push(() => {
|
|
419
|
+
window.removeEventListener("wheel", t);
|
|
420
|
+
})) : (document.body.addEventListener("wheel", t, { passive: !1 }), this.disposeList.push(() => {
|
|
421
|
+
document.body.removeEventListener("wheel", t);
|
|
422
|
+
})));
|
|
423
|
+
}
|
|
424
|
+
getSvgScaleRatio() {
|
|
425
|
+
let e = this.hookedElem.firstElementChild;
|
|
426
|
+
if (!e) return 0;
|
|
427
|
+
let t = this.cachedDOMState, n = Number.parseFloat(e.getAttribute("data-width") || e.getAttribute("width") || "1"), r = Number.parseFloat(e.getAttribute("data-height") || e.getAttribute("height") || "1");
|
|
428
|
+
return this.currentRealScale = this.previewMode === E.Slide ? Math.min(t.width / n, t.height / r) : t.width / n, this.currentRealScale * this.currentScaleRatio;
|
|
429
|
+
}
|
|
430
|
+
processQueue(e) {
|
|
431
|
+
let t = e[0];
|
|
432
|
+
switch (t) {
|
|
433
|
+
case "new":
|
|
434
|
+
case "diff-v1": return t === "new" && this.reset(), this.kModule.manipulateData({
|
|
435
|
+
action: "merge",
|
|
436
|
+
data: e[1]
|
|
437
|
+
}), this.moduleInitialized = !0, !0;
|
|
438
|
+
case "viewport-change": return this.moduleInitialized ? !0 : (console.log("viewport-change before initialization"), !1);
|
|
439
|
+
default: return console.log("svgUpdateEvent", e), !1;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
triggerUpdate() {
|
|
443
|
+
if (this.isRendering) return;
|
|
444
|
+
this.isRendering = !0;
|
|
445
|
+
let e = async () => {
|
|
446
|
+
if (this.cachedDOMState = this.retrieveDOMState(), this.patchQueue.length === 0) {
|
|
447
|
+
this.isRendering = !1, this.postprocessChanges();
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
try {
|
|
451
|
+
let t = performance.now(), n = this.canvasRenderCToken;
|
|
452
|
+
n && (await n.cancel(), await n.wait(), this.canvasRenderCToken = void 0, console.log("cancel canvas rendering"));
|
|
453
|
+
let r = !1;
|
|
454
|
+
for (; this.patchQueue.length > 0;) r = this.processQueue(this.patchQueue.shift()) || r;
|
|
455
|
+
performance.now(), r && (this.r.rescale(), await this.r.rerender(), this.r.rescale());
|
|
456
|
+
let i = performance.now();
|
|
457
|
+
this.sampledRenderTime = i - t, requestAnimationFrame(e);
|
|
458
|
+
} catch (e) {
|
|
459
|
+
console.error(e), this.isRendering = !1, this.postprocessChanges();
|
|
460
|
+
}
|
|
461
|
+
};
|
|
462
|
+
requestAnimationFrame(e);
|
|
463
|
+
}
|
|
464
|
+
postprocessChanges() {
|
|
465
|
+
this.r.postRender(), this.previewMode === E.Slide && document.querySelectorAll(".typst-page-number-indicator").forEach((e) => {
|
|
466
|
+
e.textContent = `${this.kModule.retrievePagesInfo().length}`;
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
addChangement(e) {
|
|
470
|
+
e[0] === "new" && this.patchQueue.splice(0, this.patchQueue.length);
|
|
471
|
+
let t = () => {
|
|
472
|
+
this.vpTimeout = void 0, this.patchQueue.push(e), this.triggerUpdate();
|
|
473
|
+
};
|
|
474
|
+
this.vpTimeout !== void 0 && clearTimeout(this.vpTimeout), e[0] === "viewport-change" && this.isRendering ? this.vpTimeout = setTimeout(t, this.sampledRenderTime || 100) : t();
|
|
475
|
+
}
|
|
476
|
+
addViewportChange() {
|
|
477
|
+
this.addChangement(["viewport-change", ""]);
|
|
478
|
+
}
|
|
479
|
+
};
|
|
480
|
+
function O(e) {
|
|
481
|
+
return class {
|
|
482
|
+
impl;
|
|
483
|
+
kModule;
|
|
484
|
+
constructor(t) {
|
|
485
|
+
if (t.isContentPreview && (t.renderMode = "canvas"), this.kModule = t.kModule, this.impl = new e(t), !this.impl.r) throw Error(`mode is not supported, ${t?.renderMode}`);
|
|
486
|
+
t.isContentPreview && (this.impl.partialRendering = !0, this.impl.pixelPerPt = 1, this.impl.isMixinOutline = !0);
|
|
487
|
+
}
|
|
488
|
+
dispose() {
|
|
489
|
+
this.impl.dispose();
|
|
490
|
+
}
|
|
491
|
+
reset() {
|
|
492
|
+
this.impl.reset();
|
|
493
|
+
}
|
|
494
|
+
addChangement(e) {
|
|
495
|
+
this.impl.addChangement(e);
|
|
496
|
+
}
|
|
497
|
+
addViewportChange() {
|
|
498
|
+
this.impl.addViewportChange();
|
|
499
|
+
}
|
|
500
|
+
setPageColor(e) {
|
|
501
|
+
this.impl.pageColor = e, this.addViewportChange();
|
|
502
|
+
}
|
|
503
|
+
setPartialRendering(e) {
|
|
504
|
+
this.impl.partialRendering = e;
|
|
505
|
+
}
|
|
506
|
+
setCursor(e, t, n) {
|
|
507
|
+
this.impl.cursorPosition = [
|
|
508
|
+
e,
|
|
509
|
+
t,
|
|
510
|
+
n
|
|
511
|
+
];
|
|
512
|
+
}
|
|
513
|
+
setPartialPageNumber(e) {
|
|
514
|
+
return e <= 0 || e > this.kModule.retrievePagesInfo().length ? !1 : (this.impl.partialRenderPage = e - 1, this.addViewportChange(), !0);
|
|
515
|
+
}
|
|
516
|
+
getPartialPageNumber() {
|
|
517
|
+
return this.impl.partialRenderPage + 1;
|
|
518
|
+
}
|
|
519
|
+
setOutineData(e) {
|
|
520
|
+
this.impl.outline = e, this.addViewportChange();
|
|
521
|
+
}
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
function k(e, ...t) {
|
|
525
|
+
return t.reduce((e, t) => t(e), e);
|
|
526
|
+
}
|
|
527
|
+
//#endregion
|
|
528
|
+
//#region node_modules/@myriaddreamin/typst.ts/dist/esm/contrib/dom/typst-cancel.mjs
|
|
529
|
+
var A = class {
|
|
530
|
+
isCancellationRequested = !1;
|
|
531
|
+
_onCancelled;
|
|
532
|
+
_onCancelledResolveResolved;
|
|
533
|
+
constructor() {
|
|
534
|
+
let e, t;
|
|
535
|
+
this._onCancelled = new Promise((n) => {
|
|
536
|
+
e = n, t && t(n);
|
|
537
|
+
}), this._onCancelledResolveResolved = new Promise((n) => {
|
|
538
|
+
t = n, e && n(e);
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
async cancel() {
|
|
542
|
+
await this._onCancelledResolveResolved, this.isCancellationRequested = !0;
|
|
543
|
+
}
|
|
544
|
+
isCancelRequested() {
|
|
545
|
+
return this.isCancellationRequested;
|
|
546
|
+
}
|
|
547
|
+
async consume() {
|
|
548
|
+
(await this._onCancelledResolveResolved)();
|
|
549
|
+
}
|
|
550
|
+
wait() {
|
|
551
|
+
return this._onCancelled;
|
|
552
|
+
}
|
|
553
|
+
}, j = () => new Promise((e) => requestAnimationFrame(e)), M;
|
|
554
|
+
(function(e) {
|
|
555
|
+
e[e.Doc = 0] = "Doc", e[e.Pages = 1] = "Pages";
|
|
556
|
+
})(M ||= {});
|
|
557
|
+
var N;
|
|
558
|
+
(function(e) {
|
|
559
|
+
e[e.Layout = 0] = "Layout", e[e.Svg = 1] = "Svg", e[e.Semantics = 2] = "Semantics", e[e.PrepareCanvas = 3] = "PrepareCanvas", e[e.Canvas = 4] = "Canvas";
|
|
560
|
+
})(N ||= {});
|
|
561
|
+
function P(e) {
|
|
562
|
+
return class extends e {
|
|
563
|
+
tmpl = document.createElement("template");
|
|
564
|
+
stub = this.createElement("<stub></stub>");
|
|
565
|
+
plugin;
|
|
566
|
+
docKernel;
|
|
567
|
+
resourceHeader = void 0;
|
|
568
|
+
pages = [];
|
|
569
|
+
domScale = 1;
|
|
570
|
+
track_mode = M.Doc;
|
|
571
|
+
current_task = void 0;
|
|
572
|
+
viewport;
|
|
573
|
+
constructor(...e) {
|
|
574
|
+
if (super(...e), this.registerMode("dom"), this.disposeList.push(() => {
|
|
575
|
+
this.dispose();
|
|
576
|
+
}), this.plugin = this.opts.renderer, this.opts.domScale !== void 0) {
|
|
577
|
+
if (this.opts.domScale <= 0) throw Error("domScale must be positive");
|
|
578
|
+
this.domScale = this.opts.domScale;
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
dispose() {
|
|
582
|
+
for (let e of this.pages) e.dispose();
|
|
583
|
+
this.docKernel && this.docKernel.free();
|
|
584
|
+
}
|
|
585
|
+
createElement(e) {
|
|
586
|
+
return this.tmpl.innerHTML = e, this.tmpl.content.firstElementChild;
|
|
587
|
+
}
|
|
588
|
+
async mountDom(e) {
|
|
589
|
+
if (this.docKernel) throw Error("already mounted");
|
|
590
|
+
this.hookedElem.innerHTML = "<svg class=\"typst-svg-resources\" viewBox=\"0 0 0 0\" width=\"0\" height=\"0\" style=\"opacity: 0; position: absolute;\"></svg>", this.resourceHeader = this.hookedElem.querySelector(".typst-svg-resources"), this.docKernel = await this.plugin.renderer.mount_dom(this.kModule[r], this.hookedElem), this.docKernel.bind_functions({ populateGlyphs: (e) => {
|
|
591
|
+
let t = this.createElement(e).firstElementChild;
|
|
592
|
+
this.resourceHeader.append(t);
|
|
593
|
+
} });
|
|
594
|
+
}
|
|
595
|
+
async cancelAnyway$dom() {
|
|
596
|
+
if (this.current_task) {
|
|
597
|
+
let e = this.current_task;
|
|
598
|
+
this.current_task = void 0, await e.cancel();
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
retrieveDOMPages() {
|
|
602
|
+
return Array.from(this.hookedElem.querySelectorAll(".typst-dom-page"));
|
|
603
|
+
}
|
|
604
|
+
postRender$dom() {}
|
|
605
|
+
rescale$dom() {}
|
|
606
|
+
getDomViewport(e, t) {
|
|
607
|
+
let n = t.left, r = -t.top, i = t.right, a = e.innerHeight - t.top, o = {
|
|
608
|
+
x: 0,
|
|
609
|
+
y: r / this.domScale,
|
|
610
|
+
width: Math.max(i - n, 0) / this.domScale,
|
|
611
|
+
height: Math.max(a - r, 0) / this.domScale
|
|
612
|
+
};
|
|
613
|
+
return (o.width <= 0 || o.height <= 0) && (o.x = o.y = o.width = o.height = 0), o;
|
|
614
|
+
}
|
|
615
|
+
async rerender$dom() {
|
|
616
|
+
let e = this.retrieveDOMState(), { x: t, y: n, width: r, height: i } = this.getDomViewport(e.window, e.boundingRect);
|
|
617
|
+
if (!await this.docKernel.relayout(t, n, r, i)) return;
|
|
618
|
+
let a = new A();
|
|
619
|
+
this.doRender$dom(a), this.current_task = a;
|
|
620
|
+
}
|
|
621
|
+
async doRender$dom(e) {
|
|
622
|
+
let t = (t, n) => {
|
|
623
|
+
if (t && !e.isCancelRequested() && n) return n();
|
|
624
|
+
}, n = this.retrieveDOMPages().map((e) => {
|
|
625
|
+
let { innerWidth: t, innerHeight: n } = window, r = e.getBoundingClientRect();
|
|
626
|
+
return {
|
|
627
|
+
inWindow: !(r.left > t || r.right < 0 || r.top > n || r.bottom < 0),
|
|
628
|
+
page: e
|
|
629
|
+
};
|
|
630
|
+
}), r = async (r) => {
|
|
631
|
+
if (await j(), e.isCancelRequested()) return;
|
|
632
|
+
let i = n[r].page, a = i.getBoundingClientRect(), o = this.getDomViewport(window, a), s = (e) => this.docKernel.need_repaint(r, o.x, o.y, o.width, o.height, e), c = (e) => this.docKernel.repaint(r, o.x, o.y, o.width, o.height, e), l = (n) => {
|
|
633
|
+
if (!e.isCancelRequested()) return t(s(n), () => c(n));
|
|
634
|
+
};
|
|
635
|
+
await l(N.Layout);
|
|
636
|
+
let u = (a.width ? Number.parseFloat(i.getAttribute("data-width")) / a.width : 1) * this.domScale, d = (a.height ? Number.parseFloat(i.getAttribute("data-height")) / a.height : 1) * this.domScale;
|
|
637
|
+
o.x *= u, o.y *= d, o.y -= 100, o.width *= u, o.height *= d, o.height += 200, await l(N.Svg), await l(N.Semantics), !e.isCancelRequested() && (s(N.PrepareCanvas) ? (async () => {
|
|
638
|
+
if (await c(N.PrepareCanvas), !e.isCancelRequested()) return l(N.Canvas);
|
|
639
|
+
})() : await l(N.Canvas));
|
|
640
|
+
}, i = async (t) => {
|
|
641
|
+
for (let i = 0; i < n.length; ++i) {
|
|
642
|
+
if (e.isCancelRequested()) return;
|
|
643
|
+
n[i].inWindow === t && await r(i);
|
|
644
|
+
}
|
|
645
|
+
};
|
|
646
|
+
this.cancelAnyway$dom(), await i(!0), await i(!1), e.isCancelRequested();
|
|
647
|
+
}
|
|
648
|
+
};
|
|
649
|
+
}
|
|
650
|
+
var F = class extends O(k(D, P)) {}, I = class {
|
|
651
|
+
plugin;
|
|
652
|
+
[r];
|
|
653
|
+
constructor(e, t) {
|
|
654
|
+
this.plugin = e, this[r] = t;
|
|
655
|
+
}
|
|
656
|
+
set backgroundColor(e) {
|
|
657
|
+
e !== void 0 && (this[r].background_color = e);
|
|
658
|
+
}
|
|
659
|
+
get backgroundColor() {
|
|
660
|
+
return this[r].background_color;
|
|
661
|
+
}
|
|
662
|
+
set pixelPerPt(e) {
|
|
663
|
+
e !== void 0 && (this[r].pixel_per_pt = e);
|
|
664
|
+
}
|
|
665
|
+
get pixelPerPt() {
|
|
666
|
+
return this[r].pixel_per_pt;
|
|
667
|
+
}
|
|
668
|
+
reset() {
|
|
669
|
+
this.plugin.resetSession(this);
|
|
670
|
+
}
|
|
671
|
+
get doc_width() {
|
|
672
|
+
return this[r].doc_width;
|
|
673
|
+
}
|
|
674
|
+
get docWidth() {
|
|
675
|
+
return this[r].doc_width;
|
|
676
|
+
}
|
|
677
|
+
get doc_height() {
|
|
678
|
+
return this[r].doc_height;
|
|
679
|
+
}
|
|
680
|
+
get docHeight() {
|
|
681
|
+
return this[r].doc_height;
|
|
682
|
+
}
|
|
683
|
+
retrievePagesInfo() {
|
|
684
|
+
let e = this[r].pages_info, t = [], n = e.page_count;
|
|
685
|
+
for (let r = 0; r < n; r++) {
|
|
686
|
+
let n = e.page(r);
|
|
687
|
+
t.push({
|
|
688
|
+
pageOffset: n.page_off,
|
|
689
|
+
width: n.width_pt,
|
|
690
|
+
height: n.height_pt
|
|
691
|
+
});
|
|
692
|
+
}
|
|
693
|
+
return t;
|
|
694
|
+
}
|
|
695
|
+
getSourceLoc(e) {
|
|
696
|
+
return this[r].source_span(e);
|
|
697
|
+
}
|
|
698
|
+
renderSvg(e) {
|
|
699
|
+
return this.plugin.renderSvg({
|
|
700
|
+
renderSession: this,
|
|
701
|
+
...e
|
|
702
|
+
});
|
|
703
|
+
}
|
|
704
|
+
renderToSvg(e) {
|
|
705
|
+
return this.plugin.renderToSvg({
|
|
706
|
+
renderSession: this,
|
|
707
|
+
...e
|
|
708
|
+
});
|
|
709
|
+
}
|
|
710
|
+
renderCanvas(e) {
|
|
711
|
+
return this.plugin.renderCanvas({
|
|
712
|
+
renderSession: this,
|
|
713
|
+
...e
|
|
714
|
+
});
|
|
715
|
+
}
|
|
716
|
+
manipulateData(e) {
|
|
717
|
+
this.plugin.manipulateData({
|
|
718
|
+
renderSession: this,
|
|
719
|
+
...e
|
|
720
|
+
});
|
|
721
|
+
}
|
|
722
|
+
renderSvgDiff(e) {
|
|
723
|
+
return this.plugin.renderSvgDiff({
|
|
724
|
+
renderSession: this,
|
|
725
|
+
...e
|
|
726
|
+
});
|
|
727
|
+
}
|
|
728
|
+
get_source_loc(e) {
|
|
729
|
+
return this[r].source_span(e);
|
|
730
|
+
}
|
|
731
|
+
render_in_window(e, t, n, i) {
|
|
732
|
+
return this[r].render_in_window(e, t, n, i);
|
|
733
|
+
}
|
|
734
|
+
merge_delta(e) {
|
|
735
|
+
this.plugin.manipulateData({
|
|
736
|
+
renderSession: this,
|
|
737
|
+
action: "merge",
|
|
738
|
+
data: e
|
|
739
|
+
});
|
|
740
|
+
}
|
|
741
|
+
}, L;
|
|
742
|
+
(function(e) {
|
|
743
|
+
e[e.Delete = 0] = "Delete", e[e.New = 1] = "New", e[e.Update = 2] = "Update";
|
|
744
|
+
})(L ||= {});
|
|
745
|
+
var R = class {
|
|
746
|
+
plugin;
|
|
747
|
+
[r];
|
|
748
|
+
constructor(e, t) {
|
|
749
|
+
this.plugin = e, this[r] = t;
|
|
750
|
+
}
|
|
751
|
+
manipulateData(e, t) {
|
|
752
|
+
return this[r].manipulate_data(e, t);
|
|
753
|
+
}
|
|
754
|
+
managedCanvasElemList = /* @__PURE__ */ new Map();
|
|
755
|
+
canvasCounter = Math.random();
|
|
756
|
+
renderCanvas(e) {
|
|
757
|
+
let t = this.managedCanvasElemList;
|
|
758
|
+
for (let [e, n] of t) n[0] = L.Delete;
|
|
759
|
+
for (let n of e) {
|
|
760
|
+
let e = n.canvas, r = e.dataset.manageId, i = L.Update;
|
|
761
|
+
r || (r = this.canvasCounter.toFixed(5), this.canvasCounter += 1, e.dataset.manageId = r, i = L.New);
|
|
762
|
+
let a = t.get(r);
|
|
763
|
+
if (a && a[0] !== L.Delete) throw Error("cannot update a canvas for two times in batch");
|
|
764
|
+
t.set(r, [i, { ...n }]);
|
|
765
|
+
}
|
|
766
|
+
let n = Array.from(t.entries()), i = new Uint8Array(n.length), a = Array(n.length), o = n.map(([e, [n, r]], o) => (n || t.delete(e), i[o] = n, a[o] = r.canvas, this.plugin.canvasOptionsToRust(r)));
|
|
767
|
+
return this[r].render_canvas(i, a, o);
|
|
768
|
+
}
|
|
769
|
+
async retrievePagesInfo() {
|
|
770
|
+
let e = await this[r].get_pages_info();
|
|
771
|
+
console.log(e);
|
|
772
|
+
let t = [], n = e.page_count;
|
|
773
|
+
for (let r = 0; r < n; r++) {
|
|
774
|
+
let n = e.page(r);
|
|
775
|
+
t.push({
|
|
776
|
+
pageOffset: n.page_off,
|
|
777
|
+
width: n.width_pt,
|
|
778
|
+
height: n.height_pt
|
|
779
|
+
});
|
|
780
|
+
}
|
|
781
|
+
return t;
|
|
782
|
+
}
|
|
783
|
+
}, z = (e) => new i(async (t) => await e.default(t));
|
|
784
|
+
function B() {
|
|
785
|
+
return new H();
|
|
786
|
+
}
|
|
787
|
+
var V = !0, H = class {
|
|
788
|
+
renderer;
|
|
789
|
+
rendererJs;
|
|
790
|
+
constructor() {}
|
|
791
|
+
async init(e) {
|
|
792
|
+
this.rendererJs = await (e?.getWrapper?.() || import("./wasm-pack-shim-B3C4KoWa.js"));
|
|
793
|
+
let n = this.rendererJs.TypstRendererBuilder;
|
|
794
|
+
this.renderer = await t(e, z(this.rendererJs), n, {});
|
|
795
|
+
}
|
|
796
|
+
loadGlyphPack(e) {
|
|
797
|
+
return Promise.resolve();
|
|
798
|
+
}
|
|
799
|
+
createOptionsToRust(e) {
|
|
800
|
+
let t = new this.rendererJs.CreateSessionOptions();
|
|
801
|
+
return e.format !== void 0 && (t.format = e.format), e.artifactContent !== void 0 && (t.artifact_content = e.artifactContent), t;
|
|
802
|
+
}
|
|
803
|
+
canvasOptionsToRust(e) {
|
|
804
|
+
let t = new this.rendererJs.RenderPageImageOptions();
|
|
805
|
+
if (e.pageOffset === void 0) throw Error("pageOffset is required in reflexo v0.5.0");
|
|
806
|
+
if (t.page_off = e.pageOffset, e.cacheKey !== void 0 && (t.cache_key = e.cacheKey), e.backgroundColor !== void 0 && (t.background_color = e.backgroundColor), e.pixelPerPt !== void 0 && (t.pixel_per_pt = e.pixelPerPt), e.dataSelection !== void 0) {
|
|
807
|
+
let n = 0;
|
|
808
|
+
e.dataSelection.body ? n |= 1 : e.canvas && V && (V = !1, console.warn("dataSelection.body is not set but providing canvas for body")), (e.dataSelection.text || e.dataSelection.annotation) && console.error("dataSelection.text and dataSelection.annotation are deprecated"), e.dataSelection.semantics && (n |= 8), t.data_selection = n;
|
|
809
|
+
}
|
|
810
|
+
return t;
|
|
811
|
+
}
|
|
812
|
+
retrievePagesInfoFromSession(e) {
|
|
813
|
+
return e.retrievePagesInfo();
|
|
814
|
+
}
|
|
815
|
+
renderCanvas(e) {
|
|
816
|
+
return this.withinOptionSession(e, async (t) => this.renderer.render_page_to_canvas(t[r], e.canvas || void 0, this.canvasOptionsToRust(e)));
|
|
817
|
+
}
|
|
818
|
+
async inAnimationFrame(e) {
|
|
819
|
+
return new Promise((t, n) => {
|
|
820
|
+
requestAnimationFrame(() => {
|
|
821
|
+
try {
|
|
822
|
+
t(e());
|
|
823
|
+
} catch (e) {
|
|
824
|
+
n(e);
|
|
825
|
+
}
|
|
826
|
+
});
|
|
827
|
+
});
|
|
828
|
+
}
|
|
829
|
+
async renderDisplayLayer(e, t, n) {
|
|
830
|
+
let i = e[r].pages_info.page_count, a = async (r, i) => {
|
|
831
|
+
let a = t[r].getContext("2d");
|
|
832
|
+
if (!a) throw Error("canvas context is null");
|
|
833
|
+
return await this.renderCanvas({
|
|
834
|
+
...n,
|
|
835
|
+
canvas: a,
|
|
836
|
+
renderSession: e,
|
|
837
|
+
pageOffset: i
|
|
838
|
+
});
|
|
839
|
+
}, o = performance.now(), s = await (async () => {
|
|
840
|
+
let e = [];
|
|
841
|
+
for (let t = 0; t < i; t++) e.push(await this.inAnimationFrame(() => a(t, t)));
|
|
842
|
+
return e;
|
|
843
|
+
})(), c = performance.now();
|
|
844
|
+
return console.log(`display layer used: render = ${(c - o).toFixed(1)}ms`), s;
|
|
845
|
+
}
|
|
846
|
+
renderTextLayer(e, t) {
|
|
847
|
+
let n = performance.now();
|
|
848
|
+
e.forEach((e, n) => {
|
|
849
|
+
e.innerHTML = t[n].htmlSemantics[0];
|
|
850
|
+
});
|
|
851
|
+
let r = performance.now();
|
|
852
|
+
console.log(`text layer used: render = ${(r - n).toFixed(1)}ms`);
|
|
853
|
+
}
|
|
854
|
+
async render(e) {
|
|
855
|
+
if ("format" in e && e.format !== "vector" && [
|
|
856
|
+
"serde_json",
|
|
857
|
+
"js",
|
|
858
|
+
"ir"
|
|
859
|
+
].includes(e.format)) throw Error(`deprecated format ${e.format}, please use vector format`);
|
|
860
|
+
return this.renderToCanvas(e);
|
|
861
|
+
}
|
|
862
|
+
async renderDom(e) {
|
|
863
|
+
if ("format" in e && e.format !== "vector" && [
|
|
864
|
+
"serde_json",
|
|
865
|
+
"js",
|
|
866
|
+
"ir"
|
|
867
|
+
].includes(e.format)) throw Error(`deprecated format ${e.format}, please use vector format`);
|
|
868
|
+
return this.withinOptionSession(e, async (t) => {
|
|
869
|
+
let n = new F({
|
|
870
|
+
...e,
|
|
871
|
+
renderMode: "dom",
|
|
872
|
+
hookedElem: e.container,
|
|
873
|
+
kModule: t,
|
|
874
|
+
renderer: this
|
|
875
|
+
});
|
|
876
|
+
return await n.impl.mountDom(e.pixelPerPt), n;
|
|
877
|
+
});
|
|
878
|
+
}
|
|
879
|
+
async renderToCanvas(e) {
|
|
880
|
+
let t, i, a = e.container;
|
|
881
|
+
a.style.visibility = "hidden";
|
|
882
|
+
let o = async (n, r) => {
|
|
883
|
+
try {
|
|
884
|
+
i = await this.renderDisplayLayer(t, n, e), r();
|
|
885
|
+
} finally {
|
|
886
|
+
a.style.visibility = "visible";
|
|
887
|
+
}
|
|
888
|
+
};
|
|
889
|
+
return this.withinOptionSession(e, async (s) => {
|
|
890
|
+
if (t = s, t[r].pages_info.page_count === 0) throw Error("No page found in session");
|
|
891
|
+
if (e.pixelPerPt !== void 0 && e.pixelPerPt <= 0) throw Error("Invalid typst.RenderOptions.pixelPerPt, should be a positive number " + e.pixelPerPt);
|
|
892
|
+
let c = e.backgroundColor;
|
|
893
|
+
if (c !== void 0 && !/^#[0-9a-f]{6}$/.test(c)) throw Error("Invalid typst.backgroundColor color for matching ^#?[0-9a-f]{6}$ " + c);
|
|
894
|
+
t.pixelPerPt = e.pixelPerPt ?? n.PIXEL_PER_PT, t.backgroundColor = c ?? "#ffffff";
|
|
895
|
+
let l = performance.now(), u = new T(this.retrievePagesInfoFromSession(t), a, e), d = performance.now();
|
|
896
|
+
console.log(`layer used: retrieve = ${(d - l).toFixed(1)}ms`), await o(u.canvasList, () => u.resetLayout()), this.renderTextLayer(u.textLayerList, i);
|
|
897
|
+
});
|
|
898
|
+
}
|
|
899
|
+
createModule(e) {
|
|
900
|
+
return Promise.resolve(new I(this, this.renderer.create_session(e && this.createOptionsToRust({
|
|
901
|
+
format: "vector",
|
|
902
|
+
artifactContent: e
|
|
903
|
+
}))));
|
|
904
|
+
}
|
|
905
|
+
async createWorkerV0(e) {
|
|
906
|
+
return new R(this, await this.renderer.create_worker(e));
|
|
907
|
+
}
|
|
908
|
+
workerBridge() {
|
|
909
|
+
return this.renderer.create_worker_bridge();
|
|
910
|
+
}
|
|
911
|
+
renderSvg(e, t) {
|
|
912
|
+
if (e instanceof I || t) throw Error("removed api, please use renderToSvg({ renderSession, container }) instead");
|
|
913
|
+
return this.withinOptionSession(e, async (t) => {
|
|
914
|
+
let n;
|
|
915
|
+
return e.data_selection && (n = 0, e.data_selection.body && (n |= 1), e.data_selection.defs && (n |= 2), e.data_selection.css && (n |= 4), e.data_selection.js && (n |= 8)), Promise.resolve(this.renderer.svg_data(t[r], n));
|
|
916
|
+
});
|
|
917
|
+
}
|
|
918
|
+
renderSvgDiff(e) {
|
|
919
|
+
return e.window ? this.renderer.render_svg_diff(e.renderSession[r], e.window.lo.x, e.window.lo.y, e.window.hi.x, e.window.hi.y) : this.renderer.render_svg_diff(e.renderSession[r], 0, 0, 1e33, 1e33);
|
|
920
|
+
}
|
|
921
|
+
renderToSvg(e) {
|
|
922
|
+
return this.withinOptionSession(e, async (t) => Promise.resolve(this.renderer.render_svg(t[r], e.container)));
|
|
923
|
+
}
|
|
924
|
+
getCustomV1(e) {
|
|
925
|
+
return Promise.resolve(this.renderer.get_customs(e.renderSession[r]));
|
|
926
|
+
}
|
|
927
|
+
resetSession(e) {
|
|
928
|
+
return this.renderer.reset(e[r]);
|
|
929
|
+
}
|
|
930
|
+
manipulateData(e) {
|
|
931
|
+
return this.renderer.manipulate_data(e.renderSession[r], e.action ?? "reset", e.data);
|
|
932
|
+
}
|
|
933
|
+
withinOptionSession(e, t) {
|
|
934
|
+
function n(e) {
|
|
935
|
+
return "artifactContent" in e;
|
|
936
|
+
}
|
|
937
|
+
if ("renderSession" in e) return t(e.renderSession);
|
|
938
|
+
if (n(e)) return this.runWithSession(e, t);
|
|
939
|
+
throw Error("Invalid render options, should be one of RenderByContentOptions|RenderBySessionOptions");
|
|
940
|
+
}
|
|
941
|
+
async runWithSession(e, t) {
|
|
942
|
+
let n = e, r = t;
|
|
943
|
+
t || (n = void 0, r = e);
|
|
944
|
+
let i = this.renderer.create_session(n && this.createOptionsToRust(n));
|
|
945
|
+
try {
|
|
946
|
+
let e = await r(new I(this, i));
|
|
947
|
+
return i.free(), e;
|
|
948
|
+
} catch (e) {
|
|
949
|
+
throw i.free(), e;
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
}, U = class {
|
|
953
|
+
mTimes = /* @__PURE__ */ new Map();
|
|
954
|
+
mData = /* @__PURE__ */ new Map();
|
|
955
|
+
constructor() {}
|
|
956
|
+
reset() {
|
|
957
|
+
this.mTimes.clear(), this.mData.clear();
|
|
958
|
+
}
|
|
959
|
+
insertFile(e, t, n) {
|
|
960
|
+
this.mTimes.set(e, n), this.mData.set(e, t);
|
|
961
|
+
}
|
|
962
|
+
removeFile(e) {
|
|
963
|
+
this.mTimes.delete(e), this.mData.delete(e);
|
|
964
|
+
}
|
|
965
|
+
getMTime(e) {
|
|
966
|
+
if (e.startsWith("/@memory/") && this.mTimes.has(e)) return this.mTimes.get(e);
|
|
967
|
+
}
|
|
968
|
+
isFile() {
|
|
969
|
+
return !0;
|
|
970
|
+
}
|
|
971
|
+
getRealPath(e) {
|
|
972
|
+
return e;
|
|
973
|
+
}
|
|
974
|
+
readAll(e) {
|
|
975
|
+
if (e.startsWith("/@memory/") && this.mData.has(e)) return this.mData.get(e);
|
|
976
|
+
}
|
|
977
|
+
}, W = class {
|
|
978
|
+
am;
|
|
979
|
+
cache = /* @__PURE__ */ new Map();
|
|
980
|
+
constructor(e) {
|
|
981
|
+
this.am = e;
|
|
982
|
+
}
|
|
983
|
+
resolvePath(e) {
|
|
984
|
+
return `https://packages.typst.org/preview/${e.name}-${e.version}.tar.gz`;
|
|
985
|
+
}
|
|
986
|
+
pullPackageData(e) {
|
|
987
|
+
let t = new XMLHttpRequest();
|
|
988
|
+
if (t.overrideMimeType("text/plain; charset=x-user-defined"), t.open("GET", this.resolvePath(e), !1), t.send(null), t.status === 200 && (t.response instanceof String || typeof t.response == "string")) return Uint8Array.from(t.response, (e) => e.charCodeAt(0));
|
|
989
|
+
}
|
|
990
|
+
resolve(e, t) {
|
|
991
|
+
if (e.namespace !== "preview") return;
|
|
992
|
+
let n = this.resolvePath(e);
|
|
993
|
+
if (this.cache.has(n)) return this.cache.get(n)();
|
|
994
|
+
let r = this.pullPackageData(e);
|
|
995
|
+
if (!r) return;
|
|
996
|
+
let i = `/@memory/fetch/packages/${e.namespace}/${e.name}/${e.version}`, a = [];
|
|
997
|
+
t.untar(r, (e, t, n) => {
|
|
998
|
+
a.push([
|
|
999
|
+
i + "/" + e,
|
|
1000
|
+
t,
|
|
1001
|
+
new Date(n)
|
|
1002
|
+
]);
|
|
1003
|
+
});
|
|
1004
|
+
let o = () => {
|
|
1005
|
+
for (let [e, t, n] of a) this.am.insertFile(e, t, n);
|
|
1006
|
+
return i;
|
|
1007
|
+
};
|
|
1008
|
+
return this.cache.set(n, o), o();
|
|
1009
|
+
}
|
|
1010
|
+
};
|
|
1011
|
+
//#endregion
|
|
1012
|
+
//#region node_modules/@myriaddreamin/typst.ts/dist/esm/utils.mjs
|
|
1013
|
+
function G(e) {
|
|
1014
|
+
return Math.random().toString(36).replace("0.", e || "");
|
|
1015
|
+
}
|
|
1016
|
+
//#endregion
|
|
1017
|
+
//#region node_modules/@myriaddreamin/typst.ts/dist/esm/contrib/snippet.mjs
|
|
1018
|
+
var K = typeof process < "u" && process.versions != null && process.versions.node != null, q = class t {
|
|
1019
|
+
mainFilePath;
|
|
1020
|
+
cc;
|
|
1021
|
+
fr;
|
|
1022
|
+
ex;
|
|
1023
|
+
constructor(e) {
|
|
1024
|
+
this.cc = e?.compiler || t.buildLocalCompiler, this.fr = e?.fontResolver || t.buildLocalFontResolver, this.ex = e?.renderer || t.buildLocalRenderer, this.mainFilePath = "/main.typ", this.providers = [];
|
|
1025
|
+
}
|
|
1026
|
+
setCompiler(e) {
|
|
1027
|
+
this.cc = e;
|
|
1028
|
+
}
|
|
1029
|
+
async getFontResolver() {
|
|
1030
|
+
return typeof this.fr == "function" ? this.fr = await this.fr() : this.fr;
|
|
1031
|
+
}
|
|
1032
|
+
async getCompiler() {
|
|
1033
|
+
return typeof this.cc == "function" ? this.cc = await this.cc() : this.cc;
|
|
1034
|
+
}
|
|
1035
|
+
async getCompilerReset() {
|
|
1036
|
+
let e = await this.getCompiler();
|
|
1037
|
+
return await e.reset(), e;
|
|
1038
|
+
}
|
|
1039
|
+
setRenderer(e) {
|
|
1040
|
+
this.ex = e;
|
|
1041
|
+
}
|
|
1042
|
+
async getRenderer() {
|
|
1043
|
+
return typeof this.ex == "function" ? this.ex = await this.ex() : this.ex;
|
|
1044
|
+
}
|
|
1045
|
+
providers;
|
|
1046
|
+
use(...e) {
|
|
1047
|
+
if (!this.providers) throw Error("already prepare uses for instances");
|
|
1048
|
+
this.providers.push(...e);
|
|
1049
|
+
}
|
|
1050
|
+
static preloadFontFromUrl(e) {
|
|
1051
|
+
return t.preloadFonts([e]);
|
|
1052
|
+
}
|
|
1053
|
+
static preloadFontData(e) {
|
|
1054
|
+
return t.preloadFonts([e]);
|
|
1055
|
+
}
|
|
1056
|
+
static preloadFonts(e) {
|
|
1057
|
+
return {
|
|
1058
|
+
key: "access-model",
|
|
1059
|
+
forRoles: ["compiler"],
|
|
1060
|
+
provides: [d(e)]
|
|
1061
|
+
};
|
|
1062
|
+
}
|
|
1063
|
+
static disableDefaultFontAssets() {
|
|
1064
|
+
return {
|
|
1065
|
+
key: "access-model",
|
|
1066
|
+
forRoles: ["compiler"],
|
|
1067
|
+
provides: [c()]
|
|
1068
|
+
};
|
|
1069
|
+
}
|
|
1070
|
+
static preloadFontAssets(e) {
|
|
1071
|
+
return {
|
|
1072
|
+
key: "access-model",
|
|
1073
|
+
forRoles: ["compiler"],
|
|
1074
|
+
provides: [l(e)]
|
|
1075
|
+
};
|
|
1076
|
+
}
|
|
1077
|
+
static withAccessModel(e) {
|
|
1078
|
+
return {
|
|
1079
|
+
key: "access-model",
|
|
1080
|
+
forRoles: ["compiler"],
|
|
1081
|
+
provides: [p(e)]
|
|
1082
|
+
};
|
|
1083
|
+
}
|
|
1084
|
+
static withPackageRegistry(e) {
|
|
1085
|
+
return {
|
|
1086
|
+
key: "package-registry",
|
|
1087
|
+
forRoles: ["compiler"],
|
|
1088
|
+
provides: [f(e)]
|
|
1089
|
+
};
|
|
1090
|
+
}
|
|
1091
|
+
static fetchPackageRegistry(e) {
|
|
1092
|
+
let t = e || new U();
|
|
1093
|
+
return {
|
|
1094
|
+
key: "package-registry$fetch",
|
|
1095
|
+
forRoles: ["compiler"],
|
|
1096
|
+
provides: [...e ? [] : [p(t)], f(new W(t))]
|
|
1097
|
+
};
|
|
1098
|
+
}
|
|
1099
|
+
static fetchPackageBy(e, t) {
|
|
1100
|
+
class n extends W {
|
|
1101
|
+
pullPackageData(e) {
|
|
1102
|
+
return t(e, this.resolvePath(e));
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
return {
|
|
1106
|
+
key: "package-registry$lambda",
|
|
1107
|
+
forRoles: ["compiler"],
|
|
1108
|
+
provides: [f(new n(e))]
|
|
1109
|
+
};
|
|
1110
|
+
}
|
|
1111
|
+
ccOptions;
|
|
1112
|
+
setCompilerInitOptions(e) {
|
|
1113
|
+
this.requireIsUninitialized("compiler", this.cc), this.ccOptions = e;
|
|
1114
|
+
}
|
|
1115
|
+
exOptions;
|
|
1116
|
+
setRendererInitOptions(e) {
|
|
1117
|
+
this.requireIsUninitialized("renderer", this.ex), this.exOptions = e;
|
|
1118
|
+
}
|
|
1119
|
+
setMainFilePath(e) {
|
|
1120
|
+
this.mainFilePath = e;
|
|
1121
|
+
}
|
|
1122
|
+
getMainFilePath() {
|
|
1123
|
+
return this.mainFilePath;
|
|
1124
|
+
}
|
|
1125
|
+
removeTmp(e) {
|
|
1126
|
+
return e.mainFilePath.startsWith("/tmp/") ? this.unmapShadow(e.mainFilePath) : Promise.resolve();
|
|
1127
|
+
}
|
|
1128
|
+
async setFonts(t) {
|
|
1129
|
+
let n = await this.getFontResolver();
|
|
1130
|
+
for (let r of t) await n.addLazyFont(r, "blob" in r ? r.blob : e(r), r);
|
|
1131
|
+
let r = await this.getCompiler();
|
|
1132
|
+
await n.build(async (e) => r.setFonts(e));
|
|
1133
|
+
}
|
|
1134
|
+
async addSource(e, t) {
|
|
1135
|
+
(await this.getCompiler()).addSource(e, t);
|
|
1136
|
+
}
|
|
1137
|
+
async resetShadow() {
|
|
1138
|
+
(await this.getCompiler()).resetShadow();
|
|
1139
|
+
}
|
|
1140
|
+
async mapShadow(e, t) {
|
|
1141
|
+
(await this.getCompiler()).mapShadow(e, t);
|
|
1142
|
+
}
|
|
1143
|
+
async unmapShadow(e) {
|
|
1144
|
+
(await this.getCompiler()).unmapShadow(e);
|
|
1145
|
+
}
|
|
1146
|
+
async vector(e) {
|
|
1147
|
+
let t = await this.getCompileOptions(e);
|
|
1148
|
+
return (await this.getCompilerReset()).compile(t).then((e) => e.result).finally(() => this.removeTmp(t));
|
|
1149
|
+
}
|
|
1150
|
+
async pdf(e) {
|
|
1151
|
+
let t = await this.getCompileOptions(e);
|
|
1152
|
+
return t.format = m.pdf, (await this.getCompilerReset()).compile(t).then((e) => e.result).finally(() => this.removeTmp(t));
|
|
1153
|
+
}
|
|
1154
|
+
async svg(e) {
|
|
1155
|
+
return this.transientRender(e, (t, n) => t.renderSvg({
|
|
1156
|
+
...e,
|
|
1157
|
+
renderSession: n
|
|
1158
|
+
}));
|
|
1159
|
+
}
|
|
1160
|
+
async canvas(e, t) {
|
|
1161
|
+
return this.transientRender(t, (n, r) => n.renderToCanvas({
|
|
1162
|
+
container: e,
|
|
1163
|
+
...t,
|
|
1164
|
+
renderSession: r
|
|
1165
|
+
}));
|
|
1166
|
+
}
|
|
1167
|
+
async query(e) {
|
|
1168
|
+
let t = await this.getCompileOptions(e);
|
|
1169
|
+
return (await this.getCompilerReset()).query({
|
|
1170
|
+
...e,
|
|
1171
|
+
...t
|
|
1172
|
+
}).finally(() => this.removeTmp(t));
|
|
1173
|
+
}
|
|
1174
|
+
async getSemanticTokenLegend() {
|
|
1175
|
+
return (await this.getCompilerReset()).getSemanticTokenLegend();
|
|
1176
|
+
}
|
|
1177
|
+
async getSemanticTokens(e) {
|
|
1178
|
+
let t = await this.getCompileOptions(e);
|
|
1179
|
+
return (await this.getCompilerReset()).getSemanticTokens({
|
|
1180
|
+
mainFilePath: t.mainFilePath,
|
|
1181
|
+
resultId: e.resultId
|
|
1182
|
+
}).finally(() => this.removeTmp(t));
|
|
1183
|
+
}
|
|
1184
|
+
async getCompileOptions(e) {
|
|
1185
|
+
if (e === void 0) return {
|
|
1186
|
+
mainFilePath: this.mainFilePath,
|
|
1187
|
+
diagnostics: "none"
|
|
1188
|
+
};
|
|
1189
|
+
if (typeof e == "string") throw Error("please specify opts as {mainContent: '...'} or {mainFilePath: '...'}");
|
|
1190
|
+
if ("mainFilePath" in e) return {
|
|
1191
|
+
...e,
|
|
1192
|
+
diagnostics: "none"
|
|
1193
|
+
};
|
|
1194
|
+
{
|
|
1195
|
+
let t = `/tmp/${G()}.typ`;
|
|
1196
|
+
return await this.addSource(t, e.mainContent), {
|
|
1197
|
+
mainFilePath: t,
|
|
1198
|
+
inputs: e.inputs,
|
|
1199
|
+
diagnostics: "none"
|
|
1200
|
+
};
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
async getVector(e) {
|
|
1204
|
+
if (e && "vectorData" in e) return e.vectorData;
|
|
1205
|
+
let t = await this.getCompileOptions(e);
|
|
1206
|
+
return (await this.getCompiler()).compile(t).then((e) => e.result).finally(() => this.removeTmp(t));
|
|
1207
|
+
}
|
|
1208
|
+
async transientRender(e, t) {
|
|
1209
|
+
let n = await this.getRenderer();
|
|
1210
|
+
if (!n) throw Error("does not provide renderer instance");
|
|
1211
|
+
let r = await this.getVector(e);
|
|
1212
|
+
return await n.runWithSession(async (e) => (n.manipulateData({
|
|
1213
|
+
renderSession: e,
|
|
1214
|
+
action: "reset",
|
|
1215
|
+
data: r
|
|
1216
|
+
}), t(n, e)));
|
|
1217
|
+
}
|
|
1218
|
+
prepareUseOnce = void 0;
|
|
1219
|
+
async prepareUse() {
|
|
1220
|
+
return this.prepareUseOnce ? this.prepareUseOnce : this.prepareUseOnce = this.doPrepareUse();
|
|
1221
|
+
}
|
|
1222
|
+
async doPrepareUse() {
|
|
1223
|
+
if (!this.providers) return;
|
|
1224
|
+
let e = await Promise.all(this.providers.map((e) => typeof e == "function" ? e() : e));
|
|
1225
|
+
if (this.providers = [], J == this && !e.some((e) => e.key.includes("package-registry") || e.key.includes("access-model"))) if (K) {
|
|
1226
|
+
let e = Function("m", "return import(m)");
|
|
1227
|
+
try {
|
|
1228
|
+
let n = new U(), { default: r } = await e("sync-request");
|
|
1229
|
+
J.use(t.withAccessModel(n), t.fetchPackageBy(n, (e, t) => {
|
|
1230
|
+
let n = r("GET", t);
|
|
1231
|
+
if (n.statusCode === 200) return n.getBody(void 0);
|
|
1232
|
+
}));
|
|
1233
|
+
} catch {}
|
|
1234
|
+
} else J.use(t.fetchPackageRegistry());
|
|
1235
|
+
let n = await Promise.all(this.providers.map((e) => typeof e == "function" ? e() : e)), r = this.ccOptions ||= {}, i = r.beforeBuild ||= [], a = this.exOptions ||= {}, o = a.beforeBuild ||= [];
|
|
1236
|
+
for (let t of [...e, ...n]) t.forRoles.includes("compiler") && (this.requireIsUninitialized("compiler", this.cc), i.push(...t.provides)), t.forRoles.includes("renderer") && (this.requireIsUninitialized("renderer", this.ex), o.push(...t.provides));
|
|
1237
|
+
this.providers = void 0;
|
|
1238
|
+
}
|
|
1239
|
+
requireIsUninitialized(e, t, n) {
|
|
1240
|
+
if (t && typeof t != "function") throw Error(`${e} has been initialized: ${t}`);
|
|
1241
|
+
}
|
|
1242
|
+
static async buildLocalCompiler() {
|
|
1243
|
+
let { createTypstCompiler: e } = await import("./compiler-CfW6eH2M.js");
|
|
1244
|
+
await this.prepareUse();
|
|
1245
|
+
let t = e();
|
|
1246
|
+
return await t.init(this.ccOptions), t;
|
|
1247
|
+
}
|
|
1248
|
+
static async buildLocalFontResolver() {
|
|
1249
|
+
let { createTypstFontBuilder: e } = await import("./compiler-CfW6eH2M.js");
|
|
1250
|
+
await this.prepareUse();
|
|
1251
|
+
let t = e();
|
|
1252
|
+
return await t.init(this.ccOptions), t;
|
|
1253
|
+
}
|
|
1254
|
+
static async buildGlobalCompiler() {
|
|
1255
|
+
let { createGlobalCompiler: e } = await import("./global-compiler-D_nF-JaV.js"), { createTypstCompiler: t } = await import("./compiler-CfW6eH2M.js");
|
|
1256
|
+
return await this.prepareUse(), e(t, this.ccOptions);
|
|
1257
|
+
}
|
|
1258
|
+
static async buildLocalRenderer() {
|
|
1259
|
+
let { createTypstRenderer: e } = await import("./renderer-DR_79fB0.js");
|
|
1260
|
+
await this.prepareUse();
|
|
1261
|
+
let t = e();
|
|
1262
|
+
return await t.init(this.exOptions), t;
|
|
1263
|
+
}
|
|
1264
|
+
static async buildGlobalRenderer() {
|
|
1265
|
+
let { createGlobalRenderer: e } = await import("./global-renderer-gyshX_QF.js"), { createTypstRenderer: t } = await import("./renderer-DR_79fB0.js");
|
|
1266
|
+
return await this.prepareUse(), e(t, this.exOptions);
|
|
1267
|
+
}
|
|
1268
|
+
}, J = new q({
|
|
1269
|
+
compiler: q.buildGlobalCompiler,
|
|
1270
|
+
renderer: q.buildGlobalRenderer
|
|
1271
|
+
});
|
|
1272
|
+
//#endregion
|
|
1273
|
+
export { J as $typst, m as a, v as c, B as i, b as l, H as n, h as o, R as r, x as s, I as t, _ as u };
|