zero-hour 1.3.2 → 2.0.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/README.md +102 -106
- package/dist/index.cjs +607 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +75 -0
- package/dist/index.d.ts +69 -66
- package/dist/index.js +604 -0
- package/dist/index.js.map +1 -0
- package/dist/zero-hour.css +1 -1
- package/package.json +52 -25
- package/dist/index.cjs.js +0 -75
- package/dist/index.es.js +0 -464
- package/dist/index.umd.js +0 -75
package/dist/zero-hour.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
:host{width:100%;display:block;overflow:hidden;container-type:inline-size}.zh{box-sizing:border-box;align-items:stretch;gap:0;display:flex;position:relative}.zh__group{flex:1 1 0;grid-template-rows:auto;grid-template-columns:1fr 1fr;gap:0;width:100%;min-width:0;display:grid}.zh__sep{flex:0 0 var(--zh-sep-width,4%);width:var(--zh-sep-width,4%);background-image:var(--zh-sep-url);background-position:50%;background-repeat:no-repeat;background-size:contain}.zh__digit{aspect-ratio:var(--zh-digit-aspect,9/12);width:100%;position:relative;overflow:hidden}.zh__digit-track{flex-direction:column;width:100%;height:100%;display:flex;transform:translateY(0)}.zh--mode-scroll .zh__digit-track{transition:transform var(--zh-scroll-duration,.375s)var(--zh-scroll-timing,cubic-bezier(.445
|
|
1
|
+
:host{width:100%;display:block;overflow:hidden;container-type:inline-size}.zh{box-sizing:border-box;align-items:stretch;gap:0;display:flex;position:relative}.zh__group{flex:1 1 0;grid-template-rows:auto;grid-template-columns:1fr 1fr;gap:0;width:100%;min-width:0;display:grid}.zh__sep{flex:0 0 var(--zh-sep-width,4%);width:var(--zh-sep-width,4%);background-image:var(--zh-sep-url);background-position:50%;background-repeat:no-repeat;background-size:contain}.zh__digit{aspect-ratio:var(--zh-digit-aspect,9 / 12);width:100%;position:relative;overflow:hidden}.zh__digit-track{flex-direction:column;width:100%;height:100%;display:flex;transform:translateY(0)}.zh--mode-scroll .zh__digit-track{transition:transform var(--zh-scroll-duration,.375s) var(--zh-scroll-timing,cubic-bezier(.445, .05, .55, .95))}.zh__digit-face{background-image:var(--zh-digits-url);background-repeat:no-repeat;background-size:calc(var(--zh-digits-frames,10) * 100%) 100%;background-position:calc(var(--zh-sheet-index,0) * 100% / (var(--zh-digits-frames,10) - 1)) 0;flex:0 0 100%;width:100%;height:100%}.zh__a11y{clip:rect(0 0 0 0);white-space:nowrap;clip-path:inset(50%);width:1px;height:1px;position:absolute;overflow:hidden}
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zero-hour",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Tiny countdown Web Component. Registers <countdown-timer> that renders a configurable DD:HH:MM:SS countdown to a target date/time (optional UTC offset) and fires a done event at zero.",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"author": "ux-ui.pro",
|
|
6
7
|
"license": "MIT",
|
|
7
8
|
"repository": {
|
|
@@ -12,41 +13,67 @@
|
|
|
12
13
|
"url": "https://github.com/ux-ui-pro/zero-hour/issues"
|
|
13
14
|
},
|
|
14
15
|
"homepage": "https://github.com/ux-ui-pro/zero-hour",
|
|
15
|
-
"sideEffects":
|
|
16
|
+
"sideEffects": [
|
|
17
|
+
"*.css"
|
|
18
|
+
],
|
|
19
|
+
"packageManager": "npm@10.9.3",
|
|
16
20
|
"scripts": {
|
|
17
21
|
"clean": "rimraf dist",
|
|
18
|
-
"build": "
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"lint": "biome check src",
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
22
|
+
"build": "tsdown",
|
|
23
|
+
"verify": "npm run lint && npm run typecheck && npm run build && npm run test:smoke && npm run pack:check",
|
|
24
|
+
"lint": "biome check src tests tsdown.config.ts",
|
|
25
|
+
"lint:fix": "biome check --write src tests tsdown.config.ts",
|
|
26
|
+
"format": "biome format --write src tests tsdown.config.ts",
|
|
27
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
28
|
+
"test:smoke": "node --test \"tests/**/*.js\"",
|
|
29
|
+
"pack:check": "npm pack --dry-run && publint && attw --pack . --profile node16 --exclude-entrypoints zero-hour.css",
|
|
30
|
+
"prepublishOnly": "npm run clean && npm run verify"
|
|
25
31
|
},
|
|
26
32
|
"source": "src/index.ts",
|
|
27
|
-
"main": "dist/index.cjs
|
|
28
|
-
"module": "dist/index.
|
|
29
|
-
"types": "dist/index.d.ts",
|
|
33
|
+
"main": "./dist/index.cjs",
|
|
34
|
+
"module": "./dist/index.js",
|
|
35
|
+
"types": "./dist/index.d.ts",
|
|
36
|
+
"style": "./dist/zero-hour.css",
|
|
30
37
|
"exports": {
|
|
31
38
|
".": {
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
|
|
39
|
+
"import": {
|
|
40
|
+
"types": "./dist/index.d.ts",
|
|
41
|
+
"default": "./dist/index.js"
|
|
42
|
+
},
|
|
43
|
+
"require": {
|
|
44
|
+
"types": "./dist/index.d.cts",
|
|
45
|
+
"default": "./dist/index.cjs"
|
|
46
|
+
}
|
|
35
47
|
},
|
|
36
|
-
"./zero-hour.css":
|
|
37
|
-
|
|
48
|
+
"./zero-hour.css": {
|
|
49
|
+
"default": "./dist/zero-hour.css"
|
|
50
|
+
}
|
|
38
51
|
},
|
|
39
52
|
"files": [
|
|
40
|
-
"dist
|
|
53
|
+
"dist",
|
|
54
|
+
"README.md",
|
|
55
|
+
"LICENSE"
|
|
41
56
|
],
|
|
57
|
+
"engines": {
|
|
58
|
+
"node": ">=20.19.0"
|
|
59
|
+
},
|
|
60
|
+
"publishConfig": {
|
|
61
|
+
"access": "public"
|
|
62
|
+
},
|
|
42
63
|
"devDependencies": {
|
|
43
|
-
"@
|
|
44
|
-
"@
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
64
|
+
"@arethetypeswrong/cli": "^0.18.3",
|
|
65
|
+
"@biomejs/biome": "2.4.16",
|
|
66
|
+
"@tsdown/css": "^0.22.3",
|
|
67
|
+
"@types/node": "25.9.2",
|
|
68
|
+
"@ux-ui/biome-config": "^0.1.0",
|
|
69
|
+
"@ux-ui/tsconfig-base": "^0.1.0",
|
|
70
|
+
"@ux-ui/tsdown-config": "^0.1.0",
|
|
71
|
+
"publint": "^0.3.21",
|
|
72
|
+
"rimraf": "6.1.3",
|
|
73
|
+
"sass-embedded": "^1.100.0",
|
|
74
|
+
"jsdom": "29.1.1",
|
|
75
|
+
"tsdown": "0.22.3",
|
|
76
|
+
"typescript": "6.0.3"
|
|
50
77
|
},
|
|
51
78
|
"keywords": [
|
|
52
79
|
"typescript",
|
package/dist/index.cjs.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=`:host {
|
|
2
|
-
display: block;
|
|
3
|
-
width: 100%;
|
|
4
|
-
container-type: inline-size;
|
|
5
|
-
overflow: hidden;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
.zh {
|
|
9
|
-
display: flex;
|
|
10
|
-
align-items: stretch;
|
|
11
|
-
gap: 0;
|
|
12
|
-
position: relative;
|
|
13
|
-
box-sizing: border-box;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
.zh__group {
|
|
17
|
-
display: grid;
|
|
18
|
-
grid-template-columns: 1fr 1fr;
|
|
19
|
-
grid-template-rows: auto;
|
|
20
|
-
gap: 0;
|
|
21
|
-
width: 100%;
|
|
22
|
-
flex: 1 1 0;
|
|
23
|
-
min-width: 0;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
.zh__sep {
|
|
27
|
-
flex: 0 0 var(--zh-sep-width, 4%);
|
|
28
|
-
width: var(--zh-sep-width, 4%);
|
|
29
|
-
background-image: var(--zh-sep-url);
|
|
30
|
-
background-repeat: no-repeat;
|
|
31
|
-
background-position: center;
|
|
32
|
-
background-size: contain;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
.zh__digit {
|
|
36
|
-
aspect-ratio: var(--zh-digit-aspect, 9 / 12);
|
|
37
|
-
width: 100%;
|
|
38
|
-
position: relative;
|
|
39
|
-
overflow: hidden;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
.zh__digit-track {
|
|
43
|
-
width: 100%;
|
|
44
|
-
height: 100%;
|
|
45
|
-
display: flex;
|
|
46
|
-
flex-direction: column;
|
|
47
|
-
transform: translateY(0);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
.zh--mode-scroll .zh__digit-track {
|
|
51
|
-
transition: transform var(--zh-scroll-duration, 375ms)
|
|
52
|
-
var(--zh-scroll-timing, cubic-bezier(0.445, 0.05, 0.55, 0.95));
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
.zh__digit-face {
|
|
56
|
-
flex: 0 0 100%;
|
|
57
|
-
width: 100%;
|
|
58
|
-
height: 100%;
|
|
59
|
-
background-image: var(--zh-digits-url);
|
|
60
|
-
background-repeat: no-repeat;
|
|
61
|
-
/* Digits sprite is horizontal (frames left-to-right). */
|
|
62
|
-
background-size: calc(var(--zh-digits-frames, 10) * 100%) 100%;
|
|
63
|
-
background-position: calc(var(--zh-sheet-index, 0) * 100% / (var(--zh-digits-frames, 10) - 1)) 0;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
.zh__a11y {
|
|
67
|
-
position: absolute;
|
|
68
|
-
width: 1px;
|
|
69
|
-
height: 1px;
|
|
70
|
-
overflow: hidden;
|
|
71
|
-
clip: rect(0 0 0 0);
|
|
72
|
-
white-space: nowrap;
|
|
73
|
-
clip-path: inset(50%);
|
|
74
|
-
}
|
|
75
|
-
`,T=g;function F(o){const t=o.charCodeAt(0)-48;return t>=0&&t<=9?t:0}function d(o){return o<0?0:o}const p={showDays:!0,showHours:!0,showMinutes:!0,showSeconds:!0},y={hours:0,minutes:0,seconds:0};function f(o){return"adoptedStyleSheets"in o}function z(o){try{const t=new CSSStyleSheet;return t.replaceSync(o),t}catch{return null}}const N=z(g);function E(o){const t=Math.floor(o/1e3),e=t%60,s=Math.floor(t/60)%60,i=Math.floor(t/3600),n=Math.floor(i/24),r=i%24;return{d:n,h:r,m:s,s:e,totalSec:t}}function w(o){return String(o).padStart(2,"0")}function S(o,t){return[...String(o).padStart(t,"0")]}function x(o,t,e){if(!o.hasAttribute(t))return e;const s=o.getAttribute(t);return s==null||s===""?!0:s!=="false"}function b(o){if(o==null)return null;const t=o.trim();if(!t)return null;const e=t.match(/^(\d{4})-(\d{2})-(\d{2})$/);if(!e)return null;const s=Number(e[1]),i=Number(e[2]),n=Number(e[3]);return!Number.isFinite(s)||!Number.isFinite(i)||!Number.isFinite(n)?null:{year:s,month:i,day:n}}function C(o){if(o==null)return{...y};const t=o.trim();if(!t)return{...y};const e=t.split(":"),s=Number(e[0]??"0"),i=Number(e[1]??"0"),n=Number(e[2]??"0");return{hours:Number.isFinite(s)?s:0,minutes:Number.isFinite(i)?i:0,seconds:Number.isFinite(n)?n:0}}function v(o){if(o==null)return null;const t=o.trim();if(!t)return null;const e=t.match(/^(\d{1,2}):(\d{2})(?::(\d{2}))?$/);if(!e)return null;const s=Number(e[1]),i=Number(e[2]),n=Number(e[3]??"0");return!Number.isFinite(s)||!Number.isFinite(i)||!Number.isFinite(n)||s<0||s>23||i<0||i>59||n<0||n>59?null:{hours:s,minutes:i,seconds:n}}function D(o){if(o==null)return null;let t=o.trim();if(!t)return null;/^utc/i.test(t)&&(t=t.slice(3));let e=1;if(t[0]==="+"?t=t.slice(1):t[0]==="-"&&(e=-1,t=t.slice(1)),!t)return null;const[s,i="0"]=t.split(":"),n=Number(s),r=Number(i);if(!Number.isFinite(n)||!Number.isFinite(r))return null;const l=n*60+r;return e*l}function A(){if(typeof window>"u"||!("location"in window))return null;const o=window.location?.search??"";if(!o)return null;const t=new URLSearchParams(o),e={},s=t.get("date")?.trim();s&&(e.date=s);const i=t.get("time")?.trim();i&&(e.time=i);const n=t.get("utc")?.trim();n&&(e.utc=n);const r=t.get("units")?.trim();return r&&(e.units=r),Object.keys(e).length?e:null}function U(o){const t=(o??"").trim().toLowerCase();if(!t)return p;const e=t.split(":").map(a=>a.trim()).filter(Boolean);if(!e.length)return p;const s=new Set(e),i=s.has("d"),n=s.has("h"),r=s.has("m"),l=s.has("s");return!i&&!n&&!r&&!l?p:{showDays:i,showHours:n,showMinutes:r,showSeconds:l}}class m extends HTMLElement{static defaultStylesheet=N;static observedAttributes=["digits-url","separator-url","autostart","date","time","utc","units","mode"];shadow=this.attachShadow({mode:"open"});digitsUrl=null;separatorUrl=null;autostart=!0;durationMs=0;targetEpochMs=null;startEpochMs=null;nextTickTimeout=null;doneFired=!1;rootEl;daysEl;hoursEl;minutesEl;secondsEl;a11yEl;sep0El;sep1El;sep2El;styleEl=null;showDays=!0;showHours=!0;showMinutes=!0;showSeconds=!0;mode="static";hasDigitsRendered=!1;connectedCallback(){this.render(),this.readAttributes(),this.autostart?this.start():this.renderStaticInitial()}disconnectedCallback(){this.stop()}attributeChangedCallback(t,e,s){if(!this.isConnected)return;const i=this.isRunning();this.readAttributes(),this.doneFired=!1,i&&this.autostart?this.start():this.renderStaticInitial()}start(){this.stop(),this.digitsUrl&&(this.durationMs=this.targetEpochMs!=null?this.targetEpochMs-Date.now():0,this.startEpochMs=Date.now(),this.tick(),this.scheduleNextSecondBoundary())}stop(){this.nextTickTimeout!=null&&(window.clearTimeout(this.nextTickTimeout),this.nextTickTimeout=null),this.startEpochMs=null}reset(){this.doneFired=!1,this.autostart?this.start():this.renderStaticInitial()}isRunning(){return this.startEpochMs!=null&&this.nextTickTimeout!=null}isDone(){return!this.digitsUrl||this.targetEpochMs==null?!1:Date.now()>=this.targetEpochMs}readAttributes(){this.rootEl||this.render();const t=A();this.digitsUrl=this.getAttribute("digits-url"),this.separatorUrl=this.getAttribute("separator-url"),this.autostart=x(this,"autostart",!0);const e=(this.getAttribute("mode")??"").trim().toLowerCase();this.mode=e==="scroll"?"scroll":"static";const s=U(t?.units??this.getAttribute("units"));this.showDays=s.showDays,this.showHours=s.showHours,this.showMinutes=s.showMinutes,this.showSeconds=s.showSeconds;const i=b(this.getAttribute("date")),r=b(t?.date??null)??i,l=C(this.getAttribute("time")),h=v(t?.time??null)??l,c=D(this.getAttribute("utc")),_=D(t?.utc??null)??c??0;if(!r)this.targetEpochMs=null;else{const M=Date.UTC(r.year,r.month-1,r.day,h.hours,h.minutes,h.seconds);this.targetEpochMs=M-_*60*1e3}if(this.durationMs=0,!this.digitsUrl){this.setTextFallback("—:—:—:—");return}this.rootEl.style.setProperty("--zh-digits-url",`url("${this.digitsUrl}")`),this.separatorUrl?this.rootEl.style.setProperty("--zh-sep-url",`url("${this.separatorUrl}")`):this.rootEl.style.removeProperty("--zh-sep-url"),this.applyUnitsVisibility(),this.rootEl.classList.toggle("zh--mode-scroll",this.mode==="scroll")}renderStaticInitial(){if(this.targetEpochMs!=null){const t=Date.now(),e=d(this.targetEpochMs-t),{d:s,h:i,m:n,s:r}=E(e);this.setDigits({d:s,h:i,m:n,s:r},!1)}else this.setDigits({d:0,h:0,m:0,s:0},!1)}render(){this.applyStyles(null),this.rootEl=document.createElement("div"),this.rootEl.className="zh",this.daysEl=document.createElement("div"),this.daysEl.className="zh__group",this.hoursEl=document.createElement("div"),this.hoursEl.className="zh__group",this.minutesEl=document.createElement("div"),this.minutesEl.className="zh__group",this.secondsEl=document.createElement("div"),this.secondsEl.className="zh__group",this.sep0El=document.createElement("span"),this.sep0El.className="zh__sep",this.sep1El=document.createElement("span"),this.sep1El.className="zh__sep",this.sep2El=document.createElement("span"),this.sep2El.className="zh__sep",this.a11yEl=document.createElement("span"),this.a11yEl.className="zh__a11y",this.a11yEl.setAttribute("aria-live","polite"),this.rootEl.append(this.daysEl,this.sep0El,this.hoursEl,this.sep1El,this.minutesEl,this.sep2El,this.secondsEl,this.a11yEl),this.shadow.innerHTML="",this.styleEl&&this.shadow.append(this.styleEl),this.shadow.append(this.rootEl),this.setDigits({d:0,h:0,m:0,s:0},!1),this.hasDigitsRendered=!1}setTextFallback(t){this.a11yEl.textContent=t}applyUnitsVisibility(){if(!this.rootEl)return;if(this.daysEl.style.display=this.showDays?"":"none",this.hoursEl.style.display=this.showHours?"":"none",this.minutesEl.style.display=this.showMinutes?"":"none",this.secondsEl.style.display=this.showSeconds?"":"none",!!!this.separatorUrl){this.sep0El.style.display="none",this.sep1El.style.display="none",this.sep2El.style.display="none";return}const e=[this.showDays,this.showHours,this.showMinutes,this.showSeconds],s=[];for(let n=0;n<e.length;n++)e[n]&&s.push(n);this.rootEl.style.setProperty("--zh-groups",String(s.length));const i=[!1,!1,!1];if(s.length>=2)for(let n=0;n<s.length-1;n++){const r=s[n+1],l=Math.min(2,Math.max(0,r-1));i[l]=!0}this.sep0El.style.display=i[0]?"":"none",this.sep1El.style.display=i[1]?"":"none",this.sep2El.style.display=i[2]?"":"none"}setDigits({d:t,h:e,m:s,s:i},n=!0){let r=n;this.hasDigitsRendered||(r=!1);const l=S(Math.min(t,99),2),a=S(e,2),h=[...w(s)],c=[...w(i)];this.syncDigitGroup(this.daysEl,l,r),this.syncDigitGroup(this.hoursEl,a,r),this.syncDigitGroup(this.minutesEl,h,r),this.syncDigitGroup(this.secondsEl,c,r);const u=[];this.showDays&&u.push(l.join("")),this.showHours&&u.push(a.join("")),this.showMinutes&&u.push(h.join("")),this.showSeconds&&u.push(c.join("")),this.a11yEl.textContent=u.length?u.join(":"):"—",this.hasDigitsRendered=!0}syncDigitGroup(t,e,s){for(;t.children.length<e.length;){const i=t.children.length;t.appendChild(this.createDigitSlot(e[i]))}for(;t.children.length>e.length;){const i=t.lastElementChild;if(!i)break;t.removeChild(i)}for(let i=0;i<e.length;i++){const n=t.children[i];this.syncDigitSlot(n,e[i],s)}}createDigitSlot(t){const e=document.createElement("span");e.className="zh__digit";const s=document.createElement("span");s.className="zh__digit-track";const i=this.createDigitFace(t);return i.classList.add("zh__digit-face--current"),s.append(i),e.append(s),e}createDigitFace(t){const e=document.createElement("span");return e.className="zh__digit-face",this.setFaceDigit(e,t),e}setFaceDigit(t,e){t.dataset.zhDigit=e;const s=F(e);t.style.setProperty("--zh-sheet-index",String(s))}ensureDigitTrack(t){let e=t.querySelector(".zh__digit-track");return e||(e=document.createElement("span"),e.className="zh__digit-track",t.innerHTML="",t.append(e)),e}getOrCreateCurrentFace(t,e){let s=t.querySelector(".zh__digit-face--current");if(!s)s=t.querySelector(".zh__digit-face")??this.createDigitFace(e),s.classList.add("zh__digit-face--current"),this.setFaceDigit(s,s.dataset.zhDigit??e),t.innerHTML="",t.append(s);else{const i=Array.from(t.children);for(const n of i)n!==s&&t.removeChild(n)}return s}cleanupTrack(t,e){if(!t.contains(e))return;const s=Array.from(t.children);for(const i of s)i!==e&&t.removeChild(i);e.classList.remove("zh__digit-face--next"),e.classList.add("zh__digit-face--current"),t.style.transition=this.mode==="scroll"?"":"none",t.style.transform="translateY(0)"}parseTransitionMs(t){const e=window.getComputedStyle(t),s=e.transitionDuration.split(",").map(a=>a.trim()),i=e.transitionDelay.split(",").map(a=>a.trim()),n=a=>a?a.endsWith("ms")?Number.parseFloat(a):a.endsWith("s")?Number.parseFloat(a)*1e3:Number.parseFloat(a)||0:0,r=s[0]?n(s[0]):0,l=i[0]?n(i[0]):0;return r+l}animateDigitChange(t,e,s){const i=this.createDigitFace(s);i.classList.add("zh__digit-face--next"),t.innerHTML="",t.append(i,e),t.style.transition="none",t.style.transform="translateY(-100%)",t.offsetHeight,t.style.transition="",t.style.transform="translateY(0)";const n=()=>{t.removeEventListener("transitionend",n),t.contains(i)&&this.cleanupTrack(t,i)};t.addEventListener("transitionend",n,{once:!0});const r=this.parseTransitionMs(t)+150;window.setTimeout(n,r||800)}syncDigitSlot(t,e,s){const i=this.ensureDigitTrack(t),n=this.getOrCreateCurrentFace(i,e),r=n.dataset.zhDigit??e;if(this.setFaceDigit(n,r),r===e||!s||this.mode!=="scroll"){r!==e&&this.setFaceDigit(n,e),this.cleanupTrack(i,n);return}this.animateDigitChange(i,n,e)}tick(){if(!this.digitsUrl)return;const t=d(this.durationMs);if(t===0){this.setDigits({d:0,h:0,m:0,s:0}),this.fireDoneOnce(),this.stop();return}const e=this.startEpochMs??Date.now(),s=d(Date.now()-e),i=d(t-s),{d:n,h:r,m:l,s:a,totalSec:h}=E(i);this.setDigits({d:n,h:r,m:l,s:a}),h===0&&(this.fireDoneOnce(),this.stop())}fireDoneOnce(){this.doneFired||(this.doneFired=!0,this.dispatchEvent(new CustomEvent("done")))}scheduleNextSecondBoundary(){const e=1e3-Date.now()%1e3;this.nextTickTimeout=window.setTimeout(()=>{this.tick(),this.isRunning()&&this.scheduleNextSecondBoundary()},e)}adoptStylesheet(t){this.applyStyles(t)}adoptStyles(t){this.applyStyles(t)}applyStyles(t){if(typeof t=="string"){if(f(this.shadow)){const e=z(t);if(e){this.shadow.adoptedStyleSheets=[e],this.styleEl=null;return}}this.styleEl||(this.styleEl=document.createElement("style")),this.styleEl.textContent=t;return}if(t&&f(this.shadow)){this.shadow.adoptedStyleSheets=[t],this.styleEl=null;return}if(m.defaultStylesheet&&f(this.shadow)){this.shadow.adoptedStyleSheets=[m.defaultStylesheet],this.styleEl=null;return}this.styleEl||(this.styleEl=document.createElement("style")),this.styleEl.textContent=g}}customElements.get("countdown-timer")||customElements.define("countdown-timer",m);function L(o={}){const{selector:t="countdown-timer",onDone:e,stylesheet:s}=o,i=Array.from(document.querySelectorAll(t));if(e){const n=new WeakSet,r=l=>{n.has(l)||(n.add(l),e(l))};i.forEach(l=>{l.addEventListener("done",()=>r(l));const a=l;typeof a.isDone=="function"&&a.isDone()&&r(l)})}return s&&i.forEach(n=>{const r=n;typeof s=="string"?r.adoptStyles(s):r.adoptStylesheet(s)}),i}exports.initCountdownTimers=L;exports.zeroHourCssText=T;
|
package/dist/index.es.js
DELETED
|
@@ -1,464 +0,0 @@
|
|
|
1
|
-
const g = `:host {
|
|
2
|
-
display: block;
|
|
3
|
-
width: 100%;
|
|
4
|
-
container-type: inline-size;
|
|
5
|
-
overflow: hidden;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
.zh {
|
|
9
|
-
display: flex;
|
|
10
|
-
align-items: stretch;
|
|
11
|
-
gap: 0;
|
|
12
|
-
position: relative;
|
|
13
|
-
box-sizing: border-box;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
.zh__group {
|
|
17
|
-
display: grid;
|
|
18
|
-
grid-template-columns: 1fr 1fr;
|
|
19
|
-
grid-template-rows: auto;
|
|
20
|
-
gap: 0;
|
|
21
|
-
width: 100%;
|
|
22
|
-
flex: 1 1 0;
|
|
23
|
-
min-width: 0;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
.zh__sep {
|
|
27
|
-
flex: 0 0 var(--zh-sep-width, 4%);
|
|
28
|
-
width: var(--zh-sep-width, 4%);
|
|
29
|
-
background-image: var(--zh-sep-url);
|
|
30
|
-
background-repeat: no-repeat;
|
|
31
|
-
background-position: center;
|
|
32
|
-
background-size: contain;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
.zh__digit {
|
|
36
|
-
aspect-ratio: var(--zh-digit-aspect, 9 / 12);
|
|
37
|
-
width: 100%;
|
|
38
|
-
position: relative;
|
|
39
|
-
overflow: hidden;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
.zh__digit-track {
|
|
43
|
-
width: 100%;
|
|
44
|
-
height: 100%;
|
|
45
|
-
display: flex;
|
|
46
|
-
flex-direction: column;
|
|
47
|
-
transform: translateY(0);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
.zh--mode-scroll .zh__digit-track {
|
|
51
|
-
transition: transform var(--zh-scroll-duration, 375ms)
|
|
52
|
-
var(--zh-scroll-timing, cubic-bezier(0.445, 0.05, 0.55, 0.95));
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
.zh__digit-face {
|
|
56
|
-
flex: 0 0 100%;
|
|
57
|
-
width: 100%;
|
|
58
|
-
height: 100%;
|
|
59
|
-
background-image: var(--zh-digits-url);
|
|
60
|
-
background-repeat: no-repeat;
|
|
61
|
-
/* Digits sprite is horizontal (frames left-to-right). */
|
|
62
|
-
background-size: calc(var(--zh-digits-frames, 10) * 100%) 100%;
|
|
63
|
-
background-position: calc(var(--zh-sheet-index, 0) * 100% / (var(--zh-digits-frames, 10) - 1)) 0;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
.zh__a11y {
|
|
67
|
-
position: absolute;
|
|
68
|
-
width: 1px;
|
|
69
|
-
height: 1px;
|
|
70
|
-
overflow: hidden;
|
|
71
|
-
clip: rect(0 0 0 0);
|
|
72
|
-
white-space: nowrap;
|
|
73
|
-
clip-path: inset(50%);
|
|
74
|
-
}
|
|
75
|
-
`, U = g;
|
|
76
|
-
function F(o) {
|
|
77
|
-
const t = o.charCodeAt(0) - 48;
|
|
78
|
-
return t >= 0 && t <= 9 ? t : 0;
|
|
79
|
-
}
|
|
80
|
-
function d(o) {
|
|
81
|
-
return o < 0 ? 0 : o;
|
|
82
|
-
}
|
|
83
|
-
const p = {
|
|
84
|
-
showDays: !0,
|
|
85
|
-
showHours: !0,
|
|
86
|
-
showMinutes: !0,
|
|
87
|
-
showSeconds: !0
|
|
88
|
-
}, y = { hours: 0, minutes: 0, seconds: 0 };
|
|
89
|
-
function f(o) {
|
|
90
|
-
return "adoptedStyleSheets" in o;
|
|
91
|
-
}
|
|
92
|
-
function z(o) {
|
|
93
|
-
try {
|
|
94
|
-
const t = new CSSStyleSheet();
|
|
95
|
-
return t.replaceSync(o), t;
|
|
96
|
-
} catch {
|
|
97
|
-
return null;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
const N = z(g);
|
|
101
|
-
function E(o) {
|
|
102
|
-
const t = Math.floor(o / 1e3), e = t % 60, s = Math.floor(t / 60) % 60, i = Math.floor(t / 3600), n = Math.floor(i / 24), r = i % 24;
|
|
103
|
-
return { d: n, h: r, m: s, s: e, totalSec: t };
|
|
104
|
-
}
|
|
105
|
-
function w(o) {
|
|
106
|
-
return String(o).padStart(2, "0");
|
|
107
|
-
}
|
|
108
|
-
function S(o, t) {
|
|
109
|
-
return [...String(o).padStart(t, "0")];
|
|
110
|
-
}
|
|
111
|
-
function T(o, t, e) {
|
|
112
|
-
if (!o.hasAttribute(t)) return e;
|
|
113
|
-
const s = o.getAttribute(t);
|
|
114
|
-
return s == null || s === "" ? !0 : s !== "false";
|
|
115
|
-
}
|
|
116
|
-
function D(o) {
|
|
117
|
-
if (o == null) return null;
|
|
118
|
-
const t = o.trim();
|
|
119
|
-
if (!t) return null;
|
|
120
|
-
const e = t.match(/^(\d{4})-(\d{2})-(\d{2})$/);
|
|
121
|
-
if (!e) return null;
|
|
122
|
-
const s = Number(e[1]), i = Number(e[2]), n = Number(e[3]);
|
|
123
|
-
return !Number.isFinite(s) || !Number.isFinite(i) || !Number.isFinite(n) ? null : { year: s, month: i, day: n };
|
|
124
|
-
}
|
|
125
|
-
function x(o) {
|
|
126
|
-
if (o == null) return { ...y };
|
|
127
|
-
const t = o.trim();
|
|
128
|
-
if (!t) return { ...y };
|
|
129
|
-
const e = t.split(":"), s = Number(e[0] ?? "0"), i = Number(e[1] ?? "0"), n = Number(e[2] ?? "0");
|
|
130
|
-
return {
|
|
131
|
-
hours: Number.isFinite(s) ? s : 0,
|
|
132
|
-
minutes: Number.isFinite(i) ? i : 0,
|
|
133
|
-
seconds: Number.isFinite(n) ? n : 0
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
function C(o) {
|
|
137
|
-
if (o == null) return null;
|
|
138
|
-
const t = o.trim();
|
|
139
|
-
if (!t) return null;
|
|
140
|
-
const e = t.match(/^(\d{1,2}):(\d{2})(?::(\d{2}))?$/);
|
|
141
|
-
if (!e) return null;
|
|
142
|
-
const s = Number(e[1]), i = Number(e[2]), n = Number(e[3] ?? "0");
|
|
143
|
-
return !Number.isFinite(s) || !Number.isFinite(i) || !Number.isFinite(n) || s < 0 || s > 23 || i < 0 || i > 59 || n < 0 || n > 59 ? null : { hours: s, minutes: i, seconds: n };
|
|
144
|
-
}
|
|
145
|
-
function b(o) {
|
|
146
|
-
if (o == null) return null;
|
|
147
|
-
let t = o.trim();
|
|
148
|
-
if (!t) return null;
|
|
149
|
-
/^utc/i.test(t) && (t = t.slice(3));
|
|
150
|
-
let e = 1;
|
|
151
|
-
if (t[0] === "+" ? t = t.slice(1) : t[0] === "-" && (e = -1, t = t.slice(1)), !t) return null;
|
|
152
|
-
const [s, i = "0"] = t.split(":"), n = Number(s), r = Number(i);
|
|
153
|
-
if (!Number.isFinite(n) || !Number.isFinite(r)) return null;
|
|
154
|
-
const l = n * 60 + r;
|
|
155
|
-
return e * l;
|
|
156
|
-
}
|
|
157
|
-
function v() {
|
|
158
|
-
if (typeof window > "u" || !("location" in window)) return null;
|
|
159
|
-
const o = window.location?.search ?? "";
|
|
160
|
-
if (!o) return null;
|
|
161
|
-
const t = new URLSearchParams(o), e = {}, s = t.get("date")?.trim();
|
|
162
|
-
s && (e.date = s);
|
|
163
|
-
const i = t.get("time")?.trim();
|
|
164
|
-
i && (e.time = i);
|
|
165
|
-
const n = t.get("utc")?.trim();
|
|
166
|
-
n && (e.utc = n);
|
|
167
|
-
const r = t.get("units")?.trim();
|
|
168
|
-
return r && (e.units = r), Object.keys(e).length ? e : null;
|
|
169
|
-
}
|
|
170
|
-
function A(o) {
|
|
171
|
-
const t = (o ?? "").trim().toLowerCase();
|
|
172
|
-
if (!t)
|
|
173
|
-
return p;
|
|
174
|
-
const e = t.split(":").map((a) => a.trim()).filter(Boolean);
|
|
175
|
-
if (!e.length)
|
|
176
|
-
return p;
|
|
177
|
-
const s = new Set(e), i = s.has("d"), n = s.has("h"), r = s.has("m"), l = s.has("s");
|
|
178
|
-
return !i && !n && !r && !l ? p : { showDays: i, showHours: n, showMinutes: r, showSeconds: l };
|
|
179
|
-
}
|
|
180
|
-
class m extends HTMLElement {
|
|
181
|
-
static defaultStylesheet = N;
|
|
182
|
-
static observedAttributes = [
|
|
183
|
-
"digits-url",
|
|
184
|
-
"separator-url",
|
|
185
|
-
"autostart",
|
|
186
|
-
"date",
|
|
187
|
-
"time",
|
|
188
|
-
"utc",
|
|
189
|
-
"units",
|
|
190
|
-
"mode"
|
|
191
|
-
];
|
|
192
|
-
shadow = this.attachShadow({ mode: "open" });
|
|
193
|
-
digitsUrl = null;
|
|
194
|
-
separatorUrl = null;
|
|
195
|
-
autostart = !0;
|
|
196
|
-
durationMs = 0;
|
|
197
|
-
targetEpochMs = null;
|
|
198
|
-
startEpochMs = null;
|
|
199
|
-
nextTickTimeout = null;
|
|
200
|
-
doneFired = !1;
|
|
201
|
-
rootEl;
|
|
202
|
-
daysEl;
|
|
203
|
-
hoursEl;
|
|
204
|
-
minutesEl;
|
|
205
|
-
secondsEl;
|
|
206
|
-
a11yEl;
|
|
207
|
-
sep0El;
|
|
208
|
-
sep1El;
|
|
209
|
-
sep2El;
|
|
210
|
-
styleEl = null;
|
|
211
|
-
showDays = !0;
|
|
212
|
-
showHours = !0;
|
|
213
|
-
showMinutes = !0;
|
|
214
|
-
showSeconds = !0;
|
|
215
|
-
mode = "static";
|
|
216
|
-
hasDigitsRendered = !1;
|
|
217
|
-
connectedCallback() {
|
|
218
|
-
this.render(), this.readAttributes(), this.autostart ? this.start() : this.renderStaticInitial();
|
|
219
|
-
}
|
|
220
|
-
disconnectedCallback() {
|
|
221
|
-
this.stop();
|
|
222
|
-
}
|
|
223
|
-
attributeChangedCallback(t, e, s) {
|
|
224
|
-
if (!this.isConnected) return;
|
|
225
|
-
const i = this.isRunning();
|
|
226
|
-
this.readAttributes(), this.doneFired = !1, i && this.autostart ? this.start() : this.renderStaticInitial();
|
|
227
|
-
}
|
|
228
|
-
start() {
|
|
229
|
-
this.stop(), this.digitsUrl && (this.durationMs = this.targetEpochMs != null ? this.targetEpochMs - Date.now() : 0, this.startEpochMs = Date.now(), this.tick(), this.scheduleNextSecondBoundary());
|
|
230
|
-
}
|
|
231
|
-
stop() {
|
|
232
|
-
this.nextTickTimeout != null && (window.clearTimeout(this.nextTickTimeout), this.nextTickTimeout = null), this.startEpochMs = null;
|
|
233
|
-
}
|
|
234
|
-
reset() {
|
|
235
|
-
this.doneFired = !1, this.autostart ? this.start() : this.renderStaticInitial();
|
|
236
|
-
}
|
|
237
|
-
isRunning() {
|
|
238
|
-
return this.startEpochMs != null && this.nextTickTimeout != null;
|
|
239
|
-
}
|
|
240
|
-
isDone() {
|
|
241
|
-
return !this.digitsUrl || this.targetEpochMs == null ? !1 : Date.now() >= this.targetEpochMs;
|
|
242
|
-
}
|
|
243
|
-
readAttributes() {
|
|
244
|
-
this.rootEl || this.render();
|
|
245
|
-
const t = v();
|
|
246
|
-
this.digitsUrl = this.getAttribute("digits-url"), this.separatorUrl = this.getAttribute("separator-url"), this.autostart = T(this, "autostart", !0);
|
|
247
|
-
const e = (this.getAttribute("mode") ?? "").trim().toLowerCase();
|
|
248
|
-
this.mode = e === "scroll" ? "scroll" : "static";
|
|
249
|
-
const s = A(t?.units ?? this.getAttribute("units"));
|
|
250
|
-
this.showDays = s.showDays, this.showHours = s.showHours, this.showMinutes = s.showMinutes, this.showSeconds = s.showSeconds;
|
|
251
|
-
const i = D(this.getAttribute("date")), r = D(t?.date ?? null) ?? i, l = x(this.getAttribute("time")), h = C(t?.time ?? null) ?? l, c = b(this.getAttribute("utc")), _ = b(t?.utc ?? null) ?? c ?? 0;
|
|
252
|
-
if (!r)
|
|
253
|
-
this.targetEpochMs = null;
|
|
254
|
-
else {
|
|
255
|
-
const M = Date.UTC(
|
|
256
|
-
r.year,
|
|
257
|
-
r.month - 1,
|
|
258
|
-
r.day,
|
|
259
|
-
h.hours,
|
|
260
|
-
h.minutes,
|
|
261
|
-
h.seconds
|
|
262
|
-
);
|
|
263
|
-
this.targetEpochMs = M - _ * 60 * 1e3;
|
|
264
|
-
}
|
|
265
|
-
if (this.durationMs = 0, !this.digitsUrl) {
|
|
266
|
-
this.setTextFallback("—:—:—:—");
|
|
267
|
-
return;
|
|
268
|
-
}
|
|
269
|
-
this.rootEl.style.setProperty("--zh-digits-url", `url("${this.digitsUrl}")`), this.separatorUrl ? this.rootEl.style.setProperty("--zh-sep-url", `url("${this.separatorUrl}")`) : this.rootEl.style.removeProperty("--zh-sep-url"), this.applyUnitsVisibility(), this.rootEl.classList.toggle("zh--mode-scroll", this.mode === "scroll");
|
|
270
|
-
}
|
|
271
|
-
renderStaticInitial() {
|
|
272
|
-
if (this.targetEpochMs != null) {
|
|
273
|
-
const t = Date.now(), e = d(this.targetEpochMs - t), { d: s, h: i, m: n, s: r } = E(e);
|
|
274
|
-
this.setDigits({ d: s, h: i, m: n, s: r }, !1);
|
|
275
|
-
} else
|
|
276
|
-
this.setDigits({ d: 0, h: 0, m: 0, s: 0 }, !1);
|
|
277
|
-
}
|
|
278
|
-
render() {
|
|
279
|
-
this.applyStyles(null), this.rootEl = document.createElement("div"), this.rootEl.className = "zh", this.daysEl = document.createElement("div"), this.daysEl.className = "zh__group", this.hoursEl = document.createElement("div"), this.hoursEl.className = "zh__group", this.minutesEl = document.createElement("div"), this.minutesEl.className = "zh__group", this.secondsEl = document.createElement("div"), this.secondsEl.className = "zh__group", this.sep0El = document.createElement("span"), this.sep0El.className = "zh__sep", this.sep1El = document.createElement("span"), this.sep1El.className = "zh__sep", this.sep2El = document.createElement("span"), this.sep2El.className = "zh__sep", this.a11yEl = document.createElement("span"), this.a11yEl.className = "zh__a11y", this.a11yEl.setAttribute("aria-live", "polite"), this.rootEl.append(
|
|
280
|
-
this.daysEl,
|
|
281
|
-
this.sep0El,
|
|
282
|
-
this.hoursEl,
|
|
283
|
-
this.sep1El,
|
|
284
|
-
this.minutesEl,
|
|
285
|
-
this.sep2El,
|
|
286
|
-
this.secondsEl,
|
|
287
|
-
this.a11yEl
|
|
288
|
-
), this.shadow.innerHTML = "", this.styleEl && this.shadow.append(this.styleEl), this.shadow.append(this.rootEl), this.setDigits({ d: 0, h: 0, m: 0, s: 0 }, !1), this.hasDigitsRendered = !1;
|
|
289
|
-
}
|
|
290
|
-
setTextFallback(t) {
|
|
291
|
-
this.a11yEl.textContent = t;
|
|
292
|
-
}
|
|
293
|
-
applyUnitsVisibility() {
|
|
294
|
-
if (!this.rootEl) return;
|
|
295
|
-
if (this.daysEl.style.display = this.showDays ? "" : "none", this.hoursEl.style.display = this.showHours ? "" : "none", this.minutesEl.style.display = this.showMinutes ? "" : "none", this.secondsEl.style.display = this.showSeconds ? "" : "none", !!!this.separatorUrl) {
|
|
296
|
-
this.sep0El.style.display = "none", this.sep1El.style.display = "none", this.sep2El.style.display = "none";
|
|
297
|
-
return;
|
|
298
|
-
}
|
|
299
|
-
const e = [this.showDays, this.showHours, this.showMinutes, this.showSeconds], s = [];
|
|
300
|
-
for (let n = 0; n < e.length; n++)
|
|
301
|
-
e[n] && s.push(n);
|
|
302
|
-
this.rootEl.style.setProperty("--zh-groups", String(s.length));
|
|
303
|
-
const i = [!1, !1, !1];
|
|
304
|
-
if (s.length >= 2)
|
|
305
|
-
for (let n = 0; n < s.length - 1; n++) {
|
|
306
|
-
const r = s[n + 1], l = Math.min(2, Math.max(0, r - 1));
|
|
307
|
-
i[l] = !0;
|
|
308
|
-
}
|
|
309
|
-
this.sep0El.style.display = i[0] ? "" : "none", this.sep1El.style.display = i[1] ? "" : "none", this.sep2El.style.display = i[2] ? "" : "none";
|
|
310
|
-
}
|
|
311
|
-
setDigits({ d: t, h: e, m: s, s: i }, n = !0) {
|
|
312
|
-
let r = n;
|
|
313
|
-
this.hasDigitsRendered || (r = !1);
|
|
314
|
-
const l = S(Math.min(t, 99), 2), a = S(e, 2), h = [...w(s)], c = [...w(i)];
|
|
315
|
-
this.syncDigitGroup(this.daysEl, l, r), this.syncDigitGroup(this.hoursEl, a, r), this.syncDigitGroup(this.minutesEl, h, r), this.syncDigitGroup(this.secondsEl, c, r);
|
|
316
|
-
const u = [];
|
|
317
|
-
this.showDays && u.push(l.join("")), this.showHours && u.push(a.join("")), this.showMinutes && u.push(h.join("")), this.showSeconds && u.push(c.join("")), this.a11yEl.textContent = u.length ? u.join(":") : "—", this.hasDigitsRendered = !0;
|
|
318
|
-
}
|
|
319
|
-
syncDigitGroup(t, e, s) {
|
|
320
|
-
for (; t.children.length < e.length; ) {
|
|
321
|
-
const i = t.children.length;
|
|
322
|
-
t.appendChild(this.createDigitSlot(e[i]));
|
|
323
|
-
}
|
|
324
|
-
for (; t.children.length > e.length; ) {
|
|
325
|
-
const i = t.lastElementChild;
|
|
326
|
-
if (!i) break;
|
|
327
|
-
t.removeChild(i);
|
|
328
|
-
}
|
|
329
|
-
for (let i = 0; i < e.length; i++) {
|
|
330
|
-
const n = t.children[i];
|
|
331
|
-
this.syncDigitSlot(n, e[i], s);
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
createDigitSlot(t) {
|
|
335
|
-
const e = document.createElement("span");
|
|
336
|
-
e.className = "zh__digit";
|
|
337
|
-
const s = document.createElement("span");
|
|
338
|
-
s.className = "zh__digit-track";
|
|
339
|
-
const i = this.createDigitFace(t);
|
|
340
|
-
return i.classList.add("zh__digit-face--current"), s.append(i), e.append(s), e;
|
|
341
|
-
}
|
|
342
|
-
createDigitFace(t) {
|
|
343
|
-
const e = document.createElement("span");
|
|
344
|
-
return e.className = "zh__digit-face", this.setFaceDigit(e, t), e;
|
|
345
|
-
}
|
|
346
|
-
setFaceDigit(t, e) {
|
|
347
|
-
t.dataset.zhDigit = e;
|
|
348
|
-
const s = F(e);
|
|
349
|
-
t.style.setProperty("--zh-sheet-index", String(s));
|
|
350
|
-
}
|
|
351
|
-
ensureDigitTrack(t) {
|
|
352
|
-
let e = t.querySelector(".zh__digit-track");
|
|
353
|
-
return e || (e = document.createElement("span"), e.className = "zh__digit-track", t.innerHTML = "", t.append(e)), e;
|
|
354
|
-
}
|
|
355
|
-
getOrCreateCurrentFace(t, e) {
|
|
356
|
-
let s = t.querySelector(".zh__digit-face--current");
|
|
357
|
-
if (!s)
|
|
358
|
-
s = t.querySelector(".zh__digit-face") ?? this.createDigitFace(e), s.classList.add("zh__digit-face--current"), this.setFaceDigit(s, s.dataset.zhDigit ?? e), t.innerHTML = "", t.append(s);
|
|
359
|
-
else {
|
|
360
|
-
const i = Array.from(t.children);
|
|
361
|
-
for (const n of i)
|
|
362
|
-
n !== s && t.removeChild(n);
|
|
363
|
-
}
|
|
364
|
-
return s;
|
|
365
|
-
}
|
|
366
|
-
cleanupTrack(t, e) {
|
|
367
|
-
if (!t.contains(e)) return;
|
|
368
|
-
const s = Array.from(t.children);
|
|
369
|
-
for (const i of s)
|
|
370
|
-
i !== e && t.removeChild(i);
|
|
371
|
-
e.classList.remove("zh__digit-face--next"), e.classList.add("zh__digit-face--current"), t.style.transition = this.mode === "scroll" ? "" : "none", t.style.transform = "translateY(0)";
|
|
372
|
-
}
|
|
373
|
-
parseTransitionMs(t) {
|
|
374
|
-
const e = window.getComputedStyle(t), s = e.transitionDuration.split(",").map((a) => a.trim()), i = e.transitionDelay.split(",").map((a) => a.trim()), n = (a) => a ? a.endsWith("ms") ? Number.parseFloat(a) : a.endsWith("s") ? Number.parseFloat(a) * 1e3 : Number.parseFloat(a) || 0 : 0, r = s[0] ? n(s[0]) : 0, l = i[0] ? n(i[0]) : 0;
|
|
375
|
-
return r + l;
|
|
376
|
-
}
|
|
377
|
-
animateDigitChange(t, e, s) {
|
|
378
|
-
const i = this.createDigitFace(s);
|
|
379
|
-
i.classList.add("zh__digit-face--next"), t.innerHTML = "", t.append(i, e), t.style.transition = "none", t.style.transform = "translateY(-100%)", t.offsetHeight, t.style.transition = "", t.style.transform = "translateY(0)";
|
|
380
|
-
const n = () => {
|
|
381
|
-
t.removeEventListener("transitionend", n), t.contains(i) && this.cleanupTrack(t, i);
|
|
382
|
-
};
|
|
383
|
-
t.addEventListener("transitionend", n, { once: !0 });
|
|
384
|
-
const r = this.parseTransitionMs(t) + 150;
|
|
385
|
-
window.setTimeout(n, r || 800);
|
|
386
|
-
}
|
|
387
|
-
syncDigitSlot(t, e, s) {
|
|
388
|
-
const i = this.ensureDigitTrack(t), n = this.getOrCreateCurrentFace(i, e), r = n.dataset.zhDigit ?? e;
|
|
389
|
-
if (this.setFaceDigit(n, r), r === e || !s || this.mode !== "scroll") {
|
|
390
|
-
r !== e && this.setFaceDigit(n, e), this.cleanupTrack(i, n);
|
|
391
|
-
return;
|
|
392
|
-
}
|
|
393
|
-
this.animateDigitChange(i, n, e);
|
|
394
|
-
}
|
|
395
|
-
tick() {
|
|
396
|
-
if (!this.digitsUrl) return;
|
|
397
|
-
const t = d(this.durationMs);
|
|
398
|
-
if (t === 0) {
|
|
399
|
-
this.setDigits({ d: 0, h: 0, m: 0, s: 0 }), this.fireDoneOnce(), this.stop();
|
|
400
|
-
return;
|
|
401
|
-
}
|
|
402
|
-
const e = this.startEpochMs ?? Date.now(), s = d(Date.now() - e), i = d(t - s), { d: n, h: r, m: l, s: a, totalSec: h } = E(i);
|
|
403
|
-
this.setDigits({ d: n, h: r, m: l, s: a }), h === 0 && (this.fireDoneOnce(), this.stop());
|
|
404
|
-
}
|
|
405
|
-
fireDoneOnce() {
|
|
406
|
-
this.doneFired || (this.doneFired = !0, this.dispatchEvent(new CustomEvent("done")));
|
|
407
|
-
}
|
|
408
|
-
scheduleNextSecondBoundary() {
|
|
409
|
-
const e = 1e3 - Date.now() % 1e3;
|
|
410
|
-
this.nextTickTimeout = window.setTimeout(() => {
|
|
411
|
-
this.tick(), this.isRunning() && this.scheduleNextSecondBoundary();
|
|
412
|
-
}, e);
|
|
413
|
-
}
|
|
414
|
-
adoptStylesheet(t) {
|
|
415
|
-
this.applyStyles(t);
|
|
416
|
-
}
|
|
417
|
-
adoptStyles(t) {
|
|
418
|
-
this.applyStyles(t);
|
|
419
|
-
}
|
|
420
|
-
applyStyles(t) {
|
|
421
|
-
if (typeof t == "string") {
|
|
422
|
-
if (f(this.shadow)) {
|
|
423
|
-
const e = z(t);
|
|
424
|
-
if (e) {
|
|
425
|
-
this.shadow.adoptedStyleSheets = [e], this.styleEl = null;
|
|
426
|
-
return;
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
this.styleEl || (this.styleEl = document.createElement("style")), this.styleEl.textContent = t;
|
|
430
|
-
return;
|
|
431
|
-
}
|
|
432
|
-
if (t && f(this.shadow)) {
|
|
433
|
-
this.shadow.adoptedStyleSheets = [t], this.styleEl = null;
|
|
434
|
-
return;
|
|
435
|
-
}
|
|
436
|
-
if (m.defaultStylesheet && f(this.shadow)) {
|
|
437
|
-
this.shadow.adoptedStyleSheets = [m.defaultStylesheet], this.styleEl = null;
|
|
438
|
-
return;
|
|
439
|
-
}
|
|
440
|
-
this.styleEl || (this.styleEl = document.createElement("style")), this.styleEl.textContent = g;
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
customElements.get("countdown-timer") || customElements.define("countdown-timer", m);
|
|
444
|
-
function L(o = {}) {
|
|
445
|
-
const { selector: t = "countdown-timer", onDone: e, stylesheet: s } = o, i = Array.from(document.querySelectorAll(t));
|
|
446
|
-
if (e) {
|
|
447
|
-
const n = /* @__PURE__ */ new WeakSet(), r = (l) => {
|
|
448
|
-
n.has(l) || (n.add(l), e(l));
|
|
449
|
-
};
|
|
450
|
-
i.forEach((l) => {
|
|
451
|
-
l.addEventListener("done", () => r(l));
|
|
452
|
-
const a = l;
|
|
453
|
-
typeof a.isDone == "function" && a.isDone() && r(l);
|
|
454
|
-
});
|
|
455
|
-
}
|
|
456
|
-
return s && i.forEach((n) => {
|
|
457
|
-
const r = n;
|
|
458
|
-
typeof s == "string" ? r.adoptStyles(s) : r.adoptStylesheet(s);
|
|
459
|
-
}), i;
|
|
460
|
-
}
|
|
461
|
-
export {
|
|
462
|
-
L as initCountdownTimers,
|
|
463
|
-
U as zeroHourCssText
|
|
464
|
-
};
|