bitwrench 1.2.15 → 2.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +160 -158
- package/bin/bitwrench.js +3 -0
- package/dist/bitwrench-code-edit.cjs.js +639 -0
- package/dist/bitwrench-code-edit.es5.js +875 -0
- package/dist/bitwrench-code-edit.es5.min.js +15 -0
- package/dist/bitwrench-code-edit.esm.js +628 -0
- package/dist/bitwrench-code-edit.esm.min.js +15 -0
- package/dist/bitwrench-code-edit.umd.js +645 -0
- package/dist/bitwrench-code-edit.umd.min.js +15 -0
- package/dist/bitwrench.cjs.js +6983 -0
- package/dist/bitwrench.cjs.min.js +62 -0
- package/dist/bitwrench.css +5100 -0
- package/dist/bitwrench.es5.js +8446 -0
- package/dist/bitwrench.es5.min.js +31 -0
- package/dist/bitwrench.esm.js +6981 -0
- package/dist/bitwrench.esm.min.js +62 -0
- package/dist/bitwrench.umd.js +6989 -0
- package/dist/bitwrench.umd.min.js +62 -0
- package/dist/builds.json +127 -0
- package/dist/sri.json +18 -0
- package/package.json +86 -24
- package/readme.html +288 -0
- package/src/bitwrench-code-edit.js +627 -0
- package/src/bitwrench-color-utils.js +311 -0
- package/src/bitwrench-component-base.js +736 -0
- package/src/bitwrench-components-inline.js +374 -0
- package/src/bitwrench-components-v2.js +1879 -0
- package/src/bitwrench-components.js +610 -0
- package/src/bitwrench-styles.js +3240 -0
- package/src/bitwrench.js +3367 -0
- package/src/cli/convert.js +205 -0
- package/src/cli/index.js +122 -0
- package/src/cli/inject.js +55 -0
- package/src/cli/layout-default.js +142 -0
- package/src/generate-css.js +381 -0
- package/src/vendor/quikdown.js +654 -0
- package/src/version.js +16 -0
- package/.eslintrc.json +0 -27
- package/.github/workflows/codeql-analysis.yml +0 -72
- package/.travis.yml +0 -34
- package/bitwrench.css +0 -92
- package/bitwrench.js +0 -3348
- package/bitwrench.js_sri.txt +0 -1
- package/bitwrench.min.js +0 -1
- package/bitwrench.min.js_sri.txt +0 -1
- package/bitwrench_ESM.js +0 -3207
- package/dev/bitwrench-todo.md +0 -215
- package/dev/css-arrows.md +0 -23
- package/dev/docStringDev.js +0 -124
- package/dev/docStringParseDev.js +0 -171
- package/dev/figures.html +0 -37
- package/dev/html_gen.js +0 -349
- package/dev/htmld.md +0 -250
- package/dev/htmldev.html +0 -45
- package/dev/index-old.html +0 -87
- package/dev/misc-notes.md +0 -21
- package/dev/notes.md +0 -2
- package/dev/sizes.html +0 -49
- package/dev/universal-js-module.js +0 -37
- package/examples/example1.html +0 -78
- package/examples/example10.html +0 -84
- package/examples/example2.html +0 -44
- package/examples/example3.html +0 -50
- package/examples/example4.html +0 -22
- package/examples/example5.html +0 -82
- package/examples/example6.html +0 -128
- package/examples/example7.html +0 -91
- package/examples/example8.html +0 -27
- package/examples/example9.html +0 -102
- package/icon/bitwrench-dark-tall.png +0 -0
- package/icon/bitwrench-dark.png +0 -0
- package/icon/bitwrench-icon-lt-grey.png +0 -0
- package/icon/bitwrench-icon.vsd +0 -0
- package/icon/bitwrench-logo-dark.png +0 -0
- package/icon/bitwrench-logo-full.png +0 -0
- package/icon/bitwrench-logo-green.png +0 -0
- package/icon/bitwrench-logo-grey.png +0 -0
- package/icon/bitwrench-logo-white.png +0 -0
- package/icon/bitwrench-logos-colors.png +0 -0
- package/icon/bitwrench-thick-logo.png +0 -0
- package/icon/bitwrench-thick-teal/android-chrome-192x192.png +0 -0
- package/icon/bitwrench-thick-teal/android-chrome-512x512.png +0 -0
- package/icon/bitwrench-thick-teal/apple-touch-icon.png +0 -0
- package/icon/bitwrench-thick-teal/browserconfig.xml +0 -9
- package/icon/bitwrench-thick-teal/favicon-16x16.png +0 -0
- package/icon/bitwrench-thick-teal/favicon-32x32.png +0 -0
- package/icon/bitwrench-thick-teal/favicon.ico +0 -0
- package/icon/bitwrench-thick-teal/mstile-144x144.png +0 -0
- package/icon/bitwrench-thick-teal/mstile-150x150.png +0 -0
- package/icon/bitwrench-thick-teal/mstile-310x150.png +0 -0
- package/icon/bitwrench-thick-teal/mstile-310x310.png +0 -0
- package/icon/bitwrench-thick-teal/mstile-70x70.png +0 -0
- package/icon/bitwrench-thick-teal/site.webmanifest +0 -19
- package/icon/bitwrench-thick-teal.ico +0 -0
- package/icon/bitwrench-thick-teal.svg +0 -44
- package/icon/bitwrench-thick-teal.zip +0 -0
- package/icon/favicon-test.html +0 -20
- package/icon/logos-test.PNG +0 -0
- package/images/bitwrench-512x512.png +0 -0
- package/images/bitwrench-logo-med.png +0 -0
- package/images/bitwrench-thick-logo.png +0 -0
- package/images/bitwrench-thick-logo.svg +0 -64
- package/images/bitwrench-thick-teal.ico +0 -0
- package/images/favicon.ico +0 -0
- package/index.html +0 -256
- package/instr_tmp/bitwrench.js +0 -1350
- package/karma.conf.js +0 -140
- package/makefile +0 -21
- package/quick-docs.html +0 -206
- package/test/bitwrench_test.js +0 -1255
- package/test/karma-test.js +0 -1081
- package/tools/bw_deprecatedNames.js +0 -19
- package/tools/bwconsole.js +0 -20
- package/tools/createSimpleHTMLPage.js +0 -41
- package/tools/emitreadme.sh +0 -4
- package/tools/export-bw-default-css.js +0 -41
- package/tools/umd2ModuleHack.js +0 -32
- package/tools/update-bw-package.js +0 -36
- package/tools/updatereadme.js +0 -34
package/README.md
CHANGED
|
@@ -1,202 +1,204 @@
|
|
|
1
|
+
# bitwrench.js
|
|
2
|
+
|
|
1
3
|
[](https://opensource.org/licenses/BSD-2-Clause)
|
|
2
4
|
[](https://www.npmjs.com/package/bitwrench)
|
|
3
|
-
[](http://www.deftio.com/bitwrench)
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
## Welcome to bitwrench.js
|
|
9
|
-
|
|
10
|
-
bitwrench.js is a javascript library for for creating quick demos with almost no depedancies. With bitwrench one can create web pages and components with pure json or javascript dictionaries including handlers (e.g. onclick="...code.." ==> onclick:function_ref, css , etc. )
|
|
11
|
-
bitwrench.js also has handyman functions such as loremIpsum generation, ranged random numbers and interpolaters, and color blenders. Use it for throwing up quick web pages which don't depend on any server side framework but need a little prettyifcation or for visualizing quick data. For example when debugging C/C++ embedded projects where we don't want to clutter the build dirs with lots of "weird web stuff" - just write a simple HTML page with bitwrench and still load and view raw text files, JSON, arrays and other bits of embedded files with no extra dependancies.
|
|
5
|
+
[](https://github.com/deftio/bitwrench/actions/workflows/ci.yml)
|
|
12
6
|
|
|
13
|
-
|
|
7
|
+
[](https://deftio.github.io/bitwrench/pages/)
|
|
14
8
|
|
|
9
|
+
Bitwrench is a UI library in a single script that provides HTML generation, reactive state, CSS and theme generation, 30+ components, and a static site CLI — all from plain JavaScript objects, with zero dependencies and zero compile steps. Works in browsers (including IE11) and Node.js.
|
|
15
10
|
|
|
16
|
-
|
|
11
|
+
## Quick Example
|
|
17
12
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
* simple parsing of URL params, also can be used for command line scripts, also packs simple dicts back to URLs. note that this functionality predated modern URL libs so you might want to use those for modern apps. However bitwrench versions do work on old browers such as IE8 and iPodTouch 4th generation
|
|
34
|
-
* **Data manipulation functions** and other "random" things
|
|
35
|
-
* numeric interpolation & clipping
|
|
36
|
-
* create multi-d arrays
|
|
37
|
-
* random(4,11) ==> put out a random number in the range 4-11, also provides multidim arrays of random numbers useful for testing tables etc
|
|
38
|
-
* prandom() ==> pseudorandom numbers with range settings, also provides multidim arrays of random numbers useful for testing tables etc
|
|
39
|
-
* **Logging** with time-stamps, messaging, and pretty printing (raw, HTML, and text)
|
|
40
|
-
* Logging also has auto dissolve so one can log a process and then dump later or suppress in 'production'
|
|
41
|
-
* **Built-in docString parsing** with extraction support
|
|
42
|
-
* bitwrench.js self-documents in that from the browser DOM one can pull out a given function's doc strings such as bw.docString("DOM") ==> gives docString inforfor that function.
|
|
43
|
-
* note that bitwrench.min.js strips comments so built-in help is not available.
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
There is no great structure here, just a bunch of kitchen sink things that seemed to be handy in alot of quick web dev situations. All non-dom specific calls can be run either server side or client side.
|
|
48
|
-
|
|
49
|
-
A minified form bitwrench.min.js is provided with identical functionality
|
|
13
|
+
```javascript
|
|
14
|
+
const card = {
|
|
15
|
+
t: 'div', a: { class: 'bw-card' },
|
|
16
|
+
c: [
|
|
17
|
+
{ t: 'h3', c: 'Hello bitwrench' },
|
|
18
|
+
{ t: 'p', c: 'UI as native JavaScript objects.' }
|
|
19
|
+
]
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// Mount to the DOM
|
|
23
|
+
bw.DOM('#app', card);
|
|
24
|
+
|
|
25
|
+
// Or render to an HTML string (Node.js, emails, static pages)
|
|
26
|
+
const html = bw.html(card);
|
|
27
|
+
```
|
|
50
28
|
|
|
51
|
-
|
|
52
|
-
See the quick docs here:
|
|
53
|
-
[bitwrench quick docs](./quick-docs.html)
|
|
29
|
+
Each object has four keys: **t** (tag), **a** (attributes), **c** (content), and optionally **o** (options for state and lifecycle). Nest them, loop them, compose them — it's just JavaScript.
|
|
54
30
|
|
|
55
|
-
|
|
56
|
-
[bitwrench examples](./examples)
|
|
31
|
+
## Installation
|
|
57
32
|
|
|
58
|
-
### node.js
|
|
59
33
|
```bash
|
|
60
|
-
|
|
61
|
-
npm install bitwrench --save
|
|
34
|
+
npm install bitwrench
|
|
62
35
|
```
|
|
63
36
|
|
|
64
37
|
```javascript
|
|
65
|
-
//
|
|
66
|
-
|
|
67
|
-
var s = bw.html(["div",{"class":"foo"},"This is some HTML"]); // now... ===> s = "<div class='foo'>This is some HTML</div>
|
|
38
|
+
// ES module
|
|
39
|
+
import bw from 'bitwrench';
|
|
68
40
|
|
|
41
|
+
// CommonJS
|
|
42
|
+
const bw = require('bitwrench');
|
|
69
43
|
```
|
|
70
44
|
|
|
71
|
-
|
|
72
|
-
In the browser bitwrench is loaded like any script library. Note that parameters can be passed to bitwrench to control the loading process.
|
|
73
|
-
bitwrench generates its own default css from javascript and loads those. You can see these statically in the bitwrench.css file (note that bitwrench.css can also be used standalone without the bitwrench.js library).
|
|
74
|
-
[Example Page](./examples/example5.html) source code here:
|
|
45
|
+
Or include directly in a page:
|
|
75
46
|
|
|
76
47
|
```html
|
|
48
|
+
<script src="https://cdn.jsdelivr.net/npm/bitwrench/dist/bitwrench.umd.min.js"></script>
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Features
|
|
52
|
+
|
|
53
|
+
- **HTML from plain objects** — describe UI as JavaScript objects, render to live DOM with `bw.DOM()` or to HTML strings with `bw.html()` for server-side rendering, emails, and static pages
|
|
54
|
+
- **Built-in reactivity** — `bw.update()` re-renders components when state changes, `bw.patch()` updates individual elements by ID, `bw.pub()`/`bw.sub()` provides decoupled messaging between any part of the application
|
|
55
|
+
- **CSS and theme generation** — `bw.css()` generates stylesheets from objects, `bw.generateTheme()` derives a complete visual theme (buttons, alerts, badges, cards, forms, tables, dark mode) from 2-3 seed colors
|
|
56
|
+
- **30+ ready-made components** — cards, buttons, sortable tables, form inputs, alerts, badges, tabs, navbars, spinners, progress bars — each a single function call that returns a composable object
|
|
57
|
+
- **Static site CLI** — the `bitwrench` command converts Markdown, HTML, and JSON files into styled, self-contained pages with theme support
|
|
58
|
+
- **Utilities** — color interpolation, random data generation, lorem ipsum, cookies, URL params, file I/O for both browser and Node.js
|
|
59
|
+
|
|
60
|
+
## Getting Started
|
|
77
61
|
|
|
62
|
+
```html
|
|
78
63
|
<!DOCTYPE html>
|
|
79
64
|
<html lang="en">
|
|
80
65
|
<head>
|
|
81
|
-
<script src="
|
|
66
|
+
<script src="https://cdn.jsdelivr.net/npm/bitwrench/dist/bitwrench.umd.min.js"></script>
|
|
82
67
|
</head>
|
|
83
|
-
<body
|
|
84
|
-
<
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
["div",{"class":"bw-col-4 bw-right "},"<h3>Right justified</h3>"+bw.loremIpsum(95,2)],
|
|
101
|
-
],
|
|
102
|
-
],
|
|
103
|
-
"<br><hr>",
|
|
104
|
-
["h2", {}, "Example Sortable Table"],
|
|
105
|
-
bw.htmlTable( // json to table (note table data can be functions as well)
|
|
106
|
-
[
|
|
107
|
-
["Name","Age", "Prof", "Fav Color"], // just an 2D array
|
|
108
|
-
["Sue", 34, "Engineer", {a:{style:"color:red"},c:"red"}], // inline json-html objects
|
|
109
|
-
["Bob" ,35, "Teacher", {a:{style:"color:green"},c:"green"}],
|
|
110
|
-
["Vito",23, "Mechanic", {a:{style:"color:blue",onclick:"alert('blue!')"},c:"blue"}],
|
|
111
|
-
["Hank",73, "Retired", {a:{style:"color:purple"},c:"purple"}]
|
|
112
|
-
],{sortable:true}),
|
|
113
|
-
"<br><hr>",
|
|
114
|
-
["h2",{},"Sample Buttons"],
|
|
115
|
-
"These buttons have function handlers attached.<br><br>",
|
|
116
|
-
["button",{onclick:"alert('button pressed!')"},"Alert Button"], // staight js
|
|
117
|
-
" ",
|
|
118
|
-
["button",{onclick:myFunc},"Time Button"], // bitwrench maps and registers event functions
|
|
119
|
-
"<br><hr>",
|
|
120
|
-
["h2","Built in Headings"],
|
|
121
|
-
[1,2,3,4,5,6].map( function(x){return bw.html(["h"+x,"Heading "+x])}).join(""), // Headings
|
|
122
|
-
"<br><hr>",
|
|
123
|
-
["h2","Grid System (responsive)"],
|
|
124
|
-
"Grid system (just uses css so can use either bitwrench.js loader or just bitwrench.css with no javascript. Use -fluid for responsive<br><br>",
|
|
125
|
-
["style",{},"\n.boxEv {background-color: #aaa; height: 30px; border-radius:5px; border:1px solid black;}\n.boxOd {background-color: #ddd; height:30px; border-radius:5px;border:1px solid black;;}\n"], // some styles (note bw has CSS generation shown in another example)
|
|
126
|
-
["div",{class:"bw-row bw-center"},[{a:{class:"bw-col-1 boxEv"},c:"bw-col-1"},{a:{class:"bw-col-1 boxOd"},c:"bw-col-1"},{a:{class:"bw-col-1 boxEv"},c:"bw-col-1"},{a:{class:"bw-col-1 boxOd"},c:"bw-col-1"},{a:{class:"bw-col-1 boxEv"},c:"bw-col-1"},{a:{class:"bw-col-1 boxOd"},c:"bw-col-1"},{a:{class:"bw-col-1 boxEv"},c:"bw-col-1"},{a:{class:"bw-col-1 boxOd"},c:"bw-col-1"},{a:{class:"bw-col-1 boxEv"},c:"bw-col-1"},{a:{class:"bw-col-1 boxOd"},c:"bw-col-1"},{a:{class:"bw-col-1 boxEv"},c:"bw-col-1"},{a:{class:"bw-col-1 boxOd"},c:"bw-col-1"}]],
|
|
127
|
-
["div",{class:"bw-row bw-center"},[{a:{class:"bw-col-2 boxEv"},c:"bw-col-2"},{a:{class:"bw-col-2 boxOd"},c:"bw-col-2"},{a:{class:"bw-col-2 boxEv"},c:"bw-col-2"},{a:{class:"bw-col-2 boxOd"},c:"bw-col-2"},{a:{class:"bw-col-2 boxEv"},c:"bw-col-2"},{a:{class:"bw-col-2 boxOd"},c:"bw-col-2"}]],
|
|
128
|
-
["div",{class:"bw-row bw-center"},[{a:{class:"bw-col-3 boxEv"},c:"bw-col-3"},{a:{class:"bw-col-3 boxOd"},c:"bw-col-3"},{a:{class:"bw-col-3 boxEv"},c:"bw-col-3"},{a:{class:"bw-col-3 boxOd"},c:"bw-col-3"}]],
|
|
129
|
-
["div",{class:"bw-row bw-center"},[{a:{class:"bw-col-4 boxEv"},c:"bw-col-4"},{a:{class:"bw-col-4 boxOd"},c:"bw-col-4"},{a:{class:"bw-col-4 boxEv"},c:"bw-col-4"}]],
|
|
130
|
-
["div",{class:"bw-row bw-center"},[{a:{class:"bw-col-5 boxEv"},c:"bw-col-5"},{a:{class:"bw-col-7 boxOd"},c:"bw-col-7"}]],
|
|
131
|
-
["div",{class:"bw-row bw-center"},[{a:{class:"bw-col-6 boxEv"},c:"bw-col-6"},{a:{class:"bw-col-6 boxOd"},c:"bw-col-6"}]],
|
|
132
|
-
["div",{class:"bw-row bw-center"},[{a:{class:"bw-col-7 boxEv"},c:"bw-col-7"},{a:{class:"bw-col-5 boxOd"},c:"bw-col-5"}]],
|
|
133
|
-
["div",{class:"bw-row bw-center"},[{a:{class:"bw-col-8 boxEv"},c:"bw-col-8"},{a:{class:"bw-col-4 boxOd"},c:"bw-col-4"}]],
|
|
134
|
-
["div",{class:"bw-row bw-center"},[{a:{class:"bw-col-9 boxEv"},c:"bw-col-9"},{a:{class:"bw-col-3 boxOd"},c:"bw-col-3"}]],
|
|
135
|
-
["div",{class:"bw-row bw-center"},[{a:{class:"bw-col-10 boxEv"},c:"bw-col-10"},{a:{class:"bw-col-2 boxOd"},c:"bw-col-2"}]],
|
|
136
|
-
["div",{class:"bw-row bw-center"},[{a:{class:"bw-col-11 boxEv"},c:"bw-col-11"},{a:{class:"bw-col-1 boxOd"},c:"bw-col-1"}]],
|
|
137
|
-
["div",{class:"bw-row bw-center"},[{a:{class:"bw-col-12 boxEv"},c:"bw-col-12"}]],
|
|
138
|
-
|
|
139
|
-
"<br><hr>",
|
|
140
|
-
["h2",{},"Simple Sign"],
|
|
141
|
-
["div",{style:"padding:10%; border:1px solid black;"},bw.htmlSign("This is a big sign!")],
|
|
142
|
-
"<br><hr>",
|
|
143
|
-
["h2",{},"Tabbed Content"],
|
|
144
|
-
bw.htmlTabs([
|
|
145
|
-
["Tab1",bw.loremIpsum(300)],
|
|
146
|
-
["Tab2",bw.loremIpsum(300,20)],
|
|
147
|
-
["Tab3",bw.loremIpsum(300,50)]],{tab_atr:{style:""}}) ,
|
|
148
|
-
"<br>",
|
|
149
|
-
]};
|
|
150
|
-
|
|
151
|
-
bw.DOMInsertElement("body",bw.html(htmlData),true);
|
|
152
|
-
function myFunc(x){return x.innerHTML = (new Date()).toLocaleTimeString();} // button function
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
bw.DOMInsertElement("head",bw.html(bw.htmlFavicon("\u266C","teal"))); // insert a favicon on the top tab of the page, "X" for a single letter
|
|
156
|
-
bw.DOMInsertElement("head",bw.html({t:"title",c:"Bitwrench HTML Gen "})); // insert a page title on the browser tab
|
|
157
|
-
</script>
|
|
68
|
+
<body>
|
|
69
|
+
<div id="app"></div>
|
|
70
|
+
<script>
|
|
71
|
+
bw.loadDefaultStyles();
|
|
72
|
+
|
|
73
|
+
bw.DOM('#app', {
|
|
74
|
+
t: 'div', a: { class: 'bw-container' },
|
|
75
|
+
c: [
|
|
76
|
+
{ t: 'h1', c: 'My App' },
|
|
77
|
+
bw.makeCard({
|
|
78
|
+
title: 'Welcome',
|
|
79
|
+
content: 'Built with plain JavaScript objects.'
|
|
80
|
+
}),
|
|
81
|
+
bw.makeButton({ label: 'Click me', variant: 'primary' })
|
|
82
|
+
]
|
|
83
|
+
});
|
|
84
|
+
</script>
|
|
158
85
|
</body>
|
|
159
86
|
</html>
|
|
160
87
|
```
|
|
161
|
-
|
|
162
88
|
|
|
163
|
-
##
|
|
164
|
-
all source is at github:
|
|
165
|
-
[bitwrench on github](http://github.com/deftio/bitwrench)
|
|
89
|
+
## Adding State
|
|
166
90
|
|
|
91
|
+
The `o` key adds state and a render function to any element. When state changes, call `bw.update()` to re-render:
|
|
167
92
|
|
|
168
|
-
|
|
169
|
-
|
|
93
|
+
```javascript
|
|
94
|
+
bw.DOM('#counter', {
|
|
95
|
+
t: 'div',
|
|
96
|
+
o: {
|
|
97
|
+
state: { count: 0 },
|
|
98
|
+
render: function(el) {
|
|
99
|
+
var s = el._bw_state;
|
|
100
|
+
bw.DOM(el, {
|
|
101
|
+
t: 'div', c: [
|
|
102
|
+
{ t: 'span', c: 'Count: ' + s.count },
|
|
103
|
+
{ t: 'button', a: {
|
|
104
|
+
onclick: function() { s.count++; bw.update(el); }
|
|
105
|
+
}, c: '+1' }
|
|
106
|
+
]
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
```
|
|
170
112
|
|
|
171
|
-
|
|
172
|
-
npm install eslint --save-dev
|
|
113
|
+
For communication between components, use pub/sub:
|
|
173
114
|
|
|
174
|
-
|
|
115
|
+
```javascript
|
|
116
|
+
bw.sub('item-added', function(detail) {
|
|
117
|
+
console.log('New item:', detail.name);
|
|
118
|
+
});
|
|
175
119
|
|
|
120
|
+
bw.pub('item-added', { name: 'Widget' });
|
|
176
121
|
```
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
122
|
+
|
|
123
|
+
## Theming
|
|
124
|
+
|
|
125
|
+
Generate a complete theme from two seed colors. All components — buttons, alerts, badges, cards, forms, tables — are styled automatically:
|
|
126
|
+
|
|
127
|
+
```javascript
|
|
128
|
+
bw.generateTheme('my-theme', {
|
|
129
|
+
primary: '#336699',
|
|
130
|
+
secondary: '#cc6633'
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
bw.toggleDarkMode();
|
|
180
134
|
```
|
|
181
135
|
|
|
182
|
-
##
|
|
183
|
-
|
|
136
|
+
## Core API
|
|
137
|
+
|
|
138
|
+
| Function | Description |
|
|
139
|
+
|---|---|
|
|
140
|
+
| `bw.html(obj)` | Convert an object to an HTML string |
|
|
141
|
+
| `bw.DOM(selector, obj)` | Mount an object to a DOM element |
|
|
142
|
+
| `bw.css(rules)` | Generate CSS from a JS object |
|
|
143
|
+
| `bw.loadDefaultStyles()` | Inject the built-in stylesheet |
|
|
144
|
+
| `bw.generateTheme(name, config)` | Generate a scoped theme from seed colors |
|
|
145
|
+
| `bw.patch(id, content)` | Update a specific element by UUID |
|
|
146
|
+
| `bw.update(el)` | Re-render via the element's `o.render` function |
|
|
147
|
+
| `bw.pub(topic, detail)` | Publish a message to subscribers |
|
|
148
|
+
| `bw.sub(topic, handler)` | Subscribe to a topic; returns an unsub function |
|
|
149
|
+
|
|
150
|
+
See the full [API Reference](https://deftio.github.io/bitwrench/pages/08-api-reference.html) for all functions.
|
|
151
|
+
|
|
152
|
+
## CLI
|
|
153
|
+
|
|
154
|
+
Convert Markdown, HTML, or JSON files to styled standalone pages:
|
|
184
155
|
|
|
185
156
|
```bash
|
|
186
|
-
|
|
157
|
+
# Convert Markdown to a self-contained HTML page
|
|
158
|
+
bitwrench README.md -o index.html --standalone
|
|
187
159
|
|
|
160
|
+
# Apply a theme preset
|
|
161
|
+
bitwrench doc.md -o doc.html --standalone --theme ocean
|
|
162
|
+
|
|
163
|
+
# Custom colors
|
|
164
|
+
bitwrench doc.md -o doc.html --standalone --theme "#336699,#cc6633"
|
|
188
165
|
```
|
|
189
166
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
167
|
+
Flags: `--output/-o`, `--standalone/-s`, `--cdn`, `--theme/-t`, `--css/-c`, `--title`, `--favicon/-f`, `--highlight`, `--verbose/-v`
|
|
168
|
+
|
|
169
|
+
## Build Formats
|
|
170
|
+
|
|
171
|
+
| Format | File | Use case |
|
|
172
|
+
|--------|------|----------|
|
|
173
|
+
| UMD | `bitwrench.umd.min.js` | Browsers and Node.js |
|
|
174
|
+
| ESM | `bitwrench.esm.min.js` | Modern bundlers (Vite, webpack, etc.) |
|
|
175
|
+
| CJS | `bitwrench.cjs.min.js` | Node.js `require()` |
|
|
176
|
+
| ES5 | `bitwrench.es5.min.js` | Legacy browsers (IE11) |
|
|
177
|
+
|
|
178
|
+
All formats include source maps. A separate CSS file (`bitwrench.css`) is also available for use without JavaScript.
|
|
193
179
|
|
|
180
|
+
## Documentation
|
|
181
|
+
|
|
182
|
+
- [Interactive docs and demos](https://deftio.github.io/bitwrench/pages/) — full tutorial site with live examples
|
|
183
|
+
- [Quick Start](https://deftio.github.io/bitwrench/pages/00-quick-start.html) — first steps with `bw.DOM()`
|
|
184
|
+
- [Components](https://deftio.github.io/bitwrench/pages/01-components.html) — buttons, cards, alerts, badges, navbars
|
|
185
|
+
- [Styling & Theming](https://deftio.github.io/bitwrench/pages/03-styling.html) — CSS generation and theming strategies
|
|
186
|
+
- [State & Interactivity](https://deftio.github.io/bitwrench/pages/05-state.html) — `bw.patch()`, `bw.update()`, pub/sub
|
|
187
|
+
- [Tic Tac Toe Tutorial](https://deftio.github.io/bitwrench/pages/06-tic-tac-toe-tutorial.html) — step-by-step game with state management
|
|
188
|
+
- [Framework Comparison](https://deftio.github.io/bitwrench/pages/07-framework-comparison.html) — bitwrench vs React, Vue, Svelte
|
|
189
|
+
|
|
190
|
+
## Development
|
|
191
|
+
|
|
192
|
+
```bash
|
|
193
|
+
npm install # install dev dependencies
|
|
194
|
+
npm run build # build all dist formats (UMD, ESM, CJS, ES5)
|
|
195
|
+
npm test # run unit tests (284 tests)
|
|
196
|
+
npm run test:cli # run CLI tests (49 tests)
|
|
197
|
+
npm run test:e2e # run Playwright browser tests
|
|
198
|
+
npm run lint # run ESLint
|
|
199
|
+
npm run cleanbuild # full production build with SRI hashes
|
|
194
200
|
```
|
|
195
201
|
|
|
196
|
-
##
|
|
197
|
-
* 1.2x Initial release
|
|
198
|
-
|
|
199
|
-
## License
|
|
200
|
-
bitwrench is released under the OSI Approved FreeBSD 2-clause license
|
|
202
|
+
## License
|
|
201
203
|
|
|
202
|
-
|
|
204
|
+
[BSD-2-Clause](./LICENSE.txt) — (c) M. A. Chatterjee / [deftio](https://github.com/deftio)
|
package/bin/bitwrench.js
ADDED