preact-render-to-string 3.7.1 → 3.8.2

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/dist/jsx.js CHANGED
@@ -1,722 +1,2 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
3
- typeof define === 'function' && define.amd ? define(factory) :
4
- (global.preactRenderToString = factory());
5
- }(this, (function () {
6
-
7
- if (typeof Symbol !== 'function') {
8
- var c = 0;
9
- Symbol = function Symbol(s) {
10
- return '@@' + s + ++c;
11
- };
12
- Symbol.for = function (s) {
13
- return '@@' + s;
14
- };
15
- }
16
-
17
- var NON_DIMENSION_PROPS = {
18
- boxFlex: 1, boxFlexGroup: 1, columnCount: 1, fillOpacity: 1, flex: 1, flexGrow: 1,
19
- flexPositive: 1, flexShrink: 1, flexNegative: 1, fontWeight: 1, lineClamp: 1, lineHeight: 1,
20
- opacity: 1, order: 1, orphans: 1, strokeOpacity: 1, widows: 1, zIndex: 1, zoom: 1
21
- };
22
-
23
- var ESC = {
24
- '<': '&lt;',
25
- '>': '&gt;',
26
- '"': '&quot;',
27
- '&': '&amp;'
28
- };
29
-
30
- var objectKeys = Object.keys || function (obj) {
31
- var keys = [];
32
- for (var i in obj) {
33
- if (obj.hasOwnProperty(i)) keys.push(i);
34
- }return keys;
35
- };
36
-
37
- var encodeEntities = function encodeEntities(s) {
38
- return String(s).replace(/[<>"&]/g, escapeChar);
39
- };
40
-
41
- var escapeChar = function escapeChar(a) {
42
- return ESC[a] || a;
43
- };
44
-
45
- var falsey = function falsey(v) {
46
- return v == null || v === false;
47
- };
48
-
49
- var memoize = function memoize(fn) {
50
- var mem = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
51
- return function (v) {
52
- return mem[v] || (mem[v] = fn(v));
53
- };
54
- };
55
-
56
- var indent = function indent(s, char) {
57
- return String(s).replace(/(\n+)/g, '$1' + (char || '\t'));
58
- };
59
-
60
- var isLargeString = function isLargeString(s, length, ignoreLines) {
61
- return String(s).length > (length || 40) || !ignoreLines && String(s).indexOf('\n') !== -1 || String(s).indexOf('<') !== -1;
62
- };
63
-
64
- function styleObjToCss(s) {
65
- var str = '';
66
- for (var prop in s) {
67
- var val = s[prop];
68
- if (val != null) {
69
- if (str) str += ' ';
70
- str += jsToCss(prop);
71
- str += ': ';
72
- str += val;
73
- if (typeof val === 'number' && !NON_DIMENSION_PROPS[prop]) {
74
- str += 'px';
75
- }
76
- str += ';';
77
- }
78
- }
79
- return str || undefined;
80
- }
81
-
82
- function hashToClassName(c) {
83
- var str = '';
84
- for (var prop in c) {
85
- if (c[prop]) {
86
- if (str) str += ' ';
87
- str += prop;
88
- }
89
- }
90
- return str;
91
- }
92
-
93
- var jsToCss = memoize(function (s) {
94
- return s.replace(/([A-Z])/g, '-$1').toLowerCase();
95
- });
96
-
97
- function assign(obj, props) {
98
- for (var i in props) {
99
- obj[i] = props[i];
100
- }return obj;
101
- }
102
-
103
- function getNodeProps(vnode) {
104
- var defaultProps = vnode.nodeName.defaultProps,
105
- props = assign({}, defaultProps || vnode.attributes);
106
- if (defaultProps) assign(props, vnode.attributes);
107
- if (vnode.children) props.children = vnode.children;
108
- return props;
109
- }
110
-
111
- var _typeof$1 = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
112
-
113
- var SHALLOW = { shallow: true };
114
-
115
- var UNNAMED = [];
116
-
117
- var EMPTY = {};
118
-
119
- var VOID_ELEMENTS = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr'];
120
-
121
- renderToString.render = renderToString;
122
-
123
- var shallowRender = function shallowRender(vnode, context) {
124
- return renderToString(vnode, context, SHALLOW);
125
- };
126
-
127
- function renderToString(vnode, context, opts, inner, isSvgMode) {
128
- var _ref = vnode || EMPTY,
129
- nodeName = _ref.nodeName,
130
- attributes = _ref.attributes,
131
- children = _ref.children,
132
- isComponent = false;
133
-
134
- context = context || {};
135
- opts = opts || {};
136
-
137
- var pretty = opts.pretty,
138
- indentChar = typeof pretty === 'string' ? pretty : '\t';
139
-
140
- if (vnode == null || typeof vnode === 'boolean') {
141
- return '';
142
- }
143
-
144
- if ((typeof vnode === 'undefined' ? 'undefined' : _typeof$1(vnode)) !== 'object' && !nodeName) {
145
- return encodeEntities(vnode);
146
- }
147
-
148
- if (typeof nodeName === 'function') {
149
- isComponent = true;
150
- if (opts.shallow && (inner || opts.renderRootComponent === false)) {
151
- nodeName = getComponentName(nodeName);
152
- } else {
153
- var props = getNodeProps(vnode),
154
- rendered = void 0;
155
-
156
- if (!nodeName.prototype || typeof nodeName.prototype.render !== 'function') {
157
- rendered = nodeName(props, context);
158
- } else {
159
- var c = new nodeName(props, context);
160
-
161
- c._disable = c.__x = true;
162
- c.props = props;
163
- c.context = context;
164
- if (c.componentWillMount) c.componentWillMount();
165
- rendered = c.render(c.props, c.state, c.context);
166
-
167
- if (c.getChildContext) {
168
- context = assign(assign({}, context), c.getChildContext());
169
- }
170
- }
171
-
172
- return renderToString(rendered, context, opts, opts.shallowHighOrder !== false);
173
- }
174
- }
175
-
176
- var s = '',
177
- html = void 0;
178
-
179
- if (attributes) {
180
- var attrs = objectKeys(attributes);
181
-
182
- if (opts && opts.sortAttributes === true) attrs.sort();
183
-
184
- for (var i = 0; i < attrs.length; i++) {
185
- var name = attrs[i],
186
- v = attributes[name];
187
- if (name === 'children') continue;
188
-
189
- if (name.match(/[\s\n\/='"\0<>]/)) continue;
190
-
191
- if (!(opts && opts.allAttributes) && (name === 'key' || name === 'ref')) continue;
192
-
193
- if (name === 'className') {
194
- if (attributes['class']) continue;
195
- name = 'class';
196
- } else if (isSvgMode && name.match(/^xlink\:?(.+)/)) {
197
- name = name.toLowerCase().replace(/^xlink\:?(.+)/, 'xlink:$1');
198
- }
199
-
200
- if (name === 'class' && v && (typeof v === 'undefined' ? 'undefined' : _typeof$1(v)) === 'object') {
201
- v = hashToClassName(v);
202
- } else if (name === 'style' && v && (typeof v === 'undefined' ? 'undefined' : _typeof$1(v)) === 'object') {
203
- v = styleObjToCss(v);
204
- }
205
-
206
- var hooked = opts.attributeHook && opts.attributeHook(name, v, context, opts, isComponent);
207
- if (hooked || hooked === '') {
208
- s += hooked;
209
- continue;
210
- }
211
-
212
- if (name === 'dangerouslySetInnerHTML') {
213
- html = v && v.__html;
214
- } else if ((v || v === 0 || v === '') && typeof v !== 'function') {
215
- if (v === true || v === '') {
216
- v = name;
217
-
218
- if (!opts || !opts.xml) {
219
- s += ' ' + name;
220
- continue;
221
- }
222
- }
223
- s += ' ' + name + '="' + encodeEntities(v) + '"';
224
- }
225
- }
226
- }
227
-
228
- var sub = s.replace(/^\n\s*/, ' ');
229
- if (sub !== s && !~sub.indexOf('\n')) s = sub;else if (pretty && ~s.indexOf('\n')) s += '\n';
230
-
231
- s = '<' + nodeName + s + '>';
232
-
233
- if (VOID_ELEMENTS.indexOf(nodeName) > -1) {
234
- s = s.replace(/>$/, ' />');
235
- }
236
-
237
- if (html) {
238
- if (pretty && isLargeString(html)) {
239
- html = '\n' + indentChar + indent(html, indentChar);
240
- }
241
- s += html;
242
- } else {
243
- var len = children && children.length,
244
- pieces = [],
245
- hasLarge = ~s.indexOf('\n');
246
- for (var _i = 0; _i < len; _i++) {
247
- var child = children[_i];
248
- if (!falsey(child)) {
249
- var childSvgMode = nodeName === 'svg' ? true : nodeName === 'foreignObject' ? false : isSvgMode,
250
- ret = renderToString(child, context, opts, true, childSvgMode);
251
- if (!hasLarge && pretty && isLargeString(ret)) hasLarge = true;
252
- if (ret) pieces.push(ret);
253
- }
254
- }
255
- if (pretty && hasLarge) {
256
- for (var _i2 = pieces.length; _i2--;) {
257
- pieces[_i2] = '\n' + indentChar + indent(pieces[_i2], indentChar);
258
- }
259
- }
260
- if (pieces.length) {
261
- s += pieces.join('');
262
- } else if (opts && opts.xml) {
263
- return s.substring(0, s.length - 1) + ' />';
264
- }
265
- }
266
-
267
- if (VOID_ELEMENTS.indexOf(nodeName) === -1) {
268
- if (pretty && ~s.indexOf('\n')) s += '\n';
269
- s += '</' + nodeName + '>';
270
- }
271
-
272
- return s;
273
- }
274
-
275
- function getComponentName(component) {
276
- return component.displayName || component !== Function && component.name || getFallbackComponentName(component);
277
- }
278
-
279
- function getFallbackComponentName(component) {
280
- var str = Function.prototype.toString.call(component),
281
- name = (str.match(/^\s*function\s+([^\( ]+)/) || EMPTY)[1];
282
- if (!name) {
283
- var index = -1;
284
- for (var i = UNNAMED.length; i--;) {
285
- if (UNNAMED[i] === component) {
286
- index = i;
287
- break;
288
- }
289
- }
290
-
291
- if (index < 0) {
292
- index = UNNAMED.push(component) - 1;
293
- }
294
- name = 'UnnamedComponent' + index;
295
- }
296
- return name;
297
- }
298
- renderToString.shallowRender = shallowRender;
299
-
300
- function interopDefault(ex) {
301
- return ex && typeof ex === 'object' && 'default' in ex ? ex['default'] : ex;
302
- }
303
-
304
- function createCommonjsModule(fn, module) {
305
- return module = { exports: {} }, fn(module, module.exports), module.exports;
306
- }
307
-
308
- var printString = createCommonjsModule(function (module) {
309
- 'use strict';
310
-
311
- var ESCAPED_CHARACTERS = /(\\|\"|\')/g;
312
-
313
- module.exports = function printString(val) {
314
- return val.replace(ESCAPED_CHARACTERS, '\\$1');
315
- };
316
- });
317
-
318
- var printString$1 = interopDefault(printString);
319
-
320
- var require$$0 = Object.freeze({
321
- default: printString$1
322
- });
323
-
324
- var _typeof$2 = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
325
-
326
- var index = createCommonjsModule(function (module) {
327
- 'use strict';
328
-
329
- var printString = interopDefault(require$$0);
330
-
331
- var toString = Object.prototype.toString;
332
- var toISOString = Date.prototype.toISOString;
333
- var errorToString = Error.prototype.toString;
334
- var regExpToString = RegExp.prototype.toString;
335
- var symbolToString = Symbol.prototype.toString;
336
-
337
- var SYMBOL_REGEXP = /^Symbol\((.*)\)(.*)$/;
338
- var NEWLINE_REGEXP = /\n/ig;
339
-
340
- var getSymbols = Object.getOwnPropertySymbols || function (obj) {
341
- return [];
342
- };
343
-
344
- function isToStringedArrayType(toStringed) {
345
- return toStringed === '[object Array]' || toStringed === '[object ArrayBuffer]' || toStringed === '[object DataView]' || toStringed === '[object Float32Array]' || toStringed === '[object Float64Array]' || toStringed === '[object Int8Array]' || toStringed === '[object Int16Array]' || toStringed === '[object Int32Array]' || toStringed === '[object Uint8Array]' || toStringed === '[object Uint8ClampedArray]' || toStringed === '[object Uint16Array]' || toStringed === '[object Uint32Array]';
346
- }
347
-
348
- function printNumber(val) {
349
- if (val != +val) return 'NaN';
350
- var isNegativeZero = val === 0 && 1 / val < 0;
351
- return isNegativeZero ? '-0' : '' + val;
352
- }
353
-
354
- function printFunction(val) {
355
- if (val.name === '') {
356
- return '[Function anonymous]';
357
- } else {
358
- return '[Function ' + val.name + ']';
359
- }
360
- }
361
-
362
- function printSymbol(val) {
363
- return symbolToString.call(val).replace(SYMBOL_REGEXP, 'Symbol($1)');
364
- }
365
-
366
- function printError(val) {
367
- return '[' + errorToString.call(val) + ']';
368
- }
369
-
370
- function printBasicValue(val) {
371
- if (val === true || val === false) return '' + val;
372
- if (val === undefined) return 'undefined';
373
- if (val === null) return 'null';
374
-
375
- var typeOf = typeof val === 'undefined' ? 'undefined' : _typeof$2(val);
376
-
377
- if (typeOf === 'number') return printNumber(val);
378
- if (typeOf === 'string') return '"' + printString(val) + '"';
379
- if (typeOf === 'function') return printFunction(val);
380
- if (typeOf === 'symbol') return printSymbol(val);
381
-
382
- var toStringed = toString.call(val);
383
-
384
- if (toStringed === '[object WeakMap]') return 'WeakMap {}';
385
- if (toStringed === '[object WeakSet]') return 'WeakSet {}';
386
- if (toStringed === '[object Function]' || toStringed === '[object GeneratorFunction]') return printFunction(val, min);
387
- if (toStringed === '[object Symbol]') return printSymbol(val);
388
- if (toStringed === '[object Date]') return toISOString.call(val);
389
- if (toStringed === '[object Error]') return printError(val);
390
- if (toStringed === '[object RegExp]') return regExpToString.call(val);
391
- if (toStringed === '[object Arguments]' && val.length === 0) return 'Arguments []';
392
- if (isToStringedArrayType(toStringed) && val.length === 0) return val.constructor.name + ' []';
393
-
394
- if (val instanceof Error) return printError(val);
395
-
396
- return false;
397
- }
398
-
399
- function printList(list, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min) {
400
- var body = '';
401
-
402
- if (list.length) {
403
- body += edgeSpacing;
404
-
405
- var innerIndent = prevIndent + indent;
406
-
407
- for (var i = 0; i < list.length; i++) {
408
- body += innerIndent + print(list[i], indent, innerIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min);
409
-
410
- if (i < list.length - 1) {
411
- body += ',' + spacing;
412
- }
413
- }
414
-
415
- body += edgeSpacing + prevIndent;
416
- }
417
-
418
- return '[' + body + ']';
419
- }
420
-
421
- function printArguments(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min) {
422
- return (min ? '' : 'Arguments ') + printList(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min);
423
- }
424
-
425
- function printArray(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min) {
426
- return (min ? '' : val.constructor.name + ' ') + printList(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min);
427
- }
428
-
429
- function printMap(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min) {
430
- var result = 'Map {';
431
- var iterator = val.entries();
432
- var current = iterator.next();
433
-
434
- if (!current.done) {
435
- result += edgeSpacing;
436
-
437
- var innerIndent = prevIndent + indent;
438
-
439
- while (!current.done) {
440
- var key = print(current.value[0], indent, innerIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min);
441
- var value = print(current.value[1], indent, innerIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min);
442
-
443
- result += innerIndent + key + ' => ' + value;
444
-
445
- current = iterator.next();
446
-
447
- if (!current.done) {
448
- result += ',' + spacing;
449
- }
450
- }
451
-
452
- result += edgeSpacing + prevIndent;
453
- }
454
-
455
- return result + '}';
456
- }
457
-
458
- function printObject(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min) {
459
- var constructor = min ? '' : val.constructor ? val.constructor.name + ' ' : 'Object ';
460
- var result = constructor + '{';
461
- var keys = Object.keys(val).sort();
462
- var symbols = getSymbols(val);
463
-
464
- if (symbols.length) {
465
- keys = keys.filter(function (key) {
466
- return !((typeof key === 'undefined' ? 'undefined' : _typeof$2(key)) === 'symbol' || toString.call(key) === '[object Symbol]');
467
- }).concat(symbols);
468
- }
469
-
470
- if (keys.length) {
471
- result += edgeSpacing;
472
-
473
- var innerIndent = prevIndent + indent;
474
-
475
- for (var i = 0; i < keys.length; i++) {
476
- var key = keys[i];
477
- var name = print(key, indent, innerIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min);
478
- var value = print(val[key], indent, innerIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min);
479
-
480
- result += innerIndent + name + ': ' + value;
481
-
482
- if (i < keys.length - 1) {
483
- result += ',' + spacing;
484
- }
485
- }
486
-
487
- result += edgeSpacing + prevIndent;
488
- }
489
-
490
- return result + '}';
491
- }
492
-
493
- function printSet(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min) {
494
- var result = 'Set {';
495
- var iterator = val.entries();
496
- var current = iterator.next();
497
-
498
- if (!current.done) {
499
- result += edgeSpacing;
500
-
501
- var innerIndent = prevIndent + indent;
502
-
503
- while (!current.done) {
504
- result += innerIndent + print(current.value[1], indent, innerIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min);
505
-
506
- current = iterator.next();
507
-
508
- if (!current.done) {
509
- result += ',' + spacing;
510
- }
511
- }
512
-
513
- result += edgeSpacing + prevIndent;
514
- }
515
-
516
- return result + '}';
517
- }
518
-
519
- function printComplexValue(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min) {
520
- refs = refs.slice();
521
- if (refs.indexOf(val) > -1) {
522
- return '[Circular]';
523
- } else {
524
- refs.push(val);
525
- }
526
-
527
- currentDepth++;
528
-
529
- var hitMaxDepth = currentDepth > maxDepth;
530
-
531
- if (!hitMaxDepth && val.toJSON && typeof val.toJSON === 'function') {
532
- return print(val.toJSON(), indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min);
533
- }
534
-
535
- var toStringed = toString.call(val);
536
- if (toStringed === '[object Arguments]') {
537
- return hitMaxDepth ? '[Arguments]' : printArguments(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min);
538
- } else if (isToStringedArrayType(toStringed)) {
539
- return hitMaxDepth ? '[Array]' : printArray(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min);
540
- } else if (toStringed === '[object Map]') {
541
- return hitMaxDepth ? '[Map]' : printMap(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min);
542
- } else if (toStringed === '[object Set]') {
543
- return hitMaxDepth ? '[Set]' : printSet(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min);
544
- } else if ((typeof val === 'undefined' ? 'undefined' : _typeof$2(val)) === 'object') {
545
- return hitMaxDepth ? '[Object]' : printObject(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min);
546
- }
547
- }
548
-
549
- function printPlugin(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min) {
550
- var match = false;
551
- var plugin = void 0;
552
-
553
- for (var p = 0; p < plugins.length; p++) {
554
- plugin = plugins[p];
555
-
556
- if (plugin.test(val)) {
557
- match = true;
558
- break;
559
- }
560
- }
561
-
562
- if (!match) {
563
- return false;
564
- }
565
-
566
- function boundPrint(val) {
567
- return print(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min);
568
- }
569
-
570
- function boundIndent(str) {
571
- var indentation = prevIndent + indent;
572
- return indentation + str.replace(NEWLINE_REGEXP, '\n' + indentation);
573
- }
574
-
575
- return plugin.print(val, boundPrint, boundIndent, {
576
- edgeSpacing: edgeSpacing,
577
- spacing: spacing
578
- });
579
- }
580
-
581
- function print(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min) {
582
- var basic = printBasicValue(val);
583
- if (basic) return basic;
584
-
585
- var plugin = printPlugin(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min);
586
- if (plugin) return plugin;
587
-
588
- return printComplexValue(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min);
589
- }
590
-
591
- var DEFAULTS = {
592
- indent: 2,
593
- min: false,
594
- maxDepth: Infinity,
595
- plugins: []
596
- };
597
-
598
- function validateOptions(opts) {
599
- Object.keys(opts).forEach(function (key) {
600
- if (!DEFAULTS.hasOwnProperty(key)) {
601
- throw new Error('prettyFormat: Invalid option: ' + key);
602
- }
603
- });
604
-
605
- if (opts.min && opts.indent !== undefined && opts.indent !== 0) {
606
- throw new Error('prettyFormat: Cannot run with min option and indent');
607
- }
608
- }
609
-
610
- function normalizeOptions(opts) {
611
- var result = {};
612
-
613
- Object.keys(DEFAULTS).forEach(function (key) {
614
- return result[key] = opts.hasOwnProperty(key) ? opts[key] : DEFAULTS[key];
615
- });
616
-
617
- if (result.min) {
618
- result.indent = 0;
619
- }
620
-
621
- return result;
622
- }
623
-
624
- function createIndent(indent) {
625
- return new Array(indent + 1).join(' ');
626
- }
627
-
628
- function prettyFormat(val, opts) {
629
- if (!opts) {
630
- opts = DEFAULTS;
631
- } else {
632
- validateOptions(opts);
633
- opts = normalizeOptions(opts);
634
- }
635
-
636
- var indent = void 0;
637
- var refs = void 0;
638
- var prevIndent = '';
639
- var currentDepth = 0;
640
- var spacing = opts.min ? ' ' : '\n';
641
- var edgeSpacing = opts.min ? '' : '\n';
642
-
643
- if (opts && opts.plugins.length) {
644
- indent = createIndent(opts.indent);
645
- refs = [];
646
- var pluginsResult = printPlugin(val, indent, prevIndent, spacing, edgeSpacing, refs, opts.maxDepth, currentDepth, opts.plugins, opts.min);
647
- if (pluginsResult) return pluginsResult;
648
- }
649
-
650
- var basicResult = printBasicValue(val);
651
- if (basicResult) return basicResult;
652
-
653
- if (!indent) indent = createIndent(opts.indent);
654
- if (!refs) refs = [];
655
- return printComplexValue(val, indent, prevIndent, spacing, edgeSpacing, refs, opts.maxDepth, currentDepth, opts.plugins, opts.min);
656
- }
657
-
658
- module.exports = prettyFormat;
659
- });
660
-
661
- var prettyFormat = interopDefault(index);
662
-
663
- var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
664
-
665
- var preactPlugin = {
666
- test: function test(object) {
667
- return object && (typeof object === 'undefined' ? 'undefined' : _typeof(object)) === 'object' && 'nodeName' in object && 'attributes' in object && 'children' in object && !('nodeType' in object);
668
- },
669
- print: function print(val, _print, indent) {
670
- return renderToString(val, preactPlugin.context, preactPlugin.opts, true);
671
- }
672
- };
673
-
674
- var prettyFormatOpts = {
675
- plugins: [preactPlugin]
676
- };
677
-
678
- function attributeHook(name, value, context, opts, isComponent) {
679
- var type = typeof value === 'undefined' ? 'undefined' : _typeof(value);
680
-
681
- if (name === 'dangerouslySetInnerHTML') return false;
682
-
683
- if (value == null || type === 'function' && !opts.functions) return '';
684
-
685
- if (opts.skipFalseAttributes && !isComponent && (value === false || (name === 'class' || name === 'style') && value === '')) return '';
686
-
687
- var indentChar = typeof opts.pretty === 'string' ? opts.pretty : '\t';
688
- if (type !== 'string') {
689
- if (type === 'function' && !opts.functionNames) {
690
- value = 'Function';
691
- } else {
692
- preactPlugin.context = context;
693
- preactPlugin.opts = opts;
694
- value = prettyFormat(value, prettyFormatOpts);
695
- if (~value.indexOf('\n')) {
696
- value = indent('\n' + value, indentChar) + '\n';
697
- }
698
- }
699
- return indent('\n' + name + '={' + value + '}', indentChar);
700
- }
701
- return '\n' + indentChar + name + '="' + encodeEntities(value) + '"';
702
- }
703
-
704
- var defaultOpts = {
705
- attributeHook: attributeHook,
706
- jsx: true,
707
- xml: false,
708
- functions: true,
709
- functionNames: true,
710
- skipFalseAttributes: true,
711
- pretty: ' '
712
- };
713
-
714
- function renderToJsxString(vnode, context, opts, inner) {
715
- opts = assign(assign({}, defaultOpts), opts || {});
716
- return renderToString(vnode, context, opts, inner);
717
- }
718
-
719
- return renderToJsxString;
720
-
721
- })));
1
+ if("function"!=typeof Symbol){var n=0;Symbol=function(t){return"@@"+t+ ++n},Symbol.for=function(n){return"@@"+n}}var t=/acit|ex(?:s|g|n|p|$)|rph|ows|mnc|ntw|ine[ch]|zoo|^ord/i,r=Object.keys||function(n){var t=[];for(var r in n)n.hasOwnProperty(r)&&t.push(r);return t},e=function(n){return String(n).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")},o=function(n,t){return String(n).replace(/(\n+)/g,"$1"+(t||"\t"))},i=function(n,t,r){return String(n).length>(t||40)||!r&&-1!==String(n).indexOf("\n")||-1!==String(n).indexOf("<")},a={};function u(n){var r="";for(var e in n){var o=n[e];null!=o&&(r&&(r+=" "),r+=a[e]||(a[e]=e.replace(/([A-Z])/g,"-$1").toLowerCase()),r+=": ",r+=o,"number"==typeof o&&!1===t.test(e)&&(r+="px"),r+=";")}return r||void 0}function c(n,t){for(var r in t)n[r]=t[r];return n}var f={shallow:!0},l=[],s=/^(area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)$/;function p(n,t,a,f,y){if(null==n||"boolean"==typeof n)return"";var b=n.nodeName,g=n.attributes,m=!1;t=t||{};var v,d=(a=a||{}).pretty,h="string"==typeof d?d:"\t";if("object"!=typeof n&&!b)return e(n);if("function"==typeof b){if(m=!0,!a.shallow||!f&&!1!==a.renderRootComponent){var j,x=function(n){var t=c({},n.attributes);t.children=n.children;var r=n.nodeName.defaultProps;if(void 0!==r)for(var e in r)void 0===t[e]&&(t[e]=r[e]);return t}(n);if(b.prototype&&"function"==typeof b.prototype.render){var S=new b(x,t);S._disable=S.__x=!0,S.props=x,S.context=t,S.componentWillMount&&S.componentWillMount(),j=S.render(S.props,S.state,S.context),S.getChildContext&&(t=c(c({},t),S.getChildContext()))}else j=b(x,t);return p(j,t,a,!1!==a.shallowHighOrder)}b=(v=b).displayName||v!==Function&&v.name||function(n){var t=(Function.prototype.toString.call(n).match(/^\s*function\s+([^( ]+)/)||"")[1];if(!t){for(var r=-1,e=l.length;e--;)if(l[e]===n){r=e;break}r<0&&(r=l.push(n)-1),t="UnnamedComponent"+r}return t}(v)}var O,A="";if(g){var w=r(g);a&&!0===a.sortAttributes&&w.sort();for(var k=0;k<w.length;k++){var F=w[k],N=g[F];if("children"!==F&&!F.match(/[\s\n\\/='"\0<>]/)&&(a&&a.allAttributes||"key"!==F&&"ref"!==F)){if("className"===F){if(g.class)continue;F="class"}else y&&F.match(/^xlink:?./)&&(F=F.toLowerCase().replace(/^xlink:?/,"xlink:"));"style"===F&&N&&"object"==typeof N&&(N=u(N));var C=a.attributeHook&&a.attributeHook(F,N,t,a,m);if(C||""===C)A+=C;else if("dangerouslySetInnerHTML"===F)O=N&&N.__html;else if((N||0===N||""===N)&&"function"!=typeof N){if(!(!0!==N&&""!==N||(N=F,a&&a.xml))){A+=" "+F;continue}A+=" "+F+'="'+e(N)+'"'}}}}var E=A.replace(/^\n\s*/," ");if(E===A||~E.indexOf("\n")?d&&~A.indexOf("\n")&&(A+="\n"):A=E,A="<"+b+A+">",String(b).match(/[\s\n\\/='"\0<>]/))throw A;var M=String(b).match(s);M&&(A=A.replace(/>$/," />"));var I=[];if(O)d&&i(O)&&(O="\n"+h+o(O,h)),A+=O;else if(n.children){for(var $=~A.indexOf("\n"),D=0;D<n.children.length;D++){var H=n.children[D];if(null!=H&&!1!==H){var W=p(H,t,a,!0,"svg"===b||"foreignObject"!==b&&y);!$&&d&&i(W)&&($=!0),W&&I.push(W)}}if(d&&$)for(var P=I.length;P--;)I[P]="\n"+h+o(I[P],h)}if(I.length)A+=I.join("");else if(a&&a.xml)return A.substring(0,A.length-1)+" />";return M||(d&&~A.indexOf("\n")&&(A+="\n"),A+="</"+b+">"),A}p.render=p,p.shallowRender=function(n,t){return p(n,t,f)};var y=/(\\|\"|\')/g,b=function(n){return n.replace(y,"\\$1")},g=Object.prototype.toString,m=Date.prototype.toISOString,v=Error.prototype.toString,d=RegExp.prototype.toString,h=Symbol.prototype.toString,j=/^Symbol\((.*)\)(.*)$/,x=/\n/gi,S=Object.getOwnPropertySymbols||function(n){return[]};function O(n){return"[object Array]"===n||"[object ArrayBuffer]"===n||"[object DataView]"===n||"[object Float32Array]"===n||"[object Float64Array]"===n||"[object Int8Array]"===n||"[object Int16Array]"===n||"[object Int32Array]"===n||"[object Uint8Array]"===n||"[object Uint8ClampedArray]"===n||"[object Uint16Array]"===n||"[object Uint32Array]"===n}function A(n){return""===n.name?"[Function anonymous]":"[Function "+n.name+"]"}function w(n){return h.call(n).replace(j,"Symbol($1)")}function k(n){return"["+v.call(n)+"]"}function F(n){if(!0===n||!1===n)return""+n;if(void 0===n)return"undefined";if(null===n)return"null";var t=typeof n;if("number"===t)return function(n){return n!=+n?"NaN":0===n&&1/n<0?"-0":""+n}(n);if("string"===t)return'"'+b(n)+'"';if("function"===t)return A(n);if("symbol"===t)return w(n);var r=g.call(n);return"[object WeakMap]"===r?"WeakMap {}":"[object WeakSet]"===r?"WeakSet {}":"[object Function]"===r||"[object GeneratorFunction]"===r?A(n,min):"[object Symbol]"===r?w(n):"[object Date]"===r?m.call(n):"[object Error]"===r?k(n):"[object RegExp]"===r?d.call(n):"[object Arguments]"===r&&0===n.length?"Arguments []":O(r)&&0===n.length?n.constructor.name+" []":n instanceof Error&&k(n)}function N(n,t,r,e,o,i,a,u,c,f){var l="";if(n.length){l+=o;for(var s=r+t,p=0;p<n.length;p++)l+=s+M(n[p],t,s,e,o,i,a,u,c,f),p<n.length-1&&(l+=","+e);l+=o+r}return"["+l+"]"}function C(n,t,r,e,o,i,a,u,c,f){if((i=i.slice()).indexOf(n)>-1)return"[Circular]";i.push(n);var l=++u>a;if(!l&&n.toJSON&&"function"==typeof n.toJSON)return M(n.toJSON(),t,r,e,o,i,a,u,c,f);var s=g.call(n);return"[object Arguments]"===s?l?"[Arguments]":function(n,t,r,e,o,i,a,u,c,f){return(f?"":"Arguments ")+N(n,t,r,e,o,i,a,u,c,f)}(n,t,r,e,o,i,a,u,c,f):O(s)?l?"[Array]":function(n,t,r,e,o,i,a,u,c,f){return(f?"":n.constructor.name+" ")+N(n,t,r,e,o,i,a,u,c,f)}(n,t,r,e,o,i,a,u,c,f):"[object Map]"===s?l?"[Map]":function(n,t,r,e,o,i,a,u,c,f){var l="Map {",s=n.entries(),p=s.next();if(!p.done){l+=o;for(var y=r+t;!p.done;)l+=y+M(p.value[0],t,y,e,o,i,a,u,c,f)+" => "+M(p.value[1],t,y,e,o,i,a,u,c,f),(p=s.next()).done||(l+=","+e);l+=o+r}return l+"}"}(n,t,r,e,o,i,a,u,c,f):"[object Set]"===s?l?"[Set]":function(n,t,r,e,o,i,a,u,c,f){var l="Set {",s=n.entries(),p=s.next();if(!p.done){l+=o;for(var y=r+t;!p.done;)l+=y+M(p.value[1],t,y,e,o,i,a,u,c,f),(p=s.next()).done||(l+=","+e);l+=o+r}return l+"}"}(n,t,r,e,o,i,a,u,c,f):"object"==typeof n?l?"[Object]":function(n,t,r,e,o,i,a,u,c,f){var l=(f?"":n.constructor?n.constructor.name+" ":"Object ")+"{",s=Object.keys(n).sort(),p=S(n);if(p.length&&(s=s.filter(function(n){return!("symbol"==typeof n||"[object Symbol]"===g.call(n))}).concat(p)),s.length){l+=o;for(var y=r+t,b=0;b<s.length;b++){var m=s[b];l+=y+M(m,t,y,e,o,i,a,u,c,f)+": "+M(n[m],t,y,e,o,i,a,u,c,f),b<s.length-1&&(l+=","+e)}l+=o+r}return l+"}"}(n,t,r,e,o,i,a,u,c,f):void 0}function E(n,t,r,e,o,i,a,u,c,f){for(var l,s=!1,p=0;p<c.length;p++)if((l=c[p]).test(n)){s=!0;break}return!!s&&l.print(n,function(n){return M(n,t,r,e,o,i,a,u,c,f)},function(n){var e=r+t;return e+n.replace(x,"\n"+e)},{edgeSpacing:o,spacing:e})}function M(n,t,r,e,o,i,a,u,c,f){var l=F(n);return l||(E(n,t,r,e,o,i,a,u,c,f)||C(n,t,r,e,o,i,a,u,c,f))}var I={indent:2,min:!1,maxDepth:Infinity,plugins:[]};function $(n){return new Array(n+1).join(" ")}var D={test:function(n){return n&&"object"==typeof n&&"nodeName"in n&&"attributes"in n&&"children"in n&&!("nodeType"in n)},print:function(n,t,r){return p(n,D.context,D.opts,!0)}},H={plugins:[D]},W={attributeHook:function(n,t,r,i,a){var u=typeof t;if("dangerouslySetInnerHTML"===n)return!1;if(null==t||"function"===u&&!i.functions)return"";if(i.skipFalseAttributes&&!a&&(!1===t||("class"===n||"style"===n)&&""===t))return"";var c="string"==typeof i.pretty?i.pretty:"\t";return"string"!==u?("function"!==u||i.functionNames?(D.context=r,D.opts=i,~(t=function(n,t){var r,e;t?(function(n){if(Object.keys(n).forEach(function(n){if(!I.hasOwnProperty(n))throw new Error("prettyFormat: Invalid option: "+n)}),n.min&&void 0!==n.indent&&0!==n.indent)throw new Error("prettyFormat: Cannot run with min option and indent")}(t),t=function(n){var t={};return Object.keys(I).forEach(function(r){return t[r]=n.hasOwnProperty(r)?n[r]:I[r]}),t.min&&(t.indent=0),t}(t)):t=I;var o=t.min?" ":"\n",i=t.min?"":"\n";if(t&&t.plugins.length){var a=E(n,r=$(t.indent),"",o,i,e=[],t.maxDepth,0,t.plugins,t.min);if(a)return a}return F(n)||(r||(r=$(t.indent)),e||(e=[]),C(n,r,"",o,i,e,t.maxDepth,0,t.plugins,t.min))}(t,H)).indexOf("\n")&&(t=o("\n"+t,c)+"\n")):t="Function",o("\n"+n+"={"+t+"}",c)):"\n"+c+n+'="'+e(t)+'"'},jsx:!0,xml:!1,functions:!0,functionNames:!0,skipFalseAttributes:!0,pretty:" "};module.exports=function(n,t,r,e){return p(n,t,r=c(c({},W),r||{}),e)};
722
2
  //# sourceMappingURL=jsx.js.map