@kizmann/pico-js 1.0.14 → 2.0.1

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 (124) 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 +19 -7
  7. package/src/dom/DomAttribute.js +376 -0
  8. package/src/dom/DomBuilder.js +154 -0
  9. package/src/dom/DomEvent.js +255 -0
  10. package/src/dom/DomFinder.js +671 -0
  11. package/src/dom/DomForm.js +59 -0
  12. package/src/dom/DomGlobal.js +195 -0
  13. package/src/dom/DomInview.js +334 -0
  14. package/src/dom/DomMeta.js +68 -0
  15. package/src/dom/DomObserver.js +59 -0
  16. package/src/dom/DomRectangle.js +658 -0
  17. package/src/format/FormatFile.js +56 -0
  18. package/src/format/FormatOption.js +110 -0
  19. package/src/format/FormatParam.js +109 -0
  20. package/src/format/FormatParser.js +158 -0
  21. package/src/format/FormatUrl.js +77 -0
  22. package/src/index.browser.js +31 -0
  23. package/src/index.esm.js +116 -0
  24. package/src/now/NowDefault.js +535 -0
  25. package/src/now/NowFormat.js +198 -0
  26. package/src/now/NowGrid.js +253 -0
  27. package/src/now/NowHuman.js +120 -0
  28. package/src/now/NowMatch.js +177 -0
  29. package/src/now/NowRange.js +72 -0
  30. package/src/now/NowWalker.js +546 -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 +138 -0
  50. package/types/dom/DomBuilder.d.ts +68 -0
  51. package/types/dom/DomEvent.d.ts +104 -0
  52. package/types/dom/DomFinder.d.ts +322 -0
  53. package/types/dom/DomForm.d.ts +22 -0
  54. package/types/dom/DomGlobal.d.ts +80 -0
  55. package/types/dom/DomInview.d.ts +115 -0
  56. package/types/dom/DomMeta.d.ts +30 -0
  57. package/types/dom/DomObserver.d.ts +22 -0
  58. package/types/dom/DomRectangle.d.ts +271 -0
  59. package/types/format/FormatFile.d.ts +19 -0
  60. package/types/format/FormatOption.d.ts +41 -0
  61. package/types/format/FormatParam.d.ts +40 -0
  62. package/types/format/FormatParser.d.ts +47 -0
  63. package/types/format/FormatUrl.d.ts +18 -0
  64. package/types/index.esm.d.ts +78 -0
  65. package/types/now/NowDefault.d.ts +184 -0
  66. package/types/now/NowFormat.d.ts +71 -0
  67. package/types/now/NowGrid.d.ts +108 -0
  68. package/types/now/NowHuman.d.ts +38 -0
  69. package/types/now/NowMatch.d.ts +109 -0
  70. package/types/now/NowRange.d.ts +22 -0
  71. package/types/now/NowWalker.d.ts +302 -0
  72. package/types/tool/scope.d.ts +24 -0
  73. package/types/utils/Array.d.ts +480 -0
  74. package/types/utils/Cookie.d.ts +60 -0
  75. package/types/utils/Data.d.ts +91 -0
  76. package/types/utils/Dom.d.ts +138 -0
  77. package/types/utils/Event.d.ts +58 -0
  78. package/types/utils/Format.d.ts +37 -0
  79. package/types/utils/Hash.d.ts +81 -0
  80. package/types/utils/Locale.d.ts +115 -0
  81. package/types/utils/Mixed.d.ts +469 -0
  82. package/types/utils/Now.d.ts +125 -0
  83. package/types/utils/Number.d.ts +127 -0
  84. package/types/utils/Object.d.ts +255 -0
  85. package/types/utils/Route.d.ts +37 -0
  86. package/types/utils/Runner.d.ts +139 -0
  87. package/types/utils/String.d.ts +330 -0
  88. package/types/wip/Element.d.ts +119 -0
  89. package/types/wip/Map.d.ts +254 -0
  90. package/dist/.ignore.js +0 -0
  91. package/dist/pico-js.js +0 -2
  92. package/dist/pico-js.js.map +0 -1
  93. package/src/element/default.js +0 -46
  94. package/src/element/example.js +0 -58
  95. package/src/index.js +0 -90
  96. package/src/library/cookie.js +0 -123
  97. package/src/library/data.js +0 -111
  98. package/src/library/event.js +0 -91
  99. package/src/library/locale.js +0 -84
  100. package/src/library/queue.js +0 -64
  101. package/src/library/route.js +0 -28
  102. package/src/utility/any.js +0 -369
  103. package/src/utility/array.js +0 -410
  104. package/src/utility/dom.js +0 -1425
  105. package/src/utility/now.js +0 -544
  106. package/src/utility/number.js +0 -128
  107. package/src/utility/object.js +0 -429
  108. package/src/utility/string.js +0 -328
  109. package/types/index.d.ts +0 -77
  110. package/types/library/cookie.d.ts +0 -10
  111. package/types/library/data.d.ts +0 -15
  112. package/types/library/element.d.ts +0 -22
  113. package/types/library/event.d.ts +0 -13
  114. package/types/library/locale.d.ts +0 -14
  115. package/types/library/map.d.ts +0 -43
  116. package/types/library/queue.d.ts +0 -18
  117. package/types/library/route.d.ts +0 -11
  118. package/types/utility/any.d.ts +0 -35
  119. package/types/utility/array.d.ts +0 -46
  120. package/types/utility/dom.d.ts +0 -101
  121. package/types/utility/now.d.ts +0 -79
  122. package/types/utility/number.d.ts +0 -17
  123. package/types/utility/object.d.ts +0 -29
  124. package/types/utility/string.d.ts +0 -26
package/package.json CHANGED
@@ -1,48 +1,60 @@
1
1
  {
2
2
  "name": "@kizmann/pico-js",
3
- "version": "1.0.14",
3
+ "version": "2.0.1",
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
+ "typescript": "^5.9.3",
40
53
  "webpack": "^5.0.0",
41
54
  "webpack-cli": "^4.0.0",
42
55
  "webpack-dev-server": "^4.0.0"
43
56
  },
44
57
  "dependencies": {
45
- "docsify": "^4.13.1",
46
- "moment": "^2.30.1"
58
+ "docsify": "^4.13.1"
47
59
  }
48
60
  }
@@ -0,0 +1,376 @@
1
+ import { Arr, Dom, For, Mix, Obj } from "../index.esm.js";
2
+ import { PicoDom } from "../utils/Dom.js";
3
+
4
+ /**
5
+ * @memberof PicoDom
6
+ */
7
+ export class PicoDomAttributeStatic
8
+ {
9
+ //
10
+ }
11
+
12
+ /**
13
+ * @memberof PicoDom
14
+ * @extends {PicoDom}
15
+ */
16
+ export class PicoDomAttributeInstance
17
+ {
18
+ /**
19
+ * Get or set attribute
20
+ *
21
+ * @example Dom.find("div").attr("id")
22
+ *
23
+ * @param {string} key Attr key
24
+ * @param {any} [value] Attr value
25
+ * @param {any} [fallback] Fallback value
26
+ * @returns {any|PicoDom} Attr value or instance
27
+ */
28
+ attr(key, value = undefined, fallback = null)
29
+ {
30
+ if ( this.el == null ) {
31
+ return value ? this : fallback;
32
+ }
33
+
34
+ let attr = this.el.getAttribute(key);
35
+
36
+ if ( Mix.isUndef(value) ) {
37
+ return attr || fallback;
38
+ }
39
+
40
+ if ( value === null ) {
41
+ return (this.el.removeAttribute(key), attr);
42
+ }
43
+
44
+ if ( Mix.isArr(value) ) {
45
+ value = value.join(' ');
46
+ }
47
+
48
+ if ( Mix.isObj(value) ) {
49
+ value = For.castOptions(value);
50
+ }
51
+
52
+ this.el.setAttribute(key, value);
53
+
54
+ return this;
55
+ }
56
+
57
+ /**
58
+ * Get or set data attribute
59
+ *
60
+ * @example Dom.find("div").data("id")
61
+ *
62
+ * @param {string} key Data key
63
+ * @param {any} [value] Data value
64
+ * @param {any} [fallback] Fallback value
65
+ * @returns {any|PicoDom} Data value or instance
66
+ */
67
+ data(key, value = undefined, fallback = null)
68
+ {
69
+ return this.attr('data-' + key, value, fallback);
70
+ }
71
+
72
+ /**
73
+ * Get computed style
74
+ *
75
+ * @example Dom.find("div").computed("width")
76
+ *
77
+ * @param {any} [key] Style key
78
+ * @param {any} [fallback] Fallback value
79
+ * @returns {any} Computed style
80
+ */
81
+ computed(key = null, fallback = null)
82
+ {
83
+ if ( this.el == null ) {
84
+ return fallback;
85
+ }
86
+
87
+ if ( this.getNodeType() !== 1 ) {
88
+ return fallback;
89
+ }
90
+
91
+ let computed = getComputedStyle(this.el);
92
+
93
+ if ( key == null ) {
94
+ return computed;
95
+ }
96
+
97
+ return Obj.get(computed, key, fallback);
98
+ }
99
+
100
+ /**
101
+ * Get or set style
102
+ *
103
+ * @example Dom.find("div").style({ color: "red" })
104
+ *
105
+ * @param {any} [value] Style value
106
+ * @param {boolean} [combine] Combine style
107
+ * @returns {any|PicoDom} Style or instance
108
+ */
109
+ style(value = undefined, combine = true)
110
+ {
111
+ if ( this.el == null ) {
112
+ return this;
113
+ }
114
+
115
+ if ( value === null ) {
116
+ return this.attr('style', null);
117
+ }
118
+
119
+ let styles = this.attr('style', undefined, {});
120
+
121
+ if ( Mix.isStr(styles) ) {
122
+ styles = For.parseOptions(styles);
123
+ }
124
+
125
+ if ( Mix.isUndef(value) ) {
126
+ return styles;
127
+ }
128
+
129
+ if ( combine ) {
130
+ value = { ...styles, ...value };
131
+ }
132
+
133
+ this.attr('style', value);
134
+
135
+ return this;
136
+ }
137
+
138
+ /**
139
+ * Get or set classes
140
+ *
141
+ * @example Dom.find("div").class(["active"])
142
+ *
143
+ * @param {any} [value] Class value
144
+ * @param {boolean} [combine] Combine classes
145
+ * @returns {any|PicoDom} Classes or instance
146
+ */
147
+ class(value = undefined, combine = false)
148
+ {
149
+ if ( this.el == null ) {
150
+ return this;
151
+ }
152
+
153
+ if ( value === null ) {
154
+ return this.attr('class', '');
155
+ }
156
+
157
+ let classes = this.attr('class', undefined, []);
158
+
159
+ if ( Mix.isStr(classes) ) {
160
+ classes = classes.split(' ');
161
+ }
162
+
163
+ if ( Mix.isUndef(value) ) {
164
+ return classes;
165
+ }
166
+
167
+ if ( combine ) {
168
+ value = [...classes, ...value];
169
+ }
170
+
171
+ this.attr('class', value);
172
+
173
+ return this;
174
+ }
175
+
176
+ /**
177
+ * Get or set inner HTML
178
+ *
179
+ * @example Dom.find("div").html("<span></span>")
180
+ *
181
+ * @param {any} [html] HTML content
182
+ * @returns {string|PicoDom} HTML or instance
183
+ */
184
+ html(html = undefined)
185
+ {
186
+ if ( html === undefined ) {
187
+ return this.el.innerHTML;
188
+ }
189
+
190
+ this.each((el) => {
191
+ el.innerHTML = html;
192
+ });
193
+
194
+ return this;
195
+ }
196
+
197
+ /**
198
+ * Get actual style value
199
+ *
200
+ * @example Dom.find("div").actual((el) => el.offsetWidth, { display: "block" })
201
+ *
202
+ * @param {function} cb Callback fn
203
+ * @param {any} [style] Temp style
204
+ * @returns {any} Callback result
205
+ */
206
+ actual(cb, style = null)
207
+ {
208
+ let backup = this.attr('style');
209
+
210
+ this.style(style);
211
+
212
+ let result = cb(this.el, this.el);
213
+
214
+ this.attr('style', backup);
215
+
216
+ return result;
217
+ }
218
+
219
+ /**
220
+ * Check if has class
221
+ *
222
+ * @example Dom.find("div").hasClass("active") // => true
223
+ *
224
+ * @param {any} cls Class name
225
+ * @returns {boolean} True if has class
226
+ */
227
+ hasClass(cls)
228
+ {
229
+ if ( ! Mix.isArr(cls) ) {
230
+ cls = [cls];
231
+ }
232
+
233
+ return Arr.isect(this.class(), cls).length > 0;
234
+ }
235
+
236
+ /**
237
+ * Add class to element
238
+ *
239
+ * @example Dom.find("div").addClass("active")
240
+ *
241
+ * @param {any} cls Class name
242
+ * @returns {PicoDom} Current instance
243
+ */
244
+ addClass(cls)
245
+ {
246
+ if ( this.el == null ) {
247
+ return this;
248
+ }
249
+
250
+ if ( this.els.length > 1 ) {
251
+ return this.each((el) => Dom.find(el).addClass(cls));
252
+ }
253
+
254
+ let result = this.el.className.split(' ');
255
+
256
+ if ( Mix.isStr(cls) ) {
257
+ cls = cls.split(' ');
258
+ }
259
+
260
+ result = Arr.append(result, ...cls);
261
+
262
+ this.el.className = Arr.unique(result).join(' ');
263
+
264
+ return this;
265
+ }
266
+
267
+ /**
268
+ * Remove class from element
269
+ *
270
+ * @example Dom.find("div").remClass("active")
271
+ *
272
+ * @param {any} cls Class name
273
+ * @returns {PicoDom} Current instance
274
+ */
275
+ remClass(cls)
276
+ {
277
+ if ( this.el == null ) {
278
+ return this;
279
+ }
280
+
281
+ if ( this.els.length > 1 ) {
282
+ return this.each((el) => Dom.find(el).remClass(cls));
283
+ }
284
+
285
+ let result = this.el.className.split(' ');
286
+
287
+ if ( Mix.isStr(cls) ) {
288
+ cls = cls.split(' ');
289
+ }
290
+
291
+ result = Arr.diff(result, cls);
292
+
293
+ this.el.className = Arr.unique(result).join(' ');
294
+
295
+ return this;
296
+ }
297
+
298
+ /**
299
+ * Toggle class on element
300
+ *
301
+ * @example Dom.find("div").toggleClass("active")
302
+ *
303
+ * @param {any} cls Class name
304
+ * @returns {PicoDom} Current instance
305
+ */
306
+ toggleClass(cls)
307
+ {
308
+ if ( this.els.length > 1 ) {
309
+ return this.each((el) => Dom.find(el).toggleClass(cls));
310
+ }
311
+
312
+ if ( this.hasClass(cls) ) {
313
+ return this.remClass(cls);
314
+ }
315
+
316
+ return this.addClass(cls);
317
+ }
318
+
319
+ /**
320
+ * Set class by state
321
+ *
322
+ * @example Dom.find("div").stateClass("active", true)
323
+ *
324
+ * @param {any} cls Class name
325
+ * @param {boolean} [state] Target state
326
+ * @returns {PicoDom} Current instance
327
+ */
328
+ stateClass(cls, state = true)
329
+ {
330
+ if ( this.els.length > 1 ) {
331
+ return this.each((el) => Dom.find(el).stateClass(cls));
332
+ }
333
+
334
+ if ( ! state ) {
335
+ return this.remClass(cls);
336
+ }
337
+
338
+ return this.addClass(cls);
339
+ }
340
+
341
+ }
342
+
343
+ /**
344
+ * @see PicoDom.style
345
+ */
346
+ PicoDomAttributeInstance.prototype.css = function (...args) {
347
+ console.warn('Dom.css() is deprecated, use Dom.style() instead.');
348
+ return this.style(...args);
349
+ };
350
+
351
+ /**
352
+ * @see PicoDom.remClass
353
+ */
354
+ PicoDomAttributeInstance.prototype.removeClass = function (...args) {
355
+ console.warn('Dom.removeClass() is deprecated, use Dom.remClass() instead.');
356
+ return this.remClass(...args);
357
+ };
358
+
359
+ /**
360
+ * @param {typeof PicoDom} self
361
+ * @returns {typeof PicoDom}
362
+ */
363
+ export const PicoDomAttributePlugin = function (self) {
364
+
365
+ Obj.each(Mix.class(PicoDomAttributeStatic), (fn, id) => {
366
+ self[id] = fn;
367
+ });
368
+
369
+ Obj.each(Mix.proto(PicoDomAttributeInstance), (fn, id) => {
370
+ self.prototype[id] = fn;
371
+ });
372
+
373
+ // self.init.push(PicoDomAttributeInstance.constructor);
374
+
375
+ return self;
376
+ }
@@ -0,0 +1,154 @@
1
+ import { Arr, Dom, Mix, Obj } from "../index.esm.js";
2
+ import { PicoDom } from "../utils/Dom.js";
3
+
4
+ /**
5
+ * @memberof PicoDom
6
+ */
7
+ export class PicoDomBuilderStatic
8
+ {
9
+ /**
10
+ * Create element from tag
11
+ *
12
+ * @example Dom.make("div", { class: "active" })
13
+ *
14
+ * @param {any} el Tag or element
15
+ * @param {any} [options] Attr options
16
+ * @returns {PicoDom} Dom instance
17
+ */
18
+ static make(el, options = {})
19
+ {
20
+ if ( el instanceof Dom ) {
21
+ el = el.el;
22
+ }
23
+
24
+ if ( Mix.isStr(el) ) {
25
+ el = document.createElement(el);
26
+ }
27
+
28
+ el = Obj.assign(el, options);
29
+
30
+ let ini = new Dom(el);
31
+
32
+ if ( options.class ) {
33
+ ini.class(options.class);
34
+ }
35
+
36
+ if ( options.html ) {
37
+ ini.html(options.html);
38
+ }
39
+
40
+ return ini;
41
+ }
42
+ }
43
+
44
+ /**
45
+ * @memberof PicoDom
46
+ * @extends {PicoDom}
47
+ */
48
+ export class PicoDomBuilderInstance
49
+ {
50
+ /**
51
+ * Prepend value to element
52
+ *
53
+ * @example Dom.find("div").prepend("<span></span>")
54
+ *
55
+ * @param {any} value Prepend value
56
+ * @returns {PicoDom} Current instance
57
+ */
58
+ prepend(value)
59
+ {
60
+ this.each((el) => {
61
+ if ( el.prepend != null ) el.prepend(value);
62
+ });
63
+
64
+ return this;
65
+ }
66
+
67
+ /**
68
+ * Prepend element to value
69
+ *
70
+ * @example Dom.find("span").prependTo("div")
71
+ *
72
+ * @param {any} value Target element
73
+ * @returns {PicoDom} Current instance
74
+ */
75
+ prependTo(value)
76
+ {
77
+ Dom.find(value).each((el) => {
78
+ if ( el.prepend != null ) el.prepend(this.el);
79
+ });
80
+
81
+ return this;
82
+ }
83
+
84
+ /**
85
+ * Append value to element
86
+ *
87
+ * @example Dom.find("div").append("<span></span>")
88
+ *
89
+ * @param {any} value Append value
90
+ * @returns {PicoDom} Current instance
91
+ */
92
+ append(value)
93
+ {
94
+ this.each((el) => {
95
+ if ( el.append != null ) el.append(value);
96
+ });
97
+
98
+ return this;
99
+ }
100
+
101
+ /**
102
+ * Append element to value
103
+ *
104
+ * @example Dom.find("span").appendTo("div")
105
+ *
106
+ * @param {any} value Target element
107
+ * @returns {PicoDom} Current instance
108
+ */
109
+ appendTo(value)
110
+ {
111
+ Dom.find(value).each((el) => {
112
+ if ( el.append != null ) el.append(this.el);
113
+ });
114
+
115
+ return this;
116
+ }
117
+
118
+ /**
119
+ * Replace element with value
120
+ *
121
+ * @example Dom.find("div").replace("<span></span>")
122
+ *
123
+ * @param {any} value Replacement value
124
+ * @returns {PicoDom} Current instance
125
+ */
126
+ replace(value)
127
+ {
128
+ this.parent().each(el, (el) => {
129
+ (el.insertBefore(value, el), el.removeChild(el));
130
+ });
131
+
132
+ return this;
133
+ }
134
+
135
+ }
136
+
137
+ /**
138
+ * @param {typeof PicoDom} self
139
+ * @returns {typeof PicoDom}
140
+ */
141
+ export const PicoDomBuilderPlugin = function (self) {
142
+
143
+ Obj.each(Mix.class(PicoDomBuilderStatic), (fn, id) => {
144
+ self[id] = fn;
145
+ });
146
+
147
+ Obj.each(Mix.proto(PicoDomBuilderInstance), (fn, id) => {
148
+ self.prototype[id] = fn;
149
+ });
150
+
151
+ // self.init.push(PicoDomBuilderInstance.constructor);
152
+
153
+ return self;
154
+ }