wani 0.1.18 → 0.1.20
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 +4 -4
- data/README.md +2 -2
- data/assets/build.json +3 -3
- data/assets/index.html +1 -0
- data/assets/style.css +3 -0
- data/assets/wani.wasm +0 -0
- data/lib/wani/browser/application.rb +47 -15
- data/lib/wani/browser/fonts.rb +3 -0
- data/lib/wani/browser/layout.rb +4 -2
- data/lib/wani/browser/renderer.rb +17 -0
- data/lib/wani/core/safe_html.rb +5 -1
- data/lib/wani/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5dc5de6179b5a6529b97c0f9f78527a91896ac6969ae4a4b75550880025d9785
|
|
4
|
+
data.tar.gz: 462ab7102a3c7a330e57fac7d8c13eea8f1a3e59f6eacf227c17e1cf53d48000
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 90179a275eda790ea768d86fb927bb735e1d2997a7e3154972b2ab8be7fee1283a3f1d08fa41dcc4d46b95987ed11990a277c6c66873b0d42dcef3a49a574299
|
|
7
|
+
data.tar.gz: 293f9706ff8c166e94470ba899a18e5e5711f49d2e4c2741b07a4c0e1abd16773ead83eb5d2c4a454775f35ab63a96d7b5420bb0eb2803120e1e6f8ae050fb44
|
data/README.md
CHANGED
|
@@ -40,7 +40,7 @@ wani serve
|
|
|
40
40
|
http://127.0.0.1:8000/ をブラウザーで開きます。
|
|
41
41
|
|
|
42
42
|
`new`コマンドで生成されるプロジェクトには、Markdown記法を紹介する10ページの `slides.md` とサンプルSVG画像が含まれています。
|
|
43
|
-
`slides.md`
|
|
43
|
+
`slides.md` の変更はツールバーの「再読み込み」で反映できます。Ruby の VM を起動し直さず、表示中のページと発表タイマーを維持します。時間制限の変更は次の発表開始時に反映されます。
|
|
44
44
|
|
|
45
45
|
## Markdown記法
|
|
46
46
|
|
|
@@ -174,7 +174,7 @@ Front Matter の `time_limit` に分数を指定して変更できます(小
|
|
|
174
174
|
|
|
175
175
|
- 1920×1080、16:9
|
|
176
176
|
- 白背景
|
|
177
|
-
-
|
|
177
|
+
- 画像は比率を維持して縦に配置し、画像だけの場合は本文領域を広く使います。`` または `` で画像と文章を左右に配置できます([記法ガイド](docs/markdown.md#画像))。
|
|
178
178
|
|
|
179
179
|
## 警告
|
|
180
180
|
|
data/assets/build.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.1.
|
|
3
|
-
"source_sha256": "
|
|
2
|
+
"version": "0.1.20",
|
|
3
|
+
"source_sha256": "00c049b3a3eb0b8e6dd9993561b2f0ab9ef5b41556386e5b987a9ffc2462d91c",
|
|
4
4
|
"loader_commit": "dc6b0ffd5800ed9bfc49268ed8021d456f10ddf8",
|
|
5
|
-
"wasm_sha256": "
|
|
5
|
+
"wasm_sha256": "4b68476ad9d911de4483243e215317f3f9bd6d622fc404c695ed59a5e374dbf2"
|
|
6
6
|
}
|
data/assets/index.html
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
<output id="position" aria-live="polite">— / —</output>
|
|
16
16
|
<button id="next" title="次へ (→ / Space / PageDown)" disabled>→</button>
|
|
17
17
|
<span class="toolbar-divider"></span>
|
|
18
|
+
<button id="reload-slides" title="スライドを再読み込み" disabled>再読み込み</button>
|
|
18
19
|
<button id="fullscreen" title="全画面 (F)" disabled>全画面</button>
|
|
19
20
|
<button id="speaker" title="発表者ノート (N)" disabled>ノート</button>
|
|
20
21
|
<button id="print" disabled>PDF</button>
|
data/assets/style.css
CHANGED
|
@@ -67,6 +67,9 @@ button:focus-visible, a:focus-visible { outline: 2px solid #557e64; outline-offs
|
|
|
67
67
|
.body table { border-collapse: collapse; width: 100%; }
|
|
68
68
|
.body th, .body td { border: 1px solid #bac8bd; padding: .15em .3em; }
|
|
69
69
|
.body img { display: block; object-fit: contain; max-width: 100%; }
|
|
70
|
+
.body.image-columns { display: flex; flex-direction: row; align-items: center; justify-content: space-between; gap: 6%; text-align: left; }
|
|
71
|
+
.image-columns > .image-column-image, .image-columns > .image-column-text { flex: 0 0 47%; min-width: 0; margin: 0; }
|
|
72
|
+
.image-columns > .image-column-image img { margin-inline: auto; }
|
|
70
73
|
.body a { color: #32634b; }
|
|
71
74
|
.body p:has(.youtube-video) { margin-bottom: 0; }
|
|
72
75
|
.body p.youtube-only { width: 100%; text-align: center; }
|
data/assets/wani.wasm
CHANGED
|
Binary file
|
|
@@ -14,25 +14,13 @@ module Wani
|
|
|
14
14
|
@index = 0
|
|
15
15
|
@warnings = []
|
|
16
16
|
@layout = Layout.new(@document) { |message| warn(message) }
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
@presentation = Core::Parser.new.parse(response.text.await.to_s)
|
|
20
|
-
title = @presentation.slides.first.title
|
|
21
|
-
@document[:title] = title unless title.empty?
|
|
22
|
-
@presentation.diagnostics.each { |item| warn("#{item.slide ? "スライド #{item.slide}: " : ""}#{item.message}") }
|
|
23
|
-
@renderer = Renderer.new(@document, @presentation)
|
|
24
|
-
@sections = @presentation.slides.map { |slide| @renderer.slide(slide) }
|
|
25
|
-
@sections.each { |section| element("stage").appendChild(section) }
|
|
26
|
-
font_sections = @sections + @presentation.slides.map { |slide| @renderer.slide(slide, notes: true) }
|
|
27
|
-
Fonts.new(@document) { |message| warn(message) }.apply(@presentation.fonts, font_sections)
|
|
28
|
-
@layout.wait_assets(element("stage"))
|
|
29
|
-
@sections.each_with_index { |section, index| @layout.fit_slide(section, index + 1) }
|
|
30
|
-
prepare_pages(false)
|
|
17
|
+
@presentation = fetch_presentation
|
|
18
|
+
render_presentation
|
|
31
19
|
prepare_timer_image
|
|
32
20
|
bind_events
|
|
33
21
|
@waiting_to_start = JS.global[:location][:hash].to_s.empty?
|
|
34
22
|
go(hash_index)
|
|
35
|
-
%w[previous next fullscreen speaker print print-notes].each { |id| element(id)[:disabled] = false }
|
|
23
|
+
%w[previous next fullscreen speaker print print-notes reload-slides].each { |id| element(id)[:disabled] = false }
|
|
36
24
|
update_buttons
|
|
37
25
|
if @waiting_to_start
|
|
38
26
|
element("start-overlay")[:hidden] = false
|
|
@@ -44,6 +32,49 @@ module Wani
|
|
|
44
32
|
|
|
45
33
|
private
|
|
46
34
|
|
|
35
|
+
def fetch_presentation
|
|
36
|
+
response = JS.global.fetch("/talk/slides.md", { cache: "no-store" }.to_js).await
|
|
37
|
+
raise "Markdown を読み込めません (HTTP #{response[:status].to_i})" unless response[:ok] == JS::True
|
|
38
|
+
Core::Parser.new.parse(response.text.await.to_s)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def render_presentation
|
|
42
|
+
@warnings = []
|
|
43
|
+
element("warnings")[:hidden] = true
|
|
44
|
+
element("warnings")[:textContent] = ""
|
|
45
|
+
@document.querySelectorAll('[data-wani-font]').to_a.each(&:remove)
|
|
46
|
+
title = @presentation.slides.first.title
|
|
47
|
+
@document[:title] = title.empty? ? "Wani — Markdown presentation" : title
|
|
48
|
+
@presentation.diagnostics.each { |item| warn("#{item.slide ? "スライド #{item.slide}: " : ""}#{item.message}") }
|
|
49
|
+
@renderer = Renderer.new(@document, @presentation)
|
|
50
|
+
@sections = @presentation.slides.map { |slide| @renderer.slide(slide) }
|
|
51
|
+
element("stage").replaceChildren
|
|
52
|
+
@sections.each { |section| element("stage").appendChild(section) }
|
|
53
|
+
font_sections = @sections + @presentation.slides.map { |slide| @renderer.slide(slide, notes: true) }
|
|
54
|
+
Fonts.new(@document) { |message| warn(message) }.apply(@presentation.fonts, font_sections)
|
|
55
|
+
@layout.wait_assets(element("stage"))
|
|
56
|
+
@sections.each_with_index { |section, index| @layout.fit_slide(section, index + 1) }
|
|
57
|
+
prepare_pages(false)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def reload_slides
|
|
61
|
+
element("reload-slides")[:disabled] = true
|
|
62
|
+
element("status")[:textContent] = "スライドを再読み込みしています…"
|
|
63
|
+
presentation = fetch_presentation
|
|
64
|
+
@presentation = presentation
|
|
65
|
+
render_presentation
|
|
66
|
+
prepare_timer_image if @waiting_to_start
|
|
67
|
+
@active_number = nil
|
|
68
|
+
# The start dialog remains open when the presentation has not started.
|
|
69
|
+
go(@index)
|
|
70
|
+
element("status")[:textContent] = "スライドを再読み込みしました"
|
|
71
|
+
rescue => error
|
|
72
|
+
warn("スライドを再読み込みできませんでした: #{error.message}")
|
|
73
|
+
element("status")[:textContent] = "スライドの再読み込みに失敗しました"
|
|
74
|
+
ensure
|
|
75
|
+
element("reload-slides")[:disabled] = false
|
|
76
|
+
end
|
|
77
|
+
|
|
47
78
|
def element(id)
|
|
48
79
|
@document.getElementById(id)
|
|
49
80
|
end
|
|
@@ -74,6 +105,7 @@ module Wani
|
|
|
74
105
|
end
|
|
75
106
|
element("previous").addEventListener("click") { go(@index - 1) }
|
|
76
107
|
element("next").addEventListener("click") { go(@index + 1) }
|
|
108
|
+
element("reload-slides").addEventListener("click") { async { reload_slides } }
|
|
77
109
|
element("fullscreen").addEventListener("click") { fullscreen }
|
|
78
110
|
element("speaker").addEventListener("click") { speaker }
|
|
79
111
|
element("print").addEventListener("click") { async { print_pages(false) } }
|
data/lib/wani/browser/fonts.rb
CHANGED
|
@@ -11,6 +11,7 @@ module Wani
|
|
|
11
11
|
def apply(settings, sections)
|
|
12
12
|
weights = [settings.fetch("title-weight", 700), settings.fetch("body-weight", 400)]
|
|
13
13
|
weight_style = @document.createElement("style")
|
|
14
|
+
weight_style.setAttribute("data-wani-font", "")
|
|
14
15
|
weight_style[:textContent] = ".slide .title { font-weight: #{weights[0]}; } .slide .body { font-weight: #{weights[1]}; }"
|
|
15
16
|
@document[:head].appendChild(weight_style)
|
|
16
17
|
name = settings["default"]
|
|
@@ -24,6 +25,7 @@ module Wani
|
|
|
24
25
|
return
|
|
25
26
|
end
|
|
26
27
|
link = @document.createElement("link")
|
|
28
|
+
link.setAttribute("data-wani-font", "")
|
|
27
29
|
link[:rel] = "stylesheet"
|
|
28
30
|
link[:href] = "/talk/#{entry.fetch('stylesheet')}"
|
|
29
31
|
loaded = JS.global[:Promise].new do |resolve, _reject|
|
|
@@ -49,6 +51,7 @@ module Wani
|
|
|
49
51
|
end
|
|
50
52
|
@document[:fonts][:ready].await
|
|
51
53
|
style = @document.createElement("style")
|
|
54
|
+
style.setAttribute("data-wani-font", "")
|
|
52
55
|
style[:textContent] = %(.slide .title, .slide .body { font-family: #{family}, "Zen Kaku Gothic New", sans-serif; })
|
|
53
56
|
@document[:head].appendChild(style)
|
|
54
57
|
rescue => error
|
data/lib/wani/browser/layout.rb
CHANGED
|
@@ -193,12 +193,14 @@ module Wani
|
|
|
193
193
|
mixed = !content[:textContent].to_s.strip.empty?
|
|
194
194
|
videos_only = images.all? { |image| image.closest(".youtube-video") != JS::Null }
|
|
195
195
|
fraction = mixed ? 0.45 : (videos_only ? 0.98 : 0.85)
|
|
196
|
-
|
|
196
|
+
columns = body[:classList].contains("image-columns") == JS::True
|
|
197
|
+
budget = body[:clientHeight].to_f * (columns ? 0.95 : fraction) / images.length
|
|
197
198
|
images.each do |image|
|
|
198
199
|
next if image[:naturalWidth].to_i.zero? || image[:naturalHeight].to_i.zero?
|
|
199
200
|
width = image[:naturalWidth].to_f
|
|
200
201
|
height = image.closest(".youtube-video") == JS::Null ? image[:naturalHeight].to_f : width * 9 / 16
|
|
201
|
-
|
|
202
|
+
available_width = body[:clientWidth].to_f * (columns ? 0.47 : 1.0)
|
|
203
|
+
ratio = [available_width / width, budget / height].min
|
|
202
204
|
image[:style][:width] = "#{width * ratio}px"
|
|
203
205
|
image[:style][:height] = "#{height * ratio}px"
|
|
204
206
|
end
|
|
@@ -22,6 +22,7 @@ module Wani
|
|
|
22
22
|
body = child(section, "div", "body")
|
|
23
23
|
body[:innerHTML] = notes ? slide.notes_html : slide.html
|
|
24
24
|
resolve_links(body)
|
|
25
|
+
prepare_image_columns(body) unless notes
|
|
25
26
|
body.querySelectorAll("p").to_a.each do |paragraph|
|
|
26
27
|
children = paragraph[:children].to_a
|
|
27
28
|
next unless children.length == 1 && children.first[:classList].contains("youtube-video") == JS::True
|
|
@@ -109,6 +110,22 @@ module Wani
|
|
|
109
110
|
|
|
110
111
|
private
|
|
111
112
|
|
|
113
|
+
def prepare_image_columns(body)
|
|
114
|
+
image = body[:children].to_a.find do |element|
|
|
115
|
+
element[:tagName].to_s == "P" && element[:children][:length].to_i == 1 &&
|
|
116
|
+
element.querySelector("img.wani-image-left, img.wani-image-right") != JS::Null && element[:textContent].to_s.strip.empty?
|
|
117
|
+
end
|
|
118
|
+
return unless image
|
|
119
|
+
side = image.querySelector("img")[:className].to_s.end_with?("left") ? "left" : "right"
|
|
120
|
+
text = @document.createElement("div")
|
|
121
|
+
text[:className] = "image-column-text"
|
|
122
|
+
body[:childNodes].to_a.each { |node| text.appendChild(node) unless node == image }
|
|
123
|
+
image[:classList].add("image-column-image")
|
|
124
|
+
body[:classList].add("image-columns", "image-#{side}")
|
|
125
|
+
body.appendChild(side == "left" ? image : text)
|
|
126
|
+
body.appendChild(side == "left" ? text : image)
|
|
127
|
+
end
|
|
128
|
+
|
|
112
129
|
def child(parent, tag, class_name)
|
|
113
130
|
element = @document.createElement(tag)
|
|
114
131
|
element[:className] = class_name
|
data/lib/wani/core/safe_html.rb
CHANGED
|
@@ -60,7 +60,11 @@ module Wani
|
|
|
60
60
|
alt = self.class.escape(node.attr["alt"])
|
|
61
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
62
|
elsif self.class.safe_url?(node.attr["src"], image: true)
|
|
63
|
-
|
|
63
|
+
alt = node.attr["alt"].to_s
|
|
64
|
+
split = alt.match(/\Abg\s+(left|right)(?:\s+(.*))?\z/m)
|
|
65
|
+
position = split ? " class=\"wani-image-#{split[1]}\"" : ""
|
|
66
|
+
alt = split[2].to_s if split
|
|
67
|
+
"<img#{position} src=\"#{self.class.escape(node.attr['src'])}\" alt=\"#{self.class.escape(alt)}\">"
|
|
64
68
|
else
|
|
65
69
|
@diagnostic.call("Unsafe image URL removed")
|
|
66
70
|
self.class.escape(node.attr["alt"])
|
data/lib/wani/version.rb
CHANGED