@underverse-ui/underverse 1.0.24 → 1.0.25
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.
- package/dist/index.cjs +65 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.js +63 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -174,9 +174,11 @@ __export(index_exports, {
|
|
|
174
174
|
Watermark: () => Watermark_default,
|
|
175
175
|
cn: () => cn,
|
|
176
176
|
cnLocal: () => cn2,
|
|
177
|
+
extractImageSrcsFromHtml: () => extractImageSrcsFromHtml,
|
|
177
178
|
getAnimationStyles: () => getAnimationStyles,
|
|
178
179
|
getUnderverseMessages: () => getUnderverseMessages,
|
|
179
180
|
injectAnimationStyles: () => injectAnimationStyles,
|
|
181
|
+
normalizeImageUrl: () => normalizeImageUrl,
|
|
180
182
|
prepareUEditorContentForSave: () => prepareUEditorContentForSave,
|
|
181
183
|
shadcnAnimationStyles: () => shadcnAnimationStyles2,
|
|
182
184
|
underverseMessages: () => underverseMessages,
|
|
@@ -24425,6 +24427,34 @@ function getErrorReason(error) {
|
|
|
24425
24427
|
if (typeof error === "string" && error.trim()) return error;
|
|
24426
24428
|
return "Unknown upload error.";
|
|
24427
24429
|
}
|
|
24430
|
+
function decodeHtmlEntities(value) {
|
|
24431
|
+
return value.replace(/"/gi, '"').replace(/'/gi, "'").replace(/&/gi, "&").replace(/</gi, "<").replace(/>/gi, ">").replace(/ /gi, " ");
|
|
24432
|
+
}
|
|
24433
|
+
function normalizeImageUrl(url) {
|
|
24434
|
+
const input = decodeHtmlEntities(url.trim());
|
|
24435
|
+
if (!input) return "";
|
|
24436
|
+
if (isDataImageUrl(input)) return input;
|
|
24437
|
+
const isAbsolute = /^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(input);
|
|
24438
|
+
if (!isAbsolute) {
|
|
24439
|
+
return input.split("#")[0] ?? input;
|
|
24440
|
+
}
|
|
24441
|
+
try {
|
|
24442
|
+
const parsed = new URL(input);
|
|
24443
|
+
parsed.hash = "";
|
|
24444
|
+
if (parsed.protocol === "http:" || parsed.protocol === "https:") {
|
|
24445
|
+
parsed.hostname = parsed.hostname.toLowerCase();
|
|
24446
|
+
if (parsed.protocol === "http:" && parsed.port === "80" || parsed.protocol === "https:" && parsed.port === "443") {
|
|
24447
|
+
parsed.port = "";
|
|
24448
|
+
}
|
|
24449
|
+
if (parsed.pathname.length > 1 && parsed.pathname.endsWith("/")) {
|
|
24450
|
+
parsed.pathname = parsed.pathname.slice(0, -1);
|
|
24451
|
+
}
|
|
24452
|
+
}
|
|
24453
|
+
return parsed.toString();
|
|
24454
|
+
} catch {
|
|
24455
|
+
return input.split("#")[0] ?? input;
|
|
24456
|
+
}
|
|
24457
|
+
}
|
|
24428
24458
|
function replaceSrcInTag(match, nextSrc) {
|
|
24429
24459
|
if (!match.srcAttr) return match.tag;
|
|
24430
24460
|
const { start, end, quote } = match.srcAttr;
|
|
@@ -24458,6 +24488,24 @@ function collectImgTagMatches(html) {
|
|
|
24458
24488
|
}
|
|
24459
24489
|
return matches;
|
|
24460
24490
|
}
|
|
24491
|
+
function extractImageSrcsFromHtml(html) {
|
|
24492
|
+
if (!html || !html.includes("<img")) return [];
|
|
24493
|
+
return collectImgTagMatches(html).map((match) => decodeHtmlEntities(match.srcAttr?.value.trim() ?? "")).filter(Boolean);
|
|
24494
|
+
}
|
|
24495
|
+
function createResult({
|
|
24496
|
+
html,
|
|
24497
|
+
uploaded,
|
|
24498
|
+
inlineUploaded,
|
|
24499
|
+
errors
|
|
24500
|
+
}) {
|
|
24501
|
+
return {
|
|
24502
|
+
html,
|
|
24503
|
+
uploaded,
|
|
24504
|
+
inlineImageUrls: extractImageSrcsFromHtml(html),
|
|
24505
|
+
inlineUploaded,
|
|
24506
|
+
errors
|
|
24507
|
+
};
|
|
24508
|
+
}
|
|
24461
24509
|
var UEditorPrepareContentForSaveError = class extends Error {
|
|
24462
24510
|
constructor(result) {
|
|
24463
24511
|
super(
|
|
@@ -24472,11 +24520,11 @@ async function prepareUEditorContentForSave({
|
|
|
24472
24520
|
uploadImageForSave
|
|
24473
24521
|
}) {
|
|
24474
24522
|
if (!html || !html.includes("<img")) {
|
|
24475
|
-
return { html, uploaded: [], errors: [] };
|
|
24523
|
+
return createResult({ html, uploaded: [], inlineUploaded: [], errors: [] });
|
|
24476
24524
|
}
|
|
24477
24525
|
const imgMatches = collectImgTagMatches(html);
|
|
24478
24526
|
if (imgMatches.length === 0) {
|
|
24479
|
-
return { html, uploaded: [], errors: [] };
|
|
24527
|
+
return createResult({ html, uploaded: [], inlineUploaded: [], errors: [] });
|
|
24480
24528
|
}
|
|
24481
24529
|
const base64Candidates = [];
|
|
24482
24530
|
for (const match of imgMatches) {
|
|
@@ -24491,19 +24539,21 @@ async function prepareUEditorContentForSave({
|
|
|
24491
24539
|
});
|
|
24492
24540
|
}
|
|
24493
24541
|
if (base64Candidates.length === 0) {
|
|
24494
|
-
return { html, uploaded: [], errors: [] };
|
|
24542
|
+
return createResult({ html, uploaded: [], inlineUploaded: [], errors: [] });
|
|
24495
24543
|
}
|
|
24496
24544
|
if (!uploadImageForSave) {
|
|
24497
|
-
return {
|
|
24545
|
+
return createResult({
|
|
24498
24546
|
html,
|
|
24499
24547
|
uploaded: [],
|
|
24548
|
+
inlineUploaded: [],
|
|
24500
24549
|
errors: base64Candidates.map((item) => ({
|
|
24501
24550
|
index: item.index,
|
|
24502
24551
|
reason: "`uploadImageForSave` is required to transform base64 images before save."
|
|
24503
24552
|
}))
|
|
24504
|
-
};
|
|
24553
|
+
});
|
|
24505
24554
|
}
|
|
24506
24555
|
const uploaded = [];
|
|
24556
|
+
const inlineUploaded = [];
|
|
24507
24557
|
const errors = [];
|
|
24508
24558
|
const replacements = /* @__PURE__ */ new Map();
|
|
24509
24559
|
const uploadResults = await Promise.all(
|
|
@@ -24532,9 +24582,15 @@ async function prepareUEditorContentForSave({
|
|
|
24532
24582
|
file: item.file,
|
|
24533
24583
|
meta: item.meta
|
|
24534
24584
|
});
|
|
24585
|
+
inlineUploaded.push({
|
|
24586
|
+
index: item.candidate.index,
|
|
24587
|
+
url: item.url,
|
|
24588
|
+
file: item.file,
|
|
24589
|
+
meta: item.meta
|
|
24590
|
+
});
|
|
24535
24591
|
}
|
|
24536
24592
|
if (replacements.size === 0) {
|
|
24537
|
-
return { html, uploaded, errors };
|
|
24593
|
+
return createResult({ html, uploaded, inlineUploaded, errors });
|
|
24538
24594
|
}
|
|
24539
24595
|
let transformed = "";
|
|
24540
24596
|
let cursor = 0;
|
|
@@ -24546,7 +24602,7 @@ async function prepareUEditorContentForSave({
|
|
|
24546
24602
|
cursor = match.end;
|
|
24547
24603
|
}
|
|
24548
24604
|
transformed += html.slice(cursor);
|
|
24549
|
-
return { html: transformed, uploaded, errors };
|
|
24605
|
+
return createResult({ html: transformed, uploaded, inlineUploaded, errors });
|
|
24550
24606
|
}
|
|
24551
24607
|
|
|
24552
24608
|
// ../../components/ui/UEditor/UEditor.tsx
|
|
@@ -24908,9 +24964,11 @@ function getUnderverseMessages(locale = "en") {
|
|
|
24908
24964
|
Watermark,
|
|
24909
24965
|
cn,
|
|
24910
24966
|
cnLocal,
|
|
24967
|
+
extractImageSrcsFromHtml,
|
|
24911
24968
|
getAnimationStyles,
|
|
24912
24969
|
getUnderverseMessages,
|
|
24913
24970
|
injectAnimationStyles,
|
|
24971
|
+
normalizeImageUrl,
|
|
24914
24972
|
prepareUEditorContentForSave,
|
|
24915
24973
|
shadcnAnimationStyles,
|
|
24916
24974
|
underverseMessages,
|