@operato/utils 2.0.0-alpha.0 → 2.0.0-alpha.8

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 (63) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/src/adjust-list-param.d.ts +14 -0
  3. package/dist/src/adjust-list-param.js +8 -0
  4. package/dist/src/adjust-list-param.js.map +1 -1
  5. package/dist/src/async-lock.d.ts +13 -0
  6. package/dist/src/async-lock.js +13 -0
  7. package/dist/src/async-lock.js.map +1 -1
  8. package/dist/src/clipboard.d.ts +7 -0
  9. package/dist/src/clipboard.js +7 -0
  10. package/dist/src/clipboard.js.map +1 -1
  11. package/dist/src/closest-element.d.ts +7 -0
  12. package/dist/src/closest-element.js +7 -0
  13. package/dist/src/closest-element.js.map +1 -1
  14. package/dist/src/context-path.d.ts +15 -0
  15. package/dist/src/context-path.js +20 -0
  16. package/dist/src/context-path.js.map +1 -1
  17. package/dist/src/cookie.d.ts +18 -0
  18. package/dist/src/cookie.js +18 -0
  19. package/dist/src/cookie.js.map +1 -1
  20. package/dist/src/detect-overflow.d.ts +6 -0
  21. package/dist/src/detect-overflow.js +6 -0
  22. package/dist/src/detect-overflow.js.map +1 -1
  23. package/dist/src/format.d.ts +12 -0
  24. package/dist/src/format.js +12 -0
  25. package/dist/src/format.js.map +1 -1
  26. package/dist/src/logger.d.ts +15 -0
  27. package/dist/src/logger.js +15 -3
  28. package/dist/src/logger.js.map +1 -1
  29. package/dist/src/mixins/infinite-scrollable.d.ts +24 -0
  30. package/dist/src/mixins/infinite-scrollable.js +24 -0
  31. package/dist/src/mixins/infinite-scrollable.js.map +1 -1
  32. package/dist/src/os.d.ts +4 -0
  33. package/dist/src/os.js +4 -0
  34. package/dist/src/os.js.map +1 -1
  35. package/dist/src/password-pattern.d.ts +15 -0
  36. package/dist/src/password-pattern.js +15 -0
  37. package/dist/src/password-pattern.js.map +1 -1
  38. package/dist/src/stringify-bignum.d.ts +11 -0
  39. package/dist/src/stringify-bignum.js +11 -0
  40. package/dist/src/stringify-bignum.js.map +1 -1
  41. package/dist/src/timecapsule/snapshot-taker.d.ts +31 -0
  42. package/dist/src/timecapsule/snapshot-taker.js +36 -3
  43. package/dist/src/timecapsule/snapshot-taker.js.map +1 -1
  44. package/dist/src/timecapsule/timecapsule.d.ts +50 -0
  45. package/dist/src/timecapsule/timecapsule.js +50 -3
  46. package/dist/src/timecapsule/timecapsule.js.map +1 -1
  47. package/dist/tsconfig.tsbuildinfo +1 -1
  48. package/package.json +2 -2
  49. package/src/adjust-list-param.ts +20 -0
  50. package/src/async-lock.ts +13 -0
  51. package/src/clipboard.ts +7 -0
  52. package/src/closest-element.ts +8 -0
  53. package/src/context-path.ts +20 -0
  54. package/src/cookie.ts +18 -0
  55. package/src/detect-overflow.ts +6 -0
  56. package/src/format.ts +12 -0
  57. package/src/logger.ts +15 -4
  58. package/src/mixins/infinite-scrollable.ts +24 -0
  59. package/src/os.ts +4 -0
  60. package/src/password-pattern.ts +15 -0
  61. package/src/stringify-bignum.ts +12 -0
  62. package/src/timecapsule/snapshot-taker.ts +41 -4
  63. package/src/timecapsule/timecapsule.ts +50 -4
package/dist/src/os.js CHANGED
@@ -34,6 +34,10 @@ export function isIOS() {
34
34
  export function isMacOS() {
35
35
  return navigator.userAgent.indexOf('Mac') !== -1;
36
36
  }
37
+ /**
38
+ * method to tell if platform of running browser is Safari
39
+ * @returns {boolean}
40
+ */
37
41
  export function isSafari() {
38
42
  return !navigator.userAgent.match(/chrome|chromium|crios/i) && navigator.userAgent.match(/safari/i);
39
43
  }
@@ -1 +1 @@
1
- {"version":3,"file":"os.js","sourceRoot":"","sources":["../../src/os.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,UAAU,aAAa;IAC3B,OAAO,MAAM,CAAC,UAAU,CAAC,kCAAkC,CAAC,CAAC,OAAO,CAAA;AACtE,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,gBAAgB;IAC9B,OAAO,MAAM,CAAC,UAAU,CAAC,oBAAoB,CAAC,CAAC,OAAO,CAAA;AACxD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,cAAc;IAC5B,OAAO,MAAM,CAAC,UAAU,CAAC,oBAAoB,CAAC,CAAC,OAAO,CAAA;AACxD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,KAAK;IACnB,YAAY;IACZ,OAAO,kBAAkB,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAA;AACzE,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,OAAO;IACrB,OAAO,SAAS,CAAC,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAA;AAClD,CAAC;AAED,MAAM,UAAU,QAAQ;IACtB,OAAO,CAAC,SAAS,CAAC,SAAS,CAAC,KAAK,CAAC,wBAAwB,CAAC,IAAI,SAAS,CAAC,SAAS,CAAC,KAAK,CAAC,SAAS,CAAC,CAAA;AACrG,CAAC","sourcesContent":["/**\n * method to tell if platform of running browser is kind of touch device\n * @returns {boolean}\n */\nexport function isTouchDevice() {\n return window.matchMedia('(pointer:none), (pointer:coarse)').matches\n}\n\n/**\n * method to tell if platform of running browser is kind of mobile device\n * @returns {boolean}\n */\nexport function isHandheldDevice() {\n return window.matchMedia('(max-width: 460px)').matches\n}\n\n/**\n * method to tell if platform of running browser is kind of mobile device\n * @returns {boolean}\n */\nexport function isMobileDevice() {\n return window.matchMedia('(max-width: 767px)').matches\n}\n\n/**\n * method to tell if operating system of running browser is iOS\n * @returns {boolean}\n */\nexport function isIOS() {\n //@ts-ignore\n return /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream\n}\n\n/**\n * method to tell if operating system of running browser is MacOS\n * @returns {boolean}\n */\nexport function isMacOS() {\n return navigator.userAgent.indexOf('Mac') !== -1\n}\n\nexport function isSafari() {\n return !navigator.userAgent.match(/chrome|chromium|crios/i) && navigator.userAgent.match(/safari/i)\n}\n"]}
1
+ {"version":3,"file":"os.js","sourceRoot":"","sources":["../../src/os.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,UAAU,aAAa;IAC3B,OAAO,MAAM,CAAC,UAAU,CAAC,kCAAkC,CAAC,CAAC,OAAO,CAAA;AACtE,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,gBAAgB;IAC9B,OAAO,MAAM,CAAC,UAAU,CAAC,oBAAoB,CAAC,CAAC,OAAO,CAAA;AACxD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,cAAc;IAC5B,OAAO,MAAM,CAAC,UAAU,CAAC,oBAAoB,CAAC,CAAC,OAAO,CAAA;AACxD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,KAAK;IACnB,YAAY;IACZ,OAAO,kBAAkB,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAA;AACzE,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,OAAO;IACrB,OAAO,SAAS,CAAC,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAA;AAClD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,QAAQ;IACtB,OAAO,CAAC,SAAS,CAAC,SAAS,CAAC,KAAK,CAAC,wBAAwB,CAAC,IAAI,SAAS,CAAC,SAAS,CAAC,KAAK,CAAC,SAAS,CAAC,CAAA;AACrG,CAAC","sourcesContent":["/**\n * method to tell if platform of running browser is kind of touch device\n * @returns {boolean}\n */\nexport function isTouchDevice() {\n return window.matchMedia('(pointer:none), (pointer:coarse)').matches\n}\n\n/**\n * method to tell if platform of running browser is kind of mobile device\n * @returns {boolean}\n */\nexport function isHandheldDevice() {\n return window.matchMedia('(max-width: 460px)').matches\n}\n\n/**\n * method to tell if platform of running browser is kind of mobile device\n * @returns {boolean}\n */\nexport function isMobileDevice() {\n return window.matchMedia('(max-width: 767px)').matches\n}\n\n/**\n * method to tell if operating system of running browser is iOS\n * @returns {boolean}\n */\nexport function isIOS() {\n //@ts-ignore\n return /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream\n}\n\n/**\n * method to tell if operating system of running browser is MacOS\n * @returns {boolean}\n */\nexport function isMacOS() {\n return navigator.userAgent.indexOf('Mac') !== -1\n}\n\n/**\n * method to tell if platform of running browser is Safari\n * @returns {boolean}\n */\nexport function isSafari() {\n return !navigator.userAgent.match(/chrome|chromium|crios/i) && navigator.userAgent.match(/safari/i)\n}\n"]}
@@ -1,3 +1,18 @@
1
+ /**
2
+ * Generates a regular expression pattern for validating passwords based on specified criteria.
3
+ *
4
+ * @param {object} options - An object containing options for generating the pattern.
5
+ * @param {boolean} options.lowerCase - Indicates whether the password should contain at least one lowercase character.
6
+ * @param {boolean} options.upperCase - Indicates whether the password should contain at least one uppercase character.
7
+ * @param {boolean} options.digit - Indicates whether the password should contain at least one digit.
8
+ * @param {boolean} options.specialCharacter - Indicates whether the password should contain at least one special character.
9
+ * @param {boolean} options.allowRepeat - Indicates whether repeated characters are allowed in the password.
10
+ * @param {boolean} options.useTightPattern - Indicates whether to use a tight pattern for password length.
11
+ * @param {boolean} options.useLoosePattern - Indicates whether to use a loose pattern for password length.
12
+ * @param {number} options.tightCharacterLength - The minimum length of the password for the tight pattern.
13
+ * @param {number} options.looseCharacterLength - The minimum length of the password for the loose pattern.
14
+ * @returns {RegExp} - A regular expression pattern for validating passwords based on the specified criteria.
15
+ */
1
16
  export declare function generatePasswordPatternRegExp({ lowerCase, upperCase, digit, specialCharacter, allowRepeat, useTightPattern, useLoosePattern, tightCharacterLength, looseCharacterLength }?: {
2
17
  lowerCase?: boolean;
3
18
  upperCase?: boolean;
@@ -1,3 +1,18 @@
1
+ /**
2
+ * Generates a regular expression pattern for validating passwords based on specified criteria.
3
+ *
4
+ * @param {object} options - An object containing options for generating the pattern.
5
+ * @param {boolean} options.lowerCase - Indicates whether the password should contain at least one lowercase character.
6
+ * @param {boolean} options.upperCase - Indicates whether the password should contain at least one uppercase character.
7
+ * @param {boolean} options.digit - Indicates whether the password should contain at least one digit.
8
+ * @param {boolean} options.specialCharacter - Indicates whether the password should contain at least one special character.
9
+ * @param {boolean} options.allowRepeat - Indicates whether repeated characters are allowed in the password.
10
+ * @param {boolean} options.useTightPattern - Indicates whether to use a tight pattern for password length.
11
+ * @param {boolean} options.useLoosePattern - Indicates whether to use a loose pattern for password length.
12
+ * @param {number} options.tightCharacterLength - The minimum length of the password for the tight pattern.
13
+ * @param {number} options.looseCharacterLength - The minimum length of the password for the loose pattern.
14
+ * @returns {RegExp} - A regular expression pattern for validating passwords based on the specified criteria.
15
+ */
1
16
  export function generatePasswordPatternRegExp({ lowerCase = true, upperCase = true, digit = true, specialCharacter = true, allowRepeat = false, useTightPattern = true, useLoosePattern = false, tightCharacterLength = 8, looseCharacterLength = 15 } = {}) {
2
17
  var tightChecklist = useTightPattern
3
18
  ? [
@@ -1 +1 @@
1
- {"version":3,"file":"password-pattern.js","sourceRoot":"","sources":["../../src/password-pattern.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,6BAA6B,CAAC,EAC5C,SAAS,GAAG,IAAI,EAChB,SAAS,GAAG,IAAI,EAChB,KAAK,GAAG,IAAI,EACZ,gBAAgB,GAAG,IAAI,EACvB,WAAW,GAAG,KAAK,EACnB,eAAe,GAAG,IAAI,EACtB,eAAe,GAAG,KAAK,EACvB,oBAAoB,GAAG,CAAC,EACxB,oBAAoB,GAAG,EAAE,KAWvB,EAAE;IACJ,IAAI,cAAc,GAAG,eAAe;QAClC,CAAC,CAAC;YACE,SAAS,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,EAAE,wCAAwC;YACxE,SAAS,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,EAAE,wCAAwC;YACxE,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,EAAE,yBAAyB;YACnD,gBAAgB,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,EAAE,EAAE,qCAAqC;YACnF,CAAC,WAAW,CAAC,CAAC,CAAC,yBAAyB,CAAC,CAAC,CAAC,EAAE,EAAE,gDAAgD;YAC/F,KAAK,oBAAoB,IAAI,CAAC,6BAA6B;SAC5D;QACH,CAAC,CAAC,EAAE,CAAA;IAEN,IAAI,cAAc,GAAG,eAAe;QAClC,CAAC,CAAC;YACE,KAAK,oBAAoB,IAAI,CAAC,8BAA8B;SAC7D;QACH,CAAC,CAAC,EAAE,CAAA;IAEN,IAAI,SAAS,GAAG;QACd,GAAG,EAAE,aAAa;QAClB,GAAG,cAAc;QACjB,cAAc,CAAC,MAAM,IAAI,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE;QACzD,GAAG,cAAc;QACjB,GAAG,CAAC,aAAa;KAClB,CAAA;IAED,OAAO,IAAI,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAA;AACvC,CAAC","sourcesContent":["export function generatePasswordPatternRegExp({\n lowerCase = true,\n upperCase = true,\n digit = true,\n specialCharacter = true,\n allowRepeat = false,\n useTightPattern = true,\n useLoosePattern = false,\n tightCharacterLength = 8,\n looseCharacterLength = 15\n}: {\n lowerCase?: boolean\n upperCase?: boolean\n digit?: boolean\n specialCharacter?: boolean\n allowRepeat?: boolean\n useTightPattern?: boolean\n useLoosePattern?: boolean\n tightCharacterLength?: Number\n looseCharacterLength?: Number\n} = {}) {\n var tightChecklist = useTightPattern\n ? [\n lowerCase ? '(?=.*[a-z])' : '', // has at least one lower case character\n upperCase ? '(?=.*[A-Z])' : '', // has at least one upper case character\n digit ? '(?=.*\\\\d)' : '', // has at least one digit\n specialCharacter ? '(?=.*[!@#$%^&*()])' : '', // has at least one special character\n !allowRepeat ? '(?!.*(.)\\\\1(?=\\\\1{1,}))' : '', // has not an repeated character more than twice\n `.{${tightCharacterLength},}` // has a length of 8 and more\n ]\n : []\n\n var looseChecklist = useLoosePattern\n ? [\n `.{${looseCharacterLength},}` // has a length of 15 and more\n ]\n : []\n\n var checkList = [\n '^', // from start\n ...tightChecklist,\n tightChecklist.length && looseChecklist.length ? '|' : '',\n ...looseChecklist,\n '$' //to the end\"\n ]\n\n return new RegExp(checkList.join(''))\n}\n"]}
1
+ {"version":3,"file":"password-pattern.js","sourceRoot":"","sources":["../../src/password-pattern.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,6BAA6B,CAAC,EAC5C,SAAS,GAAG,IAAI,EAChB,SAAS,GAAG,IAAI,EAChB,KAAK,GAAG,IAAI,EACZ,gBAAgB,GAAG,IAAI,EACvB,WAAW,GAAG,KAAK,EACnB,eAAe,GAAG,IAAI,EACtB,eAAe,GAAG,KAAK,EACvB,oBAAoB,GAAG,CAAC,EACxB,oBAAoB,GAAG,EAAE,KAWvB,EAAE;IACJ,IAAI,cAAc,GAAG,eAAe;QAClC,CAAC,CAAC;YACE,SAAS,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,EAAE,wCAAwC;YACxE,SAAS,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,EAAE,wCAAwC;YACxE,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,EAAE,yBAAyB;YACnD,gBAAgB,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,EAAE,EAAE,qCAAqC;YACnF,CAAC,WAAW,CAAC,CAAC,CAAC,yBAAyB,CAAC,CAAC,CAAC,EAAE,EAAE,gDAAgD;YAC/F,KAAK,oBAAoB,IAAI,CAAC,6BAA6B;SAC5D;QACH,CAAC,CAAC,EAAE,CAAA;IAEN,IAAI,cAAc,GAAG,eAAe;QAClC,CAAC,CAAC;YACE,KAAK,oBAAoB,IAAI,CAAC,8BAA8B;SAC7D;QACH,CAAC,CAAC,EAAE,CAAA;IAEN,IAAI,SAAS,GAAG;QACd,GAAG,EAAE,aAAa;QAClB,GAAG,cAAc;QACjB,cAAc,CAAC,MAAM,IAAI,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE;QACzD,GAAG,cAAc;QACjB,GAAG,CAAC,aAAa;KAClB,CAAA;IAED,OAAO,IAAI,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAA;AACvC,CAAC","sourcesContent":["/**\n * Generates a regular expression pattern for validating passwords based on specified criteria.\n *\n * @param {object} options - An object containing options for generating the pattern.\n * @param {boolean} options.lowerCase - Indicates whether the password should contain at least one lowercase character.\n * @param {boolean} options.upperCase - Indicates whether the password should contain at least one uppercase character.\n * @param {boolean} options.digit - Indicates whether the password should contain at least one digit.\n * @param {boolean} options.specialCharacter - Indicates whether the password should contain at least one special character.\n * @param {boolean} options.allowRepeat - Indicates whether repeated characters are allowed in the password.\n * @param {boolean} options.useTightPattern - Indicates whether to use a tight pattern for password length.\n * @param {boolean} options.useLoosePattern - Indicates whether to use a loose pattern for password length.\n * @param {number} options.tightCharacterLength - The minimum length of the password for the tight pattern.\n * @param {number} options.looseCharacterLength - The minimum length of the password for the loose pattern.\n * @returns {RegExp} - A regular expression pattern for validating passwords based on the specified criteria.\n */\nexport function generatePasswordPatternRegExp({\n lowerCase = true,\n upperCase = true,\n digit = true,\n specialCharacter = true,\n allowRepeat = false,\n useTightPattern = true,\n useLoosePattern = false,\n tightCharacterLength = 8,\n looseCharacterLength = 15\n}: {\n lowerCase?: boolean\n upperCase?: boolean\n digit?: boolean\n specialCharacter?: boolean\n allowRepeat?: boolean\n useTightPattern?: boolean\n useLoosePattern?: boolean\n tightCharacterLength?: Number\n looseCharacterLength?: Number\n} = {}) {\n var tightChecklist = useTightPattern\n ? [\n lowerCase ? '(?=.*[a-z])' : '', // has at least one lower case character\n upperCase ? '(?=.*[A-Z])' : '', // has at least one upper case character\n digit ? '(?=.*\\\\d)' : '', // has at least one digit\n specialCharacter ? '(?=.*[!@#$%^&*()])' : '', // has at least one special character\n !allowRepeat ? '(?!.*(.)\\\\1(?=\\\\1{1,}))' : '', // has not an repeated character more than twice\n `.{${tightCharacterLength},}` // has a length of 8 and more\n ]\n : []\n\n var looseChecklist = useLoosePattern\n ? [\n `.{${looseCharacterLength},}` // has a length of 15 and more\n ]\n : []\n\n var checkList = [\n '^', // from start\n ...tightChecklist,\n tightChecklist.length && looseChecklist.length ? '|' : '',\n ...looseChecklist,\n '$' //to the end\"\n ]\n\n return new RegExp(checkList.join(''))\n}\n"]}
@@ -1 +1,12 @@
1
+ /**
2
+ * Converts a large number into a human-readable string representation with SI unit prefixes (K, M, B, T, P, E).
3
+ *
4
+ * This function takes a large number as input and converts it into a human-readable string representation using SI unit prefixes
5
+ * (K for thousand, M for million, B for billion, T for trillion, P for quadrillion, E for quintillion, etc.).
6
+ * It checks the magnitude of the input number and selects the appropriate SI unit,
7
+ * then formats the number with two decimal places and appends the corresponding SI unit symbol to create the readable string.
8
+ *
9
+ * @param {number} n - The number to be converted.
10
+ * @returns {string} - A human-readable string representation of the number with SI unit prefixes.
11
+ */
1
12
  export declare function stringifyBigNumber(n: number): string | number;
@@ -1,3 +1,14 @@
1
+ /**
2
+ * Converts a large number into a human-readable string representation with SI unit prefixes (K, M, B, T, P, E).
3
+ *
4
+ * This function takes a large number as input and converts it into a human-readable string representation using SI unit prefixes
5
+ * (K for thousand, M for million, B for billion, T for trillion, P for quadrillion, E for quintillion, etc.).
6
+ * It checks the magnitude of the input number and selects the appropriate SI unit,
7
+ * then formats the number with two decimal places and appends the corresponding SI unit symbol to create the readable string.
8
+ *
9
+ * @param {number} n - The number to be converted.
10
+ * @returns {string} - A human-readable string representation of the number with SI unit prefixes.
11
+ */
1
12
  export function stringifyBigNumber(n) {
2
13
  if (n < 1000) {
3
14
  return n;
@@ -1 +1 @@
1
- {"version":3,"file":"stringify-bignum.js","sourceRoot":"","sources":["../../src/stringify-bignum.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,kBAAkB,CAAC,CAAS;IAC1C,IAAI,CAAC,GAAG,IAAI,EAAE,CAAC;QACb,OAAO,CAAC,CAAA;IACV,CAAC;IAED,IAAI,EAAE,GAAG;QACP,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE;QAClB,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE;QAClB,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE;QAClB,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,EAAE;QACnB,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,EAAE;QACnB,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,EAAE;KACpB,CAAA;IAED,IAAI,KAAK,CAAA;IACT,KAAK,KAAK,GAAG,EAAE,CAAC,MAAM,GAAG,CAAC,EAAE,KAAK,GAAG,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC;QAC/C,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;YACrB,MAAK;QACP,CAAC;IACH,CAAC;IAED,OAAO,CAAC,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,0BAA0B,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;AAC7F,CAAC","sourcesContent":["export function stringifyBigNumber(n: number) {\n if (n < 1000) {\n return n\n }\n\n var si = [\n { v: 1e3, s: 'K' },\n { v: 1e6, s: 'M' },\n { v: 1e9, s: 'B' },\n { v: 1e12, s: 'T' },\n { v: 1e15, s: 'P' },\n { v: 1e18, s: 'E' }\n ]\n\n var index\n for (index = si.length - 1; index > 0; index--) {\n if (n >= si[index].v) {\n break\n }\n }\n\n return (n / si[index].v).toFixed(2).replace(/\\.0+$|(\\.[0-9]*[1-9])0+$/, '$1') + si[index].s\n}\n"]}
1
+ {"version":3,"file":"stringify-bignum.js","sourceRoot":"","sources":["../../src/stringify-bignum.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,MAAM,UAAU,kBAAkB,CAAC,CAAS;IAC1C,IAAI,CAAC,GAAG,IAAI,EAAE,CAAC;QACb,OAAO,CAAC,CAAA;IACV,CAAC;IAED,IAAI,EAAE,GAAG;QACP,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE;QAClB,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE;QAClB,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE;QAClB,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,EAAE;QACnB,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,EAAE;QACnB,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,EAAE;KACpB,CAAA;IAED,IAAI,KAAK,CAAA;IACT,KAAK,KAAK,GAAG,EAAE,CAAC,MAAM,GAAG,CAAC,EAAE,KAAK,GAAG,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC;QAC/C,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;YACrB,MAAK;QACP,CAAC;IACH,CAAC;IAED,OAAO,CAAC,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,0BAA0B,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;AAC7F,CAAC","sourcesContent":["/**\n * Converts a large number into a human-readable string representation with SI unit prefixes (K, M, B, T, P, E).\n *\n * This function takes a large number as input and converts it into a human-readable string representation using SI unit prefixes\n * (K for thousand, M for million, B for billion, T for trillion, P for quadrillion, E for quintillion, etc.).\n * It checks the magnitude of the input number and selects the appropriate SI unit,\n * then formats the number with two decimal places and appends the corresponding SI unit symbol to create the readable string.\n *\n * @param {number} n - The number to be converted.\n * @returns {string} - A human-readable string representation of the number with SI unit prefixes.\n */\n\nexport function stringifyBigNumber(n: number) {\n if (n < 1000) {\n return n\n }\n\n var si = [\n { v: 1e3, s: 'K' },\n { v: 1e6, s: 'M' },\n { v: 1e9, s: 'B' },\n { v: 1e12, s: 'T' },\n { v: 1e15, s: 'P' },\n { v: 1e18, s: 'E' }\n ]\n\n var index\n for (index = si.length - 1; index > 0; index--) {\n if (n >= si[index].v) {\n break\n }\n }\n\n return (n / si[index].v).toFixed(2).replace(/\\.0+$|(\\.[0-9]*[1-9])0+$/, '$1') + si[index].s\n}\n"]}
@@ -1,16 +1,47 @@
1
1
  import { TimeCapsule } from './timecapsule';
2
+ /**
3
+ * Type definition for holding state information.
4
+ * @typedef {Object} StateHolder
5
+ * @property {*} state - The state to be held.
6
+ */
2
7
  export type StateHolder = {
3
8
  state: any;
4
9
  };
10
+ /**
11
+ * Class responsible for taking and managing snapshots of state.
12
+ */
5
13
  export declare class SnapshotTaker {
6
14
  private _brake;
7
15
  dirty: boolean;
8
16
  state_holder?: StateHolder;
9
17
  timecapsule?: TimeCapsule;
18
+ /**
19
+ * Creates an instance of SnapshotTaker.
20
+ * @param {*} state_holder - The object that holds the state to be snapshot.
21
+ * @param {TimeCapsule} timecapsule - The TimeCapsule instance associated with this SnapshotTaker.
22
+ */
10
23
  constructor(state_holder: any, timecapsule: TimeCapsule);
24
+ /**
25
+ * Disposes of the SnapshotTaker and clears associated references.
26
+ */
11
27
  dispose(): void;
28
+ /**
29
+ * Marks the SnapshotTaker as dirty and initiates snapshot creation.
30
+ */
12
31
  touch(): void;
32
+ /**
33
+ * Takes a snapshot of the current state.
34
+ * @param {boolean} [force=false] - If true, the snapshot is taken even if not dirty.
35
+ */
13
36
  take(force?: boolean): void;
37
+ /**
38
+ * Gets the brake state of the SnapshotTaker.
39
+ * @returns {boolean} - true if the brake is active, false otherwise.
40
+ */
14
41
  get brake(): boolean;
42
+ /**
43
+ * Sets the brake state of the SnapshotTaker and initiates snapshot creation.
44
+ * @param {boolean} brake - The new brake state.
45
+ */
15
46
  set brake(brake: boolean);
16
47
  }
@@ -1,18 +1,33 @@
1
- /*
2
- * Copyright © HatioLab Inc. All rights reserved.
3
- */
4
1
  import debounce from 'lodash-es/debounce';
2
+ /**
3
+ * A function that takes a SnapshotTaker as an argument and initiates snapshot creation
4
+ * using a debouncer to delay the process.
5
+ * @param {SnapshotTaker} taker - The SnapshotTaker instance to trigger snapshots for.
6
+ */
5
7
  var debouncer = debounce(taker => {
6
8
  if (!taker.brake) {
7
9
  taker.take();
8
10
  }
9
11
  }, 1000, { leading: true, trailing: false });
12
+ /**
13
+ * Function to trigger snapshot creation for a SnapshotTaker instance.
14
+ * Checks if the taker is in a brake state or not dirty before triggering the snapshot.
15
+ * @param {SnapshotTaker} taker - The SnapshotTaker instance to create a snapshot for.
16
+ */
10
17
  function take_snapshot(taker) {
11
18
  if (taker.brake || !taker.dirty)
12
19
  return;
13
20
  debouncer(taker);
14
21
  }
22
+ /**
23
+ * Class responsible for taking and managing snapshots of state.
24
+ */
15
25
  export class SnapshotTaker {
26
+ /**
27
+ * Creates an instance of SnapshotTaker.
28
+ * @param {*} state_holder - The object that holds the state to be snapshot.
29
+ * @param {TimeCapsule} timecapsule - The TimeCapsule instance associated with this SnapshotTaker.
30
+ */
16
31
  constructor(state_holder, timecapsule) {
17
32
  this._brake = false;
18
33
  this.dirty = false;
@@ -20,15 +35,25 @@ export class SnapshotTaker {
20
35
  this.timecapsule = timecapsule;
21
36
  this.timecapsule.snapshot_taker = this;
22
37
  }
38
+ /**
39
+ * Disposes of the SnapshotTaker and clears associated references.
40
+ */
23
41
  dispose() {
24
42
  delete this.state_holder;
25
43
  delete this.timecapsule;
26
44
  }
45
+ /**
46
+ * Marks the SnapshotTaker as dirty and initiates snapshot creation.
47
+ */
27
48
  touch() {
28
49
  this.dirty = true;
29
50
  take_snapshot(this);
30
51
  }
31
52
  /* 모든 조건에 관계없이 현재 상태를 snapshot으로 취한다. */
53
+ /**
54
+ * Takes a snapshot of the current state.
55
+ * @param {boolean} [force=false] - If true, the snapshot is taken even if not dirty.
56
+ */
32
57
  take(force = false) {
33
58
  var _a, _b;
34
59
  if (this.dirty || force) {
@@ -36,10 +61,18 @@ export class SnapshotTaker {
36
61
  this.dirty = false;
37
62
  }
38
63
  }
64
+ /**
65
+ * Gets the brake state of the SnapshotTaker.
66
+ * @returns {boolean} - true if the brake is active, false otherwise.
67
+ */
39
68
  get brake() {
40
69
  return this._brake;
41
70
  }
42
71
  /* 마우스를 드래깅하는 동안, 보통 brake 를 ON 시킨다. */
72
+ /**
73
+ * Sets the brake state of the SnapshotTaker and initiates snapshot creation.
74
+ * @param {boolean} brake - The new brake state.
75
+ */
43
76
  set brake(brake) {
44
77
  this._brake = !!brake;
45
78
  take_snapshot(this);
@@ -1 +1 @@
1
- {"version":3,"file":"snapshot-taker.js","sourceRoot":"","sources":["../../../src/timecapsule/snapshot-taker.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,QAAQ,MAAM,oBAAoB,CAAA;AAEzC,IAAI,SAAS,GAAG,QAAQ,CACtB,KAAK,CAAC,EAAE;IACN,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;QACjB,KAAK,CAAC,IAAI,EAAE,CAAA;IACd,CAAC;AACH,CAAC,EACD,IAAI,EACJ,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,CACnC,CAAA;AAED,SAAS,aAAa,CAAC,KAAoB;IACzC,IAAI,KAAK,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC,KAAK;QAAE,OAAM;IACvC,SAAS,CAAC,KAAK,CAAC,CAAA;AAClB,CAAC;AAMD,MAAM,OAAO,aAAa;IAQxB,YAAY,YAAiB,EAAE,WAAwB;QAP/C,WAAM,GAAY,KAAK,CAAA;QAE/B,UAAK,GAAY,KAAK,CAAA;QAMpB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA;QAChC,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;QAC9B,IAAI,CAAC,WAAW,CAAC,cAAc,GAAG,IAAI,CAAA;IACxC,CAAC;IAED,OAAO;QACL,OAAO,IAAI,CAAC,YAAY,CAAA;QACxB,OAAO,IAAI,CAAC,WAAW,CAAA;IACzB,CAAC;IAED,KAAK;QACH,IAAI,CAAC,KAAK,GAAG,IAAI,CAAA;QACjB,aAAa,CAAC,IAAI,CAAC,CAAA;IACrB,CAAC;IAED,wCAAwC;IACxC,IAAI,CAAC,QAAiB,KAAK;;QACzB,IAAI,IAAI,CAAC,KAAK,IAAI,KAAK,EAAE,CAAC;YACxB,MAAA,IAAI,CAAC,WAAW,0CAAE,QAAQ,CAAC,MAAA,IAAI,CAAC,YAAY,0CAAE,KAAK,CAAC,CAAA;YACpD,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;QACpB,CAAC;IACH,CAAC;IAED,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAA;IACpB,CAAC;IAED,uCAAuC;IACvC,IAAI,KAAK,CAAC,KAAK;QACb,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,CAAA;QACrB,aAAa,CAAC,IAAI,CAAC,CAAA;IACrB,CAAC;CACF","sourcesContent":["/*\n * Copyright © HatioLab Inc. All rights reserved.\n */\n\nimport { TimeCapsule } from './timecapsule'\nimport debounce from 'lodash-es/debounce'\n\nvar debouncer = debounce(\n taker => {\n if (!taker.brake) {\n taker.take()\n }\n },\n 1000,\n { leading: true, trailing: false }\n)\n\nfunction take_snapshot(taker: SnapshotTaker) {\n if (taker.brake || !taker.dirty) return\n debouncer(taker)\n}\n\nexport type StateHolder = {\n state: any\n}\n\nexport class SnapshotTaker {\n private _brake: boolean = false\n\n dirty: boolean = false\n\n state_holder?: StateHolder\n timecapsule?: TimeCapsule\n\n constructor(state_holder: any, timecapsule: TimeCapsule) {\n this.state_holder = state_holder\n this.timecapsule = timecapsule\n this.timecapsule.snapshot_taker = this\n }\n\n dispose() {\n delete this.state_holder\n delete this.timecapsule\n }\n\n touch() {\n this.dirty = true\n take_snapshot(this)\n }\n\n /* 모든 조건에 관계없이 현재 상태를 snapshot으로 취한다. */\n take(force: boolean = false) {\n if (this.dirty || force) {\n this.timecapsule?.snapshot(this.state_holder?.state)\n this.dirty = false\n }\n }\n\n get brake() {\n return this._brake\n }\n\n /* 마우스를 드래깅하는 동안, 보통 brake 를 ON 시킨다. */\n set brake(brake) {\n this._brake = !!brake\n take_snapshot(this)\n }\n}\n"]}
1
+ {"version":3,"file":"snapshot-taker.js","sourceRoot":"","sources":["../../../src/timecapsule/snapshot-taker.ts"],"names":[],"mappings":"AACA,OAAO,QAAQ,MAAM,oBAAoB,CAAA;AAEzC;;;;GAIG;AACH,IAAI,SAAS,GAAG,QAAQ,CACtB,KAAK,CAAC,EAAE;IACN,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;QACjB,KAAK,CAAC,IAAI,EAAE,CAAA;IACd,CAAC;AACH,CAAC,EACD,IAAI,EACJ,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,CACnC,CAAA;AAED;;;;GAIG;AACH,SAAS,aAAa,CAAC,KAAoB;IACzC,IAAI,KAAK,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC,KAAK;QAAE,OAAM;IACvC,SAAS,CAAC,KAAK,CAAC,CAAA;AAClB,CAAC;AAWD;;GAEG;AACH,MAAM,OAAO,aAAa;IAQxB;;;;OAIG;IACH,YAAY,YAAiB,EAAE,WAAwB;QAZ/C,WAAM,GAAY,KAAK,CAAA;QAE/B,UAAK,GAAY,KAAK,CAAA;QAWpB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA;QAChC,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;QAC9B,IAAI,CAAC,WAAW,CAAC,cAAc,GAAG,IAAI,CAAA;IACxC,CAAC;IAED;;OAEG;IACH,OAAO;QACL,OAAO,IAAI,CAAC,YAAY,CAAA;QACxB,OAAO,IAAI,CAAC,WAAW,CAAA;IACzB,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,KAAK,GAAG,IAAI,CAAA;QACjB,aAAa,CAAC,IAAI,CAAC,CAAA;IACrB,CAAC;IAED,wCAAwC;IACxC;;;OAGG;IACH,IAAI,CAAC,QAAiB,KAAK;;QACzB,IAAI,IAAI,CAAC,KAAK,IAAI,KAAK,EAAE,CAAC;YACxB,MAAA,IAAI,CAAC,WAAW,0CAAE,QAAQ,CAAC,MAAA,IAAI,CAAC,YAAY,0CAAE,KAAK,CAAC,CAAA;YACpD,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;QACpB,CAAC;IACH,CAAC;IAED;;;OAGG;IACH,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAA;IACpB,CAAC;IAED,uCAAuC;IACvC;;;OAGG;IACH,IAAI,KAAK,CAAC,KAAK;QACb,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,CAAA;QACrB,aAAa,CAAC,IAAI,CAAC,CAAA;IACrB,CAAC;CACF","sourcesContent":["import { TimeCapsule } from './timecapsule'\nimport debounce from 'lodash-es/debounce'\n\n/**\n * A function that takes a SnapshotTaker as an argument and initiates snapshot creation\n * using a debouncer to delay the process.\n * @param {SnapshotTaker} taker - The SnapshotTaker instance to trigger snapshots for.\n */\nvar debouncer = debounce(\n taker => {\n if (!taker.brake) {\n taker.take()\n }\n },\n 1000,\n { leading: true, trailing: false }\n)\n\n/**\n * Function to trigger snapshot creation for a SnapshotTaker instance.\n * Checks if the taker is in a brake state or not dirty before triggering the snapshot.\n * @param {SnapshotTaker} taker - The SnapshotTaker instance to create a snapshot for.\n */\nfunction take_snapshot(taker: SnapshotTaker) {\n if (taker.brake || !taker.dirty) return\n debouncer(taker)\n}\n\n/**\n * Type definition for holding state information.\n * @typedef {Object} StateHolder\n * @property {*} state - The state to be held.\n */\nexport type StateHolder = {\n state: any\n}\n\n/**\n * Class responsible for taking and managing snapshots of state.\n */\nexport class SnapshotTaker {\n private _brake: boolean = false\n\n dirty: boolean = false\n\n state_holder?: StateHolder\n timecapsule?: TimeCapsule\n\n /**\n * Creates an instance of SnapshotTaker.\n * @param {*} state_holder - The object that holds the state to be snapshot.\n * @param {TimeCapsule} timecapsule - The TimeCapsule instance associated with this SnapshotTaker.\n */\n constructor(state_holder: any, timecapsule: TimeCapsule) {\n this.state_holder = state_holder\n this.timecapsule = timecapsule\n this.timecapsule.snapshot_taker = this\n }\n\n /**\n * Disposes of the SnapshotTaker and clears associated references.\n */\n dispose() {\n delete this.state_holder\n delete this.timecapsule\n }\n\n /**\n * Marks the SnapshotTaker as dirty and initiates snapshot creation.\n */\n touch() {\n this.dirty = true\n take_snapshot(this)\n }\n\n /* 모든 조건에 관계없이 현재 상태를 snapshot으로 취한다. */\n /**\n * Takes a snapshot of the current state.\n * @param {boolean} [force=false] - If true, the snapshot is taken even if not dirty.\n */\n take(force: boolean = false) {\n if (this.dirty || force) {\n this.timecapsule?.snapshot(this.state_holder?.state)\n this.dirty = false\n }\n }\n\n /**\n * Gets the brake state of the SnapshotTaker.\n * @returns {boolean} - true if the brake is active, false otherwise.\n */\n get brake() {\n return this._brake\n }\n\n /* 마우스를 드래깅하는 동안, 보통 brake 를 ON 시킨다. */\n /**\n * Sets the brake state of the SnapshotTaker and initiates snapshot creation.\n * @param {boolean} brake - The new brake state.\n */\n set brake(brake) {\n this._brake = !!brake\n take_snapshot(this)\n }\n}\n"]}
@@ -1,19 +1,69 @@
1
1
  import { SnapshotTaker } from './snapshot-taker';
2
+ /**
3
+ * A utility class for managing and navigating through a history of snapshots.
4
+ */
2
5
  export declare class TimeCapsule {
3
6
  private q;
4
7
  private maxsize;
5
8
  private pos;
6
9
  private _snapshot_taker;
10
+ /**
11
+ * Creates an instance of TimeCapsule.
12
+ * @param {number} maxsize - The maximum number of snapshots to store.
13
+ * @param {any} [start_state] - The initial state to be stored as the first snapshot (optional).
14
+ */
7
15
  constructor(maxsize: number, start_state?: any);
16
+ /**
17
+ * Disposes of the TimeCapsule and clears all stored snapshots.
18
+ */
8
19
  dispose(): void;
20
+ /**
21
+ * Captures a snapshot of the current state and stores it.
22
+ * @param {any} state - The state to be captured as a snapshot.
23
+ */
9
24
  snapshot(state: any): void;
25
+ /**
26
+ * Moves forward to the next snapshot in the history.
27
+ * @returns {any} The next state snapshot if available, or logs a warning if not.
28
+ */
10
29
  forward(): any;
30
+ /**
31
+ * Moves backward to the previous snapshot in the history.
32
+ * @returns {any} The previous state snapshot if available, or logs a warning if not.
33
+ */
11
34
  backward(): any;
35
+ /**
36
+ * Gets the current state snapshot.
37
+ * @returns {any} The current state snapshot if available, or logs a warning if not.
38
+ */
12
39
  get current(): any;
40
+ /**
41
+ * Gets the number of snapshots stored in the TimeCapsule.
42
+ * @returns {number} The count of stored snapshots.
43
+ */
13
44
  get length(): number;
45
+ /**
46
+ * Checks if there is a snapshot available to move forward.
47
+ * @returns {boolean} True if moving forward is possible, otherwise false.
48
+ */
14
49
  get forwardable(): boolean;
50
+ /**
51
+ * Checks if there is a snapshot available to move backward.
52
+ * @returns {boolean} True if moving backward is possible, otherwise false.
53
+ */
15
54
  get backwardable(): boolean;
55
+ /**
56
+ * Gets the SnapshotTaker associated with this TimeCapsule.
57
+ * @returns {SnapshotTaker | null} The associated SnapshotTaker, or null if not set.
58
+ */
16
59
  get snapshot_taker(): SnapshotTaker | null;
60
+ /**
61
+ * Sets the SnapshotTaker for this TimeCapsule.
62
+ * @param {SnapshotTaker | null} snapshot_taker - The SnapshotTaker instance to associate with this TimeCapsule.
63
+ */
17
64
  set snapshot_taker(snapshot_taker: SnapshotTaker | null);
65
+ /**
66
+ * Resets the TimeCapsule, clearing all stored snapshots and resetting the position.
67
+ */
18
68
  reset(): void;
19
69
  }
@@ -1,8 +1,13 @@
1
- /*
2
- * Copyright © HatioLab Inc. All rights reserved.
3
- */
4
1
  import { error, warn } from '../logger';
2
+ /**
3
+ * A utility class for managing and navigating through a history of snapshots.
4
+ */
5
5
  export class TimeCapsule {
6
+ /**
7
+ * Creates an instance of TimeCapsule.
8
+ * @param {number} maxsize - The maximum number of snapshots to store.
9
+ * @param {any} [start_state] - The initial state to be stored as the first snapshot (optional).
10
+ */
6
11
  constructor(maxsize, start_state) {
7
12
  this.q = [];
8
13
  this.maxsize = 10;
@@ -20,9 +25,16 @@ export class TimeCapsule {
20
25
  this.snapshot(start_state);
21
26
  }
22
27
  }
28
+ /**
29
+ * Disposes of the TimeCapsule and clears all stored snapshots.
30
+ */
23
31
  dispose() {
24
32
  this.reset();
25
33
  }
34
+ /**
35
+ * Captures a snapshot of the current state and stores it.
36
+ * @param {any} state - The state to be captured as a snapshot.
37
+ */
26
38
  snapshot(state) {
27
39
  this.q.splice(this.pos + 1, this.q.length - (this.pos + 1), state);
28
40
  if (this.q.length > this.maxsize) {
@@ -30,6 +42,10 @@ export class TimeCapsule {
30
42
  }
31
43
  this.pos = this.q.length - 1;
32
44
  }
45
+ /**
46
+ * Moves forward to the next snapshot in the history.
47
+ * @returns {any} The next state snapshot if available, or logs a warning if not.
48
+ */
33
49
  forward() {
34
50
  if (this.snapshot_taker)
35
51
  this.snapshot_taker.take();
@@ -38,6 +54,10 @@ export class TimeCapsule {
38
54
  }
39
55
  warn('Not forwardable.');
40
56
  }
57
+ /**
58
+ * Moves backward to the previous snapshot in the history.
59
+ * @returns {any} The previous state snapshot if available, or logs a warning if not.
60
+ */
41
61
  backward() {
42
62
  if (this.snapshot_taker)
43
63
  this.snapshot_taker.take();
@@ -46,26 +66,53 @@ export class TimeCapsule {
46
66
  }
47
67
  warn('Not backwardable.');
48
68
  }
69
+ /**
70
+ * Gets the current state snapshot.
71
+ * @returns {any} The current state snapshot if available, or logs a warning if not.
72
+ */
49
73
  get current() {
50
74
  if (this.pos !== -1)
51
75
  return this.q[this.pos];
52
76
  warn('Non state has been recorded.');
53
77
  }
78
+ /**
79
+ * Gets the number of snapshots stored in the TimeCapsule.
80
+ * @returns {number} The count of stored snapshots.
81
+ */
54
82
  get length() {
55
83
  return this.q.length;
56
84
  }
85
+ /**
86
+ * Checks if there is a snapshot available to move forward.
87
+ * @returns {boolean} True if moving forward is possible, otherwise false.
88
+ */
57
89
  get forwardable() {
58
90
  return this.pos < this.q.length - 1;
59
91
  }
92
+ /**
93
+ * Checks if there is a snapshot available to move backward.
94
+ * @returns {boolean} True if moving backward is possible, otherwise false.
95
+ */
60
96
  get backwardable() {
61
97
  return this.pos > 0;
62
98
  }
99
+ /**
100
+ * Gets the SnapshotTaker associated with this TimeCapsule.
101
+ * @returns {SnapshotTaker | null} The associated SnapshotTaker, or null if not set.
102
+ */
63
103
  get snapshot_taker() {
64
104
  return this._snapshot_taker;
65
105
  }
106
+ /**
107
+ * Sets the SnapshotTaker for this TimeCapsule.
108
+ * @param {SnapshotTaker | null} snapshot_taker - The SnapshotTaker instance to associate with this TimeCapsule.
109
+ */
66
110
  set snapshot_taker(snapshot_taker) {
67
111
  this._snapshot_taker = snapshot_taker;
68
112
  }
113
+ /**
114
+ * Resets the TimeCapsule, clearing all stored snapshots and resetting the position.
115
+ */
69
116
  reset() {
70
117
  this.q = [];
71
118
  this.pos = -1;
@@ -1 +1 @@
1
- {"version":3,"file":"timecapsule.js","sourceRoot":"","sources":["../../../src/timecapsule/timecapsule.ts"],"names":[],"mappings":"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","sourcesContent":["/*\n * Copyright © HatioLab Inc. All rights reserved.\n */\n\nimport { debug, error, warn } from '../logger'\n\nimport { SnapshotTaker } from './snapshot-taker'\n\nexport class TimeCapsule {\n private q: Array<any> = []\n private maxsize = 10\n private pos = -1\n\n private _snapshot_taker: SnapshotTaker | null = null\n\n constructor(maxsize: number, start_state?: any) {\n maxsize = Number(maxsize)\n\n if (!maxsize || maxsize <= 0) {\n error('TimeCapsule maxsize should be greater than 0.', maxsize)\n } else {\n this.maxsize = maxsize\n }\n\n this.reset()\n if (start_state) {\n this.snapshot(start_state)\n }\n }\n\n dispose() {\n this.reset()\n }\n\n snapshot(state: any) {\n this.q.splice(this.pos + 1, this.q.length - (this.pos + 1), state)\n\n if (this.q.length > this.maxsize) {\n this.q.splice(0, this.q.length - this.maxsize)\n }\n\n this.pos = this.q.length - 1\n }\n\n forward() {\n if (this.snapshot_taker) this.snapshot_taker.take()\n\n if (this.forwardable) {\n return this.q[++this.pos]\n }\n warn('Not forwardable.')\n }\n\n backward() {\n if (this.snapshot_taker) this.snapshot_taker.take()\n\n if (this.backwardable) {\n return this.q[--this.pos]\n }\n warn('Not backwardable.')\n }\n\n get current() {\n if (this.pos !== -1) return this.q[this.pos]\n\n warn('Non state has been recorded.')\n }\n\n get length() {\n return this.q.length\n }\n\n get forwardable() {\n return this.pos < this.q.length - 1\n }\n\n get backwardable() {\n return this.pos > 0\n }\n\n get snapshot_taker(): SnapshotTaker | null {\n return this._snapshot_taker\n }\n\n set snapshot_taker(snapshot_taker: SnapshotTaker | null) {\n this._snapshot_taker = snapshot_taker\n }\n\n reset() {\n this.q = []\n this.pos = -1\n }\n}\n"]}
1
+ {"version":3,"file":"timecapsule.js","sourceRoot":"","sources":["../../../src/timecapsule/timecapsule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAI9C;;GAEG;AACH,MAAM,OAAO,WAAW;IAOtB;;;;OAIG;IACH,YAAY,OAAe,EAAE,WAAiB;QAXtC,MAAC,GAAe,EAAE,CAAA;QAClB,YAAO,GAAG,EAAE,CAAA;QACZ,QAAG,GAAG,CAAC,CAAC,CAAA;QAER,oBAAe,GAAyB,IAAI,CAAA;QAQlD,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,CAAA;QAEzB,IAAI,CAAC,OAAO,IAAI,OAAO,IAAI,CAAC,EAAE,CAAC;YAC7B,KAAK,CAAC,+CAA+C,EAAE,OAAO,CAAC,CAAA;QACjE,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACxB,CAAC;QAED,IAAI,CAAC,KAAK,EAAE,CAAA;QACZ,IAAI,WAAW,EAAE,CAAC;YAChB,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAA;QAC5B,CAAC;IACH,CAAC;IAED;;OAEG;IACH,OAAO;QACL,IAAI,CAAC,KAAK,EAAE,CAAA;IACd,CAAC;IAED;;;OAGG;IACH,QAAQ,CAAC,KAAU;QACjB,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,CAAA;QAElE,IAAI,IAAI,CAAC,CAAC,CAAC,MAAM,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;YACjC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,CAAA;QAChD,CAAC;QAED,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAA;IAC9B,CAAC;IAED;;;OAGG;IACH,OAAO;QACL,IAAI,IAAI,CAAC,cAAc;YAAE,IAAI,CAAC,cAAc,CAAC,IAAI,EAAE,CAAA;QAEnD,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACrB,OAAO,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAA;QAC3B,CAAC;QACD,IAAI,CAAC,kBAAkB,CAAC,CAAA;IAC1B,CAAC;IAED;;;OAGG;IACH,QAAQ;QACN,IAAI,IAAI,CAAC,cAAc;YAAE,IAAI,CAAC,cAAc,CAAC,IAAI,EAAE,CAAA;QAEnD,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YACtB,OAAO,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAA;QAC3B,CAAC;QACD,IAAI,CAAC,mBAAmB,CAAC,CAAA;IAC3B,CAAC;IAED;;;OAGG;IACH,IAAI,OAAO;QACT,IAAI,IAAI,CAAC,GAAG,KAAK,CAAC,CAAC;YAAE,OAAO,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QAE5C,IAAI,CAAC,8BAA8B,CAAC,CAAA;IACtC,CAAC;IAED;;;OAGG;IACH,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,CAAC,CAAC,MAAM,CAAA;IACtB,CAAC;IAED;;;OAGG;IACH,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAA;IACrC,CAAC;IAED;;;OAGG;IACH,IAAI,YAAY;QACd,OAAO,IAAI,CAAC,GAAG,GAAG,CAAC,CAAA;IACrB,CAAC;IAED;;;OAGG;IACH,IAAI,cAAc;QAChB,OAAO,IAAI,CAAC,eAAe,CAAA;IAC7B,CAAC;IAED;;;OAGG;IACH,IAAI,cAAc,CAAC,cAAoC;QACrD,IAAI,CAAC,eAAe,GAAG,cAAc,CAAA;IACvC,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,CAAC,GAAG,EAAE,CAAA;QACX,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,CAAA;IACf,CAAC;CACF","sourcesContent":["import { debug, error, warn } from '../logger'\n\nimport { SnapshotTaker } from './snapshot-taker'\n\n/**\n * A utility class for managing and navigating through a history of snapshots.\n */\nexport class TimeCapsule {\n private q: Array<any> = []\n private maxsize = 10\n private pos = -1\n\n private _snapshot_taker: SnapshotTaker | null = null\n\n /**\n * Creates an instance of TimeCapsule.\n * @param {number} maxsize - The maximum number of snapshots to store.\n * @param {any} [start_state] - The initial state to be stored as the first snapshot (optional).\n */\n constructor(maxsize: number, start_state?: any) {\n maxsize = Number(maxsize)\n\n if (!maxsize || maxsize <= 0) {\n error('TimeCapsule maxsize should be greater than 0.', maxsize)\n } else {\n this.maxsize = maxsize\n }\n\n this.reset()\n if (start_state) {\n this.snapshot(start_state)\n }\n }\n\n /**\n * Disposes of the TimeCapsule and clears all stored snapshots.\n */\n dispose() {\n this.reset()\n }\n\n /**\n * Captures a snapshot of the current state and stores it.\n * @param {any} state - The state to be captured as a snapshot.\n */\n snapshot(state: any) {\n this.q.splice(this.pos + 1, this.q.length - (this.pos + 1), state)\n\n if (this.q.length > this.maxsize) {\n this.q.splice(0, this.q.length - this.maxsize)\n }\n\n this.pos = this.q.length - 1\n }\n\n /**\n * Moves forward to the next snapshot in the history.\n * @returns {any} The next state snapshot if available, or logs a warning if not.\n */\n forward() {\n if (this.snapshot_taker) this.snapshot_taker.take()\n\n if (this.forwardable) {\n return this.q[++this.pos]\n }\n warn('Not forwardable.')\n }\n\n /**\n * Moves backward to the previous snapshot in the history.\n * @returns {any} The previous state snapshot if available, or logs a warning if not.\n */\n backward() {\n if (this.snapshot_taker) this.snapshot_taker.take()\n\n if (this.backwardable) {\n return this.q[--this.pos]\n }\n warn('Not backwardable.')\n }\n\n /**\n * Gets the current state snapshot.\n * @returns {any} The current state snapshot if available, or logs a warning if not.\n */\n get current() {\n if (this.pos !== -1) return this.q[this.pos]\n\n warn('Non state has been recorded.')\n }\n\n /**\n * Gets the number of snapshots stored in the TimeCapsule.\n * @returns {number} The count of stored snapshots.\n */\n get length() {\n return this.q.length\n }\n\n /**\n * Checks if there is a snapshot available to move forward.\n * @returns {boolean} True if moving forward is possible, otherwise false.\n */\n get forwardable() {\n return this.pos < this.q.length - 1\n }\n\n /**\n * Checks if there is a snapshot available to move backward.\n * @returns {boolean} True if moving backward is possible, otherwise false.\n */\n get backwardable() {\n return this.pos > 0\n }\n\n /**\n * Gets the SnapshotTaker associated with this TimeCapsule.\n * @returns {SnapshotTaker | null} The associated SnapshotTaker, or null if not set.\n */\n get snapshot_taker(): SnapshotTaker | null {\n return this._snapshot_taker\n }\n\n /**\n * Sets the SnapshotTaker for this TimeCapsule.\n * @param {SnapshotTaker | null} snapshot_taker - The SnapshotTaker instance to associate with this TimeCapsule.\n */\n set snapshot_taker(snapshot_taker: SnapshotTaker | null) {\n this._snapshot_taker = snapshot_taker\n }\n\n /**\n * Resets the TimeCapsule, clearing all stored snapshots and resetting the position.\n */\n reset() {\n this.q = []\n this.pos = -1\n }\n}\n"]}