@segnavia/html 0.29.0 → 0.31.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/font-css.js +12 -4
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/motifs.d.ts +1 -0
- package/dist/motifs.js +6 -2
- package/package.json +2 -2
package/dist/font-css.js
CHANGED
|
@@ -9,7 +9,7 @@ var FontCssRefusedError = class extends Error {
|
|
|
9
9
|
this.name = "FontCssRefusedError";
|
|
10
10
|
}
|
|
11
11
|
};
|
|
12
|
-
const CSS_WEIGHT_KEYWORD = /^(?:normal|bold
|
|
12
|
+
const CSS_WEIGHT_KEYWORD = /^(?:normal|bold)$/;
|
|
13
13
|
const CSS_WEIGHT_NUMBER = /^(?:[1-9]\d{0,2}|1000)$/;
|
|
14
14
|
function mimeType(format) {
|
|
15
15
|
if (format === "truetype") return "ttf";
|
|
@@ -28,10 +28,18 @@ function unicodeRangeDeclaration(font) {
|
|
|
28
28
|
function faceRefusal(font, problem, remedy) {
|
|
29
29
|
return new FontCssRefusedError(`The face ${JSON.stringify(font.family)} could not establish ${problem}; ${remedy} to clear this refusal.`);
|
|
30
30
|
}
|
|
31
|
+
function isCssWeightNumber(value) {
|
|
32
|
+
return CSS_WEIGHT_NUMBER.test(value);
|
|
33
|
+
}
|
|
31
34
|
function isCssWeight(value) {
|
|
32
35
|
if (value === void 0) return true;
|
|
33
|
-
if (typeof value === "number") return Number.isInteger(value) && value
|
|
34
|
-
|
|
36
|
+
if (typeof value === "number") return Number.isInteger(value) && isCssWeightNumber(String(value));
|
|
37
|
+
if (typeof value !== "string") return false;
|
|
38
|
+
if (CSS_WEIGHT_KEYWORD.test(value) || isCssWeightNumber(value)) return true;
|
|
39
|
+
const range = value.split(" ");
|
|
40
|
+
const low = range[0];
|
|
41
|
+
const high = range[1];
|
|
42
|
+
return range.length === 2 && low !== void 0 && high !== void 0 && isCssWeightNumber(low) && isCssWeightNumber(high) && Number(low) <= Number(high);
|
|
35
43
|
}
|
|
36
44
|
function isFontFormat(value) {
|
|
37
45
|
return FONT_FORMATS.some((format) => format === value);
|
|
@@ -46,7 +54,7 @@ function quoteFamily(family) {
|
|
|
46
54
|
}
|
|
47
55
|
function validatedFace(font) {
|
|
48
56
|
if (!isFontFormat(font.format)) throw faceRefusal(font, `a font format that is one of ${FONT_FORMATS.join(", ")}`, `supply one of ${FONT_FORMATS.join(", ")}`);
|
|
49
|
-
if (!isCssWeight(font.weight)) throw faceRefusal(font, "a CSS font-weight", "supply a number 1-1000 or
|
|
57
|
+
if (!isCssWeight(font.weight)) throw faceRefusal(font, "a CSS font-weight", "supply a number 1-1000, two such numbers low then high, or 'normal' or 'bold'");
|
|
50
58
|
if (font.style !== void 0 && font.style !== "normal" && font.style !== "italic") throw faceRefusal(font, "a font-style of 'normal' or 'italic'", "supply 'normal' or 'italic'");
|
|
51
59
|
return font;
|
|
52
60
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ import { bookStylesheet, sanitizeBookCss } from "./book-css.js";
|
|
|
12
12
|
import { FontCssRefusedError, fontCss, fontFaceCss } from "./font-css.js";
|
|
13
13
|
import { fontFormat } from "./font-format.js";
|
|
14
14
|
import { fontReferenceRefusals } from "./font-references.js";
|
|
15
|
-
import { ExpandMotifsOptions, ExpandedMotifs, MOTIF_DEPTH_LIMIT, MotifRefusedError, PlacedMotif, expandMotifs, hasMotifPlacement, libraryMotifPlacementRefusal, motifPlacementRefusals, renderMotifPlacements } from "./motifs.js";
|
|
15
|
+
import { ExpandMotifsOptions, ExpandedMotifs, MOTIF_DEPTH_LIMIT, MotifRefusedError, PlacedMotif, documentLanguage, expandMotifs, hasMotifPlacement, libraryMotifPlacementRefusal, motifPlacementRefusals, renderMotifPlacements } from "./motifs.js";
|
|
16
16
|
import { BookPageFacts, BookPrintedPagePlan, BookPrintedPageRole, BookSectionParents, PrintedPagePlan, PrintedPageSide, planBookPages, planPrintedPages, printedPageAt, selectBookParent } from "./printed-pages.js";
|
|
17
17
|
import { SlotFillEntry, SlotFillRefusal, SlotFillsConflictError, SlotFillsRefusedError, SlotPrintOptions, assertSingleSlotCopy, assertSlotPrintOptions, collectSlotPrintCopies, isSlotCopyRefusal, slotFillCopyId, slotFillsConflict } from "./slot-print.js";
|
|
18
18
|
import { RequiredSlotsRefusedError, UnmeasuredSlotsRefusedError, mergeSlotFitResults, requiredSlotRefusal, unmeasuredSlotRefusal } from "./slot-policy.js";
|
|
@@ -23,4 +23,4 @@ export type HtmlKind = 'plain' | 'live-data' | 'scripted' | 'refused';
|
|
|
23
23
|
export declare function classify(html: string, prefix: string): HtmlKind;
|
|
24
24
|
export declare function searchText(html: string): string;
|
|
25
25
|
//#endregion
|
|
26
|
-
export { BINDINGS, BOOK_COLUMN_MAX, BOOK_COLUMN_MIN, type BookDocument, type BookDocumentOptions, type BookFurnitureValues, type BookHeading, BookPageFacts, type BookPrintPart, BookPrintedPagePlan, BookPrintedPageRole, type BookSectionInfo, type BookSectionParents, type ExpandMotifsOptions, type ExpandedMotifs, type FillOptions, type Filled, FontCssRefusedError, MAX_SLOT_DECLARATIONS, MOTIF_DEPTH_LIMIT, MotifRefusedError, PAGINATE_FUNCTIONS, type PaginateBlock, type PaginateBookInput, type PaginateBookPage, type PaginateBookRefusal, type PaginateBookResult, type PaginateFlow, type PaginateFlowParents, type PaginateLine, type PaginateMark, type PaginateNote, type PaginateNoteRef, type PaginateOpens, type PaginatePageMarks, type PaginatePageNote, type PaginatePageRole, type PaginateSequence, type PaginateTarget, type PaginateTargetPage, type PaginateWindow, type PlacedMotif, type PreparedSlots, PrintedPagePlan, PrintedPageSide, REFUSED_ELEMENTS, RequiredSlotsRefusedError, type SanitizeOptions, type SlotFillEntry, type SlotFillRefusal, SlotFillRefusedError, SlotFillsConflictError, SlotFillsRefusedError, type SlotPrintOptions, UNICODE_RANGE_CLEARANCE, type UnicodeRangeParse, UnmeasuredSlotsRefusedError, assertSingleSlotCopy, assertSlotPrintOptions, base64ToBytes, bindingNames, bindingRoot, bookDocument, bookPrintPart, bookStylesheet, bookView, bookViewFromHtml, bytesToBase64, collectSlotPrintCopies, embedFunction, expandMotifs, fill, fillBookFurniture, findActiveContent, fontCss, fontFaceCss, fontFormat, fontReferenceRefusals, furnitureScript, hasBindings, hasMotifPlacement, hasSlotWork, heldPageNumber, isSlotCopyRefusal, libraryMotifPlacementRefusal, mergeSlotFitResults, motifPlacementRefusals, openerPageIndex, pageIndexForTarget, paginateBook, paginateScript, parseUnicodeRange, planBookPages, planPrintedPages, prepareSlotCollection, prepareSlots, printedPageAt, renderMotifPlacements, requiredSlotRefusal, sanitize, sanitizeBookCss, selectBookParent, slotFillCopyId, slotFillRefusal, slotFillsConflict, unmeasuredSlotRefusal, windowPageIndex };
|
|
26
|
+
export { BINDINGS, BOOK_COLUMN_MAX, BOOK_COLUMN_MIN, type BookDocument, type BookDocumentOptions, type BookFurnitureValues, type BookHeading, BookPageFacts, type BookPrintPart, BookPrintedPagePlan, BookPrintedPageRole, type BookSectionInfo, type BookSectionParents, type ExpandMotifsOptions, type ExpandedMotifs, type FillOptions, type Filled, FontCssRefusedError, MAX_SLOT_DECLARATIONS, MOTIF_DEPTH_LIMIT, MotifRefusedError, PAGINATE_FUNCTIONS, type PaginateBlock, type PaginateBookInput, type PaginateBookPage, type PaginateBookRefusal, type PaginateBookResult, type PaginateFlow, type PaginateFlowParents, type PaginateLine, type PaginateMark, type PaginateNote, type PaginateNoteRef, type PaginateOpens, type PaginatePageMarks, type PaginatePageNote, type PaginatePageRole, type PaginateSequence, type PaginateTarget, type PaginateTargetPage, type PaginateWindow, type PlacedMotif, type PreparedSlots, PrintedPagePlan, PrintedPageSide, REFUSED_ELEMENTS, RequiredSlotsRefusedError, type SanitizeOptions, type SlotFillEntry, type SlotFillRefusal, SlotFillRefusedError, SlotFillsConflictError, SlotFillsRefusedError, type SlotPrintOptions, UNICODE_RANGE_CLEARANCE, type UnicodeRangeParse, UnmeasuredSlotsRefusedError, assertSingleSlotCopy, assertSlotPrintOptions, base64ToBytes, bindingNames, bindingRoot, bookDocument, bookPrintPart, bookStylesheet, bookView, bookViewFromHtml, bytesToBase64, collectSlotPrintCopies, documentLanguage, embedFunction, expandMotifs, fill, fillBookFurniture, findActiveContent, fontCss, fontFaceCss, fontFormat, fontReferenceRefusals, furnitureScript, hasBindings, hasMotifPlacement, hasSlotWork, heldPageNumber, isSlotCopyRefusal, libraryMotifPlacementRefusal, mergeSlotFitResults, motifPlacementRefusals, openerPageIndex, pageIndexForTarget, paginateBook, paginateScript, parseUnicodeRange, planBookPages, planPrintedPages, prepareSlotCollection, prepareSlots, printedPageAt, renderMotifPlacements, requiredSlotRefusal, sanitize, sanitizeBookCss, selectBookParent, slotFillCopyId, slotFillRefusal, slotFillsConflict, unmeasuredSlotRefusal, windowPageIndex };
|
package/dist/index.js
CHANGED
|
@@ -12,7 +12,7 @@ import { UNICODE_RANGE_CLEARANCE, parseUnicodeRange } from "./unicode-range.js";
|
|
|
12
12
|
import { FontCssRefusedError, fontCss, fontFaceCss } from "./font-css.js";
|
|
13
13
|
import { fontFormat } from "./font-format.js";
|
|
14
14
|
import { fontReferenceRefusals } from "./font-references.js";
|
|
15
|
-
import { MOTIF_DEPTH_LIMIT, MotifRefusedError, expandMotifs, hasMotifPlacement, libraryMotifPlacementRefusal, motifPlacementRefusals, renderMotifPlacements } from "./motifs.js";
|
|
15
|
+
import { MOTIF_DEPTH_LIMIT, MotifRefusedError, documentLanguage, expandMotifs, hasMotifPlacement, libraryMotifPlacementRefusal, motifPlacementRefusals, renderMotifPlacements } from "./motifs.js";
|
|
16
16
|
import { planBookPages, planPrintedPages, printedPageAt, selectBookParent } from "./printed-pages.js";
|
|
17
17
|
import { RequiredSlotsRefusedError, UnmeasuredSlotsRefusedError, mergeSlotFitResults, requiredSlotRefusal, unmeasuredSlotRefusal } from "./slot-policy.js";
|
|
18
18
|
import { MAX_SLOT_DECLARATIONS, SlotFillRefusedError, hasSlotWork, prepareSlotCollection, prepareSlots, slotFillRefusal } from "./slots.js";
|
|
@@ -29,4 +29,4 @@ function searchText(html) {
|
|
|
29
29
|
return html.replace(/<(script|style)\b[^>]*>[\s\S]*?<\/\1\s*>/gi, " ").replace(/<[^>]+>/g, " ").replace(/ /g, " ").replace(/\s+/g, " ").trim();
|
|
30
30
|
}
|
|
31
31
|
//#endregion
|
|
32
|
-
export { BINDINGS, BOOK_COLUMN_MAX, BOOK_COLUMN_MIN, FontCssRefusedError, MAX_SLOT_DECLARATIONS, MOTIF_DEPTH_LIMIT, MotifRefusedError, PAGINATE_FUNCTIONS, REFUSED_ELEMENTS, RequiredSlotsRefusedError, SlotFillRefusedError, SlotFillsConflictError, SlotFillsRefusedError, UNICODE_RANGE_CLEARANCE, UnmeasuredSlotsRefusedError, assertSingleSlotCopy, assertSlotPrintOptions, base64ToBytes, bindingNames, bindingRoot, bookDocument, bookPrintPart, bookStylesheet, bookView, bookViewFromHtml, bytesToBase64, classify, collectSlotPrintCopies, embedFunction, expandMotifs, fill, fillBookFurniture, findActiveContent, fontCss, fontFaceCss, fontFormat, fontReferenceRefusals, furnitureScript, hasBindings, hasMotifPlacement, hasSlotWork, heldPageNumber, isSlotCopyRefusal, libraryMotifPlacementRefusal, mergeSlotFitResults, motifPlacementRefusals, openerPageIndex, pageIndexForTarget, paginateBook, paginateScript, parseUnicodeRange, planBookPages, planPrintedPages, prepareSlotCollection, prepareSlots, printedPageAt, renderMotifPlacements, requiredSlotRefusal, sanitize, sanitizeBookCss, searchText, selectBookParent, slotFillCopyId, slotFillRefusal, slotFillsConflict, unmeasuredSlotRefusal, windowPageIndex };
|
|
32
|
+
export { BINDINGS, BOOK_COLUMN_MAX, BOOK_COLUMN_MIN, FontCssRefusedError, MAX_SLOT_DECLARATIONS, MOTIF_DEPTH_LIMIT, MotifRefusedError, PAGINATE_FUNCTIONS, REFUSED_ELEMENTS, RequiredSlotsRefusedError, SlotFillRefusedError, SlotFillsConflictError, SlotFillsRefusedError, UNICODE_RANGE_CLEARANCE, UnmeasuredSlotsRefusedError, assertSingleSlotCopy, assertSlotPrintOptions, base64ToBytes, bindingNames, bindingRoot, bookDocument, bookPrintPart, bookStylesheet, bookView, bookViewFromHtml, bytesToBase64, classify, collectSlotPrintCopies, documentLanguage, embedFunction, expandMotifs, fill, fillBookFurniture, findActiveContent, fontCss, fontFaceCss, fontFormat, fontReferenceRefusals, furnitureScript, hasBindings, hasMotifPlacement, hasSlotWork, heldPageNumber, isSlotCopyRefusal, libraryMotifPlacementRefusal, mergeSlotFitResults, motifPlacementRefusals, openerPageIndex, pageIndexForTarget, paginateBook, paginateScript, parseUnicodeRange, planBookPages, planPrintedPages, prepareSlotCollection, prepareSlots, printedPageAt, renderMotifPlacements, requiredSlotRefusal, sanitize, sanitizeBookCss, searchText, selectBookParent, slotFillCopyId, slotFillRefusal, slotFillsConflict, unmeasuredSlotRefusal, windowPageIndex };
|
package/dist/motifs.d.ts
CHANGED
|
@@ -27,6 +27,7 @@ export declare class MotifRefusedError extends Error {
|
|
|
27
27
|
export declare function libraryMotifPlacementRefusal(html: string): string | undefined;
|
|
28
28
|
export declare function hasMotifPlacement(html: string): boolean;
|
|
29
29
|
export declare function renderMotifPlacements(html: string, replacement: (key: string) => string | undefined): string;
|
|
30
|
+
export declare function documentLanguage(html: string): string | undefined;
|
|
30
31
|
export declare function expandMotifs(html: string, options: ExpandMotifsOptions): Promise<ExpandedMotifs>;
|
|
31
32
|
export declare function motifPlacementRefusals(html: string, options: ExpandMotifsOptions): Promise<string[]>;
|
|
32
33
|
//#endregion
|
package/dist/motifs.js
CHANGED
|
@@ -211,6 +211,9 @@ async function expandNodes(nodes, inheritedLang, stack, state) {
|
|
|
211
211
|
else await expandNodes(node.children, inheritedLang, stack, state);
|
|
212
212
|
}
|
|
213
213
|
}
|
|
214
|
+
function documentLanguage(html) {
|
|
215
|
+
return elements(parse(html).children).find((element) => element.name === "html")?.attribs.lang?.trim() || void 0;
|
|
216
|
+
}
|
|
214
217
|
async function run(html, options, validateOnly) {
|
|
215
218
|
const document = parse(html);
|
|
216
219
|
const state = {
|
|
@@ -223,7 +226,8 @@ async function run(html, options, validateOnly) {
|
|
|
223
226
|
motifCache: /* @__PURE__ */ new Map(),
|
|
224
227
|
placements: 0
|
|
225
228
|
};
|
|
226
|
-
|
|
229
|
+
const lang = options.lang?.trim() || documentLanguage(html);
|
|
230
|
+
await expandNodes(document.children, lang, [], state);
|
|
227
231
|
return {
|
|
228
232
|
document,
|
|
229
233
|
state
|
|
@@ -242,4 +246,4 @@ async function motifPlacementRefusals(html, options) {
|
|
|
242
246
|
return (await run(html, options, true)).state.refusals;
|
|
243
247
|
}
|
|
244
248
|
//#endregion
|
|
245
|
-
export { MOTIF_DEPTH_LIMIT, MotifRefusedError, expandMotifs, hasMotifPlacement, libraryMotifPlacementRefusal, motifPlacementRefusals, renderMotifPlacements };
|
|
249
|
+
export { MOTIF_DEPTH_LIMIT, MotifRefusedError, documentLanguage, expandMotifs, hasMotifPlacement, libraryMotifPlacementRefusal, motifPlacementRefusals, renderMotifPlacements };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@segnavia/html",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.31.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@segnavia/format": "0.
|
|
29
|
+
"@segnavia/format": "0.31.0",
|
|
30
30
|
"dom-serializer": "^2.0.0",
|
|
31
31
|
"domhandler": "^5.0.3",
|
|
32
32
|
"htmlparser2": "^10.0.0",
|