bitwrench 2.0.13 → 2.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/dist/bitwrench-code-edit.cjs.js +46 -46
- package/dist/bitwrench-code-edit.cjs.min.js +16 -0
- package/dist/bitwrench-code-edit.es5.js +8 -8
- package/dist/bitwrench-code-edit.es5.min.js +2 -2
- package/dist/bitwrench-code-edit.esm.js +46 -46
- package/dist/bitwrench-code-edit.esm.min.js +2 -2
- package/dist/bitwrench-code-edit.umd.js +46 -46
- package/dist/bitwrench-code-edit.umd.min.js +2 -2
- package/dist/bitwrench-lean.cjs.js +5011 -3419
- package/dist/bitwrench-lean.cjs.min.js +35 -6
- package/dist/bitwrench-lean.es5.js +6218 -4272
- package/dist/bitwrench-lean.es5.min.js +32 -3
- package/dist/bitwrench-lean.esm.js +5011 -3419
- package/dist/bitwrench-lean.esm.min.js +35 -6
- package/dist/bitwrench-lean.umd.js +5011 -3419
- package/dist/bitwrench-lean.umd.min.js +35 -6
- package/dist/bitwrench.cjs.js +6966 -4662
- package/dist/bitwrench.cjs.min.js +38 -8
- package/dist/bitwrench.css +2453 -4784
- package/dist/bitwrench.es5.js +9592 -6813
- package/dist/bitwrench.es5.min.js +34 -5
- package/dist/bitwrench.esm.js +6966 -4662
- package/dist/bitwrench.esm.min.js +38 -8
- package/dist/bitwrench.min.css +1 -0
- package/dist/bitwrench.umd.js +6966 -4662
- package/dist/bitwrench.umd.min.js +38 -8
- package/dist/builds.json +89 -67
- package/dist/sri.json +28 -26
- package/package.json +7 -5
- package/readme.html +14 -14
- package/src/{bitwrench-components-v2.js → bitwrench-bccl.js} +1311 -600
- package/src/bitwrench-code-edit.js +45 -45
- package/src/bitwrench-color-utils.js +154 -27
- package/src/bitwrench-components-stub.js +4 -1
- package/src/bitwrench-file-ops.js +180 -0
- package/src/bitwrench-lean.js +2 -2
- package/src/bitwrench-styles.js +1468 -3494
- package/src/bitwrench-utils.js +458 -0
- package/src/bitwrench.js +1795 -1349
- package/src/cli/layout-default.js +18 -18
- package/src/generate-css.js +73 -53
- package/src/version.js +3 -3
- package/src/bitwrench-component-base.js +0 -736
- package/src/bitwrench-components-inline.js +0 -374
- package/src/bitwrench-components.js +0 -610
package/README.md
CHANGED
|
@@ -53,7 +53,7 @@ Or include directly in a page:
|
|
|
53
53
|
- **HTML from plain objects** — describe UI as JavaScript objects, render to live DOM with `bw.DOM()` or to HTML strings with `bw.html()` for server-side rendering, emails, and static pages
|
|
54
54
|
- **Built-in reactivity** — `bw.update()` re-renders components when state changes, `bw.patch()` updates individual elements by ID, `bw.pub()`/`bw.sub()` provides decoupled messaging between any part of the application
|
|
55
55
|
- **CSS and theme generation** — `bw.css()` generates stylesheets from objects, `bw.generateTheme()` derives a complete visual theme (buttons, alerts, badges, cards, forms, tables, dark mode) from 2-3 seed colors
|
|
56
|
-
- **
|
|
56
|
+
- **45+ ready-made components** — cards, buttons, sortable tables, form inputs, modals, dropdowns, accordions, tooltips, popovers, toasts, timelines, steppers, file uploads, stat cards — each a single function call that returns a composable object
|
|
57
57
|
- **Static site CLI** — the `bitwrench` command converts Markdown, HTML, and JSON files into styled, self-contained pages with theme support
|
|
58
58
|
- **Utilities** — color interpolation, random data generation, lorem ipsum, cookies, URL params, file I/O for both browser and Node.js
|
|
59
59
|
|
|
@@ -130,7 +130,7 @@ bw.generateTheme('my-theme', {
|
|
|
130
130
|
secondary: '#cc6633'
|
|
131
131
|
});
|
|
132
132
|
|
|
133
|
-
bw.
|
|
133
|
+
bw.toggleTheme(); // switch between primary and alternate palettes
|
|
134
134
|
```
|
|
135
135
|
|
|
136
136
|
## Core API
|
|
@@ -186,14 +186,14 @@ All formats include source maps. A separate CSS file (`bitwrench.css`) is also a
|
|
|
186
186
|
- [State & Interactivity](https://deftio.github.io/bitwrench/pages/05-state.html) — `bw.patch()`, `bw.update()`, pub/sub
|
|
187
187
|
- [Tic Tac Toe Tutorial](https://deftio.github.io/bitwrench/pages/06-tic-tac-toe-tutorial.html) — step-by-step game with state management
|
|
188
188
|
- [Framework Comparison](https://deftio.github.io/bitwrench/pages/07-framework-comparison.html) — bitwrench vs React, Vue, Svelte
|
|
189
|
-
- [
|
|
189
|
+
- [Themes](https://deftio.github.io/bitwrench/pages/10-themes.html) — interactive theme generator with presets, dark mode, and CSS export
|
|
190
190
|
|
|
191
191
|
## Development
|
|
192
192
|
|
|
193
193
|
```bash
|
|
194
194
|
npm install # install dev dependencies
|
|
195
195
|
npm run build # build all dist formats (UMD, ESM, CJS, ES5)
|
|
196
|
-
npm test # run unit tests (
|
|
196
|
+
npm test # run unit tests (558 tests)
|
|
197
197
|
npm run test:cli # run CLI tests (49 tests)
|
|
198
198
|
npm run test:e2e # run Playwright browser tests
|
|
199
199
|
npm run lint # run ESLint
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! bitwrench v2.0.
|
|
1
|
+
/*! bitwrench v2.0.15 | BSD-2-Clause | https://deftio.github.com/bitwrench/pages */
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
@@ -19,53 +19,53 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
19
19
|
// -- CSS (injected once) ----------------------------------------------
|
|
20
20
|
var _cssInjected = false;
|
|
21
21
|
var CSS_TEXT =
|
|
22
|
-
'.
|
|
23
|
-
'.
|
|
24
|
-
'.
|
|
25
|
-
'.
|
|
26
|
-
'.
|
|
27
|
-
'.
|
|
28
|
-
'.
|
|
29
|
-
'.
|
|
30
|
-
'.
|
|
31
|
-
'.
|
|
32
|
-
'.
|
|
33
|
-
'.
|
|
34
|
-
'.
|
|
35
|
-
'.
|
|
36
|
-
'.
|
|
37
|
-
'.
|
|
38
|
-
'.
|
|
39
|
-
'.
|
|
40
|
-
'.
|
|
41
|
-
'.
|
|
42
|
-
'.
|
|
22
|
+
'.bw_ce{background:#1e293b;border-radius:6px;border:1px solid rgba(255,255,255,0.08);overflow:auto}' +
|
|
23
|
+
'.bw_ce pre{margin:0;padding:0}' +
|
|
24
|
+
'.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}' +
|
|
25
|
+
'.bw_ce code:empty::before{content:"\\200b"}' +
|
|
26
|
+
'.bw_ce .bw_ce_keyword{color:#c792ea}' +
|
|
27
|
+
'.bw_ce .bw_ce_string{color:#c3e88d}' +
|
|
28
|
+
'.bw_ce .bw_ce_comment{color:#546e7a;font-style:italic}' +
|
|
29
|
+
'.bw_ce .bw_ce_number{color:#f78c6c}' +
|
|
30
|
+
'.bw_ce .bw_ce_operator{color:#89ddff}' +
|
|
31
|
+
'.bw_ce .bw_ce_punctuation{color:#89ddff}' +
|
|
32
|
+
'.bw_ce .bw_ce_property{color:#82aaff}' +
|
|
33
|
+
'.bw_ce .bw_ce_function{color:#82aaff}' +
|
|
34
|
+
'.bw_ce .bw_ce_tag{color:#f07178}' +
|
|
35
|
+
'.bw_ce .bw_ce_attr_name{color:#ffcb6b}' +
|
|
36
|
+
'.bw_ce .bw_ce_attr_value{color:#c3e88d}' +
|
|
37
|
+
'.bw_ce .bw_ce_selector{color:#c792ea}' +
|
|
38
|
+
'.bw_ce .bw_ce_css_prop{color:#82aaff}' +
|
|
39
|
+
'.bw_ce .bw_ce_css_value{color:#f78c6c}' +
|
|
40
|
+
'.bw_ce .bw_ce_at_rule{color:#c792ea;font-style:italic}' +
|
|
41
|
+
'.bw_ce .bw_ce_color{color:#f78c6c}' +
|
|
42
|
+
'.bw_ce .bw_ce_template_interp{color:#89ddff}' +
|
|
43
43
|
// Light theme
|
|
44
|
-
'.
|
|
45
|
-
'.
|
|
46
|
-
'.
|
|
47
|
-
'.
|
|
48
|
-
'.
|
|
49
|
-
'.
|
|
50
|
-
'.
|
|
51
|
-
'.
|
|
52
|
-
'.
|
|
53
|
-
'.
|
|
54
|
-
'.
|
|
55
|
-
'.
|
|
56
|
-
'.
|
|
57
|
-
'.
|
|
58
|
-
'.
|
|
59
|
-
'.
|
|
60
|
-
'.
|
|
61
|
-
'.
|
|
62
|
-
'.
|
|
44
|
+
'.bw_ce_light.bw_ce{background:#fafafa;border-color:#d8d8d8}' +
|
|
45
|
+
'.bw_ce_light.bw_ce code{color:#1a1a1a}' +
|
|
46
|
+
'.bw_ce_light.bw_ce .bw_ce_keyword{color:#7c3aed}' +
|
|
47
|
+
'.bw_ce_light.bw_ce .bw_ce_string{color:#16a34a}' +
|
|
48
|
+
'.bw_ce_light.bw_ce .bw_ce_comment{color:#9ca3af;font-style:italic}' +
|
|
49
|
+
'.bw_ce_light.bw_ce .bw_ce_number{color:#ea580c}' +
|
|
50
|
+
'.bw_ce_light.bw_ce .bw_ce_operator{color:#0891b2}' +
|
|
51
|
+
'.bw_ce_light.bw_ce .bw_ce_punctuation{color:#6b7280}' +
|
|
52
|
+
'.bw_ce_light.bw_ce .bw_ce_property{color:#2563eb}' +
|
|
53
|
+
'.bw_ce_light.bw_ce .bw_ce_function{color:#2563eb}' +
|
|
54
|
+
'.bw_ce_light.bw_ce .bw_ce_tag{color:#dc2626}' +
|
|
55
|
+
'.bw_ce_light.bw_ce .bw_ce_attr_name{color:#d97706}' +
|
|
56
|
+
'.bw_ce_light.bw_ce .bw_ce_attr_value{color:#16a34a}' +
|
|
57
|
+
'.bw_ce_light.bw_ce .bw_ce_selector{color:#7c3aed}' +
|
|
58
|
+
'.bw_ce_light.bw_ce .bw_ce_css_prop{color:#2563eb}' +
|
|
59
|
+
'.bw_ce_light.bw_ce .bw_ce_css_value{color:#ea580c}' +
|
|
60
|
+
'.bw_ce_light.bw_ce .bw_ce_at_rule{color:#7c3aed}' +
|
|
61
|
+
'.bw_ce_light.bw_ce .bw_ce_color{color:#ea580c}' +
|
|
62
|
+
'.bw_ce_light.bw_ce .bw_ce_template_interp{color:#0891b2}';
|
|
63
63
|
|
|
64
64
|
function ensureCSS(bw) {
|
|
65
65
|
if (_cssInjected) return;
|
|
66
66
|
_cssInjected = true;
|
|
67
67
|
if (bw && bw.injectCSS) {
|
|
68
|
-
bw.injectCSS(CSS_TEXT, { id: '
|
|
68
|
+
bw.injectCSS(CSS_TEXT, { id: 'bw_code_edit_styles' });
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
|
|
@@ -488,7 +488,7 @@ function tokensToTACO(tokArr) {
|
|
|
488
488
|
if (tok.type === 'plain') {
|
|
489
489
|
result.push(tok.text);
|
|
490
490
|
} else {
|
|
491
|
-
result.push({ t: 'span', a: { class: '
|
|
491
|
+
result.push({ t: 'span', a: { class: 'bw_ce_' + tok.type }, c: tok.text });
|
|
492
492
|
}
|
|
493
493
|
}
|
|
494
494
|
return result;
|
|
@@ -542,13 +542,13 @@ function codeEditor(opts) {
|
|
|
542
542
|
var lang = opts.lang || 'js';
|
|
543
543
|
var height = opts.height || '180px';
|
|
544
544
|
var readOnly = !!opts.readOnly;
|
|
545
|
-
var className = '
|
|
545
|
+
var className = 'bw_ce' + (opts.className ? ' ' + opts.className : '');
|
|
546
546
|
|
|
547
547
|
var highlighted = highlight(code, lang);
|
|
548
548
|
|
|
549
549
|
var codeAttrs = {
|
|
550
550
|
spellcheck: 'false',
|
|
551
|
-
class: '
|
|
551
|
+
class: 'bw_ce_code'
|
|
552
552
|
};
|
|
553
553
|
if (!readOnly) {
|
|
554
554
|
codeAttrs.contenteditable = 'true';
|
|
@@ -562,7 +562,7 @@ function codeEditor(opts) {
|
|
|
562
562
|
],
|
|
563
563
|
o: {
|
|
564
564
|
mounted: function(el) {
|
|
565
|
-
var codeEl = el.querySelector('.
|
|
565
|
+
var codeEl = el.querySelector('.bw_ce_code');
|
|
566
566
|
if (!codeEl) return;
|
|
567
567
|
|
|
568
568
|
var currentCode = code;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/*! bitwrench v2.0.15 | BSD-2-Clause | https://deftio.github.com/bitwrench/pages */
|
|
2
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});
|
|
3
|
+
/**
|
|
4
|
+
* bitwrench-code-edit.js - syntax-highlighted contenteditable code editor addon
|
|
5
|
+
*
|
|
6
|
+
* Provides bw.highlight() for tokenizing JS/CSS/HTML into TACO spans,
|
|
7
|
+
* and bw.codeEditor() for a live editable code block with syntax coloring.
|
|
8
|
+
*
|
|
9
|
+
* Can be loaded standalone (browser script tag after bitwrench.umd.js),
|
|
10
|
+
* or imported as an ES module / CJS module.
|
|
11
|
+
*
|
|
12
|
+
* @module bitwrench-code-edit
|
|
13
|
+
* @license BSD-2-Clause
|
|
14
|
+
*/
|
|
15
|
+
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 o={};function c(e){var t=[],r=0,n=e.length,a="";function l(e){a.length&&(t.push({type:e,text:a}),a="")}for(;r<n;){var s=e[r],i=e[r+1];if("/"!==s||"/"!==i)if("/"!==s||"*"!==i){if("/"===s&&"/"!==i&&"*"!==i){var p=t.length?t[t.length-1]:null,_=!1;if(a.trim().length||p&&"operator"!==p.type&&"punctuation"!==p.type&&"keyword"!==p.type||(_=!0),_){l("plain");for(var u="/",f=r+1,b=!1,w=!1;f<n;){var 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}),r=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,r+=2;r<n&&/[0-9a-fA-F_]/.test(e[r]);)h+=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])?(h+=e[r],r++):(h+=e[r]+e[r+1],r+=2);t.push({type:"number",text:h})}else if(/[a-zA-Z_$]/.test(s)){l("plain");for(var g="";r<n&&/[a-zA-Z0-9_$]/.test(e[r]);)g+=e[r],r++;for(var v=r;v<n&&(" "===e[v]||"\t"===e[v]);)v++;var x=t.length?t[t.length-1]:null,y=x&&"punctuation"===x.type&&"."===x.text;o[g]?t.push({type:"keyword",text:g}):y?v<n&&"("===e[v]?t.push({type:"function",text:g}):t.push({type:"property",text:g}):v<n&&"("===e[v]?t.push({type:"function",text:g}):t.push({type:"plain",text:g})}else if(-1==="=+-*/%!<>&|^~?:".indexOf(s))-1==="(){}[];,.".indexOf(s)?(a+=s,r++):(l("plain"),t.push({type:"punctuation",text:s}),r++);else{l("plain");var m=s;++r<n&&-1!=="=+-*/%!<>&|^~?:".indexOf(e[r])&&(m+=e[r],++r<n&&-1!=="=>&|".indexOf(e[r])&&(m+=e[r],r++)),t.push({type:"operator",text:m})}else{l("plain");var k=s,C=s,S=r+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=c(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})}r=S}}else{l("plain");var R=e.indexOf("*/",r+2);-1===R&&(R=n-2),t.push({type:"comment",text:e.substring(r,R+2)}),r=R+2}else{l("plain");var Z=e.indexOf("\n",r);-1===Z&&(Z=n),t.push({type:"comment",text:e.substring(r,Z)}),r=Z}}return l("plain"),t}function r(e){var t=[],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],s=e[o+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="";o<c&&/[0-9.]/.test(e[o]);)i+=e[o],o++;for(var p="";o<c&&/[a-zA-Z%]/.test(e[o]);)p+=e[o],o++;t.push({type:"number",text:i+p})}else"{"!==l?"}"!==l?":"!==l||"prop"!==r?";"!==l?","!==l?(n+=l,o++):(a("selector"===r?"selector":"value"===r?"css-value":"plain"),t.push({type:"punctuation",text:l}),o++):(a("value"===r?"css-value":"plain"),t.push({type:"punctuation",text:l}),r="prop",o++):(a("css-prop"),t.push({type:"punctuation",text:l}),r="value",o++):(a("prop"===r?"css-prop":"value"===r?"css-value":"plain"),t.push({type:"punctuation",text:l}),r="selector",o++):(a("selector"===r?"selector":"plain"),t.push({type:"punctuation",text:l}),r="prop",o++);else{a("css-value");var _="#";for(o++;o<c&&/[0-9a-fA-F]/.test(e[o]);)_+=e[o],o++;t.push({type:"color",text:_})}else{a("selector");var u="@";for(o++;o<c&&/[a-zA-Z\-]/.test(e[o]);)u+=e[o],o++;t.push({type:"at-rule",text:u})}else{a("selector"===r?"selector":"css-value");var f=l,b=l;for(o++;o<c;)if("\\"!==e[o]){if(e[o]===f){b+=e[o],o++;break}b+=e[o],o++}else b+=e[o]+(e[o+1]||""),o+=2;t.push({type:"string",text:b})}else{a("selector"===r?"selector":"prop"===r?"css-prop":"css-value");var w=e.indexOf("*/",o+2);-1===w&&(w=c-2),t.push({type:"comment",text:e.substring(o,w+2)}),o=w+2}}return a("selector"===r?"selector":"prop"===r?"css-prop":"css-value"),t}function n(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 s="<";for(++o<c&&"/"===e[o]&&(s+="/",o++);o<c&&/[a-zA-Z0-9\-]/.test(e[o]);)s+=e[o],o++;for(t.push({type:"tag",text:s});o<c&&">"!==e[o]&&("/"!==e[o]||">"!==e[o+1]);)if(/\s/.test(e[o])){for(var i="";o<c&&/\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<c&&/[a-zA-Z0-9_\-@:]/.test(e[o]);)p+=e[o],o++;if(t.push({type:"attr-name",text:p}),o<c&&"="===e[o])if(t.push({type:"punctuation",text:"="}),++o<c&&('"'===e[o]||"'"===e[o])){var _=e[o],u=_;for(o++;o<c&&e[o]!==_;)u+=e[o],o++;o<c&&(u+=e[o],o++),t.push({type:"attr-value",text:u})}else{for(var f="";o<c&&!/[\s>]/.test(e[o]);)f+=e[o],o++;t.push({type:"attr-value",text:f})}}else r+=e[o],o++,n("plain");var b="";o<c&&"/"===e[o]&&(b+="/",o++),o<c&&">"===e[o]&&(b+=">",o++),b&&t.push({type:"tag",text:b})}else{n("plain");var w=e.indexOf("--\x3e",o+4);-1===w&&(w=c-3),t.push({type:"comment",text:e.substring(o,w+3)}),o=w+3}}return n("plain"),t}"var,const,let,function,return,if,else,for,while,do,switch,case,break,continue,new,typeof,instanceof,this,class,extends,import,export,default,from,true,false,null,undefined,try,catch,throw,finally,async,await,yield,of,in,delete,void,with,super,static,get,set,debugger".split(",").forEach(function(e){o[e]=!0});var a={js:c,javascript:c,css:r,html:n};function l(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}((a[t]||c)(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=l(t,o),s={spellcheck:"false",class:"bw_ce_code"};return r||(s.contenteditable="true"),{t:"div",a:{class:n,style:"max-height:"+c+";overflow:auto"},c:[{t:"pre",c:{t:"code",a:s,c:a}}],o:{mounted:function(c){var n=c.querySelector(".bw_ce_code");if(n){var a=t,s=null,i="undefined"!=typeof window&&window.bw||{};c._bwCodeEdit={getValue:p,setValue:function(e){a=e;var t=l(e,o);i.html&&(n.innerHTML=i.html({t:"span",c:t}))}},r||(n.addEventListener("input",function(){clearTimeout(s),s=setTimeout(_,50)}),n.addEventListener("keydown",function(e){"Tab"===e.key&&(e.preventDefault(),document.execCommand("insertText",!1," "))}))}function p(){return n.textContent||""}function _(){var t=p();if(t!==a){a=t;var 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=l(t,o);i.html&&(n.innerHTML=i.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 i(o){o&&(o.highlight=l,o.codeEditor=function(c){return function(o){e||(e=!0,o&&o.injectCSS&&o.injectCSS(t,{id:"bw_code_edit_styles"}))}(o),s(c)})}"undefined"!=typeof window&&window.bw&&i(window.bw);var p={highlight:l,codeEditor:s,install:i,CSS_TEXT:t};exports.CSS_TEXT=t,exports.codeEditor=s,exports.default=p,exports.highlight=l,exports.install=i,exports.tokenizeCSS=r,exports.tokenizeHTML=n,exports.tokenizeJS=c;
|
|
16
|
+
//# sourceMappingURL=bitwrench-code-edit.cjs.min.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! bitwrench v2.0.
|
|
1
|
+
/*! bitwrench v2.0.15 | 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) :
|
|
@@ -20,15 +20,15 @@
|
|
|
20
20
|
|
|
21
21
|
// -- CSS (injected once) ----------------------------------------------
|
|
22
22
|
var _cssInjected = false;
|
|
23
|
-
var CSS_TEXT = '.
|
|
23
|
+
var CSS_TEXT = '.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}' +
|
|
24
24
|
// Light theme
|
|
25
|
-
'.
|
|
25
|
+
'.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}';
|
|
26
26
|
function ensureCSS(bw) {
|
|
27
27
|
if (_cssInjected) return;
|
|
28
28
|
_cssInjected = true;
|
|
29
29
|
if (bw && bw.injectCSS) {
|
|
30
30
|
bw.injectCSS(CSS_TEXT, {
|
|
31
|
-
id: '
|
|
31
|
+
id: 'bw_code_edit_styles'
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
34
|
}
|
|
@@ -703,7 +703,7 @@
|
|
|
703
703
|
result.push({
|
|
704
704
|
t: 'span',
|
|
705
705
|
a: {
|
|
706
|
-
"class": '
|
|
706
|
+
"class": 'bw_ce_' + tok.type
|
|
707
707
|
},
|
|
708
708
|
c: tok.text
|
|
709
709
|
});
|
|
@@ -759,11 +759,11 @@
|
|
|
759
759
|
var lang = opts.lang || 'js';
|
|
760
760
|
var height = opts.height || '180px';
|
|
761
761
|
var readOnly = !!opts.readOnly;
|
|
762
|
-
var className = '
|
|
762
|
+
var className = 'bw_ce' + (opts.className ? ' ' + opts.className : '');
|
|
763
763
|
var highlighted = highlight(code, lang);
|
|
764
764
|
var codeAttrs = {
|
|
765
765
|
spellcheck: 'false',
|
|
766
|
-
"class": '
|
|
766
|
+
"class": 'bw_ce_code'
|
|
767
767
|
};
|
|
768
768
|
if (!readOnly) {
|
|
769
769
|
codeAttrs.contenteditable = 'true';
|
|
@@ -784,7 +784,7 @@
|
|
|
784
784
|
}],
|
|
785
785
|
o: {
|
|
786
786
|
mounted: function mounted(el) {
|
|
787
|
-
var codeEl = el.querySelector('.
|
|
787
|
+
var codeEl = el.querySelector('.bw_ce_code');
|
|
788
788
|
if (!codeEl) return;
|
|
789
789
|
var currentCode = code;
|
|
790
790
|
var debounceTimer = null;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! bitwrench v2.0.
|
|
1
|
+
/*! bitwrench v2.0.15 | 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
|
|
@@ -11,5 +11,5 @@
|
|
|
11
11
|
*
|
|
12
12
|
* @module bitwrench-code-edit
|
|
13
13
|
* @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})});
|
|
14
|
+
*/var t=!1,o='.bw_ce{background:#1e293b;border-radius:6px;border:1px solid rgba(255,255,255,0.08);overflow:auto}.bw_ce pre{margin:0;padding:0}.bw_ce code{font-family:"SF Mono",Monaco,"Cascadia Code",Consolas,monospace;font-size:0.875rem;line-height:1.6;color:#e2e8f0;outline:none;white-space:pre-wrap;display:block;padding:0.75rem 1rem}.bw_ce code:empty::before{content:"\\200b"}.bw_ce .bw_ce_keyword{color:#c792ea}.bw_ce .bw_ce_string{color:#c3e88d}.bw_ce .bw_ce_comment{color:#546e7a;font-style:italic}.bw_ce .bw_ce_number{color:#f78c6c}.bw_ce .bw_ce_operator{color:#89ddff}.bw_ce .bw_ce_punctuation{color:#89ddff}.bw_ce .bw_ce_property{color:#82aaff}.bw_ce .bw_ce_function{color:#82aaff}.bw_ce .bw_ce_tag{color:#f07178}.bw_ce .bw_ce_attr_name{color:#ffcb6b}.bw_ce .bw_ce_attr_value{color:#c3e88d}.bw_ce .bw_ce_selector{color:#c792ea}.bw_ce .bw_ce_css_prop{color:#82aaff}.bw_ce .bw_ce_css_value{color:#f78c6c}.bw_ce .bw_ce_at_rule{color:#c792ea;font-style:italic}.bw_ce .bw_ce_color{color:#f78c6c}.bw_ce .bw_ce_template_interp{color:#89ddff}.bw_ce_light.bw_ce{background:#fafafa;border-color:#d8d8d8}.bw_ce_light.bw_ce code{color:#1a1a1a}.bw_ce_light.bw_ce .bw_ce_keyword{color:#7c3aed}.bw_ce_light.bw_ce .bw_ce_string{color:#16a34a}.bw_ce_light.bw_ce .bw_ce_comment{color:#9ca3af;font-style:italic}.bw_ce_light.bw_ce .bw_ce_number{color:#ea580c}.bw_ce_light.bw_ce .bw_ce_operator{color:#0891b2}.bw_ce_light.bw_ce .bw_ce_punctuation{color:#6b7280}.bw_ce_light.bw_ce .bw_ce_property{color:#2563eb}.bw_ce_light.bw_ce .bw_ce_function{color:#2563eb}.bw_ce_light.bw_ce .bw_ce_tag{color:#dc2626}.bw_ce_light.bw_ce .bw_ce_attr_name{color:#d97706}.bw_ce_light.bw_ce .bw_ce_attr_value{color:#16a34a}.bw_ce_light.bw_ce .bw_ce_selector{color:#7c3aed}.bw_ce_light.bw_ce .bw_ce_css_prop{color:#2563eb}.bw_ce_light.bw_ce .bw_ce_css_value{color:#ea580c}.bw_ce_light.bw_ce .bw_ce_at_rule{color:#7c3aed}.bw_ce_light.bw_ce .bw_ce_color{color:#ea580c}.bw_ce_light.bw_ce .bw_ce_template_interp{color:#0891b2}';var c={};function r(e){var t=[],o=0,n=e.length,a="";function l(e){a.length&&(t.push({type:e,text:a}),a="")}for(;o<n;){var i=e[o],s=e[o+1];if("/"!==i||"/"!==s)if("/"!==i||"*"!==s){if("/"===i&&"/"!==s&&"*"!==s){var p=t.length?t[t.length-1]:null,_=!1;if(a.trim().length||p&&"operator"!==p.type&&"punctuation"!==p.type&&"keyword"!==p.type||(_=!0),_){l("plain");for(var u="/",f=o+1,b=!1,w=!1;f<n;){var d=e[f];if(b)u+=d,b=!1,f++;else if("\\"!==d)if("["!==d)if("]"!==d){if("/"===d&&!w){u+=d,f++;break}if("\n"===d)break;u+=d,f++}else w=!1,u+=d,f++;else w=!0,u+=d,f++;else b=!0,u+=d,f++}for(;f<n&&/[gimsuvy]/.test(e[f]);)u+=e[f],f++;t.push({type:"string",text:u}),o=f;continue}}if('"'!==i&&"'"!==i&&"`"!==i)if(/[0-9]/.test(i)||"."===i&&s&&/[0-9]/.test(s)){l("plain");var h="";if("0"===i&&s&&/[xXbBoO]/.test(s))for(h=i+s,o+=2;o<n&&/[0-9a-fA-F_]/.test(e[o]);)h+=e[o],o++;else for(;o<n&&/[0-9._eE]/.test(e[o]);)"e"!==e[o]&&"E"!==e[o]||!e[o+1]||!/[+\-0-9]/.test(e[o+1])?(h+=e[o],o++):(h+=e[o]+e[o+1],o+=2);t.push({type:"number",text:h})}else if(/[a-zA-Z_$]/.test(i)){l("plain");for(var g="";o<n&&/[a-zA-Z0-9_$]/.test(e[o]);)g+=e[o],o++;for(var v=o;v<n&&(" "===e[v]||"\t"===e[v]);)v++;var y=t.length?t[t.length-1]:null,x=y&&"punctuation"===y.type&&"."===y.text;c[g]?t.push({type:"keyword",text:g}):x?v<n&&"("===e[v]?t.push({type:"function",text:g}):t.push({type:"property",text:g}):v<n&&"("===e[v]?t.push({type:"function",text:g}):t.push({type:"plain",text:g})}else if(-1==="=+-*/%!<>&|^~?:".indexOf(i))-1==="(){}[];,.".indexOf(i)?(a+=i,o++):(l("plain"),t.push({type:"punctuation",text:i}),o++);else{l("plain");var m=i;++o<n&&-1!=="=+-*/%!<>&|^~?:".indexOf(e[o])&&(m+=e[o],++o<n&&-1!=="=>&|".indexOf(e[o])&&(m+=e[o],o++)),t.push({type:"operator",text:m})}else{l("plain");var k=i,C=i,S=o+1;if("`"===k){for(;S<n;){var T=e[S];if("\\"!==T)if("$"!==T||"{"!==e[S+1]){if("`"===T){C+=T,S++;break}C+=T,S++}else{C.length&&t.push({type:"string",text:C}),C="",t.push({type:"template-interp",text:"${"}),S+=2;for(var A=1,E="";S<n&&A>0;){if("{"===e[S])A++;else if("}"===e[S]&&0===--A)break;E+=e[S],S++}var O=r(E);(t=t.concat(O)).push({type:"template-interp",text:"}"}),S++}else C+=T+(e[S+1]||""),S+=2}C.length&&t.push({type:"string",text:C})}else{for(;S<n;){var z=e[S];if("\\"!==z){if(z===k){C+=z,S++;break}if("\n"===z)break;C+=z,S++}else C+=z+(e[S+1]||""),S+=2}t.push({type:"string",text:C})}o=S}}else{l("plain");var R=e.indexOf("*/",o+2);-1===R&&(R=n-2),t.push({type:"comment",text:e.substring(o,R+2)}),o=R+2}else{l("plain");var Z=e.indexOf("\n",o);-1===Z&&(Z=n),t.push({type:"comment",text:e.substring(o,Z)}),o=Z}}return l("plain"),t}function n(e){var t=[],o=0,c=e.length,r="selector",n="";function a(e){n.length&&(t.push({type:e||"plain",text:n}),n="")}for(;o<c;){var l=e[o],i=e[o+1];if("/"!==l||"*"!==i)if('"'!==l&&"'"!==l||"value"!==r&&"selector"!==r)if("@"!==l||"selector"!==r)if("#"!==l||"value"!==r)if("value"===r&&/[0-9]/.test(l)){a("css-value");for(var s="";o<c&&/[0-9.]/.test(e[o]);)s+=e[o],o++;for(var p="";o<c&&/[a-zA-Z%]/.test(e[o]);)p+=e[o],o++;t.push({type:"number",text:s+p})}else"{"!==l?"}"!==l?":"!==l||"prop"!==r?";"!==l?","!==l?(n+=l,o++):(a("selector"===r?"selector":"value"===r?"css-value":"plain"),t.push({type:"punctuation",text:l}),o++):(a("value"===r?"css-value":"plain"),t.push({type:"punctuation",text:l}),r="prop",o++):(a("css-prop"),t.push({type:"punctuation",text:l}),r="value",o++):(a("prop"===r?"css-prop":"value"===r?"css-value":"plain"),t.push({type:"punctuation",text:l}),r="selector",o++):(a("selector"===r?"selector":"plain"),t.push({type:"punctuation",text:l}),r="prop",o++);else{a("css-value");var _="#";for(o++;o<c&&/[0-9a-fA-F]/.test(e[o]);)_+=e[o],o++;t.push({type:"color",text:_})}else{a("selector");var u="@";for(o++;o<c&&/[a-zA-Z\-]/.test(e[o]);)u+=e[o],o++;t.push({type:"at-rule",text:u})}else{a("selector"===r?"selector":"css-value");var f=l,b=l;for(o++;o<c;)if("\\"!==e[o]){if(e[o]===f){b+=e[o],o++;break}b+=e[o],o++}else b+=e[o]+(e[o+1]||""),o+=2;t.push({type:"string",text:b})}else{a("selector"===r?"selector":"prop"===r?"css-prop":"css-value");var w=e.indexOf("*/",o+2);-1===w&&(w=c-2),t.push({type:"comment",text:e.substring(o,w+2)}),o=w+2}}return a("selector"===r?"selector":"prop"===r?"css-prop":"css-value"),t}function a(e){var t=[],o=0,c=e.length,r="";function n(e){r.length&&(t.push({type:e,text:r}),r="")}for(;o<c;){var a=e[o];if("<"!==a||"\x3c!--"!==e.substring(o,o+4))if("<"!==a)if("&"!==a)r+=a,o++;else{n("plain");var l="&";for(o++;o<c&&";"!==e[o]&&/[a-zA-Z0-9#]/.test(e[o]);)l+=e[o],o++;o<c&&";"===e[o]&&(l+=";",o++),t.push({type:"string",text:l})}else{n("plain");var i="<";for(++o<c&&"/"===e[o]&&(i+="/",o++);o<c&&/[a-zA-Z0-9\-]/.test(e[o]);)i+=e[o],o++;for(t.push({type:"tag",text:i});o<c&&">"!==e[o]&&("/"!==e[o]||">"!==e[o+1]);)if(/\s/.test(e[o])){for(var s="";o<c&&/\s/.test(e[o]);)s+=e[o],o++;t.push({type:"plain",text:s})}else if(/[a-zA-Z_\-@:]/.test(e[o])){for(var p="";o<c&&/[a-zA-Z0-9_\-@:]/.test(e[o]);)p+=e[o],o++;if(t.push({type:"attr-name",text:p}),o<c&&"="===e[o])if(t.push({type:"punctuation",text:"="}),++o<c&&('"'===e[o]||"'"===e[o])){var _=e[o],u=_;for(o++;o<c&&e[o]!==_;)u+=e[o],o++;o<c&&(u+=e[o],o++),t.push({type:"attr-value",text:u})}else{for(var f="";o<c&&!/[\s>]/.test(e[o]);)f+=e[o],o++;t.push({type:"attr-value",text:f})}}else r+=e[o],o++,n("plain");var b="";o<c&&"/"===e[o]&&(b+="/",o++),o<c&&">"===e[o]&&(b+=">",o++),b&&t.push({type:"tag",text:b})}else{n("plain");var w=e.indexOf("--\x3e",o+4);-1===w&&(w=c-3),t.push({type:"comment",text:e.substring(o,w+3)}),o=w+3}}return n("plain"),t}"var,const,let,function,return,if,else,for,while,do,switch,case,break,continue,new,typeof,instanceof,this,class,extends,import,export,default,from,true,false,null,undefined,try,catch,throw,finally,async,await,yield,of,in,delete,void,with,super,static,get,set,debugger".split(",").forEach(function(e){c[e]=!0});var l={js:r,javascript:r,css:n,html:a};function i(e,t){return function(e){for(var t=[],o=0;o<e.length;o++){var c=e[o];"plain"===c.type?t.push(c.text):t.push({t:"span",a:{class:"bw_ce_"+c.type},c:c.text})}return t}((l[t]||r)(e))}function s(e){var t=(e=e||{}).code||"",o=e.lang||"js",c=e.height||"180px",r=!!e.readOnly,n="bw_ce"+(e.className?" "+e.className:""),a=i(t,o),l={spellcheck:"false",class:"bw_ce_code"};return r||(l.contenteditable="true"),{t:"div",a:{class:n,style:"max-height:"+c+";overflow:auto"},c:[{t:"pre",c:{t:"code",a:l,c:a}}],o:{mounted:function(c){var n=c.querySelector(".bw_ce_code");if(n){var a=t,l=null,s="undefined"!=typeof window&&window.bw||{};c._bwCodeEdit={getValue:p,setValue:function(e){a=e;var t=i(e,o);s.html&&(n.innerHTML=s.html({t:"span",c:t}))}},r||(n.addEventListener("input",function(){clearTimeout(l),l=setTimeout(_,50)}),n.addEventListener("keydown",function(e){"Tab"===e.key&&(e.preventDefault(),document.execCommand("insertText",!1," "))}))}function p(){return n.textContent||""}function _(){var t=p();if(t!==a){a=t;var c=function(e){var t=window.getSelection();if(!t.rangeCount)return 0;var o=t.getRangeAt(0).cloneRange();return o.selectNodeContents(e),o.setEnd(t.getRangeAt(0).startContainer,t.getRangeAt(0).startOffset),o.toString().length}(n),r=i(t,o);s.html&&(n.innerHTML=s.html({t:"span",c:r})),function(e,t){for(var o,c=window.getSelection(),r=document.createRange(),n=document.createTreeWalker(e,NodeFilter.SHOW_TEXT,null,!1),a=0;o=n.nextNode();){var l=o.textContent.length;if(a+l>=t)return r.setStart(o,t-a),r.collapse(!0),c.removeAllRanges(),void c.addRange(r);a+=l}r.selectNodeContents(e),r.collapse(!1),c.removeAllRanges(),c.addRange(r)}(n,c),e.onChange&&e.onChange(t)}}}}}}function p(e){e&&(e.highlight=i,e.codeEditor=function(c){return function(e){t||(t=!0,e&&e.injectCSS&&e.injectCSS(o,{id:"bw_code_edit_styles"}))}(e),s(c)})}"undefined"!=typeof window&&window.bw&&p(window.bw);var _={highlight:i,codeEditor:s,install:p,CSS_TEXT:o};e.CSS_TEXT=o,e.codeEditor=s,e.default=_,e.highlight=i,e.install=p,e.tokenizeCSS=n,e.tokenizeHTML=a,e.tokenizeJS=r,Object.defineProperty(e,"__esModule",{value:!0})});
|
|
15
15
|
//# sourceMappingURL=bitwrench-code-edit.es5.min.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! bitwrench v2.0.
|
|
1
|
+
/*! bitwrench v2.0.15 | 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
|
*
|
|
@@ -15,53 +15,53 @@
|
|
|
15
15
|
// -- CSS (injected once) ----------------------------------------------
|
|
16
16
|
var _cssInjected = false;
|
|
17
17
|
var CSS_TEXT =
|
|
18
|
-
'.
|
|
19
|
-
'.
|
|
20
|
-
'.
|
|
21
|
-
'.
|
|
22
|
-
'.
|
|
23
|
-
'.
|
|
24
|
-
'.
|
|
25
|
-
'.
|
|
26
|
-
'.
|
|
27
|
-
'.
|
|
28
|
-
'.
|
|
29
|
-
'.
|
|
30
|
-
'.
|
|
31
|
-
'.
|
|
32
|
-
'.
|
|
33
|
-
'.
|
|
34
|
-
'.
|
|
35
|
-
'.
|
|
36
|
-
'.
|
|
37
|
-
'.
|
|
38
|
-
'.
|
|
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}' +
|
|
39
39
|
// Light theme
|
|
40
|
-
'.
|
|
41
|
-
'.
|
|
42
|
-
'.
|
|
43
|
-
'.
|
|
44
|
-
'.
|
|
45
|
-
'.
|
|
46
|
-
'.
|
|
47
|
-
'.
|
|
48
|
-
'.
|
|
49
|
-
'.
|
|
50
|
-
'.
|
|
51
|
-
'.
|
|
52
|
-
'.
|
|
53
|
-
'.
|
|
54
|
-
'.
|
|
55
|
-
'.
|
|
56
|
-
'.
|
|
57
|
-
'.
|
|
58
|
-
'.
|
|
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}';
|
|
59
59
|
|
|
60
60
|
function ensureCSS(bw) {
|
|
61
61
|
if (_cssInjected) return;
|
|
62
62
|
_cssInjected = true;
|
|
63
63
|
if (bw && bw.injectCSS) {
|
|
64
|
-
bw.injectCSS(CSS_TEXT, { id: '
|
|
64
|
+
bw.injectCSS(CSS_TEXT, { id: 'bw_code_edit_styles' });
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
|
|
@@ -484,7 +484,7 @@ function tokensToTACO(tokArr) {
|
|
|
484
484
|
if (tok.type === 'plain') {
|
|
485
485
|
result.push(tok.text);
|
|
486
486
|
} else {
|
|
487
|
-
result.push({ t: 'span', a: { class: '
|
|
487
|
+
result.push({ t: 'span', a: { class: 'bw_ce_' + tok.type }, c: tok.text });
|
|
488
488
|
}
|
|
489
489
|
}
|
|
490
490
|
return result;
|
|
@@ -538,13 +538,13 @@ function codeEditor(opts) {
|
|
|
538
538
|
var lang = opts.lang || 'js';
|
|
539
539
|
var height = opts.height || '180px';
|
|
540
540
|
var readOnly = !!opts.readOnly;
|
|
541
|
-
var className = '
|
|
541
|
+
var className = 'bw_ce' + (opts.className ? ' ' + opts.className : '');
|
|
542
542
|
|
|
543
543
|
var highlighted = highlight(code, lang);
|
|
544
544
|
|
|
545
545
|
var codeAttrs = {
|
|
546
546
|
spellcheck: 'false',
|
|
547
|
-
class: '
|
|
547
|
+
class: 'bw_ce_code'
|
|
548
548
|
};
|
|
549
549
|
if (!readOnly) {
|
|
550
550
|
codeAttrs.contenteditable = 'true';
|
|
@@ -558,7 +558,7 @@ function codeEditor(opts) {
|
|
|
558
558
|
],
|
|
559
559
|
o: {
|
|
560
560
|
mounted: function(el) {
|
|
561
|
-
var codeEl = el.querySelector('.
|
|
561
|
+
var codeEl = el.querySelector('.bw_ce_code');
|
|
562
562
|
if (!codeEl) return;
|
|
563
563
|
|
|
564
564
|
var currentCode = code;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! bitwrench v2.0.
|
|
1
|
+
/*! bitwrench v2.0.15 | 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
|
*
|
|
@@ -11,5 +11,5 @@
|
|
|
11
11
|
* @module bitwrench-code-edit
|
|
12
12
|
* @license BSD-2-Clause
|
|
13
13
|
*/
|
|
14
|
-
var e=!1,t='.
|
|
14
|
+
var e=!1,t='.bw_ce{background:#1e293b;border-radius:6px;border:1px solid rgba(255,255,255,0.08);overflow:auto}.bw_ce pre{margin:0;padding:0}.bw_ce code{font-family:"SF Mono",Monaco,"Cascadia Code",Consolas,monospace;font-size:0.875rem;line-height:1.6;color:#e2e8f0;outline:none;white-space:pre-wrap;display:block;padding:0.75rem 1rem}.bw_ce code:empty::before{content:"\\200b"}.bw_ce .bw_ce_keyword{color:#c792ea}.bw_ce .bw_ce_string{color:#c3e88d}.bw_ce .bw_ce_comment{color:#546e7a;font-style:italic}.bw_ce .bw_ce_number{color:#f78c6c}.bw_ce .bw_ce_operator{color:#89ddff}.bw_ce .bw_ce_punctuation{color:#89ddff}.bw_ce .bw_ce_property{color:#82aaff}.bw_ce .bw_ce_function{color:#82aaff}.bw_ce .bw_ce_tag{color:#f07178}.bw_ce .bw_ce_attr_name{color:#ffcb6b}.bw_ce .bw_ce_attr_value{color:#c3e88d}.bw_ce .bw_ce_selector{color:#c792ea}.bw_ce .bw_ce_css_prop{color:#82aaff}.bw_ce .bw_ce_css_value{color:#f78c6c}.bw_ce .bw_ce_at_rule{color:#c792ea;font-style:italic}.bw_ce .bw_ce_color{color:#f78c6c}.bw_ce .bw_ce_template_interp{color:#89ddff}.bw_ce_light.bw_ce{background:#fafafa;border-color:#d8d8d8}.bw_ce_light.bw_ce code{color:#1a1a1a}.bw_ce_light.bw_ce .bw_ce_keyword{color:#7c3aed}.bw_ce_light.bw_ce .bw_ce_string{color:#16a34a}.bw_ce_light.bw_ce .bw_ce_comment{color:#9ca3af;font-style:italic}.bw_ce_light.bw_ce .bw_ce_number{color:#ea580c}.bw_ce_light.bw_ce .bw_ce_operator{color:#0891b2}.bw_ce_light.bw_ce .bw_ce_punctuation{color:#6b7280}.bw_ce_light.bw_ce .bw_ce_property{color:#2563eb}.bw_ce_light.bw_ce .bw_ce_function{color:#2563eb}.bw_ce_light.bw_ce .bw_ce_tag{color:#dc2626}.bw_ce_light.bw_ce .bw_ce_attr_name{color:#d97706}.bw_ce_light.bw_ce .bw_ce_attr_value{color:#16a34a}.bw_ce_light.bw_ce .bw_ce_selector{color:#7c3aed}.bw_ce_light.bw_ce .bw_ce_css_prop{color:#2563eb}.bw_ce_light.bw_ce .bw_ce_css_value{color:#ea580c}.bw_ce_light.bw_ce .bw_ce_at_rule{color:#7c3aed}.bw_ce_light.bw_ce .bw_ce_color{color:#ea580c}.bw_ce_light.bw_ce .bw_ce_template_interp{color:#0891b2}';var c={};function o(e){var t=[],r=0,n=e.length,a="";function l(e){a.length&&(t.push({type:e,text:a}),a="")}for(;r<n;){var s=e[r],i=e[r+1];if("/"!==s||"/"!==i)if("/"!==s||"*"!==i){if("/"===s&&"/"!==i&&"*"!==i){var p=t.length?t[t.length-1]:null,_=!1;if(a.trim().length||p&&"operator"!==p.type&&"punctuation"!==p.type&&"keyword"!==p.type||(_=!0),_){l("plain");for(var u="/",f=r+1,b=!1,w=!1;f<n;){var h=e[f];if(b)u+=h,b=!1,f++;else if("\\"!==h)if("["!==h)if("]"!==h){if("/"===h&&!w){u+=h,f++;break}if("\n"===h)break;u+=h,f++}else w=!1,u+=h,f++;else w=!0,u+=h,f++;else b=!0,u+=h,f++}for(;f<n&&/[gimsuvy]/.test(e[f]);)u+=e[f],f++;t.push({type:"string",text:u}),r=f;continue}}if('"'!==s&&"'"!==s&&"`"!==s)if(/[0-9]/.test(s)||"."===s&&i&&/[0-9]/.test(i)){l("plain");var d="";if("0"===s&&i&&/[xXbBoO]/.test(i))for(d=s+i,r+=2;r<n&&/[0-9a-fA-F_]/.test(e[r]);)d+=e[r],r++;else for(;r<n&&/[0-9._eE]/.test(e[r]);)"e"!==e[r]&&"E"!==e[r]||!e[r+1]||!/[+\-0-9]/.test(e[r+1])?(d+=e[r],r++):(d+=e[r]+e[r+1],r+=2);t.push({type:"number",text:d})}else if(/[a-zA-Z_$]/.test(s)){l("plain");for(var g="";r<n&&/[a-zA-Z0-9_$]/.test(e[r]);)g+=e[r],r++;for(var v=r;v<n&&(" "===e[v]||"\t"===e[v]);)v++;var y=t.length?t[t.length-1]:null,x=y&&"punctuation"===y.type&&"."===y.text;c[g]?t.push({type:"keyword",text:g}):x?v<n&&"("===e[v]?t.push({type:"function",text:g}):t.push({type:"property",text:g}):v<n&&"("===e[v]?t.push({type:"function",text:g}):t.push({type:"plain",text:g})}else if(-1==="=+-*/%!<>&|^~?:".indexOf(s))-1==="(){}[];,.".indexOf(s)?(a+=s,r++):(l("plain"),t.push({type:"punctuation",text:s}),r++);else{l("plain");var m=s;++r<n&&-1!=="=+-*/%!<>&|^~?:".indexOf(e[r])&&(m+=e[r],++r<n&&-1!=="=>&|".indexOf(e[r])&&(m+=e[r],r++)),t.push({type:"operator",text:m})}else{l("plain");var k=s,C=s,A=r+1;if("`"===k){for(;A<n;){var S=e[A];if("\\"!==S)if("$"!==S||"{"!==e[A+1]){if("`"===S){C+=S,A++;break}C+=S,A++}else{C.length&&t.push({type:"string",text:C}),C="",t.push({type:"template-interp",text:"${"}),A+=2;for(var O=1,E="";A<n&&O>0;){if("{"===e[A])O++;else if("}"===e[A]&&0===--O)break;E+=e[A],A++}var T=o(E);(t=t.concat(T)).push({type:"template-interp",text:"}"}),A++}else C+=S+(e[A+1]||""),A+=2}C.length&&t.push({type:"string",text:C})}else{for(;A<n;){var z=e[A];if("\\"!==z){if(z===k){C+=z,A++;break}if("\n"===z)break;C+=z,A++}else C+=z+(e[A+1]||""),A+=2}t.push({type:"string",text:C})}r=A}}else{l("plain");var R=e.indexOf("*/",r+2);-1===R&&(R=n-2),t.push({type:"comment",text:e.substring(r,R+2)}),r=R+2}else{l("plain");var Z=e.indexOf("\n",r);-1===Z&&(Z=n),t.push({type:"comment",text:e.substring(r,Z)}),r=Z}}return l("plain"),t}function r(e){var t=[],c=0,o=e.length,r="selector",n="";function a(e){n.length&&(t.push({type:e||"plain",text:n}),n="")}for(;c<o;){var l=e[c],s=e[c+1];if("/"!==l||"*"!==s)if('"'!==l&&"'"!==l||"value"!==r&&"selector"!==r)if("@"!==l||"selector"!==r)if("#"!==l||"value"!==r)if("value"===r&&/[0-9]/.test(l)){a("css-value");for(var i="";c<o&&/[0-9.]/.test(e[c]);)i+=e[c],c++;for(var p="";c<o&&/[a-zA-Z%]/.test(e[c]);)p+=e[c],c++;t.push({type:"number",text:i+p})}else"{"!==l?"}"!==l?":"!==l||"prop"!==r?";"!==l?","!==l?(n+=l,c++):(a("selector"===r?"selector":"value"===r?"css-value":"plain"),t.push({type:"punctuation",text:l}),c++):(a("value"===r?"css-value":"plain"),t.push({type:"punctuation",text:l}),r="prop",c++):(a("css-prop"),t.push({type:"punctuation",text:l}),r="value",c++):(a("prop"===r?"css-prop":"value"===r?"css-value":"plain"),t.push({type:"punctuation",text:l}),r="selector",c++):(a("selector"===r?"selector":"plain"),t.push({type:"punctuation",text:l}),r="prop",c++);else{a("css-value");var _="#";for(c++;c<o&&/[0-9a-fA-F]/.test(e[c]);)_+=e[c],c++;t.push({type:"color",text:_})}else{a("selector");var u="@";for(c++;c<o&&/[a-zA-Z\-]/.test(e[c]);)u+=e[c],c++;t.push({type:"at-rule",text:u})}else{a("selector"===r?"selector":"css-value");var f=l,b=l;for(c++;c<o;)if("\\"!==e[c]){if(e[c]===f){b+=e[c],c++;break}b+=e[c],c++}else b+=e[c]+(e[c+1]||""),c+=2;t.push({type:"string",text:b})}else{a("selector"===r?"selector":"prop"===r?"css-prop":"css-value");var w=e.indexOf("*/",c+2);-1===w&&(w=o-2),t.push({type:"comment",text:e.substring(c,w+2)}),c=w+2}}return a("selector"===r?"selector":"prop"===r?"css-prop":"css-value"),t}function n(e){var t=[],c=0,o=e.length,r="";function n(e){r.length&&(t.push({type:e,text:r}),r="")}for(;c<o;){var a=e[c];if("<"!==a||"\x3c!--"!==e.substring(c,c+4))if("<"!==a)if("&"!==a)r+=a,c++;else{n("plain");var l="&";for(c++;c<o&&";"!==e[c]&&/[a-zA-Z0-9#]/.test(e[c]);)l+=e[c],c++;c<o&&";"===e[c]&&(l+=";",c++),t.push({type:"string",text:l})}else{n("plain");var s="<";for(++c<o&&"/"===e[c]&&(s+="/",c++);c<o&&/[a-zA-Z0-9\-]/.test(e[c]);)s+=e[c],c++;for(t.push({type:"tag",text:s});c<o&&">"!==e[c]&&("/"!==e[c]||">"!==e[c+1]);)if(/\s/.test(e[c])){for(var i="";c<o&&/\s/.test(e[c]);)i+=e[c],c++;t.push({type:"plain",text:i})}else if(/[a-zA-Z_\-@:]/.test(e[c])){for(var p="";c<o&&/[a-zA-Z0-9_\-@:]/.test(e[c]);)p+=e[c],c++;if(t.push({type:"attr-name",text:p}),c<o&&"="===e[c])if(t.push({type:"punctuation",text:"="}),++c<o&&('"'===e[c]||"'"===e[c])){var _=e[c],u=_;for(c++;c<o&&e[c]!==_;)u+=e[c],c++;c<o&&(u+=e[c],c++),t.push({type:"attr-value",text:u})}else{for(var f="";c<o&&!/[\s>]/.test(e[c]);)f+=e[c],c++;t.push({type:"attr-value",text:f})}}else r+=e[c],c++,n("plain");var b="";c<o&&"/"===e[c]&&(b+="/",c++),c<o&&">"===e[c]&&(b+=">",c++),b&&t.push({type:"tag",text:b})}else{n("plain");var w=e.indexOf("--\x3e",c+4);-1===w&&(w=o-3),t.push({type:"comment",text:e.substring(c,w+3)}),c=w+3}}return n("plain"),t}"var,const,let,function,return,if,else,for,while,do,switch,case,break,continue,new,typeof,instanceof,this,class,extends,import,export,default,from,true,false,null,undefined,try,catch,throw,finally,async,await,yield,of,in,delete,void,with,super,static,get,set,debugger".split(",").forEach(function(e){c[e]=!0});var a={js:o,javascript:o,css:r,html:n};function l(e,t){return function(e){for(var t=[],c=0;c<e.length;c++){var o=e[c];"plain"===o.type?t.push(o.text):t.push({t:"span",a:{class:"bw_ce_"+o.type},c:o.text})}return t}((a[t]||o)(e))}function s(e){var t=(e=e||{}).code||"",c=e.lang||"js",o=e.height||"180px",r=!!e.readOnly,n="bw_ce"+(e.className?" "+e.className:""),a=l(t,c),s={spellcheck:"false",class:"bw_ce_code"};return r||(s.contenteditable="true"),{t:"div",a:{class:n,style:"max-height:"+o+";overflow:auto"},c:[{t:"pre",c:{t:"code",a:s,c:a}}],o:{mounted:function(o){var n=o.querySelector(".bw_ce_code");if(n){var a=t,s=null,i="undefined"!=typeof window&&window.bw||{};o._bwCodeEdit={getValue:p,setValue:function(e){a=e;var t=l(e,c);i.html&&(n.innerHTML=i.html({t:"span",c:t}))}},r||(n.addEventListener("input",function(){clearTimeout(s),s=setTimeout(_,50)}),n.addEventListener("keydown",function(e){"Tab"===e.key&&(e.preventDefault(),document.execCommand("insertText",!1," "))}))}function p(){return n.textContent||""}function _(){var t=p();if(t!==a){a=t;var o=function(e){var t=window.getSelection();if(!t.rangeCount)return 0;var c=t.getRangeAt(0).cloneRange();return c.selectNodeContents(e),c.setEnd(t.getRangeAt(0).startContainer,t.getRangeAt(0).startOffset),c.toString().length}(n),r=l(t,c);i.html&&(n.innerHTML=i.html({t:"span",c:r})),function(e,t){for(var c,o=window.getSelection(),r=document.createRange(),n=document.createTreeWalker(e,NodeFilter.SHOW_TEXT,null,!1),a=0;c=n.nextNode();){var l=c.textContent.length;if(a+l>=t)return r.setStart(c,t-a),r.collapse(!0),o.removeAllRanges(),void o.addRange(r);a+=l}r.selectNodeContents(e),r.collapse(!1),o.removeAllRanges(),o.addRange(r)}(n,o),e.onChange&&e.onChange(t)}}}}}}function i(c){c&&(c.highlight=l,c.codeEditor=function(o){return function(c){e||(e=!0,c&&c.injectCSS&&c.injectCSS(t,{id:"bw_code_edit_styles"}))}(c),s(o)})}"undefined"!=typeof window&&window.bw&&i(window.bw);var p={highlight:l,codeEditor:s,install:i,CSS_TEXT:t};export{t as CSS_TEXT,s as codeEditor,p as default,l as highlight,i as install,r as tokenizeCSS,n as tokenizeHTML,o as tokenizeJS};
|
|
15
15
|
//# sourceMappingURL=bitwrench-code-edit.esm.min.js.map
|