@slyte/html-parser 2.0.0-alpha

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.
@@ -0,0 +1,1306 @@
1
+ //ignorei18n_start
2
+
3
+ /*
4
+ pageBuilder : data,callbacks,preventSpaceText
5
+ */
6
+ import htmlParser from "../lib/htmlParser.js";
7
+ import Node, { setNodeCompile } from "./nodeStructClass.js";
8
+ import syntaxCheckWorkerNew from "./HandleMustache.js";
9
+ import decodeHtmlEntities from "./decodeHtmlEntities.js";
10
+
11
+ const MAX_DEPTH = 512;
12
+ const createMapFor = function (array) {
13
+ return array.reduce(function (acc, item) {
14
+ acc[item] = true;
15
+ return acc;
16
+ }, {});
17
+ }
18
+ let observedAttributes = {},
19
+ tagsTable = {
20
+ "table": ["tbody", "thead", "tfoot", "colgroup", "template"],
21
+ "tbody": ["tr", "template"],
22
+ "tr": ["td", "th", "template"],
23
+ "thead": ["tr", "template"],
24
+ "tfoot": ["tr", "template"],
25
+ "colgroup": ["col", "template"]
26
+ },
27
+ tagLevel = {
28
+ "td": 0,
29
+ "th": 0,
30
+ "tr": 1,
31
+ "tbody": 2,
32
+ "thead": 2,
33
+ "tfoot": 2,
34
+ "colgroup": 2
35
+ },
36
+ tableTags = ["tbody", "thead", "tfoot", "colgroup", "caption"],
37
+ allTableTags = createMapFor(tableTags.concat([ "tr", "th", "td", "col", "table", "template"])),
38
+ removedTableTags = ["body"],
39
+ ls = [],
40
+ styleTagStarted = false;
41
+ tableTags = createMapFor(tableTags);
42
+
43
+ function removeUnwantedTags(obj, depth = 0) {
44
+ if (depth > MAX_DEPTH) {
45
+ throw new Error("Parse Error: HTML nesting depth exceeds the maximum allowed (" + MAX_DEPTH + ").");
46
+ }
47
+ if (!obj || obj.tag == "td" || obj.tag == "th") {
48
+ return
49
+ };
50
+ if (obj.tag != "input" && obj.parent.tag && obj.tag && tagsTable[obj.parent.tag] && tagsTable[obj.parent.tag].indexOf(obj.tag) == -1) {
51
+ if(allTableTags[obj.parent.tag.toLowerCase()] && allTableTags[obj.tag.toLowerCase()] && tagLevel[obj.parent.tag.toLowerCase()] <= tagLevel[obj.tag.toLowerCase()]){
52
+ throw new Error("Invalid tag " + obj.tagName + " inside " + obj.parent.tagName);
53
+ }
54
+ ls.push(obj);
55
+ obj.remove();
56
+ }
57
+ if (obj.tag == "input" && obj.attr.type != "hidden") {
58
+ ls.push(obj);
59
+ obj.remove();
60
+ }
61
+ if(obj.child){
62
+ for (let i of obj.children) {
63
+ removeUnwantedTags(i, depth + 1);
64
+ }
65
+ }
66
+ }
67
+
68
+ function processTable(obj, tag, check) {
69
+ let samp = obj.querySelectorAll(tag, true);
70
+ for (let node of samp) {
71
+ let child = node.child[0]
72
+ let flag = false;
73
+ while (child) {
74
+ if (removedTableTags.indexOf(child.tag) != -1) {
75
+ flag = true;
76
+ let index = node.child.indexOf(child);
77
+ let temp = ((node.child.slice(0, index)).concat(child.child)).concat(node.child.slice(index + 1));
78
+
79
+ node.child = []
80
+ for (let childToPush of temp) {
81
+ node.appendChild(childToPush);
82
+ }
83
+ child = node.child[index];
84
+ continue;
85
+ }
86
+ child = child.next
87
+ }
88
+ if (flag) {
89
+ child = node.child[0];
90
+ while (child) {
91
+ if (child.next && child.node == "#text" && child.next.node == "#text") {
92
+ child.text = child.text + child.next.text;
93
+ child.next.remove();
94
+ }
95
+ child = child.next
96
+ }
97
+ }
98
+ child = node.child[0]
99
+ if (child && child.node != "#element") {
100
+ child = child.nextElementSibling;
101
+ }
102
+ let ptr = child;
103
+ let checkerTemplateAsFirstNode = true;
104
+ let targObj = new Node({
105
+ tag: check,
106
+ node: "#element"
107
+ })
108
+ while (child) {
109
+
110
+ if ((check == "tr") && child.tag == "template") {
111
+ child = child.nextElementSibling;
112
+ ptr = child
113
+ continue;
114
+ }
115
+ if (checkerTemplateAsFirstNode && child.tag == "template") {
116
+ child = child.nextElementSibling;
117
+ ptr = child
118
+ continue;
119
+ }
120
+ checkerTemplateAsFirstNode = false;
121
+ if (allTableTags[child.tag] && !tableTags[child.tag] && ((child.tag != check && child.tag != "col") || (flag && child.tag == "col"))) {
122
+ let temp = new Node(child);
123
+ if (temp.child) {
124
+ for (let i of temp.child) {
125
+ i.parent = temp;
126
+ }
127
+ }
128
+ targObj.appendChild(temp);
129
+
130
+ } else if (child.node != "#text") {
131
+ if (targObj.child && ptr) {
132
+ ptr.replaceWith(targObj);
133
+ targObj = new Node({
134
+ tag: check,
135
+ node: "#element"
136
+ })
137
+ }
138
+ while (child) {
139
+ child = child.nextElementSibling;
140
+ if (child && child.tag != check && child.tag !="template") {
141
+ break;
142
+ }
143
+ }
144
+ ptr = child;
145
+ if (!child) {
146
+ break;
147
+ } else {
148
+ continue;
149
+ }
150
+ } else if (child.node == "#text") {
151
+
152
+ let temp = new Node(child);
153
+ if (temp.child) {
154
+ for (let i of temp.child) {
155
+ i.parent = temp;
156
+ }
157
+ }
158
+ targObj.appendChild(temp);
159
+ }
160
+ let temp = child.next;
161
+ if (child != ptr) {
162
+ child.remove();
163
+ }
164
+ child = temp;
165
+ }
166
+ if (targObj.child && ptr) {
167
+ ptr.replaceWith(targObj);
168
+ }
169
+ };
170
+ if (check === "tbody") {
171
+ let checkParent = obj.querySelectorAll(check, true);
172
+ for (let tbody of checkParent) {
173
+ let tbodyParent = tbody.parent;
174
+ if (tbodyParent.tag != "table" && tbodyParent.tag != "template") {
175
+ if (tbody.parent.parent) {
176
+ let index = tbody.parent.parent.child.indexOf(tbody.parent);
177
+ let child = tbody.parent.parent.child
178
+ let temp = []
179
+ let tbodyNext = null;
180
+ tbodyParent.child.splice(tbodyParent.child.indexOf(tbody), 1);
181
+ // ;
182
+ if (tbody.next && tbody.next.node == "#text") {
183
+ tbodyNext = tbody.next;
184
+ tbodyParent.child.splice(tbodyParent.child.indexOf(tbody.next), 1);
185
+ }
186
+ let tbodyPushed = false;
187
+ function push_tBody(){
188
+ temp.push(tbody);
189
+ if (tbodyNext) {
190
+ temp.push(tbodyNext)
191
+ };
192
+ }
193
+ for (let i = 0; i < child.length; i++) {
194
+ if (i == index + 1) {
195
+ tbodyPushed = true;
196
+ push_tBody();
197
+ temp.push(child[i]);
198
+ } else {
199
+ temp.push(child[i]);
200
+ }
201
+ }
202
+ if(!tbodyPushed){
203
+ push_tBody();
204
+ }
205
+ tbody.parent.parent.child = []
206
+ let parent = tbody.parent.parent
207
+ for (let i = 0; i < temp.length; i++) {
208
+ parent.appendChild(temp[i]);
209
+ }
210
+
211
+ }
212
+ }
213
+ }
214
+ }
215
+ }
216
+
217
+ function processUnwantedTags(obj) {
218
+ let samp = obj.querySelectorAll("table", true);
219
+ for (let node of samp) {
220
+ ls = []
221
+ removeUnwantedTags(node);
222
+ let temp = [];
223
+ let index = node.parent.child.indexOf(node);
224
+ temp = (node.parent.child.slice(0, index)).concat(ls).concat(node.parent.child.slice(index, node.parent.child.length));
225
+
226
+ node.parent.child = [];
227
+ for (let i of temp) {
228
+ node.parent.appendChild(i);
229
+ }
230
+ }
231
+ }
232
+
233
+ function processTableTag(obj) {
234
+ processTable(obj, "table", "tbody")
235
+ processTable(obj, "thead", "tr");
236
+ processTable(obj, "tbody", "tr")
237
+ processTable(obj, "table", "colgroup", true)
238
+ processUnwantedTags(obj);
239
+
240
+ }
241
+
242
+ function processSelect(obj) {
243
+ let check = {
244
+ "opt": function (obj) {
245
+ if (!obj || !obj.child || !obj.child.length) {
246
+ return;
247
+ }
248
+ let child = (obj.child[0].node == "#text") ? obj.child[0].nextElementSibling : obj.child[0];
249
+ let ptr = undefined;
250
+ let text = ""
251
+ while (child) {
252
+ if (child.tag != "template" && child.node != "#text") {
253
+ let response = this.other(child);
254
+ if (child.node != "#text" && !ptr && child.tag != "template" && typeof response != "object") {
255
+ ptr = child;
256
+ }
257
+ if (typeof response == "object") {
258
+ child.replaceWith(new Node(response))
259
+ if (ptr) {
260
+ let index = ptr.parent.child.indexOf(ptr);
261
+ ptr.replaceWith(new Node({
262
+ node: "#text",
263
+ text: text
264
+ }));
265
+ this.text(ptr.parent.child[index]);
266
+ }
267
+ ptr = undefined;
268
+ text = ""
269
+ } else {
270
+ text += (" " + response.trim() + " ");
271
+ if (child != ptr) {
272
+ child.remove();
273
+ }
274
+ }
275
+ } else if (child.tag == "template") {
276
+ if (ptr) {
277
+ let index = ptr.parent.child.indexOf(ptr);
278
+ ptr.replaceWith(new Node({
279
+ node: "#text",
280
+ text: text
281
+ }));
282
+ this.text(ptr.parent.child[index]);
283
+ }
284
+ ptr = undefined;
285
+ text = ""
286
+ } else if (child.node == "#text" && child.text.trim().length > 0) {
287
+ let index = child.parent.child.indexOf(child);
288
+ this.text(child.parent.child[index]);
289
+ }
290
+ child = child.next;
291
+ }
292
+ if (ptr && text.trim().length > 0) {
293
+ let index = ptr.parent.child.indexOf(ptr);
294
+ ptr.replaceWith(new Node({
295
+ node: "#text",
296
+ text: text
297
+ }));
298
+ this.text(ptr.parent.child[index]);
299
+ }
300
+ },
301
+ "text": function (obj) {
302
+ let child = obj.prev;
303
+ let prevText = "";
304
+ while (child) {
305
+ if (child.node != "#text") {
306
+ break;
307
+ }
308
+ prevText = " " + child.text.trim() + prevText + " ";
309
+ let temp = child;
310
+ child.remove();
311
+ child = temp.prev;
312
+ }
313
+ child = obj.next;
314
+ let nextText = "";
315
+ while (child) {
316
+ if (child.node != "#text") {
317
+ break;
318
+ }
319
+ nextText = " " + nextText + child.text.trim() + " ";
320
+ let temp = child;
321
+ child.remove();
322
+ child = temp.next;
323
+ }
324
+ obj.text = prevText.trim() + obj.text + nextText.trim();
325
+ },
326
+ "other": function (obj, text = "") {
327
+ if (!obj) {
328
+ return text;
329
+ }
330
+ if (obj.tag == "template") {
331
+ return obj;
332
+ }
333
+ if (obj.node == "#text" && obj.text.trim().length > 0) {
334
+ text += (" " + obj.text.trim() + " ");
335
+ }
336
+ if (!obj.child) {
337
+ return text;
338
+ }
339
+ let child = obj.child
340
+ for (let i of child) {
341
+ text = this.other(i, text);
342
+ if (typeof res == "object") {
343
+ return res;
344
+ }
345
+ }
346
+ return text;
347
+ }
348
+ }
349
+ if (obj.child) {
350
+ let child = obj.child[0];
351
+ while (child) {
352
+ if (child.node != "#text") {
353
+ if (child.tag == "option" || child.tag == "optgroup") {
354
+ check.opt(child)
355
+ } else if (child.tag != "template") {
356
+ let response = check.other(child);
357
+ if (typeof response == "object") {
358
+ child.replaceWith(new Node(response))
359
+ } else {
360
+ let index = child.parent.child.indexOf(child);
361
+ child.replaceWith(new Node({
362
+ node: "#text",
363
+ text: response
364
+ }));
365
+ check.text(child.parent.child[index]);
366
+ }
367
+ }
368
+ }
369
+ child = child.next;
370
+ }
371
+ }
372
+ }
373
+
374
+ function processSelectTags(obj) {
375
+ let samp = obj.querySelectorAll("select", true);
376
+ for (let select of samp) {
377
+ processSelect(select);
378
+ }
379
+ }
380
+ export const htmlToJsObjectLyteRendered = (function () {
381
+ function removeDOCTYPE(html) {
382
+ return html
383
+ .replace(/<!doctype.*\>\n/, '')
384
+ .replace(/<!DOCTYPE.*\>\n/, '');
385
+ }
386
+ const convertToHtml = function (json, customHooks, checks) {
387
+ if (checks && checks.attrWithoutValue) {
388
+ checks.attrWithoutValue = createMapFor(checks.attrWithoutValue);
389
+ }
390
+ return getHtml(json, customHooks, checks);
391
+ }
392
+ const getHtml = function (json, customHooks, checks ,styleStarted = false) {
393
+ customHooks = customHooks || {
394
+ handlers: {}
395
+ };
396
+ if (typeof json === 'object' && json !== null && !Array.isArray(json)) {
397
+ // Empty Elements - HTML 4.01
398
+ if(json.tag == "style"){
399
+ styleStarted = true;
400
+ }
401
+ let empty = ['area', 'base', 'basefont', 'br', 'col', 'frame', 'hr', 'img', 'input', 'isindex', 'link', 'meta', 'param', 'embed', 'source', "track"],
402
+ attr = '',
403
+ attrType = json.attrType;
404
+ if (json.attr) {
405
+ let errorinfo;
406
+ if (json.attr.errorinfo) {
407
+ errorinfo = Object.assign(json.attr.errorinfo);
408
+ delete json.attr.errorinfo;
409
+ }
410
+ let spaceBetweenAttr = json.spaceBetweenAttr;
411
+ const prependSpace = function (res, spaceCheckKey) {
412
+ if (spaceBetweenAttr) {
413
+ let sp = spaceBetweenAttr[spaceCheckKey];
414
+ return ((sp && sp.sB) || " ") + res;
415
+ }
416
+ return res;
417
+ };
418
+ attr = Object.keys(json.attr).map(function (key) {
419
+ let spaceCheckKey = key.toLowerCase();
420
+ let value = json.attr[key],
421
+ closers = '"';
422
+ if (Array.isArray(value)) {
423
+ value = value.join(' ');
424
+ }
425
+ if (!checks || !checks.withoutTemplateConversion) {
426
+ value = value.replace(/&lt;/g, "<");
427
+ value = value.replace(/&gt;/g, ">");
428
+ value = value.replace(/"/g, "&quot;");
429
+ value = value.replace(/&apos;/gm, "'");
430
+ value = value.replace(/&(?!quot;)(?!amp;)(?![gl]t;)(?![Oo][Ee]lig;)(?![Ss]caron;)(?!Yuml;)(?!circ;)(?!tilde;)(?!e[mn]sp;)(?!thinsp;)(?!zwnj;)(?!zwj;)(?![hl]rm;)(?!rlm;)(?![mn]dash;)(?![rl]squo;)(?!sbquo;)(?![rbl]dquo;)(?![dD]agger;)(?!permil;)(?![rl]saquo;)(?!euro;)(?!nbsp;)(?!apos;)(?!cent;)(?!pound;)(?!yen;)(?!copy;)(?!reg;)/gm, "&amp;")
431
+ } else {
432
+ if (attrType && attrType.___nullCheck___ && attrType.___nullCheck___[key]) {
433
+ return prependSpace(key, spaceCheckKey);
434
+ }
435
+ if (checks.attrWithoutValue && checks.attrWithoutValue[key] && value == "") {
436
+ return prependSpace(key, spaceCheckKey);
437
+ }
438
+ if (attrType && attrType.___attrStart___) {
439
+ let valCloser = attrType.___attrStart___[key];
440
+ if (valCloser) {
441
+ closers = (valCloser === "'" || valCloser === '"') ? valCloser : "";
442
+ }
443
+ }
444
+ }
445
+
446
+ let sBE = "", sAE = "";
447
+ if (spaceBetweenAttr) {
448
+ let sp = spaceBetweenAttr[spaceCheckKey];
449
+ if (sp) {
450
+ if (sp.sBE) {
451
+ sBE = " ".repeat(sp.sBE);
452
+ }
453
+ if (sp.sAE) {
454
+ sAE = " ".repeat(sp.sAE);
455
+ }
456
+ }
457
+ }
458
+ return prependSpace(key + sBE + "=" + sAE + closers + value + closers, spaceCheckKey);
459
+ }).join(spaceBetweenAttr ? "" : ' ');
460
+ if (errorinfo) {
461
+ json.attr.errorInfo = errorinfo;
462
+ }
463
+ if (json.eS) {
464
+ attr = attr + json.eS;
465
+ }
466
+ if (attr !== '' && !spaceBetweenAttr) {
467
+ attr = ' ' + attr;
468
+ }
469
+ }
470
+ let child = '';
471
+ const convertChild = function () {
472
+ let ptr = json.child || json.content.child
473
+ if (ptr) {
474
+ child = ptr.map(function (item) {
475
+ return getHtml(item, customHooks, checks,styleStarted);
476
+ }).join('');
477
+ }
478
+ }
479
+ if (json.node === '#element') {
480
+ let tag = json.tag;
481
+ const handler = (customHooks.handlers || {})[json.node];
482
+ if (typeof handler === 'function') {
483
+ const output = handler(json);
484
+ if (output !== null) {
485
+ return output;
486
+ }
487
+ }
488
+
489
+ convertChild();
490
+ if (empty.indexOf(tag) > -1) {
491
+ // empty element
492
+ return '<' + json.tag + attr + '>';
493
+ }
494
+
495
+ // non empty element
496
+ let open = '<' + json.tag + attr + '>';
497
+ let close = '</' + json.tag + '>';
498
+ return open + child + close;
499
+ }
500
+
501
+ if (json.node === '#text') {
502
+ if (!styleStarted && (!checks || !checks.withoutTemplateConversion)) {
503
+ json.text = json.text.replace(/</g, "&lt;");
504
+ json.text = json.text.replace(/>/g, "&gt;");
505
+ json.text = json.text.replace(/&quot;/g, '"');
506
+ json.text = json.text.replace(/&(?!quot;)(?!amp;)(?![gl]t;)(?![Oo][Ee]lig;)(?![Ss]caron;)(?!Yuml;)(?!circ;)(?!tilde;)(?!e[mn]sp;)(?!thinsp;)(?!zwnj;)(?!zwj;)(?![hl]rm;)(?!rlm;)(?![mn]dash;)(?![rl]squo;)(?!sbquo;)(?![rbl]dquo;)(?![dD]agger;)(?!permil;)(?![rl]saquo;)(?!euro;)(?!nbsp;)(?!apos;)(?!cent;)(?!pound;)(?!yen;)(?!copy;)(?!reg;)/gm, "&amp;");
507
+ }
508
+ return json.text;
509
+ }
510
+
511
+ if (json.node === 'html') {
512
+ return json.html;
513
+ }
514
+
515
+ if (json.node === '#comment') {
516
+ let text = json.text;
517
+ if(text && text.startsWith("___PI:XMLStarts___")){
518
+ return json.text.replace("___PI:XMLStarts___","<?xml").replace("___PI:XMLEnds___","?>");
519
+ }
520
+ return '<!--' + json.text + '-->';
521
+ }
522
+
523
+ if (json.node === 'root') {
524
+ const handler = (customHooks.handlers || {})[json.node];
525
+ if (typeof handler === 'function') {
526
+ const output = handler(json);
527
+ if (output !== null) {
528
+ return output;
529
+ }
530
+ }
531
+ convertChild();
532
+ return child;
533
+ }
534
+
535
+ } else {
536
+ throw new Error("Invalid value. Expected object");
537
+ }
538
+ }
539
+ const find = (obj, find) => {
540
+ if (obj) {
541
+ let ls = Object.keys(obj);
542
+ for (let i = 0; i < ls.length; i++) {
543
+ if (ls[i] == find) {
544
+ return true;
545
+ }
546
+ }
547
+ }
548
+ return false;
549
+ }
550
+ // Strict-mode XSS guards (default on; set check.strict = false to opt out for trusted templates)
551
+ const STRICT_DANGEROUS_TAGS = createMapFor(["script", "object", "embed", "applet"]);
552
+ const SAFE_DATA_IMAGE_RE = /^data:image\/(?:png|jpe?g|gif|webp|bmp|x-icon|vnd\.microsoft\.icon)[;,]/i;
553
+ const EVENT_ATTR_RE = /^on[a-z0-9_-]+$/i;
554
+
555
+ const decodeNumericHexEntity = function (_, h) {
556
+ const code = parseInt(h, 16);
557
+ return Number.isFinite(code) ? String.fromCharCode(code) : "";
558
+ };
559
+ const decodeNumericDecEntity = function (_, d) {
560
+ const code = parseInt(d, 10);
561
+ return Number.isFinite(code) ? String.fromCharCode(code) : "";
562
+ };
563
+ const decodeHtmlForStrictCheck = function (value) {
564
+ let s = String(value == null ? "" : value);
565
+ for (let i = 0; i < 3; i++) {
566
+ const next = s
567
+ .replace(/&#x([0-9a-fA-F]+);?/g, decodeNumericHexEntity)
568
+ .replace(/&#(\d+);?/g, decodeNumericDecEntity)
569
+ .replace(/&colon;/gi, ":")
570
+ .replace(/&Tab;/gi, "\t")
571
+ .replace(/&NewLine;/gi, "\n")
572
+ .replace(/&lt;/gi, "<")
573
+ .replace(/&gt;/gi, ">")
574
+ .replace(/&quot;/gi, '"')
575
+ .replace(/&apos;/gi, "'")
576
+ .replace(/&amp;/gi, "&");
577
+ if (next === s) {
578
+ break;
579
+ }
580
+ s = next;
581
+ }
582
+ return s;
583
+ };
584
+
585
+ const normalizeForDangerousUrl = function (value) {
586
+ return decodeHtmlForStrictCheck(value).replace(
587
+ /[\u0000-\u0020\u00a0\u1680\u180e\u2000-\u200f\u2028-\u202f\u205f\u3000\ufeff]/g,
588
+ ""
589
+ );
590
+ };
591
+
592
+ const getDangerousUrlMatch = function (value) {
593
+ const s = normalizeForDangerousUrl(value).toLowerCase();
594
+ let match = s.match(/^(?:javascript|vbscript|livescript|mocha)\s*:/);
595
+ if (match) {
596
+ return match[0];
597
+ }
598
+ if (/^data\s*:/.test(s)) {
599
+ if (SAFE_DATA_IMAGE_RE.test(s) && !/^data\s*:\s*image\/svg\+xml/i.test(s)) {
600
+ return null;
601
+ }
602
+ return "data:";
603
+ }
604
+ return null;
605
+ };
606
+
607
+ const isDangerousSrcdoc = function (value) {
608
+ // Keep whitespace so patterns like "x onerror=" still match; strip only for scheme checks
609
+ const s = decodeHtmlForStrictCheck(value).toLowerCase();
610
+ if (/<script\b/.test(s)) {
611
+ return true;
612
+ }
613
+ if (/\bon[a-z0-9_-]+\s*=/.test(s)) {
614
+ return true;
615
+ }
616
+ const compact = s.replace(
617
+ /[\u0000-\u0020\u00a0\u1680\u180e\u2000-\u200f\u2028-\u202f\u205f\u3000\ufeff]/g,
618
+ ""
619
+ );
620
+ if (/(?:javascript|vbscript|livescript|mocha):/.test(compact)) {
621
+ return true;
622
+ }
623
+ if (/data:(?:text\/html|application\/xhtml|image\/svg)/.test(compact)) {
624
+ return true;
625
+ }
626
+ if (/<(?:iframe|object|embed|svg|math|link|meta|base|form|applet)\b/.test(s)) {
627
+ return true;
628
+ }
629
+ return false;
630
+ };
631
+
632
+ const throwStrictError = function (message, lineIndex, colIndex, value) {
633
+ const err = new Error(message);
634
+ err.strict = true;
635
+ err.lineIndex = lineIndex;
636
+ err.colIndex = colIndex;
637
+ err.value = value;
638
+ throw err;
639
+ };
640
+ const convertToObject = function (html, check = {
641
+ enhanced: false,
642
+ fromSub: false,
643
+ withoutTemplateConversion: false,
644
+ pageBuilder: {},
645
+ withLineIndex: false,
646
+ withColumnIndex: false,
647
+ emberFlag: false,
648
+ fileName: "",
649
+ fromCLI: false,
650
+ withoutTableProcessing: false,
651
+ ide: false
652
+ }, errorObj = {mustacheSyntax:{arr:[],obj:{}}},captureChildComponent) {
653
+ observedAttributes = {};
654
+ let cbe = check.callbacks || {};
655
+ if (!check.Compile) {
656
+ if(errorObj.warnings){
657
+ errorObj.warnings.push({
658
+ message: "Compile object is missing, so syntax checking for `Dynamic Value` is being skipped."
659
+ });
660
+ }
661
+ }
662
+ if (typeof html === "string" || html instanceof String) {
663
+ if (check) {
664
+ check.fromMain = true;
665
+ check.observedAttributes = observedAttributes;
666
+ check.fromParser = true;
667
+ check.syntaxCheckWorkerNew = syntaxCheckWorkerNew;
668
+
669
+ }
670
+
671
+ let isOptionCallBackPresent = false,
672
+ optionsData,
673
+ optionsCallBacks,preventSpaceText,cliVersion = check.cliVersion;
674
+ if (check.pageBuilder) {
675
+ preventSpaceText = check.pageBuilder.preventSpaceText;
676
+ optionsData = check.pageBuilder.data;
677
+ optionsCallBacks = check.pageBuilder.callbacks;
678
+ if (optionsCallBacks && typeof optionsCallBacks == 'object' && Object.keys(optionsCallBacks).length > 0) {
679
+ isOptionCallBackPresent = true;
680
+ }
681
+ }
682
+ html = removeDOCTYPE(html);
683
+ const bufferArray = [],
684
+ results = new Node({
685
+ node: 'root',
686
+ child: [],
687
+ check
688
+ });
689
+ if (check.Compile) {
690
+ setNodeCompile(results, check.Compile);
691
+ }
692
+ if (check.fromSub && check.hasParentSvg) {
693
+ results.hasParentSvg = check.hasParentSvg;
694
+ }
695
+ if (check.fromCLI) {
696
+ //To remove body tag inside a component
697
+ let match = html.match(/<body\s?.*?>/gm);
698
+ if (match) {
699
+ if (errorObj.warnings) {
700
+ errorObj.warnings.push({
701
+ message: "Warning: Misplaced body tag in " + match[0] + "....." + "</body>"
702
+ });
703
+ }
704
+ html = html.replace(/<body\s?.*?>/gm, "");
705
+ html = html.replace(/<\/body\s*>/gm, "");
706
+ }
707
+
708
+ }
709
+ if (check.enhanced) {
710
+ results.parent = null;
711
+ results.prev = null;
712
+ results.next = null;
713
+ if (check.withLineIndex) {
714
+ results.lineIndex = 0
715
+ };
716
+ if (check.withColumnIndex) {
717
+ results.colIndex = 0
718
+ };
719
+ }
720
+
721
+
722
+ htmlParser(html, {
723
+ start: function (tag, attrs, unary, seenSVGBefore, lineIndex, colIndex, eS) {
724
+ let parent = bufferArray[0] || results;
725
+ if (check.strict && STRICT_DANGEROUS_TAGS[String(tag).toLowerCase()]) {
726
+ throwStrictError(
727
+ "Strict-Mode: blocked <" + tag + "> — this tag is not allowed.",
728
+ lineIndex,
729
+ colIndex,
730
+ tag
731
+ );
732
+ }
733
+ if (tag == "style") {
734
+ styleTagStarted = true;
735
+ }
736
+ if (captureChildComponent && Array.isArray(captureChildComponent) && tag && tag.indexOf("-") != -1 && captureChildComponent.indexOf(tag) == -1) {
737
+ captureChildComponent.push(tag);
738
+ }
739
+ const node = (tag != "template" && (seenSVGBefore > 0 || check.hasParentSvg)) ? new Node({
740
+ node: '#element',
741
+ tag: tag,
742
+ child: [],
743
+ attrType: {},
744
+ check
745
+ }) : new Node({
746
+ node: '#element',
747
+ tag: tag,
748
+ child: [],
749
+ cont: [],
750
+ attrType: {},
751
+ check
752
+ });
753
+ if(node.tag == "table"){
754
+ check.hasSeenTable = true;
755
+ }
756
+ if(node.select == "select"){
757
+ check.hasSeenSelect = true;
758
+ }
759
+ if (check.Compile) {
760
+ setNodeCompile(node, check.Compile);
761
+ }
762
+ if (tag == "template" && seenSVGBefore == 0 && !check.hasParentSvg) {
763
+ node.content = node.createDocumentFragment();
764
+ }
765
+ if (check.enhanced) {
766
+ node.parent = parent;
767
+ node.prev = (parent.child && parent.child[parent.child.length - 1]) ? parent.child[parent.child.length - 1] : null;
768
+ node.next = null;
769
+ if (check.withLineIndex) {
770
+ node.lineIndex = lineIndex
771
+ };
772
+ if (check.withColumnIndex) {
773
+ node.colIndex = colIndex
774
+ };
775
+ node.attrType = {};
776
+ }
777
+ let attrType = {};
778
+ let spaceBetweenAttr;
779
+ if(!check.fromInternal && check.withoutTemplateConversion){
780
+ attrType = {
781
+ ___attrStart___: {},
782
+ ___nullCheck___: {}
783
+ }
784
+ node.spaceBetweenAttr = spaceBetweenAttr = {};
785
+ node.eS = eS || "";
786
+ }
787
+ let errorInfo = undefined;
788
+ if (attrs.length !== 0) {
789
+ node.attr = attrs.reduce(function (acc, attr) {
790
+ let name = attr.name;
791
+ let value = attr.value;
792
+ const nodeData = node.data;
793
+ if(spaceBetweenAttr){
794
+ spaceBetweenAttr[name.toLowerCase()] = {sB: attr.sB, sBE: attr.sBE, sAE: attr.sAE};
795
+ }
796
+ if (attr.errorInfo) {
797
+ node.errorInfo = attr.errorInfo;
798
+ }
799
+ let actValue = value;
800
+
801
+ //attrProcessStarts
802
+ value = value
803
+ .replace(/&nbsp;/gm, "@nbsp@")
804
+ .replace(/&#160;?/gm, "@nbsp@")
805
+ .replace(/&#xa0;?/gm, "@nbsp@")
806
+ .replace('.{}', '____lyteinternal____')
807
+ .replace(/\.\s*\[\s*\]/gm, '._LIB_')
808
+ .replace(/\.\s*\*/gm,'._LIS_');
809
+ value = decodeHtmlEntities.decode(value);
810
+ let _colIndex = attr.attrStartIndex || colIndex;
811
+ let res = syntaxCheckWorkerNew(value, check, errorObj, {
812
+ lineIndex,
813
+ colIndex: _colIndex
814
+ },true);
815
+ //attrProcessEnds
816
+
817
+ let _value,_name;
818
+ if(cbe.attr && typeof cbe.attr === 'function'){
819
+ let response = cbe.attr({
820
+ attrName: name,
821
+ processedValue: value,
822
+ originalValue: actValue
823
+ });
824
+ if(response != undefined){
825
+ if(typeof response === 'object'){
826
+ _value = response.attrValue;
827
+ if(response.attrName != undefined){
828
+ _name = response.attrName;
829
+ }
830
+ if(response.attrValue != undefined){
831
+ _value = response.attrValue;
832
+ }
833
+ } else if (typeof response === 'string'){
834
+ _value = response;
835
+ }
836
+ }
837
+ }
838
+
839
+ if(_value != undefined){
840
+ value = _value;
841
+ } else {
842
+ value = res.text;
843
+ }
844
+
845
+ if(_name != undefined){
846
+ name = _name;
847
+ }
848
+
849
+ if(value){
850
+ value = value
851
+ .replace(/_LIB_/g,"[]")
852
+ .replace(/_LIS_/g,"*");
853
+ }
854
+ if(check.strict){
855
+ const attrName = String(name == null ? "" : name).trim();
856
+ const attrValue = value == null ? "" : value;
857
+ if(EVENT_ATTR_RE.test(attrName)){
858
+ const isActionHelper =
859
+ (res.type == "helper" && res.capturedHelper == "action") ||
860
+ /^\s*\{\{\s*action\s*\(/i.test(String(attrValue));
861
+ if(!isActionHelper){
862
+ throwStrictError(
863
+ "Strict-Mode: Invalid "+attrName+" usage. Expected events inside {{action(…)}} inside "+node.tag,
864
+ lineIndex,
865
+ _colIndex,
866
+ attrValue
867
+ );
868
+ }
869
+ }
870
+ if(tag == "iframe" && attrName.toLowerCase() == "srcdoc" && isDangerousSrcdoc(attrValue)){
871
+ throwStrictError(
872
+ "Strict-Mode: blocked <iframe srcdoc> — inline scripts or active content detected. Remove inline JS or use a safe external script.",
873
+ lineIndex,
874
+ _colIndex,
875
+ attrValue
876
+ );
877
+ }
878
+ const dangerousUrl = getDangerousUrlMatch(attrValue);
879
+ if(dangerousUrl){
880
+ throwStrictError(
881
+ `Strict-Mode: blocked "${dangerousUrl}" URL — inline execution is not allowed.`,
882
+ lineIndex,
883
+ _colIndex,
884
+ attrValue
885
+ );
886
+ }
887
+ }
888
+ if (!acc[name] || (nodeData && nodeData[name])) {
889
+ if (isOptionCallBackPresent && optionsCallBacks[name] && typeof optionsCallBacks[name] === 'function') {
890
+ try {
891
+ value = optionsCallBacks[name](value);
892
+ } catch (e) {
893
+ console.error("Invalid callback");
894
+ return;
895
+ }
896
+ }
897
+ if (optionsData && optionsData[name]) {
898
+ const keyVal = optionsData[name];
899
+ node.data = node.data || {};
900
+ node.data[keyVal] = value;
901
+
902
+ } else {
903
+ acc[name] = value;
904
+ attrType[name] = res.type;
905
+ if (!check.fromInternal && check.withoutTemplateConversion){
906
+ attrType.___attrStart___[name] = attr.startChar;
907
+ if(attr.nullCheck){
908
+ attrType.___nullCheck___[name] = true;
909
+ }
910
+ }
911
+ }
912
+ }
913
+ return acc;
914
+ }, {});
915
+ if (errorInfo) {
916
+ node.errorInfo = errorInfo;
917
+ }
918
+
919
+ }
920
+
921
+ node.attrType = attrType;
922
+ if (check.enhanced && parent.child && parent.child.length) {
923
+ parent.child[parent.child.length - 1].next = node;
924
+ }
925
+
926
+ if (unary) {
927
+ let parent = bufferArray[0] || results;
928
+ if (parent.child === void 0) {
929
+ parent.child = [];
930
+ }
931
+ parent.child.push(node);
932
+ } else {
933
+ bufferArray.unshift(node);
934
+ }
935
+ },
936
+ end: function (tag, flag, misMatchCase, seenSVGBefore) {
937
+ if (tag == "style") {
938
+ styleTagStarted = false;
939
+ }
940
+ let node = bufferArray.shift();
941
+ if (node.parent && node.parent.node == "#element" && allTableTags[node.parent.tag.toLowerCase()] && allTableTags[node.tag.toLowerCase()] && tagLevel[node.tag] <= 1 && tagLevel[node.parent.tag.toLowerCase()] <= tagLevel[node.tag.toLowerCase()]) {
942
+ let err = new Error("Error: Invalid tag " + node.tagName + " inside " + node.parent.tagName);
943
+ err.fromParser = true;
944
+ throw err;
945
+ }
946
+ if (flag) {
947
+ node.setAttribute("lt-prop-MisMatchLastParent", "true");
948
+ }
949
+ if (misMatchCase) {
950
+ node.setAttribute("lt-prop-MisMatchClosingTags", "true");
951
+ }
952
+ if (node.tag !== tag) {
953
+ let err = new Error('Mismatch in end tag :' + tag);
954
+ err.fromParser = true;
955
+ throw err;
956
+ }
957
+ if (node.tag == "template" && seenSVGBefore == 0 && !check.hasParentSvg) {
958
+ let child = node.child;
959
+ if (!node.content) {
960
+ node.content = node.createDocumentFragment();
961
+ }
962
+ node.content.appendChildArr(child);
963
+ delete node.child;
964
+ }
965
+ if (bufferArray.length === 0) {
966
+ results.child.push(node);
967
+ } else {
968
+ const parent = bufferArray[0];
969
+ if (parent.child === void 0) {
970
+ parent.child = [];
971
+ }
972
+ parent.child.push(node);
973
+ }
974
+ let txtChild;
975
+ if (
976
+ node.tag &&
977
+ (node.tag == "pre" || node.tag == "textarea" || node.tag == "listing") &&
978
+ node.child &&
979
+ node.child.length &&
980
+ (txtChild = node.child[0]).node == "#text" &&
981
+ txtChild.text &&
982
+ (txtChild.text[0] == "\n" || txtChild.text[0] == "\r")
983
+ ) {
984
+ let text = txtChild.text;
985
+ text = text.replace(/^(?:(?:\r\n)|\r|\n)/,"");
986
+ txtChild.text = text;
987
+ if(!text){
988
+ node.child = node.child.slice(1);
989
+ txtChild.parent = null;
990
+ txtChild.prev = null;
991
+ if(txtChild.next){
992
+ txtChild.next.prev = null;
993
+ }
994
+ txtChild.next = null;
995
+ }
996
+ }
997
+ },
998
+ chars: function (text, lineIndex, colIndex, checkClosingTag) {
999
+ let trimmedContent;
1000
+ if (preventSpaceText==true || check.trimSpaces) {
1001
+ trimmedContent = text.trim();
1002
+ if(trimmedContent == ""){
1003
+ return;
1004
+ }
1005
+ (check.trimSpaces) && (text = trimmedContent);
1006
+ }
1007
+ let parent = bufferArray[0] || results;
1008
+ const node = new Node({
1009
+ node: '#text',
1010
+ text: text,
1011
+ attrType: ""
1012
+ });
1013
+ if (check.Compile) {
1014
+ setNodeCompile(node, check.Compile);
1015
+ }
1016
+ // @newChanges
1017
+ if (styleTagStarted) {
1018
+ node.style = true;
1019
+ }
1020
+ text = text
1021
+ .replace(/&nbsp;?/gm, "@nbsp@")
1022
+ .replace(/&#160;?/gm, "@nbsp@")
1023
+ .replace(/&#xa0;?/gm, "@nbsp@")
1024
+ .replace('.{}', '____lyteinternal____')
1025
+ .replace(/\.\s*\[\s*\]/gm, '._LIB_')
1026
+ .replace(/\.\s*\*/gm,'._LIS_');
1027
+ node.text = decodeHtmlEntities.decode(text, true);
1028
+ if (check.enhanced) {
1029
+ node.parent = parent;
1030
+ node.prev = (parent.child && parent.child[parent.child.length - 1]) ? parent.child[parent.child.length - 1] : null;
1031
+ node.next = null;
1032
+ if (check.withLineIndex) {
1033
+ node.lineIndex = lineIndex
1034
+ };
1035
+ if (check.withColumnIndex) {
1036
+ node.colIndex = colIndex
1037
+ };
1038
+ }
1039
+ if (check.enhanced && parent.child && parent.child.length) {
1040
+ parent.child[parent.child.length - 1].next = node;
1041
+ }
1042
+ if (bufferArray.length === 0) {
1043
+ results.child.push(node);
1044
+ } else {
1045
+ const parent = bufferArray[0] || results;
1046
+ if (parent.child === void 0) {
1047
+ parent.child = [];
1048
+ }
1049
+ parent.child.push(node);
1050
+ }
1051
+
1052
+ let res = syntaxCheckWorkerNew(node.text, check, errorObj, {
1053
+ lineIndex,
1054
+ colIndex
1055
+ });
1056
+ if(preventSpaceText==true){
1057
+ node.text = trimmedContent;
1058
+ }
1059
+ else{
1060
+ node.attrType = (res.type) ? res.type : "";
1061
+ let _text = res.text;
1062
+ if(_text){
1063
+ _text = _text
1064
+ .replace(/_LIB_/g,"[]")
1065
+ .replace(/_LIS_/g,"*");
1066
+ }
1067
+ node.text = _text;
1068
+
1069
+ if (node.prev && node.prev.node == "#text") {
1070
+ let text = node.prev.text;
1071
+ node.text = text + node.text;
1072
+ node.prev.remove();
1073
+ }
1074
+ let nodeValue = node.text;
1075
+ if (nodeValue) {
1076
+ let mustacheValues = nodeValue.match(/{{[^}]*?(?:(?:('|")[^\1]*?\1)[^}]*?)*}}/g); //'
1077
+ if (mustacheValues) {
1078
+ let newNodeArray = [],
1079
+ lastIndex = 0,
1080
+ offset = 0,
1081
+ flag = false;
1082
+ for (let i = 0; i < mustacheValues.length; i++) {
1083
+ let mustacheStartIndex = nodeValue.indexOf(mustacheValues[i]),
1084
+ mustacheEndIndex = mustacheStartIndex + mustacheValues[i].length;
1085
+ if (mustacheStartIndex) {
1086
+ flag = true;
1087
+ newNodeArray.push(node.createTextNode(nodeValue.substring(0, mustacheStartIndex), {
1088
+ parent: node.parent,
1089
+ lineIndex: (check.withLineIndex) ? lineIndex : undefined,
1090
+ colIndex: (check.withColumnIndex) ? colIndex + offset : undefined,
1091
+ attrType: ""
1092
+ }));
1093
+ }
1094
+ newNodeArray.push(node.createTextNode(nodeValue.substring(mustacheStartIndex, mustacheEndIndex), {
1095
+ parent: node.parent,
1096
+ lineIndex: (check.withLineIndex) ? lineIndex : undefined,
1097
+ colIndex: (check.withColumnIndex) ? colIndex + mustacheStartIndex + offset : undefined,
1098
+ attrType: res.type
1099
+ }));
1100
+ offset = offset + mustacheEndIndex;
1101
+ nodeValue = nodeValue.substring(mustacheEndIndex);
1102
+ lastIndex = colIndex + offset;
1103
+ }
1104
+ newNodeArray.push(node.createTextNode(nodeValue, {
1105
+ parent: node.parent,
1106
+ lineIndex: (check.withLineIndex) ? lineIndex : undefined,
1107
+ colIndex: (check.withColumnIndex) ? lastIndex : undefined,
1108
+ attrType: ""
1109
+ }));
1110
+ for (let i = 0; i < newNodeArray.length - 1; i++) {
1111
+ newNodeArray[i].next = newNodeArray[i + 1];
1112
+ }
1113
+ for (let i = 1; i < newNodeArray.length; i++) {
1114
+ newNodeArray[i].prev = newNodeArray[i - 1];
1115
+ }
1116
+ if (node.parent && node.parent.child) {
1117
+ if (flag && node.prev) {
1118
+ let lastChild = node.prev;
1119
+ lastChild.next = newNodeArray[0];
1120
+ newNodeArray[0].prev = lastChild;
1121
+ }
1122
+ let ls = node.parent.child,
1123
+ index = node.parent.child.indexOf(node),
1124
+ args = [index, 1].concat(newNodeArray);
1125
+ Array.prototype.splice.apply(ls, args);
1126
+ }
1127
+ }
1128
+ }
1129
+ }
1130
+ },
1131
+ comment: function (text, lineIndex, colIndex) {
1132
+ if (!check.withoutComment) {
1133
+ let par;
1134
+ const node = new Node({
1135
+ node: '#comment',
1136
+ text: text
1137
+ });
1138
+ par = bufferArray[0] || results;
1139
+ if (check.enhanced) {
1140
+ node.parent = par;
1141
+ node.prev = (par.child && par.child[par.child.length - 1]) ? par.child[par.child.length - 1] : null;
1142
+ node.next = null;
1143
+ if (check.withLineIndex) {
1144
+ node.lineIndex = lineIndex
1145
+ };
1146
+ if (check.withColumnIndex) {
1147
+ node.colIndex = colIndex
1148
+ };
1149
+ }
1150
+ if (check.enhanced && par.child && par.child.length) {
1151
+ par.child[par.child.length - 1].next = node;
1152
+ }
1153
+ const parent = bufferArray[0] || results;
1154
+ if (parent.child === void 0) {
1155
+ parent.child = [];
1156
+ }
1157
+ parent.child.push(node);
1158
+ }
1159
+ }
1160
+ },
1161
+ check, errorObj);
1162
+ if (!check.withoutTableProcessing) {
1163
+ if(check.hasSeenTable){
1164
+ processTableTag(results);
1165
+ }
1166
+ if(check.hasSeenSelector){
1167
+ processSelectTags(results);
1168
+ }
1169
+ }
1170
+ let s;
1171
+ if (!check.withoutTemplateConversion) {
1172
+ let comp;
1173
+ if(check.isElemental){
1174
+ comp = results.querySelector("template[@elemental='" + check.fileName + "']");
1175
+ } else {
1176
+ comp = results.querySelector("template[tag-name='" + check.fileName + "']");
1177
+ }
1178
+ if (!comp) {
1179
+ throw new Error("Cannot find template " + check.fileName);
1180
+ }
1181
+ let nextElement = comp.nextElementSibling;
1182
+ if(cliVersion == 4){
1183
+ if(!check.isElemental){
1184
+ if (nextElement && nextElement.tagName == "TEMPLATE" && nextElement.hasAttribute("view-port-template")) {
1185
+ errorObj.warnings.push({
1186
+ message: "Depricated Syntax : 'view-port-template' found in " + check.fileName + " . Migrate your app to using latest slyte-migrator."
1187
+ });
1188
+ let viewPortIf = comp.createElement("template");
1189
+ viewPortIf.setAttribute("lyte-if", "{{lyteViewPort}}");
1190
+ viewPortIf.setAttribute("__vp", "c-old");
1191
+ viewPortIf.content.appendChild(comp.createElement("dummy-port-element"));
1192
+ viewPortIf.content.appendChild(nextElement.content);
1193
+ viewPortIf.content.appendChild(comp.createElement("dummy-port-element"));
1194
+ let falseCase = comp.createElement("template");
1195
+ falseCase.setAttribute("lyte-else", "");
1196
+ falseCase.content.appendChild(comp.content);
1197
+ comp.innerHTML = "";
1198
+ comp.content.appendChild(viewPortIf);
1199
+ comp.content.appendChild(falseCase);
1200
+ nextElement.remove();
1201
+ } else if (nextElement && nextElement.tagName == "TEMPLATE" && nextElement.attributes["@view-out"]) {
1202
+ let viewPortIf = comp.createElement("template"); //actual content
1203
+ let attrVal = comp.getAttribute("@view-in");
1204
+ if (attrVal.startsWith("{{")) {
1205
+ attrVal = attrVal.substring(2, attrVal.length - 2);
1206
+ viewPortIf.setAttribute("lyte-if", "{{lyteViewPort(" + attrVal + ")}}");
1207
+ } else if (attrVal === "") {
1208
+ ;
1209
+ viewPortIf.setAttribute("lyte-if", "{{lyteViewPort()}}");
1210
+ } else {
1211
+ viewPortIf.setAttribute("lyte-if", "{{lyteViewPort(" + attrVal + ")}}");
1212
+ }
1213
+ viewPortIf.setAttribute("__vp", "c-new");
1214
+ viewPortIf.content.appendChild(comp.content);
1215
+ comp.removeAttribute("@view-in");
1216
+
1217
+ let viewPortElse = comp.createElement("template"); //loading
1218
+ viewPortElse.setAttribute("lyte-else", "");
1219
+
1220
+ viewPortElse.content.appendChild(comp.createElement("dummy-port-element"));
1221
+ viewPortElse.content.appendChild(nextElement.content);
1222
+ viewPortElse.content.appendChild(comp.createElement("dummy-port-element"));
1223
+
1224
+ comp.innerHTML = "";
1225
+
1226
+ comp.content.appendChild(viewPortIf);
1227
+ comp.content.appendChild(viewPortElse);
1228
+ nextElement.remove();
1229
+ comp.setAttribute("__vp", "c-new");
1230
+ }
1231
+ }
1232
+ } else {
1233
+ if(nextElement && nextElement.tagName == "TEMPLATE" && nextElement.hasAttribute("view-port-template")) {
1234
+ let viewPortIf = comp.createElement("template");
1235
+ viewPortIf.setAttribute("is", "if");
1236
+ viewPortIf.setAttribute("value", "{{lyteViewPort}}");
1237
+ let trueCase = comp.createElement("template");
1238
+ trueCase.setAttribute("case", "true");
1239
+ trueCase.content.appendChild(comp.createElement("dummy-port-element"));
1240
+ trueCase.content.appendChild(nextElement.content);
1241
+ trueCase.content.appendChild(comp.createElement("dummy-port-element"));
1242
+ viewPortIf.content.appendChild(trueCase);
1243
+ let falseCase = comp.createElement("template");
1244
+ falseCase.setAttribute("case", "false");
1245
+ // falseCase.innerHTML = comp.innerHTML;
1246
+ falseCase.content.appendChild(comp.content);
1247
+ viewPortIf.content.appendChild(falseCase);
1248
+ comp.innerHTML = "";
1249
+ comp.content.appendChild(viewPortIf);
1250
+ nextElement.remove();
1251
+ }
1252
+ }
1253
+ check.Compile.splitTextNodes(comp.content, errorObj.warnings, undefined, check, errorObj, undefined);
1254
+ s = results.querySelectorAll("[lyte-else]", true);
1255
+ for (let i = 0; i < s.length; i++) {
1256
+ let node = s[i]
1257
+ if (node && !(node.previousElementSibling && (find(node.previousElementSibling, "lyte-if") || find(node.previousElementSibling, "lyte-else-if")))) {
1258
+ let temp = node.cloneNode();
1259
+ temp.innerHTML = "...";
1260
+ if (errorObj && errorObj.warnings && check.fromCLI) {
1261
+ errorObj.warnings.push({
1262
+ message: "Parse Warning : `lyte-else` without `lyte-if` in " + temp.outerHTML
1263
+ });
1264
+ } else {
1265
+ console.warn("Parse Warning : `lyte-else` without `lyte-if` in " + temp.outerHTML);
1266
+ }
1267
+ }
1268
+ }
1269
+
1270
+ s = results.querySelectorAll("[lyte-else-if]", true)
1271
+ for (let i = 0; i < s.length; i++) {
1272
+ let node = s[i]
1273
+ if (node && !(node.previousElementSibling && (find(node.previousElementSibling, "lyte-if") || find(node.previousElementSibling, "lyte-else-if")))) {
1274
+ let temp = node.cloneNode();
1275
+ temp.innerHTML = "...";
1276
+ if (errorObj && errorObj.warnings && check.fromCLI) {
1277
+ errorObj.warnings.push({
1278
+ message: "Parse Warning : `lyte-else-if` without `lyte-if` in " + temp.outerHTML
1279
+ });
1280
+ } else {
1281
+ console.warn("Parse Warning : `lyte-else-if` without `lyte-if` in " + temp.outerHTML);
1282
+ }
1283
+ }
1284
+ }
1285
+ }
1286
+ if (check.emberFlag) {
1287
+ let objAttr = check.observedAttributes;
1288
+ delete objAttr.this;
1289
+ results.observedAttributes = Object.keys(objAttr);
1290
+ }
1291
+ return results;
1292
+ } else {
1293
+ throw new Error("Error: Invalid value. Expected string");
1294
+ }
1295
+ }
1296
+
1297
+ const API = {
1298
+ toHtml: convertToHtml,
1299
+ toObject: convertToObject,
1300
+ processTable: processTableTag
1301
+ }
1302
+ return API;
1303
+ }());
1304
+
1305
+ export default htmlToJsObjectLyteRendered;
1306
+ //ignorei18n_end