trmnl_preview 0.33.1 → 0.34.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: 5fafe6b552e46a6d6bd887247b26039c0862bfd90a5b0ee7dc1bf7f2107d57d3
4
- data.tar.gz: afe60774959b995e97a7c34a4230d9fa8db14645f79f9bf75d94eac6bd1133c5
3
+ metadata.gz: 9080cbf504b4e74dd3f9432cb0375b8aae603c9b1143f0b62d3a3c04ce4acb10
4
+ data.tar.gz: 14e02c7381aa8f78af114a9a360d2fc81bd560300765a571456ac3c2c0823285
5
5
  SHA512:
6
- metadata.gz: f588a82d30db94c88802984b2d5e9a50a759c80b1ad0acc4642e8694e3d69b7b3e9b98da2d657795c0591ab92eac4c227d1c34a071c4a41d9f5f49b5ae08553e
7
- data.tar.gz: f7890f9399a83afb1ec36f18f506f74cbbdf9fa3157623ec88678afc3d54ae862dd33be395125e08356768aac11e9f27888b37c1d1ece6b40db0f10173a70a28
6
+ metadata.gz: 0f8913c34e968d85bc8d6d6f5cb8c568ec17e6b9ad372c271658c928e9cac6201cd98a88a88487196aa8577e76c48e8d53a078419110edbd3abe6d2a65d62ca1
7
+ data.tar.gz: 22af8cfa7ecc90847ce83475decb253168883aec90b5368494ddadf351c8a2701d2ac6d4b0f35a6abf5899e57bfd1fc550d198829502cda802389e311383818e
data/CHANGELOG.md CHANGED
@@ -1,6 +1,19 @@
1
1
 
2
2
  # Changelog
3
3
 
4
+ ## 0.34.1
5
+
6
+ - The `random_number` filter works in `serve`, `build`, `test` and `lint`, as on TRMNL. Before, `{{ 0 | random_number: 1, 20 }}` drew 0 on every screen, so a recipe that picks a random item drew only its first one, and lint called the filter unknown.
7
+
8
+ ## 0.34.0
9
+
10
+ - `trmnlp test --report` writes `og-vs-x-<view>.png` for the quadrant and half views too, not only `og-vs-x.png` for the full view, when the tests drew that view on TRMNL OG and TRMNL X in landscape.
11
+ - Third-party plugins: a `third_party:` block in `.trmnlp.yml` with the plugin's `plugin_markup_url` makes `serve`, `build` and `test` post the same form TRMNL posts (`user_uuid` and the `trmnl` variables for the device being drawn, with an optional Bearer token) and draw each view from the markup, `shared` and `merge_variables` the plugin answers with. One answer draws every view, as one TRMNL refresh does.
12
+ - `trmnlp build --png --width --height` draws the page as the TRMNL model of that size, in landscape or portrait, as `trmnl.render(device:)` does. Before, `--width 1872 --height 1404` drew an 800x480 page in the corner of the PNG, and `trmnl.device` still said 800x480.
13
+ - `trmnlp build --png --palette <id>` and the `trmnlp serve` picker draw the PNG in the device's palette, as TRMNL does: a color palette such as `color-4bwry` or `color-6a` holds only that panel's inks, `color-12bit` keeps 16 levels a channel and `color-24bit` keeps the capture, and a gray palette such as `gray-4` sets the gray count. A page that asks for `image-dither` gets TRMNL's brightness boost and Floyd-Steinberg dither. Before, every PNG held gray steps whatever the palette. A palette id TRMNL does not have stops `build` and the preview with the ids it has.
14
+ - `have_no_overflow` passes text hidden for screen readers, in a box whose `clip-path: inset(50%)` or `clip: rect(0 0 0 0)` leaves nothing of it, as Tailwind's `sr-only`, Bootstrap's `visually-hidden` and FullCalendar's day labels hide it. Such text draws nothing, but its 1px box cuts it, so every screen of a recipe using one failed.
15
+ - `trmnl.render` takes `text_scale:` and `scale:`, and `trmnlp serve` has a Text Scale and a Scale picker. Text Scale is the setting a device owner or a playlist item picks on TRMNL, so a recipe can now be checked at `text_scale: 'large'` and `'xlarge'`, the sizes its owners draw it at. Scale sizes text and layout; TRMNL applies it itself, today only `xxsmall` for a 3x3 mashup cell, and an owner cannot pick it. `regular` adds no class, as on TRMNL.
16
+
4
17
  ## 0.33.1
5
18
 
6
19
  - The Docker image draws Hindi, Bengali, Tamil, Thai, Tibetan and other Indic text, which showed as empty boxes. It now has the same fonts TRMNL renders with, and keeps DejaVu as the default font.
data/README.md CHANGED
@@ -386,6 +386,10 @@ ignored_lint_rules:
386
386
  merged_plugins:
387
387
  private_plugin_42: ../weather
388
388
 
389
+ # a third-party plugin's markup endpoint; see Third-party plugins
390
+ third_party:
391
+ plugin_markup_url: http://localhost:3000/markup
392
+
389
393
  # replace literal asset URLs during serve, test, and build --png
390
394
  asset_overrides:
391
395
  https://example.com/logo.svg: assets/logo.svg
@@ -458,6 +462,33 @@ For example, as a polling header:
458
462
  Authorization=Bearer {{ oauth_access_token }}
459
463
  ```
460
464
 
465
+ ## Third-party plugins
466
+
467
+ A [third-party plugin](https://docs.trmnl.com/go/plugin-marketplace/introduction) serves its own markup ([how TRMNL asks for it](https://docs.trmnl.com/go/plugin-marketplace/plugin-screen-generation-flow)). Point trmnlp at the plugin's markup endpoint in `.trmnlp.yml`, and `serve`, `build` and `test` draw each view from it:
468
+
469
+ ```yaml
470
+ third_party:
471
+ plugin_markup_url: http://localhost:3000/markup
472
+ access_token: "{{ env.PLUGIN_ACCESS_TOKEN }}" # optional, sent as Authorization: Bearer
473
+ user_uuid: 1b2c3d4e-0000-4000-8000-000000000001 # optional, the uuid your plugin stored at install
474
+ ```
475
+
476
+ For each view, trmnlp sends the request TRMNL sends: a form-encoded POST of `user_uuid` and the `trmnl` variables (`trmnl[user][...]`, `trmnl[device][width]` and so on) for the device being drawn. The plugin answers with JSON:
477
+
478
+ ```json
479
+ { "markup": "...", "markup_half_horizontal": "...", "markup_half_vertical": "...", "markup_quadrant": "...",
480
+ "shared": "...", "merge_variables": { "team": "Porto" } }
481
+ ```
482
+
483
+ Each view's markup renders after `shared` with `merge_variables` only, as on TRMNL, and a view the answer leaves out shows "… view not available.". Like one TRMNL refresh, one answer draws every view: `build` asks once per device, and `serve` asks once per page load and shows the `merge_variables` in its data panel. An answer that is not 2xx, not a JSON object, or has a markup that is not a string shows why on the screen. In a test, mock the url to change the merge variables:
484
+
485
+ ```ruby
486
+ mocks = { 'http://localhost:3000/markup' => { json: { markup: '<span class="title">{{ team }}</span>', merge_variables: { team: 'Porto' } } } }
487
+ expect(trmnl.render(mocks:)).to have_text('Porto')
488
+ ```
489
+
490
+ trmnlp posts to a localhost url, which TRMNL refuses, so a plugin running on your machine works without a tunnel. `trmnlp lint` checks the markup in `src/`, so it does not apply to a third-party plugin.
491
+
461
492
  ## Serverless Transforms
462
493
 
463
494
  `trmnlp` can run a transform script (`python`, `ruby`, `php`, or `node`) against the polled API response before handing data to your Liquid templates — matching the hosted plugin service's behavior.
@@ -1,6 +1,6 @@
1
1
  # Mirrored from the TRMNL design-system source.
2
2
  # Refresh with `rake framework:sync` — do not edit manually.
3
- latest: 3.4.4
3
+ latest: 3.4.6
4
4
  versions:
5
5
  - number: 0.0.1
6
6
  released_at: '2024-06-22'
@@ -102,3 +102,7 @@ versions:
102
102
  released_at: '2026-10-15'
103
103
  - number: 3.4.4
104
104
  released_at: '2026-10-24'
105
+ - number: 3.4.5
106
+ released_at: '2026-11-06'
107
+ - number: 3.4.6
108
+ released_at: '2026-11-06'
data/lib/trmnlp/app.rb CHANGED
@@ -204,7 +204,7 @@ module TRMNLP
204
204
  get "/#{view}" do
205
205
  @view = view
206
206
  device = @user_data_assembler.device_from_params(params)
207
- user_data = @user_data_assembler.call(device:)
207
+ user_data = @context.third_party_markup&.preview_merge_variables(device:) || @user_data_assembler.call(device:)
208
208
  @user_data = JSON.pretty_generate(user_data)
209
209
  # Measured on compact JSON, the way the hosted service sizes merge variables.
210
210
  @payload_size = JSON.generate(user_data).bytesize
@@ -229,6 +229,8 @@ module TRMNLP
229
229
 
230
230
  temp_image.close
231
231
  temp_image.unlink
232
+ rescue TestingError => e
233
+ halt 400, e.message
232
234
  end
233
235
  end
234
236
 
@@ -280,15 +282,10 @@ module TRMNLP
280
282
  end
281
283
  end
282
284
 
283
- # ScreenGenerator is request-scoped — it carries the per-request width,
284
- # height, and color_depth — so it is built here rather than on the shared
285
- # Context graph. Screenshots are a serve-only concern and would not belong
286
- # on a Context shared by every command (build, lint, push, ...).
285
+ # Request-scoped (width, height, depth, palette), so built here and not on the Context every command shares.
287
286
  def render_png(html, params)
288
- ScreenGenerator.new(html, screenshot: @screenshot,
289
- width: params[:width]&.to_i,
290
- height: params[:height]&.to_i,
291
- color_depth: params[:color_depth]&.to_i).process
287
+ ScreenGenerator.new(html, screenshot: @screenshot, width: params[:width]&.to_i, height: params[:height]&.to_i,
288
+ color_depth: params[:color_depth]&.to_i, palette_id: params[:palette]).process
292
289
  end
293
290
  end
294
291
  end
data/lib/trmnlp/cli.rb CHANGED
@@ -48,6 +48,7 @@ module TRMNLP
48
48
  method_option :width, type: :numeric, desc: 'PNG width in pixels (with --png)'
49
49
  method_option :height, type: :numeric, desc: 'PNG height in pixels (with --png)'
50
50
  method_option :color_depth, type: :numeric, desc: 'PNG bit depth: 1-8 (with --png)'
51
+ method_option :palette, type: :string, desc: 'TRMNL palette id for the PNG, e.g. color-4bwry (with --png)'
51
52
  def build
52
53
  Commands::Build.run(options)
53
54
  end
@@ -8,12 +8,13 @@ require_relative '../firefox_driver'
8
8
  require_relative '../screen_generator'
9
9
  require_relative '../screenshot'
10
10
  require_relative '../testing/asset_cache'
11
+ require_relative '../testing/device_models'
11
12
 
12
13
  module TRMNLP
13
14
  module Commands
14
15
  class Build < Base
15
- Options = Data.define(:dir, :quiet, :png, :width, :height, :color_depth, :bundle_assets) do
16
- def initialize(bundle_assets: false, **) = super(**, bundle_assets:)
16
+ Options = Data.define(:dir, :quiet, :png, :width, :height, :color_depth, :bundle_assets, :palette) do
17
+ def initialize(bundle_assets: false, palette: nil, **) = super(**, bundle_assets:, palette:)
17
18
  end
18
19
 
19
20
  def call
@@ -34,7 +35,7 @@ module TRMNLP
34
35
  private
35
36
 
36
37
  def build_screen(screen)
37
- html = context.renderer.render_full_page(screen.name)
38
+ html = context.renderer.render_full_page(screen.name, device_params)
38
39
  overrides = context.config.project.asset_overrides
39
40
  built = if options.bundle_assets && overrides.any?
40
41
  asset_cache.rewrite(html, overrides:,
@@ -68,7 +69,27 @@ module TRMNLP
68
69
  # fall back to 800x480 and the screen--Nbit depth sniffed from the markup.
69
70
  def screen_generator(html)
70
71
  ScreenGenerator.new(html, screenshot:, width: options.width,
71
- height: options.height, color_depth: options.color_depth)
72
+ height: options.height, color_depth: options.color_depth, palette_id: options.palette)
73
+ end
74
+
75
+ # --width and --height draw the page as the TRMNL model of that size, as trmnl.render(device:) does.
76
+ def device_params
77
+ return {} unless options.width && options.height
78
+
79
+ @device_params ||= model_params || { width: options.width, height: options.height }
80
+ end
81
+
82
+ def model_params
83
+ size = [options.width, options.height]
84
+ model = Testing::DeviceModels.models.find { [it.values_at('width', 'height'), it.values_at('height', 'width')].include?(size) }
85
+ return unless model
86
+
87
+ orientation = model.values_at('width', 'height') == size ? 'landscape' : 'portrait'
88
+ device = Testing::DeviceModels.find(model['name'], orientation: orientation.to_sym)
89
+ device.render_params.merge(orientation:, screen_classes: device.screen_classes)
90
+ rescue TestingError => e
91
+ reporter.info(reporter.yellow("Drawing #{size.join('x')} without a TRMNL model's layout: #{e.message}"))
92
+ nil
72
93
  end
73
94
 
74
95
  def screenshot = @screenshot ||= Screenshot.new(pool: browser_pool)
@@ -15,8 +15,16 @@ module TRMNLP
15
15
  end
16
16
  end
17
17
 
18
+ THIRD_PARTY_NOTICE = 'trmnlp lint checks the markup in src/. ' \
19
+ "A third-party plugin's markup comes from its plugin_markup_url."
20
+
18
21
  def call
19
22
  context.validate!
23
+ if config.project.third_party
24
+ reporter.info(THIRD_PARTY_NOTICE)
25
+ return true
26
+ end
27
+
20
28
  report
21
29
  issues.empty?
22
30
  end
@@ -53,6 +53,19 @@ module TRMNLP
53
53
  parse_liquid(value).render(values.merge(extra_variables))
54
54
  end
55
55
 
56
+ # A third-party plugin's plugin_markup_url, access_token and user_uuid, with {{ env.X }} filled in.
57
+ def third_party
58
+ return unless @config.key?('third_party')
59
+
60
+ settings = @config['third_party']
61
+ unless settings.is_a?(Hash) && settings['plugin_markup_url']
62
+ raise InvalidConfig, ".trmnlp.yml third_party needs a plugin_markup_url, such as:\n" \
63
+ "third_party:\n plugin_markup_url: http://localhost:3000/markup"
64
+ end
65
+
66
+ with_env(settings)
67
+ end
68
+
56
69
  def time_zone = @config['time_zone'] || 'UTC'
57
70
 
58
71
  def ignored_lint_rules = Array(@config['ignored_lint_rules'])
@@ -5,6 +5,7 @@ require_relative 'config'
5
5
  require_relative 'paths'
6
6
  require_relative 'poller'
7
7
  require_relative 'renderer'
8
+ require_relative 'third_party_markup'
8
9
  require_relative 'reporter'
9
10
  require_relative 'transform_pipeline'
10
11
  require_relative 'user_data_assembler'
@@ -33,7 +34,7 @@ module TRMNLP
33
34
  def poller
34
35
  @poller ||= Poller.new(config:, paths:, oauth_session:, reporter:, async_callback:,
35
36
  outbound_request: @outbound_request,
36
- trmnl_variables: -> { user_data_assembler.polling_variables })
37
+ trmnl_variables: -> { user_data_assembler.trmnl_variables })
37
38
  end
38
39
 
39
40
  def async_callback = @async_callback ||= AsyncCallback.new(config:, paths:, reporter:)
@@ -56,7 +57,18 @@ module TRMNLP
56
57
  source_data: @source_data)
57
58
  end
58
59
 
59
- def renderer = @renderer ||= Renderer.new(config:, paths:, user_data_assembler:)
60
+ def renderer = @renderer ||= Renderer.new(config:, paths:, user_data_assembler:, third_party_markup:)
61
+
62
+ def third_party_markup
63
+ settings = config.project.third_party
64
+ return unless settings
65
+
66
+ @third_party_markup ||= ThirdPartyMarkup.new(
67
+ settings:, trmnl_variables: ->(device) { user_data_assembler.trmnl_variables(device:) },
68
+ **{ outbound_request: @outbound_request }.compact
69
+ )
70
+ end
71
+
60
72
  def watcher = @watcher ||= Watcher.new(config:, user_data_assembler:, transform_pipeline:, reporter:)
61
73
 
62
74
  def webhook_receiver
@@ -65,6 +77,8 @@ module TRMNLP
65
77
 
66
78
  def validate!
67
79
  raise NotAPlugin, "not a plugin directory (did not find #{paths.trmnlp_config})" unless paths.valid?
80
+
81
+ config.project.third_party
68
82
  end
69
83
  end
70
84
  end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'erb'
4
+
5
+ module TRMNLP
6
+ # Form-encodes nested values as TRMNL's HTTP client (HTTParty) does, so a third-party plugin gets the same body.
7
+ module FormBody
8
+ def self.encode(values)
9
+ values.flat_map { |key, value| pairs(key.to_s, value) }
10
+ .map { |name, value| "#{ERB::Util.url_encode(name)}=#{ERB::Util.url_encode(value.to_s)}" }.join('&')
11
+ end
12
+
13
+ def self.pairs(name, value)
14
+ return nested_pairs(name, value) if value.is_a?(Hash)
15
+ return [[name, value]] unless value.is_a?(Array)
16
+
17
+ value.empty? ? [["#{name}[]", '']] : value.flat_map { pairs("#{name}[]", it) }
18
+ end
19
+
20
+ # Breadth first: a hash's own values come before those of the hashes inside it, and an empty list sends nothing.
21
+ def self.nested_pairs(name, hash)
22
+ queue = [[name, hash]]
23
+ queue.each_with_object([]) do |(parent, children), found|
24
+ children.each do |key, child|
25
+ child_name = "#{parent}[#{key}]"
26
+ next queue << [child_name, child] if child.is_a?(Hash)
27
+
28
+ found.concat(child.is_a?(Array) ? child.flat_map { pairs("#{child_name}[]", it) } : [[child_name, child]])
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -14,6 +14,10 @@ module TRMNLP
14
14
  DEFAULT_ASSET_HOST = 'https://trmnl.com'
15
15
  # Framework::Themes::NAMES_BY_ID in trmnl-framework.
16
16
  THEMES = { 'black-and-yellow' => 'Black and Yellow', 'dark' => 'Dark', 'white-and-red' => 'White and Red' }.freeze
17
+ # Text Scale is the setting a device owner or a playlist item picks; Scale is a modifier TRMNL applies itself,
18
+ # today only xxsmall for a 3x3 mashup cell. Regular is the default and adds no class, as on TRMNL.
19
+ SCALES = %w[xxsmall xsmall small large xlarge xxlarge].freeze
20
+ TEXT_SCALES = %w[small large xlarge].freeze
17
21
  DATA_PATH = File.expand_path('../../db/data/framework_versions.yml', __dir__)
18
22
  # DATA_PATH holds a copy of this file, refreshed by `rake framework:sync`.
19
23
  MANIFEST_URL = 'https://raw.githubusercontent.com/usetrmnl/trmnl-framework/main/db/data/framework_versions.yml'
@@ -10,9 +10,14 @@ module TRMNLP
10
10
  MIN_DEPTH = 1
11
11
  MAX_DEPTH = 8
12
12
 
13
- def initialize(depth:, dither:)
13
+ # palette: hex colors of a color panel (TRMNL's /api/palettes `colors`); nil or empty keeps the gray steps.
14
+ # channel_bits: for the `screen--color-full` palettes only; 8 keeps the render lossless (color-24bit),
15
+ # 4 posterizes each channel to 16 levels, 4096 colors (color-12bit).
16
+ def initialize(depth:, dither:, palette: nil, channel_bits: nil)
14
17
  @depth = clamp(depth)
15
18
  @dither = dither
19
+ @palette = Array(palette)
20
+ @channel_bits = channel_bits
16
21
  end
17
22
 
18
23
  def call(path)
@@ -25,6 +30,9 @@ module TRMNLP
25
30
  private
26
31
 
27
32
  def quantize(src, dst)
33
+ return quantize_full_color(src, dst) if @channel_bits
34
+ return quantize_to_palette(src, dst) unless @palette.empty?
35
+
28
36
  MiniMagick.convert do |m|
29
37
  m << src
30
38
  @dither ? quantize_with_dither(m) : quantize_without_dither(m)
@@ -37,6 +45,48 @@ module TRMNLP
37
45
  end
38
46
  end
39
47
 
48
+ def quantize_full_color(src, dst)
49
+ MiniMagick.convert do |m|
50
+ m << src
51
+ m.posterize 2**@channel_bits if @channel_bits < 8
52
+ m.alpha 'off'
53
+ m.define 'png:compression-level=9'
54
+ m.strip
55
+ m << dst
56
+ end
57
+ end
58
+
59
+ # TRMNL's color steps: a brightness boost when dithering, then every pixel mapped to the panel's colors.
60
+ def quantize_to_palette(src, dst)
61
+ MiniMagick.convert do |m|
62
+ m << src
63
+ add_brightness_contrast(m) if @dither
64
+ add_palette_image(m)
65
+ m.dither(@dither ? 'FloydSteinberg' : 'None')
66
+ m.remap 'mpr:palette'
67
+ m.colorspace 'sRGB' if @dither
68
+ m.alpha 'off'
69
+ m.type 'Palette'
70
+ m.define 'png:compression-level=9'
71
+ m.strip
72
+ m << dst
73
+ end
74
+ end
75
+
76
+ def add_brightness_contrast(m)
77
+ m.colorspace 'HSV'
78
+ m.channel 'B'
79
+ m.sigmoidal_contrast '5,50%'
80
+ m << '+channel'
81
+ m.colorspace 'sRGB'
82
+ end
83
+
84
+ def add_palette_image(m)
85
+ m << '(' << '-size' << '1x1'
86
+ @palette.each { m << "xc:#{it}" }
87
+ m << '+append' << '+write' << 'mpr:palette' << '+delete' << ')'
88
+ end
89
+
40
90
  def quantize_without_dither(m)
41
91
  if @depth == 1
42
92
  m.monochrome
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'trmnl/liquid'
4
4
 
5
+ require_relative '../../random_number'
5
6
  require_relative '../check'
6
7
 
7
8
  module TRMNLP
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'securerandom'
4
+ require 'trmnl/liquid'
5
+
6
+ module TRMNLP
7
+ # TRMNL's random_number filter, merged in trmnl-liquid but not in the 0.8.2 release trmnlp needs.
8
+ module RandomNumber
9
+ def random_number(_value, min = nil, max = nil)
10
+ lower, upper = if min.nil? then [0, 100]
11
+ elsif max.nil? then [0, min.to_i]
12
+ else [min.to_i, max.to_i].minmax
13
+ end
14
+ lower + SecureRandom.random_number(upper - lower + 1)
15
+ end
16
+ end
17
+ end
18
+
19
+ TRMNL::Liquid::Filters.include(TRMNLP::RandomNumber) unless TRMNL::Liquid::Filters.method_defined?(:random_number)
@@ -13,10 +13,11 @@ module TRMNLP
13
13
  MAX_MERGE_VARIABLES_KB = 100
14
14
  AND_X_MORE = YAML.load_file(File.expand_path('../../db/data/and_x_more.yml', __dir__)).freeze
15
15
 
16
- def initialize(config:, paths:, user_data_assembler:)
16
+ def initialize(config:, paths:, user_data_assembler:, third_party_markup: nil)
17
17
  @config = config
18
18
  @paths = paths
19
19
  @user_data_assembler = user_data_assembler
20
+ @third_party_markup = third_party_markup
20
21
  end
21
22
 
22
23
  def render_full_page(view, params = {})
@@ -32,7 +33,7 @@ module TRMNLP
32
33
  # The data the last page was rendered from, for a test to read back.
33
34
  attr_reader :last_data
34
35
 
35
- def screen_classes(classes = 'screen', theme: nil)
36
+ def screen_classes(classes = 'screen', theme: nil, scale: nil, text_scale: nil)
36
37
  classes = (classes || 'screen').split # an explicit nil (omitted screen_classes param) still needs a base
37
38
  # The picker marks every render 1x, which sets the dither ratio; TRMNL's device render has no such class.
38
39
  classes.delete('screen--1x')
@@ -42,6 +43,8 @@ module TRMNLP
42
43
  classes << 'dark-mode' if classes.include?('screen--dark-mode')
43
44
  # A new device renders in the TRMNL font unless its owner picks another.
44
45
  classes << 'screen--fonts-trmnl' if classes.none? { it.start_with?('screen--fonts-') }
46
+ classes << "screen--scale-#{scale}" if FrameworkVersion::SCALES.include?(scale)
47
+ classes << "screen--text-scale-#{text_scale}" if FrameworkVersion::TEXT_SCALES.include?(text_scale)
45
48
  classes << "screen--theme-#{theme}" if FrameworkVersion::THEMES.key?(theme)
46
49
  classes.uniq.join(' ')
47
50
  end
@@ -54,7 +57,7 @@ module TRMNLP
54
57
 
55
58
  private
56
59
 
57
- attr_reader :config, :paths, :user_data_assembler
60
+ attr_reader :config, :paths, :user_data_assembler, :third_party_markup
58
61
 
59
62
  # NOTE: a missing template or Liquid syntax error is a user-facing
60
63
  # signal — the plugin author needs to *see* what broke. We surface
@@ -62,6 +65,8 @@ module TRMNLP
62
65
  # inside the preview frame so the dev server keeps serving instead
63
66
  # of 500-ing. Anything that's not a RenderError bubbles up as a bug.
64
67
  def render_liquid_template(view, device: {})
68
+ return render_third_party(view, device:) if third_party_markup
69
+
65
70
  template_path = paths.template(view)
66
71
  unless template_path.exist? || paths.shared_template.exist?
67
72
  raise RenderError, "Missing template: #{template_path.relative_path_from(paths.root_dir)}"
@@ -84,6 +89,22 @@ module TRMNLP
84
89
  raise RenderError, e.message
85
90
  end
86
91
 
92
+ # As on TRMNL: the plugin's markup renders with its merge variables only, and a view it left out says so.
93
+ def render_third_party(view, device:)
94
+ answer = third_party_markup.call(device:)
95
+ return view_not_available(view) if answer[view].to_s.empty?
96
+
97
+ @last_data = answer['merge_variables']
98
+ Liquid::Template.parse([answer['shared'], answer[view]].join, environment: liquid_environment).render(@last_data)
99
+ rescue Liquid::Error => e
100
+ raise RenderError, e.message
101
+ end
102
+
103
+ def view_not_available(view)
104
+ '<div class="layout"><div class="richtext richtext--center"><span class="content" data-content-limiter="true">' \
105
+ "#{view.tr('_', ' ').capitalize} view not available.</span></div></div>"
106
+ end
107
+
87
108
  def render_or_error(view, device:)
88
109
  render_liquid_template(view, device:)
89
110
  rescue RenderError => e
@@ -104,7 +125,8 @@ module TRMNLP
104
125
  class TemplateBinding
105
126
  def initialize(renderer, view, params)
106
127
  @view = view
107
- @screen_classes = renderer.screen_classes(params[:screen_classes], theme: params[:theme])
128
+ @screen_classes = renderer.screen_classes(params[:screen_classes], theme: params[:theme], scale: params[:scale],
129
+ text_scale: params[:text_scale])
108
130
  @framework = renderer.framework
109
131
  @theme_css_url = @framework.theme_css_url(params[:theme])
110
132
  @and_x_more = renderer.and_x_more
@@ -2,6 +2,7 @@
2
2
 
3
3
  require_relative 'screenshot'
4
4
  require_relative 'image_quantizer'
5
+ require_relative 'testing/device_models'
5
6
 
6
7
  module TRMNLP
7
8
  class ScreenGenerator
@@ -16,12 +17,16 @@ module TRMNLP
16
17
  'https://code.highcharts.com/12.3.0/modules/pattern-fill.js' => 'https://trmnl.com/js/highcharts/12.3.0/pattern-fill.js'
17
18
  }.freeze
18
19
 
20
+ FULL_COLOR_CLASS = 'screen--color-full'
21
+
19
22
  def initialize(html, opts = {})
20
23
  @input = html
21
24
  @screenshot = opts[:screenshot]
22
25
  @requested_width = opts[:width]
23
26
  @requested_height = opts[:height]
24
27
  @requested_color_depth = opts[:color_depth]
28
+ @requested_palette = opts[:palette]
29
+ @palette_id = opts[:palette_id].to_s.then { it.empty? ? nil : it }
25
30
  end
26
31
 
27
32
  # The page as it is shown: chart libraries swapped for TRMNL's copies, laid out unscaled until the capture.
@@ -30,9 +35,11 @@ module TRMNLP
30
35
  .sub('</head>', "#{Screenshot::LAYOUT_PASS_STYLE}</head>")
31
36
  end
32
37
 
38
+ # The palette is resolved before the capture, so an unknown id fails without a render.
33
39
  def process
40
+ options = quantizer_options
34
41
  output = @screenshot.call(html:, width:, height:)
35
- ImageQuantizer.new(depth: color_depth, dither: @input.include?('image-dither')).call(output.path)
42
+ ImageQuantizer.new(**options).call(output.path)
36
43
  output
37
44
  end
38
45
 
@@ -41,7 +48,42 @@ module TRMNLP
41
48
 
42
49
  private
43
50
 
51
+ def quantizer_options
52
+ options = { depth: color_depth, dither: @input.include?('image-dither') }
53
+ colors = palette
54
+ options[:palette] = colors if colors
55
+ options[:channel_bits] = channel_bits if channel_bits
56
+ options
57
+ end
58
+
59
+ # Given, or the colors of the `screen--color-*` class in the markup (nil when offline: gray steps then).
60
+ def palette
61
+ return @requested_palette if @requested_palette
62
+ return if channel_bits
63
+ return trmnl_palette['colors'] if trmnl_palette
64
+
65
+ framework_class = @input&.[](/screen--color-[\w-]+/)
66
+ Testing::DeviceModels.colors_for_class(framework_class) if framework_class
67
+ end
68
+
69
+ # TRMNL's palette the id names; an id TRMNL does not have stops the render with the ids it has.
70
+ def trmnl_palette
71
+ return unless @palette_id
72
+
73
+ @trmnl_palette ||= Testing::DeviceModels.palette_with_id(@palette_id)
74
+ end
75
+
76
+ # color-24bit (and the class alone) is lossless; color-12bit posterizes to 4 bits a channel.
77
+ def channel_bits
78
+ return 4 if @palette_id == 'color-12bit'
79
+
80
+ 8 if @palette_id == 'color-24bit' || (@palette_id.nil? && @input&.include?(FULL_COLOR_CLASS))
81
+ end
82
+
83
+ # A palette's gray count sets the depth, as the picker does; the color paths do not read it.
44
84
  def color_depth
85
+ return 1 if channel_bits
86
+ return Math.log2(trmnl_palette['grays']).ceil if trmnl_palette
45
87
  return @requested_color_depth if @requested_color_depth
46
88
  return ::Regexp.last_match(1).to_i if @input&.match(/screen--(\d+)bit/)
47
89
 
@@ -72,7 +72,8 @@ module TRMNLP
72
72
  def generator(screen)
73
73
  device = screen.device
74
74
  ScreenGenerator.new(screen.html, screenshot: self, width: device.width, height: device.height,
75
- color_depth: device.bit_depth)
75
+ color_depth: device.bit_depth, palette: device.palette_colors,
76
+ palette_id: device.palette_id)
76
77
  end
77
78
 
78
79
  def driver = @driver ||= @pool.checkout
@@ -11,7 +11,8 @@ module TRMNLP
11
11
  module DeviceModels
12
12
  API_URL = 'https://trmnl.com/api'
13
13
 
14
- Device = Data.define(:name, :width, :height, :bit_depth, :screen_classes, :image_size_limit) do
14
+ Device = Data.define(:name, :width, :height, :bit_depth, :screen_classes, :image_size_limit,
15
+ :palette_colors, :palette_id) do
15
16
  def render_params = { width:, height:, model: name, bit_depth: }
16
17
  end
17
18
 
@@ -29,7 +30,8 @@ module TRMNLP
29
30
  width, height = portrait ? model.values_at('height', 'width') : model.values_at('width', 'height')
30
31
  chosen = palette_for(model, palette)
31
32
  Device.new(name: model['name'], width:, height:, bit_depth: bit_depth(model, chosen),
32
- screen_classes: screen_classes(model, chosen, portrait), image_size_limit: model['image_size_limit'])
33
+ screen_classes: screen_classes(model, chosen, portrait), image_size_limit: model['image_size_limit'],
34
+ palette_colors: chosen&.dig('colors'), palette_id: chosen&.fetch('id'))
33
35
  end
34
36
 
35
37
  # The picker's classes: palette, device, size, then portrait.
@@ -39,6 +41,19 @@ module TRMNLP
39
41
  ('screen--portrait' if portrait)].compact.join(' ')
40
42
  end
41
43
 
44
+ # Colors of the palette with this framework class, or nil for gray palettes and when TRMNL cannot be reached.
45
+ def colors_for_class(framework_class)
46
+ palettes.find { it['framework_class'] == framework_class }&.dig('colors')
47
+ rescue TestingError
48
+ nil
49
+ end
50
+
51
+ # TRMNL's palette with this id; the error names every id when there is none.
52
+ def palette_with_id(id)
53
+ palettes.find { it['id'] == id.to_s } ||
54
+ raise(TestingError, "Unknown palette #{id.inspect}; known: #{palettes.map { it['id'] }.join(', ')}")
55
+ end
56
+
42
57
  def palette_for(model, id)
43
58
  candidates = palettes.select { model['palette_ids'].to_a.include?(it['id']) }
44
59
  return candidates.find { it['id'] == id.to_s } || raise(TestingError, unknown_palette(model, id)) if id
@@ -60,7 +75,8 @@ module TRMNLP
60
75
  device = device.transform_keys(&:to_sym)
61
76
  Device.new(name: device.fetch(:model, 'custom'), width: device.fetch(:width), height: device.fetch(:height),
62
77
  bit_depth: device.fetch(:bit_depth, 1), screen_classes: device[:screen_classes],
63
- image_size_limit: device[:image_size_limit])
78
+ image_size_limit: device[:image_size_limit], palette_colors: device[:palette_colors],
79
+ palette_id: device[:palette_id])
64
80
  end
65
81
 
66
82
  def models = @models ||= fetch('models')
@@ -70,11 +70,12 @@ module TRMNLP
70
70
  # JavaScript expression the page must reach before it is captured) and wait_for_timeout: (seconds).
71
71
  # rubocop:disable-next Metrics/ParameterLists -- one keyword per choice a render offers
72
72
  def render(view: 'full', device: 'og_plus', orientation: :landscape, palette: nil, dark_mode: false, theme: nil,
73
- now: nil, head: nil, wait_for: nil, wait_for_timeout: 5, fresh_browser: false,
74
- asset_overrides: {}, **)
73
+ scale: nil, text_scale: nil, now: nil, head: nil, wait_for: nil, wait_for_timeout: 5,
74
+ fresh_browser: false, asset_overrides: {}, **)
75
75
  device = DeviceModels.find(device, orientation:, palette:)
76
76
  classes = [device.screen_classes, ('screen--dark-mode' if dark_mode)].compact.join(' ')
77
- result = run(now, **).render(view:, device: device.render_params, screen_classes: classes, theme:)
77
+ result = run(now, **).render(view:, device: device.render_params, screen_classes: classes, theme:, scale:,
78
+ text_scale:)
78
79
  html = with_problems_trap(with_head(with_page_clock(result.html, now), head))
79
80
  browser = fresh_browser ? @browser.fresh : @browser
80
81
  Report.current&.record_run(result)
@@ -30,14 +30,14 @@ module TRMNLP
30
30
  @dir = "#{dir}#{ENV.fetch('TEST_ENV_NUMBER', '')}" # parallel_tests: report, report2, report3...
31
31
  @examples = {}
32
32
  @images = 0
33
- @full_landscape_images = {}
33
+ @landscape_images = {}
34
34
  end
35
35
 
36
36
  def record_screen(screen)
37
37
  return unless entry
38
38
 
39
39
  image = copy_image(screen.png_path)
40
- remember_full_landscape(screen, image)
40
+ remember_landscape(screen, image)
41
41
  entry[:screens].push(
42
42
  label: "#{screen.device.name} · #{screen.view}", width: screen.device.width, height: screen.device.height,
43
43
  image:, outlines: screen.evaluate(OUTLINES_SCRIPT), problems: screen.problems,
@@ -84,21 +84,30 @@ module TRMNLP
84
84
  name
85
85
  end
86
86
 
87
- def remember_full_landscape(screen, image)
88
- return unless screen.view == 'full' && screen.device.width > screen.device.height
87
+ def remember_landscape(screen, image)
88
+ return unless screen.device.width > screen.device.height
89
89
 
90
- @full_landscape_images[screen.device.name] ||= image
90
+ @landscape_images[[screen.view, screen.device.name]] ||= image
91
91
  end
92
92
 
93
- def og_vs_x = (OG_VS_X if @full_landscape_images.values_at('og_plus', 'v2').all?)
93
+ def og_vs_x = (OG_VS_X if og_and_x_images('full').all?)
94
+
95
+ def og_and_x_images(view) = @landscape_images.values_at([view, 'og_plus'], [view, 'v2'])
96
+
97
+ def og_vs_x_name(view) = view == 'full' ? OG_VS_X : "og-vs-x-#{view}.png"
94
98
 
95
- # Both at the OG's height, so content that fills the OG but is small on the X shows at a glance.
96
99
  def write_og_vs_x
97
- return unless og_vs_x
100
+ @landscape_images.keys.map(&:first).uniq.each do |view|
101
+ images = og_and_x_images(view)
102
+ write_side_by_side(images, og_vs_x_name(view)) if images.all?
103
+ end
104
+ end
98
105
 
106
+ # Both at the OG's height, so content that fills the OG but is small on the X shows at a glance.
107
+ def write_side_by_side(images, name)
99
108
  MiniMagick.convert do |convert|
100
- @full_landscape_images.values_at('og_plus', 'v2').each { convert << File.join(@dir, it) }
101
- convert << '-resize' << 'x480' << '+append' << '+repage' << File.join(@dir, OG_VS_X)
109
+ images.each { convert << File.join(@dir, it) }
110
+ convert << '-resize' << 'x480' << '+append' << '+repage' << File.join(@dir, name)
102
111
  end
103
112
  end
104
113
 
@@ -47,9 +47,10 @@ module TRMNLP
47
47
  call { |context| { data: context.user_data_assembler.call(device:) } }
48
48
  end
49
49
 
50
- def render(view:, device: {}, screen_classes: nil, theme: nil)
50
+ # screen: what the page's screen looks like: screen_classes:, theme:, scale: and text_scale:.
51
+ def render(view:, device: {}, **screen)
51
52
  call do |context|
52
- html = context.renderer.render_full_page(view, device.merge(screen_classes:, theme:))
53
+ html = context.renderer.render_full_page(view, device.merge(screen))
53
54
  { html:, data: context.renderer.last_data }
54
55
  end
55
56
  end
@@ -23,6 +23,16 @@ module TRMNLP
23
23
  const clips = (el) => getComputedStyle(el).overflow !== 'visible';
24
24
  const truncatesOnPurpose = (style) => style.textOverflow === 'ellipsis' || style.webkitLineClamp !== 'none';
25
25
  const drawn = (rect) => rect.width > 0 || rect.height > 0;
26
+ // The usual visually hidden pattern (Tailwind's sr-only, Bootstrap's visually-hidden): a clip that leaves
27
+ // nothing of the box, so the text is there for screen readers and draws nothing.
28
+ const clipsEverything = (style) => style.clipPath === 'inset(50%)' ||
29
+ (['absolute', 'fixed'].includes(style.position) && style.clip === 'rect(0px, 0px, 0px, 0px)');
30
+ const visuallyHidden = (el) => {
31
+ for (let node = el; node; node = node.parentElement) {
32
+ if (clipsEverything(getComputedStyle(node))) return true;
33
+ }
34
+ return false;
35
+ };
26
36
  const insideTruncation = (el) => {
27
37
  for (let parent = el.parentElement; parent; parent = parent.parentElement) {
28
38
  if (truncatesOnPurpose(getComputedStyle(parent))) return true;
@@ -80,7 +90,7 @@ module TRMNLP
80
90
  };
81
91
  return [...document.querySelectorAll('.view *')].filter((el) => {
82
92
  const box = el.getBoundingClientRect();
83
- if (!drawn(box) || insideTruncation(el) || (except && el.closest(except))) return false;
93
+ if (!drawn(box) || insideTruncation(el) || visuallyHidden(el) || (except && el.closest(except))) return false;
84
94
  const outside = box.right > screen.right + 1 || box.bottom > screen.bottom + 1 || box.left < -1 || box.top < -1;
85
95
  const style = getComputedStyle(el);
86
96
  const overflows = el.scrollWidth > el.clientWidth + 1 || el.scrollHeight > el.clientHeight + 1;
@@ -0,0 +1,92 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+
5
+ require_relative 'errors'
6
+ require_relative 'form_body'
7
+ require_relative 'outbound_request'
8
+
9
+ module TRMNLP
10
+ # A third-party plugin's markup as TRMNL fetches it: the user's uuid and the trmnl variables posted to the
11
+ # plugin's plugin_markup_url, answered with each view's markup and the merge variables they render with.
12
+ # Like one TRMNL refresh, one answer per device draws every view until #refresh.
13
+ class ThirdPartyMarkup
14
+ STAND_IN_USER_UUID = '00000000-0000-4000-8000-000000000000'
15
+ MARKUP_KEYS = { 'full' => 'markup', 'half_horizontal' => 'markup_half_horizontal',
16
+ 'half_vertical' => 'markup_half_vertical', 'quadrant' => 'markup_quadrant',
17
+ 'shared' => 'shared' }.freeze
18
+
19
+ def initialize(settings:, trmnl_variables:, outbound_request: OutboundRequest.new)
20
+ @settings = settings
21
+ @trmnl_variables = trmnl_variables
22
+ @outbound_request = outbound_request
23
+ @answers = {}
24
+ end
25
+
26
+ def call(device:) = @answers[device] ||= markups(fetch(device))
27
+
28
+ def refresh = @answers.clear
29
+
30
+ # The data trmnlp serve shows: a page load is a new refresh, so the plugin is asked again.
31
+ def preview_merge_variables(device:)
32
+ refresh
33
+ call(device:)['merge_variables']
34
+ rescue RenderError => e
35
+ { 'error' => e.message }
36
+ end
37
+
38
+ private
39
+
40
+ attr_reader :settings, :trmnl_variables, :outbound_request
41
+
42
+ def fetch(device)
43
+ user_uuid = settings['user_uuid'] || STAND_IN_USER_UUID
44
+ body = FormBody.encode({ 'user_uuid' => user_uuid }.merge(trmnl_variables.call(device)))
45
+ response, failure = outbound_request.call('POST', url, headers:, body:)
46
+ unavailable!(failure) if failure
47
+
48
+ parsed(response)
49
+ end
50
+
51
+ def url
52
+ url = settings['plugin_markup_url'].to_s.strip
53
+ return url unless url.empty?
54
+
55
+ unavailable!('plugin_markup_url in .trmnlp.yml is empty, so an environment variable it reads is probably not set')
56
+ end
57
+
58
+ def headers
59
+ token = settings['access_token'].to_s
60
+ authorization = token.empty? ? {} : { 'Authorization' => "Bearer #{token}" }
61
+ { 'Content-Type' => 'application/x-www-form-urlencoded' }.merge(authorization)
62
+ end
63
+
64
+ def parsed(response)
65
+ body = response.body.to_s.delete_prefix("\uFEFF")
66
+ unavailable!("the host replied #{response.status}: #{body[0, 200]}") unless (200..299).cover?(response.status)
67
+ unavailable!("the host replied #{response.status} with an empty body") if body.strip.empty?
68
+
69
+ answer = JSON.parse(body)
70
+ answer.is_a?(Hash) ? answer : raise(JSON::ParserError)
71
+ rescue JSON::ParserError
72
+ unavailable!("the host replied #{response.status} with no JSON object: #{body[0, 200]}")
73
+ end
74
+
75
+ def unavailable!(reason) = raise(RenderError, "Plugin markup unavailable: #{reason}")
76
+
77
+ def markups(answer)
78
+ merge_variables = answer['merge_variables'] || {}
79
+ unusable!('merge_variables must be a JSON object', merge_variables) unless merge_variables.is_a?(Hash)
80
+
81
+ MARKUP_KEYS.to_h do |name, key|
82
+ markup = answer[key]
83
+ unusable!("#{key} must be a string", markup) unless markup.nil? || markup.is_a?(String)
84
+ [name, markup]
85
+ end.merge('merge_variables' => merge_variables)
86
+ end
87
+
88
+ def unusable!(problem, value)
89
+ raise(RenderError, "Plugin markup unusable: #{problem}, not #{JSON.generate(value)}")
90
+ end
91
+ end
92
+ end
@@ -40,8 +40,8 @@ module TRMNLP
40
40
  transform_pipeline.call(transform_input(assemble(base_trmnl_data(device: {}), merge_variables)))
41
41
  end
42
42
 
43
- # What a polling url, its headers and its body render with on TRMNL.
44
- def polling_variables = assemble(base_trmnl_data(device: {}), {}).slice('trmnl')
43
+ # What a polling url, its headers and its body render with on TRMNL, and what a third-party plugin is posted.
44
+ def trmnl_variables(device: {}) = assemble(base_trmnl_data(device:), {}).slice('trmnl')
45
45
 
46
46
  def device_from_params(params)
47
47
  { 'width' => params[:width]&.to_i, 'height' => params[:height]&.to_i, 'model' => params[:model],
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TRMNLP
4
- VERSION = '0.33.1'
4
+ VERSION = '0.34.1'
5
5
  end
data/lib/trmnlp.rb CHANGED
@@ -4,6 +4,7 @@ module TRMNLP; end
4
4
  require 'oj'
5
5
  require 'trmnl/liquid'
6
6
  require_relative 'trmnlp/qr_code'
7
+ require_relative 'trmnlp/random_number'
7
8
  Oj.mimic_JSON
8
9
  require_relative 'trmnlp/rails_helpers'
9
10
  require_relative 'trmnlp/errors'
data/web/public/index.js CHANGED
@@ -53,6 +53,8 @@ trmnlp.fetchPreview = function (pickerState) {
53
53
  const encodedScreenClasses = encodeURIComponent(screenClasses);
54
54
  let src = `/render/${trmnlp.view}.${trmnlp.formatSelect.value}?screen_classes=${encodedScreenClasses}`;
55
55
  if (trmnlp.themeSelect.value) src += `&theme=${encodeURIComponent(trmnlp.themeSelect.value)}`;
56
+ if (trmnlp.scaleSelect.value) src += `&scale=${encodeURIComponent(trmnlp.scaleSelect.value)}`;
57
+ if (trmnlp.textScaleSelect.value) src += `&text_scale=${encodeURIComponent(trmnlp.textScaleSelect.value)}`;
56
58
 
57
59
  // Pass the device for both HTML and PNG renders so trmnl.device.{width,height,model,bit_depth}
58
60
  // in the Liquid context tracks the picker model selection.
@@ -65,6 +67,7 @@ trmnlp.fetchPreview = function (pickerState) {
65
67
  const grays = state.palette.grays || 2;
66
68
  const colorDepth = Math.ceil(Math.log2(grays));
67
69
  src += `&color_depth=${colorDepth}`;
70
+ if (state.palette.id) src += `&palette=${encodeURIComponent(state.palette.id)}`;
68
71
  }
69
72
 
70
73
  trmnlp.spinner.style.display = "inline-block";
@@ -287,6 +290,8 @@ document.addEventListener("DOMContentLoaded", async function () {
287
290
  trmnlp.iframe = document.querySelector("iframe");
288
291
  trmnlp.formatSelect = document.querySelector(".select-format");
289
292
  trmnlp.themeSelect = document.querySelector("[data-theme-select]");
293
+ trmnlp.scaleSelect = document.querySelector("[data-scale-select]");
294
+ trmnlp.textScaleSelect = document.querySelector("[data-text-scale-select]");
290
295
  trmnlp.userData = document.getElementById("user-data");
291
296
  trmnlp.spinner = document.querySelector(".spinner");
292
297
  trmnlp.isLiveReloadEnabled =
@@ -305,11 +310,14 @@ document.addEventListener("DOMContentLoaded", async function () {
305
310
  trmnlp.fetchPreview();
306
311
  });
307
312
 
308
- trmnlp.themeSelect.value = localStorage.getItem("trmnlp-theme") || "";
309
- trmnlp.themeSelect.addEventListener("change", () => {
310
- localStorage.setItem("trmnlp-theme", trmnlp.themeSelect.value);
311
- trmnlp.fetchPreview();
312
- });
313
+ for (const [select, key] of [[trmnlp.themeSelect, "trmnlp-theme"], [trmnlp.scaleSelect, "trmnlp-scale"],
314
+ [trmnlp.textScaleSelect, "trmnlp-text-scale"]]) {
315
+ select.value = localStorage.getItem(key) || "";
316
+ select.addEventListener("change", () => {
317
+ localStorage.setItem(key, select.value);
318
+ trmnlp.fetchPreview();
319
+ });
320
+ }
313
321
 
314
322
  trmnlp.iframe.addEventListener("load", () => {
315
323
  trmnlp.spinner.style.display = "none";
data/web/views/index.erb CHANGED
@@ -53,6 +53,20 @@
53
53
  <% end %>
54
54
  </select>
55
55
 
56
+ <select data-scale-select>
57
+ <option value="">Regular scale</option>
58
+ <% (TRMNLP::FrameworkVersion::SCALES).each do |scale| %>
59
+ <option value="<%= scale %>"><%= scale.capitalize %> scale</option>
60
+ <% end %>
61
+ </select>
62
+
63
+ <select data-text-scale-select>
64
+ <option value="">Regular text</option>
65
+ <% (TRMNLP::FrameworkVersion::TEXT_SCALES).each do |text_scale| %>
66
+ <option value="<%= text_scale %>"><%= text_scale.capitalize %> text</option>
67
+ <% end %>
68
+ </select>
69
+
56
70
  <!-- Optional: Reset button -->
57
71
  <button class="btn" type="button" data-reset-button>Reset</button>
58
72
  </form>
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.33.1
4
+ version: 0.34.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rockwell Schrock
@@ -417,6 +417,7 @@ files:
417
417
  - lib/trmnlp/context.rb
418
418
  - lib/trmnlp/errors.rb
419
419
  - lib/trmnlp/firefox_driver.rb
420
+ - lib/trmnlp/form_body.rb
420
421
  - lib/trmnlp/form_field.rb
421
422
  - lib/trmnlp/framework_version.rb
422
423
  - lib/trmnlp/image_quantizer.rb
@@ -472,6 +473,7 @@ files:
472
473
  - lib/trmnlp/poller.rb
473
474
  - lib/trmnlp/qr_code.rb
474
475
  - lib/trmnlp/rails_helpers.rb
476
+ - lib/trmnlp/random_number.rb
475
477
  - lib/trmnlp/renderer.rb
476
478
  - lib/trmnlp/reporter.rb
477
479
  - lib/trmnlp/screen.rb
@@ -500,6 +502,7 @@ files:
500
502
  - lib/trmnlp/testing/screen.rb
501
503
  - lib/trmnlp/testing/snapshot.rb
502
504
  - lib/trmnlp/testing/text_ink.rb
505
+ - lib/trmnlp/third_party_markup.rb
503
506
  - lib/trmnlp/transform_backend/http.rb
504
507
  - lib/trmnlp/transform_backend/python.rb
505
508
  - lib/trmnlp/transform_backend/subprocess.rb