studio-engine 0.146.0 → 0.147.0
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/CHANGELOG.md +6 -0
- data/app/javascript/studio/controllers/svg_png_controller.js +74 -0
- data/app/javascript/studio/stimulus.js +2 -0
- data/app/javascript/studio/svg_png.js +63 -0
- data/app/views/studio/marketing_kit/_kit.html.erb +8 -1
- data/docs/SITE_FOOTER.md +11 -4
- data/lib/studio/marketing_kit.rb +13 -2
- data/lib/studio/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e7a399317b6d569ac4874207e31449b5e0eaf12ae2f9882f2fc8a371386e4487
|
|
4
|
+
data.tar.gz: 0d25c5e228da39e8603f483aca9a22f89c692b74ce0e5def44b5d2d725232057
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2f3d94e4ed5eb4141b664ab34d5e6de2603d980ba5d9a2ab12d50c7e7c9239ff6ada22e311625132c2bde87988c76eff9e859a0fd67c109cae932752ac2edd42
|
|
7
|
+
data.tar.gz: 9bba21c6f6b82bd7a6408bd002f9388ce94078a82922d09ef8e892fe65e5214b9d115ce7a123e4b8eb8183b4f0159cf5a7d4a9e36791948775467d32dcc0dde1
|
data/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,12 @@ The format is [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). This pro
|
|
|
4
4
|
|
|
5
5
|
## Unreleased
|
|
6
6
|
|
|
7
|
+
## 0.147.0 — 2026-12-05
|
|
8
|
+
|
|
9
|
+
### Changed
|
|
10
|
+
|
|
11
|
+
- **Every marketing-kit logo download saves a PNG.** A logo whose only file is an SVG used to download the SVG; the new lazy `svg-png` controller now draws it to a transparent PNG in the browser on the click, at the logo's own shape with its longer side 2000 px. A logo with a PNG file still links that file, and a failed draw saves the SVG. See `docs/SITE_FOOTER.md`, "The marketing kit".
|
|
12
|
+
|
|
7
13
|
## 0.146.0 — 2026-11-28
|
|
8
14
|
|
|
9
15
|
### Added
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// svg-png: a marketing-kit download whose only file is an SVG saves a PNG
|
|
2
|
+
// (studio/marketing_kit/_kit, Studio::MarketingKit#tile). It sits on the link:
|
|
3
|
+
//
|
|
4
|
+
// <a href="/brand/navbar-light.svg" download data-studio-controller="svg-png"
|
|
5
|
+
// data-svg-png-name-value="navbar-light.png"
|
|
6
|
+
// data-studio-action="click->svg-png#download">Download Light</a>
|
|
7
|
+
//
|
|
8
|
+
// The click fetches the SVG, draws it on a canvas at its own shape (the longer
|
|
9
|
+
// side LONGEST px, transparent), and saves the PNG under `name`. When any step
|
|
10
|
+
// fails (an SVG on another origin the fetch may not read, say) it saves the SVG
|
|
11
|
+
// the href names, as the link does with no script. A modifier click is the
|
|
12
|
+
// browser's.
|
|
13
|
+
import { Controller } from "@hotwired/stimulus"
|
|
14
|
+
import { svgBox, pngSize, sizedSvg, plainClick } from "studio/svg_png"
|
|
15
|
+
|
|
16
|
+
function save(href, name) {
|
|
17
|
+
const link = document.createElement("a")
|
|
18
|
+
link.href = href
|
|
19
|
+
link.download = name || ""
|
|
20
|
+
document.body.appendChild(link)
|
|
21
|
+
link.click()
|
|
22
|
+
link.remove()
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async function drawPng(href) {
|
|
26
|
+
const response = await fetch(href, { credentials: "same-origin" })
|
|
27
|
+
if (!response.ok) throw new Error(`${href}: ${response.status}`)
|
|
28
|
+
|
|
29
|
+
const text = await response.text()
|
|
30
|
+
const box = svgBox(text)
|
|
31
|
+
if (!box) throw new Error(`${href}: no viewBox or size`)
|
|
32
|
+
|
|
33
|
+
const size = pngSize(box)
|
|
34
|
+
const url = URL.createObjectURL(new Blob([sizedSvg(text, box, size)], { type: "image/svg+xml" }))
|
|
35
|
+
try {
|
|
36
|
+
const image = new Image()
|
|
37
|
+
image.src = url
|
|
38
|
+
await image.decode()
|
|
39
|
+
|
|
40
|
+
const canvas = document.createElement("canvas")
|
|
41
|
+
canvas.width = size.width
|
|
42
|
+
canvas.height = size.height
|
|
43
|
+
canvas.getContext("2d").drawImage(image, 0, 0, size.width, size.height)
|
|
44
|
+
const png = await new Promise((resolve) => canvas.toBlob(resolve, "image/png"))
|
|
45
|
+
if (!png) throw new Error(`${href}: the canvas drew nothing`)
|
|
46
|
+
return png
|
|
47
|
+
} finally {
|
|
48
|
+
URL.revokeObjectURL(url)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export default class extends Controller {
|
|
53
|
+
static values = { name: String }
|
|
54
|
+
|
|
55
|
+
async download(event) {
|
|
56
|
+
if (!plainClick(event)) return
|
|
57
|
+
|
|
58
|
+
event.preventDefault()
|
|
59
|
+
if (this.busy) return
|
|
60
|
+
|
|
61
|
+
this.busy = true
|
|
62
|
+
const href = this.element.href
|
|
63
|
+
try {
|
|
64
|
+
const url = URL.createObjectURL(await drawPng(href))
|
|
65
|
+
save(url, this.nameValue)
|
|
66
|
+
setTimeout(() => URL.revokeObjectURL(url), 1000)
|
|
67
|
+
} catch (error) {
|
|
68
|
+
console.warn("svg-png: saving the SVG instead", error)
|
|
69
|
+
save(href, "")
|
|
70
|
+
} finally {
|
|
71
|
+
this.busy = false
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -68,6 +68,7 @@ export const schema = {
|
|
|
68
68
|
// So is the talk-to-agent modal: its links are real links, and with its
|
|
69
69
|
// controller failed each one opens its href (data-studio-controller-failed="talk-to-agent").
|
|
70
70
|
// So is copy-text: a colour whose controller failed still shows its hex to select.
|
|
71
|
+
// So is svg-png: a download whose controller failed saves the SVG its href names.
|
|
71
72
|
// So is the page header: its tabs are links, and a row whose controller failed
|
|
72
73
|
// keeps its bar at all times (data-studio-controller-failed="page-header").
|
|
73
74
|
// So is the carousel: its track is a native scroll row, and one whose controller
|
|
@@ -92,6 +93,7 @@ export const LAZY = {
|
|
|
92
93
|
"microphone-chip": () => import("studio/controllers/microphone_chip_controller"),
|
|
93
94
|
"voice-recorder": () => import("studio/controllers/voice_recorder_controller"),
|
|
94
95
|
"copy-text": () => import("studio/controllers/copy_text_controller"),
|
|
96
|
+
"svg-png": () => import("studio/controllers/svg_png_controller"),
|
|
95
97
|
"page-header": () => import("studio/controllers/page_header_controller"),
|
|
96
98
|
"carousel": () => import("studio/controllers/carousel_controller"),
|
|
97
99
|
"carousel-captions": () => import("studio/controllers/carousel_captions_controller"),
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// svg_png: the pure half of the svg-png controller (studio/marketing_kit/_kit).
|
|
2
|
+
// A logo whose only file is an SVG is drawn to a PNG in the browser, so every
|
|
3
|
+
// marketing-kit download is a PNG (Alex McRitchie 2026-12-05: "PNGs are more
|
|
4
|
+
// useful"). It imports nothing, so a test loads it from source.
|
|
5
|
+
|
|
6
|
+
// The PNG's longer side, in pixels: the hub's kit PNGs are 2000 px wide
|
|
7
|
+
// (mcritchie-studio lib/marketing_kit/logo_pngs.rb).
|
|
8
|
+
export const LONGEST = 2000
|
|
9
|
+
|
|
10
|
+
const ROOT = /<svg\b[^>]*>/i
|
|
11
|
+
|
|
12
|
+
function attribute(tag, name) {
|
|
13
|
+
const match = tag.match(new RegExp(`\\s${name}\\s*=\\s*(["'])(.*?)\\1`, "i"))
|
|
14
|
+
return match ? match[2] : null
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function length(value) {
|
|
18
|
+
const number = parseFloat(value)
|
|
19
|
+
return value && !/%\s*$/.test(value) && number > 0 ? number : null
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// The SVG's own shape, { width, height }: its viewBox, else its width and
|
|
23
|
+
// height. Null when it has neither, as a percentage size is not a shape.
|
|
24
|
+
export function svgBox(text) {
|
|
25
|
+
const tag = String(text).match(ROOT)?.[0]
|
|
26
|
+
if (!tag) return null
|
|
27
|
+
|
|
28
|
+
const view = (attribute(tag, "viewBox") || "").trim().split(/[\s,]+/).map(Number)
|
|
29
|
+
if (view.length === 4 && view[2] > 0 && view[3] > 0) return { width: view[2], height: view[3] }
|
|
30
|
+
|
|
31
|
+
const width = length(attribute(tag, "width"))
|
|
32
|
+
const height = length(attribute(tag, "height"))
|
|
33
|
+
return width && height ? { width, height } : null
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// The PNG's size: the SVG's shape, its longer side `longest` px. A wide logo
|
|
37
|
+
// stays wide, never padded square.
|
|
38
|
+
export function pngSize(box, longest = LONGEST) {
|
|
39
|
+
const scale = longest / Math.max(box.width, box.height)
|
|
40
|
+
return {
|
|
41
|
+
width: Math.max(1, Math.round(box.width * scale)),
|
|
42
|
+
height: Math.max(1, Math.round(box.height * scale))
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// The SVG drawn at `size`: its root's width and height set to the PNG's pixels,
|
|
47
|
+
// and a viewBox kept (added from the shape when it had none), so the browser
|
|
48
|
+
// draws the vector at that size rather than scaling up a small bitmap.
|
|
49
|
+
export function sizedSvg(text, box, size) {
|
|
50
|
+
return String(text).replace(ROOT, (tag) => {
|
|
51
|
+
let out = tag.replace(/\s(width|height)\s*=\s*(["']).*?\2/gi, "")
|
|
52
|
+
if (!attribute(tag, "viewBox")) out = out.replace(/^<svg\b/i, `<svg viewBox="0 0 ${box.width} ${box.height}"`)
|
|
53
|
+
return out.replace(/^<svg\b/i, `<svg width="${size.width}" height="${size.height}"`)
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// True for a plain primary click: the controller draws the PNG. A modifier or
|
|
58
|
+
// middle click (open in a new tab, save the link) is the browser's, as the
|
|
59
|
+
// booking link's is (studio/booking.js).
|
|
60
|
+
export function plainClick(event) {
|
|
61
|
+
return !(event.defaultPrevented || event.button !== 0 ||
|
|
62
|
+
event.metaKey || event.ctrlKey || event.shiftKey || event.altKey)
|
|
63
|
+
}
|
|
@@ -31,7 +31,14 @@
|
|
|
31
31
|
<% end %>
|
|
32
32
|
<div class="mkit-downloads">
|
|
33
33
|
<% logo[:tones].each do |tone| %>
|
|
34
|
-
|
|
34
|
+
<% if tone[:png_name] %>
|
|
35
|
+
<%# Only an SVG is there: svg-png draws the PNG on the click. %>
|
|
36
|
+
<a href="<%= tone[:href] %>" download class="mkit-download"
|
|
37
|
+
data-studio-controller="svg-png" data-svg-png-name-value="<%= tone[:png_name] %>"
|
|
38
|
+
data-studio-action="click->svg-png#download"><%= tone[:label] %></a>
|
|
39
|
+
<% else %>
|
|
40
|
+
<a href="<%= tone[:href] %>" download class="mkit-download"><%= tone[:label] %></a>
|
|
41
|
+
<% end %>
|
|
35
42
|
<% end %>
|
|
36
43
|
</div>
|
|
37
44
|
</div>
|
data/docs/SITE_FOOTER.md
CHANGED
|
@@ -361,9 +361,13 @@ overrides the site name in the page's first line.
|
|
|
361
361
|
| `tagline` | None |
|
|
362
362
|
|
|
363
363
|
- **`light` is the artwork for a light background**, and `dark` for a dark one.
|
|
364
|
-
- **A logo offers "Download Light" and "Download Dark"
|
|
365
|
-
|
|
366
|
-
|
|
364
|
+
- **A logo offers "Download Light" and "Download Dark", and each saves a PNG.** A tone
|
|
365
|
+
with a PNG file links it; make that PNG transparent. A tone with only an SVG is drawn
|
|
366
|
+
to a PNG in the browser on the click, by the lazy `svg-png` controller
|
|
367
|
+
(`studio/controllers/svg_png_controller`): the logo's own shape, its longer side
|
|
368
|
+
2000 px, on a transparent ground. If the draw fails (or the controller does not
|
|
369
|
+
load), the link saves the SVG it names. The tile shows the SVG when there is one.
|
|
370
|
+
Only PNG and SVG are read.
|
|
367
371
|
- **A file that is not there is not an error.** Each file is looked for before it is
|
|
368
372
|
linked, in `public/` and, for a name with no leading `/`, in the asset pipeline. A
|
|
369
373
|
tone with no file has no tile and no link. A logo with no file has no card. An
|
|
@@ -636,8 +640,11 @@ link. Those rules are more specific than the engine's and still apply.
|
|
|
636
640
|
- `test/integration/marketing_kit_test.rb`: the page through a real signed-out
|
|
637
641
|
request in a host that gates every controller, the footer link and its no-double
|
|
638
642
|
rule, and a host route of the same path winning from either side.
|
|
643
|
+
- `test/javascript/svg_png.test.mjs`: the shape an SVG-only logo's PNG is drawn
|
|
644
|
+
at, the sized SVG, and that only a plain click is drawn.
|
|
639
645
|
- `e2e/marketing_kit.spec.js`: the hex on the clipboard, the confirmation, the
|
|
640
|
-
refused copy, and the downloads, in a browser
|
|
646
|
+
refused copy, and the downloads, in a browser: an SVG-only logo saves a
|
|
647
|
+
transparent PNG at its own shape, and a failed draw saves the SVG.
|
|
641
648
|
|
|
642
649
|
`/admin/style` shows the footer under Tricks, with this app's own facts, or a
|
|
643
650
|
sample when it has declared none (the default footer or `false`).
|
data/lib/studio/marketing_kit.rb
CHANGED
|
@@ -93,18 +93,29 @@ module Studio
|
|
|
93
93
|
end.uniq { |card| card[:tones].map { |tone| tone[:href] } }
|
|
94
94
|
end
|
|
95
95
|
|
|
96
|
-
# A download
|
|
97
|
-
# SVG when there is one, since it stays sharp at any size.
|
|
96
|
+
# A download links the PNG when there is one, else the SVG. The tile shows
|
|
97
|
+
# the SVG when there is one, since it stays sharp at any size.
|
|
98
|
+
#
|
|
99
|
+
# A download always saves a PNG (Alex McRitchie 2026-12-05: "PNGs are more
|
|
100
|
+
# useful"). A tone with only an SVG names the PNG to draw (`png_name`), and
|
|
101
|
+
# the lazy svg-png controller draws it in the browser on the click. The href
|
|
102
|
+
# stays the SVG, so a page whose controller failed still downloads a file.
|
|
98
103
|
def tile(title, tone, ground, files, locate)
|
|
99
104
|
found = formats(files).transform_values { |file| locate.call(file) }.compact
|
|
100
105
|
href = found[:png] || found[:svg]
|
|
101
106
|
return nil if href.nil?
|
|
102
107
|
|
|
103
108
|
{ tone: tone, ground: ground, label: DOWNLOAD_LABELS.fetch(tone), href: href,
|
|
109
|
+
png_name: (png_name(href) if found[:png].nil?),
|
|
104
110
|
src: tile_src(found[:svg] || found[:png]),
|
|
105
111
|
alt: [SiteFooter.text(title), "for a #{tone} background"].compact.join(", ") }
|
|
106
112
|
end
|
|
107
113
|
|
|
114
|
+
# "/brand/navbar-light.svg?v=2" => "navbar-light.png"
|
|
115
|
+
def png_name(url)
|
|
116
|
+
"#{File.basename(url.split(/[?#]/).first.to_s, '.*')}.png"
|
|
117
|
+
end
|
|
118
|
+
|
|
108
119
|
# { png:, svg: }, or one path whose extension says which it is.
|
|
109
120
|
def formats(files)
|
|
110
121
|
return SiteFooter.symbolize(files).slice(*FORMATS) if files.is_a?(Hash)
|
data/lib/studio/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: studio-engine
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.147.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Alex McRitchie
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-12-06 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rails
|
|
@@ -554,6 +554,7 @@ files:
|
|
|
554
554
|
- app/javascript/studio/controllers/style_modals_controller.js
|
|
555
555
|
- app/javascript/studio/controllers/style_section_nav_controller.js
|
|
556
556
|
- app/javascript/studio/controllers/survey_controller.js
|
|
557
|
+
- app/javascript/studio/controllers/svg_png_controller.js
|
|
557
558
|
- app/javascript/studio/controllers/talk_to_agent_controller.js
|
|
558
559
|
- app/javascript/studio/controllers/toast_controller.js
|
|
559
560
|
- app/javascript/studio/controllers/voice_profile_controller.js
|
|
@@ -600,6 +601,7 @@ files:
|
|
|
600
601
|
- app/javascript/studio/style_modals.js
|
|
601
602
|
- app/javascript/studio/style_section_nav.js
|
|
602
603
|
- app/javascript/studio/survey.js
|
|
604
|
+
- app/javascript/studio/svg_png.js
|
|
603
605
|
- app/javascript/studio/talk_to_agent.js
|
|
604
606
|
- app/javascript/studio/theme_editor.js
|
|
605
607
|
- app/javascript/studio/toast.js
|