@btps/boundview 1.2.0-rc.3 → 1.2.0-rc.3.2
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/dist/glyphs/arimo-more.json +1 -0
- package/dist/glyphs/caladea-more.json +1 -0
- package/dist/glyphs/carlito-more.json +1 -0
- package/dist/glyphs/caveat-more.json +1 -0
- package/dist/glyphs/cousine-more.json +1 -0
- package/dist/glyphs/tinos-more.json +1 -0
- package/dist/glyphs.d.ts +7 -2
- package/dist/glyphs.js +41 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +4 -3
- package/dist/render.js +15 -3
- package/dist/signature.d.ts +35 -0
- package/dist/signature.js +86 -0
- package/dist/snapshot/bind.d.ts +13 -4
- package/dist/snapshot/bind.js +334 -111
- package/dist/snapshot/decor.d.ts +70 -0
- package/dist/snapshot/decor.js +644 -0
- package/dist/snapshot/fonts.d.ts +28 -3
- package/dist/snapshot/fonts.js +23 -4
- package/dist/snapshot/index.d.ts +46 -1
- package/dist/snapshot/index.js +1268 -182
- package/dist/snapshot/layers.d.ts +32 -0
- package/dist/snapshot/layers.js +232 -0
- package/dist/snapshot/woff2.d.ts +10 -0
- package/dist/snapshot/woff2.js +391 -0
- package/dist/svg.d.ts +1 -3
- package/dist/svg.js +39 -26
- package/package.json +7 -2
package/dist/snapshot/fonts.d.ts
CHANGED
|
@@ -19,6 +19,19 @@ export type OpenTypeFont = {
|
|
|
19
19
|
by: number;
|
|
20
20
|
}[] | undefined;
|
|
21
21
|
};
|
|
22
|
+
/** A variable font's axes and instancing, when it is one. */
|
|
23
|
+
tables: {
|
|
24
|
+
fvar?: {
|
|
25
|
+
axes: {
|
|
26
|
+
tag: string;
|
|
27
|
+
minValue: number;
|
|
28
|
+
maxValue: number;
|
|
29
|
+
}[];
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
variation?: {
|
|
33
|
+
getTransform(glyph: OpenTypeGlyph, coords: Record<string, number>): OpenTypeGlyph;
|
|
34
|
+
};
|
|
22
35
|
};
|
|
23
36
|
type OpenTypeGlyph = {
|
|
24
37
|
index: number;
|
|
@@ -50,15 +63,27 @@ type PathCommand = {
|
|
|
50
63
|
};
|
|
51
64
|
/** The characters a font always carries, so any amount or date a binding names can be drawn. */
|
|
52
65
|
export declare const ALWAYS = "0123456789.,-+%$\u20AC\u00A3\u00A5/: ";
|
|
66
|
+
/**
|
|
67
|
+
* A variable font's coordinates as the browser drew the page's text: its weight, italic where the font has an italic
|
|
68
|
+
* axis, and its optical size at the text's size in pixels (`font-optical-sizing: auto`), each held to its axis's range;
|
|
69
|
+
* undefined for a font that is not variable.
|
|
70
|
+
*/
|
|
71
|
+
export declare const variationFor: (font: OpenTypeFont, { weight, italic, size }: {
|
|
72
|
+
weight: number;
|
|
73
|
+
italic: boolean;
|
|
74
|
+
size?: number;
|
|
75
|
+
}) => Record<string, number> | undefined;
|
|
53
76
|
/**
|
|
54
77
|
* A font's glyph table for `characters`: each one's outline and advance, the
|
|
55
78
|
* kerning of the pairs among them, and its ascent and descent as far as its
|
|
56
79
|
* glyphs actually reach. Tabular figures swap in the font's own fixed-width
|
|
57
|
-
* digits, as the page drew them
|
|
58
|
-
* returned apart, so the caller can
|
|
80
|
+
* digits, as the page drew them; a variable font is read at the page's weight.
|
|
81
|
+
* Characters the font has no glyph for are returned apart, so the caller can
|
|
82
|
+
* say so.
|
|
59
83
|
*/
|
|
60
|
-
export declare const glyphTable: (font: OpenTypeFont, characters: Iterable<string>, { tabular }?: {
|
|
84
|
+
export declare const glyphTable: (font: OpenTypeFont, characters: Iterable<string>, { tabular, variation }?: {
|
|
61
85
|
tabular?: boolean;
|
|
86
|
+
variation?: Record<string, number>;
|
|
62
87
|
}) => {
|
|
63
88
|
font: BTPBoundViewFont;
|
|
64
89
|
missing: string[];
|
package/dist/snapshot/fonts.js
CHANGED
|
@@ -29,14 +29,32 @@ const outline = (commands, places) => {
|
|
|
29
29
|
})
|
|
30
30
|
.join('');
|
|
31
31
|
};
|
|
32
|
+
/**
|
|
33
|
+
* A variable font's coordinates as the browser drew the page's text: its weight, italic where the font has an italic
|
|
34
|
+
* axis, and its optical size at the text's size in pixels (`font-optical-sizing: auto`), each held to its axis's range;
|
|
35
|
+
* undefined for a font that is not variable.
|
|
36
|
+
*/
|
|
37
|
+
export const variationFor = (font, { weight, italic, size }) => {
|
|
38
|
+
const axes = font.tables.fvar?.axes;
|
|
39
|
+
if (!axes || axes.length === 0 || font.variation === undefined)
|
|
40
|
+
return undefined;
|
|
41
|
+
const coords = {};
|
|
42
|
+
for (const { tag, minValue, maxValue } of axes) {
|
|
43
|
+
const wanted = tag === 'wght' ? weight : tag === 'ital' ? (italic ? 1 : 0) : tag === 'opsz' ? size : undefined;
|
|
44
|
+
if (wanted !== undefined)
|
|
45
|
+
coords[tag] = Math.min(maxValue, Math.max(minValue, wanted));
|
|
46
|
+
}
|
|
47
|
+
return coords;
|
|
48
|
+
};
|
|
32
49
|
/**
|
|
33
50
|
* A font's glyph table for `characters`: each one's outline and advance, the
|
|
34
51
|
* kerning of the pairs among them, and its ascent and descent as far as its
|
|
35
52
|
* glyphs actually reach. Tabular figures swap in the font's own fixed-width
|
|
36
|
-
* digits, as the page drew them
|
|
37
|
-
* returned apart, so the caller can
|
|
53
|
+
* digits, as the page drew them; a variable font is read at the page's weight.
|
|
54
|
+
* Characters the font has no glyph for are returned apart, so the caller can
|
|
55
|
+
* say so.
|
|
38
56
|
*/
|
|
39
|
-
export const glyphTable = (font, characters, { tabular = false } = {}) => {
|
|
57
|
+
export const glyphTable = (font, characters, { tabular = false, variation } = {}) => {
|
|
40
58
|
const swap = new Map();
|
|
41
59
|
if (tabular) {
|
|
42
60
|
for (const script of ['DFLT', 'latn']) {
|
|
@@ -52,7 +70,8 @@ export const glyphTable = (font, characters, { tabular = false } = {}) => {
|
|
|
52
70
|
const glyphOf = (char) => {
|
|
53
71
|
const glyph = font.charToGlyph(char);
|
|
54
72
|
const swapped = swap.get(glyph.index);
|
|
55
|
-
|
|
73
|
+
const chosen = swapped === undefined ? glyph : font.glyphs.get(swapped);
|
|
74
|
+
return variation && font.variation ? font.variation.getTransform(chosen, variation) : chosen;
|
|
56
75
|
};
|
|
57
76
|
const glyphs = {};
|
|
58
77
|
const missing = [];
|
package/dist/snapshot/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { type BTPBoundView } from '@btps/sdk/boundview';
|
|
8
8
|
import { type BoundViewEngineSource } from '../render.js';
|
|
9
|
+
import { type Run } from './bind.js';
|
|
9
10
|
type Doc = Record<string, unknown>;
|
|
10
11
|
export type SnapshotOptions = {
|
|
11
12
|
/**
|
|
@@ -20,8 +21,52 @@ export type SnapshotOptions = {
|
|
|
20
21
|
/** A BoundView that cannot be sent as it is, and why. */
|
|
21
22
|
export declare class BoundViewSnapshotError extends Error {
|
|
22
23
|
readonly problems: string[];
|
|
23
|
-
|
|
24
|
+
/** The BoundView a receiver would refuse, when one was made: to see which element and why. */
|
|
25
|
+
readonly view?: BTPBoundView | undefined;
|
|
26
|
+
constructor(message: string, problems: string[],
|
|
27
|
+
/** The BoundView a receiver would refuse, when one was made: to see which element and why. */
|
|
28
|
+
view?: BTPBoundView | undefined);
|
|
24
29
|
}
|
|
30
|
+
type Decoration = {
|
|
31
|
+
line: 'underline' | 'overline' | 'line-through';
|
|
32
|
+
style: string;
|
|
33
|
+
colour: string;
|
|
34
|
+
thickness?: number;
|
|
35
|
+
offset: number;
|
|
36
|
+
};
|
|
37
|
+
type TextShadow = {
|
|
38
|
+
x: number;
|
|
39
|
+
y: number;
|
|
40
|
+
blur: number;
|
|
41
|
+
colour: string;
|
|
42
|
+
alpha: number;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* A text's look. `alpha`: its ink's, below 1 for a translucent colour. `decorations`: the lines drawn with it, its own
|
|
46
|
+
* and those its ancestors carry down to it. `shadows`: text-shadow. `smallCaps`: lower case drawn as small capitals.
|
|
47
|
+
*/
|
|
48
|
+
type Style = {
|
|
49
|
+
family: string;
|
|
50
|
+
weight: number;
|
|
51
|
+
style: string;
|
|
52
|
+
size: number;
|
|
53
|
+
colour: string;
|
|
54
|
+
spacing: number;
|
|
55
|
+
transform?: 'uppercase' | 'lowercase';
|
|
56
|
+
tabular: boolean;
|
|
57
|
+
alpha?: number;
|
|
58
|
+
smallCaps?: boolean;
|
|
59
|
+
decorations?: Decoration[];
|
|
60
|
+
shadows?: TextShadow[];
|
|
61
|
+
};
|
|
62
|
+
/** `element`: what the text is in, for its transform and the order it paints in. */
|
|
63
|
+
type LaidRun = Run & {
|
|
64
|
+
style: Style;
|
|
65
|
+
top: number;
|
|
66
|
+
element?: globalThis.Element;
|
|
67
|
+
};
|
|
68
|
+
/** Each text node as runs, one a line it was laid out on, with each character's box and the line's baseline. */
|
|
69
|
+
export declare const textRuns: (root: HTMLElement, origin: DOMRect) => LaidRun[];
|
|
25
70
|
/**
|
|
26
71
|
* Captures a preview as a BoundView: the preview's own element, laid out as
|
|
27
72
|
* the sender sees it, and the unsigned document it shows. Every fact found in
|