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