-
Notifications
You must be signed in to change notification settings - Fork 7
/
cotonic.js
7067 lines (7039 loc) · 207 KB
/
cotonic.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(() => {
var __defProp = Object.defineProperty;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __commonJS = (cb, mod) => function __require() {
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
};
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
// lib/incremental-dom-cjs.js
var require_incremental_dom_cjs = __commonJS({
"lib/incremental-dom-cjs.js"(exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var keyAttributeName = "key";
function getKeyAttributeName() {
return keyAttributeName;
}
function setKeyAttributeName(name) {
keyAttributeName = name;
}
var inAttributes = false;
var inSkip = false;
var inPatch = false;
function assert(val) {
if (!val) {
throw new Error("Expected value to be defined");
}
return val;
}
function assertInPatch(functionName) {
if (!inPatch) {
throw new Error("Cannot call " + functionName + "() unless in patch.");
}
}
function assertNoUnclosedTags(openElement, root2) {
if (openElement === root2) {
return;
}
let currentElement2 = openElement;
const openTags = [];
while (currentElement2 && currentElement2 !== root2) {
openTags.push(currentElement2.nodeName.toLowerCase());
currentElement2 = currentElement2.parentNode;
}
throw new Error("One or more tags were not closed:\n" + openTags.join("\n"));
}
function assertPatchOuterHasParentNode(parent) {
if (!parent) {
console.warn("patchOuter requires the node have a parent if there is a key.");
}
}
function assertNotInAttributes(functionName) {
if (inAttributes) {
throw new Error(functionName + "() can not be called between elementOpenStart() and elementOpenEnd().");
}
}
function assertNotInSkip(functionName) {
if (inSkip) {
throw new Error(functionName + "() may not be called inside an element that has called skip().");
}
}
function assertInAttributes(functionName) {
if (!inAttributes) {
throw new Error(functionName + "() can only be called after calling elementOpenStart().");
}
}
function assertVirtualAttributesClosed() {
if (inAttributes) {
throw new Error("elementOpenEnd() must be called after calling elementOpenStart().");
}
}
function assertCloseMatchesOpenTag(currentNameOrCtor, nameOrCtor) {
if (currentNameOrCtor !== nameOrCtor) {
throw new Error('Received a call to close "' + nameOrCtor + '" but "' + currentNameOrCtor + '" was open.');
}
}
function assertNoChildrenDeclaredYet(functionName, previousNode) {
if (previousNode !== null) {
throw new Error(functionName + "() must come before any child declarations inside the current element.");
}
}
function assertPatchElementNoExtras(maybeStartNode, maybeCurrentNode, expectedNextNode, expectedPrevNode) {
const startNode = assert(maybeStartNode);
const currentNode2 = assert(maybeCurrentNode);
const wasUpdated = currentNode2.nextSibling === expectedNextNode && currentNode2.previousSibling === expectedPrevNode;
const wasChanged = currentNode2.nextSibling === startNode.nextSibling && currentNode2.previousSibling === expectedPrevNode;
const wasRemoved = currentNode2 === startNode;
if (!wasUpdated && !wasChanged && !wasRemoved) {
throw new Error("There must be exactly one top level call corresponding to the patched element.");
}
}
function updatePatchContext(newContext) {
inPatch = newContext != null;
}
function setInAttributes(value2) {
const previous = inAttributes;
inAttributes = value2;
return previous;
}
function setInSkip(value2) {
const previous = inSkip;
inSkip = value2;
return previous;
}
var hasOwnProperty = Object.prototype.hasOwnProperty;
function Blank() {
}
Blank.prototype = /* @__PURE__ */ Object.create(null);
function has(map, property) {
return hasOwnProperty.call(map, property);
}
function createMap() {
return new Blank();
}
function truncateArray(arr, length) {
while (arr.length > length) {
arr.pop();
}
}
function createArray(initialAllocationSize) {
const arr = new Array(initialAllocationSize);
truncateArray(arr, 0);
return arr;
}
var symbols = {
default: "__default"
};
function getNamespace(name) {
if (name.lastIndexOf("xml:", 0) === 0) {
return "http://www.w3.org/XML/1998/namespace";
}
if (name.lastIndexOf("xlink:", 0) === 0) {
return "http://www.w3.org/1999/xlink";
}
return null;
}
function applyAttr(el, name, value2) {
if (value2 == null) {
el.removeAttribute(name);
} else {
const attrNS = getNamespace(name);
if (attrNS) {
el.setAttributeNS(attrNS, name, String(value2));
} else {
el.setAttribute(name, String(value2));
}
}
}
function applyProp(el, name, value2) {
el[name] = value2;
}
function setStyleValue(style, prop, value2) {
if (prop.indexOf("-") >= 0) {
style.setProperty(prop, value2);
} else {
style[prop] = value2;
}
}
function applyStyle(el, name, style) {
assert("style" in el);
const elStyle = el.style;
if (typeof style === "string") {
elStyle.cssText = style;
} else {
elStyle.cssText = "";
for (const prop in style) {
if (has(style, prop)) {
setStyleValue(elStyle, prop, style[prop]);
}
}
}
}
function applyAttributeTyped(el, name, value2) {
const type = typeof value2;
if (type === "object" || type === "function") {
applyProp(el, name, value2);
} else {
applyAttr(el, name, value2);
}
}
var attributes = createMap();
attributes[symbols.default] = applyAttributeTyped;
attributes["style"] = applyStyle;
function updateAttribute(el, name, value2) {
const mutator = attributes[name] || attributes[symbols.default];
mutator(el, name, value2);
}
var notifications = {
nodesCreated: null,
nodesDeleted: null
};
var Context = class {
constructor() {
this.created = [];
this.deleted = [];
}
markCreated(node) {
this.created.push(node);
}
markDeleted(node) {
this.deleted.push(node);
}
/**
* Notifies about nodes that were created during the patch operation.
*/
notifyChanges() {
if (notifications.nodesCreated && this.created.length > 0) {
notifications.nodesCreated(this.created);
}
if (notifications.nodesDeleted && this.deleted.length > 0) {
notifications.nodesDeleted(this.deleted);
}
}
};
function isDocumentRoot(node) {
return node.nodeType === 11 || node.nodeType === 9;
}
function isElement(node) {
return node.nodeType === 1;
}
function getAncestry(node, root2) {
const ancestry = [];
let cur = node;
while (cur !== root2) {
const n = assert(cur);
ancestry.push(n);
cur = n.parentNode;
}
return ancestry;
}
var getRootNode = typeof Node !== "undefined" && Node.prototype.getRootNode || function() {
let cur = this;
let prev = cur;
while (cur) {
prev = cur;
cur = cur.parentNode;
}
return prev;
};
function getActiveElement(node) {
const root2 = getRootNode.call(node);
return isDocumentRoot(root2) ? root2.activeElement : null;
}
function getFocusedPath(node, root2) {
const activeElement = getActiveElement(node);
if (!activeElement || !node.contains(activeElement)) {
return [];
}
return getAncestry(activeElement, root2);
}
function moveBefore(parentNode, node, referenceNode) {
const insertReferenceNode = node.nextSibling;
let cur = referenceNode;
while (cur !== null && cur !== node) {
const next = cur.nextSibling;
parentNode.insertBefore(cur, insertReferenceNode);
cur = next;
}
}
var NodeData = class {
constructor(nameOrCtor, key3, text2) {
this._attrsArr = null;
this.staticsApplied = false;
this.nameOrCtor = nameOrCtor;
this.key = key3;
this.text = text2;
}
hasEmptyAttrsArr() {
const attrs = this._attrsArr;
return !attrs || !attrs.length;
}
getAttrsArr(length) {
return this._attrsArr || (this._attrsArr = createArray(length));
}
};
function initData(node, nameOrCtor, key3, text2) {
const data = new NodeData(nameOrCtor, key3, text2);
node["__incrementalDOMData"] = data;
return data;
}
function isDataInitialized(node) {
return Boolean(node["__incrementalDOMData"]);
}
function recordAttributes(node, data) {
const attributes2 = node.attributes;
const length = attributes2.length;
if (!length) {
return;
}
const attrsArr = data.getAttrsArr(length);
for (let i = 0, j = 0; i < length; i += 1, j += 2) {
const attr2 = attributes2[i];
const name = attr2.name;
const value2 = attr2.value;
attrsArr[j] = name;
attrsArr[j + 1] = value2;
}
}
function importSingleNode(node, fallbackKey) {
if (node["__incrementalDOMData"]) {
return node["__incrementalDOMData"];
}
const nodeName = isElement(node) ? node.localName : node.nodeName;
const keyAttrName = getKeyAttributeName();
const keyAttr = isElement(node) && keyAttrName != null ? node.getAttribute(keyAttrName) : null;
const key3 = isElement(node) ? keyAttr || fallbackKey : null;
const data = initData(node, nodeName, key3);
if (isElement(node)) {
recordAttributes(node, data);
}
return data;
}
function importNode(node) {
importSingleNode(node);
for (let child = node.firstChild; child; child = child.nextSibling) {
importNode(child);
}
}
function getData(node, fallbackKey) {
return importSingleNode(node, fallbackKey);
}
function getKey(node) {
assert(node["__incrementalDOMData"]);
return getData(node).key;
}
function clearCache(node) {
node["__incrementalDOMData"] = null;
for (let child = node.firstChild; child; child = child.nextSibling) {
clearCache(child);
}
}
function getNamespaceForTag(tag, parent) {
if (tag === "svg") {
return "http://www.w3.org/2000/svg";
}
if (tag === "math") {
return "http://www.w3.org/1998/Math/MathML";
}
if (parent == null) {
return null;
}
if (getData(parent).nameOrCtor === "foreignObject") {
return null;
}
return parent.namespaceURI;
}
function createElement(doc2, parent, nameOrCtor, key3) {
let el;
if (typeof nameOrCtor === "function") {
el = new nameOrCtor();
} else {
const namespace = getNamespaceForTag(nameOrCtor, parent);
if (namespace) {
el = doc2.createElementNS(namespace, nameOrCtor);
} else {
el = doc2.createElement(nameOrCtor);
}
}
initData(el, nameOrCtor, key3);
return el;
}
function createText(doc2) {
const node = doc2.createTextNode("");
initData(node, "#text", null);
return node;
}
function defaultMatchFn(matchNode, nameOrCtor, expectedNameOrCtor, key3, expectedKey) {
return nameOrCtor == expectedNameOrCtor && key3 == expectedKey;
}
var context = null;
var currentNode = null;
var currentParent = null;
var doc = null;
var focusPath = [];
var matchFn = defaultMatchFn;
var argsBuilder = [];
var attrsBuilder = [];
function getArgsBuilder() {
return argsBuilder;
}
function getAttrsBuilder() {
return attrsBuilder;
}
function matches2(matchNode, nameOrCtor, key3) {
const data = getData(matchNode, key3);
return matchFn(matchNode, nameOrCtor, data.nameOrCtor, key3, data.key);
}
function getMatchingNode(matchNode, nameOrCtor, key3) {
if (!matchNode) {
return null;
}
let cur = matchNode;
do {
if (matches2(cur, nameOrCtor, key3)) {
return cur;
}
} while (key3 && (cur = cur.nextSibling));
return null;
}
function clearUnvisitedDOM(maybeParentNode, startNode, endNode) {
const parentNode = maybeParentNode;
let child = startNode;
while (child !== endNode) {
const next = child.nextSibling;
parentNode.removeChild(child);
context.markDeleted(child);
child = next;
}
}
function getNextNode() {
if (currentNode) {
return currentNode.nextSibling;
} else {
return currentParent.firstChild;
}
}
function enterNode() {
currentParent = currentNode;
currentNode = null;
}
function exitNode() {
clearUnvisitedDOM(currentParent, getNextNode(), null);
currentNode = currentParent;
currentParent = currentParent.parentNode;
}
function nextNode() {
currentNode = getNextNode();
}
function createNode(nameOrCtor, key3) {
let node;
if (nameOrCtor === "#text") {
node = createText(doc);
} else {
node = createElement(doc, currentParent, nameOrCtor, key3);
}
context.markCreated(node);
return node;
}
function alignWithDOM(nameOrCtor, key3) {
nextNode();
const existingNode = getMatchingNode(currentNode, nameOrCtor, key3);
const node = existingNode || createNode(nameOrCtor, key3);
if (node === currentNode) {
return;
}
if (focusPath.indexOf(node) >= 0) {
moveBefore(currentParent, node, currentNode);
} else {
currentParent.insertBefore(node, currentNode);
}
currentNode = node;
}
function open(nameOrCtor, key3) {
alignWithDOM(nameOrCtor, key3);
enterNode();
return currentParent;
}
function close() {
{
setInSkip(false);
}
exitNode();
return currentNode;
}
function text() {
alignWithDOM("#text", null);
return currentNode;
}
function currentElement() {
{
assertInPatch("currentElement");
assertNotInAttributes("currentElement");
}
return currentParent;
}
function currentPointer() {
{
assertInPatch("currentPointer");
assertNotInAttributes("currentPointer");
}
return getNextNode();
}
function skip() {
{
assertNoChildrenDeclaredYet("skip", currentNode);
setInSkip(true);
}
currentNode = currentParent.lastChild;
}
function createPatcher(run, patchConfig = {}) {
const { matches: matches3 = defaultMatchFn } = patchConfig;
const f = (node, fn, data) => {
const prevContext = context;
const prevDoc = doc;
const prevFocusPath = focusPath;
const prevArgsBuilder = argsBuilder;
const prevAttrsBuilder = attrsBuilder;
const prevCurrentNode = currentNode;
const prevCurrentParent = currentParent;
const prevMatchFn = matchFn;
let previousInAttributes = false;
let previousInSkip = false;
doc = node.ownerDocument;
context = new Context();
matchFn = matches3;
argsBuilder = [];
attrsBuilder = [];
currentNode = null;
currentParent = node.parentNode;
focusPath = getFocusedPath(node, currentParent);
{
previousInAttributes = setInAttributes(false);
previousInSkip = setInSkip(false);
updatePatchContext(context);
}
try {
const retVal = run(node, fn, data);
{
assertVirtualAttributesClosed();
}
return retVal;
} finally {
context.notifyChanges();
doc = prevDoc;
context = prevContext;
matchFn = prevMatchFn;
argsBuilder = prevArgsBuilder;
attrsBuilder = prevAttrsBuilder;
currentNode = prevCurrentNode;
currentParent = prevCurrentParent;
focusPath = prevFocusPath;
{
setInAttributes(previousInAttributes);
setInSkip(previousInSkip);
updatePatchContext(context);
}
}
};
return f;
}
function createPatchInner(patchConfig) {
return createPatcher((node, fn, data) => {
currentNode = node;
enterNode();
fn(data);
exitNode();
{
assertNoUnclosedTags(currentNode, node);
}
return node;
}, patchConfig);
}
function createPatchOuter(patchConfig) {
return createPatcher((node, fn, data) => {
const startNode = { nextSibling: node };
let expectedNextNode = null;
let expectedPrevNode = null;
{
expectedNextNode = node.nextSibling;
expectedPrevNode = node.previousSibling;
}
currentNode = startNode;
fn(data);
{
assertPatchOuterHasParentNode(currentParent);
assertPatchElementNoExtras(startNode, currentNode, expectedNextNode, expectedPrevNode);
}
if (currentParent) {
clearUnvisitedDOM(currentParent, getNextNode(), node.nextSibling);
}
return startNode === currentNode ? null : currentNode;
}, patchConfig);
}
var patchInner2 = createPatchInner();
var patchOuter2 = createPatchOuter();
var buffer = [];
var bufferStart = 0;
function queueChange(fn, a, b, c) {
buffer.push(fn);
buffer.push(a);
buffer.push(b);
buffer.push(c);
}
function flush2() {
const start = bufferStart;
const end = buffer.length;
bufferStart = end;
for (let i = start; i < end; i += 4) {
const fn = buffer[i];
fn(buffer[i + 1], buffer[i + 2], buffer[i + 3]);
}
bufferStart = start;
truncateArray(buffer, start);
}
var prevValuesMap = createMap();
function calculateDiff(prev, next, updateCtx, updateFn) {
const isNew = !prev.length;
let i = 0;
for (; i < next.length; i += 2) {
const name = next[i];
if (isNew) {
prev[i] = name;
} else if (prev[i] !== name) {
break;
}
const value2 = next[i + 1];
if (isNew || prev[i + 1] !== value2) {
prev[i + 1] = value2;
queueChange(updateFn, updateCtx, name, value2);
}
}
if (i < next.length || i < prev.length) {
const startIndex = i;
for (i = startIndex; i < prev.length; i += 2) {
prevValuesMap[prev[i]] = prev[i + 1];
}
for (i = startIndex; i < next.length; i += 2) {
const name = next[i];
const value2 = next[i + 1];
if (prevValuesMap[name] !== value2) {
queueChange(updateFn, updateCtx, name, value2);
}
prev[i] = name;
prev[i + 1] = value2;
delete prevValuesMap[name];
}
truncateArray(prev, next.length);
for (const name in prevValuesMap) {
queueChange(updateFn, updateCtx, name, void 0);
delete prevValuesMap[name];
}
}
flush2();
}
var ATTRIBUTES_OFFSET = 3;
var prevAttrsMap = createMap();
function diffAttrs(element, data) {
const attrsBuilder2 = getAttrsBuilder();
const prevAttrsArr = data.getAttrsArr(attrsBuilder2.length);
calculateDiff(prevAttrsArr, attrsBuilder2, element, updateAttribute);
truncateArray(attrsBuilder2, 0);
}
function diffStatics(node, data, statics) {
if (data.staticsApplied) {
return;
}
data.staticsApplied = true;
if (!statics || !statics.length) {
return;
}
if (data.hasEmptyAttrsArr()) {
for (let i = 0; i < statics.length; i += 2) {
updateAttribute(node, statics[i], statics[i + 1]);
}
return;
}
for (let i = 0; i < statics.length; i += 2) {
prevAttrsMap[statics[i]] = i + 1;
}
const attrsArr = data.getAttrsArr(0);
let j = 0;
for (let i = 0; i < attrsArr.length; i += 2) {
const name = attrsArr[i];
const value2 = attrsArr[i + 1];
const staticsIndex = prevAttrsMap[name];
if (staticsIndex) {
if (statics[staticsIndex] === value2) {
delete prevAttrsMap[name];
}
continue;
}
attrsArr[j] = name;
attrsArr[j + 1] = value2;
j += 2;
}
truncateArray(attrsArr, j);
for (const name in prevAttrsMap) {
updateAttribute(node, name, statics[prevAttrsMap[name]]);
delete prevAttrsMap[name];
}
}
function elementOpenStart(nameOrCtor, key3, statics) {
const argsBuilder2 = getArgsBuilder();
{
assertNotInAttributes("elementOpenStart");
setInAttributes(true);
}
argsBuilder2[0] = nameOrCtor;
argsBuilder2[1] = key3;
argsBuilder2[2] = statics;
}
function key2(key3) {
const argsBuilder2 = getArgsBuilder();
{
assertInAttributes("key");
assert(argsBuilder2);
}
argsBuilder2[1] = key3;
}
function attr(name, value2) {
const attrsBuilder2 = getAttrsBuilder();
{
assertInPatch("attr");
}
attrsBuilder2.push(name);
attrsBuilder2.push(value2);
}
function elementOpenEnd() {
const argsBuilder2 = getArgsBuilder();
{
assertInAttributes("elementOpenEnd");
setInAttributes(false);
}
const node = open(argsBuilder2[0], argsBuilder2[1]);
const data = getData(node);
diffStatics(node, data, argsBuilder2[2]);
diffAttrs(node, data);
truncateArray(argsBuilder2, 0);
return node;
}
function elementOpen(nameOrCtor, key3, statics, ...varArgs) {
{
assertNotInAttributes("elementOpen");
assertNotInSkip("elementOpen");
}
elementOpenStart(nameOrCtor, key3, statics);
for (let i = ATTRIBUTES_OFFSET; i < arguments.length; i += 2) {
attr(arguments[i], arguments[i + 1]);
}
return elementOpenEnd();
}
function applyAttrs() {
const node = currentElement();
const data = getData(node);
diffAttrs(node, data);
}
function applyStatics(statics) {
const node = currentElement();
const data = getData(node);
diffStatics(node, data, statics);
}
function elementClose(nameOrCtor) {
{
assertNotInAttributes("elementClose");
}
const node = close();
{
assertCloseMatchesOpenTag(getData(node).nameOrCtor, nameOrCtor);
}
return node;
}
function elementVoid(nameOrCtor, key3, statics, ...varArgs) {
elementOpen.apply(null, arguments);
return elementClose(nameOrCtor);
}
function text$1(value2, ...varArgs) {
{
assertNotInAttributes("text");
assertNotInSkip("text");
}
const node = text();
const data = getData(node);
if (data.text !== value2) {
data.text = value2;
let formatted = value2;
for (let i = 1; i < arguments.length; i += 1) {
const fn = arguments[i];
formatted = fn(formatted);
}
if (node.data !== formatted) {
node.data = formatted;
}
}
return node;
}
exports.applyAttr = applyAttr;
exports.applyProp = applyProp;
exports.attributes = attributes;
exports.alignWithDOM = alignWithDOM;
exports.close = close;
exports.createPatchInner = createPatchInner;
exports.createPatchOuter = createPatchOuter;
exports.currentElement = currentElement;
exports.currentPointer = currentPointer;
exports.open = open;
exports.patch = patchInner2;
exports.patchInner = patchInner2;
exports.patchOuter = patchOuter2;
exports.skip = skip;
exports.skipNode = nextNode;
exports.setKeyAttributeName = setKeyAttributeName;
exports.clearCache = clearCache;
exports.getKey = getKey;
exports.importNode = importNode;
exports.isDataInitialized = isDataInitialized;
exports.notifications = notifications;
exports.symbols = symbols;
exports.applyAttrs = applyAttrs;
exports.applyStatics = applyStatics;
exports.attr = attr;
exports.elementClose = elementClose;
exports.elementOpen = elementOpen;
exports.elementOpenEnd = elementOpenEnd;
exports.elementOpenStart = elementOpenStart;
exports.elementVoid = elementVoid;
exports.key = key2;
exports.text = text$1;
}
});
// src/cotonic.mqtt.js
var cotonic_mqtt_exports = {};
__export(cotonic_mqtt_exports, {
exec: () => exec,
extract: () => extract,
fill: () => fill,
matches: () => matches,
remove_named_wildcards: () => remove_named_wildcards
});
var SEPARATOR = "/";
var SINGLE = "+";
var ALL = "#";
function exec(pattern, topic) {
return matches(pattern, topic) ? extract(pattern, topic) : null;
}
function matches(pattern, topic) {
var patternSegments = pattern.split(SEPARATOR);
var topicSegments = topic.split(SEPARATOR);
var patternLength = patternSegments.length;
var topicLength = topicSegments.length;
var lastIndex = patternLength - 1;
for (var i = 0; i < patternLength; i++) {
var currentPattern = patternSegments[i];
var patternChar = currentPattern[0];
var currentTopic = topicSegments[i];
if (!currentTopic && !currentPattern)
continue;
if (!currentTopic && currentPattern !== ALL)
return false;
if (patternChar === ALL)
return i === lastIndex;
if (patternChar !== SINGLE && currentPattern !== currentTopic)
return false;
}
return patternLength === topicLength;
}
function fill(pattern, params) {
var patternSegments = pattern.split(SEPARATOR);
var patternLength = patternSegments.length;
var result = [];
for (var i = 0; i < patternLength; i++) {
var currentPattern = patternSegments[i];
var patternChar = currentPattern[0];
var patternParam = currentPattern.slice(1);
var paramValue = params[patternParam];
if (patternChar === ALL) {
if (paramValue !== void 0)
result.push([].concat(paramValue).join(SEPARATOR));
break;
} else if (patternChar === SINGLE)
result.push("" + paramValue);
else
result.push(currentPattern);
}
return result.join(SEPARATOR);
}
function extract(pattern, topic) {
var params = {};
var patternSegments = pattern.split(SEPARATOR);
var topicSegments = topic.split(SEPARATOR);
var patternLength = patternSegments.length;
for (var i = 0; i < patternLength; i++) {
var currentPattern = patternSegments[i];
var patternChar = currentPattern[0];
if (currentPattern.length === 1)
continue;
if (patternChar === ALL) {
params[currentPattern.slice(1)] = topicSegments.slice(i);
break;
} else if (patternChar === SINGLE) {
params[currentPattern.slice(1)] = topicSegments[i];
}
}
return params;
}
function remove_named_wildcards(pattern) {
var patternSegments = pattern.split(SEPARATOR);
var patternLength = patternSegments.length;
var mqttPattern = [];
for (var i = 0; i < patternLength; i++) {
var currentPattern = patternSegments[i];
var patternChar = currentPattern[0];
if (patternChar === ALL || patternChar == SINGLE) {
mqttPattern.push(patternChar);
} else {
mqttPattern.push(currentPattern);
}
}
return mqttPattern.join(SEPARATOR);
}
// src/cotonic.tokenizer.js
var cotonic_tokenizer_exports = {};
__export(cotonic_tokenizer_exports, {
charref: () => charref,
tokens: () => tokens
});
var TAB = 9;
var NEWLINE = 10;
var SPACE = 32;
var RETURN = 13;
var DASH = 45;
var LT = 60;
var GT = 62;
var SLASH = 47;
var UNDERSCORE = 95;
var AMPERSAND = 38;
var EQUALS = 61;
var QUESTION_MARK = 63;
var COLON = 59;
var QUOTE = 34;
var SQUOTE = 39;
var CHAR_A = 65;
var CHAR_Z = 90;
var CHAR_a = 97;
var CHAR_z = 122;
var DONE = 0;
var SCRIPT = 1;
var TEXTAREA = 2;
var NORMAL = 3;
function TokenBuilder(acc) {
function addKey(token, attributes) {
for (let i = 0; i < attributes.length; i = i + 2) {
if (attributes[i] === "key") {
token.key = attributes[i + 1];
break;
}
}
}
this.elementOpen = function(tag, attributes) {
const t = { type: "open", tag, attributes };
addKey(t, attributes);
acc.push(t);
};
this.elementVoid = function(tag, attributes) {
const t = { type: "void", tag, attributes };
addKey(t, attributes);
acc.push(t);
};
this.elementClose = function(tag) {
acc.push({ type: "close", tag });
};
this.processingInstruction = function(tag, attributes) {
acc.push({ type: "pi", tag, attributes });
};
this.doctype = function(attributes) {
acc.push({ type: "doctype", attributes });
};
this.comment = function(data) {
acc.push({ type: "comment", data });
};
this.text = function(data) {
acc.push({ type: "text", data });
};
this.result = acc;
}
function Decoder(builder) {
this.line = 1;
this.column = 1;
this.offset = 0;
this.builder = builder;
this.adv_col = function(n) {
this.column = this.column + n;
this.offset = this.offset + n;
return this;
};
this.inc_col = function() {
this.column += 1;
this.offset += 1;
return this;
};
this.inc_line = function() {
this.line += 1;
this.column = 1;
this.offset += 1;
return this;
};
this.inc_char = function(c) {
if (c === NEWLINE) {
this.inc_line();
} else {
this.inc_col();
}
return this;
};
}
var tokens = function(data, tokenBuilder) {