@mark1russell7/typeset 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/chunks/breaking.js +9 -2
- package/build/chunks/breaking.js.map +1 -1
- package/build/chunks/engines.js +1 -1
- package/build/chunks/font.js +174 -35
- package/build/chunks/font.js.map +1 -1
- package/build/chunks/fonts.js +1 -1
- package/build/chunks/measurer.d.ts.map +1 -1
- package/build/chunks/measurer.js +2 -0
- package/build/chunks/measurer.js.map +1 -1
- package/build/chunks/paragraph.d.ts +5 -0
- package/build/chunks/paragraph.d.ts.map +1 -1
- package/build/fonts-inspect.d.ts +11 -1
- package/build/fonts-inspect.d.ts.map +1 -1
- package/build/fonts-inspect.js +1 -1
- package/build/segmentation.d.ts +19 -0
- package/build/segmentation.d.ts.map +1 -0
- package/build/segmentation.js +267 -0
- package/build/segmentation.js.map +1 -0
- package/package.json +7 -3
- package/src/breaking/paragraph.ts +8 -2
- package/src/fonts/indic.ts +49 -41
- package/src/fonts/machine.ts +133 -0
- package/src/fonts-inspect.ts +2 -1
- package/src/measurer/advance.ts +4 -0
- package/src/segmentation/line-table.ts +5 -0
- package/src/segmentation/line.ts +203 -0
- package/src/segmentation/segments.ts +18 -0
- package/src/segmentation.ts +3 -0
package/build/chunks/fonts.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime.js";
|
|
2
|
-
import { c as joiningStages,
|
|
2
|
+
import { c as joiningStages, i as shapingOf, l as indicFeatures, n as measureWidth, p as normalForms, r as readFont, u as indicForms } from "./font.js";
|
|
3
3
|
import { n as isEngineName, r as shapingRisks, t as engines } from "./engines.js";
|
|
4
4
|
// src/fonts/bound.ts
|
|
5
5
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"measurer.d.ts","names":[],"sources":["../../src/measurer/advance.ts","../../src/measurer.ts"],"mappings":";;;KAaY,aAAa,cAAc;;UAGtB;;WAEN;;WAEA,MAAM;;;;;WAKN;;WAEA;;WAEA,aAAa;;;UAIP;;WAEN,gBAAgB;;WAEhB,SAAS,aAAa;;;;;WAKtB;;WAEA,WAAW;;;UAIL;WACN;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;;;;;iBAuBK,UAAU,eAAe;;;;;
|
|
1
|
+
{"version":3,"file":"measurer.d.ts","names":[],"sources":["../../src/measurer/advance.ts","../../src/measurer.ts"],"mappings":";;;KAaY,aAAa,cAAc;;UAGtB;;WAEN;;WAEA,MAAM;;;;;WAKN;;WAEA;;WAEA,aAAa;;;UAIP;;WAEN,gBAAgB;;WAEhB,SAAS,aAAa;;;;;WAKtB;;WAEA,WAAW;;;UAIL;WACN;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;;;;;iBAuBK,UAAU,eAAe;;;;;iBAwGzB,UAAU;;;;;;;;iBAmDV,YAAY,SAAS,sBAAsB,cAAc"}
|
package/build/chunks/measurer.js
CHANGED
|
@@ -55,6 +55,7 @@ function parseFont(font) {
|
|
|
55
55
|
if (size === null) throw new RangeError(`the font "${font}" has no size in px or pt`);
|
|
56
56
|
let rest = tokens.slice(index + 1).join(" ");
|
|
57
57
|
if (size[3] === void 0 && rest.startsWith("/")) rest = rest.slice(1).trim().replace(/^\S+\s*/, "");
|
|
58
|
+
else if (size[3] === "/") rest = rest.replace(/^\S+\s*/, "");
|
|
58
59
|
const families = rest.split(",").map((family) => family.trim().replace(/^(["'])(.*)\1$/, "$2").trim()).filter((family) => family.length > 0);
|
|
59
60
|
if (families.length === 0) throw new RangeError(`the font "${font}" has no family`);
|
|
60
61
|
const value = Number(size[1]);
|
|
@@ -236,6 +237,7 @@ function fontAdvance(options) {
|
|
|
236
237
|
let font = instances.get(key);
|
|
237
238
|
if (font === void 0) {
|
|
238
239
|
font = Object.keys(instance).length === 0 ? chosen.font : chosen.font.at(instance);
|
|
240
|
+
if (instances.size >= 256) instances.clear();
|
|
239
241
|
instances.set(key, font);
|
|
240
242
|
}
|
|
241
243
|
return font;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"measurer.js","names":[],"sources":["../../src/measurer/advance.ts","../../src/measurer.ts"],"sourcesContent":["/**\n * The advance function of the font model: the width of a text in a CSS font, as the measurer of\n * `@mark1russell7/layout-contract/text` asks for it. The host gives the font files as faces. The function finds the face\n * of each run of the text with the matching rules of CSS. It finds the script of the run, and measures the run with the\n * rules of one text engine.\n */\nimport { engines, isEngineName, type EngineName, type EngineRules } from \"../fonts/engines.ts\";\nimport { measureWidth, readFont, type Font } from \"../fonts/font.ts\";\nimport { shapingRisks } from \"../fonts/risks.ts\";\nimport type { Decompress } from \"../fonts/sfnt.ts\";\nimport { canvasWords } from \"../fonts/words.ts\";\n\n/** This function gives the width of a text in a CSS font, as `AdvanceFn` of layout-contract does. */\nexport type AdvanceFn = (text: string, font: string) => number;\n\n/** One font file of the host, with the family, the weight and the style that CSS matches. */\nexport interface FontFace {\n /** The family name, as the CSS font names it. The match ignores the case. */\n readonly family: string;\n /** The bytes of a TrueType, OpenType or WOFF2 file. */\n readonly data: Uint8Array;\n /**\n * The weight of the face: one value, or the range of a variable font. The default is the range of the `wght` axis of the\n * font, or 400 for a font with no `wght` axis.\n */\n readonly weight?: number | readonly [number, number];\n /** The style of the face. The default is `normal`. */\n readonly style?: \"normal\" | \"italic\" | \"oblique\";\n /** The Brotli decompressor of a WOFF2 file. */\n readonly decompress?: Decompress;\n}\n\n/** The options of `fontAdvance`. */\nexport interface FontAdvanceOptions {\n /** The font files of the host. The order sets the choice between two faces with the same match. */\n readonly faces: readonly FontFace[];\n /** The text engine: a row name of `engines`, or the rules of a row. The default is `freetype`, as Chromium on Linux. */\n readonly engine?: EngineName | EngineRules;\n /**\n * The shaping of `measureWidth`. The default is `canvas`, as `canvasAdvance` of layout-contract measures each segment\n * with `measureText`. Use `dom` for the widths of a text in a page.\n */\n readonly shaping?: \"dom\" | \"canvas\";\n /** The shaper of the host. Under the shaping `canvas`, it measures each word that `shapingRisks` flags. The shaping `dom` does not use it. */\n readonly fallback?: AdvanceFn;\n}\n\n/** The parts of a CSS font shorthand that change a width. */\nexport interface FontSpec {\n readonly style: \"normal\" | \"italic\" | \"oblique\";\n /** The angle of an oblique style in degrees. CSS gives 14 when the font names no angle. */\n readonly angle: number;\n /** The weight from 1 to 1000. */\n readonly weight: number;\n /** The width of the font as a percent of the normal width, from the keyword of `font-stretch`. */\n readonly stretch: number;\n /** The size in px. */\n readonly size: number;\n /** The family names in the order of the font, with no quotes. */\n readonly families: readonly string[];\n}\n\nconst stretches: Readonly<Record<string, number>> = {\n \"ultra-condensed\": 50,\n \"extra-condensed\": 62.5,\n condensed: 75,\n \"semi-condensed\": 87.5,\n \"semi-expanded\": 112.5,\n expanded: 125,\n \"extra-expanded\": 150,\n \"ultra-expanded\": 200,\n};\n\n// Each number pattern matches a text in one way only. Thus a long run of digits does not make the match slow.\nconst sizePattern = /^((?:\\d+(?:\\.\\d+)?|\\.\\d+)(?:e[+-]?\\d+)?)(px|pt)(\\/.*)?$/i;\nconst anglePattern = /^(-?(?:\\d+(?:\\.\\d+)?|\\.\\d+))deg$/i;\nconst weightPattern = /^(?:\\d+(?:\\.\\d+)?|\\.\\d+)$/;\n\n/**\n * This function reads a CSS font shorthand, for example `italic 700 16px/1.2 \"Noto Sans\", sans-serif`. The size must be in\n * `px` or `pt`. The function refuses `small-caps`, the system font keywords and the relative sizes with a `RangeError`.\n */\nexport function parseFont(font: string): FontSpec {\n const tokens = font.trim().split(/\\s+/);\n let style: FontSpec[\"style\"] = \"normal\";\n let angle = 14;\n let weight = 400;\n let stretch = 100;\n let index = 0;\n for (; index < tokens.length; index++) {\n const token = tokens[index]!;\n const lower = token.toLowerCase();\n const size = sizePattern.exec(token);\n if (size !== null) break;\n if (lower === \"normal\") continue;\n if (lower === \"italic\") style = \"italic\";\n else if (lower === \"oblique\") {\n style = \"oblique\";\n const next = anglePattern.exec(tokens[index + 1] ?? \"\");\n if (next !== null) {\n angle = Number(next[1]);\n index++;\n }\n } else if (lower === \"bold\" || lower === \"bolder\") weight = 700;\n else if (lower === \"lighter\") weight = 100;\n else if (weightPattern.test(token) && Number(token) >= 1 && Number(token) <= 1000) weight = Number(token);\n else if (Object.hasOwn(stretches, lower)) stretch = stretches[lower]!;\n else throw new RangeError(`the font \"${font}\" has the part \"${token}\", which the measurer does not know`);\n }\n const size = sizePattern.exec(tokens[index] ?? \"\");\n if (size === null) throw new RangeError(`the font \"${font}\" has no size in px or pt`);\n let rest = tokens.slice(index + 1).join(\" \");\n // A line height after a space: \"16px / 1.2\" or \"16px /1.2\"\n if (size[3] === undefined && rest.startsWith(\"/\")) rest = rest.slice(1).trim().replace(/^\\S+\\s*/, \"\");\n const families = rest\n .split(\",\")\n .map((family) => family.trim().replace(/^([\"'])(.*)\\1$/, \"$2\").trim())\n .filter((family) => family.length > 0);\n if (families.length === 0) throw new RangeError(`the font \"${font}\" has no family`);\n const value = Number(size[1]);\n return { style, angle, weight, stretch, size: size[2]!.toLowerCase() === \"pt\" ? (value * 4) / 3 : value, families };\n}\n\n/** The Unicode scripts and their OpenType tags. A script that is not in the list gets `DFLT`. */\nconst scriptPatterns: readonly (readonly [RegExp, string])[] = [\n [/\\p{sc=Latin}/u, \"latn\"],\n [/\\p{sc=Greek}/u, \"grek\"],\n [/\\p{sc=Cyrillic}/u, \"cyrl\"],\n [/\\p{sc=Armenian}/u, \"armn\"],\n [/\\p{sc=Hebrew}/u, \"hebr\"],\n [/\\p{sc=Arabic}/u, \"arab\"],\n [/\\p{sc=Syriac}/u, \"syrc\"],\n [/\\p{sc=Thaana}/u, \"thaa\"],\n [/\\p{sc=Devanagari}/u, \"deva\"],\n [/\\p{sc=Bengali}/u, \"beng\"],\n [/\\p{sc=Gurmukhi}/u, \"guru\"],\n [/\\p{sc=Gujarati}/u, \"gujr\"],\n [/\\p{sc=Oriya}/u, \"orya\"],\n [/\\p{sc=Tamil}/u, \"taml\"],\n [/\\p{sc=Telugu}/u, \"telu\"],\n [/\\p{sc=Kannada}/u, \"knda\"],\n [/\\p{sc=Malayalam}/u, \"mlym\"],\n [/\\p{sc=Sinhala}/u, \"sinh\"],\n [/\\p{sc=Thai}/u, \"thai\"],\n [/\\p{sc=Lao}/u, \"lao \"],\n [/\\p{sc=Tibetan}/u, \"tibt\"],\n [/\\p{sc=Myanmar}/u, \"mymr\"],\n [/\\p{sc=Georgian}/u, \"geor\"],\n [/\\p{sc=Hangul}/u, \"hang\"],\n [/\\p{sc=Ethiopic}/u, \"ethi\"],\n [/\\p{sc=Khmer}/u, \"khmr\"],\n [/\\p{sc=Mongolian}/u, \"mong\"],\n [/[\\p{sc=Hiragana}\\p{sc=Katakana}]/u, \"kana\"],\n [/\\p{sc=Bopomofo}/u, \"bopo\"],\n [/\\p{sc=Han}/u, \"hani\"],\n];\n\nconst neutral = /[\\p{sc=Common}\\p{sc=Inherited}\\p{sc=Unknown}]/u;\n\n/** This function divides a text into parts of one script. A neutral character stays with the part before it. */\nexport function scriptRuns(text: string): string[] {\n if (/^[\\0-\\x7f]*$/.test(text)) return [text];\n const runs: string[] = [];\n let run = \"\";\n let current: string | undefined;\n for (const character of text) {\n if (!neutral.test(character)) {\n const tag = scriptTag(character).replace(/kana|bopo/, \"hani\");\n if (current !== undefined && tag !== current) {\n runs.push(run);\n run = \"\";\n }\n current = tag;\n }\n run += character;\n }\n runs.push(run);\n return runs;\n}\n\n/**\n * This function gives the OpenType script tag of a text, as HarfBuzz guesses it. The tag is the script of the first\n * character that is not of the scripts Common, Inherited or Unknown. A text of only those characters, for example emoji, gets `DFLT`.\n */\nexport function scriptTag(text: string): string {\n for (const character of text) {\n if (neutral.test(character)) continue;\n for (const [pattern, tag] of scriptPatterns) if (pattern.test(character)) return tag;\n return \"DFLT\";\n }\n return \"DFLT\";\n}\n\n/** A character that stays in the run of the character before it: a mark, a joiner, a variation selector, a tag or a skin tone. */\nconst attached = /^[\\p{M}︀-️\\u{e0020}-\\u{e007f}\\u{e0100}-\\u{e01ef}\\u{1f3fb}-\\u{1f3ff}]$/u;\n\nconst styleOrder: Readonly<Record<FontSpec[\"style\"], readonly FontSpec[\"style\"][]>> = {\n normal: [\"normal\", \"oblique\", \"italic\"],\n italic: [\"italic\", \"oblique\", \"normal\"],\n oblique: [\"oblique\", \"italic\", \"normal\"],\n};\n\n/** A face with its font, read at the first use. */\ninterface Loaded {\n readonly face: FontFace;\n readonly index: number;\n readonly font: Font;\n readonly range: readonly [number, number];\n}\n\n/**\n * This function gives the rank of a face for the weight `weight`, with the rules of CSS Fonts 4. A lower rank is a\n * better match. A face whose range holds the weight has the rank 0.\n */\nfunction weightRank(range: readonly [number, number], weight: number): number {\n const [min, max] = range;\n if (min <= weight && weight <= max) return 0;\n const above = min > weight;\n // The groups of CSS: 1 is the first choice after an exact match, 3 is the last\n if (weight >= 400 && weight <= 500) {\n if (above && min <= 500) return 1000 + min;\n if (!above) return 3000 - max;\n return 5000 + min;\n }\n if (weight < 400) return above ? 3000 + min : 1000 - max;\n return above ? 1000 + min : 3000 - max;\n}\n\n/**\n * This function gives the advance function of the faces of the host: the width in px of a text in a CSS font. Each run\n * of the text gets the first family of the font with a glyph for its first character. When no family has a glyph, the\n * run gets the first family that has a face. The width of a run is `measureWidth` with the size of the font, the script\n * of `scriptTag` and the rules of the engine. The instance of a variable face takes the weight and the stretch as `wdth`.\n * It takes the style as `ital` or `slnt`, and the size as `opsz`, as `font-optical-sizing: auto` does.\n */\nexport function fontAdvance(options: FontAdvanceOptions): (text: string, font: string) => number {\n const engine = options.engine ?? \"freetype\";\n if (typeof engine === \"string\" && !isEngineName(engine)) throw new RangeError(`the engine \"${engine}\" is not a row of engines`);\n const rules: EngineRules = typeof engine === \"string\" ? engines[engine] : engine;\n const shaping = options.shaping ?? \"canvas\";\n const fallback = shaping === \"canvas\" ? options.fallback : undefined;\n const faces = options.faces;\n const loaded = new Map<number, Loaded>();\n const specs = new Map<string, FontSpec>();\n const instances = new Map<string, Font>();\n const families = new Map<string, readonly Font[] | undefined>();\n\n const load = (index: number): Loaded => {\n let entry = loaded.get(index);\n if (entry === undefined) {\n const face = faces[index]!;\n const font = readFont(face.data, { deltas: rules.deltas, metrics: rules.metrics, ...(face.decompress === undefined ? {} : { decompress: face.decompress }) });\n const axis = font.axes.find((value) => value.tag === \"wght\");\n const declared = face.weight;\n const range: readonly [number, number] = typeof declared === \"number\" ? [declared, declared] : (declared ?? (axis === undefined ? [400, 400] : [axis.min, axis.max]));\n entry = { face, index, font, range };\n loaded.set(index, entry);\n }\n return entry;\n };\n\n /** This function gives the font of the best face of a family for the spec, or `undefined` when the family has no face. */\n const fontOf = (family: string, spec: FontSpec): Font | undefined => {\n const name = family.toLowerCase();\n const candidates: Loaded[] = [];\n for (let i = 0; i < faces.length; i++) if (faces[i]!.family.toLowerCase() === name) candidates.push(load(i));\n if (candidates.length === 0) return undefined;\n const style = styleOrder[spec.style].find((value) => candidates.some((entry) => (entry.face.style ?? \"normal\") === value))!;\n let best: Loaded | undefined;\n let bestRank = Infinity;\n for (const entry of candidates) {\n if ((entry.face.style ?? \"normal\") !== style) continue;\n const rank = weightRank(entry.range, spec.weight);\n if (rank < bestRank) {\n best = entry;\n bestRank = rank;\n }\n }\n const chosen = best!;\n const tags = new Set(chosen.font.axes.map((axis) => axis.tag));\n const instance: Record<string, number> = {};\n if (tags.has(\"wght\")) instance[\"wght\"] = Math.min(chosen.range[1], Math.max(chosen.range[0], spec.weight));\n if (tags.has(\"wdth\")) instance[\"wdth\"] = spec.stretch;\n if (tags.has(\"opsz\")) instance[\"opsz\"] = spec.size;\n if (tags.has(\"ital\")) instance[\"ital\"] = spec.style === \"italic\" ? 1 : 0;\n if (tags.has(\"slnt\")) instance[\"slnt\"] = spec.style === \"oblique\" ? -spec.angle : 0;\n const key = `${chosen.index}|${JSON.stringify(instance)}`;\n let font = instances.get(key);\n if (font === undefined) {\n font = Object.keys(instance).length === 0 ? chosen.font : chosen.font.at(instance);\n instances.set(key, font);\n }\n return font;\n };\n\n const fontsOf = (font: string): { readonly spec: FontSpec; readonly fonts: readonly Font[] } => {\n let spec = specs.get(font);\n if (spec === undefined) {\n spec = parseFont(font);\n if (specs.size >= 256) specs.clear();\n specs.set(font, spec);\n }\n let fonts = families.get(font);\n if (fonts === undefined) {\n fonts = spec.families.map((family) => fontOf(family, spec)).filter((value) => value !== undefined);\n if (fonts.length === 0) throw new RangeError(`no face of the host has a family of the font \"${font}\"`);\n if (families.size >= 256) families.clear();\n families.set(font, fonts);\n }\n return { spec, fonts };\n };\n\n return (text: string, font: string): number => {\n const { spec, fonts } = fontsOf(font);\n const sum = (parts: readonly string[], width: (part: string) => number): number => parts.reduce((total, part) => total + width(part), 0);\n const measure = (run: string, face: Font): number => {\n const runs = scriptRuns(run);\n const tagged = (part: string): number => measureWidth(face, part, spec.size, { script: scriptTag(part), shaping, rounding: rules.rounding, sum: rules.sum });\n const risky = (part: string): boolean => fallback !== undefined && shapingRisks(face, part, { script: scriptTag(part), shaping }).length > 0;\n if (runs.length === 1 && !risky(run)) return tagged(run);\n if (shaping !== \"canvas\") return sum(runs, tagged);\n // The width of a word comes from the word alone. This keeps the separator law of the rope\n return sum(canvasWords(run), (word) => {\n const parts = scriptRuns(word);\n return parts.some(risky) ? fallback!(word, font) : sum(parts, tagged);\n });\n };\n if (fonts.length === 1) return measure(text, fonts[0]!);\n let width = 0;\n let run = \"\";\n let current: Font | undefined;\n let joined = false;\n for (const character of text) {\n const code = character.codePointAt(0)!;\n const stays = current !== undefined && (joined || attached.test(character));\n const face = stays ? current! : (fonts.find((value) => value.glyph(code) !== 0) ?? fonts[0]!);\n if (face !== current && run.length > 0) {\n width += measure(run, current!);\n run = \"\";\n }\n current = face;\n run += character;\n joined = code === 0x200d;\n }\n if (run.length > 0) width += measure(run, current!);\n return width;\n };\n}\n","/**\n * The subpath `./measurer`: the advance function of a layout engine, from the font model of typeset. The measurer of\n * `@mark1russell7/layout-contract/text` takes it as its `AdvanceFn`.\n */\nexport { fontAdvance, parseF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;GACvD,IAAI,YAAY,UAAU,OAAO,IAAI,MAAM,MAAM;GAEjD,OAAO,IAAI,YAAY,GAAG,IAAI,SAAS;IACrC,MAAM,QAAQ,WAAW,IAAI;IAC7B,OAAO,MAAM,KAAK,KAAK,IAAI,SAAU,MAAM,IAAI,IAAI,IAAI,OAAO,MAAM;GACtE,CAAC;EACH;EACA,IAAI,MAAM,WAAW,GAAG,OAAO,QAAQ,MAAM,MAAM,EAAG;EACtD,IAAI,QAAQ;EACZ,IAAI,MAAM;EACV,IAAI;EACJ,IAAI,SAAS;EACb,KAAK,MAAM,aAAa,MAAM;GAC5B,MAAM,OAAO,UAAU,YAAY,CAAC;GAEpC,MAAM,OADQ,YAAY,KAAA,MAAc,UAAU,SAAS,KAAK,SAAS,KACpD,UAAY,MAAM,MAAM,UAAU,MAAM,MAAM,IAAI,MAAM,CAAC,KAAK,MAAM;GACzF,IAAI,SAAS,WAAW,IAAI,SAAS,GAAG;IACtC,SAAS,QAAQ,KAAK,OAAQ;IAC9B,MAAM;GACR;GACA,UAAU;GACV,OAAO;GACP,SAAS,SAAS;EACpB;EACA,IAAI,IAAI,SAAS,GAAG,SAAS,QAAQ,KAAK,OAAQ;EAClD,OAAO;CACT;AACF"}
|
|
1
|
+
{"version":3,"file":"measurer.js","names":[],"sources":["../../src/measurer/advance.ts","../../src/measurer.ts"],"sourcesContent":["/**\n * The advance function of the font model: the width of a text in a CSS font, as the measurer of\n * `@mark1russell7/layout-contract/text` asks for it. The host gives the font files as faces. The function finds the face\n * of each run of the text with the matching rules of CSS. It finds the script of the run, and measures the run with the\n * rules of one text engine.\n */\nimport { engines, isEngineName, type EngineName, type EngineRules } from \"../fonts/engines.ts\";\nimport { measureWidth, readFont, type Font } from \"../fonts/font.ts\";\nimport { shapingRisks } from \"../fonts/risks.ts\";\nimport type { Decompress } from \"../fonts/sfnt.ts\";\nimport { canvasWords } from \"../fonts/words.ts\";\n\n/** This function gives the width of a text in a CSS font, as `AdvanceFn` of layout-contract does. */\nexport type AdvanceFn = (text: string, font: string) => number;\n\n/** One font file of the host, with the family, the weight and the style that CSS matches. */\nexport interface FontFace {\n /** The family name, as the CSS font names it. The match ignores the case. */\n readonly family: string;\n /** The bytes of a TrueType, OpenType or WOFF2 file. */\n readonly data: Uint8Array;\n /**\n * The weight of the face: one value, or the range of a variable font. The default is the range of the `wght` axis of the\n * font, or 400 for a font with no `wght` axis.\n */\n readonly weight?: number | readonly [number, number];\n /** The style of the face. The default is `normal`. */\n readonly style?: \"normal\" | \"italic\" | \"oblique\";\n /** The Brotli decompressor of a WOFF2 file. */\n readonly decompress?: Decompress;\n}\n\n/** The options of `fontAdvance`. */\nexport interface FontAdvanceOptions {\n /** The font files of the host. The order sets the choice between two faces with the same match. */\n readonly faces: readonly FontFace[];\n /** The text engine: a row name of `engines`, or the rules of a row. The default is `freetype`, as Chromium on Linux. */\n readonly engine?: EngineName | EngineRules;\n /**\n * The shaping of `measureWidth`. The default is `canvas`, as `canvasAdvance` of layout-contract measures each segment\n * with `measureText`. Use `dom` for the widths of a text in a page.\n */\n readonly shaping?: \"dom\" | \"canvas\";\n /** The shaper of the host. Under the shaping `canvas`, it measures each word that `shapingRisks` flags. The shaping `dom` does not use it. */\n readonly fallback?: AdvanceFn;\n}\n\n/** The parts of a CSS font shorthand that change a width. */\nexport interface FontSpec {\n readonly style: \"normal\" | \"italic\" | \"oblique\";\n /** The angle of an oblique style in degrees. CSS gives 14 when the font names no angle. */\n readonly angle: number;\n /** The weight from 1 to 1000. */\n readonly weight: number;\n /** The width of the font as a percent of the normal width, from the keyword of `font-stretch`. */\n readonly stretch: number;\n /** The size in px. */\n readonly size: number;\n /** The family names in the order of the font, with no quotes. */\n readonly families: readonly string[];\n}\n\nconst stretches: Readonly<Record<string, number>> = {\n \"ultra-condensed\": 50,\n \"extra-condensed\": 62.5,\n condensed: 75,\n \"semi-condensed\": 87.5,\n \"semi-expanded\": 112.5,\n expanded: 125,\n \"extra-expanded\": 150,\n \"ultra-expanded\": 200,\n};\n\n// Each number pattern matches a text in one way only. Thus a long run of digits does not make the match slow.\nconst sizePattern = /^((?:\\d+(?:\\.\\d+)?|\\.\\d+)(?:e[+-]?\\d+)?)(px|pt)(\\/.*)?$/i;\nconst anglePattern = /^(-?(?:\\d+(?:\\.\\d+)?|\\.\\d+))deg$/i;\nconst weightPattern = /^(?:\\d+(?:\\.\\d+)?|\\.\\d+)$/;\n\n/**\n * This function reads a CSS font shorthand, for example `italic 700 16px/1.2 \"Noto Sans\", sans-serif`. The size must be in\n * `px` or `pt`. The function refuses `small-caps`, the system font keywords and the relative sizes with a `RangeError`.\n */\nexport function parseFont(font: string): FontSpec {\n const tokens = font.trim().split(/\\s+/);\n let style: FontSpec[\"style\"] = \"normal\";\n let angle = 14;\n let weight = 400;\n let stretch = 100;\n let index = 0;\n for (; index < tokens.length; index++) {\n const token = tokens[index]!;\n const lower = token.toLowerCase();\n const size = sizePattern.exec(token);\n if (size !== null) break;\n if (lower === \"normal\") continue;\n if (lower === \"italic\") style = \"italic\";\n else if (lower === \"oblique\") {\n style = \"oblique\";\n const next = anglePattern.exec(tokens[index + 1] ?? \"\");\n if (next !== null) {\n angle = Number(next[1]);\n index++;\n }\n } else if (lower === \"bold\" || lower === \"bolder\") weight = 700;\n else if (lower === \"lighter\") weight = 100;\n else if (weightPattern.test(token) && Number(token) >= 1 && Number(token) <= 1000) weight = Number(token);\n else if (Object.hasOwn(stretches, lower)) stretch = stretches[lower]!;\n else throw new RangeError(`the font \"${font}\" has the part \"${token}\", which the measurer does not know`);\n }\n const size = sizePattern.exec(tokens[index] ?? \"\");\n if (size === null) throw new RangeError(`the font \"${font}\" has no size in px or pt`);\n let rest = tokens.slice(index + 1).join(\" \");\n // A line height after a space: \"16px / 1.2\" or \"16px /1.2\"\n if (size[3] === undefined && rest.startsWith(\"/\")) rest = rest.slice(1).trim().replace(/^\\S+\\s*/, \"\");\n // A line height after a slash and a space: \"16px/ 1.2\"\n else if (size[3] === \"/\") rest = rest.replace(/^\\S+\\s*/, \"\");\n const families = rest\n .split(\",\")\n .map((family) => family.trim().replace(/^([\"'])(.*)\\1$/, \"$2\").trim())\n .filter((family) => family.length > 0);\n if (families.length === 0) throw new RangeError(`the font \"${font}\" has no family`);\n const value = Number(size[1]);\n return { style, angle, weight, stretch, size: size[2]!.toLowerCase() === \"pt\" ? (value * 4) / 3 : value, families };\n}\n\n/** The Unicode scripts and their OpenType tags. A script that is not in the list gets `DFLT`. */\nconst scriptPatterns: readonly (readonly [RegExp, string])[] = [\n [/\\p{sc=Latin}/u, \"latn\"],\n [/\\p{sc=Greek}/u, \"grek\"],\n [/\\p{sc=Cyrillic}/u, \"cyrl\"],\n [/\\p{sc=Armenian}/u, \"armn\"],\n [/\\p{sc=Hebrew}/u, \"hebr\"],\n [/\\p{sc=Arabic}/u, \"arab\"],\n [/\\p{sc=Syriac}/u, \"syrc\"],\n [/\\p{sc=Thaana}/u, \"thaa\"],\n [/\\p{sc=Devanagari}/u, \"deva\"],\n [/\\p{sc=Bengali}/u, \"beng\"],\n [/\\p{sc=Gurmukhi}/u, \"guru\"],\n [/\\p{sc=Gujarati}/u, \"gujr\"],\n [/\\p{sc=Oriya}/u, \"orya\"],\n [/\\p{sc=Tamil}/u, \"taml\"],\n [/\\p{sc=Telugu}/u, \"telu\"],\n [/\\p{sc=Kannada}/u, \"knda\"],\n [/\\p{sc=Malayalam}/u, \"mlym\"],\n [/\\p{sc=Sinhala}/u, \"sinh\"],\n [/\\p{sc=Thai}/u, \"thai\"],\n [/\\p{sc=Lao}/u, \"lao \"],\n [/\\p{sc=Tibetan}/u, \"tibt\"],\n [/\\p{sc=Myanmar}/u, \"mymr\"],\n [/\\p{sc=Georgian}/u, \"geor\"],\n [/\\p{sc=Hangul}/u, \"hang\"],\n [/\\p{sc=Ethiopic}/u, \"ethi\"],\n [/\\p{sc=Khmer}/u, \"khmr\"],\n [/\\p{sc=Mongolian}/u, \"mong\"],\n [/[\\p{sc=Hiragana}\\p{sc=Katakana}]/u, \"kana\"],\n [/\\p{sc=Bopomofo}/u, \"bopo\"],\n [/\\p{sc=Han}/u, \"hani\"],\n];\n\nconst neutral = /[\\p{sc=Common}\\p{sc=Inherited}\\p{sc=Unknown}]/u;\n\n/** This function divides a text into parts of one script. A neutral character stays with the part before it. */\nexport function scriptRuns(text: string): string[] {\n if (/^[\\0-\\x7f]*$/.test(text)) return [text];\n const runs: string[] = [];\n let run = \"\";\n let current: string | undefined;\n for (const character of text) {\n if (!neutral.test(character)) {\n const tag = scriptTag(character).replace(/kana|bopo/, \"hani\");\n if (current !== undefined && tag !== current) {\n runs.push(run);\n run = \"\";\n }\n current = tag;\n }\n run += character;\n }\n runs.push(run);\n return runs;\n}\n\n/**\n * This function gives the OpenType script tag of a text, as HarfBuzz guesses it. The tag is the script of the first\n * character that is not of the scripts Common, Inherited or Unknown. A text of only those characters, for example emoji, gets `DFLT`.\n */\nexport function scriptTag(text: string): string {\n for (const character of text) {\n if (neutral.test(character)) continue;\n for (const [pattern, tag] of scriptPatterns) if (pattern.test(character)) return tag;\n return \"DFLT\";\n }\n return \"DFLT\";\n}\n\n/** A character that stays in the run of the character before it: a mark, a joiner, a variation selector, a tag or a skin tone. */\nconst attached = /^[\\p{M}︀-️\\u{e0020}-\\u{e007f}\\u{e0100}-\\u{e01ef}\\u{1f3fb}-\\u{1f3ff}]$/u;\n\nconst styleOrder: Readonly<Record<FontSpec[\"style\"], readonly FontSpec[\"style\"][]>> = {\n normal: [\"normal\", \"oblique\", \"italic\"],\n italic: [\"italic\", \"oblique\", \"normal\"],\n oblique: [\"oblique\", \"italic\", \"normal\"],\n};\n\n/** A face with its font, read at the first use. */\ninterface Loaded {\n readonly face: FontFace;\n readonly index: number;\n readonly font: Font;\n readonly range: readonly [number, number];\n}\n\n/**\n * This function gives the rank of a face for the weight `weight`, with the rules of CSS Fonts 4. A lower rank is a\n * better match. A face whose range holds the weight has the rank 0.\n */\nfunction weightRank(range: readonly [number, number], weight: number): number {\n const [min, max] = range;\n if (min <= weight && weight <= max) return 0;\n const above = min > weight;\n // The groups of CSS: 1 is the first choice after an exact match, 3 is the last\n if (weight >= 400 && weight <= 500) {\n if (above && min <= 500) return 1000 + min;\n if (!above) return 3000 - max;\n return 5000 + min;\n }\n if (weight < 400) return above ? 3000 + min : 1000 - max;\n return above ? 1000 + min : 3000 - max;\n}\n\n/**\n * This function gives the advance function of the faces of the host: the width in px of a text in a CSS font. Each run\n * of the text gets the first family of the font with a glyph for its first character. When no family has a glyph, the\n * run gets the first family that has a face. The width of a run is `measureWidth` with the size of the font, the script\n * of `scriptTag` and the rules of the engine. The instance of a variable face takes the weight and the stretch as `wdth`.\n * It takes the style as `ital` or `slnt`, and the size as `opsz`, as `font-optical-sizing: auto` does.\n */\nexport function fontAdvance(options: FontAdvanceOptions): (text: string, font: string) => number {\n const engine = options.engine ?? \"freetype\";\n if (typeof engine === \"string\" && !isEngineName(engine)) throw new RangeError(`the engine \"${engine}\" is not a row of engines`);\n const rules: EngineRules = typeof engine === \"string\" ? engines[engine] : engine;\n const shaping = options.shaping ?? \"canvas\";\n const fallback = shaping === \"canvas\" ? options.fallback : undefined;\n const faces = options.faces;\n const loaded = new Map<number, Loaded>();\n const specs = new Map<string, FontSpec>();\n const instances = new Map<string, Font>();\n const families = new Map<string, readonly Font[] | undefined>();\n\n const load = (index: number): Loaded => {\n let entry = loaded.get(index);\n if (entry === undefined) {\n const face = faces[index]!;\n const font = readFont(face.data, { deltas: rules.deltas, metrics: rules.metrics, ...(face.decompress === undefined ? {} : { decompress: face.decompress }) });\n const axis = font.axes.find((value) => value.tag === \"wght\");\n const declared = face.weight;\n const range: readonly [number, number] = typeof declared === \"number\" ? [declared, declared] : (declared ?? (axis === undefined ? [400, 400] : [axis.min, axis.max]));\n entry = { face, index, font, range };\n loaded.set(index, entry);\n }\n return entry;\n };\n\n /** This function gives the font of the best face of a family for the spec, or `undefined` when the family has no face. */\n const fontOf = (family: string, spec: FontSpec): Font | undefined => {\n const name = family.toLowerCase();\n const candidates: Loaded[] = [];\n for (let i = 0; i < faces.length; i++) if (faces[i]!.family.toLowerCase() === name) candidates.push(load(i));\n if (candidates.length === 0) return undefined;\n const style = styleOrder[spec.style].find((value) => candidates.some((entry) => (entry.face.style ?? \"normal\") === value))!;\n let best: Loaded | undefined;\n let bestRank = Infinity;\n for (const entry of candidates) {\n if ((entry.face.style ?? \"normal\") !== style) continue;\n const rank = weightRank(entry.range, spec.weight);\n if (rank < bestRank) {\n best = entry;\n bestRank = rank;\n }\n }\n const chosen = best!;\n const tags = new Set(chosen.font.axes.map((axis) => axis.tag));\n const instance: Record<string, number> = {};\n if (tags.has(\"wght\")) instance[\"wght\"] = Math.min(chosen.range[1], Math.max(chosen.range[0], spec.weight));\n if (tags.has(\"wdth\")) instance[\"wdth\"] = spec.stretch;\n if (tags.has(\"opsz\")) instance[\"opsz\"] = spec.size;\n if (tags.has(\"ital\")) instance[\"ital\"] = spec.style === \"italic\" ? 1 : 0;\n if (tags.has(\"slnt\")) instance[\"slnt\"] = spec.style === \"oblique\" ? -spec.angle : 0;\n const key = `${chosen.index}|${JSON.stringify(instance)}`;\n let font = instances.get(key);\n if (font === undefined) {\n font = Object.keys(instance).length === 0 ? chosen.font : chosen.font.at(instance);\n // A key holds the size for an axis opsz, so this cache has a bound, as the other caches have\n if (instances.size >= 256) instances.clear();\n instances.set(key, font);\n }\n return font;\n };\n\n const fontsOf = (font: string): { readonly spec: FontSpec; readonly fonts: readonly Font[] } => {\n let spec = specs.get(font);\n if (spec === undefined) {\n spec = parseFont(font);\n if (specs.size >= 256) specs.clear();\n specs.set(font, spec);\n }\n let fonts = families.get(font);\n if (fonts === undefined) {\n fonts = spec.families.map((family) => fontOf(family, spec)).filter((value) => value !== undefined);\n if (fonts.length === 0) throw new RangeError(`no face of the host has a family of the font \"${font}\"`);\n if (families.size >= 256) families.clear();\n families.set(font, fonts);\n }\n return { spec, fonts };\n };\n\n return (text: string, font: string): number => {\n const { spec, fonts } = fontsOf(font);\n const sum = (parts: readonly string[], width: (part: string) => number): number => parts.reduce((total, part) => total + width(part), 0);\n const measure = (run: string, face: Font): number => {\n const runs = scriptRuns(run);\n const tagged = (part: string): number => measureWidth(face, part, spec.size, { script: scriptTag(part), shaping, rounding: rules.rounding, sum: rules.sum });\n const risky = (part: string): boolean => fallback !== undefined && shapingRisks(face, part, { script: scriptTag(part), shaping }).length > 0;\n if (runs.length === 1 && !risky(run)) return tagged(run);\n if (shaping !== \"canvas\") return sum(runs, tagged);\n // The width of a word comes from the word alone. This keeps the separator law of the rope\n return sum(canvasWords(run), (word) => {\n const parts = scriptRuns(word);\n return parts.some(risky) ? fallback!(word, font) : sum(parts, tagged);\n });\n };\n if (fonts.length === 1) return measure(text, fonts[0]!);\n let width = 0;\n let run = \"\";\n let current: Font | undefined;\n let joined = false;\n for (const character of text) {\n const code = character.codePointAt(0)!;\n const stays = current !== undefined && (joined || attached.test(character));\n const face = stays ? current! : (fonts.find((value) => value.glyph(code) !== 0) ?? fonts[0]!);\n if (face !== current && run.length > 0) {\n width += measure(run, current!);\n run = \"\";\n }\n current = face;\n run += character;\n joined = code === 0x200d;\n }\n if (run.length > 0) width += measure(run, current!);\n return width;\n };\n}\n","/**\n * The subpath `./measurer`: the advance function of a layout engine, from the font model of typeset. The measurer of\n * `@mark1russell7/layout-contract/text` takes it as its `AdvanceFn`.\n */\nexport { fontAdvance, parseFont, scriptTag, type AdvanceFn, type FontAdvanceOptions, type FontFace, type FontSpec } from \"./measurer/advance.ts\";\n"],"mappings":";;;;;;;;;;AA8DA,MAAM,YAA8C;CAClD,mBAAmB;CACnB,mBAAmB;CACnB,WAAW;CACX,kBAAkB;CAClB,iBAAiB;CACjB,UAAU;CACV,kBAAkB;CAClB,kBAAkB;AACpB;AAGA,MAAM,cAAc;AACpB,MAAM,eAAe;AACrB,MAAM,gBAAgB;;;;;AAMtB,SAAgB,UAAU,MAAwB;CAChD,MAAM,SAAS,KAAK,KAAK,CAAC,CAAC,MAAM,KAAK;CACtC,IAAI,QA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EAAG;EACtD,IAAI,QAAQ;EACZ,IAAI,MAAM;EACV,IAAI;EACJ,IAAI,SAAS;EACb,KAAK,MAAM,aAAa,MAAM;GAC5B,MAAM,OAAO,UAAU,YAAY,CAAC;GAEpC,MAAM,OADQ,YAAY,KAAA,MAAc,UAAU,SAAS,KAAK,SAAS,KACpD,UAAY,MAAM,MAAM,UAAU,MAAM,MAAM,IAAI,MAAM,CAAC,KAAK,MAAM;GACzF,IAAI,SAAS,WAAW,IAAI,SAAS,GAAG;IACtC,SAAS,QAAQ,KAAK,OAAQ;IAC9B,MAAM;GACR;GACA,UAAU;GACV,OAAO;GACP,SAAS,SAAS;EACpB;EACA,IAAI,IAAI,SAAS,GAAG,SAAS,QAAQ,KAAK,OAAQ;EAClD,OAAO;CACT;AACF"}
|
|
@@ -43,6 +43,11 @@ interface ParagraphOptions {
|
|
|
43
43
|
* offset. The width of each part of a word comes from `widthOf`, so the kerning across an offset is not in the sum.
|
|
44
44
|
*/
|
|
45
45
|
readonly hyphenate?: (word: string) => readonly number[];
|
|
46
|
+
/**
|
|
47
|
+
* The hook of the break places inside a word, for example `lineBreaks` of `./segmentation`. It gives offsets in a word where
|
|
48
|
+
* a line can end with no hyphen and no cost. The default gives no offset. This hook wins at an offset that `hyphenate` also gives.
|
|
49
|
+
*/
|
|
50
|
+
readonly breaks?: (word: string) => readonly number[];
|
|
46
51
|
/** The text that a line shows at a hyphen break. The default is "-". */
|
|
47
52
|
readonly hyphen?: string;
|
|
48
53
|
/** The cost of a hyphen break. The default is 50, as in TeX. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paragraph.d.ts","names":[],"sources":["../../src/breaking/paragraph.ts"],"mappings":";;;;;KAMY,WAAW;;UAGN;WACN;WACA;WACA;;;UAIM;WACN;WACA;WACA;;;;;;UAOM;WACN;WACA;WACA;WACA;;WAEA;;;KAIC,OAAO,MAAM,OAAO;;UAGf;WACN,gBAAgB;;;UAIV;;WAEN,SAAS;;;;;WAKT,aAAa;;
|
|
1
|
+
{"version":3,"file":"paragraph.d.ts","names":[],"sources":["../../src/breaking/paragraph.ts"],"mappings":";;;;;KAMY,WAAW;;UAGN;WACN;WACA;WACA;;;UAIM;WACN;WACA;WACA;;;;;;UAOM;WACN;WACA;WACA;WACA;;WAEA;;;KAIC,OAAO,MAAM,OAAO;;UAGf;WACN,gBAAgB;;;UAIV;;WAEN,SAAS;;;;;WAKT,aAAa;;;;;WAKb,UAAU;;WAEV;;WAEA;;;;;;iBASK,YAAY,cAAc,SAAS,mBAAmB;;UA0BrD;WACN;;WAEA;;WAEA;;WAEA;;;iBAIK,QAAQ,gBAAgB,QAAQ;;iBAOhC,UAAU,gBAAgB,QAAQ;;iBAOlC,UAAU,gBAAgB,QAAQ,eAAe;;;;;iBAcjD,QAAQ,WAAW,WAAW,4BAA4B"}
|
package/build/fonts-inspect.d.ts
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import { i as glyphAdvances, s as shapingWords, u as defaultFeatures } from "./chunks/font.js";
|
|
2
2
|
import { n as readTables } from "./chunks/sfnt.js";
|
|
3
|
+
/** The types of the syllables of the Indic machine of HarfBuzz. */
|
|
4
|
+
type IndicSyllableType = "consonant" | "vowel" | "standalone" | "symbol" | "broken" | "non-indic";
|
|
5
|
+
/**
|
|
6
|
+
* This function divides a text into the syllables of the Indic machine of HarfBuzz. It does not normalize the text and
|
|
7
|
+
* does not insert dotted circles.
|
|
8
|
+
*/
|
|
9
|
+
export declare function indicSyllables(text: string): {
|
|
10
|
+
readonly text: string;
|
|
11
|
+
readonly type: IndicSyllableType;
|
|
12
|
+
}[];
|
|
3
13
|
/**
|
|
4
14
|
* This function divides the text of a canvas into the words that Blink shapes one at a time. Each space, tab and zero
|
|
5
15
|
* width space is a word alone. Each CJK character starts a word, with its marks and the CJK characters of the script
|
|
@@ -11,5 +21,5 @@ export declare function canvasWords(text: string): string[];
|
|
|
11
21
|
* part of a word where the bidi level changes. Blink shapes each bidi run alone and adds the widths of the words in this order.
|
|
12
22
|
*/
|
|
13
23
|
export declare function canvasSegments(text: string): string[];
|
|
14
|
-
export { defaultFeatures, glyphAdvances, readTables, shapingWords };
|
|
24
|
+
export { type IndicSyllableType, defaultFeatures, glyphAdvances, readTables, shapingWords };
|
|
15
25
|
//# sourceMappingURL=fonts-inspect.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fonts-inspect.d.ts","names":[],"sources":["../src/fonts/words.ts"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"fonts-inspect.d.ts","names":[],"sources":["../src/fonts/indic.ts","../src/fonts/words.ts"],"mappings":";;;KAqMY;;;;;wBAOI,eAAe;WAA0B;WAAuB,MAAM;;;;;;;wBCpJtE,YAAY;;;;;wBAgBZ,eAAe"}
|
package/build/fonts-inspect.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { o as canvasSegments, s as canvasWords,
|
|
1
|
+
export { o as canvasSegments, s as canvasWords, g as defaultFeatures, t as glyphAdvances, d as indicSyllables, h as readTables, a as shapingWords } from "./chunks/font.js";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** A place where a line can end. */
|
|
2
|
+
interface LineBreak {
|
|
3
|
+
/** The offset in UTF-16 units of the first character after the break. */
|
|
4
|
+
readonly offset: number;
|
|
5
|
+
/** This value is `true` when a line must end here, as at a line feed or at the end of the text. */
|
|
6
|
+
readonly required: boolean;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* This function gives the places where a line of a text can end, by the rules of UAX #14 without tailoring. The last place is
|
|
10
|
+
* the end of the text, and an empty text has no place.
|
|
11
|
+
*/
|
|
12
|
+
export declare function lineBreaks(text: string): readonly LineBreak[];
|
|
13
|
+
export declare const unicodeVersion = "17.0.0";
|
|
14
|
+
/** This function gives the grapheme clusters of a text, in their order. */
|
|
15
|
+
export declare function graphemes(text: string): readonly string[];
|
|
16
|
+
/** This function gives the offset in UTF-16 units of each word boundary of a text, with the end of the text and without its start. */
|
|
17
|
+
export declare function wordBreaks(text: string): readonly number[];
|
|
18
|
+
export type { LineBreak };
|
|
19
|
+
//# sourceMappingURL=segmentation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"segmentation.d.ts","names":[],"sources":["../src/segmentation/line.ts","../src/segmentation/line-table.ts","../src/segmentation/segments.ts"],"mappings":";UAOiB;;WAEN;;WAEA;;;;;;wBAsLK,WAAW,wBAAwB;qBChMtC;;wBCOG,UAAU;;wBAKV,WAAW"}
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
// src/segmentation/line-table.ts
|
|
2
|
+
const unicodeVersion = "17.0.0";
|
|
3
|
+
const classNames = "AL CM BA LF BK CR SP EX QU PR PO OP CP IS HY SY NU CL NL GL BB HH HL JL JV JT NS AK VI AS ID VF ZW ZWJ B2 IN WJ EB H2 H3 CB AP RI EM".split(" ");
|
|
4
|
+
const classRuns = "9B1C1D2E1FiB1G1H1I1A1J1K1A1I1L1M1A1J1N1O1N1PaQ2N3A1HrA1L1J1MtA1L1C1R1A6B1SqB1T1L1K3J5A1I1A1C2A1K1J2A1U6A1I3A1LegA1U3A1UiA1UwA2kB7TdBeA1N78A7B73A1N1V4A1J1A19B1V1B1A2B1A2B1H1B8ArW4A4WdA6Q3A3K2N2AbB1H1B3H17AlBaQ1K2Q3A1B2rA1H1A7B1Q1A6B2A2B1A4B2AaQnA1BuArB2jAbBfAaQxA9B4A1N1H3A1B2JmA4B1A9B1A3B1A5B17A3B1gA2Q5A9B16AoB1QxB1iA3B1AiB1A7BaA2B2CaQhA3B1kA1B1A7B2A2B2A3B9A1BaA2B2AaQ2A2K5A1K1A1J2A1B2A3B1kA1B1A5B4A2B2A3B3A1BkAaQ2B3A1BbA3B1kA1B1A8B1A3B1A3BkA2B2AaQ1A1J8A6B1A3B1kA1B1A7B2A2B2A3B7A3BaA2B2AaQiA1B1nA5B3A3B1A4B9A1BeAaQ9A1J6A5B1jA1B1A7B1A3B1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 2 1f 1 4 1 mi q 1 2h c 5y q 27 2 2e 2 2v 5 17 1 2m 1 2e 9 1c 1 14 8 mkd 3 1j wp t hv 8mc 6l8 e8 ls a m z 1 j 1 4 45 5a 3 6 2 6 2 6 2 3 3 7 1 7 m41 5 b 7 9 5p2 15 w 2p 37 6pp 4 1 7 1 2 1 83 f 1 t 3 2 1 e 4 8 b0 6bo 2f 9 n 5n1 1 5m 1 5a 1 2 a 2t 3 d 18 4 9 7 2 e 6 4a x c 9 1 1y 1 m c 17 4 5 c h 3 1 3 1z 1 1 1 57 2 1r d 4 1 o i 1 q 2 d 1 2e 2d 1c 1y 6 1 3 3 2 4 3 4 b 2 7 9 6b c 4 1 7v 1b 1 a 1 55 34 d 3 b 3 1l 1 1 4 g 2 c 4 a zr 1eke 2 1eke i9du";
|
|
6
|
+
// src/segmentation/line.ts
|
|
7
|
+
/**
|
|
8
|
+
* The line break algorithm of UAX #14. The rules run in their order, and the first rule that matches decides. The class of a
|
|
9
|
+
* code point comes from a table that the tool in `packages/conformance` makes from the property files of Unicode.
|
|
10
|
+
*/
|
|
11
|
+
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ!#$%&()*+-./:;<=>?@[]^_{|}~";
|
|
12
|
+
let table;
|
|
13
|
+
/** This function decodes the runs one time, at the first use, so an import of the entry costs no work. */
|
|
14
|
+
function tableOf() {
|
|
15
|
+
if (table !== void 0) return table;
|
|
16
|
+
const runs = [...classRuns.matchAll(/([0-9a-z]+)([^0-9a-z])/gu)];
|
|
17
|
+
const starts = new Uint32Array(runs.length + 1);
|
|
18
|
+
const classes = new Uint8Array(runs.length);
|
|
19
|
+
let start = 0;
|
|
20
|
+
runs.forEach((run, index) => {
|
|
21
|
+
starts[index] = start;
|
|
22
|
+
classes[index] = alphabet.indexOf(run[2]);
|
|
23
|
+
start += Number.parseInt(run[1], 36);
|
|
24
|
+
});
|
|
25
|
+
starts[runs.length] = start;
|
|
26
|
+
const lengths = eastAsianRuns.split(" ").map((length) => Number.parseInt(length, 36));
|
|
27
|
+
const east = new Uint32Array(lengths.length + 1);
|
|
28
|
+
lengths.forEach((length, index) => {
|
|
29
|
+
east[index + 1] = east[index] + length;
|
|
30
|
+
});
|
|
31
|
+
table = {
|
|
32
|
+
starts,
|
|
33
|
+
classes,
|
|
34
|
+
east
|
|
35
|
+
};
|
|
36
|
+
return table;
|
|
37
|
+
}
|
|
38
|
+
/** This function gives the index of the last start that is not above `code`. */
|
|
39
|
+
function indexOfRun(starts, code) {
|
|
40
|
+
let low = 0;
|
|
41
|
+
let high = starts.length - 1;
|
|
42
|
+
while (high - low > 1) {
|
|
43
|
+
const middle = low + high >>> 1;
|
|
44
|
+
if (starts[middle] <= code) low = middle;
|
|
45
|
+
else high = middle;
|
|
46
|
+
}
|
|
47
|
+
return low;
|
|
48
|
+
}
|
|
49
|
+
const breakClasses = /* @__PURE__ */ new Set([
|
|
50
|
+
"BK",
|
|
51
|
+
"CR",
|
|
52
|
+
"LF",
|
|
53
|
+
"NL",
|
|
54
|
+
"SP",
|
|
55
|
+
"ZW"
|
|
56
|
+
]);
|
|
57
|
+
/** This function makes the items of a text. It applies the rules LB9 and LB10. */
|
|
58
|
+
function itemsOf(text) {
|
|
59
|
+
const { starts, classes, east } = tableOf();
|
|
60
|
+
const items = [];
|
|
61
|
+
let offset = 0;
|
|
62
|
+
for (const character of text) {
|
|
63
|
+
const code = character.codePointAt(0);
|
|
64
|
+
const name = classNames[classes[indexOfRun(starts, code)]];
|
|
65
|
+
const combining = name === "CM" || name === "ZWJ";
|
|
66
|
+
const last = items.at(-1);
|
|
67
|
+
if (combining && last !== void 0 && !breakClasses.has(last.name)) last.zwj = name === "ZWJ";
|
|
68
|
+
else if (combining) items.push({
|
|
69
|
+
name: "AL",
|
|
70
|
+
code: 65,
|
|
71
|
+
start: offset,
|
|
72
|
+
east: false,
|
|
73
|
+
zwj: name === "ZWJ"
|
|
74
|
+
});
|
|
75
|
+
else items.push({
|
|
76
|
+
name,
|
|
77
|
+
code,
|
|
78
|
+
start: offset,
|
|
79
|
+
east: indexOfRun(east, code) % 2 === 1,
|
|
80
|
+
zwj: false
|
|
81
|
+
});
|
|
82
|
+
offset += character.length;
|
|
83
|
+
}
|
|
84
|
+
return items;
|
|
85
|
+
}
|
|
86
|
+
const initial = /^\p{Pi}$/u;
|
|
87
|
+
const final = /^\p{Pf}$/u;
|
|
88
|
+
const pictographic = /^\p{Extended_Pictographic}$/u;
|
|
89
|
+
const unassigned = /^\p{Cn}$/u;
|
|
90
|
+
const of = (item) => String.fromCodePoint(item.code);
|
|
91
|
+
const isPi = (item) => initial.test(of(item));
|
|
92
|
+
const isPf = (item) => final.test(of(item));
|
|
93
|
+
const inClass = (item, names) => item !== void 0 && names.has(item.name);
|
|
94
|
+
const isName = (item, name) => item?.name === name;
|
|
95
|
+
const beforeOpening = /* @__PURE__ */ new Set([
|
|
96
|
+
"BK",
|
|
97
|
+
"CR",
|
|
98
|
+
"LF",
|
|
99
|
+
"NL",
|
|
100
|
+
"OP",
|
|
101
|
+
"QU",
|
|
102
|
+
"GL",
|
|
103
|
+
"SP",
|
|
104
|
+
"ZW"
|
|
105
|
+
]);
|
|
106
|
+
const afterClosing = /* @__PURE__ */ new Set([
|
|
107
|
+
"SP",
|
|
108
|
+
"GL",
|
|
109
|
+
"WJ",
|
|
110
|
+
"CL",
|
|
111
|
+
"QU",
|
|
112
|
+
"CP",
|
|
113
|
+
"EX",
|
|
114
|
+
"IS",
|
|
115
|
+
"SY",
|
|
116
|
+
"BK",
|
|
117
|
+
"CR",
|
|
118
|
+
"LF",
|
|
119
|
+
"NL",
|
|
120
|
+
"ZW"
|
|
121
|
+
]);
|
|
122
|
+
const beforeHyphen = /* @__PURE__ */ new Set([
|
|
123
|
+
"BK",
|
|
124
|
+
"CR",
|
|
125
|
+
"LF",
|
|
126
|
+
"NL",
|
|
127
|
+
"SP",
|
|
128
|
+
"ZW",
|
|
129
|
+
"CB",
|
|
130
|
+
"GL"
|
|
131
|
+
]);
|
|
132
|
+
const alphabetic = /* @__PURE__ */ new Set(["AL", "HL"]);
|
|
133
|
+
const hyphens = /* @__PURE__ */ new Set(["HY", "HH"]);
|
|
134
|
+
const emoji = /* @__PURE__ */ new Set([
|
|
135
|
+
"ID",
|
|
136
|
+
"EB",
|
|
137
|
+
"EM"
|
|
138
|
+
]);
|
|
139
|
+
const prefix = /* @__PURE__ */ new Set(["PR", "PO"]);
|
|
140
|
+
const closing = /* @__PURE__ */ new Set(["CL", "CP"]);
|
|
141
|
+
const separators = /* @__PURE__ */ new Set(["SY", "IS"]);
|
|
142
|
+
const hangul = /* @__PURE__ */ new Set([
|
|
143
|
+
"JL",
|
|
144
|
+
"JV",
|
|
145
|
+
"JT",
|
|
146
|
+
"H2",
|
|
147
|
+
"H3"
|
|
148
|
+
]);
|
|
149
|
+
const aksara = (item) => item !== void 0 && (item.name === "AK" || item.name === "AS" || item.code === 9676);
|
|
150
|
+
const aksaraStart = (item) => item !== void 0 && (item.name === "AK" || item.code === 9676);
|
|
151
|
+
/** This function tells if the items before `index` end with `NU (SY | IS)*`. */
|
|
152
|
+
function afterNumber(items, index) {
|
|
153
|
+
let i = index;
|
|
154
|
+
while (i >= 0 && separators.has(items[i].name)) i--;
|
|
155
|
+
return isName(items[i], "NU");
|
|
156
|
+
}
|
|
157
|
+
/** This function applies the rules LB4 to LB31 at the start of the item `i`. It gives 0 for no break, 1 for a break and 2 for a necessary break. */
|
|
158
|
+
function ruleAt(items, i) {
|
|
159
|
+
const a = items[i - 1];
|
|
160
|
+
const b = items[i];
|
|
161
|
+
const c = a.name;
|
|
162
|
+
const d = b.name;
|
|
163
|
+
const earlier = items[i - 2];
|
|
164
|
+
const later = items[i + 1];
|
|
165
|
+
if (c === "BK" || c === "NL" || c === "LF") return 2;
|
|
166
|
+
if (c === "CR") return d === "LF" ? 0 : 2;
|
|
167
|
+
if (d === "BK" || d === "CR" || d === "LF" || d === "NL" || d === "SP" || d === "ZW") return 0;
|
|
168
|
+
let last = i - 1;
|
|
169
|
+
while (last >= 0 && items[last].name === "SP") last--;
|
|
170
|
+
const beforeSpaces = items[last];
|
|
171
|
+
if (isName(beforeSpaces, "ZW")) return 1;
|
|
172
|
+
if (a.zwj) return 0;
|
|
173
|
+
if (d === "WJ" || c === "WJ" || c === "GL") return 0;
|
|
174
|
+
if (d === "GL" && c !== "SP" && c !== "BA" && !hyphens.has(c)) return 0;
|
|
175
|
+
if (d === "CL" || d === "CP" || d === "EX" || d === "SY") return 0;
|
|
176
|
+
if (isName(beforeSpaces, "OP")) return 0;
|
|
177
|
+
if (beforeSpaces !== void 0 && beforeSpaces.name === "QU" && isPi(beforeSpaces)) {
|
|
178
|
+
const before = items[last - 1];
|
|
179
|
+
if (before === void 0 || beforeOpening.has(before.name)) return 0;
|
|
180
|
+
}
|
|
181
|
+
if (d === "QU" && isPf(b) && (later === void 0 || afterClosing.has(later.name))) return 0;
|
|
182
|
+
if (c === "SP" && d === "IS" && isName(later, "NU")) return 1;
|
|
183
|
+
if (d === "IS") return 0;
|
|
184
|
+
if (d === "NS" && inClass(beforeSpaces, closing)) return 0;
|
|
185
|
+
if (d === "B2" && isName(beforeSpaces, "B2")) return 0;
|
|
186
|
+
if (c === "SP") return 1;
|
|
187
|
+
if (d === "QU" && !isPi(b)) return 0;
|
|
188
|
+
if (c === "QU" && !isPf(a)) return 0;
|
|
189
|
+
if (d === "QU" && (!a.east || later === void 0 || !later.east)) return 0;
|
|
190
|
+
if (c === "QU" && (!b.east || earlier === void 0 || !earlier.east)) return 0;
|
|
191
|
+
if (d === "CB" || c === "CB") return 1;
|
|
192
|
+
if (hyphens.has(c) && alphabetic.has(d) && (earlier === void 0 || beforeHyphen.has(earlier.name))) return 0;
|
|
193
|
+
if (d === "BA" || d === "HH" || d === "HY" || d === "NS" || c === "BB") return 0;
|
|
194
|
+
if (isName(earlier, "HL") && hyphens.has(c) && d !== "HL") return 0;
|
|
195
|
+
if (c === "SY" && d === "HL") return 0;
|
|
196
|
+
if (d === "IN") return 0;
|
|
197
|
+
if (alphabetic.has(c) && d === "NU") return 0;
|
|
198
|
+
if (c === "NU" && alphabetic.has(d)) return 0;
|
|
199
|
+
if (c === "PR" && emoji.has(d)) return 0;
|
|
200
|
+
if (emoji.has(c) && d === "PO") return 0;
|
|
201
|
+
if (prefix.has(c) && alphabetic.has(d)) return 0;
|
|
202
|
+
if (alphabetic.has(c) && prefix.has(d)) return 0;
|
|
203
|
+
if (prefix.has(d) && afterNumber(items, closing.has(c) ? i - 2 : i - 1)) return 0;
|
|
204
|
+
if (d === "NU" && afterNumber(items, i - 1)) return 0;
|
|
205
|
+
if (prefix.has(c) && (d === "NU" || d === "OP" && (isName(later, "NU") || isName(later, "IS") && isName(items[i + 2], "NU")))) return 0;
|
|
206
|
+
if ((c === "HY" || c === "IS") && d === "NU") return 0;
|
|
207
|
+
if (c === "JL" && (d === "JL" || d === "JV" || d === "H2" || d === "H3")) return 0;
|
|
208
|
+
if ((c === "JV" || c === "H2") && (d === "JV" || d === "JT")) return 0;
|
|
209
|
+
if ((c === "JT" || c === "H3") && d === "JT") return 0;
|
|
210
|
+
if (hangul.has(c) && d === "PO") return 0;
|
|
211
|
+
if (c === "PR" && hangul.has(d)) return 0;
|
|
212
|
+
if (alphabetic.has(c) && alphabetic.has(d)) return 0;
|
|
213
|
+
if (c === "AP" && aksara(b)) return 0;
|
|
214
|
+
if (aksara(a) && (d === "VF" || d === "VI")) return 0;
|
|
215
|
+
if (c === "VI" && aksara(earlier) && aksaraStart(b)) return 0;
|
|
216
|
+
if (aksara(a) && aksara(b) && isName(later, "VF")) return 0;
|
|
217
|
+
if (c === "IS" && alphabetic.has(d)) return 0;
|
|
218
|
+
if ((alphabetic.has(c) || c === "NU") && d === "OP" && !b.east) return 0;
|
|
219
|
+
if (c === "CP" && !a.east && (alphabetic.has(d) || d === "NU")) return 0;
|
|
220
|
+
if (c === "RI" && d === "RI") {
|
|
221
|
+
let count = 0;
|
|
222
|
+
for (let k = i - 1; k >= 0 && items[k].name === "RI"; k--) count++;
|
|
223
|
+
if (count % 2 === 1) return 0;
|
|
224
|
+
}
|
|
225
|
+
if (d === "EM" && (c === "EB" || pictographic.test(of(a)) && unassigned.test(of(a)))) return 0;
|
|
226
|
+
return 1;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* This function gives the places where a line of a text can end, by the rules of UAX #14 without tailoring. The last place is
|
|
230
|
+
* the end of the text, and an empty text has no place.
|
|
231
|
+
*/
|
|
232
|
+
function lineBreaks(text) {
|
|
233
|
+
const items = itemsOf(text);
|
|
234
|
+
const breaks = [];
|
|
235
|
+
for (let i = 1; i < items.length; i++) {
|
|
236
|
+
const rule = ruleAt(items, i);
|
|
237
|
+
if (rule !== 0) breaks.push({
|
|
238
|
+
offset: items[i].start,
|
|
239
|
+
required: rule === 2
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
if (text.length > 0) breaks.push({
|
|
243
|
+
offset: text.length,
|
|
244
|
+
required: true
|
|
245
|
+
});
|
|
246
|
+
return breaks;
|
|
247
|
+
}
|
|
248
|
+
// src/segmentation/segments.ts
|
|
249
|
+
/**
|
|
250
|
+
* The segments of UAX #29, from `Intl.Segmenter`. The results follow the Unicode version of the runtime. The locale is the root
|
|
251
|
+
* locale, so the language of the host has no effect.
|
|
252
|
+
*/
|
|
253
|
+
const graphemeSegmenter = new Intl.Segmenter("und", { granularity: "grapheme" });
|
|
254
|
+
const wordSegmenter = new Intl.Segmenter("und", { granularity: "word" });
|
|
255
|
+
/** This function gives the grapheme clusters of a text, in their order. */
|
|
256
|
+
function graphemes(text) {
|
|
257
|
+
return Array.from(graphemeSegmenter.segment(text), (part) => part.segment);
|
|
258
|
+
}
|
|
259
|
+
/** This function gives the offset in UTF-16 units of each word boundary of a text, with the end of the text and without its start. */
|
|
260
|
+
function wordBreaks(text) {
|
|
261
|
+
const offsets = Array.from(wordSegmenter.segment(text), (part) => part.index).slice(1);
|
|
262
|
+
if (text.length > 0) offsets.push(text.length);
|
|
263
|
+
return offsets;
|
|
264
|
+
}
|
|
265
|
+
export { graphemes, lineBreaks, unicodeVersion, wordBreaks };
|
|
266
|
+
|
|
267
|
+
//# sourceMappingURL=segmentation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"segmentation.js","names":[],"sources":["../src/segmentation/line-table.ts","../src/segmentation/line.ts","../src/segmentation/segments.ts"],"sourcesContent":["// Generated by `pnpm --filter @typeset/conformance tables` from Unicode 17.0.0. Do not edit.\nexport const unicodeVersion = \"17.0.0\";\nexport const classNames: readonly string[] = \"AL CM BA LF BK CR SP EX QU PR PO OP CP IS HY SY NU CL NL GL BB HH HL JL JV JT NS AK VI AS ID VF ZW ZWJ B2 IN WJ EB H2 H3 CB AP RI EM\".split(\" \");\nexport const classRuns = \"9B1C1D2E1FiB1G1H1I1A1J1K1A1I1L1M1A1J1N1O1N1PaQ2N3A1HrA1L1J1MtA1L1C1R1A6B1SqB1T1L1K3J5A1I1A1C2A1K1J2A1U6A1I3A1LegA1U3A1UiA1UwA2kB7TdBeA1N78A7B73A1N1V4A1J1A19B1V1B1A2B1A2B1H1B8ArW4A4WdA6Q3A3K2N2AbB1H1B3H17AlBaQ1K2Q3A1B2rA1H1A7B1Q1A6B2A2B1A4B2AaQnA1BuArB2jAbBfAaQxA9B4A1N1H3A1B2JmA4B1A9B1A3B1A5B17A3B1gA2Q5A9B16AoB1QxB1iA3B1AiB1A7BaA2B2CaQhA3B1kA1B1A7B2A2B2A3B9A1BaA2B2AaQ2A2K5A1K1A1J2A1B2A3B1kA1B1A5B4A2B2A3B3A1BkAaQ2B3A1BbA3B1kA1B1A8B1A3B1A3BkA2B2AaQ1A1J8A6B1A3B1kA1B1A7B2A2B2A3B7A3BaA2B2AaQiA1B1nA5B3A3B1A4B9A1BeAaQ9A1J6A5B1jA1B1A7B1A3B1A4B7A2BbA2B2AaQ7A1U9A3B1U1jA1B1A7B1A3B1A4B7A2BbA2B2AaQ3A1BcA4B1jA2B1A7B1A3B1A4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e8 ls a m z 1 j 1 4 45 5a 3 6 2 6 2 6 2 3 3 7 1 7 m41 5 b 7 9 5p2 15 w 2p 37 6pp 4 1 7 1 2 1 83 f 1 t 3 2 1 e 4 8 b0 6bo 2f 9 n 5n1 1 5m 1 5a 1 2 a 2t 3 d 18 4 9 7 2 e 6 4a x c 9 1 1y 1 m c 17 4 5 c h 3 1 3 1z 1 1 1 57 2 1r d 4 1 o i 1 q 2 d 1 2e 2d 1c 1y 6 1 3 3 2 4 3 4 b 2 7 9 6b c 4 1 7v 1b 1 a 1 55 34 d 3 b 3 1l 1 1 4 g 2 c 4 a zr 1eke 2 1eke i9du\";\n","/**\n * The line break algorithm of UAX #14. The rules run in their order, and the first rule that matches decides. The class of a\n * code point comes from a table that the tool in `packages/conformance` makes from the property files of Unicode.\n */\nimport { classNames, classRuns, eastAsianRuns } from \"./line-table.ts\";\n\n/** A place where a line can end. */\nexport interface LineBreak {\n /** The offset in UTF-16 units of the first character after the break. */\n readonly offset: number;\n /** This value is `true` when a line must end here, as at a line feed or at the end of the text. */\n readonly required: boolean;\n}\n\ninterface Table {\n readonly starts: Uint32Array;\n readonly classes: Uint8Array;\n readonly east: Uint32Array;\n}\n\nconst alphabet = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ!#$%&()*+-./:;<=>?@[]^_{|}~\";\nlet table: Table | undefined;\n\n/** This function decodes the runs one time, at the first use, so an import of the entry costs no work. */\nfunction tableOf(): Table {\n if (table !== undefined) return table;\n const runs = [...classRuns.matchAll(/([0-9a-z]+)([^0-9a-z])/gu)];\n const starts = new Uint32Array(runs.length + 1);\n const classes = new Uint8Array(runs.length);\n let start = 0;\n runs.forEach((run, index) => {\n starts[index] = start;\n classes[index] = alphabet.indexOf(run[2]!);\n start += Number.parseInt(run[1]!, 36);\n });\n starts[runs.length] = start;\n const lengths = eastAsianRuns.split(\" \").map((length) => Number.parseInt(length, 36));\n const east = new Uint32Array(lengths.length + 1);\n lengths.forEach((length, index) => {\n east[index + 1] = east[index]! + length;\n });\n table = { starts, classes, east };\n return table;\n}\n\n/** This function gives the index of the last start that is not above `code`. */\nfunction indexOfRun(starts: Uint32Array, code: number): number {\n let low = 0;\n let high = starts.length - 1;\n while (high - low > 1) {\n const middle = (low + high) >>> 1;\n if (starts[middle]! <= code) low = middle;\n else high = middle;\n }\n return low;\n}\n\n/** One base character and its combining marks, as the rule LB9 treats them. */\ninterface Item {\n readonly name: string;\n readonly code: number;\n readonly start: number;\n readonly east: boolean;\n /** This value is `true` when the last code point of the item is U+200D. */\n zwj: boolean;\n}\n\nconst breakClasses = new Set([\"BK\", \"CR\", \"LF\", \"NL\", \"SP\", \"ZW\"]);\n\n/** This function makes the items of a text. It applies the rules LB9 and LB10. */\nfunction itemsOf(text: string): Item[] {\n const { starts, classes, east } = tableOf();\n const items: Item[] = [];\n let offset = 0;\n for (const character of text) {\n const code = character.codePointAt(0)!;\n const name = classNames[classes[indexOfRun(starts, code)]!]!;\n const combining = name === \"CM\" || name === \"ZWJ\";\n const last = items.at(-1);\n if (combining && last !== undefined && !breakClasses.has(last.name)) last.zwj = name === \"ZWJ\";\n else if (combining) items.push({ name: \"AL\", code: 0x41, start: offset, east: false, zwj: name === \"ZWJ\" });\n else items.push({ name, code, start: offset, east: indexOfRun(east, code) % 2 === 1, zwj: false });\n offset += character.length;\n }\n return items;\n}\n\nconst initial = /^\\p{Pi}$/u;\nconst final = /^\\p{Pf}$/u;\nconst pictographic = /^\\p{Extended_Pictographic}$/u;\nconst unassigned = /^\\p{Cn}$/u;\nconst of = (item: Item): string => String.fromCodePoint(item.code);\nconst isPi = (item: Item): boolean => initial.test(of(item));\nconst isPf = (item: Item): boolean => final.test(of(item));\nconst inClass = (item: Item | undefined, names: Set<string>): boolean => item !== undefined && names.has(item.name);\nconst isName = (item: Item | undefined, name: string): boolean => item?.name === name;\n\nconst beforeOpening = new Set([\"BK\", \"CR\", \"LF\", \"NL\", \"OP\", \"QU\", \"GL\", \"SP\", \"ZW\"]);\nconst afterClosing = new Set([\"SP\", \"GL\", \"WJ\", \"CL\", \"QU\", \"CP\", \"EX\", \"IS\", \"SY\", \"BK\", \"CR\", \"LF\", \"NL\", \"ZW\"]);\nconst beforeHyphen = new Set([\"BK\", \"CR\", \"LF\", \"NL\", \"SP\", \"ZW\", \"CB\", \"GL\"]);\nconst alphabetic = new Set([\"AL\", \"HL\"]);\nconst hyphens = new Set([\"HY\", \"HH\"]);\nconst emoji = new Set([\"ID\", \"EB\", \"EM\"]);\nconst prefix = new Set([\"PR\", \"PO\"]);\nconst closing = new Set([\"CL\", \"CP\"]);\nconst separators = new Set([\"SY\", \"IS\"]);\nconst hangul = new Set([\"JL\", \"JV\", \"JT\", \"H2\", \"H3\"]);\nconst aksara = (item: Item | undefined): boolean => item !== undefined && (item.name === \"AK\" || item.name === \"AS\" || item.code === 0x25cc);\nconst aksaraStart = (item: Item | undefined): boolean => item !== undefined && (item.name === \"AK\" || item.code === 0x25cc);\n\n/** This function tells if the items before `index` end with `NU (SY | IS)*`. */\nfunction afterNumber(items: readonly Item[], index: number): boolean {\n let i = index;\n while (i >= 0 && separators.has(items[i]!.name)) i--;\n return isName(items[i], \"NU\");\n}\n\n/** This function applies the rules LB4 to LB31 at the start of the item `i`. It gives 0 for no break, 1 for a break and 2 for a necessary break. */\nfunction ruleAt(items: readonly Item[], i: number): 0 | 1 | 2 {\n const a = items[i - 1]!;\n const b = items[i]!;\n const c = a.name;\n const d = b.name;\n const earlier = items[i - 2];\n const later = items[i + 1];\n if (c === \"BK\" || c === \"NL\" || c === \"LF\") return 2;\n if (c === \"CR\") return d === \"LF\" ? 0 : 2;\n if (d === \"BK\" || d === \"CR\" || d === \"LF\" || d === \"NL\" || d === \"SP\" || d === \"ZW\") return 0;\n let last = i - 1;\n while (last >= 0 && items[last]!.name === \"SP\") last--;\n const beforeSpaces = items[last];\n if (isName(beforeSpaces, \"ZW\")) return 1;\n if (a.zwj) return 0;\n if (d === \"WJ\" || c === \"WJ\" || c === \"GL\") return 0;\n if (d === \"GL\" && c !== \"SP\" && c !== \"BA\" && !hyphens.has(c)) return 0;\n if (d === \"CL\" || d === \"CP\" || d === \"EX\" || d === \"SY\") return 0;\n if (isName(beforeSpaces, \"OP\")) return 0;\n if (beforeSpaces !== undefined && beforeSpaces.name === \"QU\" && isPi(beforeSpaces)) {\n const before = items[last - 1];\n if (before === undefined || beforeOpening.has(before.name)) return 0;\n }\n if (d === \"QU\" && isPf(b) && (later === undefined || afterClosing.has(later.name))) return 0;\n if (c === \"SP\" && d === \"IS\" && isName(later, \"NU\")) return 1;\n if (d === \"IS\") return 0;\n if (d === \"NS\" && inClass(beforeSpaces, closing)) return 0;\n if (d === \"B2\" && isName(beforeSpaces, \"B2\")) return 0;\n if (c === \"SP\") return 1;\n if (d === \"QU\" && !isPi(b)) return 0;\n if (c === \"QU\" && !isPf(a)) return 0;\n if (d === \"QU\" && (!a.east || later === undefined || !later.east)) return 0;\n if (c === \"QU\" && (!b.east || earlier === undefined || !earlier.east)) return 0;\n if (d === \"CB\" || c === \"CB\") return 1;\n if (hyphens.has(c) && alphabetic.has(d) && (earlier === undefined || beforeHyphen.has(earlier.name))) return 0;\n if (d === \"BA\" || d === \"HH\" || d === \"HY\" || d === \"NS\" || c === \"BB\") return 0;\n if (isName(earlier, \"HL\") && hyphens.has(c) && d !== \"HL\") return 0;\n if (c === \"SY\" && d === \"HL\") return 0;\n if (d === \"IN\") return 0;\n if (alphabetic.has(c) && d === \"NU\") return 0;\n if (c === \"NU\" && alphabetic.has(d)) return 0;\n if (c === \"PR\" && emoji.has(d)) return 0;\n if (emoji.has(c) && d === \"PO\") return 0;\n if (prefix.has(c) && alphabetic.has(d)) return 0;\n if (alphabetic.has(c) && prefix.has(d)) return 0;\n if (prefix.has(d) && afterNumber(items, closing.has(c) ? i - 2 : i - 1)) return 0;\n if (d === \"NU\" && afterNumber(items, i - 1)) return 0;\n if (prefix.has(c) && (d === \"NU\" || (d === \"OP\" && (isName(later, \"NU\") || (isName(later, \"IS\") && isName(items[i + 2], \"NU\")))))) return 0;\n if ((c === \"HY\" || c === \"IS\") && d === \"NU\") return 0;\n if (c === \"JL\" && (d === \"JL\" || d === \"JV\" || d === \"H2\" || d === \"H3\")) return 0;\n if ((c === \"JV\" || c === \"H2\") && (d === \"JV\" || d === \"JT\")) return 0;\n if ((c === \"JT\" || c === \"H3\") && d === \"JT\") return 0;\n if (hangul.has(c) && d === \"PO\") return 0;\n if (c === \"PR\" && hangul.has(d)) return 0;\n if (alphabetic.has(c) && alphabetic.has(d)) return 0;\n if (c === \"AP\" && aksara(b)) return 0;\n if (aksara(a) && (d === \"VF\" || d === \"VI\")) return 0;\n if (c === \"VI\" && aksara(earlier) && aksaraStart(b)) return 0;\n if (aksara(a) && aksara(b) && isName(later, \"VF\")) return 0;\n if (c === \"IS\" && alphabetic.has(d)) return 0;\n if ((alphabetic.has(c) || c === \"NU\") && d === \"OP\" && !b.east) return 0;\n if (c === \"CP\" && !a.east && (alphabetic.has(d) || d === \"NU\")) return 0;\n if (c === \"RI\" && d === \"RI\") {\n let count = 0;\n for (let k = i - 1; k >= 0 && items[k]!.name === \"RI\"; k--) count++;\n if (count % 2 === 1) return 0;\n }\n if (d === \"EM\" && (c === \"EB\" || (pictographic.test(of(a)) && unassigned.test(of(a))))) return 0;\n return 1;\n}\n\n/**\n * This function gives the places where a line of a text can end, by the rules of UAX #14 without tailoring. The last place is\n * the end of the text, and an empty text has no place.\n */\nexport function lineBreaks(text: string): readonly LineBreak[] {\n const items = itemsOf(text);\n const breaks: LineBreak[] = [];\n for (let i = 1; i < items.length; i++) {\n const rule = ruleAt(items, i);\n if (rule !== 0) breaks.push({ offset: items[i]!.start, required: rule === 2 });\n }\n if (text.length > 0) breaks.push({ offset: text.length, required: true });\n return breaks;\n}\n","/**\n * The segments of UAX #29, from `Intl.Segmenter`. The results follow the Unicode version of the runtime. The locale is the root\n * locale, so the language of the host has no effect.\n */\nconst graphemeSegmenter = new Intl.Segmenter(\"und\", { granularity: \"grapheme\" });\nconst wordSegmenter = new Intl.Segmenter(\"und\", { granularity: \"word\" });\n\n/** This function gives the grapheme clusters of a text, in their order. */\nexport function graphemes(text: string): readonly string[] {\n return Array.from(graphemeSegmenter.segment(text), (part) => part.segment);\n}\n\n/** This function gives the offset in UTF-16 units of each word boundary of a text, with the end of the text and without its start. */\nexport function wordBreaks(text: string): readonly number[] {\n const offsets = Array.from(wordSegmenter.segment(text), (part) => part.index).slice(1);\n if (text.length > 0) offsets.push(text.length);\n return offsets;\n}\n"],"mappings":";AACA,MAAa,iBAAiB;AAC9B,MAAa,aAAgC,uIAAuI,MAAM,GAAG;AAC7L,MAAa,YAAY;AACzB,MAAa,gBAAgB;;;;;;ACgB7B,MAAM,WAAW;AACjB,IAAI;;AAGJ,SAAS,UAAiB;CACxB,IAAI,UAAU,KAAA,GAAW,OAAO;CAChC,MAAM,OAAO,CAAC,GAAG,UAAU,SAAS,0BAA0B,CAAC;CAC/D,MAAM,SAAS,IAAI,YAAY,KAAK,SAAS,CAAC;CAC9C,MAAM,UAAU,IAAI,WAAW,KAAK,MAAM;CAC1C,IAAI,QAAQ;CACZ,KAAK,SAAS,KAAK,UAAU;EAC3B,OAAO,SAAS;EAChB,QAAQ,SAAS,SAAS,QAAQ,IAAI,EAAG;EACzC,SAAS,OAAO,SAAS,IAAI,IAAK,EAAE;CACtC,CAAC;CACD,OAAO,KAAK,UAAU;CACtB,MAAM,UAAU,cAAc,MAAM,GAAG,CAAC,CAAC,KAAK,WAAW,OAAO,SAAS,QAAQ,EAAE,CAAC;CACpF,MAAM,OAAO,IAAI,YAAY,QAAQ,SAAS,CAAC;CAC/C,QAAQ,SAAS,QAAQ,UAAU;EACjC,KAAK,QAAQ,KAAK,KAAK,SAAU;CACnC,CAAC;CACD,QAAQ;EAAE;EAAQ;EAAS;CAAK;CAChC,OAAO;AACT;;AAGA,SAAS,WAAW,QAAqB,MAAsB;CAC7D,IAAI,MAAM;CACV,IAAI,OAAO,OAAO,SAAS;CAC3B,OAAO,OAA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,WAAW,KAAK,GAAG,CAAC,CAAC,IAAK,OAAO;CAC/F,OAAO;AACT;;;;;AAMA,SAAgB,WAAW,MAAoC;CAC7D,MAAM,QAAQ,QAAQ,IAAI;CAC1B,MAAM,SAAsB,CAAC;CAC7B,KAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;EACrC,MAAM,OAAO,OAAO,OAAO,CAAC;EAC5B,IAAI,SAAS,GAAG,OAAO,KAAK;GAAE,QAAQ,MAAM,EAAE,CAAE;GAAO,UAAU,SAAS;EAAE,CAAC;CAC/E;CACA,IAAI,KAAK,SAAS,GAAG,OAAO,KAAK;EAAE,QAAQ,KAAK;EAAQ,UAAU;CAAK,CAAC;CACxE,OAAO;AACT;;;;;;ACtMA,MAAM,oBAAoB,IAAI,KAAK,UAAU,OAAO,EAAE,aAAa,WAAW,CAAC;AAC/E,MAAM,gBAAgB,IAAI,KAAK,UAAU,OAAO,EAAE,aAAa,OAAO,CAAC;;AAGvE,SAAgB,UAAU,MAAiC;CACzD,OAAO,MAAM,KAAK,kBAAkB,QAAQ,IAAI,IAAI,SAAS,KAAK,OAAO;AAC3E;;AAGA,SAAgB,WAAW,MAAiC;CAC1D,MAAM,UAAU,MAAM,KAAK,cAAc,QAAQ,IAAI,IAAI,SAAS,KAAK,KAAK,CAAC,CAAC,MAAM,CAAC;CACrF,IAAI,KAAK,SAAS,GAAG,QAAQ,KAAK,KAAK,MAAM;CAC7C,OAAO;AACT"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@mark1russell7/typeset",
|
|
4
|
-
"version": "0.1.
|
|
5
|
-
"description": "Text measurement and line breaking. The subpath ./fonts reads font tables and gives widths, ./measurer gives the advance function of a layout, ./breaking has the line breakers, and ./text has a rope.",
|
|
4
|
+
"version": "0.1.6",
|
|
5
|
+
"description": "Text measurement and line breaking. The subpath ./fonts reads font tables and gives widths, ./measurer gives the advance function of a layout, ./breaking has the line breakers, ./segmentation has the break positions of Unicode, and ./text has a rope.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"typeset",
|
|
8
8
|
"line-breaking",
|
|
@@ -46,6 +46,10 @@
|
|
|
46
46
|
"types": "./build/measurer.d.ts",
|
|
47
47
|
"default": "./build/measurer.js"
|
|
48
48
|
},
|
|
49
|
+
"./segmentation": {
|
|
50
|
+
"types": "./build/segmentation.d.ts",
|
|
51
|
+
"default": "./build/segmentation.js"
|
|
52
|
+
},
|
|
49
53
|
"./text": {
|
|
50
54
|
"types": "./build/text.d.ts",
|
|
51
55
|
"default": "./build/text.js"
|
|
@@ -69,7 +73,7 @@
|
|
|
69
73
|
},
|
|
70
74
|
"devDependencies": {
|
|
71
75
|
"@mark1russell7/cue": "^2.0.0",
|
|
72
|
-
"@mark1russell7/layout-contract": "^0.3
|
|
76
|
+
"@mark1russell7/layout-contract": "^0.5.3",
|
|
73
77
|
"@types/node": "^26.6.5",
|
|
74
78
|
"@typeset/corpus": "0.1.0",
|
|
75
79
|
"tsdown": "^0.23.1",
|