@formepdf/shared 0.28.0 → 0.30.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/dist/index.d.ts +1 -1
- package/dist/parser.d.ts +1 -0
- package/dist/parser.js +2 -0
- package/dist/style.js +63 -0
- package/dist/types.d.ts +30 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,6 @@ export { recordCanvasOperations } from './canvas.js';
|
|
|
5
5
|
export { STRONG_DEFAULTS, EM_DEFAULTS, CODE_DEFAULTS, LINK_DEFAULTS, HEADING_DEFAULTS, mapListMarker, } from './semantics.js';
|
|
6
6
|
export { buildBarChartKind, buildLineChartKind, buildPieChartKind, buildAreaChartKind, buildDotPlotKind, } from './charts.js';
|
|
7
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, FormeDocumentClaimProps, 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';
|
|
8
|
+
export type { Style, GridTrackSize, Edges, Corners, EdgeColors, CertificationConfig, SignatureConfig, ColumnDef, BarcodeFormat, ChartDataPoint, PieDataPoint, ChartSeries, DotPlotGroup, CanvasContext, CanvasOp, TextRun, ListMarker, FormeDocument, FormeDocumentClaimProps, FormeFont, FormeNode, FormeNodeKind, FormeStyle, FormeMetadata, FormePageConfig, FormePageSize, FormeEdges, FormeBoxShadow, FormeGradientStop, FormeBackground, FormeMarginEdges, FormeColumnDef, FormeColumnWidth, FormeDimension, FormeColor, FormeEdgeValues, FormeCornerValues, FormeGridTrackSize, FormeGridPlacement, FormeListMarkerType, FormeTransformOp, FormeFontFeature, } from './types.js';
|
|
9
9
|
export { parseMarkup } from './parser.js';
|
|
10
10
|
export { encodeProps, reviveBytesMarker } from './encode.js';
|
package/dist/parser.d.ts
CHANGED
package/dist/parser.js
CHANGED
|
@@ -122,6 +122,8 @@ function parseMarkupDocument(markup) {
|
|
|
122
122
|
result.pdfUa = true;
|
|
123
123
|
if (props.pdfUa2)
|
|
124
124
|
result.pdfUa2 = true;
|
|
125
|
+
if (props.embedStandardFonts)
|
|
126
|
+
result.embedStandardFonts = true;
|
|
125
127
|
const cert = props.certification ?? props.signature;
|
|
126
128
|
if (cert) {
|
|
127
129
|
if (props.signature && !props.certification) {
|
package/dist/style.js
CHANGED
|
@@ -227,6 +227,11 @@ export function mapStyle(style) {
|
|
|
227
227
|
result.textTransform = TEXT_TRANSFORM_MAP[style.textTransform];
|
|
228
228
|
if (style.hyphens !== undefined)
|
|
229
229
|
result.hyphens = HYPHENS_MAP[style.hyphens];
|
|
230
|
+
if (style.fontFeatureSettings !== undefined || style.fontVariantNumeric !== undefined) {
|
|
231
|
+
const features = parseFontFeatures(style.fontVariantNumeric, style.fontFeatureSettings);
|
|
232
|
+
if (features)
|
|
233
|
+
result.fontFeatures = features;
|
|
234
|
+
}
|
|
230
235
|
if (style.lang !== undefined)
|
|
231
236
|
result.lang = style.lang;
|
|
232
237
|
if (style.direction !== undefined)
|
|
@@ -478,6 +483,64 @@ export function parseColor(hex) {
|
|
|
478
483
|
// Fallback: black
|
|
479
484
|
return { r: 0, g: 0, b: 0, a: 1 };
|
|
480
485
|
}
|
|
486
|
+
/** `font-variant-numeric` keywords and the OpenType feature each turns on. */
|
|
487
|
+
const VARIANT_NUMERIC_FEATURES = {
|
|
488
|
+
'lining-nums': 'lnum',
|
|
489
|
+
'oldstyle-nums': 'onum',
|
|
490
|
+
'proportional-nums': 'pnum',
|
|
491
|
+
'tabular-nums': 'tnum',
|
|
492
|
+
'diagonal-fractions': 'frac',
|
|
493
|
+
'stacked-fractions': 'afrc',
|
|
494
|
+
ordinal: 'ordn',
|
|
495
|
+
'slashed-zero': 'zero',
|
|
496
|
+
};
|
|
497
|
+
/**
|
|
498
|
+
* Combine `fontVariantNumeric` and `fontFeatureSettings` into the engine's
|
|
499
|
+
* feature list. As in CSS, the low-level `font-feature-settings` is applied
|
|
500
|
+
* after `font-variant-numeric`, so it wins for the same tag. `normal` in
|
|
501
|
+
* either clears it (an empty list, which also stops inheritance). Returns
|
|
502
|
+
* `null` when neither parses, so the property is dropped, as other
|
|
503
|
+
* unparseable values are.
|
|
504
|
+
*/
|
|
505
|
+
function parseFontFeatures(variantNumeric, featureSettings) {
|
|
506
|
+
const byTag = new Map();
|
|
507
|
+
let parsed = false;
|
|
508
|
+
if (variantNumeric !== undefined) {
|
|
509
|
+
const words = variantNumeric.trim().toLowerCase().split(/\s+/).filter(Boolean);
|
|
510
|
+
if (words.length === 1 && words[0] === 'normal') {
|
|
511
|
+
parsed = true;
|
|
512
|
+
}
|
|
513
|
+
else {
|
|
514
|
+
for (const word of words) {
|
|
515
|
+
const tag = VARIANT_NUMERIC_FEATURES[word];
|
|
516
|
+
if (tag) {
|
|
517
|
+
byTag.set(tag, 1);
|
|
518
|
+
parsed = true;
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
if (featureSettings !== undefined) {
|
|
524
|
+
const trimmed = featureSettings.trim();
|
|
525
|
+
if (trimmed.toLowerCase() === 'normal') {
|
|
526
|
+
parsed = true;
|
|
527
|
+
}
|
|
528
|
+
else {
|
|
529
|
+
for (const item of trimmed.split(',')) {
|
|
530
|
+
const m = item.trim().match(/^(["'])(.{4})\1(?:\s+(on|off|\d+))?$/i);
|
|
531
|
+
if (!m)
|
|
532
|
+
continue;
|
|
533
|
+
const raw = m[3]?.toLowerCase();
|
|
534
|
+
const value = raw === undefined || raw === 'on' ? 1 : raw === 'off' ? 0 : parseInt(raw, 10);
|
|
535
|
+
byTag.set(m[2], value);
|
|
536
|
+
parsed = true;
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
if (!parsed)
|
|
541
|
+
return null;
|
|
542
|
+
return [...byTag].map(([tag, value]) => ({ tag, value }));
|
|
543
|
+
}
|
|
481
544
|
/**
|
|
482
545
|
* Parse a CSS-like `transform` string into the engine's TransformOp[].
|
|
483
546
|
*
|
package/dist/types.d.ts
CHANGED
|
@@ -123,6 +123,20 @@ export interface Style {
|
|
|
123
123
|
textDecoration?: 'none' | 'underline' | 'line-through';
|
|
124
124
|
textTransform?: 'none' | 'uppercase' | 'lowercase' | 'capitalize';
|
|
125
125
|
hyphens?: 'none' | 'manual' | 'auto';
|
|
126
|
+
/**
|
|
127
|
+
* OpenType features, as CSS `font-feature-settings`: `'"tnum" 1'`,
|
|
128
|
+
* `'"zero", "ss01" on'`, `'normal'`. Applies to fonts with font data
|
|
129
|
+
* (registered fonts and the builtin Noto Sans); the standard fonts are not
|
|
130
|
+
* shaped and ignore it. Inherited.
|
|
131
|
+
*/
|
|
132
|
+
fontFeatureSettings?: string;
|
|
133
|
+
/**
|
|
134
|
+
* CSS `font-variant-numeric`: `'tabular-nums'`, `'oldstyle-nums'`,
|
|
135
|
+
* `'proportional-nums'`, `'lining-nums'`, `'slashed-zero'`,
|
|
136
|
+
* `'diagonal-fractions'`, `'stacked-fractions'`, `'ordinal'`, or several
|
|
137
|
+
* separated by spaces. `fontFeatureSettings` wins for the same feature.
|
|
138
|
+
*/
|
|
139
|
+
fontVariantNumeric?: string;
|
|
126
140
|
/** Language tag (BCP 47, e.g. "en-US", "de"). Controls hyphenation dictionary. */
|
|
127
141
|
lang?: string;
|
|
128
142
|
/** Text direction for BiDi support (Arabic, Hebrew). */
|
|
@@ -390,6 +404,15 @@ export interface FormeDocument {
|
|
|
390
404
|
* for a file that is archival AND accessible.
|
|
391
405
|
*/
|
|
392
406
|
pdfUa2?: boolean;
|
|
407
|
+
/**
|
|
408
|
+
* Embed the base-14 fonts (Helvetica, Times, Courier) as their
|
|
409
|
+
* metric-compatible substitutes from @formepdf/fonts-standard, with NO
|
|
410
|
+
* conformance claim: no PDF/UA or PDF/A identification. pdfUa, pdfa and
|
|
411
|
+
* pdfVersion "2.0" already embed them; this is for an ordinary document
|
|
412
|
+
* that should look the same in every viewer. Subset to the characters
|
|
413
|
+
* used; layout is unchanged. Warns if the substitutes are not registered.
|
|
414
|
+
*/
|
|
415
|
+
embedStandardFonts?: boolean;
|
|
393
416
|
flattenForms?: boolean;
|
|
394
417
|
certification?: CertificationConfig;
|
|
395
418
|
}
|
|
@@ -403,7 +426,7 @@ export interface FormeDocument {
|
|
|
403
426
|
* out (and `passes` before it: real on one layer, absent on the layer
|
|
404
427
|
* users touch).
|
|
405
428
|
*/
|
|
406
|
-
export type FormeDocumentClaimProps = Pick<FormeDocument, 'tagged' | 'pdfa' | 'pdfVersion' | 'pdfUa' | 'pdfUa2'>;
|
|
429
|
+
export type FormeDocumentClaimProps = Pick<FormeDocument, 'tagged' | 'pdfa' | 'pdfVersion' | 'pdfUa' | 'pdfUa2' | 'embedStandardFonts'>;
|
|
407
430
|
export interface FormeMetadata {
|
|
408
431
|
title?: string;
|
|
409
432
|
author?: string;
|
|
@@ -713,6 +736,11 @@ export interface FormeGridPlacement {
|
|
|
713
736
|
rowSpan?: number;
|
|
714
737
|
}
|
|
715
738
|
/** Style in the Forme JSON format (camelCase field names, PascalCase enum values) */
|
|
739
|
+
/** One OpenType feature for shaping, e.g. `{ tag: 'tnum', value: 1 }`. */
|
|
740
|
+
export interface FormeFontFeature {
|
|
741
|
+
tag: string;
|
|
742
|
+
value: number;
|
|
743
|
+
}
|
|
716
744
|
export interface FormeStyle {
|
|
717
745
|
display?: string;
|
|
718
746
|
width?: FormeDimension;
|
|
@@ -754,6 +782,7 @@ export interface FormeStyle {
|
|
|
754
782
|
textDecoration?: string;
|
|
755
783
|
textTransform?: string;
|
|
756
784
|
hyphens?: string;
|
|
785
|
+
fontFeatures?: FormeFontFeature[];
|
|
757
786
|
lang?: string;
|
|
758
787
|
direction?: string;
|
|
759
788
|
textOverflow?: string;
|