@tixyel/streamelements 7.14.0 → 7.14.1

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/index.d.ts CHANGED
@@ -2519,6 +2519,73 @@ declare class ElementHelper {
2519
2519
  * ```
2520
2520
  */
2521
2521
  escapeHtml(value: string): string;
2522
+ /**
2523
+ * Get the relative position of a square
2524
+ * @param dimensions - The square dimensions and positions
2525
+ * @returns All the relative positions
2526
+ * @example
2527
+ * ```js
2528
+ * const positions = relativePositions({ width: 10, height: 10, left: 20, top: 20 });
2529
+ * // positions.center = { x: 25, y: 25 }
2530
+ * // positions.bottom = { x: 25, y: 30 }
2531
+ * // ...
2532
+ * ```
2533
+ */
2534
+ relativePositions({ width, height, left, top, }: {
2535
+ width: number;
2536
+ height: number;
2537
+ left: number;
2538
+ top: number;
2539
+ }): {
2540
+ center: {
2541
+ x: number;
2542
+ y: number;
2543
+ };
2544
+ top: {
2545
+ x: number;
2546
+ y: number;
2547
+ };
2548
+ bottom: {
2549
+ x: number;
2550
+ y: number;
2551
+ };
2552
+ left: {
2553
+ x: number;
2554
+ y: number;
2555
+ };
2556
+ right: {
2557
+ x: number;
2558
+ y: number;
2559
+ };
2560
+ 'top-left': {
2561
+ x: number;
2562
+ y: number;
2563
+ };
2564
+ 'top-right': {
2565
+ x: number;
2566
+ y: number;
2567
+ };
2568
+ 'bottom-left': {
2569
+ x: number;
2570
+ y: number;
2571
+ };
2572
+ 'bottom-right': {
2573
+ x: number;
2574
+ y: number;
2575
+ };
2576
+ };
2577
+ getRelativePositionToAncestor(element: HTMLElement, ancestor: HTMLElement): {
2578
+ left: number;
2579
+ top: number;
2580
+ width: number;
2581
+ height: number;
2582
+ };
2583
+ svg: {
2584
+ getDimensionsFromViewBox(svgElement: SVGElement | string): {
2585
+ width: number;
2586
+ height: number;
2587
+ };
2588
+ };
2522
2589
  }
2523
2590
  type CSSValue = string | number | null | undefined;
2524
2591
 
package/dist/index.es.js CHANGED
@@ -156,6 +156,24 @@ var e = Object.defineProperty, t = (t, n) => {
156
156
  return n ? Number(r.toFixed(n)) : Math.round(r);
157
157
  }
158
158
  }, r = class {
159
+ constructor() {
160
+ this.svg = { getDimensionsFromViewBox(e) {
161
+ let t;
162
+ if (typeof e == "string") {
163
+ let n = e.match(/viewBox="([^"]+)"/);
164
+ if (!n) throw Error("Invalid SVG: viewBox not found");
165
+ t = n[1].split(" ").map(Number);
166
+ } else {
167
+ let n = e.getAttribute("viewBox");
168
+ if (!n) throw Error("Invalid SVG: viewBox not found");
169
+ t = n.split(" ").map(Number);
170
+ }
171
+ return {
172
+ width: t[2],
173
+ height: t[3]
174
+ };
175
+ } };
176
+ }
159
177
  mergeSpanStyles(e, t, n) {
160
178
  let r = t.match(/^<span(?: class="[^"]*")? style="([^"]*)">(.*)<\/span>$/s);
161
179
  if (r) {
@@ -264,6 +282,55 @@ var e = Object.defineProperty, t = (t, n) => {
264
282
  };
265
283
  return e.replace(/[&<>"']/g, (e) => t[e]);
266
284
  }
285
+ relativePositions({ width: e, height: t, left: n, top: r }) {
286
+ return {
287
+ center: {
288
+ x: n + e / 2,
289
+ y: r + t / 2
290
+ },
291
+ top: {
292
+ x: n + e / 2,
293
+ y: r
294
+ },
295
+ bottom: {
296
+ x: n + e / 2,
297
+ y: r + t
298
+ },
299
+ left: {
300
+ x: n,
301
+ y: r + t / 2
302
+ },
303
+ right: {
304
+ x: n + e,
305
+ y: r + t / 2
306
+ },
307
+ "top-left": {
308
+ x: n,
309
+ y: r
310
+ },
311
+ "top-right": {
312
+ x: n + e,
313
+ y: r
314
+ },
315
+ "bottom-left": {
316
+ x: n,
317
+ y: r + t
318
+ },
319
+ "bottom-right": {
320
+ x: n + e,
321
+ y: r + t
322
+ }
323
+ };
324
+ }
325
+ getRelativePositionToAncestor(e, t) {
326
+ let n = e.getBoundingClientRect(), r = t.getBoundingClientRect(), i = t === document.body, a = t === document.documentElement, o = window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft, s = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop, c = a || i ? o : t.scrollLeft, l = a || i ? s : t.scrollTop, u = t.clientLeft || 0, d = t.clientTop || 0, f = n.left - r.left + c - u, p = n.top - r.top + l - d;
327
+ return {
328
+ left: Math.round(f),
329
+ top: Math.round(p),
330
+ width: Math.round(n.width),
331
+ height: Math.round(n.height)
332
+ };
333
+ }
267
334
  }, i = class {
268
335
  flatten(e, t = !0, n = "") {
269
336
  let r = {};