@palmyit/elements 0.0.0-stage → 0.1.7

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 (60) hide show
  1. package/README.md +12 -2
  2. package/dist/definitions.d.ts +51 -0
  3. package/dist/definitions.js +1737 -0
  4. package/dist/manifest.json +7 -0
  5. package/dist/plmt-elements.css +2 -0
  6. package/dist/plmt-elements.js +0 -0
  7. package/dist/registry.d.ts +9 -0
  8. package/dist/render/renderHtml.d.ts +5 -0
  9. package/dist/render/styleToVars.d.ts +2 -0
  10. package/dist/render/tags.d.ts +42 -0
  11. package/dist/render/toDom.d.ts +3 -0
  12. package/dist/render/types.d.ts +14 -0
  13. package/dist/schema/Fields/BackgroundField/backgroundValue.d.ts +15 -0
  14. package/dist/schema/Fields/ColorField/color-value.d.ts +6 -0
  15. package/dist/schema/Fields/ColorField/index.d.ts +1 -0
  16. package/dist/schema/Fields/FontStyleField.d.ts +2 -0
  17. package/dist/schema/Fields/IconPicker/iconCatalog.d.ts +3 -0
  18. package/dist/schema/PButton/pButton.definition.d.ts +38 -0
  19. package/dist/schema/PCheckbox/pCheckbox.definition.d.ts +10 -0
  20. package/dist/schema/PContainer/pContainer.definition.d.ts +39 -0
  21. package/dist/schema/PDivider/pDivider.definition.d.ts +10 -0
  22. package/dist/schema/PIcon/pIcon.definition.d.ts +18 -0
  23. package/dist/schema/PImage/pImage.definition.d.ts +33 -0
  24. package/dist/schema/PList/pList.definition.d.ts +11 -0
  25. package/dist/schema/PPage/pPage.definition.d.ts +22 -0
  26. package/dist/schema/PRadio/pRadio.definition.d.ts +13 -0
  27. package/dist/schema/PRichText/pRichText.definition.d.ts +8 -0
  28. package/dist/schema/PRichText/richTextMarks.d.ts +4 -0
  29. package/dist/schema/PRichText/richTextOptions.d.ts +2 -0
  30. package/dist/schema/PSection/pSection.definition.d.ts +39 -0
  31. package/dist/schema/PSelect/pSelect.definition.d.ts +13 -0
  32. package/dist/schema/PTable/pTable.definition.d.ts +20 -0
  33. package/dist/schema/PText/pText.definition.d.ts +46 -0
  34. package/dist/schema/PTextArea/pTextArea.definition.d.ts +10 -0
  35. package/dist/schema/PTextField/pTextField.definition.d.ts +10 -0
  36. package/dist/schema/PVideo/pVideo.definition.d.ts +10 -0
  37. package/dist/schema/addressSchema.d.ts +3 -0
  38. package/dist/schema/backgroundStyleDefinitions.d.ts +15 -0
  39. package/dist/schema/device/deviceStyle.d.ts +13 -0
  40. package/dist/schema/device/devices.d.ts +21 -0
  41. package/dist/schema/deviceSettings.d.ts +13 -0
  42. package/dist/schema/deviceVisibility.d.ts +19 -0
  43. package/dist/schema/elementConfiguration.d.ts +38 -0
  44. package/dist/schema/elementRegistry.d.ts +40 -0
  45. package/dist/schema/elementStyleDefinitions.d.ts +24 -0
  46. package/dist/schema/elementTemplates.d.ts +26 -0
  47. package/dist/schema/layoutChildren.d.ts +2 -0
  48. package/dist/schema/layoutElementConfiguration.d.ts +17 -0
  49. package/dist/schema/linkSettings.d.ts +26 -0
  50. package/dist/schema/style/backgroundStyle.d.ts +5 -0
  51. package/dist/schema/style/elementStyle.d.ts +62 -0
  52. package/dist/schema/style/page-styles.d.ts +3 -0
  53. package/dist/schema/styleItems.d.ts +53 -0
  54. package/dist/schema/textItems.d.ts +10 -0
  55. package/dist/tags.json +19 -0
  56. package/dist/templates/elementSpec.d.ts +15 -0
  57. package/dist/templates/helpers.d.ts +9 -0
  58. package/dist/templates.d.ts +11 -0
  59. package/dist/templates.js +269 -0
  60. package/package.json +67 -4
@@ -0,0 +1,269 @@
1
+ // src/render/renderHtml.ts
2
+ var e = /* @__PURE__ */ new Set([
3
+ "img",
4
+ "input",
5
+ "hr",
6
+ "br",
7
+ "meta",
8
+ "link"
9
+ ]);
10
+ function t(e) {
11
+ return String(e).replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll("\"", "&quot;").replaceAll("'", "&#39;");
12
+ }
13
+ function n(e) {
14
+ return e.replaceAll(/<(script|style|iframe|object|embed)\b[^>]*>[\s\S]*?<\/\1\s*>/gi, "").replaceAll(/\s+on[a-z]+\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+)/gi, "").replaceAll(/\s+(href|src)\s*=\s*(["'])\s*javascript:[\s\S]*?\2/gi, "");
15
+ }
16
+ function r(n) {
17
+ if (typeof n == "string") return t(n);
18
+ let i = Object.entries(n.attrs).flatMap(([e, n]) => n === void 0 || n === !1 ? [] : n === !0 ? [e] : [`${e}="${t(n)}"`]), a = Object.entries(n.styleVars).flatMap(([e, t]) => t === void 0 ? [] : [`${e}:${t}`]).join(";");
19
+ a && i.push(`style="${t(a)}"`);
20
+ let o = `<${n.tag}${i.length ? ` ${i.join(" ")}` : ""}>`;
21
+ return e.has(n.tag) ? `${o.slice(0, -1)}>` : `${o}${Array.isArray(n.children) ? n.children.map(r).join("") : n.children?.html ?? ""}</${n.tag}>`;
22
+ }
23
+ // src/render/toDom.ts
24
+ function i(e) {
25
+ if (typeof e == "string") return document.createTextNode(e);
26
+ let t = document.createElement(e.tag);
27
+ for (let [n, r] of Object.entries(e.attrs)) r !== void 0 && r !== !1 && (r === !0 ? t.setAttribute(n, "") : t.setAttribute(n, String(r)));
28
+ let n = Object.entries(e.styleVars).flatMap(([e, t]) => t === void 0 ? [] : [`${e}:${t}`]).join(";");
29
+ if (n && t.setAttribute("style", n), Array.isArray(e.children)) for (let n of e.children) t.append(i(n));
30
+ else e.children?.html && (t.innerHTML = e.children.html);
31
+ return t;
32
+ }
33
+ // src/render/styleToVars.ts
34
+ var a = /^#[0-9A-Fa-f]{6}$/;
35
+ function o(e) {
36
+ if (!a.test(e.hex) || !Number.isFinite(e.opacity)) return;
37
+ if (e.opacity === 100) return e.hex.toUpperCase();
38
+ let t = Math.min(100, Math.max(0, e.opacity)) / 100;
39
+ return `rgba(${Number.parseInt(e.hex.slice(1, 3), 16)}, ${Number.parseInt(e.hex.slice(3, 5), 16)}, ${Number.parseInt(e.hex.slice(5, 7), 16)}, ${t})`;
40
+ }
41
+ var s = {
42
+ textFont: "font-family",
43
+ textColor: "color",
44
+ textSize: "font-size",
45
+ fontStyle: "font-style",
46
+ backgroundColor: "background-color",
47
+ backgroundGradient: "background-image",
48
+ borderRadiusTopLeft: "border-top-left-radius",
49
+ borderRadiusTopRight: "border-top-right-radius",
50
+ borderRadiusBottomLeft: "border-bottom-left-radius",
51
+ borderRadiusBottomRight: "border-bottom-right-radius",
52
+ gridColumns: "grid-template-columns"
53
+ }, c = (e) => e.replace(/[A-Z]/g, (e) => `-${e.toLowerCase()}`);
54
+ function l(e, t) {
55
+ return t && typeof t == "object" && "hex" in t && "opacity" in t ? o(t) : e === "backgroundGradient" && t && typeof t == "object" && "kind" in t && "value" in t ? `${String(t.kind)}-gradient(${String(t.value)})` : e === "gridColumns" && typeof t == "number" ? `repeat(${t}, minmax(0, 1fr))` : e === "textSize" && typeof t == "number" ? Number.isFinite(t) && t > 0 ? `${t}px` : void 0 : [
56
+ "string",
57
+ "number",
58
+ "boolean"
59
+ ].includes(typeof t) ? String(t) : void 0;
60
+ }
61
+ function u(e, t) {
62
+ return e ? Object.fromEntries(Object.entries(e).flatMap(([e, n]) => {
63
+ let r = l(e, n);
64
+ return r === void 0 ? [] : [[`--palmyit-${t}-${s[e] ?? c(e)}`, r]];
65
+ })) : {};
66
+ }
67
+ // src/render/tags.ts
68
+ var d = {
69
+ PPage: "plmt-page",
70
+ PSection: "plmt-section",
71
+ PContainer: "plmt-container",
72
+ PButton: "plmt-button",
73
+ PText: "plmt-text",
74
+ PRichText: "plmt-rich-text",
75
+ PImage: "plmt-image",
76
+ PVideo: "plmt-video",
77
+ PList: "plmt-list",
78
+ PIcon: "plmt-icon",
79
+ PDivider: "plmt-divider",
80
+ PTable: "plmt-table",
81
+ PTextField: "plmt-text-field",
82
+ PTextArea: "plmt-text-area",
83
+ PCheckbox: "plmt-checkbox",
84
+ PRadio: "plmt-radio",
85
+ PSelect: "plmt-select"
86
+ };
87
+ // src/templates/helpers.ts
88
+ function f(e, t = {}, n, r = {}) {
89
+ return n === void 0 ? {
90
+ tag: e,
91
+ attrs: t,
92
+ styleVars: r
93
+ } : {
94
+ tag: e,
95
+ attrs: t,
96
+ styleVars: r,
97
+ children: n
98
+ };
99
+ }
100
+ function p(e, t) {
101
+ let n = String(e.href ?? "");
102
+ if (!n) return t;
103
+ let r = String(e.target ?? "_self");
104
+ return [f("a", {
105
+ href: n,
106
+ target: r,
107
+ rel: r === "_blank" ? "noopener noreferrer" : void 0,
108
+ "aria-description": String(e.description ?? "") || void 0
109
+ }, t)];
110
+ }
111
+ function m(e) {
112
+ return e.slice(1).replaceAll(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
113
+ }
114
+ function h(e) {
115
+ return String(e.id ?? e.pageId ?? "");
116
+ }
117
+ function g(e, t) {
118
+ let n = e.style ?? {}, r = {
119
+ class: t,
120
+ "data-plmt-id": h(e)
121
+ };
122
+ return typeof n.layout == "string" && (r["data-layout"] = n.layout), typeof n.backgroundType == "string" && (r["data-background"] = n.backgroundType), r;
123
+ }
124
+ // src/templates/elementSpec.ts
125
+ var _ = /* @__PURE__ */ new Set([
126
+ "PPage",
127
+ "PSection",
128
+ "PContainer"
129
+ ]);
130
+ function v(e, t = "") {
131
+ let n = {
132
+ class: d.PIcon,
133
+ "data-name": e || void 0
134
+ };
135
+ return t.trim() ? (n.role = "img", n["aria-label"] = t) : n["aria-hidden"] = "true", f("span", n);
136
+ }
137
+ function y(e, t) {
138
+ return {
139
+ attrs: g(t, d[e]),
140
+ vars: u(t.style, m(e))
141
+ };
142
+ }
143
+ function b(e, t) {
144
+ let r = e.props, i = y(e.type, r);
145
+ if (e.type === "PVideo" && !String(r.src ?? "")) return null;
146
+ if (e.type === "PPage") return f("main", {
147
+ class: d.PPage,
148
+ "data-plmt-id": String(r.pageId),
149
+ title: String(r.title ?? ""),
150
+ "data-url": String(r.url ?? "")
151
+ }, t?.children ?? [], u({
152
+ backgroundColor: r.backgroundColor,
153
+ textColor: r.textColor,
154
+ textSize: r.textSize
155
+ }, "page"));
156
+ if (e.type === "PSection") return f("section", i.attrs, t?.children ?? [], i.vars);
157
+ if (e.type === "PContainer") return f("div", i.attrs, t?.children ?? [], i.vars);
158
+ if (e.type === "PButton") {
159
+ let e = [];
160
+ r.startIcon && e.push(v(String(r.startIcon))), e.push(String(r.name ?? "")), r.endIcon && e.push(v(String(r.endIcon)));
161
+ let t = String(r.href ?? "");
162
+ if (t) {
163
+ let n = String(r.target ?? "_self");
164
+ return f("a", {
165
+ ...i.attrs,
166
+ href: t,
167
+ target: n,
168
+ rel: n === "_blank" ? "noopener noreferrer" : void 0,
169
+ "aria-description": String(r.description ?? "") || void 0
170
+ }, e, i.vars);
171
+ }
172
+ return f("button", {
173
+ ...i.attrs,
174
+ type: "button"
175
+ }, e, i.vars);
176
+ }
177
+ if (e.type === "PText") return f("p", i.attrs, p(r, [String(r.text ?? "")]), i.vars);
178
+ if (e.type === "PRichText") return f("div", i.attrs, { html: n(String(r.text ?? "")) }, i.vars);
179
+ if (e.type === "PIcon") {
180
+ let e = String(r.label ?? ""), t = String(r.icon ?? ""), n = e.trim() ? {
181
+ role: "img",
182
+ "aria-label": e
183
+ } : { "aria-hidden": "true" }, a = p(r, []);
184
+ return f("span", {
185
+ ...i.attrs,
186
+ "data-name": t || void 0,
187
+ ...n
188
+ }, a.length ? a : void 0, i.vars);
189
+ }
190
+ if (e.type === "PImage") {
191
+ let e = f("img", {
192
+ class: String(r.href ?? "") ? void 0 : d.PImage,
193
+ src: String(r.src),
194
+ alt: String(r.alt ?? ""),
195
+ ...String(r.href ?? "") ? {} : {
196
+ "data-plmt-id": i.attrs["data-plmt-id"],
197
+ "data-background": i.attrs["data-background"]
198
+ }
199
+ }, void 0, String(r.href ?? "") ? {} : i.vars), t = String(r.href ?? "");
200
+ if (!t) return e;
201
+ let n = String(r.target ?? "_self");
202
+ return f("a", {
203
+ class: d.PImage,
204
+ "data-plmt-id": i.attrs["data-plmt-id"],
205
+ "data-background": i.attrs["data-background"],
206
+ href: t,
207
+ target: n,
208
+ rel: n === "_blank" ? "noopener noreferrer" : void 0,
209
+ "aria-description": String(r.description ?? "") || void 0
210
+ }, [f("img", {
211
+ src: String(r.src),
212
+ alt: String(r.alt ?? "")
213
+ })], i.vars);
214
+ }
215
+ if (e.type === "PVideo") return f("video", {
216
+ ...i.attrs,
217
+ src: String(r.src),
218
+ title: String(r.title ?? ""),
219
+ controls: !0
220
+ }, void 0, i.vars);
221
+ if (e.type === "PList") {
222
+ let e = r.items.map((e) => f("li", {}, [e.text]));
223
+ return f("ul", i.attrs, e, i.vars);
224
+ }
225
+ if (e.type === "PDivider") return f("hr", {
226
+ ...i.attrs,
227
+ "data-size": String(r.size ?? "4")
228
+ }, void 0, i.vars);
229
+ if (e.type === "PTable") {
230
+ let e = r.headers.map((e) => f("th", {}, [e.text])), t = r.rows.map((e) => f("tr", {}, e.cells.map((e) => f("td", {}, [e]))));
231
+ return f("div", i.attrs, [f("table", {}, [f("thead", {}, [f("tr", {}, e)]), f("tbody", {}, t)])], i.vars);
232
+ }
233
+ let a = h(r);
234
+ if (e.type === "PTextField") return f("div", i.attrs, [f("label", { for: a }, [String(r.label)]), f("input", {
235
+ id: a,
236
+ name: a,
237
+ placeholder: String(r.placeholder ?? "")
238
+ })], i.vars);
239
+ if (e.type === "PTextArea") return f("div", i.attrs, [f("label", { for: a }, [String(r.label)]), f("textarea", {
240
+ id: a,
241
+ name: a,
242
+ placeholder: String(r.placeholder ?? "")
243
+ })], i.vars);
244
+ if (e.type === "PCheckbox") return f("div", i.attrs, [f("label", {}, [f("input", {
245
+ type: "checkbox",
246
+ name: a,
247
+ checked: r.checked === !0 || void 0
248
+ }), String(r.label)])], i.vars);
249
+ if (e.type === "PRadio") {
250
+ let e = r.options.map((e) => f("label", {}, [f("input", {
251
+ type: "radio",
252
+ name: a,
253
+ value: e.text
254
+ }), e.text]));
255
+ return f("fieldset", i.attrs, [f("legend", {}, [String(r.legend)]), ...e], i.vars);
256
+ }
257
+ if (e.type === "PSelect") {
258
+ let e = r.options.map((e) => f("option", { value: e.text }, [e.text]));
259
+ return f("div", i.attrs, [f("label", { for: a }, [String(r.label)]), f("select", {
260
+ id: a,
261
+ name: a
262
+ }, e)], i.vars);
263
+ }
264
+ return f("div", i.attrs, void 0, i.vars);
265
+ }
266
+ function x(e) {
267
+ return _.has(e.type) ? b(e, { children: (e.children ?? []).map(x).filter(Boolean) }) : b(e);
268
+ }
269
+ export { m as cssPrefix, b as elementSpec, t as escapeHtml, g as hostAttrs, p as linked, h as nodeId, r as renderHtml, n as sanitizeRichTextHtml, f as spec, u as styleToCssVariables, d as tags, i as toDom, x as toElementTree };
package/package.json CHANGED
@@ -1,6 +1,69 @@
1
1
  {
2
2
  "name": "@palmyit/elements",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.7",
4
+ "description": "Palmyit element definitions, semantic HTML templates, and CSS for builder and published sites",
5
+ "private": false,
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/chimejet/palmyit-elements"
9
+ },
10
+ "license": "ISC",
11
+ "author": "Stephen <sndegwa.n@outlook.com> (https://stevndegwa.github.io/)",
12
+ "type": "module",
13
+ "files": [
14
+ "dist"
15
+ ],
16
+ "scripts": {
17
+ "build": "tsc -b && vite build && node scripts/write-manifest.mjs",
18
+ "test": "vitest run --exclude src/manifest.test.ts",
19
+ "test:watch": "vitest",
20
+ "test:manifest": "vitest run src/manifest.test.ts",
21
+ "storybook": "storybook dev -p 6007",
22
+ "build-storybook": "storybook build",
23
+ "prepublishOnly": "yarn build"
24
+ },
25
+ "exports": {
26
+ ".": "./dist/plmt-elements.js",
27
+ "./definitions": {
28
+ "types": "./dist/definitions.d.ts",
29
+ "import": "./dist/definitions.js",
30
+ "default": "./dist/definitions.js"
31
+ },
32
+ "./templates": {
33
+ "types": "./dist/templates.d.ts",
34
+ "import": "./dist/templates.js",
35
+ "default": "./dist/templates.js"
36
+ },
37
+ "./plmt-elements.css": "./dist/plmt-elements.css",
38
+ "./tags.json": "./dist/tags.json",
39
+ "./manifest.json": "./dist/manifest.json"
40
+ },
41
+ "jsdelivr": "dist/plmt-elements.css",
42
+ "unpkg": "dist/plmt-elements.css",
43
+ "sideEffects": [
44
+ "./dist/plmt-elements.js",
45
+ "./dist/plmt-elements.css",
46
+ "**/*.css"
47
+ ],
48
+ "publishConfig": {
49
+ "access": "public",
50
+ "registry": "https://registry.npmjs.org/"
51
+ },
52
+ "dependencies": {
53
+ "zod": "^4.6.5"
54
+ },
55
+ "devDependencies": {
56
+ "@storybook/addon-a11y": "^10.6.0",
57
+ "@storybook/addon-docs": "^10.6.0",
58
+ "@storybook/html-vite": "^10.6.0",
59
+ "happy-dom": "^20.0.10",
60
+ "storybook": "^10.6.0",
61
+ "typescript": "~6.0.2",
62
+ "vite": "^8.3.0",
63
+ "vite-plugin-dts": "^5.0.2",
64
+ "vitest": "^5.0.0"
65
+ },
66
+ "engines": {
67
+ "node": ">=22.14.0"
68
+ }
69
+ }