bitwrench 2.0.15 → 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 (51) 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 +57 -7
  9. package/dist/bitwrench-code-edit.cjs.min.js +9 -2
  10. package/dist/bitwrench-code-edit.es5.js +74 -11
  11. package/dist/bitwrench-code-edit.es5.min.js +9 -2
  12. package/dist/bitwrench-code-edit.esm.js +57 -7
  13. package/dist/bitwrench-code-edit.esm.min.js +9 -2
  14. package/dist/bitwrench-code-edit.umd.js +57 -7
  15. package/dist/bitwrench-code-edit.umd.min.js +9 -2
  16. package/dist/bitwrench-lean.cjs.js +413 -17
  17. package/dist/bitwrench-lean.cjs.min.js +7 -7
  18. package/dist/bitwrench-lean.es5.js +428 -16
  19. package/dist/bitwrench-lean.es5.min.js +5 -5
  20. package/dist/bitwrench-lean.esm.js +413 -17
  21. package/dist/bitwrench-lean.esm.min.js +7 -7
  22. package/dist/bitwrench-lean.umd.js +413 -17
  23. package/dist/bitwrench-lean.umd.min.js +7 -7
  24. package/dist/bitwrench.cjs.js +413 -17
  25. package/dist/bitwrench.cjs.min.js +7 -7
  26. package/dist/bitwrench.css +60 -17
  27. package/dist/bitwrench.es5.js +428 -16
  28. package/dist/bitwrench.es5.min.js +6 -6
  29. package/dist/bitwrench.esm.js +413 -17
  30. package/dist/bitwrench.esm.min.js +7 -7
  31. package/dist/bitwrench.min.css +1 -1
  32. package/dist/bitwrench.umd.js +413 -17
  33. package/dist/bitwrench.umd.min.js +7 -7
  34. package/dist/builds.json +168 -80
  35. package/dist/bwserve.cjs.js +646 -0
  36. package/dist/bwserve.esm.js +638 -0
  37. package/dist/sri.json +36 -28
  38. package/package.json +18 -3
  39. package/readme.html +62 -23
  40. package/src/bitwrench-bccl-entry.js +72 -0
  41. package/src/bitwrench-code-edit.js +56 -6
  42. package/src/bitwrench-color-utils.js +5 -6
  43. package/src/bitwrench-styles.js +20 -8
  44. package/src/bitwrench.js +385 -0
  45. package/src/bwserve/client.js +182 -0
  46. package/src/bwserve/index.js +352 -0
  47. package/src/bwserve/shell.js +103 -0
  48. package/src/cli/index.js +36 -15
  49. package/src/cli/serve.js +325 -0
  50. package/src/version.js +3 -3
  51. /package/bin/{bitwrench.js → bwcli.js} +0 -0
@@ -1,4 +1,4 @@
1
- /*! bitwrench-lean v2.0.15 | BSD-2-Clause | https://deftio.github.com/bitwrench/pages */
1
+ /*! bitwrench-lean 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' ? module.exports = factory() :
4
4
  typeof define === 'function' && define.amd ? define(factory) :
@@ -189,14 +189,14 @@
189
189
  */
190
190
 
191
191
  var VERSION_INFO = {
192
- version: '2.0.15',
192
+ version: '2.0.16',
193
193
  name: 'bitwrench',
194
194
  description: 'A library for javascript UI functions.',
195
195
  license: 'BSD-2-Clause',
196
196
  homepage: 'https://deftio.github.com/bitwrench/pages',
197
197
  repository: 'git+https://github.com/deftio/bitwrench.git',
198
198
  author: 'manu a. chatterjee <deftio@deftio.com> (https://deftio.com/)',
199
- buildDate: '2026-03-10T09:08:17.015Z'
199
+ buildDate: '2026-03-12T08:05:52.043Z'
200
200
  };
201
201
 
202
202
  /**
@@ -609,12 +609,11 @@
609
609
  var lightBase = config.light || hslToHex([h, 8, 97]);
610
610
  var darkBase = config.dark || hslToHex([h, 10, 13]);
611
611
 
612
- // Background & surface tokens — default to light (white/near-white).
613
- // Dark backgrounds require explicit config.background / config.surface.
614
- // Primary/secondary colors are accents, not page backgrounds, so
615
- // isLightPalette should NOT drive bg/surface defaults.
616
- var bgBase = config.background || '#ffffff';
617
- var surfBase = config.surface || '#f8f9fa';
612
+ // Background & surface tokens — tinted with primary hue for theme personality.
613
+ // Very subtle: bg at L=98/S=6, surface at L=96/S=8.
614
+ // User can override with config.background / config.surface.
615
+ var bgBase = config.background || hslToHex([h, 6, 98]);
616
+ var surfBase = config.surface || hslToHex([h, 8, 96]);
618
617
  var palette = {
619
618
  primary: deriveShades(config.primary),
620
619
  secondary: deriveShades(config.secondary),
@@ -1857,8 +1856,8 @@
1857
1856
  },
1858
1857
  '.bw_container_fluid': {
1859
1858
  'width': '100%',
1860
- 'padding-right': '15px',
1861
- 'padding-left': '15px',
1859
+ 'padding-right': '0.75rem',
1860
+ 'padding-left': '0.75rem',
1862
1861
  'margin-right': 'auto',
1863
1862
  'margin-left': 'auto'
1864
1863
  },
@@ -2234,7 +2233,9 @@
2234
2233
  'line-height': '1.3',
2235
2234
  'text-align': 'center',
2236
2235
  'white-space': 'nowrap',
2237
- 'vertical-align': 'baseline'
2236
+ 'vertical-align': 'baseline',
2237
+ 'padding': '0.35rem 0.65rem',
2238
+ 'border-radius': '0.25rem'
2238
2239
  },
2239
2240
  '.bw_badge:empty': {
2240
2241
  'display': 'none'
@@ -2699,7 +2700,8 @@
2699
2700
  '.bw_code_pre': {
2700
2701
  'margin': '0',
2701
2702
  'border': 'none',
2702
- 'overflow-x': 'auto'
2703
+ 'overflow-x': 'auto',
2704
+ 'max-width': '100%'
2703
2705
  },
2704
2706
  '.bw_code_block': {
2705
2707
  'display': 'block',
@@ -2928,7 +2930,7 @@
2928
2930
  },
2929
2931
  '.bw_modal_dialog': {
2930
2932
  'position': 'relative',
2931
- 'width': '100%',
2933
+ 'width': 'calc(100% - 1rem)',
2932
2934
  'max-width': '500px',
2933
2935
  'margin': '1.75rem auto',
2934
2936
  'pointer-events': 'none'
@@ -3017,7 +3019,7 @@
3017
3019
  '.bw_toast': {
3018
3020
  'pointer-events': 'auto',
3019
3021
  'width': '350px',
3020
- 'max-width': '100%',
3022
+ 'max-width': 'calc(100vw - 2rem)',
3021
3023
  'background-clip': 'padding-box',
3022
3024
  'opacity': '0'
3023
3025
  },
@@ -3224,6 +3226,7 @@
3224
3226
  'z-index': '999',
3225
3227
  'font-size': '0.875rem',
3226
3228
  'white-space': 'nowrap',
3229
+ 'max-width': 'min(300px, calc(100vw - 1rem))',
3227
3230
  'pointer-events': 'none',
3228
3231
  'opacity': '0',
3229
3232
  'visibility': 'hidden'
@@ -3282,7 +3285,7 @@
3282
3285
  'position': 'absolute',
3283
3286
  'z-index': '1000',
3284
3287
  'min-width': '200px',
3285
- 'max-width': '320px',
3288
+ 'max-width': 'min(320px, calc(100vw - 2rem))',
3286
3289
  'pointer-events': 'none',
3287
3290
  'opacity': '0',
3288
3291
  'visibility': 'hidden'
@@ -3828,6 +3831,45 @@
3828
3831
  },
3829
3832
  '.bw_feature_grid, .bw_feature-grid': {
3830
3833
  'grid-template-columns': '1fr'
3834
+ },
3835
+ '.bw_modal_dialog': {
3836
+ 'margin': '0.5rem auto'
3837
+ },
3838
+ '.bw_modal_lg': {
3839
+ 'max-width': 'calc(100% - 1rem)'
3840
+ },
3841
+ '.bw_modal_xl': {
3842
+ 'max-width': 'calc(100% - 1rem)'
3843
+ },
3844
+ '.bw_navbar': {
3845
+ 'padding': '0.5rem 0.75rem'
3846
+ },
3847
+ '.bw_navbar_brand': {
3848
+ 'margin-right': '0.5rem',
3849
+ 'font-size': '1rem'
3850
+ },
3851
+ '.bw_navbar_nav': {
3852
+ 'flex-wrap': 'wrap'
3853
+ },
3854
+ '.bw_tooltip': {
3855
+ 'white-space': 'normal'
3856
+ },
3857
+ '.bw_table': {
3858
+ 'display': 'block',
3859
+ 'overflow-x': 'auto',
3860
+ '-webkit-overflow-scrolling': 'touch'
3861
+ },
3862
+ '.bw_col, .bw_col_1, .bw_col_2, .bw_col_3, .bw_col_4, .bw_col_5, .bw_col_6, .bw_col_7, .bw_col_8, .bw_col_9, .bw_col_10, .bw_col_11, .bw_col_12': {
3863
+ 'flex': '0 0 100%',
3864
+ 'max-width': '100%'
3865
+ },
3866
+ '.bw_container': {
3867
+ 'padding-right': '0.5rem',
3868
+ 'padding-left': '0.5rem'
3869
+ },
3870
+ '.bw_container_fluid': {
3871
+ 'padding-right': '0.5rem',
3872
+ 'padding-left': '0.5rem'
3831
3873
  }
3832
3874
  }
3833
3875
  }
@@ -7643,6 +7685,376 @@
7643
7685
  return true;
7644
7686
  };
7645
7687
 
7688
+ // ===================================================================================
7689
+ // bw.clientApply() / bw.clientConnect() — Server-driven UI protocol
7690
+ // ===================================================================================
7691
+
7692
+ /**
7693
+ * Registry of named functions sent via register messages.
7694
+ * Populated by clientApply({ type: 'register', name, body }).
7695
+ * Invoked by clientApply({ type: 'call', name, args }).
7696
+ * @private
7697
+ */
7698
+ bw._clientFunctions = {};
7699
+
7700
+ /**
7701
+ * Whether exec messages are allowed. Set by clientConnect opts.allowExec.
7702
+ * Default false — exec messages are rejected unless explicitly opted in.
7703
+ * @private
7704
+ */
7705
+ bw._allowExec = false;
7706
+
7707
+ /**
7708
+ * Built-in client functions available via call() without registration.
7709
+ * @private
7710
+ */
7711
+ bw._builtinClientFunctions = {
7712
+ scrollTo: function scrollTo(selector) {
7713
+ var el = bw._el(selector);
7714
+ if (el) el.scrollTop = el.scrollHeight;
7715
+ },
7716
+ focus: function focus(selector) {
7717
+ var el = bw._el(selector);
7718
+ if (el && typeof el.focus === 'function') el.focus();
7719
+ },
7720
+ download: function download(filename, content, mimeType) {
7721
+ if (typeof document === 'undefined') return;
7722
+ var blob = new Blob([content], {
7723
+ type: mimeType || 'text/plain'
7724
+ });
7725
+ var a = document.createElement('a');
7726
+ a.href = URL.createObjectURL(blob);
7727
+ a.download = filename;
7728
+ a.click();
7729
+ URL.revokeObjectURL(a.href);
7730
+ },
7731
+ clipboard: function clipboard(text) {
7732
+ if (typeof navigator !== 'undefined' && navigator.clipboard) {
7733
+ navigator.clipboard.writeText(text);
7734
+ }
7735
+ },
7736
+ redirect: function redirect(url) {
7737
+ if (typeof window !== 'undefined') window.location.href = url;
7738
+ },
7739
+ log: function log() {
7740
+ console.log.apply(console, arguments);
7741
+ }
7742
+ };
7743
+
7744
+ /**
7745
+ * Parse a bwserve protocol message string, supporting both strict JSON
7746
+ * and r-prefixed relaxed JSON (single-quoted strings, trailing commas).
7747
+ *
7748
+ * The r-prefix format is designed for C/C++ string literals where
7749
+ * double-quote escaping is painful. The parser is a state machine
7750
+ * that walks character by character — not a regex replace.
7751
+ *
7752
+ * Escaping: apostrophes inside single-quoted values must be escaped
7753
+ * with backslash: r{'name':'Barry\'s room'}
7754
+ *
7755
+ * @param {string} str - JSON or r-prefixed relaxed JSON string
7756
+ * @returns {Object} Parsed message object
7757
+ * @throws {SyntaxError} If the string is not valid JSON or relaxed JSON
7758
+ * @category Server
7759
+ */
7760
+ bw.clientParse = function (str) {
7761
+ str = (str || '').trim();
7762
+ if (str.charAt(0) !== 'r') return JSON.parse(str);
7763
+ str = str.slice(1);
7764
+ var out = [];
7765
+ var i = 0;
7766
+ var len = str.length;
7767
+ while (i < len) {
7768
+ var ch = str[i];
7769
+ if (ch === "'") {
7770
+ // Single-quoted string → emit as double-quoted
7771
+ out.push('"');
7772
+ i++;
7773
+ while (i < len) {
7774
+ var c = str[i];
7775
+ if (c === '\\' && i + 1 < len) {
7776
+ var next = str[i + 1];
7777
+ if (next === "'") {
7778
+ out.push("'"); // \' in input → ' in output
7779
+ } else {
7780
+ out.push('\\');
7781
+ out.push(next);
7782
+ }
7783
+ i += 2;
7784
+ } else if (c === '"') {
7785
+ out.push('\\"');
7786
+ i++;
7787
+ } else if (c === "'") {
7788
+ break;
7789
+ } else {
7790
+ out.push(c);
7791
+ i++;
7792
+ }
7793
+ }
7794
+ out.push('"');
7795
+ i++; // skip closing '
7796
+ } else if (ch === '"') {
7797
+ // Double-quoted string — pass through verbatim
7798
+ out.push(ch);
7799
+ i++;
7800
+ while (i < len) {
7801
+ var c2 = str[i];
7802
+ if (c2 === '\\' && i + 1 < len) {
7803
+ out.push(c2);
7804
+ out.push(str[i + 1]);
7805
+ i += 2;
7806
+ } else {
7807
+ out.push(c2);
7808
+ i++;
7809
+ if (c2 === '"') break;
7810
+ }
7811
+ }
7812
+ } else if (ch === ',') {
7813
+ // Trailing comma check: skip comma if next non-whitespace is } or ]
7814
+ var j = i + 1;
7815
+ while (j < len && (str[j] === ' ' || str[j] === '\t' || str[j] === '\n' || str[j] === '\r')) j++;
7816
+ if (j < len && (str[j] === '}' || str[j] === ']')) {
7817
+ i++; // skip trailing comma
7818
+ } else {
7819
+ out.push(ch);
7820
+ i++;
7821
+ }
7822
+ } else {
7823
+ out.push(ch);
7824
+ i++;
7825
+ }
7826
+ }
7827
+ return JSON.parse(out.join(''));
7828
+ };
7829
+
7830
+ /**
7831
+ * Apply a bwserve protocol message to the DOM.
7832
+ *
7833
+ * Dispatches one of 9 message types:
7834
+ * replace — bw.DOM(target, node)
7835
+ * append — target.appendChild(bw.createDOM(node))
7836
+ * remove — bw.cleanup(target); target.remove()
7837
+ * patch — bw.patch(target, content, attr)
7838
+ * batch — iterate ops, call clientApply for each
7839
+ * message — bw.message(target, action, data)
7840
+ * register — store a named function for later call()
7841
+ * call — invoke a registered or built-in function
7842
+ * exec — execute arbitrary JS (requires allowExec)
7843
+ *
7844
+ * Target resolution:
7845
+ * Starts with '#' or '.' → CSS selector (querySelector)
7846
+ * Otherwise → getElementById, then bw._el fallback
7847
+ *
7848
+ * @param {Object} msg - Protocol message
7849
+ * @returns {boolean} true if the message was applied successfully
7850
+ * @category Server
7851
+ */
7852
+ bw.clientApply = function (msg) {
7853
+ if (!msg || !msg.type) return false;
7854
+ var type = msg.type;
7855
+ var target = msg.target;
7856
+ if (type === 'replace') {
7857
+ var el = bw._el(target);
7858
+ if (!el) return false;
7859
+ bw.DOM(el, msg.node);
7860
+ return true;
7861
+ } else if (type === 'patch') {
7862
+ var patched = bw.patch(target, msg.content, msg.attr);
7863
+ return patched !== null;
7864
+ } else if (type === 'append') {
7865
+ var parent = bw._el(target);
7866
+ if (!parent) return false;
7867
+ var child = bw.createDOM(msg.node);
7868
+ parent.appendChild(child);
7869
+ return true;
7870
+ } else if (type === 'remove') {
7871
+ var toRemove = bw._el(target);
7872
+ if (!toRemove) return false;
7873
+ if (typeof bw.cleanup === 'function') bw.cleanup(toRemove);
7874
+ toRemove.remove();
7875
+ return true;
7876
+ } else if (type === 'batch') {
7877
+ if (!Array.isArray(msg.ops)) return false;
7878
+ var allOk = true;
7879
+ msg.ops.forEach(function (op) {
7880
+ if (!bw.clientApply(op)) allOk = false;
7881
+ });
7882
+ return allOk;
7883
+ } else if (type === 'message') {
7884
+ return bw.message(msg.target, msg.action, msg.data);
7885
+ } else if (type === 'register') {
7886
+ if (!msg.name || !msg.body) return false;
7887
+ try {
7888
+ bw._clientFunctions[msg.name] = new Function('return ' + msg.body)();
7889
+ return true;
7890
+ } catch (e) {
7891
+ console.error('[bw] register error:', msg.name, e);
7892
+ return false;
7893
+ }
7894
+ } else if (type === 'call') {
7895
+ if (!msg.name) return false;
7896
+ var fn = bw._clientFunctions[msg.name] || bw._builtinClientFunctions[msg.name];
7897
+ if (typeof fn !== 'function') return false;
7898
+ try {
7899
+ var args = Array.isArray(msg.args) ? msg.args : [];
7900
+ fn.apply(null, args);
7901
+ return true;
7902
+ } catch (e) {
7903
+ console.error('[bw] call error:', msg.name, e);
7904
+ return false;
7905
+ }
7906
+ } else if (type === 'exec') {
7907
+ if (!bw._allowExec) {
7908
+ console.warn('[bw] exec rejected: allowExec is not enabled');
7909
+ return false;
7910
+ }
7911
+ if (!msg.code) return false;
7912
+ try {
7913
+ new Function(msg.code)();
7914
+ return true;
7915
+ } catch (e) {
7916
+ console.error('[bw] exec error:', e);
7917
+ return false;
7918
+ }
7919
+ }
7920
+ return false;
7921
+ };
7922
+
7923
+ /**
7924
+ * Connect to a bwserve SSE endpoint and apply protocol messages automatically.
7925
+ *
7926
+ * Returns a connection object with sendAction(), on(), and close() methods.
7927
+ *
7928
+ * @param {string} url - SSE endpoint URL (e.g., '/__bw/events/client-1')
7929
+ * @param {Object} [opts] - Connection options
7930
+ * @param {string} [opts.transport='sse'] - Transport type: 'sse' (default) or 'poll'
7931
+ * @param {number} [opts.interval=2000] - Poll interval in ms (only for 'poll' transport)
7932
+ * @param {string} [opts.actionUrl] - POST endpoint for actions (default: derived from url)
7933
+ * @param {boolean} [opts.reconnect=true] - Auto-reconnect on disconnect
7934
+ * @param {boolean} [opts.allowExec=false] - Enable exec message type (arbitrary JS execution)
7935
+ * @param {Function} [opts.onStatus] - Status callback: 'connecting'|'connected'|'disconnected'
7936
+ * @param {Function} [opts.onMessage] - Raw message callback (before clientApply)
7937
+ * @returns {Object} Connection object { sendAction, on, close, status }
7938
+ * @category Server
7939
+ */
7940
+ bw.clientConnect = function (url, opts) {
7941
+ opts = opts || {};
7942
+ var transport = opts.transport || 'sse';
7943
+ var actionUrl = opts.actionUrl || url.replace(/\/events\//, '/action/');
7944
+ var reconnect = opts.reconnect !== false;
7945
+ var onStatus = opts.onStatus || function () {};
7946
+ var onMessage = opts.onMessage || null;
7947
+ var handlers = {};
7948
+ // Set the global allowExec flag from connection options
7949
+ bw._allowExec = !!opts.allowExec;
7950
+ var conn = {
7951
+ status: 'connecting',
7952
+ _es: null,
7953
+ _pollTimer: null
7954
+ };
7955
+ function setStatus(s) {
7956
+ conn.status = s;
7957
+ onStatus(s);
7958
+ }
7959
+ function handleMessage(data) {
7960
+ try {
7961
+ var msg = typeof data === 'string' ? bw.clientParse(data) : data;
7962
+ if (onMessage) onMessage(msg);
7963
+ if (handlers.message) handlers.message(msg);
7964
+ bw.clientApply(msg);
7965
+ } catch (e) {
7966
+ if (handlers.error) handlers.error(e);
7967
+ }
7968
+ }
7969
+ if (transport === 'sse' && typeof EventSource !== 'undefined') {
7970
+ setStatus('connecting');
7971
+ var es = new EventSource(url);
7972
+ conn._es = es;
7973
+ es.onopen = function () {
7974
+ setStatus('connected');
7975
+ if (handlers.open) handlers.open();
7976
+ };
7977
+ es.onmessage = function (e) {
7978
+ handleMessage(e.data);
7979
+ };
7980
+ es.onerror = function () {
7981
+ if (conn.status === 'connected') {
7982
+ setStatus('disconnected');
7983
+ }
7984
+ if (handlers.error) handlers.error(new Error('SSE connection error'));
7985
+ if (!reconnect) {
7986
+ es.close();
7987
+ }
7988
+ // EventSource auto-reconnects by default when reconnect=true
7989
+ };
7990
+ } else if (transport === 'poll') {
7991
+ var interval = opts.interval || 2000;
7992
+ setStatus('connected');
7993
+ conn._pollTimer = setInterval(function () {
7994
+ fetch(url).then(function (r) {
7995
+ return r.json();
7996
+ }).then(function (msgs) {
7997
+ if (Array.isArray(msgs)) {
7998
+ msgs.forEach(handleMessage);
7999
+ } else if (msgs && msgs.type) {
8000
+ handleMessage(msgs);
8001
+ }
8002
+ })["catch"](function (e) {
8003
+ if (handlers.error) handlers.error(e);
8004
+ });
8005
+ }, interval);
8006
+ }
8007
+
8008
+ /**
8009
+ * Send an action to the server via POST.
8010
+ * @param {string} action - Action name
8011
+ * @param {Object} [data] - Action payload
8012
+ */
8013
+ conn.sendAction = function (action, data) {
8014
+ var body = JSON.stringify({
8015
+ type: 'action',
8016
+ action: action,
8017
+ data: data || {}
8018
+ });
8019
+ fetch(actionUrl, {
8020
+ method: 'POST',
8021
+ headers: {
8022
+ 'Content-Type': 'application/json'
8023
+ },
8024
+ body: body
8025
+ })["catch"](function (e) {
8026
+ if (handlers.error) handlers.error(e);
8027
+ });
8028
+ };
8029
+
8030
+ /**
8031
+ * Register an event handler.
8032
+ * @param {string} event - 'open'|'message'|'error'|'close'
8033
+ * @param {Function} handler
8034
+ */
8035
+ conn.on = function (event, handler) {
8036
+ handlers[event] = handler;
8037
+ return conn;
8038
+ };
8039
+
8040
+ /**
8041
+ * Close the connection.
8042
+ */
8043
+ conn.close = function () {
8044
+ if (conn._es) {
8045
+ conn._es.close();
8046
+ conn._es = null;
8047
+ }
8048
+ if (conn._pollTimer) {
8049
+ clearInterval(conn._pollTimer);
8050
+ conn._pollTimer = null;
8051
+ }
8052
+ setStatus('disconnected');
8053
+ if (handlers.close) handlers.close();
8054
+ };
8055
+ return conn;
8056
+ };
8057
+
7646
8058
  // ===================================================================================
7647
8059
  // bw.inspect() — Debug utility
7648
8060
  // ===================================================================================