@markmap/render 0.0.0-stage → 1.0.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +4 -2
- package/dist/animate.d.ts +12 -0
- package/dist/content.d.ts +10 -0
- package/dist/default-plugins.d.ts +3 -0
- package/dist/image.d.ts +23 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +1984 -0
- package/dist/layouts/index.d.ts +3 -0
- package/dist/layouts/org-chart.d.ts +9 -0
- package/dist/layouts/tree.d.ts +7 -0
- package/dist/layouts/two-sided.d.ts +14 -0
- package/dist/measure.d.ts +11 -0
- package/dist/options.d.ts +33 -0
- package/dist/paint.d.ts +12 -0
- package/dist/render.d.ts +74 -0
- package/dist/svg.d.ts +31 -0
- package/dist/text.d.ts +20 -0
- package/dist/themes/branch.d.ts +22 -0
- package/dist/themes/cards.d.ts +6 -0
- package/dist/themes/classic.d.ts +6 -0
- package/dist/themes/minimal.d.ts +3 -0
- package/dist/themes/shared.d.ts +38 -0
- package/package.json +36 -3
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type Layout, type LayoutOptions, type LayoutResult, type MarkmapNode } from '@markmap/core';
|
|
2
|
+
/**
|
|
3
|
+
* Top-down tidy tree: the root at the top, children in a row below their parent.
|
|
4
|
+
* `levelGap` is the gap between levels; siblings are `siblingGap × 3`
|
|
5
|
+
* apart, doubled between cousins.
|
|
6
|
+
*/
|
|
7
|
+
export declare function layoutOrgChart(root: MarkmapNode, options: LayoutOptions): LayoutResult;
|
|
8
|
+
/** Org chart: root at the top, growing downwards. */
|
|
9
|
+
export declare const orgChartLayout: Layout;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type Layout, type LayoutOptions, type LayoutResult, type MarkmapNode } from '@markmap/core';
|
|
2
|
+
/** Return the subtree that is visible when the `folded` nodes are collapsed. */
|
|
3
|
+
export declare function visibleNodes(root: MarkmapNode, folded?: ReadonlySet<string>): MarkmapNode[];
|
|
4
|
+
/** Tidy tree layout, root on the left, growing to the right. */
|
|
5
|
+
export declare function layoutTree(root: MarkmapNode, options: LayoutOptions): LayoutResult;
|
|
6
|
+
/** The classic markmap layout: a tidy tree growing to the right. */
|
|
7
|
+
export declare const treeLayout: Layout;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type Layout, type LayoutOptions, type LayoutResult, type MarkmapNode } from '@markmap/core';
|
|
2
|
+
/**
|
|
3
|
+
* How many of the root's first children go on the right; the rest go on the left. Splits
|
|
4
|
+
* the list where the two sides' leaf counts are closest, keeping document order on both
|
|
5
|
+
* sides and favoring the right on a tie.
|
|
6
|
+
*/
|
|
7
|
+
export declare function splitBranches(children: readonly MarkmapNode[]): number;
|
|
8
|
+
/**
|
|
9
|
+
* A mind map: the root in the middle, its first branches growing to the right and the
|
|
10
|
+
* rest to the left, balanced by size. Both sides keep document order top to bottom.
|
|
11
|
+
*/
|
|
12
|
+
export declare function layoutTwoSided(root: MarkmapNode, options: LayoutOptions): LayoutResult;
|
|
13
|
+
/** Root in the middle, branches on both sides. */
|
|
14
|
+
export declare const twoSidedLayout: Layout;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { FontStyle, Measurer } from '@markmap/core';
|
|
2
|
+
export declare function fontToCss(font: FontStyle): string;
|
|
3
|
+
/**
|
|
4
|
+
* Approximates widths from Helvetica metrics, without a font or canvas. Good enough
|
|
5
|
+
* for Node rendering and tests; use {@link createCanvasMeasurer} in the browser.
|
|
6
|
+
*/
|
|
7
|
+
export declare const approximateMeasurer: Measurer;
|
|
8
|
+
type Context2D = Pick<CanvasRenderingContext2D, 'font' | 'measureText'>;
|
|
9
|
+
/** Measures with a canvas 2D context, caching results per font and text. */
|
|
10
|
+
export declare function createCanvasMeasurer(ctx?: Context2D): Measurer;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type Layout, type MarkmapJSONOptions, type Theme } from '@markmap/core';
|
|
2
|
+
import type { RenderOptions } from './render';
|
|
3
|
+
/** Layouts Markdown can pick by name with the `layout` option. */
|
|
4
|
+
export declare const builtinLayouts: Readonly<Record<string, Layout>>;
|
|
5
|
+
/** Themes Markdown can pick by name with the `theme` option. */
|
|
6
|
+
export declare const builtinThemes: Readonly<Record<string, Theme>>;
|
|
7
|
+
export interface ResolveOptions {
|
|
8
|
+
/** Layouts the `layout` option may name. Defaults to {@link builtinLayouts}. */
|
|
9
|
+
layouts?: Readonly<Record<string, Layout>>;
|
|
10
|
+
/** Themes the `theme` option may name. Defaults to {@link builtinThemes}. */
|
|
11
|
+
themes?: Readonly<Record<string, Theme>>;
|
|
12
|
+
}
|
|
13
|
+
export interface ResolvedOptions<T> {
|
|
14
|
+
options: T;
|
|
15
|
+
/** The validated theme-independent options, for callers that use more of them. */
|
|
16
|
+
json: MarkmapJSONOptions;
|
|
17
|
+
/** Problems with the input, one per ignored value or unknown key. */
|
|
18
|
+
warnings: string[];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Apply the theme's own options (for example `color`) and return the keys it did not
|
|
22
|
+
* claim. Themes without options leave everything in `rest`.
|
|
23
|
+
*/
|
|
24
|
+
export declare function configureTheme(theme: Theme, input: Record<string, unknown>): {
|
|
25
|
+
theme: Theme;
|
|
26
|
+
rest: Record<string, unknown>;
|
|
27
|
+
warnings: string[];
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Validate untrusted Markdown options (usually `frontmatter.markmap`) and apply them on
|
|
31
|
+
* top of `base`: shared keys first, then the theme's own keys. Anything left is reported.
|
|
32
|
+
*/
|
|
33
|
+
export declare function resolveRenderOptions<T extends Partial<RenderOptions>>(base: T, input: unknown, { layouts, themes }?: ResolveOptions): ResolvedOptions<T & Partial<RenderOptions>>;
|
package/dist/paint.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Paint, Theme } from '@markmap/core';
|
|
2
|
+
/** Finds a token's value by name, without the leading `--`. */
|
|
3
|
+
export type TokenLookup = Readonly<Record<string, string>> | ((name: string) => string | undefined);
|
|
4
|
+
/**
|
|
5
|
+
* Resolve CSS custom properties in a paint, for drawing outside CSS (canvas, PNG export).
|
|
6
|
+
* Every `var(--name)` and `var(--name, fallback)` is replaced by the token's value, which
|
|
7
|
+
* may refer to other tokens, or else by its fallback. Anything else is kept as is.
|
|
8
|
+
* Returns `undefined` when a variable has neither, or tokens refer to each other in a loop.
|
|
9
|
+
*/
|
|
10
|
+
export declare function resolvePaint(paint: Paint | undefined, tokens: TokenLookup): string | undefined;
|
|
11
|
+
/** A theme's tokens for one color scheme: dark tokens override light ones. */
|
|
12
|
+
export declare function themeTokens(theme: Pick<Theme, 'tokens' | 'darkTokens'>, scheme?: 'light' | 'dark'): Record<string, string>;
|
package/dist/render.d.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { type ContentPlugin, type FrameNode, type Layout, type LayoutResult, type Measurer, type MarkmapNode, type NodeContext, type Primitive, type Rect, type Size, type Theme } from '@markmap/core';
|
|
2
|
+
import { type TextLayout } from './text';
|
|
3
|
+
export interface RenderOptions {
|
|
4
|
+
measurer: Measurer;
|
|
5
|
+
theme?: Theme;
|
|
6
|
+
/** Where nodes go. Defaults to {@link treeLayout}. */
|
|
7
|
+
layout?: Layout;
|
|
8
|
+
/** Ids of collapsed nodes. */
|
|
9
|
+
folded?: ReadonlySet<string>;
|
|
10
|
+
/** Wrap labels wider than this, in px. `0` disables wrapping. */
|
|
11
|
+
wrapWidth?: number;
|
|
12
|
+
levelGap?: number;
|
|
13
|
+
siblingGap?: number;
|
|
14
|
+
/** Inline content renderers. Defaults to {@link defaultContentPlugins}. */
|
|
15
|
+
plugins?: readonly ContentPlugin[];
|
|
16
|
+
}
|
|
17
|
+
export interface RenderResult {
|
|
18
|
+
theme: Theme;
|
|
19
|
+
layout: LayoutResult;
|
|
20
|
+
/** Edges first, then nodes, so nodes draw on top. */
|
|
21
|
+
primitives: Primitive[];
|
|
22
|
+
/** Area covered by the drawing, including strokes and fold circles. */
|
|
23
|
+
bounds: Rect;
|
|
24
|
+
/** Theme context of every visible node, by id. */
|
|
25
|
+
contexts: Map<string, NodeContext>;
|
|
26
|
+
/** The final frame, as a starting point for animations. */
|
|
27
|
+
state: DrawState;
|
|
28
|
+
/**
|
|
29
|
+
* Settles when content that was measured with a placeholder (such as an image of
|
|
30
|
+
* unknown size) is ready. Render again then to get the final layout.
|
|
31
|
+
*/
|
|
32
|
+
pending?: Promise<void>;
|
|
33
|
+
}
|
|
34
|
+
export interface MeasuredNode {
|
|
35
|
+
text: TextLayout;
|
|
36
|
+
box: Size;
|
|
37
|
+
}
|
|
38
|
+
/** Ids from the root to every node, both included. */
|
|
39
|
+
export declare function nodePaths(root: MarkmapNode): Map<string, readonly string[]>;
|
|
40
|
+
/**
|
|
41
|
+
* Measure the label and box of every visible node. Content that is not ready yet (see
|
|
42
|
+
* {@link InlineContext.defer}) is reported to `defer`.
|
|
43
|
+
*/
|
|
44
|
+
export declare function measureTree(root: MarkmapNode, options: RenderOptions, defer?: (task: Promise<unknown>) => void): Map<string, MeasuredNode>;
|
|
45
|
+
/** Measure, lay out and draw a tree as backend-neutral primitives. */
|
|
46
|
+
export declare function renderTree(root: MarkmapNode, options: RenderOptions): RenderResult;
|
|
47
|
+
/**
|
|
48
|
+
* Render, wait for content that was measured with a placeholder, and render again, until
|
|
49
|
+
* everything is final (at most `rounds` times). Useful outside a live view, e.g. for
|
|
50
|
+
* exporting SVG with images.
|
|
51
|
+
*/
|
|
52
|
+
export declare function renderTreeAsync(root: MarkmapNode, options: RenderOptions, rounds?: number): Promise<RenderResult>;
|
|
53
|
+
/** A node as drawn in one frame: final, or somewhere along an animation. */
|
|
54
|
+
export interface DrawNode extends FrameNode {
|
|
55
|
+
/** Parent in the same state; nodes without one get no edge. */
|
|
56
|
+
parentId?: string;
|
|
57
|
+
text: TextLayout;
|
|
58
|
+
}
|
|
59
|
+
/** Everything needed to draw one frame. Parents come before their children. */
|
|
60
|
+
export interface DrawState {
|
|
61
|
+
nodes: DrawNode[];
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Draw a state as primitives: edges first, then nodes, each in a keyed group so
|
|
65
|
+
* backends can patch them. Edge anchors come from the theme, so animating node rects
|
|
66
|
+
* moves edges along with them.
|
|
67
|
+
*/
|
|
68
|
+
export declare function drawState(state: DrawState, theme: Theme): Primitive[];
|
|
69
|
+
/**
|
|
70
|
+
* Bounding box of rects, paths and images, including stroke widths. Curve control
|
|
71
|
+
* points are included, so curves give a safe over-estimate. Text is not included:
|
|
72
|
+
* it sits inside node boxes, which callers add from the layout.
|
|
73
|
+
*/
|
|
74
|
+
export declare function primitiveBounds(primitives: Primitive[]): Rect;
|
package/dist/svg.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type Primitive, type Theme } from '@markmap/core';
|
|
2
|
+
import type { RenderResult } from './render';
|
|
3
|
+
export interface SVGStringOptions {
|
|
4
|
+
/** Space around the drawing, in px. */
|
|
5
|
+
padding?: number;
|
|
6
|
+
/** Fill the background with `--mm-bg`. */
|
|
7
|
+
background?: boolean;
|
|
8
|
+
/** Which tokens to use. Defaults to `light`. */
|
|
9
|
+
colorScheme?: ColorScheme;
|
|
10
|
+
}
|
|
11
|
+
/** `auto` follows the reader's `prefers-color-scheme`. */
|
|
12
|
+
export type ColorScheme = 'light' | 'dark' | 'auto';
|
|
13
|
+
export declare function escapeXml(value: string): string;
|
|
14
|
+
export interface PrimitivesToSVGOptions {
|
|
15
|
+
/** Emit hit areas for view actions. Off for exports. */
|
|
16
|
+
interactive?: boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Serialize primitives as SVG markup. Primitive lists are treated as immutable: the
|
|
20
|
+
* markup of each list is cached, which makes redrawing animation frames cheap.
|
|
21
|
+
*/
|
|
22
|
+
export declare function primitivesToSVG(primitives: Primitive[], options?: PrimitivesToSVGOptions): string;
|
|
23
|
+
/** Theme tokens as CSS custom property declarations. */
|
|
24
|
+
export declare function tokensToCSS(theme: Theme | Record<string, string>): string;
|
|
25
|
+
/**
|
|
26
|
+
* Rules that set a theme's tokens on `selector`. Dark tokens override light ones for
|
|
27
|
+
* `dark`, and inside a `prefers-color-scheme: dark` query for `auto`.
|
|
28
|
+
*/
|
|
29
|
+
export declare function themeCSS(theme: Theme, colorScheme?: ColorScheme, selector?: string): string;
|
|
30
|
+
/** A standalone SVG document. Theme tokens are embedded so user CSS can still override them. */
|
|
31
|
+
export declare function toSVGString(result: RenderResult, options?: SVGStringOptions): string;
|
package/dist/text.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ContentPlugin, Inline, InlineContext, Primitive, Size, TextRun, TextAlign, TextStyle } from '@markmap/core';
|
|
2
|
+
export interface TextLayout extends Size {
|
|
3
|
+
/** Backgrounds, text, strike lines, atoms and link areas, in text coordinates. */
|
|
4
|
+
primitives: Primitive[];
|
|
5
|
+
runs: TextRun[];
|
|
6
|
+
lines: number;
|
|
7
|
+
}
|
|
8
|
+
export interface TextLayoutOptions {
|
|
9
|
+
style: TextStyle;
|
|
10
|
+
/** Wrap lines longer than this, in px. `0` or less disables wrapping. */
|
|
11
|
+
wrapWidth?: number;
|
|
12
|
+
plugins: readonly ContentPlugin[];
|
|
13
|
+
ctx: InlineContext;
|
|
14
|
+
/** Alignment of lines within the widest one. Defaults to `start`. */
|
|
15
|
+
align?: TextAlign;
|
|
16
|
+
}
|
|
17
|
+
/** Apply plugin transforms to a node's content, in plugin order. */
|
|
18
|
+
export declare function transformContent(plugins: readonly ContentPlugin[], ctx: InlineContext): Inline[];
|
|
19
|
+
/** Lay out inline content into runs, decorations and atoms, wrapping at `wrapWidth`. */
|
|
20
|
+
export declare function layoutText(content: readonly Inline[], options: TextLayoutOptions): TextLayout;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pick a color index for a node from its path of ids, for themes that color by branch.
|
|
3
|
+
* The node's id is hashed, so colors stay put as the tree changes. With `colorDepth`
|
|
4
|
+
* (the root is level 1), nodes deeper than that level use their ancestor's id instead.
|
|
5
|
+
*/
|
|
6
|
+
export declare function branchIndex(path: readonly string[], count: number, colorDepth?: number): number;
|
|
7
|
+
/** The d3 category10 palette, used by the built-in themes. */
|
|
8
|
+
export declare const DEFAULT_COLORS: readonly string[];
|
|
9
|
+
/** Options shared by themes that color by branch. */
|
|
10
|
+
export interface BranchColorOptions {
|
|
11
|
+
/** Branch colors, cycled through. One color paints every branch the same. */
|
|
12
|
+
color?: string[];
|
|
13
|
+
/** Nodes deeper than this level (the root is level 1) take their ancestor's color. `0` disables. */
|
|
14
|
+
colorDepth?: number;
|
|
15
|
+
}
|
|
16
|
+
/** Branch color tokens and a lookup from a node's path to its `var(--mm-branch-N)`. */
|
|
17
|
+
export declare function branchColors(options: BranchColorOptions): {
|
|
18
|
+
tokens: {
|
|
19
|
+
[k: string]: string;
|
|
20
|
+
};
|
|
21
|
+
colorOf: (path: readonly string[]) => string;
|
|
22
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type Theme } from '@markmap/core';
|
|
2
|
+
import { type BranchColorOptions } from './branch';
|
|
3
|
+
export type CardsThemeOptions = BranchColorOptions;
|
|
4
|
+
/** Each node in a rounded card outlined in its branch color. */
|
|
5
|
+
export declare function createCardsTheme(options?: CardsThemeOptions): Theme;
|
|
6
|
+
export declare const cardsTheme: Theme;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Theme } from '@markmap/core';
|
|
2
|
+
import { type BranchColorOptions } from './branch';
|
|
3
|
+
export type ClassicThemeOptions = BranchColorOptions;
|
|
4
|
+
/** The original markmap look: underlined labels, curved edges and fold circles. */
|
|
5
|
+
export declare function createClassicTheme(options?: ClassicThemeOptions): Theme;
|
|
6
|
+
export declare const classicTheme: Theme;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Anchor, Point, Side, TextAlign, Theme } from '@markmap/core';
|
|
2
|
+
/** Tokens for inline content, shared by the built-in themes. */
|
|
3
|
+
export declare const CONTENT_TOKENS: {
|
|
4
|
+
'mm-link': string;
|
|
5
|
+
'mm-code-bg': string;
|
|
6
|
+
'mm-code-text': string;
|
|
7
|
+
'mm-mark-bg': string;
|
|
8
|
+
'mm-checkbox': string;
|
|
9
|
+
'mm-note-dot': string;
|
|
10
|
+
'mm-syntax-keyword': string;
|
|
11
|
+
'mm-syntax-string': string;
|
|
12
|
+
'mm-syntax-comment': string;
|
|
13
|
+
'mm-syntax-number': string;
|
|
14
|
+
'mm-syntax-title': string;
|
|
15
|
+
'mm-syntax-attr': string;
|
|
16
|
+
};
|
|
17
|
+
export declare const DARK_CONTENT_TOKENS: {
|
|
18
|
+
'mm-link': string;
|
|
19
|
+
'mm-code-bg': string;
|
|
20
|
+
'mm-code-text': string;
|
|
21
|
+
'mm-mark-bg': string;
|
|
22
|
+
'mm-checkbox': string;
|
|
23
|
+
'mm-note-dot': string;
|
|
24
|
+
'mm-syntax-keyword': string;
|
|
25
|
+
'mm-syntax-string': string;
|
|
26
|
+
'mm-syntax-comment': string;
|
|
27
|
+
'mm-syntax-number': string;
|
|
28
|
+
'mm-syntax-title': string;
|
|
29
|
+
'mm-syntax-attr': string;
|
|
30
|
+
};
|
|
31
|
+
export declare const SYSTEM_FONT: Theme['font'];
|
|
32
|
+
export declare const CODE_FONT = "ui-monospace, SFMono-Regular, Menlo, Consolas, monospace";
|
|
33
|
+
/** Wrapped lines hug the edge that faces the parent. */
|
|
34
|
+
export declare function alignFor(direction: Side): TextAlign;
|
|
35
|
+
/** An S-curve that leaves and arrives along the anchors' axis. */
|
|
36
|
+
export declare function sCurve(from: Anchor, to: Point): string;
|
|
37
|
+
/** The middle of one side of a box at (0, 0), pushed `gap` px outwards. */
|
|
38
|
+
export declare function sidePoint(width: number, height: number, side: Side, gap?: number): Point;
|
package/package.json
CHANGED
|
@@ -1,6 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markmap/render",
|
|
3
|
-
"version": "0.0.0
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.0.0-next.0",
|
|
4
|
+
"description": "Measure, lay out and render Markmap trees to primitives and SVG",
|
|
5
|
+
"homepage": "https://github.com/markmap/markmap#readme",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/markmap/markmap.git",
|
|
10
|
+
"directory": "packages/render"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"type": "module",
|
|
16
|
+
"sideEffects": false,
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"import": "./dist/index.js"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@markmap/core": "1.0.0-next.0",
|
|
28
|
+
"d3-flextree": "^2.1.2"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@markmap/parse": "1.0.0-next.0",
|
|
32
|
+
"@types/d3-flextree": "^2.1.4"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"clean": "rm -rf dist tsconfig.tsbuildinfo",
|
|
36
|
+
"build:types": "tsc -b",
|
|
37
|
+
"build:js": "vite build"
|
|
38
|
+
}
|
|
6
39
|
}
|