egatari 0.6.10 → 0.6.11-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 (124) hide show
  1. package/README.ja.md +22 -22
  2. package/README.md +1 -1
  3. package/bin/egatari.mjs +1 -1
  4. package/components.lock.json +288 -144
  5. package/components2.lock.json +657 -1
  6. package/kit/build.mjs +3 -2
  7. package/kit/check-messages.mjs +46 -12
  8. package/kit/check.mjs +54 -19
  9. package/kit/core/article-messages.mjs +5 -4
  10. package/kit/core/attachments.mjs +2 -1
  11. package/kit/core/build-core.mjs +2 -1
  12. package/kit/core/check-parity.mjs +3 -1
  13. package/kit/core/check-result.mjs +2 -1
  14. package/kit/core/check-rules.mjs +132 -0
  15. package/kit/core/colab-core.mjs +2 -2
  16. package/kit/core/geometry-check.mjs +302 -0
  17. package/kit/core/layout-scan.mjs +9 -2
  18. package/kit/core/live-results.mjs +1 -1
  19. package/kit/core/llm-fix.mjs +3 -2
  20. package/kit/core/llm-outline.mjs +3 -2
  21. package/kit/core/llm-pack-data.mjs +114 -114
  22. package/kit/core/narration-lint.mjs +37 -0
  23. package/kit/core/new-deck-pack.mjs +2 -1
  24. package/kit/core/new-deck.mjs +1 -1
  25. package/kit/core/plural.mjs +5 -0
  26. package/kit/core/portable.mjs +6 -5
  27. package/kit/core/sample-layout.mjs +14 -0
  28. package/kit/core/text-band.mjs +37 -0
  29. package/kit/core/tier-a.mjs +2 -1
  30. package/kit/instruction-version.json +1 -1
  31. package/kit/player.json +1 -1
  32. package/kit/player.lock.json +2 -2
  33. package/kit/render-compare.mjs +5 -4
  34. package/kit/tools.js +2 -2
  35. package/package.json +3 -2
  36. package/server/editor-ui.js +2 -2
  37. package/vendor/components/CATALOG.md +12 -12
  38. package/vendor/components/sha256/00d9072cb279a1a68166787f53395c747072388971d916c082a106844dbf888f/index.js +315 -0
  39. package/vendor/components/sha256/03e20fb6803de0d94e93de7c01d7d00cede57b0b2604b449daa4cb156367500d/README.en.md +23 -0
  40. package/vendor/components/sha256/03e20fb6803de0d94e93de7c01d7d00cede57b0b2604b449daa4cb156367500d/index.js +289 -0
  41. package/vendor/components/sha256/0e5458deb63e32aefdbf8722fa156fd44cd90d5d8f9d6a25a636007b4b599450/README.en.md +40 -0
  42. package/vendor/components/sha256/0e5458deb63e32aefdbf8722fa156fd44cd90d5d8f9d6a25a636007b4b599450/index.js +341 -0
  43. package/vendor/components/sha256/1073e03374f0fe65d2691f160bfd8c092986c168d0bd6a6094ebd444d4b89c27/index.js +592 -0
  44. package/vendor/components/sha256/12b1b32eb3a75e9f11eff407b7876473674ae996d7ce276e2ab6ffaf41ad4376/README.en.md +48 -0
  45. package/vendor/components/sha256/12b1b32eb3a75e9f11eff407b7876473674ae996d7ce276e2ab6ffaf41ad4376/index.js +384 -0
  46. package/vendor/components/sha256/147987bd84722249dab609293d4fafa93f0a2aac25b8517fda1710840b575d00/index.js +341 -0
  47. package/vendor/components/sha256/170e9072285213a2b4e79d7c2e4ddb882d1501e60b5da63c59b1679643163005/README.en.md +23 -0
  48. package/vendor/components/sha256/170e9072285213a2b4e79d7c2e4ddb882d1501e60b5da63c59b1679643163005/index.js +120 -0
  49. package/vendor/components/sha256/17da8ef5ce58354df54ebb52c8a9b0726e69d06ac28cc8e78f807ec338002782/README.en.md +32 -0
  50. package/vendor/components/sha256/17da8ef5ce58354df54ebb52c8a9b0726e69d06ac28cc8e78f807ec338002782/index.js +222 -0
  51. package/vendor/components/sha256/1b30dfd9b366ff07556024eb8ce75cca2eac8001fa392eed4e1232047001ec74/index.js +404 -0
  52. package/vendor/components/sha256/37846655693f8dd869d11d3d4cddb43be57f848037d0e49564b2250401448ab5/README.en.md +66 -0
  53. package/vendor/components/sha256/37846655693f8dd869d11d3d4cddb43be57f848037d0e49564b2250401448ab5/index.js +920 -0
  54. package/vendor/components/sha256/3fdd15756f779a16362dd854f143ca4343154059882d88d44adf64745c7876e3/README.en.md +50 -0
  55. package/vendor/components/sha256/3fdd15756f779a16362dd854f143ca4343154059882d88d44adf64745c7876e3/index.js +171 -0
  56. package/vendor/components/sha256/435c3f8e0c0abc123866e57ae2c7f3409e19d14a2eb67b1fde84c4da5d95f14c/README.en.md +31 -0
  57. package/vendor/components/sha256/435c3f8e0c0abc123866e57ae2c7f3409e19d14a2eb67b1fde84c4da5d95f14c/index.js +232 -0
  58. package/vendor/components/sha256/43740da51de85c1b7ec1eaf688f93fd9ea25b15977ab075e6abac196f08643a6/index.js +122 -0
  59. package/vendor/components/sha256/4817f77bd021ec5c77d5a15ee56e2e34d31d1d98630e86225eb20f2f9bf095e9/index.js +812 -0
  60. package/vendor/components/sha256/4e4bf3b2968c36a334dc997e32e36f22ecbc4f5dfe1c76bb7a5beef002fe8899/index.js +228 -0
  61. package/vendor/components/sha256/553e132d1f84caad648bb7175a206d4c5d18c005b5ca17989f5e8a5e3f5cdfa1/index.js +75 -0
  62. package/vendor/components/sha256/5b02d8a81a41f4d1658f1972f3fc91de3cc431b2c71bb6b92601d58f734de9ec/README.en.md +34 -0
  63. package/vendor/components/sha256/5b02d8a81a41f4d1658f1972f3fc91de3cc431b2c71bb6b92601d58f734de9ec/index.js +244 -0
  64. package/vendor/components/sha256/5c72414df5a948a7cbb882be1e5bdd4113d188e357d4a0f01fabda15781417eb/LICENSE-tabler.txt +21 -0
  65. package/vendor/components/sha256/5c72414df5a948a7cbb882be1e5bdd4113d188e357d4a0f01fabda15781417eb/index.js +4868 -0
  66. package/vendor/components/sha256/5c72414df5a948a7cbb882be1e5bdd4113d188e357d4a0f01fabda15781417eb/names.txt +4808 -0
  67. package/vendor/components/sha256/636f47e955f5550f046cfc7a3de8de70c4b97aa77771bde2ee0e31d706bb032e/index.js +278 -0
  68. package/vendor/components/sha256/65ddc34bd9c75e073f4c2cd283369417fe88769521809670c6b8730852d4f647/index.js +97 -0
  69. package/vendor/components/sha256/6b0c75b0f697fe451197301de82a113f1c2548b67f7a8d2b56576d2bae8e240c/index.js +607 -0
  70. package/vendor/components/sha256/6cdf432d3e61be3ff15e80910369324ac7ea0e8b9f62c32ef37bf09a5bfe93b9/README.en.md +33 -0
  71. package/vendor/components/sha256/6cdf432d3e61be3ff15e80910369324ac7ea0e8b9f62c32ef37bf09a5bfe93b9/index.js +390 -0
  72. package/vendor/components/sha256/6d648d0e5c96ec680c04a14b7c3d672010d3b9f101197689e9672ec00174383d/README.en.md +31 -0
  73. package/vendor/components/sha256/6d648d0e5c96ec680c04a14b7c3d672010d3b9f101197689e9672ec00174383d/index.js +267 -0
  74. package/vendor/components/sha256/71208afc5c8ea1ed6d2180f46de7385e43990cfb046ba350eefb917eca5d92fe/README.en.md +22 -0
  75. package/vendor/components/sha256/71208afc5c8ea1ed6d2180f46de7385e43990cfb046ba350eefb917eca5d92fe/index.js +145 -0
  76. package/vendor/components/sha256/7552a029f30f9c2f2ec8c5af4f144b63eeffc9172b53e35a925821f69a738b64/README.en.md +44 -0
  77. package/vendor/components/sha256/7552a029f30f9c2f2ec8c5af4f144b63eeffc9172b53e35a925821f69a738b64/index.js +203 -0
  78. package/vendor/components/sha256/781a45d97f1325cfb40aa98d00e1db9600949158fdb2749b0223b019c67a80f2/index.js +919 -0
  79. package/vendor/components/sha256/850944419734168be3dc202057de128131869c471cb8ab3baec2cfe789d56493/index.js +465 -0
  80. package/vendor/components/sha256/863d4d42075fbae1084089730f10da943c88d3e3e655235f28c24b9a3cf95c88/README.en.md +37 -0
  81. package/vendor/components/sha256/863d4d42075fbae1084089730f10da943c88d3e3e655235f28c24b9a3cf95c88/index.js +424 -0
  82. package/vendor/components/sha256/8a892d25d0bb6105ba31ea690b465876ce3af1fbaf18e2a9ce44ad2fee81260e/index.js +162 -0
  83. package/vendor/components/sha256/8acec8f299510287fbad6a69311ec58a39b0e99647dd03609c818e053b3b6087/index.js +484 -0
  84. package/vendor/components/sha256/8ef66bd1e800bcbedef436585469d308665aaa1ab6011aee699544302d0a8ad0/index.js +312 -0
  85. package/vendor/components/sha256/8fa5ed6ab12a27542e077ff965bea626ff9450b330609304dc1148fc8dbb68b0/README.en.md +40 -0
  86. package/vendor/components/sha256/8fa5ed6ab12a27542e077ff965bea626ff9450b330609304dc1148fc8dbb68b0/index.js +348 -0
  87. package/vendor/components/sha256/a0c71874d83045baaef70285bd00d87a7c6c43219fa5630dfff60d5cb08509be/index.js +250 -0
  88. package/vendor/components/sha256/a31f39625d7d1087d06a72b644cec417372f98add940288257ef07f812d8395a/index.js +747 -0
  89. package/vendor/components/sha256/ae04a57be4a26b7443796a93c58adcf1cbcf746120eba619bf9c2bcdce53c640/README.en.md +38 -0
  90. package/vendor/components/sha256/ae04a57be4a26b7443796a93c58adcf1cbcf746120eba619bf9c2bcdce53c640/index.js +289 -0
  91. package/vendor/components/sha256/ae06622a328da2a01260bc68b28bb632c391e8d62a4e8387638e5a944525a418/index.js +521 -0
  92. package/vendor/components/sha256/b490139e9afa84164054738532d5ec4985bf071e40791d903012fe3b850bae43/README.en.md +24 -0
  93. package/vendor/components/sha256/b490139e9afa84164054738532d5ec4985bf071e40791d903012fe3b850bae43/index.js +103 -0
  94. package/vendor/components/sha256/b756c66d5c6e6ace90912ab467dea3031f2c9b291d8b2a786ca660faa0e8ac84/index.js +121 -0
  95. package/vendor/components/sha256/babd98da50ea334b63f79c66be436d092e8aea32654e011a6444667abb882e77/fixtures/ABCJS-ADAPTER.md +101 -0
  96. package/vendor/components/sha256/babd98da50ea334b63f79c66be436d092e8aea32654e011a6444667abb882e77/fixtures/LICENSE-abcjs.txt +21 -0
  97. package/vendor/components/sha256/babd98da50ea334b63f79c66be436d092e8aea32654e011a6444667abb882e77/fixtures/chords.json +89 -0
  98. package/vendor/components/sha256/babd98da50ea334b63f79c66be436d092e8aea32654e011a6444667abb882e77/fixtures/doremi.json +261 -0
  99. package/vendor/components/sha256/babd98da50ea334b63f79c66be436d092e8aea32654e011a6444667abb882e77/fixtures/extras.json +192 -0
  100. package/vendor/components/sha256/babd98da50ea334b63f79c66be436d092e8aea32654e011a6444667abb882e77/fixtures/kaeru.json +521 -0
  101. package/vendor/components/sha256/babd98da50ea334b63f79c66be436d092e8aea32654e011a6444667abb882e77/fixtures/rhythm.json +248 -0
  102. package/vendor/components/sha256/babd98da50ea334b63f79c66be436d092e8aea32654e011a6444667abb882e77/fixtures/ties.json +360 -0
  103. package/vendor/components/sha256/babd98da50ea334b63f79c66be436d092e8aea32654e011a6444667abb882e77/index.js +508 -0
  104. package/vendor/components/sha256/bea7cb344f55677d5756c9711b90cc971126830ec5f66a03f71f13dbfadc401e/index.js +351 -0
  105. package/vendor/components/sha256/c08b25a2f7be68c36634cdee180aa617fd018d80b7ddf2a484a2edb4acffdbe0/README.en.md +42 -0
  106. package/vendor/components/sha256/c08b25a2f7be68c36634cdee180aa617fd018d80b7ddf2a484a2edb4acffdbe0/index.js +268 -0
  107. package/vendor/components/sha256/cbe8bb4b2fd0845a9333bc2064d86758ea6465992ad86a99167ba17f57f3e382/README.en.md +51 -0
  108. package/vendor/components/sha256/cbe8bb4b2fd0845a9333bc2064d86758ea6465992ad86a99167ba17f57f3e382/index.js +228 -0
  109. package/vendor/components/sha256/d2df3d70fc7c6e07e3cad7332a7e5501e84abeb24653786e567f57046adebcba/index.js +268 -0
  110. package/vendor/components/sha256/d386f2b94cd9fbed765ad301aa7009228599edb2859efe7f37a98d7aaa44b9bb/README.en.md +35 -0
  111. package/vendor/components/sha256/d386f2b94cd9fbed765ad301aa7009228599edb2859efe7f37a98d7aaa44b9bb/index.js +179 -0
  112. package/vendor/components/sha256/e6d219f67d241fdf00a40d4cec261d9dd3c09ad3110d3418d4e843d0f2b8c196/index.js +429 -0
  113. package/vendor/components/sha256/ef60e6c089f5f6e909f439af8fc0c9c0a2d7a1aafad5e65be6328ba993b990a0/index.js +354 -0
  114. package/vendor/components/sha256/f6f47601c90f0195353e94b76d57499591d6330a7e35714958a2c41229f70da2/index.js +198 -0
  115. package/vendor/components/sha256/f9159c87fa998487787f738fdfab52aa2483f52f170fc258840b127f6ed06051/README.en.md +44 -0
  116. package/vendor/components/sha256/f9159c87fa998487787f738fdfab52aa2483f52f170fc258840b127f6ed06051/index.js +304 -0
  117. package/vendor/components/sha256/fb482cbe2ca1da07d08f41880e03fe75ff3f1d29842ff40946541e63030219b8/README.en.md +42 -0
  118. package/vendor/components/sha256/fb482cbe2ca1da07d08f41880e03fe75ff3f1d29842ff40946541e63030219b8/index.js +481 -0
  119. package/vendor/components/sha256/fdcea28e27638d8bfe234016672375e14de8bb97c32f7b6840d1b7b10ac4b1cd/index.js +233 -0
  120. package/vendor/components/sha256/ff5eaa083a46db6aefc13d97b27c9487f9fc318805f5c89b05a12e63703b7a72/LICENSE-strokesvg.txt +115 -0
  121. package/vendor/components/sha256/ff5eaa083a46db6aefc13d97b27c9487f9fc318805f5c89b05a12e63703b7a72/OFL.txt +93 -0
  122. package/vendor/components/sha256/ff5eaa083a46db6aefc13d97b27c9487f9fc318805f5c89b05a12e63703b7a72/index.js +749 -0
  123. package/vendor/components/sha256/ff5eaa083a46db6aefc13d97b27c9487f9fc318805f5c89b05a12e63703b7a72/strokes-CHANGES.md +20 -0
  124. package/vendor/components-2/manifest-2.7.0.json +2118 -0
@@ -0,0 +1,33 @@
1
+ ---
2
+ summary: Predict, reveal; votes as bars, answer framed
3
+ steps: 0 question, 1 bars, answer-step (2)
4
+ props:
5
+ answer-step: 2 or more (default 2); after the step-1 count
6
+ unit: count unit
7
+ poll: live poll id
8
+ ticks: grid
9
+ example: {"question": "Which falls first?", "choices": [{"label": "Heavy"}, {"label": "Light"}, {"label": "Same"}], "answer": 2, "counts": [14, 3, 9], "note": "No air: same"}
10
+ ---
11
+
12
+ Child JSON: `{"question", "choices": [{"label", "tone"?}], "answer": 0-based, "counts"?: [sample], "note"?: answer line, "labels"?: {"correct"?: mark (default "✓ Correct")}}`
13
+
14
+ - 2–6 choices. Video/print/start show `counts` (or 0)
15
+ - Script uses `counts`; vote at `{note:hands up}` (parens get read)
16
+ - `poll="p1"`: live poll totals
17
+
18
+ <!-- llm: omit -->
19
+ Notes for authors of parts (check with dev)
20
+
21
+ - Steps: 0 question, choices, ticks (context first); 1 bars and controls; `answer-step` frame, "✓ correct", `note`, others faded, text `--muted` (≥ 4.5:1)
22
+ - Show later steps faintly: nothing ahead shown (`static preview = "none"`, manifest `preview: "none"`)
23
+ - Viewer state (spec §8.4): counts and guess survive step changes on the slide; reset to author values only on `ctx.entered` (since 2.0.0); `ctx.reset` only drops focus
24
+ - Hands up; teacher counts ±1 or types. Alone: click = guess. Counts kept while on the slide
25
+ - Print: author values, no guess marks; screen counts restored after
26
+ - Methods: `input(choice, count)` (0–9999 integer, else console.warn; no-op in video); `counts()`
27
+ - On change: `CustomEvent("egatari-input", {bubbles: true, detail: {counts}})`
28
+ - live: `ctx.live?.poll(id)` → `number[] | null`; bars only for arrays, not in video/print
29
+ - `static interactive = true`, `static viewerInput = true` → manifest
30
+ - Keys: `+` `-` `↑` `↓` (buttons also `←` `→`); no digit keys; Esc/Enter leave the field
31
+ - No controls in video; hidden in print
32
+ - UI text (mark, labels, announcements) follows ctx.lang; `labels.correct` overrides the mark
33
+ <!-- llm: end -->
@@ -0,0 +1,390 @@
1
+ // m-predict:予想してから答えを開く。問いと選択肢、クラスの数(手を挙げた人数)を選択肢ごとの棒で見せ、作者の書いた段階で答えを開く
2
+ // <m-predict unit="人" style="height:440px"><script type="application/json">
3
+ // {"question": "重い球と軽い球、どちらが先に落ちる?",
4
+ // "choices": [{"label": "重い球"}, {"label": "軽い球"}, {"label": "同時"}],
5
+ // "answer": 2, "counts": [14, 3, 9], "note": "空気の抵抗を除けば、重さによらず同時に落ちる(ガリレオ)"}
6
+ // (JSON の終わり)</m-predict>
7
+ // 段階:0 = 問いと選択肢(と目盛り)。1 = 数の棒。answer-step(既定 2)= 答え(正しい選択肢に枠と ✓、ほかは薄く、note)
8
+ // 見る人の入力(仕様 §8.4「Viewer input」、Studio の約束事 §3):選択肢ごとの −1・+1 と数の欄(発表者が数える)、選択肢の名前を押すと「自分の予想」。
9
+ // 入力は (i, k, t) の外で、同じスライドにいるあいだは(段階を進めても戻っても)残る。ほかのスライドから入ったとき・飛んだとき(ctx.entered)だけ作者の counts に戻る。
10
+ // ctx.reset(触った部品を段階に入るときに戻す)では、触った跡(欄やボタンのフォーカス)だけを戻し、数と予想は残す(仕様 §8.4)
11
+ // 動画(?mode=video)では操作を作らず、input() も受け付けない。印刷では操作を隠し、作者の数を字で出す
12
+ // live(拡張 live §2.5):poll="p1" と書き、ctx.live があれば ctx.live.poll("p1") の数(number[] | null)を棒に出す。
13
+ // 見せてよいか(先生が見せると決めたか、3 人以上か)は実行系が決める。部品は配列が来たときだけ出し、動画・印刷では出さない
14
+ // 見せ方(docs/conventions.md §1):fade(0。棒と答えの印がフェードして現れる)・draw(棒が上の選択肢から順に現れ、答えの枠を線で引く。長さは同じ)
15
+ // 2.0(Egatari spec §6.1 の部品):base の MotionElement・el・mtext・prog・variant を使い、プレイヤーのグローバルは使わない。
16
+ // 見る人の入力を戻すのは ctx.entered だけ(1.x の deck:pos の代わりはない)。動画かどうかは mount の ctx.mode。
17
+ // 要素の大きさの問題は ctx.report("size", …)。印刷の前後は document.defaultView の beforeprint・afterprint
18
+ egatariParts.define({name: "predict", version: "2.1.0", requires: {base: "1.2.0"}, element: "m-predict"}, function(deps){
19
+ "use strict";
20
+ var base = deps.base;
21
+ // 表示の文字(ctx.lang、見る人の言語ではなく文書の言語)。correct は子の JSON の labels.correct で上書きできる
22
+ var TEXT = {
23
+ ja: {
24
+ correct: "✓ 正解",
25
+ noteWrong: "予想ははずれ。", noteRight: "予想は当たり。",
26
+ liveResults: "投票の結果",
27
+ guessLabel: function(label){ return "予想:" + label; },
28
+ countGroup: function(label){ return label + "の数"; },
29
+ countField: function(label, unit){ return label + "の数" + (unit ? "(" + unit + ")" : ""); },
30
+ decrease: function(label){ return label + ":1 減らす"; },
31
+ increase: function(label){ return label + ":1 増やす"; },
32
+ countAnnounce: function(label, v, unit){ return label + ":" + v + unit; },
33
+ unpicked: "予想を外しました",
34
+ pickedRight: function(label){ return "当たり:" + label; },
35
+ pickedWrong: function(label){ return "はずれ。答えは " + label; },
36
+ myGuess: function(label){ return "あなたの予想:" + label; },
37
+ answerAnnounce: function(label, note){ return "答え:" + label + (note ? "。" + note : ""); },
38
+ },
39
+ en: {
40
+ correct: "✓ Correct",
41
+ noteWrong: "Wrong. ", noteRight: "Right! ",
42
+ liveResults: "Poll results",
43
+ guessLabel: function(label){ return "Guess: " + label; },
44
+ countGroup: function(label){ return label + " count"; },
45
+ countField: function(label, unit){ return label + " count" + (unit ? " (" + unit + ")" : ""); },
46
+ decrease: function(label){ return label + ": decrease by 1"; },
47
+ increase: function(label){ return label + ": increase by 1"; },
48
+ countAnnounce: function(label, v, unit){ return label + ": " + v + (unit ? " " + unit : ""); },
49
+ unpicked: "Guess cleared",
50
+ pickedRight: function(label){ return "Correct: " + label; },
51
+ pickedWrong: function(label){ return "Wrong. The answer is " + label; },
52
+ myGuess: function(label){ return "My guess: " + label; },
53
+ answerAnnounce: function(label, note){ return "Answer: " + label + (note ? ". " + note : ""); },
54
+ }
55
+ };
56
+ var CSS_ID = "predict-2-1-0-css"; // the style element this part writes, named with its name and version (spec §6.1 Identifiers)
57
+ var CSS = [
58
+ "m-predict .pd-say{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}",
59
+ "m-predict .pd-pick{position:absolute;background:transparent;border:0;border-radius:10px;cursor:pointer;padding:0;margin:0}",
60
+ "m-predict .pd-pick:focus-visible,m-predict .pd-btn:focus-visible,m-predict .pd-num:focus-visible{outline:3px solid var(--emph);outline-offset:2px}",
61
+ "m-predict .pd-ctl{position:absolute;display:flex;gap:8px;align-items:center;height:48px}",
62
+ "m-predict .pd-btn{width:60px;height:48px;font:700 27px/1 var(--font-cap,var(--font-sans,sans-serif));color:var(--fg);background:var(--bg);border:2px solid var(--term);border-radius:8px;cursor:pointer;padding:0;touch-action:manipulation}",
63
+ "m-predict .pd-btn:active{background:var(--term-tint)}",
64
+ "m-predict .pd-num{width:80px;height:48px;box-sizing:border-box;font:700 27px/1 var(--font-cap,var(--font-sans,sans-serif));font-variant-numeric:tabular-nums;text-align:center;color:var(--fg);background:var(--bg);border:2px solid var(--muted);border-radius:8px;padding:0}",
65
+ "@media print{m-predict .pd-ctl,m-predict .pd-pick,m-predict .pd-mark,m-predict .pd-live{display:none!important}}",
66
+ ].join("\n");
67
+ return class extends base.MotionElement {
68
+ static partName = "predict"; // the registry name (define meta name), for report prefixes
69
+ static variants = ["fade", "draw"];
70
+ static interactive = true; // 操作できるパーツ(docs/conventions.md §6)
71
+ static viewerInput = true; // 見る人の入力を受け付ける(仕様 §8.4)
72
+ static preview = "none"; // 先の段階は答えなので、授業の表示でも先を見せない(仕様 §8.4、docs/conventions.md §1.2)
73
+ // データの形(kit/shape.js)
74
+ static shape = {
75
+ schema: {type: "object", additionalProperties: false, required: ["choices", "answer"], properties: {
76
+ question: {type: "string"},
77
+ choices: {type: "array", minItems: 2, maxItems: 6, items: {type: "object", additionalProperties: false, required: ["label"], properties: {
78
+ label: {type: "string"}, tone: {type: "string"}}}},
79
+ answer: {type: "integer"},
80
+ counts: {type: "array", items: {type: "integer"}},
81
+ note: {type: "string"},
82
+ labels: {type: "object", additionalProperties: false, properties: {correct: {type: "string"}}}}},
83
+ example: {question: "重い球と軽い球、どちらが先に落ちる?", choices: [{label: "重い球"}, {label: "軽い球"}, {label: "同時"}], answer: 2, counts: [14, 3, 9], note: "空気の抵抗を除けば同時に落ちる"},
84
+ note: {en: "choices are objects {\"label\": …} (not strings); answer is the 0-based index of the right choice; counts (optional) has one whole number ≥ 0 per choice",
85
+ ja: "choices は {\"label\": …} の並び(字の並びではない)。answer は正しい選択肢の番号(0 から数える)。counts(省略可)は選択肢ごとに 0 以上の整数を 1 つずつ"},
86
+ };
87
+ static props = {
88
+ "answer-step": {type: "number", default: 2, doc: "2 以上(既定 2)。人数を数えるステップ 1 のあとに答えを開く"},
89
+ unit: {type: "string", default: "", doc: "数の単位(人 など)"},
90
+ poll: {type: "string", default: "", doc: "live の投票の id(live 拡張のある再生で、見せてよいと決まった集計を棒に出す)"},
91
+ ticks: {type: "bool", default: true, doc: "数の軸の目盛りと格子"},
92
+ };
93
+ get aStep(){ return Math.max(1, Math.round(this.props["answer-step"]) || 2); }
94
+ get steps(){ return this.getAttribute("steps") !== null ? +this.getAttribute("steps") : this.aStep; }
95
+ // 作者の数(counts。書かなければ全部 0)
96
+ get author(){
97
+ var d = this.data || {}, n = (d.choices || []).length;
98
+ // 9999 まで(−1・+1 と数の欄が扱う数の上限。mount で知らせる)
99
+ return Array.from({length: n}, function(_, i){ var v = d.counts && d.counts[i]; return Number.isInteger(v) && v > 0 ? Math.min(9999, v) : 0; });
100
+ }
101
+ mount(ctx){
102
+ var self = this, d = this.data || {}, n = (d.choices || []).length;
103
+ this.T = /^ja\b/i.test(ctx.lang || "") ? TEXT.ja : TEXT.en;
104
+ if (!(d.answer >= 0 && d.answer < n)) throw new Error("answer " + d.answer + " is not a choice index (0–" + (n - 1) + ")");
105
+ if (d.counts && d.counts.length !== n) throw new Error("counts has " + d.counts.length + " numbers for " + n + " choices");
106
+ if (d.counts && d.counts.some(function(v){ return v < 0; })) throw new Error("counts must be 0 or more");
107
+ var big = (d.counts || []).filter(function(v){ return v > 9999; });
108
+ if (big.length) ctx.report("data", "[predict] counts " + big.join(", ") + " are more than 9999, the most the −1/+1 buttons and the field take; 9999 is shown");
109
+ this.variant = base.variant(this);
110
+ this.video = ctx.mode === "video";
111
+ this.style.display = "block"; this.style.position = "relative";
112
+ if (!document.getElementById(CSS_ID)){ var st = document.createElement("style"); st.id = CSS_ID; st.textContent = CSS; document.head.appendChild(st); }
113
+ // 読み上げソフトへの知らせ
114
+ this.say = document.createElement("div"); this.say.className = "pd-say"; this.say.setAttribute("role", "status"); this.say.setAttribute("aria-live", "polite");
115
+ this.appendChild(this.say);
116
+ if (d.question) this.setAttribute("aria-label", d.question);
117
+ // 印刷は作者の値で描く(画面の数は消さない。afterprint で戻す)。beforeprint・afterprint は文書の窓(document.defaultView)に来る
118
+ var view = document.defaultView;
119
+ if (!this.video && view){
120
+ view.addEventListener("beforeprint", function(){ self._printing = true; self.redraw(); });
121
+ view.addEventListener("afterprint", function(){ self._printing = false; self.redraw(); });
122
+ }
123
+ this.place(ctx);
124
+ }
125
+ // 配置が変わった知らせ(仕様 §8.4 layout):要素の大きさが mount のときと変わったときだけ置き直す(変換で縮めるだけなら呼ばれない。
126
+ // 横に並んだ文の字が後から読み込まれて、段組みの中の幅が変わるときなど)。大きさ 0(隠れている)なら前の配置のまま
127
+ layout(ctx){
128
+ var W = this.clientWidth, H = this.clientHeight;
129
+ if (!W || !H || (W === this.g.W && H === this.g.H)) return;
130
+ // フォーカスが操作の中にあれば、作り直した同じ行・同じ場所の操作に戻す(字の読み込みや画面の切り替えで呼ばれても、キーボードや読み上げソフトで使う人に見えないように)
131
+ var a = document.activeElement, keep = null;
132
+ if (a && a !== this && this.contains(a)) this.rows.forEach(function(r, i){
133
+ if (a === r.pick) keep = {i: i, at: -1};
134
+ else if (r.ctl && r.ctl.contains(a)) keep = {i: i, at: Array.prototype.indexOf.call(r.ctl.children, a), sel: a === r.field ? [a.selectionStart, a.selectionEnd] : null};
135
+ });
136
+ this.place(ctx);
137
+ this.redraw();
138
+ var r = keep && this.rows[keep.i], e = r && (keep.at < 0 ? r.pick : r.ctl && r.ctl.children[keep.at]);
139
+ if (e){
140
+ e.focus({preventScroll: true});
141
+ if (keep.sel && keep.sel[0] != null) try { e.setSelectionRange(keep.sel[0], keep.sel[1]); } catch (x) {}
142
+ }
143
+ }
144
+ // 大きさで決まる絵と操作を作る。数と予想(見る人の入力)・読み上げの知らせは残す(フォーカスは layout が戻す)
145
+ place(ctx){
146
+ var self = this, P = this.props, D = base, d = this.data || {}, ch = d.choices || [], n = ch.length, T = this.T;
147
+ var correctLabel = (d.labels && d.labels.correct) || T.correct;
148
+ var W = this.clientWidth, H = this.clientHeight, inter = !this.video;
149
+ if (this.svg){
150
+ this.svg.remove();
151
+ this.rows.forEach(function(r){ if (r.pick) r.pick.remove(); if (r.ctl) r.ctl.remove(); });
152
+ }
153
+ // 字の幅(base の textWidth:テーマの字で測った幅。mk:mtext で書く字で、*_^ は数えない)
154
+ var est = function(s, size, mk){ return D.textWidth(s, size, {font: self, mark: !!mk}); };
155
+ // 縦:問い・行・目盛り・注(と予想の当たり外れ)
156
+ var qh = d.question ? 54 : 0, nh = d.note || inter ? 50 : 0, tb = P.ticks ? 40 : 8;
157
+ var rh = Math.min(88, (H - qh - nh - tb) / n);
158
+ if (inter && rh < 54) ctx.report("size", "[predict] rows are " + rh.toFixed(0) + " px high; the −1/+1 buttons need 54 (make the element taller or use fewer choices)");
159
+ // 横:予想の印・選択肢の名前・棒・数と「正解」・操作
160
+ var mk = inter ? 40 : 0, LS = 26;
161
+ var lw = Math.min(W * 0.34, Math.max.apply(null, ch.map(function(c){ return est(c.label, LS, true); })) + 16);
162
+ var cw = inter ? 232 : 0;
163
+ var valW = est("9999" + P.unit, 26) + 12, okW = est(correctLabel, 26) + 16;
164
+ // 棒の軸の長さ:選択肢の名前・数・「正解」・操作の残り。BARMIN px より短ければ知らせ、その長さは残す(負の長さで棒が消え、目盛りが重ならないように)
165
+ var x0 = mk + lw + 8, x1 = W - cw - valW - okW - 8, BARMIN = 120;
166
+ if (x1 < x0 + BARMIN){ ctx.report("size", "[predict] the element is " + W + " px wide; the bars get " + Math.round(x1 - x0) + " px, less than " + BARMIN + " (make it about " + Math.ceil(W + x0 + BARMIN - x1) + " px wide or shorten the labels)"); x1 = x0 + BARMIN; }
167
+ this.g = {W: W, H: H, qh: qh, nh: nh, rh: rh, mk: mk, lw: lw, cw: cw,
168
+ x0: x0, x1: x1, y0: qh, y1: qh + rh * n};
169
+ var G = this.g;
170
+ var svg = this.svg = D.el("svg", {viewBox: "0 0 " + W + " " + H, width: W, height: H, style: "display:block;overflow:visible"});
171
+ this.insertBefore(svg, this.say);
172
+ var fitText = function(el, s, max, size, what, mk){
173
+ var z = size;
174
+ while (z > 24 && est(s, z, mk) > max) z--;
175
+ if (est(s, z, mk) > max) ctx.report("size", "[predict] the " + what + " does not fit (" + Math.ceil(est(s, z, mk) - max) + " px too wide at 24 px); shorten it");
176
+ el.setAttribute("font-size", z);
177
+ return el;
178
+ };
179
+ if (d.question) fitText(D.mtext(svg, 0, 36, d.question, {"font-size": 30, "font-weight": 700}), d.question, W - 8, 30, "question", true);
180
+ // 答えの枠(行の後ろ)
181
+ this.frame = D.el("rect", {x: 2, y: 0, width: Math.max(0, W - cw - 12), height: rh - 8, rx: 10, fill: "none", stroke: "var(--emph)", "stroke-width": 3, opacity: 0}, svg);
182
+ this.frameLen = 2 * (W - cw - 12 + rh - 8);
183
+ // 目盛り(数の軸の上限は数で決まるので、render で置き直す。入れ物は先に作る)
184
+ var gT = D.el("g", {}, svg);
185
+ this.ticks = !P.ticks ? [] : Array.from({length: 8}, function(){
186
+ return {grid: D.el("line", {stroke: "var(--line)", "stroke-width": 1.2, y1: G.y0 + 4, y2: G.y1}, gT),
187
+ text: D.el("text", {"font-size": 24, "text-anchor": "middle", y: G.y1 + 30, style: "font-variant-numeric:tabular-nums"}, gT)};
188
+ });
189
+ if (P.ticks){ var z = D.el("text", {"font-size": 24, "text-anchor": "middle", x: G.x0, y: G.y1 + 30}, gT); z.textContent = "0"; }
190
+ D.el("line", {x1: G.x0, y1: G.y0 + 4, x2: G.x0, y2: G.y1, stroke: "var(--fg)", "stroke-width": 1.5}, svg);
191
+ var bw = Math.min(46, rh * 0.56);
192
+ this.rows = ch.map(function(c, i){
193
+ var cy = G.y0 + rh * (i + 0.5), col = tone(c.tone);
194
+ var r = {cy: cy, col: col,
195
+ mark: inter ? D.el("circle", {cx: 16, cy: cy, r: 11, fill: "none", stroke: "var(--term)", "stroke-width": 2.5, "class": "pd-mark"}, svg) : null,
196
+ dot: inter ? D.el("circle", {cx: 16, cy: cy, r: 6, fill: "var(--term)", opacity: 0, "class": "pd-mark"}, svg) : null,
197
+ bar: D.el("rect", {x: G.x0, y: (cy - bw / 2).toFixed(1), height: bw.toFixed(1), rx: 3, fill: col, opacity: 0}, svg),
198
+ label: fitText(D.mtext(svg, mk + lw, cy + 9, c.label, {"text-anchor": "end", "font-size": LS}), c.label, lw - 8, LS, "label " + JSON.stringify(c.label), true),
199
+ val: D.el("text", {"font-size": 26, "font-weight": 700, y: (cy + 9).toFixed(1), opacity: 0, style: "font-variant-numeric:tabular-nums"}, svg)};
200
+ if (i === d.answer) r.ok = D.el("text", {"font-size": 26, "font-weight": 700, y: (cy + 9).toFixed(1), fill: "var(--emph)", opacity: 0}, svg);
201
+ if (r.ok) r.ok.textContent = correctLabel;
202
+ return r;
203
+ });
204
+ this.bw = bw;
205
+ // 注(答えと一緒に)と、予想の当たり外れ(見る人が予想したときだけ)
206
+ this.noteEl = D.el("text", {x: 0, y: H - 14, "font-size": 26, opacity: 0}, svg);
207
+ this.noteText = d.note || "";
208
+ if (d.note){ var notePrefix = est(T.noteWrong, 26) >= est(T.noteRight, 26) ? T.noteWrong : T.noteRight; fitText(this.noteEl, notePrefix + d.note, W - 8, 26, "note"); }
209
+ // live の集計の見出し(集計を出すときだけ)
210
+ this.liveEl = D.el("text", {x: W, y: G.y1 + 30, "font-size": 24, "text-anchor": "end", opacity: 0, "class": "pd-live"}, svg);
211
+ this.liveEl.textContent = T.liveResults;
212
+ // 操作:選択肢の名前(自分の予想)、−1・数の欄・+1。動画では作らない
213
+ if (inter){
214
+ var mkEl = function(tag, cls, attrs){ var e = document.createElement(tag); e.className = cls; for (var a in attrs) e.setAttribute(a, attrs[a]); self.appendChild(e); return e; };
215
+ var unit = P.unit;
216
+ this.rows.forEach(function(r, i){
217
+ var top = r.cy - 24;
218
+ r.pick = mkEl("button", "pd-pick", {type: "button", "aria-pressed": "false", "aria-label": T.guessLabel(ch[i].label)});
219
+ Object.assign(r.pick.style, {left: "0px", top: (r.cy - rh / 2 + 4) + "px", width: (mk + lw) + "px", height: (rh - 8) + "px"});
220
+ r.pick.addEventListener("click", function(e){ e.stopPropagation(); self.choose(i); });
221
+ var ctl = r.ctl = mkEl("div", "pd-ctl", {role: "group", "aria-label": T.countGroup(ch[i].label)});
222
+ Object.assign(ctl.style, {left: (W - cw + 16) + "px", top: top + "px"});
223
+ var bt = function(txt, dlt, ariaLabel){
224
+ var b = document.createElement("button"); b.type = "button"; b.className = "pd-btn"; b.textContent = txt; b.setAttribute("aria-label", ariaLabel);
225
+ b.addEventListener("click", function(e){ e.stopPropagation(); self.bump(i, dlt); });
226
+ b.addEventListener("keydown", function(e){ self.key(e, i, false); });
227
+ return b;
228
+ };
229
+ ctl.appendChild(bt("−1", -1, T.decrease(ch[i].label)));
230
+ var f = r.field = document.createElement("input");
231
+ f.type = "text"; f.className = "pd-num"; f.setAttribute("inputmode", "numeric"); f.setAttribute("autocomplete", "off");
232
+ f.setAttribute("aria-label", T.countField(ch[i].label, unit));
233
+ f.addEventListener("keydown", function(e){ self.key(e, i, true); });
234
+ f.addEventListener("input", function(){
235
+ var s = f.value.replace(/[^0-9]/g, "").slice(0, 4);
236
+ if (s !== f.value) f.value = s;
237
+ self.set(i, s === "" ? 0 : +s);
238
+ });
239
+ f.addEventListener("change", function(){ f.value = String(self.counts()[i]); });
240
+ ctl.appendChild(f);
241
+ ctl.appendChild(bt("+1", 1, T.increase(ch[i].label)));
242
+ });
243
+ }
244
+ function tone(t){ return /^(term|emph|muted|accent2|fg|series-[1-4])$/.test(t || "") ? "var(--" + t + ")" : "var(--term)"; }
245
+ }
246
+ // ---- 見る人の状態((i, k, t) の外)
247
+ // 今の数(見る人が変えていればその値、そうでなければ作者の値)。新しい配列を返す
248
+ counts(){ return (this._vc || this.author).slice(); }
249
+ // 発表者の画面から(Studio が呼ぶ):choice は 0 から数える選択肢の番号、count は新しい数(0 以上の整数)
250
+ input(choice, count){
251
+ if (this.video) return;
252
+ var n = this.author.length;
253
+ if (!Number.isInteger(choice) || choice < 0 || choice >= n || !Number.isInteger(count) || count < 0 || count > 9999){
254
+ console.warn("[predict] input(" + JSON.stringify(choice) + ", " + JSON.stringify(count) + ") ignored (choice 0–" + (n - 1) + ", count a whole number 0–9999)");
255
+ return;
256
+ }
257
+ this.set(choice, count);
258
+ }
259
+ bump(i, dl){ this.set(i, this.counts()[i] + dl); }
260
+ set(i, v){
261
+ if (this.video || !this.rows) return;
262
+ v = Math.max(0, Math.min(9999, v));
263
+ var c = this.counts();
264
+ if (c[i] === v) return;
265
+ c[i] = v; this._vc = c;
266
+ this.redraw();
267
+ this.say.textContent = this.T.countAnnounce(this.data.choices[i].label, v, this.props.unit);
268
+ this.emit();
269
+ }
270
+ // 自分の予想(1 つ。もう一度押すと外す)
271
+ choose(i){
272
+ if (this.video) return;
273
+ var d = this.data, T = this.T;
274
+ this._pick = this._pick === i ? null : i;
275
+ this.redraw();
276
+ var lab = d.choices[i].label;
277
+ this.say.textContent = this._pick === null ? T.unpicked : this.revealed() ? (i === d.answer ? T.pickedRight(lab) : T.pickedWrong(d.choices[d.answer].label)) : T.myGuess(lab);
278
+ }
279
+ revealed(){ return this._k !== undefined && this._k >= this.aStep; }
280
+ key(e, i, field){
281
+ var k = e.key, up = k === "+" || k === "ArrowUp" || (!field && k === "ArrowRight"), dn = k === "-" || k === "−" || k === "ArrowDown" || (!field && k === "ArrowLeft");
282
+ if (up || dn){ e.preventDefault(); e.stopPropagation(); this.bump(i, up ? 1 : -1); return; }
283
+ if (field){
284
+ // 欄の中のキー(数字・矢印・Space など)はスライドを動かさない。Esc で欄を出る
285
+ e.stopPropagation();
286
+ if (k === "Escape" || k === "Enter") e.target.blur();
287
+ }
288
+ }
289
+ emit(){ this.dispatchEvent(new CustomEvent("egatari-input", {bubbles: true, detail: {counts: this.counts()}})); }
290
+ // 見る人の状態を捨てて作者の値に戻す。数を変えていたら知らせる
291
+ reset(){
292
+ var had = !!this._vc;
293
+ if (!had && this._pick == null) return false;
294
+ this._vc = null; this._pick = null;
295
+ if (had) this.emit();
296
+ return true;
297
+ }
298
+ // 触った跡だけを戻す(ctx.reset):部品の中のフォーカスを外す(欄は今の数を出し直す)。数と予想(見る人の入力)は残す
299
+ untouch(){
300
+ var a = document.activeElement;
301
+ if (a && a !== this && this.contains(a) && a.blur) a.blur();
302
+ }
303
+ // 入力のあとの描き直し:最後の (k, t) で paint だけを呼ぶ(render を通さないので、ctx.entered・ctx.reset を繰り返さない)
304
+ redraw(){ if (this._k !== undefined) this.paint(this._k, this._t, this._ctx); }
305
+ duration(k){
306
+ var a = this.aStep, d = 0;
307
+ if (k === 1) d = 0.6;
308
+ if (k === a) d += 0.6;
309
+ return d;
310
+ }
311
+ render(k, t, ctx){
312
+ // ほかのスライドから入ったとき・飛んだとき(ctx.entered)だけ、見る人の状態を捨てる。同じスライドの中の段階の移りでは残す。
313
+ // ctx.reset(触った部品が段階に入るとき)は触った跡だけを戻し、見る人の入力は消さない(仕様 §8.4)
314
+ if (ctx.entered === true) this.reset();
315
+ if (ctx.reset) this.untouch();
316
+ this._k = k; this._t = t; this._ctx = {mode: ctx.mode, preview: ctx.preview, live: ctx.live};
317
+ this.paint(k, t, this._ctx);
318
+ }
319
+ // (k, t) と見る人の状態の絵。ctx は {mode, preview, live}
320
+ paint(k, t, ctx){
321
+ var self = this, P = this.props, D = base, G = this.g, dd = this.data, n = this.rows.length, vr = this.variant, T = this.T;
322
+ var a = this.aStep;
323
+ // 数:live の集計(実行系が見せてよいと渡したときだけ)→ 見る人の数 → 作者の数
324
+ var live = null;
325
+ if (P.poll && ctx && ctx.live && typeof ctx.live.poll === "function" && !this.video && !this._printing){
326
+ var lv = ctx.live.poll(P.poll);
327
+ if (Array.isArray(lv)) live = Array.from({length: n}, function(_, i){ var v = +lv[i]; return isFinite(v) && v > 0 ? Math.round(v) : 0; });
328
+ }
329
+ var c = live || (this._printing ? this.author : this.counts()), pick = this._printing ? null : this._pick;
330
+ // 段階 1 の棒(draw は上から順に、同じ長さの中で)、答えの段階
331
+ // 先の段階は授業の表示(ctx.preview)でも見せない:予想する前に棒や答えが見えてはいけない(static preview = "none")
332
+ var e1 = k > 1 ? 1 : k < 1 ? 0 : null;
333
+ var at1 = 0, ea = k > a ? 1 : k < a ? 0 : D.prog(t, a === 1 ? 0.6 : 0, 0.6);
334
+ var rowE = function(j){
335
+ if (e1 !== null) return e1;
336
+ if (vr === "draw"){ var s = n > 1 ? 0.3 / (n - 1) : 0; return D.prog(t, at1 + j * s, 0.3); }
337
+ return D.prog(t, at1, 0.6);
338
+ };
339
+ // 数の軸
340
+ var M = nice(Math.max(4, Math.max.apply(null, c)) * 1.12), len = G.x1 - G.x0, X = function(v){ return G.x0 + Math.min(v, M) / M * len; };
341
+ var ts = Math.max(1, tickStep(M)), ti = 0;
342
+ // 短い軸では目盛りの数が重ならない間隔まで広げる(数の幅+16 px)
343
+ while (ts < M && len * ts / M < est(String(Math.ceil(M)), 24) + 16) ts = up(ts);
344
+ this.ticks.forEach(function(o, j){
345
+ var v = (j + 1) * ts, on = v <= M + 1e-9;
346
+ o.grid.setAttribute("x1", X(v).toFixed(1)); o.grid.setAttribute("x2", X(v).toFixed(1));
347
+ o.text.setAttribute("x", X(v).toFixed(1)); o.text.textContent = on ? String(v) : "";
348
+ o.grid.setAttribute("opacity", on ? 0.8 : 0); o.text.setAttribute("opacity", on ? 1 : 0);
349
+ });
350
+ var shown = ea > 0.5;
351
+ this.rows.forEach(function(r, j){
352
+ var e = rowE(j), isA = j === dd.answer, dim = isA ? 1 : 1 - 0.65 * ea;
353
+ r.bar.setAttribute("width", Math.max(0, X(c[j]) - G.x0).toFixed(1));
354
+ r.bar.setAttribute("opacity", (e * dim).toFixed(3));
355
+ r.val.textContent = self.fmt(c[j]);
356
+ r.val.setAttribute("x", (X(c[j]) + 10).toFixed(1));
357
+ r.val.setAttribute("opacity", e.toFixed(3));
358
+ // 答えを開いたら、ほかの選択肢の字は --muted(読める濃さのまま)
359
+ var txt = !isA && shown ? "var(--muted)" : "var(--fg)";
360
+ r.val.style.fill = txt; r.label.style.fill = txt;
361
+ r.label.setAttribute("font-weight", isA && shown ? 700 : 400);
362
+ if (r.ok){ r.ok.setAttribute("x", (X(c[j]) + 10 + est(self.fmt(c[j]), 26) + 14).toFixed(1)); r.ok.setAttribute("opacity", ea.toFixed(3)); }
363
+ if (r.dot){ r.dot.setAttribute("opacity", pick === j ? 1 : 0); r.pick.setAttribute("aria-pressed", pick === j ? "true" : "false"); }
364
+ if (r.ctl){
365
+ r.ctl.style.display = k >= 1 && !live ? "" : "none";
366
+ if (document.activeElement !== r.field) r.field.value = String(c[j]);
367
+ }
368
+ });
369
+ // 答えの枠:fade はフェード、draw は線を引く(同じ長さ)
370
+ var fy = G.y0 + G.rh * dd.answer + 4;
371
+ this.frame.setAttribute("y", fy.toFixed(1));
372
+ if (vr === "draw" && ea > 0 && ea < 1){ this.frame.setAttribute("stroke-dasharray", this.frameLen.toFixed(0)); this.frame.setAttribute("stroke-dashoffset", (this.frameLen * (1 - ea)).toFixed(1)); this.frame.setAttribute("opacity", 1); }
373
+ else { this.frame.removeAttribute("stroke-dasharray"); this.frame.removeAttribute("stroke-dashoffset"); this.frame.setAttribute("opacity", ea.toFixed(3)); }
374
+ // 注と、予想の当たり外れ
375
+ var pk = pick, st = pk != null && k >= a ? (pk === dd.answer ? T.noteRight : T.noteWrong) : "";
376
+ this.noteEl.textContent = (k >= a ? st : "") + this.noteText;
377
+ this.noteEl.setAttribute("opacity", ea.toFixed(3));
378
+ this.liveEl.setAttribute("opacity", live && k >= 1 ? 1 : 0);
379
+ // 答えを開いた段階に入ったら知らせる(入力の知らせは set・choose が後から書く)
380
+ if (this._sayK !== k && !this.video){ this._sayK = k; this.say.textContent = k >= a ? T.answerAnnounce(dd.choices[dd.answer].label, this.noteText) : ""; }
381
+ function est(s, size){ return D.textWidth(s, size, {font: self}); }
382
+ function nice(v){ var e = Math.pow(10, Math.floor(Math.log10(v))), x = v / e;
383
+ return [1, 1.2, 1.5, 2, 2.5, 3, 4, 5, 6, 8, 10].filter(function(s){ return s >= x - 1e-9; })[0] * e; }
384
+ function up(v){ var e = Math.pow(10, Math.floor(Math.log10(v))); return Math.round([1, 2, 5, 10, 20].filter(function(s){ return s * e > v + 1e-9; })[0] * e); }
385
+ function tickStep(M){ var r = M / 4.5, e = Math.pow(10, Math.floor(Math.log10(r))), x = r / e;
386
+ return Math.round((x <= 1 ? 1 : x <= 2 ? 2 : x <= 2.5 ? 2.5 : x <= 5 ? 5 : 10) * e); }
387
+ }
388
+ fmt(v){ return String(v).replace(/\B(?=(\d{3})+(?!\d))/g, ",") + this.props.unit; }
389
+ };
390
+ });
@@ -0,0 +1,31 @@
1
+ ---
2
+ summary: Outcomes → values → distribution
3
+ steps: Outcomes → arrows → groups → bars (4)
4
+ props:
5
+ dur: Motion s
6
+ stagger: Arrow delay s
7
+ digits: Decimals
8
+ size: Text px
9
+ example: {"outcomes":[{"label":"HH","x":2},{"label":"HT","x":1},{"label":"TH","x":1},{"label":"TT","x":0}],"name":"X","unit":"","fractions":true}
10
+ ---
11
+ - `outcomes`: 2–12; `label`, `x`, `p` (default equal; sum ≠ 1 reported)
12
+ - `name` (X), `fractions`
13
+ - `picture`: `dots`, `grapes`, `dice`, `coins`, `balls` (colour names; 11 basic)
14
+
15
+ <!-- llm: omit -->
16
+ For introductory probability. Left: Ω; centre: values; right: distribution. Chips → arrows → shared colours, counts and sums → bars, end labels and total. Final state stands alone; no answer preview.
17
+
18
+ - `outcomes`: 2–12 items; short `label` (≤6 chars advised), finite `x`. Repeated values allowed. Input chip order; numerical axis increases upwards.
19
+ - `p`: optional. All omitted: `1/n`. Mixed: report `data`, missing = 0. Sum outside 1±1e-9 or p outside 0–1: report, retain values. No normalization.
20
+ - `name`: X; `unit`: suffix, default empty. Literal labels.
21
+ - `fractions`: defaults true for equal probabilities. Reduced fractions: denominator ≤10000, error ≤1e-9; otherwise `digits` decimals. Invalid totals stay unrounded.
22
+ - `picture`: draw outcomes: `dots`/`grapes` (x items, 0–15), `dice` (label face 1–6), `coins` (◯ heads, ● tails), `balls` (colour names per outcome `balls` or label characters; 11 basic colours; name shown)
23
+
24
+ Equal probabilities: shown once in the title. Colours cycle series-1..4 by ascending value. Bar scale includes 0–1; extends for invalid data.
25
+
26
+ About 1184×440px for 4 outcomes; rows ≥40px; tight space reports `size`.
27
+
28
+ Fictional grapes: X = berries per bunch.
29
+
30
+ Keep enough height for probabilities below chip labels.
31
+ <!-- llm: end -->