@gsc-basic/functions 1.1.2 → 1.2.0

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/LICENSE ADDED
@@ -0,0 +1,6 @@
1
+ Copyright (c) 2026 Lenovo SSG BASD. All rights reserved.
2
+ @license Proprietary
3
+
4
+ This software is the confidential and proprietary property of Lenovo SSG BASD.
5
+ You shall not disclose such Confidential Information and shall use it only in
6
+ accordance with the terms of the license agreement.
package/README.md CHANGED
@@ -1,9 +1,13 @@
1
- # @gsc-basic/functions
2
-
3
- > Functions for Web Dev
4
-
5
- ## 说明
6
-
7
- 常用的前端方法
8
-
9
- 文档参考: [JavaScript functions](https://gsc-open.lenovo.com/zh_CN/gsc_basic/vue/basic-functions.html)
1
+ # @gsc-basic/functions
2
+
3
+ > Functions for Web Dev
4
+
5
+ ## 说明
6
+
7
+ 常用的前端方法
8
+
9
+ 文档参考: [JavaScript functions](https://gsc-open.lenovo.com/zh_CN/gsc_basic/vue/basic-functions.html)
10
+
11
+ ## Author & License
12
+
13
+ This package is maintained by Lenovo SSG BASD. It is distributed under the LicenseRef-Proprietary license; see LICENSE for details.
package/dist/index.cjs CHANGED
@@ -1 +1,14 @@
1
- "use strict";var w=Object.defineProperty,z=Object.defineProperties,V=Object.getOwnPropertyDescriptor,Y=Object.getOwnPropertyDescriptors,B=Object.getOwnPropertyNames,R=Object.getOwnPropertySymbols;var $=Object.prototype.hasOwnProperty,G=Object.prototype.propertyIsEnumerable;var T=(e,t,i)=>t in e?w(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,I=(e,t)=>{for(var i in t||(t={}))$.call(t,i)&&T(e,i,t[i]);if(R)for(var i of R(t))G.call(t,i)&&T(e,i,t[i]);return e},N=(e,t)=>z(e,Y(t));var X=(e,t)=>{for(var i in t)w(e,i,{get:t[i],enumerable:!0})},Z=(e,t,i,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of B(t))!$.call(e,n)&&n!==i&&w(e,n,{get:()=>t[n],enumerable:!(s=V(t,n))||s.enumerable});return e};var q=e=>Z(w({},"__esModule",{value:!0}),e);var f=(e,t,i)=>T(e,typeof t!="symbol"?t+"":t,i);var dt={};X(dt,{IfActivity:()=>S,SolarDay:()=>H.SolarDay,clearWorkerInterval:()=>y.clearInterval,clearWorkerTimeout:()=>y.clearTimeout,getFestival:()=>K,getTerm:()=>x,highlightHtml:()=>W,setFestivalListener:()=>U,setSpecificDayListener:()=>P,setTermListener:()=>_,setWorkerInterval:()=>y.setInterval,setWorkerTimeout:()=>y.setTimeout});module.exports=q(dt);var y=require("worker-timers");var H=require("tyme4ts"),v=require("worker-timers"),L=e=>({year:e.getFullYear(),month:e.getMonth()+1,date:e.getDate(),hour:e.getHours(),minute:e.getMinutes(),second:e.getSeconds(),millisecond:e.getMilliseconds()}),O=(e={})=>{let{advance:t=0,delayed:i=0}=e,s=[];return t>0&&s.push(...Array.from({length:t}).map((n,a)=>{let r=new Date;return r.setDate(r.getDate()-(t-a)),L(r)})),s.push(L(new Date)),i>0&&s.push(...Array.from({length:i}).map((n,a)=>{let r=new Date;return r.setDate(r.getDate()+(a+1)),L(r)})),s},C=e=>O(e).map(({year:i,month:s,date:n})=>H.SolarDay.fromYmd(i,s,n)),J=e=>C(e).map(t=>t.getLunarDay()),x=e=>C(e).map(i=>{var a;return((a=i.getTermDay().dayIndex)!=null?a:0)!==0?void 0:i.getTerm().getName()}),Q=e=>C(e).map(t=>{var i;return(i=t.getFestival())==null?void 0:i.getName()}),tt=e=>J(e).map(t=>{var i;return(i=t.getFestival())==null?void 0:i.getName()}),et=e=>O(e).map(({month:i,date:s})=>{switch(`${i}-${s}`){case"4-1":return"\u611A\u4EBA\u8282";case"2-14":return"\u60C5\u4EBA\u8282";case"12-24":return"\u5E73\u5B89\u591C";case"12-25":return"\u5723\u8BDE\u8282";default:return}}),K=(e={})=>{let t=Q(e),i=tt(e),s=et(e);return Array.from(new Set([...t,...i,...s])).filter(n=>!!n)},A=({type:e,name:t,listener:i},s={})=>{let{interval:n=10*1e3,immediate:a=!0}=s,r=n>0?n:10*1e3,o,d=()=>{let l=[];e==="festival"?l.push(...K(s)):e==="term"?l.push(...x(s)):e==="date"&&l.push(...O(s).map(({month:g,date:m})=>`${g}-${m}`)),t&&l.includes(t)&&(i==null||i(),(0,v.clearInterval)(o))};return o=(0,v.setInterval)(d,r),a&&d(),{timer:o}},U=(e,t,i={})=>{let{timer:s}=A({type:"festival",name:e,listener:t},i);return()=>(0,v.clearInterval)(s)},_=(e,t,i={})=>{let{timer:s}=A({type:"term",name:e,listener:t},i);return()=>(0,v.clearInterval)(s)},P=(e,t,i={})=>{let{timer:s}=A({type:"date",name:e,listener:t},i);return()=>(0,v.clearInterval)(s)};var it=(e,t)=>e instanceof RegExp?new RegExp(e.source,e.flags):new RegExp(e,t),st=(e,t,i="ig")=>{let s=it(t,i);return[...e.matchAll(s)].map(({index:a=0,0:r})=>({index:a,subString:r}))},rt=e=>e.replace(/([A-Z])/g,"-$1").toLowerCase(),nt=(e,t)=>{if(!t)return e;let{tagName:i="mark",bgColor:s,color:n,style:a={},renderHighlightKeyword:r}=t;if(typeof r=="function")return r(e);let o=I({},a);s&&(o.backgroundColor=s),n&&(o.color=n);let l=`style="${Object.entries(o).map(([g,m])=>`${rt(g)}:${m!=null?m:""}`).join(";")}"`;return`<${i} ${l}>${e}</${i}>`},at=(e,t)=>t.reduce((i,s)=>{let{start:n,end:a,option:r}=s,o=e.slice(n,a),d=nt(o,r);return s.subString=d,i+d},""),ot=(e,t)=>{let i=[];return t.forEach(s=>{let n=typeof s=="string"?{keyword:s}:s,{keyword:a,caseSensitive:r=!0}=n;if(!a)return;let o=st(e,a,r?"g":"gi");i.push({keyword:a,indexList:o,option:n})}),i},lt=(e,t)=>{let i=ot(e,t),s=[],n=(r,o)=>{for(let d=0;d<s.length;d++){let l=s[d];if(!l)continue;if(r>l.start&&r<l.end||r+o>l.start&&r+o<l.end||l.start>r&&l.start<r+o||l.end>r&&l.end<r+o||r===l.start&&r+o===l.end)return-1;if(r+o<=l.start)return d}return s.length};i.forEach(({indexList:r,option:o})=>{r.forEach(({index:d,subString:l})=>{let g={start:d,end:d+l.length,option:o},m=n(d,l.length);m!==-1&&s.splice(m,0,g)})});let a=[];return s.forEach((r,o)=>{if(!r)return;let{start:d,end:l}=r,g=s[o+1];o===0&&d>0&&a.push({start:0,end:d,subString:e.slice(0,d)}),a.push(N(I({},r),{subString:e.slice(d,l)})),(g==null?void 0:g.start)!==void 0&&g.start>l&&a.push({start:l,end:g.start,subString:e.slice(l,g.start)}),o===s.length-1&&l<e.length&&a.push({start:l,end:e.length,subString:e.slice(l,e.length)})}),a.length?a:[{start:0,end:e.length,subString:e}]},W=(e,t)=>{let i=lt(e,t);return{highText:at(e,i),highList:i}};var c=require("worker-timers");var p="active",F="idle",j="hidden",b,E,D,h={},u={attach(e,t){h[e]||(h[e]=[]),h[e].push(t)},fire(e,t=[]){h[e]&&h[e].forEach(i=>{i(...t)})},remove(e,t){t||Reflect.deleteProperty(h,e),h[e]&&(h[e]=h[e].filter(i=>t!==i))},dom(e,t,i){if(!D){let s=e;typeof s.addEventListener=="function"?D=(n,a,r)=>{var o;(o=n.addEventListener)==null||o.call(n,a,r,!1)}:typeof s.attachEvent=="function"?D=(n,a,r)=>{var o;(o=n.attachEvent)==null||o.call(n,`on${a}`,r)}:D=(n,a,r)=>{n[`on${a}`]=r}}D(e,t,i)}},M=class{constructor(t,i,s){this.activity=t;this.seconds=i;this.callback=s;f(this,"token");f(this,"stopped",!1);this.start(),this.activity.on("statusChanged",n=>{this.stopped||(n.status===p?this.start():this.pause())})}start(){this.stopped=!1,this.token!==void 0&&(0,c.clearInterval)(this.token),this.token=(0,c.setInterval)(this.callback,this.seconds*1e3)}stop(){this.stopped=!0,this.token!==void 0&&(0,c.clearInterval)(this.token)}resume(){this.start()}pause(){this.stop()}},S=class{constructor(){f(this,"status",p);f(this,"timers",[]);f(this,"idleTime",3e4);f(this,"idleStartedTime",Date.now());f(this,"isLegacyModeOn",!1);if("hidden"in document?(b="hidden",E="visibilitychange"):"mozHidden"in document?(b="mozHidden",E="mozvisibilitychange"):"msHidden"in document?(b="msHidden",E="msvisibilitychange"):"webkitHidden"in document&&(b="webkitHidden",E="webkitvisibilitychange"),!b||!E)this.legacyMode();else{let t=()=>{document[b]?this.blur():this.focus()};t(),u.dom(document,E,t)}this.startIdleTimer(),this.trackIdleStatus()}legacyMode(){this.isLegacyModeOn||(u.dom(window,"blur",()=>this.blur()),u.dom(window,"focus",()=>this.focus()),this.isLegacyModeOn=!0)}startIdleTimer(t){typeof MouseEvent!="undefined"&&t instanceof MouseEvent&&t.movementX===0&&t.movementY===0||(this.timers.forEach(i=>(0,c.clearTimeout)(i)),this.timers.length=0,this.status===F&&this.wakeUp(),this.idleStartedTime=Date.now(),this.timers.push((0,c.setTimeout)(()=>{(this.status===p||this.status===j)&&this.idle()},this.idleTime)))}trackIdleStatus(){let t=i=>this.startIdleTimer(i);u.dom(document,"mousemove",t),u.dom(document,"mousedown",t),u.dom(document,"keyup",t),u.dom(document,"touchstart",t),u.dom(window,"scroll",t),this.focus(t)}on(t,i){return u.attach(t,i),this}off(t,i){return u.remove(t,i),this}setIdleDuration(t){return this.idleTime=t*1e3,this.startIdleTimer(),this}getIdleDuration(){return this.idleTime}getIdleInfo(){let t=Date.now();if(this.status===F)return{isIdle:!0,idleFor:t-this.idleStartedTime,timeLeft:0,timeLeftPer:100};let i=this.idleStartedTime+this.idleTime-t;return{isIdle:!1,idleFor:t-this.idleStartedTime,timeLeft:i,timeLeftPer:Number.parseFloat((100-i*100/this.idleTime).toFixed(2))}}idle(t){return t?this.on("idle",t):(this.status=F,u.fire("idle"),u.fire("statusChanged",[{status:this.status}])),this}blur(t){return t?this.on("blur",t):(this.status=j,u.fire("blur"),u.fire("statusChanged",[{status:this.status}])),this}focus(t){return t?this.on("focus",t):this.status!==p&&(this.status=p,u.fire("focus"),u.fire("wakeUp"),u.fire("statusChanged",[{status:this.status}])),this}wakeUp(t){return t?this.on("wakeUp",t):this.status!==p&&(this.status=p,u.fire("wakeUp"),u.fire("statusChanged",[{status:this.status}])),this}onEvery(t,i){return new M(this,t,i)}now(t){return t!==void 0?this.status===t:this.status===p}};0&&(module.exports={IfActivity,SolarDay,clearWorkerInterval,clearWorkerTimeout,getFestival,getTerm,highlightHtml,setFestivalListener,setSpecificDayListener,setTermListener,setWorkerInterval,setWorkerTimeout});
1
+ /*!
2
+ Copyright (c) 2026 Lenovo SSG BASD. All rights reserved.
3
+ @license Proprietary
4
+
5
+ This software is the confidential and proprietary property of Lenovo SSG BASD.
6
+ You shall not disclose such Confidential Information and shall use it only in
7
+ accordance with the terms of the license agreement.
8
+
9
+ --- Build Info ---
10
+ Version: 1.1.2
11
+ Build Time: 2026/2/11 18:34:04
12
+ Build Commit: 9b4b89872743098216d14081433fa57d7fa73fd3
13
+ */
14
+ "use strict";var J=Object.create;var D=Object.defineProperty,X=Object.defineProperties,Z=Object.getOwnPropertyDescriptor,Q=Object.getOwnPropertyDescriptors,tt=Object.getOwnPropertyNames,$=Object.getOwnPropertySymbols,et=Object.getPrototypeOf,P=Object.prototype.hasOwnProperty,it=Object.prototype.propertyIsEnumerable;var O=(e,t,i)=>t in e?D(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,k=(e,t)=>{for(var i in t||(t={}))P.call(t,i)&&O(e,i,t[i]);if($)for(var i of $(t))it.call(t,i)&&O(e,i,t[i]);return e},U=(e,t)=>X(e,Q(t));var nt=(e,t)=>{for(var i in t)D(e,i,{get:t[i],enumerable:!0})},_=(e,t,i,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of tt(t))!P.call(e,s)&&s!==i&&D(e,s,{get:()=>t[s],enumerable:!(n=Z(t,s))||n.enumerable});return e};var rt=(e,t,i)=>(i=e!=null?J(et(e)):{},_(t||!e||!e.__esModule?D(i,"default",{value:e,enumerable:!0}):i,e)),st=e=>_(D({},"__esModule",{value:!0}),e);var p=(e,t,i)=>O(e,typeof t!="symbol"?t+"":t,i);var j=(e,t,i)=>new Promise((n,s)=>{var o=u=>{try{a(i.next(u))}catch(l){s(l)}},r=u=>{try{a(i.throw(u))}catch(l){s(l)}},a=u=>u.done?n(u.value):Promise.resolve(u.value).then(o,r);a((i=i.apply(e,t)).next())});var yt={};nt(yt,{IfActivity:()=>I,SolarDay:()=>L.SolarDay,clearWorkerInterval:()=>v.clearInterval,clearWorkerTimeout:()=>v.clearTimeout,getFestival:()=>R,getTerm:()=>K,highlightHtml:()=>V,setFestivalListener:()=>W,setSpecificDayListener:()=>B,setTermListener:()=>z,setWorkerInterval:()=>v.setInterval,setWorkerTimeout:()=>v.setTimeout,toImage:()=>q});module.exports=st(yt);var v=require("worker-timers");var L=require("tyme4ts"),b=require("worker-timers"),x=e=>({year:e.getFullYear(),month:e.getMonth()+1,date:e.getDate(),hour:e.getHours(),minute:e.getMinutes(),second:e.getSeconds(),millisecond:e.getMilliseconds()}),C=(e={})=>{let{advance:t=0,delayed:i=0}=e,n=[];return t>0&&n.push(...Array.from({length:t}).map((s,o)=>{let r=new Date;return r.setDate(r.getDate()-(t-o)),x(r)})),n.push(x(new Date)),i>0&&n.push(...Array.from({length:i}).map((s,o)=>{let r=new Date;return r.setDate(r.getDate()+(o+1)),x(r)})),n},M=e=>C(e).map(({year:i,month:n,date:s})=>L.SolarDay.fromYmd(i,n,s)),ot=e=>M(e).map(t=>t.getLunarDay()),K=e=>M(e).map(i=>{var o;return((o=i.getTermDay().dayIndex)!=null?o:0)!==0?void 0:i.getTerm().getName()}),at=e=>M(e).map(t=>{var i;return(i=t.getFestival())==null?void 0:i.getName()}),lt=e=>ot(e).map(t=>{var i;return(i=t.getFestival())==null?void 0:i.getName()}),ut=e=>C(e).map(({month:i,date:n})=>{switch(`${i}-${n}`){case"4-1":return"\u611A\u4EBA\u8282";case"2-14":return"\u60C5\u4EBA\u8282";case"12-24":return"\u5E73\u5B89\u591C";case"12-25":return"\u5723\u8BDE\u8282";default:return}}),R=(e={})=>{let t=at(e),i=lt(e),n=ut(e);return Array.from(new Set([...t,...i,...n])).filter(s=>!!s)},A=({type:e,name:t,listener:i},n={})=>{let{interval:s=10*1e3,immediate:o=!0}=n,r=s>0?s:10*1e3,a,u=()=>{let l=[];e==="festival"?l.push(...R(n)):e==="term"?l.push(...K(n)):e==="date"&&l.push(...C(n).map(({month:g,date:d})=>`${g}-${d}`)),t&&l.includes(t)&&(i==null||i(),(0,b.clearInterval)(a))};return a=(0,b.setInterval)(u,r),o&&u(),{timer:a}},W=(e,t,i={})=>{let{timer:n}=A({type:"festival",name:e,listener:t},i);return()=>(0,b.clearInterval)(n)},z=(e,t,i={})=>{let{timer:n}=A({type:"term",name:e,listener:t},i);return()=>(0,b.clearInterval)(n)},B=(e,t,i={})=>{let{timer:n}=A({type:"date",name:e,listener:t},i);return()=>(0,b.clearInterval)(n)};var dt=(e,t)=>e instanceof RegExp?new RegExp(e.source,e.flags):new RegExp(e,t),gt=(e,t,i="ig")=>{let n=dt(t,i);return[...e.matchAll(n)].map(({index:o=0,0:r})=>({index:o,subString:r}))},mt=e=>e.replace(/([A-Z])/g,"-$1").toLowerCase(),ht=(e,t)=>{if(!t)return e;let{tagName:i="mark",bgColor:n,color:s,style:o={},renderHighlightKeyword:r}=t;if(typeof r=="function")return r(e);let a=k({},o);n&&(a.backgroundColor=n),s&&(a.color=s);let l=`style="${Object.entries(a).map(([g,d])=>`${mt(g)}:${d!=null?d:""}`).join(";")}"`;return`<${i} ${l}>${e}</${i}>`},ct=(e,t)=>t.reduce((i,n)=>{let{start:s,end:o,option:r}=n,a=e.slice(s,o),u=ht(a,r);return n.subString=u,i+u},""),pt=(e,t)=>{let i=[];return t.forEach(n=>{let s=typeof n=="string"?{keyword:n}:n,{keyword:o,caseSensitive:r=!0}=s;if(!o)return;let a=gt(e,o,r?"g":"gi");i.push({keyword:o,indexList:a,option:s})}),i},ft=(e,t)=>{let i=pt(e,t),n=[],s=(r,a)=>{for(let u=0;u<n.length;u++){let l=n[u];if(!l)continue;if(r>l.start&&r<l.end||r+a>l.start&&r+a<l.end||l.start>r&&l.start<r+a||l.end>r&&l.end<r+a||r===l.start&&r+a===l.end)return-1;if(r+a<=l.start)return u}return n.length};i.forEach(({indexList:r,option:a})=>{r.forEach(({index:u,subString:l})=>{let g={start:u,end:u+l.length,option:a},d=s(u,l.length);d!==-1&&n.splice(d,0,g)})});let o=[];return n.forEach((r,a)=>{if(!r)return;let{start:u,end:l}=r,g=n[a+1];a===0&&u>0&&o.push({start:0,end:u,subString:e.slice(0,u)}),o.push(U(k({},r),{subString:e.slice(u,l)})),(g==null?void 0:g.start)!==void 0&&g.start>l&&o.push({start:l,end:g.start,subString:e.slice(l,g.start)}),a===n.length-1&&l<e.length&&o.push({start:l,end:e.length,subString:e.slice(l,e.length)})}),o.length?o:[{start:0,end:e.length,subString:e}]},V=(e,t)=>{let i=ft(e,t);return{highText:ct(e,i),highList:i}};var c=require("worker-timers");var f="active",F="idle",Y="hidden",T,w,H,h={},m={attach(e,t){h[e]||(h[e]=[]),h[e].push(t)},fire(e,t=[]){h[e]&&h[e].forEach(i=>{i(...t)})},remove(e,t){t||Reflect.deleteProperty(h,e),h[e]&&(h[e]=h[e].filter(i=>t!==i))},dom(e,t,i){if(!H){let n=e;typeof n.addEventListener=="function"?H=(s,o,r)=>{var a;(a=s.addEventListener)==null||a.call(s,o,r,!1)}:typeof n.attachEvent=="function"?H=(s,o,r)=>{var a;(a=s.attachEvent)==null||a.call(s,`on${o}`,r)}:H=(s,o,r)=>{s[`on${o}`]=r}}H(e,t,i)}},N=class{constructor(t,i,n){this.activity=t;this.seconds=i;this.callback=n;p(this,"token");p(this,"stopped",!1);this.start(),this.activity.on("statusChanged",s=>{this.stopped||(s.status===f?this.start():this.pause())})}start(){this.stopped=!1,this.token!==void 0&&(0,c.clearInterval)(this.token),this.token=(0,c.setInterval)(this.callback,this.seconds*1e3)}stop(){this.stopped=!0,this.token!==void 0&&(0,c.clearInterval)(this.token)}resume(){this.start()}pause(){this.stop()}},I=class{constructor(){p(this,"status",f);p(this,"timers",[]);p(this,"idleTime",3e4);p(this,"idleStartedTime",Date.now());p(this,"isLegacyModeOn",!1);if("hidden"in document?(T="hidden",w="visibilitychange"):"mozHidden"in document?(T="mozHidden",w="mozvisibilitychange"):"msHidden"in document?(T="msHidden",w="msvisibilitychange"):"webkitHidden"in document&&(T="webkitHidden",w="webkitvisibilitychange"),!T||!w)this.legacyMode();else{let t=()=>{document[T]?this.blur():this.focus()};t(),m.dom(document,w,t)}this.startIdleTimer(),this.trackIdleStatus()}legacyMode(){this.isLegacyModeOn||(m.dom(window,"blur",()=>this.blur()),m.dom(window,"focus",()=>this.focus()),this.isLegacyModeOn=!0)}startIdleTimer(t){typeof MouseEvent!="undefined"&&t instanceof MouseEvent&&t.movementX===0&&t.movementY===0||(this.timers.forEach(i=>(0,c.clearTimeout)(i)),this.timers.length=0,this.status===F&&this.wakeUp(),this.idleStartedTime=Date.now(),this.timers.push((0,c.setTimeout)(()=>{(this.status===f||this.status===Y)&&this.idle()},this.idleTime)))}trackIdleStatus(){let t=i=>this.startIdleTimer(i);m.dom(document,"mousemove",t),m.dom(document,"mousedown",t),m.dom(document,"keyup",t),m.dom(document,"touchstart",t),m.dom(window,"scroll",t),this.focus(t)}on(t,i){return m.attach(t,i),this}off(t,i){return m.remove(t,i),this}setIdleDuration(t){return this.idleTime=t*1e3,this.startIdleTimer(),this}getIdleDuration(){return this.idleTime}getIdleInfo(){let t=Date.now();if(this.status===F)return{isIdle:!0,idleFor:t-this.idleStartedTime,timeLeft:0,timeLeftPer:100};let i=this.idleStartedTime+this.idleTime-t;return{isIdle:!1,idleFor:t-this.idleStartedTime,timeLeft:i,timeLeftPer:Number.parseFloat((100-i*100/this.idleTime).toFixed(2))}}idle(t){return t?this.on("idle",t):(this.status=F,m.fire("idle"),m.fire("statusChanged",[{status:this.status}])),this}blur(t){return t?this.on("blur",t):(this.status=Y,m.fire("blur"),m.fire("statusChanged",[{status:this.status}])),this}focus(t){return t?this.on("focus",t):this.status!==f&&(this.status=f,m.fire("focus"),m.fire("wakeUp"),m.fire("statusChanged",[{status:this.status}])),this}wakeUp(t){return t?this.on("wakeUp",t):this.status!==f&&(this.status=f,m.fire("wakeUp"),m.fire("statusChanged",[{status:this.status}])),this}onEvery(t,i){return new N(this,t,i)}now(t){return t!==void 0?this.status===t:this.status===f}};var y=rt(require("html-to-image"),1);function q(e){return j(this,null,function*(){let{input:t,type:i="png",quality:n=1,width:s,height:o,backgroundColor:r,pixelRatio:a,style:u,filter:l}=e,g=null,d=null;if(typeof t=="string"){if(!/<[^>]+>/.test(t.trim()))try{g=document.querySelector(t)}catch(G){throw new Error(`htmlToImage: invalid selector, ${String(G)}`)}if(g||(d=document.createElement("div"),d.style.position="fixed",d.style.left="-9999px",d.style.top="-9999px",d.innerHTML=t,document.body.appendChild(d),g=d.firstElementChild),!g)throw d&&d.parentNode&&d.parentNode.removeChild(d),new Error("htmlToImage: unable to resolve input element from selector or html string")}else g=t;let E={backgroundColor:r,style:u,filter:l,pixelRatio:a};typeof s=="number"&&(E.canvasWidth=s),typeof o=="number"&&(E.canvasHeight=o);try{if(i==="png")return yield y.toPng(g,E);if(i==="jpeg")return yield y.toJpeg(g,Object.assign({},E,{quality:n}));if(i==="svg")return yield y.toSvg(g,E);if(i==="blob")return yield y.toBlob(g,E);throw new Error("htmlToImage: unsupported output type")}finally{d&&d.parentNode&&d.parentNode.removeChild(d)}})}0&&(module.exports={IfActivity,SolarDay,clearWorkerInterval,clearWorkerTimeout,getFestival,getTerm,highlightHtml,setFestivalListener,setSpecificDayListener,setTermListener,setWorkerInterval,setWorkerTimeout,toImage});
package/dist/index.d.cts CHANGED
@@ -84,4 +84,23 @@ declare class IfActivity {
84
84
  now(check?: ActivityStatus): boolean;
85
85
  }
86
86
 
87
- export { type DayOptions, type HighlightHtmlResult, type HighlightKeyword, type HighlightKeywordOption, IfActivity, getFestival, getTerm, highlightHtml, setFestivalListener, setSpecificDayListener, setTermListener };
87
+ type OutputType = 'png' | 'jpeg' | 'svg' | 'blob';
88
+ interface Options {
89
+ input: HTMLElement | string;
90
+ type?: OutputType;
91
+ quality?: number;
92
+ width?: number;
93
+ height?: number;
94
+ backgroundColor?: string;
95
+ pixelRatio?: number;
96
+ style?: Record<string, string>;
97
+ filter?: (node: Element) => boolean;
98
+ }
99
+ /**
100
+ * 简化封装:把 `html-to-image` 常用用法合并为一个易用的函数。
101
+ * - `input` 支持 HTMLElement、CSS selector 或 HTML 字符串
102
+ * - 返回值为 dataURL (png/jpeg/svg) 或 Blob
103
+ */
104
+ declare function toImage(opts: Options): Promise<string | Blob | null>;
105
+
106
+ export { type DayOptions, type HighlightHtmlResult, type HighlightKeyword, type HighlightKeywordOption, IfActivity, type Options as ToImageOptions, type OutputType as ToImageOutputType, getFestival, getTerm, highlightHtml, setFestivalListener, setSpecificDayListener, setTermListener, toImage };
package/dist/index.d.ts CHANGED
@@ -84,4 +84,23 @@ declare class IfActivity {
84
84
  now(check?: ActivityStatus): boolean;
85
85
  }
86
86
 
87
- export { type DayOptions, type HighlightHtmlResult, type HighlightKeyword, type HighlightKeywordOption, IfActivity, getFestival, getTerm, highlightHtml, setFestivalListener, setSpecificDayListener, setTermListener };
87
+ type OutputType = 'png' | 'jpeg' | 'svg' | 'blob';
88
+ interface Options {
89
+ input: HTMLElement | string;
90
+ type?: OutputType;
91
+ quality?: number;
92
+ width?: number;
93
+ height?: number;
94
+ backgroundColor?: string;
95
+ pixelRatio?: number;
96
+ style?: Record<string, string>;
97
+ filter?: (node: Element) => boolean;
98
+ }
99
+ /**
100
+ * 简化封装:把 `html-to-image` 常用用法合并为一个易用的函数。
101
+ * - `input` 支持 HTMLElement、CSS selector 或 HTML 字符串
102
+ * - 返回值为 dataURL (png/jpeg/svg) 或 Blob
103
+ */
104
+ declare function toImage(opts: Options): Promise<string | Blob | null>;
105
+
106
+ export { type DayOptions, type HighlightHtmlResult, type HighlightKeyword, type HighlightKeywordOption, IfActivity, type Options as ToImageOptions, type OutputType as ToImageOutputType, getFestival, getTerm, highlightHtml, setFestivalListener, setSpecificDayListener, setTermListener, toImage };
package/dist/index.js CHANGED
@@ -1 +1,14 @@
1
- var N=Object.defineProperty,U=Object.defineProperties;var _=Object.getOwnPropertyDescriptors;var x=Object.getOwnPropertySymbols;var P=Object.prototype.hasOwnProperty,W=Object.prototype.propertyIsEnumerable;var D=(e,t,i)=>t in e?N(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,S=(e,t)=>{for(var i in t||(t={}))P.call(t,i)&&D(e,i,t[i]);if(x)for(var i of x(t))W.call(t,i)&&D(e,i,t[i]);return e},K=(e,t)=>U(e,_(t));var m=(e,t,i)=>D(e,typeof t!="symbol"?t+"":t,i);import{clearInterval as wt,clearTimeout as Ht,setInterval as Tt,setTimeout as It}from"worker-timers";import{SolarDay as A}from"tyme4ts";import{clearInterval as b,setInterval as j}from"worker-timers";var w=e=>({year:e.getFullYear(),month:e.getMonth()+1,date:e.getDate(),hour:e.getHours(),minute:e.getMinutes(),second:e.getSeconds(),millisecond:e.getMilliseconds()}),I=(e={})=>{let{advance:t=0,delayed:i=0}=e,s=[];return t>0&&s.push(...Array.from({length:t}).map((n,a)=>{let r=new Date;return r.setDate(r.getDate()-(t-a)),w(r)})),s.push(w(new Date)),i>0&&s.push(...Array.from({length:i}).map((n,a)=>{let r=new Date;return r.setDate(r.getDate()+(a+1)),w(r)})),s},L=e=>I(e).map(({year:i,month:s,date:n})=>A.fromYmd(i,s,n)),z=e=>L(e).map(t=>t.getLunarDay()),F=e=>L(e).map(i=>{var a;return((a=i.getTermDay().dayIndex)!=null?a:0)!==0?void 0:i.getTerm().getName()}),V=e=>L(e).map(t=>{var i;return(i=t.getFestival())==null?void 0:i.getName()}),Y=e=>z(e).map(t=>{var i;return(i=t.getFestival())==null?void 0:i.getName()}),B=e=>I(e).map(({month:i,date:s})=>{switch(`${i}-${s}`){case"4-1":return"\u611A\u4EBA\u8282";case"2-14":return"\u60C5\u4EBA\u8282";case"12-24":return"\u5E73\u5B89\u591C";case"12-25":return"\u5723\u8BDE\u8282";default:return}}),M=(e={})=>{let t=V(e),i=Y(e),s=B(e);return Array.from(new Set([...t,...i,...s])).filter(n=>!!n)},k=({type:e,name:t,listener:i},s={})=>{let{interval:n=10*1e3,immediate:a=!0}=s,r=n>0?n:10*1e3,o,d=()=>{let l=[];e==="festival"?l.push(...M(s)):e==="term"?l.push(...F(s)):e==="date"&&l.push(...I(s).map(({month:g,date:c})=>`${g}-${c}`)),t&&l.includes(t)&&(i==null||i(),b(o))};return o=j(d,r),a&&d(),{timer:o}},G=(e,t,i={})=>{let{timer:s}=k({type:"festival",name:e,listener:t},i);return()=>b(s)},X=(e,t,i={})=>{let{timer:s}=k({type:"term",name:e,listener:t},i);return()=>b(s)},Z=(e,t,i={})=>{let{timer:s}=k({type:"date",name:e,listener:t},i);return()=>b(s)};var q=(e,t)=>e instanceof RegExp?new RegExp(e.source,e.flags):new RegExp(e,t),J=(e,t,i="ig")=>{let s=q(t,i);return[...e.matchAll(s)].map(({index:a=0,0:r})=>({index:a,subString:r}))},Q=e=>e.replace(/([A-Z])/g,"-$1").toLowerCase(),tt=(e,t)=>{if(!t)return e;let{tagName:i="mark",bgColor:s,color:n,style:a={},renderHighlightKeyword:r}=t;if(typeof r=="function")return r(e);let o=S({},a);s&&(o.backgroundColor=s),n&&(o.color=n);let l=`style="${Object.entries(o).map(([g,c])=>`${Q(g)}:${c!=null?c:""}`).join(";")}"`;return`<${i} ${l}>${e}</${i}>`},et=(e,t)=>t.reduce((i,s)=>{let{start:n,end:a,option:r}=s,o=e.slice(n,a),d=tt(o,r);return s.subString=d,i+d},""),it=(e,t)=>{let i=[];return t.forEach(s=>{let n=typeof s=="string"?{keyword:s}:s,{keyword:a,caseSensitive:r=!0}=n;if(!a)return;let o=J(e,a,r?"g":"gi");i.push({keyword:a,indexList:o,option:n})}),i},st=(e,t)=>{let i=it(e,t),s=[],n=(r,o)=>{for(let d=0;d<s.length;d++){let l=s[d];if(!l)continue;if(r>l.start&&r<l.end||r+o>l.start&&r+o<l.end||l.start>r&&l.start<r+o||l.end>r&&l.end<r+o||r===l.start&&r+o===l.end)return-1;if(r+o<=l.start)return d}return s.length};i.forEach(({indexList:r,option:o})=>{r.forEach(({index:d,subString:l})=>{let g={start:d,end:d+l.length,option:o},c=n(d,l.length);c!==-1&&s.splice(c,0,g)})});let a=[];return s.forEach((r,o)=>{if(!r)return;let{start:d,end:l}=r,g=s[o+1];o===0&&d>0&&a.push({start:0,end:d,subString:e.slice(0,d)}),a.push(K(S({},r),{subString:e.slice(d,l)})),(g==null?void 0:g.start)!==void 0&&g.start>l&&a.push({start:l,end:g.start,subString:e.slice(l,g.start)}),o===s.length-1&&l<e.length&&a.push({start:l,end:e.length,subString:e.slice(l,e.length)})}),a.length?a:[{start:0,end:e.length,subString:e}]},rt=(e,t)=>{let i=st(e,t);return{highText:et(e,i),highList:i}};import{clearInterval as R,clearTimeout as nt,setInterval as at,setTimeout as ot}from"worker-timers";var f="active",O="idle",$="hidden",p,y,v,h={},u={attach(e,t){h[e]||(h[e]=[]),h[e].push(t)},fire(e,t=[]){h[e]&&h[e].forEach(i=>{i(...t)})},remove(e,t){t||Reflect.deleteProperty(h,e),h[e]&&(h[e]=h[e].filter(i=>t!==i))},dom(e,t,i){if(!v){let s=e;typeof s.addEventListener=="function"?v=(n,a,r)=>{var o;(o=n.addEventListener)==null||o.call(n,a,r,!1)}:typeof s.attachEvent=="function"?v=(n,a,r)=>{var o;(o=n.attachEvent)==null||o.call(n,`on${a}`,r)}:v=(n,a,r)=>{n[`on${a}`]=r}}v(e,t,i)}},C=class{constructor(t,i,s){this.activity=t;this.seconds=i;this.callback=s;m(this,"token");m(this,"stopped",!1);this.start(),this.activity.on("statusChanged",n=>{this.stopped||(n.status===f?this.start():this.pause())})}start(){this.stopped=!1,this.token!==void 0&&R(this.token),this.token=at(this.callback,this.seconds*1e3)}stop(){this.stopped=!0,this.token!==void 0&&R(this.token)}resume(){this.start()}pause(){this.stop()}},E=class{constructor(){m(this,"status",f);m(this,"timers",[]);m(this,"idleTime",3e4);m(this,"idleStartedTime",Date.now());m(this,"isLegacyModeOn",!1);if("hidden"in document?(p="hidden",y="visibilitychange"):"mozHidden"in document?(p="mozHidden",y="mozvisibilitychange"):"msHidden"in document?(p="msHidden",y="msvisibilitychange"):"webkitHidden"in document&&(p="webkitHidden",y="webkitvisibilitychange"),!p||!y)this.legacyMode();else{let t=()=>{document[p]?this.blur():this.focus()};t(),u.dom(document,y,t)}this.startIdleTimer(),this.trackIdleStatus()}legacyMode(){this.isLegacyModeOn||(u.dom(window,"blur",()=>this.blur()),u.dom(window,"focus",()=>this.focus()),this.isLegacyModeOn=!0)}startIdleTimer(t){typeof MouseEvent!="undefined"&&t instanceof MouseEvent&&t.movementX===0&&t.movementY===0||(this.timers.forEach(i=>nt(i)),this.timers.length=0,this.status===O&&this.wakeUp(),this.idleStartedTime=Date.now(),this.timers.push(ot(()=>{(this.status===f||this.status===$)&&this.idle()},this.idleTime)))}trackIdleStatus(){let t=i=>this.startIdleTimer(i);u.dom(document,"mousemove",t),u.dom(document,"mousedown",t),u.dom(document,"keyup",t),u.dom(document,"touchstart",t),u.dom(window,"scroll",t),this.focus(t)}on(t,i){return u.attach(t,i),this}off(t,i){return u.remove(t,i),this}setIdleDuration(t){return this.idleTime=t*1e3,this.startIdleTimer(),this}getIdleDuration(){return this.idleTime}getIdleInfo(){let t=Date.now();if(this.status===O)return{isIdle:!0,idleFor:t-this.idleStartedTime,timeLeft:0,timeLeftPer:100};let i=this.idleStartedTime+this.idleTime-t;return{isIdle:!1,idleFor:t-this.idleStartedTime,timeLeft:i,timeLeftPer:Number.parseFloat((100-i*100/this.idleTime).toFixed(2))}}idle(t){return t?this.on("idle",t):(this.status=O,u.fire("idle"),u.fire("statusChanged",[{status:this.status}])),this}blur(t){return t?this.on("blur",t):(this.status=$,u.fire("blur"),u.fire("statusChanged",[{status:this.status}])),this}focus(t){return t?this.on("focus",t):this.status!==f&&(this.status=f,u.fire("focus"),u.fire("wakeUp"),u.fire("statusChanged",[{status:this.status}])),this}wakeUp(t){return t?this.on("wakeUp",t):this.status!==f&&(this.status=f,u.fire("wakeUp"),u.fire("statusChanged",[{status:this.status}])),this}onEvery(t,i){return new C(this,t,i)}now(t){return t!==void 0?this.status===t:this.status===f}};export{E as IfActivity,A as SolarDay,wt as clearWorkerInterval,Ht as clearWorkerTimeout,M as getFestival,F as getTerm,rt as highlightHtml,G as setFestivalListener,Z as setSpecificDayListener,X as setTermListener,Tt as setWorkerInterval,It as setWorkerTimeout};
1
+ /*!
2
+ Copyright (c) 2026 Lenovo SSG BASD. All rights reserved.
3
+ @license Proprietary
4
+
5
+ This software is the confidential and proprietary property of Lenovo SSG BASD.
6
+ You shall not disclose such Confidential Information and shall use it only in
7
+ accordance with the terms of the license agreement.
8
+
9
+ --- Build Info ---
10
+ Version: 1.1.2
11
+ Build Time: 2026/2/11 18:34:04
12
+ Build Commit: 9b4b89872743098216d14081433fa57d7fa73fd3
13
+ */
14
+ var j=Object.defineProperty,W=Object.defineProperties;var z=Object.getOwnPropertyDescriptors;var K=Object.getOwnPropertySymbols;var B=Object.prototype.hasOwnProperty,V=Object.prototype.propertyIsEnumerable;var I=(e,t,i)=>t in e?j(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,S=(e,t)=>{for(var i in t||(t={}))B.call(t,i)&&I(e,i,t[i]);if(K)for(var i of K(t))V.call(t,i)&&I(e,i,t[i]);return e},R=(e,t)=>W(e,z(t));var c=(e,t,i)=>I(e,typeof t!="symbol"?t+"":t,i);var A=(e,t,i)=>new Promise((n,s)=>{var o=u=>{try{a(i.next(u))}catch(l){s(l)}},r=u=>{try{a(i.throw(u))}catch(l){s(l)}},a=u=>u.done?n(u.value):Promise.resolve(u.value).then(o,r);a((i=i.apply(e,t)).next())});import{clearInterval as Mt,clearTimeout as Kt,setInterval as Rt,setTimeout as At}from"worker-timers";import{SolarDay as F}from"tyme4ts";import{clearInterval as D,setInterval as Y}from"worker-timers";var L=e=>({year:e.getFullYear(),month:e.getMonth()+1,date:e.getDate(),hour:e.getHours(),minute:e.getMinutes(),second:e.getSeconds(),millisecond:e.getMilliseconds()}),O=(e={})=>{let{advance:t=0,delayed:i=0}=e,n=[];return t>0&&n.push(...Array.from({length:t}).map((s,o)=>{let r=new Date;return r.setDate(r.getDate()-(t-o)),L(r)})),n.push(L(new Date)),i>0&&n.push(...Array.from({length:i}).map((s,o)=>{let r=new Date;return r.setDate(r.getDate()+(o+1)),L(r)})),n},k=e=>O(e).map(({year:i,month:n,date:s})=>F.fromYmd(i,n,s)),q=e=>k(e).map(t=>t.getLunarDay()),N=e=>k(e).map(i=>{var o;return((o=i.getTermDay().dayIndex)!=null?o:0)!==0?void 0:i.getTerm().getName()}),G=e=>k(e).map(t=>{var i;return(i=t.getFestival())==null?void 0:i.getName()}),J=e=>q(e).map(t=>{var i;return(i=t.getFestival())==null?void 0:i.getName()}),X=e=>O(e).map(({month:i,date:n})=>{switch(`${i}-${n}`){case"4-1":return"\u611A\u4EBA\u8282";case"2-14":return"\u60C5\u4EBA\u8282";case"12-24":return"\u5E73\u5B89\u591C";case"12-25":return"\u5723\u8BDE\u8282";default:return}}),$=(e={})=>{let t=G(e),i=J(e),n=X(e);return Array.from(new Set([...t,...i,...n])).filter(s=>!!s)},x=({type:e,name:t,listener:i},n={})=>{let{interval:s=10*1e3,immediate:o=!0}=n,r=s>0?s:10*1e3,a,u=()=>{let l=[];e==="festival"?l.push(...$(n)):e==="term"?l.push(...N(n)):e==="date"&&l.push(...O(n).map(({month:g,date:d})=>`${g}-${d}`)),t&&l.includes(t)&&(i==null||i(),D(a))};return a=Y(u,r),o&&u(),{timer:a}},Z=(e,t,i={})=>{let{timer:n}=x({type:"festival",name:e,listener:t},i);return()=>D(n)},Q=(e,t,i={})=>{let{timer:n}=x({type:"term",name:e,listener:t},i);return()=>D(n)},tt=(e,t,i={})=>{let{timer:n}=x({type:"date",name:e,listener:t},i);return()=>D(n)};var et=(e,t)=>e instanceof RegExp?new RegExp(e.source,e.flags):new RegExp(e,t),it=(e,t,i="ig")=>{let n=et(t,i);return[...e.matchAll(n)].map(({index:o=0,0:r})=>({index:o,subString:r}))},nt=e=>e.replace(/([A-Z])/g,"-$1").toLowerCase(),rt=(e,t)=>{if(!t)return e;let{tagName:i="mark",bgColor:n,color:s,style:o={},renderHighlightKeyword:r}=t;if(typeof r=="function")return r(e);let a=S({},o);n&&(a.backgroundColor=n),s&&(a.color=s);let l=`style="${Object.entries(a).map(([g,d])=>`${nt(g)}:${d!=null?d:""}`).join(";")}"`;return`<${i} ${l}>${e}</${i}>`},st=(e,t)=>t.reduce((i,n)=>{let{start:s,end:o,option:r}=n,a=e.slice(s,o),u=rt(a,r);return n.subString=u,i+u},""),ot=(e,t)=>{let i=[];return t.forEach(n=>{let s=typeof n=="string"?{keyword:n}:n,{keyword:o,caseSensitive:r=!0}=s;if(!o)return;let a=it(e,o,r?"g":"gi");i.push({keyword:o,indexList:a,option:s})}),i},at=(e,t)=>{let i=ot(e,t),n=[],s=(r,a)=>{for(let u=0;u<n.length;u++){let l=n[u];if(!l)continue;if(r>l.start&&r<l.end||r+a>l.start&&r+a<l.end||l.start>r&&l.start<r+a||l.end>r&&l.end<r+a||r===l.start&&r+a===l.end)return-1;if(r+a<=l.start)return u}return n.length};i.forEach(({indexList:r,option:a})=>{r.forEach(({index:u,subString:l})=>{let g={start:u,end:u+l.length,option:a},d=s(u,l.length);d!==-1&&n.splice(d,0,g)})});let o=[];return n.forEach((r,a)=>{if(!r)return;let{start:u,end:l}=r,g=n[a+1];a===0&&u>0&&o.push({start:0,end:u,subString:e.slice(0,u)}),o.push(R(S({},r),{subString:e.slice(u,l)})),(g==null?void 0:g.start)!==void 0&&g.start>l&&o.push({start:l,end:g.start,subString:e.slice(l,g.start)}),a===n.length-1&&l<e.length&&o.push({start:l,end:e.length,subString:e.slice(l,e.length)})}),o.length?o:[{start:0,end:e.length,subString:e}]},lt=(e,t)=>{let i=at(e,t);return{highText:st(e,i),highList:i}};import{clearInterval as P,clearTimeout as ut,setInterval as dt,setTimeout as gt}from"worker-timers";var p="active",C="idle",U="hidden",v,b,E,h={},m={attach(e,t){h[e]||(h[e]=[]),h[e].push(t)},fire(e,t=[]){h[e]&&h[e].forEach(i=>{i(...t)})},remove(e,t){t||Reflect.deleteProperty(h,e),h[e]&&(h[e]=h[e].filter(i=>t!==i))},dom(e,t,i){if(!E){let n=e;typeof n.addEventListener=="function"?E=(s,o,r)=>{var a;(a=s.addEventListener)==null||a.call(s,o,r,!1)}:typeof n.attachEvent=="function"?E=(s,o,r)=>{var a;(a=s.attachEvent)==null||a.call(s,`on${o}`,r)}:E=(s,o,r)=>{s[`on${o}`]=r}}E(e,t,i)}},M=class{constructor(t,i,n){this.activity=t;this.seconds=i;this.callback=n;c(this,"token");c(this,"stopped",!1);this.start(),this.activity.on("statusChanged",s=>{this.stopped||(s.status===p?this.start():this.pause())})}start(){this.stopped=!1,this.token!==void 0&&P(this.token),this.token=dt(this.callback,this.seconds*1e3)}stop(){this.stopped=!0,this.token!==void 0&&P(this.token)}resume(){this.start()}pause(){this.stop()}},H=class{constructor(){c(this,"status",p);c(this,"timers",[]);c(this,"idleTime",3e4);c(this,"idleStartedTime",Date.now());c(this,"isLegacyModeOn",!1);if("hidden"in document?(v="hidden",b="visibilitychange"):"mozHidden"in document?(v="mozHidden",b="mozvisibilitychange"):"msHidden"in document?(v="msHidden",b="msvisibilitychange"):"webkitHidden"in document&&(v="webkitHidden",b="webkitvisibilitychange"),!v||!b)this.legacyMode();else{let t=()=>{document[v]?this.blur():this.focus()};t(),m.dom(document,b,t)}this.startIdleTimer(),this.trackIdleStatus()}legacyMode(){this.isLegacyModeOn||(m.dom(window,"blur",()=>this.blur()),m.dom(window,"focus",()=>this.focus()),this.isLegacyModeOn=!0)}startIdleTimer(t){typeof MouseEvent!="undefined"&&t instanceof MouseEvent&&t.movementX===0&&t.movementY===0||(this.timers.forEach(i=>ut(i)),this.timers.length=0,this.status===C&&this.wakeUp(),this.idleStartedTime=Date.now(),this.timers.push(gt(()=>{(this.status===p||this.status===U)&&this.idle()},this.idleTime)))}trackIdleStatus(){let t=i=>this.startIdleTimer(i);m.dom(document,"mousemove",t),m.dom(document,"mousedown",t),m.dom(document,"keyup",t),m.dom(document,"touchstart",t),m.dom(window,"scroll",t),this.focus(t)}on(t,i){return m.attach(t,i),this}off(t,i){return m.remove(t,i),this}setIdleDuration(t){return this.idleTime=t*1e3,this.startIdleTimer(),this}getIdleDuration(){return this.idleTime}getIdleInfo(){let t=Date.now();if(this.status===C)return{isIdle:!0,idleFor:t-this.idleStartedTime,timeLeft:0,timeLeftPer:100};let i=this.idleStartedTime+this.idleTime-t;return{isIdle:!1,idleFor:t-this.idleStartedTime,timeLeft:i,timeLeftPer:Number.parseFloat((100-i*100/this.idleTime).toFixed(2))}}idle(t){return t?this.on("idle",t):(this.status=C,m.fire("idle"),m.fire("statusChanged",[{status:this.status}])),this}blur(t){return t?this.on("blur",t):(this.status=U,m.fire("blur"),m.fire("statusChanged",[{status:this.status}])),this}focus(t){return t?this.on("focus",t):this.status!==p&&(this.status=p,m.fire("focus"),m.fire("wakeUp"),m.fire("statusChanged",[{status:this.status}])),this}wakeUp(t){return t?this.on("wakeUp",t):this.status!==p&&(this.status=p,m.fire("wakeUp"),m.fire("statusChanged",[{status:this.status}])),this}onEvery(t,i){return new M(this,t,i)}now(t){return t!==void 0?this.status===t:this.status===p}};import*as f from"html-to-image";function mt(e){return A(this,null,function*(){let{input:t,type:i="png",quality:n=1,width:s,height:o,backgroundColor:r,pixelRatio:a,style:u,filter:l}=e,g=null,d=null;if(typeof t=="string"){if(!/<[^>]+>/.test(t.trim()))try{g=document.querySelector(t)}catch(_){throw new Error(`htmlToImage: invalid selector, ${String(_)}`)}if(g||(d=document.createElement("div"),d.style.position="fixed",d.style.left="-9999px",d.style.top="-9999px",d.innerHTML=t,document.body.appendChild(d),g=d.firstElementChild),!g)throw d&&d.parentNode&&d.parentNode.removeChild(d),new Error("htmlToImage: unable to resolve input element from selector or html string")}else g=t;let y={backgroundColor:r,style:u,filter:l,pixelRatio:a};typeof s=="number"&&(y.canvasWidth=s),typeof o=="number"&&(y.canvasHeight=o);try{if(i==="png")return yield f.toPng(g,y);if(i==="jpeg")return yield f.toJpeg(g,Object.assign({},y,{quality:n}));if(i==="svg")return yield f.toSvg(g,y);if(i==="blob")return yield f.toBlob(g,y);throw new Error("htmlToImage: unsupported output type")}finally{d&&d.parentNode&&d.parentNode.removeChild(d)}})}export{H as IfActivity,F as SolarDay,Mt as clearWorkerInterval,Kt as clearWorkerTimeout,$ as getFestival,N as getTerm,lt as highlightHtml,Z as setFestivalListener,tt as setSpecificDayListener,Q as setTermListener,Rt as setWorkerInterval,At as setWorkerTimeout,mt as toImage};
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@gsc-basic/functions",
3
3
  "type": "module",
4
- "version": "1.1.2",
4
+ "version": "1.2.0",
5
5
  "description": "Functions for Web Dev",
6
- "author": "wangll47 <wangll47@lenovo.com>",
7
- "license": "UNLICENSED",
6
+ "author": "Lenovo SSG BASD <-GSC_Scaffolding_Support@lenovo.com>",
7
+ "license": "LicenseRef-Proprietary",
8
8
  "repository": {
9
9
  "type": "git",
10
10
  "url": "https://gitlab.xpaas.lenovo.com/tsd-basic/gsc-frontend-config.git"
@@ -30,8 +30,9 @@
30
30
  "./dist"
31
31
  ],
32
32
  "dependencies": {
33
- "tyme4ts": "^1.4.1",
34
- "worker-timers": "^8.0.29"
33
+ "html-to-image": "^1.11.13",
34
+ "tyme4ts": "^1.4.2",
35
+ "worker-timers": "^8.0.30"
35
36
  },
36
37
  "scripts": {
37
38
  "build": "tsup",