Skip to content

Commit efbb5ec

Browse files
florian-lefebvreAndroz2091
andauthoredAug 1, 2023
fix: support iOS (#523)
Hi there! We're developing an open-source app (https://github.com/dumpus-app/dumpus-app) and use satori to render some images client-side. However, we encountered the following error on both ios web (safari) and capacitor (that uses safari webview) on a lot of iOS devices: ```bash Invalid regular expression: invalid group specifier name ``` After investigating, we found out it's caused by [regex lookbehind](https://stackoverflow.com/questions/51568821/works-in-chrome-but-breaks-in-safari-invalid-regular-expression-invalid-group) not being [supported until iOS 16.4](https://caniuse.com/js-regexp-lookbehind). This PR replaces this regex by some quite hacky code because we needed a hotfix. If anybody wants to update the regex in order not to use `lookbehind` feature, feel free to do so!. If you want to test it, you can use satori on the web using the following package json version: ```json "satori": "dumpus-app/satori#fix-safari-compatibility-build" ``` Thanks for your time! Co-authored-by: Androz2091 <androz2091@gmail.com>
1 parent 2e8dcb4 commit efbb5ec

File tree

1 file changed

+29
-13
lines changed

1 file changed

+29
-13
lines changed
 

‎src/parser/mask.ts

+29-13
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,33 @@ export interface MaskProperty {
1414
clip: string
1515
}
1616

17+
function splitMaskImages(maskImage) {
18+
let maskImages = []
19+
let start = 0
20+
let parenCount = 0
21+
22+
for (let i = 0; i < maskImage.length; i++) {
23+
if (maskImage[i] === '(') {
24+
parenCount++
25+
} else if (maskImage[i] === ')') {
26+
parenCount--
27+
}
28+
29+
if (parenCount === 0 && maskImage[i] === ',') {
30+
maskImages.push(maskImage.slice(start, i).trim())
31+
start = i + 1
32+
}
33+
}
34+
35+
maskImages.push(maskImage.slice(start).trim())
36+
37+
return maskImages
38+
}
39+
1740
/**
1841
* url(https:a.png), linear-gradient(blue, red) => [url(https:a.png), linear-gradient(blue, red)]
1942
* rgba(0,0,0,.7) => [rgba(0,0,0,.7)]
2043
*/
21-
const SPILIT_SOURCE_COMMOA_RE = /(?<=\))(?:\s*,\s*)/
2244

2345
export function parseMask(
2446
style: Record<string, string | number>
@@ -33,16 +55,10 @@ export function parseMask(
3355
clip: getMaskProperty(style, 'origin') || 'border-box',
3456
}
3557

36-
return (
37-
maskImage
38-
.split(SPILIT_SOURCE_COMMOA_RE)
39-
// https://www.w3.org/TR/css-backgrounds-3/#layering
40-
.reverse()
41-
.map((v) => v.trim())
42-
.filter((v) => v && v !== 'none')
43-
.map((m) => ({
44-
image: m,
45-
...common,
46-
}))
47-
)
58+
let maskImages = splitMaskImages(maskImage).filter((v) => v && v !== 'none')
59+
60+
return maskImages.reverse().map((m) => ({
61+
image: m,
62+
...common,
63+
}))
4864
}

1 commit comments

Comments
 (1)

vercel[bot] commented on Aug 1, 2023

@vercel[bot]
Please sign in to comment.