'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); const _default = require('./chunks/default.cjs'); class IndexSet { constructor(value = 0) { this.value = value; } set(index) { const i = 1 << index; this.value |= i; } get(index) { const i = 1 << index; return (this.value & i) !== 0; } merge(s) { this.value = this.value === 1 ? s.value : this.value |= s.value; } traverse(p) { let v = this.value; for (let i = 0; i < 7; i++) { if ((v & 1) === 1 && !p(i)) return false; else if (v === 0) return true; v >>= 1; } return true; } forEach(c) { let v = this.value; for (let i = 0; i < 7; i++) { if ((v & 1) === 1) c(i); else if (v === 0) return; v >>= 1; } } offset(i) { this.value <<= i; } toString() { let str = ""; this.traverse((i) => { str += i; str += ", "; return true; }); if (str.length !== 0) return str.slice(0, -2); else return "0"; } isEmpty() { return this.value === 0; } copy() { return new IndexSet(this.value); } } const NONE$1 = new IndexSet(0); const ZERO = new IndexSet(1); const ONE = new IndexSet(2); class IndexSetStorage { constructor() { this.data = new Uint16Array(16); } set(is, index) { if (index >= this.data.length) { let size = index; size |= size >> 1; size |= size >> 2; size |= size >> 4; size |= size >> 8; size |= size >> 16; const replace = new Uint16Array(size + 1); for (let i = 0; i < this.data.length; i++) replace[i] = this.data[i]; this.data = replace; } this.data[index] = is.value + 1; } get(index) { if (index >= this.data.length) return; const ret = this.data[index]; if (ret === 0) return; return new IndexSet(ret - 1); } } function hasInitialPinyin(s) { return !["a", "e", "i", "o", "u", "v"].includes(s.charAt(0)); } class Pinyin { constructor(str, pinin, id) { this.duo = false; this.raw = str; this.id = id; this.reload(str, pinin); } reload(str, pinin) { const split = pinin.config.keyboard.split(str); const l = []; for (const s of split) l.push(pinin.phonemes.get(s)); this.phonemes = l; this.duo = pinin.config.keyboard.duo; } match(str, start, partial) { if (this.duo) { let ret = ZERO; ret = this.phonemes[0].matchBatch(str, ret, start, partial); ret = this.phonemes[1].matchBatch(str, ret, start, partial); ret.merge(this.phonemes[2].matchBatch(str, ret, start, partial)); return ret; } else { let active = ZERO; const ret = new IndexSet(); for (const phoneme of this.phonemes) { active = phoneme.matchBatch(str, active, start, partial); if (active.isEmpty()) break; ret.merge(active); } return ret; } } toString() { return this.raw; } } const DAQIAN_KEYS = { "": "", "0": "", "1": " ", "2": "6", "3": "3", "4": "4", "a": "8", "ai": "9", "an": "0", "ang": ";", "ao": "l", "b": "1", "c": "h", "ch": "t", "d": "2", "e": "k", "ei": "o", "en": "p", "eng": "/", "er": "-", "f": "z", "g": "e", "h": "c", "i": "u", "ia": "u8", "ian": "u0", "iang": "u;", "iao": "ul", "ie": "u,", "in": "up", "ing": "u/", "iong": "m/", "iu": "u.", "j": "r", "k": "d", "l": "x", "m": "a", "n": "s", "o": "i", "ong": "j/", "ou": ".", "p": "q", "q": "f", "r": "b", "s": "n", "sh": "g", "t": "w", "u": "j", "ua": "j8", "uai": "j9", "uan": "j0", "uang": "j;", "uen": "mp", "ueng": "j/", "ui": "jo", "un": "jp", "uo": "ji", "v": "m", "van": "m0", "vang": "m;", "ve": "m,", "vn": "mp", "w": "j", "x": "v", "y": "u", "z": "y", "zh": "5" }; const XIAOHE_KEYS = { ai: "d", an: "j", ang: "h", ao: "c", ch: "i", ei: "w", en: "f", eng: "g", ia: "x", ian: "m", iang: "l", iao: "n", ie: "p", in: "b", ing: "k", iong: "s", iu: "q", ong: "s", ou: "z", sh: "u", ua: "x", uai: "k", uan: "r", uang: "l", ui: "v", un: "y", uo: "o", ve: "t", ue: "t", vn: "y", zh: "v" }; const ZIRANMA_KEYS = { ai: "l", an: "j", ang: "h", ao: "k", ch: "i", ei: "z", en: "f", eng: "g", ia: "w", ian: "m", iang: "d", iao: "c", ie: "x", in: "n", ing: "y", iong: "s", iu: "q", ong: "s", ou: "b", sh: "u", ua: "w", uai: "y", uan: "r", uang: "d", ui: "v", un: "p", uo: "o", ve: "t", ue: "t", vn: "p", zh: "v" }; const PHONETIC_LOCAL = { yi: "i", you: "iu", yin: "in", ye: "ie", ying: "ing", wu: "u", wen: "un", yu: "v", yue: "ve", yuan: "van", yun: "vn", ju: "jv", jue: "jve", juan: "jvan", jun: "jvn", qu: "qv", que: "qve", quan: "qvan", qun: "qvn", xu: "xv", xue: "xve", xuan: "xvan", xun: "xvn", shi: "sh", si: "s", chi: "ch", ci: "c", zhi: "zh", zi: "z", ri: "r" }; function keyboardCutterStandard(str) { const ret = []; let cursor = 0; if (hasInitialPinyin(str)) { cursor = str.length > 2 && str.charAt(1) === "h" ? 2 : 1; ret.push(str.slice(0, cursor)); } if (str.length !== cursor + 1) ret.push(str.slice(cursor, str.length - 1)); ret.push(str.slice(str.length - 1)); return ret; } function keyboardCutterZero(str) { const ss = keyboardCutterStandard(str); if (ss.length === 2) { const finale = ss[0]; ss[0] = finale.charAt(0); ss.push(finale.length === 2 ? finale.charAt(1) : finale); } return ss; } class Keyboard { constructor(type, options) { this.type = type; this.local = options.local; this.keys = options.keys; this.cutter = options.cutter; this.duo = options.duo; } getStrKeys(str) { return this.keys?.[str] || str; } split(str) { if (this.local) { const cut = str.slice(0, -1); const alt = this.local[cut]; if (alt) str = alt + str.charAt(str.length - 1); } return this.cutter(str); } } function createQuanPinKeyboard() { return new Keyboard("QUANPIN", { cutter: keyboardCutterStandard, duo: false }); } function createDaQianKeyboard() { return new Keyboard("DADIAN", { local: PHONETIC_LOCAL, keys: DAQIAN_KEYS, cutter: keyboardCutterStandard, duo: false }); } function createXiaoHeKeyboard() { return new Keyboard("XIAOHE", { keys: XIAOHE_KEYS, cutter: keyboardCutterZero, duo: true }); } function createZiRanMaKeyboard() { return new Keyboard("ZIRANMA", { keys: ZIRANMA_KEYS, cutter: keyboardCutterZero, duo: true }); } function resolveConfig(raw) { const fuzzy = []; if (raw.fuzzy) { const replaces = /* @__PURE__ */ new Set(); for (const str of raw.fuzzy) { const bi = str.split("|"); if (bi.length > 1) { for (const b of bi) { for (const a of bi) { if (a !== b) replaces.add(`${a}-${b}`); } } } else { const rep = str.split(">"); if (rep.length !== 2 || rep[0] === rep[1]) continue; replaces.add(`${rep[0]}-${rep[1]}`); } } for (const str of replaces) { const [from, to] = str.split("-"); fuzzy.push([from, to]); } } return { dict: new Map(Object.entries(raw.dict).map(([k, v]) => [k.charCodeAt(0), v])), keyboard: raw.keyboard || createQuanPinKeyboard(), fuzzy, accelerate: !!raw.accelerate }; } class Cache { constructor(generator) { this.data = /* @__PURE__ */ new Map(); this.generator = generator; } get(key) { let ret = this.data.get(key); if (ret === void 0) { ret = this.generator(key); if (ret !== void 0) this.data.set(key, ret); } return ret; } [Symbol.iterator]() { return this.data[Symbol.iterator](); } forEach(callbackfn, thisArg) { this.data.forEach(callbackfn, thisArg); } clear() { this.data.clear(); } } function strCmp(a, b, aStart) { const len = Math.min(a.length - aStart, b.length); for (let i = 0; i < len; i++) { if (a.charAt(i + aStart) !== b.charAt(i)) return i; } return len; } class Phoneme { reload(str, config) { const ret = /* @__PURE__ */ new Set(); ret.add(str); for (const [from, to] of config.fuzzy) { if (!str.includes(from)) continue; ret.add(str.replace(from, to)); } this.strs = Array.from(ret).map((k) => config.keyboard.keys?.[k] || k); } constructor(str, config) { this.reload(str, config); } matchBatch(source, idx, start, partial) { if (this.strs.length === 1 && this.strs[0].length === 0) return new IndexSet(idx.value); const ret = new IndexSet(); idx.forEach((i) => { const is = this.match(source, start + i, partial); is.offset(i); ret.merge(is); }); return ret; } match(source, start, partial) { const ret = new IndexSet(); if (this.strs.length === 1 && this.strs[0].length === 0) return ret; for (const str of this.strs) { const size = strCmp(source, str, start); if (partial && start + size === source.length) ret.set(size); else if (size === str.length) ret.set(size); } return ret; } } class Char { constructor(ch, pinyins) { this.ch = ch; this.pinyins = pinyins; } match(str, start, partial) { const ret = (str.charCodeAt(start) === this.ch ? ONE : NONE$1).copy(); for (const p of this.pinyins) ret.merge(p.match(str, start, partial)); return ret; } } new Char(0, []); class AccelerateProviderString { constructor() { this.s = ""; } end(i) { return i >= this.s.length; } get(i) { return this.s.charCodeAt(i); } } class Accelerator { constructor(context) { this.cache = []; this.str = new AccelerateProviderString(); this.partial = false; this.context = context; } search(s) { if (s !== this.searchStr) { this.searchStr = s; this.searchChars = [...s].map((c) => c.charCodeAt(0)); this.reset(); } } getByChar(ch, offset) { const c = this.context.getChar(ch); const ret = new IndexSet(this.searchChars[offset] === c.ch ? 2 : 0); for (const p of c.pinyins) ret.merge(this.getByPinyin(p, offset)); return ret; } getByPinyin(p, offset) { for (let i = this.cache.length; i <= offset; i++) this.cache.push(new IndexSetStorage()); const data = this.cache[offset]; const ret = data.get(p.id); if (ret === void 0) { const ret2 = p.match(this.searchStr, offset, this.partial); data.set(ret2, p.id); return ret2; } else { return ret; } } setProvider(p) { this.provider = p; } setStringProvider(s) { this.str.s = s; this.provider = this.str; } reset() { this.cache = []; } check(offset, start) { if (offset === this.searchStr.length) return this.partial || this.provider.end(start); if (this.provider.end(start)) return false; const s = this.getByChar(this.provider.get(start), offset); if (this.provider.end(start + 1)) { const i = this.searchStr.length - offset; return s.get(i); } else { return !s.traverse((i) => !this.check(offset + i, start + 1)); } } matches(offset, start) { if (this.partial) { this.partial = false; this.reset(); } return this.check(offset, start); } begins(offset, start) { if (!this.partial) { this.partial = true; this.reset(); } return this.check(offset, start); } contains(offset, start) { if (!this.partial) { this.partial = true; this.reset(); } for (let i = start; !this.provider.end(i); i++) { if (this.check(offset, i)) return true; } return false; } common(s1, s2, max) { for (let i = 0; ; i++) { if (i >= max) return max; const a = this.provider.get(s1 + i); const b = this.provider.get(s2 + i); if (a !== b || a === 0) return i; } } } class Compressor { constructor() { this.chars = []; this.strs = []; } offsets() { return this.strs; } put(s) { this.strs.push(this.chars.length); for (let i = 0; i < s.length; i++) this.chars.push(s.charCodeAt(i)); this.chars.push(0); return this.strs[this.strs.length - 1]; } end(i) { return this.chars[i] === 0; } get(i) { return this.chars[i]; } } class SimpleSearcher { constructor(logic, context) { this.objs = []; this.context = context; this.logic = logic; this.acc = new Accelerator(context); this.strs = new Compressor(); this.acc.setProvider(this.strs); this.ticket = context.ticket(this.reset.bind(this)); } put(name, identifier) { this.strs.put(name); for (let i = 0; i < name.length; i++) this.context.getChar(name.charCodeAt(i)); this.objs.push(identifier); } search(name) { const ret = /* @__PURE__ */ new Set(); this.acc.search(name); const offsets = this.strs.offsets(); for (let i = 0; i < offsets.length; i++) { const s = offsets[i]; if (this.logic.testAcc(this.acc, 0, s)) ret.add(this.objs[i]); } return [...ret]; } reset() { this.acc.reset(); } } class Stats { constructor() { this.data = /* @__PURE__ */ new Map(); } count(key) { const cnt = this.data.get(key) || 0; this.data.set(key, cnt + 1); if (cnt === Number.MAX_SAFE_INTEGER) this.data.forEach((v, k) => this.data.set(k, v / 2)); } least(keys, extra) { let ret = extra; let cnt = this.data.get(extra) || 0; for (const i of keys) { const value = this.data.get(i) || 0; if (value < cnt) { ret = i; cnt = value; } } return ret; } reset() { this.data.clear(); } } class CachedSearcher extends SimpleSearcher { constructor(logic, context, scale = 1) { super(logic, context); this.all = []; this.lenCached = 0; this.maxCached = 0; this.total = 0; this.stats = new Stats(); this.cache = /* @__PURE__ */ new Map(); this.scale = scale; } put(name, identifier) { this.reset(); for (let i = 0; i < name.length; i++) this.context.getChar(name.charCodeAt(i)); this.total += name.length; this.all.push(this.all.length); this.lenCached = 0; this.maxCached = 0; super.put(name, identifier); } search(name) { this.ticket.renew(); if (this.all.length === 0) return []; if (this.maxCached === 0) { const totalSearch = this.logic === SearchLogicContain ? this.total : this.all.length; this.maxCached = Math.ceil(this.scale * Math.log(2 * totalSearch) / Math.log(2) + 16); } if (this.lenCached === 0) this.lenCached = Math.ceil(Math.log(this.maxCached) / Math.log(8)); return this.test(name).map((i) => this.objs[i]); } reset() { super.reset(); this.stats.reset(); this.lenCached = 0; this.maxCached = 0; } filter(name) { if (!name) return this.all; let ret = this.cache.get(name); this.stats.count(name); if (ret === void 0) { const base = this.filter(name.slice(0, -1)); if (this.cache.size >= this.maxCached) { const least = this.stats.least([...this.cache.keys()], name); if (least !== name) this.cache.delete(least); else return base; } this.acc.search(name); const tmp = []; const filter = this.logic === SearchLogicEqual ? SearchLogicBegin : this.logic; for (const i of base) { if (filter.testAcc(this.acc, 0, this.strs.offsets()[i])) tmp.push(i); } if (tmp.length === base.length) ret = base; else ret = tmp; this.cache.set(name, ret); } return ret; } test(name) { const is = this.filter(name.slice(0, Math.min(name.length, this.lenCached))); if (this.logic === SearchLogicEqual || name.length > this.lenCached) { const ret = []; this.acc.search(name); for (const i of is) { if (this.logic.testAcc(this.acc, 0, this.strs.offsets()[i])) ret.push(i); } return ret; } else { return is; } } } const THRESHOLD = 128; class NSlice { constructor(start, end) { this.exit = new NMap(); this.start = start; this.end = end; } get(p, ret, offset) { if (offset === void 0) this.exit.get(p, ret); else this.getWithStart(p, ret, offset, 0); } put(p, name, identifier) { const length = this.end - this.start; const match = p.acc.common(this.start, name, length); if (match >= length) { this.exit = this.exit.put(p, name + length, identifier); } else { this.cut(p, this.start + match); this.exit = this.exit.put(p, name + match, identifier); } return this.start === this.end ? this.exit : this; } cut(p, offset) { const insert = new NMap(); if (offset + 1 === this.end) { insert.setChild(p.strs.get(offset), this.exit); } else { const half = new NSlice(offset + 1, this.end); half.exit = this.exit; insert.setChild(p.strs.get(offset), half); } this.exit = insert; this.end = offset; } getWithStart(p, ret, offset, start) { if (this.start + start === this.end) { this.exit.get(p, ret, offset); } else if (offset === p.acc.searchStr.length) { if (p.logic !== SearchLogicEqual) this.exit.get(p, ret); } else { const ch = p.strs.get(this.start + start); p.acc.getByChar(ch, offset).forEach((i) => this.getWithStart(p, ret, offset + i, start + 1)); } } } class NDense { constructor() { this.data = []; } get(p, ret, offset) { if (offset === void 0) { for (let i = 0; i < this.data.length / 2; i++) ret.add(this.data[i * 2 + 1]); return; } const full = p.logic === SearchLogicEqual; if (!full && p.acc.searchStr.length === offset) { this.get(p, ret); } else { for (let i = 0; i < this.data.length / 2; i++) { const ch = this.data[i * 2]; if (full ? p.acc.matches(offset, ch) : p.acc.begins(offset, ch)) ret.add(this.data[i * 2 + 1]); } } } put(p, name, identifier) { if (this.data.length >= THRESHOLD) { const pattern = this.data[0]; const ret = new NSlice(pattern, pattern + this.match(p)); for (let j = 0; j < this.data.length / 2; j++) ret.put(p, this.data[j * 2], this.data[j * 2 + 1]); ret.put(p, name, identifier); return ret; } else { this.data.push(name); this.data.push(identifier); return this; } } match(p) { for (let i = 0; ; i++) { const a = p.strs.get(this.data[0] + i); for (let j = 1; j < this.data.length / 2; j++) { const b = p.strs.get(this.data[j * 2] + i); if (a !== b || a === 0) return i; } } } } class NMap { constructor() { this.leaves = /* @__PURE__ */ new Set(); } get(p, ret, offset) { if (offset === void 0) { for (const i of this.leaves) ret.add(i); if (this.children !== void 0) this.children.forEach((n) => n.get(p, ret)); return; } if (p.acc.searchStr.length === offset) { if (p.logic === SearchLogicEqual) for (const i of this.leaves) ret.add(i); else this.get(p, ret); } else if (this.children !== void 0) { this.children.forEach((n, c) => p.acc.getByChar(c, offset).forEach((i) => n.get(p, ret, offset + i))); } } put(p, name, identifier) { if (p.strs.get(name) === 0) { this.leaves.add(identifier); } else { this.init(); const ch = p.strs.get(name); let sub = this.children.get(ch); if (sub === void 0) this.children.set(ch, sub = new NDense()); sub = sub.put(p, name + 1, identifier); this.children.set(ch, sub); } return !(this instanceof NAcc) && this.children && this.children.size > 32 ? new NAcc(p, this) : this; } setChild(ch, n) { this.init(); this.children.set(ch, n); } init() { if (this.children === void 0) this.children = /* @__PURE__ */ new Map(); } } class NAcc extends NMap { constructor(p, n) { super(); this.index = /* @__PURE__ */ new Map(); this.children = n.children; this.leaves = n.leaves; this.reload(p); p.naccs.push(this); } get(p, ret, offset) { if (offset === void 0) return super.get(p, ret); if (p.acc.searchStr.length === offset) { if (p.logic === SearchLogicEqual) for (const i of this.leaves) ret.add(i); else super.get(p, ret); } else { const ch = p.acc.searchStr.charCodeAt(offset); const n = this.children.get(ch); if (n !== void 0) n.get(p, ret, offset + 1); for (const [k, v] of this.index) { if (!k.match(p.acc.searchStr, offset, true).isEmpty()) { for (const i of v) { p.acc.getByChar(i, offset).forEach((j) => this.children.get(i).get(p, ret, offset + j)); } } } } } put(p, name, identifier) { super.put(p, name, identifier); this.indexChar(p, p.strs.get(name)); return this; } reload(p) { this.index.clear(); this.children.forEach((n, c) => this.indexChar(p, c)); } indexChar(p, c) { const ch = p.context.getChar(c); for (const py of ch.pinyins) { const key = py.phonemes[0]; const value = this.index.get(key) ?? /* @__PURE__ */ new Set(); value.add(c); this.index.set(key, value); } } } class TreeSearcher { constructor(logic, context) { this.root = new NDense(); this.objects = []; this.naccs = []; this.strs = new Compressor(); this.logic = logic; this.context = context; this.acc = new Accelerator(context); this.acc.setProvider(this.strs); this.ticket = context.ticket(() => { this.naccs.forEach((i) => i.reload(this)); this.acc.reset(); }); } put(name, identifier) { this.ticket.renew(); const pos = this.strs.put(name); const end = this.logic === SearchLogicEqual ? name.length : 1; for (let i = 0; i < end; i++) this.root = this.root.put(this, pos + i, this.objects.length); this.objects.push(identifier); } search(s) { this.ticket.renew(); this.acc.search(s); const ret = /* @__PURE__ */ new Set(); this.root.get(this, ret, 0); return [...ret].map((i) => this.objects[i]); } refresh() { this.ticket.renew(); } } const SearchLogicBegin = { testAcc: (a, offset, start) => a.begins(offset, start), test: (p, s1, s2) => p.begins(s1, s2), raw: (s1, s2) => s1.startsWith(s2) }; const SearchLogicContain = { testAcc: (a, offset, start) => a.contains(offset, start), test: (p, s1, s2) => p.contains(s1, s2), raw: (s1, s2) => s1.includes(s2) }; const SearchLogicEqual = { testAcc: (a, offset, start) => a.matches(offset, start), test: (p, s1, s2) => p.matches(s1, s2), raw: (s1, s2) => s1 === s2 }; const OFFSET = ["ui", "iu", "uan", "uang", "ian", "iang", "ua", "ie", "uo", "iong", "iao", "ve", "ia"]; const NONE = { a: "a", o: "o", e: "e", i: "i", u: "u", v: "\xFC" }; const FIRST = { a: "\u0101", o: "\u014D", e: "\u0113", i: "\u012B", u: "\u016B", v: "\u01D6" }; const SECOND = { a: "\xE1", o: "\xF3", e: "\xE9", i: "\xED", u: "\xFA", v: "\u01D8" }; const THIRD = { a: "\u01CE", o: "\u01D2", e: "\u011B", i: "\u01D0", u: "\u01D4", v: "\u01DA" }; const FOURTH = { a: "\xE0", o: "\xF2", e: "\xE8", i: "\xEC", u: "\xF9", v: "\u01DC" }; const TONES = [NONE, FIRST, SECOND, THIRD, FOURTH]; const SYMBOLS = { "a": "\u311A", "o": "\u311B", "e": "\u311C", "er": "\u3126", "ai": "\u311E", "ei": "\u311F", "ao": "\u3120", "ou": "\u3121", "an": "\u3122", "en": "\u3123", "ang": "\u3124", "eng": "\u3125", "ong": "\u3128\u3125", "i": "\u3127", "ia": "\u3127\u311A", "iao": "\u3127\u3120", "ie": "\u3127\u311D", "iu": "\u3127\u3121", "ian": "\u3127\u3122", "in": "\u3127\u3123", "iang": "\u3127\u3124", "ing": "\u3127\u3125", "iong": "\u3129\u3125", "u": "\u3128", "ua": "\u3128\u311A", "uo": "\u3128\u311B", "uai": "\u3128\u311E", "ui": "\u3128\u311F", "uan": "\u3128\u3122", "un": "\u3128\u3123", "uang": "\u3128\u3124", "ueng": "\u3128\u3125", "uen": "\u3129\u3123", "v": "\u3129", "ve": "\u3129\u311D", "van": "\u3129\u3122", "vang": "\u3129\u3124", "vn": "\u3129\u3123", "b": "\u3105", "p": "\u3106", "m": "\u3107", "f": "\u3108", "d": "\u3109", "t": "\u310A", "n": "\u310B", "l": "\u310C", "g": "\u310D", "k": "\u310E", "h": "\u310F", "j": "\u3110", "q": "\u3111", "x": "\u3112", "zh": "\u3113", "ch": "\u3114", "sh": "\u3115", "r": "\u3116", "z": "\u3117", "c": "\u3118", "s": "\u3119", "w": "\u3128", "y": "\u3127", "1": "", "2": "\u02CA", "3": "\u02C7", "4": "\u02CB", "0": "\u02D9", "": "" }; const LOCAL = { yi: "i", you: "iu", yin: "in", ye: "ie", ying: "ing", wu: "u", wen: "un", yu: "v", yue: "ve", yuan: "van", yun: "vn", ju: "jv", jue: "jve", juan: "jvan", jun: "jvn", qu: "qv", que: "qve", quan: "qvan", qun: "qvn", xu: "xv", xue: "xve", xuan: "xvan", xun: "xvn", shi: "sh", si: "s", chi: "ch", ci: "c", zhi: "zh", zi: "z", ri: "r" }; function formatPinyinRaw(p) { return p.toString().slice(0, -1); } function formatPinyinNumber(p) { return p.toString(); } function formatPinyinPhonetic(p) { let s = p.toString(); const str = LOCAL[s.slice(0, -1)]; if (str) s = str + s.charAt(s.length - 1); let res = ""; let split; if (!hasInitialPinyin(s)) { split = ["", s.slice(0, -1), s.slice(-1)]; } else { const i = s.length > 2 && s.charAt(1) === "h" ? 2 : 1; split = [s.slice(0, i), s.slice(i, -1), s.slice(-1)]; } const weak = split[2] === "0"; if (weak) res += SYMBOLS[split[2]]; res += SYMBOLS[split[0]]; res += SYMBOLS[split[1]]; if (!weak) res += SYMBOLS[split[2]]; return res; } function formatPinyinUnicode(p) { let res = ""; const s = p.toString(); let finale; if (!hasInitialPinyin(s)) { finale = s.slice(0, -1); } else { const i = s.length > 2 && s.charAt(1) === "h" ? 2 : 1; res += s.slice(0, i); finale = s.slice(i, -1); } const offset = OFFSET.includes(finale) ? 1 : 0; if (offset === 1) res += finale.charAt(0); const group = TONES[s.charCodeAt(s.length - 1) - 48]; res += group[finale.charAt(offset)]; if (finale.length > offset + 1) res += finale.slice(offset + 1); return res; } class PinInTicket { constructor(runnable, context) { this.runnable = runnable; this.modification = context.modification; this.context = context; } renew() { const i = this.context.modification; if (this.modification !== i) { this.modification = i; this.runnable(); } } } class PinIn { constructor(config) { this.totalPinyins = 0; this.phonemes = new Cache((str) => new Phoneme(str, this.config)); this.pinyins = new Cache((str) => new Pinyin(str, this, this.totalPinyins++)); this.chars = /* @__PURE__ */ new Map(); this.modification = 0; this.config = resolveConfig(config); for (const [c, ss] of this.config.dict) { if (!ss) continue; this.chars.set(c, new Char(c, ss.map((s) => this.pinyins.get(s)))); } } begins(s1, s2) { if (s1.length === 0) return s1.startsWith(s2); else return this.check(s1, 0, s2, 0, true); } contains(s1, s2) { if (s1.length === 0) { return s1.includes(s2); } else { for (let i = 0; i < s1.length; i++) { if (this.check(s1, i, s2, 0, true)) return true; } return false; } } matches(s1, s2) { if (s1.length === 0) return s1 === s2; else return this.check(s1, 0, s2, 0, false); } check(s1, start1, s2, start2, partial) { if (start2 === s2.length) { return partial || start1 === s1.length; } else { const r = this.getChar(s1.charCodeAt(start1)); const s = r.match(s2, start2, partial); if (start1 === s1.length - 1) { const i = s2.length - start2; return s.get(i); } else { return !s.traverse((i) => !this.check(s1, start1 + 1, s2, start2 + i, partial)); } } } getChar(c) { return this.chars.get(c) || new Char(c, []); } ticket(runnable) { return new PinInTicket(runnable, this); } } exports.defaultDict = _default.dict; exports.CachedSearcher = CachedSearcher; exports.DAQIAN_KEYS = DAQIAN_KEYS; exports.Keyboard = Keyboard; exports.PHONETIC_LOCAL = PHONETIC_LOCAL; exports.PinInTicket = PinInTicket; exports.SearchLogicBegin = SearchLogicBegin; exports.SearchLogicContain = SearchLogicContain; exports.SearchLogicEqual = SearchLogicEqual; exports.SimpleSearcher = SimpleSearcher; exports.TreeSearcher = TreeSearcher; exports.XIAOHE_KEYS = XIAOHE_KEYS; exports.ZIRANMA_KEYS = ZIRANMA_KEYS; exports.createDaQianKeyboard = createDaQianKeyboard; exports.createQuanPinKeyboard = createQuanPinKeyboard; exports.createXiaoHeKeyboard = createXiaoHeKeyboard; exports.createZiRanMaKeyboard = createZiRanMaKeyboard; exports["default"] = PinIn; exports.formatPinyinNumber = formatPinyinNumber; exports.formatPinyinPhonetic = formatPinyinPhonetic; exports.formatPinyinRaw = formatPinyinRaw; exports.formatPinyinUnicode = formatPinyinUnicode; exports.keyboardCutterStandard = keyboardCutterStandard; exports.keyboardCutterZero = keyboardCutterZero;