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 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 | function createRequest(children, destination) {
|
69 | return { destination: destination, children: children, completedChunks: [], flowing: false };
|
70 | }
|
71 |
|
72 | function performWork(request) {
|
73 | var element = request.children;
|
74 | request.children = null;
|
75 | if (element && element.$$typeof !== REACT_ELEMENT_TYPE) {
|
76 | return;
|
77 | }
|
78 | var type = element.type;
|
79 | var props = element.props;
|
80 | if (typeof type !== 'string') {
|
81 | return;
|
82 | }
|
83 | request.completedChunks.push(formatChunk(type, props));
|
84 | if (request.flowing) {
|
85 | flushCompletedChunks(request);
|
86 | }
|
87 |
|
88 | flushBuffered(request.destination);
|
89 | }
|
90 |
|
91 | function flushCompletedChunks(request) {
|
92 | var destination = request.destination;
|
93 | var chunks = request.completedChunks;
|
94 | request.completedChunks = [];
|
95 |
|
96 | try {
|
97 | for (var i = 0; i < chunks.length; i++) {
|
98 | var chunk = chunks[i];
|
99 | writeChunk(destination, chunk);
|
100 | }
|
101 | } finally {
|
102 |
|
103 | }
|
104 | close(destination);
|
105 | }
|
106 |
|
107 | function startWork(request) {
|
108 | request.flowing = true;
|
109 | scheduleWork(function () {
|
110 | return performWork(request);
|
111 | });
|
112 | }
|
113 |
|
114 | function startFlowing(request, desiredBytes) {
|
115 | request.flowing = false;
|
116 | flushCompletedChunks(request);
|
117 | }
|
118 |
|
119 |
|
120 |
|
121 |
|
122 | function renderToReadableStream(children) {
|
123 | var request = void 0;
|
124 | return new ReadableStream({
|
125 | start: function (controller) {
|
126 | request = createRequest(children, controller);
|
127 | startWork(request);
|
128 | },
|
129 | pull: function (controller) {
|
130 | startFlowing(request, controller.desiredSize);
|
131 | },
|
132 | cancel: function (reason) {}
|
133 | });
|
134 | }
|
135 |
|
136 | var ReactDOMFizzServerBrowser = {
|
137 | renderToReadableStream: renderToReadableStream
|
138 | };
|
139 |
|
140 | var ReactDOMFizzServerBrowser$1 = Object.freeze({
|
141 | default: ReactDOMFizzServerBrowser
|
142 | });
|
143 |
|
144 | var ReactDOMFizzServerBrowser$2 = ( ReactDOMFizzServerBrowser$1 && ReactDOMFizzServerBrowser ) || ReactDOMFizzServerBrowser$1;
|
145 |
|
146 |
|
147 |
|
148 | var unstableFizz_browser = ReactDOMFizzServerBrowser$2.default || ReactDOMFizzServerBrowser$2;
|
149 |
|
150 | return unstableFizz_browser;
|
151 |
|
152 | })));
|