bitwrench 2.0.15 → 2.0.17
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/README.md +57 -21
- package/dist/bitwrench-bccl.cjs.js +3750 -0
- package/dist/bitwrench-bccl.cjs.min.js +40 -0
- package/dist/bitwrench-bccl.esm.js +3745 -0
- package/dist/bitwrench-bccl.esm.min.js +40 -0
- package/dist/bitwrench-bccl.umd.js +3756 -0
- package/dist/bitwrench-bccl.umd.min.js +40 -0
- package/dist/bitwrench-code-edit.cjs.js +57 -7
- package/dist/bitwrench-code-edit.cjs.min.js +9 -2
- package/dist/bitwrench-code-edit.es5.js +74 -11
- package/dist/bitwrench-code-edit.es5.min.js +9 -2
- package/dist/bitwrench-code-edit.esm.js +57 -7
- package/dist/bitwrench-code-edit.esm.min.js +9 -2
- package/dist/bitwrench-code-edit.umd.js +57 -7
- package/dist/bitwrench-code-edit.umd.min.js +9 -2
- package/dist/bitwrench-lean.cjs.js +905 -157
- package/dist/bitwrench-lean.cjs.min.js +7 -7
- package/dist/bitwrench-lean.es5.js +931 -157
- package/dist/bitwrench-lean.es5.min.js +5 -5
- package/dist/bitwrench-lean.esm.js +904 -157
- package/dist/bitwrench-lean.esm.min.js +7 -7
- package/dist/bitwrench-lean.umd.js +905 -157
- package/dist/bitwrench-lean.umd.min.js +7 -7
- package/dist/bitwrench.cjs.js +910 -158
- package/dist/bitwrench.cjs.min.js +8 -8
- package/dist/bitwrench.css +60 -17
- package/dist/bitwrench.es5.js +939 -158
- package/dist/bitwrench.es5.min.js +6 -6
- package/dist/bitwrench.esm.js +909 -158
- package/dist/bitwrench.esm.min.js +8 -8
- package/dist/bitwrench.min.css +1 -1
- package/dist/bitwrench.umd.js +910 -158
- package/dist/bitwrench.umd.min.js +8 -8
- package/dist/builds.json +168 -80
- package/dist/bwserve.cjs.js +660 -0
- package/dist/bwserve.esm.js +652 -0
- package/dist/sri.json +36 -28
- package/package.json +20 -3
- package/readme.html +62 -23
- package/src/bitwrench-bccl-entry.js +72 -0
- package/src/bitwrench-bccl.js +5 -1
- package/src/bitwrench-code-edit.js +56 -6
- package/src/bitwrench-color-utils.js +5 -6
- package/src/bitwrench-styles.js +20 -8
- package/src/bitwrench.js +876 -140
- package/src/bwserve/client.js +182 -0
- package/src/bwserve/index.js +363 -0
- package/src/bwserve/shell.js +106 -0
- package/src/cli/index.js +36 -15
- package/src/cli/layout-default.js +47 -32
- package/src/cli/serve.js +325 -0
- package/src/version.js +3 -3
- /package/bin/{bitwrench.js → bwcli.js} +0 -0
|
@@ -1,10 +1,17 @@
|
|
|
1
|
-
/*! bitwrench v2.0.
|
|
1
|
+
/*! bitwrench v2.0.17 | BSD-2-Clause | https://deftio.github.com/bitwrench/pages */
|
|
2
2
|
/**
|
|
3
3
|
* bitwrench-code-edit.js - syntax-highlighted contenteditable code editor addon
|
|
4
4
|
*
|
|
5
5
|
* Provides bw.highlight() for tokenizing JS/CSS/HTML into TACO spans,
|
|
6
6
|
* and bw.codeEditor() for a live editable code block with syntax coloring.
|
|
7
7
|
*
|
|
8
|
+
* Theme integration: The editor chrome (background, text color, font) reads
|
|
9
|
+
* from CSS custom properties --bw_code_bg, --bw_code_text, --bw_font_mono,
|
|
10
|
+
* falling back to built-in dark values when no theme is active. Syntax
|
|
11
|
+
* highlighting colors are intentionally fixed (they are a code color scheme,
|
|
12
|
+
* not brand colors). The bw_ce_light class is still supported for manual
|
|
13
|
+
* light-mode override.
|
|
14
|
+
*
|
|
8
15
|
* Can be loaded standalone (browser script tag after bitwrench.umd.js),
|
|
9
16
|
* or imported as an ES module / CJS module.
|
|
10
17
|
*
|
|
@@ -15,9 +22,9 @@
|
|
|
15
22
|
// -- CSS (injected once) ----------------------------------------------
|
|
16
23
|
var _cssInjected = false;
|
|
17
24
|
var CSS_TEXT =
|
|
18
|
-
'.bw_ce{background
|
|
25
|
+
'.bw_ce{background:var(--bw_code_bg,#1e293b);border-radius:6px;border:1px solid rgba(255,255,255,0.08);overflow:auto}' +
|
|
19
26
|
'.bw_ce pre{margin:0;padding:0}' +
|
|
20
|
-
'.bw_ce code{font-family:"SF Mono",Monaco,"Cascadia Code",Consolas,monospace;font-size:0.875rem;line-height:1.6;color
|
|
27
|
+
'.bw_ce code{font-family:var(--bw_font_mono,"SF Mono",Monaco,"Cascadia Code",Consolas,monospace);font-size:0.875rem;line-height:1.6;color:var(--bw_code_text,#e2e8f0);outline:none;white-space:pre-wrap;display:block;padding:0.75rem 1rem}' +
|
|
21
28
|
'.bw_ce code:empty::before{content:"\\200b"}' +
|
|
22
29
|
'.bw_ce .bw_ce_keyword{color:#c792ea}' +
|
|
23
30
|
'.bw_ce .bw_ce_string{color:#c3e88d}' +
|
|
@@ -55,7 +62,12 @@ var CSS_TEXT =
|
|
|
55
62
|
'.bw_ce_light.bw_ce .bw_ce_css_value{color:#ea580c}' +
|
|
56
63
|
'.bw_ce_light.bw_ce .bw_ce_at_rule{color:#7c3aed}' +
|
|
57
64
|
'.bw_ce_light.bw_ce .bw_ce_color{color:#ea580c}' +
|
|
58
|
-
'.bw_ce_light.bw_ce .bw_ce_template_interp{color:#0891b2}'
|
|
65
|
+
'.bw_ce_light.bw_ce .bw_ce_template_interp{color:#0891b2}' +
|
|
66
|
+
// Line number gutter (opt-in via lineNumbers option)
|
|
67
|
+
'.bw_ce_wrap{display:flex;flex-direction:row}' +
|
|
68
|
+
'.bw_ce_gutter{flex:0 0 auto;padding:0.75rem 0;text-align:right;user-select:none;-webkit-user-select:none;color:#546e7a;font-family:var(--bw_font_mono,"SF Mono",Monaco,"Cascadia Code",Consolas,monospace);font-size:0.875rem;line-height:1.6;border-right:1px solid rgba(255,255,255,0.08);overflow:hidden}' +
|
|
69
|
+
'.bw_ce_gutter span{display:block;padding:0 0.5rem 0 0.75rem}' +
|
|
70
|
+
'.bw_ce_light .bw_ce_gutter{color:#9ca3af;border-right-color:#d8d8d8}';
|
|
59
71
|
|
|
60
72
|
function ensureCSS(bw) {
|
|
61
73
|
if (_cssInjected) return;
|
|
@@ -538,6 +550,7 @@ function codeEditor(opts) {
|
|
|
538
550
|
var lang = opts.lang || 'js';
|
|
539
551
|
var height = opts.height || '180px';
|
|
540
552
|
var readOnly = !!opts.readOnly;
|
|
553
|
+
var showLineNumbers = !!opts.lineNumbers;
|
|
541
554
|
var className = 'bw_ce' + (opts.className ? ' ' + opts.className : '');
|
|
542
555
|
|
|
543
556
|
var highlighted = highlight(code, lang);
|
|
@@ -550,12 +563,26 @@ function codeEditor(opts) {
|
|
|
550
563
|
codeAttrs.contenteditable = 'true';
|
|
551
564
|
}
|
|
552
565
|
|
|
566
|
+
// Build line number gutter TACO if requested
|
|
567
|
+
var gutterTaco = null;
|
|
568
|
+
if (showLineNumbers) {
|
|
569
|
+
var lineCount = (code.match(/\n/g) || []).length + 1;
|
|
570
|
+
var gutterLines = [];
|
|
571
|
+
for (var li = 1; li <= lineCount; li++) {
|
|
572
|
+
gutterLines.push({ t: 'span', c: String(li) });
|
|
573
|
+
}
|
|
574
|
+
gutterTaco = { t: 'div', a: { class: 'bw_ce_gutter' }, c: gutterLines };
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
var preBlock = { t: 'pre', a: { style: 'flex:1;min-width:0;margin:0' }, c: { t: 'code', a: codeAttrs, c: highlighted } };
|
|
578
|
+
var innerContent = showLineNumbers
|
|
579
|
+
? { t: 'div', a: { class: 'bw_ce_wrap' }, c: [gutterTaco, preBlock] }
|
|
580
|
+
: preBlock;
|
|
581
|
+
|
|
553
582
|
return {
|
|
554
583
|
t: 'div',
|
|
555
584
|
a: { class: className, style: 'max-height:' + height + ';overflow:auto' },
|
|
556
|
-
c: [
|
|
557
|
-
{ t: 'pre', c: { t: 'code', a: codeAttrs, c: highlighted } }
|
|
558
|
-
],
|
|
585
|
+
c: [innerContent],
|
|
559
586
|
o: {
|
|
560
587
|
mounted: function(el) {
|
|
561
588
|
var codeEl = el.querySelector('.bw_ce_code');
|
|
@@ -563,21 +590,43 @@ function codeEditor(opts) {
|
|
|
563
590
|
|
|
564
591
|
var currentCode = code;
|
|
565
592
|
var debounceTimer = null;
|
|
593
|
+
var gutterEl = showLineNumbers ? el.querySelector('.bw_ce_gutter') : null;
|
|
566
594
|
|
|
567
595
|
// Resolve bw from global or import context
|
|
568
596
|
var bw = (typeof window !== 'undefined' && window.bw) || {};
|
|
569
597
|
|
|
570
598
|
function getValue() { return codeEl.textContent || ''; }
|
|
571
599
|
|
|
600
|
+
function updateGutter(text) {
|
|
601
|
+
if (!gutterEl) return;
|
|
602
|
+
var count = (text.match(/\n/g) || []).length + 1;
|
|
603
|
+
var html = '';
|
|
604
|
+
for (var i = 1; i <= count; i++) html += '<span>' + i + '</span>';
|
|
605
|
+
gutterEl.innerHTML = html;
|
|
606
|
+
}
|
|
607
|
+
|
|
572
608
|
function setValue(newCode) {
|
|
573
609
|
currentCode = newCode;
|
|
574
610
|
var tacos = highlight(newCode, lang);
|
|
575
611
|
if (bw.html) codeEl.innerHTML = bw.html({ t: 'span', c: tacos });
|
|
612
|
+
updateGutter(newCode);
|
|
576
613
|
}
|
|
577
614
|
|
|
578
615
|
// Expose API on the element
|
|
579
616
|
el._bwCodeEdit = { getValue: getValue, setValue: setValue };
|
|
580
617
|
|
|
618
|
+
// Scroll sync: keep gutter aligned with code
|
|
619
|
+
if (gutterEl) {
|
|
620
|
+
var scrollParent = codeEl.closest('.bw_ce') || el;
|
|
621
|
+
scrollParent.addEventListener('scroll', function() {
|
|
622
|
+
gutterEl.style.transform = 'translateY(' + (-scrollParent.scrollTop) + 'px)';
|
|
623
|
+
});
|
|
624
|
+
// If the outer .bw_ce has overflow, sync from there
|
|
625
|
+
el.addEventListener('scroll', function() {
|
|
626
|
+
gutterEl.style.transform = 'translateY(' + (-el.scrollTop) + 'px)';
|
|
627
|
+
});
|
|
628
|
+
}
|
|
629
|
+
|
|
581
630
|
if (readOnly) return;
|
|
582
631
|
|
|
583
632
|
function rehighlight() {
|
|
@@ -588,6 +637,7 @@ function codeEditor(opts) {
|
|
|
588
637
|
var tacos = highlight(newCode, lang);
|
|
589
638
|
if (bw.html) codeEl.innerHTML = bw.html({ t: 'span', c: tacos });
|
|
590
639
|
setCaretOffset(codeEl, offset);
|
|
640
|
+
updateGutter(newCode);
|
|
591
641
|
if (opts.onChange) opts.onChange(newCode);
|
|
592
642
|
}
|
|
593
643
|
|
|
@@ -1,15 +1,22 @@
|
|
|
1
|
-
/*! bitwrench v2.0.
|
|
1
|
+
/*! bitwrench v2.0.17 | BSD-2-Clause | https://deftio.github.com/bitwrench/pages */
|
|
2
2
|
/**
|
|
3
3
|
* bitwrench-code-edit.js - syntax-highlighted contenteditable code editor addon
|
|
4
4
|
*
|
|
5
5
|
* Provides bw.highlight() for tokenizing JS/CSS/HTML into TACO spans,
|
|
6
6
|
* and bw.codeEditor() for a live editable code block with syntax coloring.
|
|
7
7
|
*
|
|
8
|
+
* Theme integration: The editor chrome (background, text color, font) reads
|
|
9
|
+
* from CSS custom properties --bw_code_bg, --bw_code_text, --bw_font_mono,
|
|
10
|
+
* falling back to built-in dark values when no theme is active. Syntax
|
|
11
|
+
* highlighting colors are intentionally fixed (they are a code color scheme,
|
|
12
|
+
* not brand colors). The bw_ce_light class is still supported for manual
|
|
13
|
+
* light-mode override.
|
|
14
|
+
*
|
|
8
15
|
* Can be loaded standalone (browser script tag after bitwrench.umd.js),
|
|
9
16
|
* or imported as an ES module / CJS module.
|
|
10
17
|
*
|
|
11
18
|
* @module bitwrench-code-edit
|
|
12
19
|
* @license BSD-2-Clause
|
|
13
20
|
*/
|
|
14
|
-
var e=!1,t='.bw_ce{background:#1e293b;border-radius:6px;border:1px solid rgba(255,255,255,0.08);overflow:auto}.bw_ce pre{margin:0;padding:0}.bw_ce code{font-family:"SF Mono",Monaco,"Cascadia Code",Consolas,monospace;font-size:0.875rem;line-height:1.6;color:#e2e8f0;outline:none;white-space:pre-wrap;display:block;padding:0.75rem 1rem}.bw_ce code:empty::before{content:"\\200b"}.bw_ce .bw_ce_keyword{color:#c792ea}.bw_ce .bw_ce_string{color:#c3e88d}.bw_ce .bw_ce_comment{color:#546e7a;font-style:italic}.bw_ce .bw_ce_number{color:#f78c6c}.bw_ce .bw_ce_operator{color:#89ddff}.bw_ce .bw_ce_punctuation{color:#89ddff}.bw_ce .bw_ce_property{color:#82aaff}.bw_ce .bw_ce_function{color:#82aaff}.bw_ce .bw_ce_tag{color:#f07178}.bw_ce .bw_ce_attr_name{color:#ffcb6b}.bw_ce .bw_ce_attr_value{color:#c3e88d}.bw_ce .bw_ce_selector{color:#c792ea}.bw_ce .bw_ce_css_prop{color:#82aaff}.bw_ce .bw_ce_css_value{color:#f78c6c}.bw_ce .bw_ce_at_rule{color:#c792ea;font-style:italic}.bw_ce .bw_ce_color{color:#f78c6c}.bw_ce .bw_ce_template_interp{color:#89ddff}.bw_ce_light.bw_ce{background:#fafafa;border-color:#d8d8d8}.bw_ce_light.bw_ce code{color:#1a1a1a}.bw_ce_light.bw_ce .bw_ce_keyword{color:#7c3aed}.bw_ce_light.bw_ce .bw_ce_string{color:#16a34a}.bw_ce_light.bw_ce .bw_ce_comment{color:#9ca3af;font-style:italic}.bw_ce_light.bw_ce .bw_ce_number{color:#ea580c}.bw_ce_light.bw_ce .bw_ce_operator{color:#0891b2}.bw_ce_light.bw_ce .bw_ce_punctuation{color:#6b7280}.bw_ce_light.bw_ce .bw_ce_property{color:#2563eb}.bw_ce_light.bw_ce .bw_ce_function{color:#2563eb}.bw_ce_light.bw_ce .bw_ce_tag{color:#dc2626}.bw_ce_light.bw_ce .bw_ce_attr_name{color:#d97706}.bw_ce_light.bw_ce .bw_ce_attr_value{color:#16a34a}.bw_ce_light.bw_ce .bw_ce_selector{color:#7c3aed}.bw_ce_light.bw_ce .bw_ce_css_prop{color:#2563eb}.bw_ce_light.bw_ce .bw_ce_css_value{color:#ea580c}.bw_ce_light.bw_ce .bw_ce_at_rule{color:#7c3aed}.bw_ce_light.bw_ce .bw_ce_color{color:#ea580c}.bw_ce_light.bw_ce .bw_ce_template_interp{color:#0891b2}';var c={};function o(e){var t=[],r=0,n=e.length,a="";function l(e){a.length&&(t.push({type:e,text:a}),a="")}for(;r<n;){var s=e[r],i=e[r+1];if("/"!==s||"/"!==i)if("/"!==s||"*"!==i){if("/"===s&&"/"!==i&&"*"!==i){var p=t.length?t[t.length-1]:null,_=!1;if(a.trim().length||p&&"operator"!==p.type&&"punctuation"!==p.type&&"keyword"!==p.type||(_=!0),_){l("plain");for(var u="/",f=r+1,b=!1,w=!1;f<n;){var h=e[f];if(b)u+=h,b=!1,f++;else if("\\"!==h)if("["!==h)if("]"!==h){if("/"===h&&!w){u+=h,f++;break}if("\n"===h)break;u+=h,f++}else w=!1,u+=h,f++;else w=!0,u+=h,f++;else b=!0,u+=h,f++}for(;f<n&&/[gimsuvy]/.test(e[f]);)u+=e[f],f++;t.push({type:"string",text:u}),r=f;continue}}if('"'!==s&&"'"!==s&&"`"!==s)if(/[0-9]/.test(s)||"."===s&&i&&/[0-9]/.test(i)){l("plain");var d="";if("0"===s&&i&&/[xXbBoO]/.test(i))for(d=s+i,r+=2;r<n&&/[0-9a-fA-F_]/.test(e[r]);)d+=e[r],r++;else for(;r<n&&/[0-9._eE]/.test(e[r]);)"e"!==e[r]&&"E"!==e[r]||!e[r+1]||!/[+\-0-9]/.test(e[r+1])?(d+=e[r],r++):(d+=e[r]+e[r+1],r+=2);t.push({type:"number",text:d})}else if(/[a-zA-Z_$]/.test(s)){l("plain");for(var g="";r<n&&/[a-zA-Z0-9_$]/.test(e[r]);)g+=e[r],r++;for(var v=r;v<n&&(" "===e[v]||"\t"===e[v]);)v++;var y=t.length?t[t.length-1]:null,x=y&&"punctuation"===y.type&&"."===y.text;c[g]?t.push({type:"keyword",text:g}):x?v<n&&"("===e[v]?t.push({type:"function",text:g}):t.push({type:"property",text:g}):v<n&&"("===e[v]?t.push({type:"function",text:g}):t.push({type:"plain",text:g})}else if(-1==="=+-*/%!<>&|^~?:".indexOf(s))-1==="(){}[];,.".indexOf(s)?(a+=s,r++):(l("plain"),t.push({type:"punctuation",text:s}),r++);else{l("plain");var m=s;++r<n&&-1!=="=+-*/%!<>&|^~?:".indexOf(e[r])&&(m+=e[r],++r<n&&-1!=="=>&|".indexOf(e[r])&&(m+=e[r],r++)),t.push({type:"operator",text:m})}else{l("plain");var k=s,C=s,A=r+1;if("`"===k){for(;A<n;){var S=e[A];if("\\"!==S)if("$"!==S||"{"!==e[A+1]){if("`"===S){C+=S,A++;break}C+=S,A++}else{C.length&&t.push({type:"string",text:C}),C="",t.push({type:"template-interp",text:"${"}),A+=2;for(var O=1,E="";A<n&&O>0;){if("{"===e[A])O++;else if("}"===e[A]&&0===--O)break;E+=e[A],A++}var T=o(E);(t=t.concat(T)).push({type:"template-interp",text:"}"}),A++}else C+=S+(e[A+1]||""),A+=2}C.length&&t.push({type:"string",text:C})}else{for(;A<n;){var z=e[A];if("\\"!==z){if(z===k){C+=z,A++;break}if("\n"===z)break;C+=z,A++}else C+=z+(e[A+1]||""),A+=2}t.push({type:"string",text:C})}r=A}}else{l("plain");var R=e.indexOf("*/",r+2);-1===R&&(R=n-2),t.push({type:"comment",text:e.substring(r,R+2)}),r=R+2}else{l("plain");var Z=e.indexOf("\n",r);-1===Z&&(Z=n),t.push({type:"comment",text:e.substring(r,Z)}),r=Z}}return l("plain"),t}function r(e){var t=[],c=0,o=e.length,r="selector",n="";function a(e){n.length&&(t.push({type:e||"plain",text:n}),n="")}for(;c<o;){var l=e[c],s=e[c+1];if("/"!==l||"*"!==s)if('"'!==l&&"'"!==l||"value"!==r&&"selector"!==r)if("@"!==l||"selector"!==r)if("#"!==l||"value"!==r)if("value"===r&&/[0-9]/.test(l)){a("css-value");for(var i="";c<o&&/[0-9.]/.test(e[c]);)i+=e[c],c++;for(var p="";c<o&&/[a-zA-Z%]/.test(e[c]);)p+=e[c],c++;t.push({type:"number",text:i+p})}else"{"!==l?"}"!==l?":"!==l||"prop"!==r?";"!==l?","!==l?(n+=l,c++):(a("selector"===r?"selector":"value"===r?"css-value":"plain"),t.push({type:"punctuation",text:l}),c++):(a("value"===r?"css-value":"plain"),t.push({type:"punctuation",text:l}),r="prop",c++):(a("css-prop"),t.push({type:"punctuation",text:l}),r="value",c++):(a("prop"===r?"css-prop":"value"===r?"css-value":"plain"),t.push({type:"punctuation",text:l}),r="selector",c++):(a("selector"===r?"selector":"plain"),t.push({type:"punctuation",text:l}),r="prop",c++);else{a("css-value");var _="#";for(c++;c<o&&/[0-9a-fA-F]/.test(e[c]);)_+=e[c],c++;t.push({type:"color",text:_})}else{a("selector");var u="@";for(c++;c<o&&/[a-zA-Z\-]/.test(e[c]);)u+=e[c],c++;t.push({type:"at-rule",text:u})}else{a("selector"===r?"selector":"css-value");var f=l,b=l;for(c++;c<o;)if("\\"!==e[c]){if(e[c]===f){b+=e[c],c++;break}b+=e[c],c++}else b+=e[c]+(e[c+1]||""),c+=2;t.push({type:"string",text:b})}else{a("selector"===r?"selector":"prop"===r?"css-prop":"css-value");var w=e.indexOf("*/",c+2);-1===w&&(w=o-2),t.push({type:"comment",text:e.substring(c,w+2)}),c=w+2}}return a("selector"===r?"selector":"prop"===r?"css-prop":"css-value"),t}function n(e){var t=[],c=0,o=e.length,r="";function n(e){r.length&&(t.push({type:e,text:r}),r="")}for(;c<o;){var a=e[c];if("<"!==a||"\x3c!--"!==e.substring(c,c+4))if("<"!==a)if("&"!==a)r+=a,c++;else{n("plain");var l="&";for(c++;c<o&&";"!==e[c]&&/[a-zA-Z0-9#]/.test(e[c]);)l+=e[c],c++;c<o&&";"===e[c]&&(l+=";",c++),t.push({type:"string",text:l})}else{n("plain");var s="<";for(++c<o&&"/"===e[c]&&(s+="/",c++);c<o&&/[a-zA-Z0-9\-]/.test(e[c]);)s+=e[c],c++;for(t.push({type:"tag",text:s});c<o&&">"!==e[c]&&("/"!==e[c]||">"!==e[c+1]);)if(/\s/.test(e[c])){for(var i="";c<o&&/\s/.test(e[c]);)i+=e[c],c++;t.push({type:"plain",text:i})}else if(/[a-zA-Z_\-@:]/.test(e[c])){for(var p="";c<o&&/[a-zA-Z0-9_\-@:]/.test(e[c]);)p+=e[c],c++;if(t.push({type:"attr-name",text:p}),c<o&&"="===e[c])if(t.push({type:"punctuation",text:"="}),++c<o&&('"'===e[c]||"'"===e[c])){var _=e[c],u=_;for(c++;c<o&&e[c]!==_;)u+=e[c],c++;c<o&&(u+=e[c],c++),t.push({type:"attr-value",text:u})}else{for(var f="";c<o&&!/[\s>]/.test(e[c]);)f+=e[c],c++;t.push({type:"attr-value",text:f})}}else r+=e[c],c++,n("plain");var b="";c<o&&"/"===e[c]&&(b+="/",c++),c<o&&">"===e[c]&&(b+=">",c++),b&&t.push({type:"tag",text:b})}else{n("plain");var w=e.indexOf("--\x3e",c+4);-1===w&&(w=o-3),t.push({type:"comment",text:e.substring(c,w+3)}),c=w+3}}return n("plain"),t}"var,const,let,function,return,if,else,for,while,do,switch,case,break,continue,new,typeof,instanceof,this,class,extends,import,export,default,from,true,false,null,undefined,try,catch,throw,finally,async,await,yield,of,in,delete,void,with,super,static,get,set,debugger".split(",").forEach(function(e){c[e]=!0});var a={js:o,javascript:o,css:r,html:n};function l(e,t){return function(e){for(var t=[],c=0;c<e.length;c++){var o=e[c];"plain"===o.type?t.push(o.text):t.push({t:"span",a:{class:"bw_ce_"+o.type},c:o.text})}return t}((a[t]||o)(e))}function s(e){var t=(e=e||{}).code||"",c=e.lang||"js",o=e.height||"180px",r=!!e.readOnly,n="bw_ce"+(e.className?" "+e.className:""),a=l(t,c),s={spellcheck:"false",class:"bw_ce_code"};return r||(s.contenteditable="true"),{t:"div",a:{class:n,style:"max-height:"+o+";overflow:auto"},c:[{t:"pre",c:{t:"code",a:s,c:a}}],o:{mounted:function(o){var n=o.querySelector(".bw_ce_code");if(n){var a=t,s=null,i="undefined"!=typeof window&&window.bw||{};o._bwCodeEdit={getValue:p,setValue:function(e){a=e;var t=l(e,c);i.html&&(n.innerHTML=i.html({t:"span",c:t}))}},r||(n.addEventListener("input",function(){clearTimeout(s),s=setTimeout(_,50)}),n.addEventListener("keydown",function(e){"Tab"===e.key&&(e.preventDefault(),document.execCommand("insertText",!1," "))}))}function p(){return n.textContent||""}function _(){var t=p();if(t!==a){a=t;var o=function(e){var t=window.getSelection();if(!t.rangeCount)return 0;var c=t.getRangeAt(0).cloneRange();return c.selectNodeContents(e),c.setEnd(t.getRangeAt(0).startContainer,t.getRangeAt(0).startOffset),c.toString().length}(n),r=l(t,c);i.html&&(n.innerHTML=i.html({t:"span",c:r})),function(e,t){for(var c,o=window.getSelection(),r=document.createRange(),n=document.createTreeWalker(e,NodeFilter.SHOW_TEXT,null,!1),a=0;c=n.nextNode();){var l=c.textContent.length;if(a+l>=t)return r.setStart(c,t-a),r.collapse(!0),o.removeAllRanges(),void o.addRange(r);a+=l}r.selectNodeContents(e),r.collapse(!1),o.removeAllRanges(),o.addRange(r)}(n,o),e.onChange&&e.onChange(t)}}}}}}function i(c){c&&(c.highlight=l,c.codeEditor=function(o){return function(c){e||(e=!0,c&&c.injectCSS&&c.injectCSS(t,{id:"bw_code_edit_styles"}))}(c),s(o)})}"undefined"!=typeof window&&window.bw&&i(window.bw);var p={highlight:l,codeEditor:s,install:i,CSS_TEXT:t};export{t as CSS_TEXT,s as codeEditor,p as default,l as highlight,i as install,r as tokenizeCSS,n as tokenizeHTML,o as tokenizeJS};
|
|
21
|
+
var e=!1,t='.bw_ce{background:var(--bw_code_bg,#1e293b);border-radius:6px;border:1px solid rgba(255,255,255,0.08);overflow:auto}.bw_ce pre{margin:0;padding:0}.bw_ce code{font-family:var(--bw_font_mono,"SF Mono",Monaco,"Cascadia Code",Consolas,monospace);font-size:0.875rem;line-height:1.6;color:var(--bw_code_text,#e2e8f0);outline:none;white-space:pre-wrap;display:block;padding:0.75rem 1rem}.bw_ce code:empty::before{content:"\\200b"}.bw_ce .bw_ce_keyword{color:#c792ea}.bw_ce .bw_ce_string{color:#c3e88d}.bw_ce .bw_ce_comment{color:#546e7a;font-style:italic}.bw_ce .bw_ce_number{color:#f78c6c}.bw_ce .bw_ce_operator{color:#89ddff}.bw_ce .bw_ce_punctuation{color:#89ddff}.bw_ce .bw_ce_property{color:#82aaff}.bw_ce .bw_ce_function{color:#82aaff}.bw_ce .bw_ce_tag{color:#f07178}.bw_ce .bw_ce_attr_name{color:#ffcb6b}.bw_ce .bw_ce_attr_value{color:#c3e88d}.bw_ce .bw_ce_selector{color:#c792ea}.bw_ce .bw_ce_css_prop{color:#82aaff}.bw_ce .bw_ce_css_value{color:#f78c6c}.bw_ce .bw_ce_at_rule{color:#c792ea;font-style:italic}.bw_ce .bw_ce_color{color:#f78c6c}.bw_ce .bw_ce_template_interp{color:#89ddff}.bw_ce_light.bw_ce{background:#fafafa;border-color:#d8d8d8}.bw_ce_light.bw_ce code{color:#1a1a1a}.bw_ce_light.bw_ce .bw_ce_keyword{color:#7c3aed}.bw_ce_light.bw_ce .bw_ce_string{color:#16a34a}.bw_ce_light.bw_ce .bw_ce_comment{color:#9ca3af;font-style:italic}.bw_ce_light.bw_ce .bw_ce_number{color:#ea580c}.bw_ce_light.bw_ce .bw_ce_operator{color:#0891b2}.bw_ce_light.bw_ce .bw_ce_punctuation{color:#6b7280}.bw_ce_light.bw_ce .bw_ce_property{color:#2563eb}.bw_ce_light.bw_ce .bw_ce_function{color:#2563eb}.bw_ce_light.bw_ce .bw_ce_tag{color:#dc2626}.bw_ce_light.bw_ce .bw_ce_attr_name{color:#d97706}.bw_ce_light.bw_ce .bw_ce_attr_value{color:#16a34a}.bw_ce_light.bw_ce .bw_ce_selector{color:#7c3aed}.bw_ce_light.bw_ce .bw_ce_css_prop{color:#2563eb}.bw_ce_light.bw_ce .bw_ce_css_value{color:#ea580c}.bw_ce_light.bw_ce .bw_ce_at_rule{color:#7c3aed}.bw_ce_light.bw_ce .bw_ce_color{color:#ea580c}.bw_ce_light.bw_ce .bw_ce_template_interp{color:#0891b2}.bw_ce_wrap{display:flex;flex-direction:row}.bw_ce_gutter{flex:0 0 auto;padding:0.75rem 0;text-align:right;user-select:none;-webkit-user-select:none;color:#546e7a;font-family:var(--bw_font_mono,"SF Mono",Monaco,"Cascadia Code",Consolas,monospace);font-size:0.875rem;line-height:1.6;border-right:1px solid rgba(255,255,255,0.08);overflow:hidden}.bw_ce_gutter span{display:block;padding:0 0.5rem 0 0.75rem}.bw_ce_light .bw_ce_gutter{color:#9ca3af;border-right-color:#d8d8d8}';var o={};function r(e){var t=[],c=0,n=e.length,a="";function l(e){a.length&&(t.push({type:e,text:a}),a="")}for(;c<n;){var s=e[c],i=e[c+1];if("/"!==s||"/"!==i)if("/"!==s||"*"!==i){if("/"===s&&"/"!==i&&"*"!==i){var p=t.length?t[t.length-1]:null,_=!1;if(a.trim().length||p&&"operator"!==p.type&&"punctuation"!==p.type&&"keyword"!==p.type||(_=!0),_){l("plain");for(var u="/",f=c+1,b=!1,w=!1;f<n;){var d=e[f];if(b)u+=d,b=!1,f++;else if("\\"!==d)if("["!==d)if("]"!==d){if("/"===d&&!w){u+=d,f++;break}if("\n"===d)break;u+=d,f++}else w=!1,u+=d,f++;else w=!0,u+=d,f++;else b=!0,u+=d,f++}for(;f<n&&/[gimsuvy]/.test(e[f]);)u+=e[f],f++;t.push({type:"string",text:u}),c=f;continue}}if('"'!==s&&"'"!==s&&"`"!==s)if(/[0-9]/.test(s)||"."===s&&i&&/[0-9]/.test(i)){l("plain");var h="";if("0"===s&&i&&/[xXbBoO]/.test(i))for(h=s+i,c+=2;c<n&&/[0-9a-fA-F_]/.test(e[c]);)h+=e[c],c++;else for(;c<n&&/[0-9._eE]/.test(e[c]);)"e"!==e[c]&&"E"!==e[c]||!e[c+1]||!/[+\-0-9]/.test(e[c+1])?(h+=e[c],c++):(h+=e[c]+e[c+1],c+=2);t.push({type:"number",text:h})}else if(/[a-zA-Z_$]/.test(s)){l("plain");for(var g="";c<n&&/[a-zA-Z0-9_$]/.test(e[c]);)g+=e[c],c++;for(var v=c;v<n&&(" "===e[v]||"\t"===e[v]);)v++;var y=t.length?t[t.length-1]:null,x=y&&"punctuation"===y.type&&"."===y.text;o[g]?t.push({type:"keyword",text:g}):x?v<n&&"("===e[v]?t.push({type:"function",text:g}):t.push({type:"property",text:g}):v<n&&"("===e[v]?t.push({type:"function",text:g}):t.push({type:"plain",text:g})}else if(-1==="=+-*/%!<>&|^~?:".indexOf(s))-1==="(){}[];,.".indexOf(s)?(a+=s,c++):(l("plain"),t.push({type:"punctuation",text:s}),c++);else{l("plain");var m=s;++c<n&&-1!=="=+-*/%!<>&|^~?:".indexOf(e[c])&&(m+=e[c],++c<n&&-1!=="=>&|".indexOf(e[c])&&(m+=e[c],c++)),t.push({type:"operator",text:m})}else{l("plain");var k=s,C=s,S=c+1;if("`"===k){for(;S<n;){var A=e[S];if("\\"!==A)if("$"!==A||"{"!==e[S+1]){if("`"===A){C+=A,S++;break}C+=A,S++}else{C.length&&t.push({type:"string",text:C}),C="",t.push({type:"template-interp",text:"${"}),S+=2;for(var T=1,E="";S<n&&T>0;){if("{"===e[S])T++;else if("}"===e[S]&&0===--T)break;E+=e[S],S++}var O=r(E);(t=t.concat(O)).push({type:"template-interp",text:"}"}),S++}else C+=A+(e[S+1]||""),S+=2}C.length&&t.push({type:"string",text:C})}else{for(;S<n;){var z=e[S];if("\\"!==z){if(z===k){C+=z,S++;break}if("\n"===z)break;C+=z,S++}else C+=z+(e[S+1]||""),S+=2}t.push({type:"string",text:C})}c=S}}else{l("plain");var R=e.indexOf("*/",c+2);-1===R&&(R=n-2),t.push({type:"comment",text:e.substring(c,R+2)}),c=R+2}else{l("plain");var Z=e.indexOf("\n",c);-1===Z&&(Z=n),t.push({type:"comment",text:e.substring(c,Z)}),c=Z}}return l("plain"),t}function c(e){var t=[],o=0,r=e.length,c="selector",n="";function a(e){n.length&&(t.push({type:e||"plain",text:n}),n="")}for(;o<r;){var l=e[o],s=e[o+1];if("/"!==l||"*"!==s)if('"'!==l&&"'"!==l||"value"!==c&&"selector"!==c)if("@"!==l||"selector"!==c)if("#"!==l||"value"!==c)if("value"===c&&/[0-9]/.test(l)){a("css-value");for(var i="";o<r&&/[0-9.]/.test(e[o]);)i+=e[o],o++;for(var p="";o<r&&/[a-zA-Z%]/.test(e[o]);)p+=e[o],o++;t.push({type:"number",text:i+p})}else"{"!==l?"}"!==l?":"!==l||"prop"!==c?";"!==l?","!==l?(n+=l,o++):(a("selector"===c?"selector":"value"===c?"css-value":"plain"),t.push({type:"punctuation",text:l}),o++):(a("value"===c?"css-value":"plain"),t.push({type:"punctuation",text:l}),c="prop",o++):(a("css-prop"),t.push({type:"punctuation",text:l}),c="value",o++):(a("prop"===c?"css-prop":"value"===c?"css-value":"plain"),t.push({type:"punctuation",text:l}),c="selector",o++):(a("selector"===c?"selector":"plain"),t.push({type:"punctuation",text:l}),c="prop",o++);else{a("css-value");var _="#";for(o++;o<r&&/[0-9a-fA-F]/.test(e[o]);)_+=e[o],o++;t.push({type:"color",text:_})}else{a("selector");var u="@";for(o++;o<r&&/[a-zA-Z\-]/.test(e[o]);)u+=e[o],o++;t.push({type:"at-rule",text:u})}else{a("selector"===c?"selector":"css-value");var f=l,b=l;for(o++;o<r;)if("\\"!==e[o]){if(e[o]===f){b+=e[o],o++;break}b+=e[o],o++}else b+=e[o]+(e[o+1]||""),o+=2;t.push({type:"string",text:b})}else{a("selector"===c?"selector":"prop"===c?"css-prop":"css-value");var w=e.indexOf("*/",o+2);-1===w&&(w=r-2),t.push({type:"comment",text:e.substring(o,w+2)}),o=w+2}}return a("selector"===c?"selector":"prop"===c?"css-prop":"css-value"),t}function n(e){var t=[],o=0,r=e.length,c="";function n(e){c.length&&(t.push({type:e,text:c}),c="")}for(;o<r;){var a=e[o];if("<"!==a||"\x3c!--"!==e.substring(o,o+4))if("<"!==a)if("&"!==a)c+=a,o++;else{n("plain");var l="&";for(o++;o<r&&";"!==e[o]&&/[a-zA-Z0-9#]/.test(e[o]);)l+=e[o],o++;o<r&&";"===e[o]&&(l+=";",o++),t.push({type:"string",text:l})}else{n("plain");var s="<";for(++o<r&&"/"===e[o]&&(s+="/",o++);o<r&&/[a-zA-Z0-9\-]/.test(e[o]);)s+=e[o],o++;for(t.push({type:"tag",text:s});o<r&&">"!==e[o]&&("/"!==e[o]||">"!==e[o+1]);)if(/\s/.test(e[o])){for(var i="";o<r&&/\s/.test(e[o]);)i+=e[o],o++;t.push({type:"plain",text:i})}else if(/[a-zA-Z_\-@:]/.test(e[o])){for(var p="";o<r&&/[a-zA-Z0-9_\-@:]/.test(e[o]);)p+=e[o],o++;if(t.push({type:"attr-name",text:p}),o<r&&"="===e[o])if(t.push({type:"punctuation",text:"="}),++o<r&&('"'===e[o]||"'"===e[o])){var _=e[o],u=_;for(o++;o<r&&e[o]!==_;)u+=e[o],o++;o<r&&(u+=e[o],o++),t.push({type:"attr-value",text:u})}else{for(var f="";o<r&&!/[\s>]/.test(e[o]);)f+=e[o],o++;t.push({type:"attr-value",text:f})}}else c+=e[o],o++,n("plain");var b="";o<r&&"/"===e[o]&&(b+="/",o++),o<r&&">"===e[o]&&(b+=">",o++),b&&t.push({type:"tag",text:b})}else{n("plain");var w=e.indexOf("--\x3e",o+4);-1===w&&(w=r-3),t.push({type:"comment",text:e.substring(o,w+3)}),o=w+3}}return n("plain"),t}"var,const,let,function,return,if,else,for,while,do,switch,case,break,continue,new,typeof,instanceof,this,class,extends,import,export,default,from,true,false,null,undefined,try,catch,throw,finally,async,await,yield,of,in,delete,void,with,super,static,get,set,debugger".split(",").forEach(function(e){o[e]=!0});var a={js:r,javascript:r,css:c,html:n};function l(e,t){return function(e){for(var t=[],o=0;o<e.length;o++){var r=e[o];"plain"===r.type?t.push(r.text):t.push({t:"span",a:{class:"bw_ce_"+r.type},c:r.text})}return t}((a[t]||r)(e))}function s(e){var t=(e=e||{}).code||"",o=e.lang||"js",r=e.height||"180px",c=!!e.readOnly,n=!!e.lineNumbers,a="bw_ce"+(e.className?" "+e.className:""),s=l(t,o),i={spellcheck:"false",class:"bw_ce_code"};c||(i.contenteditable="true");var p=null;if(n){for(var _=(t.match(/\n/g)||[]).length+1,u=[],f=1;f<=_;f++)u.push({t:"span",c:String(f)});p={t:"div",a:{class:"bw_ce_gutter"},c:u}}var b={t:"pre",a:{style:"flex:1;min-width:0;margin:0"},c:{t:"code",a:i,c:s}};return{t:"div",a:{class:a,style:"max-height:"+r+";overflow:auto"},c:[n?{t:"div",a:{class:"bw_ce_wrap"},c:[p,b]}:b],o:{mounted:function(r){var a=r.querySelector(".bw_ce_code");if(a){var s=t,i=null,p=n?r.querySelector(".bw_ce_gutter"):null,_="undefined"!=typeof window&&window.bw||{};if(r._bwCodeEdit={getValue:f,setValue:function(e){s=e;var t=l(e,o);_.html&&(a.innerHTML=_.html({t:"span",c:t})),b(e)}},p){var u=a.closest(".bw_ce")||r;u.addEventListener("scroll",function(){p.style.transform="translateY("+-u.scrollTop+"px)"}),r.addEventListener("scroll",function(){p.style.transform="translateY("+-r.scrollTop+"px)"})}c||(a.addEventListener("input",function(){clearTimeout(i),i=setTimeout(w,50)}),a.addEventListener("keydown",function(e){"Tab"===e.key&&(e.preventDefault(),document.execCommand("insertText",!1," "))}))}function f(){return a.textContent||""}function b(e){if(p){for(var t=(e.match(/\n/g)||[]).length+1,o="",r=1;r<=t;r++)o+="<span>"+r+"</span>";p.innerHTML=o}}function w(){var t=f();if(t!==s){s=t;var r=function(e){var t=window.getSelection();if(!t.rangeCount)return 0;var o=t.getRangeAt(0).cloneRange();return o.selectNodeContents(e),o.setEnd(t.getRangeAt(0).startContainer,t.getRangeAt(0).startOffset),o.toString().length}(a),c=l(t,o);_.html&&(a.innerHTML=_.html({t:"span",c:c})),function(e,t){for(var o,r=window.getSelection(),c=document.createRange(),n=document.createTreeWalker(e,NodeFilter.SHOW_TEXT,null,!1),a=0;o=n.nextNode();){var l=o.textContent.length;if(a+l>=t)return c.setStart(o,t-a),c.collapse(!0),r.removeAllRanges(),void r.addRange(c);a+=l}c.selectNodeContents(e),c.collapse(!1),r.removeAllRanges(),r.addRange(c)}(a,r),b(t),e.onChange&&e.onChange(t)}}}}}}function i(o){o&&(o.highlight=l,o.codeEditor=function(r){return function(o){e||(e=!0,o&&o.injectCSS&&o.injectCSS(t,{id:"bw_code_edit_styles"}))}(o),s(r)})}"undefined"!=typeof window&&window.bw&&i(window.bw);var p={highlight:l,codeEditor:s,install:i,CSS_TEXT:t};export{t as CSS_TEXT,s as codeEditor,p as default,l as highlight,i as install,c as tokenizeCSS,n as tokenizeHTML,r as tokenizeJS};
|
|
15
22
|
//# sourceMappingURL=bitwrench-code-edit.esm.min.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! bitwrench v2.0.
|
|
1
|
+
/*! bitwrench v2.0.17 | BSD-2-Clause | https://deftio.github.com/bitwrench/pages */
|
|
2
2
|
(function (global, factory) {
|
|
3
3
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
4
4
|
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
@@ -11,6 +11,13 @@
|
|
|
11
11
|
* Provides bw.highlight() for tokenizing JS/CSS/HTML into TACO spans,
|
|
12
12
|
* and bw.codeEditor() for a live editable code block with syntax coloring.
|
|
13
13
|
*
|
|
14
|
+
* Theme integration: The editor chrome (background, text color, font) reads
|
|
15
|
+
* from CSS custom properties --bw_code_bg, --bw_code_text, --bw_font_mono,
|
|
16
|
+
* falling back to built-in dark values when no theme is active. Syntax
|
|
17
|
+
* highlighting colors are intentionally fixed (they are a code color scheme,
|
|
18
|
+
* not brand colors). The bw_ce_light class is still supported for manual
|
|
19
|
+
* light-mode override.
|
|
20
|
+
*
|
|
14
21
|
* Can be loaded standalone (browser script tag after bitwrench.umd.js),
|
|
15
22
|
* or imported as an ES module / CJS module.
|
|
16
23
|
*
|
|
@@ -21,9 +28,9 @@
|
|
|
21
28
|
// -- CSS (injected once) ----------------------------------------------
|
|
22
29
|
var _cssInjected = false;
|
|
23
30
|
var CSS_TEXT =
|
|
24
|
-
'.bw_ce{background
|
|
31
|
+
'.bw_ce{background:var(--bw_code_bg,#1e293b);border-radius:6px;border:1px solid rgba(255,255,255,0.08);overflow:auto}' +
|
|
25
32
|
'.bw_ce pre{margin:0;padding:0}' +
|
|
26
|
-
'.bw_ce code{font-family:"SF Mono",Monaco,"Cascadia Code",Consolas,monospace;font-size:0.875rem;line-height:1.6;color
|
|
33
|
+
'.bw_ce code{font-family:var(--bw_font_mono,"SF Mono",Monaco,"Cascadia Code",Consolas,monospace);font-size:0.875rem;line-height:1.6;color:var(--bw_code_text,#e2e8f0);outline:none;white-space:pre-wrap;display:block;padding:0.75rem 1rem}' +
|
|
27
34
|
'.bw_ce code:empty::before{content:"\\200b"}' +
|
|
28
35
|
'.bw_ce .bw_ce_keyword{color:#c792ea}' +
|
|
29
36
|
'.bw_ce .bw_ce_string{color:#c3e88d}' +
|
|
@@ -61,7 +68,12 @@
|
|
|
61
68
|
'.bw_ce_light.bw_ce .bw_ce_css_value{color:#ea580c}' +
|
|
62
69
|
'.bw_ce_light.bw_ce .bw_ce_at_rule{color:#7c3aed}' +
|
|
63
70
|
'.bw_ce_light.bw_ce .bw_ce_color{color:#ea580c}' +
|
|
64
|
-
'.bw_ce_light.bw_ce .bw_ce_template_interp{color:#0891b2}'
|
|
71
|
+
'.bw_ce_light.bw_ce .bw_ce_template_interp{color:#0891b2}' +
|
|
72
|
+
// Line number gutter (opt-in via lineNumbers option)
|
|
73
|
+
'.bw_ce_wrap{display:flex;flex-direction:row}' +
|
|
74
|
+
'.bw_ce_gutter{flex:0 0 auto;padding:0.75rem 0;text-align:right;user-select:none;-webkit-user-select:none;color:#546e7a;font-family:var(--bw_font_mono,"SF Mono",Monaco,"Cascadia Code",Consolas,monospace);font-size:0.875rem;line-height:1.6;border-right:1px solid rgba(255,255,255,0.08);overflow:hidden}' +
|
|
75
|
+
'.bw_ce_gutter span{display:block;padding:0 0.5rem 0 0.75rem}' +
|
|
76
|
+
'.bw_ce_light .bw_ce_gutter{color:#9ca3af;border-right-color:#d8d8d8}';
|
|
65
77
|
|
|
66
78
|
function ensureCSS(bw) {
|
|
67
79
|
if (_cssInjected) return;
|
|
@@ -544,6 +556,7 @@
|
|
|
544
556
|
var lang = opts.lang || 'js';
|
|
545
557
|
var height = opts.height || '180px';
|
|
546
558
|
var readOnly = !!opts.readOnly;
|
|
559
|
+
var showLineNumbers = !!opts.lineNumbers;
|
|
547
560
|
var className = 'bw_ce' + (opts.className ? ' ' + opts.className : '');
|
|
548
561
|
|
|
549
562
|
var highlighted = highlight(code, lang);
|
|
@@ -556,12 +569,26 @@
|
|
|
556
569
|
codeAttrs.contenteditable = 'true';
|
|
557
570
|
}
|
|
558
571
|
|
|
572
|
+
// Build line number gutter TACO if requested
|
|
573
|
+
var gutterTaco = null;
|
|
574
|
+
if (showLineNumbers) {
|
|
575
|
+
var lineCount = (code.match(/\n/g) || []).length + 1;
|
|
576
|
+
var gutterLines = [];
|
|
577
|
+
for (var li = 1; li <= lineCount; li++) {
|
|
578
|
+
gutterLines.push({ t: 'span', c: String(li) });
|
|
579
|
+
}
|
|
580
|
+
gutterTaco = { t: 'div', a: { class: 'bw_ce_gutter' }, c: gutterLines };
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
var preBlock = { t: 'pre', a: { style: 'flex:1;min-width:0;margin:0' }, c: { t: 'code', a: codeAttrs, c: highlighted } };
|
|
584
|
+
var innerContent = showLineNumbers
|
|
585
|
+
? { t: 'div', a: { class: 'bw_ce_wrap' }, c: [gutterTaco, preBlock] }
|
|
586
|
+
: preBlock;
|
|
587
|
+
|
|
559
588
|
return {
|
|
560
589
|
t: 'div',
|
|
561
590
|
a: { class: className, style: 'max-height:' + height + ';overflow:auto' },
|
|
562
|
-
c: [
|
|
563
|
-
{ t: 'pre', c: { t: 'code', a: codeAttrs, c: highlighted } }
|
|
564
|
-
],
|
|
591
|
+
c: [innerContent],
|
|
565
592
|
o: {
|
|
566
593
|
mounted: function(el) {
|
|
567
594
|
var codeEl = el.querySelector('.bw_ce_code');
|
|
@@ -569,21 +596,43 @@
|
|
|
569
596
|
|
|
570
597
|
var currentCode = code;
|
|
571
598
|
var debounceTimer = null;
|
|
599
|
+
var gutterEl = showLineNumbers ? el.querySelector('.bw_ce_gutter') : null;
|
|
572
600
|
|
|
573
601
|
// Resolve bw from global or import context
|
|
574
602
|
var bw = (typeof window !== 'undefined' && window.bw) || {};
|
|
575
603
|
|
|
576
604
|
function getValue() { return codeEl.textContent || ''; }
|
|
577
605
|
|
|
606
|
+
function updateGutter(text) {
|
|
607
|
+
if (!gutterEl) return;
|
|
608
|
+
var count = (text.match(/\n/g) || []).length + 1;
|
|
609
|
+
var html = '';
|
|
610
|
+
for (var i = 1; i <= count; i++) html += '<span>' + i + '</span>';
|
|
611
|
+
gutterEl.innerHTML = html;
|
|
612
|
+
}
|
|
613
|
+
|
|
578
614
|
function setValue(newCode) {
|
|
579
615
|
currentCode = newCode;
|
|
580
616
|
var tacos = highlight(newCode, lang);
|
|
581
617
|
if (bw.html) codeEl.innerHTML = bw.html({ t: 'span', c: tacos });
|
|
618
|
+
updateGutter(newCode);
|
|
582
619
|
}
|
|
583
620
|
|
|
584
621
|
// Expose API on the element
|
|
585
622
|
el._bwCodeEdit = { getValue: getValue, setValue: setValue };
|
|
586
623
|
|
|
624
|
+
// Scroll sync: keep gutter aligned with code
|
|
625
|
+
if (gutterEl) {
|
|
626
|
+
var scrollParent = codeEl.closest('.bw_ce') || el;
|
|
627
|
+
scrollParent.addEventListener('scroll', function() {
|
|
628
|
+
gutterEl.style.transform = 'translateY(' + (-scrollParent.scrollTop) + 'px)';
|
|
629
|
+
});
|
|
630
|
+
// If the outer .bw_ce has overflow, sync from there
|
|
631
|
+
el.addEventListener('scroll', function() {
|
|
632
|
+
gutterEl.style.transform = 'translateY(' + (-el.scrollTop) + 'px)';
|
|
633
|
+
});
|
|
634
|
+
}
|
|
635
|
+
|
|
587
636
|
if (readOnly) return;
|
|
588
637
|
|
|
589
638
|
function rehighlight() {
|
|
@@ -594,6 +643,7 @@
|
|
|
594
643
|
var tacos = highlight(newCode, lang);
|
|
595
644
|
if (bw.html) codeEl.innerHTML = bw.html({ t: 'span', c: tacos });
|
|
596
645
|
setCaretOffset(codeEl, offset);
|
|
646
|
+
updateGutter(newCode);
|
|
597
647
|
if (opts.onChange) opts.onChange(newCode);
|
|
598
648
|
}
|
|
599
649
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! bitwrench v2.0.
|
|
1
|
+
/*! bitwrench v2.0.17 | BSD-2-Clause | https://deftio.github.com/bitwrench/pages */
|
|
2
2
|
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).bwCodeEdit={})}(this,function(e){"use strict";
|
|
3
3
|
/**
|
|
4
4
|
* bitwrench-code-edit.js - syntax-highlighted contenteditable code editor addon
|
|
@@ -6,10 +6,17 @@
|
|
|
6
6
|
* Provides bw.highlight() for tokenizing JS/CSS/HTML into TACO spans,
|
|
7
7
|
* and bw.codeEditor() for a live editable code block with syntax coloring.
|
|
8
8
|
*
|
|
9
|
+
* Theme integration: The editor chrome (background, text color, font) reads
|
|
10
|
+
* from CSS custom properties --bw_code_bg, --bw_code_text, --bw_font_mono,
|
|
11
|
+
* falling back to built-in dark values when no theme is active. Syntax
|
|
12
|
+
* highlighting colors are intentionally fixed (they are a code color scheme,
|
|
13
|
+
* not brand colors). The bw_ce_light class is still supported for manual
|
|
14
|
+
* light-mode override.
|
|
15
|
+
*
|
|
9
16
|
* Can be loaded standalone (browser script tag after bitwrench.umd.js),
|
|
10
17
|
* or imported as an ES module / CJS module.
|
|
11
18
|
*
|
|
12
19
|
* @module bitwrench-code-edit
|
|
13
20
|
* @license BSD-2-Clause
|
|
14
|
-
*/var t=!1,o='.bw_ce{background:#1e293b;border-radius:6px;border:1px solid rgba(255,255,255,0.08);overflow:auto}.bw_ce pre{margin:0;padding:0}.bw_ce code{font-family:"SF Mono",Monaco,"Cascadia Code",Consolas,monospace;font-size:0.875rem;line-height:1.6;color:#e2e8f0;outline:none;white-space:pre-wrap;display:block;padding:0.75rem 1rem}.bw_ce code:empty::before{content:"\\200b"}.bw_ce .bw_ce_keyword{color:#c792ea}.bw_ce .bw_ce_string{color:#c3e88d}.bw_ce .bw_ce_comment{color:#546e7a;font-style:italic}.bw_ce .bw_ce_number{color:#f78c6c}.bw_ce .bw_ce_operator{color:#89ddff}.bw_ce .bw_ce_punctuation{color:#89ddff}.bw_ce .bw_ce_property{color:#82aaff}.bw_ce .bw_ce_function{color:#82aaff}.bw_ce .bw_ce_tag{color:#f07178}.bw_ce .bw_ce_attr_name{color:#ffcb6b}.bw_ce .bw_ce_attr_value{color:#c3e88d}.bw_ce .bw_ce_selector{color:#c792ea}.bw_ce .bw_ce_css_prop{color:#82aaff}.bw_ce .bw_ce_css_value{color:#f78c6c}.bw_ce .bw_ce_at_rule{color:#c792ea;font-style:italic}.bw_ce .bw_ce_color{color:#f78c6c}.bw_ce .bw_ce_template_interp{color:#89ddff}.bw_ce_light.bw_ce{background:#fafafa;border-color:#d8d8d8}.bw_ce_light.bw_ce code{color:#1a1a1a}.bw_ce_light.bw_ce .bw_ce_keyword{color:#7c3aed}.bw_ce_light.bw_ce .bw_ce_string{color:#16a34a}.bw_ce_light.bw_ce .bw_ce_comment{color:#9ca3af;font-style:italic}.bw_ce_light.bw_ce .bw_ce_number{color:#ea580c}.bw_ce_light.bw_ce .bw_ce_operator{color:#0891b2}.bw_ce_light.bw_ce .bw_ce_punctuation{color:#6b7280}.bw_ce_light.bw_ce .bw_ce_property{color:#2563eb}.bw_ce_light.bw_ce .bw_ce_function{color:#2563eb}.bw_ce_light.bw_ce .bw_ce_tag{color:#dc2626}.bw_ce_light.bw_ce .bw_ce_attr_name{color:#d97706}.bw_ce_light.bw_ce .bw_ce_attr_value{color:#16a34a}.bw_ce_light.bw_ce .bw_ce_selector{color:#7c3aed}.bw_ce_light.bw_ce .bw_ce_css_prop{color:#2563eb}.bw_ce_light.bw_ce .bw_ce_css_value{color:#ea580c}.bw_ce_light.bw_ce .bw_ce_at_rule{color:#7c3aed}.bw_ce_light.bw_ce .bw_ce_color{color:#ea580c}.bw_ce_light.bw_ce .bw_ce_template_interp{color:#0891b2}';var c={};function r(e){var t=[],o=0,n=e.length,a="";function l(e){a.length&&(t.push({type:e,text:a}),a="")}for(;o<n;){var i=e[o],s=e[o+1];if("/"!==i||"/"!==s)if("/"!==i||"*"!==s){if("/"===i&&"/"!==s&&"*"!==s){var p=t.length?t[t.length-1]:null,_=!1;if(a.trim().length||p&&"operator"!==p.type&&"punctuation"!==p.type&&"keyword"!==p.type||(_=!0),_){l("plain");for(var u="/",f=o+1,b=!1,w=!1;f<n;){var d=e[f];if(b)u+=d,b=!1,f++;else if("\\"!==d)if("["!==d)if("]"!==d){if("/"===d&&!w){u+=d,f++;break}if("\n"===d)break;u+=d,f++}else w=!1,u+=d,f++;else w=!0,u+=d,f++;else b=!0,u+=d,f++}for(;f<n&&/[gimsuvy]/.test(e[f]);)u+=e[f],f++;t.push({type:"string",text:u}),o=f;continue}}if('"'!==i&&"'"!==i&&"`"!==i)if(/[0-9]/.test(i)||"."===i&&s&&/[0-9]/.test(s)){l("plain");var h="";if("0"===i&&s&&/[xXbBoO]/.test(s))for(h=i+s,o+=2;o<n&&/[0-9a-fA-F_]/.test(e[o]);)h+=e[o],o++;else for(;o<n&&/[0-9._eE]/.test(e[o]);)"e"!==e[o]&&"E"!==e[o]||!e[o+1]||!/[+\-0-9]/.test(e[o+1])?(h+=e[o],o++):(h+=e[o]+e[o+1],o+=2);t.push({type:"number",text:h})}else if(/[a-zA-Z_$]/.test(i)){l("plain");for(var g="";o<n&&/[a-zA-Z0-9_$]/.test(e[o]);)g+=e[o],o++;for(var v=o;v<n&&(" "===e[v]||"\t"===e[v]);)v++;var y=t.length?t[t.length-1]:null,x=y&&"punctuation"===y.type&&"."===y.text;c[g]?t.push({type:"keyword",text:g}):x?v<n&&"("===e[v]?t.push({type:"function",text:g}):t.push({type:"property",text:g}):v<n&&"("===e[v]?t.push({type:"function",text:g}):t.push({type:"plain",text:g})}else if(-1==="=+-*/%!<>&|^~?:".indexOf(i))-1==="(){}[];,.".indexOf(i)?(a+=i,o++):(l("plain"),t.push({type:"punctuation",text:i}),o++);else{l("plain");var m=i;++o<n&&-1!=="=+-*/%!<>&|^~?:".indexOf(e[o])&&(m+=e[o],++o<n&&-1!=="=>&|".indexOf(e[o])&&(m+=e[o],o++)),t.push({type:"operator",text:m})}else{l("plain");var k=i,C=i,S=o+1;if("`"===k){for(;S<n;){var T=e[S];if("\\"!==T)if("$"!==T||"{"!==e[S+1]){if("`"===T){C+=T,S++;break}C+=T,S++}else{C.length&&t.push({type:"string",text:C}),C="",t.push({type:"template-interp",text:"${"}),S+=2;for(var A=1,E="";S<n&&A>0;){if("{"===e[S])A++;else if("}"===e[S]&&0===--A)break;E+=e[S],S++}var O=r(E);(t=t.concat(O)).push({type:"template-interp",text:"}"}),S++}else C+=T+(e[S+1]||""),S+=2}C.length&&t.push({type:"string",text:C})}else{for(;S<n;){var z=e[S];if("\\"!==z){if(z===k){C+=z,S++;break}if("\n"===z)break;C+=z,S++}else C+=z+(e[S+1]||""),S+=2}t.push({type:"string",text:C})}o=S}}else{l("plain");var R=e.indexOf("*/",o+2);-1===R&&(R=n-2),t.push({type:"comment",text:e.substring(o,R+2)}),o=R+2}else{l("plain");var Z=e.indexOf("\n",o);-1===Z&&(Z=n),t.push({type:"comment",text:e.substring(o,Z)}),o=Z}}return l("plain"),t}function n(e){var t=[],o=0,c=e.length,r="selector",n="";function a(e){n.length&&(t.push({type:e||"plain",text:n}),n="")}for(;o<c;){var l=e[o],i=e[o+1];if("/"!==l||"*"!==i)if('"'!==l&&"'"!==l||"value"!==r&&"selector"!==r)if("@"!==l||"selector"!==r)if("#"!==l||"value"!==r)if("value"===r&&/[0-9]/.test(l)){a("css-value");for(var s="";o<c&&/[0-9.]/.test(e[o]);)s+=e[o],o++;for(var p="";o<c&&/[a-zA-Z%]/.test(e[o]);)p+=e[o],o++;t.push({type:"number",text:s+p})}else"{"!==l?"}"!==l?":"!==l||"prop"!==r?";"!==l?","!==l?(n+=l,o++):(a("selector"===r?"selector":"value"===r?"css-value":"plain"),t.push({type:"punctuation",text:l}),o++):(a("value"===r?"css-value":"plain"),t.push({type:"punctuation",text:l}),r="prop",o++):(a("css-prop"),t.push({type:"punctuation",text:l}),r="value",o++):(a("prop"===r?"css-prop":"value"===r?"css-value":"plain"),t.push({type:"punctuation",text:l}),r="selector",o++):(a("selector"===r?"selector":"plain"),t.push({type:"punctuation",text:l}),r="prop",o++);else{a("css-value");var _="#";for(o++;o<c&&/[0-9a-fA-F]/.test(e[o]);)_+=e[o],o++;t.push({type:"color",text:_})}else{a("selector");var u="@";for(o++;o<c&&/[a-zA-Z\-]/.test(e[o]);)u+=e[o],o++;t.push({type:"at-rule",text:u})}else{a("selector"===r?"selector":"css-value");var f=l,b=l;for(o++;o<c;)if("\\"!==e[o]){if(e[o]===f){b+=e[o],o++;break}b+=e[o],o++}else b+=e[o]+(e[o+1]||""),o+=2;t.push({type:"string",text:b})}else{a("selector"===r?"selector":"prop"===r?"css-prop":"css-value");var w=e.indexOf("*/",o+2);-1===w&&(w=c-2),t.push({type:"comment",text:e.substring(o,w+2)}),o=w+2}}return a("selector"===r?"selector":"prop"===r?"css-prop":"css-value"),t}function a(e){var t=[],o=0,c=e.length,r="";function n(e){r.length&&(t.push({type:e,text:r}),r="")}for(;o<c;){var a=e[o];if("<"!==a||"\x3c!--"!==e.substring(o,o+4))if("<"!==a)if("&"!==a)r+=a,o++;else{n("plain");var l="&";for(o++;o<c&&";"!==e[o]&&/[a-zA-Z0-9#]/.test(e[o]);)l+=e[o],o++;o<c&&";"===e[o]&&(l+=";",o++),t.push({type:"string",text:l})}else{n("plain");var i="<";for(++o<c&&"/"===e[o]&&(i+="/",o++);o<c&&/[a-zA-Z0-9\-]/.test(e[o]);)i+=e[o],o++;for(t.push({type:"tag",text:i});o<c&&">"!==e[o]&&("/"!==e[o]||">"!==e[o+1]);)if(/\s/.test(e[o])){for(var s="";o<c&&/\s/.test(e[o]);)s+=e[o],o++;t.push({type:"plain",text:s})}else if(/[a-zA-Z_\-@:]/.test(e[o])){for(var p="";o<c&&/[a-zA-Z0-9_\-@:]/.test(e[o]);)p+=e[o],o++;if(t.push({type:"attr-name",text:p}),o<c&&"="===e[o])if(t.push({type:"punctuation",text:"="}),++o<c&&('"'===e[o]||"'"===e[o])){var _=e[o],u=_;for(o++;o<c&&e[o]!==_;)u+=e[o],o++;o<c&&(u+=e[o],o++),t.push({type:"attr-value",text:u})}else{for(var f="";o<c&&!/[\s>]/.test(e[o]);)f+=e[o],o++;t.push({type:"attr-value",text:f})}}else r+=e[o],o++,n("plain");var b="";o<c&&"/"===e[o]&&(b+="/",o++),o<c&&">"===e[o]&&(b+=">",o++),b&&t.push({type:"tag",text:b})}else{n("plain");var w=e.indexOf("--\x3e",o+4);-1===w&&(w=c-3),t.push({type:"comment",text:e.substring(o,w+3)}),o=w+3}}return n("plain"),t}"var,const,let,function,return,if,else,for,while,do,switch,case,break,continue,new,typeof,instanceof,this,class,extends,import,export,default,from,true,false,null,undefined,try,catch,throw,finally,async,await,yield,of,in,delete,void,with,super,static,get,set,debugger".split(",").forEach(function(e){c[e]=!0});var l={js:r,javascript:r,css:n,html:a};function i(e,t){return function(e){for(var t=[],o=0;o<e.length;o++){var c=e[o];"plain"===c.type?t.push(c.text):t.push({t:"span",a:{class:"bw_ce_"+c.type},c:c.text})}return t}((l[t]||r)(e))}function s(e){var t=(e=e||{}).code||"",o=e.lang||"js",c=e.height||"180px",r=!!e.readOnly,n="bw_ce"+(e.className?" "+e.className:""),a=i(t,o),l={spellcheck:"false",class:"bw_ce_code"};return r||(l.contenteditable="true"),{t:"div",a:{class:n,style:"max-height:"+c+";overflow:auto"},c:[{t:"pre",c:{t:"code",a:l,c:a}}],o:{mounted:function(c){var n=c.querySelector(".bw_ce_code");if(n){var a=t,l=null,s="undefined"!=typeof window&&window.bw||{};c._bwCodeEdit={getValue:p,setValue:function(e){a=e;var t=i(e,o);s.html&&(n.innerHTML=s.html({t:"span",c:t}))}},r||(n.addEventListener("input",function(){clearTimeout(l),l=setTimeout(_,50)}),n.addEventListener("keydown",function(e){"Tab"===e.key&&(e.preventDefault(),document.execCommand("insertText",!1," "))}))}function p(){return n.textContent||""}function _(){var t=p();if(t!==a){a=t;var c=function(e){var t=window.getSelection();if(!t.rangeCount)return 0;var o=t.getRangeAt(0).cloneRange();return o.selectNodeContents(e),o.setEnd(t.getRangeAt(0).startContainer,t.getRangeAt(0).startOffset),o.toString().length}(n),r=i(t,o);s.html&&(n.innerHTML=s.html({t:"span",c:r})),function(e,t){for(var o,c=window.getSelection(),r=document.createRange(),n=document.createTreeWalker(e,NodeFilter.SHOW_TEXT,null,!1),a=0;o=n.nextNode();){var l=o.textContent.length;if(a+l>=t)return r.setStart(o,t-a),r.collapse(!0),c.removeAllRanges(),void c.addRange(r);a+=l}r.selectNodeContents(e),r.collapse(!1),c.removeAllRanges(),c.addRange(r)}(n,c),e.onChange&&e.onChange(t)}}}}}}function p(e){e&&(e.highlight=i,e.codeEditor=function(c){return function(e){t||(t=!0,e&&e.injectCSS&&e.injectCSS(o,{id:"bw_code_edit_styles"}))}(e),s(c)})}"undefined"!=typeof window&&window.bw&&p(window.bw);var _={highlight:i,codeEditor:s,install:p,CSS_TEXT:o};e.CSS_TEXT=o,e.codeEditor=s,e.default=_,e.highlight=i,e.install=p,e.tokenizeCSS=n,e.tokenizeHTML=a,e.tokenizeJS=r,Object.defineProperty(e,"__esModule",{value:!0})});
|
|
21
|
+
*/var t=!1,o='.bw_ce{background:var(--bw_code_bg,#1e293b);border-radius:6px;border:1px solid rgba(255,255,255,0.08);overflow:auto}.bw_ce pre{margin:0;padding:0}.bw_ce code{font-family:var(--bw_font_mono,"SF Mono",Monaco,"Cascadia Code",Consolas,monospace);font-size:0.875rem;line-height:1.6;color:var(--bw_code_text,#e2e8f0);outline:none;white-space:pre-wrap;display:block;padding:0.75rem 1rem}.bw_ce code:empty::before{content:"\\200b"}.bw_ce .bw_ce_keyword{color:#c792ea}.bw_ce .bw_ce_string{color:#c3e88d}.bw_ce .bw_ce_comment{color:#546e7a;font-style:italic}.bw_ce .bw_ce_number{color:#f78c6c}.bw_ce .bw_ce_operator{color:#89ddff}.bw_ce .bw_ce_punctuation{color:#89ddff}.bw_ce .bw_ce_property{color:#82aaff}.bw_ce .bw_ce_function{color:#82aaff}.bw_ce .bw_ce_tag{color:#f07178}.bw_ce .bw_ce_attr_name{color:#ffcb6b}.bw_ce .bw_ce_attr_value{color:#c3e88d}.bw_ce .bw_ce_selector{color:#c792ea}.bw_ce .bw_ce_css_prop{color:#82aaff}.bw_ce .bw_ce_css_value{color:#f78c6c}.bw_ce .bw_ce_at_rule{color:#c792ea;font-style:italic}.bw_ce .bw_ce_color{color:#f78c6c}.bw_ce .bw_ce_template_interp{color:#89ddff}.bw_ce_light.bw_ce{background:#fafafa;border-color:#d8d8d8}.bw_ce_light.bw_ce code{color:#1a1a1a}.bw_ce_light.bw_ce .bw_ce_keyword{color:#7c3aed}.bw_ce_light.bw_ce .bw_ce_string{color:#16a34a}.bw_ce_light.bw_ce .bw_ce_comment{color:#9ca3af;font-style:italic}.bw_ce_light.bw_ce .bw_ce_number{color:#ea580c}.bw_ce_light.bw_ce .bw_ce_operator{color:#0891b2}.bw_ce_light.bw_ce .bw_ce_punctuation{color:#6b7280}.bw_ce_light.bw_ce .bw_ce_property{color:#2563eb}.bw_ce_light.bw_ce .bw_ce_function{color:#2563eb}.bw_ce_light.bw_ce .bw_ce_tag{color:#dc2626}.bw_ce_light.bw_ce .bw_ce_attr_name{color:#d97706}.bw_ce_light.bw_ce .bw_ce_attr_value{color:#16a34a}.bw_ce_light.bw_ce .bw_ce_selector{color:#7c3aed}.bw_ce_light.bw_ce .bw_ce_css_prop{color:#2563eb}.bw_ce_light.bw_ce .bw_ce_css_value{color:#ea580c}.bw_ce_light.bw_ce .bw_ce_at_rule{color:#7c3aed}.bw_ce_light.bw_ce .bw_ce_color{color:#ea580c}.bw_ce_light.bw_ce .bw_ce_template_interp{color:#0891b2}.bw_ce_wrap{display:flex;flex-direction:row}.bw_ce_gutter{flex:0 0 auto;padding:0.75rem 0;text-align:right;user-select:none;-webkit-user-select:none;color:#546e7a;font-family:var(--bw_font_mono,"SF Mono",Monaco,"Cascadia Code",Consolas,monospace);font-size:0.875rem;line-height:1.6;border-right:1px solid rgba(255,255,255,0.08);overflow:hidden}.bw_ce_gutter span{display:block;padding:0 0.5rem 0 0.75rem}.bw_ce_light .bw_ce_gutter{color:#9ca3af;border-right-color:#d8d8d8}';var r={};function c(e){var t=[],o=0,n=e.length,a="";function l(e){a.length&&(t.push({type:e,text:a}),a="")}for(;o<n;){var i=e[o],s=e[o+1];if("/"!==i||"/"!==s)if("/"!==i||"*"!==s){if("/"===i&&"/"!==s&&"*"!==s){var p=t.length?t[t.length-1]:null,_=!1;if(a.trim().length||p&&"operator"!==p.type&&"punctuation"!==p.type&&"keyword"!==p.type||(_=!0),_){l("plain");for(var u="/",f=o+1,b=!1,w=!1;f<n;){var d=e[f];if(b)u+=d,b=!1,f++;else if("\\"!==d)if("["!==d)if("]"!==d){if("/"===d&&!w){u+=d,f++;break}if("\n"===d)break;u+=d,f++}else w=!1,u+=d,f++;else w=!0,u+=d,f++;else b=!0,u+=d,f++}for(;f<n&&/[gimsuvy]/.test(e[f]);)u+=e[f],f++;t.push({type:"string",text:u}),o=f;continue}}if('"'!==i&&"'"!==i&&"`"!==i)if(/[0-9]/.test(i)||"."===i&&s&&/[0-9]/.test(s)){l("plain");var h="";if("0"===i&&s&&/[xXbBoO]/.test(s))for(h=i+s,o+=2;o<n&&/[0-9a-fA-F_]/.test(e[o]);)h+=e[o],o++;else for(;o<n&&/[0-9._eE]/.test(e[o]);)"e"!==e[o]&&"E"!==e[o]||!e[o+1]||!/[+\-0-9]/.test(e[o+1])?(h+=e[o],o++):(h+=e[o]+e[o+1],o+=2);t.push({type:"number",text:h})}else if(/[a-zA-Z_$]/.test(i)){l("plain");for(var g="";o<n&&/[a-zA-Z0-9_$]/.test(e[o]);)g+=e[o],o++;for(var v=o;v<n&&(" "===e[v]||"\t"===e[v]);)v++;var y=t.length?t[t.length-1]:null,x=y&&"punctuation"===y.type&&"."===y.text;r[g]?t.push({type:"keyword",text:g}):x?v<n&&"("===e[v]?t.push({type:"function",text:g}):t.push({type:"property",text:g}):v<n&&"("===e[v]?t.push({type:"function",text:g}):t.push({type:"plain",text:g})}else if(-1==="=+-*/%!<>&|^~?:".indexOf(i))-1==="(){}[];,.".indexOf(i)?(a+=i,o++):(l("plain"),t.push({type:"punctuation",text:i}),o++);else{l("plain");var m=i;++o<n&&-1!=="=+-*/%!<>&|^~?:".indexOf(e[o])&&(m+=e[o],++o<n&&-1!=="=>&|".indexOf(e[o])&&(m+=e[o],o++)),t.push({type:"operator",text:m})}else{l("plain");var k=i,C=i,S=o+1;if("`"===k){for(;S<n;){var T=e[S];if("\\"!==T)if("$"!==T||"{"!==e[S+1]){if("`"===T){C+=T,S++;break}C+=T,S++}else{C.length&&t.push({type:"string",text:C}),C="",t.push({type:"template-interp",text:"${"}),S+=2;for(var E=1,A="";S<n&&E>0;){if("{"===e[S])E++;else if("}"===e[S]&&0===--E)break;A+=e[S],S++}var z=c(A);(t=t.concat(z)).push({type:"template-interp",text:"}"}),S++}else C+=T+(e[S+1]||""),S+=2}C.length&&t.push({type:"string",text:C})}else{for(;S<n;){var O=e[S];if("\\"!==O){if(O===k){C+=O,S++;break}if("\n"===O)break;C+=O,S++}else C+=O+(e[S+1]||""),S+=2}t.push({type:"string",text:C})}o=S}}else{l("plain");var M=e.indexOf("*/",o+2);-1===M&&(M=n-2),t.push({type:"comment",text:e.substring(o,M+2)}),o=M+2}else{l("plain");var R=e.indexOf("\n",o);-1===R&&(R=n),t.push({type:"comment",text:e.substring(o,R)}),o=R}}return l("plain"),t}function n(e){var t=[],o=0,r=e.length,c="selector",n="";function a(e){n.length&&(t.push({type:e||"plain",text:n}),n="")}for(;o<r;){var l=e[o],i=e[o+1];if("/"!==l||"*"!==i)if('"'!==l&&"'"!==l||"value"!==c&&"selector"!==c)if("@"!==l||"selector"!==c)if("#"!==l||"value"!==c)if("value"===c&&/[0-9]/.test(l)){a("css-value");for(var s="";o<r&&/[0-9.]/.test(e[o]);)s+=e[o],o++;for(var p="";o<r&&/[a-zA-Z%]/.test(e[o]);)p+=e[o],o++;t.push({type:"number",text:s+p})}else"{"!==l?"}"!==l?":"!==l||"prop"!==c?";"!==l?","!==l?(n+=l,o++):(a("selector"===c?"selector":"value"===c?"css-value":"plain"),t.push({type:"punctuation",text:l}),o++):(a("value"===c?"css-value":"plain"),t.push({type:"punctuation",text:l}),c="prop",o++):(a("css-prop"),t.push({type:"punctuation",text:l}),c="value",o++):(a("prop"===c?"css-prop":"value"===c?"css-value":"plain"),t.push({type:"punctuation",text:l}),c="selector",o++):(a("selector"===c?"selector":"plain"),t.push({type:"punctuation",text:l}),c="prop",o++);else{a("css-value");var _="#";for(o++;o<r&&/[0-9a-fA-F]/.test(e[o]);)_+=e[o],o++;t.push({type:"color",text:_})}else{a("selector");var u="@";for(o++;o<r&&/[a-zA-Z\-]/.test(e[o]);)u+=e[o],o++;t.push({type:"at-rule",text:u})}else{a("selector"===c?"selector":"css-value");var f=l,b=l;for(o++;o<r;)if("\\"!==e[o]){if(e[o]===f){b+=e[o],o++;break}b+=e[o],o++}else b+=e[o]+(e[o+1]||""),o+=2;t.push({type:"string",text:b})}else{a("selector"===c?"selector":"prop"===c?"css-prop":"css-value");var w=e.indexOf("*/",o+2);-1===w&&(w=r-2),t.push({type:"comment",text:e.substring(o,w+2)}),o=w+2}}return a("selector"===c?"selector":"prop"===c?"css-prop":"css-value"),t}function a(e){var t=[],o=0,r=e.length,c="";function n(e){c.length&&(t.push({type:e,text:c}),c="")}for(;o<r;){var a=e[o];if("<"!==a||"\x3c!--"!==e.substring(o,o+4))if("<"!==a)if("&"!==a)c+=a,o++;else{n("plain");var l="&";for(o++;o<r&&";"!==e[o]&&/[a-zA-Z0-9#]/.test(e[o]);)l+=e[o],o++;o<r&&";"===e[o]&&(l+=";",o++),t.push({type:"string",text:l})}else{n("plain");var i="<";for(++o<r&&"/"===e[o]&&(i+="/",o++);o<r&&/[a-zA-Z0-9\-]/.test(e[o]);)i+=e[o],o++;for(t.push({type:"tag",text:i});o<r&&">"!==e[o]&&("/"!==e[o]||">"!==e[o+1]);)if(/\s/.test(e[o])){for(var s="";o<r&&/\s/.test(e[o]);)s+=e[o],o++;t.push({type:"plain",text:s})}else if(/[a-zA-Z_\-@:]/.test(e[o])){for(var p="";o<r&&/[a-zA-Z0-9_\-@:]/.test(e[o]);)p+=e[o],o++;if(t.push({type:"attr-name",text:p}),o<r&&"="===e[o])if(t.push({type:"punctuation",text:"="}),++o<r&&('"'===e[o]||"'"===e[o])){var _=e[o],u=_;for(o++;o<r&&e[o]!==_;)u+=e[o],o++;o<r&&(u+=e[o],o++),t.push({type:"attr-value",text:u})}else{for(var f="";o<r&&!/[\s>]/.test(e[o]);)f+=e[o],o++;t.push({type:"attr-value",text:f})}}else c+=e[o],o++,n("plain");var b="";o<r&&"/"===e[o]&&(b+="/",o++),o<r&&">"===e[o]&&(b+=">",o++),b&&t.push({type:"tag",text:b})}else{n("plain");var w=e.indexOf("--\x3e",o+4);-1===w&&(w=r-3),t.push({type:"comment",text:e.substring(o,w+3)}),o=w+3}}return n("plain"),t}"var,const,let,function,return,if,else,for,while,do,switch,case,break,continue,new,typeof,instanceof,this,class,extends,import,export,default,from,true,false,null,undefined,try,catch,throw,finally,async,await,yield,of,in,delete,void,with,super,static,get,set,debugger".split(",").forEach(function(e){r[e]=!0});var l={js:c,javascript:c,css:n,html:a};function i(e,t){return function(e){for(var t=[],o=0;o<e.length;o++){var r=e[o];"plain"===r.type?t.push(r.text):t.push({t:"span",a:{class:"bw_ce_"+r.type},c:r.text})}return t}((l[t]||c)(e))}function s(e){var t=(e=e||{}).code||"",o=e.lang||"js",r=e.height||"180px",c=!!e.readOnly,n=!!e.lineNumbers,a="bw_ce"+(e.className?" "+e.className:""),l=i(t,o),s={spellcheck:"false",class:"bw_ce_code"};c||(s.contenteditable="true");var p=null;if(n){for(var _=(t.match(/\n/g)||[]).length+1,u=[],f=1;f<=_;f++)u.push({t:"span",c:String(f)});p={t:"div",a:{class:"bw_ce_gutter"},c:u}}var b={t:"pre",a:{style:"flex:1;min-width:0;margin:0"},c:{t:"code",a:s,c:l}};return{t:"div",a:{class:a,style:"max-height:"+r+";overflow:auto"},c:[n?{t:"div",a:{class:"bw_ce_wrap"},c:[p,b]}:b],o:{mounted:function(r){var a=r.querySelector(".bw_ce_code");if(a){var l=t,s=null,p=n?r.querySelector(".bw_ce_gutter"):null,_="undefined"!=typeof window&&window.bw||{};if(r._bwCodeEdit={getValue:f,setValue:function(e){l=e;var t=i(e,o);_.html&&(a.innerHTML=_.html({t:"span",c:t})),b(e)}},p){var u=a.closest(".bw_ce")||r;u.addEventListener("scroll",function(){p.style.transform="translateY("+-u.scrollTop+"px)"}),r.addEventListener("scroll",function(){p.style.transform="translateY("+-r.scrollTop+"px)"})}c||(a.addEventListener("input",function(){clearTimeout(s),s=setTimeout(w,50)}),a.addEventListener("keydown",function(e){"Tab"===e.key&&(e.preventDefault(),document.execCommand("insertText",!1," "))}))}function f(){return a.textContent||""}function b(e){if(p){for(var t=(e.match(/\n/g)||[]).length+1,o="",r=1;r<=t;r++)o+="<span>"+r+"</span>";p.innerHTML=o}}function w(){var t=f();if(t!==l){l=t;var r=function(e){var t=window.getSelection();if(!t.rangeCount)return 0;var o=t.getRangeAt(0).cloneRange();return o.selectNodeContents(e),o.setEnd(t.getRangeAt(0).startContainer,t.getRangeAt(0).startOffset),o.toString().length}(a),c=i(t,o);_.html&&(a.innerHTML=_.html({t:"span",c:c})),function(e,t){for(var o,r=window.getSelection(),c=document.createRange(),n=document.createTreeWalker(e,NodeFilter.SHOW_TEXT,null,!1),a=0;o=n.nextNode();){var l=o.textContent.length;if(a+l>=t)return c.setStart(o,t-a),c.collapse(!0),r.removeAllRanges(),void r.addRange(c);a+=l}c.selectNodeContents(e),c.collapse(!1),r.removeAllRanges(),r.addRange(c)}(a,r),b(t),e.onChange&&e.onChange(t)}}}}}}function p(e){e&&(e.highlight=i,e.codeEditor=function(r){return function(e){t||(t=!0,e&&e.injectCSS&&e.injectCSS(o,{id:"bw_code_edit_styles"}))}(e),s(r)})}"undefined"!=typeof window&&window.bw&&p(window.bw);var _={highlight:i,codeEditor:s,install:p,CSS_TEXT:o};e.CSS_TEXT=o,e.codeEditor=s,e.default=_,e.highlight=i,e.install=p,e.tokenizeCSS=n,e.tokenizeHTML=a,e.tokenizeJS=c,Object.defineProperty(e,"__esModule",{value:!0})});
|
|
15
22
|
//# sourceMappingURL=bitwrench-code-edit.umd.min.js.map
|