postext 1.101.1 → 1.102.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/dist/__tests__/defaults/headingsBalancing.test.js +8 -0
- package/dist/__tests__/defaults/headingsBalancing.test.js.map +1 -1
- package/dist/__tests__/exports.test.js +63 -0
- package/dist/__tests__/exports.test.js.map +1 -1
- package/dist/__tests__/pipeline/columns/shrinkListSpacing.test.d.ts +2 -0
- package/dist/__tests__/pipeline/columns/shrinkListSpacing.test.d.ts.map +1 -0
- package/dist/__tests__/pipeline/columns/shrinkListSpacing.test.js +91 -0
- package/dist/__tests__/pipeline/columns/shrinkListSpacing.test.js.map +1 -0
- package/dist/__tests__/review/review.test.d.ts +2 -0
- package/dist/__tests__/review/review.test.d.ts.map +1 -0
- package/dist/__tests__/review/review.test.js +72 -0
- package/dist/__tests__/review/review.test.js.map +1 -0
- package/dist/checks/configWarnings/unknownKeys.js +1 -1
- package/dist/checks/configWarnings/unknownKeys.js.map +1 -1
- package/dist/defaults/structure/headings/defaults.d.ts +1 -0
- package/dist/defaults/structure/headings/defaults.d.ts.map +1 -1
- package/dist/defaults/structure/headings/defaults.js +1 -0
- package/dist/defaults/structure/headings/defaults.js.map +1 -1
- package/dist/defaults/structure/headings/resolve.d.ts.map +1 -1
- package/dist/defaults/structure/headings/resolve.js +1 -0
- package/dist/defaults/structure/headings/resolve.js.map +1 -1
- package/dist/defaults/structure/headings/strip.d.ts.map +1 -1
- package/dist/defaults/structure/headings/strip.js +5 -0
- package/dist/defaults/structure/headings/strip.js.map +1 -1
- package/dist/pipeline/build/pass/lines/lineRoom.d.ts.map +1 -1
- package/dist/pipeline/build/pass/lines/lineRoom.js +45 -0
- package/dist/pipeline/build/pass/lines/lineRoom.js.map +1 -1
- package/dist/pipeline/build/pass/lines/listSpacing.d.ts +45 -0
- package/dist/pipeline/build/pass/lines/listSpacing.d.ts.map +1 -0
- package/dist/pipeline/build/pass/lines/listSpacing.js +115 -0
- package/dist/pipeline/build/pass/lines/listSpacing.js.map +1 -0
- package/dist/review/frameStyles/calloutFences.d.ts +35 -0
- package/dist/review/frameStyles/calloutFences.d.ts.map +1 -0
- package/dist/review/frameStyles/calloutFences.js +79 -0
- package/dist/review/frameStyles/calloutFences.js.map +1 -0
- package/dist/review/frameStyles/exerciseRefs.d.ts +25 -0
- package/dist/review/frameStyles/exerciseRefs.d.ts.map +1 -0
- package/dist/review/frameStyles/exerciseRefs.js +51 -0
- package/dist/review/frameStyles/exerciseRefs.js.map +1 -0
- package/dist/review/frameStyles/library.d.ts +29 -0
- package/dist/review/frameStyles/library.d.ts.map +1 -0
- package/dist/review/frameStyles/library.js +39 -0
- package/dist/review/frameStyles/library.js.map +1 -0
- package/dist/review/frameStyles/mergeFrameStyles.d.ts +44 -0
- package/dist/review/frameStyles/mergeFrameStyles.d.ts.map +1 -0
- package/dist/review/frameStyles/mergeFrameStyles.js +45 -0
- package/dist/review/frameStyles/mergeFrameStyles.js.map +1 -0
- package/dist/review/frameStyles/styleCompare.d.ts +112 -0
- package/dist/review/frameStyles/styleCompare.d.ts.map +1 -0
- package/dist/review/frameStyles/styleCompare.js +262 -0
- package/dist/review/frameStyles/styleCompare.js.map +1 -0
- package/dist/review/frameStyles/styleMerge.d.ts +79 -0
- package/dist/review/frameStyles/styleMerge.d.ts.map +1 -0
- package/dist/review/frameStyles/styleMerge.js +204 -0
- package/dist/review/frameStyles/styleMerge.js.map +1 -0
- package/dist/review/frameStyles/styleUsage.d.ts +70 -0
- package/dist/review/frameStyles/styleUsage.d.ts.map +1 -0
- package/dist/review/frameStyles/styleUsage.js +127 -0
- package/dist/review/frameStyles/styleUsage.js.map +1 -0
- package/dist/review/index.d.ts +15 -0
- package/dist/review/index.d.ts.map +1 -0
- package/dist/review/index.js +26 -0
- package/dist/review/index.js.map +1 -0
- package/dist/review/languages/arabicDefaults.d.ts +113 -0
- package/dist/review/languages/arabicDefaults.d.ts.map +1 -0
- package/dist/review/languages/arabicDefaults.js +413 -0
- package/dist/review/languages/arabicDefaults.js.map +1 -0
- package/dist/review/languages/chineseDefaults.d.ts +96 -0
- package/dist/review/languages/chineseDefaults.d.ts.map +1 -0
- package/dist/review/languages/chineseDefaults.js +361 -0
- package/dist/review/languages/chineseDefaults.js.map +1 -0
- package/dist/review/languages/defaultsReview.d.ts +69 -0
- package/dist/review/languages/defaultsReview.d.ts.map +1 -0
- package/dist/review/languages/defaultsReview.js +286 -0
- package/dist/review/languages/defaultsReview.js.map +1 -0
- package/dist/review/languages/documentDirection.d.ts +19 -0
- package/dist/review/languages/documentDirection.d.ts.map +1 -0
- package/dist/review/languages/documentDirection.js +36 -0
- package/dist/review/languages/documentDirection.js.map +1 -0
- package/dist/review/languages/japaneseDefaults/types.d.ts +95 -0
- package/dist/review/languages/japaneseDefaults/types.d.ts.map +1 -0
- package/dist/review/languages/japaneseDefaults/types.js +19 -0
- package/dist/review/languages/japaneseDefaults/types.js.map +1 -0
- package/dist/review/languages/japaneseDefaults/values.d.ts +70 -0
- package/dist/review/languages/japaneseDefaults/values.d.ts.map +1 -0
- package/dist/review/languages/japaneseDefaults/values.js +130 -0
- package/dist/review/languages/japaneseDefaults/values.js.map +1 -0
- package/dist/review/languages/japaneseDefaults.d.ts +21 -0
- package/dist/review/languages/japaneseDefaults.d.ts.map +1 -0
- package/dist/review/languages/japaneseDefaults.js +544 -0
- package/dist/review/languages/japaneseDefaults.js.map +1 -0
- package/dist/review/text/templateUsage.d.ts +74 -0
- package/dist/review/text/templateUsage.d.ts.map +1 -0
- package/dist/review/text/templateUsage.js +227 -0
- package/dist/review/text/templateUsage.js.map +1 -0
- package/dist/review/text/textChanges.d.ts +28 -0
- package/dist/review/text/textChanges.d.ts.map +1 -0
- package/dist/review/text/textChanges.js +49 -0
- package/dist/review/text/textChanges.js.map +1 -0
- package/dist/types/columnBalancing.d.ts +14 -0
- package/dist/types/columnBalancing.d.ts.map +1 -1
- package/dist/types/structure/headings.d.ts +1 -0
- package/dist/types/structure/headings.d.ts.map +1 -1
- package/dist/vdt/blocks.d.ts +7 -2
- package/dist/vdt/blocks.d.ts.map +1 -1
- package/package.json +5 -1
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What names a box style or an exercise style among the exercises (#1244):
|
|
3
|
+
* an exercise style's `box`, `bank.box` and `solutions.box` and the book's
|
|
4
|
+
* `exercises.solutions.box` name box styles; a `:::exercise{style=…}`
|
|
5
|
+
* fence names an exercise style. A rename (or a merge) of either rewrites
|
|
6
|
+
* them, as it rewrites the `:::callout` fences and the template frames.
|
|
7
|
+
*/
|
|
8
|
+
import { restyleExerciseChanges } from './calloutFences.js';
|
|
9
|
+
/** The exercise settings with every box style that is a key of `renames`
|
|
10
|
+
* named by its value; the same objects when none is. */
|
|
11
|
+
export function reboxExercises(config, renames) {
|
|
12
|
+
const to = (id) => (id !== undefined && renames.has(id) ? renames.get(id) : id);
|
|
13
|
+
let stylesChanged = false;
|
|
14
|
+
const exerciseStyles = config.exerciseStyles?.map((s) => {
|
|
15
|
+
const box = to(s.box);
|
|
16
|
+
const bank = to(s.bank?.box);
|
|
17
|
+
const solution = to(s.solutions?.box);
|
|
18
|
+
if (box === s.box && bank === s.bank?.box && solution === s.solutions?.box)
|
|
19
|
+
return s;
|
|
20
|
+
stylesChanged = true;
|
|
21
|
+
return {
|
|
22
|
+
...s,
|
|
23
|
+
...(box !== undefined ? { box } : {}),
|
|
24
|
+
...(s.bank ? { bank: { ...s.bank, ...(bank !== undefined ? { box: bank } : {}) } } : {}),
|
|
25
|
+
...(s.solutions ? { solutions: { ...s.solutions, ...(solution !== undefined ? { box: solution } : {}) } } : {}),
|
|
26
|
+
};
|
|
27
|
+
});
|
|
28
|
+
const bookBox = to(config.exercises?.solutions?.box);
|
|
29
|
+
const exercises = config.exercises?.solutions && bookBox !== config.exercises.solutions.box
|
|
30
|
+
? { ...config.exercises, solutions: { ...config.exercises.solutions, box: bookBox } }
|
|
31
|
+
: config.exercises;
|
|
32
|
+
return { exerciseStyles: stylesChanged ? exerciseStyles : config.exerciseStyles, exercises };
|
|
33
|
+
}
|
|
34
|
+
export function planExerciseStyleRename(styles, chapters, from, to) {
|
|
35
|
+
const renames = new Map([[from, to]]);
|
|
36
|
+
const rewrites = [];
|
|
37
|
+
chapters.forEach((ch, chapterIndex) => {
|
|
38
|
+
const changes = restyleExerciseChanges(ch.markdown, renames);
|
|
39
|
+
if (changes.length > 0)
|
|
40
|
+
rewrites.push({ chapterId: ch.id, chapterIndex, changes, baseLength: ch.markdown.length });
|
|
41
|
+
});
|
|
42
|
+
return {
|
|
43
|
+
exerciseStyles: styles.map((s) => {
|
|
44
|
+
const next = s.id === from ? { ...s, id: to } : s;
|
|
45
|
+
return next.extends === from ? { ...next, extends: to } : next;
|
|
46
|
+
}),
|
|
47
|
+
chapters: rewrites,
|
|
48
|
+
fenceCount: rewrites.reduce((n, c) => n + c.changes.length, 0),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=exerciseRefs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exerciseRefs.js","sourceRoot":"","sources":["../../../src/review/frameStyles/exerciseRefs.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAI5D;yDACyD;AACzD,MAAM,UAAU,cAAc,CAC5B,MAA2D,EAC3D,OAAoC;IAEpC,MAAM,EAAE,GAAG,CAAC,EAAsB,EAAsB,EAAE,CAAC,CAAC,EAAE,KAAK,SAAS,IAAI,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IACzH,IAAI,aAAa,GAAG,KAAK,CAAC;IAC1B,MAAM,cAAc,GAAG,MAAM,CAAC,cAAc,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;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AC,OAAO,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;QACjE,CAAC,CAAC;QACF,QAAQ,EAAE,QAAQ;QAClB,UAAU,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;KAC/D,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The frame-style library of a book (#873): its callout styles as the
|
|
3
|
+
* engine resolves them, where each is used and the merges it suggests.
|
|
4
|
+
* The Design panel's Frame styles section and the agent tools read the
|
|
5
|
+
* same answer.
|
|
6
|
+
*/
|
|
7
|
+
import { type CalloutStyleConfig, type PostextConfig, type ResolvedCalloutStyleConfig } from '../../index.js';
|
|
8
|
+
import { type CompareOptions, type MergeSuggestion, type StyleKind } from './styleCompare.js';
|
|
9
|
+
import { type StyleUsage, type UsageChapter } from './styleUsage.js';
|
|
10
|
+
export interface FrameStyleLibrary {
|
|
11
|
+
/** The styles as the book stores them (the built-in list while it
|
|
12
|
+
* stores none: `stored` is then false). */
|
|
13
|
+
styles: readonly CalloutStyleConfig[];
|
|
14
|
+
stored: boolean;
|
|
15
|
+
resolved: ResolvedCalloutStyleConfig[];
|
|
16
|
+
usage: Map<string, StyleUsage>;
|
|
17
|
+
suggestions: MergeSuggestion[];
|
|
18
|
+
/** Styles that extend another or differ from it in colours only (#976). */
|
|
19
|
+
kinds: StyleKind[];
|
|
20
|
+
}
|
|
21
|
+
/** The document language the engine resolves continuation strings in. */
|
|
22
|
+
export declare function styleLocale(config: PostextConfig, fallback?: string): string | undefined;
|
|
23
|
+
/** `config`'s callout styles resolved as a build resolves them. */
|
|
24
|
+
export declare function resolveBookStyles(config: PostextConfig, styles: readonly CalloutStyleConfig[], locale?: string): ResolvedCalloutStyleConfig[];
|
|
25
|
+
/** The comparison settings that follow from the book: its page `dpi` and
|
|
26
|
+
* the size of an `em` of its body text. */
|
|
27
|
+
export declare function bookCompareOptions(config: PostextConfig, options?: CompareOptions): CompareOptions;
|
|
28
|
+
export declare function frameStyleLibrary(config: PostextConfig, chapters: readonly UsageChapter[], options?: CompareOptions, locale?: string): FrameStyleLibrary;
|
|
29
|
+
//# sourceMappingURL=library.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"library.d.ts","sourceRoot":"","sources":["../../../src/review/frameStyles/library.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAML,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAClB,KAAK,0BAA0B,EAChC,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAgC,KAAK,cAAc,EAAE,KAAK,eAAe,EAAE,KAAK,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC5H,OAAO,EAAiC,KAAK,UAAU,EAAE,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAOpG,MAAM,WAAW,iBAAiB;IAChC;gDAC4C;IAC5C,MAAM,EAAE,SAAS,kBAAkB,EAAE,CAAC;IACtC,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,0BAA0B,EAAE,CAAC;IACvC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IAC/B,WAAW,EAAE,eAAe,EAAE,CAAC;IAC/B,2EAA2E;IAC3E,KAAK,EAAE,SAAS,EAAE,CAAC;CACpB;AAED,yEAAyE;AACzE,wBAAgB,WAAW,CAAC,MAAM,EAAE,aAAa,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAExF;AAED,mEAAmE;AACnE,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,SAAS,kBAAkB,EAAE,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,0BAA0B,EAAE,CAK7I;AAED;4CAC4C;AAC5C,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,GAAE,cAAmB,GAAG,cAAc,CAItG;AAED,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,aAAa,EACrB,QAAQ,EAAE,SAAS,YAAY,EAAE,EACjC,OAAO,GAAE,cAAmB,EAC5B,MAAM,CAAC,EAAE,MAAM,GACd,iBAAiB,CAOnB"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The frame-style library of a book (#873): its callout styles as the
|
|
3
|
+
* engine resolves them, where each is used and the merges it suggests.
|
|
4
|
+
* The Design panel's Frame styles section and the agent tools read the
|
|
5
|
+
* same answer.
|
|
6
|
+
*/
|
|
7
|
+
import { DEFAULT_CALLOUT_STYLES, resolveBodyTextConfig, resolveCalloutStylesConfig, resolveHeadingsConfig, resolveUnorderedListsConfig, } from '../../index.js';
|
|
8
|
+
import { mergeSuggestions, styleKinds } from './styleCompare.js';
|
|
9
|
+
import { bookCalloutStyles, styleUsage } from './styleUsage.js';
|
|
10
|
+
/** Points per unit; em and rem against a 12 pt reference. */
|
|
11
|
+
const TO_PT = { pt: 1, mm: 2.83465, cm: 28.3465, in: 72, px: 0.75, em: 12, rem: 12 };
|
|
12
|
+
const toPt = (d) => d.value * TO_PT[d.unit];
|
|
13
|
+
/** The document language the engine resolves continuation strings in. */
|
|
14
|
+
export function styleLocale(config, fallback) {
|
|
15
|
+
return config.locale ?? config.bodyText?.hyphenation?.locale ?? fallback;
|
|
16
|
+
}
|
|
17
|
+
/** `config`'s callout styles resolved as a build resolves them. */
|
|
18
|
+
export function resolveBookStyles(config, styles, locale) {
|
|
19
|
+
const bodyText = resolveBodyTextConfig(config.bodyText);
|
|
20
|
+
const headings = resolveHeadingsConfig(config.headings);
|
|
21
|
+
const lists = resolveUnorderedListsConfig(config.unorderedLists, bodyText);
|
|
22
|
+
return resolveCalloutStylesConfig([...styles], bodyText, headings, lists, styleLocale(config, locale));
|
|
23
|
+
}
|
|
24
|
+
/** The comparison settings that follow from the book: its page `dpi` and
|
|
25
|
+
* the size of an `em` of its body text. */
|
|
26
|
+
export function bookCompareOptions(config, options = {}) {
|
|
27
|
+
const body = resolveBodyTextConfig(config.bodyText);
|
|
28
|
+
const emPt = toPt(body.fontSize);
|
|
29
|
+
return { dpi: config.page?.dpi ?? 96, ...(emPt > 0 ? { emPt } : {}), ...options };
|
|
30
|
+
}
|
|
31
|
+
export function frameStyleLibrary(config, chapters, options = {}, locale) {
|
|
32
|
+
const styles = bookCalloutStyles(config, DEFAULT_CALLOUT_STYLES);
|
|
33
|
+
const resolved = resolveBookStyles(config, styles, locale);
|
|
34
|
+
const usage = styleUsage(config, styles, chapters);
|
|
35
|
+
const suggestions = config.calloutStyles ? mergeSuggestions(styles, resolved, usage, bookCompareOptions(config, options)) : [];
|
|
36
|
+
const kinds = config.calloutStyles ? styleKinds(styles, resolved, usage, bookCompareOptions(config, options)) : [];
|
|
37
|
+
return { styles, stored: config.calloutStyles !== undefined, resolved, usage, suggestions, kinds };
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=library.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"library.js","sourceRoot":"","sources":["../../../src/review/frameStyles/library.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EACrB,0BAA0B,EAC1B,qBAAqB,EACrB,2BAA2B,GAI5B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAA6D,MAAM,mBAAmB,CAAC;AAC5H,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAsC,MAAM,iBAAiB,CAAC;AAGpG,6DAA6D;AAC7D,MAAM,KAAK,GAAsC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE,EA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AAE,CAAC,EAAE,GAAG,OAAO,EAAE,CAAC;AACpF,CAAC;AAED,MAAM,UAAU,iBAAiB,CAC/B,MAAqB,EACrB,QAAiC,EACjC,UAA0B,EAAE,EAC5B,MAAe;IAEf,MAAM,MAAM,GAAG,iBAAiB,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC;IACjE,MAAM,QAAQ,GAAG,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IAC3D,MAAM,KAAK,GAAG,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;IACnD,MAAM,WAAW,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,gBAAgB,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,kBAAkB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAC/H,MAAM,KAAK,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,kBAAkB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACnH,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,aAAa,KAAK,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC;AACrG,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Merging box styles in one call (#1757): the configuration and the
|
|
3
|
+
* chapters' Markdown once each group's `merge` styles are folded into its
|
|
4
|
+
* `keep` style, for a host to show and a person to accept. The Sandbox's
|
|
5
|
+
* Frame styles section and its agent tools compose the same pieces
|
|
6
|
+
* (`frameStyleLibrary`, `placesToKeep`, `planMerges`), writing the plan
|
|
7
|
+
* through their own history instead.
|
|
8
|
+
*/
|
|
9
|
+
import type { PostextConfig } from '../../index.js';
|
|
10
|
+
import type { CompareOptions } from './styleCompare.js';
|
|
11
|
+
import { type FrameRewrite, type MergeGroup } from './styleMerge.js';
|
|
12
|
+
import type { UsageChapter } from './styleUsage.js';
|
|
13
|
+
export interface MergeFrameStylesOptions extends CompareOptions {
|
|
14
|
+
/** The language the styles' continuation strings are resolved in. */
|
|
15
|
+
locale?: string;
|
|
16
|
+
/** With `ignorePosition`: a style whose `:::callout` boxes stand elsewhere than
|
|
17
|
+
* the kept style's stays with only its place, based on the kept style,
|
|
18
|
+
* so no box moves (default true). */
|
|
19
|
+
keepPlaces?: boolean;
|
|
20
|
+
}
|
|
21
|
+
export interface MergeFrameStylesResult {
|
|
22
|
+
/** `config` with the merged styles gone, and every template frame and
|
|
23
|
+
* exercise setting that named one naming the kept style. */
|
|
24
|
+
config: PostextConfig;
|
|
25
|
+
/** The chapters whose fences changed, with their new Markdown; the
|
|
26
|
+
* others are left out. */
|
|
27
|
+
chapters: {
|
|
28
|
+
id: string;
|
|
29
|
+
markdown: string;
|
|
30
|
+
}[];
|
|
31
|
+
/** The styles merged away. */
|
|
32
|
+
merged: string[];
|
|
33
|
+
/** Styles kept for the place of their boxes (`keepPlaces`). */
|
|
34
|
+
stays: string[];
|
|
35
|
+
/** The template frames rewritten. */
|
|
36
|
+
frames: FrameRewrite[];
|
|
37
|
+
/** `:::callout` fences rewritten, all chapters together. */
|
|
38
|
+
fenceCount: number;
|
|
39
|
+
}
|
|
40
|
+
/** Each group's `merge` styles folded into its `keep` style. A book with
|
|
41
|
+
* no styles of its own (the built-in list) has nothing to merge: the
|
|
42
|
+
* configuration comes back as it was. An id the book has not throws. */
|
|
43
|
+
export declare function mergeFrameStyles(config: PostextConfig, chapters: readonly UsageChapter[], groups: readonly MergeGroup[], options?: MergeFrameStylesOptions): MergeFrameStylesResult;
|
|
44
|
+
//# sourceMappingURL=mergeFrameStyles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mergeFrameStyles.d.ts","sourceRoot":"","sources":["../../../src/review/frameStyles/mergeFrameStyles.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAEpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAA4C,KAAK,YAAY,EAAE,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC/G,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD,MAAM,WAAW,uBAAwB,SAAQ,cAAc;IAC7D,qEAAqE;IACrE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;0CAEsC;IACtC,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,MAAM,WAAW,sBAAsB;IACrC;iEAC6D;IAC7D,MAAM,EAAE,aAAa,CAAC;IACtB;+BAC2B;IAC3B,QAAQ,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAC7C,8BAA8B;IAC9B,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,+DAA+D;IAC/D,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,qCAAqC;IACrC,MAAM,EAAE,YAAY,EAAE,CAAC;IACvB,4DAA4D;IAC5D,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;yEAEyE;AACzE,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,aAAa,EACrB,QAAQ,EAAE,SAAS,YAAY,EAAE,EACjC,MAAM,EAAE,SAAS,UAAU,EAAE,EAC7B,OAAO,GAAE,uBAA4B,GACpC,sBAAsB,CAyBxB"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Merging box styles in one call (#1757): the configuration and the
|
|
3
|
+
* chapters' Markdown once each group's `merge` styles are folded into its
|
|
4
|
+
* `keep` style, for a host to show and a person to accept. The Sandbox's
|
|
5
|
+
* Frame styles section and its agent tools compose the same pieces
|
|
6
|
+
* (`frameStyleLibrary`, `placesToKeep`, `planMerges`), writing the plan
|
|
7
|
+
* through their own history instead.
|
|
8
|
+
*/
|
|
9
|
+
import { bookCompareOptions, frameStyleLibrary } from './library.js';
|
|
10
|
+
import { placesToKeep, planMerges, rewrittenTexts } from './styleMerge.js';
|
|
11
|
+
/** Each group's `merge` styles folded into its `keep` style. A book with
|
|
12
|
+
* no styles of its own (the built-in list) has nothing to merge: the
|
|
13
|
+
* configuration comes back as it was. An id the book has not throws. */
|
|
14
|
+
export function mergeFrameStyles(config, chapters, groups, options = {}) {
|
|
15
|
+
const { locale, keepPlaces, ...compare } = options;
|
|
16
|
+
if (!config.calloutStyles || groups.length === 0)
|
|
17
|
+
return { config, chapters: [], merged: [], stays: [], frames: [], fenceCount: 0 };
|
|
18
|
+
const library = frameStyleLibrary(config, chapters, compare, locale);
|
|
19
|
+
const ids = new Set(library.styles.map((s) => s.id));
|
|
20
|
+
for (const g of groups) {
|
|
21
|
+
for (const id of [g.keep, ...g.merge]) {
|
|
22
|
+
if (!ids.has(id))
|
|
23
|
+
throw new Error(`mergeFrameStyles: the book has no callout style ${JSON.stringify(id)}`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const places = compare.ignorePosition === true && keepPlaces !== false ? placesToKeep(groups, library, bookCompareOptions(config)) : undefined;
|
|
27
|
+
const plan = planMerges(config, library.styles, chapters, groups, places);
|
|
28
|
+
const next = { ...config, calloutStyles: plan.calloutStyles.length > 0 ? plan.calloutStyles : undefined };
|
|
29
|
+
if (plan.pageTemplates !== config.pageTemplates)
|
|
30
|
+
next.pageTemplates = plan.pageTemplates;
|
|
31
|
+
if ('exerciseStyles' in plan)
|
|
32
|
+
next.exerciseStyles = plan.exerciseStyles;
|
|
33
|
+
if ('exercises' in plan)
|
|
34
|
+
next.exercises = plan.exercises;
|
|
35
|
+
const texts = rewrittenTexts(chapters, plan);
|
|
36
|
+
return {
|
|
37
|
+
config: next,
|
|
38
|
+
chapters: [...texts].map(([id, markdown]) => ({ id, markdown })),
|
|
39
|
+
merged: plan.from,
|
|
40
|
+
stays: plan.stays,
|
|
41
|
+
frames: plan.frames,
|
|
42
|
+
fenceCount: plan.fenceCount,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=mergeFrameStyles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mergeFrameStyles.js","sourceRoot":"","sources":["../../../src/review/frameStyles/mergeFrameStyles.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAErE,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,cAAc,EAAsC,MAAM,iBAAiB,CAAC;AA6B/G;;yEAEyE;AACzE,MAAM,UAAU,gBAAgB,CAC9B,MAAqB,EACrB,QAAiC,EACjC,MAA6B,EAC7B,UAAmC,EAAE;IAErC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,OAAO,EAAE,GAAG,OAAO,CAAC;IACnD,IAAI,CAAC,MAAM,CAAC,aAAa,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,UAAU,EAAE,CAAC,EAAE,CAAC;IACpI,MAAM,OAAO,GAAG,iBAAiB,CAAC,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IACrE,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACrD,KAAK,MAAM,CAAC,IAAI,MAAM,EAAE,CAAC;QACvB,KAAK,MAAM,EA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E,CAAC,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC;QAChE,MAAM,EAAE,IAAI,CAAC,IAAI;QACjB,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,UAAU,EAAE,IAAI,CAAC,UAAU;KAC5B,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Near-identical callout styles (#873): two styles are compared on what
|
|
3
|
+
* the engine resolves them to, field by field (a Dimension and a colour
|
|
4
|
+
* are one field each), leaving out their id and name. Lengths count as
|
|
5
|
+
* equal within a tolerance in mm, colours within a ΔE, so a box ported at
|
|
6
|
+
* 3.98 mm of padding and one at 4 mm read as the same box.
|
|
7
|
+
*
|
|
8
|
+
* The suggestions group every style with the most used one it differs
|
|
9
|
+
* from in at most `maxFields` fields: «these 3 styles differ only in
|
|
10
|
+
* padding: merge?».
|
|
11
|
+
*/
|
|
12
|
+
import { type CalloutStyleConfig, type ResolvedCalloutStyleConfig } from '../../index.js';
|
|
13
|
+
import { type StyleUsage } from './styleUsage.js';
|
|
14
|
+
/** The fields a frame ignores (DESIGN §2.4: its rectangle comes from the
|
|
15
|
+
* template) plus the space around a box set in the flow: where the box
|
|
16
|
+
* stands, not what it looks like. */
|
|
17
|
+
export declare const POSITION_FIELDS: ReadonlySet<string>;
|
|
18
|
+
export interface CompareOptions {
|
|
19
|
+
/** Most settings two styles may differ in and still be suggested (the
|
|
20
|
+
* four sides of a padding count once). Default 2
|
|
21
|
+
* (the four sides of a padding). */
|
|
22
|
+
maxFields?: number;
|
|
23
|
+
/** Lengths within this many millimetres are equal. Default 0.5. */
|
|
24
|
+
lengthMm?: number;
|
|
25
|
+
/** Colours within this CIE76 ΔE are equal. Default 2. */
|
|
26
|
+
deltaE?: number;
|
|
27
|
+
/** Compare styles used by `:::callout` boxes on their look only,
|
|
28
|
+
* leaving where the box stands out (merging then moves boxes). Styles
|
|
29
|
+
* only frames use are always compared so. Default false. */
|
|
30
|
+
ignorePosition?: boolean;
|
|
31
|
+
/** Pixels per inch of `px` lengths (the page's). Default 96. */
|
|
32
|
+
dpi?: number;
|
|
33
|
+
/** Size of an `em` in points (the body text's), for an `em` length
|
|
34
|
+
* against an absolute one. Default 10. */
|
|
35
|
+
emPt?: number;
|
|
36
|
+
}
|
|
37
|
+
export type StyleLeaf = {
|
|
38
|
+
kind: 'length';
|
|
39
|
+
value: number;
|
|
40
|
+
unit: string;
|
|
41
|
+
} | {
|
|
42
|
+
kind: 'color';
|
|
43
|
+
hex: string;
|
|
44
|
+
} | {
|
|
45
|
+
kind: 'value';
|
|
46
|
+
json: string;
|
|
47
|
+
};
|
|
48
|
+
/** The fields of a resolved style, by dotted path. */
|
|
49
|
+
export declare function styleFields(style: ResolvedCalloutStyleConfig | CalloutStyleConfig): Map<string, StyleLeaf>;
|
|
50
|
+
/** `#rgb`, `#rrggbb` or `#rrggbbaa` as 0–1 channels; null for anything else
|
|
51
|
+
* (`transparent`, a name). */
|
|
52
|
+
export declare function parseHex(hex: string): {
|
|
53
|
+
r: number;
|
|
54
|
+
g: number;
|
|
55
|
+
b: number;
|
|
56
|
+
a: number;
|
|
57
|
+
} | null;
|
|
58
|
+
/** How many settings `paths` are, the sides of a padding counting once. */
|
|
59
|
+
export declare function countFields(paths: readonly string[]): number;
|
|
60
|
+
/** The top-level key of a field path (`padding.left` → `padding`). */
|
|
61
|
+
export declare function fieldGroup(path: string): string;
|
|
62
|
+
/** The fields two styles differ in, sorted; `position: false` leaves out
|
|
63
|
+
* the fields that say where the box stands. */
|
|
64
|
+
export declare function styleDiff(a: Map<string, StyleLeaf>, b: Map<string, StyleLeaf>, options?: CompareOptions & {
|
|
65
|
+
position?: boolean;
|
|
66
|
+
}): string[];
|
|
67
|
+
/** Whether `paths` are all colours on both sides: two styles of one shape
|
|
68
|
+
* in different tints (#976). A field one style has and the other lacks
|
|
69
|
+
* is a difference in shape. */
|
|
70
|
+
export declare function onlyColours(paths: readonly string[], a: Map<string, StyleLeaf>, b: Map<string, StyleLeaf>): boolean;
|
|
71
|
+
export interface MergeSuggestion {
|
|
72
|
+
/** The style kept: the most used of the group. */
|
|
73
|
+
keep: string;
|
|
74
|
+
/** The styles merged into it, in list order. */
|
|
75
|
+
merge: string[];
|
|
76
|
+
/** Every field a merged style differs from the kept one in. */
|
|
77
|
+
fields: string[];
|
|
78
|
+
/** Their top-level keys (`padding`, `body`…), sorted. */
|
|
79
|
+
groups: string[];
|
|
80
|
+
/** `:::callout` boxes that stand elsewhere once their style is the kept
|
|
81
|
+
* one (their style placed them differently). */
|
|
82
|
+
moves: number;
|
|
83
|
+
}
|
|
84
|
+
/** Groups of near-identical styles, each led by the style it would keep.
|
|
85
|
+
* `resolved[i]` is `styles[i]` as the engine resolves it. Built-in
|
|
86
|
+
* internal styles (`__postext-…`) never take part. */
|
|
87
|
+
export declare function mergeSuggestions(styles: readonly CalloutStyleConfig[], resolved: readonly ResolvedCalloutStyleConfig[], usage: ReadonlyMap<string, StyleUsage>, options?: CompareOptions): MergeSuggestion[];
|
|
88
|
+
export interface StyleKind {
|
|
89
|
+
/** The style the others are variants of: the most used of the group. */
|
|
90
|
+
base: string;
|
|
91
|
+
variants: {
|
|
92
|
+
id: string;
|
|
93
|
+
/** Based on the kind's base (`extends`), however far up. */
|
|
94
|
+
extendsBase: boolean;
|
|
95
|
+
/** The fields it sets differently from the base (colours only, for a
|
|
96
|
+
* style not based on it). */
|
|
97
|
+
fields: string[];
|
|
98
|
+
/** Their top-level keys, sorted. */
|
|
99
|
+
groups: string[];
|
|
100
|
+
}[];
|
|
101
|
+
}
|
|
102
|
+
/** The kinds of box a book has (#976): styles that extend another, or
|
|
103
|
+
* differ from it only in colours (a box in seven tints), grouped under the
|
|
104
|
+
* most used of them. A style that is nobody's variant has no entry. The
|
|
105
|
+
* merge suggestions leave these out: a variant is not a duplicate. */
|
|
106
|
+
export declare function styleKinds(styles: readonly CalloutStyleConfig[], resolved: readonly ResolvedCalloutStyleConfig[], usage: ReadonlyMap<string, StyleUsage>, options?: CompareOptions): StyleKind[];
|
|
107
|
+
/** How many styles a book keeps once every suggestion is taken. */
|
|
108
|
+
export declare function stylesAfterMerging(styleCount: number, suggestions: readonly MergeSuggestion[]): number;
|
|
109
|
+
/** The settings (top-level keys) two styles differ in, past the
|
|
110
|
+
* tolerances, where the box stands included. */
|
|
111
|
+
export declare function differingGroups(a: ResolvedCalloutStyleConfig | CalloutStyleConfig, b: ResolvedCalloutStyleConfig | CalloutStyleConfig, options?: CompareOptions): string[];
|
|
112
|
+
//# sourceMappingURL=styleCompare.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"styleCompare.d.ts","sourceRoot":"","sources":["../../../src/review/frameStyles/styleCompare.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAwC,KAAK,kBAAkB,EAAE,KAAK,0BAA0B,EAAE,MAAM,gBAAgB,CAAC;AAChI,OAAO,EAA2B,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE3E;;sCAEsC;AACtC,eAAO,MAAM,eAAe,EAAE,WAAW,CAAC,MAAM,CAE9C,CAAC;AAKH,MAAM,WAAW,cAAc;IAC7B;;yCAEqC;IACrC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,mEAAmE;IACnE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,yDAAyD;IACzD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;iEAE6D;IAC7D,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,gEAAgE;IAChE,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;+CAC2C;IAC3C,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,MAAM,SAAS,GACjB;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC/C;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3
|
+
* the engine resolves them to, field by field (a Dimension and a colour
|
|
4
|
+
* are one field each), leaving out their id and name. Lengths count as
|
|
5
|
+
* equal within a tolerance in mm, colours within a ΔE, so a box ported at
|
|
6
|
+
* 3.98 mm of padding and one at 4 mm read as the same box.
|
|
7
|
+
*
|
|
8
|
+
* The suggestions group every style with the most used one it differs
|
|
9
|
+
* from in at most `maxFields` fields: «these 3 styles differ only in
|
|
10
|
+
* padding: merge?».
|
|
11
|
+
*/
|
|
12
|
+
import { calloutStyleChain, srgbToLab, deltaE } from '../../index.js';
|
|
13
|
+
import { framesOnly, usageWeight } from './styleUsage.js';
|
|
14
|
+
/** The fields a frame ignores (DESIGN §2.4: its rectangle comes from the
|
|
15
|
+
* template) plus the space around a box set in the flow: where the box
|
|
16
|
+
* stands, not what it looks like. */
|
|
17
|
+
export const POSITION_FIELDS = new Set([
|
|
18
|
+
'placement', 'span', 'columns', 'sideAtColumnEnd', 'fixed', 'floatBarrier', 'width', 'marginTop', 'marginBottom', 'snapToGrid',
|
|
19
|
+
]);
|
|
20
|
+
/** Never compared: what names the style. */
|
|
21
|
+
const NAMING_FIELDS = new Set(['id', 'name']);
|
|
22
|
+
const MM_PER = { mm: 1, cm: 10, in: 25.4, pt: 25.4 / 72, pc: 25.4 / 6 };
|
|
23
|
+
function isDimension(v) {
|
|
24
|
+
return !!v && typeof v === 'object' && !Array.isArray(v) && typeof v.value === 'number' && typeof v.unit === 'string';
|
|
25
|
+
}
|
|
26
|
+
function isColor(v) {
|
|
27
|
+
return !!v && typeof v === 'object' && !Array.isArray(v) && typeof v.hex === 'string';
|
|
28
|
+
}
|
|
29
|
+
/** The fields of a resolved style, by dotted path. */
|
|
30
|
+
export function styleFields(style) {
|
|
31
|
+
const out = new Map();
|
|
32
|
+
const walk = (v, path) => {
|
|
33
|
+
if (v === undefined)
|
|
34
|
+
return;
|
|
35
|
+
if (isDimension(v))
|
|
36
|
+
out.set(path, { kind: 'length', value: v.value, unit: v.unit });
|
|
37
|
+
else if (isColor(v))
|
|
38
|
+
out.set(path, { kind: 'color', hex: v.hex.toLowerCase() });
|
|
39
|
+
else if (v && typeof v === 'object' && !Array.isArray(v)) {
|
|
40
|
+
for (const [k, child] of Object.entries(v))
|
|
41
|
+
walk(child, path ? `${path}.${k}` : k);
|
|
42
|
+
}
|
|
43
|
+
else
|
|
44
|
+
out.set(path, { kind: 'value', json: JSON.stringify(v) });
|
|
45
|
+
};
|
|
46
|
+
for (const [k, v] of Object.entries(style)) {
|
|
47
|
+
if (!NAMING_FIELDS.has(k))
|
|
48
|
+
walk(v, k);
|
|
49
|
+
}
|
|
50
|
+
// What an unset colour shows: bold and italic words in the body's
|
|
51
|
+
// colour. Whether the list colour was written out (`colorSet`) is no
|
|
52
|
+
// look of its own: the colour is compared.
|
|
53
|
+
const body = out.get('body.color');
|
|
54
|
+
if (body) {
|
|
55
|
+
if (!out.has('body.boldColor'))
|
|
56
|
+
out.set('body.boldColor', body);
|
|
57
|
+
if (!out.has('body.italicColor'))
|
|
58
|
+
out.set('body.italicColor', body);
|
|
59
|
+
}
|
|
60
|
+
out.delete('lists.colorSet');
|
|
61
|
+
return out;
|
|
62
|
+
}
|
|
63
|
+
/** `#rgb`, `#rrggbb` or `#rrggbbaa` as 0–1 channels; null for anything else
|
|
64
|
+
* (`transparent`, a name). */
|
|
65
|
+
export function parseHex(hex) {
|
|
66
|
+
const m = /^#([0-9a-f]{3,8})$/i.exec(hex.trim());
|
|
67
|
+
if (!m)
|
|
68
|
+
return null;
|
|
69
|
+
let h = m[1];
|
|
70
|
+
if (h.length === 3 || h.length === 4)
|
|
71
|
+
h = h.split('').map((c) => c + c).join('');
|
|
72
|
+
if (h.length !== 6 && h.length !== 8)
|
|
73
|
+
return null;
|
|
74
|
+
const n = (i) => parseInt(h.slice(i, i + 2), 16) / 255;
|
|
75
|
+
return { r: n(0), g: n(2), b: n(4), a: h.length === 8 ? n(6) : 1 };
|
|
76
|
+
}
|
|
77
|
+
function sameColor(a, b, maxDeltaE) {
|
|
78
|
+
if (a === b)
|
|
79
|
+
return true;
|
|
80
|
+
const p = parseHex(a);
|
|
81
|
+
const q = parseHex(b);
|
|
82
|
+
if (!p || !q)
|
|
83
|
+
return false;
|
|
84
|
+
if (Math.abs(p.a - q.a) > 0.02)
|
|
85
|
+
return false;
|
|
86
|
+
return deltaE(srgbToLab(p.r, p.g, p.b), srgbToLab(q.r, q.g, q.b)) <= maxDeltaE;
|
|
87
|
+
}
|
|
88
|
+
/** A length in mm; null for a relative one with no size to read it by. */
|
|
89
|
+
function lengthMm(l, dpi, emPt) {
|
|
90
|
+
const per = MM_PER[l.unit];
|
|
91
|
+
if (per !== undefined)
|
|
92
|
+
return l.value * per;
|
|
93
|
+
if (l.unit === 'px')
|
|
94
|
+
return (l.value / dpi) * 25.4;
|
|
95
|
+
if (l.unit === 'em' || l.unit === 'rem')
|
|
96
|
+
return l.value * emPt * MM_PER.pt;
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
function sameLeaf(a, b, o) {
|
|
100
|
+
if (!a || !b)
|
|
101
|
+
return a === b;
|
|
102
|
+
if (a.kind === 'length' && b.kind === 'length') {
|
|
103
|
+
if (a.unit === b.unit && a.value === b.value)
|
|
104
|
+
return true;
|
|
105
|
+
const x = lengthMm(a, o.dpi, o.emPt);
|
|
106
|
+
const y = lengthMm(b, o.dpi, o.emPt);
|
|
107
|
+
if (x === null || y === null)
|
|
108
|
+
return a.unit === b.unit && Math.abs(a.value - b.value) < 1e-9;
|
|
109
|
+
return Math.abs(x - y) <= o.lengthMm + 1e-9;
|
|
110
|
+
}
|
|
111
|
+
if (a.kind === 'color' && b.kind === 'color')
|
|
112
|
+
return sameColor(a.hex, b.hex, o.deltaE);
|
|
113
|
+
if (a.kind === 'value' && b.kind === 'value')
|
|
114
|
+
return a.json === b.json;
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
function withDefaults(o = {}) {
|
|
118
|
+
return {
|
|
119
|
+
maxFields: o.maxFields ?? 2,
|
|
120
|
+
lengthMm: o.lengthMm ?? 0.5,
|
|
121
|
+
deltaE: o.deltaE ?? 2,
|
|
122
|
+
ignorePosition: o.ignorePosition ?? false,
|
|
123
|
+
dpi: o.dpi ?? 96,
|
|
124
|
+
emPt: o.emPt ?? 10,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
/** Settings edited as one: the four sides of a padding. */
|
|
128
|
+
const ONE_SETTING = /^(padding|label\.padding|marker\.padding)\.(top|right|bottom|left)$/;
|
|
129
|
+
/** How many settings `paths` are, the sides of a padding counting once. */
|
|
130
|
+
export function countFields(paths) {
|
|
131
|
+
return new Set(paths.map((p) => p.replace(ONE_SETTING, '$1'))).size;
|
|
132
|
+
}
|
|
133
|
+
/** The top-level key of a field path (`padding.left` → `padding`). */
|
|
134
|
+
export function fieldGroup(path) {
|
|
135
|
+
const dot = path.indexOf('.');
|
|
136
|
+
return dot < 0 ? path : path.slice(0, dot);
|
|
137
|
+
}
|
|
138
|
+
/** The fields two styles differ in, sorted; `position: false` leaves out
|
|
139
|
+
* the fields that say where the box stands. */
|
|
140
|
+
export function styleDiff(a, b, options = {}) {
|
|
141
|
+
const o = withDefaults(options);
|
|
142
|
+
const out = [];
|
|
143
|
+
for (const path of new Set([...a.keys(), ...b.keys()])) {
|
|
144
|
+
if (options.position === false && POSITION_FIELDS.has(fieldGroup(path)))
|
|
145
|
+
continue;
|
|
146
|
+
if (!sameLeaf(a.get(path), b.get(path), o))
|
|
147
|
+
out.push(path);
|
|
148
|
+
}
|
|
149
|
+
return out.sort();
|
|
150
|
+
}
|
|
151
|
+
/** Whether `paths` are all colours on both sides: two styles of one shape
|
|
152
|
+
* in different tints (#976). A field one style has and the other lacks
|
|
153
|
+
* is a difference in shape. */
|
|
154
|
+
export function onlyColours(paths, a, b) {
|
|
155
|
+
return paths.length > 0 && paths.every((p) => a.get(p)?.kind === 'color' && b.get(p)?.kind === 'color');
|
|
156
|
+
}
|
|
157
|
+
/** The ids of the styles a style is based on (`extends`), nearest first. */
|
|
158
|
+
function basesOf(styles, index) {
|
|
159
|
+
return calloutStyleChain(styles, index).chain.slice(1).map((i) => styles[i].id);
|
|
160
|
+
}
|
|
161
|
+
/** Groups of near-identical styles, each led by the style it would keep.
|
|
162
|
+
* `resolved[i]` is `styles[i]` as the engine resolves it. Built-in
|
|
163
|
+
* internal styles (`__postext-…`) never take part. */
|
|
164
|
+
export function mergeSuggestions(styles, resolved, usage, options = {}) {
|
|
165
|
+
const o = withDefaults(options);
|
|
166
|
+
const items = styles
|
|
167
|
+
.map((s, index) => ({ id: s.id, index, fields: styleFields(resolved[index] ?? s), weight: usageWeight(usage.get(s.id)), framesOnly: framesOnly(usage.get(s.id)) }))
|
|
168
|
+
.filter((s) => !s.id.startsWith('__postext-'));
|
|
169
|
+
// A style that differs from another in colours only is a tint of it
|
|
170
|
+
// (#976), a variant of one kind and not a duplicate: it is left out of
|
|
171
|
+
// the suggestions (see `styleKinds`).
|
|
172
|
+
// Seeds: the most used first, then list order.
|
|
173
|
+
const order = [...items].sort((x, y) => y.weight - x.weight || x.index - y.index);
|
|
174
|
+
const taken = new Set();
|
|
175
|
+
const out = [];
|
|
176
|
+
for (const seed of order) {
|
|
177
|
+
if (taken.has(seed.id))
|
|
178
|
+
continue;
|
|
179
|
+
const members = [];
|
|
180
|
+
for (const other of items) {
|
|
181
|
+
if (other.id === seed.id || taken.has(other.id))
|
|
182
|
+
continue;
|
|
183
|
+
// Where a box stands counts unless both styles take it from frames.
|
|
184
|
+
const position = !(o.ignorePosition || (seed.framesOnly && other.framesOnly));
|
|
185
|
+
const full = styleDiff(seed.fields, other.fields, o);
|
|
186
|
+
const placed = full.some((p) => POSITION_FIELDS.has(fieldGroup(p)));
|
|
187
|
+
// A box of the text that would stand elsewhere is no near twin.
|
|
188
|
+
if (position && placed)
|
|
189
|
+
continue;
|
|
190
|
+
const diff = full.filter((p) => !POSITION_FIELDS.has(fieldGroup(p)));
|
|
191
|
+
if (onlyColours(diff, seed.fields, other.fields))
|
|
192
|
+
continue;
|
|
193
|
+
if (countFields(diff) > o.maxFields)
|
|
194
|
+
continue;
|
|
195
|
+
// Its boxes in the text take the kept style's place.
|
|
196
|
+
const moved = !other.framesOnly && placed;
|
|
197
|
+
members.push({ id: other.id, index: other.index, diff, moves: moved ? usage.get(other.id)?.fenceCount ?? 0 : 0 });
|
|
198
|
+
}
|
|
199
|
+
if (members.length === 0)
|
|
200
|
+
continue;
|
|
201
|
+
taken.add(seed.id);
|
|
202
|
+
for (const m of members)
|
|
203
|
+
taken.add(m.id);
|
|
204
|
+
const fields = [...new Set(members.flatMap((m) => m.diff))].sort();
|
|
205
|
+
out.push({
|
|
206
|
+
keep: seed.id,
|
|
207
|
+
merge: members.sort((x, y) => x.index - y.index).map((m) => m.id),
|
|
208
|
+
fields,
|
|
209
|
+
groups: [...new Set(fields.map(fieldGroup))].sort(),
|
|
210
|
+
moves: members.reduce((n, m) => n + m.moves, 0),
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
return out;
|
|
214
|
+
}
|
|
215
|
+
/** The kinds of box a book has (#976): styles that extend another, or
|
|
216
|
+
* differ from it only in colours (a box in seven tints), grouped under the
|
|
217
|
+
* most used of them. A style that is nobody's variant has no entry. The
|
|
218
|
+
* merge suggestions leave these out: a variant is not a duplicate. */
|
|
219
|
+
export function styleKinds(styles, resolved, usage, options = {}) {
|
|
220
|
+
const o = withDefaults(options);
|
|
221
|
+
const items = styles
|
|
222
|
+
.map((s, index) => ({ id: s.id, index, fields: styleFields(resolved[index] ?? s), weight: usageWeight(usage.get(s.id)), bases: basesOf(styles, index) }))
|
|
223
|
+
.filter((s) => !s.id.startsWith('__postext-'));
|
|
224
|
+
const order = [...items].sort((x, y) => y.weight - x.weight || x.index - y.index);
|
|
225
|
+
const taken = new Set();
|
|
226
|
+
const out = [];
|
|
227
|
+
for (const seed of order) {
|
|
228
|
+
if (taken.has(seed.id))
|
|
229
|
+
continue;
|
|
230
|
+
const variants = [];
|
|
231
|
+
for (const other of items) {
|
|
232
|
+
if (other.id === seed.id || taken.has(other.id))
|
|
233
|
+
continue;
|
|
234
|
+
const extendsBase = other.bases.includes(seed.id);
|
|
235
|
+
const diff = styleDiff(seed.fields, other.fields, { ...o, position: false });
|
|
236
|
+
// A style with nothing to tell it from its base is a duplicate (a
|
|
237
|
+
// merge suggestion), not a variant.
|
|
238
|
+
if (diff.length === 0)
|
|
239
|
+
continue;
|
|
240
|
+
if (!extendsBase && !onlyColours(diff, seed.fields, other.fields))
|
|
241
|
+
continue;
|
|
242
|
+
variants.push({ id: other.id, extendsBase, fields: diff, groups: [...new Set(diff.map(fieldGroup))].sort() });
|
|
243
|
+
}
|
|
244
|
+
if (variants.length === 0)
|
|
245
|
+
continue;
|
|
246
|
+
taken.add(seed.id);
|
|
247
|
+
for (const v of variants)
|
|
248
|
+
taken.add(v.id);
|
|
249
|
+
out.push({ base: seed.id, variants });
|
|
250
|
+
}
|
|
251
|
+
return out;
|
|
252
|
+
}
|
|
253
|
+
/** How many styles a book keeps once every suggestion is taken. */
|
|
254
|
+
export function stylesAfterMerging(styleCount, suggestions) {
|
|
255
|
+
return styleCount - suggestions.reduce((n, s) => n + s.merge.length, 0);
|
|
256
|
+
}
|
|
257
|
+
/** The settings (top-level keys) two styles differ in, past the
|
|
258
|
+
* tolerances, where the box stands included. */
|
|
259
|
+
export function differingGroups(a, b, options = {}) {
|
|
260
|
+
return [...new Set(styleDiff(styleFields(a), styleFields(b), options).map(fieldGroup))].sort();
|
|
261
|
+
}
|
|
262
|
+
//# sourceMappingURL=styleCompare.js.map
|