trmnl_preview 0.30.1 → 0.30.2

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: 69dba3cf0ef5187c4e4b70ea1e465161ebd2367f8d578ef6c94bc3527e5f437c
4
- data.tar.gz: 8a1a53e6a0d6cc711eda1b26dde6a6b574956fecced07c260990fdfbec665159
3
+ metadata.gz: 685a69fdb40d83171f2f8cb17d89b6954fae9c97f9f551d4210d228acbdb0690
4
+ data.tar.gz: e666f0a63344dc33447eb70cabf3202bab6c6030f967716e3b50954583e222e7
5
5
  SHA512:
6
- metadata.gz: 6ce0c7e09a2f6e3164c15eb9e8a6fa779302e5bb45573e498ca5ac64f98de88be9105751c530a9f3044cdae51cfa1edeb4d20a3d2936373bb4886f6404e5d4cc
7
- data.tar.gz: d08dd7466a052fb6dfedcde3e90761e6a236d4c784689213fcf5b17cc575c68f11cb96ecab0a7fd0a08e00b4fbf76b67d6ec4b3ad39202045dd4b645363ceec0
6
+ metadata.gz: a53e8130820062a99d94d25b2a140506baefccb9e2747c30c46d2cc7795a96c423c4c537c520514c3706a9aafacd1cb215957fdd3af6048b5145632ddb24058a
7
+ data.tar.gz: ebbaa2038fb76c066394dd98218a5305741d2b274763ddc2d41ad4151fc096763ec4593338f364d71807f032687264341e0585f17cf630684276101d757c6f78
data/CHANGELOG.md CHANGED
@@ -1,6 +1,10 @@
1
1
 
2
2
  # Changelog
3
3
 
4
+ ## 0.30.2
5
+
6
+ - `trmnlp serve`'s HTML preview of a device TRMNL scales runs the page's scripts at the CSS size too, then shows the page at the device's size and stops its timers, as the PNG and the device do. Before, a table showed 8 of 20 rows on a TRMNL X where the device shows 15.
7
+
4
8
  ## 0.30.1
5
9
 
6
10
  - 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.
data/lib/trmnlp/app.rb CHANGED
@@ -213,7 +213,7 @@ module TRMNLP
213
213
  end
214
214
 
215
215
  get "/render/#{view}.html" do
216
- @renderer.render_full_page(view, params)
216
+ Screenshot.live_preview(@renderer.render_full_page(view, params))
217
217
  end
218
218
 
219
219
  get "/render/#{view}.png" do
@@ -49,6 +49,31 @@ module TRMNLP
49
49
  Promise.race([window.TRMNLMaps.refresh(), timeout]).then(() => done(true), () => done(false));
50
50
  JS
51
51
 
52
+ # The live preview settles in the page as a capture does, then stays still, as the device shows it.
53
+ SETTLE_LIVE_PREVIEW = <<~JS.freeze
54
+ (async () => {
55
+ const wait = window.setTimeout.bind(window);
56
+ const sleep = (ms) => new Promise((resolve) => wait(resolve, ms));
57
+ const ready = () => { #{READINESS_CHECK_SCRIPT} };
58
+ const readyBy = Date.now() + 1000 * %d;
59
+ while (!ready() && Date.now() < readyBy) await sleep(50);
60
+ if (document.fonts) await Promise.race([document.fonts.ready, sleep(#{FONTS_TIMEOUT_SECONDS * 1000})]);
61
+ if (typeof window.TRMNLMaps?.refresh !== 'function') {
62
+ #{FREEZE_TIMERS}
63
+ #{APPLY_CAPTURE_SCALE}
64
+ return;
65
+ }
66
+ #{APPLY_CAPTURE_SCALE}
67
+ await Promise.race([window.TRMNLMaps.refresh(), sleep(8000)]).catch(() => {});
68
+ #{FREEZE_TIMERS}
69
+ })();
70
+ JS
71
+
72
+ def self.live_preview(html)
73
+ timeout = html.match?(MAPS_DOCUMENT_PATTERN) ? READINESS_TIMEOUT_WITH_MAPS_SECONDS : READINESS_TIMEOUT_SECONDS
74
+ html.sub('</head>', "#{LAYOUT_PASS_STYLE}<script>#{format(SETTLE_LIVE_PREVIEW, timeout)}</script></head>")
75
+ end
76
+
52
77
  def initialize(pool:, viewport_timeout: 5, fonts_timeout: FONTS_TIMEOUT_SECONDS)
53
78
  @pool = pool
54
79
  @viewport_timeout = viewport_timeout
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TRMNLP
4
- VERSION = '0.30.1'
4
+ VERSION = '0.30.2'
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.1
4
+ version: 0.30.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rockwell Schrock