@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,870 @@
1
+ //ignorei18n_start
2
+ //BabelCodeStarts
3
+ function _wrapRegExp() {
4
+ _wrapRegExp = function (e, r) {
5
+ return new BabelRegExp(e, void 0, r);
6
+ };
7
+ var e = RegExp.prototype,
8
+ r = new WeakMap();
9
+
10
+ function BabelRegExp(e, t, p) {
11
+ var o = RegExp(e, t);
12
+ return r.set(o, p || r.get(e)), _setPrototypeOf(o, BabelRegExp.prototype);
13
+ }
14
+
15
+ function buildGroups(e, t) {
16
+ var p = r.get(t);
17
+ return Object.keys(p).reduce(function (r, t) {
18
+ var o = p[t];
19
+ if ("number" == typeof o){
20
+ r[t] = e[o]
21
+ }
22
+ else {
23
+ for (var i = 0; void 0 === e[o[i]] && i + 1 < o.length;) {i++;}
24
+ r[t] = e[o[i]];
25
+ }
26
+ return r;
27
+ }, Object.create(null));
28
+ }
29
+ return _inherits(BabelRegExp, RegExp), BabelRegExp.prototype.exec = function (r) {
30
+ var t = e.exec.call(this, r);
31
+ if (t) {
32
+ t.groups = buildGroups(t, this);
33
+ var p = t.indices;
34
+ p && (p.groups = buildGroups(p, this));
35
+ }
36
+ return t;
37
+ }, BabelRegExp.prototype[Symbol.replace] = function (t, p) {
38
+ if ("string" == typeof p) {
39
+ var o = r.get(this);
40
+ return e[Symbol.replace].call(this, t, p.replace(/\$<([^>]+)>/g, function (e, r) {
41
+ var t = o[r];
42
+ return "$" + (Array.isArray(t) ? t.join("$") : t);
43
+ }));
44
+ }
45
+ if ("function" == typeof p) {
46
+ var i = this;
47
+ return e[Symbol.replace].call(this, t, function () {
48
+ var e = arguments;
49
+ return "object" != typeof e[e.length - 1] && (e = [].slice.call(e)).push(buildGroups(e, i)), p.apply(this, e);
50
+ });
51
+ }
52
+ return e[Symbol.replace].call(this, t, p);
53
+ }, _wrapRegExp.apply(this, arguments);
54
+ }
55
+
56
+ function _inherits(subClass, superClass) {
57
+ if (typeof superClass !== "function" && superClass !== null) {
58
+ throw new TypeError("Super expression must either be null or a function");
59
+ }
60
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
61
+ constructor: {
62
+ value: subClass,
63
+ writable: true,
64
+ configurable: true
65
+ }
66
+ });
67
+ Object.defineProperty(subClass, "prototype", {
68
+ writable: false
69
+ });
70
+ if (superClass) {
71
+ _setPrototypeOf(subClass, superClass)
72
+ };
73
+ }
74
+
75
+ function _setPrototypeOf(o, p) {
76
+ _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
77
+ o.__proto__ = p;
78
+ return o;
79
+ };
80
+ return _setPrototypeOf(o, p);
81
+ }
82
+ //BabelCodeEnds
83
+
84
+ const HTMLParser = (function () {
85
+ const regexFor = {
86
+ endTag: /*#__PURE__*/ _wrapRegExp(/^<\/([a-zA-z][-a-zA-Z0-9_]*)((?:\s*[a-zA-Z_:!0-9,][-a-zA-Z0-9_:%."'`;]*(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^>]+))?)*)\s*(\/?)>/, {
87
+ nodeName: 1,
88
+ attributes: 2
89
+ }),
90
+ attr: /([a-zA-Z0-9_:!'"},@{$][-a-zA-Z0-9_:."'`%;{]*)(?:\s*=\s*(?:(?:"((?:\\.|[^"])*)")|(?:'((?:\\.|[^'])*)')|([^>\s]+)))?/g
91
+ },
92
+ svgCamelCaseTags = {
93
+ "filterunits": "filterUnits",
94
+ "allowreorder": "allowReorder",
95
+ "attributename": "attributeName",
96
+ "attributetype": "attributeType",
97
+ "autoreverse": "autoReverse",
98
+ "basefrequency": "baseFrequency",
99
+ "baseprofile": "baseProfile",
100
+ "calcmode": "calcMode",
101
+ "clippathunits": "clipPathUnits",
102
+ "contentScriptType": "contentScriptType",
103
+ "contentstyletype": "contentStyleType",
104
+ "diffuseconstant": "diffuseConstant",
105
+ "edgemode": "edgeMode",
106
+ "externalresourcesrequired": "externalResourcesRequired",
107
+ "filterres": "filterRes",
108
+ "filterUnits": "filterUnits",
109
+ "glyphref": "glyphRef",
110
+ "gradienttransform": "gradientTransform",
111
+ "gradientunits": "gradientUnits",
112
+ "kernelmatrix": "kernelMatrix",
113
+ "kernelunitlength": "kernelUnitLength",
114
+ "keypoints": "keyPoints",
115
+ "keysplines": "keySplines",
116
+ "keytimes": "keyTimes",
117
+ "lengthadjust": "lengthAdjust",
118
+ "limitingconeangle": "limitingConeAngle",
119
+ "markerheight": "markerHeight",
120
+ "markerunits": "markerUnits",
121
+ "markerwidth": "markerWidth",
122
+ "maskcontentunits": "maskContentUnits",
123
+ "maskunits": "maskUnits",
124
+ "patterncontentunits": "patternContentUnits",
125
+ "patterntransform": "patternTransform",
126
+ "patternunits": "patternUnits",
127
+ "pointsatx": "pointsAtX",
128
+ "pointsaty": "pointsAtY",
129
+ "pointsatz": "pointsAtZ",
130
+ "preservealpha": "preserveAlpha",
131
+ "preserveaspectratio": "preserveAspectRatio",
132
+ "primitiveunits": "primitiveUnits",
133
+ "repeatcount": "repeatCount",
134
+ "repeatdur": "repeatDur",
135
+ "requiredextensions": "requiredExtensions",
136
+ "requiredfeatures": "requiredFeatures",
137
+ "specularconstant": "specularConstant",
138
+ "specularexponent": "specularExponent",
139
+ "spreadmethod": "spreadMethod",
140
+ "startoffset": "startOffset",
141
+ "stddeviation": "stdDeviation",
142
+ "stitchtiles": "stitchTiles",
143
+ "surfacescale": "surfaceScale",
144
+ "systemlanguage": "systemLanguage",
145
+ "tablevalues": "tableValues",
146
+ "textlength": "textLength",
147
+ "viewbox": "viewBox",
148
+ "viewtarget": "viewTarget",
149
+ "xchannelselector": "xChannelSelector",
150
+ "ychannelselector": "yChannelSelector",
151
+ "refx": "refX",
152
+ "refy": "refY",
153
+ "targetx": "targetX",
154
+ "targety": "targetY",
155
+ "numoctaves": "numOctaves",
156
+ "zoomandpan": "zoomAndPan",
157
+ },
158
+ chromeChangedTags = {
159
+ "image": "img"
160
+ },
161
+ createMapFor = function (array) {
162
+ return array.reduce(function (acc, item) {
163
+ acc[item] = true;
164
+ return acc;
165
+ }, {});
166
+ },
167
+ dasherize = function(string,fancyComponent,attr) {
168
+ let lowerTagName, specifiedComponentCheck = typeof fancyComponent == "object";
169
+ if( string &&
170
+ !svgCamelCaseTags[lowerTagName = string.toLowerCase()] &&
171
+ !svgMiddleMen[lowerTagName] &&
172
+ (!specifiedComponentCheck || fancyComponent[string]) &&
173
+ (!attr || !string.match(/^on/gm))
174
+ ){
175
+ if(!cache_d[string]){
176
+ cache_d[string] = string.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
177
+ string!= cache_d[string] && console.log(string);
178
+ }
179
+ return cache_d[string];
180
+ }
181
+ return string;
182
+ },
183
+ svgMiddleMen = createMapFor(['foreignobject']),
184
+ svgSelfClosingTags = createMapFor([
185
+ 'title',
186
+ "animate",
187
+ "animateColor",
188
+ "animateTransform",
189
+ "circle",
190
+ "ellipse",
191
+ "feBlend",
192
+ "feColorMatrix",
193
+ "feComponentTransfer",
194
+ "feComposite",
195
+ "feConvolveMatrix",
196
+ "feDiffuseLighting",
197
+ "feDisplacementMap",
198
+ "feDistantLight",
199
+ "feFlood",
200
+ "feFuncA",
201
+ "feFuncB",
202
+ "feFuncG",
203
+ "feFuncR",
204
+ "feGaussianBlur",
205
+ "feImage",
206
+ "feMergeNode",
207
+ "feMorphology",
208
+ "feOffset",
209
+ "fePointLight",
210
+ "feSpecularLighting",
211
+ "feSpotLight",
212
+ "feTile",
213
+ "feTurbulence",
214
+ "line",
215
+ "path",
216
+ "polygon",
217
+ "polyline",
218
+ "rect",
219
+ "stop",
220
+ "use"
221
+ ]),
222
+ tableTags = createMapFor(["tbody", "thead", "tfoot", "colgroup", "caption", "tr", "th", "td", "col"]),
223
+ EMPTY_ELEMENTS = createMapFor([
224
+ "area",
225
+ "base",
226
+ "basefont",
227
+ "br",
228
+ "col",
229
+ "frame",
230
+ "hr",
231
+ "img",
232
+ "image",
233
+ "track",
234
+ "input",
235
+ "link",
236
+ "meta",
237
+ "param",
238
+ "embed",
239
+ "command",
240
+ "keygen",
241
+ "source",
242
+ "wbr",
243
+ // "circle",
244
+ // "ellipse",
245
+ // "line",
246
+ // "polyline",
247
+ // "rect",
248
+ ]),
249
+ SELF_CLOSING = createMapFor([
250
+ "colgroup",
251
+ "dd",
252
+ "dt",
253
+ "li",
254
+ "options",
255
+ "p",
256
+ ]),
257
+ SPECIAL_ELEMENTS = createMapFor([
258
+ 'style',
259
+ 'script'
260
+ ]),
261
+ nodeStartStack = [];
262
+
263
+ let cache_d = {},cache_c = {},
264
+ paragraphTagStarted = 0,
265
+ willHaveUnclosedClosingTag = false,
266
+ checkClosingTag = false,
267
+ selfClosingTags = createMapFor(['style', 'area', 'base', 'br', 'col', 'embed', 'hr', 'input', 'keygen', 'link', 'meta', 'param', 'wbr', 'img', 'track', 'image']),
268
+ notAllowedTagsInsideParagraphTag = createMapFor(["div", "table", "body", "h1", "h2", "h3", "h4", "h5", "h6", "ul", "li"]);
269
+ function countStartingSpaces(str) {
270
+ return (str.match(/^\s*/) || [''])[0].length;
271
+ }
272
+ function countTrailingSpaces(str) {
273
+ return (str.match(/\s*$/) || [''])[0].length;
274
+ }
275
+
276
+ return function (htmlString, callbacks, options, errorObj, lineIndex = 1, colIndex = 0) {
277
+ let {emberFlag, fileName, withoutTableProcessing, fancyComponent} = options,
278
+ hasUnparsedChars,
279
+ match,
280
+ mismatchColIndex = {},
281
+ stack = [],
282
+ seenSVGBefore = 0,
283
+ seenSvgMiddleMenBefore = 0,
284
+ seenTableBefore = 0,
285
+ stringInPrevLoopState = htmlString,
286
+ elemStack = [],
287
+ excludeSelfClosingTag = createMapFor(options.excludeSelfClosingTag || []);
288
+ stack.getLastItem = function () {
289
+ return this[this.length - 1];
290
+ };
291
+ elemStack.getLastItem = function () {
292
+ return this[this.length - 1];
293
+ }
294
+ function validateTagName(str, errorObject) {
295
+ str = str.trim()
296
+ if (str.length == 0 || !(/^[a-zA-Z_][-a-zA-Z0-9_]*$/).test(str)) {
297
+ errorObject.bool = false;
298
+ errorObject.error = "Invalid tag name :`" + "<" + str + "`";
299
+ errorObject.fromParser = true;
300
+ return false;
301
+ }
302
+ if(seenSVGBefore && str.toLowerCase() == "image"){
303
+ return "image";
304
+ }
305
+ return chromeChangedTags[str] ? chromeChangedTags[str] : str;
306
+ }
307
+
308
+ function getStartTag(str) {
309
+ try {
310
+ let foundTagName = false,
311
+ tagName = "",
312
+ errorObject = {
313
+ bool: true
314
+ },
315
+ doubleQuotesStarted = false,
316
+ dIndex = 0,
317
+ singleQuotesStarted = false,
318
+ sIndex = 0,
319
+ mustacheStarted = 0,
320
+ mIndex = 0,
321
+ attrStartIndex = 0,
322
+ tickStarted = false;
323
+
324
+ for (let i = 0; i < str.length; i++) {
325
+ if (!foundTagName) {
326
+ if (/\s/.test(str[i]) || str[i] == "/") {
327
+ tagName = validateTagName(tagName, errorObject)
328
+ if (!tagName) return errorObject;
329
+ foundTagName = true
330
+ attrStartIndex = i;
331
+ continue;
332
+ }
333
+ if (str[i] == ">") {
334
+ tagName = validateTagName(tagName, errorObject)
335
+ if (!tagName) return errorObject;
336
+ let res = ["<" + str.substring(0, i + 1), tagName, "", "", "<" + str];
337
+ res.bool = true;
338
+ return res;
339
+ }
340
+ if (str[i] == "/" && str[i + 1] == ">") {
341
+ tagName = validateTagName(tagName, errorObject)
342
+ if (!tagName) return errorObject;
343
+ let res = ["<" + str.substring(0, i + 1), tagName, "", "/", "<" + str];
344
+ res.bool = true;
345
+ return res;
346
+ }
347
+ tagName += str[i];
348
+ continue;
349
+ }
350
+ if (str[i] == "`" && str[i - 1] != "\\" && !doubleQuotesStarted && !singleQuotesStarted) {
351
+ tickStarted = !tickStarted;
352
+ sIndex = i + 1;
353
+ }
354
+ if (str[i] == "'" && str[i - 1] != "\\" && !doubleQuotesStarted && !tickStarted) {
355
+ singleQuotesStarted = !singleQuotesStarted;
356
+ sIndex = i + 1;
357
+ }
358
+ if (str[i] == '"' && str[i - 1] != "\\" && !singleQuotesStarted && !tickStarted) {
359
+ doubleQuotesStarted = !doubleQuotesStarted;
360
+ dIndex = i + 1;
361
+ }
362
+ if (!tickStarted && !singleQuotesStarted && !doubleQuotesStarted && str[i] == "{" && str[i + 1] == "{") {
363
+ mustacheStarted = true;
364
+ mIndex = i;
365
+ }
366
+ if (!tickStarted && !singleQuotesStarted && !doubleQuotesStarted && str[i] == "}" && str[i + 1] == "}") {
367
+ mustacheStarted = false;
368
+ }
369
+ if (!tickStarted && !singleQuotesStarted && !doubleQuotesStarted && !mustacheStarted && str[i] == "<") {
370
+ errorObject.bool = false;
371
+ errorObject.error = "Unclosed `>` for the tag `" + tagName + "`";
372
+ errorObject.fromParser = true;
373
+ let temp = str.substr(0, i).split("\n");
374
+ lineIndex += (temp.length - 1);
375
+ colIndex = temp[temp.length - 1].length;
376
+ return errorObject;
377
+ }
378
+ if (!tickStarted && !singleQuotesStarted && !doubleQuotesStarted && !mustacheStarted && str[i] == ">") {
379
+ let res = [];
380
+ if (str[i - 1] == "/") {
381
+ res = ["<" + str.substring(0, i + 1), tagName, str.substring(attrStartIndex, i - 1), "/", "<" + str];
382
+ res.bool = true;
383
+ return res;
384
+ }
385
+ res = ["<" + str.substring(0, i + 1), tagName, str.substring(attrStartIndex, i), "", "<" + str]
386
+ res.bool = true;
387
+ return res;
388
+ }
389
+ }
390
+ errorObject.bool = false;
391
+ let temp;
392
+ if (singleQuotesStarted) {
393
+ errorObject.error = "Unclosed Single Quote ";
394
+ temp = str.substr(0, sIndex).split("\n");
395
+ lineIndex += (temp.length - 1);
396
+ colIndex = temp[temp.length - 1].length;
397
+ errorObject.index = str.substring(0, sIndex);
398
+ } else if (doubleQuotesStarted) {
399
+ errorObject.error = "Unclosed Double Quote ";
400
+ temp = str.substr(0, dIndex).split("\n");
401
+ lineIndex += (temp.length - 1);
402
+ colIndex = temp[temp.length - 1].length;
403
+ errorObject.index = str.substring(0, dIndex);
404
+ } else if (mustacheStarted) {
405
+ errorObject.error = "Unclosed Mustache ";
406
+ temp = str.substr(0, mIndex).split("\n");
407
+ lineIndex += (temp.length - 1);
408
+ colIndex = temp[temp.length - 1].length;
409
+ errorObject.index = str.substring(0, mIndex);
410
+ } else {
411
+ errorObject.error = "Unclosed tag `>`";
412
+ }
413
+ return errorObject;
414
+ } catch (e) {
415
+ console.log("Error in parsing")
416
+ }
417
+ }
418
+
419
+ function parseStartTag(tag, tagName, rest, unary) {
420
+ if (tagName) {
421
+ fancyComponent && (tagName = dasherize(tagName, fancyComponent));
422
+ let lowerTagName = tagName.toLowerCase();
423
+ if (lowerTagName == "svg") {
424
+ seenSVGBefore++;
425
+ }
426
+ // if (lowerTagName == "pre") {
427
+ // seenPreBefore = true;
428
+ // }
429
+ if (lowerTagName == "table") {
430
+ seenTableBefore += 1;
431
+ }
432
+ if (svgMiddleMen[lowerTagName]) {
433
+ seenSvgMiddleMenBefore++;
434
+ }
435
+ if (seenSVGBefore == 0 && tagName.toLowerCase) {
436
+ tagName = lowerTagName;
437
+ }
438
+ }
439
+ // @Handle3055 to get precise line and column number
440
+ // if(tagName && !seenPreBefore){
441
+ // tagName = tagName.replace(/\r?\n|\r/g,' ').replace(/\s+/g,' ');
442
+ // if (tag) {
443
+ // tag = tag.replace(/\r?\n|\r/g, ' ').replace(/\s+/g, ' ');
444
+ // }
445
+ // }
446
+ if (unary && !seenSVGBefore && svgSelfClosingTags[tagName]) {
447
+ let err = new Error("Error: Invalid svg tag " + tag + ".....");
448
+ err.fromParser = true;
449
+ throw err;
450
+ }
451
+ if (stack.getLastItem() == tagName && SELF_CLOSING[tagName]) {
452
+ parseEndTag("", tagName);
453
+ }
454
+ let matchRes;
455
+ if (tag && (matchRes = tag.match(/(?!({{)|"|'.*)\n(?!.*(}})|"|')/g))) {
456
+ lineIndex = lineIndex + matchRes.length;
457
+ colIndex = matchRes[matchRes.length - 1].length;
458
+ }
459
+ let col = colIndex;
460
+ if (tag) {
461
+ colIndex = colIndex + tag.length;
462
+ }
463
+
464
+ unary = EMPTY_ELEMENTS[tagName] || !!unary;
465
+ if (!unary) {
466
+ stack.push(tagName);
467
+ if (tagName != "p") {
468
+ elemStack.push(tagName);
469
+ }
470
+ }
471
+ let attrs = [];
472
+ let matchES = rest.match(/\s*$/),eS = "";//end of node space
473
+ if(matchES){
474
+ eS = matchES[0];
475
+ }
476
+ rest.replace(regexFor.attr, function (match, name) {
477
+ const arg2 = arguments[2];
478
+ const arg3 = arguments[3];
479
+ const arg4 = arguments[4];
480
+ const value = arg2 ? arg2 : (arg3 ? arg3 : (arg4 ? arg4 : ''));
481
+ let quote = name.indexOf("'"),
482
+ err,
483
+ nullCheck = (arg2 == undefined) && (arg3 == undefined) && (arg4 == undefined),
484
+ indexOfValue = tag.indexOf(value),
485
+ attrStartIndex = col+indexOfValue;
486
+ for (let index=indexOfValue; index>=0;index--){
487
+ if(tag[index] == "\n"){
488
+ attrStartIndex = indexOfValue-index;
489
+ break;
490
+ }
491
+ }
492
+ if (quote !== -1) {
493
+ err = new Error("Error: Unclosed Single quote in " + tag + "....." + "</" + tagName + ">");
494
+ err.fromParser = true;
495
+ err.lineIndex = lineIndex;
496
+ err.colIndex = colIndex;
497
+ throw err;
498
+ }
499
+ quote = name.indexOf('"')
500
+ if (quote !== -1) {
501
+ err = new Error("Error: Unclosed Double quote in " + tag.substring(0, 100) + "....." /* + "....." + "</" + tagName+ ">"*/ );
502
+ err.fromParser = true;
503
+ err.lineIndex = lineIndex;
504
+ err.colIndex = colIndex;
505
+ throw err;
506
+ }
507
+ if (name.indexOf("{{") == 0) {
508
+ err = new Error("Error: Invalid Mustache : " + name + "...");
509
+ err.fromParser = true;
510
+ err.lineIndex = lineIndex;
511
+ err.colIndex = colIndex;
512
+ throw err;
513
+ }
514
+ fancyComponent && (name = dasherize(name,false,true));
515
+ if (seenSVGBefore > 0 && svgCamelCaseTags[name.toLowerCase()]) {
516
+ name = svgCamelCaseTags[name.toLowerCase()];
517
+ } else {
518
+ name = name.toLowerCase();
519
+ }
520
+ let indexOfEqual = match.indexOf("=");
521
+ let startChar;
522
+ if(indexOfEqual != -1){
523
+ let afterEqualTo = match.slice(indexOfEqual+1);
524
+ startChar = afterEqualTo.match(/\S/);
525
+ if(startChar){
526
+ startChar = startChar[0];
527
+ } else {
528
+ startChar = "";
529
+ }
530
+ }
531
+ let obj = {
532
+ name: name,
533
+ value: value,//.replace(/"/g, "&quot;"),
534
+ escaped: value.replace(/(^|[^\\])"/g, '$1\\\"'),
535
+ attrStartIndex,
536
+ startChar,
537
+ nullCheck
538
+ }
539
+ if(options.withoutTemplateConversion){
540
+ let before = rest.split(match);
541
+ if(indexOfEqual != -1){
542
+ let beforeEqualTo = match.slice(0, indexOfEqual);
543
+ let afterEqualTo = match.slice(indexOfEqual+1);
544
+ obj.sBE = countTrailingSpaces(beforeEqualTo);
545
+ obj.sAE = countStartingSpaces(afterEqualTo);
546
+ }
547
+ if(before.length){
548
+ obj.sB = before[0].match(/\s*$/)[0]; //space before
549
+ }
550
+ }
551
+ if (name == "lyte-if" || (name == "is" && value == "if") || name == "lyte-switch" || (name == "is" && value == "switch") || name == "lyte-for" || (name == "is" && value == "for") || name == "lyte-for-in" || (name == "is" && value == "forIn")) {
552
+ obj.errorInfo = {
553
+ name: "errorInfo",
554
+ details: {
555
+ tagName: tagName,
556
+ name: name,
557
+ value: value.replace(/"/g, "&quot;")
558
+ }
559
+ }
560
+ }
561
+ attrs.push(obj);
562
+ });
563
+ if (callbacks.start) {
564
+ if (tag && tag.match(/<.*\/>/g)) {
565
+ if (!(selfClosingTags[tagName] || svgSelfClosingTags[tagName] || excludeSelfClosingTag[tagName])) {
566
+ let err = new Error("Invalid self-closing tag `" + tagName + "` in " + (tag + htmlString).substring(0, 100) + "...");
567
+ err.fromParser = true;
568
+ err.lineIndex = lineIndex;
569
+ err.colIndex = colIndex;
570
+ throw err;
571
+ }
572
+ } else {
573
+ if (!selfClosingTags[tagName]) {
574
+ nodeStartStack.push(tagName);
575
+ }
576
+ }
577
+ if (checkClosingTag) {
578
+ attrs.push({
579
+ name: "checkClosingTag",
580
+ value: "true",
581
+ escaped: "true"
582
+ });
583
+ }
584
+ callbacks.start(tagName, attrs, unary, seenSVGBefore, lineIndex, col, eS);
585
+ }
586
+ }
587
+
588
+ function parseEndTag(tag, tagName) {
589
+ if (tagName) {
590
+ fancyComponent && (tagName = dasherize(tagName, fancyComponent));
591
+ let lowerTagName = tagName.toLowerCase();
592
+ if (lowerTagName == "svg") {
593
+ seenSVGBefore--;
594
+ }
595
+ if (svgMiddleMen[lowerTagName]) {
596
+ seenSvgMiddleMenBefore--;
597
+ }
598
+ if (lowerTagName == "table") {
599
+ seenTableBefore--;
600
+ }
601
+ // if (lowerTagName == "pre") {
602
+ // seenPreBefore = false;
603
+ // }
604
+ if (seenSVGBefore == 0 && tagName.toLowerCase) {
605
+ tagName = lowerTagName;
606
+ }
607
+ if (tagName != "p" && !EMPTY_ELEMENTS[tagName]) {
608
+ let lastElem = elemStack.pop();
609
+ if (lastElem.toLowerCase() != tagName.toLowerCase()) {
610
+ if (tagName != "template") {
611
+ let i = elemStack.length - 1;
612
+ for (; i >= 0; i--) {
613
+ if (elemStack[i] == tagName) {
614
+ break;
615
+ }
616
+ }
617
+ let removeIndex = i;
618
+ for (; i > 0; i--) {
619
+ if (elemStack[i] == "template") {
620
+ elemStack.splice(removeIndex, 1);
621
+ break;
622
+ }
623
+ }
624
+ elemStack.push(lastElem);
625
+ return;
626
+ }
627
+ }
628
+ }
629
+ }
630
+ if (tag) {
631
+ colIndex += tag.length;
632
+ }
633
+ let pos;
634
+ if (!tagName) {
635
+ pos = 0;
636
+ } else {
637
+ for (pos = stack.length - 1; pos >= 0; pos--) {
638
+ if (stack[pos] == tagName) {
639
+ break;
640
+ }
641
+ }
642
+ }
643
+ if (pos >= 0) {
644
+ for (let i = stack.length - 1; i >= pos; i--) {
645
+ if (callbacks.end) {
646
+ callbacks.end(stack[i], stack[i] != tagName, this && this.misMatchCase ? this.misMatchCase : null, ((seenSvgMiddleMenBefore > 0) ? 0 : seenSVGBefore));
647
+ }
648
+ }
649
+ stack.length = pos;
650
+ }
651
+ else if (tagName == "br") {
652
+ parseStartTag(null, tagName, "", null);
653
+ }
654
+ }
655
+ const replacerFn = function (all, text) {
656
+ let matchRes;
657
+ if (text && (matchRes = text.match(/(?!({{)|"|'.*)\n(?!.*(}})|"|')/g))) {
658
+ lineIndex += matchRes.length;
659
+ colIndex = matchRes[matchRes.length - 1].length;
660
+ }
661
+ text = text.replace(/<!--([\s\S]*?)-->|<!\[CDATA\[([\s\S]*?)]]>/g, "$1$2");
662
+ let col = colIndex;
663
+ colIndex += text.length;
664
+
665
+ if (callbacks.chars) {
666
+ callbacks.chars(text, lineIndex, col, checkClosingTag);
667
+ }
668
+ return "";
669
+ }
670
+ if (emberFlag && htmlString.indexOf("{{!--")) {
671
+ htmlString = htmlString.replace(/{{!--[\s\S]*?--}}/g, "");
672
+ }
673
+ while (htmlString) {
674
+ hasUnparsedChars = true;
675
+ if (!stack.getLastItem() || !SPECIAL_ELEMENTS[stack.getLastItem()]) {
676
+ let checkStr = htmlString.substring(0, 5);
677
+ if (checkStr.indexOf("<!--")== 0) {
678
+ let index = htmlString.indexOf("-->");
679
+ if (index >= 0) {
680
+ if (callbacks.comment) {
681
+ let col = colIndex;
682
+ colIndex += htmlString.substring(4, index).length + 7;
683
+ callbacks.comment(htmlString.substring(4, index), lineIndex, col);
684
+ let matchRes = htmlString.substring(4, index).match(/\n/g)
685
+ if (matchRes) {
686
+ lineIndex = lineIndex + matchRes.length;
687
+ colIndex = matchRes[matchRes.length - 1].length;
688
+ }
689
+ }
690
+ htmlString = htmlString.substring(index + 3);
691
+ hasUnparsedChars = false;
692
+ }
693
+ }else if(checkStr.indexOf("<?xml") == 0){
694
+ let index = htmlString.indexOf("?>");
695
+ if(index>=0){
696
+ if(callbacks.comment){
697
+ let col = colIndex,matchedString,match;
698
+ colIndex += htmlString.substring(5, index).length + 7;
699
+ callbacks.comment("___PI:XMLStarts___"+(matchedString = htmlString.substring(5,index))+"___PI:XMLEnds___",lineIndex,col,true);//PI ~ Parser Internals
700
+ if(match = matchedString.match(/\n/g)){
701
+ lineIndex = lineIndex + match.length;
702
+ colIndex = 0;
703
+ }
704
+ htmlString = htmlString.substring(index + 2);
705
+ hasUnparsedChars = false;
706
+ }
707
+ }
708
+ } else if (checkStr.indexOf("</") == 0) {
709
+ match = htmlString.match(regexFor.endTag);
710
+ if (match) {
711
+ let misMatchCase = false;
712
+ if (match[1] == "p") {
713
+ paragraphTagStarted = 0;
714
+ }
715
+ if (paragraphTagStarted == 2 && match[1] == "template") {
716
+ paragraphTagStarted = 1;
717
+ }
718
+ if (match[1] == "p" && stack.getLastItem() != "p" && willHaveUnclosedClosingTag) {
719
+ parseStartTag(null, "p", "", null);
720
+ }
721
+ if (match[1] == "checkClosingTag") {
722
+ checkClosingTag = false;
723
+ htmlString = htmlString.substring(match[0].length);
724
+ continue;
725
+ }
726
+ let check = fancyComponent ? dasherize(match[1], fancyComponent) : match[1];
727
+ if (seenSVGBefore == 0 && check && check.toLowerCase) {
728
+ check = check.toLowerCase();
729
+ }
730
+ if (check != stack.getLastItem() && !EMPTY_ELEMENTS[check]) {
731
+ let err = new Error("Unclosed `" + elemStack.getLastItem() + "` in " + htmlString.substring(0, 100) + "...");
732
+ err.fromParser = true;
733
+ err.lineIndex = lineIndex;
734
+ err.colIndex = colIndex;
735
+ throw err;
736
+ }
737
+ if (match[1] == "template" && elemStack.getLastItem() != "template" && match[1] != "p" && !EMPTY_ELEMENTS[match[1]]) {
738
+ let match2 = htmlString.match(`<\/\s*` + elemStack.getLastItem() + `\s*>`);
739
+ if (match2) {
740
+ htmlString = htmlString.replace(match2[0], "</checkClosingTag>");
741
+ checkClosingTag = true;
742
+ htmlString = htmlString.replace(match[0], match2[0]);
743
+ htmlString = htmlString.substring(0, match2[0].length) + match[0] + htmlString.substring(match2[0].length);
744
+ match = htmlString.match(regexFor.endTag);
745
+ stringInPrevLoopState = undefined;
746
+ misMatchCase = true;
747
+ }
748
+ }
749
+ htmlString = htmlString.substring(match[0].length);
750
+
751
+ match[0].replace(regexFor.endTag, parseEndTag.bind({
752
+ misMatchCase: misMatchCase
753
+ }));
754
+ hasUnparsedChars = false;
755
+ }
756
+ } else if (checkStr.indexOf("<") == 0) {
757
+ match = getStartTag(htmlString.slice(1));
758
+ if (match.bool) {
759
+ if (paragraphTagStarted == 1 && match[1] != "p" && notAllowedTagsInsideParagraphTag[match[1]]) {
760
+ paragraphTagStarted = 0;
761
+ parseEndTag(null, "p");
762
+ willHaveUnclosedClosingTag = true;
763
+ }
764
+ htmlString = htmlString.substring(match[0].length);
765
+ if (match[1] == "template") {
766
+ while (htmlString.match(/^[^<]*?<\/br\s*>/)) {
767
+ htmlString = htmlString.replace(/<\/br\s*>/, "");
768
+ }
769
+ }
770
+ if (!withoutTableProcessing) {
771
+ if (stack.getLastItem() != "template" && seenTableBefore == 0 && tableTags[match[1]]) {
772
+ if (errorObj) {
773
+ errorObj.warnings.push({
774
+ message: "Warning: Misplaced " + match[1] + " tag in " + match[0] + "....." + "</" + match[1] + ">" + ((fileName && fileName.trim().length != 0) ? "\n\t at Component: " + fileName : "")
775
+ });
776
+ } else {
777
+ console.warn("Warning: Misplaced " + match[1] + " tag in " + match[0] + "....." + "</" + match[1] + ">" + ((fileName && fileName.trim().length != 0) ? "\n\t at Component: " + fileName : ""));
778
+ }
779
+ }
780
+ }
781
+ parseStartTag(match[0], match[1], match[2], match[3]);
782
+ hasUnparsedChars = false;
783
+ if (match[1] == "p") {
784
+ paragraphTagStarted = 1;
785
+ }
786
+ if (paragraphTagStarted == 1 && match[1] == "template") {
787
+ paragraphTagStarted = 2;
788
+ }
789
+ } else {
790
+ let err = new Error(match.error + ((match.index) ? " in <" + match.index.substring(0, (match.index.indexOf(">") != -1) ? match.index.indexOf(">") + 1 : 51) + "....." : ""));
791
+ err.fromParser = true;
792
+ err.lineIndex = lineIndex;
793
+ err.colIndex = colIndex;
794
+ throw err;
795
+ }
796
+ }
797
+ if (hasUnparsedChars) {
798
+ let hasSeenOpenMustache = false,
799
+ newLineCount = 0,
800
+ index,
801
+ mustacheIndex = {};
802
+ for (let i = 0; i < htmlString.length; i++) {
803
+ if (htmlString[i] == "\n") {
804
+ newLineCount++;
805
+ }
806
+ if (htmlString[i] == '{' && htmlString[i + 1] == '{') {
807
+ hasSeenOpenMustache = true;
808
+ mustacheIndex = {
809
+ colIndex: i - newLineCount,
810
+ lineIndex: lineIndex + newLineCount
811
+ };
812
+ }
813
+ if (htmlString[i] == '}' && htmlString[i + 1] == '}') {
814
+ hasSeenOpenMustache = false;
815
+ }
816
+ if (htmlString[i] == '<' && !hasSeenOpenMustache) {
817
+ index = i;
818
+ break;
819
+ }
820
+ }
821
+ if (hasSeenOpenMustache) {
822
+ let err = new Error("Unclosed Mustache at " + htmlString.substring(mustacheIndex.colIndex, mustacheIndex.colIndex + 50));
823
+ err.fromParser = true;
824
+ err.lineIndex = mustacheIndex.lineIndex;
825
+ err.colIndex = (mustacheIndex.lineIndex == lineIndex) ? /* <h1>check{{{}</h1> */ colIndex + mustacheIndex.colIndex : /* <h1>che\nck{{{}</h1> */ mustacheIndex.colIndex;
826
+ throw err;
827
+ }
828
+ if (!index) {
829
+ mismatchColIndex = {
830
+ colIndex,
831
+ lineIndex
832
+ };
833
+ index = htmlString.length;
834
+ newLineCount = 0;
835
+ }
836
+ let text = index < 0 ? htmlString : htmlString.substring(0, index);
837
+ htmlString = index < 0 ? "" : htmlString.substring(index);
838
+ if (callbacks.chars) {
839
+ // @Handle3055 to get precise line and column number
840
+ // if(!seenPreBefore && text){
841
+ // text = text.replace(/\r?\n|\r/g,' ').replace(/\s+/g,' ');
842
+ // }
843
+ callbacks.chars(text, lineIndex, colIndex, checkClosingTag);
844
+ colIndex = colIndex + text.length;
845
+ if (newLineCount) {
846
+ lineIndex += newLineCount;
847
+ colIndex = 0;
848
+ }
849
+ }
850
+ }
851
+ } else {
852
+ htmlString = htmlString.replace(new RegExp("([\\s\\S]*?)<\/" + stack.getLastItem() + "[^>]*>"), replacerFn);
853
+ parseEndTag("", stack.getLastItem());
854
+ }
855
+ if (htmlString == stringInPrevLoopState) {
856
+ throw "Parse Error: " + htmlString.substring(0, 100) + "...";
857
+ }
858
+ stringInPrevLoopState = htmlString;
859
+ }
860
+ if (stack.length > 0) {
861
+ let err = new Error("Unclosed `" + elemStack.getLastItem() + "` in " + htmlString.substring(0, 100) + "..." + ((fileName && fileName.trim().length != 0) ? "\n\t at Component: " + fileName : ""));
862
+ err.lineIndex = mismatchColIndex.lineIndex || lineIndex;
863
+ err.colIndex = mismatchColIndex.colIndex || colIndex;
864
+ throw err;
865
+ }
866
+ parseEndTag();
867
+ }
868
+ }());
869
+ export default HTMLParser;
870
+ //ignorei18n_end