{"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","// Dependencies\n// =============================================================================\n// eslint-disable-next-line no-unused-vars\nimport styles from './styles.css';\n\n\n// Plugin\n// =============================================================================\nfunction docsifyCopyCode(hook, vm) {\n hook.doneEach(function() {\n const targetElms = Array.apply(null, document.querySelectorAll('pre[data-lang]'));\n const i18n = {\n buttonText: 'Copy to clipboard',\n errorText: 'Error',\n successText: 'Copied'\n };\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 }\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 listenerHost.addEventListener('click', function(evt) {\n const isCopyCodeButton = evt.target.classList.contains('docsify-copy-code-button');\n\n if (isCopyCodeButton) {\n const buttonElm = evt.target.tagName === 'BUTTON' ? evt.target : evt.target.parentNode;\n const range = document.createRange();\n const preElm = buttonElm.parentNode;\n const codeElm = preElm.querySelector('code');\n\n let selection = window.getSelection();\n\n range.selectNode(codeElm);\n selection.removeAllRanges();\n selection.addRange(range);\n\n try {\n // Copy selected text\n const successful = document.execCommand('copy');\n\n if (successful) {\n buttonElm.classList.add('success');\n setTimeout(function() {\n buttonElm.classList.remove('success');\n }, 1000);\n }\n }\n catch(err) {\n // eslint-disable-next-line\n console.error(`docsify-copy-code: ${err}`);\n\n buttonElm.classList.add('error');\n setTimeout(function() {\n buttonElm.classList.remove('error');\n }, 1000);\n }\n\n selection = window.getSelection();\n\n if (typeof selection.removeRange === 'function') {\n selection.removeRange(range);\n }\n else if (typeof selection.removeAllRanges === 'function') {\n selection.removeAllRanges();\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\n console.warn('[Deprecation] Link to external docsify-copy-code stylesheet is no longer necessary.');\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\n console.warn('[Deprecation] Manually initializing docsify-copy-code using window.DocsifyCopyCodePlugin.init() is no longer necessary.');\n });\n };\n }\n};\n\nwindow.$docsify = window.$docsify || {};\nwindow.$docsify.plugins = [docsifyCopyCode].concat(window.$docsify.plugins || []);\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","doneEach","targetElms","Array","apply","querySelectorAll","i18n","buttonText","errorText","successText","config","copyCode","Object","keys","forEach","key","textValue","_typeof","some","match","isMatch","location","href","indexOf","template","join","elm","insertAdjacentHTML","mounted","addEventListener","evt","target","classList","contains","buttonElm","tagName","parentNode","range","createRange","codeElm","selection","getSelection","selectNode","removeAllRanges","addRange","execCommand","add","setTimeout","remove","err","error","removeRange","concat"],"mappings":";;;;;;;+PAAA,SAAq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