@sushichan044/kg-core 0.5.0 → 0.6.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.mjs CHANGED
@@ -1544,7 +1544,7 @@ function defineMatchRule(options) {
1544
1544
  }
1545
1545
  //#endregion
1546
1546
  //#region src/proofreading/rules/consistent-kanji-opening.ts
1547
- const RULE_ID$4 = "kg/consistent-kanji-opening";
1547
+ const RULE_ID$5 = "kg/consistent-kanji-opening";
1548
1548
  const MESSAGE = "「{{ closed }}」と「{{ opened }}」が混在しています。文脈上の使い分けか表記ゆれかを確認してください";
1549
1549
  const KanjiOpeningPairSchema = v.pipe(readonlyObject({
1550
1550
  closed: v.pipe(v.string(), v.nonEmpty()),
@@ -1597,8 +1597,8 @@ const DEFAULT_PAIRS = [
1597
1597
  * Reports the first kanji occurrence of every pair the manuscript also writes in kana. Whether the
1598
1598
  * two spellings are a deliberate distinction is the author's call, so the finding is a warning.
1599
1599
  */
1600
- function build$2(pairs) {
1601
- return defineParsedRule(RULE_ID$4, MESSAGE, (manuscript, report) => {
1600
+ function build$3(pairs) {
1601
+ return defineParsedRule(RULE_ID$5, MESSAGE, (manuscript, report) => {
1602
1602
  for (const { closed, opened } of pairs) {
1603
1603
  if (!manuscript.displayText.includes(opened)) continue;
1604
1604
  const index = manuscript.displayText.indexOf(closed);
@@ -1613,17 +1613,17 @@ function build$2(pairs) {
1613
1613
  }
1614
1614
  });
1615
1615
  }
1616
- const consistentKanjiOpeningRule = () => build$2(DEFAULT_PAIRS);
1616
+ const consistentKanjiOpeningRule = () => build$3(DEFAULT_PAIRS);
1617
1617
  function createConsistentKanjiOpeningRule(options = {}) {
1618
1618
  if (options.pairs === void 0) return ManuscriptResult.succeed(consistentKanjiOpeningRule());
1619
1619
  const pairs = v.safeParse(PairsSchema, options.pairs);
1620
1620
  if (!pairs.success) return ManuscriptResult.fail({
1621
1621
  kind: "InvalidRuleOptions",
1622
- ruleId: RULE_ID$4,
1622
+ ruleId: RULE_ID$5,
1623
1623
  option: "pairs",
1624
1624
  issues: ValidationIssue.from(pairs.issues)
1625
1625
  });
1626
- return ManuscriptResult.succeed(build$2(pairs.output));
1626
+ return ManuscriptResult.succeed(build$3(pairs.output));
1627
1627
  }
1628
1628
  //#endregion
1629
1629
  //#region src/proofreading/rules/internal/mixed-width.ts
@@ -1663,16 +1663,64 @@ const consistentNumeralWidthRule = () => defineMixedWidthRule({
1663
1663
  fullwidth: /[0-9]/u
1664
1664
  });
1665
1665
  //#endregion
1666
- //#region src/proofreading/rules/dash-character.ts
1667
- /**
1668
- * Stand-ins for `―`. Repeated `ー` belongs to `kg/no-consecutive-choonpu` and `−` to
1669
- * `kg/minus-before-number`, so neither is reported twice.
1670
- */
1671
- const dashCharacterRule = () => defineMatchRule({
1672
- id: "kg/dash-character",
1673
- pattern: /[—–─━﹣-]+|-{2,}/gu,
1674
- message: "ダッシュには「―」を使ってください"
1675
- });
1666
+ //#region src/proofreading/rules/dash.ts
1667
+ const RULE_ID$4 = "kg/dash";
1668
+ const DEFAULT_PREFERRED = "―";
1669
+ const DashCharacterSchema = v.picklist([
1670
+ "―",
1671
+ "—",
1672
+ "─"
1673
+ ]);
1674
+ const DASH_LIKE_RUN = /[—–―─━﹣--]+/gu;
1675
+ const EVEN_COUNT_MESSAGE = "連続するダッシュの数は偶数にしてください";
1676
+ function messageIdFor(run, preferred) {
1677
+ if (run === "-") return void 0;
1678
+ if (run !== preferred.repeat(run.length)) return "character";
1679
+ return run.length % 2 === 1 ? "even-count" : void 0;
1680
+ }
1681
+ function build$2(preferred) {
1682
+ const messages = {
1683
+ character: `ダッシュには「${preferred}」を使ってください`,
1684
+ "even-count": EVEN_COUNT_MESSAGE
1685
+ };
1686
+ return {
1687
+ kind: "parsed",
1688
+ meta: {
1689
+ id: RULE_ID$4,
1690
+ messages
1691
+ },
1692
+ check: (manuscript, context) => {
1693
+ for (const line of splitDisplayLines(manuscript.displayText)) {
1694
+ DASH_LIKE_RUN.lastIndex = 0;
1695
+ let match = DASH_LIKE_RUN.exec(line.text);
1696
+ while (match !== null) {
1697
+ const run = match[0];
1698
+ const messageId = messageIdFor(run, preferred);
1699
+ if (messageId !== void 0) {
1700
+ const start = line.start + match.index;
1701
+ context.report({
1702
+ range: displayRange(manuscript, start, start + run.length),
1703
+ messageId
1704
+ });
1705
+ }
1706
+ match = DASH_LIKE_RUN.exec(line.text);
1707
+ }
1708
+ }
1709
+ }
1710
+ };
1711
+ }
1712
+ const dashRule = () => build$2(DEFAULT_PREFERRED);
1713
+ function createDashRule(options = {}) {
1714
+ if (options.preferred === void 0) return ManuscriptResult.succeed(dashRule());
1715
+ const preferred = v.safeParse(DashCharacterSchema, options.preferred);
1716
+ if (!preferred.success) return ManuscriptResult.fail({
1717
+ kind: "InvalidRuleOptions",
1718
+ ruleId: RULE_ID$4,
1719
+ option: "preferred",
1720
+ issues: ValidationIssue.from(preferred.issues)
1721
+ });
1722
+ return ManuscriptResult.succeed(build$2(preferred.output));
1723
+ }
1676
1724
  //#endregion
1677
1725
  //#region src/proofreading/rules/ellipsis-character.ts
1678
1726
  /**
@@ -1685,14 +1733,6 @@ const ellipsisCharacterRule = () => defineMatchRule({
1685
1733
  message: "三点リーダーには「…」を使ってください"
1686
1734
  });
1687
1735
  //#endregion
1688
- //#region src/proofreading/rules/even-dash.ts
1689
- const evenDashRule = () => defineMatchRule({
1690
- id: "kg/even-dash",
1691
- pattern: /―+/gu,
1692
- accept: (match) => match[0].length % 2 === 1,
1693
- message: "連続するダッシュの数は偶数にしてください"
1694
- });
1695
- //#endregion
1696
1736
  //#region src/proofreading/rules/even-ellipsis.ts
1697
1737
  const evenEllipsisRule = () => defineMatchRule({
1698
1738
  id: "kg/even-ellipsis",
@@ -1798,13 +1838,6 @@ const minusBeforeNumberRule = () => defineMatchRule({
1798
1838
  message: "マイナス記号の直後には数字が必要です"
1799
1839
  });
1800
1840
  //#endregion
1801
- //#region src/proofreading/rules/no-consecutive-choonpu.ts
1802
- const noConsecutiveChoonpuRule = () => defineMatchRule({
1803
- id: "kg/no-consecutive-choonpu",
1804
- pattern: /ーー+/gu,
1805
- message: "長音符が連続しています"
1806
- });
1807
- //#endregion
1808
1841
  //#region src/proofreading/rules/no-consecutive-interpunct.ts
1809
1842
  const noConsecutiveInterpunctRule = () => defineMatchRule({
1810
1843
  id: "kg/no-consecutive-interpunct",
@@ -1999,12 +2032,10 @@ function createDefaultProofreadingRules() {
1999
2032
  punctuationBeforeClosingQuoteRule(),
2000
2033
  spaceAfterQuestionOrExclamationRule(),
2001
2034
  evenEllipsisRule(),
2002
- evenDashRule(),
2035
+ dashRule(),
2003
2036
  ellipsisCharacterRule(),
2004
- dashCharacterRule(),
2005
2037
  noConsecutivePunctuationRule(),
2006
2038
  noConsecutiveInterpunctRule(),
2007
- noConsecutiveChoonpuRule(),
2008
2039
  minusBeforeNumberRule(),
2009
2040
  maxArabicNumeralDigitsRule(),
2010
2041
  fullwidthJapanesePunctuationRule(),
@@ -2012,4 +2043,4 @@ function createDefaultProofreadingRules() {
2012
2043
  ];
2013
2044
  }
2014
2045
  //#endregion
2015
- export { BoldAnnotation, ComposeError, CompositionStatistics, DiagnosticOrigin, DiagnosticSeverity, DisplayRange, EmphasisAnnotation, FontPreset, FontPresetId, FontSizePt, GraphemeRange, GridCell, GridLine, GridPage, GridSettings, GridStage, InvalidRuleOptions, ItalicAnnotation, LineOffset, ManuscriptAnnotation, ManuscriptAppearanceSettings, ManuscriptCompositionSettings, ManuscriptDiagnostic, ManuscriptGeometry, ManuscriptGridLayout, ManuscriptOffsets, ManuscriptRange, ManuscriptResult, NamespacedId, PaperSize, PaperSizeId, ParseError, ParsedGrapheme, ParsedManuscript, ProofreadError, ProofreadingReport, ProofreadingRuleMeta, Rejection, RubyAnnotation, SourcePosition, SourceRange, TextRange, ValidationIssue, assertNever, composeManuscript, consistentKanjiOpeningRule, consistentLatinWidthRule, consistentNumeralWidthRule, createConsistentKanjiOpeningRule, createDefaultProofreadingRules, createMaxArabicNumeralDigitsRule, createParagraphOpeningRule, dashCharacterRule, ellipsisCharacterRule, evenDashRule, evenEllipsisRule, fullwidthJapanesePunctuationRule, kakuyomuParser, manuscriptGridComposer, maxArabicNumeralDigitsRule, minusBeforeNumberRule, mmToPt, noConsecutiveChoonpuRule, noConsecutiveInterpunctRule, noConsecutivePunctuationRule, paragraphOpeningRule, parseManuscript, pixivParser, plainTextParser, proofreadManuscript, ptToMm, punctuationBeforeClosingQuoteRule, spaceAfterQuestionOrExclamationRule, variantCharacterRule };
2046
+ export { BoldAnnotation, ComposeError, CompositionStatistics, DiagnosticOrigin, DiagnosticSeverity, DisplayRange, EmphasisAnnotation, FontPreset, FontPresetId, FontSizePt, GraphemeRange, GridCell, GridLine, GridPage, GridSettings, GridStage, InvalidRuleOptions, ItalicAnnotation, LineOffset, ManuscriptAnnotation, ManuscriptAppearanceSettings, ManuscriptCompositionSettings, ManuscriptDiagnostic, ManuscriptGeometry, ManuscriptGridLayout, ManuscriptOffsets, ManuscriptRange, ManuscriptResult, NamespacedId, PaperSize, PaperSizeId, ParseError, ParsedGrapheme, ParsedManuscript, ProofreadError, ProofreadingReport, ProofreadingRuleMeta, Rejection, RubyAnnotation, SourcePosition, SourceRange, TextRange, ValidationIssue, assertNever, composeManuscript, consistentKanjiOpeningRule, consistentLatinWidthRule, consistentNumeralWidthRule, createConsistentKanjiOpeningRule, createDashRule, createDefaultProofreadingRules, createMaxArabicNumeralDigitsRule, createParagraphOpeningRule, dashRule, ellipsisCharacterRule, evenEllipsisRule, fullwidthJapanesePunctuationRule, kakuyomuParser, manuscriptGridComposer, maxArabicNumeralDigitsRule, minusBeforeNumberRule, mmToPt, noConsecutiveInterpunctRule, noConsecutivePunctuationRule, paragraphOpeningRule, parseManuscript, pixivParser, plainTextParser, proofreadManuscript, ptToMm, punctuationBeforeClosingQuoteRule, spaceAfterQuestionOrExclamationRule, variantCharacterRule };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sushichan044/kg-core",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "Framework-independent parsing, composition, and proofreading for Japanese manuscripts",
5
5
  "keywords": [
6
6
  "japanese",