@cardenelabs/dragon 0.42.1 → 0.42.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cardenelabs/dragon",
3
- "version": "0.42.1",
3
+ "version": "0.42.2",
4
4
  "description": "Dragon — 動く図を、人は行ごとの記法で、AI は JSON で書く。時系列図と構成図を段ごとに動かし、mp4・GIF・HTML・PNG に書き出す。",
5
5
  "license": "MIT",
6
6
  "author": "cardene777",
@@ -7,6 +7,9 @@
7
7
  *
8
8
  * 形を 1 つも持たない字の file を Chromium は読まない。空白の類だけを描く file には、
9
9
  * 同じ file の形のある字を 1 つ足して削る。足した字は `unicode-range` に載せないので描かれない (#3212)。
10
+ *
11
+ * 範囲の重なる字 (`Noto Sans JP` の英字は番号付きの file と `latin` の両方に入る) は、字の表で後に並ぶ 1 つの file にだけ入れる。
12
+ * 範囲が重なる時は後に宣言した `@font-face` が勝つので、前の file に埋めた字は描かれず、大きさだけを取っていた (#3213)。
10
13
  */
11
14
  import { readFileSync } from "node:fs";
12
15
  import { readFile } from "node:fs/promises";
@@ -42,6 +45,12 @@ function ranges(list: string): [number, number][] {
42
45
 
43
46
  const hex = (code: number): string => `U+${code.toString(16).toUpperCase()}`;
44
47
 
48
+ /** 字が範囲の一覧のどれかに入るか */
49
+ function within(span: [number, number][], char: string): boolean {
50
+ const code = char.codePointAt(0) ?? -1;
51
+ return span.some(([from, to]) => code >= from && code <= to);
52
+ }
53
+
45
54
  /** 形を持たない字 (空白の類、書式の字、制御の字) か */
46
55
  const shapeless = (char: string): boolean => /^[\s\p{Cf}\p{Cc}]$/u.test(char);
47
56
 
@@ -67,12 +76,10 @@ export async function fontFaces(chars: string[]): Promise<string> {
67
76
  PACKAGES.flatMap(({ family, name }) => {
68
77
  const base = dirname(require_.resolve(`@fontsource-variable/${name}/unicode.json`));
69
78
  const table = JSON.parse(readFileSync(join(base, "unicode.json"), "utf8")) as Record<string, string>;
70
- return Object.entries(table).map(async ([key, list]) => {
71
- const span = ranges(list);
72
- const own = chars.filter((char) => {
73
- const code = char.codePointAt(0) ?? -1;
74
- return span.some(([from, to]) => code >= from && code <= to);
75
- });
79
+ const spans = Object.entries(table).map(([key, list]) => ({ key, span: ranges(list) }));
80
+ return spans.map(async ({ key, span }, index) => {
81
+ // 後に並ぶ file の範囲にも入る字は、そちらにだけ入れる
82
+ const own = chars.filter((char) => within(span, char) && !spans.slice(index + 1).some((later) => within(later.span, char)));
76
83
  if (!own.length) return "";
77
84
  const filler = own.every(shapeless) ? (shapedIn(span) ?? "") : "";
78
85
  const file = join(base, "files", `${name}-${key.replace(/[[\]]/g, "")}-wght-normal.woff2`);