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