@open-document/core 0.4.0 → 0.5.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/package.json +1 -1
- package/src/app/components/doc-search.tsx +248 -0
- package/src/app/components/ui/menu.tsx +4 -0
- package/src/app/lib/export-dom.ts +183 -0
- package/src/app/lib/export-html.ts +12 -183
- package/src/app/lib/export-image.ts +226 -0
- package/src/app/lib/page-range.test.ts +95 -0
- package/src/app/lib/page-range.ts +90 -0
- package/src/app/routes/doc.tsx +222 -24
- package/src/app/styles.css +25 -0
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pages as pictures — SVG, and PNG rasterised from it.
|
|
3
|
+
*
|
|
4
|
+
* The page is HTML, so the SVG is an HTML page wrapped in `<foreignObject>`.
|
|
5
|
+
* That has one hard consequence: an SVG handed to the canvas rasteriser is
|
|
6
|
+
* loaded in isolation, and it may not fetch anything. A stylesheet URL, a web
|
|
7
|
+
* font, an `<img src>` pointing at the server — all of them silently do not
|
|
8
|
+
* arrive, and what comes out is a page in fallback fonts with holes where the
|
|
9
|
+
* images were. So every referenced asset is fetched here and embedded as a
|
|
10
|
+
* `data:` URI before the SVG is built. Fonts installed on the reader's own
|
|
11
|
+
* machine still resolve by name; only fetched ones need embedding.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { designToCssVars } from './design';
|
|
15
|
+
import {
|
|
16
|
+
downloadBlob,
|
|
17
|
+
findCssAssetUrls,
|
|
18
|
+
findHtmlAssetUrls,
|
|
19
|
+
renderPagesToHtml,
|
|
20
|
+
toAbsolute,
|
|
21
|
+
} from './export-dom';
|
|
22
|
+
import { type DocModule, type PageGeometry, resolvePageGeometry } from './sdk';
|
|
23
|
+
import type { ExpandedPage } from './use-doc-pages';
|
|
24
|
+
|
|
25
|
+
export type ImageFormat = 'png' | 'svg';
|
|
26
|
+
|
|
27
|
+
export type ImageExportProgress = {
|
|
28
|
+
phase: 'rendering' | 'embedding' | 'drawing' | 'done';
|
|
29
|
+
current: number;
|
|
30
|
+
total: number;
|
|
31
|
+
percent: number;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Rasterised at twice the CSS size. A page printed at 1x is legible on screen
|
|
36
|
+
* and disappointing everywhere else — the moment someone drops it into a slide
|
|
37
|
+
* the text is soft. Twice is the cheapest size that survives that.
|
|
38
|
+
*/
|
|
39
|
+
const PNG_SCALE = 2;
|
|
40
|
+
|
|
41
|
+
export async function exportDocAsImages(
|
|
42
|
+
doc: DocModule,
|
|
43
|
+
docId: string,
|
|
44
|
+
pages: ExpandedPage[],
|
|
45
|
+
format: ImageFormat,
|
|
46
|
+
onProgress?: (progress: ImageExportProgress) => void,
|
|
47
|
+
): Promise<void> {
|
|
48
|
+
if (pages.length === 0) return;
|
|
49
|
+
|
|
50
|
+
const total = pages.length;
|
|
51
|
+
const geometry = resolvePageGeometry(doc.meta);
|
|
52
|
+
const report = (phase: ImageExportProgress['phase'], current: number, percent: number) =>
|
|
53
|
+
onProgress?.({ phase, current, total, percent });
|
|
54
|
+
|
|
55
|
+
report('rendering', 0, 2);
|
|
56
|
+
const pagesHtml = await renderPagesToHtml(pages, geometry, doc);
|
|
57
|
+
|
|
58
|
+
report('embedding', 0, 20);
|
|
59
|
+
const { css, html } = await embedAssets(pagesHtml, doc);
|
|
60
|
+
|
|
61
|
+
const files: { name: string; blob: Blob }[] = [];
|
|
62
|
+
for (let i = 0; i < html.length; i++) {
|
|
63
|
+
const svg = buildSvg(html[i] ?? '', css, geometry, doc);
|
|
64
|
+
const name = `${docId}-${String(i + 1).padStart(2, '0')}`;
|
|
65
|
+
if (format === 'svg') {
|
|
66
|
+
files.push({ name: `${name}.svg`, blob: new Blob([svg], { type: 'image/svg+xml' }) });
|
|
67
|
+
} else {
|
|
68
|
+
report('drawing', i + 1, 20 + Math.round(((i + 1) / total) * 75));
|
|
69
|
+
files.push({ name: `${name}.png`, blob: await rasterise(svg, geometry) });
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
report('done', total, 100);
|
|
74
|
+
await deliver(files, docId, format);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async function deliver(
|
|
78
|
+
files: { name: string; blob: Blob }[],
|
|
79
|
+
docId: string,
|
|
80
|
+
format: ImageFormat,
|
|
81
|
+
): Promise<void> {
|
|
82
|
+
const only = files[0];
|
|
83
|
+
if (files.length === 1 && only) {
|
|
84
|
+
downloadBlob(only.blob, only.name);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const { zipSync } = await import('fflate');
|
|
88
|
+
const tree: Record<string, Uint8Array> = {};
|
|
89
|
+
for (const file of files) tree[file.name] = new Uint8Array(await file.blob.arrayBuffer());
|
|
90
|
+
const zip = zipSync(tree as Parameters<typeof zipSync>[0]);
|
|
91
|
+
downloadBlob(new Blob([zip as BlobPart], { type: 'application/zip' }), `${docId}-${format}.zip`);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async function embedAssets(
|
|
95
|
+
pagesHtml: string[],
|
|
96
|
+
doc: DocModule,
|
|
97
|
+
): Promise<{ css: string; html: string[] }> {
|
|
98
|
+
const { collectCss } = await import('./export-dom');
|
|
99
|
+
let css = collectCss();
|
|
100
|
+
const joined = pagesHtml.join('\n');
|
|
101
|
+
const urls = new Set<string>([...findHtmlAssetUrls(joined), ...findCssAssetUrls(css)]);
|
|
102
|
+
|
|
103
|
+
const replacements = new Map<string, string>();
|
|
104
|
+
for (const url of urls) {
|
|
105
|
+
const absolute = toAbsolute(url);
|
|
106
|
+
if (!absolute) continue;
|
|
107
|
+
try {
|
|
108
|
+
const res = await fetch(absolute);
|
|
109
|
+
if (!res.ok) continue;
|
|
110
|
+
const blob = await res.blob();
|
|
111
|
+
replacements.set(url, await blobToDataUrl(blob));
|
|
112
|
+
} catch {
|
|
113
|
+
/* An asset that will not load is left as it was: a broken picture in the
|
|
114
|
+
output is easier to diagnose than a silently missing one. */
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
for (const [from, to] of replacements) css = css.split(from).join(to);
|
|
119
|
+
const html = pagesHtml.map((page) => {
|
|
120
|
+
let out = page;
|
|
121
|
+
for (const [from, to] of replacements) out = out.split(from).join(to);
|
|
122
|
+
return out;
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
void doc;
|
|
126
|
+
return { css, html };
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function blobToDataUrl(blob: Blob): Promise<string> {
|
|
130
|
+
return new Promise((resolve, reject) => {
|
|
131
|
+
const reader = new FileReader();
|
|
132
|
+
reader.onload = () => resolve(String(reader.result));
|
|
133
|
+
reader.onerror = () => reject(reader.error);
|
|
134
|
+
reader.readAsDataURL(blob);
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* The markup has to come out as XML, not HTML.
|
|
140
|
+
*
|
|
141
|
+
* `foreignObject` content is parsed by the XML parser, which stops at the first
|
|
142
|
+
* `<br>` or `<img>` that never closes — and the failure arrives as an image that
|
|
143
|
+
* will not load, with nothing said about why. So the page is parsed as HTML into
|
|
144
|
+
* a real tree and serialised back out as XML, which closes those tags properly.
|
|
145
|
+
*
|
|
146
|
+
* The design variables live on the page host, and renderPagesToHtml returns the
|
|
147
|
+
* host's innerHTML, so they are not in the markup and have to be put back.
|
|
148
|
+
*/
|
|
149
|
+
function buildSvg(pageHtml: string, css: string, geometry: PageGeometry, doc: DocModule): string {
|
|
150
|
+
const SVG_NS = 'http://www.w3.org/2000/svg';
|
|
151
|
+
const XHTML_NS = 'http://www.w3.org/1999/xhtml';
|
|
152
|
+
|
|
153
|
+
const svg = document.createElementNS(SVG_NS, 'svg');
|
|
154
|
+
svg.setAttribute('width', String(geometry.width));
|
|
155
|
+
svg.setAttribute('height', String(geometry.height));
|
|
156
|
+
svg.setAttribute('viewBox', `0 0 ${geometry.width} ${geometry.height}`);
|
|
157
|
+
|
|
158
|
+
const foreign = document.createElementNS(SVG_NS, 'foreignObject');
|
|
159
|
+
foreign.setAttribute('x', '0');
|
|
160
|
+
foreign.setAttribute('y', '0');
|
|
161
|
+
foreign.setAttribute('width', String(geometry.width));
|
|
162
|
+
foreign.setAttribute('height', String(geometry.height));
|
|
163
|
+
|
|
164
|
+
const wrapper = document.createElementNS(XHTML_NS, 'div');
|
|
165
|
+
const vars = doc.design ? designToCssVars(doc.design) : null;
|
|
166
|
+
const declarations = vars
|
|
167
|
+
? Object.entries(vars)
|
|
168
|
+
.map(([name, value]) => `${name}:${value}`)
|
|
169
|
+
.join(';')
|
|
170
|
+
: '';
|
|
171
|
+
wrapper.setAttribute(
|
|
172
|
+
'style',
|
|
173
|
+
`${declarations};width:${geometry.width}px;height:${geometry.height}px`,
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
const style = document.createElementNS(XHTML_NS, 'style');
|
|
177
|
+
style.appendChild(document.createTextNode(css));
|
|
178
|
+
wrapper.appendChild(style);
|
|
179
|
+
|
|
180
|
+
const content = document.createElementNS(XHTML_NS, 'div');
|
|
181
|
+
content.innerHTML = pageHtml;
|
|
182
|
+
wrapper.appendChild(content);
|
|
183
|
+
|
|
184
|
+
foreign.appendChild(wrapper);
|
|
185
|
+
svg.appendChild(foreign);
|
|
186
|
+
return new XMLSerializer().serializeToString(svg);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* SVG → canvas → PNG.
|
|
191
|
+
*
|
|
192
|
+
* The SVG goes in as a `data:` URI, not a `blob:` one. Chrome taints a canvas
|
|
193
|
+
* that has been drawn from a blob-backed SVG containing `<foreignObject>`, and
|
|
194
|
+
* refuses to export it; the same markup as a data URI draws and exports fine.
|
|
195
|
+
* Verified against Chrome 151 — a plain SVG is clean either way, so the taint
|
|
196
|
+
* follows the foreignObject and the URL scheme together, not either alone.
|
|
197
|
+
*/
|
|
198
|
+
async function rasterise(svg: string, geometry: PageGeometry): Promise<Blob> {
|
|
199
|
+
const source = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(svg)}`;
|
|
200
|
+
|
|
201
|
+
const image = new Image();
|
|
202
|
+
await new Promise<void>((resolve, reject) => {
|
|
203
|
+
image.onload = () => resolve();
|
|
204
|
+
image.onerror = () => reject(new Error('The page could not be drawn as an image.'));
|
|
205
|
+
image.src = source;
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
const canvas = document.createElement('canvas');
|
|
209
|
+
canvas.width = Math.round(geometry.width * PNG_SCALE);
|
|
210
|
+
canvas.height = Math.round(geometry.height * PNG_SCALE);
|
|
211
|
+
const ctx = canvas.getContext('2d');
|
|
212
|
+
if (!ctx) throw new Error('This browser would not give a 2D canvas.');
|
|
213
|
+
/* A page is paper. A transparent PNG dropped on a dark slide shows black
|
|
214
|
+
body text on black. */
|
|
215
|
+
ctx.fillStyle = '#ffffff';
|
|
216
|
+
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
217
|
+
ctx.setTransform(PNG_SCALE, 0, 0, PNG_SCALE, 0, 0);
|
|
218
|
+
ctx.drawImage(image, 0, 0, geometry.width, geometry.height);
|
|
219
|
+
|
|
220
|
+
return await new Promise<Blob>((resolve, reject) => {
|
|
221
|
+
canvas.toBlob(
|
|
222
|
+
(blob) => (blob ? resolve(blob) : reject(new Error('The canvas produced no image.'))),
|
|
223
|
+
'image/png',
|
|
224
|
+
);
|
|
225
|
+
});
|
|
226
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Page ranges, where off-by-one lives.
|
|
3
|
+
*
|
|
4
|
+
* The reader types "1" and means the first page; the array wants index 0. Every
|
|
5
|
+
* assertion here is about that seam, plus the two answers that must stay
|
|
6
|
+
* distinct: "nothing you typed names a page" and "you selected no pages". Only
|
|
7
|
+
* one of them should ever start a download, and neither should download
|
|
8
|
+
* everything by accident.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { describe, expect, it } from 'vitest';
|
|
12
|
+
import { describeSelection, parseRange, resolveSelection } from './page-range';
|
|
13
|
+
|
|
14
|
+
describe('parseRange', () => {
|
|
15
|
+
it('reads single pages, one-based', () => {
|
|
16
|
+
expect(parseRange('1', 5)).toEqual([0]);
|
|
17
|
+
expect(parseRange('3', 5)).toEqual([2]);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('reads spans, inclusive at both ends', () => {
|
|
21
|
+
expect(parseRange('1-3', 5)).toEqual([0, 1, 2]);
|
|
22
|
+
expect(parseRange('4-5', 5)).toEqual([3, 4]);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('reads a mixed list, sorted and deduplicated', () => {
|
|
26
|
+
expect(parseRange('5,1,2-3,1', 9)).toEqual([0, 1, 2, 4]);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
/* A range typed backwards is a range, not a mistake worth refusing. */
|
|
30
|
+
it('accepts a span written the wrong way round', () => {
|
|
31
|
+
expect(parseRange('5-2', 9)).toEqual([1, 2, 3, 4]);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
/* 中文鍵盤打出來的全形數字和破折號,使用者不會察覺自己打的是全形。 */
|
|
35
|
+
it('accepts full-width digits and dashes', () => {
|
|
36
|
+
expect(parseRange('1-3', 5)).toEqual([0, 1, 2]);
|
|
37
|
+
expect(parseRange('2,4', 5)).toEqual([1, 3]);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('clips to the document rather than inventing pages', () => {
|
|
41
|
+
expect(parseRange('3-99', 5)).toEqual([2, 3, 4]);
|
|
42
|
+
expect(parseRange('0-2', 5)).toEqual([0, 1]);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
/*
|
|
46
|
+
* The important negative: nothing usable must be null, never an empty array.
|
|
47
|
+
* An empty array flowing on would start a download of no pages.
|
|
48
|
+
*/
|
|
49
|
+
it('returns null when nothing names a real page', () => {
|
|
50
|
+
expect(parseRange('', 5)).toBeNull();
|
|
51
|
+
expect(parseRange(' ', 5)).toBeNull();
|
|
52
|
+
expect(parseRange('abc', 5)).toBeNull();
|
|
53
|
+
expect(parseRange('9', 5)).toBeNull();
|
|
54
|
+
expect(parseRange('-', 5)).toBeNull();
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
describe('resolveSelection', () => {
|
|
59
|
+
it('all covers the document', () => {
|
|
60
|
+
expect(resolveSelection({ kind: 'all' }, 3, 2)).toEqual([0, 1, 2]);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('current is the page being read, one-based in and zero-based out', () => {
|
|
64
|
+
expect(resolveSelection({ kind: 'current' }, 5, 1)).toEqual([0]);
|
|
65
|
+
expect(resolveSelection({ kind: 'current' }, 5, 4)).toEqual([3]);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
/* currentPage can lag the document while it reflows; it must not index past. */
|
|
69
|
+
it('clamps a current page outside the document', () => {
|
|
70
|
+
expect(resolveSelection({ kind: 'current' }, 3, 99)).toEqual([2]);
|
|
71
|
+
expect(resolveSelection({ kind: 'current' }, 3, 0)).toEqual([0]);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('has nothing to give for an empty document', () => {
|
|
75
|
+
expect(resolveSelection({ kind: 'all' }, 0, 1)).toBeNull();
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
describe('describeSelection', () => {
|
|
80
|
+
it('counts what the button is about to do', () => {
|
|
81
|
+
expect(describeSelection({ kind: 'all' }, 4, 1)).toEqual({ count: 4, valid: true });
|
|
82
|
+
expect(describeSelection({ kind: 'current' }, 4, 2)).toEqual({ count: 1, valid: true });
|
|
83
|
+
expect(describeSelection({ kind: 'custom', text: '2-3' }, 4, 1)).toEqual({
|
|
84
|
+
count: 2,
|
|
85
|
+
valid: true,
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('reports an unreadable range as invalid, not as zero pages', () => {
|
|
90
|
+
expect(describeSelection({ kind: 'custom', text: 'nope' }, 4, 1)).toEqual({
|
|
91
|
+
count: 0,
|
|
92
|
+
valid: false,
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
});
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which pages a download covers.
|
|
3
|
+
*
|
|
4
|
+
* The custom field takes what a print dialog takes — `2`, `1-3`, `2,5,7-9` —
|
|
5
|
+
* because that is the notation people already have in their fingers. Everything
|
|
6
|
+
* here is 1-based on the way in and 0-based on the way out, which is where this
|
|
7
|
+
* kind of code usually goes wrong: the reader says "page 1" and the array
|
|
8
|
+
* wants index 0.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export type PageSelection =
|
|
12
|
+
| { kind: 'all' }
|
|
13
|
+
| { kind: 'current' }
|
|
14
|
+
| { kind: 'custom'; text: string };
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Zero-based indices, ascending, no duplicates.
|
|
18
|
+
*
|
|
19
|
+
* An unparseable or empty custom range returns null rather than an empty list:
|
|
20
|
+
* "I could not read that" and "you asked for no pages" are different answers,
|
|
21
|
+
* and only one of them should be allowed to start a download.
|
|
22
|
+
*/
|
|
23
|
+
export function resolveSelection(
|
|
24
|
+
selection: PageSelection,
|
|
25
|
+
total: number,
|
|
26
|
+
currentPage: number,
|
|
27
|
+
): number[] | null {
|
|
28
|
+
if (total <= 0) return null;
|
|
29
|
+
if (selection.kind === 'all') return Array.from({ length: total }, (_, i) => i);
|
|
30
|
+
if (selection.kind === 'current') {
|
|
31
|
+
const index = clamp(currentPage, 1, total) - 1;
|
|
32
|
+
return [index];
|
|
33
|
+
}
|
|
34
|
+
return parseRange(selection.text, total);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** `2,5,7-9` → [1,4,6,7,8]. Null when nothing in the text names a real page. */
|
|
38
|
+
export function parseRange(text: string, total: number): number[] | null {
|
|
39
|
+
if (text.trim() === '') return null;
|
|
40
|
+
|
|
41
|
+
const wanted = new Set<number>();
|
|
42
|
+
let sawSomething = false;
|
|
43
|
+
|
|
44
|
+
for (const chunk of text.split(/[,,\s]+/)) {
|
|
45
|
+
if (chunk === '') continue;
|
|
46
|
+
/* Full-width digits and dashes: a Chinese keyboard produces them without
|
|
47
|
+
the typist noticing, and rejecting them reads as the field being broken. */
|
|
48
|
+
const plain = chunk
|
|
49
|
+
.replace(/[0-9]/g, (d) => String(d.charCodeAt(0) - 0xff10))
|
|
50
|
+
.replace(/[–—ー-]/g, '-');
|
|
51
|
+
|
|
52
|
+
const span = /^(\d+)-(\d+)$/.exec(plain);
|
|
53
|
+
if (span) {
|
|
54
|
+
const from = Number(span[1]);
|
|
55
|
+
const to = Number(span[2]);
|
|
56
|
+
if (!Number.isFinite(from) || !Number.isFinite(to)) continue;
|
|
57
|
+
/* `5-2` is a range someone typed backwards, not an empty one. */
|
|
58
|
+
const [lo, hi] = from <= to ? [from, to] : [to, from];
|
|
59
|
+
for (let page = Math.max(1, lo); page <= Math.min(total, hi); page++) {
|
|
60
|
+
wanted.add(page - 1);
|
|
61
|
+
sawSomething = true;
|
|
62
|
+
}
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (/^\d+$/.test(plain)) {
|
|
67
|
+
const page = Number(plain);
|
|
68
|
+
if (page >= 1 && page <= total) {
|
|
69
|
+
wanted.add(page - 1);
|
|
70
|
+
sawSomething = true;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (!sawSomething || wanted.size === 0) return null;
|
|
76
|
+
return [...wanted].sort((a, b) => a - b);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function describeSelection(
|
|
80
|
+
selection: PageSelection,
|
|
81
|
+
total: number,
|
|
82
|
+
currentPage: number,
|
|
83
|
+
): { count: number; valid: boolean } {
|
|
84
|
+
const pages = resolveSelection(selection, total, currentPage);
|
|
85
|
+
return { count: pages?.length ?? 0, valid: pages !== null };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function clamp(value: number, min: number, max: number): number {
|
|
89
|
+
return Math.min(max, Math.max(min, value));
|
|
90
|
+
}
|