git @ Cat's Eye Technologies DAM / 50a309c
Build non-minified versions of dam and dam-plus-widgets, too. Chris Pressey 1 year, 7 months ago
3 changed file(s) with 284 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
0 !function(){var e={makeElem:function(e,n){n=n||[];for(var t=document.createElement(e),o=0;o<n.length;o++){var r=n[o];r instanceof Element?t.appendChild(r):"string"==typeof r||r instanceof String?t.appendChild(document.createTextNode(r)):"object"==typeof r&&null!==r?Object.keys(r).forEach(function(e){"on"===e.substring(0,2)?t.addEventListener(e.substring(2),r[e]):null===r[e]?t.removeAttribute(e):t.setAttribute(e,r[e])}):console.log(r)}return t},maker:function(n){return function(){return e.makeElem(n,arguments)}}};"undefined"!=typeof module?module.exports=e:"undefined"!=typeof window&&(window.DAM=e)}();
0 (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
1 "use strict";
2
3 var _dam = _interopRequireDefault(require("./dam.js"));
4
5 var _damWidgets = require("./dam-widgets.js");
6
7 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
8
9 /* dam-plus-widgets.js version 0.2. This file is in the public domain. */
10 window.DAM = _dam["default"];
11 _dam["default"].makeCheckbox = _damWidgets.makeCheckbox;
12 _dam["default"].makePanel = _damWidgets.makePanel;
13 _dam["default"].makeSelect = _damWidgets.makeSelect;
14 _dam["default"].makeRange = _damWidgets.makeRange;
15
16 },{"./dam-widgets.js":2,"./dam.js":3}],2:[function(require,module,exports){
17 "use strict";
18
19 var _dam = _interopRequireDefault(require("./dam.js"));
20
21 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
22
23 /* dam-widgets.js version 0.2. This file is in the public domain. */
24
25 /* if you want to use this file in an ES5 context, either remove the following line
26 and ensure dam.js has already been loaded, or just use `dam-plus-widgets-web.js`
27 instead of this file, it's probably easier to do that, just do that instead. */
28
29 /*
30 * A labelled checkbox, where the checkbox appears to the left of the label.
31 * Arguments after the first (config) argument will be applied to the label element.
32 */
33 function makeCheckbox(config) {
34 if (typeof _dam["default"].makeCheckboxCounter === 'undefined') _dam["default"].makeCheckboxCounter = 0;
35 var checkboxId = 'cfzzzb_' + _dam["default"].makeCheckboxCounter++;
36
37 var _onchange = config.onchange || function (b) {}; // config label: make copy of arguments, replace first with a bespoke config
38
39
40 var args = new Array(arguments.length);
41
42 for (var i = 0; i < args.length; ++i) {
43 args[i] = arguments[i];
44 }
45
46 args[0] = {
47 'for': checkboxId,
48 'class': "dam-widget dam-checkbox"
49 };
50 return _dam["default"].makeElem('span', [_dam["default"].makeElem('input', [{
51 type: 'checkbox',
52 id: checkboxId,
53 onchange: function onchange(e) {
54 _onchange(e.target.checked);
55 }
56 }, config.checkboxAttrs || {}]), _dam["default"].makeElem('label', args)]);
57 }
58
59 ;
60 /*
61 * A collapsible panel.
62 * Arguments after the first (config) argument will be applied to the inner container div element.
63 */
64
65 function makePanel(config) {
66 var isOpen = !!config.isOpen;
67 var title = config.title || "";
68
69 function getLabel() {
70 return (isOpen ? "∇" : "⊳") + " " + title;
71 } // config inner container
72
73
74 var args = new Array(arguments.length);
75
76 for (var i = 0; i < args.length; ++i) {
77 args[i] = arguments[i];
78 }
79
80 args[0] = {};
81
82 var innerContainer = _dam["default"].makeElem('div', args);
83
84 innerContainer.style.display = isOpen ? "block" : "none";
85
86 var button = _dam["default"].makeElem('button', [getLabel(), {
87 onclick: function onclick(e) {
88 isOpen = !isOpen;
89 button.textContent = getLabel();
90 innerContainer.style.display = isOpen ? "block" : "none";
91 }
92 }]);
93
94 return _dam["default"].makeElem("div", [{
95 'class': "dam-widget dam-panel"
96 }, button, innerContainer]);
97 }
98
99 ;
100 /*
101 * A select dropdown.
102 */
103
104 function makeSelect(config) {
105 var title = config.title || "";
106 var options = config.options || [];
107
108 var onchange = config.onchange || function (v) {};
109
110 var select = _dam["default"].makeElem('select');
111
112 for (var i = 0; i < options.length; i++) {
113 var op = _dam["default"].makeElem('option');
114
115 op.value = options[i].value;
116 op.text = options[i].text;
117 op.selected = !!options[i].selected;
118 select.options.add(op);
119 }
120
121 select.addEventListener('change', function (e) {
122 onchange(options[select.selectedIndex]);
123 });
124 return _dam["default"].makeElem('label', [{
125 'class': "dam-widget dam-select"
126 }, title, select]);
127 }
128
129 ;
130 /*
131 * A range control.
132 */
133
134 function makeRange(config) {
135 var title = config.title || "";
136 var min_ = config['min'];
137 var max_ = config['max'];
138 var value = config.value || min_;
139
140 var _onchange2 = config.onchange || function (v) {};
141
142 var textInputSize = config.textInputSize || 5;
143 var textInput;
144 var slider;
145 slider = _dam["default"].makeElem('input', [{
146 type: "range",
147 min: min_,
148 max: max_,
149 value: value,
150 onchange: function onchange(e) {
151 var v = parseInt(slider.value, 10);
152
153 if (!isNaN(v) && v >= min_ && v <= max_) {
154 textInput.value = "" + v;
155
156 _onchange2(v);
157 }
158 }
159 }]);
160 textInput = _dam["default"].makeElem('input', [{
161 size: "" + textInputSize,
162 value: "" + value,
163 onchange: function onchange(e) {
164 var v = parseInt(textInput.value, 10);
165
166 if (!isNaN(v) && v >= min_ && v <= max_) {
167 slider.value = "" + v;
168
169 _onchange2(v);
170 }
171 }
172 }]);
173
174 var incButton = _dam["default"].makeElem('button', ['+', {
175 onclick: function onclick(e) {
176 var v = parseInt(textInput.value, 10);
177
178 if (!isNaN(v) && v < max_) {
179 v++;
180 textInput.value = "" + v;
181 slider.value = "" + v;
182
183 _onchange2(v);
184 }
185 }
186 }]);
187
188 var decButton = _dam["default"].makeElem('button', ['-', {
189 onclick: function onclick(e) {
190 var v = parseInt(textInput.value, 10);
191
192 if (!isNaN(v) && v > min_) {
193 v--;
194 textInput.value = "" + v;
195 slider.value = "" + v;
196
197 _onchange2(v);
198 }
199 }
200 }]);
201
202 var range = _dam["default"].makeElem('span', [{
203 'class': "dam-widget dam-range"
204 }, _dam["default"].makeElem('label', [title, slider]), textInput, decButton, incButton]);
205
206 range.setValue = function (v) {
207 if (!isNaN(v) && v >= min_ && v <= max_) {
208 textInput.value = "" + v;
209 slider.value = "" + v;
210
211 _onchange2(v);
212 }
213 };
214
215 return range;
216 }
217
218 ;
219 if (typeof module !== 'undefined') module.exports = {
220 'makeCheckbox': makeCheckbox,
221 'makePanel': makePanel,
222 'makeSelect': makeSelect,
223 'makeRange': makeRange
224 };
225
226 },{"./dam.js":3}],3:[function(require,module,exports){
227 "use strict";
228
229 function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
230
231 /* dam.js version 0.2. This file is in the public domain. */
232 (function () {
233 var DAM = {};
234
235 DAM.makeElem = function (tag, args) {
236 args = args || [];
237 var elem = document.createElement(tag);
238
239 for (var i = 0; i < args.length; i++) {
240 var arg = args[i];
241
242 if (arg instanceof Element) {
243 elem.appendChild(arg);
244 } else if (typeof arg === 'string' || arg instanceof String) {
245 elem.appendChild(document.createTextNode(arg));
246 } else if (_typeof(arg) === 'object' && arg !== null) {
247 Object.keys(arg).forEach(function (key) {
248 if (key.substring(0, 2) === 'on') {
249 elem.addEventListener(key.substring(2), arg[key]);
250 } else if (arg[key] === null) {
251 elem.removeAttribute(key);
252 } else {
253 elem.setAttribute(key, arg[key]);
254 }
255 });
256 } else {
257 console.log(arg);
258 }
259 }
260
261 return elem;
262 };
263
264 DAM.maker = function (tag) {
265 return function () {
266 return DAM.makeElem(tag, arguments);
267 };
268 };
269
270 if (typeof module !== 'undefined') {
271 module.exports = DAM;
272 } else if (typeof window !== 'undefined') {
273 window.DAM = DAM;
274 }
275 })();
276
277 },{}]},{},[1]);
44 "repository": "https://github.com/catseye/DAM.git",
55 "license": "UNLICENSE",
66 "scripts": {
7 "build:dam": "mkdir -p dist && cp src/dam.js dist/dam-0.2.js",
8 "build:dam-plus-widgets-min": "mkdir -p dist && browserify src/dam-plus-widgets.js -t [ babelify --presets [ @babel/preset-env ] ] -g [ envify --NODE_ENV production ] -g uglifyify | terser --compress --mangle | uglifyjs > dist/dam-plus-widgets-0.2.min.js",
9 "build:all": "npm run build:dam && npm run build:dam-plus-widgets-min"
7 "build:dam": "cp src/dam.js dist/dam-0.2.js",
8 "minify:dam": "cat dist/dam-0.2.js | terser --compress --mangle | uglifyjs > dist/dam-0.2.min.js",
9 "build:dam-plus-widgets": "browserify src/dam-plus-widgets.js -t [ babelify --presets [ @babel/preset-env ] ] -g [ envify --NODE_ENV production ] > dist/dam-plus-widgets-0.2.js",
10 "minify:dam-plus-widgets": "cat dist/dam-plus-widgets-0.2.js | terser --compress --mangle | uglifyjs > dist/dam-plus-widgets-0.2.min.js",
11 "build:all": "npm run build:dam && npm run minify:dam && npm run build:dam-plus-widgets && npm run minify:dam-plus-widgets"
1012 },
1113 "devDependencies": {
1214 "@babel/core": "^7.5.4",