forwardfig 0.0.0-stage → 0.1.1
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 +162 -2
- package/dist/api.d.ts +410 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +24 -0
- package/dist/forwardfig.iife.js +481 -0
- package/dist/forwardfig.js +481 -0
- package/dist/index.d.ts +66 -0
- package/dist/layout.d.ts +17 -0
- package/dist/materials.d.ts +3 -0
- package/dist/render.d.ts +20 -0
- package/dist/tex.d.ts +37 -0
- package/dist/types.d.ts +57 -0
- package/package.json +46 -4
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import * as api from './api';
|
|
2
|
+
import { layout } from './layout';
|
|
3
|
+
import { THEMES } from './render';
|
|
4
|
+
import type { Diagram } from './types';
|
|
5
|
+
export * from './api';
|
|
6
|
+
export type { Diagram, Node, Edge, Group, Dir } from './types';
|
|
7
|
+
/** Drawing core: lay out and render a plain Diagram (what Figure.diagram() returns). */
|
|
8
|
+
export declare function draw(d: Diagram, options?: {
|
|
9
|
+
theme?: string;
|
|
10
|
+
materials?: boolean;
|
|
11
|
+
}): string;
|
|
12
|
+
export { layout, THEMES };
|
|
13
|
+
declare const _default: {
|
|
14
|
+
draw: typeof draw;
|
|
15
|
+
layout: typeof layout;
|
|
16
|
+
THEMES: Record<string, import("./render").Theme>;
|
|
17
|
+
layer<O extends api.NodeOptions>(shape: api.Shape, label: string, options: O, kind?: string, defaults?: api.NodeOptions): api.Layer<O>;
|
|
18
|
+
preset<O extends api.NodeOptions = api.NodeOptions>(shape: api.Shape, label?: string, defaults?: string | (api.NodeOptions & {
|
|
19
|
+
kind?: string;
|
|
20
|
+
})): api.Factory<O>;
|
|
21
|
+
vector(values: string[], a?: string | api.NodeOptions, b?: api.NodeOptions): api.Layer<api.NodeOptions>;
|
|
22
|
+
waveform(a?: string | api.WaveformOptions, b?: api.WaveformOptions): api.Layer<api.WaveformOptions>;
|
|
23
|
+
image(src: api.ImageSource | api.ImageSource[], a?: string | api.ImageOptions, b?: api.ImageOptions): api.Layer<api.ImageOptions>;
|
|
24
|
+
magnify(a?: string | api.MagnifyOptions, b?: api.MagnifyOptions): api.Layer<api.MagnifyOptions>;
|
|
25
|
+
matrix(a?: string | api.MatrixOptions, b?: api.MatrixOptions): api.Layer<api.MatrixOptions>;
|
|
26
|
+
voxels(a?: string | api.VoxelOptions, b?: api.VoxelOptions): api.Layer<api.VoxelOptions>;
|
|
27
|
+
configure(config: api.Config | null): api.FigureOptions;
|
|
28
|
+
figure(build: (fig: api.Figure) => unknown): api.Figure;
|
|
29
|
+
figure(options: api.FigureOptions, build: (fig: api.Figure) => unknown): api.Figure;
|
|
30
|
+
Graph: typeof api.Graph;
|
|
31
|
+
Tensor: typeof api.Tensor;
|
|
32
|
+
block: api.Factory<api.NodeOptions>;
|
|
33
|
+
thin: api.Factory<api.NodeOptions>;
|
|
34
|
+
text: api.Factory<api.NodeOptions>;
|
|
35
|
+
circle: api.Factory<api.NodeOptions>;
|
|
36
|
+
op: api.Factory<api.NodeOptions>;
|
|
37
|
+
enc: api.Factory<api.NodeOptions>;
|
|
38
|
+
dec: api.Factory<api.NodeOptions>;
|
|
39
|
+
tensor: api.Factory<api.TensorOptions>;
|
|
40
|
+
stack: api.Factory<api.StackOptions>;
|
|
41
|
+
neurons: api.Factory<api.NeuronOptions>;
|
|
42
|
+
mha: api.Factory<api.NodeOptions>;
|
|
43
|
+
attention: api.Factory<api.NodeOptions>;
|
|
44
|
+
ffn: api.Factory<api.NodeOptions>;
|
|
45
|
+
mlp: api.Factory<api.NodeOptions>;
|
|
46
|
+
norm: api.Factory<api.NodeOptions>;
|
|
47
|
+
embed: api.Factory<api.NodeOptions>;
|
|
48
|
+
linear: api.Factory<api.NodeOptions>;
|
|
49
|
+
softmax: api.Factory<api.NodeOptions>;
|
|
50
|
+
matmul: api.Factory<api.NodeOptions>;
|
|
51
|
+
concat: api.Factory<api.NodeOptions>;
|
|
52
|
+
conv: api.Factory<api.NodeOptions>;
|
|
53
|
+
pool: api.Factory<api.NodeOptions>;
|
|
54
|
+
act: api.Factory<api.NodeOptions>;
|
|
55
|
+
dropout: api.Factory<api.NodeOptions>;
|
|
56
|
+
loss: api.Factory<api.NodeOptions>;
|
|
57
|
+
gaussian: api.Factory<api.GaussianOptions>;
|
|
58
|
+
space: api.Factory<api.SpaceOptions>;
|
|
59
|
+
sphere: api.Factory<api.SphereOptions>;
|
|
60
|
+
pointcloud: api.Factory<api.PointCloudOptions>;
|
|
61
|
+
add: (...xs: api.Tensor[]) => api.Tensor;
|
|
62
|
+
mul: (...xs: api.Tensor[]) => api.Tensor;
|
|
63
|
+
Module: typeof api.Module;
|
|
64
|
+
Figure: typeof api.Figure;
|
|
65
|
+
};
|
|
66
|
+
export default _default;
|
package/dist/layout.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Diagram, Node } from './types';
|
|
2
|
+
export declare const FS = 13;
|
|
3
|
+
export declare const OUTSIDE: Set<string>;
|
|
4
|
+
export declare const values: (n: Node) => string[];
|
|
5
|
+
/** label size of a block: its own fontSize, else derived from the figure's base size */
|
|
6
|
+
export declare const labelSize: (n: Node, base: number) => number;
|
|
7
|
+
/**
|
|
8
|
+
* Linear part [a, b, c, d] of an image's transform (x' = a·x + c·y, y' = b·x + d·y).
|
|
9
|
+
* tilt: turn around the vertical axis, drawn obliquely (x shrinks, the far side rises,
|
|
10
|
+
* as depth does in an oblique drawing);
|
|
11
|
+
* rotate: in-plane. Both in degrees.
|
|
12
|
+
*/
|
|
13
|
+
export declare const imageMatrix: (attrs: Record<string, string>) => [number, number, number, number];
|
|
14
|
+
export declare const nums: (s: string | undefined, def: number[]) => number[];
|
|
15
|
+
export type Box = [number, number, number, number];
|
|
16
|
+
export declare const hits: (a: Box, b: Box) => boolean;
|
|
17
|
+
export declare function layout(d: Diagram): Diagram;
|
package/dist/render.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Diagram } from './types';
|
|
2
|
+
type Pair = [fill: string, stroke: string];
|
|
3
|
+
export interface Theme {
|
|
4
|
+
bg: string;
|
|
5
|
+
text: string;
|
|
6
|
+
sub: string;
|
|
7
|
+
edge: string;
|
|
8
|
+
halo: string;
|
|
9
|
+
group: Pair;
|
|
10
|
+
shadow: string;
|
|
11
|
+
dark: boolean;
|
|
12
|
+
/** blocks without a color: neutral grey, readable on light and dark pages */
|
|
13
|
+
none: Pair;
|
|
14
|
+
ice: [string, string, string, string];
|
|
15
|
+
fire: [string, string, string];
|
|
16
|
+
c: Record<string, Pair>;
|
|
17
|
+
}
|
|
18
|
+
export declare const THEMES: Record<string, Theme>;
|
|
19
|
+
export declare function render(d: Diagram, theme?: string, materials?: boolean): string;
|
|
20
|
+
export {};
|
package/dist/tex.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export declare const SANS = "Inter,\"Helvetica Neue\",Helvetica,Arial,sans-serif";
|
|
2
|
+
/** normal font weight, the default for labels */
|
|
3
|
+
export declare const REGULAR = 400;
|
|
4
|
+
export declare const SERIF = "\"Latin Modern Math\",\"STIX Two Math\",\"Cambria Math\",\"Times New Roman\",serif";
|
|
5
|
+
export interface Run {
|
|
6
|
+
t: string;
|
|
7
|
+
x: number;
|
|
8
|
+
dy: number;
|
|
9
|
+
size: number;
|
|
10
|
+
it: boolean;
|
|
11
|
+
b: boolean;
|
|
12
|
+
serif: boolean;
|
|
13
|
+
/** typeset math from the TeX engine: inner SVG markup, its viewBox, and its box around the baseline */
|
|
14
|
+
math?: {
|
|
15
|
+
inner: string;
|
|
16
|
+
viewBox: string;
|
|
17
|
+
w: number;
|
|
18
|
+
asc: number;
|
|
19
|
+
desc: number;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/** tex source → an <svg viewBox="..."> string, as MathJax's tex2svg produces (1000 viewBox units per em). */
|
|
23
|
+
export type TexEngine = (tex: string) => string;
|
|
24
|
+
/** Use a TeX engine (null = always the built-in fallback, undefined = auto-detect MathJax). */
|
|
25
|
+
export declare function setTex(e: TexEngine | null | undefined): void;
|
|
26
|
+
export interface TextBox {
|
|
27
|
+
lines: Run[][];
|
|
28
|
+
widths: number[];
|
|
29
|
+
w: number;
|
|
30
|
+
h: number;
|
|
31
|
+
lh: number;
|
|
32
|
+
size: number;
|
|
33
|
+
}
|
|
34
|
+
export declare function font(size: number, it: boolean, b: boolean | number, serif: boolean, family?: string): string;
|
|
35
|
+
export declare function measure(t: string, f: string, size: number): number;
|
|
36
|
+
/** Lay out a label: newline, `\\` or `<br>` break lines, `$...$` switches to math. */
|
|
37
|
+
export declare function layoutLabel(label: string, size: number, weight?: number, family?: string): TextBox;
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export type Dir = 'TB' | 'BT' | 'LR' | 'RL';
|
|
2
|
+
export interface Node {
|
|
3
|
+
id: string;
|
|
4
|
+
shape: string;
|
|
5
|
+
label: string;
|
|
6
|
+
color?: string;
|
|
7
|
+
flags: Set<string>;
|
|
8
|
+
attrs: Record<string, string>;
|
|
9
|
+
groups: string[];
|
|
10
|
+
order: number;
|
|
11
|
+
x: number;
|
|
12
|
+
y: number;
|
|
13
|
+
w: number;
|
|
14
|
+
h: number;
|
|
15
|
+
}
|
|
16
|
+
export interface Edge {
|
|
17
|
+
from: string;
|
|
18
|
+
to: string;
|
|
19
|
+
op: string;
|
|
20
|
+
label?: string;
|
|
21
|
+
flags: Set<string>;
|
|
22
|
+
attrs: Record<string, string>;
|
|
23
|
+
pts: [number, number][];
|
|
24
|
+
curve?: number;
|
|
25
|
+
fc?: boolean;
|
|
26
|
+
lx?: number;
|
|
27
|
+
ly?: number;
|
|
28
|
+
}
|
|
29
|
+
export interface Group {
|
|
30
|
+
id: string;
|
|
31
|
+
label: string;
|
|
32
|
+
parent?: string;
|
|
33
|
+
flags: Set<string>;
|
|
34
|
+
attrs: Record<string, string>;
|
|
35
|
+
x: number;
|
|
36
|
+
y: number;
|
|
37
|
+
w: number;
|
|
38
|
+
h: number;
|
|
39
|
+
}
|
|
40
|
+
export interface Diagram {
|
|
41
|
+
dir: Dir;
|
|
42
|
+
theme: string;
|
|
43
|
+
gap?: [number, number];
|
|
44
|
+
/** base text size (px); blocks may set attrs.fontSize */
|
|
45
|
+
fontSize?: number;
|
|
46
|
+
/** base CSS font family; blocks may set attrs.fontFamily */
|
|
47
|
+
fontFamily?: string;
|
|
48
|
+
/** a key to the looks the figure uses (frozen, trainable, textures, crossed); labels override the names */
|
|
49
|
+
legend?: {
|
|
50
|
+
position?: 'bottom' | 'right';
|
|
51
|
+
labels?: Partial<Record<string, string>>;
|
|
52
|
+
};
|
|
53
|
+
nodes: Map<string, Node>;
|
|
54
|
+
edges: Edge[];
|
|
55
|
+
groups: Group[];
|
|
56
|
+
ranks: string[][];
|
|
57
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,48 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "forwardfig",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Draw ML architecture figures in TypeScript, written the way you write the model. Zero dependencies, SVG out.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/forwardfig.js",
|
|
7
|
+
"module": "dist/forwardfig.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/forwardfig.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"bin": {
|
|
16
|
+
"forwardfig": "dist/cli.js"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "bun build src/index.ts --minify --outfile dist/forwardfig.js && bun build src/cli.ts --minify --target=node --external sharp --outfile dist/cli.js && bun build src/index.ts --minify --format=iife --outfile dist/forwardfig.iife.js && tsc --emitDeclarationOnly --declaration --outDir dist",
|
|
23
|
+
"test": "bun test",
|
|
24
|
+
"check": "tsc --noEmit",
|
|
25
|
+
"docs:build": "bun doc/site/build.mjs",
|
|
26
|
+
"docs:dev": "bun doc/site/build.mjs && bun doc/site/serve.mjs",
|
|
27
|
+
"prepublishOnly": "bun run check && bun test && bun run build"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/node": "^26.6.5",
|
|
31
|
+
"marked": "^18.1.1",
|
|
32
|
+
"sharp": "^0.35.5",
|
|
33
|
+
"typescript": "^5.6.0"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"sharp": ">=0.33"
|
|
37
|
+
},
|
|
38
|
+
"peerDependenciesMeta": {
|
|
39
|
+
"sharp": {
|
|
40
|
+
"optional": true
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"license": "MIT",
|
|
44
|
+
"repository": {
|
|
45
|
+
"type": "git",
|
|
46
|
+
"url": "git+https://github.com/frinfo702/forwardfig.git"
|
|
47
|
+
}
|
|
48
|
+
}
|