wani 0.1.17 → 0.1.18
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 +1 -1
- data/assets/build.json +3 -3
- data/assets/style.css +2 -0
- data/assets/wani.wasm +0 -0
- data/lib/wani/browser/layout.rb +24 -0
- data/lib/wani/browser/renderer.rb +1 -0
- data/lib/wani/core/parser.rb +4 -3
- 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: 807e65f03f5fedd91956e2c1215d2b22ac5fd31c54315ad0a07c9ead33bf867d
|
|
4
|
+
data.tar.gz: f554099951da00bb88beec2f487064e4bec38d29432022e71b38787098f11416
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b72fece3fc00b4f5c4d20eab3e893fa83dd17f68996fba4707250990135c62fda11589048aba17c4c3b37a5d96ab5199da5a45da012c0ae1e72ac0aa109c4f02
|
|
7
|
+
data.tar.gz: b0bf7044acf98f19cb604c2c9cda5c1bc8be81439fdd9234b839a5e32fe1e30b597ba89e09afc7de624fa66fb1da3874da0a8db0bd0d15d908529974154f9a1c
|
data/README.md
CHANGED
data/assets/build.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.1.
|
|
3
|
-
"source_sha256": "
|
|
2
|
+
"version": "0.1.18",
|
|
3
|
+
"source_sha256": "17bfdfb57284ffc77bc65d760e866c13faef310110789e5447f01d4d95e5d453",
|
|
4
4
|
"loader_commit": "dc6b0ffd5800ed9bfc49268ed8021d456f10ddf8",
|
|
5
|
-
"wasm_sha256": "
|
|
5
|
+
"wasm_sha256": "9f1f6f718d0b1054ca4d38867dfc31a64b68e5a90bea1243855079442eab9392"
|
|
6
6
|
}
|
data/assets/style.css
CHANGED
|
@@ -54,7 +54,9 @@ button:focus-visible, a:focus-visible { outline: 2px solid #557e64; outline-offs
|
|
|
54
54
|
.titleless .body > :last-child { margin-bottom: 0; }
|
|
55
55
|
.titleless .body img { margin-inline: auto; }
|
|
56
56
|
.cover .title { margin-top: 396px; text-align: center; }
|
|
57
|
+
.cover.multiline-title .title { margin-top: 316px; flex-basis: 320px; display: flex; align-items: center; justify-content: center; white-space: pre; }
|
|
57
58
|
.cover .body { display: flex; flex-direction: column; align-items: flex-end; justify-content: flex-end; text-align: right; }
|
|
59
|
+
.cover.multiline-title .body { margin-top: -160px; }
|
|
58
60
|
.cover .body > * { flex-shrink: 0; max-width: 100%; }
|
|
59
61
|
.cover .body > :last-child { margin-bottom: 0; }
|
|
60
62
|
.body ul, .body ol { margin: .2em 0 .4em; padding-left: 1.35em; }
|
data/assets/wani.wasm
CHANGED
|
Binary file
|
data/lib/wani/browser/layout.rb
CHANGED
|
@@ -9,6 +9,7 @@ module Wani
|
|
|
9
9
|
TITLE_MIN = 24
|
|
10
10
|
TITLE_MAX = 220
|
|
11
11
|
NO_WRAP_EMS = 20
|
|
12
|
+
TITLE_GAP_MAX = 64
|
|
12
13
|
|
|
13
14
|
def initialize(document, &warn)
|
|
14
15
|
@document, @warn = document, warn
|
|
@@ -54,17 +55,20 @@ module Wani
|
|
|
54
55
|
def fit_slide(section, number)
|
|
55
56
|
section[:style][:display] = "flex"
|
|
56
57
|
title = section.querySelector(".title")
|
|
58
|
+
title[:style][:transform] = ""
|
|
57
59
|
unless title[:style][:display].to_s == "none"
|
|
58
60
|
fit_font(title, TITLE_MIN, TITLE_MAX)
|
|
59
61
|
@warn.call("スライド #{number}: タイトルが収まりません: #{title[:textContent]}") unless fits?(title)
|
|
60
62
|
end
|
|
61
63
|
body = section.querySelector(".body")
|
|
64
|
+
body[:style][:marginTop] = ""
|
|
62
65
|
prepare_wrapping(body)
|
|
63
66
|
fit_images(body)
|
|
64
67
|
if section[:classList].contains("cover") == JS::True
|
|
65
68
|
body[:style][:fontSize] = "#{COVER_BODY_SIZE}px"
|
|
66
69
|
else
|
|
67
70
|
fit_font(body, BODY_MIN, BODY_MAX)
|
|
71
|
+
add_title_gap(section, title, body)
|
|
68
72
|
end
|
|
69
73
|
body_fits = if section[:classList].contains("cover") == JS::True
|
|
70
74
|
cover_body_fits?(body)
|
|
@@ -72,6 +76,15 @@ module Wani
|
|
|
72
76
|
fits?(body)
|
|
73
77
|
end
|
|
74
78
|
@warn.call("スライド #{number}: 本文が収まりません: #{body[:textContent].to_s[0, 120]}") unless body_fits
|
|
79
|
+
if section[:classList].contains("multiline-title") == JS::True
|
|
80
|
+
title_rect = title.getBoundingClientRect
|
|
81
|
+
body_top = body[:children].to_a.map { |child| child.getBoundingClientRect[:top].to_f }.min
|
|
82
|
+
if body_top
|
|
83
|
+
scale = section.getBoundingClientRect[:width].to_f / WIDTH
|
|
84
|
+
shift = (title_rect[:bottom].to_f + 36 * scale - body_top) / scale
|
|
85
|
+
title[:style][:transform] = "translateY(-#{shift}px)" if shift.positive?
|
|
86
|
+
end
|
|
87
|
+
end
|
|
75
88
|
if section[:classList].contains("cover") == JS::True && title[:style][:display].to_s != "none"
|
|
76
89
|
title_rect = title.getBoundingClientRect
|
|
77
90
|
overlap = body[:children].to_a.any? do |child|
|
|
@@ -99,6 +112,17 @@ module Wani
|
|
|
99
112
|
|
|
100
113
|
private
|
|
101
114
|
|
|
115
|
+
def add_title_gap(section, title, body)
|
|
116
|
+
return if title[:style][:display].to_s == "none" || body[:children].to_a.empty? || !fits?(body)
|
|
117
|
+
scale = section.getBoundingClientRect[:width].to_f / WIDTH
|
|
118
|
+
return if scale <= 0
|
|
119
|
+
bottom = body[:children].to_a.map { |child| child.getBoundingClientRect[:bottom].to_f }.max
|
|
120
|
+
spare = (body.getBoundingClientRect[:bottom].to_f - bottom) / scale
|
|
121
|
+
gap = [[spare * 0.2, TITLE_GAP_MAX].min, 0].max
|
|
122
|
+
body[:style][:marginTop] = "#{gap}px"
|
|
123
|
+
body[:style][:marginTop] = "" unless fits?(body)
|
|
124
|
+
end
|
|
125
|
+
|
|
102
126
|
def prepare_wrapping(body)
|
|
103
127
|
# Rebuild the wrappers when a slide is fitted again (for example after
|
|
104
128
|
# editing). Ranges preserve links, emphasis and explicit line breaks.
|
|
@@ -18,6 +18,7 @@ module Wani
|
|
|
18
18
|
section[:className] = "slide titleless"
|
|
19
19
|
end
|
|
20
20
|
section[:classList].add("cover") if slide.number == 1 && !notes
|
|
21
|
+
section[:classList].add("multiline-title") if slide.number == 1 && !notes && slide.title.include?("\n")
|
|
21
22
|
body = child(section, "div", "body")
|
|
22
23
|
body[:innerHTML] = notes ? slide.notes_html : slide.html
|
|
23
24
|
resolve_links(body)
|
data/lib/wani/core/parser.rb
CHANGED
|
@@ -34,7 +34,7 @@ module Wani
|
|
|
34
34
|
remove(document.root, title) if title
|
|
35
35
|
renderer = SafeHTML.new(&warn)
|
|
36
36
|
note_roots = notes.map { |text| markdown(text).root }
|
|
37
|
-
Slide.new(number: number, title: title ? plain(title) : "", html: renderer.render(document.root),
|
|
37
|
+
Slide.new(number: number, title: title ? plain(title, cover: number == 1) : "", html: renderer.render(document.root),
|
|
38
38
|
page_footnote: page_footnotes.empty? ? "" : page_footnotes.last.strip,
|
|
39
39
|
notes_html: note_roots.map { |root| renderer.render(root) }.join,
|
|
40
40
|
images: ([document.root] + note_roots).flat_map { |root| walk(root).select { |node| node.type == :img && SafeHTML.safe_url?(node.attr['src'], image: true) }.map { |node| node.attr['src'] } }.uniq)
|
|
@@ -114,12 +114,13 @@ module Wani
|
|
|
114
114
|
node.children.each { |child| remove(child, target) }
|
|
115
115
|
end
|
|
116
116
|
|
|
117
|
-
def plain(node)
|
|
117
|
+
def plain(node, cover: false)
|
|
118
118
|
case node.type
|
|
119
119
|
when :text, :codespan then node.value
|
|
120
120
|
when :entity then node.value.char
|
|
121
121
|
when :smart_quote then SafeHTML::QUOTES.fetch(node.value, "")
|
|
122
|
-
|
|
122
|
+
when :html_element then cover && node.value == "br" && node.attr.empty? ? "\n" : node.children.map { |child| plain(child, cover: cover) }.join
|
|
123
|
+
else node.children.map { |child| plain(child, cover: cover) }.join
|
|
123
124
|
end
|
|
124
125
|
end
|
|
125
126
|
end
|
data/lib/wani/version.rb
CHANGED