@extenshi/mcp
Version:
Extenshi MCP server — bring the extension catalog (search, security, market research) and pre-publish scanning into your AI tools
99 lines • 7.83 kB
TypeScript
/**
* Pin guide kit — the pin guide packaged for a welcome page that ships INSIDE
* the extension (`welcome/welcome.html` opened from `runtime.onInstalled`).
*
* The hosted welcome page draws the icon and the numbered badges as HTML
* overlays on top of the illustration. An in-extension page has no such
* renderer, works offline and runs under the extension CSP (no inline scripts),
* so the kit "flattens" each step instead: the icon becomes an `<image>` and the
* badge a circle + number INSIDE the SVG. What comes out is plain markup and
* files an agent drops into the extension:
*
* - `html` — one `<section data-pin-guide-browser>` per browser, captions
* in English marked with `data-i18n` keys. No scripts, no
* event handlers, no inline styles: the extension CSP passes it.
* - `css` — optional layout, plus the light/dark switch for `theme: 'auto'`.
* - `script` — an ES module for a separate file: pick the user's browser,
* apply `chrome.i18n` captions, and read whether the icon is
* already pinned (`action.getUserSettings().isOnToolbar`).
* - `messages` — the captions in every requested language, in `chrome.i18n`
* `messages.json` shape, ready to merge into `_locales`.
* - `steps` — the flattened SVGs one by one, for `<img>` use.
*
* Same copy rules as ./pin-guide.ts: copied into @extenshi/mcp and
* @extenshi/cli, see the header of ./pin-guide-strings.ts.
*/
import { type PinGuideBrowser } from './pin-guide.js';
import { type PinGuideLocale } from './pin-guide-strings.js';
export declare const PIN_GUIDE_BROWSERS: readonly PinGuideBrowser[];
export type PinGuideKitTheme = 'light' | 'dark' | 'auto';
export interface PinGuideKitInput {
extensionName: string;
/** Default: all three. */
browsers?: readonly string[];
/** BCP 47 tags; default: every supported locale. Unsupported tags are an error. */
locales?: readonly string[];
accentColor?: string;
/** `auto` emits a light and a dark copy of every step and lets CSS pick. Default `light`. */
theme?: PinGuideKitTheme;
/**
* Where the illustrations load the icon from: a path inside the extension
* package relative to the page (`../icons/icon-48.png`), or a
* `data:image/png|jpeg|webp|svg+xml;base64,…` URI. Absent → a neutral tile.
*/
iconHref?: string | null;
/** Prefix of the `chrome.i18n` message names. Default `pinGuide`. */
keyPrefix?: string;
}
export interface PinGuideKitStep {
n: number;
/** The flattened SVG, light theme (or dark when `theme: 'dark'`). */
svg: string;
/** The dark copy, only with `theme: 'auto'`. */
svgDark: string | null;
/**
* Message names of this step's captions; `body` is null for step 2. `menu`
* names the browser's menu item written inside the illustration (Firefox
* step 3, "Pin to Toolbar") and is null for every other step.
*/
keys: {
title: string;
body: string | null;
alt: string;
menu: string | null;
};
}
export interface PinGuideKitMessage {
message: string;
description: string;
}
export interface PinGuideKit {
extensionName: string;
browsers: PinGuideBrowser[];
locales: PinGuideLocale[];
theme: PinGuideKitTheme;
steps: Partial<Record<PinGuideBrowser, PinGuideKitStep[]>>;
html: string;
css: string;
script: string;
/** Keyed by BCP 47 tag (`pt-BR`); `chromeLocaleDir` gives the `_locales` folder name. */
messages: Partial<Record<PinGuideLocale, Record<string, PinGuideKitMessage>>>;
}
export declare class PinGuideKitError extends Error {
}
/** `_locales` folder name for a BCP 47 tag: `pt-BR` → `pt_BR`. */
export declare function chromeLocaleDir(locale: PinGuideLocale): string;
/**
* Build the kit. Throws `PinGuideKitError` on input it cannot honour — an
* unknown browser or language, an unsafe icon reference, a bad key prefix —
* rather than producing something subtly wrong.
*/
export declare function buildPinGuideKit(input: PinGuideKitInput): PinGuideKit;
/**
* Shipped as a separate file next to the page: the extension CSP forbids
* inline scripts. Plain ES2020, no build step, works in Chrome, Edge and
* Firefox. `chrome` and `browser` are both probed because Firefox exposes
* `getBrowserInfo` only on `browser`.
*/
export declare const PIN_GUIDE_SCRIPT = "// Pin guide helpers \u2014 generated by Extenshi. Load with <script type=\"module\">.\n\nconst ext = globalThis.browser ?? globalThis.chrome\n\n/** 'chrome' | 'edge' | 'firefox' \u2014 which pin guide this user needs. */\nexport async function detectPinGuideBrowser() {\n try {\n const info = await globalThis.browser?.runtime?.getBrowserInfo?.()\n if (info && /firefox/i.test(info.name)) return 'firefox'\n } catch {}\n const nav = globalThis.navigator ?? {}\n if (/\\bFirefox\\//.test(nav.userAgent ?? '')) return 'firefox'\n const brands = nav.userAgentData?.brands ?? []\n if (brands.some((b) => /Microsoft Edge/i.test(b.brand)) || /\\bEdg\\//.test(nav.userAgent ?? '')) return 'edge'\n return 'chrome'\n}\n\n/** Show only the detected browser's section. Returns the browser it picked. */\nexport async function showPinGuide(root = document) {\n const browser = await detectPinGuideBrowser()\n const sections = [...root.querySelectorAll('[data-pin-guide-browser]')]\n if (sections.some((s) => s.dataset.pinGuideBrowser === browser)) {\n for (const s of sections) s.hidden = s.dataset.pinGuideBrowser !== browser\n }\n return browser\n}\n\n/** Replace the English captions with chrome.i18n messages where the extension has them. */\nexport function applyPinGuideMessages(root = document) {\n const i18n = ext?.i18n\n if (typeof i18n?.getMessage !== 'function') return\n for (const el of root.querySelectorAll('.xpg [data-i18n]')) {\n const text = i18n.getMessage(el.dataset.i18n)\n if (text) el.textContent = text\n }\n for (const el of root.querySelectorAll('.xpg [data-i18n-aria-label]')) {\n const text = i18n.getMessage(el.dataset.i18nAriaLabel)\n if (text) el.setAttribute('aria-label', text)\n }\n}\n\n/**\n * true / false when the browser can tell (action.getUserSettings: Chrome 91+,\n * Edge 91+, Firefox 116+), null when it cannot \u2014 then show the guide anyway.\n */\nexport async function isPinnedToToolbar() {\n const action = ext?.action ?? ext?.browserAction\n if (typeof action?.getUserSettings !== 'function') return null\n try {\n const settings = await action.getUserSettings()\n return typeof settings?.isOnToolbar === 'boolean' ? settings.isOnToolbar : null\n } catch {\n return null\n }\n}\n\n/**\n * Call back with the pinned state now and whenever it may have changed: on\n * action.onUserSettingsChanged where it exists (Chrome 130+, Firefox 142+), and\n * whenever the page regains focus or becomes visible \u2014 the user pins in the\n * toolbar, outside the page. Returns a function that stops listening.\n */\nexport function onPinnedChange(callback) {\n let last\n const check = async () => {\n const value = await isPinnedToToolbar()\n if (value !== last) {\n last = value\n callback(value)\n }\n }\n const onVisible = () => {\n if (document.visibilityState === 'visible') check()\n }\n const changed = (ext?.action ?? ext?.browserAction)?.onUserSettingsChanged\n changed?.addListener?.(check)\n globalThis.addEventListener('focus', check)\n document.addEventListener('visibilitychange', onVisible)\n check()\n return () => {\n changed?.removeListener?.(check)\n globalThis.removeEventListener('focus', check)\n document.removeEventListener('visibilitychange', onVisible)\n }\n}\n";
//# sourceMappingURL=pin-guide-kit.d.ts.map