git.iko.soy/rowtype-yoga/next-purs-rsc
on main help sign in
rowtype-yoga/next-purs-rsc/purescript-rsc-loader.js
480 lines 13 kB history raw
1var __create = Object.create;
2var __getProtoOf = Object.getPrototypeOf;
3var __defProp = Object.defineProperty;
4var __getOwnPropNames = Object.getOwnPropertyNames;
5var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6var __hasOwnProp = Object.prototype.hasOwnProperty;
7var __toESM = (mod, isNodeMode, target) => {
8 target = mod != null ? __create(__getProtoOf(mod)) : {};
9 const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
10 for (let key of __getOwnPropNames(mod))
11 if (!__hasOwnProp.call(to, key))
12 __defProp(to, key, {
13 get: () => mod[key],
14 enumerable: true
15 });
16 return to;
17};
18var __moduleCache = /* @__PURE__ */ new WeakMap;
19var __toCommonJS = (from) => {
20 var entry = __moduleCache.get(from), desc;
21 if (entry)
22 return entry;
23 entry = __defProp({}, "__esModule", { value: true });
24 if (from && typeof from === "object" || typeof from === "function")
25 __getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
26 get: () => from[key],
27 enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
28 }));
29 __moduleCache.set(from, entry);
30 return entry;
31};
32var __export = (target, all) => {
33 for (var name in all)
34 __defProp(target, name, {
35 get: all[name],
36 enumerable: true,
37 configurable: true,
38 set: (newValue) => all[name] = () => newValue
39 });
40};
42// loader-entry.js
43var exports_loader_entry = {};
44__export(exports_loader_entry, {
45 default: () => loader_entry_default
46});
47module.exports = __toCommonJS(exports_loader_entry);
49// output-loader/Loader.Plugin/foreign.js
50var import_fs = __toESM(require("fs"));
51var import_path = __toESM(require("path"));
52var import_unplugin = require("unplugin");
53var cache = null;
54var mtime = 0;
55var loadDirectivesImpl = () => {
56 const rootDir = process.cwd();
57 const manifestPath = import_path.default.join(rootDir, "output", "directives.json");
58 if (!import_fs.default.existsSync(manifestPath))
59 return;
60 const stat = import_fs.default.statSync(manifestPath);
61 if (stat.mtimeMs === mtime)
62 return;
63 mtime = stat.mtimeMs;
64 cache = JSON.parse(import_fs.default.readFileSync(manifestPath, "utf-8"));
65 console.log("[purescript-rsc] Loaded directives:", cache);
66};
67var lookupDirectiveImpl = (nothing) => (just) => (moduleName) => () => {
68 if (!cache)
69 return nothing;
70 const entry = cache[moduleName];
71 if (!entry)
72 return nothing;
73 const d = typeof entry === "string" ? entry : entry.directive;
74 return d ? just(d) : nothing;
75};
76var lookupImportsImpl = (moduleName) => () => {
77 if (!cache)
78 return [];
79 const entry = cache[moduleName];
80 if (!entry || typeof entry === "string")
81 return [];
82 return entry.imports || [];
83};
84var extractModuleImpl = (nothing) => (just) => (id) => {
85 const match = id.match(/output[/\\]([^/\\]+)[/\\]index\.js$/);
86 return match ? just(match[1]) : nothing;
87};
88var createPluginImpl = (transformFn) => {
89 const unplugin = import_unplugin.createUnplugin(() => ({
90 name: "purescript-rsc",
91 transform: {
92 filter: { id: /output[/\\].*[/\\]index\.js$/ },
93 handler(code, id) {
94 return transformFn(id)(code)();
95 }
96 }
97 }));
98 function raw(source) {
99 return transformFn(this.resourcePath)(source)();
100 }
101 raw.webpack = unplugin.webpack;
102 raw.vite = unplugin.vite;
103 raw.rollup = unplugin.rollup;
104 raw.esbuild = unplugin.esbuild;
105 return raw;
106};
108// output-loader/Data.Array/foreign.js
109var replicateFill = function(count, value) {
110 if (count < 1) {
111 return [];
112 }
113 var result = new Array(count);
114 return result.fill(value);
115};
116var replicatePolyfill = function(count, value) {
117 var result = [];
118 var n = 0;
119 for (var i = 0;i < count; i++) {
120 result[n++] = value;
121 }
122 return result;
123};
124var replicateImpl = typeof Array.prototype.fill === "function" ? replicateFill : replicatePolyfill;
125var fromFoldableImpl = function() {
126 function Cons(head, tail) {
127 this.head = head;
128 this.tail = tail;
129 }
130 var emptyList = {};
131 function curryCons(head) {
132 return function(tail) {
133 return new Cons(head, tail);
134 };
135 }
136 function listToArray(list) {
137 var result = [];
138 var count = 0;
139 var xs = list;
140 while (xs !== emptyList) {
141 result[count++] = xs.head;
142 xs = xs.tail;
143 }
144 return result;
145 }
146 return function(foldr, xs) {
147 return listToArray(foldr(curryCons)(emptyList)(xs));
148 };
149}();
150var length = function(xs) {
151 return xs.length;
152};
153var sortByImpl = function() {
154 function mergeFromTo(compare, fromOrdering, xs1, xs2, from, to) {
155 var mid;
156 var i;
157 var j;
158 var k;
159 var x;
160 var y;
161 var c;
162 mid = from + (to - from >> 1);
163 if (mid - from > 1)
164 mergeFromTo(compare, fromOrdering, xs2, xs1, from, mid);
165 if (to - mid > 1)
166 mergeFromTo(compare, fromOrdering, xs2, xs1, mid, to);
167 i = from;
168 j = mid;
169 k = from;
170 while (i < mid && j < to) {
171 x = xs2[i];
172 y = xs2[j];
173 c = fromOrdering(compare(x)(y));
174 if (c > 0) {
175 xs1[k++] = y;
176 ++j;
177 } else {
178 xs1[k++] = x;
179 ++i;
180 }
181 }
182 while (i < mid) {
183 xs1[k++] = xs2[i++];
184 }
185 while (j < to) {
186 xs1[k++] = xs2[j++];
187 }
188 }
189 return function(compare, fromOrdering, xs) {
190 var out;
191 if (xs.length < 2)
192 return xs;
193 out = xs.slice(0);
194 mergeFromTo(compare, fromOrdering, out, xs.slice(0), 0, xs.length);
195 return out;
196 };
197}();
199// output-loader/Data.Functor/foreign.js
200var arrayMap = function(f) {
201 return function(arr) {
202 var l = arr.length;
203 var result = new Array(l);
204 for (var i = 0;i < l; i++) {
205 result[i] = f(arr[i]);
206 }
207 return result;
208 };
209};
210// output-loader/Data.Functor/index.js
211var map = function(dict) {
212 return dict.map;
213};
214var mapFlipped = function(dictFunctor) {
215 var map1 = map(dictFunctor);
216 return function(fa) {
217 return function(f) {
218 return map1(f)(fa);
219 };
220 };
221};
222var functorArray = {
223 map: arrayMap
224};
225// output-loader/Control.Bind/foreign.js
226var arrayBind = typeof Array.prototype.flatMap === "function" ? function(arr) {
227 return function(f) {
228 return arr.flatMap(f);
229 };
230} : function(arr) {
231 return function(f) {
232 var result = [];
233 var l = arr.length;
234 for (var i = 0;i < l; i++) {
235 var xs = f(arr[i]);
236 var k = xs.length;
237 for (var j = 0;j < k; j++) {
238 result.push(xs[j]);
239 }
240 }
241 return result;
242 };
243};
244// output-loader/Data.Bounded/foreign.js
245var topChar = String.fromCharCode(65535);
246var bottomChar = String.fromCharCode(0);
247var topNumber = Number.POSITIVE_INFINITY;
248var bottomNumber = Number.NEGATIVE_INFINITY;
249// output-loader/Data.Show/foreign.js
250var showIntImpl = function(n) {
251 return n.toString();
252};
253var showStringImpl = function(s) {
254 var l = s.length;
255 return '"' + s.replace(/[\0-\x1F\x7F"\\]/g, function(c, i) {
256 switch (c) {
257 case '"':
258 case "\\":
259 return "\\" + c;
260 case "\x07":
261 return "\\a";
262 case "\b":
263 return "\\b";
264 case "\f":
265 return "\\f";
266 case `
267`:
268 return "\\n";
269 case "\r":
270 return "\\r";
271 case "\t":
272 return "\\t";
273 case "\v":
274 return "\\v";
275 }
276 var k = i + 1;
277 var empty = k < l && s[k] >= "0" && s[k] <= "9" ? "\\&" : "";
278 return "\\" + c.charCodeAt(0).toString(10) + empty;
279 }) + '"';
280};
282// output-loader/Data.Show/index.js
283var showString = {
284 show: showStringImpl
285};
286var showInt = {
287 show: showIntImpl
288};
289var show = function(dict) {
290 return dict.show;
291};
293// output-loader/Data.Maybe/index.js
294var Nothing = /* @__PURE__ */ function() {
295 function Nothing2() {}
296 Nothing2.value = new Nothing2;
297 return Nothing2;
298}();
299var Just = /* @__PURE__ */ function() {
300 function Just2(value0) {
301 this.value0 = value0;
302 }
303 Just2.create = function(value0) {
304 return new Just2(value0);
305 };
306 return Just2;
307}();
308// output-loader/Data.Array.ST/foreign.js
309var sortByImpl2 = function() {
310 function mergeFromTo(compare2, fromOrdering, xs1, xs2, from, to) {
311 var mid;
312 var i;
313 var j;
314 var k;
315 var x;
316 var y;
317 var c;
318 mid = from + (to - from >> 1);
319 if (mid - from > 1)
320 mergeFromTo(compare2, fromOrdering, xs2, xs1, from, mid);
321 if (to - mid > 1)
322 mergeFromTo(compare2, fromOrdering, xs2, xs1, mid, to);
323 i = from;
324 j = mid;
325 k = from;
326 while (i < mid && j < to) {
327 x = xs2[i];
328 y = xs2[j];
329 c = fromOrdering(compare2(x)(y));
330 if (c > 0) {
331 xs1[k++] = y;
332 ++j;
333 } else {
334 xs1[k++] = x;
335 ++i;
336 }
337 }
338 while (i < mid) {
339 xs1[k++] = xs2[i++];
340 }
341 while (j < to) {
342 xs1[k++] = xs2[j++];
343 }
344 }
345 return function(compare2, fromOrdering, xs) {
346 if (xs.length < 2)
347 return xs;
348 mergeFromTo(compare2, fromOrdering, xs, xs.slice(0), 0, xs.length);
349 return xs;
350 };
351}();
352// output-loader/Data.Traversable/foreign.js
353var traverseArrayImpl = function() {
354 function array1(a) {
355 return [a];
356 }
357 function array2(a) {
358 return function(b) {
359 return [a, b];
360 };
361 }
362 function array3(a) {
363 return function(b) {
364 return function(c) {
365 return [a, b, c];
366 };
367 };
368 }
369 function concat2(xs) {
370 return function(ys) {
371 return xs.concat(ys);
372 };
373 }
374 return function(apply2) {
375 return function(map2) {
376 return function(pure2) {
377 return function(f) {
378 return function(array) {
379 function go(bot, top2) {
380 switch (top2 - bot) {
381 case 0:
382 return pure2([]);
383 case 1:
384 return map2(array1)(f(array[bot]));
385 case 2:
386 return apply2(map2(array2)(f(array[bot])))(f(array[bot + 1]));
387 case 3:
388 return apply2(apply2(map2(array3)(f(array[bot])))(f(array[bot + 1])))(f(array[bot + 2]));
389 default:
390 var pivot = bot + Math.floor((top2 - bot) / 4) * 2;
391 return apply2(map2(concat2)(go(bot, pivot)))(go(pivot, top2));
392 }
393 }
394 return go(0, array.length);
395 };
396 };
397 };
398 };
399 };
400}();
401// output-loader/Data.String.Common/foreign.js
402var joinWith = function(s) {
403 return function(xs) {
404 return xs.join(s);
405 };
406};
408// output-loader/Data.String.Common/index.js
409var $$null = function(s) {
410 return s === "";
411};
413// output-loader/Effect.Console/foreign.js
414var log = function(s) {
415 return function() {
416 console.log(s);
417 };
418};
419// output-loader/Loader.Plugin/index.js
420var show2 = /* @__PURE__ */ show(showString);
421var mapFlipped2 = /* @__PURE__ */ mapFlipped(functorArray);
422var show1 = /* @__PURE__ */ show(showInt);
423var lookupImports = lookupImportsImpl;
424var lookupDirective = /* @__PURE__ */ function() {
425 return lookupDirectiveImpl(Nothing.value)(Just.create);
426}();
427var extractModule = /* @__PURE__ */ function() {
428 return extractModuleImpl(Nothing.value)(Just.create);
429}();
430var transform = function(id) {
431 return function(source) {
432 return function __do() {
433 loadDirectivesImpl();
434 var v = extractModule(id);
435 if (v instanceof Nothing) {
436 return source;
437 }
438 if (v instanceof Just) {
439 var directive = lookupDirective(v.value0)();
440 var imports = lookupImports(v.value0)();
441 var directiveLine = function() {
442 if (directive instanceof Just) {
443 return show2(directive.value0) + `;
444`;
445 }
446 if (directive instanceof Nothing) {
447 return "";
448 }
449 throw new Error("Failed pattern match at Loader.Plugin (line 40, column 27 - line 42, column 26): " + [directive.constructor.name]);
450 }();
451 var importLines = mapFlipped2(imports)(function(path2) {
452 return "import " + (show2(path2) + `;
453`);
454 });
455 var prefix = directiveLine + joinWith("")(importLines);
456 var $12 = $$null(prefix);
457 if ($12) {
458 return source;
459 }
460 log("[purescript-rsc] " + (v.value0 + (" -> injecting " + (show1(length(imports)) + (" import(s)" + function() {
461 if (directive instanceof Just) {
462 return " + " + show2(directive.value0);
463 }
464 if (directive instanceof Nothing) {
465 return "";
466 }
467 throw new Error("Failed pattern match at Loader.Plugin (line 48, column 14 - line 50, column 29): " + [directive.constructor.name]);
468 }())))))();
469 return prefix + source;
470 }
471 throw new Error("Failed pattern match at Loader.Plugin (line 35, column 3 - line 51, column 32): " + [v.constructor.name]);
472 };
473 };
474};
475var plugin = /* @__PURE__ */ createPluginImpl(transform);
477// loader-entry.js
478var loader_entry_default = plugin;
480module.exports=module.exports.default;