trmnl_preview 0.30.0 → 0.30.1

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: 20431d997e72a0c534f9945c0c8e23cf97dcfff3be5119cbbf2d7973b2c3af73
4
- data.tar.gz: 4a96842d311255ad1cd618e36dab4ef4eaa0504c58efe394a609ee5ddc043dba
3
+ metadata.gz: 69dba3cf0ef5187c4e4b70ea1e465161ebd2367f8d578ef6c94bc3527e5f437c
4
+ data.tar.gz: 8a1a53e6a0d6cc711eda1b26dde6a6b574956fecced07c260990fdfbec665159
5
5
  SHA512:
6
- metadata.gz: 6dcab087ef567886345b3ef14e90931af73c236680afb0555667357f277fd650eaed3c473fa7bb514196ca701cccbd3a68ee6f19e302e0be3d37a23bb5abcdb1
7
- data.tar.gz: '070453995dac9d20fb77914c1a2adcfde9d01f2ccb34899f00b94cf238278b15a3afae3abfe33da9aae17dbacad5f842e34bd080c169ef256c58d144c449b9b5'
6
+ metadata.gz: 6ce0c7e09a2f6e3164c15eb9e8a6fa779302e5bb45573e498ca5ac64f98de88be9105751c530a9f3044cdae51cfa1edeb4d20a3d2936373bb4886f6404e5d4cc
7
+ data.tar.gz: d08dd7466a052fb6dfedcde3e90761e6a236d4c784689213fcf5b17cc575c68f11cb96ecab0a7fd0a08e00b4fbf76b67d6ec4b3ad39202045dd4b645363ceec0
data/CHANGELOG.md CHANGED
@@ -1,6 +1,10 @@
1
1
 
2
2
  # Changelog
3
3
 
4
+ ## 0.30.1
5
+
6
+ - A screen on a device TRMNL scales, as the TRMNL X or a Kobo, runs its scripts at the CSS size and is scaled only for the picture, as TRMNL does. Before, the scripts measured the scaled page, so a table cut rows the device shows (7 of 14 on a TRMNL X) and clamped text kept lines the device cuts.
7
+
4
8
  ## 0.30.0
5
9
 
6
10
  - `trmnlp test` quits a Firefox that stopped answering before it starts a new one. The old geckodriver kept running until something killed it.
@@ -24,8 +24,11 @@ module TRMNLP
24
24
  @requested_color_depth = opts[:color_depth]
25
25
  end
26
26
 
27
- # The page as it is shown: chart libraries swapped for TRMNL's copies.
28
- def html = CHART_LIBRARIES.reduce(@input) { |page, (from, to)| page.gsub(from, to) }
27
+ # The page as it is shown: chart libraries swapped for TRMNL's copies, laid out unscaled until the capture.
28
+ def html
29
+ CHART_LIBRARIES.reduce(@input) { |page, (from, to)| page.gsub(from, to) }
30
+ .sub('</head>', "#{Screenshot::LAYOUT_PASS_STYLE}</head>")
31
+ end
29
32
 
30
33
  def process
31
34
  output = @screenshot.call(html:, width:, height:)
@@ -34,6 +34,21 @@ module TRMNLP
34
34
  window.onresize = null;
35
35
  JS
36
36
 
37
+ # TRMNL lays out a device it scales (TRMNL X, most BYOD screens) at its CSS size while the page's scripts
38
+ # run, then scales the frozen page for the capture, so a script that measures sees what the device shows.
39
+ LAYOUT_PASS_STYLE = '<style id="trmnlp-layout-pass">.trmnl .screen { --pixel-ratio: 1 !important; }</style>'
40
+ APPLY_CAPTURE_SCALE = <<~JS
41
+ document.getElementById('trmnlp-layout-pass')?.remove();
42
+ document.documentElement.offsetHeight;
43
+ JS
44
+ # A map redraws its canvas at the capture scale before the timers it needs are frozen, for 8s at most.
45
+ REFRESH_MAPS = <<~JS
46
+ const done = arguments[arguments.length - 1];
47
+ if (typeof window.TRMNLMaps?.refresh !== 'function') return done(false);
48
+ const timeout = new Promise((resolve) => setTimeout(resolve, 8000));
49
+ Promise.race([window.TRMNLMaps.refresh(), timeout]).then(() => done(true), () => done(false));
50
+ JS
51
+
37
52
  def initialize(pool:, viewport_timeout: 5, fonts_timeout: FONTS_TIMEOUT_SECONDS)
38
53
  @pool = pool
39
54
  @viewport_timeout = viewport_timeout
@@ -123,6 +138,14 @@ module TRMNLP
123
138
  document.documentElement.style.overflow = 'hidden';
124
139
  document.body.style.overflow = 'hidden';
125
140
  JS
141
+ freeze_at_capture_scale(driver, html)
142
+ end
143
+
144
+ def freeze_at_capture_scale(driver, html)
145
+ return driver.execute_script(FREEZE_TIMERS + APPLY_CAPTURE_SCALE) unless html.match?(MAPS_DOCUMENT_PATTERN)
146
+
147
+ driver.execute_script(APPLY_CAPTURE_SCALE)
148
+ driver.execute_async_script(REFRESH_MAPS)
126
149
  driver.execute_script(FREEZE_TIMERS)
127
150
  end
128
151
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TRMNLP
4
- VERSION = '0.30.0'
4
+ VERSION = '0.30.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trmnl_preview
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.30.0
4
+ version: 0.30.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rockwell Schrock