@diplodoc/transform 4.56.0 → 4.57.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/dist/css/_yfm-only.css.map +1 -1
  2. package/dist/css/_yfm-only.min.css.map +1 -1
  3. package/dist/css/base.css +69 -14
  4. package/dist/css/base.css.map +3 -3
  5. package/dist/css/base.min.css +1 -1
  6. package/dist/css/base.min.css.map +3 -3
  7. package/dist/css/print.css.map +1 -1
  8. package/dist/css/yfm.css +69 -14
  9. package/dist/css/yfm.css.map +3 -3
  10. package/dist/css/yfm.min.css +1 -1
  11. package/dist/css/yfm.min.css.map +3 -3
  12. package/dist/js/_yfm-only.js.map +1 -1
  13. package/dist/js/_yfm-only.min.js.map +1 -1
  14. package/dist/js/base.js +40 -7
  15. package/dist/js/base.js.map +3 -3
  16. package/dist/js/base.min.js +1 -1
  17. package/dist/js/base.min.js.map +4 -4
  18. package/dist/js/yfm.js +40 -7
  19. package/dist/js/yfm.js.map +3 -3
  20. package/dist/js/yfm.min.js +1 -1
  21. package/dist/js/yfm.min.js.map +4 -4
  22. package/lib/constants.d.ts +2 -0
  23. package/lib/constants.js +5 -0
  24. package/lib/constants.js.map +1 -0
  25. package/lib/md.js +4 -2
  26. package/lib/md.js.map +1 -1
  27. package/lib/plugins/anchors/constants.d.ts +2 -0
  28. package/lib/plugins/anchors/constants.js +19 -1
  29. package/lib/plugins/anchors/constants.js.map +1 -1
  30. package/lib/plugins/anchors/index.d.ts +1 -0
  31. package/lib/plugins/anchors/index.js +22 -5
  32. package/lib/plugins/anchors/index.js.map +1 -1
  33. package/lib/plugins/notes/constants.d.ts +2 -1
  34. package/lib/plugins/notes/constants.js.map +1 -1
  35. package/lib/plugins/notes/index.js +4 -12
  36. package/lib/plugins/notes/index.js.map +1 -1
  37. package/lib/typings.d.ts +6 -1
  38. package/package.json +3 -3
  39. package/src/js/anchor.ts +18 -0
  40. package/src/js/base.ts +1 -0
  41. package/src/js/code.ts +1 -22
  42. package/src/js/utils.ts +20 -0
  43. package/src/scss/_anchor.scss +38 -8
  44. package/src/scss/_common.scss +11 -8
  45. package/src/transform/constants.ts +3 -0
  46. package/src/transform/md.ts +3 -0
  47. package/src/transform/plugins/anchors/constants.ts +21 -0
  48. package/src/transform/plugins/anchors/index.ts +52 -8
  49. package/src/transform/plugins/notes/constants.ts +3 -1
  50. package/src/transform/plugins/notes/index.ts +4 -22
  51. package/src/transform/typings.ts +23 -1
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/js/utils.ts", "../../src/js/term/utils.ts", "../../src/js/term/index.ts"],
4
- "sourcesContent": ["export const getEventTarget = (event: Event) => {\n const path = event.composedPath();\n return Array.isArray(path) && path.length > 0 ? path[0] : event.target;\n};\n\nexport const isCustom = (event: Event) => {\n const target = getEventTarget(event);\n return !target || !(target as HTMLElement).matches;\n};\n", "export const Selector = {\n TITLE: '.yfm .yfm-term_title',\n CONTENT: '.yfm .yfm-term_dfn',\n};\nexport const openClass = 'open';\nexport const openDefinitionClass = Selector.CONTENT.replace(/\\./g, '') + ' ' + openClass;\nlet isListenerNeeded = true;\n\nexport function setDefinitionId(definitionElement: HTMLElement, termElement: HTMLElement): void {\n const termId = termElement.getAttribute('id') || Math.random().toString(36).substr(2, 8);\n definitionElement?.setAttribute('term-id', termId);\n}\n\nexport function setDefinitonAriaAttributes(\n definitionElement: HTMLElement,\n termElement: HTMLElement,\n): void {\n const ariaLive = termElement.getAttribute('aria-live') || 'polite';\n definitionElement?.setAttribute('aria-live', ariaLive);\n definitionElement?.setAttribute('aria-modal', 'true');\n}\n\nexport function setDefinitionPosition(\n definitionElement: HTMLElement,\n termElement: HTMLElement,\n): void {\n const {\n x: termX,\n y: termY,\n right: termRight,\n left: termLeft,\n width: termWidth,\n height: termHeight,\n } = termElement.getBoundingClientRect();\n\n const termParent = termParentElement(termElement);\n\n if (!termParent) {\n return;\n }\n\n const {right: termParentRight, left: termParentLeft} = termParent.getBoundingClientRect();\n\n if ((termParentRight < termLeft || termParentLeft > termRight) && !isListenerNeeded) {\n closeDefinition(definitionElement);\n return;\n }\n\n if (isListenerNeeded && termParent) {\n termParent.addEventListener('scroll', termOnResize);\n isListenerNeeded = false;\n }\n\n const relativeX = Number(definitionElement.getAttribute('relativeX'));\n const relativeY = Number(definitionElement.getAttribute('relativeY'));\n\n if (relativeX === termX && relativeY === termY) {\n return;\n }\n\n definitionElement.setAttribute('relativeX', String(termX));\n definitionElement.setAttribute('relativeY', String(termY));\n\n const offsetTop = termHeight + 5;\n const definitionParent = definitionElement.parentElement;\n\n if (!definitionParent) {\n return;\n }\n\n const {width: definitionWidth} = definitionElement.getBoundingClientRect();\n const {left: definitionParentLeft} = definitionParent.getBoundingClientRect();\n\n // If definition not fit document change base alignment\n const definitionLeftCoordinate = Number(getCoords(termElement).left);\n const definitionRightCoordinate = definitionWidth + definitionLeftCoordinate;\n\n const definitionOutOfScreenOnLeft = definitionLeftCoordinate - definitionWidth < 0;\n const definitionOutOfScreenOnRight = definitionRightCoordinate > document.body.clientWidth;\n\n const isAlignSwapped = definitionOutOfScreenOnRight || document.dir === 'rtl';\n const fitDefinitionDocument =\n isAlignSwapped && !definitionOutOfScreenOnLeft ? definitionWidth - termWidth : 0;\n const customHeaderTop = getCoords(definitionParent).top - definitionParent.offsetTop;\n const offsetRight = 5;\n const shiftLeft = definitionOutOfScreenOnRight\n ? definitionRightCoordinate - document.body.clientWidth + offsetRight\n : 0;\n const offsetLeft =\n getCoords(termElement).left -\n definitionParentLeft +\n definitionParent.offsetLeft -\n fitDefinitionDocument;\n\n const isShiftLeftNeeded = offsetLeft + definitionWidth >= document.body.clientWidth;\n\n definitionElement.style.top =\n Number(getCoords(termElement).top + offsetTop - customHeaderTop) + 'px';\n definitionElement.style.left = Number(offsetLeft - (isShiftLeftNeeded ? shiftLeft : 0)) + 'px';\n}\n\nfunction termOnResize() {\n const openedDefinition = document.getElementsByClassName(openDefinitionClass)[0] as HTMLElement;\n\n if (!openedDefinition) {\n return;\n }\n const termId = openedDefinition.getAttribute('term-id') || '';\n const termElement = document.getElementById(termId);\n\n if (!termElement) {\n return;\n }\n\n setDefinitionPosition(openedDefinition, termElement);\n}\n\nfunction termParentElement(term: HTMLElement | null) {\n if (!term) {\n return null;\n }\n\n const closestScrollableParent = term.closest('table') || term.closest('code');\n\n return closestScrollableParent || term.parentElement;\n}\n\nexport function openDefinition(target: HTMLElement) {\n const openedDefinition = document.getElementsByClassName(openDefinitionClass)[0] as HTMLElement;\n\n const termId = target.getAttribute('id');\n const termKey = target.getAttribute('term-key');\n const definitionElement = document.getElementById(termKey + '_element');\n\n const isSameTerm = openedDefinition && termId === openedDefinition.getAttribute('term-id');\n if (isSameTerm) {\n closeDefinition(openedDefinition);\n return;\n }\n\n const isTargetDefinitionContent = target.closest(\n [Selector.CONTENT.replace(' ', ''), openClass].join('.'),\n );\n\n if (openedDefinition && !isTargetDefinitionContent) {\n closeDefinition(openedDefinition);\n }\n\n if (!target.matches(Selector.TITLE) || !definitionElement) {\n return;\n }\n\n setDefinitionId(definitionElement, target);\n setDefinitonAriaAttributes(definitionElement, target);\n setDefinitionPosition(definitionElement, target);\n\n definitionElement.classList.toggle(openClass);\n\n trapFocus(definitionElement);\n}\n\nexport function closeDefinition(definition: HTMLElement) {\n definition.classList.remove(openClass);\n const term = getTermByDefinition(definition);\n const termParent = termParentElement(term);\n\n if (!termParent) {\n return;\n }\n\n termParent.removeEventListener('scroll', termOnResize);\n isListenerNeeded = true;\n}\n\nfunction getCoords(elem: HTMLElement) {\n const box = elem.getBoundingClientRect();\n\n const body = document.body;\n const docEl = document.documentElement;\n\n const scrollTop = window.pageYOffset || docEl.scrollTop || body.scrollTop;\n const scrollLeft = window.pageXOffset || docEl.scrollLeft || body.scrollLeft;\n\n const clientTop = docEl.clientTop || body.clientTop || 0;\n const clientLeft = docEl.clientLeft || body.clientLeft || 0;\n\n const top = box.top + scrollTop - clientTop;\n const left = box.left + scrollLeft - clientLeft;\n\n return {top: Math.round(top), left: Math.round(left)};\n}\n\nexport function trapFocus(element: HTMLElement) {\n const focusableElements = element.querySelectorAll(\n 'button, [href], input, select, textarea, [tabindex]:not([tabindex=\"-1\"])',\n );\n const firstFocusableElement = focusableElements[0] as HTMLElement;\n const lastFocusableElement = focusableElements[focusableElements.length - 1] as HTMLElement;\n\n if (firstFocusableElement) {\n firstFocusableElement.focus();\n }\n\n element.addEventListener('keydown', function (e) {\n const isTabPressed = e.key === 'Tab' || e.keyCode === 9;\n if (!isTabPressed) {\n return;\n }\n\n if (e.shiftKey) {\n if (document.activeElement === firstFocusableElement) {\n lastFocusableElement.focus();\n e.preventDefault();\n }\n } else if (document.activeElement === lastFocusableElement) {\n firstFocusableElement.focus();\n e.preventDefault();\n }\n });\n}\n\nexport function getTermByDefinition(definition: HTMLElement) {\n const termId = definition.getAttribute('term-id');\n\n return termId ? document.getElementById(termId) : null;\n}\n", "import {getEventTarget, isCustom} from '../utils';\n\nimport {\n closeDefinition,\n getTermByDefinition,\n openClass,\n openDefinition,\n openDefinitionClass,\n setDefinitionPosition,\n} from './utils';\n\nif (typeof document !== 'undefined') {\n document.addEventListener('click', (event) => {\n if (getEventTarget(event) || !isCustom(event)) {\n openDefinition(getEventTarget(event) as HTMLElement);\n }\n });\n\n document.addEventListener('keydown', (event) => {\n const openedDefinition = document.getElementsByClassName(\n openDefinitionClass,\n )[0] as HTMLElement;\n\n if (event.key === 'Enter' && document.activeElement) {\n openDefinition(document.activeElement as HTMLElement);\n }\n\n if (event.key === 'Escape' && openedDefinition) {\n closeDefinition(openedDefinition);\n getTermByDefinition(openedDefinition)?.focus(); // Set focus back to open button after closing popup\n }\n });\n\n window.addEventListener('resize', () => {\n const openedDefinition = document.getElementsByClassName(\n openDefinitionClass,\n )[0] as HTMLElement;\n\n if (!openedDefinition) {\n return;\n }\n\n const termId = openedDefinition.getAttribute('term-id') || '';\n const termElement = document.getElementById(termId);\n\n if (!termElement) {\n openedDefinition.classList.toggle(openClass);\n return;\n }\n\n setDefinitionPosition(openedDefinition, termElement);\n });\n}\n"],
4
+ "sourcesContent": ["export const getEventTarget = (event: Event) => {\n const path = event.composedPath();\n return Array.isArray(path) && path.length > 0 ? path[0] : event.target;\n};\n\nexport const isCustom = (event: Event) => {\n const target = getEventTarget(event);\n return !target || !(target as HTMLElement).matches;\n};\n\nexport const copyToClipboard = async (text: string) => {\n if (!text) {\n return;\n }\n\n if (navigator.clipboard && typeof navigator.clipboard.writeText) {\n return navigator.clipboard.writeText(text);\n }\n\n const textarea = document.createElement('textarea');\n textarea.setAttribute('style', 'position: absolute; left: 1000%');\n textarea.textContent = text;\n document.body.append(textarea);\n\n textarea.select();\n document.execCommand('copy');\n\n document.body.removeChild(textarea);\n};\n", "export const Selector = {\n TITLE: '.yfm .yfm-term_title',\n CONTENT: '.yfm .yfm-term_dfn',\n};\nexport const openClass = 'open';\nexport const openDefinitionClass = Selector.CONTENT.replace(/\\./g, '') + ' ' + openClass;\nlet isListenerNeeded = true;\n\nexport function setDefinitionId(definitionElement: HTMLElement, termElement: HTMLElement): void {\n const termId = termElement.getAttribute('id') || Math.random().toString(36).substr(2, 8);\n definitionElement?.setAttribute('term-id', termId);\n}\n\nexport function setDefinitonAriaAttributes(\n definitionElement: HTMLElement,\n termElement: HTMLElement,\n): void {\n const ariaLive = termElement.getAttribute('aria-live') || 'polite';\n definitionElement?.setAttribute('aria-live', ariaLive);\n definitionElement?.setAttribute('aria-modal', 'true');\n}\n\nexport function setDefinitionPosition(\n definitionElement: HTMLElement,\n termElement: HTMLElement,\n): void {\n const {\n x: termX,\n y: termY,\n right: termRight,\n left: termLeft,\n width: termWidth,\n height: termHeight,\n } = termElement.getBoundingClientRect();\n\n const termParent = termParentElement(termElement);\n\n if (!termParent) {\n return;\n }\n\n const {right: termParentRight, left: termParentLeft} = termParent.getBoundingClientRect();\n\n if ((termParentRight < termLeft || termParentLeft > termRight) && !isListenerNeeded) {\n closeDefinition(definitionElement);\n return;\n }\n\n if (isListenerNeeded && termParent) {\n termParent.addEventListener('scroll', termOnResize);\n isListenerNeeded = false;\n }\n\n const relativeX = Number(definitionElement.getAttribute('relativeX'));\n const relativeY = Number(definitionElement.getAttribute('relativeY'));\n\n if (relativeX === termX && relativeY === termY) {\n return;\n }\n\n definitionElement.setAttribute('relativeX', String(termX));\n definitionElement.setAttribute('relativeY', String(termY));\n\n const offsetTop = termHeight + 5;\n const definitionParent = definitionElement.parentElement;\n\n if (!definitionParent) {\n return;\n }\n\n const {width: definitionWidth} = definitionElement.getBoundingClientRect();\n const {left: definitionParentLeft} = definitionParent.getBoundingClientRect();\n\n // If definition not fit document change base alignment\n const definitionLeftCoordinate = Number(getCoords(termElement).left);\n const definitionRightCoordinate = definitionWidth + definitionLeftCoordinate;\n\n const definitionOutOfScreenOnLeft = definitionLeftCoordinate - definitionWidth < 0;\n const definitionOutOfScreenOnRight = definitionRightCoordinate > document.body.clientWidth;\n\n const isAlignSwapped = definitionOutOfScreenOnRight || document.dir === 'rtl';\n const fitDefinitionDocument =\n isAlignSwapped && !definitionOutOfScreenOnLeft ? definitionWidth - termWidth : 0;\n const customHeaderTop = getCoords(definitionParent).top - definitionParent.offsetTop;\n const offsetRight = 5;\n const shiftLeft = definitionOutOfScreenOnRight\n ? definitionRightCoordinate - document.body.clientWidth + offsetRight\n : 0;\n const offsetLeft =\n getCoords(termElement).left -\n definitionParentLeft +\n definitionParent.offsetLeft -\n fitDefinitionDocument;\n\n const isShiftLeftNeeded = offsetLeft + definitionWidth >= document.body.clientWidth;\n\n definitionElement.style.top =\n Number(getCoords(termElement).top + offsetTop - customHeaderTop) + 'px';\n definitionElement.style.left = Number(offsetLeft - (isShiftLeftNeeded ? shiftLeft : 0)) + 'px';\n}\n\nfunction termOnResize() {\n const openedDefinition = document.getElementsByClassName(openDefinitionClass)[0] as HTMLElement;\n\n if (!openedDefinition) {\n return;\n }\n const termId = openedDefinition.getAttribute('term-id') || '';\n const termElement = document.getElementById(termId);\n\n if (!termElement) {\n return;\n }\n\n setDefinitionPosition(openedDefinition, termElement);\n}\n\nfunction termParentElement(term: HTMLElement | null) {\n if (!term) {\n return null;\n }\n\n const closestScrollableParent = term.closest('table') || term.closest('code');\n\n return closestScrollableParent || term.parentElement;\n}\n\nexport function openDefinition(target: HTMLElement) {\n const openedDefinition = document.getElementsByClassName(openDefinitionClass)[0] as HTMLElement;\n\n const termId = target.getAttribute('id');\n const termKey = target.getAttribute('term-key');\n const definitionElement = document.getElementById(termKey + '_element');\n\n const isSameTerm = openedDefinition && termId === openedDefinition.getAttribute('term-id');\n if (isSameTerm) {\n closeDefinition(openedDefinition);\n return;\n }\n\n const isTargetDefinitionContent = target.closest(\n [Selector.CONTENT.replace(' ', ''), openClass].join('.'),\n );\n\n if (openedDefinition && !isTargetDefinitionContent) {\n closeDefinition(openedDefinition);\n }\n\n if (!target.matches(Selector.TITLE) || !definitionElement) {\n return;\n }\n\n setDefinitionId(definitionElement, target);\n setDefinitonAriaAttributes(definitionElement, target);\n setDefinitionPosition(definitionElement, target);\n\n definitionElement.classList.toggle(openClass);\n\n trapFocus(definitionElement);\n}\n\nexport function closeDefinition(definition: HTMLElement) {\n definition.classList.remove(openClass);\n const term = getTermByDefinition(definition);\n const termParent = termParentElement(term);\n\n if (!termParent) {\n return;\n }\n\n termParent.removeEventListener('scroll', termOnResize);\n isListenerNeeded = true;\n}\n\nfunction getCoords(elem: HTMLElement) {\n const box = elem.getBoundingClientRect();\n\n const body = document.body;\n const docEl = document.documentElement;\n\n const scrollTop = window.pageYOffset || docEl.scrollTop || body.scrollTop;\n const scrollLeft = window.pageXOffset || docEl.scrollLeft || body.scrollLeft;\n\n const clientTop = docEl.clientTop || body.clientTop || 0;\n const clientLeft = docEl.clientLeft || body.clientLeft || 0;\n\n const top = box.top + scrollTop - clientTop;\n const left = box.left + scrollLeft - clientLeft;\n\n return {top: Math.round(top), left: Math.round(left)};\n}\n\nexport function trapFocus(element: HTMLElement) {\n const focusableElements = element.querySelectorAll(\n 'button, [href], input, select, textarea, [tabindex]:not([tabindex=\"-1\"])',\n );\n const firstFocusableElement = focusableElements[0] as HTMLElement;\n const lastFocusableElement = focusableElements[focusableElements.length - 1] as HTMLElement;\n\n if (firstFocusableElement) {\n firstFocusableElement.focus();\n }\n\n element.addEventListener('keydown', function (e) {\n const isTabPressed = e.key === 'Tab' || e.keyCode === 9;\n if (!isTabPressed) {\n return;\n }\n\n if (e.shiftKey) {\n if (document.activeElement === firstFocusableElement) {\n lastFocusableElement.focus();\n e.preventDefault();\n }\n } else if (document.activeElement === lastFocusableElement) {\n firstFocusableElement.focus();\n e.preventDefault();\n }\n });\n}\n\nexport function getTermByDefinition(definition: HTMLElement) {\n const termId = definition.getAttribute('term-id');\n\n return termId ? document.getElementById(termId) : null;\n}\n", "import {getEventTarget, isCustom} from '../utils';\n\nimport {\n closeDefinition,\n getTermByDefinition,\n openClass,\n openDefinition,\n openDefinitionClass,\n setDefinitionPosition,\n} from './utils';\n\nif (typeof document !== 'undefined') {\n document.addEventListener('click', (event) => {\n if (getEventTarget(event) || !isCustom(event)) {\n openDefinition(getEventTarget(event) as HTMLElement);\n }\n });\n\n document.addEventListener('keydown', (event) => {\n const openedDefinition = document.getElementsByClassName(\n openDefinitionClass,\n )[0] as HTMLElement;\n\n if (event.key === 'Enter' && document.activeElement) {\n openDefinition(document.activeElement as HTMLElement);\n }\n\n if (event.key === 'Escape' && openedDefinition) {\n closeDefinition(openedDefinition);\n getTermByDefinition(openedDefinition)?.focus(); // Set focus back to open button after closing popup\n }\n });\n\n window.addEventListener('resize', () => {\n const openedDefinition = document.getElementsByClassName(\n openDefinitionClass,\n )[0] as HTMLElement;\n\n if (!openedDefinition) {\n return;\n }\n\n const termId = openedDefinition.getAttribute('term-id') || '';\n const termElement = document.getElementById(termId);\n\n if (!termElement) {\n openedDefinition.classList.toggle(openClass);\n return;\n }\n\n setDefinitionPosition(openedDefinition, termElement);\n });\n}\n"],
5
5
  "mappings": ";;;AAAO,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EACtD;;;ACtNA,MAAI,OAAO,aAAa,aAAa;AACjC,aAAS,iBAAiB,SAAS,CAAC,UAAU;AAC1C,UAAI,eAAe,KAAK,KAAK,CAAC,SAAS,KAAK,GAAG;AAC3C,uBAAe,eAAe,KAAK,CAAgB;AAAA,MACvD;AAAA,IACJ,CAAC;AAED,aAAS,iBAAiB,WAAW,CAAC,UAAU;AAlBpD;AAmBQ,YAAM,mBAAmB,SAAS;AAAA,QAC9B;AAAA,MACJ,EAAE,CAAC;AAEH,UAAI,MAAM,QAAQ,WAAW,SAAS,eAAe;AACjD,uBAAe,SAAS,aAA4B;AAAA,MACxD;AAEA,UAAI,MAAM,QAAQ,YAAY,kBAAkB;AAC5C,wBAAgB,gBAAgB;AAChC,kCAAoB,gBAAgB,MAApC,mBAAuC;AAAA,MAC3C;AAAA,IACJ,CAAC;AAED,WAAO,iBAAiB,UAAU,MAAM;AACpC,YAAM,mBAAmB,SAAS;AAAA,QAC9B;AAAA,MACJ,EAAE,CAAC;AAEH,UAAI,CAAC,kBAAkB;AACnB;AAAA,MACJ;AAEA,YAAM,SAAS,iBAAiB,aAAa,SAAS,KAAK;AAC3D,YAAM,cAAc,SAAS,eAAe,MAAM;AAElD,UAAI,CAAC,aAAa;AACd,yBAAiB,UAAU,OAAO,SAAS;AAC3C;AAAA,MACJ;AAEA,4BAAsB,kBAAkB,WAAW;AAAA,IACvD,CAAC;AAAA,EACL;",
6
6
  "names": []
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/js/utils.ts", "../../src/js/term/utils.ts", "../../src/js/term/index.ts"],
4
- "sourcesContent": ["export const getEventTarget = (event: Event) => {\n const path = event.composedPath();\n return Array.isArray(path) && path.length > 0 ? path[0] : event.target;\n};\n\nexport const isCustom = (event: Event) => {\n const target = getEventTarget(event);\n return !target || !(target as HTMLElement).matches;\n};\n", "export const Selector = {\n TITLE: '.yfm .yfm-term_title',\n CONTENT: '.yfm .yfm-term_dfn',\n};\nexport const openClass = 'open';\nexport const openDefinitionClass = Selector.CONTENT.replace(/\\./g, '') + ' ' + openClass;\nlet isListenerNeeded = true;\n\nexport function setDefinitionId(definitionElement: HTMLElement, termElement: HTMLElement): void {\n const termId = termElement.getAttribute('id') || Math.random().toString(36).substr(2, 8);\n definitionElement?.setAttribute('term-id', termId);\n}\n\nexport function setDefinitonAriaAttributes(\n definitionElement: HTMLElement,\n termElement: HTMLElement,\n): void {\n const ariaLive = termElement.getAttribute('aria-live') || 'polite';\n definitionElement?.setAttribute('aria-live', ariaLive);\n definitionElement?.setAttribute('aria-modal', 'true');\n}\n\nexport function setDefinitionPosition(\n definitionElement: HTMLElement,\n termElement: HTMLElement,\n): void {\n const {\n x: termX,\n y: termY,\n right: termRight,\n left: termLeft,\n width: termWidth,\n height: termHeight,\n } = termElement.getBoundingClientRect();\n\n const termParent = termParentElement(termElement);\n\n if (!termParent) {\n return;\n }\n\n const {right: termParentRight, left: termParentLeft} = termParent.getBoundingClientRect();\n\n if ((termParentRight < termLeft || termParentLeft > termRight) && !isListenerNeeded) {\n closeDefinition(definitionElement);\n return;\n }\n\n if (isListenerNeeded && termParent) {\n termParent.addEventListener('scroll', termOnResize);\n isListenerNeeded = false;\n }\n\n const relativeX = Number(definitionElement.getAttribute('relativeX'));\n const relativeY = Number(definitionElement.getAttribute('relativeY'));\n\n if (relativeX === termX && relativeY === termY) {\n return;\n }\n\n definitionElement.setAttribute('relativeX', String(termX));\n definitionElement.setAttribute('relativeY', String(termY));\n\n const offsetTop = termHeight + 5;\n const definitionParent = definitionElement.parentElement;\n\n if (!definitionParent) {\n return;\n }\n\n const {width: definitionWidth} = definitionElement.getBoundingClientRect();\n const {left: definitionParentLeft} = definitionParent.getBoundingClientRect();\n\n // If definition not fit document change base alignment\n const definitionLeftCoordinate = Number(getCoords(termElement).left);\n const definitionRightCoordinate = definitionWidth + definitionLeftCoordinate;\n\n const definitionOutOfScreenOnLeft = definitionLeftCoordinate - definitionWidth < 0;\n const definitionOutOfScreenOnRight = definitionRightCoordinate > document.body.clientWidth;\n\n const isAlignSwapped = definitionOutOfScreenOnRight || document.dir === 'rtl';\n const fitDefinitionDocument =\n isAlignSwapped && !definitionOutOfScreenOnLeft ? definitionWidth - termWidth : 0;\n const customHeaderTop = getCoords(definitionParent).top - definitionParent.offsetTop;\n const offsetRight = 5;\n const shiftLeft = definitionOutOfScreenOnRight\n ? definitionRightCoordinate - document.body.clientWidth + offsetRight\n : 0;\n const offsetLeft =\n getCoords(termElement).left -\n definitionParentLeft +\n definitionParent.offsetLeft -\n fitDefinitionDocument;\n\n const isShiftLeftNeeded = offsetLeft + definitionWidth >= document.body.clientWidth;\n\n definitionElement.style.top =\n Number(getCoords(termElement).top + offsetTop - customHeaderTop) + 'px';\n definitionElement.style.left = Number(offsetLeft - (isShiftLeftNeeded ? shiftLeft : 0)) + 'px';\n}\n\nfunction termOnResize() {\n const openedDefinition = document.getElementsByClassName(openDefinitionClass)[0] as HTMLElement;\n\n if (!openedDefinition) {\n return;\n }\n const termId = openedDefinition.getAttribute('term-id') || '';\n const termElement = document.getElementById(termId);\n\n if (!termElement) {\n return;\n }\n\n setDefinitionPosition(openedDefinition, termElement);\n}\n\nfunction termParentElement(term: HTMLElement | null) {\n if (!term) {\n return null;\n }\n\n const closestScrollableParent = term.closest('table') || term.closest('code');\n\n return closestScrollableParent || term.parentElement;\n}\n\nexport function openDefinition(target: HTMLElement) {\n const openedDefinition = document.getElementsByClassName(openDefinitionClass)[0] as HTMLElement;\n\n const termId = target.getAttribute('id');\n const termKey = target.getAttribute('term-key');\n const definitionElement = document.getElementById(termKey + '_element');\n\n const isSameTerm = openedDefinition && termId === openedDefinition.getAttribute('term-id');\n if (isSameTerm) {\n closeDefinition(openedDefinition);\n return;\n }\n\n const isTargetDefinitionContent = target.closest(\n [Selector.CONTENT.replace(' ', ''), openClass].join('.'),\n );\n\n if (openedDefinition && !isTargetDefinitionContent) {\n closeDefinition(openedDefinition);\n }\n\n if (!target.matches(Selector.TITLE) || !definitionElement) {\n return;\n }\n\n setDefinitionId(definitionElement, target);\n setDefinitonAriaAttributes(definitionElement, target);\n setDefinitionPosition(definitionElement, target);\n\n definitionElement.classList.toggle(openClass);\n\n trapFocus(definitionElement);\n}\n\nexport function closeDefinition(definition: HTMLElement) {\n definition.classList.remove(openClass);\n const term = getTermByDefinition(definition);\n const termParent = termParentElement(term);\n\n if (!termParent) {\n return;\n }\n\n termParent.removeEventListener('scroll', termOnResize);\n isListenerNeeded = true;\n}\n\nfunction getCoords(elem: HTMLElement) {\n const box = elem.getBoundingClientRect();\n\n const body = document.body;\n const docEl = document.documentElement;\n\n const scrollTop = window.pageYOffset || docEl.scrollTop || body.scrollTop;\n const scrollLeft = window.pageXOffset || docEl.scrollLeft || body.scrollLeft;\n\n const clientTop = docEl.clientTop || body.clientTop || 0;\n const clientLeft = docEl.clientLeft || body.clientLeft || 0;\n\n const top = box.top + scrollTop - clientTop;\n const left = box.left + scrollLeft - clientLeft;\n\n return {top: Math.round(top), left: Math.round(left)};\n}\n\nexport function trapFocus(element: HTMLElement) {\n const focusableElements = element.querySelectorAll(\n 'button, [href], input, select, textarea, [tabindex]:not([tabindex=\"-1\"])',\n );\n const firstFocusableElement = focusableElements[0] as HTMLElement;\n const lastFocusableElement = focusableElements[focusableElements.length - 1] as HTMLElement;\n\n if (firstFocusableElement) {\n firstFocusableElement.focus();\n }\n\n element.addEventListener('keydown', function (e) {\n const isTabPressed = e.key === 'Tab' || e.keyCode === 9;\n if (!isTabPressed) {\n return;\n }\n\n if (e.shiftKey) {\n if (document.activeElement === firstFocusableElement) {\n lastFocusableElement.focus();\n e.preventDefault();\n }\n } else if (document.activeElement === lastFocusableElement) {\n firstFocusableElement.focus();\n e.preventDefault();\n }\n });\n}\n\nexport function getTermByDefinition(definition: HTMLElement) {\n const termId = definition.getAttribute('term-id');\n\n return termId ? document.getElementById(termId) : null;\n}\n", "import {getEventTarget, isCustom} from '../utils';\n\nimport {\n closeDefinition,\n getTermByDefinition,\n openClass,\n openDefinition,\n openDefinitionClass,\n setDefinitionPosition,\n} from './utils';\n\nif (typeof document !== 'undefined') {\n document.addEventListener('click', (event) => {\n if (getEventTarget(event) || !isCustom(event)) {\n openDefinition(getEventTarget(event) as HTMLElement);\n }\n });\n\n document.addEventListener('keydown', (event) => {\n const openedDefinition = document.getElementsByClassName(\n openDefinitionClass,\n )[0] as HTMLElement;\n\n if (event.key === 'Enter' && document.activeElement) {\n openDefinition(document.activeElement as HTMLElement);\n }\n\n if (event.key === 'Escape' && openedDefinition) {\n closeDefinition(openedDefinition);\n getTermByDefinition(openedDefinition)?.focus(); // Set focus back to open button after closing popup\n }\n });\n\n window.addEventListener('resize', () => {\n const openedDefinition = document.getElementsByClassName(\n openDefinitionClass,\n )[0] as HTMLElement;\n\n if (!openedDefinition) {\n return;\n }\n\n const termId = openedDefinition.getAttribute('term-id') || '';\n const termElement = document.getElementById(termId);\n\n if (!termElement) {\n openedDefinition.classList.toggle(openClass);\n return;\n }\n\n setDefinitionPosition(openedDefinition, termElement);\n });\n}\n"],
4
+ "sourcesContent": ["export const getEventTarget = (event: Event) => {\n const path = event.composedPath();\n return Array.isArray(path) && path.length > 0 ? path[0] : event.target;\n};\n\nexport const isCustom = (event: Event) => {\n const target = getEventTarget(event);\n return !target || !(target as HTMLElement).matches;\n};\n\nexport const copyToClipboard = async (text: string) => {\n if (!text) {\n return;\n }\n\n if (navigator.clipboard && typeof navigator.clipboard.writeText) {\n return navigator.clipboard.writeText(text);\n }\n\n const textarea = document.createElement('textarea');\n textarea.setAttribute('style', 'position: absolute; left: 1000%');\n textarea.textContent = text;\n document.body.append(textarea);\n\n textarea.select();\n document.execCommand('copy');\n\n document.body.removeChild(textarea);\n};\n", "export const Selector = {\n TITLE: '.yfm .yfm-term_title',\n CONTENT: '.yfm .yfm-term_dfn',\n};\nexport const openClass = 'open';\nexport const openDefinitionClass = Selector.CONTENT.replace(/\\./g, '') + ' ' + openClass;\nlet isListenerNeeded = true;\n\nexport function setDefinitionId(definitionElement: HTMLElement, termElement: HTMLElement): void {\n const termId = termElement.getAttribute('id') || Math.random().toString(36).substr(2, 8);\n definitionElement?.setAttribute('term-id', termId);\n}\n\nexport function setDefinitonAriaAttributes(\n definitionElement: HTMLElement,\n termElement: HTMLElement,\n): void {\n const ariaLive = termElement.getAttribute('aria-live') || 'polite';\n definitionElement?.setAttribute('aria-live', ariaLive);\n definitionElement?.setAttribute('aria-modal', 'true');\n}\n\nexport function setDefinitionPosition(\n definitionElement: HTMLElement,\n termElement: HTMLElement,\n): void {\n const {\n x: termX,\n y: termY,\n right: termRight,\n left: termLeft,\n width: termWidth,\n height: termHeight,\n } = termElement.getBoundingClientRect();\n\n const termParent = termParentElement(termElement);\n\n if (!termParent) {\n return;\n }\n\n const {right: termParentRight, left: termParentLeft} = termParent.getBoundingClientRect();\n\n if ((termParentRight < termLeft || termParentLeft > termRight) && !isListenerNeeded) {\n closeDefinition(definitionElement);\n return;\n }\n\n if (isListenerNeeded && termParent) {\n termParent.addEventListener('scroll', termOnResize);\n isListenerNeeded = false;\n }\n\n const relativeX = Number(definitionElement.getAttribute('relativeX'));\n const relativeY = Number(definitionElement.getAttribute('relativeY'));\n\n if (relativeX === termX && relativeY === termY) {\n return;\n }\n\n definitionElement.setAttribute('relativeX', String(termX));\n definitionElement.setAttribute('relativeY', String(termY));\n\n const offsetTop = termHeight + 5;\n const definitionParent = definitionElement.parentElement;\n\n if (!definitionParent) {\n return;\n }\n\n const {width: definitionWidth} = definitionElement.getBoundingClientRect();\n const {left: definitionParentLeft} = definitionParent.getBoundingClientRect();\n\n // If definition not fit document change base alignment\n const definitionLeftCoordinate = Number(getCoords(termElement).left);\n const definitionRightCoordinate = definitionWidth + definitionLeftCoordinate;\n\n const definitionOutOfScreenOnLeft = definitionLeftCoordinate - definitionWidth < 0;\n const definitionOutOfScreenOnRight = definitionRightCoordinate > document.body.clientWidth;\n\n const isAlignSwapped = definitionOutOfScreenOnRight || document.dir === 'rtl';\n const fitDefinitionDocument =\n isAlignSwapped && !definitionOutOfScreenOnLeft ? definitionWidth - termWidth : 0;\n const customHeaderTop = getCoords(definitionParent).top - definitionParent.offsetTop;\n const offsetRight = 5;\n const shiftLeft = definitionOutOfScreenOnRight\n ? definitionRightCoordinate - document.body.clientWidth + offsetRight\n : 0;\n const offsetLeft =\n getCoords(termElement).left -\n definitionParentLeft +\n definitionParent.offsetLeft -\n fitDefinitionDocument;\n\n const isShiftLeftNeeded = offsetLeft + definitionWidth >= document.body.clientWidth;\n\n definitionElement.style.top =\n Number(getCoords(termElement).top + offsetTop - customHeaderTop) + 'px';\n definitionElement.style.left = Number(offsetLeft - (isShiftLeftNeeded ? shiftLeft : 0)) + 'px';\n}\n\nfunction termOnResize() {\n const openedDefinition = document.getElementsByClassName(openDefinitionClass)[0] as HTMLElement;\n\n if (!openedDefinition) {\n return;\n }\n const termId = openedDefinition.getAttribute('term-id') || '';\n const termElement = document.getElementById(termId);\n\n if (!termElement) {\n return;\n }\n\n setDefinitionPosition(openedDefinition, termElement);\n}\n\nfunction termParentElement(term: HTMLElement | null) {\n if (!term) {\n return null;\n }\n\n const closestScrollableParent = term.closest('table') || term.closest('code');\n\n return closestScrollableParent || term.parentElement;\n}\n\nexport function openDefinition(target: HTMLElement) {\n const openedDefinition = document.getElementsByClassName(openDefinitionClass)[0] as HTMLElement;\n\n const termId = target.getAttribute('id');\n const termKey = target.getAttribute('term-key');\n const definitionElement = document.getElementById(termKey + '_element');\n\n const isSameTerm = openedDefinition && termId === openedDefinition.getAttribute('term-id');\n if (isSameTerm) {\n closeDefinition(openedDefinition);\n return;\n }\n\n const isTargetDefinitionContent = target.closest(\n [Selector.CONTENT.replace(' ', ''), openClass].join('.'),\n );\n\n if (openedDefinition && !isTargetDefinitionContent) {\n closeDefinition(openedDefinition);\n }\n\n if (!target.matches(Selector.TITLE) || !definitionElement) {\n return;\n }\n\n setDefinitionId(definitionElement, target);\n setDefinitonAriaAttributes(definitionElement, target);\n setDefinitionPosition(definitionElement, target);\n\n definitionElement.classList.toggle(openClass);\n\n trapFocus(definitionElement);\n}\n\nexport function closeDefinition(definition: HTMLElement) {\n definition.classList.remove(openClass);\n const term = getTermByDefinition(definition);\n const termParent = termParentElement(term);\n\n if (!termParent) {\n return;\n }\n\n termParent.removeEventListener('scroll', termOnResize);\n isListenerNeeded = true;\n}\n\nfunction getCoords(elem: HTMLElement) {\n const box = elem.getBoundingClientRect();\n\n const body = document.body;\n const docEl = document.documentElement;\n\n const scrollTop = window.pageYOffset || docEl.scrollTop || body.scrollTop;\n const scrollLeft = window.pageXOffset || docEl.scrollLeft || body.scrollLeft;\n\n const clientTop = docEl.clientTop || body.clientTop || 0;\n const clientLeft = docEl.clientLeft || body.clientLeft || 0;\n\n const top = box.top + scrollTop - clientTop;\n const left = box.left + scrollLeft - clientLeft;\n\n return {top: Math.round(top), left: Math.round(left)};\n}\n\nexport function trapFocus(element: HTMLElement) {\n const focusableElements = element.querySelectorAll(\n 'button, [href], input, select, textarea, [tabindex]:not([tabindex=\"-1\"])',\n );\n const firstFocusableElement = focusableElements[0] as HTMLElement;\n const lastFocusableElement = focusableElements[focusableElements.length - 1] as HTMLElement;\n\n if (firstFocusableElement) {\n firstFocusableElement.focus();\n }\n\n element.addEventListener('keydown', function (e) {\n const isTabPressed = e.key === 'Tab' || e.keyCode === 9;\n if (!isTabPressed) {\n return;\n }\n\n if (e.shiftKey) {\n if (document.activeElement === firstFocusableElement) {\n lastFocusableElement.focus();\n e.preventDefault();\n }\n } else if (document.activeElement === lastFocusableElement) {\n firstFocusableElement.focus();\n e.preventDefault();\n }\n });\n}\n\nexport function getTermByDefinition(definition: HTMLElement) {\n const termId = definition.getAttribute('term-id');\n\n return termId ? document.getElementById(termId) : null;\n}\n", "import {getEventTarget, isCustom} from '../utils';\n\nimport {\n closeDefinition,\n getTermByDefinition,\n openClass,\n openDefinition,\n openDefinitionClass,\n setDefinitionPosition,\n} from './utils';\n\nif (typeof document !== 'undefined') {\n document.addEventListener('click', (event) => {\n if (getEventTarget(event) || !isCustom(event)) {\n openDefinition(getEventTarget(event) as HTMLElement);\n }\n });\n\n document.addEventListener('keydown', (event) => {\n const openedDefinition = document.getElementsByClassName(\n openDefinitionClass,\n )[0] as HTMLElement;\n\n if (event.key === 'Enter' && document.activeElement) {\n openDefinition(document.activeElement as HTMLElement);\n }\n\n if (event.key === 'Escape' && openedDefinition) {\n closeDefinition(openedDefinition);\n getTermByDefinition(openedDefinition)?.focus(); // Set focus back to open button after closing popup\n }\n });\n\n window.addEventListener('resize', () => {\n const openedDefinition = document.getElementsByClassName(\n openDefinitionClass,\n )[0] as HTMLElement;\n\n if (!openedDefinition) {\n return;\n }\n\n const termId = openedDefinition.getAttribute('term-id') || '';\n const termElement = document.getElementById(termId);\n\n if (!termElement) {\n openedDefinition.classList.toggle(openClass);\n return;\n }\n\n setDefinitionPosition(openedDefinition, termElement);\n });\n}\n"],
5
5
  "mappings": "yBAAO,IAAMA,EAAkBC,GAAiB,CAC5C,IAAMC,EAAOD,EAAM,aAAa,EAChC,OAAO,MAAM,QAAQC,CAAI,GAAKA,EAAK,OAAS,EAAIA,EAAK,CAAC,EAAID,EAAM,MACpE,EAEaE,EAAYF,GAAiB,CACtC,IAAMG,EAASJ,EAAeC,CAAK,EACnC,MAAO,CAACG,GAAU,CAAEA,EAAuB,OAC/C,ECRaC,EAAW,CACpB,MAAO,uBACP,QAAS,oBACb,EACaC,EAAY,OACZC,EAAsBF,EAAS,QAAQ,QAAQ,MAAO,EAAE,EAAI,IAAMC,EAC3EE,EAAmB,GAEhB,SAASC,EAAgBC,EAAgCC,EAAgC,CAC5F,IAAMC,EAASD,EAAY,aAAa,IAAI,GAAK,KAAK,OAAO,EAAE,SAAS,EAAE,EAAE,OAAO,EAAG,CAAC,EACvFD,GAAA,MAAAA,EAAmB,aAAa,UAAWE,CAAA,CAC/C,CAEO,SAASC,EACZH,EACAC,EACI,CACJ,IAAMG,EAAWH,EAAY,aAAa,WAAW,GAAK,SA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AeA,CAAM,EAAI,IACtD,CCtNI,OAAO,UAAa,cACpB,SAAS,iBAAiB,QAAUX,GAAU,EACtCD,EAAeC,CAAK,GAAK,CAACE,EAASF,CAAK,IACxC6C,EAAe9C,EAAeC,CAAK,CAAgB,CAE3D,CAAC,EAED,SAAS,iBAAiB,UAAYA,GAAU,CAlBpD,IAAAkE,EAmBQ,IAAMvB,EAAmB,SAAS,uBAC9BrC,CACJ,EAAE,CAAC,EAECN,EAAM,MAAQ,SAAW,SAAS,eAClC6C,EAAe,SAAS,aAA4B,EAGpD7C,EAAM,MAAQ,UAAY2C,IAC1BlB,EAAgBkB,CAAgB,GAChCuB,EAAAhB,EAAoBP,CAAgB,IAApC,MAAAuB,EAAuC,MAAA,EAE/C,CAAC,EAED,OAAO,iBAAiB,SAAU,IAAM,CACpC,IAAMvB,EAAmB,SAAS,uBAC9BrC,CACJ,EAAE,CAAC,EAEH,GAAI,CAACqC,EACD,OAGJ,IAAMhC,EAASgC,EAAiB,aAAa,SAAS,GAAK,GACrDjC,EAAc,SAAS,eAAeC,CAAM,EAElD,GAAI,CAACD,EAAa,CACdiC,EAAiB,UAAU,OAAOtC,CAAS,EAC3C,MACJ,CAEAS,EAAsB6B,EAAkBjC,CAAW,CACvD,CAAC",
6
6
  "names": ["getEventTarget", "event", "path", "isCustom", "target", "Selector", "openClass", "openDefinitionClass", "isListenerNeeded", "setDefinitionId", "definitionElement", "termElement", "termId", "setDefinitonAriaAttributes", "ariaLive", "setDefinitionPosition", "termX", "termY", "termRight", "termLeft", "termWidth", "termHeight", "termParent", "termParentElement", "termParentRight", "termParentLeft", "closeDefinition", "termOnResize", "relativeX", "relativeY", "offsetTop", "definitionParent", "definitionWidth", "definitionParentLeft", "definitionLeftCoordinate", "getCoords", "definitionRightCoordinate", "definitionOutOfScreenOnLeft", "definitionOutOfScreenOnRight", "fitDefinitionDocument", "customHeaderTop", "shiftLeft", "offsetLeft", "isShiftLeftNeeded", "openedDefinition", "term", "openDefinition", "termKey", "isTargetDefinitionContent", "trapFocus", "definition", "getTermByDefinition", "elem", "box", "body", "docEl", "scrollTop", "scrollLeft", "clientTop", "clientLeft", "top", "left", "element", "focusableElements", "firstFocusableElement", "lastFocusableElement", "e", "_a"]
7
7
  }
package/dist/js/base.js CHANGED
@@ -25,6 +25,26 @@
25
25
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
26
  mod
27
27
  ));
28
+ var __async = (__this, __arguments, generator) => {
29
+ return new Promise((resolve, reject) => {
30
+ var fulfilled = (value) => {
31
+ try {
32
+ step(generator.next(value));
33
+ } catch (e) {
34
+ reject(e);
35
+ }
36
+ };
37
+ var rejected = (value) => {
38
+ try {
39
+ step(generator.throw(value));
40
+ } catch (e) {
41
+ reject(e);
42
+ }
43
+ };
44
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
45
+ step((generator = generator.apply(__this, __arguments)).next());
46
+ });
47
+ };
28
48
 
29
49
  // node_modules/get-root-node-polyfill/index.js
30
50
  var require_get_root_node_polyfill = __commonJS({
@@ -85,12 +105,9 @@
85
105
  const target = getEventTarget(event);
86
106
  return !target || !target.matches;
87
107
  };
88
-
89
- // src/js/code.ts
90
- var BUTTON_SELECTOR = ".yfm-clipboard-button";
91
- function copyToClipboard(text) {
108
+ var copyToClipboard = (text) => __async(void 0, null, function* () {
92
109
  if (!text) {
93
- return Promise.resolve();
110
+ return;
94
111
  }
95
112
  if (navigator.clipboard && typeof navigator.clipboard.writeText) {
96
113
  return navigator.clipboard.writeText(text);
@@ -102,8 +119,10 @@
102
119
  textarea.select();
103
120
  document.execCommand("copy");
104
121
  document.body.removeChild(textarea);
105
- return Promise.resolve();
106
- }
122
+ });
123
+
124
+ // src/js/code.ts
125
+ var BUTTON_SELECTOR = ".yfm-clipboard-button";
107
126
  function notifySuccess(svgButton) {
108
127
  if (!svgButton) {
109
128
  return;
@@ -140,5 +159,19 @@
140
159
  });
141
160
  });
142
161
  }
162
+
163
+ // src/js/anchor.ts
164
+ var ANCHOR_BUTTON_SELECTOR = ".yfm-clipboard-anchor";
165
+ if (typeof document !== "undefined") {
166
+ document.addEventListener("click", (event) => {
167
+ const target = getEventTarget(event);
168
+ if (isCustom(event) || !target.matches(ANCHOR_BUTTON_SELECTOR)) {
169
+ return;
170
+ }
171
+ const href = target.getAttribute("data-href") || "";
172
+ const link = new URL(href, window.location.href).toString();
173
+ copyToClipboard(link);
174
+ });
175
+ }
143
176
  })();
144
177
  //# sourceMappingURL=base.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../node_modules/get-root-node-polyfill/index.js", "../../src/js/polyfill.js", "../../src/js/utils.ts", "../../src/js/code.ts"],
4
- "sourcesContent": ["'use strict';\n\n// Node getRootNode(optional GetRootNodeOptions options);\n\n/**\n * Returns the context object\u2019s shadow-including root if options\u2019s composed is true.\n * Returns the context object\u2019s root otherwise.\n *\n * The root of an object is itself, if its parent is null, or else it is the root of its parent.\n *\n * The shadow-including root of an object is its root\u2019s host\u2019s shadow-including root,\n * if the object\u2019s root is a shadow root, and its root otherwise.\n *\n * https://dom.spec.whatwg.org/#dom-node-getrootnode\n *\n * @memberof Node.prototype\n * @param {!Object} [opt = {}] - Options.\n * @param {!boolean} [opt.composed] - See above description.\n * @returns {!Node} The root node.\n */\nfunction getRootNode(opt) {\n var composed = typeof opt === 'object' && Boolean(opt.composed);\n\n return composed ? getShadowIncludingRoot(this) : getRoot(this);\n}\n\nfunction getShadowIncludingRoot(node) {\n var root = getRoot(node);\n\n if (isShadowRoot(root)) {\n return getShadowIncludingRoot(root.host);\n }\n\n return root;\n}\n\nfunction getRoot(node) {\n if (node.parentNode != null) {\n return getRoot(node.parentNode);\n }\n\n return node;\n}\n\nfunction isShadowRoot(node) {\n return node.nodeName === '#document-fragment' && node.constructor.name === 'ShadowRoot';\n}\n\nif (typeof module === 'object' && module.exports) {\n module.exports = getRootNode;\n}\n", "import getRootNode from 'get-root-node-polyfill';\n\nif (typeof document !== 'undefined') {\n // matches polyfill for old edge\n (function (e) {\n const matches =\n e.matches ||\n e.matchesSelector ||\n e.webkitMatchesSelector ||\n e.mozMatchesSelector ||\n e.msMatchesSelector ||\n e.oMatchesSelector;\n\n if (matches) {\n e.matches = e.matchesSelector = matches;\n } else {\n e.matches = e.matchesSelector = function matches(selector) {\n const rootNode = e.getRootNode ? e.getRootNode() : getRootNode.call(e);\n const matches = rootNode.querySelectorAll(selector);\n const th = this;\n return Array.prototype.some.call(matches, (e) => {\n return e === th;\n });\n };\n }\n // eslint-disable-next-line no-undef\n })(Element.prototype);\n}\n", "export const getEventTarget = (event: Event) => {\n const path = event.composedPath();\n return Array.isArray(path) && path.length > 0 ? path[0] : event.target;\n};\n\nexport const isCustom = (event: Event) => {\n const target = getEventTarget(event);\n return !target || !(target as HTMLElement).matches;\n};\n", "import {getEventTarget, isCustom} from './utils';\n\nconst BUTTON_SELECTOR = '.yfm-clipboard-button';\n\nfunction copyToClipboard(text: string) {\n if (!text) {\n return Promise.resolve();\n }\n\n if (navigator.clipboard && typeof navigator.clipboard.writeText) {\n return navigator.clipboard.writeText(text);\n }\n const textarea = document.createElement('textarea');\n textarea.setAttribute('style', 'position: absolute; left: 1000%');\n textarea.textContent = text;\n document.body.append(textarea);\n\n textarea.select();\n document.execCommand('copy');\n\n document.body.removeChild(textarea);\n\n return Promise.resolve();\n}\n\nfunction notifySuccess(svgButton: HTMLElement | null) {\n if (!svgButton) {\n return;\n }\n\n const id = svgButton.getAttribute('data-animation');\n // @ts-expect-error\n const icon = svgButton.getRootNode().getElementById(`visibileAnimation-${id}`);\n\n if (!icon) {\n return;\n }\n\n icon.beginElement();\n}\n\nif (typeof document !== 'undefined') {\n document.addEventListener('click', (event) => {\n const target = getEventTarget(event) as HTMLElement;\n\n if (isCustom(event) || !target.matches(BUTTON_SELECTOR)) {\n return;\n }\n\n const parent = target.parentNode;\n\n if (!parent) {\n return;\n }\n\n const code = parent.querySelector<HTMLElement>('pre code');\n if (!code) {\n return;\n }\n\n // Get all text nodes and filter out line numbers\n const textContent = Array.from(code.childNodes)\n .filter((node) => {\n // Skip line number spans\n if (node instanceof HTMLElement && node.classList.contains('yfm-line-number')) {\n return false;\n }\n return true;\n })\n .map((node) => node.textContent)\n .join('');\n\n copyToClipboard(textContent).then(() => {\n notifySuccess(parent.querySelector('.yfm-clipboard-icon'));\n });\n });\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAoBA,eAASA,aAAY,KAAK;AACxB,YAAI,WAAW,OAAO,QAAQ,YAAY,QAAQ,IAAI,QAAQ;AAE9D,eAAO,WAAW,uBAAuB,IAAI,IAAI,QAAQ,IAAI;AAAA,MAC/D;AAEA,eAAS,uBAAuB,MAAM;AACpC,YAAI,OAAO,QAAQ,IAAI;AAEvB,YAAI,aAAa,IAAI,GAAG;AACtB,iBAAO,uBAAuB,KAAK,IAAI;AAAA,QACzC;AAEA,eAAO;AAAA,MACT;AAEA,eAAS,QAAQ,MAAM;AACrB,YAAI,KAAK,cAAc,MAAM;AAC3B,iBAAO,QAAQ,KAAK,UAAU;AAAA,QAChC;AAEA,eAAO;AAAA,MACT;AAEA,eAAS,aAAa,MAAM;AAC1B,eAAO,KAAK,aAAa,wBAAwB,KAAK,YAAY,SAAS;AAAA,MAC7E;AAEA,UAAI,OAAO,WAAW,YAAY,OAAO,SAAS;AAChD,eAAO,UAAUA;AAAA,MACnB;AAAA;AAAA;;;AClDA,sCAAwB;AAExB,MAAI,OAAO,aAAa,aAAa;AAEjC,KAAC,SAAU,GAAG;AACV,YAAM,UACF,EAAE,WACF,EAAE,mBACF,EAAE,yBACF,EAAE,sBACF,EAAE,qBACF,EAAE;AAEN,UAAI,SAAS;AACT,UAAE,UAAU,EAAE,kBAAkB;AAAA,MACpC,OAAO;AACH,UAAE,UAAU,EAAE,kBAAkB,SAASC,SAAQ,UAAU;AACvD,gBAAM,WAAW,EAAE,c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A,MAAI,OAAO,aAAa,aAAa;AACjC,aAAS,iBAAiB,SAAS,CAAC,UAAU;AAC1C,YAAM,SAAS,eAAe,KAAK;AAEnC,UAAI,SAAS,KAAK,KAAK,CAAC,OAAO,QAAQ,eAAe,GAAG;AACrD;AAAA,MACJ;AAEA,YAAM,SAAS,OAAO;AAEtB,UAAI,CAAC,QAAQ;AACT;AAAA,MACJ;AAEA,YAAM,OAAO,OAAO,cAA2B,UAAU;AACzD,UAAI,CAAC,MAAM;AACP;AAAA,MACJ;AAGA,YAAM,cAAc,MAAM,KAAK,KAAK,UAAU,EACzC,OAAO,CAAC,SAAS;AAEd,YAAI,gBAAgB,eAAe,KAAK,UAAU,SAAS,iBAAiB,GAAG;AAC3E,iBAAO;AAAA,QACX;AACA,eAAO;AAAA,MACX,CAAC,EACA,IAAI,CAAC,SAAS,KAAK,WAAW,EAC9B,KAAK,EAAE;AAEZ,sBAAgB,WAAW,EAAE,KAAK,MAAM;AACpC,sBAAc,OAAO,cAAc,qBAAqB,CAAC;AAAA,MAC7D,CAAC;AAAA,IACL,CAAC;AAAA,EACL;",
3
+ "sources": ["../../node_modules/get-root-node-polyfill/index.js", "../../src/js/polyfill.js", "../../src/js/utils.ts", "../../src/js/code.ts", "../../src/js/anchor.ts"],
4
+ "sourcesContent": ["'use strict';\n\n// Node getRootNode(optional GetRootNodeOptions options);\n\n/**\n * Returns the context object\u2019s shadow-including root if options\u2019s composed is true.\n * Returns the context object\u2019s root otherwise.\n *\n * The root of an object is itself, if its parent is null, or else it is the root of its parent.\n *\n * The shadow-including root of an object is its root\u2019s host\u2019s shadow-including root,\n * if the object\u2019s root is a shadow root, and its root otherwise.\n *\n * https://dom.spec.whatwg.org/#dom-node-getrootnode\n *\n * @memberof Node.prototype\n * @param {!Object} [opt = {}] - Options.\n * @param {!boolean} [opt.composed] - See above description.\n * @returns {!Node} The root node.\n */\nfunction getRootNode(opt) {\n var composed = typeof opt === 'object' && Boolean(opt.composed);\n\n return composed ? getShadowIncludingRoot(this) : getRoot(this);\n}\n\nfunction getShadowIncludingRoot(node) {\n var root = getRoot(node);\n\n if (isShadowRoot(root)) {\n return getShadowIncludingRoot(root.host);\n }\n\n return root;\n}\n\nfunction getRoot(node) {\n if (node.parentNode != null) {\n return getRoot(node.parentNode);\n }\n\n return node;\n}\n\nfunction isShadowRoot(node) {\n return node.nodeName === '#document-fragment' && node.constructor.name === 'ShadowRoot';\n}\n\nif (typeof module === 'object' && module.exports) {\n module.exports = getRootNode;\n}\n", "import getRootNode from 'get-root-node-polyfill';\n\nif (typeof document !== 'undefined') {\n // matches polyfill for old edge\n (function (e) {\n const matches =\n e.matches ||\n e.matchesSelector ||\n e.webkitMatchesSelector ||\n e.mozMatchesSelector ||\n e.msMatchesSelector ||\n e.oMatchesSelector;\n\n if (matches) {\n e.matches = e.matchesSelector = matches;\n } else {\n e.matches = e.matchesSelector = function matches(selector) {\n const rootNode = e.getRootNode ? e.getRootNode() : getRootNode.call(e);\n const matches = rootNode.querySelectorAll(selector);\n const th = this;\n return Array.prototype.some.call(matches, (e) => {\n return e === th;\n });\n };\n }\n // eslint-disable-next-line no-undef\n })(Element.prototype);\n}\n", "export const getEventTarget = (event: Event) => {\n const path = event.composedPath();\n return Array.isArray(path) && path.length > 0 ? path[0] : event.target;\n};\n\nexport const isCustom = (event: Event) => {\n const target = getEventTarget(event);\n return !target || !(target as HTMLElement).matches;\n};\n\nexport const copyToClipboard = async (text: string) => {\n if (!text) {\n return;\n }\n\n if (navigator.clipboard && typeof navigator.clipboard.writeText) {\n return navigator.clipboard.writeText(text);\n }\n\n const textarea = document.createElement('textarea');\n textarea.setAttribute('style', 'position: absolute; left: 1000%');\n textarea.textContent = text;\n document.body.append(textarea);\n\n textarea.select();\n document.execCommand('copy');\n\n document.body.removeChild(textarea);\n};\n", "import {copyToClipboard, getEventTarget, isCustom} from './utils';\n\nconst BUTTON_SELECTOR = '.yfm-clipboard-button';\n\nfunction notifySuccess(svgButton: HTMLElement | null) {\n if (!svgButton) {\n return;\n }\n\n const id = svgButton.getAttribute('data-animation');\n // @ts-expect-error\n const icon = svgButton.getRootNode().getElementById(`visibileAnimation-${id}`);\n\n if (!icon) {\n return;\n }\n\n icon.beginElement();\n}\n\nif (typeof document !== 'undefined') {\n document.addEventListener('click', (event) => {\n const target = getEventTarget(event) as HTMLElement;\n\n if (isCustom(event) || !target.matches(BUTTON_SELECTOR)) {\n return;\n }\n\n const parent = target.parentNode;\n\n if (!parent) {\n return;\n }\n\n const code = parent.querySelector<HTMLElement>('pre code');\n if (!code) {\n return;\n }\n\n // Get all text nodes and filter out line numbers\n const textContent = Array.from(code.childNodes)\n .filter((node) => {\n // Skip line number spans\n if (node instanceof HTMLElement && node.classList.contains('yfm-line-number')) {\n return false;\n }\n return true;\n })\n .map((node) => node.textContent)\n .join('');\n\n copyToClipboard(textContent).then(() => {\n notifySuccess(parent.querySelector('.yfm-clipboard-icon'));\n });\n });\n}\n", "import {copyToClipboard, getEventTarget, isCustom} from './utils';\n\nconst ANCHOR_BUTTON_SELECTOR = '.yfm-clipboard-anchor';\n\nif (typeof document !== 'undefined') {\n document.addEventListener('click', (event) => {\n const target = getEventTarget(event) as HTMLElement;\n\n if (isCustom(event) || !target.matches(ANCHOR_BUTTON_SELECTOR)) {\n return;\n }\n\n const href = target.getAttribute('data-href') || '';\n const link = new URL(href, window.location.href).toString();\n\n copyToClipboard(link);\n });\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAoBA,eAASA,aAAY,KAAK;AACxB,YAAI,WAAW,OAAO,QAAQ,YAAY,QAAQ,IAAI,QAAQ;AAE9D,eAAO,WAAW,uBAAuB,IAAI,IAAI,QAAQ,IAAI;AAAA,MAC/D;AAEA,eAAS,uBAAuB,MAAM;AACpC,YAAI,OAAO,QAAQ,IAAI;AAEvB,YAAI,aAAa,IAAI,GAAG;AACtB,iBAAO,uBAAuB,KAAK,IAAI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MAC7D,CAAC;AAAA,IACL,CAAC;AAAA,EACL;;;ACrDA,MAAM,yBAAyB;AAE/B,MAAI,OAAO,aAAa,aAAa;AACjC,aAAS,iBAAiB,SAAS,CAAC,UAAU;AAC1C,YAAM,SAAS,eAAe,KAAK;AAEnC,UAAI,SAAS,KAAK,KAAK,CAAC,OAAO,QAAQ,sBAAsB,GAAG;AAC5D;AAAA,MACJ;AAEA,YAAM,OAAO,OAAO,aAAa,WAAW,KAAK;AACjD,YAAM,OAAO,IAAI,IAAI,MAAM,OAAO,SAAS,IAAI,EAAE,SAAS;AAE1D,sBAAgB,IAAI;AAAA,IACxB,CAAC;AAAA,EACL;",
6
6
  "names": ["getRootNode", "matches", "getRootNode", "e"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";(()=>{(()=>{var p=Object.create,s=Object.defineProperty,f=Object.getOwnPropertyDescriptor,l=Object.getOwnPropertyNames,d=Object.getPrototypeOf,m=Object.prototype.hasOwnProperty,y=(e,t)=>function(){return t||(0,e[l(e)[0]])((t={exports:{}}).exports,t),t.exports},_=(e,t,o,c)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of l(t))!m.call(e,n)&&n!==o&&s(e,n,{get:()=>t[n],enumerable:!(c=f(t,n))||c.enumerable});return e},h=(e,t,o)=>(o=e!=null?p(d(e)):{},_(t||!e||!e.__esModule?s(o,"default",{value:e,enumerable:!0}):o,e)),b=y({"node_modules/get-root-node-polyfill/index.js"(e,t){"use strict";function o(r){var i=typeof r=="object"&&!!r.composed;return i?c(this):n(this)}function c(r){var i=n(r);return a(i)?c(i.host):i}function n(r){return r.parentNode!=null?n(r.parentNode):r}function a(r){return r.nodeName==="#document-fragment"&&r.constructor.name==="ShadowRoot"}typeof t=="object"&&t.exports&&(t.exports=o)}}),g=h(b());typeof document!="undefined"&&function(e){let t=e.matches||e.matchesSelector||e.webkitMatchesSelector||e.mozMatchesSelector||e.msMatchesSelector||e.oMatchesSelector;t?e.matches=e.matchesSelector=t:e.matches=e.matchesSelector=function(c){let a=(e.getRootNode?e.getRootNode():g.default.call(e)).querySelectorAll(c),r=this;return Array.prototype.some.call(a,i=>i===r)}}(Element.prototype);var u=e=>{let t=e.composedPath();return Array.isArray(t)&&t.length>0?t[0]:e.target},v=e=>{let t=u(e);return!t||!t.matches},S=".yfm-clipboard-button";function O(e){if(!e)return Promise.resolve();if(navigator.clipboard&&typeof navigator.clipboard.writeText)return navigator.clipboard.writeText(e);let t=document.createElement("textarea");return t.setAttribute("style","position: absolute; left: 1000%"),t.textContent=e,document.body.append(t),t.select(),document.execCommand("copy"),document.body.removeChild(t),Promise.resolve()}function N(e){if(!e)return;let t=e.getAttribute("data-animation"),o=e.getRootNode().getElementById(`visibileAnimation-${t}`);o&&o.beginElement()}typeof document!="undefined"&&document.addEventListener("click",e=>{let t=u(e);if(v(e)||!t.matches(S))return;let o=t.parentNode;if(!o)return;let c=o.querySelector("pre code");if(!c)return;let n=Array.from(c.childNodes).filter(a=>!(a instanceof HTMLElement&&a.classList.contains("yfm-line-number"))).map(a=>a.textContent).join("");O(n).then(()=>{N(o.querySelector(".yfm-clipboard-icon"))})})})();})();
1
+ "use strict";(()=>{(()=>{var y=Object.create,f=Object.defineProperty,h=Object.getOwnPropertyDescriptor,p=Object.getOwnPropertyNames,_=Object.getPrototypeOf,v=Object.prototype.hasOwnProperty,b=(t,e)=>function(){return e||(0,t[p(t)[0]])((e={exports:{}}).exports,e),e.exports},g=(t,e,o,c)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of p(e))!v.call(t,r)&&r!==o&&f(t,r,{get:()=>e[r],enumerable:!(c=h(e,r))||c.enumerable});return t},O=(t,e,o)=>(o=t!=null?y(_(t)):{},g(e||!t||!t.__esModule?f(o,"default",{value:t,enumerable:!0}):o,t)),S=(t,e,o)=>new Promise((c,r)=>{var i=s=>{try{a(o.next(s))}catch(u){r(u)}},n=s=>{try{a(o.throw(s))}catch(u){r(u)}},a=s=>s.done?c(s.value):Promise.resolve(s.value).then(i,n);a((o=o.apply(t,e)).next())}),w=b({"node_modules/get-root-node-polyfill/index.js"(t,e){"use strict";function o(n){var a=typeof n=="object"&&!!n.composed;return a?c(this):r(this)}function c(n){var a=r(n);return i(a)?c(a.host):a}function r(n){return n.parentNode!=null?r(n.parentNode):n}function i(n){return n.nodeName==="#document-fragment"&&n.constructor.name==="ShadowRoot"}typeof e=="object"&&e.exports&&(e.exports=o)}}),N=O(w());typeof document!="undefined"&&function(t){let e=t.matches||t.matchesSelector||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector||t.oMatchesSelector;e?t.matches=t.matchesSelector=e:t.matches=t.matchesSelector=function(c){let i=(t.getRootNode?t.getRootNode():N.default.call(t)).querySelectorAll(c),n=this;return Array.prototype.some.call(i,a=>a===n)}}(Element.prototype);var l=t=>{let e=t.composedPath();return Array.isArray(e)&&e.length>0?e[0]:t.target},d=t=>{let e=l(t);return!e||!e.matches},m=t=>S(void 0,null,function*(){if(!t)return;if(navigator.clipboard&&typeof navigator.clipboard.writeText)return navigator.clipboard.writeText(t);let e=document.createElement("textarea");e.setAttribute("style","position: absolute; left: 1000%"),e.textContent=t,document.body.append(e),e.select(),document.execCommand("copy"),document.body.removeChild(e)}),P=".yfm-clipboard-button";function x(t){if(!t)return;let e=t.getAttribute("data-animation"),o=t.getRootNode().getElementById(`visibileAnimation-${e}`);o&&o.beginElement()}typeof document!="undefined"&&document.addEventListener("click",t=>{let e=l(t);if(d(t)||!e.matches(P))return;let o=e.parentNode;if(!o)return;let c=o.querySelector("pre code");if(!c)return;let r=Array.from(c.childNodes).filter(i=>!(i instanceof HTMLElement&&i.classList.contains("yfm-line-number"))).map(i=>i.textContent).join("");m(r).then(()=>{x(o.querySelector(".yfm-clipboard-icon"))})});var E=".yfm-clipboard-anchor";typeof document!="undefined"&&document.addEventListener("click",t=>{let e=l(t);if(d(t)||!e.matches(E))return;let o=e.getAttribute("data-href")||"",c=new URL(o,window.location.href).toString();m(c)})})();})();
2
2
  //# sourceMappingURL=base.min.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../node_modules/get-root-node-polyfill/index.js", "../../src/js/polyfill.js", "../../src/js/utils.ts", "../../src/js/code.ts"],
4
- "sourcesContent": ["'use strict';\n\n// Node getRootNode(optional GetRootNodeOptions options);\n\n/**\n * Returns the context object\u2019s shadow-including root if options\u2019s composed is true.\n * Returns the context object\u2019s root otherwise.\n *\n * The root of an object is itself, if its parent is null, or else it is the root of its parent.\n *\n * The shadow-including root of an object is its root\u2019s host\u2019s shadow-including root,\n * if the object\u2019s root is a shadow root, and its root otherwise.\n *\n * https://dom.spec.whatwg.org/#dom-node-getrootnode\n *\n * @memberof Node.prototype\n * @param {!Object} [opt = {}] - Options.\n * @param {!boolean} [opt.composed] - See above description.\n * @returns {!Node} The root node.\n */\nfunction getRootNode(opt) {\n var composed = typeof opt === 'object' && Boolean(opt.composed);\n\n return composed ? getShadowIncludingRoot(this) : getRoot(this);\n}\n\nfunction getShadowIncludingRoot(node) {\n var root = getRoot(node);\n\n if (isShadowRoot(root)) {\n return getShadowIncludingRoot(root.host);\n }\n\n return root;\n}\n\nfunction getRoot(node) {\n if (node.parentNode != null) {\n return getRoot(node.parentNode);\n }\n\n return node;\n}\n\nfunction isShadowRoot(node) {\n return node.nodeName === '#document-fragment' && node.constructor.name === 'ShadowRoot';\n}\n\nif (typeof module === 'object' && module.exports) {\n module.exports = getRootNode;\n}\n", "import getRootNode from 'get-root-node-polyfill';\n\nif (typeof document !== 'undefined') {\n // matches polyfill for old edge\n (function (e) {\n const matches =\n e.matches ||\n e.matchesSelector ||\n e.webkitMatchesSelector ||\n e.mozMatchesSelector ||\n e.msMatchesSelector ||\n e.oMatchesSelector;\n\n if (matches) {\n e.matches = e.matchesSelector = matches;\n } else {\n e.matches = e.matchesSelector = function matches(selector) {\n const rootNode = e.getRootNode ? e.getRootNode() : getRootNode.call(e);\n const matches = rootNode.querySelectorAll(selector);\n const th = this;\n return Array.prototype.some.call(matches, (e) => {\n return e === th;\n });\n };\n }\n // eslint-disable-next-line no-undef\n })(Element.prototype);\n}\n", "export const getEventTarget = (event: Event) => {\n const path = event.composedPath();\n return Array.isArray(path) && path.length > 0 ? path[0] : event.target;\n};\n\nexport const isCustom = (event: Event) => {\n const target = getEventTarget(event);\n return !target || !(target as HTMLElement).matches;\n};\n", "import {getEventTarget, isCustom} from './utils';\n\nconst BUTTON_SELECTOR = '.yfm-clipboard-button';\n\nfunction copyToClipboard(text: string) {\n if (!text) {\n return Promise.resolve();\n }\n\n if (navigator.clipboard && typeof navigator.clipboard.writeText) {\n return navigator.clipboard.writeText(text);\n }\n const textarea = document.createElement('textarea');\n textarea.setAttribute('style', 'position: absolute; left: 1000%');\n textarea.textContent = text;\n document.body.append(textarea);\n\n textarea.select();\n document.execCommand('copy');\n\n document.body.removeChild(textarea);\n\n return Promise.resolve();\n}\n\nfunction notifySuccess(svgButton: HTMLElement | null) {\n if (!svgButton) {\n return;\n }\n\n const id = svgButton.getAttribute('data-animation');\n // @ts-expect-error\n const icon = svgButton.getRootNode().getElementById(`visibileAnimation-${id}`);\n\n if (!icon) {\n return;\n }\n\n icon.beginElement();\n}\n\nif (typeof document !== 'undefined') {\n document.addEventListener('click', (event) => {\n const target = getEventTarget(event) as HTMLElement;\n\n if (isCustom(event) || !target.matches(BUTTON_SELECTOR)) {\n return;\n }\n\n const parent = target.parentNode;\n\n if (!parent) {\n return;\n }\n\n const code = parent.querySelector<HTMLElement>('pre code');\n if (!code) {\n return;\n }\n\n // Get all text nodes and filter out line numbers\n const textContent = Array.from(code.childNodes)\n .filter((node) => {\n // Skip line number spans\n if (node instanceof HTMLElement && node.classList.contains('yfm-line-number')) {\n return false;\n }\n return true;\n })\n .map((node) => node.textContent)\n .join('');\n\n copyToClipboard(textContent).then(() => {\n notifySuccess(parent.querySelector('.yfm-clipboard-icon'));\n });\n });\n}\n"],
5
- "mappings": "giBAAAA,EAAAC,EAAA,CAAA,+CAAAC,EAAAC,E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ECNMC,EAAkB,wBAExB,SAASC,EAAgBC,EAAc,CACnC,GAAI,CAACA,EACD,OAAO,QAAQ,QAAQ,EAG3B,GAAI,UAAU,WAAa,OAAO,UAAU,UAAU,UAClD,OAAO,UAAU,UAAU,UAAUA,CAAI,EAE7C,IAAMC,EAAW,SAAS,cAAc,UAAU,EAClD,OAAAA,EAAS,aAAa,QAAS,iCAAiC,EAChEA,EAAS,YAAcD,EACvB,SAAS,KAAK,OAAOC,CAAQ,EAE7BA,EAAS,OAAO,EAChB,SAAS,YAAY,MAAM,EAE3B,SAAS,KAAK,YAAYA,CAAQ,EAE3B,QAAQ,QAAQ,CAC3B,CAEA,SAASC,EAAcC,EAA+B,CAClD,GAAI,CAACA,EACD,OAGJ,IAAMC,EAAKD,EAAU,aAAa,gBAAgB,EAE5CE,EAAOF,EAAU,YAAY,EAAE,eAAe,qBAAqBC,CAAE,EAAE,EAExEC,GAILA,EAAK,aAAa,CACtB,CAEI,OAAO,UAAa,aACpB,SAAS,iBAAiB,QAAUX,GAAU,CAC1C,IAAMG,EAASJ,EAAeC,CAAK,EAEnC,GAAIE,EAASF,CAAK,GAAK,CAACG,EAAO,QAAQC,CAAe,EAClD,OAGJ,IAAMQ,EAAST,EAAO,WAEtB,GAAI,CAACS,EACD,OAGJ,IAAMC,EAAOD,EAAO,cAA2B,UAAU,EACzD,GAAI,CAACC,EACD,OAIJ,IAAMC,EAAc,MAAM,KAAKD,EAAK,UAAU,EACzC,OAAQvB,GAED,EAAAA,aAAgB,aAAeA,EAAK,UAAU,SAAS,iBAAiB,EAI/E,EACA,IAAKA,GAASA,EAAK,WAAW,EAC9B,KAAK,EAAE,EAEZe,EAAgBS,CAAW,EAAE,KAAK,IAAM,CACpCN,EAAcI,EAAO,cAAc,qBAAqB,CAAC,CAC7D,CAAC,CACL,CAAC",
6
- "names": ["require_get_root_node_polyfill", "__commonJS", "exports", "module", "getRootNode", "opt", "composed", "getShadowIncludingRoot", "getRoot", "node", "root", "isShadowRoot", "import_get_root_node_polyfill", "__toESM", "matches", "selector", "th", "e", "getEventTarget", "event", "path", "isCustom", "target", "BUTTON_SELECTOR", "copyToClipboard", "text", "textarea", "notifySuccess", "svgButton", "id", "icon", "parent", "code", "textContent"]
3
+ "sources": ["../../node_modules/get-root-node-polyfill/index.js", "../../src/js/polyfill.js", "../../src/js/utils.ts", "../../src/js/code.ts", "../../src/js/anchor.ts"],
4
+ "sourcesContent": ["'use strict';\n\n// Node getRootNode(optional GetRootNodeOptions options);\n\n/**\n * Returns the context object\u2019s shadow-including root if options\u2019s composed is true.\n * Returns the context object\u2019s root otherwise.\n *\n * The root of an object is itself, if its parent is null, or else it is the root of its parent.\n *\n * The shadow-including root of an object is its root\u2019s host\u2019s shadow-including root,\n * if the object\u2019s root is a shadow root, and its root otherwise.\n *\n * https://dom.spec.whatwg.org/#dom-node-getrootnode\n *\n * @memberof Node.prototype\n * @param {!Object} [opt = {}] - Options.\n * @param {!boolean} [opt.composed] - See above description.\n * @returns {!Node} The root node.\n */\nfunction getRootNode(opt) {\n var composed = typeof opt === 'object' && Boolean(opt.composed);\n\n return composed ? getShadowIncludingRoot(this) : getRoot(this);\n}\n\nfunction getShadowIncludingRoot(node) {\n var root = getRoot(node);\n\n if (isShadowRoot(root)) {\n return getShadowIncludingRoot(root.host);\n }\n\n return root;\n}\n\nfunction getRoot(node) {\n if (node.parentNode != null) {\n return getRoot(node.parentNode);\n }\n\n return node;\n}\n\nfunction isShadowRoot(node) {\n return node.nodeName === '#document-fragment' && node.constructor.name === 'ShadowRoot';\n}\n\nif (typeof module === 'object' && module.exports) {\n module.exports = getRootNode;\n}\n", "import getRootNode from 'get-root-node-polyfill';\n\nif (typeof document !== 'undefined') {\n // matches polyfill for old edge\n (function (e) {\n const matches =\n e.matches ||\n e.matchesSelector ||\n e.webkitMatchesSelector ||\n e.mozMatchesSelector ||\n e.msMatchesSelector ||\n e.oMatchesSelector;\n\n if (matches) {\n e.matches = e.matchesSelector = matches;\n } else {\n e.matches = e.matchesSelector = function matches(selector) {\n const rootNode = e.getRootNode ? e.getRootNode() : getRootNode.call(e);\n const matches = rootNode.querySelectorAll(selector);\n const th = this;\n return Array.prototype.some.call(matches, (e) => {\n return e === th;\n });\n };\n }\n // eslint-disable-next-line no-undef\n })(Element.prototype);\n}\n", "export const getEventTarget = (event: Event) => {\n const path = event.composedPath();\n return Array.isArray(path) && path.length > 0 ? path[0] : event.target;\n};\n\nexport const isCustom = (event: Event) => {\n const target = getEventTarget(event);\n return !target || !(target as HTMLElement).matches;\n};\n\nexport const copyToClipboard = async (text: string) => {\n if (!text) {\n return;\n }\n\n if (navigator.clipboard && typeof navigator.clipboard.writeText) {\n return navigator.clipboard.writeText(text);\n }\n\n const textarea = document.createElement('textarea');\n textarea.setAttribute('style', 'position: absolute; left: 1000%');\n textarea.textContent = text;\n document.body.append(textarea);\n\n textarea.select();\n document.execCommand('copy');\n\n document.body.removeChild(textarea);\n};\n", "import {copyToClipboard, getEventTarget, isCustom} from './utils';\n\nconst BUTTON_SELECTOR = '.yfm-clipboard-button';\n\nfunction notifySuccess(svgButton: HTMLElement | null) {\n if (!svgButton) {\n return;\n }\n\n const id = svgButton.getAttribute('data-animation');\n // @ts-expect-error\n const icon = svgButton.getRootNode().getElementById(`visibileAnimation-${id}`);\n\n if (!icon) {\n return;\n }\n\n icon.beginElement();\n}\n\nif (typeof document !== 'undefined') {\n document.addEventListener('click', (event) => {\n const target = getEventTarget(event) as HTMLElement;\n\n if (isCustom(event) || !target.matches(BUTTON_SELECTOR)) {\n return;\n }\n\n const parent = target.parentNode;\n\n if (!parent) {\n return;\n }\n\n const code = parent.querySelector<HTMLElement>('pre code');\n if (!code) {\n return;\n }\n\n // Get all text nodes and filter out line numbers\n const textContent = Array.from(code.childNodes)\n .filter((node) => {\n // Skip line number spans\n if (node instanceof HTMLElement && node.classList.contains('yfm-line-number')) {\n return false;\n }\n return true;\n })\n .map((node) => node.textContent)\n .join('');\n\n copyToClipboard(textContent).then(() => {\n notifySuccess(parent.querySelector('.yfm-clipboard-icon'));\n });\n });\n}\n", "import {copyToClipboard, getEventTarget, isCustom} from './utils';\n\nconst ANCHOR_BUTTON_SELECTOR = '.yfm-clipboard-anchor';\n\nif (typeof document !== 'undefined') {\n document.addEventListener('click', (event) => {\n const target = getEventTarget(event) as HTMLElement;\n\n if (isCustom(event) || !target.matches(ANCHOR_BUTTON_SELECTOR)) {\n return;\n }\n\n const href = target.getAttribute('data-href') || '';\n const link = new URL(href, window.location.href).toString();\n\n copyToClipboard(link);\n });\n}\n"],
5
+ "mappings": "yuBAAAA,EAAAC,EAAA,CAAA,+CAAAC,EAAAC,EAAA,CAAA,aAoBA,SAASC,EAAYC,EAAK,CACxB,IAAIC,EAAW,OAAOD,GAAQ,UAAY,EAAQA,EAAI,SAEtD,OAAOC,EAAWC,EAAuB,IAAI,EAAIC,EAAQ,IAAI,CAC/D,CAEA,SAASD,EAAuBE,EAAM,CACpC,IAAIC,EAAOF,EAAQC,CAAI,EAEvB,OAAIE,EAAaD,CAAI,EACZH,EAAuBG,EAAK,IAAI,EAGlCA,CACT,CAEA,SAASF,EAAQC,EAAM,CACrB,OAAIA,EAAK,YAAc,KACdD,EAAQC,EAAK,UAAU,EAGzBA,CACT,CAEA,SAASE,EAAaF,EAAM,CAC1B,OAAOA,EAAK,WAAa,sBAAwBA,EAAK,YAAY,OAAS,YAC7E,CAEI,OAAON,GAAW,UAAYA,EAAO,UACvCA,EAAO,QAAUC,EACnB,CAAA,CAAA,EClDAQ,EAAwBC,EAAAb,EAAA,CAAA,EAEpB,OAAO,UAAa,aAEnB,SAAUc,EAAG,CACV,IAAMC,EACFD,EAAE,SACFA,EAAE,iBACFA,EAAE,uBACFA,EAAE,oBACFA,EAAE,mBACFA,EAAE,iBAEFC,EACAD,EAAE,QAAUA,EAAE,gBAAkBC,EAEhCD,EAAE,QAAUA,EAAE,gBAAkB,SAAiBE,EAAU,CAEvD,IAAMD,GADWD,EAAE,YAAcA,EAAE,YAAY,EAAIF,E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,CAACC,EACD,OAIJ,IAAMC,EAAc,MAAM,KAAKD,EAAK,UAAU,EACzC,OAAQxB,GAED,EAAAA,aAAgB,aAAeA,EAAK,UAAU,SAAS,iBAAiB,EAI/E,EACA,IAAKA,GAASA,EAAK,WAAW,EAC9B,KAAK,EAAE,EAEZc,EAAgBW,CAAW,EAAE,KAAK,IAAM,CACpCN,EAAcI,EAAO,cAAc,qBAAqB,CAAC,CAC7D,CAAC,CACL,CAAC,ECpDL,IAAMG,EAAyB,wBAE3B,OAAO,UAAa,aACpB,SAAS,iBAAiB,QAAUhB,GAAU,CAC1C,IAAMG,EAASJ,EAAeC,CAAK,EAEnC,GAAIE,EAASF,CAAK,GAAK,CAACG,EAAO,QAAQa,CAAsB,EACzD,OAGJ,IAAMC,EAAOd,EAAO,aAAa,WAAW,GAAK,GAC3Ce,EAAO,IAAI,IAAID,EAAM,OAAO,SAAS,IAAI,EAAE,SAAS,EAE1Db,EAAgBc,CAAI,CACxB,CAAC",
6
+ "names": ["require_get_root_node_polyfill", "__commonJS", "exports", "module", "getRootNode", "opt", "composed", "getShadowIncludingRoot", "getRoot", "node", "root", "isShadowRoot", "import_get_root_node_polyfill", "__toESM", "e", "matches", "selector", "th", "getEventTarget", "event", "path", "isCustom", "target", "copyToClipboard", "text", "__async", "textarea", "BUTTON_SELECTOR", "notifySuccess", "svgButton", "id", "icon", "parent", "code", "textContent", "ANCHOR_BUTTON_SELECTOR", "href", "link"]
7
7
  }
package/dist/js/yfm.js CHANGED
@@ -40,6 +40,26 @@
40
40
  mod
41
41
  ));
42
42
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
43
+ var __async = (__this, __arguments, generator) => {
44
+ return new Promise((resolve, reject) => {
45
+ var fulfilled = (value) => {
46
+ try {
47
+ step(generator.next(value));
48
+ } catch (e) {
49
+ reject(e);
50
+ }
51
+ };
52
+ var rejected = (value) => {
53
+ try {
54
+ step(generator.throw(value));
55
+ } catch (e) {
56
+ reject(e);
57
+ }
58
+ };
59
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
60
+ step((generator = generator.apply(__this, __arguments)).next());
61
+ });
62
+ };
43
63
 
44
64
  // node_modules/get-root-node-polyfill/index.js
45
65
  var require_get_root_node_polyfill = __commonJS({
@@ -435,12 +455,9 @@
435
455
  const target = getEventTarget(event);
436
456
  return !target || !target.matches;
437
457
  };
438
-
439
- // src/js/code.ts
440
- var BUTTON_SELECTOR = ".yfm-clipboard-button";
441
- function copyToClipboard(text) {
458
+ var copyToClipboard = (text) => __async(void 0, null, function* () {
442
459
  if (!text) {
443
- return Promise.resolve();
460
+ return;
444
461
  }
445
462
  if (navigator.clipboard && typeof navigator.clipboard.writeText) {
446
463
  return navigator.clipboard.writeText(text);
@@ -452,8 +469,10 @@
452
469
  textarea.select();
453
470
  document.execCommand("copy");
454
471
  document.body.removeChild(textarea);
455
- return Promise.resolve();
456
- }
472
+ });
473
+
474
+ // src/js/code.ts
475
+ var BUTTON_SELECTOR = ".yfm-clipboard-button";
457
476
  function notifySuccess(svgButton) {
458
477
  if (!svgButton) {
459
478
  return;
@@ -491,6 +510,20 @@
491
510
  });
492
511
  }
493
512
 
513
+ // src/js/anchor.ts
514
+ var ANCHOR_BUTTON_SELECTOR = ".yfm-clipboard-anchor";
515
+ if (typeof document !== "undefined") {
516
+ document.addEventListener("click", (event) => {
517
+ const target = getEventTarget(event);
518
+ if (isCustom(event) || !target.matches(ANCHOR_BUTTON_SELECTOR)) {
519
+ return;
520
+ }
521
+ const href = target.getAttribute("data-href") || "";
522
+ const link = new URL(href, window.location.href).toString();
523
+ copyToClipboard(link);
524
+ });
525
+ }
526
+
494
527
  // src/js/term/utils.ts
495
528
  var Selector = {
496
529
  TITLE: ".yfm .yfm-term_title",