Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mokuji.js

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mokuji.js - npm Package Compare versions

Comparing version 1.3.3 to 1.3.4

9

dist/mokuji.js
/*!
* mokuji.js v1.3.3
* mokuji.js v1.3.4
* https://github.com/hiro0218/mokuji.js

@@ -174,3 +174,3 @@ *

for (var i = 0; i < number - currentNumber; i++) {
if (__WEBPACK_IMPORTED_MODULE_0__hasParentNode___default.a(ol, ol.parentNode)) {
if (__WEBPACK_IMPORTED_MODULE_0__hasParentNode___default()(ol, ol.parentNode)) {
ol = ol.parentNode.parentNode;

@@ -189,2 +189,7 @@ }

// not have Iterator
if (number === 0) {
return null;
}
ol = this.reverseMokuji(ol);

@@ -191,0 +196,0 @@

/*!
* mokuji.js v1.3.3
* mokuji.js v1.3.4
* https://github.com/hiro0218/mokuji.js

@@ -7,2 +7,2 @@ *

*/
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Mokuji=t():e.Mokuji=t()}(this,function(){return function(e){function t(o){if(r[o])return r[o].exports;var n=r[o]={i:o,l:!1,exports:{}};return e[o].call(n.exports,n,n.exports,t),n.l=!0,n.exports}var r={};return t.m=e,t.c=r,t.d=function(e,r,o){t.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:o})},t.n=function(e){var r=e&&e.__esModule?function(){return e["default"]}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=0)}([function(e,t,r){"use strict";function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0}),r.d(t,"init",function(){return c});var n=r(3),l=r.n(n),i=function(){function e(e,t){for(var r=0;r<t.length;r++){var o=t[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,r,o){return r&&e(t.prototype,r),o&&e(t,o),t}}();r(1).polyfill(),r(2).polyfill();var a={anchorType:"",anchorLink:!1,anchorLinkSymbol:"#",anchorLinkBefore:!0,anchorLinkClassName:"",smoothScroll:!0},c=function(){function e(t,r){if(o(this,e),t){r=Object.assign(a,r);return this.render(t,r)}}return i(e,[{key:"render",value:function(e,t){var r=this.generateMokuji(e,t);if(r)return t.anchorLink&&this.renderAnchorLink(r,t),t.smoothScroll&&this.setSmoothScroll(r),r}},{key:"generateMokuji",value:function(e,t){for(var r=this.createHeadingWalker(e),o=null,n=0,i=document.createElement("ol"),a=document.createElement("li"),c=document.createElement("a");o=r.nextNode();){var s=o.tagName.match(/\d/g).join("");if(s=Number(s),0!==n&&n<s){var u=document.createElement("ol");i.lastChild.appendChild(u),i=u}else if(0!==n&&n>s)for(var f=0;f<n-s;f++)l.a(i,i.parentNode)&&(i=i.parentNode.parentNode);o.id=this.setAnchor(o.id,o.textContent,t.anchorType),i.appendChild(this.buildList(o,c.cloneNode(!1),a.cloneNode(!1))),n=s}return i=this.reverseMokuji(i),this.removeDuplicateIds(i),i}},{key:"createHeadingWalker",value:function(e){return document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,function(e){return/^H[1-6]$/.test(e.tagName)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP},!1)}},{key:"setAnchor",value:function(e,t,r){var o=e||this.replaceSpace2Underscore(t);return o=o.replace(/\&+/g,""),o=o.replace(/\&amp;+/g,""),"wikipedia"===r&&(o=encodeURIComponent(o),o=o.replace(/\%+/g,".")),o}},{key:"renderAnchorLink",value:function(e,t){if(e){var r=e.getElementsByTagName("a"),o=document.createElement("a");o.classList.add(t.anchorLinkClassName);for(var n=0;n<r.length;n++){var l=r[n].hash,i=document.querySelector('[id="'+l.replace("#","")+'"]'),a=o.cloneNode(!1);a.setAttribute("href",l),a.textContent=t.anchorLinkSymbol,t.anchorLinkBefore?i.insertBefore(a,i.firstChild):i.appendChild(a)}}}},{key:"setSmoothScroll",value:function(e){if(e)for(var t=e.getElementsByTagName("a"),r=0;r<t.length;r++)t[r].addEventListener("click",function(e){var t=this.hash;e.preventDefault(),document.querySelector('[id="'+t.replace("#","")+'"]').scrollIntoView({behavior:"smooth"}),history.pushState(null,null,t)})}},{key:"replaceSpace2Underscore",value:function(e){return String(e).replace(/\s+/g,"_")}},{key:"buildList",value:function(e,t,r){return t.href="#"+e.id,t.textContent=e.textContent,r.appendChild(t),r}},{key:"reverseMokuji",value:function(e){for(;e.parentNode;)e=e.parentNode;return e}},{key:"removeDuplicateIds",value:function(e){for(var t=e.getElementsByTagName("a"),r=0;r<t.length;r++){var o=t[r].innerText,n=t[r].hash,l=document.querySelectorAll('[id="'+o+'"]');if(1!==l.length){var i=0;Array.from||(Array.from=function(e){return Array.prototype.slice.call(e)});for(var a=Array.from(l),c=Array.isArray(a),s=0,a=c?a:a[Symbol.iterator]();;){var u;if(c){if(s>=a.length)break;u=a[s++]}else{if(s=a.next(),s.done)break;u=s.value}for(var f=u,p=f.id+"-"+i,d=Array.from(t),h=Array.isArray(d),y=0,d=h?d:d[Symbol.iterator]();;){var v;if(h){if(y>=d.length)break;v=d[y++]}else{if(y=d.next(),y.done)break;v=y.value}var m=v;if(m.hash===n){m.href="#"+p;break}}f.id=p,i++}}}}}]),e}()},function(e,t,r){"use strict";function o(e,t){if(e===undefined||null===e)throw new TypeError("Cannot convert first argument to object");for(var r=Object(e),o=1;o<arguments.length;o++){var n=arguments[o];if(n!==undefined&&null!==n)for(var l=Object.keys(Object(n)),i=0,a=l.length;i<a;i++){var c=l[i],s=Object.getOwnPropertyDescriptor(n,c);s!==undefined&&s.enumerable&&(r[c]=n[c])}}return r}function n(){Object.assign||Object.defineProperty(Object,"assign",{enumerable:!1,configurable:!0,writable:!0,value:o})}e.exports={assign:o,polyfill:n}},function(e,t,r){!function(t,r,o){"use strict";function n(){function e(e,t){this.scrollLeft=e,this.scrollTop=t}function n(e){return.5*(1-Math.cos(Math.PI*e))}function l(e){if("object"!=typeof e||null===e||e.behavior===o||"auto"===e.behavior||"instant"===e.behavior)return!0;if("object"==typeof e&&"smooth"===e.behavior)return!1;throw new TypeError("behavior not valid")}function i(e){var o,n,l;do{e=e.parentNode,o=e===r.body,n=e.clientHeight<e.scrollHeight||e.clientWidth<e.scrollWidth,l="visible"===t.getComputedStyle(e,null).overflow}while(!o&&(!n||l));return o=n=l=null,e}function a(e){var r,o,l,i=p(),c=(i-e.startTime)/u;c=c>1?1:c,r=n(c),o=e.startX+(e.x-e.startX)*r,l=e.startY+(e.y-e.startY)*r,e.method.call(e.scrollable,o,l),o===e.x&&l===e.y||t.requestAnimationFrame(a.bind(t,e))}function c(o,n,l){var i,c,s,u,d=p();o===r.body?(i=t,c=t.scrollX||t.pageXOffset,s=t.scrollY||t.pageYOffset,u=f.scroll):(i=o,c=o.scrollLeft,s=o.scrollTop,u=e),a({scrollable:i,method:u,startTime:d,startX:c,startY:s,x:n,y:l})}if(!("scrollBehavior"in r.documentElement.style)){var s=t.HTMLElement||t.Element,u=468,f={scroll:t.scroll||t.scrollTo,scrollBy:t.scrollBy,elScroll:s.prototype.scroll||e,scrollIntoView:s.prototype.scrollIntoView},p=t.performance&&t.performance.now?t.performance.now.bind(t.performance):Date.now;t.scroll=t.scrollTo=function(){if(l(arguments[0]))return void f.scroll.call(t,arguments[0].left||arguments[0],arguments[0].top||arguments[1]);c.call(t,r.body,~~arguments[0].left,~~arguments[0].top)},t.scrollBy=function(){if(l(arguments[0]))return void f.scrollBy.call(t,arguments[0].left||arguments[0],arguments[0].top||arguments[1]);c.call(t,r.body,~~arguments[0].left+(t.scrollX||t.pageXOffset),~~arguments[0].top+(t.scrollY||t.pageYOffset))},s.prototype.scroll=s.prototype.scrollTo=function(){if(l(arguments[0]))return void f.elScroll.call(this,arguments[0].left||arguments[0],arguments[0].top||arguments[1]);c.call(this,this,arguments[0].left,arguments[0].top)},s.prototype.scrollBy=function(){var e=arguments[0];"object"==typeof e?this.scroll({left:e.left+this.scrollLeft,top:e.top+this.scrollTop,behavior:e.behavior}):this.scroll(this.scrollLeft+e,this.scrollTop+arguments[1])},s.prototype.scrollIntoView=function(){if(l(arguments[0]))return void f.scrollIntoView.call(this,arguments[0]||!0);var e=i(this),o=e.getBoundingClientRect(),n=this.getBoundingClientRect();e!==r.body?(c.call(this,e,e.scrollLeft+n.left-o.left,e.scrollTop+n.top-o.top),t.scrollBy({left:o.left,top:o.top,behavior:"smooth"})):t.scrollBy({left:n.left,top:n.top,behavior:"smooth"})}}}e.exports={polyfill:n}}(window,document)},function(e,t,r){"use strict";e.exports=function(e,t){for(;e;){if(e===t)return!0;e=e.parentNode}return!1}}])});
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Mokuji=t():e.Mokuji=t()}(this,function(){return function(e){function t(o){if(r[o])return r[o].exports;var n=r[o]={i:o,l:!1,exports:{}};return e[o].call(n.exports,n,n.exports,t),n.l=!0,n.exports}var r={};return t.m=e,t.c=r,t.d=function(e,r,o){t.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:o})},t.n=function(e){var r=e&&e.__esModule?function(){return e["default"]}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=0)}([function(e,t,r){"use strict";function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0}),r.d(t,"init",function(){return c});var n=r(3),l=r.n(n),i=function(){function e(e,t){for(var r=0;r<t.length;r++){var o=t[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,r,o){return r&&e(t.prototype,r),o&&e(t,o),t}}();r(1).polyfill(),r(2).polyfill();var a={anchorType:"",anchorLink:!1,anchorLinkSymbol:"#",anchorLinkBefore:!0,anchorLinkClassName:"",smoothScroll:!0},c=function(){function e(t,r){if(o(this,e),t){r=Object.assign(a,r);return this.render(t,r)}}return i(e,[{key:"render",value:function(e,t){var r=this.generateMokuji(e,t);if(r)return t.anchorLink&&this.renderAnchorLink(r,t),t.smoothScroll&&this.setSmoothScroll(r),r}},{key:"generateMokuji",value:function(e,t){for(var r=this.createHeadingWalker(e),o=null,n=0,i=document.createElement("ol"),a=document.createElement("li"),c=document.createElement("a");o=r.nextNode();){var s=o.tagName.match(/\d/g).join("");if(s=Number(s),0!==n&&n<s){var u=document.createElement("ol");i.lastChild.appendChild(u),i=u}else if(0!==n&&n>s)for(var f=0;f<n-s;f++)l()(i,i.parentNode)&&(i=i.parentNode.parentNode);o.id=this.setAnchor(o.id,o.textContent,t.anchorType),i.appendChild(this.buildList(o,c.cloneNode(!1),a.cloneNode(!1))),n=s}return 0===n?null:(i=this.reverseMokuji(i),this.removeDuplicateIds(i),i)}},{key:"createHeadingWalker",value:function(e){return document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,function(e){return/^H[1-6]$/.test(e.tagName)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP},!1)}},{key:"setAnchor",value:function(e,t,r){var o=e||this.replaceSpace2Underscore(t);return o=o.replace(/\&+/g,""),o=o.replace(/\&amp;+/g,""),"wikipedia"===r&&(o=encodeURIComponent(o),o=o.replace(/\%+/g,".")),o}},{key:"renderAnchorLink",value:function(e,t){if(e){var r=e.getElementsByTagName("a"),o=document.createElement("a");o.classList.add(t.anchorLinkClassName);for(var n=0;n<r.length;n++){var l=r[n].hash,i=document.querySelector('[id="'+l.replace("#","")+'"]'),a=o.cloneNode(!1);a.setAttribute("href",l),a.textContent=t.anchorLinkSymbol,t.anchorLinkBefore?i.insertBefore(a,i.firstChild):i.appendChild(a)}}}},{key:"setSmoothScroll",value:function(e){if(e)for(var t=e.getElementsByTagName("a"),r=0;r<t.length;r++)t[r].addEventListener("click",function(e){var t=this.hash;e.preventDefault(),document.querySelector('[id="'+t.replace("#","")+'"]').scrollIntoView({behavior:"smooth"}),history.pushState(null,null,t)})}},{key:"replaceSpace2Underscore",value:function(e){return String(e).replace(/\s+/g,"_")}},{key:"buildList",value:function(e,t,r){return t.href="#"+e.id,t.textContent=e.textContent,r.appendChild(t),r}},{key:"reverseMokuji",value:function(e){for(;e.parentNode;)e=e.parentNode;return e}},{key:"removeDuplicateIds",value:function(e){for(var t=e.getElementsByTagName("a"),r=0;r<t.length;r++){var o=t[r].innerText,n=t[r].hash,l=document.querySelectorAll('[id="'+o+'"]');if(1!==l.length){var i=0;Array.from||(Array.from=function(e){return Array.prototype.slice.call(e)});for(var a=Array.from(l),c=Array.isArray(a),s=0,a=c?a:a[Symbol.iterator]();;){var u;if(c){if(s>=a.length)break;u=a[s++]}else{if(s=a.next(),s.done)break;u=s.value}for(var f=u,p=f.id+"-"+i,d=Array.from(t),h=Array.isArray(d),y=0,d=h?d:d[Symbol.iterator]();;){var v;if(h){if(y>=d.length)break;v=d[y++]}else{if(y=d.next(),y.done)break;v=y.value}var m=v;if(m.hash===n){m.href="#"+p;break}}f.id=p,i++}}}}}]),e}()},function(e,t,r){"use strict";function o(e,t){if(e===undefined||null===e)throw new TypeError("Cannot convert first argument to object");for(var r=Object(e),o=1;o<arguments.length;o++){var n=arguments[o];if(n!==undefined&&null!==n)for(var l=Object.keys(Object(n)),i=0,a=l.length;i<a;i++){var c=l[i],s=Object.getOwnPropertyDescriptor(n,c);s!==undefined&&s.enumerable&&(r[c]=n[c])}}return r}function n(){Object.assign||Object.defineProperty(Object,"assign",{enumerable:!1,configurable:!0,writable:!0,value:o})}e.exports={assign:o,polyfill:n}},function(e,t,r){!function(t,r,o){"use strict";function n(){function e(e,t){this.scrollLeft=e,this.scrollTop=t}function n(e){return.5*(1-Math.cos(Math.PI*e))}function l(e){if("object"!=typeof e||null===e||e.behavior===o||"auto"===e.behavior||"instant"===e.behavior)return!0;if("object"==typeof e&&"smooth"===e.behavior)return!1;throw new TypeError("behavior not valid")}function i(e){var o,n,l;do{e=e.parentNode,o=e===r.body,n=e.clientHeight<e.scrollHeight||e.clientWidth<e.scrollWidth,l="visible"===t.getComputedStyle(e,null).overflow}while(!o&&(!n||l));return o=n=l=null,e}function a(e){var r,o,l,i=p(),c=(i-e.startTime)/u;c=c>1?1:c,r=n(c),o=e.startX+(e.x-e.startX)*r,l=e.startY+(e.y-e.startY)*r,e.method.call(e.scrollable,o,l),o===e.x&&l===e.y||t.requestAnimationFrame(a.bind(t,e))}function c(o,n,l){var i,c,s,u,d=p();o===r.body?(i=t,c=t.scrollX||t.pageXOffset,s=t.scrollY||t.pageYOffset,u=f.scroll):(i=o,c=o.scrollLeft,s=o.scrollTop,u=e),a({scrollable:i,method:u,startTime:d,startX:c,startY:s,x:n,y:l})}if(!("scrollBehavior"in r.documentElement.style)){var s=t.HTMLElement||t.Element,u=468,f={scroll:t.scroll||t.scrollTo,scrollBy:t.scrollBy,elScroll:s.prototype.scroll||e,scrollIntoView:s.prototype.scrollIntoView},p=t.performance&&t.performance.now?t.performance.now.bind(t.performance):Date.now;t.scroll=t.scrollTo=function(){if(l(arguments[0]))return void f.scroll.call(t,arguments[0].left||arguments[0],arguments[0].top||arguments[1]);c.call(t,r.body,~~arguments[0].left,~~arguments[0].top)},t.scrollBy=function(){if(l(arguments[0]))return void f.scrollBy.call(t,arguments[0].left||arguments[0],arguments[0].top||arguments[1]);c.call(t,r.body,~~arguments[0].left+(t.scrollX||t.pageXOffset),~~arguments[0].top+(t.scrollY||t.pageYOffset))},s.prototype.scroll=s.prototype.scrollTo=function(){if(l(arguments[0]))return void f.elScroll.call(this,arguments[0].left||arguments[0],arguments[0].top||arguments[1]);c.call(this,this,arguments[0].left,arguments[0].top)},s.prototype.scrollBy=function(){var e=arguments[0];"object"==typeof e?this.scroll({left:e.left+this.scrollLeft,top:e.top+this.scrollTop,behavior:e.behavior}):this.scroll(this.scrollLeft+e,this.scrollTop+arguments[1])},s.prototype.scrollIntoView=function(){if(l(arguments[0]))return void f.scrollIntoView.call(this,arguments[0]||!0);var e=i(this),o=e.getBoundingClientRect(),n=this.getBoundingClientRect();e!==r.body?(c.call(this,e,e.scrollLeft+n.left-o.left,e.scrollTop+n.top-o.top),t.scrollBy({left:o.left,top:o.top,behavior:"smooth"})):t.scrollBy({left:n.left,top:n.top,behavior:"smooth"})}}}e.exports={polyfill:n}}(window,document)},function(e,t,r){"use strict";e.exports=function(e,t){for(;e;){if(e===t)return!0;e=e.parentNode}return!1}}])});

@@ -98,2 +98,7 @@ 'use strict';

// not have Iterator
if (number === 0) {
return null;
}
ol = this.reverseMokuji(ol);

@@ -100,0 +105,0 @@

{
"name": "mokuji.js",
"version": "1.3.3",
"version": "1.3.4",
"description": "A table of content JavaScript Library",

@@ -35,12 +35,12 @@ "main": "lib/index.js",

"devDependencies": {
"babel-cli": "^6.6.5",
"babel-cli": "^6.24.1",
"babel-core": "^6.25.0",
"babel-eslint": "^7.2.3",
"babel-loader": "^7.1.0",
"babel-preset-es2015": "^6.6.0",
"babel-loader": "^7.1.1",
"babel-preset-es2015": "^6.24.1",
"cross-env": "^5.0.1",
"eslint": "^4.0.0",
"rimraf": "^2.5.2",
"webpack": "^3.0.0"
"eslint": "^4.3.0",
"rimraf": "^2.6.1",
"webpack": "^3.4.1"
}
}

@@ -37,3 +37,4 @@ var webpack = require('webpack');

}
})
}),
new webpack.optimize.AggressiveMergingPlugin(),
);

@@ -40,0 +41,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc