1 Star 0 Fork 34

堪培拉的风/outline.js

forked from Yaohaixiao/outline.js 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
anchors.min.js 23.94 KB
一键复制 编辑 原始数据 按行查看 历史
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).Anchors=e()}(this,(function(){"use strict";const t=t=>"string"==typeof t,e=t=>Object.prototype.toString.apply(t),n=t=>"function"==typeof t||"[object Function]"===e(t),r=t=>("[object Object]"===e(t)||"object"==typeof t||n(t))&&null!==t,i=t=>!!(r(t)&&t.nodeName&&t.tagName&&1===t.nodeType),s=t=>Array.isArray?Array.isArray(t):"[object Array]"===e(t),o=t=>{let e={};return null===t?null:(s(t)?e=Array.from(t):(e=Object.assign({},t),Object.keys(e).forEach((n=>e[n]=r(t[n])?o(t[n]):t[n]))),e)},l=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:300;return!!n(t)&&setTimeout((()=>{t()}),e)},c=[];let a,h;function u(t){for(;t.timeRemaining()>0&&c.length;){const t=c.shift();if(!n(t))return!1;t()}c.length?a=requestIdleCallback(u):(a=0,n(h)&&(h(),h=null))}void 0===window.requestIdleCallback&&(window.requestIdleCallback=function(t){const e=Date.now();return l((function(){t({didTimeout:!1,timeRemaining:function(){return Math.max(0,50-(Date.now()-e))}})}),10)},window.cancelIdleCallback=function(t){clearTimeout(t)});const d=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;c.push(t),n(e)&&(h=e),a||requestIdleCallback(u)},p=t=>t*t,m=function(){let e,n,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;return r?t(r)?n=document.querySelector(r):i(r)&&(n=r):(e=document.querySelectorAll("html,body"),n=e[0].scrollTop-e[1].scrollTop>=0?e[0]:e[1]),n},f=t=>{let e=t.offsetTop;return null!==t.offsetParent&&(e+=f(t.offsetParent)),e},g=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";const n=e.replace(/^>/i,"");return!!(e&&n&&t)&&(t.matches?t.matches(n):!!t.msMatchesSelector&&t.msMatchesSelector(n))},y=t=>t.host&&t!==document&&t.host.nodeType?t.host:t.parentNode,v=["focusout","blur","focusin","focus","load","unload","mouseenter","mouseleave"],b=(t,e,n)=>{const r=v.indexOf(e)>-1;n._delegateListener&&delete(n=n._delegateListener)._delegateListener,function(t,e,n){const r=t._listeners;let i=-1;if(r.length<1)return!1;r.forEach(((t,r)=>{const s=t.fn;e===t.type&&(i=r,s===n&&(i=r))})),i>-1&&r.splice(i,1)}(t,e,n),t.removeEventListener(e,n,r)},z=function(e,n){let r=arguments.length>2&&void 0!==arguments[2]&&arguments[2];const s=t(e)?document.querySelector(e):e,o=s.childNodes,l=((e,n)=>{let r=e._listeners||[];return t(n)&&n&&(r=r.filter((t=>t.type===n))),r})(s,n);l.forEach((t=>{b(s,t.type,t.fn)})),(r||!0===n||1===arguments.length)&&s&&o&&o.forEach((t=>{i(t)&&z(t,n,r)}))},x=(t,e,r)=>{if(!n(r))return z(t,e);b(t,e,r)},M=function(t,e,n,r,i,s){let o=arguments.length>6&&void 0!==arguments[6]&&arguments[6];const l=v.indexOf(n)>-1,c=function(l){const a=function(t){const e=t.target;return(n=e)&&3===n.nodeType?n.parentNode:n;var n}(l),h=((t,e,n,r)=>{const i=n||document;if(!t)return null;do{if(null!=e&&(e.startsWith(">")?t.parentNode===i&&g(t,e):g(t,e))||r&&t===i)return t;if(t===i)break}while(t=y(t))})(a,e,t);let u=s||t;l.delegateTarget=h,!0===s&&(u=i),h&&(!0===o&&x(t,n,c),r.call(u,l,i))};t._listeners||(t._listeners=[]),t._listeners.push({el:t,selector:e,type:n,fn:c,data:i,context:s,capture:l}),r._delegateListener=c,t.addEventListener(n,c,l)},$=['<symbol id="outline-icon-up" viewBox="0 0 1024 1024"><path d="M494.784 261.696c0.832-0.448 1.536-1.216 2.368-1.536a38.72 38.72 0 0 1 46.08 8.256l277.824 302.272a41.92 41.92 0 0 1-1.536 58.048 39.104 39.104 0 0 1-56.448-1.6L513.728 355.904 260.736 626.048a39.104 39.104 0 0 1-56.448 1.088 41.6 41.6 0 0 1-1.088-57.984L483.84 269.696c0.512-0.512 1.344-0.768 1.92-1.408l1.088-1.344c2.368-2.496 5.312-3.648 8-5.248z"></path></symbol>','<symbol id="outline-icon-down" viewBox="0 0 1024 1024"><path d="M494.784 762.304c0.832 0.448 1.536 1.216 2.368 1.536 15.232 7.488 33.92 4.992 46.08-8.256l277.824-302.272a41.92 41.92 0 0 0-1.536-58.048 39.104 39.104 0 0 0-56.448 1.6l-249.344 271.232-252.992-270.144a39.104 39.104 0 0 0-56.448-1.088 41.6 41.6 0 0 0-1.088 57.984l280.576 299.456c0.512 0.512 1.344 0.768 1.92 1.408l1.088 1.344c2.368 2.496 5.312 3.648 8 5.248z"></path></symbol>','<symbol id="outline-icon-menu" viewBox="0 0 1024 1024"><path d="M320 256h640V128H320zM320 576h640V448H320zM320 896h640v-128H320zM64 256h128V128H64zM64 576h128V448H64zM64 896h128v-128H64z"></path></symbol>','<symbol id="outline-icon-file" viewBox="0 0 1024 1024"><path d="M320 640h256v128H320z"></path><path d="M320 448h384v128H320z"></path><path d="M640 0l320 320v557.696C960 958.528 909.824 1024 848 1024H176C114.176 1024 64 958.528 64 877.696V146.304C64 65.472 114.176 0 176 0H640z m0 128H192v768h640V320h-192V128z"></path></symbol>','<symbol id="outline-icon-hash" viewBox="0 0 24 24"><path d="M14.216 10l-0.444 4h-3.988l0.444-4zM15.006 2.89l-0.568 5.11h-3.988l0.543-4.89c0.061-0.549-0.335-1.043-0.883-1.104s-1.043 0.335-1.104 0.884l-0.568 5.11h-4.438c-0.552 0-1 0.448-1 1s0.448 1 1 1h4.216l-0.444 4h-3.772c-0.552 0-1 0.448-1 1s0.448 1 1 1h3.549l-0.543 4.89c-0.061 0.549 0.335 1.043 0.883 1.104s1.043-0.335 1.104-0.883l0.569-5.111h3.988l-0.543 4.89c-0.061 0.549 0.335 1.043 0.883 1.104s1.043-0.335 1.104-0.883l0.568-5.111h4.438c0.552 0 1-0.448 1-1s-0.448-1-1-1h-4.216l0.444-4h3.772c0.552 0 1-0.448 1-1s-0.448-1-1-1h-3.549l0.543-4.89c0.061-0.549-0.335-1.043-0.883-1.104s-1.043 0.335-1.104 0.883z"></path></symbol>','<symbol id="outline-icon-close" viewBox="0 0 1024 1024"><path d="M536.96 491.648L310.592 265.344a32 32 0 1 0-45.248 45.248L491.584 536.96l-226.304 226.304a32 32 0 0 0 45.312 45.248l226.24-226.304 226.304 226.304a32 32 0 0 0 45.248-45.248L582.144 536.896l226.304-226.24a32 32 0 0 0-45.248-45.248L536.896 491.584z"></path></symbol>','<symbol id="outline-icon-homepage" viewBox="0 0 26 28"><path d="M22 15.5v7.5c0 0.547-0.453 1-1 1h-6v-6h-4v6h-6c-0.547 0-1-0.453-1-1v-7.5c0-0.031 0.016-0.063 0.016-0.094l8.984-7.406 8.984 7.406c0.016 0.031 0.016 0.063 0.016 0.094zM25.484 14.422l-0.969 1.156c-0.078 0.094-0.203 0.156-0.328 0.172h-0.047c-0.125 0-0.234-0.031-0.328-0.109l-10.813-9.016-10.813 9.016c-0.109 0.078-0.234 0.125-0.375 0.109-0.125-0.016-0.25-0.078-0.328-0.172l-0.969-1.156c-0.172-0.203-0.141-0.531 0.063-0.703l11.234-9.359c0.656-0.547 1.719-0.547 2.375 0l3.813 3.187v-3.047c0-0.281 0.219-0.5 0.5-0.5h3c0.281 0 0.5 0.219 0.5 0.5v6.375l3.422 2.844c0.203 0.172 0.234 0.5 0.063 0.703z"></path></symbol>','<symbol id="outline-icon-github" viewBox="0 0 24 28"><path d="M12 2c6.625 0 12 5.375 12 12 0 5.297-3.437 9.797-8.203 11.391-0.609 0.109-0.828-0.266-0.828-0.578 0-0.391 0.016-1.687 0.016-3.297 0-1.125-0.375-1.844-0.812-2.219 2.672-0.297 5.484-1.313 5.484-5.922 0-1.313-0.469-2.375-1.234-3.219 0.125-0.313 0.531-1.531-0.125-3.187-1-0.313-3.297 1.234-3.297 1.234-0.953-0.266-1.984-0.406-3-0.406s-2.047 0.141-3 0.406c0 0-2.297-1.547-3.297-1.234-0.656 1.656-0.25 2.875-0.125 3.187-0.766 0.844-1.234 1.906-1.234 3.219 0 4.594 2.797 5.625 5.469 5.922-0.344 0.313-0.656 0.844-0.766 1.609-0.688 0.313-2.438 0.844-3.484-1-0.656-1.141-1.844-1.234-1.844-1.234-1.172-0.016-0.078 0.734-0.078 0.734 0.781 0.359 1.328 1.75 1.328 1.75 0.703 2.141 4.047 1.422 4.047 1.422 0 1 0.016 1.937 0.016 2.234 0 0.313-0.219 0.688-0.828 0.578-4.766-1.594-8.203-6.094-8.203-11.391 0-6.625 5.375-12 12-12zM4.547 19.234c0.031-0.063-0.016-0.141-0.109-0.187-0.094-0.031-0.172-0.016-0.203 0.031-0.031 0.063 0.016 0.141 0.109 0.187 0.078 0.047 0.172 0.031 0.203-0.031zM5.031 19.766c0.063-0.047 0.047-0.156-0.031-0.25-0.078-0.078-0.187-0.109-0.25-0.047-0.063 0.047-0.047 0.156 0.031 0.25 0.078 0.078 0.187 0.109 0.25 0.047zM5.5 20.469c0.078-0.063 0.078-0.187 0-0.297-0.063-0.109-0.187-0.156-0.266-0.094-0.078 0.047-0.078 0.172 0 0.281s0.203 0.156 0.266 0.109zM6.156 21.125c0.063-0.063 0.031-0.203-0.063-0.297-0.109-0.109-0.25-0.125-0.313-0.047-0.078 0.063-0.047 0.203 0.063 0.297 0.109 0.109 0.25 0.125 0.313 0.047zM7.047 21.516c0.031-0.094-0.063-0.203-0.203-0.25-0.125-0.031-0.266 0.016-0.297 0.109s0.063 0.203 0.203 0.234c0.125 0.047 0.266 0 0.297-0.094zM8.031 21.594c0-0.109-0.125-0.187-0.266-0.172-0.141 0-0.25 0.078-0.25 0.172 0 0.109 0.109 0.187 0.266 0.172 0.141 0 0.25-0.078 0.25-0.172zM8.937 21.438c-0.016-0.094-0.141-0.156-0.281-0.141-0.141 0.031-0.234 0.125-0.219 0.234 0.016 0.094 0.141 0.156 0.281 0.125s0.234-0.125 0.219-0.219z"></path></symbol>','<symbol id="outline-icon-issues" viewBox="0 0 24 28"><path d="M25.5 15c0 0.547-0.453 1-1 1h-3.5c0 1.953-0.422 3.422-1.047 4.531l3.25 3.266c0.391 0.391 0.391 1.016 0 1.406-0.187 0.203-0.453 0.297-0.703 0.297s-0.516-0.094-0.703-0.297l-3.094-3.078s-2.047 1.875-4.703 1.875v-14h-2v14c-2.828 0-4.891-2.063-4.891-2.063l-2.859 3.234c-0.203 0.219-0.469 0.328-0.75 0.328-0.234 0-0.469-0.078-0.672-0.25-0.406-0.375-0.438-1-0.078-1.422l3.156-3.547c-0.547-1.078-0.906-2.469-0.906-4.281h-3.5c-0.547 0-1-0.453-1-1s0.453-1 1-1h3.5v-4.594l-2.703-2.703c-0.391-0.391-0.391-1.016 0-1.406s1.016-0.391 1.406 0l2.703 2.703h13.188l2.703-2.703c0.391-0.391 1.016-0.391 1.406 0s0.391 1.016 0 1.406l-2.703 2.703v4.594h3.5c0.547 0 1 0.453 1 1zM18 6h-10c0-2.766 2.234-5 5-5s5 2.234 5 5z"></path></symbol>','<symbol id="outline-icon-tags" viewBox="0 0 26 28"><path d="M7 7c0-1.109-0.891-2-2-2s-2 0.891-2 2 0.891 2 2 2 2-0.891 2-2zM23.672 16c0 0.531-0.219 1.047-0.578 1.406l-7.672 7.688c-0.375 0.359-0.891 0.578-1.422 0.578s-1.047-0.219-1.406-0.578l-11.172-11.188c-0.797-0.781-1.422-2.297-1.422-3.406v-6.5c0-1.094 0.906-2 2-2h6.5c1.109 0 2.625 0.625 3.422 1.422l11.172 11.156c0.359 0.375 0.578 0.891 0.578 1.422zM29.672 16c0 0.531-0.219 1.047-0.578 1.406l-7.672 7.688c-0.375 0.359-0.891 0.578-1.422 0.578-0.812 0-1.219-0.375-1.75-0.922l7.344-7.344c0.359-0.359 0.578-0.875 0.578-1.406s-0.219-1.047-0.578-1.422l-11.172-11.156c-0.797-0.797-2.312-1.422-3.422-1.422h3.5c1.109 0 2.625 0.625 3.422 1.422l11.172 11.156c0.359 0.375 0.578 0.891 0.578 1.422z"></path></symbol>','<symbol id="outline-icon-print" viewBox="0 0 24 24"><path d="M18 3v3.984h-12v-3.984h12zM18.984 12q0.422 0 0.727-0.281t0.305-0.703-0.305-0.727-0.727-0.305-0.703 0.305-0.281 0.727 0.281 0.703 0.703 0.281zM15.984 18.984v-4.969h-7.969v4.969h7.969zM18.984 8.016q1.219 0 2.109 0.891t0.891 2.109v6h-3.984v3.984h-12v-3.984h-3.984v-6q0-1.219 0.891-2.109t2.109-0.891h13.969z"></path></symbol>','<symbol id="outline-icon-info" viewBox="0 0 1024 1024"><path d="M512 384.295982a95.994 95.994 0 0 1 95.994 95.994V928.006a95.994 95.994 0 0 1-191.988 0V480.289982a95.994 95.994 0 0 1 95.994-95.994z m0-128.375977A127.992 127.992 0 1 1 512 0.063996a127.992 127.992 0 0 1 0 255.984001z"></path></symbol>','<symbol id="outline-icon-warning" viewBox="0 0 1024 1024"><path d="M512 639.704018a95.994 95.994 0 0 1-95.994-95.994V95.994a95.994 95.994 0 0 1 191.988 0v447.716018a95.994 95.994 0 0 1-95.994 95.994z m0 128.375977A127.992 127.992 0 1 1 512 1023.936004a127.992 127.992 0 0 1 0-255.984001z"></path></symbol>','<symbol id="outline-icon-error" viewBox="0 0 1024 1024"><path d="M512.64 376.96L263.744 128 128 263.744l248.96 248.96L128 761.472l135.744 135.808 248.96-248.96 248.832 248.96 135.808-135.808-248.96-248.896 248.96-248.896L761.536 128 512.64 376.96z"></path></symbol>','<symbol id="outline-icon-success" viewBox="0 0 1024 1024"><path d="M426.368 580.864l-226.56-226.56L64 489.984l362.048 362.112 0.32-0.32 0.32 0.32 588.288-588.352L879.36 128 426.304 580.864z"></path></symbol>','<symbol id="outline-icon-circle-info" viewBox="0 0 1024 1024"><path d="M512 810.666667s-42.666667 4.266667-42.666667-42.666667v-341.333333c0-46.933333 42.666667-42.666667 42.666667-42.666667s42.666667-4.266667 42.666667 42.666667v341.333333c0 46.933333-42.666667 42.666667-42.666667 42.666667z m0 213.333333C228.949333 1024 0 795.050667 0 512S228.949333 0 512 0s512 228.949333 512 512-229.674667 512-512 512z m0-938.666667C276.608 85.333333 85.333333 276.608 85.333333 512s191.274667 426.666667 426.666667 426.666667 426.666667-191.274667 426.666667-426.666667S747.392 85.333333 512 85.333333z m0 213.333334c-23.466667 0-42.666667-19.2-42.666667-42.666667s19.2-42.666667 42.666667-42.666667 42.666667 19.2 42.666667 42.666667-19.2 42.666667-42.666667 42.666667z"></path></symbol>','<symbol id="outline-icon-circle-warning" viewBox="0 0 1024 1024"><path d="M512 213.333333s-42.666667-4.266667-42.666667 42.666667v341.333333c0 46.933333 42.666667 42.666667 42.666667 42.666667s42.666667 4.266667 42.666667-42.666667V256c0-46.933333-42.666667-42.666667-42.666667-42.666667z m0-213.333333C228.949333 0 0 228.949333 0 512s228.949333 512 512 512 512-228.949333 512-512S794.325333 0 512 0z m0 938.666667C276.608 938.666667 85.333333 747.392 85.333333 512S276.608 85.333333 512 85.333333s426.666667 191.274667 426.666667 426.666667-191.274667 426.666667-426.666667 426.666667z m0-213.333334c-23.466667 0-42.666667 19.2-42.666667 42.666667s19.2 42.666667 42.666667 42.666667 42.666667-19.2 42.666667-42.666667-19.2-42.666667-42.666667-42.666667z"></path></symbol>','<symbol id="outline-icon-circle-error" viewBox="0 0 1024 1024"><path d="M512 0a512 512 0 1 0 512 512 512 512 0 0 0-512-512z m0 955.776A443.84 443.84 0 0 1 512 68.224a443.904 443.904 0 0 1 0 887.552z"></path><path d="M641.664 326.144a32 32 0 0 1 50.304 39.168l-3.52 4.48-306.112 328.064a32 32 0 0 1-50.304-39.168l3.52-4.48 306.112-328.064z"></path><path d="M324.608 337.088a32 32 0 0 1 40.704-5.12l4.48 3.584 328.064 306.112a32 32 0 0 1-39.168 50.304l-4.48-3.52-328.064-306.112a32 32 0 0 1-1.536-45.248z"></path></symbol>','<symbol id="outline-icon-circle-success" viewBox="0 0 1024 1024"><path d="M512 0C228.949333 0 0 228.949333 0 512s228.949333 512 512 512 512-228.949333 512-512S794.325333 0 512 0z m0 950.869333C269.909333 950.869333 73.130667 754.090667 73.130667 512 73.130667 269.909333 269.909333 73.130667 512 73.130667c242.090667 0 438.869333 196.778667 438.869333 438.869333 0 242.090667-196.778667 438.869333-438.869333 438.869333z"></path><path d="M737.834667 353.834667a42.666667 42.666667 0 0 1 63.872 56.32l-3.541334 4.010666L486.997333 725.333333a85.333333 85.333333 0 0 1-115.242666 4.992L366.336 725.333333l-140.501333-140.501333a42.666667 42.666667 0 0 1 56.32-63.872l4.010666 3.541333L426.666667 665.002667l311.168-311.168z"></path></symbol>'],w=function(e){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"icon";return t(e)?function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"icon";const n=/id="(.*?)"/,r=/^(\w+)-/;return $.find((i=>{const s=n.exec(i)[1];return r.exec(s)[1]===e&&s===("icon"===e?`${e}-${t}`:`${e}-icon-${t}`)}))}(e,n):[...$]},L=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";const n=document.body;let r=document.querySelector("#outline-icons"),i=[];(e=>{if(!e)return!1;s(e)&&e.length>0?e.forEach((e=>{-1===$.indexOf(e)&&t(e)&&$.push(e)})):t(e)&&$.push(e)})(e),i=w(),r?r.innerHTML=i.join(""):(r=document.createElement("div"),r.innerHTML=`<svg id="outline-icons" aria-hidden="true" style="position:absolute;display:none;width:0;height:0;overflow:hidden;">${i.join("")}</svg>`,n.insertBefore(r.firstChild,n.firstChild))},A=e=>!!t(e)&&e.replace(/(^\s+)|(\s+$)/g,""),T=t=>{return!(!r(t)||!(i(t)||(t=>!(!r(t)||"[object NodeList]"!==e(t)))(t)||(n=t,r(n)&&"[object DocumentFragment]"===e(n))||(t=>!(!r(t)||!("[object Text]"===e(t)||t.tagName&&3===t.nodeType)))(t)));var n},E=(t,e)=>{const n=Object.prototype.hasOwnProperty;return t&&n.call(t,e)},S=(t,e)=>{if(!t||!r(e))return!1;Object.keys(e).forEach((n=>{const r=e[n];E(e,n)&&((t,e,n)=>{let r=t.tagName.toLowerCase();switch(e){case"style":t.style.cssText=n;break;case"value":"input"===r||"textarea"===r?t.value=n:t.setAttribute(e,n);break;case"htmlFor":t.setAttribute("for",n);break;case"className":t.className=n;break;case"innerHTML":t.innerHTML=n;break;case"innerText":t.innerText=n;break;default:t.setAttribute(e,n)}})(t,n,r)}))},j=function(e){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const r="outline-icon",i=n.size||0,o=n.color||"",l=n.iconSet||"",c=s(i)?i[0]:i,a=s(i)?i[1]:i,h=i?`width:${c}px;height:${a}px;`:"",u=o?h+`color:${o}`:h,d=n.attrs||{},p=document.createElement("i");let m,f="",g="";return t(e)?((e=>{const n=new RegExp("^\\s*(?:<\\?xml[^>]*>\\s*)?(?:<\\!doctype svg[^>]*\\s*(?:\\[?(?:\\s*<![^>]*>\\s*)*\\]?)*[^>]*>\\s*)?<svg[^>]*>[^]*<\\/svg>\\s*$\\s*$","i");return t(e)&&n.test(e)})(e)?g=e:(f=l&&"icon"!==l?`xlink:href="#${l}-icon-${e}"`:`xlink:href="#icon-${e}"`,g=`<svg><use ${f}></use></svg>`),p.innerHTML=g,d.className?d.className=`${r} ${d.className}`:d.className=r,S(p,d),m=p.querySelector("svg"),S(m,{"aria-hidden":!0,xmlns:"http://www.w3.org/2000/svg",class:"outline-icon__svg",width:200,height:200,style:u}),p):null},C=(e,n,i)=>{const o="outline-heading",l=i.hasAnchor||!0,c=i.isAtStart||!0,a=i.showCode||!1,h=i.chapterCode||"",u=i.anchorURL||"",d=`heading-${n}`,p={id:d,className:c?`${o} ${o}_start`:o,"data-id":n},m=A(e.innerHTML);let f,g;if(a&&(p.innerHTML=h+" "+m),S(e,p),!l)return!1;g=function(t){return j(t,arguments.length>1&&void 0!==arguments[1]?arguments[1]:{})}("hash",{iconSet:"outline"}),f=((e,n,i)=>{const o=document.createDocumentFragment(),l=document.createElement(e),c=e=>T(e)||t(e),a=e=>{let n;if(!c(e))return!1;T(e)?n=e:t(e)&&(n=document.createTextNode(e)),o.appendChild(n)};return r(n)?S(l,n):s(n)&&n.every((t=>c(t)))?n.forEach((t=>{a(t)})):T(n)?a(n):t(n)&&a(document.createTextNode(n)),s(i)?i.forEach((t=>{a(t)})):a(i),l.appendChild(o),l})("a",{id:`anchor-${n}`,className:`${o}__anchor anchor-${n}`,href:u||`#${d}`,target:u?"_blank":"self","data-id":n},g),e.appendChild(f)},k=(t,e)=>{var n;let r,s=t.className;if(!s||!((t,e)=>{const n=new RegExp("(\\s|^)"+e+"(\\s|$)");let r,s;return!!i(t)&&(r=t.className,!!r&&(s=t.classList,s&&s.contains?t.classList.contains(e):!!n.exec(r)))})(t,e))return!1;r=t.classList,null!==(n=r)&&void 0!==n&&n.remove?r.remove(e):(s=A(s.replace(e,"")),t.className=s)},_=function(e){let n=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];const i="outline-heading",s=e.innerHTML;let o;if(e.innerHTML=s.replace(/^\d+(\.?\d+)*\s?/gi,""),e.removeAttribute("id"),e.removeAttribute("data-id"),k(e,i),!n)return!1;var l;o=e.querySelector(`.${i}__anchor`),r&&k(e,`${i}_start`),l=A(e.className),t(l)&&""===l&&e.removeAttribute("class"),o&&e.removeChild(o)},N=function(e){let r=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,o=1,l=0,c="";const a=[];return e.forEach(((e,r)=>{const s=e.tagName,h=s.replace(/h/i,"");let u=parseInt(h,10),d=-1;var p;u>o?(l+=1,d=1===l?-1:r-1):u===o||u<o&&u>l?1===u?(l=1,d=-1):d=a[r-1].pid:u<=l&&(1===u?l=1:(l-=o-u,l<=1&&(l=1)),d=1===l?-1:((t,e,n)=>{let r,i,s=t[n-1];for(i=0;i<e;i+=1)r=s.pid,s=t[r];return r=s.pid,r})(a,o-u,r)),o=u,p=A(e.innerHTML),c=t(p)?p.replace(/<\/?[^>]+(>|$)/g,""):"",n(i)&&(c=i(c)),a.push({id:r,pid:d,level:l,rel:`heading-${r}`,text:c,tagName:s})})),r?(t=>{const e={};return t.forEach((t=>{const n=JSON.stringify((t=>[t.pid])(t));e[n]=e[n]||[],e[n].push(t),t.index=e[n].length,-1===t.pid&&(t.code=String(t.index))})),Object.keys(e).forEach((t=>{e[t].forEach((t=>{const n=e[`[${t.id}]`];if(!n||!s(n))return!1;n.forEach((e=>{e.code=t.code+"."+e.index}))}))})),t})(a):a},H={},B=t=>E(H,t)&&H[t].length>0,O=function(t){return!(arguments.length>1&&void 0!==arguments[1])||arguments[1]?B(t):(t=>{let e=B(t),n=t.lastIndexOf(".");for(;!e&&-1!==n;)n=(t=t.substring(0,n)).lastIndexOf("."),e=B(t);return e})(t)},q=function(t,n){let r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];const i=t=>{if(!B(t))return!1;H[t].forEach((t=>{const r=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]","[object BigInt64Array]","[object BigUint64Array]"].indexOf(e(n))>-1?n.toString():n;t.callback.call(t.context||t,r)}))},s=()=>{let e=t,n=t.lastIndexOf(".");for(;-1!==n;)e=e.substring(0,n),n=e.lastIndexOf("."),i(e);i(t),i("*")};if(!O(t))return!1;r?setTimeout(s,10):s()},I=(()=>{let t=0;return e=>(t+=1,e?e+"-"+t:"guid-"+t)})(),F=t=>{if(!E(H,t))return!1;delete H[t]},U=(t,e)=>{if(!O(t))return!1;e?(t=>{const e=Object.keys(H);if(!t||e.length<1)return!1;e.forEach((e=>{const n=H[e];let r;n.forEach(((e,i)=>{e.callback!==t&&e.token!==t||(r=e.topic,n.splice(-1,i))})),n.length<1&&F(r)}))})(e):F(t)};class D{constructor(t){this.attrs={},t&&this.initialize(t)}initialize(t){return this.attr(t).render().addListeners(),this}attr(e,n){const i=this.attrs;return t(e)?n&&E(i,e)?(i[e]=n,this):i[e]:r(e)?(s=i,o=e,Object.keys(o).forEach((t=>{E(o,t)&&(s[t]=o[t])})),this):0===arguments.length?i:this;var s,o}render(){return this}refresh(){return this}destroy(){return this.removeListeners(),this}reload(t){return this.destroy().initialize(t),this}$emit(t,e){return q(t,e),this}$on(t,e){return function(t,e){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;const i=I();let s="symbol"==typeof t?t.toString():t;n(e)&&(H[s]||(H[s]=[]),H[s].push({topic:s,callback:e,context:r,token:i}))}(t,e,this),this}$off(t,e){return U(t,e),this}addListeners(){return this}removeListeners(){return this}}class V extends D{constructor(t){super(),this._default(),t&&this.initialize(t)}_default(){return this.attrs=o(V.DEFAULTS),this.$articleElement=null,this.$scrollElement=null,this.$headings=[],this.chapters=[],this}initialize(e){const r=this.attr("showCode")||!0;let s,o,l,c,a;return this.attr(e),a=this.attr("articleElement"),o=this.attr("scrollElement"),l=this.attr("selector"),s=this.attr("created"),t(a)?c=document.querySelector(a):i(a)&&(c=a),c?(this.$articleElement=c,this.$scrollElement=m(o),this.$headings=[...c.querySelectorAll(l)],this.$headings.length<1||(this.chapters=N(this.$headings,r,this.attr("chapterTextFilter")),n(s)&&s.call(this),this.render().addListeners()),this):this}getChapters(){let t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];const e=this.chapters;return t?((t,e,n)=>{const r={},i=[];return t.forEach(((t,n)=>{r[t[e]]=n,t.children=[]})),t.forEach((e=>{const s=t[r[e[n]]];-1!==e[n]?s.children.push(e):i.push(e)})),i})(e,"id","pid"):e}count(){return this.chapters.length}render(){const t=this.attr("mounted");return L(),this._paint(this.chapters),n(t)&&t.call(this),this}erase(){return this._remove(),this}_paint(t){const e=400,n=this.attr("hasAnchor"),r=this.attr("isAtStart"),i=this.attr("showCode"),s=this.attr("anchorURL"),o=this.count(),l=[...this.$headings],c=(o,l)=>{o.forEach(((o,c)=>{const a=c+l*e,h=t[a].code;C(o,a,{hasAnchor:n,isAtStart:r,showCode:i,chapterCode:h,anchorURL:s})}))};let a=-1;if(o>e)for(a+=1,c(l.splice(0,e),0);l.length>0;){const t=l.splice(0,e);d((()=>{c(t,a+=1)}),(()=>{this.$emit("anchors:all:paint")}))}else c(l,0);return this}_remove(){const t=this.attr("hasAnchor"),e=this.attr("isAtStart");return this.$headings.forEach((n=>{_(n,t,e)})),this}refresh(t){const e=this.$articleElement,n=this.attr("selector");return this.$headings=[...e.querySelectorAll(n)],this.chapters=t,this.erase()._paint(t),this}scrollTo(t,e){return((t,e,r)=>{const i=m(t);let s=i.scrollTop,o=0;const l=e-s,c=i.scrollHeight,a=e-c<=0?e:c,h=t=>(n(r)&&r(t),!1),u=()=>{if(o+=1,l<0){if(s-=p(o),i.scrollTop=s,s<=e)return i.scrollTop=e,h(e)}else if(s+=p(o),i.scrollTop=s,s>=a)return i.scrollTop=a,h(a);requestAnimationFrame(u)};requestAnimationFrame(u)})(this.$scrollElement,t,e),this}destroy(){const t=this.attr("beforeDestroy"),e=this.attr("afterDestroy");return n(t)&&t.call(this),this.removeListeners()._remove()._default(),n(e)&&e.call(this),this}addListeners(){const t=this.$articleElement;return this.count()<1||M(t,".outline-heading__anchor","click",this.onAnchorTrigger,this,!0),this}removeListeners(){const t=this.$articleElement;return this.count()<1||x(t,"click",this.onAnchorTrigger),this}onAnchorTrigger(t){const e=this.attr("anchorURL"),r=this.attr("afterScroll"),i=this.attr("stickyHeight"),s=t.delegateTarget.parentNode,o=f(s)-(i+10),c=this.$scrollElement,a=c.scrollHeight-c.clientHeight;return this.scrollTo(o,(()=>{n(r)&&r.call(this,"anchor"),l((()=>{this.$emit("toolbar:update",{top:o,min:0,max:a})}))})),e||function(t){t.stopPropagation(),t.preventDefault()}(t),this}}return V.DEFAULTS={scrollElement:"html,body",articleElement:"#article",selector:"h1,h2,h3,h4,h5,h6",stickyHeight:0,anchorURL:"",hasAnchor:!0,isAtStart:!0,showCode:!1,created:null,mounted:null,afterScroll:null,beforeDestroy:null,afterDestroy:null,chapterTextFilter:null},V}));
//# sourceMappingURL=anchors.min.js.map
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/lelezr/outline.js.git
git@gitee.com:lelezr/outline.js.git
lelezr
outline.js
outline.js
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385