commandkit 0.1.6 → 0.1.7-dev.20231212150647

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.js CHANGED
@@ -30,54 +30,61 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var src_exports = {};
32
32
  __export(src_exports, {
33
+ ButtonKit: () => ButtonKit,
33
34
  CommandKit: () => CommandKit,
34
- CommandType: () => CommandType,
35
- ReloadType: () => ReloadType
35
+ createEffect: () => createEffect,
36
+ createSignal: () => createSignal,
37
+ defineConfig: () => defineConfig,
38
+ getConfig: () => getConfig
36
39
  });
37
40
  module.exports = __toCommonJS(src_exports);
38
41
 
39
- // src/utils/get-paths.ts
42
+ // src/utils/resolve-file-url.ts
40
43
  var import_path = __toESM(require("path"));
41
- var import_fs = __toESM(require("fs"));
42
- function getFilePaths(directory, nesting) {
44
+ function toFileURL(filePath) {
45
+ const resolvedPath = import_path.default.resolve(filePath);
46
+ return "file://" + resolvedPath.replace(/\\\\|\\/g, "/");
47
+ }
48
+
49
+ // src/utils/get-paths.ts
50
+ var import_path2 = __toESM(require("path"));
51
+ var import_promises = __toESM(require("fs/promises"));
52
+ async function getFilePaths(directory, nesting) {
43
53
  let filePaths = [];
44
54
  if (!directory)
45
55
  return filePaths;
46
- const files = import_fs.default.readdirSync(directory, { withFileTypes: true });
56
+ const files = await import_promises.default.readdir(directory, { withFileTypes: true });
47
57
  for (const file of files) {
48
- const filePath = import_path.default.join(directory, file.name);
58
+ const filePath = import_path2.default.join(directory, file.name);
49
59
  if (file.isFile()) {
50
60
  filePaths.push(filePath);
51
61
  }
52
62
  if (nesting && file.isDirectory()) {
53
- filePaths = [...filePaths, ...getFilePaths(filePath, true)];
63
+ filePaths = [...filePaths, ...await getFilePaths(filePath, true)];
54
64
  }
55
65
  }
56
66
  return filePaths;
57
67
  }
58
- function getFolderPaths(directory, nesting) {
68
+ async function getFolderPaths(directory, nesting) {
59
69
  let folderPaths = [];
60
70
  if (!directory)
61
71
  return folderPaths;
62
- const folders = import_fs.default.readdirSync(directory, { withFileTypes: true });
72
+ const folders = await import_promises.default.readdir(directory, { withFileTypes: true });
63
73
  for (const folder of folders) {
64
- const folderPath = import_path.default.join(directory, folder.name);
74
+ const folderPath = import_path2.default.join(directory, folder.name);
65
75
  if (folder.isDirectory()) {
66
76
  folderPaths.push(folderPath);
67
77
  if (nesting) {
68
- folderPaths = [...folderPaths, ...getFolderPaths(folderPath, true)];
78
+ folderPaths = [...folderPaths, ...await getFolderPaths(folderPath, true)];
69
79
  }
70
80
  }
71
81
  }
72
82
  return folderPaths;
73
83
  }
74
84
 
75
- // src/utils/resolve-file-url.ts
76
- var import_path2 = __toESM(require("path"));
77
- function toFileURL(filePath) {
78
- const resolvedPath = import_path2.default.resolve(filePath);
79
- return "file://" + resolvedPath.replace(/\\\\|\\/g, "/");
80
- }
85
+ // src/utils/clone.ts
86
+ var import_rfdc = __toESM(require("rfdc"));
87
+ var clone = (0, import_rfdc.default)();
81
88
 
82
89
  // src/utils/colors.ts
83
90
  var resetColor = "\x1B[0m";
@@ -361,35 +368,10 @@ async function registerDevCommands(client, commands, guildIds) {
361
368
  }
362
369
  }
363
370
 
364
- // src/handlers/command-handler/validations/botPermissions.ts
365
- function botPermissions_default({ interaction, targetCommand }) {
366
- const botMember = interaction.guild?.members.me;
367
- let commandPermissions = targetCommand.options?.botPermissions;
368
- if (!botMember || !commandPermissions)
369
- return;
370
- if (!Array.isArray(commandPermissions)) {
371
- commandPermissions = [commandPermissions];
372
- }
373
- const missingPermissions = [];
374
- for (const permission of commandPermissions) {
375
- const hasPermission = botMember.permissions.has(permission);
376
- if (!hasPermission) {
377
- missingPermissions.push(`\`${permission.toString()}\``);
378
- }
379
- }
380
- if (missingPermissions.length) {
381
- interaction.reply({
382
- content: `\u274C I do not have enough permissions to execute this command. Missing: ${missingPermissions.join(
383
- ", "
384
- )}`,
385
- ephemeral: true
386
- });
387
- return true;
388
- }
389
- }
390
-
391
371
  // src/handlers/command-handler/validations/devOnly.ts
392
372
  function devOnly_default({ interaction, targetCommand, handlerData }) {
373
+ if (interaction.isAutocomplete())
374
+ return;
393
375
  if (targetCommand.options?.devOnly) {
394
376
  if (interaction.inGuild() && !handlerData.devGuildIds.includes(interaction.guildId)) {
395
377
  interaction.reply({
@@ -417,50 +399,76 @@ function devOnly_default({ interaction, targetCommand, handlerData }) {
417
399
  }
418
400
  }
419
401
 
420
- // src/handlers/command-handler/validations/guildOnly.ts
421
- function guildOnly_default({ interaction, targetCommand }) {
422
- if (targetCommand.options?.guildOnly && !interaction.inGuild()) {
423
- interaction.reply({
424
- content: "\u274C This command can only be used inside a server.",
425
- ephemeral: true
426
- });
427
- return true;
402
+ // src/handlers/command-handler/validations/permissions.ts
403
+ var import_discord = require("discord.js");
404
+ function permissions_default({ interaction, targetCommand }) {
405
+ if (interaction.isAutocomplete())
406
+ return;
407
+ const userPermissions = interaction.memberPermissions;
408
+ let userPermissionsRequired = targetCommand.options?.userPermissions;
409
+ let missingUserPermissions = [];
410
+ if (typeof userPermissionsRequired === "string") {
411
+ userPermissionsRequired = [userPermissionsRequired];
428
412
  }
429
- }
430
-
431
- // src/handlers/command-handler/validations/userPermissions.ts
432
- function userPermissions_default({ interaction, targetCommand }) {
433
- const memberPermissions = interaction.memberPermissions;
434
- let commandPermissions = targetCommand.options?.userPermissions;
435
- if (!memberPermissions || !commandPermissions)
413
+ const botPermissions = interaction.guild?.members.me?.permissions;
414
+ let botPermissionsRequired = targetCommand.options?.botPermissions;
415
+ let missingBotPermissions = [];
416
+ if (typeof botPermissionsRequired === "string") {
417
+ botPermissionsRequired = [botPermissionsRequired];
418
+ }
419
+ if (!userPermissionsRequired?.length && !botPermissionsRequired?.length) {
436
420
  return;
437
- if (!Array.isArray(commandPermissions)) {
438
- commandPermissions = [commandPermissions];
439
- }
440
- const missingPermissions = [];
441
- for (const permission of commandPermissions) {
442
- const hasPermission = memberPermissions.has(permission);
443
- if (!hasPermission) {
444
- missingPermissions.push(`\`${permission.toString()}\``);
445
- }
446
- }
447
- if (missingPermissions.length) {
448
- interaction.reply({
449
- content: `\u274C You do not have enough permissions to run this command. Missing: ${missingPermissions.join(
450
- ", "
451
- )}`,
452
- ephemeral: true
453
- });
454
- return true;
455
421
  }
422
+ if (userPermissions && userPermissionsRequired) {
423
+ for (const permission of userPermissionsRequired) {
424
+ const hasPermission = userPermissions.has(permission);
425
+ if (!hasPermission) {
426
+ missingUserPermissions.push(permission);
427
+ }
428
+ }
429
+ }
430
+ if (botPermissions && botPermissionsRequired) {
431
+ for (const permission of botPermissionsRequired) {
432
+ const hasPermission = botPermissions.has(permission);
433
+ if (!hasPermission) {
434
+ missingBotPermissions.push(permission);
435
+ }
436
+ }
437
+ }
438
+ if (!missingUserPermissions.length && !missingBotPermissions.length) {
439
+ return;
440
+ }
441
+ const pattern = /([a-z])([A-Z])|([A-Z]+)([A-Z][a-z])/g;
442
+ missingUserPermissions = missingUserPermissions.map((str) => str.replace(pattern, "$1$3 $2$4"));
443
+ missingBotPermissions = missingBotPermissions.map((str) => str.replace(pattern, "$1$3 $2$4"));
444
+ let embedDescription = "";
445
+ const formatter = new Intl.ListFormat("en", { style: "long", type: "conjunction" });
446
+ const getPermissionWord = (permissions) => permissions.length === 1 ? "permission" : "permissions";
447
+ if (missingUserPermissions.length) {
448
+ const formattedPermissions = missingUserPermissions.map((p) => `\`${p}\``);
449
+ const permissionsString = formatter.format(formattedPermissions);
450
+ embedDescription += `- You must have the ${permissionsString} ${getPermissionWord(
451
+ missingUserPermissions
452
+ )} to be able to run this command.
453
+ `;
454
+ }
455
+ if (missingBotPermissions.length) {
456
+ const formattedPermissions = missingBotPermissions.map((p) => `\`${p}\``);
457
+ const permissionsString = formatter.format(formattedPermissions);
458
+ embedDescription += `- I must have the ${permissionsString} ${getPermissionWord(
459
+ missingBotPermissions
460
+ )} to be able to execute this command.
461
+ `;
462
+ }
463
+ const embed = new import_discord.EmbedBuilder().setTitle(`:x: Missing permissions!`).setDescription(embedDescription).setColor("Red");
464
+ interaction.reply({ embeds: [embed], ephemeral: true });
465
+ return true;
456
466
  }
457
467
 
458
468
  // src/handlers/command-handler/validations/index.ts
459
- var validations_default = [botPermissions_default, devOnly_default, guildOnly_default, userPermissions_default];
469
+ var validations_default = [devOnly_default, permissions_default];
460
470
 
461
471
  // src/handlers/command-handler/CommandHandler.ts
462
- var import_rfdc = __toESM(require("rfdc"));
463
- var clone = (0, import_rfdc.default)();
464
472
  var CommandHandler = class {
465
473
  #data;
466
474
  constructor({ ...options }) {
@@ -472,19 +480,19 @@ var CommandHandler = class {
472
480
  }
473
481
  async init() {
474
482
  await this.#buildCommands();
475
- this.#buildValidations();
483
+ this.#buildBuiltInValidations();
476
484
  const devOnlyCommands = this.#data.commands.filter((cmd) => cmd.options?.devOnly);
477
485
  if (devOnlyCommands.length && !this.#data.devGuildIds.length) {
478
486
  console.log(
479
487
  colors_default.yellow(
480
- '\u2139\uFE0F Warning: You have commands marked as "devOnly" but "devGuildIds" has not been set.'
488
+ '\u2139\uFE0F Warning: You have commands marked as "devOnly", but "devGuildIds" have not been set.'
481
489
  )
482
490
  );
483
491
  }
484
492
  if (devOnlyCommands.length && !this.#data.devUserIds.length && !this.#data.devRoleIds.length) {
485
493
  console.log(
486
494
  colors_default.yellow(
487
- '\u2139\uFE0F Warning: You have commands marked as "devOnly" but not "devUserIds" or "devRoleIds" were set.'
495
+ '\u2139\uFE0F Warning: You have commands marked as "devOnly", but "devUserIds" or "devRoleIds" have not been set.'
488
496
  )
489
497
  );
490
498
  }
@@ -505,12 +513,11 @@ var CommandHandler = class {
505
513
  }
506
514
  async #buildCommands() {
507
515
  const allowedExtensions = /\.(js|mjs|cjs|ts)$/i;
508
- const commandFilePaths = getFilePaths(this.#data.commandsPath, true).filter(
509
- (path3) => allowedExtensions.test(path3)
510
- );
516
+ const paths = await getFilePaths(this.#data.commandsPath, true);
517
+ const commandFilePaths = paths.filter((path3) => allowedExtensions.test(path3));
511
518
  for (const commandFilePath of commandFilePaths) {
512
519
  const modulePath = toFileURL(commandFilePath);
513
- let importedObj = await import(`${modulePath}?t=${Date.now()}`);
520
+ const importedObj = await import(`${modulePath}?t=${Date.now()}`);
514
521
  let commandObj = clone(importedObj);
515
522
  if (typeof module !== "undefined" && typeof require !== "undefined") {
516
523
  delete require.cache[require.resolve(commandFilePath)];
@@ -562,24 +569,34 @@ var CommandHandler = class {
562
569
  } else {
563
570
  commandObj.category = commandCategory;
564
571
  }
572
+ if (commandObj.options?.guildOnly) {
573
+ console.log(
574
+ colors_default.yellow(
575
+ `\u2139\uFE0F Deprecation warning: The command "${commandObj.data.name}" uses "options.guildOnly", which will be deprecated soon. Use "data.dm_permission" instead.`
576
+ )
577
+ );
578
+ }
565
579
  this.#data.commands.push(commandObj);
566
580
  }
567
581
  }
568
- #buildValidations() {
569
- for (const validationFunction of validations_default) {
570
- this.#data.builtInValidations.push(validationFunction);
582
+ #buildBuiltInValidations() {
583
+ for (const builtInValidationFunction of validations_default) {
584
+ this.#data.builtInValidations.push(builtInValidationFunction);
571
585
  }
572
586
  }
573
587
  handleCommands() {
574
588
  this.#data.client.on("interactionCreate", async (interaction) => {
575
- if (!interaction.isChatInputCommand() && !interaction.isContextMenuCommand())
589
+ if (!interaction.isChatInputCommand() && !interaction.isContextMenuCommand() && !interaction.isAutocomplete())
576
590
  return;
591
+ const isAutocomplete = interaction.isAutocomplete();
577
592
  const targetCommand = this.#data.commands.find(
578
593
  (cmd) => cmd.data.name === interaction.commandName
579
594
  );
580
595
  if (!targetCommand)
581
596
  return;
582
- const { data, options, run, ...rest } = targetCommand;
597
+ const { data, options, run, autocompleteRun, ...rest } = targetCommand;
598
+ if (isAutocomplete && !autocompleteRun)
599
+ return;
583
600
  const commandObj = {
584
601
  data: targetCommand.data,
585
602
  options: targetCommand.options,
@@ -618,17 +635,23 @@ var CommandHandler = class {
618
635
  }
619
636
  if (!canRun)
620
637
  return;
621
- targetCommand.run({
638
+ const context2 = {
622
639
  interaction,
623
640
  client: this.#data.client,
624
641
  handler: this.#data.commandkitInstance
625
- });
642
+ };
643
+ await targetCommand[isAutocomplete ? "autocompleteRun" : "run"](context2);
626
644
  });
627
645
  }
628
646
  get commands() {
629
647
  return this.#data.commands;
630
648
  }
631
649
  async reloadCommands(type) {
650
+ if (!this.#data.commandsPath) {
651
+ throw new Error(
652
+ 'Cannot reload commands as "commandsPath" was not provided when instantiating CommandKit.'
653
+ );
654
+ }
632
655
  this.#data.commands = [];
633
656
  await this.#buildCommands();
634
657
  if (this.#data.bulkRegister) {
@@ -649,13 +672,9 @@ var CommandHandler = class {
649
672
  });
650
673
  }
651
674
  }
652
- async useUpdatedValidations() {
653
- }
654
675
  };
655
676
 
656
677
  // src/handlers/event-handler/EventHandler.ts
657
- var import_rfdc2 = __toESM(require("rfdc"));
658
- var clone2 = (0, import_rfdc2.default)();
659
678
  var EventHandler = class {
660
679
  #data;
661
680
  constructor({ ...options }) {
@@ -669,13 +688,12 @@ var EventHandler = class {
669
688
  this.#registerEvents();
670
689
  }
671
690
  async #buildEvents() {
672
- const eventFolderPaths = getFolderPaths(this.#data.eventsPath);
691
+ const eventFolderPaths = await getFolderPaths(this.#data.eventsPath);
673
692
  for (const eventFolderPath of eventFolderPaths) {
674
693
  const eventName = eventFolderPath.replace(/\\\\|\\/g, "/").split("/").pop();
675
694
  const allowedExtensions = /\.(js|mjs|cjs|ts)$/i;
676
- const eventFilePaths = getFilePaths(eventFolderPath, true).filter(
677
- (path3) => allowedExtensions.test(path3)
678
- );
695
+ const eventPaths = await getFilePaths(eventFolderPath, true);
696
+ const eventFilePaths = eventPaths.filter((path3) => allowedExtensions.test(path3));
679
697
  const eventObj = {
680
698
  name: eventName,
681
699
  functions: []
@@ -684,7 +702,7 @@ var EventHandler = class {
684
702
  for (const eventFilePath of eventFilePaths) {
685
703
  const modulePath = toFileURL(eventFilePath);
686
704
  let importedFunction = (await import(`${modulePath}?t=${Date.now()}`)).default;
687
- let eventFunction = clone2(importedFunction);
705
+ let eventFunction = clone(importedFunction);
688
706
  if (typeof module !== "undefined" && typeof require !== "undefined") {
689
707
  delete require.cache[require.resolve(eventFilePath)];
690
708
  }
@@ -722,6 +740,11 @@ var EventHandler = class {
722
740
  return this.#data.events;
723
741
  }
724
742
  async reloadEvents(commandHandler) {
743
+ if (!this.#data.eventsPath) {
744
+ throw new Error(
745
+ 'Cannot reload events as "eventsPath" was not provided when instantiating CommandKit.'
746
+ );
747
+ }
725
748
  this.#data.events = [];
726
749
  await this.#buildEvents();
727
750
  this.#data.client.removeAllListeners();
@@ -731,8 +754,6 @@ var EventHandler = class {
731
754
  };
732
755
 
733
756
  // src/handlers/validation-handler/ValidationHandler.ts
734
- var import_rfdc3 = __toESM(require("rfdc"));
735
- var clone3 = (0, import_rfdc3.default)();
736
757
  var ValidationHandler = class {
737
758
  #data;
738
759
  constructor({ ...options }) {
@@ -742,17 +763,17 @@ var ValidationHandler = class {
742
763
  };
743
764
  }
744
765
  async init() {
745
- await this.#buildValidations();
766
+ this.#data.validations = await this.#buildValidations();
746
767
  }
747
768
  async #buildValidations() {
748
769
  const allowedExtensions = /\.(js|mjs|cjs|ts)$/i;
749
- const validationFilePaths = getFilePaths(this.#data.validationsPath, true).filter(
750
- (path3) => allowedExtensions.test(path3)
751
- );
770
+ const validationPaths = await getFilePaths(this.#data.validationsPath, true);
771
+ const validationFilePaths = validationPaths.filter((path3) => allowedExtensions.test(path3));
772
+ const validationFunctions = [];
752
773
  for (const validationFilePath of validationFilePaths) {
753
774
  const modulePath = toFileURL(validationFilePath);
754
775
  let importedFunction = (await import(`${modulePath}?t=${Date.now()}`)).default;
755
- let validationFunction = clone3(importedFunction);
776
+ let validationFunction = clone(importedFunction);
756
777
  if (typeof module !== "undefined" && typeof require !== "undefined") {
757
778
  delete require.cache[require.resolve(validationFilePath)];
758
779
  }
@@ -768,21 +789,33 @@ var ValidationHandler = class {
768
789
  );
769
790
  continue;
770
791
  }
771
- this.#data.validations.push(validationFunction);
792
+ validationFunctions.push(validationFunction);
772
793
  }
794
+ return validationFunctions;
773
795
  }
774
796
  get validations() {
775
797
  return this.#data.validations;
776
798
  }
777
799
  async reloadValidations() {
778
- this.#data.validations = [];
779
- await this.#buildValidations();
800
+ if (!this.#data.validationsPath) {
801
+ throw new Error(
802
+ 'Cannot reload validations as "validationsPath" was not provided when instantiating CommandKit.'
803
+ );
804
+ }
805
+ const newValidations = await this.#buildValidations();
806
+ this.#data.validations = newValidations;
780
807
  }
781
808
  };
782
809
 
783
810
  // src/CommandKit.ts
784
811
  var CommandKit = class {
785
812
  #data;
813
+ /**
814
+ * Create a new command and event handler with CommandKit.
815
+ *
816
+ * @param options - The default CommandKit configuration.
817
+ * @see {@link https://commandkit.js.org/docs/commandkit-setup}
818
+ */
786
819
  constructor(options) {
787
820
  if (!options.client) {
788
821
  throw new Error(colors_default.red('"client" is required when instantiating CommandKit.'));
@@ -795,6 +828,9 @@ var CommandKit = class {
795
828
  this.#data = options;
796
829
  this.#init();
797
830
  }
831
+ /**
832
+ * (Private) Initialize CommandKit.
833
+ */
798
834
  async #init() {
799
835
  if (this.#data.eventsPath) {
800
836
  const eventHandler = new EventHandler({
@@ -903,21 +939,147 @@ var CommandKit = class {
903
939
  }
904
940
  };
905
941
 
906
- // src/types/index.ts
907
- var CommandType = /* @__PURE__ */ ((CommandType2) => {
908
- CommandType2[CommandType2["ChatInput"] = 1] = "ChatInput";
909
- CommandType2[CommandType2["Message"] = 3] = "Message";
910
- CommandType2[CommandType2["User"] = 2] = "User";
911
- return CommandType2;
912
- })(CommandType || {});
913
- var ReloadType = /* @__PURE__ */ ((ReloadType2) => {
914
- ReloadType2["Developer"] = "dev";
915
- ReloadType2["Global"] = "global";
916
- return ReloadType2;
917
- })(ReloadType || {});
942
+ // src/components/ButtonKit.ts
943
+ var import_discord2 = require("discord.js");
944
+ var ButtonKit = class extends import_discord2.ButtonBuilder {
945
+ #onClickHandler = null;
946
+ #contextData = null;
947
+ #collector = null;
948
+ onClick(handler, data) {
949
+ if (this.data.style === import_discord2.ButtonStyle.Link) {
950
+ throw new TypeError('Cannot setup "onClick" handler on link buttons.');
951
+ }
952
+ this.#destroyCollector();
953
+ this.#onClickHandler = handler;
954
+ if (handler && data)
955
+ this.#contextData = data;
956
+ this.#setupInteractionCollector();
957
+ return this;
958
+ }
959
+ #setupInteractionCollector() {
960
+ if (!this.#contextData || !this.#onClickHandler)
961
+ return;
962
+ const message = this.#contextData.message;
963
+ if (!message) {
964
+ throw new TypeError(
965
+ 'Cannot setup "onClick" handler without a message in the context data.'
966
+ );
967
+ }
968
+ if ("customId" in this.data && !this.data.customId) {
969
+ throw new TypeError('Cannot setup "onClick" handler on a button without a custom id.');
970
+ }
971
+ const data = {
972
+ time: 864e5,
973
+ autoReset: true,
974
+ ...this.#contextData
975
+ };
976
+ const collector = this.#collector = message.createMessageComponentCollector({
977
+ filter: (interaction) => interaction.customId === this.data.custom_id && interaction.message.id === message.id,
978
+ componentType: import_discord2.ComponentType.Button,
979
+ ...data
980
+ });
981
+ this.#collector.on("collect", (interaction) => {
982
+ const handler = this.#onClickHandler;
983
+ if (!handler)
984
+ return this.#destroyCollector();
985
+ if (!this.#collector) {
986
+ return collector.stop("destroyed");
987
+ }
988
+ if (data.autoReset) {
989
+ this.#collector.resetTimer();
990
+ }
991
+ return handler(interaction);
992
+ });
993
+ this.#collector.on("end", () => {
994
+ this.#destroyCollector();
995
+ });
996
+ }
997
+ #destroyCollector() {
998
+ this.#onClickHandler?.(null);
999
+ this.#collector?.stop("end");
1000
+ this.#collector?.removeAllListeners();
1001
+ this.#collector = null;
1002
+ this.#contextData = null;
1003
+ this.#onClickHandler = null;
1004
+ }
1005
+ };
1006
+
1007
+ // src/config.ts
1008
+ var globalConfig = {
1009
+ envExtra: true,
1010
+ outDir: "dist",
1011
+ watch: true,
1012
+ clearRestartLogs: true,
1013
+ minify: false,
1014
+ sourcemap: false,
1015
+ nodeOptions: [],
1016
+ antiCrash: true
1017
+ };
1018
+ function getConfig() {
1019
+ return globalConfig;
1020
+ }
1021
+ var requiredProps = ["src", "main"];
1022
+ function defineConfig(config) {
1023
+ for (const prop of requiredProps) {
1024
+ if (!config[prop]) {
1025
+ throw new Error(`[CommandKit Config] Missing required config property: ${prop}`);
1026
+ }
1027
+ }
1028
+ globalConfig = {
1029
+ ...globalConfig,
1030
+ ...config
1031
+ };
1032
+ return globalConfig;
1033
+ }
1034
+
1035
+ // src/utils/signal.ts
1036
+ var context = [];
1037
+ function createSignal(value) {
1038
+ const subscribers = /* @__PURE__ */ new Set();
1039
+ let disposed = false;
1040
+ let val = value instanceof Function ? value() : value;
1041
+ const getter = () => {
1042
+ if (!disposed) {
1043
+ const running = getCurrentObserver();
1044
+ if (running)
1045
+ subscribers.add(running);
1046
+ }
1047
+ return val;
1048
+ };
1049
+ const setter = (newValue) => {
1050
+ if (disposed)
1051
+ return;
1052
+ val = newValue instanceof Function ? newValue(val) : newValue;
1053
+ for (const subscriber of subscribers) {
1054
+ subscriber();
1055
+ }
1056
+ };
1057
+ const dispose = () => {
1058
+ subscribers.clear();
1059
+ disposed = true;
1060
+ };
1061
+ return [getter, setter, dispose];
1062
+ }
1063
+ function createEffect(callback) {
1064
+ const execute = () => {
1065
+ context.push(execute);
1066
+ try {
1067
+ callback();
1068
+ } finally {
1069
+ context.pop();
1070
+ }
1071
+ };
1072
+ execute();
1073
+ }
1074
+ function getCurrentObserver() {
1075
+ return context[context.length - 1];
1076
+ }
918
1077
  // Annotate the CommonJS export names for ESM import in node:
919
1078
  0 && (module.exports = {
1079
+ ButtonKit,
920
1080
  CommandKit,
921
- CommandType,
922
- ReloadType
1081
+ createEffect,
1082
+ createSignal,
1083
+ defineConfig,
1084
+ getConfig
923
1085
  });