@forsakringskassan/docs-live-example 1.4.3 → 1.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +134 -94
- package/dist/esm/index.js +134 -94
- package/dist/index.d.ts +1 -0
- package/package.json +3 -2
package/dist/cjs/index.js
CHANGED
|
@@ -58,8 +58,7 @@ var require_core = __commonJS({
|
|
|
58
58
|
* @param {CompiledMode} mode
|
|
59
59
|
*/
|
|
60
60
|
constructor(mode) {
|
|
61
|
-
if (mode.data === void 0)
|
|
62
|
-
mode.data = {};
|
|
61
|
+
if (mode.data === void 0) mode.data = {};
|
|
63
62
|
this.data = mode.data;
|
|
64
63
|
this.isMatchIgnored = false;
|
|
65
64
|
}
|
|
@@ -126,8 +125,7 @@ var require_core = __commonJS({
|
|
|
126
125
|
*
|
|
127
126
|
* @param {Node} node */
|
|
128
127
|
openNode(node) {
|
|
129
|
-
if (!emitsWrappingTags(node))
|
|
130
|
-
return;
|
|
128
|
+
if (!emitsWrappingTags(node)) return;
|
|
131
129
|
const className = scopeToCSSClass(
|
|
132
130
|
node.scope,
|
|
133
131
|
{ prefix: this.classPrefix }
|
|
@@ -139,8 +137,7 @@ var require_core = __commonJS({
|
|
|
139
137
|
*
|
|
140
138
|
* @param {Node} node */
|
|
141
139
|
closeNode(node) {
|
|
142
|
-
if (!emitsWrappingTags(node))
|
|
143
|
-
return;
|
|
140
|
+
if (!emitsWrappingTags(node)) return;
|
|
144
141
|
this.buffer += SPAN_CLOSE;
|
|
145
142
|
}
|
|
146
143
|
/**
|
|
@@ -191,8 +188,7 @@ var require_core = __commonJS({
|
|
|
191
188
|
return void 0;
|
|
192
189
|
}
|
|
193
190
|
closeAllNodes() {
|
|
194
|
-
while (this.closeNode())
|
|
195
|
-
;
|
|
191
|
+
while (this.closeNode()) ;
|
|
196
192
|
}
|
|
197
193
|
toJSON() {
|
|
198
194
|
return JSON.stringify(this.rootNode, null, 4);
|
|
@@ -222,10 +218,8 @@ var require_core = __commonJS({
|
|
|
222
218
|
* @param {Node} node
|
|
223
219
|
*/
|
|
224
220
|
static _collapse(node) {
|
|
225
|
-
if (typeof node === "string")
|
|
226
|
-
|
|
227
|
-
if (!node.children)
|
|
228
|
-
return;
|
|
221
|
+
if (typeof node === "string") return;
|
|
222
|
+
if (!node.children) return;
|
|
229
223
|
if (node.children.every((el) => typeof el === "string")) {
|
|
230
224
|
node.children = [node.children.join("")];
|
|
231
225
|
} else {
|
|
@@ -265,8 +259,7 @@ var require_core = __commonJS({
|
|
|
265
259
|
*/
|
|
266
260
|
__addSublanguage(emitter, name) {
|
|
267
261
|
const node = emitter.root;
|
|
268
|
-
if (name)
|
|
269
|
-
node.scope = `language:${name}`;
|
|
262
|
+
if (name) node.scope = `language:${name}`;
|
|
270
263
|
this.add(node);
|
|
271
264
|
}
|
|
272
265
|
toHTML() {
|
|
@@ -279,10 +272,8 @@ var require_core = __commonJS({
|
|
|
279
272
|
}
|
|
280
273
|
};
|
|
281
274
|
function source(re) {
|
|
282
|
-
if (!re)
|
|
283
|
-
|
|
284
|
-
if (typeof re === "string")
|
|
285
|
-
return re;
|
|
275
|
+
if (!re) return null;
|
|
276
|
+
if (typeof re === "string") return re;
|
|
286
277
|
return re.source;
|
|
287
278
|
}
|
|
288
279
|
function lookahead(re) {
|
|
@@ -371,8 +362,7 @@ var require_core = __commonJS({
|
|
|
371
362
|
relevance: 0,
|
|
372
363
|
/** @type {ModeCallback} */
|
|
373
364
|
"on:begin": (m, resp) => {
|
|
374
|
-
if (m.index !== 0)
|
|
375
|
-
resp.ignoreMatch();
|
|
365
|
+
if (m.index !== 0) resp.ignoreMatch();
|
|
376
366
|
}
|
|
377
367
|
}, opts);
|
|
378
368
|
};
|
|
@@ -522,8 +512,7 @@ var require_core = __commonJS({
|
|
|
522
512
|
},
|
|
523
513
|
/** @type {ModeCallback} */
|
|
524
514
|
"on:end": (m, resp) => {
|
|
525
|
-
if (resp.data._beginMatch !== m[1])
|
|
526
|
-
resp.ignoreMatch();
|
|
515
|
+
if (resp.data._beginMatch !== m[1]) resp.ignoreMatch();
|
|
527
516
|
}
|
|
528
517
|
}
|
|
529
518
|
);
|
|
@@ -568,39 +557,30 @@ var require_core = __commonJS({
|
|
|
568
557
|
}
|
|
569
558
|
}
|
|
570
559
|
function beginKeywords(mode, parent) {
|
|
571
|
-
if (!parent)
|
|
572
|
-
|
|
573
|
-
if (!mode.beginKeywords)
|
|
574
|
-
return;
|
|
560
|
+
if (!parent) return;
|
|
561
|
+
if (!mode.beginKeywords) return;
|
|
575
562
|
mode.begin = "\\b(" + mode.beginKeywords.split(" ").join("|") + ")(?!\\.)(?=\\b|\\s)";
|
|
576
563
|
mode.__beforeBegin = skipIfHasPrecedingDot;
|
|
577
564
|
mode.keywords = mode.keywords || mode.beginKeywords;
|
|
578
565
|
delete mode.beginKeywords;
|
|
579
|
-
if (mode.relevance === void 0)
|
|
580
|
-
mode.relevance = 0;
|
|
566
|
+
if (mode.relevance === void 0) mode.relevance = 0;
|
|
581
567
|
}
|
|
582
568
|
function compileIllegal(mode, _parent) {
|
|
583
|
-
if (!Array.isArray(mode.illegal))
|
|
584
|
-
return;
|
|
569
|
+
if (!Array.isArray(mode.illegal)) return;
|
|
585
570
|
mode.illegal = either(...mode.illegal);
|
|
586
571
|
}
|
|
587
572
|
function compileMatch(mode, _parent) {
|
|
588
|
-
if (!mode.match)
|
|
589
|
-
|
|
590
|
-
if (mode.begin || mode.end)
|
|
591
|
-
throw new Error("begin & end are not supported with match");
|
|
573
|
+
if (!mode.match) return;
|
|
574
|
+
if (mode.begin || mode.end) throw new Error("begin & end are not supported with match");
|
|
592
575
|
mode.begin = mode.match;
|
|
593
576
|
delete mode.match;
|
|
594
577
|
}
|
|
595
578
|
function compileRelevance(mode, _parent) {
|
|
596
|
-
if (mode.relevance === void 0)
|
|
597
|
-
mode.relevance = 1;
|
|
579
|
+
if (mode.relevance === void 0) mode.relevance = 1;
|
|
598
580
|
}
|
|
599
581
|
var beforeMatchExt = (mode, parent) => {
|
|
600
|
-
if (!mode.beforeMatch)
|
|
601
|
-
|
|
602
|
-
if (mode.starts)
|
|
603
|
-
throw new Error("beforeMatch cannot be used with starts");
|
|
582
|
+
if (!mode.beforeMatch) return;
|
|
583
|
+
if (mode.starts) throw new Error("beforeMatch cannot be used with starts");
|
|
604
584
|
const originalMode = Object.assign({}, mode);
|
|
605
585
|
Object.keys(mode).forEach((key) => {
|
|
606
586
|
delete mode[key];
|
|
@@ -675,8 +655,7 @@ var require_core = __commonJS({
|
|
|
675
655
|
console.log(`WARN: ${message}`, ...args);
|
|
676
656
|
};
|
|
677
657
|
var deprecated = (version2, message) => {
|
|
678
|
-
if (seenDeprecations[`${version2}/${message}`])
|
|
679
|
-
return;
|
|
658
|
+
if (seenDeprecations[`${version2}/${message}`]) return;
|
|
680
659
|
console.log(`Deprecated as of ${version2}. ${message}`);
|
|
681
660
|
seenDeprecations[`${version2}/${message}`] = true;
|
|
682
661
|
};
|
|
@@ -696,8 +675,7 @@ var require_core = __commonJS({
|
|
|
696
675
|
mode[key]._multi = true;
|
|
697
676
|
}
|
|
698
677
|
function beginMultiClass(mode) {
|
|
699
|
-
if (!Array.isArray(mode.begin))
|
|
700
|
-
return;
|
|
678
|
+
if (!Array.isArray(mode.begin)) return;
|
|
701
679
|
if (mode.skip || mode.excludeBegin || mode.returnBegin) {
|
|
702
680
|
error("skip, excludeBegin, returnBegin not compatible with beginScope: {}");
|
|
703
681
|
throw MultiClassError;
|
|
@@ -710,8 +688,7 @@ var require_core = __commonJS({
|
|
|
710
688
|
mode.begin = _rewriteBackreferences(mode.begin, { joinWith: "" });
|
|
711
689
|
}
|
|
712
690
|
function endMultiClass(mode) {
|
|
713
|
-
if (!Array.isArray(mode.end))
|
|
714
|
-
return;
|
|
691
|
+
if (!Array.isArray(mode.end)) return;
|
|
715
692
|
if (mode.skip || mode.excludeEnd || mode.returnEnd) {
|
|
716
693
|
error("skip, excludeEnd, returnEnd not compatible with endScope: {}");
|
|
717
694
|
throw MultiClassError;
|
|
@@ -792,8 +769,7 @@ var require_core = __commonJS({
|
|
|
792
769
|
}
|
|
793
770
|
// @ts-ignore
|
|
794
771
|
getMatcher(index) {
|
|
795
|
-
if (this.multiRegexes[index])
|
|
796
|
-
return this.multiRegexes[index];
|
|
772
|
+
if (this.multiRegexes[index]) return this.multiRegexes[index];
|
|
797
773
|
const matcher = new MultiRegex();
|
|
798
774
|
this.rules.slice(index).forEach(([re, opts]) => matcher.addRule(re, opts));
|
|
799
775
|
matcher.compile();
|
|
@@ -809,8 +785,7 @@ var require_core = __commonJS({
|
|
|
809
785
|
// @ts-ignore
|
|
810
786
|
addRule(re, opts) {
|
|
811
787
|
this.rules.push([re, opts]);
|
|
812
|
-
if (opts.type === "begin")
|
|
813
|
-
this.count++;
|
|
788
|
+
if (opts.type === "begin") this.count++;
|
|
814
789
|
}
|
|
815
790
|
/** @param {string} s */
|
|
816
791
|
exec(s) {
|
|
@@ -818,8 +793,7 @@ var require_core = __commonJS({
|
|
|
818
793
|
m.lastIndex = this.lastIndex;
|
|
819
794
|
let result = m.exec(s);
|
|
820
795
|
if (this.resumingScanAtSamePosition()) {
|
|
821
|
-
if (result && result.index === this.lastIndex)
|
|
822
|
-
;
|
|
796
|
+
if (result && result.index === this.lastIndex) ;
|
|
823
797
|
else {
|
|
824
798
|
const m2 = this.getMatcher(0);
|
|
825
799
|
m2.lastIndex = this.lastIndex + 1;
|
|
@@ -851,8 +825,7 @@ var require_core = __commonJS({
|
|
|
851
825
|
/** @type CompiledMode */
|
|
852
826
|
mode
|
|
853
827
|
);
|
|
854
|
-
if (mode.isCompiled)
|
|
855
|
-
return cmode;
|
|
828
|
+
if (mode.isCompiled) return cmode;
|
|
856
829
|
[
|
|
857
830
|
scopeClassName,
|
|
858
831
|
// do this early so compiler extensions generally don't have to worry about
|
|
@@ -884,25 +857,20 @@ var require_core = __commonJS({
|
|
|
884
857
|
}
|
|
885
858
|
cmode.keywordPatternRe = langRe(keywordPattern, true);
|
|
886
859
|
if (parent) {
|
|
887
|
-
if (!mode.begin)
|
|
888
|
-
mode.begin = /\B|\b/;
|
|
860
|
+
if (!mode.begin) mode.begin = /\B|\b/;
|
|
889
861
|
cmode.beginRe = langRe(cmode.begin);
|
|
890
|
-
if (!mode.end && !mode.endsWithParent)
|
|
891
|
-
|
|
892
|
-
if (mode.end)
|
|
893
|
-
cmode.endRe = langRe(cmode.end);
|
|
862
|
+
if (!mode.end && !mode.endsWithParent) mode.end = /\B|\b/;
|
|
863
|
+
if (mode.end) cmode.endRe = langRe(cmode.end);
|
|
894
864
|
cmode.terminatorEnd = source(cmode.end) || "";
|
|
895
865
|
if (mode.endsWithParent && parent.terminatorEnd) {
|
|
896
866
|
cmode.terminatorEnd += (mode.end ? "|" : "") + parent.terminatorEnd;
|
|
897
867
|
}
|
|
898
868
|
}
|
|
899
|
-
if (mode.illegal)
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
if (!mode.contains)
|
|
905
|
-
mode.contains = [];
|
|
869
|
+
if (mode.illegal) cmode.illegalRe = langRe(
|
|
870
|
+
/** @type {RegExp | string} */
|
|
871
|
+
mode.illegal
|
|
872
|
+
);
|
|
873
|
+
if (!mode.contains) mode.contains = [];
|
|
906
874
|
mode.contains = [].concat(...mode.contains.map(function(c) {
|
|
907
875
|
return expandOrCloneMode(c === "self" ? mode : c);
|
|
908
876
|
}));
|
|
@@ -919,8 +887,7 @@ var require_core = __commonJS({
|
|
|
919
887
|
cmode.matcher = buildModeRegex(cmode);
|
|
920
888
|
return cmode;
|
|
921
889
|
}
|
|
922
|
-
if (!language.compilerExtensions)
|
|
923
|
-
language.compilerExtensions = [];
|
|
890
|
+
if (!language.compilerExtensions) language.compilerExtensions = [];
|
|
924
891
|
if (language.contains && language.contains.includes("self")) {
|
|
925
892
|
throw new Error("ERR: contains `self` is not supported at the top-level of a language. See documentation.");
|
|
926
893
|
}
|
|
@@ -931,8 +898,7 @@ var require_core = __commonJS({
|
|
|
931
898
|
);
|
|
932
899
|
}
|
|
933
900
|
function dependencyOnParent(mode) {
|
|
934
|
-
if (!mode)
|
|
935
|
-
return false;
|
|
901
|
+
if (!mode) return false;
|
|
936
902
|
return mode.endsWithParent || dependencyOnParent(mode.starts);
|
|
937
903
|
}
|
|
938
904
|
function expandOrCloneMode(mode) {
|
|
@@ -1049,8 +1015,7 @@ var require_core = __commonJS({
|
|
|
1049
1015
|
emitter.addText(buf);
|
|
1050
1016
|
buf = "";
|
|
1051
1017
|
keywordHits[word] = (keywordHits[word] || 0) + 1;
|
|
1052
|
-
if (keywordHits[word] <= MAX_KEYWORD_HITS)
|
|
1053
|
-
relevance += keywordRelevance;
|
|
1018
|
+
if (keywordHits[word] <= MAX_KEYWORD_HITS) relevance += keywordRelevance;
|
|
1054
1019
|
if (kind.startsWith("_")) {
|
|
1055
1020
|
buf += match[0];
|
|
1056
1021
|
} else {
|
|
@@ -1067,8 +1032,7 @@ var require_core = __commonJS({
|
|
|
1067
1032
|
emitter.addText(buf);
|
|
1068
1033
|
}
|
|
1069
1034
|
function processSubLanguage() {
|
|
1070
|
-
if (modeBuffer === "")
|
|
1071
|
-
return;
|
|
1035
|
+
if (modeBuffer === "") return;
|
|
1072
1036
|
let result2 = null;
|
|
1073
1037
|
if (typeof top.subLanguage === "string") {
|
|
1074
1038
|
if (!languages[top.subLanguage]) {
|
|
@@ -1095,8 +1059,7 @@ var require_core = __commonJS({
|
|
|
1095
1059
|
modeBuffer = "";
|
|
1096
1060
|
}
|
|
1097
1061
|
function emitKeyword(keyword, scope) {
|
|
1098
|
-
if (keyword === "")
|
|
1099
|
-
return;
|
|
1062
|
+
if (keyword === "") return;
|
|
1100
1063
|
emitter.startScope(scope);
|
|
1101
1064
|
emitter.addText(keyword);
|
|
1102
1065
|
emitter.endScope();
|
|
@@ -1143,8 +1106,7 @@ var require_core = __commonJS({
|
|
|
1143
1106
|
if (mode["on:end"]) {
|
|
1144
1107
|
const resp = new Response(mode);
|
|
1145
1108
|
mode["on:end"](match, resp);
|
|
1146
|
-
if (resp.isMatchIgnored)
|
|
1147
|
-
matched = false;
|
|
1109
|
+
if (resp.isMatchIgnored) matched = false;
|
|
1148
1110
|
}
|
|
1149
1111
|
if (matched) {
|
|
1150
1112
|
while (mode.endsParent && mode.parent) {
|
|
@@ -1172,11 +1134,9 @@ var require_core = __commonJS({
|
|
|
1172
1134
|
const resp = new Response(newMode);
|
|
1173
1135
|
const beforeCallbacks = [newMode.__beforeBegin, newMode["on:begin"]];
|
|
1174
1136
|
for (const cb of beforeCallbacks) {
|
|
1175
|
-
if (!cb)
|
|
1176
|
-
continue;
|
|
1137
|
+
if (!cb) continue;
|
|
1177
1138
|
cb(match, resp);
|
|
1178
|
-
if (resp.isMatchIgnored)
|
|
1179
|
-
return doIgnore(lexeme);
|
|
1139
|
+
if (resp.isMatchIgnored) return doIgnore(lexeme);
|
|
1180
1140
|
}
|
|
1181
1141
|
if (newMode.skip) {
|
|
1182
1142
|
modeBuffer += lexeme;
|
|
@@ -1309,8 +1269,7 @@ var require_core = __commonJS({
|
|
|
1309
1269
|
}
|
|
1310
1270
|
top.matcher.lastIndex = index;
|
|
1311
1271
|
const match = top.matcher.exec(codeToHighlight);
|
|
1312
|
-
if (!match)
|
|
1313
|
-
break;
|
|
1272
|
+
if (!match) break;
|
|
1314
1273
|
const beforeMatch = codeToHighlight.substring(index, match.index);
|
|
1315
1274
|
const processedCount = processLexeme(beforeMatch, match);
|
|
1316
1275
|
index = match.index + processedCount;
|
|
@@ -1379,8 +1338,7 @@ var require_core = __commonJS({
|
|
|
1379
1338
|
);
|
|
1380
1339
|
results.unshift(plaintext);
|
|
1381
1340
|
const sorted = results.sort((a, b) => {
|
|
1382
|
-
if (a.relevance !== b.relevance)
|
|
1383
|
-
return b.relevance - a.relevance;
|
|
1341
|
+
if (a.relevance !== b.relevance) return b.relevance - a.relevance;
|
|
1384
1342
|
if (a.language && b.language) {
|
|
1385
1343
|
if (getLanguage(a.language).supersetOf === b.language) {
|
|
1386
1344
|
return 1;
|
|
@@ -1403,8 +1361,7 @@ var require_core = __commonJS({
|
|
|
1403
1361
|
function highlightElement(element) {
|
|
1404
1362
|
let node = null;
|
|
1405
1363
|
const language = blockLanguage(element);
|
|
1406
|
-
if (shouldNotHighlight(language))
|
|
1407
|
-
return;
|
|
1364
|
+
if (shouldNotHighlight(language)) return;
|
|
1408
1365
|
fire(
|
|
1409
1366
|
"before:highlightElement",
|
|
1410
1367
|
{ el: element, language }
|
|
@@ -1469,8 +1426,7 @@ var require_core = __commonJS({
|
|
|
1469
1426
|
blocks.forEach(highlightElement);
|
|
1470
1427
|
}
|
|
1471
1428
|
function boot() {
|
|
1472
|
-
if (wantsHighlight)
|
|
1473
|
-
highlightAll();
|
|
1429
|
+
if (wantsHighlight) highlightAll();
|
|
1474
1430
|
}
|
|
1475
1431
|
if (typeof window !== "undefined" && window.addEventListener) {
|
|
1476
1432
|
window.addEventListener("DOMContentLoaded", boot, false);
|
|
@@ -1488,8 +1444,7 @@ var require_core = __commonJS({
|
|
|
1488
1444
|
}
|
|
1489
1445
|
lang = PLAINTEXT_LANGUAGE;
|
|
1490
1446
|
}
|
|
1491
|
-
if (!lang.name)
|
|
1492
|
-
lang.name = languageName;
|
|
1447
|
+
if (!lang.name) lang.name = languageName;
|
|
1493
1448
|
languages[languageName] = lang;
|
|
1494
1449
|
lang.rawDefinition = languageDefinition.bind(null, hljs);
|
|
1495
1450
|
if (lang.aliases) {
|
|
@@ -1615,7 +1570,8 @@ var require_core = __commonJS({
|
|
|
1615
1570
|
// src/index.ts
|
|
1616
1571
|
var src_exports = {};
|
|
1617
1572
|
__export(src_exports, {
|
|
1618
|
-
LiveExample: () => LiveExample_default2
|
|
1573
|
+
LiveExample: () => LiveExample_default2,
|
|
1574
|
+
createElement: () => createElement
|
|
1619
1575
|
});
|
|
1620
1576
|
module.exports = __toCommonJS(src_exports);
|
|
1621
1577
|
|
|
@@ -2437,3 +2393,87 @@ function render2(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
2437
2393
|
LiveExample_default.render = render2;
|
|
2438
2394
|
LiveExample_default.__file = "src/LiveExample.vue";
|
|
2439
2395
|
var LiveExample_default2 = LiveExample_default;
|
|
2396
|
+
|
|
2397
|
+
// src/create-element.ts
|
|
2398
|
+
var voidElements = [
|
|
2399
|
+
"area",
|
|
2400
|
+
"base",
|
|
2401
|
+
"br",
|
|
2402
|
+
"col",
|
|
2403
|
+
"embed",
|
|
2404
|
+
"hr",
|
|
2405
|
+
"img",
|
|
2406
|
+
"input",
|
|
2407
|
+
"link",
|
|
2408
|
+
"meta",
|
|
2409
|
+
"param",
|
|
2410
|
+
"source",
|
|
2411
|
+
"track",
|
|
2412
|
+
"wbr"
|
|
2413
|
+
];
|
|
2414
|
+
function unpackArgs(args) {
|
|
2415
|
+
if (args.length === 0) {
|
|
2416
|
+
return { attributes: {}, children: [] };
|
|
2417
|
+
}
|
|
2418
|
+
if (args.length === 1) {
|
|
2419
|
+
const [arg02] = args;
|
|
2420
|
+
if (typeof arg02 === "string") {
|
|
2421
|
+
return { attributes: {}, children: [arg02] };
|
|
2422
|
+
} else if (Array.isArray(arg02)) {
|
|
2423
|
+
return { attributes: {}, children: arg02 };
|
|
2424
|
+
} else {
|
|
2425
|
+
return { attributes: arg02, children: [] };
|
|
2426
|
+
}
|
|
2427
|
+
}
|
|
2428
|
+
const [arg0, arg1] = args;
|
|
2429
|
+
return { attributes: arg0, children: Array.isArray(arg1) ? arg1 : [arg1] };
|
|
2430
|
+
}
|
|
2431
|
+
function serializeChildren(children) {
|
|
2432
|
+
if (children.length > 0) {
|
|
2433
|
+
return ` ${children.join(" ")} `;
|
|
2434
|
+
} else {
|
|
2435
|
+
return "";
|
|
2436
|
+
}
|
|
2437
|
+
}
|
|
2438
|
+
function serializeAttribute(key, value, prefix = "") {
|
|
2439
|
+
if (Array.isArray(value)) {
|
|
2440
|
+
const tokens = value.map((it) => it ? String(it) : null).filter(Boolean);
|
|
2441
|
+
if (tokens.length > 0) {
|
|
2442
|
+
return `${prefix}${key}="${tokens.join(" ")}"`;
|
|
2443
|
+
} else {
|
|
2444
|
+
return [];
|
|
2445
|
+
}
|
|
2446
|
+
}
|
|
2447
|
+
if (value === null || value === void 0) {
|
|
2448
|
+
return [];
|
|
2449
|
+
}
|
|
2450
|
+
if (typeof value === "string" || typeof value === "number") {
|
|
2451
|
+
return `${prefix}${key}="${value}"`;
|
|
2452
|
+
}
|
|
2453
|
+
if (typeof value === "boolean") {
|
|
2454
|
+
return value ? `${prefix}${key}` : [];
|
|
2455
|
+
}
|
|
2456
|
+
return Object.entries(value).map(([nestedKey, value2]) => {
|
|
2457
|
+
return serializeAttribute(nestedKey, value2, `${prefix}${key}-`);
|
|
2458
|
+
}).flat().filter(Boolean);
|
|
2459
|
+
}
|
|
2460
|
+
function serializeAttributes(attrs) {
|
|
2461
|
+
const entries = Object.entries(attrs);
|
|
2462
|
+
const kv = entries.map(([key, value]) => serializeAttribute(key, value));
|
|
2463
|
+
const flat = kv.flat();
|
|
2464
|
+
if (flat.length > 0) {
|
|
2465
|
+
return ` ${kv.flat().join(" ")}`;
|
|
2466
|
+
} else {
|
|
2467
|
+
return "";
|
|
2468
|
+
}
|
|
2469
|
+
}
|
|
2470
|
+
function createElement(tagName, ...args) {
|
|
2471
|
+
const { attributes, children } = unpackArgs(args);
|
|
2472
|
+
const attrs = serializeAttributes(attributes);
|
|
2473
|
+
if (voidElements.includes(tagName)) {
|
|
2474
|
+
return `<${tagName}${attrs}>`;
|
|
2475
|
+
} else {
|
|
2476
|
+
const content = serializeChildren(children);
|
|
2477
|
+
return `<${tagName}${attrs}>${content}</${tagName}>`;
|
|
2478
|
+
}
|
|
2479
|
+
}
|
package/dist/esm/index.js
CHANGED
|
@@ -52,8 +52,7 @@ var require_core = __commonJS({
|
|
|
52
52
|
* @param {CompiledMode} mode
|
|
53
53
|
*/
|
|
54
54
|
constructor(mode) {
|
|
55
|
-
if (mode.data === void 0)
|
|
56
|
-
mode.data = {};
|
|
55
|
+
if (mode.data === void 0) mode.data = {};
|
|
57
56
|
this.data = mode.data;
|
|
58
57
|
this.isMatchIgnored = false;
|
|
59
58
|
}
|
|
@@ -120,8 +119,7 @@ var require_core = __commonJS({
|
|
|
120
119
|
*
|
|
121
120
|
* @param {Node} node */
|
|
122
121
|
openNode(node) {
|
|
123
|
-
if (!emitsWrappingTags(node))
|
|
124
|
-
return;
|
|
122
|
+
if (!emitsWrappingTags(node)) return;
|
|
125
123
|
const className = scopeToCSSClass(
|
|
126
124
|
node.scope,
|
|
127
125
|
{ prefix: this.classPrefix }
|
|
@@ -133,8 +131,7 @@ var require_core = __commonJS({
|
|
|
133
131
|
*
|
|
134
132
|
* @param {Node} node */
|
|
135
133
|
closeNode(node) {
|
|
136
|
-
if (!emitsWrappingTags(node))
|
|
137
|
-
return;
|
|
134
|
+
if (!emitsWrappingTags(node)) return;
|
|
138
135
|
this.buffer += SPAN_CLOSE;
|
|
139
136
|
}
|
|
140
137
|
/**
|
|
@@ -185,8 +182,7 @@ var require_core = __commonJS({
|
|
|
185
182
|
return void 0;
|
|
186
183
|
}
|
|
187
184
|
closeAllNodes() {
|
|
188
|
-
while (this.closeNode())
|
|
189
|
-
;
|
|
185
|
+
while (this.closeNode()) ;
|
|
190
186
|
}
|
|
191
187
|
toJSON() {
|
|
192
188
|
return JSON.stringify(this.rootNode, null, 4);
|
|
@@ -216,10 +212,8 @@ var require_core = __commonJS({
|
|
|
216
212
|
* @param {Node} node
|
|
217
213
|
*/
|
|
218
214
|
static _collapse(node) {
|
|
219
|
-
if (typeof node === "string")
|
|
220
|
-
|
|
221
|
-
if (!node.children)
|
|
222
|
-
return;
|
|
215
|
+
if (typeof node === "string") return;
|
|
216
|
+
if (!node.children) return;
|
|
223
217
|
if (node.children.every((el) => typeof el === "string")) {
|
|
224
218
|
node.children = [node.children.join("")];
|
|
225
219
|
} else {
|
|
@@ -259,8 +253,7 @@ var require_core = __commonJS({
|
|
|
259
253
|
*/
|
|
260
254
|
__addSublanguage(emitter, name) {
|
|
261
255
|
const node = emitter.root;
|
|
262
|
-
if (name)
|
|
263
|
-
node.scope = `language:${name}`;
|
|
256
|
+
if (name) node.scope = `language:${name}`;
|
|
264
257
|
this.add(node);
|
|
265
258
|
}
|
|
266
259
|
toHTML() {
|
|
@@ -273,10 +266,8 @@ var require_core = __commonJS({
|
|
|
273
266
|
}
|
|
274
267
|
};
|
|
275
268
|
function source(re) {
|
|
276
|
-
if (!re)
|
|
277
|
-
|
|
278
|
-
if (typeof re === "string")
|
|
279
|
-
return re;
|
|
269
|
+
if (!re) return null;
|
|
270
|
+
if (typeof re === "string") return re;
|
|
280
271
|
return re.source;
|
|
281
272
|
}
|
|
282
273
|
function lookahead(re) {
|
|
@@ -365,8 +356,7 @@ var require_core = __commonJS({
|
|
|
365
356
|
relevance: 0,
|
|
366
357
|
/** @type {ModeCallback} */
|
|
367
358
|
"on:begin": (m, resp) => {
|
|
368
|
-
if (m.index !== 0)
|
|
369
|
-
resp.ignoreMatch();
|
|
359
|
+
if (m.index !== 0) resp.ignoreMatch();
|
|
370
360
|
}
|
|
371
361
|
}, opts);
|
|
372
362
|
};
|
|
@@ -516,8 +506,7 @@ var require_core = __commonJS({
|
|
|
516
506
|
},
|
|
517
507
|
/** @type {ModeCallback} */
|
|
518
508
|
"on:end": (m, resp) => {
|
|
519
|
-
if (resp.data._beginMatch !== m[1])
|
|
520
|
-
resp.ignoreMatch();
|
|
509
|
+
if (resp.data._beginMatch !== m[1]) resp.ignoreMatch();
|
|
521
510
|
}
|
|
522
511
|
}
|
|
523
512
|
);
|
|
@@ -562,39 +551,30 @@ var require_core = __commonJS({
|
|
|
562
551
|
}
|
|
563
552
|
}
|
|
564
553
|
function beginKeywords(mode, parent) {
|
|
565
|
-
if (!parent)
|
|
566
|
-
|
|
567
|
-
if (!mode.beginKeywords)
|
|
568
|
-
return;
|
|
554
|
+
if (!parent) return;
|
|
555
|
+
if (!mode.beginKeywords) return;
|
|
569
556
|
mode.begin = "\\b(" + mode.beginKeywords.split(" ").join("|") + ")(?!\\.)(?=\\b|\\s)";
|
|
570
557
|
mode.__beforeBegin = skipIfHasPrecedingDot;
|
|
571
558
|
mode.keywords = mode.keywords || mode.beginKeywords;
|
|
572
559
|
delete mode.beginKeywords;
|
|
573
|
-
if (mode.relevance === void 0)
|
|
574
|
-
mode.relevance = 0;
|
|
560
|
+
if (mode.relevance === void 0) mode.relevance = 0;
|
|
575
561
|
}
|
|
576
562
|
function compileIllegal(mode, _parent) {
|
|
577
|
-
if (!Array.isArray(mode.illegal))
|
|
578
|
-
return;
|
|
563
|
+
if (!Array.isArray(mode.illegal)) return;
|
|
579
564
|
mode.illegal = either(...mode.illegal);
|
|
580
565
|
}
|
|
581
566
|
function compileMatch(mode, _parent) {
|
|
582
|
-
if (!mode.match)
|
|
583
|
-
|
|
584
|
-
if (mode.begin || mode.end)
|
|
585
|
-
throw new Error("begin & end are not supported with match");
|
|
567
|
+
if (!mode.match) return;
|
|
568
|
+
if (mode.begin || mode.end) throw new Error("begin & end are not supported with match");
|
|
586
569
|
mode.begin = mode.match;
|
|
587
570
|
delete mode.match;
|
|
588
571
|
}
|
|
589
572
|
function compileRelevance(mode, _parent) {
|
|
590
|
-
if (mode.relevance === void 0)
|
|
591
|
-
mode.relevance = 1;
|
|
573
|
+
if (mode.relevance === void 0) mode.relevance = 1;
|
|
592
574
|
}
|
|
593
575
|
var beforeMatchExt = (mode, parent) => {
|
|
594
|
-
if (!mode.beforeMatch)
|
|
595
|
-
|
|
596
|
-
if (mode.starts)
|
|
597
|
-
throw new Error("beforeMatch cannot be used with starts");
|
|
576
|
+
if (!mode.beforeMatch) return;
|
|
577
|
+
if (mode.starts) throw new Error("beforeMatch cannot be used with starts");
|
|
598
578
|
const originalMode = Object.assign({}, mode);
|
|
599
579
|
Object.keys(mode).forEach((key) => {
|
|
600
580
|
delete mode[key];
|
|
@@ -669,8 +649,7 @@ var require_core = __commonJS({
|
|
|
669
649
|
console.log(`WARN: ${message}`, ...args);
|
|
670
650
|
};
|
|
671
651
|
var deprecated = (version2, message) => {
|
|
672
|
-
if (seenDeprecations[`${version2}/${message}`])
|
|
673
|
-
return;
|
|
652
|
+
if (seenDeprecations[`${version2}/${message}`]) return;
|
|
674
653
|
console.log(`Deprecated as of ${version2}. ${message}`);
|
|
675
654
|
seenDeprecations[`${version2}/${message}`] = true;
|
|
676
655
|
};
|
|
@@ -690,8 +669,7 @@ var require_core = __commonJS({
|
|
|
690
669
|
mode[key]._multi = true;
|
|
691
670
|
}
|
|
692
671
|
function beginMultiClass(mode) {
|
|
693
|
-
if (!Array.isArray(mode.begin))
|
|
694
|
-
return;
|
|
672
|
+
if (!Array.isArray(mode.begin)) return;
|
|
695
673
|
if (mode.skip || mode.excludeBegin || mode.returnBegin) {
|
|
696
674
|
error("skip, excludeBegin, returnBegin not compatible with beginScope: {}");
|
|
697
675
|
throw MultiClassError;
|
|
@@ -704,8 +682,7 @@ var require_core = __commonJS({
|
|
|
704
682
|
mode.begin = _rewriteBackreferences(mode.begin, { joinWith: "" });
|
|
705
683
|
}
|
|
706
684
|
function endMultiClass(mode) {
|
|
707
|
-
if (!Array.isArray(mode.end))
|
|
708
|
-
return;
|
|
685
|
+
if (!Array.isArray(mode.end)) return;
|
|
709
686
|
if (mode.skip || mode.excludeEnd || mode.returnEnd) {
|
|
710
687
|
error("skip, excludeEnd, returnEnd not compatible with endScope: {}");
|
|
711
688
|
throw MultiClassError;
|
|
@@ -786,8 +763,7 @@ var require_core = __commonJS({
|
|
|
786
763
|
}
|
|
787
764
|
// @ts-ignore
|
|
788
765
|
getMatcher(index) {
|
|
789
|
-
if (this.multiRegexes[index])
|
|
790
|
-
return this.multiRegexes[index];
|
|
766
|
+
if (this.multiRegexes[index]) return this.multiRegexes[index];
|
|
791
767
|
const matcher = new MultiRegex();
|
|
792
768
|
this.rules.slice(index).forEach(([re, opts]) => matcher.addRule(re, opts));
|
|
793
769
|
matcher.compile();
|
|
@@ -803,8 +779,7 @@ var require_core = __commonJS({
|
|
|
803
779
|
// @ts-ignore
|
|
804
780
|
addRule(re, opts) {
|
|
805
781
|
this.rules.push([re, opts]);
|
|
806
|
-
if (opts.type === "begin")
|
|
807
|
-
this.count++;
|
|
782
|
+
if (opts.type === "begin") this.count++;
|
|
808
783
|
}
|
|
809
784
|
/** @param {string} s */
|
|
810
785
|
exec(s) {
|
|
@@ -812,8 +787,7 @@ var require_core = __commonJS({
|
|
|
812
787
|
m.lastIndex = this.lastIndex;
|
|
813
788
|
let result = m.exec(s);
|
|
814
789
|
if (this.resumingScanAtSamePosition()) {
|
|
815
|
-
if (result && result.index === this.lastIndex)
|
|
816
|
-
;
|
|
790
|
+
if (result && result.index === this.lastIndex) ;
|
|
817
791
|
else {
|
|
818
792
|
const m2 = this.getMatcher(0);
|
|
819
793
|
m2.lastIndex = this.lastIndex + 1;
|
|
@@ -845,8 +819,7 @@ var require_core = __commonJS({
|
|
|
845
819
|
/** @type CompiledMode */
|
|
846
820
|
mode
|
|
847
821
|
);
|
|
848
|
-
if (mode.isCompiled)
|
|
849
|
-
return cmode;
|
|
822
|
+
if (mode.isCompiled) return cmode;
|
|
850
823
|
[
|
|
851
824
|
scopeClassName,
|
|
852
825
|
// do this early so compiler extensions generally don't have to worry about
|
|
@@ -878,25 +851,20 @@ var require_core = __commonJS({
|
|
|
878
851
|
}
|
|
879
852
|
cmode.keywordPatternRe = langRe(keywordPattern, true);
|
|
880
853
|
if (parent) {
|
|
881
|
-
if (!mode.begin)
|
|
882
|
-
mode.begin = /\B|\b/;
|
|
854
|
+
if (!mode.begin) mode.begin = /\B|\b/;
|
|
883
855
|
cmode.beginRe = langRe(cmode.begin);
|
|
884
|
-
if (!mode.end && !mode.endsWithParent)
|
|
885
|
-
|
|
886
|
-
if (mode.end)
|
|
887
|
-
cmode.endRe = langRe(cmode.end);
|
|
856
|
+
if (!mode.end && !mode.endsWithParent) mode.end = /\B|\b/;
|
|
857
|
+
if (mode.end) cmode.endRe = langRe(cmode.end);
|
|
888
858
|
cmode.terminatorEnd = source(cmode.end) || "";
|
|
889
859
|
if (mode.endsWithParent && parent.terminatorEnd) {
|
|
890
860
|
cmode.terminatorEnd += (mode.end ? "|" : "") + parent.terminatorEnd;
|
|
891
861
|
}
|
|
892
862
|
}
|
|
893
|
-
if (mode.illegal)
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
if (!mode.contains)
|
|
899
|
-
mode.contains = [];
|
|
863
|
+
if (mode.illegal) cmode.illegalRe = langRe(
|
|
864
|
+
/** @type {RegExp | string} */
|
|
865
|
+
mode.illegal
|
|
866
|
+
);
|
|
867
|
+
if (!mode.contains) mode.contains = [];
|
|
900
868
|
mode.contains = [].concat(...mode.contains.map(function(c) {
|
|
901
869
|
return expandOrCloneMode(c === "self" ? mode : c);
|
|
902
870
|
}));
|
|
@@ -913,8 +881,7 @@ var require_core = __commonJS({
|
|
|
913
881
|
cmode.matcher = buildModeRegex(cmode);
|
|
914
882
|
return cmode;
|
|
915
883
|
}
|
|
916
|
-
if (!language.compilerExtensions)
|
|
917
|
-
language.compilerExtensions = [];
|
|
884
|
+
if (!language.compilerExtensions) language.compilerExtensions = [];
|
|
918
885
|
if (language.contains && language.contains.includes("self")) {
|
|
919
886
|
throw new Error("ERR: contains `self` is not supported at the top-level of a language. See documentation.");
|
|
920
887
|
}
|
|
@@ -925,8 +892,7 @@ var require_core = __commonJS({
|
|
|
925
892
|
);
|
|
926
893
|
}
|
|
927
894
|
function dependencyOnParent(mode) {
|
|
928
|
-
if (!mode)
|
|
929
|
-
return false;
|
|
895
|
+
if (!mode) return false;
|
|
930
896
|
return mode.endsWithParent || dependencyOnParent(mode.starts);
|
|
931
897
|
}
|
|
932
898
|
function expandOrCloneMode(mode) {
|
|
@@ -1043,8 +1009,7 @@ var require_core = __commonJS({
|
|
|
1043
1009
|
emitter.addText(buf);
|
|
1044
1010
|
buf = "";
|
|
1045
1011
|
keywordHits[word] = (keywordHits[word] || 0) + 1;
|
|
1046
|
-
if (keywordHits[word] <= MAX_KEYWORD_HITS)
|
|
1047
|
-
relevance += keywordRelevance;
|
|
1012
|
+
if (keywordHits[word] <= MAX_KEYWORD_HITS) relevance += keywordRelevance;
|
|
1048
1013
|
if (kind.startsWith("_")) {
|
|
1049
1014
|
buf += match[0];
|
|
1050
1015
|
} else {
|
|
@@ -1061,8 +1026,7 @@ var require_core = __commonJS({
|
|
|
1061
1026
|
emitter.addText(buf);
|
|
1062
1027
|
}
|
|
1063
1028
|
function processSubLanguage() {
|
|
1064
|
-
if (modeBuffer === "")
|
|
1065
|
-
return;
|
|
1029
|
+
if (modeBuffer === "") return;
|
|
1066
1030
|
let result2 = null;
|
|
1067
1031
|
if (typeof top.subLanguage === "string") {
|
|
1068
1032
|
if (!languages[top.subLanguage]) {
|
|
@@ -1089,8 +1053,7 @@ var require_core = __commonJS({
|
|
|
1089
1053
|
modeBuffer = "";
|
|
1090
1054
|
}
|
|
1091
1055
|
function emitKeyword(keyword, scope) {
|
|
1092
|
-
if (keyword === "")
|
|
1093
|
-
return;
|
|
1056
|
+
if (keyword === "") return;
|
|
1094
1057
|
emitter.startScope(scope);
|
|
1095
1058
|
emitter.addText(keyword);
|
|
1096
1059
|
emitter.endScope();
|
|
@@ -1137,8 +1100,7 @@ var require_core = __commonJS({
|
|
|
1137
1100
|
if (mode["on:end"]) {
|
|
1138
1101
|
const resp = new Response(mode);
|
|
1139
1102
|
mode["on:end"](match, resp);
|
|
1140
|
-
if (resp.isMatchIgnored)
|
|
1141
|
-
matched = false;
|
|
1103
|
+
if (resp.isMatchIgnored) matched = false;
|
|
1142
1104
|
}
|
|
1143
1105
|
if (matched) {
|
|
1144
1106
|
while (mode.endsParent && mode.parent) {
|
|
@@ -1166,11 +1128,9 @@ var require_core = __commonJS({
|
|
|
1166
1128
|
const resp = new Response(newMode);
|
|
1167
1129
|
const beforeCallbacks = [newMode.__beforeBegin, newMode["on:begin"]];
|
|
1168
1130
|
for (const cb of beforeCallbacks) {
|
|
1169
|
-
if (!cb)
|
|
1170
|
-
continue;
|
|
1131
|
+
if (!cb) continue;
|
|
1171
1132
|
cb(match, resp);
|
|
1172
|
-
if (resp.isMatchIgnored)
|
|
1173
|
-
return doIgnore(lexeme);
|
|
1133
|
+
if (resp.isMatchIgnored) return doIgnore(lexeme);
|
|
1174
1134
|
}
|
|
1175
1135
|
if (newMode.skip) {
|
|
1176
1136
|
modeBuffer += lexeme;
|
|
@@ -1303,8 +1263,7 @@ var require_core = __commonJS({
|
|
|
1303
1263
|
}
|
|
1304
1264
|
top.matcher.lastIndex = index;
|
|
1305
1265
|
const match = top.matcher.exec(codeToHighlight);
|
|
1306
|
-
if (!match)
|
|
1307
|
-
break;
|
|
1266
|
+
if (!match) break;
|
|
1308
1267
|
const beforeMatch = codeToHighlight.substring(index, match.index);
|
|
1309
1268
|
const processedCount = processLexeme(beforeMatch, match);
|
|
1310
1269
|
index = match.index + processedCount;
|
|
@@ -1373,8 +1332,7 @@ var require_core = __commonJS({
|
|
|
1373
1332
|
);
|
|
1374
1333
|
results.unshift(plaintext);
|
|
1375
1334
|
const sorted = results.sort((a, b) => {
|
|
1376
|
-
if (a.relevance !== b.relevance)
|
|
1377
|
-
return b.relevance - a.relevance;
|
|
1335
|
+
if (a.relevance !== b.relevance) return b.relevance - a.relevance;
|
|
1378
1336
|
if (a.language && b.language) {
|
|
1379
1337
|
if (getLanguage(a.language).supersetOf === b.language) {
|
|
1380
1338
|
return 1;
|
|
@@ -1397,8 +1355,7 @@ var require_core = __commonJS({
|
|
|
1397
1355
|
function highlightElement(element) {
|
|
1398
1356
|
let node = null;
|
|
1399
1357
|
const language = blockLanguage(element);
|
|
1400
|
-
if (shouldNotHighlight(language))
|
|
1401
|
-
return;
|
|
1358
|
+
if (shouldNotHighlight(language)) return;
|
|
1402
1359
|
fire(
|
|
1403
1360
|
"before:highlightElement",
|
|
1404
1361
|
{ el: element, language }
|
|
@@ -1463,8 +1420,7 @@ var require_core = __commonJS({
|
|
|
1463
1420
|
blocks.forEach(highlightElement);
|
|
1464
1421
|
}
|
|
1465
1422
|
function boot() {
|
|
1466
|
-
if (wantsHighlight)
|
|
1467
|
-
highlightAll();
|
|
1423
|
+
if (wantsHighlight) highlightAll();
|
|
1468
1424
|
}
|
|
1469
1425
|
if (typeof window !== "undefined" && window.addEventListener) {
|
|
1470
1426
|
window.addEventListener("DOMContentLoaded", boot, false);
|
|
@@ -1482,8 +1438,7 @@ var require_core = __commonJS({
|
|
|
1482
1438
|
}
|
|
1483
1439
|
lang = PLAINTEXT_LANGUAGE;
|
|
1484
1440
|
}
|
|
1485
|
-
if (!lang.name)
|
|
1486
|
-
lang.name = languageName;
|
|
1441
|
+
if (!lang.name) lang.name = languageName;
|
|
1487
1442
|
languages[languageName] = lang;
|
|
1488
1443
|
lang.rawDefinition = languageDefinition.bind(null, hljs);
|
|
1489
1444
|
if (lang.aliases) {
|
|
@@ -2424,6 +2379,91 @@ function render2(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
2424
2379
|
LiveExample_default.render = render2;
|
|
2425
2380
|
LiveExample_default.__file = "src/LiveExample.vue";
|
|
2426
2381
|
var LiveExample_default2 = LiveExample_default;
|
|
2382
|
+
|
|
2383
|
+
// src/create-element.ts
|
|
2384
|
+
var voidElements = [
|
|
2385
|
+
"area",
|
|
2386
|
+
"base",
|
|
2387
|
+
"br",
|
|
2388
|
+
"col",
|
|
2389
|
+
"embed",
|
|
2390
|
+
"hr",
|
|
2391
|
+
"img",
|
|
2392
|
+
"input",
|
|
2393
|
+
"link",
|
|
2394
|
+
"meta",
|
|
2395
|
+
"param",
|
|
2396
|
+
"source",
|
|
2397
|
+
"track",
|
|
2398
|
+
"wbr"
|
|
2399
|
+
];
|
|
2400
|
+
function unpackArgs(args) {
|
|
2401
|
+
if (args.length === 0) {
|
|
2402
|
+
return { attributes: {}, children: [] };
|
|
2403
|
+
}
|
|
2404
|
+
if (args.length === 1) {
|
|
2405
|
+
const [arg02] = args;
|
|
2406
|
+
if (typeof arg02 === "string") {
|
|
2407
|
+
return { attributes: {}, children: [arg02] };
|
|
2408
|
+
} else if (Array.isArray(arg02)) {
|
|
2409
|
+
return { attributes: {}, children: arg02 };
|
|
2410
|
+
} else {
|
|
2411
|
+
return { attributes: arg02, children: [] };
|
|
2412
|
+
}
|
|
2413
|
+
}
|
|
2414
|
+
const [arg0, arg1] = args;
|
|
2415
|
+
return { attributes: arg0, children: Array.isArray(arg1) ? arg1 : [arg1] };
|
|
2416
|
+
}
|
|
2417
|
+
function serializeChildren(children) {
|
|
2418
|
+
if (children.length > 0) {
|
|
2419
|
+
return ` ${children.join(" ")} `;
|
|
2420
|
+
} else {
|
|
2421
|
+
return "";
|
|
2422
|
+
}
|
|
2423
|
+
}
|
|
2424
|
+
function serializeAttribute(key, value, prefix = "") {
|
|
2425
|
+
if (Array.isArray(value)) {
|
|
2426
|
+
const tokens = value.map((it) => it ? String(it) : null).filter(Boolean);
|
|
2427
|
+
if (tokens.length > 0) {
|
|
2428
|
+
return `${prefix}${key}="${tokens.join(" ")}"`;
|
|
2429
|
+
} else {
|
|
2430
|
+
return [];
|
|
2431
|
+
}
|
|
2432
|
+
}
|
|
2433
|
+
if (value === null || value === void 0) {
|
|
2434
|
+
return [];
|
|
2435
|
+
}
|
|
2436
|
+
if (typeof value === "string" || typeof value === "number") {
|
|
2437
|
+
return `${prefix}${key}="${value}"`;
|
|
2438
|
+
}
|
|
2439
|
+
if (typeof value === "boolean") {
|
|
2440
|
+
return value ? `${prefix}${key}` : [];
|
|
2441
|
+
}
|
|
2442
|
+
return Object.entries(value).map(([nestedKey, value2]) => {
|
|
2443
|
+
return serializeAttribute(nestedKey, value2, `${prefix}${key}-`);
|
|
2444
|
+
}).flat().filter(Boolean);
|
|
2445
|
+
}
|
|
2446
|
+
function serializeAttributes(attrs) {
|
|
2447
|
+
const entries = Object.entries(attrs);
|
|
2448
|
+
const kv = entries.map(([key, value]) => serializeAttribute(key, value));
|
|
2449
|
+
const flat = kv.flat();
|
|
2450
|
+
if (flat.length > 0) {
|
|
2451
|
+
return ` ${kv.flat().join(" ")}`;
|
|
2452
|
+
} else {
|
|
2453
|
+
return "";
|
|
2454
|
+
}
|
|
2455
|
+
}
|
|
2456
|
+
function createElement(tagName, ...args) {
|
|
2457
|
+
const { attributes, children } = unpackArgs(args);
|
|
2458
|
+
const attrs = serializeAttributes(attributes);
|
|
2459
|
+
if (voidElements.includes(tagName)) {
|
|
2460
|
+
return `<${tagName}${attrs}>`;
|
|
2461
|
+
} else {
|
|
2462
|
+
const content = serializeChildren(children);
|
|
2463
|
+
return `<${tagName}${attrs}>${content}</${tagName}>`;
|
|
2464
|
+
}
|
|
2465
|
+
}
|
|
2427
2466
|
export {
|
|
2428
|
-
LiveExample_default2 as LiveExample
|
|
2467
|
+
LiveExample_default2 as LiveExample,
|
|
2468
|
+
createElement
|
|
2429
2469
|
};
|
package/dist/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@forsakringskassan/docs-live-example",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.4",
|
|
4
4
|
"description": "Components used for live examples",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"documentation"
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
"homepage": "https://github.com/Forsakringskassan/docs-live-example",
|
|
9
9
|
"bugs": "https://github.com/Forsakringskassan/docs-live-example/issues",
|
|
10
10
|
"repository": {
|
|
11
|
-
"
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/Forsakringskassan/docs-live-example.git"
|
|
12
13
|
},
|
|
13
14
|
"license": "MIT",
|
|
14
15
|
"author": "Försäkringskassan",
|