@omegagrid/core 0.10.2 → 0.10.5
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.
- package/dist/common/actions.d.ts +16 -0
- package/dist/common/actions.d.ts.map +1 -0
- package/dist/common/actions.js +14 -0
- package/dist/common/actions.js.map +1 -0
- package/dist/common/colors.d.ts +39 -0
- package/dist/common/colors.d.ts.map +1 -0
- package/dist/common/colors.js +59 -0
- package/dist/common/colors.js.map +1 -0
- package/dist/common/csv.d.ts +23 -0
- package/dist/common/csv.d.ts.map +1 -0
- package/dist/common/csv.js +93 -0
- package/dist/common/csv.js.map +1 -0
- package/dist/common/dates.d.ts +32 -0
- package/dist/common/dates.d.ts.map +1 -0
- package/dist/common/dates.js +172 -0
- package/dist/common/dates.js.map +1 -0
- package/dist/common/device.d.ts +2 -0
- package/dist/common/device.d.ts.map +1 -0
- package/dist/common/device.js +13 -0
- package/dist/common/device.js.map +1 -0
- package/dist/common/dom.d.ts +90 -0
- package/dist/common/dom.d.ts.map +1 -0
- package/dist/common/dom.js +308 -0
- package/dist/common/dom.js.map +1 -0
- package/dist/common/events.d.ts +15 -0
- package/dist/common/events.d.ts.map +1 -0
- package/dist/common/events.js +33 -0
- package/dist/common/events.js.map +1 -0
- package/dist/common/html.d.ts +3 -0
- package/dist/common/html.d.ts.map +1 -0
- package/dist/common/html.js +25 -0
- package/dist/common/html.js.map +1 -0
- package/dist/common/index.d.ts +19 -0
- package/dist/common/index.d.ts.map +1 -0
- package/dist/common/index.js +19 -0
- package/dist/common/index.js.map +1 -0
- package/dist/common/linkedList.d.ts +24 -0
- package/dist/common/linkedList.d.ts.map +1 -0
- package/dist/common/linkedList.js +65 -0
- package/dist/common/linkedList.js.map +1 -0
- package/dist/common/loaders.d.ts +17 -0
- package/dist/common/loaders.d.ts.map +1 -0
- package/dist/common/loaders.js +54 -0
- package/dist/common/loaders.js.map +1 -0
- package/dist/common/logger.d.ts +25 -0
- package/dist/common/logger.d.ts.map +1 -0
- package/dist/common/logger.js +57 -0
- package/dist/common/logger.js.map +1 -0
- package/dist/common/matrix.d.ts +6 -0
- package/dist/common/matrix.d.ts.map +1 -0
- package/dist/common/matrix.js +17 -0
- package/dist/common/matrix.js.map +1 -0
- package/dist/common/numbers.d.ts +26 -0
- package/dist/common/numbers.d.ts.map +1 -0
- package/dist/common/numbers.js +239 -0
- package/dist/common/numbers.js.map +1 -0
- package/dist/common/options.d.ts +17 -0
- package/dist/common/options.d.ts.map +1 -0
- package/dist/common/options.js +29 -0
- package/dist/common/options.js.map +1 -0
- package/dist/common/paper.d.ts +8 -0
- package/dist/common/paper.d.ts.map +1 -0
- package/dist/common/paper.js +17 -0
- package/dist/common/paper.js.map +1 -0
- package/dist/common/shortcutManager.d.ts +17 -0
- package/dist/common/shortcutManager.d.ts.map +1 -0
- package/dist/common/shortcutManager.js +49 -0
- package/dist/common/shortcutManager.js.map +1 -0
- package/dist/common/tree.d.ts +87 -0
- package/dist/common/tree.d.ts.map +1 -0
- package/dist/common/tree.js +204 -0
- package/dist/common/tree.js.map +1 -0
- package/dist/common/utils.d.ts +30 -0
- package/dist/common/utils.d.ts.map +1 -0
- package/dist/common/utils.js +136 -0
- package/dist/common/utils.js.map +1 -0
- package/dist/constants.d.ts +48 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +24 -0
- package/dist/constants.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/model/adapter.d.ts +8 -0
- package/dist/model/adapter.d.ts.map +1 -0
- package/dist/model/adapter.js +13 -0
- package/dist/model/adapter.js.map +1 -0
- package/dist/model/component.d.ts +19 -0
- package/dist/model/component.d.ts.map +1 -0
- package/dist/model/component.js +84 -0
- package/dist/model/component.js.map +1 -0
- package/dist/model/componentSlice.d.ts +8 -0
- package/dist/model/componentSlice.d.ts.map +1 -0
- package/dist/model/componentSlice.js +10 -0
- package/dist/model/componentSlice.js.map +1 -0
- package/dist/model/componentStore.d.ts +12 -0
- package/dist/model/componentStore.d.ts.map +1 -0
- package/dist/model/componentStore.js +26 -0
- package/dist/model/componentStore.js.map +1 -0
- package/dist/model/index.d.ts +6 -0
- package/dist/model/index.d.ts.map +1 -0
- package/dist/model/index.js +6 -0
- package/dist/model/index.js.map +1 -0
- package/dist/model/plugins.d.ts +13 -0
- package/dist/model/plugins.d.ts.map +1 -0
- package/dist/model/plugins.js +27 -0
- package/dist/model/plugins.js.map +1 -0
- package/dist/themes/definitions/tmDark.d.ts +4 -0
- package/dist/themes/definitions/tmDark.d.ts.map +1 -0
- package/dist/themes/definitions/tmDark.js +83 -0
- package/dist/themes/definitions/tmDark.js.map +1 -0
- package/dist/themes/definitions/tmLight.d.ts +4 -0
- package/dist/themes/definitions/tmLight.d.ts.map +1 -0
- package/dist/themes/definitions/tmLight.js +83 -0
- package/dist/themes/definitions/tmLight.js.map +1 -0
- package/dist/themes/helpers.d.ts +7 -0
- package/dist/themes/helpers.d.ts.map +1 -0
- package/dist/themes/helpers.js +34 -0
- package/dist/themes/helpers.js.map +1 -0
- package/dist/themes/index.d.ts +18 -0
- package/dist/themes/index.d.ts.map +1 -0
- package/dist/themes/index.js +48 -0
- package/dist/themes/index.js.map +1 -0
- package/dist/themes/mixins.d.ts +10 -0
- package/dist/themes/mixins.d.ts.map +1 -0
- package/dist/themes/mixins.js +39 -0
- package/dist/themes/mixins.js.map +1 -0
- package/dist/themes/transformations.d.ts +9 -0
- package/dist/themes/transformations.d.ts.map +1 -0
- package/dist/themes/transformations.js +48 -0
- package/dist/themes/transformations.js.map +1 -0
- package/dist/types.d.ts +130 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +12 -0
- package/dist/types.js.map +1 -0
- package/dist/ui/accordion.d.ts +16 -0
- package/dist/ui/accordion.d.ts.map +1 -0
- package/dist/ui/accordion.js +209 -0
- package/dist/ui/accordion.js.map +1 -0
- package/dist/ui/alert.d.ts +15 -0
- package/dist/ui/alert.d.ts.map +1 -0
- package/dist/ui/alert.js +101 -0
- package/dist/ui/alert.js.map +1 -0
- package/dist/ui/baseElement.d.ts +7 -0
- package/dist/ui/baseElement.d.ts.map +1 -0
- package/dist/ui/baseElement.js +10 -0
- package/dist/ui/baseElement.js.map +1 -0
- package/dist/ui/button.d.ts +21 -0
- package/dist/ui/button.d.ts.map +1 -0
- package/dist/ui/button.js +100 -0
- package/dist/ui/button.js.map +1 -0
- package/dist/ui/button.style.d.ts +2 -0
- package/dist/ui/button.style.d.ts.map +1 -0
- package/dist/ui/button.style.js +60 -0
- package/dist/ui/button.style.js.map +1 -0
- package/dist/ui/checkbox.d.ts +14 -0
- package/dist/ui/checkbox.d.ts.map +1 -0
- package/dist/ui/checkbox.js +47 -0
- package/dist/ui/checkbox.js.map +1 -0
- package/dist/ui/close.d.ts +6 -0
- package/dist/ui/close.d.ts.map +1 -0
- package/dist/ui/close.js +33 -0
- package/dist/ui/close.js.map +1 -0
- package/dist/ui/colorpicker.d.ts +24 -0
- package/dist/ui/colorpicker.d.ts.map +1 -0
- package/dist/ui/colorpicker.js +228 -0
- package/dist/ui/colorpicker.js.map +1 -0
- package/dist/ui/container.d.ts +39 -0
- package/dist/ui/container.d.ts.map +1 -0
- package/dist/ui/container.js +313 -0
- package/dist/ui/container.js.map +1 -0
- package/dist/ui/dropdown.d.ts +48 -0
- package/dist/ui/dropdown.d.ts.map +1 -0
- package/dist/ui/dropdown.js +300 -0
- package/dist/ui/dropdown.js.map +1 -0
- package/dist/ui/dropdownColorPicker.d.ts +12 -0
- package/dist/ui/dropdownColorPicker.d.ts.map +1 -0
- package/dist/ui/dropdownColorPicker.js +60 -0
- package/dist/ui/dropdownColorPicker.js.map +1 -0
- package/dist/ui/dropdownList.d.ts +8 -0
- package/dist/ui/dropdownList.d.ts.map +1 -0
- package/dist/ui/dropdownList.js +48 -0
- package/dist/ui/dropdownList.js.map +1 -0
- package/dist/ui/dropdownMenu.d.ts +11 -0
- package/dist/ui/dropdownMenu.d.ts.map +1 -0
- package/dist/ui/dropdownMenu.js +61 -0
- package/dist/ui/dropdownMenu.js.map +1 -0
- package/dist/ui/expander.d.ts +28 -0
- package/dist/ui/expander.d.ts.map +1 -0
- package/dist/ui/expander.js +144 -0
- package/dist/ui/expander.js.map +1 -0
- package/dist/ui/fileInput.d.ts +24 -0
- package/dist/ui/fileInput.d.ts.map +1 -0
- package/dist/ui/fileInput.js +130 -0
- package/dist/ui/fileInput.js.map +1 -0
- package/dist/ui/fileInput.style.d.ts +2 -0
- package/dist/ui/fileInput.style.d.ts.map +1 -0
- package/dist/ui/fileInput.style.js +73 -0
- package/dist/ui/fileInput.style.js.map +1 -0
- package/dist/ui/floatingWindow.d.ts +19 -0
- package/dist/ui/floatingWindow.d.ts.map +1 -0
- package/dist/ui/floatingWindow.js +87 -0
- package/dist/ui/floatingWindow.js.map +1 -0
- package/dist/ui/icon.d.ts +46 -0
- package/dist/ui/icon.d.ts.map +1 -0
- package/dist/ui/icon.js +189 -0
- package/dist/ui/icon.js.map +1 -0
- package/dist/ui/icon.style.d.ts +2 -0
- package/dist/ui/icon.style.d.ts.map +1 -0
- package/dist/ui/icon.style.js +556 -0
- package/dist/ui/icon.style.js.map +1 -0
- package/dist/ui/images.d.ts +2 -0
- package/dist/ui/images.d.ts.map +1 -0
- package/dist/ui/images.js +14 -0
- package/dist/ui/images.js.map +1 -0
- package/dist/ui/index.d.ts +32 -0
- package/dist/ui/index.d.ts.map +1 -0
- package/dist/ui/index.js +32 -0
- package/dist/ui/index.js.map +1 -0
- package/dist/ui/input.d.ts +12 -0
- package/dist/ui/input.d.ts.map +1 -0
- package/dist/ui/input.js +45 -0
- package/dist/ui/input.js.map +1 -0
- package/dist/ui/input.style.d.ts +2 -0
- package/dist/ui/input.style.d.ts.map +1 -0
- package/dist/ui/input.style.js +36 -0
- package/dist/ui/input.style.js.map +1 -0
- package/dist/ui/label.d.ts +16 -0
- package/dist/ui/label.d.ts.map +1 -0
- package/dist/ui/label.js +90 -0
- package/dist/ui/label.js.map +1 -0
- package/dist/ui/list.d.ts +87 -0
- package/dist/ui/list.d.ts.map +1 -0
- package/dist/ui/list.js +427 -0
- package/dist/ui/list.js.map +1 -0
- package/dist/ui/list.style.d.ts +2 -0
- package/dist/ui/list.style.d.ts.map +1 -0
- package/dist/ui/list.style.js +35 -0
- package/dist/ui/list.style.js.map +1 -0
- package/dist/ui/loader.d.ts +6 -0
- package/dist/ui/loader.d.ts.map +1 -0
- package/dist/ui/loader.js +25 -0
- package/dist/ui/loader.js.map +1 -0
- package/dist/ui/menu.d.ts +41 -0
- package/dist/ui/menu.d.ts.map +1 -0
- package/dist/ui/menu.js +154 -0
- package/dist/ui/menu.js.map +1 -0
- package/dist/ui/menu.style.d.ts +3 -0
- package/dist/ui/menu.style.d.ts.map +1 -0
- package/dist/ui/menu.style.js +50 -0
- package/dist/ui/menu.style.js.map +1 -0
- package/dist/ui/numericInput.d.ts +37 -0
- package/dist/ui/numericInput.d.ts.map +1 -0
- package/dist/ui/numericInput.js +175 -0
- package/dist/ui/numericInput.js.map +1 -0
- package/dist/ui/numericInput.style.d.ts +2 -0
- package/dist/ui/numericInput.style.d.ts.map +1 -0
- package/dist/ui/numericInput.style.js +29 -0
- package/dist/ui/numericInput.style.js.map +1 -0
- package/dist/ui/overlay.d.ts +17 -0
- package/dist/ui/overlay.d.ts.map +1 -0
- package/dist/ui/overlay.js +87 -0
- package/dist/ui/overlay.js.map +1 -0
- package/dist/ui/overlay.style.d.ts +2 -0
- package/dist/ui/overlay.style.d.ts.map +1 -0
- package/dist/ui/overlay.style.js +46 -0
- package/dist/ui/overlay.style.js.map +1 -0
- package/dist/ui/panel.d.ts +25 -0
- package/dist/ui/panel.d.ts.map +1 -0
- package/dist/ui/panel.js +151 -0
- package/dist/ui/panel.js.map +1 -0
- package/dist/ui/panel.style.d.ts +2 -0
- package/dist/ui/panel.style.d.ts.map +1 -0
- package/dist/ui/panel.style.js +73 -0
- package/dist/ui/panel.style.js.map +1 -0
- package/dist/ui/sizer.d.ts +57 -0
- package/dist/ui/sizer.d.ts.map +1 -0
- package/dist/ui/sizer.js +224 -0
- package/dist/ui/sizer.js.map +1 -0
- package/dist/ui/slider.d.ts +52 -0
- package/dist/ui/slider.d.ts.map +1 -0
- package/dist/ui/slider.js +213 -0
- package/dist/ui/slider.js.map +1 -0
- package/dist/ui/slider.style.d.ts +2 -0
- package/dist/ui/slider.style.d.ts.map +1 -0
- package/dist/ui/slider.style.js +61 -0
- package/dist/ui/slider.style.js.map +1 -0
- package/dist/ui/sortableList.d.ts +39 -0
- package/dist/ui/sortableList.d.ts.map +1 -0
- package/dist/ui/sortableList.js +167 -0
- package/dist/ui/sortableList.js.map +1 -0
- package/dist/ui/splitContainer.d.ts +52 -0
- package/dist/ui/splitContainer.d.ts.map +1 -0
- package/dist/ui/splitContainer.js +252 -0
- package/dist/ui/splitContainer.js.map +1 -0
- package/dist/ui/splitContainer.style.d.ts +2 -0
- package/dist/ui/splitContainer.style.d.ts.map +1 -0
- package/dist/ui/splitContainer.style.js +62 -0
- package/dist/ui/splitContainer.style.js.map +1 -0
- package/dist/ui/switch.d.ts +22 -0
- package/dist/ui/switch.d.ts.map +1 -0
- package/dist/ui/switch.js +83 -0
- package/dist/ui/switch.js.map +1 -0
- package/dist/ui/switch.style.d.ts +2 -0
- package/dist/ui/switch.style.d.ts.map +1 -0
- package/dist/ui/switch.style.js +149 -0
- package/dist/ui/switch.style.js.map +1 -0
- package/dist/ui/tooltip.d.ts +24 -0
- package/dist/ui/tooltip.d.ts.map +1 -0
- package/dist/ui/tooltip.js +143 -0
- package/dist/ui/tooltip.js.map +1 -0
- package/dist/ui/tooltip.style.d.ts +2 -0
- package/dist/ui/tooltip.style.d.ts.map +1 -0
- package/dist/ui/tooltip.style.js +112 -0
- package/dist/ui/tooltip.style.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
export class LinkedListNode {
|
|
2
|
+
constructor(data) {
|
|
3
|
+
this.data = data;
|
|
4
|
+
this.next = null;
|
|
5
|
+
this.prev = null;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export class LinkedList {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.head = null;
|
|
11
|
+
}
|
|
12
|
+
insertAtEnd(data) {
|
|
13
|
+
const node = new LinkedListNode(data);
|
|
14
|
+
if (!this.head)
|
|
15
|
+
this.head = node;
|
|
16
|
+
else {
|
|
17
|
+
const getLast = (node) => node.next ? getLast(node.next) : node;
|
|
18
|
+
const lastNode = getLast(this.head);
|
|
19
|
+
node.prev = lastNode;
|
|
20
|
+
lastNode.next = node;
|
|
21
|
+
}
|
|
22
|
+
return node;
|
|
23
|
+
}
|
|
24
|
+
insertInBegin(data) {
|
|
25
|
+
const node = new LinkedListNode(data);
|
|
26
|
+
if (!this.head)
|
|
27
|
+
this.head = node;
|
|
28
|
+
else {
|
|
29
|
+
this.head.prev = node;
|
|
30
|
+
node.next = this.head;
|
|
31
|
+
this.head = node;
|
|
32
|
+
}
|
|
33
|
+
return node;
|
|
34
|
+
}
|
|
35
|
+
deleteNode(node) {
|
|
36
|
+
if (!node.prev)
|
|
37
|
+
this.head = node.next;
|
|
38
|
+
else {
|
|
39
|
+
const prevNode = node.prev;
|
|
40
|
+
prevNode.next = node.next;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
search(comparator) {
|
|
44
|
+
const checkNext = (node) => {
|
|
45
|
+
if (comparator(node.data))
|
|
46
|
+
return node;
|
|
47
|
+
return node.next ? checkNext(node.next) : null;
|
|
48
|
+
};
|
|
49
|
+
return this.head ? checkNext(this.head) : null;
|
|
50
|
+
}
|
|
51
|
+
traverse() {
|
|
52
|
+
const array = [];
|
|
53
|
+
if (!this.head)
|
|
54
|
+
return array;
|
|
55
|
+
const addToArray = (node) => {
|
|
56
|
+
array.push(node.data);
|
|
57
|
+
return node.next ? addToArray(node.next) : array;
|
|
58
|
+
};
|
|
59
|
+
return addToArray(this.head);
|
|
60
|
+
}
|
|
61
|
+
size() {
|
|
62
|
+
return this.traverse().length;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=linkedList.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"linkedList.js","sourceRoot":"","sources":["../../src/common/linkedList.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,cAAc;IAG1B,YAAmB,IAAO;QAAP,SAAI,GAAJ,IAAI,CAAG;QAFnB,SAAI,GAA6B,IAAI,CAAC;QACtC,SAAI,GAA6B,IAAI,CAAC;IAChB,CAAC;CAC9B;AAWD,MAAM,OAAO,UAAU;IAAvB;QACS,SAAI,GAA6B,IAAI,CAAC;IAsD/C,CAAC;IApDO,WAAW,CAAC,IAAO;QACzB,MAAM,IAAI,GAAG,IAAI,cAAc,CAAC,IAAI,CAAC,CAAC;QACtC,IAAI,CAAC,IAAI,CAAC,IAAI;YAAE,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;aAC5B,CAAC;YACL,MAAM,OAAO,GAAG,CAAC,IAAuB,EAAqB,EAAE,CAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;YACvG,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACpC,IAAI,CAAC,IAAI,GAAG,QAAQ,CAAC;YACrB,QAAQ,CAAC,IAAI,GAAG,IAAI,CAAC;QACtB,CAAC;QACD,OAAO,IAAI,CAAC;IACb,CAAC;IAEM,aAAa,CAAC,IAAO;QAC3B,MAAM,IAAI,GAAG,IAAI,cAAc,CAAC,IAAI,CAAC,CAAC;QACtC,IAAI,CAAC,IAAI,CAAC,IAAI;YAAE,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;aAC5B,CAAC;YACL,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;YAC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I;QACV,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAC,MAAM,CAAC;IAC/B,CAAC;CACD","sourcesContent":["export class LinkedListNode<T> {\n\tpublic next: LinkedListNode<T> | null = null;\n\tpublic prev: LinkedListNode<T> | null = null;\n\tconstructor(public data: T) {}\n}\n\nexport interface ILinkedList<T> {\n\tinsertInBegin(data: T): LinkedListNode<T>;\n\tinsertAtEnd(data: T): LinkedListNode<T>;\n\tdeleteNode(node: LinkedListNode<T>): void;\n\ttraverse(): T[];\n\tsize(): number;\n\tsearch(comparator: (data: T) => boolean): LinkedListNode<T> | null;\n}\n\nexport class LinkedList<T> implements ILinkedList<T> {\n\tprivate head: LinkedListNode<T> | null = null;\n\t\n\tpublic insertAtEnd(data: T): LinkedListNode<T> {\n\t\tconst node = new LinkedListNode(data);\n\t\tif (!this.head) this.head = node;\n\t\telse {\n\t\t\tconst getLast = (node: LinkedListNode<T>): LinkedListNode<T> => node.next ? getLast(node.next) : node;\n\t\t\tconst lastNode = getLast(this.head);\n\t\t\tnode.prev = lastNode;\n\t\t\tlastNode.next = node;\n\t\t}\n\t\treturn node;\n\t}\n\t\n\tpublic insertInBegin(data: T): LinkedListNode<T> {\n\t\tconst node = new LinkedListNode(data);\n\t\tif (!this.head) this.head = node;\n\t\telse {\n\t\t\tthis.head.prev = node;\n\t\t\tnode.next = this.head;\n\t\t\tthis.head = node;\n\t\t}\n\t\treturn node;\n\t}\n\t\n\tpublic deleteNode(node: LinkedListNode<T>): void {\n\t\tif (!node.prev) this.head = node.next;\n\t\telse {\n\t\t\tconst prevNode = node.prev;\n\t\t\tprevNode.next = node.next;\n\t\t}\n\t}\n\t\n\tpublic search(comparator: (data: T) => boolean): LinkedListNode<T> | null {\n\t\tconst checkNext = (node: LinkedListNode<T>): LinkedListNode<T> | null => {\n\t\t\tif (comparator(node.data)) return node;\n\t\t\treturn node.next ? checkNext(node.next) : null;\n\t\t};\n\t\treturn this.head ? checkNext(this.head) : null;\n\t}\n\t\n\tpublic traverse(): T[] {\n\t\tconst array: T[] = [];\n\t\tif (!this.head) return array;\n\t\tconst addToArray = (node: LinkedListNode<T>): T[] => {\n\t\t\tarray.push(node.data);\n\t\t\treturn node.next ? addToArray(node.next) : array;\n\t\t};\n\t\treturn addToArray(this.head);\n\t}\n\t\n\tpublic size(): number {\n\t\treturn this.traverse().length;\n\t}\n}"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface Require {
|
|
2
|
+
(paths: string[], callback?: () => void): void;
|
|
3
|
+
config: (options: {
|
|
4
|
+
[key: string]: unknown;
|
|
5
|
+
}) => void;
|
|
6
|
+
}
|
|
7
|
+
export declare class AMD {
|
|
8
|
+
static require: Require;
|
|
9
|
+
}
|
|
10
|
+
export declare class ScriptLoader {
|
|
11
|
+
#private;
|
|
12
|
+
static scripts: Map<string, boolean>;
|
|
13
|
+
static load(url: string, doc?: Document & {
|
|
14
|
+
__ogid?: string;
|
|
15
|
+
}): Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=loaders.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loaders.d.ts","sourceRoot":"","sources":["../../src/common/loaders.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,OAAO;IACvB,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,QAAQ,CAAC,EAAE,MAAM,IAAI,GAAG,IAAI,CAAC;IAC/C,MAAM,EAAE,CAAC,OAAO,EAAE;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAC,KAAK,IAAI,CAAC;CACpD;AAED,qBAAa,GAAG;IACf,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC;CACxB;AAED,qBAAa,YAAY;;IAExB,MAAM,CAAC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;WAGxB,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,QAAQ,GAAG;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAC;CAqCjE"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
2
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
3
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
4
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
|
+
};
|
|
6
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
7
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
10
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
11
|
+
};
|
|
12
|
+
var _a, _ScriptLoader_resolutions;
|
|
13
|
+
import { isString } from "./utils";
|
|
14
|
+
export class AMD {
|
|
15
|
+
}
|
|
16
|
+
export class ScriptLoader {
|
|
17
|
+
static async load(url, doc) {
|
|
18
|
+
doc = doc || document;
|
|
19
|
+
let id = doc.__ogid;
|
|
20
|
+
if (!id) {
|
|
21
|
+
id = Math.random().toString(36).slice(2);
|
|
22
|
+
doc.__ogid = id;
|
|
23
|
+
}
|
|
24
|
+
const urlId = `${id}-${url}`;
|
|
25
|
+
if (!__classPrivateFieldGet(this, _a, "f", _ScriptLoader_resolutions))
|
|
26
|
+
__classPrivateFieldSet(this, _a, new Map(), "f", _ScriptLoader_resolutions);
|
|
27
|
+
if (!this.scripts)
|
|
28
|
+
this.scripts = new Map();
|
|
29
|
+
if (this.scripts.has(urlId))
|
|
30
|
+
return;
|
|
31
|
+
return new Promise((resolve, reject) => {
|
|
32
|
+
const resolutions = __classPrivateFieldGet(this, _a, "f", _ScriptLoader_resolutions).get(urlId) || [];
|
|
33
|
+
resolutions.push([resolve, reject]);
|
|
34
|
+
__classPrivateFieldGet(this, _a, "f", _ScriptLoader_resolutions).set(urlId, resolutions);
|
|
35
|
+
if (resolutions.length > 1)
|
|
36
|
+
return;
|
|
37
|
+
const script = doc.createElement('script');
|
|
38
|
+
script.src = url;
|
|
39
|
+
script.onload = () => {
|
|
40
|
+
__classPrivateFieldGet(this, _a, "f", _ScriptLoader_resolutions).get(urlId).forEach(([resolve]) => resolve());
|
|
41
|
+
__classPrivateFieldGet(this, _a, "f", _ScriptLoader_resolutions).delete(urlId);
|
|
42
|
+
};
|
|
43
|
+
script.onerror = (error) => {
|
|
44
|
+
const err = isString(error) ? new Error(error) : error;
|
|
45
|
+
__classPrivateFieldGet(this, _a, "f", _ScriptLoader_resolutions).get(urlId).forEach(([_, reject]) => reject(err));
|
|
46
|
+
__classPrivateFieldGet(this, _a, "f", _ScriptLoader_resolutions).delete(urlId);
|
|
47
|
+
};
|
|
48
|
+
doc.head.appendChild(script);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
_a = ScriptLoader;
|
|
53
|
+
_ScriptLoader_resolutions = { value: void 0 };
|
|
54
|
+
//# sourceMappingURL=loaders.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loaders.js","sourceRoot":"","sources":["../../src/common/loaders.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAOnC,MAAM,OAAO,GAAG;CAEf;AAED,MAAM,OAAO,YAAY;IAKxB,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,GAAW,EAAE,GAAkC;QAChE,GAAG,GAAG,GAAG,IAAI,QAAQ,CAAC;QACtB,IAAI,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC;QACpB,IAAI,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YACjC,CAAC,CAAA;YACD,MAAM,CAAC,OAAO,GAAG,CAAC,KAAK,EAAE,EAAE;gBAC1B,MAAM,GAAG,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,KAAe,CAAC,CAAC,CAAC,CAAE,KAA0B,CAAC;gBACvF,uBAAA,IAAI,qCAAa,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;gBACnE,uBAAA,IAAI,qCAAa,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACjC,CAAC,CAAC;YACF,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QAC9B,CAAC,CAAC,CAAC;IACJ,CAAC;CAGD;;AAvCO,6CAAY,CAAkD","sourcesContent":["import { isString } from \"./utils\";\n\nexport interface Require {\n\t(paths: string[], callback?: () => void): void;\n\tconfig: (options: {[key: string]: unknown}) => void;\n}\n\nexport class AMD {\n\tstatic require: Require;\n}\n\nexport class ScriptLoader {\n\n\tstatic scripts: Map<string, boolean>;\n\tstatic #resolutions: Map<string, [() => void, (e: Error) => void][]>;\n\n\tstatic async load(url: string, doc?: Document & {__ogid?: string}) {\n\t\tdoc = doc || document;\n\t\tlet id = doc.__ogid;\n\t\tif (!id) {\n\t\t\tid = Math.random().toString(36).slice(2);\n\t\t\tdoc.__ogid = id;\n\t\t}\n\n\t\tconst urlId = `${id}-${url}`;\n\n\t\tif (!this.#resolutions) this.#resolutions = new Map();\n\t\tif (!this.scripts) this.scripts = new Map();\n\t\tif (this.scripts.has(urlId)) return;\n\n\t\treturn new Promise<void>((resolve, reject) => {\n\t\t\tconst resolutions = this.#resolutions.get(urlId) || [];\n\t\t\tresolutions.push([resolve, reject]);\n\t\t\tthis.#resolutions.set(urlId, resolutions);\n\n\t\t\tif (resolutions.length > 1) return;\n\n\t\t\tconst script = doc.createElement('script');\n\t\t\tscript.src = url;\n\t\t\tscript.onload = () => {\n\t\t\t\tthis.#resolutions.get(urlId).forEach(([resolve]) => resolve());\n\t\t\t\tthis.#resolutions.delete(urlId);\n\t\t\t}\n\t\t\tscript.onerror = (error) => {\n\t\t\t\tconst err = isString(error) ? new Error(error as string) : (error as unknown as Error);\n\t\t\t\tthis.#resolutions.get(urlId).forEach(([_, reject]) => reject(err));\n\t\t\t\tthis.#resolutions.delete(urlId);\n\t\t\t};\n\t\t\tdoc.head.appendChild(script);\n\t\t});\n\t}\n\n\n}"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export declare enum LogLevel {
|
|
2
|
+
Info = "i",
|
|
3
|
+
Warn = "w",
|
|
4
|
+
Error = "e",
|
|
5
|
+
Debug = "d",
|
|
6
|
+
Trace = "t"
|
|
7
|
+
}
|
|
8
|
+
export declare class Logger {
|
|
9
|
+
readonly id: string;
|
|
10
|
+
readonly name?: string;
|
|
11
|
+
styles: string[];
|
|
12
|
+
errorStyles: string[];
|
|
13
|
+
defaultLevel: LogLevel;
|
|
14
|
+
constructor(id: string, name?: string);
|
|
15
|
+
private format;
|
|
16
|
+
log(message: string): void;
|
|
17
|
+
info(message: string): void;
|
|
18
|
+
warn(message: string): void;
|
|
19
|
+
error(message: string, exception?: Error): void;
|
|
20
|
+
debug(message: string): void;
|
|
21
|
+
trace(message: string): void;
|
|
22
|
+
}
|
|
23
|
+
export declare function registerLogger(id: string, name?: string): Logger;
|
|
24
|
+
export declare function getLogger(id?: string): Logger;
|
|
25
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/common/logger.ts"],"names":[],"mappings":"AAAA,oBAAY,QAAQ;IACnB,IAAI,MAAM;IACV,IAAI,MAAM;IACV,KAAK,MAAM;IACX,KAAK,MAAM;IACX,KAAK,MAAM;CACX;AAED,qBAAa,MAAM;IAOjB,QAAQ,CAAC,EAAE,EAAE,MAAM;IACnB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM;IANhB,MAAM,WAA0D;IAChE,WAAW,WAA0D;IACrE,YAAY,WAAiB;gBAG1B,EAAE,EAAE,MAAM,EACV,IAAI,CAAC,EAAE,MAAM;IAKvB,OAAO,CAAC,MAAM;IAIP,GAAG,CAAC,OAAO,EAAE,MAAM;IAInB,IAAI,CAAC,OAAO,EAAE,MAAM;IAIpB,IAAI,CAAC,OAAO,EAAE,MAAM;IAIpB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,KAAK;IAKxC,KAAK,CAAC,OAAO,EAAE,MAAM;IAIrB,KAAK,CAAC,OAAO,EAAE,MAAM;CAI5B;AAID,wBAAgB,cAAc,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAKhE;AAED,wBAAgB,SAAS,CAAC,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAM7C"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export var LogLevel;
|
|
2
|
+
(function (LogLevel) {
|
|
3
|
+
LogLevel["Info"] = "i";
|
|
4
|
+
LogLevel["Warn"] = "w";
|
|
5
|
+
LogLevel["Error"] = "e";
|
|
6
|
+
LogLevel["Debug"] = "d";
|
|
7
|
+
LogLevel["Trace"] = "t";
|
|
8
|
+
})(LogLevel || (LogLevel = {}));
|
|
9
|
+
export class Logger {
|
|
10
|
+
constructor(id, name) {
|
|
11
|
+
this.id = id;
|
|
12
|
+
this.name = name;
|
|
13
|
+
this.styles = ['color: #ffff00', 'color: #00955d', 'color: #aaaaaa'];
|
|
14
|
+
this.errorStyles = ['color: #ff0000', 'color: #00955d', 'color: #aaaaaa'];
|
|
15
|
+
this.defaultLevel = LogLevel.Info;
|
|
16
|
+
this.name = name || id;
|
|
17
|
+
}
|
|
18
|
+
format(message, level) {
|
|
19
|
+
return `%c[${level}] %c${this.name.padEnd(20, ' ')} %c${message.padEnd(50, ' ')}`;
|
|
20
|
+
}
|
|
21
|
+
log(message) {
|
|
22
|
+
console.log(message, ...this.styles);
|
|
23
|
+
}
|
|
24
|
+
info(message) {
|
|
25
|
+
console.info(this.format(message, LogLevel.Info), ...this.styles);
|
|
26
|
+
}
|
|
27
|
+
warn(message) {
|
|
28
|
+
console.info(this.format(message, LogLevel.Warn), ...this.styles);
|
|
29
|
+
}
|
|
30
|
+
error(message, exception) {
|
|
31
|
+
console.error(this.format(message, LogLevel.Error), ...this.errorStyles);
|
|
32
|
+
if (exception)
|
|
33
|
+
console.error(exception);
|
|
34
|
+
}
|
|
35
|
+
debug(message) {
|
|
36
|
+
console.info(this.format(message, LogLevel.Debug), ...this.styles);
|
|
37
|
+
}
|
|
38
|
+
trace(message) {
|
|
39
|
+
console.trace(this.format(message, LogLevel.Trace), ...this.styles);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const staticLoggers = new Map();
|
|
43
|
+
export function registerLogger(id, name) {
|
|
44
|
+
if (!staticLoggers.has(id)) {
|
|
45
|
+
staticLoggers.set(id, new Logger(id, name));
|
|
46
|
+
}
|
|
47
|
+
return staticLoggers.get(id);
|
|
48
|
+
}
|
|
49
|
+
export function getLogger(id) {
|
|
50
|
+
if (id == null) {
|
|
51
|
+
id = (staticLoggers.size > 0 ? Array.from(staticLoggers.keys())[0] : null);
|
|
52
|
+
if (id == null)
|
|
53
|
+
return registerLogger('omega', 'Ω');
|
|
54
|
+
}
|
|
55
|
+
return registerLogger(id);
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/common/logger.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,QAMX;AAND,WAAY,QAAQ;IACnB,sBAAU,CAAA;IACV,sBAAU,CAAA;IACV,uBAAW,CAAA;IACX,uBA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um LogLevel {\n\tInfo = 'i',\n\tWarn = 'w',\n\tError = 'e',\n\tDebug = 'd',\n\tTrace = 't'\n}\n\nexport class Logger {\n\n\tpublic styles = ['color: #ffff00', 'color: #00955d', 'color: #aaaaaa'];\n\tpublic errorStyles = ['color: #ff0000', 'color: #00955d', 'color: #aaaaaa'];\n\tpublic defaultLevel = LogLevel.Info;\n\n\tconstructor(\n\t\treadonly id: string,\n\t\treadonly name?: string\n\t) {\n\t\tthis.name = name || id;\n\t}\n\n\tprivate format(message: string, level: LogLevel) : string {\n\t\treturn `%c[${level}] %c${this.name.padEnd(20, ' ')} %c${message.padEnd(50, ' ')}`;\n\t}\n\n\tpublic log(message: string) {\n\t\tconsole.log(message, ...this.styles);\n\t}\n\n\tpublic info(message: string) {\n\t\tconsole.info(this.format(message, LogLevel.Info), ...this.styles);\n\t}\n\n\tpublic warn(message: string) {\n\t\tconsole.info(this.format(message, LogLevel.Warn), ...this.styles);\n\t}\n\n\tpublic error(message: string, exception?: Error) {\n\t\tconsole.error(this.format(message, LogLevel.Error), ...this.errorStyles);\n\t\tif (exception) console.error(exception);\n\t}\n\n\tpublic debug(message: string) {\n\t\tconsole.info(this.format(message, LogLevel.Debug), ...this.styles);\n\t}\n\n\tpublic trace(message: string) {\n\t\tconsole.trace(this.format(message, LogLevel.Trace), ...this.styles);\n\t}\n\t\n}\n\nconst staticLoggers = new Map<string, Logger>();\n\nexport function registerLogger(id: string, name?: string): Logger {\n\tif (!staticLoggers.has(id)) {\n\t\tstaticLoggers.set(id, new Logger(id, name));\n\t}\n\treturn staticLoggers.get(id);\n}\n\nexport function getLogger(id?: string): Logger {\n\tif (id == null) {\n\t\tid = (staticLoggers.size > 0 ? Array.from(staticLoggers.keys())[0] : null);\n\t\tif (id == null) return registerLogger('omega', 'Ω');\n\t}\n\treturn registerLogger(id);\n}"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Matrix } from "../types";
|
|
2
|
+
export declare function reverseColumns<T>(m: Matrix<T>): T[][];
|
|
3
|
+
export declare function reverseRows<T>(m: Matrix<T>): T[][];
|
|
4
|
+
export declare function transpose<T>(m: Matrix<T>): Matrix<T>;
|
|
5
|
+
export declare function clone<T>(m: Matrix<T>): T[][];
|
|
6
|
+
//# sourceMappingURL=matrix.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matrix.d.ts","sourceRoot":"","sources":["../../src/common/matrix.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,wBAAgB,cAAc,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,SAE7C;AAED,wBAAgB,WAAW,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,SAE1C;AAED,wBAAgB,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,aAMxC;AAED,wBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,SAEpC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export function reverseColumns(m) {
|
|
2
|
+
return m.map(v => [...v].reverse());
|
|
3
|
+
}
|
|
4
|
+
export function reverseRows(m) {
|
|
5
|
+
return m.map(v => [...v]).reverse();
|
|
6
|
+
}
|
|
7
|
+
export function transpose(m) {
|
|
8
|
+
const t = Array(m[0].length).fill(null).map(() => Array(m.length));
|
|
9
|
+
for (let i = 0; i < m.length; i++)
|
|
10
|
+
for (let j = 0; j < m[i].length; j++)
|
|
11
|
+
t[j][i] = m[i][j];
|
|
12
|
+
return t;
|
|
13
|
+
}
|
|
14
|
+
export function clone(m) {
|
|
15
|
+
return m.map(v => [...v]);
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=matrix.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matrix.js","sourceRoot":"","sources":["../../src/common/matrix.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,cAAc,CAAI,CAAY;IAC7C,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;AACrC,CAAC;AAED,MAAM,UAAU,WAAW,CAAI,CAAY;IAC1C,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;AACrC,CAAC;AAED,MAAM,UAAU,SAAS,CAAI,CAAY;IACxC,MAAM,CAAC,GAAc,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;IAC9E,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE;QAChC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE;YACnC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACpB,OAAO,CAAC,CAAC;AACV,CAAC;AAED,MAAM,UAAU,KAAK,CAAI,CAAY;IACpC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AAC3B,CAAC","sourcesContent":["import { Matrix } from \"../types\";\n\nexport function reverseColumns<T>(m: Matrix<T>) {\n\treturn m.map(v => [...v].reverse());\n}\n\nexport function reverseRows<T>(m: Matrix<T>) {\n\treturn m.map(v => [...v]).reverse();\n}\n\nexport function transpose<T>(m: Matrix<T>) {\n\tconst t: Matrix<T> = Array(m[0].length).fill(null).map(() => Array(m.length));\n\tfor (let i = 0; i < m.length; i++)\n\t\tfor (let j = 0; j < m[i].length; j++)\n\t\t\tt[j][i] = m[i][j];\n\treturn t;\n}\n\nexport function clone<T>(m: Matrix<T>) {\n\treturn m.map(v => [...v]);\n}"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { DecimalSeparator, LocaleId, ValueFormatter } from "../types";
|
|
2
|
+
export type NumberFormatOptions = {
|
|
3
|
+
/** number color */
|
|
4
|
+
color?: string;
|
|
5
|
+
/** unit of measure */
|
|
6
|
+
text?: string;
|
|
7
|
+
/** Sign display method. */
|
|
8
|
+
signDisplay?: 'auto' | 'never' | 'always' | 'exceptZero' | 'negative';
|
|
9
|
+
/** display brackets for negative values */
|
|
10
|
+
brackets?: boolean;
|
|
11
|
+
/** empty string format */
|
|
12
|
+
empty?: boolean;
|
|
13
|
+
} & Intl.NumberFormatOptions;
|
|
14
|
+
export type NumberFormatterFunction = ValueFormatter<number>;
|
|
15
|
+
export type NumberFormatString = string;
|
|
16
|
+
export declare const isExtendedNumberFormat: (options: NumberFormatOptions) => string | boolean;
|
|
17
|
+
export declare function mod(n: number, d: number): number;
|
|
18
|
+
export declare function romanize(num: number): string | number;
|
|
19
|
+
export declare function isNumberFormat(format: string): boolean;
|
|
20
|
+
export declare function getNumberFormatter(locale: LocaleId, format?: NumberFormatString, fixFormat?: boolean): NumberFormatterFunction;
|
|
21
|
+
export declare function createNumberFormatter(locale: LocaleId, format?: NumberFormatString, fixFormat?: boolean): NumberFormatterFunction;
|
|
22
|
+
export declare function stringFormatToNumberFormat(xlFormat: NumberFormatString): (string | NumberFormatOptions)[];
|
|
23
|
+
export type FormatType = 'd' | 'n';
|
|
24
|
+
export declare function fixNumberFormat(format: string, type: FormatType): string;
|
|
25
|
+
export declare function getLocalDecimalSeparator(locale: LocaleId): DecimalSeparator;
|
|
26
|
+
//# sourceMappingURL=numbers.d.ts.map
|
|
@@ -0,0 +1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GAAG,GAAC,GAAG,CAAC;AAMjC,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,UAG/D;AAED,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,QAAQ,GAI5B,gBAAgB,CAC5C"}
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { getDateFormatter } from "./dates";
|
|
2
|
+
import { isObject, isCharLetter, isString, isNumber } from "./utils";
|
|
3
|
+
export const isExtendedNumberFormat = (options) => {
|
|
4
|
+
return options.text || options.color || options.brackets || options.empty;
|
|
5
|
+
};
|
|
6
|
+
export function mod(n, d) {
|
|
7
|
+
let r = n % d;
|
|
8
|
+
if (r < 0)
|
|
9
|
+
r += Math.abs(d);
|
|
10
|
+
return r;
|
|
11
|
+
}
|
|
12
|
+
const ROMAN_KEYS = [
|
|
13
|
+
"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM",
|
|
14
|
+
"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC",
|
|
15
|
+
"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"
|
|
16
|
+
];
|
|
17
|
+
export function romanize(num) {
|
|
18
|
+
if (isNaN(num))
|
|
19
|
+
return NaN;
|
|
20
|
+
const digits = String(+num).split("");
|
|
21
|
+
let roman = "";
|
|
22
|
+
let i = 3;
|
|
23
|
+
while (i--)
|
|
24
|
+
roman = (ROMAN_KEYS[+digits.pop() + (i * 10)] || "") + roman;
|
|
25
|
+
return Array(+digits.join("") + 1).join("M") + roman;
|
|
26
|
+
}
|
|
27
|
+
export function isNumberFormat(format) {
|
|
28
|
+
return ['0', '#'].includes(format[0]);
|
|
29
|
+
}
|
|
30
|
+
const formatterMap = new Map();
|
|
31
|
+
export function getNumberFormatter(locale, format = '', fixFormat) {
|
|
32
|
+
const map = formatterMap.has(locale) ? formatterMap.get(locale) : formatterMap.set(locale, new Map()).get(locale);
|
|
33
|
+
if (!map.has(format))
|
|
34
|
+
map.set(format, createNumberFormatter(locale, format, fixFormat));
|
|
35
|
+
return map.get(format);
|
|
36
|
+
}
|
|
37
|
+
function createExtendedNumberFormatter(locale, format) {
|
|
38
|
+
const formatter = new Intl.NumberFormat(locale, format);
|
|
39
|
+
return { format: (value) => {
|
|
40
|
+
let str = isNumber(value) ? formatter.format(value) : '';
|
|
41
|
+
if (format.text)
|
|
42
|
+
str += (format.text || '');
|
|
43
|
+
if (format.brackets)
|
|
44
|
+
str = `(${str})`;
|
|
45
|
+
if (format.color)
|
|
46
|
+
str = `<span style="color:${format.color}">${str}</span>`;
|
|
47
|
+
return str;
|
|
48
|
+
} };
|
|
49
|
+
}
|
|
50
|
+
export function createNumberFormatter(locale, format = '', fixFormat) {
|
|
51
|
+
const formats = (format ? stringFormatToNumberFormat(fixFormat ? fixNumberFormat(format, 'n') : format) : [{ maximumFractionDigits: 3 }]);
|
|
52
|
+
const formatters = formats.map(options => {
|
|
53
|
+
if (isObject(options)) {
|
|
54
|
+
if ((isExtendedNumberFormat(options))) {
|
|
55
|
+
return createExtendedNumberFormatter(locale, options);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
return new Intl.NumberFormat(locale, options);
|
|
59
|
+
// const f = new Intl.NumberFormat(locale, options as NumberFormatOptions);
|
|
60
|
+
// return {format: (value: number) => {
|
|
61
|
+
// console.log(value);
|
|
62
|
+
// return isNumber(value) ? f.format(value) : null;
|
|
63
|
+
// }};
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
return { format: getDateFormatter(locale, options) };
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
if (formatters.length == 1)
|
|
71
|
+
formatters.push(formatters[0]);
|
|
72
|
+
if (formatters.length == 2)
|
|
73
|
+
formatters.push(formatters[0]);
|
|
74
|
+
const formatter = (value) => {
|
|
75
|
+
if (value == null)
|
|
76
|
+
return '';
|
|
77
|
+
// string format
|
|
78
|
+
if (isString(value))
|
|
79
|
+
return formatters[3] ? formatters[3].format(value) : value;
|
|
80
|
+
// positive format
|
|
81
|
+
if (isNaN(value))
|
|
82
|
+
return '#NaN';
|
|
83
|
+
// positive format
|
|
84
|
+
if (value > 0)
|
|
85
|
+
return formatters[0].format(value);
|
|
86
|
+
// negative format
|
|
87
|
+
if (value < 0)
|
|
88
|
+
return formatters[1].format(value);
|
|
89
|
+
// zero format
|
|
90
|
+
if (value == 0)
|
|
91
|
+
return formatters[2].format(value);
|
|
92
|
+
};
|
|
93
|
+
return formatter;
|
|
94
|
+
}
|
|
95
|
+
const DEFAULT_NUMBER_FORMAT = {
|
|
96
|
+
useGrouping: false,
|
|
97
|
+
maximumFractionDigits: 0,
|
|
98
|
+
// https://caniuse.com/mdn-javascript_builtins_intl_numberformat_numberformat_options_parameter_options_signdisplay_parameter_negative
|
|
99
|
+
signDisplay: 'negative',
|
|
100
|
+
empty: true
|
|
101
|
+
};
|
|
102
|
+
export function stringFormatToNumberFormat(xlFormat) {
|
|
103
|
+
const formats = [];
|
|
104
|
+
let format = Object.assign({}, DEFAULT_NUMBER_FORMAT);
|
|
105
|
+
let inFraction = false;
|
|
106
|
+
let offset = 0, ch, min, max;
|
|
107
|
+
while (offset < xlFormat.length) {
|
|
108
|
+
ch = xlFormat.charAt(offset);
|
|
109
|
+
if (ch != ';' && format.empty)
|
|
110
|
+
delete format.empty;
|
|
111
|
+
switch (ch.toLowerCase()) {
|
|
112
|
+
case '(':
|
|
113
|
+
format.brackets = true;
|
|
114
|
+
++offset;
|
|
115
|
+
break;
|
|
116
|
+
case '[':
|
|
117
|
+
format.color = '';
|
|
118
|
+
while (++offset < xlFormat.length) {
|
|
119
|
+
ch = xlFormat.charAt(offset);
|
|
120
|
+
if (ch === ']')
|
|
121
|
+
break;
|
|
122
|
+
format.color += ch;
|
|
123
|
+
}
|
|
124
|
+
break;
|
|
125
|
+
case ';':
|
|
126
|
+
formats.push(format);
|
|
127
|
+
format = Object.assign({}, DEFAULT_NUMBER_FORMAT);
|
|
128
|
+
if (formats.length == 1)
|
|
129
|
+
format.signDisplay = 'never';
|
|
130
|
+
inFraction = false;
|
|
131
|
+
++offset;
|
|
132
|
+
break;
|
|
133
|
+
case '0':
|
|
134
|
+
case '#':
|
|
135
|
+
min = null;
|
|
136
|
+
max = null;
|
|
137
|
+
while (offset < xlFormat.length) {
|
|
138
|
+
ch = xlFormat.charAt(offset);
|
|
139
|
+
if (ch === '0')
|
|
140
|
+
min = min === null ? 1 : (min + 1);
|
|
141
|
+
else if (ch === '#')
|
|
142
|
+
max = max === null ? 1 : (max + 1);
|
|
143
|
+
else if (ch === ',')
|
|
144
|
+
format.useGrouping = true;
|
|
145
|
+
else
|
|
146
|
+
break;
|
|
147
|
+
++offset;
|
|
148
|
+
}
|
|
149
|
+
if (inFraction) {
|
|
150
|
+
if (min !== null) {
|
|
151
|
+
format.minimumFractionDigits = min;
|
|
152
|
+
if (max == null)
|
|
153
|
+
format.maximumFractionDigits = min;
|
|
154
|
+
}
|
|
155
|
+
if (max !== null)
|
|
156
|
+
format.maximumFractionDigits = (max + (min || 0));
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
if (min !== null)
|
|
160
|
+
format.minimumIntegerDigits = min;
|
|
161
|
+
}
|
|
162
|
+
break;
|
|
163
|
+
case '"':
|
|
164
|
+
format.text = '';
|
|
165
|
+
while (++offset < xlFormat.length) {
|
|
166
|
+
ch = xlFormat.charAt(offset);
|
|
167
|
+
if (ch === '"')
|
|
168
|
+
break;
|
|
169
|
+
format.text += ch;
|
|
170
|
+
}
|
|
171
|
+
++offset;
|
|
172
|
+
break;
|
|
173
|
+
case '.':
|
|
174
|
+
inFraction = true;
|
|
175
|
+
++offset;
|
|
176
|
+
break;
|
|
177
|
+
case '+':
|
|
178
|
+
format.signDisplay = 'exceptZero';
|
|
179
|
+
++offset;
|
|
180
|
+
break;
|
|
181
|
+
case '-':
|
|
182
|
+
if (formats.length == 1)
|
|
183
|
+
format.signDisplay = 'always';
|
|
184
|
+
++offset;
|
|
185
|
+
break;
|
|
186
|
+
case '$':
|
|
187
|
+
format.style = 'currency';
|
|
188
|
+
++offset;
|
|
189
|
+
break;
|
|
190
|
+
case '%':
|
|
191
|
+
format.style = 'percent';
|
|
192
|
+
++offset;
|
|
193
|
+
break;
|
|
194
|
+
default:
|
|
195
|
+
if (isCharLetter(ch)) {
|
|
196
|
+
let dateFormat = ch;
|
|
197
|
+
format = null;
|
|
198
|
+
while (++offset < xlFormat.length) {
|
|
199
|
+
ch = xlFormat.charAt(offset);
|
|
200
|
+
if (ch === ';') {
|
|
201
|
+
format = Object.assign({}, DEFAULT_NUMBER_FORMAT);
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
else
|
|
205
|
+
dateFormat += ch;
|
|
206
|
+
}
|
|
207
|
+
formats.push(dateFormat);
|
|
208
|
+
}
|
|
209
|
+
++offset;
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
if (format)
|
|
214
|
+
formats.push(format);
|
|
215
|
+
return formats;
|
|
216
|
+
}
|
|
217
|
+
const dateFormatReplaces = [
|
|
218
|
+
[/\\/g, ''],
|
|
219
|
+
[/m/g, 'M'],
|
|
220
|
+
[/ddd/g, 'eee']
|
|
221
|
+
];
|
|
222
|
+
const numberFormatReplaces = [
|
|
223
|
+
[/0,/g, '#,']
|
|
224
|
+
];
|
|
225
|
+
const formatReplaces = {
|
|
226
|
+
'd': dateFormatReplaces,
|
|
227
|
+
'n': numberFormatReplaces
|
|
228
|
+
};
|
|
229
|
+
export function fixNumberFormat(format, type) {
|
|
230
|
+
formatReplaces[type].forEach(([regex, s]) => format = format.replace(regex, s));
|
|
231
|
+
return format;
|
|
232
|
+
}
|
|
233
|
+
export function getLocalDecimalSeparator(locale) {
|
|
234
|
+
return Intl.NumberFormat(locale, {
|
|
235
|
+
minimumIntegerDigits: 1,
|
|
236
|
+
minimumFractionDigits: 1
|
|
237
|
+
}).format(1.1).charAt(1);
|
|
238
|
+
}
|
|
239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E,CAAC;oBACvB,CAAC;oBACD,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;gBAC1B,CAAC;gBACD,EAAE,MAAM,CAAC;gBACT,MAAM;QACR,CAAC;IACF,CAAC;IAED,IAAI,MAAM;QAAE,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACjC,OAAO,OAAO,CAAC;AAChB,CAAC;AAGD,MAAM,kBAAkB,GAAuB;IAC9C,CAAC,KAAK,EAAE,EAAE,CAAC;IACX,CAAC,IAAI,EAAE,GAAG,CAAC;IACX,CAAC,MAAM,EAAE,KAAK,CAAC;CACf,CAAC;AAEF,MAAM,oBAAoB,GAAuB;IAChD,CAAC,KAAK,EAAE,IAAI,CAAC;CACb,CAAC;AAGF,MAAM,cAAc,GAAkD;IACrE,GAAG,EAAE,kBAAkB;IACvB,GAAG,EAAE,oBAAoB;CACzB,CAAC;AAEF,MAAM,UAAU,eAAe,CAAC,MAAc,EAAE,IAAgB;IAC/D,cAAc,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;IAChF,OAAO,MAAM,CAAC;AACf,CAAC;AAED,MAAM,UAAU,wBAAwB,CAAC,MAAgB;IACxD,OAAO,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE;QAChC,oBAAoB,EAAE,CAAC;QACvB,qBAAqB,EAAE,CAAC;KACxB,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAqB,CAAC;AAC9C,CAAC","sourcesContent":["import { getDateFormatter } from \"./dates\";\nimport { DecimalSeparator, LocaleId, ValueFormatter } from \"../types\";\nimport { isObject, isCharLetter, isString, isNumber } from \"./utils\";\n\nexport type NumberFormatOptions = {\n\t/** number color */\n\tcolor?: string,\n\t/** unit of measure */\n\ttext?: string,\n\t/** Sign display method. */\n\tsignDisplay?: 'auto'|'never'|'always'|'exceptZero'|'negative',\n\t/** display brackets for negative values */\n\tbrackets?: boolean,\n\t/** empty string format */\n\tempty?: boolean,\n} & Intl.NumberFormatOptions;\nexport type NumberFormatterFunction = ValueFormatter<number>;\nexport type NumberFormatString = string;\n\nexport const isExtendedNumberFormat = (options: NumberFormatOptions) => {\n\treturn options.text || options.color || options.brackets || options.empty \n};\n\nexport function mod(n: number, d: number) {\n\tlet r = n % d;\n\tif (r < 0) r += Math.abs(d);\n\treturn r;\n}\n\nconst ROMAN_KEYS = [\n\t\"\",\"C\",\"CC\",\"CCC\",\"CD\",\"D\",\"DC\",\"DCC\",\"DCCC\",\"CM\",\n\t\"\",\"X\",\"XX\",\"XXX\",\"XL\",\"L\",\"LX\",\"LXX\",\"LXXX\",\"XC\",\n\t\"\",\"I\",\"II\",\"III\",\"IV\",\"V\",\"VI\",\"VII\",\"VIII\",\"IX\"\n];\n\nexport function romanize(num: number) {\n\tif (isNaN(num)) return NaN;\n\tconst digits = String(+num).split(\"\");\n let roman = \"\";\n\tlet i = 3;\n while (i--) roman = (ROMAN_KEYS[+digits.pop() + (i * 10)] || \"\") + roman;\n return Array(+digits.join(\"\") + 1).join(\"M\") + roman;\n}\n\nexport function isNumberFormat(format: string) {\n\treturn ['0', '#'].includes(format[0]);\n}\n\nconst formatterMap = new Map<LocaleId, Map<NumberFormatString, NumberFormatterFunction>>();\n\nexport function getNumberFormatter(locale: LocaleId, format: NumberFormatString = '', fixFormat?: boolean) : NumberFormatterFunction {\n\tconst map = formatterMap.has(locale) ? formatterMap.get(locale) : formatterMap.set(locale, new Map()).get(locale);\n\tif (!map.has(format)) map.set(format, createNumberFormatter(locale, format, fixFormat));\n\treturn map.get(format);\n}\n\n\nfunction createExtendedNumberFormatter(locale: LocaleId, format: NumberFormatOptions) {\n\tconst formatter = new Intl.NumberFormat(locale, format);\n\treturn {format: (value: number) => {\n\t\tlet str = isNumber(value) ? formatter.format(value) : '';\n\t\tif (format.text) str += (format.text || '');\n\t\tif (format.brackets) str = `(${str})`;\n\t\tif (format.color) str = `<span style=\"color:${format.color}\">${str}</span>`;\n\t\treturn str;\n\t}};\n}\n\nexport function createNumberFormatter(locale: LocaleId, format: NumberFormatString = '', fixFormat?: boolean) : NumberFormatterFunction {\n\tconst formats = (format ? stringFormatToNumberFormat(fixFormat ? fixNumberFormat(format, 'n') : format) : [{maximumFractionDigits: 3}]);\n\n\tconst formatters = formats.map(options => {\n\t\tif (isObject(options)) {\n\t\t\tif ((isExtendedNumberFormat(options as NumberFormatOptions))) {\n\t\t\t\treturn createExtendedNumberFormatter(locale, options as NumberFormatOptions);\n\t\t\t} else {\n\t\t\t\treturn new Intl.NumberFormat(locale, options as NumberFormatOptions);\n\t\t\t\t// const f = new Intl.NumberFormat(locale, options as NumberFormatOptions);\n\t\t\t\t// return {format: (value: number) => {\n\t\t\t\t// \tconsole.log(value);\n\t\t\t\t// \treturn isNumber(value) ? f.format(value) : null;\n\t\t\t\t// }};\n\t\t\t}\n\t\t} else {\n\t\t\treturn {format: getDateFormatter(locale, options as string)}\n\t\t}\n\t});\n\n\tif (formatters.length == 1) formatters.push(formatters[0]);\n\tif (formatters.length == 2) formatters.push(formatters[0]);\n\t\n\tconst formatter = (value: number|string) => {\n\t\tif (value == null) return '';\n\n\t\t// string format\n\t\tif (isString(value)) return formatters[3] ? formatters[3].format(value as unknown as number) : (value as string);\n\n\t\t// positive format\n\t\tif (isNaN(value as number)) return '#NaN';\n\n\t\t// positive format\n\t\tif (value as number > 0) return formatters[0].format(value as number);\n\n\t\t// negative format\n\t\tif (value as number < 0) return formatters[1].format(value as number);\n\n\t\t// zero format\n\t\tif (value == 0) return formatters[2].format(value);\n\t};\n\n\treturn formatter;\n}\n\nconst DEFAULT_NUMBER_FORMAT: NumberFormatOptions = {\n\tuseGrouping: false,\n\tmaximumFractionDigits: 0,\n\t// https://caniuse.com/mdn-javascript_builtins_intl_numberformat_numberformat_options_parameter_options_signdisplay_parameter_negative\n\tsignDisplay: 'negative',\n\tempty: true\n} as unknown as NumberFormatOptions;\n\nexport function stringFormatToNumberFormat(xlFormat: NumberFormatString) {\n\tconst formats: (NumberFormatOptions|string)[] = [];\n\tlet format: NumberFormatOptions = Object.assign({}, DEFAULT_NUMBER_FORMAT);\n\tlet inFraction = false;\n\tlet offset = 0, ch: string, min: number, max: number;\n\twhile (offset < xlFormat.length) {\n\t\tch = xlFormat.charAt(offset);\n\t\tif (ch != ';' && format.empty) delete format.empty;\n\t\t\n\t\tswitch (ch.toLowerCase()) {\n\t\t\tcase '(':\n\t\t\t\tformat.brackets = true;\n\t\t\t\t++offset;\n\t\t\t\tbreak;\n\t\t\tcase '[':\n\t\t\t\tformat.color = '';\n\t\t\t\twhile (++offset < xlFormat.length) {\n\t\t\t\t\tch = xlFormat.charAt(offset);\n\t\t\t\t\tif (ch === ']') break;\n\t\t\t\t\tformat.color += ch;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase ';':\n\t\t\t\tformats.push(format);\n\t\t\t\tformat = Object.assign({}, DEFAULT_NUMBER_FORMAT);\n\t\t\t\tif (formats.length == 1) format.signDisplay = 'never';\n\t\t\t\tinFraction = false;\n\t\t\t\t++offset;\n\t\t\t\tbreak;\n\t\t\tcase '0':\n\t\t\tcase '#':\n\t\t\t\tmin = null;\n\t\t\t\tmax = null;\n\t\t\t\twhile (offset < xlFormat.length) {\n\t\t\t\t\tch = xlFormat.charAt(offset);\n\t\t\t\t\tif (ch === '0') min = min === null ? 1 : (min + 1);\n\t\t\t\t\telse if (ch === '#') max = max === null ? 1 : (max + 1);\n\t\t\t\t\telse if (ch === ',') format.useGrouping = true;\n\t\t\t\t\telse break;\n\t\t\t\t\t++offset;\n\t\t\t\t}\n\t\t\t\tif (inFraction) {\n\t\t\t\t\tif (min !== null) {\n\t\t\t\t\t\tformat.minimumFractionDigits = min;\n\t\t\t\t\t\tif (max == null) format.maximumFractionDigits = min;\n\t\t\t\t\t}\n\t\t\t\t\tif (max !== null) format.maximumFractionDigits = (max + (min || 0));\n\t\t\t\t} else {\n\t\t\t\t\tif (min !== null) format.minimumIntegerDigits = min;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase '\"':\n\t\t\t\tformat.text = '';\n\t\t\t\twhile (++offset < xlFormat.length) {\n\t\t\t\t\tch = xlFormat.charAt(offset);\n\t\t\t\t\tif (ch === '\"') break;\n\t\t\t\t\tformat.text += ch;\n\t\t\t\t}\n\t\t\t\t++offset;\n\t\t\t\tbreak;\n\t\t\tcase '.':\n\t\t\t\tinFraction = true;\n\t\t\t\t++offset;\n\t\t\t\tbreak;\n\t\t\tcase '+':\n\t\t\t\tformat.signDisplay = 'exceptZero';\n\t\t\t\t++offset;\n\t\t\t\tbreak;\n\t\t\tcase '-':\n\t\t\t\tif (formats.length == 1) format.signDisplay = 'always';\n\t\t\t\t++offset;\n\t\t\t\tbreak;\n\t\t\tcase '$':\n\t\t\t\tformat.style = 'currency';\n\t\t\t\t++offset;\n\t\t\t\tbreak;\n\t\t\tcase '%':\n\t\t\t\tformat.style = 'percent';\n\t\t\t\t++offset;\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tif (isCharLetter(ch)) {\n\t\t\t\t\tlet dateFormat = ch;\n\t\t\t\t\tformat = null;\n\t\t\t\t\twhile (++offset < xlFormat.length) {\n\t\t\t\t\t\tch = xlFormat.charAt(offset);\n\t\t\t\t\t\tif (ch === ';') {\n\t\t\t\t\t\t\tformat = Object.assign({}, DEFAULT_NUMBER_FORMAT);\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse dateFormat += ch;\n\t\t\t\t\t}\n\t\t\t\t\tformats.push(dateFormat);\n\t\t\t\t}\n\t\t\t\t++offset;\n\t\t\t\tbreak;\n\t\t}\n\t}\n\t\n\tif (format) formats.push(format);\n\treturn formats;\n}\n\n\nconst dateFormatReplaces: [RegExp, string][] = [\n\t[/\\\\/g, ''],\n\t[/m/g, 'M'],\n\t[/ddd/g, 'eee']\n];\n\nconst numberFormatReplaces: [RegExp, string][] = [\n\t[/0,/g, '#,']\n];\n\nexport type FormatType = 'd'|'n';\nconst formatReplaces: Record<FormatType, typeof dateFormatReplaces> = {\n\t'd': dateFormatReplaces,\n\t'n': numberFormatReplaces\n};\n\nexport function fixNumberFormat(format: string, type: FormatType) {\n\tformatReplaces[type].forEach(([regex, s]) => format = format.replace(regex, s));\n\treturn format;\n}\n\nexport function getLocalDecimalSeparator(locale: LocaleId) {\n\treturn Intl.NumberFormat(locale, {\n\t\tminimumIntegerDigits: 1,\n\t\tminimumFractionDigits: 1\n\t}).format(1.1).charAt(1) as DecimalSeparator;\n}\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { DecimalSeparator, User } from "../types";
|
|
2
|
+
import { DateFormatString, DateFormatterFunction } from "./dates";
|
|
3
|
+
export type Options = {
|
|
4
|
+
/** formatting, numbers, dates, etc */
|
|
5
|
+
formatLocale?: string;
|
|
6
|
+
/** translation */
|
|
7
|
+
locale?: string;
|
|
8
|
+
dateFormat?: DateFormatString;
|
|
9
|
+
dateFormatter?: DateFormatterFunction;
|
|
10
|
+
systemDecimalSeparator?: DecimalSeparator;
|
|
11
|
+
fontSize?: number;
|
|
12
|
+
user?: User;
|
|
13
|
+
};
|
|
14
|
+
export declare const setDefaultOptions: (options: Partial<Options>) => void;
|
|
15
|
+
export declare const getDefaultOptions: () => Partial<Options>;
|
|
16
|
+
export declare function initOptions<T extends Partial<Options>>(options?: T, origOptions?: T): T;
|
|
17
|
+
//# sourceMappingURL=options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../src/common/options.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,EAAuB,gBAAgB,EAAE,qBAAqB,EAAiB,MAAM,SAAS,CAAC;AAKtG,MAAM,MAAM,OAAO,GAAG;IACrB,sCAAsC;IACtC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,kBAAkB;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,gBAAgB,CAAC;IAC9B,aAAa,CAAC,EAAE,qBAAqB,CAAC;IACtC,sBAAsB,CAAC,EAAE,gBAAgB,CAAC;IAC1C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,IAAI,CAAA;CACX,CAAA;AAID,eAAO,MAAM,iBAAiB,GAAI,SAAS,OAAO,CAAC,OAAO,CAAC,SAG1D,CAAA;AAED,eAAO,MAAM,iBAAiB,QAAO,OAAO,CAAC,OAAO,CAUlC,CAAC;AAEnB,wBAAgB,WAAW,CAAC,CAAC,SAAS,OAAO,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,EAAE,CAAC,EAAE,WAAW,GAAE,CAAQ,GAAG,CAAC,CAK7F"}
|