ranuts 0.1.0-alpha → 0.1.0-alpha.2

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.
package/dist/index.js CHANGED
@@ -1,66 +1,129 @@
1
- const fs = require("fs");
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => {
4
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ return value;
6
+ };
7
+ import fs from "node:fs";
8
+ let fileSystem = fs;
9
+ if (typeof process !== "undefined" && typeof fileSystem.Stats === "function") {
10
+ fileSystem._identification = true;
11
+ } else {
12
+ fileSystem = { _identification: false, message: "require is not defined" };
13
+ }
14
+ const fs$1 = fileSystem;
2
15
  const writeFile = (path, content) => new Promise((resolve, reject) => {
3
- fs.writeFile(path, content, {
4
- mode: 438,
5
- flag: "w+",
6
- encoding: "utf-8"
7
- }, (err) => {
8
- if (err) {
9
- reject({ status: false, data: err });
10
- throw err;
11
- } else {
12
- resolve({ status: true, data: { path, content } });
16
+ if (!fs$1._identification)
17
+ return reject({ _identification: false, data: "fs is not loaded" });
18
+ fs$1.writeFile(
19
+ path,
20
+ content,
21
+ {
22
+ mode: 438,
23
+ flag: "w+",
24
+ encoding: "utf-8"
25
+ },
26
+ (err) => {
27
+ if (err) {
28
+ reject({ _identification: false, data: err });
29
+ throw err;
30
+ } else {
31
+ resolve({ _identification: true, data: { path, content } });
32
+ }
13
33
  }
14
- });
34
+ );
15
35
  });
16
36
  const readFile = (path, format = "utf-8") => new Promise((resolve, reject) => {
17
- fs.readFile(path, format, (err, data) => {
18
- err ? reject({ status: false, data: err }) : resolve({ status: true, data });
37
+ if (!fs$1._identification)
38
+ return reject({ _identification: false, data: "fs is not loaded" });
39
+ fs$1.readFile(path, format, (err, data) => {
40
+ err ? reject({ _identification: false, data: err }) : resolve({ _identification: true, data });
19
41
  });
20
42
  });
21
43
  const watchFile = (path, interval = 20) => new Promise((resolve, reject) => {
22
- fs.watchFile(path, { interval }, (curr, prev) => {
44
+ if (!fs$1._identification)
45
+ return reject({ _identification: false, data: "fs is not loaded" });
46
+ fs$1.watchFile(path, { interval }, (curr, prev) => {
23
47
  if (curr.mtime !== prev.mtime) {
24
- fs.unwatchFile(path);
25
- resolve({ status: true, data: { msg: "file is changed" } });
48
+ fs$1.unwatchFile(path);
49
+ resolve({ _identification: true, data: { msg: "file is changed" } });
26
50
  } else {
27
- resolve({ status: false, data: { msg: "file is not changed" } });
51
+ resolve({
52
+ _identification: false,
53
+ data: { msg: "file is not changed" }
54
+ });
28
55
  }
29
56
  });
30
57
  });
31
- class EventEmitter {
58
+ class Subscribe {
32
59
  constructor() {
33
- this.on = (eventName, callback) => {
60
+ __publicField(this, "_events");
61
+ __publicField(this, "on", (eventName, eventItem) => {
34
62
  if (this._events[eventName] && eventName !== Symbol.for("new-listener")) {
35
63
  this.emit(Symbol.for("new-listener"), eventName);
36
64
  }
37
65
  const callbacks = this._events[eventName] || [];
38
- callbacks.push(callback);
66
+ if (typeof eventItem === "function") {
67
+ callbacks.push({
68
+ name: eventName,
69
+ callback: eventItem
70
+ });
71
+ } else {
72
+ callbacks.push(eventItem);
73
+ }
39
74
  this._events[eventName] = callbacks;
40
- };
41
- this.emit = (eventName, ...args) => {
75
+ });
76
+ __publicField(this, "emit", (eventName, ...args) => {
42
77
  const callbacks = this._events[eventName] || [];
43
- callbacks.forEach((cb) => cb(...args));
44
- };
45
- this.once = (eventName, callback) => {
46
- const one = (...args) => {
78
+ callbacks.forEach((item) => {
79
+ const { callback } = item;
47
80
  callback(...args);
48
- this.off(eventName, one);
49
- };
50
- one.initialCallback = callback;
81
+ });
82
+ });
83
+ __publicField(this, "once", (eventName, eventItem) => {
84
+ let one;
85
+ if (typeof eventItem === "function") {
86
+ one = {
87
+ name: eventName,
88
+ callback: (...args) => {
89
+ eventItem(...args);
90
+ this.off(eventName, one);
91
+ },
92
+ initialCallback: eventItem
93
+ };
94
+ } else {
95
+ const { callback } = eventItem;
96
+ one = {
97
+ name: eventName,
98
+ callback: (...args) => {
99
+ callback(...args);
100
+ this.off(eventName, one);
101
+ },
102
+ initialCallback: callback
103
+ };
104
+ }
51
105
  this.on(eventName, one);
52
- };
53
- this.off = (eventName, callback) => {
106
+ });
107
+ __publicField(this, "off", (eventName, eventItem) => {
54
108
  const callbacks = this._events[eventName] || [];
55
- const newCallbacks = callbacks.filter((fn) => fn != callback && fn.initialCallback != callback);
109
+ const newCallbacks = callbacks.filter((item) => {
110
+ if (typeof eventItem === "function") {
111
+ return item.callback !== eventItem && item.initialCallback !== eventItem;
112
+ } else {
113
+ const { callback } = eventItem;
114
+ return item.callback !== callback && item.initialCallback !== callback;
115
+ }
116
+ });
56
117
  this._events[eventName] = newCallbacks;
57
- };
118
+ });
58
119
  this._events = {};
59
120
  }
60
121
  }
61
122
  const queryFileInfo = (path) => new Promise((resolve, reject) => {
62
- fs.stat(path, (err, data) => {
63
- err ? reject({ status: false, data: err }) : resolve({ status: true, data });
123
+ if (!fs$1._identification)
124
+ return reject({ _identification: false, data: "fs is not loaded" });
125
+ fs$1.stat(path, (err, data) => {
126
+ err ? reject({ _identification: false, data: err }) : resolve({ _identification: true, data });
64
127
  });
65
128
  });
66
129
  const filterObj = (obj, list) => {
@@ -72,15 +135,986 @@ const filterObj = (obj, list) => {
72
135
  });
73
136
  return result;
74
137
  };
75
- const index = {
76
- writeFile,
77
- readFile,
78
- watchFile,
79
- EventEmitter,
80
- queryFileInfo,
81
- filterObj
138
+ const readDir = (options) => {
139
+ const { dirPath } = options;
140
+ try {
141
+ return fs$1.readdirSync(dirPath);
142
+ } catch (error) {
143
+ console.log("readDir error", error);
144
+ throw error;
145
+ }
146
+ };
147
+ const str2Xml = (xmlStr, format = "text/xml") => {
148
+ if (window.DOMParser)
149
+ return new window.DOMParser().parseFromString(xmlStr, format).documentElement;
150
+ if (typeof window.ActiveXObject !== "undefined" && new window.ActiveXObject("Microsoft.XMLDOM")) {
151
+ const xmlDoc = new window.ActiveXObject("Microsoft.XMLDOM");
152
+ xmlDoc.async = "false";
153
+ xmlDoc.loadXML(xmlStr);
154
+ return xmlDoc;
155
+ }
156
+ return void 0;
157
+ };
158
+ function vnode$1(sel, data, children, text, elm) {
159
+ const key = data === void 0 ? void 0 : data.key;
160
+ return { sel, data, children, text, elm, key };
161
+ }
162
+ function createElement(tagName2, options) {
163
+ return document.createElement(tagName2, options);
164
+ }
165
+ function createElementNS(namespaceURI, qualifiedName, options) {
166
+ return document.createElementNS(namespaceURI, qualifiedName, options);
167
+ }
168
+ function createDocumentFragment() {
169
+ return parseFragment(document.createDocumentFragment());
170
+ }
171
+ function createTextNode(text) {
172
+ return document.createTextNode(text);
173
+ }
174
+ function createComment(text) {
175
+ return document.createComment(text);
176
+ }
177
+ function insertBefore(parentNode2, newNode, referenceNode) {
178
+ if (isDocumentFragment(parentNode2)) {
179
+ let node = parentNode2;
180
+ while (node && isDocumentFragment(node)) {
181
+ const fragment = parseFragment(node);
182
+ node = fragment.parent;
183
+ }
184
+ parentNode2 = node != null ? node : parentNode2;
185
+ }
186
+ if (isDocumentFragment(newNode)) {
187
+ newNode = parseFragment(newNode, parentNode2);
188
+ }
189
+ if (referenceNode && isDocumentFragment(referenceNode)) {
190
+ referenceNode = parseFragment(referenceNode).firstChildNode;
191
+ }
192
+ parentNode2.insertBefore(newNode, referenceNode);
193
+ }
194
+ function removeChild(node, child) {
195
+ node.removeChild(child);
196
+ }
197
+ function appendChild(node, child) {
198
+ if (isDocumentFragment(child)) {
199
+ child = parseFragment(child, node);
200
+ }
201
+ node.appendChild(child);
202
+ }
203
+ function parentNode(node) {
204
+ if (isDocumentFragment(node)) {
205
+ while (node && isDocumentFragment(node)) {
206
+ const fragment = parseFragment(node);
207
+ node = fragment.parent;
208
+ }
209
+ return node != null ? node : null;
210
+ }
211
+ return node.parentNode;
212
+ }
213
+ function nextSibling(node) {
214
+ var _a;
215
+ if (isDocumentFragment(node)) {
216
+ const fragment = parseFragment(node);
217
+ const parent = parentNode(fragment);
218
+ if (parent && fragment.lastChildNode) {
219
+ const children = Array.from(parent.childNodes);
220
+ const index = children.indexOf(fragment.lastChildNode);
221
+ return (_a = children[index + 1]) != null ? _a : null;
222
+ }
223
+ return null;
224
+ }
225
+ return node.nextSibling;
226
+ }
227
+ function tagName(elm) {
228
+ return elm.tagName;
229
+ }
230
+ function setTextContent(node, text) {
231
+ node.textContent = text;
232
+ }
233
+ function getTextContent(node) {
234
+ return node.textContent;
235
+ }
236
+ function isElement(node) {
237
+ return node.nodeType === 1;
238
+ }
239
+ function isText(node) {
240
+ return node.nodeType === 3;
241
+ }
242
+ function isComment(node) {
243
+ return node.nodeType === 8;
244
+ }
245
+ function isDocumentFragment(node) {
246
+ return node.nodeType === 11;
247
+ }
248
+ function parseFragment(fragmentNode, parentNode2) {
249
+ var _a, _b, _c;
250
+ const fragment = fragmentNode;
251
+ (_a = fragment.parent) != null ? _a : fragment.parent = parentNode2 != null ? parentNode2 : null;
252
+ (_b = fragment.firstChildNode) != null ? _b : fragment.firstChildNode = fragmentNode.firstChild;
253
+ (_c = fragment.lastChildNode) != null ? _c : fragment.lastChildNode = fragmentNode.lastChild;
254
+ return fragment;
255
+ }
256
+ const htmlDomApi = {
257
+ createElement,
258
+ createElementNS,
259
+ createTextNode,
260
+ createDocumentFragment,
261
+ createComment,
262
+ insertBefore,
263
+ removeChild,
264
+ appendChild,
265
+ parentNode,
266
+ nextSibling,
267
+ tagName,
268
+ setTextContent,
269
+ getTextContent,
270
+ isElement,
271
+ isText,
272
+ isComment,
273
+ isDocumentFragment
274
+ };
275
+ const array = Array.isArray;
276
+ function primitive(s) {
277
+ return typeof s === "string" || typeof s === "number";
278
+ }
279
+ function isVnode$1(s) {
280
+ return !!(s == null ? void 0 : s.sel);
281
+ }
282
+ const xlinkNS = "http://www.w3.org/1999/xlink";
283
+ const xmlNS = "http://www.w3.org/XML/1998/namespace";
284
+ const colonChar = 58;
285
+ const xChar = 120;
286
+ function updateAttrs(oldVnode, vnode2) {
287
+ let key;
288
+ const elm = vnode2.elm;
289
+ let oldAttrs = oldVnode.data && oldVnode.data.attrs;
290
+ let attrs = vnode2.data && vnode2.data.attrs;
291
+ if (!oldAttrs && !attrs)
292
+ return;
293
+ if (oldAttrs === attrs)
294
+ return;
295
+ oldAttrs = oldAttrs || {};
296
+ attrs = attrs || {};
297
+ for (key in attrs) {
298
+ const cur = attrs[key];
299
+ const old = oldAttrs[key];
300
+ if (old !== cur) {
301
+ if (cur === true) {
302
+ elm.setAttribute(key, "");
303
+ } else if (cur === false) {
304
+ elm.removeAttribute(key);
305
+ } else {
306
+ if (key.charCodeAt(0) !== xChar) {
307
+ elm.setAttribute(key, cur);
308
+ } else if (key.charCodeAt(3) === colonChar) {
309
+ elm.setAttributeNS(xmlNS, key, cur);
310
+ } else if (key.charCodeAt(5) === colonChar) {
311
+ elm.setAttributeNS(xlinkNS, key, cur);
312
+ } else {
313
+ elm.setAttribute(key, `${cur}`);
314
+ }
315
+ }
316
+ }
317
+ }
318
+ for (key in oldAttrs) {
319
+ if (!(key in attrs)) {
320
+ elm.removeAttribute(key);
321
+ }
322
+ }
323
+ }
324
+ const attributesModule = { create: updateAttrs, update: updateAttrs };
325
+ function updateClass(oldVnode, vnode2) {
326
+ let cur;
327
+ let name;
328
+ const elm = vnode2.elm;
329
+ let oldClass = oldVnode.data && oldVnode.data.class;
330
+ let className = vnode2.data && vnode2.data.class;
331
+ if (!oldClass && !className)
332
+ return;
333
+ if (oldClass === className)
334
+ return;
335
+ oldClass = oldClass || {};
336
+ className = className || {};
337
+ for (name in oldClass) {
338
+ if (oldClass[name] && !Object.prototype.hasOwnProperty.call(className, name)) {
339
+ elm.classList.remove(name);
340
+ }
341
+ }
342
+ for (name in className) {
343
+ cur = className[name];
344
+ if (cur !== oldClass[name]) {
345
+ elm.classList[cur ? "add" : "remove"](name);
346
+ }
347
+ }
348
+ }
349
+ const classModule = { create: updateClass, update: updateClass };
350
+ const isFunction = (handler) => {
351
+ return typeof handler === "function";
352
+ };
353
+ function invokeHandler(handler, vnode2, event) {
354
+ if (isFunction(handler)) {
355
+ handler.call(vnode2, event, vnode2);
356
+ } else if (typeof handler === "object") {
357
+ for (let i = 0; i < handler.length; i++) {
358
+ invokeHandler(handler[i], vnode2, event);
359
+ }
360
+ }
361
+ }
362
+ function handleEvent(event, vnode2) {
363
+ const name = event.type;
364
+ const on = vnode2.data && vnode2.data.on;
365
+ if (on && on[name]) {
366
+ invokeHandler(on[name], vnode2, event);
367
+ }
368
+ }
369
+ function createListener() {
370
+ return function handler(event) {
371
+ handleEvent(event, handler.vnode);
372
+ };
373
+ }
374
+ function updateEventListeners(oldVnode, vnode2) {
375
+ var _a, _b;
376
+ const oldOn = (_a = oldVnode == null ? void 0 : oldVnode.data) == null ? void 0 : _a.on;
377
+ const oldListener = oldVnode == null ? void 0 : oldVnode.listener;
378
+ const oldElm = oldVnode.elm;
379
+ const on = (_b = vnode2 == null ? void 0 : vnode2.data) == null ? void 0 : _b.on;
380
+ const elm = vnode2 && vnode2.elm;
381
+ let name;
382
+ if (oldOn === on) {
383
+ return;
384
+ }
385
+ if (oldOn && oldListener) {
386
+ if (!on) {
387
+ for (name in oldOn) {
388
+ oldElm.removeEventListener(name, oldListener, false);
389
+ }
390
+ } else {
391
+ for (name in oldOn) {
392
+ if (!on[name]) {
393
+ oldElm.removeEventListener(name, oldListener, false);
394
+ }
395
+ }
396
+ }
397
+ }
398
+ if (on) {
399
+ const listener = vnode2.listener = oldVnode.listener || createListener();
400
+ if (!oldOn) {
401
+ for (name in on) {
402
+ elm.addEventListener(name, listener, false);
403
+ }
404
+ } else {
405
+ for (name in on) {
406
+ if (!oldOn[name]) {
407
+ elm.addEventListener(name, listener, false);
408
+ }
409
+ }
410
+ }
411
+ }
412
+ }
413
+ const eventListenersModule = {
414
+ create: updateEventListeners,
415
+ update: updateEventListeners,
416
+ destroy: updateEventListeners
417
+ };
418
+ function updateProps(oldVnode, vnode2) {
419
+ let key;
420
+ let cur;
421
+ let old;
422
+ const elm = vnode2.elm;
423
+ let oldProps = oldVnode.data ? oldVnode.data.props : void 0;
424
+ let props = vnode2.data ? vnode2.data.props : void 0;
425
+ if (!oldProps && !props)
426
+ return;
427
+ if (oldProps === props)
428
+ return;
429
+ oldProps = oldProps || {};
430
+ props = props || {};
431
+ for (key in props) {
432
+ cur = props[key];
433
+ old = oldProps[key];
434
+ if (old !== cur && (key !== "value" || elm[key] !== cur)) {
435
+ elm[key] = cur;
436
+ }
437
+ }
438
+ }
439
+ const propsModule = { create: updateProps, update: updateProps };
440
+ let reflowForced = false;
441
+ function updateStyle(oldVnode, vnode2) {
442
+ let cur;
443
+ let name;
444
+ const elm = vnode2.elm;
445
+ let oldStyle = oldVnode.data.style;
446
+ let style = vnode2.data.style;
447
+ if (!oldStyle && !style)
448
+ return;
449
+ if (oldStyle === style)
450
+ return;
451
+ oldStyle = oldStyle || {};
452
+ style = style || {};
453
+ for (name in oldStyle) {
454
+ if (!style[name]) {
455
+ if (name[0] === "-" && name[1] === "-") {
456
+ elm.style.removeProperty(name);
457
+ } else {
458
+ elm.style[name] = "";
459
+ }
460
+ }
461
+ }
462
+ for (name in style) {
463
+ cur = style[name];
464
+ if (cur !== oldStyle[name]) {
465
+ if (name[0] === "-" && name[1] === "-") {
466
+ elm.style.setProperty(name, cur);
467
+ } else {
468
+ elm.style[name] = cur;
469
+ }
470
+ }
471
+ }
472
+ }
473
+ function forceReflow() {
474
+ reflowForced = false;
475
+ }
476
+ function applyDestroyStyle(vnode2) {
477
+ let style;
478
+ let name;
479
+ const elm = vnode2.elm;
480
+ const s = vnode2.data.style;
481
+ if (!s || !(style = s.destroy))
482
+ return;
483
+ for (name in style) {
484
+ elm.style[name] = style[name];
485
+ }
486
+ }
487
+ function applyRemoveStyle(vnode2, rm) {
488
+ const s = vnode2.data.style;
489
+ if (!s || !s.remove) {
490
+ rm();
491
+ return;
492
+ }
493
+ if (!reflowForced) {
494
+ vnode2.elm.offsetLeft;
495
+ reflowForced = true;
496
+ }
497
+ let name;
498
+ const elm = vnode2.elm;
499
+ let i = 0;
500
+ const style = s.remove;
501
+ let amount = 0;
502
+ const applied = [];
503
+ for (name in style) {
504
+ applied.push(name);
505
+ elm.style[name] = style[name];
506
+ }
507
+ const compStyle = getComputedStyle(elm);
508
+ const props = compStyle["transition-property"].split(", ");
509
+ for (; i < props.length; ++i) {
510
+ if (applied.indexOf(props[i]) !== -1)
511
+ amount++;
512
+ }
513
+ elm.addEventListener(
514
+ "transitionend",
515
+ function(ev) {
516
+ if (ev.target === elm)
517
+ --amount;
518
+ if (amount === 0)
519
+ rm();
520
+ }
521
+ );
522
+ }
523
+ const styleModule = {
524
+ pre: forceReflow,
525
+ create: updateStyle,
526
+ update: updateStyle,
527
+ destroy: applyDestroyStyle,
528
+ remove: applyRemoveStyle
529
+ };
530
+ const modules = {
531
+ attributesModule,
532
+ classModule,
533
+ eventListenersModule,
534
+ propsModule,
535
+ styleModule
536
+ };
537
+ function sameVnode(vnode1, vnode2) {
538
+ return vnode1.key === vnode2.key && vnode1.sel === vnode2.sel;
539
+ }
540
+ function isVnode(vnode2) {
541
+ return vnode2.sel !== void 0;
542
+ }
543
+ function createKeyToOldIdx(children, beginIdx, endIdx) {
544
+ var _a;
545
+ const map = {};
546
+ for (let i = beginIdx; i <= endIdx; ++i) {
547
+ const key = (_a = children[i]) == null ? void 0 : _a.key;
548
+ if (key !== void 0) {
549
+ map[key] = i;
550
+ }
551
+ }
552
+ return map;
553
+ }
554
+ const emptyNode = vnode$1("", {}, [], void 0, void 0);
555
+ function init() {
556
+ const api = htmlDomApi;
557
+ const cbs = {
558
+ create: [],
559
+ update: [],
560
+ destroy: []
561
+ };
562
+ for (const key of Object.keys(cbs)) {
563
+ cbs[key] = [];
564
+ for (const module of Object.keys(modules)) {
565
+ const hook = modules[module][key];
566
+ if (hook !== void 0) {
567
+ cbs[key].push(hook);
568
+ }
569
+ }
570
+ }
571
+ function emptyNodeAt(elm) {
572
+ const id = elm.id ? "#" + elm.id : "";
573
+ const c = elm.className ? "." + elm.className.split(" ").join(".") : "";
574
+ return vnode$1(
575
+ api.tagName(elm).toLowerCase() + id + c,
576
+ {},
577
+ [],
578
+ void 0,
579
+ elm
580
+ );
581
+ }
582
+ function isUndef(s) {
583
+ return s === void 0;
584
+ }
585
+ function isDef(s) {
586
+ return s !== void 0;
587
+ }
588
+ function createElm(vnode2) {
589
+ let i;
590
+ const children = vnode2.children;
591
+ const sel = vnode2.sel;
592
+ if (sel === "!") {
593
+ if (isUndef(vnode2.text)) {
594
+ vnode2.text = "";
595
+ }
596
+ vnode2.elm = api.createComment(`${vnode2.text}`);
597
+ } else if (sel !== void 0) {
598
+ const hashIdx = sel.indexOf("#");
599
+ const dotIdx = sel.indexOf(".", hashIdx);
600
+ const hash = hashIdx > 0 ? hashIdx : sel.length;
601
+ const dot = dotIdx > 0 ? dotIdx : sel.length;
602
+ const tag = hashIdx !== -1 || dotIdx !== -1 ? sel.slice(0, Math.min(hash, dot)) : sel;
603
+ const elm = vnode2.elm = api.createElement(tag);
604
+ if (hash < dot)
605
+ elm.setAttribute("id", sel.slice(hash + 1, dot));
606
+ if (dotIdx > 0)
607
+ elm.setAttribute("class", sel.slice(dot + 1).replace(/\./g, " "));
608
+ for (i = 0; i < cbs.create.length; ++i) {
609
+ cbs.create[i](emptyNode, vnode2);
610
+ }
611
+ if (array(children)) {
612
+ for (i = 0; i < children.length; ++i) {
613
+ const ch = children[i];
614
+ if (ch != null) {
615
+ api.appendChild(elm, createElm(ch));
616
+ }
617
+ }
618
+ } else if (primitive(vnode2.text)) {
619
+ api.appendChild(elm, api.createTextNode(`${vnode2.text}`));
620
+ }
621
+ } else {
622
+ vnode2.elm = api.createTextNode(`${vnode2.text}`);
623
+ }
624
+ return vnode2.elm;
625
+ }
626
+ function addVnodes(parentElm, before, vnodes, startIdx, endIdx) {
627
+ for (; startIdx <= endIdx; ++startIdx) {
628
+ const ch = vnodes[startIdx];
629
+ if (ch != null) {
630
+ api.insertBefore(parentElm, createElm(ch), before);
631
+ }
632
+ }
633
+ }
634
+ function invokeDestroyHook(vnode2) {
635
+ const data = vnode2.data;
636
+ if (data !== void 0) {
637
+ for (let i = 0; i < cbs.destroy.length; ++i)
638
+ cbs.destroy[i](vnode2);
639
+ if (vnode2.children !== void 0) {
640
+ for (let j = 0; j < vnode2.children.length; ++j) {
641
+ const child = vnode2.children[j];
642
+ if (child != null && typeof child !== "string" && typeof child !== "number") {
643
+ invokeDestroyHook(child);
644
+ }
645
+ }
646
+ }
647
+ }
648
+ }
649
+ function createRmCb(childElm) {
650
+ return function rmCb() {
651
+ const parent = api.parentNode(childElm);
652
+ api.removeChild(parent, childElm);
653
+ };
654
+ }
655
+ function removeVnodes(parentElm, vnodes, startIdx, endIdx) {
656
+ for (; startIdx <= endIdx; ++startIdx) {
657
+ let rm;
658
+ const ch = vnodes[startIdx];
659
+ if (ch != null) {
660
+ if (isDef(ch.sel)) {
661
+ invokeDestroyHook(ch);
662
+ rm = createRmCb(ch.elm);
663
+ rm();
664
+ } else {
665
+ api.removeChild(parentElm, ch.elm);
666
+ }
667
+ }
668
+ }
669
+ }
670
+ function updateChildren(parentElm, oldCh, newCh) {
671
+ let oldStartIdx = 0;
672
+ let newStartIdx = 0;
673
+ let oldEndIdx = oldCh.length - 1;
674
+ let newEndIdx = newCh.length - 1;
675
+ let oldStartVnode = oldCh[0];
676
+ let oldEndVnode = oldCh[oldEndIdx];
677
+ let newStartVnode = newCh[0];
678
+ let newEndVnode = newCh[newEndIdx];
679
+ let oldKeyToIdx;
680
+ let idxInOld;
681
+ let elmToMove;
682
+ let before;
683
+ while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
684
+ if (oldStartVnode == null) {
685
+ oldStartVnode = oldCh[++oldStartIdx];
686
+ } else if (oldEndVnode == null) {
687
+ oldEndVnode = oldCh[--oldEndIdx];
688
+ } else if (newStartVnode == null) {
689
+ newStartVnode = newCh[++newStartIdx];
690
+ } else if (newEndVnode == null) {
691
+ newEndVnode = newCh[--newEndIdx];
692
+ } else if (sameVnode(oldStartVnode, newStartVnode)) {
693
+ patchVnode(oldStartVnode, newStartVnode);
694
+ oldStartVnode = oldCh[++oldStartIdx];
695
+ newStartVnode = newCh[++newStartIdx];
696
+ } else if (sameVnode(oldEndVnode, newEndVnode)) {
697
+ patchVnode(oldEndVnode, newEndVnode);
698
+ oldEndVnode = oldCh[--oldEndIdx];
699
+ newEndVnode = newCh[--newEndIdx];
700
+ } else if (sameVnode(oldStartVnode, newEndVnode)) {
701
+ patchVnode(oldStartVnode, newEndVnode);
702
+ api.insertBefore(parentElm, oldStartVnode.elm, api.nextSibling(oldEndVnode.elm));
703
+ oldStartVnode = oldCh[++oldStartIdx];
704
+ newEndVnode = newCh[--newEndIdx];
705
+ } else if (sameVnode(oldEndVnode, newStartVnode)) {
706
+ patchVnode(oldEndVnode, newStartVnode);
707
+ api.insertBefore(parentElm, oldEndVnode.elm, oldStartVnode.elm);
708
+ oldEndVnode = oldCh[--oldEndIdx];
709
+ newStartVnode = newCh[++newStartIdx];
710
+ } else {
711
+ if (oldKeyToIdx === void 0) {
712
+ oldKeyToIdx = createKeyToOldIdx(oldCh, oldStartIdx, oldEndIdx);
713
+ }
714
+ idxInOld = oldKeyToIdx[newStartVnode.key];
715
+ if (isUndef(idxInOld)) {
716
+ api.insertBefore(
717
+ parentElm,
718
+ createElm(newStartVnode),
719
+ oldStartVnode.elm
720
+ );
721
+ } else {
722
+ elmToMove = oldCh[idxInOld];
723
+ if (elmToMove.sel !== newStartVnode.sel) {
724
+ api.insertBefore(
725
+ parentElm,
726
+ createElm(newStartVnode),
727
+ oldStartVnode.elm
728
+ );
729
+ } else {
730
+ patchVnode(elmToMove, newStartVnode);
731
+ oldCh[idxInOld] = void 0;
732
+ api.insertBefore(parentElm, elmToMove.elm, oldStartVnode.elm);
733
+ }
734
+ }
735
+ newStartVnode = newCh[++newStartIdx];
736
+ }
737
+ }
738
+ if (oldStartIdx <= oldEndIdx || newStartIdx <= newEndIdx) {
739
+ if (oldStartIdx > oldEndIdx) {
740
+ before = newCh[newEndIdx + 1] == null ? null : newCh[newEndIdx + 1].elm;
741
+ addVnodes(parentElm, before, newCh, newStartIdx, newEndIdx);
742
+ } else {
743
+ removeVnodes(parentElm, oldCh, oldStartIdx, oldEndIdx);
744
+ }
745
+ }
746
+ }
747
+ function patchVnode(oldVnode, vnode2) {
748
+ if (vnode2.data !== void 0) {
749
+ for (let i = 0; i < cbs.update.length; ++i) {
750
+ cbs.update[i](oldVnode, vnode2);
751
+ }
752
+ }
753
+ const elm = vnode2.elm = oldVnode.elm;
754
+ const oldCh = oldVnode.children;
755
+ const ch = vnode2.children;
756
+ if (oldVnode === vnode2)
757
+ return;
758
+ if (isUndef(vnode2.text)) {
759
+ if (isDef(oldCh) && isDef(ch)) {
760
+ if (oldCh !== ch) {
761
+ updateChildren(elm, oldCh, ch);
762
+ }
763
+ }
764
+ }
765
+ }
766
+ return function patch(oldVnode, vnode2) {
767
+ let elm, parent;
768
+ if (!isVnode(oldVnode)) {
769
+ oldVnode = emptyNodeAt(oldVnode);
770
+ }
771
+ if (sameVnode(oldVnode, vnode2)) {
772
+ patchVnode(oldVnode, vnode2);
773
+ } else {
774
+ elm = oldVnode.elm;
775
+ parent = api.parentNode(elm);
776
+ createElm(vnode2);
777
+ if (parent != null) {
778
+ api.insertBefore(parent, vnode2.elm, api.nextSibling(elm));
779
+ removeVnodes(parent, [oldVnode], 0, 0);
780
+ }
781
+ }
782
+ return vnode2;
783
+ };
784
+ }
785
+ function addNS(data, children, sel) {
786
+ data.ns = "http://www.w3.org/2000/svg";
787
+ if (sel !== "foreignObject" && children !== void 0) {
788
+ for (let i = 0; i < children.length; ++i) {
789
+ const child = children[i];
790
+ if (typeof child === "string" || typeof child === "number")
791
+ continue;
792
+ const childData = child.data;
793
+ if (childData !== void 0) {
794
+ addNS(childData, child.children, child.sel);
795
+ }
796
+ }
797
+ }
798
+ }
799
+ function h(sel, b, c) {
800
+ let data = {};
801
+ let children = void 0;
802
+ let text;
803
+ let i;
804
+ if (c !== void 0) {
805
+ if (b != null) {
806
+ data = b;
807
+ }
808
+ if (array(c)) {
809
+ children = c;
810
+ } else if (primitive(c)) {
811
+ text = c;
812
+ } else if (c && c.sel) {
813
+ children = [c];
814
+ }
815
+ } else if (b !== void 0 && b != null) {
816
+ if (array(b)) {
817
+ children = b;
818
+ } else if (primitive(b)) {
819
+ text = b;
820
+ } else {
821
+ if (isVnode$1(b)) {
822
+ children = [b];
823
+ } else {
824
+ data = b;
825
+ }
826
+ }
827
+ }
828
+ if (typeof children !== "undefined") {
829
+ for (i = 0; i < children.length; ++i) {
830
+ const msg = children[i];
831
+ if (primitive(msg)) {
832
+ children[i] = vnode$1(void 0, void 0, void 0, msg, void 0);
833
+ }
834
+ }
835
+ }
836
+ if (sel[0] === "s" && sel[1] === "v" && sel[2] === "g" && (sel.length === 3 || sel[3] === "." || sel[3] === "#")) {
837
+ addNS(data, children, sel);
838
+ }
839
+ return vnode$1(sel, data, children, text, void 0);
840
+ }
841
+ function querystring(data = {}) {
842
+ if (typeof data !== "object") {
843
+ throw new TypeError("param must be object");
844
+ }
845
+ return Object.entries(data).reduce((searchParams, [name, value]) => value === void 0 || value == null ? searchParams : (searchParams.append(decodeURIComponent(name), decodeURIComponent(value)), searchParams), new URLSearchParams()).toString();
846
+ }
847
+ function randomString(len = 8) {
848
+ const chars = "ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678";
849
+ const maxPos = chars.length;
850
+ let pwd = "";
851
+ for (let i = 0; i < len; i++) {
852
+ pwd += chars.charAt(Math.floor(Math.random() * maxPos));
853
+ }
854
+ return `${Date.now()}-${pwd}`;
855
+ }
856
+ function getCookie(name) {
857
+ const cookieList = window.document.cookie.match(
858
+ new RegExp(`(^| )${name}(?:=([^;]*))?(;|$)`)
859
+ );
860
+ if (cookieList && cookieList[2])
861
+ return cookieList[2];
862
+ return "";
863
+ }
864
+ function createData(params = {}) {
865
+ return Object.assign({}, {
866
+ id: randomString(),
867
+ path: window.location.href,
868
+ time: Date.now(),
869
+ userAgent: window.navigator.userAgent,
870
+ referrer: document.referrer,
871
+ ip: window.returnCitySN || { cid: "", cip: "", cname: "" },
872
+ userId: getCookie("chaxus_prod")
873
+ }, params);
874
+ }
875
+ const throttle = (fn, wait = 300) => {
876
+ let timer = null;
877
+ return function(...args) {
878
+ const context = this;
879
+ if (!timer) {
880
+ timer = setTimeout(() => {
881
+ timer = null;
882
+ fn.apply(context, args);
883
+ }, wait);
884
+ }
885
+ };
886
+ };
887
+ const Noop = () => {
888
+ };
889
+ function replaceOld(source, name, replacement, isForced) {
890
+ if (typeof source === "undefined")
891
+ return;
892
+ if (name in source || isForced) {
893
+ const original = source[name];
894
+ const wrapped = replacement(original);
895
+ if (typeof wrapped === "function") {
896
+ source[name] = wrapped;
897
+ }
898
+ }
899
+ }
900
+ const isString = (obj) => {
901
+ return toString.call(obj) === "[object String]";
902
+ };
903
+ const handleClick = (hooks = Noop) => {
904
+ document.addEventListener("click", function(event) {
905
+ hooks(event);
906
+ }, true);
907
+ };
908
+ const handleError = (hooks = Noop) => {
909
+ window.addEventListener("unhandledrejection", (error) => {
910
+ hooks(error);
911
+ }, true);
912
+ window.addEventListener("error", (error) => {
913
+ hooks(error);
914
+ return false;
915
+ }, true);
916
+ };
917
+ function getPerformance() {
918
+ const [performanceNavigationTiming] = performance.getEntriesByType("navigation");
919
+ const [firstPaint, firstContentfulPaint] = performance.getEntriesByType("paint");
920
+ const {
921
+ domainLookupEnd,
922
+ domainLookupStart,
923
+ connectEnd,
924
+ connectStart,
925
+ secureConnectionStart,
926
+ loadEventStart,
927
+ domInteractive,
928
+ domContentLoadedEventEnd,
929
+ duration,
930
+ responseStart,
931
+ requestStart,
932
+ responseEnd,
933
+ fetchStart,
934
+ transferSize,
935
+ encodedBodySize,
936
+ redirectEnd,
937
+ redirectStart,
938
+ redirectCount
939
+ } = performanceNavigationTiming;
940
+ const { startTime: fp } = firstPaint;
941
+ const { startTime: fcp } = firstContentfulPaint;
942
+ return {
943
+ dnsSearch: domainLookupEnd - domainLookupStart,
944
+ tcpConnect: connectEnd - connectStart,
945
+ sslConnect: connectEnd - secureConnectionStart,
946
+ request: responseStart - requestStart,
947
+ response: responseEnd - responseStart,
948
+ parseDomTree: domInteractive - responseEnd,
949
+ resource: loadEventStart - domContentLoadedEventEnd,
950
+ domReady: domContentLoadedEventEnd - fetchStart,
951
+ interactive: domInteractive - fetchStart,
952
+ complete: loadEventStart - fetchStart,
953
+ httpHead: transferSize - encodedBodySize,
954
+ redirect: redirectCount,
955
+ redirectTime: redirectEnd - redirectStart,
956
+ duration,
957
+ fp,
958
+ fcp
959
+ };
960
+ }
961
+ const getHost = (env) => {
962
+ let host = "";
963
+ if (env && isString(env)) {
964
+ if (/trunk|neibu|release/.test(env)) {
965
+ host = `.${env}`;
966
+ } else if (/test/.test(env)) {
967
+ host = env;
968
+ } else if (/prod/.test(env)) {
969
+ host = "";
970
+ } else {
971
+ host = "";
972
+ }
973
+ } else {
974
+ const env2 = /\w(\.trunk|\.neibu|\.release|test)\./.exec(
975
+ window.location.hostname
976
+ );
977
+ if (env2) {
978
+ host = env2[1];
979
+ }
980
+ }
981
+ return host ? `https://log${host}.chaxus.com` : "https://log.chaxus.com";
982
+ };
983
+ const sendBeacon = ({ url = "", type = "application/json; charset=UTF-8", payload = {} }) => {
984
+ const requestUrl = url ? url : getHost();
985
+ if (navigator.sendBeacon) {
986
+ const param = new Blob([JSON.stringify(payload)], { type });
987
+ return navigator.sendBeacon(requestUrl, param);
988
+ }
989
+ };
990
+ const sendImage = ({ url = "", payload = {} }) => {
991
+ const requestUrl = url ? url : getHost();
992
+ const image = new Image();
993
+ image.width = 1;
994
+ image.height = 1;
995
+ image.src = `${requestUrl}?${querystring(payload)}`;
996
+ };
997
+ const report = ({ url = "", type = "application/json; charset=UTF-8", payload = {} }) => {
998
+ const requestUrl = url ? url : getHost();
999
+ if (typeof navigator.sendBeacon !== "undefined") {
1000
+ return sendBeacon({ url: requestUrl, type, payload });
1001
+ }
1002
+ return sendImage({ url: requestUrl, payload });
1003
+ };
1004
+ const handleFetchHook = (options = {}) => {
1005
+ if (typeof window !== "undefined") {
1006
+ const { requestHook = Noop, responseHook = Noop, errorHook = Noop } = options;
1007
+ const replacement = (originalFetch) => {
1008
+ return (url, config) => {
1009
+ requestHook(url, config);
1010
+ return originalFetch.apply(window, [url, config]).then((response) => {
1011
+ responseHook(url, config, response);
1012
+ return response;
1013
+ }).catch((error) => {
1014
+ errorHook(url, error);
1015
+ throw error;
1016
+ });
1017
+ };
1018
+ };
1019
+ replaceOld(window, "fetch", replacement);
1020
+ }
1021
+ };
1022
+ const handleXhrHook = (options = {}) => {
1023
+ const originalXhrProto = XMLHttpRequest.prototype;
1024
+ const { requestHook = Noop, responseHook = Noop, errorHook = Noop } = options;
1025
+ const replacementXhrOpen = (originalOpen) => {
1026
+ return function(...args) {
1027
+ requestHook(args);
1028
+ originalOpen.apply(this, args);
1029
+ };
1030
+ };
1031
+ replaceOld(originalXhrProto, "open", replacementXhrOpen);
1032
+ const replacementXhrSend = (originalSend) => {
1033
+ return function(...args) {
1034
+ this.addEventListener("loadend", function() {
1035
+ responseHook(this);
1036
+ });
1037
+ this.addEventListener("error", function() {
1038
+ errorHook(this);
1039
+ });
1040
+ originalSend.apply(this, args);
1041
+ };
1042
+ };
1043
+ replaceOld(originalXhrProto, "send", replacementXhrSend);
1044
+ };
1045
+ class Monitor {
1046
+ reportPerformance() {
1047
+ const params = getPerformance();
1048
+ const payload = createData();
1049
+ report({
1050
+ payload: {
1051
+ ...params,
1052
+ ...payload
1053
+ }
1054
+ });
1055
+ }
1056
+ log(payload) {
1057
+ report({ payload });
1058
+ }
1059
+ reportClick() {
1060
+ const throttleReport = throttle(report);
1061
+ const payload = createData();
1062
+ const hook = (event) => {
1063
+ throttleReport({ payload: { ...payload, event, type: "click" } });
1064
+ };
1065
+ handleClick(hook);
1066
+ }
1067
+ reportXhr() {
1068
+ const throttleReport = throttle(report);
1069
+ const payload = createData();
1070
+ const requestHook = (...args) => {
1071
+ throttleReport({ payload: { ...payload, ...args, type: "xhrRequest" } });
1072
+ };
1073
+ const responseHook = (...args) => {
1074
+ throttleReport({ payload: { ...payload, ...args, type: "xhrResponse" } });
1075
+ };
1076
+ const errorHook = (...args) => {
1077
+ throttleReport({ payload: { ...payload, ...args, type: "xhrError" } });
1078
+ };
1079
+ handleXhrHook({ requestHook, responseHook, errorHook });
1080
+ }
1081
+ reportFetch() {
1082
+ const throttleReport = throttle(report);
1083
+ const payload = createData();
1084
+ const requestHook = (...args) => {
1085
+ throttleReport({ payload: { ...payload, ...args, type: "fetchRequest" } });
1086
+ };
1087
+ const responseHook = (...args) => {
1088
+ throttleReport({ payload: { ...payload, ...args, type: "fetchResponse" } });
1089
+ };
1090
+ const errorHook = (...args) => {
1091
+ throttleReport({ payload: { ...payload, ...args, type: "fetchError" } });
1092
+ };
1093
+ handleFetchHook({ requestHook, responseHook, errorHook });
1094
+ }
1095
+ reportError() {
1096
+ const throttleReport = throttle(report);
1097
+ const payload = createData();
1098
+ const hook = (...args) => {
1099
+ throttleReport({ payload: { ...payload, ...args, type: "error" } });
1100
+ };
1101
+ handleError(hook);
1102
+ }
1103
+ }
1104
+ const vnode = {
1105
+ init,
1106
+ h
82
1107
  };
83
1108
  export {
84
- index as default
1109
+ Subscribe as EventEmitter,
1110
+ Monitor,
1111
+ filterObj,
1112
+ queryFileInfo,
1113
+ readDir,
1114
+ readFile,
1115
+ str2Xml,
1116
+ vnode,
1117
+ watchFile,
1118
+ writeFile
85
1119
  };
86
1120
  //# sourceMappingURL=index.js.map