@gnsx/three 0.185.15 → 0.185.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2065,9 +2065,79 @@ function warnOnce( ...params ) {
2065
2065
 
2066
2066
  }
2067
2067
 
2068
+ // WITH_GENESYS
2069
+ /**
2070
+ * Shared MessageChannel used by {@link yieldToTask}. One pair of ports is
2071
+ * owned for the lifetime of this module so compileAsync does not allocate a
2072
+ * channel per yield.
2073
+ *
2074
+ * @private
2075
+ * @type {MessageChannel|null}
2076
+ */
2077
+ let _taskYieldChannel = null;
2078
+
2079
+ /**
2080
+ * Resolvers waiting for the next MessageChannel task. Sequential
2081
+ * `await yieldToMain()` callers queue at most one entry; the array still
2082
+ * preserves ordering if several yields overlap.
2083
+ *
2084
+ * @private
2085
+ * @type {Array<Function>}
2086
+ */
2087
+ const _taskYieldResolvers = [];
2088
+
2089
+ /**
2090
+ * Yields to a new event-loop task without waiting for a display frame.
2091
+ *
2092
+ * @private
2093
+ * @return {Promise<void>}
2094
+ */
2095
+ function yieldToTask() {
2096
+
2097
+ return new Promise( resolve => {
2098
+
2099
+ if ( typeof MessageChannel === 'function' ) {
2100
+
2101
+ if ( _taskYieldChannel === null ) {
2102
+
2103
+ _taskYieldChannel = new MessageChannel();
2104
+ _taskYieldChannel.port1.onmessage = function () {
2105
+
2106
+ const next = _taskYieldResolvers.shift();
2107
+ if ( next !== undefined ) next();
2108
+
2109
+ };
2110
+
2111
+ }
2112
+
2113
+ _taskYieldResolvers.push( resolve );
2114
+ _taskYieldChannel.port2.postMessage( null );
2115
+ return;
2116
+
2117
+ }
2118
+
2119
+ if ( typeof setTimeout === 'function' ) {
2120
+
2121
+ setTimeout( resolve, 0 );
2122
+ return;
2123
+
2124
+ }
2125
+
2126
+ resolve();
2127
+
2128
+ } );
2129
+
2130
+ }
2131
+ // !WITH_GENESYS
2132
+
2068
2133
  /**
2069
2134
  * Yields execution to the main thread to allow rendering and other tasks.
2070
- * Uses scheduler.yield() when available (Chrome 115+), falls back to requestAnimationFrame.
2135
+ * Uses scheduler.yield() when available (Chrome 115+).
2136
+ * WITH_GENESYS
2137
+ * Falls back to a MessageChannel (or setTimeout) task continuation so browsers
2138
+ * without the Scheduler API do not wait one animation frame per yield.
2139
+ * !WITH_GENESYS
2140
+ * Falls back to requestAnimationFrame.
2071
2141
  *
2072
2142
  * @return {Promise<void>}
2073
2143
  */
@@ -2079,11 +2149,14 @@ function yieldToMain() {
2079
2149
 
2080
2150
  }
2081
2151
 
2082
- return new Promise( resolve => {
2083
-
2084
- requestAnimationFrame( resolve );
2085
-
2086
- } );
2152
+ // WITH_GENESYS
2153
+ return yieldToTask();
2154
+ // !WITH_GENESYS
2155
+ // return new Promise( resolve => {
2156
+ //
2157
+ // requestAnimationFrame( resolve );
2158
+ //
2159
+ // } );
2087
2160
 
2088
2161
  }
2089
2162