bootstrap-time 0.0.0-stage → 0.1.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,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 M. de Ridder
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,47 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
1
+ # bootstrap-time
2
+
3
+ Analog clock based on Bootstrap.
4
+
5
+ The package is available on [npm](https://www.npmjs.com/package/bootstrap-time) and [jsDelivr](https://www.jsdelivr.com/package/npm/bootstrap-time).
6
+
7
+ ## What's included
8
+
9
+ ```
10
+ src/ source
11
+ js/bootstrap-time.js script entrypoint
12
+ scss/bootstrap-time.scss style entrypoint
13
+ dist/ generated, do not edit
14
+ css/bootstrap-time.css
15
+ css/bootstrap-time.min.css
16
+ js/bootstrap-time.js
17
+ js/bootstrap-time.min.js
18
+ examples/ HTML that points at dist
19
+ ```
20
+
21
+ `npm run build` compiles `src` into `dist`. Bootstrap 6 is required. The time field uses [form adornments](https://getbootstrap.com/docs/6.0/forms/form-adorn/), which Bootstrap 5.3 does not have. Bootstrap 5.3 can only place an addon beside the input with `input-group`, not inside it. The clock icon comes from bootstrap-icons.
22
+
23
+ ## Usage
24
+
25
+ Install from npm:
26
+
27
+ ```bash
28
+ npm install bootstrap-time bootstrap@6 bootstrap-icons
29
+ ```
30
+
31
+ Or load the published files from jsDelivr:
32
+
33
+ ```html
34
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@6.0.0-alpha.1/dist/css/bootstrap.min.css">
35
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.13.2/font/bootstrap-icons.min.css">
36
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-time@0.1.0/dist/css/bootstrap-time.min.css">
37
+ <script src="https://cdn.jsdelivr.net/npm/bootstrap-time@0.1.0/dist/js/bootstrap-time.min.js"></script>
38
+ ```
39
+
40
+ Local builds use the same paths under `dist/`:
41
+
42
+ ```html
43
+ <link rel="stylesheet" href="dist/css/bootstrap-time.min.css">
44
+ <script src="dist/js/bootstrap-time.min.js"></script>
45
+ ```
46
+
47
+ The script initializes the clock when `.clock-picker`, `#clock`, `#time-input`, `#hour-arrow` and `#minute-arrow` are present. The widget overlays the form under the time input. See `examples/bootstrap-time.html`.
@@ -0,0 +1,120 @@
1
+ .clock-picker {
2
+ position: relative;
3
+ width: 20rem;
4
+ }
5
+ .clock-picker input[type=time]::-webkit-calendar-picker-indicator {
6
+ display: none;
7
+ appearance: none;
8
+ }
9
+
10
+ .clock-toggle {
11
+ pointer-events: auto;
12
+ width: 2.25rem;
13
+ height: 2.25rem;
14
+ margin: -0.25rem;
15
+ border: 0;
16
+ border-radius: 50%;
17
+ background: transparent;
18
+ color: var(--bs-form-adorn-icon-color, var(--bs-secondary-color));
19
+ }
20
+ .clock-toggle .bi {
21
+ font-size: 1rem;
22
+ line-height: 1;
23
+ }
24
+ .clock-toggle:hover, .clock-toggle:focus-visible {
25
+ background-color: var(--bs-bg-3);
26
+ color: var(--bs-body-color);
27
+ }
28
+
29
+ .clock-widget {
30
+ position: absolute;
31
+ top: 100%;
32
+ left: 0;
33
+ z-index: 5;
34
+ width: 20rem;
35
+ margin-top: 0.25rem;
36
+ padding: 0.25rem 0.5rem 1rem;
37
+ background-color: var(--bs-secondary-bg-subtle);
38
+ color: var(--bs-secondary-fg);
39
+ }
40
+
41
+ .clock-arrows {
42
+ display: flex;
43
+ justify-content: flex-end;
44
+ gap: 0.25rem;
45
+ }
46
+
47
+ .btn.clock-arrow {
48
+ display: inline-flex;
49
+ align-items: center;
50
+ justify-content: center;
51
+ width: 2rem;
52
+ height: 2rem;
53
+ min-height: 0;
54
+ padding: 0;
55
+ border-radius: 50%;
56
+ background-color: transparent;
57
+ color: var(--bs-body-color);
58
+ text-decoration: none;
59
+ }
60
+ .btn.clock-arrow svg {
61
+ width: 1.5rem;
62
+ height: 1.5rem;
63
+ fill: currentColor;
64
+ }
65
+ .btn.clock-arrow:hover, .btn.clock-arrow:focus-visible {
66
+ background-color: var(--bs-bg-3);
67
+ color: var(--bs-body-color);
68
+ }
69
+ .btn.clock-arrow:disabled, .btn.clock-arrow:disabled:hover {
70
+ background-color: transparent;
71
+ color: var(--bs-secondary-color);
72
+ opacity: 0.45;
73
+ }
74
+
75
+ .clock {
76
+ width: 16rem;
77
+ height: 16rem;
78
+ border-radius: 50%;
79
+ }
80
+
81
+ .clock-hand {
82
+ position: absolute;
83
+ left: 50%;
84
+ bottom: 50%;
85
+ width: 2px;
86
+ height: var(--hand);
87
+ transform-origin: center bottom;
88
+ transform: translateX(-50%) rotate(var(--angle));
89
+ transition: transform 0.3s ease, height 0.3s ease;
90
+ border-radius: 1px;
91
+ pointer-events: none;
92
+ }
93
+
94
+ .clock-knob {
95
+ position: absolute;
96
+ left: 50%;
97
+ top: 0;
98
+ width: 2.25rem;
99
+ height: 2.25rem;
100
+ border-radius: 50%;
101
+ transform: translate(-50%, -50%);
102
+ }
103
+
104
+ .clock-number {
105
+ position: absolute;
106
+ left: 50%;
107
+ top: 50%;
108
+ z-index: 1;
109
+ width: 2.25rem;
110
+ height: 2.25rem;
111
+ margin: -1.125rem;
112
+ border: 0;
113
+ border-radius: 50%;
114
+ background: transparent;
115
+ color: inherit;
116
+ transform: rotate(var(--angle)) translateY(calc(var(--radius) * -1)) rotate(calc(var(--angle) * -1));
117
+ }
118
+ .clock-number[aria-pressed=true] {
119
+ color: var(--bs-white, #fff);
120
+ }
@@ -0,0 +1 @@
1
+ .clock-picker{position:relative;width:20rem}.clock-picker input[type=time]::-webkit-calendar-picker-indicator{display:none;appearance:none}.clock-toggle{pointer-events:auto;width:2.25rem;height:2.25rem;margin:-0.25rem;border:0;border-radius:50%;background:rgba(0,0,0,0);color:var(--bs-form-adorn-icon-color, var(--bs-secondary-color))}.clock-toggle .bi{font-size:1rem;line-height:1}.clock-toggle:hover,.clock-toggle:focus-visible{background-color:var(--bs-bg-3);color:var(--bs-body-color)}.clock-widget{position:absolute;top:100%;left:0;z-index:5;width:20rem;margin-top:.25rem;padding:.25rem .5rem 1rem;background-color:var(--bs-secondary-bg-subtle);color:var(--bs-secondary-fg)}.clock-arrows{display:flex;justify-content:flex-end;gap:.25rem}.btn.clock-arrow{display:inline-flex;align-items:center;justify-content:center;width:2rem;height:2rem;min-height:0;padding:0;border-radius:50%;background-color:rgba(0,0,0,0);color:var(--bs-body-color);text-decoration:none}.btn.clock-arrow svg{width:1.5rem;height:1.5rem;fill:currentColor}.btn.clock-arrow:hover,.btn.clock-arrow:focus-visible{background-color:var(--bs-bg-3);color:var(--bs-body-color)}.btn.clock-arrow:disabled,.btn.clock-arrow:disabled:hover{background-color:rgba(0,0,0,0);color:var(--bs-secondary-color);opacity:.45}.clock{width:16rem;height:16rem;border-radius:50%}.clock-hand{position:absolute;left:50%;bottom:50%;width:2px;height:var(--hand);transform-origin:center bottom;transform:translateX(-50%) rotate(var(--angle));transition:transform .3s ease,height .3s ease;border-radius:1px;pointer-events:none}.clock-knob{position:absolute;left:50%;top:0;width:2.25rem;height:2.25rem;border-radius:50%;transform:translate(-50%, -50%)}.clock-number{position:absolute;left:50%;top:50%;z-index:1;width:2.25rem;height:2.25rem;margin:-1.125rem;border:0;border-radius:50%;background:rgba(0,0,0,0);color:inherit;transform:rotate(var(--angle)) translateY(calc(var(--radius) * -1)) rotate(calc(var(--angle) * -1))}.clock-number[aria-pressed=true]{color:var(--bs-white, #fff)}
@@ -0,0 +1,172 @@
1
+ // Analog clock based on Bootstrap.
2
+ // Source entrypoint. `npm run build` writes dist/js/bootstrap-time.js
3
+ // and dist/js/bootstrap-time.min.js.
4
+
5
+ (function () {
6
+ "use strict";
7
+
8
+ var INNER_RADIUS = "4.6rem";
9
+ var OUTER_RADIUS = "6.4rem";
10
+
11
+ function init() {
12
+ var picker = document.querySelector(".clock-picker");
13
+ var clock = document.querySelector("#clock");
14
+ var widget = document.querySelector("#clock-widget");
15
+ var timeInput = document.querySelector("#time-input");
16
+ var hourArrow = document.querySelector("#hour-arrow");
17
+ var minuteArrow = document.querySelector("#minute-arrow");
18
+ var clockToggle = document.querySelector("#clock-toggle");
19
+ if (!clock || !timeInput || !hourArrow || !minuteArrow) return;
20
+
21
+ var initial = (timeInput.value || "17:00").split(":");
22
+ var hour = Number(initial[0]) || 0;
23
+ var minute = Number(initial[1]) || 0;
24
+ var mode = "hour";
25
+ var handAngle = 150;
26
+ var hand = document.createElement("div");
27
+ var knob = document.createElement("span");
28
+
29
+ hand.className = "clock-hand bg-primary";
30
+ knob.className = "clock-knob bg-primary";
31
+ knob.setAttribute("aria-hidden", "true");
32
+ hand.append(knob);
33
+ clock.append(hand);
34
+
35
+ function pad(value) {
36
+ return String(value).padStart(2, "0");
37
+ }
38
+
39
+ function targetAngle() {
40
+ return mode === "hour" ? (hour % 12) * 30 : minute * 6;
41
+ }
42
+
43
+ function handLength() {
44
+ var innerHour = hour === 0 || hour > 12;
45
+ return mode === "hour" && innerHour ? INNER_RADIUS : OUTER_RADIUS;
46
+ }
47
+
48
+ function moveHand() {
49
+ var target = targetAngle();
50
+ var delta = ((target - handAngle) % 360 + 540) % 360 - 180;
51
+ handAngle += delta;
52
+ hand.style.setProperty("--angle", handAngle + "deg");
53
+ hand.style.setProperty("--hand", handLength());
54
+ }
55
+
56
+ function updateArrows() {
57
+ hourArrow.disabled = mode === "hour";
58
+ minuteArrow.disabled = mode === "minute";
59
+ }
60
+
61
+ function writeInput() {
62
+ timeInput.value = pad(hour) + ":" + pad(minute);
63
+ }
64
+
65
+ function showMode(nextMode) {
66
+ if (mode === nextMode) return;
67
+ mode = nextMode;
68
+ updateArrows();
69
+ renderClock();
70
+ }
71
+
72
+ function renderClock() {
73
+ clock.querySelectorAll(".clock-number").forEach(function (node) {
74
+ node.remove();
75
+ });
76
+ clock.setAttribute("aria-label", mode === "hour" ? "Kies een uur" : "Kies de minuten");
77
+
78
+ var numbers = mode === "hour"
79
+ ? [12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]
80
+ : [0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55];
81
+ var selected = mode === "hour" ? hour : minute;
82
+ moveHand();
83
+
84
+ numbers.forEach(function (value, index) {
85
+ var button = document.createElement("button");
86
+ var inner = mode === "hour" && index >= 12;
87
+ var angle = (mode === "hour" ? index % 12 : index) * 30;
88
+
89
+ button.type = "button";
90
+ button.className = "clock-number";
91
+ button.textContent = mode === "hour" && value === 0 ? "00" : String(value);
92
+ button.setAttribute("aria-pressed", value === selected ? "true" : "false");
93
+ button.style.setProperty("--angle", angle + "deg");
94
+ button.style.setProperty("--radius", inner ? INNER_RADIUS : OUTER_RADIUS);
95
+ button.addEventListener("click", function () {
96
+ if (mode === "hour") {
97
+ hour = value;
98
+ mode = "minute";
99
+ } else {
100
+ minute = value;
101
+ }
102
+ writeInput();
103
+ updateArrows();
104
+ renderClock();
105
+ });
106
+ clock.append(button);
107
+ });
108
+ }
109
+
110
+ function showWidget() {
111
+ if (!widget) return;
112
+ widget.hidden = false;
113
+ if (clockToggle) clockToggle.setAttribute("aria-pressed", "true");
114
+ }
115
+
116
+ function hideWidget() {
117
+ if (!widget) return;
118
+ widget.hidden = true;
119
+ if (clockToggle) clockToggle.setAttribute("aria-pressed", "false");
120
+ }
121
+
122
+ function toggleWidget() {
123
+ if (widget && widget.hidden) showWidget();
124
+ else hideWidget();
125
+ }
126
+
127
+ hourArrow.addEventListener("click", function () {
128
+ showMode("hour");
129
+ });
130
+ minuteArrow.addEventListener("click", function () {
131
+ showMode("minute");
132
+ });
133
+ if (clockToggle) {
134
+ clockToggle.addEventListener("click", toggleWidget);
135
+ }
136
+ timeInput.addEventListener("focus", showWidget);
137
+ timeInput.addEventListener("input", function () {
138
+ if (!timeInput.value) return;
139
+ var parts = timeInput.value.split(":");
140
+ var nextHour = Number(parts[0]);
141
+ var nextMinute = Number(parts[1]);
142
+ if (nextMinute !== minute) mode = "minute";
143
+ else if (nextHour !== hour) mode = "hour";
144
+ hour = nextHour;
145
+ minute = nextMinute;
146
+ updateArrows();
147
+ renderClock();
148
+ });
149
+ if (picker) {
150
+ picker.addEventListener("mousedown", function (event) {
151
+ if (event.target === timeInput) return;
152
+ if (clockToggle && clockToggle.contains(event.target)) return;
153
+ event.preventDefault();
154
+ });
155
+ }
156
+ document.addEventListener("mousedown", function (event) {
157
+ if (!picker || picker.contains(event.target)) return;
158
+ hideWidget();
159
+ });
160
+
161
+ updateArrows();
162
+ writeInput();
163
+ renderClock();
164
+ hideWidget();
165
+ }
166
+
167
+ if (document.readyState === "loading") {
168
+ document.addEventListener("DOMContentLoaded", init);
169
+ } else {
170
+ init();
171
+ }
172
+ })();
@@ -0,0 +1 @@
1
+ !function(){"use strict";var e="4.6rem",t="6.4rem";function n(){var n=document.querySelector(".clock-picker"),r=document.querySelector("#clock"),u=document.querySelector("#clock-widget"),o=document.querySelector("#time-input"),c=document.querySelector("#hour-arrow"),i=document.querySelector("#minute-arrow"),a=document.querySelector("#clock-toggle");if(r&&o&&c&&i){var d=(o.value||"17:00").split(":"),s=Number(d[0])||0,l=Number(d[1])||0,m="hour",f=150,p=document.createElement("div"),h=document.createElement("span");p.className="clock-hand bg-primary",h.className="clock-knob bg-primary",h.setAttribute("aria-hidden","true"),p.append(h),r.append(p),c.addEventListener("click",function(){k("hour")}),i.addEventListener("click",function(){k("minute")}),a&&a.addEventListener("click",function(){u&&u.hidden?S():L()}),o.addEventListener("focus",S),o.addEventListener("input",function(){if(o.value){var e=o.value.split(":"),t=Number(e[0]),n=Number(e[1]);n!==l?m="minute":t!==s&&(m="hour"),s=t,l=n,b(),E()}}),n&&n.addEventListener("mousedown",function(e){e.target!==o&&(a&&a.contains(e.target)||e.preventDefault())}),document.addEventListener("mousedown",function(e){n&&!n.contains(e.target)&&L()}),b(),g(),E(),L()}function v(e){return String(e).padStart(2,"0")}function y(){f+=((("hour"===m?s%12*30:6*l)-f)%360+540)%360-180,p.style.setProperty("--angle",f+"deg"),p.style.setProperty("--hand","hour"===m&&(0===s||s>12)?e:t)}function b(){c.disabled="hour"===m,i.disabled="minute"===m}function g(){o.value=v(s)+":"+v(l)}function k(e){m!==e&&(m=e,b(),E())}function E(){r.querySelectorAll(".clock-number").forEach(function(e){e.remove()}),r.setAttribute("aria-label","hour"===m?"Kies een uur":"Kies de minuten");var n="hour"===m?[12,1,2,3,4,5,6,7,8,9,10,11,0,13,14,15,16,17,18,19,20,21,22,23]:[0,5,10,15,20,25,30,35,40,45,50,55],u="hour"===m?s:l;y(),n.forEach(function(n,o){var c=document.createElement("button"),i="hour"===m&&o>=12,a=30*("hour"===m?o%12:o);c.type="button",c.className="clock-number",c.textContent="hour"===m&&0===n?"00":String(n),c.setAttribute("aria-pressed",n===u?"true":"false"),c.style.setProperty("--angle",a+"deg"),c.style.setProperty("--radius",i?e:t),c.addEventListener("click",function(){"hour"===m?(s=n,m="minute"):l=n,g(),b(),E()}),r.append(c)})}function S(){u&&(u.hidden=!1,a&&a.setAttribute("aria-pressed","true"))}function L(){u&&(u.hidden=!0,a&&a.setAttribute("aria-pressed","false"))}}"loading"===document.readyState?document.addEventListener("DOMContentLoaded",n):n()}();
package/package.json CHANGED
@@ -1,6 +1,68 @@
1
- {
2
- "name": "bootstrap-time",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
1
+ {
2
+ "name": "bootstrap-time",
3
+ "version": "0.1.0",
4
+ "description": "Time picker based on Bootstrap.",
5
+ "author": "M. de Ridder",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/matthijsderidder/bootstrap-time.git"
10
+ },
11
+ "bugs": {
12
+ "url": "https://github.com/matthijsderidder/bootstrap-time/issues"
13
+ },
14
+ "homepage": "https://github.com/matthijsderidder/bootstrap-time#readme",
15
+ "keywords": [
16
+ "bootstrap",
17
+ "clock",
18
+ "time",
19
+ "timepicker",
20
+ "css",
21
+ "scss"
22
+ ],
23
+ "files": [
24
+ "dist",
25
+ "src"
26
+ ],
27
+ "main": "./dist/js/bootstrap-time.js",
28
+ "module": "./dist/js/bootstrap-time.js",
29
+ "style": "./dist/css/bootstrap-time.css",
30
+ "sass": "./src/scss/bootstrap-time.scss",
31
+ "sideEffects": [
32
+ "**/*.css"
33
+ ],
34
+ "exports": {
35
+ ".": {
36
+ "style": "./dist/css/bootstrap-time.css",
37
+ "sass": "./src/scss/bootstrap-time.scss",
38
+ "import": "./dist/js/bootstrap-time.js",
39
+ "default": "./dist/js/bootstrap-time.js"
40
+ },
41
+ "./css": "./dist/css/bootstrap-time.css",
42
+ "./css/min": "./dist/css/bootstrap-time.min.css",
43
+ "./js": "./dist/js/bootstrap-time.js",
44
+ "./js/min": "./dist/js/bootstrap-time.min.js",
45
+ "./scss": "./src/scss/bootstrap-time.scss",
46
+ "./dist/*": "./dist/*",
47
+ "./src/*": "./src/*",
48
+ "./package.json": "./package.json"
49
+ },
50
+ "jsdelivr": "dist/js/bootstrap-time.min.js",
51
+ "unpkg": "dist/js/bootstrap-time.min.js",
52
+ "scripts": {
53
+ "build:css": "sass src/scss/bootstrap-time.scss dist/css/bootstrap-time.css --style=expanded --no-source-map && sass src/scss/bootstrap-time.scss dist/css/bootstrap-time.min.css --style=compressed --no-source-map",
54
+ "build:js": "mkdir -p dist/js && cp src/js/bootstrap-time.js dist/js/bootstrap-time.js && terser src/js/bootstrap-time.js --compress --mangle --output dist/js/bootstrap-time.min.js",
55
+ "build": "npm run build:css && npm run build:js",
56
+ "clean": "rm -rf dist"
57
+ },
58
+ "devDependencies": {
59
+ "sass": "^1.93.2",
60
+ "terser": "^5.44.0"
61
+ },
62
+ "peerDependencies": {
63
+ "bootstrap": ">=6.0.0-alpha.1"
64
+ },
65
+ "dependencies": {
66
+ "bootstrap-icons": "^1.13.2"
67
+ }
68
+ }
@@ -0,0 +1,172 @@
1
+ // Analog clock based on Bootstrap.
2
+ // Source entrypoint. `npm run build` writes dist/js/bootstrap-time.js
3
+ // and dist/js/bootstrap-time.min.js.
4
+
5
+ (function () {
6
+ "use strict";
7
+
8
+ var INNER_RADIUS = "4.6rem";
9
+ var OUTER_RADIUS = "6.4rem";
10
+
11
+ function init() {
12
+ var picker = document.querySelector(".clock-picker");
13
+ var clock = document.querySelector("#clock");
14
+ var widget = document.querySelector("#clock-widget");
15
+ var timeInput = document.querySelector("#time-input");
16
+ var hourArrow = document.querySelector("#hour-arrow");
17
+ var minuteArrow = document.querySelector("#minute-arrow");
18
+ var clockToggle = document.querySelector("#clock-toggle");
19
+ if (!clock || !timeInput || !hourArrow || !minuteArrow) return;
20
+
21
+ var initial = (timeInput.value || "17:00").split(":");
22
+ var hour = Number(initial[0]) || 0;
23
+ var minute = Number(initial[1]) || 0;
24
+ var mode = "hour";
25
+ var handAngle = 150;
26
+ var hand = document.createElement("div");
27
+ var knob = document.createElement("span");
28
+
29
+ hand.className = "clock-hand bg-primary";
30
+ knob.className = "clock-knob bg-primary";
31
+ knob.setAttribute("aria-hidden", "true");
32
+ hand.append(knob);
33
+ clock.append(hand);
34
+
35
+ function pad(value) {
36
+ return String(value).padStart(2, "0");
37
+ }
38
+
39
+ function targetAngle() {
40
+ return mode === "hour" ? (hour % 12) * 30 : minute * 6;
41
+ }
42
+
43
+ function handLength() {
44
+ var innerHour = hour === 0 || hour > 12;
45
+ return mode === "hour" && innerHour ? INNER_RADIUS : OUTER_RADIUS;
46
+ }
47
+
48
+ function moveHand() {
49
+ var target = targetAngle();
50
+ var delta = ((target - handAngle) % 360 + 540) % 360 - 180;
51
+ handAngle += delta;
52
+ hand.style.setProperty("--angle", handAngle + "deg");
53
+ hand.style.setProperty("--hand", handLength());
54
+ }
55
+
56
+ function updateArrows() {
57
+ hourArrow.disabled = mode === "hour";
58
+ minuteArrow.disabled = mode === "minute";
59
+ }
60
+
61
+ function writeInput() {
62
+ timeInput.value = pad(hour) + ":" + pad(minute);
63
+ }
64
+
65
+ function showMode(nextMode) {
66
+ if (mode === nextMode) return;
67
+ mode = nextMode;
68
+ updateArrows();
69
+ renderClock();
70
+ }
71
+
72
+ function renderClock() {
73
+ clock.querySelectorAll(".clock-number").forEach(function (node) {
74
+ node.remove();
75
+ });
76
+ clock.setAttribute("aria-label", mode === "hour" ? "Kies een uur" : "Kies de minuten");
77
+
78
+ var numbers = mode === "hour"
79
+ ? [12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]
80
+ : [0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55];
81
+ var selected = mode === "hour" ? hour : minute;
82
+ moveHand();
83
+
84
+ numbers.forEach(function (value, index) {
85
+ var button = document.createElement("button");
86
+ var inner = mode === "hour" && index >= 12;
87
+ var angle = (mode === "hour" ? index % 12 : index) * 30;
88
+
89
+ button.type = "button";
90
+ button.className = "clock-number";
91
+ button.textContent = mode === "hour" && value === 0 ? "00" : String(value);
92
+ button.setAttribute("aria-pressed", value === selected ? "true" : "false");
93
+ button.style.setProperty("--angle", angle + "deg");
94
+ button.style.setProperty("--radius", inner ? INNER_RADIUS : OUTER_RADIUS);
95
+ button.addEventListener("click", function () {
96
+ if (mode === "hour") {
97
+ hour = value;
98
+ mode = "minute";
99
+ } else {
100
+ minute = value;
101
+ }
102
+ writeInput();
103
+ updateArrows();
104
+ renderClock();
105
+ });
106
+ clock.append(button);
107
+ });
108
+ }
109
+
110
+ function showWidget() {
111
+ if (!widget) return;
112
+ widget.hidden = false;
113
+ if (clockToggle) clockToggle.setAttribute("aria-pressed", "true");
114
+ }
115
+
116
+ function hideWidget() {
117
+ if (!widget) return;
118
+ widget.hidden = true;
119
+ if (clockToggle) clockToggle.setAttribute("aria-pressed", "false");
120
+ }
121
+
122
+ function toggleWidget() {
123
+ if (widget && widget.hidden) showWidget();
124
+ else hideWidget();
125
+ }
126
+
127
+ hourArrow.addEventListener("click", function () {
128
+ showMode("hour");
129
+ });
130
+ minuteArrow.addEventListener("click", function () {
131
+ showMode("minute");
132
+ });
133
+ if (clockToggle) {
134
+ clockToggle.addEventListener("click", toggleWidget);
135
+ }
136
+ timeInput.addEventListener("focus", showWidget);
137
+ timeInput.addEventListener("input", function () {
138
+ if (!timeInput.value) return;
139
+ var parts = timeInput.value.split(":");
140
+ var nextHour = Number(parts[0]);
141
+ var nextMinute = Number(parts[1]);
142
+ if (nextMinute !== minute) mode = "minute";
143
+ else if (nextHour !== hour) mode = "hour";
144
+ hour = nextHour;
145
+ minute = nextMinute;
146
+ updateArrows();
147
+ renderClock();
148
+ });
149
+ if (picker) {
150
+ picker.addEventListener("mousedown", function (event) {
151
+ if (event.target === timeInput) return;
152
+ if (clockToggle && clockToggle.contains(event.target)) return;
153
+ event.preventDefault();
154
+ });
155
+ }
156
+ document.addEventListener("mousedown", function (event) {
157
+ if (!picker || picker.contains(event.target)) return;
158
+ hideWidget();
159
+ });
160
+
161
+ updateArrows();
162
+ writeInput();
163
+ renderClock();
164
+ hideWidget();
165
+ }
166
+
167
+ if (document.readyState === "loading") {
168
+ document.addEventListener("DOMContentLoaded", init);
169
+ } else {
170
+ init();
171
+ }
172
+ })();
@@ -0,0 +1,134 @@
1
+ // Analog clock based on Bootstrap.
2
+ // Source entrypoint. `npm run build` writes dist/css/bootstrap-time.css
3
+ // and dist/css/bootstrap-time.min.css.
4
+
5
+ .clock-picker {
6
+ position: relative;
7
+ width: 20rem;
8
+
9
+ input[type="time"]::-webkit-calendar-picker-indicator {
10
+ display: none;
11
+ appearance: none;
12
+ }
13
+ }
14
+
15
+ .clock-toggle {
16
+ pointer-events: auto;
17
+ width: 2.25rem;
18
+ height: 2.25rem;
19
+ margin: -0.25rem;
20
+ border: 0;
21
+ border-radius: 50%;
22
+ background: transparent;
23
+ color: var(--bs-form-adorn-icon-color, var(--bs-secondary-color));
24
+
25
+ .bi {
26
+ font-size: 1rem;
27
+ line-height: 1;
28
+ }
29
+
30
+ &:hover,
31
+ &:focus-visible {
32
+ background-color: var(--bs-bg-3);
33
+ color: var(--bs-body-color);
34
+ }
35
+ }
36
+
37
+ .clock-widget {
38
+ position: absolute;
39
+ top: 100%;
40
+ left: 0;
41
+ z-index: 5;
42
+ width: 20rem;
43
+ margin-top: 0.25rem;
44
+ padding: 0.25rem 0.5rem 1rem;
45
+ background-color: var(--bs-secondary-bg-subtle);
46
+ color: var(--bs-secondary-fg);
47
+ }
48
+
49
+ .clock-arrows {
50
+ display: flex;
51
+ justify-content: flex-end;
52
+ gap: 0.25rem;
53
+ }
54
+
55
+ .btn.clock-arrow {
56
+ display: inline-flex;
57
+ align-items: center;
58
+ justify-content: center;
59
+ width: 2rem;
60
+ height: 2rem;
61
+ min-height: 0;
62
+ padding: 0;
63
+ border-radius: 50%;
64
+ background-color: transparent;
65
+ color: var(--bs-body-color);
66
+ text-decoration: none;
67
+
68
+ svg {
69
+ width: 1.5rem;
70
+ height: 1.5rem;
71
+ fill: currentColor;
72
+ }
73
+
74
+ &:hover,
75
+ &:focus-visible {
76
+ background-color: var(--bs-bg-3);
77
+ color: var(--bs-body-color);
78
+ }
79
+
80
+ &:disabled,
81
+ &:disabled:hover {
82
+ background-color: transparent;
83
+ color: var(--bs-secondary-color);
84
+ opacity: 0.45;
85
+ }
86
+ }
87
+
88
+ .clock {
89
+ width: 16rem;
90
+ height: 16rem;
91
+ border-radius: 50%;
92
+ }
93
+
94
+ .clock-hand {
95
+ position: absolute;
96
+ left: 50%;
97
+ bottom: 50%;
98
+ width: 2px;
99
+ height: var(--hand);
100
+ transform-origin: center bottom;
101
+ transform: translateX(-50%) rotate(var(--angle));
102
+ transition: transform 0.3s ease, height 0.3s ease;
103
+ border-radius: 1px;
104
+ pointer-events: none;
105
+ }
106
+
107
+ .clock-knob {
108
+ position: absolute;
109
+ left: 50%;
110
+ top: 0;
111
+ width: 2.25rem;
112
+ height: 2.25rem;
113
+ border-radius: 50%;
114
+ transform: translate(-50%, -50%);
115
+ }
116
+
117
+ .clock-number {
118
+ position: absolute;
119
+ left: 50%;
120
+ top: 50%;
121
+ z-index: 1;
122
+ width: 2.25rem;
123
+ height: 2.25rem;
124
+ margin: -1.125rem;
125
+ border: 0;
126
+ border-radius: 50%;
127
+ background: transparent;
128
+ color: inherit;
129
+ transform: rotate(var(--angle)) translateY(calc(var(--radius) * -1)) rotate(calc(var(--angle) * -1));
130
+
131
+ &[aria-pressed="true"] {
132
+ color: var(--bs-white, #fff);
133
+ }
134
+ }