dtable-ui-component 0.1.75-beta1 → 0.1.75-beta5

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 (227) hide show
  1. package/lib/AutoNumberFormatter/index.css +1 -0
  2. package/{es/components/cell-formatter/auto-number-formatter.js → lib/AutoNumberFormatter/index.js} +1 -0
  3. package/lib/ButtonFormatter/index.css +13 -0
  4. package/{es/components/cell-formatter/button-formatter.js → lib/ButtonFormatter/index.js} +1 -0
  5. package/lib/CTimeFormatter/index.css +1 -0
  6. package/{es/components/cell-formatter/ctime-formatter.js → lib/CTimeFormatter/index.js} +1 -0
  7. package/lib/CheckboxFormatter/index.css +1 -0
  8. package/{es/components/cell-formatter/checkbox-formatter.js → lib/CheckboxFormatter/index.js} +1 -0
  9. package/lib/CollaboratorFormatter/index.css +1 -0
  10. package/{es/components/cell-formatter/collaborator-formatter.js → lib/CollaboratorFormatter/index.js} +3 -2
  11. package/lib/CollaboratorItem/index.css +49 -0
  12. package/{es/components/common/collaborator-item.js → lib/CollaboratorItem/index.js} +1 -0
  13. package/lib/CreatorFormatter/index.css +1 -0
  14. package/{es/components/cell-formatter/creator-formatter.js → lib/CreatorFormatter/index.js} +3 -2
  15. package/lib/DateFormatter/index.css +1 -0
  16. package/{es/components/cell-formatter/date-formatter.js → lib/DateFormatter/index.js} +2 -1
  17. package/lib/DurationFormatter/index.css +1 -0
  18. package/{es/components/cell-formatter/duration-formatter.js → lib/DurationFormatter/index.js} +2 -1
  19. package/lib/EmailFormatter/index.css +5 -0
  20. package/{es/components/cell-formatter/email-formatter.js → lib/EmailFormatter/index.js} +1 -0
  21. package/lib/FileFormatter/index.css +29 -0
  22. package/{es/components/cell-formatter/file-formatter.js → lib/FileFormatter/index.js} +2 -1
  23. package/{es/components/cell-formatter/widgets/file-item-formatter.js → lib/FileItemFormatter/index.js} +3 -2
  24. package/{es/components/file-uploader → lib/FileUploader}/index.js +0 -0
  25. package/lib/FormulaFormatter/index.css +19 -0
  26. package/{es/components/cell-formatter/formula-formatter.js → lib/FormulaFormatter/index.js} +8 -8
  27. package/lib/GeolocationFormatter/index.css +1 -0
  28. package/{es/components/cell-formatter/geolocation-formatter.js → lib/GeolocationFormatter/index.js} +2 -1
  29. package/{es/components/common → lib/ImageFormatter}/images-lazy-load.js +2 -2
  30. package/lib/ImageFormatter/index.css +34 -0
  31. package/{es/components/cell-formatter/image-formatter.js → lib/ImageFormatter/index.js} +4 -3
  32. package/{es/css/image-previewer-ligntbox.css → lib/ImagePreviewerLightbox/index.css} +0 -0
  33. package/{es/components/cell-formatter/widgets/image-previewer-lightbox.js → lib/ImagePreviewerLightbox/index.js} +3 -3
  34. package/lib/LastModifierFormatter/index.css +1 -0
  35. package/{es/components/cell-formatter/last-modifier-formatter.js → lib/LastModifierFormatter/index.js} +5 -4
  36. package/lib/LinkFormatter/index.css +27 -0
  37. package/{es/components/cell-formatter/link-formatter.js → lib/LinkFormatter/index.js} +2 -2
  38. package/{es/css/loading.css → lib/Loading/index.css} +0 -0
  39. package/{es/components/loading.js → lib/Loading/index.js} +1 -1
  40. package/{es/components/cell-formatter/widgets/long-text-formatter → lib/LongTextFormatter}/html-long-text-formatter.js +1 -1
  41. package/lib/LongTextFormatter/index.css +63 -0
  42. package/{es/components/cell-formatter/long-text-formatter.js → lib/LongTextFormatter/index.js} +3 -2
  43. package/{es/components/cell-formatter/widgets/long-text-formatter → lib/LongTextFormatter}/simple-long-text-formatter.js +1 -1
  44. package/lib/MTimeFormatter/index.css +1 -0
  45. package/{es/components/cell-formatter/mtime-formatter.js → lib/MTimeFormatter/index.js} +1 -0
  46. package/{es/components/common/modal-portal.js → lib/ModalPortal/index.js} +0 -0
  47. package/lib/MultipleSelectFormatter/index.css +1 -0
  48. package/{es/components/cell-formatter/multiple-select-formatter.js → lib/MultipleSelectFormatter/index.js} +2 -1
  49. package/lib/NumberFormatter/index.css +1 -0
  50. package/{es/components/cell-formatter/number-formatter.js → lib/NumberFormatter/index.js} +2 -1
  51. package/lib/RateFormatter/index.css +1 -0
  52. package/{es/components/cell-formatter/rate-formatter.js → lib/RateFormatter/index.js} +1 -0
  53. package/{es/components/common/select-item.js → lib/SelectItem/index.js} +0 -0
  54. package/lib/SingleSelectFormatter/index.css +1 -0
  55. package/{es/components/cell-formatter/single-select-formatter.js → lib/SingleSelectFormatter/index.js} +2 -1
  56. package/lib/TextFormatter/index.css +1 -0
  57. package/{es/components/cell-formatter/text-formatter.js → lib/TextFormatter/index.js} +1 -0
  58. package/lib/UrlFormatter/index.css +5 -0
  59. package/{es/components/cell-formatter/url-formatter.js → lib/UrlFormatter/index.js} +1 -0
  60. package/lib/app.js +75 -80
  61. package/{es/components/cell-factory/cell-formatter-factory.js → lib/cellFormatterFactory/index.js} +3 -3
  62. package/lib/components/cell-editor/checkbox-editor.js +59 -66
  63. package/lib/components/cell-editor/collaborator-editor.js +113 -126
  64. package/lib/components/cell-editor/date-editor.js +99 -119
  65. package/lib/components/cell-editor/index.js +9 -40
  66. package/lib/components/cell-editor/link-editor.js +122 -140
  67. package/lib/components/cell-editor/multiple-select-editor.js +114 -127
  68. package/lib/components/cell-editor/number-editor.js +78 -86
  69. package/lib/components/cell-editor/single-select-editor.js +106 -120
  70. package/lib/components/cell-editor/text-editor.js +65 -72
  71. package/lib/components/cell-editor-dialog/pc-file-editor-dialog.js +31 -51
  72. package/lib/components/cell-editor-dialog/pc-files-addition/index.js +0 -1
  73. package/lib/components/cell-editor-dialog/pc-files-addition/pc-file-uploaded-item.js +0 -1
  74. package/lib/components/cell-editor-dialog/pc-files-preview/index.js +0 -1
  75. package/lib/components/cell-editor-dialog/pc-files-preview/pc-file-item-preview.js +0 -1
  76. package/lib/components/cell-editor-popover/mb-collaborator-editor-popover.js +105 -111
  77. package/lib/components/cell-editor-popover/mb-date-editor-popover.js +140 -157
  78. package/lib/components/cell-editor-popover/mb-link-editor-popover.js +103 -109
  79. package/lib/components/cell-editor-popover/mb-select-editor-popover.js +142 -155
  80. package/lib/components/cell-editor-popover/pc-collaborator-editor-popover.js +74 -89
  81. package/lib/components/cell-editor-popover/pc-date-editor-popover.js +88 -102
  82. package/lib/components/cell-editor-popover/pc-link-editor-popover.js +77 -91
  83. package/lib/components/cell-editor-popover/pc-select-editor-popover.js +91 -105
  84. package/lib/components/common/collaborator-item.js +43 -59
  85. package/lib/components/common/edit-editor-button.js +28 -39
  86. package/lib/components/common/link-editor-option.js +63 -71
  87. package/lib/components/common/mobile/mb-editor-header.js +39 -52
  88. package/lib/components/common/select-editor-option.js +58 -74
  89. package/lib/constants/cell-types.js +25 -54
  90. package/lib/constants/index.js +5 -26
  91. package/lib/css/cell-formatter.css +0 -243
  92. package/lib/formatterConfig/index.js +31 -0
  93. package/lib/index.js +31 -64
  94. package/lib/lang/index.js +11 -27
  95. package/lib/locals/de.js +1 -6
  96. package/lib/locals/en.js +1 -6
  97. package/lib/locals/fr.js +1 -6
  98. package/lib/locals/zh-CN.js +1 -6
  99. package/{es/components/toast → lib/toaster}/alert.js +0 -0
  100. package/{es/components/toast → lib/toaster}/index.js +0 -0
  101. package/{es/components/toast → lib/toaster}/toast.js +0 -0
  102. package/{es/components/toast → lib/toaster}/toastManager.js +0 -0
  103. package/{es/components/toast → lib/toaster}/toaster.js +0 -0
  104. package/lib/utils/cell-value-validator.js +4 -14
  105. package/lib/utils/column-utils.js +5 -13
  106. package/lib/utils/editor-utils.js +3 -13
  107. package/lib/utils/markdown2html.js +1 -7
  108. package/lib/utils/normalize-long-text-value.js +1 -6
  109. package/lib/utils/number-precision.js +14 -31
  110. package/lib/utils/utils.js +8 -33
  111. package/lib/utils/value-format-utils.js +60 -108
  112. package/package.json +5 -5
  113. package/es/app.css +0 -20
  114. package/es/app.js +0 -91
  115. package/es/assets/images/avatar/default_avatar.png +0 -0
  116. package/es/assets/images/file/192/excel.png +0 -0
  117. package/es/assets/images/file/192/file.png +0 -0
  118. package/es/assets/images/file/192/music.png +0 -0
  119. package/es/assets/images/file/192/pdf.png +0 -0
  120. package/es/assets/images/file/192/pic.png +0 -0
  121. package/es/assets/images/file/192/ppt.png +0 -0
  122. package/es/assets/images/file/192/txt.png +0 -0
  123. package/es/assets/images/file/192/video.png +0 -0
  124. package/es/assets/images/file/192/word.png +0 -0
  125. package/es/assets/images/file/24/excel.png +0 -0
  126. package/es/assets/images/file/24/file.png +0 -0
  127. package/es/assets/images/file/24/music.png +0 -0
  128. package/es/assets/images/file/24/pdf.png +0 -0
  129. package/es/assets/images/file/24/pic.png +0 -0
  130. package/es/assets/images/file/24/ppt.png +0 -0
  131. package/es/assets/images/file/24/txt.png +0 -0
  132. package/es/assets/images/file/24/video.png +0 -0
  133. package/es/assets/images/file/24/word.png +0 -0
  134. package/es/assets/images/folder/folder-192.png +0 -0
  135. package/es/assets/images/folder/folder-24.png +0 -0
  136. package/es/components/cell-editor/checkbox-editor.js +0 -104
  137. package/es/components/cell-editor/collaborator-editor.js +0 -236
  138. package/es/components/cell-editor/date-editor.js +0 -151
  139. package/es/components/cell-editor/index.js +0 -9
  140. package/es/components/cell-editor/link-editor.js +0 -303
  141. package/es/components/cell-editor/multiple-select-editor.js +0 -237
  142. package/es/components/cell-editor/number-editor.js +0 -154
  143. package/es/components/cell-editor/single-select-editor.js +0 -202
  144. package/es/components/cell-editor/text-editor.js +0 -122
  145. package/es/components/cell-editor-dialog/pc-file-editor-dialog.js +0 -46
  146. package/es/components/cell-editor-dialog/pc-files-addition/index.js +0 -0
  147. package/es/components/cell-editor-dialog/pc-files-addition/pc-file-uploaded-item.js +0 -0
  148. package/es/components/cell-editor-dialog/pc-files-preview/index.js +0 -0
  149. package/es/components/cell-editor-dialog/pc-files-preview/pc-file-item-preview.js +0 -0
  150. package/es/components/cell-editor-popover/mb-collaborator-editor-popover.js +0 -177
  151. package/es/components/cell-editor-popover/mb-date-editor-popover.js +0 -245
  152. package/es/components/cell-editor-popover/mb-link-editor-popover.js +0 -170
  153. package/es/components/cell-editor-popover/mb-select-editor-popover.js +0 -230
  154. package/es/components/cell-editor-popover/pc-collaborator-editor-popover.js +0 -109
  155. package/es/components/cell-editor-popover/pc-date-editor-popover.js +0 -142
  156. package/es/components/cell-editor-popover/pc-link-editor-popover.js +0 -114
  157. package/es/components/cell-editor-popover/pc-select-editor-popover.js +0 -143
  158. package/es/components/cell-formatter/formatter-config.js +0 -31
  159. package/es/components/cell-formatter/index.js +0 -27
  160. package/es/components/common/edit-editor-button.js +0 -56
  161. package/es/components/common/link-editor-option.js +0 -113
  162. package/es/components/common/mobile/mb-editor-header.js +0 -48
  163. package/es/components/common/select-editor-option.js +0 -106
  164. package/es/constants/cell-types.js +0 -25
  165. package/es/constants/index.js +0 -48
  166. package/es/css/cell-editor.css +0 -614
  167. package/es/css/cell-formatter.css +0 -247
  168. package/es/css/custom-rc-calendar.css +0 -118
  169. package/es/index.js +0 -6
  170. package/es/lang/index.js +0 -50
  171. package/es/locals/de.js +0 -2
  172. package/es/locals/en.js +0 -17
  173. package/es/locals/fr.js +0 -2
  174. package/es/locals/zh-CN.js +0 -17
  175. package/es/utils/cell-value-validator.js +0 -32
  176. package/es/utils/column-utils.js +0 -7
  177. package/es/utils/editor-utils.js +0 -71
  178. package/es/utils/markdown2html.js +0 -62
  179. package/es/utils/normalize-long-text-value.js +0 -69
  180. package/es/utils/number-precision.js +0 -163
  181. package/es/utils/unified/index.js +0 -470
  182. package/es/utils/utils.js +0 -116
  183. package/es/utils/value-format-utils.js +0 -495
  184. package/es/utils/vfile/core.js +0 -172
  185. package/es/utils/vfile/index.js +0 -48
  186. package/lib/components/cell-factory/cell-formatter-factory.js +0 -28
  187. package/lib/components/cell-formatter/auto-number-formatter.js +0 -45
  188. package/lib/components/cell-formatter/button-formatter.js +0 -66
  189. package/lib/components/cell-formatter/checkbox-formatter.js +0 -56
  190. package/lib/components/cell-formatter/collaborator-formatter.js +0 -111
  191. package/lib/components/cell-formatter/creator-formatter.js +0 -105
  192. package/lib/components/cell-formatter/ctime-formatter.js +0 -70
  193. package/lib/components/cell-formatter/date-formatter.js +0 -73
  194. package/lib/components/cell-formatter/duration-formatter.js +0 -49
  195. package/lib/components/cell-formatter/email-formatter.js +0 -45
  196. package/lib/components/cell-formatter/file-formatter.js +0 -77
  197. package/lib/components/cell-formatter/formatter-config.js +0 -66
  198. package/lib/components/cell-formatter/formula-formatter.js +0 -189
  199. package/lib/components/cell-formatter/geolocation-formatter.js +0 -66
  200. package/lib/components/cell-formatter/image-formatter.js +0 -171
  201. package/lib/components/cell-formatter/index.js +0 -112
  202. package/lib/components/cell-formatter/last-modifier-formatter.js +0 -105
  203. package/lib/components/cell-formatter/link-formatter.js +0 -165
  204. package/lib/components/cell-formatter/long-text-formatter.js +0 -46
  205. package/lib/components/cell-formatter/mtime-formatter.js +0 -70
  206. package/lib/components/cell-formatter/multiple-select-formatter.js +0 -84
  207. package/lib/components/cell-formatter/number-formatter.js +0 -60
  208. package/lib/components/cell-formatter/rate-formatter.js +0 -93
  209. package/lib/components/cell-formatter/single-select-formatter.js +0 -84
  210. package/lib/components/cell-formatter/text-formatter.js +0 -67
  211. package/lib/components/cell-formatter/url-formatter.js +0 -45
  212. package/lib/components/cell-formatter/widgets/file-item-formatter.js +0 -63
  213. package/lib/components/cell-formatter/widgets/image-previewer-lightbox.js +0 -152
  214. package/lib/components/cell-formatter/widgets/long-text-formatter/html-long-text-formatter.js +0 -107
  215. package/lib/components/cell-formatter/widgets/long-text-formatter/simple-long-text-formatter.js +0 -110
  216. package/lib/components/common/images-lazy-load.js +0 -158
  217. package/lib/components/common/modal-portal.js +0 -51
  218. package/lib/components/common/select-item.js +0 -73
  219. package/lib/components/file-uploader/index.js +0 -63
  220. package/lib/components/loading.js +0 -16
  221. package/lib/components/toast/alert.js +0 -164
  222. package/lib/components/toast/index.js +0 -12
  223. package/lib/components/toast/toast.js +0 -223
  224. package/lib/components/toast/toastManager.js +0 -189
  225. package/lib/components/toast/toaster.js +0 -92
  226. package/lib/css/image-previewer-ligntbox.css +0 -87
  227. package/lib/css/loading.css +0 -54
@@ -1,69 +0,0 @@
1
- var hrefReg = /\[.+\]\(\S+\)|<img src=(\S+).+\/>|!\[\]\(\S+\)|<\S+>/g;
2
- var imageReg1 = /^<img( width=[\\|/|"](\d)+[\\|/|"])? src="(\S+)" .?\/>/;
3
- var imageReg2 = /^!\[\]\((\S+)\)/;
4
- var linkReg1 = /^\[.+\]\(\S+\)/;
5
- var linkReg2 = /^<\S+>$/;
6
-
7
- var getLinks = function getLinks(hrefList) {
8
- var hrefObj = {
9
- links: [],
10
- images: []
11
- };
12
- hrefList.forEach(function (href) {
13
- if (href.search(linkReg1) >= 0 || href.search(linkReg2) >= 0) {
14
- hrefObj.links.push(href);
15
- } else {
16
- var imageSrcList = href.match(imageReg1);
17
- var imageSrcList1 = href.match(imageReg2);
18
-
19
- if (imageSrcList) {
20
- hrefObj.images.push(imageSrcList[1]);
21
- } else if (imageSrcList1) {
22
- hrefObj.images.push(imageSrcList1[1]);
23
- }
24
- }
25
- });
26
- return hrefObj;
27
- };
28
-
29
- var getPreviewContent = function getPreviewContent(markdownContent) {
30
- var preview = '';
31
- var newMarkdownContent = markdownContent.replace(hrefReg, '');
32
-
33
- for (var index = 0; index < newMarkdownContent.length; index++) {
34
- if (newMarkdownContent[index] === '#') {
35
- continue;
36
- } else if (newMarkdownContent[index] === '\n') {
37
- preview += ' ';
38
- } else {
39
- preview += newMarkdownContent[index];
40
- }
41
-
42
- if (preview.length === 150) {
43
- break;
44
- }
45
- }
46
-
47
- var hrefList = markdownContent.match(hrefReg);
48
-
49
- if (hrefList) {
50
- var _getLinks = getLinks(hrefList),
51
- images = _getLinks.images,
52
- links = _getLinks.links;
53
-
54
- return {
55
- preview: preview,
56
- images: images,
57
- links: links
58
- };
59
- }
60
-
61
- return {
62
- preview: preview,
63
- images: [],
64
- links: [],
65
- text: markdownContent
66
- };
67
- };
68
-
69
- export default getPreviewContent;
@@ -1,163 +0,0 @@
1
- import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
-
3
- /**
4
- * @desc Solve the problem of floating calculation, avoid multiple digits after the decimal point and loss of calculation accuracy.
5
- * example: 3 + 2.4 = 4.699999999999999,1.0 - 0.9 = 0.09999999999999998
6
- */
7
-
8
- /**
9
- * Correct wrong data
10
- * strip(0.09999999999999998)=0.1
11
- */
12
- function strip(num) {
13
- var precision = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 12;
14
- return +parseFloat(num.toPrecision(precision));
15
- }
16
- /**
17
- * Return digits length of a number
18
- * @param {*number} num Input number
19
- */
20
-
21
-
22
- function digitLength(num) {
23
- // Get digit length of e
24
- var eSplit = num.toString().split(/[eE]/);
25
- var len = (eSplit[0].split('.')[1] || '').length - +(eSplit[1] || 0);
26
- return len > 0 ? len : 0;
27
- }
28
- /**
29
- * Convert decimals to integers and support scientific notation. If it is a decimal, it is enlarged to an integer
30
- * @param {*number} num Number of inputs
31
- */
32
-
33
-
34
- function float2Fixed(num) {
35
- if (num.toString().indexOf('e') === -1) {
36
- return Number(num.toString().replace('.', ''));
37
- }
38
-
39
- var dLen = digitLength(num);
40
- return dLen > 0 ? strip(num * Math.pow(10, dLen)) : num;
41
- }
42
- /**
43
- * Check whether the number is out of range, and give a prompt if it is out of range
44
- * @param {*number} num Number of inputs
45
- */
46
-
47
-
48
- function checkBoundary(num) {
49
- if (_boundaryCheckingState) {
50
- if (num > Number.MAX_SAFE_INTEGER || num < Number.MIN_SAFE_INTEGER) {
51
- console.warn("".concat(num, " is beyond boundary when transfer to integer, the results may not be accurate"));
52
- }
53
- }
54
- }
55
- /**
56
- * Exact multiplication
57
- */
58
-
59
-
60
- function times(num1, num2) {
61
- for (var _len = arguments.length, others = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
62
- others[_key - 2] = arguments[_key];
63
- }
64
-
65
- if (others.length > 0) {
66
- return times.apply(void 0, [times(num1, num2), others[0]].concat(_toConsumableArray(others.slice(1))));
67
- }
68
-
69
- var num1Changed = float2Fixed(num1);
70
- var num2Changed = float2Fixed(num2);
71
- var baseNum = digitLength(num1) + digitLength(num2);
72
- var leftValue = num1Changed * num2Changed;
73
- checkBoundary(leftValue);
74
- return leftValue / Math.pow(10, baseNum);
75
- }
76
- /**
77
- * Exact addition
78
- */
79
-
80
-
81
- function plus(num1, num2) {
82
- for (var _len2 = arguments.length, others = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
83
- others[_key2 - 2] = arguments[_key2];
84
- }
85
-
86
- if (others.length > 0) {
87
- return plus.apply(void 0, [plus(num1, num2), others[0]].concat(_toConsumableArray(others.slice(1))));
88
- }
89
-
90
- var baseNum = Math.pow(10, Math.max(digitLength(num1), digitLength(num2)));
91
- return (times(num1, baseNum) + times(num2, baseNum)) / baseNum;
92
- }
93
- /**
94
- * Exact subtraction
95
- */
96
-
97
-
98
- function minus(num1, num2) {
99
- for (var _len3 = arguments.length, others = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
100
- others[_key3 - 2] = arguments[_key3];
101
- }
102
-
103
- if (others.length > 0) {
104
- return minus.apply(void 0, [minus(num1, num2), others[0]].concat(_toConsumableArray(others.slice(1))));
105
- }
106
-
107
- var baseNum = Math.pow(10, Math.max(digitLength(num1), digitLength(num2)));
108
- return (times(num1, baseNum) - times(num2, baseNum)) / baseNum;
109
- }
110
- /**
111
- * Exact division
112
- */
113
-
114
-
115
- function divide(num1, num2) {
116
- for (var _len4 = arguments.length, others = new Array(_len4 > 2 ? _len4 - 2 : 0), _key4 = 2; _key4 < _len4; _key4++) {
117
- others[_key4 - 2] = arguments[_key4];
118
- }
119
-
120
- if (others.length > 0) {
121
- return divide.apply(void 0, [divide(num1, num2), others[0]].concat(_toConsumableArray(others.slice(1))));
122
- }
123
-
124
- var num1Changed = float2Fixed(num1);
125
- var num2Changed = float2Fixed(num2);
126
- checkBoundary(num1Changed);
127
- checkBoundary(num2Changed); // fix: Similar to 10 ** -4 is 0.00009999999999999999, strip correction
128
-
129
- return times(num1Changed / num2Changed, strip(Math.pow(10, digitLength(num2) - digitLength(num1))));
130
- }
131
- /**
132
- * rounding
133
- */
134
-
135
-
136
- function round(num, ratio) {
137
- var base = Math.pow(10, ratio);
138
- return divide(Math.round(times(num, base)), base);
139
- }
140
-
141
- var _boundaryCheckingState = true;
142
- /**
143
- * Whether to perform boundary check, default true
144
- * @param flag Mark switch, true is on, false is off, default is true
145
- */
146
-
147
- function enableBoundaryChecking() {
148
- var flag = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
149
- _boundaryCheckingState = flag;
150
- }
151
-
152
- export { strip, plus, minus, times, divide, round, digitLength, float2Fixed, enableBoundaryChecking };
153
- export default {
154
- strip: strip,
155
- plus: plus,
156
- minus: minus,
157
- times: times,
158
- divide: divide,
159
- round: round,
160
- digitLength: digitLength,
161
- float2Fixed: float2Fixed,
162
- enableBoundaryChecking: enableBoundaryChecking
163
- };
@@ -1,470 +0,0 @@
1
- 'use strict';
2
- /* Dependencies. */
3
-
4
- var extend = require('extend');
5
-
6
- var bail = require('bail');
7
-
8
- var vfile = require('../vfile');
9
-
10
- var trough = require('trough');
11
-
12
- var string = require('x-is-string');
13
-
14
- var plain = require('is-plain-obj');
15
- /* Expose a frozen processor. */
16
-
17
-
18
- module.exports = unified().freeze();
19
- var slice = [].slice;
20
- var own = {}.hasOwnProperty;
21
- /* Process pipeline. */
22
-
23
- var pipeline = trough().use(pipelineParse).use(pipelineRun).use(pipelineStringify);
24
-
25
- function pipelineParse(p, ctx) {
26
- ctx.tree = p.parse(ctx.file);
27
- }
28
-
29
- function pipelineRun(p, ctx, next) {
30
- p.run(ctx.tree, ctx.file, done);
31
-
32
- function done(err, tree, file) {
33
- if (err) {
34
- next(err);
35
- } else {
36
- ctx.tree = tree;
37
- ctx.file = file;
38
- next();
39
- }
40
- }
41
- }
42
-
43
- function pipelineStringify(p, ctx) {
44
- ctx.file.contents = p.stringify(ctx.tree, ctx.file);
45
- }
46
- /* Function to create the first processor. */
47
-
48
-
49
- function unified() {
50
- var attachers = [];
51
- var transformers = trough();
52
- var namespace = {};
53
- var frozen = false;
54
- var freezeIndex = -1;
55
- /* Data management. */
56
-
57
- processor.data = data;
58
- /* Lock. */
59
-
60
- processor.freeze = freeze;
61
- /* Plug-ins. */
62
-
63
- processor.attachers = attachers;
64
- processor.use = use;
65
- /* API. */
66
-
67
- processor.parse = parse;
68
- processor.stringify = stringify;
69
- processor.run = run;
70
- processor.runSync = runSync;
71
- processor.process = process;
72
- processor.processSync = processSync;
73
- /* Expose. */
74
-
75
- return processor;
76
- /* Create a new processor based on the processor
77
- * in the current scope. */
78
-
79
- function processor() {
80
- var destination = unified();
81
- var length = attachers.length;
82
- var index = -1;
83
-
84
- while (++index < length) {
85
- destination.use.apply(null, attachers[index]);
86
- }
87
-
88
- destination.data(extend(true, {}, namespace));
89
- return destination;
90
- }
91
- /* Freeze: used to signal a processor that has finished
92
- * configuration.
93
- *
94
- * For example, take unified itself. It’s frozen.
95
- * Plug-ins should not be added to it. Rather, it should
96
- * be extended, by invoking it, before modifying it.
97
- *
98
- * In essence, always invoke this when exporting a
99
- * processor. */
100
-
101
-
102
- function freeze() {
103
- var values;
104
- var plugin;
105
- var options;
106
- var transformer;
107
-
108
- if (frozen) {
109
- return processor;
110
- }
111
-
112
- while (++freezeIndex < attachers.length) {
113
- values = attachers[freezeIndex];
114
- plugin = values[0];
115
- options = values[1];
116
- transformer = null;
117
-
118
- if (options === false) {
119
- continue;
120
- }
121
-
122
- if (options === true) {
123
- values[1] = undefined;
124
- }
125
-
126
- transformer = plugin.apply(processor, values.slice(1));
127
-
128
- if (typeof transformer === 'function') {
129
- transformers.use(transformer);
130
- }
131
- }
132
-
133
- frozen = true;
134
- freezeIndex = Infinity;
135
- return processor;
136
- }
137
- /* Data management.
138
- * Getter / setter for processor-specific informtion. */
139
-
140
-
141
- function data(key, value) {
142
- if (string(key)) {
143
- /* Set `key`. */
144
- if (arguments.length === 2) {
145
- assertUnfrozen('data', frozen);
146
- namespace[key] = value;
147
- return processor;
148
- }
149
- /* Get `key`. */
150
-
151
-
152
- return own.call(namespace, key) && namespace[key] || null;
153
- }
154
- /* Set space. */
155
-
156
-
157
- if (key) {
158
- assertUnfrozen('data', frozen);
159
- namespace = key;
160
- return processor;
161
- }
162
- /* Get space. */
163
-
164
-
165
- return namespace;
166
- }
167
- /* Plug-in management.
168
- *
169
- * Pass it:
170
- * * an attacher and options,
171
- * * a preset,
172
- * * a list of presets, attachers, and arguments (list
173
- * of attachers and options). */
174
-
175
-
176
- function use(value) {
177
- var settings;
178
- assertUnfrozen('use', frozen);
179
-
180
- if (value === null || value === undefined) {
181
- /* Empty */
182
- } else if (typeof value === 'function') {
183
- addPlugin.apply(null, arguments);
184
- } else if (typeof value === 'object') {
185
- if ('length' in value) {
186
- addList(value);
187
- } else {
188
- addPreset(value);
189
- }
190
- } else {
191
- throw new Error('Expected usable value, not `' + value + '`');
192
- }
193
-
194
- if (settings) {
195
- namespace.settings = extend(namespace.settings || {}, settings);
196
- }
197
-
198
- return processor;
199
-
200
- function addPreset(result) {
201
- addList(result.plugins);
202
-
203
- if (result.settings) {
204
- settings = extend(settings || {}, result.settings);
205
- }
206
- }
207
-
208
- function add(value) {
209
- if (typeof value === 'function') {
210
- addPlugin(value);
211
- } else if (typeof value === 'object') {
212
- if ('length' in value) {
213
- addPlugin.apply(null, value);
214
- } else {
215
- addPreset(value);
216
- }
217
- } else {
218
- throw new Error('Expected usable value, not `' + value + '`');
219
- }
220
- }
221
-
222
- function addList(plugins) {
223
- var length;
224
- var index;
225
-
226
- if (plugins === null || plugins === undefined) {
227
- /* Empty */
228
- } else if (typeof plugins === 'object' && 'length' in plugins) {
229
- length = plugins.length;
230
- index = -1;
231
-
232
- while (++index < length) {
233
- add(plugins[index]);
234
- }
235
- } else {
236
- throw new Error('Expected a list of plugins, not `' + plugins + '`');
237
- }
238
- }
239
-
240
- function addPlugin(plugin, value) {
241
- var entry = find(plugin);
242
-
243
- if (entry) {
244
- if (plain(entry[1]) && plain(value)) {
245
- value = extend(entry[1], value);
246
- }
247
-
248
- entry[1] = value;
249
- } else {
250
- attachers.push(slice.call(arguments));
251
- }
252
- }
253
- }
254
-
255
- function find(plugin) {
256
- var length = attachers.length;
257
- var index = -1;
258
- var entry;
259
-
260
- while (++index < length) {
261
- entry = attachers[index];
262
-
263
- if (entry[0] === plugin) {
264
- return entry;
265
- }
266
- }
267
- }
268
- /* Parse a file (in string or VFile representation)
269
- * into a Unist node using the `Parser` on the
270
- * processor. */
271
-
272
-
273
- function parse(doc) {
274
- var file = vfile(doc);
275
- var Parser;
276
- freeze();
277
- Parser = processor.Parser;
278
- assertParser('parse', Parser);
279
-
280
- if (newable(Parser)) {
281
- return new Parser(String(file), file).parse();
282
- }
283
-
284
- return Parser(String(file), file); // eslint-disable-line new-cap
285
- }
286
- /* Run transforms on a Unist node representation of a file
287
- * (in string or VFile representation), async. */
288
-
289
-
290
- function run(node, file, cb) {
291
- assertNode(node);
292
- freeze();
293
-
294
- if (!cb && typeof file === 'function') {
295
- cb = file;
296
- file = null;
297
- }
298
-
299
- if (!cb) {
300
- return new Promise(executor);
301
- }
302
-
303
- executor(null, cb);
304
-
305
- function executor(resolve, reject) {
306
- transformers.run(node, vfile(file), done);
307
-
308
- function done(err, tree, file) {
309
- tree = tree || node;
310
-
311
- if (err) {
312
- reject(err);
313
- } else if (resolve) {
314
- resolve(tree);
315
- } else {
316
- cb(null, tree, file);
317
- }
318
- }
319
- }
320
- }
321
- /* Run transforms on a Unist node representation of a file
322
- * (in string or VFile representation), sync. */
323
-
324
-
325
- function runSync(node, file) {
326
- var complete = false;
327
- var result;
328
- run(node, file, done);
329
- assertDone('runSync', 'run', complete);
330
- return result;
331
-
332
- function done(err, tree) {
333
- complete = true;
334
- bail(err);
335
- result = tree;
336
- }
337
- }
338
- /* Stringify a Unist node representation of a file
339
- * (in string or VFile representation) into a string
340
- * using the `Compiler` on the processor. */
341
-
342
-
343
- function stringify(node, doc) {
344
- var file = vfile(doc);
345
- var Compiler;
346
- freeze();
347
- Compiler = processor.Compiler;
348
- assertCompiler('stringify', Compiler);
349
- assertNode(node);
350
-
351
- if (newable(Compiler)) {
352
- return new Compiler(node, file).compile();
353
- }
354
-
355
- return Compiler(node, file); // eslint-disable-line new-cap
356
- }
357
- /* Parse a file (in string or VFile representation)
358
- * into a Unist node using the `Parser` on the processor,
359
- * then run transforms on that node, and compile the
360
- * resulting node using the `Compiler` on the processor,
361
- * and store that result on the VFile. */
362
-
363
-
364
- function process(doc, cb) {
365
- freeze();
366
- assertParser('process', processor.Parser);
367
- assertCompiler('process', processor.Compiler);
368
-
369
- if (!cb) {
370
- return new Promise(executor);
371
- }
372
-
373
- executor(null, cb);
374
-
375
- function executor(resolve, reject) {
376
- var file = vfile(doc);
377
- pipeline.run(processor, {
378
- file: file
379
- }, done);
380
-
381
- function done(err) {
382
- if (err) {
383
- reject(err);
384
- } else if (resolve) {
385
- resolve(file);
386
- } else {
387
- cb(null, file);
388
- }
389
- }
390
- }
391
- }
392
- /* Process the given document (in string or VFile
393
- * representation), sync. */
394
-
395
-
396
- function processSync(doc) {
397
- var complete = false;
398
- var file;
399
- freeze();
400
- assertParser('processSync', processor.Parser);
401
- assertCompiler('processSync', processor.Compiler);
402
- file = vfile(doc);
403
- process(file, done);
404
- assertDone('processSync', 'process', complete);
405
- return file;
406
-
407
- function done(err) {
408
- complete = true;
409
- bail(err);
410
- }
411
- }
412
- }
413
- /* Check if `func` is a constructor. */
414
-
415
-
416
- function newable(value) {
417
- return typeof value === 'function' && keys(value.prototype);
418
- }
419
- /* Check if `value` is an object with keys. */
420
-
421
-
422
- function keys(value) {
423
- var key;
424
-
425
- for (key in value) {
426
- return true;
427
- }
428
-
429
- return false;
430
- }
431
- /* Assert a parser is available. */
432
-
433
-
434
- function assertParser(name, Parser) {
435
- if (typeof Parser !== 'function') {
436
- throw new Error('Cannot `' + name + '` without `Parser`');
437
- }
438
- }
439
- /* Assert a compiler is available. */
440
-
441
-
442
- function assertCompiler(name, Compiler) {
443
- if (typeof Compiler !== 'function') {
444
- throw new Error('Cannot `' + name + '` without `Compiler`');
445
- }
446
- }
447
- /* Assert the processor is not frozen. */
448
-
449
-
450
- function assertUnfrozen(name, frozen) {
451
- if (frozen) {
452
- throw new Error(['Cannot invoke `' + name + '` on a frozen processor.\nCreate a new ', 'processor first, by invoking it: use `processor()` instead of ', '`processor`.'].join(''));
453
- }
454
- }
455
- /* Assert `node` is a Unist node. */
456
-
457
-
458
- function assertNode(node) {
459
- if (!node || !string(node.type)) {
460
- throw new Error('Expected node, got `' + node + '`');
461
- }
462
- }
463
- /* Assert that `complete` is `true`. */
464
-
465
-
466
- function assertDone(name, asyncName, complete) {
467
- if (!complete) {
468
- throw new Error('`' + name + '` finished async. Use `' + asyncName + '` instead');
469
- }
470
- }