@tixyel/streamelements 7.0.4 → 7.1.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.
package/dist/index.d.ts CHANGED
@@ -2414,15 +2414,28 @@ declare class ElementHelper {
2414
2414
  * Adds 'container' class and data-index to all parent elements, and wraps each character in a span with class 'char' and data-index.
2415
2415
  * @param htmlString - The input HTML string containing formatted text elements (span, strong, em, etc).
2416
2416
  * @param startIndex - The starting index for the data-index attribute (default is 0).
2417
+ * @param preserveInterElementWhitespace - Whether to preserve whitespace between elements (default is false).
2418
+ * @param options - Optional settings for splitting text, including skipWhitespaceIndex to control index incrementing for whitespace characters.
2417
2419
  * @returns - A new HTML string with containers and character-level indexing.
2418
2420
  * @example
2419
2421
  * ```javascript
2420
2422
  * const result = splitTextToChars('<span>TesTe</span> <strong>bold</strong>', 0);
2421
2423
  * console.log(result);
2422
2424
  * // Output: '<span class="container" data-index="0"><span class="char" data-index="0">T</span><span class="char" data-index="1">e</span>...'
2425
+ *
2426
+ * // Example with skipWhitespaceIndex
2427
+ * const resultSkipWhitespace = splitTextToChars('<span>Hello World</span>', 0, false, { skipWhitespaceIndex: true });
2428
+ * // The space character will have data-index but won't increment index for subsequent characters
2423
2429
  * ```
2424
2430
  */
2425
- splitTextToChars(htmlString: string, startIndex?: number, preserveInterElementWhitespace?: boolean): string;
2431
+ splitTextToChars(htmlString: string, startIndex?: number, preserveInterElementWhitespace?: boolean, options?: {
2432
+ /**
2433
+ * If true, skips incrementing the index for whitespace characters (space, newline, tab).
2434
+ * These characters will still have a data-index, but it won't be incremented for subsequent characters.
2435
+ * Default is true.
2436
+ */
2437
+ skipWhitespaceIndex?: boolean;
2438
+ }): string;
2426
2439
  }
2427
2440
 
2428
2441
  declare class ObjectHelper {
@@ -2986,7 +2999,7 @@ declare class UtilsHelper {
2986
2999
  userId: string;
2987
3000
  name: string;
2988
3001
  broadcasterId?: string;
2989
- }, session: StreamElements.Session.Data, checkWithAPI?: boolean): Promise<3 | 1 | 2>;
3002
+ }, session: StreamElements.Session.Data, checkWithAPI?: boolean): Promise<1 | 2 | 3>;
2990
3003
  /**
2991
3004
  * Identifies a user based on the received event and session data, returning their ID, name, role, badges, and top status.
2992
3005
  * @param receivedEvent - The event received from the provider (Twitch or YouTube) containing user information.
@@ -3015,7 +3028,8 @@ declare class UtilsHelper {
3015
3028
  * // }
3016
3029
  * ```
3017
3030
  */
3018
- identifyUser(receivedEvent: StreamElements.Event.Provider.Twitch.Message | StreamElements.Event.Provider.YouTube.Message, session: StreamElements.Session.Data): Promise<IdentifyYouTubeResult | IdentifyTwitchResult | undefined>;
3031
+ identifyUser(provider: 'twitch', receivedEvent: StreamElements.Event.Provider.Twitch.Message, session: StreamElements.Session.Data): Promise<IdentifyTwitchResult | undefined>;
3032
+ identifyUser(provider: 'youtube', receivedEvent: StreamElements.Event.Provider.YouTube.Message, session: StreamElements.Session.Data): Promise<IdentifyYouTubeResult | undefined>;
3019
3033
  }
3020
3034
  type TopType = {
3021
3035
  gifter: boolean;
package/dist/index.es.js CHANGED
@@ -289,33 +289,35 @@ var e = class {
289
289
  let s = r * (o.clientWidth * t / e.offsetWidth), c = new i().balance(s, a.minFontSize, a.maxFontSize);
290
290
  return e.style.fontSize = c + "px", e;
291
291
  }
292
- splitTextToChars(e, t = 0, n = !1) {
293
- let r = new DOMParser(), i = document.createElement("div"), a = t;
294
- function o(e) {
292
+ splitTextToChars(e, t = 0, n = !1, r = {}) {
293
+ let { skipWhitespaceIndex: i = !0 } = r, a = new DOMParser(), o = document.createElement("div"), s = t;
294
+ function c(e) {
295
295
  if (e.nodeType === Node.TEXT_NODE) {
296
- let t = (e.textContent || "").split("").map((e, t) => {
297
- let n = document.createElement("span");
298
- return n.classList.add("char"), n.dataset.index = String(a), n.dataset.exclusivityIndex = String(t), n.style.setProperty("--char-index", String(a)), n.style.setProperty("--exclusivity-index", String(t)), e === " " || e === "\n" || e === " " ? n.style.whiteSpace = "pre-wrap" : a++, n.textContent = e, n;
299
- }), n = document.createDocumentFragment();
300
- return t.forEach((e) => n.appendChild(e)), n;
296
+ let t = e.textContent || "", n = 0, r = t.split("").map((e) => {
297
+ let t = document.createElement("span");
298
+ t.classList.add("char"), t.dataset.index = String(s), t.dataset.exclusivityIndex = String(n), t.dataset.type = "char", t.style.setProperty("--char-index", String(s)), t.style.setProperty("--exclusivity-index", String(n));
299
+ let r = e === " " || e === "\n" || e === " ";
300
+ return r && (t.style.whiteSpace = "pre-wrap", t.classList.remove("char"), t.classList.add("whitespace"), t.dataset.type = "whitespace"), (!r || !i) && (s++, n++), t.textContent = e, t;
301
+ }), a = document.createDocumentFragment();
302
+ return r.forEach((e) => a.appendChild(e)), a;
301
303
  } else if (e.nodeType === Node.ELEMENT_NODE) {
302
304
  let t = e.cloneNode(!1);
303
- return t.classList.add("container"), t.dataset.index = String(a), t.style.setProperty("--char-index", String(a)), t.style.setProperty("--exclusivity-index", String(a)), a++, e.childNodes.forEach((e) => {
304
- let n = o(e);
305
+ return t.classList.add("container"), t.dataset.index = String(s), t.dataset.type = "container", t.style.setProperty("--char-index", String(s)), t.style.setProperty("--exclusivity-index", String(s)), s++, e.childNodes.forEach((e) => {
306
+ let n = c(e);
305
307
  t.appendChild(n);
306
308
  }), t;
307
309
  }
308
310
  return e.cloneNode(!0);
309
311
  }
310
- r.parseFromString(e, "text/html").body.childNodes.forEach((e) => {
312
+ a.parseFromString(e, "text/html").body.childNodes.forEach((e) => {
311
313
  if (!n && e.nodeType === Node.TEXT_NODE && !e.textContent?.trim()) return;
312
- let t = o(e);
313
- i.appendChild(t);
314
+ let t = c(e);
315
+ o.appendChild(t);
314
316
  });
315
- let s = "";
316
- return Array.from(i.childNodes).forEach((e) => {
317
- e.nodeType === Node.TEXT_NODE ? s += e.textContent : s += e.outerHTML;
318
- }), s;
317
+ let l = "";
318
+ return Array.from(o.childNodes).forEach((e) => {
319
+ e.nodeType === Node.TEXT_NODE ? l += e.textContent : l += e.outerHTML;
320
+ }), l;
319
321
  }
320
322
  }, o = class {
321
323
  flatten(e, t = !0, n = "") {
@@ -10254,11 +10256,7 @@ var M = class {
10254
10256
  continue;
10255
10257
  }
10256
10258
  n.length < c && this.emit("warn", /* @__PURE__ */ Error(`User "${e}" could only receive ${n.length} badge(s), below the configured minimum of ${c}`));
10257
- let i = o.length + 1, a = n.some((e) => [
10258
- "subscriber",
10259
- "prime",
10260
- "founder"
10261
- ].includes(String(e).toLocaleLowerCase())), s = new I(`fake_user_${i.toString().padStart(2, "0")}_${Math.random().toString(36).slice(2, 8)}+${this.id}`, e, n, a, a ? t.getRandomSubTier() : void 0);
10259
+ let i = o.length + 1, a = n.some((e) => ["subscriber"].includes(String(e).toLocaleLowerCase())), s = new I(`fake_user_${i.toString().padStart(2, "0")}_${Math.random().toString(36).slice(2, 8)}+${this.id}`, e, n, a, a ? t.getRandomSubTier() : void 0);
10262
10260
  o.push(s);
10263
10261
  }
10264
10262
  return o.length < i.length && this.emit("warn", /* @__PURE__ */ Error("Some users could not be assigned badges due to limits. Consider increasing limits or adding more badges.")), o;
@@ -10388,100 +10386,92 @@ var M = class {
10388
10386
  }
10389
10387
  return 1;
10390
10388
  }
10391
- async identifyUser(e, t) {
10392
- let n = new D().parseProvider(e), r = (e) => ({
10393
- gifter: t["subscriber-alltime-gifter"].name === e,
10389
+ async identifyUser(e, t, n) {
10390
+ let r = (e) => ({
10391
+ gifter: n["subscriber-alltime-gifter"].name === e,
10394
10392
  tip: {
10395
10393
  session: {
10396
- donator: t["tip-session-top-donator"].name === e,
10397
- donation: t["tip-session-top-donation"].name === e
10394
+ donator: n["tip-session-top-donator"].name === e,
10395
+ donation: n["tip-session-top-donation"].name === e
10398
10396
  },
10399
10397
  weekly: {
10400
- donator: t["tip-weekly-top-donator"].name === e,
10401
- donation: t["tip-weekly-top-donation"].name === e
10398
+ donator: n["tip-weekly-top-donator"].name === e,
10399
+ donation: n["tip-weekly-top-donation"].name === e
10402
10400
  },
10403
10401
  monthly: {
10404
- donator: t["tip-monthly-top-donator"].name === e,
10405
- donation: t["tip-monthly-top-donation"].name === e
10402
+ donator: n["tip-monthly-top-donator"].name === e,
10403
+ donation: n["tip-monthly-top-donation"].name === e
10406
10404
  },
10407
10405
  alltime: {
10408
- donator: t["tip-alltime-top-donator"].name === e,
10409
- donation: t["tip-alltime-top-donation"].name === e
10406
+ donator: n["tip-alltime-top-donator"].name === e,
10407
+ donation: n["tip-alltime-top-donation"].name === e
10410
10408
  }
10411
10409
  },
10412
10410
  cheer: {
10413
10411
  session: {
10414
- donator: t["cheer-session-top-donator"].name === e,
10415
- amount: t["cheer-session-top-donation"].name === e
10412
+ donator: n["cheer-session-top-donator"].name === e,
10413
+ amount: n["cheer-session-top-donation"].name === e
10416
10414
  },
10417
10415
  weekly: {
10418
- donator: t["cheer-weekly-top-donator"].name === e,
10419
- amount: t["cheer-weekly-top-donation"].name === e
10416
+ donator: n["cheer-weekly-top-donator"].name === e,
10417
+ amount: n["cheer-weekly-top-donation"].name === e
10420
10418
  },
10421
10419
  monthly: {
10422
- donator: t["cheer-monthly-top-donator"].name === e,
10423
- amount: t["cheer-monthly-top-donation"].name === e
10420
+ donator: n["cheer-monthly-top-donator"].name === e,
10421
+ amount: n["cheer-monthly-top-donation"].name === e
10424
10422
  },
10425
10423
  alltime: {
10426
- donator: t["cheer-alltime-top-donator"].name === e,
10427
- amount: t["cheer-alltime-top-donation"].name === e
10424
+ donator: n["cheer-alltime-top-donator"].name === e,
10425
+ amount: n["cheer-alltime-top-donation"].name === e
10428
10426
  }
10429
10427
  },
10430
10428
  superchat: {
10431
10429
  session: {
10432
- donator: t["superchat-session-top-donator"].name === e,
10433
- amount: t["superchat-session-top-donation"].name === e
10430
+ donator: n["superchat-session-top-donator"].name === e,
10431
+ amount: n["superchat-session-top-donation"].name === e
10434
10432
  },
10435
10433
  weekly: {
10436
- donator: t["superchat-weekly-top-donator"].name === e,
10437
- amount: t["superchat-weekly-top-donation"].name === e
10434
+ donator: n["superchat-weekly-top-donator"].name === e,
10435
+ amount: n["superchat-weekly-top-donation"].name === e
10438
10436
  },
10439
10437
  monthly: {
10440
- donator: t["superchat-monthly-top-donator"].name === e,
10441
- amount: t["superchat-monthly-top-donation"].name === e
10438
+ donator: n["superchat-monthly-top-donator"].name === e,
10439
+ amount: n["superchat-monthly-top-donation"].name === e
10442
10440
  },
10443
10441
  alltime: {
10444
- donator: t["superchat-alltime-top-donator"].name === e,
10445
- amount: t["superchat-alltime-top-donation"].name === e
10442
+ donator: n["superchat-alltime-top-donator"].name === e,
10443
+ amount: n["superchat-alltime-top-donation"].name === e
10446
10444
  }
10447
10445
  }
10448
10446
  });
10449
- switch (n.provider) {
10450
- case "twitch":
10451
- switch (n.data.listener) {
10452
- case "message": {
10453
- let e = n.data.event.data, i = await this.findSubscriptionTier({
10454
- userId: e.userId,
10455
- name: e.displayName,
10456
- broadcasterId: e.tags["room-id"]
10457
- }, t ?? {}, !1);
10458
- return {
10459
- id: e.userId,
10460
- name: e.displayName,
10461
- color: e.displayColor,
10462
- role: e.tags.badges.split(",")[0].split("/")[0],
10463
- tags: e.tags.badges.split(",").map((e) => e.split("/")[0]),
10464
- badges: e.badges,
10465
- tier: e.tags.badges.includes("subscriber") ? i : void 0,
10466
- top: r(e.displayName)
10467
- };
10468
- }
10469
- }
10470
- break;
10471
- case "youtube":
10472
- switch (n.data.listener) {
10473
- case "message": {
10474
- let e = n.data.event.data, t = e.authorDetails.isChatOwner ? "broadcaster" : e.authorDetails.isChatModerator ? "moderator" : e.authorDetails.isChatSponsor ? "sponsor" : e.authorDetails.isVerified ? "verified" : "viewer";
10475
- return {
10476
- id: e.userId,
10477
- name: e.displayName,
10478
- role: t,
10479
- badges: e.badges,
10480
- top: r(e.displayName)
10481
- };
10482
- }
10483
- }
10484
- break;
10447
+ switch (e) {
10448
+ case "twitch": {
10449
+ let e = t.event.data, i = await this.findSubscriptionTier({
10450
+ userId: e.userId,
10451
+ name: e.displayName,
10452
+ broadcasterId: e.tags["room-id"]
10453
+ }, n ?? {}, !1);
10454
+ return {
10455
+ id: e.userId,
10456
+ name: e.displayName,
10457
+ color: e.displayColor,
10458
+ role: e.tags.badges.split(",")[0].split("/")[0],
10459
+ tags: e.tags.badges.split(",").map((e) => e.split("/")[0]),
10460
+ badges: e.badges,
10461
+ tier: e.tags.badges.includes("subscriber") ? i : void 0,
10462
+ top: r(e.displayName)
10463
+ };
10464
+ }
10465
+ case "youtube": {
10466
+ let e = t.event.data, n = e.authorDetails.isChatOwner ? "broadcaster" : e.authorDetails.isChatModerator ? "moderator" : e.authorDetails.isChatSponsor ? "sponsor" : e.authorDetails.isVerified ? "verified" : "viewer";
10467
+ return {
10468
+ id: e.userId,
10469
+ name: e.displayName,
10470
+ role: n,
10471
+ badges: e.badges,
10472
+ top: r(e.displayName)
10473
+ };
10474
+ }
10485
10475
  }
10486
10476
  }
10487
10477
  }, B;