bitwrench 2.0.14 → 2.0.16

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 (61) hide show
  1. package/README.md +57 -21
  2. package/dist/bitwrench-bccl.cjs.js +3746 -0
  3. package/dist/bitwrench-bccl.cjs.min.js +40 -0
  4. package/dist/bitwrench-bccl.esm.js +3741 -0
  5. package/dist/bitwrench-bccl.esm.min.js +40 -0
  6. package/dist/bitwrench-bccl.umd.js +3752 -0
  7. package/dist/bitwrench-bccl.umd.min.js +40 -0
  8. package/dist/bitwrench-code-edit.cjs.js +99 -49
  9. package/dist/bitwrench-code-edit.cjs.min.js +23 -0
  10. package/dist/bitwrench-code-edit.es5.js +79 -16
  11. package/dist/bitwrench-code-edit.es5.min.js +9 -2
  12. package/dist/bitwrench-code-edit.esm.js +99 -49
  13. package/dist/bitwrench-code-edit.esm.min.js +9 -2
  14. package/dist/bitwrench-code-edit.umd.js +99 -49
  15. package/dist/bitwrench-code-edit.umd.min.js +9 -2
  16. package/dist/bitwrench-lean.cjs.js +4923 -3248
  17. package/dist/bitwrench-lean.cjs.min.js +35 -6
  18. package/dist/bitwrench-lean.es5.js +6325 -4580
  19. package/dist/bitwrench-lean.es5.min.js +32 -3
  20. package/dist/bitwrench-lean.esm.js +4923 -3248
  21. package/dist/bitwrench-lean.esm.min.js +35 -6
  22. package/dist/bitwrench-lean.umd.js +4923 -3248
  23. package/dist/bitwrench-lean.umd.min.js +35 -6
  24. package/dist/bitwrench.cjs.js +5082 -3667
  25. package/dist/bitwrench.cjs.min.js +38 -8
  26. package/dist/bitwrench.css +2289 -6034
  27. package/dist/bitwrench.es5.js +6862 -5346
  28. package/dist/bitwrench.es5.min.js +34 -5
  29. package/dist/bitwrench.esm.js +5082 -3667
  30. package/dist/bitwrench.esm.min.js +38 -8
  31. package/dist/bitwrench.min.css +1 -0
  32. package/dist/bitwrench.umd.js +5082 -3667
  33. package/dist/bitwrench.umd.min.js +38 -8
  34. package/dist/builds.json +184 -74
  35. package/dist/bwserve.cjs.js +646 -0
  36. package/dist/bwserve.esm.js +638 -0
  37. package/dist/sri.json +36 -26
  38. package/package.json +23 -6
  39. package/readme.html +71 -32
  40. package/src/bitwrench-bccl-entry.js +72 -0
  41. package/src/{bitwrench-components-v2.js → bitwrench-bccl.js} +396 -647
  42. package/src/bitwrench-code-edit.js +98 -48
  43. package/src/bitwrench-color-utils.js +24 -18
  44. package/src/bitwrench-components-stub.js +4 -1
  45. package/src/bitwrench-file-ops.js +180 -0
  46. package/src/bitwrench-lean.js +2 -2
  47. package/src/bitwrench-styles.js +1287 -4029
  48. package/src/bitwrench-utils.js +458 -0
  49. package/src/bitwrench.js +2070 -1292
  50. package/src/bwserve/client.js +182 -0
  51. package/src/bwserve/index.js +352 -0
  52. package/src/bwserve/shell.js +103 -0
  53. package/src/cli/index.js +36 -15
  54. package/src/cli/layout-default.js +18 -18
  55. package/src/cli/serve.js +325 -0
  56. package/src/generate-css.js +73 -53
  57. package/src/version.js +3 -3
  58. package/src/bitwrench-component-base.js +0 -736
  59. package/src/bitwrench-components-inline.js +0 -374
  60. package/src/bitwrench-components.js +0 -610
  61. /package/bin/{bitwrench.js → bwcli.js} +0 -0
@@ -1,4 +1,4 @@
1
- /*! bitwrench v2.0.14 | BSD-2-Clause | https://deftio.github.com/bitwrench/pages */
1
+ /*! bitwrench v2.0.16 | 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,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=o+1,w=!1,d=!1;b<n;){var h=e[b];if(w)f+=h,w=!1,b++;else if("\\"!==h)if("["!==h)if("]"!==h){if("/"===h&&!d){f+=h,b++;break}if("\n"===h)break;f+=h,b++}else d=!1,f+=h,b++;else d=!0,f+=h,b++;else w=!0,f+=h,b++}for(;b<n&&/[gimsuvy]/.test(e[b]);)f+=e[b],b++;t.push({type:"string",text:f}),o=b;continue}}if('"'!==i&&"'"!==i&&"`"!==i)if(/[0-9]/.test(i)||"."===i&&s&&/[0-9]/.test(s)){l("plain");var g="";if("0"===i&&s&&/[xXbBoO]/.test(s))for(g=i+s,o+=2;o<n&&/[0-9a-fA-F_]/.test(e[o]);)g+=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])?(g+=e[o],o++):(g+=e[o]+e[o+1],o+=2);t.push({type:"number",text:g})}else if(/[a-zA-Z_$]/.test(i)){l("plain");for(var v="";o<n&&/[a-zA-Z0-9_$]/.test(e[o]);)v+=e[o],o++;for(var y=o;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(i))-1==="(){}[];,.".indexOf(i)?(a+=i,o++):(l("plain"),t.push({type:"punctuation",text:i}),o++);else{l("plain");var k=i;++o<n&&-1!=="=+-*/%!<>&|^~?:".indexOf(e[o])&&(k+=e[o],++o<n&&-1!=="=>&|".indexOf(e[o])&&(k+=e[o],o++)),t.push({type:"operator",text:k})}else{l("plain");var C=i,S=i,T=o+1;if("`"===C){for(;T<n;){var A=e[T];if("\\"!==A)if("$"!==A||"{"!==e[T+1]){if("`"===A){S+=A,T++;break}S+=A,T++}else{S.length&&t.push({type:"string",text:S}),S="",t.push({type:"template-interp",text:"${"}),T+=2;for(var E=1,O="";T<n&&E>0;){if("{"===e[T])E++;else if("}"===e[T]&&0===--E)break;O+=e[T],T++}var z=r(O);(t=t.concat(z)).push({type:"template-interp",text:"}"}),T++}else S+=A+(e[T+1]||""),T+=2}S.length&&t.push({type:"string",text:S})}else{for(;T<n;){var _=e[T];if("\\"!==_){if(_===C){S+=_,T++;break}if("\n"===_)break;S+=_,T++}else S+=_+(e[T+1]||""),T+=2}t.push({type:"string",text:S})}o=T}}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 u="#";for(o++;o<c&&/[0-9a-fA-F]/.test(e[o]);)u+=e[o],o++;t.push({type:"color",text:u})}else{a("selector");var f="@";for(o++;o<c&&/[a-zA-Z\-]/.test(e[o]);)f+=e[o],o++;t.push({type:"at-rule",text:f})}else{a("selector"===r?"selector":"css-value");var b=l,w=l;for(o++;o<c;)if("\\"!==e[o]){if(e[o]===b){w+=e[o],o++;break}w+=e[o],o++}else w+=e[o]+(e[o+1]||""),o+=2;t.push({type:"string",text:w})}else{a("selector"===r?"selector":"prop"===r?"css-prop":"css-value");var d=e.indexOf("*/",o+2);-1===d&&(d=c-2),t.push({type:"comment",text:e.substring(o,d+2)}),o=d+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 u=e[o],f=u;for(o++;o<c&&e[o]!==u;)f+=e[o],o++;o<c&&(f+=e[o],o++),t.push({type:"attr-value",text:f})}else{for(var b="";o<c&&!/[\s>]/.test(e[o]);)b+=e[o],o++;t.push({type:"attr-value",text:b})}}else r+=e[o],o++,n("plain");var w="";o<c&&"/"===e[o]&&(w+="/",o++),o<c&&">"===e[o]&&(w+=">",o++),w&&t.push({type:"tag",text:w})}else{n("plain");var d=e.indexOf("--\x3e",o+4);-1===d&&(d=c-3),t.push({type:"comment",text:e.substring(o,d+3)}),o=d+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(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 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 u={highlight:i,codeEditor:s,install:p,CSS_TEXT:o};e.CSS_TEXT=o,e.codeEditor=s,e.default=u,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.es5.min.js.map
@@ -1,10 +1,17 @@
1
- /*! bitwrench v2.0.14 | BSD-2-Clause | https://deftio.github.com/bitwrench/pages */
1
+ /*! bitwrench v2.0.16 | 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,53 +22,58 @@
15
22
  // -- CSS (injected once) ----------------------------------------------
16
23
  var _cssInjected = false;
17
24
  var CSS_TEXT =
18
- '.bw-ce{background:#1e293b;border-radius:6px;border:1px solid rgba(255,255,255,0.08);overflow:auto}' +
19
- '.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:#e2e8f0;outline:none;white-space:pre-wrap;display:block;padding:0.75rem 1rem}' +
21
- '.bw-ce code:empty::before{content:"\\200b"}' +
22
- '.bw-ce .bw-ce-keyword{color:#c792ea}' +
23
- '.bw-ce .bw-ce-string{color:#c3e88d}' +
24
- '.bw-ce .bw-ce-comment{color:#546e7a;font-style:italic}' +
25
- '.bw-ce .bw-ce-number{color:#f78c6c}' +
26
- '.bw-ce .bw-ce-operator{color:#89ddff}' +
27
- '.bw-ce .bw-ce-punctuation{color:#89ddff}' +
28
- '.bw-ce .bw-ce-property{color:#82aaff}' +
29
- '.bw-ce .bw-ce-function{color:#82aaff}' +
30
- '.bw-ce .bw-ce-tag{color:#f07178}' +
31
- '.bw-ce .bw-ce-attr-name{color:#ffcb6b}' +
32
- '.bw-ce .bw-ce-attr-value{color:#c3e88d}' +
33
- '.bw-ce .bw-ce-selector{color:#c792ea}' +
34
- '.bw-ce .bw-ce-css-prop{color:#82aaff}' +
35
- '.bw-ce .bw-ce-css-value{color:#f78c6c}' +
36
- '.bw-ce .bw-ce-at-rule{color:#c792ea;font-style:italic}' +
37
- '.bw-ce .bw-ce-color{color:#f78c6c}' +
38
- '.bw-ce .bw-ce-template-interp{color:#89ddff}' +
25
+ '.bw_ce{background:var(--bw_code_bg,#1e293b);border-radius:6px;border:1px solid rgba(255,255,255,0.08);overflow:auto}' +
26
+ '.bw_ce pre{margin:0;padding:0}' +
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}' +
28
+ '.bw_ce code:empty::before{content:"\\200b"}' +
29
+ '.bw_ce .bw_ce_keyword{color:#c792ea}' +
30
+ '.bw_ce .bw_ce_string{color:#c3e88d}' +
31
+ '.bw_ce .bw_ce_comment{color:#546e7a;font-style:italic}' +
32
+ '.bw_ce .bw_ce_number{color:#f78c6c}' +
33
+ '.bw_ce .bw_ce_operator{color:#89ddff}' +
34
+ '.bw_ce .bw_ce_punctuation{color:#89ddff}' +
35
+ '.bw_ce .bw_ce_property{color:#82aaff}' +
36
+ '.bw_ce .bw_ce_function{color:#82aaff}' +
37
+ '.bw_ce .bw_ce_tag{color:#f07178}' +
38
+ '.bw_ce .bw_ce_attr_name{color:#ffcb6b}' +
39
+ '.bw_ce .bw_ce_attr_value{color:#c3e88d}' +
40
+ '.bw_ce .bw_ce_selector{color:#c792ea}' +
41
+ '.bw_ce .bw_ce_css_prop{color:#82aaff}' +
42
+ '.bw_ce .bw_ce_css_value{color:#f78c6c}' +
43
+ '.bw_ce .bw_ce_at_rule{color:#c792ea;font-style:italic}' +
44
+ '.bw_ce .bw_ce_color{color:#f78c6c}' +
45
+ '.bw_ce .bw_ce_template_interp{color:#89ddff}' +
39
46
  // Light theme
40
- '.bw-ce-light.bw-ce{background:#fafafa;border-color:#d8d8d8}' +
41
- '.bw-ce-light.bw-ce code{color:#1a1a1a}' +
42
- '.bw-ce-light.bw-ce .bw-ce-keyword{color:#7c3aed}' +
43
- '.bw-ce-light.bw-ce .bw-ce-string{color:#16a34a}' +
44
- '.bw-ce-light.bw-ce .bw-ce-comment{color:#9ca3af;font-style:italic}' +
45
- '.bw-ce-light.bw-ce .bw-ce-number{color:#ea580c}' +
46
- '.bw-ce-light.bw-ce .bw-ce-operator{color:#0891b2}' +
47
- '.bw-ce-light.bw-ce .bw-ce-punctuation{color:#6b7280}' +
48
- '.bw-ce-light.bw-ce .bw-ce-property{color:#2563eb}' +
49
- '.bw-ce-light.bw-ce .bw-ce-function{color:#2563eb}' +
50
- '.bw-ce-light.bw-ce .bw-ce-tag{color:#dc2626}' +
51
- '.bw-ce-light.bw-ce .bw-ce-attr-name{color:#d97706}' +
52
- '.bw-ce-light.bw-ce .bw-ce-attr-value{color:#16a34a}' +
53
- '.bw-ce-light.bw-ce .bw-ce-selector{color:#7c3aed}' +
54
- '.bw-ce-light.bw-ce .bw-ce-css-prop{color:#2563eb}' +
55
- '.bw-ce-light.bw-ce .bw-ce-css-value{color:#ea580c}' +
56
- '.bw-ce-light.bw-ce .bw-ce-at-rule{color:#7c3aed}' +
57
- '.bw-ce-light.bw-ce .bw-ce-color{color:#ea580c}' +
58
- '.bw-ce-light.bw-ce .bw-ce-template-interp{color:#0891b2}';
47
+ '.bw_ce_light.bw_ce{background:#fafafa;border-color:#d8d8d8}' +
48
+ '.bw_ce_light.bw_ce code{color:#1a1a1a}' +
49
+ '.bw_ce_light.bw_ce .bw_ce_keyword{color:#7c3aed}' +
50
+ '.bw_ce_light.bw_ce .bw_ce_string{color:#16a34a}' +
51
+ '.bw_ce_light.bw_ce .bw_ce_comment{color:#9ca3af;font-style:italic}' +
52
+ '.bw_ce_light.bw_ce .bw_ce_number{color:#ea580c}' +
53
+ '.bw_ce_light.bw_ce .bw_ce_operator{color:#0891b2}' +
54
+ '.bw_ce_light.bw_ce .bw_ce_punctuation{color:#6b7280}' +
55
+ '.bw_ce_light.bw_ce .bw_ce_property{color:#2563eb}' +
56
+ '.bw_ce_light.bw_ce .bw_ce_function{color:#2563eb}' +
57
+ '.bw_ce_light.bw_ce .bw_ce_tag{color:#dc2626}' +
58
+ '.bw_ce_light.bw_ce .bw_ce_attr_name{color:#d97706}' +
59
+ '.bw_ce_light.bw_ce .bw_ce_attr_value{color:#16a34a}' +
60
+ '.bw_ce_light.bw_ce .bw_ce_selector{color:#7c3aed}' +
61
+ '.bw_ce_light.bw_ce .bw_ce_css_prop{color:#2563eb}' +
62
+ '.bw_ce_light.bw_ce .bw_ce_css_value{color:#ea580c}' +
63
+ '.bw_ce_light.bw_ce .bw_ce_at_rule{color:#7c3aed}' +
64
+ '.bw_ce_light.bw_ce .bw_ce_color{color:#ea580c}' +
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;
62
74
  _cssInjected = true;
63
75
  if (bw && bw.injectCSS) {
64
- bw.injectCSS(CSS_TEXT, { id: 'bw-code-edit-styles' });
76
+ bw.injectCSS(CSS_TEXT, { id: 'bw_code_edit_styles' });
65
77
  }
66
78
  }
67
79
 
@@ -484,7 +496,7 @@ function tokensToTACO(tokArr) {
484
496
  if (tok.type === 'plain') {
485
497
  result.push(tok.text);
486
498
  } else {
487
- result.push({ t: 'span', a: { class: 'bw-ce-' + tok.type }, c: tok.text });
499
+ result.push({ t: 'span', a: { class: 'bw_ce_' + tok.type }, c: tok.text });
488
500
  }
489
501
  }
490
502
  return result;
@@ -538,46 +550,83 @@ function codeEditor(opts) {
538
550
  var lang = opts.lang || 'js';
539
551
  var height = opts.height || '180px';
540
552
  var readOnly = !!opts.readOnly;
541
- var className = 'bw-ce' + (opts.className ? ' ' + opts.className : '');
553
+ var showLineNumbers = !!opts.lineNumbers;
554
+ var className = 'bw_ce' + (opts.className ? ' ' + opts.className : '');
542
555
 
543
556
  var highlighted = highlight(code, lang);
544
557
 
545
558
  var codeAttrs = {
546
559
  spellcheck: 'false',
547
- class: 'bw-ce-code'
560
+ class: 'bw_ce_code'
548
561
  };
549
562
  if (!readOnly) {
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
- var codeEl = el.querySelector('.bw-ce-code');
588
+ var codeEl = el.querySelector('.bw_ce_code');
562
589
  if (!codeEl) return;
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.14 | BSD-2-Clause | https://deftio.github.com/bitwrench/pages */
1
+ /*! bitwrench v2.0.16 | 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,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};
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.14 | BSD-2-Clause | https://deftio.github.com/bitwrench/pages */
1
+ /*! bitwrench v2.0.16 | 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,53 +28,58 @@
21
28
  // -- CSS (injected once) ----------------------------------------------
22
29
  var _cssInjected = false;
23
30
  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}' +
31
+ '.bw_ce{background:var(--bw_code_bg,#1e293b);border-radius:6px;border:1px solid rgba(255,255,255,0.08);overflow:auto}' +
32
+ '.bw_ce pre{margin:0;padding:0}' +
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}' +
34
+ '.bw_ce code:empty::before{content:"\\200b"}' +
35
+ '.bw_ce .bw_ce_keyword{color:#c792ea}' +
36
+ '.bw_ce .bw_ce_string{color:#c3e88d}' +
37
+ '.bw_ce .bw_ce_comment{color:#546e7a;font-style:italic}' +
38
+ '.bw_ce .bw_ce_number{color:#f78c6c}' +
39
+ '.bw_ce .bw_ce_operator{color:#89ddff}' +
40
+ '.bw_ce .bw_ce_punctuation{color:#89ddff}' +
41
+ '.bw_ce .bw_ce_property{color:#82aaff}' +
42
+ '.bw_ce .bw_ce_function{color:#82aaff}' +
43
+ '.bw_ce .bw_ce_tag{color:#f07178}' +
44
+ '.bw_ce .bw_ce_attr_name{color:#ffcb6b}' +
45
+ '.bw_ce .bw_ce_attr_value{color:#c3e88d}' +
46
+ '.bw_ce .bw_ce_selector{color:#c792ea}' +
47
+ '.bw_ce .bw_ce_css_prop{color:#82aaff}' +
48
+ '.bw_ce .bw_ce_css_value{color:#f78c6c}' +
49
+ '.bw_ce .bw_ce_at_rule{color:#c792ea;font-style:italic}' +
50
+ '.bw_ce .bw_ce_color{color:#f78c6c}' +
51
+ '.bw_ce .bw_ce_template_interp{color:#89ddff}' +
45
52
  // 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}';
53
+ '.bw_ce_light.bw_ce{background:#fafafa;border-color:#d8d8d8}' +
54
+ '.bw_ce_light.bw_ce code{color:#1a1a1a}' +
55
+ '.bw_ce_light.bw_ce .bw_ce_keyword{color:#7c3aed}' +
56
+ '.bw_ce_light.bw_ce .bw_ce_string{color:#16a34a}' +
57
+ '.bw_ce_light.bw_ce .bw_ce_comment{color:#9ca3af;font-style:italic}' +
58
+ '.bw_ce_light.bw_ce .bw_ce_number{color:#ea580c}' +
59
+ '.bw_ce_light.bw_ce .bw_ce_operator{color:#0891b2}' +
60
+ '.bw_ce_light.bw_ce .bw_ce_punctuation{color:#6b7280}' +
61
+ '.bw_ce_light.bw_ce .bw_ce_property{color:#2563eb}' +
62
+ '.bw_ce_light.bw_ce .bw_ce_function{color:#2563eb}' +
63
+ '.bw_ce_light.bw_ce .bw_ce_tag{color:#dc2626}' +
64
+ '.bw_ce_light.bw_ce .bw_ce_attr_name{color:#d97706}' +
65
+ '.bw_ce_light.bw_ce .bw_ce_attr_value{color:#16a34a}' +
66
+ '.bw_ce_light.bw_ce .bw_ce_selector{color:#7c3aed}' +
67
+ '.bw_ce_light.bw_ce .bw_ce_css_prop{color:#2563eb}' +
68
+ '.bw_ce_light.bw_ce .bw_ce_css_value{color:#ea580c}' +
69
+ '.bw_ce_light.bw_ce .bw_ce_at_rule{color:#7c3aed}' +
70
+ '.bw_ce_light.bw_ce .bw_ce_color{color:#ea580c}' +
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;
68
80
  _cssInjected = true;
69
81
  if (bw && bw.injectCSS) {
70
- bw.injectCSS(CSS_TEXT, { id: 'bw-code-edit-styles' });
82
+ bw.injectCSS(CSS_TEXT, { id: 'bw_code_edit_styles' });
71
83
  }
72
84
  }
73
85
 
@@ -490,7 +502,7 @@
490
502
  if (tok.type === 'plain') {
491
503
  result.push(tok.text);
492
504
  } else {
493
- result.push({ t: 'span', a: { class: 'bw-ce-' + tok.type }, c: tok.text });
505
+ result.push({ t: 'span', a: { class: 'bw_ce_' + tok.type }, c: tok.text });
494
506
  }
495
507
  }
496
508
  return result;
@@ -544,46 +556,83 @@
544
556
  var lang = opts.lang || 'js';
545
557
  var height = opts.height || '180px';
546
558
  var readOnly = !!opts.readOnly;
547
- var className = 'bw-ce' + (opts.className ? ' ' + opts.className : '');
559
+ var showLineNumbers = !!opts.lineNumbers;
560
+ var className = 'bw_ce' + (opts.className ? ' ' + opts.className : '');
548
561
 
549
562
  var highlighted = highlight(code, lang);
550
563
 
551
564
  var codeAttrs = {
552
565
  spellcheck: 'false',
553
- class: 'bw-ce-code'
566
+ class: 'bw_ce_code'
554
567
  };
555
568
  if (!readOnly) {
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
- var codeEl = el.querySelector('.bw-ce-code');
594
+ var codeEl = el.querySelector('.bw_ce_code');
568
595
  if (!codeEl) return;
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