@unmade/svg-helpers 0.1.1 → 0.1.3

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.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("./named-colours.cjs"),m=s=>{let t=Array.from(s),r=!1;return t[0]==="#"&&(t.shift(),r=!0),t.length===3&&(t=t.map(e=>`${e}${e}`)),`${r?"#":""}${t.join("").toLowerCase()}`},h=s=>Math.max(0,Math.min(255,Math.round(s))).toString(16).padStart(2,"0"),l=(s,t,r)=>`#${h(s)}${h(t)}${h(r)}`,f=(s,t,r)=>{if(t===0){const d=Math.round(r*255);return[d,d,d]}const e=(s%360+360)%360,o=(1-Math.abs(2*r-1))*t,u=o*(1-Math.abs(e/60%2-1)),c=r-o/2;let n=0,a=0,i=0;return e<60?(n=o,a=u,i=0):e<120?(n=u,a=o,i=0):e<180?(n=0,a=o,i=u):e<240?(n=0,a=u,i=o):e<300?(n=u,a=0,i=o):(n=o,a=0,i=u),[Math.round((n+c)*255),Math.round((a+c)*255),Math.round((i+c)*255)]},b=s=>/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.test(s),x=s=>{const t=s.trim().toLowerCase();if(t.startsWith("#")||/^[0-9a-f]{3}([0-9a-f]{3})?$/.test(t))return b(t)?m(t):void 0;if(t.startsWith("rgb")){const e=t.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*[\d.]+\s*)?\)/);return e?l(Number.parseInt(e[1],10),Number.parseInt(e[2],10),Number.parseInt(e[3],10)):void 0}if(t.startsWith("hsl")){const e=t.match(/hsla?\(\s*(\d+)\s*,\s*([\d.]+)%\s*,\s*([\d.]+)%\s*(?:,\s*[\d.]+\s*)?\)/);if(!e)return;const o=Number.parseInt(e[1],10),u=Number.parseFloat(e[2])/100,c=Number.parseFloat(e[3])/100,[n,a,i]=f(o,u,c);return l(n,a,i)}const r=p.CSS_NAMED_COLOURS[t];if(r)return r};exports.expandHex=m;exports.hslToRgb=f;exports.isHex=b;exports.normaliseColour=x;exports.rgbToHex=l;
1
+ const e=require("./named-colours.cjs");var t=e=>{let t=Array.from(e),n=!1;return t[0]===`#`&&(t.shift(),n=!0),t.length===3&&(t=t.map(e=>`${e}${e}`)),`${n?`#`:``}${t.join(``).toLowerCase()}`},n=e=>Math.max(0,Math.min(255,Math.round(typeof e==`string`?Number.parseInt(e,10):e))).toString(16).padStart(2,`0`),r=(...e)=>{let[t,r,i]=Array.isArray(e[0])?e[0]:e;return`#${n(t)}${n(r)}${n(i)}`},i=(e,t,n)=>{if(t===0){let e=Math.round(n*255);return[e,e,e]}let r=(e%360+360)%360,i=(1-Math.abs(2*n-1))*t,a=i*(1-Math.abs(r/60%2-1)),o=n-i/2,s=0,c=0,l=0;return r<60?(s=i,c=a,l=0):r<120?(s=a,c=i,l=0):r<180?(s=0,c=i,l=a):r<240?(s=0,c=a,l=i):r<300?(s=a,c=0,l=i):(s=i,c=0,l=a),[Math.round((s+o)*255),Math.round((c+o)*255),Math.round((l+o)*255)]},a=e=>/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.test(e),o=e=>Number.parseInt(e,16),s=e=>{let n=t(e).replace(`#`,``);return[o(n.slice(0,2)),o(n.slice(2,4)),o(n.slice(4,6))]},c=n=>{let o=n.trim().toLowerCase();if(o.startsWith(`#`)||/^[0-9a-f]{3}([0-9a-f]{3})?$/.test(o))return a(o)?t(o):void 0;if(o.startsWith(`rgb`)){let e=o.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*[\d.]+\s*)?\)/);return e?r(Number.parseInt(e[1],10),Number.parseInt(e[2],10),Number.parseInt(e[3],10)):void 0}if(o.startsWith(`hsl`)){let e=o.match(/hsla?\(\s*(\d+)\s*,\s*([\d.]+)%\s*,\s*([\d.]+)%\s*(?:,\s*[\d.]+\s*)?\)/);if(!e)return;let[t,n,a]=i(Number.parseInt(e[1],10),Number.parseFloat(e[2])/100,Number.parseFloat(e[3])/100);return r(t,n,a)}let s=e.CSS_NAMED_COLOURS[o];if(s)return s};exports.expandHex=t,exports.hexToInt=o,exports.hexToRgb=s,exports.hslToRgb=i,exports.isHex=a,exports.normaliseColour=c,exports.rgbToHex=r,exports.toHex=n;
@@ -0,0 +1,62 @@
1
+ /** An RGB colour as a tuple of three channel values (0–255). */
2
+ export type RGB = [number, number, number];
3
+ /**
4
+ * Convert a short hex to full length.
5
+ *
6
+ * @param short - the initial hex value
7
+ * @returns the expanded hex value
8
+ */
9
+ export declare const expandHex: (short: string) => string;
10
+ /**
11
+ * Convert a number (or numeric string) to a two-character hex string,
12
+ * clamped to the 0–255 range.
13
+ *
14
+ * @param val - the value to convert
15
+ * @returns two-character hex string (e.g. `"0a"`, `"ff"`)
16
+ */
17
+ export declare const toHex: (val: string | number) => string;
18
+ /**
19
+ * Convert RGB channel values (0–255) to a `#rrggbb` hex string.
20
+ */
21
+ export declare const rgbToHex: (...args: [r: number, g: number, b: number] | [[number, number, number]]) => string;
22
+ /**
23
+ * Convert HSL values to RGB.
24
+ *
25
+ * @param h - Hue in degrees (0–360)
26
+ * @param s - Saturation as a fraction (0–1)
27
+ * @param l - Lightness as a fraction (0–1)
28
+ * @returns [r, g, b] with each channel in 0–255
29
+ */
30
+ export declare const hslToRgb: (h: number, s: number, l: number) => [number, number, number];
31
+ /**
32
+ * Validate whether a string is a hex colour (3 or 6 digit, with optional #).
33
+ */
34
+ export declare const isHex: (str: string) => boolean;
35
+ /**
36
+ * Convert a hex string (e.g. `"ff"`) to an integer.
37
+ *
38
+ * @param hex - the hex string to convert (without `#` prefix)
39
+ * @returns the integer value
40
+ */
41
+ export declare const hexToInt: (hex: string) => number;
42
+ /**
43
+ * Convert a hex colour string to an RGB tuple.
44
+ *
45
+ * Accepts 3-digit (`#abc`) or 6-digit (`#aabbcc`) hex, with or without `#`.
46
+ *
47
+ * @param hex - the hex colour string
48
+ * @returns `[r, g, b]` with each channel in 0–255
49
+ */
50
+ export declare const hexToRgb: (hex: string) => RGB;
51
+ /**
52
+ * Normalise any CSS colour value to a canonical `#rrggbb` lowercase hex string.
53
+ *
54
+ * Supported formats:
55
+ * - Hex: `#RGB`, `#RRGGBB` (with or without `#`)
56
+ * - RGB/RGBA: `rgb(r, g, b)`, `rgba(r, g, b, a)`
57
+ * - HSL/HSLA: `hsl(h, s%, l%)`, `hsla(h, s%, l%, a)`
58
+ * - CSS named colours: `red`, `blue`, `coral`, etc.
59
+ *
60
+ * @returns Normalised `#rrggbb` string, or `undefined` if the value is not a recognised colour
61
+ */
62
+ export declare const normaliseColour: (value: string) => string | undefined;
@@ -1,48 +1,48 @@
1
- import { CSS_NAMED_COLOURS as f } from "./named-colours.mjs";
2
- const l = (r) => {
3
- let t = Array.from(r), e = !1;
4
- return t[0] === "#" && (t.shift(), e = !0), t.length === 3 && (t = t.map((s) => `${s}${s}`)), `${e ? "#" : ""}${t.join("").toLowerCase()}`;
5
- }, m = (r) => Math.max(0, Math.min(255, Math.round(r))).toString(16).padStart(2, "0"), d = (r, t, e) => `#${m(r)}${m(t)}${m(e)}`, b = (r, t, e) => {
6
- if (t === 0) {
7
- const u = Math.round(e * 255);
8
- return [u, u, u];
9
- }
10
- const s = (r % 360 + 360) % 360, n = (1 - Math.abs(2 * e - 1)) * t, c = n * (1 - Math.abs(s / 60 % 2 - 1)), h = e - n / 2;
11
- let o = 0, a = 0, i = 0;
12
- return s < 60 ? (o = n, a = c, i = 0) : s < 120 ? (o = c, a = n, i = 0) : s < 180 ? (o = 0, a = n, i = c) : s < 240 ? (o = 0, a = c, i = n) : s < 300 ? (o = c, a = 0, i = n) : (o = n, a = 0, i = c), [
13
- Math.round((o + h) * 255),
14
- Math.round((a + h) * 255),
15
- Math.round((i + h) * 255)
16
- ];
17
- }, p = (r) => /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.test(r), M = (r) => {
18
- const t = r.trim().toLowerCase();
19
- if (t.startsWith("#") || /^[0-9a-f]{3}([0-9a-f]{3})?$/.test(t))
20
- return p(t) ? l(t) : void 0;
21
- if (t.startsWith("rgb")) {
22
- const s = t.match(
23
- /rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*[\d.]+\s*)?\)/
24
- );
25
- return s ? d(
26
- Number.parseInt(s[1], 10),
27
- Number.parseInt(s[2], 10),
28
- Number.parseInt(s[3], 10)
29
- ) : void 0;
30
- }
31
- if (t.startsWith("hsl")) {
32
- const s = t.match(
33
- /hsla?\(\s*(\d+)\s*,\s*([\d.]+)%\s*,\s*([\d.]+)%\s*(?:,\s*[\d.]+\s*)?\)/
34
- );
35
- if (!s) return;
36
- const n = Number.parseInt(s[1], 10), c = Number.parseFloat(s[2]) / 100, h = Number.parseFloat(s[3]) / 100, [o, a, i] = b(n, c, h);
37
- return d(o, a, i);
38
- }
39
- const e = f[t];
40
- if (e) return e;
41
- };
42
- export {
43
- l as expandHex,
44
- b as hslToRgb,
45
- p as isHex,
46
- M as normaliseColour,
47
- d as rgbToHex
1
+ import { CSS_NAMED_COLOURS as e } from "./named-colours.mjs";
2
+ //#region src/colours/format.ts
3
+ var t = (e) => {
4
+ let t = Array.from(e), n = !1;
5
+ return t[0] === "#" && (t.shift(), n = !0), t.length === 3 && (t = t.map((e) => `${e}${e}`)), `${n ? "#" : ""}${t.join("").toLowerCase()}`;
6
+ }, n = (e) => Math.max(0, Math.min(255, Math.round(typeof e == "string" ? Number.parseInt(e, 10) : e))).toString(16).padStart(2, "0"), r = (...e) => {
7
+ let [t, r, i] = Array.isArray(e[0]) ? e[0] : e;
8
+ return `#${n(t)}${n(r)}${n(i)}`;
9
+ }, i = (e, t, n) => {
10
+ if (t === 0) {
11
+ let e = Math.round(n * 255);
12
+ return [
13
+ e,
14
+ e,
15
+ e
16
+ ];
17
+ }
18
+ let r = (e % 360 + 360) % 360, i = (1 - Math.abs(2 * n - 1)) * t, a = i * (1 - Math.abs(r / 60 % 2 - 1)), o = n - i / 2, s = 0, c = 0, l = 0;
19
+ return r < 60 ? (s = i, c = a, l = 0) : r < 120 ? (s = a, c = i, l = 0) : r < 180 ? (s = 0, c = i, l = a) : r < 240 ? (s = 0, c = a, l = i) : r < 300 ? (s = a, c = 0, l = i) : (s = i, c = 0, l = a), [
20
+ Math.round((s + o) * 255),
21
+ Math.round((c + o) * 255),
22
+ Math.round((l + o) * 255)
23
+ ];
24
+ }, a = (e) => /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.test(e), o = (e) => Number.parseInt(e, 16), s = (e) => {
25
+ let n = t(e).replace("#", "");
26
+ return [
27
+ o(n.slice(0, 2)),
28
+ o(n.slice(2, 4)),
29
+ o(n.slice(4, 6))
30
+ ];
31
+ }, c = (n) => {
32
+ let o = n.trim().toLowerCase();
33
+ if (o.startsWith("#") || /^[0-9a-f]{3}([0-9a-f]{3})?$/.test(o)) return a(o) ? t(o) : void 0;
34
+ if (o.startsWith("rgb")) {
35
+ let e = o.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*[\d.]+\s*)?\)/);
36
+ return e ? r(Number.parseInt(e[1], 10), Number.parseInt(e[2], 10), Number.parseInt(e[3], 10)) : void 0;
37
+ }
38
+ if (o.startsWith("hsl")) {
39
+ let e = o.match(/hsla?\(\s*(\d+)\s*,\s*([\d.]+)%\s*,\s*([\d.]+)%\s*(?:,\s*[\d.]+\s*)?\)/);
40
+ if (!e) return;
41
+ let [t, n, a] = i(Number.parseInt(e[1], 10), Number.parseFloat(e[2]) / 100, Number.parseFloat(e[3]) / 100);
42
+ return r(t, n, a);
43
+ }
44
+ let s = e[o];
45
+ if (s) return s;
48
46
  };
47
+ //#endregion
48
+ export { t as expandHex, o as hexToInt, s as hexToRgb, i as hslToRgb, a as isHex, c as normaliseColour, r as rgbToHex, n as toHex };
@@ -0,0 +1,46 @@
1
+ export { expandHex, rgbToHex, hslToRgb, isHex, normaliseColour, toHex, hexToInt, hexToRgb, type RGB } from './format';
2
+ export { CSS_NAMED_COLOURS } from './named-colours';
3
+ export declare const ELEMENTS: {
4
+ svg: string;
5
+ circle: string;
6
+ desc: string;
7
+ ellipse: string;
8
+ rect: string;
9
+ line: string;
10
+ path: string;
11
+ polygon: string;
12
+ polyline: string;
13
+ stop: string;
14
+ };
15
+ export declare const COLOURABLE_ELEMENT_SELECTORS: {
16
+ tiling: string[];
17
+ nonTiling: string[];
18
+ };
19
+ /**
20
+ * Fetch all colourable elements from an SVG
21
+ *
22
+ * @param {SVGElement} svg - the SVG input
23
+ * @returns {SVGElement[]} the elements
24
+ */
25
+ export declare const getColourableElements: (svg: SVGElement) => SVGElement[];
26
+ /**
27
+ * Get a list of the unique colours used in an SVG document.
28
+ *
29
+ * Extracts fill, stroke, and stop-color attributes from all colourable
30
+ * elements. Normalises all colour formats (hex, rgb, hsl, named) to
31
+ * canonical `#rrggbb` lowercase hex. Elements inside `<clipPath>` are excluded.
32
+ *
33
+ * @param {SVGElement} svg - the document
34
+ * @returns {string[]} unique colour hex strings
35
+ */
36
+ export declare const getUniqueColoursFromSVG: (svg: SVGElement) => string[];
37
+ /**
38
+ * Extract unique normalised colours from a raw SVG string.
39
+ *
40
+ * Parses the string via DOMParser, then delegates to `getUniqueColoursFromSVG`.
41
+ * This is a convenience function for working with SVG glyph data from fonts.
42
+ *
43
+ * @param svgString - Raw SVG markup
44
+ * @returns Array of unique `#rrggbb` hex colour strings
45
+ */
46
+ export declare const getColoursFromSvgString: (svgString: string) => string[];
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e={aliceblue:"#f0f8ff",antiquewhite:"#faebd7",aqua:"#00ffff",aquamarine:"#7fffd4",azure:"#f0ffff",beige:"#f5f5dc",bisque:"#ffe4c4",black:"#000000",blanchedalmond:"#ffebcd",blue:"#0000ff",blueviolet:"#8a2be2",brown:"#a52a2a",burlywood:"#deb887",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",cornflowerblue:"#6495ed",cornsilk:"#fff8dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkgray:"#a9a9a9",darkgreen:"#006400",darkgrey:"#a9a9a9",darkkhaki:"#bdb76b",darkmagenta:"#8b008b",darkolivegreen:"#556b2f",darkorange:"#ff8c00",darkorchid:"#9932cc",darkred:"#8b0000",darksalmon:"#e9967a",darkseagreen:"#8fbc8f",darkslateblue:"#483d8b",darkslategray:"#2f4f4f",darkslategrey:"#2f4f4f",darkturquoise:"#00ced1",darkviolet:"#9400d3",deeppink:"#ff1493",deepskyblue:"#00bfff",dimgray:"#696969",dimgrey:"#696969",dodgerblue:"#1e90ff",firebrick:"#b22222",floralwhite:"#fffaf0",forestgreen:"#228b22",fuchsia:"#ff00ff",gainsboro:"#dcdcdc",ghostwhite:"#f8f8ff",gold:"#ffd700",goldenrod:"#daa520",gray:"#808080",green:"#008000",greenyellow:"#adff2f",grey:"#808080",honeydew:"#f0fff0",hotpink:"#ff69b4",indianred:"#cd5c5c",indigo:"#4b0082",ivory:"#fffff0",khaki:"#f0e68c",lavender:"#e6e6fa",lavenderblush:"#fff0f5",lawngreen:"#7cfc00",lemonchiffon:"#fffacd",lightblue:"#add8e6",lightcoral:"#f08080",lightcyan:"#e0ffff",lightgoldenrodyellow:"#fafad2",lightgray:"#d3d3d3",lightgreen:"#90ee90",lightgrey:"#d3d3d3",lightpink:"#ffb6c1",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",lightskyblue:"#87cefa",lightslategray:"#778899",lightslategrey:"#778899",lightsteelblue:"#b0c4de",lightyellow:"#ffffe0",lime:"#00ff00",limegreen:"#32cd32",linen:"#faf0e6",magenta:"#ff00ff",maroon:"#800000",mediumaquamarine:"#66cdaa",mediumblue:"#0000cd",mediumorchid:"#ba55d3",mediumpurple:"#9370db",mediumseagreen:"#3cb371",mediumslateblue:"#7b68ee",mediumspringgreen:"#00fa9a",mediumturquoise:"#48d1cc",mediumvioletred:"#c71585",midnightblue:"#191970",mintcream:"#f5fffa",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",navajowhite:"#ffdead",navy:"#000080",oldlace:"#fdf5e6",olive:"#808000",olivedrab:"#6b8e23",orange:"#ffa500",orangered:"#ff4500",orchid:"#da70d6",palegoldenrod:"#eee8aa",palegreen:"#98fb98",paleturquoise:"#afeeee",palevioletred:"#db7093",papayawhip:"#ffefd5",peachpuff:"#ffdab9",peru:"#cd853f",pink:"#ffc0cb",plum:"#dda0dd",powderblue:"#b0e0e6",purple:"#800080",rebeccapurple:"#663399",red:"#ff0000",rosybrown:"#bc8f8f",royalblue:"#4169e1",saddlebrown:"#8b4513",salmon:"#fa8072",sandybrown:"#f4a460",seagreen:"#2e8b57",seashell:"#fff5ee",sienna:"#a0522d",silver:"#c0c0c0",skyblue:"#87ceeb",slateblue:"#6a5acd",slategray:"#708090",slategrey:"#708090",snow:"#fffafa",springgreen:"#00ff7f",steelblue:"#4682b4",tan:"#d2b48c",teal:"#008080",thistle:"#d8bfd8",tomato:"#ff6347",turquoise:"#40e0d0",violet:"#ee82ee",wheat:"#f5deb3",white:"#ffffff",whitesmoke:"#f5f5f5",yellow:"#ffff00",yellowgreen:"#9acd32"};exports.CSS_NAMED_COLOURS=e;
1
+ var e={aliceblue:`#f0f8ff`,antiquewhite:`#faebd7`,aqua:`#00ffff`,aquamarine:`#7fffd4`,azure:`#f0ffff`,beige:`#f5f5dc`,bisque:`#ffe4c4`,black:`#000000`,blanchedalmond:`#ffebcd`,blue:`#0000ff`,blueviolet:`#8a2be2`,brown:`#a52a2a`,burlywood:`#deb887`,cadetblue:`#5f9ea0`,chartreuse:`#7fff00`,chocolate:`#d2691e`,coral:`#ff7f50`,cornflowerblue:`#6495ed`,cornsilk:`#fff8dc`,crimson:`#dc143c`,cyan:`#00ffff`,darkblue:`#00008b`,darkcyan:`#008b8b`,darkgoldenrod:`#b8860b`,darkgray:`#a9a9a9`,darkgreen:`#006400`,darkgrey:`#a9a9a9`,darkkhaki:`#bdb76b`,darkmagenta:`#8b008b`,darkolivegreen:`#556b2f`,darkorange:`#ff8c00`,darkorchid:`#9932cc`,darkred:`#8b0000`,darksalmon:`#e9967a`,darkseagreen:`#8fbc8f`,darkslateblue:`#483d8b`,darkslategray:`#2f4f4f`,darkslategrey:`#2f4f4f`,darkturquoise:`#00ced1`,darkviolet:`#9400d3`,deeppink:`#ff1493`,deepskyblue:`#00bfff`,dimgray:`#696969`,dimgrey:`#696969`,dodgerblue:`#1e90ff`,firebrick:`#b22222`,floralwhite:`#fffaf0`,forestgreen:`#228b22`,fuchsia:`#ff00ff`,gainsboro:`#dcdcdc`,ghostwhite:`#f8f8ff`,gold:`#ffd700`,goldenrod:`#daa520`,gray:`#808080`,green:`#008000`,greenyellow:`#adff2f`,grey:`#808080`,honeydew:`#f0fff0`,hotpink:`#ff69b4`,indianred:`#cd5c5c`,indigo:`#4b0082`,ivory:`#fffff0`,khaki:`#f0e68c`,lavender:`#e6e6fa`,lavenderblush:`#fff0f5`,lawngreen:`#7cfc00`,lemonchiffon:`#fffacd`,lightblue:`#add8e6`,lightcoral:`#f08080`,lightcyan:`#e0ffff`,lightgoldenrodyellow:`#fafad2`,lightgray:`#d3d3d3`,lightgreen:`#90ee90`,lightgrey:`#d3d3d3`,lightpink:`#ffb6c1`,lightsalmon:`#ffa07a`,lightseagreen:`#20b2aa`,lightskyblue:`#87cefa`,lightslategray:`#778899`,lightslategrey:`#778899`,lightsteelblue:`#b0c4de`,lightyellow:`#ffffe0`,lime:`#00ff00`,limegreen:`#32cd32`,linen:`#faf0e6`,magenta:`#ff00ff`,maroon:`#800000`,mediumaquamarine:`#66cdaa`,mediumblue:`#0000cd`,mediumorchid:`#ba55d3`,mediumpurple:`#9370db`,mediumseagreen:`#3cb371`,mediumslateblue:`#7b68ee`,mediumspringgreen:`#00fa9a`,mediumturquoise:`#48d1cc`,mediumvioletred:`#c71585`,midnightblue:`#191970`,mintcream:`#f5fffa`,mistyrose:`#ffe4e1`,moccasin:`#ffe4b5`,navajowhite:`#ffdead`,navy:`#000080`,oldlace:`#fdf5e6`,olive:`#808000`,olivedrab:`#6b8e23`,orange:`#ffa500`,orangered:`#ff4500`,orchid:`#da70d6`,palegoldenrod:`#eee8aa`,palegreen:`#98fb98`,paleturquoise:`#afeeee`,palevioletred:`#db7093`,papayawhip:`#ffefd5`,peachpuff:`#ffdab9`,peru:`#cd853f`,pink:`#ffc0cb`,plum:`#dda0dd`,powderblue:`#b0e0e6`,purple:`#800080`,rebeccapurple:`#663399`,red:`#ff0000`,rosybrown:`#bc8f8f`,royalblue:`#4169e1`,saddlebrown:`#8b4513`,salmon:`#fa8072`,sandybrown:`#f4a460`,seagreen:`#2e8b57`,seashell:`#fff5ee`,sienna:`#a0522d`,silver:`#c0c0c0`,skyblue:`#87ceeb`,slateblue:`#6a5acd`,slategray:`#708090`,slategrey:`#708090`,snow:`#fffafa`,springgreen:`#00ff7f`,steelblue:`#4682b4`,tan:`#d2b48c`,teal:`#008080`,thistle:`#d8bfd8`,tomato:`#ff6347`,turquoise:`#40e0d0`,violet:`#ee82ee`,wheat:`#f5deb3`,white:`#ffffff`,whitesmoke:`#f5f5f5`,yellow:`#ffff00`,yellowgreen:`#9acd32`};exports.CSS_NAMED_COLOURS=e;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * CSS named colours mapped to their lowercase hex equivalents.
3
+ *
4
+ * Lookup keys are lowercase to allow case-insensitive matching.
5
+ * @see https://www.w3.org/TR/css-color-4/#named-colors
6
+ */
7
+ export declare const CSS_NAMED_COLOURS: Readonly<Record<string, string>>;
@@ -1,153 +1,153 @@
1
- const e = {
2
- aliceblue: "#f0f8ff",
3
- antiquewhite: "#faebd7",
4
- aqua: "#00ffff",
5
- aquamarine: "#7fffd4",
6
- azure: "#f0ffff",
7
- beige: "#f5f5dc",
8
- bisque: "#ffe4c4",
9
- black: "#000000",
10
- blanchedalmond: "#ffebcd",
11
- blue: "#0000ff",
12
- blueviolet: "#8a2be2",
13
- brown: "#a52a2a",
14
- burlywood: "#deb887",
15
- cadetblue: "#5f9ea0",
16
- chartreuse: "#7fff00",
17
- chocolate: "#d2691e",
18
- coral: "#ff7f50",
19
- cornflowerblue: "#6495ed",
20
- cornsilk: "#fff8dc",
21
- crimson: "#dc143c",
22
- cyan: "#00ffff",
23
- darkblue: "#00008b",
24
- darkcyan: "#008b8b",
25
- darkgoldenrod: "#b8860b",
26
- darkgray: "#a9a9a9",
27
- darkgreen: "#006400",
28
- darkgrey: "#a9a9a9",
29
- darkkhaki: "#bdb76b",
30
- darkmagenta: "#8b008b",
31
- darkolivegreen: "#556b2f",
32
- darkorange: "#ff8c00",
33
- darkorchid: "#9932cc",
34
- darkred: "#8b0000",
35
- darksalmon: "#e9967a",
36
- darkseagreen: "#8fbc8f",
37
- darkslateblue: "#483d8b",
38
- darkslategray: "#2f4f4f",
39
- darkslategrey: "#2f4f4f",
40
- darkturquoise: "#00ced1",
41
- darkviolet: "#9400d3",
42
- deeppink: "#ff1493",
43
- deepskyblue: "#00bfff",
44
- dimgray: "#696969",
45
- dimgrey: "#696969",
46
- dodgerblue: "#1e90ff",
47
- firebrick: "#b22222",
48
- floralwhite: "#fffaf0",
49
- forestgreen: "#228b22",
50
- fuchsia: "#ff00ff",
51
- gainsboro: "#dcdcdc",
52
- ghostwhite: "#f8f8ff",
53
- gold: "#ffd700",
54
- goldenrod: "#daa520",
55
- gray: "#808080",
56
- green: "#008000",
57
- greenyellow: "#adff2f",
58
- grey: "#808080",
59
- honeydew: "#f0fff0",
60
- hotpink: "#ff69b4",
61
- indianred: "#cd5c5c",
62
- indigo: "#4b0082",
63
- ivory: "#fffff0",
64
- khaki: "#f0e68c",
65
- lavender: "#e6e6fa",
66
- lavenderblush: "#fff0f5",
67
- lawngreen: "#7cfc00",
68
- lemonchiffon: "#fffacd",
69
- lightblue: "#add8e6",
70
- lightcoral: "#f08080",
71
- lightcyan: "#e0ffff",
72
- lightgoldenrodyellow: "#fafad2",
73
- lightgray: "#d3d3d3",
74
- lightgreen: "#90ee90",
75
- lightgrey: "#d3d3d3",
76
- lightpink: "#ffb6c1",
77
- lightsalmon: "#ffa07a",
78
- lightseagreen: "#20b2aa",
79
- lightskyblue: "#87cefa",
80
- lightslategray: "#778899",
81
- lightslategrey: "#778899",
82
- lightsteelblue: "#b0c4de",
83
- lightyellow: "#ffffe0",
84
- lime: "#00ff00",
85
- limegreen: "#32cd32",
86
- linen: "#faf0e6",
87
- magenta: "#ff00ff",
88
- maroon: "#800000",
89
- mediumaquamarine: "#66cdaa",
90
- mediumblue: "#0000cd",
91
- mediumorchid: "#ba55d3",
92
- mediumpurple: "#9370db",
93
- mediumseagreen: "#3cb371",
94
- mediumslateblue: "#7b68ee",
95
- mediumspringgreen: "#00fa9a",
96
- mediumturquoise: "#48d1cc",
97
- mediumvioletred: "#c71585",
98
- midnightblue: "#191970",
99
- mintcream: "#f5fffa",
100
- mistyrose: "#ffe4e1",
101
- moccasin: "#ffe4b5",
102
- navajowhite: "#ffdead",
103
- navy: "#000080",
104
- oldlace: "#fdf5e6",
105
- olive: "#808000",
106
- olivedrab: "#6b8e23",
107
- orange: "#ffa500",
108
- orangered: "#ff4500",
109
- orchid: "#da70d6",
110
- palegoldenrod: "#eee8aa",
111
- palegreen: "#98fb98",
112
- paleturquoise: "#afeeee",
113
- palevioletred: "#db7093",
114
- papayawhip: "#ffefd5",
115
- peachpuff: "#ffdab9",
116
- peru: "#cd853f",
117
- pink: "#ffc0cb",
118
- plum: "#dda0dd",
119
- powderblue: "#b0e0e6",
120
- purple: "#800080",
121
- rebeccapurple: "#663399",
122
- red: "#ff0000",
123
- rosybrown: "#bc8f8f",
124
- royalblue: "#4169e1",
125
- saddlebrown: "#8b4513",
126
- salmon: "#fa8072",
127
- sandybrown: "#f4a460",
128
- seagreen: "#2e8b57",
129
- seashell: "#fff5ee",
130
- sienna: "#a0522d",
131
- silver: "#c0c0c0",
132
- skyblue: "#87ceeb",
133
- slateblue: "#6a5acd",
134
- slategray: "#708090",
135
- slategrey: "#708090",
136
- snow: "#fffafa",
137
- springgreen: "#00ff7f",
138
- steelblue: "#4682b4",
139
- tan: "#d2b48c",
140
- teal: "#008080",
141
- thistle: "#d8bfd8",
142
- tomato: "#ff6347",
143
- turquoise: "#40e0d0",
144
- violet: "#ee82ee",
145
- wheat: "#f5deb3",
146
- white: "#ffffff",
147
- whitesmoke: "#f5f5f5",
148
- yellow: "#ffff00",
149
- yellowgreen: "#9acd32"
150
- };
151
- export {
152
- e as CSS_NAMED_COLOURS
1
+ //#region src/colours/named-colours.ts
2
+ var e = {
3
+ aliceblue: "#f0f8ff",
4
+ antiquewhite: "#faebd7",
5
+ aqua: "#00ffff",
6
+ aquamarine: "#7fffd4",
7
+ azure: "#f0ffff",
8
+ beige: "#f5f5dc",
9
+ bisque: "#ffe4c4",
10
+ black: "#000000",
11
+ blanchedalmond: "#ffebcd",
12
+ blue: "#0000ff",
13
+ blueviolet: "#8a2be2",
14
+ brown: "#a52a2a",
15
+ burlywood: "#deb887",
16
+ cadetblue: "#5f9ea0",
17
+ chartreuse: "#7fff00",
18
+ chocolate: "#d2691e",
19
+ coral: "#ff7f50",
20
+ cornflowerblue: "#6495ed",
21
+ cornsilk: "#fff8dc",
22
+ crimson: "#dc143c",
23
+ cyan: "#00ffff",
24
+ darkblue: "#00008b",
25
+ darkcyan: "#008b8b",
26
+ darkgoldenrod: "#b8860b",
27
+ darkgray: "#a9a9a9",
28
+ darkgreen: "#006400",
29
+ darkgrey: "#a9a9a9",
30
+ darkkhaki: "#bdb76b",
31
+ darkmagenta: "#8b008b",
32
+ darkolivegreen: "#556b2f",
33
+ darkorange: "#ff8c00",
34
+ darkorchid: "#9932cc",
35
+ darkred: "#8b0000",
36
+ darksalmon: "#e9967a",
37
+ darkseagreen: "#8fbc8f",
38
+ darkslateblue: "#483d8b",
39
+ darkslategray: "#2f4f4f",
40
+ darkslategrey: "#2f4f4f",
41
+ darkturquoise: "#00ced1",
42
+ darkviolet: "#9400d3",
43
+ deeppink: "#ff1493",
44
+ deepskyblue: "#00bfff",
45
+ dimgray: "#696969",
46
+ dimgrey: "#696969",
47
+ dodgerblue: "#1e90ff",
48
+ firebrick: "#b22222",
49
+ floralwhite: "#fffaf0",
50
+ forestgreen: "#228b22",
51
+ fuchsia: "#ff00ff",
52
+ gainsboro: "#dcdcdc",
53
+ ghostwhite: "#f8f8ff",
54
+ gold: "#ffd700",
55
+ goldenrod: "#daa520",
56
+ gray: "#808080",
57
+ green: "#008000",
58
+ greenyellow: "#adff2f",
59
+ grey: "#808080",
60
+ honeydew: "#f0fff0",
61
+ hotpink: "#ff69b4",
62
+ indianred: "#cd5c5c",
63
+ indigo: "#4b0082",
64
+ ivory: "#fffff0",
65
+ khaki: "#f0e68c",
66
+ lavender: "#e6e6fa",
67
+ lavenderblush: "#fff0f5",
68
+ lawngreen: "#7cfc00",
69
+ lemonchiffon: "#fffacd",
70
+ lightblue: "#add8e6",
71
+ lightcoral: "#f08080",
72
+ lightcyan: "#e0ffff",
73
+ lightgoldenrodyellow: "#fafad2",
74
+ lightgray: "#d3d3d3",
75
+ lightgreen: "#90ee90",
76
+ lightgrey: "#d3d3d3",
77
+ lightpink: "#ffb6c1",
78
+ lightsalmon: "#ffa07a",
79
+ lightseagreen: "#20b2aa",
80
+ lightskyblue: "#87cefa",
81
+ lightslategray: "#778899",
82
+ lightslategrey: "#778899",
83
+ lightsteelblue: "#b0c4de",
84
+ lightyellow: "#ffffe0",
85
+ lime: "#00ff00",
86
+ limegreen: "#32cd32",
87
+ linen: "#faf0e6",
88
+ magenta: "#ff00ff",
89
+ maroon: "#800000",
90
+ mediumaquamarine: "#66cdaa",
91
+ mediumblue: "#0000cd",
92
+ mediumorchid: "#ba55d3",
93
+ mediumpurple: "#9370db",
94
+ mediumseagreen: "#3cb371",
95
+ mediumslateblue: "#7b68ee",
96
+ mediumspringgreen: "#00fa9a",
97
+ mediumturquoise: "#48d1cc",
98
+ mediumvioletred: "#c71585",
99
+ midnightblue: "#191970",
100
+ mintcream: "#f5fffa",
101
+ mistyrose: "#ffe4e1",
102
+ moccasin: "#ffe4b5",
103
+ navajowhite: "#ffdead",
104
+ navy: "#000080",
105
+ oldlace: "#fdf5e6",
106
+ olive: "#808000",
107
+ olivedrab: "#6b8e23",
108
+ orange: "#ffa500",
109
+ orangered: "#ff4500",
110
+ orchid: "#da70d6",
111
+ palegoldenrod: "#eee8aa",
112
+ palegreen: "#98fb98",
113
+ paleturquoise: "#afeeee",
114
+ palevioletred: "#db7093",
115
+ papayawhip: "#ffefd5",
116
+ peachpuff: "#ffdab9",
117
+ peru: "#cd853f",
118
+ pink: "#ffc0cb",
119
+ plum: "#dda0dd",
120
+ powderblue: "#b0e0e6",
121
+ purple: "#800080",
122
+ rebeccapurple: "#663399",
123
+ red: "#ff0000",
124
+ rosybrown: "#bc8f8f",
125
+ royalblue: "#4169e1",
126
+ saddlebrown: "#8b4513",
127
+ salmon: "#fa8072",
128
+ sandybrown: "#f4a460",
129
+ seagreen: "#2e8b57",
130
+ seashell: "#fff5ee",
131
+ sienna: "#a0522d",
132
+ silver: "#c0c0c0",
133
+ skyblue: "#87ceeb",
134
+ slateblue: "#6a5acd",
135
+ slategray: "#708090",
136
+ slategrey: "#708090",
137
+ snow: "#fffafa",
138
+ springgreen: "#00ff7f",
139
+ steelblue: "#4682b4",
140
+ tan: "#d2b48c",
141
+ teal: "#008080",
142
+ thistle: "#d8bfd8",
143
+ tomato: "#ff6347",
144
+ turquoise: "#40e0d0",
145
+ violet: "#ee82ee",
146
+ wheat: "#f5deb3",
147
+ white: "#ffffff",
148
+ whitesmoke: "#f5f5f5",
149
+ yellow: "#ffff00",
150
+ yellowgreen: "#9acd32"
153
151
  };
152
+ //#endregion
153
+ export { e as CSS_NAMED_COLOURS };
package/dist/colours.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("@unmade/platform"),l=require("./colours/format.cjs"),d=require("./colours/named-colours.cjs"),e={svg:"svg",circle:"circle",desc:"desc",ellipse:"ellipse",rect:"rect",line:"line",path:"path",polygon:"polygon",polyline:"polyline",stop:"stop"},n={fill:"fill",stroke:"stroke"},p={tiling:[e.circle,e.ellipse,e.rect,e.line,e.path,e.polygon,e.polyline,e.stop,`[${n.fill}]`,`[${n.stroke}]`],nonTiling:[e.circle,e.desc,e.ellipse,e.rect,e.line,e.path,e.polygon,e.polyline,e.stop,`[${n.fill}]`,`[${n.stroke}]`]},S=o=>Array.from(o.querySelectorAll(p.tiling.map(r=>`*:not(clipPath) > ${r}`).join(", "))),C=o=>{const r=o.getAttribute(n.stroke);return r==="none"||!r?!1:r},a=o=>{if(!(o==="none"||o==="transparent"||o.startsWith("url(")))return l.normaliseColour(o)},m=o=>{const s=S(o).reduce((i,c)=>{const g=c.getAttribute("stop-color"),E=c.getAttribute(n.fill)||"#000",u=C(c);if(!g){const t=a(E);t&&i.add(t)}if(g){const t=a(g);t&&i.add(t)}if(u){const t=a(u);t&&i.add(t)}return i},new Set);return Array.from(s)},T=o=>{const s=new f.DOMParser().parseFromString(o,"image/svg+xml").querySelector("svg");return s?m(s):[]};exports.expandHex=l.expandHex;exports.hslToRgb=l.hslToRgb;exports.isHex=l.isHex;exports.normaliseColour=l.normaliseColour;exports.rgbToHex=l.rgbToHex;exports.CSS_NAMED_COLOURS=d.CSS_NAMED_COLOURS;exports.COLOURABLE_ELEMENT_SELECTORS=p;exports.ELEMENTS=e;exports.getColourableElements=S;exports.getColoursFromSvgString=T;exports.getUniqueColoursFromSVG=m;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./colours/named-colours.cjs"),t=require("./colours/format.cjs");let n=require("@unmade/platform");var r={svg:`svg`,circle:`circle`,desc:`desc`,ellipse:`ellipse`,rect:`rect`,line:`line`,path:`path`,polygon:`polygon`,polyline:`polyline`,stop:`stop`},i={fill:`fill`,stroke:`stroke`},a={tiling:[r.circle,r.ellipse,r.rect,r.line,r.path,r.polygon,r.polyline,r.stop,`[${i.fill}]`,`[${i.stroke}]`],nonTiling:[r.circle,r.desc,r.ellipse,r.rect,r.line,r.path,r.polygon,r.polyline,r.stop,`[${i.fill}]`,`[${i.stroke}]`]},o=e=>Array.from(e.querySelectorAll(a.tiling.map(e=>`*:not(clipPath) > ${e}`).join(`, `))),s=e=>{let t=e.getAttribute(i.stroke);return t===`none`||!t?!1:t},c=e=>{if(!(e===`none`||e===`transparent`||e.startsWith(`url(`)))return t.normaliseColour(e)},l=e=>{let t=o(e).reduce((e,t)=>{let n=t.getAttribute(`stop-color`),r=t.getAttribute(i.fill)||`#000`,a=s(t);if(r&&!n){let t=c(r);t&&e.add(t)}if(n){let t=c(n);t&&e.add(t)}if(a){let t=c(a);t&&e.add(t)}return e},new Set);return Array.from(t)},u=e=>{let t=new n.DOMParser().parseFromString(e,`image/svg+xml`).querySelector(`svg`);return t?l(t):[]};exports.COLOURABLE_ELEMENT_SELECTORS=a,exports.CSS_NAMED_COLOURS=e.CSS_NAMED_COLOURS,exports.ELEMENTS=r,exports.expandHex=t.expandHex,exports.getColourableElements=o,exports.getColoursFromSvgString=u,exports.getUniqueColoursFromSVG=l,exports.hexToInt=t.hexToInt,exports.hexToRgb=t.hexToRgb,exports.hslToRgb=t.hslToRgb,exports.isHex=t.isHex,exports.normaliseColour=t.normaliseColour,exports.rgbToHex=t.rgbToHex,exports.toHex=t.toHex;
package/dist/colours.mjs CHANGED
@@ -1,92 +1,73 @@
1
- import { DOMParser as f } from "@unmade/platform";
2
- import { normaliseColour as m } from "./colours/format.mjs";
3
- import { expandHex as x, hslToRgb as h, isHex as O, rgbToHex as b } from "./colours/format.mjs";
4
- import { CSS_NAMED_COLOURS as R } from "./colours/named-colours.mjs";
5
- const e = {
6
- svg: "svg",
7
- circle: "circle",
8
- desc: "desc",
9
- ellipse: "ellipse",
10
- rect: "rect",
11
- line: "line",
12
- path: "path",
13
- polygon: "polygon",
14
- polyline: "polyline",
15
- stop: "stop"
16
- }, n = {
17
- fill: "fill",
18
- stroke: "stroke"
19
- }, u = {
20
- tiling: [
21
- e.circle,
22
- e.ellipse,
23
- e.rect,
24
- e.line,
25
- e.path,
26
- e.polygon,
27
- e.polyline,
28
- e.stop,
29
- `[${n.fill}]`,
30
- `[${n.stroke}]`
31
- ],
32
- nonTiling: [
33
- e.circle,
34
- e.desc,
35
- e.ellipse,
36
- e.rect,
37
- e.line,
38
- e.path,
39
- e.polygon,
40
- e.polyline,
41
- e.stop,
42
- `[${n.fill}]`,
43
- `[${n.stroke}]`
44
- ]
45
- }, d = (t) => Array.from(
46
- t.querySelectorAll(
47
- u.tiling.map((r) => `*:not(clipPath) > ${r}`).join(", ")
48
- )
49
- ), S = (t) => {
50
- const r = t.getAttribute(n.stroke);
51
- return r === "none" || !r ? !1 : r;
52
- }, p = (t) => {
53
- if (!(t === "none" || t === "transparent" || t.startsWith("url(")))
54
- return m(t);
55
- }, E = (t) => {
56
- const l = d(t).reduce(
57
- (s, i) => {
58
- const c = i.getAttribute("stop-color"), a = i.getAttribute(n.fill) || "#000", g = S(i);
59
- if (!c) {
60
- const o = p(a);
61
- o && s.add(o);
62
- }
63
- if (c) {
64
- const o = p(c);
65
- o && s.add(o);
66
- }
67
- if (g) {
68
- const o = p(g);
69
- o && s.add(o);
70
- }
71
- return s;
72
- },
73
- /* @__PURE__ */ new Set()
74
- );
75
- return Array.from(l);
76
- }, C = (t) => {
77
- const l = new f().parseFromString(t, "image/svg+xml").querySelector("svg");
78
- return l ? E(l) : [];
79
- };
80
- export {
81
- u as COLOURABLE_ELEMENT_SELECTORS,
82
- R as CSS_NAMED_COLOURS,
83
- e as ELEMENTS,
84
- x as expandHex,
85
- d as getColourableElements,
86
- C as getColoursFromSvgString,
87
- E as getUniqueColoursFromSVG,
88
- h as hslToRgb,
89
- O as isHex,
90
- m as normaliseColour,
91
- b as rgbToHex
1
+ import { CSS_NAMED_COLOURS as e } from "./colours/named-colours.mjs";
2
+ import { expandHex as t, hexToInt as n, hexToRgb as r, hslToRgb as i, isHex as a, normaliseColour as o, rgbToHex as s, toHex as c } from "./colours/format.mjs";
3
+ import { DOMParser as l } from "@unmade/platform";
4
+ //#region src/colours/index.ts
5
+ var u = {
6
+ svg: "svg",
7
+ circle: "circle",
8
+ desc: "desc",
9
+ ellipse: "ellipse",
10
+ rect: "rect",
11
+ line: "line",
12
+ path: "path",
13
+ polygon: "polygon",
14
+ polyline: "polyline",
15
+ stop: "stop"
16
+ }, d = {
17
+ fill: "fill",
18
+ stroke: "stroke"
19
+ }, f = {
20
+ tiling: [
21
+ u.circle,
22
+ u.ellipse,
23
+ u.rect,
24
+ u.line,
25
+ u.path,
26
+ u.polygon,
27
+ u.polyline,
28
+ u.stop,
29
+ `[${d.fill}]`,
30
+ `[${d.stroke}]`
31
+ ],
32
+ nonTiling: [
33
+ u.circle,
34
+ u.desc,
35
+ u.ellipse,
36
+ u.rect,
37
+ u.line,
38
+ u.path,
39
+ u.polygon,
40
+ u.polyline,
41
+ u.stop,
42
+ `[${d.fill}]`,
43
+ `[${d.stroke}]`
44
+ ]
45
+ }, p = (e) => Array.from(e.querySelectorAll(f.tiling.map((e) => `*:not(clipPath) > ${e}`).join(", "))), m = (e) => {
46
+ let t = e.getAttribute(d.stroke);
47
+ return t === "none" || !t ? !1 : t;
48
+ }, h = (e) => {
49
+ if (!(e === "none" || e === "transparent" || e.startsWith("url("))) return o(e);
50
+ }, g = (e) => {
51
+ let t = p(e).reduce((e, t) => {
52
+ let n = t.getAttribute("stop-color"), r = t.getAttribute(d.fill) || "#000", i = m(t);
53
+ if (r && !n) {
54
+ let t = h(r);
55
+ t && e.add(t);
56
+ }
57
+ if (n) {
58
+ let t = h(n);
59
+ t && e.add(t);
60
+ }
61
+ if (i) {
62
+ let t = h(i);
63
+ t && e.add(t);
64
+ }
65
+ return e;
66
+ }, /* @__PURE__ */ new Set());
67
+ return Array.from(t);
68
+ }, _ = (e) => {
69
+ let t = new l().parseFromString(e, "image/svg+xml").querySelector("svg");
70
+ return t ? g(t) : [];
92
71
  };
72
+ //#endregion
73
+ export { f as COLOURABLE_ELEMENT_SELECTORS, e as CSS_NAMED_COLOURS, u as ELEMENTS, t as expandHex, p as getColourableElements, _ as getColoursFromSvgString, g as getUniqueColoursFromSVG, n as hexToInt, r as hexToRgb, i as hslToRgb, a as isHex, o as normaliseColour, s as rgbToHex, c as toHex };
package/dist/index.d.ts CHANGED
@@ -1,99 +1,2 @@
1
- export declare const COLOURABLE_ELEMENT_SELECTORS: {
2
- tiling: string[];
3
- nonTiling: string[];
4
- };
5
-
6
- /**
7
- * CSS named colours mapped to their lowercase hex equivalents.
8
- *
9
- * Lookup keys are lowercase to allow case-insensitive matching.
10
- * @see https://www.w3.org/TR/css-color-4/#named-colors
11
- */
12
- export declare const CSS_NAMED_COLOURS: Readonly<Record<string, string>>;
13
-
14
- export declare const ELEMENTS: {
15
- svg: string;
16
- circle: string;
17
- desc: string;
18
- ellipse: string;
19
- rect: string;
20
- line: string;
21
- path: string;
22
- polygon: string;
23
- polyline: string;
24
- stop: string;
25
- };
26
-
27
- /**
28
- * Convert a short hex to full length.
29
- *
30
- * @param short - the initial hex value
31
- * @returns the expanded hex value
32
- */
33
- export declare const expandHex: (short: string) => string;
34
-
35
- /**
36
- * Fetch all colourable elements from an SVG
37
- *
38
- * @param {SVGElement} svg - the SVG input
39
- * @returns {SVGElement[]} the elements
40
- */
41
- export declare const getColourableElements: (svg: SVGElement) => SVGElement[];
42
-
43
- /**
44
- * Extract unique normalised colours from a raw SVG string.
45
- *
46
- * Parses the string via DOMParser, then delegates to `getUniqueColoursFromSVG`.
47
- * This is a convenience function for working with SVG glyph data from fonts.
48
- *
49
- * @param svgString - Raw SVG markup
50
- * @returns Array of unique `#rrggbb` hex colour strings
51
- */
52
- export declare const getColoursFromSvgString: (svgString: string) => string[];
53
-
54
- /**
55
- * Get a list of the unique colours used in an SVG document.
56
- *
57
- * Extracts fill, stroke, and stop-color attributes from all colourable
58
- * elements. Normalises all colour formats (hex, rgb, hsl, named) to
59
- * canonical `#rrggbb` lowercase hex. Elements inside `<clipPath>` are excluded.
60
- *
61
- * @param {SVGElement} svg - the document
62
- * @returns {string[]} unique colour hex strings
63
- */
64
- export declare const getUniqueColoursFromSVG: (svg: SVGElement) => string[];
65
-
66
- /**
67
- * Convert HSL values to RGB.
68
- *
69
- * @param h - Hue in degrees (0–360)
70
- * @param s - Saturation as a fraction (0–1)
71
- * @param l - Lightness as a fraction (0–1)
72
- * @returns [r, g, b] with each channel in 0–255
73
- */
74
- export declare const hslToRgb: (h: number, s: number, l: number) => [number, number, number];
75
-
76
- /**
77
- * Validate whether a string is a hex colour (3 or 6 digit, with optional #).
78
- */
79
- export declare const isHex: (str: string) => boolean;
80
-
81
- /**
82
- * Normalise any CSS colour value to a canonical `#rrggbb` lowercase hex string.
83
- *
84
- * Supported formats:
85
- * - Hex: `#RGB`, `#RRGGBB` (with or without `#`)
86
- * - RGB/RGBA: `rgb(r, g, b)`, `rgba(r, g, b, a)`
87
- * - HSL/HSLA: `hsl(h, s%, l%)`, `hsla(h, s%, l%, a)`
88
- * - CSS named colours: `red`, `blue`, `coral`, etc.
89
- *
90
- * @returns Normalised `#rrggbb` string, or `undefined` if the value is not a recognised colour
91
- */
92
- export declare const normaliseColour: (value: string) => string | undefined;
93
-
94
- /**
95
- * Convert RGB channel values (0–255) to a `#rrggbb` hex string.
96
- */
97
- export declare const rgbToHex: (r: number, g: number, b: number) => string;
98
-
99
- export { }
1
+ export * from './colours/index.js'
2
+ export {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unmade/svg-helpers",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Set of helper functions for working with SVG content",
5
5
  "type": "module",
6
6
  "main": "./dist/colours.cjs",
@@ -8,9 +8,9 @@
8
8
  "types": "./dist/index.d.ts",
9
9
  "exports": {
10
10
  ".": {
11
+ "types": "./dist/index.d.ts",
11
12
  "import": "./dist/colours.mjs",
12
- "require": "./dist/colours.cjs",
13
- "types": "./dist/index.d.ts"
13
+ "require": "./dist/colours.cjs"
14
14
  }
15
15
  },
16
16
  "files": [
@@ -23,13 +23,14 @@
23
23
  "typecheck": "tsc --noEmit"
24
24
  },
25
25
  "dependencies": {
26
- "@unmade/platform": "^0.1.2"
26
+ "@unmade/platform": "^0.1.3"
27
27
  },
28
28
  "devDependencies": {
29
- "typescript": "^5.9.3",
30
- "vite": "^7.3.1",
31
- "vite-plugin-dts": "^4.5.4",
32
- "vitest": "^3.2.4"
29
+ "@typescript/typescript6": "^6.0.2",
30
+ "typescript": "^7.0.2",
31
+ "vite": "^8.0.16",
32
+ "vite-plugin-dts": "^5.0.3",
33
+ "vitest": "^4.1.10"
33
34
  },
34
35
  "keywords": [
35
36
  "svg"