@thunderid/browser 1.0.6 → 1.0.9
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.
- package/dist/cjs/index.cjs +21 -7
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.js +21 -7
- package/dist/index.js.map +1 -1
- package/dist/utils/generateAvatarDataUri.d.ts.map +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -3631,6 +3631,23 @@ const AVATAR_PALETTES = [
|
|
|
3631
3631
|
* without needing the actual palette values.
|
|
3632
3632
|
*/
|
|
3633
3633
|
const AVATAR_GRADIENT_COUNT = AVATAR_PALETTES.length;
|
|
3634
|
+
const XML_ESCAPES = {
|
|
3635
|
+
"\"": """,
|
|
3636
|
+
"&": "&",
|
|
3637
|
+
"'": "'",
|
|
3638
|
+
"<": "<",
|
|
3639
|
+
">": ">"
|
|
3640
|
+
};
|
|
3641
|
+
/**
|
|
3642
|
+
* Escapes a caller-supplied value for interpolation into SVG text.
|
|
3643
|
+
*/
|
|
3644
|
+
const escapeXml = (value) => value.replace(/["&'<>]/g, (ch) => XML_ESCAPES[ch]);
|
|
3645
|
+
/**
|
|
3646
|
+
* Encodes an SVG document as a data URI. Lone UTF-16 surrogates are replaced with U+FFFD
|
|
3647
|
+
* first, since `encodeURIComponent` throws a `URIError` on them. `Array.from` iterates by
|
|
3648
|
+
* code point, so a surrogate it yields on its own is unpaired.
|
|
3649
|
+
*/
|
|
3650
|
+
const toSvgDataUri = (svg) => `data:image/svg+xml,${encodeURIComponent(Array.from(svg, (ch) => ch.length === 1 && ch >= "\ud800" && ch <= "\udfff" ? "�" : ch).join(""))}`;
|
|
3634
3651
|
/**
|
|
3635
3652
|
* Fills in `params.content` when the spec itself didn't carry one, deriving it from a raw
|
|
3636
3653
|
* seed name (e.g. an app or user display name) — extracting initials for letter variants,
|
|
@@ -3681,11 +3698,10 @@ const generateGradientAvatar = ({ shape, variant, content, colors, bg }) => {
|
|
|
3681
3698
|
let text = "";
|
|
3682
3699
|
if (variant !== "blank") {
|
|
3683
3700
|
const letterCount = variant === "one_letter" ? 1 : 2;
|
|
3684
|
-
const initials = (content || "A").toUpperCase().slice(0, letterCount);
|
|
3701
|
+
const initials = escapeXml(Array.from((content || "A").toUpperCase()).slice(0, letterCount).join(""));
|
|
3685
3702
|
text = `<text x="50" y="64" font-family="Helvetica,Arial,sans-serif" font-weight="700" font-size="${letterCount === 1 ? 46 : 34}" text-anchor="middle" fill="#fff">${initials}</text>`;
|
|
3686
3703
|
}
|
|
3687
|
-
|
|
3688
|
-
return `data:image/svg+xml,${encodeURIComponent(svg)}`;
|
|
3704
|
+
return toSvgDataUri(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">${defs}${shapeMarkup(shape, background)}${text}</svg>`);
|
|
3689
3705
|
};
|
|
3690
3706
|
/**
|
|
3691
3707
|
* Renders one of the curated anonymous-animal icons, applying the requested background
|
|
@@ -3697,8 +3713,7 @@ const generateAnonymousAnimalAvatar = ({ shape, content, bg }) => {
|
|
|
3697
3713
|
const icon = ANONYMOUS_ANIMAL_ICONS[Object.prototype.hasOwnProperty.call(ANONYMOUS_ANIMAL_ICONS, content) ? content : pickAnonymousAvatarName_default()];
|
|
3698
3714
|
const color = bg ?? icon.color;
|
|
3699
3715
|
const markup = icon.markup.replaceAll("%COLOR%", color);
|
|
3700
|
-
|
|
3701
|
-
return `data:image/svg+xml,${encodeURIComponent(svg)}`;
|
|
3716
|
+
return toSvgDataUri(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">${shapeMarkup(shape, color)}${markup}</svg>`);
|
|
3702
3717
|
};
|
|
3703
3718
|
/**
|
|
3704
3719
|
* Renders one of the curated anonymous-entity icons (application/organization/resource-server
|
|
@@ -3710,8 +3725,7 @@ const generateAnonymousEntityAvatar = ({ shape, content, bg }) => {
|
|
|
3710
3725
|
const icon = ANONYMOUS_ENTITY_ICONS[Object.prototype.hasOwnProperty.call(ANONYMOUS_ENTITY_ICONS, content) ? content : pickAnonymousEntityName_default()];
|
|
3711
3726
|
const color = bg ?? icon.color;
|
|
3712
3727
|
const markup = icon.markup.replaceAll("%COLOR%", color);
|
|
3713
|
-
|
|
3714
|
-
return `data:image/svg+xml,${encodeURIComponent(svg)}`;
|
|
3728
|
+
return toSvgDataUri(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">${shapeMarkup(shape, color)}${markup}</svg>`);
|
|
3715
3729
|
};
|
|
3716
3730
|
/**
|
|
3717
3731
|
* Generates an avatar image as an `svg+xml` data URI from a fully-resolved {@link AvatarParams}.
|