comparison react_games/public/current/current.js @ 44:0cfd7d9277b0

[ReactGame] 2048
author MrJuneJune <me@mrjunejune.com>
date Wed, 03 Dec 2025 18:34:22 -0800
parents fb9bcd3145cb
children
comparison
equal deleted inserted replaced
43:5e6a5d3c6868 44:0cfd7d9277b0
23 // compatible transform (i.e. "__esModule" has not been set), then set 23 // compatible transform (i.e. "__esModule" has not been set), then set
24 // "default" to the CommonJS "module.exports" for node compatibility. 24 // "default" to the CommonJS "module.exports" for node compatibility.
25 isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, 25 isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26 mod 26 mod
27 )); 27 ));
28
29 // node_modules/scheduler/cjs/scheduler.development.js
30 var require_scheduler_development = __commonJS({
31 "node_modules/scheduler/cjs/scheduler.development.js"(exports) {
32 "use strict";
33 (function() {
34 function performWorkUntilDeadline() {
35 needsPaint = false;
36 if (isMessageLoopRunning) {
37 var currentTime = exports.unstable_now();
38 startTime = currentTime;
39 var hasMoreWork = true;
40 try {
41 a: {
42 isHostCallbackScheduled = false;
43 isHostTimeoutScheduled && (isHostTimeoutScheduled = false, localClearTimeout(taskTimeoutID), taskTimeoutID = -1);
44 isPerformingWork = true;
45 var previousPriorityLevel = currentPriorityLevel;
46 try {
47 b: {
48 advanceTimers(currentTime);
49 for (currentTask = peek(taskQueue); null !== currentTask && !(currentTask.expirationTime > currentTime && shouldYieldToHost()); ) {
50 var callback = currentTask.callback;
51 if ("function" === typeof callback) {
52 currentTask.callback = null;
53 currentPriorityLevel = currentTask.priorityLevel;
54 var continuationCallback = callback(
55 currentTask.expirationTime <= currentTime
56 );
57 currentTime = exports.unstable_now();
58 if ("function" === typeof continuationCallback) {
59 currentTask.callback = continuationCallback;
60 advanceTimers(currentTime);
61 hasMoreWork = true;
62 break b;
63 }
64 currentTask === peek(taskQueue) && pop(taskQueue);
65 advanceTimers(currentTime);
66 } else pop(taskQueue);
67 currentTask = peek(taskQueue);
68 }
69 if (null !== currentTask) hasMoreWork = true;
70 else {
71 var firstTimer = peek(timerQueue);
72 null !== firstTimer && requestHostTimeout(
73 handleTimeout,
74 firstTimer.startTime - currentTime
75 );
76 hasMoreWork = false;
77 }
78 }
79 break a;
80 } finally {
81 currentTask = null, currentPriorityLevel = previousPriorityLevel, isPerformingWork = false;
82 }
83 hasMoreWork = void 0;
84 }
85 } finally {
86 hasMoreWork ? schedulePerformWorkUntilDeadline() : isMessageLoopRunning = false;
87 }
88 }
89 }
90 function push(heap, node) {
91 var index = heap.length;
92 heap.push(node);
93 a: for (; 0 < index; ) {
94 var parentIndex = index - 1 >>> 1, parent = heap[parentIndex];
95 if (0 < compare(parent, node))
96 heap[parentIndex] = node, heap[index] = parent, index = parentIndex;
97 else break a;
98 }
99 }
100 function peek(heap) {
101 return 0 === heap.length ? null : heap[0];
102 }
103 function pop(heap) {
104 if (0 === heap.length) return null;
105 var first = heap[0], last = heap.pop();
106 if (last !== first) {
107 heap[0] = last;
108 a: for (var index = 0, length = heap.length, halfLength = length >>> 1; index < halfLength; ) {
109 var leftIndex = 2 * (index + 1) - 1, left = heap[leftIndex], rightIndex = leftIndex + 1, right = heap[rightIndex];
110 if (0 > compare(left, last))
111 rightIndex < length && 0 > compare(right, left) ? (heap[index] = right, heap[rightIndex] = last, index = rightIndex) : (heap[index] = left, heap[leftIndex] = last, index = leftIndex);
112 else if (rightIndex < length && 0 > compare(right, last))
113 heap[index] = right, heap[rightIndex] = last, index = rightIndex;
114 else break a;
115 }
116 }
117 return first;
118 }
119 function compare(a, b) {
120 var diff = a.sortIndex - b.sortIndex;
121 return 0 !== diff ? diff : a.id - b.id;
122 }
123 function advanceTimers(currentTime) {
124 for (var timer = peek(timerQueue); null !== timer; ) {
125 if (null === timer.callback) pop(timerQueue);
126 else if (timer.startTime <= currentTime)
127 pop(timerQueue), timer.sortIndex = timer.expirationTime, push(taskQueue, timer);
128 else break;
129 timer = peek(timerQueue);
130 }
131 }
132 function handleTimeout(currentTime) {
133 isHostTimeoutScheduled = false;
134 advanceTimers(currentTime);
135 if (!isHostCallbackScheduled)
136 if (null !== peek(taskQueue))
137 isHostCallbackScheduled = true, isMessageLoopRunning || (isMessageLoopRunning = true, schedulePerformWorkUntilDeadline());
138 else {
139 var firstTimer = peek(timerQueue);
140 null !== firstTimer && requestHostTimeout(
141 handleTimeout,
142 firstTimer.startTime - currentTime
143 );
144 }
145 }
146 function shouldYieldToHost() {
147 return needsPaint ? true : exports.unstable_now() - startTime < frameInterval ? false : true;
148 }
149 function requestHostTimeout(callback, ms) {
150 taskTimeoutID = localSetTimeout(function() {
151 callback(exports.unstable_now());
152 }, ms);
153 }
154 "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
155 exports.unstable_now = void 0;
156 if ("object" === typeof performance && "function" === typeof performance.now) {
157 var localPerformance = performance;
158 exports.unstable_now = function() {
159 return localPerformance.now();
160 };
161 } else {
162 var localDate = Date, initialTime = localDate.now();
163 exports.unstable_now = function() {
164 return localDate.now() - initialTime;
165 };
166 }
167 var taskQueue = [], timerQueue = [], taskIdCounter = 1, currentTask = null, currentPriorityLevel = 3, isPerformingWork = false, isHostCallbackScheduled = false, isHostTimeoutScheduled = false, needsPaint = false, localSetTimeout = "function" === typeof setTimeout ? setTimeout : null, localClearTimeout = "function" === typeof clearTimeout ? clearTimeout : null, localSetImmediate = "undefined" !== typeof setImmediate ? setImmediate : null, isMessageLoopRunning = false, taskTimeoutID = -1, frameInterval = 5, startTime = -1;
168 if ("function" === typeof localSetImmediate)
169 var schedulePerformWorkUntilDeadline = function() {
170 localSetImmediate(performWorkUntilDeadline);
171 };
172 else if ("undefined" !== typeof MessageChannel) {
173 var channel = new MessageChannel(), port = channel.port2;
174 channel.port1.onmessage = performWorkUntilDeadline;
175 schedulePerformWorkUntilDeadline = function() {
176 port.postMessage(null);
177 };
178 } else
179 schedulePerformWorkUntilDeadline = function() {
180 localSetTimeout(performWorkUntilDeadline, 0);
181 };
182 exports.unstable_IdlePriority = 5;
183 exports.unstable_ImmediatePriority = 1;
184 exports.unstable_LowPriority = 4;
185 exports.unstable_NormalPriority = 3;
186 exports.unstable_Profiling = null;
187 exports.unstable_UserBlockingPriority = 2;
188 exports.unstable_cancelCallback = function(task) {
189 task.callback = null;
190 };
191 exports.unstable_forceFrameRate = function(fps) {
192 0 > fps || 125 < fps ? console.error(
193 "forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported"
194 ) : frameInterval = 0 < fps ? Math.floor(1e3 / fps) : 5;
195 };
196 exports.unstable_getCurrentPriorityLevel = function() {
197 return currentPriorityLevel;
198 };
199 exports.unstable_next = function(eventHandler) {
200 switch (currentPriorityLevel) {
201 case 1:
202 case 2:
203 case 3:
204 var priorityLevel = 3;
205 break;
206 default:
207 priorityLevel = currentPriorityLevel;
208 }
209 var previousPriorityLevel = currentPriorityLevel;
210 currentPriorityLevel = priorityLevel;
211 try {
212 return eventHandler();
213 } finally {
214 currentPriorityLevel = previousPriorityLevel;
215 }
216 };
217 exports.unstable_requestPaint = function() {
218 needsPaint = true;
219 };
220 exports.unstable_runWithPriority = function(priorityLevel, eventHandler) {
221 switch (priorityLevel) {
222 case 1:
223 case 2:
224 case 3:
225 case 4:
226 case 5:
227 break;
228 default:
229 priorityLevel = 3;
230 }
231 var previousPriorityLevel = currentPriorityLevel;
232 currentPriorityLevel = priorityLevel;
233 try {
234 return eventHandler();
235 } finally {
236 currentPriorityLevel = previousPriorityLevel;
237 }
238 };
239 exports.unstable_scheduleCallback = function(priorityLevel, callback, options) {
240 var currentTime = exports.unstable_now();
241 "object" === typeof options && null !== options ? (options = options.delay, options = "number" === typeof options && 0 < options ? currentTime + options : currentTime) : options = currentTime;
242 switch (priorityLevel) {
243 case 1:
244 var timeout = -1;
245 break;
246 case 2:
247 timeout = 250;
248 break;
249 case 5:
250 timeout = 1073741823;
251 break;
252 case 4:
253 timeout = 1e4;
254 break;
255 default:
256 timeout = 5e3;
257 }
258 timeout = options + timeout;
259 priorityLevel = {
260 id: taskIdCounter++,
261 callback,
262 priorityLevel,
263 startTime: options,
264 expirationTime: timeout,
265 sortIndex: -1
266 };
267 options > currentTime ? (priorityLevel.sortIndex = options, push(timerQueue, priorityLevel), null === peek(taskQueue) && priorityLevel === peek(timerQueue) && (isHostTimeoutScheduled ? (localClearTimeout(taskTimeoutID), taskTimeoutID = -1) : isHostTimeoutScheduled = true, requestHostTimeout(handleTimeout, options - currentTime))) : (priorityLevel.sortIndex = timeout, push(taskQueue, priorityLevel), isHostCallbackScheduled || isPerformingWork || (isHostCallbackScheduled = true, isMessageLoopRunning || (isMessageLoopRunning = true, schedulePerformWorkUntilDeadline())));
268 return priorityLevel;
269 };
270 exports.unstable_shouldYield = shouldYieldToHost;
271 exports.unstable_wrapCallback = function(callback) {
272 var parentPriorityLevel = currentPriorityLevel;
273 return function() {
274 var previousPriorityLevel = currentPriorityLevel;
275 currentPriorityLevel = parentPriorityLevel;
276 try {
277 return callback.apply(this, arguments);
278 } finally {
279 currentPriorityLevel = previousPriorityLevel;
280 }
281 };
282 };
283 "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
284 })();
285 }
286 });
287
288 // node_modules/scheduler/index.js
289 var require_scheduler = __commonJS({
290 "node_modules/scheduler/index.js"(exports, module) {
291 "use strict";
292 if (false) {
293 module.exports = null;
294 } else {
295 module.exports = require_scheduler_development();
296 }
297 }
298 });
299 28
300 // node_modules/react/cjs/react.development.js 29 // node_modules/react/cjs/react.development.js
301 var require_react_development = __commonJS({ 30 var require_react_development = __commonJS({
302 "node_modules/react/cjs/react.development.js"(exports, module) { 31 "node_modules/react/cjs/react.development.js"(exports, module) {
303 "use strict"; 32 "use strict";
1246 "use strict"; 975 "use strict";
1247 if (false) { 976 if (false) {
1248 module.exports = null; 977 module.exports = null;
1249 } else { 978 } else {
1250 module.exports = require_react_development(); 979 module.exports = require_react_development();
980 }
981 }
982 });
983
984 // node_modules/scheduler/cjs/scheduler.development.js
985 var require_scheduler_development = __commonJS({
986 "node_modules/scheduler/cjs/scheduler.development.js"(exports) {
987 "use strict";
988 (function() {
989 function performWorkUntilDeadline() {
990 needsPaint = false;
991 if (isMessageLoopRunning) {
992 var currentTime = exports.unstable_now();
993 startTime = currentTime;
994 var hasMoreWork = true;
995 try {
996 a: {
997 isHostCallbackScheduled = false;
998 isHostTimeoutScheduled && (isHostTimeoutScheduled = false, localClearTimeout(taskTimeoutID), taskTimeoutID = -1);
999 isPerformingWork = true;
1000 var previousPriorityLevel = currentPriorityLevel;
1001 try {
1002 b: {
1003 advanceTimers(currentTime);
1004 for (currentTask = peek(taskQueue); null !== currentTask && !(currentTask.expirationTime > currentTime && shouldYieldToHost()); ) {
1005 var callback = currentTask.callback;
1006 if ("function" === typeof callback) {
1007 currentTask.callback = null;
1008 currentPriorityLevel = currentTask.priorityLevel;
1009 var continuationCallback = callback(
1010 currentTask.expirationTime <= currentTime
1011 );
1012 currentTime = exports.unstable_now();
1013 if ("function" === typeof continuationCallback) {
1014 currentTask.callback = continuationCallback;
1015 advanceTimers(currentTime);
1016 hasMoreWork = true;
1017 break b;
1018 }
1019 currentTask === peek(taskQueue) && pop(taskQueue);
1020 advanceTimers(currentTime);
1021 } else pop(taskQueue);
1022 currentTask = peek(taskQueue);
1023 }
1024 if (null !== currentTask) hasMoreWork = true;
1025 else {
1026 var firstTimer = peek(timerQueue);
1027 null !== firstTimer && requestHostTimeout(
1028 handleTimeout,
1029 firstTimer.startTime - currentTime
1030 );
1031 hasMoreWork = false;
1032 }
1033 }
1034 break a;
1035 } finally {
1036 currentTask = null, currentPriorityLevel = previousPriorityLevel, isPerformingWork = false;
1037 }
1038 hasMoreWork = void 0;
1039 }
1040 } finally {
1041 hasMoreWork ? schedulePerformWorkUntilDeadline() : isMessageLoopRunning = false;
1042 }
1043 }
1044 }
1045 function push(heap, node) {
1046 var index = heap.length;
1047 heap.push(node);
1048 a: for (; 0 < index; ) {
1049 var parentIndex = index - 1 >>> 1, parent = heap[parentIndex];
1050 if (0 < compare(parent, node))
1051 heap[parentIndex] = node, heap[index] = parent, index = parentIndex;
1052 else break a;
1053 }
1054 }
1055 function peek(heap) {
1056 return 0 === heap.length ? null : heap[0];
1057 }
1058 function pop(heap) {
1059 if (0 === heap.length) return null;
1060 var first = heap[0], last = heap.pop();
1061 if (last !== first) {
1062 heap[0] = last;
1063 a: for (var index = 0, length = heap.length, halfLength = length >>> 1; index < halfLength; ) {
1064 var leftIndex = 2 * (index + 1) - 1, left = heap[leftIndex], rightIndex = leftIndex + 1, right = heap[rightIndex];
1065 if (0 > compare(left, last))
1066 rightIndex < length && 0 > compare(right, left) ? (heap[index] = right, heap[rightIndex] = last, index = rightIndex) : (heap[index] = left, heap[leftIndex] = last, index = leftIndex);
1067 else if (rightIndex < length && 0 > compare(right, last))
1068 heap[index] = right, heap[rightIndex] = last, index = rightIndex;
1069 else break a;
1070 }
1071 }
1072 return first;
1073 }
1074 function compare(a, b) {
1075 var diff = a.sortIndex - b.sortIndex;
1076 return 0 !== diff ? diff : a.id - b.id;
1077 }
1078 function advanceTimers(currentTime) {
1079 for (var timer = peek(timerQueue); null !== timer; ) {
1080 if (null === timer.callback) pop(timerQueue);
1081 else if (timer.startTime <= currentTime)
1082 pop(timerQueue), timer.sortIndex = timer.expirationTime, push(taskQueue, timer);
1083 else break;
1084 timer = peek(timerQueue);
1085 }
1086 }
1087 function handleTimeout(currentTime) {
1088 isHostTimeoutScheduled = false;
1089 advanceTimers(currentTime);
1090 if (!isHostCallbackScheduled)
1091 if (null !== peek(taskQueue))
1092 isHostCallbackScheduled = true, isMessageLoopRunning || (isMessageLoopRunning = true, schedulePerformWorkUntilDeadline());
1093 else {
1094 var firstTimer = peek(timerQueue);
1095 null !== firstTimer && requestHostTimeout(
1096 handleTimeout,
1097 firstTimer.startTime - currentTime
1098 );
1099 }
1100 }
1101 function shouldYieldToHost() {
1102 return needsPaint ? true : exports.unstable_now() - startTime < frameInterval ? false : true;
1103 }
1104 function requestHostTimeout(callback, ms) {
1105 taskTimeoutID = localSetTimeout(function() {
1106 callback(exports.unstable_now());
1107 }, ms);
1108 }
1109 "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
1110 exports.unstable_now = void 0;
1111 if ("object" === typeof performance && "function" === typeof performance.now) {
1112 var localPerformance = performance;
1113 exports.unstable_now = function() {
1114 return localPerformance.now();
1115 };
1116 } else {
1117 var localDate = Date, initialTime = localDate.now();
1118 exports.unstable_now = function() {
1119 return localDate.now() - initialTime;
1120 };
1121 }
1122 var taskQueue = [], timerQueue = [], taskIdCounter = 1, currentTask = null, currentPriorityLevel = 3, isPerformingWork = false, isHostCallbackScheduled = false, isHostTimeoutScheduled = false, needsPaint = false, localSetTimeout = "function" === typeof setTimeout ? setTimeout : null, localClearTimeout = "function" === typeof clearTimeout ? clearTimeout : null, localSetImmediate = "undefined" !== typeof setImmediate ? setImmediate : null, isMessageLoopRunning = false, taskTimeoutID = -1, frameInterval = 5, startTime = -1;
1123 if ("function" === typeof localSetImmediate)
1124 var schedulePerformWorkUntilDeadline = function() {
1125 localSetImmediate(performWorkUntilDeadline);
1126 };
1127 else if ("undefined" !== typeof MessageChannel) {
1128 var channel = new MessageChannel(), port = channel.port2;
1129 channel.port1.onmessage = performWorkUntilDeadline;
1130 schedulePerformWorkUntilDeadline = function() {
1131 port.postMessage(null);
1132 };
1133 } else
1134 schedulePerformWorkUntilDeadline = function() {
1135 localSetTimeout(performWorkUntilDeadline, 0);
1136 };
1137 exports.unstable_IdlePriority = 5;
1138 exports.unstable_ImmediatePriority = 1;
1139 exports.unstable_LowPriority = 4;
1140 exports.unstable_NormalPriority = 3;
1141 exports.unstable_Profiling = null;
1142 exports.unstable_UserBlockingPriority = 2;
1143 exports.unstable_cancelCallback = function(task) {
1144 task.callback = null;
1145 };
1146 exports.unstable_forceFrameRate = function(fps) {
1147 0 > fps || 125 < fps ? console.error(
1148 "forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported"
1149 ) : frameInterval = 0 < fps ? Math.floor(1e3 / fps) : 5;
1150 };
1151 exports.unstable_getCurrentPriorityLevel = function() {
1152 return currentPriorityLevel;
1153 };
1154 exports.unstable_next = function(eventHandler) {
1155 switch (currentPriorityLevel) {
1156 case 1:
1157 case 2:
1158 case 3:
1159 var priorityLevel = 3;
1160 break;
1161 default:
1162 priorityLevel = currentPriorityLevel;
1163 }
1164 var previousPriorityLevel = currentPriorityLevel;
1165 currentPriorityLevel = priorityLevel;
1166 try {
1167 return eventHandler();
1168 } finally {
1169 currentPriorityLevel = previousPriorityLevel;
1170 }
1171 };
1172 exports.unstable_requestPaint = function() {
1173 needsPaint = true;
1174 };
1175 exports.unstable_runWithPriority = function(priorityLevel, eventHandler) {
1176 switch (priorityLevel) {
1177 case 1:
1178 case 2:
1179 case 3:
1180 case 4:
1181 case 5:
1182 break;
1183 default:
1184 priorityLevel = 3;
1185 }
1186 var previousPriorityLevel = currentPriorityLevel;
1187 currentPriorityLevel = priorityLevel;
1188 try {
1189 return eventHandler();
1190 } finally {
1191 currentPriorityLevel = previousPriorityLevel;
1192 }
1193 };
1194 exports.unstable_scheduleCallback = function(priorityLevel, callback, options) {
1195 var currentTime = exports.unstable_now();
1196 "object" === typeof options && null !== options ? (options = options.delay, options = "number" === typeof options && 0 < options ? currentTime + options : currentTime) : options = currentTime;
1197 switch (priorityLevel) {
1198 case 1:
1199 var timeout = -1;
1200 break;
1201 case 2:
1202 timeout = 250;
1203 break;
1204 case 5:
1205 timeout = 1073741823;
1206 break;
1207 case 4:
1208 timeout = 1e4;
1209 break;
1210 default:
1211 timeout = 5e3;
1212 }
1213 timeout = options + timeout;
1214 priorityLevel = {
1215 id: taskIdCounter++,
1216 callback,
1217 priorityLevel,
1218 startTime: options,
1219 expirationTime: timeout,
1220 sortIndex: -1
1221 };
1222 options > currentTime ? (priorityLevel.sortIndex = options, push(timerQueue, priorityLevel), null === peek(taskQueue) && priorityLevel === peek(timerQueue) && (isHostTimeoutScheduled ? (localClearTimeout(taskTimeoutID), taskTimeoutID = -1) : isHostTimeoutScheduled = true, requestHostTimeout(handleTimeout, options - currentTime))) : (priorityLevel.sortIndex = timeout, push(taskQueue, priorityLevel), isHostCallbackScheduled || isPerformingWork || (isHostCallbackScheduled = true, isMessageLoopRunning || (isMessageLoopRunning = true, schedulePerformWorkUntilDeadline())));
1223 return priorityLevel;
1224 };
1225 exports.unstable_shouldYield = shouldYieldToHost;
1226 exports.unstable_wrapCallback = function(callback) {
1227 var parentPriorityLevel = currentPriorityLevel;
1228 return function() {
1229 var previousPriorityLevel = currentPriorityLevel;
1230 currentPriorityLevel = parentPriorityLevel;
1231 try {
1232 return callback.apply(this, arguments);
1233 } finally {
1234 currentPriorityLevel = previousPriorityLevel;
1235 }
1236 };
1237 };
1238 "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
1239 })();
1240 }
1241 });
1242
1243 // node_modules/scheduler/index.js
1244 var require_scheduler = __commonJS({
1245 "node_modules/scheduler/index.js"(exports, module) {
1246 "use strict";
1247 if (false) {
1248 module.exports = null;
1249 } else {
1250 module.exports = require_scheduler_development();
1251 } 1251 }
1252 } 1252 }
1253 }); 1253 });
1254 1254
1255 // node_modules/react-dom/cjs/react-dom.development.js 1255 // node_modules/react-dom/cjs/react-dom.development.js
19587 }); 19587 });
19588 19588
19589 // src/current.tsx 19589 // src/current.tsx
19590 var require_current = __commonJS({ 19590 var require_current = __commonJS({
19591 "src/current.tsx"() { 19591 "src/current.tsx"() {
19592 var import_react = __toESM(require_react());
19592 var import_client = __toESM(require_client()); 19593 var import_client = __toESM(require_client());
19593 var import_jsx_runtime = __toESM(require_jsx_runtime()); 19594 var import_jsx_runtime = __toESM(require_jsx_runtime());
19594 var shaders = ` 19595 var MAX_WIDTH = 4;
19595 struct VertexOut { 19596 var gameStyle = {
19596 @builtin(position) position : vec4f, 19597 container: {
19597 @location(0) color : vec4f 19598 display: "flex",
19598 } 19599 flexDirection: "column",
19599 19600 justifyContent: "center",
19600 @vertex 19601 alignItems: "center",
19601 fn vertex_main(@location(0) position: vec4f, 19602 height: "100vh"
19602 @location(1) color: vec4f) -> VertexOut 19603 },
19603 { 19604 board: {
19604 var output : VertexOut; 19605 display: "grid",
19605 output.position = position; 19606 gridTemplateColumns: "repeat(4, 50px)",
19606 output.color = color; 19607 background: "#EEFFEE"
19607 return output; 19608 },
19608 } 19609 cell: (color) => ({
19609 19610 display: "flex",
19610 @fragment 19611 justifyContent: "center",
19611 fn fragment_main(fragData: VertexOut) -> @location(0) vec4f 19612 alignItems: "center",
19612 { 19613 aspectRatio: "1 / 1 ",
19613 return fragData.color; 19614 margin: "10px",
19614 } 19615 background: color
19615 `; 19616 })
19616 async function init() { 19617 };
19617 if (!navigator.gpu) { 19618 function initializeBoard() {
19618 throw Error("WebGPU not supported."); 19619 const board = Array.from(
19619 } 19620 { length: MAX_WIDTH },
19620 const adapter = await navigator.gpu.requestAdapter(); 19621 () => Array.from({ length: MAX_WIDTH }, () => ({ value: 0, color: "orange" }))
19621 if (!adapter) { 19622 );
19622 throw Error("Couldn't request WebGPU adapter."); 19623 let rowIndex;
19623 } 19624 let colIndex;
19624 const device = await adapter.requestDevice(); 19625 rowIndex = Math.floor(Math.random() * 4);
19625 const shaderModule = device.createShaderModule({ 19626 colIndex = Math.floor(Math.random() * 4);
19626 code: shaders 19627 board[rowIndex][colIndex].value = 2;
19628 board[rowIndex - 1][colIndex].value = 2;
19629 return board;
19630 }
19631 function initializeGame() {
19632 return {
19633 board: initializeBoard(),
19634 state: "in_progress",
19635 steps: 0
19636 };
19637 }
19638 function handleMove(board, command) {
19639 const copiedBoard = board.map(
19640 (row) => row.map((cell) => ({ ...cell, merged: false }))
19641 );
19642 let diff;
19643 let startRow, endRow, stepRow;
19644 let startCol, endCol, stepCol;
19645 const size = copiedBoard.length;
19646 switch (command) {
19647 case "u":
19648 diff = { row: -1, col: 0 };
19649 startRow = 0;
19650 endRow = size;
19651 stepRow = 1;
19652 startCol = 0;
19653 endCol = size;
19654 stepCol = 1;
19655 break;
19656 case "d":
19657 diff = { row: 1, col: 0 };
19658 startRow = size - 1;
19659 endRow = -1;
19660 stepRow = -1;
19661 startCol = 0;
19662 endCol = size;
19663 stepCol = 1;
19664 break;
19665 case "l":
19666 diff = { row: 0, col: -1 };
19667 startRow = 0;
19668 endRow = size;
19669 stepRow = 1;
19670 startCol = 0;
19671 endCol = size;
19672 stepCol = 1;
19673 break;
19674 case "r":
19675 diff = { row: 0, col: 1 };
19676 startRow = 0;
19677 endRow = size;
19678 stepRow = 1;
19679 startCol = size - 1;
19680 endCol = -1;
19681 stepCol = -1;
19682 break;
19683 }
19684 for (let rowIndex = startRow; rowIndex !== endRow; rowIndex += stepRow) {
19685 for (let colIndex = startCol; colIndex !== endCol; colIndex += stepCol) {
19686 const currentCell = copiedBoard[rowIndex][colIndex];
19687 if (currentCell.value === 0) continue;
19688 let r = rowIndex;
19689 let c = colIndex;
19690 let emptySlot = { r: rowIndex, c: colIndex };
19691 let finalSlot = { r: rowIndex, c: colIndex };
19692 while (true) {
19693 r += diff.row;
19694 c += diff.col;
19695 if (r < 0 || r >= size || c < 0 || c >= size) {
19696 finalSlot = emptySlot;
19697 break;
19698 }
19699 const nextCell = copiedBoard[r][c];
19700 if (nextCell.value === 0) {
19701 emptySlot = { r, c };
19702 finalSlot = emptySlot;
19703 } else if (nextCell.value === currentCell.value && !nextCell.merged) {
19704 finalSlot = { r, c };
19705 break;
19706 } else {
19707 finalSlot = emptySlot;
19708 break;
19709 }
19710 }
19711 const targetCell = copiedBoard[finalSlot.r][finalSlot.c];
19712 if (finalSlot.r === rowIndex && finalSlot.c === colIndex) {
19713 continue;
19714 }
19715 if (targetCell.value === currentCell.value && !targetCell.merged) {
19716 targetCell.value *= 2;
19717 targetCell.merged = true;
19718 copiedBoard[rowIndex][colIndex].value = 0;
19719 } else if (targetCell.value === 0) {
19720 targetCell.value = currentCell.value;
19721 copiedBoard[rowIndex][colIndex].value = 0;
19722 }
19723 }
19724 }
19725 return copiedBoard;
19726 }
19727 function addNewItemsToTheBoard(board) {
19728 let randomRowIndex;
19729 let randomColIndex;
19730 let zeroPos = 0;
19731 board.forEach((row) => {
19732 row.forEach((cell) => {
19733 if (cell.value === 0) {
19734 zeroPos += 1;
19735 }
19736 });
19627 }); 19737 });
19628 const canvas = document.querySelector("#gpuCanvas"); 19738 if (zeroPos === 0) {
19629 const context = canvas.getContext("webgpu"); 19739 return;
19630 context.configure({ 19740 }
19631 device, 19741 let curr = 0;
19632 format: navigator.gpu.getPreferredCanvasFormat(), 19742 const maxAddedValues = zeroPos < 2 ? 1 : zeroPos / 2 | 0;
19633 alphaMode: "premultiplied" 19743 while (curr < maxAddedValues) {
19634 }); 19744 randomRowIndex = Math.floor(Math.random() * board.length);
19635 console.log(device); 19745 randomColIndex = Math.floor(Math.random() * board.length);
19746 if (board[randomRowIndex][randomColIndex].value === 0) {
19747 board[randomRowIndex][randomColIndex].value = 2;
19748 curr++;
19749 }
19750 }
19636 } 19751 }
19637 void init(); 19752 function gameDispatch(game, gameAction) {
19638 var Current = () => { 19753 switch (gameAction.type) {
19639 return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: "hello " }); 19754 case "move": {
19640 }; 19755 const newBoard = handleMove(game.board, gameAction.command);
19756 addNewItemsToTheBoard(newBoard);
19757 return {
19758 ...game,
19759 board: newBoard
19760 };
19761 }
19762 case "calculate": {
19763 return {
19764 ...game
19765 };
19766 }
19767 }
19768 }
19769 function Current() {
19770 const [game, dispatch] = (0, import_react.useReducer)(gameDispatch, null, initializeGame);
19771 (0, import_react.useEffect)(() => {
19772 window.addEventListener("keyup", (e) => {
19773 switch (e.key) {
19774 case "ArrowDown": {
19775 dispatch({ type: "move", command: "d" });
19776 return;
19777 }
19778 case "ArrowUp": {
19779 dispatch({ type: "move", command: "u" });
19780 return;
19781 }
19782 case "ArrowRight": {
19783 dispatch({ type: "move", command: "r" });
19784 return;
19785 }
19786 case "ArrowLeft": {
19787 dispatch({ type: "move", command: "l" });
19788 return;
19789 }
19790 default:
19791 return;
19792 }
19793 });
19794 }, []);
19795 return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: gameStyle.container, children: [
19796 /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h1", { children: " 2048 " }),
19797 /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: gameStyle.board, children: game.board.map((row) => {
19798 return row.map((cell) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: gameStyle.cell(cell.color), children: [
19799 " ",
19800 cell.value,
19801 " "
19802 ] }));
19803 }) })
19804 ] });
19805 }
19641 import_client.default.createRoot(document.getElementById("root")).render(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Current, {})); 19806 import_client.default.createRoot(document.getElementById("root")).render(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Current, {}));
19642 } 19807 }
19643 }); 19808 });
19644 require_current(); 19809 require_current();
19645 })(); 19810 })();
19646 /*! Bundled license information: 19811 /*! Bundled license information:
19647 19812
19648 scheduler/cjs/scheduler.development.js: 19813 react/cjs/react.development.js:
19649 (** 19814 (**
19650 * @license React 19815 * @license React
19651 * scheduler.development.js 19816 * react.development.js
19652 * 19817 *
19653 * Copyright (c) Meta Platforms, Inc. and affiliates. 19818 * Copyright (c) Meta Platforms, Inc. and affiliates.
19654 * 19819 *
19655 * This source code is licensed under the MIT license found in the 19820 * This source code is licensed under the MIT license found in the
19656 * LICENSE file in the root directory of this source tree. 19821 * LICENSE file in the root directory of this source tree.
19657 *) 19822 *)
19658 19823
19659 react/cjs/react.development.js: 19824 scheduler/cjs/scheduler.development.js:
19660 (** 19825 (**
19661 * @license React 19826 * @license React
19662 * react.development.js 19827 * scheduler.development.js
19663 * 19828 *
19664 * Copyright (c) Meta Platforms, Inc. and affiliates. 19829 * Copyright (c) Meta Platforms, Inc. and affiliates.
19665 * 19830 *
19666 * This source code is licensed under the MIT license found in the 19831 * This source code is licensed under the MIT license found in the
19667 * LICENSE file in the root directory of this source tree. 19832 * LICENSE file in the root directory of this source tree.