utils.js 897 B

123456789101112131415161718192021222324252627
  1. // src/jsx/utils.ts
  2. var normalizeElementKeyMap = /* @__PURE__ */ new Map([
  3. ["className", "class"],
  4. ["htmlFor", "for"],
  5. ["crossOrigin", "crossorigin"],
  6. ["httpEquiv", "http-equiv"],
  7. ["itemProp", "itemprop"],
  8. ["fetchPriority", "fetchpriority"],
  9. ["noModule", "nomodule"],
  10. ["formAction", "formaction"]
  11. ]);
  12. var normalizeIntrinsicElementKey = (key) => normalizeElementKeyMap.get(key) || key;
  13. var styleObjectForEach = (style, fn) => {
  14. for (const [k, v] of Object.entries(style)) {
  15. const key = k[0] === "-" || !/[A-Z]/.test(k) ? k : k.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`);
  16. fn(
  17. key,
  18. v == null ? null : typeof v === "number" ? !key.match(
  19. /^(?:a|border-im|column(?:-c|s)|flex(?:$|-[^b])|grid-(?:ar|[^a])|font-w|li|or|sca|st|ta|wido|z)|ty$/
  20. ) ? `${v}px` : `${v}` : v
  21. );
  22. }
  23. };
  24. export {
  25. normalizeIntrinsicElementKey,
  26. styleObjectForEach
  27. };