blob: fec50c19a6e914181d8a2d98cb48d4237a14e049 [file] [log] [blame]
{
"version": 3,
"sources": ["styleguide.ts"],
"sourcesContent": ["/**\n * @license\n * Copyright 2021 The Go Authors. All rights reserved.\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file.\n */\n\nimport { SelectNavController, makeSelectNav } from '../_outline/select.js';\nimport { TreeNavController } from '../_outline/tree.js';\n\nwindow.addEventListener('load', () => {\n const tree = document.querySelector<HTMLElement>('.js-tree');\n if (tree) {\n const treeCtrl = new TreeNavController(tree);\n const select = makeSelectNav(treeCtrl);\n document.querySelector('.js-mainNavMobile')?.appendChild(select);\n }\n\n const guideTree = document.querySelector<HTMLElement>('.Outline .js-tree');\n if (guideTree) {\n const treeCtrl = new TreeNavController(guideTree);\n const select = makeSelectNav(treeCtrl);\n document.querySelector('.Outline .js-select')?.appendChild(select);\n }\n\n for (const el of document.querySelectorAll('.js-toggleTheme')) {\n el.addEventListener('click', e => {\n const value = (e.currentTarget as HTMLButtonElement).getAttribute('data-value');\n document.documentElement.setAttribute('data-theme', String(value));\n });\n }\n for (const el of document.querySelectorAll('.js-toggleLayout')) {\n el.addEventListener('click', e => {\n const value = (e.currentTarget as HTMLButtonElement).getAttribute('data-value');\n document.documentElement.setAttribute('data-layout', String(value));\n });\n }\n\n for (const el of document.querySelectorAll<HTMLSelectElement>('.js-selectNav')) {\n new SelectNavController(el);\n }\n});\n\ncustomElements.define(\n 'go-color',\n class extends HTMLElement {\n constructor() {\n super();\n this.style.setProperty('display', 'contents');\n // The current version of TypeScript is not aware of String.replaceAll.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const name = this.id as any;\n this.removeAttribute('id');\n this.innerHTML = `\n <div style=\"--color: var(${name});\" class=\"GoColor-circle\"></div>\n <span>\n <div id=\"${name}\" class=\"go-textLabel GoColor-title\">${name\n .replace('--color-', '')\n .replaceAll('-', ' ')}</div>\n <pre class=\"StringifyElement-markup\">var(${name})</pre>\n </span>\n `;\n this.querySelector('pre')?.addEventListener('click', () => {\n navigator.clipboard.writeText(`var(${name})`);\n });\n }\n }\n);\n\ncustomElements.define(\n 'go-icon',\n class extends HTMLElement {\n constructor() {\n super();\n this.style.setProperty('display', 'contents');\n // The current version of TypeScript is not aware of String.replaceAll.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const name = this.getAttribute('name') as any;\n this.innerHTML = `<p id=\"icon-${name}\" class=\"go-textLabel GoIcon-title\">${name.replaceAll(\n '_',\n ' '\n )}</p>\n <stringify-el>\n <img class=\"go-Icon\" height=\"24\" width=\"24\" src=\"/static/_icon/${name}_gm_grey_24dp.svg\" alt=\"\">\n </stringify-el>\n `;\n }\n }\n);\n\ncustomElements.define(\n 'clone-el',\n class extends HTMLElement {\n constructor() {\n super();\n this.style.setProperty('display', 'contents');\n const selector = this.getAttribute('selector');\n if (!selector) return;\n const html = ' ' + document.querySelector(selector)?.outerHTML;\n this.innerHTML = `\n <stringify-el collapsed>${html}</stringify-el>\n `;\n }\n }\n);\n\ncustomElements.define(\n 'stringify-el',\n class extends HTMLElement {\n constructor() {\n super();\n this.style.setProperty('display', 'contents');\n const html = this.innerHTML;\n const idAttr = this.id ? ` id=\"${this.id}\"` : '';\n this.removeAttribute('id');\n let markup = `<pre class=\"StringifyElement-markup\">` + escape(trim(html)) + `</pre>`;\n if (this.hasAttribute('collapsed')) {\n markup = `<details class=\"StringifyElement-details\"><summary>Markup</summary>${markup}</details>`;\n }\n this.innerHTML = `<span${idAttr}>${html}</span>${markup}`;\n this.querySelector('pre')?.addEventListener('click', () => {\n navigator.clipboard.writeText(html);\n });\n }\n }\n);\n\n/**\n * trim removes excess indentation from html markup by\n * measuring the number of spaces in the first line of\n * the given string and removing that number of spaces\n * from the beginning of each line.\n */\nfunction trim(html: string) {\n return html\n .split('\\n')\n .reduce<{ result: string[]; start: number }>(\n (acc, val) => {\n if (acc.result.length === 0) {\n const start = val.indexOf('<');\n acc.start = start === -1 ? 0 : start;\n }\n val = val.slice(acc.start);\n if (val) {\n acc.result.push(val);\n }\n return acc;\n },\n { result: [], start: 0 }\n )\n .result.join('\\n');\n}\n\nfunction escape(html: string) {\n // The current version of TypeScript is not aware of String.replaceAll.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return (html as any)?.replaceAll('<', '&lt;')?.replaceAll('>', '&gt;');\n}\n"],
"mappings": "AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GAOA,+EACA,wDAEA,OAAO,iBAAiB,OAAQ,IAAM,CACpC,KAAM,GAAO,SAAS,cAA2B,YACjD,GAAI,EAAM,CACR,KAAM,GAAW,GAAI,GAAkB,GACjC,EAAS,EAAc,GAC7B,SAAS,cAAc,sBAAsB,YAAY,GAG3D,KAAM,GAAY,SAAS,cAA2B,qBACtD,GAAI,EAAW,CACb,KAAM,GAAW,GAAI,GAAkB,GACjC,EAAS,EAAc,GAC7B,SAAS,cAAc,wBAAwB,YAAY,GAG7D,SAAW,KAAM,UAAS,iBAAiB,mBACzC,EAAG,iBAAiB,QAAS,GAAK,CAChC,KAAM,GAAS,EAAE,cAAoC,aAAa,cAClE,SAAS,gBAAgB,aAAa,aAAc,OAAO,MAG/D,SAAW,KAAM,UAAS,iBAAiB,oBACzC,EAAG,iBAAiB,QAAS,GAAK,CAChC,KAAM,GAAS,EAAE,cAAoC,aAAa,cAClE,SAAS,gBAAgB,aAAa,cAAe,OAAO,MAIhE,SAAW,KAAM,UAAS,iBAAoC,iBAC5D,GAAI,GAAoB,KAI5B,eAAe,OACb,WACA,aAAc,YAAY,CACxB,aAAc,CACZ,QACA,KAAK,MAAM,YAAY,UAAW,YAGlC,KAAM,GAAO,KAAK,GAClB,KAAK,gBAAgB,MACrB,KAAK,UAAY;AAAA,mCACY;AAAA;AAAA,qBAEd,yCAA4C,EACxD,QAAQ,WAAY,IACpB,WAAW,IAAK;AAAA,qDAC4B;AAAA;AAAA,QAG/C,KAAK,cAAc,QAAQ,iBAAiB,QAAS,IAAM,CACzD,UAAU,UAAU,UAAU,OAA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