@lingxia/polyfills 0.9.0

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.
@@ -0,0 +1 @@
1
+ (function(root){if(typeof Object.assign!=="function"){Object.defineProperty(Object,"assign",{value:function(target){if(target==null){throw new TypeError("Cannot convert undefined or null to object")}var to=Object(target);for(var i=1;i<arguments.length;i++){var src=arguments[i];if(src!=null){for(var key in src){if(Object.prototype.hasOwnProperty.call(src,key)){to[key]=src[key]}}}}return to},writable:true,configurable:true})}if(typeof Object.entries!=="function"){Object.entries=function(obj){var keys=Object.keys(obj);var out=[];for(var i=0;i<keys.length;i++){out.push([keys[i],obj[keys[i]]])}return out}}if(typeof Object.values!=="function"){Object.values=function(obj){var keys=Object.keys(obj);var out=[];for(var i=0;i<keys.length;i++){out.push(obj[keys[i]])}return out}}if(typeof Array.from!=="function"){Array.from=function(source,mapFn,thisArg){if(source==null){throw new TypeError("Array.from requires an iterable or array-like")}var out=[];if(typeof source.length!=="number"&&typeof source.forEach==="function"){source.forEach(function(v){out.push(v)})}else{var len=source.length>>>0;for(var i=0;i<len;i++){out.push(source[i])}}if(typeof mapFn==="function"){for(var j=0;j<out.length;j++){out[j]=mapFn.call(thisArg,out[j],j)}}return out}}if(typeof Array.prototype.includes!=="function"){Object.defineProperty(Array.prototype,"includes",{value:function(target){var len=this.length>>>0;for(var i=0;i<len;i++){if(this[i]===target||target!==target&&this[i]!==this[i]){return true}}return false},writable:true,configurable:true})}if(typeof Array.prototype.find!=="function"){Object.defineProperty(Array.prototype,"find",{value:function(predicate){var len=this.length>>>0;var thisArg=arguments[1];for(var i=0;i<len;i++){if(predicate.call(thisArg,this[i],i,this))return this[i]}return undefined},writable:true,configurable:true})}if(typeof Array.prototype.findIndex!=="function"){Object.defineProperty(Array.prototype,"findIndex",{value:function(predicate){var len=this.length>>>0;var thisArg=arguments[1];for(var i=0;i<len;i++){if(predicate.call(thisArg,this[i],i,this))return i}return-1},writable:true,configurable:true})}if(typeof String.prototype.startsWith!=="function"){Object.defineProperty(String.prototype,"startsWith",{value:function(search,pos){pos=pos||0;return this.substring(pos,pos+search.length)===String(search)},writable:true,configurable:true})}if(typeof String.prototype.endsWith!=="function"){Object.defineProperty(String.prototype,"endsWith",{value:function(search,endPos){if(endPos===undefined||endPos>this.length)endPos=this.length;return this.substring(endPos-search.length,endPos)===String(search)},writable:true,configurable:true})}if(typeof String.prototype.includes!=="function"){Object.defineProperty(String.prototype,"includes",{value:function(search,start){return this.indexOf(search,start||0)!==-1},writable:true,configurable:true})}if(typeof Number.isFinite!=="function"){Number.isFinite=function(value){return typeof value==="number"&&isFinite(value)}}if(typeof Number.isInteger!=="function"){Number.isInteger=function(value){return typeof value==="number"&&isFinite(value)&&Math.floor(value)===value}}if(typeof Promise!=="undefined"&&typeof Promise.prototype.finally!=="function"){Object.defineProperty(Promise.prototype,"finally",{value:function(callback){var P=this.constructor||Promise;return this.then(function(value){return P.resolve(callback()).then(function(){return value})},function(reason){return P.resolve(callback()).then(function(){throw reason})})},writable:true,configurable:true})}if(typeof Promise!=="undefined"&&typeof Promise.allSettled!=="function"){Promise.allSettled=function(promises){return Promise.all(Array.prototype.map.call(promises,function(p){return Promise.resolve(p).then(function(value){return{status:"fulfilled",value:value}},function(reason){return{status:"rejected",reason:reason}})}))}}if(typeof Promise!=="undefined"&&typeof Promise.any!=="function"){Promise.any=function(promises){return new Promise(function(resolve,reject){var arr=[];for(var i=0;i<promises.length;i++)arr.push(promises[i]);var errors=new Array(arr.length);var remaining=arr.length;if(remaining===0){reject({name:"AggregateError",errors:[],message:"All promises were rejected"});return}arr.forEach(function(p,idx){Promise.resolve(p).then(resolve,function(err){errors[idx]=err;if(--remaining===0){reject({name:"AggregateError",errors:errors,message:"All promises were rejected"})}})})})}}if(typeof Object.fromEntries!=="function"){Object.fromEntries=function(iterable){var out={};if(iterable==null)return out;if(typeof iterable.forEach==="function"){iterable.forEach(function(pair){if(pair)out[pair[0]]=pair[1]})}else{for(var i=0;i<iterable.length;i++){var pair=iterable[i];if(pair)out[pair[0]]=pair[1]}}return out}}if(typeof String.prototype.padStart!=="function"){Object.defineProperty(String.prototype,"padStart",{value:function(targetLength,padString){var s=String(this);if(s.length>=targetLength)return s;var pad=String(padString===undefined?" ":padString);if(pad.length===0)return s;var need=targetLength-s.length;var prefix="";while(prefix.length<need)prefix+=pad;return prefix.slice(0,need)+s},writable:true,configurable:true})}if(typeof String.prototype.padEnd!=="function"){Object.defineProperty(String.prototype,"padEnd",{value:function(targetLength,padString){var s=String(this);if(s.length>=targetLength)return s;var pad=String(padString===undefined?" ":padString);if(pad.length===0)return s;var need=targetLength-s.length;var suffix="";while(suffix.length<need)suffix+=pad;return s+suffix.slice(0,need)},writable:true,configurable:true})}if(typeof String.prototype.trimStart!=="function"){Object.defineProperty(String.prototype,"trimStart",{value:function(){return String(this).replace(/^[\s\xA0]+/,"")},writable:true,configurable:true})}if(typeof String.prototype.trimEnd!=="function"){Object.defineProperty(String.prototype,"trimEnd",{value:function(){return String(this).replace(/[\s\xA0]+$/,"")},writable:true,configurable:true})}if(typeof String.prototype.replaceAll!=="function"){Object.defineProperty(String.prototype,"replaceAll",{value:function(search,replacement){if(search instanceof RegExp){if(!search.global){throw new TypeError("String.prototype.replaceAll called with a non-global RegExp argument")}return String(this).replace(search,replacement)}var str=String(search).replace(/[.*+?^${}()|[\]\\]/g,"\\$&");return String(this).replace(new RegExp(str,"g"),replacement)},writable:true,configurable:true})}if(typeof Array.prototype.flat!=="function"){Object.defineProperty(Array.prototype,"flat",{value:function(depth){var d=depth===undefined?1:Number(depth);var out=[];(function rec(arr,level){for(var i=0;i<arr.length;i++){var v=arr[i];if(Array.isArray(v)&&level>0)rec(v,level-1);else out.push(v)}})(this,d);return out},writable:true,configurable:true})}if(typeof Array.prototype.flatMap!=="function"){Object.defineProperty(Array.prototype,"flatMap",{value:function(callback,thisArg){var mapped=Array.prototype.map.call(this,callback,thisArg);return Array.prototype.flat.call(mapped,1)},writable:true,configurable:true})}if(typeof Array.prototype.at!=="function"){Object.defineProperty(Array.prototype,"at",{value:function(index){var n=Math.trunc(Number(index))||0;if(n<0)n+=this.length;if(n<0||n>=this.length)return undefined;return this[n]},writable:true,configurable:true})}if(typeof root.globalThis==="undefined"){try{root.globalThis=root}catch(e){}}var symbolCounter=0;if(typeof Symbol==="undefined"){var SymbolShim=function(description){var key="@@_sym_"+ ++symbolCounter+"_"+(description||"");return key};SymbolShim.iterator=SymbolShim("Symbol.iterator");SymbolShim.asyncIterator=SymbolShim("Symbol.asyncIterator");SymbolShim.toStringTag=SymbolShim("Symbol.toStringTag");var symbolForRegistry={};SymbolShim["for"]=function(key){var k=String(key);if(!Object.prototype.hasOwnProperty.call(symbolForRegistry,k)){symbolForRegistry[k]=SymbolShim(k)}return symbolForRegistry[k]};root.Symbol=SymbolShim}if(typeof Set==="undefined"){var SetShim=function(iterable){this._items=[];var self=this;if(iterable!=null){if(typeof iterable.forEach==="function"){iterable.forEach(function(v){self.add(v)})}else if(typeof iterable.length==="number"){for(var i=0;i<iterable.length;i++)self.add(iterable[i])}}};SetShim.prototype.add=function(value){if(this._items.indexOf(value)===-1)this._items.push(value);return this};SetShim.prototype.has=function(value){return this._items.indexOf(value)!==-1};SetShim.prototype["delete"]=function(value){var idx=this._items.indexOf(value);if(idx===-1)return false;this._items.splice(idx,1);return true};SetShim.prototype.clear=function(){this._items.length=0};SetShim.prototype.forEach=function(callback,thisArg){var copy=this._items.slice();for(var i=0;i<copy.length;i++){callback.call(thisArg,copy[i],copy[i],this)}};Object.defineProperty(SetShim.prototype,"size",{get:function(){return this._items.length}});root.Set=SetShim}if(typeof Map==="undefined"){var MapShim=function(iterable){this._keys=[];this._values=[];var self=this;if(iterable!=null&&typeof iterable.forEach==="function"){iterable.forEach(function(entry){self.set(entry[0],entry[1])})}else if(iterable!=null&&typeof iterable.length==="number"){for(var i=0;i<iterable.length;i++){self.set(iterable[i][0],iterable[i][1])}}};MapShim.prototype.get=function(key){var idx=this._keys.indexOf(key);return idx===-1?undefined:this._values[idx]};MapShim.prototype.set=function(key,value){var idx=this._keys.indexOf(key);if(idx===-1){this._keys.push(key);this._values.push(value)}else{this._values[idx]=value}return this};MapShim.prototype.has=function(key){return this._keys.indexOf(key)!==-1};MapShim.prototype["delete"]=function(key){var idx=this._keys.indexOf(key);if(idx===-1)return false;this._keys.splice(idx,1);this._values.splice(idx,1);return true};MapShim.prototype.clear=function(){this._keys.length=0;this._values.length=0};MapShim.prototype.forEach=function(callback,thisArg){var keysCopy=this._keys.slice();var valuesCopy=this._values.slice();for(var i=0;i<keysCopy.length;i++){callback.call(thisArg,valuesCopy[i],keysCopy[i],this)}};MapShim.prototype.keys=function(){return this._keys.slice()};MapShim.prototype.values=function(){return this._values.slice()};MapShim.prototype.entries=function(){var out=[];for(var i=0;i<this._keys.length;i++){out.push([this._keys[i],this._values[i]])}return out};Object.defineProperty(MapShim.prototype,"size",{get:function(){return this._keys.length}});root.Map=MapShim}})(typeof window!=="undefined"?window:this);
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@lingxia/polyfills",
3
+ "version": "0.9.0",
4
+ "private": false,
5
+ "description": "ES5 stdlib polyfills shipped to the lxapp runtime when targeting old Android WebView (Chromium 37–44).",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/LingXia-Dev/LingXia.git",
9
+ "directory": "packages/lingxia-polyfills"
10
+ },
11
+ "type": "module",
12
+ "main": "dist/polyfills.es5.js",
13
+ "exports": {
14
+ ".": "./dist/polyfills.es5.js",
15
+ "./dist/polyfills.es5.js": "./dist/polyfills.es5.js",
16
+ "./package.json": "./package.json"
17
+ },
18
+ "scripts": {
19
+ "build": "node ./scripts/build.mjs && npm run check",
20
+ "check": "node ./scripts/check.mjs",
21
+ "clean": "rm -rf dist",
22
+ "prepublishOnly": "npm run clean && npm run build"
23
+ },
24
+ "devDependencies": {
25
+ "terser": "^5.39.0"
26
+ },
27
+ "files": [
28
+ "dist",
29
+ "src"
30
+ ],
31
+ "publishConfig": {
32
+ "registry": "https://registry.npmjs.org",
33
+ "access": "public"
34
+ },
35
+ "license": "MIT"
36
+ }
package/src/es5.js ADDED
@@ -0,0 +1,515 @@
1
+ // @lingxia/polyfills — ES5 stdlib polyfills shipped as a standalone asset
2
+ // when the CLI's legacy HTML pipeline targets ES5 (Android 5.x/6.x stock
3
+ // WebView, Chromium 37–44). The CLI's `tsc target=ES5` post-pass downlevels
4
+ // SYNTAX; this file's job is to fill the stdlib gaps tsc can't handle.
5
+ //
6
+ // Each guard is a feature detect — on engines that already have the method,
7
+ // the block is a no-op. Don't grow this file casually; every byte ships to
8
+ // every Android device.
9
+ //
10
+ // CRITICAL: this file must be built with terser `compress: false`. Terser's
11
+ // aggressive simplification of `typeof X.y !== "function"` patterns against
12
+ // known builtin members inverts feature-detect guards — the polyfill ends
13
+ // up skipping the engines that need it. See scripts/build.mjs.
14
+ (function (root) {
15
+ // No "use strict" — we deliberately mutate globals (Symbol/Set/Map),
16
+ // which strict mode wouldn't allow via bare assignment.
17
+
18
+ // Object.assign — Chromium 45+
19
+ if (typeof Object.assign !== "function") {
20
+ Object.defineProperty(Object, "assign", {
21
+ value: function (target) {
22
+ if (target == null) {
23
+ throw new TypeError("Cannot convert undefined or null to object");
24
+ }
25
+ var to = Object(target);
26
+ for (var i = 1; i < arguments.length; i++) {
27
+ var src = arguments[i];
28
+ if (src != null) {
29
+ for (var key in src) {
30
+ if (Object.prototype.hasOwnProperty.call(src, key)) {
31
+ to[key] = src[key];
32
+ }
33
+ }
34
+ }
35
+ }
36
+ return to;
37
+ },
38
+ writable: true,
39
+ configurable: true,
40
+ });
41
+ }
42
+
43
+ // Object.entries — Chromium 54+
44
+ if (typeof Object.entries !== "function") {
45
+ Object.entries = function (obj) {
46
+ var keys = Object.keys(obj);
47
+ var out = [];
48
+ for (var i = 0; i < keys.length; i++) {
49
+ out.push([keys[i], obj[keys[i]]]);
50
+ }
51
+ return out;
52
+ };
53
+ }
54
+
55
+ // Object.values — Chromium 54+
56
+ if (typeof Object.values !== "function") {
57
+ Object.values = function (obj) {
58
+ var keys = Object.keys(obj);
59
+ var out = [];
60
+ for (var i = 0; i < keys.length; i++) {
61
+ out.push(obj[keys[i]]);
62
+ }
63
+ return out;
64
+ };
65
+ }
66
+
67
+ // Array.from — Chromium 45+. Used by the bridge to snapshot Map iterators
68
+ // before mutating them, so this needs to handle Map/Set in addition to
69
+ // array-likes.
70
+ if (typeof Array.from !== "function") {
71
+ Array.from = function (source, mapFn, thisArg) {
72
+ if (source == null) {
73
+ throw new TypeError("Array.from requires an iterable or array-like");
74
+ }
75
+ var out = [];
76
+ // Map/Set iterators expose forEach; use it when length isn't present.
77
+ if (typeof source.length !== "number" && typeof source.forEach === "function") {
78
+ source.forEach(function (v) { out.push(v); });
79
+ } else {
80
+ var len = source.length >>> 0;
81
+ for (var i = 0; i < len; i++) {
82
+ out.push(source[i]);
83
+ }
84
+ }
85
+ if (typeof mapFn === "function") {
86
+ for (var j = 0; j < out.length; j++) {
87
+ out[j] = mapFn.call(thisArg, out[j], j);
88
+ }
89
+ }
90
+ return out;
91
+ };
92
+ }
93
+
94
+ // Array.prototype.includes — Chromium 47+
95
+ if (typeof Array.prototype.includes !== "function") {
96
+ Object.defineProperty(Array.prototype, "includes", {
97
+ value: function (target) {
98
+ var len = this.length >>> 0;
99
+ for (var i = 0; i < len; i++) {
100
+ // NaN-safe compare
101
+ if (this[i] === target || (target !== target && this[i] !== this[i])) {
102
+ return true;
103
+ }
104
+ }
105
+ return false;
106
+ },
107
+ writable: true,
108
+ configurable: true,
109
+ });
110
+ }
111
+
112
+ // Array.prototype.find / findIndex — Chromium 45+
113
+ if (typeof Array.prototype.find !== "function") {
114
+ Object.defineProperty(Array.prototype, "find", {
115
+ value: function (predicate) {
116
+ var len = this.length >>> 0;
117
+ var thisArg = arguments[1];
118
+ for (var i = 0; i < len; i++) {
119
+ if (predicate.call(thisArg, this[i], i, this)) return this[i];
120
+ }
121
+ return undefined;
122
+ },
123
+ writable: true,
124
+ configurable: true,
125
+ });
126
+ }
127
+ if (typeof Array.prototype.findIndex !== "function") {
128
+ Object.defineProperty(Array.prototype, "findIndex", {
129
+ value: function (predicate) {
130
+ var len = this.length >>> 0;
131
+ var thisArg = arguments[1];
132
+ for (var i = 0; i < len; i++) {
133
+ if (predicate.call(thisArg, this[i], i, this)) return i;
134
+ }
135
+ return -1;
136
+ },
137
+ writable: true,
138
+ configurable: true,
139
+ });
140
+ }
141
+
142
+ // String.prototype.startsWith / endsWith / includes — Chromium 41+
143
+ if (typeof String.prototype.startsWith !== "function") {
144
+ Object.defineProperty(String.prototype, "startsWith", {
145
+ value: function (search, pos) {
146
+ pos = pos || 0;
147
+ return this.substring(pos, pos + search.length) === String(search);
148
+ },
149
+ writable: true,
150
+ configurable: true,
151
+ });
152
+ }
153
+ if (typeof String.prototype.endsWith !== "function") {
154
+ Object.defineProperty(String.prototype, "endsWith", {
155
+ value: function (search, endPos) {
156
+ if (endPos === undefined || endPos > this.length) endPos = this.length;
157
+ return this.substring(endPos - search.length, endPos) === String(search);
158
+ },
159
+ writable: true,
160
+ configurable: true,
161
+ });
162
+ }
163
+ if (typeof String.prototype.includes !== "function") {
164
+ Object.defineProperty(String.prototype, "includes", {
165
+ value: function (search, start) {
166
+ return this.indexOf(search, start || 0) !== -1;
167
+ },
168
+ writable: true,
169
+ configurable: true,
170
+ });
171
+ }
172
+
173
+ // Number.isFinite — Chromium 19+, but missing on a few stock WebViews.
174
+ if (typeof Number.isFinite !== "function") {
175
+ Number.isFinite = function (value) {
176
+ return typeof value === "number" && isFinite(value);
177
+ };
178
+ }
179
+ if (typeof Number.isInteger !== "function") {
180
+ Number.isInteger = function (value) {
181
+ return typeof value === "number" && isFinite(value) && Math.floor(value) === value;
182
+ };
183
+ }
184
+
185
+ // Promise.prototype.finally — Chromium 63+. The page-runtime emits
186
+ // `.then(...).catch(...).finally(...)` chains, which crash with
187
+ // "undefined is not a function" on older WebViews.
188
+ if (typeof Promise !== "undefined" && typeof Promise.prototype.finally !== "function") {
189
+ Object.defineProperty(Promise.prototype, "finally", {
190
+ value: function (callback) {
191
+ var P = this.constructor || Promise;
192
+ return this.then(
193
+ function (value) {
194
+ return P.resolve(callback()).then(function () { return value; });
195
+ },
196
+ function (reason) {
197
+ return P.resolve(callback()).then(function () { throw reason; });
198
+ }
199
+ );
200
+ },
201
+ writable: true,
202
+ configurable: true,
203
+ });
204
+ }
205
+ // Promise.allSettled — Chromium 76+. Cheap to polyfill.
206
+ if (typeof Promise !== "undefined" && typeof Promise.allSettled !== "function") {
207
+ Promise.allSettled = function (promises) {
208
+ return Promise.all(
209
+ Array.prototype.map.call(promises, function (p) {
210
+ return Promise.resolve(p).then(
211
+ function (value) { return { status: "fulfilled", value: value }; },
212
+ function (reason) { return { status: "rejected", reason: reason }; }
213
+ );
214
+ })
215
+ );
216
+ };
217
+ }
218
+ // Promise.any — Chromium 85+. Rejects with AggregateError-ish object if all reject.
219
+ if (typeof Promise !== "undefined" && typeof Promise.any !== "function") {
220
+ Promise.any = function (promises) {
221
+ return new Promise(function (resolve, reject) {
222
+ var arr = [];
223
+ for (var i = 0; i < promises.length; i++) arr.push(promises[i]);
224
+ var errors = new Array(arr.length);
225
+ var remaining = arr.length;
226
+ if (remaining === 0) {
227
+ reject({ name: "AggregateError", errors: [], message: "All promises were rejected" });
228
+ return;
229
+ }
230
+ arr.forEach(function (p, idx) {
231
+ Promise.resolve(p).then(resolve, function (err) {
232
+ errors[idx] = err;
233
+ if (--remaining === 0) {
234
+ reject({ name: "AggregateError", errors: errors, message: "All promises were rejected" });
235
+ }
236
+ });
237
+ });
238
+ });
239
+ };
240
+ }
241
+
242
+ // Object.fromEntries — Chromium 73+. Used by lingxia-react components.
243
+ if (typeof Object.fromEntries !== "function") {
244
+ Object.fromEntries = function (iterable) {
245
+ var out = {};
246
+ if (iterable == null) return out;
247
+ if (typeof iterable.forEach === "function") {
248
+ iterable.forEach(function (pair) {
249
+ if (pair) out[pair[0]] = pair[1];
250
+ });
251
+ } else {
252
+ for (var i = 0; i < iterable.length; i++) {
253
+ var pair = iterable[i];
254
+ if (pair) out[pair[0]] = pair[1];
255
+ }
256
+ }
257
+ return out;
258
+ };
259
+ }
260
+
261
+ // String.prototype.padStart / padEnd — Chromium 57+. Used by lingxia-elements/picker.
262
+ if (typeof String.prototype.padStart !== "function") {
263
+ Object.defineProperty(String.prototype, "padStart", {
264
+ value: function (targetLength, padString) {
265
+ var s = String(this);
266
+ if (s.length >= targetLength) return s;
267
+ var pad = String(padString === undefined ? " " : padString);
268
+ if (pad.length === 0) return s;
269
+ var need = targetLength - s.length;
270
+ var prefix = "";
271
+ while (prefix.length < need) prefix += pad;
272
+ return prefix.slice(0, need) + s;
273
+ },
274
+ writable: true,
275
+ configurable: true,
276
+ });
277
+ }
278
+ if (typeof String.prototype.padEnd !== "function") {
279
+ Object.defineProperty(String.prototype, "padEnd", {
280
+ value: function (targetLength, padString) {
281
+ var s = String(this);
282
+ if (s.length >= targetLength) return s;
283
+ var pad = String(padString === undefined ? " " : padString);
284
+ if (pad.length === 0) return s;
285
+ var need = targetLength - s.length;
286
+ var suffix = "";
287
+ while (suffix.length < need) suffix += pad;
288
+ return s + suffix.slice(0, need);
289
+ },
290
+ writable: true,
291
+ configurable: true,
292
+ });
293
+ }
294
+ // String.prototype.trimStart / trimEnd — Chromium 66+.
295
+ if (typeof String.prototype.trimStart !== "function") {
296
+ Object.defineProperty(String.prototype, "trimStart", {
297
+ value: function () {
298
+ return String(this).replace(/^[\s\xA0]+/, "");
299
+ },
300
+ writable: true,
301
+ configurable: true,
302
+ });
303
+ }
304
+ if (typeof String.prototype.trimEnd !== "function") {
305
+ Object.defineProperty(String.prototype, "trimEnd", {
306
+ value: function () {
307
+ return String(this).replace(/[\s\xA0]+$/, "");
308
+ },
309
+ writable: true,
310
+ configurable: true,
311
+ });
312
+ }
313
+ // String.prototype.replaceAll — Chromium 85+.
314
+ if (typeof String.prototype.replaceAll !== "function") {
315
+ Object.defineProperty(String.prototype, "replaceAll", {
316
+ value: function (search, replacement) {
317
+ if (search instanceof RegExp) {
318
+ if (!search.global) {
319
+ throw new TypeError("String.prototype.replaceAll called with a non-global RegExp argument");
320
+ }
321
+ return String(this).replace(search, replacement);
322
+ }
323
+ // Build a global regex from the escaped literal.
324
+ var str = String(search).replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
325
+ return String(this).replace(new RegExp(str, "g"), replacement);
326
+ },
327
+ writable: true,
328
+ configurable: true,
329
+ });
330
+ }
331
+
332
+ // Array.prototype.flat / flatMap — Chromium 69+.
333
+ if (typeof Array.prototype.flat !== "function") {
334
+ Object.defineProperty(Array.prototype, "flat", {
335
+ value: function (depth) {
336
+ var d = depth === undefined ? 1 : Number(depth);
337
+ var out = [];
338
+ (function rec(arr, level) {
339
+ for (var i = 0; i < arr.length; i++) {
340
+ var v = arr[i];
341
+ if (Array.isArray(v) && level > 0) rec(v, level - 1);
342
+ else out.push(v);
343
+ }
344
+ })(this, d);
345
+ return out;
346
+ },
347
+ writable: true,
348
+ configurable: true,
349
+ });
350
+ }
351
+ if (typeof Array.prototype.flatMap !== "function") {
352
+ Object.defineProperty(Array.prototype, "flatMap", {
353
+ value: function (callback, thisArg) {
354
+ var mapped = Array.prototype.map.call(this, callback, thisArg);
355
+ return Array.prototype.flat.call(mapped, 1);
356
+ },
357
+ writable: true,
358
+ configurable: true,
359
+ });
360
+ }
361
+ // Array.prototype.at — Chromium 92+. Sugar for negative indexing.
362
+ if (typeof Array.prototype.at !== "function") {
363
+ Object.defineProperty(Array.prototype, "at", {
364
+ value: function (index) {
365
+ var n = Math.trunc(Number(index)) || 0;
366
+ if (n < 0) n += this.length;
367
+ if (n < 0 || n >= this.length) return undefined;
368
+ return this[n];
369
+ },
370
+ writable: true,
371
+ configurable: true,
372
+ });
373
+ }
374
+
375
+ // globalThis — Chromium 71+. Can't polyfill the keyword itself, but we can
376
+ // assign a property on the global object so `typeof globalThis !== "undefined"`
377
+ // checks pass. Code that uses `globalThis.X` will still need the property
378
+ // to exist on `window` already (which is the same object).
379
+ if (typeof root.globalThis === "undefined") {
380
+ try { root.globalThis = root; } catch (e) { /* property may be non-writable */ }
381
+ }
382
+
383
+ // Android 5.0 stock WebView (Chromium 37) is missing Symbol, Set, Map.
384
+ // 5.1 (Chromium 39) has them. Below shims are intentionally minimal —
385
+ // they cover the bridge/page-runtime usage and nothing else.
386
+
387
+ // Symbol — Chromium 38+. Real Symbol can't be polyfilled; this shim
388
+ // returns unique strings, so `typeof Symbol(...) === "symbol"` will be
389
+ // false. Callers in our codebase only use Symbol as a unique key for
390
+ // Object.defineProperty / property access, which works fine with strings.
391
+ var symbolCounter = 0;
392
+ if (typeof Symbol === "undefined") {
393
+ var SymbolShim = function (description) {
394
+ var key = "@@_sym_" + (++symbolCounter) + "_" + (description || "");
395
+ return key;
396
+ };
397
+ SymbolShim.iterator = SymbolShim("Symbol.iterator");
398
+ SymbolShim.asyncIterator = SymbolShim("Symbol.asyncIterator");
399
+ SymbolShim.toStringTag = SymbolShim("Symbol.toStringTag");
400
+ var symbolForRegistry = {};
401
+ SymbolShim["for"] = function (key) {
402
+ var k = String(key);
403
+ if (!Object.prototype.hasOwnProperty.call(symbolForRegistry, k)) {
404
+ symbolForRegistry[k] = SymbolShim(k);
405
+ }
406
+ return symbolForRegistry[k];
407
+ };
408
+ root.Symbol = SymbolShim;
409
+ }
410
+
411
+ // Set — Chromium 38+. Minimal: add/has/delete/clear/forEach/size.
412
+ if (typeof Set === "undefined") {
413
+ var SetShim = function (iterable) {
414
+ this._items = [];
415
+ var self = this;
416
+ if (iterable != null) {
417
+ if (typeof iterable.forEach === "function") {
418
+ iterable.forEach(function (v) { self.add(v); });
419
+ } else if (typeof iterable.length === "number") {
420
+ for (var i = 0; i < iterable.length; i++) self.add(iterable[i]);
421
+ }
422
+ }
423
+ };
424
+ SetShim.prototype.add = function (value) {
425
+ if (this._items.indexOf(value) === -1) this._items.push(value);
426
+ return this;
427
+ };
428
+ SetShim.prototype.has = function (value) {
429
+ return this._items.indexOf(value) !== -1;
430
+ };
431
+ SetShim.prototype["delete"] = function (value) {
432
+ var idx = this._items.indexOf(value);
433
+ if (idx === -1) return false;
434
+ this._items.splice(idx, 1);
435
+ return true;
436
+ };
437
+ SetShim.prototype.clear = function () { this._items.length = 0; };
438
+ SetShim.prototype.forEach = function (callback, thisArg) {
439
+ // Snapshot to mirror native semantics: re-entrant add during iteration
440
+ // doesn't affect this pass.
441
+ var copy = this._items.slice();
442
+ for (var i = 0; i < copy.length; i++) {
443
+ callback.call(thisArg, copy[i], copy[i], this);
444
+ }
445
+ };
446
+ Object.defineProperty(SetShim.prototype, "size", {
447
+ get: function () { return this._items.length; },
448
+ });
449
+ root.Set = SetShim;
450
+ }
451
+
452
+ // Map — Chromium 38+. Minimal: get/set/has/delete/clear/forEach/size/keys/values/entries.
453
+ if (typeof Map === "undefined") {
454
+ var MapShim = function (iterable) {
455
+ this._keys = [];
456
+ this._values = [];
457
+ var self = this;
458
+ if (iterable != null && typeof iterable.forEach === "function") {
459
+ iterable.forEach(function (entry) { self.set(entry[0], entry[1]); });
460
+ } else if (iterable != null && typeof iterable.length === "number") {
461
+ for (var i = 0; i < iterable.length; i++) {
462
+ self.set(iterable[i][0], iterable[i][1]);
463
+ }
464
+ }
465
+ };
466
+ MapShim.prototype.get = function (key) {
467
+ var idx = this._keys.indexOf(key);
468
+ return idx === -1 ? undefined : this._values[idx];
469
+ };
470
+ MapShim.prototype.set = function (key, value) {
471
+ var idx = this._keys.indexOf(key);
472
+ if (idx === -1) {
473
+ this._keys.push(key);
474
+ this._values.push(value);
475
+ } else {
476
+ this._values[idx] = value;
477
+ }
478
+ return this;
479
+ };
480
+ MapShim.prototype.has = function (key) {
481
+ return this._keys.indexOf(key) !== -1;
482
+ };
483
+ MapShim.prototype["delete"] = function (key) {
484
+ var idx = this._keys.indexOf(key);
485
+ if (idx === -1) return false;
486
+ this._keys.splice(idx, 1);
487
+ this._values.splice(idx, 1);
488
+ return true;
489
+ };
490
+ MapShim.prototype.clear = function () {
491
+ this._keys.length = 0;
492
+ this._values.length = 0;
493
+ };
494
+ MapShim.prototype.forEach = function (callback, thisArg) {
495
+ var keysCopy = this._keys.slice();
496
+ var valuesCopy = this._values.slice();
497
+ for (var i = 0; i < keysCopy.length; i++) {
498
+ callback.call(thisArg, valuesCopy[i], keysCopy[i], this);
499
+ }
500
+ };
501
+ MapShim.prototype.keys = function () { return this._keys.slice(); };
502
+ MapShim.prototype.values = function () { return this._values.slice(); };
503
+ MapShim.prototype.entries = function () {
504
+ var out = [];
505
+ for (var i = 0; i < this._keys.length; i++) {
506
+ out.push([this._keys[i], this._values[i]]);
507
+ }
508
+ return out;
509
+ };
510
+ Object.defineProperty(MapShim.prototype, "size", {
511
+ get: function () { return this._keys.length; },
512
+ });
513
+ root.Map = MapShim;
514
+ }
515
+ })(typeof window !== "undefined" ? window : this);