@noxfly/noxus 3.0.0-dev.0 → 3.0.0-dev.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.
Files changed (37) hide show
  1. package/README.md +12 -9
  2. package/dist/child.d.mts +112 -4
  3. package/dist/child.d.ts +112 -4
  4. package/dist/child.js +30 -30
  5. package/dist/child.mjs +30 -30
  6. package/dist/main.d.mts +450 -6
  7. package/dist/main.d.ts +450 -6
  8. package/dist/main.js +229 -229
  9. package/dist/main.mjs +231 -231
  10. package/dist/preload.d.mts +28 -0
  11. package/dist/preload.d.ts +28 -0
  12. package/dist/preload.js +95 -0
  13. package/dist/preload.mjs +70 -0
  14. package/dist/renderer.d.mts +159 -22
  15. package/dist/renderer.d.ts +159 -22
  16. package/dist/renderer.js +11 -58
  17. package/dist/renderer.mjs +7 -53
  18. package/package.json +18 -13
  19. package/src/DI/injector-explorer.ts +2 -2
  20. package/src/decorators/guards.decorator.ts +1 -1
  21. package/src/decorators/middleware.decorator.ts +1 -1
  22. package/src/index.ts +2 -5
  23. package/src/{app.ts → internal/app.ts} +8 -8
  24. package/src/{bootstrap.ts → internal/bootstrap.ts} +4 -4
  25. package/src/{request.ts → internal/request.ts} +2 -2
  26. package/src/{router.ts → internal/router.ts} +9 -9
  27. package/src/{routes.ts → internal/routes.ts} +2 -2
  28. package/src/{socket.ts → internal/socket.ts} +2 -2
  29. package/src/main.ts +7 -7
  30. package/src/non-electron-process.ts +1 -1
  31. package/src/preload.ts +10 -0
  32. package/src/renderer.ts +13 -0
  33. package/tsup.config.ts +27 -11
  34. /package/src/{exceptions.ts → internal/exceptions.ts} +0 -0
  35. /package/src/{preload-bridge.ts → internal/preload-bridge.ts} +0 -0
  36. /package/src/{renderer-client.ts → internal/renderer-client.ts} +0 -0
  37. /package/src/{renderer-events.ts → internal/renderer-events.ts} +0 -0
package/dist/main.mjs CHANGED
@@ -622,10 +622,172 @@ var init_method_decorator = __esm({
622
622
  }
623
623
  });
624
624
 
625
- // src/exceptions.ts
625
+ // src/utils/radix-tree.ts
626
+ var _RadixNode, RadixNode, _RadixTree, RadixTree;
627
+ var init_radix_tree = __esm({
628
+ "src/utils/radix-tree.ts"() {
629
+ "use strict";
630
+ _RadixNode = class _RadixNode {
631
+ /**
632
+ * Creates a new RadixNode.
633
+ * @param segment - The segment of the path this node represents.
634
+ */
635
+ constructor(segment) {
636
+ this.children = [];
637
+ this.segment = segment;
638
+ this.isParam = segment.startsWith(":");
639
+ if (this.isParam) {
640
+ this.paramName = segment.slice(1);
641
+ }
642
+ }
643
+ /**
644
+ * Matches a child node against a given segment.
645
+ * This method checks if the segment matches any of the children nodes.
646
+ * @param segment - The segment to match against the children of this node.
647
+ * @returns A child node that matches the segment, or undefined if no match is found.
648
+ */
649
+ matchChild(segment) {
650
+ for (const child of this.children) {
651
+ if (child.isParam || segment.startsWith(child.segment))
652
+ return child;
653
+ }
654
+ return void 0;
655
+ }
656
+ /**
657
+ * Finds a child node that matches the segment exactly.
658
+ * This method checks if there is a child node that matches the segment exactly.
659
+ * @param segment - The segment to find an exact match for among the children of this node.
660
+ * @returns A child node that matches the segment exactly, or undefined if no match is found.
661
+ */
662
+ findExactChild(segment) {
663
+ return this.children.find((c) => c.segment === segment);
664
+ }
665
+ /**
666
+ * Adds a child node to this node's children.
667
+ * This method adds a new child node to the list of children for this node.
668
+ * @param node - The child node to add to this node's children.
669
+ */
670
+ addChild(node) {
671
+ this.children.push(node);
672
+ }
673
+ };
674
+ __name(_RadixNode, "RadixNode");
675
+ RadixNode = _RadixNode;
676
+ _RadixTree = class _RadixTree {
677
+ constructor() {
678
+ this.root = new RadixNode("");
679
+ }
680
+ /**
681
+ * Inserts a path and its associated value into the Radix Tree.
682
+ * This method normalizes the path and inserts it into the tree, associating it with
683
+ * @param path - The path to insert into the tree.
684
+ * @param value - The value to associate with the path.
685
+ */
686
+ insert(path2, value) {
687
+ const segments = this.normalize(path2);
688
+ this.insertRecursive(this.root, segments, value);
689
+ }
690
+ /**
691
+ * Recursively inserts a path into the Radix Tree.
692
+ * This method traverses the tree and inserts the segments of the path, creating new nodes
693
+ * @param node - The node to start inserting from.
694
+ * @param segments - The segments of the path to insert.
695
+ * @param value - The value to associate with the path.
696
+ */
697
+ insertRecursive(node, segments, value) {
698
+ if (segments.length === 0) {
699
+ node.value = value;
700
+ return;
701
+ }
702
+ const segment = segments[0] ?? "";
703
+ let child = node.children.find(
704
+ (c) => c.isParam === segment.startsWith(":") && (c.isParam || c.segment === segment)
705
+ );
706
+ if (!child) {
707
+ child = new RadixNode(segment);
708
+ node.addChild(child);
709
+ }
710
+ this.insertRecursive(child, segments.slice(1), value);
711
+ }
712
+ /**
713
+ * Searches for a path in the Radix Tree.
714
+ * This method normalizes the path and searches for it in the tree, returning the node
715
+ * @param path - The path to search for in the Radix Tree.
716
+ * @returns An ISearchResult containing the node and parameters if a match is found, otherwise undefined.
717
+ */
718
+ search(path2) {
719
+ const segments = this.normalize(path2);
720
+ return this.searchRecursive(this.root, segments, {});
721
+ }
722
+ /**
723
+ * Recursively searches for a path in the Radix Tree.
724
+ * This method traverses the tree and searches for the segments of the path, collecting parameters
725
+ * @param node - The node to start searching from.
726
+ * @param segments - The segments of the path to search for.
727
+ * @param params - The parameters collected during the search.
728
+ * @returns An ISearchResult containing the node and parameters if a match is found, otherwise undefined.
729
+ */
730
+ searchRecursive(node, segments, params) {
731
+ if (segments.length === 0) {
732
+ if (node.value !== void 0) {
733
+ return {
734
+ node,
735
+ params
736
+ };
737
+ }
738
+ return void 0;
739
+ }
740
+ const [segment, ...rest] = segments;
741
+ for (const child of node.children) {
742
+ if (child.isParam) {
743
+ const paramName = child.paramName;
744
+ const childParams = {
745
+ ...params,
746
+ [paramName]: segment ?? ""
747
+ };
748
+ if (rest.length === 0) {
749
+ return {
750
+ node: child,
751
+ params: childParams
752
+ };
753
+ }
754
+ const result = this.searchRecursive(child, rest, childParams);
755
+ if (result)
756
+ return result;
757
+ } else if (segment === child.segment) {
758
+ if (rest.length === 0) {
759
+ return {
760
+ node: child,
761
+ params
762
+ };
763
+ }
764
+ const result = this.searchRecursive(child, rest, params);
765
+ if (result)
766
+ return result;
767
+ }
768
+ }
769
+ return void 0;
770
+ }
771
+ /**
772
+ * Normalizes a path into an array of segments.
773
+ * This method removes leading and trailing slashes, splits the path by slashes, and
774
+ * @param path - The path to normalize.
775
+ * @returns An array of normalized path segments.
776
+ */
777
+ normalize(path2) {
778
+ const segments = path2.replace(/^\/+|\/+$/g, "").split("/").filter(Boolean);
779
+ return ["", ...segments];
780
+ }
781
+ };
782
+ __name(_RadixTree, "RadixTree");
783
+ RadixTree = _RadixTree;
784
+ }
785
+ });
786
+
787
+ // src/internal/exceptions.ts
626
788
  var _ResponseException, ResponseException, _BadRequestException, BadRequestException, _UnauthorizedException, UnauthorizedException, _PaymentRequiredException, PaymentRequiredException, _ForbiddenException, ForbiddenException, _NotFoundException, NotFoundException, _MethodNotAllowedException, MethodNotAllowedException, _NotAcceptableException, NotAcceptableException, _RequestTimeoutException, RequestTimeoutException, _ConflictException, ConflictException, _UpgradeRequiredException, UpgradeRequiredException, _TooManyRequestsException, TooManyRequestsException, _InternalServerException, InternalServerException, _NotImplementedException, NotImplementedException, _BadGatewayException, BadGatewayException, _ServiceUnavailableException, ServiceUnavailableException, _GatewayTimeoutException, GatewayTimeoutException, _HttpVersionNotSupportedException, HttpVersionNotSupportedException, _VariantAlsoNegotiatesException, VariantAlsoNegotiatesException, _InsufficientStorageException, InsufficientStorageException, _LoopDetectedException, LoopDetectedException, _NotExtendedException, NotExtendedException, _NetworkAuthenticationRequiredException, NetworkAuthenticationRequiredException, _NetworkConnectTimeoutException, NetworkConnectTimeoutException;
627
789
  var init_exceptions = __esm({
628
- "src/exceptions.ts"() {
790
+ "src/internal/exceptions.ts"() {
629
791
  "use strict";
630
792
  _ResponseException = class _ResponseException extends Error {
631
793
  constructor(statusOrMessage, message) {
@@ -832,7 +994,7 @@ var init_exceptions = __esm({
832
994
  }
833
995
  });
834
996
 
835
- // src/request.ts
997
+ // src/internal/request.ts
836
998
  function createRendererEventMessage(event, payload) {
837
999
  return {
838
1000
  type: RENDERER_EVENT_TYPE,
@@ -849,7 +1011,7 @@ function isRendererEventMessage(value) {
849
1011
  }
850
1012
  var _Request, Request, RENDERER_EVENT_TYPE;
851
1013
  var init_request = __esm({
852
- "src/request.ts"() {
1014
+ "src/internal/request.ts"() {
853
1015
  "use strict";
854
1016
  init_app_injector();
855
1017
  _Request = class _Request {
@@ -873,185 +1035,23 @@ var init_request = __esm({
873
1035
  }
874
1036
  });
875
1037
 
876
- // src/utils/radix-tree.ts
877
- var _RadixNode, RadixNode, _RadixTree, RadixTree;
878
- var init_radix_tree = __esm({
879
- "src/utils/radix-tree.ts"() {
880
- "use strict";
881
- _RadixNode = class _RadixNode {
882
- /**
883
- * Creates a new RadixNode.
884
- * @param segment - The segment of the path this node represents.
885
- */
886
- constructor(segment) {
887
- this.children = [];
888
- this.segment = segment;
889
- this.isParam = segment.startsWith(":");
890
- if (this.isParam) {
891
- this.paramName = segment.slice(1);
892
- }
893
- }
894
- /**
895
- * Matches a child node against a given segment.
896
- * This method checks if the segment matches any of the children nodes.
897
- * @param segment - The segment to match against the children of this node.
898
- * @returns A child node that matches the segment, or undefined if no match is found.
899
- */
900
- matchChild(segment) {
901
- for (const child of this.children) {
902
- if (child.isParam || segment.startsWith(child.segment))
903
- return child;
904
- }
905
- return void 0;
906
- }
907
- /**
908
- * Finds a child node that matches the segment exactly.
909
- * This method checks if there is a child node that matches the segment exactly.
910
- * @param segment - The segment to find an exact match for among the children of this node.
911
- * @returns A child node that matches the segment exactly, or undefined if no match is found.
912
- */
913
- findExactChild(segment) {
914
- return this.children.find((c) => c.segment === segment);
915
- }
916
- /**
917
- * Adds a child node to this node's children.
918
- * This method adds a new child node to the list of children for this node.
919
- * @param node - The child node to add to this node's children.
920
- */
921
- addChild(node) {
922
- this.children.push(node);
923
- }
924
- };
925
- __name(_RadixNode, "RadixNode");
926
- RadixNode = _RadixNode;
927
- _RadixTree = class _RadixTree {
928
- constructor() {
929
- this.root = new RadixNode("");
930
- }
931
- /**
932
- * Inserts a path and its associated value into the Radix Tree.
933
- * This method normalizes the path and inserts it into the tree, associating it with
934
- * @param path - The path to insert into the tree.
935
- * @param value - The value to associate with the path.
936
- */
937
- insert(path2, value) {
938
- const segments = this.normalize(path2);
939
- this.insertRecursive(this.root, segments, value);
940
- }
941
- /**
942
- * Recursively inserts a path into the Radix Tree.
943
- * This method traverses the tree and inserts the segments of the path, creating new nodes
944
- * @param node - The node to start inserting from.
945
- * @param segments - The segments of the path to insert.
946
- * @param value - The value to associate with the path.
947
- */
948
- insertRecursive(node, segments, value) {
949
- if (segments.length === 0) {
950
- node.value = value;
951
- return;
952
- }
953
- const segment = segments[0] ?? "";
954
- let child = node.children.find(
955
- (c) => c.isParam === segment.startsWith(":") && (c.isParam || c.segment === segment)
956
- );
957
- if (!child) {
958
- child = new RadixNode(segment);
959
- node.addChild(child);
960
- }
961
- this.insertRecursive(child, segments.slice(1), value);
962
- }
963
- /**
964
- * Searches for a path in the Radix Tree.
965
- * This method normalizes the path and searches for it in the tree, returning the node
966
- * @param path - The path to search for in the Radix Tree.
967
- * @returns An ISearchResult containing the node and parameters if a match is found, otherwise undefined.
968
- */
969
- search(path2) {
970
- const segments = this.normalize(path2);
971
- return this.searchRecursive(this.root, segments, {});
972
- }
973
- /**
974
- * Recursively searches for a path in the Radix Tree.
975
- * This method traverses the tree and searches for the segments of the path, collecting parameters
976
- * @param node - The node to start searching from.
977
- * @param segments - The segments of the path to search for.
978
- * @param params - The parameters collected during the search.
979
- * @returns An ISearchResult containing the node and parameters if a match is found, otherwise undefined.
980
- */
981
- searchRecursive(node, segments, params) {
982
- if (segments.length === 0) {
983
- if (node.value !== void 0) {
984
- return {
985
- node,
986
- params
987
- };
988
- }
989
- return void 0;
990
- }
991
- const [segment, ...rest] = segments;
992
- for (const child of node.children) {
993
- if (child.isParam) {
994
- const paramName = child.paramName;
995
- const childParams = {
996
- ...params,
997
- [paramName]: segment ?? ""
998
- };
999
- if (rest.length === 0) {
1000
- return {
1001
- node: child,
1002
- params: childParams
1003
- };
1004
- }
1005
- const result = this.searchRecursive(child, rest, childParams);
1006
- if (result)
1007
- return result;
1008
- } else if (segment === child.segment) {
1009
- if (rest.length === 0) {
1010
- return {
1011
- node: child,
1012
- params
1013
- };
1014
- }
1015
- const result = this.searchRecursive(child, rest, params);
1016
- if (result)
1017
- return result;
1018
- }
1019
- }
1020
- return void 0;
1021
- }
1022
- /**
1023
- * Normalizes a path into an array of segments.
1024
- * This method removes leading and trailing slashes, splits the path by slashes, and
1025
- * @param path - The path to normalize.
1026
- * @returns An array of normalized path segments.
1027
- */
1028
- normalize(path2) {
1029
- const segments = path2.replace(/^\/+|\/+$/g, "").split("/").filter(Boolean);
1030
- return ["", ...segments];
1031
- }
1032
- };
1033
- __name(_RadixTree, "RadixTree");
1034
- RadixTree = _RadixTree;
1035
- }
1036
- });
1037
-
1038
- // src/router.ts
1038
+ // src/internal/router.ts
1039
1039
  var router_exports = {};
1040
1040
  __export(router_exports, {
1041
1041
  Router: () => Router
1042
1042
  });
1043
1043
  var Router;
1044
1044
  var init_router = __esm({
1045
- "src/router.ts"() {
1045
+ "src/internal/router.ts"() {
1046
1046
  "use strict";
1047
1047
  init_controller_decorator();
1048
1048
  init_injectable_decorator();
1049
1049
  init_method_decorator();
1050
1050
  init_injector_explorer();
1051
- init_exceptions();
1052
- init_request();
1053
1051
  init_logger();
1054
1052
  init_radix_tree();
1053
+ init_exceptions();
1054
+ init_request();
1055
1055
  Router = class {
1056
1056
  constructor() {
1057
1057
  this.routes = new RadixTree();
@@ -1295,67 +1295,12 @@ init_app_injector();
1295
1295
  init_token();
1296
1296
  init_router();
1297
1297
 
1298
- // src/app.ts
1298
+ // src/internal/app.ts
1299
1299
  init_injectable_decorator();
1300
1300
  init_app_injector();
1301
1301
  init_injector_explorer();
1302
- init_request();
1303
- init_router();
1304
- import { app, BrowserWindow as BrowserWindow2, ipcMain, MessageChannelMain } from "electron/main";
1305
-
1306
- // src/socket.ts
1307
- init_injectable_decorator();
1308
- init_request();
1309
- init_logger();
1310
- var NoxSocket = class {
1311
- constructor() {
1312
- this.channels = /* @__PURE__ */ new Map();
1313
- }
1314
- register(senderId, requestChannel, socketChannel) {
1315
- this.channels.set(senderId, { request: requestChannel, socket: socketChannel });
1316
- }
1317
- get(senderId) {
1318
- return this.channels.get(senderId);
1319
- }
1320
- unregister(senderId) {
1321
- this.channels.delete(senderId);
1322
- }
1323
- getSenderIds() {
1324
- return [...this.channels.keys()];
1325
- }
1326
- emit(eventName, payload, targetSenderIds) {
1327
- const normalizedEvent = eventName.trim();
1328
- if (normalizedEvent.length === 0) {
1329
- throw new Error("Renderer event name must be a non-empty string.");
1330
- }
1331
- const recipients = targetSenderIds ?? this.getSenderIds();
1332
- let delivered = 0;
1333
- for (const senderId of recipients) {
1334
- const channel = this.channels.get(senderId);
1335
- if (!channel) {
1336
- Logger.warn(`No message channel found for sender ID: ${senderId} while emitting "${normalizedEvent}".`);
1337
- continue;
1338
- }
1339
- try {
1340
- channel.socket.port1.postMessage(createRendererEventMessage(normalizedEvent, payload));
1341
- delivered++;
1342
- } catch (error) {
1343
- Logger.error(`[Noxus] Failed to emit "${normalizedEvent}" to sender ${senderId}.`, error);
1344
- }
1345
- }
1346
- return delivered;
1347
- }
1348
- emitToRenderer(senderId, eventName, payload) {
1349
- return this.emit(eventName, payload, [senderId]) > 0;
1350
- }
1351
- };
1352
- __name(NoxSocket, "NoxSocket");
1353
- NoxSocket = __decorateClass([
1354
- Injectable({ lifetime: "singleton" })
1355
- ], NoxSocket);
1356
-
1357
- // src/app.ts
1358
1302
  init_logger();
1303
+ import { app, BrowserWindow as BrowserWindow2, ipcMain, MessageChannelMain } from "electron/main";
1359
1304
 
1360
1305
  // src/window/window-manager.ts
1361
1306
  init_injectable_decorator();
@@ -1526,7 +1471,62 @@ WindowManager = __decorateClass([
1526
1471
  Injectable({ lifetime: "singleton" })
1527
1472
  ], WindowManager);
1528
1473
 
1529
- // src/app.ts
1474
+ // src/internal/app.ts
1475
+ init_request();
1476
+ init_router();
1477
+
1478
+ // src/internal/socket.ts
1479
+ init_injectable_decorator();
1480
+ init_logger();
1481
+ init_request();
1482
+ var NoxSocket = class {
1483
+ constructor() {
1484
+ this.channels = /* @__PURE__ */ new Map();
1485
+ }
1486
+ register(senderId, requestChannel, socketChannel) {
1487
+ this.channels.set(senderId, { request: requestChannel, socket: socketChannel });
1488
+ }
1489
+ get(senderId) {
1490
+ return this.channels.get(senderId);
1491
+ }
1492
+ unregister(senderId) {
1493
+ this.channels.delete(senderId);
1494
+ }
1495
+ getSenderIds() {
1496
+ return [...this.channels.keys()];
1497
+ }
1498
+ emit(eventName, payload, targetSenderIds) {
1499
+ const normalizedEvent = eventName.trim();
1500
+ if (normalizedEvent.length === 0) {
1501
+ throw new Error("Renderer event name must be a non-empty string.");
1502
+ }
1503
+ const recipients = targetSenderIds ?? this.getSenderIds();
1504
+ let delivered = 0;
1505
+ for (const senderId of recipients) {
1506
+ const channel = this.channels.get(senderId);
1507
+ if (!channel) {
1508
+ Logger.warn(`No message channel found for sender ID: ${senderId} while emitting "${normalizedEvent}".`);
1509
+ continue;
1510
+ }
1511
+ try {
1512
+ channel.socket.port1.postMessage(createRendererEventMessage(normalizedEvent, payload));
1513
+ delivered++;
1514
+ } catch (error) {
1515
+ Logger.error(`[Noxus] Failed to emit "${normalizedEvent}" to sender ${senderId}.`, error);
1516
+ }
1517
+ }
1518
+ return delivered;
1519
+ }
1520
+ emitToRenderer(senderId, eventName, payload) {
1521
+ return this.emit(eventName, payload, [senderId]) > 0;
1522
+ }
1523
+ };
1524
+ __name(NoxSocket, "NoxSocket");
1525
+ NoxSocket = __decorateClass([
1526
+ Injectable({ lifetime: "singleton" })
1527
+ ], NoxSocket);
1528
+
1529
+ // src/internal/app.ts
1530
1530
  var NoxApp = class {
1531
1531
  constructor() {
1532
1532
  this.router = inject(Router);
@@ -1668,10 +1668,10 @@ NoxApp = __decorateClass([
1668
1668
  Injectable({ lifetime: "singleton", deps: [Router, NoxSocket, WindowManager] })
1669
1669
  ], NoxApp);
1670
1670
 
1671
- // src/bootstrap.ts
1672
- import { app as app2 } from "electron/main";
1671
+ // src/internal/bootstrap.ts
1673
1672
  init_app_injector();
1674
1673
  init_injector_explorer();
1674
+ import { app as app2 } from "electron/main";
1675
1675
  async function bootstrapApplication(config = {}) {
1676
1676
  await app2.whenReady();
1677
1677
  const overrides = /* @__PURE__ */ new Map();
@@ -1703,7 +1703,7 @@ init_logger();
1703
1703
  init_forward_ref();
1704
1704
  init_request();
1705
1705
 
1706
- // src/routes.ts
1706
+ // src/internal/routes.ts
1707
1707
  function defineRoutes(routes) {
1708
1708
  const paths = routes.map((r) => r.path.replace(/^\/+|\/+$/g, ""));
1709
1709
  const duplicates = paths.filter((p, i) => paths.indexOf(p) !== i);
@@ -0,0 +1,28 @@
1
+ /**
2
+ * @copyright 2025 NoxFly
3
+ * @license MIT
4
+ * @author NoxFly
5
+ */
6
+
7
+ interface IPortRequester {
8
+ requestPort(): void;
9
+ }
10
+
11
+
12
+ interface NoxusPreloadAPI extends IPortRequester {
13
+ }
14
+ interface NoxusPreloadOptions {
15
+ exposeAs?: string;
16
+ initMessageType?: string;
17
+ requestChannel?: string;
18
+ responseChannel?: string;
19
+ targetWindow?: Window;
20
+ }
21
+ /**
22
+ * Exposes a minimal bridge in the isolated preload context so renderer processes
23
+ * can request the two MessagePorts required by Noxus. The bridge forwards both
24
+ * request/response and socket ports to the renderer via window.postMessage.
25
+ */
26
+ declare function exposeNoxusBridge(options?: NoxusPreloadOptions): NoxusPreloadAPI;
27
+
28
+ export { type NoxusPreloadAPI, type NoxusPreloadOptions, exposeNoxusBridge };
@@ -0,0 +1,28 @@
1
+ /**
2
+ * @copyright 2025 NoxFly
3
+ * @license MIT
4
+ * @author NoxFly
5
+ */
6
+
7
+ interface IPortRequester {
8
+ requestPort(): void;
9
+ }
10
+
11
+
12
+ interface NoxusPreloadAPI extends IPortRequester {
13
+ }
14
+ interface NoxusPreloadOptions {
15
+ exposeAs?: string;
16
+ initMessageType?: string;
17
+ requestChannel?: string;
18
+ responseChannel?: string;
19
+ targetWindow?: Window;
20
+ }
21
+ /**
22
+ * Exposes a minimal bridge in the isolated preload context so renderer processes
23
+ * can request the two MessagePorts required by Noxus. The bridge forwards both
24
+ * request/response and socket ports to the renderer via window.postMessage.
25
+ */
26
+ declare function exposeNoxusBridge(options?: NoxusPreloadOptions): NoxusPreloadAPI;
27
+
28
+ export { type NoxusPreloadAPI, type NoxusPreloadOptions, exposeNoxusBridge };
@@ -0,0 +1,95 @@
1
+ /**
2
+ * @copyright 2025 NoxFly
3
+ * @license MIT
4
+ * @author NoxFly
5
+ */
6
+ "use strict";
7
+ var __defProp = Object.defineProperty;
8
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
9
+ var __getOwnPropNames = Object.getOwnPropertyNames;
10
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
11
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
12
+ var __export = (target, all) => {
13
+ for (var name in all)
14
+ __defProp(target, name, { get: all[name], enumerable: true });
15
+ };
16
+ var __copyProps = (to, from, except, desc) => {
17
+ if (from && typeof from === "object" || typeof from === "function") {
18
+ for (let key of __getOwnPropNames(from))
19
+ if (!__hasOwnProp.call(to, key) && key !== except)
20
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
21
+ }
22
+ return to;
23
+ };
24
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
+
26
+ // src/preload.ts
27
+ var preload_exports = {};
28
+ __export(preload_exports, {
29
+ exposeNoxusBridge: () => exposeNoxusBridge
30
+ });
31
+ module.exports = __toCommonJS(preload_exports);
32
+
33
+ // src/internal/preload-bridge.ts
34
+ var import_renderer = require("electron/renderer");
35
+ var DEFAULT_EXPOSE_NAME = "noxus";
36
+ var DEFAULT_INIT_EVENT = "init-port";
37
+ var DEFAULT_REQUEST_CHANNEL = "gimme-my-port";
38
+ var DEFAULT_RESPONSE_CHANNEL = "port";
39
+ function exposeNoxusBridge(options = {}) {
40
+ const {
41
+ exposeAs = DEFAULT_EXPOSE_NAME,
42
+ initMessageType = DEFAULT_INIT_EVENT,
43
+ requestChannel = DEFAULT_REQUEST_CHANNEL,
44
+ responseChannel = DEFAULT_RESPONSE_CHANNEL,
45
+ targetWindow = window
46
+ } = options;
47
+ const api = {
48
+ requestPort: /* @__PURE__ */ __name(() => {
49
+ import_renderer.ipcRenderer.send(requestChannel);
50
+ import_renderer.ipcRenderer.once(responseChannel, (event, message) => {
51
+ const ports = (event.ports ?? []).filter((port) => port !== void 0);
52
+ if (ports.length === 0) {
53
+ console.error("[Noxus] No MessagePort received from main process.");
54
+ return;
55
+ }
56
+ for (const port of ports) {
57
+ try {
58
+ port.start();
59
+ } catch (error) {
60
+ console.error("[Noxus] Failed to start MessagePort.", error);
61
+ }
62
+ }
63
+ targetWindow.postMessage(
64
+ {
65
+ type: initMessageType,
66
+ senderId: message?.senderId
67
+ },
68
+ "*",
69
+ ports
70
+ );
71
+ });
72
+ }, "requestPort")
73
+ };
74
+ import_renderer.contextBridge.exposeInMainWorld(exposeAs, api);
75
+ return api;
76
+ }
77
+ __name(exposeNoxusBridge, "exposeNoxusBridge");
78
+ // Annotate the CommonJS export names for ESM import in node:
79
+ 0 && (module.exports = {
80
+ exposeNoxusBridge
81
+ });
82
+ /**
83
+ * @copyright 2025 NoxFly
84
+ * @license MIT
85
+ * @author NoxFly
86
+ */
87
+ /**
88
+ * @copyright 2025 NoxFly
89
+ * @license MIT
90
+ * @author NoxFly
91
+ *
92
+ * Entry point for Electron preload scripts.
93
+ * Imports electron/renderer — must NOT be bundled into renderer web code.
94
+ */
95
+ //# sourceMappingURL=preload.js.map