Files
Futontime_UI/modules/ebookplayer/foliate/overlayer.js
2026-02-09 10:48:21 +01:00

1 line
10 KiB
JavaScript

define(["exports"],function(_exports){function _createForOfIteratorHelper(r,e){var o,a,u,n,t="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(t)return u=!(a=!0),{s:function(){t=t.call(r)},n:function(){var r=t.next();return a=r.done,r},e:function(r){u=!0,o=r},f:function(){try{a||null==t.return||t.return()}finally{if(u)throw o}}};if(Array.isArray(r)||(t=function(r,a){{var t;if(r)return"string"==typeof r?_arrayLikeToArray(r,a):"Map"===(t="Object"===(t={}.toString.call(r).slice(8,-1))&&r.constructor?r.constructor.name:t)||"Set"===t?Array.from(r):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?_arrayLikeToArray(r,a):void 0}}(r))||e&&r&&"number"==typeof r.length)return t&&(r=t),n=0,{s:e=function(){},n:function(){return n>=r.length?{done:!0}:{done:!1,value:r[n++]}},e:function(r){throw r},f:e};throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _arrayLikeToArray(r,a){(null==a||a>r.length)&&(a=r.length);for(var e=0,n=Array(a);e<a;e++)n[e]=r[e];return n}function _classPrivateFieldInitSpec(e,t,a){(function(e,t){if(t.has(e))throw new TypeError("Cannot initialize the same private elements twice on an object")})(e,t),t.set(e,a)}function _classPrivateFieldGet(s,a){return s.get(function(e,t,n){if("function"==typeof e?e===t:e.has(t))return arguments.length<3?t:n;throw new TypeError("Private element is not present on this object")}(s,a))}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.Overlayer=void 0;function createSVGElement(tag){return document.createElementNS("http://www.w3.org/2000/svg",tag)}var _svg=new WeakMap,_map=new WeakMap;_exports.Overlayer=function(){return babelHelpers.createClass(function Overlayer(){babelHelpers.classCallCheck(this,Overlayer),_classPrivateFieldInitSpec(this,_svg,createSVGElement("svg")),_classPrivateFieldInitSpec(this,_map,new Map),Object.assign(_classPrivateFieldGet(_svg,this).style,{position:"absolute",top:"0",left:"0",width:"100%",height:"100%",pointerEvents:"none"})},[{key:"element",get:function(){return _classPrivateFieldGet(_svg,this)}},{key:"add",value:function(key,range,draw,options){_classPrivateFieldGet(_map,this).has(key)&&this.remove(key);var rects=(range="function"==typeof range?range(_classPrivateFieldGet(_svg,this).getRootNode()):range).getClientRects(),element=draw(rects,options);_classPrivateFieldGet(_svg,this).append(element),_classPrivateFieldGet(_map,this).set(key,{range:range,draw:draw,options:options,element:element,rects:rects})}},{key:"remove",value:function(key){_classPrivateFieldGet(_map,this).has(key)&&(_classPrivateFieldGet(_svg,this).removeChild(_classPrivateFieldGet(_map,this).get(key).element),_classPrivateFieldGet(_map,this).delete(key))}},{key:"redraw",value:function(){var _step,_iterator=_createForOfIteratorHelper(_classPrivateFieldGet(_map,this).values());try{for(_iterator.s();!(_step=_iterator.n()).done;){var obj=_step.value,range=obj.range,draw=obj.draw,options=obj.options,element=obj.element,rects=(_classPrivateFieldGet(_svg,this).removeChild(element),range.getClientRects()),el=draw(rects,options);_classPrivateFieldGet(_svg,this).append(el),obj.element=el,obj.rects=rects}}catch(err){_iterator.e(err)}finally{_iterator.f()}}},{key:"hitTest",value:function(_ref){for(var x=_ref.x,y=_ref.y,arr=Array.from(_classPrivateFieldGet(_map,this).entries()),i=arr.length-1;0<=i;i--){var _step2,_arr$i=babelHelpers.slicedToArray(arr[i],2),key=_arr$i[0],obj=_arr$i[1],_iterator2=_createForOfIteratorHelper(obj.rects);try{for(_iterator2.s();!(_step2=_iterator2.n()).done;){var _step2$value=_step2.value,left=_step2$value.left,top=_step2$value.top,right=_step2$value.right,bottom=_step2$value.bottom;if(top<=y&&left<=x&&y<bottom&&x<right)return[key,obj.range]}}catch(err){_iterator2.e(err)}finally{_iterator2.f()}}return[]}}],[{key:"underline",value:function(rects){var options=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},_options$color=options.color,_options$color=void 0===_options$color?"red":_options$color,_options$width=options.width,strokeWidth=void 0===_options$width?2:_options$width,_options$width=options.writingMode,g=createSVGElement("g");if(g.setAttribute("fill",_options$color),"vertical-rl"===_options$width||"vertical-lr"===_options$width){var _step3,_iterator3=_createForOfIteratorHelper(rects);try{for(_iterator3.s();!(_step3=_iterator3.n()).done;){var _step3$value=_step3.value,right=_step3$value.right,top=_step3$value.top,height=_step3$value.height,el=createSVGElement("rect");el.setAttribute("x",right-strokeWidth),el.setAttribute("y",top),el.setAttribute("height",height),el.setAttribute("width",strokeWidth),g.append(el)}}catch(err){_iterator3.e(err)}finally{_iterator3.f()}}else{var _step4,_iterator4=_createForOfIteratorHelper(rects);try{for(_iterator4.s();!(_step4=_iterator4.n()).done;){var _step4$value=_step4.value,left=_step4$value.left,bottom=_step4$value.bottom,width=_step4$value.width,_el=createSVGElement("rect");_el.setAttribute("x",left),_el.setAttribute("y",bottom-strokeWidth),_el.setAttribute("height",strokeWidth),_el.setAttribute("width",width),g.append(_el)}}catch(err){_iterator4.e(err)}finally{_iterator4.f()}}return g}},{key:"strikethrough",value:function(rects){var options=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},_options$color2=options.color,_options$color2=void 0===_options$color2?"red":_options$color2,_options$width2=options.width,strokeWidth=void 0===_options$width2?2:_options$width2,_options$width2=options.writingMode,g=createSVGElement("g");if(g.setAttribute("fill",_options$color2),"vertical-rl"===_options$width2||"vertical-lr"===_options$width2){var _step5,_iterator5=_createForOfIteratorHelper(rects);try{for(_iterator5.s();!(_step5=_iterator5.n()).done;){var _step5$value=_step5.value,right=_step5$value.right,left=_step5$value.left,top=_step5$value.top,height=_step5$value.height,el=createSVGElement("rect");el.setAttribute("x",(right+left)/2),el.setAttribute("y",top),el.setAttribute("height",height),el.setAttribute("width",strokeWidth),g.append(el)}}catch(err){_iterator5.e(err)}finally{_iterator5.f()}}else{var _step6,_iterator6=_createForOfIteratorHelper(rects);try{for(_iterator6.s();!(_step6=_iterator6.n()).done;){var _step6$value=_step6.value,_left=_step6$value.left,_top=_step6$value.top,bottom=_step6$value.bottom,width=_step6$value.width,_el2=createSVGElement("rect");_el2.setAttribute("x",_left),_el2.setAttribute("y",(_top+bottom)/2),_el2.setAttribute("height",strokeWidth),_el2.setAttribute("width",width),g.append(_el2)}}catch(err){_iterator6.e(err)}finally{_iterator6.f()}}return g}},{key:"squiggly",value:function(rects){var options=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},_options$color3=options.color,_options$color3=void 0===_options$color3?"red":_options$color3,_options$width3=options.width,_options$width3=void 0===_options$width3?2:_options$width3,options=options.writingMode,g=createSVGElement("g"),block=(g.setAttribute("fill","none"),g.setAttribute("stroke",_options$color3),g.setAttribute("stroke-width",_options$width3),1.5*_options$width3);if("vertical-rl"===options||"vertical-lr"===options){var _step7,_iterator7=_createForOfIteratorHelper(rects);try{for(_iterator7.s();!(_step7=_iterator7.n()).done;)!function(){var _step7$value=_step7.value,right=_step7$value.right,top=_step7$value.top,_step7$value=_step7$value.height,el=createSVGElement("path"),n=Math.round(_step7$value/block/1.5),inline=_step7$value/n,_step7$value=Array.from({length:n},function(_,i){return"l".concat(i%2?-block:block," ").concat(inline)}).join("");el.setAttribute("d","M".concat(right," ").concat(top).concat(_step7$value)),g.append(el)}()}catch(err){_iterator7.e(err)}finally{_iterator7.f()}}else{var _step8,_iterator8=_createForOfIteratorHelper(rects);try{for(_iterator8.s();!(_step8=_iterator8.n()).done;)!function(){var _step8$value=_step8.value,left=_step8$value.left,bottom=_step8$value.bottom,_step8$value=_step8$value.width,el=createSVGElement("path"),n=Math.round(_step8$value/block/1.5),inline=_step8$value/n,_step8$value=Array.from({length:n},function(_,i){return"l".concat(inline," ").concat(i%2?block:-block)}).join("");el.setAttribute("d","M".concat(left," ").concat(bottom).concat(_step8$value)),g.append(el)}()}catch(err){_iterator8.e(err)}finally{_iterator8.f()}}return g}},{key:"highlight",value:function(rects){var _step9,_options$color4=(1<arguments.length&&void 0!==arguments[1]?arguments[1]:{}).color,_options$color4=void 0===_options$color4?"red":_options$color4,g=createSVGElement("g"),_iterator9=(g.setAttribute("fill",_options$color4),g.style.opacity="var(--overlayer-highlight-opacity, .3)",g.style.mixBlendMode="var(--overlayer-highlight-blend-mode, normal)",_createForOfIteratorHelper(rects));try{for(_iterator9.s();!(_step9=_iterator9.n()).done;){var _step9$value=_step9.value,left=_step9$value.left,top=_step9$value.top,height=_step9$value.height,width=_step9$value.width,el=createSVGElement("rect");el.setAttribute("x",left),el.setAttribute("y",top),el.setAttribute("height",height),el.setAttribute("width",width),g.append(el)}}catch(err){_iterator9.e(err)}finally{_iterator9.f()}return g}},{key:"outline",value:function(rects){var _step0,options=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},_options$color5=options.color,_options$color5=void 0===_options$color5?"red":_options$color5,_options$width4=options.width,_options$width4=void 0===_options$width4?3:_options$width4,options=options.radius,radius=void 0===options?3:options,g=createSVGElement("g"),_iterator0=(g.setAttribute("fill","none"),g.setAttribute("stroke",_options$color5),g.setAttribute("stroke-width",_options$width4),_createForOfIteratorHelper(rects));try{for(_iterator0.s();!(_step0=_iterator0.n()).done;){var _step0$value=_step0.value,left=_step0$value.left,top=_step0$value.top,height=_step0$value.height,width=_step0$value.width,el=createSVGElement("rect");el.setAttribute("x",left),el.setAttribute("y",top),el.setAttribute("height",height),el.setAttribute("width",width),el.setAttribute("rx",radius),g.append(el)}}catch(err){_iterator0.e(err)}finally{_iterator0.f()}return g}},{key:"copyImage",value:function(_ref2){var rect=babelHelpers.slicedToArray(_ref2,1)[0],src=(1<arguments.length&&void 0!==arguments[1]?arguments[1]:{}).src,image=createSVGElement("image"),left=rect.left,top=rect.top,height=rect.height,rect=rect.width;return image.setAttribute("href",src),image.setAttribute("x",left),image.setAttribute("y",top),image.setAttribute("height",height),image.setAttribute("width",rect),image}}])}()});