wani 0.1.18 → 0.1.19

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: 807e65f03f5fedd91956e2c1215d2b22ac5fd31c54315ad0a07c9ead33bf867d
4
- data.tar.gz: f554099951da00bb88beec2f487064e4bec38d29432022e71b38787098f11416
3
+ metadata.gz: 666d21b324b5457905dcdc891c7265426e50828f28763ec7f219ffd9d64ada79
4
+ data.tar.gz: c4ddb01d9df3d6c8c2b48c2bcc47b0f8e84dad874d5c5b0c55797012e5c402a0
5
5
  SHA512:
6
- metadata.gz: b72fece3fc00b4f5c4d20eab3e893fa83dd17f68996fba4707250990135c62fda11589048aba17c4c3b37a5d96ab5199da5a45da012c0ae1e72ac0aa109c4f02
7
- data.tar.gz: b0bf7044acf98f19cb604c2c9cda5c1bc8be81439fdd9234b839a5e32fe1e30b597ba89e09afc7de624fa66fb1da3874da0a8db0bd0d15d908529974154f9a1c
6
+ metadata.gz: b7a33af1ca64b366e00e591bf9116a99db49787329bc505f222c19e7048a0d47b47eebfcf4c93cd98cbc80ce7db11ee70c2bc1ffe4e2573f3d2715583baae054
7
+ data.tar.gz: 6cc590a84d9618a4fa8f60853f9b5ab4cba52023878d69f42d4481e98d64fdd0985479e87e72551f306a7959437266e558bbc6bf9a9ec90ebf0cf84ad9050d07
data/README.md CHANGED
@@ -174,7 +174,7 @@ Front Matter の `time_limit` に分数を指定して変更できます(小
174
174
 
175
175
  - 1920×1080、16:9
176
176
  - 白背景
177
- - 画像は比率を維持して縦に配置し、画像だけの場合は本文領域を広く使います。
177
+ - 画像は比率を維持して縦に配置し、画像だけの場合は本文領域を広く使います。`![bg left](画像パス)` または `![bg right](画像パス)` で画像と文章を左右に配置できます([記法ガイド](docs/markdown.md#画像))。
178
178
 
179
179
  ## 警告
180
180
 
data/assets/build.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
- "version": "0.1.18",
3
- "source_sha256": "17bfdfb57284ffc77bc65d760e866c13faef310110789e5447f01d4d95e5d453",
2
+ "version": "0.1.19",
3
+ "source_sha256": "14dc67db4de65efbcb96d0a65c2ba826bcd553006ea403428eba2665fb133ab8",
4
4
  "loader_commit": "dc6b0ffd5800ed9bfc49268ed8021d456f10ddf8",
5
- "wasm_sha256": "9f1f6f718d0b1054ca4d38867dfc31a64b68e5a90bea1243855079442eab9392"
5
+ "wasm_sha256": "2c9c66985f3c8ddb4b949abc046b843cd4b4a7c530f8dfb8730d34215c062cb5"
6
6
  }
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
@@ -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
- budget = body[:clientHeight].to_f * fraction / images.length
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
- ratio = [body[:clientWidth].to_f / width, budget / height].min
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
@@ -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
- "<img src=\"#{self.class.escape(node.attr['src'])}\" alt=\"#{self.class.escape(node.attr['alt'])}\">"
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
@@ -1,3 +1,3 @@
1
1
  module Wani
2
- VERSION = "0.1.18"
2
+ VERSION = "0.1.19"
3
3
  end
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.18
4
+ version: 0.1.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - ledsun