@getuserfeedback/protocol 3.0.10 → 3.0.11
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/dist/host/widget-layout-transition-plan.d.ts +1 -0
- package/dist/host/widget-layout-transition-plan.d.ts.map +1 -1
- package/dist/host/widget-layout-transition-plan.js +8 -0
- package/package.json +1 -1
- package/src/host/widget-layout-transition-plan.test.ts +60 -0
- package/src/host/widget-layout-transition-plan.ts +10 -0
|
@@ -14,6 +14,7 @@ export type WidgetLayoutInstantTransitionPlan = {
|
|
|
14
14
|
settledAtMs: number;
|
|
15
15
|
};
|
|
16
16
|
export type WidgetLayoutTransitionPlan = WidgetLayoutUnchangedTransitionPlan | WidgetLayoutInstantTransitionPlan;
|
|
17
|
+
export declare function getWidgetLayoutPlanNowMs(): number;
|
|
17
18
|
export declare function areWidgetLayoutSizeUpdatesEqual(left: WidgetLayoutComparableSizeUpdate | undefined, right: WidgetLayoutComparableSizeUpdate): boolean;
|
|
18
19
|
export declare function planWidgetLayoutTransition(input: {
|
|
19
20
|
previous?: WidgetLayoutSizeUpdate;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"widget-layout-transition-plan.d.ts","sourceRoot":"","sources":["../../src/host/widget-layout-transition-plan.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,gBAAgB,EAChB,sBAAsB,EACtB,2BAA2B,EAC3B,MAAM,gCAAgC,CAAC;AAExC,MAAM,MAAM,gCAAgC,GACzC,sBAAsB,GACtB,2BAA2B,CAAC;AAE/B,MAAM,MAAM,mCAAmC,GAAG;IACjD,IAAI,EAAE,WAAW,CAAC;IAClB,IAAI,EAAE,gBAAgB,CAAC;IACvB,MAAM,EAAE,sBAAsB,CAAC;IAC/B,YAAY,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,iCAAiC,GAAG;IAC/C,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,EAAE,gBAAgB,CAAC;IACvB,MAAM,EAAE,sBAAsB,CAAC;IAC/B,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,0BAA0B,GACnC,mCAAmC,GACnC,iCAAiC,CAAC;AAErC,wBAAgB,+BAA+B,CAC9C,IAAI,EAAE,gCAAgC,GAAG,SAAS,EAClD,KAAK,EAAE,gCAAgC,GACrC,OAAO,CAiCT;AAED,wBAAgB,0BAA0B,CAAC,KAAK,EAAE;IACjD,QAAQ,CAAC,EAAE,sBAAsB,CAAC;IAClC,IAAI,EAAE,sBAAsB,CAAC;IAC7B,KAAK,EAAE,MAAM,CAAC;CACd,GAAG,0BAA0B,CAyB7B"}
|
|
1
|
+
{"version":3,"file":"widget-layout-transition-plan.d.ts","sourceRoot":"","sources":["../../src/host/widget-layout-transition-plan.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,gBAAgB,EAChB,sBAAsB,EACtB,2BAA2B,EAC3B,MAAM,gCAAgC,CAAC;AAExC,MAAM,MAAM,gCAAgC,GACzC,sBAAsB,GACtB,2BAA2B,CAAC;AAE/B,MAAM,MAAM,mCAAmC,GAAG;IACjD,IAAI,EAAE,WAAW,CAAC;IAClB,IAAI,EAAE,gBAAgB,CAAC;IACvB,MAAM,EAAE,sBAAsB,CAAC;IAC/B,YAAY,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,iCAAiC,GAAG;IAC/C,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,EAAE,gBAAgB,CAAC;IACvB,MAAM,EAAE,sBAAsB,CAAC;IAC/B,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,0BAA0B,GACnC,mCAAmC,GACnC,iCAAiC,CAAC;AAErC,wBAAgB,wBAAwB,IAAI,MAAM,CAQjD;AAED,wBAAgB,+BAA+B,CAC9C,IAAI,EAAE,gCAAgC,GAAG,SAAS,EAClD,KAAK,EAAE,gCAAgC,GACrC,OAAO,CAiCT;AAED,wBAAgB,0BAA0B,CAAC,KAAK,EAAE;IACjD,QAAQ,CAAC,EAAE,sBAAsB,CAAC;IAClC,IAAI,EAAE,sBAAsB,CAAC;IAC7B,KAAK,EAAE,MAAM,CAAC;CACd,GAAG,0BAA0B,CAyB7B"}
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
export function getWidgetLayoutPlanNowMs() {
|
|
2
|
+
const performanceNow = typeof globalThis.performance?.now === "function"
|
|
3
|
+
? globalThis.performance.now()
|
|
4
|
+
: undefined;
|
|
5
|
+
return typeof performanceNow === "number" && Number.isFinite(performanceNow)
|
|
6
|
+
? performanceNow
|
|
7
|
+
: Date.now();
|
|
8
|
+
}
|
|
1
9
|
export function areWidgetLayoutSizeUpdatesEqual(left, right) {
|
|
2
10
|
if (left?.size.width !== right.size.width ||
|
|
3
11
|
left.size.height !== right.size.height ||
|
package/package.json
CHANGED
|
@@ -5,10 +5,70 @@ import {
|
|
|
5
5
|
} from "./widget-layout-size-update.js";
|
|
6
6
|
import {
|
|
7
7
|
areWidgetLayoutSizeUpdatesEqual,
|
|
8
|
+
getWidgetLayoutPlanNowMs,
|
|
8
9
|
planWidgetLayoutTransition,
|
|
9
10
|
} from "./widget-layout-transition-plan.js";
|
|
10
11
|
|
|
11
12
|
describe("widget layout transition plan", () => {
|
|
13
|
+
test("uses the browser monotonic clock for layout plan timestamps", () => {
|
|
14
|
+
const originalPerformanceDescriptor = Object.getOwnPropertyDescriptor(
|
|
15
|
+
globalThis,
|
|
16
|
+
"performance",
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
Object.defineProperty(globalThis, "performance", {
|
|
21
|
+
configurable: true,
|
|
22
|
+
value: {
|
|
23
|
+
now: () => 123.45,
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
expect(getWidgetLayoutPlanNowMs()).toBe(123.45);
|
|
28
|
+
} finally {
|
|
29
|
+
if (originalPerformanceDescriptor) {
|
|
30
|
+
Object.defineProperty(
|
|
31
|
+
globalThis,
|
|
32
|
+
"performance",
|
|
33
|
+
originalPerformanceDescriptor,
|
|
34
|
+
);
|
|
35
|
+
} else {
|
|
36
|
+
Reflect.deleteProperty(globalThis, "performance");
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test("falls back to Date.now when the monotonic clock is unavailable", () => {
|
|
42
|
+
const originalNow = Date.now;
|
|
43
|
+
const originalPerformanceDescriptor = Object.getOwnPropertyDescriptor(
|
|
44
|
+
globalThis,
|
|
45
|
+
"performance",
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
try {
|
|
49
|
+
Date.now = () => 1_700;
|
|
50
|
+
Object.defineProperty(globalThis, "performance", {
|
|
51
|
+
configurable: true,
|
|
52
|
+
value: {
|
|
53
|
+
now: () => Number.NaN,
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
expect(getWidgetLayoutPlanNowMs()).toBe(1_700);
|
|
58
|
+
} finally {
|
|
59
|
+
Date.now = originalNow;
|
|
60
|
+
if (originalPerformanceDescriptor) {
|
|
61
|
+
Object.defineProperty(
|
|
62
|
+
globalThis,
|
|
63
|
+
"performance",
|
|
64
|
+
originalPerformanceDescriptor,
|
|
65
|
+
);
|
|
66
|
+
} else {
|
|
67
|
+
Reflect.deleteProperty(globalThis, "performance");
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
|
|
12
72
|
test("plans the first instant layout update at the requested time", () => {
|
|
13
73
|
const next = toInstantWidgetLayoutSizeUpdate({ width: 320, height: 240 });
|
|
14
74
|
|
|
@@ -27,6 +27,16 @@ export type WidgetLayoutTransitionPlan =
|
|
|
27
27
|
| WidgetLayoutUnchangedTransitionPlan
|
|
28
28
|
| WidgetLayoutInstantTransitionPlan;
|
|
29
29
|
|
|
30
|
+
export function getWidgetLayoutPlanNowMs(): number {
|
|
31
|
+
const performanceNow =
|
|
32
|
+
typeof globalThis.performance?.now === "function"
|
|
33
|
+
? globalThis.performance.now()
|
|
34
|
+
: undefined;
|
|
35
|
+
return typeof performanceNow === "number" && Number.isFinite(performanceNow)
|
|
36
|
+
? performanceNow
|
|
37
|
+
: Date.now();
|
|
38
|
+
}
|
|
39
|
+
|
|
30
40
|
export function areWidgetLayoutSizeUpdatesEqual(
|
|
31
41
|
left: WidgetLayoutComparableSizeUpdate | undefined,
|
|
32
42
|
right: WidgetLayoutComparableSizeUpdate,
|