autokap 1.9.1 → 1.9.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.
package/dist/mockup.d.ts CHANGED
@@ -204,18 +204,27 @@ export interface MockupOptions {
204
204
  height: number;
205
205
  };
206
206
  }
207
+ /**
208
+ * Status bar default: shown only on phone mockups. Tablet, laptop, and browser
209
+ * categories default to off (browser is additionally excluded at render time).
210
+ * An explicit user choice (`mockupOptions.showStatusBar`) always overrides this.
211
+ */
212
+ export declare function defaultShowStatusBar(category: DeviceCategory): boolean;
207
213
  /**
208
214
  * Resolve the two per-variant frame decisions shared by both render paths (CLI direct-upload
209
215
  * framing and the cloud legacy-multipart route): a variant's own `mockupOptions` wins, falling
210
216
  * back to the viewport-inferred orientation and the deprecated program-level `applyStatusBar`.
211
217
  * Pure + exported so the precedence is tested once instead of in two duplicated call sites.
218
+ *
219
+ * `showStatusBar` is left `undefined` when neither the variant nor the legacy fallback set it,
220
+ * so `applyDeviceFrame` can apply the category-aware default (phones on, everything else off).
212
221
  */
213
222
  export declare function resolveVariantFrameOptions(mockupOptions: MockupOptions | undefined, fallback: {
214
223
  orientation?: MockupOrientation;
215
224
  showStatusBar?: boolean;
216
225
  }): {
217
226
  orientation?: MockupOrientation;
218
- showStatusBar: boolean;
227
+ showStatusBar?: boolean;
219
228
  };
220
229
  export interface ResolvedDeviceFrameDescriptor {
221
230
  id: string;
package/dist/mockup.js CHANGED
@@ -17,21 +17,33 @@ function getSupabaseMockupConfig() {
17
17
  serviceKey: process.env.SUPABASE_SERVICE_ROLE_KEY,
18
18
  };
19
19
  }
20
+ /**
21
+ * Status bar default: shown only on phone mockups. Tablet, laptop, and browser
22
+ * categories default to off (browser is additionally excluded at render time).
23
+ * An explicit user choice (`mockupOptions.showStatusBar`) always overrides this.
24
+ */
25
+ export function defaultShowStatusBar(category) {
26
+ return category === 'phone';
27
+ }
20
28
  /**
21
29
  * Resolve the two per-variant frame decisions shared by both render paths (CLI direct-upload
22
30
  * framing and the cloud legacy-multipart route): a variant's own `mockupOptions` wins, falling
23
31
  * back to the viewport-inferred orientation and the deprecated program-level `applyStatusBar`.
24
32
  * Pure + exported so the precedence is tested once instead of in two duplicated call sites.
33
+ *
34
+ * `showStatusBar` is left `undefined` when neither the variant nor the legacy fallback set it,
35
+ * so `applyDeviceFrame` can apply the category-aware default (phones on, everything else off).
25
36
  */
26
37
  export function resolveVariantFrameOptions(mockupOptions, fallback) {
27
38
  return {
28
39
  orientation: mockupOptions?.orientation ?? fallback.orientation,
29
- showStatusBar: mockupOptions?.showStatusBar ?? fallback.showStatusBar ?? false,
40
+ showStatusBar: mockupOptions?.showStatusBar ?? fallback.showStatusBar,
30
41
  };
31
42
  }
32
43
  const DEFAULT_MOCKUP_OPTIONS = {
33
44
  orientation: 'portrait',
34
45
  outputScale: 2,
46
+ // Placeholder only — applyDeviceFrame re-resolves this per device category (see defaultShowStatusBar).
35
47
  showStatusBar: true,
36
48
  showSafeAreaTop: true,
37
49
  showSafeAreaBottom: true,
@@ -523,6 +535,9 @@ export async function applyDeviceFrame(screenshot, deviceId, options) {
523
535
  if (!config)
524
536
  throw new Error(`Unknown device frame: ${deviceId}`);
525
537
  const opts = { ...DEFAULT_MOCKUP_OPTIONS, ...options };
538
+ // Status bar defaults to on for phones only; tablet/laptop/browser default to off.
539
+ // An explicit user choice wins; browser is additionally excluded at render time below.
540
+ opts.showStatusBar = options?.showStatusBar ?? defaultShowStatusBar(config.category);
526
541
  const requestedOrientation = opts.orientation ?? 'portrait';
527
542
  // Normalize against supported orientations so stale extra configs in Supabase
528
543
  // do not override landscape-only desktop/tablet/browser frames.
@@ -1,10 +1,18 @@
1
1
  /**
2
- * Safari macOS browser bar — uses the Figma-exported asset directly.
2
+ * Safari macOS browser bar — RECONSTRUCTED layout (not a stretched asset).
3
3
  *
4
- * Reference SVG: assets/frames/Safari tool bar.svg (1299×88, single-row toolbar).
5
- * The asset is embedded as a string constant via `safari-toolbar-asset.ts`
6
- * (auto-generated). All icons are baked as paths only the URL inside
7
- * the address pill is dynamic.
4
+ * The Figma export (1280×52 visible toolbar) used to be drawn with
5
+ * `preserveAspectRatio="none"` on a FIXED viewBox, so any target width whose
6
+ * aspect ratio differed from 1280:52 horizontally squished every icon worse
7
+ * the wider the mockup got. This now mirrors the Chrome generator
8
+ * (`browser-bar.ts`): a height-driven UNIFORM scale + a DYNAMIC-width viewBox,
9
+ * with the toolbar's icon GLYPHS reused verbatim from the asset but re-anchored
10
+ * - left group (traffic lights, sidebar, back/forward) pinned left,
11
+ * - right group (share, open, new tab, tab overview) pinned right via `dx`,
12
+ * - center address pill: dynamic width, centered, inner icons follow its edges.
13
+ * Only the container and pill backgrounds are redrawn; the Figma blur/blend
14
+ * layers are dropped (resvg ignores them anyway and they are invisible on the
15
+ * white/dark toolbar). Colors and glyph shapes are preserved from the asset.
8
16
  *
9
17
  * Two outputs:
10
18
  * - HTML (Playwright preview / React) — inline SVG inside a scaled wrapper
@@ -1,17 +1,25 @@
1
1
  /**
2
- * Safari macOS browser bar — uses the Figma-exported asset directly.
2
+ * Safari macOS browser bar — RECONSTRUCTED layout (not a stretched asset).
3
3
  *
4
- * Reference SVG: assets/frames/Safari tool bar.svg (1299×88, single-row toolbar).
5
- * The asset is embedded as a string constant via `safari-toolbar-asset.ts`
6
- * (auto-generated). All icons are baked as paths only the URL inside
7
- * the address pill is dynamic.
4
+ * The Figma export (1280×52 visible toolbar) used to be drawn with
5
+ * `preserveAspectRatio="none"` on a FIXED viewBox, so any target width whose
6
+ * aspect ratio differed from 1280:52 horizontally squished every icon worse
7
+ * the wider the mockup got. This now mirrors the Chrome generator
8
+ * (`browser-bar.ts`): a height-driven UNIFORM scale + a DYNAMIC-width viewBox,
9
+ * with the toolbar's icon GLYPHS reused verbatim from the asset but re-anchored
10
+ * - left group (traffic lights, sidebar, back/forward) pinned left,
11
+ * - right group (share, open, new tab, tab overview) pinned right via `dx`,
12
+ * - center address pill: dynamic width, centered, inner icons follow its edges.
13
+ * Only the container and pill backgrounds are redrawn; the Figma blur/blend
14
+ * layers are dropped (resvg ignores them anyway and they are invisible on the
15
+ * white/dark toolbar). Colors and glyph shapes are preserved from the asset.
8
16
  *
9
17
  * Two outputs:
10
18
  * - HTML (Playwright preview / React) — inline SVG inside a scaled wrapper
11
19
  * - SVG (sharp / resvg server compositing)
12
20
  */
13
21
  import { SF_PRO_TEXT_REGULAR, SF_PRO_TEXT_SEMIBOLD, } from './sf-pro-fonts.js';
14
- import { SAFARI_TOOLBAR_SVG, SAFARI_TOOLBAR_VIEWBOX, SAFARI_URL_PILL, } from './safari-toolbar-asset.js';
22
+ import { SAFARI_TOOLBAR_SVG, SAFARI_TOOLBAR_VIEWBOX, SAFARI_TOOLBAR_REF_W, SAFARI_TOOLBAR_REF_H, SAFARI_URL_PILL, } from './safari-toolbar-asset.js';
15
23
  // ── Fonts ────────────────────────────────────────────────────────────────
16
24
  const FONT_CSS_HTML = `<style>
17
25
  @font-face{font-family:'SF Pro Text';src:local('SF Pro Text'),local('.SFNSText'),url('${SF_PRO_TEXT_REGULAR}') format('woff2');font-weight:400;font-style:normal}
@@ -19,12 +27,71 @@ const FONT_CSS_HTML = `<style>
19
27
  </style>`;
20
28
  // SVG output: fonts are NOT embedded inline. Resvg-js 2.6.2 does not honor
21
29
  // `@font-face url(data:font/woff2;base64,…)` declarations inside SVG style
22
- // blocks; fonts must instead be supplied via `font.fontFiles` to the Resvg
23
- // constructor. The browser-bar pipeline (mockup.ts::rasterizeSvg) loads SF
24
- // Pro Text from disk via `sf-pro-resvg-fonts.ts`. The `font-family` hint on
25
- // the URL <text> element below remains for any consumer that DOES honor
26
- // CSS @font-face (a future Resvg release, a different SVG renderer, etc.).
30
+ // blocks; fonts are supplied via `font.fontFiles` to the Resvg constructor by
31
+ // `mockup.ts::rasterizeSvg` (see `sf-pro-resvg-fonts.ts`). The `font-family`
32
+ // hint on the URL <text> element remains for renderers that DO honor it.
27
33
  const FF = "'SF Pro Text',-apple-system,BlinkMacSystemFont,system-ui,sans-serif";
34
+ // ── Reference geometry (asset coordinate space, original 88-tall viewBox) ──
35
+ // The cropped viewBox is `0 18 1280 52`; pills/glyphs keep their native y so
36
+ // the vertical layout is identical to the asset — only X is reflowed.
37
+ const REF_W = SAFARI_TOOLBAR_REF_W; // 1280
38
+ const REF_H = SAFARI_TOOLBAR_REF_H; // 52
39
+ const VB_Y = SAFARI_TOOLBAR_VIEWBOX.y; // 18
40
+ const PILL_Y = SAFARI_URL_PILL.y; // 26
41
+ const PILL_H = SAFARI_URL_PILL.height; // 36
42
+ const PILL_RX = 18;
43
+ const SIDEBAR_PILL = { x: 95, w: 54 };
44
+ const NAV_PILL = { x: 163, w: 67 };
45
+ const RIGHT_PILL = { x: 1134, w: 139 };
46
+ const REF_URL_PILL = { x: SAFARI_URL_PILL.x, w: SAFARI_URL_PILL.width }; // 447 / 385
47
+ // macOS traffic lights (cx derived from x + r), y=37 d=14 → cy=44 r=7.
48
+ const TRAFFIC = [
49
+ { x: 17, color: '#FF736A' },
50
+ { x: 40, color: '#FEBC2E' },
51
+ { x: 63, color: '#19C332' },
52
+ ];
53
+ // End of the fixed left cluster (back/forward pill right edge).
54
+ const LEFT_BOUND = NAV_PILL.x + NAV_PILL.w; // 230
55
+ // Horizontal breathing room between the address pill and the side clusters.
56
+ const PILL_GAP = 28;
57
+ // ── Icon glyph extraction (reuse the asset's vector paths verbatim) ────────
58
+ // We pull only the icon glyphs (specific fills) out of the baked asset and
59
+ // drop the pill-background / blur / blend layers, which we redraw ourselves.
60
+ const ICON_FILLS = new Set(['#4C4C4C', '#808080', '#C6C6C6', '#E6E6E6']);
61
+ // Light → dark recolor for the reused glyphs (mirrors the asset's dark intent).
62
+ const DARK_ICON = {
63
+ '#4C4C4C': '#E4E4E4',
64
+ '#808080': '#8E8E93',
65
+ '#C6C6C6': '#6E6E73',
66
+ '#E6E6E6': '#4A4A4C',
67
+ };
68
+ let cachedGlyphs = null;
69
+ function assetGlyphs() {
70
+ if (cachedGlyphs)
71
+ return cachedGlyphs;
72
+ const glyphs = [];
73
+ const tagRe = /<path\b[^>]*?\/>/g;
74
+ let m;
75
+ while ((m = tagRe.exec(SAFARI_TOOLBAR_SVG)) !== null) {
76
+ const tag = m[0];
77
+ const dM = tag.match(/\sd="([^"]+)"/);
78
+ const fM = tag.match(/\sfill="([^"]+)"/);
79
+ if (!dM || !fM || !ICON_FILLS.has(fM[1]))
80
+ continue;
81
+ const xM = dM[1].match(/M\s*(-?[\d.]+)/);
82
+ glyphs.push({ d: dM[1], fill: fM[1], x0: xM ? parseFloat(xM[1]) : 0 });
83
+ }
84
+ cachedGlyphs = glyphs;
85
+ return glyphs;
86
+ }
87
+ const r = (n) => Math.round(n * 100) / 100;
88
+ function emitGlyph(g, isDark, tx = 0) {
89
+ if (!g)
90
+ return '';
91
+ const fill = isDark ? (DARK_ICON[g.fill] ?? g.fill) : g.fill;
92
+ const t = tx ? ` transform="translate(${r(tx)} 0)"` : '';
93
+ return `<path d="${g.d}" fill="${fill}"${t}/>`;
94
+ }
28
95
  // ── Helpers ──────────────────────────────────────────────────────────────
29
96
  function escText(s) {
30
97
  return s
@@ -36,62 +103,76 @@ function escText(s) {
36
103
  function cleanUrl(raw) {
37
104
  return (raw || 'apple.com').replace(/^https?:\/\//, '').replace(/\/$/, '');
38
105
  }
39
- /** Build the URL <text> overlay placed inside the address pill. */
40
- function urlTextSvg(url, color) {
41
- const cx = SAFARI_URL_PILL.x + SAFARI_URL_PILL.width / 2;
42
- const cy = SAFARI_URL_PILL.y + SAFARI_URL_PILL.height / 2;
43
- return `<text x="${cx}" y="${cy}" font-family="${FF}" font-size="14" font-weight="510" fill="${color}" text-anchor="middle" dominant-baseline="central">${escText(url)}</text>`;
44
- }
45
- /**
46
- * Strip the asset's outer `<svg ...>` opening tag so we can re-emit it with
47
- * our own width/height/viewBox, then append a URL text element before `</svg>`.
48
- */
49
- function buildSafariSvgInner(url, isDark) {
50
- // Asset begins with `<svg width="1299" height="88" viewBox="0 0 1299 88" fill="none" xmlns="...">`
51
- // Drop everything up to the end of that opening tag.
52
- const openEnd = SAFARI_TOOLBAR_SVG.indexOf('>');
53
- const closeStart = SAFARI_TOOLBAR_SVG.lastIndexOf('</svg>');
54
- let inner = SAFARI_TOOLBAR_SVG.slice(openEnd + 1, closeStart);
55
- if (isDark) {
56
- // Minimal dark-mode token swap keeps the asset usable until a dedicated
57
- // dark variant ships. Hardcoded colors map to Safari's dark palette.
58
- inner = inner
59
- .replace(/fill="white"/g, 'fill="#2C2C2E"')
60
- .replace(/fill="#FFFFFF"/gi, 'fill="#2C2C2E"')
61
- .replace(/fill="#F7F7F7"/gi, 'fill="#3A3A3C"')
62
- .replace(/fill="#4C4C4C"/gi, 'fill="#E4E4E4"')
63
- .replace(/fill="#808080"/gi, 'fill="#8E8E93"')
64
- .replace(/fill="#C6C6C6"/gi, 'fill="#6E6E73"')
65
- .replace(/fill="#E6E6E6"/gi, 'fill="#4A4A4C"');
66
- }
106
+ // ── Core: reflowed toolbar SVG at the requested pixel dimensions ───────────
107
+ function buildSafariBarSvg(svgW, svgH, isDark, url) {
108
+ // Uniform scale driven by height; the viewBox width grows with the target so
109
+ // icons never stretch only spacing and the address pill width adapt.
110
+ const s = svgH / REF_H;
111
+ const iw = Math.max(REF_W, Math.round(svgW / s));
112
+ const dx = iw - REF_W; // right-cluster shift
113
+ // Address pill: centered, dynamic width, clamped so it never collides with
114
+ // the fixed side clusters.
115
+ const rightBound = RIGHT_PILL.x + dx; // left edge of the right cluster
116
+ const maxPillW = Math.max(120, (rightBound - PILL_GAP) - (LEFT_BOUND + PILL_GAP));
117
+ let pillW = Math.min(720, Math.max(360, Math.round(iw * 0.36)));
118
+ pillW = Math.min(pillW, maxPillW);
119
+ let pillX = Math.round(iw / 2 - pillW / 2);
120
+ pillX = Math.max(LEFT_BOUND + PILL_GAP, Math.min(pillX, rightBound - PILL_GAP - pillW));
121
+ const pillRight = pillX + pillW;
122
+ // Tokens
123
+ const barBg = isDark ? '#2C2C2E' : '#FFFFFF';
124
+ const pillBg = isDark ? '#3A3A3C' : '#F0F0F0';
125
+ const border = isDark ? '#1F1F22' : '#E4E4E4';
67
126
  const urlColor = isDark ? '#E4E4E4' : '#4C4C4C';
68
- return inner + urlTextSvg(url, urlColor);
127
+ const gl = assetGlyphs();
128
+ const leftGlyphs = gl.filter(g => g.x0 < 240);
129
+ const readerGlyph = gl.find(g => g.fill === '#808080' && g.x0 < 640);
130
+ const reloadGlyph = gl.find(g => g.fill === '#808080' && g.x0 >= 640);
131
+ const rightGlyphs = gl.filter(g => g.x0 >= 1000);
132
+ const cy = PILL_Y + PILL_H / 2; // 44
133
+ const trafficLights = TRAFFIC.map(t => `<circle cx="${t.x + 7}" cy="${cy}" r="7" fill="${t.color}"/>`
134
+ + `<circle cx="${t.x + 7}" cy="${cy}" r="6.75" fill="none" stroke="#000000" stroke-opacity="0.1" stroke-width="0.5"/>`).join('');
135
+ const pill = (x, w) => `<rect x="${r(x)}" y="${PILL_Y}" width="${r(w)}" height="${PILL_H}" rx="${PILL_RX}" fill="${pillBg}"/>`;
136
+ const leftLayer = leftGlyphs.map(g => emitGlyph(g, isDark)).join('');
137
+ const rightLayer = rightGlyphs.map(g => emitGlyph(g, isDark, dx)).join('');
138
+ const body = [
139
+ // Toolbar background (top corners are rounded by the wrapper's clip).
140
+ `<rect x="0" y="${VB_Y}" width="${iw}" height="${REF_H + 1}" fill="${barBg}"/>`,
141
+ // Bottom hairline separator.
142
+ `<rect x="0" y="${VB_Y + REF_H - 0.5}" width="${iw}" height="0.5" fill="${border}"/>`,
143
+ // Pill backgrounds
144
+ pill(SIDEBAR_PILL.x, SIDEBAR_PILL.w),
145
+ pill(NAV_PILL.x, NAV_PILL.w),
146
+ pill(pillX, pillW),
147
+ pill(RIGHT_PILL.x + dx, RIGHT_PILL.w),
148
+ // Glyphs
149
+ trafficLights,
150
+ leftLayer,
151
+ emitGlyph(readerGlyph, isDark, pillX - REF_URL_PILL.x),
152
+ emitGlyph(reloadGlyph, isDark, pillRight - (REF_URL_PILL.x + REF_URL_PILL.w)),
153
+ rightLayer,
154
+ // URL text (centered in the address pill)
155
+ `<text x="${r(pillX + pillW / 2)}" y="${cy}" font-family="${FF}" font-size="14" font-weight="510" fill="${urlColor}" text-anchor="middle" dominant-baseline="central">${escText(url)}</text>`,
156
+ ].join('\n');
157
+ return `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="${svgW}" height="${svgH}" viewBox="0 ${VB_Y} ${iw} ${REF_H}" preserveAspectRatio="none" fill="none">
158
+ ${body}
159
+ </svg>`;
69
160
  }
70
161
  // ── Generator (HTML, for Playwright client preview) ──────────────────────
71
162
  export function generateSafariBrowserBarHtml(options) {
72
163
  const { config, width, height, pixelScale = 1 } = options;
73
164
  const url = cleanUrl(config.url);
74
165
  const isDark = config.colorScheme === 'dark';
75
- const inner = buildSafariSvgInner(url, isDark);
76
- // The asset's reference is 1299×88. We render it at the target width×height
77
- // by setting the SVG width/height directly — viewBox handles the scaling.
78
- // pixelScale lets the server multiply for high-DPI raster output.
79
166
  const w = width * pixelScale;
80
167
  const h = height * pixelScale;
81
- const vb = SAFARI_TOOLBAR_VIEWBOX;
82
- return `${FONT_CSS_HTML}<div style="width:${w}px;height:${h}px;position:relative;overflow:hidden;line-height:0;font-size:0">
83
- <svg width="${w}" height="${h}" viewBox="${vb.x} ${vb.y} ${vb.width} ${vb.height}" preserveAspectRatio="none" xmlns="http://www.w3.org/2000/svg" fill="none" style="display:block">${inner}</svg>
84
- </div>`;
168
+ const svg = buildSafariBarSvg(w, h, isDark, url);
169
+ return `${FONT_CSS_HTML}<div style="width:${w}px;height:${h}px;position:relative;overflow:hidden;line-height:0;font-size:0">${svg}</div>`;
85
170
  }
86
171
  // ── Generator (SVG, for sharp / resvg server compositing) ────────────────
87
172
  export function generateSafariBrowserBarSvg(options) {
88
173
  const { config, width, height } = options;
89
174
  const url = cleanUrl(config.url);
90
175
  const isDark = config.colorScheme === 'dark';
91
- const inner = buildSafariSvgInner(url, isDark);
92
- const vb = SAFARI_TOOLBAR_VIEWBOX;
93
- return `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="${width}" height="${height}" viewBox="${vb.x} ${vb.y} ${vb.width} ${vb.height}" preserveAspectRatio="none" fill="none">
94
- ${inner}
95
- </svg>`;
176
+ return buildSafariBarSvg(width, height, isDark, url);
96
177
  }
97
178
  //# sourceMappingURL=safari-browser-bar.js.map
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "autokap",
3
- "version": "1.9.1",
3
+ "version": "1.9.2",
4
4
  "description": "AI-powered CLI tool for capturing clean screenshots of websites",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",