Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ The hero is the first entry of a store's list in `store-assets/manifest.json`, w
- `file` is under `store-assets/<store>/`, like every other entry, and must contain `{locale}`: each locale gets its own image.
- `source` is the raw capture under `store-assets/`, with the capture helper's `<name>.json` sidecar beside it. The hero shows the whole window the sidecar records, never part of it. `hero.crop` (`[x, y, width, height]` in capture pixels) may widen that region, and is refused if it would cut the window. The one exception is a tall flyout in the `split` layout: with `"fade": "bottom"` beside it, `hero.crop` may cut the window's bottom edge (its top and sides stay whole), and the hero fades the UI out toward the cut so it clearly continues. Every other cut is still refused, and `fade` without a crop that really cuts the bottom fails. A capture taken at 200% display scale (sidecar `"scale": 200`) is drawn at its logical size and looks sharper; a plain run says when a 100% capture is enlarged enough to look soft. `split` needs a capture; for `brand-card` it is optional.
- `hero.icon` is repo-relative, a `.png` or `.svg`. `primary` and `accent` are `#RRGGBB`: the panel or gradient is drawn from `primary`, the accent bar runs from `primary` to `accent`.
- `hero.textFreeFile` (split layout only) also draws one text-free image: the panel's brand gradient across the whole canvas with the same window, whole and enlarged, centred on it, and no icon, name, headline or subline. It is for a page, such as a product page on a website, that sets the name and headline in its own text above the image. Without the panel the window has the whole canvas, so a wide window is drawn larger than in the hero. The path is under `store-assets/<store>/` like `file`, has no `{locale}` (the image has no text, so one serves every locale), and is best kept out of `screenshots/` so it is never uploaded as a listing screenshot, for example `"textFreeFile": "text-free/00-hero-dark.png"`. It is the manifest's `size`, and `--check` covers it like the heroes.
- The output size is the manifest's `size` (1366 x 768 by default, up to 3840 x 2160, about 16:9), so the hero matches the listing's other screenshots. The PNG is 8-bit RGB without alpha, with unfiltered rows, the format winui-app-kit's screenshot renderer writes.

The text comes from the same store's `listings.json`. Every locale with its own record needs `heroHeadline`, and the command names every locale that lacks one before drawing anything. `heroSubline` is required for `brand-card`, and for `split` is set in every locale or none. A `copyFrom` locale reuses its target's image and needs neither. The app name is the locale's `title`. A `\n` in either field forces a line break; otherwise lines are broken at word boundaries (Japanese and Chinese words too) and balanced. The headline starts large and shrinks in steps until it fits above the bottom third of the image, which Microsoft reserves for overlays; if it still does not fit at the smallest size that reads on a 320 x 180 search card, the command fails and names the locale, so shorten it there.
Expand All @@ -367,7 +368,7 @@ Rendering uses `@resvg/resvg-js`, found the same way as for [icons](#icons), inc

The renderer and fonts are pinned so that `--check` redraws the same pixels anywhere, but that is so far shown only on Linux x64 (WSL and CI); `check:icons` has relied on the same property for shapes, and a hero adds text, blur and image scaling. Japanese and Chinese line breaks come from the ICU data built into Node, so a Node update that changes ICU can move a break; `--check` then reports the hero, and a plain run redraws it.

Two complete examples, with synthetic captures, are in `docs/examples/store-hero/`.
Two complete examples, with synthetic captures, are in `docs/examples/store-hero/`; the split one also draws a text-free image.

### Refusing secrets and oversized files at commit time

Expand Down
3 changes: 2 additions & 1 deletion docs/examples/store-hero/split/store-assets/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"layout": "split",
"icon": "assets/brand/icon.svg",
"primary": "#2563EB",
"accent": "#10B981"
"accent": "#10B981",
"textFreeFile": "text-free/00-hero-dark.png"
},
"caption": "Every room's lights from the tray.",
"alt": "Sample App's tray flyout, enlarged beside the headline: a card per room with an on switch and a level slider."
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 37 additions & 9 deletions src/store-hero/config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,22 @@ function checkHeroBlock(root, entry, label) {
if (hero.crop === undefined)
fail(`${label}.hero.fade needs a crop saying where the window is cut`)
}

// The text-free variant is one image for every locale, so its path has no {locale}.
if (hero.textFreeFile !== undefined) {
const file = hero.textFreeFile
if (
typeof file !== 'string' ||
!file.endsWith('.png') ||
file.includes(LOCALE_TOKEN)
) {
fail(
`${label}.hero.textFreeFile must be a .png path without ${LOCALE_TOKEN}, since one image serves every locale`,
)
}
if (hero.layout !== 'split')
fail(`${label}.hero.textFreeFile applies only to the split layout`)
}
}

/**
Expand Down Expand Up @@ -263,7 +279,8 @@ export function heroLocales(listings, layout, label) {
*
* @param {string} root the repo root; `hero.icon` is relative to it
* @param {string} assetsDir the store-assets folder, relative to `root`
* @returns {Array<object>} jobs with their layout, size, colours, icon, capture and locales
* @returns {Array<object>} jobs with their layout, size, colours, icon, capture and outputs: one
* per locale, then the text-free variant (`textFree: true`, no locale) when one is configured
*/
export function loadHeroJobs(root, assetsDir = DEFAULT_ASSETS_DIR) {
const assets = path.join(root, assetsDir)
Expand Down Expand Up @@ -307,6 +324,24 @@ export function loadHeroJobs(root, assetsDir = DEFAULT_ASSETS_DIR) {
typeof entry.source === 'string'
? resolveCapture(assets, entry.source, hero.crop, label, hero.fade)
: null
const outputs = locales.map((text) => ({
...text,
path: path.join(
assetsDir,
store,
entry.file.replaceAll(LOCALE_TOKEN, text.locale),
),
}))
if (hero.textFreeFile !== undefined) {
const textFreePath = path.join(assetsDir, store, hero.textFreeFile)
if (outputs.some((output) => output.path === textFreePath)) {
fail(
`${label}.hero.textFreeFile (${hero.textFreeFile}) is also a locale's hero; give it its own name`,
)
}
outputs.push({ textFree: true, path: textFreePath })
}

jobs.push({
store,
layout: hero.layout,
Expand All @@ -315,14 +350,7 @@ export function loadHeroJobs(root, assetsDir = DEFAULT_ASSETS_DIR) {
accent: hero.accent.toUpperCase(),
icon: path.join(root, hero.icon),
capture,
outputs: locales.map((text) => ({
...text,
path: path.join(
assetsDir,
store,
entry.file.replaceAll(LOCALE_TOKEN, text.locale),
),
})),
outputs,
pattern: path.join(assetsDir, store, entry.file),
})
}
Expand Down
149 changes: 112 additions & 37 deletions src/store-hero/layouts.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
*
* Both keep the headline inside the top two-thirds (Microsoft's guidance for overlays) and fail
* rather than shrink text below a size that still reads on a 320 x 180 Store search card.
*
* A split hero may also have a text-free variant (`textFreeLayout`): its background and window
* with no text, for a web page that sets the app's name and headline in its own HTML.
*/
import {
CANVAS_HEIGHT,
Expand Down Expand Up @@ -71,6 +74,7 @@ export const GEOMETRY = {
},
ghost: { left: 640, top: 250, bleed: 160, maxScale: 1.25, opacity: 0.42 },
},
textFree: { margin: 64, maxScale: 2 },
}

/** The bottom margin every text block keeps from the canvas edge. */
Expand Down Expand Up @@ -205,53 +209,58 @@ function bottomFade(context, { y, height }) {
)
}

/** The brand panel's gradient (`url(#panel)`): the primary colour darkened toward night. */
function panelGradient(primary) {
return `<linearGradient id="panel" x1="0" y1="0" x2="0.55" y2="1"><stop offset="0" stop-color="${mix(primary, NIGHT, 0.4)}"/><stop offset="1" stop-color="${mix(primary, NIGHT, 0.12)}"/></linearGradient>`
}

/** A soft glow of the accent colour toward the bottom-right corner (`url(#tint-b)`). */
function accentGlow(accent) {
return `<radialGradient id="tint-b" cx="0.88" cy="0.9" r="0.6"><stop offset="0" stop-color="${accent}" stop-opacity="0.3"/><stop offset="0.7" stop-color="${accent}" stop-opacity="0"/></radialGradient>`
}

/**
* The split layout. The window is scaled to fit the space right of the panel (never above
* `maxScale` times its logical size) and centred there, a little above the middle so its top,
* where flyouts put their title and main control, sits in the top two-thirds.
* The split layout's background: the blurred capture, then the brand tint over it. It also defines
* the panel gradient the layout draws later.
*/
export function splitLayout(job, output, context) {
const g = GEOMETRY.split
function brandBackdrop(job, context) {
const { primary, accent } = job
const parts = []

// Background: the blurred capture, then the brand tint over it.
parts.push(
`<rect width="${round(context.width)}" height="${CANVAS_HEIGHT}" fill="${NIGHT}"/>`,
)
parts.push(backdrop(job, context))
parts.push(
return (
`<rect width="${round(context.width)}" height="${CANVAS_HEIGHT}" fill="${NIGHT}"/>` +
backdrop(job, context) +
'<defs>' +
`<radialGradient id="tint-a" cx="0.2" cy="0.18" r="0.8"><stop offset="0" stop-color="${primary}" stop-opacity="0.55"/><stop offset="0.72" stop-color="${primary}" stop-opacity="0"/></radialGradient>` +
`<radialGradient id="tint-b" cx="0.88" cy="0.9" r="0.6"><stop offset="0" stop-color="${accent}" stop-opacity="0.3"/><stop offset="0.7" stop-color="${accent}" stop-opacity="0"/></radialGradient>` +
`<linearGradient id="panel" x1="0" y1="0" x2="0.55" y2="1"><stop offset="0" stop-color="${mix(primary, NIGHT, 0.4)}"/><stop offset="1" stop-color="${mix(primary, NIGHT, 0.12)}"/></linearGradient>` +
'<filter id="panel-shadow" x="-10%" y="-10%" width="130%" height="120%"><feGaussianBlur stdDeviation="30"/></filter>' +
'</defs>',
)
parts.push(
`<rect width="${round(context.width)}" height="${CANVAS_HEIGHT}" fill="url(#tint-a)"/>`,
)
parts.push(
`<rect width="${round(context.width)}" height="${CANVAS_HEIGHT}" fill="url(#tint-b)"/>`,
`<radialGradient id="tint-a" cx="0.2" cy="0.18" r="0.8"><stop offset="0" stop-color="${primary}" stop-opacity="0.55"/><stop offset="0.72" stop-color="${primary}" stop-opacity="0"/></radialGradient>` +
accentGlow(accent) +
panelGradient(primary) +
'<filter id="panel-shadow" x="-10%" y="-10%" width="130%" height="120%"><feGaussianBlur stdDeviation="30"/></filter>' +
'</defs>' +
`<rect width="${round(context.width)}" height="${CANVAS_HEIGHT}" fill="url(#tint-a)"/>` +
`<rect width="${round(context.width)}" height="${CANVAS_HEIGHT}" fill="url(#tint-b)"/>`
)
}

// The enlarged window, whole (or cut at the bottom and faded), in the space right of the panel.
const area = {
left: g.panelWidth + g.window.gap,
width: context.width - g.panelWidth - g.window.gap * 2,
height: CANVAS_HEIGHT - g.window.margin * 2,
}
/**
* The app's window, whole (or cut at the bottom and faded), enlarged to fit `area` and centred in
* it, with its shadow and outline. The scale never exceeds `maxScale` times the window's logical
* size, and how far the capture is enlarged is noted for the soft-capture advice.
*
* @param {{ left: number, width: number, height: number }} area where the window may go; it is
* placed `margin` units from the top at the least
* @param {{ margin: number, maxScale: number, lift: number }} fit `lift` raises the window above
* the vertical centre by that many units
*/
function enlargedWindow(job, context, area, { margin, maxScale, lift }) {
const [, , regionWidth, regionHeight] = job.capture.region
const logical = job.capture.scale / 100
const scale = Math.min(
g.window.maxScale,
maxScale,
area.width / (regionWidth / logical),
area.height / (regionHeight / logical),
)
const shownWidth = (regionWidth / logical) * scale
const shownHeight = (regionHeight / logical) * scale
const x = area.left + (area.width - shownWidth) / 2
const y = Math.max(g.window.margin, (CANVAS_HEIGHT - shownHeight) / 2 - 40)
const y = Math.max(margin, (CANVAS_HEIGHT - shownHeight) / 2 - lift)
const window = windowImage({
capture: job.capture,
image: context.captureImage,
Expand All @@ -268,13 +277,40 @@ export function splitLayout(job, output, context) {
radius: window.radius,
})
const outline = `<rect x="${round(x)}" y="${round(y)}" width="${round(window.width)}" height="${round(window.height)}" rx="${round(window.radius)}" fill="none" stroke="#FFFFFF" stroke-opacity="0.08" stroke-width="1"/>`
context.notes.push({ upscale: (scale * context.pixelsPerUnit) / logical })

if (job.capture.fade === 'bottom') {
parts.push(bottomFade(context, { y, height: window.height }))
parts.push(`<g mask="url(#cut-fade)">${shadow}${window.svg}${outline}</g>`)
} else {
parts.push(shadow, window.svg, outline)
return (
bottomFade(context, { y, height: window.height }) +
`<g mask="url(#cut-fade)">${shadow}${window.svg}${outline}</g>`
)
}
context.notes.push({ upscale: (scale * context.pixelsPerUnit) / logical })
return shadow + window.svg + outline
}

/**
* The split layout. The window is scaled to fit the space right of the panel (never above
* `maxScale` times its logical size) and centred there, a little above the middle so its top,
* where flyouts put their title and main control, sits in the top two-thirds.
*/
export function splitLayout(job, output, context) {
const g = GEOMETRY.split
const { primary, accent } = job
const parts = [brandBackdrop(job, context)]

// The enlarged window, whole (or cut at the bottom and faded), in the space right of the panel.
parts.push(
enlargedWindow(
job,
context,
{
left: g.panelWidth + g.window.gap,
width: context.width - g.panelWidth - g.window.gap * 2,
height: CANVAS_HEIGHT - g.window.margin * 2,
},
{ margin: g.window.margin, maxScale: g.window.maxScale, lift: 40 },
),
)

// The brand panel and its copy, drawn last so the panel's shadow falls on the backdrop.
parts.push(
Expand Down Expand Up @@ -434,6 +470,45 @@ export function brandCardLayout(job, output, context) {
return parts.join('')
}

/**
* The split hero's brand panel gradient across the whole canvas, with the accent glow, so the
* text-free variant reads as the same brand colour as the hero's panel.
*/
function brandPanelBackground(job, context) {
const { primary, accent } = job
return (
'<defs>' +
panelGradient(primary) +
accentGlow(accent) +
'</defs>' +
`<rect width="${round(context.width)}" height="${CANVAS_HEIGHT}" fill="url(#panel)"/>` +
`<rect width="${round(context.width)}" height="${CANVAS_HEIGHT}" fill="url(#tint-b)"/>`
)
}

/**
* The text-free variant of the split layout: the hero's brand colour and enlarged window, with no
* icon, name or text, for pages that set their own headline above the image. The panel's gradient
* fills the canvas and the window is centred on it, so a wide window has room to be drawn larger,
* which keeps the UI legible when the image is shown small, as on a phone.
*/
export function textFreeLayout(job, context) {
const g = GEOMETRY.textFree
return (
brandPanelBackground(job, context) +
enlargedWindow(
job,
context,
{
left: g.margin,
width: context.width - g.margin * 2,
height: CANVAS_HEIGHT - g.margin * 2,
},
{ margin: g.margin, maxScale: g.maxScale, lift: 0 },
)
)
}

export const LAYOUT_BUILDERS = {
split: splitLayout,
'brand-card': brandCardLayout,
Expand Down
11 changes: 7 additions & 4 deletions src/store-hero/render.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
import { CANVAS_HEIGHT, dataUri, escapeXml, round } from './draw.mjs'
import { fontFamily } from './fonts.mjs'
import { LAYOUT_BUILDERS } from './layouts.mjs'
import { LAYOUT_BUILDERS, textFreeLayout } from './layouts.mjs'
import { rgbRows } from './png.mjs'

/**
Expand Down Expand Up @@ -35,14 +35,15 @@ export function createRenderer(Resvg, fontFiles) {
}

/**
* Draws one locale's hero.
* Draws one locale's hero, or the job's text-free variant when `output.textFree` is set.
*
* @returns {{ rows: Buffer, notes: Array<{ upscale: number }> }} PNG rows (see `rgbRows`) and
* facts worth reporting, such as how far the capture was enlarged
*/
function render(job, output) {
const { width, height } = job.size
const family = fontFamily(output.locale)
// The text-free variant has no locale and draws no text, so any family will do.
const family = output.textFree ? 'Noto Sans' : fontFamily(output.locale)
const context = {
width: (CANVAS_HEIGHT * width) / height,
pixelsPerUnit: height / CANVAS_HEIGHT,
Expand All @@ -53,7 +54,9 @@ export function createRenderer(Resvg, fontFiles) {
notes: [],
}

const body = LAYOUT_BUILDERS[job.layout](job, output, context)
const body = output.textFree
? textFreeLayout(job, context)
: LAYOUT_BUILDERS[job.layout](job, output, context)
const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${round(context.width)} ${CANVAS_HEIGHT}">${body}</svg>`
const image = new Resvg(svg, options).render()
return {
Expand Down
Loading