@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
package/package.json CHANGED
@@ -1,48 +1,61 @@
1
1
  {
2
2
  "name": "@kizmann/pico-js",
3
- "version": "1.0.13",
3
+ "version": "2.0.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "private": false,
7
7
  "author": "Eduard Kizmann <kizmann@protonmail.ch>",
8
8
  "repository": "https://github.com/vankizmann/pico-js",
9
- "main": "src/index.js",
10
- "unpkg": "dist/pico-js.js",
9
+ "main": "src/index.esm.js",
10
+ "unpkg": "dist/pico-js.browser.js",
11
11
  "types": "types/index.d.ts",
12
+ "imports": {
13
+ "#src/*": "./src/*"
14
+ },
12
15
  "files": [
13
16
  "dist/",
14
17
  "src/",
15
18
  "types/",
16
19
  "package.json"
17
20
  ],
21
+ "publishConfig": {
22
+ "access": "public",
23
+ "provenance": true
24
+ },
18
25
  "scripts": {
19
26
  "build": "webpack --mode production --config webpack.config.cjs",
20
- "watch": "webpack --watch --mode development --config webpack.config.cjs"
27
+ "watch": "webpack --watch --mode development --config webpack.config.cjs",
28
+ "test:unit": "node --test ./tests/unit.test.js",
29
+ "test:load": "node ./tests/load.test.js"
21
30
  },
22
31
  "devDependencies": {
23
32
  "@babel/core": "^7.4.5",
24
33
  "@babel/plugin-proposal-class-properties": "^7.4.4",
25
34
  "@babel/plugin-proposal-export-default-from": "^7.2.0",
26
35
  "@babel/plugin-proposal-object-rest-spread": "^7.4.4",
36
+ "@babel/plugin-transform-runtime": "^7.28.5",
27
37
  "@babel/preset-env": "^7.4.4",
28
38
  "babel-loader": "^8.0.6",
29
39
  "cross-env": "^5.1",
30
40
  "css-loader": "^3.2.0",
31
41
  "html-webpack-plugin": "^5.0.0",
42
+ "lodash": "^4.17.23",
32
43
  "mini-css-extract-plugin": "^2.0.0",
44
+ "mitata": "^1.0.34",
33
45
  "postcss": "^8.4.31",
34
46
  "postcss-inline-svg": "^5.0.0",
35
47
  "postcss-loader": "^5.0.0",
36
48
  "sass": "^1.87.0",
37
49
  "sass-loader": "^12.0.0",
38
50
  "terser-webpack-plugin": "^4.2.3",
39
- "uuid": "^3.3.2",
51
+ "tinybench": "^6.0.0",
52
+ "tsc-alias": "^1.8.16",
53
+ "typescript": "^5.9.3",
40
54
  "webpack": "^5.0.0",
41
55
  "webpack-cli": "^4.0.0",
42
56
  "webpack-dev-server": "^4.0.0"
43
57
  },
44
58
  "dependencies": {
45
- "docsify": "^4.13.1",
46
- "moment": "^2.30.1"
59
+ "docsify": "^4.13.1"
47
60
  }
48
61
  }
@@ -0,0 +1,374 @@
1
+ import { Arr, Dom, For, Mix, Obj } from "#src/index.esm.js";
2
+
3
+ /**
4
+ * @memberof PicoDom
5
+ */
6
+ export class PicoDomAttributeStatic
7
+ {
8
+ //
9
+ }
10
+
11
+ /**
12
+ * @memberof PicoDom
13
+ * @extends {PicoDom}
14
+ */
15
+ export class PicoDomAttributeInstance
16
+ {
17
+ /**
18
+ * Get or set attribute
19
+ *
20
+ * @example Dom.find("div").attr("id")
21
+ *
22
+ * @param {string} key Attr key
23
+ * @param {any} [value] Attr value
24
+ * @param {any} [fallback] Fallback value
25
+ * @returns {any|this} Attr value or instance
26
+ */
27
+ attr(key, value = undefined, fallback = null)
28
+ {
29
+ if ( this.el == null ) {
30
+ return value ? this : fallback;
31
+ }
32
+
33
+ let attr = this.el.getAttribute(key);
34
+
35
+ if ( Mix.isUndef(value) ) {
36
+ return attr || fallback;
37
+ }
38
+
39
+ if ( value === null ) {
40
+ return (this.el.removeAttribute(key), attr);
41
+ }
42
+
43
+ if ( Mix.isArr(value) ) {
44
+ value = value.join(' ');
45
+ }
46
+
47
+ if ( Mix.isObj(value) ) {
48
+ value = For.castOptions(value);
49
+ }
50
+
51
+ this.el.setAttribute(key, value);
52
+
53
+ return this;
54
+ }
55
+
56
+ /**
57
+ * Get or set data attribute
58
+ *
59
+ * @example Dom.find("div").data("id")
60
+ *
61
+ * @param {string} key Data key
62
+ * @param {any} [value] Data value
63
+ * @param {any} [fallback] Fallback value
64
+ * @returns {any|this} Data value or instance
65
+ */
66
+ data(key, value = undefined, fallback = null)
67
+ {
68
+ return this.attr('data-' + key, value, fallback);
69
+ }
70
+
71
+ /**
72
+ * Get computed style
73
+ *
74
+ * @example Dom.find("div").computed("width")
75
+ *
76
+ * @param {any} [key] Style key
77
+ * @param {any} [fallback] Fallback value
78
+ * @returns {any} Computed style
79
+ */
80
+ computed(key = null, fallback = null)
81
+ {
82
+ if ( this.el == null ) {
83
+ return fallback;
84
+ }
85
+
86
+ if ( this.getNodeType() !== 1 ) {
87
+ return fallback;
88
+ }
89
+
90
+ let computed = getComputedStyle(this.el);
91
+
92
+ if ( key == null ) {
93
+ return computed;
94
+ }
95
+
96
+ return Obj.get(computed, key, fallback);
97
+ }
98
+
99
+ /**
100
+ * Get or set style
101
+ *
102
+ * @example Dom.find("div").style({ color: "red" })
103
+ *
104
+ * @param {any} [value] Style value
105
+ * @param {boolean} [combine] Combine style
106
+ * @returns {any|this} Style or instance
107
+ */
108
+ style(value = undefined, combine = true)
109
+ {
110
+ if ( this.el == null ) {
111
+ return this;
112
+ }
113
+
114
+ if ( value === null ) {
115
+ return this.attr('style', null);
116
+ }
117
+
118
+ let styles = this.attr('style', undefined, {});
119
+
120
+ if ( Mix.isStr(styles) ) {
121
+ styles = For.parseOptions(styles);
122
+ }
123
+
124
+ if ( Mix.isUndef(value) ) {
125
+ return styles;
126
+ }
127
+
128
+ if ( combine ) {
129
+ value = { ...styles, ...value };
130
+ }
131
+
132
+ this.attr('style', value);
133
+
134
+ return this;
135
+ }
136
+
137
+ /**
138
+ * Get or set classes
139
+ *
140
+ * @example Dom.find("div").class(["active"])
141
+ *
142
+ * @param {any} [value] Class value
143
+ * @param {boolean} [combine] Combine classes
144
+ * @returns {any|this} Classes or instance
145
+ */
146
+ class(value = undefined, combine = false)
147
+ {
148
+ if ( this.el == null ) {
149
+ return this;
150
+ }
151
+
152
+ if ( value === null ) {
153
+ return this.attr('class', '');
154
+ }
155
+
156
+ let classes = this.attr('class', undefined, []);
157
+
158
+ if ( Mix.isStr(classes) ) {
159
+ classes = classes.split(' ');
160
+ }
161
+
162
+ if ( Mix.isUndef(value) ) {
163
+ return classes;
164
+ }
165
+
166
+ if ( combine ) {
167
+ value = [...classes, ...value];
168
+ }
169
+
170
+ this.attr('class', value);
171
+
172
+ return this;
173
+ }
174
+
175
+ /**
176
+ * Get or set inner HTML
177
+ *
178
+ * @example Dom.find("div").html("<span></span>")
179
+ *
180
+ * @param {any} [html] HTML content
181
+ * @returns {string|this} HTML or instance
182
+ */
183
+ html(html = undefined)
184
+ {
185
+ if ( html === undefined ) {
186
+ return this.el.innerHTML;
187
+ }
188
+
189
+ this.each((el) => {
190
+ el.innerHTML = html;
191
+ });
192
+
193
+ return this;
194
+ }
195
+
196
+ /**
197
+ * Get actual style value
198
+ *
199
+ * @example Dom.find("div").actual((el) => el.offsetWidth, { display: "block" })
200
+ *
201
+ * @param {function} cb Callback fn
202
+ * @param {any} [style] Temp style
203
+ * @returns {any} Callback result
204
+ */
205
+ actual(cb, style = null)
206
+ {
207
+ let backup = this.attr('style');
208
+
209
+ this.style(style);
210
+
211
+ let result = cb(this.el, this.el);
212
+
213
+ this.attr('style', backup);
214
+
215
+ return result;
216
+ }
217
+
218
+ /**
219
+ * Check if has class
220
+ *
221
+ * @example Dom.find("div").hasClass("active") // => true
222
+ *
223
+ * @param {any} cls Class name
224
+ * @returns {boolean} True if has class
225
+ */
226
+ hasClass(cls)
227
+ {
228
+ if ( ! Mix.isArr(cls) ) {
229
+ cls = [cls];
230
+ }
231
+
232
+ return Arr.isect(this.class(), cls).length > 0;
233
+ }
234
+
235
+ /**
236
+ * Add class to element
237
+ *
238
+ * @example Dom.find("div").addClass("active")
239
+ *
240
+ * @param {any} cls Class name
241
+ * @returns {this} Current instance
242
+ */
243
+ addClass(cls)
244
+ {
245
+ if ( this.el == null ) {
246
+ return this;
247
+ }
248
+
249
+ if ( this.els.length > 1 ) {
250
+ return this.each((el) => Dom.find(el).addClass(cls));
251
+ }
252
+
253
+ let result = this.el.className.split(' ');
254
+
255
+ if ( Mix.isStr(cls) ) {
256
+ cls = cls.split(' ');
257
+ }
258
+
259
+ result = Arr.append(result, ...cls);
260
+
261
+ this.el.className = Arr.unique(result).join(' ');
262
+
263
+ return this;
264
+ }
265
+
266
+ /**
267
+ * Remove class from element
268
+ *
269
+ * @example Dom.find("div").remClass("active")
270
+ *
271
+ * @param {any} cls Class name
272
+ * @returns {this} Current instance
273
+ */
274
+ remClass(cls)
275
+ {
276
+ if ( this.el == null ) {
277
+ return this;
278
+ }
279
+
280
+ if ( this.els.length > 1 ) {
281
+ return this.each((el) => Dom.find(el).remClass(cls));
282
+ }
283
+
284
+ let result = this.el.className.split(' ');
285
+
286
+ if ( Mix.isStr(cls) ) {
287
+ cls = cls.split(' ');
288
+ }
289
+
290
+ result = Arr.diff(result, cls);
291
+
292
+ this.el.className = Arr.unique(result).join(' ');
293
+
294
+ return this;
295
+ }
296
+
297
+ /**
298
+ * Toggle class on element
299
+ *
300
+ * @example Dom.find("div").toggleClass("active")
301
+ *
302
+ * @param {any} cls Class name
303
+ * @returns {this} Current instance
304
+ */
305
+ toggleClass(cls)
306
+ {
307
+ if ( this.els.length > 1 ) {
308
+ return this.each((el) => Dom.find(el).toggleClass(cls));
309
+ }
310
+
311
+ if ( this.hasClass(cls) ) {
312
+ return this.remClass(cls);
313
+ }
314
+
315
+ return this.addClass(cls);
316
+ }
317
+
318
+ /**
319
+ * Set class by state
320
+ *
321
+ * @example Dom.find("div").stateClass("active", true)
322
+ *
323
+ * @param {any} cls Class name
324
+ * @param {boolean} [state] Target state
325
+ * @returns {this} Current instance
326
+ */
327
+ stateClass(cls, state = true)
328
+ {
329
+ if ( this.els.length > 1 ) {
330
+ return this.each((el) => Dom.find(el).stateClass(cls));
331
+ }
332
+
333
+ if ( ! state ) {
334
+ return this.remClass(cls);
335
+ }
336
+
337
+ return this.addClass(cls);
338
+ }
339
+
340
+ }
341
+
342
+ /**
343
+ * @see PicoDom.style
344
+ */
345
+ PicoDomAttributeInstance.prototype.css = function (...args) {
346
+ console.warn('Dom.css() is deprecated, use Dom.style() instead.');
347
+ return this.style(...args);
348
+ };
349
+
350
+ /**
351
+ * @see PicoDom.remClass
352
+ */
353
+ PicoDomAttributeInstance.prototype.removeClass = function (...args) {
354
+ console.warn('Dom.removeClass() is deprecated, use Dom.remClass() instead.');
355
+ return this.remClass(...args);
356
+ };
357
+
358
+ /**
359
+ * @returns {typeof import('#src/utils/Dom.js').PicoDom}
360
+ */
361
+ export const PicoDomAttributePlugin = function (self) {
362
+
363
+ Obj.each(Mix.class(PicoDomAttributeStatic), (fn, id) => {
364
+ self[id] = fn;
365
+ });
366
+
367
+ Obj.each(Mix.proto(PicoDomAttributeInstance), (fn, id) => {
368
+ self.prototype[id] = fn;
369
+ });
370
+
371
+ // self.init.push(PicoDomAttributeInstance.constructor);
372
+
373
+ return self;
374
+ }
@@ -0,0 +1,152 @@
1
+ import { Arr, Dom, Mix, Obj } from "#src/index.esm.js";
2
+
3
+ /**
4
+ * @memberof PicoDom
5
+ */
6
+ export class PicoDomBuilderStatic
7
+ {
8
+ /**
9
+ * Create element from tag
10
+ *
11
+ * @example Dom.make("div", { class: "active" })
12
+ *
13
+ * @param {any} el Tag or element
14
+ * @param {any} [options] Attr options
15
+ * @returns {PicoDom} Dom instance
16
+ */
17
+ static make(el, options = {})
18
+ {
19
+ if ( el instanceof Dom ) {
20
+ el = el.el;
21
+ }
22
+
23
+ if ( Mix.isStr(el) ) {
24
+ el = document.createElement(el);
25
+ }
26
+
27
+ el = Obj.assign(el, options);
28
+
29
+ let ini = new Dom(el);
30
+
31
+ if ( options.class ) {
32
+ ini.class(options.class);
33
+ }
34
+
35
+ if ( options.html ) {
36
+ ini.html(options.html);
37
+ }
38
+
39
+ return ini;
40
+ }
41
+ }
42
+
43
+ /**
44
+ * @memberof PicoDom
45
+ * @extends {PicoDom}
46
+ */
47
+ export class PicoDomBuilderInstance
48
+ {
49
+ /**
50
+ * Prepend value to element
51
+ *
52
+ * @example Dom.find("div").prepend("<span></span>")
53
+ *
54
+ * @param {any} value Prepend value
55
+ * @returns {this} Current instance
56
+ */
57
+ prepend(value)
58
+ {
59
+ this.each((el) => {
60
+ if ( el.prepend != null ) el.prepend(value);
61
+ });
62
+
63
+ return this;
64
+ }
65
+
66
+ /**
67
+ * Prepend element to value
68
+ *
69
+ * @example Dom.find("span").prependTo("div")
70
+ *
71
+ * @param {any} value Target element
72
+ * @returns {this} Current instance
73
+ */
74
+ prependTo(value)
75
+ {
76
+ Dom.find(value).each((el) => {
77
+ if ( el.prepend != null ) el.prepend(this.el);
78
+ });
79
+
80
+ return this;
81
+ }
82
+
83
+ /**
84
+ * Append value to element
85
+ *
86
+ * @example Dom.find("div").append("<span></span>")
87
+ *
88
+ * @param {any} value Append value
89
+ * @returns {this} Current instance
90
+ */
91
+ append(value)
92
+ {
93
+ this.each((el) => {
94
+ if ( el.append != null ) el.append(value);
95
+ });
96
+
97
+ return this;
98
+ }
99
+
100
+ /**
101
+ * Append element to value
102
+ *
103
+ * @example Dom.find("span").appendTo("div")
104
+ *
105
+ * @param {any} value Target element
106
+ * @returns {this} Current instance
107
+ */
108
+ appendTo(value)
109
+ {
110
+ Dom.find(value).each((el) => {
111
+ if ( el.append != null ) el.append(this.el);
112
+ });
113
+
114
+ return this;
115
+ }
116
+
117
+ /**
118
+ * Replace element with value
119
+ *
120
+ * @example Dom.find("div").replace("<span></span>")
121
+ *
122
+ * @param {any} value Replacement value
123
+ * @returns {this} Current instance
124
+ */
125
+ replace(value)
126
+ {
127
+ this.parent().each(el, (el) => {
128
+ (el.insertBefore(value, el), el.removeChild(el));
129
+ });
130
+
131
+ return this;
132
+ }
133
+
134
+ }
135
+
136
+ /**
137
+ * @returns {typeof import('#src/utils/Dom.js').PicoDom}
138
+ */
139
+ export const PicoDomBuilderPlugin = function (self) {
140
+
141
+ Obj.each(Mix.class(PicoDomBuilderStatic), (fn, id) => {
142
+ self[id] = fn;
143
+ });
144
+
145
+ Obj.each(Mix.proto(PicoDomBuilderInstance), (fn, id) => {
146
+ self.prototype[id] = fn;
147
+ });
148
+
149
+ // self.init.push(PicoDomBuilderInstance.constructor);
150
+
151
+ return self;
152
+ }