@duskmoon-dev/el-datetime 1.6.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 +87 -0
- package/dist/cjs/index.js +220 -0
- package/dist/cjs/index.js.map +11 -0
- package/dist/cjs/register.js +223 -0
- package/dist/cjs/register.js.map +12 -0
- package/dist/esm/index.js +178 -0
- package/dist/esm/index.js.map +11 -0
- package/dist/esm/register.js +176 -0
- package/dist/esm/register.js.map +12 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/el-dm-datetime.d.ts +28 -0
- package/dist/types/el-dm-datetime.d.ts.map +1 -0
- package/dist/types/index.d.ts +9 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/register.d.ts +2 -0
- package/dist/types/register.d.ts.map +1 -0
- package/package.json +64 -0
package/README.md
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# @duskmoon-dev/el-datetime
|
|
2
|
+
|
|
3
|
+
A display-only Web Component that formats ISO dates and datetimes as semantic `<time>`
|
|
4
|
+
content.
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
bun add @duskmoon-dev/el-datetime
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Registration
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
import '@duskmoon-dev/el-datetime/register';
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Or register it explicitly:
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
import { register } from '@duskmoon-dev/el-datetime';
|
|
22
|
+
|
|
23
|
+
register();
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
```html
|
|
29
|
+
<el-dm-datetime
|
|
30
|
+
value="2026-08-11T14:30:45Z"
|
|
31
|
+
format="YYYY-MM-DD HH:mm:ss"
|
|
32
|
+
time-zone="Asia/Shanghai"
|
|
33
|
+
></el-dm-datetime>
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
The example renders `2026-08-11 22:30:45` while retaining the original value in the
|
|
37
|
+
inner `<time datetime="...">` attribute.
|
|
38
|
+
|
|
39
|
+
## Attributes
|
|
40
|
+
|
|
41
|
+
| Attribute | Type | Default | Description |
|
|
42
|
+
| ----------- | -------- | -------------------- | ------------------------------------------------------------------------------------- |
|
|
43
|
+
| `value` | `string` | `''` | ISO date or datetime to display |
|
|
44
|
+
| `format` | `string` | `'YYYY-MM-DD HH:mm'` | Output format |
|
|
45
|
+
| `time-zone` | `string` | `''` | IANA time zone for timestamps with `Z` or an offset; empty uses the browser time zone |
|
|
46
|
+
|
|
47
|
+
## Format tokens
|
|
48
|
+
|
|
49
|
+
| Token | Output |
|
|
50
|
+
| ------------ | ----------------------------------------- |
|
|
51
|
+
| `YYYY`, `YY` | Four- or two-digit year |
|
|
52
|
+
| `M`, `MM` | Month without or with zero-padding |
|
|
53
|
+
| `D`, `DD` | Day without or with zero-padding |
|
|
54
|
+
| `H`, `HH` | 24-hour time without or with zero-padding |
|
|
55
|
+
| `h`, `hh` | 12-hour time without or with zero-padding |
|
|
56
|
+
| `m`, `mm` | Minutes without or with zero-padding |
|
|
57
|
+
| `s`, `ss` | Seconds without or with zero-padding |
|
|
58
|
+
| `SSS` | Milliseconds |
|
|
59
|
+
| `A`, `a` | Upper- or lowercase meridiem |
|
|
60
|
+
|
|
61
|
+
Wrap literal text in brackets so token letters are not interpreted:
|
|
62
|
+
|
|
63
|
+
```html
|
|
64
|
+
<el-dm-datetime value="2026-08-11T14:30:45" format="YYYY-MM-DD [at] h:mm A"></el-dm-datetime>
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
This renders `2026-08-11 at 2:30 PM`.
|
|
68
|
+
|
|
69
|
+
## Input and time-zone behavior
|
|
70
|
+
|
|
71
|
+
- Accepted values are `YYYY-MM-DD` and ISO datetimes such as `2026-08-11T14:30`,
|
|
72
|
+
`2026-08-11T14:30:45.123456Z`, or `2026-08-11T14:30:45+08:00`. Fractional
|
|
73
|
+
seconds are truncated to milliseconds for the `SSS` token.
|
|
74
|
+
- Date-only and offsetless datetime values are wall-clock values and are not shifted by
|
|
75
|
+
`time-zone`.
|
|
76
|
+
- Values with `Z` or an explicit offset represent an instant. They are converted to
|
|
77
|
+
`time-zone`, or to the browser's local time zone when the attribute is omitted.
|
|
78
|
+
- Invalid values, impossible dates, and invalid time zones render empty content without
|
|
79
|
+
throwing.
|
|
80
|
+
|
|
81
|
+
Use an explicit `Z` or offset whenever time-zone conversion matters.
|
|
82
|
+
|
|
83
|
+
## CSS parts
|
|
84
|
+
|
|
85
|
+
| Part | Description |
|
|
86
|
+
| ------ | ----------------------------- |
|
|
87
|
+
| `time` | The semantic `<time>` element |
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
function __accessProp(key) {
|
|
6
|
+
return this[key];
|
|
7
|
+
}
|
|
8
|
+
var __toCommonJS = (from) => {
|
|
9
|
+
var entry = (__moduleCache ??= new WeakMap).get(from), desc;
|
|
10
|
+
if (entry)
|
|
11
|
+
return entry;
|
|
12
|
+
entry = __defProp({}, "__esModule", { value: true });
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (var key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(entry, key))
|
|
16
|
+
__defProp(entry, key, {
|
|
17
|
+
get: __accessProp.bind(from, key),
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
__moduleCache.set(from, entry);
|
|
22
|
+
return entry;
|
|
23
|
+
};
|
|
24
|
+
var __moduleCache;
|
|
25
|
+
var __returnValue = (v) => v;
|
|
26
|
+
function __exportSetter(name, newValue) {
|
|
27
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
28
|
+
}
|
|
29
|
+
var __export = (target, all) => {
|
|
30
|
+
for (var name in all)
|
|
31
|
+
__defProp(target, name, {
|
|
32
|
+
get: all[name],
|
|
33
|
+
enumerable: true,
|
|
34
|
+
configurable: true,
|
|
35
|
+
set: __exportSetter.bind(all, name)
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// src/index.ts
|
|
40
|
+
var exports_src = {};
|
|
41
|
+
__export(exports_src, {
|
|
42
|
+
register: () => register,
|
|
43
|
+
ElDmDatetime: () => ElDmDatetime,
|
|
44
|
+
DEFAULT_DATETIME_FORMAT: () => DEFAULT_DATETIME_FORMAT
|
|
45
|
+
});
|
|
46
|
+
module.exports = __toCommonJS(exports_src);
|
|
47
|
+
|
|
48
|
+
// src/el-dm-datetime.ts
|
|
49
|
+
var import_el_base = require("@duskmoon-dev/el-base");
|
|
50
|
+
var DEFAULT_DATETIME_FORMAT = "YYYY-MM-DD HH:mm";
|
|
51
|
+
var ISO_DATETIME_PATTERN = /^(\d{4})-(\d{2})-(\d{2})(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d+))?)?(Z|[+-]\d{2}:\d{2})?)?$/;
|
|
52
|
+
var FORMAT_TOKEN_PATTERN = /\[([^\]]*)\]|YYYY|SSS|YY|MM|DD|HH|hh|mm|ss|M|D|H|h|m|s|A|a/g;
|
|
53
|
+
var styles = import_el_base.css`
|
|
54
|
+
:host {
|
|
55
|
+
display: inline;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
:host([hidden]) {
|
|
59
|
+
display: none;
|
|
60
|
+
}
|
|
61
|
+
`;
|
|
62
|
+
function isLeapYear(year) {
|
|
63
|
+
return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
|
|
64
|
+
}
|
|
65
|
+
function daysInMonth(year, month) {
|
|
66
|
+
if (month === 2)
|
|
67
|
+
return isLeapYear(year) ? 29 : 28;
|
|
68
|
+
return [4, 6, 9, 11].includes(month) ? 30 : 31;
|
|
69
|
+
}
|
|
70
|
+
function parseIsoDateTime(value) {
|
|
71
|
+
const match = ISO_DATETIME_PATTERN.exec(value);
|
|
72
|
+
if (!match)
|
|
73
|
+
return;
|
|
74
|
+
const year = Number(match[1]);
|
|
75
|
+
const month = Number(match[2]);
|
|
76
|
+
const day = Number(match[3]);
|
|
77
|
+
const hour = Number(match[4] ?? 0);
|
|
78
|
+
const minute = Number(match[5] ?? 0);
|
|
79
|
+
const second = Number(match[6] ?? 0);
|
|
80
|
+
const millisecond = Number((match[7] ?? "").slice(0, 3).padEnd(3, "0") || 0);
|
|
81
|
+
const offset = match[8];
|
|
82
|
+
if (year < 1 || month < 1 || month > 12 || day < 1 || day > daysInMonth(year, month) || hour > 23 || minute > 59 || second > 59) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const parts = { year, month, day, hour, minute, second, millisecond };
|
|
86
|
+
if (!offset)
|
|
87
|
+
return { parts };
|
|
88
|
+
let offsetMinutes = 0;
|
|
89
|
+
if (offset !== "Z") {
|
|
90
|
+
const offsetHours = Number(offset.slice(1, 3));
|
|
91
|
+
const offsetRemainder = Number(offset.slice(4, 6));
|
|
92
|
+
if (offsetHours > 23 || offsetRemainder > 59)
|
|
93
|
+
return;
|
|
94
|
+
const direction = offset[0] === "+" ? 1 : -1;
|
|
95
|
+
offsetMinutes = direction * (offsetHours * 60 + offsetRemainder);
|
|
96
|
+
}
|
|
97
|
+
const utc = new Date(0);
|
|
98
|
+
utc.setUTCFullYear(year, month - 1, day);
|
|
99
|
+
utc.setUTCHours(hour, minute, second, millisecond);
|
|
100
|
+
return {
|
|
101
|
+
parts,
|
|
102
|
+
instant: new Date(utc.getTime() - offsetMinutes * 60000)
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
function isValidTimeZone(timeZone) {
|
|
106
|
+
if (!timeZone)
|
|
107
|
+
return true;
|
|
108
|
+
try {
|
|
109
|
+
new Intl.DateTimeFormat("en-US", { timeZone }).format();
|
|
110
|
+
return true;
|
|
111
|
+
} catch {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function partsForInstant(date, timeZone) {
|
|
116
|
+
if (!timeZone) {
|
|
117
|
+
return {
|
|
118
|
+
year: date.getFullYear(),
|
|
119
|
+
month: date.getMonth() + 1,
|
|
120
|
+
day: date.getDate(),
|
|
121
|
+
hour: date.getHours(),
|
|
122
|
+
minute: date.getMinutes(),
|
|
123
|
+
second: date.getSeconds(),
|
|
124
|
+
millisecond: date.getMilliseconds()
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
try {
|
|
128
|
+
const parts = new Intl.DateTimeFormat("en-US-u-ca-gregory-nu-latn", {
|
|
129
|
+
timeZone,
|
|
130
|
+
year: "numeric",
|
|
131
|
+
month: "2-digit",
|
|
132
|
+
day: "2-digit",
|
|
133
|
+
hour: "2-digit",
|
|
134
|
+
minute: "2-digit",
|
|
135
|
+
second: "2-digit",
|
|
136
|
+
hourCycle: "h23"
|
|
137
|
+
}).formatToParts(date);
|
|
138
|
+
const values = new Map(parts.map(({ type, value }) => [type, value]));
|
|
139
|
+
return {
|
|
140
|
+
year: Number(values.get("year")),
|
|
141
|
+
month: Number(values.get("month")),
|
|
142
|
+
day: Number(values.get("day")),
|
|
143
|
+
hour: Number(values.get("hour")),
|
|
144
|
+
minute: Number(values.get("minute")),
|
|
145
|
+
second: Number(values.get("second")),
|
|
146
|
+
millisecond: date.getMilliseconds()
|
|
147
|
+
};
|
|
148
|
+
} catch {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
function formatDateTime(parts, format) {
|
|
153
|
+
const hour12 = parts.hour % 12 || 12;
|
|
154
|
+
const meridiem = parts.hour < 12 ? "AM" : "PM";
|
|
155
|
+
const tokens = {
|
|
156
|
+
YYYY: String(parts.year).padStart(4, "0"),
|
|
157
|
+
YY: String(parts.year % 100).padStart(2, "0"),
|
|
158
|
+
M: String(parts.month),
|
|
159
|
+
MM: String(parts.month).padStart(2, "0"),
|
|
160
|
+
D: String(parts.day),
|
|
161
|
+
DD: String(parts.day).padStart(2, "0"),
|
|
162
|
+
H: String(parts.hour),
|
|
163
|
+
HH: String(parts.hour).padStart(2, "0"),
|
|
164
|
+
h: String(hour12),
|
|
165
|
+
hh: String(hour12).padStart(2, "0"),
|
|
166
|
+
m: String(parts.minute),
|
|
167
|
+
mm: String(parts.minute).padStart(2, "0"),
|
|
168
|
+
s: String(parts.second),
|
|
169
|
+
ss: String(parts.second).padStart(2, "0"),
|
|
170
|
+
SSS: String(parts.millisecond).padStart(3, "0"),
|
|
171
|
+
A: meridiem,
|
|
172
|
+
a: meridiem.toLowerCase()
|
|
173
|
+
};
|
|
174
|
+
return format.replace(FORMAT_TOKEN_PATTERN, (match, literal) => literal ?? tokens[match] ?? match);
|
|
175
|
+
}
|
|
176
|
+
function escapeHtml(value) {
|
|
177
|
+
const entities = {
|
|
178
|
+
"&": "&",
|
|
179
|
+
"<": "<",
|
|
180
|
+
">": ">",
|
|
181
|
+
'"': """,
|
|
182
|
+
"'": "'"
|
|
183
|
+
};
|
|
184
|
+
return value.replace(/[&<>"']/g, (character) => entities[character]);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
class ElDmDatetime extends import_el_base.BaseElement {
|
|
188
|
+
static properties = {
|
|
189
|
+
value: { type: String, reflect: true, default: "" },
|
|
190
|
+
format: { type: String, reflect: true, default: DEFAULT_DATETIME_FORMAT },
|
|
191
|
+
timeZone: { type: String, reflect: true, default: "" }
|
|
192
|
+
};
|
|
193
|
+
constructor() {
|
|
194
|
+
super();
|
|
195
|
+
this.attachStyles(styles);
|
|
196
|
+
}
|
|
197
|
+
render() {
|
|
198
|
+
const value = this.value ?? "";
|
|
199
|
+
const format = this.format ?? DEFAULT_DATETIME_FORMAT;
|
|
200
|
+
const timeZone = this.timeZone ?? "";
|
|
201
|
+
const parsed = value ? parseIsoDateTime(value) : undefined;
|
|
202
|
+
if (!parsed || !isValidTimeZone(timeZone)) {
|
|
203
|
+
return '<time part="time"></time>';
|
|
204
|
+
}
|
|
205
|
+
const parts = parsed.instant ? partsForInstant(parsed.instant, timeZone) : parsed.parts;
|
|
206
|
+
if (!parts)
|
|
207
|
+
return '<time part="time"></time>';
|
|
208
|
+
return `<time part="time" datetime="${escapeHtml(value)}">${escapeHtml(formatDateTime(parts, format))}</time>`;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// src/index.ts
|
|
213
|
+
function register() {
|
|
214
|
+
if (!customElements.get("el-dm-datetime")) {
|
|
215
|
+
customElements.define("el-dm-datetime", ElDmDatetime);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
//# debugId=0C96C18D237CDD5D64756E2164756E21
|
|
220
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/el-dm-datetime.ts", "../../src/index.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import { BaseElement, css } from '@duskmoon-dev/el-base';\n\nexport const DEFAULT_DATETIME_FORMAT = 'YYYY-MM-DD HH:mm';\n\ninterface DateTimeParts {\n year: number;\n month: number;\n day: number;\n hour: number;\n minute: number;\n second: number;\n millisecond: number;\n}\n\ninterface ParsedDateTime {\n parts: DateTimeParts;\n instant?: Date;\n}\n\nconst ISO_DATETIME_PATTERN =\n /^(\\d{4})-(\\d{2})-(\\d{2})(?:T(\\d{2}):(\\d{2})(?::(\\d{2})(?:\\.(\\d+))?)?(Z|[+-]\\d{2}:\\d{2})?)?$/;\nconst FORMAT_TOKEN_PATTERN = /\\[([^\\]]*)\\]|YYYY|SSS|YY|MM|DD|HH|hh|mm|ss|M|D|H|h|m|s|A|a/g;\n\nconst styles = css`\n :host {\n display: inline;\n }\n\n :host([hidden]) {\n display: none;\n }\n`;\n\nfunction isLeapYear(year: number): boolean {\n return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);\n}\n\nfunction daysInMonth(year: number, month: number): number {\n if (month === 2) return isLeapYear(year) ? 29 : 28;\n return [4, 6, 9, 11].includes(month) ? 30 : 31;\n}\n\nfunction parseIsoDateTime(value: string): ParsedDateTime | undefined {\n const match = ISO_DATETIME_PATTERN.exec(value);\n if (!match) return undefined;\n\n const year = Number(match[1]);\n const month = Number(match[2]);\n const day = Number(match[3]);\n const hour = Number(match[4] ?? 0);\n const minute = Number(match[5] ?? 0);\n const second = Number(match[6] ?? 0);\n const millisecond = Number((match[7] ?? '').slice(0, 3).padEnd(3, '0') || 0);\n const offset = match[8];\n\n if (\n year < 1 ||\n month < 1 ||\n month > 12 ||\n day < 1 ||\n day > daysInMonth(year, month) ||\n hour > 23 ||\n minute > 59 ||\n second > 59\n ) {\n return undefined;\n }\n\n const parts = { year, month, day, hour, minute, second, millisecond };\n if (!offset) return { parts };\n\n let offsetMinutes = 0;\n if (offset !== 'Z') {\n const offsetHours = Number(offset.slice(1, 3));\n const offsetRemainder = Number(offset.slice(4, 6));\n if (offsetHours > 23 || offsetRemainder > 59) return undefined;\n\n const direction = offset[0] === '+' ? 1 : -1;\n offsetMinutes = direction * (offsetHours * 60 + offsetRemainder);\n }\n\n const utc = new Date(0);\n utc.setUTCFullYear(year, month - 1, day);\n utc.setUTCHours(hour, minute, second, millisecond);\n\n return {\n parts,\n instant: new Date(utc.getTime() - offsetMinutes * 60_000),\n };\n}\n\nfunction isValidTimeZone(timeZone: string): boolean {\n if (!timeZone) return true;\n\n try {\n new Intl.DateTimeFormat('en-US', { timeZone }).format();\n return true;\n } catch {\n return false;\n }\n}\n\nfunction partsForInstant(date: Date, timeZone: string): DateTimeParts | undefined {\n if (!timeZone) {\n return {\n year: date.getFullYear(),\n month: date.getMonth() + 1,\n day: date.getDate(),\n hour: date.getHours(),\n minute: date.getMinutes(),\n second: date.getSeconds(),\n millisecond: date.getMilliseconds(),\n };\n }\n\n try {\n const parts = new Intl.DateTimeFormat('en-US-u-ca-gregory-nu-latn', {\n timeZone,\n year: 'numeric',\n month: '2-digit',\n day: '2-digit',\n hour: '2-digit',\n minute: '2-digit',\n second: '2-digit',\n hourCycle: 'h23',\n }).formatToParts(date);\n const values = new Map(parts.map(({ type, value }) => [type, value]));\n\n return {\n year: Number(values.get('year')),\n month: Number(values.get('month')),\n day: Number(values.get('day')),\n hour: Number(values.get('hour')),\n minute: Number(values.get('minute')),\n second: Number(values.get('second')),\n millisecond: date.getMilliseconds(),\n };\n } catch {\n return undefined;\n }\n}\n\nfunction formatDateTime(parts: DateTimeParts, format: string): string {\n const hour12 = parts.hour % 12 || 12;\n const meridiem = parts.hour < 12 ? 'AM' : 'PM';\n const tokens: Record<string, string> = {\n YYYY: String(parts.year).padStart(4, '0'),\n YY: String(parts.year % 100).padStart(2, '0'),\n M: String(parts.month),\n MM: String(parts.month).padStart(2, '0'),\n D: String(parts.day),\n DD: String(parts.day).padStart(2, '0'),\n H: String(parts.hour),\n HH: String(parts.hour).padStart(2, '0'),\n h: String(hour12),\n hh: String(hour12).padStart(2, '0'),\n m: String(parts.minute),\n mm: String(parts.minute).padStart(2, '0'),\n s: String(parts.second),\n ss: String(parts.second).padStart(2, '0'),\n SSS: String(parts.millisecond).padStart(3, '0'),\n A: meridiem,\n a: meridiem.toLowerCase(),\n };\n\n return format.replace(\n FORMAT_TOKEN_PATTERN,\n (match: string, literal: string | undefined) => literal ?? tokens[match] ?? match,\n );\n}\n\nfunction escapeHtml(value: string): string {\n const entities: Record<string, string> = {\n '&': '&',\n '<': '<',\n '>': '>',\n '\"': '"',\n \"'\": ''',\n };\n\n return value.replace(/[&<>\"']/g, (character) => entities[character]);\n}\n\n/** Display an ISO date or datetime using a token-based format. */\nexport class ElDmDatetime extends BaseElement {\n static properties = {\n value: { type: String, reflect: true, default: '' },\n format: { type: String, reflect: true, default: DEFAULT_DATETIME_FORMAT },\n timeZone: { type: String, reflect: true, default: '' },\n };\n\n declare value: string;\n declare format: string;\n declare timeZone: string;\n\n constructor() {\n super();\n this.attachStyles(styles);\n }\n\n protected render(): string {\n const value = this.value ?? '';\n const format = this.format ?? DEFAULT_DATETIME_FORMAT;\n const timeZone = this.timeZone ?? '';\n const parsed = value ? parseIsoDateTime(value) : undefined;\n\n if (!parsed || !isValidTimeZone(timeZone)) {\n return '<time part=\"time\"></time>';\n }\n\n const parts = parsed.instant ? partsForInstant(parsed.instant, timeZone) : parsed.parts;\n if (!parts) return '<time part=\"time\"></time>';\n\n return `<time part=\"time\" datetime=\"${escapeHtml(value)}\">${escapeHtml(formatDateTime(parts, format))}</time>`;\n }\n}\n",
|
|
6
|
+
"/**\n * @duskmoon-dev/el-datetime\n *\n * Display-only ISO date and datetime formatting custom element.\n */\n\nimport { ElDmDatetime } from './el-dm-datetime.js';\n\nexport { DEFAULT_DATETIME_FORMAT, ElDmDatetime } from './el-dm-datetime.js';\n\n/** Register the el-dm-datetime custom element. */\nexport function register(): void {\n if (!customElements.get('el-dm-datetime')) {\n customElements.define('el-dm-datetime', ElDmDatetime);\n }\n}\n"
|
|
7
|
+
],
|
|
8
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAiC,IAAjC;AAEO,IAAM,0BAA0B;AAiBvC,IAAM,uBACJ;AACF,IAAM,uBAAuB;AAE7B,IAAM,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUf,SAAS,UAAU,CAAC,MAAuB;AAAA,EACzC,OAAO,OAAO,MAAM,MAAM,OAAO,QAAQ,KAAK,OAAO,QAAQ;AAAA;AAG/D,SAAS,WAAW,CAAC,MAAc,OAAuB;AAAA,EACxD,IAAI,UAAU;AAAA,IAAG,OAAO,WAAW,IAAI,IAAI,KAAK;AAAA,EAChD,OAAO,CAAC,GAAG,GAAG,G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YAAY;AAAA,EACtD;AAAA;",
|
|
9
|
+
"debugId": "0C96C18D237CDD5D64756E2164756E21",
|
|
10
|
+
"names": []
|
|
11
|
+
}
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
function __accessProp(key) {
|
|
6
|
+
return this[key];
|
|
7
|
+
}
|
|
8
|
+
var __toCommonJS = (from) => {
|
|
9
|
+
var entry = (__moduleCache ??= new WeakMap).get(from), desc;
|
|
10
|
+
if (entry)
|
|
11
|
+
return entry;
|
|
12
|
+
entry = __defProp({}, "__esModule", { value: true });
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (var key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(entry, key))
|
|
16
|
+
__defProp(entry, key, {
|
|
17
|
+
get: __accessProp.bind(from, key),
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
__moduleCache.set(from, entry);
|
|
22
|
+
return entry;
|
|
23
|
+
};
|
|
24
|
+
var __moduleCache;
|
|
25
|
+
var __returnValue = (v) => v;
|
|
26
|
+
function __exportSetter(name, newValue) {
|
|
27
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
28
|
+
}
|
|
29
|
+
var __export = (target, all) => {
|
|
30
|
+
for (var name in all)
|
|
31
|
+
__defProp(target, name, {
|
|
32
|
+
get: all[name],
|
|
33
|
+
enumerable: true,
|
|
34
|
+
configurable: true,
|
|
35
|
+
set: __exportSetter.bind(all, name)
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// src/index.ts
|
|
40
|
+
var exports_src = {};
|
|
41
|
+
__export(exports_src, {
|
|
42
|
+
register: () => register,
|
|
43
|
+
ElDmDatetime: () => ElDmDatetime,
|
|
44
|
+
DEFAULT_DATETIME_FORMAT: () => DEFAULT_DATETIME_FORMAT
|
|
45
|
+
});
|
|
46
|
+
module.exports = __toCommonJS(exports_src);
|
|
47
|
+
|
|
48
|
+
// src/el-dm-datetime.ts
|
|
49
|
+
var import_el_base = require("@duskmoon-dev/el-base");
|
|
50
|
+
var DEFAULT_DATETIME_FORMAT = "YYYY-MM-DD HH:mm";
|
|
51
|
+
var ISO_DATETIME_PATTERN = /^(\d{4})-(\d{2})-(\d{2})(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d+))?)?(Z|[+-]\d{2}:\d{2})?)?$/;
|
|
52
|
+
var FORMAT_TOKEN_PATTERN = /\[([^\]]*)\]|YYYY|SSS|YY|MM|DD|HH|hh|mm|ss|M|D|H|h|m|s|A|a/g;
|
|
53
|
+
var styles = import_el_base.css`
|
|
54
|
+
:host {
|
|
55
|
+
display: inline;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
:host([hidden]) {
|
|
59
|
+
display: none;
|
|
60
|
+
}
|
|
61
|
+
`;
|
|
62
|
+
function isLeapYear(year) {
|
|
63
|
+
return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
|
|
64
|
+
}
|
|
65
|
+
function daysInMonth(year, month) {
|
|
66
|
+
if (month === 2)
|
|
67
|
+
return isLeapYear(year) ? 29 : 28;
|
|
68
|
+
return [4, 6, 9, 11].includes(month) ? 30 : 31;
|
|
69
|
+
}
|
|
70
|
+
function parseIsoDateTime(value) {
|
|
71
|
+
const match = ISO_DATETIME_PATTERN.exec(value);
|
|
72
|
+
if (!match)
|
|
73
|
+
return;
|
|
74
|
+
const year = Number(match[1]);
|
|
75
|
+
const month = Number(match[2]);
|
|
76
|
+
const day = Number(match[3]);
|
|
77
|
+
const hour = Number(match[4] ?? 0);
|
|
78
|
+
const minute = Number(match[5] ?? 0);
|
|
79
|
+
const second = Number(match[6] ?? 0);
|
|
80
|
+
const millisecond = Number((match[7] ?? "").slice(0, 3).padEnd(3, "0") || 0);
|
|
81
|
+
const offset = match[8];
|
|
82
|
+
if (year < 1 || month < 1 || month > 12 || day < 1 || day > daysInMonth(year, month) || hour > 23 || minute > 59 || second > 59) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const parts = { year, month, day, hour, minute, second, millisecond };
|
|
86
|
+
if (!offset)
|
|
87
|
+
return { parts };
|
|
88
|
+
let offsetMinutes = 0;
|
|
89
|
+
if (offset !== "Z") {
|
|
90
|
+
const offsetHours = Number(offset.slice(1, 3));
|
|
91
|
+
const offsetRemainder = Number(offset.slice(4, 6));
|
|
92
|
+
if (offsetHours > 23 || offsetRemainder > 59)
|
|
93
|
+
return;
|
|
94
|
+
const direction = offset[0] === "+" ? 1 : -1;
|
|
95
|
+
offsetMinutes = direction * (offsetHours * 60 + offsetRemainder);
|
|
96
|
+
}
|
|
97
|
+
const utc = new Date(0);
|
|
98
|
+
utc.setUTCFullYear(year, month - 1, day);
|
|
99
|
+
utc.setUTCHours(hour, minute, second, millisecond);
|
|
100
|
+
return {
|
|
101
|
+
parts,
|
|
102
|
+
instant: new Date(utc.getTime() - offsetMinutes * 60000)
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
function isValidTimeZone(timeZone) {
|
|
106
|
+
if (!timeZone)
|
|
107
|
+
return true;
|
|
108
|
+
try {
|
|
109
|
+
new Intl.DateTimeFormat("en-US", { timeZone }).format();
|
|
110
|
+
return true;
|
|
111
|
+
} catch {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function partsForInstant(date, timeZone) {
|
|
116
|
+
if (!timeZone) {
|
|
117
|
+
return {
|
|
118
|
+
year: date.getFullYear(),
|
|
119
|
+
month: date.getMonth() + 1,
|
|
120
|
+
day: date.getDate(),
|
|
121
|
+
hour: date.getHours(),
|
|
122
|
+
minute: date.getMinutes(),
|
|
123
|
+
second: date.getSeconds(),
|
|
124
|
+
millisecond: date.getMilliseconds()
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
try {
|
|
128
|
+
const parts = new Intl.DateTimeFormat("en-US-u-ca-gregory-nu-latn", {
|
|
129
|
+
timeZone,
|
|
130
|
+
year: "numeric",
|
|
131
|
+
month: "2-digit",
|
|
132
|
+
day: "2-digit",
|
|
133
|
+
hour: "2-digit",
|
|
134
|
+
minute: "2-digit",
|
|
135
|
+
second: "2-digit",
|
|
136
|
+
hourCycle: "h23"
|
|
137
|
+
}).formatToParts(date);
|
|
138
|
+
const values = new Map(parts.map(({ type, value }) => [type, value]));
|
|
139
|
+
return {
|
|
140
|
+
year: Number(values.get("year")),
|
|
141
|
+
month: Number(values.get("month")),
|
|
142
|
+
day: Number(values.get("day")),
|
|
143
|
+
hour: Number(values.get("hour")),
|
|
144
|
+
minute: Number(values.get("minute")),
|
|
145
|
+
second: Number(values.get("second")),
|
|
146
|
+
millisecond: date.getMilliseconds()
|
|
147
|
+
};
|
|
148
|
+
} catch {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
function formatDateTime(parts, format) {
|
|
153
|
+
const hour12 = parts.hour % 12 || 12;
|
|
154
|
+
const meridiem = parts.hour < 12 ? "AM" : "PM";
|
|
155
|
+
const tokens = {
|
|
156
|
+
YYYY: String(parts.year).padStart(4, "0"),
|
|
157
|
+
YY: String(parts.year % 100).padStart(2, "0"),
|
|
158
|
+
M: String(parts.month),
|
|
159
|
+
MM: String(parts.month).padStart(2, "0"),
|
|
160
|
+
D: String(parts.day),
|
|
161
|
+
DD: String(parts.day).padStart(2, "0"),
|
|
162
|
+
H: String(parts.hour),
|
|
163
|
+
HH: String(parts.hour).padStart(2, "0"),
|
|
164
|
+
h: String(hour12),
|
|
165
|
+
hh: String(hour12).padStart(2, "0"),
|
|
166
|
+
m: String(parts.minute),
|
|
167
|
+
mm: String(parts.minute).padStart(2, "0"),
|
|
168
|
+
s: String(parts.second),
|
|
169
|
+
ss: String(parts.second).padStart(2, "0"),
|
|
170
|
+
SSS: String(parts.millisecond).padStart(3, "0"),
|
|
171
|
+
A: meridiem,
|
|
172
|
+
a: meridiem.toLowerCase()
|
|
173
|
+
};
|
|
174
|
+
return format.replace(FORMAT_TOKEN_PATTERN, (match, literal) => literal ?? tokens[match] ?? match);
|
|
175
|
+
}
|
|
176
|
+
function escapeHtml(value) {
|
|
177
|
+
const entities = {
|
|
178
|
+
"&": "&",
|
|
179
|
+
"<": "<",
|
|
180
|
+
">": ">",
|
|
181
|
+
'"': """,
|
|
182
|
+
"'": "'"
|
|
183
|
+
};
|
|
184
|
+
return value.replace(/[&<>"']/g, (character) => entities[character]);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
class ElDmDatetime extends import_el_base.BaseElement {
|
|
188
|
+
static properties = {
|
|
189
|
+
value: { type: String, reflect: true, default: "" },
|
|
190
|
+
format: { type: String, reflect: true, default: DEFAULT_DATETIME_FORMAT },
|
|
191
|
+
timeZone: { type: String, reflect: true, default: "" }
|
|
192
|
+
};
|
|
193
|
+
constructor() {
|
|
194
|
+
super();
|
|
195
|
+
this.attachStyles(styles);
|
|
196
|
+
}
|
|
197
|
+
render() {
|
|
198
|
+
const value = this.value ?? "";
|
|
199
|
+
const format = this.format ?? DEFAULT_DATETIME_FORMAT;
|
|
200
|
+
const timeZone = this.timeZone ?? "";
|
|
201
|
+
const parsed = value ? parseIsoDateTime(value) : undefined;
|
|
202
|
+
if (!parsed || !isValidTimeZone(timeZone)) {
|
|
203
|
+
return '<time part="time"></time>';
|
|
204
|
+
}
|
|
205
|
+
const parts = parsed.instant ? partsForInstant(parsed.instant, timeZone) : parsed.parts;
|
|
206
|
+
if (!parts)
|
|
207
|
+
return '<time part="time"></time>';
|
|
208
|
+
return `<time part="time" datetime="${escapeHtml(value)}">${escapeHtml(formatDateTime(parts, format))}</time>`;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// src/index.ts
|
|
213
|
+
function register() {
|
|
214
|
+
if (!customElements.get("el-dm-datetime")) {
|
|
215
|
+
customElements.define("el-dm-datetime", ElDmDatetime);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// src/register.ts
|
|
220
|
+
register();
|
|
221
|
+
|
|
222
|
+
//# debugId=602D423238F52C4464756E2164756E21
|
|
223
|
+
//# sourceMappingURL=register.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/el-dm-datetime.ts", "../../src/index.ts", "../../src/register.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import { BaseElement, css } from '@duskmoon-dev/el-base';\n\nexport const DEFAULT_DATETIME_FORMAT = 'YYYY-MM-DD HH:mm';\n\ninterface DateTimeParts {\n year: number;\n month: number;\n day: number;\n hour: number;\n minute: number;\n second: number;\n millisecond: number;\n}\n\ninterface ParsedDateTime {\n parts: DateTimeParts;\n instant?: Date;\n}\n\nconst ISO_DATETIME_PATTERN =\n /^(\\d{4})-(\\d{2})-(\\d{2})(?:T(\\d{2}):(\\d{2})(?::(\\d{2})(?:\\.(\\d+))?)?(Z|[+-]\\d{2}:\\d{2})?)?$/;\nconst FORMAT_TOKEN_PATTERN = /\\[([^\\]]*)\\]|YYYY|SSS|YY|MM|DD|HH|hh|mm|ss|M|D|H|h|m|s|A|a/g;\n\nconst styles = css`\n :host {\n display: inline;\n }\n\n :host([hidden]) {\n display: none;\n }\n`;\n\nfunction isLeapYear(year: number): boolean {\n return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);\n}\n\nfunction daysInMonth(year: number, month: number): number {\n if (month === 2) return isLeapYear(year) ? 29 : 28;\n return [4, 6, 9, 11].includes(month) ? 30 : 31;\n}\n\nfunction parseIsoDateTime(value: string): ParsedDateTime | undefined {\n const match = ISO_DATETIME_PATTERN.exec(value);\n if (!match) return undefined;\n\n const year = Number(match[1]);\n const month = Number(match[2]);\n const day = Number(match[3]);\n const hour = Number(match[4] ?? 0);\n const minute = Number(match[5] ?? 0);\n const second = Number(match[6] ?? 0);\n const millisecond = Number((match[7] ?? '').slice(0, 3).padEnd(3, '0') || 0);\n const offset = match[8];\n\n if (\n year < 1 ||\n month < 1 ||\n month > 12 ||\n day < 1 ||\n day > daysInMonth(year, month) ||\n hour > 23 ||\n minute > 59 ||\n second > 59\n ) {\n return undefined;\n }\n\n const parts = { year, month, day, hour, minute, second, millisecond };\n if (!offset) return { parts };\n\n let offsetMinutes = 0;\n if (offset !== 'Z') {\n const offsetHours = Number(offset.slice(1, 3));\n const offsetRemainder = Number(offset.slice(4, 6));\n if (offsetHours > 23 || offsetRemainder > 59) return undefined;\n\n const direction = offset[0] === '+' ? 1 : -1;\n offsetMinutes = direction * (offsetHours * 60 + offsetRemainder);\n }\n\n const utc = new Date(0);\n utc.setUTCFullYear(year, month - 1, day);\n utc.setUTCHours(hour, minute, second, millisecond);\n\n return {\n parts,\n instant: new Date(utc.getTime() - offsetMinutes * 60_000),\n };\n}\n\nfunction isValidTimeZone(timeZone: string): boolean {\n if (!timeZone) return true;\n\n try {\n new Intl.DateTimeFormat('en-US', { timeZone }).format();\n return true;\n } catch {\n return false;\n }\n}\n\nfunction partsForInstant(date: Date, timeZone: string): DateTimeParts | undefined {\n if (!timeZone) {\n return {\n year: date.getFullYear(),\n month: date.getMonth() + 1,\n day: date.getDate(),\n hour: date.getHours(),\n minute: date.getMinutes(),\n second: date.getSeconds(),\n millisecond: date.getMilliseconds(),\n };\n }\n\n try {\n const parts = new Intl.DateTimeFormat('en-US-u-ca-gregory-nu-latn', {\n timeZone,\n year: 'numeric',\n month: '2-digit',\n day: '2-digit',\n hour: '2-digit',\n minute: '2-digit',\n second: '2-digit',\n hourCycle: 'h23',\n }).formatToParts(date);\n const values = new Map(parts.map(({ type, value }) => [type, value]));\n\n return {\n year: Number(values.get('year')),\n month: Number(values.get('month')),\n day: Number(values.get('day')),\n hour: Number(values.get('hour')),\n minute: Number(values.get('minute')),\n second: Number(values.get('second')),\n millisecond: date.getMilliseconds(),\n };\n } catch {\n return undefined;\n }\n}\n\nfunction formatDateTime(parts: DateTimeParts, format: string): string {\n const hour12 = parts.hour % 12 || 12;\n const meridiem = parts.hour < 12 ? 'AM' : 'PM';\n const tokens: Record<string, string> = {\n YYYY: String(parts.year).padStart(4, '0'),\n YY: String(parts.year % 100).padStart(2, '0'),\n M: String(parts.month),\n MM: String(parts.month).padStart(2, '0'),\n D: String(parts.day),\n DD: String(parts.day).padStart(2, '0'),\n H: String(parts.hour),\n HH: String(parts.hour).padStart(2, '0'),\n h: String(hour12),\n hh: String(hour12).padStart(2, '0'),\n m: String(parts.minute),\n mm: String(parts.minute).padStart(2, '0'),\n s: String(parts.second),\n ss: String(parts.second).padStart(2, '0'),\n SSS: String(parts.millisecond).padStart(3, '0'),\n A: meridiem,\n a: meridiem.toLowerCase(),\n };\n\n return format.replace(\n FORMAT_TOKEN_PATTERN,\n (match: string, literal: string | undefined) => literal ?? tokens[match] ?? match,\n );\n}\n\nfunction escapeHtml(value: string): string {\n const entities: Record<string, string> = {\n '&': '&',\n '<': '<',\n '>': '>',\n '\"': '"',\n \"'\": ''',\n };\n\n return value.replace(/[&<>\"']/g, (character) => entities[character]);\n}\n\n/** Display an ISO date or datetime using a token-based format. */\nexport class ElDmDatetime extends BaseElement {\n static properties = {\n value: { type: String, reflect: true, default: '' },\n format: { type: String, reflect: true, default: DEFAULT_DATETIME_FORMAT },\n timeZone: { type: String, reflect: true, default: '' },\n };\n\n declare value: string;\n declare format: string;\n declare timeZone: string;\n\n constructor() {\n super();\n this.attachStyles(styles);\n }\n\n protected render(): string {\n const value = this.value ?? '';\n const format = this.format ?? DEFAULT_DATETIME_FORMAT;\n const timeZone = this.timeZone ?? '';\n const parsed = value ? parseIsoDateTime(value) : undefined;\n\n if (!parsed || !isValidTimeZone(timeZone)) {\n return '<time part=\"time\"></time>';\n }\n\n const parts = parsed.instant ? partsForInstant(parsed.instant, timeZone) : parsed.parts;\n if (!parts) return '<time part=\"time\"></time>';\n\n return `<time part=\"time\" datetime=\"${escapeHtml(value)}\">${escapeHtml(formatDateTime(parts, format))}</time>`;\n }\n}\n",
|
|
6
|
+
"/**\n * @duskmoon-dev/el-datetime\n *\n * Display-only ISO date and datetime formatting custom element.\n */\n\nimport { ElDmDatetime } from './el-dm-datetime.js';\n\nexport { DEFAULT_DATETIME_FORMAT, ElDmDatetime } from './el-dm-datetime.js';\n\n/** Register the el-dm-datetime custom element. */\nexport function register(): void {\n if (!customElements.get('el-dm-datetime')) {\n customElements.define('el-dm-datetime', ElDmDatetime);\n }\n}\n",
|
|
7
|
+
"import { register } from './index.js';\n\nregister();\n"
|
|
8
|
+
],
|
|
9
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAiC,IAAjC;AAEO,IAAM,0BAA0B;AAiBvC,IAAM,uBACJ;AACF,IAAM,uBAAuB;AAE7B,IAAM,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUf,SAAS,UAAU,CAAC,MAAuB;AAAA,EACzC,OAAO,OAAO,MAAM,MAAM,OAAO,QAAQ,KAAK,OAAO,QAAQ;AAAA;AAG/D,SAAS,WAAW,CAAC,MAAc,OAAuB;AAAA,EACxD,IAAI,UAAU;AAAA,IAAG,OAAO,WAAW,IAAI,IAAI,KAAK;AAAA,EAChD,OAAO,CAAC,GAAG,GAAG,GAAG,EAAE,EAAE,SAAS,KAAK,IAAI,KAAK;AAAA;AAG9C,SAAS,gBAAgB,CAAC,OAA2C;AAAA,EACnE,MAAM,QAAQ,qBAAqB,KAAK,KAAK;AAAA,EAC7C,IAAI,CAAC;AAAA,IAAO;AAAA,EAEZ,MAAM,OAAO,OAAO,MAAM,EAAE;AAAA,EAC5B,MAAM,QAAQ,OAAO,MAAM,EAAE;AAAA,EAC7B,MAAM,MAAM,OAAO,MAAM,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_DATETIME_PATTERN = /^(\d{4})-(\d{2})-(\d{2})(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d+))?)?(Z|[+-]\d{2}:\d{2})?)?$/;
|
|
5
|
+
var FORMAT_TOKEN_PATTERN = /\[([^\]]*)\]|YYYY|SSS|YY|MM|DD|HH|hh|mm|ss|M|D|H|h|m|s|A|a/g;
|
|
6
|
+
var styles = css`
|
|
7
|
+
:host {
|
|
8
|
+
display: inline;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
:host([hidden]) {
|
|
12
|
+
display: none;
|
|
13
|
+
}
|
|
14
|
+
`;
|
|
15
|
+
function isLeapYear(year) {
|
|
16
|
+
return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
|
|
17
|
+
}
|
|
18
|
+
function daysInMonth(year, month) {
|
|
19
|
+
if (month === 2)
|
|
20
|
+
return isLeapYear(year) ? 29 : 28;
|
|
21
|
+
return [4, 6, 9, 11].includes(month) ? 30 : 31;
|
|
22
|
+
}
|
|
23
|
+
function parseIsoDateTime(value) {
|
|
24
|
+
const match = ISO_DATETIME_PATTERN.exec(value);
|
|
25
|
+
if (!match)
|
|
26
|
+
return;
|
|
27
|
+
const year = Number(match[1]);
|
|
28
|
+
const month = Number(match[2]);
|
|
29
|
+
const day = Number(match[3]);
|
|
30
|
+
const hour = Number(match[4] ?? 0);
|
|
31
|
+
const minute = Number(match[5] ?? 0);
|
|
32
|
+
const second = Number(match[6] ?? 0);
|
|
33
|
+
const millisecond = Number((match[7] ?? "").slice(0, 3).padEnd(3, "0") || 0);
|
|
34
|
+
const offset = match[8];
|
|
35
|
+
if (year < 1 || month < 1 || month > 12 || day < 1 || day > daysInMonth(year, month) || hour > 23 || minute > 59 || second > 59) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const parts = { year, month, day, hour, minute, second, millisecond };
|
|
39
|
+
if (!offset)
|
|
40
|
+
return { parts };
|
|
41
|
+
let offsetMinutes = 0;
|
|
42
|
+
if (offset !== "Z") {
|
|
43
|
+
const offsetHours = Number(offset.slice(1, 3));
|
|
44
|
+
const offsetRemainder = Number(offset.slice(4, 6));
|
|
45
|
+
if (offsetHours > 23 || offsetRemainder > 59)
|
|
46
|
+
return;
|
|
47
|
+
const direction = offset[0] === "+" ? 1 : -1;
|
|
48
|
+
offsetMinutes = direction * (offsetHours * 60 + offsetRemainder);
|
|
49
|
+
}
|
|
50
|
+
const utc = new Date(0);
|
|
51
|
+
utc.setUTCFullYear(year, month - 1, day);
|
|
52
|
+
utc.setUTCHours(hour, minute, second, millisecond);
|
|
53
|
+
return {
|
|
54
|
+
parts,
|
|
55
|
+
instant: new Date(utc.getTime() - offsetMinutes * 60000)
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function isValidTimeZone(timeZone) {
|
|
59
|
+
if (!timeZone)
|
|
60
|
+
return true;
|
|
61
|
+
try {
|
|
62
|
+
new Intl.DateTimeFormat("en-US", { timeZone }).format();
|
|
63
|
+
return true;
|
|
64
|
+
} catch {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function partsForInstant(date, timeZone) {
|
|
69
|
+
if (!timeZone) {
|
|
70
|
+
return {
|
|
71
|
+
year: date.getFullYear(),
|
|
72
|
+
month: date.getMonth() + 1,
|
|
73
|
+
day: date.getDate(),
|
|
74
|
+
hour: date.getHours(),
|
|
75
|
+
minute: date.getMinutes(),
|
|
76
|
+
second: date.getSeconds(),
|
|
77
|
+
millisecond: date.getMilliseconds()
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
const parts = new Intl.DateTimeFormat("en-US-u-ca-gregory-nu-latn", {
|
|
82
|
+
timeZone,
|
|
83
|
+
year: "numeric",
|
|
84
|
+
month: "2-digit",
|
|
85
|
+
day: "2-digit",
|
|
86
|
+
hour: "2-digit",
|
|
87
|
+
minute: "2-digit",
|
|
88
|
+
second: "2-digit",
|
|
89
|
+
hourCycle: "h23"
|
|
90
|
+
}).formatToParts(date);
|
|
91
|
+
const values = new Map(parts.map(({ type, value }) => [type, value]));
|
|
92
|
+
return {
|
|
93
|
+
year: Number(values.get("year")),
|
|
94
|
+
month: Number(values.get("month")),
|
|
95
|
+
day: Number(values.get("day")),
|
|
96
|
+
hour: Number(values.get("hour")),
|
|
97
|
+
minute: Number(values.get("minute")),
|
|
98
|
+
second: Number(values.get("second")),
|
|
99
|
+
millisecond: date.getMilliseconds()
|
|
100
|
+
};
|
|
101
|
+
} catch {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
function formatDateTime(parts, format) {
|
|
106
|
+
const hour12 = parts.hour % 12 || 12;
|
|
107
|
+
const meridiem = parts.hour < 12 ? "AM" : "PM";
|
|
108
|
+
const tokens = {
|
|
109
|
+
YYYY: String(parts.year).padStart(4, "0"),
|
|
110
|
+
YY: String(parts.year % 100).padStart(2, "0"),
|
|
111
|
+
M: String(parts.month),
|
|
112
|
+
MM: String(parts.month).padStart(2, "0"),
|
|
113
|
+
D: String(parts.day),
|
|
114
|
+
DD: String(parts.day).padStart(2, "0"),
|
|
115
|
+
H: String(parts.hour),
|
|
116
|
+
HH: String(parts.hour).padStart(2, "0"),
|
|
117
|
+
h: String(hour12),
|
|
118
|
+
hh: String(hour12).padStart(2, "0"),
|
|
119
|
+
m: String(parts.minute),
|
|
120
|
+
mm: String(parts.minute).padStart(2, "0"),
|
|
121
|
+
s: String(parts.second),
|
|
122
|
+
ss: String(parts.second).padStart(2, "0"),
|
|
123
|
+
SSS: String(parts.millisecond).padStart(3, "0"),
|
|
124
|
+
A: meridiem,
|
|
125
|
+
a: meridiem.toLowerCase()
|
|
126
|
+
};
|
|
127
|
+
return format.replace(FORMAT_TOKEN_PATTERN, (match, literal) => literal ?? tokens[match] ?? match);
|
|
128
|
+
}
|
|
129
|
+
function escapeHtml(value) {
|
|
130
|
+
const entities = {
|
|
131
|
+
"&": "&",
|
|
132
|
+
"<": "<",
|
|
133
|
+
">": ">",
|
|
134
|
+
'"': """,
|
|
135
|
+
"'": "'"
|
|
136
|
+
};
|
|
137
|
+
return value.replace(/[&<>"']/g, (character) => entities[character]);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
class ElDmDatetime extends BaseElement {
|
|
141
|
+
static properties = {
|
|
142
|
+
value: { type: String, reflect: true, default: "" },
|
|
143
|
+
format: { type: String, reflect: true, default: DEFAULT_DATETIME_FORMAT },
|
|
144
|
+
timeZone: { type: String, reflect: true, default: "" }
|
|
145
|
+
};
|
|
146
|
+
constructor() {
|
|
147
|
+
super();
|
|
148
|
+
this.attachStyles(styles);
|
|
149
|
+
}
|
|
150
|
+
render() {
|
|
151
|
+
const value = this.value ?? "";
|
|
152
|
+
const format = this.format ?? DEFAULT_DATETIME_FORMAT;
|
|
153
|
+
const timeZone = this.timeZone ?? "";
|
|
154
|
+
const parsed = value ? parseIsoDateTime(value) : undefined;
|
|
155
|
+
if (!parsed || !isValidTimeZone(timeZone)) {
|
|
156
|
+
return '<time part="time"></time>';
|
|
157
|
+
}
|
|
158
|
+
const parts = parsed.instant ? partsForInstant(parsed.instant, timeZone) : parsed.parts;
|
|
159
|
+
if (!parts)
|
|
160
|
+
return '<time part="time"></time>';
|
|
161
|
+
return `<time part="time" datetime="${escapeHtml(value)}">${escapeHtml(formatDateTime(parts, format))}</time>`;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// src/index.ts
|
|
166
|
+
function register() {
|
|
167
|
+
if (!customElements.get("el-dm-datetime")) {
|
|
168
|
+
customElements.define("el-dm-datetime", ElDmDatetime);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
export {
|
|
172
|
+
register,
|
|
173
|
+
ElDmDatetime,
|
|
174
|
+
DEFAULT_DATETIME_FORMAT
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
//# debugId=902EAFAA92AFC32964756E2164756E21
|
|
178
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/el-dm-datetime.ts", "../../src/index.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import { BaseElement, css } from '@duskmoon-dev/el-base';\n\nexport const DEFAULT_DATETIME_FORMAT = 'YYYY-MM-DD HH:mm';\n\ninterface DateTimeParts {\n year: number;\n month: number;\n day: number;\n hour: number;\n minute: number;\n second: number;\n millisecond: number;\n}\n\ninterface ParsedDateTime {\n parts: DateTimeParts;\n instant?: Date;\n}\n\nconst ISO_DATETIME_PATTERN =\n /^(\\d{4})-(\\d{2})-(\\d{2})(?:T(\\d{2}):(\\d{2})(?::(\\d{2})(?:\\.(\\d+))?)?(Z|[+-]\\d{2}:\\d{2})?)?$/;\nconst FORMAT_TOKEN_PATTERN = /\\[([^\\]]*)\\]|YYYY|SSS|YY|MM|DD|HH|hh|mm|ss|M|D|H|h|m|s|A|a/g;\n\nconst styles = css`\n :host {\n display: inline;\n }\n\n :host([hidden]) {\n display: none;\n }\n`;\n\nfunction isLeapYear(year: number): boolean {\n return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);\n}\n\nfunction daysInMonth(year: number, month: number): number {\n if (month === 2) return isLeapYear(year) ? 29 : 28;\n return [4, 6, 9, 11].includes(month) ? 30 : 31;\n}\n\nfunction parseIsoDateTime(value: string): ParsedDateTime | undefined {\n const match = ISO_DATETIME_PATTERN.exec(value);\n if (!match) return undefined;\n\n const year = Number(match[1]);\n const month = Number(match[2]);\n const day = Number(match[3]);\n const hour = Number(match[4] ?? 0);\n const minute = Number(match[5] ?? 0);\n const second = Number(match[6] ?? 0);\n const millisecond = Number((match[7] ?? '').slice(0, 3).padEnd(3, '0') || 0);\n const offset = match[8];\n\n if (\n year < 1 ||\n month < 1 ||\n month > 12 ||\n day < 1 ||\n day > daysInMonth(year, month) ||\n hour > 23 ||\n minute > 59 ||\n second > 59\n ) {\n return undefined;\n }\n\n const parts = { year, month, day, hour, minute, second, millisecond };\n if (!offset) return { parts };\n\n let offsetMinutes = 0;\n if (offset !== 'Z') {\n const offsetHours = Number(offset.slice(1, 3));\n const offsetRemainder = Number(offset.slice(4, 6));\n if (offsetHours > 23 || offsetRemainder > 59) return undefined;\n\n const direction = offset[0] === '+' ? 1 : -1;\n offsetMinutes = direction * (offsetHours * 60 + offsetRemainder);\n }\n\n const utc = new Date(0);\n utc.setUTCFullYear(year, month - 1, day);\n utc.setUTCHours(hour, minute, second, millisecond);\n\n return {\n parts,\n instant: new Date(utc.getTime() - offsetMinutes * 60_000),\n };\n}\n\nfunction isValidTimeZone(timeZone: string): boolean {\n if (!timeZone) return true;\n\n try {\n new Intl.DateTimeFormat('en-US', { timeZone }).format();\n return true;\n } catch {\n return false;\n }\n}\n\nfunction partsForInstant(date: Date, timeZone: string): DateTimeParts | undefined {\n if (!timeZone) {\n return {\n year: date.getFullYear(),\n month: date.getMonth() + 1,\n day: date.getDate(),\n hour: date.getHours(),\n minute: date.getMinutes(),\n second: date.getSeconds(),\n millisecond: date.getMilliseconds(),\n };\n }\n\n try {\n const parts = new Intl.DateTimeFormat('en-US-u-ca-gregory-nu-latn', {\n timeZone,\n year: 'numeric',\n month: '2-digit',\n day: '2-digit',\n hour: '2-digit',\n minute: '2-digit',\n second: '2-digit',\n hourCycle: 'h23',\n }).formatToParts(date);\n const values = new Map(parts.map(({ type, value }) => [type, value]));\n\n return {\n year: Number(values.get('year')),\n month: Number(values.get('month')),\n day: Number(values.get('day')),\n hour: Number(values.get('hour')),\n minute: Number(values.get('minute')),\n second: Number(values.get('second')),\n millisecond: date.getMilliseconds(),\n };\n } catch {\n return undefined;\n }\n}\n\nfunction formatDateTime(parts: DateTimeParts, format: string): string {\n const hour12 = parts.hour % 12 || 12;\n const meridiem = parts.hour < 12 ? 'AM' : 'PM';\n const tokens: Record<string, string> = {\n YYYY: String(parts.year).padStart(4, '0'),\n YY: String(parts.year % 100).padStart(2, '0'),\n M: String(parts.month),\n MM: String(parts.month).padStart(2, '0'),\n D: String(parts.day),\n DD: String(parts.day).padStart(2, '0'),\n H: String(parts.hour),\n HH: String(parts.hour).padStart(2, '0'),\n h: String(hour12),\n hh: String(hour12).padStart(2, '0'),\n m: String(parts.minute),\n mm: String(parts.minute).padStart(2, '0'),\n s: String(parts.second),\n ss: String(parts.second).padStart(2, '0'),\n SSS: String(parts.millisecond).padStart(3, '0'),\n A: meridiem,\n a: meridiem.toLowerCase(),\n };\n\n return format.replace(\n FORMAT_TOKEN_PATTERN,\n (match: string, literal: string | undefined) => literal ?? tokens[match] ?? match,\n );\n}\n\nfunction escapeHtml(value: string): string {\n const entities: Record<string, string> = {\n '&': '&',\n '<': '<',\n '>': '>',\n '\"': '"',\n \"'\": ''',\n };\n\n return value.replace(/[&<>\"']/g, (character) => entities[character]);\n}\n\n/** Display an ISO date or datetime using a token-based format. */\nexport class ElDmDatetime extends BaseElement {\n static properties = {\n value: { type: String, reflect: true, default: '' },\n format: { type: String, reflect: true, default: DEFAULT_DATETIME_FORMAT },\n timeZone: { type: String, reflect: true, default: '' },\n };\n\n declare value: string;\n declare format: string;\n declare timeZone: string;\n\n constructor() {\n super();\n this.attachStyles(styles);\n }\n\n protected render(): string {\n const value = this.value ?? '';\n const format = this.format ?? DEFAULT_DATETIME_FORMAT;\n const timeZone = this.timeZone ?? '';\n const parsed = value ? parseIsoDateTime(value) : undefined;\n\n if (!parsed || !isValidTimeZone(timeZone)) {\n return '<time part=\"time\"></time>';\n }\n\n const parts = parsed.instant ? partsForInstant(parsed.instant, timeZone) : parsed.parts;\n if (!parts) return '<time part=\"time\"></time>';\n\n return `<time part=\"time\" datetime=\"${escapeHtml(value)}\">${escapeHtml(formatDateTime(parts, format))}</time>`;\n }\n}\n",
|
|
6
|
+
"/**\n * @duskmoon-dev/el-datetime\n *\n * Display-only ISO date and datetime formatting custom element.\n */\n\nimport { ElDmDatetime } from './el-dm-datetime.js';\n\nexport { DEFAULT_DATETIME_FORMAT, ElDmDatetime } from './el-dm-datetime.js';\n\n/** Register the el-dm-datetime custom element. */\nexport function register(): void {\n if (!customElements.get('el-dm-datetime')) {\n customElements.define('el-dm-datetime', ElDmDatetime);\n }\n}\n"
|
|
7
|
+
],
|
|
8
|
+
"mappings": ";AAAA;AAEO,IAAM,0BAA0B;AAiBvC,IAAM,uBACJ;AACF,IAAM,uBAAuB;AAE7B,IAAM,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUf,SAAS,UAAU,CAAC,MAAuB;AAAA,EACzC,OAAO,OAAO,MAAM,MAAM,OAAO,QAAQ,KAAK,OAAO,QAAQ;AAAA;AAG/D,SAAS,WAAW,CAAC,MAAc,OAAuB;AAAA,EACxD,IAAI,UAAU;AAAA,IAAG,OAAO,WAAW,IAAI,IAAI,KAAK;AAAA,EAChD,OAAO,CAAC,GAAG,GAAG,GAAG,EAAE,EAAE,SAAS,KAAK,IAAI,KAAK;AAAA;AAG9C,SAAS,gBAAgB,CAAC,OAA2C;AAAA,EACnE,MAAM,QAAQ,qBAAqB,KAAK,KAAK;AAAA,EAC7C,IAAI,CAAC;AAAA,IAAO;AAAA,EAEZ,MAAM,OAAO,OAAO,MAAM,EAAE;AAAA,EAC5B,MAAM,QAAQ,OAAO,MAAM,EAAE;AAAA,EAC7B,MAAM,MAAM,OAAO,MAAM,EAAE;AAAA,EAC3B,MAAM,OAAO,OAAO,MAAM,MAAM,CAAC;AAAA,EACjC,MAAM,SAAS,OAAO,MAAM,MAAM,CAAC;AAAA,EACnC,MAAM,SAAS,OAAO,MAAM,MAAM,CAAC;AAAA,EACnC,MAAM,cAAc,QAAQ,MAAM,MAAM,IAAI,MAAM,GAAG,CAAC,EAAE,OAAO,GAAG,GAAG,KAAK,CAAC;AAAA,EAC3E,MAAM,SAAS,MAAM;AAAA,EAErB,IACE,OAAO,KACP,QAAQ,KACR,QAAQ,MACR,MAAM,KACN,MAAM,YAAY,MAAM,KAAK,KAC7B,OAAO,MACP,SAAS,MAC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,SAAS;AAAA,IAC5B,MAAM,SAAS,KAAK,UAAU;AAAA,IAC9B,MAAM,WAAW,KAAK,YAAY;AAAA,IAClC,MAAM,SAAS,QAAQ,iBAAiB,KAAK,IAAI;AAAA,IAEjD,IAAI,CAAC,UAAU,CAAC,gBAAgB,QAAQ,GAAG;AAAA,MACzC,OAAO;AAAA,IACT;AAAA,IAEA,MAAM,QAAQ,OAAO,UAAU,gBAAgB,OAAO,SAAS,QAAQ,IAAI,OAAO;AAAA,IAClF,IAAI,CAAC;AAAA,MAAO,OAAO;AAAA,IAEnB,OAAO,+BAA+B,WAAW,KAAK,MAAM,WAAW,eAAe,OAAO,MAAM,CAAC;AAAA;AAExG;;;AC5MO,SAAS,QAAQ,GAAS;AAAA,EAC/B,IAAI,CAAC,eAAe,IAAI,gBAAgB,GAAG;AAAA,IACzC,eAAe,OAAO,kBAAkB,YAAY;AAAA,EACtD;AAAA;",
|
|
9
|
+
"debugId": "902EAFAA92AFC32964756E2164756E21",
|
|
10
|
+
"names": []
|
|
11
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
// src/el-dm-datetime.ts
|
|
2
|
+
import { BaseElement, css } from "@duskmoon-dev/el-base";
|
|
3
|
+
var DEFAULT_DATETIME_FORMAT = "YYYY-MM-DD HH:mm";
|
|
4
|
+
var ISO_DATETIME_PATTERN = /^(\d{4})-(\d{2})-(\d{2})(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d+))?)?(Z|[+-]\d{2}:\d{2})?)?$/;
|
|
5
|
+
var FORMAT_TOKEN_PATTERN = /\[([^\]]*)\]|YYYY|SSS|YY|MM|DD|HH|hh|mm|ss|M|D|H|h|m|s|A|a/g;
|
|
6
|
+
var styles = css`
|
|
7
|
+
:host {
|
|
8
|
+
display: inline;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
:host([hidden]) {
|
|
12
|
+
display: none;
|
|
13
|
+
}
|
|
14
|
+
`;
|
|
15
|
+
function isLeapYear(year) {
|
|
16
|
+
return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
|
|
17
|
+
}
|
|
18
|
+
function daysInMonth(year, month) {
|
|
19
|
+
if (month === 2)
|
|
20
|
+
return isLeapYear(year) ? 29 : 28;
|
|
21
|
+
return [4, 6, 9, 11].includes(month) ? 30 : 31;
|
|
22
|
+
}
|
|
23
|
+
function parseIsoDateTime(value) {
|
|
24
|
+
const match = ISO_DATETIME_PATTERN.exec(value);
|
|
25
|
+
if (!match)
|
|
26
|
+
return;
|
|
27
|
+
const year = Number(match[1]);
|
|
28
|
+
const month = Number(match[2]);
|
|
29
|
+
const day = Number(match[3]);
|
|
30
|
+
const hour = Number(match[4] ?? 0);
|
|
31
|
+
const minute = Number(match[5] ?? 0);
|
|
32
|
+
const second = Number(match[6] ?? 0);
|
|
33
|
+
const millisecond = Number((match[7] ?? "").slice(0, 3).padEnd(3, "0") || 0);
|
|
34
|
+
const offset = match[8];
|
|
35
|
+
if (year < 1 || month < 1 || month > 12 || day < 1 || day > daysInMonth(year, month) || hour > 23 || minute > 59 || second > 59) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const parts = { year, month, day, hour, minute, second, millisecond };
|
|
39
|
+
if (!offset)
|
|
40
|
+
return { parts };
|
|
41
|
+
let offsetMinutes = 0;
|
|
42
|
+
if (offset !== "Z") {
|
|
43
|
+
const offsetHours = Number(offset.slice(1, 3));
|
|
44
|
+
const offsetRemainder = Number(offset.slice(4, 6));
|
|
45
|
+
if (offsetHours > 23 || offsetRemainder > 59)
|
|
46
|
+
return;
|
|
47
|
+
const direction = offset[0] === "+" ? 1 : -1;
|
|
48
|
+
offsetMinutes = direction * (offsetHours * 60 + offsetRemainder);
|
|
49
|
+
}
|
|
50
|
+
const utc = new Date(0);
|
|
51
|
+
utc.setUTCFullYear(year, month - 1, day);
|
|
52
|
+
utc.setUTCHours(hour, minute, second, millisecond);
|
|
53
|
+
return {
|
|
54
|
+
parts,
|
|
55
|
+
instant: new Date(utc.getTime() - offsetMinutes * 60000)
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function isValidTimeZone(timeZone) {
|
|
59
|
+
if (!timeZone)
|
|
60
|
+
return true;
|
|
61
|
+
try {
|
|
62
|
+
new Intl.DateTimeFormat("en-US", { timeZone }).format();
|
|
63
|
+
return true;
|
|
64
|
+
} catch {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function partsForInstant(date, timeZone) {
|
|
69
|
+
if (!timeZone) {
|
|
70
|
+
return {
|
|
71
|
+
year: date.getFullYear(),
|
|
72
|
+
month: date.getMonth() + 1,
|
|
73
|
+
day: date.getDate(),
|
|
74
|
+
hour: date.getHours(),
|
|
75
|
+
minute: date.getMinutes(),
|
|
76
|
+
second: date.getSeconds(),
|
|
77
|
+
millisecond: date.getMilliseconds()
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
const parts = new Intl.DateTimeFormat("en-US-u-ca-gregory-nu-latn", {
|
|
82
|
+
timeZone,
|
|
83
|
+
year: "numeric",
|
|
84
|
+
month: "2-digit",
|
|
85
|
+
day: "2-digit",
|
|
86
|
+
hour: "2-digit",
|
|
87
|
+
minute: "2-digit",
|
|
88
|
+
second: "2-digit",
|
|
89
|
+
hourCycle: "h23"
|
|
90
|
+
}).formatToParts(date);
|
|
91
|
+
const values = new Map(parts.map(({ type, value }) => [type, value]));
|
|
92
|
+
return {
|
|
93
|
+
year: Number(values.get("year")),
|
|
94
|
+
month: Number(values.get("month")),
|
|
95
|
+
day: Number(values.get("day")),
|
|
96
|
+
hour: Number(values.get("hour")),
|
|
97
|
+
minute: Number(values.get("minute")),
|
|
98
|
+
second: Number(values.get("second")),
|
|
99
|
+
millisecond: date.getMilliseconds()
|
|
100
|
+
};
|
|
101
|
+
} catch {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
function formatDateTime(parts, format) {
|
|
106
|
+
const hour12 = parts.hour % 12 || 12;
|
|
107
|
+
const meridiem = parts.hour < 12 ? "AM" : "PM";
|
|
108
|
+
const tokens = {
|
|
109
|
+
YYYY: String(parts.year).padStart(4, "0"),
|
|
110
|
+
YY: String(parts.year % 100).padStart(2, "0"),
|
|
111
|
+
M: String(parts.month),
|
|
112
|
+
MM: String(parts.month).padStart(2, "0"),
|
|
113
|
+
D: String(parts.day),
|
|
114
|
+
DD: String(parts.day).padStart(2, "0"),
|
|
115
|
+
H: String(parts.hour),
|
|
116
|
+
HH: String(parts.hour).padStart(2, "0"),
|
|
117
|
+
h: String(hour12),
|
|
118
|
+
hh: String(hour12).padStart(2, "0"),
|
|
119
|
+
m: String(parts.minute),
|
|
120
|
+
mm: String(parts.minute).padStart(2, "0"),
|
|
121
|
+
s: String(parts.second),
|
|
122
|
+
ss: String(parts.second).padStart(2, "0"),
|
|
123
|
+
SSS: String(parts.millisecond).padStart(3, "0"),
|
|
124
|
+
A: meridiem,
|
|
125
|
+
a: meridiem.toLowerCase()
|
|
126
|
+
};
|
|
127
|
+
return format.replace(FORMAT_TOKEN_PATTERN, (match, literal) => literal ?? tokens[match] ?? match);
|
|
128
|
+
}
|
|
129
|
+
function escapeHtml(value) {
|
|
130
|
+
const entities = {
|
|
131
|
+
"&": "&",
|
|
132
|
+
"<": "<",
|
|
133
|
+
">": ">",
|
|
134
|
+
'"': """,
|
|
135
|
+
"'": "'"
|
|
136
|
+
};
|
|
137
|
+
return value.replace(/[&<>"']/g, (character) => entities[character]);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
class ElDmDatetime extends BaseElement {
|
|
141
|
+
static properties = {
|
|
142
|
+
value: { type: String, reflect: true, default: "" },
|
|
143
|
+
format: { type: String, reflect: true, default: DEFAULT_DATETIME_FORMAT },
|
|
144
|
+
timeZone: { type: String, reflect: true, default: "" }
|
|
145
|
+
};
|
|
146
|
+
constructor() {
|
|
147
|
+
super();
|
|
148
|
+
this.attachStyles(styles);
|
|
149
|
+
}
|
|
150
|
+
render() {
|
|
151
|
+
const value = this.value ?? "";
|
|
152
|
+
const format = this.format ?? DEFAULT_DATETIME_FORMAT;
|
|
153
|
+
const timeZone = this.timeZone ?? "";
|
|
154
|
+
const parsed = value ? parseIsoDateTime(value) : undefined;
|
|
155
|
+
if (!parsed || !isValidTimeZone(timeZone)) {
|
|
156
|
+
return '<time part="time"></time>';
|
|
157
|
+
}
|
|
158
|
+
const parts = parsed.instant ? partsForInstant(parsed.instant, timeZone) : parsed.parts;
|
|
159
|
+
if (!parts)
|
|
160
|
+
return '<time part="time"></time>';
|
|
161
|
+
return `<time part="time" datetime="${escapeHtml(value)}">${escapeHtml(formatDateTime(parts, format))}</time>`;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// src/index.ts
|
|
166
|
+
function register() {
|
|
167
|
+
if (!customElements.get("el-dm-datetime")) {
|
|
168
|
+
customElements.define("el-dm-datetime", ElDmDatetime);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// src/register.ts
|
|
173
|
+
register();
|
|
174
|
+
|
|
175
|
+
//# debugId=731A53637B58714B64756E2164756E21
|
|
176
|
+
//# sourceMappingURL=register.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/el-dm-datetime.ts", "../../src/index.ts", "../../src/register.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import { BaseElement, css } from '@duskmoon-dev/el-base';\n\nexport const DEFAULT_DATETIME_FORMAT = 'YYYY-MM-DD HH:mm';\n\ninterface DateTimeParts {\n year: number;\n month: number;\n day: number;\n hour: number;\n minute: number;\n second: number;\n millisecond: number;\n}\n\ninterface ParsedDateTime {\n parts: DateTimeParts;\n instant?: Date;\n}\n\nconst ISO_DATETIME_PATTERN =\n /^(\\d{4})-(\\d{2})-(\\d{2})(?:T(\\d{2}):(\\d{2})(?::(\\d{2})(?:\\.(\\d+))?)?(Z|[+-]\\d{2}:\\d{2})?)?$/;\nconst FORMAT_TOKEN_PATTERN = /\\[([^\\]]*)\\]|YYYY|SSS|YY|MM|DD|HH|hh|mm|ss|M|D|H|h|m|s|A|a/g;\n\nconst styles = css`\n :host {\n display: inline;\n }\n\n :host([hidden]) {\n display: none;\n }\n`;\n\nfunction isLeapYear(year: number): boolean {\n return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);\n}\n\nfunction daysInMonth(year: number, month: number): number {\n if (month === 2) return isLeapYear(year) ? 29 : 28;\n return [4, 6, 9, 11].includes(month) ? 30 : 31;\n}\n\nfunction parseIsoDateTime(value: string): ParsedDateTime | undefined {\n const match = ISO_DATETIME_PATTERN.exec(value);\n if (!match) return undefined;\n\n const year = Number(match[1]);\n const month = Number(match[2]);\n const day = Number(match[3]);\n const hour = Number(match[4] ?? 0);\n const minute = Number(match[5] ?? 0);\n const second = Number(match[6] ?? 0);\n const millisecond = Number((match[7] ?? '').slice(0, 3).padEnd(3, '0') || 0);\n const offset = match[8];\n\n if (\n year < 1 ||\n month < 1 ||\n month > 12 ||\n day < 1 ||\n day > daysInMonth(year, month) ||\n hour > 23 ||\n minute > 59 ||\n second > 59\n ) {\n return undefined;\n }\n\n const parts = { year, month, day, hour, minute, second, millisecond };\n if (!offset) return { parts };\n\n let offsetMinutes = 0;\n if (offset !== 'Z') {\n const offsetHours = Number(offset.slice(1, 3));\n const offsetRemainder = Number(offset.slice(4, 6));\n if (offsetHours > 23 || offsetRemainder > 59) return undefined;\n\n const direction = offset[0] === '+' ? 1 : -1;\n offsetMinutes = direction * (offsetHours * 60 + offsetRemainder);\n }\n\n const utc = new Date(0);\n utc.setUTCFullYear(year, month - 1, day);\n utc.setUTCHours(hour, minute, second, millisecond);\n\n return {\n parts,\n instant: new Date(utc.getTime() - offsetMinutes * 60_000),\n };\n}\n\nfunction isValidTimeZone(timeZone: string): boolean {\n if (!timeZone) return true;\n\n try {\n new Intl.DateTimeFormat('en-US', { timeZone }).format();\n return true;\n } catch {\n return false;\n }\n}\n\nfunction partsForInstant(date: Date, timeZone: string): DateTimeParts | undefined {\n if (!timeZone) {\n return {\n year: date.getFullYear(),\n month: date.getMonth() + 1,\n day: date.getDate(),\n hour: date.getHours(),\n minute: date.getMinutes(),\n second: date.getSeconds(),\n millisecond: date.getMilliseconds(),\n };\n }\n\n try {\n const parts = new Intl.DateTimeFormat('en-US-u-ca-gregory-nu-latn', {\n timeZone,\n year: 'numeric',\n month: '2-digit',\n day: '2-digit',\n hour: '2-digit',\n minute: '2-digit',\n second: '2-digit',\n hourCycle: 'h23',\n }).formatToParts(date);\n const values = new Map(parts.map(({ type, value }) => [type, value]));\n\n return {\n year: Number(values.get('year')),\n month: Number(values.get('month')),\n day: Number(values.get('day')),\n hour: Number(values.get('hour')),\n minute: Number(values.get('minute')),\n second: Number(values.get('second')),\n millisecond: date.getMilliseconds(),\n };\n } catch {\n return undefined;\n }\n}\n\nfunction formatDateTime(parts: DateTimeParts, format: string): string {\n const hour12 = parts.hour % 12 || 12;\n const meridiem = parts.hour < 12 ? 'AM' : 'PM';\n const tokens: Record<string, string> = {\n YYYY: String(parts.year).padStart(4, '0'),\n YY: String(parts.year % 100).padStart(2, '0'),\n M: String(parts.month),\n MM: String(parts.month).padStart(2, '0'),\n D: String(parts.day),\n DD: String(parts.day).padStart(2, '0'),\n H: String(parts.hour),\n HH: String(parts.hour).padStart(2, '0'),\n h: String(hour12),\n hh: String(hour12).padStart(2, '0'),\n m: String(parts.minute),\n mm: String(parts.minute).padStart(2, '0'),\n s: String(parts.second),\n ss: String(parts.second).padStart(2, '0'),\n SSS: String(parts.millisecond).padStart(3, '0'),\n A: meridiem,\n a: meridiem.toLowerCase(),\n };\n\n return format.replace(\n FORMAT_TOKEN_PATTERN,\n (match: string, literal: string | undefined) => literal ?? tokens[match] ?? match,\n );\n}\n\nfunction escapeHtml(value: string): string {\n const entities: Record<string, string> = {\n '&': '&',\n '<': '<',\n '>': '>',\n '\"': '"',\n \"'\": ''',\n };\n\n return value.replace(/[&<>\"']/g, (character) => entities[character]);\n}\n\n/** Display an ISO date or datetime using a token-based format. */\nexport class ElDmDatetime extends BaseElement {\n static properties = {\n value: { type: String, reflect: true, default: '' },\n format: { type: String, reflect: true, default: DEFAULT_DATETIME_FORMAT },\n timeZone: { type: String, reflect: true, default: '' },\n };\n\n declare value: string;\n declare format: string;\n declare timeZone: string;\n\n constructor() {\n super();\n this.attachStyles(styles);\n }\n\n protected render(): string {\n const value = this.value ?? '';\n const format = this.format ?? DEFAULT_DATETIME_FORMAT;\n const timeZone = this.timeZone ?? '';\n const parsed = value ? parseIsoDateTime(value) : undefined;\n\n if (!parsed || !isValidTimeZone(timeZone)) {\n return '<time part=\"time\"></time>';\n }\n\n const parts = parsed.instant ? partsForInstant(parsed.instant, timeZone) : parsed.parts;\n if (!parts) return '<time part=\"time\"></time>';\n\n return `<time part=\"time\" datetime=\"${escapeHtml(value)}\">${escapeHtml(formatDateTime(parts, format))}</time>`;\n }\n}\n",
|
|
6
|
+
"/**\n * @duskmoon-dev/el-datetime\n *\n * Display-only ISO date and datetime formatting custom element.\n */\n\nimport { ElDmDatetime } from './el-dm-datetime.js';\n\nexport { DEFAULT_DATETIME_FORMAT, ElDmDatetime } from './el-dm-datetime.js';\n\n/** Register the el-dm-datetime custom element. */\nexport function register(): void {\n if (!customElements.get('el-dm-datetime')) {\n customElements.define('el-dm-datetime', ElDmDatetime);\n }\n}\n",
|
|
7
|
+
"import { register } from './index.js';\n\nregister();\n"
|
|
8
|
+
],
|
|
9
|
+
"mappings": ";AAAA;AAEO,IAAM,0BAA0B;AAiBvC,IAAM,uBACJ;AACF,IAAM,uBAAuB;AAE7B,IAAM,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUf,SAAS,UAAU,CAAC,MAAuB;AAAA,EACzC,OAAO,OAAO,MAAM,MAAM,OAAO,QAAQ,KAAK,OAAO,QAAQ;AAAA;AAG/D,SAAS,WAAW,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A;AAExG;;;AC5MO,SAAS,QAAQ,GAAS;AAAA,EAC/B,IAAI,CAAC,eAAe,IAAI,gBAAgB,GAAG;AAAA,IACzC,eAAe,OAAO,kBAAkB,YAAY;AAAA,EACtD;AAAA;;;ACZF,SAAS;",
|
|
10
|
+
"debugId": "731A53637B58714B64756E2164756E21",
|
|
11
|
+
"names": []
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"fileNames":["../../../node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts","../../../node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es2015.d.ts","../../../node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es2016.d.ts","../../../node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es2017.d.ts","../../../node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es2018.d.ts","../../../node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es2019.d.ts","../../../node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es2020.d.ts","../../../node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es2021.d.ts","../../../node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es2022.d.ts","../../../node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.dom.d.ts","../../../node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.dom.iterable.d.ts","../../../node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es2015.core.d.ts","../../../node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es2015.collection.d.ts","../../../node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es2015.generator.d.ts","../../../node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es2015.iterable.d.ts","../../../node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es2015.promise.d.ts","../../../node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es2015.proxy.d.ts","../../../node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es2015.reflect.d.ts","../../../node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es2015.symbol.d.ts","../../../node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../../../node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es2016.array.include.d.ts","../../../node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es2016.intl.d.ts","../../../node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es2017.arraybuffer.d.ts","../../../node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es2017.date.d.ts","../../../node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es2017.object.d.ts","../../../node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../../../node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es2017.string.d.ts","../../../node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es2017.intl.d.ts","../../../node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../../../node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","../../../node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","../../../node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es2018.intl.d.ts","../../../node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es2018.promise.d.ts","../../../node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es2018.regexp.d.ts","../../../node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es2019.array.d.ts","../../../node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es2019.object.d.ts","../../../node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es2019.string.d.ts","../../../node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es2019.symbol.d.ts","../../../node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es2019.intl.d.ts","../../../node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es2020.bigint.d.ts","../../../node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es2020.date.d.ts","../../../node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es2020.promise.d.ts","../../../node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts","../../../node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es2020.string.d.ts","../../../node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts","../../../node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es2020.intl.d.ts","../../../node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es2020.number.d.ts","../../../node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es2021.promise.d.ts","../../../node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es2021.string.d.ts","../../../node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es2021.weakref.d.ts","../../../node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es2021.intl.d.ts","../../../node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es2022.array.d.ts","../../../node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es2022.error.d.ts","../../../node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es2022.intl.d.ts","../../../node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es2022.object.d.ts","../../../node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es2022.string.d.ts","../../../node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es2022.regexp.d.ts","../../../node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.decorators.d.ts","../../../node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.decorators.legacy.d.ts","../../../packages/base/dist/types/base-element.d.ts","../../../packages/base/dist/types/styles.d.ts","../../../packages/base/dist/types/animations.d.ts","../../../packages/base/dist/types/themes.d.ts","../../../packages/base/dist/types/mixins.d.ts","../../../packages/base/dist/types/types.d.ts","../../../packages/base/dist/types/validation.d.ts","../../../packages/base/dist/types/performance.d.ts","../../../packages/base/dist/types/index.d.ts","../src/el-dm-datetime.ts","../src/index.ts","../src/register.ts"],"fileIdsList":[[68],[69],[70],[60,61,62,63,64,65,66,67],[60],[65]],"fileInfos":[{"version":"bcd24271a113971ba9eb71ff8cb01bc6b0f872a85c23fdbe5d93065b375933cd","affectsGlobalScope":true,"impliedFormat":1},{"version":"3f88bedbeb09c6f5a6645cb24c7c55f1aa22d19ae96c8e6959cbd8b85a707bc6","impliedFormat":1},{"version":"7fe93b39b810eadd916be8db880dd7f0f7012a5cc6ffb62de8f62a2117fa6f1f","impliedFormat":1},{"version":"bb0074cc08b84a2374af33d8bf044b80851ccc9e719a5e202eacf40db2c31600","impliedFormat":1},{"version":"1a7daebe4f45fb03d9ec53d60008fbf9ac45a697fdc89e4ce218bc94b94f94d6","impliedFormat":1},{"version":"f94b133a3cb14a288803be545ac2683e0d0ff6661bcd37e31aaaec54fc382aed","impliedFormat":1},{"version":"f59d0650799f8782fd74cf73c19223730c6d1b9198671b1c5b3a38e1188b5953","impliedFormat":1},{"version":"8a15b4607d9a499e2dbeed9ec0d3c0d7372c850b2d5f1fb259e8f6d41d468a84","impliedFormat":1},{"version":"26e0fe14baee4e127f4365d1ae0b276f400562e45e19e35fd2d4c296684715e6","impliedFormat":1},{"version":"d6b1eba8496bdd0eed6fc8a685768fe01b2da4a0388b5fe7df558290bffcf32f","affectsGlobalScope":true,"impliedFormat":1},{"version":"7f57fc4404ff020bc45b9c620aff2b40f700b95fe31164024c453a5e3c163c54","impliedFormat":1},{"version":"eadcffda2aa84802c73938e589b9e58248d74c59cb7fcbca6474e3435ac15504","affectsGlobalScope":true,"impliedFormat":1},{"version":"105ba8ff7ba746404fe1a2e189d1d3d2e0eb29a08c18dded791af02f29fb4711","affectsGlobalScope":true,"impliedFormat":1},{"version":"00343ca5b2e3d48fa5df1db6e32ea2a59afab09590274a6cccb1dbae82e60c7c","affectsGlobalScope":true,"impliedFormat":1},{"version":"ebd9f816d4002697cb2864bea1f0b70a103124e18a8cd9645eeccc09bdf80ab4","affectsGlobalScope":true,"impliedFormat":1},{"version":"2c1afac30a01772cd2a9a298a7ce7706b5892e447bb46bdbeef720f7b5da77ad","affectsGlobalScope":true,"impliedFormat":1},{"version":"7b0225f483e4fa685625ebe43dd584bb7973bbd84e66a6ba7bbe175ee1048b4f","affectsGlobalScope":true,"impliedFormat":1},{"version":"c0a4b8ac6ce74679c1da2b3795296f5896e31c38e888469a8e0f99dc3305de60","affectsGlobalScope":true,"impliedFormat":1},{"version":"3084a7b5f569088e0146533a00830e206565de65cae2239509168b11434cd84f","affectsGlobalScope":true,"impliedFormat":1},{"version":"c5079c53f0f141a0698faa903e76cb41cd664e3efb01cc17a5c46ec2eb0bef42","affectsGlobalScope":true,"impliedFormat":1},{"version":"32cafbc484dea6b0ab62cf8473182bbcb23020d70845b406f80b7526f38ae862","affectsGlobalScope":true,"impliedFormat":1},{"version":"fca4cdcb6d6c5ef18a869003d02c9f0fd95df8cfaf6eb431cd3376bc034cad36","affectsGlobalScope":true,"impliedFormat":1},{"version":"b93ec88115de9a9dc1b602291b85baf825c85666bf25985cc5f698073892b467","affectsGlobalScope":true,"impliedFormat":1},{"version":"f5c06dcc3fe849fcb297c247865a161f995cc29de7aa823afdd75aaaddc1419b","affectsGlobalScope":true,"impliedFormat":1},{"version":"b77e16112127a4b169ef0b8c3a4d730edf459c5f25fe52d5e436a6919206c4d7","affectsGlobalScope":true,"impliedFormat":1},{"version":"fbffd9337146eff822c7c00acbb78b01ea7ea23987f6c961eba689349e744f8c","affectsGlobalScope":true,"impliedFormat":1},{"version":"a995c0e49b721312f74fdfb89e4ba29bd9824c770bbb4021d74d2bf560e4c6bd","affectsGlobalScope":true,"impliedFormat":1},{"version":"c7b3542146734342e440a84b213384bfa188835537ddbda50d30766f0593aff9","affectsGlobalScope":true,"impliedFormat":1},{"version":"ce6180fa19b1cccd07ee7f7dbb9a367ac19c0ed160573e4686425060b6df7f57","affectsGlobalScope":true,"impliedFormat":1},{"version":"3f02e2476bccb9dbe21280d6090f0df17d2f66b74711489415a8aa4df73c9675","affectsGlobalScope":true,"impliedFormat":1},{"version":"45e3ab34c1c013c8ab2dc1ba4c80c780744b13b5676800ae2e3be27ae862c40c","affectsGlobalScope":true,"impliedFormat":1},{"version":"805c86f6cca8d7702a62a844856dbaa2a3fd2abef0536e65d48732441dde5b5b","affectsGlobalScope":true,"impliedFormat":1},{"version":"e42e397f1a5a77994f0185fd1466520691456c772d06bf843e5084ceb879a0ad","affectsGlobalScope":true,"impliedFormat":1},{"version":"f4c2b41f90c95b1c532ecc874bd3c111865793b23aebcc1c3cbbabcd5d76ffb0","affectsGlobalScope":true,"impliedFormat":1},{"version":"ab26191cfad5b66afa11b8bf935ef1cd88fabfcb28d30b2dfa6fad877d050332","affectsGlobalScope":true,"impliedFormat":1},{"version":"2088bc26531e38fb05eedac2951480db5309f6be3fa4a08d2221abb0f5b4200d","affectsGlobalScope":true,"impliedFormat":1},{"version":"cb9d366c425fea79716a8fb3af0d78e6b22ebbab3bd64d25063b42dc9f531c1e","affectsGlobalScope":true,"impliedFormat":1},{"version":"500934a8089c26d57ebdb688fc9757389bb6207a3c8f0674d68efa900d2abb34","affectsGlobalScope":true,"impliedFormat":1},{"version":"689da16f46e647cef0d64b0def88910e818a5877ca5379ede156ca3afb780ac3","affectsGlobalScope":true,"impliedFormat":1},{"version":"bc21cc8b6fee4f4c2440d08035b7ea3c06b3511314c8bab6bef7a92de58a2593","affectsGlobalScope":true,"impliedFormat":1},{"version":"7ca53d13d2957003abb47922a71866ba7cb2068f8d154877c596d63c359fed25","affectsGlobalScope":true,"impliedFormat":1},{"version":"54725f8c4df3d900cb4dac84b64689ce29548da0b4e9b7c2de61d41c79293611","affectsGlobalScope":true,"impliedFormat":1},{"version":"e5594bc3076ac29e6c1ebda77939bc4c8833de72f654b6e376862c0473199323","affectsGlobalScope":true,"impliedFormat":1},{"version":"2f3eb332c2d73e729f3364fcc0c2b375e72a121e8157d25a82d67a138c83a95c","affectsGlobalScope":true,"impliedFormat":1},{"version":"6f4427f9642ce8d500970e4e69d1397f64072ab73b97e476b4002a646ac743b1","affectsGlobalScope":true,"impliedFormat":1},{"version":"48915f327cd1dea4d7bd358d9dc7732f58f9e1626a29cc0c05c8c692419d9bb7","affectsGlobalScope":true,"impliedFormat":1},{"version":"b7bf9377723203b5a6a4b920164df22d56a43f593269ba6ae1fdc97774b68855","affectsGlobalScope":true,"impliedFormat":1},{"version":"db9709688f82c9e5f65a119c64d835f906efe5f559d08b11642d56eb85b79357","affectsGlobalScope":true,"impliedFormat":1},{"version":"4b25b8c874acd1a4cf8444c3617e037d444d19080ac9f634b405583fd10ce1f7","affectsGlobalScope":true,"impliedFormat":1},{"version":"37be57d7c90cf1f8112ee2636a068d8fd181289f82b744160ec56a7dc158a9f5","affectsGlobalScope":true,"impliedFormat":1},{"version":"a917a49ac94cd26b754ab84e113369a75d1a47a710661d7cd25e961cc797065f","affectsGlobalScope":true,"impliedFormat":1},{"version":"6d3261badeb7843d157ef3e6f5d1427d0eeb0af0cf9df84a62cfd29fd47ac86e","affectsGlobalScope":true,"impliedFormat":1},{"version":"195daca651dde22f2167ac0d0a05e215308119a3100f5e6268e8317d05a92526","affectsGlobalScope":true,"impliedFormat":1},{"version":"8b11e4285cd2bb164a4dc09248bdec69e9842517db4ca47c1ba913011e44ff2f","affectsGlobalScope":true,"impliedFormat":1},{"version":"0508571a52475e245b02bc50fa1394065a0a3d05277fbf5120c3784b85651799","affectsGlobalScope":true,"impliedFormat":1},{"version":"8f9af488f510c3015af3cc8c267a9e9d96c4dd38a1fdff0e11dc5a544711415b","affectsGlobalScope":true,"impliedFormat":1},{"version":"fc611fea8d30ea72c6bbfb599c9b4d393ce22e2f5bfef2172534781e7d138104","affectsGlobalScope":true,"impliedFormat":1},{"version":"1ce14b81c5cc821994aa8ec1d42b220dd41b27fcc06373bce3958af7421b77d4","affectsGlobalScope":true,"impliedFormat":1},{"version":"b3a048b3e9302ef9a34ef4ebb9aecfb28b66abb3bce577206a79fee559c230da","affectsGlobalScope":true,"impliedFormat":1},"42526b6de804c10fd86f1cf55a6c660a74ee448e381f0f78356f223b75982280","28914adcfb92fa94199e1c887da7d67a7d9d736d9571627d6b02e55ff82f577b","b0a69607a92876948c2a42e3aa6703b0d724699468ed7e3c6e2a237d119a9db9","cdacb8e4ac607a46494d1187e073382c43e7269e8bf698502a285a8ccb470925","f5091ebbd718ea236a7f503df569deb07aff0621aa8f73ed90e419de88f006aa","d3a328c0eccf652bc8b6c14515a8b848a558b9d684e15a7c0c2e15de5016df57","1b5193795ee478857bf1115fed004151284dd4da883a5a4f22e62631c3b414ad","3be01044afc63501423c361deb531d3e95f5c2677f1f7a628802bd346988d62c","78d8d1ca7d54a437702c8a8c08764b6a49f2cf2ca357d0e459bfe89a06abf50a",{"version":"532c6cbc03a204a7276f7de3f828ce0154ace2ca1f0f758f1e6b07cfd6a8f43e","signature":"fc6fad98ef67a1c190fc1cde52b38bc4eae10219ce3289292b94973ba81e1a3e"},{"version":"060561f2befdb582c8188555cf85d6f660e5b567f23922d6ed1f0165d9c459b7","signature":"f93740d875e994467a4e7c69a2e8a624eccfbc8610ec4bf5088eab8ace985f98"},{"version":"e0a32396c971f440a5871afb0cc7947f33b4854a30f95b8e90e0a9aa0dd3f6bd","signature":"8e609bb71c20b858c77f0e9f90bb1319db8477b13f9f965f1a1e18524bf50881"}],"root":[[69,71]],"options":{"composite":true,"declaration":true,"declarationMap":true,"emitDeclarationOnly":true,"esModuleInterop":true,"module":99,"outDir":"./types","rootDir":"../src","skipLibCheck":true,"sourceMap":true,"strict":true,"target":9},"referencedMap":[[69,1],[70,2],[71,3],[68,4],[64,5],[66,6]],"latestChangedDtsFile":"./types/register.d.ts","version":"6.0.3"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { BaseElement } from '@duskmoon-dev/el-base';
|
|
2
|
+
export declare const DEFAULT_DATETIME_FORMAT = "YYYY-MM-DD HH:mm";
|
|
3
|
+
/** Display an ISO date or datetime using a token-based format. */
|
|
4
|
+
export declare class ElDmDatetime extends BaseElement {
|
|
5
|
+
static properties: {
|
|
6
|
+
value: {
|
|
7
|
+
type: StringConstructor;
|
|
8
|
+
reflect: boolean;
|
|
9
|
+
default: string;
|
|
10
|
+
};
|
|
11
|
+
format: {
|
|
12
|
+
type: StringConstructor;
|
|
13
|
+
reflect: boolean;
|
|
14
|
+
default: string;
|
|
15
|
+
};
|
|
16
|
+
timeZone: {
|
|
17
|
+
type: StringConstructor;
|
|
18
|
+
reflect: boolean;
|
|
19
|
+
default: string;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
value: string;
|
|
23
|
+
format: string;
|
|
24
|
+
timeZone: string;
|
|
25
|
+
constructor();
|
|
26
|
+
protected render(): string;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=el-dm-datetime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"el-dm-datetime.d.ts","sourceRoot":"","sources":["../../src/el-dm-datetime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAO,MAAM,uBAAuB,CAAC;AAEzD,eAAO,MAAM,uBAAuB,qBAAqB,CAAC;AAqL1D,kEAAkE;AAClE,qBAAa,YAAa,SAAQ,WAAW;IAC3C,MAAM,CAAC,UAAU;;;;;;;;;;;;;;;;MAIf;IAEM,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;;IAOzB,SAAS,CAAC,MAAM,IAAI,MAAM;CAe3B"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @duskmoon-dev/el-datetime
|
|
3
|
+
*
|
|
4
|
+
* Display-only ISO date and datetime formatting custom element.
|
|
5
|
+
*/
|
|
6
|
+
export { DEFAULT_DATETIME_FORMAT, ElDmDatetime } from './el-dm-datetime.js';
|
|
7
|
+
/** Register the el-dm-datetime custom element. */
|
|
8
|
+
export declare function register(): void;
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EAAE,uBAAuB,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAE5E,kDAAkD;AAClD,wBAAgB,QAAQ,IAAI,IAAI,CAI/B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../src/register.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@duskmoon-dev/el-datetime",
|
|
3
|
+
"version": "1.6.0",
|
|
4
|
+
"description": "Display-only DuskMoon custom element for formatting ISO dates and datetimes",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/cjs/index.js",
|
|
7
|
+
"module": "./dist/esm/index.js",
|
|
8
|
+
"types": "./dist/types/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/types/index.d.ts",
|
|
12
|
+
"import": "./dist/esm/index.js",
|
|
13
|
+
"require": "./dist/cjs/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./register": {
|
|
16
|
+
"types": "./dist/types/register.d.ts",
|
|
17
|
+
"import": "./dist/esm/register.js",
|
|
18
|
+
"require": "./dist/cjs/register.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"prebuild": "bun run clean",
|
|
26
|
+
"build": "bun run build:esm && bun run build:cjs && bun run build:types",
|
|
27
|
+
"build:esm": "bun build ./src/index.ts ./src/register.ts --outdir ./dist/esm --format esm --sourcemap --external @duskmoon-dev/el-base",
|
|
28
|
+
"build:cjs": "bun build ./src/index.ts ./src/register.ts --outdir ./dist/cjs --format cjs --sourcemap --external @duskmoon-dev/el-base",
|
|
29
|
+
"build:types": "tsc --emitDeclarationOnly --outDir ./dist/types",
|
|
30
|
+
"dev": "bun build ./src/index.ts --outdir ./dist/esm --format esm --sourcemap --external @duskmoon-dev/el-base --watch",
|
|
31
|
+
"clean": "del-cli dist",
|
|
32
|
+
"test": "bun test",
|
|
33
|
+
"typecheck": "tsc --noEmit",
|
|
34
|
+
"format": "prettier --write 'src/**/*.ts' '*.json' '*.md'",
|
|
35
|
+
"format:check": "prettier --check 'src/**/*.ts' '*.json' '*.md'",
|
|
36
|
+
"lint": "eslint src",
|
|
37
|
+
"lint:check": "eslint src --max-warnings 0",
|
|
38
|
+
"lint:fix": "eslint src --fix",
|
|
39
|
+
"release": "bun publish",
|
|
40
|
+
"release:dry-run": "bun publish --dry-run"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@duskmoon-dev/el-base": "1.6.0"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"typescript": "6.0.3"
|
|
47
|
+
},
|
|
48
|
+
"publishConfig": {
|
|
49
|
+
"access": "public"
|
|
50
|
+
},
|
|
51
|
+
"repository": {
|
|
52
|
+
"type": "git",
|
|
53
|
+
"url": "git+https://github.com/duskmoon-dev/duskmoon-elements.git"
|
|
54
|
+
},
|
|
55
|
+
"keywords": [
|
|
56
|
+
"duskmoon-dev",
|
|
57
|
+
"custom-elements",
|
|
58
|
+
"web-components",
|
|
59
|
+
"datetime",
|
|
60
|
+
"date-formatting"
|
|
61
|
+
],
|
|
62
|
+
"author": "AkaraChen",
|
|
63
|
+
"license": "MIT"
|
|
64
|
+
}
|