@bestime/utils_browser 1.0.14 → 1.0.15

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.
@@ -19,7 +19,8 @@ declare function observeDomResize(
19
19
  element: HTMLElement,
20
20
  handler: (element: HTMLElement) => void,
21
21
  type?: ('width' | 'height' | 'position')[],
22
- interval?: number
22
+ interval?: number,
23
+ immediate?: boolean
23
24
  ): () => void;
24
25
 
25
26
  /**
@@ -194,7 +195,7 @@ type Direction = 1 | -1;
194
195
  * @param isPrevent 是否阻止原生滚动,仅用来获取滚动方向
195
196
  * @returns
196
197
  */
197
- declare function export_default$1(
198
+ declare function observeMouseWheel(
198
199
  el: HTMLElement,
199
200
  callback: (direction: Direction) => void,
200
201
  isPrevent: boolean
@@ -427,6 +428,29 @@ declare class WaterMark {
427
428
  _draw(): void;
428
429
  }
429
430
 
431
+ /**
432
+ * 将部分属性变为可选
433
+ */
434
+ type TPartialOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
435
+
436
+ interface IWaterfallFlowConfig {
437
+ el: HTMLElement;
438
+ gap: number;
439
+ /**
440
+ * 自动播放在第一次主动执行 resize 后生效(避免首次渲染过渡动画卡顿)
441
+ */
442
+ autoResize?: number;
443
+ }
444
+ declare class WaterfallFlow {
445
+ private _cfg;
446
+ private _timer;
447
+ constructor(config: TPartialOptional<IWaterfallFlowConfig, 'gap'>);
448
+ _autoPlay(): void;
449
+ resize(): void;
450
+ pause(): this;
451
+ dispose(): void;
452
+ }
453
+
430
454
  declare const style: (str: string) => void;
431
455
 
432
456
  export {
@@ -434,6 +458,7 @@ export {
434
458
  SeamlessRolling,
435
459
  TextRainCanvas,
436
460
  WaterMark,
461
+ WaterfallFlow,
437
462
  addClass,
438
463
  _default as browser,
439
464
  copyText,
@@ -452,7 +477,7 @@ export {
452
477
  libraryFile,
453
478
  observeDomResize,
454
479
  export_default as observeDomScroll,
455
- export_default$1 as observeMouseWheel,
480
+ observeMouseWheel,
456
481
  pdfToImage,
457
482
  prevent,
458
483
  removeClass,
@@ -1,5 +1,9 @@
1
1
  /**
2
2
  * 浏览器工具库 => jUtilsBrowser
3
- * @update 2025-08-06 10:49:02
3
+ * @update 2026-01-17 22:11:46
4
4
  */
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};
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,i,n,t,e){e=!1!==e;let r=[0,0,!1],a=[0,0,!1],s=[0,0,!1],l=[0,0,!1];const c=hpInterval.add(h,t=t||500);function h(){if(document.body.contains(o)){let t=!1;var e;n?.includes("position")&&(e=o.getBoundingClientRect(),s[0]=e.left,s[2]=s[0]!==s[1],l[0]=e.top,l[2]=l[0]!==l[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],n?.includes("width")&&(t=!0)),a[2]&&(a[1]=a[0],n?.includes("height")&&(t=!0)),(l[2]||s[2])&&(l[1]=l[0],s[1]=s[0],n?.includes("position")&&(t=!0)),n&&0!==n.length||(r[2]||a[2]||l[2]||s[2])&&(t=!0),t&&i(o)}else d()}function d(){hpInterval.remove(c),r=undefined,a=undefined}return e&&h(),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,i=0;i<t;i++)e+=e;return o[o.length-1].src.replace(new RegExp(e+"$"),"")}function hpCreateFileLoaderElement(e,o,i,n){if($headElement){let t;if("js"===e?(t=document.createElement("script")).src=o:((t=document.createElement("link")).setAttribute("rel","stylesheet"),t.href=o),n)for(var r in n)t.setAttribute(r,n[r]);t.onload=t.onerror=i,$headElement.appendChild(t)}}const cache={};function loadMultiple(o,i){const n=[];let r=0;for(let e=0;e<o.length;e++)loadSingle(o[e],function(t){n[e]=t,++r===o.length&&i.apply($undefinedValue,n)})}function loadSingle(t,e){var o=t.dependencies&&t.dependencies.length,i=t["with"]&&t["with"].length;cache[t.url]||(cache[t.url]={count:0,dependencies:!o,"with":!i,complete:!1,create:!1,url:t.url});const n=cache[t.url];function r(){return $browserGlobal[t.module]}function a(){n.complete&&n.dependencies&&n["with"]&&(t.module?e(r()):e())}n.count++,!n.dependencies&&o?(n.dependencies=!0,loadMultiple(t.dependencies,function(){loadSingle(t,e)})):!n["with"]&&i?(n["with"]=!0,loadMultiple(t["with"].concat(t),a)):n.create?variableHasValue(function(){return n.complete},a,300):(n.create=!0,hpCreateFileLoaderElement(t.type,t.url,function(){n.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 i=t+"="+encodeURI(e)+";path=/;";"number"==typeof o&&((t=new Date).setTime(t.getTime()+o),i+="expires="+t.toUTCString()),document.cookie=i}function getCookie(t,e){e=e||document.cookie;let i="";return e.replace(new RegExp("(^|;\\s?)"+t+"=(.*?)($|(;\\s?))"),function(t,e,o){i=$decodeURIComponent(o)}),i}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,i){function e(t){let e;if(e=t.wheelDelta?0<t.wheelDelta?1:-1:t.detail<0?1:-1,o(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)}}}function observeDomScroll(o,t){const i=_KvPair(t),n=_Number(i.offetY);let r=!1,a=0;function e(){var t,e;r||(e=(t=o.scrollTop)-a,a=t,0!=e?e<0&&i.onTop&&t<=0+n?(r=!0,i.onTop(function(){r=!1})):0<e&&i.onBottom&&t>=o.scrollHeight-o.offsetHeight-n?(r=!0,i.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 i=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(i){return`<tr>${o.columns.map(function(t){var e=i.$colField?.[t]??1,o=i.$rowSpan?.[t]??1;if(0!==e&&0!==o)return`<td align="center" colSpan="${e}" rowSpan="${o}">${i[t]??""}</td>`}).filter(function(t){return!isNull(t)}).join("")}</tr>`}).join("");return e.innerHTML=`<thead>${i}</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,n,e){const o=await loadPdfPlugin(e);return new Promise(function(i){o.getDocument(t).promise.then(function(t){console.log("pdf",t),t.getPage(1).then(function(t){var e=t.getViewport({scale:1}),o=n.getContext("2d");n.height=e.height,n.width=e.width,t.render({canvasContext:o,viewport:e}).promise.then(function(){i({width:e.width,height:e.height})})})},function(t){console.error(t),i({width:0,height:0})})})}function infoContainerPosition(t){var e=t.mode||"top-right",o=t.width,i=t.height,n=defualtFormatter(10,t.offsetY),r=defualtFormatter(10,t.offsetX),a=defualtFormatter(10,t.padding);let s=t.x,l=t.y;var t=t.targetSize||getWindowSize(),c=[a,t.width-o-a],t=[a,t.height-i-a];return"top-right"===e?(s+=r,l=l-i-n,s<c[0]?s=c[0]:s>c[1]&&(a=s-o-2*r,s=c[0]<a?a:c[1]),l<t[0]?(a=l+i+2*n,l=a<t[1]?a:t[0]):l>t[1]&&(l=l-i-2*n)):"bottom-right"===e?(s+=r,(l+=n)>t[1]&&(a=l-i-2*n,l=a<t[0]?t[1]:a),s>c[1]&&(t=s-o-2*r,s=t<c[0]?c[1]:t)):"top-left"===e&&(s=s-o-r,l=l-i-n),{x:s,y:l}}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,i=t.offsetHeight;t.width=o,t.height=i,this.width=o,this.height=i,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(i=>{i.list.forEach((t,e)=>{let o;this.reverse?(o=(e-i.currentIndex)/10,o=1-t.speed*o,e<i.currentIndex&&(o=0)):(o=(i.currentIndex-e)/10,o=1-t.speed*o,e>i.currentIndex&&(o=0)),0<o&&(this.ctx.fillStyle=`rgba(${this.color.join(",")}, ${o})`,this.ctx.fillText(t.text,t.x,t.y))}),this.reverse?(i.currentIndex--,i.currentIndex+10<0&&(i.currentIndex=this.count+getRandom(0,this.count))):(i.currentIndex++,i.currentIndex-10>i.list.length-1&&(i.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 i=getRandom(0,this.text.length-1);o.push({text:this.text[i],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 i=[];var n=this.fontSize,t=Math.floor(this.width/n);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?i.push(this.createColumn(o*n,this.count+e)):i.push(this.createColumn(o*n,-e))}return this.pointList=i}}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,i,n]=rgbStringToList(hexToRgba(t)),[e,r,a]=rgbStringToList(hexToRgba(e)),e=Math.round(t+(e-t)*o),t=Math.round(i+(r-i)*o),r=Math.round(n+(a-n)*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}),i=max(e,function(t){return t.data}),n=i-t;let r=0;for(let t=1;t<e.length;t++){var a=e[t-1],s=e[t],l=(s.data-a.data)/n,c=r+l;o.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{data:o,max:i,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 i=this._ctx;var{fontFamily:e,fontSize:n,tickWidth:r,paddingTop:a,paddingBottom:s}=this._cfg,l=(i.font=n+"px "+e,3*n),c=t-s-a,h=Math.ceil(c/l),l=c/h;i.textBaseline="middle";let d=0;const u=[];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):roundFixed(f,2),g=i.measureText(f);d=Math.max(g.width,d),u.push({label:f,width:g.width})}for(let e=0;e<u.length;e++){var m=u[e];let t=0;t=0===e?0:e===u.length-1?c-1:Math.floor(e*l),t+=a;var p=o-d-4-r;i.fillStyle=this._cfg.tickColor,i.fillRect(p,t,r,1),i.fillStyle=this._cfg.fontColor,i.fillText(m.label,p+r+4,t)}return{maxLabelWidth:4+d+r}}_draw(){if(!this._canvas||!this._ctx)return this;var{paddingTop:e,paddingBottom:t}=this._cfg,o=this._canvas.offsetWidth,i=this._canvas.offsetHeight,n=(this._canvas.width=o,this._canvas.height=i,this._ctx.clearRect(0,0,o,i),this._drawAxias(o,i))["maxLabelWidth"],r=i-e-t;for(let t=0;t<this._colorList.length;t++){var a=this._colorList[t],s=r*(1-a.to.ratio),l=r*(1-a.from.ratio),s=Math.ceil(s+e),l=Math.ceil(l+e);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,o-n,l-s)}}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 i=textCanvas.getContext("2d");i.font=t.fontSize+"px "+t.fontFamily;let n=0;const r=[],a=(t.text.forEach(function(t){t=i.measureText(t);r.push(t.width),n=Math.max(t.width,n)}),t.fontSize*t.fontLineHeight),s=a*t.text.length;var o=Math.abs(n*Math.cos(e))+Math.abs(s*Math.sin(e)),l=Math.abs(n*Math.sin(e))+Math.abs(s*Math.cos(e));textCanvas.width=o,textCanvas.height=l,i.translate(o/2,l/2),i.rotate(e),i.fillStyle=t.fontBackgroundColor,i.fillRect(-n/2,-s/2,n,s),i.fillStyle=t.fontColor,i.font=t.fontSize+"px "+t.fontFamily,i.textBaseline="top",i.textAlign="left";const c=(a-t.fontSize)/2;return t.text.forEach(function(t,e){var o=n/2-r[e]/2;i.fillText(t,-n/2+o,-s/2+e*a+c)}),{img:textCanvas,width:o,height:l}}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,i=this._oWrapper.offsetHeight*window.devicePixelRatio;t.width=o,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 n=t.getContext("2d");if(n&&(n.clearRect(0,0,o,i),!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<i;t+=r.height+this._cfg.gapY)n.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,n="",o=document.createElement("style");return o.className=t,document.getElementsByTagName("head")[0].appendChild(o),function(t){var i;e=n,_String(t).replace(/(.*?)({.*?})/g,function(t,e,o){return e=trim(e),n=n.replace(new RegExp("("+e+"\\s*?)({.*?})","g"),function(){return i=!0,e+trim(o)}),""}),i?e!==n&&fillHtml(o,n):(n+=_String(t),fillHtml(o,n))}}const oStyle=createStyle("bt-waterflow");function getMinMatrix(t){const e=min(t,function(t){return t.height});var o=Math.max(t.findIndex(t=>t.height===e),0);return{index:o,position:t[o]}}oStyle(`
6
+ .bt-waterflow-wrapper{position:relative;list-style:none;margin:0;padding:0;box-sizing:border-box;}
7
+ .bt-waterflow-item{list-style:none;margin:0;padding:0;position:absolute;bottom:unset;right:unset;left:0;top:0;opacity:0;transition: 0.5s;transform:scale(0) rotateX(45deg);transform-origin:top center;}
8
+ .bt-waterflow-item.rendered{transform:scale(1) rotateX(0);opacity: 1;}
9
+ `);class WaterfallFlow{_cfg;_timer;constructor(t){this._cfg=Object.assign({gap:10},t),addClass(t.el,"bt-waterflow-wrapper")}_autoPlay(){clearTimeout(this._timer),this._cfg.autoResize&&(this._timer=setTimeout(()=>{this.resize()},this._cfg.autoResize))}resize(){clearTimeout(this._timer);var e=this._cfg.el.getElementsByClassName("bt-waterflow-item");if(0!==e.length){var t=this._cfg.el.offsetWidth,o=Math.max(1,Math.floor((t+this._cfg.gap)/(e[0].offsetWidth+this._cfg.gap)));const r=[];var i=(t-(o-1)*this._cfg.gap-e[0].offsetWidth*o)/2;for(let t=0;t<o;t++)r.push({height:0,data:[]});for(let t=0;t<e.length;t++){const a=e[t],s=getMinMatrix(r);var n=0<s.position.height?this._cfg.gap:0,n={left:i+(a.offsetWidth+this._cfg.gap)*s.index,top:s.position.height+n,height:a.offsetHeight};s.position.height=n.height+n.top,s.position.data.push(n),a.style.left=n.left+"px",a.style.top=n.top+"px",addClass(a,"rendered")}t=max(r,function(t){return t.height})??0;this._cfg.el.style.height=t+"px",this._autoPlay()}}pause(){return clearTimeout(this._timer),this}dispose(){clearTimeout(this._timer)}}const style=createStyle("bt-browser-core");export{LinearGradientColorLegend,SeamlessRolling,TextRainCanvas,WaterMark,WaterfallFlow,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};
@@ -19,7 +19,8 @@ declare function observeDomResize(
19
19
  element: HTMLElement,
20
20
  handler: (element: HTMLElement) => void,
21
21
  type?: ('width' | 'height' | 'position')[],
22
- interval?: number
22
+ interval?: number,
23
+ immediate?: boolean
23
24
  ): () => void;
24
25
 
25
26
  /**
@@ -194,7 +195,7 @@ type Direction = 1 | -1;
194
195
  * @param isPrevent 是否阻止原生滚动,仅用来获取滚动方向
195
196
  * @returns
196
197
  */
197
- declare function export_default$1(
198
+ declare function observeMouseWheel(
198
199
  el: HTMLElement,
199
200
  callback: (direction: Direction) => void,
200
201
  isPrevent: boolean
@@ -427,6 +428,29 @@ declare class WaterMark {
427
428
  _draw(): void;
428
429
  }
429
430
 
431
+ /**
432
+ * 将部分属性变为可选
433
+ */
434
+ type TPartialOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
435
+
436
+ interface IWaterfallFlowConfig {
437
+ el: HTMLElement;
438
+ gap: number;
439
+ /**
440
+ * 自动播放在第一次主动执行 resize 后生效(避免首次渲染过渡动画卡顿)
441
+ */
442
+ autoResize?: number;
443
+ }
444
+ declare class WaterfallFlow {
445
+ private _cfg;
446
+ private _timer;
447
+ constructor(config: TPartialOptional<IWaterfallFlowConfig, 'gap'>);
448
+ _autoPlay(): void;
449
+ resize(): void;
450
+ pause(): this;
451
+ dispose(): void;
452
+ }
453
+
430
454
  declare const style: (str: string) => void;
431
455
 
432
456
  declare global {
@@ -439,6 +463,7 @@ declare global {
439
463
  SeamlessRolling,
440
464
  TextRainCanvas,
441
465
  WaterMark,
466
+ WaterfallFlow,
442
467
  addClass,
443
468
  _default as browser,
444
469
  copyText,
@@ -457,7 +482,7 @@ declare global {
457
482
  libraryFile,
458
483
  observeDomResize,
459
484
  export_default as observeDomScroll,
460
- export_default$1 as observeMouseWheel,
485
+ observeMouseWheel,
461
486
  pdfToImage,
462
487
  prevent,
463
488
  removeClass,
@@ -1,5 +1,9 @@
1
1
  /**
2
2
  * 浏览器工具库 => jUtilsBrowser
3
- * @update 2025-08-06 10:49:02
3
+ * @update 2026-01-17 22:11:46
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 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)}});
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 i=0,n,o=!1;const r={};let s;var d={add:function(t,e){return n="HI-"+ ++i,r[n]={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)),n},remove:function(t){delete r[t],0===Object.keys(r).length&&(o=!1,clearInterval(s),s=undefined)}};function a(t,e){const i=document.createElement("a");i.style.display="none",i.download=e,i.setAttribute("href",t),i.setAttribute("target","_blank"),i.setAttribute("download",e),document.body.appendChild(i),i.click(),i.remove()}const l=void 0,c=decodeURIComponent,u=window,f=document.getElementsByTagName("head")[0],g=u.URL;function m(t,e){t=g.createObjectURL(t);a(t,e),g.revokeObjectURL(t),undefined}const p={};function x(i,n){const o=[];let r=0;for(let e=0;e<i.length;e++)w(i[e],function(t){o[e]=t,++r===i.length&&n.apply(l,o)})}function w(t,e){var i=t.dependencies&&t.dependencies.length,n=t["with"]&&t["with"].length;p[t.url]||(p[t.url]={count:0,dependencies:!i,"with":!n,complete:!1,create:!1,url:t.url});const o=p[t.url];function r(){return u[t.module]}function s(){o.complete&&o.dependencies&&o["with"]&&(t.module?e(r()):e())}if(o.count++,!o.dependencies&&i)o.dependencies=!0,x(t.dependencies,function(){w(t,e)});else if(!o["with"]&&n)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 i=t.type,n=t.url,a=function(){o.complete=!0,t.interceptor&&t.interceptor(r()),s()},l=t.attribute;if(f){let t;if("js"===i?(t=document.createElement("script")).src=n:((t=document.createElement("link")).setAttribute("rel","stylesheet"),t.href=n),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,i){var n;n=e,e=n=v.isString(n)?n:JSON.stringify(n);let o=t+"="+encodeURI(e)+";path=/;";"number"==typeof i&&((n=new Date).setTime(n.getTime()+i),o+="expires="+n.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 y(e,t){v.isArray(t)?v.forEach(t,function(t){e.classList.add(t)}):e.classList.add(t)}var S=u.navigator.userAgent,S={isChrome:/Chrome/.test(S),isIPhone:/iPhone/.test(S)};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 i=t.offsetWidth,n=t.offsetHeight;t.width=i,t.height=n,this.width=i,this.height=n,e&&(this.text=e.text||this.text,this.fontSize=e.fontSize||this.fontSize,this.color=e.color?function(t){for(var e=[],i=1;i<7;i+=2)e.push(parseInt("0x"+t.slice(i,i+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(n=>{n.list.forEach((t,e)=>{let i;this.reverse?(i=(e-n.currentIndex)/10,i=1-t.speed*i,e<n.currentIndex&&(i=0)):(i=(n.currentIndex-e)/10,i=1-t.speed*i,e>n.currentIndex&&(i=0)),0<i&&(this.ctx.fillStyle=`rgba(${this.color.join(",")}, ${i})`,this.ctx.fillText(t.text,t.x,t.y))}),this.reverse?(n.currentIndex--,n.currentIndex+10<0&&(n.currentIndex=this.count+v.getRandom(0,this.count))):(n.currentIndex++,n.currentIndex-10>n.list.length-1&&(n.currentIndex=-v.getRandom(0,this.count)))}),clearTimeout(this.timer),this.timer=setTimeout(this.draw,this.interval)}createColumn(e,t){const i=[];for(let t=0;t<this.count;t++){var n=v.getRandom(0,this.text.length-1);i.push({text:this.text[n],x:e,y:Math.floor(t*this.fontLineHeight),speed:1})}return{currentIndex:t,list:i}}dispose(){this.isStop=!0,clearTimeout(this.timer)}start(){this.isStop=!1,this.draw()}getPointList(){const n=[];var o=this.fontSize,t=Math.floor(this.width/o);for(let i=0;i<t;i++){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?n.push(this.createColumn(i*o,this.count+e)):n.push(this.createColumn(i*o,-e))}return this.pointList=n}}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=u.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 F{_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(i,t){const n=this._ctx;var{fontFamily:e,fontSize:o,tickWidth:r,paddingTop:s,paddingBottom:a}=this._cfg,l=(n.font=o+"px "+e,3*o),c=t-a-s,h=Math.ceil(c/l),l=c/h;n.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),g=n.measureText(f);u=Math.max(g.width,u),d.push({label:f,width:g.width})}for(let e=0;e<d.length;e++){var m=d[e];let t=0;t=0===e?0:e===d.length-1?c-1:Math.floor(e*l),t+=s;var p=i-u-4-r;n.fillStyle=this._cfg.tickColor,n.fillRect(p,t,r,1),n.fillStyle=this._cfg.fontColor,n.fillText(m.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,i=this._canvas.offsetWidth,n=this._canvas.offsetHeight,o=(this._canvas.width=i,this._canvas.height=n,this._ctx.clearRect(0,0,i,n),this._drawAxias(i,n))["maxLabelWidth"],r=n-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,i-o,l-a)}}setColors(t){return t.length<2||(t=function(e){e.sort(function(t,e){return t.data-e.data});const i=[];var t=v.min(e,function(t){return t.data}),n=v.max(e,function(t){return t.data}),o=n-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;i.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:i,max:n,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 i;i=t||(e<this._colorList[0].from.value?this._colorList[0]:this._colorList[this._colorList.length-1]);var t=e-i.from.value,t=Math.min(t/(i.to.value-i.from.value),1),n=i.from.color,o=i.to.color,[n,r,s]=(t=Math.max(t,0),t=Math.min(t,1),M(v.hexToRgba(n))),[o,a,l]=M(v.hexToRgba(o)),o=Math.round(n+(o-n)*t),n=Math.round(r+(a-r)*t),a=Math.round(s+(l-s)*t);return v.rgbaToHex(`rgba(${o},${n},${a},1)`)}}const E=document.createElement("canvas");class W{_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 i=this._oWrapper.offsetWidth*window.devicePixelRatio,n=this._oWrapper.offsetHeight*window.devicePixelRatio;t.width=i,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 o=t.getContext("2d");if(o&&(o.clearRect(0,0,i,n),!this._cfg.disabled)){var r=function(t){var e=t.angle*Math.PI/180;const n=E.getContext("2d");n.font=t.fontSize+"px "+t.fontFamily;let o=0;const r=[],s=(t.text.forEach(function(t){t=n.measureText(t);r.push(t.width),o=Math.max(t.width,o)}),t.fontSize*t.fontLineHeight),a=s*t.text.length;var i=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));E.width=i,E.height=l,n.translate(i/2,l/2),n.rotate(e),n.fillStyle=t.fontBackgroundColor,n.fillRect(-o/2,-a/2,o,a),n.fillStyle=t.fontColor,n.font=t.fontSize+"px "+t.fontFamily,n.textBaseline="top",n.textAlign="left";const c=(s-t.fontSize)/2;return t.text.forEach(function(t,e){var i=o/2-r[e]/2;n.fillText(t,-o/2+i,-a/2+e*s+c)}),{img:E,width:i,height:l}}(this._cfg);for(let e=0;e<i;e+=r.width+this._cfg.gapX)for(let t=0;t<n;t+=r.height+this._cfg.gapY)o.drawImage(r.img,e,t)}}}function H(t,e){t.styleSheet?t.styleSheet.cssText=e:t.innerHTML=e}let z=0;function I(t){z++,(t=v.trim(t))&&!/^[0-9]/.test(t)||(t="bt-style-"+z);var e,o="",i=document.createElement("style");return i.className=t,document.getElementsByTagName("head")[0].appendChild(i),function(t){var n;e=o,v._String(t).replace(/(.*?)({.*?})/g,function(t,e,i){return e=v.trim(e),o=o.replace(new RegExp("("+e+"\\s*?)({.*?})","g"),function(){return n=!0,e+v.trim(i)}),""}),n?e!==o&&H(i,o):(o+=v._String(t),H(i,o))}}const k=I("bt-waterflow");k(`
6
+ .bt-waterflow-wrapper{position:relative;list-style:none;margin:0;padding:0;box-sizing:border-box;}
7
+ .bt-waterflow-item{list-style:none;margin:0;padding:0;position:absolute;bottom:unset;right:unset;left:0;top:0;opacity:0;transition: 0.5s;transform:scale(0) rotateX(45deg);transform-origin:top center;}
8
+ .bt-waterflow-item.rendered{transform:scale(1) rotateX(0);opacity: 1;}
9
+ `);class B{_cfg;_timer;constructor(t){this._cfg=Object.assign({gap:10},t),y(t.el,"bt-waterflow-wrapper")}_autoPlay(){clearTimeout(this._timer),this._cfg.autoResize&&(this._timer=setTimeout(()=>{this.resize()},this._cfg.autoResize))}resize(){clearTimeout(this._timer);var e=this._cfg.el.getElementsByClassName("bt-waterflow-item");if(0!==e.length){var t=this._cfg.el.offsetWidth,i=Math.max(1,Math.floor((t+this._cfg.gap)/(e[0].offsetWidth+this._cfg.gap)));const r=[];var n=(t-(i-1)*this._cfg.gap-e[0].offsetWidth*i)/2;for(let t=0;t<i;t++)r.push({height:0,data:[]});for(let t=0;t<e.length;t++){const s=e[t],a=function(t){const e=v.min(t,function(t){return t.height});var i=Math.max(t.findIndex(t=>t.height===e),0);return{index:i,position:t[i]}}(r);var o=0<a.position.height?this._cfg.gap:0,o={left:n+(s.offsetWidth+this._cfg.gap)*a.index,top:a.position.height+o,height:s.offsetHeight};a.position.height=o.height+o.top,a.position.data.push(o),s.style.left=o.left+"px",s.style.top=o.top+"px",y(s,"rendered")}t=v.max(r,function(t){return t.height})??0;this._cfg.el.style.height=t+"px",this._autoPlay()}}pause(){return clearTimeout(this._timer),this}dispose(){clearTimeout(this._timer)}}var $=I("bt-browser-core");t.LinearGradientColorLegend=F,t.SeamlessRolling=T,t.TextRainCanvas=L,t.WaterMark=W,t.WaterfallFlow=B,t.addClass=y,t.browser=S,t.copyText=R,t.createXLSX=async function(t){const e=document.createElement("table"),i=v.parseTreeToTableHeader(t.header);var n=i.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>${i.columns.map(function(t){var e=n.$colField?.[t]??1,i=n.$rowSpan?.[t]??1;if(0!==e&&0!==i)return`<td align="center" colSpan="${e}" rowSpan="${i}">${n[t]??""}</td>`}).filter(function(t){return!v.isNull(t)}).join("")}</tr>`}).join("");return e.innerHTML=`<thead>${n}</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,i){if(e){e=t;t=i;const n=t||C;e.requestFullscreen?e.requestFullscreen():e.webkitRequestFullScreen?e.webkitRequestFullScreen():e.mozRequestFullScreen?e.mozRequestFullScreen():e.msRequestFullscreen&&e.msRequestFullscreen(),n(!0)}else{t=i;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 n="";return e.replace(new RegExp("(^|;\\s?)"+t+"=(.*?)($|(;\\s?))"),function(t,e,i){n=c(i)}),n},t.getJsFileBaseUrl=function(t){t=t||0;for(var e="/[^/]*",i=document.scripts,n=0;n<t;n++)e+=e;return i[i.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",i=t.width,n=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-i-s],t=[s,t.height-n-s];return"top-right"===e?(a+=r,l=l-n-o,a<c[0]?a=c[0]:a>c[1]&&(s=a-i-2*r,a=c[0]<s?s:c[1]),l<t[0]?(s=l+n+2*o,l=s<t[1]?s:t[0]):l>t[1]&&(l=l-n-2*o)):"bottom-right"===e?(a+=r,(l+=o)>t[1]&&(s=l-n-2*o,l=s<t[0]?t[1]:s),a>c[1]&&(t=a-i-2*r,a=t<c[0]?c[1]:t)):"top-left"===e&&(a=a-i-r,l=l-n-o),{x:a,y:l}},t.libraryFile=_,t.observeDomResize=function(i,n,o,t,e){e=!1!==e;let r=[0,0,!1],s=[0,0,!1],a=[0,0,!1],l=[0,0,!1];const c=d.add(h,t=t||500);function h(){if(document.body.contains(i)){let t=!1;var e;o?.includes("position")&&(e=i.getBoundingClientRect(),a[0]=e.left,a[2]=a[0]!==a[1],l[0]=e.top,l[2]=l[0]!==l[1]),r[0]=i.offsetWidth,r[2]=r[0]!==r[1],s[0]=i.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&&n(i)}else u()}function u(){d.remove(c),r=undefined,s=undefined}return e&&h(),u},t.observeDomScroll=function(i,t){const n=v._KvPair(t),o=v._Number(n.offetY);let r=!1,s=0;function e(){var t,e;r||(e=(t=i.scrollTop)-s,s=t,0!=e?e<0&&n.onTop&&t<=0+o?(r=!0,n.onTop(function(){r=!1})):0<e&&n.onBottom&&t>=i.scrollHeight-i.offsetHeight-o?(r=!0,n.onBottom(function(){r=!1})):r=!1:(r=!1,console.log("未处理")))}return i.addEventListener("scroll",e),{dispose:function(){i.removeEventListener("scroll",e)}}},t.observeMouseWheel=function(t,i,n){function e(t){let e;if(e=t.wheelDelta?0<t.wheelDelta?1:-1:t.detail<0?1:-1,i(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)}}},t.pdfToImage=async function(t,o,e){n=e;const i=await new Promise(function(t){_({type:"js",module:"pdfjsLib",attribute:{type:"module"},url:n.index,interceptor:function(t){t.GlobalWorkerOptions.workerSrc=n.worker}},t)});var n;return new Promise(function(n){i.getDocument(t).promise.then(function(t){console.log("pdf",t),t.getPage(1).then(function(t){var e=t.getViewport({scale:1}),i=o.getContext("2d");o.height=e.height,o.width=e.width,t.render({canvasContext:i,viewport:e}).promise.then(function(){n({width:e.width,height:e.height})})})},function(t){console.error(t),n({width:0,height:0})})})},t.prevent=function(t,e,i){t=t||u.event,i=!1!==i,(e=!1!==e)&&u.event?u.event.cancelBubble=!0:t.stopPropagation(),i&&u.event?u.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,i){b(t,e),y(t,i)},t.setCookie=e,t.setStorage=function(t,e){localStorage.setItem(t,(t=e,t=v.isString(t)?t:JSON.stringify(t)))},t.style=$,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.14",
3
+ "version": "1.0.15",
4
4
  "main": "./dist/esm/index.min.mjs",
5
5
  "module": "./dist/esm/index.min.mjs",
6
6
  "types": "./dist/esm/index.d.ts",