@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,253 @@
1
+ import { Arr, Hash, Mix, Obj, Dom } from "#src/index.esm.js";
2
+
3
+ /**
4
+ * @memberof PicoDom
5
+ */
6
+ export class PicoDomEventStatic
7
+ {
8
+ static events = [];
9
+ }
10
+
11
+ /**
12
+ * @memberof PicoDom
13
+ * @extends {PicoDom}
14
+ */
15
+ export class PicoDomEventInstance
16
+ {
17
+
18
+ /**
19
+ * Bind event listener
20
+ *
21
+ * @example Dom.bind(el, "click", cb)
22
+ *
23
+ * @param {Element} el Target element
24
+ * @param {string} event Event name
25
+ * @param {function} cb Callback fn
26
+ * @param {string} [selector] Event selector
27
+ * @param {boolean} [pause] Pause listener
28
+ * @param {any} [options] Listener options
29
+ * @returns {this} Current instance
30
+ */
31
+ bind(el, event, cb, selector = null, pause = false, options = {})
32
+ {
33
+ if ( Mix.isPrim(options) ) {
34
+ options = { id: options };
35
+ }
36
+
37
+ Dom.events = Arr.append(Dom.events, {
38
+ el, event, cb, selector, pause, options
39
+ });
40
+
41
+ el.addEventListener(event, cb, options);
42
+
43
+ return this;
44
+ }
45
+
46
+ /**
47
+ * Unbind event listener
48
+ *
49
+ * @example Dom.unbind(el, "click")
50
+ *
51
+ * @param {Element} el Target element
52
+ * @param {string} event Event name
53
+ * @param {string} [selector] Event selector
54
+ * @param {any} [options] Listener options
55
+ * @returns {this} Current instance
56
+ */
57
+ unbind(el, event, selector = null, options = {})
58
+ {
59
+ if ( Mix.isPrim(options) ) {
60
+ options = { id: options };
61
+ }
62
+
63
+ let indexes = Arr.filterIndex(Dom.events, {
64
+ el, event, selector, options
65
+ });
66
+
67
+ if ( indexes.length === 0 ) {
68
+ return;
69
+ }
70
+
71
+ let args = (val) => {
72
+ return [event, val.cb, val.options];
73
+ };
74
+
75
+ Arr.each(indexes.reverse(), (index) => {
76
+ el.removeEventListener(...args(Dom.events[index]));
77
+ });
78
+
79
+ Arr.splices(Dom.events, indexes);
80
+
81
+ return this;
82
+ }
83
+
84
+ /**
85
+ * Listen to event
86
+ *
87
+ * @example Dom.find("div").on("click", cb)
88
+ *
89
+ * @param {any} event Event name
90
+ * @param {function} cb Callback fn
91
+ * @param {any} [options] Listener options
92
+ * @param {boolean} [pause] Pause listener
93
+ * @param {string} [selector] Event selector
94
+ * @returns {this} Current instance
95
+ */
96
+ on(event, cb, options = {}, pause = false, selector = null)
97
+ {
98
+ if ( Mix.isPrim(options) ) {
99
+ options = { id: options };
100
+ }
101
+
102
+ if ( Mix.isArr(event) ) {
103
+ return (Arr.each(event, (e) => this.on(e, ...arguments)), this);
104
+ }
105
+
106
+ let fn = (e) => {
107
+ cb.call(e.target, e, e.target);
108
+ };
109
+
110
+ this.each((el) => {
111
+ this.bind(el, event, fn, selector, pause, options);
112
+ });
113
+
114
+ return this;
115
+ }
116
+
117
+ /**
118
+ * Stop listening to event
119
+ *
120
+ * @example Dom.find("div").off("click")
121
+ *
122
+ * @param {any} event Event name
123
+ * @param {string} [selector] Event selector
124
+ * @param {any} [options] Listener options
125
+ * @returns {this} Current instance
126
+ */
127
+ off(event, selector = null, options = {})
128
+ {
129
+ if ( Mix.isArr(event) ) {
130
+ return (Arr.each(event, (e) => this.off(e, ...arguments)), this);
131
+ }
132
+
133
+ if ( Mix.isObj(selector) ) {
134
+ (options = selector, selector = null);
135
+ }
136
+
137
+ this.each((el) => {
138
+ this.unbind(el, event, selector, options);
139
+ });
140
+
141
+ return this;
142
+ }
143
+
144
+ /**
145
+ * Listen to event once
146
+ *
147
+ * @example Dom.find("div").once("click", cb)
148
+ *
149
+ * @param {any} event Event name
150
+ * @param {function} cb Callback fn
151
+ * @param {any} [options] Listener options
152
+ * @returns {this} Current instance
153
+ */
154
+ once(event, cb, options = {})
155
+ {
156
+ options.id = Hash.make(24);
157
+
158
+ this.on(event, (e) => {
159
+ cb(e); this.off(event, options);
160
+ }, options);
161
+
162
+ return this;
163
+ }
164
+
165
+ /**
166
+ * Listen to live event
167
+ *
168
+ * @example Dom.find("div").live("click", "span", cb)
169
+ *
170
+ * @param {any} event Event name
171
+ * @param {string} selector Event selector
172
+ * @param {function} cb Callback fn
173
+ * @param {any} [options] Listener options
174
+ * @param {boolean} [pause] Pause listener
175
+ * @returns {this} Current instance
176
+ */
177
+ live(event, selector, cb, options = {}, pause = false)
178
+ {
179
+ let fn = function (event) {
180
+
181
+ let target = Dom.getNodeEvent(selector, event);
182
+
183
+ if ( target == null ) {
184
+ return;
185
+ }
186
+
187
+ cb.call({}, event, target);
188
+ };
189
+
190
+ this.on(event, fn, options, pause, selector);
191
+
192
+ return this;
193
+ }
194
+
195
+ /**
196
+ * Fire event on element
197
+ *
198
+ * @example Dom.find("div").fire("click")
199
+ *
200
+ * @param {string} event Event name
201
+ * @returns {this} Current instance
202
+ */
203
+ fire(event)
204
+ {
205
+ let callback = new Event(event);
206
+
207
+ this.each((el) => {
208
+ el.dispatchEvent(callback);
209
+ });
210
+
211
+ return this;
212
+ }
213
+
214
+ }
215
+
216
+ /**
217
+ * @see PicoDom.once
218
+ */
219
+ PicoDomEventInstance.prototype.one = function (...args) {
220
+ console.warn('Dom.one() is deprecated, use Dom.once() instead.');
221
+ return this.once(...args);
222
+ };
223
+
224
+
225
+ PicoDomEventInstance.prototype.delayed = function () {
226
+ console.error('Dom.delayed() is not implemented anymore.');
227
+ };
228
+
229
+ PicoDomEventInstance.prototype.pause = function () {
230
+ console.error('Dom.pause() is not implemented anymore.');
231
+ };
232
+
233
+ PicoDomEventInstance.prototype.unpause = function () {
234
+ console.error('Dom.unpause() is not implemented anymore.');
235
+ };
236
+
237
+ /**
238
+ * @returns {typeof import('#src/utils/Dom.js').PicoDom}
239
+ */
240
+ export const PicoDomEventPlugin = function (self) {
241
+
242
+ Obj.each(Mix.class(PicoDomEventStatic), (fn, id) => {
243
+ self[id] = fn;
244
+ });
245
+
246
+ Obj.each(Mix.proto(PicoDomEventInstance), (fn, id) => {
247
+ self.prototype[id] = fn;
248
+ });
249
+
250
+ // self.init.push(PicoDomEventInstance.constructor);
251
+
252
+ return self;
253
+ }