@formepdf/shared 0.11.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 +7 -0
- package/dist/canvas.d.ts +6 -0
- package/dist/canvas.js +43 -0
- package/dist/charts.d.ts +100 -0
- package/dist/charts.js +98 -0
- package/dist/font.d.ts +13 -0
- package/dist/font.js +52 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +10 -0
- package/dist/semantics.d.ts +15 -0
- package/dist/semantics.js +44 -0
- package/dist/style.d.ts +7 -0
- package/dist/style.js +1024 -0
- package/dist/types.d.ts +743 -0
- package/dist/types.js +2 -0
- package/package.json +30 -0
package/README.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# @formepdf/shared
|
|
2
|
+
|
|
3
|
+
Framework-agnostic core shared by Forme's authoring adapters (`@formepdf/react`, and future adapters): the Forme document-model types, the `Style` type and its mapping to engine JSON (including CSS string shorthands), color/dimension/edge/corner parsing, custom font registration and merging, and the `<Canvas>` operation recorder.
|
|
4
|
+
|
|
5
|
+
Plain data in → document model out. No framework dependencies.
|
|
6
|
+
|
|
7
|
+
You normally don't install this package directly — it comes in as a dependency of an adapter, which re-exports everything user-facing.
|
package/dist/canvas.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { CanvasContext, CanvasOp } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Execute a <Canvas> draw callback against a recording context, capturing
|
|
4
|
+
* the drawing calls as a serializable CanvasOp list.
|
|
5
|
+
*/
|
|
6
|
+
export declare function recordCanvasOperations(draw: (ctx: CanvasContext) => void): CanvasOp[];
|
package/dist/canvas.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Execute a <Canvas> draw callback against a recording context, capturing
|
|
3
|
+
* the drawing calls as a serializable CanvasOp list.
|
|
4
|
+
*/
|
|
5
|
+
export function recordCanvasOperations(draw) {
|
|
6
|
+
const operations = [];
|
|
7
|
+
// Create a recording context that captures draw calls as CanvasOp[]
|
|
8
|
+
const ctx = {
|
|
9
|
+
moveTo(x, y) { operations.push({ op: 'MoveTo', x, y }); },
|
|
10
|
+
lineTo(x, y) { operations.push({ op: 'LineTo', x, y }); },
|
|
11
|
+
bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y) {
|
|
12
|
+
operations.push({ op: 'BezierCurveTo', cp1x, cp1y, cp2x, cp2y, x, y });
|
|
13
|
+
},
|
|
14
|
+
quadraticCurveTo(cpx, cpy, x, y) {
|
|
15
|
+
operations.push({ op: 'QuadraticCurveTo', cpx, cpy, x, y });
|
|
16
|
+
},
|
|
17
|
+
closePath() { operations.push({ op: 'ClosePath' }); },
|
|
18
|
+
rect(x, y, w, h) { operations.push({ op: 'Rect', x, y, width: w, height: h }); },
|
|
19
|
+
circle(cx, cy, r) { operations.push({ op: 'Circle', cx, cy, r }); },
|
|
20
|
+
ellipse(cx, cy, rx, ry) { operations.push({ op: 'Ellipse', cx, cy, rx, ry }); },
|
|
21
|
+
arc(cx, cy, r, startAngle, endAngle, counterclockwise = false) {
|
|
22
|
+
operations.push({ op: 'Arc', cx, cy, r, start_angle: startAngle, end_angle: endAngle, counterclockwise });
|
|
23
|
+
},
|
|
24
|
+
line(x1, y1, x2, y2) {
|
|
25
|
+
operations.push({ op: 'MoveTo', x: x1, y: y1 });
|
|
26
|
+
operations.push({ op: 'LineTo', x: x2, y: y2 });
|
|
27
|
+
operations.push({ op: 'Stroke' });
|
|
28
|
+
},
|
|
29
|
+
stroke() { operations.push({ op: 'Stroke' }); },
|
|
30
|
+
fill() { operations.push({ op: 'Fill' }); },
|
|
31
|
+
fillAndStroke() { operations.push({ op: 'FillAndStroke' }); },
|
|
32
|
+
setFillColor(r, g, b) { operations.push({ op: 'SetFillColor', r, g, b }); },
|
|
33
|
+
setStrokeColor(r, g, b) { operations.push({ op: 'SetStrokeColor', r, g, b }); },
|
|
34
|
+
setLineWidth(w) { operations.push({ op: 'SetLineWidth', width: w }); },
|
|
35
|
+
setLineCap(cap) { operations.push({ op: 'SetLineCap', cap }); },
|
|
36
|
+
setLineJoin(join) { operations.push({ op: 'SetLineJoin', join }); },
|
|
37
|
+
save() { operations.push({ op: 'Save' }); },
|
|
38
|
+
restore() { operations.push({ op: 'Restore' }); },
|
|
39
|
+
};
|
|
40
|
+
// Execute the draw callback to record operations
|
|
41
|
+
draw(ctx);
|
|
42
|
+
return operations;
|
|
43
|
+
}
|
package/dist/charts.d.ts
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chart prop types and document-model kind builders shared by the
|
|
3
|
+
* authoring adapters.
|
|
4
|
+
*
|
|
5
|
+
* The camelCase-to-snake_case prop mapping, including every default,
|
|
6
|
+
* lives here so the adapters cannot drift: react and svelte both
|
|
7
|
+
* serialize a chart by calling the same builder. Adapters remain
|
|
8
|
+
* responsible for style mapping (`mapStyle`) and any adapter-specific
|
|
9
|
+
* envelope (source locations, children).
|
|
10
|
+
*/
|
|
11
|
+
import type { ChartDataPoint, ChartSeries, DotPlotGroup, FormeNodeKind, Style } from './types.js';
|
|
12
|
+
export interface BarChartProps {
|
|
13
|
+
width: number;
|
|
14
|
+
height: number;
|
|
15
|
+
data: ChartDataPoint[];
|
|
16
|
+
/** Bar color. Default: "#1a365d". */
|
|
17
|
+
color?: string;
|
|
18
|
+
/** Show X-axis labels below bars. Default: true. */
|
|
19
|
+
showLabels?: boolean;
|
|
20
|
+
/** Show horizontal grid lines. Default: false. */
|
|
21
|
+
showGrid?: boolean;
|
|
22
|
+
/** Show value labels above bars. Default: false. */
|
|
23
|
+
showValues?: boolean;
|
|
24
|
+
/** Chart title. */
|
|
25
|
+
title?: string;
|
|
26
|
+
style?: Style;
|
|
27
|
+
}
|
|
28
|
+
export interface LineChartProps {
|
|
29
|
+
width: number;
|
|
30
|
+
height: number;
|
|
31
|
+
/** Multi-series data. */
|
|
32
|
+
series: ChartSeries[];
|
|
33
|
+
/** X-axis labels. */
|
|
34
|
+
labels: string[];
|
|
35
|
+
/** Show dots at data points. Default: false. */
|
|
36
|
+
showPoints?: boolean;
|
|
37
|
+
/** Show horizontal grid lines. Default: false. */
|
|
38
|
+
showGrid?: boolean;
|
|
39
|
+
/** Chart title. */
|
|
40
|
+
title?: string;
|
|
41
|
+
style?: Style;
|
|
42
|
+
}
|
|
43
|
+
export interface PieChartProps {
|
|
44
|
+
width: number;
|
|
45
|
+
height: number;
|
|
46
|
+
data: ChartDataPoint[];
|
|
47
|
+
/** Render as donut chart. Default: false. */
|
|
48
|
+
donut?: boolean;
|
|
49
|
+
/** Show legend. Default: false. */
|
|
50
|
+
showLegend?: boolean;
|
|
51
|
+
/** Chart title. */
|
|
52
|
+
title?: string;
|
|
53
|
+
style?: Style;
|
|
54
|
+
}
|
|
55
|
+
export interface AreaChartProps {
|
|
56
|
+
width: number;
|
|
57
|
+
height: number;
|
|
58
|
+
/** Multi-series data. */
|
|
59
|
+
series: ChartSeries[];
|
|
60
|
+
/** X-axis labels. */
|
|
61
|
+
labels: string[];
|
|
62
|
+
/** Show horizontal grid lines. Default: false. */
|
|
63
|
+
showGrid?: boolean;
|
|
64
|
+
/** Chart title. */
|
|
65
|
+
title?: string;
|
|
66
|
+
style?: Style;
|
|
67
|
+
}
|
|
68
|
+
export interface DotPlotProps {
|
|
69
|
+
width: number;
|
|
70
|
+
height: number;
|
|
71
|
+
/** Groups of (x, y) data points. */
|
|
72
|
+
groups: DotPlotGroup[];
|
|
73
|
+
/** Minimum X value. Auto-computed if omitted. */
|
|
74
|
+
xMin?: number;
|
|
75
|
+
/** Maximum X value. Auto-computed if omitted. */
|
|
76
|
+
xMax?: number;
|
|
77
|
+
/** Minimum Y value. Auto-computed if omitted. */
|
|
78
|
+
yMin?: number;
|
|
79
|
+
/** Maximum Y value. Auto-computed if omitted. */
|
|
80
|
+
yMax?: number;
|
|
81
|
+
/** X-axis label. */
|
|
82
|
+
xLabel?: string;
|
|
83
|
+
/** Y-axis label. */
|
|
84
|
+
yLabel?: string;
|
|
85
|
+
/** Show legend. Default: false. */
|
|
86
|
+
showLegend?: boolean;
|
|
87
|
+
/** Dot radius in points. Default: 4. */
|
|
88
|
+
dotSize?: number;
|
|
89
|
+
style?: Style;
|
|
90
|
+
}
|
|
91
|
+
/** Build the document-model kind for a `<BarChart>`. */
|
|
92
|
+
export declare function buildBarChartKind(props: BarChartProps): FormeNodeKind;
|
|
93
|
+
/** Build the document-model kind for a `<LineChart>`. */
|
|
94
|
+
export declare function buildLineChartKind(props: LineChartProps): FormeNodeKind;
|
|
95
|
+
/** Build the document-model kind for a `<PieChart>`. */
|
|
96
|
+
export declare function buildPieChartKind(props: PieChartProps): FormeNodeKind;
|
|
97
|
+
/** Build the document-model kind for an `<AreaChart>`. */
|
|
98
|
+
export declare function buildAreaChartKind(props: AreaChartProps): FormeNodeKind;
|
|
99
|
+
/** Build the document-model kind for a `<DotPlot>`. */
|
|
100
|
+
export declare function buildDotPlotKind(props: DotPlotProps): FormeNodeKind;
|
package/dist/charts.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chart prop types and document-model kind builders shared by the
|
|
3
|
+
* authoring adapters.
|
|
4
|
+
*
|
|
5
|
+
* The camelCase-to-snake_case prop mapping, including every default,
|
|
6
|
+
* lives here so the adapters cannot drift: react and svelte both
|
|
7
|
+
* serialize a chart by calling the same builder. Adapters remain
|
|
8
|
+
* responsible for style mapping (`mapStyle`) and any adapter-specific
|
|
9
|
+
* envelope (source locations, children).
|
|
10
|
+
*/
|
|
11
|
+
/** Copy data points so the kind owns plain data (per-datum color stays optional). */
|
|
12
|
+
function mapDataPoints(data) {
|
|
13
|
+
return data.map(d => ({ label: d.label, value: d.value, color: d.color }));
|
|
14
|
+
}
|
|
15
|
+
/** Build the document-model kind for a `<BarChart>`. */
|
|
16
|
+
export function buildBarChartKind(props) {
|
|
17
|
+
const kind = {
|
|
18
|
+
type: 'BarChart',
|
|
19
|
+
data: mapDataPoints(props.data),
|
|
20
|
+
width: props.width,
|
|
21
|
+
height: props.height,
|
|
22
|
+
show_labels: props.showLabels ?? true,
|
|
23
|
+
show_values: props.showValues ?? false,
|
|
24
|
+
show_grid: props.showGrid ?? false,
|
|
25
|
+
};
|
|
26
|
+
if (props.color !== undefined)
|
|
27
|
+
kind.color = props.color;
|
|
28
|
+
if (props.title !== undefined)
|
|
29
|
+
kind.title = props.title;
|
|
30
|
+
return kind;
|
|
31
|
+
}
|
|
32
|
+
/** Build the document-model kind for a `<LineChart>`. */
|
|
33
|
+
export function buildLineChartKind(props) {
|
|
34
|
+
const kind = {
|
|
35
|
+
type: 'LineChart',
|
|
36
|
+
series: props.series.map(s => ({ name: s.name, data: s.data, color: s.color })),
|
|
37
|
+
labels: props.labels,
|
|
38
|
+
width: props.width,
|
|
39
|
+
height: props.height,
|
|
40
|
+
show_points: props.showPoints ?? false,
|
|
41
|
+
show_grid: props.showGrid ?? false,
|
|
42
|
+
};
|
|
43
|
+
if (props.title !== undefined)
|
|
44
|
+
kind.title = props.title;
|
|
45
|
+
return kind;
|
|
46
|
+
}
|
|
47
|
+
/** Build the document-model kind for a `<PieChart>`. */
|
|
48
|
+
export function buildPieChartKind(props) {
|
|
49
|
+
const kind = {
|
|
50
|
+
type: 'PieChart',
|
|
51
|
+
data: mapDataPoints(props.data),
|
|
52
|
+
width: props.width,
|
|
53
|
+
height: props.height,
|
|
54
|
+
donut: props.donut ?? false,
|
|
55
|
+
show_legend: props.showLegend ?? false,
|
|
56
|
+
};
|
|
57
|
+
if (props.title !== undefined)
|
|
58
|
+
kind.title = props.title;
|
|
59
|
+
return kind;
|
|
60
|
+
}
|
|
61
|
+
/** Build the document-model kind for an `<AreaChart>`. */
|
|
62
|
+
export function buildAreaChartKind(props) {
|
|
63
|
+
const kind = {
|
|
64
|
+
type: 'AreaChart',
|
|
65
|
+
series: props.series.map(s => ({ name: s.name, data: s.data, color: s.color })),
|
|
66
|
+
labels: props.labels,
|
|
67
|
+
width: props.width,
|
|
68
|
+
height: props.height,
|
|
69
|
+
show_grid: props.showGrid ?? false,
|
|
70
|
+
};
|
|
71
|
+
if (props.title !== undefined)
|
|
72
|
+
kind.title = props.title;
|
|
73
|
+
return kind;
|
|
74
|
+
}
|
|
75
|
+
/** Build the document-model kind for a `<DotPlot>`. */
|
|
76
|
+
export function buildDotPlotKind(props) {
|
|
77
|
+
const kind = {
|
|
78
|
+
type: 'DotPlot',
|
|
79
|
+
groups: props.groups.map(g => ({ name: g.name, color: g.color, data: g.data })),
|
|
80
|
+
width: props.width,
|
|
81
|
+
height: props.height,
|
|
82
|
+
show_legend: props.showLegend ?? false,
|
|
83
|
+
dot_size: props.dotSize ?? 4,
|
|
84
|
+
};
|
|
85
|
+
if (props.xMin !== undefined)
|
|
86
|
+
kind.x_min = props.xMin;
|
|
87
|
+
if (props.xMax !== undefined)
|
|
88
|
+
kind.x_max = props.xMax;
|
|
89
|
+
if (props.yMin !== undefined)
|
|
90
|
+
kind.y_min = props.yMin;
|
|
91
|
+
if (props.yMax !== undefined)
|
|
92
|
+
kind.y_max = props.yMax;
|
|
93
|
+
if (props.xLabel !== undefined)
|
|
94
|
+
kind.x_label = props.xLabel;
|
|
95
|
+
if (props.yLabel !== undefined)
|
|
96
|
+
kind.y_label = props.yLabel;
|
|
97
|
+
return kind;
|
|
98
|
+
}
|
package/dist/font.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { FormeFont } from './types.js';
|
|
2
|
+
export interface FontRegistration {
|
|
3
|
+
family: string;
|
|
4
|
+
src: string | Uint8Array;
|
|
5
|
+
fontWeight?: number | 'normal' | 'bold';
|
|
6
|
+
fontStyle?: 'normal' | 'italic' | 'oblique';
|
|
7
|
+
}
|
|
8
|
+
export declare const Font: {
|
|
9
|
+
register(options: FontRegistration): void;
|
|
10
|
+
clear(): void;
|
|
11
|
+
getRegistered(): FontRegistration[];
|
|
12
|
+
};
|
|
13
|
+
export declare function mergeFonts(globalFonts: FontRegistration[], docFonts?: FontRegistration[]): FormeFont[];
|
package/dist/font.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
const globalFonts = [];
|
|
2
|
+
function normalizeWeight(w) {
|
|
3
|
+
if (w === undefined || w === 'normal')
|
|
4
|
+
return 400;
|
|
5
|
+
if (w === 'bold')
|
|
6
|
+
return 700;
|
|
7
|
+
return typeof w === 'number' ? w : (parseInt(w, 10) || 400);
|
|
8
|
+
}
|
|
9
|
+
export const Font = {
|
|
10
|
+
register(options) {
|
|
11
|
+
globalFonts.push({
|
|
12
|
+
...options,
|
|
13
|
+
fontWeight: normalizeWeight(options.fontWeight),
|
|
14
|
+
fontStyle: options.fontStyle || 'normal',
|
|
15
|
+
});
|
|
16
|
+
},
|
|
17
|
+
clear() {
|
|
18
|
+
globalFonts.length = 0;
|
|
19
|
+
},
|
|
20
|
+
getRegistered() {
|
|
21
|
+
return [...globalFonts];
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
// ─── Font merging ─────────────────────────────────────────────────
|
|
25
|
+
function normalizeFontWeight(w) {
|
|
26
|
+
if (w === undefined || w === 'normal')
|
|
27
|
+
return 400;
|
|
28
|
+
if (w === 'bold')
|
|
29
|
+
return 700;
|
|
30
|
+
return typeof w === 'number' ? w : (parseInt(w, 10) || 400);
|
|
31
|
+
}
|
|
32
|
+
function fontKey(family, weight, italic) {
|
|
33
|
+
return `${family}:${weight}:${italic}`;
|
|
34
|
+
}
|
|
35
|
+
export function mergeFonts(globalFonts, docFonts) {
|
|
36
|
+
const map = new Map();
|
|
37
|
+
for (const f of globalFonts) {
|
|
38
|
+
const weight = normalizeFontWeight(f.fontWeight);
|
|
39
|
+
const italic = f.fontStyle === 'italic' || f.fontStyle === 'oblique';
|
|
40
|
+
const key = fontKey(f.family, weight, italic);
|
|
41
|
+
map.set(key, { family: f.family, src: f.src, weight, italic });
|
|
42
|
+
}
|
|
43
|
+
if (docFonts) {
|
|
44
|
+
for (const f of docFonts) {
|
|
45
|
+
const weight = normalizeFontWeight(f.fontWeight);
|
|
46
|
+
const italic = f.fontStyle === 'italic' || f.fontStyle === 'oblique';
|
|
47
|
+
const key = fontKey(f.family, weight, italic);
|
|
48
|
+
map.set(key, { family: f.family, src: f.src, weight, italic });
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return Array.from(map.values());
|
|
52
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { mapStyle, mapDimension, parseColor, expandEdges, expandCorners, mapColumnWidth } from './style.js';
|
|
2
|
+
export { Font, mergeFonts } from './font.js';
|
|
3
|
+
export type { FontRegistration } from './font.js';
|
|
4
|
+
export { recordCanvasOperations } from './canvas.js';
|
|
5
|
+
export { STRONG_DEFAULTS, EM_DEFAULTS, CODE_DEFAULTS, LINK_DEFAULTS, HEADING_DEFAULTS, mapListMarker, } from './semantics.js';
|
|
6
|
+
export { buildBarChartKind, buildLineChartKind, buildPieChartKind, buildAreaChartKind, buildDotPlotKind, } from './charts.js';
|
|
7
|
+
export type { BarChartProps, LineChartProps, PieChartProps, AreaChartProps, DotPlotProps, } from './charts.js';
|
|
8
|
+
export type { Style, GridTrackSize, Edges, Corners, EdgeColors, CertificationConfig, SignatureConfig, ColumnDef, BarcodeFormat, ChartDataPoint, PieDataPoint, ChartSeries, DotPlotGroup, CanvasContext, CanvasOp, TextRun, ListMarker, FormeDocument, FormeFont, FormeNode, FormeNodeKind, FormeStyle, FormeMetadata, FormePageConfig, FormePageSize, FormeEdges, FormeBoxShadow, FormeGradientStop, FormeBackground, FormeMarginEdges, FormeColumnDef, FormeColumnWidth, FormeDimension, FormeColor, FormeEdgeValues, FormeCornerValues, FormeGridTrackSize, FormeGridPlacement, FormeListMarkerType, FormeTransformOp, } from './types.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Style mapping
|
|
2
|
+
export { mapStyle, mapDimension, parseColor, expandEdges, expandCorners, mapColumnWidth } from './style.js';
|
|
3
|
+
// Font registration
|
|
4
|
+
export { Font, mergeFonts } from './font.js';
|
|
5
|
+
// Canvas recording
|
|
6
|
+
export { recordCanvasOperations } from './canvas.js';
|
|
7
|
+
// Semantic component constants (headings, inline formatting, lists)
|
|
8
|
+
export { STRONG_DEFAULTS, EM_DEFAULTS, CODE_DEFAULTS, LINK_DEFAULTS, HEADING_DEFAULTS, mapListMarker, } from './semantics.js';
|
|
9
|
+
// Chart kind builders (shared camelCase-to-snake_case prop mapping)
|
|
10
|
+
export { buildBarChartKind, buildLineChartKind, buildPieChartKind, buildAreaChartKind, buildDotPlotKind, } from './charts.js';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Framework-neutral constants for the semantic components (headings,
|
|
3
|
+
* inline formatting, lists). Each adapter (react, svelte) walks its own
|
|
4
|
+
* element tree, but the default styles and the list-marker wire mapping
|
|
5
|
+
* must be identical so the adapters cannot drift.
|
|
6
|
+
*/
|
|
7
|
+
import type { Style } from './types.js';
|
|
8
|
+
import type { FormeListMarkerType } from './types.js';
|
|
9
|
+
export declare const STRONG_DEFAULTS: Style;
|
|
10
|
+
export declare const EM_DEFAULTS: Style;
|
|
11
|
+
export declare const CODE_DEFAULTS: Style;
|
|
12
|
+
export declare const LINK_DEFAULTS: Style;
|
|
13
|
+
export declare const HEADING_DEFAULTS: Record<1 | 2 | 3 | 4 | 5 | 6, Style>;
|
|
14
|
+
/** CSS `list-style-type`-shaped string → engine wire enum value. */
|
|
15
|
+
export declare function mapListMarker(marker: string | undefined, defaultValue: FormeListMarkerType): FormeListMarkerType;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Framework-neutral constants for the semantic components (headings,
|
|
3
|
+
* inline formatting, lists). Each adapter (react, svelte) walks its own
|
|
4
|
+
* element tree, but the default styles and the list-marker wire mapping
|
|
5
|
+
* must be identical so the adapters cannot drift.
|
|
6
|
+
*/
|
|
7
|
+
// Inline formatting components produce TextRuns with these default styles
|
|
8
|
+
// (merged under any user-supplied style, so user style wins).
|
|
9
|
+
export const STRONG_DEFAULTS = { fontWeight: 700 };
|
|
10
|
+
export const EM_DEFAULTS = { fontStyle: 'italic' };
|
|
11
|
+
export const CODE_DEFAULTS = {
|
|
12
|
+
fontFamily: 'Courier',
|
|
13
|
+
backgroundColor: '#F4F4F5',
|
|
14
|
+
};
|
|
15
|
+
export const LINK_DEFAULTS = {
|
|
16
|
+
color: '#2563EB',
|
|
17
|
+
textDecoration: 'underline',
|
|
18
|
+
};
|
|
19
|
+
// Default style per heading level. Tuned for typical document layout —
|
|
20
|
+
// users override individual properties via `style` on the heading element.
|
|
21
|
+
// margin top/bottom are in points; font sizes are points.
|
|
22
|
+
export const HEADING_DEFAULTS = {
|
|
23
|
+
1: { fontSize: 32, fontWeight: 700, marginTop: 24, marginBottom: 16 },
|
|
24
|
+
2: { fontSize: 24, fontWeight: 700, marginTop: 20, marginBottom: 14 },
|
|
25
|
+
3: { fontSize: 20, fontWeight: 600, marginTop: 16, marginBottom: 12 },
|
|
26
|
+
4: { fontSize: 18, fontWeight: 600, marginTop: 14, marginBottom: 10 },
|
|
27
|
+
5: { fontSize: 16, fontWeight: 600, marginTop: 12, marginBottom: 8 },
|
|
28
|
+
6: { fontSize: 14, fontWeight: 600, marginTop: 10, marginBottom: 6 },
|
|
29
|
+
};
|
|
30
|
+
/** CSS `list-style-type`-shaped string → engine wire enum value. */
|
|
31
|
+
export function mapListMarker(marker, defaultValue) {
|
|
32
|
+
switch (marker) {
|
|
33
|
+
case 'disc': return 'disc';
|
|
34
|
+
case 'circle': return 'circle';
|
|
35
|
+
case 'square': return 'square';
|
|
36
|
+
case 'none': return 'none';
|
|
37
|
+
case 'decimal': return 'decimal';
|
|
38
|
+
case 'lower-alpha': return 'lowerAlpha';
|
|
39
|
+
case 'upper-alpha': return 'upperAlpha';
|
|
40
|
+
case 'lower-roman': return 'lowerRoman';
|
|
41
|
+
case 'upper-roman': return 'upperRoman';
|
|
42
|
+
default: return defaultValue;
|
|
43
|
+
}
|
|
44
|
+
}
|
package/dist/style.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Style, Edges, Corners, ColumnDef, FormeStyle, FormeEdges, FormeColumnWidth, FormeDimension, FormeColor, FormeCornerValues } from './types.js';
|
|
2
|
+
export declare function mapStyle(style?: Style): FormeStyle;
|
|
3
|
+
export declare function mapDimension(val: number | string): FormeDimension;
|
|
4
|
+
export declare function parseColor(hex: string): FormeColor;
|
|
5
|
+
export declare function expandEdges(val: number | string | number[] | Edges): FormeEdges;
|
|
6
|
+
export declare function expandCorners(val: number | Corners): FormeCornerValues;
|
|
7
|
+
export declare function mapColumnWidth(w: ColumnDef['width']): FormeColumnWidth;
|