@kensio/colophon 2.14.0 → 2.15.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 +3 -3
- package/dist/config/defaults.d.ts +9 -5
- package/dist/config/defaults.d.ts.map +1 -1
- package/dist/config/defaults.js +8 -4
- package/dist/config/defaults.js.map +1 -1
- package/dist/highlight/grid.d.ts +5 -8
- package/dist/highlight/grid.d.ts.map +1 -1
- package/dist/highlight/grid.js +5 -5
- package/dist/highlight/grid.js.map +1 -1
- package/dist/highlight/index.d.ts.map +1 -1
- package/dist/highlight/index.js +1 -8
- package/dist/highlight/index.js.map +1 -1
- package/dist/highlight/types.d.ts +9 -6
- package/dist/highlight/types.d.ts.map +1 -1
- package/dist/layout/block.d.ts +6 -0
- package/dist/layout/block.d.ts.map +1 -1
- package/dist/layout/block.js.map +1 -1
- package/dist/layout/draw.d.ts.map +1 -1
- package/dist/layout/draw.js +3 -0
- package/dist/layout/draw.js.map +1 -1
- package/dist/layout/index.d.ts +1 -1
- package/dist/layout/index.d.ts.map +1 -1
- package/dist/layout/index.js +1 -1
- package/dist/layout/index.js.map +1 -1
- package/dist/measure/index.js +0 -0
- package/dist/measure/index.js.map +1 -1
- package/dist/measure/runs.d.ts +13 -2
- package/dist/measure/runs.d.ts.map +1 -1
- package/dist/measure/runs.js +37 -2
- package/dist/measure/runs.js.map +1 -1
- package/dist/templates/code/advance.d.ts +25 -0
- package/dist/templates/code/advance.d.ts.map +1 -0
- package/dist/templates/code/advance.js +36 -0
- package/dist/templates/code/advance.js.map +1 -0
- package/dist/templates/code/clip.d.ts +4 -3
- package/dist/templates/code/clip.d.ts.map +1 -1
- package/dist/templates/code/clip.js +18 -11
- package/dist/templates/code/clip.js.map +1 -1
- package/dist/templates/code/extent.d.ts +39 -0
- package/dist/templates/code/extent.d.ts.map +1 -0
- package/dist/templates/code/extent.js +54 -0
- package/dist/templates/code/extent.js.map +1 -0
- package/dist/templates/code/fit.d.ts +10 -8
- package/dist/templates/code/fit.d.ts.map +1 -1
- package/dist/templates/code/fit.js +5 -18
- package/dist/templates/code/fit.js.map +1 -1
- package/dist/templates/code/index.d.ts.map +1 -1
- package/dist/templates/code/index.js +7 -6
- package/dist/templates/code/index.js.map +1 -1
- package/dist/templates/code/layout.d.ts +6 -3
- package/dist/templates/code/layout.d.ts.map +1 -1
- package/dist/templates/code/layout.js +20 -7
- package/dist/templates/code/layout.js.map +1 -1
- package/dist/templates/code/mark/draw.d.ts +1 -0
- package/dist/templates/code/mark/draw.d.ts.map +1 -1
- package/dist/templates/code/mark/draw.js +3 -3
- package/dist/templates/code/mark/draw.js.map +1 -1
- package/dist/templates/code/mark/index.d.ts +2 -1
- package/dist/templates/code/mark/index.d.ts.map +1 -1
- package/dist/templates/code/mark/index.js +2 -2
- package/dist/templates/code/mark/index.js.map +1 -1
- package/dist/templates/code/mark/locate.d.ts +9 -7
- package/dist/templates/code/mark/locate.d.ts.map +1 -1
- package/dist/templates/code/mark/locate.js +28 -26
- package/dist/templates/code/mark/locate.js.map +1 -1
- package/dist/templates/code/spans.d.ts +5 -3
- package/dist/templates/code/spans.d.ts.map +1 -1
- package/dist/templates/code/spans.js +8 -6
- package/dist/templates/code/spans.js.map +1 -1
- package/dist/templates/code/truncate.d.ts +13 -0
- package/dist/templates/code/truncate.d.ts.map +1 -0
- package/dist/templates/code/truncate.js +23 -0
- package/dist/templates/code/truncate.js.map +1 -0
- package/dist/templates/cover/lines.d.ts.map +1 -1
- package/dist/templates/cover/lines.js +6 -2
- package/dist/templates/cover/lines.js.map +1 -1
- package/dist/templates/cover/lockup.d.ts +8 -1
- package/dist/templates/cover/lockup.d.ts.map +1 -1
- package/dist/templates/cover/lockup.js +11 -4
- package/dist/templates/cover/lockup.js.map +1 -1
- package/dist/templates/cover/tracking.d.ts +16 -0
- package/dist/templates/cover/tracking.d.ts.map +1 -0
- package/dist/templates/cover/tracking.js +40 -0
- package/dist/templates/cover/tracking.js.map +1 -0
- package/dist/templates/terminal/index.d.ts.map +1 -1
- package/dist/templates/terminal/index.js +7 -5
- package/dist/templates/terminal/index.js.map +1 -1
- package/dist/templates/terminal/session.d.ts.map +1 -1
- package/dist/templates/terminal/session.js +1 -12
- package/dist/templates/terminal/session.js.map +1 -1
- package/dist/text/element.d.ts +5 -0
- package/dist/text/element.d.ts.map +1 -1
- package/dist/text/element.js +4 -1
- package/dist/text/element.js.map +1 -1
- package/dist/text/index.d.ts +1 -0
- package/dist/text/index.d.ts.map +1 -1
- package/dist/text/index.js +1 -0
- package/dist/text/index.js.map +1 -1
- package/dist/text/track.d.ts +30 -0
- package/dist/text/track.d.ts.map +1 -0
- package/dist/text/track.js +44 -0
- package/dist/text/track.js.map +1 -0
- package/dist/texture/chevrons.js +1 -1
- package/dist/texture/grid.js +1 -1
- package/dist/texture/grid.js.map +1 -1
- package/dist/texture/halftone.js +2 -2
- package/dist/texture/honeycomb.js +1 -1
- package/dist/texture/honeycomb.js.map +1 -1
- package/dist/texture/index.d.ts.map +1 -1
- package/dist/texture/index.js +1 -3
- package/dist/texture/index.js.map +1 -1
- package/dist/texture/moire.js +1 -1
- package/dist/texture/moire.js.map +1 -1
- package/dist/texture/pattern.js +3 -3
- package/dist/texture/pattern.js.map +1 -1
- package/dist/texture/rays.js +1 -1
- package/dist/texture/resolve.d.ts +1 -2
- package/dist/texture/resolve.d.ts.map +1 -1
- package/dist/texture/resolve.js +4 -6
- package/dist/texture/resolve.js.map +1 -1
- package/dist/texture/scallops.js +1 -1
- package/dist/texture/topographic/index.js +2 -2
- package/dist/texture/topographic/index.js.map +1 -1
- package/dist/texture/waves.js +1 -1
- package/dist/theme/presets.d.ts +6 -6
- package/dist/theme/presets.js +6 -6
- package/dist/types.d.ts +36 -40
- package/dist/types.d.ts.map +1 -1
- package/dist/validate/keys.d.ts +0 -2
- package/dist/validate/keys.d.ts.map +1 -1
- package/dist/validate/keys.js +0 -8
- package/dist/validate/keys.js.map +1 -1
- package/dist/validate/values.d.ts.map +1 -1
- package/dist/validate/values.js +21 -0
- package/dist/validate/values.js.map +1 -1
- package/package.json +1 -1
- package/dist/templates/code/width.d.ts +0 -10
- package/dist/templates/code/width.d.ts.map +0 -1
- package/dist/templates/code/width.js +0 -26
- package/dist/templates/code/width.js.map +0 -1
- package/dist/texture/grain.d.ts +0 -17
- package/dist/texture/grain.d.ts.map +0 -1
- package/dist/texture/grain.js +0 -29
- package/dist/texture/grain.js.map +0 -1
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { CodeToken } from "../../highlight/index.js";
|
|
2
|
+
import type { Advance } from "./advance.js";
|
|
3
|
+
/** One token of a line, and how far along the line it starts. */
|
|
4
|
+
export interface PlacedToken {
|
|
5
|
+
readonly token: CodeToken;
|
|
6
|
+
readonly x: number;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* One line as plain text, rebuilt by putting each token back at its own
|
|
10
|
+
* column.
|
|
11
|
+
*
|
|
12
|
+
* What sits between two tokens is the snippet's own indentation: the
|
|
13
|
+
* highlighter drops whitespace-only runs and keeps the column they ended at,
|
|
14
|
+
* and tabs were expanded to spaces before that, so padding the gaps with
|
|
15
|
+
* spaces gives the line back exactly.
|
|
16
|
+
*/
|
|
17
|
+
export declare function lineText(tokens: readonly CodeToken[]): string;
|
|
18
|
+
/**
|
|
19
|
+
* Each token of a line with the width of everything before it, which is where
|
|
20
|
+
* it has to be drawn.
|
|
21
|
+
*/
|
|
22
|
+
export declare function placeTokens(tokens: readonly CodeToken[], advance: Advance): readonly PlacedToken[];
|
|
23
|
+
/**
|
|
24
|
+
* How far along a line a character column falls.
|
|
25
|
+
*
|
|
26
|
+
* A column past the end of the line is measured as though the line ran on in
|
|
27
|
+
* spaces, so a mark naming more characters than the line holds still gets the
|
|
28
|
+
* width it asked for rather than stopping at the last glyph.
|
|
29
|
+
*/
|
|
30
|
+
export declare function columnX(tokens: readonly CodeToken[], column: number, advance: Advance): number;
|
|
31
|
+
/** Width of the ink on one line. */
|
|
32
|
+
export declare function lineWidth(tokens: readonly CodeToken[], advance: Advance): number;
|
|
33
|
+
/**
|
|
34
|
+
* Width of the widest line, measured from the lines actually being drawn.
|
|
35
|
+
* Narrower than the snippet's longest line whenever that line was dropped or
|
|
36
|
+
* clipped, which keeps the panel hugged tight to what is visible.
|
|
37
|
+
*/
|
|
38
|
+
export declare function blockWidth(lines: readonly (readonly CodeToken[])[], advance: Advance): number;
|
|
39
|
+
//# sourceMappingURL=extent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extent.d.ts","sourceRoot":"","sources":["../../../src/templates/code/extent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,iEAAiE;AACjE,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;IAC1B,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,SAAS,SAAS,EAAE,GAAG,MAAM,CAQ7D;AAED;;;GAGG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,SAAS,SAAS,EAAE,EAC5B,OAAO,EAAE,OAAO,GACf,SAAS,WAAW,EAAE,CAOxB;AAED;;;;;;GAMG;AACH,wBAAgB,OAAO,CACrB,MAAM,EAAE,SAAS,SAAS,EAAE,EAC5B,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,OAAO,GACf,MAAM,CAER;AAED,oCAAoC;AACpC,wBAAgB,SAAS,CACvB,MAAM,EAAE,SAAS,SAAS,EAAE,EAC5B,OAAO,EAAE,OAAO,GACf,MAAM,CAER;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CACxB,KAAK,EAAE,SAAS,CAAC,SAAS,SAAS,EAAE,CAAC,EAAE,EACxC,OAAO,EAAE,OAAO,GACf,MAAM,CAQR"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One line as plain text, rebuilt by putting each token back at its own
|
|
3
|
+
* column.
|
|
4
|
+
*
|
|
5
|
+
* What sits between two tokens is the snippet's own indentation: the
|
|
6
|
+
* highlighter drops whitespace-only runs and keeps the column they ended at,
|
|
7
|
+
* and tabs were expanded to spaces before that, so padding the gaps with
|
|
8
|
+
* spaces gives the line back exactly.
|
|
9
|
+
*/
|
|
10
|
+
export function lineText(tokens) {
|
|
11
|
+
let text = "";
|
|
12
|
+
for (const token of tokens) {
|
|
13
|
+
text = text.padEnd(token.column, " ") + token.text;
|
|
14
|
+
}
|
|
15
|
+
return text;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Each token of a line with the width of everything before it, which is where
|
|
19
|
+
* it has to be drawn.
|
|
20
|
+
*/
|
|
21
|
+
export function placeTokens(tokens, advance) {
|
|
22
|
+
const text = lineText(tokens);
|
|
23
|
+
return tokens.map((token) => ({
|
|
24
|
+
token,
|
|
25
|
+
x: advance(text.slice(0, token.column)),
|
|
26
|
+
}));
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* How far along a line a character column falls.
|
|
30
|
+
*
|
|
31
|
+
* A column past the end of the line is measured as though the line ran on in
|
|
32
|
+
* spaces, so a mark naming more characters than the line holds still gets the
|
|
33
|
+
* width it asked for rather than stopping at the last glyph.
|
|
34
|
+
*/
|
|
35
|
+
export function columnX(tokens, column, advance) {
|
|
36
|
+
return advance(lineText(tokens).padEnd(column, " ").slice(0, column));
|
|
37
|
+
}
|
|
38
|
+
/** Width of the ink on one line. */
|
|
39
|
+
export function lineWidth(tokens, advance) {
|
|
40
|
+
return advance(lineText(tokens));
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Width of the widest line, measured from the lines actually being drawn.
|
|
44
|
+
* Narrower than the snippet's longest line whenever that line was dropped or
|
|
45
|
+
* clipped, which keeps the panel hugged tight to what is visible.
|
|
46
|
+
*/
|
|
47
|
+
export function blockWidth(lines, advance) {
|
|
48
|
+
let width = 0;
|
|
49
|
+
for (const tokens of lines) {
|
|
50
|
+
width = Math.max(width, lineWidth(tokens, advance));
|
|
51
|
+
}
|
|
52
|
+
return width;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=extent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extent.js","sourceRoot":"","sources":["../../../src/templates/code/extent.ts"],"names":[],"mappings":"AASA;;;;;;;;GAQG;AACH,MAAM,UAAU,QAAQ,CAAC,MAA4B;IACnD,IAAI,IAAI,GAAG,EAAE,CAAC;IAEd,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC;IACrD,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,WAAW,CACzB,MAA4B,EAC5B,OAAgB;IAEhB,MAAM,IAAI,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC;IAE9B,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAC5B,KAAK;QACL,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;KACxC,CAAC,CAAC,CAAC;AACN,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,OAAO,CACrB,MAA4B,EAC5B,MAAc,EACd,OAAgB;IAEhB,OAAO,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;AACxE,CAAC;AAED,oCAAoC;AACpC,MAAM,UAAU,SAAS,CACvB,MAA4B,EAC5B,OAAgB;IAEhB,OAAO,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;AACnC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,UAAU,CACxB,KAAwC,EACxC,OAAgB;IAEhB,IAAI,KAAK,GAAG,CAAC,CAAC;IAEd,KAAK,MAAM,MAAM,IAAI,KAAK,EAAE,CAAC;QAC3B,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACtD,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
import type { CodeToken
|
|
1
|
+
import type { CodeToken } from "../../highlight/index.js";
|
|
2
2
|
import type { Dimensions, ResolvedConfig } from "../../types.js";
|
|
3
|
+
/**
|
|
4
|
+
* How much room a snippet wants: how many lines it has, and how wide the
|
|
5
|
+
* widest of them is as a multiple of the font size.
|
|
6
|
+
*/
|
|
7
|
+
export interface SnippetExtent {
|
|
8
|
+
readonly lines: number;
|
|
9
|
+
readonly width: number;
|
|
10
|
+
}
|
|
3
11
|
/**
|
|
4
12
|
* Pick the largest font size that fits the snippet in the panel on both axes,
|
|
5
13
|
* clamped to the configured bounds.
|
|
@@ -10,13 +18,7 @@ import type { Dimensions, ResolvedConfig } from "../../types.js";
|
|
|
10
18
|
* let a landscape image render the same snippet at half the size of its square
|
|
11
19
|
* counterpart.
|
|
12
20
|
*/
|
|
13
|
-
export declare function fitFontSize(
|
|
14
|
-
/**
|
|
15
|
-
* Width of the laid-out block in characters, measured from the lines actually
|
|
16
|
-
* being drawn. Narrower than the snippet's longest line whenever that line was
|
|
17
|
-
* dropped or clipped, which keeps the panel hugged tight to what is visible.
|
|
18
|
-
*/
|
|
19
|
-
export declare function blockColumns(lines: readonly (readonly CodeToken[])[]): number;
|
|
21
|
+
export declare function fitFontSize(extent: SnippetExtent, area: Dimensions, imageWidth: number, config: ResolvedConfig): number;
|
|
20
22
|
/**
|
|
21
23
|
* Drop lines that cannot fit at the chosen font size, marking the truncation
|
|
22
24
|
* with an ellipsis line so the image never silently misrepresents the snippet.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fit.d.ts","sourceRoot":"","sources":["../../../src/templates/code/fit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,
|
|
1
|
+
{"version":3,"file":"fit.d.ts","sourceRoot":"","sources":["../../../src/templates/code/fit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAGjE;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAED;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,aAAa,EACrB,IAAI,EAAE,UAAU,EAChB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,cAAc,GACrB,MAAM,CAUR;AAaD;;;;;GAKG;AACH,wBAAgB,QAAQ,CACtB,KAAK,EAAE,SAAS,CAAC,SAAS,SAAS,EAAE,CAAC,EAAE,EACxC,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,MAAM,GACX,SAAS,CAAC,SAAS,SAAS,EAAE,CAAC,EAAE,CAWnC"}
|
|
@@ -9,28 +9,15 @@ import { ellipsis } from "../../text/ellipsis.js";
|
|
|
9
9
|
* let a landscape image render the same snippet at half the size of its square
|
|
10
10
|
* counterpart.
|
|
11
11
|
*/
|
|
12
|
-
export function fitFontSize(
|
|
12
|
+
export function fitFontSize(extent, area, imageWidth, config) {
|
|
13
13
|
const { lineHeight, maxFontScale, minFontScale } = config.code;
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
// A snippet with nothing in it puts no bound on the width, and the clamp
|
|
15
|
+
// below is what then decides the size.
|
|
16
|
+
const byWidth = extent.width > 0 ? area.width / extent.width : Infinity;
|
|
17
|
+
const byHeight = area.height / (Math.max(1, extent.lines) * lineHeight);
|
|
16
18
|
const fitted = Math.min(byWidth, byHeight, imageWidth * maxFontScale);
|
|
17
19
|
return Math.max(1, Math.floor(Math.max(fitted, imageWidth * minFontScale)));
|
|
18
20
|
}
|
|
19
|
-
/**
|
|
20
|
-
* Width of the laid-out block in characters, measured from the lines actually
|
|
21
|
-
* being drawn. Narrower than the snippet's longest line whenever that line was
|
|
22
|
-
* dropped or clipped, which keeps the panel hugged tight to what is visible.
|
|
23
|
-
*/
|
|
24
|
-
export function blockColumns(lines) {
|
|
25
|
-
let columns = 0;
|
|
26
|
-
for (const tokens of lines) {
|
|
27
|
-
const last = tokens.at(-1);
|
|
28
|
-
if (last !== undefined) {
|
|
29
|
-
columns = Math.max(columns, last.column + last.text.length);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return columns;
|
|
33
|
-
}
|
|
34
21
|
function ellipsisToken(column) {
|
|
35
22
|
return {
|
|
36
23
|
text: ellipsis,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fit.js","sourceRoot":"","sources":["../../../src/templates/code/fit.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"fit.js","sourceRoot":"","sources":["../../../src/templates/code/fit.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAWlD;;;;;;;;;GASG;AACH,MAAM,UAAU,WAAW,CACzB,MAAqB,EACrB,IAAgB,EAChB,UAAkB,EAClB,MAAsB;IAEtB,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,YAAY,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC;IAE/D,yEAAyE;IACzE,u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C,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAE1E,OAAO,CAAC,GAAG,IAAI,EAAE,CAAC,aAAa,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AAC/D,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/templates/code/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAe/C;;;;;;;;GAQG;AACH,eAAO,MAAM,YAAY,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/templates/code/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAe/C;;;;;;;;GAQG;AACH,eAAO,MAAM,YAAY,EAAE,QAgH1B,CAAC"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { highlightCode } from "../../highlight/index.js";
|
|
2
2
|
import { footerFontSize, hasFooter } from "../footer.js";
|
|
3
3
|
import { optionalString } from "../../props.js";
|
|
4
|
+
import { codeAdvance } from "./advance.js";
|
|
4
5
|
import { barRoom, windowBar } from "./bar.js";
|
|
5
6
|
import { codeFooter, codeHeading } from "./chrome.js";
|
|
6
|
-
import {
|
|
7
|
+
import { blockWidth } from "./extent.js";
|
|
7
8
|
import { gutterColumns, numberLines } from "./gutter.js";
|
|
8
9
|
import { codeMarks } from "./mark/index.js";
|
|
9
10
|
import { fitSnippet } from "./layout.js";
|
|
@@ -11,7 +12,6 @@ import { layoutPanel, titleBand } from "./panel.js";
|
|
|
11
12
|
import { hugPanel, panelSvg } from "./plate.js";
|
|
12
13
|
import { codeBody } from "./spans.js";
|
|
13
14
|
import { warnIfTruncated } from "./warn.js";
|
|
14
|
-
import { charWidthRatio } from "./width.js";
|
|
15
15
|
/**
|
|
16
16
|
* Syntax-highlighted code snippet on a rounded panel over the configured
|
|
17
17
|
* background. Reads `code` and `language` from the props (as the original
|
|
@@ -36,7 +36,8 @@ export const codeTemplate = {
|
|
|
36
36
|
const available = layoutPanel(dimensions, config, titleFs, footerFs, title !== undefined && title !== "", hasFooter(config));
|
|
37
37
|
const bar = barRoom(config, available.width);
|
|
38
38
|
const gutter = gutterColumns(config, highlighted.lines.length);
|
|
39
|
-
const
|
|
39
|
+
const advance = codeAdvance(measure, config.code.fontFamily);
|
|
40
|
+
const fitted = fitSnippet(highlighted, { ...available, y: available.y + bar, height: available.height - bar }, width, config, advance, gutter);
|
|
40
41
|
const dropped = highlighted.lines.length - fitted.lines.length;
|
|
41
42
|
warnIfTruncated(config, dimensions, { dropped, clipped: fitted.clipped }, highlighted.lines.length);
|
|
42
43
|
const lines = numberLines(fitted.lines, gutter, dropped);
|
|
@@ -45,7 +46,7 @@ export const codeTemplate = {
|
|
|
45
46
|
// block leaves the code marooned off to one side.
|
|
46
47
|
const bodyHeight = fitted.lines.length * fitted.step;
|
|
47
48
|
const panel = hugPanel(available, {
|
|
48
|
-
width:
|
|
49
|
+
width: blockWidth(lines, advance) * fitted.fontSize + fitted.padding * 2,
|
|
49
50
|
height: bar + bodyHeight + fitted.padding * 2,
|
|
50
51
|
});
|
|
51
52
|
// Code reads from the left edge, as it does in an editor. Indentation is
|
|
@@ -56,7 +57,7 @@ export const codeTemplate = {
|
|
|
56
57
|
originX,
|
|
57
58
|
originY,
|
|
58
59
|
fontSize: fitted.fontSize,
|
|
59
|
-
|
|
60
|
+
advance,
|
|
60
61
|
step: fitted.step,
|
|
61
62
|
fontFamily: config.code.fontFamily,
|
|
62
63
|
foreground: highlighted.foreground,
|
|
@@ -70,7 +71,7 @@ export const codeTemplate = {
|
|
|
70
71
|
fontSize: fitted.fontSize,
|
|
71
72
|
step: fitted.step,
|
|
72
73
|
band: { x: originX, width: panel.width - fitted.padding * 2 },
|
|
73
|
-
}, config);
|
|
74
|
+
}, config, advance);
|
|
74
75
|
const shadowOffset = Math.round(Math.min(width, height) * 0.01);
|
|
75
76
|
const plate = panelSvg(panel, highlighted.background, Math.max(1, shadowOffset), config);
|
|
76
77
|
return (codeHeading(title, titleBand(panel, dimensions, titleFs), titleFs, config) +
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/templates/code/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEzD,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/templates/code/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEzD,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,WA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,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC;YAC7C,KAAK;YACL,IAAI;YACJ,UAAU,CAAC,UAAU,EAAE,QAAQ,EAAE,MAAM,CAAC,CACzC,CAAC;IACJ,CAAC;CACF,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { CodeToken, HighlightedCode } from "../../highlight/index.js";
|
|
2
2
|
import type { ResolvedConfig } from "../../types.js";
|
|
3
|
+
import type { Advance } from "./advance.js";
|
|
3
4
|
import type { Panel } from "./panel.js";
|
|
4
5
|
/**
|
|
5
6
|
* A snippet sized to the space it has: the lines that survived, the grid they
|
|
@@ -9,6 +10,7 @@ export interface FittedCode {
|
|
|
9
10
|
readonly lines: readonly (readonly CodeToken[])[];
|
|
10
11
|
readonly clipped: number;
|
|
11
12
|
readonly fontSize: number;
|
|
13
|
+
/** One cell of the monospace grid, in pixels, for the parts that are one. */
|
|
12
14
|
readonly charWidth: number;
|
|
13
15
|
readonly step: number;
|
|
14
16
|
readonly padding: number;
|
|
@@ -19,8 +21,9 @@ export interface FittedCode {
|
|
|
19
21
|
*
|
|
20
22
|
* `gutter` is columns reserved to the left of the code, for line numbers. It
|
|
21
23
|
* is counted in characters rather than pixels because that is what it is: the
|
|
22
|
-
* numbers
|
|
23
|
-
* whatever font size the fitting settles on.
|
|
24
|
+
* numbers are digits in a monospace face, so the space they take follows
|
|
25
|
+
* whatever font size the fitting settles on. Everything to the right of them
|
|
26
|
+
* is measured instead, since the code is text and not necessarily a grid.
|
|
24
27
|
*/
|
|
25
|
-
export declare function fitSnippet(highlighted: HighlightedCode, available: Panel, imageWidth: number, config: ResolvedConfig,
|
|
28
|
+
export declare function fitSnippet(highlighted: HighlightedCode, available: Panel, imageWidth: number, config: ResolvedConfig, advance: Advance, gutter?: number): FittedCode;
|
|
26
29
|
//# sourceMappingURL=layout.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"layout.d.ts","sourceRoot":"","sources":["../../../src/templates/code/layout.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"layout.d.ts","sourceRoot":"","sources":["../../../src/templates/code/layout.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAK5C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAExC;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC,SAAS,SAAS,EAAE,CAAC,EAAE,CAAC;IAClD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,6EAA6E;IAC7E,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CACxB,WAAW,EAAE,eAAe,EAC5B,SAAS,EAAE,KAAK,EAChB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,cAAc,EACtB,OAAO,EAAE,OAAO,EAChB,MAAM,SAAI,GACT,UAAU,CAuCZ"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { cellWidth } from "./advance.js";
|
|
1
2
|
import { clipLines } from "./clip.js";
|
|
3
|
+
import { blockWidth } from "./extent.js";
|
|
2
4
|
import { fitFontSize, fitLines } from "./fit.js";
|
|
3
5
|
/**
|
|
4
6
|
* Fit a highlighted snippet into the panel it has been allotted: choose the
|
|
@@ -6,21 +8,32 @@ import { fitFontSize, fitLines } from "./fit.js";
|
|
|
6
8
|
*
|
|
7
9
|
* `gutter` is columns reserved to the left of the code, for line numbers. It
|
|
8
10
|
* is counted in characters rather than pixels because that is what it is: the
|
|
9
|
-
* numbers
|
|
10
|
-
* whatever font size the fitting settles on.
|
|
11
|
+
* numbers are digits in a monospace face, so the space they take follows
|
|
12
|
+
* whatever font size the fitting settles on. Everything to the right of them
|
|
13
|
+
* is measured instead, since the code is text and not necessarily a grid.
|
|
11
14
|
*/
|
|
12
|
-
export function fitSnippet(highlighted, available, imageWidth, config,
|
|
15
|
+
export function fitSnippet(highlighted, available, imageWidth, config, advance, gutter = 0) {
|
|
13
16
|
const inner = Math.round(Math.min(available.width, available.height) * 0.07);
|
|
14
17
|
const codeWidth = Math.max(1, available.width - inner * 2);
|
|
15
18
|
const codeHeight = Math.max(1, available.height - inner * 2);
|
|
16
|
-
const
|
|
17
|
-
const
|
|
19
|
+
const cell = cellWidth(advance);
|
|
20
|
+
const fontSize = fitFontSize({
|
|
21
|
+
lines: highlighted.lines.length,
|
|
22
|
+
width: blockWidth(highlighted.lines, advance) + gutter * cell,
|
|
23
|
+
}, { width: codeWidth, height: codeHeight }, imageWidth, config);
|
|
18
24
|
const step = fontSize * config.code.lineHeight;
|
|
19
|
-
const { lines, clipped } = clipLines(fitLines(highlighted.lines, codeHeight, step), Math.max(
|
|
25
|
+
const { lines, clipped } = clipLines(fitLines(highlighted.lines, codeHeight, step), Math.max(cell, codeWidth / fontSize - gutter * cell), advance);
|
|
20
26
|
// Padding reads best proportional to the text rather than the panel, since a
|
|
21
27
|
// snippet fitted down to a small size wants tighter margins. Only ever
|
|
22
28
|
// shrink, so the code area the font was fitted against stays valid.
|
|
23
29
|
const padding = Math.max(Math.min(inner, Math.round(fontSize * 1.6)), Math.round(inner * 0.35));
|
|
24
|
-
return {
|
|
30
|
+
return {
|
|
31
|
+
lines,
|
|
32
|
+
clipped,
|
|
33
|
+
fontSize,
|
|
34
|
+
charWidth: fontSize * cell,
|
|
35
|
+
step,
|
|
36
|
+
padding,
|
|
37
|
+
};
|
|
25
38
|
}
|
|
26
39
|
//# sourceMappingURL=layout.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"layout.js","sourceRoot":"","sources":["../../../src/templates/code/layout.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"layout.js","sourceRoot":"","sources":["../../../src/templates/code/layout.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAiBjD;;;;;;;;;GASG;AACH,MAAM,UAAU,UAAU,CACxB,WAA4B,EAC5B,SAAgB,EAChB,UAAkB,EAClB,MAAsB,EACtB,OAAgB,EAChB,MAAM,GAAG,CAAC;IAEV,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC;IAC7E,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,SAAS,CAAC,KAAK,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC;IAC3D,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,SAAS,CAAC,MAAM,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC;IAC7D,MAAM,IAAI,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC;IAEhC,MAAM,QAAQ,GAAG,WAAW,CAC1B;QACE,KAAK,EAAE,WAAW,CAAC,KAAK,CAAC,MAAM;QAC/B,KAAK,EAAE,UAAU,CAAC,WAAW,CAAC,KAAK,EAAE,OAAO,CAAC,GAAG,MAAM,GAAG,IAAI;KAC9D,EACD,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,EACxC,UAAU,EACV,MAAM,CACP,CAAC;IACF,MAAM,IAAI,GAAG,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC;IAE/C,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,SAAS,CAClC,QAAQ,CAAC,WAAW,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,CAAC,EAC7C,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,SAAS,GAAG,QAAQ,GAAG,MAAM,GAAG,IAAI,CAAC,EACpD,OAAO,CACR,CAAC;IAEF,6EAA6E;IAC7E,uEAAuE;IACvE,oEAAoE;IACpE,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CACtB,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,GAAG,CAAC,CAAC,EAC3C,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC,CACzB,CAAC;IAEF,OAAO;QACL,KAAK;QACL,OAAO;QACP,QAAQ;QACR,SAAS,EAAE,QAAQ,GAAG,IAAI;QAC1B,IAAI;QACJ,OAAO;KACR,CAAC;AACJ,CAAC"}
|
|
@@ -4,6 +4,7 @@ export interface MarkMetrics {
|
|
|
4
4
|
/** Where column zero of the code is, past the gutter. */
|
|
5
5
|
readonly originX: number;
|
|
6
6
|
readonly originY: number;
|
|
7
|
+
/** One cell of the monospace grid, which is what the padding is keyed to. */
|
|
7
8
|
readonly charWidth: number;
|
|
8
9
|
readonly fontSize: number;
|
|
9
10
|
readonly step: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"draw.d.ts","sourceRoot":"","sources":["../../../../src/templates/code/mark/draw.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM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ACd,OAAO,EAAE,WAAW,EACpB,KAAK,EAAE,MAAM,GACZ,MAAM,CA2BR"}
|
|
@@ -23,14 +23,14 @@ export function markSvg(span, metrics, color) {
|
|
|
23
23
|
const { originX, charWidth, fontSize } = metrics;
|
|
24
24
|
const { y, height } = lineRect(span, metrics);
|
|
25
25
|
const fill = span.color ?? color;
|
|
26
|
-
if (span.
|
|
26
|
+
if (span.width === undefined) {
|
|
27
27
|
return box({ x: metrics.band.x, y, width: metrics.band.width, height }, { radius: Math.round(fontSize * 0.2), fill, fillOpacity: 0.16 });
|
|
28
28
|
}
|
|
29
29
|
const pad = charWidth * padScale;
|
|
30
30
|
return box({
|
|
31
|
-
x: Math.round(originX + span.
|
|
31
|
+
x: Math.round(originX + span.x * fontSize - pad),
|
|
32
32
|
y,
|
|
33
|
-
width: Math.round(span.
|
|
33
|
+
width: Math.round(span.width * fontSize + pad * 2),
|
|
34
34
|
height,
|
|
35
35
|
}, {
|
|
36
36
|
radius: Math.round(fontSize * 0.2),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"draw.js","sourceRoot":"","sources":["../../../../src/templates/code/mark/draw.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"draw.js","sourceRoot":"","sources":["../../../../src/templates/code/mark/draw.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAgB/C,2EAA2E;AAC3E,MAAM,QAAQ,GAAG,IAAI,CAAC;AAEtB,4EAA4E;AAC5E,SAAS,QAAQ,CACf,IAAc,EACd,OAAoB;IAEpB,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IAC5C,MAAM,GAAG,GAAG,QAAQ,GAAG,QAAQ,CAAC;IAEhC,OAAO;QACL,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,IAAI,CAA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AAE,IAAI;QACZ,WAAW,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC;KACtD,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { CodeToken } from "../../../highlight/index.js";
|
|
2
2
|
import type { MetaImageProps, ResolvedConfig } from "../../../types.js";
|
|
3
|
+
import type { Advance } from "../advance.js";
|
|
3
4
|
import type { MarkMetrics } from "./draw.js";
|
|
4
5
|
export type { MarkMetrics } from "./draw.js";
|
|
5
6
|
/**
|
|
@@ -12,5 +13,5 @@ export type { MarkMetrics } from "./draw.js";
|
|
|
12
13
|
* marks were not found, and the truncation warning beside it says whether
|
|
13
14
|
* there was room for them.
|
|
14
15
|
*/
|
|
15
|
-
export declare function codeMarks(props: MetaImageProps, lines: readonly (readonly CodeToken[])[], metrics: MarkMetrics, config: ResolvedConfig): string;
|
|
16
|
+
export declare function codeMarks(props: MetaImageProps, lines: readonly (readonly CodeToken[])[], metrics: MarkMetrics, config: ResolvedConfig, advance: Advance): string;
|
|
16
17
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/templates/code/mark/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/templates/code/mark/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACxE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAE7C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAI7C,YAAY,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAE7C;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CACvB,KAAK,EAAE,cAAc,EACrB,KAAK,EAAE,SAAS,CAAC,SAAS,SAAS,EAAE,CAAC,EAAE,EACxC,OAAO,EAAE,WAAW,EACpB,MAAM,EAAE,cAAc,EACtB,OAAO,EAAE,OAAO,GACf,MAAM,CA0BR"}
|
|
@@ -11,14 +11,14 @@ import { readMarks } from "./read.js";
|
|
|
11
11
|
* marks were not found, and the truncation warning beside it says whether
|
|
12
12
|
* there was room for them.
|
|
13
13
|
*/
|
|
14
|
-
export function codeMarks(props, lines, metrics, config) {
|
|
14
|
+
export function codeMarks(props, lines, metrics, config, advance) {
|
|
15
15
|
// Widened because this arrives from a post's frontmatter: the declared type
|
|
16
16
|
// is what a project means to write, not what the file holds.
|
|
17
17
|
const declared = props["mark"];
|
|
18
18
|
const missing = [];
|
|
19
19
|
let drawn = "";
|
|
20
20
|
for (const mark of readMarks(declared, config)) {
|
|
21
|
-
const span = locateMark(mark, lines);
|
|
21
|
+
const span = locateMark(mark, lines, advance);
|
|
22
22
|
if (span === undefined) {
|
|
23
23
|
missing.push(mark.text ?? `line ${String(mark.line ?? 0)}`);
|
|
24
24
|
continue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/templates/code/mark/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/templates/code/mark/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAItC;;;;;;;;;GASG;AACH,MAAM,UAAU,SAAS,CACvB,KAAqB,EACrB,KAAwC,EACxC,OAAoB,EACpB,MAAsB,EACtB,OAAgB;IAEhB,4EAA4E;IAC5E,6DAA6D;IAC7D,MAAM,QAAQ,GAAY,KAAK,CAAC,MAAM,CAAC,CAAC;IACxC,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,IAAI,KAAK,GAAG,EAAE,CAAC;IAEf,KAAK,MAAM,IAAI,IAAI,SAAS,CAAC,QAAQ,EAAE,MAAM,CAAC,EAAE,CAAC;QAC/C,MAAM,IAAI,GAAG,UAAU,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;QAE9C,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACvB,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,QAAQ,MAAM,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC;YAC5D,SAAS;QACX,CAAC;QAED,KAAK,IAAI,OAAO,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IAC3D,CAAC;IAED,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACvB,MAAM,CAAC,SAAS,CACd,aAAa,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;YACnE,qCAAqC,CACxC,CAAC;IACJ,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
import type { CodeToken } from "../../../highlight/index.js";
|
|
2
|
+
import type { Advance } from "../advance.js";
|
|
2
3
|
import type { CodeMark } from "./read.js";
|
|
3
|
-
/** Where a mark landed on the
|
|
4
|
+
/** Where a mark landed on the drawn snippet, once it was found. */
|
|
4
5
|
export interface MarkSpan {
|
|
5
6
|
/** Zero-based, into the lines being drawn. */
|
|
6
7
|
readonly line: number;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
/** How far along the line the mark starts, as a multiple of the size. */
|
|
9
|
+
readonly x: number;
|
|
10
|
+
/** How much of the line it covers, or `undefined` for the whole of it. */
|
|
11
|
+
readonly width: number | undefined;
|
|
10
12
|
readonly color: string | undefined;
|
|
11
13
|
}
|
|
12
14
|
/**
|
|
13
|
-
* Turn a declared mark into
|
|
14
|
-
* something the image does not show.
|
|
15
|
+
* Turn a declared mark into coordinates on the drawn snippet, or nothing where
|
|
16
|
+
* it names something the image does not show.
|
|
15
17
|
*
|
|
16
18
|
* A mark naming a line and no column is the whole line, which is the band an
|
|
17
19
|
* editor draws rather than a box around a word.
|
|
18
20
|
*/
|
|
19
|
-
export declare function locateMark(mark: CodeMark, lines: readonly (readonly CodeToken[])[]): MarkSpan | undefined;
|
|
21
|
+
export declare function locateMark(mark: CodeMark, lines: readonly (readonly CodeToken[])[], advance: Advance): MarkSpan | undefined;
|
|
20
22
|
//# sourceMappingURL=locate.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"locate.d.ts","sourceRoot":"","sources":["../../../../src/templates/code/mark/locate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAE1C,
|
|
1
|
+
{"version":3,"file":"locate.d.ts","sourceRoot":"","sources":["../../../../src/templates/code/mark/locate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAE7C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAE1C,mEAAmE;AACnE,MAAM,WAAW,QAAQ;IACvB,8CAA8C;IAC9C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,yEAAyE;IACzE,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;IACnB,0EAA0E;IAC1E,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;CACpC;AAiDD;;;;;;GAMG;AACH,wBAAgB,UAAU,CACxB,IAAI,EAAE,QAAQ,EACd,KAAK,EAAE,SAAS,CAAC,SAAS,SAAS,EAAE,CAAC,EAAE,EACxC,OAAO,EAAE,OAAO,GACf,QAAQ,GAAG,SAAS,CA0BtB"}
|
|
@@ -1,21 +1,13 @@
|
|
|
1
|
+
import { columnX, lineText } from "../extent.js";
|
|
1
2
|
/**
|
|
2
|
-
*
|
|
3
|
-
* own column.
|
|
3
|
+
* The first line holding the text, and which character of it it starts at.
|
|
4
4
|
*
|
|
5
|
-
* The tokens are what survived highlighting, fitting and clipping, so this
|
|
6
|
-
* the line as it will be drawn rather than as it was written.
|
|
7
|
-
* is drawn is the point: a mark on a line that was dropped has
|
|
8
|
-
* and finding it in the original snippet would only mean
|
|
9
|
-
* wrong place.
|
|
5
|
+
* The tokens are what survived highlighting, fitting and clipping, so this
|
|
6
|
+
* searches the line as it will be drawn rather than as it was written.
|
|
7
|
+
* Searching what is drawn is the point: a mark on a line that was dropped has
|
|
8
|
+
* nowhere to go, and finding it in the original snippet would only mean
|
|
9
|
+
* drawing a box in the wrong place.
|
|
10
10
|
*/
|
|
11
|
-
function lineText(tokens) {
|
|
12
|
-
let text = "";
|
|
13
|
-
for (const token of tokens) {
|
|
14
|
-
text = text.padEnd(token.column, " ") + token.text;
|
|
15
|
-
}
|
|
16
|
-
return text;
|
|
17
|
-
}
|
|
18
|
-
/** The first line holding the text, and where on it. */
|
|
19
11
|
function findText(text, lines) {
|
|
20
12
|
for (const [line, tokens] of lines.entries()) {
|
|
21
13
|
const column = lineText(tokens).indexOf(text);
|
|
@@ -26,31 +18,41 @@ function findText(text, lines) {
|
|
|
26
18
|
return undefined;
|
|
27
19
|
}
|
|
28
20
|
/**
|
|
29
|
-
*
|
|
30
|
-
*
|
|
21
|
+
* A run of characters on one line, measured. A mark is declared in characters,
|
|
22
|
+
* since that is how somebody reads a snippet, and drawn at whatever width the
|
|
23
|
+
* face gives them.
|
|
24
|
+
*/
|
|
25
|
+
function spanOf(found, length, lines, advance, color) {
|
|
26
|
+
const tokens = lines[found.line] ?? [];
|
|
27
|
+
const x = columnX(tokens, found.column, advance);
|
|
28
|
+
return {
|
|
29
|
+
line: found.line,
|
|
30
|
+
x,
|
|
31
|
+
width: columnX(tokens, found.column + length, advance) - x,
|
|
32
|
+
color,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Turn a declared mark into coordinates on the drawn snippet, or nothing where
|
|
37
|
+
* it names something the image does not show.
|
|
31
38
|
*
|
|
32
39
|
* A mark naming a line and no column is the whole line, which is the band an
|
|
33
40
|
* editor draws rather than a box around a word.
|
|
34
41
|
*/
|
|
35
|
-
export function locateMark(mark, lines) {
|
|
42
|
+
export function locateMark(mark, lines, advance) {
|
|
36
43
|
const color = mark.color;
|
|
37
44
|
if (mark.text !== undefined) {
|
|
38
45
|
const found = findText(mark.text, lines);
|
|
39
46
|
return found === undefined
|
|
40
47
|
? undefined
|
|
41
|
-
:
|
|
48
|
+
: spanOf(found, mark.length ?? mark.text.length, lines, advance, color);
|
|
42
49
|
}
|
|
43
50
|
const line = (mark.line ?? 0) - 1;
|
|
44
51
|
if (line < 0 || line >= lines.length) {
|
|
45
52
|
return undefined;
|
|
46
53
|
}
|
|
47
54
|
return mark.column === undefined
|
|
48
|
-
? { line,
|
|
49
|
-
: {
|
|
50
|
-
line,
|
|
51
|
-
column: mark.column - 1,
|
|
52
|
-
length: mark.length ?? 1,
|
|
53
|
-
color,
|
|
54
|
-
};
|
|
55
|
+
? { line, x: 0, width: undefined, color }
|
|
56
|
+
: spanOf({ line, column: mark.column - 1 }, mark.length ?? 1, lines, advance, color);
|
|
55
57
|
}
|
|
56
58
|
//# sourceMappingURL=locate.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"locate.js","sourceRoot":"","sources":["../../../../src/templates/code/mark/locate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"locate.js","sourceRoot":"","sources":["../../../../src/templates/code/mark/locate.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAcjD;;;;;;;;GAQG;AACH,SAAS,QAAQ,CACf,IAAY,EACZ,KAAwC;IAExC,KAAK,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC;QAC7C,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAE9C,IAAI,MAAM,KAAK,CAAC,CAAC,EAAE,CAAC;YAClB,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QAC1B,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;GAIG;AACH,SAAS,MAAM,CACb,KAAuC,EACvC,MAAc,EACd,KAAwC,EACxC,OAAgB,EAChB,KAAyB;IAEzB,MAAM,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;IACvC,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEjD,OAAO;QACL,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,CAAC;QACD,KAAK,EAAE,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC;QAC1D,KAAK;KACN,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CACxB,IA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