{"version":3,"sources":["../src/index.ts","../src/features/gfm-alert/icons.ts","../src/features/gfm-alert/renderer.ts","../src/features/gfm-alert/types.ts","../src/features/gfm-alert/index.ts"],"sourcesContent":["export type { AlertType, GfmAlertOptions } from \"./features/gfm-alert/index.js\";\nexport { ALERT_TYPES, gfmAlert } from \"./features/gfm-alert/index.js\";\n","import type { AlertType } from \"./types.js\";\n\nconst pathData: Record<AlertType, string> = {\n\tNOTE: \"M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8Zm8-6.5a6.5 6.5 0 1 0 0 13 6.5 6.5 0 0 0 0-13ZM6.5 7.75A.75.75 0 0 1 7.25 7h1a.75.75 0 0 1 .75.75v2.75h.25a.75.75 0 0 1 0 1.5h-2a.75.75 0 0 1 0-1.5h.25v-2h-.25a.75.75 0 0 1-.75-.75ZM8 6a1 1 0 1 1 0-2 1 1 0 0 1 0 2Z\",\n\tTIP: \"M8 1.5c-2.363 0-4 1.69-4 3.75 0 .984.424 1.625.984 2.304l.214.253c.223.264.47.556.673.848.284.411.537.896.621 1.49a.75.75 0 0 1-1.484.211c-.04-.282-.163-.547-.37-.847a8.456 8.456 0 0 0-.542-.68c-.084-.1-.173-.205-.268-.32C3.201 7.75 2.5 6.766 2.5 5.25 2.5 2.31 4.863 0 8 0s5.5 2.31 5.5 5.25c0 1.516-.701 2.5-1.328 3.259-.095.115-.184.22-.268.319-.207.245-.383.453-.541.681-.208.3-.33.565-.37.847a.751.751 0 0 1-1.485-.212c.084-.593.337-1.078.621-1.489.203-.292.45-.584.673-.848.075-.088.147-.173.213-.253.561-.679.985-1.32.985-2.304 0-2.06-1.637-3.75-4-3.75ZM5.75 12h4.5a.75.75 0 0 1 0 1.5h-4.5a.75.75 0 0 1 0-1.5ZM6 15.25a.75.75 0 0 1 .75-.75h2.5a.75.75 0 0 1 0 1.5h-2.5a.75.75 0 0 1-.75-.75Z\",\n\tIMPORTANT:\n\t\t\"M0 1.75C0 .784.784 0 1.75 0h12.5C15.216 0 16 .784 16 1.75v9.5A1.75 1.75 0 0 1 14.25 13H8.06l-2.573 2.573A1.458 1.458 0 0 1 3 14.543V13H1.75A1.75 1.75 0 0 1 0 11.25Zm1.75-.25a.25.25 0 0 0-.25.25v9.5c0 .138.112.25.25.25h2a.75.75 0 0 1 .75.75v2.19l2.72-2.72a.749.749 0 0 1 .53-.22h6.5a.25.25 0 0 0 .25-.25v-9.5a.25.25 0 0 0-.25-.25Zm7 2.25v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 9a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z\",\n\tWARNING:\n\t\t\"M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z\",\n\tCAUTION:\n\t\t\"M4.47.22A.749.749 0 0 1 5 0h6c.199 0 .389.079.53.22l4.25 4.25c.141.14.22.331.22.53v6a.749.749 0 0 1-.22.53l-4.25 4.25A.749.749 0 0 1 11 16H5a.749.749 0 0 1-.53-.22L.22 11.53A.749.749 0 0 1 0 11V5c0-.199.079-.389.22-.53Zm.84 1.28L1.5 5.31v5.38l3.81 3.81h5.38l3.81-3.81V5.31L10.69 1.5ZM8 4a.75.75 0 0 1 .75.75v3.5a.75.75 0 0 1-1.5 0v-3.5A.75.75 0 0 1 8 4Zm0 8a1 1 0 1 1 0-2 1 1 0 0 1 0 2Z\",\n};\n\nexport function getAlertIconSvg(type: AlertType): string {\n\tconst d = pathData[type] ?? \"\";\n\treturn `<svg class=\"octicon\" viewBox=\"0 0 16 16\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"${d}\"></path></svg>`;\n}\n\nexport function getAlertIconSvgInline(type: AlertType): string {\n\tconst d = pathData[type] ?? \"\";\n\treturn `<svg style=\"margin-right:8px;fill:currentColor\" viewBox=\"0 0 16 16\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"${d}\"></path></svg>`;\n}\n","import type { Token, Tokens } from \"marked\";\nimport { getAlertIconSvg, getAlertIconSvgInline } from \"./icons.js\";\nimport type { AlertType, GfmAlertOptions } from \"./types.js\";\n\nconst ALERT_REGEX = /^\\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\\]/i;\n\nconst INLINE_COLORS: Record<AlertType, { border: string; title: string }> = {\n\tNOTE: { border: \"#0969da\", title: \"#0969da\" },\n\tTIP: { border: \"#1f883d\", title: \"#1a7f37\" },\n\tIMPORTANT: { border: \"#8957e5\", title: \"#8250df\" },\n\tWARNING: { border: \"#9e6a03\", title: \"#9a6700\" },\n\tCAUTION: { border: \"#cf222e\", title: \"#d1242f\" },\n};\n\nfunction isAlertParagraph(token: Token): token is Tokens.Paragraph {\n\tif (token.type !== \"paragraph\") return false;\n\tconst paragraph = token as Tokens.Paragraph;\n\tconst firstText = paragraph.tokens[0];\n\tif (firstText?.type !== \"text\") return false;\n\treturn ALERT_REGEX.test(firstText.text);\n}\n\nfunction stripAlertMarker(paragraph: Tokens.Paragraph): Tokens.Paragraph[] {\n\tconst firstText = paragraph.tokens[0] as Tokens.Text;\n\tconst remaining = firstText.text.replace(ALERT_REGEX, \"\").trimStart();\n\n\tif (!remaining) {\n\t\treturn [];\n\t}\n\n\treturn [\n\t\t{\n\t\t\t...paragraph,\n\t\t\ttokens: [{ ...firstText, text: remaining }, ...paragraph.tokens.slice(1)],\n\t\t},\n\t];\n}\n\nfunction buildClassNames(alertType: AlertType, extra?: string): string {\n\tconst classes = [\n\t\t\"markdown-alert\",\n\t\t`markdown-alert-${alertType.toLowerCase()}`,\n\t];\n\tif (extra) {\n\t\tfor (const cls of extra.split(\" \")) {\n\t\t\tif (cls.length > 0) classes.push(cls);\n\t\t}\n\t}\n\treturn classes.join(\" \");\n}\n\nfunction extractAlertType(token: Tokens.Paragraph): AlertType {\n\tconst firstText = token.tokens[0];\n\tif (firstText?.type !== \"text\") return \"NOTE\";\n\tconst match = firstText.text.match(ALERT_REGEX);\n\treturn (match?.[1]?.toUpperCase() as AlertType) ?? \"NOTE\";\n}\n\nexport function createBlockquoteRenderer(\n\tparser: { parse: (tokens: Token[]) => string },\n\ttoken: Tokens.Blockquote,\n\toptions: GfmAlertOptions = {},\n): string {\n\tconst firstToken = token.tokens[0];\n\n\tif (!firstToken || !isAlertParagraph(firstToken)) {\n\t\treturn `<blockquote>\\n${parser.parse(token.tokens)}</blockquote>\\n`;\n\t}\n\n\tconst alertType = extractAlertType(firstToken as Tokens.Paragraph);\n\tconst restTokens = token.tokens.slice(1);\n\tconst stripped = stripAlertMarker(firstToken as Tokens.Paragraph);\n\tconst allTokens = [...stripped, ...restTokens];\n\n\tconst body = parser.parse(allTokens);\n\tconst icon = getAlertIconSvg(alertType);\n\n\tif (options.inlineStyles) {\n\t\tconst colors = INLINE_COLORS[alertType];\n\t\tconst inlineIcon = getAlertIconSvgInline(alertType);\n\t\treturn `<div style=\"border-left:0.25em solid ${colors.border};color:inherit;margin-bottom:16px;padding:0.5rem 1em\" dir=\"auto\">\\n<p style=\"align-items:center;display:flex;font-size:14px;font-weight:500;line-height:1;color:${colors.title}\" dir=\"auto\">${inlineIcon}${alertType}</p>\\n${body}</div>\\n`;\n\t}\n\n\tconst classNames = buildClassNames(alertType, options.className);\n\treturn `<div class=\"${classNames}\" dir=\"auto\">\\n<p class=\"markdown-alert-title\" dir=\"auto\">${icon}${alertType}</p>\\n${body}</div>\\n`;\n}\n","export const ALERT_TYPES = [\n\t\"NOTE\",\n\t\"TIP\",\n\t\"IMPORTANT\",\n\t\"WARNING\",\n\t\"CAUTION\",\n] as const;\n\nexport type AlertType = (typeof ALERT_TYPES)[number];\n\nexport interface GfmAlertOptions {\n\t/** Extra CSS class names appended to the alert container. */\n\tclassName?: string;\n\t/** Use inline styles instead of CSS classes. Eliminates the need to import alert.css. */\n\tinlineStyles?: boolean;\n}\n","import type { MarkedExtension } from \"marked\";\nimport { createBlockquoteRenderer } from \"./renderer.js\";\nimport type { GfmAlertOptions } from \"./types.js\";\n\nexport type { AlertType, GfmAlertOptions } from \"./types.js\";\nexport { ALERT_TYPES } from \"./types.js\";\n\nexport function gfmAlert(options: GfmAlertOptions = {}): MarkedExtension {\n\treturn {\n\t\trenderer: {\n\t\t\tblockquote({ tokens }) {\n\t\t\t\treturn createBlockquoteRenderer(\n\t\t\t\t\tthis.parser,\n\t\t\t\t\t{ type: \"blockquote\", raw: \"\", text: \"\", tokens },\n\t\t\t\t\toptions,\n\t\t\t\t);\n\t\t\t},\n\t\t},\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEA,IAAM,WAAsC;AAAA,EAC3C,MAAM;AAAA,EACN,KAAK;AAAA,EACL,WACC;AAAA,EACD,SACC;AAAA,EACD,SACC;AACF;AAEO,SAAS,gBAAgB,MAAyB;AACxD,QAAM,IAAI,SAAS,IAAI,KAAK;AAC5B,SAAO,+FAA+F,CAAC;AACxG;AAEO,SAAS,sBAAsB,MAAyB;AAC9D,QAAM,IAAI,SAAS,IAAI,KAAK;AAC5B,SAAO,0HAA0H,CAAC;AACnI;;;ACjBA,IAAM,cAAc;AAEpB,IAAM,gBAAsE;AAAA,EAC3E,MAAM,EAAE,QAAQ,WAAW,OAAO,UAAU;AAAA,EAC5C,KAAK,EAAE,QAAQ,WAAW,OAAO,UAAU;AAAA,EAC3C,WAAW,EAAE,QAAQ,WAAW,OAAO,UAAU;AAAA,EACjD,SAAS,EAAE,QAAQ,WAAW,OAAO,UAAU;AAAA,EAC/C,SAAS,EAAE,QAAQ,WAAW,OAAO,UAAU;AAChD;AAEA,SAAS,iBAAiB,OAAyC;AAClE,MAAI,MAAM,SAAS,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