@iconpik/web 0.0.0-stage → 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 thesvg.org
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/LICENSING.md ADDED
@@ -0,0 +1,184 @@
1
+ # Icon Licensing Guide
2
+
3
+ How licensing works on **thesvg.org**, what you promise when you submit, and what we promise when we publish. Plain language, with sources you can verify.
4
+
5
+ > **Not legal advice.** This document explains how we operate. If the brand you're submitting belongs to someone else and you're unsure about your rights, talk to a lawyer or the brand owner before submitting. See [DISCLAIMER.md](./DISCLAIMER.md) for the full project disclaimer.
6
+
7
+ ## Table of contents
8
+
9
+ 1. [License vs. trademark — read this first](#1-license-vs-trademark--read-this-first)
10
+ 2. [What you promise when you submit](#2-what-you-promise-when-you-submit)
11
+ 3. [What we promise when we publish](#3-what-we-promise-when-we-publish)
12
+ 4. [Pick a license by question](#4-pick-a-license-by-question)
13
+ 5. [The licenses we accept](#5-the-licenses-we-accept)
14
+ 6. [The "Other / custom" path](#6-the-other--custom-path)
15
+ 7. [What we never accept](#7-what-we-never-accept)
16
+ 8. [If you find a wrong license — takedown procedure](#8-if-you-find-a-wrong-license--takedown-procedure)
17
+
18
+ ---
19
+
20
+ ## 1. License vs. trademark — read this first
21
+
22
+ These are two different things, and **both** can apply to a brand icon. Confusing them is the single most common mistake on the submission form.
23
+
24
+ | | License | Trademark |
25
+ |---|---|---|
26
+ | **Controls** | Who can copy / modify / redistribute the **SVG file** | Who can use the **brand mark** to identify goods or services |
27
+ | **Set by** | The author or publisher of the file | The brand owner, often via national / EU registration |
28
+ | **Source of truth** | The `LICENSE` file shipped with the asset | The brand's "Brand Guidelines" or "Trademark Usage Policy" page |
29
+ | **Authoritative reference** | [SPDX License List](https://spdx.org/licenses/) | [USPTO Trademark Basics](https://www.uspto.gov/trademarks/basics), [EUIPO Trademark Basics](https://euipo.europa.eu/ohimportal/en/trade-marks-in-the-european-union) |
30
+
31
+ A logo can have a **permissive license** (the SVG is free to copy) **and** still be a **registered trademark** (you can't use it to imply endorsement, sell merchandise, or pass off your product as the brand). All brand marks on thesvg.org are subject to the original owner's trademark rights — see [TRADEMARK.md](./TRADEMARK.md) for our full policy.
32
+
33
+ **The submission form is only asking about the *license* of the SVG file itself, not whether you have permission to use the brand commercially.**
34
+
35
+ > **UI icons are different.** The interface icons at thesvg.org/ui are original drawings made for theSVG, not brand marks, so there is no trademark to consider. They are released under the [MIT license](./LICENSE) like the rest of the repository. Only contribute a UI icon you drew yourself, and never trace, convert or adapt an icon from another set. See [CONTRIBUTING.md](./CONTRIBUTING.md#ui-icons).
36
+
37
+ ---
38
+
39
+ ## 2. What you promise when you submit
40
+
41
+ By picking a license on the form, you're asserting:
42
+
43
+ 1. **You have the right to license this asset.** Either you created it, it's already published under that license by the brand owner, or it's in the public domain.
44
+ 2. **The license is accurate.** If you pick `MIT`, you're saying the upstream source actually publishes the brand mark under MIT (not just the project's code — many OSS projects have permissive code but restricted brand assets).
45
+ 3. **You'll respond if we ask follow-up questions.** Especially for the "Other / custom" path, where a maintainer will reach out on the GitHub issue.
46
+
47
+ If you're unsure about any of these, pick **"Other / custom — needs maintainer review"** and we'll figure it out together before merging. **Picking incorrectly creates legal exposure for both you and us** — that's why the form blocks submission until a license is chosen.
48
+
49
+ ---
50
+
51
+ ## 3. What we promise when we publish
52
+
53
+ When your icon lands in the registry, we:
54
+
55
+ 1. **Record your declared license verbatim** in the `icons.json` entry. Downstream consumers (apps, packages, jsDelivr, the npm package `@thesvg/icons`) inherit that field as-is. The license is part of the public API.
56
+ 2. **Surface the license on the icon's detail page** at `thesvg.org/icon/<slug>` so anyone using the icon can see what they're agreeing to.
57
+ 3. **Promptly remove or relicense an icon** if we discover the declared license is wrong — see [section 8](#8-if-you-find-a-wrong-license--takedown-procedure).
58
+ 4. **Never relicense your asset more permissively than you declared.** If you submit a CC BY-ND icon, we'll never quietly re-publish it as MIT.
59
+
60
+ What we **don't** do: We don't audit every submission against the brand owner's trademark policy at intake. We rely on submitters to be honest, on community reports for corrections, and on the [takedown procedure](./LEGAL.md) for disputes. Submitters and downstream users are responsible for trademark compliance — see [TRADEMARK.md](./TRADEMARK.md).
61
+
62
+ ---
63
+
64
+ ## 4. Pick a license by question
65
+
66
+ ### Q1. Did you draw this icon yourself, from scratch, with no copying?
67
+
68
+ **Pick:** [`CC0 1.0`](https://creativecommons.org/publicdomain/zero/1.0/) (public domain dedication)
69
+
70
+ You're waiving all rights and letting anyone use it for any purpose. Best for personal projects, generic icons, and brand kits you've designed and want to gift to the community. CC0 is the closest thing to true public domain that's legally enforceable in jurisdictions where you can't "release to public domain" by simple declaration.
71
+
72
+ ### Q2. Is this the official logo of an open-source project?
73
+
74
+ Look in the project's repository for a `LICENSE` file inside the brand-assets folder — commonly `assets/`, `branding/`, `logo/`, or `media/`. **The project's source code license is not automatically the same as the brand asset license.** Many projects deliberately restrict their brand mark even when the code is permissive.
75
+
76
+ | What the project says | Pick |
77
+ |---|---|
78
+ | Brand assets explicitly CC0 / public domain | [`CC0 1.0`](https://creativecommons.org/publicdomain/zero/1.0/) |
79
+ | Apache-licensed project, no separate brand policy | [`Apache 2.0`](https://spdx.org/licenses/Apache-2.0.html) |
80
+ | MIT-licensed project, no separate brand policy | [`MIT`](https://spdx.org/licenses/MIT.html) |
81
+ | BSD-licensed project, no separate brand policy | [`BSD-3-Clause`](https://spdx.org/licenses/BSD-3-Clause.html) |
82
+ | ISC-licensed project, no separate brand policy | [`ISC`](https://spdx.org/licenses/ISC.html) |
83
+ | MPL 2.0 project (Firefox / Mozilla) | [`MPL-2.0`](https://spdx.org/licenses/MPL-2.0.html) |
84
+ | CC BY 4.0 (Creative Commons attribution) | [`CC BY 4.0`](https://creativecommons.org/licenses/by/4.0/) |
85
+ | CC BY-SA 4.0 (share-alike, e.g. Wikipedia assets) | [`CC BY-SA 4.0`](https://creativecommons.org/licenses/by-sa/4.0/) |
86
+ | CC BY-ND 4.0 (no derivatives — common for corporate kits) | [`CC BY-ND 4.0`](https://creativecommons.org/licenses/by-nd/4.0/) |
87
+ | Brand guidelines doc with usage restrictions, no SPDX license | [Other / custom](#6-the-other--custom-path) |
88
+
89
+ ### Q3. Is this a corporate / company brand mark?
90
+
91
+ **Pick:** [Other / custom](#6-the-other--custom-path)
92
+
93
+ Most companies don't license their logos under a public open-source license. They publish brand guidelines instead — see for example [Google's Brand Resource Center](https://about.google/brand-resource-center/), [Microsoft's Trademark Usage Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks), or [Apple's Guidelines for Using Apple Trademarks](https://www.apple.com/legal/intellectualproperty/guidelinesfor3rdparties.html). Picking "Other / custom" lets us:
94
+
95
+ 1. Read the linked brand guidelines and verify the usage you're proposing is permitted.
96
+ 2. Label the issue `license-unsure` so it routes to a maintainer for confirmation.
97
+ 3. Document the actual policy in the `icons.json` entry instead of pretending it's MIT.
98
+
99
+ ### Q4. Is this a fork / modification of an existing icon?
100
+
101
+ Same license as the original — most permissive licenses require this (Apache, MPL, all CC licenses). If you can't find the original's license, pick [Other / custom](#6-the-other--custom-path).
102
+
103
+ ---
104
+
105
+ ## 5. The licenses we accept
106
+
107
+ All ten licenses below are listed in the [SPDX License List](https://spdx.org/licenses/) and most are approved by the [Open Source Initiative](https://opensource.org/licenses/). Links go to the canonical text — read it before picking.
108
+
109
+ ### Public-domain dedications
110
+
111
+ - **[CC0 1.0](https://creativecommons.org/publicdomain/zero/1.0/)** — "No Rights Reserved." Best legally-enforceable public-domain dedication. ([SPDX](https://spdx.org/licenses/CC0-1.0.html))
112
+ - **[The Unlicense](https://unlicense.org/)** — public-domain dedication common in small OSS projects. ([SPDX](https://spdx.org/licenses/Unlicense.html), [OSI-approved](https://opensource.org/license/unlicense))
113
+
114
+ ### Permissive
115
+
116
+ - **[MIT](https://opensource.org/license/mit)** — short and permissive, attribution only. The most common OSS license. ([SPDX](https://spdx.org/licenses/MIT.html))
117
+ - **[Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0)** — permissive with an explicit patent grant. Common for cloud / infra brands. ([SPDX](https://spdx.org/licenses/Apache-2.0.html), [OSI-approved](https://opensource.org/license/apache-2-0))
118
+ - **[BSD 3-Clause](https://opensource.org/license/bsd-3-clause)** — permissive with attribution + no-endorsement clause. ([SPDX](https://spdx.org/licenses/BSD-3-Clause.html))
119
+ - **[ISC](https://opensource.org/license/isc-license-txt)** — functionally equivalent to MIT, shorter text. ([SPDX](https://spdx.org/licenses/ISC.html))
120
+
121
+ ### Creative Commons attribution family
122
+
123
+ The CC family is published by the [Creative Commons](https://creativecommons.org/) non-profit. Each license has a [machine-readable summary](https://creativecommons.org/share-your-work/cclicenses/) and full legal code.
124
+
125
+ - **[CC BY 4.0](https://creativecommons.org/licenses/by/4.0/)** — attribution required, otherwise unrestricted. ([SPDX](https://spdx.org/licenses/CC-BY-4.0.html))
126
+ - **[CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/)** — attribution + share-alike. Wikipedia uses this for most of its assets. ([SPDX](https://spdx.org/licenses/CC-BY-SA-4.0.html))
127
+ - **[CC BY-ND 4.0](https://creativecommons.org/licenses/by-nd/4.0/)** — attribution, **no derivatives**. Picking this means the logo cannot be modified, only used as-is. Common for corporate brand kits. ([SPDX](https://spdx.org/licenses/CC-BY-ND-4.0.html))
128
+
129
+ ### Weak copyleft
130
+
131
+ - **[Mozilla Public License 2.0](https://www.mozilla.org/en-US/MPL/2.0/)** — file-level copyleft. Used by Firefox, Thunderbird, and Mozilla-adjacent projects. ([SPDX](https://spdx.org/licenses/MPL-2.0.html), [OSI-approved](https://opensource.org/license/mpl-2-0))
132
+
133
+ ---
134
+
135
+ ## 6. The "Other / custom" path
136
+
137
+ Pick **"Other / custom — needs maintainer review"** when any of these apply:
138
+
139
+ - The asset has a real license, but it's not in the list above (e.g. a custom company brand-usage policy, EPL, AGPL, a CC license we don't pre-stock).
140
+ - The brand has published guidelines but no formal SPDX license at all.
141
+ - You're not sure and want a maintainer to confirm before merging.
142
+
143
+ When you pick Other:
144
+
145
+ 1. You'll be prompted for a short description (≤120 chars). Examples:
146
+ - `"Acme Brand Guidelines v2 — non-commercial only"`
147
+ - `"Custom — written permission from owner, see issue thread"`
148
+ - `"EPL-2.0"`
149
+ 2. The auto-generated GitHub issue is labeled [`license-unsure`](https://github.com/GLINCKER/thesvg/issues?q=label%3Alicense-unsure).
150
+ 3. A maintainer reviews the source link, the brand guidelines, and the description before merging. They may request more info on the issue thread.
151
+ 4. If the license is verifiable and acceptable, the asset is merged with the declared text recorded verbatim in `icons.json`.
152
+
153
+ **This path is not a way to bypass the rules — it's a way to be honest about ambiguity.** A clearly-labeled `license-unsure` submission is much easier to handle than a "yeah, just say MIT" submission that we have to take down later.
154
+
155
+ ---
156
+
157
+ ## 7. What we never accept
158
+
159
+ - **"All rights reserved"** assets without explicit, documented owner permission. Even if you uploaded it, we can't republish it without rights.
160
+ - **Assets where the license forbids redistribution.** Some brand assets are licensed only for internal company use — those can't go into a public registry.
161
+ - **Mislabeled licenses.** Submitting a CC BY-ND asset as MIT, for example. This creates legal exposure for you, for us, and for every downstream consumer.
162
+ - **Assets you found on the internet with no traceable source.** "I got it from Google Images" is not a license declaration.
163
+
164
+ ---
165
+
166
+ ## 8. If you find a wrong license — takedown procedure
167
+
168
+ License accuracy is a first-class concern for us. If you spot an icon whose declared license is wrong (e.g. marked MIT when it should be Other / proprietary):
169
+
170
+ 1. **Open an issue** at [github.com/GLINCKER/thesvg/issues](https://github.com/GLINCKER/thesvg/issues/new) titled `[License] <slug> — <what's wrong>`.
171
+ 2. Include: the icon slug, the declared license in the registry, what you believe the correct license is, and a link to the authoritative source.
172
+ 3. We aim to respond within 72 hours. For verifiable mistakes we either relicense the entry or remove the asset entirely.
173
+
174
+ For formal takedown requests from rights-holders or their representatives, see the procedure in [LEGAL.md](./LEGAL.md).
175
+
176
+ ---
177
+
178
+ ## Related policies
179
+
180
+ - [DISCLAIMER.md](./DISCLAIMER.md) — project disclaimer
181
+ - [LEGAL.md](./LEGAL.md) — DMCA / takedown procedure
182
+ - [TRADEMARK.md](./TRADEMARK.md) — trademark policy
183
+ - [CONTRIBUTING.md](./CONTRIBUTING.md) — general contribution guide
184
+ - [CODE_OF_CONDUCT.md](./CODE_OF_CONDUCT.md) — community standards
package/NOTICE.md ADDED
@@ -0,0 +1,7 @@
1
+ # iconPik attribution
2
+
3
+ Derived from [theSVG](https://github.com/glincker/thesvg), originally copyright thesvg.org.
4
+ Original MIT license and third-party icon notices are included unchanged.
5
+ Brand names, logos and flags retain their respective owners and applicable licenses.
6
+
7
+ iconPik packaging and distribution: https://www.iconpik.com
package/README.md CHANGED
@@ -1,3 +1,47 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
1
+ # @iconpik/web
2
+
3
+ Framework-free helper for [thesvg.org](https://www.iconpik.com) brand icons. Swap `<i data-iconpik="github"></i>` for inline SVG, or get SVG strings directly. Pure TypeScript, ESM and CJS, no runtime dependencies.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @iconpik/web @iconpik/icons
9
+ ```
10
+
11
+ `@iconpik/icons` is an optional peer dependency: this package only needs the icon modules you pass in, so bundlers keep just the icons you import.
12
+
13
+ ## createIcons
14
+
15
+ ```html
16
+ <i data-iconpik="github"></i>
17
+ <i data-iconpik="figma" data-iconpik-variant="mono" data-iconpik-size="32" class="logo"></i>
18
+ ```
19
+
20
+ ```ts
21
+ import { github, figma } from "@iconpik/icons";
22
+ import { createIcons } from "@iconpik/web";
23
+
24
+ createIcons({ icons: { github, figma } });
25
+ ```
26
+
27
+ Options: `icons` (required), `nameAttr` (default `data-iconpik`), `root` (default `document`). Unknown names are left in place. `class` and other attributes on the placeholder carry over to the svg. Returns the number of elements replaced.
28
+
29
+ ## getIconSvg
30
+
31
+ ```ts
32
+ import { github } from "@iconpik/icons";
33
+ import { getIconSvg } from "@iconpik/web";
34
+
35
+ getIconSvg(github, { size: 24, className: "logo", title: "GitHub" });
36
+ getIconSvg("github", { icons: { github }, variant: "mono" });
37
+ ```
38
+
39
+ Options: `icons`, `variant`, `size`, `className`, `title` (adds `role="img"` and `aria-label`, otherwise `aria-hidden`), `attrs`. Returns `undefined` for unknown icons.
40
+
41
+ Names resolve by key, camelCased key, or icon slug, so `1password` finds the `_1password` export.
42
+
43
+ ## Related
44
+
45
+ `@iconpik/icons` (SVG strings), `@iconpik/react`, `@iconpik/static` (raw files for CDNs).
46
+
47
+ MIT. Brand marks remain the property of their owners.
@@ -0,0 +1,81 @@
1
+ # Third-party notices
2
+
3
+ This file is generated by `scripts/flags/generate-flags.mjs`. Do not edit it by hand.
4
+
5
+ The flag artwork in `public/icons/flag-*` and in `@thesvg/flags` is derived from the open source projects below. Each is MIT licensed, which requires that the copyright notice and license text accompany copies of the software. They are reproduced here in full. The SVG files were optimized with SVGO; the artwork is otherwise unchanged and the files carry no credit text, so the notices live here and in `packages/flags/src/data/licenses.json`, which maps every file to its upstream path.
6
+
7
+ National flags are public symbols. The MIT license covers the SVG drawings in those repositories, not any right of a state or organization in its own emblem. See LEGAL.md and DISCLAIMER.md.
8
+
9
+ ## flag-icons
10
+
11
+ - URL: https://github.com/lipis/flag-icons
12
+ - Version: 7.6.0, commit ac7e0eb3259eb62aa6100c435607e2fe03896a97
13
+ - License: MIT
14
+ - Accessed: 2026-11-13
15
+
16
+ The MIT License (MIT)
17
+
18
+ Copyright (c) 2013 Panayiotis Lipiridis
19
+
20
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
21
+ this software and associated documentation files (the "Software"), to deal in
22
+ the Software without restriction, including without limitation the rights to
23
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
24
+ of the Software, and to permit persons to whom the Software is furnished to do
25
+ so, subject to the following conditions:
26
+
27
+ The above copyright notice and this permission notice shall be included in all
28
+ copies or substantial portions of the Software.
29
+
30
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
31
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
32
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
33
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
34
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
35
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36
+ SOFTWARE.
37
+
38
+ ## circle-flags
39
+
40
+ - URL: https://github.com/HatScripts/circle-flags
41
+ - Version: main, commit 379588b5da95482d6bbf10bd45644a35b0609ea6
42
+ - License: MIT
43
+ - Accessed: 2026-11-13
44
+
45
+ # MIT License
46
+
47
+ Copyright (c) 2026 HatScripts
48
+
49
+ Permission is hereby granted, free of charge, to any person obtaining a copy
50
+ of this software and associated documentation files (the "Software"), to deal
51
+ in the Software without restriction, including without limitation the rights
52
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
53
+ copies of the Software, and to permit persons to whom the Software is
54
+ furnished to do so, subject to the following conditions:
55
+
56
+ The above copyright notice and this permission notice shall be included in all
57
+ copies or substantial portions of the Software.
58
+
59
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
60
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
61
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
62
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
63
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
64
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
65
+ SOFTWARE.
66
+
67
+ ## wikimedia-commons (rectangle variants of a few regional flags)
68
+
69
+ - URL: https://commons.wikimedia.org
70
+ - License: public domain or CC0, per file, verified through the Commons API on 2026-11-13. Neither requires attribution; the files are listed for transparency.
71
+
72
+ - Flag of Corsica.svg by Patricia.fidi, CC0: https://commons.wikimedia.org/wiki/File:Flag_of_Corsica.svg
73
+ - Flag of Occitania (with star).svg by Nimlar and others, Public domain: https://commons.wikimedia.org/wiki/File:Flag_of_Occitania_(with_star).svg
74
+ - Flag of the Balearic Islands.svg by see file page, CC0: https://commons.wikimedia.org/wiki/File:Flag_of_the_Balearic_Islands.svg
75
+ - Flag of the Land of Valencia (official).svg by Mutxamel and others, Public domain: https://commons.wikimedia.org/wiki/File:Flag_of_the_Land_of_Valencia_(official).svg
76
+
77
+ ## Reference data used only to validate and label (not redistributed)
78
+
79
+ - i18n-iso-countries 7.14.0 (MIT): ISO 3166-1 alpha-2, alpha-3 and numeric codes and localized country names.
80
+ - Unicode CLDR via cldr-core 47.0.0 (Unicode License V3): territory languages.
81
+ - Wikimedia Commons files were used only where listed above; otherwise they were a manual cross-check.
@@ -0,0 +1,154 @@
1
+ "use strict";
2
+ /**
3
+ * @iconpik/web: framework-free helpers that turn @iconpik/icons modules into inline SVG.
4
+ * Icons are passed in by the caller, so bundlers only keep the icons you import.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.findIcon = findIcon;
8
+ exports.getIconSvg = getIconSvg;
9
+ exports.createIcons = createIcons;
10
+ const SVG_OPEN = /<svg\b[^>]*>/i;
11
+ // Module-level so every returned svg gets a fresh prefix, even across calls in one document.
12
+ let idCounter = 0;
13
+ function escapeRe(value) {
14
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
15
+ }
16
+ /** Prefixes every id and each reference to it (url(#), href, aria id lists, style selectors). */
17
+ function uniquifyIds(svg) {
18
+ const ids = new Set();
19
+ for (const m of svg.matchAll(/\sid\s*=\s*(?:"([^"]*)"|'([^']*)')/gi)) {
20
+ const id = m[1] ?? m[2];
21
+ if (id)
22
+ ids.add(id);
23
+ }
24
+ if (ids.size === 0)
25
+ return svg;
26
+ const prefix = `iconpik-${++idCounter}-`;
27
+ const alt = Array.from(ids)
28
+ .sort((a, b) => b.length - a.length)
29
+ .map(escapeRe)
30
+ .join("|");
31
+ let out = svg;
32
+ out = out.replace(/(\sid\s*=\s*)(["'])([^"']*)\2/gi, (all, head, q, id) => ids.has(id) ? `${head}${q}${prefix}${id}${q}` : all);
33
+ out = out.replace(new RegExp(`url\\(\\s*(["']?)#(${alt})\\1\\s*\\)`, "g"), (_, q, id) => `url(${q}#${prefix}${id}${q})`);
34
+ out = out.replace(new RegExp(`((?:xlink:)?href\\s*=\\s*)(["'])#(${alt})\\2`, "gi"), (_, head, q, id) => `${head}${q}#${prefix}${id}${q}`);
35
+ out = out.replace(/(\saria-(?:labelledby|describedby|controls|owns|flowto|activedescendant|details)\s*=\s*)(["'])([^"']*)\2/gi, (_, head, q, list) => `${head}${q}${list
36
+ .split(/\s+/)
37
+ .map((t) => (ids.has(t) ? prefix + t : t))
38
+ .join(" ")}${q}`);
39
+ out = out.replace(/(<style\b[^>]*>)([\s\S]*?)(<\/style>)/gi, (_, open, css, close) => `${open}${css.replace(new RegExp(`#(${alt})(?![\\w-])`, "g"), (__, id) => `#${prefix}${id}`)}${close}`);
40
+ return out;
41
+ }
42
+ function hasAccessibleName(attrs) {
43
+ if (!attrs)
44
+ return false;
45
+ return ["aria-label", "aria-labelledby"].some((k) => attrs[k] !== undefined && attrs[k] !== null && attrs[k] !== "");
46
+ }
47
+ function escapeAttr(value) {
48
+ return value.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
49
+ }
50
+ function setAttr(tag, name, value) {
51
+ const existing = new RegExp(`\\s${name}\\s*=\\s*("[^"]*"|'[^']*')`, "i");
52
+ const cleaned = tag.replace(existing, "");
53
+ if (value === null)
54
+ return cleaned;
55
+ return cleaned.replace(/\/?>$/, (end) => ` ${name}="${escapeAttr(value)}"${end}`);
56
+ }
57
+ function camelCase(name) {
58
+ return name.replace(/[-_\s]+(.)?/g, (_, c) => (c ? c.toUpperCase() : ""));
59
+ }
60
+ /** Finds an icon by key, slug, or camelCased key. */
61
+ function findIcon(icons, name) {
62
+ const direct = icons[name];
63
+ if (direct)
64
+ return direct;
65
+ const camel = icons[camelCase(name)];
66
+ if (camel)
67
+ return camel;
68
+ const prefixed = icons[`_${name}`];
69
+ if (prefixed)
70
+ return prefixed;
71
+ for (const key of Object.keys(icons)) {
72
+ if (icons[key]?.slug === name)
73
+ return icons[key];
74
+ }
75
+ return undefined;
76
+ }
77
+ /**
78
+ * Returns the SVG markup for an icon, or undefined when the name or variant source is missing.
79
+ * Pass an icon module directly, or a name together with `opts.icons`.
80
+ */
81
+ function getIconSvg(nameOrIcon, opts = {}) {
82
+ const icon = typeof nameOrIcon === "string" ? (opts.icons ? findIcon(opts.icons, nameOrIcon) : undefined) : nameOrIcon;
83
+ if (!icon)
84
+ return undefined;
85
+ const source = (opts.variant && icon.variants?.[opts.variant]) || icon.svg;
86
+ if (!source)
87
+ return undefined;
88
+ const match = SVG_OPEN.exec(source);
89
+ if (!match)
90
+ return undefined;
91
+ let tag = match[0];
92
+ if (opts.size !== undefined) {
93
+ tag = setAttr(tag, "width", String(opts.size));
94
+ tag = setAttr(tag, "height", String(opts.size));
95
+ }
96
+ if (opts.className)
97
+ tag = setAttr(tag, "class", opts.className);
98
+ if (opts.title) {
99
+ tag = setAttr(tag, "role", "img");
100
+ tag = setAttr(tag, "aria-label", opts.title);
101
+ }
102
+ else if (!hasAccessibleName(opts.attrs)) {
103
+ tag = setAttr(tag, "aria-hidden", "true");
104
+ }
105
+ for (const [key, value] of Object.entries(opts.attrs ?? {})) {
106
+ tag = setAttr(tag, key, value === null ? null : String(value));
107
+ }
108
+ return uniquifyIds(source.replace(SVG_OPEN, () => tag)).trim();
109
+ }
110
+ /**
111
+ * Replaces every element carrying `nameAttr` with its inline SVG. Unknown names are left untouched.
112
+ * Per-element options: `data-iconpik-variant`, `data-iconpik-size`; class and other attributes carry over.
113
+ * Returns the number of elements replaced.
114
+ */
115
+ function createIcons({ icons, nameAttr = "data-iconpik", root = document }) {
116
+ const hosts = Array.from(root.querySelectorAll(`[${nameAttr}]`));
117
+ let replaced = 0;
118
+ for (const host of hosts) {
119
+ const name = host.getAttribute(nameAttr);
120
+ if (!name)
121
+ continue;
122
+ const className = host.getAttribute("class") ?? undefined;
123
+ // A named placeholder must not come out aria-hidden.
124
+ const attrs = {};
125
+ for (const key of ["aria-label", "aria-labelledby"]) {
126
+ const v = host.getAttribute(key);
127
+ if (v)
128
+ attrs[key] = v;
129
+ }
130
+ const markup = getIconSvg(name, {
131
+ icons,
132
+ variant: host.getAttribute(`${nameAttr}-variant`) ?? undefined,
133
+ size: host.getAttribute(`${nameAttr}-size`) ?? undefined,
134
+ className,
135
+ attrs,
136
+ });
137
+ if (!markup)
138
+ continue;
139
+ const doc = host.ownerDocument;
140
+ const holder = doc.createElement("template");
141
+ holder.innerHTML = markup;
142
+ const svg = holder.content.firstElementChild;
143
+ if (!svg)
144
+ continue;
145
+ for (const attr of Array.from(host.attributes)) {
146
+ if (attr.name === nameAttr || attr.name.startsWith(`${nameAttr}-`) || attr.name === "class")
147
+ continue;
148
+ svg.setAttribute(attr.name, attr.value);
149
+ }
150
+ host.replaceWith(svg);
151
+ replaced++;
152
+ }
153
+ return replaced;
154
+ }
@@ -0,0 +1,48 @@
1
+ /**
2
+ * @iconpik/web: framework-free helpers that turn @iconpik/icons modules into inline SVG.
3
+ * Icons are passed in by the caller, so bundlers only keep the icons you import.
4
+ */
5
+ /** Structural subset of an @iconpik/icons module, so this package needs no runtime import of it. */
6
+ export interface WebIcon {
7
+ slug?: string;
8
+ title?: string;
9
+ svg: string;
10
+ variants?: Record<string, string>;
11
+ }
12
+ /** Icons keyed by name, e.g. `{ github }` from `import { github } from "@iconpik/icons"`. */
13
+ export type IconSet = Record<string, WebIcon>;
14
+ export interface IconSvgOptions {
15
+ /** Icon set to look the name up in. Not needed when the first argument is an icon module. */
16
+ icons?: IconSet;
17
+ /** Variant name such as "mono" or "dark". Falls back to the default svg. */
18
+ variant?: string;
19
+ /** Sets width and height on the root svg. */
20
+ size?: number | string;
21
+ /** Sets the class attribute on the root svg. */
22
+ className?: string;
23
+ /** Adds role="img" and an aria-label. Without a title, aria-label or aria-labelledby the svg is aria-hidden. */
24
+ title?: string;
25
+ /** Extra attributes for the root svg. A null value removes the attribute. */
26
+ attrs?: Record<string, string | number | null>;
27
+ }
28
+ export interface CreateIconsOptions {
29
+ icons: IconSet;
30
+ /** Attribute that holds the icon name. */
31
+ nameAttr?: string;
32
+ /** Element or document to scan. */
33
+ root?: ParentNode;
34
+ }
35
+ /** Finds an icon by key, slug, or camelCased key. */
36
+ export declare function findIcon(icons: IconSet, name: string): WebIcon | undefined;
37
+ /**
38
+ * Returns the SVG markup for an icon, or undefined when the name or variant source is missing.
39
+ * Pass an icon module directly, or a name together with `opts.icons`.
40
+ */
41
+ export declare function getIconSvg(nameOrIcon: string | WebIcon, opts?: IconSvgOptions): string | undefined;
42
+ /**
43
+ * Replaces every element carrying `nameAttr` with its inline SVG. Unknown names are left untouched.
44
+ * Per-element options: `data-iconpik-variant`, `data-iconpik-size`; class and other attributes carry over.
45
+ * Returns the number of elements replaced.
46
+ */
47
+ export declare function createIcons({ icons, nameAttr, root }: CreateIconsOptions): number;
48
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,oGAAoG;AACpG,MAAM,WAAW,OAAO;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACnC;AAED,6FAA6F;AAC7F,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE9C,MAAM,WAAW,cAAc;IAC7B,6FAA6F;IAC7F,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,4EAA4E;IAC5E,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,6CAA6C;IAC7C,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACvB,gDAAgD;IAChD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gHAAgH;IAChH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,6EAA6E;IAC7E,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC,CAAC;CAChD;AAED,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,OAAO,CAAC;IACf,0CAA0C;IAC1C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,mCAAmC;IACnC,IAAI,CAAC,EAAE,UAAU,CAAC;CACnB;AAwED,qDAAqD;AACrD,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAW1E;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,EAAE,IAAI,GAAE,cAAmB,GAAG,MAAM,GAAG,SAAS,CAwBtG;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,EAAE,KAAK,EAAE,QAAyB,EAAE,IAAe,EAAE,EAAE,kBAAkB,GAAG,MAAM,CAkC7G"}
package/dist/index.js ADDED
@@ -0,0 +1,149 @@
1
+ /**
2
+ * @iconpik/web: framework-free helpers that turn @iconpik/icons modules into inline SVG.
3
+ * Icons are passed in by the caller, so bundlers only keep the icons you import.
4
+ */
5
+ const SVG_OPEN = /<svg\b[^>]*>/i;
6
+ // Module-level so every returned svg gets a fresh prefix, even across calls in one document.
7
+ let idCounter = 0;
8
+ function escapeRe(value) {
9
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
10
+ }
11
+ /** Prefixes every id and each reference to it (url(#), href, aria id lists, style selectors). */
12
+ function uniquifyIds(svg) {
13
+ const ids = new Set();
14
+ for (const m of svg.matchAll(/\sid\s*=\s*(?:"([^"]*)"|'([^']*)')/gi)) {
15
+ const id = m[1] ?? m[2];
16
+ if (id)
17
+ ids.add(id);
18
+ }
19
+ if (ids.size === 0)
20
+ return svg;
21
+ const prefix = `iconpik-${++idCounter}-`;
22
+ const alt = Array.from(ids)
23
+ .sort((a, b) => b.length - a.length)
24
+ .map(escapeRe)
25
+ .join("|");
26
+ let out = svg;
27
+ out = out.replace(/(\sid\s*=\s*)(["'])([^"']*)\2/gi, (all, head, q, id) => ids.has(id) ? `${head}${q}${prefix}${id}${q}` : all);
28
+ out = out.replace(new RegExp(`url\\(\\s*(["']?)#(${alt})\\1\\s*\\)`, "g"), (_, q, id) => `url(${q}#${prefix}${id}${q})`);
29
+ out = out.replace(new RegExp(`((?:xlink:)?href\\s*=\\s*)(["'])#(${alt})\\2`, "gi"), (_, head, q, id) => `${head}${q}#${prefix}${id}${q}`);
30
+ out = out.replace(/(\saria-(?:labelledby|describedby|controls|owns|flowto|activedescendant|details)\s*=\s*)(["'])([^"']*)\2/gi, (_, head, q, list) => `${head}${q}${list
31
+ .split(/\s+/)
32
+ .map((t) => (ids.has(t) ? prefix + t : t))
33
+ .join(" ")}${q}`);
34
+ out = out.replace(/(<style\b[^>]*>)([\s\S]*?)(<\/style>)/gi, (_, open, css, close) => `${open}${css.replace(new RegExp(`#(${alt})(?![\\w-])`, "g"), (__, id) => `#${prefix}${id}`)}${close}`);
35
+ return out;
36
+ }
37
+ function hasAccessibleName(attrs) {
38
+ if (!attrs)
39
+ return false;
40
+ return ["aria-label", "aria-labelledby"].some((k) => attrs[k] !== undefined && attrs[k] !== null && attrs[k] !== "");
41
+ }
42
+ function escapeAttr(value) {
43
+ return value.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
44
+ }
45
+ function setAttr(tag, name, value) {
46
+ const existing = new RegExp(`\\s${name}\\s*=\\s*("[^"]*"|'[^']*')`, "i");
47
+ const cleaned = tag.replace(existing, "");
48
+ if (value === null)
49
+ return cleaned;
50
+ return cleaned.replace(/\/?>$/, (end) => ` ${name}="${escapeAttr(value)}"${end}`);
51
+ }
52
+ function camelCase(name) {
53
+ return name.replace(/[-_\s]+(.)?/g, (_, c) => (c ? c.toUpperCase() : ""));
54
+ }
55
+ /** Finds an icon by key, slug, or camelCased key. */
56
+ export function findIcon(icons, name) {
57
+ const direct = icons[name];
58
+ if (direct)
59
+ return direct;
60
+ const camel = icons[camelCase(name)];
61
+ if (camel)
62
+ return camel;
63
+ const prefixed = icons[`_${name}`];
64
+ if (prefixed)
65
+ return prefixed;
66
+ for (const key of Object.keys(icons)) {
67
+ if (icons[key]?.slug === name)
68
+ return icons[key];
69
+ }
70
+ return undefined;
71
+ }
72
+ /**
73
+ * Returns the SVG markup for an icon, or undefined when the name or variant source is missing.
74
+ * Pass an icon module directly, or a name together with `opts.icons`.
75
+ */
76
+ export function getIconSvg(nameOrIcon, opts = {}) {
77
+ const icon = typeof nameOrIcon === "string" ? (opts.icons ? findIcon(opts.icons, nameOrIcon) : undefined) : nameOrIcon;
78
+ if (!icon)
79
+ return undefined;
80
+ const source = (opts.variant && icon.variants?.[opts.variant]) || icon.svg;
81
+ if (!source)
82
+ return undefined;
83
+ const match = SVG_OPEN.exec(source);
84
+ if (!match)
85
+ return undefined;
86
+ let tag = match[0];
87
+ if (opts.size !== undefined) {
88
+ tag = setAttr(tag, "width", String(opts.size));
89
+ tag = setAttr(tag, "height", String(opts.size));
90
+ }
91
+ if (opts.className)
92
+ tag = setAttr(tag, "class", opts.className);
93
+ if (opts.title) {
94
+ tag = setAttr(tag, "role", "img");
95
+ tag = setAttr(tag, "aria-label", opts.title);
96
+ }
97
+ else if (!hasAccessibleName(opts.attrs)) {
98
+ tag = setAttr(tag, "aria-hidden", "true");
99
+ }
100
+ for (const [key, value] of Object.entries(opts.attrs ?? {})) {
101
+ tag = setAttr(tag, key, value === null ? null : String(value));
102
+ }
103
+ return uniquifyIds(source.replace(SVG_OPEN, () => tag)).trim();
104
+ }
105
+ /**
106
+ * Replaces every element carrying `nameAttr` with its inline SVG. Unknown names are left untouched.
107
+ * Per-element options: `data-iconpik-variant`, `data-iconpik-size`; class and other attributes carry over.
108
+ * Returns the number of elements replaced.
109
+ */
110
+ export function createIcons({ icons, nameAttr = "data-iconpik", root = document }) {
111
+ const hosts = Array.from(root.querySelectorAll(`[${nameAttr}]`));
112
+ let replaced = 0;
113
+ for (const host of hosts) {
114
+ const name = host.getAttribute(nameAttr);
115
+ if (!name)
116
+ continue;
117
+ const className = host.getAttribute("class") ?? undefined;
118
+ // A named placeholder must not come out aria-hidden.
119
+ const attrs = {};
120
+ for (const key of ["aria-label", "aria-labelledby"]) {
121
+ const v = host.getAttribute(key);
122
+ if (v)
123
+ attrs[key] = v;
124
+ }
125
+ const markup = getIconSvg(name, {
126
+ icons,
127
+ variant: host.getAttribute(`${nameAttr}-variant`) ?? undefined,
128
+ size: host.getAttribute(`${nameAttr}-size`) ?? undefined,
129
+ className,
130
+ attrs,
131
+ });
132
+ if (!markup)
133
+ continue;
134
+ const doc = host.ownerDocument;
135
+ const holder = doc.createElement("template");
136
+ holder.innerHTML = markup;
137
+ const svg = holder.content.firstElementChild;
138
+ if (!svg)
139
+ continue;
140
+ for (const attr of Array.from(host.attributes)) {
141
+ if (attr.name === nameAttr || attr.name.startsWith(`${nameAttr}-`) || attr.name === "class")
142
+ continue;
143
+ svg.setAttribute(attr.name, attr.value);
144
+ }
145
+ host.replaceWith(svg);
146
+ replaced++;
147
+ }
148
+ return replaced;
149
+ }
package/package.json CHANGED
@@ -1,6 +1,75 @@
1
1
  {
2
2
  "name": "@iconpik/web",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "Framework-free helper that swaps data-iconpik elements for inline brand SVGs from @iconpik/icons",
5
+ "type": "module",
6
+ "sideEffects": false,
7
+ "license": "MIT",
8
+ "author": "iconPik contributors",
9
+ "homepage": "https://www.iconpik.com",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/mrdoing/iconpik.git",
13
+ "directory": "packages/web"
14
+ },
15
+ "bugs": {
16
+ "url": "https://github.com/mrdoing/iconpik/issues"
17
+ },
18
+ "keywords": [
19
+ "svg",
20
+ "icons",
21
+ "brand",
22
+ "logos",
23
+ "vanilla",
24
+ "dom",
25
+ "tree-shakeable",
26
+ "esm",
27
+ "typescript"
28
+ ],
29
+ "exports": {
30
+ ".": {
31
+ "types": "./dist/index.d.ts",
32
+ "import": "./dist/index.js",
33
+ "require": "./dist/cjs/index.cjs"
34
+ },
35
+ "./package.json": "./package.json"
36
+ },
37
+ "main": "./dist/cjs/index.cjs",
38
+ "module": "./dist/index.js",
39
+ "types": "./dist/index.d.ts",
40
+ "files": [
41
+ "dist",
42
+ "README.md",
43
+ "LICENSE",
44
+ "NOTICE.md",
45
+ "LICENSING.md",
46
+ "THIRD_PARTY_NOTICES.md"
47
+ ],
48
+ "peerDependencies": {
49
+ "@iconpik/icons": "^0.1.0"
50
+ },
51
+ "peerDependenciesMeta": {
52
+ "@iconpik/icons": {
53
+ "optional": true
54
+ }
55
+ },
56
+ "devDependencies": {
57
+ "tsx": "^4.23.15",
58
+ "typescript": "^6.0.3"
59
+ },
60
+ "engines": {
61
+ "node": ">=18"
62
+ },
63
+ "publishConfig": {
64
+ "access": "public",
65
+ "registry": "https://registry.npmjs.org/",
66
+ "provenance": false
67
+ },
68
+ "contributors": [
69
+ "thesvg.org (upstream)"
70
+ ],
71
+ "scripts": {
72
+ "build": "node scripts/build.mjs",
73
+ "test": "node scripts/build.mjs && tsx --test test/*.test.ts"
74
+ }
6
75
  }