From 03bbb76a2c65018409ef82e1548adb4be49cf3cc Mon Sep 17 00:00:00 2001 From: necobot Date: Sat, 25 Jul 2026 23:11:25 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=8E=92=E9=99=A4=E7=A0=B4=E5=9D=8F?= =?UTF-8?q?=E8=A1=8C=E6=A1=86=E7=9A=84=E7=BB=84=E5=90=88=E5=AD=97=E7=AC=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mosaic.test.ts | 12 ++++++++++++ src/mosaic.ts | 7 +------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/mosaic.test.ts b/src/mosaic.test.ts index 82627a6..a4fb6ab 100644 --- a/src/mosaic.test.ts +++ b/src/mosaic.test.ts @@ -98,6 +98,18 @@ describe('generateMosaic', () => { expect(expanded.outputLength).toBe(expanded.inputLength * 10) }) + it('不生成可能跳出正常行框的 Unicode 组合符', () => { + const outputs = Array.from({ length: 20 }, (_, seed) => + generateMosaic(SOURCE, [], { + volume: 1000, + disorder: 100, + seed, + }).output, + ).join('') + + expect(outputs).not.toMatch(/\p{Mark}/u) + }) + it('相同种子可复现,不同种子会重新侵蚀', () => { const candidates = selectKeywords(SOURCE, 14, 1) const first = generateMosaic(SOURCE, candidates, { diff --git a/src/mosaic.ts b/src/mosaic.ts index dcce973..6ceb301 100644 --- a/src/mosaic.ts +++ b/src/mosaic.ts @@ -237,8 +237,6 @@ const ENCODING_FRAGMENTS = ['Ã', 'Â', 'æ', 'å', '¤', '锟', '斤', '拷'] a const COMPLEX_HAN = ['黻', '鬯', '夔', '爨', '龘', '靐', '罅', '黹'] as const -const COMBINING_MARKS = ['\u0336', '\u0337', '\u0338', '\u035F'] as const - const HAN_PATTERN = /\p{Script=Han}/u const WORD_PATTERN = /[\p{L}\p{N}]/u @@ -395,15 +393,12 @@ function generateNoise(length: number, disorder: number, random: Random): string let output = '' let previous = '' const repeatChance = 0.02 + disorder * 0.0015 - const combiningChance = 0.02 + disorder * 0.0011 for (let index = 0; index < length; index += 1) { const shouldRepeat = previous !== '' && random() < repeatChance const glyph = shouldRepeat ? previous : chooseNoiseGlyph(random) - const combining = - random() < combiningChance ? choose(COMBINING_MARKS, random) : '' - output += `${glyph}${combining}` + output += glyph previous = glyph }