@fusion.dev/helix-core 0.170.0 → 0.171.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/custom-elements.json +41 -3
- package/dist/mixins/mixin-field/mixin-field.js +4 -0
- package/dist/utils/elapsed-time/elapsed-time.js +4 -10
- package/dist/utils/relative-time/relative-time.d.ts +25 -2
- package/dist/utils/relative-time/relative-time.js +30 -10
- package/dist/utils/report-runtime/report-runtime.d.ts +2 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +4 -4
package/custom-elements.json
CHANGED
|
@@ -30178,11 +30178,41 @@
|
|
|
30178
30178
|
"kind": "variable",
|
|
30179
30179
|
"name": "UNITS",
|
|
30180
30180
|
"type": {
|
|
30181
|
-
"text": "
|
|
30181
|
+
"text": "Unit[]"
|
|
30182
30182
|
},
|
|
30183
30183
|
"default": "[ { ms: 1000, unit: 'second' }, { ms: 60_000, unit: 'minute' }, { ms: 3_600_000, unit: 'hour' }, { ms: 86_400_000, unit: 'day' }, { ms: 604_800_000, unit: 'week' }, { ms: 2_629_800_000, unit: 'month' }, { ms: 31_557_600_000, unit: 'year' }, ]",
|
|
30184
30184
|
"description": "How long each unit lasts, in milliseconds, largest last. `elapsedTime`\nreads its minute, hour and day from here."
|
|
30185
30185
|
},
|
|
30186
|
+
{
|
|
30187
|
+
"kind": "function",
|
|
30188
|
+
"name": "roundedCount",
|
|
30189
|
+
"return": {
|
|
30190
|
+
"type": {
|
|
30191
|
+
"text": "{ count: number; index: number; next: number }"
|
|
30192
|
+
}
|
|
30193
|
+
},
|
|
30194
|
+
"parameters": [
|
|
30195
|
+
{
|
|
30196
|
+
"name": "size",
|
|
30197
|
+
"type": {
|
|
30198
|
+
"text": "number"
|
|
30199
|
+
}
|
|
30200
|
+
},
|
|
30201
|
+
{
|
|
30202
|
+
"name": "units",
|
|
30203
|
+
"type": {
|
|
30204
|
+
"text": "readonly U[]"
|
|
30205
|
+
}
|
|
30206
|
+
},
|
|
30207
|
+
{
|
|
30208
|
+
"name": "growing",
|
|
30209
|
+
"type": {
|
|
30210
|
+
"text": "boolean"
|
|
30211
|
+
}
|
|
30212
|
+
}
|
|
30213
|
+
],
|
|
30214
|
+
"description": "A size of time as a rounded count of one of `units`, and how long that\ncount holds while the size grows (`growing`, a moment gone) or shrinks (a\nmoment to come).\n\n**Rounded, as Shoelace's relative time rounds.** Truncated, a date 48 hours\nahead, measured a few milliseconds later, read \"tomorrow\", and 59 minutes\nread \"59 minutes\" while 61 read \"1 hour\". A count that rounds up to the next\nunit's size reads in that unit: 59.6 minutes is 1 hour, 6.6 days is 1 week.\n\n`units` run smallest first and the size is at least the first of them.\nExported for `elapsedTime`, which reads its minute, hour and day the same way."
|
|
30215
|
+
},
|
|
30186
30216
|
{
|
|
30187
30217
|
"kind": "function",
|
|
30188
30218
|
"name": "relativeTime",
|
|
@@ -30218,6 +30248,14 @@
|
|
|
30218
30248
|
"module": "src/utils/relative-time/relative-time.ts"
|
|
30219
30249
|
}
|
|
30220
30250
|
},
|
|
30251
|
+
{
|
|
30252
|
+
"kind": "js",
|
|
30253
|
+
"name": "roundedCount",
|
|
30254
|
+
"declaration": {
|
|
30255
|
+
"name": "roundedCount",
|
|
30256
|
+
"module": "src/utils/relative-time/relative-time.ts"
|
|
30257
|
+
}
|
|
30258
|
+
},
|
|
30221
30259
|
{
|
|
30222
30260
|
"kind": "js",
|
|
30223
30261
|
"name": "relativeTime",
|
|
@@ -33673,7 +33711,7 @@
|
|
|
33673
33711
|
"type": {
|
|
33674
33712
|
"text": "string"
|
|
33675
33713
|
},
|
|
33676
|
-
"default": "'0.
|
|
33714
|
+
"default": "'0.171.0'",
|
|
33677
33715
|
"description": "The version of the package this file ships in.\n\n**Written by `fusion/scripts/version.mjs`** wherever it writes the package's\n`package.json`, and stamped back into the repository beside it after a\nrelease, so the two never disagree; a spec beside this holds them to it.\nNothing else in the running code knows which release it is."
|
|
33678
33716
|
}
|
|
33679
33717
|
],
|
|
@@ -34233,6 +34271,6 @@
|
|
|
34233
34271
|
],
|
|
34234
34272
|
"helix": {
|
|
34235
34273
|
"package": "@fusion.dev/helix-core",
|
|
34236
|
-
"version": "0.
|
|
34274
|
+
"version": "0.171.0"
|
|
34237
34275
|
}
|
|
34238
34276
|
}
|
|
@@ -142,6 +142,10 @@ export const MixinField = (Base) => {
|
|
|
142
142
|
this.refreshFeedback();
|
|
143
143
|
}
|
|
144
144
|
copyValidity(control) {
|
|
145
|
+
if (!control.willValidate) {
|
|
146
|
+
this.internals.setValidity({});
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
145
149
|
const message = control.validity.valueMissing && this.valueMissingMessage
|
|
146
150
|
? this.valueMissingMessage
|
|
147
151
|
: control.validationMessage;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { UNITS as TIME_UNITS } from '../relative-time/relative-time.js';
|
|
1
|
+
import { roundedCount, UNITS as TIME_UNITS } from '../relative-time/relative-time.js';
|
|
2
2
|
const held = new Map();
|
|
3
3
|
const dated = new Map();
|
|
4
4
|
const UNITS = TIME_UNITS.slice(1, 4);
|
|
@@ -44,15 +44,9 @@ export const elapsedTime = (locale) => {
|
|
|
44
44
|
const format = sameYear ? dates[0] : dates[1];
|
|
45
45
|
return { next: Number.POSITIVE_INFINITY, text: format.format(from) };
|
|
46
46
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
index = at;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
const chosen = UNITS[index];
|
|
54
|
-
const count = Math.trunc(size / chosen.ms);
|
|
55
|
-
const remaining = Math.min(chosen.ms - (size % chosen.ms), HORIZON - size);
|
|
47
|
+
const growing = elapsed > 0;
|
|
48
|
+
const { count, index, next } = roundedCount(size, UNITS, growing);
|
|
49
|
+
const remaining = growing ? Math.min(next, HORIZON - size) : next;
|
|
56
50
|
return {
|
|
57
51
|
next: Math.max(1000, Math.min(remaining, 3_600_000)),
|
|
58
52
|
text: short[index].format(count),
|
|
@@ -2,10 +2,32 @@
|
|
|
2
2
|
* How long each unit lasts, in milliseconds, largest last. `elapsedTime`
|
|
3
3
|
* reads its minute, hour and day from here.
|
|
4
4
|
*/
|
|
5
|
-
export declare const UNITS:
|
|
5
|
+
export declare const UNITS: Unit[];
|
|
6
|
+
/** One unit of `UNITS`. */
|
|
7
|
+
type Unit = {
|
|
6
8
|
ms: number;
|
|
7
9
|
unit: Intl.RelativeTimeFormatUnit;
|
|
8
|
-
}
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* A size of time as a rounded count of one of `units`, and how long that
|
|
13
|
+
* count holds while the size grows (`growing`, a moment gone) or shrinks (a
|
|
14
|
+
* moment to come).
|
|
15
|
+
*
|
|
16
|
+
* **Rounded, as Shoelace's relative time rounds.** Truncated, a date 48 hours
|
|
17
|
+
* ahead, measured a few milliseconds later, read "tomorrow", and 59 minutes
|
|
18
|
+
* read "59 minutes" while 61 read "1 hour". A count that rounds up to the next
|
|
19
|
+
* unit's size reads in that unit: 59.6 minutes is 1 hour, 6.6 days is 1 week.
|
|
20
|
+
*
|
|
21
|
+
* `units` run smallest first and the size is at least the first of them.
|
|
22
|
+
* Exported for `elapsedTime`, which reads its minute, hour and day the same way.
|
|
23
|
+
*/
|
|
24
|
+
export declare const roundedCount: <U extends {
|
|
25
|
+
ms: number;
|
|
26
|
+
}>(size: number, units: readonly U[], growing: boolean) => {
|
|
27
|
+
count: number;
|
|
28
|
+
index: number;
|
|
29
|
+
next: number;
|
|
30
|
+
};
|
|
9
31
|
/** What one timestamp reads as, and when that stops being true. */
|
|
10
32
|
export interface Relative {
|
|
11
33
|
/**
|
|
@@ -42,3 +64,4 @@ export interface RelativeOptions {
|
|
|
42
64
|
* says aloud and what every caller wanted before Format Date offered the rest.
|
|
43
65
|
*/
|
|
44
66
|
export declare const relativeTime: (locale: string, options?: RelativeOptions) => ((from: Date, now: Date) => Relative);
|
|
67
|
+
export {};
|
|
@@ -8,6 +8,32 @@ export const UNITS = [
|
|
|
8
8
|
{ ms: 2_629_800_000, unit: 'month' },
|
|
9
9
|
{ ms: 31_557_600_000, unit: 'year' },
|
|
10
10
|
];
|
|
11
|
+
export const roundedCount = (size, units, growing) => {
|
|
12
|
+
let index = 0;
|
|
13
|
+
for (let at = 1; at < units.length; at += 1) {
|
|
14
|
+
if (size >= units[at].ms) {
|
|
15
|
+
index = at;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
const ms = (at) => units[at].ms;
|
|
19
|
+
let count = Math.round(size / ms(index));
|
|
20
|
+
while (index + 1 < units.length && count * ms(index) >= ms(index + 1)) {
|
|
21
|
+
index += 1;
|
|
22
|
+
count = Math.round(size / ms(index));
|
|
23
|
+
}
|
|
24
|
+
if (growing) {
|
|
25
|
+
return { count, index, next: (count + 0.5) * ms(index) - size };
|
|
26
|
+
}
|
|
27
|
+
const below = [(count - 0.5) * ms(index)];
|
|
28
|
+
if (size >= ms(index)) {
|
|
29
|
+
below.push(ms(index));
|
|
30
|
+
}
|
|
31
|
+
if (index > 0) {
|
|
32
|
+
below.push((Math.ceil(ms(index) / ms(index - 1)) - 0.5) * ms(index - 1));
|
|
33
|
+
}
|
|
34
|
+
const floor = Math.max(...below.filter((at) => at <= size));
|
|
35
|
+
return { count, index, next: size - floor + 1 };
|
|
36
|
+
};
|
|
11
37
|
export const relativeTime = (locale, options = {}) => {
|
|
12
38
|
const numeric = options.numeric ?? 'auto';
|
|
13
39
|
const style = options.style ?? 'long';
|
|
@@ -30,17 +56,11 @@ export const relativeTime = (locale, options = {}) => {
|
|
|
30
56
|
text: found.format(elapsed > 0 ? 0 : -0, 'second'),
|
|
31
57
|
};
|
|
32
58
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
if (size >= unit.ms) {
|
|
36
|
-
chosen = unit;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
const count = Math.trunc(elapsed / chosen.ms);
|
|
40
|
-
const remaining = chosen.ms - (size % chosen.ms);
|
|
59
|
+
const { count, index, next } = roundedCount(size, UNITS.slice(1), elapsed < 0);
|
|
60
|
+
const chosen = UNITS[index + 1];
|
|
41
61
|
return {
|
|
42
|
-
next: Math.max(1000, Math.min(
|
|
43
|
-
text: found.format(count, chosen.unit),
|
|
62
|
+
next: Math.max(1000, Math.min(next, 3_600_000)),
|
|
63
|
+
text: found.format(elapsed < 0 ? -count : count, chosen.unit),
|
|
44
64
|
};
|
|
45
65
|
};
|
|
46
66
|
};
|
|
@@ -34,6 +34,8 @@ export type RuntimeKind =
|
|
|
34
34
|
| 'misread-direction'
|
|
35
35
|
/** A React handler prop names an event the element never dispatches itself. Development builds only. */
|
|
36
36
|
| 'misplaced-handler'
|
|
37
|
+
/** A Chat was given turns both as children and as `turns`, which it draws as two runs. */
|
|
38
|
+
| 'mixed-turns'
|
|
37
39
|
/** An Image has no `alt`, so a screen reader announces its file name. */
|
|
38
40
|
| 'missing-alt'
|
|
39
41
|
/** The three.js driver could not load its layout, so the notes stay where they started. */
|
package/dist/version.d.ts
CHANGED
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '0.
|
|
1
|
+
export const VERSION = '0.171.0';
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fusion.dev/helix-core",
|
|
3
3
|
"description": "Helix element primitives: base classes, mixins, decorators, utilities.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.171.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Ross Sheppard <ross.sheppard@fusion.dev>",
|
|
7
7
|
"repository": {
|
|
@@ -62,11 +62,11 @@
|
|
|
62
62
|
"bugs": "https://github.com/project-fusion/fusion/issues",
|
|
63
63
|
"dependencies": {
|
|
64
64
|
"@floating-ui/dom": "^1.8.0",
|
|
65
|
-
"@fusion.dev/helix-icons": "0.
|
|
65
|
+
"@fusion.dev/helix-icons": "0.171.0"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
|
-
"@fusion.dev/helix-cem": "0.
|
|
69
|
-
"@fusion.dev/helix-testing": "0.
|
|
68
|
+
"@fusion.dev/helix-cem": "0.171.0",
|
|
69
|
+
"@fusion.dev/helix-testing": "0.171.0",
|
|
70
70
|
"@lit-labs/ssr": "^4.1.0",
|
|
71
71
|
"lit": "^3.2.1"
|
|
72
72
|
},
|