@bestime/utils_browser 1.0.10 → 1.0.12
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.
- package/dist/esm/index.d.ts +132 -7
- package/dist/esm/index.mjs +5 -0
- package/dist/umd/index.d.ts +132 -7
- package/dist/umd/index.min.cjs +2 -2
- package/package.json +6 -7
- package/dist/esm/index.min.mjs +0 -5
package/dist/esm/index.d.ts
CHANGED
|
@@ -36,6 +36,13 @@ declare function downloadFileByUrl(url: string, fileName: string): void;
|
|
|
36
36
|
*/
|
|
37
37
|
declare function downloadFileByArrayBuffer(data: ArrayBuffer, fileName: string): void;
|
|
38
38
|
|
|
39
|
+
/**
|
|
40
|
+
* 下载Blob文件
|
|
41
|
+
* @param data - 数据
|
|
42
|
+
* @param fileName - 文件名
|
|
43
|
+
*/
|
|
44
|
+
declare function downloadFileByBolb(data: Blob, fileName: string): void;
|
|
45
|
+
|
|
39
46
|
/**
|
|
40
47
|
* 移除Dom节点
|
|
41
48
|
* @param dom - 待移除的dom元素
|
|
@@ -196,7 +203,7 @@ declare function export_default$1(
|
|
|
196
203
|
};
|
|
197
204
|
|
|
198
205
|
type TCallbackHandler = (next: () => void) => void;
|
|
199
|
-
interface IOptions$
|
|
206
|
+
interface IOptions$3 {
|
|
200
207
|
onBottom?: TCallbackHandler;
|
|
201
208
|
onTop?: TCallbackHandler;
|
|
202
209
|
/** Y轴触底、触顶的差值 */
|
|
@@ -209,7 +216,7 @@ interface IOptions$1 {
|
|
|
209
216
|
*/
|
|
210
217
|
declare function export_default(
|
|
211
218
|
el: HTMLElement,
|
|
212
|
-
config?: IOptions$
|
|
219
|
+
config?: IOptions$3
|
|
213
220
|
): {
|
|
214
221
|
/**
|
|
215
222
|
* 销毁
|
|
@@ -237,13 +244,15 @@ declare function createXLSX(options: {
|
|
|
237
244
|
}): Promise<HTMLTableElement>;
|
|
238
245
|
|
|
239
246
|
interface IPluginSrc {
|
|
247
|
+
/** .mjs结尾的主文件 */
|
|
240
248
|
index: string;
|
|
249
|
+
/** .mjs结尾的worker文件 */
|
|
241
250
|
worker: string;
|
|
242
251
|
}
|
|
243
252
|
declare function pdfToImage(
|
|
244
253
|
url: string,
|
|
245
254
|
canvas: HTMLCanvasElement,
|
|
246
|
-
src
|
|
255
|
+
src: IPluginSrc
|
|
247
256
|
): Promise<unknown>;
|
|
248
257
|
|
|
249
258
|
/**
|
|
@@ -266,7 +275,7 @@ declare function infoContainerPosition(options: {
|
|
|
266
275
|
offsetY?: number;
|
|
267
276
|
/** 距离视口多少时表示超出可视范围。默认 10*/
|
|
268
277
|
padding?: number;
|
|
269
|
-
mode?: 'top-right';
|
|
278
|
+
mode?: 'top-right' | 'bottom-right';
|
|
270
279
|
/** 在什么区域活动 */
|
|
271
280
|
targetSize?: {
|
|
272
281
|
width: number;
|
|
@@ -277,7 +286,7 @@ declare function infoContainerPosition(options: {
|
|
|
277
286
|
y: number;
|
|
278
287
|
};
|
|
279
288
|
|
|
280
|
-
interface IOptions {
|
|
289
|
+
interface IOptions$2 {
|
|
281
290
|
text?: string;
|
|
282
291
|
fontSize?: number;
|
|
283
292
|
color?: string;
|
|
@@ -299,7 +308,7 @@ declare class TextRainCanvas {
|
|
|
299
308
|
interval: number;
|
|
300
309
|
width: number;
|
|
301
310
|
height: number;
|
|
302
|
-
|
|
311
|
+
fontLineHeight: number;
|
|
303
312
|
count: number;
|
|
304
313
|
oCanvas: HTMLCanvasElement;
|
|
305
314
|
ctx: CanvasRenderingContext2D;
|
|
@@ -308,7 +317,7 @@ declare class TextRainCanvas {
|
|
|
308
317
|
currentIndex: number;
|
|
309
318
|
list: IPointItem[];
|
|
310
319
|
}[];
|
|
311
|
-
constructor(oCanvas: HTMLCanvasElement, option?: IOptions);
|
|
320
|
+
constructor(oCanvas: HTMLCanvasElement, option?: IOptions$2);
|
|
312
321
|
draw(): void;
|
|
313
322
|
createColumn(
|
|
314
323
|
x: number,
|
|
@@ -325,12 +334,126 @@ declare class TextRainCanvas {
|
|
|
325
334
|
}[];
|
|
326
335
|
}
|
|
327
336
|
|
|
337
|
+
declare class SeamlessRolling {
|
|
338
|
+
_wrapper: HTMLDivElement;
|
|
339
|
+
_timer: number;
|
|
340
|
+
constructor(wraper: HTMLDivElement);
|
|
341
|
+
_updateContent(): void;
|
|
342
|
+
_doScroll(): void;
|
|
343
|
+
dispose(): void;
|
|
344
|
+
}
|
|
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
|
+
declare function func01(text: string): Promise<void>;
|
|
362
|
+
/**
|
|
363
|
+
* 复制文本
|
|
364
|
+
*/
|
|
365
|
+
declare const copyText: typeof func01;
|
|
366
|
+
|
|
367
|
+
interface IColorItem {
|
|
368
|
+
data: number;
|
|
369
|
+
color: string;
|
|
370
|
+
}
|
|
371
|
+
interface IOptions$1 {
|
|
372
|
+
fontFamily: string;
|
|
373
|
+
fontSize: number;
|
|
374
|
+
tickWidth: number;
|
|
375
|
+
tickColor: string;
|
|
376
|
+
fontColor: string;
|
|
377
|
+
paddingTop: number;
|
|
378
|
+
paddingBottom: number;
|
|
379
|
+
colors: IColorItem[];
|
|
380
|
+
}
|
|
381
|
+
interface IUseColorItem {
|
|
382
|
+
from: {
|
|
383
|
+
value: number;
|
|
384
|
+
color: string;
|
|
385
|
+
ratio: number;
|
|
386
|
+
};
|
|
387
|
+
to: {
|
|
388
|
+
value: number;
|
|
389
|
+
color: string;
|
|
390
|
+
ratio: number;
|
|
391
|
+
};
|
|
392
|
+
ratio: number;
|
|
393
|
+
label: string;
|
|
394
|
+
}
|
|
395
|
+
declare class LinearGradientColorLegend {
|
|
396
|
+
_cfg: IOptions$1;
|
|
397
|
+
_canvas: HTMLCanvasElement | undefined;
|
|
398
|
+
_colorList: IUseColorItem[];
|
|
399
|
+
_ctx: CanvasRenderingContext2D | undefined;
|
|
400
|
+
_minValue: number;
|
|
401
|
+
_maxValue: number;
|
|
402
|
+
constructor(options: Partial<IOptions$1>);
|
|
403
|
+
mount(oCanvas: HTMLCanvasElement): void;
|
|
404
|
+
_drawAxias(
|
|
405
|
+
width: number,
|
|
406
|
+
height: number
|
|
407
|
+
): {
|
|
408
|
+
maxLabelWidth: number;
|
|
409
|
+
};
|
|
410
|
+
_draw(): this | undefined;
|
|
411
|
+
setColors(colors: IColorItem[]): this;
|
|
412
|
+
/**
|
|
413
|
+
* 根据值获取颜色
|
|
414
|
+
* @param value
|
|
415
|
+
* @returns
|
|
416
|
+
*/
|
|
417
|
+
getColor(value: number): string;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
interface IOptions {
|
|
421
|
+
disabled?: boolean;
|
|
422
|
+
gapX: number;
|
|
423
|
+
gapY: number;
|
|
424
|
+
text: string[];
|
|
425
|
+
/** 行高(仅支持倍率) */
|
|
426
|
+
fontLineHeight: number;
|
|
427
|
+
fontSize: number;
|
|
428
|
+
fontBackgroundColor: string;
|
|
429
|
+
fontFamily: string;
|
|
430
|
+
fontColor: string;
|
|
431
|
+
/** 旋转角度(0-360) */
|
|
432
|
+
angle: number;
|
|
433
|
+
}
|
|
434
|
+
declare class WaterMark {
|
|
435
|
+
_cfg: IOptions;
|
|
436
|
+
_oWrapper: HTMLDivElement;
|
|
437
|
+
_canvas: HTMLCanvasElement;
|
|
438
|
+
constructor(oWrapper: HTMLDivElement, config: Partial<IOptions>);
|
|
439
|
+
_reload(): HTMLCanvasElement;
|
|
440
|
+
setConfig(config: Partial<IOptions>): void;
|
|
441
|
+
_draw(): void;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
declare const style: (str: string) => void;
|
|
445
|
+
|
|
328
446
|
export {
|
|
447
|
+
LinearGradientColorLegend,
|
|
448
|
+
SeamlessRolling,
|
|
329
449
|
TextRainCanvas,
|
|
450
|
+
WaterMark,
|
|
330
451
|
addClass,
|
|
331
452
|
_default as browser,
|
|
453
|
+
copyText,
|
|
332
454
|
createXLSX,
|
|
333
455
|
downloadFileByArrayBuffer,
|
|
456
|
+
downloadFileByBolb,
|
|
334
457
|
downloadFileByUrl,
|
|
335
458
|
fullScreen,
|
|
336
459
|
getCookie,
|
|
@@ -353,6 +476,8 @@ export {
|
|
|
353
476
|
replaceClass,
|
|
354
477
|
setCookie,
|
|
355
478
|
setStorage,
|
|
479
|
+
speakText,
|
|
480
|
+
style,
|
|
356
481
|
toggleClass
|
|
357
482
|
};
|
|
358
483
|
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 浏览器工具库 => jUtilsBrowser
|
|
3
|
+
* @update 2025-04-16 19:17:01
|
|
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};
|
package/dist/umd/index.d.ts
CHANGED
|
@@ -36,6 +36,13 @@ declare function downloadFileByUrl(url: string, fileName: string): void;
|
|
|
36
36
|
*/
|
|
37
37
|
declare function downloadFileByArrayBuffer(data: ArrayBuffer, fileName: string): void;
|
|
38
38
|
|
|
39
|
+
/**
|
|
40
|
+
* 下载Blob文件
|
|
41
|
+
* @param data - 数据
|
|
42
|
+
* @param fileName - 文件名
|
|
43
|
+
*/
|
|
44
|
+
declare function downloadFileByBolb(data: Blob, fileName: string): void;
|
|
45
|
+
|
|
39
46
|
/**
|
|
40
47
|
* 移除Dom节点
|
|
41
48
|
* @param dom - 待移除的dom元素
|
|
@@ -196,7 +203,7 @@ declare function export_default$1(
|
|
|
196
203
|
};
|
|
197
204
|
|
|
198
205
|
type TCallbackHandler = (next: () => void) => void;
|
|
199
|
-
interface IOptions$
|
|
206
|
+
interface IOptions$3 {
|
|
200
207
|
onBottom?: TCallbackHandler;
|
|
201
208
|
onTop?: TCallbackHandler;
|
|
202
209
|
/** Y轴触底、触顶的差值 */
|
|
@@ -209,7 +216,7 @@ interface IOptions$1 {
|
|
|
209
216
|
*/
|
|
210
217
|
declare function export_default(
|
|
211
218
|
el: HTMLElement,
|
|
212
|
-
config?: IOptions$
|
|
219
|
+
config?: IOptions$3
|
|
213
220
|
): {
|
|
214
221
|
/**
|
|
215
222
|
* 销毁
|
|
@@ -237,13 +244,15 @@ declare function createXLSX(options: {
|
|
|
237
244
|
}): Promise<HTMLTableElement>;
|
|
238
245
|
|
|
239
246
|
interface IPluginSrc {
|
|
247
|
+
/** .mjs结尾的主文件 */
|
|
240
248
|
index: string;
|
|
249
|
+
/** .mjs结尾的worker文件 */
|
|
241
250
|
worker: string;
|
|
242
251
|
}
|
|
243
252
|
declare function pdfToImage(
|
|
244
253
|
url: string,
|
|
245
254
|
canvas: HTMLCanvasElement,
|
|
246
|
-
src
|
|
255
|
+
src: IPluginSrc
|
|
247
256
|
): Promise<unknown>;
|
|
248
257
|
|
|
249
258
|
/**
|
|
@@ -266,7 +275,7 @@ declare function infoContainerPosition(options: {
|
|
|
266
275
|
offsetY?: number;
|
|
267
276
|
/** 距离视口多少时表示超出可视范围。默认 10*/
|
|
268
277
|
padding?: number;
|
|
269
|
-
mode?: 'top-right';
|
|
278
|
+
mode?: 'top-right' | 'bottom-right';
|
|
270
279
|
/** 在什么区域活动 */
|
|
271
280
|
targetSize?: {
|
|
272
281
|
width: number;
|
|
@@ -277,7 +286,7 @@ declare function infoContainerPosition(options: {
|
|
|
277
286
|
y: number;
|
|
278
287
|
};
|
|
279
288
|
|
|
280
|
-
interface IOptions {
|
|
289
|
+
interface IOptions$2 {
|
|
281
290
|
text?: string;
|
|
282
291
|
fontSize?: number;
|
|
283
292
|
color?: string;
|
|
@@ -299,7 +308,7 @@ declare class TextRainCanvas {
|
|
|
299
308
|
interval: number;
|
|
300
309
|
width: number;
|
|
301
310
|
height: number;
|
|
302
|
-
|
|
311
|
+
fontLineHeight: number;
|
|
303
312
|
count: number;
|
|
304
313
|
oCanvas: HTMLCanvasElement;
|
|
305
314
|
ctx: CanvasRenderingContext2D;
|
|
@@ -308,7 +317,7 @@ declare class TextRainCanvas {
|
|
|
308
317
|
currentIndex: number;
|
|
309
318
|
list: IPointItem[];
|
|
310
319
|
}[];
|
|
311
|
-
constructor(oCanvas: HTMLCanvasElement, option?: IOptions);
|
|
320
|
+
constructor(oCanvas: HTMLCanvasElement, option?: IOptions$2);
|
|
312
321
|
draw(): void;
|
|
313
322
|
createColumn(
|
|
314
323
|
x: number,
|
|
@@ -325,17 +334,131 @@ declare class TextRainCanvas {
|
|
|
325
334
|
}[];
|
|
326
335
|
}
|
|
327
336
|
|
|
337
|
+
declare class SeamlessRolling {
|
|
338
|
+
_wrapper: HTMLDivElement;
|
|
339
|
+
_timer: number;
|
|
340
|
+
constructor(wraper: HTMLDivElement);
|
|
341
|
+
_updateContent(): void;
|
|
342
|
+
_doScroll(): void;
|
|
343
|
+
dispose(): void;
|
|
344
|
+
}
|
|
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
|
+
declare function func01(text: string): Promise<void>;
|
|
362
|
+
/**
|
|
363
|
+
* 复制文本
|
|
364
|
+
*/
|
|
365
|
+
declare const copyText: typeof func01;
|
|
366
|
+
|
|
367
|
+
interface IColorItem {
|
|
368
|
+
data: number;
|
|
369
|
+
color: string;
|
|
370
|
+
}
|
|
371
|
+
interface IOptions$1 {
|
|
372
|
+
fontFamily: string;
|
|
373
|
+
fontSize: number;
|
|
374
|
+
tickWidth: number;
|
|
375
|
+
tickColor: string;
|
|
376
|
+
fontColor: string;
|
|
377
|
+
paddingTop: number;
|
|
378
|
+
paddingBottom: number;
|
|
379
|
+
colors: IColorItem[];
|
|
380
|
+
}
|
|
381
|
+
interface IUseColorItem {
|
|
382
|
+
from: {
|
|
383
|
+
value: number;
|
|
384
|
+
color: string;
|
|
385
|
+
ratio: number;
|
|
386
|
+
};
|
|
387
|
+
to: {
|
|
388
|
+
value: number;
|
|
389
|
+
color: string;
|
|
390
|
+
ratio: number;
|
|
391
|
+
};
|
|
392
|
+
ratio: number;
|
|
393
|
+
label: string;
|
|
394
|
+
}
|
|
395
|
+
declare class LinearGradientColorLegend {
|
|
396
|
+
_cfg: IOptions$1;
|
|
397
|
+
_canvas: HTMLCanvasElement | undefined;
|
|
398
|
+
_colorList: IUseColorItem[];
|
|
399
|
+
_ctx: CanvasRenderingContext2D | undefined;
|
|
400
|
+
_minValue: number;
|
|
401
|
+
_maxValue: number;
|
|
402
|
+
constructor(options: Partial<IOptions$1>);
|
|
403
|
+
mount(oCanvas: HTMLCanvasElement): void;
|
|
404
|
+
_drawAxias(
|
|
405
|
+
width: number,
|
|
406
|
+
height: number
|
|
407
|
+
): {
|
|
408
|
+
maxLabelWidth: number;
|
|
409
|
+
};
|
|
410
|
+
_draw(): this | undefined;
|
|
411
|
+
setColors(colors: IColorItem[]): this;
|
|
412
|
+
/**
|
|
413
|
+
* 根据值获取颜色
|
|
414
|
+
* @param value
|
|
415
|
+
* @returns
|
|
416
|
+
*/
|
|
417
|
+
getColor(value: number): string;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
interface IOptions {
|
|
421
|
+
disabled?: boolean;
|
|
422
|
+
gapX: number;
|
|
423
|
+
gapY: number;
|
|
424
|
+
text: string[];
|
|
425
|
+
/** 行高(仅支持倍率) */
|
|
426
|
+
fontLineHeight: number;
|
|
427
|
+
fontSize: number;
|
|
428
|
+
fontBackgroundColor: string;
|
|
429
|
+
fontFamily: string;
|
|
430
|
+
fontColor: string;
|
|
431
|
+
/** 旋转角度(0-360) */
|
|
432
|
+
angle: number;
|
|
433
|
+
}
|
|
434
|
+
declare class WaterMark {
|
|
435
|
+
_cfg: IOptions;
|
|
436
|
+
_oWrapper: HTMLDivElement;
|
|
437
|
+
_canvas: HTMLCanvasElement;
|
|
438
|
+
constructor(oWrapper: HTMLDivElement, config: Partial<IOptions>);
|
|
439
|
+
_reload(): HTMLCanvasElement;
|
|
440
|
+
setConfig(config: Partial<IOptions>): void;
|
|
441
|
+
_draw(): void;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
declare const style: (str: string) => void;
|
|
445
|
+
|
|
328
446
|
declare global {
|
|
329
447
|
/**
|
|
330
448
|
* 该声明文件用于全局声明(不用npm安装时拷贝到项目中直接使用)
|
|
331
449
|
*/
|
|
332
450
|
namespace jUtilsBrowser {
|
|
333
451
|
export {
|
|
452
|
+
LinearGradientColorLegend,
|
|
453
|
+
SeamlessRolling,
|
|
334
454
|
TextRainCanvas,
|
|
455
|
+
WaterMark,
|
|
335
456
|
addClass,
|
|
336
457
|
_default as browser,
|
|
458
|
+
copyText,
|
|
337
459
|
createXLSX,
|
|
338
460
|
downloadFileByArrayBuffer,
|
|
461
|
+
downloadFileByBolb,
|
|
339
462
|
downloadFileByUrl,
|
|
340
463
|
fullScreen,
|
|
341
464
|
getCookie,
|
|
@@ -358,6 +481,8 @@ declare global {
|
|
|
358
481
|
replaceClass,
|
|
359
482
|
setCookie,
|
|
360
483
|
setStorage,
|
|
484
|
+
speakText,
|
|
485
|
+
style,
|
|
361
486
|
toggleClass
|
|
362
487
|
};
|
|
363
488
|
}
|
package/dist/umd/index.min.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 浏览器工具库 => jUtilsBrowser
|
|
3
|
-
* @update
|
|
3
|
+
* @update 2025-04-16 19:17:01
|
|
4
4
|
*/
|
|
5
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@bestime/utils_base")):"function"==typeof define&&define.amd?define(["exports","@bestime/utils_base"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).jUtilsBrowser={},e.jUtilsBase)}(this,function(e,a){"use strict";function d(){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 h={add:function(e,t){return i="HI-"+ ++n,r[i]={start:+new Date,current:0,handler:e,interval:t},o||(clearInterval(s),o=!0,s=setInterval(function(){for(var e in r){const t=r[e];t.current=+new Date,t.current-t.start>=t.interval&&(t.start=t.current,r[e].handler())}},17)),i},remove:function(e){delete r[e],0===Object.keys(r).length&&(o=!1,clearInterval(s),s=undefined)}};function c(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 l=void 0,u=decodeURIComponent,f=window,m=document.getElementsByTagName("head")[0];const p={};function g(n,i){const o=[];let r=0;for(let t=0;t<n.length;t++)v(n[t],function(e){o[t]=e,++r===n.length&&i.apply(l,o)})}function v(e,t){var n=e.dependencies&&e.dependencies.length,i=e["with"]&&e["with"].length;p[e.url]||(p[e.url]={count:0,dependencies:!n,"with":!i,complete:!1,create:!1,url:e.url});const o=p[e.url];function r(){return f[e.module]}function s(){o.complete&&o.dependencies&&o["with"]&&(e.module?t(r()):t())}if(o.count++,!o.dependencies&&n)o.dependencies=!0,g(e.dependencies,function(){v(e,t)});else if(!o["with"]&&i)o["with"]=!0,g(e["with"].concat(e),s);else if(o.create)a.variableHasValue(function(){return o.complete},s,300);else{o.create=!0;var n=e.type,i=e.url,c=function(){o.complete=!0,e.interceptor&&e.interceptor(r()),s()},l=e.attribute;if(m){let e;if("js"===n?(e=document.createElement("script")).src=i:((e=document.createElement("link")).setAttribute("rel","stylesheet"),e.href=i),l)for(var u in l)e.setAttribute(u,l[u]);e.onload=e.onerror=c,m.appendChild(e)}}}function w(e,t){(e instanceof Array?g:v)(e,t)}function t(e,t,n){var i;i=t,t=i=a.isString(i)?i:JSON.stringify(i);let o=e+"="+encodeURI(t)+";path=/;";"number"==typeof n&&((i=new Date).setTime(i.getTime()+n),o+="expires="+i.toUTCString()),document.cookie=o}function x(t,e){a.isArray(e)?a.forEach(e,function(e){t.classList.remove(e)}):t.classList.remove(e)}function b(t,e){a.isArray(e)?a.forEach(e,function(e){t.classList.add(e)}):t.classList.add(e)}var S=f.navigator.userAgent,S={isChrome:/Chrome/.test(S),isIPhone:/iPhone/.test(S)};const y=e=>{};class C{text="abcdefghijklmnopqrstuvwxyz";fontSize=14;color=[0,255,0];reverse=!1;isStop=!1;interval=100;width;height;textLineHeight;count;oCanvas;ctx;timer;pointList=[];constructor(e,t){this.draw=this.draw.bind(this);var n=e.offsetWidth,i=e.offsetHeight;e.width=n,e.height=i,this.width=n,this.height=i,t&&(this.text=t.text||this.text,this.fontSize=t.fontSize||this.fontSize,this.color=t.color?function(e){for(var t=[],n=1;n<7;n+=2)t.push(parseInt("0x"+e.slice(n,n+2)));return t}(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.textLineHeight=1.2*this.fontSize,this.count=Math.ceil(this.height/this.textLineHeight),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((e,t)=>{let n;this.reverse?(n=(t-i.currentIndex)/10,n=1-e.speed*n,t<i.currentIndex&&(n=0)):(n=(i.currentIndex-t)/10,n=1-e.speed*n,t>i.currentIndex&&(n=0)),0<n&&(this.ctx.fillStyle=`rgba(${this.color.join(",")}, ${n})`,this.ctx.fillText(e.text,e.x,e.y))}),this.reverse?(i.currentIndex--,i.currentIndex+10<0&&(i.currentIndex=this.count+a.getRandom(0,this.count))):(i.currentIndex++,i.currentIndex-10>i.list.length-1&&(i.currentIndex=-a.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 i=a.getRandom(0,this.text.length-1);n.push({text:this.text[i],x:t,y:Math.floor(e*this.textLineHeight),speed:1})}return{currentIndex:e,list:n}}dispose(){this.isStop=!0,clearTimeout(this.timer)}start(){this.isStop=!1,this.draw()}getPointList(){const i=[];var o=this.fontSize,e=Math.floor(this.width/o);for(let n=0;n<e;n++){let t=0;for(let e=0;e<this.count&&(e?t+=a.getRandom(t+10,this.count):t+=a.getRandom(t,10),!(t>this.count));e++)this.reverse?i.push(this.createColumn(n*o,this.count+t)):i.push(this.createColumn(n*o,-t))}return this.pointList=i}}e.TextRainCanvas=C,e.addClass=b,e.browser=S,e.createXLSX=async function(e){const t=document.createElement("table"),n=a.parseTreeToTableHeader(e.header);var i=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(i){return`<tr>${n.columns.map(function(e){var t=i.$colField?.[e]??1,n=i.$rowSpan?.[e]??1;if(0!==t&&0!==n)return`<td align="center" colSpan="${t}" rowSpan="${n}">${i[e]??""}</td>`}).filter(function(e){return!a.isNull(e)}).join("")}</tr>`}).join("");return t.innerHTML=`<thead>${i}</thead><tbody>${e}</tbody>`,t.setAttribute("border","1"),t},e.downloadFileByArrayBuffer=function(e,t){const n=f.URL;c(e=n.createObjectURL(new Blob([e])),t),n.revokeObjectURL(e),undefined},e.downloadFileByUrl=c,e.fullScreen=function(e,t,n){if(t){t=e;e=n;const i=e||y;t.requestFullscreen?t.requestFullscreen():t.webkitRequestFullScreen?t.webkitRequestFullScreen():t.mozRequestFullScreen?t.mozRequestFullScreen():t.msRequestFullscreen&&t.msRequestFullscreen(),i(!0)}else{e=n;const o=e||y,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))}},e.getCookie=function(e,t){t=t||document.cookie;let i="";return t.replace(new RegExp("(^|;\\s?)"+e+"=(.*?)($|(;\\s?))"),function(e,t,n){i=u(n)}),i},e.getJsFileBaseUrl=function(e){e=e||0;for(var t="/[^/]*",n=document.scripts,i=0;i<e;i++)t+=t;return n[n.length-1].src.replace(new RegExp(t+"$"),"")},e.getRatio=function(){return window.devicePixelRatio||1},e.getRelativePos=function(e){var t=e.getBoundingClientRect();return{x:t.left,y:t.top,height:e.offsetHeight,width:e.offsetWidth,clientWidth:e.clientWidth,clientHeight:e.clientHeight}},e.getStorage=function(e){return e=localStorage.getItem(e),a.defualtFormatter("",e)},e.getWindowSize=d,e.infoContainerPosition=function(e){var t=e.mode||"top-right",n=e.width,i=e.height,o=a.defualtFormatter(10,e.offsetY),r=a.defualtFormatter(10,e.offsetX),s=a.defualtFormatter(10,e.padding);let c=e.x,l=e.y;var e=e.targetSize||d(),u=[s,e.width-n-s],e=[s,e.height-i-s];return"top-right"===t?(c+=r,l=l-i-o,c<u[0]?c=u[0]:c>u[1]&&(s=c-n-2*r,c=u[0]<s?s:u[1]),l<e[0]?(s=l+i+2*o,l=s<e[1]?s:e[0]):l>e[1]&&(l=l-i-2*o)):"bottom-right"===t?(c+=r,(l+=o)>e[1]&&(s=l-i-2*o,l=s<e[0]?e[1]:s),c>u[1]&&(e=c-n-2*r,c=e<u[0]?u[1]:e)):"top-left"===t&&(c=c-n-r,l=l-i-o),{x:c,y:l}},e.libraryFile=w,e.observeDomResize=function(n,i,o,e){let r=[0,0,!1],s=[0,0,!1],c=[0,0,!1],l=[0,0,!1];const t=h.add(u,e=e||500);function u(){if(document.body.contains(n)){let e=!1;var t;o?.includes("position")&&(t=n.getBoundingClientRect(),c[0]=t.left,c[2]=c[0]!==c[1],l[0]=t.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")&&(e=!0)),s[2]&&(s[1]=s[0],o?.includes("height")&&(e=!0)),(l[2]||c[2])&&(l[1]=l[0],c[1]=c[0],o?.includes("position")&&(e=!0)),o&&0!==o.length||(r[2]||s[2]||l[2]||c[2])&&(e=!0),e&&i(n)}else a()}function a(){h.remove(t),r=undefined,s=undefined}return u(),a},e.observeDomScroll=function(n,e){const i=a._KvPair(e),o=a._Number(i.offetY);let r=!1,s=0;function t(){var e,t;r||(t=(e=n.scrollTop)-s,s=e,0!=t?t<0&&i.onTop&&e<=0+o?(r=!0,i.onTop(function(){r=!1})):0<t&&i.onBottom&&e>=n.scrollHeight-n.offsetHeight-o?(r=!0,i.onBottom(function(){r=!1})):r=!1:(r=!1,console.log("未处理")))}return n.addEventListener("scroll",t),{dispose:function(){n.removeEventListener("scroll",t)}}},e.observeMouseWheel=function(e,n,i){function t(e){let t;if(t=e.wheelDelta?0<e.wheelDelta?1:-1:e.detail<0?1:-1,n(t),i)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)}}},e.pdfToImage=async function(e,o,t){const n=await async function(e){const t=e||{index:"//mozilla.github.io/pdf.js/build/pdf.mjs",worker:"//mozilla.github.io/pdf.js/build/pdf.worker.mjs"};return new Promise(function(e){w({type:"js",module:"pdfjsLib",attribute:{type:"module"},url:t.index,interceptor:function(e){e.GlobalWorkerOptions.workerSrc=t.worker}},e)})}(t);return new Promise(function(i){n.getDocument(e).promise.then(function(e){e.getPage(1).then(function(e){var t=e.getViewport({scale:1}),n=o.getContext("2d");o.height=t.height,o.width=t.width,e.render({canvasContext:n,viewport:t}).promise.then(function(){i({width:t.width,height:t.height})})})},function(e){console.error(e),i({width:0,height:0})})})},e.prevent=function(e,t,n){e=e||f.event,n=!1!==n,(t=!1!==t)&&f.event?f.event.cancelBubble=!0:e.stopPropagation(),n&&f.event?f.event.returnValue=!1:e.preventDefault()},e.removeClass=x,e.removeCookie=function(e){t(e,"",-1)},e.removeElement=function(e){e.parentNode&&e.parentNode.removeChild(e)},e.removeStorage=function(e){localStorage.removeItem(e)},e.replaceClass=function(e,t,n){x(e,t),b(e,n)},e.setCookie=t,e.setStorage=function(e,t){localStorage.setItem(e,(e=t,e=a.isString(e)?e:JSON.stringify(e)))},e.toggleClass=function(t,e){a.isArray(e)?a.forEach(e,function(e){t.classList.toggle(e)}):t.classList.toggle(e)}});
|
|
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)}});
|
package/package.json
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bestime/utils_browser",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"main": "./dist/esm/index.
|
|
5
|
-
"module": "./dist/esm/index.
|
|
3
|
+
"version": "1.0.12",
|
|
4
|
+
"main": "./dist/esm/index.mjs",
|
|
5
|
+
"module": "./dist/esm/index.mjs",
|
|
6
6
|
"types": "./dist/esm/index.d.ts",
|
|
7
|
-
"description": "
|
|
7
|
+
"description": "浏览器相关工具",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"files": [
|
|
10
10
|
"dist"
|
|
11
11
|
],
|
|
12
12
|
"scripts": {
|
|
13
|
-
"build": "rollup --config rollup.config.prod.js"
|
|
14
|
-
"serve": "rollup --config rollup.config.dev.js --watch"
|
|
13
|
+
"build": "rollup --config rollup.config.prod.js"
|
|
15
14
|
},
|
|
16
15
|
|
|
17
16
|
"dependencies": {
|
|
18
|
-
"@bestime/utils_base": "1.0.
|
|
17
|
+
"@bestime/utils_base": "^1.0.14"
|
|
19
18
|
},
|
|
20
19
|
"devDependencies": {
|
|
21
20
|
"@babel/core": "7.18.6",
|
package/dist/esm/index.min.mjs
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 浏览器工具库 => jUtilsBrowser
|
|
3
|
-
* @update 2024-10-02 01:28:19
|
|
4
|
-
*/
|
|
5
|
-
import{defualtFormatter,isString,variableHasValue,isArray,forEach,_KvPair,_Number,parseTreeToTableHeader,isNull,getRandom}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],l=[0,0,!1],s=[0,0,!1],a=[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],a[0]=t.top,a[2]=a[0]!==a[1]),r[0]=n.offsetWidth,r[2]=r[0]!==r[1],l[0]=n.offsetHeight,l[2]=l[0]!==l[1],r[2]&&(r[1]=r[0],i?.includes("width")&&(e=!0)),l[2]&&(l[1]=l[0],i?.includes("height")&&(e=!0)),(a[2]||s[2])&&(a[1]=a[0],s[1]=s[0],i?.includes("position")&&(e=!0)),i&&0!==i.length||(r[2]||l[2]||a[2]||s[2])&&(e=!0),e&&o(n)}else u()}function u(){hpInterval.remove(t),r=undefined,l=undefined}return c(),u}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];function downloadFileByArrayBuffer(e,t){const n=$browserGlobal.URL;e=n.createObjectURL(new Blob([e]));downloadFileByUrl(e,t),n.revokeObjectURL(e),undefined}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 l(){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),l)):i.create?variableHasValue(function(){return i.complete},l,300):(i.create=!0,hpCreateFileLoaderElement(e.type,e.url,function(){i.complete=!0,e.interceptor&&e.interceptor(r()),l()},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,l=0;function t(){var e,t;r||(t=(e=n.scrollTop)-l,l=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(e){const t=e||{index:"//mozilla.github.io/pdf.js/build/pdf.mjs",worker:"//mozilla.github.io/pdf.js/build/pdf.worker.mjs"};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){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),l=defualtFormatter(10,e.padding);let s=e.x,a=e.y;var e=e.targetSize||getWindowSize(),c=[l,e.width-n-l],e=[l,e.height-o-l];return"top-right"===t?(s+=r,a=a-o-i,s<c[0]?s=c[0]:s>c[1]&&(l=s-n-2*r,s=c[0]<l?l:c[1]),a<e[0]?(l=a+o+2*i,a=l<e[1]?l:e[0]):a>e[1]&&(a=a-o-2*i)):"bottom-right"===t?(s+=r,(a+=i)>e[1]&&(l=a-o-2*i,a=l<e[0]?e[1]:l),s>c[1]&&(e=s-n-2*r,s=e<c[0]?c[1]:e)):"top-left"===t&&(s=s-n-r,a=a-o-i),{x:s,y:a}}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;textLineHeight;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.textLineHeight=1.2*this.fontSize,this.count=Math.ceil(this.height/this.textLineHeight),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.textLineHeight),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}}export{TextRainCanvas,addClass,browser,createXLSX,downloadFileByArrayBuffer,downloadFileByUrl,fullScreen,getCookie,getJsFileBaseUrl,getRatio,getRelativePos,getStorage,getWindowSize,infoContainerPosition,libraryFile,observeDomResize,observeDomScroll,observeMouseWheel,pdfToImage,prevent,removeClass,removeCookie,removeElement,removeStorage,replaceClass,setCookie,setStorage,toggleClass};
|