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.
Files changed (119) hide show
  1. package/README.md +160 -158
  2. package/bin/bitwrench.js +3 -0
  3. package/dist/bitwrench-code-edit.cjs.js +639 -0
  4. package/dist/bitwrench-code-edit.es5.js +875 -0
  5. package/dist/bitwrench-code-edit.es5.min.js +15 -0
  6. package/dist/bitwrench-code-edit.esm.js +628 -0
  7. package/dist/bitwrench-code-edit.esm.min.js +15 -0
  8. package/dist/bitwrench-code-edit.umd.js +645 -0
  9. package/dist/bitwrench-code-edit.umd.min.js +15 -0
  10. package/dist/bitwrench.cjs.js +6983 -0
  11. package/dist/bitwrench.cjs.min.js +62 -0
  12. package/dist/bitwrench.css +5100 -0
  13. package/dist/bitwrench.es5.js +8446 -0
  14. package/dist/bitwrench.es5.min.js +31 -0
  15. package/dist/bitwrench.esm.js +6981 -0
  16. package/dist/bitwrench.esm.min.js +62 -0
  17. package/dist/bitwrench.umd.js +6989 -0
  18. package/dist/bitwrench.umd.min.js +62 -0
  19. package/dist/builds.json +127 -0
  20. package/dist/sri.json +18 -0
  21. package/package.json +86 -24
  22. package/readme.html +288 -0
  23. package/src/bitwrench-code-edit.js +627 -0
  24. package/src/bitwrench-color-utils.js +311 -0
  25. package/src/bitwrench-component-base.js +736 -0
  26. package/src/bitwrench-components-inline.js +374 -0
  27. package/src/bitwrench-components-v2.js +1879 -0
  28. package/src/bitwrench-components.js +610 -0
  29. package/src/bitwrench-styles.js +3240 -0
  30. package/src/bitwrench.js +3367 -0
  31. package/src/cli/convert.js +205 -0
  32. package/src/cli/index.js +122 -0
  33. package/src/cli/inject.js +55 -0
  34. package/src/cli/layout-default.js +142 -0
  35. package/src/generate-css.js +381 -0
  36. package/src/vendor/quikdown.js +654 -0
  37. package/src/version.js +16 -0
  38. package/.eslintrc.json +0 -27
  39. package/.github/workflows/codeql-analysis.yml +0 -72
  40. package/.travis.yml +0 -34
  41. package/bitwrench.css +0 -92
  42. package/bitwrench.js +0 -3348
  43. package/bitwrench.js_sri.txt +0 -1
  44. package/bitwrench.min.js +0 -1
  45. package/bitwrench.min.js_sri.txt +0 -1
  46. package/bitwrench_ESM.js +0 -3207
  47. package/dev/bitwrench-todo.md +0 -215
  48. package/dev/css-arrows.md +0 -23
  49. package/dev/docStringDev.js +0 -124
  50. package/dev/docStringParseDev.js +0 -171
  51. package/dev/figures.html +0 -37
  52. package/dev/html_gen.js +0 -349
  53. package/dev/htmld.md +0 -250
  54. package/dev/htmldev.html +0 -45
  55. package/dev/index-old.html +0 -87
  56. package/dev/misc-notes.md +0 -21
  57. package/dev/notes.md +0 -2
  58. package/dev/sizes.html +0 -49
  59. package/dev/universal-js-module.js +0 -37
  60. package/examples/example1.html +0 -78
  61. package/examples/example10.html +0 -84
  62. package/examples/example2.html +0 -44
  63. package/examples/example3.html +0 -50
  64. package/examples/example4.html +0 -22
  65. package/examples/example5.html +0 -82
  66. package/examples/example6.html +0 -128
  67. package/examples/example7.html +0 -91
  68. package/examples/example8.html +0 -27
  69. package/examples/example9.html +0 -102
  70. package/icon/bitwrench-dark-tall.png +0 -0
  71. package/icon/bitwrench-dark.png +0 -0
  72. package/icon/bitwrench-icon-lt-grey.png +0 -0
  73. package/icon/bitwrench-icon.vsd +0 -0
  74. package/icon/bitwrench-logo-dark.png +0 -0
  75. package/icon/bitwrench-logo-full.png +0 -0
  76. package/icon/bitwrench-logo-green.png +0 -0
  77. package/icon/bitwrench-logo-grey.png +0 -0
  78. package/icon/bitwrench-logo-white.png +0 -0
  79. package/icon/bitwrench-logos-colors.png +0 -0
  80. package/icon/bitwrench-thick-logo.png +0 -0
  81. package/icon/bitwrench-thick-teal/android-chrome-192x192.png +0 -0
  82. package/icon/bitwrench-thick-teal/android-chrome-512x512.png +0 -0
  83. package/icon/bitwrench-thick-teal/apple-touch-icon.png +0 -0
  84. package/icon/bitwrench-thick-teal/browserconfig.xml +0 -9
  85. package/icon/bitwrench-thick-teal/favicon-16x16.png +0 -0
  86. package/icon/bitwrench-thick-teal/favicon-32x32.png +0 -0
  87. package/icon/bitwrench-thick-teal/favicon.ico +0 -0
  88. package/icon/bitwrench-thick-teal/mstile-144x144.png +0 -0
  89. package/icon/bitwrench-thick-teal/mstile-150x150.png +0 -0
  90. package/icon/bitwrench-thick-teal/mstile-310x150.png +0 -0
  91. package/icon/bitwrench-thick-teal/mstile-310x310.png +0 -0
  92. package/icon/bitwrench-thick-teal/mstile-70x70.png +0 -0
  93. package/icon/bitwrench-thick-teal/site.webmanifest +0 -19
  94. package/icon/bitwrench-thick-teal.ico +0 -0
  95. package/icon/bitwrench-thick-teal.svg +0 -44
  96. package/icon/bitwrench-thick-teal.zip +0 -0
  97. package/icon/favicon-test.html +0 -20
  98. package/icon/logos-test.PNG +0 -0
  99. package/images/bitwrench-512x512.png +0 -0
  100. package/images/bitwrench-logo-med.png +0 -0
  101. package/images/bitwrench-thick-logo.png +0 -0
  102. package/images/bitwrench-thick-logo.svg +0 -64
  103. package/images/bitwrench-thick-teal.ico +0 -0
  104. package/images/favicon.ico +0 -0
  105. package/index.html +0 -256
  106. package/instr_tmp/bitwrench.js +0 -1350
  107. package/karma.conf.js +0 -140
  108. package/makefile +0 -21
  109. package/quick-docs.html +0 -206
  110. package/test/bitwrench_test.js +0 -1255
  111. package/test/karma-test.js +0 -1081
  112. package/tools/bw_deprecatedNames.js +0 -19
  113. package/tools/bwconsole.js +0 -20
  114. package/tools/createSimpleHTMLPage.js +0 -41
  115. package/tools/emitreadme.sh +0 -4
  116. package/tools/export-bw-default-css.js +0 -41
  117. package/tools/umd2ModuleHack.js +0 -32
  118. package/tools/update-bw-package.js +0 -36
  119. package/tools/updatereadme.js +0 -34
package/dev/html_gen.js DELETED
@@ -1,349 +0,0 @@
1
-
2
-
3
-
4
- //assumes proper node form
5
- bw.htmlNodeRender(x) {
6
- s = bw.toa(x,"string",x,)
7
- return s;
8
- }
9
-
10
- //====================================
11
-
12
-
13
- bw.htmlRender = function(htmlData, opts) {
14
- /**
15
- must be of form
16
- t ==> tag (string)
17
- a ==> attrib {}
18
- c ==> content [] content can be string | node (other values converted to string)
19
- o ==> options {}
20
-
21
- htmldict
22
- {
23
- tag: "tagValue",
24
- attrib : {},
25
- content : [], // each member must be: string or htmlDict or null. other values cast to string.
26
- options : {},
27
-
28
- }
29
- */
30
-
31
- var html = "";
32
-
33
- var _atr = function(k,v,o){ // to do handle "smart" attributes ==> class : ["class1", "class2"] ==> style : bw.makeCSS()
34
- var val=v,ok = _to(o.overide)=="undefined" ? k : ok;
35
- switch(ok) {
36
- case "style" :
37
- val = bw.makeCSS(val,{pretty:false});
38
- break;
39
- default :
40
- if (bw.to(v)=="array")
41
- val = val.join(" ");
42
- val = val.toString();
43
- }
44
- return k+"="+"\""+val.replace("\"","\\\"")+"\"";
45
- }
46
- var _s = function(n,c){return Array(n+1).join(c);}
47
- ind_s = ddict.o.pretty ? Array(ddict.s.level * ddict.o.pretty_indent ).join(ddict.o.pretty_space) : ""; // not   ==> we're not trying to render this space just make it pretty for inspection
48
- ind_c = ddict.o.pretty ? Array((ddict.s.level+1) * ddict.o.pretty_indent ).join(ddict.o.pretty_space) : ""; // not   ==> we're not trying to render this space just make it pretty for inspection
49
- ind_e = ddict.o.pretty ? "\n" : "";
50
-
51
- var _clsTag = function(t,c) {
52
-
53
- }
54
- try {
55
- var i,atrk=[],_a=[],k,v;
56
- for (i in ddict.a)
57
- if (ddict.hasOwnProperty(i)) atrk.push(i);
58
- atrk = atrk.sort(function(x)bw.naturalCompare);
59
- for (i=0; i<atrk.length; i++) {
60
- k=artk[i]; v=ddict[k];
61
- if (v=null) { _a.push(k); continue;}
62
- _a.push(_fatr(k,v));
63
- }
64
- _a = _a.join(" ");
65
- _a = ((_a.length>0) ? " ": "") + _a;
66
-
67
- html += ind_s + "<" +ddict.t + _a+">";
68
- html += ddict.c.map((function(x){
69
- var s = _to(x) == "object" ? bw.htmlFromDict(x) : x.toString();
70
- return ind_c+s;
71
- }
72
- ).join((ddict.pretty?"\n":""));
73
- html += ind_e + "</" +ddict.t +">";
74
-
75
- }
76
- catch(e) {
77
- logd(e);
78
- }
79
- }
80
-
81
- //=====old=====
82
- //==================================================
83
- /**
84
- */
85
-
86
-
87
-
88
- bw.html_fc = function(x) {
89
- var i,n = { t: "div", a: {}, c: "", o: {}}; // default html dict format
90
- var m = "";
91
- switch (_to(x)) {
92
- case "null" :
93
- case "undefined" :
94
- n = x;
95
- break;
96
- case "object":
97
- [["tag","t"],["attrib","a"],["content","c"],["options","o"]].forEach(function(z){ n[z[1]]= z[0] in x ? x[z[0]] : n[z[1]];});
98
- for (i in n) { // we only copy those fields we care about..
99
- n[i] = (i in x) ? x[i] : n[i]; // need to handle complicated types: t:"", a:{}, c:"" | []
100
- if (bw.isnu(n[i])) {
101
- n = null; // force entire object to be null or undefined
102
- m = "HTML gen err: bad object";
103
- break;
104
- }
105
- }
106
- break;
107
- case "array":
108
- var idx = [[],["c"], ["t","c"], ["t","a","c"],["t","a","c","o"],["t","a","c","o","s"]];
109
- m = (x.length > 5) ? 5 : x.length;
110
- for (i=0; i< m; i++) {
111
- bw.logd(idx[m][i] + ":" + x[i]);
112
- n[idx[m][i]] = x[i];
113
- }
114
- for (i in n)
115
- if (bw.isnu(n[i])) {
116
- n = null;
117
- m = "HTML gen err: bad array";
118
- break;
119
- }
120
-
121
- break;
122
- case "function":
123
- var opts = {};
124
- n = bw.html_fc2(x(),opts); // evaluate and convert...
125
- break;
126
- default: // string, number, Date, bool, Regex
127
- n.c =x.toString();
128
- }
129
- return n;
130
- };
131
-
132
- bw.htmlExt = function(data, opts) {
133
- var dopts = {
134
- tagClose: "auto",
135
- contentHTMLSafe : "false", // convert content node chars to htmlSafe equivalents e.g. " " ==> &nbsp;
136
-
137
- pretty: "true",
138
- indStr : " ", // only used in pretty set to true. can be "\t" etc
139
- indFixed: "", //
140
-
141
- maxdepthAllowed : 50
142
-
143
- };
144
- dopts = optsCopy(dopts,opts);
145
- var state = {
146
- cdepth : 0, // curdepth
147
- cbreadth : 0, // curbreadth (e.g. content[3])
148
- maxdepth : 0,
149
- ncount : 0, // num nodes rendered
150
- errors : [] // trapped erors
151
- }
152
- var ret = ["",state];
153
- var htmlRenderNode = function(d,o,s) { // assumes
154
- var h="", n = htmlNorm(d,o,s) // get it in dict form
155
-
156
- }
157
- {
158
- var hd = (function(){return {t:"div",a:{},c:[],{o:tagClose:"auto"}}})();
159
-
160
- //emit tagOpen
161
- // indFixed + ?pretty|indstr + <tag + atr() + tagselfclose>
162
- // for i=0.. hd.c.length
163
- // if c[i] == object | function :
164
- // cbreadth++
165
- // convert
166
- // else
167
- // (emit) indFixed + ?pretty|indstr c[i].toString()
168
-
169
- }
170
- return ret;
171
- }
172
-
173
- //=======================================
174
- /*
175
- state has levels, node, nodecount info
176
- */
177
- bw.HTMLNorm = function(x,state) {
178
-
179
- function bwHTMLNode () {this.t="div"; this.a={}; this.c=[]; this.o={};}
180
- function bwError (v,x) {this.value=v; this.msg = typeof x == "undefined" ? "error" : x;}
181
-
182
- var i,n = new bwHTMLNode(); // default html dict format
183
- var m = "";
184
- switch (_to(x)) {
185
- case "null" :
186
- case "undefined" :
187
- n = new bwError(x,"HTML Node error : "+_to(x));
188
- break;
189
- case "object":
190
- [["tag","t"],["attrib","a"],["content","c"],["options","o"]].forEach(function(z){ n[z[1]]= z[0] in x ? x[z[0]] : n[z[1]];});
191
- for (i in n) { // we only copy those fields we care about..
192
- n[i] = (i in x) ? x[i] : n[i]; // need to handle complicated types: t:"", a:{}, c:"" | []
193
- if (bw.isnu(n[i])) {
194
- n = null; // force entire object to be null or undefined
195
- m = "HTML gen err: bad object";
196
- break;
197
- }
198
- }
199
- break;
200
- case "array":
201
- var idx = [[],["c"], ["t","c"], ["t","a","c"],["t","a","c","o"],["t","a","c","o","s"]];
202
- m = (x.length > 5) ? 5 : x.length;
203
- for (i=0; i< m; i++) {
204
- //console.log(idx[m][i] + ":" + x[i]);
205
- n[idx[m][i]] = x[i];
206
- }
207
- for (i in n)
208
- if (bw.isnu(n[i])) {
209
- n = null;
210
- m = "HTML gen err: bad array";
211
- break;
212
- }
213
-
214
- break;
215
- case "function":
216
- var opts = {};
217
- n = bw.html_fc2(x(),opts); // evaluate and convert...
218
- n = _to(n)=="function" ? new bwError(n.toString(),"HTML Node error: function returned a function") : n;
219
- break;
220
- default: // string, number, Date, bool, Regex ==> will be come just plain rendered content later
221
- n.c =x.toString();
222
- }
223
- return n;
224
- };
225
- //**********************************************************
226
- //**********************************************************
227
- bw.htmlMod20200215 = function (d,options) {
228
- /**
229
- bw.html(data)
230
-
231
- takes data of one of these exact forms:
232
-
233
- string
234
- array: ["div", content]
235
- array: ["div",{attribute dict},content]
236
- array: ["div",{attribute dict},content, options]
237
- dict: {tag:"div", atr: {attribute dict}, "content": content}
238
- content can be string or array
239
-
240
- and creates an HTML string wich can be used to generate DOM elements such as
241
- document.getELementById("theID").innerHTML = buildHTMLObjString(data).
242
-
243
- content can be nested
244
-
245
- d is string or an array ["tag".{attributs dict},content] or dict of this form
246
- tag, atr, content (also allow short hand t,a,c)
247
- tag or t = string --> "div"
248
- atr or a = dict --> {"style" : "width=40;height=50", "class" : "foo bar"}
249
- content or c = [] or string. if array each element must be either string or dict of this form.
250
- if any element is a function it will be evaluated in place with no params.
251
-
252
- */
253
- var dopts = {
254
- pretty : false,
255
- indent : 0,
256
- indentStr : " "
257
- };
258
- dopts = optsCopy(dopts,options);
259
-
260
- var outFn = function(s,opts) {
261
- var w = Array(opts["indent"]).join(opts["indentStr"]);
262
- var we = Array(opts["indent"]-1).join(opts["indentStr"]);
263
- return opts["pretty"] ? "\n"+w+ s + "\n" +we: s;
264
- };
265
-
266
-
267
- dopts["indent"]++;
268
-
269
- var s="", t="div",a={},c=[],i;
270
-
271
- switch (_to(d)) {
272
- case "date":
273
- case "number":
274
- s=String(d); // eslint-disable-line no-fallthrough
275
- case "string":
276
- s=d;
277
- return outFn(s,dopts); // Note return statement here...
278
- break; // eslint-disable-line no-unreachable
279
- case "function" :
280
- s = bw.html(d(),dopts);
281
- break;
282
- case "array":
283
-
284
- if ((_to(d[0]) == "undefined") || d.length != 3)
285
- return "";
286
- t = _to(d[0]) != "undefined" ? d[0] :t;
287
- a = _to(d[1]) != "undefined" ? d[1] :a;
288
- c = _to(d[2]) != "undefined" ? d[2] :c;
289
- t = _to(t) == "function" ? t() :t;
290
- a = _to(a) == "function" ? a() :a;
291
- c = _to(c) == "function" ? c() :c;
292
- c = _to(c) != "array" ? [c] :c;
293
- break;
294
- case "object":
295
- t = _to(d["t"]) == "function" ? d["t"]() : t;
296
- t = _to(d["tag"]) == "function" ? d["tag"]() : t;
297
- t = _to(d["t"]) == "string" ? d["t"] : t;
298
- t = _to(d["tag"]) == "string" ? d["tag"] : t;
299
-
300
- a = _to(d["a"]) == "function" ? d["a"]() : a;
301
- a = _to(d["atr"]) == "function" ? d["atr"]() : a;
302
- a = _to(d["a"]) == "object" ? d["a"] : a;
303
- a = _to(d["atr"]) == "object" ? d["atr"] : a;
304
- switch (_to(d["c"])) {
305
- case "function" :
306
- c = d["content"](); break;
307
- case "array" :
308
- c = d["content"]; break;
309
- default:
310
- c = [d["content"]];
311
- }
312
- switch (_to(d["c"])) {
313
- case "function" :
314
- c = d["c"](); break;
315
- case "array" :
316
- c = d["c"]; break;
317
- default:
318
- c = [d["c"]];
319
- }
320
- break;
321
- default:
322
- bw.log("bw.html:: error in type");
323
- }
324
-
325
- s+= "<" + t ;
326
- for (i in a) {
327
- s+=" "+ String(i)+"=\"" + String(a[i]) +"\"";
328
- }
329
- s+= ">";
330
- //console.log(t,a,c);
331
- for (i=0; i<c.length; i++) {
332
- var _c = "";
333
-
334
- switch(_to(c[i])) {
335
- case "function":
336
- _c = c[i](); // eslint-disable-line no-fallthrough
337
- case "object": // eslint-disable-line no-fallthrough
338
- case "array" :
339
- _c = bw.html(c[i],dopts);
340
- break;
341
- default:
342
- _c = String (c[i]);
343
- }
344
- s+= _c;
345
- }
346
- s+= "</" + t + ">";
347
-
348
- return outFn(s,dopts);
349
- };
package/dev/htmld.md DELETED
@@ -1,250 +0,0 @@
1
-
2
-
3
- dataStack = []
4
-
5
-
6
- start:
7
-
8
- node = bw.HtmlNode(data, {atomic:"raw"})
9
-
10
-
11
- if (node == "atomic")
12
- html += indent + node
13
- else
14
- switch (node.t, node.c)
15
-
16
- case node.t isvoidTag():
17
-
18
- case node.c isEmpty
19
-
20
- default
21
- html += indent + tag
22
-
23
-
24
-
25
- //=================
26
- ```html
27
- <div foo="bar"> ["<"+n.t, ">", "</"+n.t+">"]
28
- content
29
- </div>
30
-
31
- <meta foo="bar" /> ["<"+n.t, "/>", ""]
32
-
33
- <link href="./place/to/get" /> ["<"+n.t, "/>", ""]
34
-
35
- <div> ["<"+n.t, ">", "</"+n.t+">"]
36
- <div id="123"> ["<"+n.t, ">", "</"+n.t+">"]
37
- this is the content
38
- </div>
39
- <div id="123"> ["<"+n.t, ">", "</"+n.t+">"]
40
- this is the content2
41
- </div>
42
- </div>
43
-
44
- <div>
45
- <div id="123">this is the content</div>
46
- </div>
47
-
48
- //=============
49
-
50
-
51
- //if f() ==> resolve to "" | node
52
-
53
- var n= bw.HTMLNode(data);
54
-
55
- if _to(n.node) == "function" {
56
- n = bw.htmlNode(n.node());
57
- n = _toa(n.ntype,["BW_HTMLNode","string"],n,""); // if its still not a content we just need to punt it.
58
- }
59
-
60
- var h = [];
61
-
62
- if n.ntype == "string"
63
- h.push(n.node.toString())
64
- else
65
- crend = function(c){ return c!= "array"}
66
-
67
- h = ["<",n.tag, a{}];
68
-
69
- auto:
70
- if node.isVoidTag
71
- // <tag a{} /> # content is not rendered for void tags # ["<",n.t , a{}, "/>" ]
72
- h.push( "/>");
73
- break;
74
-
75
- all:
76
- none:
77
- //<tag a{}> .... </tag> # h=["<",n.t , a{}, crend() , "</", n.t, ">"]
78
- h.push(">");
79
- for (i in c)
80
- h.push(htmlEmit(c[i]).html)
81
- if ( opts.tagClose == "all" )
82
- h.push( "</",n.t,">");
83
-
84
-
85
- state.nodeCount++
86
- html = h.join("");
87
- ```
88
-
89
- bw.htmlRender = function (data,opts,state) {
90
- dopts= {
91
-
92
- }
93
-
94
- dopts = optsCopy(dopts,opts);
95
-
96
- }
97
- {
98
- c: "foo" ==>
99
- }
100
-
101
- bw.htmlNode(data, opts)
102
- {
103
- opts {
104
- convertAtomicToNode : true | false, // if true, converts atomic to a span element e.g. "foo" ==> {t:"span",c:["foo"]}
105
- }
106
-
107
- return {
108
- node: HTMLNode | string | function
109
- isHTMLVoidTag : true | false, // returns true if tag is "meta" or "br" etc
110
- isAtomic : true | false, // returns true if input data was not a proper node.
111
- error : false | string
112
-
113
- }
114
- }
115
-
116
- //===========================
117
-
118
- // ===================================================================================
119
- bw.htmlEmit = function(htmlData, opts, state) {
120
- /**
121
-
122
-
123
- //global options:
124
- pretty (true | false) (default: true) attempts to make HTML pretty (human readable) if false it will be as compact as possible
125
- pretty_space (if pretty == true) (default: " ") this is the stirng used as the indent string but one could make it "\t" or " " etc.
126
- pretty_indent (if pretty == true) a fixed indent to provide to every line of html
127
-
128
-
129
-
130
- tagClose : ("auto" | closeempty | all | none) whether to close a tag. default is "auto"
131
- "auto" : will apply smart rules to tag closing. e.g. html void elements such as br are not closed
132
- "closeempty" : all void elements are now self closed (e.g. are self closed ==> <meta /> or <br />)
133
- "all" : tags are forced closed with </tagname> ==> can be useful for xml type generation
134
- "none" : tags are not closed at all
135
-
136
- all options can be overridden via local node
137
-
138
- */
139
- var html = "",stats={};
140
- var dopts = {
141
- pretty : true,
142
- pretty_space: " ",
143
- pretty_indent: "", //fixed indent when pretty pass as " " etc
144
- htmlEscContent : false // change spaces, /n /t to html equivalents
145
- }
146
- dopts = optsCopy(dopts,opts);
147
-
148
-
149
- state = bw.toa(state,"object",state, {
150
- levelCount : 0,
151
- levelMax : 0,
152
- nodeCount : 0
153
- });
154
-
155
-
156
- var _s = function(n){return dopts.pretty_indent+ Array(n+1).join(dopts.pretty_space);} // generate indents for pretty
157
-
158
- var _atr = function(k,v,o){ // to do handle "smart" attributes ==> class : ["class1", "class2"] ==> style : bw.makeCSS()
159
- var val=v,ok = "atr_def"in o ? "none" : k;
160
- if (v==null)
161
- return k;
162
- switch(ok) {
163
- case "style" :
164
- val = bw.makeCSS(val,{pretty:false});
165
- break;
166
- default :
167
- if (bw.to(v)=="array")
168
- val = val.join(" ");
169
- val = val.toString();
170
- }
171
- return k+"="+"\""+val.replace("\"","\\\"")+"\"";
172
- }
173
-
174
- var _cls = function(n) { // takes BW HTML node
175
- var r=["","</"+n.t+">"] // r[0] is whether to include closing slash on start tag, r[1] is whether to include closing tag
176
- var ce = _to(n.c)!="array" ? true : ((n.c.length ==0) ? true : false);
177
- // o.tagClose==auto && _isv(t)==true ==> ,
178
- // _isv(t)==false ==> , </t>
179
- // o.tagClose==closeEmpty && _isv(t)==true ==> /,
180
- // _isv(t)==false ==> , </t>
181
-
182
- // o.tagClose==none ==> ,
183
- // o.tagClose==all ==> , </t>
184
- r = bw.choice(n.o.tagClose,
185
- {
186
- "auto" : (function(){return (n.isVoidTag) ? ["",""] : ["","</"+n.t+">"];}) (),
187
- "closeEmpty" : (function(){return (n.isVoidTag) ? ["/",""] : ["","</"+n.t+">"];}) (),
188
- "none" : ["",""]
189
- },r);
190
- console.log("cls:",r);
191
- return r;
192
- }
193
-
194
- var ind_s = dopts.pretty ? _s(state.levelCount) : ""; // not &nbsp; ==> we're not trying to render this space just make it pretty for inspection
195
- var ind_c = dopts.pretty ? _s(state.levelCount+1) : ""; // not &nbsp; ==> we're not trying to render this space just make it pretty for inspection
196
- var ind_e = dopts.pretty ? "\n" : "";
197
-
198
-
199
- try {
200
- var i,atrk=[],_a=[],k,v, nx = bw.htmlNode(htmlData);
201
- switch (nx.ntype) {
202
- case "BW_HTMLNode":
203
- {
204
- var node = nx.node;
205
- for (i in node.a)
206
- if (node.a.hasOwnProperty(i)) atrk.push(i);
207
- atrk = atrk.sort(bw.naturalCompare);
208
- for (i=0; i<atrk.length; i++) {
209
- k=atrk[i]; v=node.a[k];
210
- console.log(k,v)
211
- _a.push(_atr(k,v,node.o));
212
- }
213
- _a = _a.join(" ");
214
- _a = ((_a.length>0) ? " ": "") + _a;
215
- console.log( _a, node,nx, ind_s,ind_c,ind_e);
216
- if ("atomic" == nx[1]) {
217
- html += ind_c+node.c[0] + ind_e;
218
- }
219
- else {
220
- //console.log(state.levelCount, state.nodeCount,_a)
221
- html += ind_s + "<" +node.t + _a+ _cls(node)[0]+">";
222
- html += node.c.map(function(x){
223
- state.levelCount++;
224
- state.levelMax += state.levelMax < state.levelCount ? 1 : 0;
225
- var s = bw.htmlEmit(x,dopts,state).html;
226
- state.levelCount--;
227
- return s;
228
- }
229
- ).join((dopts.pretty?"\n":""));
230
- html += ind_e + _cls(node)[1] +(dopts.pretty?"\n":"");
231
- }
232
- }
233
- break;
234
- case "function" :
235
- var z = bw.htmlEmit(nx.node());
236
- html += z.html;
237
- break;
238
- default :
239
- html += node.node;
240
- }
241
- state.nodeCount ++;
242
- //console.log(html);
243
- }
244
- catch(e) {
245
- console.log(htmlData,node,e);
246
- bw.logd(e);
247
- }
248
-
249
- return {html:html, stats: state}
250
- }
package/dev/htmldev.html DELETED
@@ -1,45 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
5
- <link rel="icon" type="image/x-icon" href="../images/favicon.ico" />
6
- <!-- bitwrench.js library examples
7
- (c) M A Chatterjee
8
- deftio <at> deftio <dot> com
9
- web : http:deftio.com/bitwrench
10
- github: http:github.com/deftio/bitwrench
11
- -->
12
- <script type="text/javascript" src="../bitwrench.js"></script>
13
- <style type="text/css"></style>
14
- </style>
15
- </head>
16
- <body class="bw-def-page-setup bw-font-sans-serif">
17
- <div id="top"></div>
18
- <hr>
19
- <div id="bot"></div>
20
- <script>
21
-
22
- var content =
23
- [
24
- ["h1","Example HTML Gen with bitwrench"],
25
- ["p", {},[{t:"strong",a:{style:{color:"red"}}, c:"bitwrench.js version"}, bw.version()["version"]]],
26
- ["p", {},"This example shows how to set up json like webpage with bitwrench"],
27
- ["p",{style:"color:orange;"},()=>{return "arrow "+new Date()}],
28
- "<br>",
29
- {tag:"div",a:{class:"bw-left", onclick:function(x){x.style.color=x.style.color=="red"?"blue":"red";} }, c:"click me"},
30
- ["h2",{class:"bw-left bw-col-6", id:"result"},"H2 heading"],
31
- ["div",{}, [{c:"foo"},"bar",["span"," bar2"],{c:[1," content in the middle " ,43]} ]],
32
- "<br>",
33
- ];
34
-
35
- var c2 = {c:content};
36
-
37
- // make the content go live since we're in a browser. Note that if we were on node we could just write out our content
38
- bw.DOM("#top", bw.html({c:content}));
39
- var x = bw.htmlEmit(c2);
40
- bw.DOM("#bot", x.html);
41
-
42
- //document.getElementById("test").innerHTML = bw.logExport({"exportFormat":"HTML"});
43
- </script>
44
- </body>
45
- </html>