@gtkx/runtime 1.0.0-rc.1 → 1.0.0-rc.2

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 (116) hide show
  1. package/dist/arg.d.ts +6 -5
  2. package/dist/arg.d.ts.map +1 -1
  3. package/dist/arg.js +5 -4
  4. package/dist/arg.js.map +1 -1
  5. package/dist/bind.d.ts +3 -2
  6. package/dist/bind.d.ts.map +1 -1
  7. package/dist/bind.js +5 -3
  8. package/dist/bind.js.map +1 -1
  9. package/dist/callback.d.ts +3 -3
  10. package/dist/callback.d.ts.map +1 -1
  11. package/dist/callback.js +51 -33
  12. package/dist/callback.js.map +1 -1
  13. package/dist/descriptors.d.ts +67 -64
  14. package/dist/descriptors.d.ts.map +1 -1
  15. package/dist/descriptors.js +92 -60
  16. package/dist/descriptors.js.map +1 -1
  17. package/dist/error.d.ts +5 -6
  18. package/dist/error.d.ts.map +1 -1
  19. package/dist/error.js +10 -6
  20. package/dist/error.js.map +1 -1
  21. package/dist/exit-hook.d.ts +2 -0
  22. package/dist/exit-hook.d.ts.map +1 -0
  23. package/dist/exit-hook.js +3 -0
  24. package/dist/exit-hook.js.map +1 -0
  25. package/dist/fn.d.ts +2 -2
  26. package/dist/fn.d.ts.map +1 -1
  27. package/dist/fn.js +26 -15
  28. package/dist/fn.js.map +1 -1
  29. package/dist/index.d.ts +3 -2
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +2 -1
  32. package/dist/index.js.map +1 -1
  33. package/dist/library.d.ts +6 -5
  34. package/dist/library.d.ts.map +1 -1
  35. package/dist/library.js +6 -5
  36. package/dist/library.js.map +1 -1
  37. package/dist/lifecycle.d.ts +10 -9
  38. package/dist/lifecycle.d.ts.map +1 -1
  39. package/dist/lifecycle.js +38 -23
  40. package/dist/lifecycle.js.map +1 -1
  41. package/dist/listeners.d.ts +8 -8
  42. package/dist/listeners.d.ts.map +1 -1
  43. package/dist/listeners.js +28 -15
  44. package/dist/listeners.js.map +1 -1
  45. package/dist/mixin.d.ts +5 -11
  46. package/dist/mixin.d.ts.map +1 -1
  47. package/dist/mixin.js +24 -14
  48. package/dist/mixin.js.map +1 -1
  49. package/dist/native-value.d.ts +3 -2
  50. package/dist/native-value.d.ts.map +1 -1
  51. package/dist/native-value.js +75 -42
  52. package/dist/native-value.js.map +1 -1
  53. package/dist/object.d.ts +4 -3
  54. package/dist/object.d.ts.map +1 -1
  55. package/dist/object.js +8 -5
  56. package/dist/object.js.map +1 -1
  57. package/dist/promisify.d.ts +9 -1
  58. package/dist/promisify.d.ts.map +1 -1
  59. package/dist/promisify.js +18 -15
  60. package/dist/promisify.js.map +1 -1
  61. package/dist/properties.d.ts +14 -0
  62. package/dist/properties.d.ts.map +1 -0
  63. package/dist/properties.js +79 -0
  64. package/dist/properties.js.map +1 -0
  65. package/dist/register-class.d.ts +10 -2
  66. package/dist/register-class.d.ts.map +1 -1
  67. package/dist/register-class.js +83 -29
  68. package/dist/register-class.js.map +1 -1
  69. package/dist/registry.d.ts +23 -21
  70. package/dist/registry.d.ts.map +1 -1
  71. package/dist/registry.js +54 -35
  72. package/dist/registry.js.map +1 -1
  73. package/dist/signal.d.ts +7 -6
  74. package/dist/signal.d.ts.map +1 -1
  75. package/dist/signal.js +19 -12
  76. package/dist/signal.js.map +1 -1
  77. package/dist/t.d.ts +2 -2
  78. package/dist/t.d.ts.map +1 -1
  79. package/dist/t.js +2 -1
  80. package/dist/t.js.map +1 -1
  81. package/dist/tuple.d.ts +3 -2
  82. package/dist/tuple.d.ts.map +1 -1
  83. package/dist/tuple.js +7 -4
  84. package/dist/tuple.js.map +1 -1
  85. package/dist/type.d.ts +48 -41
  86. package/dist/type.d.ts.map +1 -1
  87. package/dist/type.js +107 -87
  88. package/dist/type.js.map +1 -1
  89. package/dist/value.d.ts +19 -10
  90. package/dist/value.d.ts.map +1 -1
  91. package/dist/value.js +164 -99
  92. package/dist/value.js.map +1 -1
  93. package/package.json +4 -6
  94. package/src/arg.ts +7 -5
  95. package/src/bind.ts +13 -4
  96. package/src/callback.ts +97 -35
  97. package/src/descriptors.ts +227 -85
  98. package/src/error.ts +18 -9
  99. package/src/exit-hook.ts +3 -0
  100. package/src/fn.ts +53 -22
  101. package/src/index.ts +4 -2
  102. package/src/library.ts +7 -5
  103. package/src/lifecycle.ts +54 -26
  104. package/src/listeners.ts +46 -18
  105. package/src/mixin.ts +39 -14
  106. package/src/native-value.ts +103 -46
  107. package/src/object.ts +19 -7
  108. package/src/promisify.ts +42 -15
  109. package/src/properties.ts +115 -0
  110. package/src/register-class.ts +157 -30
  111. package/src/registry.ts +144 -54
  112. package/src/signal.ts +53 -13
  113. package/src/t.ts +3 -1
  114. package/src/tuple.ts +16 -4
  115. package/src/type.ts +183 -93
  116. package/src/value.ts +231 -108
@@ -1 +1 @@
1
- {"version":3,"file":"library.d.ts","sourceRoot":"","sources":["../src/library.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,eAAe,EAAU,KAAK,qBAAqB,EAAgB,MAAM,kBAAkB,CAAC;AAE1G,eAAO,MAAM,GAAG,yCAAyC,CAAC;AAC1D,eAAO,MAAM,UAAU,KAAK,CAAC;AAC7B,eAAO,MAAM,OAAO,EAAE,eAA6F,CAAC;AAEpH,eAAO,MAAM,OAAO,EAAE,qBAGpB,CAAC;AAEH,eAAO,MAAM,SAAS,EAAE,qBAGtB,CAAC"}
1
+ {"version":3,"file":"library.d.ts","sourceRoot":"","sources":["../src/library.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,eAAe,EAAU,KAAK,qBAAqB,EAAgB,MAAM,kBAAkB,CAAC;AAE1G,QAAA,MAAM,GAAG,yCAAyC,CAAC;AACnD,QAAA,MAAM,UAAU,KAAK,CAAC;AACtB,QAAA,MAAM,OAAO,EAAE,eAA6F,CAAC;AAE7G,QAAA,MAAM,OAAO,EAAE,qBAGb,CAAC;AAEH,QAAA,MAAM,SAAS,EAAE,qBAGf,CAAC;AAEH,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC"}
package/dist/library.js CHANGED
@@ -1,13 +1,14 @@
1
1
  import { boxedT, fundamentalT } from "./descriptors.js";
2
- export const LIB = "libgobject-2.0.so.0,libglib-2.0.so.0";
3
- export const VALUE_SIZE = 24;
4
- export const VALUE_T = boxedT("GValue", { sharedLibrary: LIB, getTypeFnName: "g_value_get_type" });
5
- export const PARAM_T = fundamentalT(LIB, "g_param_spec_ref", "g_param_spec_unref", {
2
+ const LIB = "libgobject-2.0.so.0,libglib-2.0.so.0";
3
+ const VALUE_SIZE = 24;
4
+ const VALUE_T = boxedT("GValue", { sharedLibrary: LIB, getTypeFnName: "g_value_get_type" });
5
+ const PARAM_T = fundamentalT(LIB, "g_param_spec_ref", "g_param_spec_unref", {
6
6
  ownership: "borrowed",
7
7
  typeName: "GParam",
8
8
  });
9
- export const VARIANT_T = fundamentalT(LIB, "g_variant_ref", "g_variant_unref", {
9
+ const VARIANT_T = fundamentalT(LIB, "g_variant_ref", "g_variant_unref", {
10
10
  ownership: "borrowed",
11
11
  typeName: "GVariant",
12
12
  });
13
+ export { LIB, VALUE_SIZE, VALUE_T, PARAM_T, VARIANT_T };
13
14
  //# sourceMappingURL=library.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"library.js","sourceRoot":"","sources":["../src/library.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,MAAM,EAA8B,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAE1G,MAAM,CAAC,MAAM,GAAG,GAAG,sCAAsC,CAAC;AAC1D,MAAM,CAAC,MAAM,UAAU,GAAG,EAAE,CAAC;AAC7B,MAAM,CAAC,MAAM,OAAO,GAAoB,MAAM,CAAC,QAAQ,EAAE,EAAE,aAAa,EAAE,GAAG,EAAE,aAAa,EAAE,kBAAkB,EAAE,CAAC,CAAC;AAEpH,MAAM,CAAC,MAAM,OAAO,GAA0B,YAAY,CAAC,GAAG,EAAE,kBAAkB,EAAE,oBAAoB,EAAE;IACtG,SAAS,EAAE,UAAU;IACrB,QAAQ,EAAE,QAAQ;CACrB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,SAAS,GAA0B,YAAY,CAAC,GAAG,EAAE,eAAe,EAAE,iBAAiB,EAAE;IAClG,SAAS,EAAE,UAAU;IACrB,QAAQ,EAAE,UAAU;CACvB,CAAC,CAAC","sourcesContent":["import { type BoxedDescriptor, boxedT, type FundamentalDescriptor, fundamentalT } from \"./descriptors.js\";\n\nexport const LIB = \"libgobject-2.0.so.0,libglib-2.0.so.0\";\nexport const VALUE_SIZE = 24;\nexport const VALUE_T: BoxedDescriptor = boxedT(\"GValue\", { sharedLibrary: LIB, getTypeFnName: \"g_value_get_type\" });\n\nexport const PARAM_T: FundamentalDescriptor = fundamentalT(LIB, \"g_param_spec_ref\", \"g_param_spec_unref\", {\n ownership: \"borrowed\",\n typeName: \"GParam\",\n});\n\nexport const VARIANT_T: FundamentalDescriptor = fundamentalT(LIB, \"g_variant_ref\", \"g_variant_unref\", {\n ownership: \"borrowed\",\n typeName: \"GVariant\",\n});\n"]}
1
+ {"version":3,"file":"library.js","sourceRoot":"","sources":["../src/library.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,MAAM,EAA8B,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAE1G,MAAM,GAAG,GAAG,sCAAsC,CAAC;AACnD,MAAM,UAAU,GAAG,EAAE,CAAC;AACtB,MAAM,OAAO,GAAoB,MAAM,CAAC,QAAQ,EAAE,EAAE,aAAa,EAAE,GAAG,EAAE,aAAa,EAAE,kBAAkB,EAAE,CAAC,CAAC;AAE7G,MAAM,OAAO,GAA0B,YAAY,CAAC,GAAG,EAAE,kBAAkB,EAAE,oBAAoB,EAAE;IAC/F,SAAS,EAAE,UAAU;IACrB,QAAQ,EAAE,QAAQ;CACrB,CAAC,CAAC;AAEH,MAAM,SAAS,GAA0B,YAAY,CAAC,GAAG,EAAE,eAAe,EAAE,iBAAiB,EAAE;IAC3F,SAAS,EAAE,UAAU;IACrB,QAAQ,EAAE,UAAU;CACvB,CAAC,CAAC;AAEH,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC","sourcesContent":["import { type BoxedDescriptor, boxedT, type FundamentalDescriptor, fundamentalT } from \"./descriptors.js\";\n\nconst LIB = \"libgobject-2.0.so.0,libglib-2.0.so.0\";\nconst VALUE_SIZE = 24;\nconst VALUE_T: BoxedDescriptor = boxedT(\"GValue\", { sharedLibrary: LIB, getTypeFnName: \"g_value_get_type\" });\n\nconst PARAM_T: FundamentalDescriptor = fundamentalT(LIB, \"g_param_spec_ref\", \"g_param_spec_unref\", {\n ownership: \"borrowed\",\n typeName: \"GParam\",\n});\n\nconst VARIANT_T: FundamentalDescriptor = fundamentalT(LIB, \"g_variant_ref\", \"g_variant_unref\", {\n ownership: \"borrowed\",\n typeName: \"GVariant\",\n});\n\nexport { LIB, VALUE_SIZE, VALUE_T, PARAM_T, VARIANT_T };\n"]}
@@ -2,7 +2,7 @@
2
2
  * Minimal structural interface of a GTK4/GIO application needed to register, run,
3
3
  * and shut it down, plus the signals its lifecycle helpers connect to.
4
4
  */
5
- export type ApplicationLike = {
5
+ type ApplicationLike = {
6
6
  getIsRegistered(): boolean;
7
7
  register(cancellable: null): boolean;
8
8
  activate(): void;
@@ -12,30 +12,31 @@ export type ApplicationLike = {
12
12
  removeWindow?(window: object): void;
13
13
  on(signal: "activate" | "shutdown", handler: () => void): unknown;
14
14
  };
15
+ /**
16
+ * Runs every registered exit callback and shuts down the native runtime. Safe to
17
+ * call more than once; only the first call takes effect.
18
+ */
19
+ declare const quit: () => void;
15
20
  /**
16
21
  * Registers a callback to run once when the process quits, before the native
17
22
  * runtime is torn down.
18
23
  *
19
24
  * @param callback Invoked during shutdown.
20
25
  */
21
- export declare const onExit: (callback: () => void) => void;
22
- /**
23
- * Runs every registered exit callback and shuts down the native runtime. Safe to
24
- * call more than once; only the first call takes effect.
25
- */
26
- export declare const quit: () => void;
26
+ declare const onExit: (callback: () => void) => void;
27
27
  /**
28
28
  * Registers the application if needed and activates it, keeping the runtime alive
29
29
  * while it is active and releasing it on shutdown.
30
30
  *
31
31
  * @param application The application to register and activate.
32
32
  */
33
- export declare const runApplication: (application: ApplicationLike) => void;
33
+ declare const runApplication: (application: ApplicationLike) => void;
34
34
  /**
35
35
  * Closes all of the application's windows and drives its main loop until it quits,
36
36
  * so pending shutdown work can complete before the process exits.
37
37
  *
38
38
  * @param application The application to shut down.
39
39
  */
40
- export declare const quitApplication: (application: ApplicationLike) => void;
40
+ declare const quitApplication: (application: ApplicationLike) => void;
41
+ export { onExit, quit, runApplication, quitApplication, type ApplicationLike };
41
42
  //# sourceMappingURL=lifecycle.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"lifecycle.d.ts","sourceRoot":"","sources":["../src/lifecycle.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG;IAC1B,eAAe,IAAI,OAAO,CAAC;IAC3B,QAAQ,CAAC,WAAW,EAAE,IAAI,GAAG,OAAO,CAAC;IACrC,QAAQ,IAAI,IAAI,CAAC;IACjB,IAAI,IAAI,IAAI,CAAC;IACb,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IAC5B,UAAU,CAAC,IAAI,MAAM,EAAE,CAAC;IACxB,YAAY,CAAC,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,EAAE,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,EAAE,OAAO,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC;CACrE,CAAC;AAKF;;;;;GAKG;AACH,eAAO,MAAM,MAAM,aAAc,MAAM,IAAI,KAAG,IAE7C,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,IAAI,QAAO,IAOvB,CAAC;AAIF;;;;;GAKG;AACH,eAAO,MAAM,cAAc,gBAAiB,eAAe,KAAG,IAM7D,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,eAAe,gBAAiB,eAAe,KAAG,IAM9D,CAAC"}
1
+ {"version":3,"file":"lifecycle.d.ts","sourceRoot":"","sources":["../src/lifecycle.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,KAAK,eAAe,GAAG;IACnB,eAAe,IAAI,OAAO,CAAC;IAC3B,QAAQ,CAAC,WAAW,EAAE,IAAI,GAAG,OAAO,CAAC;IACrC,QAAQ,IAAI,IAAI,CAAC;IACjB,IAAI,IAAI,IAAI,CAAC;IACb,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IAC5B,UAAU,CAAC,IAAI,MAAM,EAAE,CAAC;IACxB,YAAY,CAAC,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,EAAE,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,EAAE,OAAO,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC;CACrE,CAAC;AAGF;;;GAGG;AACH,QAAA,MAAM,IAAI,EAAE,MAAM,IAAmB,CAAC;AAoBtC;;;;;GAKG;AACH,QAAA,MAAM,MAAM,GAAI,UAAU,MAAM,IAAI,KAAG,IAEtC,CAAC;AAEF;;;;;GAKG;AACH,QAAA,MAAM,cAAc,GAAI,aAAa,eAAe,KAAG,IActD,CAAC;AAEF;;;;;GAKG;AACH,QAAA,MAAM,eAAe,GAAI,aAAa,eAAe,KAAG,IAiBvD,CAAC;AAEF,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,EAAE,eAAe,EAAE,KAAK,eAAe,EAAE,CAAC"}
package/dist/lifecycle.js CHANGED
@@ -1,40 +1,49 @@
1
1
  import { keepAlive, quit as nativeQuit } from "@gtkx/native";
2
2
  import { blockMatchedSignalHandlers } from "./signal.js";
3
3
  const shutdownCallbacks = [];
4
- let hasQuit = false;
4
+ /**
5
+ * Runs every registered exit callback and shuts down the native runtime. Safe to
6
+ * call more than once; only the first call takes effect.
7
+ */
8
+ const quit = createQuit();
9
+ function createQuit() {
10
+ let hasQuit = false;
11
+ return () => {
12
+ if (hasQuit) {
13
+ return;
14
+ }
15
+ hasQuit = true;
16
+ for (const callback of shutdownCallbacks) {
17
+ callback();
18
+ }
19
+ nativeQuit();
20
+ };
21
+ }
5
22
  /**
6
23
  * Registers a callback to run once when the process quits, before the native
7
24
  * runtime is torn down.
8
25
  *
9
26
  * @param callback Invoked during shutdown.
10
27
  */
11
- export const onExit = (callback) => {
28
+ const onExit = (callback) => {
12
29
  shutdownCallbacks.push(callback);
13
30
  };
14
- /**
15
- * Runs every registered exit callback and shuts down the native runtime. Safe to
16
- * call more than once; only the first call takes effect.
17
- */
18
- export const quit = () => {
19
- if (hasQuit)
20
- return;
21
- hasQuit = true;
22
- for (const callback of shutdownCallbacks)
23
- callback();
24
- nativeQuit();
25
- };
26
- process.on("exit", quit);
27
31
  /**
28
32
  * Registers the application if needed and activates it, keeping the runtime alive
29
33
  * while it is active and releasing it on shutdown.
30
34
  *
31
35
  * @param application The application to register and activate.
32
36
  */
33
- export const runApplication = (application) => {
34
- application.on("activate", () => keepAlive(true));
35
- application.on("shutdown", () => keepAlive(false));
36
- if (!application.getIsRegistered())
37
+ const runApplication = (application) => {
38
+ application.on("activate", () => {
39
+ keepAlive(true);
40
+ });
41
+ application.on("shutdown", () => {
42
+ keepAlive(false);
43
+ });
44
+ if (!application.getIsRegistered()) {
37
45
  application.register(null);
46
+ }
38
47
  application.activate();
39
48
  };
40
49
  /**
@@ -43,13 +52,19 @@ export const runApplication = (application) => {
43
52
  *
44
53
  * @param application The application to shut down.
45
54
  */
46
- export const quitApplication = (application) => {
47
- if (!application.getIsRegistered())
55
+ const quitApplication = (application) => {
56
+ if (!application.getIsRegistered()) {
48
57
  return;
49
- for (const window of application.getWindows?.() ?? [])
58
+ }
59
+ const windows = application.getWindows?.() ?? [];
60
+ for (const window of windows) {
50
61
  application.removeWindow?.(window);
51
- application.on("shutdown", () => application.quit());
62
+ }
63
+ application.on("shutdown", () => {
64
+ application.quit();
65
+ });
52
66
  blockMatchedSignalHandlers(application, "activate");
53
67
  application.run([]);
54
68
  };
69
+ export { onExit, quit, runApplication, quitApplication };
55
70
  //# sourceMappingURL=lifecycle.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"lifecycle.js","sourceRoot":"","sources":["../src/lifecycle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,IAAI,IAAI,UAAU,EAAE,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AAiBzD,MAAM,iBAAiB,GAAmB,EAAE,CAAC;AAC7C,IAAI,OAAO,GAAG,KAAK,CAAC;AAEpB;;;;;GAKG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,QAAoB,EAAQ,EAAE;IACjD,iBAAiB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AACrC,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,GAAS,EAAE;IAC3B,IAAI,OAAO;QAAE,OAAO;IACpB,OAAO,GAAG,IAAI,CAAC;IAEf,KAAK,MAAM,QAAQ,IAAI,iBAAiB;QAAE,QAAQ,EAAE,CAAC;IAErD,UAAU,EAAE,CAAC;AACjB,CAAC,CAAC;AAEF,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AAEzB;;;;;GAKG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,WAA4B,EAAQ,EAAE;IACjE,WAAW,CAAC,EAAE,CAAC,UAAU,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;IAClD,WAAW,CAAC,EAAE,CAAC,UAAU,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;IAEnD,IAAI,CAAC,WAAW,CAAC,eAAe,EAAE;QAAE,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC/D,WAAW,CAAC,QAAQ,EAAE,CAAC;AAC3B,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,WAA4B,EAAQ,EAAE;IAClE,IAAI,CAAC,WAAW,CAAC,eAAe,EAAE;QAAE,OAAO;IAC3C,KAAK,MAAM,MAAM,IAAI,WAAW,CAAC,UAAU,EAAE,EAAE,IAAI,EAAE;QAAE,WAAW,CAAC,YAAY,EAAE,CAAC,MAAM,CAAC,CAAC;IAC1F,WAAW,CAAC,EAAE,CAAC,UAAU,EAAE,GAAG,EAAE,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC;IACrD,0BAA0B,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;IACpD,WAAW,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AACxB,CAAC,CAAC","sourcesContent":["import { keepAlive, quit as nativeQuit } from \"@gtkx/native\";\nimport { blockMatchedSignalHandlers } from \"./signal.js\";\n\n/**\n * Minimal structural interface of a GTK4/GIO application needed to register, run,\n * and shut it down, plus the signals its lifecycle helpers connect to.\n */\nexport type ApplicationLike = {\n getIsRegistered(): boolean;\n register(cancellable: null): boolean;\n activate(): void;\n quit(): void;\n run(argv: string[]): number;\n getWindows?(): object[];\n removeWindow?(window: object): void;\n on(signal: \"activate\" | \"shutdown\", handler: () => void): unknown;\n};\n\nconst shutdownCallbacks: (() => void)[] = [];\nlet hasQuit = false;\n\n/**\n * Registers a callback to run once when the process quits, before the native\n * runtime is torn down.\n *\n * @param callback Invoked during shutdown.\n */\nexport const onExit = (callback: () => void): void => {\n shutdownCallbacks.push(callback);\n};\n\n/**\n * Runs every registered exit callback and shuts down the native runtime. Safe to\n * call more than once; only the first call takes effect.\n */\nexport const quit = (): void => {\n if (hasQuit) return;\n hasQuit = true;\n\n for (const callback of shutdownCallbacks) callback();\n\n nativeQuit();\n};\n\nprocess.on(\"exit\", quit);\n\n/**\n * Registers the application if needed and activates it, keeping the runtime alive\n * while it is active and releasing it on shutdown.\n *\n * @param application The application to register and activate.\n */\nexport const runApplication = (application: ApplicationLike): void => {\n application.on(\"activate\", () => keepAlive(true));\n application.on(\"shutdown\", () => keepAlive(false));\n\n if (!application.getIsRegistered()) application.register(null);\n application.activate();\n};\n\n/**\n * Closes all of the application's windows and drives its main loop until it quits,\n * so pending shutdown work can complete before the process exits.\n *\n * @param application The application to shut down.\n */\nexport const quitApplication = (application: ApplicationLike): void => {\n if (!application.getIsRegistered()) return;\n for (const window of application.getWindows?.() ?? []) application.removeWindow?.(window);\n application.on(\"shutdown\", () => application.quit());\n blockMatchedSignalHandlers(application, \"activate\");\n application.run([]);\n};\n"]}
1
+ {"version":3,"file":"lifecycle.js","sourceRoot":"","sources":["../src/lifecycle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,IAAI,IAAI,UAAU,EAAE,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AAiBzD,MAAM,iBAAiB,GAAmB,EAAE,CAAC;AAC7C;;;GAGG;AACH,MAAM,IAAI,GAAe,UAAU,EAAE,CAAC;AAEtC,SAAS,UAAU;IACf,IAAI,OAAO,GAAG,KAAK,CAAC;IAEpB,OAAO,GAAG,EAAE;QACR,IAAI,OAAO,EAAE,CAAC;YACV,OAAO;QACX,CAAC;QAED,OAAO,GAAG,IAAI,CAAC;QAEf,KAAK,MAAM,QAAQ,IAAI,iBAAiB,EAAE,CAAC;YACvC,QAAQ,EAAE,CAAC;QACf,CAAC;QAED,UAAU,EAAE,CAAC;IACjB,CAAC,CAAC;AACN,CAAC;AAED;;;;;GAKG;AACH,MAAM,MAAM,GAAG,CAAC,QAAoB,EAAQ,EAAE;IAC1C,iBAAiB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AACrC,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,cAAc,GAAG,CAAC,WAA4B,EAAQ,EAAE;IAC1D,WAAW,CAAC,EAAE,CAAC,UAAU,EAAE,GAAG,EAAE;QAC5B,SAAS,CAAC,IAAI,CAAC,CAAC;IACpB,CAAC,CAAC,CAAC;IAEH,WAAW,CAAC,EAAE,CAAC,UAAU,EAAE,GAAG,EAAE;QAC5B,SAAS,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,WAAW,CAAC,eAAe,EAAE,EAAE,CAAC;QACjC,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;IAED,WAAW,CAAC,QAAQ,EAAE,CAAC;AAC3B,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,eAAe,GAAG,CAAC,WAA4B,EAAQ,EAAE;IAC3D,IAAI,CAAC,WAAW,CAAC,eAAe,EAAE,EAAE,CAAC;QACjC,OAAO;IACX,CAAC;IAED,MAAM,OAAO,GAAG,WAAW,CAAC,UAAU,EAAE,EAAE,IAAI,EAAE,CAAC;IAEjD,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC3B,WAAW,CAAC,YAAY,EAAE,CAAC,MAAM,CAAC,CAAC;IACvC,CAAC;IAED,WAAW,CAAC,EAAE,CAAC,UAAU,EAAE,GAAG,EAAE;QAC5B,WAAW,CAAC,IAAI,EAAE,CAAC;IACvB,CAAC,CAAC,CAAC;IAEH,0BAA0B,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;IACpD,WAAW,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AACxB,CAAC,CAAC;AAEF,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,EAAE,eAAe,EAAwB,CAAC","sourcesContent":["import { keepAlive, quit as nativeQuit } from \"@gtkx/native\";\nimport { blockMatchedSignalHandlers } from \"./signal.js\";\n\n/**\n * Minimal structural interface of a GTK4/GIO application needed to register, run,\n * and shut it down, plus the signals its lifecycle helpers connect to.\n */\ntype ApplicationLike = {\n getIsRegistered(): boolean;\n register(cancellable: null): boolean;\n activate(): void;\n quit(): void;\n run(argv: string[]): number;\n getWindows?(): object[];\n removeWindow?(window: object): void;\n on(signal: \"activate\" | \"shutdown\", handler: () => void): unknown;\n};\n\nconst shutdownCallbacks: (() => void)[] = [];\n/**\n * Runs every registered exit callback and shuts down the native runtime. Safe to\n * call more than once; only the first call takes effect.\n */\nconst quit: () => void = createQuit();\n\nfunction createQuit(): () => void {\n let hasQuit = false;\n\n return () => {\n if (hasQuit) {\n return;\n }\n\n hasQuit = true;\n\n for (const callback of shutdownCallbacks) {\n callback();\n }\n\n nativeQuit();\n };\n}\n\n/**\n * Registers a callback to run once when the process quits, before the native\n * runtime is torn down.\n *\n * @param callback Invoked during shutdown.\n */\nconst onExit = (callback: () => void): void => {\n shutdownCallbacks.push(callback);\n};\n\n/**\n * Registers the application if needed and activates it, keeping the runtime alive\n * while it is active and releasing it on shutdown.\n *\n * @param application The application to register and activate.\n */\nconst runApplication = (application: ApplicationLike): void => {\n application.on(\"activate\", () => {\n keepAlive(true);\n });\n\n application.on(\"shutdown\", () => {\n keepAlive(false);\n });\n\n if (!application.getIsRegistered()) {\n application.register(null);\n }\n\n application.activate();\n};\n\n/**\n * Closes all of the application's windows and drives its main loop until it quits,\n * so pending shutdown work can complete before the process exits.\n *\n * @param application The application to shut down.\n */\nconst quitApplication = (application: ApplicationLike): void => {\n if (!application.getIsRegistered()) {\n return;\n }\n\n const windows = application.getWindows?.() ?? [];\n\n for (const window of windows) {\n application.removeWindow?.(window);\n }\n\n application.on(\"shutdown\", () => {\n application.quit();\n });\n\n blockMatchedSignalHandlers(application, \"activate\");\n application.run([]);\n};\n\nexport { onExit, quit, runApplication, quitApplication, type ApplicationLike };\n"]}
@@ -1,6 +1,6 @@
1
- import type { SignalHandler } from "./signal.js";
1
+ import { type SignalHandler } from "./signal.js";
2
2
  type SignalConnectable = {
3
- connect(signal: string, handler: SignalHandler, after?: boolean): number;
3
+ connect(signal: string, handler: SignalHandler, isAfter?: boolean): number;
4
4
  disconnect(handlerId: number): void;
5
5
  };
6
6
  /**
@@ -10,9 +10,9 @@ type SignalConnectable = {
10
10
  * @param instance The object emitting the signal.
11
11
  * @param signal The signal name to connect to.
12
12
  * @param handler The callback invoked on each emission.
13
- * @param after When true, run the handler after the default handler.
13
+ * @param isAfter When true, run the handler after the default handler.
14
14
  */
15
- export declare function onSignal(instance: SignalConnectable, signal: string, handler: SignalHandler, after?: boolean): void;
15
+ declare function onSignal(instance: SignalConnectable, signal: string, handler: SignalHandler, isAfter?: boolean): void;
16
16
  /**
17
17
  * Connects a handler that runs at most once, disconnecting itself after the first
18
18
  * emission.
@@ -20,9 +20,9 @@ export declare function onSignal(instance: SignalConnectable, signal: string, ha
20
20
  * @param instance The object emitting the signal.
21
21
  * @param signal The signal name to connect to.
22
22
  * @param handler The callback invoked on the first emission.
23
- * @param after When true, run the handler after the default handler.
23
+ * @param isAfter When true, run the handler after the default handler.
24
24
  */
25
- export declare function onceSignal(instance: SignalConnectable, signal: string, handler: SignalHandler, after?: boolean): void;
25
+ declare function onceSignal(instance: SignalConnectable, signal: string, handler: SignalHandler, isAfter?: boolean): void;
26
26
  /**
27
27
  * Disconnects a handler previously connected with {@link onSignal} or
28
28
  * {@link onceSignal}. Does nothing if the handler is not currently connected.
@@ -31,6 +31,6 @@ export declare function onceSignal(instance: SignalConnectable, signal: string,
31
31
  * @param signal The signal name the handler was connected to.
32
32
  * @param handler The handler to disconnect.
33
33
  */
34
- export declare function offSignal(instance: SignalConnectable, signal: string, handler: SignalHandler): void;
35
- export {};
34
+ declare function offSignal(instance: SignalConnectable, signal: string, handler: SignalHandler): void;
35
+ export { onSignal, onceSignal, offSignal };
36
36
  //# sourceMappingURL=listeners.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"listeners.d.ts","sourceRoot":"","sources":["../src/listeners.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEj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M,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,IAAI,CAahH;AAED;;;;;;;GAOG;AACH,iBAAS,SAAS,CAAC,QAAQ,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,GAAG,IAAI,CAc5F;AAED,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC"}
package/dist/listeners.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { isSignalHandlerConnected } from "./signal.js";
1
2
  const listenerTable = new WeakMap();
2
3
  const findListenerHandlerId = (instance, signal, handler) => listenerTable.get(instance)?.get(signal)?.get(handler);
3
4
  const trackListener = (instance, signal, handler, handlerId) => {
@@ -13,12 +14,20 @@ const trackListener = (instance, signal, handler, handlerId) => {
13
14
  }
14
15
  byHandler.set(handler, handlerId);
15
16
  };
16
- const untrackListener = (instance, signal, handler) => {
17
+ const untrackHandlerId = (instance, signal, handlerId) => {
17
18
  const bySignal = listenerTable.get(instance);
18
19
  const byHandler = bySignal?.get(signal);
19
- byHandler?.delete(handler);
20
- if (byHandler?.size === 0)
20
+ if (byHandler === undefined) {
21
+ return;
22
+ }
23
+ for (const [handler, id] of byHandler) {
24
+ if (id === handlerId) {
25
+ byHandler.delete(handler);
26
+ }
27
+ }
28
+ if (byHandler.size === 0) {
21
29
  bySignal?.delete(signal);
30
+ }
22
31
  };
23
32
  /**
24
33
  * Connects a handler to a signal and tracks it so it can later be removed with
@@ -27,10 +36,10 @@ const untrackListener = (instance, signal, handler) => {
27
36
  * @param instance The object emitting the signal.
28
37
  * @param signal The signal name to connect to.
29
38
  * @param handler The callback invoked on each emission.
30
- * @param after When true, run the handler after the default handler.
39
+ * @param isAfter When true, run the handler after the default handler.
31
40
  */
32
- export function onSignal(instance, signal, handler, after) {
33
- const handlerId = instance.connect(signal, handler, after);
41
+ function onSignal(instance, signal, handler, isAfter) {
42
+ const handlerId = instance.connect(signal, handler, isAfter);
34
43
  trackListener(instance, signal, handler, handlerId);
35
44
  }
36
45
  /**
@@ -40,17 +49,16 @@ export function onSignal(instance, signal, handler, after) {
40
49
  * @param instance The object emitting the signal.
41
50
  * @param signal The signal name to connect to.
42
51
  * @param handler The callback invoked on the first emission.
43
- * @param after When true, run the handler after the default handler.
52
+ * @param isAfter When true, run the handler after the default handler.
44
53
  */
45
- export function onceSignal(instance, signal, handler, after) {
54
+ function onceSignal(instance, signal, handler, isAfter) {
46
55
  let handlerId = 0;
47
56
  const wrapped = (...args) => {
48
- untrackListener(instance, signal, wrapped);
49
- untrackListener(instance, signal, handler);
57
+ untrackHandlerId(instance, signal, handlerId);
50
58
  instance.disconnect(handlerId);
51
59
  return handler(...args);
52
60
  };
53
- handlerId = instance.connect(signal, wrapped, after);
61
+ handlerId = instance.connect(signal, wrapped, isAfter);
54
62
  trackListener(instance, signal, wrapped, handlerId);
55
63
  trackListener(instance, signal, handler, handlerId);
56
64
  }
@@ -62,11 +70,16 @@ export function onceSignal(instance, signal, handler, after) {
62
70
  * @param signal The signal name the handler was connected to.
63
71
  * @param handler The handler to disconnect.
64
72
  */
65
- export function offSignal(instance, signal, handler) {
73
+ function offSignal(instance, signal, handler) {
66
74
  const handlerId = findListenerHandlerId(instance, signal, handler);
67
- if (handlerId !== undefined) {
68
- instance.disconnect(handlerId);
69
- untrackListener(instance, signal, handler);
75
+ if (handlerId === undefined) {
76
+ return;
77
+ }
78
+ untrackHandlerId(instance, signal, handlerId);
79
+ if (!isSignalHandlerConnected(instance, handlerId)) {
80
+ return;
70
81
  }
82
+ instance.disconnect(handlerId);
71
83
  }
84
+ export { onSignal, onceSignal, offSignal };
72
85
  //# sourceMappingURL=listeners.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"listeners.js","sourceRoot":"","sources":["../src/listeners.ts"],"names":[],"mappings":"AAOA,MAAM,aAAa,GAAG,IAAI,OAAO,EAAmD,CAAC;AAErF,MAAM,qBAAqB,GAAG,CAAC,QAAg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nectable = {\n connect(signal: string, handler: SignalHandler, after?: boolean): number;\n disconnect(handlerId: number): void;\n};\n\nconst listenerTable = new WeakMap<object, Map<string, Map<SignalHandler, number>>>();\n\nconst findListenerHandlerId = (instance: object, signal: string, handler: SignalHandler): number | undefined =>\n listenerTable.get(instance)?.get(signal)?.get(handler);\n\nconst trackListener = (instance: object, signal: string, handler: SignalHandler, handlerId: number): void => {\n let bySignal = listenerTable.get(instance);\n if (!bySignal) {\n bySignal = new Map();\n listenerTable.set(instance, bySignal);\n }\n let byHandler = bySignal.get(signal);\n if (!byHandler) {\n byHandler = new Map();\n bySignal.set(signal, byHandler);\n }\n byHandler.set(handler, handlerId);\n};\n\nconst untrackListener = (instance: object, signal: string, handler: SignalHandler): void => {\n const bySignal = listenerTable.get(instance);\n const byHandler = bySignal?.get(signal);\n byHandler?.delete(handler);\n if (byHandler?.size === 0) bySignal?.delete(signal);\n};\n\n/**\n * Connects a handler to a signal and tracks it so it can later be removed with\n * {@link offSignal}.\n *\n * @param instance The object emitting the signal.\n * @param signal The signal name to connect to.\n * @param handler The callback invoked on each emission.\n * @param after When true, run the handler after the default handler.\n */\nexport function onSignal(instance: SignalConnectable, signal: string, handler: SignalHandler, after?: boolean): void {\n const handlerId = instance.connect(signal, handler, after);\n trackListener(instance, signal, handler, handlerId);\n}\n\n/**\n * Connects a handler that runs at most once, disconnecting itself after the first\n * emission.\n *\n * @param instance The object emitting the signal.\n * @param signal The signal name to connect to.\n * @param handler The callback invoked on the first emission.\n * @param after When true, run the handler after the default handler.\n */\nexport function onceSignal(instance: SignalConnectable, signal: string, handler: SignalHandler, after?: boolean): void {\n let handlerId = 0;\n const wrapped: SignalHandler = (...args) => {\n untrackListener(instance, signal, wrapped);\n untrackListener(instance, signal, handler);\n instance.disconnect(handlerId);\n return handler(...args);\n };\n handlerId = instance.connect(signal, wrapped, after);\n trackListener(instance, signal, wrapped, handlerId);\n trackListener(instance, signal, handler, handlerId);\n}\n\n/**\n * Disconnects a handler previously connected with {@link onSignal} or\n * {@link onceSignal}. Does nothing if the handler is not currently connected.\n *\n * @param instance The object the handler was connected to.\n * @param signal The signal name the handler was connected to.\n * @param handler The handler to disconnect.\n */\nexport function offSignal(instance: SignalConnectable, signal: string, handler: SignalHandler): void {\n const handlerId = findListenerHandlerId(instance, signal, handler);\n if (handlerId !== undefined) {\n instance.disconnect(handlerId);\n untrackListener(instance, signal, handler);\n }\n}\n"]}
1
+ {"version":3,"file":"listeners.js","sourceRoot":"","sources":["../src/listeners.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAsB,MAAM,aAAa,CAAC;AAO3E,MAAM,aAAa,GAA6D,IAAI,OAAO,EAAE,CAAC;AAE9F,MAAM,qBAAqB,GAAG,CAAC,QAAgB,EAAE,MAAc,EAAE,OAAsB,EAAsB,EAAE,CAC3G,aAAa,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;AAE3D,MAAM,aAAa,GAAG,CAAC,QAAgB,EAAE,MAAc,EAAE,OAAsB,EAAE,SAAiB,EAAQ,EAAE;IACxG,IAAI,QAAQ,GAAG,aAAa,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAE3C,IAAI,CAAC,QAAQ,EAAE,CAAC;QACZ,QAAQ,GAAG,IAAI,GAAG,EAAE,CAAC;QACrB,aAAa,CAAC,GAAG,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAC1C,CAAC;IAED,IAAI,SAAS,GAAG,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAErC,IAAI,CAAC,SAAS,EAAE,CAAC;QACb,SAAS,GAAG,IAAI,GAAG,EAAE,CAAC;QACtB,QAAQ,CAAC,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IACpC,CAAC;IAED,SAAS,CAAC,GAAG,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;AACtC,CAAC,CAAC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AEF,SAAS,GAAG,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IACvD,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;IACpD,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;AACxD,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,SAAS,CAAC,QAA2B,EAAE,MAAc,EAAE,OAAsB;IAClF,MAAM,SAAS,GAAG,qBAAqB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAEnE,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;QAC1B,OAAO;IACX,CAAC;IAED,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;IAE9C,IAAI,CAAC,wBAAwB,CAAC,QAAQ,EAAE,SAAS,CAAC,EAAE,CAAC;QACjD,OAAO;IACX,CAAC;IAED,QAAQ,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;AACnC,CAAC;AAED,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC","sourcesContent":["import { isSignalHandlerConnected, type SignalHandler } from \"./signal.js\";\n\ntype SignalConnectable = {\n connect(signal: string, handler: SignalHandler, isAfter?: boolean): number;\n disconnect(handlerId: number): void;\n};\n\nconst listenerTable: WeakMap<object, Map<string, Map<SignalHandler, number>>> = new WeakMap();\n\nconst findListenerHandlerId = (instance: object, signal: string, handler: SignalHandler): number | undefined =>\n listenerTable.get(instance)?.get(signal)?.get(handler);\n\nconst trackListener = (instance: object, signal: string, handler: SignalHandler, handlerId: number): void => {\n let bySignal = listenerTable.get(instance);\n\n if (!bySignal) {\n bySignal = new Map();\n listenerTable.set(instance, bySignal);\n }\n\n let byHandler = bySignal.get(signal);\n\n if (!byHandler) {\n byHandler = new Map();\n bySignal.set(signal, byHandler);\n }\n\n byHandler.set(handler, handlerId);\n};\n\nconst untrackHandlerId = (instance: object, signal: string, handlerId: number): void => {\n const bySignal = listenerTable.get(instance);\n const byHandler = bySignal?.get(signal);\n\n if (byHandler === undefined) {\n return;\n }\n\n for (const [handler, id] of byHandler) {\n if (id === handlerId) {\n byHandler.delete(handler);\n }\n }\n\n if (byHandler.size === 0) {\n bySignal?.delete(signal);\n }\n};\n\n/**\n * Connects a handler to a signal and tracks it so it can later be removed with\n * {@link offSignal}.\n *\n * @param instance The object emitting the signal.\n * @param signal The signal name to connect to.\n * @param handler The callback invoked on each emission.\n * @param isAfter When true, run the handler after the default handler.\n */\nfunction onSignal(instance: SignalConnectable, signal: string, handler: SignalHandler, isAfter?: boolean): void {\n const handlerId = instance.connect(signal, handler, isAfter);\n trackListener(instance, signal, handler, handlerId);\n}\n\n/**\n * Connects a handler that runs at most once, disconnecting itself after the first\n * emission.\n *\n * @param instance The object emitting the signal.\n * @param signal The signal name to connect to.\n * @param handler The callback invoked on the first emission.\n * @param isAfter When true, run the handler after the default handler.\n */\nfunction onceSignal(instance: SignalConnectable, signal: string, handler: SignalHandler, isAfter?: boolean): void {\n let handlerId = 0;\n\n const wrapped: SignalHandler = (...args) => {\n untrackHandlerId(instance, signal, handlerId);\n instance.disconnect(handlerId);\n\n return handler(...args);\n };\n\n handlerId = instance.connect(signal, wrapped, isAfter);\n trackListener(instance, signal, wrapped, handlerId);\n trackListener(instance, signal, handler, handlerId);\n}\n\n/**\n * Disconnects a handler previously connected with {@link onSignal} or\n * {@link onceSignal}. Does nothing if the handler is not currently connected.\n *\n * @param instance The object the handler was connected to.\n * @param signal The signal name the handler was connected to.\n * @param handler The handler to disconnect.\n */\nfunction offSignal(instance: SignalConnectable, signal: string, handler: SignalHandler): void {\n const handlerId = findListenerHandlerId(instance, signal, handler);\n\n if (handlerId === undefined) {\n return;\n }\n\n untrackHandlerId(instance, signal, handlerId);\n\n if (!isSignalHandlerConnected(instance, handlerId)) {\n return;\n }\n\n instance.disconnect(handlerId);\n}\n\nexport { onSignal, onceSignal, offSignal };\n"]}
package/dist/mixin.d.ts CHANGED
@@ -1,19 +1,13 @@
1
1
  import type { AnyClass } from "@gtkx/utils";
2
- export type MixinReceiver = {
3
- connect(signal: string, handler: (...args: unknown[]) => unknown, after?: boolean): number;
2
+ type MixinReceiver = {
3
+ connect(signal: string, handler: (...args: unknown[]) => unknown, isAfter?: boolean): number;
4
4
  emit(signal: string, ...args: unknown[]): unknown;
5
5
  };
6
6
  /**
7
7
  * A factory that, given a base class, returns a subclass adding extra members to
8
8
  * be merged onto a target prototype.
9
9
  */
10
- export type Mixin = (base: AnyClass<MixinReceiver>) => AnyClass;
11
- /**
12
- * Copies each mixin's prototype members onto the target class prototype, skipping
13
- * any member already defined anywhere in the target's class chain.
14
- *
15
- * @param target The class whose prototype receives the mixin members.
16
- * @param mixins The mixins to apply, in order.
17
- */
18
- export declare function installMixins(target: AnyClass, mixins: Mixin[]): void;
10
+ type Mixin = (base: AnyClass<MixinReceiver>) => AnyClass;
11
+ declare function installMixins(target: AnyClass, mixins: Mixin[]): void;
12
+ export { installMixins, type MixinReceiver, type Mixin };
19
13
  //# sourceMappingURL=mixin.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mixin.d.ts","sourceRoot":"","sources":["../src/mixin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5C,MAAM,MAAM,aAAa,GAAG;IACxB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IAC3F,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;CACrD,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,KAAK,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,aAAa,CAAC,KAAK,QAAQ,CAAC;AAWhE;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAkBrE"}
1
+ {"version":3,"file":"mixin.d.ts","sourceRoot":"","sources":["../src/mixin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5C,KAAK,aAAa,GAAG;IACjB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IAC7F,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;CACrD,CAAC;AAEF;;;GAGG;AACH,KAAK,KAAK,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,aAAa,CAAC,KAAK,QAAQ,CAAC;AA6CzD,iBAAS,aAAa,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAc9D;AAED,OAAO,EAAE,aAAa,EAAE,KAAK,aAAa,EAAE,KAAK,KAAK,EAAE,CAAC"}
package/dist/mixin.js CHANGED
@@ -1,12 +1,25 @@
1
- function definedInClassChain(prototype, key) {
1
+ function isDefinedInClassChain(prototype, key) {
2
2
  let current = prototype;
3
3
  while (current !== null && current !== Object.prototype) {
4
- if (Object.hasOwn(current, key))
4
+ if (Object.hasOwn(current, key)) {
5
5
  return true;
6
- current = Object.getPrototypeOf(current);
6
+ }
7
+ current = Reflect.getPrototypeOf(current);
7
8
  }
8
9
  return false;
9
10
  }
11
+ function copyLayerMember(target, layer, key) {
12
+ if (key === "constructor") {
13
+ return;
14
+ }
15
+ if (isDefinedInClassChain(target.prototype, key)) {
16
+ return;
17
+ }
18
+ const descriptor = Object.getOwnPropertyDescriptor(layer, key);
19
+ if (descriptor !== undefined) {
20
+ Object.defineProperty(target.prototype, key, descriptor);
21
+ }
22
+ }
10
23
  /**
11
24
  * Copies each mixin's prototype members onto the target class prototype, skipping
12
25
  * any member already defined anywhere in the target's class chain.
@@ -14,7 +27,12 @@ function definedInClassChain(prototype, key) {
14
27
  * @param target The class whose prototype receives the mixin members.
15
28
  * @param mixins The mixins to apply, in order.
16
29
  */
17
- export function installMixins(target, mixins) {
30
+ function copyLayerMembers(target, layer) {
31
+ for (const key of Object.getOwnPropertyNames(layer)) {
32
+ copyLayerMember(target, layer, key);
33
+ }
34
+ }
35
+ function installMixins(target, mixins) {
18
36
  const empty = class {
19
37
  connect() {
20
38
  return 0;
@@ -24,16 +42,8 @@ export function installMixins(target, mixins) {
24
42
  }
25
43
  };
26
44
  for (const mixin of mixins) {
27
- const layer = mixin(empty).prototype;
28
- for (const key of Object.getOwnPropertyNames(layer)) {
29
- if (key === "constructor")
30
- continue;
31
- if (definedInClassChain(target.prototype, key))
32
- continue;
33
- const descriptor = Object.getOwnPropertyDescriptor(layer, key);
34
- if (descriptor !== undefined)
35
- Object.defineProperty(target.prototype, key, descriptor);
36
- }
45
+ copyLayerMembers(target, mixin(empty).prototype);
37
46
  }
38
47
  }
48
+ export { installMixins };
39
49
  //# sourceMappingURL=mixin.js.map
package/dist/mixin.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"mixin.js","sourceRoot":"","sources":["../src/mixin.ts"],"names":[],"mappings":"AAaA,SAAS,mBAAmB,CAAC,SAAiB,EAAE,GAAW;IACvD,IAAI,OAAO,GAAkB,SAAS,CAAC;IACvC,OAAO,OAAO,KAAK,IAAI,IAAI,OAAO,KAAK,MAAM,CAAC,SAAS,EAAE,CAAC;QACtD,IAAI,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,GAAG,CAAC;YAAE,OAAO,IAAI,CAAC;QAC7C,OAAO,GAAG,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;IAC7C,CAAC;IACD,OAAO,KAAK,CAAC;AACjB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAAC,MAAgB,EAAE,MAAe;IAC3D,MAAM,KAAK,GAA4B;QACnC,OAAO;YACH,OAAO,CAAC,CAAC;QACb,CAAC;QACD,IAAI;YACA,OAAO,SAAS,CAAC;QACrB,CAAC;KACJ,CAAC;IACF,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QACzB,MAAM,KAAK,GAAW,KAAK,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC;QAC7C,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,mBAAmB,CAAC,KAAK,CAAC,EAAE,CAAC;YAClD,IAAI,GAAG,KAAK,aAAa;gBAAE,SAAS;YACpC,IAAI,mBAAmB,CAAC,MAAM,CAAC,SAAS,EAAE,GAAG,CAAC;gBAAE,SAAS;YACzD,MAAM,UAAU,GAAG,MAAM,CAAC,wBAAwB,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;YAC/D,IAAI,UAAU,KAAK,SAAS;gBAAE,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,SAAS,EAAE,GAAG,EAAE,UAAU,CAAC,CAAC;QAC3F,CAAC;IACL,CAAC;AACL,CAAC","sourcesContent":["import type { AnyClass } from \"@gtkx/utils\";\n\nexport type MixinReceiver = {\n connect(signal: string, handler: (...args: unknown[]) => unknown, after?: boolean): number;\n emit(signal: string, ...args: unknown[]): unknown;\n};\n\n/**\n * A factory that, given a base class, returns a subclass adding extra members to\n * be merged onto a target prototype.\n */\nexport type Mixin = (base: AnyClass<MixinReceiver>) => AnyClass;\n\nfunction definedInClassChain(prototype: object, key: string): boolean {\n let current: object | null = prototype;\n while (current !== null && current !== Object.prototype) {\n if (Object.hasOwn(current, key)) return true;\n current = Object.getPrototypeOf(current);\n }\n return false;\n}\n\n/**\n * Copies each mixin's prototype members onto the target class prototype, skipping\n * any member already defined anywhere in the target's class chain.\n *\n * @param target The class whose prototype receives the mixin members.\n * @param mixins The mixins to apply, in order.\n */\nexport function installMixins(target: AnyClass, mixins: Mixin[]): void {\n const empty: AnyClass<MixinReceiver> = class {\n connect(): number {\n return 0;\n }\n emit(): unknown {\n return undefined;\n }\n };\n for (const mixin of mixins) {\n const layer: object = mixin(empty).prototype;\n for (const key of Object.getOwnPropertyNames(layer)) {\n if (key === \"constructor\") continue;\n if (definedInClassChain(target.prototype, key)) continue;\n const descriptor = Object.getOwnPropertyDescriptor(layer, key);\n if (descriptor !== undefined) Object.defineProperty(target.prototype, key, descriptor);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"mixin.js","sourceRoot":"","sources":["../src/mixin.ts"],"names":[],"mappings":"AAaA,SAAS,qBAAqB,CAAC,SAAiB,EAAE,GAAW;IACzD,IAAI,OAAO,GAAkB,SAAS,CAAC;IAEvC,OAAO,OAAO,KAAK,IAAI,IAAI,OAAO,KAAK,MAAM,CAAC,SAAS,EAAE,CAAC;QACtD,IAAI,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,GAAG,CAAC,EAAE,CAAC;YAC9B,OAAO,IAAI,CAAC;QAChB,CAAC;QAED,OAAO,GAAG,OAAO,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;IAC9C,CAAC;IAED,OAAO,KAAK,CAAC;AACjB,CAAC;AAED,SAAS,eAAe,CAAC,MAAgB,EAAE,KAAa,EAAE,GAAW;IACjE,IAAI,GAAG,KAAK,aAAa,EAAE,CAAC;QACxB,OAAO;IACX,CAAC;IAED,IAAI,qBAAqB,CAAC,MAAM,CAAC,SAAS,EAAE,GAAG,CAAC,EAAE,CAAC;QAC/C,OAAO;IACX,CAAC;IAED,MAAM,UAAU,GAAG,MAAM,CAAC,wBAAwB,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAE/D,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;QAC3B,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,SAAS,EAAE,GAAG,EAAE,UAAU,CAAC,CAAC;IAC7D,CAAC;AACL,CAAC;AAED;;;;;;GAMG;AACH,SAAS,gBAAgB,CAAC,MAAgB,EAAE,KAAa;IACrD,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,mBAAmB,CAAC,KAAK,CAAC,EAAE,CAAC;QAClD,eAAe,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;IACxC,CAAC;AACL,CAAC;AAED,SAAS,aAAa,CAAC,MAAgB,EAAE,MAAe;IACpD,MAAM,KAAK,GAA4B;QACnC,OAAO;YACH,OAAO,CAAC,CAAC;QACb,CAAC;QAED,IAAI;YACA,OAAO,SAAS,CAAC;QACrB,CAAC;KACJ,CAAC;IAEF,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QACzB,gBAAgB,CAAC,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,CAAC;IACrD,CAAC;AACL,CAAC;AAED,OAAO,EAAE,aAAa,EAAkC,CAAC","sourcesContent":["import type { AnyClass } from \"@gtkx/utils\";\n\ntype MixinReceiver = {\n connect(signal: string, handler: (...args: unknown[]) => unknown, isAfter?: boolean): number;\n emit(signal: string, ...args: unknown[]): unknown;\n};\n\n/**\n * A factory that, given a base class, returns a subclass adding extra members to\n * be merged onto a target prototype.\n */\ntype Mixin = (base: AnyClass<MixinReceiver>) => AnyClass;\n\nfunction isDefinedInClassChain(prototype: object, key: string): boolean {\n let current: object | null = prototype;\n\n while (current !== null && current !== Object.prototype) {\n if (Object.hasOwn(current, key)) {\n return true;\n }\n\n current = Reflect.getPrototypeOf(current);\n }\n\n return false;\n}\n\nfunction copyLayerMember(target: AnyClass, layer: object, key: string): void {\n if (key === \"constructor\") {\n return;\n }\n\n if (isDefinedInClassChain(target.prototype, key)) {\n return;\n }\n\n const descriptor = Object.getOwnPropertyDescriptor(layer, key);\n\n if (descriptor !== undefined) {\n Object.defineProperty(target.prototype, key, descriptor);\n }\n}\n\n/**\n * Copies each mixin's prototype members onto the target class prototype, skipping\n * any member already defined anywhere in the target's class chain.\n *\n * @param target The class whose prototype receives the mixin members.\n * @param mixins The mixins to apply, in order.\n */\nfunction copyLayerMembers(target: AnyClass, layer: object): void {\n for (const key of Object.getOwnPropertyNames(layer)) {\n copyLayerMember(target, layer, key);\n }\n}\n\nfunction installMixins(target: AnyClass, mixins: Mixin[]): void {\n const empty: AnyClass<MixinReceiver> = class {\n connect(): number {\n return 0;\n }\n\n emit(): unknown {\n return undefined;\n }\n };\n\n for (const mixin of mixins) {\n copyLayerMembers(target, mixin(empty).prototype);\n }\n}\n\nexport { installMixins, type MixinReceiver, type Mixin };\n"]}
@@ -7,6 +7,7 @@ import type { Descriptor } from "@gtkx/native";
7
7
  * @param descriptor Describes the native type of the value.
8
8
  * @param value The raw native value to convert.
9
9
  */
10
- export declare function fromNative(descriptor: Descriptor, value: unknown): unknown;
11
- export declare function toNative(descriptor: Descriptor, value: unknown): unknown;
10
+ declare function fromNative(descriptor: Descriptor, value: unknown): unknown;
11
+ declare function toNative(descriptor: Descriptor, value: unknown): unknown;
12
+ export { fromNative, toNative };
12
13
  //# sourceMappingURL=native-value.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"native-value.d.ts","sourceRoot":"","sources":["../src/native-value.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAA0B,MAAM,cAAc,CAAC;AAUvE;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAiC1E;AAOD,wBAAgB,QAAQ,CAAC,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAmBxE"}
1
+ {"version":3,"file":"native-value.d.ts","sourceRoot":"","sources":["../src/native-value.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAA0B,MAAM,cAAc,CAAC;AA+DvE;;;;;;;GAOG;AACH,iBAAS,UAAU,CAAC,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAyBnE;AAiBD,iBAAS,QAAQ,CAAC,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAmBjE;AAED,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC"}