@guardian/interactive-component-library 0.5.6 → 0.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.
@@ -1,6 +1,15 @@
1
- export function ZoomControl({ resetEnabled, onZoomIn, onZoomOut, onReset }: {
2
- resetEnabled: any;
3
- onZoomIn: any;
4
- onZoomOut: any;
5
- onReset: any;
1
+ /**
2
+ * @param {Object} props
3
+ * @param {boolean} props.resetEnabled
4
+ * @param {boolean} props.resetVisible
5
+ * @param {(event: MouseEvent) => {}} props.onZoomIn
6
+ * @param {(event: MouseEvent) => {}} props.onZoomOut
7
+ * @param {(event: MouseEvent) => {}} props.onReset
8
+ */
9
+ export function ZoomControl({ resetEnabled, resetVisible, onZoomIn, onZoomOut, onReset, }: {
10
+ resetEnabled: boolean;
11
+ resetVisible: boolean;
12
+ onZoomIn: (event: MouseEvent) => {};
13
+ onZoomOut: (event: MouseEvent) => {};
14
+ onReset: (event: MouseEvent) => {};
6
15
  }): import("preact").JSX.Element;
@@ -3,7 +3,13 @@ import { IconMinus } from "./icons/minus.js";
3
3
  import { IconPlus } from "./icons/plus.js";
4
4
  import { IconReset } from "./icons/reset.js";
5
5
  import styles from "./style.module.css.js";
6
- function ZoomControl({ resetEnabled, onZoomIn, onZoomOut, onReset }) {
6
+ function ZoomControl({
7
+ resetEnabled,
8
+ resetVisible,
9
+ onZoomIn,
10
+ onZoomOut,
11
+ onReset
12
+ }) {
7
13
  const _onZoomIn = (event) => {
8
14
  event.stopPropagation();
9
15
  onZoomIn(event);
@@ -23,6 +29,7 @@ function ZoomControl({ resetEnabled, onZoomIn, onZoomOut, onReset }) {
23
29
  "button",
24
30
  {
25
31
  className: styles.button,
32
+ style: { display: resetVisible ? "block" : "none" },
26
33
  onClick: _onReset,
27
34
  disabled: !resetEnabled,
28
35
  children: /* @__PURE__ */ jsx(
@@ -49,17 +49,6 @@ export class TextLayerRenderer {
49
49
  maxX: number;
50
50
  maxY: number;
51
51
  };
52
- /**
53
- * @param {import("../styles/Text").Text} textStyle
54
- * @param {{x: number, y: number}} position
55
- */
56
- getElementPosition(textStyle: import('../styles/Text').Text, position: {
57
- x: number;
58
- y: number;
59
- }): {
60
- left: string;
61
- top: string;
62
- };
63
52
  getCollisionBoxElement(bbox: any): HTMLDivElement;
64
53
  /**
65
54
  * Draws a `Text` element's icon on the canvas.
@@ -48,15 +48,20 @@ class TextLayerRenderer {
48
48
  );
49
49
  const textElement = this.getTextElementWithID(feature.uid);
50
50
  textElement.innerText = featureStyle.text.content;
51
- const [canvasX, canvasY] = transform.apply(point.coordinates);
51
+ const [canvasX, canvasY] = featureStyle.text.callout ? transform.apply(
52
+ projection([
53
+ featureStyle.text.callout.offsetTo.x,
54
+ featureStyle.text.callout.offsetTo.y
55
+ ])
56
+ ) : transform.apply(point.coordinates);
52
57
  const [relativeX, relativeY] = [
53
58
  canvasX / sizeInPixels[0],
54
59
  canvasY / sizeInPixels[1]
55
60
  ];
56
- const position = this.getElementPosition(featureStyle.text, {
57
- x: relativeX,
58
- y: relativeY
59
- });
61
+ const position = {
62
+ left: `${relativeX * 100}%`,
63
+ top: `${relativeY * 100}%`
64
+ };
60
65
  const elementDimens = this.styleTextElement(
61
66
  textElement,
62
67
  featureStyle.text,
@@ -78,13 +83,14 @@ class TextLayerRenderer {
78
83
  canvasCtx ?? (canvasCtx = canvasSingleton.getContext2d());
79
84
  }
80
85
  if (callout) {
81
- const canvasOffsetX = (callout.offsetBy.x - callout.leaderGap) * window.devicePixelRatio;
82
- const canvasOffsetY = callout.offsetBy.y * window.devicePixelRatio;
86
+ const [originalX, originalY] = transform.apply(point.coordinates);
87
+ const offsetDiffX = canvasX - originalX;
88
+ const offsetDiffY = canvasY - originalY;
83
89
  canvasCtx.beginPath();
84
- canvasCtx.moveTo(canvasX, canvasY);
85
- canvasCtx.lineTo(canvasX + canvasOffsetX / 2, canvasY + canvasOffsetY);
86
- canvasCtx.moveTo(canvasX + canvasOffsetX / 2, canvasY + canvasOffsetY);
87
- canvasCtx.lineTo(canvasX + canvasOffsetX, canvasY + canvasOffsetY);
90
+ canvasCtx.moveTo(originalX, originalY);
91
+ canvasCtx.lineTo(originalX + offsetDiffX / 2, originalY + offsetDiffY);
92
+ canvasCtx.moveTo(originalX + offsetDiffX / 2, canvasY);
93
+ canvasCtx.lineTo(canvasX, canvasY);
88
94
  canvasCtx.strokeStyle = callout.leaderColor;
89
95
  canvasCtx.lineWidth = callout.leaderWidth;
90
96
  canvasCtx.stroke();
@@ -95,10 +101,6 @@ class TextLayerRenderer {
95
101
  canvasCtx.save();
96
102
  let iconPosX = relativeX * viewPortSize[0];
97
103
  let iconPosY = relativeY * viewPortSize[1];
98
- if (callout) {
99
- iconPosX += callout.offsetBy.x;
100
- iconPosY += callout.offsetBy.y;
101
- }
102
104
  if (icon.position === "right") {
103
105
  iconPosX += elementDimens.width;
104
106
  } else if (icon.position === "left") {
@@ -200,12 +202,6 @@ class TextLayerRenderer {
200
202
  let minY = position.y + translateY - collisionPadding.top;
201
203
  let maxX = minX + dimens.width + collisionPadding.left + collisionPadding.right;
202
204
  let maxY = minY + dimens.height + collisionPadding.top + collisionPadding.bottom;
203
- if (textStyle.callout) {
204
- minX += textStyle.callout.offsetBy.x;
205
- minY += textStyle.callout.offsetBy.y;
206
- maxX += textStyle.callout.offsetBy.x;
207
- maxY += textStyle.callout.offsetBy.y;
208
- }
209
205
  minX = Math.floor(minX);
210
206
  minY = Math.floor(minY);
211
207
  maxX = Math.ceil(maxX);
@@ -217,22 +213,6 @@ class TextLayerRenderer {
217
213
  maxY
218
214
  };
219
215
  }
220
- /**
221
- * @param {import("../styles/Text").Text} textStyle
222
- * @param {{x: number, y: number}} position
223
- */
224
- getElementPosition(textStyle, position) {
225
- if (textStyle.callout) {
226
- return {
227
- left: `calc(${position.x * 100}% + ${textStyle.callout.offsetBy.x}px)`,
228
- top: `calc(${position.y * 100}% + ${textStyle.callout.offsetBy.y}px)`
229
- };
230
- }
231
- return {
232
- left: `${position.x * 100}%`,
233
- top: `${position.y * 100}%`
234
- };
235
- }
236
216
  getCollisionBoxElement(bbox) {
237
217
  const element = document.createElement("div");
238
218
  const style = element.style;
@@ -2,9 +2,9 @@
2
2
  * TODO: add leader 'style' option, e.g. kink, direct, manhattan, etc.
3
3
  *
4
4
  * @typedef CalloutOptions
5
- * @property {{ x: number, y: number }} offsetBy { x, y } offset in pixels, relative to the text position.
5
+ * @property {{ x: number, y: number }} offsetTo { x, y } map coordinates to offset the text to.
6
6
  *
7
- * E.g. { x: 10, y: 20 } will move the callout 10 pixels to the right and 20 pixels down.
7
+ * E.g. { x: 200, y: 300 } will place the callout at map coordinates (200, 300).
8
8
  * @property {number} [leaderGap=5] Distance in pixels between the leader line and the text
9
9
  * @property {string} [leaderColor="#121212"] Hex colour of the leader line
10
10
  * @property {number} [leaderWidth=1] Stroke width of the leader line
@@ -106,16 +106,16 @@ export class Text implements TextStyle {
106
106
  */
107
107
  export type CalloutOptions = {
108
108
  /**
109
- * { x, y } offset in pixels, relative to the text position.
109
+ * { x, y } map coordinates to offset the text to.
110
110
  *
111
- * E.g. { x: 10, y: 20 } will move the callout 10 pixels to the right and 20 pixels down.
111
+ * E.g. { x: 200, y: 300 } will place the callout at map coordinates (200, 300).
112
112
  */
113
113
  /**
114
- * { x, y } offset in pixels, relative to the text position.
114
+ * { x, y } map coordinates to offset the text to.
115
115
  *
116
- * E.g. { x: 10, y: 20 } will move the callout 10 pixels to the right and 20 pixels down.
116
+ * E.g. { x: 200, y: 300 } will place the callout at map coordinates (200, 300).
117
117
  */
118
- offsetBy: {
118
+ offsetTo: {
119
119
  x: number;
120
120
  y: number;
121
121
  };
@@ -16,7 +16,7 @@ class Text {
16
16
  * @param {TextStyle} [options] Style options
17
17
  */
18
18
  constructor(options) {
19
- var _a, _b, _c, _d, _e, _f, _g, _h;
19
+ var _a, _b, _c, _d, _e, _f, _g;
20
20
  this.content = options == null ? void 0 : options.content;
21
21
  this.anchor = (options == null ? void 0 : options.anchor) || TextAnchor.CENTER;
22
22
  this.fontFamily = (options == null ? void 0 : options.fontFamily) || "var(--text-sans)";
@@ -28,17 +28,16 @@ class Text {
28
28
  this.radialOffset = (options == null ? void 0 : options.radialOffset) || 0;
29
29
  if (options.callout) {
30
30
  this.callout = options.callout;
31
- (_a = this.callout).offsetBy ?? (_a.offsetBy = { x: 0, y: 0 });
32
- (_b = this.callout).leaderGap ?? (_b.leaderGap = 5);
33
- (_c = this.callout).leaderColor ?? (_c.leaderColor = "#121212");
34
- (_d = this.callout).leaderWidth ?? (_d.leaderWidth = 1);
31
+ (_a = this.callout).leaderGap ?? (_a.leaderGap = 5);
32
+ (_b = this.callout).leaderColor ?? (_b.leaderColor = "#121212");
33
+ (_c = this.callout).leaderWidth ?? (_c.leaderWidth = 1);
35
34
  }
36
35
  if (options.icon) {
37
36
  this.icon = options.icon;
38
- (_e = this.icon).shape ?? (_e.shape = "circle");
39
- (_f = this.icon).position ?? (_f.position = "left");
40
- (_g = this.icon).size ?? (_g.size = 10);
41
- (_h = this.icon).padding ?? (_h.padding = 5);
37
+ (_d = this.icon).shape ?? (_d.shape = "circle");
38
+ (_e = this.icon).position ?? (_e.position = "left");
39
+ (_f = this.icon).size ?? (_f.size = 10);
40
+ (_g = this.icon).padding ?? (_g.padding = 5);
42
41
  }
43
42
  }
44
43
  /**
package/dist/style.css CHANGED
@@ -1237,6 +1237,18 @@ button {
1237
1237
  .border-color--undeclared {
1238
1238
  border-color: var(--undeclared) !important;
1239
1239
  }
1240
+ .border-color--ind-dem {
1241
+ border-color: var(--ind-dem) !important;
1242
+ }
1243
+ .border-color--lib {
1244
+ border-color: var(--lib) !important;
1245
+ }
1246
+ .border-color--grn {
1247
+ border-color: var(--grn) !important;
1248
+ }
1249
+ .border-color--ken {
1250
+ border-color: var(--ken) !important;
1251
+ }
1240
1252
  /* BEFORE-ELEMENT-COLOR ----------------------------------------------------- */
1241
1253
  .before-color--dem:before {
1242
1254
  background-color: var(--dem) !important;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@guardian/interactive-component-library",
3
3
  "private": false,
4
- "version": "0.5.6",
4
+ "version": "0.6.0",
5
5
  "packageManager": "pnpm@8.4.0",
6
6
  "repository": {
7
7
  "type": "git",