@jungherz-de/glasskit-elements 1.15.2 → 1.16.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 +8 -5
- package/dist/components/glk-calendar.js +261 -0
- package/dist/components/glk-date-strip.js +180 -0
- package/dist/components/glk-image-picker.js +175 -0
- package/dist/components/shared/dates-CNWaJf09.js +76 -0
- package/dist/glasskit-elements.esm.js +680 -3
- package/dist/glasskit-elements.js +682 -2
- package/dist/glasskit-elements.min.js +1 -1
- package/package.json +3 -3
- package/src/components/forms/glk-calendar.js +259 -0
- package/src/components/forms/glk-image-picker.js +173 -0
- package/src/components/navigation/glk-date-strip.js +178 -0
- package/src/dates.js +74 -0
- package/src/index.js +3 -0
package/src/dates.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// Date helpers shared by <glk-date-strip> and <glk-calendar>. Everything
|
|
2
|
+
// works on local calendar days — a date is "YYYY-MM-DD" in the element API
|
|
3
|
+
// and a local Date inside — so a day never shifts across midnight the way a
|
|
4
|
+
// UTC timestamp would. Names come from Intl, keyed by the element's locale
|
|
5
|
+
// attribute or the browser language.
|
|
6
|
+
|
|
7
|
+
export const pad = n => String(n).padStart(2, '0');
|
|
8
|
+
|
|
9
|
+
/** Local Date → "YYYY-MM-DD". */
|
|
10
|
+
export const isoDate = d => `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
|
|
11
|
+
|
|
12
|
+
/** "YYYY-MM-DD" or "YYYY-MM" → local Date, or null when unreadable. */
|
|
13
|
+
export function parseIso(text) {
|
|
14
|
+
const m = /^(\d{4})-(\d{2})(?:-(\d{2}))?$/.exec(String(text ?? '').trim());
|
|
15
|
+
if (!m) return null;
|
|
16
|
+
const d = new Date(Number(m[1]), Number(m[2]) - 1, Number(m[3] ?? 1));
|
|
17
|
+
return Number.isNaN(d.getTime()) ? null : d;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Days after a date; the Date constructor rolls over month and year ends. */
|
|
21
|
+
export const addDays = (d, n) => new Date(d.getFullYear(), d.getMonth(), d.getDate() + n);
|
|
22
|
+
|
|
23
|
+
/** A JSON object attribute → object; anything else → {}. */
|
|
24
|
+
export function parseJsonObject(text) {
|
|
25
|
+
try {
|
|
26
|
+
const v = JSON.parse(text || '{}');
|
|
27
|
+
return v && typeof v === 'object' && !Array.isArray(v) ? v : {};
|
|
28
|
+
} catch {
|
|
29
|
+
return {};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function resolveLocale(attr) {
|
|
34
|
+
return attr || (typeof navigator !== 'undefined' && navigator.language) || 'en';
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Intl formatters are cheap to keep and not to make; one set per locale.
|
|
38
|
+
const cache = new Map();
|
|
39
|
+
export function formatters(locale) {
|
|
40
|
+
let f = cache.get(locale);
|
|
41
|
+
if (!f) {
|
|
42
|
+
try {
|
|
43
|
+
f = {
|
|
44
|
+
weekday: new Intl.DateTimeFormat(locale, { weekday: 'short' }),
|
|
45
|
+
day: new Intl.DateTimeFormat(locale, { weekday: 'long', day: 'numeric', month: 'long', year: 'numeric' }),
|
|
46
|
+
month: new Intl.DateTimeFormat(locale, { month: 'long', year: 'numeric' })
|
|
47
|
+
};
|
|
48
|
+
} catch {
|
|
49
|
+
return formatters('en'); // an unknown locale tag throws a RangeError
|
|
50
|
+
}
|
|
51
|
+
cache.set(locale, f);
|
|
52
|
+
}
|
|
53
|
+
return f;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Short weekday without the trailing dot some locales add ("Mo." → "Mo"). */
|
|
57
|
+
export const weekdayShort = (f, d) => f.weekday.format(d).replace(/\.$/, '');
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* First day of the week for a locale, 0 = Sunday … 6 = Saturday. Read from
|
|
61
|
+
* Intl.Locale where the browser has it (getWeekInfo(), or the older weekInfo
|
|
62
|
+
* accessor); Monday where it cannot say.
|
|
63
|
+
*/
|
|
64
|
+
export function firstWeekday(locale) {
|
|
65
|
+
try {
|
|
66
|
+
const loc = new Intl.Locale(locale);
|
|
67
|
+
const info = typeof loc.getWeekInfo === 'function' ? loc.getWeekInfo() : loc.weekInfo;
|
|
68
|
+
if (info && info.firstDay >= 1 && info.firstDay <= 7) return info.firstDay % 7;
|
|
69
|
+
} catch { /* no Intl.Locale, or an unknown tag */ }
|
|
70
|
+
return 1;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** A tone is a short lowercase token that becomes a __mark--<tone> modifier. */
|
|
74
|
+
export const isTone = v => typeof v === 'string' && /^[a-z][a-z0-9-]*$/.test(v);
|
package/src/index.js
CHANGED
|
@@ -15,6 +15,7 @@ export { GlkTabItem } from './components/navigation/glk-tab-item.js';
|
|
|
15
15
|
export { GlkTabDock } from './components/navigation/glk-tab-dock.js';
|
|
16
16
|
export { GlkTabAccessory } from './components/navigation/glk-tab-accessory.js';
|
|
17
17
|
export { GlkSteps } from './components/navigation/glk-steps.js';
|
|
18
|
+
export { GlkDateStrip } from './components/navigation/glk-date-strip.js';
|
|
18
19
|
|
|
19
20
|
// Content
|
|
20
21
|
export { GlkCard } from './components/content/glk-card.js';
|
|
@@ -38,6 +39,8 @@ export { GlkCheckbox } from './components/forms/glk-checkbox.js';
|
|
|
38
39
|
export { GlkRadio } from './components/forms/glk-radio.js';
|
|
39
40
|
export { GlkRange } from './components/forms/glk-range.js';
|
|
40
41
|
export { GlkSegmented } from './components/forms/glk-segmented.js';
|
|
42
|
+
export { GlkCalendar } from './components/forms/glk-calendar.js';
|
|
43
|
+
export { GlkImagePicker } from './components/forms/glk-image-picker.js';
|
|
41
44
|
|
|
42
45
|
// Feedback
|
|
43
46
|
export { GlkProgress } from './components/feedback/glk-progress.js';
|