wani 0.1.14 → 0.1.16

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f47f0147e24156fd966b89b0185cacd07d7afd45d285c0a0d607d44de3cb6406
4
- data.tar.gz: d8209c67e888d8e909551c0842167724fa8562934fc29f76a874de0a11c2d96d
3
+ metadata.gz: 2211ec774d104372f053f45eff713ce11bb25559a6c5f5770cb8aee772f7fea8
4
+ data.tar.gz: eebe25656e75d3d5679855ba5d3318105a27f511c64fd6d6829a583b8d3b4012
5
5
  SHA512:
6
- metadata.gz: 0a89984cbbbb6c8466b69b89affab16e36d0791bf63bc7ecc687ee06765be2899f6f3af75b526463e26ba5cf52917b6b1f09d5584af708456365cb2eb80e71f1
7
- data.tar.gz: 565853474a5a6054b46042b8bced8759a4339d12845fd4ccc2fe28f6e862013c9c802913543cf68707e166d7d80f1fdadcce7df6d9e3cdfa087f53a1640115c7
6
+ metadata.gz: 6a778f887a3eac4882ba9648eeeb64d4aa50efd3dd8582de2070a9fac2c2829af85a10ff0a97c17e5da0601a6474017c978d77a3807be0b4a39830abb6b059bf
7
+ data.tar.gz: 2c67e0eedf595709727b180406e7de518a9a0fd36d0c19b72339ad513e1fc7380ff3e4361a954b765bc0b4ff1f8383d8f88a911c1e540a8d84e6940422f7ed66
data/README.md CHANGED
@@ -2,33 +2,23 @@
2
2
 
3
3
  Markdown からスライドを作り、ブラウザー内の Ruby でプレゼンテーションするツールです。
4
4
  Rabbit へのオマージュとして、因幡の白兎に登場するワニ(鮫)にちなんだ名前です。
5
+ 兎とワニがスライドの進み具合を楽しく伝えます。
5
6
 
6
7
  **Markdownを書いたら、あとは話す準備を。**
7
8
 
8
- waniは、内容に合わせて文字サイズを自動調整するプレゼンテーションツールです。
9
- タイトルも本文もスライドに収まる大きさに自動調整。
10
- 文字サイズの調整に手をかけず、伝えたい内容に集中してください。
9
+ waniは文字サイズを自動調整するプレゼンテーションツールです。
10
+ 表紙のタイトルは中央に、本文は固定サイズで右下に右揃えで表示します。タイトルと本文が重なる場合は警告します。2枚目以降はタイトルも本文もスライドに収まる限り最も大きく表示します。
11
+ 文字サイズの調整に手間を掛けません。
11
12
 
12
- 兎とワニがスライドの進み具合を楽しく伝えます。
13
13
  持ち時間も、発表の演出に。
14
14
  最後の5秒は観客と一緒にカウントダウン。
15
15
  時間になるとワニが登場し、発表のフィナーレを飾ります。
16
16
 
17
- <p align="center">
18
- <img src="docs/images/wani-characters.png" alt="ノートパソコンを使う兎と、それを見守るワニ" width="640">
19
- </p>
20
-
21
- <p align="center">
22
- <img src="docs/images/rabbit.png" alt="ノートパソコンを持った兎" width="240">
23
- <img src="docs/images/wani.png" alt="笑顔のワニ" width="240">
24
- </p>
25
-
26
17
  ## インストールと開始
27
18
 
28
19
  ### インストール
29
20
 
30
21
  [RubyGems.org](https://rubygems.org/gems/wani) からインストールできます。
31
- Ruby 3.2 以上が必要です。
32
22
 
33
23
  ```sh
34
24
  gem install wani
@@ -47,11 +37,10 @@ wani check
47
37
  wani serve
48
38
  ```
49
39
 
40
+ http://127.0.0.1:8000/ をブラウザーで開きます。
50
41
 
51
- 表示された http://127.0.0.1:8000/ をブラウザーで開きます。
52
-
53
- `new`コマンドで生成されるプロジェクトには、Markdown記法を紹介する10ページの `slides.md` とサンプルSVG画像が含まれます。
54
- `slides.md` を編集したらブラウザーを再読み込みしてください。
42
+ `new`コマンドで生成されるプロジェクトには、Markdown記法を紹介する10ページの `slides.md` とサンプルSVG画像が含まれています。
43
+ `slides.md` の変更はブラウザーを再読み込みすると反映されます。
55
44
 
56
45
  ## Markdown記法
57
46
 
@@ -79,16 +68,21 @@ notes:
79
68
  見出しレベルが違っても、タイトルのデザインは同じです。
80
69
  ```
81
70
 
82
- - 独立した `---` の行でスライドを分割
83
- - 各ページの最初の見出しをタイトルに
84
- - 本文には段落、強調、リスト、引用、コード、リンク、画像、表が使用可能
85
- - コードフェンスに `ruby` や `js` などの言語名を付けると、スライド・ノート・PDFで構文ハイライトを適用
86
- - 画像は、slides.mdを基準に相対パスで記述
87
- - `<!-- notes: ... -->` は発表者ノート
88
- - `<!-- page-footnote: ... -->` はページごとの脚注
71
+ - タイトル:各ページの最初の見出し
72
+ - 画像:slides.mdを基準に相対パスで記述
73
+ - 発表者ノーと:`<!-- notes: ... -->`
74
+ - 本文: 段落、強調、リスト、引用、コード、リンク、画像、表が使用可能
75
+ - ページ区切り : `---`
89
76
 
90
77
  詳細は [Markdown記法ガイド](docs/markdown.md) を参照してください。
91
78
 
79
+ ## フォント文字サイズを自動調整
80
+
81
+ - タイトルは1行に収める
82
+ - 本文は全角20文字当の幅を超える場合は自然に折り返し
83
+ - 明示的な改行は維持
84
+ - 文字サイズは本文全体で共通
85
+
92
86
  ## コマンド紹介
93
87
 
94
88
  ```sh
@@ -162,62 +156,44 @@ wani --help
162
156
 
163
157
  ## 発表タイマー
164
158
 
165
- hashなしのURLで開くと、最初のスライドに半透明の黒いベールと「スタート」ボタンを表示します。
166
- 待機中はページ移動と計測を止め、ボタンを押すとベールが消えてタイマーが始まります。Fキーで全画面にして待機できます。
167
- `#slide=1` などのhash付きURLでは、読み込み完了から計測します。
168
- 既定では5分で時間切れ画面を表示します。
169
- Front Matter の `time_limit` に分数を指定して変更できます(小数も可)。
170
- `time_limit: 0` でタイマーを無効にします。
159
+ 最初のスライドに半透明の黒いベールと「スタート」ボタンを表示します。
160
+ URL でスライド番号を指定した場合は、ボタンを表示せず、タイマーも使用しません。
161
+ ボタンを押すとベールが消えてタイマーが始まります。
171
162
 
172
163
  残り30秒になると、全画面表示中もカウントダウンを表示します。
173
- 残り5秒は中央に数字を表示し、画面の短辺に対して20%・40%・60%・80%・100%と強調サイズを増やします。
174
- 各数字は0.8秒で通常サイズに戻ります。動きを減らす設定では拡大アニメーションを省略します。
164
+ 残り5秒は中央に数字を表示します。
175
165
  時間切れになると、兎柄フードをくわえたワニ(さめ)の画像を表示します。
176
- 画像は軽量なWebP形式で配布し、発表開始前に読み込みとデコードを済ませて、時間切れの文字と同時に表示します。
177
166
  左右キーまたは「スライドに戻る」ボタンで、時間切れ直前のスライドに戻れます。
178
- 戻った後は通常通りページを移動でき、時間切れ画面は再表示しません。
179
- 最終スライドの表示中はタイマーを一時停止し、カウントダウンも時間切れ画面も表示しません。
180
- 前のスライドに戻ると、停止前の残り時間から再開します。1ページだけの場合も停止します。
181
- ページを再読み込みするとタイマーも最初から始まります。
182
- 開始待ち画面、タイマー、時間切れ画面はPDFには含めません。
183
167
 
184
- ## スライド
168
+ 既定では5分です。
169
+ Front Matter の `time_limit` に分数を指定して変更できます(小数も可)。
170
+ `time_limit: 0` でタイマーを無効にします。
171
+
172
+
173
+ ## スライドのフォーマット
185
174
 
186
175
  - 1920×1080、16:9
187
176
  - 白背景
188
177
  - 画像は比率を維持して縦に配置し、画像だけの場合は本文領域を広く使います。
189
- - `#slide=3` のようなハッシュ付き URL で特定のスライドを開く
190
-
191
- ### 画像とフォントを読み込み、幅と高さに合わせて文字サイズを自動調整
192
- - タイトルは1行に収める
193
- - 本文の段落・見出し・箇条書きは、使用フォントの全角20文字(「あ」20個)相当の幅以下なら折り返さず、それを超える場合は自然に折り返し
194
- - 明示的な改行は維持。改行ごとに幅を判定
195
- - 文字サイズは本文全体で共通
196
178
 
197
-
198
- ### 警告
179
+ ## 警告
199
180
 
200
181
  - 収まらない内容に警告を表示
201
182
  - 画像の読み込みを最大15秒待ち、失敗やタイムアウトを通知
202
183
 
203
184
  ## 印刷
204
185
 
205
- ツールバーの「PDF」「ノート付き PDF」から印刷ダイアログを開き、PDFとして保存します。
186
+ ツールバーの「PDF」「ノート付き PDF」から印刷ダイアログを開き、PDFとして保存できます。
206
187
  Ctrl+P でも印刷できます。
188
+ 用紙は320×180mmを指定し、ブラウザーのヘッダー・フッターはオフにしてください。
207
189
 
208
- - 用紙は320×180mmを指定し、ブラウザーのヘッダー・フッターはオフにしてください。
209
- - 通常版は1スライド1ページ、ノート付きは各スライドの次に対応するノートを置きます。
210
- - 画像・フォントの完了後に印刷し、ページごとの脚注とページ番号を出力します。兎と鰐の装飾は常に非表示です。
211
-
190
+ - 通常版は1スライド1ページ、ノート付きは各スライドの次に対応するノートを配置
191
+ - ページごとの脚注とページ番号を出力
212
192
 
213
193
  ## 同梱フォント
214
194
 
215
195
  日本語・英数字の標準書体は **IBM Plex Sans JP** です。
216
- 通常と太字のフォントを gem に同梱します。
217
-
218
- 本文・タイトル・発表者画面・PDF に同じ書体を使います。
219
- コードには **UDEV Gothic** を使い、日本語も半角1:全角2の等幅で表示します。
220
- UDEV Gothic も通常・太字を同梱するため、外部への通信やOSへのインストールは不要です。
196
+ コードは **UDEV Gothic** を使い、日本語も半角1:全角2の等幅で表示します。
221
197
 
222
198
  フォントは SIL Open Font License 1.1 です。原文のライセンス・著作権表示と配布元・チェックサムは
223
199
  [third_party/ibm-plex-sans-jp](third_party/ibm-plex-sans-jp/README.md) と
@@ -226,7 +202,7 @@ UDEV Gothic も通常・太字を同梱するため、外部への通信やOSへ
226
202
  ## フォントを変更する
227
203
 
228
204
  タイトルと本文には、[Fontsource](https://fontsource.org/fonts)のフォントを追加して使えます。
229
- フォントの追加時にはインターネット接続が必要です。追加後はオフラインで表示・PDF出力ができ、OSへのフォントのインストールやNode.js・npmは不要です。
205
+ フォントの追加時にはインターネット接続が必要です。追加後はオフラインでも表示・PDF出力ができます。
230
206
 
231
207
  ### Fontsourceのフォントを使う
232
208
 
@@ -305,24 +281,6 @@ wani font remove noto-sans-jp
305
281
 
306
282
  スライドで使用中の場合は確認を求めます。削除する場合は、Front Matterの`font`も削除するか、別の追加済みフォントに変更してください。
307
283
 
308
- ### 他の人に渡す場合
309
-
310
- 追加したフォントは`fonts/ID/`、登録情報は`.wani/fonts.yml`に保存されます。
311
- `slides.md`や画像と一緒に、`fonts/`と`.wani/fonts.yml`も保存・配布してください。`.wani`は隠しディレクトリなので、コピーし忘れないようにしてください。
312
-
313
- 各フォントのライセンスは`fonts/ID/LICENSE`に保存されます。Web公開・再配布・PDF配布の際は、そのフォントのライセンス条件を確認してください。
314
-
315
- ## 動作環境と制約
316
-
317
- 確認済みの環境は Linux / Ruby 4.0.7 / Chrome 156.0.8078.47 です。
318
- Windows・WSL2、Edge / Firefox / Safari、通常ブラウザーの印刷ダイアログ操作は未検証です。
319
-
320
- WSL2 内で `wani serve` を起動した場合は、Windows 側のブラウザーで http://localhost:8000/ を開きます。
321
- 環境のポート転送設定に応じて `--bind 0.0.0.0` を指定してください。
322
-
323
- 複雑に入れ子になった Markdown 方言、最適な画像の自動配置、ライブリロードは対象外です。
324
- 発表者画面はメイン画面の終了・再読み込み後に開き直してください。
325
-
326
284
  ## 開発者向けドキュメント
327
285
 
328
286
  - [アーキテクチャ](docs/architecture.md):共通モジュール、静的配信、wasm・ローダー、フォント、レイアウトの設計
data/assets/build.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
- "version": "0.1.14",
3
- "source_sha256": "c3e705b68ea3335c7704a5be6989fd09d40d0bbc6f8dd6a2d26dd7ea9a49d05a",
2
+ "version": "0.1.16",
3
+ "source_sha256": "32912ebee7503573d054f7cde1150bf882b5211532079d3d348cea72c6af2556",
4
4
  "loader_commit": "dc6b0ffd5800ed9bfc49268ed8021d456f10ddf8",
5
- "wasm_sha256": "feac70ebd959b1aa5d8f628fce3bb8d5570b4404a3128cd37f721f611fe62d83"
5
+ "wasm_sha256": "10b7d39455116b9a76ab0e89754068eb54bc9078cda5fb57891e6cd5b190c0b3"
6
6
  }
data/assets/index.html CHANGED
@@ -30,7 +30,7 @@
30
30
  <output id="countdown" aria-live="off" aria-label="発表の残り時間" hidden></output>
31
31
  <section id="time-expired" role="dialog" aria-modal="true" aria-labelledby="time-expired-title" hidden>
32
32
  <h1 id="time-expired-title">時間切れです!</h1>
33
- <img id="time-expired-image" class="time-expired-image" src="/assets/time-expired.webp" width="1086" height="724" alt="兎柄フードをくわえるワニ(さめ)">
33
+ <img id="time-expired-image" class="time-expired-image" width="1200" height="900" alt="ウサギとサメのイラスト">
34
34
  <p>← または → キーで元のスライドに戻れます</p>
35
35
  <button id="resume-slides">スライドに戻る</button>
36
36
  </section>
data/assets/style.css CHANGED
@@ -44,7 +44,7 @@ button:focus-visible, a:focus-visible { outline: 2px solid #557e64; outline-offs
44
44
  #status { font-size: 12px; margin: 0; padding: 8px 24px; color: #607569; min-height: 30px; }
45
45
  #viewport { width: 100%; flex: 1 1 0; min-height: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; padding: 20px; }
46
46
  #stage { flex: 0 0 1920px; transform-origin: center; box-shadow: 0 8px 48px #20352e18; }
47
- .slide { width: 1920px; height: 1080px; padding: 64px 80px 48px; display: flex; flex-direction: column; overflow: hidden; background: white; color: #172b24; }
47
+ .slide { position: relative; width: 1920px; height: 1080px; padding: 64px 80px 48px; display: flex; flex-direction: column; overflow: hidden; background: white; color: #172b24; }
48
48
  .title { margin: 0 0 36px; white-space: nowrap; flex: 0 0 160px; font-weight: 700; line-height: 1.12; overflow: hidden; letter-spacing: -.025em; }
49
49
  .body { flex: 1 1 0; min-height: 0; overflow: hidden; line-height: 1.3; }
50
50
  .body p { margin: 0 0 .35em; }
@@ -53,6 +53,10 @@ button:focus-visible, a:focus-visible { outline: 2px solid #557e64; outline-offs
53
53
  .titleless .body > * { flex-shrink: 0; }
54
54
  .titleless .body > :last-child { margin-bottom: 0; }
55
55
  .titleless .body img { margin-inline: auto; }
56
+ .cover .title { margin-top: 396px; text-align: center; }
57
+ .cover .body { display: flex; flex-direction: column; align-items: flex-end; justify-content: flex-end; text-align: right; }
58
+ .cover .body > * { flex-shrink: 0; max-width: 100%; }
59
+ .cover .body > :last-child { margin-bottom: 0; }
56
60
  .body ul, .body ol { margin: .2em 0 .4em; padding-left: 1.35em; }
57
61
  .body pre { margin: .3em 0; padding: .4em .55em; background: #f3f6f2; white-space: pre-wrap; tab-size: 2; }
58
62
  .titleless .body pre { width: fit-content; max-width: 100%; margin-inline: auto; text-align: left; }
@@ -62,6 +66,17 @@ button:focus-visible, a:focus-visible { outline: 2px solid #557e64; outline-offs
62
66
  .body th, .body td { border: 1px solid #bac8bd; padding: .15em .3em; }
63
67
  .body img { display: block; object-fit: contain; max-width: 100%; }
64
68
  .body a { color: #32634b; }
69
+ .body p:has(.youtube-video) { margin-bottom: 0; }
70
+ .body p.youtube-only { width: 100%; text-align: center; }
71
+ .youtube-video { display: inline-block; position: relative; vertical-align: top; max-width: 100%; }
72
+ .youtube-video img { aspect-ratio: 16 / 9; object-fit: cover; }
73
+ .youtube-play { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); background: #e00; color: white; border: 0; border-radius: 14px; font-size: 48px; padding: 8px 32px; }
74
+ .youtube-play:hover { background: #b00; }
75
+ .youtube-overlay { position: absolute; inset: 0; z-index: 10; background: black; }
76
+ .youtube-frame { width: 100%; height: 100%; border: 0; }
77
+ .youtube-close { position: absolute; z-index: 1; top: 24px; right: 24px; padding: 12px 20px; font-size: 28px; background: #202020e8; color: white; border-color: white; }
78
+ .youtube-close:hover { background: #444; }
79
+ @media print { .youtube-overlay, .youtube-play { display: none !important; } }
65
80
  .slide-footer { flex: 0 0 128px; position: relative; display: flex; align-items: start; font-size: 24px; color: #71887e; padding-top: 12px; }
66
81
  .page-footnote { width: 100%; min-width: 0; height: 1.5em; line-height: 1.5; white-space: nowrap; overflow: hidden; }
67
82
  .decorations { position: absolute; left: 0; right: 132px; bottom: 0; height: 80px; }
@@ -75,11 +90,15 @@ button:focus-visible, a:focus-visible { outline: 2px solid #557e64; outline-offs
75
90
  .rabbit-image { display: block; width: 84px; height: 40px; }
76
91
  .decorations[data-direction="left"] .rabbit-image { scale: -1 1; }
77
92
  .slide.active .bridge-segment[data-appearing="true"] { animation: wani-arrive .35s ease-out; }
78
- .slide.active .decorations[data-moving="true"] .rabbit-position { animation: rabbit-advance .45s ease-in-out; }
79
- .slide.active .decorations[data-moving="true"] .rabbit-image { animation: rabbit-hop .45s ease-in-out; }
93
+ .slide.active .decorations[data-moving="true"] .rabbit-position { animation: rabbit-advance .45s linear; }
94
+ .slide.active .decorations[data-moving="true"] .rabbit-image { animation: rabbit-hop .45s linear; }
80
95
  @keyframes wani-arrive { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }
81
96
  @keyframes rabbit-advance { from { left: calc((100% - 84px) * var(--rabbit-from)); } to { left: calc((100% - 84px) * var(--rabbit-progress)); } }
82
- @keyframes rabbit-hop { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-12px); } }
97
+ @keyframes rabbit-hop {
98
+ 0% { transform: translateY(0); animation-timing-function: cubic-bezier(.16, 1, .3, 1); }
99
+ 50% { transform: translateY(-60px); animation-timing-function: cubic-bezier(.333333, 0, .666667, .333333); }
100
+ 100% { transform: translateY(0); }
101
+ }
83
102
  @media (prefers-reduced-motion: reduce) { .decorations * { animation: none !important; } }
84
103
  #stage .slide:not(.active) { display: none; }
85
104
  .help { padding: 8px 24px; font-size: 11px; color: #718578; display: flex; gap: 22px; }
@@ -110,7 +129,7 @@ button:focus-visible, a:focus-visible { outline: 2px solid #557e64; outline-offs
110
129
  #time-expired { position: fixed; inset: 0; z-index: 30; display: flex; flex-direction: column; align-items: center; justify-content: center; background: white; color: #20352e; padding: 16px; overflow: auto; }
111
130
  #time-expired[hidden], #countdown[hidden] { display: none; }
112
131
  #time-expired h1 { margin: 0; font-size: clamp(24px, 4vw, 56px); }
113
- .time-expired-image { width: min(90vw, calc(65vh * 1086 / 724)); aspect-ratio: 1086 / 724; height: auto; flex-shrink: 0; }
132
+ .time-expired-image { width: min(90vw, calc(65vh * 4 / 3)); aspect-ratio: 4 / 3; height: auto; flex-shrink: 0; }
114
133
  #time-expired p { margin: 8px 0; text-align: center; }
115
134
  @media print { #countdown, #time-expired { display: none !important; } }
116
135
 
Binary file
Binary file
Binary file
Binary file
data/assets/wani.wasm CHANGED
Binary file
@@ -17,6 +17,8 @@ module Wani
17
17
  response = JS.global.fetch("/talk/slides.md").await
18
18
  raise "Markdown を読み込めません (HTTP #{response[:status].to_i})" unless response[:ok] == JS::True
19
19
  @presentation = Core::Parser.new.parse(response.text.await.to_s)
20
+ title = @presentation.slides.first.title
21
+ @document[:title] = title unless title.empty?
20
22
  @presentation.diagnostics.each { |item| warn("#{item.slide ? "スライド #{item.slide}: " : ""}#{item.message}") }
21
23
  @renderer = Renderer.new(@document, @presentation)
22
24
  @sections = @presentation.slides.map { |slide| @renderer.slide(slide) }
@@ -36,8 +38,6 @@ module Wani
36
38
  element("start-overlay")[:hidden] = false
37
39
  element("viewport")[:inert] = true
38
40
  element("start-presentation").focus
39
- else
40
- start_timer
41
41
  end
42
42
  element("status")[:textContent] = "準備できました"
43
43
  end
@@ -83,6 +83,14 @@ module Wani
83
83
  next if event[:ctrlKey] == JS::True || event[:altKey] == JS::True || event[:metaKey] == JS::True
84
84
  next if %w[INPUT TEXTAREA SELECT].include?(target[:tagName].to_s) || target[:isContentEditable] == JS::True
85
85
  next if @waiting_to_start && !%w[f F Escape n N].include?(event[:key].to_s)
86
+ if event[:key].to_s == "Escape"
87
+ close = @sections[@index].querySelector(".youtube-close")
88
+ unless close == JS::Null
89
+ close.click
90
+ event.preventDefault
91
+ next
92
+ end
93
+ end
86
94
  handled = true
87
95
  case event[:key].to_s
88
96
  when "ArrowRight", " ", "PageDown" then go(@index + 1)
@@ -117,6 +125,9 @@ module Wani
117
125
  end
118
126
  previous_number = @active_number || 0
119
127
  @index = index.clamp(0, @sections.length - 1)
128
+ if previous_number.positive? && previous_number != @index + 1
129
+ @sections[previous_number - 1].querySelectorAll(".youtube-overlay").to_a.each(&:remove)
130
+ end
120
131
  @renderer.transition(@sections[@index], previous_number)
121
132
  @sections.each_with_index { |section, number| section[:classList].toggle("active", number == @index) }
122
133
  @active_number = @index + 1
@@ -184,6 +195,7 @@ module Wani
184
195
  @presentation.slides.each_with_index do |slide, index|
185
196
  [false, *(notes ? [true] : [])].each do |is_note|
186
197
  section = is_note ? @renderer.slide(slide, notes: true) : @sections[index].cloneNode(true)
198
+ section.querySelectorAll(".youtube-overlay").to_a.each(&:remove)
187
199
  if is_note
188
200
  element("stage").appendChild(section)
189
201
  @layout.wait_assets(section)
@@ -5,6 +5,7 @@ module Wani
5
5
  HEIGHT = 1080
6
6
  BODY_MIN = 16
7
7
  BODY_MAX = 160
8
+ COVER_BODY_SIZE = 48
8
9
  TITLE_MIN = 24
9
10
  TITLE_MAX = 220
10
11
  NO_WRAP_EMS = 20
@@ -60,8 +61,26 @@ module Wani
60
61
  body = section.querySelector(".body")
61
62
  prepare_wrapping(body)
62
63
  fit_images(body)
63
- fit_font(body, BODY_MIN, BODY_MAX)
64
- @warn.call("スライド #{number}: 本文が収まりません: #{body[:textContent].to_s[0, 120]}") unless fits?(body)
64
+ if section[:classList].contains("cover") == JS::True
65
+ body[:style][:fontSize] = "#{COVER_BODY_SIZE}px"
66
+ else
67
+ fit_font(body, BODY_MIN, BODY_MAX)
68
+ end
69
+ body_fits = if section[:classList].contains("cover") == JS::True
70
+ cover_body_fits?(body)
71
+ else
72
+ fits?(body)
73
+ end
74
+ @warn.call("スライド #{number}: 本文が収まりません: #{body[:textContent].to_s[0, 120]}") unless body_fits
75
+ if section[:classList].contains("cover") == JS::True && title[:style][:display].to_s != "none"
76
+ title_rect = title.getBoundingClientRect
77
+ overlap = body[:children].to_a.any? do |child|
78
+ rect = child.getBoundingClientRect
79
+ rect[:top].to_f < title_rect[:bottom].to_f && rect[:bottom].to_f > title_rect[:top].to_f &&
80
+ rect[:left].to_f < title_rect[:right].to_f && rect[:right].to_f > title_rect[:left].to_f
81
+ end
82
+ @warn.call("スライド #{number}: タイトルと本文が重なっています") if overlap
83
+ end
65
84
  footnote = section.querySelector(".page-footnote")
66
85
  if footnote[:scrollWidth].to_i > footnote[:clientWidth].to_i + 1
67
86
  @warn.call("スライド #{number}: 脚注が1行に収まりません。短くするか、詳細を本文へ移してください。")
@@ -119,6 +138,15 @@ module Wani
119
138
  node[:scrollWidth].to_i <= node[:clientWidth].to_i + 1 && node[:scrollHeight].to_i <= node[:clientHeight].to_i + 1
120
139
  end
121
140
 
141
+ def cover_body_fits?(body)
142
+ bounds = body.getBoundingClientRect
143
+ body[:scrollWidth].to_i <= body[:clientWidth].to_i + 1 && body[:children].to_a.all? do |child|
144
+ rect = child.getBoundingClientRect
145
+ rect[:top].to_f >= bounds[:top].to_f - 1 && rect[:bottom].to_f <= bounds[:bottom].to_f + 1 &&
146
+ rect[:left].to_f >= bounds[:left].to_f - 1 && rect[:right].to_f <= bounds[:right].to_f + 1
147
+ end
148
+ end
149
+
122
150
  def fit_font(node, minimum, maximum)
123
151
  low, high, best = minimum, maximum, minimum
124
152
  while low <= high
@@ -136,13 +164,19 @@ module Wani
136
164
  def fit_images(body)
137
165
  images = body.querySelectorAll("img").to_a
138
166
  return if images.empty?
139
- mixed = !body[:textContent].to_s.strip.empty?
140
- budget = body[:clientHeight].to_f * (mixed ? 0.45 : 0.85) / images.length
167
+ content = body.cloneNode(true)
168
+ content.querySelectorAll(".youtube-video").to_a.each(&:remove)
169
+ mixed = !content[:textContent].to_s.strip.empty?
170
+ videos_only = images.all? { |image| image.closest(".youtube-video") != JS::Null }
171
+ fraction = mixed ? 0.45 : (videos_only ? 0.98 : 0.85)
172
+ budget = body[:clientHeight].to_f * fraction / images.length
141
173
  images.each do |image|
142
174
  next if image[:naturalWidth].to_i.zero? || image[:naturalHeight].to_i.zero?
143
- ratio = [body[:clientWidth].to_f / image[:naturalWidth].to_f, budget / image[:naturalHeight].to_f].min
144
- image[:style][:width] = "#{image[:naturalWidth].to_f * ratio}px"
145
- image[:style][:height] = "#{image[:naturalHeight].to_f * ratio}px"
175
+ width = image[:naturalWidth].to_f
176
+ height = image.closest(".youtube-video") == JS::Null ? image[:naturalHeight].to_f : width * 9 / 16
177
+ ratio = [body[:clientWidth].to_f / width, budget / height].min
178
+ image[:style][:width] = "#{width * ratio}px"
179
+ image[:style][:height] = "#{height * ratio}px"
146
180
  end
147
181
  end
148
182
  end
@@ -3,18 +3,29 @@ module Wani
3
3
  class Application
4
4
  private
5
5
 
6
- # Decode the actual displayed image before enabling presentation controls.
6
+ # Decode the candidates before enabling presentation controls.
7
7
  def prepare_timer_image
8
8
  return if @presentation.time_limit.zero?
9
9
 
10
- element("time-expired-image").decode.await
11
- rescue JS::Error
12
- warn("時間切れの画像を読み込めませんでした")
10
+ @timer_images = (1..4).map do |number|
11
+ image = @document.createElement("img")
12
+ image[:src] = "/assets/time-expired-#{number}.webp"
13
+ image
14
+ end
15
+ @timer_images.each do |image|
16
+ begin
17
+ image.decode.await
18
+ rescue JS::Error
19
+ warn("時間切れの画像を読み込めませんでした")
20
+ end
21
+ end
13
22
  end
14
23
 
15
24
  def start_timer
16
25
  return if @presentation.time_limit.zero?
17
26
 
27
+ selected = (JS.global[:Math].random.to_f * @timer_images.length).floor
28
+ element("time-expired-image")[:src] = @timer_images[selected][:src]
18
29
  @deadline = JS.global[:Date].now.to_f + @presentation.time_limit * 60_000
19
30
  element("resume-slides").addEventListener("click") { go(@index) }
20
31
  @timer_callback = -> { tick_timer }
@@ -17,9 +17,18 @@ module Wani
17
17
  title[:style][:display] = "none"
18
18
  section[:className] = "slide titleless"
19
19
  end
20
+ section[:classList].add("cover") if slide.number == 1 && !notes
20
21
  body = child(section, "div", "body")
21
22
  body[:innerHTML] = notes ? slide.notes_html : slide.html
22
23
  resolve_links(body)
24
+ body.querySelectorAll("p").to_a.each do |paragraph|
25
+ children = paragraph[:children].to_a
26
+ next unless children.length == 1 && children.first[:classList].contains("youtube-video") == JS::True
27
+ copy = paragraph.cloneNode(true)
28
+ copy.querySelector(".youtube-video").remove
29
+ paragraph[:classList].add("youtube-only") if copy[:textContent].to_s.strip.empty?
30
+ end
31
+ prepare_videos(body)
23
32
  footer = child(section, "footer", "slide-footer")
24
33
  child(footer, "span", "page-footnote")[:textContent] = slide.page_footnote
25
34
  number = child(footer, "span", "slide-number")
@@ -63,6 +72,32 @@ module Wani
63
72
  end
64
73
  end
65
74
 
75
+ def prepare_videos(root)
76
+ root.querySelectorAll(".youtube-video").to_a.each do |video|
77
+ button = video.querySelector(".youtube-play")
78
+ button.addEventListener("click") do
79
+ section = video.closest(".slide")
80
+ next unless section.querySelector(".youtube-overlay") == JS::Null
81
+ overlay = child(section, "div", "youtube-overlay")
82
+ frame = child(overlay, "iframe", "youtube-frame")
83
+ url = video.getAttribute("data-youtube-src").to_s
84
+ frame[:src] = "#{url}#{url.include?("?") ? "&" : "?"}autoplay=1"
85
+ frame[:title] = button.getAttribute("aria-label")
86
+ frame.setAttribute("allow", "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share")
87
+ frame.setAttribute("allowfullscreen", "")
88
+ close = child(overlay, "button", "youtube-close")
89
+ close[:type] = "button"
90
+ close[:textContent] = "閉じる ×"
91
+ close.setAttribute("aria-label", "動画を閉じる")
92
+ close.addEventListener("click") do
93
+ overlay.remove
94
+ button.focus
95
+ end
96
+ close.focus
97
+ end
98
+ end
99
+ end
100
+
66
101
  def resolve_links(root)
67
102
  root.querySelectorAll("img, a").to_a.each do |node|
68
103
  attribute = node[:tagName].to_s == "IMG" ? "src" : "href"
@@ -16,6 +16,21 @@ module Wani
16
16
  !scheme || (image ? %w[http https] : %w[http https mailto]).include?(scheme.downcase)
17
17
  end
18
18
 
19
+ # Accept only an explicit, canonical YouTube video URL and numeric bounds.
20
+ def self.youtube(value)
21
+ return nil unless value.is_a?(String)
22
+ match = value.match(%r{\Ahttps://(?:www\.)?youtube\.com/watch\?([^#]+)\z})
23
+ return nil unless match
24
+ pairs = match[1].split("&", -1).map { |part| part.split("=", 2) }
25
+ return nil unless pairs.all? { |key, val| %w[v start end].include?(key) && val && !val.empty? }
26
+ return nil unless pairs.map(&:first).uniq.length == pairs.length
27
+ params = pairs.to_h
28
+ return nil unless params["v"]&.match?(/\A[A-Za-z0-9_-]{11}\z/)
29
+ return nil unless %w[start end].all? { |key| !params[key] || params[key].match?(/\A\d{1,8}\z/) }
30
+ return nil if params["end"] && params["end"].to_i <= (params["start"] || "0").to_i
31
+ params
32
+ end
33
+
19
34
  def initialize(&diagnostic)
20
35
  @diagnostic = diagnostic || ->(_message) {}
21
36
  end
@@ -37,7 +52,14 @@ module Wani
37
52
  body
38
53
  end
39
54
  when :img
40
- if self.class.safe_url?(node.attr["src"], image: true)
55
+ if (video = self.class.youtube(node.attr["src"]))
56
+ id = video.fetch("v")
57
+ query = %w[start end].filter_map { |key| "#{key}=#{video[key]}" if video[key] }.join("&")
58
+ url = "https://www.youtube.com/embed/#{id}"
59
+ url += "?#{query}" unless query.empty?
60
+ alt = self.class.escape(node.attr["alt"])
61
+ "<span class=\"youtube-video\" data-youtube-src=\"#{self.class.escape(url)}\"><img src=\"https://i.ytimg.com/vi/#{id}/hqdefault.jpg\" alt=\"#{alt}\"><button type=\"button\" class=\"youtube-play\" aria-label=\"#{alt.empty? ? 'YouTube動画を再生' : alt + 'を再生'}\">▶</button></span>"
62
+ elsif self.class.safe_url?(node.attr["src"], image: true)
41
63
  "<img src=\"#{self.class.escape(node.attr['src'])}\" alt=\"#{self.class.escape(node.attr['alt'])}\">"
42
64
  else
43
65
  @diagnostic.call("Unsafe image URL removed")
@@ -7,7 +7,7 @@ module Wani
7
7
  module Server
8
8
  # Only the selected Markdown, images below its directory and fixed gem assets are public.
9
9
  class Application
10
- ASSETS = %w[index.html style.css highlight.css rouge.LICENSE bootstrap.rb speaker.html rabbit.svg shark.svg time-expired.webp runtime.pr672.js wani.wasm runtime.LICENSE runtime.NOTICE build.json
10
+ ASSETS = %w[index.html style.css highlight.css rouge.LICENSE bootstrap.rb speaker.html rabbit.svg shark.svg time-expired-1.webp time-expired-2.webp time-expired-3.webp time-expired-4.webp runtime.pr672.js wani.wasm runtime.LICENSE runtime.NOTICE build.json
11
11
  fonts/IBMPlexSansJP-Regular.woff2 fonts/IBMPlexSansJP-Bold.woff2
12
12
  fonts/UDEVGothic-Regular.ttf fonts/UDEVGothic-Bold.ttf].freeze
13
13
  TYPES = { ".html" => "text/html; charset=utf-8", ".css" => "text/css; charset=utf-8", ".rb" => "text/plain; charset=utf-8", ".js" => "text/javascript", ".wasm" => "application/wasm", ".md" => "text/plain; charset=utf-8", ".svg" => "image/svg+xml", ".png" => "image/png", ".jpg" => "image/jpeg", ".jpeg" => "image/jpeg", ".webp" => "image/webp", ".json" => "application/json", ".woff2" => "font/woff2", ".ttf" => "font/ttf" }.freeze
@@ -46,7 +46,7 @@ module Wani
46
46
  if type.start_with?("image/")
47
47
  headers["Content-Security-Policy"] = "sandbox; default-src 'none'; style-src 'unsafe-inline'"
48
48
  else
49
- headers["Content-Security-Policy"] = "default-src 'self'; script-src 'self' 'unsafe-eval' 'wasm-unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' https: http:; connect-src 'self'; object-src 'none'; base-uri 'none'; frame-ancestors 'none'"
49
+ headers["Content-Security-Policy"] = "default-src 'self'; script-src 'self' 'unsafe-eval' 'wasm-unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' https: http:; connect-src 'self'; frame-src https://www.youtube.com; object-src 'none'; base-uri 'none'; frame-ancestors 'none'"
50
50
  end
51
51
  body = File.binread(file)
52
52
  report_font(body.dup.force_encoding(Encoding::UTF_8)) if path == "/talk/slides.md" && @diagnostics
data/lib/wani/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Wani
2
- VERSION = "0.1.14"
2
+ VERSION = "0.1.16"
3
3
  end
data/templates/slides.md CHANGED
@@ -6,10 +6,6 @@ time_limit: 5
6
6
 
7
7
  Ruby と Markdown でプレゼンテーション。
8
8
 
9
- - 左右キー・Space で移動
10
- - F で全画面
11
- - N で発表者ノート
12
-
13
9
  <!-- page-footnote: Wani のサンプルへようこそ -->
14
10
 
15
11
  <!-- notes:
@@ -160,6 +156,7 @@ N キーで、このページの実際のノートを確認できます。
160
156
 
161
157
  # 発表と配布へ
162
158
 
159
+ - 左右キー・Space で移動し、F キーで全画面にする
163
160
  - N キーで、このページの発表者ノートを開く
164
161
  - 「PDF」でスライドを保存する
165
162
  - 「ノート付き PDF」で説明も一緒に配布する
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wani
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.14
4
+ version: 0.1.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - ledsun
@@ -102,7 +102,10 @@ files:
102
102
  - assets/shark.svg
103
103
  - assets/speaker.html
104
104
  - assets/style.css
105
- - assets/time-expired.webp
105
+ - assets/time-expired-1.webp
106
+ - assets/time-expired-2.webp
107
+ - assets/time-expired-3.webp
108
+ - assets/time-expired-4.webp
106
109
  - assets/wani.wasm
107
110
  - exe/wani
108
111
  - lib/wani.rb
Binary file