wani 0.1.15 → 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 +4 -4
- data/assets/build.json +3 -3
- data/assets/index.html +1 -1
- data/assets/style.css +13 -2
- data/assets/time-expired-1.webp +0 -0
- data/assets/time-expired-2.webp +0 -0
- data/assets/time-expired-3.webp +0 -0
- data/assets/time-expired-4.webp +0 -0
- data/assets/wani.wasm +0 -0
- data/lib/wani/browser/application.rb +12 -0
- data/lib/wani/browser/layout.rb +11 -5
- data/lib/wani/browser/presentation_timer.rb +15 -4
- data/lib/wani/browser/renderer.rb +34 -0
- data/lib/wani/core/safe_html.rb +23 -1
- data/lib/wani/server/application.rb +2 -2
- data/lib/wani/version.rb +1 -1
- metadata +5 -2
- data/assets/time-expired.webp +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2211ec774d104372f053f45eff713ce11bb25559a6c5f5770cb8aee772f7fea8
|
|
4
|
+
data.tar.gz: eebe25656e75d3d5679855ba5d3318105a27f511c64fd6d6829a583b8d3b4012
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6a778f887a3eac4882ba9648eeeb64d4aa50efd3dd8582de2070a9fac2c2829af85a10ff0a97c17e5da0601a6474017c978d77a3807be0b4a39830abb6b059bf
|
|
7
|
+
data.tar.gz: 2c67e0eedf595709727b180406e7de518a9a0fd36d0c19b72339ad513e1fc7380ff3e4361a954b765bc0b4ff1f8383d8f88a911c1e540a8d84e6940422f7ed66
|
data/assets/build.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.1.
|
|
3
|
-
"source_sha256": "
|
|
2
|
+
"version": "0.1.16",
|
|
3
|
+
"source_sha256": "32912ebee7503573d054f7cde1150bf882b5211532079d3d348cea72c6af2556",
|
|
4
4
|
"loader_commit": "dc6b0ffd5800ed9bfc49268ed8021d456f10ddf8",
|
|
5
|
-
"wasm_sha256": "
|
|
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"
|
|
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; }
|
|
@@ -66,6 +66,17 @@ button:focus-visible, a:focus-visible { outline: 2px solid #557e64; outline-offs
|
|
|
66
66
|
.body th, .body td { border: 1px solid #bac8bd; padding: .15em .3em; }
|
|
67
67
|
.body img { display: block; object-fit: contain; max-width: 100%; }
|
|
68
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; } }
|
|
69
80
|
.slide-footer { flex: 0 0 128px; position: relative; display: flex; align-items: start; font-size: 24px; color: #71887e; padding-top: 12px; }
|
|
70
81
|
.page-footnote { width: 100%; min-width: 0; height: 1.5em; line-height: 1.5; white-space: nowrap; overflow: hidden; }
|
|
71
82
|
.decorations { position: absolute; left: 0; right: 132px; bottom: 0; height: 80px; }
|
|
@@ -118,7 +129,7 @@ button:focus-visible, a:focus-visible { outline: 2px solid #557e64; outline-offs
|
|
|
118
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; }
|
|
119
130
|
#time-expired[hidden], #countdown[hidden] { display: none; }
|
|
120
131
|
#time-expired h1 { margin: 0; font-size: clamp(24px, 4vw, 56px); }
|
|
121
|
-
.time-expired-image { width: min(90vw, calc(65vh *
|
|
132
|
+
.time-expired-image { width: min(90vw, calc(65vh * 4 / 3)); aspect-ratio: 4 / 3; height: auto; flex-shrink: 0; }
|
|
122
133
|
#time-expired p { margin: 8px 0; text-align: center; }
|
|
123
134
|
@media print { #countdown, #time-expired { display: none !important; } }
|
|
124
135
|
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
data/assets/wani.wasm
CHANGED
|
Binary file
|
|
@@ -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)
|
data/lib/wani/browser/layout.rb
CHANGED
|
@@ -164,13 +164,19 @@ module Wani
|
|
|
164
164
|
def fit_images(body)
|
|
165
165
|
images = body.querySelectorAll("img").to_a
|
|
166
166
|
return if images.empty?
|
|
167
|
-
|
|
168
|
-
|
|
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
|
|
169
173
|
images.each do |image|
|
|
170
174
|
next if image[:naturalWidth].to_i.zero? || image[:naturalHeight].to_i.zero?
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
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"
|
|
174
180
|
end
|
|
175
181
|
end
|
|
176
182
|
end
|
|
@@ -3,18 +3,29 @@ module Wani
|
|
|
3
3
|
class Application
|
|
4
4
|
private
|
|
5
5
|
|
|
6
|
-
# Decode the
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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 }
|
|
@@ -21,6 +21,14 @@ module Wani
|
|
|
21
21
|
body = child(section, "div", "body")
|
|
22
22
|
body[:innerHTML] = notes ? slide.notes_html : slide.html
|
|
23
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)
|
|
24
32
|
footer = child(section, "footer", "slide-footer")
|
|
25
33
|
child(footer, "span", "page-footnote")[:textContent] = slide.page_footnote
|
|
26
34
|
number = child(footer, "span", "slide-number")
|
|
@@ -64,6 +72,32 @@ module Wani
|
|
|
64
72
|
end
|
|
65
73
|
end
|
|
66
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
|
+
|
|
67
101
|
def resolve_links(root)
|
|
68
102
|
root.querySelectorAll("img, a").to_a.each do |node|
|
|
69
103
|
attribute = node[:tagName].to_s == "IMG" ? "src" : "href"
|
data/lib/wani/core/safe_html.rb
CHANGED
|
@@ -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.
|
|
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
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.
|
|
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
|
data/assets/time-expired.webp
DELETED
|
Binary file
|