ablok-components 0.3.147 → 0.3.148

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.
@@ -94,6 +94,10 @@ declare const __VLS_base: import('../../../../vue/dist/vue.esm-bundler.js').Defi
94
94
  type: NumberConstructor;
95
95
  default: number;
96
96
  };
97
+ convertSvg: {
98
+ type: BooleanConstructor;
99
+ default: boolean;
100
+ };
97
101
  aspectRatio: NumberConstructor;
98
102
  localUrlFormat: {
99
103
  type: PropType<LocalUrlFormat>;
@@ -191,6 +195,10 @@ declare const __VLS_base: import('../../../../vue/dist/vue.esm-bundler.js').Defi
191
195
  type: NumberConstructor;
192
196
  default: number;
193
197
  };
198
+ convertSvg: {
199
+ type: BooleanConstructor;
200
+ default: boolean;
201
+ };
194
202
  aspectRatio: NumberConstructor;
195
203
  localUrlFormat: {
196
204
  type: PropType<LocalUrlFormat>;
@@ -222,6 +230,7 @@ declare const __VLS_base: import('../../../../vue/dist/vue.esm-bundler.js').Defi
222
230
  localUrlFormat: LocalUrlFormat;
223
231
  enableReview: boolean;
224
232
  maxImageWidth: number;
233
+ convertSvg: boolean;
225
234
  }, {}, {}, {}, string, import('../../../../vue/dist/vue.esm-bundler.js').ComponentProvideOptions, true, {}, any>;
226
235
  declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
227
236
  declare const _default: typeof __VLS_export;
@@ -1,22 +1,22 @@
1
1
  import e from "../../atoms/svg-icon/svg-icon.js";
2
2
  import t from "../../atoms/base-image/base-image.js";
3
- import { sanitizeHtml as ee } from "../../../composables/useSanitize.js";
4
- import { resizeImageFileByMaxWidth as n, srcToFile as r, uniqueId as i } from "../../../utilities/helpers.js";
5
- import a from "../../atoms/input-file/input-file.js";
6
- import { useDragAndDrop as o } from "../../../composables/useDragAndDrop.js";
7
- import { useUploadTransport as s } from "../../../composables/useUploadTransport.js";
8
- import { useLocalFileUrl as c } from "../../../composables/useLocalFileUrl.js";
9
- import l from "../image-crop-resize/image-crop-resize.js";
10
- import u from "../../templates/modal-dialog/modal-dialog.js";
11
- import { Fragment as d, Transition as f, computed as p, createBlock as te, createCommentVNode as m, createElementBlock as h, createElementVNode as g, createVNode as _, defineComponent as v, normalizeClass as y, normalizeStyle as b, onBeforeUnmount as x, openBlock as S, ref as C, renderSlot as w, toDisplayString as T, toRef as E, unref as D, watch as O, withCtx as k, withModifiers as A } from "vue";
3
+ import { sanitizeHtml as n } from "../../../composables/useSanitize.js";
4
+ import { convertSvgFileToPng as r, resizeImageFileByMaxWidth as i, srcToFile as ee, uniqueId as a } from "../../../utilities/helpers.js";
5
+ import o from "../../atoms/input-file/input-file.js";
6
+ import { useDragAndDrop as s } from "../../../composables/useDragAndDrop.js";
7
+ import { useUploadTransport as c } from "../../../composables/useUploadTransport.js";
8
+ import { useLocalFileUrl as l } from "../../../composables/useLocalFileUrl.js";
9
+ import u from "../image-crop-resize/image-crop-resize.js";
10
+ import d from "../../templates/modal-dialog/modal-dialog.js";
11
+ import { Fragment as f, Transition as p, computed as m, createBlock as h, createCommentVNode as g, createElementBlock as _, createElementVNode as v, createVNode as y, defineComponent as b, normalizeClass as x, normalizeStyle as S, onBeforeUnmount as C, openBlock as w, ref as T, renderSlot as E, toDisplayString as D, toRef as O, unref as k, watch as A, withCtx as j, withModifiers as M } from "vue";
12
12
  //#region src/components/molecules/image-upload/image-upload.vue?vue&type=script&setup=true&lang.ts
13
- var ne = { class: "image-upload__controls" }, re = { class: "d-flex gap-1 align-items-center" }, j = {
13
+ var te = { class: "image-upload__controls" }, ne = { class: "d-flex gap-1 align-items-center" }, re = {
14
14
  key: 1,
15
15
  class: "image-upload__controls"
16
- }, M = ["for"], N = ["innerHTML"], P = {
16
+ }, N = ["for"], P = ["innerHTML"], F = {
17
17
  key: 0,
18
18
  class: "image-upload__loading-spinner"
19
- }, F = /*@__PURE__*/ v({
19
+ }, I = /*@__PURE__*/ b({
20
20
  __name: "image-upload",
21
21
  props: {
22
22
  modelValue: {
@@ -26,11 +26,11 @@ var ne = { class: "image-upload__controls" }, re = { class: "d-flex gap-1 align-
26
26
  src: { type: String },
27
27
  name: {
28
28
  type: String,
29
- default: () => i()
29
+ default: () => a()
30
30
  },
31
31
  id: {
32
32
  type: String,
33
- default: () => i()
33
+ default: () => a()
34
34
  },
35
35
  label: {
36
36
  type: String,
@@ -105,6 +105,10 @@ var ne = { class: "image-upload__controls" }, re = { class: "d-flex gap-1 align-
105
105
  type: Number,
106
106
  default: 4096
107
107
  },
108
+ convertSvg: {
109
+ type: Boolean,
110
+ default: !1
111
+ },
108
112
  aspectRatio: Number,
109
113
  localUrlFormat: {
110
114
  type: String,
@@ -112,110 +116,110 @@ var ne = { class: "image-upload__controls" }, re = { class: "d-flex gap-1 align-
112
116
  }
113
117
  },
114
118
  emits: ["update:modelValue", "update:src"],
115
- setup(i, { emit: v }) {
116
- let F = i, I = v, L = C(), R = C([]), z = C(!1), B = C(!1), V = C(null), H = C(null), U = C(null), W = !1, { pending: G, uploadFile: K } = s(F), { toLocalUrl: q, revoke: J } = c(E(F, "localUrlFormat")), { isDragging: Y } = o(L, {
117
- enabled: () => F.dropFiles,
119
+ setup(a, { emit: b }) {
120
+ let I = a, L = b, R = T(), z = T([]), B = T(!1), V = T(!1), H = T(null), U = T(null), W = T(null), G = !1, { pending: K, uploadFile: q } = c(I), { toLocalUrl: J, revoke: Y } = l(O(I, "localUrlFormat")), { isDragging: ie } = s(R, {
121
+ enabled: () => I.dropFiles,
118
122
  onDrop: (e) => {
119
- R.value = e;
123
+ z.value = e;
120
124
  }
121
- }), X = p(() => F.modelValue ? F.modelValue : F.src ? {
125
+ }), X = m(() => I.modelValue ? I.modelValue : I.src ? {
122
126
  type: "",
123
- src: F.src
124
- } : V.value);
127
+ src: I.src
128
+ } : H.value);
125
129
  function Z(e) {
126
- J(V.value?.src), V.value = e;
130
+ Y(H.value?.src), H.value = e;
127
131
  }
128
132
  function Q() {
129
- Z(null), R.value = [], z.value = !1, I("update:modelValue", void 0), I("update:src", "");
133
+ Z(null), z.value = [], B.value = !1, L("update:modelValue", void 0), L("update:src", "");
130
134
  }
131
135
  function $() {
132
136
  Q();
133
137
  }
134
- O(() => R.value, async (e) => {
138
+ A(() => z.value, async (e) => {
135
139
  if (!e || !e.length || !e[0]) return;
136
- z.value = !1;
137
- let t = await n(e[0], F.maxImageWidth);
138
- F.enableReview ? (H.value = {
139
- src: await q(t),
140
- type: t.type
141
- }, W = !0, B.value = !0) : Z({
142
- src: F.toDataUrl ? await q(t) : await K(t),
143
- type: t.type
140
+ B.value = !1;
141
+ let t = I.convertSvg ? await r(e[0], I.maxImageWidth) : e[0], n = await i(t, I.maxImageWidth);
142
+ I.enableReview ? (U.value = {
143
+ src: await J(n),
144
+ type: n.type
145
+ }, G = !0, V.value = !0) : Z({
146
+ src: I.toDataUrl ? await J(n) : await q(n),
147
+ type: n.type
144
148
  });
145
- }), O(() => V.value, (e) => {
146
- I("update:modelValue", e || void 0), I("update:src", e?.src || "");
147
- }), O(() => U.value, async (e) => {
149
+ }), A(() => H.value, (e) => {
150
+ L("update:modelValue", e || void 0), L("update:src", e?.src || "");
151
+ }), A(() => W.value, async (e) => {
148
152
  if (e) {
149
153
  try {
150
154
  Z({
151
- src: F.toDataUrl ? await q(e) : await K(e),
155
+ src: I.toDataUrl ? await J(e) : await q(e),
152
156
  type: e.type
153
157
  });
154
158
  } catch (t) {
155
159
  console.error(`Failed to process file "${e.name}"`, t);
156
160
  }
157
- U.value = null;
161
+ W.value = null;
158
162
  }
159
- }), O(() => B.value, (e, t) => {
160
- !e && t && H.value && (W && (J(H.value.src), $()), W = !1, H.value = null);
161
- }), O(() => F.src, (e) => {
162
- !e && V.value && $();
163
+ }), A(() => V.value, (e, t) => {
164
+ !e && t && U.value && (G && (Y(U.value.src), $()), G = !1, U.value = null);
165
+ }), A(() => I.src, (e) => {
166
+ !e && H.value && $();
163
167
  });
164
- function ie(e, t) {
165
- W = !1, H.value = {
168
+ function ae(e, t) {
169
+ G = !1, U.value = {
166
170
  src: e,
167
171
  type: t
168
- }, B.value = !0;
172
+ }, V.value = !0;
169
173
  }
170
- async function ae() {
171
- H.value && (U.value = await r(H.value.src, "file", H.value.type), W && J(H.value.src)), W = !1, H.value = null, B.value = !1;
174
+ async function oe() {
175
+ U.value && (W.value = await ee(U.value.src, "file", U.value.type), G && Y(U.value.src)), G = !1, U.value = null, V.value = !1;
172
176
  }
173
- return x(() => {
174
- J(V.value?.src);
175
- }), (n, r) => (S(), h("div", {
177
+ return C(() => {
178
+ Y(H.value?.src);
179
+ }), (r, i) => (w(), _("div", {
176
180
  ref_key: "root",
177
- ref: L,
178
- class: y(["image-upload", {
179
- "has-dragging": i.dropFiles,
180
- "is-dragging": D(Y)
181
+ ref: R,
182
+ class: x(["image-upload", {
183
+ "has-dragging": a.dropFiles,
184
+ "is-dragging": k(ie)
181
185
  }])
182
186
  }, [
183
- !B.value && X.value ? (S(), h("div", {
187
+ !V.value && X.value ? (w(), _("div", {
184
188
  key: 0,
185
- class: y(["mb-2", i.enablePreview ? "image-upload__thumbnail" : "image-upload__reset"])
186
- }, [i.enablePreview ? (S(), h(d, { key: 0 }, [_(t, {
187
- src: `${X.value.src}${i.previewWidth ? `?width=${i.previewWidth}` : ""}`,
189
+ class: x(["mb-2", a.enablePreview ? "image-upload__thumbnail" : "image-upload__reset"])
190
+ }, [a.enablePreview ? (w(), _(f, { key: 0 }, [y(t, {
191
+ src: `${X.value.src}${a.previewWidth ? `?width=${a.previewWidth}` : ""}`,
188
192
  class: "img-thumbnail rounded",
189
- ready: z.value,
190
- "onUpdate:ready": r[0] ||= (e) => z.value = e,
193
+ ready: B.value,
194
+ "onUpdate:ready": i[0] ||= (e) => B.value = e,
191
195
  animate: !1,
192
- style: b({
193
- maxWidth: i.previewWidth ? `${i.previewWidth}px` : "auto",
196
+ style: S({
197
+ maxWidth: a.previewWidth ? `${a.previewWidth}px` : "auto",
194
198
  height: "auto"
195
199
  })
196
200
  }, null, 8, [
197
201
  "src",
198
202
  "ready",
199
203
  "style"
200
- ]), g("div", ne, [g("div", re, [g("button", {
204
+ ]), v("div", te, [v("div", ne, [v("button", {
201
205
  type: "button",
202
- onClick: r[1] ||= A((e) => ie(X.value.src, X.value.type), ["prevent", "stop"]),
206
+ onClick: i[1] ||= M((e) => ae(X.value.src, X.value.type), ["prevent", "stop"]),
203
207
  class: "btn btn--edit btn-sm btn-light"
204
- }, [_(e, { symbol: "edit-2" })]), g("button", {
208
+ }, [y(e, { symbol: "edit-2" })]), v("button", {
205
209
  type: "button",
206
- onClick: r[2] ||= A((e) => Q(), ["prevent", "stop"]),
210
+ onClick: i[2] ||= M((e) => Q(), ["prevent", "stop"]),
207
211
  class: "btn btn--close btn-sm btn-light"
208
- }, [_(e, { symbol: "x" })])])])], 64)) : (S(), h("div", j, [g("button", {
209
- onClick: r[3] ||= A((e) => Q(), ["prevent", "stop"]),
212
+ }, [y(e, { symbol: "x" })])])])], 64)) : (w(), _("div", re, [v("button", {
213
+ onClick: i[3] ||= M((e) => Q(), ["prevent", "stop"]),
210
214
  class: "btn btn--close btn-outline-contrast"
211
- }, [_(e, { symbol: "x" })])]))], 2)) : m("", !0),
212
- _(a, {
213
- modelValue: R.value,
214
- "onUpdate:modelValue": r[4] ||= (e) => R.value = e,
215
- id: i.id,
216
- name: i.name,
217
- accept: i.accept,
218
- "max-file-size": i.maxFileSize,
215
+ }, [y(e, { symbol: "x" })])]))], 2)) : g("", !0),
216
+ y(o, {
217
+ modelValue: z.value,
218
+ "onUpdate:modelValue": i[4] ||= (e) => z.value = e,
219
+ id: a.id,
220
+ name: a.name,
221
+ accept: a.accept,
222
+ "max-file-size": a.maxFileSize,
219
223
  class: "d-none"
220
224
  }, null, 8, [
221
225
  "modelValue",
@@ -224,41 +228,41 @@ var ne = { class: "image-upload__controls" }, re = { class: "d-flex gap-1 align-
224
228
  "accept",
225
229
  "max-file-size"
226
230
  ]),
227
- i.src ? m("", !0) : (S(), h("label", {
231
+ a.src ? g("", !0) : (w(), _("label", {
228
232
  key: 1,
229
- for: i.id,
233
+ for: a.id,
230
234
  class: "image-upload__label"
231
- }, [w(n.$slots, "button", {}, () => [g("span", {
235
+ }, [E(r.$slots, "button", {}, () => [v("span", {
232
236
  class: "btn btn-outline-contrast",
233
- innerHTML: D(ee)(i.label || n.$t("common.selectFile"))
234
- }, null, 8, N)]), _(f, { name: "fade" }, {
235
- default: k(() => [D(G) ? (S(), h("span", P, [...r[7] ||= [g("span", {
237
+ innerHTML: k(n)(a.label || r.$t("common.selectFile"))
238
+ }, null, 8, P)]), y(p, { name: "fade" }, {
239
+ default: j(() => [k(K) ? (w(), _("span", F, [...i[7] ||= [v("span", {
236
240
  class: "spinner-border",
237
241
  role: "status"
238
- }, [g("span", { class: "visually-hidden" }, "Loading...")], -1)]])) : m("", !0)]),
242
+ }, [v("span", { class: "visually-hidden" }, "Loading...")], -1)]])) : g("", !0)]),
239
243
  _: 1
240
- })], 8, M)),
241
- _(u, {
242
- modelValue: B.value,
243
- "onUpdate:modelValue": r[6] ||= (e) => B.value = e,
244
+ })], 8, N)),
245
+ y(d, {
246
+ modelValue: V.value,
247
+ "onUpdate:modelValue": i[6] ||= (e) => V.value = e,
244
248
  footer: !1
245
249
  }, {
246
- default: k(() => [B.value && H.value ? (S(), te(l, {
250
+ default: j(() => [V.value && U.value ? (w(), h(u, {
247
251
  key: 0,
248
- modelValue: H.value.src,
249
- "onUpdate:modelValue": r[5] ||= (e) => H.value.src = e,
250
- "aspect-ratio": i.aspectRatio
252
+ modelValue: U.value.src,
253
+ "onUpdate:modelValue": i[5] ||= (e) => U.value.src = e,
254
+ "aspect-ratio": a.aspectRatio
251
255
  }, {
252
- submit: k(() => [g("button", {
256
+ submit: j(() => [v("button", {
253
257
  class: "btn btn-primary",
254
- onClick: A(ae, ["prevent", "stop"])
255
- }, T(n.$t("common.save")), 1)]),
258
+ onClick: M(oe, ["prevent", "stop"])
259
+ }, D(r.$t("common.save")), 1)]),
256
260
  _: 1
257
- }, 8, ["modelValue", "aspect-ratio"])) : m("", !0)]),
261
+ }, 8, ["modelValue", "aspect-ratio"])) : g("", !0)]),
258
262
  _: 1
259
263
  }, 8, ["modelValue"])
260
264
  ], 2));
261
265
  }
262
266
  });
263
267
  //#endregion
264
- export { F as default };
268
+ export { I as default };
@@ -6,6 +6,18 @@ export declare function srcToFile(src: string, fileName: string, mimeType: strin
6
6
  export declare function loadImageFromDataUrl(dataUrl: string): Promise<HTMLImageElement>;
7
7
  export declare function resizeImageElementToDataUrl(img: HTMLImageElement, width: number, height: number, mimeType?: string, quality?: number): string;
8
8
  export declare function resizeImageFileByMaxWidth(file: File, maxWidth: number, quality?: number): Promise<File>;
9
+ /**
10
+ * Converts an SVG file to a PNG file by rasterizing it on a canvas.
11
+ * Non-SVG files are returned unchanged.
12
+ *
13
+ * SVGs without intrinsic dimensions (naturalWidth === 0) are rasterized at
14
+ * `fallbackWidth` (square), so callers can control the output size.
15
+ * @param file - The file to convert
16
+ * @param fallbackWidth - Width used when the SVG has no intrinsic size
17
+ * @param quality - Optional PNG quality passed to canvas.toDataURL
18
+ * @returns A PNG File, or the original file if it is not an SVG
19
+ */
20
+ export declare function convertSvgFileToPng(file: File, fallbackWidth?: number, quality?: number): Promise<File>;
9
21
  /**
10
22
  * Basic client-side input cleanup for user-entered text.
11
23
  *
@@ -52,8 +52,13 @@ async function o(e, n, o) {
52
52
  let d = Math.round(n), f = u / l;
53
53
  return await r(a(c, d, Math.round(d * f), e.type || "image/png", o), e.name, e.type || "image/png");
54
54
  }
55
- function s(e) {
55
+ async function s(e, n = 1024, o) {
56
+ if ((e.type || "").toLowerCase() !== "image/svg+xml") return e;
57
+ let s = await i(await t(e));
58
+ return await r(a(s, s.naturalWidth || Math.round(n), s.naturalHeight || Math.round(n), "image/png", o), `${e.name.replace(/\.svg$/i, "")}.png`, "image/png");
59
+ }
60
+ function c(e) {
56
61
  return !e || typeof e != "string" ? "" : e.replace(/\0/g, "").replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, "").replace(/on\w+\s*=\s*["'][^"']*["']/gi, "").replace(/on\w+\s*=\s*[^\s>]*/gi, "").replace(/javascript:/gi, "").replace(/data:text\/html/gi, "");
57
62
  }
58
63
  //#endregion
59
- export { t as fileToDataUrl, n as getExtensionFromMimeType, i as loadImageFromDataUrl, a as resizeImageElementToDataUrl, o as resizeImageFileByMaxWidth, s as sanitizeInput, r as srcToFile, e as uniqueId };
64
+ export { s as convertSvgFileToPng, t as fileToDataUrl, n as getExtensionFromMimeType, i as loadImageFromDataUrl, a as resizeImageElementToDataUrl, o as resizeImageFileByMaxWidth, c as sanitizeInput, r as srcToFile, e as uniqueId };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ablok-components",
3
3
  "private": false,
4
- "version": "0.3.147",
4
+ "version": "0.3.148",
5
5
  "type": "module",
6
6
  "dependencies": {
7
7
  "@tiptap/core": "^3.30.0",