@shaxpir/duiduidui-models 1.0.1 → 1.2.0

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 (226) hide show
  1. package/dist/models/{content/ArrayView.d.ts → ArrayView.d.ts} +1 -1
  2. package/dist/models/{content/ArrayView.js → ArrayView.js} +14 -14
  3. package/dist/models/BayesianScore.d.ts +9 -0
  4. package/dist/models/BayesianScore.js +27 -0
  5. package/dist/models/{markup/ChangeModel.d.ts → ChangeModel.d.ts} +2 -3
  6. package/dist/models/{markup/ChangeModel.js → ChangeModel.js} +20 -10
  7. package/dist/models/{content/Content.d.ts → Content.d.ts} +9 -10
  8. package/dist/models/{content/Content.js → Content.js} +2 -6
  9. package/dist/models/{content/ContentKind.d.ts → ContentKind.d.ts} +3 -0
  10. package/dist/models/{content/ContentKind.js → ContentKind.js} +5 -1
  11. package/dist/models/{content/Device.d.ts → Device.d.ts} +15 -7
  12. package/dist/models/{content/Device.js → Device.js} +14 -18
  13. package/dist/models/Hanzi.d.ts +15 -0
  14. package/dist/models/{content/Manifest.d.ts → Manifest.d.ts} +7 -3
  15. package/dist/models/{content/Manifest.js → Manifest.js} +12 -8
  16. package/dist/models/{content/Media.d.ts → Media.d.ts} +2 -3
  17. package/dist/models/{content/Media.js → Media.js} +4 -5
  18. package/dist/models/{content/Metric.d.ts → Metric.d.ts} +2 -3
  19. package/dist/models/{content/Metric.js → Metric.js} +18 -20
  20. package/dist/models/{content/Model.d.ts → Model.d.ts} +3 -5
  21. package/dist/models/{content/Model.js → Model.js} +5 -6
  22. package/dist/models/{markup/Operation.d.ts → Operation.d.ts} +2 -5
  23. package/dist/models/{markup/Operation.js → Operation.js} +30 -25
  24. package/dist/models/Phrase.d.ts +39 -0
  25. package/dist/models/{content/Profile.d.ts → Profile.d.ts} +1 -2
  26. package/dist/models/{content/Profile.js → Profile.js} +7 -9
  27. package/dist/models/Progress.d.ts +26 -0
  28. package/dist/models/Progress.js +39 -0
  29. package/dist/models/Review.d.ts +14 -0
  30. package/dist/models/{content/Session.d.ts → Session.d.ts} +7 -15
  31. package/dist/models/Session.js +103 -0
  32. package/dist/models/Term.d.ts +36 -0
  33. package/dist/models/Term.js +82 -0
  34. package/dist/models/User.d.ts +32 -0
  35. package/dist/models/User.js +65 -0
  36. package/dist/models/Workspace.d.ts +37 -0
  37. package/dist/models/Workspace.js +94 -0
  38. package/dist/models/index.d.ts +22 -2
  39. package/dist/models/index.js +22 -2
  40. package/dist/repo/PermissiveJson1.d.ts +16 -16
  41. package/dist/repo/PermissiveJson1.js +17 -7
  42. package/dist/repo/ShareSync.d.ts +6 -6
  43. package/dist/repo/ShareSync.js +26 -19
  44. package/dist/repo/index.d.ts +1 -0
  45. package/dist/repo/index.js +1 -0
  46. package/dist/util/Encryption.d.ts +1 -1
  47. package/dist/util/index.d.ts +0 -6
  48. package/dist/util/index.js +0 -6
  49. package/lib/models/{content/ArrayView.ts → ArrayView.ts} +2 -2
  50. package/lib/models/BayesianScore.ts +32 -0
  51. package/lib/models/{markup/ChangeModel.ts → ChangeModel.ts} +3 -4
  52. package/lib/models/{content/Content.ts → Content.ts} +15 -18
  53. package/lib/models/{content/ContentKind.ts → ContentKind.ts} +6 -1
  54. package/lib/models/{content/Device.ts → Device.ts} +26 -22
  55. package/lib/models/Hanzi.ts +16 -0
  56. package/lib/models/{content/Manifest.ts → Manifest.ts} +15 -6
  57. package/lib/models/{content/Media.ts → Media.ts} +3 -4
  58. package/lib/models/Metric.ts +233 -0
  59. package/lib/models/{content/Model.ts → Model.ts} +4 -6
  60. package/lib/models/{markup/Operation.ts → Operation.ts} +6 -16
  61. package/lib/models/{content/Permissions.ts → Permissions.ts} +0 -2
  62. package/lib/models/Phrase.ts +53 -0
  63. package/lib/models/{content/Profile.ts → Profile.ts} +4 -6
  64. package/lib/models/Progress.ts +66 -0
  65. package/lib/models/Review.ts +18 -0
  66. package/lib/models/Session.ts +140 -0
  67. package/lib/models/Term.ts +139 -0
  68. package/lib/models/User.ts +97 -0
  69. package/lib/models/Workspace.ts +129 -0
  70. package/lib/models/index.ts +22 -2
  71. package/lib/repo/ShareSync.ts +9 -13
  72. package/lib/repo/index.ts +1 -0
  73. package/lib/util/Encryption.ts +1 -1
  74. package/lib/util/index.ts +0 -6
  75. package/package.json +4 -15
  76. package/dist/models/OutboundMessage.d.ts +0 -18
  77. package/dist/models/OutboundMessage.js +0 -25
  78. package/dist/models/content/Activity.d.ts +0 -10
  79. package/dist/models/content/Billing.d.ts +0 -144
  80. package/dist/models/content/Billing.js +0 -418
  81. package/dist/models/content/Book.d.ts +0 -77
  82. package/dist/models/content/Book.js +0 -407
  83. package/dist/models/content/Category.d.ts +0 -16
  84. package/dist/models/content/Category.js +0 -20
  85. package/dist/models/content/Checkpointable.d.ts +0 -21
  86. package/dist/models/content/Checkpointable.js +0 -156
  87. package/dist/models/content/Comment.d.ts +0 -19
  88. package/dist/models/content/Comment.js +0 -53
  89. package/dist/models/content/ConceptArt.d.ts +0 -31
  90. package/dist/models/content/ConceptArt.js +0 -84
  91. package/dist/models/content/Context.d.ts +0 -28
  92. package/dist/models/content/Context.js +0 -162
  93. package/dist/models/content/DevEnv.d.ts +0 -5
  94. package/dist/models/content/DevEnv.js +0 -9
  95. package/dist/models/content/Dictionary.d.ts +0 -31
  96. package/dist/models/content/Dictionary.js +0 -5
  97. package/dist/models/content/DictionaryEntry.d.ts +0 -20
  98. package/dist/models/content/DictionaryEntry.js +0 -2
  99. package/dist/models/content/ElasticModel.d.ts +0 -149
  100. package/dist/models/content/ElasticModel.js +0 -179
  101. package/dist/models/content/Environment.d.ts +0 -61
  102. package/dist/models/content/Environment.js +0 -124
  103. package/dist/models/content/ExportOptions.d.ts +0 -64
  104. package/dist/models/content/ExportOptions.js +0 -213
  105. package/dist/models/content/Folder.d.ts +0 -16
  106. package/dist/models/content/Folder.js +0 -33
  107. package/dist/models/content/Fragment.d.ts +0 -54
  108. package/dist/models/content/Fragment.js +0 -181
  109. package/dist/models/content/Hanzi.d.ts +0 -21
  110. package/dist/models/content/HighlightRule.d.ts +0 -9
  111. package/dist/models/content/HighlightRule.js +0 -2
  112. package/dist/models/content/Migration.d.ts +0 -68
  113. package/dist/models/content/Migration.js +0 -155
  114. package/dist/models/content/Phrase.d.ts +0 -8
  115. package/dist/models/content/Placeholder.d.ts +0 -8
  116. package/dist/models/content/Placeholder.js +0 -36
  117. package/dist/models/content/RichText.d.ts +0 -58
  118. package/dist/models/content/RichText.js +0 -79
  119. package/dist/models/content/Session.js +0 -173
  120. package/dist/models/content/Speech.d.ts +0 -67
  121. package/dist/models/content/Speech.js +0 -97
  122. package/dist/models/content/Stub.d.ts +0 -24
  123. package/dist/models/content/Stub.js +0 -179
  124. package/dist/models/content/Time.d.ts +0 -56
  125. package/dist/models/content/Time.js +0 -295
  126. package/dist/models/content/User.d.ts +0 -36
  127. package/dist/models/content/User.js +0 -95
  128. package/dist/models/content/Workspace.d.ts +0 -71
  129. package/dist/models/content/Workspace.js +0 -237
  130. package/dist/models/content/index.d.ts +0 -17
  131. package/dist/models/content/index.js +0 -34
  132. package/dist/models/legacy/LegacyBodyFormat.d.ts +0 -9
  133. package/dist/models/legacy/LegacyBodyFormat.js +0 -2
  134. package/dist/models/legacy/LegacyComment.d.ts +0 -12
  135. package/dist/models/legacy/LegacyComment.js +0 -2
  136. package/dist/models/legacy/LegacyContent.d.ts +0 -53
  137. package/dist/models/legacy/LegacyContent.js +0 -55
  138. package/dist/models/legacy/LegacyConversion.d.ts +0 -55
  139. package/dist/models/legacy/LegacyConversion.js +0 -401
  140. package/dist/models/legacy/LegacyFragment.d.ts +0 -21
  141. package/dist/models/legacy/LegacyFragment.js +0 -2
  142. package/dist/models/legacy/LegacyLocator.d.ts +0 -8
  143. package/dist/models/legacy/LegacyLocator.js +0 -31
  144. package/dist/models/legacy/LegacyOutboundMessage.d.ts +0 -16
  145. package/dist/models/legacy/LegacyOutboundMessage.js +0 -13
  146. package/dist/models/legacy/LegacyPicture.d.ts +0 -14
  147. package/dist/models/legacy/LegacyPicture.js +0 -2
  148. package/dist/models/legacy/LegacyProfile.d.ts +0 -9
  149. package/dist/models/legacy/LegacyProfile.js +0 -2
  150. package/dist/models/legacy/LegacySession.d.ts +0 -41
  151. package/dist/models/legacy/LegacySession.js +0 -35
  152. package/dist/models/legacy/LegacyStory.d.ts +0 -23
  153. package/dist/models/legacy/LegacyStory.js +0 -2
  154. package/dist/models/legacy/LegacyStub.d.ts +0 -15
  155. package/dist/models/legacy/LegacyStub.js +0 -2
  156. package/dist/models/legacy/LegacyTransaction.d.ts +0 -14
  157. package/dist/models/legacy/LegacyTransaction.js +0 -49
  158. package/dist/models/legacy/LegacyUser.d.ts +0 -28
  159. package/dist/models/legacy/LegacyUser.js +0 -32
  160. package/dist/models/legacy/LegacyWorkspace.d.ts +0 -23
  161. package/dist/models/legacy/LegacyWorkspace.js +0 -6
  162. package/dist/models/legacy/index.d.ts +0 -15
  163. package/dist/models/legacy/index.js +0 -32
  164. package/dist/models/markup/BodyFormat.d.ts +0 -14
  165. package/dist/models/markup/BodyFormat.js +0 -190
  166. package/dist/models/markup/DeltaOps.d.ts +0 -5
  167. package/dist/models/markup/DeltaOps.js +0 -74
  168. package/dist/models/markup/HtmlMarkup.d.ts +0 -4
  169. package/dist/models/markup/HtmlMarkup.js +0 -21
  170. package/dist/models/markup/index.d.ts +0 -4
  171. package/dist/models/markup/index.js +0 -21
  172. package/dist/util/Async.d.ts +0 -8
  173. package/dist/util/Async.js +0 -18
  174. package/dist/util/Base62.d.ts +0 -6
  175. package/dist/util/Base62.js +0 -47
  176. package/dist/util/BinarySearch.d.ts +0 -7
  177. package/dist/util/BinarySearch.js +0 -46
  178. package/dist/util/CachingHasher.d.ts +0 -8
  179. package/dist/util/CachingHasher.js +0 -41
  180. package/dist/util/Color.d.ts +0 -32
  181. package/dist/util/Color.js +0 -204
  182. package/dist/util/Dispatch.d.ts +0 -15
  183. package/dist/util/Dispatch.js +0 -79
  184. package/dist/util/EditDistance.d.ts +0 -13
  185. package/dist/util/EditDistance.js +0 -184
  186. package/dist/util/NumberFormat.d.ts +0 -14
  187. package/dist/util/NumberFormat.js +0 -224
  188. package/dist/util/Struct.d.ts +0 -4
  189. package/dist/util/Struct.js +0 -15
  190. package/dist/util/Template.d.ts +0 -16
  191. package/dist/util/Template.js +0 -128
  192. package/dist/util/Text.d.ts +0 -45
  193. package/dist/util/Text.js +0 -243
  194. package/dist/util/Tuples.d.ts +0 -9
  195. package/dist/util/Tuples.js +0 -135
  196. package/dist/util/Validate.d.ts +0 -4
  197. package/dist/util/Validate.js +0 -11
  198. package/dist/util/Vocabulary.d.ts +0 -3
  199. package/dist/util/Vocabulary.js +0 -35
  200. package/lib/models/content/Billing.ts +0 -558
  201. package/lib/models/content/DevEnv.ts +0 -5
  202. package/lib/models/content/DictionaryEntry.ts +0 -22
  203. package/lib/models/content/Hanzi.ts +0 -25
  204. package/lib/models/content/Phrase.ts +0 -10
  205. package/lib/models/content/Time.ts +0 -328
  206. package/lib/models/content/User.ts +0 -130
  207. package/lib/models/content/index.ts +0 -19
  208. package/lib/models/markup/DeltaOps.ts +0 -71
  209. package/lib/models/markup/index.ts +0 -6
  210. package/lib/util/Base62.ts +0 -47
  211. package/lib/util/CachingHasher.ts +0 -38
  212. package/lib/util/Dispatch.ts +0 -92
  213. package/lib/util/NumberFormat.ts +0 -194
  214. package/lib/util/Struct.ts +0 -14
  215. package/lib/util/Tuples.ts +0 -131
  216. /package/dist/models/{content/GeoLocation.d.ts → GeoLocation.d.ts} +0 -0
  217. /package/dist/models/{content/GeoLocation.js → GeoLocation.js} +0 -0
  218. /package/dist/models/{content/Hanzi.js → Hanzi.js} +0 -0
  219. /package/dist/models/{content/Permissions.d.ts → Permissions.d.ts} +0 -0
  220. /package/dist/models/{content/Permissions.js → Permissions.js} +0 -0
  221. /package/dist/models/{content/Phrase.js → Phrase.js} +0 -0
  222. /package/dist/models/{content/Activity.js → Review.js} +0 -0
  223. /package/dist/{models/markup → repo}/TextEditOps.d.ts +0 -0
  224. /package/dist/{models/markup → repo}/TextEditOps.js +0 -0
  225. /package/lib/models/{content/GeoLocation.ts → GeoLocation.ts} +0 -0
  226. /package/lib/{models/markup → repo}/TextEditOps.ts +0 -0
@@ -1,47 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Base62 = void 0;
4
- class Base62 {
5
- static encode(value, padToLength = 1) {
6
- if (value < 0) {
7
- throw new Error("number out of range: " + value);
8
- }
9
- let result = "";
10
- while (value > 0) {
11
- let index = value % 62;
12
- let digit = Base62.CHARS.charAt(index);
13
- result = digit + result;
14
- value = Math.floor(value / 62);
15
- }
16
- while (result.length < padToLength) {
17
- result = "0" + result;
18
- }
19
- return result;
20
- }
21
- static decode(value) {
22
- let result = 0;
23
- for (let i = 0, len = value.length; i < len; i++) {
24
- let c = value.charAt(i);
25
- result *= 62;
26
- result += Base62.CHARS.indexOf(c);
27
- }
28
- return result;
29
- }
30
- static fromHexHash(hex, length) {
31
- // NOTE: the crazy one-liner below is equivalent to this commented code...
32
- // const b64 = Buffer.from(hex, 'hex').toString('base64');
33
- // ...but it doesn't require Buffer class, which is only available in Node.js, not in browsers.
34
- // This one-liner came from stackoverflow: https://stackoverflow.com/questions/23190056/hex-to-base64-converter-for-javascript
35
- const b64 = btoa(hex.match(/\w{2}/g).map((a) => { return String.fromCharCode(parseInt(a, 16)); }).join(""));
36
- let alphanum = b64.replace(/[^a-zA-Z0-9]/g, "");
37
- if (alphanum.length < length) {
38
- alphanum = alphanum.padEnd(length, "0");
39
- }
40
- else if (alphanum.length > length) {
41
- alphanum = alphanum.substring(0, length);
42
- }
43
- return alphanum;
44
- }
45
- }
46
- exports.Base62 = Base62;
47
- Base62.CHARS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
@@ -1,7 +0,0 @@
1
- import { CompactDateTime } from "../models/content/Time";
2
- import { SpeechMarkItem } from "../models/content/Speech";
3
- export declare class BinarySearch {
4
- static ofDateTimes(value: CompactDateTime, values: CompactDateTime[]): number;
5
- static ofStrings(value: string, values: string[]): number;
6
- static ofSpeechMarks(seekPoint: number, speechMarks: SpeechMarkItem[]): number;
7
- }
@@ -1,46 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BinarySearch = void 0;
4
- class BinarySearch {
5
- static ofDateTimes(value, values) {
6
- return BinarySearch.ofStrings(value, values);
7
- }
8
- static ofStrings(value, values) {
9
- let low = 0;
10
- let high = values.length - 1;
11
- while (low <= high) {
12
- let mid = Math.floor((low + high) / 2);
13
- let midValue = values[mid];
14
- let comparison = midValue.localeCompare(value);
15
- if (comparison < 0) {
16
- low = mid + 1;
17
- }
18
- else if (comparison > 0) {
19
- high = mid - 1;
20
- }
21
- else {
22
- return mid;
23
- }
24
- }
25
- return -(low + 1);
26
- }
27
- static ofSpeechMarks(seekPoint, speechMarks) {
28
- let low = 0;
29
- let high = speechMarks.length - 1;
30
- while (low <= high) {
31
- let mid = Math.floor((low + high) / 2);
32
- let speechMark = speechMarks[mid];
33
- if (speechMark.time < seekPoint) {
34
- low = mid + 1;
35
- }
36
- else if (speechMark.time > seekPoint) {
37
- high = mid - 1;
38
- }
39
- else {
40
- return mid;
41
- }
42
- }
43
- return low - 1;
44
- }
45
- }
46
- exports.BinarySearch = BinarySearch;
@@ -1,8 +0,0 @@
1
- import { ContentId } from '../models/content/Content';
2
- export declare class CachingHasher {
3
- private static readonly MAX_SIZE;
4
- private static md5HashLookup;
5
- private static contentIdLookup;
6
- static makeMd5Hash(text: string): string;
7
- static makeMd5ContentId(text: string): ContentId;
8
- }
@@ -1,41 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.CachingHasher = void 0;
7
- const md5_1 = __importDefault(require("md5"));
8
- const Base62_1 = require("./Base62");
9
- class CachingHasher {
10
- static makeMd5Hash(text) {
11
- if (CachingHasher.md5HashLookup.size > CachingHasher.MAX_SIZE) {
12
- CachingHasher.md5HashLookup.clear();
13
- }
14
- if (CachingHasher.md5HashLookup.has(text)) {
15
- return CachingHasher.md5HashLookup.get(text);
16
- }
17
- else {
18
- const rawHash = (0, md5_1.default)(text);
19
- this.md5HashLookup.set(text, rawHash);
20
- return rawHash;
21
- }
22
- }
23
- static makeMd5ContentId(text) {
24
- if (CachingHasher.contentIdLookup.size > CachingHasher.MAX_SIZE) {
25
- CachingHasher.contentIdLookup.clear();
26
- }
27
- if (CachingHasher.contentIdLookup.has(text)) {
28
- return CachingHasher.contentIdLookup.get(text);
29
- }
30
- else {
31
- const rawHash = (0, md5_1.default)(text);
32
- const asBase62 = Base62_1.Base62.fromHexHash(rawHash, 16);
33
- this.contentIdLookup.set(text, asBase62);
34
- return asBase62;
35
- }
36
- }
37
- }
38
- exports.CachingHasher = CachingHasher;
39
- CachingHasher.MAX_SIZE = 1000;
40
- CachingHasher.md5HashLookup = new Map();
41
- CachingHasher.contentIdLookup = new Map();
@@ -1,32 +0,0 @@
1
- export declare class RGB {
2
- r: number;
3
- g: number;
4
- b: number;
5
- constructor(r: number, g: number, b: number);
6
- toHEX(): string;
7
- toHSV(): HSV;
8
- toHSLUV(): HSLUV;
9
- static parse(color: string): RGB;
10
- }
11
- export declare class HSLUV {
12
- h: number;
13
- s: number;
14
- l: number;
15
- constructor(h: number, s: number, l: number);
16
- toRGB(): RGB;
17
- }
18
- export declare class HSV {
19
- h: number;
20
- s: number;
21
- v: number;
22
- constructor(h: number, s: number, v: number);
23
- toRGB(): RGB;
24
- }
25
- export declare class Color {
26
- private static readonly EPSILON_SATURATION;
27
- static normalize(color: string): string;
28
- static makeShadeOf(color: string, hslOverride: {
29
- [key: string]: number;
30
- }): string;
31
- static interpolate(loColor: string, hiColor: string, steps: number, percent: number): string;
32
- }
@@ -1,204 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Color = exports.HSV = exports.HSLUV = exports.RGB = void 0;
4
- const hsluv_1 = require("hsluv");
5
- const NumberFormat_1 = require("./NumberFormat");
6
- class RGB {
7
- constructor(r, g, b) {
8
- this.r = r;
9
- this.g = g;
10
- this.b = b;
11
- }
12
- toHEX() {
13
- return "#" +
14
- NumberFormat_1.NumberFormat.asHex(this.r, 2) +
15
- NumberFormat_1.NumberFormat.asHex(this.g, 2) +
16
- NumberFormat_1.NumberFormat.asHex(this.b, 2);
17
- }
18
- toHSV() {
19
- let r = this.r;
20
- let g = this.g;
21
- let b = this.b;
22
- let max = Math.max(r, g, b);
23
- let min = Math.min(r, g, b);
24
- let d = max - min;
25
- let h;
26
- switch (max) {
27
- case min:
28
- h = 0;
29
- break;
30
- case r:
31
- h = (g - b) + d * (g < b ? 6 : 0);
32
- h /= 6 * d;
33
- break;
34
- case g:
35
- h = (b - r) + d * 2;
36
- h /= 6 * d;
37
- break;
38
- case b:
39
- h = (r - g) + d * 4;
40
- h /= 6 * d;
41
- break;
42
- }
43
- let s = max === 0 ? 0 : d / max;
44
- let v = max / 255;
45
- return new HSV(h, s, v);
46
- }
47
- toHSLUV() {
48
- const converter = new hsluv_1.Hsluv();
49
- converter.rgb_r = this.r / 255;
50
- converter.rgb_g = this.g / 255;
51
- converter.rgb_b = this.b / 255;
52
- converter.rgbToHsluv();
53
- const h = converter.hsluv_h;
54
- const s = converter.hsluv_s;
55
- const l = converter.hsluv_l;
56
- return new HSLUV(h, s, l);
57
- }
58
- static parse(color) {
59
- // match RGB values formatted as "rgb(12,34,56)" (with optional whitespace)
60
- let match = /^\s*rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)\s*$/i.exec(color);
61
- if (match !== null) {
62
- return new RGB(parseInt(match[1]), parseInt(match[2]), parseInt(match[3]));
63
- }
64
- // match RGB values formatted as "#AABBCC" (with optional #hash prefix)
65
- match = /^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(color);
66
- if (match !== null) {
67
- return new RGB(parseInt(match[1], 16), parseInt(match[2], 16), parseInt(match[3], 16));
68
- }
69
- // match RGB values formatted as "#ABC" (with optional #hash prefix)
70
- match = /^#?([0-9a-f])([0-9a-f])([0-9a-f])$/i.exec(color);
71
- if (match !== null) {
72
- const red = match[1] + match[1];
73
- const grn = match[2] + match[2];
74
- const blu = match[3] + match[3];
75
- return new RGB(parseInt(red, 16), parseInt(grn, 16), parseInt(blu, 16));
76
- }
77
- throw Error("can\x27t parse color: " + color);
78
- }
79
- }
80
- exports.RGB = RGB;
81
- // We get better interpolations by using a perceptually uniform color space...
82
- // https://programmingdesignsystems.com/color/perceptually-uniform-color-spaces/
83
- class HSLUV {
84
- constructor(h, s, l) {
85
- this.h = h;
86
- this.s = s;
87
- this.l = l;
88
- }
89
- toRGB() {
90
- let h = this.h;
91
- let s = this.s;
92
- let l = this.l;
93
- let converter = new hsluv_1.Hsluv();
94
- converter.hsluv_h = h;
95
- converter.hsluv_s = s;
96
- converter.hsluv_l = l;
97
- converter.hsluvToRgb();
98
- let r = Math.round(converter.rgb_r * 255);
99
- let g = Math.round(converter.rgb_g * 255);
100
- let b = Math.round(converter.rgb_b * 255);
101
- return new RGB(r, g, b);
102
- }
103
- }
104
- exports.HSLUV = HSLUV;
105
- class HSV {
106
- constructor(h, s, v) {
107
- this.h = h;
108
- this.s = s;
109
- this.v = v;
110
- }
111
- toRGB() {
112
- let h = this.h;
113
- let s = this.s;
114
- let v = this.v;
115
- let i = Math.floor(h * 6);
116
- let f = h * 6 - i;
117
- let p = v * (1 - s);
118
- let q = v * (1 - f * s);
119
- let t = v * (1 - (1 - f) * s);
120
- let r, g, b;
121
- switch (i % 6) {
122
- case 0:
123
- r = v, g = t, b = p;
124
- break;
125
- case 1:
126
- r = q, g = v, b = p;
127
- break;
128
- case 2:
129
- r = p, g = v, b = t;
130
- break;
131
- case 3:
132
- r = p, g = q, b = v;
133
- break;
134
- case 4:
135
- r = t, g = p, b = v;
136
- break;
137
- case 5:
138
- r = v, g = p, b = q;
139
- break;
140
- }
141
- return new RGB(Math.round(r * 255), Math.round(g * 255), Math.round(b * 255));
142
- }
143
- }
144
- exports.HSV = HSV;
145
- class Color {
146
- static normalize(color) {
147
- let rgb = RGB.parse(color);
148
- return rgb.toHEX();
149
- }
150
- static makeShadeOf(color, hslOverride) {
151
- let rgb = RGB.parse(color);
152
- let hsluv = rgb.toHSLUV();
153
- if (hslOverride.hasOwnProperty("h")) {
154
- hsluv.h = hslOverride.h;
155
- }
156
- if (hslOverride.hasOwnProperty("s")) {
157
- hsluv.s = hslOverride.s;
158
- }
159
- if (hslOverride.hasOwnProperty("l")) {
160
- hsluv.l = hslOverride.l;
161
- }
162
- rgb = hsluv.toRGB();
163
- return rgb.toHEX();
164
- }
165
- static interpolate(loColor, hiColor, steps, percent) {
166
- // NOTE: Unlike HSV (where all 3 values are floats between 0 and 1), the HSLUV color space
167
- // has a hue value between 0 and 360, and saturation and lightness values between 0 and 100.
168
- let loRGB = RGB.parse(loColor);
169
- let hiRGB = RGB.parse(hiColor);
170
- // There's no point interpolating if the number of steps is only 2.
171
- if (steps === 2) {
172
- return percent > 0.5 ? hiRGB.toHEX() : loRGB.toHEX();
173
- }
174
- let loHSLUV = loRGB.toHSLUV();
175
- let hiHSLUV = hiRGB.toHSLUV();
176
- // If one of the colors is completely desaturated, it should share the same hue as the other color
177
- if (loHSLUV.s < Color.EPSILON_SATURATION)
178
- loHSLUV.h = hiHSLUV.h;
179
- if (hiHSLUV.s < Color.EPSILON_SATURATION)
180
- hiHSLUV.h = loHSLUV.h;
181
- let clockwiseDiff = (loHSLUV.h >= hiHSLUV.h) ? 1 + hiHSLUV.h - loHSLUV.h : hiHSLUV.h - loHSLUV.h;
182
- let counterClockwiseDiff = (loHSLUV.h >= hiHSLUV.h) ? loHSLUV.h - hiHSLUV.h : 1 + loHSLUV.h - hiHSLUV.h;
183
- // Quantize the percentage to a certain number of discreet color steps.
184
- // We've already handled 2-step quantization above, and values less than 2
185
- // are ignored because they don't make sense.
186
- if (steps >= 3) {
187
- percent = Math.round(percent * (steps - 1)) / (steps - 1);
188
- }
189
- // Interpolate the values
190
- let h = (clockwiseDiff <= counterClockwiseDiff)
191
- ? loHSLUV.h + (clockwiseDiff * percent)
192
- : loHSLUV.h - (counterClockwiseDiff * percent);
193
- if (h < 0)
194
- h = 360 + h;
195
- if (h > 360)
196
- h = h - 360;
197
- let s = (1 - percent) * loHSLUV.s + percent * hiHSLUV.s;
198
- let l = (1 - percent) * loHSLUV.l + percent * hiHSLUV.l;
199
- let rgb = new HSLUV(h, s, l).toRGB();
200
- return rgb.toHEX();
201
- }
202
- }
203
- exports.Color = Color;
204
- Color.EPSILON_SATURATION = 1.0;
@@ -1,15 +0,0 @@
1
- export type DispatchTopic = string;
2
- export type DispatchCallback = (topic: string, details?: any) => void;
3
- export interface DispatchMessage {
4
- topic: DispatchTopic;
5
- details?: any;
6
- }
7
- export declare class Dispatch {
8
- private static debug;
9
- private static readonly callbacksByTopic;
10
- static setDebug(value: boolean): void;
11
- static subscribe(topic: string, callback: DispatchCallback): void;
12
- static unsubscribe(topic: DispatchTopic, callback: DispatchCallback): void;
13
- static publish(topic: DispatchTopic, details?: any): Promise<void>;
14
- static sequence(messages: DispatchMessage[]): Promise<void>;
15
- }
@@ -1,79 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Dispatch = void 0;
4
- class Dispatch {
5
- static setDebug(value) {
6
- Dispatch.debug = value;
7
- }
8
- static subscribe(topic, callback) {
9
- let topicCallbacks = [];
10
- if (Dispatch.callbacksByTopic.has(topic)) {
11
- topicCallbacks = Dispatch.callbacksByTopic.get(topic);
12
- }
13
- else {
14
- Dispatch.callbacksByTopic.set(topic, topicCallbacks);
15
- }
16
- topicCallbacks.push(callback);
17
- }
18
- static unsubscribe(topic, callback) {
19
- if (Dispatch.callbacksByTopic.has(topic)) {
20
- let topicCallbacks = [];
21
- let newTopicCallbacks = [];
22
- for (let i = 0, len = topicCallbacks.length; i < len; i++) {
23
- let cb = topicCallbacks[i];
24
- if (cb.toString() != callback.toString()) {
25
- newTopicCallbacks.push(callback);
26
- }
27
- }
28
- if (newTopicCallbacks.length == 0) {
29
- Dispatch.callbacksByTopic.delete(topic);
30
- }
31
- else {
32
- Dispatch.callbacksByTopic.set(topic, newTopicCallbacks);
33
- }
34
- }
35
- }
36
- // Calls all the callbacks to this particular topic. Returns a Promise which resolves when ALL
37
- // of the topic callbacks have also resolved, or in the same event loop if they are synchronous.
38
- static async publish(topic, details) {
39
- if (Dispatch.callbacksByTopic.has(topic)) {
40
- let topicCallbackResults = [];
41
- let errors = [];
42
- let subjectSubscribers = Dispatch.callbacksByTopic.get(topic);
43
- if (Dispatch.debug) {
44
- console.log(`Dispatching '${topic}' to ${subjectSubscribers.length} subscribers, with details: ${JSON.stringify(details)}`);
45
- }
46
- for (let i = 0, len = subjectSubscribers.length; i < len; i++) {
47
- let callback = subjectSubscribers[i];
48
- // catch errors here so we don't interrupt any of the other callbacks
49
- let result;
50
- try {
51
- result = callback(topic, details);
52
- topicCallbackResults.push(result);
53
- }
54
- catch (e) {
55
- errors.push(e);
56
- }
57
- }
58
- await Promise.all(topicCallbackResults);
59
- if (errors.length > 0) {
60
- return Promise.reject(errors);
61
- }
62
- return Promise.resolve();
63
- }
64
- else if (Dispatch.debug) {
65
- console.log(`Dispatch has no subscribers to topic '${topic}'`);
66
- }
67
- }
68
- // Fire off a sequence of messages. Waits for the preceding message callbacks to finish / resolve
69
- // before publishing the next (if the first message throws an exception, this short-circuits).
70
- static async sequence(messages) {
71
- for (let i = 0, len = messages.length; i < len; i++) {
72
- let message = messages[i];
73
- await Dispatch.publish(message.topic, message.details);
74
- }
75
- }
76
- }
77
- exports.Dispatch = Dispatch;
78
- Dispatch.debug = false;
79
- Dispatch.callbacksByTopic = new Map();
@@ -1,13 +0,0 @@
1
- export declare class EditDistance {
2
- private static readonly CHARACTERS;
3
- private static readonly FORBIDDEN_START_AND_END_CHARS;
4
- static readonly ALWAYS_TRUE: (word: string) => boolean;
5
- static of(s1: string, s2: string): number;
6
- static permute(word: string, distance: number, predicate?: (word: string) => boolean): string[];
7
- private static preFilterCandidate;
8
- private static generateDeleteCandidates;
9
- private static generateTransposeCandidates;
10
- private static generateReplaceCandidates;
11
- private static generateInsertCandidates;
12
- private static collectCandidateIfPassPredicate;
13
- }
@@ -1,184 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EditDistance = void 0;
4
- const Struct_1 = require("../util/Struct");
5
- class EditDistance {
6
- // This function copied from here:
7
- // https://github.com/gustaveWPM/Typescript-Damerau-Levenshtein/blob/main/damerauLevenshtein.ts
8
- // The algorithm is designed here:
9
- // https://en.wikipedia.org/wiki/Damerau–Levenshtein_distance
10
- static of(s1, s2) {
11
- if (s1 === s2)
12
- return 0;
13
- const [s1len, s2len] = [s1.length, s2.length];
14
- const matrix = Array.from({ length: s1len + 1 }, () => new Array(s2len + 1).fill(0));
15
- for (let y = 1; y <= s1len; y++)
16
- matrix[y][0] = y;
17
- for (let x = 1; x <= s2len; x++)
18
- matrix[0][x] = x;
19
- for (let y = 1; y <= s1len; y++) {
20
- for (let x = 1; x <= s2len; x++) {
21
- if (s1[y - 1] === s2[x - 1]) {
22
- matrix[y][x] = matrix[y - 1][x - 1];
23
- }
24
- else {
25
- matrix[y][x] =
26
- 1 +
27
- Math.min(matrix[y - 1][x], matrix[y][x - 1], matrix[y - 1][x - 1]);
28
- if (y > 1 &&
29
- x > 1 &&
30
- s1[y - 1] === s2[x - 2] &&
31
- s1[y - 2] === s2[x - 1]) {
32
- matrix[y][x] = Math.min(matrix[y][x], matrix[y - 2][x - 2] + 1);
33
- }
34
- }
35
- }
36
- }
37
- return matrix[s1len][s2len];
38
- }
39
- static permute(word, distance, predicate) {
40
- let roots = [word];
41
- let predicateIsFunction = typeof (predicate) === "function";
42
- let useDeferredPredicate = distance > 1 && predicateIsFunction;
43
- let failed = {};
44
- let candidates = {};
45
- while (distance > 0) {
46
- let p = distance > 1 || !predicateIsFunction
47
- ? EditDistance.ALWAYS_TRUE
48
- : predicate;
49
- let lastGenCandidates = Struct_1.Struct.clone(candidates);
50
- for (let i = 0, len = roots.length; i < len; i++) {
51
- word = roots[i];
52
- let wordLength = word.length;
53
- EditDistance.generateDeleteCandidates(failed, candidates, p, word, wordLength);
54
- EditDistance.generateTransposeCandidates(failed, candidates, p, word, wordLength);
55
- EditDistance.generateReplaceCandidates(failed, candidates, p, word, wordLength);
56
- EditDistance.generateInsertCandidates(failed, candidates, p, word, wordLength);
57
- }
58
- distance--;
59
- if (distance === 0) {
60
- if (useDeferredPredicate) {
61
- let confirmedCandidates = {};
62
- for (let candidate in candidates) {
63
- EditDistance.collectCandidateIfPassPredicate(failed, confirmedCandidates, candidate, predicate);
64
- }
65
- candidates = confirmedCandidates;
66
- }
67
- }
68
- else {
69
- roots = [];
70
- for (let candidate in candidates) {
71
- if (!lastGenCandidates.hasOwnProperty(candidate)) {
72
- roots.push(candidate);
73
- }
74
- }
75
- }
76
- }
77
- return Object.keys(candidates);
78
- }
79
- static preFilterCandidate(failed, candidates, candidate, predicate) {
80
- const firstChar = candidate.charAt(0);
81
- const lastChar = candidate.charAt(candidate.length - 1);
82
- if (!EditDistance.FORBIDDEN_START_AND_END_CHARS.includes(firstChar) && !EditDistance.FORBIDDEN_START_AND_END_CHARS.includes(lastChar)) {
83
- EditDistance.collectCandidateIfPassPredicate(failed, candidates, candidate, predicate);
84
- }
85
- }
86
- static generateDeleteCandidates(failed, candidates, predicate, word, len) {
87
- if (len < 2) {
88
- return;
89
- }
90
- let last = len - 1;
91
- for (let i = 0; i < len; i++) {
92
- let candidate;
93
- if (i === 0) {
94
- candidate = word.substring(1);
95
- }
96
- else if (i === last) {
97
- candidate = word.substring(0, last);
98
- }
99
- else {
100
- candidate = word.substring(0, i) + word.substring(i + 1, len);
101
- }
102
- EditDistance.preFilterCandidate(failed, candidates, candidate, predicate);
103
- }
104
- }
105
- static generateTransposeCandidates(failed, candidates, predicate, word, len) {
106
- if (len < 2) {
107
- return;
108
- }
109
- else {
110
- let last = len - 1;
111
- for (let i = 0; i < last; i++) {
112
- let textBefore = i === 0 ? "" : word.substring(0, i);
113
- let a = word.charAt(i);
114
- let b = word.charAt(i + 1);
115
- let textAfter = i === last - 1 ? "" : word.substring(i + 2);
116
- const candidate = textBefore + b + a + textAfter;
117
- EditDistance.preFilterCandidate(failed, candidates, candidate, predicate);
118
- }
119
- }
120
- }
121
- static generateReplaceCandidates(failed, candidates, predicate, word, len) {
122
- if (len < 2) {
123
- return;
124
- }
125
- let last = len - 1;
126
- for (let i = 0; i < len; i++) {
127
- let charToReplace = word.charAt(i);
128
- for (let j = 0, jLen = EditDistance.CHARACTERS.length; j < jLen; j++) {
129
- let c = EditDistance.CHARACTERS[j];
130
- if (c !== charToReplace) {
131
- let candidate;
132
- if (i === 0) {
133
- candidate = c + word.substring(1);
134
- }
135
- else if (i === last) {
136
- candidate = word.substring(0, last) + c;
137
- }
138
- else {
139
- candidate = word.substring(0, i) + c + word.substring(i + 1, len);
140
- }
141
- EditDistance.preFilterCandidate(failed, candidates, candidate, predicate);
142
- }
143
- }
144
- }
145
- }
146
- static generateInsertCandidates(failed, candidates, predicate, word, len) {
147
- for (let j = 0, jLen = EditDistance.CHARACTERS.length; j < jLen; j++) {
148
- let c = EditDistance.CHARACTERS[j];
149
- EditDistance.preFilterCandidate(failed, candidates, c + word, predicate);
150
- for (let i = 1; i < len; i++) {
151
- EditDistance.preFilterCandidate(failed, candidates, word.substring(0, i) + c + word.substring(i, len), predicate);
152
- }
153
- EditDistance.preFilterCandidate(failed, candidates, word + c, predicate);
154
- }
155
- }
156
- static collectCandidateIfPassPredicate(failed, candidates, candidate, predicate) {
157
- // If this candidate has failed, don't bother checking it again.
158
- if (failed.hasOwnProperty(candidate)) {
159
- return;
160
- }
161
- // If we've already collected this candidate, don't collect it again.
162
- if (candidates.hasOwnProperty(candidate)) {
163
- return;
164
- }
165
- if (!predicate(candidate)) {
166
- failed[candidate] = candidate;
167
- return;
168
- }
169
- candidates[candidate] = candidate;
170
- }
171
- }
172
- exports.EditDistance = EditDistance;
173
- // This list of characters is used to generate candidates for the edit distance algorithm.
174
- // These characters exclude numerals, punctuation, and most non-English characters. However,
175
- // this list does include the characters çéñöü becuase they are common in English borrow-words
176
- // like "façade", "café", "jalapeño", and "über". This list also includes the hyphen and
177
- // apostrophe, which are common in English words. This list excludes characters that might
178
- // be common in proper names from non-English cultures, like "á", "í", "ó", "ú", "ý", "ÿ",
179
- // "â", "ê", "î", "ô", "û", so we will sometimes be unable to include those words in
180
- // spelling suggestions.
181
- EditDistance.CHARACTERS = "abcdefghijklmnopqrstuvwxyzçéñöü'-";
182
- // We don't allow words to start or end with a hyphen or apostrophe.
183
- EditDistance.FORBIDDEN_START_AND_END_CHARS = "-'";
184
- EditDistance.ALWAYS_TRUE = function () { return true; };