@tixyel/streamelements 2.0.0 → 3.0.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/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # @tixyel/streamelements
2
+
3
+ TypeScript/JavaScript helper library for building custom widgets for [StreamElements](https://streamelements.com/), focused on productivity, type safety, and local development. Designed for browser usage via CDN, with TypeScript types for IDE autocompletion.
4
+
5
+ ## Features
6
+
7
+ - **Typed event helpers** for Twitch, YouTube, and Kick (in development)
8
+ - **Utility functions** for common widget tasks
9
+ - **TypeScript types** for all major StreamElements events
10
+ - **Local development support**: Test your widget locally without uploading to StreamElements
11
+ - **Easy integration**: Use directly in the browser via CDN
12
+
13
+ ## Usage
14
+
15
+ Add the following to your HTML:
16
+
17
+ ```html
18
+ <script src="https://cdn.jsdelivr.net/npm/@tixyel/streamelements"></script>
19
+ <script>
20
+ const { Client, Simulation, logger } = window.Tixyel;
21
+
22
+ new Client({ id: 'my-widget' }).on('load', (event) => {
23
+ logger.received('Widget loaded!', event);
24
+ });
25
+ </script>
26
+ ```
27
+
28
+ > **Note:** This package is designed for browser usage via CDN only.
29
+ > TypeScript is used only to provide type definitions and autocompletion in your IDE when working with `window.Tixyel`.
30
+
31
+ ## API Overview
32
+
33
+ - **Client**: Manages events and integration with StreamElements.
34
+ - **Simulation**: Simulates events for local testing.
35
+ - **Logger**: Utility for formatted logs.
36
+ - **Button/Command**: Helpers for custom actions.
37
+
38
+ ## License
39
+
40
+ Apache-2.0
package/dist/index.d.ts CHANGED
@@ -545,6 +545,12 @@ declare enum Alejo$Pronouns {
545
545
  itits = "It/Its"
546
546
  }
547
547
  type Alejo$Pronouns$name = 'hehim' | 'sheher' | 'theythem' | 'shethem' | 'hethem' | 'heshe' | 'xexem' | 'faefaer' | 'vever' | 'aeaer' | 'ziehir' | 'perper' | 'eem' | 'itits';
548
+ type Alejo$Pronouns$display = 'He/Him' | 'She/Her' | 'They/Them' | 'She/They' | 'He/They' | 'He/She' | 'Xe/Xem' | 'Fae/Faer' | 'Ve/Ver' | 'Ae/Aer' | 'Zie/Hir' | 'Per/Per' | 'E/Em' | 'It/Its';
549
+ type Alejo$Pronouns$User = {
550
+ id: string;
551
+ login: string;
552
+ pronouns: Alejo$Pronouns$name;
553
+ };
548
554
 
549
555
  /**
550
556
  * EventProvider class for managing event listeners and emitters.
@@ -610,6 +616,7 @@ type MapNumberValuesToString<T> = {
610
616
  type UseStorageEvents<T> = {
611
617
  load: [T | null];
612
618
  save: [T];
619
+ update: [T];
613
620
  };
614
621
  type UseStorageOptions<T> = {
615
622
  id?: string;
@@ -628,8 +635,25 @@ declare class useStorage<T extends object = Record<string, any>> extends EventPr
628
635
  * @param data Data to save (defaults to current)
629
636
  */
630
637
  save(data?: T): void;
638
+ /**
639
+ * Updates the storage data and emits an update event if the data has changed.
640
+ * @param data Data to update (defaults to current)
641
+ */
642
+ update(data?: T): void;
643
+ /**
644
+ * Adds a value to the storage at the specified path.
645
+ * @param path Path to add the value to
646
+ * @param value Value to add
647
+ */
631
648
  add<P extends string>(path: P, value: PathValue<T, P>): void;
632
- setByPath<P extends string>(obj: T, path: P, value: PathValue<T, P>): void;
649
+ /**
650
+ * Sets a value in the storage at the specified path.
651
+ * @param obj The object to set the value in
652
+ * @param path The path to set the value at
653
+ * @param value The value to set
654
+ * @returns The updated object
655
+ */
656
+ static setByPath<P extends string, T extends object>(obj: T, path: P, value: PathValue<T, P>): void;
633
657
  on<K extends keyof UseStorageEvents<T>>(eventName: K, callback: (...args: UseStorageEvents<T>[K]) => void): this;
634
658
  }
635
659
 
@@ -637,7 +661,9 @@ type StreamElements$AlertService = {
637
661
  listener: 'alertService:toggleSound';
638
662
  event: toggleSound;
639
663
  };
640
- type toggleSound = {};
664
+ type toggleSound = {
665
+ muted: boolean;
666
+ };
641
667
 
642
668
  type StreamElements$BotCounter = {
643
669
  listener: 'bot:counter';
@@ -776,7 +802,7 @@ type StreamElements$KVStore = {
776
802
  type KVStore = {
777
803
  data: {
778
804
  key: `customWidget.${string}`;
779
- value: string | number | boolean;
805
+ value: string | number | boolean | Record<string, any>;
780
806
  };
781
807
  };
782
808
 
@@ -830,19 +856,6 @@ type Follower = {
830
856
  originalEventName: 'follower-latest';
831
857
  };
832
858
 
833
- type Twitch$DeleteMessage = {
834
- listener: 'delete-message';
835
- event: {
836
- msgId: string;
837
- };
838
- };
839
- type Twitch$DeleteMessages = {
840
- listener: 'delete-messages';
841
- event: {
842
- userId: string;
843
- };
844
- };
845
-
846
859
  type Twitch$IRC = {
847
860
  /**
848
861
  * Contains metadata related to the chat badges in the badges tag.
@@ -992,6 +1005,19 @@ type Twitch$IRC = {
992
1005
  'vip': undefined | '';
993
1006
  };
994
1007
 
1008
+ type Twitch$DeleteMessage = {
1009
+ listener: 'delete-message';
1010
+ event: {
1011
+ msgId: string;
1012
+ };
1013
+ };
1014
+ type Twitch$DeleteMessages = {
1015
+ listener: 'delete-messages';
1016
+ event: {
1017
+ userId: string;
1018
+ };
1019
+ };
1020
+
995
1021
  type Twitch$Message = {
996
1022
  listener: 'message';
997
1023
  event: Message;
@@ -1318,10 +1344,10 @@ declare class Button {
1318
1344
  }
1319
1345
 
1320
1346
  type ClientEvents = {
1321
- load: [event: onWidgetLoad];
1322
- action: [action: any, type: 'created' | 'updated' | 'executed'];
1323
- session: [session: Session$1];
1324
- event: [event: ClientEvents$1];
1347
+ load: [this: Client, event: onWidgetLoad];
1348
+ action: [this: Client, action: Button | Command, type: 'created' | 'executed'];
1349
+ session: [this: Client, session: Session$1];
1350
+ event: [this: Client, event: ClientEvents$1];
1325
1351
  };
1326
1352
  type ClientOptions = {
1327
1353
  id?: string;
@@ -1630,21 +1656,94 @@ declare class Logger implements LoggerMethods {
1630
1656
  constructor();
1631
1657
  }
1632
1658
 
1659
+ type Emote = TwitchEmote | BttvEmote | SeventvEmote;
1660
+ declare function findEmotesInText(text: string, emotes?: Emote[]): Emote[];
1661
+ declare function replaceEmotesWithHTML(text: string, emotes: Emote[]): string;
1662
+
1663
+ type QueueEvents<T> = {
1664
+ load: [];
1665
+ cancel: [];
1666
+ update: [queue: QueueItem<T>[], priorityQueue: QueueItem<T>[], history: QueueItem<T>[], timeouts: Array<ReturnType<typeof setTimeout>>];
1667
+ process: [item: QueueItem<T>, queue: useQueue<T>];
1668
+ };
1669
+ type QueueProps = {
1670
+ isoDate: string;
1671
+ isLoop: boolean;
1672
+ isPriority: boolean;
1673
+ isImmediate: boolean;
1674
+ };
1675
+ type QueueItem<T> = {
1676
+ value: T;
1677
+ } & QueueProps;
1678
+ type QueueProcessor<T> = (item: T, queue: useQueue<T>) => Promise<any>;
1679
+ interface QueueOptions<T> {
1680
+ duration: number | boolean | undefined;
1681
+ processor: QueueProcessor<T>;
1682
+ }
1683
+ declare class useQueue<T> extends EventProvider<QueueEvents<T>> {
1684
+ queue: QueueItem<T>[];
1685
+ priorityQueue: QueueItem<T>[];
1686
+ history: QueueItem<T>[];
1687
+ timeouts: Array<ReturnType<typeof setTimeout>>;
1688
+ running: boolean;
1689
+ duration: number | boolean | undefined;
1690
+ loaded: boolean;
1691
+ processor: QueueProcessor<T>;
1692
+ constructor(options: QueueOptions<T>);
1693
+ enqueue(value: T, options?: Partial<QueueProps>): this;
1694
+ private run;
1695
+ private next;
1696
+ resume(): this;
1697
+ update(save: Partial<useQueue<T>>): this;
1698
+ cancel(): void;
1699
+ hasItems(): boolean;
1700
+ }
1701
+
1633
1702
  declare const Tixyel: {
1703
+ readonly Client: typeof Client;
1704
+ readonly Simulation: typeof Simulation;
1705
+ readonly logger: Logger;
1706
+ readonly utils: {
1707
+ readonly findEmotesInText: typeof findEmotesInText;
1708
+ readonly replaceEmotesWithHTML: typeof replaceEmotesWithHTML;
1709
+ };
1710
+ readonly modules: {
1711
+ readonly Button: typeof Button;
1712
+ readonly Command: typeof Command;
1713
+ readonly EventProvider: typeof EventProvider;
1714
+ readonly useStorage: typeof useStorage;
1715
+ readonly useQueue: typeof useQueue;
1716
+ };
1717
+ };
1718
+ type _Tixyel_ = {
1634
1719
  Client: typeof Client;
1635
1720
  Simulation: typeof Simulation;
1636
1721
  logger: Logger;
1722
+ utils: {
1723
+ findEmotesInText: typeof findEmotesInText;
1724
+ replaceEmotesWithHTML: typeof replaceEmotesWithHTML;
1725
+ };
1726
+ modules: {
1727
+ Button: typeof Button;
1728
+ Command: typeof Command;
1729
+ EventProvider: typeof EventProvider;
1730
+ useStorage: typeof useStorage;
1731
+ useQueue: typeof useQueue;
1732
+ };
1637
1733
  };
1638
1734
  declare global {
1639
1735
  interface Window {
1640
- Tixyel: typeof Tixyel;
1641
- client?: Client;
1736
+ Tixyel: _Tixyel_;
1737
+ client: Client;
1642
1738
  }
1643
1739
  interface WindowEventMap {
1644
- 'onWidgetLoad': onWidgetLoadEvent;
1645
- 'onSessionUpdate': onSessionUpdateEvent;
1646
- 'onEventReceived': onEventReceivedEvent;
1740
+ onWidgetLoad: onWidgetLoadEvent;
1741
+ onSessionUpdate: onSessionUpdateEvent;
1742
+ onEventReceived: onEventReceivedEvent;
1647
1743
  }
1744
+ var Tixyel: _Tixyel_;
1745
+ var client: Client;
1648
1746
  }
1649
1747
 
1650
- export { Tixyel };
1748
+ export { Alejo$Pronouns, Tixyel };
1749
+ export type { Alejo$Pronouns$User, Alejo$Pronouns$display, Alejo$Pronouns$name, BttvEmote, ClientEvents$1 as ClientEvents, Facebook, Kick, Provider, SeventvEmote, StreamElements, Twitch, Twitch$Cheer, Twitch$DeleteMessage, Twitch$DeleteMessages, Twitch$Follower, Twitch$IRC, Twitch$Message, Twitch$Raid, Twitch$Subscriber, TwitchBadge, TwitchBadgesKeys, TwitchEmote, Youtube };