@bestime/utils_browser 1.0.13 → 1.0.14

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.
@@ -336,28 +336,13 @@ declare class TextRainCanvas {
336
336
 
337
337
  declare class SeamlessRolling {
338
338
  _wrapper: HTMLDivElement;
339
- _timer: number;
339
+ _timer: any;
340
340
  constructor(wraper: HTMLDivElement);
341
341
  _updateContent(): void;
342
342
  _doScroll(): void;
343
343
  dispose(): void;
344
344
  }
345
345
 
346
- type Tlanguage =
347
- | 'Microsoft Huihui - Chinese (Simplified, PRC)'
348
- | 'Microsoft Kangkang - Chinese (Simplified, PRC)'
349
- | 'Microsoft Kangkang - Chinese (Simplified, PRC)'
350
- | 'Microsoft Yaoyao - Chinese (Simplified, PRC)'
351
- | 'Google 한국의'
352
- | 'Google 日本語'
353
- | 'Google 粤語(香港)';
354
- declare function speakText(
355
- message: string,
356
- options: {
357
- language?: Tlanguage;
358
- }
359
- ): Promise<void>;
360
-
361
346
  declare function func01(text: string): Promise<void>;
362
347
  /**
363
348
  * 复制文本
@@ -376,6 +361,7 @@ interface IOptions$1 {
376
361
  fontColor: string;
377
362
  paddingTop: number;
378
363
  paddingBottom: number;
364
+ labelFormatter?: (data: number) => string;
379
365
  colors: IColorItem[];
380
366
  }
381
367
  interface IUseColorItem {
@@ -476,7 +462,6 @@ export {
476
462
  replaceClass,
477
463
  setCookie,
478
464
  setStorage,
479
- speakText,
480
465
  style,
481
466
  toggleClass
482
467
  };
@@ -1,5 +1,5 @@
1
1
  /**
2
2
  * 浏览器工具库 => jUtilsBrowser
3
- * @update 2025-04-22 10:03:23
3
+ * @update 2025-08-06 10:49:02
4
4
  */
5
- import{defualtFormatter,isString,variableHasValue,isArray,forEach,_KvPair,_Number,parseTreeToTableHeader,isNull,getRandom,trim,roundFixed,getType,hexToRgba,rgbaToHex,min,max,split,_String}from"@bestime/utils_base";function getWindowSize(){return{width:document.documentElement.clientWidth||document.body.clientWidth||window.innerWidth||0,height:document.documentElement.clientHeight||document.body.clientHeight||window.innerHeight||0}}let htivId=0,idName="",isStart=!1;const records={};let timer;function stop(){isStart=!1,clearInterval(timer),timer=undefined}function startRun(){clearInterval(timer),isStart=!0,timer=setInterval(function(){for(var e in records){const t=records[e];t.current=+new Date,t.current-t.start>=t.interval&&(t.start=t.current,records[e].handler())}},17)}function add(e,t){return idName="HI-"+ ++htivId,records[idName]={start:+new Date,current:0,handler:e,interval:t},isStart||startRun(),idName}function remove(e){delete records[e],0===Object.keys(records).length&&stop()}var hpInterval={add:add,remove:remove};function observeDomResize(n,o,i,e){let r=[0,0,!1],a=[0,0,!1],s=[0,0,!1],l=[0,0,!1];const t=hpInterval.add(c,e=e||500);function c(){if(document.body.contains(n)){let e=!1;var t;i?.includes("position")&&(t=n.getBoundingClientRect(),s[0]=t.left,s[2]=s[0]!==s[1],l[0]=t.top,l[2]=l[0]!==l[1]),r[0]=n.offsetWidth,r[2]=r[0]!==r[1],a[0]=n.offsetHeight,a[2]=a[0]!==a[1],r[2]&&(r[1]=r[0],i?.includes("width")&&(e=!0)),a[2]&&(a[1]=a[0],i?.includes("height")&&(e=!0)),(l[2]||s[2])&&(l[1]=l[0],s[1]=s[0],i?.includes("position")&&(e=!0)),i&&0!==i.length||(r[2]||a[2]||l[2]||s[2])&&(e=!0),e&&o(n)}else d()}function d(){hpInterval.remove(t),r=undefined,a=undefined}return c(),d}function downloadFileByUrl(e,t){const n=document.createElement("a");n.style.display="none",n.download=t,n.setAttribute("href",e),n.setAttribute("target","_blank"),n.setAttribute("download",t),document.body.appendChild(n),n.click(),n.remove()}const $undefinedValue=void 0,$decodeURIComponent=decodeURIComponent,$browserGlobal=window,$headElement=document.getElementsByTagName("head")[0],iUrl=$browserGlobal.URL;function downloadFileByBolb(e,t){e=iUrl.createObjectURL(e);downloadFileByUrl(e,t),iUrl.revokeObjectURL(e),undefined}function downloadFileByArrayBuffer(e,t){downloadFileByBolb(new Blob([e]),t)}function removeElement(e){e.parentNode&&e.parentNode.removeChild(e)}function prevent(e,t,n){e=e||$browserGlobal.event,n=!1!==n,(t=!1!==t)&&$browserGlobal.event?$browserGlobal.event.cancelBubble=!0:e.stopPropagation(),n&&$browserGlobal.event?$browserGlobal.event.returnValue=!1:e.preventDefault()}function getStorage(e){e=localStorage.getItem(e);return defualtFormatter("",e)}function removeStorage(e){localStorage.removeItem(e)}function hpSetStringValue(e){return e=isString(e)?e:JSON.stringify(e)}function setStorage(e,t){localStorage.setItem(e,hpSetStringValue(t))}function getRelativePos(e){var t=e.getBoundingClientRect();return{x:t.left,y:t.top,height:e.offsetHeight,width:e.offsetWidth,clientWidth:e.clientWidth,clientHeight:e.clientHeight}}function getJsFileBaseUrl(e){e=e||0;for(var t="/[^/]*",n=document.scripts,o=0;o<e;o++)t+=t;return n[n.length-1].src.replace(new RegExp(t+"$"),"")}function hpCreateFileLoaderElement(t,n,o,i){if($headElement){let e;if("js"===t?(e=document.createElement("script")).src=n:((e=document.createElement("link")).setAttribute("rel","stylesheet"),e.href=n),i)for(var r in i)e.setAttribute(r,i[r]);e.onload=e.onerror=o,$headElement.appendChild(e)}}const cache={};function loadMultiple(n,o){const i=[];let r=0;for(let t=0;t<n.length;t++)loadSingle(n[t],function(e){i[t]=e,++r===n.length&&o.apply($undefinedValue,i)})}function loadSingle(e,t){var n=e.dependencies&&e.dependencies.length,o=e["with"]&&e["with"].length;cache[e.url]||(cache[e.url]={count:0,dependencies:!n,"with":!o,complete:!1,create:!1,url:e.url});const i=cache[e.url];function r(){return $browserGlobal[e.module]}function a(){i.complete&&i.dependencies&&i["with"]&&(e.module?t(r()):t())}i.count++,!i.dependencies&&n?(i.dependencies=!0,loadMultiple(e.dependencies,function(){loadSingle(e,t)})):!i["with"]&&o?(i["with"]=!0,loadMultiple(e["with"].concat(e),a)):i.create?variableHasValue(function(){return i.complete},a,300):(i.create=!0,hpCreateFileLoaderElement(e.type,e.url,function(){i.complete=!0,e.interceptor&&e.interceptor(r()),a()},e.attribute))}function libraryFile(e,t){(e instanceof Array?loadMultiple:loadSingle)(e,t)}function setObjectToString(e){return e=isString(e)?e:JSON.stringify(e)}function setCookie(e,t,n){t=setObjectToString(t);let o=e+"="+encodeURI(t)+";path=/;";"number"==typeof n&&((e=new Date).setTime(e.getTime()+n),o+="expires="+e.toUTCString()),document.cookie=o}function getCookie(e,t){t=t||document.cookie;let o="";return t.replace(new RegExp("(^|;\\s?)"+e+"=(.*?)($|(;\\s?))"),function(e,t,n){o=$decodeURIComponent(n)}),o}function removeCookie(e){setCookie(e,"",-1)}function removeClass(t,e){isArray(e)?forEach(e,function(e){t.classList.remove(e)}):t.classList.remove(e)}function addClass(t,e){isArray(e)?forEach(e,function(e){t.classList.add(e)}):t.classList.add(e)}function replaceClass(e,t,n){removeClass(e,t),addClass(e,n)}function toggleClass(t,e){isArray(e)?forEach(e,function(e){t.classList.toggle(e)}):t.classList.toggle(e)}const agent=$browserGlobal.navigator.userAgent;var browser={isChrome:/Chrome/.test(agent),isIPhone:/iPhone/.test(agent)};function getRatio(){return window.devicePixelRatio||1}function observeMouseWheel(e,n,o){function t(e){let t;if(t=e.wheelDelta?0<e.wheelDelta?1:-1:e.detail<0?1:-1,n(t),o)return e.preventDefault&&e.preventDefault(),!1}return e.addEventListener("mousewheel",t),e.addEventListener("DOMMouseScroll",t),{dispose:function(){e.removeEventListener("mousewheel",t),e.removeEventListener("DOMMouseScroll",t)}}}function observeDomScroll(n,e){const o=_KvPair(e),i=_Number(o.offetY);let r=!1,a=0;function t(){var e,t;r||(t=(e=n.scrollTop)-a,a=e,0!=t?t<0&&o.onTop&&e<=0+i?(r=!0,o.onTop(function(){r=!1})):0<t&&o.onBottom&&e>=n.scrollHeight-n.offsetHeight-i?(r=!0,o.onBottom(function(){r=!1})):r=!1:(r=!1,console.log("未处理")))}return n.addEventListener("scroll",t),{dispose:function(){n.removeEventListener("scroll",t)}}}const defaultCallback=e=>{};function open(e,t){const n=t||defaultCallback;e.requestFullscreen?e.requestFullscreen():e.webkitRequestFullScreen?e.webkitRequestFullScreen():e.mozRequestFullScreen?e.mozRequestFullScreen():e.msRequestFullscreen&&e.msRequestFullscreen(),n(!0)}function close(e){const t=e||defaultCallback,n=document;document.exitFullscreen?document.exitFullscreen().then(function(){t(!0)})["catch"](function(){t(!1)}):n.webkitCancelFullScreen?(n.webkitCancelFullScreen(),t(!0)):n.mozCancelFullScreen?(n.mozCancelFullScreen(),t(!0)):n.msExitFullscreen&&(n.msExitFullscreen(),t(!0))}function fullScreen(e,t,n){t?open(e,n):close(n)}async function createXLSX(e){const t=document.createElement("table"),n=parseTreeToTableHeader(e.header);var o=n.data.map(function(e){return`<tr>${e.map(function(e){if(e&&0!==e.colSpan)return`<td align="center" rowSpan="${e.rowSpan}" colSpan="${e.colSpan}">${e?.title}</td>`}).join("")}</tr>`}).join(""),e=e.body.map(function(o){return`<tr>${n.columns.map(function(e){var t=o.$colField?.[e]??1,n=o.$rowSpan?.[e]??1;if(0!==t&&0!==n)return`<td align="center" colSpan="${t}" rowSpan="${n}">${o[e]??""}</td>`}).filter(function(e){return!isNull(e)}).join("")}</tr>`}).join("");return t.innerHTML=`<thead>${o}</thead><tbody>${e}</tbody>`,t.setAttribute("border","1"),t}async function loadPdfPlugin(t){return new Promise(function(e){libraryFile({type:"js",module:"pdfjsLib",attribute:{type:"module"},url:t.index,interceptor:function(e){e.GlobalWorkerOptions.workerSrc=t.worker}},e)})}async function pdfToImage(e,i,t){const n=await loadPdfPlugin(t);return new Promise(function(o){n.getDocument(e).promise.then(function(e){console.log("pdf",e),e.getPage(1).then(function(e){var t=e.getViewport({scale:1}),n=i.getContext("2d");i.height=t.height,i.width=t.width,e.render({canvasContext:n,viewport:t}).promise.then(function(){o({width:t.width,height:t.height})})})},function(e){console.error(e),o({width:0,height:0})})})}function infoContainerPosition(e){var t=e.mode||"top-right",n=e.width,o=e.height,i=defualtFormatter(10,e.offsetY),r=defualtFormatter(10,e.offsetX),a=defualtFormatter(10,e.padding);let s=e.x,l=e.y;var e=e.targetSize||getWindowSize(),c=[a,e.width-n-a],e=[a,e.height-o-a];return"top-right"===t?(s+=r,l=l-o-i,s<c[0]?s=c[0]:s>c[1]&&(a=s-n-2*r,s=c[0]<a?a:c[1]),l<e[0]?(a=l+o+2*i,l=a<e[1]?a:e[0]):l>e[1]&&(l=l-o-2*i)):"bottom-right"===t?(s+=r,(l+=i)>e[1]&&(a=l-o-2*i,l=a<e[0]?e[1]:a),s>c[1]&&(e=s-n-2*r,s=e<c[0]?c[1]:e)):"top-left"===t&&(s=s-n-r,l=l-o-i),{x:s,y:l}}function hexToRgb(e){for(var t=[],n=1;n<7;n+=2)t.push(parseInt("0x"+e.slice(n,n+2)));return t}class TextRainCanvas{text="abcdefghijklmnopqrstuvwxyz";fontSize=14;color=[0,255,0];reverse=!1;isStop=!1;interval=100;width;height;fontLineHeight;count;oCanvas;ctx;timer;pointList=[];constructor(e,t){this.draw=this.draw.bind(this);var n=e.offsetWidth,o=e.offsetHeight;e.width=n,e.height=o,this.width=n,this.height=o,t&&(this.text=t.text||this.text,this.fontSize=t.fontSize||this.fontSize,this.color=t.color?hexToRgb(t.color):this.color,this.reverse=(null!=t.reverse?t:this).reverse,this.interval=t.interval||this.interval),this.oCanvas=e,this.ctx=e.getContext("2d"),this.fontLineHeight=1.2*this.fontSize,this.count=Math.ceil(this.height/this.fontLineHeight),this.getPointList(),this.draw()}draw(){if(this.isStop)return clearTimeout(this.timer);this.ctx.font=this.fontSize+'px "Microsoft YaHei"',this.ctx.textBaseline="top",this.ctx.clearRect(0,0,this.width,this.height),this.pointList.forEach(o=>{o.list.forEach((e,t)=>{let n;this.reverse?(n=(t-o.currentIndex)/10,n=1-e.speed*n,t<o.currentIndex&&(n=0)):(n=(o.currentIndex-t)/10,n=1-e.speed*n,t>o.currentIndex&&(n=0)),0<n&&(this.ctx.fillStyle=`rgba(${this.color.join(",")}, ${n})`,this.ctx.fillText(e.text,e.x,e.y))}),this.reverse?(o.currentIndex--,o.currentIndex+10<0&&(o.currentIndex=this.count+getRandom(0,this.count))):(o.currentIndex++,o.currentIndex-10>o.list.length-1&&(o.currentIndex=-getRandom(0,this.count)))}),clearTimeout(this.timer),this.timer=setTimeout(this.draw,this.interval)}createColumn(t,e){const n=[];for(let e=0;e<this.count;e++){var o=getRandom(0,this.text.length-1);n.push({text:this.text[o],x:t,y:Math.floor(e*this.fontLineHeight),speed:1})}return{currentIndex:e,list:n}}dispose(){this.isStop=!0,clearTimeout(this.timer)}start(){this.isStop=!1,this.draw()}getPointList(){const o=[];var i=this.fontSize,e=Math.floor(this.width/i);for(let n=0;n<e;n++){let t=0;for(let e=0;e<this.count&&(e?t+=getRandom(t+10,this.count):t+=getRandom(t,10),!(t>this.count));e++)this.reverse?o.push(this.createColumn(n*i,this.count+t)):o.push(this.createColumn(n*i,-t))}return this.pointList=o}}class SeamlessRolling{_wrapper;_timer=-1;constructor(e){this._wrapper=e,this._updateContent()}_updateContent(){const e=this._wrapper.children[0];var t=e.cloneNode(!0);this._wrapper.appendChild(t),console.log("firstNode",e,t)}_doScroll(){clearTimeout(this._timer),this._timer=setTimeout(()=>{},60)}dispose(){clearTimeout(this._timer)}}var synth=window.speechSynthesis,utterance=new SpeechSynthesisUtterance;let voidList=[];function oVoidListChange(e){voidList=synth.getVoices()}async function readyLanguage(o){function i(e){console.log("朗读错误",e)}utterance.addEventListener("error",i);let r;return new Promise(function(e){function t(){clearTimeout(r),synth.cancel(),utterance.removeEventListener("error",i),utterance.removeEventListener("start",t),e()}!function n(){utterance.voice=o,utterance.text=1..toString(),synth.speak(utterance),clearTimeout(r),utterance.removeEventListener("start",t),utterance.addEventListener("start",t),r=setTimeout(n,1e3)}()})}async function speakText(e,t){synth.cancel(),utterance.rate=1,utterance.pitch=1,await variableHasValue["async"](function(){return 0<voidList.length});var n=voidList.find(e=>trim(e.name,"*")===trim(t.language,"*"))||voidList[0];utterance.lang=n.lang,await readyLanguage(n),utterance.text=e,synth.speak(utterance)}function func01(e){return navigator.clipboard.writeText(e)}async function func02(e){const t=document.createElement("textarea");t.value=e,document.body.appendChild(t),t.select(),document.execCommand("copy"),document.body.removeChild(t)}synth.addEventListener("voiceschanged",oVoidListChange),window.addEventListener("beforeunload",function(e){return synth.cancel(),synth.removeEventListener("voiceschanged",oVoidListChange),!1});const copyText=$browserGlobal.navigator?.clipboard?.writeText?func01:func02;function rgbStringToList(e){e=e.replace(/^rgba\((.*)\)$/,"$1");const t=split(e,",");return t.map(function(e){return _Number(e)})}function getColorByRadio(e,t,n){n=Math.min(n,1);var[e,o,i]=rgbStringToList(hexToRgba(e)),[t,r,a]=rgbStringToList(hexToRgba(t)),t=Math.round(e+(t-e)*n),e=Math.round(o+(r-o)*n),r=Math.round(i+(a-i)*n);return rgbaToHex(`rgba(${t},${e},${r},1)`)}function convertColors(t){t.sort(function(e,t){return e.data-t.data});const n=[];var e=min(t,function(e){return e.data}),o=max(t,function(e){return e.data}),i=o-e;let r=0;for(let e=1;e<t.length;e++){var a=t[e-1],s=t[e],l=(s.data-a.data)/i,c=r+l;n.push({from:{value:a.data,color:a.color,ratio:r},to:{value:s.data,color:s.color,ratio:c},ratio:l,label:a.data+"至"+s.data}),r=c}return console.log("转换",n),{data:n,max:o,min:e}}class LinearGradientColorLegend{_cfg;_canvas;_colorList=[];_ctx;_minValue=0;_maxValue=0;constructor(e){this._cfg=Object.assign({fontSize:14,fontFamily:"Microsoft YaHei",tickWidth:5,paddingTop:10,paddingBottom:10,tickColor:"#92949b",fontColor:"#444",colors:[]},e),this.setColors(this._cfg.colors)}mount(e){this._canvas=e,this._ctx=e.getContext("2d"),this._draw()}_drawAxias(n,e){const o=this._ctx;var{fontFamily:t,fontSize:i,tickWidth:r,paddingTop:a,paddingBottom:s}=this._cfg,l=(o.font=i+"px "+t,3*i),c=e-s-a,d=Math.ceil(c/l),l=c/d;o.textBaseline="middle";let u=0;const h=[];for(let e=0;e<=d;e++){var f=1-e/d,f=roundFixed(f*(this._maxValue-this._minValue)+this._minValue,2),g=o.measureText(f);u=Math.max(g.width,u),h.push({label:f,width:g.width})}for(let t=0;t<h.length;t++){var m=h[t];let e=0;e=0===t?0:t===h.length-1?c-1:Math.floor(t*l),e+=a;var p=n-u-4-r;o.fillStyle=this._cfg.tickColor,o.fillRect(p,e,r,1),o.fillStyle=this._cfg.fontColor,o.fillText(m.label,p+r+4,e)}return{maxLabelWidth:4+u+r}}_draw(){if(!this._canvas||!this._ctx)return this;var{paddingTop:t,paddingBottom:e}=this._cfg,n=this._canvas.offsetWidth,o=this._canvas.offsetHeight,i=(this._canvas.width=n,this._canvas.height=o,this._ctx.clearRect(0,0,n,o),this._drawAxias(n,o))["maxLabelWidth"],r=o-t-e;for(let e=0;e<this._colorList.length;e++){var a=this._colorList[e],s=r*(1-a.to.ratio),l=r*(1-a.from.ratio),s=Math.ceil(s+t),l=Math.ceil(l+t);const c=this._ctx.createLinearGradient(0,s,0,l);c.addColorStop(1,a.from.color),c.addColorStop(0,a.to.color),this._ctx.fillStyle=c,this._ctx.fillRect(0,s,n-i,l-s)}}setColors(e){return e.length<2||(e=convertColors(e),this._colorList=e.data,this._minValue=e.min,this._maxValue=e.max,this._draw()),this}getColor(t){if(!this._colorList.length)return"#0000";!isNaN(t)&&"Number"===getType(t)||(t=this._colorList[0].from.value);var e=this._colorList.find(function(e){return t>=e.from.value&&t<e.to.value})??this._colorList[this._colorList.length-1],n=Math.min(t/(e.to.value-e.from.value),1);return getColorByRadio(e.from.color,e.to.color,n)}}const textCanvas=document.createElement("canvas");function createRotatedRectCanvas(e){var t=e.angle*Math.PI/180;const o=textCanvas.getContext("2d");o.font=e.fontSize+"px "+e.fontFamily;let i=0;const r=[],a=(e.text.forEach(function(e){e=o.measureText(e);r.push(e.width),i=Math.max(e.width,i)}),e.fontSize*e.fontLineHeight),s=a*e.text.length;var n=Math.abs(i*Math.cos(t))+Math.abs(s*Math.sin(t)),l=Math.abs(i*Math.sin(t))+Math.abs(s*Math.cos(t));textCanvas.width=n,textCanvas.height=l,o.translate(n/2,l/2),o.rotate(t),o.fillStyle=e.fontBackgroundColor,o.fillRect(-i/2,-s/2,i,s),o.fillStyle=e.fontColor,o.font=e.fontSize+"px "+e.fontFamily,o.textBaseline="top",o.textAlign="left";const c=(a-e.fontSize)/2;return e.text.forEach(function(e,t){var n=i/2-r[t]/2;o.fillText(e,-i/2+n,-s/2+t*a+c)}),{img:textCanvas,width:n,height:l}}class WaterMark{_cfg;_oWrapper;_canvas;constructor(e,t){this._oWrapper=e,this._cfg=Object.assign({fontFamily:"Microsoft YaHei",fontLineHeight:1.4,gapX:20,gapY:0,fontBackgroundColor:"rgba(0,0,0,0)",angle:-45,text:["作者 bestime","2025-04-09"],fontSize:16,fontColor:"red"},t),this._canvas=this._reload(),this._draw()}_reload(){let e=this._canvas;return e||(e=document.createElement("canvas"),this._oWrapper.appendChild(e)),e}setConfig(e){Object.assign(this._cfg,e),this._draw()}_draw(){const e=this._reload();var n=this._oWrapper.offsetWidth*window.devicePixelRatio,o=this._oWrapper.offsetHeight*window.devicePixelRatio;e.width=n,e.height=o,e.style.cssText="position:absolute;left:0;top:0;right:0;bottom:0;z-index: 1;user-select: none;pointer-events: none;",e.style.width=this._oWrapper.offsetWidth+"px",e.style.height=this._oWrapper.offsetHeight+"px";const i=e.getContext("2d");if(i&&(i.clearRect(0,0,n,o),!this._cfg.disabled)){var r=createRotatedRectCanvas(this._cfg);for(let t=0;t<n;t+=r.width+this._cfg.gapX)for(let e=0;e<o;e+=r.height+this._cfg.gapY)i.drawImage(r.img,t,e)}}}function fillHtml(e,t){e.styleSheet?e.styleSheet.cssText=t:e.innerHTML=t}let id=0;function createStyle(e){id++,(e=trim(e))&&!/^[0-9]/.test(e)||(e="bt-style-"+id);var t,i="",n=document.createElement("style");return n.className=e,document.getElementsByTagName("head")[0].appendChild(n),function(e){var o;t=i,_String(e).replace(/(.*?)({.*?})/g,function(e,t,n){return t=trim(t),i=i.replace(new RegExp("("+t+"\\s*?)({.*?})","g"),function(){return o=!0,t+trim(n)}),""}),o?t!==i&&fillHtml(n,i):(i+=_String(e),fillHtml(n,i))}}const style=createStyle("bt-browser-core");export{LinearGradientColorLegend,SeamlessRolling,TextRainCanvas,WaterMark,addClass,browser,copyText,createXLSX,downloadFileByArrayBuffer,downloadFileByBolb,downloadFileByUrl,fullScreen,getCookie,getJsFileBaseUrl,getRatio,getRelativePos,getStorage,getWindowSize,infoContainerPosition,libraryFile,observeDomResize,observeDomScroll,observeMouseWheel,pdfToImage,prevent,removeClass,removeCookie,removeElement,removeStorage,replaceClass,setCookie,setStorage,speakText,style,toggleClass};
5
+ import{defualtFormatter,isString,variableHasValue,isArray,forEach,_KvPair,_Number,parseTreeToTableHeader,isNull,getRandom,roundFixed,getType,hexToRgba,rgbaToHex,min,max,split,trim,_String}from"@bestime/utils_base";function getWindowSize(){return{width:document.documentElement.clientWidth||document.body.clientWidth||window.innerWidth||0,height:document.documentElement.clientHeight||document.body.clientHeight||window.innerHeight||0}}let htivId=0,idName="",isStart=!1;const records={};let timer;function stop(){isStart=!1,clearInterval(timer),timer=undefined}function startRun(){clearInterval(timer),isStart=!0,timer=setInterval(function(){for(var t in records){const e=records[t];e.current=+new Date,e.current-e.start>=e.interval&&(e.start=e.current,records[t].handler())}},17)}function add(t,e){return idName="HI-"+ ++htivId,records[idName]={start:+new Date,current:0,handler:t,interval:e},isStart||startRun(),idName}function remove(t){delete records[t],0===Object.keys(records).length&&stop()}var hpInterval={add:add,remove:remove};function observeDomResize(o,n,i,t){let r=[0,0,!1],a=[0,0,!1],l=[0,0,!1],s=[0,0,!1];const e=hpInterval.add(c,t=t||500);function c(){if(document.body.contains(o)){let t=!1;var e;i?.includes("position")&&(e=o.getBoundingClientRect(),l[0]=e.left,l[2]=l[0]!==l[1],s[0]=e.top,s[2]=s[0]!==s[1]),r[0]=o.offsetWidth,r[2]=r[0]!==r[1],a[0]=o.offsetHeight,a[2]=a[0]!==a[1],r[2]&&(r[1]=r[0],i?.includes("width")&&(t=!0)),a[2]&&(a[1]=a[0],i?.includes("height")&&(t=!0)),(s[2]||l[2])&&(s[1]=s[0],l[1]=l[0],i?.includes("position")&&(t=!0)),i&&0!==i.length||(r[2]||a[2]||s[2]||l[2])&&(t=!0),t&&n(o)}else d()}function d(){hpInterval.remove(e),r=undefined,a=undefined}return c(),d}function downloadFileByUrl(t,e){const o=document.createElement("a");o.style.display="none",o.download=e,o.setAttribute("href",t),o.setAttribute("target","_blank"),o.setAttribute("download",e),document.body.appendChild(o),o.click(),o.remove()}const $undefinedValue=void 0,$decodeURIComponent=decodeURIComponent,$browserGlobal=window,$headElement=document.getElementsByTagName("head")[0],iUrl=$browserGlobal.URL;function downloadFileByBolb(t,e){t=iUrl.createObjectURL(t);downloadFileByUrl(t,e),iUrl.revokeObjectURL(t),undefined}function downloadFileByArrayBuffer(t,e){downloadFileByBolb(new Blob([t]),e)}function removeElement(t){t.parentNode&&t.parentNode.removeChild(t)}function prevent(t,e,o){t=t||$browserGlobal.event,o=!1!==o,(e=!1!==e)&&$browserGlobal.event?$browserGlobal.event.cancelBubble=!0:t.stopPropagation(),o&&$browserGlobal.event?$browserGlobal.event.returnValue=!1:t.preventDefault()}function getStorage(t){t=localStorage.getItem(t);return defualtFormatter("",t)}function removeStorage(t){localStorage.removeItem(t)}function hpSetStringValue(t){return t=isString(t)?t:JSON.stringify(t)}function setStorage(t,e){localStorage.setItem(t,hpSetStringValue(e))}function getRelativePos(t){var e=t.getBoundingClientRect();return{x:e.left,y:e.top,height:t.offsetHeight,width:t.offsetWidth,clientWidth:t.clientWidth,clientHeight:t.clientHeight}}function getJsFileBaseUrl(t){t=t||0;for(var e="/[^/]*",o=document.scripts,n=0;n<t;n++)e+=e;return o[o.length-1].src.replace(new RegExp(e+"$"),"")}function hpCreateFileLoaderElement(e,o,n,i){if($headElement){let t;if("js"===e?(t=document.createElement("script")).src=o:((t=document.createElement("link")).setAttribute("rel","stylesheet"),t.href=o),i)for(var r in i)t.setAttribute(r,i[r]);t.onload=t.onerror=n,$headElement.appendChild(t)}}const cache={};function loadMultiple(o,n){const i=[];let r=0;for(let e=0;e<o.length;e++)loadSingle(o[e],function(t){i[e]=t,++r===o.length&&n.apply($undefinedValue,i)})}function loadSingle(t,e){var o=t.dependencies&&t.dependencies.length,n=t["with"]&&t["with"].length;cache[t.url]||(cache[t.url]={count:0,dependencies:!o,"with":!n,complete:!1,create:!1,url:t.url});const i=cache[t.url];function r(){return $browserGlobal[t.module]}function a(){i.complete&&i.dependencies&&i["with"]&&(t.module?e(r()):e())}i.count++,!i.dependencies&&o?(i.dependencies=!0,loadMultiple(t.dependencies,function(){loadSingle(t,e)})):!i["with"]&&n?(i["with"]=!0,loadMultiple(t["with"].concat(t),a)):i.create?variableHasValue(function(){return i.complete},a,300):(i.create=!0,hpCreateFileLoaderElement(t.type,t.url,function(){i.complete=!0,t.interceptor&&t.interceptor(r()),a()},t.attribute))}function libraryFile(t,e){(t instanceof Array?loadMultiple:loadSingle)(t,e)}function setObjectToString(t){return t=isString(t)?t:JSON.stringify(t)}function setCookie(t,e,o){e=setObjectToString(e);let n=t+"="+encodeURI(e)+";path=/;";"number"==typeof o&&((t=new Date).setTime(t.getTime()+o),n+="expires="+t.toUTCString()),document.cookie=n}function getCookie(t,e){e=e||document.cookie;let n="";return e.replace(new RegExp("(^|;\\s?)"+t+"=(.*?)($|(;\\s?))"),function(t,e,o){n=$decodeURIComponent(o)}),n}function removeCookie(t){setCookie(t,"",-1)}function removeClass(e,t){isArray(t)?forEach(t,function(t){e.classList.remove(t)}):e.classList.remove(t)}function addClass(e,t){isArray(t)?forEach(t,function(t){e.classList.add(t)}):e.classList.add(t)}function replaceClass(t,e,o){removeClass(t,e),addClass(t,o)}function toggleClass(e,t){isArray(t)?forEach(t,function(t){e.classList.toggle(t)}):e.classList.toggle(t)}const agent=$browserGlobal.navigator.userAgent;var browser={isChrome:/Chrome/.test(agent),isIPhone:/iPhone/.test(agent)};function getRatio(){return window.devicePixelRatio||1}function observeMouseWheel(t,o,n){function e(t){let e;if(e=t.wheelDelta?0<t.wheelDelta?1:-1:t.detail<0?1:-1,o(e),n)return t.preventDefault&&t.preventDefault(),!1}return t.addEventListener("mousewheel",e),t.addEventListener("DOMMouseScroll",e),{dispose:function(){t.removeEventListener("mousewheel",e),t.removeEventListener("DOMMouseScroll",e)}}}function observeDomScroll(o,t){const n=_KvPair(t),i=_Number(n.offetY);let r=!1,a=0;function e(){var t,e;r||(e=(t=o.scrollTop)-a,a=t,0!=e?e<0&&n.onTop&&t<=0+i?(r=!0,n.onTop(function(){r=!1})):0<e&&n.onBottom&&t>=o.scrollHeight-o.offsetHeight-i?(r=!0,n.onBottom(function(){r=!1})):r=!1:(r=!1,console.log("未处理")))}return o.addEventListener("scroll",e),{dispose:function(){o.removeEventListener("scroll",e)}}}const defaultCallback=t=>{};function open(t,e){const o=e||defaultCallback;t.requestFullscreen?t.requestFullscreen():t.webkitRequestFullScreen?t.webkitRequestFullScreen():t.mozRequestFullScreen?t.mozRequestFullScreen():t.msRequestFullscreen&&t.msRequestFullscreen(),o(!0)}function close(t){const e=t||defaultCallback,o=document;document.exitFullscreen?document.exitFullscreen().then(function(){e(!0)})["catch"](function(){e(!1)}):o.webkitCancelFullScreen?(o.webkitCancelFullScreen(),e(!0)):o.mozCancelFullScreen?(o.mozCancelFullScreen(),e(!0)):o.msExitFullscreen&&(o.msExitFullscreen(),e(!0))}function fullScreen(t,e,o){e?open(t,o):close(o)}async function createXLSX(t){const e=document.createElement("table"),o=parseTreeToTableHeader(t.header);var n=o.data.map(function(t){return`<tr>${t.map(function(t){if(t&&0!==t.colSpan)return`<td align="center" rowSpan="${t.rowSpan}" colSpan="${t.colSpan}">${t?.title}</td>`}).join("")}</tr>`}).join(""),t=t.body.map(function(n){return`<tr>${o.columns.map(function(t){var e=n.$colField?.[t]??1,o=n.$rowSpan?.[t]??1;if(0!==e&&0!==o)return`<td align="center" colSpan="${e}" rowSpan="${o}">${n[t]??""}</td>`}).filter(function(t){return!isNull(t)}).join("")}</tr>`}).join("");return e.innerHTML=`<thead>${n}</thead><tbody>${t}</tbody>`,e.setAttribute("border","1"),e}async function loadPdfPlugin(e){return new Promise(function(t){libraryFile({type:"js",module:"pdfjsLib",attribute:{type:"module"},url:e.index,interceptor:function(t){t.GlobalWorkerOptions.workerSrc=e.worker}},t)})}async function pdfToImage(t,i,e){const o=await loadPdfPlugin(e);return new Promise(function(n){o.getDocument(t).promise.then(function(t){console.log("pdf",t),t.getPage(1).then(function(t){var e=t.getViewport({scale:1}),o=i.getContext("2d");i.height=e.height,i.width=e.width,t.render({canvasContext:o,viewport:e}).promise.then(function(){n({width:e.width,height:e.height})})})},function(t){console.error(t),n({width:0,height:0})})})}function infoContainerPosition(t){var e=t.mode||"top-right",o=t.width,n=t.height,i=defualtFormatter(10,t.offsetY),r=defualtFormatter(10,t.offsetX),a=defualtFormatter(10,t.padding);let l=t.x,s=t.y;var t=t.targetSize||getWindowSize(),c=[a,t.width-o-a],t=[a,t.height-n-a];return"top-right"===e?(l+=r,s=s-n-i,l<c[0]?l=c[0]:l>c[1]&&(a=l-o-2*r,l=c[0]<a?a:c[1]),s<t[0]?(a=s+n+2*i,s=a<t[1]?a:t[0]):s>t[1]&&(s=s-n-2*i)):"bottom-right"===e?(l+=r,(s+=i)>t[1]&&(a=s-n-2*i,s=a<t[0]?t[1]:a),l>c[1]&&(t=l-o-2*r,l=t<c[0]?c[1]:t)):"top-left"===e&&(l=l-o-r,s=s-n-i),{x:l,y:s}}function hexToRgb(t){for(var e=[],o=1;o<7;o+=2)e.push(parseInt("0x"+t.slice(o,o+2)));return e}class TextRainCanvas{text="abcdefghijklmnopqrstuvwxyz";fontSize=14;color=[0,255,0];reverse=!1;isStop=!1;interval=100;width;height;fontLineHeight;count;oCanvas;ctx;timer;pointList=[];constructor(t,e){this.draw=this.draw.bind(this);var o=t.offsetWidth,n=t.offsetHeight;t.width=o,t.height=n,this.width=o,this.height=n,e&&(this.text=e.text||this.text,this.fontSize=e.fontSize||this.fontSize,this.color=e.color?hexToRgb(e.color):this.color,this.reverse=(null!=e.reverse?e:this).reverse,this.interval=e.interval||this.interval),this.oCanvas=t,this.ctx=t.getContext("2d"),this.fontLineHeight=1.2*this.fontSize,this.count=Math.ceil(this.height/this.fontLineHeight),this.getPointList(),this.draw()}draw(){if(this.isStop)return clearTimeout(this.timer);this.ctx.font=this.fontSize+'px "Microsoft YaHei"',this.ctx.textBaseline="top",this.ctx.clearRect(0,0,this.width,this.height),this.pointList.forEach(n=>{n.list.forEach((t,e)=>{let o;this.reverse?(o=(e-n.currentIndex)/10,o=1-t.speed*o,e<n.currentIndex&&(o=0)):(o=(n.currentIndex-e)/10,o=1-t.speed*o,e>n.currentIndex&&(o=0)),0<o&&(this.ctx.fillStyle=`rgba(${this.color.join(",")}, ${o})`,this.ctx.fillText(t.text,t.x,t.y))}),this.reverse?(n.currentIndex--,n.currentIndex+10<0&&(n.currentIndex=this.count+getRandom(0,this.count))):(n.currentIndex++,n.currentIndex-10>n.list.length-1&&(n.currentIndex=-getRandom(0,this.count)))}),clearTimeout(this.timer),this.timer=setTimeout(this.draw,this.interval)}createColumn(e,t){const o=[];for(let t=0;t<this.count;t++){var n=getRandom(0,this.text.length-1);o.push({text:this.text[n],x:e,y:Math.floor(t*this.fontLineHeight),speed:1})}return{currentIndex:t,list:o}}dispose(){this.isStop=!0,clearTimeout(this.timer)}start(){this.isStop=!1,this.draw()}getPointList(){const n=[];var i=this.fontSize,t=Math.floor(this.width/i);for(let o=0;o<t;o++){let e=0;for(let t=0;t<this.count&&(t?e+=getRandom(e+10,this.count):e+=getRandom(e,10),!(e>this.count));t++)this.reverse?n.push(this.createColumn(o*i,this.count+e)):n.push(this.createColumn(o*i,-e))}return this.pointList=n}}class SeamlessRolling{_wrapper;_timer;constructor(t){this._wrapper=t,this._updateContent()}_updateContent(){const t=this._wrapper.children[0];var e=t.cloneNode(!0);this._wrapper.appendChild(e),console.log("firstNode",t,e)}_doScroll(){clearTimeout(this._timer),this._timer=setTimeout(()=>{},60)}dispose(){clearTimeout(this._timer)}}function func01(t){return navigator.clipboard.writeText(t)}async function func02(t){const e=document.createElement("textarea");e.value=t,document.body.appendChild(e),e.select(),document.execCommand("copy"),document.body.removeChild(e)}const copyText=$browserGlobal.navigator?.clipboard?.writeText?func01:func02;function rgbStringToList(t){t=t.replace(/^rgba\((.*)\)$/,"$1");const e=split(t,",");return e.map(function(t){return _Number(t)})}function getColorByRadio(t,e,o){o=Math.max(o,0),o=Math.min(o,1);var[t,n,i]=rgbStringToList(hexToRgba(t)),[e,r,a]=rgbStringToList(hexToRgba(e)),e=Math.round(t+(e-t)*o),t=Math.round(n+(r-n)*o),r=Math.round(i+(a-i)*o);return rgbaToHex(`rgba(${e},${t},${r},1)`)}function convertColors(e){e.sort(function(t,e){return t.data-e.data});const o=[];var t=min(e,function(t){return t.data}),n=max(e,function(t){return t.data}),i=n-t;let r=0;for(let t=1;t<e.length;t++){var a=e[t-1],l=e[t],s=(l.data-a.data)/i,c=r+s;o.push({from:{value:a.data,color:a.color,ratio:r},to:{value:l.data,color:l.color,ratio:c},ratio:s,label:a.data+"至"+l.data}),r=c}return{data:o,max:n,min:t}}class LinearGradientColorLegend{_cfg;_canvas;_colorList=[];_ctx;_minValue=0;_maxValue=0;constructor(t){this._cfg=Object.assign({fontSize:14,fontFamily:"Microsoft YaHei",tickWidth:5,paddingTop:10,paddingBottom:10,tickColor:"#92949b",fontColor:"#444",colors:[]},t),this.setColors(this._cfg.colors)}mount(t){this._canvas=t,this._ctx=t.getContext("2d"),this._draw()}_drawAxias(o,t){const n=this._ctx;var{fontFamily:e,fontSize:i,tickWidth:r,paddingTop:a,paddingBottom:l}=this._cfg,s=(n.font=i+"px "+e,3*i),c=t-l-a,d=Math.ceil(c/s),s=c/d;n.textBaseline="middle";let h=0;const u=[];for(let t=0;t<=d;t++){var f=(1-t/d)*(this._maxValue-this._minValue)+this._minValue,f=this._cfg.labelFormatter?this._cfg.labelFormatter(f):roundFixed(f,2),m=n.measureText(f);h=Math.max(m.width,h),u.push({label:f,width:m.width})}for(let e=0;e<u.length;e++){var g=u[e];let t=0;t=0===e?0:e===u.length-1?c-1:Math.floor(e*s),t+=a;var p=o-h-4-r;n.fillStyle=this._cfg.tickColor,n.fillRect(p,t,r,1),n.fillStyle=this._cfg.fontColor,n.fillText(g.label,p+r+4,t)}return{maxLabelWidth:4+h+r}}_draw(){if(!this._canvas||!this._ctx)return this;var{paddingTop:e,paddingBottom:t}=this._cfg,o=this._canvas.offsetWidth,n=this._canvas.offsetHeight,i=(this._canvas.width=o,this._canvas.height=n,this._ctx.clearRect(0,0,o,n),this._drawAxias(o,n))["maxLabelWidth"],r=n-e-t;for(let t=0;t<this._colorList.length;t++){var a=this._colorList[t],l=r*(1-a.to.ratio),s=r*(1-a.from.ratio),l=Math.ceil(l+e),s=Math.ceil(s+e);const c=this._ctx.createLinearGradient(0,l,0,s);c.addColorStop(1,a.from.color),c.addColorStop(0,a.to.color),this._ctx.fillStyle=c,this._ctx.fillRect(0,l,o-i,s-l)}}setColors(t){return t.length<2||(t=convertColors(t),this._colorList=t.data,this._minValue=t.min,this._maxValue=t.max,this._draw()),this}getColor(e){if(!this._colorList.length)return"#0000";!isNaN(e)&&"Number"===getType(e)||(e=this._colorList[0].from.value);var t=this._colorList.find(function(t){return e>=t.from.value&&e<t.to.value});let o;o=t||(e<this._colorList[0].from.value?this._colorList[0]:this._colorList[this._colorList.length-1]);t=e-o.from.value,t=Math.min(t/(o.to.value-o.from.value),1);return getColorByRadio(o.from.color,o.to.color,t)}}const textCanvas=document.createElement("canvas");function createRotatedRectCanvas(t){var e=t.angle*Math.PI/180;const n=textCanvas.getContext("2d");n.font=t.fontSize+"px "+t.fontFamily;let i=0;const r=[],a=(t.text.forEach(function(t){t=n.measureText(t);r.push(t.width),i=Math.max(t.width,i)}),t.fontSize*t.fontLineHeight),l=a*t.text.length;var o=Math.abs(i*Math.cos(e))+Math.abs(l*Math.sin(e)),s=Math.abs(i*Math.sin(e))+Math.abs(l*Math.cos(e));textCanvas.width=o,textCanvas.height=s,n.translate(o/2,s/2),n.rotate(e),n.fillStyle=t.fontBackgroundColor,n.fillRect(-i/2,-l/2,i,l),n.fillStyle=t.fontColor,n.font=t.fontSize+"px "+t.fontFamily,n.textBaseline="top",n.textAlign="left";const c=(a-t.fontSize)/2;return t.text.forEach(function(t,e){var o=i/2-r[e]/2;n.fillText(t,-i/2+o,-l/2+e*a+c)}),{img:textCanvas,width:o,height:s}}class WaterMark{_cfg;_oWrapper;_canvas;constructor(t,e){this._oWrapper=t,this._cfg=Object.assign({fontFamily:"Microsoft YaHei",fontLineHeight:1.4,gapX:20,gapY:0,fontBackgroundColor:"rgba(0,0,0,0)",angle:-45,text:["作者 bestime","2025-04-09"],fontSize:16,fontColor:"red"},e),this._canvas=this._reload(),this._draw()}_reload(){let t=this._canvas;return t||(t=document.createElement("canvas"),this._oWrapper.appendChild(t)),t}setConfig(t){Object.assign(this._cfg,t),this._draw()}_draw(){const t=this._reload();var o=this._oWrapper.offsetWidth*window.devicePixelRatio,n=this._oWrapper.offsetHeight*window.devicePixelRatio;t.width=o,t.height=n,t.style.cssText="position:absolute;left:0;top:0;right:0;bottom:0;z-index: 1;user-select: none;pointer-events: none;",t.style.width=this._oWrapper.offsetWidth+"px",t.style.height=this._oWrapper.offsetHeight+"px";const i=t.getContext("2d");if(i&&(i.clearRect(0,0,o,n),!this._cfg.disabled)){var r=createRotatedRectCanvas(this._cfg);for(let e=0;e<o;e+=r.width+this._cfg.gapX)for(let t=0;t<n;t+=r.height+this._cfg.gapY)i.drawImage(r.img,e,t)}}}function fillHtml(t,e){t.styleSheet?t.styleSheet.cssText=e:t.innerHTML=e}let id=0;function createStyle(t){id++,(t=trim(t))&&!/^[0-9]/.test(t)||(t="bt-style-"+id);var e,i="",o=document.createElement("style");return o.className=t,document.getElementsByTagName("head")[0].appendChild(o),function(t){var n;e=i,_String(t).replace(/(.*?)({.*?})/g,function(t,e,o){return e=trim(e),i=i.replace(new RegExp("("+e+"\\s*?)({.*?})","g"),function(){return n=!0,e+trim(o)}),""}),n?e!==i&&fillHtml(o,i):(i+=_String(t),fillHtml(o,i))}}const style=createStyle("bt-browser-core");export{LinearGradientColorLegend,SeamlessRolling,TextRainCanvas,WaterMark,addClass,browser,copyText,createXLSX,downloadFileByArrayBuffer,downloadFileByBolb,downloadFileByUrl,fullScreen,getCookie,getJsFileBaseUrl,getRatio,getRelativePos,getStorage,getWindowSize,infoContainerPosition,libraryFile,observeDomResize,observeDomScroll,observeMouseWheel,pdfToImage,prevent,removeClass,removeCookie,removeElement,removeStorage,replaceClass,setCookie,setStorage,style,toggleClass};
@@ -336,28 +336,13 @@ declare class TextRainCanvas {
336
336
 
337
337
  declare class SeamlessRolling {
338
338
  _wrapper: HTMLDivElement;
339
- _timer: number;
339
+ _timer: any;
340
340
  constructor(wraper: HTMLDivElement);
341
341
  _updateContent(): void;
342
342
  _doScroll(): void;
343
343
  dispose(): void;
344
344
  }
345
345
 
346
- type Tlanguage =
347
- | 'Microsoft Huihui - Chinese (Simplified, PRC)'
348
- | 'Microsoft Kangkang - Chinese (Simplified, PRC)'
349
- | 'Microsoft Kangkang - Chinese (Simplified, PRC)'
350
- | 'Microsoft Yaoyao - Chinese (Simplified, PRC)'
351
- | 'Google 한국의'
352
- | 'Google 日本語'
353
- | 'Google 粤語(香港)';
354
- declare function speakText(
355
- message: string,
356
- options: {
357
- language?: Tlanguage;
358
- }
359
- ): Promise<void>;
360
-
361
346
  declare function func01(text: string): Promise<void>;
362
347
  /**
363
348
  * 复制文本
@@ -376,6 +361,7 @@ interface IOptions$1 {
376
361
  fontColor: string;
377
362
  paddingTop: number;
378
363
  paddingBottom: number;
364
+ labelFormatter?: (data: number) => string;
379
365
  colors: IColorItem[];
380
366
  }
381
367
  interface IUseColorItem {
@@ -481,7 +467,6 @@ declare global {
481
467
  replaceClass,
482
468
  setCookie,
483
469
  setStorage,
484
- speakText,
485
470
  style,
486
471
  toggleClass
487
472
  };
@@ -1,5 +1,5 @@
1
1
  /**
2
2
  * 浏览器工具库 => jUtilsBrowser
3
- * @update 2025-04-22 10:03:23
3
+ * @update 2025-08-06 10:49:02
4
4
  */
5
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@bestime/utils_base")):"function"==typeof define&&define.amd?define(["exports","@bestime/utils_base"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).jUtilsBrowser={},t.jUtilsBase)}(this,function(t,v){"use strict";function h(){return{width:document.documentElement.clientWidth||document.body.clientWidth||window.innerWidth||0,height:document.documentElement.clientHeight||document.body.clientHeight||window.innerHeight||0}}let n=0,i,o=!1;const r={};let s;var u={add:function(t,e){return i="HI-"+ ++n,r[i]={start:+new Date,current:0,handler:t,interval:e},o||(clearInterval(s),o=!0,s=setInterval(function(){for(var t in r){const e=r[t];e.current=+new Date,e.current-e.start>=e.interval&&(e.start=e.current,r[t].handler())}},17)),i},remove:function(t){delete r[t],0===Object.keys(r).length&&(o=!1,clearInterval(s),s=undefined)}};function a(t,e){const n=document.createElement("a");n.style.display="none",n.download=e,n.setAttribute("href",t),n.setAttribute("target","_blank"),n.setAttribute("download",e),document.body.appendChild(n),n.click(),n.remove()}const c=void 0,z=decodeURIComponent,d=window,f=document.getElementsByTagName("head")[0],l=d.URL;function m(t,e){t=l.createObjectURL(t);a(t,e),l.revokeObjectURL(t),undefined}const g={};function p(n,i){const o=[];let r=0;for(let e=0;e<n.length;e++)w(n[e],function(t){o[e]=t,++r===n.length&&i.apply(c,o)})}function w(t,e){var n=t.dependencies&&t.dependencies.length,i=t["with"]&&t["with"].length;g[t.url]||(g[t.url]={count:0,dependencies:!n,"with":!i,complete:!1,create:!1,url:t.url});const o=g[t.url];function r(){return d[t.module]}function s(){o.complete&&o.dependencies&&o["with"]&&(t.module?e(r()):e())}if(o.count++,!o.dependencies&&n)o.dependencies=!0,p(t.dependencies,function(){w(t,e)});else if(!o["with"]&&i)o["with"]=!0,p(t["with"].concat(t),s);else if(o.create)v.variableHasValue(function(){return o.complete},s,300);else{o.create=!0;var n=t.type,i=t.url,a=function(){o.complete=!0,t.interceptor&&t.interceptor(r()),s()},c=t.attribute;if(f){let t;if("js"===n?(t=document.createElement("script")).src=i:((t=document.createElement("link")).setAttribute("rel","stylesheet"),t.href=i),c)for(var l in c)t.setAttribute(l,c[l]);t.onload=t.onerror=a,f.appendChild(t)}}}function x(t,e){(t instanceof Array?p:w)(t,e)}function e(t,e,n){var i;i=e,e=i=v.isString(i)?i:JSON.stringify(i);let o=t+"="+encodeURI(e)+";path=/;";"number"==typeof n&&((i=new Date).setTime(i.getTime()+n),o+="expires="+i.toUTCString()),document.cookie=o}function b(e,t){v.isArray(t)?v.forEach(t,function(t){e.classList.remove(t)}):e.classList.remove(t)}function _(e,t){v.isArray(t)?v.forEach(t,function(t){e.classList.add(t)}):e.classList.add(t)}var y=d.navigator.userAgent,y={isChrome:/Chrome/.test(y),isIPhone:/iPhone/.test(y)};const S=t=>{};class ${text="abcdefghijklmnopqrstuvwxyz";fontSize=14;color=[0,255,0];reverse=!1;isStop=!1;interval=100;width;height;fontLineHeight;count;oCanvas;ctx;timer;pointList=[];constructor(t,e){this.draw=this.draw.bind(this);var n=t.offsetWidth,i=t.offsetHeight;t.width=n,t.height=i,this.width=n,this.height=i,e&&(this.text=e.text||this.text,this.fontSize=e.fontSize||this.fontSize,this.color=e.color?function(t){for(var e=[],n=1;n<7;n+=2)e.push(parseInt("0x"+t.slice(n,n+2)));return e}(e.color):this.color,this.reverse=(null!=e.reverse?e:this).reverse,this.interval=e.interval||this.interval),this.oCanvas=t,this.ctx=t.getContext("2d"),this.fontLineHeight=1.2*this.fontSize,this.count=Math.ceil(this.height/this.fontLineHeight),this.getPointList(),this.draw()}draw(){if(this.isStop)return clearTimeout(this.timer);this.ctx.font=this.fontSize+'px "Microsoft YaHei"',this.ctx.textBaseline="top",this.ctx.clearRect(0,0,this.width,this.height),this.pointList.forEach(i=>{i.list.forEach((t,e)=>{let n;this.reverse?(n=(e-i.currentIndex)/10,n=1-t.speed*n,e<i.currentIndex&&(n=0)):(n=(i.currentIndex-e)/10,n=1-t.speed*n,e>i.currentIndex&&(n=0)),0<n&&(this.ctx.fillStyle=`rgba(${this.color.join(",")}, ${n})`,this.ctx.fillText(t.text,t.x,t.y))}),this.reverse?(i.currentIndex--,i.currentIndex+10<0&&(i.currentIndex=this.count+v.getRandom(0,this.count))):(i.currentIndex++,i.currentIndex-10>i.list.length-1&&(i.currentIndex=-v.getRandom(0,this.count)))}),clearTimeout(this.timer),this.timer=setTimeout(this.draw,this.interval)}createColumn(e,t){const n=[];for(let t=0;t<this.count;t++){var i=v.getRandom(0,this.text.length-1);n.push({text:this.text[i],x:e,y:Math.floor(t*this.fontLineHeight),speed:1})}return{currentIndex:t,list:n}}dispose(){this.isStop=!0,clearTimeout(this.timer)}start(){this.isStop=!1,this.draw()}getPointList(){const i=[];var o=this.fontSize,t=Math.floor(this.width/o);for(let n=0;n<t;n++){let e=0;for(let t=0;t<this.count&&(t?e+=v.getRandom(e+10,this.count):e+=v.getRandom(e,10),!(e>this.count));t++)this.reverse?i.push(this.createColumn(n*o,this.count+e)):i.push(this.createColumn(n*o,-e))}return this.pointList=i}}class j{_wrapper;_timer=-1;constructor(t){this._wrapper=t,this._updateContent()}_updateContent(){const t=this._wrapper.children[0];var e=t.cloneNode(!0);this._wrapper.appendChild(e),console.log("firstNode",t,e)}_doScroll(){clearTimeout(this._timer),this._timer=setTimeout(()=>{},60)}dispose(){clearTimeout(this._timer)}}var C=window.speechSynthesis,L=new SpeechSynthesisUtterance;let T=[];function E(t){T=C.getVoices()}C.addEventListener("voiceschanged",E),window.addEventListener("beforeunload",function(t){return C.cancel(),C.removeEventListener("voiceschanged",E),!1});var P=d.navigator?.clipboard?.writeText?function(t){return navigator.clipboard.writeText(t)}:async function(t){const e=document.createElement("textarea");e.value=t,document.body.appendChild(e),e.select(),document.execCommand("copy"),document.body.removeChild(e)};function R(t){t=t.replace(/^rgba\((.*)\)$/,"$1");const e=v.split(t,",");return e.map(function(t){return v._Number(t)})}class A{_cfg;_canvas;_colorList=[];_ctx;_minValue=0;_maxValue=0;constructor(t){this._cfg=Object.assign({fontSize:14,fontFamily:"Microsoft YaHei",tickWidth:5,paddingTop:10,paddingBottom:10,tickColor:"#92949b",fontColor:"#444",colors:[]},t),this.setColors(this._cfg.colors)}mount(t){this._canvas=t,this._ctx=t.getContext("2d"),this._draw()}_drawAxias(n,t){const i=this._ctx;var{fontFamily:e,fontSize:o,tickWidth:r,paddingTop:s,paddingBottom:a}=this._cfg,c=(i.font=o+"px "+e,3*o),l=t-a-s,h=Math.ceil(l/c),c=l/h;i.textBaseline="middle";let u=0;const d=[];for(let t=0;t<=h;t++){var f=1-t/h,f=v.roundFixed(f*(this._maxValue-this._minValue)+this._minValue,2),m=i.measureText(f);u=Math.max(m.width,u),d.push({label:f,width:m.width})}for(let e=0;e<d.length;e++){var g=d[e];let t=0;t=0===e?0:e===d.length-1?l-1:Math.floor(e*c),t+=s;var p=n-u-4-r;i.fillStyle=this._cfg.tickColor,i.fillRect(p,t,r,1),i.fillStyle=this._cfg.fontColor,i.fillText(g.label,p+r+4,t)}return{maxLabelWidth:4+u+r}}_draw(){if(!this._canvas||!this._ctx)return this;var{paddingTop:e,paddingBottom:t}=this._cfg,n=this._canvas.offsetWidth,i=this._canvas.offsetHeight,o=(this._canvas.width=n,this._canvas.height=i,this._ctx.clearRect(0,0,n,i),this._drawAxias(n,i))["maxLabelWidth"],r=i-e-t;for(let t=0;t<this._colorList.length;t++){var s=this._colorList[t],a=r*(1-s.to.ratio),c=r*(1-s.from.ratio),a=Math.ceil(a+e),c=Math.ceil(c+e);const l=this._ctx.createLinearGradient(0,a,0,c);l.addColorStop(1,s.from.color),l.addColorStop(0,s.to.color),this._ctx.fillStyle=l,this._ctx.fillRect(0,a,n-o,c-a)}}setColors(t){return t.length<2||(t=function(e){e.sort(function(t,e){return t.data-e.data});const n=[];var t=v.min(e,function(t){return t.data}),i=v.max(e,function(t){return t.data}),o=i-t;let r=0;for(let t=1;t<e.length;t++){var s=e[t-1],a=e[t],c=(a.data-s.data)/o,l=r+c;n.push({from:{value:s.data,color:s.color,ratio:r},to:{value:a.data,color:a.color,ratio:l},ratio:c,label:s.data+"至"+a.data}),r=l}return console.log("转换",n),{data:n,max:i,min:t}}(t),this._colorList=t.data,this._minValue=t.min,this._maxValue=t.max,this._draw()),this}getColor(e){if(!this._colorList.length)return"#0000";!isNaN(e)&&"Number"===v.getType(e)||(e=this._colorList[0].from.value);var t=this._colorList.find(function(t){return e>=t.from.value&&e<t.to.value})??this._colorList[this._colorList.length-1],n=Math.min(e/(t.to.value-t.from.value),1),i=t.from.color,t=t.to.color,[i,o,r]=(n=Math.min(n,1),R(v.hexToRgba(i))),[t,s,a]=R(v.hexToRgba(t)),t=Math.round(i+(t-i)*n),i=Math.round(o+(s-o)*n),s=Math.round(r+(a-r)*n);return v.rgbaToHex(`rgba(${t},${i},${s},1)`)}}const M=document.createElement("canvas");class N{_cfg;_oWrapper;_canvas;constructor(t,e){this._oWrapper=t,this._cfg=Object.assign({fontFamily:"Microsoft YaHei",fontLineHeight:1.4,gapX:20,gapY:0,fontBackgroundColor:"rgba(0,0,0,0)",angle:-45,text:["作者 bestime","2025-04-09"],fontSize:16,fontColor:"red"},e),this._canvas=this._reload(),this._draw()}_reload(){let t=this._canvas;return t||(t=document.createElement("canvas"),this._oWrapper.appendChild(t)),t}setConfig(t){Object.assign(this._cfg,t),this._draw()}_draw(){const t=this._reload();var n=this._oWrapper.offsetWidth*window.devicePixelRatio,i=this._oWrapper.offsetHeight*window.devicePixelRatio;t.width=n,t.height=i,t.style.cssText="position:absolute;left:0;top:0;right:0;bottom:0;z-index: 1;user-select: none;pointer-events: none;",t.style.width=this._oWrapper.offsetWidth+"px",t.style.height=this._oWrapper.offsetHeight+"px";const o=t.getContext("2d");if(o&&(o.clearRect(0,0,n,i),!this._cfg.disabled)){var r=function(t){var e=t.angle*Math.PI/180;const i=M.getContext("2d");i.font=t.fontSize+"px "+t.fontFamily;let o=0;const r=[],s=(t.text.forEach(function(t){t=i.measureText(t);r.push(t.width),o=Math.max(t.width,o)}),t.fontSize*t.fontLineHeight),a=s*t.text.length;var n=Math.abs(o*Math.cos(e))+Math.abs(a*Math.sin(e)),c=Math.abs(o*Math.sin(e))+Math.abs(a*Math.cos(e));M.width=n,M.height=c,i.translate(n/2,c/2),i.rotate(e),i.fillStyle=t.fontBackgroundColor,i.fillRect(-o/2,-a/2,o,a),i.fillStyle=t.fontColor,i.font=t.fontSize+"px "+t.fontFamily,i.textBaseline="top",i.textAlign="left";const l=(s-t.fontSize)/2;return t.text.forEach(function(t,e){var n=o/2-r[e]/2;i.fillText(t,-o/2+n,-a/2+e*s+l)}),{img:M,width:n,height:c}}(this._cfg);for(let e=0;e<n;e+=r.width+this._cfg.gapX)for(let t=0;t<i;t+=r.height+this._cfg.gapY)o.drawImage(r.img,e,t)}}}function F(t,e){t.styleSheet?t.styleSheet.cssText=e:t.innerHTML=e}let H=0;B="bt-browser-core",H++,(B=v.trim(B))&&!/^[0-9]/.test(B)||(B="bt-style-"+H),W="",(I=document.createElement("style")).className=B,document.getElementsByTagName("head")[0].appendChild(I);var k,W,I,B=function(t){var i;k=W,v._String(t).replace(/(.*?)({.*?})/g,function(t,e,n){return e=v.trim(e),W=W.replace(new RegExp("("+e+"\\s*?)({.*?})","g"),function(){return i=!0,e+v.trim(n)}),""}),i?k!==W&&F(I,W):(W+=v._String(t),F(I,W))};t.LinearGradientColorLegend=A,t.SeamlessRolling=j,t.TextRainCanvas=$,t.WaterMark=N,t.addClass=_,t.browser=y,t.copyText=P,t.createXLSX=async function(t){const e=document.createElement("table"),n=v.parseTreeToTableHeader(t.header);var i=n.data.map(function(t){return`<tr>${t.map(function(t){if(t&&0!==t.colSpan)return`<td align="center" rowSpan="${t.rowSpan}" colSpan="${t.colSpan}">${t?.title}</td>`}).join("")}</tr>`}).join(""),t=t.body.map(function(i){return`<tr>${n.columns.map(function(t){var e=i.$colField?.[t]??1,n=i.$rowSpan?.[t]??1;if(0!==e&&0!==n)return`<td align="center" colSpan="${e}" rowSpan="${n}">${i[t]??""}</td>`}).filter(function(t){return!v.isNull(t)}).join("")}</tr>`}).join("");return e.innerHTML=`<thead>${i}</thead><tbody>${t}</tbody>`,e.setAttribute("border","1"),e},t.downloadFileByArrayBuffer=function(t,e){m(new Blob([t]),e)},t.downloadFileByBolb=m,t.downloadFileByUrl=a,t.fullScreen=function(t,e,n){if(e){e=t;t=n;const i=t||S;e.requestFullscreen?e.requestFullscreen():e.webkitRequestFullScreen?e.webkitRequestFullScreen():e.mozRequestFullScreen?e.mozRequestFullScreen():e.msRequestFullscreen&&e.msRequestFullscreen(),i(!0)}else{t=n;const o=t||S,r=document;document.exitFullscreen?document.exitFullscreen().then(function(){o(!0)})["catch"](function(){o(!1)}):r.webkitCancelFullScreen?(r.webkitCancelFullScreen(),o(!0)):r.mozCancelFullScreen?(r.mozCancelFullScreen(),o(!0)):r.msExitFullscreen&&(r.msExitFullscreen(),o(!0))}},t.getCookie=function(t,e){e=e||document.cookie;let i="";return e.replace(new RegExp("(^|;\\s?)"+t+"=(.*?)($|(;\\s?))"),function(t,e,n){i=z(n)}),i},t.getJsFileBaseUrl=function(t){t=t||0;for(var e="/[^/]*",n=document.scripts,i=0;i<t;i++)e+=e;return n[n.length-1].src.replace(new RegExp(e+"$"),"")},t.getRatio=function(){return window.devicePixelRatio||1},t.getRelativePos=function(t){var e=t.getBoundingClientRect();return{x:e.left,y:e.top,height:t.offsetHeight,width:t.offsetWidth,clientWidth:t.clientWidth,clientHeight:t.clientHeight}},t.getStorage=function(t){return t=localStorage.getItem(t),v.defualtFormatter("",t)},t.getWindowSize=h,t.infoContainerPosition=function(t){var e=t.mode||"top-right",n=t.width,i=t.height,o=v.defualtFormatter(10,t.offsetY),r=v.defualtFormatter(10,t.offsetX),s=v.defualtFormatter(10,t.padding);let a=t.x,c=t.y;var t=t.targetSize||h(),l=[s,t.width-n-s],t=[s,t.height-i-s];return"top-right"===e?(a+=r,c=c-i-o,a<l[0]?a=l[0]:a>l[1]&&(s=a-n-2*r,a=l[0]<s?s:l[1]),c<t[0]?(s=c+i+2*o,c=s<t[1]?s:t[0]):c>t[1]&&(c=c-i-2*o)):"bottom-right"===e?(a+=r,(c+=o)>t[1]&&(s=c-i-2*o,c=s<t[0]?t[1]:s),a>l[1]&&(t=a-n-2*r,a=t<l[0]?l[1]:t)):"top-left"===e&&(a=a-n-r,c=c-i-o),{x:a,y:c}},t.libraryFile=x,t.observeDomResize=function(n,i,o,t){let r=[0,0,!1],s=[0,0,!1],a=[0,0,!1],c=[0,0,!1];const e=u.add(l,t=t||500);function l(){if(document.body.contains(n)){let t=!1;var e;o?.includes("position")&&(e=n.getBoundingClientRect(),a[0]=e.left,a[2]=a[0]!==a[1],c[0]=e.top,c[2]=c[0]!==c[1]),r[0]=n.offsetWidth,r[2]=r[0]!==r[1],s[0]=n.offsetHeight,s[2]=s[0]!==s[1],r[2]&&(r[1]=r[0],o?.includes("width")&&(t=!0)),s[2]&&(s[1]=s[0],o?.includes("height")&&(t=!0)),(c[2]||a[2])&&(c[1]=c[0],a[1]=a[0],o?.includes("position")&&(t=!0)),o&&0!==o.length||(r[2]||s[2]||c[2]||a[2])&&(t=!0),t&&i(n)}else h()}function h(){u.remove(e),r=undefined,s=undefined}return l(),h},t.observeDomScroll=function(n,t){const i=v._KvPair(t),o=v._Number(i.offetY);let r=!1,s=0;function e(){var t,e;r||(e=(t=n.scrollTop)-s,s=t,0!=e?e<0&&i.onTop&&t<=0+o?(r=!0,i.onTop(function(){r=!1})):0<e&&i.onBottom&&t>=n.scrollHeight-n.offsetHeight-o?(r=!0,i.onBottom(function(){r=!1})):r=!1:(r=!1,console.log("未处理")))}return n.addEventListener("scroll",e),{dispose:function(){n.removeEventListener("scroll",e)}}},t.observeMouseWheel=function(t,n,i){function e(t){let e;if(e=t.wheelDelta?0<t.wheelDelta?1:-1:t.detail<0?1:-1,n(e),i)return t.preventDefault&&t.preventDefault(),!1}return t.addEventListener("mousewheel",e),t.addEventListener("DOMMouseScroll",e),{dispose:function(){t.removeEventListener("mousewheel",e),t.removeEventListener("DOMMouseScroll",e)}}},t.pdfToImage=async function(t,o,e){i=e;const n=await new Promise(function(t){x({type:"js",module:"pdfjsLib",attribute:{type:"module"},url:i.index,interceptor:function(t){t.GlobalWorkerOptions.workerSrc=i.worker}},t)});var i;return new Promise(function(i){n.getDocument(t).promise.then(function(t){console.log("pdf",t),t.getPage(1).then(function(t){var e=t.getViewport({scale:1}),n=o.getContext("2d");o.height=e.height,o.width=e.width,t.render({canvasContext:n,viewport:e}).promise.then(function(){i({width:e.width,height:e.height})})})},function(t){console.error(t),i({width:0,height:0})})})},t.prevent=function(t,e,n){t=t||d.event,n=!1!==n,(e=!1!==e)&&d.event?d.event.cancelBubble=!0:t.stopPropagation(),n&&d.event?d.event.returnValue=!1:t.preventDefault()},t.removeClass=b,t.removeCookie=function(t){e(t,"",-1)},t.removeElement=function(t){t.parentNode&&t.parentNode.removeChild(t)},t.removeStorage=function(t){localStorage.removeItem(t)},t.replaceClass=function(t,e,n){b(t,e),_(t,n)},t.setCookie=e,t.setStorage=function(t,e){localStorage.setItem(t,(t=e,t=v.isString(t)?t:JSON.stringify(t)))},t.speakText=async function(t,e){C.cancel(),L.rate=1,L.pitch=1,await v.variableHasValue["async"](function(){return 0<T.length});var n=T.find(t=>v.trim(t.name,"*")===v.trim(e.language,"*"))||T[0];L.lang=n.lang,await async function(i){function o(t){console.log("朗读错误",t)}L.addEventListener("error",o);let r;return new Promise(function(t){function e(){clearTimeout(r),C.cancel(),L.removeEventListener("error",o),L.removeEventListener("start",e),t()}!function n(){L.voice=i,L.text=1..toString(),C.speak(L),clearTimeout(r),L.removeEventListener("start",e),L.addEventListener("start",e),r=setTimeout(n,1e3)}()})}(n),L.text=t,C.speak(L)},t.style=B,t.toggleClass=function(e,t){v.isArray(t)?v.forEach(t,function(t){e.classList.toggle(t)}):e.classList.toggle(t)}});
5
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@bestime/utils_base")):"function"==typeof define&&define.amd?define(["exports","@bestime/utils_base"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).jUtilsBrowser={},t.jUtilsBase)}(this,function(t,v){"use strict";function h(){return{width:document.documentElement.clientWidth||document.body.clientWidth||window.innerWidth||0,height:document.documentElement.clientHeight||document.body.clientHeight||window.innerHeight||0}}let n=0,i,o=!1;const r={};let s;var u={add:function(t,e){return i="HI-"+ ++n,r[i]={start:+new Date,current:0,handler:t,interval:e},o||(clearInterval(s),o=!0,s=setInterval(function(){for(var t in r){const e=r[t];e.current=+new Date,e.current-e.start>=e.interval&&(e.start=e.current,r[t].handler())}},17)),i},remove:function(t){delete r[t],0===Object.keys(r).length&&(o=!1,clearInterval(s),s=undefined)}};function a(t,e){const n=document.createElement("a");n.style.display="none",n.download=e,n.setAttribute("href",t),n.setAttribute("target","_blank"),n.setAttribute("download",e),document.body.appendChild(n),n.click(),n.remove()}const l=void 0,c=decodeURIComponent,d=window,f=document.getElementsByTagName("head")[0],m=d.URL;function g(t,e){t=m.createObjectURL(t);a(t,e),m.revokeObjectURL(t),undefined}const p={};function x(n,i){const o=[];let r=0;for(let e=0;e<n.length;e++)w(n[e],function(t){o[e]=t,++r===n.length&&i.apply(l,o)})}function w(t,e){var n=t.dependencies&&t.dependencies.length,i=t["with"]&&t["with"].length;p[t.url]||(p[t.url]={count:0,dependencies:!n,"with":!i,complete:!1,create:!1,url:t.url});const o=p[t.url];function r(){return d[t.module]}function s(){o.complete&&o.dependencies&&o["with"]&&(t.module?e(r()):e())}if(o.count++,!o.dependencies&&n)o.dependencies=!0,x(t.dependencies,function(){w(t,e)});else if(!o["with"]&&i)o["with"]=!0,x(t["with"].concat(t),s);else if(o.create)v.variableHasValue(function(){return o.complete},s,300);else{o.create=!0;var n=t.type,i=t.url,a=function(){o.complete=!0,t.interceptor&&t.interceptor(r()),s()},l=t.attribute;if(f){let t;if("js"===n?(t=document.createElement("script")).src=i:((t=document.createElement("link")).setAttribute("rel","stylesheet"),t.href=i),l)for(var c in l)t.setAttribute(c,l[c]);t.onload=t.onerror=a,f.appendChild(t)}}}function _(t,e){(t instanceof Array?x:w)(t,e)}function e(t,e,n){var i;i=e,e=i=v.isString(i)?i:JSON.stringify(i);let o=t+"="+encodeURI(e)+";path=/;";"number"==typeof n&&((i=new Date).setTime(i.getTime()+n),o+="expires="+i.toUTCString()),document.cookie=o}function b(e,t){v.isArray(t)?v.forEach(t,function(t){e.classList.remove(t)}):e.classList.remove(t)}function S(e,t){v.isArray(t)?v.forEach(t,function(t){e.classList.add(t)}):e.classList.add(t)}var y=d.navigator.userAgent,y={isChrome:/Chrome/.test(y),isIPhone:/iPhone/.test(y)};const C=t=>{};class L{text="abcdefghijklmnopqrstuvwxyz";fontSize=14;color=[0,255,0];reverse=!1;isStop=!1;interval=100;width;height;fontLineHeight;count;oCanvas;ctx;timer;pointList=[];constructor(t,e){this.draw=this.draw.bind(this);var n=t.offsetWidth,i=t.offsetHeight;t.width=n,t.height=i,this.width=n,this.height=i,e&&(this.text=e.text||this.text,this.fontSize=e.fontSize||this.fontSize,this.color=e.color?function(t){for(var e=[],n=1;n<7;n+=2)e.push(parseInt("0x"+t.slice(n,n+2)));return e}(e.color):this.color,this.reverse=(null!=e.reverse?e:this).reverse,this.interval=e.interval||this.interval),this.oCanvas=t,this.ctx=t.getContext("2d"),this.fontLineHeight=1.2*this.fontSize,this.count=Math.ceil(this.height/this.fontLineHeight),this.getPointList(),this.draw()}draw(){if(this.isStop)return clearTimeout(this.timer);this.ctx.font=this.fontSize+'px "Microsoft YaHei"',this.ctx.textBaseline="top",this.ctx.clearRect(0,0,this.width,this.height),this.pointList.forEach(i=>{i.list.forEach((t,e)=>{let n;this.reverse?(n=(e-i.currentIndex)/10,n=1-t.speed*n,e<i.currentIndex&&(n=0)):(n=(i.currentIndex-e)/10,n=1-t.speed*n,e>i.currentIndex&&(n=0)),0<n&&(this.ctx.fillStyle=`rgba(${this.color.join(",")}, ${n})`,this.ctx.fillText(t.text,t.x,t.y))}),this.reverse?(i.currentIndex--,i.currentIndex+10<0&&(i.currentIndex=this.count+v.getRandom(0,this.count))):(i.currentIndex++,i.currentIndex-10>i.list.length-1&&(i.currentIndex=-v.getRandom(0,this.count)))}),clearTimeout(this.timer),this.timer=setTimeout(this.draw,this.interval)}createColumn(e,t){const n=[];for(let t=0;t<this.count;t++){var i=v.getRandom(0,this.text.length-1);n.push({text:this.text[i],x:e,y:Math.floor(t*this.fontLineHeight),speed:1})}return{currentIndex:t,list:n}}dispose(){this.isStop=!0,clearTimeout(this.timer)}start(){this.isStop=!1,this.draw()}getPointList(){const i=[];var o=this.fontSize,t=Math.floor(this.width/o);for(let n=0;n<t;n++){let e=0;for(let t=0;t<this.count&&(t?e+=v.getRandom(e+10,this.count):e+=v.getRandom(e,10),!(e>this.count));t++)this.reverse?i.push(this.createColumn(n*o,this.count+e)):i.push(this.createColumn(n*o,-e))}return this.pointList=i}}class T{_wrapper;_timer;constructor(t){this._wrapper=t,this._updateContent()}_updateContent(){const t=this._wrapper.children[0];var e=t.cloneNode(!0);this._wrapper.appendChild(e),console.log("firstNode",t,e)}_doScroll(){clearTimeout(this._timer),this._timer=setTimeout(()=>{},60)}dispose(){clearTimeout(this._timer)}}var R=d.navigator?.clipboard?.writeText?function(t){return navigator.clipboard.writeText(t)}:async function(t){const e=document.createElement("textarea");e.value=t,document.body.appendChild(e),e.select(),document.execCommand("copy"),document.body.removeChild(e)};function M(t){t=t.replace(/^rgba\((.*)\)$/,"$1");const e=v.split(t,",");return e.map(function(t){return v._Number(t)})}class z{_cfg;_canvas;_colorList=[];_ctx;_minValue=0;_maxValue=0;constructor(t){this._cfg=Object.assign({fontSize:14,fontFamily:"Microsoft YaHei",tickWidth:5,paddingTop:10,paddingBottom:10,tickColor:"#92949b",fontColor:"#444",colors:[]},t),this.setColors(this._cfg.colors)}mount(t){this._canvas=t,this._ctx=t.getContext("2d"),this._draw()}_drawAxias(n,t){const i=this._ctx;var{fontFamily:e,fontSize:o,tickWidth:r,paddingTop:s,paddingBottom:a}=this._cfg,l=(i.font=o+"px "+e,3*o),c=t-a-s,h=Math.ceil(c/l),l=c/h;i.textBaseline="middle";let u=0;const d=[];for(let t=0;t<=h;t++){var f=(1-t/h)*(this._maxValue-this._minValue)+this._minValue,f=this._cfg.labelFormatter?this._cfg.labelFormatter(f):v.roundFixed(f,2),m=i.measureText(f);u=Math.max(m.width,u),d.push({label:f,width:m.width})}for(let e=0;e<d.length;e++){var g=d[e];let t=0;t=0===e?0:e===d.length-1?c-1:Math.floor(e*l),t+=s;var p=n-u-4-r;i.fillStyle=this._cfg.tickColor,i.fillRect(p,t,r,1),i.fillStyle=this._cfg.fontColor,i.fillText(g.label,p+r+4,t)}return{maxLabelWidth:4+u+r}}_draw(){if(!this._canvas||!this._ctx)return this;var{paddingTop:e,paddingBottom:t}=this._cfg,n=this._canvas.offsetWidth,i=this._canvas.offsetHeight,o=(this._canvas.width=n,this._canvas.height=i,this._ctx.clearRect(0,0,n,i),this._drawAxias(n,i))["maxLabelWidth"],r=i-e-t;for(let t=0;t<this._colorList.length;t++){var s=this._colorList[t],a=r*(1-s.to.ratio),l=r*(1-s.from.ratio),a=Math.ceil(a+e),l=Math.ceil(l+e);const c=this._ctx.createLinearGradient(0,a,0,l);c.addColorStop(1,s.from.color),c.addColorStop(0,s.to.color),this._ctx.fillStyle=c,this._ctx.fillRect(0,a,n-o,l-a)}}setColors(t){return t.length<2||(t=function(e){e.sort(function(t,e){return t.data-e.data});const n=[];var t=v.min(e,function(t){return t.data}),i=v.max(e,function(t){return t.data}),o=i-t;let r=0;for(let t=1;t<e.length;t++){var s=e[t-1],a=e[t],l=(a.data-s.data)/o,c=r+l;n.push({from:{value:s.data,color:s.color,ratio:r},to:{value:a.data,color:a.color,ratio:c},ratio:l,label:s.data+"至"+a.data}),r=c}return{data:n,max:i,min:t}}(t),this._colorList=t.data,this._minValue=t.min,this._maxValue=t.max,this._draw()),this}getColor(e){if(!this._colorList.length)return"#0000";!isNaN(e)&&"Number"===v.getType(e)||(e=this._colorList[0].from.value);var t=this._colorList.find(function(t){return e>=t.from.value&&e<t.to.value});let n;n=t||(e<this._colorList[0].from.value?this._colorList[0]:this._colorList[this._colorList.length-1]);var t=e-n.from.value,t=Math.min(t/(n.to.value-n.from.value),1),i=n.from.color,o=n.to.color,[i,r,s]=(t=Math.max(t,0),t=Math.min(t,1),M(v.hexToRgba(i))),[o,a,l]=M(v.hexToRgba(o)),o=Math.round(i+(o-i)*t),i=Math.round(r+(a-r)*t),a=Math.round(s+(l-s)*t);return v.rgbaToHex(`rgba(${o},${i},${a},1)`)}}const F=document.createElement("canvas");class ${_cfg;_oWrapper;_canvas;constructor(t,e){this._oWrapper=t,this._cfg=Object.assign({fontFamily:"Microsoft YaHei",fontLineHeight:1.4,gapX:20,gapY:0,fontBackgroundColor:"rgba(0,0,0,0)",angle:-45,text:["作者 bestime","2025-04-09"],fontSize:16,fontColor:"red"},e),this._canvas=this._reload(),this._draw()}_reload(){let t=this._canvas;return t||(t=document.createElement("canvas"),this._oWrapper.appendChild(t)),t}setConfig(t){Object.assign(this._cfg,t),this._draw()}_draw(){const t=this._reload();var n=this._oWrapper.offsetWidth*window.devicePixelRatio,i=this._oWrapper.offsetHeight*window.devicePixelRatio;t.width=n,t.height=i,t.style.cssText="position:absolute;left:0;top:0;right:0;bottom:0;z-index: 1;user-select: none;pointer-events: none;",t.style.width=this._oWrapper.offsetWidth+"px",t.style.height=this._oWrapper.offsetHeight+"px";const o=t.getContext("2d");if(o&&(o.clearRect(0,0,n,i),!this._cfg.disabled)){var r=function(t){var e=t.angle*Math.PI/180;const i=F.getContext("2d");i.font=t.fontSize+"px "+t.fontFamily;let o=0;const r=[],s=(t.text.forEach(function(t){t=i.measureText(t);r.push(t.width),o=Math.max(t.width,o)}),t.fontSize*t.fontLineHeight),a=s*t.text.length;var n=Math.abs(o*Math.cos(e))+Math.abs(a*Math.sin(e)),l=Math.abs(o*Math.sin(e))+Math.abs(a*Math.cos(e));F.width=n,F.height=l,i.translate(n/2,l/2),i.rotate(e),i.fillStyle=t.fontBackgroundColor,i.fillRect(-o/2,-a/2,o,a),i.fillStyle=t.fontColor,i.font=t.fontSize+"px "+t.fontFamily,i.textBaseline="top",i.textAlign="left";const c=(s-t.fontSize)/2;return t.text.forEach(function(t,e){var n=o/2-r[e]/2;i.fillText(t,-o/2+n,-a/2+e*s+c)}),{img:F,width:n,height:l}}(this._cfg);for(let e=0;e<n;e+=r.width+this._cfg.gapX)for(let t=0;t<i;t+=r.height+this._cfg.gapY)o.drawImage(r.img,e,t)}}}function E(t,e){t.styleSheet?t.styleSheet.cssText=e:t.innerHTML=e}let H=0;B="bt-browser-core",H++,(B=v.trim(B))&&!/^[0-9]/.test(B)||(B="bt-style-"+H),k="",(I=document.createElement("style")).className=B,document.getElementsByTagName("head")[0].appendChild(I);var W,k,I,B=function(t){var i;W=k,v._String(t).replace(/(.*?)({.*?})/g,function(t,e,n){return e=v.trim(e),k=k.replace(new RegExp("("+e+"\\s*?)({.*?})","g"),function(){return i=!0,e+v.trim(n)}),""}),i?W!==k&&E(I,k):(k+=v._String(t),E(I,k))};t.LinearGradientColorLegend=z,t.SeamlessRolling=T,t.TextRainCanvas=L,t.WaterMark=$,t.addClass=S,t.browser=y,t.copyText=R,t.createXLSX=async function(t){const e=document.createElement("table"),n=v.parseTreeToTableHeader(t.header);var i=n.data.map(function(t){return`<tr>${t.map(function(t){if(t&&0!==t.colSpan)return`<td align="center" rowSpan="${t.rowSpan}" colSpan="${t.colSpan}">${t?.title}</td>`}).join("")}</tr>`}).join(""),t=t.body.map(function(i){return`<tr>${n.columns.map(function(t){var e=i.$colField?.[t]??1,n=i.$rowSpan?.[t]??1;if(0!==e&&0!==n)return`<td align="center" colSpan="${e}" rowSpan="${n}">${i[t]??""}</td>`}).filter(function(t){return!v.isNull(t)}).join("")}</tr>`}).join("");return e.innerHTML=`<thead>${i}</thead><tbody>${t}</tbody>`,e.setAttribute("border","1"),e},t.downloadFileByArrayBuffer=function(t,e){g(new Blob([t]),e)},t.downloadFileByBolb=g,t.downloadFileByUrl=a,t.fullScreen=function(t,e,n){if(e){e=t;t=n;const i=t||C;e.requestFullscreen?e.requestFullscreen():e.webkitRequestFullScreen?e.webkitRequestFullScreen():e.mozRequestFullScreen?e.mozRequestFullScreen():e.msRequestFullscreen&&e.msRequestFullscreen(),i(!0)}else{t=n;const o=t||C,r=document;document.exitFullscreen?document.exitFullscreen().then(function(){o(!0)})["catch"](function(){o(!1)}):r.webkitCancelFullScreen?(r.webkitCancelFullScreen(),o(!0)):r.mozCancelFullScreen?(r.mozCancelFullScreen(),o(!0)):r.msExitFullscreen&&(r.msExitFullscreen(),o(!0))}},t.getCookie=function(t,e){e=e||document.cookie;let i="";return e.replace(new RegExp("(^|;\\s?)"+t+"=(.*?)($|(;\\s?))"),function(t,e,n){i=c(n)}),i},t.getJsFileBaseUrl=function(t){t=t||0;for(var e="/[^/]*",n=document.scripts,i=0;i<t;i++)e+=e;return n[n.length-1].src.replace(new RegExp(e+"$"),"")},t.getRatio=function(){return window.devicePixelRatio||1},t.getRelativePos=function(t){var e=t.getBoundingClientRect();return{x:e.left,y:e.top,height:t.offsetHeight,width:t.offsetWidth,clientWidth:t.clientWidth,clientHeight:t.clientHeight}},t.getStorage=function(t){return t=localStorage.getItem(t),v.defualtFormatter("",t)},t.getWindowSize=h,t.infoContainerPosition=function(t){var e=t.mode||"top-right",n=t.width,i=t.height,o=v.defualtFormatter(10,t.offsetY),r=v.defualtFormatter(10,t.offsetX),s=v.defualtFormatter(10,t.padding);let a=t.x,l=t.y;var t=t.targetSize||h(),c=[s,t.width-n-s],t=[s,t.height-i-s];return"top-right"===e?(a+=r,l=l-i-o,a<c[0]?a=c[0]:a>c[1]&&(s=a-n-2*r,a=c[0]<s?s:c[1]),l<t[0]?(s=l+i+2*o,l=s<t[1]?s:t[0]):l>t[1]&&(l=l-i-2*o)):"bottom-right"===e?(a+=r,(l+=o)>t[1]&&(s=l-i-2*o,l=s<t[0]?t[1]:s),a>c[1]&&(t=a-n-2*r,a=t<c[0]?c[1]:t)):"top-left"===e&&(a=a-n-r,l=l-i-o),{x:a,y:l}},t.libraryFile=_,t.observeDomResize=function(n,i,o,t){let r=[0,0,!1],s=[0,0,!1],a=[0,0,!1],l=[0,0,!1];const e=u.add(c,t=t||500);function c(){if(document.body.contains(n)){let t=!1;var e;o?.includes("position")&&(e=n.getBoundingClientRect(),a[0]=e.left,a[2]=a[0]!==a[1],l[0]=e.top,l[2]=l[0]!==l[1]),r[0]=n.offsetWidth,r[2]=r[0]!==r[1],s[0]=n.offsetHeight,s[2]=s[0]!==s[1],r[2]&&(r[1]=r[0],o?.includes("width")&&(t=!0)),s[2]&&(s[1]=s[0],o?.includes("height")&&(t=!0)),(l[2]||a[2])&&(l[1]=l[0],a[1]=a[0],o?.includes("position")&&(t=!0)),o&&0!==o.length||(r[2]||s[2]||l[2]||a[2])&&(t=!0),t&&i(n)}else h()}function h(){u.remove(e),r=undefined,s=undefined}return c(),h},t.observeDomScroll=function(n,t){const i=v._KvPair(t),o=v._Number(i.offetY);let r=!1,s=0;function e(){var t,e;r||(e=(t=n.scrollTop)-s,s=t,0!=e?e<0&&i.onTop&&t<=0+o?(r=!0,i.onTop(function(){r=!1})):0<e&&i.onBottom&&t>=n.scrollHeight-n.offsetHeight-o?(r=!0,i.onBottom(function(){r=!1})):r=!1:(r=!1,console.log("未处理")))}return n.addEventListener("scroll",e),{dispose:function(){n.removeEventListener("scroll",e)}}},t.observeMouseWheel=function(t,n,i){function e(t){let e;if(e=t.wheelDelta?0<t.wheelDelta?1:-1:t.detail<0?1:-1,n(e),i)return t.preventDefault&&t.preventDefault(),!1}return t.addEventListener("mousewheel",e),t.addEventListener("DOMMouseScroll",e),{dispose:function(){t.removeEventListener("mousewheel",e),t.removeEventListener("DOMMouseScroll",e)}}},t.pdfToImage=async function(t,o,e){i=e;const n=await new Promise(function(t){_({type:"js",module:"pdfjsLib",attribute:{type:"module"},url:i.index,interceptor:function(t){t.GlobalWorkerOptions.workerSrc=i.worker}},t)});var i;return new Promise(function(i){n.getDocument(t).promise.then(function(t){console.log("pdf",t),t.getPage(1).then(function(t){var e=t.getViewport({scale:1}),n=o.getContext("2d");o.height=e.height,o.width=e.width,t.render({canvasContext:n,viewport:e}).promise.then(function(){i({width:e.width,height:e.height})})})},function(t){console.error(t),i({width:0,height:0})})})},t.prevent=function(t,e,n){t=t||d.event,n=!1!==n,(e=!1!==e)&&d.event?d.event.cancelBubble=!0:t.stopPropagation(),n&&d.event?d.event.returnValue=!1:t.preventDefault()},t.removeClass=b,t.removeCookie=function(t){e(t,"",-1)},t.removeElement=function(t){t.parentNode&&t.parentNode.removeChild(t)},t.removeStorage=function(t){localStorage.removeItem(t)},t.replaceClass=function(t,e,n){b(t,e),S(t,n)},t.setCookie=e,t.setStorage=function(t,e){localStorage.setItem(t,(t=e,t=v.isString(t)?t:JSON.stringify(t)))},t.style=B,t.toggleClass=function(e,t){v.isArray(t)?v.forEach(t,function(t){e.classList.toggle(t)}):e.classList.toggle(t)}});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bestime/utils_browser",
3
- "version": "1.0.13",
3
+ "version": "1.0.14",
4
4
  "main": "./dist/esm/index.min.mjs",
5
5
  "module": "./dist/esm/index.min.mjs",
6
6
  "types": "./dist/esm/index.d.ts",