@getuserfeedback/protocol 3.0.8 → 3.0.9

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.
@@ -2,14 +2,43 @@ export type WidgetLayoutSize = {
2
2
  width: number;
3
3
  height: number;
4
4
  };
5
- export type WidgetLayoutSizeTransition = {
5
+ export type WidgetLayoutCubicBezier = readonly [
6
+ x1: number,
7
+ y1: number,
8
+ x2: number,
9
+ y2: number
10
+ ];
11
+ export type WidgetLayoutInstantSizeTransition = {
6
12
  kind: "instant";
7
13
  durationMs: 0;
8
14
  };
15
+ export type WidgetLayoutTimedSizeTransition = {
16
+ kind: "timed";
17
+ durationMs: number;
18
+ easing: {
19
+ kind: "cubic-bezier";
20
+ points: WidgetLayoutCubicBezier;
21
+ };
22
+ };
23
+ export type WidgetLayoutSizeTransition = WidgetLayoutInstantSizeTransition;
9
24
  export type WidgetLayoutSizeUpdate = {
10
25
  size: WidgetLayoutSize;
11
26
  transition: WidgetLayoutSizeTransition;
12
27
  };
13
- export declare const INSTANT_WIDGET_LAYOUT_SIZE_TRANSITION: WidgetLayoutSizeTransition;
28
+ export type WidgetLayoutTimedSizeUpdate = {
29
+ size: WidgetLayoutSize;
30
+ transition: WidgetLayoutTimedSizeTransition;
31
+ };
32
+ export declare const INSTANT_WIDGET_LAYOUT_SIZE_TRANSITION: WidgetLayoutInstantSizeTransition;
33
+ export declare function isWidgetLayoutCubicBezier(points: unknown): points is WidgetLayoutCubicBezier;
14
34
  export declare function toInstantWidgetLayoutSizeUpdate(size: WidgetLayoutSize): WidgetLayoutSizeUpdate;
35
+ export declare function toTimedWidgetLayoutSizeTransition(input: {
36
+ durationMs: number;
37
+ easing: WidgetLayoutCubicBezier;
38
+ }): WidgetLayoutTimedSizeTransition;
39
+ export declare function toTimedWidgetLayoutSizeUpdate(input: {
40
+ size: WidgetLayoutSize;
41
+ durationMs: number;
42
+ easing: WidgetLayoutCubicBezier;
43
+ }): WidgetLayoutTimedSizeUpdate;
15
44
  //# sourceMappingURL=widget-layout-size-update.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"widget-layout-size-update.d.ts","sourceRoot":"","sources":["../../src/host/widget-layout-size-update.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GAAG;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG;IACxC,IAAI,EAAE,SAAS,CAAC;IAChB,UAAU,EAAE,CAAC,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACpC,IAAI,EAAE,gBAAgB,CAAC;IACvB,UAAU,EAAE,0BAA0B,CAAC;CACvC,CAAC;AAEF,eAAO,MAAM,qCAAqC,EAAE,0BAIlD,CAAC;AAEH,wBAAgB,+BAA+B,CAC9C,IAAI,EAAE,gBAAgB,GACpB,sBAAsB,CAKxB"}
1
+ {"version":3,"file":"widget-layout-size-update.d.ts","sourceRoot":"","sources":["../../src/host/widget-layout-size-update.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GAAG;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG,SAAS;IAC9C,EAAE,EAAE,MAAM;IACV,EAAE,EAAE,MAAM;IACV,EAAE,EAAE,MAAM;IACV,EAAE,EAAE,MAAM;CACV,CAAC;AAEF,MAAM,MAAM,iCAAiC,GAAG;IAC/C,IAAI,EAAE,SAAS,CAAC;IAChB,UAAU,EAAE,CAAC,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,+BAA+B,GAAG;IAC7C,IAAI,EAAE,OAAO,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE;QACP,IAAI,EAAE,cAAc,CAAC;QACrB,MAAM,EAAE,uBAAuB,CAAC;KAChC,CAAC;CACF,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG,iCAAiC,CAAC;AAE3E,MAAM,MAAM,sBAAsB,GAAG;IACpC,IAAI,EAAE,gBAAgB,CAAC;IACvB,UAAU,EAAE,0BAA0B,CAAC;CACvC,CAAC;AAEF,MAAM,MAAM,2BAA2B,GAAG;IACzC,IAAI,EAAE,gBAAgB,CAAC;IACvB,UAAU,EAAE,+BAA+B,CAAC;CAC5C,CAAC;AAEF,eAAO,MAAM,qCAAqC,EAAE,iCAIlD,CAAC;AAKH,wBAAgB,yBAAyB,CACxC,MAAM,EAAE,OAAO,GACb,MAAM,IAAI,uBAAuB,CAenC;AAED,wBAAgB,+BAA+B,CAC9C,IAAI,EAAE,gBAAgB,GACpB,sBAAsB,CAKxB;AAED,wBAAgB,iCAAiC,CAAC,KAAK,EAAE;IACxD,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,uBAAuB,CAAC;CAChC,GAAG,+BAA+B,CAmBlC;AAED,wBAAgB,6BAA6B,CAAC,KAAK,EAAE;IACpD,IAAI,EAAE,gBAAgB,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,uBAAuB,CAAC;CAChC,GAAG,2BAA2B,CAQ9B"}
@@ -2,9 +2,49 @@ export const INSTANT_WIDGET_LAYOUT_SIZE_TRANSITION = {
2
2
  kind: "instant",
3
3
  durationMs: 0,
4
4
  };
5
+ const isFiniteNumber = (value) => typeof value === "number" && Number.isFinite(value);
6
+ export function isWidgetLayoutCubicBezier(points) {
7
+ if (!Array.isArray(points) || points.length !== 4) {
8
+ return false;
9
+ }
10
+ const [x1, y1, x2, y2] = points;
11
+ return (isFiniteNumber(x1) &&
12
+ x1 >= 0 &&
13
+ x1 <= 1 &&
14
+ isFiniteNumber(y1) &&
15
+ isFiniteNumber(x2) &&
16
+ x2 >= 0 &&
17
+ x2 <= 1 &&
18
+ isFiniteNumber(y2));
19
+ }
5
20
  export function toInstantWidgetLayoutSizeUpdate(size) {
6
21
  return {
7
22
  size: { ...size },
8
23
  transition: INSTANT_WIDGET_LAYOUT_SIZE_TRANSITION,
9
24
  };
10
25
  }
26
+ export function toTimedWidgetLayoutSizeTransition(input) {
27
+ if (!Number.isFinite(input.durationMs) || input.durationMs <= 0) {
28
+ throw new RangeError("Timed widget layout transitions require durationMs > 0");
29
+ }
30
+ if (!isWidgetLayoutCubicBezier(input.easing)) {
31
+ throw new RangeError("Timed widget layout transitions require cubic-bezier x control points in [0, 1] and finite y control points");
32
+ }
33
+ return {
34
+ kind: "timed",
35
+ durationMs: input.durationMs,
36
+ easing: {
37
+ kind: "cubic-bezier",
38
+ points: [...input.easing],
39
+ },
40
+ };
41
+ }
42
+ export function toTimedWidgetLayoutSizeUpdate(input) {
43
+ return {
44
+ size: { ...input.size },
45
+ transition: toTimedWidgetLayoutSizeTransition({
46
+ durationMs: input.durationMs,
47
+ easing: input.easing,
48
+ }),
49
+ };
50
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getuserfeedback/protocol",
3
- "version": "3.0.8",
3
+ "version": "3.0.9",
4
4
  "description": "getuserfeedback widget protocol — host surface and (later) wire protocol",
5
5
  "keywords": [
6
6
  "getuserfeedback",
@@ -1,7 +1,10 @@
1
1
  import { describe, expect, test } from "bun:test";
2
2
  import {
3
3
  INSTANT_WIDGET_LAYOUT_SIZE_TRANSITION,
4
+ isWidgetLayoutCubicBezier,
4
5
  toInstantWidgetLayoutSizeUpdate,
6
+ toTimedWidgetLayoutSizeTransition,
7
+ toTimedWidgetLayoutSizeUpdate,
5
8
  } from "./widget-layout-size-update.js";
6
9
 
7
10
  describe("widget layout size update", () => {
@@ -22,4 +25,66 @@ describe("widget layout size update", () => {
22
25
  toInstantWidgetLayoutSizeUpdate({ width: 1, height: 1 }).transition,
23
26
  ).toBe(INSTANT_WIDGET_LAYOUT_SIZE_TRANSITION);
24
27
  });
28
+
29
+ test("keeps the existing size update contract instant-only", () => {
30
+ const update = toInstantWidgetLayoutSizeUpdate({ width: 320, height: 240 });
31
+
32
+ expect(update.transition.kind).toBe("instant");
33
+ });
34
+
35
+ test("wraps a host size in the timed transition contract", () => {
36
+ expect(
37
+ toTimedWidgetLayoutSizeUpdate({
38
+ size: { width: 320, height: 240 },
39
+ durationMs: 180,
40
+ easing: [0.2, 0, 0, 1],
41
+ }),
42
+ ).toEqual({
43
+ size: { width: 320, height: 240 },
44
+ transition: {
45
+ kind: "timed",
46
+ durationMs: 180,
47
+ easing: {
48
+ kind: "cubic-bezier",
49
+ points: [0.2, 0, 0, 1],
50
+ },
51
+ },
52
+ });
53
+ });
54
+
55
+ test("accepts cubic-bezier y control point overshoot", () => {
56
+ expect(isWidgetLayoutCubicBezier([0.34, -0.2, 0.64, 1.35])).toBe(true);
57
+ expect(
58
+ toTimedWidgetLayoutSizeTransition({
59
+ durationMs: 220,
60
+ easing: [0.34, -0.2, 0.64, 1.35],
61
+ }).easing.points,
62
+ ).toEqual([0.34, -0.2, 0.64, 1.35]);
63
+ });
64
+
65
+ test("fails closed for non-array cubic-bezier input", () => {
66
+ expect(isWidgetLayoutCubicBezier(null)).toBe(false);
67
+ expect(isWidgetLayoutCubicBezier({ 0: 0.2, 1: 0, 2: 0, 3: 1 })).toBe(false);
68
+ expect(isWidgetLayoutCubicBezier("0.2,0,0,1")).toBe(false);
69
+ });
70
+
71
+ test("rejects cubic-bezier x control points outside normalized time", () => {
72
+ expect(isWidgetLayoutCubicBezier([-0.01, 0, 0.5, 1])).toBe(false);
73
+ expect(isWidgetLayoutCubicBezier([0.5, 0, 1.01, 1])).toBe(false);
74
+ expect(() =>
75
+ toTimedWidgetLayoutSizeTransition({
76
+ durationMs: 220,
77
+ easing: [-0.01, 0, 0.5, 1],
78
+ }),
79
+ ).toThrow(RangeError);
80
+ });
81
+
82
+ test("rejects invalid timed transition duration", () => {
83
+ expect(() =>
84
+ toTimedWidgetLayoutSizeTransition({
85
+ durationMs: 0,
86
+ easing: [0.2, 0, 0, 1],
87
+ }),
88
+ ).toThrow(RangeError);
89
+ });
25
90
  });
@@ -3,22 +3,67 @@ export type WidgetLayoutSize = {
3
3
  height: number;
4
4
  };
5
5
 
6
- export type WidgetLayoutSizeTransition = {
6
+ export type WidgetLayoutCubicBezier = readonly [
7
+ x1: number,
8
+ y1: number,
9
+ x2: number,
10
+ y2: number,
11
+ ];
12
+
13
+ export type WidgetLayoutInstantSizeTransition = {
7
14
  kind: "instant";
8
15
  durationMs: 0;
9
16
  };
10
17
 
18
+ export type WidgetLayoutTimedSizeTransition = {
19
+ kind: "timed";
20
+ durationMs: number;
21
+ easing: {
22
+ kind: "cubic-bezier";
23
+ points: WidgetLayoutCubicBezier;
24
+ };
25
+ };
26
+
27
+ export type WidgetLayoutSizeTransition = WidgetLayoutInstantSizeTransition;
28
+
11
29
  export type WidgetLayoutSizeUpdate = {
12
30
  size: WidgetLayoutSize;
13
31
  transition: WidgetLayoutSizeTransition;
14
32
  };
15
33
 
16
- export const INSTANT_WIDGET_LAYOUT_SIZE_TRANSITION: WidgetLayoutSizeTransition =
34
+ export type WidgetLayoutTimedSizeUpdate = {
35
+ size: WidgetLayoutSize;
36
+ transition: WidgetLayoutTimedSizeTransition;
37
+ };
38
+
39
+ export const INSTANT_WIDGET_LAYOUT_SIZE_TRANSITION: WidgetLayoutInstantSizeTransition =
17
40
  {
18
41
  kind: "instant",
19
42
  durationMs: 0,
20
43
  };
21
44
 
45
+ const isFiniteNumber = (value: unknown): value is number =>
46
+ typeof value === "number" && Number.isFinite(value);
47
+
48
+ export function isWidgetLayoutCubicBezier(
49
+ points: unknown,
50
+ ): points is WidgetLayoutCubicBezier {
51
+ if (!Array.isArray(points) || points.length !== 4) {
52
+ return false;
53
+ }
54
+ const [x1, y1, x2, y2] = points;
55
+ return (
56
+ isFiniteNumber(x1) &&
57
+ x1 >= 0 &&
58
+ x1 <= 1 &&
59
+ isFiniteNumber(y1) &&
60
+ isFiniteNumber(x2) &&
61
+ x2 >= 0 &&
62
+ x2 <= 1 &&
63
+ isFiniteNumber(y2)
64
+ );
65
+ }
66
+
22
67
  export function toInstantWidgetLayoutSizeUpdate(
23
68
  size: WidgetLayoutSize,
24
69
  ): WidgetLayoutSizeUpdate {
@@ -27,3 +72,41 @@ export function toInstantWidgetLayoutSizeUpdate(
27
72
  transition: INSTANT_WIDGET_LAYOUT_SIZE_TRANSITION,
28
73
  };
29
74
  }
75
+
76
+ export function toTimedWidgetLayoutSizeTransition(input: {
77
+ durationMs: number;
78
+ easing: WidgetLayoutCubicBezier;
79
+ }): WidgetLayoutTimedSizeTransition {
80
+ if (!Number.isFinite(input.durationMs) || input.durationMs <= 0) {
81
+ throw new RangeError(
82
+ "Timed widget layout transitions require durationMs > 0",
83
+ );
84
+ }
85
+ if (!isWidgetLayoutCubicBezier(input.easing)) {
86
+ throw new RangeError(
87
+ "Timed widget layout transitions require cubic-bezier x control points in [0, 1] and finite y control points",
88
+ );
89
+ }
90
+ return {
91
+ kind: "timed",
92
+ durationMs: input.durationMs,
93
+ easing: {
94
+ kind: "cubic-bezier",
95
+ points: [...input.easing],
96
+ },
97
+ };
98
+ }
99
+
100
+ export function toTimedWidgetLayoutSizeUpdate(input: {
101
+ size: WidgetLayoutSize;
102
+ durationMs: number;
103
+ easing: WidgetLayoutCubicBezier;
104
+ }): WidgetLayoutTimedSizeUpdate {
105
+ return {
106
+ size: { ...input.size },
107
+ transition: toTimedWidgetLayoutSizeTransition({
108
+ durationMs: input.durationMs,
109
+ easing: input.easing,
110
+ }),
111
+ };
112
+ }