@getuserfeedback/protocol 3.0.9 → 3.0.10

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.
@@ -12,4 +12,5 @@ export { createCommandRequestId } from "./request-id.js";
12
12
  export * from "./sdk-types.js";
13
13
  export { createUniqueId } from "./unique-id.js";
14
14
  export * from "./widget-layout-size-update.js";
15
+ export * from "./widget-layout-transition-plan.js";
15
16
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/host/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kCAAkC,CAAC;AACjD,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACzD,cAAc,gBAAgB,CAAC;AAC/B,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,cAAc,gCAAgC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/host/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kCAAkC,CAAC;AACjD,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACzD,cAAc,gBAAgB,CAAC;AAC/B,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,oCAAoC,CAAC"}
@@ -12,3 +12,4 @@ export { createCommandRequestId } from "./request-id.js";
12
12
  export * from "./sdk-types.js";
13
13
  export { createUniqueId } from "./unique-id.js";
14
14
  export * from "./widget-layout-size-update.js";
15
+ export * from "./widget-layout-transition-plan.js";
@@ -0,0 +1,23 @@
1
+ import type { WidgetLayoutSize, WidgetLayoutSizeUpdate, WidgetLayoutTimedSizeUpdate } from "./widget-layout-size-update.js";
2
+ export type WidgetLayoutComparableSizeUpdate = WidgetLayoutSizeUpdate | WidgetLayoutTimedSizeUpdate;
3
+ export type WidgetLayoutUnchangedTransitionPlan = {
4
+ kind: "unchanged";
5
+ size: WidgetLayoutSize;
6
+ update: WidgetLayoutSizeUpdate;
7
+ observedAtMs: number;
8
+ };
9
+ export type WidgetLayoutInstantTransitionPlan = {
10
+ kind: "instant";
11
+ size: WidgetLayoutSize;
12
+ update: WidgetLayoutSizeUpdate;
13
+ startedAtMs: number;
14
+ settledAtMs: number;
15
+ };
16
+ export type WidgetLayoutTransitionPlan = WidgetLayoutUnchangedTransitionPlan | WidgetLayoutInstantTransitionPlan;
17
+ export declare function areWidgetLayoutSizeUpdatesEqual(left: WidgetLayoutComparableSizeUpdate | undefined, right: WidgetLayoutComparableSizeUpdate): boolean;
18
+ export declare function planWidgetLayoutTransition(input: {
19
+ previous?: WidgetLayoutSizeUpdate;
20
+ next: WidgetLayoutSizeUpdate;
21
+ nowMs: number;
22
+ }): WidgetLayoutTransitionPlan;
23
+ //# sourceMappingURL=widget-layout-transition-plan.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,52 @@
1
+ export function areWidgetLayoutSizeUpdatesEqual(left, right) {
2
+ if (left?.size.width !== right.size.width ||
3
+ left.size.height !== right.size.height ||
4
+ left.transition.kind !== right.transition.kind ||
5
+ left.transition.durationMs !== right.transition.durationMs) {
6
+ return false;
7
+ }
8
+ const leftTransition = left.transition;
9
+ const rightTransition = right.transition;
10
+ switch (rightTransition.kind) {
11
+ case "instant":
12
+ return true;
13
+ case "timed":
14
+ if (leftTransition.kind !== "timed") {
15
+ return false;
16
+ }
17
+ return (leftTransition.easing.kind === rightTransition.easing.kind &&
18
+ leftTransition.easing.points.length ===
19
+ rightTransition.easing.points.length &&
20
+ leftTransition.easing.points.every((point, index) => point === rightTransition.easing.points[index]));
21
+ default: {
22
+ const unreachable = rightTransition;
23
+ throw new Error(`Unsupported widget layout transition: ${JSON.stringify(unreachable)}`);
24
+ }
25
+ }
26
+ }
27
+ export function planWidgetLayoutTransition(input) {
28
+ if (!Number.isFinite(input.nowMs)) {
29
+ throw new RangeError("Widget layout transition plans require finite nowMs");
30
+ }
31
+ if (areWidgetLayoutSizeUpdatesEqual(input.previous, input.next)) {
32
+ return {
33
+ kind: "unchanged",
34
+ size: { ...input.next.size },
35
+ update: {
36
+ size: { ...input.next.size },
37
+ transition: { ...input.next.transition },
38
+ },
39
+ observedAtMs: input.nowMs,
40
+ };
41
+ }
42
+ return {
43
+ kind: "instant",
44
+ size: { ...input.next.size },
45
+ update: {
46
+ size: { ...input.next.size },
47
+ transition: { ...input.next.transition },
48
+ },
49
+ startedAtMs: input.nowMs,
50
+ settledAtMs: input.nowMs,
51
+ };
52
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getuserfeedback/protocol",
3
- "version": "3.0.9",
3
+ "version": "3.0.10",
4
4
  "description": "getuserfeedback widget protocol — host surface and (later) wire protocol",
5
5
  "keywords": [
6
6
  "getuserfeedback",
package/src/host/index.ts CHANGED
@@ -13,3 +13,4 @@ export { createCommandRequestId } from "./request-id.js";
13
13
  export * from "./sdk-types.js";
14
14
  export { createUniqueId } from "./unique-id.js";
15
15
  export * from "./widget-layout-size-update.js";
16
+ export * from "./widget-layout-transition-plan.js";
@@ -0,0 +1,122 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import {
3
+ toInstantWidgetLayoutSizeUpdate,
4
+ toTimedWidgetLayoutSizeUpdate,
5
+ } from "./widget-layout-size-update.js";
6
+ import {
7
+ areWidgetLayoutSizeUpdatesEqual,
8
+ planWidgetLayoutTransition,
9
+ } from "./widget-layout-transition-plan.js";
10
+
11
+ describe("widget layout transition plan", () => {
12
+ test("plans the first instant layout update at the requested time", () => {
13
+ const next = toInstantWidgetLayoutSizeUpdate({ width: 320, height: 240 });
14
+
15
+ expect(
16
+ planWidgetLayoutTransition({
17
+ next,
18
+ nowMs: 1_000,
19
+ }),
20
+ ).toEqual({
21
+ kind: "instant",
22
+ size: { width: 320, height: 240 },
23
+ update: {
24
+ size: { width: 320, height: 240 },
25
+ transition: {
26
+ kind: "instant",
27
+ durationMs: 0,
28
+ },
29
+ },
30
+ startedAtMs: 1_000,
31
+ settledAtMs: 1_000,
32
+ });
33
+ });
34
+
35
+ test("keeps repeated identical instant updates explicit as unchanged", () => {
36
+ const previous = toInstantWidgetLayoutSizeUpdate({
37
+ width: 320,
38
+ height: 240,
39
+ });
40
+ const next = toInstantWidgetLayoutSizeUpdate({ width: 320, height: 240 });
41
+
42
+ expect(
43
+ planWidgetLayoutTransition({
44
+ previous,
45
+ next,
46
+ nowMs: 1_250,
47
+ }),
48
+ ).toMatchObject({
49
+ kind: "unchanged",
50
+ observedAtMs: 1_250,
51
+ });
52
+ expect(areWidgetLayoutSizeUpdatesEqual(previous, next)).toBe(true);
53
+ });
54
+
55
+ test("compares the full timed transition shape before it is live", () => {
56
+ const base = {
57
+ size: { width: 320, height: 240 },
58
+ durationMs: 180,
59
+ } as const;
60
+
61
+ expect(
62
+ areWidgetLayoutSizeUpdatesEqual(
63
+ toTimedWidgetLayoutSizeUpdate({ ...base, easing: [0.2, 0, 0, 1] }),
64
+ toTimedWidgetLayoutSizeUpdate({ ...base, easing: [0.2, 0, 0, 1] }),
65
+ ),
66
+ ).toBe(true);
67
+ expect(
68
+ areWidgetLayoutSizeUpdatesEqual(
69
+ toTimedWidgetLayoutSizeUpdate({ ...base, easing: [0.2, 0, 0, 1] }),
70
+ toTimedWidgetLayoutSizeUpdate({ ...base, easing: [0.3, 0, 0, 1] }),
71
+ ),
72
+ ).toBe(false);
73
+ });
74
+
75
+ test("treats size changes as instant while the live protocol is instant-only", () => {
76
+ const previous = toInstantWidgetLayoutSizeUpdate({
77
+ width: 320,
78
+ height: 240,
79
+ });
80
+ const next = toInstantWidgetLayoutSizeUpdate({ width: 320, height: 360 });
81
+
82
+ expect(
83
+ planWidgetLayoutTransition({
84
+ previous,
85
+ next,
86
+ nowMs: 1_500,
87
+ }),
88
+ ).toMatchObject({
89
+ kind: "instant",
90
+ size: { width: 320, height: 360 },
91
+ startedAtMs: 1_500,
92
+ settledAtMs: 1_500,
93
+ });
94
+ });
95
+
96
+ test("does not leak mutable references from the next update", () => {
97
+ const next = {
98
+ size: { width: 320, height: 240 },
99
+ transition: { kind: "instant", durationMs: 0 },
100
+ } as const;
101
+ const plan = planWidgetLayoutTransition({
102
+ next,
103
+ nowMs: 1_000,
104
+ });
105
+
106
+ (next.size as { height: number }).height = 360;
107
+ (next.transition as { durationMs: number }).durationMs = 1;
108
+
109
+ expect(plan.size).toEqual({ width: 320, height: 240 });
110
+ expect(plan.update.size).toEqual({ width: 320, height: 240 });
111
+ expect(plan.update.transition.durationMs).toBe(0);
112
+ });
113
+
114
+ test("rejects non-finite plan time", () => {
115
+ expect(() =>
116
+ planWidgetLayoutTransition({
117
+ next: toInstantWidgetLayoutSizeUpdate({ width: 320, height: 240 }),
118
+ nowMs: Number.NaN,
119
+ }),
120
+ ).toThrow(RangeError);
121
+ });
122
+ });
@@ -0,0 +1,97 @@
1
+ import type {
2
+ WidgetLayoutSize,
3
+ WidgetLayoutSizeUpdate,
4
+ WidgetLayoutTimedSizeUpdate,
5
+ } from "./widget-layout-size-update.js";
6
+
7
+ export type WidgetLayoutComparableSizeUpdate =
8
+ | WidgetLayoutSizeUpdate
9
+ | WidgetLayoutTimedSizeUpdate;
10
+
11
+ export type WidgetLayoutUnchangedTransitionPlan = {
12
+ kind: "unchanged";
13
+ size: WidgetLayoutSize;
14
+ update: WidgetLayoutSizeUpdate;
15
+ observedAtMs: number;
16
+ };
17
+
18
+ export type WidgetLayoutInstantTransitionPlan = {
19
+ kind: "instant";
20
+ size: WidgetLayoutSize;
21
+ update: WidgetLayoutSizeUpdate;
22
+ startedAtMs: number;
23
+ settledAtMs: number;
24
+ };
25
+
26
+ export type WidgetLayoutTransitionPlan =
27
+ | WidgetLayoutUnchangedTransitionPlan
28
+ | WidgetLayoutInstantTransitionPlan;
29
+
30
+ export function areWidgetLayoutSizeUpdatesEqual(
31
+ left: WidgetLayoutComparableSizeUpdate | undefined,
32
+ right: WidgetLayoutComparableSizeUpdate,
33
+ ): boolean {
34
+ if (
35
+ left?.size.width !== right.size.width ||
36
+ left.size.height !== right.size.height ||
37
+ left.transition.kind !== right.transition.kind ||
38
+ left.transition.durationMs !== right.transition.durationMs
39
+ ) {
40
+ return false;
41
+ }
42
+ const leftTransition = left.transition;
43
+ const rightTransition = right.transition;
44
+ switch (rightTransition.kind) {
45
+ case "instant":
46
+ return true;
47
+ case "timed":
48
+ if (leftTransition.kind !== "timed") {
49
+ return false;
50
+ }
51
+ return (
52
+ leftTransition.easing.kind === rightTransition.easing.kind &&
53
+ leftTransition.easing.points.length ===
54
+ rightTransition.easing.points.length &&
55
+ leftTransition.easing.points.every(
56
+ (point, index) => point === rightTransition.easing.points[index],
57
+ )
58
+ );
59
+ default: {
60
+ const unreachable: never = rightTransition;
61
+ throw new Error(
62
+ `Unsupported widget layout transition: ${JSON.stringify(unreachable)}`,
63
+ );
64
+ }
65
+ }
66
+ }
67
+
68
+ export function planWidgetLayoutTransition(input: {
69
+ previous?: WidgetLayoutSizeUpdate;
70
+ next: WidgetLayoutSizeUpdate;
71
+ nowMs: number;
72
+ }): WidgetLayoutTransitionPlan {
73
+ if (!Number.isFinite(input.nowMs)) {
74
+ throw new RangeError("Widget layout transition plans require finite nowMs");
75
+ }
76
+ if (areWidgetLayoutSizeUpdatesEqual(input.previous, input.next)) {
77
+ return {
78
+ kind: "unchanged",
79
+ size: { ...input.next.size },
80
+ update: {
81
+ size: { ...input.next.size },
82
+ transition: { ...input.next.transition },
83
+ },
84
+ observedAtMs: input.nowMs,
85
+ };
86
+ }
87
+ return {
88
+ kind: "instant",
89
+ size: { ...input.next.size },
90
+ update: {
91
+ size: { ...input.next.size },
92
+ transition: { ...input.next.transition },
93
+ },
94
+ startedAtMs: input.nowMs,
95
+ settledAtMs: input.nowMs,
96
+ };
97
+ }