-
Notifications
You must be signed in to change notification settings - Fork 0
/
bundle.js
315 lines (265 loc) · 8.09 KB
/
bundle.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
const range_slider_integer = require('..')
const opts = { min: 0, max: 10 }
const rsi = range_slider_integer(opts)
document.body.append(rsi)
},{"..":4}],2:[function(require,module,exports){
module.exports = inputInteger
const sheet = new CSSStyleSheet
const theme = get_theme()
sheet.replaceSync(theme)
var id = 0
function inputInteger (opts, protocol) {
const { min = 0, max = 1000 } = opts
const name = `input-integer-${id++}`
const notify = protocol({ from: name }, listen)
function listen (message) {
const { type, data } = message
if (type === 'update') {
input.value = data
}
}
const el = document.createElement('div')
const shadow = el.attachShadow({ mode: 'closed' })
const input = document.createElement('input')
input.type = 'number'
input.min = min //opts.min
input.max = max //opts.max
input.onkeyup = (e) => handle_onkeyup(e, input, min, max)
input.onmouseleave = (e) => handle_onmouseleave_and_blur(e, input, min)
input.onblur = (e) => handle_onmouseleave_and_blur(e, input, min)
shadow.append(input)
shadow.adoptedStyleSheets = [sheet]
return el
// handlers
function handle_onkeyup (e, input, min, max) {
const val = Number(e.target.value)
const val_len = val.toString().length // e.target.value.length
const min_len = min.toString().length
if (val > max) input.value = max
else if (val_len === min_len && val < min) input.value = min
notify({ from: name, type: 'update', data: val })
}
function handle_onmouseleave_and_blur (e, input, min) {
const val = Number(e.target.value)
if (val < min) input.value = ''
}
}
function get_theme () {
return `
:host {
--b: 0, 0%;
--color-white: var(--b), 100%;
--color-black: var(--b), 0%;
--color-grey: var(--b), 85%;
--bg-color: var(--color-grey);
--shadow-xy: 0 0;
--shadow-blur: 8px;
--shadow-color: var(--color-white);
--shadow-opacity: 0;
--shadow-opacity-focus: 0.65;
}
input {
text-align: left;
align-items: center;
font-size: 1.4rem;
font-weight: 200;
color: hsla(var(--color-black), 1);
background-color: hsla(var(--bg-color), 1);
padding: 8px 12px;
box-shadow: var(--shadow-xy) var(--shadow-blur) hsla( var(--shadow-color), var(--shadow-opacity));
transition: font-size .3s, color .3s, background-color .3s, box-shadow .3s ease-in-out;
outline: none;
border: 1px solid hsla(var(--bg-color), 1);
border-radius: 8px;
}
input:focus {
--shadow-color: var(--color-black);
--shadow-opacity: var(--shadow-opacity-focus);
--shadow-xy: 4px 4px;
box-shadow: var(--shadow-xy) var(--shadow-blur) hsla( var(--shadow-color), var(--shadow-opacity));
}
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
-webkit-appearance: none;
}
`
}
},{}],3:[function(require,module,exports){
module.exports = rangeSlider
var id = 0
function rangeSlider (opts, protocol) {
const { min = 0, max = 1000 } = opts
const name = `range-${id++}`
const notify = protocol({ from: name }, listen)
function listen (message) {
const { type, data } = message
if (type === 'update') {
input.value = data
fill.style.width = `${(data/max)*100}%`
input.focus()
}
}
const el = document.createElement('div')
el.classList.add('container')
const shadow = el.attachShadow({ mode: 'closed'})
const input = document.createElement('input')
input.type = 'range'
input.min = min
input.max = max
input.value = min
input.oninput = handle_input
const bar = document.createElement('div')
bar.classList.add('bar')
const ruler = document.createElement('div')
ruler.classList.add('ruler')
const fill = document.createElement('div')
fill.classList.add('fill')
bar.append(ruler, fill)
const style = document.createElement('style')
style.textContent = get_theme()
shadow.append(style, input, bar)
return el
// handler
function handle_input (e) {
const val = Number(e.target.value)
fill.style.width = `${(val/max)*100}%`
notify({ from: name, type: 'update', data: val })
}
}
function get_theme () {
return `
:host { box-sizing: border-box; }
*, *:before, *:after { box-sizing: inherit; }
:host {
--white : hsla(0,0%,100%,1);
--transparent : hsla(0,0%,0%,0);
--grey : hsla(0,0%,90%,1);
--blue : hsla(207, 88%, 66%, 1);
position: relative;
width: 100%;
height: 16px;
}
input {
position: absolute;
top: 0;
left: 0;
width: 100%;
-webkit-appearance: none;
outline: none;
margin: 0;
z-index: 2;
background-color: var(--transparent);
}
.bar {
position: absolute;
top: 3px;
left: 0;
z-index: 0;
height: 10px;
width: 100%;
border-radius: 8px;
overflow: hidden;
background-color: var(--grey);
display: flex;
flex-direction: column;
justify-content: center;
}
.ruler {
position: absolute;
height: 6px;
width: 100%;
transform: scale(-1, 1);
background-size: 20px 8px;
background-image: repeating-linear-gradient(to right,
var(--grey) 0px,
var(--grey) 17px,
var(--white) 17px,
var(--white) 20px
);
}
.fill {
position: absolute;
height: 100%;
width: 0%;
background-color: var(--grey);
}
input:focus + .bar .fill,
input:focus-within + .bar .fill,
input:active + .bar .fill {
background-color: var(--blue);
}
input::-webkit-slider-thumb {
-webkit-appearance: none;
width: 16px;
height: 16px;
border-radius: 50%;
background-color: var(--white);
border: 1px solid var(--grey);
cursor: pointer;
box-shadow: 0 3px 6px rgba(0, 0, 0, .4);
transition: background-color .3s, box-shadow .15s linear;
}
input::-webkit-slider-thumb:hover {
box-shadow: 0 0 0 14px rgba(94, 176, 245, .8);
}
input::-moz-range-thumb {
width: 16px;
height: 16px;
border-radius: 50%;
background-color: var(--white);
border: 1px solid var(--grey);
cursor: pointer;
box-shadow: 0 3px 6px rgba(0, 0, 0, .4);
transition: background-color .3s, box-shadow .15s linear;
}
input::-moz-range-thumb:hover {
box-shadow: 0 0 0 14px rgba(94, 176, 245, .8);
}
`
}
},{}],4:[function(require,module,exports){
const range = require('range-slider-ui')
const integer = require('input-integer-ui')
module.exports = range_slider_integer
function range_slider_integer (opts) {
const state = {}
const el = document.createElement('div')
const shadow = el.attachShadow({ mode: 'closed' })
const rsi = document.createElement('div')
rsi.classList.add('rsi')
const range_slider = range(opts, protocol)
const input_integer = integer(opts, protocol)
rsi.append(range_slider, input_integer)
const style = document.createElement('style')
style.textContent = get_theme()
shadow.append(rsi, style)
return el
function protocol (message, notify) {
const { from } = message
state[from] = { value: 0, notify }
return listen
}
function listen (message) {
const { from, type, data } = message
state[from].value = data
if (type === 'update') {
var notify
if (from === 'range-0') notify = state['input-integer-0'].notify
else if (from === 'input-integer-0') notify = state['range-0'].notify
notify({ type, data })
}
}
function get_theme () {
return `
.rsi {
padding: 5%;
display: grid;
grid-template-columns: 8fr 1fr;
align-items: center;
justify-items: center;
}
`
}
}
},{"input-integer-ui":2,"range-slider-ui":3}]},{},[1]);