bitwrench 2.0.17 → 2.0.18

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 (67) hide show
  1. package/README.md +127 -38
  2. package/dist/bitwrench-bccl.cjs.js +8 -8
  3. package/dist/bitwrench-bccl.cjs.min.js +3 -3
  4. package/dist/bitwrench-bccl.esm.js +8 -8
  5. package/dist/bitwrench-bccl.esm.min.js +3 -3
  6. package/dist/bitwrench-bccl.umd.js +8 -8
  7. package/dist/bitwrench-bccl.umd.min.js +2 -2
  8. package/dist/bitwrench-code-edit.cjs.js +1 -1
  9. package/dist/bitwrench-code-edit.cjs.min.js +1 -1
  10. package/dist/bitwrench-code-edit.es5.js +1 -1
  11. package/dist/bitwrench-code-edit.es5.min.js +1 -1
  12. package/dist/bitwrench-code-edit.esm.js +1 -1
  13. package/dist/bitwrench-code-edit.esm.min.js +1 -1
  14. package/dist/bitwrench-code-edit.umd.js +1 -1
  15. package/dist/bitwrench-code-edit.umd.min.js +1 -1
  16. package/dist/bitwrench-lean.cjs.js +941 -775
  17. package/dist/bitwrench-lean.cjs.min.js +20 -20
  18. package/dist/bitwrench-lean.es5.js +1012 -961
  19. package/dist/bitwrench-lean.es5.min.js +18 -18
  20. package/dist/bitwrench-lean.esm.js +941 -775
  21. package/dist/bitwrench-lean.esm.min.js +20 -20
  22. package/dist/bitwrench-lean.umd.js +941 -775
  23. package/dist/bitwrench-lean.umd.min.js +20 -20
  24. package/dist/bitwrench-util-css.cjs.js +236 -0
  25. package/dist/bitwrench-util-css.cjs.min.js +22 -0
  26. package/dist/bitwrench-util-css.es5.js +414 -0
  27. package/dist/bitwrench-util-css.es5.min.js +21 -0
  28. package/dist/bitwrench-util-css.esm.js +230 -0
  29. package/dist/bitwrench-util-css.esm.min.js +21 -0
  30. package/dist/bitwrench-util-css.umd.js +242 -0
  31. package/dist/bitwrench-util-css.umd.min.js +21 -0
  32. package/dist/bitwrench.cjs.js +948 -782
  33. package/dist/bitwrench.cjs.min.js +21 -21
  34. package/dist/bitwrench.css +456 -132
  35. package/dist/bitwrench.es5.js +1024 -970
  36. package/dist/bitwrench.es5.min.js +19 -19
  37. package/dist/bitwrench.esm.js +949 -783
  38. package/dist/bitwrench.esm.min.js +21 -21
  39. package/dist/bitwrench.min.css +1 -1
  40. package/dist/bitwrench.umd.js +948 -782
  41. package/dist/bitwrench.umd.min.js +21 -21
  42. package/dist/builds.json +178 -90
  43. package/dist/bwserve.cjs.js +514 -68
  44. package/dist/bwserve.esm.js +513 -69
  45. package/dist/sri.json +44 -36
  46. package/package.json +3 -2
  47. package/readme.html +136 -49
  48. package/src/bitwrench-bccl.js +7 -7
  49. package/src/bitwrench-color-utils.js +31 -9
  50. package/src/bitwrench-esm-entry.js +11 -0
  51. package/src/bitwrench-styles.js +439 -232
  52. package/src/bitwrench-util-css.js +229 -0
  53. package/src/bitwrench.js +483 -485
  54. package/src/bwserve/attach.js +57 -0
  55. package/src/bwserve/bwclient.js +141 -0
  56. package/src/bwserve/bwshell.js +102 -0
  57. package/src/bwserve/client.js +151 -1
  58. package/src/bwserve/index.js +127 -28
  59. package/src/cli/attach.js +555 -0
  60. package/src/cli/convert.js +2 -5
  61. package/src/cli/index.js +7 -0
  62. package/src/cli/inject.js +1 -1
  63. package/src/cli/serve.js +6 -2
  64. package/src/generate-css.js +11 -4
  65. package/src/vendor/html2canvas.min.js +20 -0
  66. package/src/version.js +3 -3
  67. package/src/bwserve/shell.js +0 -106
@@ -1,18 +1,18 @@
1
- /*! bitwrench-lean v2.0.17 | BSD-2-Clause | https://deftio.github.com/bitwrench/pages */
1
+ /*! bitwrench-lean v2.0.18 | BSD-2-Clause | https://deftio.github.com/bitwrench/pages */
2
2
  /**
3
3
  * Auto-generated version file from package.json
4
4
  * DO NOT EDIT DIRECTLY - Use npm run generate-version
5
5
  */
6
6
 
7
7
  const VERSION_INFO = {
8
- version: '2.0.17',
8
+ version: '2.0.18',
9
9
  name: 'bitwrench',
10
10
  description: 'A library for javascript UI functions.',
11
11
  license: 'BSD-2-Clause',
12
12
  homepage: 'https://deftio.github.com/bitwrench/pages',
13
13
  repository: 'git+https://github.com/deftio/bitwrench.git',
14
14
  author: 'manu a. chatterjee <deftio@deftio.com> (https://deftio.com/)',
15
- buildDate: '2026-03-13T23:15:10.823Z'
15
+ buildDate: '2026-03-17T00:50:09.505Z'
16
16
  };
17
17
 
18
18
  /**
@@ -306,13 +306,18 @@ function harmonize(sourceHex, targetHex, amount) {
306
306
  */
307
307
  function deriveShades(hex) {
308
308
  var rgb = colorParse(hex);
309
+ // For light input colors (L > 75), mixing toward white produces invisible borders.
310
+ // Darken instead so borders remain visible against light backgrounds.
311
+ var borderColor = hexToHsl(hex)[2] > 75
312
+ ? adjustLightness(hex, -18)
313
+ : mixColor(hex, '#ffffff', 0.60);
309
314
  return {
310
315
  base: hex,
311
316
  hover: adjustLightness(hex, -10),
312
317
  active: adjustLightness(hex, -15),
313
318
  light: mixColor(hex, '#ffffff', 0.85),
314
319
  darkText: adjustLightness(hex, -40),
315
- border: mixColor(hex, '#ffffff', 0.60),
320
+ border: borderColor,
316
321
  focus: 'rgba(' + rgb[0] + ',' + rgb[1] + ',' + rgb[2] + ',0.25)',
317
322
  textOn: textOnColor(hex)
318
323
  };
@@ -371,19 +376,27 @@ function deriveAlternateConfig(config) {
371
376
  alt.secondary = deriveAlternateSeed(config.secondary);
372
377
  alt.tertiary = config.tertiary ? deriveAlternateSeed(config.tertiary) : alt.primary;
373
378
 
374
- // Derive alternate surface colors from primary hue
379
+ // Derive alternate surface colors from primary hue.
380
+ // Check actual page surface brightness (not seed color brightness) to decide
381
+ // whether alternate should be dark or light. The page surface is what the
382
+ // user sees; seeds can be dark while the page is still light (default L=96).
375
383
  var priHsl = hexToHsl(config.primary);
376
384
  var h = priHsl[0];
377
- var isLight = isLightPalette(config);
385
+ var primarySurface = config.surface || hslToHex([h, 8, 96]);
386
+ var isLight = relativeLuminance(primarySurface) > 0.179;
378
387
 
379
388
  if (isLight) {
380
- // Primary is light → alternate needs dark surfaces
389
+ // Page surface is light → alternate needs dark surfaces
381
390
  alt.light = hslToHex([h, Math.min(priHsl[1], 15), 15]);
382
391
  alt.dark = hslToHex([h, 5, 88]);
392
+ alt.surface = hslToHex([h, 12, 18]);
393
+ alt.background = hslToHex([h, 10, 14]);
383
394
  } else {
384
- // Primary is dark → alternate needs light surfaces
395
+ // Page surface is dark → alternate needs light surfaces
385
396
  alt.light = hslToHex([h, Math.min(priHsl[1], 10), 96]);
386
397
  alt.dark = hslToHex([h, 10, 18]);
398
+ alt.surface = hslToHex([h, 8, 96]);
399
+ alt.background = hslToHex([h, 6, 98]);
387
400
  }
388
401
 
389
402
  // Semantic colors: harmonize toward primary, then invert for alternate
@@ -431,10 +444,18 @@ function derivePalette(config) {
431
444
  var darkBase = config.dark || hslToHex([h, 10, 13]);
432
445
 
433
446
  // Background & surface tokens — tinted with primary hue for theme personality.
434
- // Very subtle: bg at L=98/S=6, surface at L=96/S=8.
447
+ // Saturation high enough that the hue is visible (each theme feels distinct)
448
+ // but low enough to stay neutral and readable.
435
449
  // User can override with config.background / config.surface.
436
- var bgBase = config.background || hslToHex([h, 6, 98]);
437
- var surfBase = config.surface || hslToHex([h, 8, 96]);
450
+ var bgBase = config.background || hslToHex([h, 22, 96]);
451
+ var surfBase = config.surface || hslToHex([h, 25, 94]);
452
+
453
+ // surfaceAlt: subtle background variant for striped rows, hover states, headers.
454
+ // Slightly lighter than surface in dark mode, slightly darker in light mode.
455
+ var surfHsl = hexToHsl(surfBase);
456
+ var surfAlt = surfHsl[2] <= 50
457
+ ? hslToHex([surfHsl[0], surfHsl[1], Math.min(surfHsl[2] + 8, 100)])
458
+ : hslToHex([surfHsl[0], surfHsl[1], Math.max(surfHsl[2] - 3, 0)]);
438
459
 
439
460
  var palette = {
440
461
  primary: deriveShades(config.primary),
@@ -447,7 +468,8 @@ function derivePalette(config) {
447
468
  light: deriveShades(lightBase),
448
469
  dark: deriveShades(darkBase),
449
470
  background: bgBase,
450
- surface: surfBase
471
+ surface: surfBase,
472
+ surfaceAlt: surfAlt
451
473
  };
452
474
 
453
475
  return palette;
@@ -494,10 +516,12 @@ var SPACING_SCALE = {
494
516
  5: '1.5rem', // 24px
495
517
  6: '2rem'};
496
518
 
519
+ let _S=SPACING_SCALE;
520
+
497
521
  var SPACING_PRESETS = {
498
- compact: { btn: SPACING_SCALE[1] + ' ' + SPACING_SCALE[3], card: SPACING_SCALE[3] + ' ' + SPACING_SCALE[4], alert: SPACING_SCALE[2] + ' ' + SPACING_SCALE[4], cell: SPACING_SCALE[2] + ' ' + SPACING_SCALE[3], input: SPACING_SCALE[1] + ' ' + SPACING_SCALE[3] },
499
- normal: { btn: SPACING_SCALE[2] + ' ' + SPACING_SCALE[4], card: SPACING_SCALE[5] + ' ' + SPACING_SCALE[5], alert: SPACING_SCALE[3] + ' ' + SPACING_SCALE[5], cell: SPACING_SCALE[3] + ' ' + SPACING_SCALE[4], input: SPACING_SCALE[2] + ' ' + SPACING_SCALE[3] },
500
- spacious: { btn: SPACING_SCALE[3] + ' ' + SPACING_SCALE[5], card: SPACING_SCALE[6] + ' ' + SPACING_SCALE[6], alert: SPACING_SCALE[4] + ' ' + SPACING_SCALE[5], cell: SPACING_SCALE[4] + ' ' + SPACING_SCALE[5], input: SPACING_SCALE[3] + ' ' + SPACING_SCALE[4] }
522
+ compact: { btn: _S[1] + ' ' + _S[3], card: _S[3] + ' ' + _S[4], alert: _S[2] + ' ' + _S[4], cell: _S[2] + ' ' + _S[3], input: _S[1] + ' ' + _S[3] },
523
+ normal: { btn: _S[2] + ' ' + _S[4], card: _S[5] + ' ' + _S[5], alert: _S[3] + ' ' + _S[5], cell: _S[3] + ' ' + _S[4], input: _S[2] + ' ' + _S[3] },
524
+ spacious: { btn: _S[3] + ' ' + _S[5], card: _S[6] + ' ' + _S[6], alert: _S[4] + ' ' + _S[5], cell: _S[4] + ' ' + _S[5], input: _S[3] + ' ' + _S[4] }
501
525
  };
502
526
 
503
527
  var RADIUS_PRESETS = {
@@ -609,20 +633,14 @@ var DEFAULT_PALETTE_CONFIG = {
609
633
  * Built-in theme presets — named color combinations
610
634
  * Each preset provides primary, secondary, and tertiary seed colors.
611
635
  */
612
- var THEME_PRESETS = {
613
- teal: { primary: '#006666', secondary: '#6c757d', tertiary: '#006666' },
614
- ocean: { primary: '#0077b6', secondary: '#90e0ef', tertiary: '#00b4d8' },
615
- sunset: { primary: '#e76f51', secondary: '#264653', tertiary: '#e9c46a' },
616
- forest: { primary: '#2d6a4f', secondary: '#95d5b2', tertiary: '#52b788' },
617
- slate: { primary: '#343a40', secondary: '#adb5bd', tertiary: '#6c757d' },
618
- rose: { primary: '#e11d48', secondary: '#fda4af', tertiary: '#fb7185' },
619
- indigo: { primary: '#4f46e5', secondary: '#a5b4fc', tertiary: '#818cf8' },
620
- amber: { primary: '#d97706', secondary: '#fbbf24', tertiary: '#f59e0b' },
621
- emerald: { primary: '#059669', secondary: '#6ee7b7', tertiary: '#34d399' },
622
- nord: { primary: '#5e81ac', secondary: '#88c0d0', tertiary: '#81a1c1' },
623
- coral: { primary: '#ef6461', secondary: '#4a7c7e', tertiary: '#e8a87c' },
624
- midnight: { primary: '#1e3a5f', secondary: '#7c8db5', tertiary: '#3d5a80' }
625
- };
636
+ var THEME_PRESETS = Object.fromEntries([
637
+ ['teal','#006666','#6c757d','#006666'],['ocean','#0077b6','#90e0ef','#00b4d8'],
638
+ ['sunset','#e76f51','#264653','#e9c46a'],['forest','#2d6a4f','#95d5b2','#52b788'],
639
+ ['slate','#343a40','#adb5bd','#6c757d'],['rose','#e11d48','#fda4af','#fb7185'],
640
+ ['indigo','#4f46e5','#a5b4fc','#818cf8'],['amber','#d97706','#fbbf24','#f59e0b'],
641
+ ['emerald','#059669','#6ee7b7','#34d399'],['nord','#5e81ac','#88c0d0','#81a1c1'],
642
+ ['coral','#ef6461','#4a7c7e','#e8a87c'],['midnight','#1e3a5f','#7c8db5','#3d5a80']
643
+ ].map(function(e) { return [e[0], {primary:e[1],secondary:e[2],tertiary:e[3]}]; }));
626
644
 
627
645
  /**
628
646
  * Resolve layout config to spacing, radius, typeScale, elevation, and motion objects.
@@ -669,6 +687,7 @@ function scopeSelector(name, sel) {
669
687
  if (sel.includes(',')) return sel.split(',').map(function(s) { return '.' + name + ' ' + s.trim(); }).join(', ');
670
688
  return '.' + name + ' ' + sel;
671
689
  }
690
+ var _sx=scopeSelector;
672
691
 
673
692
  // =========================================================================
674
693
  // Themed CSS generators
@@ -677,12 +696,12 @@ function scopeSelector(name, sel) {
677
696
  function generateTypographyThemed(scope, palette, layout) {
678
697
  var mot = layout.motion;
679
698
  var rules = {};
680
- rules[scopeSelector(scope, 'a')] = {
699
+ rules[_sx(scope, 'a')] = {
681
700
  'color': palette.primary.base,
682
701
  'text-decoration': 'none',
683
702
  'transition': 'color ' + mot.fast + ' ' + mot.easing
684
703
  };
685
- rules[scopeSelector(scope, 'a:hover')] = {
704
+ rules[_sx(scope, 'a:hover')] = {
686
705
  'color': palette.primary.hover,
687
706
  'text-decoration': 'underline'
688
707
  };
@@ -695,11 +714,11 @@ function generateButtons(scope, palette, layout) {
695
714
  var rd = layout.radius;
696
715
 
697
716
  // Base button (only when scoped — unscoped uses defaultStyles)
698
- rules[scopeSelector(scope, '.bw_btn')] = {
717
+ rules[_sx(scope, '.bw_btn')] = {
699
718
  'padding': sp.btn,
700
719
  'border-radius': rd.btn
701
720
  };
702
- rules[scopeSelector(scope, '.bw_btn:focus-visible')] = {
721
+ rules[_sx(scope, '.bw_btn:focus-visible')] = {
703
722
  'outline': '2px solid currentColor',
704
723
  'outline-offset': '2px',
705
724
  'box-shadow': '0 0 0 3px ' + palette.primary.focus
@@ -708,12 +727,12 @@ function generateButtons(scope, palette, layout) {
708
727
  // Variant colors handled by palette class on component root
709
728
 
710
729
  // Size variants (structural, reuse layout radius)
711
- rules[scopeSelector(scope, '.bw_btn_lg')] = {
730
+ rules[_sx(scope, '.bw_btn_lg')] = {
712
731
  'padding': '0.625rem 1.5rem',
713
732
  'font-size': '1rem',
714
733
  'border-radius': rd.btn === '50rem' ? '50rem' : (parseInt(rd.btn) + 2) + 'px'
715
734
  };
716
- rules[scopeSelector(scope, '.bw_btn_sm')] = {
735
+ rules[_sx(scope, '.bw_btn_sm')] = {
717
736
  'padding': '0.25rem 0.75rem',
718
737
  'font-size': '0.8125rem',
719
738
  'border-radius': rd.btn === '50rem' ? '50rem' : (Math.max(parseInt(rd.btn) - 1, 0)) + 'px'
@@ -727,7 +746,7 @@ function generateAlerts(scope, palette, layout) {
727
746
  var sp = layout.spacing;
728
747
  var rd = layout.radius;
729
748
 
730
- rules[scopeSelector(scope, '.bw_alert')] = {
749
+ rules[_sx(scope, '.bw_alert')] = {
731
750
  'padding': sp.alert,
732
751
  'border-radius': rd.alert
733
752
  };
@@ -746,36 +765,36 @@ function generateCards(scope, palette, layout) {
746
765
 
747
766
  var elev = layout.elevation;
748
767
  var motion = layout.motion;
749
- rules[scopeSelector(scope, '.bw_card')] = {
768
+ rules[_sx(scope, '.bw_card')] = {
750
769
  'background-color': palette.surface || '#fff',
751
770
  'border': '1px solid ' + palette.light.border,
752
771
  'border-radius': rd.card,
753
772
  'box-shadow': elev.sm,
754
773
  'transition': 'box-shadow ' + motion.normal + ' ' + motion.easing + ', transform ' + motion.normal + ' ' + motion.easing
755
774
  };
756
- rules[scopeSelector(scope, '.bw_card:hover')] = {
775
+ rules[_sx(scope, '.bw_card:hover')] = {
757
776
  'box-shadow': elev.md
758
777
  };
759
- rules[scopeSelector(scope, '.bw_card_hoverable:hover')] = {
778
+ rules[_sx(scope, '.bw_card_hoverable:hover')] = {
760
779
  'box-shadow': elev.lg
761
780
  };
762
- rules[scopeSelector(scope, '.bw_card_body')] = {
781
+ rules[_sx(scope, '.bw_card_body')] = {
763
782
  'padding': sp.card
764
783
  };
765
- rules[scopeSelector(scope, '.bw_card_header')] = {
784
+ rules[_sx(scope, '.bw_card_header')] = {
766
785
  'padding': sp.card.split(' ').map(function(v) { return (parseFloat(v) * 0.7).toFixed(3).replace(/\.?0+$/, '') + 'rem'; }).join(' '),
767
- 'background-color': palette.light.light,
786
+ 'background-color': palette.surfaceAlt,
768
787
  'border-bottom': '1px solid ' + palette.light.border
769
788
  };
770
- rules[scopeSelector(scope, '.bw_card_footer')] = {
771
- 'background-color': palette.light.light,
789
+ rules[_sx(scope, '.bw_card_footer')] = {
790
+ 'background-color': palette.surfaceAlt,
772
791
  'border-top': '1px solid ' + palette.light.border,
773
792
  'color': palette.secondary.base
774
793
  };
775
- rules[scopeSelector(scope, '.bw_card_title')] = {
794
+ rules[_sx(scope, '.bw_card_title')] = {
776
795
  'color': palette.dark.base
777
796
  };
778
- rules[scopeSelector(scope, '.bw_card_subtitle')] = {
797
+ rules[_sx(scope, '.bw_card_subtitle')] = {
779
798
  'color': palette.secondary.base
780
799
  };
781
800
 
@@ -789,55 +808,55 @@ function generateForms(scope, palette, layout) {
789
808
  var sp = layout.spacing;
790
809
  var rd = layout.radius;
791
810
 
792
- rules[scopeSelector(scope, '.bw_form_control')] = {
811
+ rules[_sx(scope, '.bw_form_control')] = {
793
812
  'padding': sp.input,
794
813
  'border-radius': rd.input,
795
814
  'color': palette.dark.base,
796
815
  'background-color': palette.surface || '#fff',
797
816
  'border-color': palette.light.border
798
817
  };
799
- rules[scopeSelector(scope, '.bw_form_control:focus')] = {
818
+ rules[_sx(scope, '.bw_form_control:focus')] = {
800
819
  'border-color': palette.primary.border,
801
820
  'outline': '2px solid ' + palette.primary.base,
802
821
  'outline-offset': '-1px',
803
822
  'box-shadow': '0 0 0 0.25rem ' + palette.primary.focus
804
823
  };
805
- rules[scopeSelector(scope, '.bw_form_control::placeholder')] = {
824
+ rules[_sx(scope, '.bw_form_control::placeholder')] = {
806
825
  'color': palette.secondary.base
807
826
  };
808
- rules[scopeSelector(scope, '.bw_form_label')] = {
827
+ rules[_sx(scope, '.bw_form_label')] = {
809
828
  'color': palette.dark.base
810
829
  };
811
- rules[scopeSelector(scope, '.bw_form_text')] = {
830
+ rules[_sx(scope, '.bw_form_text')] = {
812
831
  'color': palette.secondary.base
813
832
  };
814
- rules[scopeSelector(scope, '.bw_form_check_input:checked')] = {
833
+ rules[_sx(scope, '.bw_form_check_input:checked')] = {
815
834
  'background-color': palette.primary.base,
816
835
  'border-color': palette.primary.base
817
836
  };
818
- rules[scopeSelector(scope, '.bw_form_check_input:focus')] = {
837
+ rules[_sx(scope, '.bw_form_check_input:focus')] = {
819
838
  'box-shadow': '0 0 0 0.25rem ' + palette.primary.focus
820
839
  };
821
840
  // Validation states
822
- rules[scopeSelector(scope, '.bw_form_control.bw_is_valid')] = { 'border-color': palette.success.base };
823
- rules[scopeSelector(scope, '.bw_form_control.bw_is_valid:focus')] = {
841
+ rules[_sx(scope, '.bw_form_control.bw_is_valid')] = { 'border-color': palette.success.base };
842
+ rules[_sx(scope, '.bw_form_control.bw_is_valid:focus')] = {
824
843
  'border-color': palette.success.base,
825
844
  'box-shadow': '0 0 0 0.2rem ' + palette.success.focus
826
845
  };
827
- rules[scopeSelector(scope, '.bw_form_control.bw_is_invalid')] = { 'border-color': palette.danger.base };
828
- rules[scopeSelector(scope, '.bw_form_control.bw_is_invalid:focus')] = {
846
+ rules[_sx(scope, '.bw_form_control.bw_is_invalid')] = { 'border-color': palette.danger.base };
847
+ rules[_sx(scope, '.bw_form_control.bw_is_invalid:focus')] = {
829
848
  'border-color': palette.danger.base,
830
849
  'box-shadow': '0 0 0 0.2rem ' + palette.danger.focus
831
850
  };
832
851
  // Form select
833
- rules[scopeSelector(scope, '.bw_form_select')] = {
852
+ rules[_sx(scope, '.bw_form_select')] = {
834
853
  'padding': sp.input,
835
854
  'border-radius': rd.input,
836
855
  'color': palette.dark.base,
837
856
  'background-color': palette.surface || '#fff',
838
857
  'border-color': palette.light.border
839
858
  };
840
- rules[scopeSelector(scope, '.bw_form_select:focus')] = {
859
+ rules[_sx(scope, '.bw_form_select:focus')] = {
841
860
  'border-color': palette.primary.border,
842
861
  'box-shadow': '0 0 0 0.25rem ' + palette.primary.focus
843
862
  };
@@ -845,43 +864,46 @@ function generateForms(scope, palette, layout) {
845
864
  return rules;
846
865
  }
847
866
 
848
- function generateNavigation(scope, palette) {
867
+ function generateNavigation(scope, palette, layout) {
849
868
  var rules = {};
850
- rules[scopeSelector(scope, '.bw_navbar')] = {
851
- 'background-color': palette.light.light,
869
+ rules[_sx(scope, '.bw_navbar')] = {
870
+ 'background-color': palette.surfaceAlt,
852
871
  'border-bottom-color': palette.light.border
853
872
  };
854
- rules[scopeSelector(scope, '.bw_navbar_brand')] = {
873
+ rules[_sx(scope, '.bw_navbar_brand')] = {
855
874
  'color': palette.dark.base
856
875
  };
857
- rules[scopeSelector(scope, '.bw_navbar_nav .bw_nav_link')] = {
858
- 'color': palette.secondary.base
876
+ rules[_sx(scope, '.bw_navbar_nav .bw_nav_link')] = {
877
+ 'color': palette.secondary.base,
878
+ 'border-radius': layout.radius.btn
859
879
  };
860
- rules[scopeSelector(scope, '.bw_navbar_nav .bw_nav_link:hover')] = {
861
- 'color': palette.dark.base
880
+ rules[_sx(scope, '.bw_navbar_nav .bw_nav_link:hover')] = {
881
+ 'color': palette.dark.base,
882
+ 'background-color': palette.surfaceAlt
862
883
  };
863
- rules[scopeSelector(scope, '.bw_navbar_nav .bw_nav_link.active')] = {
884
+ rules[_sx(scope, '.bw_navbar_nav .bw_nav_link.active')] = {
864
885
  'color': palette.primary.base,
865
- 'background-color': palette.primary.focus
886
+ 'background-color': palette.primary.focus,
887
+ 'font-weight': '600'
866
888
  };
867
- rules[scopeSelector(scope, '.bw_navbar_dark')] = {
889
+ rules[_sx(scope, '.bw_navbar_dark')] = {
868
890
  'background-color': palette.dark.base,
869
891
  'border-bottom-color': palette.dark.hover
870
892
  };
871
- rules[scopeSelector(scope, '.bw_navbar_dark .bw_navbar_brand')] = {
893
+ rules[_sx(scope, '.bw_navbar_dark .bw_navbar_brand')] = {
872
894
  'color': palette.light.base
873
895
  };
874
- rules[scopeSelector(scope, '.bw_navbar_dark .bw_nav_link')] = {
875
- 'color': 'rgba(255,255,255,.65)'
896
+ rules[_sx(scope, '.bw_navbar_dark .bw_nav_link')] = {
897
+ 'color': palette.light.border
876
898
  };
877
- rules[scopeSelector(scope, '.bw_navbar_dark .bw_nav_link:hover')] = {
878
- 'color': '#fff'
899
+ rules[_sx(scope, '.bw_navbar_dark .bw_nav_link:hover')] = {
900
+ 'color': palette.light.base
879
901
  };
880
- rules[scopeSelector(scope, '.bw_navbar_dark .bw_nav_link.active')] = {
881
- 'color': '#fff',
902
+ rules[_sx(scope, '.bw_navbar_dark .bw_nav_link.active')] = {
903
+ 'color': palette.light.base,
882
904
  'font-weight': '600'
883
905
  };
884
- rules[scopeSelector(scope, '.bw_nav_pills .bw_nav_link.active')] = {
906
+ rules[_sx(scope, '.bw_nav_pills .bw_nav_link.active')] = {
885
907
  'color': palette.primary.textOn,
886
908
  'background-color': palette.primary.base
887
909
  };
@@ -892,49 +914,58 @@ function generateTables(scope, palette, layout) {
892
914
  var rules = {};
893
915
  var sp = layout.spacing;
894
916
 
895
- rules[scopeSelector(scope, '.bw_table')] = {
917
+ rules[_sx(scope, '.bw_table')] = {
896
918
  'color': palette.dark.base,
897
919
  'border-color': palette.light.border
898
920
  };
899
- rules[scopeSelector(scope, '.bw_table > :not(caption) > * > *')] = {
921
+ rules[_sx(scope, '.bw_table > :not(caption) > * > *')] = {
900
922
  'padding': sp.cell,
901
923
  'border-bottom-color': palette.light.border
902
924
  };
903
- rules[scopeSelector(scope, '.bw_table > thead > tr > *')] = {
925
+ rules[_sx(scope, '.bw_table > thead > tr > *')] = {
904
926
  'color': palette.secondary.base,
905
927
  'border-bottom-color': palette.light.border,
906
- 'background-color': palette.light.light
928
+ 'background-color': palette.surfaceAlt
907
929
  };
908
- rules[scopeSelector(scope, '.bw_table_striped > tbody > tr:nth-of-type(odd) > *')] = {
909
- 'background-color': 'rgba(0, 0, 0, 0.05)'
930
+ rules[_sx(scope, '.bw_table_striped > tbody > tr:nth-of-type(odd) > *')] = {
931
+ 'background-color': palette.surfaceAlt
910
932
  };
911
- rules[scopeSelector(scope, '.bw_table_hover > tbody > tr:hover > *')] = {
933
+ rules[_sx(scope, '.bw_table_hover > tbody > tr:hover > *')] = {
912
934
  'background-color': palette.primary.focus
913
935
  };
914
- rules[scopeSelector(scope, '.bw_table_bordered')] = {
936
+ rules[_sx(scope, '.bw_table_selectable > tbody > tr')] = {
937
+ 'cursor': 'pointer'
938
+ };
939
+ rules[_sx(scope, '.bw_table > tbody > tr.bw_table_row_selected > *')] = {
940
+ 'background-color': palette.primary.light
941
+ };
942
+ rules[_sx(scope, '.bw_table_bordered')] = {
915
943
  'border-color': palette.light.border
916
944
  };
917
- rules[scopeSelector(scope, '.bw_table caption')] = {
945
+ rules[_sx(scope, '.bw_table caption')] = {
918
946
  'color': palette.secondary.base
919
947
  };
920
948
 
921
949
  return rules;
922
950
  }
923
951
 
924
- function generateTabs(scope, palette) {
925
- var rules = {};
926
- rules[scopeSelector(scope, '.bw_nav_tabs')] = {
952
+ function generateTabs(scope, palette, layout) {
953
+ var rules = {}, mo = layout.motion;
954
+ rules[_sx(scope, '.bw_nav_tabs')] = {
927
955
  'border-bottom-color': palette.light.border
928
956
  };
929
- rules[scopeSelector(scope, '.bw_nav_link')] = {
930
- 'color': palette.secondary.base
957
+ rules[_sx(scope, '.bw_nav_link')] = {
958
+ 'color': palette.secondary.base,
959
+ 'transition': 'color ' + mo.fast + ' ' + mo.easing + ', border-color ' + mo.fast + ' ' + mo.easing + ', background-color ' + mo.fast + ' ' + mo.easing
931
960
  };
932
- rules[scopeSelector(scope, '.bw_nav_tabs .bw_nav_link:hover')] = {
961
+ rules[_sx(scope, '.bw_nav_tabs .bw_nav_link:hover')] = {
933
962
  'color': palette.dark.base,
963
+ 'background-color': palette.surfaceAlt,
934
964
  'border-bottom-color': palette.light.border
935
965
  };
936
- rules[scopeSelector(scope, '.bw_nav_tabs .bw_nav_link.active')] = {
966
+ rules[_sx(scope, '.bw_nav_tabs .bw_nav_link.active')] = {
937
967
  'color': palette.primary.base,
968
+ 'background-color': palette.primary.focus,
938
969
  'border-bottom': '2px solid ' + palette.primary.base
939
970
  };
940
971
  return rules;
@@ -943,23 +974,25 @@ function generateTabs(scope, palette) {
943
974
  function generateListGroups(scope, palette, layout) {
944
975
  var rules = {};
945
976
  var sp = layout.spacing;
977
+ var mo = layout.motion;
946
978
 
947
- rules[scopeSelector(scope, '.bw_list_group_item')] = {
979
+ rules[_sx(scope, '.bw_list_group_item')] = {
948
980
  'padding': sp.cell,
949
981
  'color': palette.dark.base,
950
982
  'background-color': palette.surface || '#fff',
951
- 'border-color': palette.light.border
983
+ 'border-color': palette.light.border,
984
+ 'transition': 'color ' + mo.fast + ' ' + mo.easing + ', background-color ' + mo.fast + ' ' + mo.easing
952
985
  };
953
- rules[scopeSelector(scope, 'a.bw_list_group_item:hover')] = {
954
- 'background-color': palette.light.light,
986
+ rules[_sx(scope, 'a.bw_list_group_item:hover')] = {
987
+ 'background-color': palette.surfaceAlt,
955
988
  'color': palette.dark.hover
956
989
  };
957
- rules[scopeSelector(scope, '.bw_list_group_item.active')] = {
990
+ rules[_sx(scope, '.bw_list_group_item.active')] = {
958
991
  'color': palette.primary.textOn,
959
992
  'background-color': palette.primary.base,
960
993
  'border-color': palette.primary.base
961
994
  };
962
- rules[scopeSelector(scope, '.bw_list_group_item.disabled')] = {
995
+ rules[_sx(scope, '.bw_list_group_item.disabled')] = {
963
996
  'color': palette.secondary.base,
964
997
  'background-color': palette.surface || '#fff'
965
998
  };
@@ -967,28 +1000,37 @@ function generateListGroups(scope, palette, layout) {
967
1000
  return rules;
968
1001
  }
969
1002
 
970
- function generatePagination(scope, palette) {
971
- var rules = {};
972
- rules[scopeSelector(scope, '.bw_page_link')] = {
1003
+ function generatePagination(scope, palette, layout) {
1004
+ var rules = {}, mo = layout.motion, rd = layout.radius;
1005
+ rules[_sx(scope, '.bw_page_item:first-child .bw_page_link')] = {
1006
+ 'border-top-left-radius': rd.btn,
1007
+ 'border-bottom-left-radius': rd.btn
1008
+ };
1009
+ rules[_sx(scope, '.bw_page_item:last-child .bw_page_link')] = {
1010
+ 'border-top-right-radius': rd.btn,
1011
+ 'border-bottom-right-radius': rd.btn
1012
+ };
1013
+ rules[_sx(scope, '.bw_page_link')] = {
973
1014
  'color': palette.primary.base,
974
1015
  'background-color': palette.surface || '#fff',
975
- 'border-color': palette.light.border
1016
+ 'border-color': palette.light.border,
1017
+ 'transition': 'color ' + mo.fast + ' ' + mo.easing + ', background-color ' + mo.fast + ' ' + mo.easing
976
1018
  };
977
- rules[scopeSelector(scope, '.bw_page_link:hover')] = {
1019
+ rules[_sx(scope, '.bw_page_link:hover')] = {
978
1020
  'color': palette.primary.hover,
979
- 'background-color': palette.light.light,
1021
+ 'background-color': palette.surfaceAlt,
980
1022
  'border-color': palette.light.border
981
1023
  };
982
- rules[scopeSelector(scope, '.bw_page_link:focus')] = {
1024
+ rules[_sx(scope, '.bw_page_link:focus')] = {
983
1025
  'outline': '2px solid ' + palette.primary.base,
984
1026
  'outline-offset': '-2px'
985
1027
  };
986
- rules[scopeSelector(scope, '.bw_page_item.bw_active .bw_page_link')] = {
1028
+ rules[_sx(scope, '.bw_page_item.bw_active .bw_page_link')] = {
987
1029
  'color': palette.primary.textOn,
988
1030
  'background-color': palette.primary.base,
989
1031
  'border-color': palette.primary.base
990
1032
  };
991
- rules[scopeSelector(scope, '.bw_page_item.bw_disabled .bw_page_link')] = {
1033
+ rules[_sx(scope, '.bw_page_item.bw_disabled .bw_page_link')] = {
992
1034
  'color': palette.secondary.base,
993
1035
  'background-color': palette.surface || '#fff',
994
1036
  'border-color': palette.light.border
@@ -998,12 +1040,12 @@ function generatePagination(scope, palette) {
998
1040
 
999
1041
  function generateProgress(scope, palette) {
1000
1042
  var rules = {};
1001
- rules[scopeSelector(scope, '.bw_progress')] = {
1002
- 'background-color': palette.light.light,
1043
+ rules[_sx(scope, '.bw_progress')] = {
1044
+ 'background-color': palette.surfaceAlt,
1003
1045
  'box-shadow': 'inset 0 1px 2px rgba(0,0,0,.1)'
1004
1046
  };
1005
- rules[scopeSelector(scope, '.bw_progress_bar')] = {
1006
- 'color': '#fff',
1047
+ rules[_sx(scope, '.bw_progress_bar')] = {
1048
+ 'color': palette.primary.textOn,
1007
1049
  'background-color': palette.primary.base,
1008
1050
  'box-shadow': 'inset 0 -1px 0 rgba(0,0,0,.15)'
1009
1051
  };
@@ -1022,26 +1064,31 @@ function generateResetThemed(scope, palette) {
1022
1064
  'color': palette.dark.base,
1023
1065
  'background-color': bg
1024
1066
  };
1025
- rules[scopeSelector(scope, 'body')] = baseReset;
1026
- // Also apply to the scope element itself so themes work on any container, not just body
1027
- if (scope) {
1028
- rules['.' + scope] = baseReset;
1029
- }
1067
+ rules[_sx(scope, 'body')] = baseReset;
1030
1068
  return rules;
1031
1069
  }
1032
1070
 
1033
- function generateBreadcrumbThemed(scope, palette) {
1034
- var rules = {};
1035
- rules[scopeSelector(scope, '.bw_breadcrumb_item + .bw_breadcrumb_item::before')] = {
1036
- 'color': palette.secondary.base
1071
+ function generateBreadcrumbThemed(scope, palette, layout) {
1072
+ var rules = {}, mo = layout.motion;
1073
+ rules[_sx(scope, '.bw_breadcrumb')] = {
1074
+ 'background-color': palette.surfaceAlt,
1075
+ 'padding': '0.625rem 1rem',
1076
+ 'border-radius': layout.radius.btn
1037
1077
  };
1038
- rules[scopeSelector(scope, '.bw_breadcrumb_item.active')] = {
1078
+ rules[_sx(scope, '.bw_breadcrumb_item + .bw_breadcrumb_item::before')] = {
1039
1079
  'color': palette.secondary.base
1040
1080
  };
1041
- rules[scopeSelector(scope, '.bw_breadcrumb_item a:hover')] = {
1081
+ rules[_sx(scope, '.bw_breadcrumb_item a')] = {
1082
+ 'color': palette.primary.base,
1083
+ 'transition': 'color ' + mo.fast + ' ' + mo.easing
1084
+ };
1085
+ rules[_sx(scope, '.bw_breadcrumb_item a:hover')] = {
1042
1086
  'color': palette.primary.hover,
1043
1087
  'text-decoration': 'underline'
1044
1088
  };
1089
+ rules[_sx(scope, '.bw_breadcrumb_item.active')] = {
1090
+ 'color': palette.dark.base
1091
+ };
1045
1092
  return rules;
1046
1093
  }
1047
1094
 
@@ -1049,11 +1096,11 @@ function generateBreadcrumbThemed(scope, palette) {
1049
1096
 
1050
1097
  function generateCloseButtonThemed(scope, palette) {
1051
1098
  var rules = {};
1052
- rules[scopeSelector(scope, '.bw_close')] = {
1099
+ rules[_sx(scope, '.bw_close')] = {
1053
1100
  'color': palette.dark.base,
1054
1101
  'opacity': '0.5'
1055
1102
  };
1056
- rules[scopeSelector(scope, '.bw_close:focus')] = {
1103
+ rules[_sx(scope, '.bw_close:focus')] = {
1057
1104
  'box-shadow': '0 0 0 0.25rem ' + palette.primary.focus
1058
1105
  };
1059
1106
  return rules;
@@ -1061,82 +1108,94 @@ function generateCloseButtonThemed(scope, palette) {
1061
1108
 
1062
1109
  function generateSectionsThemed(scope, palette) {
1063
1110
  var rules = {};
1064
- rules[scopeSelector(scope, '.bw_section_subtitle')] = {
1111
+ rules[_sx(scope, '.bw_section_subtitle')] = {
1065
1112
  'color': palette.secondary.base
1066
1113
  };
1067
- rules[scopeSelector(scope, '.bw_feature_description')] = {
1114
+ rules[_sx(scope, '.bw_feature_description')] = {
1068
1115
  'color': palette.secondary.base
1069
1116
  };
1070
- rules[scopeSelector(scope, '.bw_cta_description')] = {
1117
+ rules[_sx(scope, '.bw_cta_description')] = {
1071
1118
  'color': palette.secondary.base
1072
1119
  };
1073
1120
  return rules;
1074
1121
  }
1075
1122
 
1076
- function generateAccordionThemed(scope, palette) {
1123
+ function generateAccordionThemed(scope, palette, layout) {
1077
1124
  var rules = {};
1078
- rules[scopeSelector(scope, '.bw_accordion_item')] = {
1125
+ var rd = layout ? layout.radius : { card: '8px' };
1126
+ rules[_sx(scope, '.bw_accordion_item')] = {
1079
1127
  'background-color': palette.surface || '#fff',
1080
1128
  'border-color': palette.light.border
1081
1129
  };
1082
- rules[scopeSelector(scope, '.bw_accordion_button')] = {
1130
+ rules[_sx(scope, '.bw_accordion_item:first-child')] = {
1131
+ 'border-top-left-radius': rd.card,
1132
+ 'border-top-right-radius': rd.card
1133
+ };
1134
+ rules[_sx(scope, '.bw_accordion_item:last-child')] = {
1135
+ 'border-bottom-left-radius': rd.card,
1136
+ 'border-bottom-right-radius': rd.card
1137
+ };
1138
+ rules[_sx(scope, '.bw_accordion_button')] = {
1083
1139
  'color': palette.dark.base
1084
1140
  };
1085
- rules[scopeSelector(scope, '.bw_accordion_button:not(.bw_collapsed)')] = {
1141
+ rules[_sx(scope, '.bw_accordion_button:not(.bw_collapsed)')] = {
1086
1142
  'color': palette.primary.darkText,
1087
- 'background-color': palette.primary.light
1143
+ 'background-color': palette.primary.light,
1144
+ 'border-left': '3px solid ' + palette.primary.base
1088
1145
  };
1089
- rules[scopeSelector(scope, '.bw_accordion_button:hover')] = {
1090
- 'background-color': palette.light.light
1146
+ rules[_sx(scope, '.bw_accordion_button:hover')] = {
1147
+ 'background-color': palette.surfaceAlt
1091
1148
  };
1092
- rules[scopeSelector(scope, '.bw_accordion_button:not(.bw_collapsed):hover')] = {
1093
- 'background-color': palette.primary.hover
1149
+ rules[_sx(scope, '.bw_accordion_button:not(.bw_collapsed):hover')] = {
1150
+ 'background-color': palette.primary.base,
1151
+ 'color': palette.primary.textOn
1094
1152
  };
1095
- rules[scopeSelector(scope, '.bw_accordion_button:focus-visible')] = {
1153
+ rules[_sx(scope, '.bw_accordion_button:focus-visible')] = {
1096
1154
  'box-shadow': '0 0 0 0.2rem ' + palette.primary.focus
1097
1155
  };
1098
- rules[scopeSelector(scope, '.bw_accordion_body')] = {
1099
- 'border-top': '1px solid ' + palette.light.border
1156
+ rules[_sx(scope, '.bw_accordion_body')] = {
1157
+ 'border-top': '1px solid ' + palette.light.border,
1158
+ 'background-color': palette.surfaceAlt
1100
1159
  };
1101
1160
  return rules;
1102
1161
  }
1103
1162
 
1104
1163
  function generateCarouselThemed(scope, palette) {
1105
1164
  var rules = {};
1106
- rules[scopeSelector(scope, '.bw_carousel')] = {
1107
- 'background-color': palette.light.light
1165
+ rules[_sx(scope, '.bw_carousel')] = {
1166
+ 'background-color': palette.surfaceAlt
1108
1167
  };
1109
- rules[scopeSelector(scope, '.bw_carousel_indicator.active')] = {
1168
+ rules[_sx(scope, '.bw_carousel_indicator.active')] = {
1110
1169
  'background-color': palette.primary.base
1111
1170
  };
1112
- rules[scopeSelector(scope, '.bw_carousel_control')] = {
1113
- 'background-color': 'rgba(0,0,0,0.4)',
1114
- 'color': '#fff'
1171
+ rules[_sx(scope, '.bw_carousel_control')] = {
1172
+ 'background-color': palette.dark.base,
1173
+ 'color': palette.dark.textOn
1115
1174
  };
1116
- rules[scopeSelector(scope, '.bw_carousel_control:hover')] = {
1117
- 'background-color': 'rgba(0,0,0,0.6)'
1175
+ rules[_sx(scope, '.bw_carousel_control:hover')] = {
1176
+ 'background-color': palette.dark.hover
1118
1177
  };
1119
- rules[scopeSelector(scope, '.bw_carousel_caption')] = {
1120
- 'background': 'linear-gradient(transparent, rgba(0,0,0,0.6))',
1121
- 'color': '#fff'
1178
+ rules[_sx(scope, '.bw_carousel_caption')] = {
1179
+ 'background': 'linear-gradient(transparent, ' + palette.dark.base + ')',
1180
+ 'color': palette.dark.textOn
1122
1181
  };
1123
1182
  return rules;
1124
1183
  }
1125
1184
 
1126
1185
  function generateModalThemed(scope, palette, layout) {
1127
1186
  var rules = {};
1128
- rules[scopeSelector(scope, '.bw_modal_content')] = {
1187
+ rules[_sx(scope, '.bw_modal_content')] = {
1129
1188
  'background-color': palette.surface || '#fff',
1130
1189
  'border-color': palette.light.border,
1131
1190
  'box-shadow': layout.elevation.lg
1132
1191
  };
1133
- rules[scopeSelector(scope, '.bw_modal_header')] = {
1192
+ rules[_sx(scope, '.bw_modal_header')] = {
1134
1193
  'border-bottom-color': palette.light.border
1135
1194
  };
1136
- rules[scopeSelector(scope, '.bw_modal_footer')] = {
1195
+ rules[_sx(scope, '.bw_modal_footer')] = {
1137
1196
  'border-top-color': palette.light.border
1138
1197
  };
1139
- rules[scopeSelector(scope, '.bw_modal_title')] = {
1198
+ rules[_sx(scope, '.bw_modal_title')] = {
1140
1199
  'color': palette.dark.base
1141
1200
  };
1142
1201
  return rules;
@@ -1144,13 +1203,13 @@ function generateModalThemed(scope, palette, layout) {
1144
1203
 
1145
1204
  function generateToastThemed(scope, palette, layout) {
1146
1205
  var rules = {};
1147
- rules[scopeSelector(scope, '.bw_toast')] = {
1206
+ rules[_sx(scope, '.bw_toast')] = {
1148
1207
  'background-color': palette.surface || '#fff',
1149
- 'border-color': 'rgba(0,0,0,0.1)',
1208
+ 'border-color': palette.light.border,
1150
1209
  'box-shadow': layout.elevation.lg
1151
1210
  };
1152
- rules[scopeSelector(scope, '.bw_toast_header')] = {
1153
- 'border-bottom-color': 'rgba(0,0,0,0.05)'
1211
+ rules[_sx(scope, '.bw_toast_header')] = {
1212
+ 'border-bottom-color': palette.light.border
1154
1213
  };
1155
1214
  // Variant toast borders handled by palette class
1156
1215
  return rules;
@@ -1158,22 +1217,23 @@ function generateToastThemed(scope, palette, layout) {
1158
1217
 
1159
1218
  function generateDropdownThemed(scope, palette, layout) {
1160
1219
  var rules = {};
1161
- rules[scopeSelector(scope, '.bw_dropdown_menu')] = {
1220
+ rules[_sx(scope, '.bw_dropdown_menu')] = {
1162
1221
  'background-color': palette.surface || '#fff',
1163
1222
  'border-color': palette.light.border,
1164
1223
  'box-shadow': layout.elevation.md
1165
1224
  };
1166
- rules[scopeSelector(scope, '.bw_dropdown_item')] = {
1167
- 'color': palette.dark.base
1225
+ rules[_sx(scope, '.bw_dropdown_item')] = {
1226
+ 'color': palette.dark.base,
1227
+ 'transition': 'background-color ' + layout.motion.fast + ' ' + layout.motion.easing
1168
1228
  };
1169
- rules[scopeSelector(scope, '.bw_dropdown_item:hover')] = {
1229
+ rules[_sx(scope, '.bw_dropdown_item:hover')] = {
1170
1230
  'color': palette.dark.hover,
1171
- 'background-color': palette.light.light
1231
+ 'background-color': palette.surfaceAlt
1172
1232
  };
1173
- rules[scopeSelector(scope, '.bw_dropdown_item.disabled')] = {
1233
+ rules[_sx(scope, '.bw_dropdown_item.disabled')] = {
1174
1234
  'color': palette.secondary.base
1175
1235
  };
1176
- rules[scopeSelector(scope, '.bw_dropdown_divider')] = {
1236
+ rules[_sx(scope, '.bw_dropdown_divider')] = {
1177
1237
  'border-top-color': palette.light.border
1178
1238
  };
1179
1239
  return rules;
@@ -1181,15 +1241,15 @@ function generateDropdownThemed(scope, palette, layout) {
1181
1241
 
1182
1242
  function generateSwitchThemed(scope, palette) {
1183
1243
  var rules = {};
1184
- rules[scopeSelector(scope, '.bw_form_switch .bw_switch_input')] = {
1244
+ rules[_sx(scope, '.bw_form_switch .bw_switch_input')] = {
1185
1245
  'background-color': palette.secondary.base,
1186
1246
  'border-color': palette.secondary.base
1187
1247
  };
1188
- rules[scopeSelector(scope, '.bw_form_switch .bw_switch_input:checked')] = {
1248
+ rules[_sx(scope, '.bw_form_switch .bw_switch_input:checked')] = {
1189
1249
  'background-color': palette.primary.base,
1190
1250
  'border-color': palette.primary.base
1191
1251
  };
1192
- rules[scopeSelector(scope, '.bw_form_switch .bw_switch_input:focus')] = {
1252
+ rules[_sx(scope, '.bw_form_switch .bw_switch_input:focus')] = {
1193
1253
  'box-shadow': '0 0 0 0.25rem ' + palette.primary.focus
1194
1254
  };
1195
1255
  return rules;
@@ -1197,88 +1257,102 @@ function generateSwitchThemed(scope, palette) {
1197
1257
 
1198
1258
  function generateSkeletonThemed(scope, palette) {
1199
1259
  var rules = {};
1200
- rules[scopeSelector(scope, '.bw_skeleton')] = {
1201
- 'background': 'linear-gradient(90deg, ' + palette.light.border + ' 25%, ' + palette.light.light + ' 37%, ' + palette.light.border + ' 63%)'
1260
+ rules[_sx(scope, '.bw_skeleton')] = {
1261
+ 'background': 'linear-gradient(90deg, ' + palette.light.border + ' 25%, ' + palette.surfaceAlt + ' 37%, ' + palette.light.border + ' 63%)'
1202
1262
  };
1203
1263
  return rules;
1204
1264
  }
1205
1265
 
1206
1266
  // generateAvatarThemed: removed — palette class on root handles variants
1207
1267
 
1208
- function generateStatCardThemed(scope, palette) {
1209
- var rules = {};
1268
+ function generateStatCardThemed(scope, palette, layout) {
1269
+ var rules = {}, mo = layout.motion, el = layout.elevation, rd = layout.radius;
1270
+ rules[_sx(scope, '.bw_stat_card')] = {
1271
+ 'background-color': palette.surface || '#fff',
1272
+ 'color': palette.dark.base,
1273
+ 'border': '1px solid ' + palette.light.border,
1274
+ 'border-radius': rd.card,
1275
+ 'box-shadow': el.sm,
1276
+ 'transition': 'box-shadow ' + mo.fast + ' ' + mo.easing + ', transform ' + mo.fast + ' ' + mo.easing
1277
+ };
1278
+ rules[_sx(scope, '.bw_stat_card:hover')] = { 'box-shadow': el.md };
1210
1279
  // Variant border colors handled by palette class
1211
- rules[scopeSelector(scope, '.bw_stat_change_up')] = { 'color': palette.success.base };
1212
- rules[scopeSelector(scope, '.bw_stat_change_down')] = { 'color': palette.danger.base };
1280
+ rules[_sx(scope, '.bw_stat_change_up')] = { 'color': palette.success.base };
1281
+ rules[_sx(scope, '.bw_stat_change_down')] = { 'color': palette.danger.base };
1213
1282
  return rules;
1214
1283
  }
1215
1284
 
1216
1285
  function generateTimelineThemed(scope, palette) {
1217
1286
  var rules = {};
1218
- rules[scopeSelector(scope, '.bw_timeline::before')] = { 'background-color': palette.light.border };
1287
+ rules[_sx(scope, '.bw_timeline::before')] = { 'background-color': palette.light.border };
1219
1288
  // Variant marker colors handled by palette class
1220
- rules[scopeSelector(scope, '.bw_timeline_date')] = { 'color': palette.secondary.base };
1289
+ rules[_sx(scope, '.bw_timeline_date')] = { 'color': palette.secondary.base };
1221
1290
  return rules;
1222
1291
  }
1223
1292
 
1224
1293
  function generateStepperThemed(scope, palette) {
1225
1294
  var rules = {};
1226
- rules[scopeSelector(scope, '.bw_step_indicator')] = {
1227
- 'background-color': palette.light.light,
1295
+ rules[_sx(scope, '.bw_step_indicator')] = {
1296
+ 'background-color': palette.surfaceAlt,
1228
1297
  'border': '2px solid ' + palette.light.border,
1229
1298
  'color': palette.secondary.base
1230
1299
  };
1231
- rules[scopeSelector(scope, '.bw_step + .bw_step::before')] = { 'background-color': palette.light.border };
1232
- rules[scopeSelector(scope, '.bw_step_active .bw_step_indicator')] = {
1300
+ rules[_sx(scope, '.bw_step + .bw_step::before')] = { 'background-color': palette.light.border };
1301
+ rules[_sx(scope, '.bw_step_active .bw_step_indicator')] = {
1233
1302
  'background-color': palette.primary.base,
1234
1303
  'color': palette.primary.textOn
1235
1304
  };
1236
- rules[scopeSelector(scope, '.bw_step_active .bw_step_label')] = {
1305
+ rules[_sx(scope, '.bw_step_active .bw_step_label')] = {
1237
1306
  'color': palette.dark.base,
1238
1307
  'font-weight': '600'
1239
1308
  };
1240
- rules[scopeSelector(scope, '.bw_step_completed .bw_step_indicator')] = {
1309
+ rules[_sx(scope, '.bw_step_completed .bw_step_indicator')] = {
1241
1310
  'background-color': palette.primary.base,
1242
1311
  'color': palette.primary.textOn
1243
1312
  };
1244
- rules[scopeSelector(scope, '.bw_step_completed .bw_step_label')] = { 'color': palette.primary.base };
1245
- rules[scopeSelector(scope, '.bw_step_completed + .bw_step::before')] = { 'background-color': palette.primary.base };
1313
+ rules[_sx(scope, '.bw_step_completed .bw_step_label')] = { 'color': palette.primary.base };
1314
+ rules[_sx(scope, '.bw_step_completed + .bw_step::before')] = { 'background-color': palette.primary.base };
1246
1315
  return rules;
1247
1316
  }
1248
1317
 
1249
1318
  function generateChipInputThemed(scope, palette) {
1250
1319
  var rules = {};
1251
- rules[scopeSelector(scope, '.bw_chip_input')] = { 'border-color': palette.light.border };
1252
- rules[scopeSelector(scope, '.bw_chip_input:focus-within')] = {
1320
+ rules[_sx(scope, '.bw_chip_input')] = {
1321
+ 'border-color': palette.light.border,
1322
+ 'background-color': palette.surface || '#fff',
1323
+ 'color': palette.dark.base
1324
+ };
1325
+ rules[_sx(scope, '.bw_chip_input:focus-within')] = {
1253
1326
  'border-color': palette.primary.base,
1254
1327
  'box-shadow': '0 0 0 0.2rem ' + palette.primary.focus
1255
1328
  };
1256
- rules[scopeSelector(scope, '.bw_chip')] = {
1257
- 'background-color': palette.light.light,
1329
+ rules[_sx(scope, '.bw_chip')] = {
1330
+ 'background-color': palette.surfaceAlt,
1258
1331
  'color': palette.dark.base
1259
1332
  };
1260
- rules[scopeSelector(scope, '.bw_chip_remove:hover')] = {
1333
+ rules[_sx(scope, '.bw_chip_remove:hover')] = {
1261
1334
  'color': palette.danger.base,
1262
1335
  'background-color': palette.danger.light
1263
1336
  };
1264
1337
  return rules;
1265
1338
  }
1266
1339
 
1267
- function generateFileUploadThemed(scope, palette) {
1268
- var rules = {};
1269
- rules[scopeSelector(scope, '.bw_file_upload')] = {
1340
+ function generateFileUploadThemed(scope, palette, layout) {
1341
+ var rules = {}, mo = layout.motion;
1342
+ rules[_sx(scope, '.bw_file_upload')] = {
1270
1343
  'border-color': palette.light.border,
1271
- 'background-color': palette.light.light
1344
+ 'background-color': palette.surfaceAlt,
1345
+ 'transition': 'border-color ' + mo.fast + ' ' + mo.easing + ', background-color ' + mo.fast + ' ' + mo.easing
1272
1346
  };
1273
- rules[scopeSelector(scope, '.bw_file_upload:hover')] = {
1347
+ rules[_sx(scope, '.bw_file_upload:hover')] = {
1274
1348
  'border-color': palette.primary.base,
1275
1349
  'background-color': palette.primary.light
1276
1350
  };
1277
- rules[scopeSelector(scope, '.bw_file_upload:focus')] = {
1351
+ rules[_sx(scope, '.bw_file_upload:focus')] = {
1278
1352
  'outline': '2px solid ' + palette.primary.base,
1279
1353
  'outline-offset': '2px'
1280
1354
  };
1281
- rules[scopeSelector(scope, '.bw_file_upload.bw_file_upload_active')] = {
1355
+ rules[_sx(scope, '.bw_file_upload.bw_file_upload_active')] = {
1282
1356
  'border-color': palette.primary.base,
1283
1357
  'background-color': palette.primary.light,
1284
1358
  'border-style': 'solid'
@@ -1288,35 +1362,73 @@ function generateFileUploadThemed(scope, palette) {
1288
1362
 
1289
1363
  function generateRangeThemed(scope, palette) {
1290
1364
  var rules = {};
1291
- rules[scopeSelector(scope, '.bw_range')] = { 'background-color': palette.light.border };
1292
- rules[scopeSelector(scope, '.bw_range::-webkit-slider-thumb')] = {
1365
+ rules[_sx(scope, '.bw_range')] = { 'background-color': palette.light.border };
1366
+ rules[_sx(scope, '.bw_range::-webkit-slider-thumb')] = {
1293
1367
  'background-color': palette.primary.base,
1294
- 'border-color': '#fff',
1368
+ 'border-color': palette.surface || '#fff',
1295
1369
  'box-shadow': '0 1px 3px rgba(0,0,0,0.2)',
1296
1370
  'transition': 'background-color 0.15s ease-out, transform 0.15s ease-out'
1297
1371
  };
1298
- rules[scopeSelector(scope, '.bw_range::-moz-range-thumb')] = {
1372
+ rules[_sx(scope, '.bw_range::-moz-range-thumb')] = {
1299
1373
  'background-color': palette.primary.base,
1300
- 'border-color': '#fff',
1374
+ 'border-color': palette.surface || '#fff',
1301
1375
  'box-shadow': '0 1px 3px rgba(0,0,0,0.2)'
1302
1376
  };
1303
1377
  return rules;
1304
1378
  }
1305
1379
 
1306
- function generateSearchThemed(scope, palette) {
1307
- var rules = {};
1308
- rules[scopeSelector(scope, '.bw_search_clear:hover')] = { 'color': palette.dark.base };
1380
+ function generateTooltipThemed(scope, palette, layout) {
1381
+ var rules = {}, sp = layout.spacing, rd = layout.radius, el = layout.elevation, mo = layout.motion;
1382
+ rules[_sx(scope, '.bw_tooltip')] = {
1383
+ 'background-color': palette.dark.base, 'color': palette.dark.textOn,
1384
+ 'padding': sp.input, 'border-radius': rd.badge, 'box-shadow': el.md,
1385
+ 'transition': 'opacity ' + mo.fast + ' ' + mo.easing + ', transform ' + mo.fast + ' ' + mo.easing
1386
+ };
1309
1387
  return rules;
1310
1388
  }
1311
1389
 
1312
- function generateCodeDemoThemed(scope, palette) {
1390
+ function generatePopoverThemed(scope, palette, layout) {
1391
+ var rules = {}, sp = layout.spacing, rd = layout.radius, el = layout.elevation, mo = layout.motion;
1392
+ rules[_sx(scope, '.bw_popover')] = {
1393
+ 'background-color': palette.surface || '#fff', 'color': palette.dark.base,
1394
+ 'border': '1px solid ' + palette.light.border, 'border-radius': rd.card, 'box-shadow': el.lg,
1395
+ 'transition': 'opacity ' + mo.fast + ' ' + mo.easing + ', transform ' + mo.fast + ' ' + mo.easing
1396
+ };
1397
+ rules[_sx(scope, '.bw_popover_header')] = {
1398
+ 'background-color': palette.surfaceAlt, 'border-bottom': '1px solid ' + palette.light.border,
1399
+ 'padding': sp.input
1400
+ };
1401
+ rules[_sx(scope, '.bw_popover_body')] = { 'padding': sp.card };
1402
+ return rules;
1403
+ }
1404
+
1405
+ function generateSearchThemed(scope, palette, layout) {
1406
+ var rules = {}, mo = layout.motion;
1407
+ rules[_sx(scope, '.bw_search_input')] = {
1408
+ 'background-color': palette.surface || '#fff',
1409
+ 'color': palette.dark.base
1410
+ };
1411
+ rules[_sx(scope, '.bw_search_clear')] = {
1412
+ 'transition': 'color ' + mo.fast + ' ' + mo.easing + ', background-color ' + mo.fast + ' ' + mo.easing
1413
+ };
1414
+ rules[_sx(scope, '.bw_search_clear:hover')] = { 'color': palette.dark.base };
1415
+ return rules;
1416
+ }
1417
+
1418
+ function generateCodeDemoThemed(scope, palette, layout) {
1313
1419
  var rules = {};
1314
- rules[scopeSelector(scope, '.bw_code_copy_btn_copied')] = {
1420
+ var rd = layout ? layout.radius : { card: '0.375rem' };
1421
+ rules[_sx(scope, '.bw_code_demo')] = {
1422
+ 'background-color': palette.surface || '#fff',
1423
+ 'color': palette.dark.base,
1424
+ 'border-radius': rd.card
1425
+ };
1426
+ rules[_sx(scope, '.bw_code_copy_btn_copied')] = {
1315
1427
  'background': palette.success.base,
1316
1428
  'color': palette.success.textOn,
1317
1429
  'border-color': palette.success.base
1318
1430
  };
1319
- rules[scopeSelector(scope, '.bw_copy_btn:hover')] = {
1431
+ rules[_sx(scope, '.bw_copy_btn:hover')] = {
1320
1432
  'background': 'rgba(255,255,255,0.2)',
1321
1433
  'color': '#fff'
1322
1434
  };
@@ -1326,7 +1438,7 @@ function generateCodeDemoThemed(scope, palette) {
1326
1438
  function generateNavPillsThemed(scope, palette, layout) {
1327
1439
  var rules = {};
1328
1440
  var rd = layout.radius;
1329
- rules[scopeSelector(scope, '.bw_nav_pills .bw_nav_link')] = { 'border-radius': rd.btn };
1441
+ rules[_sx(scope, '.bw_nav_pills .bw_nav_link')] = { 'border-radius': rd.btn };
1330
1442
  return rules;
1331
1443
  }
1332
1444
 
@@ -1352,21 +1464,21 @@ function generatePaletteClasses(scope, palette) {
1352
1464
  var s = palette[k];
1353
1465
 
1354
1466
  // --- Root palette class: sets default bg/color/border ---
1355
- rules[scopeSelector(scope, '.bw_' + k)] = {
1467
+ rules[_sx(scope, '.bw_' + k)] = {
1356
1468
  'background-color': s.base,
1357
1469
  'color': s.textOn,
1358
1470
  'border-color': s.base
1359
1471
  };
1360
1472
 
1361
1473
  // --- Pseudo-states (shared across all components) ---
1362
- rules[scopeSelector(scope, '.bw_' + k + ':hover')] = {
1474
+ rules[_sx(scope, '.bw_' + k + ':hover')] = {
1363
1475
  'background-color': s.hover,
1364
1476
  'border-color': s.active
1365
1477
  };
1366
- rules[scopeSelector(scope, '.bw_' + k + ':active')] = {
1478
+ rules[_sx(scope, '.bw_' + k + ':active')] = {
1367
1479
  'background-color': s.active
1368
1480
  };
1369
- rules[scopeSelector(scope, '.bw_' + k + ':focus-visible')] = {
1481
+ rules[_sx(scope, '.bw_' + k + ':focus-visible')] = {
1370
1482
  'box-shadow': '0 0 0 3px ' + s.focus,
1371
1483
  'outline': 'none'
1372
1484
  };
@@ -1374,70 +1486,99 @@ function generatePaletteClasses(scope, palette) {
1374
1486
  // --- Component-specific overrides ---
1375
1487
 
1376
1488
  // Alerts: light bg, dark text, subtle border
1377
- rules[scopeSelector(scope, '.bw_alert.bw_' + k)] = {
1489
+ rules[_sx(scope, '.bw_alert.bw_' + k)] = {
1378
1490
  'background-color': s.light,
1379
1491
  'color': s.darkText,
1380
1492
  'border-color': s.border
1381
1493
  };
1382
1494
 
1383
1495
  // Toast: inherit bg, left border accent
1384
- rules[scopeSelector(scope, '.bw_toast.bw_' + k)] = {
1496
+ rules[_sx(scope, '.bw_toast.bw_' + k)] = {
1385
1497
  'background-color': 'inherit',
1386
1498
  'color': 'inherit',
1387
1499
  'border-left': '4px solid ' + s.base
1388
1500
  };
1389
1501
 
1390
1502
  // Stat card: inherit bg, left border accent
1391
- rules[scopeSelector(scope, '.bw_stat_card.bw_' + k)] = {
1503
+ rules[_sx(scope, '.bw_stat_card.bw_' + k)] = {
1392
1504
  'background-color': 'inherit',
1393
1505
  'color': 'inherit',
1394
1506
  'border-left-color': s.base
1395
1507
  };
1396
1508
 
1397
1509
  // Card accent: left border accent, inherit bg
1398
- rules[scopeSelector(scope, '.bw_card.bw_' + k)] = {
1510
+ rules[_sx(scope, '.bw_card.bw_' + k)] = {
1399
1511
  'background-color': 'inherit',
1400
1512
  'color': 'inherit',
1401
1513
  'border-left': '4px solid ' + s.base
1402
1514
  };
1403
1515
 
1404
1516
  // Timeline marker: colored dot
1405
- rules[scopeSelector(scope, '.bw_timeline_marker.bw_' + k)] = {
1517
+ rules[_sx(scope, '.bw_timeline_marker.bw_' + k)] = {
1406
1518
  'box-shadow': '0 0 0 2px ' + s.base
1407
1519
  };
1408
1520
 
1409
- // Spinner: text color only, transparent bg
1410
- rules[scopeSelector(scope, '.bw_spinner_border.bw_' + k + ',\n' + scopeSelector(scope, '.bw_spinner_grow.bw_' + k))] = {
1521
+ // Spinner: set color, re-apply border pattern so the root palette class
1522
+ // border-color doesn't fill in the transparent gap that makes it spin.
1523
+ // Also neutralize hover/active which would override border-right-color.
1524
+ rules[_sx(scope, '.bw_spinner_border.bw_' + k)] = {
1411
1525
  'background-color': 'transparent',
1412
1526
  'color': s.base,
1413
- 'border-color': 'currentColor'
1527
+ 'border-color': s.base,
1528
+ 'border-right-color': 'transparent'
1529
+ };
1530
+ rules[_sx(scope, '.bw_spinner_border.bw_' + k + ':hover')] = {
1531
+ 'background-color': 'transparent',
1532
+ 'border-color': s.base,
1533
+ 'border-right-color': 'transparent'
1534
+ };
1535
+ rules[_sx(scope, '.bw_spinner_grow.bw_' + k)] = {
1536
+ 'background-color': s.base,
1537
+ 'color': s.base
1414
1538
  };
1415
1539
 
1416
1540
  // Outline button: transparent bg, colored border+text, solid on hover
1417
- rules[scopeSelector(scope, '.bw_btn_outline.bw_' + k)] = {
1541
+ rules[_sx(scope, '.bw_btn_outline.bw_' + k)] = {
1418
1542
  'background-color': 'transparent',
1419
1543
  'color': s.base,
1420
1544
  'border-color': s.base
1421
1545
  };
1422
- rules[scopeSelector(scope, '.bw_btn_outline.bw_' + k + ':hover')] = {
1546
+ rules[_sx(scope, '.bw_btn_outline.bw_' + k + ':hover')] = {
1423
1547
  'background-color': s.base,
1424
1548
  'color': s.textOn
1425
1549
  };
1426
1550
 
1427
1551
  // Hero: gradient background
1428
- rules[scopeSelector(scope, '.bw_hero.bw_' + k)] = {
1552
+ rules[_sx(scope, '.bw_hero.bw_' + k)] = {
1429
1553
  'background': 'linear-gradient(135deg, ' + s.base + ' 0%, ' + s.hover + ' 100%)',
1430
1554
  'color': s.textOn
1431
1555
  };
1432
1556
 
1433
- // Progress bar: white text on colored bg (default is fine, just ensure text)
1434
- rules[scopeSelector(scope, '.bw_progress_bar.bw_' + k)] = {
1435
- 'color': '#fff'
1557
+ // Progress bar: contrasting text on colored bg
1558
+ rules[_sx(scope, '.bw_progress_bar.bw_' + k)] = {
1559
+ 'color': s.textOn
1560
+ };
1561
+
1562
+ // Background utility: .bw_bg_primary, .bw_bg_secondary, etc.
1563
+ rules[_sx(scope, '.bw_bg_' + k)] = {
1564
+ 'background-color': s.base,
1565
+ 'color': s.textOn
1566
+ };
1567
+
1568
+ // Text color utility: .bw_text_primary, .bw_text_secondary, etc.
1569
+ rules[_sx(scope, '.bw_text_' + k)] = {
1570
+ 'color': s.base
1436
1571
  };
1437
1572
  });
1438
1573
 
1439
- // Text muted
1440
- rules[scopeSelector(scope, '.bw_text_muted')] = { 'color': palette.secondary.base };
1574
+ // Text muted — always a neutral gray, never a brand color
1575
+ rules[_sx(scope, '.bw_text_muted')] = { 'color': '#6c757d' };
1576
+
1577
+ // Common bg/text utilities that aren't per-variant
1578
+ rules[_sx(scope, '.bw_bg_dark')] = { 'background-color': '#212529', 'color': '#f8f9fa' };
1579
+ rules[_sx(scope, '.bw_bg_light')] = { 'background-color': '#f8f9fa', 'color': '#212529' };
1580
+ rules[_sx(scope, '.bw_text_light')] = { 'color': '#f8f9fa' };
1581
+ rules[_sx(scope, '.bw_text_dark')] = { 'color': '#212529' };
1441
1582
 
1442
1583
  return rules;
1443
1584
  }
@@ -1459,30 +1600,32 @@ function generateThemedCSS(scopeName, palette, layout) {
1459
1600
  generateAlerts(scopeName, palette, layout),
1460
1601
  generateCards(scopeName, palette, layout),
1461
1602
  generateForms(scopeName, palette, layout),
1462
- generateNavigation(scopeName, palette),
1603
+ generateNavigation(scopeName, palette, layout),
1463
1604
  generateTables(scopeName, palette, layout),
1464
- generateTabs(scopeName, palette),
1605
+ generateTabs(scopeName, palette, layout),
1465
1606
  generateListGroups(scopeName, palette, layout),
1466
- generatePagination(scopeName, palette),
1607
+ generatePagination(scopeName, palette, layout),
1467
1608
  generateProgress(scopeName, palette),
1468
- generateBreadcrumbThemed(scopeName, palette),
1609
+ generateBreadcrumbThemed(scopeName, palette, layout),
1469
1610
  generateCloseButtonThemed(scopeName, palette),
1470
1611
  generateSectionsThemed(scopeName, palette),
1471
- generateAccordionThemed(scopeName, palette),
1612
+ generateAccordionThemed(scopeName, palette, layout),
1472
1613
  generateCarouselThemed(scopeName, palette),
1473
1614
  generateModalThemed(scopeName, palette, layout),
1474
1615
  generateToastThemed(scopeName, palette, layout),
1475
1616
  generateDropdownThemed(scopeName, palette, layout),
1476
1617
  generateSwitchThemed(scopeName, palette),
1477
1618
  generateSkeletonThemed(scopeName, palette),
1478
- generateStatCardThemed(scopeName, palette),
1619
+ generateStatCardThemed(scopeName, palette, layout),
1479
1620
  generateTimelineThemed(scopeName, palette),
1480
1621
  generateStepperThemed(scopeName, palette),
1481
1622
  generateChipInputThemed(scopeName, palette),
1482
- generateFileUploadThemed(scopeName, palette),
1623
+ generateFileUploadThemed(scopeName, palette, layout),
1483
1624
  generateRangeThemed(scopeName, palette),
1484
- generateSearchThemed(scopeName, palette),
1485
- generateCodeDemoThemed(scopeName, palette),
1625
+ generateSearchThemed(scopeName, palette, layout),
1626
+ generateTooltipThemed(scopeName, palette, layout),
1627
+ generatePopoverThemed(scopeName, palette, layout),
1628
+ generateCodeDemoThemed(scopeName, palette, layout),
1486
1629
  generateNavPillsThemed(scopeName, palette, layout),
1487
1630
  generatePaletteClasses(scopeName, palette)
1488
1631
  );
@@ -1707,6 +1850,8 @@ var structuralRules = {
1707
1850
  },
1708
1851
  '.bw_table caption': { 'font-size': '0.875rem', 'caption-side': 'bottom' },
1709
1852
  '.bw_table_bordered > :not(caption) > * > *': { 'border-width': '1px', 'border-style': 'solid' },
1853
+ '.bw_table_selectable > tbody > tr': { 'cursor': 'pointer' },
1854
+ '.bw_table > tbody > tr.bw_table_row_selected > *': { 'background-color': 'rgba(0, 102, 102, 0.1)' },
1710
1855
  '.bw_table_responsive': { 'overflow-x': 'auto', '-webkit-overflow-scrolling': 'touch' }
1711
1856
  },
1712
1857
 
@@ -1760,6 +1905,7 @@ var structuralRules = {
1760
1905
  '.bw_nav_tabs .bw_nav_item': { 'margin-bottom': '-2px' },
1761
1906
  '.bw_nav_link': {
1762
1907
  'display': 'block', 'font-size': '0.875rem', 'font-weight': '500',
1908
+ 'padding': '0.625rem 1rem',
1763
1909
  'text-decoration': 'none', 'cursor': 'pointer',
1764
1910
  'border': 'none', 'background': 'transparent', 'font-family': 'inherit'
1765
1911
  },
@@ -1794,10 +1940,11 @@ var structuralRules = {
1794
1940
  '.bw_page_item': { 'display': 'list-item', 'list-style': 'none' },
1795
1941
  '.bw_page_link': {
1796
1942
  'position': 'relative', 'display': 'block', 'padding': '0.375rem 0.75rem',
1797
- 'margin-left': '-1px', 'line-height': '1.25', 'text-decoration': 'none'
1943
+ 'margin-left': '-1px', 'line-height': '1.25', 'text-decoration': 'none',
1944
+ 'border': '1px solid transparent', 'cursor': 'pointer',
1945
+ 'font-family': 'inherit', 'font-size': 'inherit', 'background': 'none'
1798
1946
  },
1799
- '.bw_page_item:first-child .bw_page_link': { 'margin-left': '0', 'border-top-left-radius': '0.375rem', 'border-bottom-left-radius': '0.375rem' },
1800
- '.bw_page_item:last-child .bw_page_link': { 'border-top-right-radius': '0.375rem', 'border-bottom-right-radius': '0.375rem' },
1947
+ '.bw_page_item:first-child .bw_page_link': { 'margin-left': '0' },
1801
1948
  '.bw_page_link:focus-visible': { 'z-index': '3', 'outline': '2px solid currentColor', 'outline-offset': '-2px' }
1802
1949
  },
1803
1950
 
@@ -1954,6 +2101,7 @@ var structuralRules = {
1954
2101
  '.bw_accordion_header': { 'margin': '0' },
1955
2102
  '.bw_accordion_button': {
1956
2103
  'position': 'relative', 'display': 'flex', 'align-items': 'center', 'width': '100%',
2104
+ 'padding': '0.875rem 1.25rem',
1957
2105
  'font-size': '1rem', 'font-weight': '500', 'text-align': 'left',
1958
2106
  'background-color': 'transparent', 'border': '0', 'overflow-anchor': 'none', 'cursor': 'pointer',
1959
2107
  'font-family': 'inherit'
@@ -1965,10 +2113,9 @@ var structuralRules = {
1965
2113
  'background-repeat': 'no-repeat', 'background-size': '1.25rem'
1966
2114
  },
1967
2115
  '.bw_accordion_button:not(.bw_collapsed)::after': { 'transform': 'rotate(-180deg)' },
1968
- '.bw_accordion_collapse': { 'max-height': '0', 'overflow': 'hidden' },
1969
- '.bw_accordion_collapse.bw_collapse_show': { 'max-height': 'none' },
1970
- '.bw_accordion_item:first-child': { 'border-top-left-radius': '8px', 'border-top-right-radius': '8px' },
1971
- '.bw_accordion_item:last-child': { 'border-bottom-left-radius': '8px', 'border-bottom-right-radius': '8px' }
2116
+ '.bw_accordion_body': { 'padding': '1rem 1.25rem' },
2117
+ '.bw_accordion_collapse': { 'max-height': '0', 'overflow': 'hidden', 'transition': 'max-height 0.3s ease' },
2118
+ '.bw_accordion_collapse.bw_collapse_show': { 'max-height': 'none' }
1972
2119
  },
1973
2120
 
1974
2121
  // ---- Carousel ----
@@ -2114,7 +2261,13 @@ var structuralRules = {
2114
2261
 
2115
2262
  // ---- Stat card ----
2116
2263
  statCard: {
2117
- '.bw_stat_card': { 'border-left': '4px solid transparent' },
2264
+ '.bw_stat_card': {
2265
+ 'padding': '1.25rem',
2266
+ 'border-left': '4px solid transparent',
2267
+ 'border-radius': '0.375rem',
2268
+ 'background-color': 'inherit',
2269
+ 'transition': 'transform 0.15s ease'
2270
+ },
2118
2271
  '.bw_stat_card:hover': { 'transform': 'translateY(-1px)' },
2119
2272
  '.bw_stat_icon': { 'font-size': '1.5rem', 'margin-bottom': '0.5rem' },
2120
2273
  '.bw_stat_value': { 'font-size': '2rem', 'font-weight': '700', 'line-height': '1.2' },
@@ -2477,6 +2630,20 @@ function generateUtilityRules() {
2477
2630
  rules['.list-inline-item'] = { 'display': 'inline-block' };
2478
2631
  rules['.list-inline-item:not(:last-child)'] = { 'margin-right': '.5rem' };
2479
2632
 
2633
+ // Typography — bw_ prefixed utilities via loops
2634
+ var _imp = function(p, v) { var o = {}; o[p] = v + ' !important'; return o; };
2635
+ [['fs',{'xs':'0.75rem','sm':'0.875rem','base':'1rem','lg':'1.125rem','xl':'1.25rem','2xl':'1.5rem'},'font-size'],
2636
+ ['fw',{light:'300',normal:'400',medium:'500',semibold:'600',bold:'700'},'font-weight'],
2637
+ ['lh',{tight:'1.25',normal:'1.5',relaxed:'1.75'},'line-height']
2638
+ ].forEach(function(d) { for (var dk in d[1]) rules['.bw_'+d[0]+'_'+dk] = _imp(d[2], d[1][dk]); });
2639
+
2640
+ // Flex utilities
2641
+ rules['.bw_flex'] = { 'display': 'flex' };
2642
+ rules['.bw_flex_column'] = { 'flex-direction': 'column' };
2643
+ rules['.bw_flex_wrap'] = { 'flex-wrap': 'wrap' };
2644
+ rules['.bw_flex_center'] = { 'display': 'flex', 'align-items': 'center', 'justify-content': 'center' };
2645
+ for (var gk in spacingValues) rules['.bw_gap_' + gk] = { 'gap': spacingValues[gk] + ' !important' };
2646
+
2480
2647
  // Visibility
2481
2648
  rules['.bw_visible, .visible'] = { 'visibility': 'visible !important' };
2482
2649
  rules['.bw_invisible, .invisible'] = { 'visibility': 'hidden !important' };
@@ -2537,6 +2704,26 @@ function getStructuralStyles() {
2537
2704
  return getStructuralCSS();
2538
2705
  }
2539
2706
 
2707
+ /**
2708
+ * Get CSS reset rules only (box-sizing, html/body font, reduced-motion).
2709
+ * Separate from themed/structural rules for independent injection.
2710
+ * @returns {Object} CSS rules object for the reset layer
2711
+ */
2712
+ function getResetStyles() {
2713
+ var rules = {};
2714
+ Object.assign(rules, structuralRules.base);
2715
+ // Include reduced-motion preference
2716
+ rules['@media (prefers-reduced-motion: reduce)'] = {
2717
+ '*, *::before, *::after': {
2718
+ 'animation-duration': '0.01ms !important',
2719
+ 'animation-iteration-count': '1 !important',
2720
+ 'transition-duration': '0.01ms !important',
2721
+ 'scroll-behavior': 'auto !important'
2722
+ }
2723
+ };
2724
+ return rules;
2725
+ }
2726
+
2540
2727
  // =========================================================================
2541
2728
  // defaultStyles — backward-compatible categorized view
2542
2729
  // =========================================================================
@@ -2566,60 +2753,41 @@ Object.assign({}, structuralRules, {
2566
2753
  });
2567
2754
 
2568
2755
  /**
2569
- * Generate alternate-palette CSS scoped under `.bw_theme_alt`.
2570
- * Uses the same `generateThemedCSS()` pipeline as the primary palette —
2571
- * both sides go through identical code paths.
2572
- *
2573
- * @param {string} name - Theme scope name (e.g. 'ocean'). '' for global.
2574
- * @param {Object} altPalette - From derivePalette(deriveAlternateConfig(...))
2575
- * @param {Object} layout - From resolveLayout()
2576
- * @returns {Object} CSS rules object scoped under .bw_theme_alt (+ optional .name)
2756
+ * Prefix every selector in a rules object with a scope selector.
2757
+ * Handles @media/@keyframes blocks and comma-separated selectors.
2758
+ * @param {Object} rules - CSS rules object
2759
+ * @param {string} prefix - Scope prefix (e.g. '#my-dashboard', '.bw_theme_alt')
2760
+ * @param {boolean} [compound=false] - If true, use compound selector (no space)
2761
+ * for the first segment: `#scope.bw_theme_alt .sel` vs `#scope .sel`
2762
+ * @returns {Object} New rules object with scoped selectors
2577
2763
  */
2578
- function generateAlternateCSS(name, altPalette, layout) {
2579
- // Generate themed CSS using the same pipeline as primary
2580
- var rawRules = generateThemedCSS('', altPalette, layout);
2581
-
2582
- // Re-scope every selector under .bw_theme_alt (+ optional theme name)
2583
- var altPrefix = name ? '.' + name + '.bw_theme_alt' : '.bw_theme_alt';
2584
- var altRules = {};
2585
-
2586
- for (var sel in rawRules) {
2587
- if (!rawRules.hasOwnProperty(sel)) continue;
2588
-
2764
+ function scopeRulesUnder(rules, prefix, compound) {
2765
+ var scoped = {};
2766
+ for (var sel in rules) {
2767
+ if (!rules.hasOwnProperty(sel)) continue;
2589
2768
  if (sel.charAt(0) === '@') {
2590
2769
  // @media / @keyframes — recurse into the block
2591
- var innerBlock = rawRules[sel];
2592
- var altInner = {};
2770
+ var innerBlock = rules[sel];
2771
+ var scopedInner = {};
2593
2772
  for (var innerSel in innerBlock) {
2594
2773
  if (!innerBlock.hasOwnProperty(innerSel)) continue;
2595
- altInner[altPrefix + ' ' + innerSel] = innerBlock[innerSel];
2774
+ scopedInner[_prefixSelector(innerSel, prefix)] = innerBlock[innerSel];
2596
2775
  }
2597
- altRules[sel] = altInner;
2776
+ scoped[sel] = scopedInner;
2598
2777
  } else {
2599
- // Regular selector — prefix with alt scope
2600
- // Handle comma-separated selectors
2601
- var parts = sel.split(',');
2602
- var scopedParts = [];
2603
- for (var i = 0; i < parts.length; i++) {
2604
- var s = parts[i].trim();
2605
- // 'body' selector gets special treatment: .bw_theme_alt body
2606
- if (s === 'body' || s.indexOf('body') === 0) {
2607
- scopedParts.push(altPrefix + ' ' + s);
2608
- } else {
2609
- scopedParts.push(altPrefix + ' ' + s);
2610
- }
2611
- }
2612
- altRules[scopedParts.join(', ')] = rawRules[sel];
2778
+ scoped[_prefixSelector(sel, prefix)] = rules[sel];
2613
2779
  }
2614
2780
  }
2781
+ return scoped;
2782
+ }
2615
2783
 
2616
- // Add body-level overrides for the alternate surface
2617
- altRules[altPrefix + ' body, :root' + altPrefix + ' body'] = {
2618
- 'color': altPalette.dark.base,
2619
- 'background-color': altPalette.light.base
2620
- };
2621
-
2622
- return altRules;
2784
+ function _prefixSelector(sel, prefix) {
2785
+ var parts = sel.split(',');
2786
+ var result = [];
2787
+ for (var i = 0; i < parts.length; i++) {
2788
+ result.push(prefix + ' ' + parts[i].trim());
2789
+ }
2790
+ return result.join(', ');
2623
2791
  }
2624
2792
 
2625
2793
  /**
@@ -3627,7 +3795,12 @@ bw._el = function(id) {
3627
3795
  el = document.querySelector('[data-bw_id="' + id + '"]');
3628
3796
  }
3629
3797
 
3630
- // 5. Cache the result for next time
3798
+ // 5. Try class-based lookup for bw_uuid_* tokens (UUID addressing)
3799
+ if (!el && id.indexOf('bw_uuid_') === 0) {
3800
+ el = document.querySelector('.' + id);
3801
+ }
3802
+
3803
+ // 6. Cache the result for next time
3631
3804
  if (el) {
3632
3805
  bw._nodeMap[id] = el;
3633
3806
  }
@@ -3680,6 +3853,84 @@ bw._deregisterNode = function(el, bwId) {
3680
3853
  }
3681
3854
  };
3682
3855
 
3856
+ // ===================================================================================
3857
+ // bw.assignUUID() / bw.getUUID() — Explicit UUID addressing for TACO objects
3858
+ // ===================================================================================
3859
+
3860
+ /**
3861
+ * Regex to match a bw_uuid_* token in a class string.
3862
+ * @private
3863
+ */
3864
+ var _UUID_RE = /\bbw_uuid_[a-z0-9_]+\b/;
3865
+
3866
+ /**
3867
+ * Assign a UUID to a TACO object by appending a `bw_uuid_*` token to `taco.a.class`.
3868
+ *
3869
+ * Idempotent by default — calling twice returns the same UUID. Pass `forceNew=true`
3870
+ * to replace an existing UUID (useful in loops where each TACO needs a unique ID).
3871
+ *
3872
+ * @param {Object} taco - A TACO object `{t, a, c, o}`
3873
+ * @param {boolean} [forceNew=false] - If true, replaces any existing UUID with a new one
3874
+ * @returns {string} The UUID string (e.g. 'bw_uuid_a1b2c3d4e5')
3875
+ * @category Identifiers
3876
+ * @example
3877
+ * var card = bw.makeStatCard({ value: '0', label: 'Scans' });
3878
+ * var uuid = bw.assignUUID(card); // 'bw_uuid_a1b2c3d4e5'
3879
+ * var same = bw.assignUUID(card); // same UUID (idempotent)
3880
+ * var diff = bw.assignUUID(card, true); // new UUID (forced)
3881
+ */
3882
+ bw.assignUUID = function(taco, forceNew) {
3883
+ if (!taco || !_is(taco, 'object')) return null;
3884
+
3885
+ // Ensure taco.a exists
3886
+ if (!taco.a) taco.a = {};
3887
+ if (!_is(taco.a.class, 'string')) taco.a.class = taco.a.class ? String(taco.a.class) : '';
3888
+
3889
+ var existing = taco.a.class.match(_UUID_RE);
3890
+
3891
+ if (existing && !forceNew) {
3892
+ return existing[0];
3893
+ }
3894
+
3895
+ // Remove old UUID if forceNew
3896
+ if (existing) {
3897
+ taco.a.class = taco.a.class.replace(_UUID_RE, '').replace(/\s+/g, ' ').trim();
3898
+ }
3899
+
3900
+ var uuid = bw.uuid('uuid');
3901
+ taco.a.class = (taco.a.class ? taco.a.class + ' ' : '') + uuid;
3902
+ return uuid;
3903
+ };
3904
+
3905
+ /**
3906
+ * Read the UUID from a TACO object or DOM element. Pure getter, no side effects.
3907
+ *
3908
+ * @param {Object|Element} tacoOrElement - A TACO object or DOM element
3909
+ * @returns {string|null} The UUID string, or null if none assigned
3910
+ * @category Identifiers
3911
+ * @example
3912
+ * bw.getUUID(card) // 'bw_uuid_a1b2c3d4e5' (from TACO)
3913
+ * bw.getUUID(domEl) // 'bw_uuid_a1b2c3d4e5' (from DOM element)
3914
+ * bw.getUUID({t:'div'}) // null (no UUID)
3915
+ */
3916
+ bw.getUUID = function(tacoOrElement) {
3917
+ if (!tacoOrElement) return null;
3918
+
3919
+ var classStr;
3920
+ // DOM element: check className
3921
+ if (tacoOrElement.className !== undefined && tacoOrElement.tagName) {
3922
+ classStr = tacoOrElement.className;
3923
+ }
3924
+ // TACO object: check a.class
3925
+ else if (tacoOrElement.a && _is(tacoOrElement.a.class, 'string')) {
3926
+ classStr = tacoOrElement.a.class;
3927
+ }
3928
+
3929
+ if (!classStr) return null;
3930
+ var match = classStr.match(_UUID_RE);
3931
+ return match ? match[0] : null;
3932
+ };
3933
+
3683
3934
  /**
3684
3935
  * Escape HTML special characters to prevent XSS.
3685
3936
  *
@@ -3729,6 +3980,42 @@ bw.raw = function(str) {
3729
3980
  return { __bw_raw: true, v: String(str) };
3730
3981
  };
3731
3982
 
3983
+ /**
3984
+ * Hyperscript-style TACO constructor.
3985
+ *
3986
+ * A convenience helper that returns a canonical TACO object from positional
3987
+ * arguments. The return value is a plain object — serializable, works with
3988
+ * bwserve, and accepted everywhere TACO is accepted.
3989
+ *
3990
+ * @param {string} tag - HTML tag name (e.g. 'div', 'p', 'section')
3991
+ * @param {Object|null} [attrs] - HTML attributes object. Pass null or omit to skip.
3992
+ * @param {*} [content] - Content: string, number, TACO object, or array of children.
3993
+ * @param {Object} [options] - TACO options (state, lifecycle hooks, render fn).
3994
+ * @returns {Object} Plain TACO object {t, a?, c?, o?}
3995
+ * @category Utilities
3996
+ * @see bw.html
3997
+ * @see bw.createDOM
3998
+ * @see bw.DOM
3999
+ * @example
4000
+ * bw.h('div')
4001
+ * // => { t: 'div' }
4002
+ *
4003
+ * bw.h('p', { class: 'bw_text_muted' }, 'Hello')
4004
+ * // => { t: 'p', a: { class: 'bw_text_muted' }, c: 'Hello' }
4005
+ *
4006
+ * bw.h('ul', null, [
4007
+ * bw.h('li', null, 'one'),
4008
+ * bw.h('li', null, 'two')
4009
+ * ])
4010
+ * // => { t: 'ul', c: [{ t: 'li', c: 'one' }, { t: 'li', c: 'two' }] }
4011
+ */
4012
+ bw.h = function(tag, attrs, content, options) {
4013
+ var taco = { t: String(tag) };
4014
+ if (attrs !== null && attrs !== undefined) taco.a = attrs;
4015
+ if (content !== undefined) taco.c = content;
4016
+ if (options !== undefined) taco.o = options;
4017
+ return taco;
4018
+ };
3732
4019
 
3733
4020
  /**
3734
4021
  * Convert a TACO object (or array of TACOs) to an HTML string.
@@ -3993,7 +4280,7 @@ bw.htmlPage = function(opts) {
3993
4280
  ? (THEME_PRESETS[theme.toLowerCase()] || null)
3994
4281
  : theme;
3995
4282
  if (themeConfig) {
3996
- var themeResult = bw.generateTheme('', Object.assign({}, themeConfig, { inject: false }));
4283
+ var themeResult = bw.makeStyles(themeConfig);
3997
4284
  themeCSS = themeResult.css;
3998
4285
  }
3999
4286
  }
@@ -4019,14 +4306,14 @@ bw.htmlPage = function(opts) {
4019
4306
  // Combine all CSS
4020
4307
  var allCSS = (themeCSS ? themeCSS + '\n' : '') + css;
4021
4308
 
4022
- // Body-end script: registry entries + optional loadDefaultStyles
4309
+ // Body-end script: registry entries + optional loadStyles
4023
4310
  var bodyEndScript = '';
4024
4311
  var bodyEndParts = [];
4025
4312
  if (registryEntries) {
4026
4313
  bodyEndParts.push(registryEntries);
4027
4314
  }
4028
4315
  if (runtime === 'inline' || runtime === 'cdn') {
4029
- bodyEndParts.push('if(typeof bw!=="undefined"){bw.loadDefaultStyles();}');
4316
+ bodyEndParts.push('if(typeof bw!=="undefined"){bw.loadStyles();}');
4030
4317
  }
4031
4318
  if (bodyEndParts.length > 0) {
4032
4319
  bodyEndScript = '<script>\n' + bodyEndParts.join('\n') + '\n</script>';
@@ -4200,6 +4487,14 @@ bw.createDOM = function(taco, options = {}) {
4200
4487
  bw._registerNode(el, null);
4201
4488
  }
4202
4489
 
4490
+ // Register UUID class in node cache (bw_uuid_* tokens in class string)
4491
+ if (el.className) {
4492
+ var uuidMatch = el.className.match(_UUID_RE);
4493
+ if (uuidMatch) {
4494
+ bw._nodeMap[uuidMatch[0]] = el;
4495
+ }
4496
+ }
4497
+
4203
4498
  // Handle lifecycle hooks and state
4204
4499
  if (opts.mounted || opts.unmount || opts.render || opts.state) {
4205
4500
  const id = attrs['data-bw_id'] || bw.uuid();
@@ -4572,6 +4867,16 @@ bw.renderComponent = function(taco, options = {}) {
4572
4867
  bw.cleanup = function(element) {
4573
4868
  if (!bw._isBrowser || !element) return;
4574
4869
 
4870
+ // Deregister UUID classes from node cache (element + descendants)
4871
+ // Covers elements that have UUID but no data-bw_id
4872
+ var selfUuidMatch = element.className && element.className.match(_UUID_RE);
4873
+ if (selfUuidMatch) delete bw._nodeMap[selfUuidMatch[0]];
4874
+ var uuidEls = element.querySelectorAll('[class*="bw_uuid_"]');
4875
+ uuidEls.forEach(function(uel) {
4876
+ var m = uel.className && uel.className.match(_UUID_RE);
4877
+ if (m) delete bw._nodeMap[m[0]];
4878
+ });
4879
+
4575
4880
  // Find all elements with data-bw_id
4576
4881
  const elements = element.querySelectorAll('[data-bw_id]');
4577
4882
 
@@ -4587,6 +4892,10 @@ bw.cleanup = function(element) {
4587
4892
  // Deregister from node cache
4588
4893
  bw._deregisterNode(el, id);
4589
4894
 
4895
+ // Deregister UUID class from node cache
4896
+ var uuidMatch = el.className && el.className.match(_UUID_RE);
4897
+ if (uuidMatch) delete bw._nodeMap[uuidMatch[0]];
4898
+
4590
4899
  // Clean up pub/sub subscriptions tied to this element
4591
4900
  if (el._bw_subs) {
4592
4901
  el._bw_subs.forEach(function(unsub) { unsub(); });
@@ -4611,6 +4920,10 @@ bw.cleanup = function(element) {
4611
4920
  // Deregister from node cache
4612
4921
  bw._deregisterNode(element, id);
4613
4922
 
4923
+ // Deregister UUID class from node cache
4924
+ var elemUuidMatch = element.className && element.className.match(_UUID_RE);
4925
+ if (elemUuidMatch) delete bw._nodeMap[elemUuidMatch[0]];
4926
+
4614
4927
  // Clean up pub/sub subscriptions tied to element itself
4615
4928
  if (element._bw_subs) {
4616
4929
  element._bw_subs.forEach(function(unsub) { unsub(); });
@@ -5222,7 +5535,7 @@ function ComponentHandle(taco) {
5222
5535
  willMount: o.willMount || null,
5223
5536
  mounted: o.mounted || null,
5224
5537
  willUpdate: o.willUpdate || null,
5225
- onUpdate: o.onUpdate || null,
5538
+ onUpdate: o.onUpdate || o.updated || null,
5226
5539
  unmount: o.unmount || null,
5227
5540
  willDestroy: o.willDestroy || null
5228
5541
  };
@@ -6161,7 +6474,7 @@ bw.component = function(taco) {
6161
6474
  * and calls the named method. This is the bitwrench equivalent of
6162
6475
  * Win32 SendMessage(hwnd, msg, wParam, lParam).
6163
6476
  *
6164
- * @param {string} target - Component UUID (data-bw_comp_id) or user tag (CSS class)
6477
+ * @param {string} target - Component UUID (bw_uuid_*), comp ID (data-bw_comp_id), or user tag (CSS class)
6165
6478
  * @param {string} action - Method name to call on the component
6166
6479
  * @param {*} data - Data to pass to the method
6167
6480
  * @returns {boolean} True if message was dispatched successfully
@@ -6178,9 +6491,14 @@ bw.component = function(taco) {
6178
6491
  * };
6179
6492
  */
6180
6493
  bw.message = function(target, action, data) {
6181
- // Try data-bw_comp_id attribute first, then CSS class (user tag)
6182
- var el = bw.$('[data-bw_comp_id="' + target + '"]')[0];
6183
- if (!el) {
6494
+ // Try bw._el() first (handles UUID class, nodeMap cache, getElementById)
6495
+ var el = bw._el(target);
6496
+ // Then try data-bw_comp_id attribute
6497
+ if (!el || !el._bwComponentHandle) {
6498
+ el = bw.$('[data-bw_comp_id="' + target + '"]')[0];
6499
+ }
6500
+ // Then try CSS class (user tag)
6501
+ if (!el || !el._bwComponentHandle) {
6184
6502
  el = bw.$('.' + target)[0];
6185
6503
  }
6186
6504
  if (!el || !el._bwComponentHandle) return false;
@@ -6194,59 +6512,24 @@ bw.message = function(target, action, data) {
6194
6512
  };
6195
6513
 
6196
6514
  // ===================================================================================
6197
- // bw.clientApply() / bw.clientConnect() — Server-driven UI protocol
6515
+ // bw.apply() / bw.parseJSONFlex() — Server-driven UI protocol
6198
6516
  // ===================================================================================
6199
6517
 
6200
6518
  /**
6201
6519
  * Registry of named functions sent via register messages.
6202
- * Populated by clientApply({ type: 'register', name, body }).
6203
- * Invoked by clientApply({ type: 'call', name, args }).
6520
+ * Populated by bw.apply({ type: 'register', name, body }).
6521
+ * Invoked by bw.apply({ type: 'call', name, args }).
6204
6522
  * @private
6205
6523
  */
6206
6524
  bw._clientFunctions = {};
6207
6525
 
6208
6526
  /**
6209
- * Whether exec messages are allowed. Set by clientConnect opts.allowExec.
6527
+ * Whether exec messages are allowed. Set by bwclient connect opts.allowExec.
6210
6528
  * Default false — exec messages are rejected unless explicitly opted in.
6211
6529
  * @private
6212
6530
  */
6213
6531
  bw._allowExec = false;
6214
6532
 
6215
- /**
6216
- * Built-in client functions available via call() without registration.
6217
- * @private
6218
- */
6219
- bw._builtinClientFunctions = {
6220
- scrollTo: function(selector) {
6221
- var el = bw._el(selector);
6222
- if (el) el.scrollTop = el.scrollHeight;
6223
- },
6224
- focus: function(selector) {
6225
- var el = bw._el(selector);
6226
- if (el && _is(el.focus, 'function')) el.focus();
6227
- },
6228
- download: function(filename, content, mimeType) {
6229
- if (typeof document === 'undefined') return;
6230
- var blob = new Blob([content], { type: mimeType || 'text/plain' });
6231
- var a = document.createElement('a');
6232
- a.href = URL.createObjectURL(blob);
6233
- a.download = filename;
6234
- a.click();
6235
- URL.revokeObjectURL(a.href);
6236
- },
6237
- clipboard: function(text) {
6238
- if (typeof navigator !== 'undefined' && navigator.clipboard) {
6239
- navigator.clipboard.writeText(text);
6240
- }
6241
- },
6242
- redirect: function(url) {
6243
- if (typeof window !== 'undefined') window.location.href = url;
6244
- },
6245
- log: function() {
6246
- console.log.apply(console, arguments);
6247
- }
6248
- };
6249
-
6250
6533
  /**
6251
6534
  * Parse a bwserve protocol message string, supporting both strict JSON
6252
6535
  * and r-prefixed relaxed JSON (single-quoted strings, trailing commas).
@@ -6261,9 +6544,9 @@ bw._builtinClientFunctions = {
6261
6544
  * @param {string} str - JSON or r-prefixed relaxed JSON string
6262
6545
  * @returns {Object} Parsed message object
6263
6546
  * @throws {SyntaxError} If the string is not valid JSON or relaxed JSON
6264
- * @category Server
6547
+ * @category Core
6265
6548
  */
6266
- bw.clientParse = function(str) {
6549
+ bw.parseJSONFlex = function(str) {
6267
6550
  str = (str || '').trim();
6268
6551
  if (str.charAt(0) !== 'r') return JSON.parse(str);
6269
6552
  str = str.slice(1);
@@ -6348,10 +6631,10 @@ bw.clientParse = function(str) {
6348
6631
  * append — target.appendChild(bw.createDOM(node))
6349
6632
  * remove — bw.cleanup(target); target.remove()
6350
6633
  * patch — bw.patch(target, content, attr)
6351
- * batch — iterate ops, call clientApply for each
6634
+ * batch — iterate ops, call bw.apply for each
6352
6635
  * message — bw.message(target, action, data)
6353
6636
  * register — store a named function for later call()
6354
- * call — invoke a registered or built-in function
6637
+ * call — invoke a registered function
6355
6638
  * exec — execute arbitrary JS (requires allowExec)
6356
6639
  *
6357
6640
  * Target resolution:
@@ -6360,9 +6643,9 @@ bw.clientParse = function(str) {
6360
6643
  *
6361
6644
  * @param {Object} msg - Protocol message
6362
6645
  * @returns {boolean} true if the message was applied successfully
6363
- * @category Server
6646
+ * @category Core
6364
6647
  */
6365
- bw.clientApply = function(msg) {
6648
+ bw.apply = function(msg) {
6366
6649
  if (!msg || !msg.type) return false;
6367
6650
 
6368
6651
  var type = msg.type;
@@ -6396,7 +6679,7 @@ bw.clientApply = function(msg) {
6396
6679
  if (!_isA(msg.ops)) return false;
6397
6680
  var allOk = true;
6398
6681
  msg.ops.forEach(function(op) {
6399
- if (!bw.clientApply(op)) allOk = false;
6682
+ if (!bw.apply(op)) allOk = false;
6400
6683
  });
6401
6684
  return allOk;
6402
6685
 
@@ -6415,7 +6698,7 @@ bw.clientApply = function(msg) {
6415
6698
 
6416
6699
  } else if (type === 'call') {
6417
6700
  if (!msg.name) return false;
6418
- var fn = bw._clientFunctions[msg.name] || bw._builtinClientFunctions[msg.name];
6701
+ var fn = bw._clientFunctions[msg.name];
6419
6702
  if (!_is(fn, 'function')) return false;
6420
6703
  try {
6421
6704
  var args = _isA(msg.args) ? msg.args : [];
@@ -6444,139 +6727,6 @@ bw.clientApply = function(msg) {
6444
6727
  return false;
6445
6728
  };
6446
6729
 
6447
- /**
6448
- * Connect to a bwserve SSE endpoint and apply protocol messages automatically.
6449
- *
6450
- * Returns a connection object with sendAction(), on(), and close() methods.
6451
- *
6452
- * @param {string} url - SSE endpoint URL (e.g., '/__bw/events/client-1')
6453
- * @param {Object} [opts] - Connection options
6454
- * @param {string} [opts.transport='sse'] - Transport type: 'sse' (default) or 'poll'
6455
- * @param {number} [opts.interval=2000] - Poll interval in ms (only for 'poll' transport)
6456
- * @param {string} [opts.actionUrl] - POST endpoint for actions (default: derived from url)
6457
- * @param {boolean} [opts.reconnect=true] - Auto-reconnect on disconnect
6458
- * @param {boolean} [opts.allowExec=false] - Enable exec message type (arbitrary JS execution)
6459
- * @param {Function} [opts.onStatus] - Status callback: 'connecting'|'connected'|'disconnected'
6460
- * @param {Function} [opts.onMessage] - Raw message callback (before clientApply)
6461
- * @returns {Object} Connection object { sendAction, on, close, status }
6462
- * @category Server
6463
- */
6464
- bw.clientConnect = function(url, opts) {
6465
- opts = opts || {};
6466
- var transport = opts.transport || 'sse';
6467
- var actionUrl = opts.actionUrl || url.replace(/\/events\//, '/action/');
6468
- var reconnect = opts.reconnect !== false;
6469
- var onStatus = opts.onStatus || function() {};
6470
- var onMessage = opts.onMessage || null;
6471
- var handlers = {};
6472
- // Set the global allowExec flag from connection options
6473
- bw._allowExec = !!opts.allowExec;
6474
- var conn = {
6475
- status: 'connecting',
6476
- _es: null,
6477
- _pollTimer: null
6478
- };
6479
-
6480
- function setStatus(s) {
6481
- conn.status = s;
6482
- onStatus(s);
6483
- }
6484
-
6485
- function handleMessage(data) {
6486
- try {
6487
- var msg = _is(data, 'string') ? bw.clientParse(data) : data;
6488
- if (onMessage) onMessage(msg);
6489
- if (handlers.message) handlers.message(msg);
6490
- bw.clientApply(msg);
6491
- } catch (e) {
6492
- if (handlers.error) handlers.error(e);
6493
- }
6494
- }
6495
-
6496
- if (transport === 'sse' && typeof EventSource !== 'undefined') {
6497
- setStatus('connecting');
6498
- var es = new EventSource(url);
6499
- conn._es = es;
6500
-
6501
- es.onopen = function() {
6502
- setStatus('connected');
6503
- if (handlers.open) handlers.open();
6504
- };
6505
-
6506
- es.onmessage = function(e) {
6507
- handleMessage(e.data);
6508
- };
6509
-
6510
- es.onerror = function() {
6511
- if (conn.status === 'connected') {
6512
- setStatus('disconnected');
6513
- }
6514
- if (handlers.error) handlers.error(new Error('SSE connection error'));
6515
- if (!reconnect) {
6516
- es.close();
6517
- }
6518
- // EventSource auto-reconnects by default when reconnect=true
6519
- };
6520
- } else if (transport === 'poll') {
6521
- var interval = opts.interval || 2000;
6522
- setStatus('connected');
6523
- conn._pollTimer = setInterval(function() {
6524
- fetch(url).then(function(r) { return r.json(); }).then(function(msgs) {
6525
- if (_isA(msgs)) {
6526
- msgs.forEach(handleMessage);
6527
- } else if (msgs && msgs.type) {
6528
- handleMessage(msgs);
6529
- }
6530
- }).catch(function(e) {
6531
- if (handlers.error) handlers.error(e);
6532
- });
6533
- }, interval);
6534
- }
6535
-
6536
- /**
6537
- * Send an action to the server via POST.
6538
- * @param {string} action - Action name
6539
- * @param {Object} [data] - Action payload
6540
- */
6541
- conn.sendAction = function(action, data) {
6542
- var body = JSON.stringify({ type: 'action', action: action, data: data || {} });
6543
- fetch(actionUrl, {
6544
- method: 'POST',
6545
- headers: { 'Content-Type': 'application/json' },
6546
- body: body
6547
- }).catch(function(e) {
6548
- if (handlers.error) handlers.error(e);
6549
- });
6550
- };
6551
-
6552
- /**
6553
- * Register an event handler.
6554
- * @param {string} event - 'open'|'message'|'error'|'close'
6555
- * @param {Function} handler
6556
- */
6557
- conn.on = function(event, handler) {
6558
- handlers[event] = handler;
6559
- return conn;
6560
- };
6561
-
6562
- /**
6563
- * Close the connection.
6564
- */
6565
- conn.close = function() {
6566
- if (conn._es) {
6567
- conn._es.close();
6568
- conn._es = null;
6569
- }
6570
- if (conn._pollTimer) {
6571
- clearInterval(conn._pollTimer);
6572
- conn._pollTimer = null;
6573
- }
6574
- setStatus('disconnected');
6575
- if (handlers.close) handlers.close();
6576
- };
6577
-
6578
- return conn;
6579
- };
6580
6730
 
6581
6731
  // ===================================================================================
6582
6732
  // bw.inspect() — Debug utility
@@ -6785,7 +6935,7 @@ bw.css = function(rules, options = {}) {
6785
6935
  * @returns {Element} The style element
6786
6936
  * @category CSS & Styling
6787
6937
  * @see bw.css
6788
- * @see bw.loadDefaultStyles
6938
+ * @see bw.loadStyles
6789
6939
  * @example
6790
6940
  * bw.injectCSS('.my-class { color: red; }');
6791
6941
  * bw.injectCSS({ '.card': { padding: '1rem' } }, { id: 'card-styles' });
@@ -6830,9 +6980,8 @@ bw.injectCSS = function(css, options = {}) {
6830
6980
  * @param {...Object} styles - Style objects to merge (left-to-right)
6831
6981
  * @returns {Object} Merged style object
6832
6982
  * @category CSS & Styling
6833
- * @see bw.u
6834
6983
  * @example
6835
- * var style = bw.s(bw.u.flex, bw.u.gap4, { color: 'red' });
6984
+ * var style = bw.s({ display: 'flex' }, { gap: '1rem' }, { color: 'red' });
6836
6985
  * // => { display: 'flex', gap: '1rem', color: 'red' }
6837
6986
  */
6838
6987
  bw.s = function() {
@@ -6844,99 +6993,6 @@ bw.s = function() {
6844
6993
  return result;
6845
6994
  };
6846
6995
 
6847
- /**
6848
- * Pre-built CSS utility objects (like Tailwind utilities, but in JS).
6849
- *
6850
- * Compose with `bw.s()` to build inline styles without writing raw CSS strings.
6851
- * Includes flex, padding, margin, typography, color, border, and transition utilities.
6852
- *
6853
- * @category CSS & Styling
6854
- * @see bw.s
6855
- * @example
6856
- * { t: 'div', a: { style: bw.s(bw.u.flex, bw.u.gap4, bw.u.p4) },
6857
- * c: 'Flexbox with 1rem gap and padding' }
6858
- */
6859
- bw.u = {
6860
- // Display
6861
- flex: { display: 'flex' },
6862
- flexCol: { display: 'flex', flexDirection: 'column' },
6863
- flexRow: { display: 'flex', flexDirection: 'row' },
6864
- flexWrap: { display: 'flex', flexWrap: 'wrap' },
6865
- block: { display: 'block' },
6866
- inline: { display: 'inline' },
6867
- hidden: { display: 'none' },
6868
-
6869
- // Flex alignment
6870
- justifyCenter: { justifyContent: 'center' },
6871
- justifyBetween: { justifyContent: 'space-between' },
6872
- justifyEnd: { justifyContent: 'flex-end' },
6873
- alignCenter: { alignItems: 'center' },
6874
- alignStart: { alignItems: 'flex-start' },
6875
- alignEnd: { alignItems: 'flex-end' },
6876
-
6877
- // Gap (0.25rem increments)
6878
- gap1: { gap: '0.25rem' },
6879
- gap2: { gap: '0.5rem' },
6880
- gap3: { gap: '0.75rem' },
6881
- gap4: { gap: '1rem' },
6882
- gap6: { gap: '1.5rem' },
6883
- gap8: { gap: '2rem' },
6884
-
6885
- // Padding
6886
- p0: { padding: '0' },
6887
- p1: { padding: '0.25rem' },
6888
- p2: { padding: '0.5rem' },
6889
- p3: { padding: '0.75rem' },
6890
- p4: { padding: '1rem' },
6891
- p6: { padding: '1.5rem' },
6892
- p8: { padding: '2rem' },
6893
- px4: { paddingLeft: '1rem', paddingRight: '1rem' },
6894
- py2: { paddingTop: '0.5rem', paddingBottom: '0.5rem' },
6895
- py4: { paddingTop: '1rem', paddingBottom: '1rem' },
6896
-
6897
- // Margin (same scale)
6898
- m0: { margin: '0' },
6899
- m4: { margin: '1rem' },
6900
- mt2: { marginTop: '0.5rem' },
6901
- mt4: { marginTop: '1rem' },
6902
- mb2: { marginBottom: '0.5rem' },
6903
- mb4: { marginBottom: '1rem' },
6904
- mx_auto: { marginLeft: 'auto', marginRight: 'auto' },
6905
-
6906
- // Typography
6907
- textSm: { fontSize: '0.875rem' },
6908
- textBase: { fontSize: '1rem' },
6909
- textLg: { fontSize: '1.125rem' },
6910
- textXl: { fontSize: '1.25rem' },
6911
- text2xl: { fontSize: '1.5rem' },
6912
- text3xl: { fontSize: '1.875rem' },
6913
- bold: { fontWeight: '700' },
6914
- semibold: { fontWeight: '600' },
6915
- italic: { fontStyle: 'italic' },
6916
- textCenter: { textAlign: 'center' },
6917
- textRight: { textAlign: 'right' },
6918
-
6919
- // Colors (from design tokens)
6920
- bgWhite: { background: '#ffffff' },
6921
- bgTeal: { background: '#006666', color: '#ffffff' },
6922
- textWhite: { color: '#ffffff' },
6923
- textTeal: { color: '#006666' },
6924
- textMuted: { color: '#888' },
6925
-
6926
- // Borders
6927
- rounded: { borderRadius: '0.375rem' },
6928
- roundedLg: { borderRadius: '0.5rem' },
6929
- roundedFull: { borderRadius: '9999px' },
6930
- border: { border: '1px solid #d8d8d8' },
6931
-
6932
- // Sizing
6933
- wFull: { width: '100%' },
6934
- hFull: { height: '100%' },
6935
-
6936
- // Transitions
6937
- transition: { transition: 'all 0.2s ease' }
6938
- };
6939
-
6940
6996
  /**
6941
6997
  * Generate responsive CSS with media query breakpoints.
6942
6998
  *
@@ -7058,103 +7114,49 @@ if (bw._isBrowser) {
7058
7114
  };
7059
7115
  }
7060
7116
 
7061
- /**
7062
- * Load the built-in Bootstrap-inspired default stylesheet.
7063
- *
7064
- * Injects bitwrench's batteries-included CSS (buttons, cards, grids, forms,
7065
- * alerts, badges, nav, tabs, etc.) into the document head. Call once at app startup.
7066
- * Returns null in Node.js (no DOM).
7067
- *
7068
- * @param {Object} [options] - Style loading options
7069
- * @param {boolean} [options.minify=true] - Minify the CSS output
7070
- * @returns {Element|null} Style element if in browser, null in Node.js
7071
- * @category CSS & Styling
7072
- * @see bw.setTheme
7073
- * @see bw.applyTheme
7074
- * @see bw.toggleTheme
7075
- * @example
7076
- * bw.loadDefaultStyles(); // inject all default CSS
7077
- */
7078
- bw.loadDefaultStyles = function(options = {}) {
7079
- const { minify = true, palette } = options;
7080
7117
 
7081
- // 1. Inject structural CSS (layout, sizing — never changes with theme)
7082
- if (bw._isBrowser) {
7083
- var structuralCSS = bw.css(getStructuralStyles());
7084
- bw.injectCSS(structuralCSS, { id: 'bw_structural', append: false, minify: minify });
7085
- }
7086
-
7087
- // 2. Inject cosmetic CSS via generateTheme (colors, shadows, radii)
7088
- var paletteConfig = Object.assign({}, DEFAULT_PALETTE_CONFIG, palette || {});
7089
- var result = bw.generateTheme('', Object.assign({}, paletteConfig, { inject: true }));
7090
- return result;
7091
- };
7118
+ // =========================================================================
7119
+ // v2.0.18 Clean Styles API — makeStyles / applyStyles / loadStyles / etc.
7120
+ // =========================================================================
7092
7121
 
7122
+ /**
7123
+ * Convert a scope selector to a <style> element id.
7124
+ * @private
7125
+ * @param {string} [scope] - Scope selector (e.g. '#my-dashboard', '.preview')
7126
+ * @returns {string} Style element id (e.g. 'bw_style_my_dashboard')
7127
+ */
7128
+ function _scopeToStyleId(scope) {
7129
+ if (!scope || scope === '' || scope === 'global') return 'bw_style_global';
7130
+ if (scope === 'reset') return 'bw_style_reset';
7131
+ // Strip leading # or . and convert - to _
7132
+ var clean = scope.replace(/^[#.]/, '').replace(/-/g, '_');
7133
+ return 'bw_style_' + clean;
7134
+ }
7093
7135
 
7094
7136
  /**
7095
- * Generate a complete, scoped theme from seed colors.
7137
+ * Generate a complete styles object from seed colors and layout config.
7138
+ * Pure function — no DOM, no state, no side effects.
7096
7139
  *
7097
- * Produces CSS for all themed components (buttons, alerts, badges, cards,
7098
- * forms, nav, tables, tabs, list groups, pagination, progress, hero, utilities)
7099
- * scoped under `.name` class. Multiple themes can coexist in the stylesheet.
7100
- * Swap themes by changing the class on a container element.
7140
+ * All parameters are optional. Defaults to the bitwrench default palette.
7101
7141
  *
7102
- * @param {string} name - CSS scope class (e.g. 'ocean'). Empty string = unscoped global.
7103
- * @param {Object} config - Theme configuration
7104
- * @param {string} config.primary - Primary brand color hex
7105
- * @param {string} config.secondary - Secondary color hex
7106
- * @param {string} [config.tertiary] - Tertiary/accent color hex (defaults to primary)
7107
- * @param {string} [config.success='#198754'] - Success color hex
7108
- * @param {string} [config.danger='#dc3545'] - Danger color hex
7109
- * @param {string} [config.warning='#ffc107'] - Warning color hex
7110
- * @param {string} [config.info='#0dcaf0'] - Info color hex
7111
- * @param {string} [config.light='#f8f9fa'] - Light color hex
7112
- * @param {string} [config.dark='#212529'] - Dark color hex
7113
- * @param {string} [config.background] - Page background hex (default: '#ffffff' light, derived dark)
7114
- * @param {string} [config.surface] - Surface/card background hex (default: '#f8f9fa' light, derived dark)
7142
+ * @param {Object} [config] - Style configuration
7143
+ * @param {string} [config.primary='#006666'] - Primary brand color hex
7144
+ * @param {string} [config.secondary='#6c757d'] - Secondary color hex
7145
+ * @param {string} [config.tertiary] - Tertiary color hex (defaults to primary)
7115
7146
  * @param {string} [config.spacing='normal'] - 'compact' | 'normal' | 'spacious'
7116
7147
  * @param {string} [config.radius='md'] - 'none' | 'sm' | 'md' | 'lg' | 'pill'
7117
- * @param {number} [config.fontSize=1.0] - Base font size scale factor
7118
- * @param {string|number} [config.typeRatio='normal'] - 'tight' | 'normal' | 'relaxed' | 'dramatic' or a number
7119
- * @param {string} [config.elevation='md'] - 'flat' | 'sm' | 'md' | 'lg'
7120
- * @param {string} [config.motion='standard'] - 'reduced' | 'standard' | 'expressive'
7121
- * @param {number} [config.harmonize=0.20] - 0-1, semantic color hue shift toward primary
7122
- * @param {boolean} [config.inject=true] - Inject into DOM (browser only)
7123
- * @returns {Object} { css, palette, name, isLightPrimary, alternate: { css, palette } }
7148
+ * @returns {Object} { css, alternateCss, rules, alternateRules, palette, alternatePalette, isLightPrimary }
7124
7149
  * @category CSS & Styling
7125
- * @see bw.applyTheme
7126
- * @see bw.toggleTheme
7127
- * @see bw.loadDefaultStyles
7150
+ * @see bw.applyStyles
7151
+ * @see bw.loadStyles
7128
7152
  * @example
7129
- * // Generate and inject an ocean theme (primary + alternate)
7130
- * var theme = bw.generateTheme('ocean', {
7131
- * primary: '#0077b6',
7132
- * secondary: '#90e0ef',
7133
- * tertiary: '#00b4d8'
7134
- * });
7135
- *
7136
- * // Apply to a container
7137
- * document.getElementById('app').classList.add('ocean');
7138
- *
7139
- * // Toggle to alternate palette
7140
- * bw.toggleTheme();
7141
- *
7142
- * // Generate CSS for static export (Node.js)
7143
- * var result = bw.generateTheme('sunset', {
7144
- * primary: '#e76f51',
7145
- * secondary: '#264653',
7146
- * inject: false
7147
- * });
7148
- * fs.writeFileSync('sunset.css', result.css + result.alternate.css);
7153
+ * var styles = bw.makeStyles({ primary: '#4f46e5', secondary: '#d97706' });
7154
+ * console.log(styles.palette.primary.base); // '#4f46e5'
7155
+ * // styles.css contains all themed CSS — nothing injected
7149
7156
  */
7150
- bw.generateTheme = function(name, config) {
7151
- if (!config || !config.primary || !config.secondary) {
7152
- throw new Error('bw.generateTheme requires config.primary and config.secondary');
7153
- }
7154
-
7155
- // Merge with defaults; if user didn't supply tertiary, default to their primary
7156
- var fullConfig = Object.assign({}, DEFAULT_PALETTE_CONFIG, config);
7157
- if (!config.tertiary) fullConfig.tertiary = fullConfig.primary;
7157
+ bw.makeStyles = function(config) {
7158
+ var fullConfig = Object.assign({}, DEFAULT_PALETTE_CONFIG, config || {});
7159
+ if (config && !config.tertiary) fullConfig.tertiary = fullConfig.primary;
7158
7160
 
7159
7161
  // Derive primary palette
7160
7162
  var palette = derivePalette(fullConfig);
@@ -7162,131 +7164,207 @@ bw.generateTheme = function(name, config) {
7162
7164
  // Resolve layout
7163
7165
  var layout = resolveLayout(fullConfig);
7164
7166
 
7165
- // Generate primary themed CSS rules
7166
- var themedRules = generateThemedCSS(name, palette, layout);
7167
+ // Generate primary themed CSS rules (unscoped)
7168
+ var themedRules = generateThemedCSS('', palette, layout);
7167
7169
  var cssStr = bw.css(themedRules);
7168
7170
 
7169
7171
  // Derive alternate palette (luminance-inverted)
7170
7172
  var altConfig = deriveAlternateConfig(fullConfig);
7171
7173
  var altPalette = derivePalette(altConfig);
7172
7174
 
7173
- // Generate alternate CSS scoped under .bw_theme_alt
7174
- var altRules = generateAlternateCSS(name, altPalette, layout);
7175
- var altCssStr = bw.css(altRules);
7175
+ // Generate alternate CSS rules WITHOUT .bw_theme_alt prefix (raw rules)
7176
+ // applyStyles() wraps them appropriately based on scope
7177
+ var altRawRules = generateThemedCSS('', altPalette, layout);
7178
+
7179
+ // Add body-level surface overrides for the alternate palette.
7180
+ // When .bw_theme_alt is on <html>, ".bw_theme_alt body" correctly matches.
7181
+ altRawRules['body'] = {
7182
+ 'color': altPalette.dark.base,
7183
+ 'background-color': altPalette.surface || altPalette.light.base
7184
+ };
7185
+
7186
+ var altCssStr = bw.css(altRawRules);
7176
7187
 
7177
7188
  // Determine if primary is light-flavored
7178
7189
  var lightPrimary = isLightPalette(fullConfig);
7179
7190
 
7180
- // Inject both CSS sets into DOM if requested
7181
- var shouldInject = config.inject !== false;
7182
- if (shouldInject && bw._isBrowser) {
7183
- var safeName = name ? name.replace(/-/g, '_') : '';
7184
- var styleId = safeName ? 'bw_theme_' + safeName : 'bw_theme_default';
7185
- var altStyleId = safeName ? 'bw_theme_' + safeName + '_alt' : 'bw_theme_default_alt';
7186
-
7187
- bw.injectCSS(cssStr, { id: styleId, append: false });
7188
- bw.injectCSS(altCssStr, { id: altStyleId, append: false });
7191
+ return {
7192
+ css: cssStr,
7193
+ alternateCss: altCssStr,
7194
+ rules: themedRules,
7195
+ alternateRules: altRawRules,
7196
+ palette: palette,
7197
+ alternatePalette: altPalette,
7198
+ isLightPrimary: lightPrimary
7199
+ };
7200
+ };
7189
7201
 
7190
- bw._activeThemeStyleIds = [styleId, altStyleId];
7202
+ /**
7203
+ * Inject styles into the DOM with optional scoping.
7204
+ *
7205
+ * Takes a styles object from `makeStyles()` and creates a single `<style>`
7206
+ * element in `<head>`. If a scope selector is provided, all CSS rules are
7207
+ * wrapped under that selector. Alternate CSS is wrapped under `.bw_theme_alt`.
7208
+ *
7209
+ * @param {Object} styles - Result of `bw.makeStyles()`
7210
+ * @param {string} [scope] - Scope selector (e.g. '#my-dashboard', '.preview'). Omit for global.
7211
+ * @returns {Element|null} The `<style>` element, or null in Node.js
7212
+ * @category CSS & Styling
7213
+ * @see bw.makeStyles
7214
+ * @see bw.loadStyles
7215
+ * @see bw.clearStyles
7216
+ * @example
7217
+ * var styles = bw.makeStyles({ primary: '#4f46e5' });
7218
+ * bw.applyStyles(styles); // global
7219
+ * bw.applyStyles(styles, '#my-dashboard'); // scoped
7220
+ */
7221
+ bw.applyStyles = function(styles, scope) {
7222
+ if (!bw._isBrowser) return null;
7223
+ if (!styles || !styles.rules) {
7224
+ _cw('bw.applyStyles: invalid styles object');
7225
+ return null;
7191
7226
  }
7192
7227
 
7193
- // Update bw.u color entries to reflect the palette
7194
- if (!name) {
7195
- bw.u.bgTeal = { background: palette.primary.base, color: palette.primary.textOn };
7196
- bw.u.textTeal = { color: palette.primary.base };
7197
- bw.u.bgWhite = { background: '#ffffff' };
7198
- bw.u.textWhite = { color: '#ffffff' };
7228
+ var styleId = _scopeToStyleId(scope);
7229
+
7230
+ // Scope the primary rules if a scope is provided
7231
+ var primaryRules = styles.rules;
7232
+ if (scope) {
7233
+ primaryRules = scopeRulesUnder(primaryRules, scope);
7199
7234
  }
7200
7235
 
7201
- // Store active theme state
7202
- var result = {
7203
- css: cssStr,
7204
- palette: palette,
7205
- name: name,
7206
- isLightPrimary: lightPrimary,
7207
- alternate: {
7208
- css: altCssStr,
7209
- palette: altPalette
7236
+ // Wrap alternate rules with .bw_theme_alt
7237
+ var altRules = styles.alternateRules;
7238
+ if (altRules) {
7239
+ if (scope) {
7240
+ // Scoped compound: #scope.bw_theme_alt .bw_card
7241
+ altRules = scopeRulesUnder(altRules, scope + '.bw_theme_alt');
7242
+ } else {
7243
+ // Global: .bw_theme_alt .bw_card
7244
+ altRules = scopeRulesUnder(altRules, '.bw_theme_alt');
7210
7245
  }
7211
- };
7212
- bw._activeTheme = result;
7213
- bw._activeThemeMode = 'primary';
7246
+ }
7214
7247
 
7215
- return result;
7248
+ // Combine primary + alternate into one CSS string
7249
+ var combined = bw.css(primaryRules);
7250
+ if (altRules) {
7251
+ combined += '\n' + bw.css(altRules);
7252
+ }
7253
+
7254
+ return bw.injectCSS(combined, { id: styleId, append: false });
7216
7255
  };
7217
7256
 
7218
7257
  /**
7219
- * Apply a theme mode. Switches between primary and alternate palettes
7220
- * by adding/removing the `bw_theme_alt` class on `<html>`.
7258
+ * Generate and apply styles in one call. Convenience wrapper.
7259
+ *
7260
+ * Equivalent to: `bw.applyStyles(bw.makeStyles(config), scope)`
7221
7261
  *
7222
- * @param {string} mode - 'primary' | 'alternate' | 'light' | 'dark'
7223
- * @returns {string} Active mode: 'primary' or 'alternate'
7262
+ * @param {Object} [config] - Style configuration (same as `makeStyles`)
7263
+ * @param {string} [scope] - Scope selector (same as `applyStyles`)
7264
+ * @returns {Element|null} The `<style>` element, or null in Node.js
7224
7265
  * @category CSS & Styling
7225
- * @see bw.generateTheme
7226
- * @see bw.toggleTheme
7266
+ * @see bw.makeStyles
7267
+ * @see bw.applyStyles
7227
7268
  * @example
7228
- * bw.applyTheme('alternate'); // switch to alternate palette
7229
- * bw.applyTheme('dark'); // switch to whichever palette is darker
7230
- * bw.applyTheme('primary'); // switch back to primary palette
7231
- */
7232
- bw.applyTheme = function(mode) {
7233
- if (!bw._isBrowser) return mode || 'primary';
7234
- var root = document.documentElement;
7235
- var isLight = bw._activeTheme ? bw._activeTheme.isLightPrimary : true;
7236
-
7237
- var wantAlt;
7238
- if (mode === 'primary') wantAlt = false;
7239
- else if (mode === 'alternate') wantAlt = true;
7240
- else if (mode === 'light') wantAlt = !isLight;
7241
- else if (mode === 'dark') wantAlt = isLight;
7242
- else wantAlt = false;
7243
-
7244
- if (wantAlt) {
7245
- root.classList.add('bw_theme_alt');
7246
- } else {
7247
- root.classList.remove('bw_theme_alt');
7269
+ * bw.loadStyles(); // defaults, global
7270
+ * bw.loadStyles({ primary: '#4f46e5' }); // custom, global
7271
+ * bw.loadStyles({ primary: '#4f46e5' }, '#my-dashboard'); // custom, scoped
7272
+ */
7273
+ bw.loadStyles = function(config, scope) {
7274
+ // Also inject structural CSS first (only once)
7275
+ if (bw._isBrowser) {
7276
+ var existing = document.getElementById('bw_structural');
7277
+ if (!existing) {
7278
+ var structuralCSS = bw.css(getStructuralStyles());
7279
+ bw.injectCSS(structuralCSS, { id: 'bw_structural', append: false });
7280
+ }
7248
7281
  }
7282
+ return bw.applyStyles(bw.makeStyles(config), scope);
7283
+ };
7249
7284
 
7250
- bw._activeThemeMode = wantAlt ? 'alternate' : 'primary';
7251
- return bw._activeThemeMode;
7285
+ /**
7286
+ * Inject the CSS reset (box-sizing, html/body font, reduced-motion).
7287
+ * Idempotent — if already injected, returns the existing `<style>` element.
7288
+ *
7289
+ * @returns {Element|null} The `<style>` element, or null in Node.js
7290
+ * @category CSS & Styling
7291
+ * @see bw.loadStyles
7292
+ * @see bw.clearStyles
7293
+ * @example
7294
+ * bw.loadReset(); // inject once, safe to call multiple times
7295
+ */
7296
+ bw.loadReset = function() {
7297
+ if (!bw._isBrowser) return null;
7298
+ var existing = document.getElementById('bw_style_reset');
7299
+ if (existing) return existing;
7300
+ return bw.injectCSS(bw.css(getResetStyles()), { id: 'bw_style_reset', append: false });
7252
7301
  };
7253
7302
 
7254
7303
  /**
7255
- * Toggle between primary and alternate theme palettes.
7304
+ * Toggle between primary and alternate palettes.
7256
7305
  *
7306
+ * Adds/removes the `bw_theme_alt` class on the scoping element.
7307
+ * Without a scope, toggles on `<html>` (global).
7308
+ * With a scope, toggles on the first matching element.
7309
+ *
7310
+ * @param {string} [scope] - Scope selector (e.g. '#my-dashboard'). Omit for global.
7257
7311
  * @returns {string} Active mode after toggle: 'primary' or 'alternate'
7258
7312
  * @category CSS & Styling
7259
- * @see bw.applyTheme
7260
- * @see bw.generateTheme
7313
+ * @see bw.applyStyles
7314
+ * @see bw.clearStyles
7261
7315
  * @example
7262
- * bw.toggleTheme(); // flip between primary and alternate
7316
+ * bw.toggleStyles(); // global toggle on <html>
7317
+ * bw.toggleStyles('#my-dashboard'); // scoped toggle
7263
7318
  */
7264
- bw.toggleTheme = function() {
7265
- var current = bw._activeThemeMode || 'primary';
7266
- return bw.applyTheme(current === 'primary' ? 'alternate' : 'primary');
7319
+ bw.toggleStyles = function(scope) {
7320
+ if (!bw._isBrowser) return 'primary';
7321
+ var target;
7322
+ if (scope) {
7323
+ var els = bw.$(scope);
7324
+ target = els[0];
7325
+ } else {
7326
+ target = document.documentElement;
7327
+ }
7328
+ if (!target) return 'primary';
7329
+
7330
+ var hasAlt = target.classList.contains('bw_theme_alt');
7331
+ if (hasAlt) {
7332
+ target.classList.remove('bw_theme_alt');
7333
+ return 'primary';
7334
+ } else {
7335
+ target.classList.add('bw_theme_alt');
7336
+ return 'alternate';
7337
+ }
7267
7338
  };
7268
7339
 
7269
7340
  /**
7270
- * Remove the currently active theme's injected style elements from the DOM.
7271
- * Use this before generating a new theme with a different name to prevent
7272
- * stale CSS accumulation.
7341
+ * Remove injected styles for a given scope.
7342
+ *
7343
+ * Finds the `<style>` element by id and removes it. Also removes
7344
+ * the `bw_theme_alt` class from the relevant element.
7273
7345
  *
7346
+ * @param {string} [scope] - Scope selector. Omit to remove global styles.
7274
7347
  * @category CSS & Styling
7275
- * @see bw.generateTheme
7348
+ * @see bw.applyStyles
7349
+ * @see bw.loadStyles
7276
7350
  * @example
7277
- * bw.clearTheme(); // remove current theme styles
7278
- * bw.generateTheme('sunset', conf); // inject fresh theme
7279
- */
7280
- bw.clearTheme = function() {
7281
- if (bw._activeThemeStyleIds && bw._isBrowser) {
7282
- bw._activeThemeStyleIds.forEach(function(id) {
7283
- var el = document.getElementById(id);
7284
- if (el) el.remove();
7285
- });
7286
- bw._activeThemeStyleIds = null;
7351
+ * bw.clearStyles(); // remove global styles
7352
+ * bw.clearStyles('#my-dashboard'); // remove scoped styles
7353
+ * bw.clearStyles('reset'); // remove the CSS reset
7354
+ */
7355
+ bw.clearStyles = function(scope) {
7356
+ if (!bw._isBrowser) return;
7357
+ var styleId = _scopeToStyleId(scope);
7358
+ var el = document.getElementById(styleId);
7359
+ if (el) el.remove();
7360
+
7361
+ // Also remove bw_theme_alt from the relevant element
7362
+ if (scope && scope !== 'reset' && scope !== 'global') {
7363
+ var targets = bw.$(scope);
7364
+ if (targets[0]) targets[0].classList.remove('bw_theme_alt');
7365
+ } else if (!scope || scope === 'global') {
7366
+ document.documentElement.classList.remove('bw_theme_alt');
7287
7367
  }
7288
- bw._activeTheme = null;
7289
- bw._activeThemeMode = 'primary';
7290
7368
  };
7291
7369
 
7292
7370
  // Expose color utility functions on bw namespace
@@ -7509,10 +7587,15 @@ bw.copyToClipboard = function(text) {
7509
7587
  * @param {Object} config - Table configuration
7510
7588
  * @param {Array<Object>} config.data - Array of row objects to display
7511
7589
  * @param {Array<Object>} [config.columns] - Column definitions with key, label, render
7512
- * @param {string} [config.className='table'] - CSS class for table element
7590
+ * @param {string} [config.className=''] - Additional CSS classes for table element
7513
7591
  * @param {boolean} [config.sortable=true] - Enable click-to-sort headers
7514
7592
  * @param {Function} [config.onSort] - Sort callback (column, direction)
7515
- * @returns {Object} TACO object for table
7593
+ * @param {boolean} [config.selectable=false] - Enable row selection on click
7594
+ * @param {Function} [config.onRowClick] - Row click callback (row, index, event)
7595
+ * @param {number} [config.pageSize] - Rows per page (enables pagination when set)
7596
+ * @param {number} [config.currentPage=1] - Current page number (1-based)
7597
+ * @param {Function} [config.onPageChange] - Page change callback (newPage)
7598
+ * @returns {Object} TACO object for table (with optional pagination controls)
7516
7599
  * @category Component Builders
7517
7600
  * @see bw.makeDataTable
7518
7601
  * @example
@@ -7524,7 +7607,12 @@ bw.copyToClipboard = function(text) {
7524
7607
  * columns: [
7525
7608
  * { key: 'name', label: 'Name' },
7526
7609
  * { key: 'age', label: 'Age' }
7527
- * ]
7610
+ * ],
7611
+ * selectable: true,
7612
+ * onRowClick: function(row, i) { console.log('clicked', row.name); },
7613
+ * pageSize: 10,
7614
+ * currentPage: 1,
7615
+ * onPageChange: function(page) { console.log('page', page); }
7528
7616
  * });
7529
7617
  */
7530
7618
  bw.makeTable = function(config) {
@@ -7537,41 +7625,47 @@ bw.makeTable = function(config) {
7537
7625
  sortable = true,
7538
7626
  onSort,
7539
7627
  sortColumn,
7540
- sortDirection = 'asc'
7628
+ sortDirection = 'asc',
7629
+ selectable = false,
7630
+ onRowClick,
7631
+ pageSize,
7632
+ currentPage = 1,
7633
+ onPageChange
7541
7634
  } = config;
7542
7635
 
7543
- // Build class list: always include bw_table, add striped/hover, append user className
7636
+ // Build class list: always include bw_table, add striped/hover/selectable, append user className
7544
7637
  let cls = 'bw_table';
7545
7638
  if (striped) cls += ' bw_table_striped';
7546
- if (hover) cls += ' bw_table_hover';
7639
+ if (hover || selectable) cls += ' bw_table_hover';
7640
+ if (selectable) cls += ' bw_table_selectable';
7547
7641
  if (className) cls += ' ' + className;
7548
7642
  cls = cls.trim();
7549
-
7643
+
7550
7644
  // Auto-detect columns if not provided
7551
- const cols = columns || (data.length > 0
7645
+ const cols = columns || (data.length > 0
7552
7646
  ? _keys(data[0]).map(key => ({ key, label: key }))
7553
7647
  : []);
7554
-
7648
+
7555
7649
  // Current sort state
7556
7650
  let currentSortColumn = sortColumn || null;
7557
7651
  let currentSortDirection = sortDirection;
7558
-
7652
+
7559
7653
  // Sort data if column specified
7560
7654
  let sortedData = [...data];
7561
7655
  if (currentSortColumn) {
7562
7656
  sortedData.sort((a, b) => {
7563
7657
  const aVal = a[currentSortColumn];
7564
7658
  const bVal = b[currentSortColumn];
7565
-
7659
+
7566
7660
  // Handle different types
7567
7661
  if (_is(aVal, 'number') && _is(bVal, 'number')) {
7568
7662
  return currentSortDirection === 'asc' ? aVal - bVal : bVal - aVal;
7569
7663
  }
7570
-
7664
+
7571
7665
  // String comparison
7572
7666
  const aStr = String(aVal || '').toLowerCase();
7573
7667
  const bStr = String(bVal || '').toLowerCase();
7574
-
7668
+
7575
7669
  if (currentSortDirection === 'asc') {
7576
7670
  return aStr.localeCompare(bStr);
7577
7671
  } else {
@@ -7579,23 +7673,32 @@ bw.makeTable = function(config) {
7579
7673
  }
7580
7674
  });
7581
7675
  }
7582
-
7676
+
7677
+ // Pagination
7678
+ const totalRows = sortedData.length;
7679
+ const totalPages = pageSize ? Math.max(1, Math.ceil(totalRows / pageSize)) : 1;
7680
+ const page = Math.max(1, Math.min(currentPage, totalPages));
7681
+ if (pageSize) {
7682
+ const start = (page - 1) * pageSize;
7683
+ sortedData = sortedData.slice(start, start + pageSize);
7684
+ }
7685
+
7583
7686
  // Create sort handler
7584
7687
  const handleSort = (column) => {
7585
7688
  if (!sortable) return;
7586
-
7689
+
7587
7690
  if (currentSortColumn === column) {
7588
7691
  currentSortDirection = currentSortDirection === 'asc' ? 'desc' : 'asc';
7589
7692
  } else {
7590
7693
  currentSortColumn = column;
7591
7694
  currentSortDirection = 'asc';
7592
7695
  }
7593
-
7696
+
7594
7697
  if (onSort) {
7595
7698
  onSort(column, currentSortDirection);
7596
7699
  }
7597
7700
  };
7598
-
7701
+
7599
7702
  // Build table header
7600
7703
  const thead = {
7601
7704
  t: 'thead',
@@ -7618,24 +7721,87 @@ bw.makeTable = function(config) {
7618
7721
  }))
7619
7722
  }
7620
7723
  };
7621
-
7622
- // Build table body
7724
+
7725
+ // Build table body with selectable/onRowClick support
7623
7726
  const tbody = {
7624
7727
  t: 'tbody',
7625
- c: sortedData.map(row => ({
7626
- t: 'tr',
7627
- c: cols.map(col => ({
7628
- t: 'td',
7629
- c: col.render ? col.render(row[col.key], row) : String(row[col.key] || '')
7630
- }))
7631
- }))
7728
+ c: sortedData.map((row, idx) => {
7729
+ const globalIdx = pageSize ? (page - 1) * pageSize + idx : idx;
7730
+ const rowAttrs = {};
7731
+ if (selectable || onRowClick) {
7732
+ rowAttrs.style = 'cursor:pointer;';
7733
+ rowAttrs.onclick = function(e) {
7734
+ if (selectable) {
7735
+ // Toggle selected class on this row
7736
+ var tr = e.currentTarget;
7737
+ tr.classList.toggle('bw_table_row_selected');
7738
+ }
7739
+ if (onRowClick) {
7740
+ onRowClick(row, globalIdx, e);
7741
+ }
7742
+ };
7743
+ }
7744
+ return {
7745
+ t: 'tr',
7746
+ a: rowAttrs,
7747
+ c: cols.map(col => ({
7748
+ t: 'td',
7749
+ c: col.render ? col.render(row[col.key], row) : String(row[col.key] || '')
7750
+ }))
7751
+ };
7752
+ })
7632
7753
  };
7633
-
7634
- return {
7754
+
7755
+ const table = {
7635
7756
  t: 'table',
7636
7757
  a: { class: cls },
7637
7758
  c: [thead, tbody]
7638
7759
  };
7760
+
7761
+ // If no pagination, return table directly
7762
+ if (!pageSize) return table;
7763
+
7764
+ // Build pagination controls
7765
+ const pageButtons = [];
7766
+ // Previous button
7767
+ pageButtons.push({
7768
+ t: 'button',
7769
+ a: {
7770
+ class: 'bw_btn bw_btn_sm',
7771
+ disabled: page <= 1 ? 'disabled' : undefined,
7772
+ onclick: page > 1 && onPageChange ? function() { onPageChange(page - 1); } : undefined
7773
+ },
7774
+ c: 'Prev'
7775
+ });
7776
+ // Page info
7777
+ pageButtons.push({
7778
+ t: 'span',
7779
+ a: { style: 'margin:0 0.5rem;font-size:0.875rem;' },
7780
+ c: 'Page ' + page + ' of ' + totalPages
7781
+ });
7782
+ // Next button
7783
+ pageButtons.push({
7784
+ t: 'button',
7785
+ a: {
7786
+ class: 'bw_btn bw_btn_sm',
7787
+ disabled: page >= totalPages ? 'disabled' : undefined,
7788
+ onclick: page < totalPages && onPageChange ? function() { onPageChange(page + 1); } : undefined
7789
+ },
7790
+ c: 'Next'
7791
+ });
7792
+
7793
+ return {
7794
+ t: 'div',
7795
+ a: { class: 'bw_table_paginated' },
7796
+ c: [
7797
+ table,
7798
+ {
7799
+ t: 'div',
7800
+ a: { class: 'bw_table_pagination', style: 'display:flex;align-items:center;justify-content:flex-end;padding:0.5rem 0;gap:0.25rem;' },
7801
+ c: pageButtons
7802
+ }
7803
+ ]
7804
+ };
7639
7805
  };
7640
7806
 
7641
7807
  /**