react-smart-copy 1.17.1 → 1.18.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.
- package/README.md +22 -3
- package/dist/capture.cjs +30 -153
- package/dist/capture.cjs.map +1 -1
- package/dist/capture.d.cts +2 -25
- package/dist/capture.d.ts +2 -25
- package/dist/capture.js +5 -128
- package/dist/capture.js.map +1 -1
- package/dist/chunks/clipboard-adapter-Cfz-rzw3.cjs +102 -0
- package/dist/chunks/clipboard-adapter-Cfz-rzw3.cjs.map +1 -0
- package/dist/chunks/clipboard-adapter-CtH4VELE.d.cts +43 -0
- package/dist/chunks/clipboard-adapter-DEXkXxwV.js +97 -0
- package/dist/chunks/clipboard-adapter-DEXkXxwV.js.map +1 -0
- package/dist/chunks/clipboard-adapter-Ds0irroN.d.ts +43 -0
- package/dist/chunks/contrast-C6CVklEI.cjs +842 -0
- package/dist/chunks/contrast-C6CVklEI.cjs.map +1 -0
- package/dist/chunks/contrast-DpK2JIVu.js +789 -0
- package/dist/chunks/contrast-DpK2JIVu.js.map +1 -0
- package/dist/chunks/copy-interceptor-C6NABy1l.d.ts +141 -0
- package/dist/chunks/copy-interceptor-CZWzGOkL.d.cts +141 -0
- package/dist/chunks/core-Cp2HSpaz.js +1035 -0
- package/dist/chunks/core-Cp2HSpaz.js.map +1 -0
- package/dist/chunks/core-DYf_Lhbe.cjs +1142 -0
- package/dist/chunks/core-DYf_Lhbe.cjs.map +1 -0
- package/dist/chunks/deadline-C29AlS_Q.js +46 -0
- package/dist/chunks/deadline-C29AlS_Q.js.map +1 -0
- package/dist/chunks/deadline-DkiB8ZHE.cjs +51 -0
- package/dist/chunks/deadline-DkiB8ZHE.cjs.map +1 -0
- package/dist/chunks/errors-9h8sdFFX.js +120 -0
- package/dist/chunks/errors-9h8sdFFX.js.map +1 -0
- package/dist/chunks/errors-BwOF6T_M.cjs +167 -0
- package/dist/chunks/errors-BwOF6T_M.cjs.map +1 -0
- package/dist/chunks/index-mr7sSAgP.d.ts +426 -0
- package/dist/chunks/index-vz0iW5V2.d.cts +426 -0
- package/dist/chunks/mime--LB7kdqG.cjs +153 -0
- package/dist/chunks/mime--LB7kdqG.cjs.map +1 -0
- package/dist/chunks/mime-aa-HA2dm.js +100 -0
- package/dist/chunks/mime-aa-HA2dm.js.map +1 -0
- package/dist/chunks/paste-adapter--SPL4PRE.d.cts +35 -0
- package/dist/chunks/paste-adapter-uahXnTYk.d.ts +35 -0
- package/dist/chunks/paste-reader-Bo01IMC_.cjs +289 -0
- package/dist/chunks/paste-reader-Bo01IMC_.cjs.map +1 -0
- package/dist/chunks/paste-reader-D9i7yMXF.js +224 -0
- package/dist/chunks/paste-reader-D9i7yMXF.js.map +1 -0
- package/dist/chunks/paste-reader-DcXnRWQr.d.cts +96 -0
- package/dist/chunks/paste-reader-DcXnRWQr.d.ts +96 -0
- package/dist/chunks/payload-CUymxwim.cjs +100 -0
- package/dist/chunks/payload-CUymxwim.cjs.map +1 -0
- package/dist/chunks/payload-CcwKJ_bU.d.cts +162 -0
- package/dist/chunks/payload-Cl_8hCI5.d.ts +162 -0
- package/dist/chunks/payload-DGw-JOo7.js +71 -0
- package/dist/chunks/payload-DGw-JOo7.js.map +1 -0
- package/dist/chunks/payload-DI5AorDz.js +103 -0
- package/dist/chunks/payload-DI5AorDz.js.map +1 -0
- package/dist/chunks/payload-J6GjHuh3.cjs +132 -0
- package/dist/chunks/payload-J6GjHuh3.cjs.map +1 -0
- package/dist/chunks/share-Bop47Znn.js +208 -0
- package/dist/chunks/share-Bop47Znn.js.map +1 -0
- package/dist/chunks/share-C0esXvRK.d.cts +115 -0
- package/dist/chunks/share-ayDz974N.cjs +231 -0
- package/dist/chunks/share-ayDz974N.cjs.map +1 -0
- package/dist/chunks/share-e7FenIr2.d.ts +115 -0
- package/dist/chunks/text-field-Ba8W3v4R.cjs +77 -0
- package/dist/chunks/text-field-Ba8W3v4R.cjs.map +1 -0
- package/dist/chunks/text-field-C0SGmvvR.d.cts +18 -0
- package/dist/chunks/text-field-C0SGmvvR.d.ts +18 -0
- package/dist/chunks/text-field-DUvrMMaK.js +66 -0
- package/dist/chunks/text-field-DUvrMMaK.js.map +1 -0
- package/dist/chunks/url-BcMYVCXQ.js +135 -0
- package/dist/chunks/url-BcMYVCXQ.js.map +1 -0
- package/dist/chunks/url-D4PGsRm8.cjs +164 -0
- package/dist/chunks/url-D4PGsRm8.cjs.map +1 -0
- package/dist/chunks/url-DWdElCT3.d.cts +43 -0
- package/dist/chunks/url-DWdElCT3.d.ts +43 -0
- package/dist/code.cjs +20 -109
- package/dist/code.cjs.map +1 -1
- package/dist/code.d.cts +4 -28
- package/dist/code.d.ts +4 -28
- package/dist/code.js +4 -93
- package/dist/code.js.map +1 -1
- package/dist/color.cjs +21 -893
- package/dist/color.cjs.map +1 -1
- package/dist/color.d.cts +4 -28
- package/dist/color.d.ts +4 -28
- package/dist/color.js +4 -876
- package/dist/color.js.map +1 -1
- package/dist/core.cjs +52 -1659
- package/dist/core.d.cts +8 -878
- package/dist/core.d.ts +8 -878
- package/dist/core.js +7 -1614
- package/dist/image.cjs +23 -91
- package/dist/image.cjs.map +1 -1
- package/dist/image.d.cts +1 -0
- package/dist/image.d.ts +1 -0
- package/dist/image.js +5 -73
- package/dist/image.js.map +1 -1
- package/dist/index.cjs +74 -2072
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -978
- package/dist/index.d.ts +8 -978
- package/dist/index.js +7 -2005
- package/dist/index.js.map +1 -1
- package/dist/link.cjs +24 -338
- package/dist/link.cjs.map +1 -1
- package/dist/link.d.cts +5 -83
- package/dist/link.d.ts +5 -83
- package/dist/link.js +5 -319
- package/dist/link.js.map +1 -1
- package/dist/markdown.cjs +8 -97
- package/dist/markdown.cjs.map +1 -1
- package/dist/markdown.d.cts +3 -16
- package/dist/markdown.d.ts +3 -16
- package/dist/markdown.js +3 -92
- package/dist/markdown.js.map +1 -1
- package/dist/rich.cjs +26 -934
- package/dist/rich.cjs.map +1 -1
- package/dist/rich.d.cts +4 -90
- package/dist/rich.d.ts +4 -90
- package/dist/rich.js +4 -912
- package/dist/rich.js.map +1 -1
- package/dist/share.cjs +5 -640
- package/dist/share.d.cts +3 -248
- package/dist/share.d.ts +3 -248
- package/dist/share.js +1 -637
- package/dist/structured.cjs +13 -95
- package/dist/structured.cjs.map +1 -1
- package/dist/structured.d.cts +2 -11
- package/dist/structured.d.ts +2 -11
- package/dist/structured.js +4 -86
- package/dist/structured.js.map +1 -1
- package/dist/table.cjs +11 -39
- package/dist/table.cjs.map +1 -1
- package/dist/table.d.cts +2 -12
- package/dist/table.d.ts +2 -12
- package/dist/table.js +2 -30
- package/dist/table.js.map +1 -1
- package/dist/testing.cjs +10 -43
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.d.cts +6 -181
- package/dist/testing.d.ts +6 -181
- package/dist/testing.js +3 -36
- package/dist/testing.js.map +1 -1
- package/package.json +20 -2
- package/dist/core.cjs.map +0 -1
- package/dist/core.js.map +0 -1
- package/dist/share.cjs.map +0 -1
- package/dist/share.js.map +0 -1
package/dist/color.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"color.js","names":[],"sources":["../src/color/convert.ts","../src/core/errors.ts","../src/color/names.ts","../src/color/parse.ts","../src/color/format.ts","../src/color/contrast.ts","../src/core/text-field.ts","../src/color/payload.ts"],"sourcesContent":["/**\n * Colour space conversions, from the CSS Color 4 specification's sample code.\n * A {@link Color} is stored as extended sRGB: gamma-encoded r, g and b, which go\n * below 0 or above 1 for colours outside sRGB (a Display P3 or OKLCH colour), and\n * alpha in [0, 1]. Every conversion keeps such colours exact until a format needs\n * them in a gamut.\n */\n\n/** A colour: extended sRGB channels (0 to 1 inside sRGB) and alpha (0 to 1). */\nexport interface Color {\n readonly r: number;\n readonly g: number;\n readonly b: number;\n readonly alpha: number;\n}\n\nexport type Vec3 = readonly [number, number, number];\ntype Mat3 = readonly [Vec3, Vec3, Vec3];\n\n/** The gamuts a colour can be mapped into: sRGB (every screen) and Display P3 (wide-gamut screens). */\nexport type Gamut = 'srgb' | 'p3';\n\nexport const color = (r: number, g: number, b: number, alpha = 1): Color => Object.freeze({ r, g, b, alpha });\n\nconst mul = (m: Mat3, [x, y, z]: Vec3): Vec3 => [\n m[0][0] * x + m[0][1] * y + m[0][2] * z,\n m[1][0] * x + m[1][1] * y + m[1][2] * z,\n m[2][0] * x + m[2][1] * y + m[2][2] * z,\n];\n\n/** The sRGB (and Display P3) transfer function, extended to negative values by symmetry. */\nconst toLinear = (c: number): number => {\n const abs = Math.abs(c);\n return abs <= 0.04045 ? c / 12.92 : Math.sign(c) * ((abs + 0.055) / 1.055) ** 2.4;\n};\nconst fromLinear = (c: number): number => {\n const abs = Math.abs(c);\n return abs > 0.0031308 ? Math.sign(c) * (1.055 * abs ** (1 / 2.4) - 0.055) : 12.92 * c;\n};\n\n/** Applies `f` to each component; the result stays a three-component vector. */\nexport const map3 = ([x, y, z]: Vec3, f: (v: number, i: 0 | 1 | 2) => number): Vec3 => [f(x, 0), f(y, 1), f(z, 2)];\n/** Three numbers as a vector, or null when one is missing. */\nexport const vec3 = ([x, y, z]: readonly (number | null)[]): Vec3 | null =>\n typeof x === 'number' && typeof y === 'number' && typeof z === 'number' ? [x, y, z] : null;\nexport const linearRgb = (c: Color): Vec3 => [toLinear(c.r), toLinear(c.g), toLinear(c.b)];\nexport const fromLinearRgb = ([r, g, b]: Vec3, alpha: number): Color => color(fromLinear(r), fromLinear(g), fromLinear(b), alpha);\n\nconst SRGB_TO_XYZ: Mat3 = [\n [0.41239079926595934, 0.357584339383878, 0.1804807884018343],\n [0.21263900587151027, 0.715168678767756, 0.07219231536073371],\n [0.01933081871559182, 0.11919477979462598, 0.9505321522496607],\n];\nconst XYZ_TO_SRGB: Mat3 = [\n [3.2409699419045226, -1.537383177570094, -0.4986107602930034],\n [-0.9692436362808796, 1.8759675015077202, 0.04155505740717559],\n [0.05563007969699366, -0.20397695888897652, 1.0569715142428786],\n];\nconst P3_TO_XYZ: Mat3 = [\n [0.4865709486482162, 0.26566769316909306, 0.1982172852343625],\n [0.2289745640697488, 0.6917385218365064, 0.079286914093745],\n [0, 0.04511338185890264, 1.043944368900976],\n];\nconst XYZ_TO_P3: Mat3 = [\n [2.493496911941425, -0.9313836179191239, -0.40271078445071684],\n [-0.8294889695615747, 1.7626640603183463, 0.023624685841943577],\n [0.03584583024378447, -0.07617238926804182, 0.9568845240076872],\n];\n/** Bradford chromatic adaptation between the D65 and D50 white points (Lab and LCH use D50). */\nconst D65_TO_D50: Mat3 = [\n [1.0479297925449969, 0.022946870601609652, -0.05019226628920524],\n [0.02962780877005599, 0.9904344267538799, -0.017073799063418826],\n [-0.009243040646204504, 0.015055191490298152, 0.7518742814281371],\n];\nconst D50_TO_D65: Mat3 = [\n [0.955473421488075, -0.02309845494876471, 0.06325924320057072],\n [-0.0283697093338637, 1.0099953980813041, 0.021041441191917323],\n [0.012314014864481998, -0.020507649298898964, 1.330365926242124],\n];\n/** Linear sRGB to OKLab's cone responses, and back. */\nconst LRGB_TO_LMS: Mat3 = [\n [0.412221469470763, 0.5363325372617348, 0.0514459932675022],\n [0.2119034958178252, 0.6806995506452344, 0.1073969535369406],\n [0.0883024591900564, 0.2817188391361215, 0.6299787016738222],\n];\nconst LMS_TO_LRGB: Mat3 = [\n [4.0767416360759574, -3.3077115392580616, 0.2309699031821044],\n [-1.2684379732850317, 2.6097573492876887, -0.3413193760026573],\n [-0.0041960761386756, -0.7034186179359362, 1.7076146940746117],\n];\nconst LMS_TO_OKLAB: Mat3 = [\n [0.210454268309314, 0.7936177747023054, -0.0040720430116193],\n [1.9779985324311684, -2.4285922420485799, 0.450593709617411],\n [0.0259040424655478, 0.7827717124575296, -0.8086757549230774],\n];\nconst OKLAB_TO_LMS: Mat3 = [\n [1, 0.3963377773761749, 0.2158037573099136],\n [1, -0.1055613458156586, -0.0638541728258133],\n [1, -0.0894841775298119, -1.2914855480194092],\n];\n\nexport const toXyz = (c: Color): Vec3 => mul(SRGB_TO_XYZ, linearRgb(c));\nexport const fromXyz = (xyz: Vec3, alpha: number): Color => fromLinearRgb(mul(XYZ_TO_SRGB, xyz), alpha);\n\n/** Display P3 channels (gamma-encoded, 0 to 1 inside P3). */\nexport const toP3 = (c: Color): Vec3 => map3(mul(XYZ_TO_P3, toXyz(c)), fromLinear);\nexport const fromP3 = (p3: Vec3, alpha: number): Color => fromXyz(mul(P3_TO_XYZ, map3(p3, toLinear)), alpha);\nexport const fromXyzD50 = (xyz: Vec3, alpha: number): Color => fromXyz(mul(D50_TO_D65, xyz), alpha);\n\n/** OKLab: L in [0, 1], a and b around ±0.4. */\nexport const toOklab = (c: Color): Vec3 => mul(LMS_TO_OKLAB, map3(mul(LRGB_TO_LMS, linearRgb(c)), Math.cbrt));\nexport const fromOklab = (lab: Vec3, alpha: number): Color =>\n fromLinearRgb(mul(LMS_TO_LRGB, map3(mul(OKLAB_TO_LMS, lab), (v) => v ** 3)), alpha);\n\nconst D50_WHITE: Vec3 = [0.3457 / 0.3585, 1, (1 - 0.3457 - 0.3585) / 0.3585];\nconst KAPPA = 24389 / 27;\nconst EPSILON = 216 / 24389;\n\n/** CIE Lab (D50): L in [0, 100], a and b around ±125. */\nexport const toLab = (c: Color): Vec3 => {\n const [x, y, z] = map3(mul(D65_TO_D50, toXyz(c)), (v, i) => v / D50_WHITE[i]);\n const f = (v: number) => (v > EPSILON ? Math.cbrt(v) : (KAPPA * v + 16) / 116);\n const [fx, fy, fz] = [f(x), f(y), f(z)];\n return [116 * fy - 16, 500 * (fx - fy), 200 * (fy - fz)];\n};\nexport const fromLab = ([l, a, b]: Vec3, alpha: number): Color => {\n const fy = (l + 16) / 116;\n const fx = a / 500 + fy;\n const fz = fy - b / 200;\n const xyz: Vec3 = [\n fx ** 3 > EPSILON ? fx ** 3 : (116 * fx - 16) / KAPPA,\n l > KAPPA * EPSILON ? fy ** 3 : l / KAPPA,\n fz ** 3 > EPSILON ? fz ** 3 : (116 * fz - 16) / KAPPA,\n ];\n return fromXyzD50(map3(xyz, (v, i) => v * D50_WHITE[i]), alpha);\n};\n\n/** Lab-like to its polar form: lightness, chroma, and hue in degrees from 0 to 360. */\nexport const toPolar = ([l, a, b]: Vec3): Vec3 => [l, Math.hypot(a, b), ((Math.atan2(b, a) * 180) / Math.PI + 360) % 360];\nexport const fromPolar = ([l, c, h]: Vec3): Vec3 => [l, c * Math.cos((h * Math.PI) / 180), c * Math.sin((h * Math.PI) / 180)];\n\nconst clip01 = (v: number) => Math.min(1, Math.max(0, v));\n\n/**\n * Below this spread between channels a colour is grey: what is left is rounding error from\n * converting it (from Lab, OKLCH, P3...), and its hue and saturation would be noise. The\n * faintest real tint in 8-bit sRGB, such as #fffffe, has a spread of about 0.004.\n */\nconst GREY = 1e-9;\n\n/**\n * Hue, saturation and lightness of a colour inside sRGB (hue 0 for greys), with s and l in [0, 1].\n * Channels are clipped first: colours count as inside sRGB within rounding error, a little past 0 or 1.\n */\nexport function toHsl(c: Color): Vec3 {\n const [r, g, b] = map3([c.r, c.g, c.b], clip01);\n const max = Math.max(r, g, b);\n const min = Math.min(r, g, b);\n const l = (max + min) / 2;\n const d = max - min;\n if (d < GREY) return [0, 0, l];\n // Clipped, with d > 0: l is strictly between 0 and 1, and s is at most 1.\n const s = (max - l) / Math.min(l, 1 - l);\n let h: number;\n if (max === r) h = (g - b) / d + (g < b ? 6 : 0);\n else if (max === g) h = (b - r) / d + 2;\n else h = (r - g) / d + 4;\n return [h * 60, s, l];\n}\n\nexport function fromHsl(h: number, s: number, l: number, alpha: number): Color {\n const hue = ((h % 360) + 360) % 360;\n const f = (n: number) => {\n const k = (n + hue / 30) % 12;\n return l - s * Math.min(l, 1 - l) * Math.max(-1, Math.min(k - 3, 9 - k, 1));\n };\n return color(f(0), f(8), f(4), alpha);\n}\n\nexport function fromHwb(h: number, w: number, b: number, alpha: number): Color {\n if (w + b >= 1) {\n const grey = w / (w + b);\n return color(grey, grey, grey, alpha);\n }\n const pure = fromHsl(h, 1, 0.5, 1);\n const scale = (v: number) => v * (1 - w - b) + w;\n return color(scale(pure.r), scale(pure.g), scale(pure.b), alpha);\n}\n\n/** Hue, whiteness and blackness of an sRGB colour, with w and b in [0, 1] (channels clipped, as in `toHsl`). */\nexport function toHwb(c: Color): Vec3 {\n const [h] = toHsl(c);\n const [r, g, b] = map3([c.r, c.g, c.b], clip01);\n return [h, Math.min(r, g, b), 1 - Math.max(r, g, b)];\n}\n\n/** Distance in OKLab: about 0.02 is the smallest difference people notice. */\nconst deltaEOK = (a: Color, b: Color): number => {\n const [l1, a1, b1] = toOklab(a);\n const [l2, a2, b2] = toOklab(b);\n return Math.hypot(l1 - l2, a1 - a2, b1 - b2);\n};\n\nconst channels = (c: Color, gamut: Gamut): Vec3 => (gamut === 'srgb' ? [c.r, c.g, c.b] : toP3(c));\nconst clipTo = (c: Color, gamut: Gamut): Color => {\n const [x, y, z] = map3(channels(c, gamut), clip01);\n return gamut === 'srgb' ? color(x, y, z, c.alpha) : fromP3([x, y, z], c.alpha);\n};\n\n/** Whether a colour is inside a gamut, within rounding error. */\nexport function inGamut(c: Color, gamut: Gamut = 'srgb'): boolean {\n return channels(c, gamut).every((v) => v >= -1e-6 && v <= 1 + 1e-6);\n}\n\n/**\n * The colour inside `gamut` that looks closest: the CSS Color 4 gamut mapping\n * algorithm, which keeps lightness and hue and reduces chroma in OKLCH until\n * clipping is no longer visible (`\"map\"`), or plain clipping of each channel (`\"clip\"`).\n */\nexport function toGamut(c: Color, gamut: Gamut = 'srgb', method: 'map' | 'clip' = 'map'): Color {\n if (inGamut(c, gamut)) return clipTo(c, gamut);\n if (method === 'clip') return clipTo(c, gamut);\n const [l, chroma, hue] = toPolar(toOklab(c));\n // Lightness comes back from a round trip through linear RGB, where engines' Math.cbrt\n // and ** differ in the last bits: a lightness of 1 can read as 0.9999999998. The\n // tolerance keeps the result the same on every JavaScript engine.\n if (l >= 1 - 1e-7) return clipTo(color(1, 1, 1, c.alpha), gamut);\n if (l <= 1e-7) return clipTo(color(0, 0, 0, c.alpha), gamut);\n const JND = 0.02;\n let low = 0;\n let high = chroma;\n let lowInGamut = true;\n let current = c;\n let clipped = clipTo(current, gamut);\n if (deltaEOK(clipped, current) < JND) return clipped;\n while (high - low > 0.0001) {\n const mid = (low + high) / 2;\n current = fromOklab(fromPolar([l, mid, hue]), c.alpha);\n if (lowInGamut && inGamut(current, gamut)) {\n low = mid;\n continue;\n }\n clipped = clipTo(current, gamut);\n const e = deltaEOK(clipped, current);\n if (e < JND) {\n if (JND - e < 0.0001) return clipped;\n lowInGamut = false;\n low = mid;\n } else {\n high = mid;\n }\n }\n return clipped;\n}\n","import type { PasteSource } from './paste-reader';\n\n/**\n * Every way a clipboard operation can fail, as a closed union.\n *\n * `CopyError.message` is developer-facing (logs, telemetry). For user-facing\n * text use {@link describeCopyError} / {@link describePasteError}, or map\n * `type` through your own i18n layer.\n */\nexport type CopyErrorType =\n /** No Clipboard API (old browser, server, locked-down webview). Not retryable. */\n | 'unsupported'\n /** Page is not served over HTTPS/localhost. Not retryable. */\n | 'insecure-context'\n /** Browser or user blocked the operation. Also what Safari reports for a missing user gesture. */\n | 'permission-denied'\n /** The document lost focus mid-operation (Chromium). Retrying after refocus usually works. */\n | 'not-focused'\n /** Empty or malformed payload, or a lazy source that threw. Caught before touching the clipboard. */\n | 'invalid-payload'\n /** The browser cannot handle this MIME type (e.g. non-PNG image, HTML without ClipboardItem). */\n | 'unsupported-format'\n /** A lazy image source (or capture) threw, rejected or did not produce a Blob. */\n | 'blob-generation-failed'\n /** `retry()` was called after `maxRetries` was reached. Terminal. */\n | 'max-retries-exceeded'\n /** Paste: the clipboard held nothing matching `accept`. */\n | 'no-content'\n /** Content exceeded a configured safety limit (bytes, items or pixels). Not retryable. */\n | 'too-large'\n /** An operation did not settle within its deadline. Retryable. */\n | 'timeout'\n /** The caller aborted the operation through an `AbortSignal`. Not retryable. */\n | 'aborted'\n /** Anything the platform threw that we could not classify. */\n | 'unknown';\n\n/** Which clipboard direction failed; only changes developer-facing messages. */\nexport type ClipboardOperation = 'write' | 'read';\n\nexport interface CopyError {\n readonly type: CopyErrorType;\n readonly message: string;\n readonly cause?: unknown;\n}\n\nexport function createCopyError(type: CopyErrorType, message: string, cause?: unknown): CopyError {\n return cause === undefined ? { type, message } : { type, message, cause };\n}\n\nconst RETRYABLE_ERRORS: ReadonlySet<CopyErrorType> = /* @__PURE__ */ new Set<CopyErrorType>([\n 'permission-denied',\n 'not-focused',\n 'blob-generation-failed',\n 'timeout',\n 'unknown',\n]);\n\n/** Whether retrying the same payload could plausibly succeed. */\nexport function isRetryableError(error: CopyError): boolean {\n return RETRYABLE_ERRORS.has(error.type);\n}\n\n/**\n * Branded (not `instanceof`) so failures stay recognisable even when the core\n * is bundled twice, e.g. `react-smart-copy` and `react-smart-copy/core` together.\n */\nconst COPY_FAILURE_BRAND = Symbol.for('react-smart-copy.CopyFailure');\n\n/** Error thrown by adapters to carry a fully classified {@link CopyError}. */\nexport class CopyFailure extends Error {\n readonly copyError: CopyError;\n readonly [COPY_FAILURE_BRAND] = true;\n\n constructor(copyError: CopyError) {\n super(copyError.message);\n this.name = 'CopyFailure';\n this.copyError = copyError;\n }\n}\n\nexport function isCopyFailure(value: unknown): value is CopyFailure {\n return (\n typeof value === 'object' &&\n value !== null &&\n (value as Record<PropertyKey, unknown>)[COPY_FAILURE_BRAND] === true\n );\n}\n\n/** Shorthand for throwing a classified failure. */\nexport function copyFailure(type: CopyErrorType, message: string, cause?: unknown): CopyFailure {\n return new CopyFailure(createCopyError(type, message, cause));\n}\n\nfunction readString(value: unknown, key: string): string | undefined {\n if (typeof value !== 'object' || value === null) return undefined;\n const field = (value as Record<string, unknown>)[key];\n return typeof field === 'string' ? field : undefined;\n}\n\n/**\n * Classifies anything thrown by the platform or an adapter into a {@link CopyError}.\n * `operation` only tailors the developer-facing message.\n */\nexport function toCopyError(cause: unknown, operation: ClipboardOperation = 'write'): CopyError {\n if (isCopyFailure(cause)) return cause.copyError;\n\n const name = readString(cause, 'name');\n const message = readString(cause, 'message') ?? '';\n const verb = operation === 'read' ? 'read' : 'write';\n\n switch (name) {\n case 'NotAllowedError':\n return /focus/i.test(message)\n ? createCopyError('not-focused', `The document was not focused during the clipboard ${verb}.`, cause)\n : createCopyError('permission-denied', `Clipboard ${verb} permission was denied.`, cause);\n case 'SecurityError':\n return createCopyError('insecure-context', 'The clipboard is blocked in this context.', cause);\n case 'NotSupportedError':\n case 'DataError':\n return createCopyError('unsupported-format', 'The browser rejected this clipboard format.', cause);\n case 'AbortError':\n return createCopyError('aborted', `The clipboard ${verb} was aborted.`, cause);\n case 'TimeoutError':\n return createCopyError('timeout', `The clipboard ${verb} timed out.`, cause);\n default:\n return createCopyError('unknown', message || `The clipboard ${verb} failed for an unknown reason.`, cause);\n }\n}\n\nconst COPY_DESCRIPTIONS: Readonly<Record<CopyErrorType, string>> = {\n unsupported: \"Copying isn't supported in this browser.\",\n 'insecure-context': 'Copying requires a secure (HTTPS) connection.',\n 'permission-denied': 'Clipboard access was blocked. Allow it and try again.',\n 'not-focused': 'The page lost focus while copying. Try again.',\n 'invalid-payload': 'There is nothing to copy.',\n 'unsupported-format': \"This content can't be copied in this browser.\",\n 'blob-generation-failed': \"The image couldn't be prepared for copying.\",\n 'max-retries-exceeded': 'Copying failed after several attempts.',\n 'no-content': 'There is nothing to copy.',\n 'too-large': 'This content is too large to copy.',\n timeout: 'Copying took too long. Try again.',\n aborted: 'Copying was cancelled.',\n unknown: \"Couldn't copy to the clipboard. Try again.\",\n};\n\nconst PASTE_DESCRIPTIONS: Readonly<Record<CopyErrorType, string>> = {\n unsupported: \"Pasting isn't supported in this browser.\",\n 'insecure-context': 'Pasting requires a secure (HTTPS) connection.',\n 'permission-denied': 'Clipboard access was blocked. Allow it and try again.',\n 'not-focused': 'The page lost focus while pasting. Try again.',\n 'invalid-payload': \"The clipboard content couldn't be read.\",\n 'unsupported-format': \"This clipboard content isn't supported here.\",\n 'blob-generation-failed': \"The pasted image couldn't be read.\",\n 'max-retries-exceeded': 'Pasting failed after several attempts.',\n 'no-content': \"The clipboard doesn't contain anything that can be pasted here.\",\n 'too-large': 'The clipboard content is too large to paste.',\n timeout: 'Pasting took too long. Try again.',\n aborted: 'Pasting was cancelled.',\n unknown: \"Couldn't read the clipboard. Try again.\",\n};\n\n/** Default English, user-facing sentence for a copy error. Replace for i18n. */\nexport function describeCopyError(error: CopyError): string {\n return COPY_DESCRIPTIONS[error.type];\n}\n\n/** Drops can only fail in these ways; the rest of the paste wording would mention the clipboard. */\nconst DROP_DESCRIPTIONS: Readonly<Partial<Record<CopyErrorType, string>>> = {\n 'invalid-payload': \"The dropped content couldn't be read.\",\n 'no-content': 'Nothing that was dropped can be used here.',\n 'too-large': 'The dropped content is too large.',\n unknown: \"Couldn't read the dropped content. Try again.\",\n};\n\n/**\n * Default English, user-facing sentence for a paste error. Pass the error\n * state's `source` to word drag-and-drop failures as drops. Replace for i18n.\n */\nexport function describePasteError(error: CopyError, source?: PasteSource): string {\n return (source === 'drop' ? DROP_DESCRIPTIONS[error.type] : undefined) ?? PASTE_DESCRIPTIONS[error.type];\n}\n","/**\n * The 148 named colours of CSS Color 4, as \"name rrggbb\" pairs. Parsed into a map\n * the first time a name is looked up, so the table costs nothing until then.\n */\nconst NAMED = [\n 'aliceblue f0f8ff antiquewhite faebd7 aqua 00ffff aquamarine 7fffd4 azure f0ffff beige f5f5dc bisque ffe4c4',\n 'black 000000 blanchedalmond ffebcd blue 0000ff blueviolet 8a2be2 brown a52a2a burlywood deb887',\n 'cadetblue 5f9ea0 chartreuse 7fff00 chocolate d2691e coral ff7f50 cornflowerblue 6495ed cornsilk fff8dc',\n 'crimson dc143c cyan 00ffff darkblue 00008b darkcyan 008b8b darkgoldenrod b8860b darkgray a9a9a9',\n 'darkgreen 006400 darkgrey a9a9a9 darkkhaki bdb76b darkmagenta 8b008b darkolivegreen 556b2f darkorange ff8c00',\n 'darkorchid 9932cc darkred 8b0000 darksalmon e9967a darkseagreen 8fbc8f darkslateblue 483d8b',\n 'darkslategray 2f4f4f darkslategrey 2f4f4f darkturquoise 00ced1 darkviolet 9400d3 deeppink ff1493',\n 'deepskyblue 00bfff dimgray 696969 dimgrey 696969 dodgerblue 1e90ff firebrick b22222 floralwhite fffaf0',\n 'forestgreen 228b22 fuchsia ff00ff gainsboro dcdcdc ghostwhite f8f8ff gold ffd700 goldenrod daa520 gray 808080',\n 'green 008000 greenyellow adff2f grey 808080 honeydew f0fff0 hotpink ff69b4 indianred cd5c5c indigo 4b0082',\n 'ivory fffff0 khaki f0e68c lavender e6e6fa lavenderblush fff0f5 lawngreen 7cfc00 lemonchiffon fffacd',\n 'lightblue add8e6 lightcoral f08080 lightcyan e0ffff lightgoldenrodyellow fafad2 lightgray d3d3d3',\n 'lightgreen 90ee90 lightgrey d3d3d3 lightpink ffb6c1 lightsalmon ffa07a lightseagreen 20b2aa',\n 'lightskyblue 87cefa lightslategray 778899 lightslategrey 778899 lightsteelblue b0c4de lightyellow ffffe0',\n 'lime 00ff00 limegreen 32cd32 linen faf0e6 magenta ff00ff maroon 800000 mediumaquamarine 66cdaa',\n 'mediumblue 0000cd mediumorchid ba55d3 mediumpurple 9370db mediumseagreen 3cb371 mediumslateblue 7b68ee',\n 'mediumspringgreen 00fa9a mediumturquoise 48d1cc mediumvioletred c71585 midnightblue 191970 mintcream f5fffa',\n 'mistyrose ffe4e1 moccasin ffe4b5 navajowhite ffdead navy 000080 oldlace fdf5e6 olive 808000 olivedrab 6b8e23',\n 'orange ffa500 orangered ff4500 orchid da70d6 palegoldenrod eee8aa palegreen 98fb98 paleturquoise afeeee',\n 'palevioletred db7093 papayawhip ffefd5 peachpuff ffdab9 peru cd853f pink ffc0cb plum dda0dd powderblue b0e0e6',\n 'purple 800080 rebeccapurple 663399 red ff0000 rosybrown bc8f8f royalblue 4169e1 saddlebrown 8b4513',\n 'salmon fa8072 sandybrown f4a460 seagreen 2e8b57 seashell fff5ee sienna a0522d silver c0c0c0 skyblue 87ceeb',\n 'slateblue 6a5acd slategray 708090 slategrey 708090 snow fffafa springgreen 00ff7f steelblue 4682b4 tan d2b48c',\n 'teal 008080 thistle d8bfd8 tomato ff6347 turquoise 40e0d0 violet ee82ee wheat f5deb3 white ffffff',\n 'whitesmoke f5f5f5 yellow ffff00 yellowgreen 9acd32',\n].join(' ');\n\nlet table: Map<string, number> | undefined;\n\n/** The colour for a CSS colour name (lowercase), as 0xrrggbb, or `undefined`. */\nexport function namedColor(name: string): number | undefined {\n if (table === undefined) {\n table = new Map();\n const parts = NAMED.split(' ');\n for (let i = 0; i < parts.length; i += 2) table.set(parts[i] as string, parseInt(parts[i + 1] as string, 16));\n }\n return table.get(name);\n}\n","import { color, fromHsl, fromHwb, fromLab, fromLinearRgb, fromOklab, fromP3, fromPolar, fromXyz, fromXyzD50, map3, vec3, type Color, type Vec3 } from './convert';\nimport { namedColor } from './names';\n\n/** Longer input is not a colour: parsing stays cheap whatever is pasted. */\nconst MAX_LENGTH = 256;\n\nconst NUMBER = /^[+-]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(?:e[+-]?\\d+)?$/;\nconst HEX = /^#([\\da-f]{3,4}|[\\da-f]{6}|[\\da-f]{8})$/;\nconst FUNCTION = /^([a-z][a-z\\d-]*)\\(([^()]*)\\)$/;\n\ntype Kind = 'number' | 'percent' | 'angle';\ninterface Token {\n readonly kind: Kind | 'none';\n readonly value: number;\n}\n\nconst ANGLE_UNITS: Readonly<Record<string, number>> = { deg: 1, grad: 0.9, rad: 180 / Math.PI, turn: 360 };\n\n/** One component: a number, a percentage, an angle (in degrees) or `none`. */\nfunction token(text: string): Token | null {\n if (text === 'none') return { kind: 'none', value: 0 };\n if (text.endsWith('%')) {\n const body = text.slice(0, -1);\n return NUMBER.test(body) ? { kind: 'percent', value: Number(body) } : null;\n }\n const unit = /[a-z]+$/.exec(text)?.[0];\n if (unit !== undefined) {\n const factor = ANGLE_UNITS[unit];\n const body = text.slice(0, -unit.length);\n // `e` alone is an exponent, never a unit.\n return factor === undefined || !NUMBER.test(body) ? null : { kind: 'angle', value: Number(body) * factor };\n }\n return NUMBER.test(text) ? { kind: 'number', value: Number(text) } : null;\n}\n\nconst clamp = (v: number, min: number, max: number) => Math.min(max, Math.max(min, v));\n\n/** A component's value: numbers as they are, percentages scaled so 100% is `full`. */\nfunction amount(t: Token, full: number, allowed: readonly Kind[]): number | null {\n if (t.kind === 'none') return 0;\n if (!allowed.includes(t.kind)) return null;\n return t.kind === 'percent' ? (t.value / 100) * full : t.value;\n}\n\nconst hueOf = (t: Token): number | null => amount(t, 0, ['number', 'angle']);\nconst alphaOf = (t: Token | undefined): number | null => {\n if (t === undefined) return 1;\n const value = amount(t, 1, ['number', 'percent']);\n return value === null ? null : clamp(value, 0, 1);\n};\n\n/** Splits arguments into three components and an optional alpha; `legacy` for the comma syntax. */\nfunction split(args: string): { readonly parts: Token[]; readonly alpha: Token | undefined; readonly legacy: boolean } | null {\n const legacy = args.includes(',');\n let main: string[];\n let alphaText: string | undefined;\n if (legacy) {\n const list = args.split(',').map((part) => part.trim());\n if (list.length < 3 || list.length > 4) return null;\n main = list.slice(0, 3);\n alphaText = list[3];\n } else {\n const [body, rest, extra] = args.split('/');\n if (extra !== undefined) return null;\n main = (body as string).trim().split(/\\s+/);\n alphaText = rest?.trim();\n if (main.length !== 3 || alphaText === '') return null;\n }\n const parts = main.map(token);\n if (parts.some((part) => part === null)) return null;\n const alpha = alphaText === undefined ? undefined : token(alphaText);\n if (alpha === null) return null;\n // The comma syntax predates `none`.\n if (legacy && [...parts, alpha].some((part) => part?.kind === 'none')) return null;\n return { parts: parts as Token[], alpha, legacy };\n}\n\nfunction rgb(parts: readonly Token[], legacy: boolean): Vec3 | null {\n // The comma syntax takes numbers or percentages, not a mix.\n if (legacy && new Set(parts.map((part) => part.kind)).size !== 1) return null;\n const values = parts.map((part) => amount(part, 255, ['number', 'percent']));\n const vector = vec3(values);\n return vector === null ? null : map3(vector, (v) => clamp(v, 0, 255) / 255);\n}\n\nconst PREDEFINED: Readonly<Record<string, (v: Vec3, alpha: number) => Color>> = {\n srgb: ([r, g, b], alpha) => color(r, g, b, alpha),\n 'srgb-linear': fromLinearRgb,\n 'display-p3': fromP3,\n xyz: fromXyz,\n 'xyz-d65': fromXyz,\n 'xyz-d50': fromXyzD50,\n};\n\n/** `color(space c1 c2 c3 / alpha)`. */\nfunction predefined(args: string): Color | null {\n const match = /^([a-z\\d-]+)\\s+(.*)$/.exec(args.trim());\n if (match === null) return null;\n const convert = PREDEFINED[match[1] as string];\n const parsed = split(match[2] as string);\n if (convert === undefined || parsed === null || parsed.legacy) return null;\n const values = parsed.parts.map((part) => amount(part, 1, ['number', 'percent']));\n const alpha = alphaOf(parsed.alpha);\n const vector = vec3(values);\n return vector === null || alpha === null ? null : convert(vector, alpha);\n}\n\nfunction functional(name: string, args: string): Color | null {\n if (name === 'color') return predefined(args);\n const parsed = split(args);\n if (parsed === null) return null;\n const { parts, legacy } = parsed;\n const [a, b, c] = parts as [Token, Token, Token];\n const alpha = alphaOf(parsed.alpha);\n if (alpha === null) return null;\n switch (name) {\n case 'rgb':\n case 'rgba': {\n const values = rgb(parts, legacy);\n return values === null ? null : color(values[0], values[1], values[2], alpha);\n }\n case 'hsl':\n case 'hsla': {\n const hue = hueOf(a);\n // The comma syntax requires percentages for saturation and lightness.\n const kinds: readonly Kind[] = legacy ? ['percent'] : ['number', 'percent'];\n const s = amount(b, 100, kinds);\n const l = amount(c, 100, kinds);\n if (hue === null || s === null || l === null) return null;\n return fromHsl(hue, clamp(s, 0, 100) / 100, clamp(l, 0, 100) / 100, alpha);\n }\n case 'hwb': {\n const hue = hueOf(a);\n const w = amount(b, 100, ['number', 'percent']);\n const k = amount(c, 100, ['number', 'percent']);\n if (legacy || hue === null || w === null || k === null) return null;\n return fromHwb(hue, clamp(w, 0, 100) / 100, clamp(k, 0, 100) / 100, alpha);\n }\n default:\n return legacy ? null : lab(name, a, b, c, alpha);\n }\n}\n\n/** lab(), lch(), oklab() and oklch(). */\nfunction lab(name: string, a: Token, b: Token, c: Token, alpha: number): Color | null {\n const ok = name.startsWith('ok');\n const polar = name.endsWith('ch');\n if (!['lab', 'lch', 'oklab', 'oklch'].includes(name)) return null;\n const lightMax = ok ? 1 : 100;\n const l = amount(a, lightMax, ['number', 'percent']);\n // 100% is 0.4 in OKLab and OKLCH, 125 for Lab's a and b, 150 for LCH's chroma.\n const second = amount(b, ok ? 0.4 : polar ? 150 : 125, ['number', 'percent']);\n const third = polar ? hueOf(c) : amount(c, ok ? 0.4 : 125, ['number', 'percent']);\n if (l === null || second === null || third === null) return null;\n const lightness = clamp(l, 0, lightMax);\n const values: Vec3 = polar ? fromPolar([lightness, Math.max(0, second), third]) : [lightness, second, third];\n return ok ? fromOklab(values, alpha) : fromLab(values, alpha);\n}\n\n/**\n * Parses a CSS colour, or returns `null`: hex (`#rgb`, `#rgba`, `#rrggbb`,\n * `#rrggbbaa`), the 148 named colours and `transparent`, `rgb()` and `hsl()` in\n * both syntaxes, `hwb()`, `lab()`, `lch()`, `oklab()`, `oklch()`, and `color()`\n * in `srgb`, `srgb-linear`, `display-p3`, `xyz`, `xyz-d65` and `xyz-d50`.\n * Never throws. Colours outside sRGB keep their exact value.\n *\n * Not colours on their own: `currentcolor`, system colours, `var()`, `calc()`,\n * `color-mix()` and relative colours.\n *\n * @example\n * parseColor('oklch(62.8% 0.258 29.23)'); // { r: 1, g: 0, b: 0, alpha: 1 } (rounded)\n */\nexport function parseColor(input: string): Color | null {\n if (typeof input !== 'string' || input.length > MAX_LENGTH) return null;\n const text = input.trim().toLowerCase();\n const hex = HEX.exec(text)?.[1];\n if (hex !== undefined) {\n const full = hex.length <= 4 ? hex.replace(/./g, (digit) => digit + digit) : hex;\n const byte = (i: number) => parseInt(full.slice(i, i + 2), 16) / 255;\n return color(byte(0), byte(2), byte(4), full.length === 8 ? byte(6) : 1);\n }\n if (text === 'transparent') return color(0, 0, 0, 0);\n const named = namedColor(text);\n if (named !== undefined) return color(((named >> 16) & 255) / 255, ((named >> 8) & 255) / 255, (named & 255) / 255);\n const match = FUNCTION.exec(text);\n return match === null ? null : functional(match[1] as string, (match[2] as string).trim());\n}\n","import { copyFailure } from '../core/errors';\nimport { toGamut, toHsl, toHwb, toLab, toOklab, toP3, toPolar, type Color } from './convert';\nimport { parseColor } from './parse';\n\n/**\n * How to write a colour:\n * - `hex`: `#ff0000`, `#ff000080` with alpha\n * - `rgb`, `hsl`, `hwb`: `rgb(255 0 0)`, `hsl(0 100% 50%)`, `hwb(0 0% 0%)`\n * - `oklch`, `oklab`: `oklch(62.8% 0.2577 29.23)`, `oklab(62.8% 0.2249 0.1258)`\n * - `lab`, `lch`: `lab(54.29 80.8 69.89)`, `lch(54.29 106.84 40.85)`\n * - `p3`: `color(display-p3 0.9176 0.2003 0.1386)`\n */\nexport type ColorFormat = 'hex' | 'rgb' | 'hsl' | 'hwb' | 'oklch' | 'oklab' | 'lab' | 'lch' | 'p3';\n\nexport const COLOR_FORMATS: readonly ColorFormat[] = /* @__PURE__ */ Object.freeze(['hex', 'rgb', 'hsl', 'hwb', 'oklch', 'oklab', 'lab', 'lch', 'p3']);\n\nexport interface FormatColorOptions {\n /**\n * For colours outside the format's gamut (sRGB for `hex`, `rgb`, `hsl` and `hwb`;\n * Display P3 for `p3`): `\"map\"` (default) finds the closest colour that looks the\n * same, as CSS Color 4 specifies; `\"clip\"` clips each channel, as most browsers draw.\n * `oklch`, `oklab`, `lab` and `lch` hold every colour exactly.\n */\n readonly gamut?: 'map' | 'clip';\n /** The comma syntax for `rgb` and `hsl` (`rgba(255, 0, 0, 0.5)`), for older tools. Default `false`. */\n readonly legacy?: boolean;\n /** Uppercase hex digits (`#FF0000`). Default `false`. */\n readonly uppercase?: boolean;\n /**\n * Decimal places for every non-integer component. Default: per format, the fewest\n * that bring every 8-bit colour back exactly (checked on 836,056 colours).\n */\n readonly precision?: number;\n}\n\n/** A colour, or text to parse as one: throws a typed `invalid-payload` error for text that is not a colour. */\nexport type ColorInput = Color | string;\n\nconst isColor = (value: unknown): value is Color =>\n typeof value === 'object' &&\n value !== null &&\n ['r', 'g', 'b', 'alpha'].every((key) => Number.isFinite((value as Record<string, unknown>)[key]));\n\n/** Resolves a colour input, throwing a typed error for anything that is not one. */\nexport function toColor(input: ColorInput): Color {\n if (typeof input === 'string') {\n const parsed = parseColor(input);\n if (parsed === null) throw copyFailure('invalid-payload', `Not a colour: ${JSON.stringify(input.slice(0, 100))}.`);\n return parsed;\n }\n if (!isColor(input)) throw copyFailure('invalid-payload', 'A colour must be a CSS colour string or an { r, g, b, alpha } object with finite numbers.');\n return input;\n}\n\n/** Rounds to `places` decimals, without trailing zeros or `-0`. */\nfunction num(value: number, places: number): string {\n const factor = 10 ** places;\n const rounded = Math.round(value * factor) / factor;\n return String(Object.is(rounded, -0) ? 0 : rounded);\n}\n\n/** A hue in degrees, with 360 written as 0. */\nconst hue = (value: number, places: number): string => {\n const text = num(value, places);\n return text === '360' ? '0' : text;\n};\n\nconst byte = (v: number) => Math.round(Math.min(1, Math.max(0, v)) * 255);\n\n/** The alpha suffix of a functional notation: nothing when opaque. */\nconst alphaPart = (alpha: number, legacy: boolean, places: number): string =>\n alpha >= 1 ? '' : legacy ? `, ${num(alpha, places)}` : ` / ${num(alpha, places)}`;\n\n/**\n * Writes a colour in a CSS format. Text is parsed first, so this also converts\n * between formats.\n *\n * @example\n * formatColor('rgb(255 0 0)', 'oklch'); // 'oklch(62.8% 0.2577 29.23)'\n * formatColor('color(display-p3 1 0 0)', 'hex'); // '#ff0000' after gamut mapping, never a wrong hue\n */\nexport function formatColor(input: ColorInput, format: ColorFormat = 'hex', options: FormatColorOptions = {}): string {\n const c = toColor(input);\n const { gamut = 'map', legacy = false, uppercase = false, precision } = options;\n const method: unknown = gamut; // Plain-JS callers can pass anything.\n if (method !== 'map' && method !== 'clip') throw copyFailure('invalid-payload', '`gamut` must be \"map\" or \"clip\".');\n if (precision !== undefined && !(Number.isInteger(precision) && precision >= 0 && precision <= 10)) {\n throw copyFailure('invalid-payload', '`precision` must be an integer from 0 to 10.');\n }\n const dp = (fallback: number) => precision ?? fallback;\n const a = c.alpha;\n switch (format) {\n case 'hex': {\n const s = toGamut(c, 'srgb', gamut);\n const digits = [s.r, s.g, s.b, ...(a < 1 ? [a] : [])].map((v) => byte(v).toString(16).padStart(2, '0')).join('');\n return `#${uppercase ? digits.toUpperCase() : digits}`;\n }\n case 'rgb': {\n const s = toGamut(c, 'srgb', gamut);\n const [r, g, b] = [s.r, s.g, s.b].map(byte);\n return legacy ? `${a < 1 ? 'rgba' : 'rgb'}(${String(r)}, ${String(g)}, ${String(b)}${alphaPart(a, true, dp(3))})` : `rgb(${String(r)} ${String(g)} ${String(b)}${alphaPart(a, false, dp(3))})`;\n }\n case 'hsl': {\n const [h, s, l] = toHsl(toGamut(c, 'srgb', gamut));\n const [hh, ss, ll] = [hue(h, dp(2)), `${num(s * 100, dp(2))}%`, `${num(l * 100, dp(2))}%`];\n return legacy ? `${a < 1 ? 'hsla' : 'hsl'}(${hh}, ${ss}, ${ll}${alphaPart(a, true, dp(3))})` : `hsl(${hh} ${ss} ${ll}${alphaPart(a, false, dp(3))})`;\n }\n case 'hwb': {\n const [h, w, b] = toHwb(toGamut(c, 'srgb', gamut));\n return `hwb(${hue(h, dp(2))} ${num(w * 100, dp(2))}% ${num(b * 100, dp(2))}%${alphaPart(a, false, dp(3))})`;\n }\n case 'oklab': {\n const [l, x, y] = toOklab(c);\n return `oklab(${num(l * 100, dp(2))}% ${num(x, dp(5))} ${num(y, dp(5))}${alphaPart(a, false, dp(3))})`;\n }\n case 'oklch': {\n // The hue is written whenever the written chroma isn't 0; with chroma 0 it means nothing.\n const [l, ch, h] = toPolar(toOklab(c));\n const chroma = num(ch, dp(5));\n return `oklch(${num(l * 100, dp(2))}% ${chroma} ${chroma === '0' ? '0' : hue(h, dp(2))}${alphaPart(a, false, dp(3))})`;\n }\n case 'lab': {\n const [l, x, y] = toLab(c);\n return `lab(${num(l, dp(2))} ${num(x, dp(2))} ${num(y, dp(2))}${alphaPart(a, false, dp(3))})`;\n }\n case 'lch': {\n const [l, ch, h] = toPolar(toLab(c));\n const chroma = num(ch, dp(2));\n return `lch(${num(l, dp(2))} ${chroma} ${chroma === '0' ? '0' : hue(h, dp(2))}${alphaPart(a, false, dp(3))})`;\n }\n case 'p3': {\n const [r, g, b] = toP3(toGamut(c, 'p3', gamut));\n return `color(display-p3 ${num(r, dp(4))} ${num(g, dp(4))} ${num(b, dp(4))}${alphaPart(a, false, dp(3))})`;\n }\n default:\n throw copyFailure('invalid-payload', `Unknown colour format ${JSON.stringify(String(format))}: use one of ${COLOR_FORMATS.join(', ')}.`);\n }\n}\n","import { copyFailure } from '../core/errors';\nimport { color, toGamut, type Color } from './convert';\nimport { toColor, type ColorInput } from './format';\n\nconst WHITE = /* @__PURE__ */ color(1, 1, 1);\n\n/** `top` drawn over `bottom`, both made opaque first. */\nfunction over(top: Color, bottom: Color): Color {\n const mix = (a: number, b: number) => a * top.alpha + b * (1 - top.alpha);\n return color(mix(top.r, bottom.r), mix(top.g, bottom.g), mix(top.b, bottom.b));\n}\n\n/** WCAG 2 relative luminance of an opaque sRGB colour. */\nfunction luminance(c: Color): number {\n const lin = (v: number) => (v <= 0.04045 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4);\n return 0.2126 * lin(c.r) + 0.7152 * lin(c.g) + 0.0722 * lin(c.b);\n}\n\n/**\n * The WCAG 2 contrast ratio of text over a background, from 1 to 21. Colours are\n * mapped into sRGB, a translucent background is drawn over white, and translucent\n * text over the background, as a browser would show them. Never rounded: 4.499 is\n * not 4.5.\n *\n * @example\n * contrastRatio('#767676', '#fff'); // 4.54\n */\nexport function contrastRatio(text: ColorInput, background: ColorInput): number {\n const bg = over(toGamut(toColor(background)), WHITE);\n const fg = over(toGamut(toColor(text)), bg);\n const [light, dark] = [luminance(fg), luminance(bg)].sort((a, b) => b - a) as [number, number];\n return (light + 0.05) / (dark + 0.05);\n}\n\n/** The WCAG 2 level a contrast ratio meets: `AAA`, `AA`, or `fail`. */\nexport type ContrastLevel = 'AAA' | 'AA' | 'fail';\n\nexport interface ContrastLevelOptions {\n /** Large text: at least 24px, or 18.66px bold. Its thresholds are 3 (AA) and 4.5 (AAA) instead of 4.5 and 7. */\n readonly large?: boolean;\n}\n\n/** The WCAG 2 level met by a contrast ratio (`contrastRatio`), for normal or large text. */\nexport function contrastLevel(ratio: number, options: ContrastLevelOptions = {}): ContrastLevel {\n if (!Number.isFinite(ratio) || ratio < 1) throw copyFailure('invalid-payload', 'A contrast ratio is a number from 1 to 21.');\n const [aa, aaa] = options.large === true ? [3, 4.5] : [4.5, 7];\n if (ratio >= aaa) return 'AAA';\n return ratio >= aa ? 'AA' : 'fail';\n}\n","/**\n * Text-field helpers shared by the paste handlers of the opt-in entry points.\n * Internal: not part of `react-smart-copy/core`'s public API.\n */\n\n/** Text fields `setRangeText` and `execCommand('insertText')` both support. */\nexport type TextField = HTMLTextAreaElement | HTMLInputElement;\n\nconst TEXT_INPUTS = new Set(['text', 'search', 'url', 'tel', 'password']);\n\nexport function asTextField(target: EventTarget | null): TextField | null {\n if (typeof target !== 'object' || target === null) return null;\n const element = target as Partial<Element> & { type?: unknown };\n if (element.nodeName === 'TEXTAREA') return target as HTMLTextAreaElement;\n if (element.nodeName === 'INPUT' && typeof element.type === 'string' && TEXT_INPUTS.has(element.type)) return target as HTMLInputElement;\n return null;\n}\n\n/**\n * Inserts text at the cursor of a `<textarea>` or text `<input>`, replacing the\n * selection, as typing or pasting would: the browser's undo (Ctrl/⌘+Z) still\n * works, `input` events fire (so React and other frameworks see the change),\n * and `maxlength` is respected. Returns `false` for disabled or read-only fields.\n */\nexport function insertText(field: TextField, text: string): boolean {\n if (field.disabled || field.readOnly) return false;\n // An <input> holds one line: each run of line breaks (a paragraph break too) becomes one space.\n const value = field.nodeName === 'INPUT' ? text.replace(/[ \\t]*(?:\\r\\n|\\r|\\n)+[ \\t]*/g, ' ') : text;\n const doc = field.ownerDocument;\n field.focus();\n // `null` for inputs without a selection API (email, number): the text is appended.\n const start = field.selectionStart;\n const end = field.selectionEnd;\n try {\n // Re-applying the selection ends the current typing run, so the paste gets its own undo step\n // (as a native paste does) instead of merging with what was typed just before.\n if (start !== null && end !== null) field.setSelectionRange(start, end);\n // The only way to keep the native undo stack; supported for text fields in every current browser.\n // eslint-disable-next-line @typescript-eslint/no-deprecated -- no replacement keeps undo history\n if (doc.activeElement === field && doc.execCommand('insertText', false, value)) return true;\n } catch {\n // Fall through to the manual insertion.\n }\n const from = start ?? field.value.length;\n const to = end ?? from;\n let insert = value;\n if (field.maxLength >= 0) {\n const room = Math.max(0, field.maxLength - (field.value.length - (to - from)));\n insert = insert.slice(0, room);\n // Never leave half of a surrogate pair (an emoji) behind.\n if (/[\\ud800-\\udbff]$/.test(insert)) insert = insert.slice(0, -1);\n }\n if (start === null) setNativeValue(field, field.value + insert);\n else field.setRangeText(insert, from, to, 'end');\n const view = doc.defaultView;\n const event =\n view !== null && typeof view.InputEvent === 'function'\n ? new view.InputEvent('input', { bubbles: true, inputType: 'insertFromPaste', data: insert })\n : new Event('input', { bubbles: true });\n field.dispatchEvent(event);\n return true;\n}\n\n/**\n * Sets a field's value through the prototype's setter. React tracks the value\n * set on the element itself; going around it lets React see the change and\n * call `onChange` for the `input` event that follows.\n */\nfunction setNativeValue(field: TextField, next: string): void {\n const descriptor = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(field) as object, 'value');\n // eslint-disable-next-line @typescript-eslint/unbound-method -- it is called right below with the field as `this`\n const setter = descriptor?.set;\n if (setter) setter.call(field, next);\n else field.value = next;\n}\n","import { copyFailure } from '../core/errors';\nimport type { HtmlPayload, TextPayload } from '../core/payload';\nimport { asTextField, insertText } from '../core/text-field';\nimport { toGamut, type Color } from './convert';\nimport { formatColor, toColor, type ColorFormat, type ColorInput, type FormatColorOptions } from './format';\nimport { parseColor } from './parse';\n\nexport interface ColorPayloadOptions extends FormatColorOptions {\n /** Default `\"hex\"`. */\n readonly format?: ColorFormat;\n /**\n * Add a small swatch of the colour for apps that paste rich text (Docs, Notion,\n * Slack, mail), next to the value. Editors and colour fields still get the value\n * alone. Default `true`.\n */\n readonly swatch?: boolean;\n}\n\n/** The sRGB hex of a colour for the swatch's inline style: always generated here, never user text. */\nconst swatchColor = (c: Color): string => formatColor(toGamut(c), 'hex');\n\n/**\n * A colour to copy: its value in a CSS format as the plain text, and with\n * `swatch` (default) a small coloured square next to the value for rich-text apps.\n *\n * @example\n * copy(() => colorPayload('#3b82f6', { format: 'oklch' }));\n * // text: 'oklch(62.31% 0.188 259.81)', plus a blue swatch in Docs and Slack\n */\nexport function colorPayload(input: ColorInput, options: ColorPayloadOptions = {}): HtmlPayload | TextPayload {\n const { format = 'hex', swatch = true, ...formatOptions } = options;\n const c = toColor(input);\n const value = formatColor(c, format, formatOptions);\n const withSwatch: unknown = swatch; // Plain-JS callers can pass anything.\n if (typeof withSwatch !== 'boolean') throw copyFailure('invalid-payload', '`swatch` must be a boolean.');\n if (!withSwatch) return { kind: 'text', value };\n // The value is escaped although formatColor only writes [#a-z0-9 .%/(),-].\n const escaped = value.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');\n const box = `display:inline-block;width:0.9em;height:0.9em;vertical-align:-0.1em;border:1px solid rgba(0,0,0,0.25);border-radius:2px;background:${swatchColor(c)}`;\n return { kind: 'html', html: `<span style=\"${box}\"></span> <code>${escaped}</code>`, text: value };\n}\n\nexport interface ReadColorOptions {\n /** Also read hex without its `#` (`ff8800`): 3, 6 or 8 digits. Off by default, since words like \"decade\" are hex. */\n readonly bareHex?: boolean;\n}\n\n/** Pasted content: a `PasteResult`, a `DataTransfer`-like source, or text. */\nexport type ColorSource = string | { readonly text?: string | null };\n\n/** `name: value;` as copied from a stylesheet or the browser's developer tools. */\nconst DECLARATION = /^(?:--)?[a-z][\\w-]*\\s*:\\s*(.+?)\\s*(?:!important\\s*)?;?$/i;\n\n/**\n * The one colour that pasted text holds, or `null`: any CSS colour `parseColor`\n * reads, also as a declaration copied from a stylesheet or developer tools\n * (`background: #fff;`, `--brand: oklch(…)`). Never throws for content.\n *\n * @example\n * readColor(' rgb(59, 130, 246) '); // a Color\n * readColor('color: #3b82f6 !important;'); // a Color\n */\nexport function readColor(source: ColorSource, options: ReadColorOptions = {}): Color | null {\n const raw = typeof source === 'string' ? source : source.text;\n if (typeof raw !== 'string' || raw.length > 512) return null;\n const text = raw.trim();\n const value = DECLARATION.exec(text)?.[1] ?? text;\n const direct = parseColor(value);\n if (direct !== null || options.bareHex !== true) return direct;\n return /^(?:[\\da-f]{3}|[\\da-f]{6}|[\\da-f]{8})$/i.test(value) ? parseColor(`#${value}`) : null;\n}\n\n/** Structural paste event: a DOM `ClipboardEvent` and React's `onPaste` event both fit. */\nexport interface ColorPasteEvent {\n readonly clipboardData: { getData(format: string): string } | null;\n readonly currentTarget: EventTarget | null;\n readonly target: EventTarget | null;\n readonly defaultPrevented: boolean;\n preventDefault(): void;\n}\n\nexport interface PasteAsColorOptions extends ReadColorOptions, FormatColorOptions {\n /** The format the field takes. Default `\"hex\"`. */\n readonly format?: ColorFormat;\n /** Called with the pasted colour before it is inserted; return `false` to leave the paste to the browser. */\n readonly onColor?: (color: Color) => boolean | undefined;\n}\n\n/**\n * A paste handler for colour fields: a pasted colour in any CSS format (or a\n * declaration copied from developer tools) is inserted in the field's format,\n * so `rgb(59 130 246)` pasted into a hex field becomes `#3b82f6`. Anything else\n * is left to the browser, and the browser's undo still works. Returns whether\n * it handled the paste.\n *\n * @example\n * <input value={hex} onChange={…} onPaste={(event) => pasteAsColor(event, { format: 'hex' })} />\n */\nexport function pasteAsColor(event: ColorPasteEvent, options: PasteAsColorOptions = {}): boolean {\n const { format = 'hex', onColor, bareHex, ...formatOptions } = options;\n // Invalid options are a programming error: they throw before the paste is touched.\n formatColor('#000', format, formatOptions);\n if (event.defaultPrevented || event.clipboardData === null) return false;\n const field = asTextField(event.currentTarget) ?? asTextField(event.target);\n if (field === null || field.disabled || field.readOnly) return false;\n const pasted = readColor(event.clipboardData.getData('text/plain'), bareHex === undefined ? {} : { bareHex });\n if (pasted === null || onColor?.(pasted) === false) return false;\n event.preventDefault();\n return insertText(field, formatColor(pasted, format, formatOptions));\n}\n"],"mappings":";AAsBA,MAAa,SAAS,GAAW,GAAW,GAAW,QAAQ,MAAa,OAAO,OAAO;CAAE;CAAG;CAAG;CAAG;AAAM,CAAC;AAE5G,MAAM,OAAO,GAAS,CAAC,GAAG,GAAG,OAAmB;CAC9C,EAAE,EAAE,CAAC,KAAK,IAAI,EAAE,EAAE,CAAC,KAAK,IAAI,EAAE,EAAE,CAAC,KAAK;CACtC,EAAE,EAAE,CAAC,KAAK,IAAI,EAAE,EAAE,CAAC,KAAK,IAAI,EAAE,EAAE,CAAC,KAAK;CACtC,EAAE,EAAE,CAAC,KAAK,IAAI,EAAE,EAAE,CAAC,KAAK,IAAI,EAAE,EAAE,CAAC,KAAK;AACxC;;AAGA,MAAM,YAAY,MAAsB;CACtC,MAAM,MAAM,KAAK,IAAI,CAAC;CACtB,OAAO,OAAO,SAAU,IAAI,QAAQ,KAAK,KAAK,CAAC,MAAM,MAAM,QAAS,UAAU;AAChF;AACA,MAAM,cAAc,MAAsB;CACxC,MAAM,MAAM,KAAK,IAAI,CAAC;CACtB,OAAO,MAAM,WAAY,KAAK,KAAK,CAAC,KAAK,QAAQ,QAAQ,IAAI,OAAO,QAAS,QAAQ;AACvF;;AAGA,MAAa,QAAQ,CAAC,GAAG,GAAG,IAAU,MAAiD;CAAC,EAAE,GAAG,CAAC;CAAG,EAAE,GAAG,CAAC;CAAG,EAAE,GAAG,CAAC;AAAC;;AAEjH,MAAa,QAAQ,CAAC,GAAG,GAAG,OAC1B,OAAO,MAAM,YAAY,OAAO,MAAM,YAAY,OAAO,MAAM,WAAW;CAAC;CAAG;CAAG;AAAC,IAAI;AACxF,MAAa,aAAa,MAAmB;CAAC,SAAS,EAAE,CAAC;CAAG,SAAS,EAAE,CAAC;CAAG,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C3D,MAAM,eAAe;CACrB,OAAO,WAAW,OAAO,YAAY,QAAQ,QAAQ,aAAa,CAAC;AACrE"}
|
|
1
|
+
{"version":3,"file":"color.js","names":[],"sources":["../src/color/payload.ts"],"sourcesContent":["import { copyFailure } from '../core/errors';\nimport type { HtmlPayload, TextPayload } from '../core/payload';\nimport { asTextField, insertText } from '../core/text-field';\nimport { toGamut, type Color } from './convert';\nimport { formatColor, toColor, type ColorFormat, type ColorInput, type FormatColorOptions } from './format';\nimport { parseColor } from './parse';\n\nexport interface ColorPayloadOptions extends FormatColorOptions {\n /** Default `\"hex\"`. */\n readonly format?: ColorFormat;\n /**\n * Add a small swatch of the colour for apps that paste rich text (Docs, Notion,\n * Slack, mail), next to the value. Editors and colour fields still get the value\n * alone. Default `true`.\n */\n readonly swatch?: boolean;\n}\n\n/** The sRGB hex of a colour for the swatch's inline style: always generated here, never user text. */\nconst swatchColor = (c: Color): string => formatColor(toGamut(c), 'hex');\n\n/**\n * A colour to copy: its value in a CSS format as the plain text, and with\n * `swatch` (default) a small coloured square next to the value for rich-text apps.\n *\n * @example\n * copy(() => colorPayload('#3b82f6', { format: 'oklch' }));\n * // text: 'oklch(62.31% 0.188 259.81)', plus a blue swatch in Docs and Slack\n */\nexport function colorPayload(input: ColorInput, options: ColorPayloadOptions = {}): HtmlPayload | TextPayload {\n const { format = 'hex', swatch = true, ...formatOptions } = options;\n const c = toColor(input);\n const value = formatColor(c, format, formatOptions);\n const withSwatch: unknown = swatch; // Plain-JS callers can pass anything.\n if (typeof withSwatch !== 'boolean') throw copyFailure('invalid-payload', '`swatch` must be a boolean.');\n if (!withSwatch) return { kind: 'text', value };\n // The value is escaped although formatColor only writes [#a-z0-9 .%/(),-].\n const escaped = value.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');\n const box = `display:inline-block;width:0.9em;height:0.9em;vertical-align:-0.1em;border:1px solid rgba(0,0,0,0.25);border-radius:2px;background:${swatchColor(c)}`;\n return { kind: 'html', html: `<span style=\"${box}\"></span> <code>${escaped}</code>`, text: value };\n}\n\nexport interface ReadColorOptions {\n /** Also read hex without its `#` (`ff8800`): 3, 6 or 8 digits. Off by default, since words like \"decade\" are hex. */\n readonly bareHex?: boolean;\n}\n\n/** Pasted content: a `PasteResult`, a `DataTransfer`-like source, or text. */\nexport type ColorSource = string | { readonly text?: string | null };\n\n/** `name: value;` as copied from a stylesheet or the browser's developer tools. */\nconst DECLARATION = /^(?:--)?[a-z][\\w-]*\\s*:\\s*(.+?)\\s*(?:!important\\s*)?;?$/i;\n\n/**\n * The one colour that pasted text holds, or `null`: any CSS colour `parseColor`\n * reads, also as a declaration copied from a stylesheet or developer tools\n * (`background: #fff;`, `--brand: oklch(…)`). Never throws for content.\n *\n * @example\n * readColor(' rgb(59, 130, 246) '); // a Color\n * readColor('color: #3b82f6 !important;'); // a Color\n */\nexport function readColor(source: ColorSource, options: ReadColorOptions = {}): Color | null {\n const raw = typeof source === 'string' ? source : source.text;\n if (typeof raw !== 'string' || raw.length > 512) return null;\n const text = raw.trim();\n const value = DECLARATION.exec(text)?.[1] ?? text;\n const direct = parseColor(value);\n if (direct !== null || options.bareHex !== true) return direct;\n return /^(?:[\\da-f]{3}|[\\da-f]{6}|[\\da-f]{8})$/i.test(value) ? parseColor(`#${value}`) : null;\n}\n\n/** Structural paste event: a DOM `ClipboardEvent` and React's `onPaste` event both fit. */\nexport interface ColorPasteEvent {\n readonly clipboardData: { getData(format: string): string } | null;\n readonly currentTarget: EventTarget | null;\n readonly target: EventTarget | null;\n readonly defaultPrevented: boolean;\n preventDefault(): void;\n}\n\nexport interface PasteAsColorOptions extends ReadColorOptions, FormatColorOptions {\n /** The format the field takes. Default `\"hex\"`. */\n readonly format?: ColorFormat;\n /** Called with the pasted colour before it is inserted; return `false` to leave the paste to the browser. */\n readonly onColor?: (color: Color) => boolean | undefined;\n}\n\n/**\n * A paste handler for colour fields: a pasted colour in any CSS format (or a\n * declaration copied from developer tools) is inserted in the field's format,\n * so `rgb(59 130 246)` pasted into a hex field becomes `#3b82f6`. Anything else\n * is left to the browser, and the browser's undo still works. Returns whether\n * it handled the paste.\n *\n * @example\n * <input value={hex} onChange={…} onPaste={(event) => pasteAsColor(event, { format: 'hex' })} />\n */\nexport function pasteAsColor(event: ColorPasteEvent, options: PasteAsColorOptions = {}): boolean {\n const { format = 'hex', onColor, bareHex, ...formatOptions } = options;\n // Invalid options are a programming error: they throw before the paste is touched.\n formatColor('#000', format, formatOptions);\n if (event.defaultPrevented || event.clipboardData === null) return false;\n const field = asTextField(event.currentTarget) ?? asTextField(event.target);\n if (field === null || field.disabled || field.readOnly) return false;\n const pasted = readColor(event.clipboardData.getData('text/plain'), bareHex === undefined ? {} : { bareHex });\n if (pasted === null || onColor?.(pasted) === false) return false;\n event.preventDefault();\n return insertText(field, formatColor(pasted, format, formatOptions));\n}\n"],"mappings":";;;;;;AAmBA,MAAM,eAAe,MAAqB,YAAY,QAAQ,CAAC,GAAG,KAAK;;;;;;;;;AAUvE,SAAgB,aAAa,OAAmB,UAA+B,CAAC,GAA8B;CAC5G,MAAM,EAAE,SAAS,OAAO,SAAS,MAAM,GAAG,kBAAkB;CAC5D,MAAM,IAAI,QAAQ,KAAK;CACvB,MAAM,QAAQ,YAAY,GAAG,QAAQ,aAAa;CAClD,MAAM,aAAsB;CAC5B,IAAI,OAAO,eAAe,WAAW,MAAM,YAAY,mBAAmB,6BAA6B;CACvG,IAAI,CAAC,YAAY,OAAO;EAAE,MAAM;EAAQ;CAAM;CAE9C,MAAM,UAAU,MAAM,QAAQ,MAAM,OAAO,CAAC,CAAC,QAAQ,MAAM,MAAM,CAAC,CAAC,QAAQ,MAAM,MAAM;CAEvF,OAAO;EAAE,MAAM;EAAQ,MAAM,gBAAgB,sIADqG,YAAY,CAAC,IAC9G,uBAAuB,QAAQ;EAAU,MAAM;CAAM;AACxG;;AAWA,MAAM,cAAc;;;;;;;;;;AAWpB,SAAgB,UAAU,QAAqB,UAA4B,CAAC,GAAiB;CAC3F,MAA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