1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | 'use strict';
|
11 |
|
12 | (function (global, factory) {
|
13 | typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
14 | typeof define === 'function' && define.amd ? define(factory) :
|
15 | (global.ReactDOMFizzServer = factory());
|
16 | }(this, (function () { 'use strict';
|
17 |
|
18 | function scheduleWork(callback) {
|
19 | callback();
|
20 | }
|
21 |
|
22 | function flushBuffered(destination) {
|
23 |
|
24 |
|
25 | }
|
26 |
|
27 |
|
28 |
|
29 | function writeChunk(destination, buffer) {
|
30 | destination.enqueue(buffer);
|
31 | }
|
32 |
|
33 |
|
34 |
|
35 | function close(destination) {
|
36 | destination.close();
|
37 | }
|
38 |
|
39 | var textEncoder = new TextEncoder();
|
40 |
|
41 | function convertStringToBuffer(content) {
|
42 | return textEncoder.encode(content);
|
43 | }
|
44 |
|
45 | function formatChunk(type, props) {
|
46 | var str = '<' + type + '>';
|
47 | if (typeof props.children === 'string') {
|
48 | str += props.children;
|
49 | }
|
50 | str += '</' + type + '>';
|
51 | return convertStringToBuffer(str);
|
52 | }
|
53 |
|
54 |
|
55 |
|
56 | var hasSymbol = typeof Symbol === 'function' && Symbol.for;
|
57 |
|
58 | var REACT_ELEMENT_TYPE = hasSymbol ? Symbol.for('react.element') : 0xeac7;
|
59 |
|
60 | function createRequest(children, destination) {
|
61 | return { destination: destination, children: children, completedChunks: [], flowing: false };
|
62 | }
|
63 |
|
64 | function performWork(request) {
|
65 | var element = request.children;
|
66 | request.children = null;
|
67 | if (element && element.$$typeof !== REACT_ELEMENT_TYPE) {
|
68 | return;
|
69 | }
|
70 | var type = element.type;
|
71 | var props = element.props;
|
72 | if (typeof type !== 'string') {
|
73 | return;
|
74 | }
|
75 | request.completedChunks.push(formatChunk(type, props));
|
76 | if (request.flowing) {
|
77 | flushCompletedChunks(request);
|
78 | }
|
79 |
|
80 | flushBuffered(request.destination);
|
81 | }
|
82 |
|
83 | function flushCompletedChunks(request) {
|
84 | var destination = request.destination;
|
85 | var chunks = request.completedChunks;
|
86 | request.completedChunks = [];
|
87 |
|
88 | try {
|
89 | for (var i = 0; i < chunks.length; i++) {
|
90 | var chunk = chunks[i];
|
91 | writeChunk(destination, chunk);
|
92 | }
|
93 | } finally {
|
94 |
|
95 | }
|
96 | close(destination);
|
97 | }
|
98 |
|
99 | function startWork(request) {
|
100 | request.flowing = true;
|
101 | scheduleWork(function () {
|
102 | return performWork(request);
|
103 | });
|
104 | }
|
105 |
|
106 | function startFlowing(request, desiredBytes) {
|
107 | request.flowing = false;
|
108 | flushCompletedChunks(request);
|
109 | }
|
110 |
|
111 |
|
112 |
|
113 |
|
114 | function renderToReadableStream(children) {
|
115 | var request = void 0;
|
116 | return new ReadableStream({
|
117 | start: function (controller) {
|
118 | request = createRequest(children, controller);
|
119 | startWork(request);
|
120 | },
|
121 | pull: function (controller) {
|
122 | startFlowing(request, controller.desiredSize);
|
123 | },
|
124 | cancel: function (reason) {}
|
125 | });
|
126 | }
|
127 |
|
128 | var ReactDOMFizzServerBrowser = {
|
129 | renderToReadableStream: renderToReadableStream
|
130 | };
|
131 |
|
132 | var ReactDOMFizzServerBrowser$1 = Object.freeze({
|
133 | default: ReactDOMFizzServerBrowser
|
134 | });
|
135 |
|
136 | var ReactDOMFizzServerBrowser$2 = ( ReactDOMFizzServerBrowser$1 && ReactDOMFizzServerBrowser ) || ReactDOMFizzServerBrowser$1;
|
137 |
|
138 |
|
139 |
|
140 | var unstableFizz_browser = ReactDOMFizzServerBrowser$2.default || ReactDOMFizzServerBrowser$2;
|
141 |
|
142 | return unstableFizz_browser;
|
143 |
|
144 | })));
|