-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
350 lines (322 loc) · 19.3 KB
/
index.html
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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Human readable random string generator playground.</title>
<link
rel="icon"
href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%2210 0 100 100%22><text y=%22.90em%22 font-size=%2290%22>🔑</text></svg>"
/>
<!-- prettier-ignore -->
<style>
/*!
* Bootstrap Reboot v5.3.1 (https://getbootstrap.com/)
* Copyright 2011-2023 The Bootstrap Authors
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
*/:root,[data-bs-theme=light]{--bs-blue:#0d6efd;--bs-indigo:#6610f2;--bs-purple:#6f42c1;--bs-pink:#d63384;--bs-red:#dc3545;--bs-orange:#fd7e14;--bs-yellow:#ffc107;--bs-green:#198754;--bs-teal:#20c997;--bs-cyan:#0dcaf0;--bs-black:#000;--bs-white:#fff;--bs-gray:#6c757d;--bs-gray-dark:#343a40;--bs-gray-100:#f8f9fa;--bs-gray-200:#e9ecef;--bs-gray-300:#dee2e6;--bs-gray-400:#ced4da;--bs-gray-500:#adb5bd;--bs-gray-600:#6c757d;--bs-gray-700:#495057;--bs-gray-800:#343a40;--bs-gray-900:#212529;--bs-primary:#0d6efd;--bs-secondary:#6c757d;--bs-success:#198754;--bs-info:#0dcaf0;--bs-warning:#ffc107;--bs-danger:#dc3545;--bs-light:#f8f9fa;--bs-dark:#212529;--bs-primary-rgb:13,110,253;--bs-secondary-rgb:108,117,125;--bs-success-rgb:25,135,84;--bs-info-rgb:13,202,240;--bs-warning-rgb:255,193,7;--bs-danger-rgb:220,53,69;--bs-light-rgb:248,249,250;--bs-dark-rgb:33,37,41;--bs-primary-text-emphasis:#052c65;--bs-secondary-text-emphasis:#2b2f32;--bs-success-text-emphasis:#0a3622;--bs-info-text-emphasis:#055160;--bs-warning-text-emphasis:#664d03;--bs-danger-text-emphasis:#58151c;--bs-light-text-emphasis:#495057;--bs-dark-text-emphasis:#495057;--bs-primary-bg-subtle:#cfe2ff;--bs-secondary-bg-subtle:#e2e3e5;--bs-success-bg-subtle:#d1e7dd;--bs-info-bg-subtle:#cff4fc;--bs-warning-bg-subtle:#fff3cd;--bs-danger-bg-subtle:#f8d7da;--bs-light-bg-subtle:#fcfcfd;--bs-dark-bg-subtle:#ced4da;--bs-primary-border-subtle:#9ec5fe;--bs-secondary-border-subtle:#c4c8cb;--bs-success-border-subtle:#a3cfbb;--bs-info-border-subtle:#9eeaf9;--bs-warning-border-subtle:#ffe69c;--bs-danger-border-subtle:#f1aeb5;--bs-light-border-subtle:#e9ecef;--bs-dark-border-subtle:#adb5bd;--bs-white-rgb:255,255,255;--bs-black-rgb:0,0,0;--bs-font-sans-serif:system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue","Noto Sans","Liberation Sans",Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";--bs-font-monospace:SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace;--bs-gradient:linear-gradient(180deg, rgba(255, 255, 255, 0.15), rgba(255, 255, 255, 0));--bs-body-font-family:var(--bs-font-sans-serif);--bs-body-font-size:1rem;--bs-body-font-weight:400;--bs-body-line-height:1.5;--bs-body-color:#212529;--bs-body-color-rgb:33,37,41;--bs-body-bg:#fff;--bs-body-bg-rgb:255,255,255;--bs-emphasis-color:#000;--bs-emphasis-color-rgb:0,0,0;--bs-secondary-color:rgba(33, 37, 41, 0.75);--bs-secondary-color-rgb:33,37,41;--bs-secondary-bg:#e9ecef;--bs-secondary-bg-rgb:233,236,239;--bs-tertiary-color:rgba(33, 37, 41, 0.5);--bs-tertiary-color-rgb:33,37,41;--bs-tertiary-bg:#f8f9fa;--bs-tertiary-bg-rgb:248,249,250;--bs-heading-color:inherit;--bs-link-color:#0d6efd;--bs-link-color-rgb:13,110,253;--bs-link-decoration:underline;--bs-link-hover-color:#0a58ca;--bs-link-hover-color-rgb:10,88,202;--bs-code-color:#d63384;--bs-highlight-bg:#fff3cd;--bs-border-width:1px;--bs-border-style:solid;--bs-border-color:#dee2e6;--bs-border-color-translucent:rgba(0, 0, 0, 0.175);--bs-border-radius:0.375rem;--bs-border-radius-sm:0.25rem;--bs-border-radius-lg:0.5rem;--bs-border-radius-xl:1rem;--bs-border-radius-xxl:2rem;--bs-border-radius-2xl:var(--bs-border-radius-xxl);--bs-border-radius-pill:50rem;--bs-box-shadow:0 0.5rem 1rem rgba(0, 0, 0, 0.15);--bs-box-shadow-sm:0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);--bs-box-shadow-lg:0 1rem 3rem rgba(0, 0, 0, 0.175);--bs-box-shadow-inset:inset 0 1px 2px rgba(0, 0, 0, 0.075);--bs-focus-ring-width:0.25rem;--bs-focus-ring-opacity:0.25;--bs-focus-ring-color:rgba(13, 110, 253, 0.25);--bs-form-valid-color:#198754;--bs-form-valid-border-color:#198754;--bs-form-invalid-color:#dc3545;--bs-form-invalid-border-color:#dc3545}[data-bs-theme=dark]{color-scheme:dark;--bs-body-color:#dee2e6;--bs-body-color-rgb:222,226,230;--bs-body-bg:#212529;--bs-body-bg-rgb:33,37,41;--bs-emphasis-color:#fff;--bs-emphasis-color-rgb:255,255,255;--bs-secondary-color:rgba(222, 226, 230, 0.75);--bs-secondary-color-rgb:222,226,230;--bs-secondary-bg:#343a40;--bs-secondary-bg-rgb:52,58,64;--bs-tertiary-color:rgba(222, 226, 230, 0.5);--bs-tertiary-color-rgb:222,226,230;--bs-tertiary-bg:#2b3035;--bs-tertiary-bg-rgb:43,48,53;--bs-primary-text-emphasis:#6ea8fe;--bs-secondary-text-emphasis:#a7acb1;--bs-success-text-emphasis:#75b798;--bs-info-text-emphasis:#6edff6;--bs-warning-text-emphasis:#ffda6a;--bs-danger-text-emphasis:#ea868f;--bs-light-text-emphasis:#f8f9fa;--bs-dark-text-emphasis:#dee2e6;--bs-primary-bg-subtle:#031633;--bs-secondary-bg-subtle:#161719;--bs-success-bg-subtle:#051b11;--bs-info-bg-subtle:#032830;--bs-warning-bg-subtle:#332701;--bs-danger-bg-subtle:#2c0b0e;--bs-light-bg-subtle:#343a40;--bs-dark-bg-subtle:#1a1d20;--bs-primary-border-subtle:#084298;--bs-secondary-border-subtle:#41464b;--bs-success-border-subtle:#0f5132;--bs-info-border-subtle:#087990;--bs-warning-border-subtle:#997404;--bs-danger-border-subtle:#842029;--bs-light-border-subtle:#495057;--bs-dark-border-subtle:#343a40;--bs-heading-color:inherit;--bs-link-color:#6ea8fe;--bs-link-hover-color:#8bb9fe;--bs-link-color-rgb:110,168,254;--bs-link-hover-color-rgb:139,185,254;--bs-code-color:#e685b5;--bs-border-color:#495057;--bs-border-color-translucent:rgba(255, 255, 255, 0.15);--bs-form-valid-color:#75b798;--bs-form-valid-border-color:#75b798;--bs-form-invalid-color:#ea868f;--bs-form-invalid-border-color:#ea868f}*,::after,::before{box-sizing:border-box}@media (prefers-reduced-motion:no-preference){:root{scroll-behavior:smooth}}body{margin:0;font-family:var(--bs-body-font-family);font-size:var(--bs-body-font-size);font-weight:var(--bs-body-font-weight);line-height:var(--bs-body-line-height);color:var(--bs-body-color);text-align:var(--bs-body-text-align);background-color:var(--bs-body-bg);-webkit-text-size-adjust:100%;-webkit-tap-highlight-color:transparent}hr{margin:1rem 0;color:inherit;border:0;border-top:var(--bs-border-width) solid;opacity:.25}h1,h2,h3,h4,h5,h6{margin-top:0;margin-bottom:.5rem;font-weight:500;line-height:1.2;color:var(--bs-heading-color)}h1{font-size:calc(1.375rem + 1.5vw)}@media (min-width:1200px){h1{font-size:2.5rem}}h2{font-size:calc(1.325rem + .9vw)}@media (min-width:1200px){h2{font-size:2rem}}h3{font-size:calc(1.3rem + .6vw)}@media (min-width:1200px){h3{font-size:1.75rem}}h4{font-size:calc(1.275rem + .3vw)}@media (min-width:1200px){h4{font-size:1.5rem}}h5{font-size:1.25rem}h6{font-size:1rem}p{margin-top:0;margin-bottom:1rem}abbr[title]{-webkit-text-decoration:underline dotted;text-decoration:underline dotted;cursor:help;-webkit-text-decoration-skip-ink:none;text-decoration-skip-ink:none}address{margin-bottom:1rem;font-style:normal;line-height:inherit}ol,ul{padding-left:2rem}dl,ol,ul{margin-top:0;margin-bottom:1rem}ol ol,ol ul,ul ol,ul ul{margin-bottom:0}dt{font-weight:700}dd{margin-bottom:.5rem;margin-left:0}blockquote{margin:0 0 1rem}b,strong{font-weight:bolder}small{font-size:.875em}mark{padding:.1875em;background-color:var(--bs-highlight-bg)}sub,sup{position:relative;font-size:.75em;line-height:0;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}a{color:rgba(var(--bs-link-color-rgb),var(--bs-link-opacity,1));text-decoration:underline}a:hover{--bs-link-color-rgb:var(--bs-link-hover-color-rgb)}a:not([href]):not([class]),a:not([href]):not([class]):hover{color:inherit;text-decoration:none}code,kbd,pre,samp{font-family:var(--bs-font-monospace);font-size:1em}pre{display:block;margin-top:0;margin-bottom:1rem;overflow:auto;font-size:.875em}pre code{font-size:inherit;color:inherit;word-break:normal}code{font-size:.875em;color:var(--bs-code-color);word-wrap:break-word}a>code{color:inherit}kbd{padding:.1875rem .375rem;font-size:.875em;color:var(--bs-body-bg);background-color:var(--bs-body-color);border-radius:.25rem}kbd kbd{padding:0;font-size:1em}figure{margin:0 0 1rem}img,svg{vertical-align:middle}table{caption-side:bottom;border-collapse:collapse}caption{padding-top:.5rem;padding-bottom:.5rem;color:var(--bs-secondary-color);text-align:left}th{text-align:inherit;text-align:-webkit-match-parent}tbody,td,tfoot,th,thead,tr{border-color:inherit;border-style:solid;border-width:0}label{display:inline-block}button{border-radius:0}button:focus:not(:focus-visible){outline:0}button,input,optgroup,select,textarea{margin:0;font-family:inherit;font-size:inherit;line-height:inherit}button,select{text-transform:none}[role=button]{cursor:pointer}select{word-wrap:normal}select:disabled{opacity:1}[list]:not([type=date]):not([type=datetime-local]):not([type=month]):not([type=week]):not([type=time])::-webkit-calendar-picker-indicator{display:none!important}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button}[type=button]:not(:disabled),[type=reset]:not(:disabled),[type=submit]:not(:disabled),button:not(:disabled){cursor:pointer}::-moz-focus-inner{padding:0;border-style:none}textarea{resize:vertical}fieldset{min-width:0;padding:0;margin:0;border:0}legend{float:left;width:100%;padding:0;margin-bottom:.5rem;font-size:calc(1.275rem + .3vw);line-height:inherit}@media (min-width:1200px){legend{font-size:1.5rem}}legend+*{clear:left}::-webkit-datetime-edit-day-field,::-webkit-datetime-edit-fields-wrapper,::-webkit-datetime-edit-hour-field,::-webkit-datetime-edit-minute,::-webkit-datetime-edit-month-field,::-webkit-datetime-edit-text,::-webkit-datetime-edit-year-field{padding:0}::-webkit-inner-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-color-swatch-wrapper{padding:0}::-webkit-file-upload-button{font:inherit;-webkit-appearance:button}::file-selector-button{font:inherit;-webkit-appearance:button}output{display:inline-block}iframe{border:0}summary{display:list-item;cursor:pointer}progress{vertical-align:baseline}[hidden]{display:none!important}
</style>
<script>
const qs = (selector, scope = null) => {
if (selector instanceof HTMLElement) return selector;
return (scope || document).querySelector(selector);
};
const qsa = (selector, scope = null) =>
(scope || document).querySelectorAll(selector);
const $each = (nodelist, cb) => {
for (const [index, $el] of nodelist.entries()) {
cb($el, index);
}
};
// "normal":
// target, type, callback
// target, type, callback, options
// "delegated":
// target, selector, type, handler
// target, selector, type, handler, options
const $on = (...args) => {
const isFn = (v) => typeof v === 'function';
let target, selector, type, callback, options;
// target, selector, type, handler, options
if (args.length >= 5) {
[target, selector, type, callback, options] = args;
}
// target, selector, type, callback,
else if (args.length === 4 && isFn(args[3])) {
[target, selector, type, callback] = args;
}
// target, type, callback, options
// target, type, callback
else {
[target, type, callback, options] = args;
}
// sanity check
if (!isFn(callback)) {
console.warn('Expecting function callback argument');
return () => void 0;
}
if (typeof target === 'string') target = qs(target);
// no-op
if (!target) return () => void 0;
options = options || {};
// normalizing callback args of the two different strategies below to this:
// callback(event, $element)
// "normal"
if (!selector) {
// The currentTarget read-only property of the Event interface identifies the current
// target for the event, as the event traverses the DOM. It always refers to the
// element to which the event handler has been attached, as opposed to Event.target,
// which identifies the element on which the event occurred and which may be its descendant.
const dispatchEvent = (event) => callback(event, event.currentTarget);
target.addEventListener(type, dispatchEvent, options);
return () => target.removeEventListener(type, dispatchEvent, options);
}
// "delegated"
else {
const dispatchEvent = (event) => {
// direct child
let element = event.target;
if (element.matches(selector)) {
return callback.call(element, event, element);
}
// keep looking within ancestors up to the root...
element = event.target.closest(selector);
// if found, still check if we've not gone too far (outside of the parent context)
if (element && target.contains(element)) {
return callback.call(element, event, element);
}
};
target.addEventListener(type, dispatchEvent, options);
return () => target.removeEventListener(type, dispatchEvent, options);
}
};
// target, type, callback
// target, selector, type, handler
// positivelly expecting correct args number
const $once = (...args) => $on(...args, { once: true });
//
const escapeHtml = (str) =>
str
.replaceAll('&', '&')
.replaceAll('<', '<')
.replaceAll('>', '>')
.replaceAll('"', '"')
.replaceAll("'", ''');
</script>
<style>
main {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
}
h1 {
font-size: 1.5rem;
}
p.desc {
margin-bottom: 2rem;
}
table {
width: 100%;
table-layout: fixed;
background-color: rgba(0, 0, 0, 0.1);
}
th,
td {
text-align: center;
}
th {
padding: 1rem 0.5rem 0.5rem 0.5rem;
}
td {
padding: 0 1rem 1rem 1rem;
}
td span {
display: block;
opacity: 0.5;
margin-bottom: 0.5rem;
font-family: var(--bs-font-monospace);
}
td input {
display: block;
width: 100%;
}
#results {
background-color: rgba(0, 0, 0, 0.05);
padding: 0.5rem;
margin-bottom: 0.3rem;
}
#results code {
border: 0;
padding: 0.5rem;
display: block;
text-align: center;
font-size: 0.9rem;
position: relative;
}
#results code:hover {
background-color: white;
cursor: pointer;
}
#results code.copied::after {
content: 'Copied!';
float: right;
position: absolute;
right: 0.5rem;
color: rgba(0, 0, 0, 0.2);
}
.info {
text-align: center;
color: rgba(0, 0, 0, 0.3);
font-size: 0.8rem;
margin-bottom: 1rem;
}
.info a {
color: rgba(0, 0, 0, 0.3);
}
.info a:hover {
color: rgba(0, 0, 0, 0.7);
}
#refresher {
background-color: rgba(0, 0, 0, 0.05);
border: 1px solid rgba(0, 0, 0, 0.2);
color: rgba(0, 0, 0, 0.5);
border-radius: 0.3rem;
font-size: 0.9rem;
}
#refresher:hover {
color: rgba(0, 0, 0, 1);
}
.secondary {
opacity: 0.8;
font-weight: normal;
font-size: smaller;
background-color: darkgray;
}
input[type='range'],
input[type='checkbox'] {
cursor: pointer;
}
</style>
</head>
<body>
<main>
<h1>
<a href="https://github.com/marianmeres/random-human-readable">
<code>@marianmeres/random-human-readable</code></a
>
playground
</h1>
<p class="desc">
Simple utility to help generating random but human readable strings. Useful for
creating passwords, tokens or just plain text placeholders. See
<a href="https://github.com/marianmeres/random-human-readable">readme</a> for
more.
</p>
<table>
<thead>
<tr>
<th>adjectives</th>
<th>colors</th>
<th>nouns</th>
<th class="secondary">syllables</th>
<th class="secondary">digits</th>
<th class="secondary">special chars</th>
<th>random case</th>
</tr>
</thead>
<tbody>
<!-- prettier-ignore -->
<tr>
<td><span></span><input type="range" min="0" max="5" value="1" step="1" id="adjCount" /></td>
<td><span></span><input type="range" min="0" max="5" value="1" step="1" id="colorsCount" /></td>
<td><span></span><input type="range" min="0" max="5" value="2" step="1" id="nounsCount" /></td>
<td class="secondary"><span></span><input type="range" min="0" max="10" value="0" step="1" id="syllablesCount" /></td>
<td class="secondary"><span></span><input type="range" min="0" max="10" value="0" step="1" id="digitsCount" /></td>
<td class="secondary"><span></span><input type="range" min="0" max="10" value="0" step="1" id="specialCharsCount" /></td>
<td><span></span><input type="checkbox" value="1" id="randomizeCase" /></td>
</tr>
</tbody>
</table>
<div id="results">Please wait...</div>
<div class="info">
Click on any result to copy it to clipboard. All values are generated and stay in
the browser only. Author <a href="mailto:[email protected]">[email protected]</a>.
<span id="version"></span>
</div>
<div style="text-align: center">
<button id="refresher">Refresh</button>
</div>
</main>
<script type="module">
import { getRandomHumanReadable } from './dist/index.js';
const $inputs = {
adjCount: qs('#adjCount'),
colorsCount: qs('#colorsCount'),
nounsCount: qs('#nounsCount'),
syllablesCount: qs('#syllablesCount'),
digitsCount: qs('#digitsCount'),
specialCharsCount: qs('#specialCharsCount'),
randomizeCase: qs('#randomizeCase'),
};
const $results = qs('#results');
const render = () => {
let opts = {};
Object.entries($inputs).forEach(([k, v]) => {
opts[k] = k === 'randomizeCase' ? v.checked : parseInt(v.value);
qs('span', v.parentNode).innerHTML = opts[k];
});
console.log(opts);
let resultsHtml = '';
let i = 10;
while (i-- > 0) {
resultsHtml += `<code>${escapeHtml(getRandomHumanReadable(opts))}</code>`;
}
$results.innerHTML = resultsHtml;
};
Object.values($inputs).forEach(($el) => $el.addEventListener('input', render));
qs('#refresher').addEventListener('click', render);
let _cleanupTimer = null;
const cleanupCopyInfo = () =>
$each(qsa('code', $results), (e) => e.classList.remove('copied'));
$on($results, 'code', 'click', (e) => {
const type = 'text/plain';
const text = e.target.innerHTML;
const blob = new Blob([text], { type });
const data = [new ClipboardItem({ [type]: blob })];
navigator.clipboard.write(data).then(
() => {
if (_cleanupTimer) {
clearTimeout(_cleanupTimer);
_cleanupTimer = null;
}
cleanupCopyInfo();
e.target.classList.add('copied');
_cleanupTimer = setTimeout(cleanupCopyInfo, 2_000);
},
() => console.error('Unable to copy to clipboard')
);
// console.log(e, text);
});
render();
// fetch current version
(async () => {
try {
const { version } = await (await fetch('./package.json')).json();
qs('#version').innerHTML = `Version ${version}.`;
} catch (e) {
console.error('Unable to fetch version');
}
})();
</script>
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-44ECMC95KE"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', 'G-44ECMC95KE');
</script>
</body>
</html>