egatari 0.6.15 → 0.6.17

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 (44) hide show
  1. package/CHANGELOG.md +36 -1
  2. package/README.ja.md +65 -64
  3. package/README.md +40 -39
  4. package/bin/egatari.mjs +3 -3
  5. package/kit/check-messages.mjs +95 -70
  6. package/kit/check.mjs +17 -11
  7. package/kit/core/article-messages.mjs +15 -15
  8. package/kit/core/check-parity.mjs +1 -1
  9. package/kit/core/check-rules.mjs +11 -6
  10. package/kit/core/colab-core.mjs +2 -2
  11. package/kit/core/export-name.mjs +2 -2
  12. package/kit/core/geometry-check.mjs +363 -25
  13. package/kit/core/layout-scan.mjs +8 -3
  14. package/kit/core/live-policy.mjs +2 -2
  15. package/kit/core/live.mjs +2 -2
  16. package/kit/core/llm-fix.mjs +12 -12
  17. package/kit/core/llm-insert.mjs +11 -11
  18. package/kit/core/llm-outline.mjs +7 -7
  19. package/kit/core/llm-pack-data.mjs +10 -10
  20. package/kit/core/parts2.mjs +5 -5
  21. package/kit/core/portable.mjs +5 -5
  22. package/kit/core/purposes.mjs +2 -2
  23. package/kit/core/ref-voice.mjs +1 -1
  24. package/kit/core/scorm.mjs +1 -1
  25. package/kit/core/sound-preferences.mjs +1 -1
  26. package/kit/core/theme-derive.mjs +209 -0
  27. package/kit/core/themes-list.mjs +1 -1
  28. package/kit/core/themes-lock.mjs +1 -1
  29. package/kit/core/tier-a.mjs +7 -7
  30. package/kit/deck.js +7 -4
  31. package/kit/instruction-version.json +1 -1
  32. package/kit/live.js +20 -20
  33. package/kit/player.json +1 -1
  34. package/kit/player.lock.json +2 -2
  35. package/kit/presenter.js +2 -2
  36. package/kit/templates/new-deck.mjs +6 -6
  37. package/kit/tools.js +5 -5
  38. package/kit/track.js +1 -1
  39. package/package.json +1 -1
  40. package/server/editor-ui.js +20 -17
  41. package/tts/yomi.yaml +8 -0
  42. package/vendor/egatari-spec/SOURCE.json +2 -2
  43. package/vendor/egatari-spec/schema/deck-meta.schema.json +1 -1
  44. package/vendor/egatari-spec/schema/egatari-metadata.schema.json +2 -2
@@ -2,18 +2,34 @@
2
2
  // 編集アプリのプレビュー(app/frame-shim.js)が同じこの関数を使う(体裁の検査 kit/core/layout-scan.mjs と同じ入れ方)
3
3
  //
4
4
  // 部品は描いた要素に印(札)を付けるだけで、測るのはここ 1 か所:
5
- // 箱 形の要素そのもの(<rect>・<path>・<ellipse>・<polygon>)に data-part="box"・data-part-id
6
- // 辺 <g data-part="edge" data-part-id data-part-from data-part-to>。線そのもの(<line> か <path>)に data-part-line(矢じりは除く)。1 つの辺に線が 2 本のこともある
5
+ // 箱 形の要素そのもの(<rect>・<path>・<ellipse>・<polygon>・<circle>)に data-part="box"・data-part-id。形の中かは isPointInFill で測る
6
+ // 辺 <g data-part="edge" data-part-id data-part-from data-part-to>。線そのもの(<line> か <path>)に data-part-line(矢じりは除く)。1 つの辺に線が 2 本のこともある。
7
+ // 端(from・to)は箱の id か点(mark)の id(点から字への引き出し線。handoff #45 の決定 2)。端が点なら、その点の字と、その点を中に持つ箱は、この辺の通過・横切りの相手にしない
7
8
  // 字 <text data-part="label" data-part-id=<持ち主> data-part-of="box|edge|mark">。縁取りがあれば data-part-halo、箱の外に置く字は data-part-at="outside"。
8
9
  // foreignObject の字は中身を Range で測る
9
10
  // 点 data-part="mark"(m-quad の点。<g transform> の中の <circle cx=0 cy=0> でも getBoundingClientRect で測る)。字の障害物
10
11
  // @ で始まる端(@spine・@moved など)は節でない
12
+ // わざと重ねる所:要素そのものか祖先の <g> に o.overlap の印(data-overlap="ok"、kit/core/layout-scan.mjs の OVERLAP_ATTR。handoff #45 の決定 3)。
13
+ // その要素が関わる重なりの知らせ(geoEdgeThroughBox・geoLineOverLabel・geoLabelOverlap)を出さない。値は "ok" だけ。箱の縁を越える字(geoLabelOutsideBox)は重なりでないので外さない
14
+ // 枠の中(handoff #46。属性の名前は WITHIN_ATTRS の 1 か所):図形に data-within="名前"、枠に data-frame="名前"。名前は 1 つ(WITHIN_NAME)。宣言した図形だけを、ステップごとに測る(geometrySteps)。
15
+ // 名前の形に合わない値は測らず、要素ごとに geoBadMarkName(警告。a: {el, kind: 'shape'|'frame', attr, value})で知らせる
16
+ // 図の端で欠ける線(handoff #52):印は要らない。インラインの SVG(作成者の図もパーツの図も)の線のある形の要素を、ステップごとに測る(geometrySteps)
11
17
  //
12
- // geometryScan(s, o) → [{code, sev, a}] s:最終段階まで出したスライドの <section>。o = {bands, dflt}
18
+ // geometryScan(s, o) → [{code, sev, a}] s:最終段階まで出したスライドの <section>。o = {bands, dflt, overlap, within, frame, name, clip}
13
19
  // bands 字体ごとの字の範囲(kit/core/text-band.mjs の TEXT_BANDS。{字体の名前: {up, down}}、em)
14
20
  // dflt 表にない字体だけの字の範囲(DEFAULT_BAND)
21
+ // overlap わざと重ねる印の属性の名前(OVERLAP_ATTR)。なければ外さない
22
+ // within・frame 枠の中の印の属性の名前(WITHIN_ATTRS)
23
+ // name 枠の中の印の値の形(WITHIN_NAME。RegExp の source)。なければ枠の中は見ない
24
+ // clip わざと切る印の属性の名前(kit/core/layout-scan.mjs の CLIP_ATTR)。その中の形は図の端で欠けても知らせない
25
+ // o.mode === 'step' のときだけ、今の表示で測る 1 段階分を返す:枠の外に出た図形(geoOutsideFrame)と図の端で欠ける線(geoClippedStroke)
15
26
  // 縦書きのスライド(layout-tate)は測らない([] を返す。数は geometryTate)
16
- // geometryTate(slides) → n 縦横が混ざる教材で、測らなかった縦書きのスライドのうち印のあるものの数(geoTateSlides)。
27
+ // geometrySteps(s, o, seek, scan) → null | [{code: 'geoOutsideFrame', sev, a: {shape, frame, step, px, at, steps}} | {code: 'geoClippedStroke', sev, a: {shape, side, px, stroke, step, steps}}]
28
+ // スライドの全部のステップ(0 … s._max。static は 0 だけ)を seek(k) で出し、scan(= geometryScan)を o.mode = 'step' で呼ぶ(2 つの検査で 1 回だけ歩く)。
29
+ // 測るものがない(枠の中の印も、線のある形の入った SVG もない)スライドは歩かずに null。
30
+ // 図形(と枠)ごとに 1 つ:いちばん大きく出た・欠けたステップ(step。結論のステップは 'concl')とその値(px ほか)と、出た・欠けたステップの一覧(steps)。
31
+ // 最後のステップだけでは途中のはみ出しを逃す(backlog #91 の分裂期の染色体)。終わった後の表示は呼ぶ側が戻す
32
+ // geometryTate(slides, o) → n 縦横が混ざる教材で、測らなかった縦書きのスライドのうち印のあるものの数(geoTateSlides)。
17
33
  // 中身のスライド(表紙・章の扉を除く)がみな縦書きなら 0(そのときは決まりの台帳が R-geometry を skipped/tate にする。kit/core/check-rules.mjs の factsFromSource の allTate と同じ数え方)
18
34
  //
19
35
  // 座標はスライドの座標(1280×720。拡大率で割る)。
@@ -25,19 +41,39 @@
25
41
  // この関数は文字列にしてページに入れる(check.mjs は page.evaluate、編集アプリは仲立ちの文字列に埋める)。
26
42
  // だから外の名前を使わない(中だけで閉じる)。閉じるタグと HTML の注釈の始まりを書かない(tools/build-app.mjs が確かめる)
27
43
 
44
+ // 枠の中の印の名前(仕様 §8.4 Marks for geometry checks)。呼ぶ側が o.within・o.frame として渡す(kit/core/layout-scan.mjs の GEO_OPTS)
45
+ export const WITHIN_ATTRS = Object.freeze({ within: 'data-within', frame: 'data-frame' });
46
+ // その値の形:名前 1 つ(小文字の英字で始まり、小文字の英字・数字・-)。関数は外の名前を使えないので、呼ぶ側が o.name(RegExp の source)として渡す(GEO_OPTS)。
47
+ // これに合わない値は測らず、geoBadMarkName(警告)で知らせる(綴りの誤りで点検が黙って外れないように。handoff #46、11/18 の決定)
48
+ export const WITHIN_NAME = '^[a-z][a-z0-9-]*$';
49
+
28
50
  export function geometryScan(s, o) {
29
51
  const out = [];
30
52
  if (!s || s.classList.contains('layout-tate')) return out;
31
53
  const BANDS = (o && o.bands) || {}, DFLT = (o && o.dflt) || { up: 0.86, down: 0.26 };
32
54
  const SEL = (v) => '[data-part="' + v + '"]';
33
- if (!s.querySelector([SEL('box'), SEL('edge'), SEL('label'), SEL('mark')].join(','))) return out;
55
+ const STEP = !!(o && o.mode === 'step'), WA = (o && o.within) || '', FA = (o && o.frame) || '', OV = (o && o.overlap) || '', CL = (o && o.clip) || '';
56
+ const NAME = o && o.name ? new RegExp(o.name) : null;
57
+ const add = (sev, code, a) => out.push({ code, sev, a });
58
+ // 枠の中の印の値が名前 1 つ(o.name)でない(geoBadMarkName。handoff #46):その印は測らないので、黙って点検が外れないよう知らせる。
59
+ // 要素ごとに 1 つ(data-within と data-frame の両方が名前でなければ data-within のほう)。値の形だけを見るので、見えているかに依らない。
60
+ // 名前の合わない印だけのスライドも見る(下の data-part の有無で返す前に)。o.mode === 'step' のときは出さない(ステップごとに重なるので)
61
+ if (!STEP && NAME && WA && FA) {
62
+ const seen = { [WA]: 0, [FA]: 0 };
63
+ for (const el of s.querySelectorAll('[' + WA + '],[' + FA + ']')) {
64
+ const n = el.hasAttribute(WA) ? ++seen[WA] : 0, m = el.hasAttribute(FA) ? ++seen[FA] : 0;
65
+ const bad = [[WA, 'shape', n], [FA, 'frame', m]].find(([at]) => el.hasAttribute(at) && !NAME.test(el.getAttribute(at)));
66
+ if (bad) add('warn', 'geoBadMarkName', { el: el.getAttribute('data-part-id') || el.id || el.localName + '#' + bad[2], kind: bad[1], attr: bad[0], value: el.getAttribute(bad[0]) });
67
+ }
68
+ }
69
+ const WITHIN = STEP && !!WA && !!FA && !!NAME && !!s.querySelector('[' + WA + ']'), EDGE = STEP && !!s.querySelector('svg');
70
+ if (STEP ? !WITHIN && !EDGE : !s.querySelector([SEL('box'), SEL('edge'), SEL('label'), SEL('mark')].join(','))) return out;
34
71
  const sr = s.getBoundingClientRect();
35
72
  const k = sr.width / 1280 || 1;
36
73
  const SX = (x) => (x - sr.left) / k, SY = (y) => (y - sr.top) / k;
37
74
  const box = (r) => ({ l: SX(r.left), t: SY(r.top), r: SX(r.right), b: SY(r.bottom) });
38
75
  const rnd = (v) => Math.round(v);
39
76
  const rr = (q) => [rnd(q.l), rnd(q.t), rnd(q.r), rnd(q.b)];
40
- const add = (sev, code, a) => out.push({ code, sev, a });
41
77
  const TOL = 2;
42
78
 
43
79
  // 字体の並び → 字の範囲(kit/core/text-band.mjs の textBand と同じ決め方:並びの中で表にある字体の最も広いもの、なければ dflt)
@@ -72,37 +108,75 @@ export function geometryScan(s, o) {
72
108
  };
73
109
  const strokeOf = (el, M) => { const w = parseFloat(getComputedStyle(el).strokeWidth); return (isFinite(w) ? w : 1) * (M ? M.sc : 1); };
74
110
  const textOf = (el) => (el.textContent || '').replace(/\s+/g, ' ').trim().slice(0, 40);
111
+ // わざと重ねる印(data-overlap="ok"):要素そのものか、スライドの中の祖先の <g>
112
+ const okOverlap = (el) => {
113
+ if (!OV) return false;
114
+ for (let e = el; e && e !== s; e = e.parentElement) if ((e === el || e.localName === 'g') && e.getAttribute(OV) === 'ok') return true;
115
+ return false;
116
+ };
117
+
118
+ // 形の要素の輪郭(getTotalLength・getPointAtLength でスライドの座標 step px ごと、8〜2000 点)。測れなければ []
119
+ const outline = (el, step) => {
120
+ const M = mapper(el);
121
+ if (!M) return [];
122
+ let len = 0;
123
+ try { len = el.getTotalLength(); } catch (e) { len = 0; }
124
+ if (!(len > 0)) return [];
125
+ const n = Math.min(2000, Math.max(8, Math.ceil(len * M.sc / step)));
126
+ const pts = [];
127
+ for (let i = 0; i <= n; i++) { const p = el.getPointAtLength(len * i / n); pts.push(M.pt(p.x, p.y)); }
128
+ return pts;
129
+ };
130
+ // 点から折れ線(閉じた輪郭)のいちばん近い点 {x, y, d}
131
+ const nearRing = (ring, x, y) => {
132
+ let best = { x, y, d: Infinity };
133
+ for (let i = 0; i < ring.length; i++) {
134
+ const a = ring[i], b = ring[(i + 1) % ring.length], dx = b.x - a.x, dy = b.y - a.y, L2 = dx * dx + dy * dy;
135
+ const t = L2 > 0 ? Math.max(0, Math.min(1, ((x - a.x) * dx + (y - a.y) * dy) / L2)) : 0;
136
+ const qx = a.x + dx * t, qy = a.y + dy * t, d = Math.hypot(x - qx, y - qy);
137
+ if (d < best.d) best = { x: qx, y: qy, d };
138
+ }
139
+ return best;
140
+ };
141
+ const toRing = (ring, x, y) => nearRing(ring, x, y).d;
142
+ // 矩形の周りの点(4px ごと)
143
+ const rectRing = (q) => {
144
+ const pts = [], w = q.r - q.l, h = q.b - q.t, n = Math.max(1, Math.ceil(w / 4)), m = Math.max(1, Math.ceil(h / 4));
145
+ for (let i = 0; i <= n; i++) { const x = q.l + w * i / n; pts.push({ x, y: q.t }, { x, y: q.b }); }
146
+ for (let j = 1; j < m; j++) { const y = q.t + h * j / m; pts.push({ x: q.l, y }, { x: q.r, y }); }
147
+ return pts;
148
+ };
75
149
 
76
150
  // ---------------------------------------------------------------- 箱
77
151
  const boxes = [];
78
- for (const el of s.querySelectorAll(SEL('box'))) {
152
+ if (!STEP) for (const el of s.querySelectorAll(SEL('box'))) {
79
153
  if (!shown(el)) continue;
80
154
  const q = box(el.getBoundingClientRect());
81
155
  if (q.r - q.l <= 0 || q.b - q.t <= 0) continue;
82
156
  const M = mapper(el);
83
157
  let inv = null;
84
158
  if (M && typeof el.isPointInFill === 'function') { try { inv = M.m.inverse(); } catch (e) { inv = null; } }
85
- boxes.push({ el, id: el.getAttribute('data-part-id') || '', root: rootOf(el), q, inv, sw: strokeOf(el, M) });
159
+ boxes.push({ el, id: el.getAttribute('data-part-id') || '', root: rootOf(el), q, inv, sw: strokeOf(el, M), ok: okOverlap(el) });
86
160
  }
87
161
  // 点(スライドの座標)が箱の内側に tol より深く入っているか:点とそのまわり 8 方向の tol の点がみな箱の形の中
88
162
  // (形は isPointInFill。ひし形の <polygon>・楕円・角の丸い <rect> も形どおり。形を測れない要素は外接矩形)
89
163
  const DIRS = [[1, 0], [-1, 0], [0, 1], [0, -1], [0.7071, 0.7071], [0.7071, -0.7071], [-0.7071, 0.7071], [-0.7071, -0.7071]];
164
+ const inFillOf = (b, px, py) => {
165
+ const cx = sr.left + px * k, cy = sr.top + py * k, m = b.inv;
166
+ try { return b.el.isPointInFill(new DOMPoint(m.a * cx + m.c * cy + m.e, m.b * cx + m.d * cy + m.f)); } catch (e) { return true; }
167
+ };
90
168
  const deepIn = (b, x, y, tol) => {
91
169
  if (x <= b.q.l + tol || x >= b.q.r - tol || y <= b.q.t + tol || y >= b.q.b - tol) return false;
92
170
  if (!b.inv) return true;
93
- const inFill = (px, py) => {
94
- const cx = sr.left + px * k, cy = sr.top + py * k, m = b.inv;
95
- try { return b.el.isPointInFill(new DOMPoint(m.a * cx + m.c * cy + m.e, m.b * cx + m.d * cy + m.f)); } catch (e) { return true; }
96
- };
97
- if (!inFill(x, y)) return false;
98
- for (const d of DIRS) if (!inFill(x + d[0] * tol, y + d[1] * tol)) return false;
171
+ if (!inFillOf(b, x, y)) return false;
172
+ for (const d of DIRS) if (!inFillOf(b, x + d[0] * tol, y + d[1] * tol)) return false;
99
173
  return true;
100
174
  };
101
175
 
102
176
  // ---------------------------------------------------------------- 辺(線ごとの折れ線、スライドの座標)
103
177
  const LINE = 'line,path,polyline,polygon';
104
178
  const edges = [];
105
- for (const g of s.querySelectorAll(SEL('edge'))) {
179
+ if (!STEP) for (const g of s.querySelectorAll(SEL('edge'))) {
106
180
  if (!shown(g)) continue;
107
181
  const id = g.getAttribute('data-part-id') || '', from = g.getAttribute('data-part-from') || '', to = g.getAttribute('data-part-to') || '';
108
182
  const els = g.matches(LINE) && g.hasAttribute('data-part-line') ? [g] : [...g.querySelectorAll('[data-part-line]')].filter((x) => x.matches(LINE));
@@ -122,9 +196,9 @@ export function geometryScan(s, o) {
122
196
  const n = Math.min(2000, Math.max(2, Math.ceil(len * M.sc / 4)));
123
197
  for (let i = 0; i <= n; i++) { const p = el.getPointAtLength(len * i / n); pts.push(M.pt(p.x, p.y)); }
124
198
  }
125
- lines.push({ el, pts, tol: strokeOf(el, M) / 2 + TOL });
199
+ lines.push({ el, pts, tol: strokeOf(el, M) / 2 + TOL, ok: okOverlap(el) });
126
200
  }
127
- if (lines.length) edges.push({ el: g, id, from, to, root: rootOf(g), lines });
201
+ if (lines.length) edges.push({ el: g, id, from, to, root: rootOf(g), lines, ok: okOverlap(g) });
128
202
  }
129
203
  // 折れ線を 2px ごとの点に細かくする(箱の通過を見る)
130
204
  const dense = (pts) => {
@@ -195,18 +269,232 @@ export function geometryScan(s, o) {
195
269
  }
196
270
  return htmlTextRects(el);
197
271
  };
272
+
273
+ // ---------------------------------------------------------------- 0. 図形が枠の外に出る(geoOutsideFrame の 1 段階分。o.mode === 'step'。handoff #46)
274
+ // 図形(data-within="名前")の輪郭の点が、同じ名前の枠(data-frame="名前")の形の中にあるかを、今の表示で測る。
275
+ // 図形の点:形の要素(SVGGeometryElement)は輪郭を getTotalLength・getPointAtLength で 2px ごと(多くても 2000 点)。<g> なら中の見えている形の要素と字の全部。
276
+ // 字は字の範囲(上の textRects。R-geometry の text-band と同じ値)の周り。HTML の要素は外接矩形の周り
277
+ // 枠:形の要素なら isPointInFill(楕円・円・多角形も形どおり)と、輪郭の折れ線までの距離。そのほか(<g>・HTML)は外接矩形
278
+ // はみ出しの量:点が枠の外なら枠の輪郭までの距離。図形の線の太さの半分を足し、枠の線の太さの半分を引く(線どうしが重なって描けているなら中)。2px までは中とみなす
279
+ // 同じ名前の枠が同じ図(rootOf)にいくつもあれば、いちばんよく収まる枠と比べる(表のマスなど)。同じ図になければスライドの中から。見えている枠がなければ測らない
280
+ const GEOM = 'path,rect,circle,ellipse,line,polyline,polygon';
281
+ const NOT_DRAWN = 'defs,clipPath,mask,marker,pattern,symbol';
282
+ const halfPaint = (el) => {
283
+ const st = getComputedStyle(el);
284
+ if (st.stroke === 'none' || parseFloat(st.strokeOpacity) === 0) return 0;
285
+ return strokeOf(el, mapper(el)) / 2;
286
+ };
287
+ // ---------------------------------------------------------------- 0'. 図形の線が図の端で欠ける(geoClippedStroke の 1 段階分。o.mode === 'step'。handoff #52)
288
+ // インラインの SVG の、線(stroke)の見える形の要素(<rect>・<circle>・<ellipse>・<line>・<polyline>・<polygon>・<path>。字は svgTextOut が見る)ごとに、
289
+ // 描いた範囲(形の外接矩形を線の太さの半分だけ広げたもの。スライドの座標)を、その形を切る範囲(祖先の <svg> のうち overflow が visible でないものの見える範囲。
290
+ // 外側の <svg> は箱、中の <svg> は x・y・width・height。軸ごと)と比べる。overflow が visible の <svg>(属性でも CSS でも)は切らないので見ない。
291
+ // 描いた範囲:変形が回転・傾きのない(ふつうの)形は getBBox の角を getScreenCTM で写し、線の太さの半分を足す。回転した形は輪郭(outline)の点の外接矩形。
292
+ // 開いた線(<line>・<polyline>・z のない <path>)は輪郭の点を法線の向きにだけ線の太さの半分ずらす(butt の端は長さの向きに出ない。round・square の端は出る)
293
+ // 知らせるのは「事故の形」:どこかの辺で 1px より多く欠け、かつ描いた範囲の 9 割以上が見える範囲の中(大半が外の飾りは知らせない)。
294
+ // 9 割は面積の割合(軸ごとの重なりの割合の積)。太さのない向き(水平・垂直の線の太さの向き)は割合に入れない(端に沿う線は、太さの半分が欠けても長さは中)
295
+ // 測らないもの:線のない形(塗りだけの背景は端からはみ出させることが多い)・見えない形・defs など描かれない所・KaTeX・目印の重ね(svg.marks)・
296
+ // わざと切る印(o.clip)の中・clip-path か mask の付いた形(とその祖先)・data-overlap="ok"(要素そのものか祖先の <g>)
297
+ // 1 つの形の値:side(左右上下の欠けた量、1px 以下は 0)・px(いちばん大きい量)・stroke(形そのものは中にあり、線の太さの分だけ欠ける)
298
+ const clippedStrokes = () => {
299
+ const SVGNS = 'http://www.w3.org/2000/svg';
300
+ const SKIP = NOT_DRAWN + ',text,.katex,svg.marks' + (CL ? ',[' + CL + ']' : '');
301
+ const CUT = 1, SHARE = 0.9;
302
+ // <svg> の見える範囲({l, t, r, b, x, y}。x・y はその軸で切るか)。切らないか、大きさがなければ null
303
+ const vps = new Map();
304
+ const viewport = (e) => {
305
+ if (vps.has(e)) return vps.get(e);
306
+ let v = null;
307
+ const st = getComputedStyle(e), x = st.overflowX !== 'visible', y = st.overflowY !== 'visible';
308
+ if (x || y) {
309
+ const p = e.parentElement, outer = !p || p.namespaceURI !== SVGNS || p.localName === 'foreignObject';
310
+ let q = null;
311
+ if (outer) q = box(e.getBoundingClientRect());
312
+ else {
313
+ const M = mapper(p);
314
+ if (M) {
315
+ const X = e.x.baseVal.value, Y = e.y.baseVal.value, W = e.width.baseVal.value, H = e.height.baseVal.value;
316
+ const c = [M.pt(X, Y), M.pt(X + W, Y), M.pt(X, Y + H), M.pt(X + W, Y + H)];
317
+ q = { l: Math.min.apply(null, c.map((a) => a.x)), r: Math.max.apply(null, c.map((a) => a.x)), t: Math.min.apply(null, c.map((a) => a.y)), b: Math.max.apply(null, c.map((a) => a.y)) };
318
+ }
319
+ }
320
+ if (q && q.r - q.l > 0 && q.b - q.t > 0) v = Object.assign(q, { x, y });
321
+ }
322
+ vps.set(e, v);
323
+ return v;
324
+ };
325
+ // 形を切る範囲:祖先の <svg> の見える範囲を重ねたもの(外側の <svg> まで)。どれも切らなければ null
326
+ const clipOf = (el) => {
327
+ let q = null;
328
+ for (let e = el.parentElement; e && e !== s; e = e.parentElement) {
329
+ if (e.localName !== 'svg' || e.namespaceURI !== SVGNS) continue;
330
+ const v = viewport(e);
331
+ if (v) {
332
+ if (!q) q = { l: -Infinity, t: -Infinity, r: Infinity, b: Infinity, x: false, y: false };
333
+ if (v.x) { q.l = Math.max(q.l, v.l); q.r = Math.min(q.r, v.r); q.x = true; }
334
+ if (v.y) { q.t = Math.max(q.t, v.t); q.b = Math.min(q.b, v.b); q.y = true; }
335
+ }
336
+ const p = e.parentElement;
337
+ if (!p || p.namespaceURI !== SVGNS || p.localName === 'foreignObject') break;
338
+ }
339
+ return q;
340
+ };
341
+ const cutBy = (el) => {
342
+ for (let e = el; e && e !== s; e = e.parentElement) {
343
+ const st = getComputedStyle(e);
344
+ if ((st.clipPath && st.clipPath !== 'none') || (st.maskImage && st.maskImage !== 'none')) return true;
345
+ if (e.localName === 'svg' && (!e.parentElement || e.parentElement.namespaceURI !== SVGNS)) break;
346
+ }
347
+ return false;
348
+ };
349
+ const bbOf = (pts) => ({ l: Math.min.apply(null, pts.map((p) => p.x)), r: Math.max.apply(null, pts.map((p) => p.x)), t: Math.min.apply(null, pts.map((p) => p.y)), b: Math.max.apply(null, pts.map((p) => p.y)) });
350
+ const grow = (q, w) => ({ l: q.l - w, t: q.t - w, r: q.r + w, b: q.b + w });
351
+ const seen = {};
352
+ for (const el of s.querySelectorAll(GEOM)) {
353
+ const tag = el.localName;
354
+ seen[tag] = (seen[tag] || 0) + 1;
355
+ const nth = seen[tag];
356
+ if (el.namespaceURI !== SVGNS || el.closest(SKIP) || okOverlap(el)) continue;
357
+ const C = clipOf(el);
358
+ if (!C) continue;
359
+ const st = getComputedStyle(el);
360
+ if (st.stroke === 'none' || parseFloat(st.strokeOpacity) === 0 || !(parseFloat(st.strokeWidth) > 0)) continue;
361
+ const M = mapper(el);
362
+ if (!M) continue;
363
+ let bb;
364
+ try { bb = el.getBBox(); } catch (e) { continue; }
365
+ // 線の太さの半分(スライドの座標)。non-scaling-stroke は画面の px
366
+ const w = (st.vectorEffect === 'non-scaling-stroke' ? parseFloat(st.strokeWidth) / k : strokeOf(el, M)) / 2;
367
+ const g0 = bbOf([M.pt(bb.x, bb.y), M.pt(bb.x + bb.width, bb.y), M.pt(bb.x, bb.y + bb.height), M.pt(bb.x + bb.width, bb.y + bb.height)]);
368
+ // 端から離れた形は細かく測らない(回転した形の外接矩形は実際より大きいので、離れていればなお離れている。square の端の斜めの角まで見て 1.5 倍)
369
+ const w2 = w * 1.5;
370
+ if ((!C.x || (g0.l - w2 - C.l > CUT && C.r - g0.r - w2 > CUT)) && (!C.y || (g0.t - w2 - C.t > CUT && C.b - g0.b - w2 > CUT))) continue;
371
+ if (!shown(el) || cutBy(el)) continue;
372
+ const rot = Math.abs(M.m.b) > 1e-6 || Math.abs(M.m.c) > 1e-6;
373
+ const open = tag === 'line' || tag === 'polyline' || (tag === 'path' && !/z/i.test(el.getAttribute('d') || ''));
374
+ let g = g0, p;
375
+ if (!open) {
376
+ if (rot) { const pts = outline(el, 4); if (pts.length) g = bbOf(pts); }
377
+ p = grow(g, w);
378
+ } else {
379
+ const pts = tag === 'line' ? [M.pt(el.x1.baseVal.value, el.y1.baseVal.value), M.pt(el.x2.baseVal.value, el.y2.baseVal.value)] : outline(el, 4);
380
+ if (pts.length < 2) continue;
381
+ g = bbOf(pts);
382
+ const ps = [], cap = st.strokeLinecap;
383
+ for (let i = 0; i < pts.length; i++) {
384
+ const a = pts[Math.max(0, i - 1)], b = pts[Math.min(pts.length - 1, i + 1)], L = Math.hypot(b.x - a.x, b.y - a.y);
385
+ if (!(L > 0)) continue;
386
+ const tx = (b.x - a.x) / L, ty = (b.y - a.y) / L, nx = -ty * w, ny = tx * w, q = pts[i];
387
+ ps.push({ x: q.x + nx, y: q.y + ny }, { x: q.x - nx, y: q.y - ny });
388
+ const end = i === 0 ? -1 : i === pts.length - 1 ? 1 : 0;
389
+ if (end && cap === 'round') ps.push({ x: q.x - w, y: q.y }, { x: q.x + w, y: q.y }, { x: q.x, y: q.y - w }, { x: q.x, y: q.y + w });
390
+ if (end && cap === 'square') { const ex = end * tx * w, ey = end * ty * w; ps.push({ x: q.x + ex + nx, y: q.y + ey + ny }, { x: q.x + ex - nx, y: q.y + ey - ny }); }
391
+ }
392
+ if (!ps.length) continue;
393
+ p = bbOf(ps);
394
+ }
395
+ const side = { left: C.x ? C.l - p.l : 0, right: C.x ? p.r - C.r : 0, top: C.y ? C.t - p.t : 0, bottom: C.y ? p.b - C.b : 0 };
396
+ const worst = Math.max(side.left, side.right, side.top, side.bottom);
397
+ if (!(worst > CUT)) continue;
398
+ const share = (a0, a1, c0, c1, thin) => (thin || a1 - a0 <= 0 ? 1 : Math.max(0, Math.min(a1, c1) - Math.max(a0, c0)) / (a1 - a0));
399
+ const inside = share(p.l, p.r, C.l, C.r, !C.x || g.r - g.l < 1) * share(p.t, p.b, C.t, C.b, !C.y || g.b - g.t < 1);
400
+ if (inside < SHARE) continue;
401
+ // 形そのもの(線の太さを除く)は見える範囲の中か(中なら線だけが欠ける)
402
+ const geo = Math.max(C.x ? C.l - g.l : 0, C.x ? g.r - C.r : 0, C.y ? C.t - g.t : 0, C.y ? g.b - C.b : 0);
403
+ for (const kk of Object.keys(side)) side[kk] = side[kk] > CUT ? rnd(side[kk]) : 0;
404
+ add('warn', 'geoClippedStroke', { shape: el.getAttribute('data-part-id') || el.id || tag + '#' + nth, side, px: rnd(worst), stroke: geo <= CUT });
405
+ }
406
+ };
407
+
408
+ if (WITHIN) {
409
+ const shapePts = (el) => {
410
+ const pts = [];
411
+ const geo = (g) => { const w = halfPaint(g); for (const p of outline(g, 2)) pts.push({ x: p.x, y: p.y, w }); };
412
+ const txt = (t) => { for (const r of textRects(t)) for (const p of rectRing(r)) pts.push({ x: p.x, y: p.y, w: 0 }); };
413
+ if (el.namespaceURI === 'http://www.w3.org/2000/svg' && el.localName !== 'svg') {
414
+ if (el.matches(GEOM)) geo(el);
415
+ else if (el.localName === 'text' || el.localName === 'foreignObject') txt(el);
416
+ else {
417
+ for (const g of el.querySelectorAll(GEOM)) if (shown(g) && !g.closest(NOT_DRAWN)) geo(g);
418
+ for (const t of el.querySelectorAll('text,foreignObject')) if (shown(t) && !t.parentElement.closest('text,foreignObject')) txt(t);
419
+ }
420
+ } else for (const p of rectRing(box(el.getBoundingClientRect()))) pts.push({ x: p.x, y: p.y, w: 0 });
421
+ return pts;
422
+ };
423
+ const frameOf = (el) => {
424
+ if (el.namespaceURI === 'http://www.w3.org/2000/svg' && typeof el.isPointInFill === 'function') {
425
+ const M = mapper(el);
426
+ let inv = null;
427
+ try { inv = M && M.m.inverse(); } catch (e) { inv = null; }
428
+ const ring = outline(el, 2);
429
+ if (inv && ring.length > 2) {
430
+ return {
431
+ half: halfPaint(el),
432
+ inside: (x, y) => { const cx = sr.left + x * k, cy = sr.top + y * k; try { return el.isPointInFill(new DOMPoint(inv.a * cx + inv.c * cy + inv.e, inv.b * cx + inv.d * cy + inv.f)); } catch (e) { return true; } },
433
+ dist: (x, y) => toRing(ring, x, y),
434
+ };
435
+ }
436
+ }
437
+ const q = box(el.getBoundingClientRect());
438
+ return {
439
+ half: 0,
440
+ inside: (x, y) => x >= q.l && x <= q.r && y >= q.t && y <= q.b,
441
+ dist: (x, y) => (x >= q.l && x <= q.r && y >= q.t && y <= q.b ? Math.min(x - q.l, q.r - x, y - q.t, q.b - y) : Math.hypot(Math.max(q.l - x, 0, x - q.r), Math.max(q.t - y, 0, y - q.b))),
442
+ };
443
+ };
444
+ // 名前は 1 つだけ(o.name)。並べた名前・大文字・空などの値は測らない(枠の側も同じ値でしか合わない)。その値は geoBadMarkName が最後のステップで 1 度知らせる
445
+ const all = [...s.querySelectorAll('[' + WA + ']')];
446
+ all.forEach((el, n) => {
447
+ const name = el.getAttribute(WA) || '';
448
+ if (!NAME.test(name) || !shown(el)) return;
449
+ const sel = '[' + FA + '="' + name + '"]';
450
+ const root = rootOf(el);
451
+ let fs = [...s.querySelectorAll(sel)].filter((f) => f !== el && !el.contains(f) && shown(f));
452
+ const near = fs.filter((f) => rootOf(f) === root);
453
+ if (near.length) fs = near;
454
+ if (!fs.length) return;
455
+ const pts = shapePts(el);
456
+ if (!pts.length) return;
457
+ let best = null;
458
+ for (const f of fs) {
459
+ const F = frameOf(f);
460
+ let worst = -Infinity, at = null;
461
+ for (const p of pts) {
462
+ let v;
463
+ if (F.inside(p.x, p.y)) { if (p.w - F.half <= TOL) continue; v = p.w - F.half - F.dist(p.x, p.y); }
464
+ else v = F.dist(p.x, p.y) + p.w - F.half;
465
+ if (v > worst) { worst = v; at = p; }
466
+ }
467
+ if (!best || worst < best.worst) best = { worst, at };
468
+ if (best.worst <= TOL) break;
469
+ }
470
+ if (best && best.worst > TOL) {
471
+ add('warn', 'geoOutsideFrame', { shape: el.getAttribute('data-part-id') || el.id || el.localName + '#' + (n + 1), frame: name, px: rnd(best.worst), at: [rnd(best.at.x), rnd(best.at.y)] });
472
+ }
473
+ });
474
+ }
475
+ if (STEP) {
476
+ if (EDGE) clippedStrokes();
477
+ return out;
478
+ }
479
+
198
480
  const labels = [];
199
481
  for (const el of s.querySelectorAll(SEL('label'))) {
200
482
  if (!shown(el)) continue;
201
483
  const rs = textRects(el);
202
484
  if (!rs.length) continue;
203
- labels.push({ el, id: el.getAttribute('data-part-id') || '', of: el.getAttribute('data-part-of') || '', outside: el.getAttribute('data-part-at') === 'outside', halo: el.hasAttribute('data-part-halo'), t: textOf(el), root: rootOf(el), rs });
485
+ labels.push({ el, id: el.getAttribute('data-part-id') || '', of: el.getAttribute('data-part-of') || '', outside: el.getAttribute('data-part-at') === 'outside', halo: el.hasAttribute('data-part-halo'), t: textOf(el), root: rootOf(el), rs, ok: okOverlap(el) });
204
486
  }
205
487
  const marks = [];
206
488
  for (const el of s.querySelectorAll(SEL('mark'))) {
207
489
  if (!shown(el)) continue;
208
490
  const q = box(el.getBoundingClientRect());
209
- if (q.r - q.l > 0 && q.b - q.t > 0) marks.push({ el, id: el.getAttribute('data-part-id') || '', root: rootOf(el), q });
491
+ if (q.r - q.l > 0 && q.b - q.t > 0) marks.push({ el, id: el.getAttribute('data-part-id') || '', root: rootOf(el), q, ok: okOverlap(el) });
492
+ }
493
+ // 辺の端が点(mark)のとき:その点の字と、その点を中に持つ箱は、この辺の相手にしない(点から字への引き出し線。handoff #45 の決定 2)
494
+ for (const E of edges) {
495
+ const ends = marks.filter((Mk) => Mk.root === E.root && Mk.id && (Mk.id === E.from || Mk.id === E.to));
496
+ E.markIds = ends.map((Mk) => Mk.id);
497
+ E.inBoxes = boxes.filter((B) => B.root === E.root && ends.some((Mk) => deepIn(B, (Mk.q.l + Mk.q.r) / 2, (Mk.q.t + Mk.q.b) / 2, 0)));
210
498
  }
211
499
  const meet = (a, b, tol) => {
212
500
  const q = { l: Math.max(a.l, b.l), t: Math.max(a.t, b.t), r: Math.min(a.r, b.r), b: Math.min(a.b, b.b) };
@@ -215,10 +503,12 @@ export function geometryScan(s, o) {
215
503
 
216
504
  // ---------------------------------------------------------------- 1. 辺が元でも先でもない箱の内側を通る(geoEdgeThroughBox)
217
505
  for (const E of edges) {
506
+ if (E.ok) continue;
218
507
  for (const B of boxes) {
219
- if (B.root !== E.root || B.id === E.from || B.id === E.to) continue;
508
+ if (B.root !== E.root || B.id === E.from || B.id === E.to || B.ok || E.inBoxes.includes(B)) continue;
220
509
  let seg = null;
221
510
  for (const L of E.lines) {
511
+ if (L.ok) continue;
222
512
  let first = null, last = null;
223
513
  for (const p of dense(L.pts)) {
224
514
  if (deepIn(B, p.x, p.y, L.tol)) { if (!first) first = p; last = p; }
@@ -245,10 +535,12 @@ export function geometryScan(s, o) {
245
535
  return { x: a.x + dx * tm, y: a.y + dy * tm };
246
536
  };
247
537
  for (const E of edges) {
538
+ if (E.ok) continue;
248
539
  for (const Lb of labels) {
249
- if (Lb.root !== E.root || (Lb.of === 'edge' && Lb.id === E.id) || E.el.contains(Lb.el)) continue;
540
+ if (Lb.root !== E.root || Lb.ok || (Lb.of === 'edge' && Lb.id === E.id) || (Lb.of === 'mark' && E.markIds.includes(Lb.id)) || E.el.contains(Lb.el)) continue;
250
541
  let at = null;
251
542
  for (const L of E.lines) {
543
+ if (L.ok) continue;
252
544
  for (const r of Lb.rs) {
253
545
  const q = { l: r.l + L.tol, t: r.t + L.tol, r: r.r - L.tol, b: r.b - L.tol };
254
546
  if (q.r <= q.l || q.b <= q.t) continue;
@@ -264,15 +556,16 @@ export function geometryScan(s, o) {
264
556
  // ---------------------------------------------------------------- 3. 字の範囲どうし・字と持ち主でない点が重なる(geoLabelOverlap)
265
557
  for (let i = 0; i < labels.length; i++) {
266
558
  const A = labels[i];
559
+ if (A.ok) continue;
267
560
  for (let j = i + 1; j < labels.length; j++) {
268
561
  const B = labels[j];
269
- if (A.root !== B.root || A.el.contains(B.el) || B.el.contains(A.el)) continue;
562
+ if (A.root !== B.root || B.ok || A.el.contains(B.el) || B.el.contains(A.el)) continue;
270
563
  let q = null;
271
564
  for (const r of A.rs) { for (const u of B.rs) if ((q = meet(r, u, TOL))) break; if (q) break; }
272
565
  if (q) add('warn', 'geoLabelOverlap', { label: A.id, of: A.of, t: A.t, other: B.id, otherOf: B.of, u: B.t, mark: false, rect: rr(q) });
273
566
  }
274
567
  for (const Mk of marks) {
275
- if (Mk.root !== A.root || (A.of === 'mark' && A.id === Mk.id) || Mk.el.contains(A.el) || A.el.contains(Mk.el)) continue;
568
+ if (Mk.root !== A.root || Mk.ok || (A.of === 'mark' && A.id === Mk.id) || Mk.el.contains(A.el) || A.el.contains(Mk.el)) continue;
276
569
  let q = null;
277
570
  for (const r of A.rs) if ((q = meet(r, Mk.q, TOL))) break;
278
571
  if (q) add('warn', 'geoLabelOverlap', { label: A.id, of: A.of, t: A.t, other: Mk.id, otherOf: 'mark', u: '', mark: true, rect: rr(q) });
@@ -280,23 +573,68 @@ export function geometryScan(s, o) {
280
573
  }
281
574
 
282
575
  // ---------------------------------------------------------------- 4. 箱の中の字が箱の縁を越える(geoLabelOutsideBox)。data-part-at="outside" の字は見ない
576
+ // <rect> の箱は外接矩形と比べる。<circle>・<ellipse>・<polygon>・<path> の箱は形と比べる(ほかの点検と同じ isPointInFill と輪郭までの距離):
577
+ // 字の範囲の周りの点のうち形の外のものについて、輪郭のいちばん近い点からのずれを左右上下に分けて、いちばん大きいものを px にする(2px までは中)
283
578
  for (const Lb of labels) {
284
579
  if (Lb.of !== 'box' || Lb.outside) continue;
285
580
  const B = boxes.find((b) => b.id === Lb.id && b.root === Lb.root);
286
581
  if (!B) continue;
287
582
  const l = Math.min.apply(null, Lb.rs.map((r) => r.l)), r = Math.max.apply(null, Lb.rs.map((x) => x.r));
288
583
  const t = Math.min.apply(null, Lb.rs.map((x) => x.t)), b = Math.max.apply(null, Lb.rs.map((x) => x.b));
584
+ const ring = B.inv && B.el.localName !== 'rect' ? outline(B.el, 2) : [];
585
+ if (ring.length > 2) {
586
+ const d = { left: 0, right: 0, top: 0, bottom: 0 };
587
+ let worst = 0;
588
+ for (const q of Lb.rs) for (const p of rectRing(q)) {
589
+ if (inFillOf(B, p.x, p.y)) continue;
590
+ const o = nearRing(ring, p.x, p.y);
591
+ worst = Math.max(worst, o.d);
592
+ d.left = Math.max(d.left, o.x - p.x); d.right = Math.max(d.right, p.x - o.x); d.top = Math.max(d.top, o.y - p.y); d.bottom = Math.max(d.bottom, p.y - o.y);
593
+ }
594
+ if (worst > TOL) add('warn', 'geoLabelOutsideBox', { box: B.id, t: Lb.t, px: { left: rnd(d.left), right: rnd(d.right), top: rnd(d.top), bottom: rnd(d.bottom) }, rect: rr({ l, t, r, b }), boxRect: rr(B.q) });
595
+ continue;
596
+ }
289
597
  const px = { left: rnd(Math.max(0, B.q.l - l)), right: rnd(Math.max(0, r - B.q.r)), top: rnd(Math.max(0, B.q.t - t)), bottom: rnd(Math.max(0, b - B.q.b)) };
290
598
  if (B.q.l - l > TOL || r - B.q.r > TOL || B.q.t - t > TOL || b - B.q.b > TOL) add('warn', 'geoLabelOutsideBox', { box: B.id, t: Lb.t, px, rect: rr({ l, t, r, b }), boxRect: rr(B.q) });
291
599
  }
292
600
  return out;
293
601
  }
294
602
 
603
+ // 図形が枠の外に出る(geoOutsideFrame。handoff #46)を、スライドの全部のステップで測ってまとめる。geometryScan と同じく文字列でページに入れる。
604
+ // seek(k):そのステップの終わりの表示にする(kit/check.mjs と編集アプリは DECK.seek(i, k, Infinity))。scan:geometryScan(中で外の名前を使えないので渡してもらう)
605
+ export function geometrySteps(s, o, seek, scan) {
606
+ if (!s || s.classList.contains('layout-tate')) return null;
607
+ const WA = (o && o.within) || '', CL = (o && o.clip) || '';
608
+ // 歩くのは、枠の中の印があるか、形の要素の入った、切る(overflow が visible でない)SVG があるスライドだけ
609
+ const SKIP = '.katex,svg.marks' + (CL ? ',[' + CL + ']' : '');
610
+ const svgs = [].filter.call(s.querySelectorAll('svg'), (g) => {
611
+ if (g.closest(SKIP) || !g.querySelector('path,rect,circle,ellipse,line,polyline,polygon')) return false;
612
+ const st = getComputedStyle(g);
613
+ return st.overflowX !== 'visible' || st.overflowY !== 'visible';
614
+ });
615
+ if (!(WA && s.querySelector('[' + WA + ']')) && !svgs.length) return null;
616
+ const max = s.classList.contains('static') ? 0 : (isFinite(s._max) && s._max > 0 ? s._max : 0);
617
+ const oo = Object.assign({}, o, { mode: 'step' }), by = new Map(), order = [];
618
+ for (let k = 0; k <= max; k++) {
619
+ seek(k);
620
+ const name = k === s._cstep ? 'concl' : String(k);
621
+ for (const f of scan(s, oo)) {
622
+ const key = f.code + '\n' + f.a.shape + '\n' + (f.a.frame || '');
623
+ let r = by.get(key);
624
+ if (!r) { r = { code: f.code, sev: f.sev, a: Object.assign({}, f.a, { step: name, steps: [] }) }; by.set(key, r); order.push(r); }
625
+ r.a.steps.push(name);
626
+ if (f.a.px > r.a.px) r.a = Object.assign({}, f.a, { step: name, steps: r.a.steps });
627
+ }
628
+ }
629
+ return order;
630
+ }
631
+
295
632
  // 縦横が混ざる教材で、形の点検から外した縦書きのスライド(印のあるもの)の数。中身のスライドがみな縦書きなら 0。geometryScan と同じく文字列でページに入れる
296
- export function geometryTate(slides) {
633
+ // 印:data-part の 4 つと、枠の中の印(o.within・o.frame。渡されたときだけ)
634
+ export function geometryTate(slides, o) {
297
635
  const content = [].filter.call(slides || [], (s) => !s.classList.contains('cover') && !s.classList.contains('sec'));
298
636
  const tate = content.filter((s) => s.classList.contains('layout-tate'));
299
637
  if (!tate.length || tate.length === content.length) return 0;
300
- const sel = ['box', 'edge', 'label', 'mark'].map((v) => '[data-part="' + v + '"]').join(',');
638
+ const sel = ['box', 'edge', 'label', 'mark'].map((v) => '[data-part="' + v + '"]').concat(o && o.within ? ['[' + o.within + ']'] : [], o && o.frame ? ['[' + o.frame + ']'] : []).join(',');
301
639
  return tate.filter((s) => !!s.querySelector(sel)).length;
302
640
  }
@@ -23,7 +23,7 @@
23
23
  // だから外の名前を使わない(中だけで閉じる)。仲立ちはデッキの script の要素の中にそのまま入るので、閉じるタグと HTML の注釈の始まりを書かない(tools/build-app.mjs が確かめる)
24
24
 
25
25
  import { findRawMath } from './raw-math.mjs';
26
- import { geometryScan, geometryTate } from './geometry-check.mjs';
26
+ import { geometryScan, geometrySteps, geometryTate, WITHIN_ATTRS, WITHIN_NAME } from './geometry-check.mjs';
27
27
  import { TEXT_BANDS, DEFAULT_BAND } from './text-band.mjs';
28
28
 
29
29
  // わざと切る印(CLIP_ATTR。docs/contract.md §10):その要素の中(子孫も、SVG の字も)は、箱で切れる・スライドの外に出る・
@@ -38,6 +38,11 @@ export const ANNOT_ATTR = 'data-annot';
38
38
  // その SVG の字は textOverlap だけを見ない。値は "ok" だけ(空の属性やほかの値は効かない)。部品全体でなく、重ねる字だけに付ける。
39
39
  export const OVERLAP_ATTR = 'data-overlap';
40
40
 
41
+ // 描いた図の形の点検(kit/core/geometry-check.mjs)に渡す値:字の範囲の表(kit/core/text-band.mjs)・わざと重ねる印の名前(OVERLAP_ATTR。R-geometry も見る、handoff #45)・
42
+ // 枠の中の印の名前(WITHIN_ATTRS)と値の形(WITHIN_NAME。handoff #46)・わざと切る印の名前(CLIP_ATTR。その中は図の端で欠ける線 geoClippedStroke を見ない、handoff #52)。
43
+ // コマンド版(kit/check.mjs)・編集アプリ(withLayoutScan)・試験が同じこれを使う
44
+ export const GEO_OPTS = Object.freeze({ bands: TEXT_BANDS, dflt: DEFAULT_BAND, overlap: OVERLAP_ATTR, within: WITHIN_ATTRS.within, frame: WITHIN_ATTRS.frame, name: WITHIN_NAME, clip: CLIP_ATTR });
45
+
41
46
  export function layoutScan(s, o) {
42
47
  const JA = !!o.JA, CLIP = o.clip, ANNOT = o.annot, OVERLAP = o.overlap, refRe = new RegExp(o.refRe);
43
48
  // テーマの寸法(1280×720 の px)。既定は kit/core/theme-metrics.mjs の DEFAULT_METRICS と同じ値
@@ -759,9 +764,9 @@ export async function metricsFonts(doc, timeoutMs) {
759
764
 
760
765
  // 編集アプリの仲立ち(app/frame-shim.js の文字列。「(function frameShim(cfg){…})」)に、この関数・寸法の比べ方(metricsProbe・metricsFonts)・残った数式の検出(findRawMath)と印の名前を渡す形にする。
761
766
  // 戻り値も「(…)(cfg)」で呼べる 1 つの式(仲立ちの中では layoutScan・metricsProbe・metricsFonts・findRawMath・LAYOUT_CLIP・LAYOUT_ANNOT・LAYOUT_OVERLAP という名前で使える)
762
- // 描いた図の形の点検(kit/core/geometry-check.mjs の geometryScan・geometryTate)と字の範囲の表(GEO_OPTS = {bands: TEXT_BANDS, dflt: DEFAULT_BAND})も同じ名前で渡す
767
+ // 描いた図の形の点検(kit/core/geometry-check.mjs の geometryScan・geometrySteps・geometryTate)とその値(上の GEO_OPTS)も同じ名前で渡す
763
768
  export function withLayoutScan(shimSrc) {
764
769
  // 仲立ちの文字列は注釈の行から始まるので、return の後ろで改行して括弧で囲む(return の直後の改行で式が切れないように)
765
770
  // findRawMath(kit/core/raw-math.mjs):組まれずに残った数式(rawMath)。コマンド版(kit/check.mjs)と同じ関数を仲立ちにも渡す
766
- return `(function(layoutScan, LAYOUT_CLIP, LAYOUT_ANNOT, LAYOUT_OVERLAP, metricsProbe, metricsFonts, findRawMath, geometryScan, geometryTate, GEO_OPTS){return (\n${String(shimSrc).trim()}\n);})(${layoutScan}, ${JSON.stringify(CLIP_ATTR)}, ${JSON.stringify(ANNOT_ATTR)}, ${JSON.stringify(OVERLAP_ATTR)}, ${metricsProbe}, ${metricsFonts}, ${findRawMath}, ${geometryScan}, ${geometryTate}, ${JSON.stringify({ bands: TEXT_BANDS, dflt: DEFAULT_BAND })})`;
771
+ return `(function(layoutScan, LAYOUT_CLIP, LAYOUT_ANNOT, LAYOUT_OVERLAP, metricsProbe, metricsFonts, findRawMath, geometryScan, geometrySteps, geometryTate, GEO_OPTS){return (\n${String(shimSrc).trim()}\n);})(${layoutScan}, ${JSON.stringify(CLIP_ATTR)}, ${JSON.stringify(ANNOT_ATTR)}, ${JSON.stringify(OVERLAP_ATTR)}, ${metricsProbe}, ${metricsFonts}, ${findRawMath}, ${geometryScan}, ${geometrySteps}, ${geometryTate}, ${JSON.stringify(GEO_OPTS)})`;
767
772
  }
@@ -80,9 +80,9 @@ export function LivePolicy(opts) {
80
80
  if (!parseEndpoint(live.endpoint)) add('endpoint', 'live.endpoint', {}, 'live.endpoint: not an https origin (e.g. https://live.example.org)');
81
81
  if (!str(live.room) || !RE.room.test(live.room)) add('room', 'live.room', {}, 'live.room: not a room id (r- and 8 characters a-z, 2-7)');
82
82
  if (wantKey) { if (!str(live.key) || !RE.key.test(live.key)) add('key', 'live.key', {}, 'live.key: not a key (22 or more characters A-Z a-z 0-9 _ -)'); }
83
- else if (own(live, 'key')) add('keyStored', 'live.key', {}, 'live.key: the key must not be stored in the lesson (it goes only into the exported file)');
83
+ else if (own(live, 'key')) add('keyStored', 'live.key', {}, 'live.key: the key must not be stored in the file (it goes only into the exported file)');
84
84
  if (own(live, 'sourceSha256')) {
85
- if (!wantKey) add('unknownMember', 'live.sourceSha256', { member: 'sourceSha256' }, 'live.sourceSha256: only in the exported file (the lesson has its own sourceSha256)');
85
+ if (!wantKey) add('unknownMember', 'live.sourceSha256', { member: 'sourceSha256' }, 'live.sourceSha256: only in the exported file (the file has its own sourceSha256)');
86
86
  else if (!str(live.sourceSha256) || !RE.sha256.test(live.sourceSha256)) add('sourceSha256', 'live.sourceSha256', {}, 'live.sourceSha256: not 64 lowercase hex digits');
87
87
  }
88
88
  var w = live.window;
package/kit/core/live.mjs CHANGED
@@ -231,8 +231,8 @@ export function localToRfc3339(value, offsetMin) {
231
231
  const LABEL_MAX = LP.LIMITS.label;
232
232
  const HEADING_MAX = 24;
233
233
  const WORDS = {
234
- ja: { whole: '教材全体', step: (k) => `ステップ ${k}`, concl: '結論', slide: (n, h, st) => `${n} 枚目『${h}』・${st}`, fb: (s, st) => `${s} · ${st}` },
235
- en: { whole: 'whole lesson', step: (k) => `step ${k}`, concl: 'conclusion', slide: (n, h, st) => `Slide ${n} '${h}', ${st}`, fb: (s, st) => `${s} · ${st}` },
234
+ ja: { whole: 'ファイル全体', step: (k) => `ステップ ${k}`, concl: '結論', slide: (n, h, st) => `${n} 枚目『${h}』・${st}`, fb: (s, st) => `${s} · ${st}` },
235
+ en: { whole: 'whole file', step: (k) => `step ${k}`, concl: 'conclusion', slide: (n, h, st) => `Slide ${n} '${h}', ${st}`, fb: (s, st) => `${s} · ${st}` },
236
236
  };
237
237
  const words = (lang) => WORDS[lang === 'en' ? 'en' : 'ja'];
238
238
  const cut = (t, n) => { const c = [...t]; return c.length <= n ? t : c.slice(0, n - 1).join('').trimEnd() + '…'; };