-
Notifications
You must be signed in to change notification settings - Fork 0
/
bundle.js
3003 lines (2708 loc) · 90.3 KB
/
bundle.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(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){
(function (__filename){(function (){
const bel = require('bel')
const csjs = require('csjs-inject')
const path = require('path')
const filename = path.basename(__filename)
const autocomplete = require('..')
const domlog = require('ui-domlog')
function demoComponent () {
let recipients = []
let result = fetchData('./src/data.json')
// show logs
const terminal = bel`<div class=${css.terminal}></div>`
const searchBox = autocomplete({page: 'PLANS', flow: 'search', name: 'swarm key', data: result }, protocol('swarmkey'))
// container
const container = wrap(searchBox, terminal)
return container
function wrap (content, terminal) {
const container = bel`
<div class=${css.wrap}>
<section class=${css.container}>
${content}
</section>
${terminal}
</div>
`
return container
}
function renderPublish (message) {
showLog({...message, filename, line: 31})
}
function protocol (name) {
return send => {
recipients[name] = send
return receive
}
}
function receive (message) {
const { page, from, flow, type, action, body } = message
// console.log(`DEMO <= ${page}/${from} ${type}` );
showLog(message)
if (type === 'init') return showLog({page, from, flow, type: 'ready', body, filename, line: 45})
if (type === 'clear search') return
if (type === 'publish') return renderPublish(message)
}
// keep the scroll on bottom when the log displayed on the terminal
function showLog (message) {
sendMessage(message)
.then( log => {
terminal.append(log)
terminal.scrollTop = terminal.scrollHeight
}
)}
async function fetchData (path) {
const response = await fetch(path)
if ( response.ok ) return response.json().then(data => data)
if ( response.status === 404 ) {
sendMessage({page: 'demo', from: 'data', flow: 'getData', type: 'error', body: `GET ${response.url} 404 (not found)`, filename, line: 63})
.then( log => terminal.append(log) )
// throw new Error(`Failed load file from ${response.url}`)
}
}
async function sendMessage (message) {
return await new Promise( (resolve, reject) => {
if (message === undefined) reject('no message import')
const log = domlog(message)
return resolve(log)
}).catch( err => {
throw new Error(err.message)
})
}
}
const css = csjs`
html {
font-size: 62.5%;
box-sizing: border-box;
height: 100%;
}
*, *::before, *::after {
box-sizing: inherit;
}
body {
margin: 0;
padding: 0;
font-family: Arial, Helvetica, sans-serif;
font-size: 100%;
background-color: rgba(0, 0, 0, .1);
height: 100%;
}
.wrap {
display: grid;
grid-template-columns: 1fr;
grid-template-rows: 75% 25%;
height: 100%;
}
.container {
width: 80%;
max-width: 98%;
margin: 20px auto 0 auto;
}
.terminal {
background-color: #212121;
color: #f2f2f2;
font-size: 13px;
overflow-y: auto;
}
`
document.body.append( demoComponent() )
}).call(this)}).call(this,"/demo/demo.js")
},{"..":32,"bel":3,"csjs-inject":6,"path":29,"ui-domlog":31}],2:[function(require,module,exports){
var trailingNewlineRegex = /\n[\s]+$/
var leadingNewlineRegex = /^\n[\s]+/
var trailingSpaceRegex = /[\s]+$/
var leadingSpaceRegex = /^[\s]+/
var multiSpaceRegex = /[\n\s]+/g
var TEXT_TAGS = [
'a', 'abbr', 'b', 'bdi', 'bdo', 'br', 'cite', 'data', 'dfn', 'em', 'i',
'kbd', 'mark', 'q', 'rp', 'rt', 'rtc', 'ruby', 's', 'amp', 'small', 'span',
'strong', 'sub', 'sup', 'time', 'u', 'var', 'wbr'
]
var VERBATIM_TAGS = [
'code', 'pre', 'textarea'
]
module.exports = function appendChild (el, childs) {
if (!Array.isArray(childs)) return
var nodeName = el.nodeName.toLowerCase()
var hadText = false
var value, leader
for (var i = 0, len = childs.length; i < len; i++) {
var node = childs[i]
if (Array.isArray(node)) {
appendChild(el, node)
continue
}
if (typeof node === 'number' ||
typeof node === 'boolean' ||
typeof node === 'function' ||
node instanceof Date ||
node instanceof RegExp) {
node = node.toString()
}
var lastChild = el.childNodes[el.childNodes.length - 1]
// Iterate over text nodes
if (typeof node === 'string') {
hadText = true
// If we already had text, append to the existing text
if (lastChild && lastChild.nodeName === '#text') {
lastChild.nodeValue += node
// We didn't have a text node yet, create one
} else {
node = document.createTextNode(node)
el.appendChild(node)
lastChild = node
}
// If this is the last of the child nodes, make sure we close it out
// right
if (i === len - 1) {
hadText = false
// Trim the child text nodes if the current node isn't a
// node where whitespace matters.
if (TEXT_TAGS.indexOf(nodeName) === -1 &&
VERBATIM_TAGS.indexOf(nodeName) === -1) {
value = lastChild.nodeValue
.replace(leadingNewlineRegex, '')
.replace(trailingSpaceRegex, '')
.replace(trailingNewlineRegex, '')
.replace(multiSpaceRegex, ' ')
if (value === '') {
el.removeChild(lastChild)
} else {
lastChild.nodeValue = value
}
} else if (VERBATIM_TAGS.indexOf(nodeName) === -1) {
// The very first node in the list should not have leading
// whitespace. Sibling text nodes should have whitespace if there
// was any.
leader = i === 0 ? '' : ' '
value = lastChild.nodeValue
.replace(leadingNewlineRegex, leader)
.replace(leadingSpaceRegex, ' ')
.replace(trailingSpaceRegex, '')
.replace(trailingNewlineRegex, '')
.replace(multiSpaceRegex, ' ')
lastChild.nodeValue = value
}
}
// Iterate over DOM nodes
} else if (node && node.nodeType) {
// If the last node was a text node, make sure it is properly closed out
if (hadText) {
hadText = false
// Trim the child text nodes if the current node isn't a
// text node or a code node
if (TEXT_TAGS.indexOf(nodeName) === -1 &&
VERBATIM_TAGS.indexOf(nodeName) === -1) {
value = lastChild.nodeValue
.replace(leadingNewlineRegex, '')
.replace(trailingNewlineRegex, '')
.replace(multiSpaceRegex, ' ')
// Remove empty text nodes, append otherwise
if (value === '') {
el.removeChild(lastChild)
} else {
lastChild.nodeValue = value
}
// Trim the child nodes if the current node is not a node
// where all whitespace must be preserved
} else if (VERBATIM_TAGS.indexOf(nodeName) === -1) {
value = lastChild.nodeValue
.replace(leadingSpaceRegex, ' ')
.replace(leadingNewlineRegex, '')
.replace(trailingNewlineRegex, '')
.replace(multiSpaceRegex, ' ')
lastChild.nodeValue = value
}
}
// Store the last nodename
var _nodeName = node.nodeName
if (_nodeName) nodeName = _nodeName.toLowerCase()
// Append the node to the DOM
el.appendChild(node)
}
}
}
},{}],3:[function(require,module,exports){
var hyperx = require('hyperx')
var appendChild = require('./appendChild')
var SVGNS = 'http://www.w3.org/2000/svg'
var XLINKNS = 'http://www.w3.org/1999/xlink'
var BOOL_PROPS = [
'autofocus', 'checked', 'defaultchecked', 'disabled', 'formnovalidate',
'indeterminate', 'readonly', 'required', 'selected', 'willvalidate'
]
var COMMENT_TAG = '!--'
var SVG_TAGS = [
'svg', 'altGlyph', 'altGlyphDef', 'altGlyphItem', 'animate', 'animateColor',
'animateMotion', 'animateTransform', 'circle', 'clipPath', 'color-profile',
'cursor', 'defs', 'desc', 'ellipse', 'feBlend', 'feColorMatrix',
'feComponentTransfer', 'feComposite', 'feConvolveMatrix',
'feDiffuseLighting', 'feDisplacementMap', 'feDistantLight', 'feFlood',
'feFuncA', 'feFuncB', 'feFuncG', 'feFuncR', 'feGaussianBlur', 'feImage',
'feMerge', 'feMergeNode', 'feMorphology', 'feOffset', 'fePointLight',
'feSpecularLighting', 'feSpotLight', 'feTile', 'feTurbulence', 'filter',
'font', 'font-face', 'font-face-format', 'font-face-name', 'font-face-src',
'font-face-uri', 'foreignObject', 'g', 'glyph', 'glyphRef', 'hkern', 'image',
'line', 'linearGradient', 'marker', 'mask', 'metadata', 'missing-glyph',
'mpath', 'path', 'pattern', 'polygon', 'polyline', 'radialGradient', 'rect',
'set', 'stop', 'switch', 'symbol', 'text', 'textPath', 'title', 'tref',
'tspan', 'use', 'view', 'vkern'
]
function belCreateElement (tag, props, children) {
var el
// If an svg tag, it needs a namespace
if (SVG_TAGS.indexOf(tag) !== -1) {
props.namespace = SVGNS
}
// If we are using a namespace
var ns = false
if (props.namespace) {
ns = props.namespace
delete props.namespace
}
// Create the element
if (ns) {
el = document.createElementNS(ns, tag)
} else if (tag === COMMENT_TAG) {
return document.createComment(props.comment)
} else {
el = document.createElement(tag)
}
// Create the properties
for (var p in props) {
if (props.hasOwnProperty(p)) {
var key = p.toLowerCase()
var val = props[p]
// Normalize className
if (key === 'classname') {
key = 'class'
p = 'class'
}
// The for attribute gets transformed to htmlFor, but we just set as for
if (p === 'htmlFor') {
p = 'for'
}
// If a property is boolean, set itself to the key
if (BOOL_PROPS.indexOf(key) !== -1) {
if (val === 'true') val = key
else if (val === 'false') continue
}
// If a property prefers being set directly vs setAttribute
if (key.slice(0, 2) === 'on') {
el[p] = val
} else {
if (ns) {
if (p === 'xlink:href') {
el.setAttributeNS(XLINKNS, p, val)
} else if (/^xmlns($|:)/i.test(p)) {
// skip xmlns definitions
} else {
el.setAttributeNS(null, p, val)
}
} else {
el.setAttribute(p, val)
}
}
}
}
appendChild(el, children)
return el
}
module.exports = hyperx(belCreateElement, {comments: true})
module.exports.default = module.exports
module.exports.createElement = belCreateElement
},{"./appendChild":2,"hyperx":27}],4:[function(require,module,exports){
(function (global){(function (){
'use strict';
var csjs = require('csjs');
var insertCss = require('insert-css');
function csjsInserter() {
var args = Array.prototype.slice.call(arguments);
var result = csjs.apply(null, args);
if (global.document) {
insertCss(csjs.getCss(result));
}
return result;
}
module.exports = csjsInserter;
}).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{"csjs":9,"insert-css":28}],5:[function(require,module,exports){
'use strict';
module.exports = require('csjs/get-css');
},{"csjs/get-css":8}],6:[function(require,module,exports){
'use strict';
var csjs = require('./csjs');
module.exports = csjs;
module.exports.csjs = csjs;
module.exports.getCss = require('./get-css');
},{"./csjs":4,"./get-css":5}],7:[function(require,module,exports){
'use strict';
module.exports = require('./lib/csjs');
},{"./lib/csjs":13}],8:[function(require,module,exports){
'use strict';
module.exports = require('./lib/get-css');
},{"./lib/get-css":17}],9:[function(require,module,exports){
'use strict';
var csjs = require('./csjs');
module.exports = csjs();
module.exports.csjs = csjs;
module.exports.noScope = csjs({ noscope: true });
module.exports.getCss = require('./get-css');
},{"./csjs":7,"./get-css":8}],10:[function(require,module,exports){
'use strict';
/**
* base62 encode implementation based on base62 module:
* https://github.com/andrew/base62.js
*/
var CHARS = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
module.exports = function encode(integer) {
if (integer === 0) {
return '0';
}
var str = '';
while (integer > 0) {
str = CHARS[integer % 62] + str;
integer = Math.floor(integer / 62);
}
return str;
};
},{}],11:[function(require,module,exports){
'use strict';
var makeComposition = require('./composition').makeComposition;
module.exports = function createExports(classes, keyframes, compositions) {
var keyframesObj = Object.keys(keyframes).reduce(function(acc, key) {
var val = keyframes[key];
acc[val] = makeComposition([key], [val], true);
return acc;
}, {});
var exports = Object.keys(classes).reduce(function(acc, key) {
var val = classes[key];
var composition = compositions[key];
var extended = composition ? getClassChain(composition) : [];
var allClasses = [key].concat(extended);
var unscoped = allClasses.map(function(name) {
return classes[name] ? classes[name] : name;
});
acc[val] = makeComposition(allClasses, unscoped);
return acc;
}, keyframesObj);
return exports;
}
function getClassChain(obj) {
var visited = {}, acc = [];
function traverse(obj) {
return Object.keys(obj).forEach(function(key) {
if (!visited[key]) {
visited[key] = true;
acc.push(key);
traverse(obj[key]);
}
});
}
traverse(obj);
return acc;
}
},{"./composition":12}],12:[function(require,module,exports){
'use strict';
module.exports = {
makeComposition: makeComposition,
isComposition: isComposition,
ignoreComposition: ignoreComposition
};
/**
* Returns an immutable composition object containing the given class names
* @param {array} classNames - The input array of class names
* @return {Composition} - An immutable object that holds multiple
* representations of the class composition
*/
function makeComposition(classNames, unscoped, isAnimation) {
var classString = classNames.join(' ');
return Object.create(Composition.prototype, {
classNames: { // the original array of class names
value: Object.freeze(classNames),
configurable: false,
writable: false,
enumerable: true
},
unscoped: { // the original array of class names
value: Object.freeze(unscoped),
configurable: false,
writable: false,
enumerable: true
},
className: { // space-separated class string for use in HTML
value: classString,
configurable: false,
writable: false,
enumerable: true
},
selector: { // comma-separated, period-prefixed string for use in CSS
value: classNames.map(function(name) {
return isAnimation ? name : '.' + name;
}).join(', '),
configurable: false,
writable: false,
enumerable: true
},
toString: { // toString() method, returns class string for use in HTML
value: function() {
return classString;
},
configurable: false,
writeable: false,
enumerable: false
}
});
}
/**
* Returns whether the input value is a Composition
* @param value - value to check
* @return {boolean} - whether value is a Composition or not
*/
function isComposition(value) {
return value instanceof Composition;
}
function ignoreComposition(values) {
return values.reduce(function(acc, val) {
if (isComposition(val)) {
val.classNames.forEach(function(name, i) {
acc[name] = val.unscoped[i];
});
}
return acc;
}, {});
}
/**
* Private constructor for use in `instanceof` checks
*/
function Composition() {}
},{}],13:[function(require,module,exports){
'use strict';
var extractExtends = require('./css-extract-extends');
var composition = require('./composition');
var isComposition = composition.isComposition;
var ignoreComposition = composition.ignoreComposition;
var buildExports = require('./build-exports');
var scopify = require('./scopeify');
var cssKey = require('./css-key');
var extractExports = require('./extract-exports');
module.exports = function csjsTemplate(opts) {
opts = (typeof opts === 'undefined') ? {} : opts;
var noscope = (typeof opts.noscope === 'undefined') ? false : opts.noscope;
return function csjsHandler(strings, values) {
// Fast path to prevent arguments deopt
var values = Array(arguments.length - 1);
for (var i = 1; i < arguments.length; i++) {
values[i - 1] = arguments[i];
}
var css = joiner(strings, values.map(selectorize));
var ignores = ignoreComposition(values);
var scope = noscope ? extractExports(css) : scopify(css, ignores);
var extracted = extractExtends(scope.css);
var localClasses = without(scope.classes, ignores);
var localKeyframes = without(scope.keyframes, ignores);
var compositions = extracted.compositions;
var exports = buildExports(localClasses, localKeyframes, compositions);
return Object.defineProperty(exports, cssKey, {
enumerable: false,
configurable: false,
writeable: false,
value: extracted.css
});
}
}
/**
* Replaces class compositions with comma seperated class selectors
* @param value - the potential class composition
* @return - the original value or the selectorized class composition
*/
function selectorize(value) {
return isComposition(value) ? value.selector : value;
}
/**
* Joins template string literals and values
* @param {array} strings - array of strings
* @param {array} values - array of values
* @return {string} - strings and values joined
*/
function joiner(strings, values) {
return strings.map(function(str, i) {
return (i !== values.length) ? str + values[i] : str;
}).join('');
}
/**
* Returns first object without keys of second
* @param {object} obj - source object
* @param {object} unwanted - object with unwanted keys
* @return {object} - first object without unwanted keys
*/
function without(obj, unwanted) {
return Object.keys(obj).reduce(function(acc, key) {
if (!unwanted[key]) {
acc[key] = obj[key];
}
return acc;
}, {});
}
},{"./build-exports":11,"./composition":12,"./css-extract-extends":14,"./css-key":15,"./extract-exports":16,"./scopeify":22}],14:[function(require,module,exports){
'use strict';
var makeComposition = require('./composition').makeComposition;
var regex = /\.([^\s]+)(\s+)(extends\s+)(\.[^{]+)/g;
module.exports = function extractExtends(css) {
var found, matches = [];
while (found = regex.exec(css)) {
matches.unshift(found);
}
function extractCompositions(acc, match) {
var extendee = getClassName(match[1]);
var keyword = match[3];
var extended = match[4];
// remove from output css
var index = match.index + match[1].length + match[2].length;
var len = keyword.length + extended.length;
acc.css = acc.css.slice(0, index) + " " + acc.css.slice(index + len + 1);
var extendedClasses = splitter(extended);
extendedClasses.forEach(function(className) {
if (!acc.compositions[extendee]) {
acc.compositions[extendee] = {};
}
if (!acc.compositions[className]) {
acc.compositions[className] = {};
}
acc.compositions[extendee][className] = acc.compositions[className];
});
return acc;
}
return matches.reduce(extractCompositions, {
css: css,
compositions: {}
});
};
function splitter(match) {
return match.split(',').map(getClassName);
}
function getClassName(str) {
var trimmed = str.trim();
return trimmed[0] === '.' ? trimmed.substr(1) : trimmed;
}
},{"./composition":12}],15:[function(require,module,exports){
'use strict';
/**
* CSS identifiers with whitespace are invalid
* Hence this key will not cause a collision
*/
module.exports = ' css ';
},{}],16:[function(require,module,exports){
'use strict';
var regex = require('./regex');
var classRegex = regex.classRegex;
var keyframesRegex = regex.keyframesRegex;
module.exports = extractExports;
function extractExports(css) {
return {
css: css,
keyframes: getExport(css, keyframesRegex),
classes: getExport(css, classRegex)
};
}
function getExport(css, regex) {
var prop = {};
var match;
while((match = regex.exec(css)) !== null) {
var name = match[2];
prop[name] = name;
}
return prop;
}
},{"./regex":19}],17:[function(require,module,exports){
'use strict';
var cssKey = require('./css-key');
module.exports = function getCss(csjs) {
return csjs[cssKey];
};
},{"./css-key":15}],18:[function(require,module,exports){
'use strict';
/**
* djb2 string hash implementation based on string-hash module:
* https://github.com/darkskyapp/string-hash
*/
module.exports = function hashStr(str) {
var hash = 5381;
var i = str.length;
while (i) {
hash = (hash * 33) ^ str.charCodeAt(--i)
}
return hash >>> 0;
};
},{}],19:[function(require,module,exports){
'use strict';
var findClasses = /(\.)(?!\d)([^\s\.,{\[>+~#:)]*)(?![^{]*})/.source;
var findKeyframes = /(@\S*keyframes\s*)([^{\s]*)/.source;
var ignoreComments = /(?!(?:[^*/]|\*[^/]|\/[^*])*\*+\/)/.source;
var classRegex = new RegExp(findClasses + ignoreComments, 'g');
var keyframesRegex = new RegExp(findKeyframes + ignoreComments, 'g');
module.exports = {
classRegex: classRegex,
keyframesRegex: keyframesRegex,
ignoreComments: ignoreComments,
};
},{}],20:[function(require,module,exports){
var ignoreComments = require('./regex').ignoreComments;
module.exports = replaceAnimations;
function replaceAnimations(result) {
var animations = Object.keys(result.keyframes).reduce(function(acc, key) {
acc[result.keyframes[key]] = key;
return acc;
}, {});
var unscoped = Object.keys(animations);
if (unscoped.length) {
var regexStr = '((?:animation|animation-name)\\s*:[^};]*)('
+ unscoped.join('|') + ')([;\\s])' + ignoreComments;
var regex = new RegExp(regexStr, 'g');
var replaced = result.css.replace(regex, function(match, preamble, name, ending) {
return preamble + animations[name] + ending;
});
return {
css: replaced,
keyframes: result.keyframes,
classes: result.classes
}
}
return result;
}
},{"./regex":19}],21:[function(require,module,exports){
'use strict';
var encode = require('./base62-encode');
var hash = require('./hash-string');
module.exports = function fileScoper(fileSrc) {
var suffix = encode(hash(fileSrc));
return function scopedName(name) {
return name + '_' + suffix;
}
};
},{"./base62-encode":10,"./hash-string":18}],22:[function(require,module,exports){
'use strict';
var fileScoper = require('./scoped-name');
var replaceAnimations = require('./replace-animations');
var regex = require('./regex');
var classRegex = regex.classRegex;
var keyframesRegex = regex.keyframesRegex;
module.exports = scopify;
function scopify(css, ignores) {
var makeScopedName = fileScoper(css);
var replacers = {
classes: classRegex,
keyframes: keyframesRegex
};
function scopeCss(result, key) {
var replacer = replacers[key];
function replaceFn(fullMatch, prefix, name) {
var scopedName = ignores[name] ? name : makeScopedName(name);
result[key][scopedName] = name;
return prefix + scopedName;
}
return {
css: result.css.replace(replacer, replaceFn),
keyframes: result.keyframes,
classes: result.classes
};
}
var result = Object.keys(replacers).reduce(scopeCss, {
css: css,
keyframes: {},
classes: {}
});
return replaceAnimations(result);
}
},{"./regex":19,"./replace-animations":20,"./scoped-name":21}],23:[function(require,module,exports){
(function (__filename){(function (){
const bel = require('bel')
const csjs = require('csjs-inject')
const path = require('path')
const filename = path.basename(__filename)
module.exports = button
function button ({page, flow = null, name, content, style, color, custom, current, disabled = false}, protocol) {
const widget = 'ui-button'
const send2Parent = protocol( receive )
send2Parent({page, from: name, flow: flow ? `${flow}/${widget}` : widget, type: 'init', filename, line: 11})
let state
let button = bel`<button role="button" class="${css.btn} ${ checkStyle() } ${color ? css[color] : ''} ${custom ? custom.join(' ') : ''} ${current ? css.current : '' }" name=${name} aria-label=${name} disabled=${disabled}>${content}</button>`
button.onclick = click
return button
function checkStyle() {
let arr = []
if (Array.isArray(style)) {
for (let i = 0; i < style.length; i++) {
arr.push(css[style[i]])
}
return arr.join(' ')
}
return css[style]
}
function click(e) {
let x = e.clientX - e.target.offsetLeft
let y = e.clientY - e.target.offsetTop
let ripple = document.createElement('span')
ripple.classList.add(css.ripple)
ripple.style.left = `${x}px`
ripple.style.top = `${y}px`
button.append(ripple)
setTimeout( () => { ripple.remove() }, 600)
send2Parent({page, from: name, flow: flow ? `${flow}/${widget}` : widget, type: 'click', filename, line: 40})
}
function setState(update) {
return state = update
}
function toggleActive (isActive, message) {
const { page, from, flow } = message
let newState = isActive ? setState('self-active') : setState('remove-active')
button.classList.toggle(css.active)
return send2Parent({page, flow, from, type: 'state', body: newState, filename, line: 51})
}
function receive(message) {
const { type } = message
// console.log('received from main component', message )
if ( type === 'current-active' ) button.classList.add(css.current)
if ( type === 'remove-current' ) button.classList.remove(css.current)
if ( type === 'disabled' ) button.setAttribute('disabled', true)
if ( type === 'active' ) toggleActive(true, message)
if ( type === 'remove-active' ) toggleActive(false, message)
}
}
const css = csjs`
.btn {
position: relative;
border: none;
background: transparent;
padding: 15px 20px;
font-size: 14px;
cursor: pointer;
outline: none;
overflow: hidden;
transition: color .3s, background-color .3s, border .3s ease-in-out;
}
.btn svg g {
transition: fill .3s linear;
}
.solid {
color: #fff;
font-weight: bold;
border-radius: 8px;
}
.solid:hover {
background-color: rgba(0, 0, 0, .8);
}
.solid [class^="icon"] path {
stroke: #fff;
}
.outlined {
border-radius: 8px;
}
.circle-solid {
border-radius: 100%;
}
.circle-solid:hover {
border-radius: 100%;
background-color: #333;
}
.default {
border-radius: 8px;
background-color: transparent;
}
.fill-grey svg g {
fill: #BBBBBB;
}
.fill-grey:hover {
background-color: rgba(0, 0, 0, .75);
}
.fill-grey:hover svg g {
fill: #fff;
}
.fill-dark svg g {
fill: #333;
}
.fill-dark:hover {
background-color: rgba(255,255,255, .5);
}
.fill-white svg g {
fill: #fff;
}
.fill-white:hover {
background-color: rgba(188,188,188, .5);
}
.stroke-black path {
stroke: #000;
}
.stroke-grey path {
stroke: #BBB;
}
.link {}
.link:hover {
color: rgba(0, 0, 0, .6);
}
.link-black {
color: #000;
}
.link-white {
color: #fff;
}
.link-blue {
color: #4BAFFF;
}
.link-blue:hover {
color: #008af9;
}
.link-grey {