iran-license-plate
Version:
A general react component for Iran license plate.
599 lines (585 loc) • 20.7 kB
JavaScript
// src/IranLicensePlate/components/IranSvg.tsx
import { jsx, jsxs } from "react/jsx-runtime";
var IranSvg = (props) => {
return /* @__PURE__ */ jsx(
"svg",
{
...props,
xmlns: "http://www.w3.org/2000/svg",
fill: "currentColor",
width: "16.167",
height: "3.664",
viewBox: "0 0 16.167 3.664",
children: /* @__PURE__ */ jsxs("g", { id: "Group_12203", "data-name": "Group 12203", transform: "translate(0 0)", children: [
/* @__PURE__ */ jsx(
"path",
{
id: "Path_1648",
"data-name": "Path 1648",
d: "M-3223.412-2468.545h-.955v-3.664h.955Z",
transform: "translate(3239.58 2472.21)"
}
),
/* @__PURE__ */ jsx(
"path",
{
id: "Path_1650",
"data-name": "Path 1650",
d: "M-3223.412-2468.545h-.955v-3.664h.955Z",
transform: "translate(3231.002 2472.21)"
}
),
/* @__PURE__ */ jsx(
"path",
{
id: "Path_1650-2",
"data-name": "Path 1650",
d: "M-3223.412-2471.392h-.955v-.817h.955Z",
transform: "translate(3226.851 2473.437)"
}
),
/* @__PURE__ */ jsx(
"path",
{
id: "Path_1650-3",
"data-name": "Path 1650",
d: "M-3223.412-2471.392h-.955v-.817h.955Z",
transform: "translate(3237.623 2475.054)"
}
),
/* @__PURE__ */ jsx(
"path",
{
id: "Path_1650-4",
"data-name": "Path 1650",
d: "M-3223.412-2471.392h-.955v-.817h.955Z",
transform: "translate(3235.713 2475.057)"
}
),
/* @__PURE__ */ jsx(
"path",
{
id: "Path_1649",
"data-name": "Path 1649",
d: "M-3230.345-2468.2h-.955v-2.185h4.664v-.522h.955v1.477h-4.664Z",
transform: "translate(3239.892 2471.857)"
}
),
/* @__PURE__ */ jsx(
"path",
{
id: "Path_1651",
"data-name": "Path 1651",
d: "M-3232.92-2467.552h-5.924v-2.435h.955v1.48h4.014v-1.48h.955Z",
transform: "translate(3238.844 2471.213)"
}
)
] })
}
);
};
// src/IranLicensePlate/assets/disable.svg
var disable_default = "./disable-WI532OT3.svg";
// src/IranLicensePlate/index.tsx
import IranFlag from "./assets/Flag.png";
// src/IranLicensePlate/helper.tsx
var governmental = () => {
return {
type: "governmental",
letter: "\u0627\u0644\u0641",
bg: "#ee161f",
text: "#ffffff"
};
};
var personal = (farsiLetter) => {
return {
type: "personal",
letter: farsiLetter,
bg: "#ffffff",
text: "#000000"
};
};
var handicapped = () => {
return {
type: "handicapped",
letter: "\u0698",
bg: "#ffffff",
text: "#000000"
};
};
var temporary = () => {
return {
type: "temporary",
letter: "\u06AF",
bg: "#ffffff",
text: "#000000"
};
};
var taxi = () => {
return {
type: "taxi",
letter: "\u062A",
bg: "#ffca0b",
text: "#000000"
};
};
var publicPlaque = () => {
return {
type: "public",
letter: "\u0639",
bg: "#ffca0b",
text: "#000000"
};
};
var agriculture = () => {
return {
type: "agriculture",
letter: "\u06A9",
bg: "#ffca0b",
text: "#000000"
};
};
var police = () => {
return {
type: "police",
letter: "\u067E",
bg: "#005224",
text: "#ffffff"
};
};
var sepah = () => {
return {
type: "sepah",
letter: "\u062B",
bg: "#005224",
text: "#ffffff"
};
};
var military = () => {
return {
type: "military",
letter: "\u0634",
bg: "#cfa260",
text: "#000000"
};
};
var headquarter = () => {
return {
type: "headquarter",
letter: "\u0641",
bg: "#0079c1",
text: "#ffffff"
};
};
var ministry = () => {
return {
type: "ministry",
letter: "\u0632",
bg: "#0079c1",
text: "#ffffff"
};
};
var diplomatic = () => {
return {
type: "diplomatic",
letter: "D",
bg: "#00a2e8",
text: "#000000"
};
};
var service = () => {
return {
type: "service",
letter: "S",
bg: "#00a2e8",
text: "#000000"
};
};
function getPlaqueInfo(letter) {
const AvailibleLetters = {
f: () => governmental(),
//الف
b: () => personal("\u0628"),
// ب
j: () => personal("\u062C"),
// ج
d: () => personal("\u062F"),
// د
s: () => personal("\u0633"),
// س
c: () => personal("\u0635"),
// ص
t: () => personal("\u0637"),
// ط
q: () => personal("\u0642"),
// ق
l: () => personal("\u0644"),
// ل
m: () => personal("\u0645"),
// م
n: () => personal("\u0646"),
// ن
v: () => personal("\u0648"),
// و
h: () => personal("\u0647\u0640"),
// ه
y: () => personal("\u06CC"),
// ی
//
H: () => handicapped(),
// ژ
//
T: () => taxi(),
// ت
A: () => publicPlaque(),
// ع
//
P: () => police(),
// پ
C: () => sepah(),
// ث
M: () => military(),
// ش
//
Z: () => ministry(),
// ز
F: () => headquarter(),
// ف
//
K: () => agriculture(),
// ک
G: () => temporary(),
// گ
//
D: () => diplomatic(),
// D
S: () => service()
// S
};
return AvailibleLetters[letter || "b"]();
}
// src/IranLicensePlate/assets/images/anzali.svg
var anzali_default = "./anzali-PD35AKT5.svg";
// src/IranLicensePlate/assets/images/maku.svg
var maku_default = "./maku-DP26DVJD.svg";
// src/IranLicensePlate/assets/images/aras.svg
var aras_default = "./aras-GJURVGKA.svg";
// src/IranLicensePlate/assets/images/arvand.svg
var arvand_default = "./arvand-XGGYO3IJ.svg";
// src/IranLicensePlate/assets/images/chfz.svg
var chfz_default = "./chfz-ZYI6NQ62.svg";
// src/IranLicensePlate/assets/images/kish.svg
var kish_default = "./kish-SJ7A4NW7.svg";
// src/IranLicensePlate/assets/images/qeshm.svg
var qeshm_default = "./qeshm-IQLSDVYS.svg";
// src/IranLicensePlate/components/images.tsx
import { jsx as jsx2 } from "react/jsx-runtime";
var AnzaliSVG = (props) => {
return /* @__PURE__ */ jsx2("img", { src: anzali_default, alt: "", ...props });
};
var MakuSVG = (props) => {
return /* @__PURE__ */ jsx2("img", { src: maku_default, alt: "", ...props });
};
var ArasSVG = (props) => {
return /* @__PURE__ */ jsx2("img", { src: aras_default, alt: "", ...props });
};
var ArvandSVG = (props) => {
return /* @__PURE__ */ jsx2("img", { src: arvand_default, alt: "", ...props });
};
var CHfzSVG = (props) => {
return /* @__PURE__ */ jsx2("img", { src: chfz_default, alt: "", ...props });
};
var KishSVG = (props) => {
return /* @__PURE__ */ jsx2("img", { src: kish_default, alt: "", ...props });
};
var QeshmSVG = (props) => {
return /* @__PURE__ */ jsx2("img", { src: qeshm_default, alt: "", ...props });
};
// src/IranLicensePlate/components/FreeImage.tsx
import { Fragment, jsx as jsx3 } from "react/jsx-runtime";
var FreeImage = ({ region }) => {
switch (region) {
case "ANZALI":
return /* @__PURE__ */ jsx3(AnzaliSVG, { width: "100%", height: "100%" });
case "ARAS":
return /* @__PURE__ */ jsx3(ArasSVG, { width: "100%", height: "100%" });
case "ARVAND":
return /* @__PURE__ */ jsx3(ArvandSVG, { width: "100%", height: "100%" });
case "CHFZ":
return /* @__PURE__ */ jsx3(CHfzSVG, { width: "70%", height: "70%" });
case "KISH":
return /* @__PURE__ */ jsx3(KishSVG, { width: "100%", height: "100%" });
case "MAKU":
return /* @__PURE__ */ jsx3(MakuSVG, { width: "100%", height: "100%" });
case "QESHM":
return /* @__PURE__ */ jsx3(QeshmSVG, { width: "100%", height: "100%" });
default:
return /* @__PURE__ */ jsx3(Fragment, {});
}
};
var FreeImage_default = FreeImage;
// src/IranLicensePlate/components/Spinner.tsx
import { jsx as jsx4 } from "react/jsx-runtime";
var SpinnerSvg = (props) => {
return /* @__PURE__ */ jsx4(
"svg",
{
xmlns: "http://www.w3.org/2000/svg",
width: "20px",
height: "20px",
...props,
viewBox: "0 0 100 100",
preserveAspectRatio: "xMidYMid",
children: /* @__PURE__ */ jsx4(
"circle",
{
cx: "50",
cy: "50",
fill: "none",
stroke: "currentColor",
r: "35",
strokeDasharray: "164.93361431346415 56.97787143782138",
children: /* @__PURE__ */ jsx4(
"animateTransform",
{
attributeName: "transform",
type: "rotate",
repeatCount: "indefinite",
dur: "1s",
values: "0 50 50;360 50 50",
keyTimes: "0;1"
}
)
}
)
}
);
};
// src/IranLicensePlate/index.tsx
import { Fragment as Fragment2, jsx as jsx5, jsxs as jsxs2 } from "react/jsx-runtime";
var IranLicensePlate = ({
serial,
className,
style,
isLoading,
isUnknown
}) => {
const iranRegularRGX = /(?<region>\w{2})(?<CityNumber>\d{2})-(?<Section2>\d{3})(?<Letter>\w)(?<Section4>\d{2})(-(?<Expire>\d{4}))?/;
const iranFreeRGX = /(?<region>\w*)(?<CityNumber>\d{2})-(?<Section2>\d{5})/;
if (!serial || isUnknown || isLoading) {
return /* @__PURE__ */ jsx5(Fragment2, { children: /* @__PURE__ */ jsxs2(
"div",
{
dir: "rtl",
className: (isLoading ? " ip-animate-pulse ip-duration-100" : "") + " ip-grid ip-min-w-[175px] ip-bg-red-600 ip-text-white ip-border-black ip-border-2 ip-rounded-lg ip-relative ip-overflow-hidden ip-grid-cols-12 ip-w-full ip-aspect-[18/4] ip-text-[1em] " + className,
style: {
fontFamily: "IranSansNumber",
backgroundColor: "#ffffff",
color: "#000000",
minWidth: "175px",
...style
},
children: [
/* @__PURE__ */ jsxs2("div", { className: "ip-col-span-11 ip-flex ip-min-h-0", children: [
/* @__PURE__ */ jsxs2("div", { className: "ip-aspect-square ip-border-black ip-border-l-2 ip-h-full ip-grid ip-text-[1.2em]", children: [
/* @__PURE__ */ jsx5(IranSvg, { className: "ip-w-full ip-h-full ip-aspect-[0.5/1] ip-px-2 ip-pt-0.5 " }),
/* @__PURE__ */ jsx5("div", { className: "ip-grid ip-aspect-[1.5/1] ip-h-fit ip-px-1", children: /* @__PURE__ */ jsx5("p", { className: "ip-text-[1.2em] ip-grid ip-items-center ip-leading-none ip-font-semibold ip-text-center", children: "--" }) })
] }),
/* @__PURE__ */ jsxs2("div", { className: " ip-grow ip-text-[2.2em] ip-font-semibold ip-flex ip-items-center ip-justify-around", children: [
/* @__PURE__ */ jsx5("p", { children: " --- " }),
/* @__PURE__ */ jsx5("div", { className: "ip-flex ip-flex-col ip-h-full ip-leading-none ip-justify-center", children: /* @__PURE__ */ jsx5("p", { className: "ip-leading-[0.6em]", children: isLoading ? /* @__PURE__ */ jsx5(SpinnerSvg, { width: "1.2em", height: "1.2em" }) : "\u061F" }) }),
/* @__PURE__ */ jsx5("p", { children: " -- " })
] })
] }),
/* @__PURE__ */ jsxs2("div", { className: "ip-col-span-1 ip-p-0.5 ip-bg-[#003399] ip-flex ip-flex-col ip-text-[1em] ", children: [
/* @__PURE__ */ jsx5(
"img",
{
src: IranFlag,
alt: "Flag",
className: "p-[0.1rem] pt-[0.2rem] "
}
),
/* @__PURE__ */ jsxs2(
"div",
{
dir: "ltr",
className: "ip-w-full ip-flex ip-flex-col ip-text-[0.43em] ip-items-start ip-mt-auto ip-text-white",
children: [
/* @__PURE__ */ jsx5("p", { className: "", children: "I.R." }),
/* @__PURE__ */ jsx5("p", { className: "", children: "IRAN" })
]
}
)
] })
]
}
) });
}
if (serial.match(iranRegularRGX)) {
const matches = iranRegularRGX.exec(serial);
const info = getPlaqueInfo(matches?.groups?.Letter);
return /* @__PURE__ */ jsx5(Fragment2, { children: /* @__PURE__ */ jsxs2(
"div",
{
dir: "rtl",
className: "ip-grid ip-min-w-[175px] ip-bg-red-600 ip-text-white ip-border-black ip-border-2 ip-rounded-lg ip-relative ip-overflow-hidden ip-grid-cols-12 ip-w-full ip-aspect-[18/4] ip-text-[1em] " + className,
style: {
fontFamily: "IranSansNumber",
backgroundColor: info.bg,
color: info.text,
minWidth: "175px",
...style
},
children: [
/* @__PURE__ */ jsxs2("div", { className: "ip-col-span-11 ip-flex ip-min-h-0", children: [
/* @__PURE__ */ jsxs2("div", { className: "ip-aspect-square ip-border-black ip-border-l-2 ip-h-full ip-grid ip-text-[1.2em]", children: [
/* @__PURE__ */ jsx5(IranSvg, { className: "ip-w-full ip-h-full ip-aspect-[0.5/1] ip-px-2 ip-pt-0.5 " }),
/* @__PURE__ */ jsxs2("div", { className: "ip-grid ip-aspect-[1.5/1] ip-h-fit ip-px-1", children: [
/* @__PURE__ */ jsx5("p", { className: "ip-text-[1.2em] ip-grid ip-items-center ip-leading-none ip-font-semibold ip-text-center", children: matches?.groups?.CityNumber }),
matches?.groups?.Expire ? /* @__PURE__ */ jsx5(
"p",
{
style: { borderColor: info.text },
className: "ip-text-[0.8em] ip-leading-none ip-border-t-2 ip-pt-1 ip-font-semibold ip-text-center",
children: [
matches?.groups?.Expire.slice(0, 2),
matches?.groups?.Expire.slice(2)
].join("/")
}
) : /* @__PURE__ */ jsx5(Fragment2, {})
] })
] }),
/* @__PURE__ */ jsxs2("div", { className: " ip-grow ip-text-[2.2em] ip-font-semibold ip-flex ip-items-center ip-justify-around", children: [
/* @__PURE__ */ jsxs2("p", { children: [
" ",
matches?.groups?.Section2
] }),
/* @__PURE__ */ jsxs2("div", { className: "ip-flex ip-flex-col ip-h-full ip-leading-none ip-justify-center", children: [
/* @__PURE__ */ jsx5(
"p",
{
className: "ip-w-full ip-font-extralight ip-text-[0.4em]",
style: {
fontFamily: "sans-serif"
},
children: info.type === "taxi" ? "TAXI" : ""
}
),
info.type === "handicapped" ? /* @__PURE__ */ jsx5("img", { src: disable_default, className: "ip-w-[1em] ip-h-[1em] " }) : /* @__PURE__ */ jsx5("p", { className: "ip-leading-[0.6em]", children: info.letter })
] }),
/* @__PURE__ */ jsxs2("p", { children: [
" ",
matches?.groups?.Section4
] })
] })
] }),
/* @__PURE__ */ jsxs2("div", { className: "ip-col-span-1 ip-p-0.5 ip-bg-[#003399] ip-flex ip-flex-col ip-text-[1em] ", children: [
/* @__PURE__ */ jsx5(
"img",
{
src: IranFlag,
alt: "Flag",
className: "p-[0.1rem] pt-[0.2rem] "
}
),
/* @__PURE__ */ jsxs2(
"div",
{
dir: "ltr",
className: "ip-w-full ip-flex ip-flex-col ip-text-[0.43em] ip-items-start ip-mt-auto ip-text-white",
children: [
/* @__PURE__ */ jsx5("p", { className: "", children: "I.R." }),
/* @__PURE__ */ jsx5("p", { className: "", children: "IRAN" })
]
}
)
] })
]
}
) });
}
if (serial.match(iranFreeRGX)) {
const matches = iranFreeRGX.exec(serial);
const isPublic = matches?.groups?.CityNumber ? +matches?.groups?.CityNumber % 2 !== 0 : true;
return /* @__PURE__ */ jsx5(Fragment2, { children: /* @__PURE__ */ jsxs2(
"div",
{
dir: "rtl",
className: "ip-grid ip-min-w-[175px] ip-border-black ip-border-2 ip-rounded-lg ip-relative ip-overflow-hidden ip-grid-cols-12 ip-w-full ip-text-[1em] " + className,
style: {
backgroundColor: isPublic ? "#ffffff" : "#ffca0b",
color: "#000000",
minWidth: "175px",
...style
},
children: [
/* @__PURE__ */ jsxs2("div", { className: "ip-grid ip-aspect-[10/5] ip-w-full ip-col-span-9", children: [
/* @__PURE__ */ jsxs2(
"div",
{
className: " ip-grid ip-grid-cols-12 ip-aspect-[10/4] ip-tracking-widest ",
style: {
fontFamily: "IranSansNumber"
},
children: [
/* @__PURE__ */ jsx5("div", { className: "ip-col-span-5 ip-border-black ip-border-l-2 ip-h-full ip-grid ip-text-[1.2em]", children: /* @__PURE__ */ jsx5("div", { className: "ip-grid ip-h-full ip-text-[1.7em]", children: /* @__PURE__ */ jsx5("p", { className: "ip-text-[1.2em] ip-grid ip-items-center ip-leading-none ip-font-semibold ip-text-center", children: matches?.groups?.CityNumber }) }) }),
/* @__PURE__ */ jsx5("div", { className: "ip-col-span-7 ip-grow ip-text-[2.5em] ip-font-semibold ip-flex ip-items-center ip-justify-around", children: /* @__PURE__ */ jsxs2("p", { children: [
" ",
matches?.groups?.Section2
] }) })
]
}
),
/* @__PURE__ */ jsxs2("div", { className: " ip-grid ip-grid-cols-12 ip-aspect-[11/2] ip-border-black ip-border-t-2", children: [
/* @__PURE__ */ jsx5("div", { className: "ip-col-span-5 ip-border-black ip-border-l-2 ip-h-full ip-grid ip-text-[1.2em]", children: /* @__PURE__ */ jsx5("div", { className: "ip-grid ip-h-full ip-text-[1.4em]", children: /* @__PURE__ */ jsx5("p", { className: "ip-text-[1.2em] ip-grid ip-items-center ip-leading-none ip-font-semibold ip-text-center", children: matches?.groups?.CityNumber }) }) }),
/* @__PURE__ */ jsx5("div", { className: "ip-col-span-7 ip-grow ip-text-[2.2em] ip-font-semibold ip-flex ip-items-center ip-justify-around", children: /* @__PURE__ */ jsxs2("p", { children: [
" ",
matches?.groups?.Section2
] }) })
] })
] }),
/* @__PURE__ */ jsxs2("div", { className: "ip-col-span-3 ip-p-0.5 ip-bg-[#003399] ip-flex ip-flex-col ip-text-[1em] ", children: [
/* @__PURE__ */ jsxs2("div", { className: "ip-flex ip-w-full ip-gap-2", children: [
/* @__PURE__ */ jsxs2(
"div",
{
dir: "ltr",
className: "ip-w-full ip-flex ip-flex-col ip-text-[0.43em] ip-items-start ip-mt-auto ip-text-white",
children: [
/* @__PURE__ */ jsx5("p", { className: "", children: "I.R." }),
/* @__PURE__ */ jsx5("p", { className: "", children: "IRAN" })
]
}
),
/* @__PURE__ */ jsx5(
"img",
{
src: IranFlag,
alt: "Flag",
className: "p-[0.1rem] pt-[0.2rem] ip-flex ip-w-1/2"
}
)
] }),
/* @__PURE__ */ jsx5("div", { className: "ip-w-full ip-h-full ip-flex ip-items-center ip-justify-center ip-p-4", children: /* @__PURE__ */ jsx5(FreeImage_default, { region: matches?.groups?.region }) }),
/* @__PURE__ */ jsx5(
"div",
{
dir: "ltr",
className: "ip-w-full ip-text-center ip-text-[1em] ip-items-center ip-mt-auto ip-text-white",
children: /* @__PURE__ */ jsx5("p", { className: "ip-text-center", children: matches?.groups?.region === "CHFZ" ? "CH.F.Z" : matches?.groups?.region })
}
)
] })
]
}
) });
}
return /* @__PURE__ */ jsx5(Fragment2, { children: "Wrong Serial?" });
};
var IranLicensePlate_default = IranLicensePlate;
export {
IranLicensePlate,
IranLicensePlate_default as default
};
//# sourceMappingURL=index.mjs.map