From 9fb20517ae0f6f755818209dbc927f5bdc21089b Mon Sep 17 00:00:00 2001 From: dan Date: Wed, 1 Nov 2023 16:52:34 +0000 Subject: [PATCH] Remove unused Intl.Segmenter polyfill (#1789) --- package.json | 1 - src/platform/polyfills.ts | 16 ---------------- src/platform/polyfills.web.ts | 6 +----- web/static/js/intl-segmenter-polyfill.min.js | 2 -- 4 files changed, 1 insertion(+), 24 deletions(-) delete mode 100644 web/static/js/intl-segmenter-polyfill.min.js diff --git a/package.json b/package.json index 3a91528c..66f7cfbb 100644 --- a/package.json +++ b/package.json @@ -102,7 +102,6 @@ "expo-system-ui": "~2.4.0", "expo-updates": "~0.18.12", "fast-text-encoding": "^1.0.6", - "graphemer": "^1.4.0", "history": "^5.3.0", "js-sha256": "^0.9.0", "lande": "^1.0.10", diff --git a/src/platform/polyfills.ts b/src/platform/polyfills.ts index c26c864c..807cc492 100644 --- a/src/platform/polyfills.ts +++ b/src/platform/polyfills.ts @@ -1,5 +1,4 @@ import 'fast-text-encoding' -import Graphemer from 'graphemer' // @ts-ignore no decl -prf import findLast from 'array.prototype.findlast' export {} @@ -54,18 +53,3 @@ globalThis.atob = (str: string): string => { } return result } - -const splitter = new Graphemer() -globalThis.Intl = globalThis.Intl || {} - -// @ts-ignore we're polyfilling -prf -globalThis.Intl.Segmenter = - // @ts-ignore we're polyfilling -prf - globalThis.Intl.Segmenter || - class Segmenter { - constructor() {} - // NOTE - // this is not a precisely correct polyfill but it's sufficient for our needs - // -prf - segment = splitter.iterateGraphemes - } diff --git a/src/platform/polyfills.web.ts b/src/platform/polyfills.web.ts index 1df661d7..acd8fd9e 100644 --- a/src/platform/polyfills.web.ts +++ b/src/platform/polyfills.web.ts @@ -9,12 +9,8 @@ window.setImmediate = (cb: () => void) => setTimeout(cb, 0) // @ts-ignore not on the TS signature due to bad support -prf if (!globalThis.Intl?.Segmenter) { - // NOTE loading as a separate script to reduce main bundle size, as this is only needed in FF -prf - const script = document.createElement('script') - script.setAttribute('src', '/static/js/intl-segmenter-polyfill.min.js') - document.head.appendChild(script) - // loading emoji mart data + // TODO: This condition doesn't make sense; emojimart has nothing to do with Intl. const emojiMartScript = document.createElement('script') emojiMartScript.setAttribute('src', '/static/js/emoji-mart-data.js') document.head.appendChild(emojiMartScript) diff --git a/web/static/js/intl-segmenter-polyfill.min.js b/web/static/js/intl-segmenter-polyfill.min.js deleted file mode 100644 index bdd9af2d..00000000 --- a/web/static/js/intl-segmenter-polyfill.min.js +++ /dev/null @@ -1,2 +0,0 @@ -var k=Object.create;var M=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var j=Object.getPrototypeOf,F=Object.prototype.hasOwnProperty;var l=(x,E)=>()=>(E||x((E={exports:{}}).exports,E),E.exports);var Z=(x,E,R,i)=>{if(E&&typeof E=="object"||typeof E=="function")for(let T of y(E))!F.call(x,T)&&T!==R&&M(x,T,{get:()=>E[T],enumerable:!(i=m(E,T))||i.enumerable});return x};var J=(x,E,R)=>(R=x!=null?k(j(x)):{},Z(E||!x||!x.__esModule?M(R,"default",{value:x,enumerable:!0}):R,x));var V=l(K=>{"use strict";Object.defineProperty(K,"__esModule",{value:!0});K.EXTENDED_PICTOGRAPHIC=K.CLUSTER_BREAK=void 0;var W;(function(x){x[x.CR=0]="CR",x[x.LF=1]="LF",x[x.CONTROL=2]="CONTROL",x[x.EXTEND=3]="EXTEND",x[x.REGIONAL_INDICATOR=4]="REGIONAL_INDICATOR",x[x.SPACINGMARK=5]="SPACINGMARK",x[x.L=6]="L",x[x.V=7]="V",x[x.T=8]="T",x[x.LV=9]="LV",x[x.LVT=10]="LVT",x[x.OTHER=11]="OTHER",x[x.PREPEND=12]="PREPEND",x[x.E_BASE=13]="E_BASE",x[x.E_MODIFIER=14]="E_MODIFIER",x[x.ZWJ=15]="ZWJ",x[x.GLUE_AFTER_ZWJ=16]="GLUE_AFTER_ZWJ",x[x.E_BASE_GAZ=17]="E_BASE_GAZ"})(W=K.CLUSTER_BREAK||(K.CLUSTER_BREAK={}));K.EXTENDED_PICTOGRAPHIC=101});var O=l(X=>{"use strict";Object.defineProperty(X,"__esModule",{value:!0});var r=V(),u=0,N=1,w=2,q=3,z=4,D=class{static isSurrogate(E,R){return 55296<=E.charCodeAt(R)&&E.charCodeAt(R)<=56319&&56320<=E.charCodeAt(R+1)&&E.charCodeAt(R+1)<=57343}static codePointAt(E,R){R===void 0&&(R=0);let i=E.charCodeAt(R);if(55296<=i&&i<=56319&&R=1){let T=E.charCodeAt(R-1),t=i;return 55296<=T&&T<=56319?(T-55296)*1024+(t-56320)+65536:t}return i}static shouldBreak(E,R,i,T,t,_){let n=[E].concat(R).concat([i]),S=[T].concat(t).concat([_]),A=n[n.length-2],L=i,B=_,G=n.lastIndexOf(r.CLUSTER_BREAK.REGIONAL_INDICATOR);if(G>0&&n.slice(1,G).every(function(s){return s===r.CLUSTER_BREAK.REGIONAL_INDICATOR})&&[r.CLUSTER_BREAK.PREPEND,r.CLUSTER_BREAK.REGIONAL_INDICATOR].indexOf(A)===-1)return n.filter(function(s){return s===r.CLUSTER_BREAK.REGIONAL_INDICATOR}).length%2===1?q:z;if(A===r.CLUSTER_BREAK.CR&&L===r.CLUSTER_BREAK.LF)return u;if(A===r.CLUSTER_BREAK.CONTROL||A===r.CLUSTER_BREAK.CR||A===r.CLUSTER_BREAK.LF)return N;if(L===r.CLUSTER_BREAK.CONTROL||L===r.CLUSTER_BREAK.CR||L===r.CLUSTER_BREAK.LF)return N;if(A===r.CLUSTER_BREAK.L&&(L===r.CLUSTER_BREAK.L||L===r.CLUSTER_BREAK.V||L===r.CLUSTER_BREAK.LV||L===r.CLUSTER_BREAK.LVT))return u;if((A===r.CLUSTER_BREAK.LV||A===r.CLUSTER_BREAK.V)&&(L===r.CLUSTER_BREAK.V||L===r.CLUSTER_BREAK.T))return u;if((A===r.CLUSTER_BREAK.LVT||A===r.CLUSTER_BREAK.T)&&L===r.CLUSTER_BREAK.T)return u;if(L===r.CLUSTER_BREAK.EXTEND||L===r.CLUSTER_BREAK.ZWJ)return u;if(L===r.CLUSTER_BREAK.SPACINGMARK)return u;if(A===r.CLUSTER_BREAK.PREPEND)return u;let a=S.slice(0,-1).lastIndexOf(r.EXTENDED_PICTOGRAPHIC);return a!==-1&&S[a]===r.EXTENDED_PICTOGRAPHIC&&n.slice(a+1,-2).every(function(s){return s===r.CLUSTER_BREAK.EXTEND})&&A===r.CLUSTER_BREAK.ZWJ&&B===r.EXTENDED_PICTOGRAPHIC?u:R.indexOf(r.CLUSTER_BREAK.REGIONAL_INDICATOR)!==-1?w:A===r.CLUSTER_BREAK.REGIONAL_INDICATOR&&L===r.CLUSTER_BREAK.REGIONAL_INDICATOR?u:N}};X.default=D});var H=l(I=>{"use strict";Object.defineProperty(I,"__esModule",{value:!0});var P=class{constructor(E,R){this._index=0,this._str=E,this._nextBreak=R}[Symbol.iterator](){return this}next(){let E;if((E=this._nextBreak(this._str,this._index)){"use strict";var h=b&&b.__importDefault||function(x){return x&&x.__esModule?x:{default:x}};Object.defineProperty(b,"__esModule",{value:!0});var f=V(),U=h(O()),Q=h(H()),C=class{static nextBreak(E,R){if(R===void 0&&(R=0),R<0)return 0;if(R>=E.length-1)return E.length;let i=U.default.codePointAt(E,R),T=C.getGraphemeBreakProperty(i),t=C.getEmojiProperty(i),_=[],n=[];for(let S=R+1;S{"use strict";var Y=e&&e.__importDefault||function(x){return x&&x.__esModule?x:{default:x}};Object.defineProperty(e,"__esModule",{value:!0});var $=Y(g());e.default=$.default});var v=J(p()),c=new v.default;globalThis.Intl=globalThis.Intl||{};globalThis.Intl.Segmenter=globalThis.Intl.Segmenter||class{constructor(){}segment=c.iterateGraphemes}; -