bitwrench 1.2.16 → 2.0.7

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.
Files changed (130) hide show
  1. package/README.md +160 -158
  2. package/bin/bitwrench.js +3 -0
  3. package/dist/bitwrench-code-edit.cjs.js +639 -0
  4. package/dist/bitwrench-code-edit.es5.js +875 -0
  5. package/dist/bitwrench-code-edit.es5.min.js +15 -0
  6. package/dist/bitwrench-code-edit.esm.js +628 -0
  7. package/dist/bitwrench-code-edit.esm.min.js +15 -0
  8. package/dist/bitwrench-code-edit.umd.js +645 -0
  9. package/dist/bitwrench-code-edit.umd.min.js +15 -0
  10. package/dist/bitwrench.cjs.js +6983 -0
  11. package/dist/bitwrench.cjs.min.js +62 -0
  12. package/dist/bitwrench.css +5100 -0
  13. package/dist/bitwrench.es5.js +8446 -0
  14. package/dist/bitwrench.es5.min.js +31 -0
  15. package/dist/bitwrench.esm.js +6981 -0
  16. package/dist/bitwrench.esm.min.js +62 -0
  17. package/dist/bitwrench.umd.js +6989 -0
  18. package/dist/bitwrench.umd.min.js +62 -0
  19. package/dist/builds.json +127 -0
  20. package/dist/sri.json +18 -0
  21. package/package.json +86 -24
  22. package/readme.html +288 -0
  23. package/src/bitwrench-code-edit.js +627 -0
  24. package/src/bitwrench-color-utils.js +311 -0
  25. package/src/bitwrench-component-base.js +736 -0
  26. package/src/bitwrench-components-inline.js +374 -0
  27. package/src/bitwrench-components-v2.js +1879 -0
  28. package/src/bitwrench-components.js +610 -0
  29. package/src/bitwrench-styles.js +3240 -0
  30. package/src/bitwrench.js +3367 -0
  31. package/src/cli/convert.js +205 -0
  32. package/src/cli/index.js +122 -0
  33. package/src/cli/inject.js +55 -0
  34. package/src/cli/layout-default.js +142 -0
  35. package/src/generate-css.js +381 -0
  36. package/src/vendor/quikdown.js +654 -0
  37. package/src/version.js +16 -0
  38. package/.eslintrc.json +0 -27
  39. package/.github/workflows/codeql-analysis.yml +0 -72
  40. package/.travis.yml +0 -34
  41. package/bitwrench.css +0 -92
  42. package/bitwrench.js +0 -3348
  43. package/bitwrench.js_sri.txt +0 -1
  44. package/bitwrench.min.js +0 -1
  45. package/bitwrench.min.js_sri.txt +0 -1
  46. package/bitwrench_ESM.js +0 -3207
  47. package/bitwrench_ESM.js_sri.txt +0 -1
  48. package/bitwrench_ESM.min.js +0 -1
  49. package/bitwrench_ESM.min.js_sri.txt +0 -1
  50. package/dev/bitwrench-todo.md +0 -215
  51. package/dev/css-arrows.md +0 -23
  52. package/dev/docStringDev.js +0 -124
  53. package/dev/docStringParseDev.js +0 -171
  54. package/dev/example11-load-mjs-page.html +0 -17
  55. package/dev/figures.html +0 -37
  56. package/dev/html_gen.js +0 -349
  57. package/dev/htmld.md +0 -250
  58. package/dev/htmldev.html +0 -45
  59. package/dev/index-old.html +0 -87
  60. package/dev/misc-notes.md +0 -21
  61. package/dev/norm.css +0 -30
  62. package/dev/notes.md +0 -2
  63. package/dev/pageData.mjs +0 -69
  64. package/dev/sizes.html +0 -49
  65. package/dev/universal-js-module.js +0 -37
  66. package/examples/example1.html +0 -78
  67. package/examples/example10.html +0 -84
  68. package/examples/example11.html +0 -17
  69. package/examples/example12.html +0 -18
  70. package/examples/example2.html +0 -44
  71. package/examples/example3.html +0 -50
  72. package/examples/example4.html +0 -22
  73. package/examples/example5.html +0 -82
  74. package/examples/example6.html +0 -128
  75. package/examples/example7.html +0 -91
  76. package/examples/example8.html +0 -27
  77. package/examples/example9.html +0 -102
  78. package/examples/examplePageData12.mjs +0 -73
  79. package/examples/pageData.mjs +0 -69
  80. package/examples/pico.min.css +0 -5
  81. package/icon/bitwrench-dark-tall.png +0 -0
  82. package/icon/bitwrench-dark.png +0 -0
  83. package/icon/bitwrench-icon-lt-grey.png +0 -0
  84. package/icon/bitwrench-icon.vsd +0 -0
  85. package/icon/bitwrench-logo-dark.png +0 -0
  86. package/icon/bitwrench-logo-full.png +0 -0
  87. package/icon/bitwrench-logo-green.png +0 -0
  88. package/icon/bitwrench-logo-grey.png +0 -0
  89. package/icon/bitwrench-logo-white.png +0 -0
  90. package/icon/bitwrench-logos-colors.png +0 -0
  91. package/icon/bitwrench-thick-logo.png +0 -0
  92. package/icon/bitwrench-thick-teal/android-chrome-192x192.png +0 -0
  93. package/icon/bitwrench-thick-teal/android-chrome-512x512.png +0 -0
  94. package/icon/bitwrench-thick-teal/apple-touch-icon.png +0 -0
  95. package/icon/bitwrench-thick-teal/browserconfig.xml +0 -9
  96. package/icon/bitwrench-thick-teal/favicon-16x16.png +0 -0
  97. package/icon/bitwrench-thick-teal/favicon-32x32.png +0 -0
  98. package/icon/bitwrench-thick-teal/favicon.ico +0 -0
  99. package/icon/bitwrench-thick-teal/mstile-144x144.png +0 -0
  100. package/icon/bitwrench-thick-teal/mstile-150x150.png +0 -0
  101. package/icon/bitwrench-thick-teal/mstile-310x150.png +0 -0
  102. package/icon/bitwrench-thick-teal/mstile-310x310.png +0 -0
  103. package/icon/bitwrench-thick-teal/mstile-70x70.png +0 -0
  104. package/icon/bitwrench-thick-teal/site.webmanifest +0 -19
  105. package/icon/bitwrench-thick-teal.ico +0 -0
  106. package/icon/bitwrench-thick-teal.svg +0 -44
  107. package/icon/bitwrench-thick-teal.zip +0 -0
  108. package/icon/favicon-test.html +0 -20
  109. package/icon/logos-test.PNG +0 -0
  110. package/images/bitwrench-512x512.png +0 -0
  111. package/images/bitwrench-logo-med.png +0 -0
  112. package/images/bitwrench-thick-logo.png +0 -0
  113. package/images/bitwrench-thick-logo.svg +0 -64
  114. package/images/bitwrench-thick-teal.ico +0 -0
  115. package/images/favicon.ico +0 -0
  116. package/index.html +0 -282
  117. package/instr_tmp/bitwrench.js +0 -1350
  118. package/karma.conf.js +0 -140
  119. package/makefile +0 -21
  120. package/quick-docs.html +0 -206
  121. package/test/bitwrench_test.js +0 -1255
  122. package/test/karma-test.js +0 -1081
  123. package/tools/bw_deprecatedNames.js +0 -19
  124. package/tools/bwconsole.js +0 -20
  125. package/tools/createSimpleHTMLPage.js +0 -41
  126. package/tools/emitreadme.sh +0 -4
  127. package/tools/export-bw-default-css.js +0 -41
  128. package/tools/umd2ModuleHack.js +0 -32
  129. package/tools/update-bw-package.js +0 -36
  130. package/tools/updatereadme.js +0 -34
@@ -0,0 +1,15 @@
1
+ /*! bitwrench v2.0.7 | BSD-2-Clause | http://deftio.com/bitwrench */
2
+ /**
3
+ * bitwrench-code-edit.js - syntax-highlighted contenteditable code editor addon
4
+ *
5
+ * Provides bw.highlight() for tokenizing JS/CSS/HTML into TACO spans,
6
+ * and bw.codeEditor() for a live editable code block with syntax coloring.
7
+ *
8
+ * Can be loaded standalone (browser script tag after bitwrench.umd.js),
9
+ * or imported as an ES module / CJS module.
10
+ *
11
+ * @module bitwrench-code-edit
12
+ * @license BSD-2-Clause
13
+ */
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,u=!1;if(a.trim().length||p&&"operator"!==p.type&&"punctuation"!==p.type&&"keyword"!==p.type||(u=!0),u){l("plain");for(var f="/",b=r+1,w=!1,h=!1;b<n;){var d=e[b];if(w)f+=d,w=!1,b++;else if("\\"!==d)if("["!==d)if("]"!==d){if("/"===d&&!h){f+=d,b++;break}if("\n"===d)break;f+=d,b++}else h=!1,f+=d,b++;else h=!0,f+=d,b++;else w=!0,f+=d,b++}for(;b<n&&/[gimsuvy]/.test(e[b]);)f+=e[b],b++;t.push({type:"string",text:f}),r=b;continue}}if('"'!==s&&"'"!==s&&"`"!==s)if(/[0-9]/.test(s)||"."===s&&i&&/[0-9]/.test(i)){l("plain");var g="";if("0"===s&&i&&/[xXbBoO]/.test(i))for(g=s+i,r+=2;r<n&&/[0-9a-fA-F_]/.test(e[r]);)g+=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])?(g+=e[r],r++):(g+=e[r]+e[r+1],r+=2);t.push({type:"number",text:g})}else if(/[a-zA-Z_$]/.test(s)){l("plain");for(var v="";r<n&&/[a-zA-Z0-9_$]/.test(e[r]);)v+=e[r],r++;for(var y=r;y<n&&(" "===e[y]||"\t"===e[y]);)y++;var x=t.length?t[t.length-1]:null,m=x&&"punctuation"===x.type&&"."===x.text;c[v]?t.push({type:"keyword",text:v}):m?y<n&&"("===e[y]?t.push({type:"function",text:v}):t.push({type:"property",text:v}):y<n&&"("===e[y]?t.push({type:"function",text:v}):t.push({type:"plain",text:v})}else if(-1==="=+-*/%!<>&|^~?:".indexOf(s))-1==="(){}[];,.".indexOf(s)?(a+=s,r++):(l("plain"),t.push({type:"punctuation",text:s}),r++);else{l("plain");var k=s;++r<n&&-1!=="=+-*/%!<>&|^~?:".indexOf(e[r])&&(k+=e[r],++r<n&&-1!=="=>&|".indexOf(e[r])&&(k+=e[r],r++)),t.push({type:"operator",text:k})}else{l("plain");var C=s,A=s,S=r+1;if("`"===C){for(;S<n;){var O=e[S];if("\\"!==O)if("$"!==O||"{"!==e[S+1]){if("`"===O){A+=O,S++;break}A+=O,S++}else{A.length&&t.push({type:"string",text:A}),A="",t.push({type:"template-interp",text:"${"}),S+=2;for(var E=1,T="";S<n&&E>0;){if("{"===e[S])E++;else if("}"===e[S]&&0===--E)break;T+=e[S],S++}var z=o(T);(t=t.concat(z)).push({type:"template-interp",text:"}"}),S++}else A+=O+(e[S+1]||""),S+=2}A.length&&t.push({type:"string",text:A})}else{for(;S<n;){var R=e[S];if("\\"!==R){if(R===C){A+=R,S++;break}if("\n"===R)break;A+=R,S++}else A+=R+(e[S+1]||""),S+=2}t.push({type:"string",text:A})}r=S}}else{l("plain");var _=e.indexOf("*/",r+2);-1===_&&(_=n-2),t.push({type:"comment",text:e.substring(r,_+2)}),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 u="#";for(c++;c<o&&/[0-9a-fA-F]/.test(e[c]);)u+=e[c],c++;t.push({type:"color",text:u})}else{a("selector");var f="@";for(c++;c<o&&/[a-zA-Z\-]/.test(e[c]);)f+=e[c],c++;t.push({type:"at-rule",text:f})}else{a("selector"===r?"selector":"css-value");var b=l,w=l;for(c++;c<o;)if("\\"!==e[c]){if(e[c]===b){w+=e[c],c++;break}w+=e[c],c++}else w+=e[c]+(e[c+1]||""),c+=2;t.push({type:"string",text:w})}else{a("selector"===r?"selector":"prop"===r?"css-prop":"css-value");var h=e.indexOf("*/",c+2);-1===h&&(h=o-2),t.push({type:"comment",text:e.substring(c,h+2)}),c=h+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 u=e[c],f=u;for(c++;c<o&&e[c]!==u;)f+=e[c],c++;c<o&&(f+=e[c],c++),t.push({type:"attr-value",text:f})}else{for(var b="";c<o&&!/[\s>]/.test(e[c]);)b+=e[c],c++;t.push({type:"attr-value",text:b})}}else r+=e[c],c++,n("plain");var w="";c<o&&"/"===e[c]&&(w+="/",c++),c<o&&">"===e[c]&&(w+=">",c++),w&&t.push({type:"tag",text:w})}else{n("plain");var h=e.indexOf("--\x3e",c+4);-1===h&&(h=o-3),t.push({type:"comment",text:e.substring(c,h+3)}),c=h+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(u,50)})),n.addEventListener("keydown",(function(e){"Tab"===e.key&&(e.preventDefault(),document.execCommand("insertText",!1," "))})))}function p(){return n.textContent||""}function u(){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};
15
+ //# sourceMappingURL=bitwrench-code-edit.esm.min.js.map
@@ -0,0 +1,645 @@
1
+ /*! bitwrench v2.0.7 | BSD-2-Clause | http://deftio.com/bitwrench */
2
+ (function (global, factory) {
3
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
4
+ typeof define === 'function' && define.amd ? define(['exports'], factory) :
5
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.bwCodeEdit = {}));
6
+ })(this, (function (exports) { 'use strict';
7
+
8
+ /**
9
+ * bitwrench-code-edit.js - syntax-highlighted contenteditable code editor addon
10
+ *
11
+ * Provides bw.highlight() for tokenizing JS/CSS/HTML into TACO spans,
12
+ * and bw.codeEditor() for a live editable code block with syntax coloring.
13
+ *
14
+ * Can be loaded standalone (browser script tag after bitwrench.umd.js),
15
+ * or imported as an ES module / CJS module.
16
+ *
17
+ * @module bitwrench-code-edit
18
+ * @license BSD-2-Clause
19
+ */
20
+
21
+ // -- CSS (injected once) ----------------------------------------------
22
+ var _cssInjected = false;
23
+ var CSS_TEXT =
24
+ '.bw-ce{background:#1e293b;border-radius:6px;border:1px solid rgba(255,255,255,0.08);overflow:auto}' +
25
+ '.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:#e2e8f0;outline:none;white-space:pre-wrap;display:block;padding:0.75rem 1rem}' +
27
+ '.bw-ce code:empty::before{content:"\\200b"}' +
28
+ '.bw-ce .bw-ce-keyword{color:#c792ea}' +
29
+ '.bw-ce .bw-ce-string{color:#c3e88d}' +
30
+ '.bw-ce .bw-ce-comment{color:#546e7a;font-style:italic}' +
31
+ '.bw-ce .bw-ce-number{color:#f78c6c}' +
32
+ '.bw-ce .bw-ce-operator{color:#89ddff}' +
33
+ '.bw-ce .bw-ce-punctuation{color:#89ddff}' +
34
+ '.bw-ce .bw-ce-property{color:#82aaff}' +
35
+ '.bw-ce .bw-ce-function{color:#82aaff}' +
36
+ '.bw-ce .bw-ce-tag{color:#f07178}' +
37
+ '.bw-ce .bw-ce-attr-name{color:#ffcb6b}' +
38
+ '.bw-ce .bw-ce-attr-value{color:#c3e88d}' +
39
+ '.bw-ce .bw-ce-selector{color:#c792ea}' +
40
+ '.bw-ce .bw-ce-css-prop{color:#82aaff}' +
41
+ '.bw-ce .bw-ce-css-value{color:#f78c6c}' +
42
+ '.bw-ce .bw-ce-at-rule{color:#c792ea;font-style:italic}' +
43
+ '.bw-ce .bw-ce-color{color:#f78c6c}' +
44
+ '.bw-ce .bw-ce-template-interp{color:#89ddff}' +
45
+ // Light theme
46
+ '.bw-ce-light.bw-ce{background:#fafafa;border-color:#d8d8d8}' +
47
+ '.bw-ce-light.bw-ce code{color:#1a1a1a}' +
48
+ '.bw-ce-light.bw-ce .bw-ce-keyword{color:#7c3aed}' +
49
+ '.bw-ce-light.bw-ce .bw-ce-string{color:#16a34a}' +
50
+ '.bw-ce-light.bw-ce .bw-ce-comment{color:#9ca3af;font-style:italic}' +
51
+ '.bw-ce-light.bw-ce .bw-ce-number{color:#ea580c}' +
52
+ '.bw-ce-light.bw-ce .bw-ce-operator{color:#0891b2}' +
53
+ '.bw-ce-light.bw-ce .bw-ce-punctuation{color:#6b7280}' +
54
+ '.bw-ce-light.bw-ce .bw-ce-property{color:#2563eb}' +
55
+ '.bw-ce-light.bw-ce .bw-ce-function{color:#2563eb}' +
56
+ '.bw-ce-light.bw-ce .bw-ce-tag{color:#dc2626}' +
57
+ '.bw-ce-light.bw-ce .bw-ce-attr-name{color:#d97706}' +
58
+ '.bw-ce-light.bw-ce .bw-ce-attr-value{color:#16a34a}' +
59
+ '.bw-ce-light.bw-ce .bw-ce-selector{color:#7c3aed}' +
60
+ '.bw-ce-light.bw-ce .bw-ce-css-prop{color:#2563eb}' +
61
+ '.bw-ce-light.bw-ce .bw-ce-css-value{color:#ea580c}' +
62
+ '.bw-ce-light.bw-ce .bw-ce-at-rule{color:#7c3aed}' +
63
+ '.bw-ce-light.bw-ce .bw-ce-color{color:#ea580c}' +
64
+ '.bw-ce-light.bw-ce .bw-ce-template-interp{color:#0891b2}';
65
+
66
+ function ensureCSS(bw) {
67
+ if (_cssInjected) return;
68
+ _cssInjected = true;
69
+ if (bw && bw.injectCSS) {
70
+ bw.injectCSS(CSS_TEXT, { id: 'bw-code-edit-styles' });
71
+ }
72
+ }
73
+
74
+ // -- JS keywords ------------------------------------------------------
75
+ var JS_KEYWORDS = {};
76
+ '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(k) { JS_KEYWORDS[k] = true; });
77
+
78
+ // -- JS Tokenizer -----------------------------------------------------
79
+ function tokenizeJS(code) {
80
+ var tokens = [];
81
+ var i = 0, len = code.length;
82
+ var buf = '';
83
+
84
+ function flush(type) {
85
+ if (buf.length) { tokens.push({ type: type, text: buf }); buf = ''; }
86
+ }
87
+
88
+ while (i < len) {
89
+ var ch = code[i];
90
+ var next = code[i + 1];
91
+
92
+ // Line comment
93
+ if (ch === '/' && next === '/') {
94
+ flush('plain');
95
+ var end = code.indexOf('\n', i);
96
+ if (end === -1) end = len;
97
+ tokens.push({ type: 'comment', text: code.substring(i, end) });
98
+ i = end;
99
+ continue;
100
+ }
101
+
102
+ // Block comment
103
+ if (ch === '/' && next === '*') {
104
+ flush('plain');
105
+ var end2 = code.indexOf('*/', i + 2);
106
+ if (end2 === -1) end2 = len - 2;
107
+ tokens.push({ type: 'comment', text: code.substring(i, end2 + 2) });
108
+ i = end2 + 2;
109
+ continue;
110
+ }
111
+
112
+ // Regex (simple heuristic: / after operator or start-of-line)
113
+ if (ch === '/' && next !== '/' && next !== '*') {
114
+ var prevToken = tokens.length ? tokens[tokens.length - 1] : null;
115
+ var prevBuf = buf.trim();
116
+ var isRegex = false;
117
+ if (!prevBuf.length) {
118
+ if (!prevToken) isRegex = true;
119
+ else if (prevToken.type === 'operator' || prevToken.type === 'punctuation' || prevToken.type === 'keyword') isRegex = true;
120
+ }
121
+ if (isRegex) {
122
+ flush('plain');
123
+ var rBuf = '/';
124
+ var ri = i + 1;
125
+ var escaped = false;
126
+ var inCharClass = false;
127
+ while (ri < len) {
128
+ var rc = code[ri];
129
+ if (escaped) { rBuf += rc; escaped = false; ri++; continue; }
130
+ if (rc === '\\') { escaped = true; rBuf += rc; ri++; continue; }
131
+ if (rc === '[') { inCharClass = true; rBuf += rc; ri++; continue; }
132
+ if (rc === ']') { inCharClass = false; rBuf += rc; ri++; continue; }
133
+ if (rc === '/' && !inCharClass) { rBuf += rc; ri++; break; }
134
+ if (rc === '\n') break;
135
+ rBuf += rc; ri++;
136
+ }
137
+ // Flags
138
+ while (ri < len && /[gimsuvy]/.test(code[ri])) { rBuf += code[ri]; ri++; }
139
+ tokens.push({ type: 'string', text: rBuf });
140
+ i = ri;
141
+ continue;
142
+ }
143
+ }
144
+
145
+ // Strings
146
+ if (ch === '"' || ch === "'" || ch === '`') {
147
+ flush('plain');
148
+ var quote = ch;
149
+ var sBuf = ch;
150
+ var si = i + 1;
151
+ if (quote === '`') {
152
+ // Template literal
153
+ while (si < len) {
154
+ var sc = code[si];
155
+ if (sc === '\\') { sBuf += sc + (code[si + 1] || ''); si += 2; continue; }
156
+ if (sc === '$' && code[si + 1] === '{') {
157
+ // Flush string part so far
158
+ if (sBuf.length) tokens.push({ type: 'string', text: sBuf }); sBuf = '';
159
+ // Find matching brace (simple: count braces)
160
+ tokens.push({ type: 'template-interp', text: '${' });
161
+ si += 2;
162
+ var depth = 1;
163
+ var interpBuf = '';
164
+ while (si < len && depth > 0) {
165
+ if (code[si] === '{') depth++;
166
+ else if (code[si] === '}') { depth--; if (depth === 0) break; }
167
+ interpBuf += code[si]; si++;
168
+ }
169
+ // Tokenize the interpolation content recursively
170
+ var interpTokens = tokenizeJS(interpBuf);
171
+ tokens = tokens.concat(interpTokens);
172
+ tokens.push({ type: 'template-interp', text: '}' });
173
+ si++; // skip closing }
174
+ continue;
175
+ }
176
+ if (sc === '`') { sBuf += sc; si++; break; }
177
+ sBuf += sc; si++;
178
+ }
179
+ if (sBuf.length) tokens.push({ type: 'string', text: sBuf });
180
+ } else {
181
+ while (si < len) {
182
+ var sc2 = code[si];
183
+ if (sc2 === '\\') { sBuf += sc2 + (code[si + 1] || ''); si += 2; continue; }
184
+ if (sc2 === quote) { sBuf += sc2; si++; break; }
185
+ if (sc2 === '\n') break;
186
+ sBuf += sc2; si++;
187
+ }
188
+ tokens.push({ type: 'string', text: sBuf });
189
+ }
190
+ i = si;
191
+ continue;
192
+ }
193
+
194
+ // Numbers
195
+ if (/[0-9]/.test(ch) || (ch === '.' && next && /[0-9]/.test(next))) {
196
+ flush('plain');
197
+ var nBuf = '';
198
+ if (ch === '0' && next && /[xXbBoO]/.test(next)) {
199
+ nBuf = ch + next; i += 2;
200
+ while (i < len && /[0-9a-fA-F_]/.test(code[i])) { nBuf += code[i]; i++; }
201
+ } else {
202
+ while (i < len && /[0-9._eE]/.test(code[i])) {
203
+ if ((code[i] === 'e' || code[i] === 'E') && code[i + 1] && /[+\-0-9]/.test(code[i + 1])) {
204
+ nBuf += code[i] + code[i + 1]; i += 2; continue;
205
+ }
206
+ nBuf += code[i]; i++;
207
+ }
208
+ }
209
+ tokens.push({ type: 'number', text: nBuf });
210
+ continue;
211
+ }
212
+
213
+ // Identifiers / keywords
214
+ if (/[a-zA-Z_$]/.test(ch)) {
215
+ flush('plain');
216
+ var wBuf = '';
217
+ while (i < len && /[a-zA-Z0-9_$]/.test(code[i])) { wBuf += code[i]; i++; }
218
+ // Look-ahead: is it a function call?
219
+ var la = i;
220
+ while (la < len && (code[la] === ' ' || code[la] === '\t')) la++;
221
+ // Look-back: is it a property (after dot)?
222
+ var prevTok = tokens.length ? tokens[tokens.length - 1] : null;
223
+ var isDot = prevTok && prevTok.type === 'punctuation' && prevTok.text === '.';
224
+
225
+ if (JS_KEYWORDS[wBuf]) {
226
+ tokens.push({ type: 'keyword', text: wBuf });
227
+ } else if (isDot) {
228
+ if (la < len && code[la] === '(') {
229
+ tokens.push({ type: 'function', text: wBuf });
230
+ } else {
231
+ tokens.push({ type: 'property', text: wBuf });
232
+ }
233
+ } else if (la < len && code[la] === '(') {
234
+ tokens.push({ type: 'function', text: wBuf });
235
+ } else {
236
+ tokens.push({ type: 'plain', text: wBuf });
237
+ }
238
+ continue;
239
+ }
240
+
241
+ // Operators
242
+ if ('=+-*/%!<>&|^~?:'.indexOf(ch) !== -1) {
243
+ flush('plain');
244
+ // Consume multi-char operators
245
+ var opBuf = ch;
246
+ i++;
247
+ if (i < len && '=+-*/%!<>&|^~?:'.indexOf(code[i]) !== -1) {
248
+ opBuf += code[i]; i++;
249
+ if (i < len && '=>&|'.indexOf(code[i]) !== -1) { opBuf += code[i]; i++; }
250
+ }
251
+ tokens.push({ type: 'operator', text: opBuf });
252
+ continue;
253
+ }
254
+
255
+ // Punctuation
256
+ if ('(){}[];,.'.indexOf(ch) !== -1) {
257
+ flush('plain');
258
+ tokens.push({ type: 'punctuation', text: ch });
259
+ i++;
260
+ continue;
261
+ }
262
+
263
+ // Plain (whitespace + anything else)
264
+ buf += ch;
265
+ i++;
266
+ }
267
+ flush('plain');
268
+ return tokens;
269
+ }
270
+
271
+ // -- CSS Tokenizer ----------------------------------------------------
272
+ function tokenizeCSS(code) {
273
+ var tokens = [];
274
+ var i = 0, len = code.length;
275
+ var state = 'selector'; // selector | prop | value
276
+ var buf = '';
277
+
278
+ function flush(type) {
279
+ if (buf.length) { tokens.push({ type: type || 'plain', text: buf }); buf = ''; }
280
+ }
281
+
282
+ while (i < len) {
283
+ var ch = code[i];
284
+ var next = code[i + 1];
285
+
286
+ // Block comment
287
+ if (ch === '/' && next === '*') {
288
+ flush(state === 'selector' ? 'selector' : state === 'prop' ? 'css-prop' : 'css-value');
289
+ var end = code.indexOf('*/', i + 2);
290
+ if (end === -1) end = len - 2;
291
+ tokens.push({ type: 'comment', text: code.substring(i, end + 2) });
292
+ i = end + 2;
293
+ continue;
294
+ }
295
+
296
+ // Strings in values
297
+ if ((ch === '"' || ch === "'") && (state === 'value' || state === 'selector')) {
298
+ flush(state === 'selector' ? 'selector' : 'css-value');
299
+ var quote = ch;
300
+ var sBuf = ch;
301
+ i++;
302
+ while (i < len) {
303
+ if (code[i] === '\\') { sBuf += code[i] + (code[i + 1] || ''); i += 2; continue; }
304
+ if (code[i] === quote) { sBuf += code[i]; i++; break; }
305
+ sBuf += code[i]; i++;
306
+ }
307
+ tokens.push({ type: 'string', text: sBuf });
308
+ continue;
309
+ }
310
+
311
+ // At-rules
312
+ if (ch === '@' && state === 'selector') {
313
+ flush('selector');
314
+ var aBuf = '@';
315
+ i++;
316
+ while (i < len && /[a-zA-Z\-]/.test(code[i])) { aBuf += code[i]; i++; }
317
+ tokens.push({ type: 'at-rule', text: aBuf });
318
+ continue;
319
+ }
320
+
321
+ // Hex colors in values
322
+ if (ch === '#' && state === 'value') {
323
+ flush('css-value');
324
+ var hBuf = '#';
325
+ i++;
326
+ while (i < len && /[0-9a-fA-F]/.test(code[i])) { hBuf += code[i]; i++; }
327
+ tokens.push({ type: 'color', text: hBuf });
328
+ continue;
329
+ }
330
+
331
+ // Numbers in values
332
+ if (state === 'value' && /[0-9]/.test(ch)) {
333
+ flush('css-value');
334
+ var nBuf2 = '';
335
+ while (i < len && /[0-9.]/.test(code[i])) { nBuf2 += code[i]; i++; }
336
+ // Unit
337
+ var uBuf = '';
338
+ while (i < len && /[a-zA-Z%]/.test(code[i])) { uBuf += code[i]; i++; }
339
+ tokens.push({ type: 'number', text: nBuf2 + uBuf });
340
+ continue;
341
+ }
342
+
343
+ // Punctuation and state transitions
344
+ if (ch === '{') {
345
+ flush(state === 'selector' ? 'selector' : 'plain');
346
+ tokens.push({ type: 'punctuation', text: ch });
347
+ state = 'prop';
348
+ i++; continue;
349
+ }
350
+ if (ch === '}') {
351
+ flush(state === 'prop' ? 'css-prop' : state === 'value' ? 'css-value' : 'plain');
352
+ tokens.push({ type: 'punctuation', text: ch });
353
+ state = 'selector';
354
+ i++; continue;
355
+ }
356
+ if (ch === ':' && state === 'prop') {
357
+ flush('css-prop');
358
+ tokens.push({ type: 'punctuation', text: ch });
359
+ state = 'value';
360
+ i++; continue;
361
+ }
362
+ if (ch === ';') {
363
+ flush(state === 'value' ? 'css-value' : 'plain');
364
+ tokens.push({ type: 'punctuation', text: ch });
365
+ state = 'prop';
366
+ i++; continue;
367
+ }
368
+ if (ch === ',') {
369
+ flush(state === 'selector' ? 'selector' : state === 'value' ? 'css-value' : 'plain');
370
+ tokens.push({ type: 'punctuation', text: ch });
371
+ i++; continue;
372
+ }
373
+
374
+ // Accumulate into buffer
375
+ buf += ch;
376
+ i++;
377
+ }
378
+ flush(state === 'selector' ? 'selector' : state === 'prop' ? 'css-prop' : 'css-value');
379
+ return tokens;
380
+ }
381
+
382
+ // -- HTML Tokenizer ---------------------------------------------------
383
+ function tokenizeHTML(code) {
384
+ var tokens = [];
385
+ var i = 0, len = code.length;
386
+ var buf = '';
387
+
388
+ function flush(type) {
389
+ if (buf.length) { tokens.push({ type: type, text: buf }); buf = ''; }
390
+ }
391
+
392
+ while (i < len) {
393
+ var ch = code[i];
394
+
395
+ // Comment
396
+ if (ch === '<' && code.substring(i, i + 4) === '<!--') {
397
+ flush('plain');
398
+ var end = code.indexOf('-->', i + 4);
399
+ if (end === -1) end = len - 3;
400
+ tokens.push({ type: 'comment', text: code.substring(i, end + 3) });
401
+ i = end + 3;
402
+ continue;
403
+ }
404
+
405
+ // Tag
406
+ if (ch === '<') {
407
+ flush('plain');
408
+ // Consume < and optional /
409
+ var tBuf = '<';
410
+ i++;
411
+ if (i < len && code[i] === '/') { tBuf += '/'; i++; }
412
+ // Tag name
413
+ while (i < len && /[a-zA-Z0-9\-]/.test(code[i])) { tBuf += code[i]; i++; }
414
+ tokens.push({ type: 'tag', text: tBuf });
415
+
416
+ // Attributes
417
+ while (i < len && code[i] !== '>' && !(code[i] === '/' && code[i + 1] === '>')) {
418
+ // Whitespace
419
+ if (/\s/.test(code[i])) {
420
+ var wBuf = '';
421
+ while (i < len && /\s/.test(code[i])) { wBuf += code[i]; i++; }
422
+ tokens.push({ type: 'plain', text: wBuf });
423
+ continue;
424
+ }
425
+ // Attribute name
426
+ if (/[a-zA-Z_\-@:]/.test(code[i])) {
427
+ var aBuf = '';
428
+ while (i < len && /[a-zA-Z0-9_\-@:]/.test(code[i])) { aBuf += code[i]; i++; }
429
+ tokens.push({ type: 'attr-name', text: aBuf });
430
+ // = sign
431
+ if (i < len && code[i] === '=') {
432
+ tokens.push({ type: 'punctuation', text: '=' });
433
+ i++;
434
+ // Attribute value
435
+ if (i < len && (code[i] === '"' || code[i] === "'")) {
436
+ var q = code[i];
437
+ var vBuf = q;
438
+ i++;
439
+ while (i < len && code[i] !== q) { vBuf += code[i]; i++; }
440
+ if (i < len) { vBuf += code[i]; i++; }
441
+ tokens.push({ type: 'attr-value', text: vBuf });
442
+ } else {
443
+ // Unquoted value
444
+ var uBuf2 = '';
445
+ while (i < len && !/[\s>]/.test(code[i])) { uBuf2 += code[i]; i++; }
446
+ tokens.push({ type: 'attr-value', text: uBuf2 });
447
+ }
448
+ }
449
+ continue;
450
+ }
451
+ // Anything else in tag
452
+ buf += code[i]; i++;
453
+ flush('plain');
454
+ }
455
+
456
+ // Close of tag
457
+ var closeBuf = '';
458
+ if (i < len && code[i] === '/') { closeBuf += '/'; i++; }
459
+ if (i < len && code[i] === '>') { closeBuf += '>'; i++; }
460
+ if (closeBuf) tokens.push({ type: 'tag', text: closeBuf });
461
+ continue;
462
+ }
463
+
464
+ // Entity
465
+ if (ch === '&') {
466
+ flush('plain');
467
+ var eBuf = '&';
468
+ i++;
469
+ while (i < len && code[i] !== ';' && /[a-zA-Z0-9#]/.test(code[i])) { eBuf += code[i]; i++; }
470
+ if (i < len && code[i] === ';') { eBuf += ';'; i++; }
471
+ tokens.push({ type: 'string', text: eBuf });
472
+ continue;
473
+ }
474
+
475
+ // Plain text
476
+ buf += ch;
477
+ i++;
478
+ }
479
+ flush('plain');
480
+ return tokens;
481
+ }
482
+
483
+ // -- Token to TACO conversion -----------------------------------------
484
+ var TOKENIZERS = { js: tokenizeJS, javascript: tokenizeJS, css: tokenizeCSS, html: tokenizeHTML };
485
+
486
+ function tokensToTACO(tokArr) {
487
+ var result = [];
488
+ for (var i = 0; i < tokArr.length; i++) {
489
+ var tok = tokArr[i];
490
+ if (tok.type === 'plain') {
491
+ result.push(tok.text);
492
+ } else {
493
+ result.push({ t: 'span', a: { class: 'bw-ce-' + tok.type }, c: tok.text });
494
+ }
495
+ }
496
+ return result;
497
+ }
498
+
499
+ // -- Public: highlight ------------------------------------------------
500
+ function highlight(code, lang) {
501
+ var tokenizer = TOKENIZERS[lang] || tokenizeJS;
502
+ var tokens = tokenizer(code);
503
+ return tokensToTACO(tokens);
504
+ }
505
+
506
+ // -- Caret save/restore -----------------------------------------------
507
+ function getCaretOffset(el) {
508
+ var sel = window.getSelection();
509
+ if (!sel.rangeCount) return 0;
510
+ var range = sel.getRangeAt(0).cloneRange();
511
+ range.selectNodeContents(el);
512
+ range.setEnd(sel.getRangeAt(0).startContainer, sel.getRangeAt(0).startOffset);
513
+ return range.toString().length;
514
+ }
515
+
516
+ function setCaretOffset(el, offset) {
517
+ var sel = window.getSelection();
518
+ var range = document.createRange();
519
+ var walker = document.createTreeWalker(el, NodeFilter.SHOW_TEXT, null, false);
520
+ var pos = 0;
521
+ var node;
522
+ while ((node = walker.nextNode())) {
523
+ var nodeLen = node.textContent.length;
524
+ if (pos + nodeLen >= offset) {
525
+ range.setStart(node, offset - pos);
526
+ range.collapse(true);
527
+ sel.removeAllRanges();
528
+ sel.addRange(range);
529
+ return;
530
+ }
531
+ pos += nodeLen;
532
+ }
533
+ // If offset exceeds content, place at end
534
+ range.selectNodeContents(el);
535
+ range.collapse(false);
536
+ sel.removeAllRanges();
537
+ sel.addRange(range);
538
+ }
539
+
540
+ // -- Public: codeEditor -----------------------------------------------
541
+ function codeEditor(opts) {
542
+ opts = opts || {};
543
+ var code = opts.code || '';
544
+ var lang = opts.lang || 'js';
545
+ var height = opts.height || '180px';
546
+ var readOnly = !!opts.readOnly;
547
+ var className = 'bw-ce' + (opts.className ? ' ' + opts.className : '');
548
+
549
+ var highlighted = highlight(code, lang);
550
+
551
+ var codeAttrs = {
552
+ spellcheck: 'false',
553
+ class: 'bw-ce-code'
554
+ };
555
+ if (!readOnly) {
556
+ codeAttrs.contenteditable = 'true';
557
+ }
558
+
559
+ return {
560
+ t: 'div',
561
+ a: { class: className, style: 'max-height:' + height + ';overflow:auto' },
562
+ c: [
563
+ { t: 'pre', c: { t: 'code', a: codeAttrs, c: highlighted } }
564
+ ],
565
+ o: {
566
+ mounted: function(el) {
567
+ var codeEl = el.querySelector('.bw-ce-code');
568
+ if (!codeEl) return;
569
+
570
+ var currentCode = code;
571
+ var debounceTimer = null;
572
+
573
+ // Resolve bw from global or import context
574
+ var bw = (typeof window !== 'undefined' && window.bw) || {};
575
+
576
+ function getValue() { return codeEl.textContent || ''; }
577
+
578
+ function setValue(newCode) {
579
+ currentCode = newCode;
580
+ var tacos = highlight(newCode, lang);
581
+ if (bw.html) codeEl.innerHTML = bw.html({ t: 'span', c: tacos });
582
+ }
583
+
584
+ // Expose API on the element
585
+ el._bwCodeEdit = { getValue: getValue, setValue: setValue };
586
+
587
+ if (readOnly) return;
588
+
589
+ function rehighlight() {
590
+ var newCode = getValue();
591
+ if (newCode === currentCode) return;
592
+ currentCode = newCode;
593
+ var offset = getCaretOffset(codeEl);
594
+ var tacos = highlight(newCode, lang);
595
+ if (bw.html) codeEl.innerHTML = bw.html({ t: 'span', c: tacos });
596
+ setCaretOffset(codeEl, offset);
597
+ if (opts.onChange) opts.onChange(newCode);
598
+ }
599
+
600
+ codeEl.addEventListener('input', function() {
601
+ clearTimeout(debounceTimer);
602
+ debounceTimer = setTimeout(rehighlight, 50);
603
+ });
604
+
605
+ // Tab key: insert 2 spaces
606
+ codeEl.addEventListener('keydown', function(e) {
607
+ if (e.key === 'Tab') {
608
+ e.preventDefault();
609
+ document.execCommand('insertText', false, ' ');
610
+ }
611
+ });
612
+ }
613
+ }
614
+ };
615
+ }
616
+
617
+ // -- Auto-attach to bw when loaded as script tag ----------------------
618
+ function install(bw) {
619
+ if (!bw) return;
620
+ bw.highlight = highlight;
621
+ bw.codeEditor = function(opts) {
622
+ ensureCSS(bw);
623
+ return codeEditor(opts);
624
+ };
625
+ }
626
+
627
+ // Auto-install if bw is on window (script tag usage)
628
+ if (typeof window !== 'undefined' && window.bw) {
629
+ install(window.bw);
630
+ }
631
+ var bitwrenchCodeEdit = { highlight, codeEditor, install, CSS_TEXT };
632
+
633
+ exports.CSS_TEXT = CSS_TEXT;
634
+ exports.codeEditor = codeEditor;
635
+ exports.default = bitwrenchCodeEdit;
636
+ exports.highlight = highlight;
637
+ exports.install = install;
638
+ exports.tokenizeCSS = tokenizeCSS;
639
+ exports.tokenizeHTML = tokenizeHTML;
640
+ exports.tokenizeJS = tokenizeJS;
641
+
642
+ Object.defineProperty(exports, '__esModule', { value: true });
643
+
644
+ }));
645
+ //# sourceMappingURL=bitwrench-code-edit.umd.js.map