egatari 0.6.11 → 0.6.12

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 (135) hide show
  1. package/CHANGELOG.md +33 -1
  2. package/bin/egatari.mjs +4 -3
  3. package/components.lock.json +30 -15
  4. package/components2.lock.json +201 -1
  5. package/fonts/@fontsource/fraunces/400.css +29 -0
  6. package/fonts/@fontsource/fraunces/700.css +29 -0
  7. package/fonts/@fontsource/fraunces/LICENSE +93 -0
  8. package/fonts/@fontsource/fraunces/files/fraunces-latin-400-normal.woff2 +0 -0
  9. package/fonts/@fontsource/fraunces/files/fraunces-latin-700-normal.woff2 +0 -0
  10. package/fonts/@fontsource/fraunces/files/fraunces-latin-ext-400-normal.woff2 +0 -0
  11. package/fonts/@fontsource/fraunces/files/fraunces-latin-ext-700-normal.woff2 +0 -0
  12. package/fonts/@fontsource/fraunces/files/fraunces-vietnamese-400-normal.woff2 +0 -0
  13. package/fonts/@fontsource/fraunces/files/fraunces-vietnamese-700-normal.woff2 +0 -0
  14. package/fonts/@fontsource/fraunces/package.json +6 -0
  15. package/kit/check-messages.mjs +18 -7
  16. package/kit/check.mjs +12 -4
  17. package/kit/core/article-render.mjs +5 -5
  18. package/kit/core/build-core.mjs +25 -9
  19. package/kit/core/check-parity.mjs +1 -1
  20. package/kit/core/check-rules.mjs +2 -2
  21. package/kit/core/check-source.mjs +3 -0
  22. package/kit/core/colab-core.mjs +1 -1
  23. package/kit/core/kicker.mjs +42 -0
  24. package/kit/core/layout-scan.mjs +19 -7
  25. package/kit/core/llm-pack-data.mjs +8 -8
  26. package/kit/core/llm-pack.mjs +2 -2
  27. package/kit/core/theme-shapes.mjs +3 -1
  28. package/kit/core/themes-list.mjs +2 -0
  29. package/kit/instruction-version.json +1 -1
  30. package/kit/layouts.css +8 -0
  31. package/kit/player.json +1 -1
  32. package/kit/player.lock.json +2 -2
  33. package/package.json +2 -1
  34. package/themes/asagi/theme.json +1 -1
  35. package/themes/asagi/tokens.css +6 -0
  36. package/themes/bengara/theme.json +13 -0
  37. package/themes/bengara/tokens.css +66 -0
  38. package/themes/business/theme.json +1 -1
  39. package/themes/business/tokens.css +6 -0
  40. package/themes/default/theme.json +1 -1
  41. package/themes/default/tokens.css +9 -0
  42. package/themes/kogecha/theme.json +1 -1
  43. package/themes/kogecha/tokens.css +6 -0
  44. package/themes/kokugo/theme.json +1 -1
  45. package/themes/kokugo/tokens.css +6 -0
  46. package/themes/murasaki/theme.json +1 -1
  47. package/themes/murasaki/tokens.css +6 -0
  48. package/themes/sumi/theme.json +1 -1
  49. package/themes/sumi/tokens.css +8 -0
  50. package/themes/tokiwa/theme.json +1 -1
  51. package/themes/tokiwa/tokens.css +6 -0
  52. package/themes.lock.json +90 -24
  53. package/vendor/components/CATALOG.md +11 -11
  54. package/vendor/components/sha256/04626b77b3c683fd4c8e549339eca153615e021eb0e649c31291deb2dab30667/README.en.md +38 -0
  55. package/vendor/components/sha256/04626b77b3c683fd4c8e549339eca153615e021eb0e649c31291deb2dab30667/index.js +289 -0
  56. package/vendor/components/sha256/0c4eb83646ab8027d40697db161eb952425db78c42b36291626214d5064b9498/fixtures/ABCJS-ADAPTER.md +101 -0
  57. package/vendor/components/sha256/0c4eb83646ab8027d40697db161eb952425db78c42b36291626214d5064b9498/fixtures/LICENSE-abcjs.txt +21 -0
  58. package/vendor/components/sha256/0c4eb83646ab8027d40697db161eb952425db78c42b36291626214d5064b9498/fixtures/chords.json +89 -0
  59. package/vendor/components/sha256/0c4eb83646ab8027d40697db161eb952425db78c42b36291626214d5064b9498/fixtures/doremi.json +261 -0
  60. package/vendor/components/sha256/0c4eb83646ab8027d40697db161eb952425db78c42b36291626214d5064b9498/fixtures/extras.json +192 -0
  61. package/vendor/components/sha256/0c4eb83646ab8027d40697db161eb952425db78c42b36291626214d5064b9498/fixtures/kaeru.json +521 -0
  62. package/vendor/components/sha256/0c4eb83646ab8027d40697db161eb952425db78c42b36291626214d5064b9498/fixtures/rhythm.json +248 -0
  63. package/vendor/components/sha256/0c4eb83646ab8027d40697db161eb952425db78c42b36291626214d5064b9498/fixtures/ties.json +360 -0
  64. package/vendor/components/sha256/0c4eb83646ab8027d40697db161eb952425db78c42b36291626214d5064b9498/index.js +508 -0
  65. package/vendor/components/sha256/0dc2a0945e7a4004278fcc9b8f02223bbb87f6269bffe3dd3ebeb3a78ce23d34/index.js +404 -0
  66. package/vendor/components/sha256/0e2e45b024bb2f37e82c83a4d9cd9f9c16b5dc4924dde81735c268a3d49f9d7f/index.js +97 -0
  67. package/vendor/components/sha256/0ef62e33d330f8e31ccb1f480b5e3b349769a142cc2737a9e6583d5eff9f56ca/index.js +919 -0
  68. package/vendor/components/sha256/1b33a252d51091e2d8cdea176f10268f128640bed3aa46da88d7de31ced59b44/README.en.md +48 -0
  69. package/vendor/components/sha256/1b33a252d51091e2d8cdea176f10268f128640bed3aa46da88d7de31ced59b44/index.js +384 -0
  70. package/vendor/components/sha256/1b767b6cf1855156872f87981a7c99f0161013499d6c4b21785624435db92078/README.en.md +34 -0
  71. package/vendor/components/sha256/1b767b6cf1855156872f87981a7c99f0161013499d6c4b21785624435db92078/index.js +244 -0
  72. package/vendor/components/sha256/3ace61e46a4555eab46ca8053db2fb76a874d4d5409bc5891cc449f43ef7e0bd/README.en.md +44 -0
  73. package/vendor/components/sha256/3ace61e46a4555eab46ca8053db2fb76a874d4d5409bc5891cc449f43ef7e0bd/index.js +304 -0
  74. package/vendor/components/sha256/4079077e03343995edc5e34b8bda0cf200dc6d854a52486fe0a6a4ceaf0d4b6f/README.en.md +44 -0
  75. package/vendor/components/sha256/4079077e03343995edc5e34b8bda0cf200dc6d854a52486fe0a6a4ceaf0d4b6f/index.js +203 -0
  76. package/vendor/components/sha256/40aaaaf988e7c32460ffaf5f18b5690ee28fd1fe7e879d8434d58283992bc554/README.en.md +37 -0
  77. package/vendor/components/sha256/40aaaaf988e7c32460ffaf5f18b5690ee28fd1fe7e879d8434d58283992bc554/index.js +438 -0
  78. package/vendor/components/sha256/442be174439d106ef462c19d598c407e86d5de3fcd4700ed54ae4147c4b9969c/README.en.md +24 -0
  79. package/vendor/components/sha256/442be174439d106ef462c19d598c407e86d5de3fcd4700ed54ae4147c4b9969c/index.js +103 -0
  80. package/vendor/components/sha256/48a776e7683e1aba8cad5aa4067914c017681efaa74f175066e0ab081bf3d013/index.js +351 -0
  81. package/vendor/components/sha256/4a9331635c2dd28e4b46108eaffe49c6d29cf626ecb900ac6e9029552be0cf49/index.js +607 -0
  82. package/vendor/components/sha256/5458baef7a30298cf4b0029331f13233d162403e686f9c20085dd2104cad7141/README.en.md +23 -0
  83. package/vendor/components/sha256/5458baef7a30298cf4b0029331f13233d162403e686f9c20085dd2104cad7141/index.js +120 -0
  84. package/vendor/components/sha256/586063d3a4e24e2995923811b2b9466bde86dbaafb3bcf103546d3f28159205a/index.js +812 -0
  85. package/vendor/components/sha256/5acc5f87e29f1170bc35dbee08087d0d03c1023969c6c1b1367a0f559d60e5ee/index.js +198 -0
  86. package/vendor/components/sha256/5c032594230fe688f661b6ccf27070c84f8c0e38611186280fb9c56d89ac3319/README.en.md +32 -0
  87. package/vendor/components/sha256/5c032594230fe688f661b6ccf27070c84f8c0e38611186280fb9c56d89ac3319/index.js +222 -0
  88. package/vendor/components/sha256/603de10f0ee50d07ec610e21b45b9db78d69376b4dfd2baba78595c1002e27ec/README.en.md +50 -0
  89. package/vendor/components/sha256/603de10f0ee50d07ec610e21b45b9db78d69376b4dfd2baba78595c1002e27ec/index.js +171 -0
  90. package/vendor/components/sha256/609e45a826d07a54cbbcbf4ce2ad6b5474dca1d0be394eb9fad895db4a73422f/README.en.md +51 -0
  91. package/vendor/components/sha256/609e45a826d07a54cbbcbf4ce2ad6b5474dca1d0be394eb9fad895db4a73422f/index.js +228 -0
  92. package/vendor/components/sha256/6364043cb31bbd86aacb7432af1a8affef8cae5c6efdbe13fbebd116fd51b91f/index.js +233 -0
  93. package/vendor/components/sha256/6f9f7283226d3534aa1cb4a47ba258204aa286ead01b25cdbde14119260bc702/README.en.md +66 -0
  94. package/vendor/components/sha256/6f9f7283226d3534aa1cb4a47ba258204aa286ead01b25cdbde14119260bc702/index.js +920 -0
  95. package/vendor/components/sha256/72edfd6678b22be0bb3e32b0d8cb0dfee403767e1eacac354d278d7318d03826/README.en.md +35 -0
  96. package/vendor/components/sha256/72edfd6678b22be0bb3e32b0d8cb0dfee403767e1eacac354d278d7318d03826/index.js +179 -0
  97. package/vendor/components/sha256/7482c50bea5ef7d72dc5d4afaddb8c4e725b5a83fa0c6175f9a9c556f23a4e10/LICENSE-tabler.txt +21 -0
  98. package/vendor/components/sha256/7482c50bea5ef7d72dc5d4afaddb8c4e725b5a83fa0c6175f9a9c556f23a4e10/index.js +4868 -0
  99. package/vendor/components/sha256/7482c50bea5ef7d72dc5d4afaddb8c4e725b5a83fa0c6175f9a9c556f23a4e10/names.txt +4808 -0
  100. package/vendor/components/sha256/7cb8948c550b66bf4b34a62e7b61385aaa79896e09d82ccb1846c0ac499ad352/README.en.md +40 -0
  101. package/vendor/components/sha256/7cb8948c550b66bf4b34a62e7b61385aaa79896e09d82ccb1846c0ac499ad352/index.js +348 -0
  102. package/vendor/components/sha256/87cc60da38d209cda449dd7c24171e287ac8184c5036ca04548ef9e2015c2d9e/README.en.md +42 -0
  103. package/vendor/components/sha256/87cc60da38d209cda449dd7c24171e287ac8184c5036ca04548ef9e2015c2d9e/index.js +268 -0
  104. package/vendor/components/sha256/8cb367c71c002c689defddc6f075be911d5485421715119b5515181e962a2401/index.js +121 -0
  105. package/vendor/components/sha256/97bfd6e79c7278c55153bf4c2330da0432cf0ee312baa11650e07cdd7912831d/index.js +354 -0
  106. package/vendor/components/sha256/a426e6a3f8f4593403ba63ecc4a3f1f41064f4016fd9fb8d51e7876bf8c6f573/README.en.md +40 -0
  107. package/vendor/components/sha256/a426e6a3f8f4593403ba63ecc4a3f1f41064f4016fd9fb8d51e7876bf8c6f573/index.js +348 -0
  108. package/vendor/components/sha256/c108119117042cacc65a35ec73fcab95a2a92b2a2797129f66e326783f8db178/index.js +465 -0
  109. package/vendor/components/sha256/c3fad2047cec6a2bd8a5b907f752e2addeeea2f373fd8115914552dcee0b2f6f/README.en.md +23 -0
  110. package/vendor/components/sha256/c3fad2047cec6a2bd8a5b907f752e2addeeea2f373fd8115914552dcee0b2f6f/index.js +289 -0
  111. package/vendor/components/sha256/c59f1ac3132fdf6f56e8880c866570cd7443f09eb8802b6e7af32675ad358edf/README.en.md +31 -0
  112. package/vendor/components/sha256/c59f1ac3132fdf6f56e8880c866570cd7443f09eb8802b6e7af32675ad358edf/index.js +236 -0
  113. package/vendor/components/sha256/d3a75f67160490db1831aaa8ac58ebc5f7ffb6a6fd21e2bdeaa6fe979bfaff7f/README.en.md +42 -0
  114. package/vendor/components/sha256/d3a75f67160490db1831aaa8ac58ebc5f7ffb6a6fd21e2bdeaa6fe979bfaff7f/index.js +488 -0
  115. package/vendor/components/sha256/d998b5db828427505e39cdae67676dc6480c791d6037152dec222ae81cdbba1f/index.js +484 -0
  116. package/vendor/components/sha256/ea17602aaecca64b672b3bc827965ff378cb460250177f7b66f73081a48d4e81/index.js +278 -0
  117. package/vendor/components/sha256/f9cef6dd9580a4f19aa09d47f736ab2391f5f585b20b16a62bd781398cb6b8ac/README.en.md +22 -0
  118. package/vendor/components/sha256/f9cef6dd9580a4f19aa09d47f736ab2391f5f585b20b16a62bd781398cb6b8ac/index.js +145 -0
  119. package/vendor/components-2/manifest-2.8.0.json +2199 -0
  120. package/vendor/themes/asagi/1.2.0/theme.json +14 -0
  121. package/vendor/themes/asagi/1.2.0/tokens.css +30 -0
  122. package/vendor/themes/business/1.2.0/theme.json +5 -0
  123. package/vendor/themes/business/1.2.0/tokens.css +41 -0
  124. package/vendor/themes/default/1.4.0/theme.json +4 -0
  125. package/vendor/themes/default/1.4.0/tokens.css +86 -0
  126. package/vendor/themes/kogecha/1.2.0/theme.json +10 -0
  127. package/vendor/themes/kogecha/1.2.0/tokens.css +29 -0
  128. package/vendor/themes/kokugo/1.2.0/theme.json +5 -0
  129. package/vendor/themes/kokugo/1.2.0/tokens.css +25 -0
  130. package/vendor/themes/murasaki/1.2.0/theme.json +10 -0
  131. package/vendor/themes/murasaki/1.2.0/tokens.css +25 -0
  132. package/vendor/themes/sumi/1.2.0/theme.json +10 -0
  133. package/vendor/themes/sumi/1.2.0/tokens.css +49 -0
  134. package/vendor/themes/tokiwa/1.2.0/theme.json +10 -0
  135. package/vendor/themes/tokiwa/1.2.0/tokens.css +27 -0
@@ -0,0 +1,289 @@
1
+ // m-sampling: population → sample → simulated sampling distribution.
2
+ egatariParts.define({name: "sampling", version: "2.0.1", requires: {base: "1.2.0", plot: "1.1.2"}, element: "m-sampling"}, function(deps){
3
+ "use strict";
4
+ var base = deps.base;
5
+ var TEXT = {
6
+ ja: {population: "母集団", sample: "標本", distribution: "標本分布", with: "戻す(復元抽出)", without: "戻さない(非復元抽出)", mean: "平均", proportion: "の割合", meanAxis: "標本平均", proportionAxis: "標本比率", statsMean: "標本統計量の平均", caption: function(n, r){ return "n = " + n + "、" + r + " 回"; }},
7
+ en: {population: "population", sample: "Sample", distribution: "Sampling distribution", with: "with replacement", without: "without replacement", mean: "Mean", proportion: " proportion", meanAxis: "Sample mean", proportionAxis: "Sample proportion", statsMean: "mean of sample statistics", caption: function(n, r){ return "n = " + n + ", " + r + " samples"; }}
8
+ };
9
+ var OBJ = {white: "#ffffff", black: "#222222", red: "#d62728", green: "#2ca02c", yellow: "#f2c12e", blue: "#1f77b4", brown: "#8c564b", purple: "#9467bd", pink: "#e377c2", orange: "#ff7f0e", gray: "#7f7f7f"};
10
+ var OBJ_NAME = {"白": "white", "黒": "black", "赤": "red", "緑": "green", "黄": "yellow", "青": "blue", "茶": "brown", "紫": "purple", "桃": "pink", "橙": "orange", "灰": "gray",
11
+ "白色": "white", "黒色": "black", "赤色": "red", "緑色": "green", "黄色": "yellow", "青色": "blue", "茶色": "brown", "紫色": "purple", "桃色": "pink", "橙色": "orange", "灰色": "gray", "ピンク": "pink", "オレンジ": "orange", "グレー": "gray", "grey": "gray"};
12
+ function objColor(name){
13
+ var k = String(name).trim(), lower = k.toLowerCase(), own = Object.prototype.hasOwnProperty;
14
+ var en = own.call(OBJ, lower) ? lower : own.call(OBJ_NAME, k) ? OBJ_NAME[k] : own.call(OBJ_NAME, lower) ? OBJ_NAME[lower] : null;
15
+ return en ? "var(--obj-" + en + ", " + OBJ[en] + ")" : null;
16
+ }
17
+ // Mulberry32; the only mutable random state lives in mount's local generator.
18
+ function random(seed){
19
+ return function(){
20
+ seed = (seed + 0x6D2B79F5) | 0;
21
+ var z = Math.imul(seed ^ seed >>> 15, 1 | seed);
22
+ z ^= z + Math.imul(z ^ z >>> 7, 61 | z);
23
+ return ((z ^ z >>> 14) >>> 0) / 4294967296;
24
+ };
25
+ }
26
+ function set(e, a, v){ e.setAttribute(a, String(v)); }
27
+ function mean(values){
28
+ var scale = Math.max.apply(null, values.map(function(v){ return Math.abs(v); }).concat([1]));
29
+ var average = values.reduce(function(s, v){ return s + v / scale; }, 0) / values.length;
30
+ return Math.max(-1, Math.min(1, average)) * scale;
31
+ }
32
+ function meanTicks(lo, hi, values){
33
+ if (lo === hi) return [lo];
34
+ if (hi - lo <= 10 && values.every(Number.isInteger)) return Array.from({length: hi - lo + 1}, function(_, i){ return lo + i; });
35
+ var scale = Math.max(1, Math.abs(lo), Math.abs(hi));
36
+ var rough = Math.max(Number.MIN_VALUE, (hi / scale - lo / scale) / 4 * scale);
37
+ var power = Math.pow(10, Math.floor(Math.log10(rough))) || Number.MIN_VALUE, fraction = rough / power;
38
+ var step = (fraction <= 1 ? 1 : fraction <= 2 ? 2 : fraction <= 5 ? 5 : 10) * power;
39
+ var start = Math.ceil(lo / step), ticks = [];
40
+ for (var i = 0; i < 10; i++){
41
+ var v = (start + i) * step;
42
+ if (!Number.isFinite(v) || v > hi + step * 1e-10) break;
43
+ ticks.push(v);
44
+ }
45
+ return ticks;
46
+ }
47
+ return class extends base.MotionElement {
48
+ static partName = "sampling";
49
+ static preview = "none";
50
+ static steps = 4;
51
+ static shape = {
52
+ schema: {type: "object", additionalProperties: false, required: ["n"], anyOf: [{required: ["balls"]}, {required: ["values"]}], properties: {
53
+ balls: {type: "object"}, values: {type: "array", minItems: 2, maxItems: 30, items: {type: "number"}},
54
+ of: {type: "string"}, n: {type: "number"}, replace: {type: "boolean"}, repeat: {type: "number"}, seed: {type: "number"},
55
+ stat: {enum: ["mean", "proportion"]}, digits: {type: "number"}
56
+ }},
57
+ example: {values: [1, 2, 3, 4, 5, 6], n: 2, replace: true, repeat: 40, seed: 3}
58
+ };
59
+ static props = {
60
+ dur: {type: "number", default: 1, doc: "ステップの秒数"},
61
+ stagger: {type: "number", default: 0.25, doc: "抽出のずれ(秒)"},
62
+ fast: {type: "number", default: 2.5, doc: "反復の秒数"},
63
+ size: {type: "number", default: 0, doc: "文字 px(0 は 26)"}
64
+ };
65
+ timing(name, fallback, zero){ var v = this.props[name]; return Number.isFinite(v) && (zero ? v >= 0 : v > 0) ? v : fallback; }
66
+ duration(k){
67
+ if (k < 1 || k > 4) return 0;
68
+ if (k === 4) return this.timing("fast", 2.5);
69
+ var n = this.model ? this.model.n : Math.max(1, Math.min(30, Math.round(this.data.n)));
70
+ return this.timing("dur", 1) + (k === 2 ? (n - 1) * this.timing("stagger", 0.25, true) : 0);
71
+ }
72
+ fmt(v){ return v.toFixed(this.model.digits); }
73
+ label(g, x, y, s, anchor){
74
+ var t = base.el("text", {x: x, y: y, "font-size": this.fs, "text-anchor": anchor || "start", fill: "var(--fg)"}, g);
75
+ t.textContent = s; return t;
76
+ }
77
+ mount(ctx){
78
+ var self = this, d = this.data, P = this.props;
79
+ this.T = /^ja\b/i.test(ctx.lang || "") ? TEXT.ja : TEXT.en;
80
+ var T = this.T;
81
+ [["dur", 1, false], ["stagger", 0.25, true], ["fast", 2.5, false]].forEach(function(a){
82
+ if (self.timing(a[0], -1, a[2]) === -1){ ctx.report("attr", "[sampling] invalid " + a[0] + "; using " + a[1]); P[a[0]] = a[1]; }
83
+ });
84
+ if (!(P.size === 0 || Number.isFinite(P.size) && P.size >= 24)){ ctx.report("attr", "[sampling] size must be 0 or at least 24; using 26"); P.size = 0; }
85
+ this.fs = P.size || 26;
86
+ this.style.display = "block"; this.style.position = "relative"; this.style.writingMode = "horizontal-tb";
87
+ this.setAttribute("role", "img");
88
+ var W = Math.max(1, this.clientWidth), H = Math.max(1, this.clientHeight);
89
+ var items = [], composition = [], balls = d.balls !== undefined;
90
+ var invalid = balls && d.values !== undefined;
91
+ if (balls){
92
+ Object.keys(d.balls).forEach(function(name){
93
+ var count = d.balls[name], col = objColor(name);
94
+ if (!col) ctx.report("data", "[sampling] unknown colour " + name + "; drawn as gray with its name");
95
+ if (!Number.isInteger(count) || count < 0 || count > 30){ invalid = true; return; }
96
+ composition.push(name + " " + count);
97
+ for (var i = 0; i < count; i++) items.push({label: name, color: col || objColor("gray")});
98
+ });
99
+ } else {
100
+ items = d.values.map(function(v){ return {label: String(v), value: v}; });
101
+ composition = items.map(function(o){ return o.label; });
102
+ }
103
+ if (invalid || items.length < 2 || items.length > 30){
104
+ ctx.report("data", "[sampling] supply exactly one population: 2–30 values or balls with non-negative integer counts totalling 2–30");
105
+ this.svg = base.el("svg", {viewBox: "0 0 " + W + " " + H, width: W, height: H, "aria-hidden": "true"}, this);
106
+ this.label(this.svg, 8, this.fs + 4, T.population + ": 2–30");
107
+ if (!this.getAttribute("aria-label")) this.setAttribute("aria-label", T.population + ": 2–30");
108
+ return;
109
+ }
110
+ function integer(key, fallback, lo, hi){
111
+ var v = d[key] === undefined ? fallback : d[key];
112
+ if (!Number.isInteger(v) || v < lo || v > hi){
113
+ v = Math.max(lo, Math.min(hi, Math.round(v)));
114
+ ctx.report("data", "[sampling] " + key + " must be an integer " + lo + "–" + hi + "; clamped to " + v);
115
+ }
116
+ return v;
117
+ }
118
+ var stat = balls ? "proportion" : "mean", of = d.of === undefined ? (balls ? Object.keys(d.balls)[0] : "") : d.of;
119
+ if (d.stat !== undefined && d.stat !== stat) ctx.report("data", "[sampling] stat=" + d.stat + " is incompatible with this population; using " + stat);
120
+ if (balls && !Object.prototype.hasOwnProperty.call(d.balls, of)) ctx.report("data", "[sampling] of=" + of + " is absent from the population; proportion is zero");
121
+ var n = integer("n", 1, 1, d.replace ? 30 : items.length), repeat = integer("repeat", 40, 1, 200), digits = integer("digits", 2, 0, 10);
122
+ var seed = d.seed === undefined ? 1 : d.seed;
123
+ if (!Number.isSafeInteger(seed)){ ctx.report("data", "[sampling] seed must be a safe integer; using 1"); seed = 1; }
124
+ function statistic(sample){
125
+ return balls ? sample.filter(function(id){ return items[id].label === of; }).length / sample.length : mean(sample.map(function(id){ return items[id].value; }));
126
+ }
127
+ var rng = random(seed), samples = [];
128
+ for (var r = 0; r < repeat; r++){
129
+ var pool = items.map(function(_, i){ return i; }), ids = [];
130
+ for (var j = 0; j < n; j++){
131
+ var at = Math.floor(rng() * pool.length); ids.push(pool[at]);
132
+ if (!d.replace) pool.splice(at, 1);
133
+ }
134
+ samples.push({ids: ids, value: statistic(ids)});
135
+ }
136
+ this.model = {items: items, samples: samples, n: n, repeat: repeat, digits: digits, replace: !!d.replace, stat: stat, of: of,
137
+ population: statistic(items.map(function(_, i){ return i; })), average: mean(samples.map(function(o){ return o.value; }))};
138
+ var m = this.model, rule = m.replace ? T.with : T.without;
139
+ this.composition = composition.join(T === TEXT.ja ? "・" : ", ");
140
+ if (!this.getAttribute("aria-label")) this.setAttribute("aria-label", T.population + ": " + this.composition + "; " + rule + "; " + T.caption(n, repeat) + "; " + T.population + " " + this.fmt(m.population) + "; " + T.statsMean + " " + this.fmt(m.average));
141
+ // Source Sans 3's SVG box is 1.43em tall, including its descender.
142
+ var fs = this.fs, line = fs * 1.45 + 4, width = function(s){ return base.textWidth(s, fs, {font: self}) + 8; };
143
+ var left = W * 0.24, middle = W * 0.38, sx = left + 22, px = left + middle + 48, pw = Math.max(1, W - px - 22);
144
+ // Plot supplies the numerical mapping and axis; normalized values avoid overflow.
145
+ var vals = items.map(function(o){ return o.value; }), lo = balls ? 0 : Math.min.apply(null, vals), hi = balls ? 1 : Math.max.apply(null, vals);
146
+ var scale = Math.max(1, Math.abs(lo), Math.abs(hi)), a = lo / scale, b = hi / scale;
147
+ var captionY = H - fs * 0.4 - 4, axisY = captionY - 3 * line;
148
+ var plotTop = fs + 4 + fs * 0.4 + 8, plotH = axisY - plotTop;
149
+ var plot = deps.plot.Plot(this, {xr: a === b ? [a - 1, b + 1] : [a, b], yr: [0, 1], xt: [], yt: [], noY: true,
150
+ m: {l: px + 12, r: W - px - 12 - Math.max(1, pw - 24), t: plotTop, b: H - axisY}});
151
+ this.svg = plot.svg;
152
+ set(this.svg, "width", W); set(this.svg, "height", H); set(this.svg, "aria-hidden", "true");
153
+ var axes = [].filter.call(this.svg.children, function(e){ return e.getAttribute("class") === "axes"; })[0];
154
+ this.svg.removeChild(axes);
155
+ var X = function(v){ return plot.x(v / scale); };
156
+ this.populationLayer = base.el("g", {opacity: 0}, this.svg);
157
+ this.sampleLayer = base.el("g", {opacity: 0}, this.svg);
158
+ this.plotLayer = base.el("g", {opacity: 0}, this.svg);
159
+ this.plotLayer.appendChild(axes);
160
+ this.finalLayer = base.el("g", {opacity: 0}, this.plotLayer);
161
+ this.label(this.populationLayer, 8, fs + 4, T.population);
162
+ this.label(this.sampleLayer, sx, fs + 4, T.sample);
163
+ this.label(this.plotLayer, px, fs + 4, T.distribution);
164
+ var small = false, itemW = Math.max(52, ...items.map(function(o){ return width(o.label) + (balls ? 36 : 16); }));
165
+ var cols = Math.max(1, Math.min(items.length, Math.floor((left - 24) / itemW))), rows = Math.ceil(items.length / cols), rowH = Math.max(48, line);
166
+ var bagTop = line + 10, bagBottom = bagTop + rows * rowH + 12;
167
+ base.el("rect", {x: 4, y: bagTop, width: Math.max(1, left - 8), height: bagBottom - bagTop, rx: 18, fill: "none", stroke: "var(--fg)", "stroke-width": 2}, this.populationLayer);
168
+ function item(g, o){
169
+ var shape = base.el(balls ? "circle" : "rect", balls ? {cx: 14, cy: 0, r: 12, fill: o.color, stroke: "var(--fg)", "stroke-width": 2} : {x: 0, y: -rowH / 2 + 3, width: itemW - 8, height: rowH - 6, rx: 6, fill: "var(--bg)", stroke: "var(--fg)", "stroke-width": 2}, g);
170
+ var text = self.label(g, balls ? 34 : (itemW - 8) / 2, fs * 0.312, o.label, balls ? "start" : "middle");
171
+ return {g: g, shape: shape, text: text};
172
+ }
173
+ this.originals = items.map(function(o, i){
174
+ var x = 14 + (i % cols) * itemW, y = bagTop + 8 + rowH / 2 + Math.floor(i / cols) * rowH;
175
+ var q = item(base.el("g", {transform: "translate(" + x + " " + y + ")"}, self.populationLayer), o); q.x = x; q.y = y; return q;
176
+ });
177
+ // Wrap word groups below the bag; reserve a full font box between baselines.
178
+ var y = bagBottom;
179
+ if (balls){
180
+ // Keep separators inside the string: width padding must not add spaces around ・.
181
+ var words = "";
182
+ composition.forEach(function(s){
183
+ var joined = words ? words + (T === TEXT.ja ? "・" : ", ") + s : s;
184
+ if (words && width(joined) > left - 16){ y += line; self.label(self.populationLayer, 8, y, words); words = s; }
185
+ else words = joined;
186
+ if (width(s) > left - 16) small = true;
187
+ });
188
+ y += line; self.label(self.populationLayer, 8, y, words);
189
+ }
190
+ var rules = width(rule) <= left - 16 ? [rule] : (T === TEXT.ja ? [m.replace ? "戻す" : "戻さない", m.replace ? "(復元抽出)" : "(非復元抽出)"] : rule.split(" "));
191
+ rules.forEach(function(s){ y += line; self.label(self.populationLayer, 8, y, s); if (width(s) > left - 16) small = true; });
192
+ if (y + fs * 0.4 + 4 > H || itemW > left - 24) small = true;
193
+ var sampleY = bagTop + rowH / 2 + 8, sampleW = n * itemW;
194
+ if (sampleW > middle - 10) small = true;
195
+ this.drawn = Array.from({length: n}, function(_, j){ var q = item(base.el("g", {}, self.sampleLayer), items[samples[0].ids[j]]); q.x = sx + j * itemW; q.y = sampleY; return q; });
196
+ this.statLayer = base.el("g", {opacity: 0}, this.sampleLayer);
197
+ var statY = sampleY + rowH / 2 + line;
198
+ this.statName = this.label(this.statLayer, sx, statY, balls ? of + T.proportion : T.mean);
199
+ this.statValue = this.label(this.statLayer, sx, statY + line, "");
200
+ var statLabel = balls ? of + T.proportion : T.mean;
201
+ if (width(statLabel) > middle - 10 || statY + line + fs * 0.4 > H) small = true;
202
+ var ticks = balls ? [0, 0.25, 0.5, 0.75, 1] : meanTicks(lo, hi, vals), lastRight = -Infinity;
203
+ ticks.forEach(function(v){
204
+ var xx = X(v), rounded = +v.toPrecision(4), s = Number.isFinite(rounded) ? String(rounded) : String(v), w = width(s);
205
+ base.el("line", {x1: xx, x2: xx, y1: axisY, y2: axisY + 7, stroke: "var(--fg)", "stroke-width": 2}, self.plotLayer);
206
+ var anchor = v === lo ? "start" : v === hi ? "end" : "middle";
207
+ var tx = anchor === "start" ? xx : anchor === "end" ? xx - w : xx - w / 2;
208
+ if (tx < lastRight + 4) small = true; lastRight = tx + w;
209
+ self.label(self.plotLayer, xx, axisY + line, s, anchor);
210
+ });
211
+ this.label(this.plotLayer, px, axisY + 2 * line, balls ? T.proportionAxis : T.meanAxis);
212
+ this.label(this.finalLayer, px, captionY, T.caption(n, repeat));
213
+ var markerLabel = T.population + " " + this.fmt(m.population);
214
+ var markerY = fs + 4 + line, markerRight = px + width(markerLabel);
215
+ this.label(this.finalLayer, px, markerY, markerLabel);
216
+ var markerBottom = markerY + fs * 0.4 + 8;
217
+ base.el("line", {x1: X(m.population), x2: X(m.population), y1: markerBottom, y2: axisY, stroke: "var(--emph)", "stroke-width": 2, "stroke-dasharray": "6 5"}, this.finalLayer);
218
+ // Stack horizontally intersecting dots at separate levels, preserving exact numerical x.
219
+ function stack(radius){
220
+ var levels = [];
221
+ return samples.map(function(o){
222
+ var xx = X(o.value), lv = 0;
223
+ while (levels[lv] && levels[lv].some(function(v){ return Math.abs(v - xx) < 2 * radius + 2; })) lv++;
224
+ if (!levels[lv]) levels[lv] = []; levels[lv].push(xx);
225
+ return {x: xx, level: lv};
226
+ });
227
+ }
228
+ // The marker label occupies only the plot's upper-left corner, not a whole row.
229
+ // A 1px gap between circle fills leaves more room for repeated values.
230
+ function fits(positions, radius){
231
+ return positions.every(function(o){
232
+ var top = axisY - 2 * radius - 3 - o.level * (2 * radius + 1);
233
+ return top >= (o.x - radius < markerRight && o.x + radius > px ? markerBottom : plotTop);
234
+ });
235
+ }
236
+ var radius = 8, positions;
237
+ while (true){
238
+ positions = stack(radius);
239
+ if (fits(positions, radius) || radius === 5) break;
240
+ radius--;
241
+ }
242
+ if (!fits(positions, radius)) ctx.report("size", "[sampling] dot stack exceeds plot at minimum 5px radius; increase height or reduce repeat");
243
+ this.dots = positions.map(function(o){
244
+ var yy = axisY - radius - 3 - o.level * (2 * radius + 1);
245
+ return {x: o.x, y: yy, el: base.el("circle", {cx: o.x, cy: yy, r: radius, fill: "var(--term)", stroke: "var(--fg)", "stroke-width": 1, opacity: 0}, self.plotLayer)};
246
+ });
247
+ this.plotTop = plotTop;
248
+ if ([T.distribution, markerLabel, T.caption(n, repeat), balls ? T.proportionAxis : T.meanAxis].some(function(s){ return width(s) > pw; }) || plotH < 40) small = true;
249
+ if (small) ctx.report("size", "[sampling] population, sample row or plot labels do not fit; enlarge the element or shorten names");
250
+ // Check all statistic strings, since a later sample can be wider than the first.
251
+ if (samples.some(function(o){ return width(self.statText(o)) > middle - 10; })) ctx.report("size", "[sampling] statistic does not fit; enlarge width or reduce digits");
252
+ }
253
+ statText(sample){
254
+ var m = this.model;
255
+ return (m.stat === "proportion" ? sample.ids.filter(function(i){ return m.items[i].label === m.of; }).length + "/" + m.n + " = " : "") + this.fmt(sample.value);
256
+ }
257
+ render(k, t){
258
+ if (!this.model) return;
259
+ var self = this, m = this.model, P = this.props;
260
+ var phase = function(step){ return k > step ? 1 : k < step ? 0 : base.prog(t, 0, P.dur); };
261
+ set(this.populationLayer, "opacity", phase(1));
262
+ set(this.sampleLayer, "opacity", k >= 2 ? 1 : 0);
263
+ set(this.statLayer, "opacity", phase(3));
264
+ set(this.plotLayer, "opacity", phase(3));
265
+ var progress = k > 4 ? 1 : k < 4 ? 0 : Math.max(0, Math.min(1, t / P.fast));
266
+ var completed = k < 3 ? 0 : k === 3 ? (t >= P.dur ? 1 : 0) : 1 + Math.floor(progress * (m.repeat - 1));
267
+ var rep = k >= 4 ? Math.min(m.repeat - 1, completed - 1) : 0, sample = m.samples[rep];
268
+ var full = k >= 4 && progress === 1 || k === 3 && t >= P.dur;
269
+ this.originals.forEach(function(o, i){
270
+ var j = sample.ids.indexOf(i), gone = !m.replace && j >= 0 && !full && (k >= 3 || k === 2 && t > j * P.stagger);
271
+ set(o.g, "opacity", gone ? 0 : 1);
272
+ });
273
+ this.drawn.forEach(function(o, j){
274
+ var id = sample.ids[j], original = self.originals[id], e = k > 2 ? 1 : k < 2 ? 0 : base.prog(t, j * P.stagger, P.dur);
275
+ set(o.g, "opacity", k >= 2 && (k > 2 || t > j * P.stagger) ? 1 : 0);
276
+ set(o.g, "transform", "translate(" + base.lerp(original.x, o.x, e) + " " + base.lerp(original.y, o.y, e) + ")");
277
+ o.text.textContent = m.items[id].label;
278
+ if (m.stat === "proportion") set(o.shape, "style", "fill:" + m.items[id].color + ";stroke:var(--fg)");
279
+ });
280
+ this.statValue.textContent = this.statText(sample);
281
+ this.dots.forEach(function(o, i){
282
+ var drop = i === 0 && k === 3 ? base.prog(t, 0, P.dur) : 1;
283
+ set(o.el, "opacity", i < completed || i === 0 && k === 3 && t > 0 ? 1 : 0);
284
+ set(o.el, "cy", base.lerp(self.plotTop, o.y, drop));
285
+ });
286
+ set(this.finalLayer, "opacity", k >= 4 && progress === 1 ? 1 : 0);
287
+ }
288
+ };
289
+ });
@@ -0,0 +1,31 @@
1
+ ---
2
+ summary: 2-axis positioning map (4 quadrants); points one per step
3
+ steps: largest step / to.step (1 point = 1 step)
4
+ props:
5
+ fade: point appear (s)
6
+ move: to move (s)
7
+ size: label px
8
+ quads-step: quadrant-name step (0 = start)
9
+ example: {"x": {"lo": "Manual", "hi": "Auto"}, "y": {"lo": "Costly", "hi": "Cheap"}, "items": [{"label": "Co. A", "x": 0.25, "y": 0.7}, {"label": "Us", "x": 0.8, "y": 0.82, "self": true}]}
10
+ ---
11
+
12
+ Positioning, effect×effort, SWOT: show the empty space.
13
+
14
+ Child JSON: `{"x": {"lo", "hi"}, "y": {"lo", "hi"}, "quads": {"tr", "tl", "bl", "br", "fill"}, "items": [...]}`.
15
+
16
+ - `x` `y`: axis end words (step 0)
17
+ - `quads`: names (tr = top-right, tl, bl, br); `fill: "tr"` tints one; names at `quads-step`
18
+ - item: `label`, `x` `y` (0–1; 0.5 = axis cross), `step` (default next), `at`, `tone` (`term`/`fg`; default muted), `anchor` (`right`, `left`, `above`, `below`), `r`
19
+ - `self: true`: big `--emph` point, ring pulse
20
+ - `to: {"x", "y", "label", "step", "at"}`: slides at `to.step` (default next), dashed trail; `label` on arrival
21
+ - `cues(k)`: start times of 2nd+ points in a step, for `{cue}`
22
+
23
+ The demo is `demo.html`. Names and positions are fictional.
24
+
25
+ Notes
26
+
27
+ <!-- llm: omit -->
28
+ - Labels crossing an axis move: opposite side → above → below (start and `to`; even with `anchor`). Axis lines have `class="axis"`; `tools/test-components.mjs` flags crossings
29
+ <!-- llm: end -->
30
+ - Quadrant names avoid points and labels (else labels move, or `ctx.report`)
31
+ - Label overlaps not fixed: change `anchor` or shift
@@ -0,0 +1,236 @@
1
+ // m-quad:2 軸の位置づけ(ポジショニングマップ・SWOT 風の 4 象限)。点を段階ごとに 1 つずつ置く
2
+ // <m-quad style="height:420px"><script type="application/json">
3
+ // {"x": {"lo": "手作業", "hi": "自動"}, "y": {"lo": "高い", "hi": "安い"},
4
+ // "quads": {"tr": "狙う場所", "tl": "", "bl": "", "br": ""},
5
+ // "items": [{"label": "A 社", "x": 0.25, "y": 0.7}, {"label": "自社", "x": 0.8, "y": 0.82, "self": true, "to": {"x": 0.9, "y": 0.9, "label": "3 年後"}}]}
6
+ // (JSON の終わり)</m-quad>
7
+ // 座標は 0〜1(0.5 が軸の交わるところ)。軸と両端の言葉は段階 0 から見える。象限の名前は quads-step(既定 0)で出る
8
+ // 点は既定で 1 つ = 1 段階(step で直接、at で段階の中の開始秒)。self の点は強調の色で大きく、着いたときに輪が広がる
9
+ // to は移動先:to.step(既定は点の次の段階)に、点が破線の跡を引きながら滑る
10
+ // 2.0(Egatari spec §6.1 の部品):base の MotionElement・el・prog・lerp・clamp・previewOpacity を使い、プレイヤーのグローバルは使わない
11
+ egatariParts.define({name: "quad", version: "2.1.0", requires: {base: "1.2.0"}, element: "m-quad"}, function(deps){
12
+ "use strict";
13
+ var base = deps.base;
14
+ return class extends base.MotionElement {
15
+ static partName = "quad"; // the registry name (define meta name), for report prefixes
16
+ // データの形(kit/shape.js)。x・y は 0〜1(0.5 が軸の交わるところ)
17
+ static shape = {
18
+ schema: {type: "object", additionalProperties: false, required: ["items"], properties: {
19
+ x: {type: "object", properties: {lo: {type: "string"}, hi: {type: "string"}}}, y: {type: "object", properties: {lo: {type: "string"}, hi: {type: "string"}}},
20
+ quads: {type: "object", properties: {tr: {type: "string"}, tl: {type: "string"}, bl: {type: "string"}, br: {type: "string"}, fill: {type: "string"}}},
21
+ items: {type: "array", minItems: 1, items: {type: "object", required: ["x", "y"], properties: {
22
+ label: {type: "string"}, x: {type: "number"}, y: {type: "number"}, step: {type: "integer"}, at: {type: "number"}, tone: {type: "string"}, anchor: {enum: ["right", "left", "above", "below"]},
23
+ r: {type: "number"}, self: {type: "boolean"}, to: {type: "object", required: ["x", "y"], properties: {x: {type: "number"}, y: {type: "number"}, label: {type: "string"}, step: {type: "integer"}, at: {type: "number"}}}}}}}},
24
+ example: {x: {lo: "手作業", hi: "自動"}, y: {lo: "高い", hi: "安い"}, items: [{label: "A 社", x: 0.25, y: 0.7}, {label: "自社", x: 0.8, y: 0.82, self: true}]},
25
+ };
26
+ static props = {
27
+ fade: {type: "number", default: 0.5, doc: "点が現れる秒数"},
28
+ move: {type: "number", default: 1.2, doc: "to の移動の秒数"},
29
+ size: {type: "number", default: 26, doc: "点の名前の字の大きさ(px)"},
30
+ "quads-step": {type: "number", default: 0, doc: "象限の名前を出すステップ(0 = 初めから)"},
31
+ };
32
+ get steps(){
33
+ if (this.getAttribute("steps") !== null) return +this.getAttribute("steps");
34
+ var m = this.props["quads-step"];
35
+ this.plan().forEach(function(o){ m = Math.max(m, o.step, o.to ? o.to.step : 0); });
36
+ return m;
37
+ }
38
+ // 点の段階と開始時刻(データだけから決める)
39
+ plan(){
40
+ if (this._plan) return this._plan;
41
+ var d = this.data || {}, q0 = this.props["quads-step"], n = 0, seen = {};
42
+ return (this._plan = (d.items || []).map(function(it){
43
+ var step = it.step !== undefined ? it.step : q0 + (++n);
44
+ n = Math.max(n, step - q0);
45
+ var j = seen[step] = (seen[step] || 0) + 1;
46
+ var to = it.to ? {x: it.to.x, y: it.to.y, label: it.to.label || "", step: it.to.step !== undefined ? it.to.step : step + 1, at: it.to.at || 0} : null;
47
+ return {it: it, step: step, at: it.at !== undefined ? it.at : (j - 1) * 0.6, to: to};
48
+ }));
49
+ }
50
+ mount(ctx){
51
+ var P = this.props, D = base, self = this, d = this.data || {};
52
+ this.style.display = "block"; this.style.position = "relative";
53
+ var W = this.clientWidth, H = this.clientHeight;
54
+ var svg = D.el("svg", {viewBox: "0 0 " + W + " " + H, width: W, height: H, "aria-hidden": "true", style: "display:block;overflow:visible"}, this);
55
+ // 読み上げ:最後の形(点はすべて置かれ、to の点は行き先にいる)を 1 文で。作者の aria-label があればそれを使う(上書きしない)
56
+ if (this._aria === undefined) this._aria = this.getAttribute("aria-label");
57
+ this.setAttribute("role", "img");
58
+ if (!this._aria) this.setAttribute("aria-label", this.summary(/^ja\b/i.test(ctx.lang || "ja")));
59
+ // 図の枠:両端の言葉の分だけ上下と左右に余白
60
+ var m = {l: 12, r: 12, t: 40, b: 40};
61
+ var x0 = m.l, x1 = W - m.r, y0 = m.t, y1 = H - m.b, cx = (x0 + x1) / 2, cy = (y0 + y1) / 2;
62
+ this.X = function(v){ return x0 + v * (x1 - x0); };
63
+ this.Y = function(v){ return y1 - v * (y1 - y0); };
64
+ // 象限の地(右上だけ淡く塗れる:quads.fill = "tr" など)と名前
65
+ var q = d.quads || {}, xa0 = d.x || {}, gQ = D.el("g", {}, svg);
66
+ this.quadG = D.el("g", {}, svg);
67
+ var corner = {tr: [cx, y0, x1 - cx, cy - y0, x1 - 16, y0 + 34, "end"], tl: [x0, y0, cx - x0, cy - y0, x0 + 16, y0 + 34, "start"],
68
+ bl: [x0, cy, cx - x0, y1 - cy, x0 + 16, y1 - 16, "start"], br: [cx, cy, x1 - cx, y1 - cy, x1 - 16, y1 - 16, "end"]};
69
+ ["tr", "tl", "bl", "br"].forEach(function(key){
70
+ var c = corner[key];
71
+ if (q.fill === key) D.el("rect", {x: c[0], y: c[1], width: c[2], height: c[3], fill: "var(--term-tint)"}, gQ);
72
+ });
73
+ // 軸(両向きの矢印)と両端の言葉。横軸の言葉は軸の下、縦軸の言葉は軸の上端・下端の外
74
+ var ax = D.el("g", {}, svg), K = "var(--fg)";
75
+ D.el("line", {x1: x0, y1: cy, x2: x1, y2: cy, stroke: K, "stroke-width": 2, class: "axis"}, ax);
76
+ D.el("line", {x1: cx, y1: y0, x2: cx, y2: y1, stroke: K, "stroke-width": 2, class: "axis"}, ax);
77
+ [[x1, cy, 0], [x0, cy, 180], [cx, y0, -90], [cx, y1, 90]].forEach(function(a){
78
+ D.el("path", {d: "M0,0L-14,-7L-14,7Z", fill: K, transform: "translate(" + a[0] + " " + a[1] + ") rotate(" + a[2] + ")"}, ax);
79
+ });
80
+ var xa = xa0, ya = d.y || {};
81
+ if (xa.lo) D.mtext(ax, x0 + 4, cy + 34, xa.lo, {"text-anchor": "start", "font-size": 24});
82
+ if (xa.hi) D.mtext(ax, x1 - 4, cy + 34, xa.hi, {"text-anchor": "end", "font-size": 24});
83
+ if (ya.hi) D.mtext(ax, cx, y0 - 14, ya.hi, {"text-anchor": "middle", "font-size": 24});
84
+ if (ya.lo) D.mtext(ax, cx, y1 + 32, ya.lo, {"text-anchor": "middle", "font-size": 24});
85
+ // 点の名前の置き場所(既定は右。anchor で left / above / below)。
86
+ // 名前が軸の線を横切るなら、丸の反対の側 → 上 → 下の順に置き直す(点の始めの位置と to の位置の両方で確かめる)。
87
+ // 象限の名前を置いたあとは、その名前にかかる置き場所も避ける。幅は字から見積もる(base の textWidth:テーマの字で測った幅。mtext の *_^ は数えない)
88
+ var est = function(s, z){ return D.textWidth(s || "", z, {font: self, mark: true}); };
89
+ var meet = function(a, b, gp){ return a[0] < b[2] + gp && a[2] > b[0] - gp && a[1] < b[3] + gp && a[3] > b[1] - gp; };
90
+ var items = this.plan().map(function(o){
91
+ var it = o.it, me = !!it.self, r = it.r || (me ? 14 : 11), off = r + 10, w = est(it.label, P.size);
92
+ var place = function(an){ return an === "left" ? [-off, 9, "end"] : an === "above" ? [0, -off - 4, "middle"] : an === "below" ? [0, off + 22, "middle"] : [off, 9, "start"]; };
93
+ var boxAt = function(an, px, py){
94
+ var lp = place(an), lx = px + lp[0], ly = py + lp[1], a0 = lp[2] === "start" ? lx : lp[2] === "end" ? lx - w : lx - w / 2;
95
+ return [a0, ly - P.size * 0.88, a0 + w, ly + P.size * 0.22];
96
+ };
97
+ var crosses = function(an, px, py){
98
+ var b = boxAt(an, px, py);
99
+ return (b[0] - 6 < cx && b[2] + 6 > cx && b[1] < y1 && b[3] > y0) || (b[1] - 6 < cy && b[3] + 6 > cy && b[0] < x1 && b[2] > x0);
100
+ };
101
+ var pts = [[self.X(it.x), self.Y(it.y)]].concat(o.to ? [[self.X(o.to.x), self.Y(o.to.y)]] : []);
102
+ var pref = it.anchor || "right", order = [pref, pref === "left" ? "right" : pref === "right" ? "left" : pref === "above" ? "below" : "above", "above", "below", "left", "right"];
103
+ var pick = function(names){
104
+ return order.filter(function(a){ return !pts.some(function(q){ return crosses(a, q[0], q[1]) || names.some(function(nb){ return meet(boxAt(a, q[0], q[1]), nb, 6); }); }); })[0];
105
+ };
106
+ var an = pick([]) || pref;
107
+ return {o: o, it: it, me: me, r: r, pts: pts, place: place, boxAt: boxAt, pick: pick, an: an,
108
+ // 丸と名前が占める箱(点の始めと to の位置)
109
+ boxes: function(a){ return [].concat.apply([], pts.map(function(q){ return [[q[0] - r, q[1] - r, q[0] + r, q[1] + r], boxAt(a, q[0], q[1])]; })); }};
110
+ });
111
+ // 象限の名前:隅(外側の角)に置く。点や点の名前、軸の言葉にかかるなら、同じ象限の残りの 3 つの隅を順に試す。
112
+ // どこもかかるなら外側の角に置き、点の名前のほうを動かす(上の pick)。動かせなければ知らせる(layout)
113
+ var axisBoxes = [];
114
+ if (xa0.lo) axisBoxes.push([x0 + 4, cy + 34 - 24 * 0.88, x0 + 4 + est(xa0.lo, 24), cy + 34 + 24 * 0.22]);
115
+ if (xa0.hi) axisBoxes.push([x1 - 4 - est(xa0.hi, 24), cy + 34 - 24 * 0.88, x1 - 4, cy + 34 + 24 * 0.22]);
116
+ var names = [];
117
+ ["tr", "tl", "bl", "br"].forEach(function(key){
118
+ if (!q[key]) return;
119
+ var c = corner[key], top = key[0] === "t", right = key[1] === "r", w = est(q[key], 26);
120
+ var ins = [c[0] + 16, c[0] + c[2] - 16], ys = top ? [y0 + 34, cy - 16] : [y1 - 16, cy + 42];
121
+ var cand = [[right ? ins[1] : ins[0], ys[0], right ? "end" : "start"], [right ? ins[0] : ins[1], ys[0], right ? "start" : "end"],
122
+ [right ? ins[1] : ins[0], ys[1], right ? "end" : "start"], [right ? ins[0] : ins[1], ys[1], right ? "start" : "end"]];
123
+ var boxOf = function(k){ var x = k[2] === "end" ? k[0] - w : k[0]; return [x, k[1] - 26 * 0.88, x + w, k[1] + 26 * 0.22]; };
124
+ var busy = function(b){ return axisBoxes.some(function(a){ return meet(b, a, 6); }) || items.some(function(m){ return m.boxes(m.an).some(function(a){ return meet(b, a, 6); }); }); };
125
+ var k = cand.filter(function(k){ return !busy(boxOf(k)); })[0] || cand[0];
126
+ D.mtext(self.quadG, k[0], k[1], q[key], {"text-anchor": k[2], "font-size": 26, "font-weight": 700, fill: q.fill === key ? "var(--term)" : "var(--muted)"});
127
+ names.push({key: key, box: boxOf(k)});
128
+ });
129
+ items.forEach(function(m){
130
+ if (!names.length || !m.boxes(m.an).some(function(a){ return names.some(function(nm){ return meet(a, nm.box, 6); }); })) return;
131
+ var a = m.pick(names.map(function(nm){ return nm.box; }));
132
+ if (a) m.an = a;
133
+ else ctx.report("layout", "[quad] the label " + JSON.stringify(m.it.label || "") + " overlaps a quadrant name and has no free side; move the point or shorten a name");
134
+ });
135
+ // 点:丸と名前
136
+ var gT = D.el("g", {}, svg), gP = D.el("g", {}, svg);
137
+ // data-part:Studio の形の検査(geometry check)が測る印。点の丸は mark(id は items の並びで p1, p2 …)、点の名前と行き先の名前は
138
+ // その点の label(箱の外の字)、動いた跡は p<n> から @moved への edge(破線が data-part-line、矢じりは端)
139
+ this.pts = items.map(function(m, i){
140
+ var o = m.o, it = m.it, me = m.me, r = m.r, col = me ? "var(--emph)" : it.tone === "term" ? "var(--term)" : it.tone === "fg" ? "var(--fg)" : "var(--muted)";
141
+ var pid = "p" + (i + 1), lb = {"data-part": "label", "data-part-id": pid, "data-part-of": "mark", "data-part-at": "outside"};
142
+ var gM = o.to ? D.el("g", {"data-part": "edge", "data-part-id": pid + "\u2192@moved", "data-part-from": pid, "data-part-to": "@moved"}, gT) : null;
143
+ var trail = o.to ? D.el("line", {stroke: col, "stroke-width": 2.5, "stroke-dasharray": "7 6", opacity: 0, "data-part-line": ""}, gM) : null;
144
+ // 動いた跡の印(最後の形にも残す):出発点の白抜きの丸と、行き先へ向く矢じり(丸の手前)
145
+ var from = o.to ? D.el("circle", {cx: self.X(it.x).toFixed(2), cy: self.Y(it.y).toFixed(2), r: (r * 0.8).toFixed(1), fill: "var(--bg)", stroke: col, "stroke-width": 2.5, opacity: 0}, gT) : null;
146
+ var head = o.to ? D.el("path", {d: "M0,0L-14,-7L-14,7Z", fill: col, opacity: 0}, gM) : null;
147
+ var ring = me ? D.el("circle", {r: r, fill: "none", stroke: col, "stroke-width": 3, opacity: 0}, gP) : null;
148
+ var g = D.el("g", {opacity: 0}, gP);
149
+ D.el("circle", {cx: 0, cy: 0, r: r, fill: col, stroke: "var(--bg)", "stroke-width": 2.5, "data-part": "mark", "data-part-id": pid}, g);
150
+ var lp = m.place(m.an);
151
+ D.mtext(g, lp[0], lp[1], it.label || "", Object.assign({"text-anchor": lp[2], "font-size": P.size, "font-weight": me ? 700 : 400, fill: me ? col : "var(--fg)"}, lb));
152
+ var lab2 = o.to && o.to.label ? D.mtext(gP, 0, 0, o.to.label, Object.assign({"text-anchor": "middle", "font-size": 24, fill: col, opacity: 0}, lb)) : null;
153
+ return {o: o, g: g, ring: ring, r: r, trail: trail, from: from, head: head, lab2: lab2};
154
+ });
155
+ }
156
+ // 最後の形を 1 文で(読み上げの名前):象限の名前と、点ごとの最後の位置(右上・左下など。to の点は出発点から行き先へ)
157
+ summary(ja){
158
+ var d = this.data || {}, q = d.quads || {}, xa = d.x || {}, ya = d.y || {};
159
+ var where = function(x, y, bare){
160
+ var h = x > 0.5 ? (ja ? "右" : "right") : x < 0.5 ? (ja ? "左" : "left") : "", v = y > 0.5 ? (ja ? "上" : "upper") : y < 0.5 ? (ja ? "下" : "lower") : "";
161
+ var key = (y > 0.5 ? "t" : "b") + (x > 0.5 ? "r" : "l");
162
+ var s = ja ? (h + v || "中央") : ([v, h].filter(Boolean).join(" ") || "centre");
163
+ return s + (h && v && q[key] && !bare ? (ja ? "(" + q[key] + ")" : " (" + q[key] + ")") : "");
164
+ };
165
+ var axis = function(a, n){ return a.lo || a.hi ? (ja ? n + ":" + (a.lo || "") + "→" + (a.hi || "") : n + ": " + (a.lo || "") + " to " + (a.hi || "")) : ""; };
166
+ var ax = [axis(xa, ja ? "横" : "x"), axis(ya, ja ? "縦" : "y")].filter(Boolean).join(ja ? "、" : "; ");
167
+ var pts = this.plan().map(function(o){
168
+ var it = o.it, nm = it.label || (ja ? "点" : "a point");
169
+ if (!o.to) return ja ? nm + "は" + where(it.x, it.y) : nm + " is " + where(it.x, it.y);
170
+ var lb = o.to.label ? (ja ? "(" + o.to.label + ")" : " (" + o.to.label + ")") : "", w0 = where(it.x, it.y), w1 = where(o.to.x, o.to.y, true);
171
+ // 同じ象限の中の移動なら、行き先に象限の名前を繰り返さない
172
+ if (w1 !== where(it.x, it.y, true)) w1 = where(o.to.x, o.to.y);
173
+ return ja ? nm + "は" + w0 + "から" + w1 + "へ" + lb : nm + " moves from " + w0 + " to " + w1 + lb;
174
+ });
175
+ return (ja ? "4 象限" : "Four quadrants") + (ax ? (ja ? "(" + ax + ")" : " (" + ax + ")") : "") + (ja ? ":" : ": ") + pts.join(ja ? "、" : ", ");
176
+ }
177
+ duration(k){
178
+ var P = this.props, d = k === P["quads-step"] && k > 0 ? P.fade : 0;
179
+ this.plan().forEach(function(o){
180
+ if (o.step === k) d = Math.max(d, o.at + P.fade + (o.it.self ? 0.6 : 0));
181
+ if (o.to && o.to.step === k) d = Math.max(d, o.to.at + P.move + 0.3);
182
+ });
183
+ return d;
184
+ }
185
+ // 同じ段階に 2 つ以上の点があれば、2 つ目からの開始時刻を口述原稿の {cue} に合わせられる
186
+ cues(k){
187
+ var c = [];
188
+ this.plan().forEach(function(o){ if (o.step === k && o.at > 0) c.push(o.at); });
189
+ return c.length ? c.sort(function(a, b){ return a - b; }) : null;
190
+ }
191
+ render(k, t, ctx){
192
+ var P = this.props, D = base, self = this;
193
+ // 先の段階を薄く見せる表示(授業の表示):後の段階の点(動いた後の位置)・動く跡・行き先の名前・象限の名前を、
194
+ // テーマの --preview-opacity の濃さに。今の段階に出ている点は元の位置のまま
195
+ var preview = !!ctx.preview, PV = preview ? base.previewOpacity(this) : 1;
196
+ var pr = function(step, at, dur){ return step < k ? 1 : step > k ? 0 : D.prog(t, at, dur); };
197
+ var qs = P["quads-step"];
198
+ this.quadG.setAttribute("opacity", (qs === 0 ? 1 : preview && qs > k ? PV : pr(qs, 0, P.fade)).toFixed(3));
199
+ this.pts.forEach(function(p){
200
+ var o = p.o, e = pr(o.step, o.at, P.fade), fp = preview && o.step > k, fm = preview && o.to && o.to.step > k;
201
+ var m = o.to ? (fp ? 1 : pr(o.to.step, o.to.at, P.move)) : 0;
202
+ if (fp) e = 1;
203
+ var x0 = self.X(o.it.x), y0 = self.Y(o.it.y);
204
+ var x = o.to ? D.lerp(x0, self.X(o.to.x), m) : x0, y = o.to ? D.lerp(y0, self.Y(o.to.y), m) : y0;
205
+ var s = D.lerp(0.6, 1, e);
206
+ p.g.setAttribute("opacity", fp ? PV.toFixed(3) : e.toFixed(3));
207
+ p.g.setAttribute("transform", "translate(" + x.toFixed(2) + " " + y.toFixed(2) + ") scale(" + s.toFixed(4) + ")");
208
+ // 自社の点:着いたときに輪が 1 回広がって消える(最終状態では出さない)
209
+ if (p.ring){
210
+ var rt = !fp && o.step === k && t !== Infinity ? D.clamp((t - o.at - P.fade * 0.6) / 0.8) : 1;
211
+ p.ring.setAttribute("cx", x.toFixed(2)); p.ring.setAttribute("cy", y.toFixed(2));
212
+ p.ring.setAttribute("r", (p.r * (1 + 1.6 * rt)).toFixed(2));
213
+ p.ring.setAttribute("opacity", (rt > 0 && rt < 1 ? 0.8 * (1 - rt) : 0).toFixed(3));
214
+ }
215
+ if (p.trail){
216
+ p.trail.setAttribute("x1", x0.toFixed(2)); p.trail.setAttribute("y1", y0.toFixed(2));
217
+ p.trail.setAttribute("x2", x.toFixed(2)); p.trail.setAttribute("y2", y.toFixed(2));
218
+ if (fm){ p.trail.setAttribute("x2", self.X(o.to.x).toFixed(2)); p.trail.setAttribute("y2", self.Y(o.to.y).toFixed(2)); }
219
+ p.trail.setAttribute("opacity", fm ? PV : m > 0 ? 0.9 : 0);
220
+ // 出発点の丸は跡と同じ濃さ。矢じりは今の点の丸の手前(丸の縁から 3px)に、跡が丸と出発点の丸の外に出ている長さがあるときだけ
221
+ var hx = fm ? self.X(o.to.x) : x, hy = fm ? self.Y(o.to.y) : y, len = Math.hypot(hx - x0, hy - y0), ho = fm ? PV : m > 0 ? 0.9 : 0;
222
+ p.from.setAttribute("opacity", ho);
223
+ if (len > p.r * 1.8 + 3 + 14 + 4){
224
+ var ux = (hx - x0) / len, uy = (hy - y0) / len, tip = p.r * s + 3;
225
+ p.head.setAttribute("transform", "translate(" + (hx - ux * tip).toFixed(2) + " " + (hy - uy * tip).toFixed(2) + ") rotate(" + (Math.atan2(uy, ux) * 180 / Math.PI).toFixed(1) + ")");
226
+ p.head.setAttribute("opacity", ho);
227
+ } else { p.head.removeAttribute("transform"); p.head.setAttribute("opacity", 0); } // 作った直後と同じ(呼ぶ順で DOM が変わらない)
228
+ }
229
+ if (p.lab2){
230
+ p.lab2.setAttribute("x", self.X(o.to.x).toFixed(2)); p.lab2.setAttribute("y", (self.Y(o.to.y) - p.r - 14).toFixed(2));
231
+ p.lab2.setAttribute("opacity", fm ? PV.toFixed(3) : pr(o.to.step, o.to.at + P.move * 0.8, 0.3).toFixed(3));
232
+ }
233
+ });
234
+ }
235
+ };
236
+ });
@@ -0,0 +1,42 @@
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`), `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` (default), `draw` (lines first), `grow`
26
+ - Show later steps faintly (`ctx.preview`): later parts faint
27
+
28
+ The demo is `demo.html` (company and values fictional).
29
+
30
+ <!-- llm: omit -->
31
+ Notes
32
+
33
+ - Moves ≤ 12 px within `fade` time. Edge step default: later end; edges bulge outward (`down` below, `right` right)
34
+ - Layout: subtrees placed bottom-up and pushed together until level contours touch (Reingold–Tilford); small subtrees in between go left
35
+ - Text 27 → 24 px (`size` fixes it). Width estimated from characters (CJK 1, others 0.6)
36
+ - 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", …)`
37
+ - Motion: `fade` from below; `draw`, `grow` from the parent's direction, 12 px (root always as `fade`). `grow` from 0.92×
38
+ - `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)
39
+ - `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
40
+ - Show later steps faintly: later path faint; `branch` colour changes only at its step
41
+ - Edges take room outside the tree (`down`: 56 px below, +36 with a label); across depths they may cross boxes
42
+ <!-- llm: end -->