@dev-pi2pie/word-counter 0.1.3-canary.1 → 0.1.3-canary.2

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.
@@ -474,7 +474,7 @@ function detectLatinLocale(char, context) {
474
474
  }
475
475
  return DEFAULT_LOCALE;
476
476
  }
477
- function detectLocaleForChar(char, previousLocale, options = {}, context = resolveLocaleDetectContext(options)) {
477
+ function detectLocaleForChar(char, previousLocale, options = {}, context = resolveLocaleDetectContext(options), allowLatinLocaleCarry = true, allowJapaneseHanCarry = true) {
478
478
  if (regex.hiragana.test(char) || regex.katakana.test(char)) return "ja";
479
479
  if (regex.hangul.test(char)) return "ko";
480
480
  if (regex.arabic.test(char)) return "ar";
@@ -482,13 +482,13 @@ function detectLocaleForChar(char, previousLocale, options = {}, context = resol
482
482
  if (regex.devanagari.test(char)) return "hi";
483
483
  if (regex.thai.test(char)) return "th";
484
484
  if (regex.han.test(char)) {
485
- if (previousLocale && previousLocale.startsWith("ja")) return previousLocale;
485
+ if (allowJapaneseHanCarry && previousLocale && previousLocale.startsWith("ja")) return previousLocale;
486
486
  return context.hanHint ?? DEFAULT_HAN_TAG;
487
487
  }
488
488
  if (regex.latin.test(char)) {
489
489
  const hintedLocale = detectLatinLocale(char, context);
490
490
  if (hintedLocale !== DEFAULT_LOCALE) return hintedLocale;
491
- if (previousLocale && isLatinLocale(previousLocale, context) && previousLocale !== DEFAULT_LOCALE) return previousLocale;
491
+ if (allowLatinLocaleCarry && previousLocale && isLatinLocale(previousLocale, context) && previousLocale !== DEFAULT_LOCALE) return previousLocale;
492
492
  if (context.latinHint) return context.latinHint;
493
493
  return DEFAULT_LOCALE;
494
494
  }
@@ -497,32 +497,59 @@ function detectLocaleForChar(char, previousLocale, options = {}, context = resol
497
497
 
498
498
  //#endregion
499
499
  //#region src/wc/segment.ts
500
+ const HARD_BOUNDARY_REGEX = /[\r\n,.!?;:,、。!?;:.。、]/u;
501
+ const LATIN_PROMOTION_BREAK_REGEX = /[\s,.!?;:,、。!?;:.。、]/u;
500
502
  function segmentTextByLocale(text, options = {}) {
501
503
  const context = resolveLocaleDetectContext(options);
502
504
  const chunks = [];
503
505
  let currentLocale = DEFAULT_LOCALE;
504
506
  let buffer = "";
505
507
  let bufferHasScript = false;
508
+ let sawCarryBoundary = false;
509
+ const updateCarryBoundaryState = (detected, char) => {
510
+ if (detected !== null) {
511
+ sawCarryBoundary = false;
512
+ return;
513
+ }
514
+ if (HARD_BOUNDARY_REGEX.test(char)) sawCarryBoundary = true;
515
+ };
506
516
  for (const char of text) {
507
- const detected = detectLocaleForChar(char, currentLocale, options, context);
517
+ const detected = detectLocaleForChar(char, currentLocale, options, context, !sawCarryBoundary, !sawCarryBoundary);
508
518
  const targetLocale = detected ?? currentLocale;
509
519
  if (buffer === "") {
510
520
  currentLocale = targetLocale;
511
521
  buffer = char;
512
522
  bufferHasScript = detected !== null;
523
+ updateCarryBoundaryState(detected, char);
513
524
  continue;
514
525
  }
515
526
  if (detected !== null && !bufferHasScript) {
516
527
  currentLocale = targetLocale;
517
528
  buffer += char;
518
529
  bufferHasScript = true;
530
+ updateCarryBoundaryState(detected, char);
519
531
  continue;
520
532
  }
521
533
  if (targetLocale !== currentLocale && detected !== null) {
522
534
  if (currentLocale === DEFAULT_LOCALE && isLatinLocale(targetLocale, context)) {
535
+ const promotionBreakIndex = findLastLatinPromotionBreakIndex(buffer);
536
+ if (promotionBreakIndex === -1) {
537
+ currentLocale = targetLocale;
538
+ buffer += char;
539
+ bufferHasScript = true;
540
+ updateCarryBoundaryState(detected, char);
541
+ continue;
542
+ }
543
+ const prefix = buffer.slice(0, promotionBreakIndex + 1);
544
+ const suffix = buffer.slice(promotionBreakIndex + 1);
545
+ if (prefix.length > 0) chunks.push({
546
+ locale: currentLocale,
547
+ text: prefix
548
+ });
523
549
  currentLocale = targetLocale;
524
- buffer += char;
550
+ buffer = `${suffix}${char}`;
525
551
  bufferHasScript = true;
552
+ updateCarryBoundaryState(detected, char);
526
553
  continue;
527
554
  }
528
555
  chunks.push({
@@ -532,10 +559,12 @@ function segmentTextByLocale(text, options = {}) {
532
559
  currentLocale = targetLocale;
533
560
  buffer = char;
534
561
  bufferHasScript = true;
562
+ updateCarryBoundaryState(detected, char);
535
563
  continue;
536
564
  }
537
565
  buffer += char;
538
566
  if (detected !== null) bufferHasScript = true;
567
+ updateCarryBoundaryState(detected, char);
539
568
  }
540
569
  if (buffer.length > 0) chunks.push({
541
570
  locale: currentLocale,
@@ -543,6 +572,14 @@ function segmentTextByLocale(text, options = {}) {
543
572
  });
544
573
  return mergeAdjacentChunks(chunks);
545
574
  }
575
+ function findLastLatinPromotionBreakIndex(buffer) {
576
+ for (let index = buffer.length - 1; index >= 0; index -= 1) {
577
+ const char = buffer[index];
578
+ if (!char) continue;
579
+ if (LATIN_PROMOTION_BREAK_REGEX.test(char)) return index;
580
+ }
581
+ return -1;
582
+ }
546
583
  function mergeAdjacentChunks(chunks) {
547
584
  if (chunks.length === 0) return chunks;
548
585
  const merged = [];
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["wordCounter","wordCounter"],"sources":["../../src/wc/segmenter.ts","../../src/utils/append-all.ts","../../src/wc/non-words.ts","../../src/wc/analyze.ts","../../src/wc/mode.ts","../../src/wc/latin-hints.ts","../../src/wc/locale-detect.ts","../../src/wc/segment.ts","../../src/wc/wc.ts","../../src/wc/index.ts","../../src/markdown/toml/arrays.ts","../../src/markdown/toml/keys.ts","../../src/markdown/toml/strings.ts","../../src/markdown/toml/values.ts","../../src/markdown/toml/parse-frontmatter.ts","../../src/markdown/parse-markdown.ts","../../src/markdown/section-count.ts","../../src/utils/show-singular-or-plural-word.ts","../../src/index.cjs.ts"],"sourcesContent":["const segmenterCache = new Map<string, Intl.Segmenter>();\nconst graphemeSegmenterCache = new Map<string, Intl.Segmenter>();\n\nexport function getSegmenter(locale: string): Intl.Segmenter {\n const cached = segmenterCache.get(locale);\n if (cached) {\n return cached;\n }\n const segmenter = new Intl.Segmenter(locale, { granularity: \"word\" });\n segmenterCache.set(locale, segmenter);\n return segmenter;\n}\n\nexport function getGraphemeSegmenter(locale: string): Intl.Segmenter {\n const cached = graphemeSegmenterCache.get(locale);\n if (cached) {\n return cached;\n }\n const segmenter = new Intl.Segmenter(locale, { granularity: \"grapheme\" });\n graphemeSegmenterCache.set(locale, segmenter);\n return segmenter;\n}\n\nfunction supportsSegmenter(): boolean {\n return typeof Intl !== \"undefined\" && typeof Intl.Segmenter === \"function\";\n}\n\nexport function countWordsForLocale(text: string, locale: string): number {\n const segmenter = getSegmenter(locale);\n let count = 0;\n for (const segment of segmenter.segment(text)) {\n if (segment.isWordLike) {\n count++;\n }\n }\n return count;\n}\n\nexport function countCharsForLocale(text: string, locale: string): number {\n if (!supportsSegmenter()) {\n return Array.from(text).length;\n }\n const segmenter = getGraphemeSegmenter(locale);\n let count = 0;\n for (const _segment of segmenter.segment(text)) {\n count++;\n }\n return count;\n}\n","export function appendAll<T>(target: T[], source: readonly T[]): void {\n for (const item of source) {\n target.push(item);\n }\n}\n","import type { NonWordCollection, WhitespaceCounts } from \"./types\";\nimport { appendAll } from \"../utils/append-all\";\n\nconst emojiRegex = /(?:\\p{Extended_Pictographic}|\\p{Emoji_Presentation})/u;\nconst emojiPresentationRegex = /\\p{Emoji_Presentation}/u;\nconst keycapEmojiRegex = /[0-9#*]\\uFE0F?\\u20E3/u;\nconst symbolRegex = /\\p{S}/u;\nconst punctuationRegex = /\\p{P}/u;\nconst whitespaceRegex = /\\s/u;\nconst newlineChars = new Set([\"\\n\", \"\\r\", \"\\u2028\", \"\\u2029\"]);\n\nexport function createNonWordCollection(): NonWordCollection {\n return {\n emoji: [],\n symbols: [],\n punctuation: [],\n counts: {\n emoji: 0,\n symbols: 0,\n punctuation: 0,\n },\n };\n}\n\nexport function addNonWord(\n collection: NonWordCollection,\n category: \"emoji\" | \"symbol\" | \"punctuation\",\n segment: string,\n): void {\n if (category === \"emoji\") {\n collection.emoji.push(segment);\n collection.counts.emoji += 1;\n return;\n }\n if (category === \"symbol\") {\n collection.symbols.push(segment);\n collection.counts.symbols += 1;\n return;\n }\n collection.punctuation.push(segment);\n collection.counts.punctuation += 1;\n}\n\nexport function addWhitespace(\n collection: NonWordCollection,\n segment: string,\n): number {\n let whitespace = collection.whitespace;\n let count = 0;\n for (const char of segment) {\n if (char === \" \") {\n whitespace = whitespace ?? createWhitespaceCounts();\n whitespace.spaces += 1;\n count += 1;\n continue;\n }\n if (char === \"\\t\") {\n whitespace = whitespace ?? createWhitespaceCounts();\n whitespace.tabs += 1;\n count += 1;\n continue;\n }\n if (newlineChars.has(char)) {\n whitespace = whitespace ?? createWhitespaceCounts();\n whitespace.newlines += 1;\n count += 1;\n continue;\n }\n if (whitespaceRegex.test(char)) {\n whitespace = whitespace ?? createWhitespaceCounts();\n whitespace.other += 1;\n count += 1;\n }\n }\n\n if (count > 0) {\n collection.whitespace = whitespace ?? createWhitespaceCounts();\n collection.counts.whitespace = (collection.counts.whitespace ?? 0) + count;\n }\n\n return count;\n}\n\nexport function classifyNonWordSegment(\n segment: string,\n): \"emoji\" | \"symbol\" | \"punctuation\" | null {\n const hasEmojiVariationSelector = segment.includes(\"\\uFE0F\");\n if (\n keycapEmojiRegex.test(segment) ||\n emojiPresentationRegex.test(segment) ||\n (hasEmojiVariationSelector && emojiRegex.test(segment))\n ) {\n return \"emoji\";\n }\n if (symbolRegex.test(segment)) {\n return \"symbol\";\n }\n if (punctuationRegex.test(segment)) {\n return \"punctuation\";\n }\n return null;\n}\n\nexport function mergeNonWordCollections(\n target: NonWordCollection,\n source: NonWordCollection,\n): NonWordCollection {\n if (source.counts.emoji > 0) {\n appendAll(target.emoji, source.emoji);\n target.counts.emoji += source.counts.emoji;\n }\n if (source.counts.symbols > 0) {\n appendAll(target.symbols, source.symbols);\n target.counts.symbols += source.counts.symbols;\n }\n if (source.counts.punctuation > 0) {\n appendAll(target.punctuation, source.punctuation);\n target.counts.punctuation += source.counts.punctuation;\n }\n if (source.counts.whitespace && source.counts.whitespace > 0 && source.whitespace) {\n const whitespace = target.whitespace ?? createWhitespaceCounts();\n whitespace.spaces += source.whitespace.spaces;\n whitespace.tabs += source.whitespace.tabs;\n whitespace.newlines += source.whitespace.newlines;\n whitespace.other += source.whitespace.other;\n target.whitespace = whitespace;\n target.counts.whitespace = (target.counts.whitespace ?? 0) + source.counts.whitespace;\n }\n return target;\n}\n\nfunction createWhitespaceCounts(): WhitespaceCounts {\n return { spaces: 0, tabs: 0, newlines: 0, other: 0 };\n}\n","import { countCharsForLocale, getSegmenter } from \"./segmenter\";\nimport {\n addNonWord,\n addWhitespace,\n classifyNonWordSegment,\n createNonWordCollection,\n mergeNonWordCollections,\n} from \"./non-words\";\nimport { appendAll } from \"../utils/append-all\";\nimport type {\n CharCollectorBreakdown,\n ChunkAnalysis,\n CollectorBreakdown,\n LocaleChunk,\n NonWordCollection,\n} from \"./types\";\n\ntype CharAnalysis = LocaleChunk & { chars: number; nonWords?: NonWordCollection };\ntype CharChunkAnalysis = CharAnalysis & { wordChars: number; nonWordChars: number };\n\nexport function analyzeChunk(\n chunk: LocaleChunk,\n collectNonWords?: boolean,\n includeWhitespace?: boolean,\n): ChunkAnalysis {\n const segmenter = getSegmenter(chunk.locale);\n const segments: string[] = [];\n const nonWords: NonWordCollection | null = collectNonWords\n ? createNonWordCollection()\n : null;\n for (const part of segmenter.segment(chunk.text)) {\n if (part.isWordLike) {\n segments.push(part.segment);\n } else if (collectNonWords && nonWords) {\n if (includeWhitespace) {\n addWhitespace(nonWords, part.segment);\n }\n const category = classifyNonWordSegment(part.segment);\n if (category) {\n addNonWord(nonWords, category, part.segment);\n }\n }\n }\n return {\n locale: chunk.locale,\n text: chunk.text,\n segments,\n words: segments.length,\n nonWords: nonWords ?? undefined,\n };\n}\n\nexport function analyzeCharChunk(\n chunk: LocaleChunk,\n collectNonWords?: boolean,\n includeWhitespace?: boolean,\n): CharChunkAnalysis {\n const segmenter = getSegmenter(chunk.locale);\n const nonWords: NonWordCollection | null = collectNonWords\n ? createNonWordCollection()\n : null;\n let chars = 0;\n let wordChars = 0;\n let nonWordChars = 0;\n\n for (const part of segmenter.segment(chunk.text)) {\n if (part.isWordLike) {\n const count = countCharsForLocale(part.segment, chunk.locale);\n chars += count;\n wordChars += count;\n continue;\n }\n\n if (collectNonWords && nonWords) {\n let whitespaceCount = 0;\n if (includeWhitespace) {\n whitespaceCount = addWhitespace(nonWords, part.segment);\n }\n const category = classifyNonWordSegment(part.segment);\n if (category) {\n addNonWord(nonWords, category, part.segment);\n }\n if (category || whitespaceCount > 0) {\n const count = countCharsForLocale(part.segment, chunk.locale);\n chars += count;\n nonWordChars += count;\n }\n }\n }\n\n return {\n locale: chunk.locale,\n text: chunk.text,\n chars,\n wordChars,\n nonWordChars,\n nonWords: nonWords ?? undefined,\n };\n}\n\nexport function aggregateCharsByLocale(\n chunks: CharChunkAnalysis[],\n): Array<CharCollectorBreakdown & { wordChars: number; nonWordChars: number }> {\n const order: string[] = [];\n const map = new Map<\n string,\n CharCollectorBreakdown & { wordChars: number; nonWordChars: number }\n >();\n\n for (const chunk of chunks) {\n const existing = map.get(chunk.locale);\n if (existing) {\n existing.chars += chunk.chars;\n existing.wordChars += chunk.wordChars;\n existing.nonWordChars += chunk.nonWordChars;\n if (chunk.nonWords) {\n if (!existing.nonWords) {\n existing.nonWords = createNonWordCollection();\n }\n mergeNonWordCollections(existing.nonWords, chunk.nonWords);\n }\n continue;\n }\n\n order.push(chunk.locale);\n map.set(chunk.locale, {\n locale: chunk.locale,\n chars: chunk.chars,\n wordChars: chunk.wordChars,\n nonWordChars: chunk.nonWordChars,\n nonWords: chunk.nonWords\n ? mergeNonWordCollections(createNonWordCollection(), chunk.nonWords)\n : undefined,\n });\n }\n\n return order.map((locale) => map.get(locale)!);\n}\n\nexport function aggregateByLocale(\n chunks: ChunkAnalysis[]\n): CollectorBreakdown[] {\n const order: string[] = [];\n const map = new Map<string, CollectorBreakdown>();\n\n for (const chunk of chunks) {\n const existing = map.get(chunk.locale);\n if (existing) {\n existing.words += chunk.words;\n appendAll(existing.segments, chunk.segments);\n continue;\n }\n\n order.push(chunk.locale);\n map.set(chunk.locale, {\n locale: chunk.locale,\n words: chunk.words,\n segments: [...chunk.segments],\n });\n }\n\n return order.map((locale) => map.get(locale)!);\n}\n","import type { WordCounterMode } from \"./types\";\n\nconst MODE_ALIASES: Record<string, WordCounterMode> = {\n chunk: \"chunk\",\n chunks: \"chunk\",\n segments: \"segments\",\n segment: \"segments\",\n seg: \"segments\",\n collector: \"collector\",\n collect: \"collector\",\n colle: \"collector\",\n char: \"char\",\n chars: \"char\",\n character: \"char\",\n characters: \"char\",\n \"char-collector\": \"char-collector\",\n};\n\nconst CHAR_MODE_ALIASES = new Set([\"char\", \"chars\", \"character\", \"characters\"]);\nconst COLLECTOR_MODE_ALIASES = new Set([\"collector\", \"collect\", \"colle\", \"col\"]);\n\nfunction collapseSeparators(value: string): string {\n return value.replace(/[-_\\s]+/g, \"\");\n}\n\nfunction isComposedCharCollectorFromTokens(value: string): boolean {\n const tokens = value\n .split(/[-_\\s]+/)\n .map((token) => token.trim())\n .filter((token) => token.length > 0);\n if (tokens.length < 2) {\n return false;\n }\n\n let hasCharAlias = false;\n let hasCollectorAlias = false;\n for (const token of tokens) {\n if (CHAR_MODE_ALIASES.has(token)) {\n hasCharAlias = true;\n continue;\n }\n if (COLLECTOR_MODE_ALIASES.has(token)) {\n hasCollectorAlias = true;\n continue;\n }\n return false;\n }\n\n return hasCharAlias && hasCollectorAlias;\n}\n\nfunction isComposedCharCollectorCompact(value: string): boolean {\n for (const charAlias of CHAR_MODE_ALIASES) {\n for (const collectorAlias of COLLECTOR_MODE_ALIASES) {\n if (value === `${charAlias}${collectorAlias}` || value === `${collectorAlias}${charAlias}`) {\n return true;\n }\n }\n }\n return false;\n}\n\nexport function normalizeMode(input?: string | null): WordCounterMode | null {\n if (!input) {\n return null;\n }\n const normalized = input.trim().toLowerCase();\n const direct = MODE_ALIASES[normalized];\n if (direct) {\n return direct;\n }\n\n if (isComposedCharCollectorFromTokens(normalized)) {\n return \"char-collector\";\n }\n\n const compact = collapseSeparators(normalized);\n if (isComposedCharCollectorCompact(compact)) {\n return \"char-collector\";\n }\n\n return MODE_ALIASES[compact] ?? null;\n}\n\nexport function resolveMode(\n input?: string | null,\n fallback: WordCounterMode = \"chunk\",\n): WordCounterMode {\n return normalizeMode(input) ?? fallback;\n}\n","import type { LatinHintRule } from \"./types\";\n\nconst DEFAULT_LATIN_HINT_RULES_SOURCE = [\n { tag: \"de\", pattern: \"[äöüÄÖÜß]\" },\n { tag: \"es\", pattern: \"[ñÑ¿¡]\" },\n { tag: \"pt\", pattern: \"[ãõÃÕ]\" },\n { tag: \"fr\", pattern: \"[œŒæÆ]\" },\n { tag: \"pl\", pattern: \"[ąćęłńśźżĄĆĘŁŃŚŹŻ]\" },\n { tag: \"tr\", pattern: \"[ıİğĞşŞ]\" },\n { tag: \"ro\", pattern: \"[ăĂâÂîÎșȘțȚ]\" },\n { tag: \"hu\", pattern: \"[őŐűŰ]\" },\n { tag: \"is\", pattern: \"[ðÐþÞ]\" },\n] satisfies LatinHintRule[];\n\nexport const DEFAULT_LATIN_HINT_RULES: ReadonlyArray<Readonly<LatinHintRule>> = Object.freeze(\n DEFAULT_LATIN_HINT_RULES_SOURCE.map((rule) => Object.freeze({ ...rule })),\n);\n","import type { LatinHintRule } from \"./types\";\nimport { DEFAULT_LATIN_HINT_RULES } from \"./latin-hints\";\n\nexport const DEFAULT_LOCALE = \"und-Latn\";\nexport const DEFAULT_HAN_TAG = \"und-Hani\";\n\nconst MAX_LATIN_HINT_PATTERN_LENGTH = 256;\n\nexport interface LocaleDetectOptions {\n latinLanguageHint?: string;\n latinTagHint?: string;\n latinLocaleHint?: string;\n latinHintRules?: LatinHintRule[];\n useDefaultLatinHints?: boolean;\n hanLanguageHint?: string;\n hanTagHint?: string;\n}\n\ntype ResolvedLatinHintRule = {\n tag: string;\n pattern: RegExp;\n priority: number;\n order: number;\n};\n\nexport type LocaleDetectContext = {\n latinHint?: string;\n hanHint?: string;\n latinHintRules: ResolvedLatinHintRule[];\n latinLocales: Set<string>;\n};\n\nconst regex = {\n hiragana: /\\p{Script=Hiragana}/u,\n katakana: /\\p{Script=Katakana}/u,\n hangul: /\\p{Script=Hangul}/u,\n han: /\\p{Script=Han}/u,\n latin: /\\p{Script=Latin}/u,\n arabic: /\\p{Script=Arabic}/u,\n cyrillic: /\\p{Script=Cyrillic}/u,\n devanagari: /\\p{Script=Devanagari}/u,\n thai: /\\p{Script=Thai}/u,\n};\n\nconst defaultLatinLocales = new Set<string>([\n DEFAULT_LOCALE,\n ...DEFAULT_LATIN_HINT_RULES.map((hint) => hint.tag),\n]);\n\nexport function isLatinLocale(locale: string, context?: LocaleDetectContext): boolean {\n if (context) {\n return context.latinLocales.has(locale);\n }\n return defaultLatinLocales.has(locale);\n}\n\nfunction resolveLatinHint(options: LocaleDetectOptions): string | undefined {\n const latinTagHint = options.latinTagHint?.trim();\n if (latinTagHint) {\n return latinTagHint;\n }\n\n const latinLanguageHint = options.latinLanguageHint?.trim();\n if (latinLanguageHint) {\n return latinLanguageHint;\n }\n\n const latinLocaleHint = options.latinLocaleHint?.trim();\n if (latinLocaleHint) {\n return latinLocaleHint;\n }\n\n return undefined;\n}\n\nfunction resolveHanHint(options: LocaleDetectOptions): string | undefined {\n const hanTagHint = options.hanTagHint?.trim();\n if (hanTagHint) {\n return hanTagHint;\n }\n\n const hanLanguageHint = options.hanLanguageHint?.trim();\n if (hanLanguageHint) {\n return hanLanguageHint;\n }\n\n return undefined;\n}\n\nfunction compileLatinHintPattern(\n pattern: string | RegExp,\n label: string,\n): RegExp {\n const source = typeof pattern === \"string\" ? pattern : pattern.source;\n const hasUnicodeMode =\n typeof pattern !== \"string\" &&\n (pattern.flags.includes(\"u\") || pattern.flags.includes(\"v\"));\n const flags =\n typeof pattern === \"string\"\n ? \"u\"\n : hasUnicodeMode\n ? pattern.flags\n : `${pattern.flags}u`;\n if (source.length === 0) {\n throw new Error(`${label}: pattern must not be empty.`);\n }\n if (source.length > MAX_LATIN_HINT_PATTERN_LENGTH) {\n throw new Error(\n `${label}: pattern must be at most ${MAX_LATIN_HINT_PATTERN_LENGTH} characters.`,\n );\n }\n try {\n return new RegExp(source, flags);\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n throw new Error(`${label}: invalid Unicode regex pattern (${message}).`);\n }\n}\n\nfunction normalizeLatinHintPriority(priority: unknown, label: string): number {\n if (priority === undefined) {\n return 0;\n }\n if (typeof priority !== \"number\" || !Number.isFinite(priority)) {\n throw new Error(`${label}: priority must be a finite number when provided.`);\n }\n return priority;\n}\n\nfunction compileLatinHintRule(\n rule: Readonly<LatinHintRule>,\n order: number,\n label: string,\n): ResolvedLatinHintRule {\n const tag = typeof rule.tag === \"string\" ? rule.tag.trim() : \"\";\n if (!tag) {\n throw new Error(`${label}: tag must be a non-empty string.`);\n }\n const pattern = compileLatinHintPattern(rule.pattern, label);\n const priority = normalizeLatinHintPriority(rule.priority, label);\n return {\n tag,\n pattern,\n priority,\n order,\n };\n}\n\nfunction resolveLatinHintRules(options: LocaleDetectOptions): ResolvedLatinHintRule[] {\n const useDefaultLatinHints = options.useDefaultLatinHints !== false;\n const customRules = options.latinHintRules ?? [];\n const combinedRules: Array<{ rule: Readonly<LatinHintRule>; label: string }> = [];\n\n for (let index = 0; index < customRules.length; index += 1) {\n const rule = customRules[index];\n if (!rule) {\n continue;\n }\n combinedRules.push({\n rule,\n label: `Invalid custom Latin hint rule at index ${index}`,\n });\n }\n\n if (useDefaultLatinHints) {\n for (let index = 0; index < DEFAULT_LATIN_HINT_RULES.length; index += 1) {\n const rule = DEFAULT_LATIN_HINT_RULES[index];\n if (!rule) {\n continue;\n }\n combinedRules.push({\n rule,\n label: `Invalid default Latin hint rule at index ${index}`,\n });\n }\n }\n\n const resolvedRules = combinedRules.map((entry, index) =>\n compileLatinHintRule(entry.rule, index, entry.label),\n );\n\n resolvedRules.sort((left, right) => {\n if (left.priority !== right.priority) {\n return right.priority - left.priority;\n }\n return left.order - right.order;\n });\n\n return resolvedRules;\n}\n\nexport function resolveLocaleDetectContext(\n options: LocaleDetectOptions = {},\n): LocaleDetectContext {\n const latinHint = resolveLatinHint(options);\n const latinHintRules = resolveLatinHintRules(options);\n const latinLocales = new Set<string>([DEFAULT_LOCALE]);\n for (const rule of latinHintRules) {\n latinLocales.add(rule.tag);\n }\n if (latinHint) {\n latinLocales.add(latinHint);\n }\n\n return {\n latinHint,\n hanHint: resolveHanHint(options),\n latinHintRules,\n latinLocales,\n };\n}\n\nfunction detectLatinLocale(char: string, context: LocaleDetectContext): string {\n for (const hint of context.latinHintRules) {\n hint.pattern.lastIndex = 0;\n if (hint.pattern.test(char)) {\n return hint.tag;\n }\n }\n return DEFAULT_LOCALE;\n}\n\nexport function detectLocaleForChar(\n char: string,\n previousLocale?: string | null,\n options: LocaleDetectOptions = {},\n context: LocaleDetectContext = resolveLocaleDetectContext(options),\n): string | null {\n if (regex.hiragana.test(char) || regex.katakana.test(char)) {\n return \"ja\";\n }\n if (regex.hangul.test(char)) {\n return \"ko\";\n }\n if (regex.arabic.test(char)) {\n return \"ar\";\n }\n if (regex.cyrillic.test(char)) {\n return \"ru\";\n }\n if (regex.devanagari.test(char)) {\n return \"hi\";\n }\n if (regex.thai.test(char)) {\n return \"th\";\n }\n\n if (regex.han.test(char)) {\n if (previousLocale && previousLocale.startsWith(\"ja\")) {\n return previousLocale;\n }\n return context.hanHint ?? DEFAULT_HAN_TAG;\n }\n\n if (regex.latin.test(char)) {\n const hintedLocale = detectLatinLocale(char, context);\n if (hintedLocale !== DEFAULT_LOCALE) {\n return hintedLocale;\n }\n if (previousLocale && isLatinLocale(previousLocale, context) && previousLocale !== DEFAULT_LOCALE) {\n return previousLocale;\n }\n if (context.latinHint) {\n return context.latinHint;\n }\n return DEFAULT_LOCALE;\n }\n\n return null;\n}\n","import {\n DEFAULT_LOCALE,\n detectLocaleForChar,\n isLatinLocale,\n resolveLocaleDetectContext,\n type LocaleDetectOptions,\n} from \"./locale-detect\";\nimport type { LocaleChunk } from \"./types\";\n\nexport function segmentTextByLocale(\n text: string,\n options: LocaleDetectOptions = {}\n): LocaleChunk[] {\n const context = resolveLocaleDetectContext(options);\n const chunks: LocaleChunk[] = [];\n // Keep currentLocale as a non-null string to simplify type-narrowing.\n let currentLocale: string = DEFAULT_LOCALE;\n let buffer = \"\";\n let bufferHasScript = false;\n\n for (const char of text) {\n const detected = detectLocaleForChar(char, currentLocale, options, context);\n const targetLocale = detected ?? currentLocale;\n\n // If buffer is empty, this is the first character for a new chunk.\n if (buffer === \"\") {\n currentLocale = targetLocale;\n buffer = char;\n bufferHasScript = detected !== null;\n continue;\n }\n\n if (detected !== null && !bufferHasScript) {\n currentLocale = targetLocale;\n buffer += char;\n bufferHasScript = true;\n continue;\n }\n\n if (targetLocale !== currentLocale && detected !== null) {\n if (currentLocale === DEFAULT_LOCALE && isLatinLocale(targetLocale, context)) {\n currentLocale = targetLocale;\n buffer += char;\n bufferHasScript = true;\n continue;\n }\n // currentLocale is guaranteed to be a string here.\n chunks.push({ locale: currentLocale, text: buffer });\n currentLocale = targetLocale;\n buffer = char;\n bufferHasScript = true;\n continue;\n }\n\n buffer += char;\n if (detected !== null) {\n bufferHasScript = true;\n }\n }\n\n if (buffer.length > 0) {\n chunks.push({ locale: currentLocale, text: buffer });\n }\n\n return mergeAdjacentChunks(chunks);\n}\n\nfunction mergeAdjacentChunks(chunks: LocaleChunk[]): LocaleChunk[] {\n if (chunks.length === 0) {\n return chunks;\n }\n\n const merged: LocaleChunk[] = [];\n // We already returned for empty arrays above, so the first element is present.\n let last = chunks[0]!;\n\n for (let i = 1; i < chunks.length; i++) {\n const chunk = chunks[i]!;\n if (chunk.locale === last.locale) {\n last = { locale: last.locale, text: last.text + chunk.text };\n } else {\n merged.push(last);\n last = chunk;\n }\n }\n\n merged.push(last);\n return merged;\n}\n","import {\n analyzeCharChunk,\n analyzeChunk,\n aggregateByLocale,\n aggregateCharsByLocale,\n} from \"./analyze\";\nimport { resolveMode } from \"./mode\";\nimport { segmentTextByLocale } from \"./segment\";\nimport { countCharsForLocale, countWordsForLocale } from \"./segmenter\";\nimport { createNonWordCollection, mergeNonWordCollections } from \"./non-words\";\nimport type {\n CharBreakdown,\n CharCollectorBreakdown,\n ChunkBreakdown,\n ChunkWithSegments,\n NonWordCollection,\n WordCounterMode,\n WordCounterOptions,\n WordCounterResult,\n} from \"./types\";\n\nexport type {\n LatinHintRule,\n NonWordCollection,\n WordCounterMode,\n WordCounterOptions,\n WordCounterResult,\n WordCounterBreakdown,\n} from \"./types\";\n\nexport { countCharsForLocale, countWordsForLocale, segmentTextByLocale };\nexport { DEFAULT_LATIN_HINT_RULES } from \"./latin-hints\";\n\nexport function wordCounter(\n text: string,\n options: WordCounterOptions = {}\n): WordCounterResult {\n const mode: WordCounterMode = resolveMode(options.mode, \"chunk\");\n const collectNonWords = Boolean(options.nonWords);\n const includeWhitespace = Boolean(options.includeWhitespace);\n const chunks = segmentTextByLocale(text, {\n latinLanguageHint: options.latinLanguageHint,\n latinTagHint: options.latinTagHint,\n latinLocaleHint: options.latinLocaleHint,\n latinHintRules: options.latinHintRules,\n useDefaultLatinHints: options.useDefaultLatinHints,\n hanLanguageHint: options.hanLanguageHint,\n hanTagHint: options.hanTagHint,\n });\n\n if (mode === \"char\" || mode === \"char-collector\") {\n const analyzed = chunks.map((chunk) =>\n analyzeCharChunk(chunk, collectNonWords, includeWhitespace),\n );\n const total = analyzed.reduce((sum, chunk) => sum + chunk.chars, 0);\n const counts = collectNonWords\n ? {\n words: analyzed.reduce((sum, chunk) => sum + chunk.wordChars, 0),\n nonWords: analyzed.reduce((sum, chunk) => sum + chunk.nonWordChars, 0),\n total,\n }\n : undefined;\n\n if (mode === \"char\") {\n const items: CharBreakdown[] = analyzed.map((chunk) => ({\n locale: chunk.locale,\n text: chunk.text,\n chars: chunk.chars,\n nonWords: chunk.nonWords,\n }));\n return {\n total,\n counts,\n breakdown: {\n mode,\n items,\n },\n };\n }\n\n const aggregated = aggregateCharsByLocale(analyzed);\n const items: CharCollectorBreakdown[] = aggregated.map((chunk) => ({\n locale: chunk.locale,\n chars: chunk.chars,\n nonWords: chunk.nonWords,\n }));\n return {\n total,\n counts,\n breakdown: {\n mode,\n items,\n },\n };\n }\n\n const analyzed = chunks.map((chunk) =>\n analyzeChunk(chunk, collectNonWords, includeWhitespace),\n );\n const wordsTotal = analyzed.reduce((sum, chunk) => sum + chunk.words, 0);\n const nonWordsTotal = collectNonWords\n ? analyzed.reduce((sum, chunk) => {\n if (!chunk.nonWords) {\n return sum;\n }\n return sum + getNonWordTotal(chunk.nonWords);\n }, 0)\n : 0;\n const total = analyzed.reduce((sum, chunk) => {\n let chunkTotal = chunk.words;\n if (collectNonWords && chunk.nonWords) {\n chunkTotal += getNonWordTotal(chunk.nonWords);\n }\n return sum + chunkTotal;\n }, 0);\n\n const counts = collectNonWords ? { words: wordsTotal, nonWords: nonWordsTotal, total } : undefined;\n\n if (mode === \"segments\") {\n const items: ChunkWithSegments[] = analyzed.map((chunk) => ({\n locale: chunk.locale,\n text: chunk.text,\n words: chunk.words,\n segments: chunk.segments,\n nonWords: chunk.nonWords,\n }));\n return {\n total,\n counts,\n breakdown: {\n mode,\n items,\n },\n };\n }\n\n if (mode === \"collector\") {\n const items = aggregateByLocale(analyzed);\n const nonWords = collectNonWordsAggregate(analyzed, collectNonWords);\n return {\n total,\n counts,\n breakdown: {\n mode,\n items,\n nonWords,\n },\n };\n }\n\n const items: ChunkBreakdown[] = analyzed.map((chunk) => ({\n locale: chunk.locale,\n text: chunk.text,\n words: chunk.words,\n nonWords: chunk.nonWords,\n }));\n\n return {\n total,\n counts,\n breakdown: {\n mode,\n items,\n },\n };\n}\n\nfunction getNonWordTotal(nonWords: NonWordCollection): number {\n return (\n nonWords.counts.emoji +\n nonWords.counts.symbols +\n nonWords.counts.punctuation +\n (nonWords.counts.whitespace ?? 0)\n );\n}\n\n\nfunction collectNonWordsAggregate(\n analyzed: Array<{ nonWords?: NonWordCollection }>,\n enabled: boolean,\n): NonWordCollection | undefined {\n if (!enabled) {\n return undefined;\n }\n const collection = createNonWordCollection();\n for (const chunk of analyzed) {\n if (!chunk.nonWords) {\n continue;\n }\n mergeNonWordCollections(collection, chunk.nonWords);\n }\n return collection;\n}\n","import { wordCounter } from \"./wc\";\n\nexport default wordCounter;\nexport { countCharsForLocale, countWordsForLocale, segmentTextByLocale } from \"./wc\";\nexport { DEFAULT_LATIN_HINT_RULES } from \"./wc\";\nexport type {\n LatinHintRule,\n NonWordCollection,\n WordCounterMode,\n WordCounterOptions,\n WordCounterResult,\n WordCounterBreakdown,\n} from \"./wc\";\n","export function ensureArrayContainer(\n result: Record<string, unknown>,\n key: string,\n): Record<string, unknown>[] {\n const existing = result[key];\n if (Array.isArray(existing)) {\n return existing as Record<string, unknown>[];\n }\n const list: Record<string, unknown>[] = [];\n result[key] = list;\n return list;\n}\n\nexport function flattenArrayTables(result: Record<string, unknown>): void {\n for (const [key, value] of Object.entries(result)) {\n if (!Array.isArray(value)) {\n continue;\n }\n const flattened = value\n .map((entry) =>\n Object.entries(entry)\n .map(([entryKey, entryValue]) => `${entryKey}=${entryValue}`)\n .join(\", \"),\n )\n .join(\" | \");\n result[key] = flattened;\n }\n}\n","function stripKeyQuotes(key: string): string {\n const trimmed = key.trim();\n if (\n (trimmed.startsWith(\"\\\"\") && trimmed.endsWith(\"\\\"\")) ||\n (trimmed.startsWith(\"'\") && trimmed.endsWith(\"'\"))\n ) {\n return trimmed.slice(1, -1);\n }\n return trimmed;\n}\n\nexport function normalizeKeyPath(key: string): string | null {\n const trimmed = key.trim();\n if (!trimmed) {\n return null;\n }\n\n if (\n (trimmed.startsWith(\"\\\"\") && trimmed.endsWith(\"\\\"\")) ||\n (trimmed.startsWith(\"'\") && trimmed.endsWith(\"'\"))\n ) {\n const unquoted = stripKeyQuotes(trimmed);\n return unquoted ? unquoted : null;\n }\n\n const segments = trimmed.split(\".\").map((segment) => segment.trim());\n if (segments.some((segment) => !segment)) {\n return null;\n }\n return segments.join(\".\");\n}\n","export function stripInlineComment(line: string): string {\n let inString: \"single\" | \"double\" | null = null;\n let escaped = false;\n\n for (let i = 0; i < line.length; i += 1) {\n const char = line[i] ?? \"\";\n\n if (inString) {\n if (escaped) {\n escaped = false;\n continue;\n }\n\n if (char === \"\\\\\" && inString === \"double\") {\n escaped = true;\n continue;\n }\n\n if (inString === \"double\" && char === \"\\\"\") {\n inString = null;\n continue;\n }\n\n if (inString === \"single\" && char === \"'\") {\n inString = null;\n continue;\n }\n\n continue;\n }\n\n if (char === \"\\\"\") {\n inString = \"double\";\n continue;\n }\n\n if (char === \"'\") {\n inString = \"single\";\n continue;\n }\n\n if (char === \"#\") {\n return line.slice(0, i).trimEnd();\n }\n }\n\n return line;\n}\n\nfunction unescapeBasic(input: string): string {\n return input\n .replace(/\\\\\\\\/g, \"\\\\\")\n .replace(/\\\\\"/g, \"\\\"\")\n .replace(/\\\\n/g, \"\\n\")\n .replace(/\\\\t/g, \"\\t\")\n .replace(/\\\\r/g, \"\\r\");\n}\n\nexport function parseStringLiteral(value: string): string | null {\n if (value.startsWith('\"\"\"') && value.endsWith('\"\"\"')) {\n const inner = value.slice(3, -3);\n return unescapeBasic(inner);\n }\n\n if (value.startsWith(\"'''\") && value.endsWith(\"'''\")) {\n return value.slice(3, -3);\n }\n\n if (value.startsWith(\"\\\"\") && value.endsWith(\"\\\"\")) {\n return unescapeBasic(value.slice(1, -1));\n }\n\n if (value.startsWith(\"'\") && value.endsWith(\"'\")) {\n return value.slice(1, -1);\n }\n\n return null;\n}\n","import { normalizeKeyPath } from \"./keys\";\nimport { parseStringLiteral } from \"./strings\";\nimport type { TomlValue } from \"./types\";\n\nfunction parsePrimitive(raw: string): string | number | boolean | null {\n const value = raw.trim();\n if (!value) {\n return null;\n }\n\n const stringLiteral = parseStringLiteral(value);\n if (stringLiteral !== null) {\n return stringLiteral;\n }\n\n if (value === \"true\") {\n return true;\n }\n\n if (value === \"false\") {\n return false;\n }\n\n if (/^[+-]?\\d+(?:\\.\\d+)?(?:[eE][+-]?\\d+)?$/.test(value)) {\n return Number(value);\n }\n\n if (/^\\d{4}-\\d{2}-\\d{2}/.test(value)) {\n return value;\n }\n\n return value;\n}\n\nfunction parseArray(raw: string): Array<string | number | boolean> | null {\n const value = raw.trim();\n if (!value.startsWith(\"[\") || !value.endsWith(\"]\")) {\n return null;\n }\n\n const inner = value.slice(1, -1).trim();\n if (!inner) {\n return [];\n }\n\n const items: Array<string | number | boolean> = [];\n let current = \"\";\n let inString: \"single\" | \"double\" | null = null;\n let escaped = false;\n\n for (let i = 0; i < inner.length; i += 1) {\n const char = inner[i] ?? \"\";\n\n if (inString) {\n current += char;\n if (escaped) {\n escaped = false;\n continue;\n }\n\n if (char === \"\\\\\" && inString === \"double\") {\n escaped = true;\n continue;\n }\n\n if (inString === \"double\" && char === \"\\\"\") {\n inString = null;\n } else if (inString === \"single\" && char === \"'\") {\n inString = null;\n }\n continue;\n }\n\n if (char === \"\\\"\") {\n inString = \"double\";\n current += char;\n continue;\n }\n\n if (char === \"'\") {\n inString = \"single\";\n current += char;\n continue;\n }\n\n if (char === \",\") {\n const item = parsePrimitive(current);\n if (item === null) {\n return null;\n }\n items.push(item);\n current = \"\";\n continue;\n }\n\n current += char;\n }\n\n const finalItem = parsePrimitive(current);\n if (finalItem === null) {\n return null;\n }\n items.push(finalItem);\n\n return items;\n}\n\nfunction parseInlineTable(raw: string): Record<string, TomlValue> | null {\n const trimmed = raw.trim();\n if (!trimmed.startsWith(\"{\") || !trimmed.endsWith(\"}\")) {\n return null;\n }\n\n const inner = trimmed.slice(1, -1).trim();\n if (!inner) {\n return {};\n }\n\n const pairs: string[] = [];\n let current = \"\";\n let inString: \"single\" | \"double\" | null = null;\n let escaped = false;\n let bracketDepth = 0;\n let braceDepth = 0;\n\n for (let i = 0; i < inner.length; i += 1) {\n const char = inner[i] ?? \"\";\n\n if (inString) {\n current += char;\n if (escaped) {\n escaped = false;\n continue;\n }\n\n if (char === \"\\\\\" && inString === \"double\") {\n escaped = true;\n continue;\n }\n\n if (inString === \"double\" && char === \"\\\"\") {\n inString = null;\n } else if (inString === \"single\" && char === \"'\") {\n inString = null;\n }\n continue;\n }\n\n if (char === \"\\\"\") {\n inString = \"double\";\n current += char;\n continue;\n }\n\n if (char === \"'\") {\n inString = \"single\";\n current += char;\n continue;\n }\n\n if (char === \"[\") {\n bracketDepth += 1;\n current += char;\n continue;\n }\n\n if (char === \"]\") {\n if (bracketDepth > 0) {\n bracketDepth -= 1;\n }\n current += char;\n continue;\n }\n\n if (char === \"{\") {\n braceDepth += 1;\n current += char;\n continue;\n }\n\n if (char === \"}\") {\n if (braceDepth > 0) {\n braceDepth -= 1;\n }\n current += char;\n continue;\n }\n\n if (char === \",\" && bracketDepth === 0 && braceDepth === 0) {\n pairs.push(current);\n current = \"\";\n continue;\n }\n\n current += char;\n }\n\n if (current.trim()) {\n pairs.push(current);\n }\n\n const output: Record<string, TomlValue> = {};\n for (const pair of pairs) {\n const separatorIndex = pair.indexOf(\"=\");\n if (separatorIndex === -1) {\n return null;\n }\n const key = normalizeKeyPath(pair.slice(0, separatorIndex));\n if (!key) {\n return null;\n }\n const valueRaw = pair.slice(separatorIndex + 1).trim();\n if (!valueRaw) {\n return null;\n }\n if (valueRaw.startsWith(\"{\")) {\n return null;\n }\n const normalized = normalizeValue(valueRaw);\n if (normalized === null) {\n return null;\n }\n if (typeof normalized === \"object\" && !Array.isArray(normalized)) {\n return null;\n }\n output[key] = normalized;\n }\n\n return output;\n}\n\nexport function normalizeValue(value: string): TomlValue | null {\n if (!value) {\n return null;\n }\n\n const trimmed = value.trim();\n if (trimmed.startsWith(\"{\") && trimmed.endsWith(\"}\")) {\n return parseInlineTable(trimmed);\n }\n\n const array = parseArray(trimmed);\n if (array) {\n return array;\n }\n\n if (trimmed.startsWith(\"[\") && trimmed.endsWith(\"]\")) {\n return null;\n }\n\n return parsePrimitive(trimmed);\n}\n\nexport function toPlainText(value: unknown): string {\n if (value == null) {\n return \"\";\n }\n if (Array.isArray(value)) {\n return value.map((item) => String(item)).join(\", \");\n }\n return String(value);\n}\n","import { ensureArrayContainer, flattenArrayTables } from \"./arrays\";\nimport { normalizeKeyPath } from \"./keys\";\nimport { stripInlineComment } from \"./strings\";\nimport { normalizeValue, toPlainText } from \"./values\";\n\nexport function parseTomlFrontmatter(frontmatter: string): Record<string, unknown> | null {\n const result: Record<string, unknown> = {};\n const lines = frontmatter.split(\"\\n\");\n let tablePrefix = \"\";\n let tableTarget: Record<string, unknown> | null = null;\n let tablePrefixInList = false;\n\n for (let index = 0; index < lines.length; index += 1) {\n const rawLine = lines[index] ?? \"\";\n const trimmedLine = rawLine.trim();\n if (!trimmedLine || trimmedLine.startsWith(\"#\")) {\n continue;\n }\n\n if (trimmedLine.startsWith(\"[[\")) {\n const match = trimmedLine.match(/^\\[\\[([^\\]]+)]]$/);\n if (!match) {\n return null;\n }\n const normalizedTable = normalizeKeyPath(match[1] ?? \"\");\n if (!normalizedTable) {\n return null;\n }\n const list = ensureArrayContainer(result, normalizedTable);\n const newEntry: Record<string, unknown> = {};\n list.push(newEntry);\n tableTarget = newEntry;\n tablePrefix = normalizedTable;\n tablePrefixInList = true;\n continue;\n }\n\n const tableMatch = trimmedLine.match(/^\\[([^\\]]+)]$/);\n if (tableMatch) {\n const normalizedTable = normalizeKeyPath(tableMatch[1] ?? \"\");\n if (!normalizedTable) {\n return null;\n }\n tablePrefix = normalizedTable;\n tablePrefixInList = false;\n tableTarget = null;\n continue;\n }\n\n const lineForParsing = /(\"\"\"|''')/.test(rawLine) ? rawLine : stripInlineComment(rawLine);\n const separatorIndex = lineForParsing.indexOf(\"=\");\n if (separatorIndex === -1) {\n return null;\n }\n\n const keyRaw = lineForParsing.slice(0, separatorIndex);\n const key = normalizeKeyPath(keyRaw);\n let valueRaw = lineForParsing.slice(separatorIndex + 1).trim();\n if (!key) {\n return null;\n }\n\n const tripleDelimiter = valueRaw.startsWith('\"\"\"') ? '\"\"\"' : valueRaw.startsWith(\"'''\") ? \"'''\" : null;\n if (tripleDelimiter) {\n const closingIndex = valueRaw.indexOf(tripleDelimiter, tripleDelimiter.length);\n if (closingIndex !== -1) {\n const after = valueRaw.slice(closingIndex + tripleDelimiter.length);\n const strippedAfter = stripInlineComment(after);\n valueRaw = `${valueRaw.slice(0, closingIndex + tripleDelimiter.length)}${strippedAfter}`;\n } else {\n const delimiter = tripleDelimiter;\n let combined = valueRaw;\n let closed = false;\n while (index + 1 < lines.length) {\n index += 1;\n const nextLine = lines[index] ?? \"\";\n combined += `\\n${nextLine}`;\n if (new RegExp(`${delimiter}\\\\s*$`).test(nextLine)) {\n closed = true;\n break;\n }\n }\n if (!closed) {\n return null;\n }\n valueRaw = combined;\n }\n }\n\n const normalized = normalizeValue(valueRaw);\n if (normalized === null) {\n return null;\n }\n\n const fullKey = tablePrefix ? `${tablePrefix}.${key}` : key;\n if (typeof normalized === \"object\" && !Array.isArray(normalized)) {\n for (const [inlineKey, inlineValue] of Object.entries(normalized)) {\n const entryKey = tablePrefixInList ? `${key}.${inlineKey}` : `${fullKey}.${inlineKey}`;\n if (tablePrefixInList && tableTarget) {\n tableTarget[entryKey] = toPlainText(inlineValue);\n } else {\n result[entryKey] = toPlainText(inlineValue);\n }\n }\n continue;\n }\n\n if (tablePrefixInList && tableTarget) {\n tableTarget[key] = toPlainText(normalized);\n continue;\n }\n\n result[fullKey] = toPlainText(normalized);\n }\n\n flattenArrayTables(result);\n\n return result;\n}\n","import { parseDocument } from \"yaml\";\nimport { parseTomlFrontmatter } from \"./toml-simple\";\nimport type { FrontmatterType, ParsedMarkdown } from \"./types\";\n\nconst FENCE_TO_TYPE: Record<string, FrontmatterType> = {\n \"---\": \"yaml\",\n \"+++\": \"toml\",\n \";;;\": \"json\",\n};\n\nfunction normalizeNewlines(input: string): string {\n return input.replace(/\\r\\n/g, \"\\n\");\n}\n\nfunction stripBom(line: string): string {\n return line.startsWith(\"\\uFEFF\") ? line.slice(1) : line;\n}\n\nfunction getFenceType(line: string): FrontmatterType | null {\n const match = line.match(/^[\\t ]*(---|\\+\\+\\+|;;;)[\\t ]*$/);\n if (!match) {\n return null;\n }\n return FENCE_TO_TYPE[match[1] ?? \"\"] ?? null;\n}\n\nfunction parseFrontmatter(frontmatter: string, type: FrontmatterType | null): Record<string, unknown> | null {\n if (!type) {\n return null;\n }\n\n if (type === \"json\") {\n try {\n return JSON.parse(frontmatter) as Record<string, unknown>;\n } catch {\n return null;\n }\n }\n\n if (type === \"yaml\") {\n const doc = parseDocument(frontmatter, { prettyErrors: false });\n if (doc.errors.length > 0) {\n return null;\n }\n const data = doc.toJSON();\n if (!data || typeof data !== \"object\" || Array.isArray(data)) {\n return null;\n }\n return data as Record<string, unknown>;\n }\n\n if (type === \"toml\") {\n return parseTomlFrontmatter(frontmatter);\n }\n\n return null;\n}\n\nfunction extractJsonBlock(text: string, startIndex: number): { jsonText: string; endIndex: number } | null {\n let depth = 0;\n let inString = false;\n let escaped = false;\n\n for (let i = startIndex; i < text.length; i += 1) {\n const char = text[i] ?? \"\";\n\n if (inString) {\n if (escaped) {\n escaped = false;\n continue;\n }\n\n if (char === \"\\\\\") {\n escaped = true;\n continue;\n }\n\n if (char === \"\\\"\") {\n inString = false;\n }\n\n continue;\n }\n\n if (char === \"\\\"\") {\n inString = true;\n continue;\n }\n\n if (char === \"{\") {\n depth += 1;\n continue;\n }\n\n if (char === \"}\") {\n depth -= 1;\n if (depth === 0) {\n const jsonText = text.slice(startIndex, i + 1);\n return { jsonText, endIndex: i };\n }\n }\n }\n\n return null;\n}\n\nexport function parseMarkdown(input: string): ParsedMarkdown {\n const normalized = normalizeNewlines(input);\n const lines = normalized.split(\"\\n\");\n if (lines.length === 0) {\n return { frontmatter: null, content: normalized, data: null, frontmatterType: null };\n }\n\n lines[0] = stripBom(lines[0] ?? \"\");\n const normalizedWithoutBom = lines.join(\"\\n\");\n\n const openingType = getFenceType(lines[0] ?? \"\");\n if (!openingType) {\n const leadingWhitespace = normalizedWithoutBom.match(/^[\\t \\n]*/)?.[0] ?? \"\";\n const jsonStart = leadingWhitespace.length;\n if (normalizedWithoutBom[jsonStart] !== \"{\") {\n return { frontmatter: null, content: normalizedWithoutBom, data: null, frontmatterType: null };\n }\n\n const jsonBlock = extractJsonBlock(normalizedWithoutBom, jsonStart);\n if (!jsonBlock) {\n return { frontmatter: null, content: normalizedWithoutBom, data: null, frontmatterType: null };\n }\n\n const frontmatter = jsonBlock.jsonText;\n let content = normalizedWithoutBom.slice(jsonBlock.endIndex + 1);\n if (content.startsWith(\"\\n\")) {\n content = content.slice(1);\n }\n const data = parseFrontmatter(frontmatter, \"json\");\n if (!data) {\n return { frontmatter: null, content: normalizedWithoutBom, data: null, frontmatterType: null };\n }\n\n return {\n frontmatter,\n content,\n data,\n frontmatterType: \"json\",\n };\n }\n\n let closingIndex = -1;\n for (let i = 1; i < lines.length; i += 1) {\n if (getFenceType(lines[i] ?? \"\") === openingType) {\n closingIndex = i;\n break;\n }\n }\n\n if (closingIndex === -1) {\n return { frontmatter: null, content: normalizedWithoutBom, data: null, frontmatterType: null };\n }\n\n const frontmatter = lines.slice(1, closingIndex).join(\"\\n\");\n const content = lines.slice(closingIndex + 1).join(\"\\n\");\n const data = parseFrontmatter(frontmatter, openingType);\n\n return {\n frontmatter,\n content,\n data,\n frontmatterType: openingType,\n };\n}\n","import type { WordCounterMode, WordCounterOptions, WordCounterResult } from \"../wc/types\";\nimport wordCounter from \"../wc\";\nimport { parseMarkdown } from \"./parse-markdown\";\nimport type { SectionMode, SectionedResult } from \"./types\";\n\nfunction normalizeText(value: unknown): string {\n if (value == null) {\n return \"\";\n }\n if (typeof value === \"string\") {\n return value;\n }\n if (typeof value === \"number\" || typeof value === \"boolean\") {\n return String(value);\n }\n try {\n return JSON.stringify(value);\n } catch {\n return String(value);\n }\n}\n\nfunction buildPerKeyItems(\n data: Record<string, unknown> | null,\n mode: WordCounterMode,\n options: WordCounterOptions,\n): Array<{ name: string; source: \"frontmatter\"; result: WordCounterResult }> {\n if (!data || typeof data !== \"object\" || Array.isArray(data)) {\n return [];\n }\n\n return Object.entries(data).map(([key, value]) => {\n const valueText = normalizeText(value);\n const text = valueText ? `${key}: ${valueText}` : key;\n return {\n name: key,\n source: \"frontmatter\",\n result: wordCounter(text, options),\n };\n });\n}\n\nfunction buildSingleItem(\n name: string,\n text: string,\n mode: WordCounterMode,\n options: WordCounterOptions,\n source: \"frontmatter\" | \"content\",\n) {\n return [{ name, source, result: wordCounter(text, options) }];\n}\n\nfunction sumTotals(items: Array<{ result: WordCounterResult }>): number {\n return items.reduce((sum, item) => sum + item.result.total, 0);\n}\n\nexport function countSections(\n input: string,\n section: SectionMode,\n options: WordCounterOptions = {},\n): SectionedResult {\n const mode: WordCounterMode = options.mode ?? \"chunk\";\n if (section === \"all\") {\n const result = wordCounter(input, options);\n return {\n section,\n total: result.total,\n frontmatterType: null,\n items: [{ name: \"all\", source: \"content\", result }],\n };\n }\n\n const parsed = parseMarkdown(input);\n const frontmatterText = parsed.frontmatter ?? \"\";\n const contentText = parsed.content ?? \"\";\n\n let items: Array<{ name: string; source: \"frontmatter\" | \"content\"; result: WordCounterResult }> = [];\n\n if (section === \"frontmatter\") {\n items = buildSingleItem(\"frontmatter\", frontmatterText, mode, options, \"frontmatter\");\n } else if (section === \"content\") {\n items = buildSingleItem(\"content\", contentText, mode, options, \"content\");\n } else if (section === \"split\") {\n items = [\n ...buildSingleItem(\"frontmatter\", frontmatterText, mode, options, \"frontmatter\"),\n ...buildSingleItem(\"content\", contentText, mode, options, \"content\"),\n ];\n } else if (section === \"per-key\") {\n items = buildPerKeyItems(parsed.data, mode, options);\n } else if (section === \"split-per-key\") {\n items = [\n ...buildPerKeyItems(parsed.data, mode, options),\n ...buildSingleItem(\"content\", contentText, mode, options, \"content\"),\n ];\n }\n\n return {\n section,\n total: sumTotals(items),\n frontmatterType: parsed.frontmatterType,\n items,\n };\n}\n","export function showSingularOrPluralWord(count: number, word: string): string {\n return `${count} ${word}${count === 1 ? \"\" : \"s\"}`;\n}\n","import wordCounter, {\n countCharsForLocale,\n countWordsForLocale,\n segmentTextByLocale,\n} from \"./wc\";\nimport { parseMarkdown, countSections } from \"./markdown\";\nimport { showSingularOrPluralWord } from \"./utils\";\n\nconst cjsExports = Object.assign(wordCounter, {\n default: wordCounter,\n wordCounter,\n countCharsForLocale,\n countWordsForLocale,\n segmentTextByLocale,\n parseMarkdown,\n countSections,\n showSingularOrPluralWord,\n});\n\nexport = cjsExports;\n"],"mappings":";;;AAAA,MAAM,iCAAiB,IAAI,KAA6B;AACxD,MAAM,yCAAyB,IAAI,KAA6B;AAEhE,SAAgB,aAAa,QAAgC;CAC3D,MAAM,SAAS,eAAe,IAAI,OAAO;AACzC,KAAI,OACF,QAAO;CAET,MAAM,YAAY,IAAI,KAAK,UAAU,QAAQ,EAAE,aAAa,QAAQ,CAAC;AACrE,gBAAe,IAAI,QAAQ,UAAU;AACrC,QAAO;;AAGT,SAAgB,qBAAqB,QAAgC;CACnE,MAAM,SAAS,uBAAuB,IAAI,OAAO;AACjD,KAAI,OACF,QAAO;CAET,MAAM,YAAY,IAAI,KAAK,UAAU,QAAQ,EAAE,aAAa,YAAY,CAAC;AACzE,wBAAuB,IAAI,QAAQ,UAAU;AAC7C,QAAO;;AAGT,SAAS,oBAA6B;AACpC,QAAO,OAAO,SAAS,eAAe,OAAO,KAAK,cAAc;;AAGlE,SAAgB,oBAAoB,MAAc,QAAwB;CACxE,MAAM,YAAY,aAAa,OAAO;CACtC,IAAI,QAAQ;AACZ,MAAK,MAAM,WAAW,UAAU,QAAQ,KAAK,CAC3C,KAAI,QAAQ,WACV;AAGJ,QAAO;;AAGT,SAAgB,oBAAoB,MAAc,QAAwB;AACxE,KAAI,CAAC,mBAAmB,CACtB,QAAO,MAAM,KAAK,KAAK,CAAC;CAE1B,MAAM,YAAY,qBAAqB,OAAO;CAC9C,IAAI,QAA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W,aAAa,MAAM,SAAS,UAAU,CACrE;UACQ,YAAY,UACrB,SAAQ,iBAAiB,OAAO,MAAM,MAAM,QAAQ;UAC3C,YAAY,gBACrB,SAAQ,CACN,GAAG,iBAAiB,OAAO,MAAM,MAAM,QAAQ,EAC/C,GAAG,gBAAgB,WAAW,aAAa,MAAM,SAAS,UAAU,CACrE;AAGH,QAAO;EACL;EACA,OAAO,UAAU,MAAM;EACvB,iBAAiB,OAAO;EACxB;EACD;;;;;ACrGH,SAAgB,yBAAyB,OAAe,MAAsB;AAC5E,QAAO,GAAG,MAAM,GAAG,OAAO,UAAU,IAAI,KAAK;;;;;ACO/C,MAAM,aAAa,OAAO,OAAOC,YAAa;CAC5C,SAASA;CACT;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;iBAEO"}
1
+ {"version":3,"file":"index.cjs","names":["wordCounter","wordCounter"],"sources":["../../src/wc/segmenter.ts","../../src/utils/append-all.ts","../../src/wc/non-words.ts","../../src/wc/analyze.ts","../../src/wc/mode.ts","../../src/wc/latin-hints.ts","../../src/wc/locale-detect.ts","../../src/wc/segment.ts","../../src/wc/wc.ts","../../src/wc/index.ts","../../src/markdown/toml/arrays.ts","../../src/markdown/toml/keys.ts","../../src/markdown/toml/strings.ts","../../src/markdown/toml/values.ts","../../src/markdown/toml/parse-frontmatter.ts","../../src/markdown/parse-markdown.ts","../../src/markdown/section-count.ts","../../src/utils/show-singular-or-plural-word.ts","../../src/index.cjs.ts"],"sourcesContent":["const segmenterCache = new Map<string, Intl.Segmenter>();\nconst graphemeSegmenterCache = new Map<string, Intl.Segmenter>();\n\nexport function getSegmenter(locale: string): Intl.Segmenter {\n const cached = segmenterCache.get(locale);\n if (cached) {\n return cached;\n }\n const segmenter = new Intl.Segmenter(locale, { granularity: \"word\" });\n segmenterCache.set(locale, segmenter);\n return segmenter;\n}\n\nexport function getGraphemeSegmenter(locale: string): Intl.Segmenter {\n const cached = graphemeSegmenterCache.get(locale);\n if (cached) {\n return cached;\n }\n const segmenter = new Intl.Segmenter(locale, { granularity: \"grapheme\" });\n graphemeSegmenterCache.set(locale, segmenter);\n return segmenter;\n}\n\nfunction supportsSegmenter(): boolean {\n return typeof Intl !== \"undefined\" && typeof Intl.Segmenter === \"function\";\n}\n\nexport function countWordsForLocale(text: string, locale: string): number {\n const segmenter = getSegmenter(locale);\n let count = 0;\n for (const segment of segmenter.segment(text)) {\n if (segment.isWordLike) {\n count++;\n }\n }\n return count;\n}\n\nexport function countCharsForLocale(text: string, locale: string): number {\n if (!supportsSegmenter()) {\n return Array.from(text).length;\n }\n const segmenter = getGraphemeSegmenter(locale);\n let count = 0;\n for (const _segment of segmenter.segment(text)) {\n count++;\n }\n return count;\n}\n","export function appendAll<T>(target: T[], source: readonly T[]): void {\n for (const item of source) {\n target.push(item);\n }\n}\n","import type { NonWordCollection, WhitespaceCounts } from \"./types\";\nimport { appendAll } from \"../utils/append-all\";\n\nconst emojiRegex = /(?:\\p{Extended_Pictographic}|\\p{Emoji_Presentation})/u;\nconst emojiPresentationRegex = /\\p{Emoji_Presentation}/u;\nconst keycapEmojiRegex = /[0-9#*]\\uFE0F?\\u20E3/u;\nconst symbolRegex = /\\p{S}/u;\nconst punctuationRegex = /\\p{P}/u;\nconst whitespaceRegex = /\\s/u;\nconst newlineChars = new Set([\"\\n\", \"\\r\", \"\\u2028\", \"\\u2029\"]);\n\nexport function createNonWordCollection(): NonWordCollection {\n return {\n emoji: [],\n symbols: [],\n punctuation: [],\n counts: {\n emoji: 0,\n symbols: 0,\n punctuation: 0,\n },\n };\n}\n\nexport function addNonWord(\n collection: NonWordCollection,\n category: \"emoji\" | \"symbol\" | \"punctuation\",\n segment: string,\n): void {\n if (category === \"emoji\") {\n collection.emoji.push(segment);\n collection.counts.emoji += 1;\n return;\n }\n if (category === \"symbol\") {\n collection.symbols.push(segment);\n collection.counts.symbols += 1;\n return;\n }\n collection.punctuation.push(segment);\n collection.counts.punctuation += 1;\n}\n\nexport function addWhitespace(\n collection: NonWordCollection,\n segment: string,\n): number {\n let whitespace = collection.whitespace;\n let count = 0;\n for (const char of segment) {\n if (char === \" \") {\n whitespace = whitespace ?? createWhitespaceCounts();\n whitespace.spaces += 1;\n count += 1;\n continue;\n }\n if (char === \"\\t\") {\n whitespace = whitespace ?? createWhitespaceCounts();\n whitespace.tabs += 1;\n count += 1;\n continue;\n }\n if (newlineChars.has(char)) {\n whitespace = whitespace ?? createWhitespaceCounts();\n whitespace.newlines += 1;\n count += 1;\n continue;\n }\n if (whitespaceRegex.test(char)) {\n whitespace = whitespace ?? createWhitespaceCounts();\n whitespace.other += 1;\n count += 1;\n }\n }\n\n if (count > 0) {\n collection.whitespace = whitespace ?? createWhitespaceCounts();\n collection.counts.whitespace = (collection.counts.whitespace ?? 0) + count;\n }\n\n return count;\n}\n\nexport function classifyNonWordSegment(\n segment: string,\n): \"emoji\" | \"symbol\" | \"punctuation\" | null {\n const hasEmojiVariationSelector = segment.includes(\"\\uFE0F\");\n if (\n keycapEmojiRegex.test(segment) ||\n emojiPresentationRegex.test(segment) ||\n (hasEmojiVariationSelector && emojiRegex.test(segment))\n ) {\n return \"emoji\";\n }\n if (symbolRegex.test(segment)) {\n return \"symbol\";\n }\n if (punctuationRegex.test(segment)) {\n return \"punctuation\";\n }\n return null;\n}\n\nexport function mergeNonWordCollections(\n target: NonWordCollection,\n source: NonWordCollection,\n): NonWordCollection {\n if (source.counts.emoji > 0) {\n appendAll(target.emoji, source.emoji);\n target.counts.emoji += source.counts.emoji;\n }\n if (source.counts.symbols > 0) {\n appendAll(target.symbols, source.symbols);\n target.counts.symbols += source.counts.symbols;\n }\n if (source.counts.punctuation > 0) {\n appendAll(target.punctuation, source.punctuation);\n target.counts.punctuation += source.counts.punctuation;\n }\n if (source.counts.whitespace && source.counts.whitespace > 0 && source.whitespace) {\n const whitespace = target.whitespace ?? createWhitespaceCounts();\n whitespace.spaces += source.whitespace.spaces;\n whitespace.tabs += source.whitespace.tabs;\n whitespace.newlines += source.whitespace.newlines;\n whitespace.other += source.whitespace.other;\n target.whitespace = whitespace;\n target.counts.whitespace = (target.counts.whitespace ?? 0) + source.counts.whitespace;\n }\n return target;\n}\n\nfunction createWhitespaceCounts(): WhitespaceCounts {\n return { spaces: 0, tabs: 0, newlines: 0, other: 0 };\n}\n","import { countCharsForLocale, getSegmenter } from \"./segmenter\";\nimport {\n addNonWord,\n addWhitespace,\n classifyNonWordSegment,\n createNonWordCollection,\n mergeNonWordCollections,\n} from \"./non-words\";\nimport { appendAll } from \"../utils/append-all\";\nimport type {\n CharCollectorBreakdown,\n ChunkAnalysis,\n CollectorBreakdown,\n LocaleChunk,\n NonWordCollection,\n} from \"./types\";\n\ntype CharAnalysis = LocaleChunk & { chars: number; nonWords?: NonWordCollection };\ntype CharChunkAnalysis = CharAnalysis & { wordChars: number; nonWordChars: number };\n\nexport function analyzeChunk(\n chunk: LocaleChunk,\n collectNonWords?: boolean,\n includeWhitespace?: boolean,\n): ChunkAnalysis {\n const segmenter = getSegmenter(chunk.locale);\n const segments: string[] = [];\n const nonWords: NonWordCollection | null = collectNonWords\n ? createNonWordCollection()\n : null;\n for (const part of segmenter.segment(chunk.text)) {\n if (part.isWordLike) {\n segments.push(part.segment);\n } else if (collectNonWords && nonWords) {\n if (includeWhitespace) {\n addWhitespace(nonWords, part.segment);\n }\n const category = classifyNonWordSegment(part.segment);\n if (category) {\n addNonWord(nonWords, category, part.segment);\n }\n }\n }\n return {\n locale: chunk.locale,\n text: chunk.text,\n segments,\n words: segments.length,\n nonWords: nonWords ?? undefined,\n };\n}\n\nexport function analyzeCharChunk(\n chunk: LocaleChunk,\n collectNonWords?: boolean,\n includeWhitespace?: boolean,\n): CharChunkAnalysis {\n const segmenter = getSegmenter(chunk.locale);\n const nonWords: NonWordCollection | null = collectNonWords\n ? createNonWordCollection()\n : null;\n let chars = 0;\n let wordChars = 0;\n let nonWordChars = 0;\n\n for (const part of segmenter.segment(chunk.text)) {\n if (part.isWordLike) {\n const count = countCharsForLocale(part.segment, chunk.locale);\n chars += count;\n wordChars += count;\n continue;\n }\n\n if (collectNonWords && nonWords) {\n let whitespaceCount = 0;\n if (includeWhitespace) {\n whitespaceCount = addWhitespace(nonWords, part.segment);\n }\n const category = classifyNonWordSegment(part.segment);\n if (category) {\n addNonWord(nonWords, category, part.segment);\n }\n if (category || whitespaceCount > 0) {\n const count = countCharsForLocale(part.segment, chunk.locale);\n chars += count;\n nonWordChars += count;\n }\n }\n }\n\n return {\n locale: chunk.locale,\n text: chunk.text,\n chars,\n wordChars,\n nonWordChars,\n nonWords: nonWords ?? undefined,\n };\n}\n\nexport function aggregateCharsByLocale(\n chunks: CharChunkAnalysis[],\n): Array<CharCollectorBreakdown & { wordChars: number; nonWordChars: number }> {\n const order: string[] = [];\n const map = new Map<\n string,\n CharCollectorBreakdown & { wordChars: number; nonWordChars: number }\n >();\n\n for (const chunk of chunks) {\n const existing = map.get(chunk.locale);\n if (existing) {\n existing.chars += chunk.chars;\n existing.wordChars += chunk.wordChars;\n existing.nonWordChars += chunk.nonWordChars;\n if (chunk.nonWords) {\n if (!existing.nonWords) {\n existing.nonWords = createNonWordCollection();\n }\n mergeNonWordCollections(existing.nonWords, chunk.nonWords);\n }\n continue;\n }\n\n order.push(chunk.locale);\n map.set(chunk.locale, {\n locale: chunk.locale,\n chars: chunk.chars,\n wordChars: chunk.wordChars,\n nonWordChars: chunk.nonWordChars,\n nonWords: chunk.nonWords\n ? mergeNonWordCollections(createNonWordCollection(), chunk.nonWords)\n : undefined,\n });\n }\n\n return order.map((locale) => map.get(locale)!);\n}\n\nexport function aggregateByLocale(\n chunks: ChunkAnalysis[]\n): CollectorBreakdown[] {\n const order: string[] = [];\n const map = new Map<string, CollectorBreakdown>();\n\n for (const chunk of chunks) {\n const existing = map.get(chunk.locale);\n if (existing) {\n existing.words += chunk.words;\n appendAll(existing.segments, chunk.segments);\n continue;\n }\n\n order.push(chunk.locale);\n map.set(chunk.locale, {\n locale: chunk.locale,\n words: chunk.words,\n segments: [...chunk.segments],\n });\n }\n\n return order.map((locale) => map.get(locale)!);\n}\n","import type { WordCounterMode } from \"./types\";\n\nconst MODE_ALIASES: Record<string, WordCounterMode> = {\n chunk: \"chunk\",\n chunks: \"chunk\",\n segments: \"segments\",\n segment: \"segments\",\n seg: \"segments\",\n collector: \"collector\",\n collect: \"collector\",\n colle: \"collector\",\n char: \"char\",\n chars: \"char\",\n character: \"char\",\n characters: \"char\",\n \"char-collector\": \"char-collector\",\n};\n\nconst CHAR_MODE_ALIASES = new Set([\"char\", \"chars\", \"character\", \"characters\"]);\nconst COLLECTOR_MODE_ALIASES = new Set([\"collector\", \"collect\", \"colle\", \"col\"]);\n\nfunction collapseSeparators(value: string): string {\n return value.replace(/[-_\\s]+/g, \"\");\n}\n\nfunction isComposedCharCollectorFromTokens(value: string): boolean {\n const tokens = value\n .split(/[-_\\s]+/)\n .map((token) => token.trim())\n .filter((token) => token.length > 0);\n if (tokens.length < 2) {\n return false;\n }\n\n let hasCharAlias = false;\n let hasCollectorAlias = false;\n for (const token of tokens) {\n if (CHAR_MODE_ALIASES.has(token)) {\n hasCharAlias = true;\n continue;\n }\n if (COLLECTOR_MODE_ALIASES.has(token)) {\n hasCollectorAlias = true;\n continue;\n }\n return false;\n }\n\n return hasCharAlias && hasCollectorAlias;\n}\n\nfunction isComposedCharCollectorCompact(value: string): boolean {\n for (const charAlias of CHAR_MODE_ALIASES) {\n for (const collectorAlias of COLLECTOR_MODE_ALIASES) {\n if (value === `${charAlias}${collectorAlias}` || value === `${collectorAlias}${charAlias}`) {\n return true;\n }\n }\n }\n return false;\n}\n\nexport function normalizeMode(input?: string | null): WordCounterMode | null {\n if (!input) {\n return null;\n }\n const normalized = input.trim().toLowerCase();\n const direct = MODE_ALIASES[normalized];\n if (direct) {\n return direct;\n }\n\n if (isComposedCharCollectorFromTokens(normalized)) {\n return \"char-collector\";\n }\n\n const compact = collapseSeparators(normalized);\n if (isComposedCharCollectorCompact(compact)) {\n return \"char-collector\";\n }\n\n return MODE_ALIASES[compact] ?? null;\n}\n\nexport function resolveMode(\n input?: string | null,\n fallback: WordCounterMode = \"chunk\",\n): WordCounterMode {\n return normalizeMode(input) ?? fallback;\n}\n","import type { LatinHintRule } from \"./types\";\n\nconst DEFAULT_LATIN_HINT_RULES_SOURCE = [\n { tag: \"de\", pattern: \"[äöüÄÖÜß]\" },\n { tag: \"es\", pattern: \"[ñÑ¿¡]\" },\n { tag: \"pt\", pattern: \"[ãõÃÕ]\" },\n { tag: \"fr\", pattern: \"[œŒæÆ]\" },\n { tag: \"pl\", pattern: \"[ąćęłńśźżĄĆĘŁŃŚŹŻ]\" },\n { tag: \"tr\", pattern: \"[ıİğĞşŞ]\" },\n { tag: \"ro\", pattern: \"[ăĂâÂîÎșȘțȚ]\" },\n { tag: \"hu\", pattern: \"[őŐűŰ]\" },\n { tag: \"is\", pattern: \"[ðÐþÞ]\" },\n] satisfies LatinHintRule[];\n\nexport const DEFAULT_LATIN_HINT_RULES: ReadonlyArray<Readonly<LatinHintRule>> = Object.freeze(\n DEFAULT_LATIN_HINT_RULES_SOURCE.map((rule) => Object.freeze({ ...rule })),\n);\n","import type { LatinHintRule } from \"./types\";\nimport { DEFAULT_LATIN_HINT_RULES } from \"./latin-hints\";\n\nexport const DEFAULT_LOCALE = \"und-Latn\";\nexport const DEFAULT_HAN_TAG = \"und-Hani\";\n\nconst MAX_LATIN_HINT_PATTERN_LENGTH = 256;\n\nexport interface LocaleDetectOptions {\n latinLanguageHint?: string;\n latinTagHint?: string;\n latinLocaleHint?: string;\n latinHintRules?: LatinHintRule[];\n useDefaultLatinHints?: boolean;\n hanLanguageHint?: string;\n hanTagHint?: string;\n}\n\ntype ResolvedLatinHintRule = {\n tag: string;\n pattern: RegExp;\n priority: number;\n order: number;\n};\n\nexport type LocaleDetectContext = {\n latinHint?: string;\n hanHint?: string;\n latinHintRules: ResolvedLatinHintRule[];\n latinLocales: Set<string>;\n};\n\nconst regex = {\n hiragana: /\\p{Script=Hiragana}/u,\n katakana: /\\p{Script=Katakana}/u,\n hangul: /\\p{Script=Hangul}/u,\n han: /\\p{Script=Han}/u,\n latin: /\\p{Script=Latin}/u,\n arabic: /\\p{Script=Arabic}/u,\n cyrillic: /\\p{Script=Cyrillic}/u,\n devanagari: /\\p{Script=Devanagari}/u,\n thai: /\\p{Script=Thai}/u,\n};\n\nconst defaultLatinLocales = new Set<string>([\n DEFAULT_LOCALE,\n ...DEFAULT_LATIN_HINT_RULES.map((hint) => hint.tag),\n]);\n\nexport function isLatinLocale(locale: string, context?: LocaleDetectContext): boolean {\n if (context) {\n return context.latinLocales.has(locale);\n }\n return defaultLatinLocales.has(locale);\n}\n\nfunction resolveLatinHint(options: LocaleDetectOptions): string | undefined {\n const latinTagHint = options.latinTagHint?.trim();\n if (latinTagHint) {\n return latinTagHint;\n }\n\n const latinLanguageHint = options.latinLanguageHint?.trim();\n if (latinLanguageHint) {\n return latinLanguageHint;\n }\n\n const latinLocaleHint = options.latinLocaleHint?.trim();\n if (latinLocaleHint) {\n return latinLocaleHint;\n }\n\n return undefined;\n}\n\nfunction resolveHanHint(options: LocaleDetectOptions): string | undefined {\n const hanTagHint = options.hanTagHint?.trim();\n if (hanTagHint) {\n return hanTagHint;\n }\n\n const hanLanguageHint = options.hanLanguageHint?.trim();\n if (hanLanguageHint) {\n return hanLanguageHint;\n }\n\n return undefined;\n}\n\nfunction compileLatinHintPattern(\n pattern: string | RegExp,\n label: string,\n): RegExp {\n const source = typeof pattern === \"string\" ? pattern : pattern.source;\n const hasUnicodeMode =\n typeof pattern !== \"string\" &&\n (pattern.flags.includes(\"u\") || pattern.flags.includes(\"v\"));\n const flags =\n typeof pattern === \"string\"\n ? \"u\"\n : hasUnicodeMode\n ? pattern.flags\n : `${pattern.flags}u`;\n if (source.length === 0) {\n throw new Error(`${label}: pattern must not be empty.`);\n }\n if (source.length > MAX_LATIN_HINT_PATTERN_LENGTH) {\n throw new Error(\n `${label}: pattern must be at most ${MAX_LATIN_HINT_PATTERN_LENGTH} characters.`,\n );\n }\n try {\n return new RegExp(source, flags);\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n throw new Error(`${label}: invalid Unicode regex pattern (${message}).`);\n }\n}\n\nfunction normalizeLatinHintPriority(priority: unknown, label: string): number {\n if (priority === undefined) {\n return 0;\n }\n if (typeof priority !== \"number\" || !Number.isFinite(priority)) {\n throw new Error(`${label}: priority must be a finite number when provided.`);\n }\n return priority;\n}\n\nfunction compileLatinHintRule(\n rule: Readonly<LatinHintRule>,\n order: number,\n label: string,\n): ResolvedLatinHintRule {\n const tag = typeof rule.tag === \"string\" ? rule.tag.trim() : \"\";\n if (!tag) {\n throw new Error(`${label}: tag must be a non-empty string.`);\n }\n const pattern = compileLatinHintPattern(rule.pattern, label);\n const priority = normalizeLatinHintPriority(rule.priority, label);\n return {\n tag,\n pattern,\n priority,\n order,\n };\n}\n\nfunction resolveLatinHintRules(options: LocaleDetectOptions): ResolvedLatinHintRule[] {\n const useDefaultLatinHints = options.useDefaultLatinHints !== false;\n const customRules = options.latinHintRules ?? [];\n const combinedRules: Array<{ rule: Readonly<LatinHintRule>; label: string }> = [];\n\n for (let index = 0; index < customRules.length; index += 1) {\n const rule = customRules[index];\n if (!rule) {\n continue;\n }\n combinedRules.push({\n rule,\n label: `Invalid custom Latin hint rule at index ${index}`,\n });\n }\n\n if (useDefaultLatinHints) {\n for (let index = 0; index < DEFAULT_LATIN_HINT_RULES.length; index += 1) {\n const rule = DEFAULT_LATIN_HINT_RULES[index];\n if (!rule) {\n continue;\n }\n combinedRules.push({\n rule,\n label: `Invalid default Latin hint rule at index ${index}`,\n });\n }\n }\n\n const resolvedRules = combinedRules.map((entry, index) =>\n compileLatinHintRule(entry.rule, index, entry.label),\n );\n\n resolvedRules.sort((left, right) => {\n if (left.priority !== right.priority) {\n return right.priority - left.priority;\n }\n return left.order - right.order;\n });\n\n return resolvedRules;\n}\n\nexport function resolveLocaleDetectContext(\n options: LocaleDetectOptions = {},\n): LocaleDetectContext {\n const latinHint = resolveLatinHint(options);\n const latinHintRules = resolveLatinHintRules(options);\n const latinLocales = new Set<string>([DEFAULT_LOCALE]);\n for (const rule of latinHintRules) {\n latinLocales.add(rule.tag);\n }\n if (latinHint) {\n latinLocales.add(latinHint);\n }\n\n return {\n latinHint,\n hanHint: resolveHanHint(options),\n latinHintRules,\n latinLocales,\n };\n}\n\nfunction detectLatinLocale(char: string, context: LocaleDetectContext): string {\n for (const hint of context.latinHintRules) {\n hint.pattern.lastIndex = 0;\n if (hint.pattern.test(char)) {\n return hint.tag;\n }\n }\n return DEFAULT_LOCALE;\n}\n\nexport function detectLocaleForChar(\n char: string,\n previousLocale?: string | null,\n options: LocaleDetectOptions = {},\n context: LocaleDetectContext = resolveLocaleDetectContext(options),\n allowLatinLocaleCarry = true,\n allowJapaneseHanCarry = true,\n): string | null {\n if (regex.hiragana.test(char) || regex.katakana.test(char)) {\n return \"ja\";\n }\n if (regex.hangul.test(char)) {\n return \"ko\";\n }\n if (regex.arabic.test(char)) {\n return \"ar\";\n }\n if (regex.cyrillic.test(char)) {\n return \"ru\";\n }\n if (regex.devanagari.test(char)) {\n return \"hi\";\n }\n if (regex.thai.test(char)) {\n return \"th\";\n }\n\n if (regex.han.test(char)) {\n if (allowJapaneseHanCarry && previousLocale && previousLocale.startsWith(\"ja\")) {\n return previousLocale;\n }\n return context.hanHint ?? DEFAULT_HAN_TAG;\n }\n\n if (regex.latin.test(char)) {\n const hintedLocale = detectLatinLocale(char, context);\n if (hintedLocale !== DEFAULT_LOCALE) {\n return hintedLocale;\n }\n if (\n allowLatinLocaleCarry &&\n previousLocale &&\n isLatinLocale(previousLocale, context) &&\n previousLocale !== DEFAULT_LOCALE\n ) {\n return previousLocale;\n }\n if (context.latinHint) {\n return context.latinHint;\n }\n return DEFAULT_LOCALE;\n }\n\n return null;\n}\n","import {\n DEFAULT_LOCALE,\n detectLocaleForChar,\n isLatinLocale,\n resolveLocaleDetectContext,\n type LocaleDetectOptions,\n} from \"./locale-detect\";\nimport type { LocaleChunk } from \"./types\";\n\nconst HARD_BOUNDARY_REGEX = /[\\r\\n,.!?;:,、。!?;:.。、]/u;\nconst LATIN_PROMOTION_BREAK_REGEX = /[\\s,.!?;:,、。!?;:.。、]/u;\n\nexport function segmentTextByLocale(\n text: string,\n options: LocaleDetectOptions = {}\n): LocaleChunk[] {\n const context = resolveLocaleDetectContext(options);\n const chunks: LocaleChunk[] = [];\n // Keep currentLocale as a non-null string to simplify type-narrowing.\n let currentLocale: string = DEFAULT_LOCALE;\n let buffer = \"\";\n let bufferHasScript = false;\n let sawCarryBoundary = false;\n\n const updateCarryBoundaryState = (detected: string | null, char: string): void => {\n if (detected !== null) {\n sawCarryBoundary = false;\n return;\n }\n if (HARD_BOUNDARY_REGEX.test(char)) {\n sawCarryBoundary = true;\n }\n };\n\n for (const char of text) {\n const detected = detectLocaleForChar(\n char,\n currentLocale,\n options,\n context,\n !sawCarryBoundary,\n !sawCarryBoundary,\n );\n const targetLocale = detected ?? currentLocale;\n\n // If buffer is empty, this is the first character for a new chunk.\n if (buffer === \"\") {\n currentLocale = targetLocale;\n buffer = char;\n bufferHasScript = detected !== null;\n updateCarryBoundaryState(detected, char);\n continue;\n }\n\n if (detected !== null && !bufferHasScript) {\n currentLocale = targetLocale;\n buffer += char;\n bufferHasScript = true;\n updateCarryBoundaryState(detected, char);\n continue;\n }\n\n if (targetLocale !== currentLocale && detected !== null) {\n if (currentLocale === DEFAULT_LOCALE && isLatinLocale(targetLocale, context)) {\n const promotionBreakIndex = findLastLatinPromotionBreakIndex(buffer);\n if (promotionBreakIndex === -1) {\n currentLocale = targetLocale;\n buffer += char;\n bufferHasScript = true;\n updateCarryBoundaryState(detected, char);\n continue;\n }\n\n const prefix = buffer.slice(0, promotionBreakIndex + 1);\n const suffix = buffer.slice(promotionBreakIndex + 1);\n if (prefix.length > 0) {\n chunks.push({ locale: currentLocale, text: prefix });\n }\n currentLocale = targetLocale;\n buffer = `${suffix}${char}`;\n bufferHasScript = true;\n updateCarryBoundaryState(detected, char);\n continue;\n }\n // currentLocale is guaranteed to be a string here.\n chunks.push({ locale: currentLocale, text: buffer });\n currentLocale = targetLocale;\n buffer = char;\n bufferHasScript = true;\n updateCarryBoundaryState(detected, char);\n continue;\n }\n\n buffer += char;\n if (detected !== null) {\n bufferHasScript = true;\n }\n updateCarryBoundaryState(detected, char);\n }\n\n if (buffer.length > 0) {\n chunks.push({ locale: currentLocale, text: buffer });\n }\n\n return mergeAdjacentChunks(chunks);\n}\n\nfunction findLastLatinPromotionBreakIndex(buffer: string): number {\n for (let index = buffer.length - 1; index >= 0; index -= 1) {\n const char = buffer[index];\n if (!char) {\n continue;\n }\n if (LATIN_PROMOTION_BREAK_REGEX.test(char)) {\n return index;\n }\n }\n return -1;\n}\n\nfunction mergeAdjacentChunks(chunks: LocaleChunk[]): LocaleChunk[] {\n if (chunks.length === 0) {\n return chunks;\n }\n\n const merged: LocaleChunk[] = [];\n // We already returned for empty arrays above, so the first element is present.\n let last = chunks[0]!;\n\n for (let i = 1; i < chunks.length; i++) {\n const chunk = chunks[i]!;\n if (chunk.locale === last.locale) {\n last = { locale: last.locale, text: last.text + chunk.text };\n } else {\n merged.push(last);\n last = chunk;\n }\n }\n\n merged.push(last);\n return merged;\n}\n","import {\n analyzeCharChunk,\n analyzeChunk,\n aggregateByLocale,\n aggregateCharsByLocale,\n} from \"./analyze\";\nimport { resolveMode } from \"./mode\";\nimport { segmentTextByLocale } from \"./segment\";\nimport { countCharsForLocale, countWordsForLocale } from \"./segmenter\";\nimport { createNonWordCollection, mergeNonWordCollections } from \"./non-words\";\nimport type {\n CharBreakdown,\n CharCollectorBreakdown,\n ChunkBreakdown,\n ChunkWithSegments,\n NonWordCollection,\n WordCounterMode,\n WordCounterOptions,\n WordCounterResult,\n} from \"./types\";\n\nexport type {\n LatinHintRule,\n NonWordCollection,\n WordCounterMode,\n WordCounterOptions,\n WordCounterResult,\n WordCounterBreakdown,\n} from \"./types\";\n\nexport { countCharsForLocale, countWordsForLocale, segmentTextByLocale };\nexport { DEFAULT_LATIN_HINT_RULES } from \"./latin-hints\";\n\nexport function wordCounter(\n text: string,\n options: WordCounterOptions = {}\n): WordCounterResult {\n const mode: WordCounterMode = resolveMode(options.mode, \"chunk\");\n const collectNonWords = Boolean(options.nonWords);\n const includeWhitespace = Boolean(options.includeWhitespace);\n const chunks = segmentTextByLocale(text, {\n latinLanguageHint: options.latinLanguageHint,\n latinTagHint: options.latinTagHint,\n latinLocaleHint: options.latinLocaleHint,\n latinHintRules: options.latinHintRules,\n useDefaultLatinHints: options.useDefaultLatinHints,\n hanLanguageHint: options.hanLanguageHint,\n hanTagHint: options.hanTagHint,\n });\n\n if (mode === \"char\" || mode === \"char-collector\") {\n const analyzed = chunks.map((chunk) =>\n analyzeCharChunk(chunk, collectNonWords, includeWhitespace),\n );\n const total = analyzed.reduce((sum, chunk) => sum + chunk.chars, 0);\n const counts = collectNonWords\n ? {\n words: analyzed.reduce((sum, chunk) => sum + chunk.wordChars, 0),\n nonWords: analyzed.reduce((sum, chunk) => sum + chunk.nonWordChars, 0),\n total,\n }\n : undefined;\n\n if (mode === \"char\") {\n const items: CharBreakdown[] = analyzed.map((chunk) => ({\n locale: chunk.locale,\n text: chunk.text,\n chars: chunk.chars,\n nonWords: chunk.nonWords,\n }));\n return {\n total,\n counts,\n breakdown: {\n mode,\n items,\n },\n };\n }\n\n const aggregated = aggregateCharsByLocale(analyzed);\n const items: CharCollectorBreakdown[] = aggregated.map((chunk) => ({\n locale: chunk.locale,\n chars: chunk.chars,\n nonWords: chunk.nonWords,\n }));\n return {\n total,\n counts,\n breakdown: {\n mode,\n items,\n },\n };\n }\n\n const analyzed = chunks.map((chunk) =>\n analyzeChunk(chunk, collectNonWords, includeWhitespace),\n );\n const wordsTotal = analyzed.reduce((sum, chunk) => sum + chunk.words, 0);\n const nonWordsTotal = collectNonWords\n ? analyzed.reduce((sum, chunk) => {\n if (!chunk.nonWords) {\n return sum;\n }\n return sum + getNonWordTotal(chunk.nonWords);\n }, 0)\n : 0;\n const total = analyzed.reduce((sum, chunk) => {\n let chunkTotal = chunk.words;\n if (collectNonWords && chunk.nonWords) {\n chunkTotal += getNonWordTotal(chunk.nonWords);\n }\n return sum + chunkTotal;\n }, 0);\n\n const counts = collectNonWords ? { words: wordsTotal, nonWords: nonWordsTotal, total } : undefined;\n\n if (mode === \"segments\") {\n const items: ChunkWithSegments[] = analyzed.map((chunk) => ({\n locale: chunk.locale,\n text: chunk.text,\n words: chunk.words,\n segments: chunk.segments,\n nonWords: chunk.nonWords,\n }));\n return {\n total,\n counts,\n breakdown: {\n mode,\n items,\n },\n };\n }\n\n if (mode === \"collector\") {\n const items = aggregateByLocale(analyzed);\n const nonWords = collectNonWordsAggregate(analyzed, collectNonWords);\n return {\n total,\n counts,\n breakdown: {\n mode,\n items,\n nonWords,\n },\n };\n }\n\n const items: ChunkBreakdown[] = analyzed.map((chunk) => ({\n locale: chunk.locale,\n text: chunk.text,\n words: chunk.words,\n nonWords: chunk.nonWords,\n }));\n\n return {\n total,\n counts,\n breakdown: {\n mode,\n items,\n },\n };\n}\n\nfunction getNonWordTotal(nonWords: NonWordCollection): number {\n return (\n nonWords.counts.emoji +\n nonWords.counts.symbols +\n nonWords.counts.punctuation +\n (nonWords.counts.whitespace ?? 0)\n );\n}\n\n\nfunction collectNonWordsAggregate(\n analyzed: Array<{ nonWords?: NonWordCollection }>,\n enabled: boolean,\n): NonWordCollection | undefined {\n if (!enabled) {\n return undefined;\n }\n const collection = createNonWordCollection();\n for (const chunk of analyzed) {\n if (!chunk.nonWords) {\n continue;\n }\n mergeNonWordCollections(collection, chunk.nonWords);\n }\n return collection;\n}\n","import { wordCounter } from \"./wc\";\n\nexport default wordCounter;\nexport { countCharsForLocale, countWordsForLocale, segmentTextByLocale } from \"./wc\";\nexport { DEFAULT_LATIN_HINT_RULES } from \"./wc\";\nexport type {\n LatinHintRule,\n NonWordCollection,\n WordCounterMode,\n WordCounterOptions,\n WordCounterResult,\n WordCounterBreakdown,\n} from \"./wc\";\n","export function ensureArrayContainer(\n result: Record<string, unknown>,\n key: string,\n): Record<string, unknown>[] {\n const existing = result[key];\n if (Array.isArray(existing)) {\n return existing as Record<string, unknown>[];\n }\n const list: Record<string, unknown>[] = [];\n result[key] = list;\n return list;\n}\n\nexport function flattenArrayTables(result: Record<string, unknown>): void {\n for (const [key, value] of Object.entries(result)) {\n if (!Array.isArray(value)) {\n continue;\n }\n const flattened = value\n .map((entry) =>\n Object.entries(entry)\n .map(([entryKey, entryValue]) => `${entryKey}=${entryValue}`)\n .join(\", \"),\n )\n .join(\" | \");\n result[key] = flattened;\n }\n}\n","function stripKeyQuotes(key: string): string {\n const trimmed = key.trim();\n if (\n (trimmed.startsWith(\"\\\"\") && trimmed.endsWith(\"\\\"\")) ||\n (trimmed.startsWith(\"'\") && trimmed.endsWith(\"'\"))\n ) {\n return trimmed.slice(1, -1);\n }\n return trimmed;\n}\n\nexport function normalizeKeyPath(key: string): string | null {\n const trimmed = key.trim();\n if (!trimmed) {\n return null;\n }\n\n if (\n (trimmed.startsWith(\"\\\"\") && trimmed.endsWith(\"\\\"\")) ||\n (trimmed.startsWith(\"'\") && trimmed.endsWith(\"'\"))\n ) {\n const unquoted = stripKeyQuotes(trimmed);\n return unquoted ? unquoted : null;\n }\n\n const segments = trimmed.split(\".\").map((segment) => segment.trim());\n if (segments.some((segment) => !segment)) {\n return null;\n }\n return segments.join(\".\");\n}\n","export function stripInlineComment(line: string): string {\n let inString: \"single\" | \"double\" | null = null;\n let escaped = false;\n\n for (let i = 0; i < line.length; i += 1) {\n const char = line[i] ?? \"\";\n\n if (inString) {\n if (escaped) {\n escaped = false;\n continue;\n }\n\n if (char === \"\\\\\" && inString === \"double\") {\n escaped = true;\n continue;\n }\n\n if (inString === \"double\" && char === \"\\\"\") {\n inString = null;\n continue;\n }\n\n if (inString === \"single\" && char === \"'\") {\n inString = null;\n continue;\n }\n\n continue;\n }\n\n if (char === \"\\\"\") {\n inString = \"double\";\n continue;\n }\n\n if (char === \"'\") {\n inString = \"single\";\n continue;\n }\n\n if (char === \"#\") {\n return line.slice(0, i).trimEnd();\n }\n }\n\n return line;\n}\n\nfunction unescapeBasic(input: string): string {\n return input\n .replace(/\\\\\\\\/g, \"\\\\\")\n .replace(/\\\\\"/g, \"\\\"\")\n .replace(/\\\\n/g, \"\\n\")\n .replace(/\\\\t/g, \"\\t\")\n .replace(/\\\\r/g, \"\\r\");\n}\n\nexport function parseStringLiteral(value: string): string | null {\n if (value.startsWith('\"\"\"') && value.endsWith('\"\"\"')) {\n const inner = value.slice(3, -3);\n return unescapeBasic(inner);\n }\n\n if (value.startsWith(\"'''\") && value.endsWith(\"'''\")) {\n return value.slice(3, -3);\n }\n\n if (value.startsWith(\"\\\"\") && value.endsWith(\"\\\"\")) {\n return unescapeBasic(value.slice(1, -1));\n }\n\n if (value.startsWith(\"'\") && value.endsWith(\"'\")) {\n return value.slice(1, -1);\n }\n\n return null;\n}\n","import { normalizeKeyPath } from \"./keys\";\nimport { parseStringLiteral } from \"./strings\";\nimport type { TomlValue } from \"./types\";\n\nfunction parsePrimitive(raw: string): string | number | boolean | null {\n const value = raw.trim();\n if (!value) {\n return null;\n }\n\n const stringLiteral = parseStringLiteral(value);\n if (stringLiteral !== null) {\n return stringLiteral;\n }\n\n if (value === \"true\") {\n return true;\n }\n\n if (value === \"false\") {\n return false;\n }\n\n if (/^[+-]?\\d+(?:\\.\\d+)?(?:[eE][+-]?\\d+)?$/.test(value)) {\n return Number(value);\n }\n\n if (/^\\d{4}-\\d{2}-\\d{2}/.test(value)) {\n return value;\n }\n\n return value;\n}\n\nfunction parseArray(raw: string): Array<string | number | boolean> | null {\n const value = raw.trim();\n if (!value.startsWith(\"[\") || !value.endsWith(\"]\")) {\n return null;\n }\n\n const inner = value.slice(1, -1).trim();\n if (!inner) {\n return [];\n }\n\n const items: Array<string | number | boolean> = [];\n let current = \"\";\n let inString: \"single\" | \"double\" | null = null;\n let escaped = false;\n\n for (let i = 0; i < inner.length; i += 1) {\n const char = inner[i] ?? \"\";\n\n if (inString) {\n current += char;\n if (escaped) {\n escaped = false;\n continue;\n }\n\n if (char === \"\\\\\" && inString === \"double\") {\n escaped = true;\n continue;\n }\n\n if (inString === \"double\" && char === \"\\\"\") {\n inString = null;\n } else if (inString === \"single\" && char === \"'\") {\n inString = null;\n }\n continue;\n }\n\n if (char === \"\\\"\") {\n inString = \"double\";\n current += char;\n continue;\n }\n\n if (char === \"'\") {\n inString = \"single\";\n current += char;\n continue;\n }\n\n if (char === \",\") {\n const item = parsePrimitive(current);\n if (item === null) {\n return null;\n }\n items.push(item);\n current = \"\";\n continue;\n }\n\n current += char;\n }\n\n const finalItem = parsePrimitive(current);\n if (finalItem === null) {\n return null;\n }\n items.push(finalItem);\n\n return items;\n}\n\nfunction parseInlineTable(raw: string): Record<string, TomlValue> | null {\n const trimmed = raw.trim();\n if (!trimmed.startsWith(\"{\") || !trimmed.endsWith(\"}\")) {\n return null;\n }\n\n const inner = trimmed.slice(1, -1).trim();\n if (!inner) {\n return {};\n }\n\n const pairs: string[] = [];\n let current = \"\";\n let inString: \"single\" | \"double\" | null = null;\n let escaped = false;\n let bracketDepth = 0;\n let braceDepth = 0;\n\n for (let i = 0; i < inner.length; i += 1) {\n const char = inner[i] ?? \"\";\n\n if (inString) {\n current += char;\n if (escaped) {\n escaped = false;\n continue;\n }\n\n if (char === \"\\\\\" && inString === \"double\") {\n escaped = true;\n continue;\n }\n\n if (inString === \"double\" && char === \"\\\"\") {\n inString = null;\n } else if (inString === \"single\" && char === \"'\") {\n inString = null;\n }\n continue;\n }\n\n if (char === \"\\\"\") {\n inString = \"double\";\n current += char;\n continue;\n }\n\n if (char === \"'\") {\n inString = \"single\";\n current += char;\n continue;\n }\n\n if (char === \"[\") {\n bracketDepth += 1;\n current += char;\n continue;\n }\n\n if (char === \"]\") {\n if (bracketDepth > 0) {\n bracketDepth -= 1;\n }\n current += char;\n continue;\n }\n\n if (char === \"{\") {\n braceDepth += 1;\n current += char;\n continue;\n }\n\n if (char === \"}\") {\n if (braceDepth > 0) {\n braceDepth -= 1;\n }\n current += char;\n continue;\n }\n\n if (char === \",\" && bracketDepth === 0 && braceDepth === 0) {\n pairs.push(current);\n current = \"\";\n continue;\n }\n\n current += char;\n }\n\n if (current.trim()) {\n pairs.push(current);\n }\n\n const output: Record<string, TomlValue> = {};\n for (const pair of pairs) {\n const separatorIndex = pair.indexOf(\"=\");\n if (separatorIndex === -1) {\n return null;\n }\n const key = normalizeKeyPath(pair.slice(0, separatorIndex));\n if (!key) {\n return null;\n }\n const valueRaw = pair.slice(separatorIndex + 1).trim();\n if (!valueRaw) {\n return null;\n }\n if (valueRaw.startsWith(\"{\")) {\n return null;\n }\n const normalized = normalizeValue(valueRaw);\n if (normalized === null) {\n return null;\n }\n if (typeof normalized === \"object\" && !Array.isArray(normalized)) {\n return null;\n }\n output[key] = normalized;\n }\n\n return output;\n}\n\nexport function normalizeValue(value: string): TomlValue | null {\n if (!value) {\n return null;\n }\n\n const trimmed = value.trim();\n if (trimmed.startsWith(\"{\") && trimmed.endsWith(\"}\")) {\n return parseInlineTable(trimmed);\n }\n\n const array = parseArray(trimmed);\n if (array) {\n return array;\n }\n\n if (trimmed.startsWith(\"[\") && trimmed.endsWith(\"]\")) {\n return null;\n }\n\n return parsePrimitive(trimmed);\n}\n\nexport function toPlainText(value: unknown): string {\n if (value == null) {\n return \"\";\n }\n if (Array.isArray(value)) {\n return value.map((item) => String(item)).join(\", \");\n }\n return String(value);\n}\n","import { ensureArrayContainer, flattenArrayTables } from \"./arrays\";\nimport { normalizeKeyPath } from \"./keys\";\nimport { stripInlineComment } from \"./strings\";\nimport { normalizeValue, toPlainText } from \"./values\";\n\nexport function parseTomlFrontmatter(frontmatter: string): Record<string, unknown> | null {\n const result: Record<string, unknown> = {};\n const lines = frontmatter.split(\"\\n\");\n let tablePrefix = \"\";\n let tableTarget: Record<string, unknown> | null = null;\n let tablePrefixInList = false;\n\n for (let index = 0; index < lines.length; index += 1) {\n const rawLine = lines[index] ?? \"\";\n const trimmedLine = rawLine.trim();\n if (!trimmedLine || trimmedLine.startsWith(\"#\")) {\n continue;\n }\n\n if (trimmedLine.startsWith(\"[[\")) {\n const match = trimmedLine.match(/^\\[\\[([^\\]]+)]]$/);\n if (!match) {\n return null;\n }\n const normalizedTable = normalizeKeyPath(match[1] ?? \"\");\n if (!normalizedTable) {\n return null;\n }\n const list = ensureArrayContainer(result, normalizedTable);\n const newEntry: Record<string, unknown> = {};\n list.push(newEntry);\n tableTarget = newEntry;\n tablePrefix = normalizedTable;\n tablePrefixInList = true;\n continue;\n }\n\n const tableMatch = trimmedLine.match(/^\\[([^\\]]+)]$/);\n if (tableMatch) {\n const normalizedTable = normalizeKeyPath(tableMatch[1] ?? \"\");\n if (!normalizedTable) {\n return null;\n }\n tablePrefix = normalizedTable;\n tablePrefixInList = false;\n tableTarget = null;\n continue;\n }\n\n const lineForParsing = /(\"\"\"|''')/.test(rawLine) ? rawLine : stripInlineComment(rawLine);\n const separatorIndex = lineForParsing.indexOf(\"=\");\n if (separatorIndex === -1) {\n return null;\n }\n\n const keyRaw = lineForParsing.slice(0, separatorIndex);\n const key = normalizeKeyPath(keyRaw);\n let valueRaw = lineForParsing.slice(separatorIndex + 1).trim();\n if (!key) {\n return null;\n }\n\n const tripleDelimiter = valueRaw.startsWith('\"\"\"') ? '\"\"\"' : valueRaw.startsWith(\"'''\") ? \"'''\" : null;\n if (tripleDelimiter) {\n const closingIndex = valueRaw.indexOf(tripleDelimiter, tripleDelimiter.length);\n if (closingIndex !== -1) {\n const after = valueRaw.slice(closingIndex + tripleDelimiter.length);\n const strippedAfter = stripInlineComment(after);\n valueRaw = `${valueRaw.slice(0, closingIndex + tripleDelimiter.length)}${strippedAfter}`;\n } else {\n const delimiter = tripleDelimiter;\n let combined = valueRaw;\n let closed = false;\n while (index + 1 < lines.length) {\n index += 1;\n const nextLine = lines[index] ?? \"\";\n combined += `\\n${nextLine}`;\n if (new RegExp(`${delimiter}\\\\s*$`).test(nextLine)) {\n closed = true;\n break;\n }\n }\n if (!closed) {\n return null;\n }\n valueRaw = combined;\n }\n }\n\n const normalized = normalizeValue(valueRaw);\n if (normalized === null) {\n return null;\n }\n\n const fullKey = tablePrefix ? `${tablePrefix}.${key}` : key;\n if (typeof normalized === \"object\" && !Array.isArray(normalized)) {\n for (const [inlineKey, inlineValue] of Object.entries(normalized)) {\n const entryKey = tablePrefixInList ? `${key}.${inlineKey}` : `${fullKey}.${inlineKey}`;\n if (tablePrefixInList && tableTarget) {\n tableTarget[entryKey] = toPlainText(inlineValue);\n } else {\n result[entryKey] = toPlainText(inlineValue);\n }\n }\n continue;\n }\n\n if (tablePrefixInList && tableTarget) {\n tableTarget[key] = toPlainText(normalized);\n continue;\n }\n\n result[fullKey] = toPlainText(normalized);\n }\n\n flattenArrayTables(result);\n\n return result;\n}\n","import { parseDocument } from \"yaml\";\nimport { parseTomlFrontmatter } from \"./toml-simple\";\nimport type { FrontmatterType, ParsedMarkdown } from \"./types\";\n\nconst FENCE_TO_TYPE: Record<string, FrontmatterType> = {\n \"---\": \"yaml\",\n \"+++\": \"toml\",\n \";;;\": \"json\",\n};\n\nfunction normalizeNewlines(input: string): string {\n return input.replace(/\\r\\n/g, \"\\n\");\n}\n\nfunction stripBom(line: string): string {\n return line.startsWith(\"\\uFEFF\") ? line.slice(1) : line;\n}\n\nfunction getFenceType(line: string): FrontmatterType | null {\n const match = line.match(/^[\\t ]*(---|\\+\\+\\+|;;;)[\\t ]*$/);\n if (!match) {\n return null;\n }\n return FENCE_TO_TYPE[match[1] ?? \"\"] ?? null;\n}\n\nfunction parseFrontmatter(frontmatter: string, type: FrontmatterType | null): Record<string, unknown> | null {\n if (!type) {\n return null;\n }\n\n if (type === \"json\") {\n try {\n return JSON.parse(frontmatter) as Record<string, unknown>;\n } catch {\n return null;\n }\n }\n\n if (type === \"yaml\") {\n const doc = parseDocument(frontmatter, { prettyErrors: false });\n if (doc.errors.length > 0) {\n return null;\n }\n const data = doc.toJSON();\n if (!data || typeof data !== \"object\" || Array.isArray(data)) {\n return null;\n }\n return data as Record<string, unknown>;\n }\n\n if (type === \"toml\") {\n return parseTomlFrontmatter(frontmatter);\n }\n\n return null;\n}\n\nfunction extractJsonBlock(text: string, startIndex: number): { jsonText: string; endIndex: number } | null {\n let depth = 0;\n let inString = false;\n let escaped = false;\n\n for (let i = startIndex; i < text.length; i += 1) {\n const char = text[i] ?? \"\";\n\n if (inString) {\n if (escaped) {\n escaped = false;\n continue;\n }\n\n if (char === \"\\\\\") {\n escaped = true;\n continue;\n }\n\n if (char === \"\\\"\") {\n inString = false;\n }\n\n continue;\n }\n\n if (char === \"\\\"\") {\n inString = true;\n continue;\n }\n\n if (char === \"{\") {\n depth += 1;\n continue;\n }\n\n if (char === \"}\") {\n depth -= 1;\n if (depth === 0) {\n const jsonText = text.slice(startIndex, i + 1);\n return { jsonText, endIndex: i };\n }\n }\n }\n\n return null;\n}\n\nexport function parseMarkdown(input: string): ParsedMarkdown {\n const normalized = normalizeNewlines(input);\n const lines = normalized.split(\"\\n\");\n if (lines.length === 0) {\n return { frontmatter: null, content: normalized, data: null, frontmatterType: null };\n }\n\n lines[0] = stripBom(lines[0] ?? \"\");\n const normalizedWithoutBom = lines.join(\"\\n\");\n\n const openingType = getFenceType(lines[0] ?? \"\");\n if (!openingType) {\n const leadingWhitespace = normalizedWithoutBom.match(/^[\\t \\n]*/)?.[0] ?? \"\";\n const jsonStart = leadingWhitespace.length;\n if (normalizedWithoutBom[jsonStart] !== \"{\") {\n return { frontmatter: null, content: normalizedWithoutBom, data: null, frontmatterType: null };\n }\n\n const jsonBlock = extractJsonBlock(normalizedWithoutBom, jsonStart);\n if (!jsonBlock) {\n return { frontmatter: null, content: normalizedWithoutBom, data: null, frontmatterType: null };\n }\n\n const frontmatter = jsonBlock.jsonText;\n let content = normalizedWithoutBom.slice(jsonBlock.endIndex + 1);\n if (content.startsWith(\"\\n\")) {\n content = content.slice(1);\n }\n const data = parseFrontmatter(frontmatter, \"json\");\n if (!data) {\n return { frontmatter: null, content: normalizedWithoutBom, data: null, frontmatterType: null };\n }\n\n return {\n frontmatter,\n content,\n data,\n frontmatterType: \"json\",\n };\n }\n\n let closingIndex = -1;\n for (let i = 1; i < lines.length; i += 1) {\n if (getFenceType(lines[i] ?? \"\") === openingType) {\n closingIndex = i;\n break;\n }\n }\n\n if (closingIndex === -1) {\n return { frontmatter: null, content: normalizedWithoutBom, data: null, frontmatterType: null };\n }\n\n const frontmatter = lines.slice(1, closingIndex).join(\"\\n\");\n const content = lines.slice(closingIndex + 1).join(\"\\n\");\n const data = parseFrontmatter(frontmatter, openingType);\n\n return {\n frontmatter,\n content,\n data,\n frontmatterType: openingType,\n };\n}\n","import type { WordCounterMode, WordCounterOptions, WordCounterResult } from \"../wc/types\";\nimport wordCounter from \"../wc\";\nimport { parseMarkdown } from \"./parse-markdown\";\nimport type { SectionMode, SectionedResult } from \"./types\";\n\nfunction normalizeText(value: unknown): string {\n if (value == null) {\n return \"\";\n }\n if (typeof value === \"string\") {\n return value;\n }\n if (typeof value === \"number\" || typeof value === \"boolean\") {\n return String(value);\n }\n try {\n return JSON.stringify(value);\n } catch {\n return String(value);\n }\n}\n\nfunction buildPerKeyItems(\n data: Record<string, unknown> | null,\n mode: WordCounterMode,\n options: WordCounterOptions,\n): Array<{ name: string; source: \"frontmatter\"; result: WordCounterResult }> {\n if (!data || typeof data !== \"object\" || Array.isArray(data)) {\n return [];\n }\n\n return Object.entries(data).map(([key, value]) => {\n const valueText = normalizeText(value);\n const text = valueText ? `${key}: ${valueText}` : key;\n return {\n name: key,\n source: \"frontmatter\",\n result: wordCounter(text, options),\n };\n });\n}\n\nfunction buildSingleItem(\n name: string,\n text: string,\n mode: WordCounterMode,\n options: WordCounterOptions,\n source: \"frontmatter\" | \"content\",\n) {\n return [{ name, source, result: wordCounter(text, options) }];\n}\n\nfunction sumTotals(items: Array<{ result: WordCounterResult }>): number {\n return items.reduce((sum, item) => sum + item.result.total, 0);\n}\n\nexport function countSections(\n input: string,\n section: SectionMode,\n options: WordCounterOptions = {},\n): SectionedResult {\n const mode: WordCounterMode = options.mode ?? \"chunk\";\n if (section === \"all\") {\n const result = wordCounter(input, options);\n return {\n section,\n total: result.total,\n frontmatterType: null,\n items: [{ name: \"all\", source: \"content\", result }],\n };\n }\n\n const parsed = parseMarkdown(input);\n const frontmatterText = parsed.frontmatter ?? \"\";\n const contentText = parsed.content ?? \"\";\n\n let items: Array<{ name: string; source: \"frontmatter\" | \"content\"; result: WordCounterResult }> = [];\n\n if (section === \"frontmatter\") {\n items = buildSingleItem(\"frontmatter\", frontmatterText, mode, options, \"frontmatter\");\n } else if (section === \"content\") {\n items = buildSingleItem(\"content\", contentText, mode, options, \"content\");\n } else if (section === \"split\") {\n items = [\n ...buildSingleItem(\"frontmatter\", frontmatterText, mode, options, \"frontmatter\"),\n ...buildSingleItem(\"content\", contentText, mode, options, \"content\"),\n ];\n } else if (section === \"per-key\") {\n items = buildPerKeyItems(parsed.data, mode, options);\n } else if (section === \"split-per-key\") {\n items = [\n ...buildPerKeyItems(parsed.data, mode, options),\n ...buildSingleItem(\"content\", contentText, mode, options, \"content\"),\n ];\n }\n\n return {\n section,\n total: sumTotals(items),\n frontmatterType: parsed.frontmatterType,\n items,\n };\n}\n","export function showSingularOrPluralWord(count: number, word: string): string {\n return `${count} ${word}${count === 1 ? \"\" : \"s\"}`;\n}\n","import wordCounter, {\n countCharsForLocale,\n countWordsForLocale,\n segmentTextByLocale,\n} from \"./wc\";\nimport { parseMarkdown, countSections } from \"./markdown\";\nimport { showSingularOrPluralWord } from \"./utils\";\n\nconst cjsExports = Object.assign(wordCounter, {\n default: wordCounter,\n wordCounter,\n countCharsForLocale,\n countWordsForLocale,\n segmentTextByLocale,\n parseMarkdown,\n countSections,\n showSingularOrPluralWord,\n});\n\nexport = cjsExports;\n"],"mappings":";;;AAAA,MAAM,iCAAiB,IAAI,KAA6B;AACxD,MAAM,yCAAyB,IAAI,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;AAC1C,SAAO;GACL;GACA,OAAO,OAAO;GACd,iBAAiB;GACjB,OAAO,CAAC;IAAE,MAAM;IAAO,QAAQ;IAAW;IAAQ,CAAC;GACpD;;CAGH,MAAM,SAAS,cAAc,MAAM;CACnC,MAAM,kBAAkB,OAAO,eAAe;CAC9C,MAAM,cAAc,OAAO,WAAW;CAEtC,IAAI,QAA+F,EAAE;AAErG,KAAI,YAAY,cACd,SAAQ,gBAAgB,eAAe,iBAAiB,MAAM,SAAS,cAAc;UAC5E,YAAY,UACrB,SAAQ,gBAAgB,WAAW,aAAa,MAAM,SAAS,UAAU;UAChE,YAAY,QACrB,SAAQ,CACN,GAAG,gBAAgB,eAAe,iBAAiB,MAAM,SAAS,cAAc,EAChF,GAAG,gBAAgB,WAAW,aAAa,MAAM,SAAS,UAAU,CACrE;UACQ,YAAY,UACrB,SAAQ,iBAAiB,OAAO,MAAM,MAAM,QAAQ;UAC3C,YAAY,gBACrB,SAAQ,CACN,GAAG,iBAAiB,OAAO,MAAM,MAAM,QAAQ,EAC/C,GAAG,gBAAgB,WAAW,aAAa,MAAM,SAAS,UAAU,CACrE;AAGH,QAAO;EACL;EACA,OAAO,UAAU,MAAM;EACvB,iBAAiB,OAAO;EACxB;EACD;;;;;ACrGH,SAAgB,yBAAyB,OAAe,MAAsB;AAC5E,QAAO,GAAG,MAAM,GAAG,OAAO,UAAU,IAAI,KAAK;;;;;ACO/C,MAAM,aAAa,OAAO,OAAOC,YAAa;CAC5C,SAASA;CACT;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;iBAEO"}
package/dist/esm/bin.mjs CHANGED
@@ -421,7 +421,7 @@ var require_picocolors = /* @__PURE__ */ __commonJSMin(((exports, module) => {
421
421
  //#endregion
422
422
  //#region src/cli/program/version-embedded.ts
423
423
  var import_picocolors = /* @__PURE__ */ __toESM(require_picocolors(), 1);
424
- const EMBEDDED_PACKAGE_VERSION = "0.1.3-canary.1";
424
+ const EMBEDDED_PACKAGE_VERSION = "0.1.3-canary.2";
425
425
 
426
426
  //#endregion
427
427
  //#region src/cli/program/version.ts
@@ -1760,7 +1760,7 @@ function detectLatinLocale(char, context) {
1760
1760
  }
1761
1761
  return DEFAULT_LOCALE;
1762
1762
  }
1763
- function detectLocaleForChar(char, previousLocale, options = {}, context = resolveLocaleDetectContext(options)) {
1763
+ function detectLocaleForChar(char, previousLocale, options = {}, context = resolveLocaleDetectContext(options), allowLatinLocaleCarry = true, allowJapaneseHanCarry = true) {
1764
1764
  if (regex.hiragana.test(char) || regex.katakana.test(char)) return "ja";
1765
1765
  if (regex.hangul.test(char)) return "ko";
1766
1766
  if (regex.arabic.test(char)) return "ar";
@@ -1768,13 +1768,13 @@ function detectLocaleForChar(char, previousLocale, options = {}, context = resol
1768
1768
  if (regex.devanagari.test(char)) return "hi";
1769
1769
  if (regex.thai.test(char)) return "th";
1770
1770
  if (regex.han.test(char)) {
1771
- if (previousLocale && previousLocale.startsWith("ja")) return previousLocale;
1771
+ if (allowJapaneseHanCarry && previousLocale && previousLocale.startsWith("ja")) return previousLocale;
1772
1772
  return context.hanHint ?? DEFAULT_HAN_TAG;
1773
1773
  }
1774
1774
  if (regex.latin.test(char)) {
1775
1775
  const hintedLocale = detectLatinLocale(char, context);
1776
1776
  if (hintedLocale !== DEFAULT_LOCALE) return hintedLocale;
1777
- if (previousLocale && isLatinLocale(previousLocale, context) && previousLocale !== DEFAULT_LOCALE) return previousLocale;
1777
+ if (allowLatinLocaleCarry && previousLocale && isLatinLocale(previousLocale, context) && previousLocale !== DEFAULT_LOCALE) return previousLocale;
1778
1778
  if (context.latinHint) return context.latinHint;
1779
1779
  return DEFAULT_LOCALE;
1780
1780
  }
@@ -1783,32 +1783,59 @@ function detectLocaleForChar(char, previousLocale, options = {}, context = resol
1783
1783
 
1784
1784
  //#endregion
1785
1785
  //#region src/wc/segment.ts
1786
+ const HARD_BOUNDARY_REGEX = /[\r\n,.!?;:,、。!?;:.。、]/u;
1787
+ const LATIN_PROMOTION_BREAK_REGEX = /[\s,.!?;:,、。!?;:.。、]/u;
1786
1788
  function segmentTextByLocale(text, options = {}) {
1787
1789
  const context = resolveLocaleDetectContext(options);
1788
1790
  const chunks = [];
1789
1791
  let currentLocale = DEFAULT_LOCALE;
1790
1792
  let buffer = "";
1791
1793
  let bufferHasScript = false;
1794
+ let sawCarryBoundary = false;
1795
+ const updateCarryBoundaryState = (detected, char) => {
1796
+ if (detected !== null) {
1797
+ sawCarryBoundary = false;
1798
+ return;
1799
+ }
1800
+ if (HARD_BOUNDARY_REGEX.test(char)) sawCarryBoundary = true;
1801
+ };
1792
1802
  for (const char of text) {
1793
- const detected = detectLocaleForChar(char, currentLocale, options, context);
1803
+ const detected = detectLocaleForChar(char, currentLocale, options, context, !sawCarryBoundary, !sawCarryBoundary);
1794
1804
  const targetLocale = detected ?? currentLocale;
1795
1805
  if (buffer === "") {
1796
1806
  currentLocale = targetLocale;
1797
1807
  buffer = char;
1798
1808
  bufferHasScript = detected !== null;
1809
+ updateCarryBoundaryState(detected, char);
1799
1810
  continue;
1800
1811
  }
1801
1812
  if (detected !== null && !bufferHasScript) {
1802
1813
  currentLocale = targetLocale;
1803
1814
  buffer += char;
1804
1815
  bufferHasScript = true;
1816
+ updateCarryBoundaryState(detected, char);
1805
1817
  continue;
1806
1818
  }
1807
1819
  if (targetLocale !== currentLocale && detected !== null) {
1808
1820
  if (currentLocale === DEFAULT_LOCALE && isLatinLocale(targetLocale, context)) {
1821
+ const promotionBreakIndex = findLastLatinPromotionBreakIndex(buffer);
1822
+ if (promotionBreakIndex === -1) {
1823
+ currentLocale = targetLocale;
1824
+ buffer += char;
1825
+ bufferHasScript = true;
1826
+ updateCarryBoundaryState(detected, char);
1827
+ continue;
1828
+ }
1829
+ const prefix = buffer.slice(0, promotionBreakIndex + 1);
1830
+ const suffix = buffer.slice(promotionBreakIndex + 1);
1831
+ if (prefix.length > 0) chunks.push({
1832
+ locale: currentLocale,
1833
+ text: prefix
1834
+ });
1809
1835
  currentLocale = targetLocale;
1810
- buffer += char;
1836
+ buffer = `${suffix}${char}`;
1811
1837
  bufferHasScript = true;
1838
+ updateCarryBoundaryState(detected, char);
1812
1839
  continue;
1813
1840
  }
1814
1841
  chunks.push({
@@ -1818,10 +1845,12 @@ function segmentTextByLocale(text, options = {}) {
1818
1845
  currentLocale = targetLocale;
1819
1846
  buffer = char;
1820
1847
  bufferHasScript = true;
1848
+ updateCarryBoundaryState(detected, char);
1821
1849
  continue;
1822
1850
  }
1823
1851
  buffer += char;
1824
1852
  if (detected !== null) bufferHasScript = true;
1853
+ updateCarryBoundaryState(detected, char);
1825
1854
  }
1826
1855
  if (buffer.length > 0) chunks.push({
1827
1856
  locale: currentLocale,
@@ -1829,6 +1858,14 @@ function segmentTextByLocale(text, options = {}) {
1829
1858
  });
1830
1859
  return mergeAdjacentChunks(chunks);
1831
1860
  }
1861
+ function findLastLatinPromotionBreakIndex(buffer) {
1862
+ for (let index = buffer.length - 1; index >= 0; index -= 1) {
1863
+ const char = buffer[index];
1864
+ if (!char) continue;
1865
+ if (LATIN_PROMOTION_BREAK_REGEX.test(char)) return index;
1866
+ }
1867
+ return -1;
1868
+ }
1832
1869
  function mergeAdjacentChunks(chunks) {
1833
1870
  if (chunks.length === 0) return chunks;
1834
1871
  const merged = [];