egatari 0.6.18 → 0.6.20-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/CHANGELOG.md +33 -1
  2. package/README.ja.md +7 -2
  3. package/README.md +7 -2
  4. package/components.lock.json +40 -12
  5. package/components2.lock.json +534 -1
  6. package/kit/build.mjs +1 -1
  7. package/kit/check-messages.mjs +4 -0
  8. package/kit/check.mjs +6 -2
  9. package/kit/core/bookmark.mjs +13 -0
  10. package/kit/core/build-core.mjs +1 -1
  11. package/kit/core/check-parity.mjs +2 -0
  12. package/kit/core/check-rules.mjs +1 -1
  13. package/kit/core/check-source.mjs +4 -1
  14. package/kit/core/checks.mjs +79 -0
  15. package/kit/core/find-replace.mjs +170 -0
  16. package/kit/core/format.mjs +4 -1
  17. package/kit/core/image-insert.mjs +197 -0
  18. package/kit/core/image-size.mjs +1 -1
  19. package/kit/core/layout-scan.mjs +1 -1
  20. package/kit/core/llm-fix.mjs +1 -1
  21. package/kit/core/llm-pack-assemble.mjs +17 -10
  22. package/kit/core/llm-pack-data.mjs +94 -30
  23. package/kit/core/llm-pack.mjs +2 -1
  24. package/kit/core/part-labels.mjs +1 -0
  25. package/kit/core/portable.mjs +5 -2
  26. package/kit/core/scorm.mjs +30 -6
  27. package/kit/core/script-unclosed.mjs +66 -0
  28. package/kit/core/slide-ops.mjs +5 -1
  29. package/kit/core/template-text.mjs +2 -0
  30. package/kit/deck.js +71 -4
  31. package/kit/instruction-version.json +1 -1
  32. package/kit/layouts.css +8 -0
  33. package/kit/panes.js +17 -1
  34. package/kit/player.json +1 -1
  35. package/kit/player.lock.json +2 -2
  36. package/kit/templates/new-deck.mjs +1 -1
  37. package/kit/tools.js +136 -4
  38. package/kit/track.js +46 -5
  39. package/package.json +1 -1
  40. package/server/editor-ui.js +21 -1
  41. package/server/script-field.js +1 -1
  42. package/vendor/components/CATALOG.md +5 -4
  43. package/vendor/components/sha256/15306d854d67d52ca2b1d66135f0d3296882e6b21fd85c029399b8077c8a7f9d/README.en.md +34 -0
  44. package/vendor/components/sha256/15306d854d67d52ca2b1d66135f0d3296882e6b21fd85c029399b8077c8a7f9d/index.js +398 -0
  45. package/vendor/components/sha256/277ac772315f93737a094cd0f0842726f2435d352d9a90822aebfe0d5d7e79a1/README.en.md +23 -0
  46. package/vendor/components/sha256/277ac772315f93737a094cd0f0842726f2435d352d9a90822aebfe0d5d7e79a1/index.js +294 -0
  47. package/vendor/components/sha256/3be5f64deb1951327b614b29a9b632878fab362687c76e3f48f3af1d1ebbb1cf/README.en.md +47 -0
  48. package/vendor/components/sha256/3be5f64deb1951327b614b29a9b632878fab362687c76e3f48f3af1d1ebbb1cf/index.js +223 -0
  49. package/vendor/components/sha256/7c7b0373cfd38fd5ecb4169021e0b908f0a17be1a29b14f85dd89fdb92e7bf81/README.en.md +44 -0
  50. package/vendor/components/sha256/7c7b0373cfd38fd5ecb4169021e0b908f0a17be1a29b14f85dd89fdb92e7bf81/index.js +306 -0
  51. package/vendor/components/sha256/8a9215c7fea15265c2f3038f3d01a2f72441fc1e931245dee46dcaacf3548a98/README.en.md +38 -0
  52. package/vendor/components/sha256/8a9215c7fea15265c2f3038f3d01a2f72441fc1e931245dee46dcaacf3548a98/index.js +414 -0
  53. package/vendor/components/sha256/91be5c714c046244436569ecac24d9d1eb84504b3e28d8899fc89a5865e8d955/README.en.md +40 -0
  54. package/vendor/components/sha256/91be5c714c046244436569ecac24d9d1eb84504b3e28d8899fc89a5865e8d955/index.js +355 -0
  55. package/vendor/components/sha256/939bdae590ebed3d182b0c9940a35b6c03872505bfa242341990a81cae02fd06/README.en.md +34 -0
  56. package/vendor/components/sha256/939bdae590ebed3d182b0c9940a35b6c03872505bfa242341990a81cae02fd06/index.js +397 -0
  57. package/vendor/components/sha256/9a426812105a44446e8b3f98e0ccfdb6701e8386c08e8aa201b69cb5b52a4c1f/index.js +278 -0
  58. package/vendor/components/sha256/9c5dd0bc0c3279c5f0fea3fdb9d0735870880aef96e8bbf9ecdd77dff0f5ddc8/README.en.md +44 -0
  59. package/vendor/components/sha256/9c5dd0bc0c3279c5f0fea3fdb9d0735870880aef96e8bbf9ecdd77dff0f5ddc8/index.js +551 -0
  60. package/vendor/components/sha256/a5b032657720d3beb64f0b3699954e13b0eb985f36161b9ae046c83fd6048ff5/README.en.md +18 -0
  61. package/vendor/components/sha256/a5b032657720d3beb64f0b3699954e13b0eb985f36161b9ae046c83fd6048ff5/index.js +382 -0
  62. package/vendor/components/sha256/ad4d42a34eff125d8ccd7caf9ac329b7a8092960e7ee872fdeb853bd9c57942f/README.en.md +54 -0
  63. package/vendor/components/sha256/ad4d42a34eff125d8ccd7caf9ac329b7a8092960e7ee872fdeb853bd9c57942f/index.js +470 -0
  64. package/vendor/components/sha256/b35d01e480a203dc27aa18b0d341cc1cbc2dcca69235e909919484f1545b371f/README.en.md +23 -0
  65. package/vendor/components/sha256/b35d01e480a203dc27aa18b0d341cc1cbc2dcca69235e909919484f1545b371f/index.js +150 -0
  66. package/vendor/components-2/manifest-2.20.0.json +3217 -0
  67. package/vendor/components-2/manifest-2.21.0.json +3220 -0
  68. package/vendor/components-2/manifest-2.22.0.json +3240 -0
  69. package/vendor/egatari-spec/SOURCE.json +2 -2
  70. package/vendor/egatari-spec/schema/deck-meta.schema.json +3 -0
  71. package/vendor/egatari-spec/schema/egatari-metadata.schema.json +6 -0
@@ -2,6 +2,8 @@
2
2
  // BOOKMARK_MAX 名前の字数の上限(20。字は code point で数える)
3
3
  // bookmarkName(v) 属性の値 → 見せる名前(空白を 1 つにして前後を除く。なければ '')
4
4
  // bookmarkLength(name) 字数(code point)
5
+ // bookmarkDefault(heading, taken) しおりを付けるときの既定の名前:見出しを 20 字で切ったもの。taken(ほかのスライドのしおりの名前)と
6
+ // 同じなら、後ろに「 2」「 3」…を足して 20 字に収める(同じ名前が並ばない:bookmarkDup を出さない)。見出しがなければ ''
5
7
  // bookmarkFindings(src) 原稿の文字列 → [{i, sev, code, a}]。品質チェックのコマンド版(kit/check.mjs)と編集アプリ(kit/core/check-source.mjs)が同じものを出す
6
8
  // bookmarkDup:同じ名前のしおりが 2 枚以上(名前ごとに 1 つ、最初のスライドに。a = {name, n})
7
9
  // bookmarkLong:名前が 20 字を超える(スライドごと。a = {name, n})
@@ -10,6 +12,17 @@ import { analyzeSlideIds } from './build-core.mjs';
10
12
  export const BOOKMARK_MAX = 20;
11
13
  export const bookmarkName = (v) => String(v == null ? '' : v).replace(/\s+/g, ' ').trim();
12
14
  export const bookmarkLength = (name) => [...String(name)].length;
15
+ const cutTo = (s, n) => [...s].slice(0, Math.max(0, n)).join('').trim();
16
+ export function bookmarkDefault(heading, taken = []) {
17
+ const base = cutTo(bookmarkName(heading), BOOKMARK_MAX);
18
+ if (!base) return '';
19
+ const used = new Set([...taken].map(bookmarkName));
20
+ if (!used.has(base)) return base;
21
+ for (let k = 2; ; k++) {
22
+ const suf = ' ' + k, n = cutTo(base, BOOKMARK_MAX - bookmarkLength(suf)) + suf;
23
+ if (!used.has(n)) return n;
24
+ }
25
+ }
13
26
 
14
27
  export function bookmarkFindings(src) {
15
28
  const out = [];
@@ -838,7 +838,7 @@ export function classicModule(src, name) {
838
838
 
839
839
  // 実行系に入れる kit/core の ES モジュールのうち、export が複数のもの(import なし・export function / export const だけ)。
840
840
  // 即時関数の中で読み、export したものを DECK.<name> の object に入れる(読み上げで聞く:kit/tools.js が使う。format spec §5.6)
841
- export const RUNTIME_NAMESPACES = Object.freeze({ 'core/tts-normalize.mjs': 'TtsNormalize', 'core/read-aloud.mjs': 'ReadAloud', 'core/narration-parse.mjs': 'Narration', 'core/sounds.mjs': 'Sounds', 'core/sound-preferences.mjs': 'SoundPreferences' });
841
+ export const RUNTIME_NAMESPACES = Object.freeze({ 'core/tts-normalize.mjs': 'TtsNormalize', 'core/read-aloud.mjs': 'ReadAloud', 'core/narration-parse.mjs': 'Narration', 'core/sounds.mjs': 'Sounds', 'core/sound-preferences.mjs': 'SoundPreferences', 'core/checks.mjs': 'Checks' });
842
842
  export function classicNamespace(src, name) {
843
843
  const s = String(src);
844
844
  const names = [...s.matchAll(/^export\s+(?:function|const)\s+([A-Za-z_$][\w$]*)/gm)].map((m) => m[1]);
@@ -17,6 +17,8 @@ export const IN_EDITOR = Object.freeze([
17
17
  'bookmarkDup', 'bookmarkLong',
18
18
  // 縦と横の入れ替わり(kit/core/tate-mix.mjs)
19
19
  'tateMixed',
20
+ // 閉じていない <script>(kit/core/script-unclosed.mjs)
21
+ 'scriptUnclosed',
20
22
  // 組み立てた文書の埋め込み画像から(kit/core/image-size.mjs)
21
23
  'imgTooLarge', 'imgTotal',
22
24
  'narrNote', 'narrFormula', 'turnLong', 'narrLang', 'predictAnswerWithCount', 'predictAnswerNeverShown',
@@ -68,7 +68,7 @@ export const RULES = Object.freeze([
68
68
  { id: 'R-dialogue', kind: 'authoring', phase: 'B 台本', codes: ['turnLong'], applies: needs('narration', 'noNarration') },
69
69
  { id: 'R-marks', kind: 'authoring', phase: 'F 強調', codes: ['markMissing'], applies: needs('marks', 'noMarks') },
70
70
  { id: 'R-steps', kind: 'authoring', phase: 'E タイムライン', codes: ['predictAnswerWithCount', 'predictAnswerNeverShown'], applies: (f) => ((f.parts || []).includes('m-predict') ? null : 'noParts') },
71
- { id: 'R-components', kind: 'authoring', phase: 'E タイムライン', codes: ['compReport', 'compData'], applies: (f) => ((f.parts || []).length ? null : 'noParts') },
71
+ { id: 'R-components', kind: 'authoring', phase: 'E タイムライン', codes: ['compReport', 'compData', 'scriptUnclosed'], applies: (f) => ((f.parts || []).length ? null : 'noParts') },
72
72
  // ---- 検査器の族(C-*)
73
73
  { id: 'C-build', kind: 'checker', phase: '読み込み', codes: ['build', 'consoleError', 'extensionVersion', 'component-requires-missing', 'component-not-in-catalogue'] },
74
74
  // しおり(format spec §8.0)の名前もスライドの宛先なので、id と同じ族(bookmarkDup・bookmarkLong)
@@ -4,7 +4,7 @@
4
4
  // I:id の書式・重なり(slideId)、旧来の鍵(legacyDataKey・legacyIndex)、1.0 の語彙にない書き方(legacyColorClass・legacyStepAttr・legacyLectureMode)、
5
5
  // 予想(m-predict)の答えが数の棒と同時(predictAnswerWithCount)・steps が小さく答えが出ない(predictAnswerNeverShown)、
6
6
  // テーマの色の語彙の外の色(colorOutside、情報)、{#id} の見出しとスライドの見出しの違い(narrHeadingDiffers、情報)
7
- // 肩見出しの長さ・置き場所・スライドの種類(kickerLong・kickerPlace・kickerSlide)
7
+ // 肩見出しの長さ・置き場所・スライドの種類(kickerLong・kickerPlace・kickerSlide)、閉じていない <script>(scriptUnclosed)
8
8
  // B:{note:} の書き損じ(narrNote)、式らしい台本(narrFormula)、長すぎる 1 ターン(turnLong、情報)、台本の言語がスライドと違う(narrLang、情報)
9
9
  // コマンド版は台本の段階を実行系(DECK.NARRATION)から取る。ここは narration.md から取り、どのスライドにも合わない節は見ない(それは組み立ての知らせ)
10
10
  import { analyzeSlideIds, isJapanese } from './build-core.mjs';
@@ -14,6 +14,7 @@ import { kickerFindings } from './kicker.mjs';
14
14
  import { cautionFindings } from './caution.mjs';
15
15
  import { bookmarkFindings } from './bookmark.mjs';
16
16
  import { tateMixFindings } from './tate-mix.mjs';
17
+ import { scriptUnclosedFindings } from './script-unclosed.mjs';
17
18
  import { predictStepProblems } from './predict-steps.mjs';
18
19
  import { parseNarration, normalizeKey, noteProblems } from './narration-parse.mjs';
19
20
  import { narrationLang, textLang, formulaLike, formulaText } from './narration-lint.mjs';
@@ -28,6 +29,8 @@ export function sourceFindings({ deck, narration = '', voiceLang } = {}) {
28
29
  for (const f of bookmarkFindings(deck)) add(f.i, f.sev, f.code, f.a);
29
30
  // 縦と横の入れ替わり(#70。kit/core/tate-mix.mjs、コマンド版と同じ)
30
31
  for (const f of tateMixFindings(deck)) add(f.i, f.sev, f.code, f.a);
32
+ // 閉じていない <script>(#96。kit/core/script-unclosed.mjs、コマンド版と同じ)
33
+ for (const f of scriptUnclosedFindings(deck)) add(f.i, f.sev, f.code, f.a);
31
34
  const ids = analyzeSlideIds(deck);
32
35
  for (const p of ids.problems) add(p.slide, p.sev, 'slideId', { msg: p.msg });
33
36
  for (const s of ids.slides) {
@@ -0,0 +1,79 @@
1
+ // 確認問題(パーツの問いへの答え。format spec §8.4 ctx.answer・§9.2 completion.checks、spec bindings/scorm12.md §2.1・§3)の純ロジック
2
+ // - import なし・DOM と node: に触れない:再生器では build(kit/core/build-core.mjs の classicNamespace)が DECK.Checks にし(kit/track.js が使う)、
3
+ // 試験と包み(kit/core/scorm.mjs)は ES モジュールとして読む
4
+ // - 問いの鍵は包み方 §2.1 の `<slideKey>/<スライドの中のパーツの番号>/<id>`。スライドの鍵と id は encodeURIComponent で ASCII にする
5
+ // (cmi.suspend_data は ASCII、鍵は , でつなぐ)。ふつうの鍵(s-abc123)と id(q)はそのまま
6
+ // - 数えるのは「少なくとも 1 回」(§9.2):一度答えた・正解した問いは、後で外しても答えた・正解したまま。最後の答え(latest)は別に持つ
7
+ // - ファイルの問いは、パーツのクラスが宣言した questions(§8.4)の、要素ごとの 1 組(§9.2。開いたときに数える:kit/deck.js の DECK.questions)。
8
+ // 宣言にない問いの答えは使わない(§8.4:無視する。recordAnswer も宣言した問いだけを記録する)
9
+ // - 正解のある問い:まだ答えていない問いと、correct が true か false で答えた問い。null だけで答えた問いは正解がない(§9.2)。
10
+ // 点数の分母も同じ組(包み方 §2.1)。再開のデータには答えた(qa)と正解した(qc)しかないので、qa にあって qc にない問いは
11
+ // true か false で答えたとみなす(点数を上げない・"correct" では正解するまで満たさない側に倒す)
12
+ //
13
+ // checksRule(completion) → "answered" | "correct" | null(知らない値は null:今までの決まりのまま)
14
+ // questionKey(slideKey, index, id) → 問いの鍵
15
+ // answerValue(correct, value) → {correct, value?}(形の違う知らせは null)
16
+ // newAnswers(declared?) → {declared, answered, correct, right, latest}(鍵 → 1 の object。declared はファイルの問いの鍵の並びから。
17
+ // right は true か false で答えた問い。latest は鍵 → {correct, value?})
18
+ // recordAnswer(state, key, correct, value?) → 記録したか(宣言にない鍵は false。同じ鍵は最後の答えで置き換え、答えた・正解したは残す)
19
+ // checksMet(rule, state) → 確認問題の条件を満たしたか(rule がなければ true):"answered" はどの問いにも答えた、"correct" は正解のある問いすべてに正解した
20
+ // scoreOf(state) → 正解のある問いのうち正解した割合(0〜100 の整数)。正解のある問いがなければ null
21
+ // keysText(set) → 鍵を , でつないだ字(名前の順)。keysFrom(text) → 鍵の並び(形の違う鍵は捨てる)
22
+ // restoreAnswers(state, qa, qc) → state(再開のデータの qa・qc を足す。宣言にない鍵は捨てる)
23
+
24
+ const KEY_RE = /^[A-Za-z0-9%._~!*'()-]+\/(0|[1-9][0-9]*)\/[A-Za-z0-9%._~!*'()-]+$/;
25
+ const own = (o, k) => Object.prototype.hasOwnProperty.call(o, k);
26
+
27
+ export function checksRule(completion) {
28
+ const c = completion && typeof completion === 'object' ? completion.checks : undefined;
29
+ return c === 'answered' || c === 'correct' ? c : null;
30
+ }
31
+ export function questionKey(slideKey, index, id) {
32
+ return encodeURIComponent(String(slideKey)) + '/' + index + '/' + encodeURIComponent(String(id));
33
+ }
34
+ export function answerValue(correct, value) {
35
+ if (correct !== true && correct !== false && correct !== null) return null;
36
+ const r = { correct };
37
+ if (typeof value === 'string') r.value = value.slice(0, 1000);
38
+ else if (typeof value === 'number' && isFinite(value)) r.value = value;
39
+ return r;
40
+ }
41
+ export function newAnswers(declared) {
42
+ const d = Object.create(null);
43
+ (Array.isArray(declared) ? declared : []).forEach((k) => { d[k] = 1; });
44
+ return { declared: d, answered: Object.create(null), correct: Object.create(null), right: Object.create(null), latest: Object.create(null) };
45
+ }
46
+ export function recordAnswer(state, key, correct, value) {
47
+ if (!own(state.declared, key)) return false;
48
+ state.answered[key] = 1;
49
+ if (correct === true || correct === false) state.right[key] = 1;
50
+ if (correct === true) state.correct[key] = 1;
51
+ state.latest[key] = value === undefined ? { correct } : { correct, value };
52
+ return true;
53
+ }
54
+ // 正解のある問い:宣言した問いのうち、null だけで答えた問いを除いたもの
55
+ const withRight = (state) => Object.keys(state.declared).filter((k) => !own(state.answered, k) || own(state.right, k));
56
+ export function checksMet(rule, state) {
57
+ if (rule === 'answered') return Object.keys(state.declared).every((k) => own(state.answered, k));
58
+ if (rule === 'correct') return withRight(state).every((k) => own(state.correct, k));
59
+ return true;
60
+ }
61
+ export function scoreOf(state) {
62
+ const right = withRight(state);
63
+ if (!right.length) return null;
64
+ const n = right.filter((k) => own(state.correct, k)).length;
65
+ return Math.round((100 * n) / right.length);
66
+ }
67
+ export function keysText(set) {
68
+ return Object.keys(set).sort().join(',');
69
+ }
70
+ export function keysFrom(text) {
71
+ if (typeof text !== 'string' || !text) return [];
72
+ return text.split(',').filter((k) => KEY_RE.test(k));
73
+ }
74
+ export function restoreAnswers(state, qa, qc) {
75
+ const c = keysFrom(qc).filter((k) => own(state.declared, k));
76
+ keysFrom(qa).filter((k) => own(state.declared, k)).forEach((k) => { state.answered[k] = 1; state.right[k] = 1; });
77
+ c.forEach((k) => { state.answered[k] = 1; state.right[k] = 1; state.correct[k] = 1; });
78
+ return state;
79
+ }
@@ -0,0 +1,170 @@
1
+ // 検索と置換(handoff #86):スライドの原稿(deck.html)と台本(narration.md)をまたいで、字を探して置き換える。Node にもブラウザにも依存しない
2
+ // (読み込むのは parse5・narration-parse・build-core だけ。編集アプリ app/find-panel.js と単体の試験 tools/test-find-replace.mjs が使う)
3
+ //
4
+ // 置き換えてもマークアップを壊さないように、探す場所を限る:
5
+ // 原稿:スライド(<section class="slide">)の中の字の部分だけ。タグ・属性・<script>・<style>・注釈の中は探さない。
6
+ // 文字参照(&amp; など)は字に戻して探し(「&」で &amp; が見つかる)、置換後の文字列は &・<・> を文字参照にして書く。
7
+ // 1 つの一致は 1 つの字の塊の中だけ(タグをまたがない)
8
+ // id も data-key もないスライドの最初の見出し(スライドの鍵になり、台本の節を結ぶ)も探さない
9
+ // 台本:ステップ([0]・[1]…・[concl])の話す字だけ。見出し(## …)・題(# …)・ステップの印([1])・話者(Expert: など)・注釈・拡張の行(@x-…)・
10
+ // 区切りと指示({cue}・{mark:…}・{note:…})は探さない。読み({語|よみ})は語の側だけを探す。置換後の文字列の改行は外す
11
+ //
12
+ // findMatches({deck, narr, query, matchCase?, scope?: 'all' | 'slides' | 'script'})
13
+ // → {matches: [{file: 'deck' | 'narr', start, end, text, slide(スライドの番号。台本は節のスライド、なければ null), slideKey?, stepKey?}], slides(一致のあるスライドの数), script(台本の一致の数)}
14
+ // 一致は重ならない(左から)。並びはスライドの順(同じスライドは原稿、台本の順)
15
+ // replaceMatches(text, matches, replacement, file) → 置き換えた文字列(matches はその text の上のもの。file が 'deck' なら文字参照にする)
16
+ import { parse } from 'parse5';
17
+ import { parseHeading, isStepKey, EXT_LINE } from './narration-parse.mjs';
18
+ import { analyzeSlideIds } from './build-core.mjs';
19
+
20
+ const NAMED = { amp: '&', lt: '<', gt: '>', quot: '"', apos: "'", nbsp: ' ' };
21
+ const SKIP = new Set(['script', 'style', 'noscript']);
22
+ const ROLE = /^(Expert|Novice|E|N)\s*[::]\s*/;
23
+
24
+ const attr = (n, name) => (n.attrs || []).find((a) => a.name === name);
25
+ const isSlide = (n) => n.tagName === 'section' && (attr(n, 'class')?.value || '').split(/\s+/).includes('slide');
26
+ const escRe = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
27
+ export const escHtml = (s) => String(s).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
28
+
29
+ // 原稿の字の塊(raw:原稿のまま、base:その先頭の位置)を字に戻し、字の 1 単位ごとに原稿の範囲 [from[i], to[i]) を持つ
30
+ export function decodeRun(raw, base = 0) {
31
+ let text = '';
32
+ const from = [], to = [];
33
+ for (let i = 0; i < raw.length;) {
34
+ let m = null;
35
+ if (raw[i] === '&') m = /^&(#\d{1,7}|#[xX][0-9a-fA-F]{1,6}|[a-zA-Z][a-zA-Z0-9]{1,31});/.exec(raw.slice(i, i + 40));
36
+ let ch = null;
37
+ if (m) {
38
+ const k = m[1];
39
+ if (k[0] === '#') { const cp = k[1] === 'x' || k[1] === 'X' ? parseInt(k.slice(2), 16) : parseInt(k.slice(1), 10); if (cp > 0 && cp <= 0x10ffff) ch = String.fromCodePoint(cp); }
40
+ else if (Object.prototype.hasOwnProperty.call(NAMED, k)) ch = NAMED[k];
41
+ }
42
+ if (ch !== null) {
43
+ for (let j = 0; j < ch.length; j++) { from.push(base + i); to.push(base + i + m[0].length); }
44
+ text += ch; i += m[0].length;
45
+ } else { text += raw[i]; from.push(base + i); to.push(base + i + 1); i++; }
46
+ }
47
+ return { text, from, to };
48
+ }
49
+
50
+ function walk(node, fn) {
51
+ if (fn(node) === false) return;
52
+ for (const c of node.childNodes || []) walk(c, fn);
53
+ if (node.content) walk(node.content, fn);
54
+ }
55
+ // 原稿のスライドの中の字の塊:[{slide, key, raw, base}]
56
+ export function deckRuns(deck) {
57
+ const doc = parse(String(deck), { sourceCodeLocationInfo: true });
58
+ const out = [];
59
+ let n = 0;
60
+ walk(doc, (s) => {
61
+ if (!s.tagName || !isSlide(s)) return true;
62
+ const slide = n++;
63
+ // id も data-key もないスライドは、最初の見出しが鍵(台本の節が見出しで結ばれる。build-core の analyzeSlideIds):置き換えると台本と離れるので探さない
64
+ let keyHead = null;
65
+ if (!attr(s, 'id') && !attr(s, 'data-key')) walk(s, (x) => { if (keyHead) return false; if (x.tagName === 'h2' || x.tagName === 'h1') { keyHead = x; return false; } return true; });
66
+ walk(s, (x) => {
67
+ if (x.tagName && SKIP.has(x.tagName)) return false;
68
+ if (x === keyHead) return false;
69
+ if (x.nodeName === '#text' && x.sourceCodeLocation) {
70
+ const { startOffset: a, endOffset: b } = x.sourceCodeLocation;
71
+ out.push({ slide, raw: deck.slice(a, b), base: a });
72
+ }
73
+ return true;
74
+ });
75
+ return false; // 入れ子のスライドは数えない
76
+ });
77
+ return { runs: out, count: n };
78
+ }
79
+ // 台本の話す字の塊:[{slideKey, stepKey, raw, base}](台本の字はそのまま。文字参照はない)
80
+ export function narrRuns(narr) {
81
+ const text = String(narr ?? '');
82
+ const out = [];
83
+ let slideKey = null, step = null, inComment = false, pos = 0;
84
+ const push = (s, base) => {
85
+ // {…} の外の字と、読み {語|よみ} の語の側だけ
86
+ let i = 0;
87
+ while (i < s.length) {
88
+ const o = s.indexOf('{', i);
89
+ const end = o < 0 ? s.length : o;
90
+ if (end > i) out.push({ slideKey, stepKey: step, raw: s.slice(i, end), base: base + i });
91
+ if (o < 0) break;
92
+ const c = s.indexOf('}', o + 1);
93
+ if (c < 0) { out.push({ slideKey, stepKey: step, raw: s.slice(o), base: base + o }); break; }
94
+ const inner = s.slice(o + 1, c);
95
+ if (!/^(cue$|mark:|note:)/.test(inner)) {
96
+ const bar = inner.indexOf('|');
97
+ if (bar > 0) out.push({ slideKey, stepKey: step, raw: inner.slice(0, bar), base: base + o + 1 });
98
+ else if (bar < 0 && inner) out.push({ slideKey, stepKey: step, raw: inner, base: base + o + 1 });
99
+ }
100
+ i = c + 1;
101
+ }
102
+ };
103
+ const content = (ln, at, base) => {
104
+ const rest = ln.slice(at), r = ROLE.exec(rest);
105
+ const off = at + (r ? r[0].length : 0);
106
+ if (off < ln.length) push(ln.slice(off), base + off);
107
+ };
108
+ for (const m of text.matchAll(/[^\r\n]*(\r\n|\r|\n|$)/g)) {
109
+ if (!m[0]) break;
110
+ const ln = m[0].replace(/(\r\n|\r|\n)$/, ''), base = pos;
111
+ pos += m[0].length;
112
+ if (inComment) { if (ln.includes('-->')) inComment = false; continue; }
113
+ if (/^\s*<!--/.test(ln) && !ln.includes('-->')) { inComment = true; continue; }
114
+ if (/^\s*<!--.*-->\s*$/.test(ln)) continue;
115
+ const h = /^##\s+(.+?)\s*$/.exec(ln);
116
+ if (h) { slideKey = parseHeading(h[1]).key; step = null; continue; }
117
+ if (/^#\s/.test(ln)) continue;
118
+ const s = /^(\s*\[(\d+|concl)\]\s*)(.*)$/.exec(ln);
119
+ if (s && slideKey !== null) {
120
+ step = isStepKey(s[2]) ? s[2] : null;
121
+ if (step !== null) content(ln, s[1].length, base);
122
+ continue;
123
+ }
124
+ if (step === null || !ln.trim() || EXT_LINE.test(ln)) continue;
125
+ content(ln, ln.length - ln.trimStart().length, base);
126
+ }
127
+ return out;
128
+ }
129
+
130
+ function search(runs, decoded, re, file) {
131
+ const out = [];
132
+ for (const r of runs) {
133
+ const d = decoded ? decodeRun(r.raw, r.base) : null;
134
+ const hay = d ? d.text : r.raw;
135
+ re.lastIndex = 0;
136
+ let m;
137
+ while ((m = re.exec(hay))) {
138
+ if (!m[0].length) { re.lastIndex++; continue; }
139
+ const a = m.index, b = a + m[0].length;
140
+ const start = d ? d.from[a] : r.base + a, end = d ? d.to[b - 1] : r.base + b;
141
+ out.push({ file, start, end, text: m[0], slide: r.slide ?? null, slideKey: r.slideKey ?? null, ...(file === 'narr' ? { stepKey: r.stepKey } : {}) });
142
+ }
143
+ }
144
+ return out;
145
+ }
146
+
147
+ export function findMatches({ deck, narr, query, matchCase = false, scope = 'all' }) {
148
+ const q = String(query ?? '');
149
+ if (!q) return { matches: [], slides: 0, script: 0 };
150
+ const re = new RegExp(escRe(q), matchCase ? 'g' : 'gi');
151
+ const D = deck != null ? deckRuns(String(deck)) : { runs: [], count: 0 };
152
+ const dm = scope === 'script' || deck == null ? [] : search(D.runs, true, re, 'deck');
153
+ let nm = scope === 'slides' || narr == null ? [] : search(narrRuns(narr), false, re, 'narr');
154
+ // 台本の節の鍵 → スライドの番号(組み立てと同じ鍵:id・data-key・見出し・s<n>)
155
+ const keys = deck != null ? analyzeSlideIds(String(deck)).slides.map((x) => x.key) : [];
156
+ const index = (k) => { const i = k == null ? -1 : keys.indexOf(k); return i < 0 ? null : i; };
157
+ nm = nm.map((x) => ({ ...x, slide: index(x.slideKey) }));
158
+ for (const x of dm) x.slideKey = keys[x.slide] ?? null;
159
+ const ord = (x) => (x.slide == null ? Infinity : x.slide);
160
+ const matches = [...dm, ...nm].sort((a, b) => ord(a) - ord(b) || (a.file === b.file ? a.start - b.start : a.file === 'deck' ? -1 : 1));
161
+ return { matches, slides: new Set(dm.map((x) => x.slide)).size, script: nm.length };
162
+ }
163
+
164
+ export function replaceMatches(text, matches, replacement, file) {
165
+ let rep = String(replacement ?? '');
166
+ rep = file === 'deck' ? escHtml(rep) : rep.replace(/[\r\n]+/g, ' ');
167
+ let out = String(text);
168
+ for (const m of [...matches].filter((x) => x.file === file).sort((a, b) => b.start - a.start)) out = out.slice(0, m.start) + rep + out.slice(m.end);
169
+ return out;
170
+ }
@@ -25,6 +25,8 @@ export const FORMAT = Object.freeze({
25
25
  SCHEMA_PREFIX: `${NAME}-`, // 仕様の Schema のファイル名の前置(<prefix>index.schema.json など)
26
26
  SCHEMA_BASE: 'https://egatari.org/schema/', // Schema の $id の前置(試験は写しを $id で引く。ネットワークは使わない)
27
27
  SPEC_URL: 'https://github.com/egatari/egatari-spec',
28
+ VERSIONS: Object.freeze(['1.0']), // 再生できる形式の版(major.minor。埋め込みの ready の formats、Player P8)
29
+ PLAYER_SPEC: '1.0', // 従うプレーヤーの文書(Egatari Player)の版(ready の player)
28
30
  VENDOR_DIR: `vendor/${NAME}-spec`, // 仕様の Schema と試験用の入力の写し(リポジトリの根から)
29
31
  // 授業の部屋(拡張 live。仕様の extensions/live.md):既定の部屋のサービス・通信の約束(egatari/live の protocol/)の写し・再生器の記憶の鍵の前置
30
32
  LIVE_ENDPOINT: `https://live.${NAME}.org`,
@@ -35,4 +37,5 @@ export const FORMAT = Object.freeze({
35
37
  });
36
38
  // 実行系(kit/deck.js)に渡す分(build-core が DECK.FORMAT として埋め込む)
37
39
  export const RUNTIME_FORMAT = Object.freeze({ id: FORMAT.FORMAT_ID, displayName: FORMAT.DISPLAY_NAME, blobPrefix: FORMAT.BLOB_PREFIX, uriScheme: FORMAT.URI_SCHEME, readableId: FORMAT.READABLE_ID,
38
- indexId: FORMAT.INDEX_ID, attachKey: FORMAT.ATTACH_KEY, attachDir: FORMAT.ATTACH_DIR, attachRoles: FORMAT.ATTACH_ROLES });
40
+ indexId: FORMAT.INDEX_ID, attachKey: FORMAT.ATTACH_KEY, attachDir: FORMAT.ATTACH_DIR, attachRoles: FORMAT.ATTACH_ROLES,
41
+ versions: FORMAT.VERSIONS, playerSpec: FORMAT.PLAYER_SPEC });
@@ -0,0 +1,197 @@
1
+ // 本文に画像を足す(編集アプリのスライド ▾ の「画像を挿入…」。app/image-insert.js。handoff #85)。Node にもブラウザにも依存しない(純粋な ESM)
2
+ // 原稿(deck.html)の文字列を受け取り、新しい文字列を返す。読み書きはしない。
3
+ // 自由な配置はしない:置き方は本文の中(全幅・半分・3 分の 1)と 2 列の左・右だけ。縦横比を保って幅に合わせる(はみ出しは今の品質チェック)。
4
+ // 体裁は今あるものだけ(kit/layouts.css の .fig・.cols。幅は要素の style)。画像は <img src="data:…">(SVG も data:image/svg+xml なので中のスクリプトは動かない)
5
+ //
6
+ // IMAGE_TYPES 受け取る画像の種類(PNG・JPEG・WebP・SVG)
7
+ // PLACEMENTS 置き方:'full' | 'half' | 'third' | 'left' | 'right'
8
+ // imageType(bytes) 中身(先頭のバイト)から種類を決める → IMAGE_TYPES のどれか | null(名前や申告の type は信じない)
9
+ // dataUrl(bytes, mime) → 'data:<mime>;base64,…'
10
+ // sizeNotice(n) 1 つの画像の目安(kit/core/image-size.mjs の MAX_IMAGE_BYTES、1 MiB)を超えれば MB の字(小数 1 桁)、超えなければ null
11
+ // slideSteps(src, index) そのスライドのステップの数(結論の行を除く){max, isStatic, auto, concl}。concl:結論の行があるか。auto:本文の直下の箇条が 1 つずつ出る形(kit/deck.js の autoList)
12
+ // imageHtml({src, alt, placement, step}) 入れる塊:<div class="fig"[ data-step]><img src alt style></div>
13
+ // insertImage(src, index, opts) index 番目のスライドに入れた原稿。本文(.body)の終わり(結論の行 .concl は .body の外なので、その前)、
14
+ // 2 列なら .body の直下の .cols の左・右の列の終わり。.cols がなければ本文を右(左)の列に入れて 2 列にする。
15
+ // ステップを付けるときと 2 列にするときは、本文の直下の箇条の自動のステップを data-step に書き出す(見え方を変えない)
16
+ import { parse } from 'parse5';
17
+ import { MAX_IMAGE_BYTES } from './image-size.mjs';
18
+
19
+ export const IMAGE_TYPES = Object.freeze(['image/png', 'image/jpeg', 'image/webp', 'image/svg+xml']);
20
+ export const PLACEMENTS = Object.freeze(['full', 'half', 'third', 'left', 'right']);
21
+ const WIDTH = { full: '100%', half: '50%', third: '33.333%', left: '100%', right: '100%' };
22
+ const MiB = 1048576;
23
+
24
+ // ---------------------------------------------------------------- 種類・data: URL・大きさの知らせ
25
+ export function imageType(bytes) {
26
+ const b = bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes || []);
27
+ const at = (i, ...xs) => xs.every((x, j) => b[i + j] === x);
28
+ if (at(0, 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a)) return 'image/png';
29
+ if (at(0, 0xff, 0xd8, 0xff)) return 'image/jpeg';
30
+ if (at(0, 0x52, 0x49, 0x46, 0x46) && at(8, 0x57, 0x45, 0x42, 0x50)) return 'image/webp';
31
+ // SVG:先頭(BOM・空白・<?xml …?>・注釈・<!DOCTYPE …> を除く)が <svg
32
+ let t;
33
+ try { t = new TextDecoder('utf-8', { fatal: false }).decode(b.subarray(0, 4096)); } catch { return null; }
34
+ t = t.replace(/^/, '');
35
+ for (let k = 0; k < 20; k++) {
36
+ const s = t.replace(/^\s+/, '');
37
+ const m = /^(<\?xml[\s\S]*?\?>|<!--[\s\S]*?-->|<!DOCTYPE[^>]*>)/i.exec(s);
38
+ if (!m) { t = s; break; }
39
+ t = s.slice(m[0].length);
40
+ }
41
+ return /^<svg[\s>]/i.test(t) ? 'image/svg+xml' : null;
42
+ }
43
+
44
+ export function dataUrl(bytes, mime) {
45
+ if (!IMAGE_TYPES.includes(mime)) throw new Error('unsupported image type: ' + mime);
46
+ const b = bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes);
47
+ let bin = '';
48
+ for (let i = 0; i < b.length; i += 0x8000) bin += String.fromCharCode.apply(null, b.subarray(i, i + 0x8000));
49
+ return `data:${mime};base64,${btoa(bin)}`;
50
+ }
51
+
52
+ export function sizeNotice(n) {
53
+ return n > MAX_IMAGE_BYTES ? (Math.round((n / MiB) * 10) / 10).toFixed(1) : null;
54
+ }
55
+
56
+ // ---------------------------------------------------------------- スライドの木
57
+ function walk(node, fn) {
58
+ if (fn(node) === false) return;
59
+ for (const c of node.childNodes || []) walk(c, fn);
60
+ if (node.content) walk(node.content, fn);
61
+ }
62
+ const attrOf = (n, a) => (n.attrs || []).find((x) => x.name === a);
63
+ const classes = (n) => (attrOf(n, 'class')?.value || '').split(/\s+/).filter(Boolean);
64
+ const hasClass = (n, c) => classes(n).includes(c);
65
+ const isSlide = (n) => n.tagName === 'section' && hasClass(n, 'slide');
66
+ const kids = (n) => (n.childNodes || []).filter((c) => c.tagName);
67
+ function slideNode(src, index) {
68
+ const doc = parse(src, { sourceCodeLocationInfo: true });
69
+ let node = null, k = 0;
70
+ walk(doc, (x) => { if (x.tagName && isSlide(x)) { if (k === index) node = x; k++; return false; } return true; });
71
+ if (!node) throw Object.assign(new Error(`no slide ${index + 1}`), { code: 'no-slide' });
72
+ if (!node.sourceCodeLocation || !node.sourceCodeLocation.endTag) throw Object.assign(new Error(`slide ${index + 1} has no end tag (</section>)`), { code: 'deck-problem' });
73
+ return node;
74
+ }
75
+ function descendants(node, pred) {
76
+ const out = [];
77
+ walk(node, (x) => { if (x !== node && x.tagName && pred(x)) out.push(x); return true; });
78
+ return out;
79
+ }
80
+ // 本文の直下の箇条(kit/deck.js の autoList と同じ:.body > ul > li, .body > ol > li を文書の順に)
81
+ function autoItems(slide) {
82
+ const out = [];
83
+ walk(slide, (x) => {
84
+ if (x.tagName === 'li' && x.parentNode && /^(ul|ol)$/.test(x.parentNode.tagName || '') && x.parentNode.parentNode && hasClass(x.parentNode.parentNode, 'body')) out.push(x);
85
+ return true;
86
+ });
87
+ return out;
88
+ }
89
+ function autoListOn(slide) {
90
+ return !hasClass(slide, 'static') && !hasClass(slide, 'nostep') && !descendants(slide, (x) => attrOf(x, 'data-step') || attrOf(x, 'data-from')).length;
91
+ }
92
+
93
+ export function slideSteps(src, index) {
94
+ const s = slideNode(src, index);
95
+ const concl = descendants(s, (x) => hasClass(x, 'concl')).length > 0;
96
+ if (hasClass(s, 'static')) return { max: 0, isStatic: true, auto: false, concl };
97
+ if (autoListOn(s)) return { max: autoItems(s).length, isStatic: false, auto: autoItems(s).length > 0, concl };
98
+ let max = 0;
99
+ for (const e of descendants(s, (x) => attrOf(x, 'data-step') || attrOf(x, 'data-from'))) {
100
+ const v = Number((attrOf(e, 'data-step') || attrOf(e, 'data-from')).value);
101
+ if (Number.isInteger(v) && v > max) max = v;
102
+ }
103
+ const ds = Number(attrOf(s, 'data-steps')?.value);
104
+ if (Number.isInteger(ds) && ds > max) max = ds;
105
+ return { max, isStatic: false, auto: false, concl };
106
+ }
107
+
108
+ // ---------------------------------------------------------------- 入れる塊
109
+ const escAttr = (v) => String(v).replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
110
+ export function imageHtml({ src, alt, placement, step }) {
111
+ if (!PLACEMENTS.includes(placement)) throw new Error('unknown placement: ' + placement);
112
+ if (!/^data:image\/(png|jpeg|webp|svg\+xml);base64,[A-Za-z0-9+/]*={0,2}$/.test(String(src))) throw new Error('the image must be a base64 data: URL of PNG, JPEG, WebP or SVG');
113
+ const st = step == null || step === 0 ? '' : ` data-step="${Number(step)}"`;
114
+ if (st && !(Number.isInteger(Number(step)) && Number(step) > 0)) throw new Error('bad step: ' + step);
115
+ const center = placement === 'half' || placement === 'third' ? ';margin:0 auto' : '';
116
+ return `<div class="fig"${st}><img src="${src}" alt="${escAttr(alt == null ? '' : String(alt).replace(/\s+/g, ' ').trim())}" style="display:block;width:${WIDTH[placement]};height:auto${center}"></div>`;
117
+ }
118
+
119
+ // ---------------------------------------------------------------- 入れる
120
+ const eolOf = (t) => (t.includes('\r\n') ? '\r\n' : '\n');
121
+ // off の前が行の頭からの空白だけなら、その行の頭。そうでなければ -1
122
+ function lineHead(src, off) {
123
+ const h = src.lastIndexOf('\n', off - 1) + 1;
124
+ return /^[ \t]*$/.test(src.slice(h, off)) ? h : -1;
125
+ }
126
+ const indentAt = (src, off) => { const h = src.lastIndexOf('\n', off - 1) + 1; return /^[ \t]*/.exec(src.slice(h))[0]; };
127
+ // 要素の終わりのタグの前に、子として html を入れる(終わりのタグが自分の行にあれば、その前の行として字下げを揃える)
128
+ function appendChild(src, node, html) {
129
+ const L = node.sourceCodeLocation, e = L.endTag.startOffset, eol = eolOf(src);
130
+ const pad = indentAt(src, L.startOffset) + ' ';
131
+ const h = lineHead(src, e);
132
+ if (h >= 0) return src.slice(0, h) + pad + html + eol + src.slice(h);
133
+ return src.slice(0, e) + html + src.slice(e);
134
+ }
135
+ // 本文の直下の箇条の自動のステップを data-step に書き出す(autoList のときだけ。見え方は変わらない)
136
+ function materialize(src, index) {
137
+ const s = slideNode(src, index);
138
+ if (!autoListOn(s)) return src;
139
+ const edits = autoItems(s).map((li, k) => {
140
+ const t = li.sourceCodeLocation.startTag;
141
+ let at = t.endOffset - 1; if (src[at - 1] === '/') at--;
142
+ return [at, ` data-step="${k + 1}"`];
143
+ });
144
+ edits.sort((a, b) => b[0] - a[0]);
145
+ for (const [at, t] of edits) src = src.slice(0, at) + t + src.slice(at);
146
+ return src;
147
+ }
148
+
149
+ export function insertImage(src, index, opts) {
150
+ const html = imageHtml(opts);
151
+ const cols = opts.placement === 'left' || opts.placement === 'right';
152
+ const stepped = !(opts.step == null || opts.step === 0);
153
+ if (stepped && hasClass(slideNode(src, index), 'static')) throw Object.assign(new Error('a static slide has no steps'), { code: 'static' });
154
+ if (stepped || cols) src = materialize(src, index);
155
+ const s = slideNode(src, index), eol = eolOf(src);
156
+ let body = kids(s).find((x) => hasClass(x, 'body'));
157
+ if (!body) {
158
+ // 本文がない:結論の行の前(なければ </section> の前)に本文を作る
159
+ const pad = indentAt(src, s.sourceCodeLocation.startOffset) + ' ';
160
+ const concl = kids(s).find((x) => hasClass(x, 'concl'));
161
+ const inner = cols ? colsHtml(opts.placement, html, '', pad + ' ', eol) : `${pad} ${html}`;
162
+ const block = `${pad}<div class="body">${eol}${inner}${eol}${pad}</div>`;
163
+ if (concl) { const at = concl.sourceCodeLocation.startOffset, h = lineHead(src, at); return h >= 0 ? src.slice(0, h) + block + eol + src.slice(h) : src.slice(0, at) + block.trimStart() + src.slice(at); }
164
+ return appendChild(src, s, block.trimStart());
165
+ }
166
+ if (!cols) return appendChild(src, body, html);
167
+ const wrap = kids(body).find((x) => hasClass(x, 'cols'));
168
+ if (wrap) {
169
+ const c = kids(wrap), k = opts.placement === 'left' ? 0 : 1, target = c[k];
170
+ if (target && target.tagName === 'div' && target.sourceCodeLocation && target.sourceCodeLocation.endTag) return appendChild(src, target, html);
171
+ // その列がない・パーツなどの要素:新しい列(<div>)として左なら先頭、右なら左の列の後ろに入れる
172
+ const col = `<div>${html}</div>`;
173
+ if (k === 0 || !c[0]) {
174
+ const at = c[0] ? c[0].sourceCodeLocation.startOffset : wrap.sourceCodeLocation.startTag.endOffset;
175
+ if (!c[0]) return appendChild(src, wrap, col);
176
+ const h = lineHead(src, at), pad = indentAt(src, at);
177
+ return h >= 0 ? src.slice(0, h) + pad + col + eol + src.slice(h) : src.slice(0, at) + col + src.slice(at);
178
+ }
179
+ const after = c[0].sourceCodeLocation.endOffset;
180
+ return src.slice(0, after) + eol + indentAt(src, c[0].sourceCodeLocation.startOffset) + col + src.slice(after);
181
+ }
182
+ // 2 列にする:今の本文をもう一方の列へ
183
+ const B = body.sourceCodeLocation, a = B.startTag.endOffset, b = B.endTag.startOffset;
184
+ const pad = indentAt(src, B.startOffset) + ' ';
185
+ let inner = src.slice(a, b).replace(/^[ \t]*\r?\n/, '').replace(/\s+$/, '');
186
+ // 列の中へ動かす本文は 4 字下げる(空白に意味のある pre・textarea を含むときは字を変えない)
187
+ if (!/<(pre|textarea)\b/i.test(inner)) inner = inner.split(/(\r?\n)/).map((x, k) => (k % 2 === 0 && x.trim() ? ' ' + x : x)).join('');
188
+ const close = lineHead(src, b) >= 0 ? eol + indentAt(src, b) : eol + indentAt(src, B.startOffset);
189
+ return src.slice(0, a) + eol + colsHtml(opts.placement, html, inner, pad, eol) + close + src.slice(b);
190
+ }
191
+ function colsHtml(placement, html, inner, pad, eol) {
192
+ const img = `${pad} ${html}`;
193
+ const other = inner ? inner : '';
194
+ const colOf = (x) => (x ? `${pad} <div>${eol}${x}${eol}${pad} </div>` : `${pad} <div></div>`);
195
+ const L = placement === 'left' ? img : other, R = placement === 'left' ? other : img;
196
+ return `${pad}<div class="cols">${eol}${colOf(L)}${eol}${colOf(R)}${eol}${pad}</div>`;
197
+ }
@@ -1,7 +1,7 @@
1
1
  // 埋め込んだ画像の大きさ(data: URI を戻したバイト数)。組み立てた HTML をコマンド版と編集アプリで同じように調べる
2
2
  import { parse } from 'parse5';
3
3
 
4
- const MAX_IMAGE_BYTES = 1048576;
4
+ export const MAX_IMAGE_BYTES = 1048576; // 1 つの画像の目安(1 MiB)。編集アプリの「画像を挿入」の知らせも同じ値(kit/core/image-insert.mjs)
5
5
  const attr = (n, name) => (n.attrs || []).find((a) => a.name === name)?.value || '';
6
6
  function dataBytes(src) {
7
7
  const m = /^data:([^,]*),([\s\S]*)$/i.exec(src.trim());
@@ -200,7 +200,7 @@ export function layoutScan(s, o) {
200
200
  if (!n.textContent.trim()) continue;
201
201
  const e = n.parentElement;
202
202
  // ルビ(rt)の振り仮名は本文の半分の大きさが決まり(docs/reference.md「Japanese language arts」)
203
- if (e.closest('svg') || e.closest('.katex') || e.closest('[' + ANNOT + ']') || e.closest('.cite') || e.closest('.pn') || e.closest('.figcap') || e.closest('rt')) continue;
203
+ if (e.closest('svg') || e.closest('.katex') || e.closest('[' + ANNOT + ']') || e.closest('.cite') || e.closest('.source') || e.closest('.pn') || e.closest('.figcap') || e.closest('rt')) continue;
204
204
  if (hiddenEl(e)) continue; // 読み上げ用の隠し方の中の字(.sr-only の形の 1×1 の箱・clip-path: inset(50%) など)は見えない
205
205
  const f = parseFloat(getComputedStyle(e).fontSize);
206
206
  const lim2 = e.closest('table,.plot') ? 23.9 : 26.6;
@@ -47,7 +47,7 @@ const BY_CODE = {
47
47
  titleLong: ['R-title'], titleLongEn: ['R-title'], conclLong: ['R-concl'], conclLongEn: ['R-concl'], conclOverflow: ['R-concl', 'R-fit'],
48
48
  overflowBottom: ['R-fit'], overflowRight: ['R-fit'], smallText: ['R-fit'], katexError: ['R-math'],
49
49
  noNarration: ['R-narr-steps'], orphanNarration: ['R-narr-steps'], readingExpr: ['R-reading', 'R-formula'], readingSeveral: ['R-reading'], readingGap: ['R-reading'],
50
- compData: ['R-components'], consoleError: ['R-components'],
50
+ compData: ['R-components'], scriptUnclosed: ['R-components'], consoleError: ['R-components'],
51
51
  contrast: ['R-colors'], formula: ['R-formula'], missingSection: ['R-headings'], narrHeadingDiffers: ['R-headings'], markTarget: ['R-marks'],
52
52
  // 体裁の検査(kit/core/layout-scan.mjs)がブラウザ版にも出すコマンド版の code
53
53
  titleColon: ['R-title'], tateTitle: ['R-title'], tateBodyHead: ['R-fit'], bodyConclCol: ['R-fit'], bodyLeft: ['R-fit'], smallSvgText: ['R-fit'],