@studiometa/js-toolkit 2.2.2 → 2.2.3

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 (45) hide show
  1. package/Base/index.cjs +3 -4
  2. package/Base/index.js +1 -2
  3. package/Base/managers/ServicesManager.cjs +4 -5
  4. package/Base/managers/ServicesManager.js +4 -5
  5. package/Base/utils.cjs +1 -5
  6. package/Base/utils.d.ts +0 -8
  7. package/Base/utils.js +1 -5
  8. package/package.json +1 -1
  9. package/services/drag.cjs +126 -148
  10. package/services/drag.d.ts +10 -10
  11. package/services/drag.js +125 -148
  12. package/services/index.cjs +3 -1
  13. package/services/index.d.ts +1 -0
  14. package/services/index.js +3 -1
  15. package/services/key.cjs +48 -63
  16. package/services/key.d.ts +0 -8
  17. package/services/key.js +47 -63
  18. package/services/load.cjs +24 -40
  19. package/services/load.d.ts +0 -8
  20. package/services/load.js +23 -37
  21. package/services/pointer.cjs +73 -103
  22. package/services/pointer.d.ts +1 -9
  23. package/services/pointer.js +72 -100
  24. package/services/raf.cjs +36 -53
  25. package/services/raf.d.ts +0 -8
  26. package/services/raf.js +36 -54
  27. package/services/resize.cjs +59 -68
  28. package/services/resize.d.ts +0 -7
  29. package/services/resize.js +58 -68
  30. package/services/scroll.cjs +49 -71
  31. package/services/scroll.js +48 -71
  32. package/services/service.cjs +68 -0
  33. package/services/service.d.ts +18 -0
  34. package/services/service.js +46 -0
  35. package/utils/css/animate.cjs +3 -7
  36. package/utils/css/animate.js +2 -6
  37. package/utils/index.cjs +1 -0
  38. package/utils/index.d.ts +1 -0
  39. package/utils/index.js +1 -0
  40. package/utils/noop.cjs +31 -0
  41. package/utils/noop.d.ts +12 -0
  42. package/utils/noop.js +9 -0
  43. package/services/Service.cjs +0 -76
  44. package/services/Service.d.ts +0 -76
  45. package/services/Service.js +0 -55
@@ -4,7 +4,6 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __getProtoOf = Object.getPrototypeOf;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
7
  var __export = (target, all) => {
9
8
  for (var name in all)
10
9
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -19,10 +18,6 @@ var __copyProps = (to, from, except, desc) => {
19
18
  };
20
19
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
21
20
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
22
- var __publicField = (obj, key, value) => {
23
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
24
- return value;
25
- };
26
21
 
27
22
  // packages/js-toolkit/services/scroll.js
28
23
  var scroll_exports = {};
@@ -30,12 +25,41 @@ __export(scroll_exports, {
30
25
  default: () => useScroll
31
26
  });
32
27
  module.exports = __toCommonJS(scroll_exports);
33
- var import_Service = __toESM(require("./Service.cjs"), 1);
28
+ var import_service = require("./service.cjs");
34
29
  var import_debounce = __toESM(require("../utils/debounce.cjs"), 1);
35
- var Scroll = class extends import_Service.default {
36
- constructor() {
37
- super(...arguments);
38
- __publicField(this, "props", {
30
+ function createScrollService() {
31
+ function updateProps() {
32
+ const yLast = props.y;
33
+ const xLast = props.x;
34
+ if (window.pageYOffset !== props.y) {
35
+ props.y = window.pageYOffset;
36
+ }
37
+ if (window.pageXOffset !== props.x) {
38
+ props.x = window.pageXOffset;
39
+ }
40
+ props.changed.x = props.x !== xLast;
41
+ props.changed.y = props.y !== yLast;
42
+ props.last.x = xLast;
43
+ props.last.y = yLast;
44
+ props.delta.x = props.x - xLast;
45
+ props.delta.y = props.y - yLast;
46
+ props.max.x = (document.scrollingElement || document.body).scrollWidth - window.innerWidth;
47
+ props.max.y = (document.scrollingElement || document.body).scrollHeight - window.innerHeight;
48
+ props.progress.x = props.max.x === 0 ? 1 : props.x / props.max.x;
49
+ props.progress.y = props.max.y === 0 ? 1 : props.y / props.max.y;
50
+ props.direction.x = props.x > xLast ? "RIGHT" : props.x < xLast ? "LEFT" : "NONE";
51
+ props.direction.y = props.y > yLast ? "DOWN" : props.y < yLast ? "UP" : "NONE";
52
+ return props;
53
+ }
54
+ const onScrollDebounced = (0, import_debounce.default)(() => {
55
+ trigger(updateProps());
56
+ }, 100);
57
+ function onScroll() {
58
+ trigger(updateProps());
59
+ onScrollDebounced();
60
+ }
61
+ const { add, remove, has, props, trigger } = (0, import_service.useService)({
62
+ props: {
39
63
  x: window.pageXOffset,
40
64
  y: window.pageYOffset,
41
65
  changed: {
@@ -62,71 +86,25 @@ var Scroll = class extends import_Service.default {
62
86
  x: "NONE",
63
87
  y: "NONE"
64
88
  }
65
- });
66
- }
67
- init() {
68
- this.updateProps();
69
- document.addEventListener("scroll", this, { passive: true, capture: true });
70
- return this;
71
- }
72
- get debouncedHandler() {
73
- const debounced = (0, import_debounce.default)(() => {
74
- this.updateProps();
75
- this.trigger(this.props);
76
- }, 100);
77
- Object.defineProperty(this, "debouncedHandler", {
78
- value: debounced
79
- });
80
- return debounced;
81
- }
82
- handleEvent() {
83
- this.updateProps();
84
- this.trigger(this.props);
85
- this.debouncedHandler();
86
- }
87
- kill() {
88
- document.removeEventListener("scroll", this);
89
- return this;
90
- }
91
- updateProps() {
92
- const yLast = this.props.y;
93
- const xLast = this.props.x;
94
- if (window.pageYOffset !== this.props.y) {
95
- this.props.y = window.pageYOffset;
89
+ },
90
+ init() {
91
+ document.addEventListener("scroll", onScroll, { passive: true, capture: true });
92
+ },
93
+ kill() {
94
+ document.removeEventListener("scroll", onScroll);
96
95
  }
97
- if (window.pageXOffset !== this.props.x) {
98
- this.props.x = window.pageXOffset;
99
- }
100
- this.props.changed.x = this.props.x !== xLast;
101
- this.props.changed.y = this.props.y !== yLast;
102
- this.props.last.x = xLast;
103
- this.props.last.y = yLast;
104
- this.props.delta.x = this.props.x - xLast;
105
- this.props.delta.y = this.props.y - yLast;
106
- this.props.max.x = (document.scrollingElement || document.body).scrollWidth - window.innerWidth;
107
- this.props.max.y = (document.scrollingElement || document.body).scrollHeight - window.innerHeight;
108
- this.props.progress.x = this.props.max.x === 0 ? 1 : this.props.x / this.props.max.x;
109
- this.props.progress.y = this.props.max.y === 0 ? 1 : this.props.y / this.props.max.y;
110
- this.props.direction.x = this.props.x > xLast ? "RIGHT" : this.props.x < xLast ? "LEFT" : "NONE";
111
- this.props.direction.y = this.props.y > yLast ? "DOWN" : this.props.y < yLast ? "UP" : "NONE";
112
- return this.props;
113
- }
114
- };
115
- var instance;
96
+ });
97
+ return {
98
+ add,
99
+ remove,
100
+ has,
101
+ props: () => props
102
+ };
103
+ }
116
104
  var scroll;
117
105
  function useScroll() {
118
106
  if (!scroll) {
119
- if (!instance) {
120
- instance = new Scroll();
121
- }
122
- scroll = {
123
- add: instance.add.bind(instance),
124
- remove: instance.remove.bind(instance),
125
- has: instance.has.bind(instance),
126
- props() {
127
- return instance.props;
128
- }
129
- };
107
+ scroll = createScrollService();
130
108
  }
131
109
  return scroll;
132
110
  }
@@ -1,15 +1,38 @@
1
- var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
- var __publicField = (obj, key, value) => {
4
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
- return value;
6
- };
7
- import Service from "./Service.js";
1
+ import { useService } from "./service.js";
8
2
  import debounce from "../utils/debounce.js";
9
- class Scroll extends Service {
10
- constructor() {
11
- super(...arguments);
12
- __publicField(this, "props", {
3
+ function createScrollService() {
4
+ function updateProps() {
5
+ const yLast = props.y;
6
+ const xLast = props.x;
7
+ if (window.pageYOffset !== props.y) {
8
+ props.y = window.pageYOffset;
9
+ }
10
+ if (window.pageXOffset !== props.x) {
11
+ props.x = window.pageXOffset;
12
+ }
13
+ props.changed.x = props.x !== xLast;
14
+ props.changed.y = props.y !== yLast;
15
+ props.last.x = xLast;
16
+ props.last.y = yLast;
17
+ props.delta.x = props.x - xLast;
18
+ props.delta.y = props.y - yLast;
19
+ props.max.x = (document.scrollingElement || document.body).scrollWidth - window.innerWidth;
20
+ props.max.y = (document.scrollingElement || document.body).scrollHeight - window.innerHeight;
21
+ props.progress.x = props.max.x === 0 ? 1 : props.x / props.max.x;
22
+ props.progress.y = props.max.y === 0 ? 1 : props.y / props.max.y;
23
+ props.direction.x = props.x > xLast ? "RIGHT" : props.x < xLast ? "LEFT" : "NONE";
24
+ props.direction.y = props.y > yLast ? "DOWN" : props.y < yLast ? "UP" : "NONE";
25
+ return props;
26
+ }
27
+ const onScrollDebounced = debounce(() => {
28
+ trigger(updateProps());
29
+ }, 100);
30
+ function onScroll() {
31
+ trigger(updateProps());
32
+ onScrollDebounced();
33
+ }
34
+ const { add, remove, has, props, trigger } = useService({
35
+ props: {
13
36
  x: window.pageXOffset,
14
37
  y: window.pageYOffset,
15
38
  changed: {
@@ -36,71 +59,25 @@ class Scroll extends Service {
36
59
  x: "NONE",
37
60
  y: "NONE"
38
61
  }
39
- });
40
- }
41
- init() {
42
- this.updateProps();
43
- document.addEventListener("scroll", this, { passive: true, capture: true });
44
- return this;
45
- }
46
- get debouncedHandler() {
47
- const debounced = debounce(() => {
48
- this.updateProps();
49
- this.trigger(this.props);
50
- }, 100);
51
- Object.defineProperty(this, "debouncedHandler", {
52
- value: debounced
53
- });
54
- return debounced;
55
- }
56
- handleEvent() {
57
- this.updateProps();
58
- this.trigger(this.props);
59
- this.debouncedHandler();
60
- }
61
- kill() {
62
- document.removeEventListener("scroll", this);
63
- return this;
64
- }
65
- updateProps() {
66
- const yLast = this.props.y;
67
- const xLast = this.props.x;
68
- if (window.pageYOffset !== this.props.y) {
69
- this.props.y = window.pageYOffset;
70
- }
71
- if (window.pageXOffset !== this.props.x) {
72
- this.props.x = window.pageXOffset;
62
+ },
63
+ init() {
64
+ document.addEventListener("scroll", onScroll, { passive: true, capture: true });
65
+ },
66
+ kill() {
67
+ document.removeEventListener("scroll", onScroll);
73
68
  }
74
- this.props.changed.x = this.props.x !== xLast;
75
- this.props.changed.y = this.props.y !== yLast;
76
- this.props.last.x = xLast;
77
- this.props.last.y = yLast;
78
- this.props.delta.x = this.props.x - xLast;
79
- this.props.delta.y = this.props.y - yLast;
80
- this.props.max.x = (document.scrollingElement || document.body).scrollWidth - window.innerWidth;
81
- this.props.max.y = (document.scrollingElement || document.body).scrollHeight - window.innerHeight;
82
- this.props.progress.x = this.props.max.x === 0 ? 1 : this.props.x / this.props.max.x;
83
- this.props.progress.y = this.props.max.y === 0 ? 1 : this.props.y / this.props.max.y;
84
- this.props.direction.x = this.props.x > xLast ? "RIGHT" : this.props.x < xLast ? "LEFT" : "NONE";
85
- this.props.direction.y = this.props.y > yLast ? "DOWN" : this.props.y < yLast ? "UP" : "NONE";
86
- return this.props;
87
- }
69
+ });
70
+ return {
71
+ add,
72
+ remove,
73
+ has,
74
+ props: () => props
75
+ };
88
76
  }
89
- let instance;
90
77
  let scroll;
91
78
  function useScroll() {
92
79
  if (!scroll) {
93
- if (!instance) {
94
- instance = new Scroll();
95
- }
96
- scroll = {
97
- add: instance.add.bind(instance),
98
- remove: instance.remove.bind(instance),
99
- has: instance.has.bind(instance),
100
- props() {
101
- return instance.props;
102
- }
103
- };
80
+ scroll = createScrollService();
104
81
  }
105
82
  return scroll;
106
83
  }
@@ -0,0 +1,68 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // packages/js-toolkit/services/service.js
20
+ var service_exports = {};
21
+ __export(service_exports, {
22
+ useService: () => useService
23
+ });
24
+ module.exports = __toCommonJS(service_exports);
25
+ function useService(options) {
26
+ const callbacks = /* @__PURE__ */ new Map();
27
+ let isInit = false;
28
+ const { init, kill, props } = options;
29
+ function has(key) {
30
+ return callbacks.has(key);
31
+ }
32
+ function get(key) {
33
+ return callbacks.get(key);
34
+ }
35
+ function add(key, callback) {
36
+ if (has(key)) {
37
+ console.warn(`The key \`${key}\` has already been added.`);
38
+ return;
39
+ }
40
+ if (callbacks.size === 0 && !isInit) {
41
+ init();
42
+ isInit = true;
43
+ }
44
+ callbacks.set(key, callback);
45
+ }
46
+ function remove(key) {
47
+ callbacks.delete(key);
48
+ if (callbacks.size === 0 && isInit) {
49
+ kill();
50
+ isInit = false;
51
+ }
52
+ }
53
+ function trigger(p) {
54
+ callbacks.forEach(function forEachCallback(callback) {
55
+ callback(p);
56
+ });
57
+ }
58
+ return {
59
+ callbacks,
60
+ props,
61
+ add,
62
+ remove,
63
+ has,
64
+ get,
65
+ trigger
66
+ };
67
+ }
68
+ if (module.exports.default) module.exports = module.exports.default;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Use a service.
3
+ * @template {Record<string, any>} T
4
+ * @param {{ init: () => void, kill: () => void, props: T }} options
5
+ */
6
+ export function useService<T extends Record<string, any>>(options: {
7
+ init: () => void;
8
+ kill: () => void;
9
+ props: T;
10
+ }): {
11
+ callbacks: Map<string, (props: T) => any>;
12
+ props: T;
13
+ add: (key: string, callback: (props: T) => any) => void;
14
+ remove: (key: string) => void;
15
+ has: (key: string) => boolean;
16
+ get: (key: string) => (props: T) => any;
17
+ trigger: (p: T) => void;
18
+ };
@@ -0,0 +1,46 @@
1
+ function useService(options) {
2
+ const callbacks = /* @__PURE__ */ new Map();
3
+ let isInit = false;
4
+ const { init, kill, props } = options;
5
+ function has(key) {
6
+ return callbacks.has(key);
7
+ }
8
+ function get(key) {
9
+ return callbacks.get(key);
10
+ }
11
+ function add(key, callback) {
12
+ if (has(key)) {
13
+ console.warn(`The key \`${key}\` has already been added.`);
14
+ return;
15
+ }
16
+ if (callbacks.size === 0 && !isInit) {
17
+ init();
18
+ isInit = true;
19
+ }
20
+ callbacks.set(key, callback);
21
+ }
22
+ function remove(key) {
23
+ callbacks.delete(key);
24
+ if (callbacks.size === 0 && isInit) {
25
+ kill();
26
+ isInit = false;
27
+ }
28
+ }
29
+ function trigger(p) {
30
+ callbacks.forEach(function forEachCallback(callback) {
31
+ callback(p);
32
+ });
33
+ }
34
+ return {
35
+ callbacks,
36
+ props,
37
+ add,
38
+ remove,
39
+ has,
40
+ get,
41
+ trigger
42
+ };
43
+ }
44
+ export {
45
+ useService
46
+ };
@@ -31,10 +31,9 @@ var import_isDefined = __toESM(require("../isDefined.cjs"), 1);
31
31
  var import_transform = __toESM(require("./transform.cjs"), 1);
32
32
  var import_raf = __toESM(require("../../services/raf.cjs"), 1);
33
33
  var import_scheduler = require("../scheduler.cjs");
34
+ var import_noop = require("../noop.cjs");
34
35
  var id = 0;
35
36
  var running = /* @__PURE__ */ new WeakMap();
36
- var noop = () => {
37
- };
38
37
  var PROGRESS_PRECISION = 1e-4;
39
38
  var CSSUnitConverter = {
40
39
  "%": (value, getSizeRef) => value * getSizeRef() / 100,
@@ -52,12 +51,9 @@ function getAnimationStepValue(val, getSizeRef) {
52
51
  }
53
52
  return CSSUnitConverter[val[1]](val[0], getSizeRef);
54
53
  }
55
- function linear(value) {
56
- return value;
57
- }
58
54
  function normalizeEase(ease) {
59
55
  if (!(0, import_isDefined.default)(ease)) {
60
- return linear;
56
+ return import_noop.noopValue;
61
57
  }
62
58
  if (Array.isArray(ease)) {
63
59
  return (0, import_easing.cubicBezier)(...ease);
@@ -131,7 +127,7 @@ function animate(element, keyframes, options = {}) {
131
127
  let endTime = startTime + duration;
132
128
  const key = `animate-${id}`;
133
129
  id += 1;
134
- const { onProgress = noop, onFinish = noop } = options;
130
+ const { onProgress = import_noop.noop, onFinish = import_noop.noop } = options;
135
131
  let isRunning = false;
136
132
  const keyframesCount = keyframes.length - 1;
137
133
  const normalizedKeyframes = keyframes.map((keyframe, index) => {
@@ -4,10 +4,9 @@ import isDefined from "../isDefined.js";
4
4
  import transform, { TRANSFORM_PROPS } from "./transform.js";
5
5
  import useRaf from "../../services/raf.js";
6
6
  import { domScheduler as scheduler } from "../scheduler.js";
7
+ import { noop, noopValue } from "../noop.js";
7
8
  let id = 0;
8
9
  const running = /* @__PURE__ */ new WeakMap();
9
- const noop = () => {
10
- };
11
10
  const PROGRESS_PRECISION = 1e-4;
12
11
  const CSSUnitConverter = {
13
12
  "%": (value, getSizeRef) => value * getSizeRef() / 100,
@@ -25,12 +24,9 @@ function getAnimationStepValue(val, getSizeRef) {
25
24
  }
26
25
  return CSSUnitConverter[val[1]](val[0], getSizeRef);
27
26
  }
28
- function linear(value) {
29
- return value;
30
- }
31
27
  function normalizeEase(ease) {
32
28
  if (!isDefined(ease)) {
33
- return linear;
29
+ return noopValue;
34
30
  }
35
31
  if (Array.isArray(ease)) {
36
32
  return cubicBezier(...ease);
package/utils/index.cjs CHANGED
@@ -56,4 +56,5 @@ __reExport(utils_exports, require("./collide/index.cjs"), module.exports);
56
56
  __reExport(utils_exports, require("./math/index.cjs"), module.exports);
57
57
  __reExport(utils_exports, require("./string/index.cjs"), module.exports);
58
58
  __reExport(utils_exports, require("./scheduler.cjs"), module.exports);
59
+ __reExport(utils_exports, require("./noop.cjs"), module.exports);
59
60
  if (module.exports.default) module.exports = module.exports.default;
package/utils/index.d.ts CHANGED
@@ -14,4 +14,5 @@ export * from "./collide/index.js";
14
14
  export * from "./math/index.js";
15
15
  export * from "./string/index.js";
16
16
  export * from "./scheduler.js";
17
+ export * from "./noop.js";
17
18
  export { objectToURLSearchParams, push as historyPush, replace as historyReplace } from "./history.js";
package/utils/index.js CHANGED
@@ -19,6 +19,7 @@ export * from "./collide/index.js";
19
19
  export * from "./math/index.js";
20
20
  export * from "./string/index.js";
21
21
  export * from "./scheduler.js";
22
+ export * from "./noop.js";
22
23
  export {
23
24
  default2 as debounce,
24
25
  default3 as focusTrap,
package/utils/noop.cjs ADDED
@@ -0,0 +1,31 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // packages/js-toolkit/utils/noop.js
20
+ var noop_exports = {};
21
+ __export(noop_exports, {
22
+ noop: () => noop,
23
+ noopValue: () => noopValue
24
+ });
25
+ module.exports = __toCommonJS(noop_exports);
26
+ function noop() {
27
+ }
28
+ function noopValue(value) {
29
+ return value;
30
+ }
31
+ if (module.exports.default) module.exports = module.exports.default;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * No operation function.
3
+ * @returns {void}
4
+ */
5
+ export function noop(): void;
6
+ /**
7
+ * No operation function which return the given value unaltered.
8
+ * @template {any} T
9
+ * @param {T} value
10
+ * @returns {T}
11
+ */
12
+ export function noopValue<T extends unknown>(value: T): T;
package/utils/noop.js ADDED
@@ -0,0 +1,9 @@
1
+ function noop() {
2
+ }
3
+ function noopValue(value) {
4
+ return value;
5
+ }
6
+ export {
7
+ noop,
8
+ noopValue
9
+ };
@@ -1,76 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var __publicField = (obj, key, value) => {
20
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
21
- return value;
22
- };
23
-
24
- // packages/js-toolkit/services/Service.js
25
- var Service_exports = {};
26
- __export(Service_exports, {
27
- default: () => Service
28
- });
29
- module.exports = __toCommonJS(Service_exports);
30
- var Service = class {
31
- constructor() {
32
- __publicField(this, "callbacks", /* @__PURE__ */ new Map());
33
- __publicField(this, "isInit", false);
34
- __publicField(this, "props");
35
- }
36
- updateProps(...args) {
37
- this.props = args;
38
- throw new Error("The `updateProps` method must be implemented.");
39
- }
40
- init() {
41
- throw new Error("The `init` method must be implemented.");
42
- }
43
- kill() {
44
- throw new Error("The `kill` method must be implemented.");
45
- }
46
- add(key, callback) {
47
- if (this.has(key)) {
48
- throw new Error(`A callback with the key \`${key}\` has already been registered.`);
49
- }
50
- if (this.callbacks.size === 0 && !this.isInit) {
51
- this.init();
52
- this.isInit = true;
53
- }
54
- this.callbacks.set(key, callback);
55
- }
56
- has(key) {
57
- return this.callbacks.has(key);
58
- }
59
- get(key) {
60
- return this.callbacks.get(key);
61
- }
62
- remove(key) {
63
- this.callbacks.delete(key);
64
- if (this.callbacks.size === 0 && this.isInit) {
65
- this.kill();
66
- this.isInit = false;
67
- }
68
- }
69
- trigger(...args) {
70
- this.callbacks.forEach(function forEachCallback(callback) {
71
- callback(...args);
72
- });
73
- return this;
74
- }
75
- };
76
- if (module.exports.default) module.exports = module.exports.default;