{"version":3,"file":"docsify-copy-code.min.js","sources":["../node_modules/style-inject/dist/style-inject.es.js","../src/index.js"],"sourcesContent":["function styleInject(css, ref) {\n if ( ref === void 0 ) ref = {};\n var insertAt = ref.insertAt;\n\n if (!css || typeof document === 'undefined') { return; }\n\n var head = document.head || document.getElementsByTagName('head')[0];\n var style = document.createElement('style');\n style.type = 'text/css';\n\n if (insertAt === 'top') {\n if (head.firstChild) {\n head.insertBefore(style, head.firstChild);\n } else {\n head.appendChild(style);\n }\n } else {\n head.appendChild(style);\n }\n\n if (style.styleSheet) {\n style.styleSheet.cssText = css;\n } else {\n style.appendChild(document.createTextNode(css));\n }\n}\n\nexport default styleInject;\n","import './styles.css';\n\nfunction docsifyCopyCode(hook, vm) {\n const i18n = {\n buttonText: 'Copy to clipboard',\n errorText: 'Error',\n successText: 'Copied',\n };\n\n hook.doneEach(function () {\n const targetElms = Array.from(document.querySelectorAll('pre[data-lang]'));\n\n // Update i18n strings based on options and location.href\n if (vm.config.copyCode) {\n Object.keys(i18n).forEach((key) => {\n const textValue = vm.config.copyCode[key];\n\n if (typeof textValue === 'string') {\n i18n[key] = textValue;\n } else if (typeof textValue === 'object') {\n Object.keys(textValue).some((match) => {\n const isMatch = location.href.indexOf(match) > -1;\n\n i18n[key] = isMatch ? textValue[match] : i18n[key];\n\n return isMatch;\n });\n }\n });\n }\n\n const template = [\n '',\n ].join('');\n\n targetElms.forEach((elm) => {\n elm.insertAdjacentHTML('beforeend', template);\n });\n });\n\n hook.mounted(function () {\n const listenerHost = document.querySelector('.content');\n\n if (listenerHost) {\n listenerHost.addEventListener('click', function (evt) {\n const isCopyCodeButton = evt.target.classList.contains(\n 'docsify-copy-code-button'\n );\n\n if (isCopyCodeButton) {\n const buttonElm =\n evt.target.tagName === 'BUTTON'\n ? evt.target\n : evt.target.parentNode;\n const range = document.createRange();\n const preElm = buttonElm.parentNode;\n const codeElm = preElm.querySelector('code');\n const liveRegionElm = buttonElm.querySelector('[aria-live]');\n\n let selection = window.getSelection();\n\n range.selectNode(codeElm);\n\n if (selection) {\n selection.removeAllRanges();\n selection.addRange(range);\n }\n\n try {\n // Copy selected text\n const successful = document.execCommand('copy');\n\n if (successful) {\n buttonElm.classList.add('success');\n liveRegionElm.innerText = i18n.successText;\n\n setTimeout(function () {\n buttonElm.classList.remove('success');\n liveRegionElm.innerText = '';\n }, 1000);\n }\n } catch (err) {\n // eslint-disable-next-line no-console\n console.error(`docsify-copy-code: ${err}`);\n\n buttonElm.classList.add('error');\n liveRegionElm.innerText = i18n.errorText;\n\n setTimeout(function () {\n buttonElm.classList.remove('error');\n liveRegionElm.innerText = '';\n }, 1000);\n }\n\n selection = window.getSelection();\n\n if (selection) {\n if (typeof selection.removeRange === 'function') {\n selection.removeRange(range);\n } else if (typeof selection.removeAllRanges === 'function') {\n selection.removeAllRanges();\n }\n }\n }\n });\n }\n });\n}\n\n// Deprecation warning for v1.x: stylesheet\nif (document.querySelector('link[href*=\"docsify-copy-code\"]')) {\n // eslint-disable-next-line no-console\n console.warn(\n '[Deprecation] Link to external docsify-copy-code stylesheet is no longer necessary.'\n );\n}\n\n// Deprecation warning for v1.x: init()\nwindow.DocsifyCopyCodePlugin = {\n init: function () {\n return function (hook, vm) {\n hook.ready(function () {\n // eslint-disable-next-line no-console\n console.warn(\n '[Deprecation] Manually initializing docsify-copy-code using window.DocsifyCopyCodePlugin.init() is no longer necessary.'\n );\n });\n };\n },\n};\n\nwindow.$docsify = window.$docsify || {};\nwindow.$docsify.plugins = [docsifyCopyCode].concat(\n window.$docsify.plugins || []\n);\n"],"names":["css","ref","insertAt","document","head","getElementsByTagName","style","createElement","type","firstChild","insertBefore","appendChild","styleSheet","cssText","createTextNode","querySelector","console","warn","window","DocsifyCopyCodePlugin","init","hook","vm","ready","$docsify","plugins","i18n","buttonText","errorText","successText","doneEach","targetElms","Array","from","querySelectorAll","config","copyCode","Object","keys","forEach","key","textValue","_typeof","some","match","isMatch","location","href","indexOf","template","concat","join","elm","insertAdjacentHTML","mounted","listenerHost","addEventListener","evt","target","classList","contains","buttonElm","tagName","parentNode","range","createRange","codeElm","liveRegionElm","selection","getSelection","selectNode","removeAllRanges","addRange","execCommand","add","innerText","setTimeout","remove","err","error","removeRange"],"mappings":";;;;;;;gQAAA,SAAqBA,EAAKC,QACX,IAARA,IAAiBA,EAAM,CAAA,GAC5B,IAAIC,EAAWD,EAAIC,SAEnB,GAAKF,GAA2B,oBAAbG,SAAnB,CAEA,IAAIC,EAAOD,SAASC,MAAQD,SAASE,qBAAqB,QAAQ,GAC9DC,EAAQH,SAASI,cAAc,SACnCD,EAAME,KAAO,WAEI,QAAbN,GACEE,EAAKK,WACPL,EAAKM,aAAaJ,EAAOF,EAAKK,YAKhCL,EAAKO,YAAYL,GAGfA,EAAMM,WACRN,EAAMM,WAAWC,QAAUb,EAE3BM,EAAMK,YAAYR,SAASW,eAAed,GAnBY,CAqB1D,o6BC0FIG,SAASY,cAAc,oCAEzBC,QAAQC,KACN,uFAKJC,OAAOC,sBAAwB,CAC7BC,KAAM,WACJ,OAAO,SAAUC,EAAMC,GACrBD,EAAKE,OAAM,WAETP,QAAQC,KACN,0HAEJ,IAEJ,GAGFC,OAAOM,SAAWN,OAAOM,UAAY,GACrCN,OAAOM,SAASC,QAAU,CAvI1B,SAAyBJ,EAAMC,GAC7B,IAAMI,EAAO,CACXC,WAAY,oBACZC,UAAW,QACXC,YAAa,UAGfR,EAAKS,UAAS,WACZ,IAAMC,EAAaC,MAAMC,KAAK9B,SAAS+B,iBAAiB,mBAGpDZ,EAAGa,OAAOC,UACZC,OAAOC,KAAKZ,GAAMa,SAAQ,SAACC,GACzB,IAAMC,EAAYnB,EAAGa,OAAOC,SAASI,GAEZ,iBAAdC,EACTf,EAAKc,GAAOC,EACkB,WAArBC,EAAOD,IAChBJ,OAAOC,KAAKG,GAAWE,MAAK,SAACC,GAC3B,IAAMC,EAAUC,SAASC,KAAKC,QAAQJ,IAAU,EAIhD,OAFAlB,EAAKc,GAAOK,EAAUJ,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