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 | function flushBuffered(destination) {
|
22 |
|
23 | }
|
24 |
|
25 | function writeChunk(destination, buffer) {
|
26 | destination.enqueue(buffer);
|
27 | return destination.desiredSize > 0;
|
28 | }
|
29 |
|
30 | function close(destination) {
|
31 | destination.close();
|
32 | }
|
33 | var textEncoder = new TextEncoder();
|
34 | function convertStringToBuffer(content) {
|
35 | return textEncoder.encode(content);
|
36 | }
|
37 |
|
38 | function formatChunkAsString(type, props) {
|
39 | var str = '<' + type + '>';
|
40 |
|
41 | if (typeof props.children === 'string') {
|
42 | str += props.children;
|
43 | }
|
44 |
|
45 | str += '</' + type + '>';
|
46 | return str;
|
47 | }
|
48 | function formatChunk(type, props) {
|
49 | return convertStringToBuffer(formatChunkAsString(type, props));
|
50 | }
|
51 |
|
52 |
|
53 |
|
54 | var hasSymbol = typeof Symbol === 'function' && Symbol.for;
|
55 | var REACT_ELEMENT_TYPE = hasSymbol ? Symbol.for('react.element') : 0xeac7;
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 | function createRequest(children, destination) {
|
65 | return {
|
66 | destination: destination,
|
67 | children: children,
|
68 | completedChunks: [],
|
69 | flowing: false
|
70 | };
|
71 | }
|
72 |
|
73 | function performWork(request) {
|
74 | var element = request.children;
|
75 | request.children = null;
|
76 |
|
77 | if (element && element.$$typeof !== REACT_ELEMENT_TYPE) {
|
78 | return;
|
79 | }
|
80 |
|
81 | var type = element.type;
|
82 | var props = element.props;
|
83 |
|
84 | if (typeof type !== 'string') {
|
85 | return;
|
86 | }
|
87 |
|
88 | request.completedChunks.push(formatChunk(type, props));
|
89 |
|
90 | if (request.flowing) {
|
91 | flushCompletedChunks(request);
|
92 | }
|
93 |
|
94 | flushBuffered(request.destination);
|
95 | }
|
96 |
|
97 | function flushCompletedChunks(request) {
|
98 | var destination = request.destination;
|
99 | var chunks = request.completedChunks;
|
100 | request.completedChunks = [];
|
101 | try {
|
102 | for (var i = 0; i < chunks.length; i++) {
|
103 | var chunk = chunks[i];
|
104 | writeChunk(destination, chunk);
|
105 | }
|
106 | } finally {
|
107 |
|
108 | }
|
109 |
|
110 | close(destination);
|
111 | }
|
112 |
|
113 | function startWork(request) {
|
114 | request.flowing = true;
|
115 | scheduleWork(function () {
|
116 | return performWork(request);
|
117 | });
|
118 | }
|
119 | function startFlowing(request) {
|
120 | request.flowing = false;
|
121 | flushCompletedChunks(request);
|
122 | }
|
123 |
|
124 |
|
125 |
|
126 |
|
127 | function renderToReadableStream(children) {
|
128 | var request;
|
129 | return new ReadableStream({
|
130 | start: function (controller) {
|
131 | request = createRequest(children, controller);
|
132 | startWork(request);
|
133 | },
|
134 | pull: function (controller) {
|
135 | startFlowing(request);
|
136 | },
|
137 | cancel: function (reason) {}
|
138 | });
|
139 | }
|
140 |
|
141 | var ReactDOMFizzServerBrowser = {
|
142 | renderToReadableStream: renderToReadableStream
|
143 | };
|
144 |
|
145 | var ReactDOMFizzServerBrowser$1 = Object.freeze({
|
146 | default: ReactDOMFizzServerBrowser
|
147 | });
|
148 |
|
149 | var ReactDOMFizzServerBrowser$2 = ( ReactDOMFizzServerBrowser$1 && ReactDOMFizzServerBrowser ) || ReactDOMFizzServerBrowser$1;
|
150 |
|
151 |
|
152 |
|
153 |
|
154 |
|
155 | var unstableFizz_browser = ReactDOMFizzServerBrowser$2.default || ReactDOMFizzServerBrowser$2;
|
156 |
|
157 | return unstableFizz_browser;
|
158 |
|
159 | })));
|