egatari 0.6.18 → 0.6.20-rc.1

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.
Files changed (71) hide show
  1. package/CHANGELOG.md +33 -1
  2. package/README.ja.md +7 -2
  3. package/README.md +7 -2
  4. package/components.lock.json +40 -12
  5. package/components2.lock.json +534 -1
  6. package/kit/build.mjs +1 -1
  7. package/kit/check-messages.mjs +4 -0
  8. package/kit/check.mjs +6 -2
  9. package/kit/core/bookmark.mjs +13 -0
  10. package/kit/core/build-core.mjs +1 -1
  11. package/kit/core/check-parity.mjs +2 -0
  12. package/kit/core/check-rules.mjs +1 -1
  13. package/kit/core/check-source.mjs +4 -1
  14. package/kit/core/checks.mjs +79 -0
  15. package/kit/core/find-replace.mjs +170 -0
  16. package/kit/core/format.mjs +4 -1
  17. package/kit/core/image-insert.mjs +197 -0
  18. package/kit/core/image-size.mjs +1 -1
  19. package/kit/core/layout-scan.mjs +1 -1
  20. package/kit/core/llm-fix.mjs +1 -1
  21. package/kit/core/llm-pack-assemble.mjs +17 -10
  22. package/kit/core/llm-pack-data.mjs +94 -30
  23. package/kit/core/llm-pack.mjs +2 -1
  24. package/kit/core/part-labels.mjs +1 -0
  25. package/kit/core/portable.mjs +5 -2
  26. package/kit/core/scorm.mjs +30 -6
  27. package/kit/core/script-unclosed.mjs +66 -0
  28. package/kit/core/slide-ops.mjs +5 -1
  29. package/kit/core/template-text.mjs +2 -0
  30. package/kit/deck.js +71 -4
  31. package/kit/instruction-version.json +1 -1
  32. package/kit/layouts.css +8 -0
  33. package/kit/panes.js +17 -1
  34. package/kit/player.json +1 -1
  35. package/kit/player.lock.json +2 -2
  36. package/kit/templates/new-deck.mjs +1 -1
  37. package/kit/tools.js +136 -4
  38. package/kit/track.js +46 -5
  39. package/package.json +1 -1
  40. package/server/editor-ui.js +21 -1
  41. package/server/script-field.js +1 -1
  42. package/vendor/components/CATALOG.md +5 -4
  43. package/vendor/components/sha256/15306d854d67d52ca2b1d66135f0d3296882e6b21fd85c029399b8077c8a7f9d/README.en.md +34 -0
  44. package/vendor/components/sha256/15306d854d67d52ca2b1d66135f0d3296882e6b21fd85c029399b8077c8a7f9d/index.js +398 -0
  45. package/vendor/components/sha256/277ac772315f93737a094cd0f0842726f2435d352d9a90822aebfe0d5d7e79a1/README.en.md +23 -0
  46. package/vendor/components/sha256/277ac772315f93737a094cd0f0842726f2435d352d9a90822aebfe0d5d7e79a1/index.js +294 -0
  47. package/vendor/components/sha256/3be5f64deb1951327b614b29a9b632878fab362687c76e3f48f3af1d1ebbb1cf/README.en.md +47 -0
  48. package/vendor/components/sha256/3be5f64deb1951327b614b29a9b632878fab362687c76e3f48f3af1d1ebbb1cf/index.js +223 -0
  49. package/vendor/components/sha256/7c7b0373cfd38fd5ecb4169021e0b908f0a17be1a29b14f85dd89fdb92e7bf81/README.en.md +44 -0
  50. package/vendor/components/sha256/7c7b0373cfd38fd5ecb4169021e0b908f0a17be1a29b14f85dd89fdb92e7bf81/index.js +306 -0
  51. package/vendor/components/sha256/8a9215c7fea15265c2f3038f3d01a2f72441fc1e931245dee46dcaacf3548a98/README.en.md +38 -0
  52. package/vendor/components/sha256/8a9215c7fea15265c2f3038f3d01a2f72441fc1e931245dee46dcaacf3548a98/index.js +414 -0
  53. package/vendor/components/sha256/91be5c714c046244436569ecac24d9d1eb84504b3e28d8899fc89a5865e8d955/README.en.md +40 -0
  54. package/vendor/components/sha256/91be5c714c046244436569ecac24d9d1eb84504b3e28d8899fc89a5865e8d955/index.js +355 -0
  55. package/vendor/components/sha256/939bdae590ebed3d182b0c9940a35b6c03872505bfa242341990a81cae02fd06/README.en.md +34 -0
  56. package/vendor/components/sha256/939bdae590ebed3d182b0c9940a35b6c03872505bfa242341990a81cae02fd06/index.js +397 -0
  57. package/vendor/components/sha256/9a426812105a44446e8b3f98e0ccfdb6701e8386c08e8aa201b69cb5b52a4c1f/index.js +278 -0
  58. package/vendor/components/sha256/9c5dd0bc0c3279c5f0fea3fdb9d0735870880aef96e8bbf9ecdd77dff0f5ddc8/README.en.md +44 -0
  59. package/vendor/components/sha256/9c5dd0bc0c3279c5f0fea3fdb9d0735870880aef96e8bbf9ecdd77dff0f5ddc8/index.js +551 -0
  60. package/vendor/components/sha256/a5b032657720d3beb64f0b3699954e13b0eb985f36161b9ae046c83fd6048ff5/README.en.md +18 -0
  61. package/vendor/components/sha256/a5b032657720d3beb64f0b3699954e13b0eb985f36161b9ae046c83fd6048ff5/index.js +382 -0
  62. package/vendor/components/sha256/ad4d42a34eff125d8ccd7caf9ac329b7a8092960e7ee872fdeb853bd9c57942f/README.en.md +54 -0
  63. package/vendor/components/sha256/ad4d42a34eff125d8ccd7caf9ac329b7a8092960e7ee872fdeb853bd9c57942f/index.js +470 -0
  64. package/vendor/components/sha256/b35d01e480a203dc27aa18b0d341cc1cbc2dcca69235e909919484f1545b371f/README.en.md +23 -0
  65. package/vendor/components/sha256/b35d01e480a203dc27aa18b0d341cc1cbc2dcca69235e909919484f1545b371f/index.js +150 -0
  66. package/vendor/components-2/manifest-2.20.0.json +3217 -0
  67. package/vendor/components-2/manifest-2.21.0.json +3220 -0
  68. package/vendor/components-2/manifest-2.22.0.json +3240 -0
  69. package/vendor/egatari-spec/SOURCE.json +2 -2
  70. package/vendor/egatari-spec/schema/deck-meta.schema.json +3 -0
  71. package/vendor/egatari-spec/schema/egatari-metadata.schema.json +6 -0
@@ -0,0 +1,278 @@
1
+ // m-kobun:古文の品詞分解(語をスラッシュで切り、品詞で色を分ける)を 1 文ずつ見せ、最後に現代語訳と並べる
2
+ // <m-kobun style="height:430px">
3
+ // 春[名]/は[係助]/あけぼの[名]。
4
+ // = 春は明け方(がよい)。
5
+ // 紫だち[動・タ四・連用]/たる[助動・たり・存続・連体]/雲[名]/の[格助]/…
6
+ // </m-kobun>
7
+ // 1 行が 1 文(1 段階)。語は / で切り、語の後ろの [ ] に品詞と詳しいこと(・で区切る)を書く。[ ] の後ろの字(、。)は語に付けて出す。
8
+ // 「= …」の行は直前の文の現代語訳(最後の段階で、本文の下(縦書きでは左)に並べる)。{漢字|かな} は振り仮名。
9
+ // 助動詞は [助動・基本形・意味・活用形]:押す(タップする)と、その助動詞の活用表と意味を出す(部品の中の表から。読み込みはしない)。
10
+ // 押して出した札は発表の操作で、画面の決まり (i, k, t) の外:段階を動かす・もう一度押す・札を押す・同じ段階に入り直す(ctx.reset)と消え、動画と印刷には出ない
11
+ // 2.0(Egatari spec §6.1 の部品):base の MotionElement・prog・previewOpacity を使い、プレイヤーのグローバルは使わない。
12
+ // 書き方の誤りは ctx.report("data", "[kobun] …") で知らせる(1.x の console.warn("m-kobun: …") の代わり)。動画かどうかは mount の ctx.mode。
13
+ // 読み取り(parse)と助動詞の表は試験のために static testing に出す(ほかのパーツは読まない)
14
+ egatariParts.define({name: "kobun", version: "2.0.4", requires: {base: "1.3.0"}, element: "m-kobun"}, function(deps){
15
+ "use strict";
16
+ var base = deps.base;
17
+ var D = base;
18
+
19
+ // ---------------------------------------------------------------- 品詞
20
+ // 品詞の頭の字 → [種類, 名前]。色は種類ごと(テーマの変数だけ)
21
+ var POS = [
22
+ ["助動", "aux", "助動詞"], ["格助", "pt", "格助詞"], ["係助", "pt", "係助詞"], ["副助", "pt", "副助詞"], ["接助", "pt", "接続助詞"],
23
+ ["終助", "pt", "終助詞"], ["間助", "pt", "間投助詞"], ["助", "pt", "助詞"], ["形動", "adj", "形容動詞"], ["形", "adj", "形容詞"],
24
+ ["動", "verb", "動詞"], ["補動", "verb", "補助動詞"], ["名", "noun", "名詞"], ["代", "noun", "代名詞"], ["副", "etc", "副詞"],
25
+ ["連体", "etc", "連体詞"], ["接", "etc", "接続詞"], ["感", "etc", "感動詞"], ["接頭", "etc", "接頭語"], ["接尾", "etc", "接尾語"]];
26
+ var COLOR = {noun: "var(--fg)", verb: "var(--term)", adj: "var(--accent2)", aux: "var(--emph)", pt: "var(--muted)", etc: "var(--fg)"};
27
+ // the longest name that starts the tag (接頭 and 接尾 before 接)
28
+ function posOf(tag){ var b = null; for (var i = 0; i < POS.length; i++) if (tag.indexOf(POS[i][0]) === 0 && (!b || POS[i][0].length > b[0].length)) b = POS[i]; return b ? {kind: b[1], name: b[2], short: b[0]} : {kind: "etc", name: tag, short: tag, unknown: true}; }
29
+
30
+ // ---------------------------------------------------------------- 文語の助動詞(活用・接続・意味)
31
+ // 活用は 未然・連用・終止・連体・已然・命令(○ は形がない、( )はまれな形)
32
+ var AUX = {
33
+ "る": {f: "れ れ る るる るれ れよ", type: "下二段型", conn: "未然形(四段・ナ変・ラ変)", mean: "受身・尊敬・自発・可能"},
34
+ "らる": {f: "られ られ らる らるる らるれ られよ", type: "下二段型", conn: "未然形(四段・ナ変・ラ変以外)", mean: "受身・尊敬・自発・可能"},
35
+ "す": {f: "せ せ す する すれ せよ", type: "下二段型", conn: "未然形(四段・ナ変・ラ変)", mean: "使役・尊敬"},
36
+ "さす": {f: "させ させ さす さする さすれ させよ", type: "下二段型", conn: "未然形(四段・ナ変・ラ変以外)", mean: "使役・尊敬"},
37
+ "しむ": {f: "しめ しめ しむ しむる しむれ しめよ", type: "下二段型", conn: "未然形", mean: "使役・尊敬"},
38
+ "ず": {f: "ず・ざら ず・ざり ず ぬ・ざる ね・ざれ ざれ", type: "特殊型", conn: "未然形", mean: "打消"},
39
+ "じ": {f: "○ ○ じ じ じ ○", type: "無変化型", conn: "未然形", mean: "打消推量・打消意志"},
40
+ "む": {f: "(ま) ○ む(ん) む(ん) め ○", type: "四段型", conn: "未然形", mean: "推量・意志・適当・勧誘・仮定・婉曲"},
41
+ "むず": {f: "○ ○ むず むずる むずれ ○", type: "サ変型", conn: "未然形", mean: "推量・意志・適当・勧誘・仮定・婉曲"},
42
+ "まし": {f: "ましか・(ませ) ○ まし まし ましか ○", type: "特殊型", conn: "未然形", mean: "反実仮想・ためらいの意志・推量"},
43
+ "べし": {f: "べから べく・べかり べし べき・べかる べけれ ○", type: "形容詞型(ク活用)", conn: "終止形(ラ変型には連体形)", mean: "推量・意志・可能・当然・命令・適当"},
44
+ "まじ": {f: "まじから まじく・まじかり まじ まじき・まじかる まじけれ ○", type: "形容詞型(シク活用)", conn: "終止形(ラ変型には連体形)", mean: "打消推量・打消意志・不可能・打消当然・禁止・不適当"},
45
+ "らむ": {f: "○ ○ らむ(らん) らむ(らん) らめ ○", type: "四段型", conn: "終止形(ラ変型には連体形)", mean: "現在推量・現在の原因推量・伝聞・婉曲"},
46
+ "けむ": {f: "○ ○ けむ(けん) けむ(けん) けめ ○", type: "四段型", conn: "連用形", mean: "過去推量・過去の原因推量・過去の伝聞・婉曲"},
47
+ "き": {f: "(せ) ○ き し しか ○", type: "特殊型", conn: "連用形(カ変・サ変には未然形にも)", mean: "過去(自分が経験したこと)"},
48
+ "けり": {f: "(けら) ○ けり ける けれ ○", type: "ラ変型", conn: "連用形", mean: "過去(伝え聞いたこと)・詠嘆"},
49
+ "つ": {f: "て て つ つる つれ てよ", type: "下二段型", conn: "連用形", mean: "完了・強意・並列"},
50
+ "ぬ": {f: "な に ぬ ぬる ぬれ ね", type: "ナ変型", conn: "連用形", mean: "完了・強意・並列"},
51
+ "たり(完了)": {f: "たら たり たり たる たれ たれ", type: "ラ変型", conn: "連用形", mean: "完了・存続"},
52
+ "り": {f: "ら り り る れ れ", type: "ラ変型", conn: "サ変の未然形・四段の已然形", mean: "完了・存続"},
53
+ "なり(断定)": {f: "なら なり・に なり なる なれ なれ", type: "形容動詞型(ナリ活用)", conn: "体言・連体形", mean: "断定・存在"},
54
+ "なり(伝聞推定)": {f: "○ (なり) なり なる なれ ○", type: "ラ変型", conn: "終止形(ラ変型には連体形)", mean: "伝聞・推定"},
55
+ "めり": {f: "○ (めり) めり める めれ ○", type: "ラ変型", conn: "終止形(ラ変型には連体形)", mean: "推定・婉曲"},
56
+ "らし": {f: "○ ○ らし らし らし ○", type: "無変化型", conn: "終止形(ラ変型には連体形)", mean: "推定"},
57
+ "たり(断定)": {f: "たら たり・と たり たる たれ たれ", type: "形容動詞型(タリ活用)", conn: "体言", mean: "断定"},
58
+ "ごとし": {f: "○ ごとく ごとし ごとき ○ ○", type: "形容詞型(ク活用)", conn: "連体形・助詞「の」「が」", mean: "比況・例示"},
59
+ "まほし": {f: "まほしから まほしく・まほしかり まほし まほしき・まほしかる まほしけれ ○", type: "形容詞型(シク活用)", conn: "未然形", mean: "希望"},
60
+ "たし": {f: "たから たく・たかり たし たき・たかる たけれ ○", type: "形容詞型(ク活用)", conn: "連用形", mean: "希望"},
61
+ };
62
+ var FORMS = ["未然", "連用", "終止", "連体", "已然", "命令"];
63
+ // 基本形と意味から表の項目を選ぶ(なり・たりは意味で分ける)
64
+ function auxOf(base, mean){
65
+ var b = String(base || "").replace(/[((].*$/, "");
66
+ if (AUX[base]) return {key: base, a: AUX[base]};
67
+ if (b === "なり") return /伝聞|推定/.test(mean || "") ? {key: "なり(伝聞推定)", a: AUX["なり(伝聞推定)"]} : {key: "なり(断定)", a: AUX["なり(断定)"]};
68
+ if (b === "たり") return /断定/.test(mean || "") ? {key: "たり(断定)", a: AUX["たり(断定)"]} : {key: "たり(完了)", a: AUX["たり(完了)"]};
69
+ if (b === "ん") return {key: "む", a: AUX["む"]};
70
+ if (b === "んず") return {key: "むず", a: AUX["むず"]};
71
+ return AUX[b] ? {key: b, a: AUX[b]} : null;
72
+ }
73
+
74
+ // ---------------------------------------------------------------- 読み取り
75
+ // parse(文字列) → {lines: [{words: [{text: [{t, rb}], tail, tag, pos, info, aux}], yaku}], warnings}
76
+ function rubyText(s){
77
+ var out = [], re = /\{([^|{}]*)\|([^{}]*)\}/g, last = 0, m;
78
+ while ((m = re.exec(s))){ if (m.index > last) out.push({t: s.slice(last, m.index)}); out.push({t: m[1], rb: m[2]}); last = re.lastIndex; }
79
+ if (last < s.length) out.push({t: s.slice(last)});
80
+ return out;
81
+ }
82
+ function parse(src){
83
+ var lines = [], warnings = [];
84
+ String(src || "").split(/\r?\n/).map(function(l){ return l.trim(); }).filter(Boolean).forEach(function(l){
85
+ if (/^[==]/.test(l)){
86
+ if (!lines.length) warnings.push("現代語訳の前に本文がない:" + l);
87
+ else lines[lines.length - 1].yaku = l.replace(/^[==]\s*/, "");
88
+ return;
89
+ }
90
+ var words = l.split(/[//]/).filter(function(w){ return w.trim() !== ""; }).map(function(w){
91
+ var m = /^(.*?)(?:[[[]([^\]]]*)[\]]])?([^[\][]]*)$/.exec(w.trim());
92
+ var tag = m[2] ? m[2].trim() : "", parts = tag ? tag.split(/[・・]/) : [], pos = tag ? posOf(parts[0]) : null;
93
+ var word = {text: rubyText(m[1]), tail: m[3] || "", tag: tag, pos: pos, info: parts.slice(1), aux: null};
94
+ if (pos && pos.unknown) warnings.push("品詞「" + parts[0] + "」は知らない(そのまま出す):" + POS.map(function(p){ return p[0]; }).join("・") + " のどれか");
95
+ if (pos && pos.kind === "aux"){
96
+ // [助動・基本形・意味・活用形]
97
+ var x = auxOf(parts[1], parts[2]);
98
+ if (!x) warnings.push("表にない助動詞「" + (parts[1] || "") + "」(" + w + ")");
99
+ word.aux = {base: parts[1] || "", mean: parts[2] || "", form: parts[3] || "", entry: x};
100
+ }
101
+ return word;
102
+ });
103
+ lines.push({words: words, yaku: ""});
104
+ });
105
+ return {lines: lines, warnings: warnings};
106
+ }
107
+ function plainText(w){ return w.text.map(function(s){ return s.t; }).join("") + w.tail; }
108
+
109
+ // ---------------------------------------------------------------- 部品
110
+ var CSS = [
111
+ "m-kobun{display:block;position:relative;font-family:var(--font-mincho);color:var(--fg)}",
112
+ "m-kobun .kb-text{position:absolute;inset:0;line-height:1.5}",
113
+ "m-kobun.kb-tate .kb-text{writing-mode:vertical-rl}",
114
+ "m-kobun .kb-line{display:flex;flex-direction:column;margin:0 0 6px}",
115
+ "m-kobun.kb-tate .kb-line{margin:0 0 0 14px}",
116
+ "m-kobun .kb-src{display:block}",
117
+ "m-kobun .kb-w{display:inline-flex;flex-direction:column;align-items:center;vertical-align:top}",
118
+ "m-kobun .kb-tag{font-size:24px;line-height:1.1;white-space:nowrap;font-family:var(--font-cap,var(--font-sans))}",
119
+ // スラッシュ:横書きでは斜めの線、縦書きでは横の線(背景で描く)
120
+ "m-kobun .kb-sep{display:inline-block;height:1.3em;vertical-align:top;background:linear-gradient(to bottom right,transparent calc(50% - 1.3px),var(--muted) calc(50% - 1.3px),var(--muted) calc(50% + 1.3px),transparent calc(50% + 1.3px))}",
121
+ "m-kobun.kb-tate .kb-sep{height:auto;width:1.1em;background:linear-gradient(var(--muted),var(--muted)) center/70% 2.5px no-repeat}",
122
+ "m-kobun .kb-aux{cursor:pointer;border-radius:4px}",
123
+ "m-kobun .kb-aux:focus-visible{outline:2px solid var(--emph);outline-offset:2px}",
124
+ "m-kobun .kb-yaku{display:block;font-size:27px;line-height:1.5;color:var(--term);font-family:var(--font-cap,var(--font-sans))}",
125
+ "m-kobun .kb-pop{position:absolute;z-index:5;writing-mode:horizontal-tb;background:var(--bg);border:2px solid var(--emph);border-radius:10px;" +
126
+ "padding:10px 16px;box-shadow:0 4px 18px color-mix(in srgb,var(--fg) 22%,transparent);font-family:var(--font-cap,var(--font-sans));font-size:24px;line-height:1.35;color:var(--fg);display:none}",
127
+ "m-kobun .kb-pop b{color:var(--emph)}",
128
+ "m-kobun .kb-pop table{border-collapse:collapse;margin-top:6px;font-size:24px;width:auto}",
129
+ "m-kobun .kb-pop th,m-kobun .kb-pop td{border:1px solid var(--line);padding:2px 8px;text-align:center;font-weight:400;color:var(--fg)}",
130
+ "m-kobun .kb-pop td.on{background:var(--emph-tint);color:var(--emph);font-weight:700}",
131
+ "@media print{m-kobun .kb-pop{display:none!important}}",
132
+ ].join("\n");
133
+ var CSS_ID = "kobun-2-0-3-css"; // the style element this part writes, named with its name and version (spec §6.1 Identifiers)
134
+ return class extends base.MotionElement {
135
+ static partName = "kobun"; // the registry name (define meta name), for report prefixes
136
+ static testing = {parse: parse, AUX: AUX, FORMS: FORMS, auxOf: auxOf, posOf: posOf}; // for tools/test-kokugo.mjs only (no part reads it)
137
+ static interactive = true; // 操作できるパーツ(助動詞を押すと札。docs/conventions.md §6)
138
+ // データの形(kit/shape.js):JSON ではなく、要素の中に 1 行 1 文の字(語を / で切り [品詞])
139
+ static shape = {text: true, example: "春[名]/は[係助]/あけぼの[名]。\n= 春は明け方(がよい)。"};
140
+ static props = {
141
+ size: {type: "number", default: 34, doc: "本文の字の大きさ(px)"},
142
+ tate: {type: "bool", default: false, doc: "縦書きにする(品詞は語の左、現代語訳は文の左に)"},
143
+ yaku: {type: "bool", default: true, doc: "現代語訳(= の行)があれば、最後のステップで並べる"},
144
+ fade: {type: "number", default: 0.6, doc: "1 文の品詞分解を出す秒数"},
145
+ detail: {type: "bool", default: false, doc: "品詞の下に [ ] の中をすべて(活用の種類・活用形など)出す"},
146
+ };
147
+ get model(){ if (!this._m) this._m = parse(this._src !== undefined ? this._src : this.textContent); return this._m; }
148
+ get hasYaku(){ return this.props.yaku && this.model.lines.some(function(l){ return l.yaku; }); }
149
+ get steps(){ return this.getAttribute("steps") !== null ? +this.getAttribute("steps") : this.model.lines.length + (this.hasYaku ? 1 : 0); }
150
+ mount(ctx){
151
+ var self = this, P = this.props;
152
+ this._src = this.textContent;
153
+ var m = this.model;
154
+ m.warnings.forEach(function(w){ ctx.report("data", "[kobun] " + w); });
155
+ this.mode = ctx.mode;
156
+ this.textContent = "";
157
+ this.classList.add("plot");
158
+ // kb-tate, not tate: Studio's layouts give .tate a vertical writing mode and height 100%, which made the element 0 wide
159
+ if (P.tate) this.classList.add("kb-tate");
160
+ if (!document.getElementById(CSS_ID)){ var st = document.createElement("style"); st.id = CSS_ID; st.textContent = CSS; document.head.appendChild(st); }
161
+ var mk = function(tag, cls, parent, text){ var e = document.createElement(tag); if (cls) e.className = cls; if (text !== undefined) e.textContent = text; parent.appendChild(e); return e; };
162
+ var box = mk("div", "kb-text", this);
163
+ box.style.fontSize = P.size + "px";
164
+ this.lines = m.lines.map(function(line, li){
165
+ var L = {el: mk("div", "kb-line", box), words: [], seps: []};
166
+ var src = mk("span", "kb-src", L.el);
167
+ line.words.forEach(function(w, wi){
168
+ if (wi > 0){
169
+ // スラッシュ(背景で描く)。幅(縦書きでは高さ)は段階で 0 から広げる
170
+ var sp = mk("span", "kb-sep", src);
171
+ L.seps.push(sp);
172
+ }
173
+ var we = mk("span", "kb-w", src);
174
+ var tx = mk("span", "kb-wt", we);
175
+ w.text.forEach(function(s){
176
+ if (s.rb){ var r = mk("ruby", "", tx, s.t); mk("rt", "", r, s.rb); }
177
+ else tx.appendChild(document.createTextNode(s.t));
178
+ });
179
+ if (w.tail) tx.appendChild(document.createTextNode(w.tail));
180
+ var tg = mk("span", "kb-tag", we, w.pos ? (P.detail ? w.tag : w.pos.short) :" ");
181
+ if (!w.pos) tg.setAttribute("aria-hidden", "true"); // 品詞のない語の空きの札(いつも見えない)
182
+ var W = {el: we, tx: tx, tag: tg, w: w};
183
+ if (w.aux && w.aux.entry){
184
+ we.classList.add("kb-aux"); we.tabIndex = 0; we.setAttribute("role", "button");
185
+ we.setAttribute("aria-label", plainText(w) + ":助動詞「" + w.aux.base + "」" + w.aux.mean + "・" + w.aux.form + "形(押すと活用表)");
186
+ var open = function(e){ e.preventDefault(); e.stopPropagation(); self.toggle(li, wi); };
187
+ we.addEventListener("click", open);
188
+ we.addEventListener("keydown", function(e){ if (e.key === "Enter" || e.key === " "){ open(e); } });
189
+ }
190
+ L.words.push(W);
191
+ });
192
+ if (line.yaku) L.yaku = mk("span", "kb-yaku", L.el, line.yaku);
193
+ if (L.yaku && !self.hasYaku) L.yaku.setAttribute("aria-hidden", "true"); // yaku="false":現代語訳は出さない(読まない)
194
+ return L;
195
+ });
196
+ this.pop = mk("div", "kb-pop", this);
197
+ this.pop.addEventListener("click", function(e){ e.stopPropagation(); self._open = null; self.redraw(); });
198
+ // 読み上げ:本文の語・品詞・押せる助動詞は中身として読める(role="figure"。img にすると押せる語が読めなくなる)。名前は最後の形を 1 文で:
199
+ // 品詞分解した本文と、現代語訳を並べるなら現代語訳。作者の aria-label があればそれを使う(上書きしない)
200
+ if (this._aria === undefined) this._aria = this.getAttribute("aria-label");
201
+ this.setAttribute("role", "figure");
202
+ if (!this._aria){
203
+ var body = m.lines.map(function(l){ return l.words.map(plainText).join(""); }).join("");
204
+ this.setAttribute("aria-label", "古文の品詞分解:" + body + (this.hasYaku ? (/[。、..,,]$/.test(body) ? "" : "。") + "現代語訳:" + m.lines.map(function(l){ return l.yaku || ""; }).join("") : ""));
205
+ }
206
+ }
207
+ // 押した助動詞の札:開いている札と同じなら閉じる。今の段階で開いた札だけを出す
208
+ toggle(li, wi){
209
+ if (this.mode === "video") return;
210
+ var o = this._open;
211
+ this._open = o && o.li === li && o.wi === wi ? null : {li: li, wi: wi, k: this._k};
212
+ this.redraw();
213
+ }
214
+ redraw(){ if (this._k !== undefined) this.render(this._k, this._t, this._ctx); }
215
+ duration(k){
216
+ var n = this.model.lines.length;
217
+ if (k >= 1 && k <= n) return this.props.fade + 0.2;
218
+ if (k === n + 1) return 0.6;
219
+ return 0;
220
+ }
221
+ render(k, t, ctx){
222
+ var self = this, P = this.props, n = this.model.lines.length, tate = P.tate;
223
+ var lag = n > 1 ? Math.min(0.12, 0.15 / (n - 1)) : 0;
224
+ // 段階が動いたら札を閉じる。同じ段階にもう一度入るとき(ctx.reset:触れた部品を、宣言した姿に戻す)も閉じる
225
+ if (this._open && (this._open.k !== k || ctx.reset)) this._open = null;
226
+ // 札を押したときに描き直す ctx:この描画のもの(reset と entered は除く)
227
+ this._k = k; this._t = t; this._ctx = Object.assign({}, ctx, {reset: false, entered: false});
228
+ // 先の段階を薄く見せる表示(授業の表示):後の文の区切りと品詞の札、現代語訳を --preview-opacity の濃さで出す。
229
+ // 本文の字は初めから見えているので濃さも色も変えない(品詞の色は札で見せる)。薄い語の活用表は開かない
230
+ var preview = !!ctx.preview, PV = preview ? base.previewOpacity(this) : 0.45;
231
+ this.lines.forEach(function(L, li){
232
+ // 文 li の品詞分解は段階 li + 1 に出る
233
+ var s = li + 1, e = k > s ? 1 : k < s ? 0 : D.prog(t, 0, P.fade), faint = preview && k < s;
234
+ L.seps.forEach(function(sp){
235
+ sp.style[tate ? "height" : "width"] = ((faint ? 1 : e) * 0.55).toFixed(3) + "em";
236
+ sp.style.opacity = (faint ? PV : e).toFixed(3);
237
+ });
238
+ L.words.forEach(function(W){
239
+ var col = W.w.pos ? COLOR[W.w.pos.kind] : "var(--fg)";
240
+ W.tx.style.color = e > 0.5 ? col : "var(--fg)";
241
+ W.tx.style.fontWeight = e > 0.5 && W.w.pos && W.w.pos.kind === "aux" ? 700 : 400;
242
+ W.tag.style.color = col;
243
+ W.tag.style.opacity = W.w.pos ? (faint ? PV : e).toFixed(3) : 0;
244
+ W.el.style.background = W.w.aux && e > 0.5 ? "var(--emph-tint)" : "transparent";
245
+ if (W.w.aux && W.w.aux.entry){ W.el.style.pointerEvents = faint ? "none" : ""; W.el.tabIndex = faint ? -1 : 0; }
246
+ });
247
+ // 現代語訳は文ごとに少しずつ遅らせて出し、段階の長さ(0.6 秒)の中で出し終える(2 文までは 0.12 秒ずつ、それより多ければ詰める)
248
+ if (L.yaku){ var y = self.hasYaku ? (k > n + 1 ? 1 : k < n + 1 ? (preview ? PV : 0) : D.prog(t, li * lag, 0.45)) : 0; L.yaku.style.opacity = y.toFixed(3); }
249
+ });
250
+ // 札
251
+ var o = this._open;
252
+ if (!o){ this.pop.style.display = "none"; return; }
253
+ var W = this.lines[o.li].words[o.wi], a = W.w.aux, ent = a.entry;
254
+ this.pop.textContent = "";
255
+ var head = document.createElement("div");
256
+ var b = document.createElement("b"); b.textContent = a.base; head.appendChild(b);
257
+ head.appendChild(document.createTextNode("(助動詞・" + ent.a.type + ") この文では " + a.mean + "・" + a.form + "形"));
258
+ this.pop.appendChild(head);
259
+ var row = function(label, text){ var d = document.createElement("div"); d.textContent = label + ":" + text; self.pop.appendChild(d); };
260
+ row("接続", ent.a.conn); row("意味", ent.a.mean);
261
+ var tb = document.createElement("table"), tr1 = document.createElement("tr"), tr2 = document.createElement("tr"), forms = ent.a.f.split(" ");
262
+ FORMS.forEach(function(f, j){
263
+ var th = document.createElement("th"); th.textContent = f; tr1.appendChild(th);
264
+ var td = document.createElement("td"); td.textContent = forms[j] || "○"; if (a.form && a.form.indexOf(f) === 0) td.className = "on"; tr2.appendChild(td);
265
+ });
266
+ tb.appendChild(tr1); tb.appendChild(tr2); this.pop.appendChild(tb);
267
+ this.pop.style.display = "block";
268
+ // 語の近く(下か左)に置き、部品の外にはみ出さない
269
+ var r = W.el.getBoundingClientRect(), R = this.getBoundingClientRect(), sc = R.width / (this.offsetWidth || 1) || 1;
270
+ var x = (r.left - R.left) / sc, y = (r.bottom - R.top) / sc + 8, pw = this.pop.offsetWidth, ph = this.pop.offsetHeight;
271
+ if (tate){ x = (r.left - R.left) / sc - pw - 10; y = (r.top - R.top) / sc; }
272
+ // 横書きで下に入らなければ語の上へ
273
+ if (!tate && y + ph > this.offsetHeight) y = (r.top - R.top) / sc - ph - 8;
274
+ x = Math.max(0, Math.min(this.offsetWidth - pw, x)); y = Math.max(0, Math.min(Math.max(0, this.offsetHeight - ph), y));
275
+ this.pop.style.left = x.toFixed(1) + "px"; this.pop.style.top = y.toFixed(1) + "px";
276
+ }
277
+ };
278
+ });
@@ -0,0 +1,44 @@
1
+ ---
2
+ summary: Hierarchy tree (org chart, taxonomy), built level by level from the root; auto layout
3
+ steps: depth (by="level") or node count (by="node"); or the largest step
4
+ props:
5
+ orient: down (default) or right
6
+ by: level (default) or node (depth-first)
7
+ link: elbow (default) or straight
8
+ size: box text px (0 = 27, shrink to 24)
9
+ fade: box appear (s)
10
+ draw: line draw (s)
11
+ example: {"nodes": [{"id": "r", "label": "Animals"}, {"id": "a", "label": "Vertebrates", "parent": "r"}, {"id": "b", "label": "Invertebrates", "parent": "r"}]}
12
+ ---
13
+
14
+ Parent–child structures (org charts, taxonomies, outlines). No coordinates; laid out without overlaps.
15
+
16
+ Child JSON: `{"nodes": [...], "edges": [...]}` (`edges` optional).
17
+
18
+ - node: `id`, `label` (`\n`) or `tex` (KaTeX), `parent` (parent `id`; exactly one root without `parent`), `note` (small, **under** box), `tone` (`term` default, `emph`, `muted`, `accent2`, `series-1..4`), `dash: true` (dashed, unfilled), `step`, `at` (start s)
19
+ - Children in array order; parent centred over them
20
+ - edge: extra links (`from` `to` `label` `tone` `dash` `step`), dashed arrow outside the tree; best at same depth; step: later end
21
+ - Child `branch`: line text (e.g. probability). `path`: root-first `id`s highlighted in turn (default 1 step per line, after the tree; `pathStep`: in one step; `pathNote`: end note)
22
+ - `orient="right"` for wide taxonomies. `by="node"`: one at a time, depth-first (to follow a branch). Node `step` wins
23
+ - Lines `--muted`, 3 px; `tone: emph` box: `--emph-tint` fill
24
+ - Fit (~440 px high): ~8 four-character boxes per level (`down`), ~7 (`right`); ~5 levels. More leaves: 2 staggered rows (~16 / ~11), then 2-line names. Text ≥ 24 px; overflow spills, reported. Too many: split
25
+ - `variant`: `fade`, `draw`, `grow`
26
+ - Show later steps faintly (`ctx.preview`): later parts faint
27
+
28
+ Premise contrast (positioning): root the question, children the positions (this work `emph`), then premises, then what each can say; a dropped premise `dash: true`.
29
+
30
+ The demo is `demo.html` (company, values and the premise contrast fictional).
31
+
32
+ <!-- llm: omit -->
33
+ Notes
34
+
35
+ - Moves ≤ 12 px within `fade` time. Edge step default: later end; edges bulge outward (`down` below, `right` right)
36
+ - Layout: subtrees placed bottom-up and pushed together until level contours touch (Reingold–Tilford); small subtrees in between go left
37
+ - Text 27 → 24 px (`size` fixes it). Width estimated from characters (CJK 1, others 0.6)
38
+ - At 24 px, no smaller text (conventions §2.3); tries: stagger children of parents with ≥ 3 leaf children (not with `straight`) → wrap names (≥ 4 chars, no `\n` or `*_^`; at the middle space, or after a mid hiragana; single Latin words never). Else least-overflow layout; shortfall via `ctx.report("size", …)`
39
+ - Motion: `fade` from below; `draw`, `grow` from the parent's direction, 12 px (root always as `fade`). `grow` from 0.92×
40
+ - `branch`: 24 px, `--fg`. `elbow` bends 20 px from the parent, text on the child line; levels widen to fit (`right` +52 px, `down` ≥ 76 px); no staggering. `straight`: outside the line's middle (crowded at ≥ 3 children)
41
+ - `path`: must start at the root, each pair parent–child, else a data card. Default: one step per line after the tree's last step. `pathStep`: drawn in that step (`draw` s each). `--emph` 6 px over the line, `--emph` 4 px frame on reached boxes, `branch` in `--emph`. `pathNote` beyond the end box after the last line; may overlap if the end box is not at the deepest level
42
+ - Show later steps faintly: later path faint; `branch` colour changes only at its step
43
+ - Edges take room outside the tree (`down`: 56 px below, +36 with a label); across depths they may cross boxes
44
+ <!-- llm: end -->