@sushichan044/kg-core 0.10.2 → 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.
@@ -99,6 +99,24 @@ const ParsedManuscript = {
99
99
  })))
100
100
  };
101
101
  //#endregion
102
+ //#region src/appearance/a5-page-format.ts
103
+ const A5_PAGE_FORMAT = {
104
+ fontSizeQ: 12.7,
105
+ flow: {
106
+ lineLengthEm: 27,
107
+ linesPerStage: 23,
108
+ stagesPerPage: 2
109
+ },
110
+ page: {
111
+ lineGapMm: 1.825,
112
+ stageGapMm: 10,
113
+ topMm: 12,
114
+ bottomMm: 16.55,
115
+ innerMm: 21.825,
116
+ outerMm: 13
117
+ }
118
+ };
119
+ //#endregion
102
120
  //#region src/appearance/font-preset-id.ts
103
121
  const FontPresetIdSchema = v.picklist(["mincho", "gothic"]);
104
122
  const FontPresetId = {
@@ -106,17 +124,11 @@ const FontPresetId = {
106
124
  is: (value) => v.is(FontPresetIdSchema, value)
107
125
  };
108
126
  //#endregion
109
- //#region src/appearance/font-size-pt.ts
110
- const RANGE = {
111
- min: 6,
112
- max: 24,
113
- step: .5
114
- };
115
- const FontSizePtSchema = v.pipe(v.number(), v.finite(), v.minValue(RANGE.min), v.maxValue(RANGE.max), v.multipleOf(RANGE.step));
116
- const FontSizePt = {
117
- schema: FontSizePtSchema,
118
- range: RANGE,
119
- is: (value) => v.is(FontSizePtSchema, value)
127
+ //#region src/appearance/font-size-q.ts
128
+ const FontSizeQSchema = v.pipe(v.number(), v.finite(), v.minValue(Number.MIN_VALUE));
129
+ const FontSizeQ = {
130
+ schema: FontSizeQSchema,
131
+ is: (value) => v.is(FontSizeQSchema, value)
120
132
  };
121
133
  //#endregion
122
134
  //#region src/appearance/paper-size-id.ts
@@ -135,12 +147,12 @@ const PaperSizeId = {
135
147
  const ManuscriptAppearanceSettings = {
136
148
  schema: readonlyObject({
137
149
  paperSize: PaperSizeId.schema,
138
- fontSizePt: FontSizePt.schema,
150
+ fontSizeQ: FontSizeQ.schema,
139
151
  fontPreset: FontPresetId.schema
140
152
  }),
141
153
  defaults: {
142
154
  paperSize: "a5",
143
- fontSizePt: 9,
155
+ fontSizeQ: A5_PAGE_FORMAT.fontSizeQ,
144
156
  fontPreset: "mincho"
145
157
  }
146
158
  };
@@ -152,6 +164,110 @@ const LineOffset = {
152
164
  total: (offset) => offset.leading + offset.trailing
153
165
  };
154
166
  //#endregion
167
+ //#region src/appearance/paper-size.ts
168
+ const PAPER_SIZES = {
169
+ a4: {
170
+ id: "a4",
171
+ label: "A4",
172
+ widthMm: 210,
173
+ heightMm: 297
174
+ },
175
+ a5: {
176
+ id: "a5",
177
+ label: "A5",
178
+ widthMm: 148,
179
+ heightMm: 210
180
+ },
181
+ a6: {
182
+ id: "a6",
183
+ label: "A6(文庫)",
184
+ widthMm: 105,
185
+ heightMm: 148
186
+ },
187
+ "jis-b5": {
188
+ id: "jis-b5",
189
+ label: "B5(JIS)",
190
+ widthMm: 182,
191
+ heightMm: 257
192
+ },
193
+ "jis-b6": {
194
+ id: "jis-b6",
195
+ label: "B6(JIS)",
196
+ widthMm: 128,
197
+ heightMm: 182
198
+ },
199
+ shinsho: {
200
+ id: "shinsho",
201
+ label: "新書",
202
+ widthMm: 106,
203
+ heightMm: 173
204
+ }
205
+ };
206
+ const PaperSize = {
207
+ of: (id) => PAPER_SIZES[id],
208
+ all: Object.values(PAPER_SIZES)
209
+ };
210
+ //#endregion
211
+ //#region src/composer/page-settings.ts
212
+ const length$1 = () => v.pipe(v.number(), v.finite(), v.minValue(0));
213
+ const ManuscriptPageSettings = {
214
+ schema: readonlyObject({
215
+ lineGapMm: length$1(),
216
+ stageGapMm: length$1(),
217
+ topMm: length$1(),
218
+ bottomMm: length$1(),
219
+ innerMm: length$1(),
220
+ outerMm: length$1()
221
+ }),
222
+ defaults: A5_PAGE_FORMAT.page,
223
+ /**
224
+ * Centre a non-A5 text grid using half-cell line gaps and two-cell stage gaps.
225
+ */
226
+ centered: (flow, appearance) => {
227
+ const cell = appearance.fontSizeQ / 4;
228
+ const paper = PaperSize.of(appearance.paperSize);
229
+ const lineGapMm = cell / 2;
230
+ const stageGapMm = cell * 2;
231
+ const horizontal = (paper.widthMm - flow.linesPerStage * cell - (flow.linesPerStage - 1) * lineGapMm) / 2;
232
+ const vertical = (paper.heightMm - flow.stagesPerPage * flow.lineLengthEm * cell - (flow.stagesPerPage - 1) * stageGapMm) / 2;
233
+ return {
234
+ lineGapMm,
235
+ stageGapMm,
236
+ topMm: vertical,
237
+ bottomMm: vertical,
238
+ innerMm: horizontal,
239
+ outerMm: horizontal
240
+ };
241
+ }
242
+ };
243
+ //#endregion
244
+ //#region src/composer/manuscript-geometry.ts
245
+ const length = () => v.pipe(v.number(), v.finite(), v.minValue(0));
246
+ const ManuscriptGeometry = {
247
+ schema: readonlyObject({
248
+ ...ManuscriptPageSettings.schema.entries,
249
+ paperWidthMm: length(),
250
+ paperHeightMm: length(),
251
+ cellSizeMm: length(),
252
+ fontSizeQ: FontSizeQ.schema,
253
+ contentWidthMm: length(),
254
+ contentHeightMm: length()
255
+ }),
256
+ of: (flow, appearance, page) => {
257
+ const paper = PaperSize.of(appearance.paperSize);
258
+ const cellSizeMm = appearance.fontSizeQ / 4;
259
+ return {
260
+ ...page,
261
+ paperWidthMm: paper.widthMm,
262
+ paperHeightMm: paper.heightMm,
263
+ cellSizeMm,
264
+ fontSizeQ: appearance.fontSizeQ,
265
+ contentWidthMm: flow.linesPerStage * cellSizeMm + (flow.linesPerStage - 1) * page.lineGapMm,
266
+ contentHeightMm: flow.stagesPerPage * flow.lineLengthEm * cellSizeMm + (flow.stagesPerPage - 1) * page.stageGapMm
267
+ };
268
+ }
269
+ };
270
+ //#endregion
155
271
  //#region src/composer/manuscript-offsets.ts
156
272
  const MAX_DOCUMENT_OFFSET = 1e4;
157
273
  const ManuscriptOffsets = {
@@ -210,25 +326,49 @@ const NovelFlowSettings = {
210
326
  stagesPerPage: boundedCount(RANGES.stagesPerPage)
211
327
  }),
212
328
  ranges: RANGES,
213
- defaults: {
214
- lineLengthEm: 27,
215
- linesPerStage: 23,
216
- stagesPerPage: 2
217
- }
329
+ defaults: A5_PAGE_FORMAT.flow
218
330
  };
219
331
  //#endregion
220
332
  //#region src/composer/composition-settings.ts
221
333
  const NovelCompositionSettingsSchema = v.pipe(readonlyObject({
222
334
  flow: NovelFlowSettings.schema,
223
335
  offsets: ManuscriptOffsets.schema,
224
- appearance: ManuscriptAppearanceSettings.schema
225
- }), v.check(({ flow, offsets }) => LineOffset.total(offsets.stage) <= ManuscriptOffsets.maxStageTotal(flow) && LineOffset.total(offsets.page) <= ManuscriptOffsets.maxPageTotal(flow, offsets.stage), "page or stage offsets leave no usable novel lines"));
336
+ appearance: ManuscriptAppearanceSettings.schema,
337
+ page: ManuscriptPageSettings.schema
338
+ }), v.check(({ flow, offsets }) => LineOffset.total(offsets.stage) <= ManuscriptOffsets.maxStageTotal(flow) && LineOffset.total(offsets.page) <= ManuscriptOffsets.maxPageTotal(flow, offsets.stage), "page or stage offsets leave no usable novel lines"), v.check(({ flow, appearance, page }) => {
339
+ const geometry = ManuscriptGeometry.of(flow, appearance, page);
340
+ return Math.abs(geometry.contentHeightMm + page.topMm + page.bottomMm - geometry.paperHeightMm) <= 1e-6 && Math.abs(geometry.contentWidthMm + page.innerMm + page.outerMm - geometry.paperWidthMm) <= 1e-6;
341
+ }, "text dimensions and margins must match the paper dimensions"), v.check(({ appearance, page }) => page.lineGapMm + 1e-6 >= appearance.fontSizeQ / 8, "line gap must leave room for half-size annotations"), v.check(({ flow, appearance, page }) => appearance.paperSize !== "a5" || appearance.fontSizeQ === A5_PAGE_FORMAT.fontSizeQ && flow.lineLengthEm === A5_PAGE_FORMAT.flow.lineLengthEm && flow.linesPerStage === A5_PAGE_FORMAT.flow.linesPerStage && flow.stagesPerPage === A5_PAGE_FORMAT.flow.stagesPerPage && page.lineGapMm === A5_PAGE_FORMAT.page.lineGapMm && page.stageGapMm === A5_PAGE_FORMAT.page.stageGapMm && page.topMm === A5_PAGE_FORMAT.page.topMm && page.bottomMm === A5_PAGE_FORMAT.page.bottomMm && page.innerMm === A5_PAGE_FORMAT.page.innerMm && page.outerMm === A5_PAGE_FORMAT.page.outerMm, "A5 uses the fixed 12.7Q, 27-character, 23-line, two-stage format"));
226
342
  const NovelCompositionSettings = {
227
343
  schema: NovelCompositionSettingsSchema,
228
344
  defaults: {
229
345
  flow: NovelFlowSettings.defaults,
230
346
  offsets: ManuscriptOffsets.defaults,
231
- appearance: ManuscriptAppearanceSettings.defaults
347
+ appearance: ManuscriptAppearanceSettings.defaults,
348
+ page: ManuscriptPageSettings.defaults
349
+ },
350
+ /**
351
+ * Select the fixed A5 format, or centre the current grid on another paper size.
352
+ */
353
+ forPaper: (paperSize, settings) => {
354
+ const appearance = {
355
+ ...settings.appearance,
356
+ paperSize
357
+ };
358
+ if (paperSize === "a5") return {
359
+ ...settings,
360
+ flow: A5_PAGE_FORMAT.flow,
361
+ appearance: {
362
+ ...appearance,
363
+ fontSizeQ: A5_PAGE_FORMAT.fontSizeQ
364
+ },
365
+ page: A5_PAGE_FORMAT.page
366
+ };
367
+ return {
368
+ ...settings,
369
+ appearance,
370
+ page: ManuscriptPageSettings.centered(settings.flow, appearance)
371
+ };
232
372
  },
233
373
  is: (value) => v.is(NovelCompositionSettingsSchema, value)
234
374
  };
@@ -1749,7 +1889,7 @@ const MeasurementSession = { create: (provider, settings) => {
1749
1889
  kind,
1750
1890
  presentation,
1751
1891
  fontPreset: settings.appearance.fontPreset,
1752
- fontSizePt: settings.appearance.fontSizePt,
1892
+ fontSizeQ: settings.appearance.fontSizeQ,
1753
1893
  scale: 1,
1754
1894
  writingMode: "vertical-rl"
1755
1895
  } : {
@@ -1757,7 +1897,7 @@ const MeasurementSession = { create: (provider, settings) => {
1757
1897
  kind,
1758
1898
  presentation: "mixed",
1759
1899
  fontPreset: settings.appearance.fontPreset,
1760
- fontSizePt: settings.appearance.fontSizePt,
1900
+ fontSizeQ: settings.appearance.fontSizeQ,
1761
1901
  scale: defaultBookStyle.annotation.sizeEm,
1762
1902
  writingMode: "vertical-rl"
1763
1903
  };
@@ -2578,121 +2718,6 @@ const SourceSpace = { collect: (graphemes, advancesEm) => {
2578
2718
  return [];
2579
2719
  });
2580
2720
  } };
2581
- //#endregion
2582
- //#region src/appearance/paper-size.ts
2583
- const PAPER_SIZES = {
2584
- a4: {
2585
- id: "a4",
2586
- label: "A4",
2587
- widthMm: 210,
2588
- heightMm: 297
2589
- },
2590
- a5: {
2591
- id: "a5",
2592
- label: "A5",
2593
- widthMm: 148,
2594
- heightMm: 210
2595
- },
2596
- a6: {
2597
- id: "a6",
2598
- label: "A6(文庫)",
2599
- widthMm: 105,
2600
- heightMm: 148
2601
- },
2602
- "jis-b5": {
2603
- id: "jis-b5",
2604
- label: "B5(JIS)",
2605
- widthMm: 182,
2606
- heightMm: 257
2607
- },
2608
- "jis-b6": {
2609
- id: "jis-b6",
2610
- label: "B6(JIS)",
2611
- widthMm: 128,
2612
- heightMm: 182
2613
- },
2614
- shinsho: {
2615
- id: "shinsho",
2616
- label: "新書",
2617
- widthMm: 106,
2618
- heightMm: 173
2619
- }
2620
- };
2621
- const PaperSize = {
2622
- of: (id) => PAPER_SIZES[id],
2623
- all: Object.values(PAPER_SIZES)
2624
- };
2625
- //#endregion
2626
- //#region src/internal/length.ts
2627
- const PT_PER_MM = 72 / 25.4;
2628
- function ptToMm(pt) {
2629
- return pt / PT_PER_MM;
2630
- }
2631
- function mmToPt(mm) {
2632
- return mm * PT_PER_MM;
2633
- }
2634
- //#endregion
2635
- //#region src/composer/manuscript-geometry.ts
2636
- const STAGE_GAP_CELLS = 2;
2637
- const LINE_GAP_CELLS = .5;
2638
- const nonNegativeLength = () => v.pipe(v.number(), v.finite(), v.minValue(0));
2639
- const ManuscriptGeometrySchema = readonlyObject({
2640
- paperWidthMm: nonNegativeLength(),
2641
- paperHeightMm: nonNegativeLength(),
2642
- cellSizeMm: nonNegativeLength(),
2643
- lineGapMm: nonNegativeLength(),
2644
- fontSizePt: FontSizePt.schema,
2645
- contentWidthMm: nonNegativeLength(),
2646
- contentHeightMm: nonNegativeLength(),
2647
- marginInlineMm: v.pipe(v.number(), v.finite()),
2648
- marginBlockMm: v.pipe(v.number(), v.finite()),
2649
- fitsPaper: v.boolean()
2650
- });
2651
- /**
2652
- * Every stage stacked vertically, plus the gap between adjacent stages.
2653
- */
2654
- function contentHeightInEm(flow) {
2655
- return flow.stagesPerPage * flow.lineLengthEm + STAGE_GAP_CELLS * (flow.stagesPerPage - 1);
2656
- }
2657
- /**
2658
- * Every vertical line side by side, plus the gap between adjacent lines.
2659
- */
2660
- function contentWidthInEm(flow) {
2661
- return flow.linesPerStage + LINE_GAP_CELLS * (flow.linesPerStage - 1);
2662
- }
2663
- const ManuscriptGeometry = {
2664
- schema: ManuscriptGeometrySchema,
2665
- of: (flow, appearance) => {
2666
- const paper = PaperSize.of(appearance.paperSize);
2667
- const cellSizeMm = ptToMm(appearance.fontSizePt);
2668
- const contentWidthMm = contentWidthInEm(flow) * cellSizeMm;
2669
- const contentHeightMm = contentHeightInEm(flow) * cellSizeMm;
2670
- const marginInlineMm = (paper.widthMm - contentWidthMm) / 2;
2671
- const marginBlockMm = (paper.heightMm - contentHeightMm) / 2;
2672
- return {
2673
- paperWidthMm: paper.widthMm,
2674
- paperHeightMm: paper.heightMm,
2675
- cellSizeMm,
2676
- lineGapMm: LINE_GAP_CELLS * cellSizeMm,
2677
- fontSizePt: appearance.fontSizePt,
2678
- contentWidthMm,
2679
- contentHeightMm,
2680
- marginInlineMm,
2681
- marginBlockMm,
2682
- fitsPaper: marginInlineMm >= 0 && marginBlockMm >= 0
2683
- };
2684
- },
2685
- /**
2686
- * The largest step-aligned point size whose text area still fits the paper.
2687
- */
2688
- maxFontSizePt: (flow, paperSizeId) => {
2689
- const paper = PaperSize.of(paperSizeId);
2690
- const maxCellSizeMm = Math.min(paper.widthMm / contentWidthInEm(flow), paper.heightMm / contentHeightInEm(flow));
2691
- const steps = Math.floor(mmToPt(maxCellSizeMm) / FontSizePt.range.step + 1e-9);
2692
- const aligned = Math.round(steps * FontSizePt.range.step * 1e3) / 1e3;
2693
- return Math.min(FontSizePt.range.max, Math.max(FontSizePt.range.min, aligned));
2694
- }
2695
- };
2696
2721
  const CompositionStatistics = { schema: readonlyObject({
2697
2722
  chars: nonNegativeInteger(),
2698
2723
  sourceLines: nonNegativeInteger(),
@@ -3400,7 +3425,7 @@ function createCompose(provider) {
3400
3425
  ], settings);
3401
3426
  return ManuscriptResult.succeed({
3402
3427
  pages,
3403
- geometry: ManuscriptGeometry.of(settings.flow, settings.appearance),
3428
+ geometry: ManuscriptGeometry.of(settings.flow, settings.appearance, settings.page),
3404
3429
  stats: {
3405
3430
  chars: sourceLines.reduce((total, line) => total + line.length, 0),
3406
3431
  sourceLines: sourceLines.length,
@@ -3419,4 +3444,4 @@ function createNovelComposer(options) {
3419
3444
  }
3420
3445
  const novelComposer = createNovelComposer({ measurer: logicalRunMeasurer });
3421
3446
  //#endregion
3422
- export { PaperSize as a, MeasurementTextRange as c, ManuscriptOffsets as d, ManuscriptAppearanceSettings as f, ParsedManuscript as g, FontPresetId as h, ManuscriptGeometry as i, NovelCompositionSettings as l, FontSizePt as m, novelComposer as n, RunMeasurement as o, PaperSizeId as p, logicalRunMeasurer as r, MeasuredCluster as s, createNovelComposer as t, NovelFlowSettings as u };
3447
+ export { ParsedManuscript as _, MeasuredCluster as a, NovelFlowSettings as c, ManuscriptPageSettings as d, PaperSize as f, FontPresetId as g, FontSizeQ as h, RunMeasurement as i, ManuscriptOffsets as l, PaperSizeId as m, novelComposer as n, MeasurementTextRange as o, ManuscriptAppearanceSettings as p, logicalRunMeasurer as r, NovelCompositionSettings as s, createNovelComposer as t, ManuscriptGeometry as u };
package/dist/plugin.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { a as ManuscriptResult, i as ParsedManuscript, n as ValidationIssue, r as NamespacedId } from "./composed-manuscript-C0f3mxKs.mjs";
2
- import { a as RunMeasurer, c as MeasurementRequest, d as ManuscriptComposer, f as ManuscriptParser, o as logicalRunMeasurer, p as Rejection, r as createNovelComposer, s as RunMeasurement, t as PresentationKind } from "./presentation-kind-BwIZFSZS.mjs";
2
+ import { a as RunMeasurer, c as MeasurementRequest, f as ManuscriptComposer, m as Rejection, o as logicalRunMeasurer, p as ManuscriptParser, r as createNovelComposer, s as RunMeasurement, t as PresentationKind } from "./presentation-kind-BCQndPoK.mjs";
3
3
  import * as v from "valibot";
4
4
  //#region src/composer/measurement-text-range.d.ts
5
5
  declare const MeasurementTextRangeSchema: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
package/dist/plugin.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { d as ManuscriptResult, m as NamespacedId, u as ValidationIssue, y as readonlyObject } from "./question-or-exclamation-spacing-C5cFLeKr.mjs";
2
- import { c as MeasurementTextRange, g as ParsedManuscript, h as FontPresetId, m as FontSizePt, o as RunMeasurement, r as logicalRunMeasurer, s as MeasuredCluster, t as createNovelComposer } from "./novel-composer-CHNWyvn8.mjs";
2
+ import { _ as ParsedManuscript, a as MeasuredCluster, g as FontPresetId, h as FontSizeQ, i as RunMeasurement, o as MeasurementTextRange, r as logicalRunMeasurer, t as createNovelComposer } from "./novel-composer-z0cv8OHb.mjs";
3
3
  import * as v from "valibot";
4
4
  const PresentationKind = { schema: v.picklist([
5
5
  "mixed",
@@ -12,7 +12,7 @@ const PresentationKind = { schema: v.picklist([
12
12
  const context = {
13
13
  text: v.string(),
14
14
  fontPreset: FontPresetId.schema,
15
- fontSizePt: FontSizePt.schema,
15
+ fontSizeQ: FontSizeQ.schema,
16
16
  scale: v.pipe(v.number(), v.finite(), v.minValue(Number.MIN_VALUE)),
17
17
  writingMode: v.literal("vertical-rl")
18
18
  };