noofpi 0.0.0-stage → 1.0.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.
Files changed (41) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +47 -2
  3. package/bin/noofpi.mjs +2 -0
  4. package/client.d.ts +79 -0
  5. package/dist/build-77DKK3YK.js +48 -0
  6. package/dist/chunk-2XCZWFIQ.js +253 -0
  7. package/dist/chunk-6OWKWAIW.js +68 -0
  8. package/dist/chunk-ELXCFUA4.js +97 -0
  9. package/dist/chunk-EZPJF4D4.js +314 -0
  10. package/dist/chunk-FIJJ3EGL.js +353 -0
  11. package/dist/chunk-G35DW4NA.js +129 -0
  12. package/dist/chunk-KAV3UNMO.js +996 -0
  13. package/dist/chunk-KGZP2RCF.js +51 -0
  14. package/dist/chunk-MTWSTW7V.js +44 -0
  15. package/dist/chunk-MTXQR32N.js +8 -0
  16. package/dist/chunk-NALDZ3PS.js +90 -0
  17. package/dist/chunk-WX2V6EYH.js +102 -0
  18. package/dist/chunk-WXEYXDO6.js +280 -0
  19. package/dist/chunk-X34Y6ESE.js +810 -0
  20. package/dist/chunk-Y3NBZ6DW.js +55 -0
  21. package/dist/chunk-YZAZ7IWK.js +27 -0
  22. package/dist/cli.js +93 -0
  23. package/dist/dev-ZJ732ORK.js +122 -0
  24. package/dist/devtools-KTDSD5PR.js +564 -0
  25. package/dist/images-BNwTAi50.d.ts +36 -0
  26. package/dist/index.d.ts +115 -0
  27. package/dist/index.js +15 -0
  28. package/dist/route-rules-COilNsVT.d.ts +127 -0
  29. package/dist/runtime/default-app.js +15 -0
  30. package/dist/runtime/entry-client.js +70 -0
  31. package/dist/runtime/entry-server.js +107 -0
  32. package/dist/runtime/index.d.ts +523 -0
  33. package/dist/runtime/index.js +224 -0
  34. package/dist/runtime/routes.js +14 -0
  35. package/dist/server/bun.js +47 -0
  36. package/dist/server/index.d.ts +109 -0
  37. package/dist/server/index.js +48 -0
  38. package/dist/server/node.js +15 -0
  39. package/dist/start-I2LQWV7B.js +61 -0
  40. package/dist/validation-ClXd_DAW.d.ts +159 -0
  41. package/package.json +101 -4
@@ -0,0 +1,129 @@
1
+ // src/head.ts
2
+ var DEFAULT_TITLE = "noofpi";
3
+ var HEAD_TAG_ATTR = "data-noofpi-head";
4
+ var HEAD_ATTRS_ATTR = "data-noofpi-attrs";
5
+ var BASE_HTML_ATTRS = { lang: "en" };
6
+ var TITLE_SEPARATORS = /^[\s|\-–—·:•]+|[\s|\-–—·:•]+$/g;
7
+ var SAFE_ATTR_NAME = /^[^\s"'<>/=\u0000-\u001f\u007f]+$/;
8
+ var isSafeAttrName = (name) => SAFE_ATTR_NAME.test(name) && !/^on/i.test(name);
9
+ function normalizeAttrs(attrs) {
10
+ const result = {};
11
+ for (const [name, value] of Object.entries(attrs ?? {})) {
12
+ if (value === void 0 || value === null || value === false) continue;
13
+ if (!isSafeAttrName(name)) continue;
14
+ result[name] = value === true ? "" : String(value);
15
+ }
16
+ return result;
17
+ }
18
+ function tagKey(kind, tag) {
19
+ if (kind === "meta") {
20
+ if ("charset" in tag) return "charset";
21
+ for (const name of ["name", "property", "http-equiv", "itemprop"])
22
+ if (name in tag) return `${name}:${tag[name]}`;
23
+ return void 0;
24
+ }
25
+ if (tag.rel === "canonical") return "canonical";
26
+ return tag.rel && tag.href ? `${tag.rel}|${tag.href}|${tag.hreflang ?? ""}` : void 0;
27
+ }
28
+ function mergeTags(kind, lists) {
29
+ const tags = /* @__PURE__ */ new Map();
30
+ let anonymous = 0;
31
+ for (const list of lists)
32
+ for (const raw of list ?? []) {
33
+ const tag = normalizeAttrs(raw);
34
+ tags.set(tagKey(kind, tag) ?? `#${anonymous++}`, tag);
35
+ }
36
+ return [...tags.values()];
37
+ }
38
+ function resolveTitle(template, title) {
39
+ if (title)
40
+ return template?.includes("%s") ? template.split("%s").join(title) : title;
41
+ if (!template) return DEFAULT_TITLE;
42
+ return template.split("%s").join("").replace(TITLE_SEPARATORS, "") || DEFAULT_TITLE;
43
+ }
44
+ function resolveHead(defaults, entries = []) {
45
+ const all = [defaults ?? {}, ...entries];
46
+ const pageTitle = entries.map((entry) => entry.title).filter(Boolean).pop();
47
+ return {
48
+ title: resolveTitle(defaults?.title, pageTitle),
49
+ meta: mergeTags(
50
+ "meta",
51
+ all.map((input) => input.meta)
52
+ ),
53
+ link: mergeTags(
54
+ "link",
55
+ all.map((input) => input.link)
56
+ ),
57
+ htmlAttrs: Object.assign(
58
+ { ...BASE_HTML_ATTRS },
59
+ ...all.map((input) => normalizeAttrs(input.htmlAttrs))
60
+ ),
61
+ bodyAttrs: Object.assign(
62
+ {},
63
+ ...all.map((input) => normalizeAttrs(input.bodyAttrs))
64
+ )
65
+ };
66
+ }
67
+ var escapeText = (value) => value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
68
+ var escapeAttr = (value) => escapeText(value).replace(/"/g, "&quot;");
69
+ var renderAttrs = (attrs) => Object.entries(attrs).map(([name, value]) => `${name}="${escapeAttr(value)}"`).join(" ");
70
+ var ATTRIBUTE = /([^\s"'<>/=]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'>]+)))?/g;
71
+ function mergeTagAttrs(html, tag, attrs) {
72
+ return html.replace(
73
+ new RegExp(`<${tag}\\b([^>]*)>`, "i"),
74
+ (whole, rest) => {
75
+ const existing = /* @__PURE__ */ new Map();
76
+ for (const match of rest.matchAll(ATTRIBUTE))
77
+ existing.set(
78
+ match[1].toLowerCase(),
79
+ match[2] ?? match[3] ?? match[4] ?? ""
80
+ );
81
+ existing.delete(HEAD_ATTRS_ATTR);
82
+ const changed = Object.entries(attrs).filter(
83
+ ([name, value]) => existing.get(name.toLowerCase()) !== value
84
+ );
85
+ if (!changed.length) return whole;
86
+ const kept = [...existing].filter(
87
+ ([name]) => !changed.some(([changedName]) => changedName.toLowerCase() === name)
88
+ );
89
+ const merged = {
90
+ ...Object.fromEntries(kept),
91
+ ...Object.fromEntries(changed),
92
+ [HEAD_ATTRS_ATTR]: changed.map(([name]) => name).join(" ")
93
+ };
94
+ return `<${tag} ${renderAttrs(merged)}>`;
95
+ }
96
+ );
97
+ }
98
+ function applyHead(html, head) {
99
+ let result = html;
100
+ const title = `<title>${escapeText(head.title)}</title>`;
101
+ if (/<title>[\s\S]*?<\/title>/i.test(result))
102
+ result = result.replace(/<title>[\s\S]*?<\/title>/i, () => title);
103
+ else result = result.replace("</head>", () => ` ${title}
104
+ </head>`);
105
+ if (head.meta.some((tag) => "charset" in tag))
106
+ result = result.replace(/\s*<meta\s+charset=[^>]*>/i, "");
107
+ if (head.meta.some((tag) => tag.name === "viewport"))
108
+ result = result.replace(/\s*<meta\s+name="viewport"[^>]*>/i, "");
109
+ const tags = [
110
+ ...head.meta.map((attrs) => ["meta", attrs]),
111
+ ...head.link.map((attrs) => ["link", attrs])
112
+ ].map(
113
+ ([name, attrs]) => ` <${name} ${renderAttrs({ ...attrs, [HEAD_TAG_ATTR]: "" })} />
114
+ `
115
+ );
116
+ if (tags.length)
117
+ result = result.replace("</head>", () => tags.join("") + " </head>");
118
+ result = mergeTagAttrs(result, "html", head.htmlAttrs);
119
+ if (Object.keys(head.bodyAttrs).length)
120
+ result = mergeTagAttrs(result, "body", head.bodyAttrs);
121
+ return result;
122
+ }
123
+
124
+ export {
125
+ HEAD_TAG_ATTR,
126
+ HEAD_ATTRS_ATTR,
127
+ resolveHead,
128
+ applyHead
129
+ };