@kizmann/pico-js 1.0.13 → 2.0.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 (125) hide show
  1. package/README.md +27 -7
  2. package/dist/pico-js.browser.js +2 -0
  3. package/dist/pico-js.browser.js.map +1 -0
  4. package/dist/pico-js.esm.js +2 -0
  5. package/dist/pico-js.esm.js.map +1 -0
  6. package/package.json +20 -7
  7. package/src/dom/DomAttribute.js +374 -0
  8. package/src/dom/DomBuilder.js +152 -0
  9. package/src/dom/DomEvent.js +253 -0
  10. package/src/dom/DomFinder.js +669 -0
  11. package/src/dom/DomForm.js +57 -0
  12. package/src/dom/DomGlobal.js +193 -0
  13. package/src/dom/DomInview.js +332 -0
  14. package/src/dom/DomMeta.js +66 -0
  15. package/src/dom/DomObserver.js +57 -0
  16. package/src/dom/DomRectangle.js +657 -0
  17. package/src/format/FormatFile.js +54 -0
  18. package/src/format/FormatOption.js +108 -0
  19. package/src/format/FormatParam.js +107 -0
  20. package/src/format/FormatParser.js +156 -0
  21. package/src/format/FormatUrl.js +75 -0
  22. package/src/index.browser.js +10 -0
  23. package/src/index.esm.js +138 -0
  24. package/src/now/NowDefault.js +533 -0
  25. package/src/now/NowFormat.js +196 -0
  26. package/src/now/NowGrid.js +251 -0
  27. package/src/now/NowHuman.js +118 -0
  28. package/src/now/NowMatch.js +175 -0
  29. package/src/now/NowRange.js +70 -0
  30. package/src/now/NowWalker.js +544 -0
  31. package/src/tool/scope.js +103 -0
  32. package/src/utils/Array.js +986 -0
  33. package/src/utils/Cookie.js +184 -0
  34. package/src/utils/Data.js +200 -0
  35. package/src/utils/Dom.js +208 -0
  36. package/src/utils/Event.js +140 -0
  37. package/src/utils/Format.js +62 -0
  38. package/src/utils/Hash.js +164 -0
  39. package/src/utils/Locale.js +229 -0
  40. package/src/utils/Mixed.js +887 -0
  41. package/src/utils/Now.js +234 -0
  42. package/src/utils/Number.js +238 -0
  43. package/src/utils/Object.js +655 -0
  44. package/src/utils/Route.js +67 -0
  45. package/src/utils/Runner.js +327 -0
  46. package/src/utils/String.js +618 -0
  47. package/src/{library/element.js → wip/Element.js} +90 -16
  48. package/src/{library/map.js → wip/Map.js} +256 -40
  49. package/types/dom/DomAttribute.d.ts +137 -0
  50. package/types/dom/DomBuilder.d.ts +67 -0
  51. package/types/dom/DomEvent.d.ts +103 -0
  52. package/types/dom/DomFinder.d.ts +321 -0
  53. package/types/dom/DomForm.d.ts +21 -0
  54. package/types/dom/DomGlobal.d.ts +79 -0
  55. package/types/dom/DomInview.d.ts +114 -0
  56. package/types/dom/DomMeta.d.ts +29 -0
  57. package/types/dom/DomObserver.d.ts +21 -0
  58. package/types/dom/DomRectangle.d.ts +270 -0
  59. package/types/format/FormatFile.d.ts +18 -0
  60. package/types/format/FormatOption.d.ts +40 -0
  61. package/types/format/FormatParam.d.ts +39 -0
  62. package/types/format/FormatParser.d.ts +46 -0
  63. package/types/format/FormatUrl.d.ts +17 -0
  64. package/types/index.browser.d.ts +1 -0
  65. package/types/index.esm.d.ts +52 -0
  66. package/types/now/NowDefault.d.ts +183 -0
  67. package/types/now/NowFormat.d.ts +70 -0
  68. package/types/now/NowGrid.d.ts +107 -0
  69. package/types/now/NowHuman.d.ts +37 -0
  70. package/types/now/NowMatch.d.ts +108 -0
  71. package/types/now/NowRange.d.ts +21 -0
  72. package/types/now/NowWalker.d.ts +301 -0
  73. package/types/tool/scope.d.ts +24 -0
  74. package/types/utils/Array.d.ts +480 -0
  75. package/types/utils/Cookie.d.ts +60 -0
  76. package/types/utils/Data.d.ts +91 -0
  77. package/types/utils/Dom.d.ts +138 -0
  78. package/types/utils/Event.d.ts +58 -0
  79. package/types/utils/Format.d.ts +37 -0
  80. package/types/utils/Hash.d.ts +81 -0
  81. package/types/utils/Locale.d.ts +115 -0
  82. package/types/utils/Mixed.d.ts +469 -0
  83. package/types/utils/Now.d.ts +125 -0
  84. package/types/utils/Number.d.ts +127 -0
  85. package/types/utils/Object.d.ts +255 -0
  86. package/types/utils/Route.d.ts +37 -0
  87. package/types/utils/Runner.d.ts +139 -0
  88. package/types/utils/String.d.ts +330 -0
  89. package/types/wip/Element.d.ts +119 -0
  90. package/types/wip/Map.d.ts +254 -0
  91. package/dist/.ignore.js +0 -0
  92. package/dist/pico-js.js +0 -2
  93. package/dist/pico-js.js.map +0 -1
  94. package/src/element/default.js +0 -46
  95. package/src/element/example.js +0 -58
  96. package/src/index.js +0 -90
  97. package/src/library/cookie.js +0 -123
  98. package/src/library/data.js +0 -111
  99. package/src/library/event.js +0 -91
  100. package/src/library/locale.js +0 -84
  101. package/src/library/queue.js +0 -64
  102. package/src/library/route.js +0 -28
  103. package/src/utility/any.js +0 -369
  104. package/src/utility/array.js +0 -410
  105. package/src/utility/dom.js +0 -1425
  106. package/src/utility/now.js +0 -544
  107. package/src/utility/number.js +0 -128
  108. package/src/utility/object.js +0 -429
  109. package/src/utility/string.js +0 -328
  110. package/types/index.d.ts +0 -77
  111. package/types/library/cookie.d.ts +0 -10
  112. package/types/library/data.d.ts +0 -15
  113. package/types/library/element.d.ts +0 -22
  114. package/types/library/event.d.ts +0 -13
  115. package/types/library/locale.d.ts +0 -14
  116. package/types/library/map.d.ts +0 -43
  117. package/types/library/queue.d.ts +0 -18
  118. package/types/library/route.d.ts +0 -11
  119. package/types/utility/any.d.ts +0 -35
  120. package/types/utility/array.d.ts +0 -46
  121. package/types/utility/dom.d.ts +0 -101
  122. package/types/utility/now.d.ts +0 -79
  123. package/types/utility/number.d.ts +0 -17
  124. package/types/utility/object.d.ts +0 -29
  125. package/types/utility/string.d.ts +0 -26
@@ -0,0 +1,657 @@
1
+ import { Arr, Dom, Mix, Obj } from "#src/index.esm.js";
2
+
3
+
4
+ /**
5
+ * @memberof PicoDom
6
+ */
7
+ export class PicoDomRectangleStatic
8
+ {
9
+ /**
10
+ * Cast value to number
11
+ *
12
+ * @example Dom.num("10px") // => 10
13
+ *
14
+ * @param {any} value Input value
15
+ * @returns {number} Number value
16
+ */
17
+ static num(value)
18
+ {
19
+ if ( typeof value === 'string' ) {
20
+ value = value.replace(/(^\s+|\s$|px)/g, '');
21
+ }
22
+
23
+ return Mix.num(value, 0);
24
+ }
25
+ }
26
+
27
+ /**
28
+ * @memberof PicoDom
29
+ * @extends {PicoDom}
30
+ */
31
+ export class PicoDomRectangleInstance
32
+ {
33
+ /**
34
+ * Get margin values
35
+ *
36
+ * @example Dom.find("div").margin()
37
+ *
38
+ * @param {string} [key] Margin key
39
+ * @param {number} [fallback] Fallback value
40
+ * @returns {any} Margin values
41
+ */
42
+ margin(key = null, fallback = 0)
43
+ {
44
+ let computed = this.computed();
45
+
46
+ let result = {
47
+ top: Dom.num(computed.marginTop),
48
+ right: Dom.num(computed.marginRight),
49
+ bottom: Dom.num(computed.marginBottom),
50
+ left: Dom.num(computed.marginLeft)
51
+ };
52
+
53
+ if ( key == null ) {
54
+ return result;
55
+ }
56
+
57
+ return Obj.get(result, key, fallback);
58
+ }
59
+
60
+ /**
61
+ * Get padding values
62
+ *
63
+ * @example Dom.find("div").padding()
64
+ *
65
+ * @param {string} [key] Padding key
66
+ * @param {number} [fallback] Fallback value
67
+ * @returns {any} Padding values
68
+ */
69
+ padding(key = null, fallback = 0)
70
+ {
71
+ let computed = this.computed();
72
+
73
+ let result = {
74
+ top: Dom.num(computed.paddingTop),
75
+ right: Dom.num(computed.paddingRight),
76
+ bottom: Dom.num(computed.paddingBottom),
77
+ left: Dom.num(computed.paddingLeft)
78
+ };
79
+
80
+ if ( key == null ) {
81
+ return result;
82
+ }
83
+
84
+ return Obj.get(result, key, fallback);
85
+ }
86
+
87
+ /**
88
+ * Get element height
89
+ *
90
+ * @example Dom.find("div").height() // => 100
91
+ *
92
+ * @returns {number} Height value
93
+ */
94
+ height()
95
+ {
96
+ if ( this.el == null ) {
97
+ return 0;
98
+ }
99
+
100
+ if ( this.el instanceof Window ) {
101
+ return this.el.innerHeight;
102
+ }
103
+
104
+ return this.el.offsetHeight;
105
+ }
106
+
107
+ /**
108
+ * Get client height
109
+ *
110
+ * @example Dom.find("div").clientHeight()
111
+ *
112
+ * @returns {number} Height value
113
+ */
114
+ clientHeight()
115
+ {
116
+ if ( this.el == null ) {
117
+ return 0;
118
+ }
119
+
120
+ return Dom.num(this.computed('height', 0));
121
+ }
122
+
123
+ /**
124
+ * Get scroll height
125
+ *
126
+ * @example Dom.find("div").scrollHeight()
127
+ *
128
+ * @returns {number} Height value
129
+ */
130
+ scrollHeight()
131
+ {
132
+ if ( this.el == null ) {
133
+ return 0;
134
+ }
135
+
136
+ return this.el.scrollHeight;
137
+ }
138
+
139
+ /**
140
+ * Get inner height
141
+ *
142
+ * @example Dom.find("div").innerHeight()
143
+ *
144
+ * @returns {number} Height value
145
+ */
146
+ innerHeight()
147
+ {
148
+ if ( this.el == null ) {
149
+ return 0;
150
+ }
151
+
152
+ if ( this.el instanceof Window ) {
153
+ return this.el.innerHeight;
154
+ }
155
+
156
+ let pad = this.padding();
157
+
158
+ return this.el.offsetHeight - pad.top - pad.bottom;
159
+ }
160
+
161
+ /**
162
+ * Get real height
163
+ *
164
+ * @example Dom.find("div").realHeight({ display: "block" })
165
+ *
166
+ * @param {any} [style] Temp style
167
+ * @returns {number} Height value
168
+ */
169
+ realHeight(style = {})
170
+ {
171
+ let height = 'auto';
172
+
173
+ this.actual(() => {
174
+ return height = this.height();
175
+ }, style);
176
+
177
+ return height;
178
+ }
179
+
180
+ /**
181
+ * Evaluate target height
182
+ *
183
+ * @example Dom.find("div").evaluateHeight(".container")
184
+ *
185
+ * @param {any} [target] Target element
186
+ * @param {boolean} [apply] Apply style
187
+ * @returns {number} Height value
188
+ */
189
+ evaluateHeight(target = null, apply = true)
190
+ {
191
+ target = Dom.find(target);
192
+
193
+ if ( target === null ) {
194
+ target = this.parent();
195
+ }
196
+
197
+ let height = 'auto';
198
+
199
+ this.actual(() => {
200
+ height = target.innerHeight();
201
+ }, { display: 'none' });
202
+
203
+ if ( apply === true ) {
204
+ this.style({ height: height + 'px' });
205
+ }
206
+
207
+ return height;
208
+ }
209
+
210
+ /**
211
+ * Get element width
212
+ *
213
+ * @example Dom.find("div").width() // => 100
214
+ *
215
+ * @returns {number} Width value
216
+ */
217
+ width()
218
+ {
219
+ if ( this.el == null ) {
220
+ return 0;
221
+ }
222
+
223
+ if ( this.el instanceof Window ) {
224
+ return this.el.innerWidth;
225
+ }
226
+
227
+ return this.el.offsetWidth;
228
+ }
229
+
230
+ /**
231
+ * Get client width
232
+ *
233
+ * @example Dom.find("div").clientWidth()
234
+ *
235
+ * @returns {number} Width value
236
+ */
237
+ clientWidth()
238
+ {
239
+ if ( this.el == null ) {
240
+ return 0;
241
+ }
242
+
243
+ return Dom.num(this.computed('width', 0));
244
+ }
245
+
246
+ /**
247
+ * Get scroll width
248
+ *
249
+ * @example Dom.find("div").scrollWidth()
250
+ *
251
+ * @returns {number} Width value
252
+ */
253
+ scrollWidth()
254
+ {
255
+ if ( this.el == null ) {
256
+ return 0;
257
+ }
258
+
259
+ return this.el.scrollWidth;
260
+ }
261
+
262
+ /**
263
+ * Get inner width
264
+ *
265
+ * @example Dom.find("div").innerWidth()
266
+ *
267
+ * @returns {number} Width value
268
+ */
269
+ innerWidth()
270
+ {
271
+ if ( this.el == null ) {
272
+ return 0;
273
+ }
274
+
275
+ if ( this.el instanceof Window ) {
276
+ return this.el.innerWidth;
277
+ }
278
+
279
+ let pad = this.padding();
280
+
281
+ return this.el.offsetWidth - pad.left - pad.right;
282
+ }
283
+
284
+ /**
285
+ * Get real width
286
+ *
287
+ * @example Dom.find("div").realWidth({ display: "block" })
288
+ *
289
+ * @param {any} [style] Temp style
290
+ * @returns {number} Width value
291
+ */
292
+ realWidth(style = {})
293
+ {
294
+ let width = 'auto';
295
+
296
+ this.actual(() => {
297
+ return width = this.width();
298
+ }, style);
299
+
300
+ return width;
301
+ }
302
+
303
+ /**
304
+ * Evaluate target width
305
+ *
306
+ * @example Dom.find("div").evaluateWidth(".container")
307
+ *
308
+ * @param {any} [target] Target element
309
+ * @param {boolean} [apply] Apply style
310
+ * @returns {number} Width value
311
+ */
312
+ evaluateWidth(target = null, apply = true)
313
+ {
314
+ target = Dom.find(target);
315
+
316
+ if ( target === null ) {
317
+ target = this.parent();
318
+ }
319
+
320
+ let width = 'auto';
321
+
322
+ this.actual(() => {
323
+ width = target.innerWidth();
324
+ }, { display: 'none' });
325
+
326
+ if ( apply === true ) {
327
+ this.style({ width: width + 'px' });
328
+ }
329
+
330
+ return width;
331
+ }
332
+
333
+ /**
334
+ * Get element offset
335
+ *
336
+ * @example Dom.find("div").offset()
337
+ *
338
+ * @param {string} [key] Offset key
339
+ * @param {any} [boundry] View boundry
340
+ * @returns {any} Offset values
341
+ */
342
+ offset(key = null, boundry = null)
343
+ {
344
+ let offset = this.getOffset(boundry);
345
+
346
+ if ( key == null ) {
347
+ return offset;
348
+ }
349
+
350
+ return Obj.get(offset, key, 0);
351
+ }
352
+
353
+ /**
354
+ * Get top offset
355
+ *
356
+ * @example Dom.find("div").offsetTop()
357
+ *
358
+ * @param {any} [boundry] View boundry
359
+ * @returns {number} Top offset
360
+ */
361
+ offsetTop(boundry = null)
362
+ {
363
+ return this.offset('top', boundry);
364
+ }
365
+
366
+ /**
367
+ * Get bottom offset
368
+ *
369
+ * @example Dom.find("div").offsetBottom()
370
+ *
371
+ * @param {any} [boundry] View boundry
372
+ * @returns {number} Bottom offset
373
+ */
374
+ offsetBottom(boundry = null)
375
+ {
376
+ return this.offset('bottom', boundry);
377
+ }
378
+
379
+ /**
380
+ * Get left offset
381
+ *
382
+ * @example Dom.find("div").offsetLeft()
383
+ *
384
+ * @param {any} [boundry] View boundry
385
+ * @returns {number} Left offset
386
+ */
387
+ offsetLeft(boundry = null)
388
+ {
389
+ return this.offset('left', boundry);
390
+ }
391
+
392
+ /**
393
+ * Get right offset
394
+ *
395
+ * @example Dom.find("div").offsetRight()
396
+ *
397
+ * @param {any} [boundry] View boundry
398
+ * @returns {number} Right offset
399
+ */
400
+ offsetRight(boundry = null)
401
+ {
402
+ return this.offset('right', boundry);
403
+ }
404
+
405
+ /**
406
+ * Loop through offset parents
407
+ *
408
+ * @example Dom.find("div").loopOffset((el) => console.log(el))
409
+ *
410
+ * @param {function} cb Callback fn
411
+ * @param {any} [boundry] Loop limit
412
+ * @returns {this} Current instance
413
+ */
414
+ loopOffset(cb, boundry = null)
415
+ {
416
+ if ( boundry == null ) {
417
+ boundry = Dom.body();
418
+ }
419
+
420
+ for ( let el = this.el; el && el !== boundry; el = el.offsetParent ) {
421
+ cb.call({}, el);
422
+ }
423
+
424
+ return this;
425
+ }
426
+
427
+ /**
428
+ * Calculate relative offset
429
+ *
430
+ * @example Dom.calcOffset(offset, 100, 100)
431
+ *
432
+ * @param {any} offset Base offset
433
+ * @param {number} width Element width
434
+ * @param {number} height Element height
435
+ * @returns {any} Calculated offset
436
+ */
437
+ calcOffset(offset, width, height)
438
+ {
439
+ let size = {
440
+ right: Dom.body().scrollWidth - offset.left - width,
441
+ bottom: Dom.body().scrollHeight - offset.top - height,
442
+ };
443
+
444
+ return { ...offset, ...size };
445
+ }
446
+
447
+ /**
448
+ * Get relative offset
449
+ *
450
+ * @example Dom.find("div").getOffset()
451
+ *
452
+ * @param {any} [boundry] View boundry
453
+ * @returns {any} Offset values
454
+ */
455
+ getOffset(boundry = null)
456
+ {
457
+ if ( boundry == null ) {
458
+ boundry = Dom.body();
459
+ }
460
+
461
+ let cb, source = {
462
+ top: 0, left: 0, bottom: 0, right: 0
463
+ };
464
+
465
+ if ( this.el == null ) {
466
+ return source;
467
+ }
468
+
469
+ cb = (el) => {
470
+ source.top += Dom.num(el.offsetTop, 0);
471
+ source.left += Dom.num(el.offsetLeft, 0);
472
+ };
473
+
474
+ this.loopOffset(cb);
475
+
476
+ source = this.calcOffset(...[
477
+ source, this.width(), this.height()
478
+ ]);
479
+
480
+ let body = Dom.find(boundry);
481
+
482
+ let target = {
483
+ top: 0, left: 0, bottom: 0, right: 0
484
+ };
485
+
486
+ cb = (el) => {
487
+ target.top += Dom.num(el.offsetTop, 0);
488
+ target.left += Dom.num(el.offsetLeft, 0);
489
+ };
490
+
491
+ body.loopOffset(cb);
492
+
493
+ target = this.calcOffset(...[
494
+ target, body.scrollWidth(), body.scrollHeight()
495
+ ]);
496
+
497
+ return {
498
+ top: source.top - target.top,
499
+ bottom: source.bottom - target.bottom,
500
+ left: source.left - target.left,
501
+ right: source.right - target.right
502
+ };
503
+ }
504
+
505
+ /**
506
+ * Get element scroll
507
+ *
508
+ * @example Dom.find("div").scroll()
509
+ *
510
+ * @param {any} [key] Scroll key
511
+ * @param {any} [boundry] View boundry
512
+ * @returns {any} Scroll values
513
+ */
514
+ scroll(key = null, boundry = null)
515
+ {
516
+ let scroll = this.getScroll(boundry);
517
+
518
+ if ( key == null ) {
519
+ return scroll;
520
+ }
521
+
522
+ return Obj.get(scroll, key, 0);
523
+ }
524
+
525
+ /**
526
+ * Get or set scroll top
527
+ *
528
+ * @example Dom.find("div").scrollTop(100)
529
+ *
530
+ * @param {any} [value] Scroll value
531
+ * @param {any} [boundry] View boundry
532
+ * @returns {number|this} Value or instance
533
+ */
534
+ scrollTop(value = null, boundry = null)
535
+ {
536
+ if ( value == null ) {
537
+ return this.scroll('top', boundry);
538
+ }
539
+
540
+ this.each((el) => {
541
+ el.scrollTop = value;
542
+ });
543
+
544
+ return this;
545
+ }
546
+
547
+ /**
548
+ * Get or set scroll left
549
+ *
550
+ * @example Dom.find("div").scrollLeft(100)
551
+ *
552
+ * @param {any} [value] Scroll value
553
+ * @param {any} [boundry] View boundry
554
+ * @returns {number|this} Value or instance
555
+ */
556
+ scrollLeft(value = null, boundry = null)
557
+ {
558
+ if ( value == null ) {
559
+ return this.scroll('left', boundry);
560
+ }
561
+
562
+ this.each((el) => {
563
+ el.scrollLeft = value;
564
+ });
565
+
566
+ return this.scroll('left', boundry);
567
+ }
568
+
569
+ /**
570
+ * Get relative scroll
571
+ *
572
+ * @example Dom.find("div").getScroll()
573
+ *
574
+ * @param {any} [boundry] View boundry
575
+ * @returns {any} Scroll values
576
+ */
577
+ getScroll(boundry = null)
578
+ {
579
+ if ( boundry == null ) {
580
+ boundry = Dom.win();
581
+ }
582
+
583
+ let cb, source = {
584
+ top: 0, left: 0
585
+ };
586
+
587
+ if ( this.el == null ) {
588
+ return source;
589
+ }
590
+
591
+ cb = (el) => {
592
+ source.top += Dom.num(el.scrollTop || el.pageYOffset || 0);
593
+ source.left += Dom.num(el.scrollLeft || el.pageXOffset || 0);
594
+ }
595
+
596
+ this.loopParent(cb);
597
+
598
+ let target = {
599
+ top: 0, left: 0
600
+ };
601
+
602
+ cb = (el) => {
603
+ target.top += Dom.num(el.scrollTop || el.pageYOffset || 0);
604
+ target.left += Dom.num(el.scrollLeft || el.pageXOffset || 0);
605
+ };
606
+
607
+ Dom.find(boundry).loopParent(cb);
608
+
609
+ return {
610
+ top: source.top - target.top,
611
+ left: source.left - target.left
612
+ };
613
+ }
614
+
615
+ }
616
+
617
+ /**
618
+ * @see PicoDom.loopOffsetParent
619
+ */
620
+ PicoDomRectangleInstance.prototype.loopOffsetParent = function (...args) {
621
+ console.warn('Dom.loopOffsetParent() is deprecated, use Dom.loopOffset() instead.');
622
+ return this.loopOffset(...args);
623
+ };
624
+
625
+ /**
626
+ * @see PicoDom.scrollTopGlobal
627
+ */
628
+ PicoDomRectangleInstance.prototype.scrollTopGlobal = function () {
629
+ console.warn('Dom.scrollTopGlobal() is deprecated, use Dom.scroll(\'top\') instead.');
630
+ return this.scroll('top', null);
631
+ };
632
+
633
+ /**
634
+ * @see PicoDom.scrollLeftGlobal
635
+ */
636
+ PicoDomRectangleInstance.prototype.scrollLeftGlobal = function () {
637
+ console.warn('Dom.scrollLeftGlobal() is deprecated, use Dom.scroll(\'left\') instead.');
638
+ return this.scroll('left', null);
639
+ };
640
+
641
+ /**
642
+ * @returns {typeof import('#src/utils/Dom.js').PicoDom}
643
+ */
644
+ export const PicoDomRectanglePlugin = function (self) {
645
+
646
+ Obj.each(Mix.class(PicoDomRectangleStatic), (fn, id) => {
647
+ self[id] = fn;
648
+ });
649
+
650
+ Obj.each(Mix.proto(PicoDomRectangleInstance), (fn, id) => {
651
+ self.prototype[id] = fn;
652
+ });
653
+
654
+ // self.init.push(PicoDomRectangleInstance.constructor);
655
+
656
+ return self;
657
+ }
@@ -0,0 +1,54 @@
1
+ import { Mix, Obj, Num } from "#src/index.esm.js";
2
+
3
+ export const FILE_UNITS = [
4
+ 'B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'
5
+ ];
6
+
7
+ /**
8
+ * @memberof PicoFormat
9
+ * @extends {PicoFormat}
10
+ */
11
+ export class PicoFormatFileStatic
12
+ {
13
+
14
+ /**
15
+ * Format file size
16
+ *
17
+ * @example Format.filesize(1000) // => "1.0 KB"
18
+ *
19
+ * @param {any} value Bytes value
20
+ * @param {number} [decimals] Decimal points
21
+ * @returns {string} Formatted size
22
+ */
23
+ static filesize(value, decimals = 1)
24
+ {
25
+ if ( ! Mix.isNum(value) ) {
26
+ value = Mix.num(value, 0);
27
+ }
28
+
29
+ let fn = (i) => {
30
+ return Num.fixed(value / Math.pow(1000, i), decimals);
31
+ }
32
+
33
+ for ( let i = 0; i < FILE_UNITS.length; i++ ) {
34
+ if ( value <= Math.pow(1000, i+1) ) {
35
+ return fn(i) + ' ' + FILE_UNITS[i]
36
+ }
37
+ }
38
+
39
+ return fn(FILE_UNITS.length);
40
+ }
41
+
42
+ }
43
+
44
+ /**
45
+ * @returns {typeof import('#src/utils/Format.js').PicoFormat}
46
+ */
47
+ export const PicoFormatFilePlugin = function (self) {
48
+
49
+ Obj.each(Mix.class(PicoFormatFileStatic), (fn, id) => {
50
+ self[id] = fn;
51
+ });
52
+
53
+ return self;
54
+ }