@haoduo-icon/flag 1.0.0 → 1.0.2
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/package.json +1 -1
- package/pkg-index.js +51 -9
package/package.json
CHANGED
package/pkg-index.js
CHANGED
|
@@ -580,11 +580,25 @@ class HdIcon extends HTMLElement {
|
|
|
580
580
|
static get observedAttributes() {
|
|
581
581
|
return ["icon"];
|
|
582
582
|
}
|
|
583
|
-
_use;
|
|
583
|
+
_use = null;
|
|
584
584
|
constructor() {
|
|
585
585
|
super();
|
|
586
|
-
|
|
587
|
-
|
|
586
|
+
}
|
|
587
|
+
ensureTemplate() {
|
|
588
|
+
if (this._use)
|
|
589
|
+
return;
|
|
590
|
+
const svgNs = "http://www.w3.org/2000/svg";
|
|
591
|
+
const svg = document.createElementNS(svgNs, "svg");
|
|
592
|
+
svg.setAttribute("width", "1em");
|
|
593
|
+
svg.setAttribute("height", "1em");
|
|
594
|
+
svg.setAttribute("fill", "currentColor");
|
|
595
|
+
svg.setAttribute("style", "display: inline-block; vertical-align: middle; overflow: hidden;");
|
|
596
|
+
const use = document.createElementNS(svgNs, "use");
|
|
597
|
+
use.setAttribute("width", "100%");
|
|
598
|
+
use.setAttribute("height", "100%");
|
|
599
|
+
svg.appendChild(use);
|
|
600
|
+
this.appendChild(svg);
|
|
601
|
+
this._use = use;
|
|
588
602
|
}
|
|
589
603
|
attributeChangedCallback(name, oldValue, newValue) {
|
|
590
604
|
if (name === "icon" && newValue !== oldValue) {
|
|
@@ -592,6 +606,7 @@ class HdIcon extends HTMLElement {
|
|
|
592
606
|
}
|
|
593
607
|
}
|
|
594
608
|
connectedCallback() {
|
|
609
|
+
this.ensureTemplate();
|
|
595
610
|
this.render();
|
|
596
611
|
if (typeof window !== "undefined") {
|
|
597
612
|
window.addEventListener("hd-icon-registered", this.handleRegistration);
|
|
@@ -602,22 +617,49 @@ class HdIcon extends HTMLElement {
|
|
|
602
617
|
window.removeEventListener("hd-icon-registered", this.handleRegistration);
|
|
603
618
|
}
|
|
604
619
|
}
|
|
620
|
+
parseIconKey(iconKey) {
|
|
621
|
+
if (!iconKey)
|
|
622
|
+
return null;
|
|
623
|
+
const colonIndex = iconKey.indexOf(":");
|
|
624
|
+
if (colonIndex > 0 && colonIndex < iconKey.length - 1) {
|
|
625
|
+
return {
|
|
626
|
+
pkg: iconKey.slice(0, colonIndex),
|
|
627
|
+
name: iconKey.slice(colonIndex + 1)
|
|
628
|
+
};
|
|
629
|
+
}
|
|
630
|
+
const registry = getRegistry();
|
|
631
|
+
let matchedPkg = "";
|
|
632
|
+
for (const pkg of registry.keys()) {
|
|
633
|
+
if (iconKey.startsWith(pkg + "-") && pkg.length > matchedPkg.length) {
|
|
634
|
+
matchedPkg = pkg;
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
if (matchedPkg) {
|
|
638
|
+
return {
|
|
639
|
+
pkg: matchedPkg,
|
|
640
|
+
name: iconKey.slice(matchedPkg.length + 1)
|
|
641
|
+
};
|
|
642
|
+
}
|
|
643
|
+
return null;
|
|
644
|
+
}
|
|
605
645
|
handleRegistration = (e) => {
|
|
606
646
|
const detail = e.detail;
|
|
607
647
|
const iconKey = this.getAttribute("icon");
|
|
608
|
-
if (iconKey && iconKey.startsWith(detail.pkg + ":")) {
|
|
648
|
+
if (iconKey && (iconKey.startsWith(detail.pkg + ":") || iconKey.startsWith(detail.pkg + "-"))) {
|
|
609
649
|
this.render();
|
|
610
650
|
}
|
|
611
651
|
};
|
|
612
652
|
async render() {
|
|
653
|
+
this.ensureTemplate();
|
|
613
654
|
const iconKey = this.getAttribute("icon");
|
|
614
655
|
if (!iconKey)
|
|
615
656
|
return;
|
|
616
|
-
const
|
|
617
|
-
if (!
|
|
618
|
-
console.warn(`[hd-icon] Invalid icon format: "${iconKey}". Expected "pkg:name".`);
|
|
657
|
+
const parsed = this.parseIconKey(iconKey);
|
|
658
|
+
if (!parsed) {
|
|
659
|
+
console.warn(`[hd-icon] Invalid icon format: "${iconKey}". Expected "pkg:name" or "pkg-name".`);
|
|
619
660
|
return;
|
|
620
661
|
}
|
|
662
|
+
const { pkg, name } = parsed;
|
|
621
663
|
const registry = getRegistry().get(pkg);
|
|
622
664
|
if (!registry) {
|
|
623
665
|
return;
|
|
@@ -651,7 +693,7 @@ class HdIcon extends HTMLElement {
|
|
|
651
693
|
console.warn(`[hd-icon] Failed to resolve icon URL: ${chunkFile} relative to ${registry.baseUrl}`, e);
|
|
652
694
|
}
|
|
653
695
|
}
|
|
654
|
-
this._use
|
|
696
|
+
this._use?.setAttribute("href", `${url}#${symbolId}`);
|
|
655
697
|
}
|
|
656
698
|
}
|
|
657
699
|
if (typeof customElements !== "undefined" && !customElements.get("hd-icon")) {
|
|
@@ -662,7 +704,7 @@ if (typeof window !== "undefined") {
|
|
|
662
704
|
}
|
|
663
705
|
|
|
664
706
|
// iconpkg/flag/src-index.ts
|
|
665
|
-
var lookup = "
|
|
707
|
+
var lookup = "AAAC54kZAh4YbRoHqiUfWDdCWVOkRCUUNkUmRFRmODdjNDaFFUcUpGWVZ0VHFlZWNXOFSHRINWRllJSxRkJzJzhXYnZWRRYEWG8D2AYJAhmPCgoTHQN8BgUBDQMFAhQbEP8CBXIFZAcDNgQOHgffAwsMEe8vEjMqmwHoAX0B7AMDfEUGkgFGEwY3LzjeAgIPkgFRBgECvwEqBAGDBcwBj0oPEgEFApoDGQQhBAoKAQEThwISBSYFPQICWQIev5LUQn4k+tscKtKmjRLxoPIpJcTgWpj3LFuXRuJL0XXR5glpWKAdz/E011z9O2/CS3De9A8PBx/1K95M9ZpjTtzLVb9VS6nD9scd5wy4lb/djwBpDf4w/frqRd+B0QTD8v8oU4kQAyI63IZ8brbc+b3VcprgVkijpbgJGJH/ubYEdO3ao8hGK3R/q3dWVHpOLmH6tByho3Dz4WKi73NNWez4wtDKRiteFiwrTxso7pKg+tOEscuXhzy+OiLyI9hPP6IevQN8b8tTw7H70rBJzDbEZDX5N5goGFx2OBLd6y0MMSCp5tVHtpzuWvCzHJc40SP0vjHQYDXapZEpygYrd2Vi1w3wlrzhjiTPf9gIHi4ZwNjmE8lWiSHnjNfE3REc3NGLXRaS7rMFPfwgD62hfX0VTdARkAxCuqwyl42u6AQjQf+YNCRQ0/Nf+gahUHXvwRGZn88Qo8yRlfiaM9aM5VaKdjflgDtxpkWFkyNrRPkXJ3vUdL0JbYynHZrqFE2kEDWSISgbRfHE1VmFGf/07YCUVkXyJhf+gEH1bPe+7IkzgQLg2zz1XIlCAHEPFCDcMUTZjeWF0QgTyHMiQ78GWolgKwV2dod7Je3l6BcBIy3MGya44PCAG2n/zRhCcyn7rMYFb3Sig03yuAwZSpRNb0uQ3wcSlh/xUHip0HfWXZmkfpFZ4N51vvV3zjbyCzz6ODxh6GQtuF5BOjeLwuNOQSgIIIAIEIIACBQAAAgAAAAAAwAAAAtmbGFnLTAxLnN2ZwAAAAtmbGFnLTAyLnN2ZwAAAAtmbGFnLTAzLnN2Z/////8AAAACAAAAiFQFgCUQmVFmpVCWlBASKBiZaVAqaBSZJZWCaWQqAIUQBhkWCkpQYElAQZRBQqUhRogGFVCCViREkqmEQEiBRABRYaggKUIqIBJkZFUAlaggBBQkhUhGZGUiEhkZRaSFBhUaJkCViYVQUAVQEJFYYSGImaAECiYYkWhhhUBEimqGVRmVVFBkJAAAAAAA";
|
|
666
708
|
var chunks = {
|
|
667
709
|
"flag-01.svg": new URL("./flag-01.svg", import.meta.url).href,
|
|
668
710
|
"flag-02.svg": new URL("./flag-02.svg", import.meta.url).href,
|