@deot/vc 1.0.50 → 1.0.52
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 +2 -2
- package/dist/index.d.ts +58 -6
- package/dist/index.iife.js +4258 -37
- package/dist/index.js +3 -3
- package/dist/index.umd.cjs +4258 -37
- package/package.json +4 -4
package/dist/index.iife.js
CHANGED
|
@@ -200,7 +200,7 @@ var Vc = (function (exports, vue) {
|
|
|
200
200
|
return target;
|
|
201
201
|
};
|
|
202
202
|
|
|
203
|
-
const getStyle$
|
|
203
|
+
const getStyle$2 = (el, name) => {
|
|
204
204
|
if (IS_SERVER$2 || !name) return "";
|
|
205
205
|
if (name === "float") {
|
|
206
206
|
name = "cssFloat";
|
|
@@ -216,8 +216,8 @@ var Vc = (function (exports, vue) {
|
|
|
216
216
|
const isScroller = (el, options) => {
|
|
217
217
|
if (IS_SERVER$2 || !el) return false;
|
|
218
218
|
const { className, direction } = options || {};
|
|
219
|
-
let overflow = getStyle$
|
|
220
|
-
overflow = overflow || getStyle$
|
|
219
|
+
let overflow = getStyle$2(el, `overflow-${direction ? "y" : "x"}`);
|
|
220
|
+
overflow = overflow || getStyle$2(el, "overflow");
|
|
221
221
|
return !!(overflow.match(/(scroll|auto)/) || className?.test(el.className));
|
|
222
222
|
};
|
|
223
223
|
|
|
@@ -6612,7 +6612,7 @@ var Vc = (function (exports, vue) {
|
|
|
6612
6612
|
* @returns {boolean}
|
|
6613
6613
|
*/
|
|
6614
6614
|
|
|
6615
|
-
function isSafari$
|
|
6615
|
+
function isSafari$2() {
|
|
6616
6616
|
return !!(navigator.vendor && navigator.vendor.match(/apple/i));
|
|
6617
6617
|
}
|
|
6618
6618
|
|
|
@@ -7490,7 +7490,7 @@ var Vc = (function (exports, vue) {
|
|
|
7490
7490
|
// that's because I want to show image before it's fully loaded,
|
|
7491
7491
|
// as browser can render parts of image while it is loading.
|
|
7492
7492
|
// We do not do this in Safari due to partial loading bug.
|
|
7493
|
-
if (supportsDecode && this.slide && (!this.slide.isActive || isSafari$
|
|
7493
|
+
if (supportsDecode && this.slide && (!this.slide.isActive || isSafari$2())) {
|
|
7494
7494
|
this.isDecoding = true; // purposefully using finally instead of then,
|
|
7495
7495
|
// as if srcset sizes changes dynamically - it may cause decode error
|
|
7496
7496
|
|
|
@@ -7521,7 +7521,7 @@ var Vc = (function (exports, vue) {
|
|
|
7521
7521
|
return;
|
|
7522
7522
|
}
|
|
7523
7523
|
|
|
7524
|
-
if (this.isImageContent() && this.isDecoding && !isSafari$
|
|
7524
|
+
if (this.isImageContent() && this.isDecoding && !isSafari$2()) {
|
|
7525
7525
|
// add image to slide when it becomes active,
|
|
7526
7526
|
// even if it's not finished decoding
|
|
7527
7527
|
this.appendImage();
|
|
@@ -11302,7 +11302,7 @@ var Vc = (function (exports, vue) {
|
|
|
11302
11302
|
...listeners
|
|
11303
11303
|
}), {
|
|
11304
11304
|
prepend: slots.prepend && (() => slots.prepend?.()),
|
|
11305
|
-
append:
|
|
11305
|
+
append: slots.append ? () => slots.append?.() : props2.step ? () => {
|
|
11306
11306
|
return vue.createVNode("div", {
|
|
11307
11307
|
"class": "vc-input-number__icon"
|
|
11308
11308
|
}, [vue.createVNode("div", {
|
|
@@ -20539,23 +20539,103 @@ var Vc = (function (exports, vue) {
|
|
|
20539
20539
|
tag: {
|
|
20540
20540
|
type: String,
|
|
20541
20541
|
default: "div"
|
|
20542
|
+
},
|
|
20543
|
+
// useCORS
|
|
20544
|
+
crossOrigin: {
|
|
20545
|
+
type: String,
|
|
20546
|
+
// ''. 'anonymous', 'use-credentials'
|
|
20547
|
+
default: "anonymous",
|
|
20548
|
+
validator: (v) => /^(|anonymous|use-credentials)$/.test(v)
|
|
20549
|
+
},
|
|
20550
|
+
transformSource: Function,
|
|
20551
|
+
// 传递给snap-dom的配置项
|
|
20552
|
+
options: {
|
|
20553
|
+
type: Object,
|
|
20554
|
+
default: () => ({})
|
|
20542
20555
|
}
|
|
20543
20556
|
};
|
|
20544
|
-
const COMPONENT_NAME$Z = "vc-
|
|
20545
|
-
const
|
|
20557
|
+
const COMPONENT_NAME$Z = "vc-snapshot";
|
|
20558
|
+
const Snapshot = /* @__PURE__ */ vue.defineComponent({
|
|
20546
20559
|
name: COMPONENT_NAME$Z,
|
|
20547
20560
|
props: props$H,
|
|
20561
|
+
emits: ["ready"],
|
|
20548
20562
|
setup(props2, {
|
|
20549
|
-
|
|
20563
|
+
emit,
|
|
20564
|
+
slots,
|
|
20565
|
+
expose
|
|
20550
20566
|
}) {
|
|
20567
|
+
const current = vue.ref();
|
|
20568
|
+
const instance = vue.ref();
|
|
20569
|
+
const refresh = async () => {
|
|
20570
|
+
if (!props2.crossOrigin) return;
|
|
20571
|
+
const transformSource = props2.transformSource || VcInstance.options.Snapshot?.transformSource || ((v) => v);
|
|
20572
|
+
return Promise.all(Array.from(current.value.querySelectorAll("img")).map((node) => {
|
|
20573
|
+
return new Promise((resolve) => {
|
|
20574
|
+
(async () => {
|
|
20575
|
+
let url;
|
|
20576
|
+
try {
|
|
20577
|
+
url = await transformSource(node.src);
|
|
20578
|
+
} catch (e) {
|
|
20579
|
+
console.error(e);
|
|
20580
|
+
}
|
|
20581
|
+
const image = new Image();
|
|
20582
|
+
image.crossOrigin = props2.crossOrigin;
|
|
20583
|
+
image.src = `${url}?=${(/* @__PURE__ */ new Date()).getTime()}`;
|
|
20584
|
+
image.onload = () => {
|
|
20585
|
+
node.src = image.src;
|
|
20586
|
+
resolve(1);
|
|
20587
|
+
};
|
|
20588
|
+
image.onerror = () => resolve(0);
|
|
20589
|
+
})();
|
|
20590
|
+
});
|
|
20591
|
+
}));
|
|
20592
|
+
};
|
|
20593
|
+
const toDataURL = async () => {
|
|
20594
|
+
await refresh();
|
|
20595
|
+
return instance.value.toRaw();
|
|
20596
|
+
};
|
|
20597
|
+
const download = async (options) => {
|
|
20598
|
+
await refresh();
|
|
20599
|
+
const _download = VcInstance.options.Snapshot?.download || (() => false);
|
|
20600
|
+
const allow = _download(options);
|
|
20601
|
+
if (allow && allow.then) {
|
|
20602
|
+
allow.catch(() => {
|
|
20603
|
+
instance.value.download(options);
|
|
20604
|
+
});
|
|
20605
|
+
return;
|
|
20606
|
+
}
|
|
20607
|
+
allow || instance.value.download(options);
|
|
20608
|
+
};
|
|
20609
|
+
expose({
|
|
20610
|
+
instance,
|
|
20611
|
+
refresh,
|
|
20612
|
+
toDataURL,
|
|
20613
|
+
download
|
|
20614
|
+
});
|
|
20615
|
+
vue.onMounted(async () => {
|
|
20616
|
+
try {
|
|
20617
|
+
let snapDOM = window.snapdom || await Promise.resolve().then(() => snapdom$1);
|
|
20618
|
+
snapDOM = snapDOM.snapdom || snapDOM;
|
|
20619
|
+
instance.value = await snapDOM(current.value, props2.options);
|
|
20620
|
+
emit("ready", {
|
|
20621
|
+
instance: instance.value,
|
|
20622
|
+
dependencies: {
|
|
20623
|
+
snapDOM
|
|
20624
|
+
}
|
|
20625
|
+
});
|
|
20626
|
+
} catch (e) {
|
|
20627
|
+
throw new VcError("snapshot", e);
|
|
20628
|
+
}
|
|
20629
|
+
});
|
|
20551
20630
|
return () => {
|
|
20552
20631
|
return vue.createVNode("div", {
|
|
20553
|
-
"
|
|
20632
|
+
"ref": current,
|
|
20633
|
+
"class": "vc-snapshot"
|
|
20554
20634
|
}, [slots?.default?.()]);
|
|
20555
20635
|
};
|
|
20556
20636
|
}
|
|
20557
20637
|
});
|
|
20558
|
-
const
|
|
20638
|
+
const MSnapshot = Snapshot;
|
|
20559
20639
|
const MIcon = Icon;
|
|
20560
20640
|
const props$G = {
|
|
20561
20641
|
src: String,
|
|
@@ -23629,6 +23709,7 @@ var Vc = (function (exports, vue) {
|
|
|
23629
23709
|
checked,
|
|
23630
23710
|
classes,
|
|
23631
23711
|
computedLabel,
|
|
23712
|
+
isDisabled,
|
|
23632
23713
|
handleChange,
|
|
23633
23714
|
handleFocus,
|
|
23634
23715
|
handleBlur
|
|
@@ -23648,7 +23729,7 @@ var Vc = (function (exports, vue) {
|
|
|
23648
23729
|
}, null)]), vue.createVNode("input", {
|
|
23649
23730
|
"checked": checked.value,
|
|
23650
23731
|
"name": radioName.value,
|
|
23651
|
-
"disabled":
|
|
23732
|
+
"disabled": isDisabled.value,
|
|
23652
23733
|
"type": "radio",
|
|
23653
23734
|
"onChange": handleChange,
|
|
23654
23735
|
"onFocus": handleFocus,
|
|
@@ -23660,7 +23741,11 @@ var Vc = (function (exports, vue) {
|
|
|
23660
23741
|
const COMPONENT_NAME$x = "vc-radio-button";
|
|
23661
23742
|
const RadioButton = /* @__PURE__ */ vue.defineComponent({
|
|
23662
23743
|
name: COMPONENT_NAME$x,
|
|
23663
|
-
props:
|
|
23744
|
+
props: {
|
|
23745
|
+
...props$m,
|
|
23746
|
+
labelStyle: [String, Object],
|
|
23747
|
+
labelClass: [String, Object]
|
|
23748
|
+
},
|
|
23664
23749
|
emits: ["update:modelValue", "change"],
|
|
23665
23750
|
setup(props2, {
|
|
23666
23751
|
slots
|
|
@@ -23671,6 +23756,7 @@ var Vc = (function (exports, vue) {
|
|
|
23671
23756
|
checked,
|
|
23672
23757
|
classes,
|
|
23673
23758
|
computedLabel,
|
|
23759
|
+
isDisabled,
|
|
23674
23760
|
handleChange,
|
|
23675
23761
|
handleFocus,
|
|
23676
23762
|
handleBlur
|
|
@@ -23682,12 +23768,15 @@ var Vc = (function (exports, vue) {
|
|
|
23682
23768
|
}, [vue.createVNode("input", {
|
|
23683
23769
|
"checked": checked.value,
|
|
23684
23770
|
"name": radioName.value,
|
|
23685
|
-
"disabled":
|
|
23771
|
+
"disabled": isDisabled.value,
|
|
23686
23772
|
"type": "radio",
|
|
23687
23773
|
"onChange": handleChange,
|
|
23688
23774
|
"onFocus": handleFocus,
|
|
23689
23775
|
"onBlur": handleBlur
|
|
23690
|
-
}, null),
|
|
23776
|
+
}, null), vue.createVNode("span", {
|
|
23777
|
+
"class": [props2.labelClass, "vc-radio-button__label"],
|
|
23778
|
+
"style": props2.labelStyle
|
|
23779
|
+
}, [slots.default ? slots.default() : computedLabel.value || ""])]);
|
|
23691
23780
|
};
|
|
23692
23781
|
}
|
|
23693
23782
|
});
|
|
@@ -23793,6 +23882,7 @@ var Vc = (function (exports, vue) {
|
|
|
23793
23882
|
checked,
|
|
23794
23883
|
classes,
|
|
23795
23884
|
computedLabel,
|
|
23885
|
+
isDisabled,
|
|
23796
23886
|
handleChange,
|
|
23797
23887
|
handleFocus,
|
|
23798
23888
|
handleBlur
|
|
@@ -23812,7 +23902,7 @@ var Vc = (function (exports, vue) {
|
|
|
23812
23902
|
}, null)]), vue.createVNode("input", {
|
|
23813
23903
|
"checked": checked.value,
|
|
23814
23904
|
"name": radioName.value,
|
|
23815
|
-
"disabled":
|
|
23905
|
+
"disabled": isDisabled.value,
|
|
23816
23906
|
"type": "radio",
|
|
23817
23907
|
"onChange": handleChange,
|
|
23818
23908
|
"onFocus": handleFocus,
|
|
@@ -26232,7 +26322,7 @@ var Vc = (function (exports, vue) {
|
|
|
26232
26322
|
let hiddenEl$1;
|
|
26233
26323
|
const getFitIndex = (options = {}) => {
|
|
26234
26324
|
const { el: el2, line, value, suffix, indent = 0 } = options;
|
|
26235
|
-
let lineHeight = parseInt(getStyle$
|
|
26325
|
+
let lineHeight = parseInt(getStyle$2(el2, "line-height"), 10);
|
|
26236
26326
|
if (!hiddenEl$1) {
|
|
26237
26327
|
hiddenEl$1 = document.createElement("div");
|
|
26238
26328
|
document.body.appendChild(hiddenEl$1);
|
|
@@ -26244,7 +26334,7 @@ var Vc = (function (exports, vue) {
|
|
|
26244
26334
|
boxSizing,
|
|
26245
26335
|
sizingStyle
|
|
26246
26336
|
} = utils.getComputedStyle(el2, SIZING_STYLE$1);
|
|
26247
|
-
const textIndent = `text-indent: ${parseInt(getStyle$
|
|
26337
|
+
const textIndent = `text-indent: ${parseInt(getStyle$2(el2, "text-indent"), 10) + indent}px;`;
|
|
26248
26338
|
hiddenEl$1.setAttribute("style", `${sizingStyle};${textIndent};${HIDDEN_TEXT_STYLE}`);
|
|
26249
26339
|
let sideHeight = paddingSize || 0;
|
|
26250
26340
|
boxSizing === "border-box" && (sideHeight += borderSize);
|
|
@@ -31826,8 +31916,8 @@ var Vc = (function (exports, vue) {
|
|
|
31826
31916
|
MFormItem,
|
|
31827
31917
|
Fragment,
|
|
31828
31918
|
MFragment,
|
|
31829
|
-
|
|
31830
|
-
|
|
31919
|
+
Snapshot,
|
|
31920
|
+
MSnapshot,
|
|
31831
31921
|
Icon,
|
|
31832
31922
|
MIcon,
|
|
31833
31923
|
Image: Image$1$1,
|
|
@@ -55022,10 +55112,10 @@ var Vc = (function (exports, vue) {
|
|
|
55022
55112
|
return styleChanged;
|
|
55023
55113
|
}
|
|
55024
55114
|
function bindPathAndTextCommonStyle(ctx, el, prevEl, forceSetAll, scope) {
|
|
55025
|
-
var style = getStyle(el, scope.inHover);
|
|
55115
|
+
var style = getStyle$1(el, scope.inHover);
|
|
55026
55116
|
var prevStyle = forceSetAll
|
|
55027
55117
|
? null
|
|
55028
|
-
: (prevEl && getStyle(prevEl, scope.inHover) || {});
|
|
55118
|
+
: (prevEl && getStyle$1(prevEl, scope.inHover) || {});
|
|
55029
55119
|
if (style === prevStyle) {
|
|
55030
55120
|
return false;
|
|
55031
55121
|
}
|
|
@@ -55076,7 +55166,7 @@ var Vc = (function (exports, vue) {
|
|
|
55076
55166
|
return styleChanged;
|
|
55077
55167
|
}
|
|
55078
55168
|
function bindImageStyle(ctx, el, prevEl, forceSetAll, scope) {
|
|
55079
|
-
return bindCommonProps(ctx, getStyle(el, scope.inHover), prevEl && getStyle(prevEl, scope.inHover), forceSetAll, scope);
|
|
55169
|
+
return bindCommonProps(ctx, getStyle$1(el, scope.inHover), prevEl && getStyle$1(prevEl, scope.inHover), forceSetAll, scope);
|
|
55080
55170
|
}
|
|
55081
55171
|
function setContextTransform(ctx, el) {
|
|
55082
55172
|
var m = el.transform;
|
|
@@ -55135,7 +55225,7 @@ var Vc = (function (exports, vue) {
|
|
|
55135
55225
|
scope.batchFill = '';
|
|
55136
55226
|
scope.batchStroke = '';
|
|
55137
55227
|
}
|
|
55138
|
-
function getStyle(el, inHover) {
|
|
55228
|
+
function getStyle$1(el, inHover) {
|
|
55139
55229
|
return inHover ? (el.__hoverStyle || el.style) : el.style;
|
|
55140
55230
|
}
|
|
55141
55231
|
function brushSingle(ctx, el) {
|
|
@@ -55189,7 +55279,7 @@ var Vc = (function (exports, vue) {
|
|
|
55189
55279
|
else if (!canBatchPath) {
|
|
55190
55280
|
flushPathDrawn(ctx, scope);
|
|
55191
55281
|
}
|
|
55192
|
-
var style = getStyle(el, scope.inHover);
|
|
55282
|
+
var style = getStyle$1(el, scope.inHover);
|
|
55193
55283
|
if (el instanceof Path) {
|
|
55194
55284
|
if (scope.lastDrawType !== DRAW_TYPE_PATH) {
|
|
55195
55285
|
forceSetStyle = true;
|
|
@@ -72576,7 +72666,7 @@ var Vc = (function (exports, vue) {
|
|
|
72576
72666
|
if (!coordSys.axisPointerEnabled) {
|
|
72577
72667
|
return;
|
|
72578
72668
|
}
|
|
72579
|
-
var coordSysKey = makeKey(coordSys.model);
|
|
72669
|
+
var coordSysKey = makeKey$1(coordSys.model);
|
|
72580
72670
|
var axesInfoInCoordSys = result.coordSysAxesInfo[coordSysKey] = {};
|
|
72581
72671
|
result.coordSysMap[coordSysKey] = coordSys;
|
|
72582
72672
|
// Set tooltip (like 'cross') is a convenient way to show axisPointer
|
|
@@ -72616,7 +72706,7 @@ var Vc = (function (exports, vue) {
|
|
|
72616
72706
|
axisPointerModel = fromTooltip ? makeAxisPointerModel(axis, baseTooltipModel, globalAxisPointerModel, ecModel, fromTooltip, triggerTooltip) : axisPointerModel;
|
|
72617
72707
|
var snap = axisPointerModel.get('snap');
|
|
72618
72708
|
var triggerEmphasis = axisPointerModel.get('triggerEmphasis');
|
|
72619
|
-
var axisKey = makeKey(axis.model);
|
|
72709
|
+
var axisKey = makeKey$1(axis.model);
|
|
72620
72710
|
var involveSeries = triggerTooltip || snap || axis.type === 'category';
|
|
72621
72711
|
// If result.axesInfo[key] exist, override it (tooltip has higher priority).
|
|
72622
72712
|
var axisInfo = result.axesInfo[axisKey] = {
|
|
@@ -72688,7 +72778,7 @@ var Vc = (function (exports, vue) {
|
|
|
72688
72778
|
if (!coordSys || seriesTooltipTrigger === 'none' || seriesTooltipTrigger === false || seriesTooltipTrigger === 'item' || seriesTooltipShow === false || seriesModel.get(['axisPointer', 'show'], true) === false) {
|
|
72689
72779
|
return;
|
|
72690
72780
|
}
|
|
72691
|
-
each$f(result.coordSysAxesInfo[makeKey(coordSys.model)], function (axisInfo) {
|
|
72781
|
+
each$f(result.coordSysAxesInfo[makeKey$1(coordSys.model)], function (axisInfo) {
|
|
72692
72782
|
var axis = axisInfo.axis;
|
|
72693
72783
|
if (coordSys.getAxis(axis.dim) === axis) {
|
|
72694
72784
|
axisInfo.seriesModels.push(seriesModel);
|
|
@@ -72766,7 +72856,7 @@ var Vc = (function (exports, vue) {
|
|
|
72766
72856
|
}
|
|
72767
72857
|
function getAxisInfo$1(axisModel) {
|
|
72768
72858
|
var coordSysAxesInfo = (axisModel.ecModel.getComponent('axisPointer') || {}).coordSysAxesInfo;
|
|
72769
|
-
return coordSysAxesInfo && coordSysAxesInfo.axesInfo[makeKey(axisModel)];
|
|
72859
|
+
return coordSysAxesInfo && coordSysAxesInfo.axesInfo[makeKey$1(axisModel)];
|
|
72770
72860
|
}
|
|
72771
72861
|
function getAxisPointerModel(axisModel) {
|
|
72772
72862
|
var axisInfo = getAxisInfo$1(axisModel);
|
|
@@ -72779,7 +72869,7 @@ var Vc = (function (exports, vue) {
|
|
|
72779
72869
|
* @param {module:echarts/model/Model} model
|
|
72780
72870
|
* @return {string} unique key
|
|
72781
72871
|
*/
|
|
72782
|
-
function makeKey(model) {
|
|
72872
|
+
function makeKey$1(model) {
|
|
72783
72873
|
return model.type + '||' + model.id;
|
|
72784
72874
|
}
|
|
72785
72875
|
|
|
@@ -95072,7 +95162,7 @@ var Vc = (function (exports, vue) {
|
|
|
95072
95162
|
return;
|
|
95073
95163
|
}
|
|
95074
95164
|
var coordSysModel = axisInfo.coordSys.model;
|
|
95075
|
-
var coordSysKey = makeKey(coordSysModel);
|
|
95165
|
+
var coordSysKey = makeKey$1(coordSysModel);
|
|
95076
95166
|
var coordSysItem = dataByCoordSys.map[coordSysKey];
|
|
95077
95167
|
if (!coordSysItem) {
|
|
95078
95168
|
coordSysItem = dataByCoordSys.map[coordSysKey] = {
|
|
@@ -112301,7 +112391,7 @@ var Vc = (function (exports, vue) {
|
|
|
112301
112391
|
* @returns {boolean}
|
|
112302
112392
|
*/
|
|
112303
112393
|
|
|
112304
|
-
function isSafari() {
|
|
112394
|
+
function isSafari$1() {
|
|
112305
112395
|
return !!(navigator.vendor && navigator.vendor.match(/apple/i));
|
|
112306
112396
|
}
|
|
112307
112397
|
|
|
@@ -117336,7 +117426,7 @@ var Vc = (function (exports, vue) {
|
|
|
117336
117426
|
// that's because I want to show image before it's fully loaded,
|
|
117337
117427
|
// as browser can render parts of image while it is loading.
|
|
117338
117428
|
// We do not do this in Safari due to partial loading bug.
|
|
117339
|
-
if (supportsDecode && this.slide && (!this.slide.isActive || isSafari())) {
|
|
117429
|
+
if (supportsDecode && this.slide && (!this.slide.isActive || isSafari$1())) {
|
|
117340
117430
|
this.isDecoding = true; // purposefully using finally instead of then,
|
|
117341
117431
|
// as if srcset sizes changes dynamically - it may cause decode error
|
|
117342
117432
|
|
|
@@ -117367,7 +117457,7 @@ var Vc = (function (exports, vue) {
|
|
|
117367
117457
|
return;
|
|
117368
117458
|
}
|
|
117369
117459
|
|
|
117370
|
-
if (this.isImageContent() && this.isDecoding && !isSafari()) {
|
|
117460
|
+
if (this.isImageContent() && this.isDecoding && !isSafari$1()) {
|
|
117371
117461
|
// add image to slide when it becomes active,
|
|
117372
117462
|
// even if it's not finished decoding
|
|
117373
117463
|
this.appendImage();
|
|
@@ -132194,6 +132284,4137 @@ var Vc = (function (exports, vue) {
|
|
|
132194
132284
|
default: Quill
|
|
132195
132285
|
}, Symbol.toStringTag, { value: 'Module' }));
|
|
132196
132286
|
|
|
132287
|
+
/*
|
|
132288
|
+
* snapdom
|
|
132289
|
+
* v.1.9.14
|
|
132290
|
+
* Author Juan Martin Muda
|
|
132291
|
+
* License MIT
|
|
132292
|
+
**/
|
|
132293
|
+
|
|
132294
|
+
|
|
132295
|
+
// src/core/cache.js
|
|
132296
|
+
var cache = {
|
|
132297
|
+
image: /* @__PURE__ */ new Map(),
|
|
132298
|
+
background: /* @__PURE__ */ new Map(),
|
|
132299
|
+
resource: /* @__PURE__ */ new Map(),
|
|
132300
|
+
defaultStyle: /* @__PURE__ */ new Map(),
|
|
132301
|
+
baseStyle: /* @__PURE__ */ new Map(),
|
|
132302
|
+
computedStyle: /* @__PURE__ */ new WeakMap(),
|
|
132303
|
+
font: /* @__PURE__ */ new Set(),
|
|
132304
|
+
session: {
|
|
132305
|
+
styleMap: /* @__PURE__ */ new Map(),
|
|
132306
|
+
styleCache: /* @__PURE__ */ new WeakMap(),
|
|
132307
|
+
nodeMap: /* @__PURE__ */ new Map()
|
|
132308
|
+
}
|
|
132309
|
+
};
|
|
132310
|
+
function applyCachePolicy(policy = "soft") {
|
|
132311
|
+
switch (policy) {
|
|
132312
|
+
case "auto": {
|
|
132313
|
+
cache.session.styleMap = /* @__PURE__ */ new Map();
|
|
132314
|
+
cache.session.nodeMap = /* @__PURE__ */ new Map();
|
|
132315
|
+
return;
|
|
132316
|
+
}
|
|
132317
|
+
case "soft": {
|
|
132318
|
+
cache.session.styleMap = /* @__PURE__ */ new Map();
|
|
132319
|
+
cache.session.nodeMap = /* @__PURE__ */ new Map();
|
|
132320
|
+
cache.session.styleCache = /* @__PURE__ */ new WeakMap();
|
|
132321
|
+
return;
|
|
132322
|
+
}
|
|
132323
|
+
case "full": {
|
|
132324
|
+
return;
|
|
132325
|
+
}
|
|
132326
|
+
case "disabled": {
|
|
132327
|
+
cache.session.styleMap = /* @__PURE__ */ new Map();
|
|
132328
|
+
cache.session.nodeMap = /* @__PURE__ */ new Map();
|
|
132329
|
+
cache.session.styleCache = /* @__PURE__ */ new WeakMap();
|
|
132330
|
+
cache.computedStyle = /* @__PURE__ */ new WeakMap();
|
|
132331
|
+
cache.baseStyle = /* @__PURE__ */ new Map();
|
|
132332
|
+
cache.defaultStyle = /* @__PURE__ */ new Map();
|
|
132333
|
+
cache.image = /* @__PURE__ */ new Map();
|
|
132334
|
+
cache.background = /* @__PURE__ */ new Map();
|
|
132335
|
+
cache.resource = /* @__PURE__ */ new Map();
|
|
132336
|
+
cache.font = /* @__PURE__ */ new Set();
|
|
132337
|
+
return;
|
|
132338
|
+
}
|
|
132339
|
+
default: {
|
|
132340
|
+
cache.session.styleMap = /* @__PURE__ */ new Map();
|
|
132341
|
+
cache.session.nodeMap = /* @__PURE__ */ new Map();
|
|
132342
|
+
cache.session.styleCache = /* @__PURE__ */ new WeakMap();
|
|
132343
|
+
return;
|
|
132344
|
+
}
|
|
132345
|
+
}
|
|
132346
|
+
}
|
|
132347
|
+
|
|
132348
|
+
// src/utils/helpers.js
|
|
132349
|
+
function extractURL(value) {
|
|
132350
|
+
const match = value.match(/url\((['"]?)(.*?)(\1)\)/);
|
|
132351
|
+
if (!match) return null;
|
|
132352
|
+
const url = match[2].trim();
|
|
132353
|
+
if (url.startsWith("#")) return null;
|
|
132354
|
+
return url;
|
|
132355
|
+
}
|
|
132356
|
+
function stripTranslate(transform) {
|
|
132357
|
+
if (!transform || transform === "none") return "";
|
|
132358
|
+
let cleaned = transform.replace(/translate[XY]?\([^)]*\)/g, "");
|
|
132359
|
+
cleaned = cleaned.replace(/matrix\(([^)]+)\)/g, (_, values) => {
|
|
132360
|
+
const parts = values.split(",").map((s) => s.trim());
|
|
132361
|
+
if (parts.length !== 6) return `matrix(${values})`;
|
|
132362
|
+
parts[4] = "0";
|
|
132363
|
+
parts[5] = "0";
|
|
132364
|
+
return `matrix(${parts.join(", ")})`;
|
|
132365
|
+
});
|
|
132366
|
+
cleaned = cleaned.replace(/matrix3d\(([^)]+)\)/g, (_, values) => {
|
|
132367
|
+
const parts = values.split(",").map((s) => s.trim());
|
|
132368
|
+
if (parts.length !== 16) return `matrix3d(${values})`;
|
|
132369
|
+
parts[12] = "0";
|
|
132370
|
+
parts[13] = "0";
|
|
132371
|
+
return `matrix3d(${parts.join(", ")})`;
|
|
132372
|
+
});
|
|
132373
|
+
return cleaned.trim().replace(/\s{2,}/g, " ");
|
|
132374
|
+
}
|
|
132375
|
+
function safeEncodeURI(uri) {
|
|
132376
|
+
if (/%[0-9A-Fa-f]{2}/.test(uri)) return uri;
|
|
132377
|
+
try {
|
|
132378
|
+
return encodeURI(uri);
|
|
132379
|
+
} catch {
|
|
132380
|
+
return uri;
|
|
132381
|
+
}
|
|
132382
|
+
}
|
|
132383
|
+
|
|
132384
|
+
// src/modules/snapFetch.js
|
|
132385
|
+
function createSnapLogger(prefix = "[snapDOM]", { ttlMs = 5 * 6e4, maxEntries = 12 } = {}) {
|
|
132386
|
+
const seen = /* @__PURE__ */ new Map();
|
|
132387
|
+
let emitted = 0;
|
|
132388
|
+
function log(level, key, msg) {
|
|
132389
|
+
if (emitted >= maxEntries) return;
|
|
132390
|
+
const now = Date.now();
|
|
132391
|
+
const until = seen.get(key) || 0;
|
|
132392
|
+
if (until > now) return;
|
|
132393
|
+
seen.set(key, now + ttlMs);
|
|
132394
|
+
emitted++;
|
|
132395
|
+
if (level === "warn" && console && console.warn) console.warn(`${prefix} ${msg}`);
|
|
132396
|
+
else if (console && console.error) console.error(`${prefix} ${msg}`);
|
|
132397
|
+
}
|
|
132398
|
+
return {
|
|
132399
|
+
warnOnce(key, msg) {
|
|
132400
|
+
log("warn", key, msg);
|
|
132401
|
+
},
|
|
132402
|
+
errorOnce(key, msg) {
|
|
132403
|
+
log("error", key, msg);
|
|
132404
|
+
},
|
|
132405
|
+
reset() {
|
|
132406
|
+
seen.clear();
|
|
132407
|
+
emitted = 0;
|
|
132408
|
+
}
|
|
132409
|
+
};
|
|
132410
|
+
}
|
|
132411
|
+
var snapLogger = createSnapLogger("[snapDOM]", { ttlMs: 3 * 6e4, maxEntries: 10 });
|
|
132412
|
+
var _inflight = /* @__PURE__ */ new Map();
|
|
132413
|
+
var _errorCache = /* @__PURE__ */ new Map();
|
|
132414
|
+
function isSpecialURL(url) {
|
|
132415
|
+
return /^data:|^blob:|^about:blank$/i.test(url);
|
|
132416
|
+
}
|
|
132417
|
+
function isAlreadyProxied(url, useProxy) {
|
|
132418
|
+
try {
|
|
132419
|
+
const baseHref = typeof location !== "undefined" && location.href ? location.href : "http://localhost/";
|
|
132420
|
+
const proxyBaseRaw = useProxy.includes("{url}") ? useProxy.split("{url}")[0] : useProxy;
|
|
132421
|
+
const proxyBase = new URL(proxyBaseRaw || ".", baseHref);
|
|
132422
|
+
const u = new URL(url, baseHref);
|
|
132423
|
+
if (u.origin === proxyBase.origin) return true;
|
|
132424
|
+
const sp = u.searchParams;
|
|
132425
|
+
if (sp && (sp.has("url") || sp.has("target"))) return true;
|
|
132426
|
+
} catch {
|
|
132427
|
+
}
|
|
132428
|
+
return false;
|
|
132429
|
+
}
|
|
132430
|
+
function shouldProxy(url, useProxy) {
|
|
132431
|
+
if (!useProxy) return false;
|
|
132432
|
+
if (isSpecialURL(url)) return false;
|
|
132433
|
+
if (isAlreadyProxied(url, useProxy)) return false;
|
|
132434
|
+
try {
|
|
132435
|
+
const base = typeof location !== "undefined" && location.href ? location.href : "http://localhost/";
|
|
132436
|
+
const u = new URL(url, base);
|
|
132437
|
+
return typeof location !== "undefined" ? u.origin !== location.origin : true;
|
|
132438
|
+
} catch {
|
|
132439
|
+
return !!useProxy;
|
|
132440
|
+
}
|
|
132441
|
+
}
|
|
132442
|
+
function applyProxy(url, useProxy) {
|
|
132443
|
+
if (!useProxy) return url;
|
|
132444
|
+
if (useProxy.includes("{url}")) {
|
|
132445
|
+
return useProxy.replace("{urlRaw}", safeEncodeURI(url)).replace("{url}", encodeURIComponent(url));
|
|
132446
|
+
}
|
|
132447
|
+
if (/[?&]url=?$/.test(useProxy)) {
|
|
132448
|
+
return `${useProxy}${encodeURIComponent(url)}`;
|
|
132449
|
+
}
|
|
132450
|
+
if (useProxy.endsWith("?")) {
|
|
132451
|
+
return `${useProxy}url=${encodeURIComponent(url)}`;
|
|
132452
|
+
}
|
|
132453
|
+
if (useProxy.endsWith("/")) {
|
|
132454
|
+
return `${useProxy}${safeEncodeURI(url)}`;
|
|
132455
|
+
}
|
|
132456
|
+
const sep = useProxy.includes("?") ? "&" : "?";
|
|
132457
|
+
return `${useProxy}${sep}url=${encodeURIComponent(url)}`;
|
|
132458
|
+
}
|
|
132459
|
+
function blobToDataURL(blob) {
|
|
132460
|
+
return new Promise((res, rej) => {
|
|
132461
|
+
const fr = new FileReader();
|
|
132462
|
+
fr.onload = () => res(String(fr.result || ""));
|
|
132463
|
+
fr.onerror = () => rej(new Error("read_failed"));
|
|
132464
|
+
fr.readAsDataURL(blob);
|
|
132465
|
+
});
|
|
132466
|
+
}
|
|
132467
|
+
function makeKey(url, o) {
|
|
132468
|
+
return [
|
|
132469
|
+
o.as || "blob",
|
|
132470
|
+
o.timeout ?? 3e3,
|
|
132471
|
+
o.useProxy || "",
|
|
132472
|
+
o.errorTTL ?? 8e3,
|
|
132473
|
+
url
|
|
132474
|
+
].join("|");
|
|
132475
|
+
}
|
|
132476
|
+
async function snapFetch(url, options = {}) {
|
|
132477
|
+
const as = options.as ?? "blob";
|
|
132478
|
+
const timeout = options.timeout ?? 3e3;
|
|
132479
|
+
const useProxy = options.useProxy || "";
|
|
132480
|
+
const errorTTL = options.errorTTL ?? 8e3;
|
|
132481
|
+
const headers = options.headers || {};
|
|
132482
|
+
const silent = !!options.silent;
|
|
132483
|
+
if (/^data:/i.test(url)) {
|
|
132484
|
+
try {
|
|
132485
|
+
if (as === "text") {
|
|
132486
|
+
return { ok: true, data: String(url), status: 200, url, fromCache: false };
|
|
132487
|
+
}
|
|
132488
|
+
if (as === "dataURL") {
|
|
132489
|
+
return {
|
|
132490
|
+
ok: true,
|
|
132491
|
+
data: String(url),
|
|
132492
|
+
status: 200,
|
|
132493
|
+
url,
|
|
132494
|
+
fromCache: false,
|
|
132495
|
+
mime: String(url).slice(5).split(";")[0] || ""
|
|
132496
|
+
};
|
|
132497
|
+
}
|
|
132498
|
+
const [, meta = "", data = ""] = String(url).match(/^data:([^,]*),(.*)$/) || [];
|
|
132499
|
+
const isBase64 = /;base64/i.test(meta);
|
|
132500
|
+
const bin = isBase64 ? atob(data) : decodeURIComponent(data);
|
|
132501
|
+
const bytes = new Uint8Array([...bin].map((c) => c.charCodeAt(0)));
|
|
132502
|
+
const b = new Blob([bytes], { type: (meta || "").split(";")[0] || "" });
|
|
132503
|
+
return { ok: true, data: b, status: 200, url, fromCache: false, mime: b.type || "" };
|
|
132504
|
+
} catch {
|
|
132505
|
+
return { ok: false, data: null, status: 0, url, fromCache: false, reason: "special_url_error" };
|
|
132506
|
+
}
|
|
132507
|
+
}
|
|
132508
|
+
if (/^blob:/i.test(url)) {
|
|
132509
|
+
try {
|
|
132510
|
+
const resp = await fetch(url);
|
|
132511
|
+
if (!resp.ok) {
|
|
132512
|
+
return { ok: false, data: null, status: resp.status, url, fromCache: false, reason: "http_error" };
|
|
132513
|
+
}
|
|
132514
|
+
const blob = await resp.blob();
|
|
132515
|
+
const mime = blob.type || resp.headers.get("content-type") || "";
|
|
132516
|
+
if (as === "dataURL") {
|
|
132517
|
+
const dataURL = await blobToDataURL(blob);
|
|
132518
|
+
return { ok: true, data: dataURL, status: resp.status, url, fromCache: false, mime };
|
|
132519
|
+
}
|
|
132520
|
+
if (as === "text") {
|
|
132521
|
+
const text = await blob.text();
|
|
132522
|
+
return { ok: true, data: text, status: resp.status, url, fromCache: false, mime };
|
|
132523
|
+
}
|
|
132524
|
+
return { ok: true, data: blob, status: resp.status, url, fromCache: false, mime };
|
|
132525
|
+
} catch {
|
|
132526
|
+
return { ok: false, data: null, status: 0, url, fromCache: false, reason: "network" };
|
|
132527
|
+
}
|
|
132528
|
+
}
|
|
132529
|
+
if (/^about:blank$/i.test(url)) {
|
|
132530
|
+
if (as === "dataURL") {
|
|
132531
|
+
return {
|
|
132532
|
+
ok: true,
|
|
132533
|
+
data: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR4nGMAAQAABQABDQottAAAAABJRU5ErkJggg==",
|
|
132534
|
+
status: 200,
|
|
132535
|
+
url,
|
|
132536
|
+
fromCache: false,
|
|
132537
|
+
mime: "image/png"
|
|
132538
|
+
};
|
|
132539
|
+
}
|
|
132540
|
+
return { ok: true, data: as === "text" ? "" : new Blob([]), status: 200, url, fromCache: false };
|
|
132541
|
+
}
|
|
132542
|
+
const key = makeKey(url, { as, timeout, useProxy, errorTTL });
|
|
132543
|
+
const e = _errorCache.get(key);
|
|
132544
|
+
if (e && e.until > Date.now()) {
|
|
132545
|
+
return { ...e.result, fromCache: true };
|
|
132546
|
+
} else if (e) {
|
|
132547
|
+
_errorCache.delete(key);
|
|
132548
|
+
}
|
|
132549
|
+
const inflight = _inflight.get(key);
|
|
132550
|
+
if (inflight) return inflight;
|
|
132551
|
+
const finalURL = shouldProxy(url, useProxy) ? applyProxy(url, useProxy) : url;
|
|
132552
|
+
let cred = options.credentials;
|
|
132553
|
+
if (!cred) {
|
|
132554
|
+
try {
|
|
132555
|
+
const base = typeof location !== "undefined" && location.href ? location.href : "http://localhost/";
|
|
132556
|
+
const u = new URL(url, base);
|
|
132557
|
+
const sameOrigin = typeof location !== "undefined" && u.origin === location.origin;
|
|
132558
|
+
cred = sameOrigin ? "include" : "omit";
|
|
132559
|
+
} catch {
|
|
132560
|
+
cred = "omit";
|
|
132561
|
+
}
|
|
132562
|
+
}
|
|
132563
|
+
const ctrl = new AbortController();
|
|
132564
|
+
const timer = setTimeout(() => ctrl.abort("timeout"), timeout);
|
|
132565
|
+
const p = (async () => {
|
|
132566
|
+
try {
|
|
132567
|
+
const resp = await fetch(finalURL, { signal: ctrl.signal, credentials: cred, headers });
|
|
132568
|
+
if (!resp.ok) {
|
|
132569
|
+
const result = { ok: false, data: null, status: resp.status, url: finalURL, fromCache: false, reason: "http_error" };
|
|
132570
|
+
if (errorTTL > 0) _errorCache.set(key, { until: Date.now() + errorTTL, result });
|
|
132571
|
+
if (!silent) {
|
|
132572
|
+
const short = `${resp.status} ${resp.statusText || ""}`.trim();
|
|
132573
|
+
snapLogger.warnOnce(
|
|
132574
|
+
`http:${resp.status}:${as}:${new URL(url, location?.href ?? "http://localhost/").origin}`,
|
|
132575
|
+
`HTTP error ${short} while fetching ${as} ${url}`
|
|
132576
|
+
);
|
|
132577
|
+
}
|
|
132578
|
+
options.onError && options.onError(result);
|
|
132579
|
+
return result;
|
|
132580
|
+
}
|
|
132581
|
+
if (as === "text") {
|
|
132582
|
+
const text = await resp.text();
|
|
132583
|
+
return { ok: true, data: text, status: resp.status, url: finalURL, fromCache: false };
|
|
132584
|
+
}
|
|
132585
|
+
const blob = await resp.blob();
|
|
132586
|
+
const mime = blob.type || resp.headers.get("content-type") || "";
|
|
132587
|
+
if (as === "dataURL") {
|
|
132588
|
+
const dataURL = await blobToDataURL(blob);
|
|
132589
|
+
return { ok: true, data: dataURL, status: resp.status, url: finalURL, fromCache: false, mime };
|
|
132590
|
+
}
|
|
132591
|
+
return { ok: true, data: blob, status: resp.status, url: finalURL, fromCache: false, mime };
|
|
132592
|
+
} catch (err) {
|
|
132593
|
+
const reason = err && typeof err === "object" && "name" in err && err.name === "AbortError" ? String(err.message || "").includes("timeout") ? "timeout" : "abort" : "network";
|
|
132594
|
+
const result = { ok: false, data: null, status: 0, url: finalURL, fromCache: false, reason };
|
|
132595
|
+
if (!/^blob:/i.test(url) && errorTTL > 0) {
|
|
132596
|
+
_errorCache.set(key, { until: Date.now() + errorTTL, result });
|
|
132597
|
+
}
|
|
132598
|
+
if (!silent) {
|
|
132599
|
+
const k = `${reason}:${as}:${new URL(url, location?.href ?? "http://localhost/").origin}`;
|
|
132600
|
+
const tips = reason === "timeout" ? `Timeout after ${timeout}ms. Consider increasing timeout or using a proxy for ${url}` : reason === "abort" ? `Request aborted while fetching ${as} ${url}` : `Network/CORS issue while fetching ${as} ${url}. A proxy may be required`;
|
|
132601
|
+
snapLogger.errorOnce(k, tips);
|
|
132602
|
+
}
|
|
132603
|
+
options.onError && options.onError(result);
|
|
132604
|
+
return result;
|
|
132605
|
+
} finally {
|
|
132606
|
+
clearTimeout(timer);
|
|
132607
|
+
_inflight.delete(key);
|
|
132608
|
+
}
|
|
132609
|
+
})();
|
|
132610
|
+
_inflight.set(key, p);
|
|
132611
|
+
return p;
|
|
132612
|
+
}
|
|
132613
|
+
|
|
132614
|
+
// src/utils/image.js
|
|
132615
|
+
function createBackground(baseCanvas, backgroundColor) {
|
|
132616
|
+
if (!backgroundColor || !baseCanvas.width || !baseCanvas.height) {
|
|
132617
|
+
return baseCanvas;
|
|
132618
|
+
}
|
|
132619
|
+
const temp = document.createElement("canvas");
|
|
132620
|
+
temp.width = baseCanvas.width;
|
|
132621
|
+
temp.height = baseCanvas.height;
|
|
132622
|
+
const ctx = temp.getContext("2d");
|
|
132623
|
+
ctx.fillStyle = backgroundColor;
|
|
132624
|
+
ctx.fillRect(0, 0, temp.width, temp.height);
|
|
132625
|
+
ctx.drawImage(baseCanvas, 0, 0);
|
|
132626
|
+
return temp;
|
|
132627
|
+
}
|
|
132628
|
+
async function inlineSingleBackgroundEntry(entry, options = {}) {
|
|
132629
|
+
const isGradient = /^((repeating-)?(linear|radial|conic)-gradient)\(/i.test(entry);
|
|
132630
|
+
if (isGradient || entry.trim() === "none") {
|
|
132631
|
+
return entry;
|
|
132632
|
+
}
|
|
132633
|
+
const rawUrl = extractURL(entry);
|
|
132634
|
+
if (!rawUrl) {
|
|
132635
|
+
return entry;
|
|
132636
|
+
}
|
|
132637
|
+
const encodedUrl = safeEncodeURI(rawUrl);
|
|
132638
|
+
if (cache.background.has(encodedUrl)) {
|
|
132639
|
+
const dataUrl = cache.background.get(encodedUrl);
|
|
132640
|
+
return dataUrl ? `url("${dataUrl}")` : "none";
|
|
132641
|
+
}
|
|
132642
|
+
try {
|
|
132643
|
+
const dataUrl = await snapFetch(encodedUrl, { as: "dataURL", useProxy: options.useProxy });
|
|
132644
|
+
if (dataUrl.ok) {
|
|
132645
|
+
cache.background.set(encodedUrl, dataUrl.data);
|
|
132646
|
+
return `url("${dataUrl.data}")`;
|
|
132647
|
+
}
|
|
132648
|
+
cache.background.set(encodedUrl, null);
|
|
132649
|
+
return "none";
|
|
132650
|
+
} catch {
|
|
132651
|
+
cache.background.set(encodedUrl, null);
|
|
132652
|
+
return "none";
|
|
132653
|
+
}
|
|
132654
|
+
}
|
|
132655
|
+
|
|
132656
|
+
// src/utils/css.js
|
|
132657
|
+
var NO_CAPTURE_TAGS = /* @__PURE__ */ new Set([
|
|
132658
|
+
"meta",
|
|
132659
|
+
"script",
|
|
132660
|
+
"noscript",
|
|
132661
|
+
"title",
|
|
132662
|
+
"link",
|
|
132663
|
+
"template"
|
|
132664
|
+
]);
|
|
132665
|
+
var NO_DEFAULTS_TAGS = /* @__PURE__ */ new Set([
|
|
132666
|
+
// non-painting / head stuff
|
|
132667
|
+
"meta",
|
|
132668
|
+
"link",
|
|
132669
|
+
"style",
|
|
132670
|
+
"title",
|
|
132671
|
+
"noscript",
|
|
132672
|
+
"script",
|
|
132673
|
+
"template",
|
|
132674
|
+
// SVG whole namespace (safe for LeaderLine/presentation attrs)
|
|
132675
|
+
"g",
|
|
132676
|
+
"defs",
|
|
132677
|
+
"use",
|
|
132678
|
+
"marker",
|
|
132679
|
+
"mask",
|
|
132680
|
+
"clipPath",
|
|
132681
|
+
"pattern",
|
|
132682
|
+
"path",
|
|
132683
|
+
"polygon",
|
|
132684
|
+
"polyline",
|
|
132685
|
+
"line",
|
|
132686
|
+
"circle",
|
|
132687
|
+
"ellipse",
|
|
132688
|
+
"rect",
|
|
132689
|
+
"filter",
|
|
132690
|
+
"lineargradient",
|
|
132691
|
+
"radialgradient",
|
|
132692
|
+
"stop"
|
|
132693
|
+
]);
|
|
132694
|
+
var commonTags = [
|
|
132695
|
+
"div",
|
|
132696
|
+
"span",
|
|
132697
|
+
"p",
|
|
132698
|
+
"a",
|
|
132699
|
+
"img",
|
|
132700
|
+
"ul",
|
|
132701
|
+
"li",
|
|
132702
|
+
"button",
|
|
132703
|
+
"input",
|
|
132704
|
+
"select",
|
|
132705
|
+
"textarea",
|
|
132706
|
+
"label",
|
|
132707
|
+
"section",
|
|
132708
|
+
"article",
|
|
132709
|
+
"header",
|
|
132710
|
+
"footer",
|
|
132711
|
+
"nav",
|
|
132712
|
+
"main",
|
|
132713
|
+
"aside",
|
|
132714
|
+
"h1",
|
|
132715
|
+
"h2",
|
|
132716
|
+
"h3",
|
|
132717
|
+
"h4",
|
|
132718
|
+
"h5",
|
|
132719
|
+
"h6",
|
|
132720
|
+
"table",
|
|
132721
|
+
"thead",
|
|
132722
|
+
"tbody",
|
|
132723
|
+
"tr",
|
|
132724
|
+
"td",
|
|
132725
|
+
"th"
|
|
132726
|
+
];
|
|
132727
|
+
function precacheCommonTags() {
|
|
132728
|
+
for (let tag of commonTags) {
|
|
132729
|
+
const t = String(tag).toLowerCase();
|
|
132730
|
+
if (NO_CAPTURE_TAGS.has(t)) continue;
|
|
132731
|
+
if (NO_DEFAULTS_TAGS.has(t)) continue;
|
|
132732
|
+
getDefaultStyleForTag(t);
|
|
132733
|
+
}
|
|
132734
|
+
}
|
|
132735
|
+
function getDefaultStyleForTag(tagName) {
|
|
132736
|
+
tagName = String(tagName).toLowerCase();
|
|
132737
|
+
if (NO_DEFAULTS_TAGS.has(tagName)) {
|
|
132738
|
+
const empty = {};
|
|
132739
|
+
cache.defaultStyle.set(tagName, empty);
|
|
132740
|
+
return empty;
|
|
132741
|
+
}
|
|
132742
|
+
if (cache.defaultStyle.has(tagName)) {
|
|
132743
|
+
return cache.defaultStyle.get(tagName);
|
|
132744
|
+
}
|
|
132745
|
+
let sandbox = document.getElementById("snapdom-sandbox");
|
|
132746
|
+
if (!sandbox) {
|
|
132747
|
+
sandbox = document.createElement("div");
|
|
132748
|
+
sandbox.id = "snapdom-sandbox";
|
|
132749
|
+
sandbox.setAttribute("data-snapdom-sandbox", "true");
|
|
132750
|
+
sandbox.setAttribute("aria-hidden", "true");
|
|
132751
|
+
sandbox.style.position = "absolute";
|
|
132752
|
+
sandbox.style.left = "-9999px";
|
|
132753
|
+
sandbox.style.top = "-9999px";
|
|
132754
|
+
sandbox.style.width = "0px";
|
|
132755
|
+
sandbox.style.height = "0px";
|
|
132756
|
+
sandbox.style.overflow = "hidden";
|
|
132757
|
+
document.body.appendChild(sandbox);
|
|
132758
|
+
}
|
|
132759
|
+
const el = document.createElement(tagName);
|
|
132760
|
+
el.style.all = "initial";
|
|
132761
|
+
sandbox.appendChild(el);
|
|
132762
|
+
const styles = getComputedStyle(el);
|
|
132763
|
+
const defaults = {};
|
|
132764
|
+
for (let prop of styles) {
|
|
132765
|
+
if (shouldIgnoreProp(prop)) continue;
|
|
132766
|
+
const value = styles.getPropertyValue(prop);
|
|
132767
|
+
defaults[prop] = value;
|
|
132768
|
+
}
|
|
132769
|
+
sandbox.removeChild(el);
|
|
132770
|
+
cache.defaultStyle.set(tagName, defaults);
|
|
132771
|
+
return defaults;
|
|
132772
|
+
}
|
|
132773
|
+
var NO_PAINT_TOKEN = /(?:^|-)(animation|transition)(?:-|$)/i;
|
|
132774
|
+
var NO_PAINT_PREFIX = /^(--|view-timeline|scroll-timeline|animation-trigger|offset-|position-try|app-region|interactivity|overlay|view-transition|-webkit-locale|-webkit-user-(?:drag|modify)|-webkit-tap-highlight-color|-webkit-text-security)$/i;
|
|
132775
|
+
var NO_PAINT_EXACT = /* @__PURE__ */ new Set([
|
|
132776
|
+
// Interaction hints
|
|
132777
|
+
"cursor",
|
|
132778
|
+
"pointer-events",
|
|
132779
|
+
"touch-action",
|
|
132780
|
+
"user-select",
|
|
132781
|
+
// Printing/speech/reading-mode hints
|
|
132782
|
+
"print-color-adjust",
|
|
132783
|
+
"speak",
|
|
132784
|
+
"reading-flow",
|
|
132785
|
+
"reading-order",
|
|
132786
|
+
// Anchoring/container/timeline scopes (metadata for layout queries)
|
|
132787
|
+
"anchor-name",
|
|
132788
|
+
"anchor-scope",
|
|
132789
|
+
"container-name",
|
|
132790
|
+
"container-type",
|
|
132791
|
+
"timeline-scope"
|
|
132792
|
+
]);
|
|
132793
|
+
function shouldIgnoreProp(prop) {
|
|
132794
|
+
const p = String(prop).toLowerCase();
|
|
132795
|
+
if (NO_PAINT_EXACT.has(p)) return true;
|
|
132796
|
+
if (NO_PAINT_PREFIX.test(p)) return true;
|
|
132797
|
+
if (NO_PAINT_TOKEN.test(p)) return true;
|
|
132798
|
+
return false;
|
|
132799
|
+
}
|
|
132800
|
+
function getStyleKey(snapshot, tagName) {
|
|
132801
|
+
tagName = String(tagName || "").toLowerCase();
|
|
132802
|
+
if (NO_DEFAULTS_TAGS.has(tagName)) {
|
|
132803
|
+
return "";
|
|
132804
|
+
}
|
|
132805
|
+
const entries = [];
|
|
132806
|
+
const defaults = getDefaultStyleForTag(tagName);
|
|
132807
|
+
for (let [prop, value] of Object.entries(snapshot)) {
|
|
132808
|
+
if (shouldIgnoreProp(prop)) continue;
|
|
132809
|
+
const def = defaults[prop];
|
|
132810
|
+
if (value && value !== def) entries.push(`${prop}:${value}`);
|
|
132811
|
+
}
|
|
132812
|
+
entries.sort();
|
|
132813
|
+
return entries.join(";");
|
|
132814
|
+
}
|
|
132815
|
+
function collectUsedTagNames(root) {
|
|
132816
|
+
const tagSet = /* @__PURE__ */ new Set();
|
|
132817
|
+
if (root.nodeType !== Node.ELEMENT_NODE && root.nodeType !== Node.DOCUMENT_FRAGMENT_NODE) {
|
|
132818
|
+
return [];
|
|
132819
|
+
}
|
|
132820
|
+
if (root.tagName) {
|
|
132821
|
+
tagSet.add(root.tagName.toLowerCase());
|
|
132822
|
+
}
|
|
132823
|
+
if (typeof root.querySelectorAll === "function") {
|
|
132824
|
+
root.querySelectorAll("*").forEach((el) => tagSet.add(el.tagName.toLowerCase()));
|
|
132825
|
+
}
|
|
132826
|
+
return Array.from(tagSet);
|
|
132827
|
+
}
|
|
132828
|
+
function generateDedupedBaseCSS(usedTagNames) {
|
|
132829
|
+
const groups = /* @__PURE__ */ new Map();
|
|
132830
|
+
for (let tagName of usedTagNames) {
|
|
132831
|
+
const styles = cache.defaultStyle.get(tagName);
|
|
132832
|
+
if (!styles) continue;
|
|
132833
|
+
const key = Object.entries(styles).map(([k, v]) => `${k}:${v};`).sort().join("");
|
|
132834
|
+
if (!key) continue;
|
|
132835
|
+
if (!groups.has(key)) {
|
|
132836
|
+
groups.set(key, []);
|
|
132837
|
+
}
|
|
132838
|
+
groups.get(key).push(tagName);
|
|
132839
|
+
}
|
|
132840
|
+
let css = "";
|
|
132841
|
+
for (let [styleBlock, tagList] of groups.entries()) {
|
|
132842
|
+
css += `${tagList.join(",")} { ${styleBlock} }
|
|
132843
|
+
`;
|
|
132844
|
+
}
|
|
132845
|
+
return css;
|
|
132846
|
+
}
|
|
132847
|
+
function generateCSSClasses(styleMap) {
|
|
132848
|
+
const keys = Array.from(new Set(styleMap.values())).filter(Boolean).sort();
|
|
132849
|
+
const classMap = /* @__PURE__ */ new Map();
|
|
132850
|
+
let i = 1;
|
|
132851
|
+
for (const k of keys) classMap.set(k, `c${i++}`);
|
|
132852
|
+
return classMap;
|
|
132853
|
+
}
|
|
132854
|
+
function getStyle(el, pseudo = null) {
|
|
132855
|
+
if (!(el instanceof Element)) {
|
|
132856
|
+
return window.getComputedStyle(el, pseudo);
|
|
132857
|
+
}
|
|
132858
|
+
let map = cache.computedStyle.get(el);
|
|
132859
|
+
if (!map) {
|
|
132860
|
+
map = /* @__PURE__ */ new Map();
|
|
132861
|
+
cache.computedStyle.set(el, map);
|
|
132862
|
+
}
|
|
132863
|
+
if (!map.has(pseudo)) {
|
|
132864
|
+
const st = window.getComputedStyle(el, pseudo);
|
|
132865
|
+
map.set(pseudo, st);
|
|
132866
|
+
}
|
|
132867
|
+
return map.get(pseudo);
|
|
132868
|
+
}
|
|
132869
|
+
function snapshotComputedStyle(style) {
|
|
132870
|
+
const snap = {};
|
|
132871
|
+
for (let prop of style) {
|
|
132872
|
+
snap[prop] = style.getPropertyValue(prop);
|
|
132873
|
+
}
|
|
132874
|
+
return snap;
|
|
132875
|
+
}
|
|
132876
|
+
function splitBackgroundImage(bg) {
|
|
132877
|
+
const parts = [];
|
|
132878
|
+
let depth = 0;
|
|
132879
|
+
let lastIndex = 0;
|
|
132880
|
+
for (let i = 0; i < bg.length; i++) {
|
|
132881
|
+
const char = bg[i];
|
|
132882
|
+
if (char === "(") depth++;
|
|
132883
|
+
if (char === ")") depth--;
|
|
132884
|
+
if (char === "," && depth === 0) {
|
|
132885
|
+
parts.push(bg.slice(lastIndex, i).trim());
|
|
132886
|
+
lastIndex = i + 1;
|
|
132887
|
+
}
|
|
132888
|
+
}
|
|
132889
|
+
parts.push(bg.slice(lastIndex).trim());
|
|
132890
|
+
return parts;
|
|
132891
|
+
}
|
|
132892
|
+
|
|
132893
|
+
// src/utils/browser.js
|
|
132894
|
+
function idle(fn, { fast = false } = {}) {
|
|
132895
|
+
if (fast) return fn();
|
|
132896
|
+
if ("requestIdleCallback" in window) {
|
|
132897
|
+
requestIdleCallback(fn, { timeout: 50 });
|
|
132898
|
+
} else {
|
|
132899
|
+
setTimeout(fn, 1);
|
|
132900
|
+
}
|
|
132901
|
+
}
|
|
132902
|
+
function isSafari() {
|
|
132903
|
+
const ua = typeof navigator !== "undefined" && navigator.userAgent ? navigator.userAgent : "";
|
|
132904
|
+
const isSafariUA = /^((?!chrome|android).)*safari/i.test(ua);
|
|
132905
|
+
const isUIWebView = /AppleWebKit/i.test(ua) && /Mobile/i.test(ua) && !/Safari/i.test(ua);
|
|
132906
|
+
const isWeChatUA = /(MicroMessenger|wxwork|WeCom|WindowsWechat|MacWechat)/i.test(ua);
|
|
132907
|
+
return isSafariUA || isUIWebView || isWeChatUA;
|
|
132908
|
+
}
|
|
132909
|
+
|
|
132910
|
+
// src/modules/styles.js
|
|
132911
|
+
var snapshotCache = /* @__PURE__ */ new WeakMap();
|
|
132912
|
+
var snapshotKeyCache = /* @__PURE__ */ new Map();
|
|
132913
|
+
var __epoch = 0;
|
|
132914
|
+
function bumpEpoch() {
|
|
132915
|
+
__epoch++;
|
|
132916
|
+
}
|
|
132917
|
+
var __wired = false;
|
|
132918
|
+
function setupInvalidationOnce(root = document.documentElement) {
|
|
132919
|
+
if (__wired) return;
|
|
132920
|
+
__wired = true;
|
|
132921
|
+
try {
|
|
132922
|
+
const domObs = new MutationObserver(() => bumpEpoch());
|
|
132923
|
+
domObs.observe(root, { subtree: true, childList: true, characterData: true, attributes: true });
|
|
132924
|
+
} catch {
|
|
132925
|
+
}
|
|
132926
|
+
try {
|
|
132927
|
+
const headObs = new MutationObserver(() => bumpEpoch());
|
|
132928
|
+
headObs.observe(document.head, { subtree: true, childList: true, characterData: true, attributes: true });
|
|
132929
|
+
} catch {
|
|
132930
|
+
}
|
|
132931
|
+
try {
|
|
132932
|
+
const f = document.fonts;
|
|
132933
|
+
if (f) {
|
|
132934
|
+
f.addEventListener?.("loadingdone", bumpEpoch);
|
|
132935
|
+
f.ready?.then(() => bumpEpoch()).catch(() => {
|
|
132936
|
+
});
|
|
132937
|
+
}
|
|
132938
|
+
} catch {
|
|
132939
|
+
}
|
|
132940
|
+
}
|
|
132941
|
+
function snapshotComputedStyleFull(style, options = {}) {
|
|
132942
|
+
const out = {};
|
|
132943
|
+
const vis = style.getPropertyValue("visibility");
|
|
132944
|
+
for (let i = 0; i < style.length; i++) {
|
|
132945
|
+
const prop = style[i];
|
|
132946
|
+
let val = style.getPropertyValue(prop);
|
|
132947
|
+
if ((prop === "background-image" || prop === "content") && val.includes("url(") && !val.includes("data:")) {
|
|
132948
|
+
val = "none";
|
|
132949
|
+
}
|
|
132950
|
+
out[prop] = val;
|
|
132951
|
+
}
|
|
132952
|
+
if (options.embedFonts) {
|
|
132953
|
+
const EXTRA_FONT_PROPS = [
|
|
132954
|
+
"font-feature-settings",
|
|
132955
|
+
"font-variation-settings",
|
|
132956
|
+
"font-kerning",
|
|
132957
|
+
"font-variant",
|
|
132958
|
+
"font-variant-ligatures",
|
|
132959
|
+
"font-optical-sizing"
|
|
132960
|
+
];
|
|
132961
|
+
for (const prop of EXTRA_FONT_PROPS) {
|
|
132962
|
+
if (out[prop]) continue;
|
|
132963
|
+
try {
|
|
132964
|
+
const v = style.getPropertyValue(prop);
|
|
132965
|
+
if (v) out[prop] = v;
|
|
132966
|
+
} catch {
|
|
132967
|
+
}
|
|
132968
|
+
}
|
|
132969
|
+
}
|
|
132970
|
+
if (vis === "hidden") out.opacity = "0";
|
|
132971
|
+
return out;
|
|
132972
|
+
}
|
|
132973
|
+
var __snapshotSig = /* @__PURE__ */ new WeakMap();
|
|
132974
|
+
function styleSignature(snap) {
|
|
132975
|
+
let sig = __snapshotSig.get(snap);
|
|
132976
|
+
if (sig) return sig;
|
|
132977
|
+
const entries = Object.entries(snap).sort((a, b) => a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0);
|
|
132978
|
+
sig = entries.map(([k, v]) => `${k}:${v}`).join(";");
|
|
132979
|
+
__snapshotSig.set(snap, sig);
|
|
132980
|
+
return sig;
|
|
132981
|
+
}
|
|
132982
|
+
function getSnapshot(el, preStyle = null, options = {}) {
|
|
132983
|
+
const rec = snapshotCache.get(el);
|
|
132984
|
+
if (rec && rec.epoch === __epoch) return rec.snapshot;
|
|
132985
|
+
const style = preStyle || getComputedStyle(el);
|
|
132986
|
+
const snap = snapshotComputedStyleFull(style, options);
|
|
132987
|
+
stripHeightForWrappers(el, style, snap);
|
|
132988
|
+
snapshotCache.set(el, { epoch: __epoch, snapshot: snap });
|
|
132989
|
+
return snap;
|
|
132990
|
+
}
|
|
132991
|
+
function _resolveCtx(sessionOrCtx, opts) {
|
|
132992
|
+
if (sessionOrCtx && sessionOrCtx.session && sessionOrCtx.persist) return sessionOrCtx;
|
|
132993
|
+
if (sessionOrCtx && (sessionOrCtx.styleMap || sessionOrCtx.styleCache || sessionOrCtx.nodeMap)) {
|
|
132994
|
+
return {
|
|
132995
|
+
session: sessionOrCtx,
|
|
132996
|
+
persist: {
|
|
132997
|
+
snapshotKeyCache,
|
|
132998
|
+
defaultStyle: cache.defaultStyle,
|
|
132999
|
+
baseStyle: cache.baseStyle,
|
|
133000
|
+
image: cache.image,
|
|
133001
|
+
resource: cache.resource,
|
|
133002
|
+
background: cache.background,
|
|
133003
|
+
font: cache.font
|
|
133004
|
+
},
|
|
133005
|
+
options: opts || {}
|
|
133006
|
+
};
|
|
133007
|
+
}
|
|
133008
|
+
return {
|
|
133009
|
+
session: cache.session,
|
|
133010
|
+
persist: {
|
|
133011
|
+
snapshotKeyCache,
|
|
133012
|
+
defaultStyle: cache.defaultStyle,
|
|
133013
|
+
baseStyle: cache.baseStyle,
|
|
133014
|
+
image: cache.image,
|
|
133015
|
+
resource: cache.resource,
|
|
133016
|
+
background: cache.background,
|
|
133017
|
+
font: cache.font
|
|
133018
|
+
},
|
|
133019
|
+
options: sessionOrCtx || opts || {}
|
|
133020
|
+
};
|
|
133021
|
+
}
|
|
133022
|
+
async function inlineAllStyles(source, clone, sessionOrCtx, opts) {
|
|
133023
|
+
if (source.tagName === "STYLE") return;
|
|
133024
|
+
const ctx = _resolveCtx(sessionOrCtx, opts);
|
|
133025
|
+
const resetMode = ctx.options && ctx.options.cache || "auto";
|
|
133026
|
+
if (resetMode !== "disabled") setupInvalidationOnce(document.documentElement);
|
|
133027
|
+
if (resetMode === "disabled" && !ctx.session.__bumpedForDisabled) {
|
|
133028
|
+
bumpEpoch();
|
|
133029
|
+
snapshotKeyCache.clear();
|
|
133030
|
+
ctx.session.__bumpedForDisabled = true;
|
|
133031
|
+
}
|
|
133032
|
+
if (NO_DEFAULTS_TAGS.has(source.tagName?.toLowerCase())) {
|
|
133033
|
+
const author = source.getAttribute?.("style");
|
|
133034
|
+
if (author) clone.setAttribute("style", author);
|
|
133035
|
+
}
|
|
133036
|
+
const { session, persist } = ctx;
|
|
133037
|
+
if (!session.styleCache.has(source)) {
|
|
133038
|
+
session.styleCache.set(source, getComputedStyle(source));
|
|
133039
|
+
}
|
|
133040
|
+
const pre = session.styleCache.get(source);
|
|
133041
|
+
const snap = getSnapshot(source, pre, ctx.options);
|
|
133042
|
+
const sig = styleSignature(snap);
|
|
133043
|
+
let key = persist.snapshotKeyCache.get(sig);
|
|
133044
|
+
if (!key) {
|
|
133045
|
+
const tag = source.tagName?.toLowerCase() || "div";
|
|
133046
|
+
key = getStyleKey(snap, tag);
|
|
133047
|
+
persist.snapshotKeyCache.set(sig, key);
|
|
133048
|
+
}
|
|
133049
|
+
session.styleMap.set(clone, key);
|
|
133050
|
+
}
|
|
133051
|
+
function isReplaced(el) {
|
|
133052
|
+
return el instanceof HTMLImageElement || el instanceof HTMLCanvasElement || el instanceof HTMLVideoElement || el instanceof HTMLIFrameElement || el instanceof SVGElement || el instanceof HTMLObjectElement || el instanceof HTMLEmbedElement;
|
|
133053
|
+
}
|
|
133054
|
+
function hasBox(cs) {
|
|
133055
|
+
if (cs.backgroundImage && cs.backgroundImage !== "none") return true;
|
|
133056
|
+
if (cs.backgroundColor && cs.backgroundColor !== "rgba(0, 0, 0, 0)" && cs.backgroundColor !== "transparent") return true;
|
|
133057
|
+
if ((parseFloat(cs.borderTopWidth) || 0) > 0) return true;
|
|
133058
|
+
if ((parseFloat(cs.borderBottomWidth) || 0) > 0) return true;
|
|
133059
|
+
if ((parseFloat(cs.paddingTop) || 0) > 0) return true;
|
|
133060
|
+
if ((parseFloat(cs.paddingBottom) || 0) > 0) return true;
|
|
133061
|
+
const ob = cs.overflowBlock || cs.overflowY || "visible";
|
|
133062
|
+
return ob !== "visible";
|
|
133063
|
+
}
|
|
133064
|
+
function isFlexOrGridItem(el) {
|
|
133065
|
+
const p = el.parentElement;
|
|
133066
|
+
if (!p) return false;
|
|
133067
|
+
const pd = getComputedStyle(p).display || "";
|
|
133068
|
+
return pd.includes("flex") || pd.includes("grid");
|
|
133069
|
+
}
|
|
133070
|
+
function hasFlowFast(el, cs) {
|
|
133071
|
+
if (el.textContent && /\S/.test(el.textContent)) return true;
|
|
133072
|
+
const f = el.firstElementChild, l = el.lastElementChild;
|
|
133073
|
+
if (f && f.tagName === "BR" || l && l.tagName === "BR") return true;
|
|
133074
|
+
const sh = el.scrollHeight;
|
|
133075
|
+
if (sh === 0) return false;
|
|
133076
|
+
const pt = parseFloat(cs.paddingTop) || 0;
|
|
133077
|
+
const pb = parseFloat(cs.paddingBottom) || 0;
|
|
133078
|
+
return sh > pt + pb;
|
|
133079
|
+
}
|
|
133080
|
+
function stripHeightForWrappers(el, cs, snap) {
|
|
133081
|
+
if (el instanceof HTMLElement && el.style && el.style.height) return;
|
|
133082
|
+
const disp = cs.display || "";
|
|
133083
|
+
if (disp.includes("flex") || disp.includes("grid")) return;
|
|
133084
|
+
if (isReplaced(el)) return;
|
|
133085
|
+
const pos = cs.position;
|
|
133086
|
+
if (pos === "absolute" || pos === "fixed" || pos === "sticky") return;
|
|
133087
|
+
if (cs.transform !== "none") return;
|
|
133088
|
+
if (hasBox(cs)) return;
|
|
133089
|
+
if (isFlexOrGridItem(el)) return;
|
|
133090
|
+
if (!hasFlowFast(el, cs)) return;
|
|
133091
|
+
delete snap.height;
|
|
133092
|
+
delete snap["block-size"];
|
|
133093
|
+
}
|
|
133094
|
+
|
|
133095
|
+
// src/modules/CSSVar.js
|
|
133096
|
+
function resolveCSSVars(sourceEl, cloneEl) {
|
|
133097
|
+
if (!(sourceEl instanceof Element) || !(cloneEl instanceof Element)) return;
|
|
133098
|
+
const styleAttr = sourceEl.getAttribute?.("style");
|
|
133099
|
+
let hasVar = !!(styleAttr && styleAttr.includes("var("));
|
|
133100
|
+
if (!hasVar && sourceEl.attributes?.length) {
|
|
133101
|
+
const attrs = sourceEl.attributes;
|
|
133102
|
+
for (let i = 0; i < attrs.length; i++) {
|
|
133103
|
+
const a = attrs[i];
|
|
133104
|
+
if (a && typeof a.value === "string" && a.value.includes("var(")) {
|
|
133105
|
+
hasVar = true;
|
|
133106
|
+
break;
|
|
133107
|
+
}
|
|
133108
|
+
}
|
|
133109
|
+
}
|
|
133110
|
+
if (!hasVar) return;
|
|
133111
|
+
let cs;
|
|
133112
|
+
try {
|
|
133113
|
+
cs = getComputedStyle(sourceEl);
|
|
133114
|
+
} catch {
|
|
133115
|
+
return;
|
|
133116
|
+
}
|
|
133117
|
+
const author = sourceEl.style;
|
|
133118
|
+
if (author && author.length) {
|
|
133119
|
+
for (let i = 0; i < author.length; i++) {
|
|
133120
|
+
const prop = author[i];
|
|
133121
|
+
const val = author.getPropertyValue(prop);
|
|
133122
|
+
if (!val || !val.includes("var(")) continue;
|
|
133123
|
+
const resolved = cs.getPropertyValue(prop);
|
|
133124
|
+
if (resolved) {
|
|
133125
|
+
try {
|
|
133126
|
+
cloneEl.style.setProperty(prop, resolved.trim(), author.getPropertyPriority(prop));
|
|
133127
|
+
} catch {
|
|
133128
|
+
}
|
|
133129
|
+
}
|
|
133130
|
+
}
|
|
133131
|
+
}
|
|
133132
|
+
if (sourceEl.attributes?.length) {
|
|
133133
|
+
const attrs = sourceEl.attributes;
|
|
133134
|
+
for (let i = 0; i < attrs.length; i++) {
|
|
133135
|
+
const a = attrs[i];
|
|
133136
|
+
if (!a || typeof a.value !== "string" || !a.value.includes("var(")) continue;
|
|
133137
|
+
const propName = a.name;
|
|
133138
|
+
let resolved = "";
|
|
133139
|
+
try {
|
|
133140
|
+
resolved = cs.getPropertyValue(propName);
|
|
133141
|
+
} catch {
|
|
133142
|
+
}
|
|
133143
|
+
if (resolved) {
|
|
133144
|
+
try {
|
|
133145
|
+
cloneEl.style.setProperty(propName, resolved.trim());
|
|
133146
|
+
} catch {
|
|
133147
|
+
}
|
|
133148
|
+
}
|
|
133149
|
+
}
|
|
133150
|
+
}
|
|
133151
|
+
}
|
|
133152
|
+
|
|
133153
|
+
// src/core/clone.js
|
|
133154
|
+
function idleCallback(childList, callback, fast) {
|
|
133155
|
+
return Promise.all(childList.map((child) => {
|
|
133156
|
+
return new Promise((resolve) => {
|
|
133157
|
+
function deal() {
|
|
133158
|
+
idle((deadline) => {
|
|
133159
|
+
const hasIdleBudget = deadline && typeof deadline.timeRemaining === "function" ? deadline.timeRemaining() > 0 : true;
|
|
133160
|
+
if (hasIdleBudget) {
|
|
133161
|
+
callback(child, resolve);
|
|
133162
|
+
} else {
|
|
133163
|
+
deal();
|
|
133164
|
+
}
|
|
133165
|
+
}, { fast });
|
|
133166
|
+
}
|
|
133167
|
+
deal();
|
|
133168
|
+
});
|
|
133169
|
+
}));
|
|
133170
|
+
}
|
|
133171
|
+
function addNotSlottedRightmost(sel) {
|
|
133172
|
+
sel = sel.trim();
|
|
133173
|
+
if (!sel) return sel;
|
|
133174
|
+
if (/:not\(\s*\[data-sd-slotted\]\s*\)\s*$/.test(sel)) return sel;
|
|
133175
|
+
return `${sel}:not([data-sd-slotted])`;
|
|
133176
|
+
}
|
|
133177
|
+
function wrapWithScope(selectorList, scopeSelector, excludeSlotted = true) {
|
|
133178
|
+
return selectorList.split(",").map((s) => s.trim()).filter(Boolean).map((s) => {
|
|
133179
|
+
if (s.startsWith(":where(")) return s;
|
|
133180
|
+
if (s.startsWith("@")) return s;
|
|
133181
|
+
const body = excludeSlotted ? addNotSlottedRightmost(s) : s;
|
|
133182
|
+
return `:where(${scopeSelector} ${body})`;
|
|
133183
|
+
}).join(", ");
|
|
133184
|
+
}
|
|
133185
|
+
function rewriteShadowCSS(cssText, scopeSelector) {
|
|
133186
|
+
if (!cssText) return "";
|
|
133187
|
+
cssText = cssText.replace(/:host\(([^)]+)\)/g, (_, sel) => {
|
|
133188
|
+
return `:where(${scopeSelector}:is(${sel.trim()}))`;
|
|
133189
|
+
});
|
|
133190
|
+
cssText = cssText.replace(/:host\b/g, `:where(${scopeSelector})`);
|
|
133191
|
+
cssText = cssText.replace(/:host-context\(([^)]+)\)/g, (_, sel) => {
|
|
133192
|
+
return `:where(:where(${sel.trim()}) ${scopeSelector})`;
|
|
133193
|
+
});
|
|
133194
|
+
cssText = cssText.replace(/::slotted\(([^)]+)\)/g, (_, sel) => {
|
|
133195
|
+
return `:where(${scopeSelector} ${sel.trim()})`;
|
|
133196
|
+
});
|
|
133197
|
+
cssText = cssText.replace(/(^|})(\s*)([^@}{]+){/g, (_, brace, ws, selectorList) => {
|
|
133198
|
+
const wrapped = wrapWithScope(
|
|
133199
|
+
selectorList,
|
|
133200
|
+
scopeSelector,
|
|
133201
|
+
/*excludeSlotted*/
|
|
133202
|
+
true
|
|
133203
|
+
);
|
|
133204
|
+
return `${brace}${ws}${wrapped}{`;
|
|
133205
|
+
});
|
|
133206
|
+
return cssText;
|
|
133207
|
+
}
|
|
133208
|
+
function nextShadowScopeId(sessionCache) {
|
|
133209
|
+
sessionCache.shadowScopeSeq = (sessionCache.shadowScopeSeq || 0) + 1;
|
|
133210
|
+
return `s${sessionCache.shadowScopeSeq}`;
|
|
133211
|
+
}
|
|
133212
|
+
function extractShadowCSS(sr) {
|
|
133213
|
+
let css = "";
|
|
133214
|
+
try {
|
|
133215
|
+
sr.querySelectorAll("style").forEach((s) => {
|
|
133216
|
+
css += (s.textContent || "") + "\n";
|
|
133217
|
+
});
|
|
133218
|
+
const sheets = sr.adoptedStyleSheets || [];
|
|
133219
|
+
for (const sh of sheets) {
|
|
133220
|
+
try {
|
|
133221
|
+
if (sh && sh.cssRules) {
|
|
133222
|
+
for (const rule of sh.cssRules) css += rule.cssText + "\n";
|
|
133223
|
+
}
|
|
133224
|
+
} catch {
|
|
133225
|
+
}
|
|
133226
|
+
}
|
|
133227
|
+
} catch {
|
|
133228
|
+
}
|
|
133229
|
+
return css;
|
|
133230
|
+
}
|
|
133231
|
+
function injectScopedStyle(hostClone, cssText, scopeId) {
|
|
133232
|
+
if (!cssText) return;
|
|
133233
|
+
const style = document.createElement("style");
|
|
133234
|
+
style.setAttribute("data-sd", scopeId);
|
|
133235
|
+
style.textContent = cssText;
|
|
133236
|
+
hostClone.insertBefore(style, hostClone.firstChild || null);
|
|
133237
|
+
}
|
|
133238
|
+
function freezeImgSrcset(original, cloned) {
|
|
133239
|
+
try {
|
|
133240
|
+
const chosen = original.currentSrc || original.src || "";
|
|
133241
|
+
if (!chosen) return;
|
|
133242
|
+
cloned.setAttribute("src", chosen);
|
|
133243
|
+
cloned.removeAttribute("srcset");
|
|
133244
|
+
cloned.removeAttribute("sizes");
|
|
133245
|
+
cloned.loading = "eager";
|
|
133246
|
+
cloned.decoding = "sync";
|
|
133247
|
+
} catch {
|
|
133248
|
+
}
|
|
133249
|
+
}
|
|
133250
|
+
function collectCustomPropsFromCSS(cssText) {
|
|
133251
|
+
const out = /* @__PURE__ */ new Set();
|
|
133252
|
+
if (!cssText) return out;
|
|
133253
|
+
const re = /var\(\s*(--[A-Za-z0-9_-]+)\b/g;
|
|
133254
|
+
let m;
|
|
133255
|
+
while (m = re.exec(cssText)) out.add(m[1]);
|
|
133256
|
+
return out;
|
|
133257
|
+
}
|
|
133258
|
+
function resolveCustomProp(el, name) {
|
|
133259
|
+
try {
|
|
133260
|
+
const cs = getComputedStyle(el);
|
|
133261
|
+
let v = cs.getPropertyValue(name).trim();
|
|
133262
|
+
if (v) return v;
|
|
133263
|
+
} catch {
|
|
133264
|
+
}
|
|
133265
|
+
try {
|
|
133266
|
+
const rootCS = getComputedStyle(document.documentElement);
|
|
133267
|
+
let v = rootCS.getPropertyValue(name).trim();
|
|
133268
|
+
if (v) return v;
|
|
133269
|
+
} catch {
|
|
133270
|
+
}
|
|
133271
|
+
return "";
|
|
133272
|
+
}
|
|
133273
|
+
function buildSeedCustomPropsRule(hostEl, names, scopeSelector) {
|
|
133274
|
+
const decls = [];
|
|
133275
|
+
for (const name of names) {
|
|
133276
|
+
const val = resolveCustomProp(hostEl, name);
|
|
133277
|
+
if (val) decls.push(`${name}: ${val};`);
|
|
133278
|
+
}
|
|
133279
|
+
if (!decls.length) return "";
|
|
133280
|
+
return `${scopeSelector}{${decls.join("")}}
|
|
133281
|
+
`;
|
|
133282
|
+
}
|
|
133283
|
+
function markSlottedSubtree(root) {
|
|
133284
|
+
if (!root) return;
|
|
133285
|
+
if (root.nodeType === Node.ELEMENT_NODE) {
|
|
133286
|
+
root.setAttribute("data-sd-slotted", "");
|
|
133287
|
+
}
|
|
133288
|
+
if (root.querySelectorAll) {
|
|
133289
|
+
root.querySelectorAll("*").forEach((el) => el.setAttribute("data-sd-slotted", ""));
|
|
133290
|
+
}
|
|
133291
|
+
}
|
|
133292
|
+
async function getAccessibleIframeDocument(iframe, attempts = 3) {
|
|
133293
|
+
const probe = () => {
|
|
133294
|
+
try {
|
|
133295
|
+
return iframe.contentDocument || iframe.contentWindow?.document || null;
|
|
133296
|
+
} catch {
|
|
133297
|
+
return null;
|
|
133298
|
+
}
|
|
133299
|
+
};
|
|
133300
|
+
let doc = probe();
|
|
133301
|
+
let i = 0;
|
|
133302
|
+
while (i < attempts && (!doc || !doc.body && !doc.documentElement)) {
|
|
133303
|
+
await new Promise((r) => setTimeout(r, 0));
|
|
133304
|
+
doc = probe();
|
|
133305
|
+
i++;
|
|
133306
|
+
}
|
|
133307
|
+
return doc && (doc.body || doc.documentElement) ? doc : null;
|
|
133308
|
+
}
|
|
133309
|
+
function measureContentBox(el) {
|
|
133310
|
+
const rect = el.getBoundingClientRect();
|
|
133311
|
+
let bl = 0, br = 0, bt = 0, bb = 0;
|
|
133312
|
+
try {
|
|
133313
|
+
const cs = getComputedStyle(el);
|
|
133314
|
+
bl = parseFloat(cs.borderLeftWidth) || 0;
|
|
133315
|
+
br = parseFloat(cs.borderRightWidth) || 0;
|
|
133316
|
+
bt = parseFloat(cs.borderTopWidth) || 0;
|
|
133317
|
+
bb = parseFloat(cs.borderBottomWidth) || 0;
|
|
133318
|
+
} catch {
|
|
133319
|
+
}
|
|
133320
|
+
const contentWidth = Math.max(0, Math.round(rect.width - (bl + br)));
|
|
133321
|
+
const contentHeight = Math.max(0, Math.round(rect.height - (bt + bb)));
|
|
133322
|
+
return { contentWidth, contentHeight, rect };
|
|
133323
|
+
}
|
|
133324
|
+
function pinIframeViewport(doc, w, h) {
|
|
133325
|
+
const style = doc.createElement("style");
|
|
133326
|
+
style.setAttribute("data-sd-iframe-pin", "");
|
|
133327
|
+
style.textContent = `html, body {margin: 0 !important;padding: 0 !important;width: ${w}px !important;height: ${h}px !important;min-width: ${w}px !important;min-height: ${h}px !important;box-sizing: border-box !important;overflow: hidden !important;background-clip: border-box !important;}`;
|
|
133328
|
+
(doc.head || doc.documentElement).appendChild(style);
|
|
133329
|
+
return () => {
|
|
133330
|
+
try {
|
|
133331
|
+
style.remove();
|
|
133332
|
+
} catch {
|
|
133333
|
+
}
|
|
133334
|
+
};
|
|
133335
|
+
}
|
|
133336
|
+
async function rasterizeIframe(iframe, sessionCache, options) {
|
|
133337
|
+
const doc = await getAccessibleIframeDocument(iframe, 3);
|
|
133338
|
+
if (!doc) throw new Error("iframe document not accessible/ready");
|
|
133339
|
+
const { contentWidth, contentHeight, rect } = measureContentBox(iframe);
|
|
133340
|
+
const snap = options?.snap;
|
|
133341
|
+
if (!snap || typeof snap.toPng !== "function") {
|
|
133342
|
+
throw new Error("snapdom.toPng not available in iframe or window");
|
|
133343
|
+
}
|
|
133344
|
+
const nested = { ...options, scale: 1 };
|
|
133345
|
+
const unpin = pinIframeViewport(doc, contentWidth, contentHeight);
|
|
133346
|
+
let imgEl;
|
|
133347
|
+
try {
|
|
133348
|
+
imgEl = await snap.toPng(doc.documentElement, nested);
|
|
133349
|
+
} finally {
|
|
133350
|
+
unpin();
|
|
133351
|
+
}
|
|
133352
|
+
imgEl.style.display = "block";
|
|
133353
|
+
imgEl.style.width = `${contentWidth}px`;
|
|
133354
|
+
imgEl.style.height = `${contentHeight}px`;
|
|
133355
|
+
const wrapper = document.createElement("div");
|
|
133356
|
+
sessionCache.nodeMap.set(wrapper, iframe);
|
|
133357
|
+
inlineAllStyles(iframe, wrapper, sessionCache, options);
|
|
133358
|
+
wrapper.style.overflow = "hidden";
|
|
133359
|
+
wrapper.style.display = "block";
|
|
133360
|
+
if (!wrapper.style.width) wrapper.style.width = `${Math.round(rect.width)}px`;
|
|
133361
|
+
if (!wrapper.style.height) wrapper.style.height = `${Math.round(rect.height)}px`;
|
|
133362
|
+
wrapper.appendChild(imgEl);
|
|
133363
|
+
return wrapper;
|
|
133364
|
+
}
|
|
133365
|
+
async function deepClone(node, sessionCache, options) {
|
|
133366
|
+
if (!node) throw new Error("Invalid node");
|
|
133367
|
+
const clonedAssignedNodes = /* @__PURE__ */ new Set();
|
|
133368
|
+
let pendingSelectValue = null;
|
|
133369
|
+
let pendingTextAreaValue = null;
|
|
133370
|
+
if (node.nodeType === Node.ELEMENT_NODE) {
|
|
133371
|
+
const tag = (node.localName || node.tagName || "").toLowerCase();
|
|
133372
|
+
if (node.id === "snapdom-sandbox" || node.hasAttribute("data-snapdom-sandbox")) {
|
|
133373
|
+
return null;
|
|
133374
|
+
}
|
|
133375
|
+
if (NO_CAPTURE_TAGS.has(tag)) {
|
|
133376
|
+
return null;
|
|
133377
|
+
}
|
|
133378
|
+
}
|
|
133379
|
+
if (node.nodeType === Node.TEXT_NODE) {
|
|
133380
|
+
return node.cloneNode(true);
|
|
133381
|
+
}
|
|
133382
|
+
if (node.nodeType !== Node.ELEMENT_NODE) {
|
|
133383
|
+
return node.cloneNode(true);
|
|
133384
|
+
}
|
|
133385
|
+
if (node.getAttribute("data-capture") === "exclude") {
|
|
133386
|
+
if (options.excludeMode === "hide") {
|
|
133387
|
+
const spacer = document.createElement("div");
|
|
133388
|
+
const rect = node.getBoundingClientRect();
|
|
133389
|
+
spacer.style.cssText = `display:inline-block;width:${rect.width}px;height:${rect.height}px;visibility:hidden;`;
|
|
133390
|
+
return spacer;
|
|
133391
|
+
} else if (options.excludeMode === "remove") {
|
|
133392
|
+
return null;
|
|
133393
|
+
}
|
|
133394
|
+
}
|
|
133395
|
+
if (options.exclude && Array.isArray(options.exclude)) {
|
|
133396
|
+
for (const selector of options.exclude) {
|
|
133397
|
+
try {
|
|
133398
|
+
if (node.matches?.(selector)) {
|
|
133399
|
+
if (options.excludeMode === "hide") {
|
|
133400
|
+
const spacer = document.createElement("div");
|
|
133401
|
+
const rect = node.getBoundingClientRect();
|
|
133402
|
+
spacer.style.cssText = `display:inline-block;width:${rect.width}px;height:${rect.height}px;visibility:hidden;`;
|
|
133403
|
+
return spacer;
|
|
133404
|
+
} else if (options.excludeMode === "remove") {
|
|
133405
|
+
return null;
|
|
133406
|
+
}
|
|
133407
|
+
}
|
|
133408
|
+
} catch (err) {
|
|
133409
|
+
console.warn(`Invalid selector in exclude option: ${selector}`, err);
|
|
133410
|
+
}
|
|
133411
|
+
}
|
|
133412
|
+
}
|
|
133413
|
+
if (typeof options.filter === "function") {
|
|
133414
|
+
try {
|
|
133415
|
+
if (!options.filter(node)) {
|
|
133416
|
+
if (options.filterMode === "hide") {
|
|
133417
|
+
const spacer = document.createElement("div");
|
|
133418
|
+
const rect = node.getBoundingClientRect();
|
|
133419
|
+
spacer.style.cssText = `display:inline-block;width:${rect.width}px;height:${rect.height}px;visibility:hidden;`;
|
|
133420
|
+
return spacer;
|
|
133421
|
+
} else if (options.filterMode === "remove") {
|
|
133422
|
+
return null;
|
|
133423
|
+
}
|
|
133424
|
+
}
|
|
133425
|
+
} catch (err) {
|
|
133426
|
+
console.warn("Error in filter function:", err);
|
|
133427
|
+
}
|
|
133428
|
+
}
|
|
133429
|
+
if (node.tagName === "IFRAME") {
|
|
133430
|
+
let sameOrigin = false;
|
|
133431
|
+
try {
|
|
133432
|
+
sameOrigin = !!(node.contentDocument || node.contentWindow?.document);
|
|
133433
|
+
} catch {
|
|
133434
|
+
sameOrigin = false;
|
|
133435
|
+
}
|
|
133436
|
+
if (sameOrigin) {
|
|
133437
|
+
try {
|
|
133438
|
+
const wrapper = await rasterizeIframe(node, sessionCache, options);
|
|
133439
|
+
return wrapper;
|
|
133440
|
+
} catch (err) {
|
|
133441
|
+
console.warn("[SnapDOM] iframe rasterization failed, fallback:", err);
|
|
133442
|
+
}
|
|
133443
|
+
}
|
|
133444
|
+
if (options.placeholders) {
|
|
133445
|
+
const fallback = document.createElement("div");
|
|
133446
|
+
fallback.style.cssText = `width:${node.offsetWidth}px;height:${node.offsetHeight}px;background-image:repeating-linear-gradient(45deg,#ddd,#ddd 5px,#f9f9f9 5px,#f9f9f9 10px);display:flex;align-items:center;justify-content:center;font-size:12px;color:#555;border:1px solid #aaa;`;
|
|
133447
|
+
inlineAllStyles(node, fallback, sessionCache, options);
|
|
133448
|
+
return fallback;
|
|
133449
|
+
} else {
|
|
133450
|
+
const rect = node.getBoundingClientRect();
|
|
133451
|
+
const spacer = document.createElement("div");
|
|
133452
|
+
spacer.style.cssText = `display:inline-block;width:${rect.width}px;height:${rect.height}px;visibility:hidden;`;
|
|
133453
|
+
inlineAllStyles(node, spacer, sessionCache, options);
|
|
133454
|
+
return spacer;
|
|
133455
|
+
}
|
|
133456
|
+
}
|
|
133457
|
+
if (node.getAttribute("data-capture") === "placeholder") {
|
|
133458
|
+
const clone2 = node.cloneNode(false);
|
|
133459
|
+
sessionCache.nodeMap.set(clone2, node);
|
|
133460
|
+
inlineAllStyles(node, clone2, sessionCache, options);
|
|
133461
|
+
const placeholder = document.createElement("div");
|
|
133462
|
+
placeholder.textContent = node.getAttribute("data-placeholder-text") || "";
|
|
133463
|
+
placeholder.style.cssText = "color:#666;font-size:12px;text-align:center;line-height:1.4;padding:0.5em;box-sizing:border-box;";
|
|
133464
|
+
clone2.appendChild(placeholder);
|
|
133465
|
+
return clone2;
|
|
133466
|
+
}
|
|
133467
|
+
if (node.tagName === "CANVAS") {
|
|
133468
|
+
const dataURL = node.toDataURL();
|
|
133469
|
+
const img = document.createElement("img");
|
|
133470
|
+
img.src = dataURL;
|
|
133471
|
+
img.width = node.width;
|
|
133472
|
+
img.height = node.height;
|
|
133473
|
+
sessionCache.nodeMap.set(img, node);
|
|
133474
|
+
inlineAllStyles(node, img, sessionCache, options);
|
|
133475
|
+
return img;
|
|
133476
|
+
}
|
|
133477
|
+
let clone;
|
|
133478
|
+
try {
|
|
133479
|
+
clone = node.cloneNode(false);
|
|
133480
|
+
resolveCSSVars(node, clone);
|
|
133481
|
+
sessionCache.nodeMap.set(clone, node);
|
|
133482
|
+
if (node.tagName === "IMG") {
|
|
133483
|
+
freezeImgSrcset(node, clone);
|
|
133484
|
+
try {
|
|
133485
|
+
const rect = node.getBoundingClientRect();
|
|
133486
|
+
let w = Math.round(rect.width || 0);
|
|
133487
|
+
let h = Math.round(rect.height || 0);
|
|
133488
|
+
if (!w || !h) {
|
|
133489
|
+
const computed = window.getComputedStyle(node);
|
|
133490
|
+
const cssW = parseFloat(computed.width) || 0;
|
|
133491
|
+
const cssH = parseFloat(computed.height) || 0;
|
|
133492
|
+
const attrW = parseInt(node.getAttribute("width") || "", 10) || 0;
|
|
133493
|
+
const attrH = parseInt(node.getAttribute("height") || "", 10) || 0;
|
|
133494
|
+
const propW = node.width || node.naturalWidth || 0;
|
|
133495
|
+
const propH = node.height || node.naturalHeight || 0;
|
|
133496
|
+
w = Math.round(w || cssW || attrW || propW || 0);
|
|
133497
|
+
h = Math.round(h || cssH || attrH || propH || 0);
|
|
133498
|
+
}
|
|
133499
|
+
if (w) clone.dataset.snapdomWidth = String(w);
|
|
133500
|
+
if (h) clone.dataset.snapdomHeight = String(h);
|
|
133501
|
+
} catch {
|
|
133502
|
+
}
|
|
133503
|
+
}
|
|
133504
|
+
} catch (err) {
|
|
133505
|
+
console.error("[Snapdom] Failed to clone node:", node, err);
|
|
133506
|
+
throw err;
|
|
133507
|
+
}
|
|
133508
|
+
if (node instanceof HTMLTextAreaElement) {
|
|
133509
|
+
const rect = node.getBoundingClientRect();
|
|
133510
|
+
clone.style.width = `${rect.width}px`;
|
|
133511
|
+
clone.style.height = `${rect.height}px`;
|
|
133512
|
+
}
|
|
133513
|
+
if (node instanceof HTMLInputElement) {
|
|
133514
|
+
clone.value = node.value;
|
|
133515
|
+
clone.setAttribute("value", node.value);
|
|
133516
|
+
if (node.checked !== void 0) {
|
|
133517
|
+
clone.checked = node.checked;
|
|
133518
|
+
if (node.checked) clone.setAttribute("checked", "");
|
|
133519
|
+
if (node.indeterminate) clone.indeterminate = node.indeterminate;
|
|
133520
|
+
}
|
|
133521
|
+
}
|
|
133522
|
+
if (node instanceof HTMLSelectElement) {
|
|
133523
|
+
pendingSelectValue = node.value;
|
|
133524
|
+
}
|
|
133525
|
+
if (node instanceof HTMLTextAreaElement) {
|
|
133526
|
+
pendingTextAreaValue = node.value;
|
|
133527
|
+
}
|
|
133528
|
+
inlineAllStyles(node, clone, sessionCache, options);
|
|
133529
|
+
if (node.shadowRoot) {
|
|
133530
|
+
let callback2 = function(child, resolve) {
|
|
133531
|
+
if (child.nodeType === Node.ELEMENT_NODE && child.tagName === "STYLE") {
|
|
133532
|
+
return resolve(null);
|
|
133533
|
+
} else {
|
|
133534
|
+
deepClone(child, sessionCache, options).then((clonedChild) => {
|
|
133535
|
+
resolve(clonedChild || null);
|
|
133536
|
+
}).catch(() => {
|
|
133537
|
+
resolve(null);
|
|
133538
|
+
});
|
|
133539
|
+
}
|
|
133540
|
+
};
|
|
133541
|
+
try {
|
|
133542
|
+
const slots = node.shadowRoot.querySelectorAll("slot");
|
|
133543
|
+
for (const s of slots) {
|
|
133544
|
+
let assigned = [];
|
|
133545
|
+
try {
|
|
133546
|
+
assigned = s.assignedNodes?.({ flatten: true }) || s.assignedNodes?.() || [];
|
|
133547
|
+
} catch {
|
|
133548
|
+
assigned = s.assignedNodes?.() || [];
|
|
133549
|
+
}
|
|
133550
|
+
for (const an of assigned) clonedAssignedNodes.add(an);
|
|
133551
|
+
}
|
|
133552
|
+
} catch {
|
|
133553
|
+
}
|
|
133554
|
+
const scopeId = nextShadowScopeId(sessionCache);
|
|
133555
|
+
const scopeSelector = `[data-sd="${scopeId}"]`;
|
|
133556
|
+
try {
|
|
133557
|
+
clone.setAttribute("data-sd", scopeId);
|
|
133558
|
+
} catch {
|
|
133559
|
+
}
|
|
133560
|
+
const rawCSS = extractShadowCSS(node.shadowRoot);
|
|
133561
|
+
const rewritten = rewriteShadowCSS(rawCSS, scopeSelector);
|
|
133562
|
+
const neededVars = collectCustomPropsFromCSS(rawCSS);
|
|
133563
|
+
const seed = buildSeedCustomPropsRule(node, neededVars, scopeSelector);
|
|
133564
|
+
injectScopedStyle(clone, seed + rewritten, scopeId);
|
|
133565
|
+
const shadowFrag = document.createDocumentFragment();
|
|
133566
|
+
const cloneList2 = await idleCallback(Array.from(node.shadowRoot.childNodes), callback2, options.fast);
|
|
133567
|
+
shadowFrag.append(...cloneList2.filter((clonedChild) => !!clonedChild));
|
|
133568
|
+
clone.appendChild(shadowFrag);
|
|
133569
|
+
}
|
|
133570
|
+
if (node.tagName === "SLOT") {
|
|
133571
|
+
let callback2 = function(child, resolve) {
|
|
133572
|
+
deepClone(child, sessionCache, options).then((clonedChild) => {
|
|
133573
|
+
if (clonedChild) {
|
|
133574
|
+
markSlottedSubtree(clonedChild);
|
|
133575
|
+
}
|
|
133576
|
+
resolve(clonedChild || null);
|
|
133577
|
+
}).catch(() => {
|
|
133578
|
+
resolve(null);
|
|
133579
|
+
});
|
|
133580
|
+
};
|
|
133581
|
+
const assigned = node.assignedNodes?.({ flatten: true }) || [];
|
|
133582
|
+
const nodesToClone = assigned.length > 0 ? assigned : Array.from(node.childNodes);
|
|
133583
|
+
const fragment = document.createDocumentFragment();
|
|
133584
|
+
const cloneList2 = await idleCallback(Array.from(nodesToClone), callback2, options.fast);
|
|
133585
|
+
fragment.append(...cloneList2.filter((clonedChild) => !!clonedChild));
|
|
133586
|
+
return fragment;
|
|
133587
|
+
}
|
|
133588
|
+
function callback(child, resolve) {
|
|
133589
|
+
if (clonedAssignedNodes.has(child)) return resolve(null);
|
|
133590
|
+
deepClone(child, sessionCache, options).then((clonedChild) => {
|
|
133591
|
+
resolve(clonedChild || null);
|
|
133592
|
+
}).catch(() => {
|
|
133593
|
+
resolve(null);
|
|
133594
|
+
});
|
|
133595
|
+
}
|
|
133596
|
+
const cloneList = await idleCallback(Array.from(node.childNodes), callback, options.fast);
|
|
133597
|
+
clone.append(...cloneList.filter((clonedChild) => !!clonedChild));
|
|
133598
|
+
if (pendingSelectValue !== null && clone instanceof HTMLSelectElement) {
|
|
133599
|
+
clone.value = pendingSelectValue;
|
|
133600
|
+
for (const opt of clone.options) {
|
|
133601
|
+
if (opt.value === pendingSelectValue) {
|
|
133602
|
+
opt.setAttribute("selected", "");
|
|
133603
|
+
} else {
|
|
133604
|
+
opt.removeAttribute("selected");
|
|
133605
|
+
}
|
|
133606
|
+
}
|
|
133607
|
+
}
|
|
133608
|
+
if (pendingTextAreaValue !== null && clone instanceof HTMLTextAreaElement) {
|
|
133609
|
+
clone.textContent = pendingTextAreaValue;
|
|
133610
|
+
}
|
|
133611
|
+
return clone;
|
|
133612
|
+
}
|
|
133613
|
+
|
|
133614
|
+
// src/modules/iconFonts.js
|
|
133615
|
+
var defaultIconFonts = [
|
|
133616
|
+
// /uicons/i,
|
|
133617
|
+
/font\s*awesome/i,
|
|
133618
|
+
/material\s*icons/i,
|
|
133619
|
+
/ionicons/i,
|
|
133620
|
+
/glyphicons/i,
|
|
133621
|
+
/feather/i,
|
|
133622
|
+
/bootstrap\s*icons/i,
|
|
133623
|
+
/remix\s*icons/i,
|
|
133624
|
+
/heroicons/i,
|
|
133625
|
+
/layui/i,
|
|
133626
|
+
/lucide/i
|
|
133627
|
+
];
|
|
133628
|
+
var userIconFonts = [];
|
|
133629
|
+
function extendIconFonts(fonts) {
|
|
133630
|
+
const list = Array.isArray(fonts) ? fonts : [fonts];
|
|
133631
|
+
for (const f of list) {
|
|
133632
|
+
if (f instanceof RegExp) {
|
|
133633
|
+
userIconFonts.push(f);
|
|
133634
|
+
} else if (typeof f === "string") {
|
|
133635
|
+
userIconFonts.push(new RegExp(f, "i"));
|
|
133636
|
+
} else {
|
|
133637
|
+
console.warn("[snapdom] Ignored invalid iconFont value:", f);
|
|
133638
|
+
}
|
|
133639
|
+
}
|
|
133640
|
+
}
|
|
133641
|
+
function isIconFont2(input) {
|
|
133642
|
+
const text = typeof input === "string" ? input : "";
|
|
133643
|
+
const candidates = [...defaultIconFonts, ...userIconFonts];
|
|
133644
|
+
for (const rx of candidates) {
|
|
133645
|
+
if (rx instanceof RegExp && rx.test(text)) return true;
|
|
133646
|
+
}
|
|
133647
|
+
if (/icon/i.test(text) || /glyph/i.test(text) || /symbols/i.test(text) || /feather/i.test(text) || /fontawesome/i.test(text)) return true;
|
|
133648
|
+
return false;
|
|
133649
|
+
}
|
|
133650
|
+
|
|
133651
|
+
// src/modules/fonts.js
|
|
133652
|
+
async function iconToImage(unicodeChar, fontFamily, fontWeight, fontSize = 32, color = "#000") {
|
|
133653
|
+
fontFamily = fontFamily.replace(/^['"]+|['"]+$/g, "");
|
|
133654
|
+
const dpr = window.devicePixelRatio || 1;
|
|
133655
|
+
try {
|
|
133656
|
+
await document.fonts.ready;
|
|
133657
|
+
} catch {
|
|
133658
|
+
}
|
|
133659
|
+
const span = document.createElement("span");
|
|
133660
|
+
span.textContent = unicodeChar;
|
|
133661
|
+
span.style.position = "absolute";
|
|
133662
|
+
span.style.visibility = "hidden";
|
|
133663
|
+
span.style.fontFamily = `"${fontFamily}"`;
|
|
133664
|
+
span.style.fontWeight = fontWeight || "normal";
|
|
133665
|
+
span.style.fontSize = `${fontSize}px`;
|
|
133666
|
+
span.style.lineHeight = "1";
|
|
133667
|
+
span.style.whiteSpace = "nowrap";
|
|
133668
|
+
span.style.padding = "0";
|
|
133669
|
+
span.style.margin = "0";
|
|
133670
|
+
document.body.appendChild(span);
|
|
133671
|
+
const rect = span.getBoundingClientRect();
|
|
133672
|
+
const width = Math.ceil(rect.width);
|
|
133673
|
+
const height = Math.ceil(rect.height);
|
|
133674
|
+
document.body.removeChild(span);
|
|
133675
|
+
const canvas = document.createElement("canvas");
|
|
133676
|
+
canvas.width = Math.max(1, width * dpr);
|
|
133677
|
+
canvas.height = Math.max(1, height * dpr);
|
|
133678
|
+
const ctx = canvas.getContext("2d");
|
|
133679
|
+
ctx.scale(dpr, dpr);
|
|
133680
|
+
ctx.font = fontWeight ? `${fontWeight} ${fontSize}px "${fontFamily}"` : `${fontSize}px "${fontFamily}"`;
|
|
133681
|
+
ctx.textAlign = "left";
|
|
133682
|
+
ctx.textBaseline = "top";
|
|
133683
|
+
ctx.fillStyle = color;
|
|
133684
|
+
ctx.fillText(unicodeChar, 0, 0);
|
|
133685
|
+
return {
|
|
133686
|
+
dataUrl: canvas.toDataURL(),
|
|
133687
|
+
width,
|
|
133688
|
+
height
|
|
133689
|
+
};
|
|
133690
|
+
}
|
|
133691
|
+
var GENERIC_FAMILIES = /* @__PURE__ */ new Set([
|
|
133692
|
+
"serif",
|
|
133693
|
+
"sans-serif",
|
|
133694
|
+
"monospace",
|
|
133695
|
+
"cursive",
|
|
133696
|
+
"fantasy",
|
|
133697
|
+
"system-ui",
|
|
133698
|
+
"emoji",
|
|
133699
|
+
"math",
|
|
133700
|
+
"fangsong",
|
|
133701
|
+
"ui-serif",
|
|
133702
|
+
"ui-sans-serif",
|
|
133703
|
+
"ui-monospace",
|
|
133704
|
+
"ui-rounded"
|
|
133705
|
+
]);
|
|
133706
|
+
function pickPrimaryFamily(familyList) {
|
|
133707
|
+
if (!familyList) return "";
|
|
133708
|
+
for (let raw of familyList.split(",")) {
|
|
133709
|
+
let f = raw.trim().replace(/^['"]+|['"]+$/g, "");
|
|
133710
|
+
if (!f) continue;
|
|
133711
|
+
if (!GENERIC_FAMILIES.has(f.toLowerCase())) return f;
|
|
133712
|
+
}
|
|
133713
|
+
return "";
|
|
133714
|
+
}
|
|
133715
|
+
function normWeight(w) {
|
|
133716
|
+
const t = String(w ?? "400").trim().toLowerCase();
|
|
133717
|
+
if (t === "normal") return 400;
|
|
133718
|
+
if (t === "bold") return 700;
|
|
133719
|
+
const n = parseInt(t, 10);
|
|
133720
|
+
return Number.isFinite(n) ? Math.min(900, Math.max(100, n)) : 400;
|
|
133721
|
+
}
|
|
133722
|
+
function normStyle(s) {
|
|
133723
|
+
const t = String(s ?? "normal").trim().toLowerCase();
|
|
133724
|
+
if (t.startsWith("italic")) return "italic";
|
|
133725
|
+
if (t.startsWith("oblique")) return "oblique";
|
|
133726
|
+
return "normal";
|
|
133727
|
+
}
|
|
133728
|
+
function normStretchPct(st) {
|
|
133729
|
+
const m = String(st ?? "100%").match(/(\d+(?:\.\d+)?)\s*%/);
|
|
133730
|
+
return m ? Math.max(50, Math.min(200, parseFloat(m[1]))) : 100;
|
|
133731
|
+
}
|
|
133732
|
+
function parseWeightSpec(spec) {
|
|
133733
|
+
const s = String(spec || "400").trim();
|
|
133734
|
+
const m = s.match(/^(\d{2,3})\s+(\d{2,3})$/);
|
|
133735
|
+
if (m) {
|
|
133736
|
+
const a = normWeight(m[1]), b = normWeight(m[2]);
|
|
133737
|
+
return { min: Math.min(a, b), max: Math.max(a, b) };
|
|
133738
|
+
}
|
|
133739
|
+
const v = normWeight(s);
|
|
133740
|
+
return { min: v, max: v };
|
|
133741
|
+
}
|
|
133742
|
+
function parseStyleSpec(spec) {
|
|
133743
|
+
const t = String(spec || "normal").trim().toLowerCase();
|
|
133744
|
+
if (t === "italic") return { kind: "italic" };
|
|
133745
|
+
if (t.startsWith("oblique")) return { kind: "oblique" };
|
|
133746
|
+
return { kind: "normal" };
|
|
133747
|
+
}
|
|
133748
|
+
function parseStretchSpec(spec) {
|
|
133749
|
+
const s = String(spec || "100%").trim();
|
|
133750
|
+
const mm = s.match(/(\d+(?:\.\d+)?)\s*%\s+(\d+(?:\.\d+)?)\s*%/);
|
|
133751
|
+
if (mm) {
|
|
133752
|
+
const a = parseFloat(mm[1]), b = parseFloat(mm[2]);
|
|
133753
|
+
return { min: Math.min(a, b), max: Math.max(a, b) };
|
|
133754
|
+
}
|
|
133755
|
+
const m = s.match(/(\d+(?:\.\d+)?)\s*%/);
|
|
133756
|
+
const v = m ? parseFloat(m[1]) : 100;
|
|
133757
|
+
return { min: v, max: v };
|
|
133758
|
+
}
|
|
133759
|
+
function isLikelyFontStylesheet(href, requiredFamilies) {
|
|
133760
|
+
if (!href) return false;
|
|
133761
|
+
try {
|
|
133762
|
+
const u = new URL(href, location.href);
|
|
133763
|
+
const sameOrigin = u.origin === location.origin;
|
|
133764
|
+
if (sameOrigin) return true;
|
|
133765
|
+
const host = u.host.toLowerCase();
|
|
133766
|
+
const FONT_HOSTS = [
|
|
133767
|
+
"fonts.googleapis.com",
|
|
133768
|
+
"fonts.gstatic.com",
|
|
133769
|
+
"use.typekit.net",
|
|
133770
|
+
"p.typekit.net",
|
|
133771
|
+
"kit.fontawesome.com",
|
|
133772
|
+
"use.fontawesome.com"
|
|
133773
|
+
];
|
|
133774
|
+
if (FONT_HOSTS.some((h) => host.endsWith(h))) return true;
|
|
133775
|
+
const path = (u.pathname + u.search).toLowerCase();
|
|
133776
|
+
if (/\bfont(s)?\b/.test(path) || /\.woff2?(\b|$)/.test(path)) return true;
|
|
133777
|
+
for (const fam of requiredFamilies) {
|
|
133778
|
+
const tokenA = fam.toLowerCase().replace(/\s+/g, "+");
|
|
133779
|
+
const tokenB = fam.toLowerCase().replace(/\s+/g, "-");
|
|
133780
|
+
if (path.includes(tokenA) || path.includes(tokenB)) return true;
|
|
133781
|
+
}
|
|
133782
|
+
return false;
|
|
133783
|
+
} catch {
|
|
133784
|
+
return false;
|
|
133785
|
+
}
|
|
133786
|
+
}
|
|
133787
|
+
function familiesFromRequired(required) {
|
|
133788
|
+
const out = /* @__PURE__ */ new Set();
|
|
133789
|
+
for (const k of required || []) {
|
|
133790
|
+
const fam = String(k).split("__")[0]?.trim();
|
|
133791
|
+
if (fam) out.add(fam);
|
|
133792
|
+
}
|
|
133793
|
+
return out;
|
|
133794
|
+
}
|
|
133795
|
+
function rewriteRelativeUrls(cssText, baseHref) {
|
|
133796
|
+
if (!cssText) return cssText;
|
|
133797
|
+
return cssText.replace(
|
|
133798
|
+
/url\(\s*(['"]?)([^)'"]+)\1\s*\)/g,
|
|
133799
|
+
(m, q, u) => {
|
|
133800
|
+
const src = (u || "").trim();
|
|
133801
|
+
if (!src || /^data:|^blob:|^https?:|^file:|^about:/i.test(src)) return m;
|
|
133802
|
+
let abs = src;
|
|
133803
|
+
try {
|
|
133804
|
+
abs = new URL(src, baseHref || location.href).href;
|
|
133805
|
+
} catch {
|
|
133806
|
+
}
|
|
133807
|
+
return `url("${abs}")`;
|
|
133808
|
+
}
|
|
133809
|
+
);
|
|
133810
|
+
}
|
|
133811
|
+
var IMPORT_ANY_RE = /@import\s+(?:url\(\s*(['"]?)([^)"']+)\1\s*\)|(['"])([^"']+)\3)([^;]*);/g;
|
|
133812
|
+
var MAX_IMPORT_DEPTH = 4;
|
|
133813
|
+
async function inlineImportsAndRewrite(cssText, ownerHref, useProxy) {
|
|
133814
|
+
if (!cssText) return cssText;
|
|
133815
|
+
const visited = /* @__PURE__ */ new Set();
|
|
133816
|
+
function normalizeUrl(u, base) {
|
|
133817
|
+
try {
|
|
133818
|
+
return new URL(u, base || location.href).href;
|
|
133819
|
+
} catch {
|
|
133820
|
+
return u;
|
|
133821
|
+
}
|
|
133822
|
+
}
|
|
133823
|
+
async function resolveOnce(text, baseHref, depth = 0) {
|
|
133824
|
+
if (depth > MAX_IMPORT_DEPTH) {
|
|
133825
|
+
console.warn(`[snapDOM] @import depth exceeded (${MAX_IMPORT_DEPTH}) at ${baseHref}`);
|
|
133826
|
+
return text;
|
|
133827
|
+
}
|
|
133828
|
+
let out = "";
|
|
133829
|
+
let last = 0;
|
|
133830
|
+
let m;
|
|
133831
|
+
while (m = IMPORT_ANY_RE.exec(text)) {
|
|
133832
|
+
out += text.slice(last, m.index);
|
|
133833
|
+
last = IMPORT_ANY_RE.lastIndex;
|
|
133834
|
+
const rawUrl = (m[2] || m[4] || "").trim();
|
|
133835
|
+
const absUrl = normalizeUrl(rawUrl, baseHref);
|
|
133836
|
+
if (visited.has(absUrl)) {
|
|
133837
|
+
console.warn(`[snapDOM] Skipping circular @import: ${absUrl}`);
|
|
133838
|
+
continue;
|
|
133839
|
+
}
|
|
133840
|
+
visited.add(absUrl);
|
|
133841
|
+
let imported = "";
|
|
133842
|
+
try {
|
|
133843
|
+
const r = await snapFetch(absUrl, { as: "text", useProxy, silent: true });
|
|
133844
|
+
if (r.ok && typeof r.data === "string") imported = r.data;
|
|
133845
|
+
} catch {
|
|
133846
|
+
}
|
|
133847
|
+
if (imported) {
|
|
133848
|
+
imported = rewriteRelativeUrls(imported, absUrl);
|
|
133849
|
+
imported = await resolveOnce(imported, absUrl, depth + 1);
|
|
133850
|
+
out += `
|
|
133851
|
+
/* inlined: ${absUrl} */
|
|
133852
|
+
${imported}
|
|
133853
|
+
`;
|
|
133854
|
+
} else {
|
|
133855
|
+
out += m[0];
|
|
133856
|
+
}
|
|
133857
|
+
}
|
|
133858
|
+
out += text.slice(last);
|
|
133859
|
+
return out;
|
|
133860
|
+
}
|
|
133861
|
+
let rewritten = rewriteRelativeUrls(cssText, ownerHref || location.href);
|
|
133862
|
+
rewritten = await resolveOnce(rewritten, ownerHref || location.href, 0);
|
|
133863
|
+
return rewritten;
|
|
133864
|
+
}
|
|
133865
|
+
var URL_RE = /url\((["']?)([^"')]+)\1\)/g;
|
|
133866
|
+
var FACE_RE = /@font-face[^{}]*\{[^}]*\}/g;
|
|
133867
|
+
function parseUnicodeRange(ur) {
|
|
133868
|
+
if (!ur) return [];
|
|
133869
|
+
const ranges = [];
|
|
133870
|
+
const parts = ur.split(",").map((s) => s.trim()).filter(Boolean);
|
|
133871
|
+
for (const p of parts) {
|
|
133872
|
+
const m = p.match(/^U\+([0-9A-Fa-f?]+)(?:-([0-9A-Fa-f?]+))?$/);
|
|
133873
|
+
if (!m) continue;
|
|
133874
|
+
const a = m[1], b = m[2];
|
|
133875
|
+
const expand = (hex) => {
|
|
133876
|
+
if (!hex.includes("?")) return parseInt(hex, 16);
|
|
133877
|
+
const min = parseInt(hex.replace(/\?/g, "0"), 16);
|
|
133878
|
+
const max = parseInt(hex.replace(/\?/g, "F"), 16);
|
|
133879
|
+
return [min, max];
|
|
133880
|
+
};
|
|
133881
|
+
if (b) {
|
|
133882
|
+
const A = expand(a), B = expand(b);
|
|
133883
|
+
const min = Array.isArray(A) ? A[0] : A;
|
|
133884
|
+
const max = Array.isArray(B) ? B[1] : B;
|
|
133885
|
+
ranges.push([Math.min(min, max), Math.max(min, max)]);
|
|
133886
|
+
} else {
|
|
133887
|
+
const X = expand(a);
|
|
133888
|
+
if (Array.isArray(X)) ranges.push([X[0], X[1]]);
|
|
133889
|
+
else ranges.push([X, X]);
|
|
133890
|
+
}
|
|
133891
|
+
}
|
|
133892
|
+
return ranges;
|
|
133893
|
+
}
|
|
133894
|
+
function unicodeIntersects(used, ranges) {
|
|
133895
|
+
if (!ranges.length) return true;
|
|
133896
|
+
if (!used || used.size === 0) return true;
|
|
133897
|
+
for (const cp of used) {
|
|
133898
|
+
for (const [a, b] of ranges) if (cp >= a && cp <= b) return true;
|
|
133899
|
+
}
|
|
133900
|
+
return false;
|
|
133901
|
+
}
|
|
133902
|
+
function extractSrcUrls(srcValue, baseHref) {
|
|
133903
|
+
const urls = [];
|
|
133904
|
+
if (!srcValue) return urls;
|
|
133905
|
+
for (const m of srcValue.matchAll(URL_RE)) {
|
|
133906
|
+
let u = (m[2] || "").trim();
|
|
133907
|
+
if (!u || u.startsWith("data:")) continue;
|
|
133908
|
+
if (!/^https?:/i.test(u)) {
|
|
133909
|
+
try {
|
|
133910
|
+
u = new URL(u, baseHref || location.href).href;
|
|
133911
|
+
} catch {
|
|
133912
|
+
}
|
|
133913
|
+
}
|
|
133914
|
+
urls.push(u);
|
|
133915
|
+
}
|
|
133916
|
+
return urls;
|
|
133917
|
+
}
|
|
133918
|
+
async function inlineUrlsInCssBlock(cssBlock, baseHref, useProxy = "") {
|
|
133919
|
+
let out = cssBlock;
|
|
133920
|
+
for (const m of cssBlock.matchAll(URL_RE)) {
|
|
133921
|
+
const raw = extractURL(m[0]);
|
|
133922
|
+
if (!raw) continue;
|
|
133923
|
+
let abs = raw;
|
|
133924
|
+
if (!abs.startsWith("http") && !abs.startsWith("data:")) {
|
|
133925
|
+
try {
|
|
133926
|
+
abs = new URL(abs, baseHref || location.href).href;
|
|
133927
|
+
} catch {
|
|
133928
|
+
}
|
|
133929
|
+
}
|
|
133930
|
+
if (isIconFont2(abs)) continue;
|
|
133931
|
+
if (cache.resource?.has(abs)) {
|
|
133932
|
+
cache.font?.add(abs);
|
|
133933
|
+
out = out.replace(m[0], `url(${cache.resource.get(abs)})`);
|
|
133934
|
+
continue;
|
|
133935
|
+
}
|
|
133936
|
+
if (cache.font?.has(abs)) continue;
|
|
133937
|
+
try {
|
|
133938
|
+
const r = await snapFetch(abs, { as: "dataURL", useProxy, silent: true });
|
|
133939
|
+
if (r.ok && typeof r.data === "string") {
|
|
133940
|
+
const b64 = r.data;
|
|
133941
|
+
cache.resource?.set(abs, b64);
|
|
133942
|
+
cache.font?.add(abs);
|
|
133943
|
+
out = out.replace(m[0], `url(${b64})`);
|
|
133944
|
+
}
|
|
133945
|
+
} catch {
|
|
133946
|
+
console.warn("[snapDOM] Failed to fetch font resource:", abs);
|
|
133947
|
+
}
|
|
133948
|
+
}
|
|
133949
|
+
return out;
|
|
133950
|
+
}
|
|
133951
|
+
function subsetFromRanges(ranges) {
|
|
133952
|
+
if (!ranges.length) return null;
|
|
133953
|
+
const hit = (a, b) => ranges.some(([x, y]) => !(y < a || x > b));
|
|
133954
|
+
const latin = hit(0, 255) || hit(305, 305);
|
|
133955
|
+
const latinExt = hit(256, 591) || hit(7680, 7935);
|
|
133956
|
+
const greek = hit(880, 1023);
|
|
133957
|
+
const cyr = hit(1024, 1279);
|
|
133958
|
+
const viet = hit(7840, 7929) || hit(258, 259) || hit(416, 417) || hit(431, 432);
|
|
133959
|
+
if (viet) return "vietnamese";
|
|
133960
|
+
if (cyr) return "cyrillic";
|
|
133961
|
+
if (greek) return "greek";
|
|
133962
|
+
if (latinExt) return "latin-ext";
|
|
133963
|
+
if (latin) return "latin";
|
|
133964
|
+
return null;
|
|
133965
|
+
}
|
|
133966
|
+
function buildSimpleExcluder(ex = {}) {
|
|
133967
|
+
const famSet = new Set((ex.families || []).map((s) => String(s).toLowerCase()));
|
|
133968
|
+
const domSet = new Set((ex.domains || []).map((s) => String(s).toLowerCase()));
|
|
133969
|
+
const subSet = new Set((ex.subsets || []).map((s) => String(s).toLowerCase()));
|
|
133970
|
+
return (meta, parsedRanges) => {
|
|
133971
|
+
if (famSet.size && famSet.has(meta.family.toLowerCase())) return true;
|
|
133972
|
+
if (domSet.size) {
|
|
133973
|
+
for (const u of meta.srcUrls) {
|
|
133974
|
+
try {
|
|
133975
|
+
if (domSet.has(new URL(u).host.toLowerCase())) return true;
|
|
133976
|
+
} catch {
|
|
133977
|
+
}
|
|
133978
|
+
}
|
|
133979
|
+
}
|
|
133980
|
+
if (subSet.size) {
|
|
133981
|
+
const label = subsetFromRanges(parsedRanges);
|
|
133982
|
+
if (label && subSet.has(label)) return true;
|
|
133983
|
+
}
|
|
133984
|
+
return false;
|
|
133985
|
+
};
|
|
133986
|
+
}
|
|
133987
|
+
function dedupeFontFaces(cssText) {
|
|
133988
|
+
if (!cssText) return cssText;
|
|
133989
|
+
const FACE_RE_G = /@font-face[^{}]*\{[^}]*\}/gi;
|
|
133990
|
+
const seen = /* @__PURE__ */ new Set();
|
|
133991
|
+
const out = [];
|
|
133992
|
+
for (const block of cssText.match(FACE_RE_G) || []) {
|
|
133993
|
+
const familyRaw = block.match(/font-family:\s*([^;]+);/i)?.[1] || "";
|
|
133994
|
+
const family = pickPrimaryFamily(familyRaw);
|
|
133995
|
+
const weightSpec = (block.match(/font-weight:\s*([^;]+);/i)?.[1] || "400").trim();
|
|
133996
|
+
const styleSpec = (block.match(/font-style:\s*([^;]+);/i)?.[1] || "normal").trim();
|
|
133997
|
+
const stretchSpec = (block.match(/font-stretch:\s*([^;]+);/i)?.[1] || "100%").trim();
|
|
133998
|
+
const urange = (block.match(/unicode-range:\s*([^;]+);/i)?.[1] || "").trim();
|
|
133999
|
+
const srcRaw = (block.match(/src\s*:\s*([^;]+);/i)?.[1] || "").trim();
|
|
134000
|
+
const urls = extractSrcUrls(srcRaw, location.href);
|
|
134001
|
+
const srcPart = urls.length ? urls.map((u) => String(u).toLowerCase()).sort().join("|") : srcRaw.toLowerCase();
|
|
134002
|
+
const key = [
|
|
134003
|
+
String(family || "").toLowerCase(),
|
|
134004
|
+
weightSpec,
|
|
134005
|
+
styleSpec,
|
|
134006
|
+
stretchSpec,
|
|
134007
|
+
urange.toLowerCase(),
|
|
134008
|
+
srcPart
|
|
134009
|
+
].join("|");
|
|
134010
|
+
if (!seen.has(key)) {
|
|
134011
|
+
seen.add(key);
|
|
134012
|
+
out.push(block);
|
|
134013
|
+
}
|
|
134014
|
+
}
|
|
134015
|
+
if (out.length === 0) return cssText;
|
|
134016
|
+
let i = 0;
|
|
134017
|
+
return cssText.replace(FACE_RE_G, () => out[i++] || "");
|
|
134018
|
+
}
|
|
134019
|
+
function buildFontsCacheKey(required, exclude, localFonts, useProxy) {
|
|
134020
|
+
const req = Array.from(required || []).sort().join("|");
|
|
134021
|
+
const ex = exclude ? JSON.stringify({
|
|
134022
|
+
families: (exclude.families || []).map((s) => String(s).toLowerCase()).sort(),
|
|
134023
|
+
domains: (exclude.domains || []).map((s) => String(s).toLowerCase()).sort(),
|
|
134024
|
+
subsets: (exclude.subsets || []).map((s) => String(s).toLowerCase()).sort()
|
|
134025
|
+
}) : "";
|
|
134026
|
+
const lf = (localFonts || []).map((f) => `${(f.family || "").toLowerCase()}::${f.weight || "normal"}::${f.style || "normal"}::${f.src || ""}`).sort().join("|");
|
|
134027
|
+
const px = useProxy || "";
|
|
134028
|
+
return `fonts-embed-css::req=${req}::ex=${ex}::lf=${lf}::px=${px}`;
|
|
134029
|
+
}
|
|
134030
|
+
async function collectFacesFromSheet(sheet, baseHref, emitFace, ctx) {
|
|
134031
|
+
let rules;
|
|
134032
|
+
try {
|
|
134033
|
+
rules = sheet.cssRules || [];
|
|
134034
|
+
} catch {
|
|
134035
|
+
return;
|
|
134036
|
+
}
|
|
134037
|
+
const normalizeUrl = (u, base) => {
|
|
134038
|
+
try {
|
|
134039
|
+
return new URL(u, base || location.href).href;
|
|
134040
|
+
} catch {
|
|
134041
|
+
return u;
|
|
134042
|
+
}
|
|
134043
|
+
};
|
|
134044
|
+
for (const rule of rules) {
|
|
134045
|
+
if (rule.type === CSSRule.IMPORT_RULE && rule.styleSheet) {
|
|
134046
|
+
const childHref = rule.href ? normalizeUrl(rule.href, baseHref) : baseHref;
|
|
134047
|
+
if (ctx.depth >= MAX_IMPORT_DEPTH) {
|
|
134048
|
+
console.warn(`[snapDOM] CSSOM import depth exceeded (${MAX_IMPORT_DEPTH}) at ${childHref}`);
|
|
134049
|
+
continue;
|
|
134050
|
+
}
|
|
134051
|
+
if (childHref && ctx.visitedSheets.has(childHref)) {
|
|
134052
|
+
console.warn(`[snapDOM] Skipping circular CSSOM import: ${childHref}`);
|
|
134053
|
+
continue;
|
|
134054
|
+
}
|
|
134055
|
+
if (childHref) ctx.visitedSheets.add(childHref);
|
|
134056
|
+
const nextCtx = { ...ctx, depth: (ctx.depth || 0) + 1 };
|
|
134057
|
+
await collectFacesFromSheet(rule.styleSheet, childHref, emitFace, nextCtx);
|
|
134058
|
+
continue;
|
|
134059
|
+
}
|
|
134060
|
+
if (rule.type === CSSRule.FONT_FACE_RULE) {
|
|
134061
|
+
const famRaw = (rule.style.getPropertyValue("font-family") || "").trim();
|
|
134062
|
+
const family = pickPrimaryFamily(famRaw);
|
|
134063
|
+
if (!family || isIconFont2(family)) continue;
|
|
134064
|
+
const weightSpec = (rule.style.getPropertyValue("font-weight") || "400").trim();
|
|
134065
|
+
const styleSpec = (rule.style.getPropertyValue("font-style") || "normal").trim();
|
|
134066
|
+
const stretchSpec = (rule.style.getPropertyValue("font-stretch") || "100%").trim();
|
|
134067
|
+
const srcRaw = (rule.style.getPropertyValue("src") || "").trim();
|
|
134068
|
+
const urange = (rule.style.getPropertyValue("unicode-range") || "").trim();
|
|
134069
|
+
if (!ctx.faceMatchesRequired(family, styleSpec, weightSpec, stretchSpec)) continue;
|
|
134070
|
+
const ranges = parseUnicodeRange(urange);
|
|
134071
|
+
if (!unicodeIntersects(ctx.usedCodepoints, ranges)) continue;
|
|
134072
|
+
const meta = {
|
|
134073
|
+
family,
|
|
134074
|
+
weightSpec,
|
|
134075
|
+
styleSpec,
|
|
134076
|
+
stretchSpec,
|
|
134077
|
+
unicodeRange: urange,
|
|
134078
|
+
srcRaw,
|
|
134079
|
+
srcUrls: extractSrcUrls(srcRaw, baseHref || location.href),
|
|
134080
|
+
href: baseHref || location.href
|
|
134081
|
+
};
|
|
134082
|
+
if (ctx.simpleExcluder && ctx.simpleExcluder(meta, ranges)) continue;
|
|
134083
|
+
if (/url\(/i.test(srcRaw)) {
|
|
134084
|
+
const inlinedSrc = await inlineUrlsInCssBlock(srcRaw, baseHref || location.href, ctx.useProxy);
|
|
134085
|
+
await emitFace(`@font-face{font-family:${family};src:${inlinedSrc};font-style:${styleSpec};font-weight:${weightSpec};font-stretch:${stretchSpec};${urange ? `unicode-range:${urange};` : ""}}`);
|
|
134086
|
+
} else {
|
|
134087
|
+
await emitFace(`@font-face{font-family:${family};src:${srcRaw};font-style:${styleSpec};font-weight:${weightSpec};font-stretch:${stretchSpec};${urange ? `unicode-range:${urange};` : ""}}`);
|
|
134088
|
+
}
|
|
134089
|
+
}
|
|
134090
|
+
}
|
|
134091
|
+
}
|
|
134092
|
+
async function embedCustomFonts({
|
|
134093
|
+
required,
|
|
134094
|
+
usedCodepoints,
|
|
134095
|
+
exclude = void 0,
|
|
134096
|
+
localFonts = [],
|
|
134097
|
+
useProxy = ""
|
|
134098
|
+
} = {}) {
|
|
134099
|
+
if (!(required instanceof Set)) required = /* @__PURE__ */ new Set();
|
|
134100
|
+
if (!(usedCodepoints instanceof Set)) usedCodepoints = /* @__PURE__ */ new Set();
|
|
134101
|
+
const requiredIndex = /* @__PURE__ */ new Map();
|
|
134102
|
+
for (const key of required) {
|
|
134103
|
+
const [fam, w, s, st] = String(key).split("__");
|
|
134104
|
+
if (!fam) continue;
|
|
134105
|
+
const arr = requiredIndex.get(fam) || [];
|
|
134106
|
+
arr.push({ w: parseInt(w, 10), s, st: parseInt(st, 10) });
|
|
134107
|
+
requiredIndex.set(fam, arr);
|
|
134108
|
+
}
|
|
134109
|
+
function faceMatchesRequired(fam, styleSpec, weightSpec, stretchSpec) {
|
|
134110
|
+
if (!requiredIndex.has(fam)) return false;
|
|
134111
|
+
const need = requiredIndex.get(fam);
|
|
134112
|
+
const ws = parseWeightSpec(weightSpec);
|
|
134113
|
+
const ss = parseStyleSpec(styleSpec);
|
|
134114
|
+
const ts = parseStretchSpec(stretchSpec);
|
|
134115
|
+
const faceIsRange = ws.min !== ws.max;
|
|
134116
|
+
const faceSingleW = ws.min;
|
|
134117
|
+
const styleOK = (reqKind) => ss.kind === "normal" && reqKind === "normal" || ss.kind !== "normal" && (reqKind === "italic" || reqKind === "oblique");
|
|
134118
|
+
let exactMatched = false;
|
|
134119
|
+
for (const r of need) {
|
|
134120
|
+
const wOk = faceIsRange ? r.w >= ws.min && r.w <= ws.max : r.w === faceSingleW;
|
|
134121
|
+
const sOk = styleOK(normStyle(r.s));
|
|
134122
|
+
const tOk = r.st >= ts.min && r.st <= ts.max;
|
|
134123
|
+
if (wOk && sOk && tOk) {
|
|
134124
|
+
exactMatched = true;
|
|
134125
|
+
break;
|
|
134126
|
+
}
|
|
134127
|
+
}
|
|
134128
|
+
if (exactMatched) return true;
|
|
134129
|
+
if (!faceIsRange) {
|
|
134130
|
+
for (const r of need) {
|
|
134131
|
+
const sOk = styleOK(normStyle(r.s));
|
|
134132
|
+
const tOk = r.st >= ts.min && r.st <= ts.max;
|
|
134133
|
+
const nearWeight = Math.abs(faceSingleW - r.w) <= 300;
|
|
134134
|
+
if (nearWeight && sOk && tOk) return true;
|
|
134135
|
+
}
|
|
134136
|
+
}
|
|
134137
|
+
return false;
|
|
134138
|
+
}
|
|
134139
|
+
const simpleExcluder = buildSimpleExcluder(exclude);
|
|
134140
|
+
const cacheKey = buildFontsCacheKey(required, exclude, localFonts, useProxy);
|
|
134141
|
+
if (cache.resource?.has(cacheKey)) {
|
|
134142
|
+
return cache.resource.get(cacheKey);
|
|
134143
|
+
}
|
|
134144
|
+
const requiredFamilies = familiesFromRequired(required);
|
|
134145
|
+
const importUrls = [];
|
|
134146
|
+
const IMPORT_ANY_RE_LOCAL = IMPORT_ANY_RE;
|
|
134147
|
+
for (const styleTag of document.querySelectorAll("style")) {
|
|
134148
|
+
const cssText = styleTag.textContent || "";
|
|
134149
|
+
for (const m of cssText.matchAll(IMPORT_ANY_RE_LOCAL)) {
|
|
134150
|
+
const u = (m[2] || m[4] || "").trim();
|
|
134151
|
+
if (!u || isIconFont2(u)) continue;
|
|
134152
|
+
const hasLink = !!document.querySelector(`link[rel="stylesheet"][href="${u}"]`);
|
|
134153
|
+
if (!hasLink) importUrls.push(u);
|
|
134154
|
+
}
|
|
134155
|
+
}
|
|
134156
|
+
if (importUrls.length) {
|
|
134157
|
+
await Promise.all(importUrls.map((u) => new Promise((resolve) => {
|
|
134158
|
+
if (document.querySelector(`link[rel="stylesheet"][href="${u}"]`)) return resolve(null);
|
|
134159
|
+
const link = document.createElement("link");
|
|
134160
|
+
link.rel = "stylesheet";
|
|
134161
|
+
link.href = u;
|
|
134162
|
+
link.setAttribute("data-snapdom", "injected-import");
|
|
134163
|
+
link.onload = () => resolve(link);
|
|
134164
|
+
link.onerror = () => resolve(null);
|
|
134165
|
+
document.head.appendChild(link);
|
|
134166
|
+
})));
|
|
134167
|
+
}
|
|
134168
|
+
let finalCSS = "";
|
|
134169
|
+
const linkNodes = Array.from(document.querySelectorAll('link[rel="stylesheet"]')).filter((l) => !!l.href);
|
|
134170
|
+
for (const link of linkNodes) {
|
|
134171
|
+
try {
|
|
134172
|
+
if (isIconFont2(link.href)) continue;
|
|
134173
|
+
let cssText = "";
|
|
134174
|
+
let sameOrigin = false;
|
|
134175
|
+
try {
|
|
134176
|
+
sameOrigin = new URL(link.href, location.href).origin === location.origin;
|
|
134177
|
+
} catch {
|
|
134178
|
+
}
|
|
134179
|
+
if (!sameOrigin) {
|
|
134180
|
+
if (!isLikelyFontStylesheet(link.href, requiredFamilies)) continue;
|
|
134181
|
+
}
|
|
134182
|
+
if (sameOrigin) {
|
|
134183
|
+
const sheet = Array.from(document.styleSheets).find((s) => s.href === link.href);
|
|
134184
|
+
if (sheet) {
|
|
134185
|
+
try {
|
|
134186
|
+
const rules = sheet.cssRules || [];
|
|
134187
|
+
cssText = Array.from(rules).map((r) => r.cssText).join("");
|
|
134188
|
+
} catch {
|
|
134189
|
+
}
|
|
134190
|
+
}
|
|
134191
|
+
}
|
|
134192
|
+
if (!cssText) {
|
|
134193
|
+
const res = await snapFetch(link.href, { as: "text", useProxy });
|
|
134194
|
+
cssText = res.data;
|
|
134195
|
+
if (isIconFont2(link.href)) continue;
|
|
134196
|
+
}
|
|
134197
|
+
cssText = await inlineImportsAndRewrite(cssText, link.href, useProxy);
|
|
134198
|
+
let facesOut = "";
|
|
134199
|
+
for (const face of cssText.match(FACE_RE) || []) {
|
|
134200
|
+
const famRaw = (face.match(/font-family:\s*([^;]+);/i)?.[1] || "").trim();
|
|
134201
|
+
const family = pickPrimaryFamily(famRaw);
|
|
134202
|
+
if (!family || isIconFont2(family)) continue;
|
|
134203
|
+
const weightSpec = (face.match(/font-weight:\s*([^;]+);/i)?.[1] || "400").trim();
|
|
134204
|
+
const styleSpec = (face.match(/font-style:\s*([^;]+);/i)?.[1] || "normal").trim();
|
|
134205
|
+
const stretchSpec = (face.match(/font-stretch:\s*([^;]+);/i)?.[1] || "100%").trim();
|
|
134206
|
+
const urange = (face.match(/unicode-range:\s*([^;]+);/i)?.[1] || "").trim();
|
|
134207
|
+
const srcRaw = (face.match(/src\s*:\s*([^;]+);/i)?.[1] || "").trim();
|
|
134208
|
+
const srcUrls = extractSrcUrls(srcRaw, link.href);
|
|
134209
|
+
if (!faceMatchesRequired(family, styleSpec, weightSpec, stretchSpec)) continue;
|
|
134210
|
+
const ranges = parseUnicodeRange(urange);
|
|
134211
|
+
if (!unicodeIntersects(usedCodepoints, ranges)) continue;
|
|
134212
|
+
const meta = { family, weightSpec, styleSpec, stretchSpec, unicodeRange: urange, srcRaw, srcUrls, href: link.href };
|
|
134213
|
+
if (exclude && simpleExcluder(meta, ranges)) continue;
|
|
134214
|
+
const newFace = /url\(/i.test(srcRaw) ? await inlineUrlsInCssBlock(face, link.href, useProxy) : face;
|
|
134215
|
+
facesOut += newFace;
|
|
134216
|
+
}
|
|
134217
|
+
if (facesOut.trim()) finalCSS += facesOut;
|
|
134218
|
+
} catch {
|
|
134219
|
+
console.warn("[snapDOM] Failed to process stylesheet:", link.href);
|
|
134220
|
+
}
|
|
134221
|
+
}
|
|
134222
|
+
const ctx = {
|
|
134223
|
+
requiredIndex,
|
|
134224
|
+
usedCodepoints,
|
|
134225
|
+
faceMatchesRequired,
|
|
134226
|
+
simpleExcluder: exclude ? buildSimpleExcluder(exclude) : null,
|
|
134227
|
+
useProxy,
|
|
134228
|
+
visitedSheets: /* @__PURE__ */ new Set(),
|
|
134229
|
+
depth: 0
|
|
134230
|
+
};
|
|
134231
|
+
for (const sheet of document.styleSheets) {
|
|
134232
|
+
if (sheet.href && linkNodes.some((l) => l.href === sheet.href)) continue;
|
|
134233
|
+
try {
|
|
134234
|
+
const rootHref = sheet.href || location.href;
|
|
134235
|
+
if (rootHref) ctx.visitedSheets.add(rootHref);
|
|
134236
|
+
await collectFacesFromSheet(
|
|
134237
|
+
sheet,
|
|
134238
|
+
rootHref,
|
|
134239
|
+
async (faceCss) => {
|
|
134240
|
+
finalCSS += faceCss;
|
|
134241
|
+
},
|
|
134242
|
+
ctx
|
|
134243
|
+
);
|
|
134244
|
+
} catch {
|
|
134245
|
+
}
|
|
134246
|
+
}
|
|
134247
|
+
try {
|
|
134248
|
+
for (const f of document.fonts || []) {
|
|
134249
|
+
if (!f || !f.family || f.status !== "loaded" || !f._snapdomSrc) continue;
|
|
134250
|
+
const fam = String(f.family).replace(/^['"]+|['"]+$/g, "");
|
|
134251
|
+
if (isIconFont2(fam)) continue;
|
|
134252
|
+
if (!requiredIndex.has(fam)) continue;
|
|
134253
|
+
if (exclude?.families && exclude.families.some((n) => String(n).toLowerCase() === fam.toLowerCase())) {
|
|
134254
|
+
continue;
|
|
134255
|
+
}
|
|
134256
|
+
let b64 = f._snapdomSrc;
|
|
134257
|
+
if (!String(b64).startsWith("data:")) {
|
|
134258
|
+
if (cache.resource?.has(f._snapdomSrc)) {
|
|
134259
|
+
b64 = cache.resource.get(f._snapdomSrc);
|
|
134260
|
+
cache.font?.add(f._snapdomSrc);
|
|
134261
|
+
} else if (!cache.font?.has(f._snapdomSrc)) {
|
|
134262
|
+
try {
|
|
134263
|
+
const r = await snapFetch(f._snapdomSrc, { as: "dataURL", useProxy, silent: true });
|
|
134264
|
+
if (r.ok && typeof r.data === "string") {
|
|
134265
|
+
b64 = r.data;
|
|
134266
|
+
cache.resource?.set(f._snapdomSrc, b64);
|
|
134267
|
+
cache.font?.add(f._snapdomSrc);
|
|
134268
|
+
} else {
|
|
134269
|
+
continue;
|
|
134270
|
+
}
|
|
134271
|
+
} catch {
|
|
134272
|
+
console.warn("[snapDOM] Failed to fetch dynamic font src:", f._snapdomSrc);
|
|
134273
|
+
continue;
|
|
134274
|
+
}
|
|
134275
|
+
}
|
|
134276
|
+
}
|
|
134277
|
+
finalCSS += `@font-face{font-family:'${fam}';src:url(${b64});font-style:${f.style || "normal"};font-weight:${f.weight || "normal"};}`;
|
|
134278
|
+
}
|
|
134279
|
+
} catch {
|
|
134280
|
+
}
|
|
134281
|
+
for (const font of localFonts) {
|
|
134282
|
+
if (!font || typeof font !== "object") continue;
|
|
134283
|
+
const family = String(font.family || "").replace(/^['"]+|['"]+$/g, "");
|
|
134284
|
+
if (!family || isIconFont2(family)) continue;
|
|
134285
|
+
if (!requiredIndex.has(family)) continue;
|
|
134286
|
+
if (exclude?.families && exclude.families.some((n) => String(n).toLowerCase() === family.toLowerCase())) continue;
|
|
134287
|
+
const weight = font.weight != null ? String(font.weight) : "normal";
|
|
134288
|
+
const style = font.style != null ? String(font.style) : "normal";
|
|
134289
|
+
const stretch = font.stretchPct != null ? `${font.stretchPct}%` : "100%";
|
|
134290
|
+
const src = String(font.src || "");
|
|
134291
|
+
let b64 = src;
|
|
134292
|
+
if (!b64.startsWith("data:")) {
|
|
134293
|
+
if (cache.resource?.has(src)) {
|
|
134294
|
+
b64 = cache.resource.get(src);
|
|
134295
|
+
cache.font?.add(src);
|
|
134296
|
+
} else if (!cache.font?.has(src)) {
|
|
134297
|
+
try {
|
|
134298
|
+
const r = await snapFetch(src, { as: "dataURL", useProxy, silent: true });
|
|
134299
|
+
if (r.ok && typeof r.data === "string") {
|
|
134300
|
+
b64 = r.data;
|
|
134301
|
+
cache.resource?.set(src, b64);
|
|
134302
|
+
cache.font?.add(src);
|
|
134303
|
+
} else {
|
|
134304
|
+
continue;
|
|
134305
|
+
}
|
|
134306
|
+
} catch {
|
|
134307
|
+
console.warn("[snapDOM] Failed to fetch localFonts src:", src);
|
|
134308
|
+
continue;
|
|
134309
|
+
}
|
|
134310
|
+
}
|
|
134311
|
+
}
|
|
134312
|
+
finalCSS += `@font-face{font-family:'${family}';src:url(${b64});font-style:${style};font-weight:${weight};font-stretch:${stretch};}`;
|
|
134313
|
+
}
|
|
134314
|
+
if (finalCSS) {
|
|
134315
|
+
finalCSS = dedupeFontFaces(finalCSS);
|
|
134316
|
+
cache.resource?.set(cacheKey, finalCSS);
|
|
134317
|
+
}
|
|
134318
|
+
return finalCSS;
|
|
134319
|
+
}
|
|
134320
|
+
function collectUsedFontVariants(root) {
|
|
134321
|
+
const req = /* @__PURE__ */ new Set();
|
|
134322
|
+
if (!root) return req;
|
|
134323
|
+
const tw = document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT, null);
|
|
134324
|
+
const addFromStyle = (cs) => {
|
|
134325
|
+
const family = pickPrimaryFamily(cs.fontFamily);
|
|
134326
|
+
if (!family) return;
|
|
134327
|
+
const key = (w, s, st) => `${family}__${normWeight(w)}__${normStyle(s)}__${normStretchPct(st)}`;
|
|
134328
|
+
req.add(key(cs.fontWeight, cs.fontStyle, cs.fontStretch));
|
|
134329
|
+
};
|
|
134330
|
+
addFromStyle(getComputedStyle(root));
|
|
134331
|
+
const csBeforeRoot = getComputedStyle(root, "::before");
|
|
134332
|
+
if (csBeforeRoot && csBeforeRoot.content && csBeforeRoot.content !== "none") addFromStyle(csBeforeRoot);
|
|
134333
|
+
const csAfterRoot = getComputedStyle(root, "::after");
|
|
134334
|
+
if (csAfterRoot && csAfterRoot.content && csAfterRoot.content !== "none") addFromStyle(csAfterRoot);
|
|
134335
|
+
while (tw.nextNode()) {
|
|
134336
|
+
const el = (
|
|
134337
|
+
/** @type {Element} */
|
|
134338
|
+
tw.currentNode
|
|
134339
|
+
);
|
|
134340
|
+
const cs = getComputedStyle(el);
|
|
134341
|
+
addFromStyle(cs);
|
|
134342
|
+
const b = getComputedStyle(el, "::before");
|
|
134343
|
+
if (b && b.content && b.content !== "none") addFromStyle(b);
|
|
134344
|
+
const a = getComputedStyle(el, "::after");
|
|
134345
|
+
if (a && a.content && a.content !== "none") addFromStyle(a);
|
|
134346
|
+
}
|
|
134347
|
+
return req;
|
|
134348
|
+
}
|
|
134349
|
+
function collectUsedCodepoints(root) {
|
|
134350
|
+
const used = /* @__PURE__ */ new Set();
|
|
134351
|
+
const pushText = (txt) => {
|
|
134352
|
+
if (!txt) return;
|
|
134353
|
+
for (const ch of txt) used.add(ch.codePointAt(0));
|
|
134354
|
+
};
|
|
134355
|
+
const walker = document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT, null);
|
|
134356
|
+
while (walker.nextNode()) {
|
|
134357
|
+
const n = walker.currentNode;
|
|
134358
|
+
if (n.nodeType === Node.TEXT_NODE) {
|
|
134359
|
+
pushText(n.nodeValue || "");
|
|
134360
|
+
} else if (n.nodeType === Node.ELEMENT_NODE) {
|
|
134361
|
+
const el = (
|
|
134362
|
+
/** @type {Element} */
|
|
134363
|
+
n
|
|
134364
|
+
);
|
|
134365
|
+
for (const pseudo of ["::before", "::after"]) {
|
|
134366
|
+
const cs = getComputedStyle(el, pseudo);
|
|
134367
|
+
const c = cs?.getPropertyValue("content");
|
|
134368
|
+
if (!c || c === "none") continue;
|
|
134369
|
+
if (/^"/.test(c) || /^'/.test(c)) {
|
|
134370
|
+
pushText(c.slice(1, -1));
|
|
134371
|
+
} else {
|
|
134372
|
+
const matches = c.match(/\\[0-9A-Fa-f]{1,6}/g);
|
|
134373
|
+
if (matches) {
|
|
134374
|
+
for (const m of matches) {
|
|
134375
|
+
try {
|
|
134376
|
+
used.add(parseInt(m.slice(1), 16));
|
|
134377
|
+
} catch {
|
|
134378
|
+
}
|
|
134379
|
+
}
|
|
134380
|
+
}
|
|
134381
|
+
}
|
|
134382
|
+
}
|
|
134383
|
+
}
|
|
134384
|
+
}
|
|
134385
|
+
return used;
|
|
134386
|
+
}
|
|
134387
|
+
async function ensureFontsReady(families, warmupRepetitions = 2) {
|
|
134388
|
+
try {
|
|
134389
|
+
await document.fonts.ready;
|
|
134390
|
+
} catch {
|
|
134391
|
+
}
|
|
134392
|
+
const fams = Array.from(families || []).filter(Boolean);
|
|
134393
|
+
if (fams.length === 0) return;
|
|
134394
|
+
const warmupOnce = () => {
|
|
134395
|
+
const container = document.createElement("div");
|
|
134396
|
+
container.style.cssText = "position:absolute!important;left:-9999px!important;top:0!important;opacity:0!important;pointer-events:none!important;contain:layout size style;";
|
|
134397
|
+
for (const fam of fams) {
|
|
134398
|
+
const span = document.createElement("span");
|
|
134399
|
+
span.textContent = "AaBbGg1234\xC1\xC9\xCD\xD3\xDA\xE7\xF1\u2014\u221E";
|
|
134400
|
+
span.style.fontFamily = `"${fam}"`;
|
|
134401
|
+
span.style.fontWeight = "700";
|
|
134402
|
+
span.style.fontStyle = "italic";
|
|
134403
|
+
span.style.fontSize = "32px";
|
|
134404
|
+
span.style.lineHeight = "1";
|
|
134405
|
+
span.style.whiteSpace = "nowrap";
|
|
134406
|
+
span.style.margin = "0";
|
|
134407
|
+
span.style.padding = "0";
|
|
134408
|
+
container.appendChild(span);
|
|
134409
|
+
}
|
|
134410
|
+
document.body.appendChild(container);
|
|
134411
|
+
container.offsetWidth;
|
|
134412
|
+
document.body.removeChild(container);
|
|
134413
|
+
};
|
|
134414
|
+
for (let i = 0; i < Math.max(1, warmupRepetitions); i++) {
|
|
134415
|
+
warmupOnce();
|
|
134416
|
+
await new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r)));
|
|
134417
|
+
}
|
|
134418
|
+
}
|
|
134419
|
+
|
|
134420
|
+
// src/modules/counter.js
|
|
134421
|
+
function hasCounters(input) {
|
|
134422
|
+
return /\bcounter\s*\(|\bcounters\s*\(/.test(input || "");
|
|
134423
|
+
}
|
|
134424
|
+
function unquoteDoubleStrings(s) {
|
|
134425
|
+
return (s || "").replace(/"([^"]*)"/g, "$1");
|
|
134426
|
+
}
|
|
134427
|
+
function alpha(n, upper = false) {
|
|
134428
|
+
let s = "", x = Math.max(1, n);
|
|
134429
|
+
while (x > 0) {
|
|
134430
|
+
x--;
|
|
134431
|
+
s = String.fromCharCode(97 + x % 26) + s;
|
|
134432
|
+
x = Math.floor(x / 26);
|
|
134433
|
+
}
|
|
134434
|
+
return upper ? s.toUpperCase() : s;
|
|
134435
|
+
}
|
|
134436
|
+
function roman(n, upper = true) {
|
|
134437
|
+
const map = [[1e3, "M"], [900, "CM"], [500, "D"], [400, "CD"], [100, "C"], [90, "XC"], [50, "L"], [40, "XL"], [10, "X"], [9, "IX"], [5, "V"], [4, "IV"], [1, "I"]];
|
|
134438
|
+
let num = Math.max(1, Math.min(3999, n)), out = "";
|
|
134439
|
+
for (const [v, sym] of map) while (num >= v) {
|
|
134440
|
+
out += sym;
|
|
134441
|
+
num -= v;
|
|
134442
|
+
}
|
|
134443
|
+
return upper ? out : out.toLowerCase();
|
|
134444
|
+
}
|
|
134445
|
+
function formatCounter(value, style) {
|
|
134446
|
+
switch ((style || "decimal").toLowerCase()) {
|
|
134447
|
+
case "decimal":
|
|
134448
|
+
return String(Math.max(0, value));
|
|
134449
|
+
case "decimal-leading-zero":
|
|
134450
|
+
return (value < 10 ? "0" : "") + String(Math.max(0, value));
|
|
134451
|
+
case "lower-alpha":
|
|
134452
|
+
return alpha(value, false);
|
|
134453
|
+
case "upper-alpha":
|
|
134454
|
+
return alpha(value, true);
|
|
134455
|
+
case "lower-roman":
|
|
134456
|
+
return roman(value, false);
|
|
134457
|
+
case "upper-roman":
|
|
134458
|
+
return roman(value, true);
|
|
134459
|
+
default:
|
|
134460
|
+
return String(Math.max(0, value));
|
|
134461
|
+
}
|
|
134462
|
+
}
|
|
134463
|
+
function buildCounterContext(root) {
|
|
134464
|
+
const nodeCounters = /* @__PURE__ */ new WeakMap();
|
|
134465
|
+
const rootEl = root instanceof Document ? root.documentElement : root;
|
|
134466
|
+
const isLi = (el) => el && el.tagName === "LI";
|
|
134467
|
+
const countPrevLi = (li) => {
|
|
134468
|
+
let c = 0, p = li?.parentElement;
|
|
134469
|
+
if (!p) return 0;
|
|
134470
|
+
for (const sib of p.children) {
|
|
134471
|
+
if (sib === li) break;
|
|
134472
|
+
if (sib.tagName === "LI") c++;
|
|
134473
|
+
}
|
|
134474
|
+
return c;
|
|
134475
|
+
};
|
|
134476
|
+
const cloneMap = (m) => {
|
|
134477
|
+
const out = /* @__PURE__ */ new Map();
|
|
134478
|
+
for (const [k, arr] of m) out.set(k, arr.slice());
|
|
134479
|
+
return out;
|
|
134480
|
+
};
|
|
134481
|
+
const applyTo = (baseMap, parentMap, el) => {
|
|
134482
|
+
const map = cloneMap(baseMap);
|
|
134483
|
+
let reset;
|
|
134484
|
+
try {
|
|
134485
|
+
reset = el.style?.counterReset || getComputedStyle(el).counterReset;
|
|
134486
|
+
} catch {
|
|
134487
|
+
}
|
|
134488
|
+
if (reset && reset !== "none") {
|
|
134489
|
+
for (const part of reset.split(",")) {
|
|
134490
|
+
const toks = part.trim().split(/\s+/);
|
|
134491
|
+
const name = toks[0];
|
|
134492
|
+
const val = Number.isFinite(Number(toks[1])) ? Number(toks[1]) : 0;
|
|
134493
|
+
if (!name) continue;
|
|
134494
|
+
const parentStack = parentMap.get(name);
|
|
134495
|
+
if (parentStack && parentStack.length) {
|
|
134496
|
+
const s = parentStack.slice();
|
|
134497
|
+
s.push(val);
|
|
134498
|
+
map.set(name, s);
|
|
134499
|
+
} else {
|
|
134500
|
+
map.set(name, [val]);
|
|
134501
|
+
}
|
|
134502
|
+
}
|
|
134503
|
+
}
|
|
134504
|
+
let inc;
|
|
134505
|
+
try {
|
|
134506
|
+
inc = el.style?.counterIncrement || getComputedStyle(el).counterIncrement;
|
|
134507
|
+
} catch {
|
|
134508
|
+
}
|
|
134509
|
+
if (inc && inc !== "none") {
|
|
134510
|
+
for (const part of inc.split(",")) {
|
|
134511
|
+
const toks = part.trim().split(/\s+/);
|
|
134512
|
+
const name = toks[0];
|
|
134513
|
+
const by = Number.isFinite(Number(toks[1])) ? Number(toks[1]) : 1;
|
|
134514
|
+
if (!name) continue;
|
|
134515
|
+
const stack = map.get(name) || [];
|
|
134516
|
+
if (stack.length === 0) stack.push(0);
|
|
134517
|
+
stack[stack.length - 1] += by;
|
|
134518
|
+
map.set(name, stack);
|
|
134519
|
+
}
|
|
134520
|
+
}
|
|
134521
|
+
try {
|
|
134522
|
+
const cs = getComputedStyle(el);
|
|
134523
|
+
if (cs.display === "list-item" && isLi(el)) {
|
|
134524
|
+
const p = el.parentElement;
|
|
134525
|
+
let idx = 1;
|
|
134526
|
+
if (p && p.tagName === "OL") {
|
|
134527
|
+
const startAttr = p.getAttribute("start");
|
|
134528
|
+
const start = Number.isFinite(Number(startAttr)) ? Number(startAttr) : 1;
|
|
134529
|
+
const prev = countPrevLi(el);
|
|
134530
|
+
const ownAttr = el.getAttribute("value");
|
|
134531
|
+
idx = Number.isFinite(Number(ownAttr)) ? Number(ownAttr) : start + prev;
|
|
134532
|
+
} else {
|
|
134533
|
+
idx = 1 + countPrevLi(el);
|
|
134534
|
+
}
|
|
134535
|
+
const s = map.get("list-item") || [];
|
|
134536
|
+
if (s.length === 0) s.push(0);
|
|
134537
|
+
s[s.length - 1] = idx;
|
|
134538
|
+
map.set("list-item", s);
|
|
134539
|
+
}
|
|
134540
|
+
} catch {
|
|
134541
|
+
}
|
|
134542
|
+
return map;
|
|
134543
|
+
};
|
|
134544
|
+
const build = (el, parentMap, carryMap) => {
|
|
134545
|
+
const curr = applyTo(carryMap, parentMap, el);
|
|
134546
|
+
nodeCounters.set(el, curr);
|
|
134547
|
+
let nextCarry = curr;
|
|
134548
|
+
for (const child of el.children) {
|
|
134549
|
+
const childCarry = build(child, curr, nextCarry);
|
|
134550
|
+
nextCarry = childCarry;
|
|
134551
|
+
}
|
|
134552
|
+
return curr;
|
|
134553
|
+
};
|
|
134554
|
+
const empty = /* @__PURE__ */ new Map();
|
|
134555
|
+
build(rootEl, empty, empty);
|
|
134556
|
+
return {
|
|
134557
|
+
/**
|
|
134558
|
+
* Get top value for counter name at given node.
|
|
134559
|
+
* @param {Element} node
|
|
134560
|
+
* @param {string} name
|
|
134561
|
+
*/
|
|
134562
|
+
get(node, name) {
|
|
134563
|
+
const s = nodeCounters.get(node)?.get(name);
|
|
134564
|
+
return s && s.length ? s[s.length - 1] : 0;
|
|
134565
|
+
},
|
|
134566
|
+
/**
|
|
134567
|
+
* Get full stack for counter name at given node.
|
|
134568
|
+
* @param {Element} node
|
|
134569
|
+
* @param {string} name
|
|
134570
|
+
*/
|
|
134571
|
+
getStack(node, name) {
|
|
134572
|
+
const s = nodeCounters.get(node)?.get(name);
|
|
134573
|
+
return s ? s.slice() : [];
|
|
134574
|
+
}
|
|
134575
|
+
};
|
|
134576
|
+
}
|
|
134577
|
+
function resolveCountersInContent(raw, node, ctx) {
|
|
134578
|
+
if (!raw || raw === "none") return raw;
|
|
134579
|
+
try {
|
|
134580
|
+
const RX = /\b(counter|counters)\s*\(([^)]+)\)/g;
|
|
134581
|
+
let out = raw.replace(RX, (_, fn, args) => {
|
|
134582
|
+
const parts = String(args).split(",").map((s) => s.trim());
|
|
134583
|
+
if (fn === "counter") {
|
|
134584
|
+
const name = parts[0]?.replace(/^["']|["']$/g, "");
|
|
134585
|
+
const style = (parts[1] || "decimal").toLowerCase();
|
|
134586
|
+
const v = ctx.get(node, name);
|
|
134587
|
+
return formatCounter(v, style);
|
|
134588
|
+
} else {
|
|
134589
|
+
const name = parts[0]?.replace(/^["']|["']$/g, "");
|
|
134590
|
+
const sep = parts[1]?.replace(/^["']|["']$/g, "") ?? "";
|
|
134591
|
+
const style = (parts[2] || "decimal").toLowerCase();
|
|
134592
|
+
const stack = ctx.getStack(node, name);
|
|
134593
|
+
if (!stack.length) return "";
|
|
134594
|
+
const pieces = stack.map((v) => formatCounter(v, style));
|
|
134595
|
+
return pieces.join(sep);
|
|
134596
|
+
}
|
|
134597
|
+
});
|
|
134598
|
+
return unquoteDoubleStrings(out);
|
|
134599
|
+
} catch {
|
|
134600
|
+
return "- ";
|
|
134601
|
+
}
|
|
134602
|
+
}
|
|
134603
|
+
|
|
134604
|
+
// src/modules/pseudo.js
|
|
134605
|
+
var counterCtx = null;
|
|
134606
|
+
var __siblingCounters = /* @__PURE__ */ new WeakMap();
|
|
134607
|
+
function unquoteDoubleStrings2(s) {
|
|
134608
|
+
return (s || "").replace(/"([^"]*)"/g, "$1");
|
|
134609
|
+
}
|
|
134610
|
+
function collapseCssContent(raw) {
|
|
134611
|
+
if (!raw) return "";
|
|
134612
|
+
const tokens = [];
|
|
134613
|
+
const rx = /"([^"]*)"/g;
|
|
134614
|
+
let m;
|
|
134615
|
+
while (m = rx.exec(raw)) tokens.push(m[1]);
|
|
134616
|
+
if (tokens.length) return tokens.join("");
|
|
134617
|
+
return unquoteDoubleStrings2(raw);
|
|
134618
|
+
}
|
|
134619
|
+
function withSiblingOverrides(node, base) {
|
|
134620
|
+
const parent = node.parentElement;
|
|
134621
|
+
const map = parent ? __siblingCounters.get(parent) : null;
|
|
134622
|
+
if (!map) return base;
|
|
134623
|
+
return {
|
|
134624
|
+
get(n, name) {
|
|
134625
|
+
const v = base.get(n, name);
|
|
134626
|
+
const ov = map.get(name);
|
|
134627
|
+
return typeof ov === "number" ? Math.max(v, ov) : v;
|
|
134628
|
+
},
|
|
134629
|
+
getStack(n, name) {
|
|
134630
|
+
const s = base.getStack(n, name);
|
|
134631
|
+
if (!s.length) return s;
|
|
134632
|
+
const ov = map.get(name);
|
|
134633
|
+
if (typeof ov === "number") {
|
|
134634
|
+
const out = s.slice();
|
|
134635
|
+
out[out.length - 1] = Math.max(out[out.length - 1], ov);
|
|
134636
|
+
return out;
|
|
134637
|
+
}
|
|
134638
|
+
return s;
|
|
134639
|
+
}
|
|
134640
|
+
};
|
|
134641
|
+
}
|
|
134642
|
+
function deriveCounterCtxForPseudo(node, pseudoStyle, baseCtx) {
|
|
134643
|
+
const modStacks = /* @__PURE__ */ new Map();
|
|
134644
|
+
function parseListDecl(value) {
|
|
134645
|
+
const out = [];
|
|
134646
|
+
if (!value || value === "none") return out;
|
|
134647
|
+
for (const part of String(value).split(",")) {
|
|
134648
|
+
const toks = part.trim().split(/\s+/);
|
|
134649
|
+
const name = toks[0];
|
|
134650
|
+
const num = Number.isFinite(Number(toks[1])) ? Number(toks[1]) : void 0;
|
|
134651
|
+
if (name) out.push({ name, num });
|
|
134652
|
+
}
|
|
134653
|
+
return out;
|
|
134654
|
+
}
|
|
134655
|
+
const resets = parseListDecl(pseudoStyle?.counterReset);
|
|
134656
|
+
const incs = parseListDecl(pseudoStyle?.counterIncrement);
|
|
134657
|
+
function getStackDerived(name) {
|
|
134658
|
+
if (modStacks.has(name)) return modStacks.get(name).slice();
|
|
134659
|
+
let stack = baseCtx.getStack(node, name);
|
|
134660
|
+
stack = stack.length ? stack.slice() : [];
|
|
134661
|
+
const r = resets.find((x) => x.name === name);
|
|
134662
|
+
if (r) {
|
|
134663
|
+
const val = Number.isFinite(r.num) ? r.num : 0;
|
|
134664
|
+
stack = stack.length ? [...stack, val] : [val];
|
|
134665
|
+
}
|
|
134666
|
+
const inc = incs.find((x) => x.name === name);
|
|
134667
|
+
if (inc) {
|
|
134668
|
+
const by = Number.isFinite(inc.num) ? inc.num : 1;
|
|
134669
|
+
if (stack.length === 0) stack = [0];
|
|
134670
|
+
stack[stack.length - 1] += by;
|
|
134671
|
+
}
|
|
134672
|
+
modStacks.set(name, stack.slice());
|
|
134673
|
+
return stack;
|
|
134674
|
+
}
|
|
134675
|
+
return {
|
|
134676
|
+
get(_node, name) {
|
|
134677
|
+
const s = getStackDerived(name);
|
|
134678
|
+
return s.length ? s[s.length - 1] : 0;
|
|
134679
|
+
},
|
|
134680
|
+
getStack(_node, name) {
|
|
134681
|
+
return getStackDerived(name);
|
|
134682
|
+
},
|
|
134683
|
+
/** expone increments del pseudo para que el caller pueda propagar a hermanos */
|
|
134684
|
+
__incs: incs
|
|
134685
|
+
};
|
|
134686
|
+
}
|
|
134687
|
+
function resolvePseudoContentAndIncs(node, pseudo, baseCtx) {
|
|
134688
|
+
let ps;
|
|
134689
|
+
try {
|
|
134690
|
+
ps = getComputedStyle(node, pseudo);
|
|
134691
|
+
} catch {
|
|
134692
|
+
}
|
|
134693
|
+
const raw = ps?.content;
|
|
134694
|
+
if (!raw || raw === "none" || raw === "normal") return { text: "", incs: [] };
|
|
134695
|
+
const baseWithSiblings = withSiblingOverrides(node, baseCtx);
|
|
134696
|
+
const derived = deriveCounterCtxForPseudo(node, ps, baseWithSiblings);
|
|
134697
|
+
let resolved = hasCounters(raw) ? resolveCountersInContent(raw, node, derived) : raw;
|
|
134698
|
+
const text = collapseCssContent(resolved);
|
|
134699
|
+
return { text, incs: derived.__incs || [] };
|
|
134700
|
+
}
|
|
134701
|
+
async function inlinePseudoElements(source, clone, sessionCache, options) {
|
|
134702
|
+
if (!(source instanceof Element) || !(clone instanceof Element)) return;
|
|
134703
|
+
if (!counterCtx) {
|
|
134704
|
+
try {
|
|
134705
|
+
counterCtx = buildCounterContext(source.ownerDocument || document);
|
|
134706
|
+
} catch {
|
|
134707
|
+
}
|
|
134708
|
+
}
|
|
134709
|
+
for (const pseudo of ["::before", "::after", "::first-letter"]) {
|
|
134710
|
+
try {
|
|
134711
|
+
const style = getStyle(source, pseudo);
|
|
134712
|
+
if (!style || typeof style[Symbol.iterator] !== "function") continue;
|
|
134713
|
+
const isEmptyPseudo = style.content === "none" && style.backgroundImage === "none" && style.backgroundColor === "transparent" && (style.borderStyle === "none" || parseFloat(style.borderWidth) === 0) && (!style.transform || style.transform === "none") && style.display === "inline";
|
|
134714
|
+
if (isEmptyPseudo) continue;
|
|
134715
|
+
if (pseudo === "::first-letter") {
|
|
134716
|
+
const normal = getComputedStyle(source);
|
|
134717
|
+
const isMeaningful = style.color !== normal.color || style.fontSize !== normal.fontSize || style.fontWeight !== normal.fontWeight;
|
|
134718
|
+
if (!isMeaningful) continue;
|
|
134719
|
+
const textNode = Array.from(clone.childNodes).find(
|
|
134720
|
+
(n) => n.nodeType === Node.TEXT_NODE && n.textContent?.trim().length > 0
|
|
134721
|
+
);
|
|
134722
|
+
if (!textNode) continue;
|
|
134723
|
+
const text = textNode.textContent;
|
|
134724
|
+
const match = text.match(/^([^\p{L}\p{N}\s]*[\p{L}\p{N}](?:['’])?)/u);
|
|
134725
|
+
const first = match?.[0];
|
|
134726
|
+
const rest = text.slice(first?.length || 0);
|
|
134727
|
+
if (!first || /[\uD800-\uDFFF]/.test(first)) continue;
|
|
134728
|
+
const span = document.createElement("span");
|
|
134729
|
+
span.textContent = first;
|
|
134730
|
+
span.dataset.snapdomPseudo = "::first-letter";
|
|
134731
|
+
const snapshot2 = snapshotComputedStyle(style);
|
|
134732
|
+
const key2 = getStyleKey(snapshot2, "span");
|
|
134733
|
+
sessionCache.styleMap.set(span, key2);
|
|
134734
|
+
const restNode = document.createTextNode(rest);
|
|
134735
|
+
clone.replaceChild(restNode, textNode);
|
|
134736
|
+
clone.insertBefore(span, restNode);
|
|
134737
|
+
continue;
|
|
134738
|
+
}
|
|
134739
|
+
const rawContent = style.content;
|
|
134740
|
+
const { text: cleanContent, incs } = resolvePseudoContentAndIncs(source, pseudo, counterCtx);
|
|
134741
|
+
const bg = style.backgroundImage;
|
|
134742
|
+
const bgColor = style.backgroundColor;
|
|
134743
|
+
const fontFamily = style.fontFamily;
|
|
134744
|
+
const fontSize = parseInt(style.fontSize) || 32;
|
|
134745
|
+
const fontWeight = parseInt(style.fontWeight) || false;
|
|
134746
|
+
const color = style.color || "#000";
|
|
134747
|
+
const borderStyle = style.borderStyle;
|
|
134748
|
+
const borderWidth = parseFloat(style.borderWidth);
|
|
134749
|
+
const transform = style.transform;
|
|
134750
|
+
const isIconFont22 = isIconFont2(fontFamily);
|
|
134751
|
+
const hasExplicitContent = rawContent !== "none" && cleanContent !== "";
|
|
134752
|
+
const hasBg = bg && bg !== "none";
|
|
134753
|
+
const hasBgColor = bgColor && bgColor !== "transparent" && bgColor !== "rgba(0, 0, 0, 0)";
|
|
134754
|
+
const hasBorder = borderStyle && borderStyle !== "none" && borderWidth > 0;
|
|
134755
|
+
const hasTransform = transform && transform !== "none";
|
|
134756
|
+
const shouldRender = hasExplicitContent || hasBg || hasBgColor || hasBorder || hasTransform;
|
|
134757
|
+
if (!shouldRender) {
|
|
134758
|
+
if (incs && incs.length && source.parentElement) {
|
|
134759
|
+
const map = __siblingCounters.get(source.parentElement) || /* @__PURE__ */ new Map();
|
|
134760
|
+
for (const { name } of incs) {
|
|
134761
|
+
if (!name) continue;
|
|
134762
|
+
const baseWithSibs = withSiblingOverrides(source, counterCtx);
|
|
134763
|
+
const derived = deriveCounterCtxForPseudo(source, getComputedStyle(source, pseudo), baseWithSibs);
|
|
134764
|
+
const finalVal = derived.get(source, name);
|
|
134765
|
+
map.set(name, finalVal);
|
|
134766
|
+
}
|
|
134767
|
+
__siblingCounters.set(source.parentElement, map);
|
|
134768
|
+
}
|
|
134769
|
+
continue;
|
|
134770
|
+
}
|
|
134771
|
+
const pseudoEl = document.createElement("span");
|
|
134772
|
+
pseudoEl.dataset.snapdomPseudo = pseudo;
|
|
134773
|
+
pseudoEl.style.verticalAlign = "middle";
|
|
134774
|
+
pseudoEl.style.pointerEvents = "none";
|
|
134775
|
+
const snapshot = snapshotComputedStyle(style);
|
|
134776
|
+
const key = getStyleKey(snapshot, "span");
|
|
134777
|
+
sessionCache.styleMap.set(pseudoEl, key);
|
|
134778
|
+
if (isIconFont22 && cleanContent && cleanContent.length === 1) {
|
|
134779
|
+
const { dataUrl, width: w, height: h } = await iconToImage(cleanContent, fontFamily, fontWeight, fontSize, color);
|
|
134780
|
+
const imgEl = document.createElement("img");
|
|
134781
|
+
imgEl.src = dataUrl;
|
|
134782
|
+
imgEl.style = `height:${fontSize}px;width:${w / h * fontSize}px;object-fit:contain;`;
|
|
134783
|
+
pseudoEl.appendChild(imgEl);
|
|
134784
|
+
clone.dataset.snapdomHasIcon = "true";
|
|
134785
|
+
} else if (cleanContent && cleanContent.startsWith("url(")) {
|
|
134786
|
+
const rawUrl = extractURL(cleanContent);
|
|
134787
|
+
if (rawUrl?.trim()) {
|
|
134788
|
+
try {
|
|
134789
|
+
const imgEl = document.createElement("img");
|
|
134790
|
+
const dataUrl = await snapFetch(safeEncodeURI(rawUrl), { as: "dataURL", useProxy: options.useProxy });
|
|
134791
|
+
imgEl.src = dataUrl.data;
|
|
134792
|
+
imgEl.style = `width:${fontSize}px;height:auto;object-fit:contain;`;
|
|
134793
|
+
pseudoEl.appendChild(imgEl);
|
|
134794
|
+
} catch (e) {
|
|
134795
|
+
console.error(`[snapdom] Error in pseudo ${pseudo} for`, source, e);
|
|
134796
|
+
}
|
|
134797
|
+
}
|
|
134798
|
+
} else if (!isIconFont22 && hasExplicitContent) {
|
|
134799
|
+
pseudoEl.textContent = cleanContent;
|
|
134800
|
+
}
|
|
134801
|
+
pseudoEl.style.background = "none";
|
|
134802
|
+
if ("mask" in pseudoEl.style) {
|
|
134803
|
+
pseudoEl.style.mask = "none";
|
|
134804
|
+
}
|
|
134805
|
+
if (hasBg) {
|
|
134806
|
+
try {
|
|
134807
|
+
const bgSplits = splitBackgroundImage(bg);
|
|
134808
|
+
const newBgParts = await Promise.all(bgSplits.map(inlineSingleBackgroundEntry));
|
|
134809
|
+
pseudoEl.style.backgroundImage = newBgParts.join(", ");
|
|
134810
|
+
} catch (e) {
|
|
134811
|
+
console.warn(`[snapdom] Failed to inline background-image for ${pseudo}`, e);
|
|
134812
|
+
}
|
|
134813
|
+
}
|
|
134814
|
+
if (hasBgColor) pseudoEl.style.backgroundColor = bgColor;
|
|
134815
|
+
const hasContent2 = pseudoEl.childNodes.length > 0 || pseudoEl.textContent?.trim() !== "";
|
|
134816
|
+
const hasVisibleBox = hasContent2 || hasBg || hasBgColor || hasBorder || hasTransform;
|
|
134817
|
+
if (incs && incs.length && source.parentElement) {
|
|
134818
|
+
const map = __siblingCounters.get(source.parentElement) || /* @__PURE__ */ new Map();
|
|
134819
|
+
const baseWithSibs = withSiblingOverrides(source, counterCtx);
|
|
134820
|
+
const derived = deriveCounterCtxForPseudo(source, getComputedStyle(source, pseudo), baseWithSibs);
|
|
134821
|
+
for (const { name } of incs) {
|
|
134822
|
+
if (!name) continue;
|
|
134823
|
+
const finalVal = derived.get(source, name);
|
|
134824
|
+
map.set(name, finalVal);
|
|
134825
|
+
}
|
|
134826
|
+
__siblingCounters.set(source.parentElement, map);
|
|
134827
|
+
}
|
|
134828
|
+
if (!hasVisibleBox) continue;
|
|
134829
|
+
if (pseudo === "::before") {
|
|
134830
|
+
clone.insertBefore(pseudoEl, clone.firstChild);
|
|
134831
|
+
} else {
|
|
134832
|
+
clone.appendChild(pseudoEl);
|
|
134833
|
+
}
|
|
134834
|
+
} catch (e) {
|
|
134835
|
+
console.warn(`[snapdom] Failed to capture ${pseudo} for`, source, e);
|
|
134836
|
+
}
|
|
134837
|
+
}
|
|
134838
|
+
const sChildren = Array.from(source.children);
|
|
134839
|
+
const cChildren = Array.from(clone.children).filter((child) => !child.dataset.snapdomPseudo);
|
|
134840
|
+
for (let i = 0; i < Math.min(sChildren.length, cChildren.length); i++) {
|
|
134841
|
+
await inlinePseudoElements(sChildren[i], cChildren[i], sessionCache, options);
|
|
134842
|
+
}
|
|
134843
|
+
}
|
|
134844
|
+
|
|
134845
|
+
// src/modules/svgDefs.js
|
|
134846
|
+
function inlineExternalDefsAndSymbols(rootElement) {
|
|
134847
|
+
if (!rootElement) return;
|
|
134848
|
+
const usedIds = /* @__PURE__ */ new Set();
|
|
134849
|
+
rootElement.querySelectorAll("use").forEach((use) => {
|
|
134850
|
+
const href = use.getAttribute("xlink:href") || use.getAttribute("href");
|
|
134851
|
+
if (href && href.startsWith("#")) {
|
|
134852
|
+
usedIds.add(href.slice(1));
|
|
134853
|
+
}
|
|
134854
|
+
});
|
|
134855
|
+
if (!usedIds.size) return;
|
|
134856
|
+
const allGlobal = Array.from(document.querySelectorAll("svg > symbol, svg > defs"));
|
|
134857
|
+
const globalSymbols = allGlobal.filter((el) => el.tagName.toLowerCase() === "symbol");
|
|
134858
|
+
const globalDefs = allGlobal.filter((el) => el.tagName.toLowerCase() === "defs");
|
|
134859
|
+
let container = rootElement.querySelector("svg.inline-defs-container");
|
|
134860
|
+
if (!container) {
|
|
134861
|
+
container = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
134862
|
+
container.setAttribute("aria-hidden", "true");
|
|
134863
|
+
container.setAttribute("style", "position: absolute; width: 0; height: 0; overflow: hidden;");
|
|
134864
|
+
container.classList.add("inline-defs-container");
|
|
134865
|
+
rootElement.insertBefore(container, rootElement.firstChild);
|
|
134866
|
+
}
|
|
134867
|
+
const existingIds = /* @__PURE__ */ new Set();
|
|
134868
|
+
rootElement.querySelectorAll("symbol[id], defs > *[id]").forEach((el) => {
|
|
134869
|
+
existingIds.add(el.id);
|
|
134870
|
+
});
|
|
134871
|
+
usedIds.forEach((id) => {
|
|
134872
|
+
if (existingIds.has(id)) return;
|
|
134873
|
+
const symbol = globalSymbols.find((sym) => sym.id === id);
|
|
134874
|
+
if (symbol) {
|
|
134875
|
+
container.appendChild(symbol.cloneNode(true));
|
|
134876
|
+
existingIds.add(id);
|
|
134877
|
+
return;
|
|
134878
|
+
}
|
|
134879
|
+
for (const defs of globalDefs) {
|
|
134880
|
+
const defEl = defs.querySelector(`#${CSS.escape(id)}`);
|
|
134881
|
+
if (defEl) {
|
|
134882
|
+
let defsContainer = container.querySelector("defs");
|
|
134883
|
+
if (!defsContainer) {
|
|
134884
|
+
defsContainer = document.createElementNS("http://www.w3.org/2000/svg", "defs");
|
|
134885
|
+
container.appendChild(defsContainer);
|
|
134886
|
+
}
|
|
134887
|
+
defsContainer.appendChild(defEl.cloneNode(true));
|
|
134888
|
+
existingIds.add(id);
|
|
134889
|
+
break;
|
|
134890
|
+
}
|
|
134891
|
+
}
|
|
134892
|
+
});
|
|
134893
|
+
}
|
|
134894
|
+
|
|
134895
|
+
// src/modules/changeCSS.js
|
|
134896
|
+
function freezeSticky(originalRoot, cloneRoot) {
|
|
134897
|
+
if (!originalRoot || !cloneRoot) return;
|
|
134898
|
+
const scrollTop = originalRoot.scrollTop || 0;
|
|
134899
|
+
if (!scrollTop) return;
|
|
134900
|
+
if (getComputedStyle(cloneRoot).position === "static") {
|
|
134901
|
+
cloneRoot.style.position = "relative";
|
|
134902
|
+
}
|
|
134903
|
+
const rootRect = originalRoot.getBoundingClientRect();
|
|
134904
|
+
const viewportH = originalRoot.clientHeight;
|
|
134905
|
+
const PH_ATTR = "data-snap-ph";
|
|
134906
|
+
const walker = document.createTreeWalker(originalRoot, NodeFilter.SHOW_ELEMENT);
|
|
134907
|
+
while (walker.nextNode()) {
|
|
134908
|
+
const el = (
|
|
134909
|
+
/** @type {HTMLElement} */
|
|
134910
|
+
walker.currentNode
|
|
134911
|
+
);
|
|
134912
|
+
const cs = getComputedStyle(el);
|
|
134913
|
+
const pos = cs.position;
|
|
134914
|
+
if (pos !== "sticky" && pos !== "-webkit-sticky") continue;
|
|
134915
|
+
const topInit = _toPx(cs.top);
|
|
134916
|
+
const bottomInit = _toPx(cs.bottom);
|
|
134917
|
+
if (topInit == null && bottomInit == null) continue;
|
|
134918
|
+
const path = _pathOf(el, originalRoot);
|
|
134919
|
+
const cloneEl = _findByPathIgnoringPlaceholders(cloneRoot, path, PH_ATTR);
|
|
134920
|
+
if (!cloneEl) continue;
|
|
134921
|
+
const elRect = el.getBoundingClientRect();
|
|
134922
|
+
const widthPx = elRect.width;
|
|
134923
|
+
const heightPx = elRect.height;
|
|
134924
|
+
const leftPx = elRect.left - rootRect.left;
|
|
134925
|
+
if (!(widthPx > 0 && heightPx > 0)) continue;
|
|
134926
|
+
if (!Number.isFinite(leftPx)) continue;
|
|
134927
|
+
const topAbsPx = topInit != null ? topInit + scrollTop : scrollTop + (viewportH - heightPx - /** bottomInit non-null */
|
|
134928
|
+
bottomInit);
|
|
134929
|
+
if (!Number.isFinite(topAbsPx)) continue;
|
|
134930
|
+
const zParsed = Number.parseInt(cs.zIndex, 10);
|
|
134931
|
+
const hasZ = Number.isFinite(zParsed);
|
|
134932
|
+
const overlayZ = hasZ ? Math.max(zParsed, 1) + 1 : 2;
|
|
134933
|
+
const placeholderZ = hasZ ? zParsed - 1 : 0;
|
|
134934
|
+
const ph = cloneEl.cloneNode(false);
|
|
134935
|
+
ph.setAttribute(PH_ATTR, "1");
|
|
134936
|
+
ph.style.position = "sticky";
|
|
134937
|
+
ph.style.left = `${leftPx}px`;
|
|
134938
|
+
ph.style.top = `${topAbsPx}px`;
|
|
134939
|
+
ph.style.width = `${widthPx}px`;
|
|
134940
|
+
ph.style.height = `${heightPx}px`;
|
|
134941
|
+
ph.style.visibility = "hidden";
|
|
134942
|
+
ph.style.zIndex = String(placeholderZ);
|
|
134943
|
+
ph.style.overflow = "hidden";
|
|
134944
|
+
ph.style.background = "transparent";
|
|
134945
|
+
ph.style.boxShadow = "none";
|
|
134946
|
+
ph.style.filter = "none";
|
|
134947
|
+
cloneEl.parentElement?.insertBefore(ph, cloneEl);
|
|
134948
|
+
cloneEl.style.position = "absolute";
|
|
134949
|
+
cloneEl.style.left = `${leftPx}px`;
|
|
134950
|
+
cloneEl.style.top = `${topAbsPx}px`;
|
|
134951
|
+
cloneEl.style.bottom = "auto";
|
|
134952
|
+
cloneEl.style.zIndex = String(overlayZ);
|
|
134953
|
+
cloneEl.style.pointerEvents = "none";
|
|
134954
|
+
}
|
|
134955
|
+
}
|
|
134956
|
+
function _toPx(v) {
|
|
134957
|
+
if (!v || v === "auto") return null;
|
|
134958
|
+
const n = Number.parseFloat(v);
|
|
134959
|
+
return Number.isFinite(n) ? n : null;
|
|
134960
|
+
}
|
|
134961
|
+
function _pathOf(el, root) {
|
|
134962
|
+
const path = [];
|
|
134963
|
+
for (let cur = el; cur && cur !== root; ) {
|
|
134964
|
+
const p = cur.parentElement;
|
|
134965
|
+
if (!p) break;
|
|
134966
|
+
path.push(Array.prototype.indexOf.call(p.children, cur));
|
|
134967
|
+
cur = p;
|
|
134968
|
+
}
|
|
134969
|
+
return path.reverse();
|
|
134970
|
+
}
|
|
134971
|
+
function _findByPathIgnoringPlaceholders(root, path, phAttr) {
|
|
134972
|
+
let cur = root;
|
|
134973
|
+
for (let i = 0; i < path.length; i++) {
|
|
134974
|
+
const kids = _childrenWithoutPlaceholders(cur, phAttr);
|
|
134975
|
+
cur = /** @type {HTMLElement|undefined} */
|
|
134976
|
+
kids[path[i]];
|
|
134977
|
+
if (!cur) return null;
|
|
134978
|
+
}
|
|
134979
|
+
return cur instanceof HTMLElement ? cur : null;
|
|
134980
|
+
}
|
|
134981
|
+
function _childrenWithoutPlaceholders(el, phAttr) {
|
|
134982
|
+
const out = [];
|
|
134983
|
+
const ch = el.children;
|
|
134984
|
+
for (let i = 0; i < ch.length; i++) {
|
|
134985
|
+
const c = ch[i];
|
|
134986
|
+
if (!c.hasAttribute(phAttr)) out.push(c);
|
|
134987
|
+
}
|
|
134988
|
+
return out;
|
|
134989
|
+
}
|
|
134990
|
+
|
|
134991
|
+
// src/core/prepare.js
|
|
134992
|
+
async function prepareClone(element, options = {}) {
|
|
134993
|
+
const sessionCache = {
|
|
134994
|
+
styleMap: cache.session.styleMap,
|
|
134995
|
+
styleCache: cache.session.styleCache,
|
|
134996
|
+
nodeMap: cache.session.nodeMap
|
|
134997
|
+
};
|
|
134998
|
+
let clone;
|
|
134999
|
+
let classCSS = "";
|
|
135000
|
+
let shadowScopedCSS = "";
|
|
135001
|
+
stabilizeLayout(element);
|
|
135002
|
+
try {
|
|
135003
|
+
inlineExternalDefsAndSymbols(element);
|
|
135004
|
+
} catch (e) {
|
|
135005
|
+
console.warn("inlineExternal defs or symbol failed:", e);
|
|
135006
|
+
}
|
|
135007
|
+
try {
|
|
135008
|
+
clone = await deepClone(element, sessionCache, options, element);
|
|
135009
|
+
} catch (e) {
|
|
135010
|
+
console.warn("deepClone failed:", e);
|
|
135011
|
+
throw e;
|
|
135012
|
+
}
|
|
135013
|
+
try {
|
|
135014
|
+
await inlinePseudoElements(element, clone, sessionCache, options);
|
|
135015
|
+
} catch (e) {
|
|
135016
|
+
console.warn("inlinePseudoElements failed:", e);
|
|
135017
|
+
}
|
|
135018
|
+
await resolveBlobUrlsInTree(clone);
|
|
135019
|
+
try {
|
|
135020
|
+
const styleNodes = clone.querySelectorAll("style[data-sd]");
|
|
135021
|
+
for (const s of styleNodes) {
|
|
135022
|
+
shadowScopedCSS += s.textContent || "";
|
|
135023
|
+
s.remove();
|
|
135024
|
+
}
|
|
135025
|
+
} catch {
|
|
135026
|
+
}
|
|
135027
|
+
const keyToClass = generateCSSClasses(sessionCache.styleMap);
|
|
135028
|
+
classCSS = Array.from(keyToClass.entries()).map(([key, className]) => `.${className}{${key}}`).join("");
|
|
135029
|
+
classCSS = shadowScopedCSS + classCSS;
|
|
135030
|
+
for (const [node, key] of sessionCache.styleMap.entries()) {
|
|
135031
|
+
if (node.tagName === "STYLE") continue;
|
|
135032
|
+
if (node.getRootNode && node.getRootNode() instanceof ShadowRoot) {
|
|
135033
|
+
node.setAttribute("style", key.replace(/;/g, "; "));
|
|
135034
|
+
continue;
|
|
135035
|
+
}
|
|
135036
|
+
const className = keyToClass.get(key);
|
|
135037
|
+
if (className) node.classList.add(className);
|
|
135038
|
+
const bgImage = node.style?.backgroundImage;
|
|
135039
|
+
const hasIcon = node.dataset?.snapdomHasIcon;
|
|
135040
|
+
if (bgImage && bgImage !== "none") node.style.backgroundImage = bgImage;
|
|
135041
|
+
if (hasIcon) {
|
|
135042
|
+
node.style.verticalAlign = "middle";
|
|
135043
|
+
node.style.display = "inline";
|
|
135044
|
+
}
|
|
135045
|
+
}
|
|
135046
|
+
for (const [cloneNode, originalNode] of sessionCache.nodeMap.entries()) {
|
|
135047
|
+
const scrollX = originalNode.scrollLeft;
|
|
135048
|
+
const scrollY = originalNode.scrollTop;
|
|
135049
|
+
const hasScroll = scrollX || scrollY;
|
|
135050
|
+
if (hasScroll && cloneNode instanceof HTMLElement) {
|
|
135051
|
+
cloneNode.style.overflow = "hidden";
|
|
135052
|
+
cloneNode.style.scrollbarWidth = "none";
|
|
135053
|
+
cloneNode.style.msOverflowStyle = "none";
|
|
135054
|
+
const inner = document.createElement("div");
|
|
135055
|
+
inner.style.transform = `translate(${-scrollX}px, ${-scrollY}px)`;
|
|
135056
|
+
inner.style.willChange = "transform";
|
|
135057
|
+
inner.style.display = "inline-block";
|
|
135058
|
+
inner.style.width = "100%";
|
|
135059
|
+
while (cloneNode.firstChild) {
|
|
135060
|
+
inner.appendChild(cloneNode.firstChild);
|
|
135061
|
+
}
|
|
135062
|
+
cloneNode.appendChild(inner);
|
|
135063
|
+
}
|
|
135064
|
+
}
|
|
135065
|
+
const contentRoot = clone instanceof HTMLElement && clone.firstElementChild instanceof HTMLElement ? clone.firstElementChild : clone;
|
|
135066
|
+
freezeSticky(element, contentRoot);
|
|
135067
|
+
if (element === sessionCache.nodeMap.get(clone)) {
|
|
135068
|
+
const computed = sessionCache.styleCache.get(element) || window.getComputedStyle(element);
|
|
135069
|
+
sessionCache.styleCache.set(element, computed);
|
|
135070
|
+
const transform = stripTranslate(computed.transform);
|
|
135071
|
+
clone.style.margin = "0";
|
|
135072
|
+
clone.style.top = "auto";
|
|
135073
|
+
clone.style.left = "auto";
|
|
135074
|
+
clone.style.right = "auto";
|
|
135075
|
+
clone.style.bottom = "auto";
|
|
135076
|
+
clone.style.animation = "none";
|
|
135077
|
+
clone.style.transition = "none";
|
|
135078
|
+
clone.style.willChange = "auto";
|
|
135079
|
+
clone.style.float = "none";
|
|
135080
|
+
clone.style.clear = "none";
|
|
135081
|
+
clone.style.transform = transform || "";
|
|
135082
|
+
}
|
|
135083
|
+
for (const [cloneNode, originalNode] of sessionCache.nodeMap.entries()) {
|
|
135084
|
+
if (originalNode.tagName === "PRE") {
|
|
135085
|
+
cloneNode.style.marginTop = "0";
|
|
135086
|
+
cloneNode.style.marginBlockStart = "0";
|
|
135087
|
+
}
|
|
135088
|
+
}
|
|
135089
|
+
return { clone, classCSS, styleCache: sessionCache.styleCache };
|
|
135090
|
+
}
|
|
135091
|
+
function stabilizeLayout(element) {
|
|
135092
|
+
const style = getComputedStyle(element);
|
|
135093
|
+
const outlineStyle = style.outlineStyle;
|
|
135094
|
+
const outlineWidth = style.outlineWidth;
|
|
135095
|
+
const borderStyle = style.borderStyle;
|
|
135096
|
+
const borderWidth = style.borderWidth;
|
|
135097
|
+
const outlineVisible = outlineStyle !== "none" && parseFloat(outlineWidth) > 0;
|
|
135098
|
+
const borderAbsent = borderStyle === "none" || parseFloat(borderWidth) === 0;
|
|
135099
|
+
if (outlineVisible && borderAbsent) {
|
|
135100
|
+
element.style.border = `${outlineWidth} solid transparent`;
|
|
135101
|
+
}
|
|
135102
|
+
}
|
|
135103
|
+
var _blobToDataUrlCache = /* @__PURE__ */ new Map();
|
|
135104
|
+
async function blobUrlToDataUrl(blobUrl) {
|
|
135105
|
+
if (cache.resource?.has(blobUrl)) return cache.resource.get(blobUrl);
|
|
135106
|
+
if (_blobToDataUrlCache.has(blobUrl)) return _blobToDataUrlCache.get(blobUrl);
|
|
135107
|
+
const p = (async () => {
|
|
135108
|
+
const r = await snapFetch(blobUrl, { as: "dataURL", silent: true });
|
|
135109
|
+
if (!r.ok || typeof r.data !== "string") {
|
|
135110
|
+
throw new Error(`[snapDOM] Failed to read blob URL: ${blobUrl}`);
|
|
135111
|
+
}
|
|
135112
|
+
cache.resource?.set(blobUrl, r.data);
|
|
135113
|
+
return r.data;
|
|
135114
|
+
})();
|
|
135115
|
+
_blobToDataUrlCache.set(blobUrl, p);
|
|
135116
|
+
try {
|
|
135117
|
+
const data = await p;
|
|
135118
|
+
_blobToDataUrlCache.set(blobUrl, data);
|
|
135119
|
+
return data;
|
|
135120
|
+
} catch (e) {
|
|
135121
|
+
_blobToDataUrlCache.delete(blobUrl);
|
|
135122
|
+
throw e;
|
|
135123
|
+
}
|
|
135124
|
+
}
|
|
135125
|
+
var BLOB_URL_RE = /\bblob:[^)"'\s]+/g;
|
|
135126
|
+
async function replaceBlobUrlsInCssText(cssText) {
|
|
135127
|
+
if (!cssText || cssText.indexOf("blob:") === -1) return cssText;
|
|
135128
|
+
const uniques = Array.from(new Set(cssText.match(BLOB_URL_RE) || []));
|
|
135129
|
+
if (uniques.length === 0) return cssText;
|
|
135130
|
+
let out = cssText;
|
|
135131
|
+
for (const u of uniques) {
|
|
135132
|
+
try {
|
|
135133
|
+
const d = await blobUrlToDataUrl(u);
|
|
135134
|
+
out = out.split(u).join(d);
|
|
135135
|
+
} catch {
|
|
135136
|
+
}
|
|
135137
|
+
}
|
|
135138
|
+
return out;
|
|
135139
|
+
}
|
|
135140
|
+
function isBlobUrl(u) {
|
|
135141
|
+
return typeof u === "string" && u.startsWith("blob:");
|
|
135142
|
+
}
|
|
135143
|
+
function parseSrcset(srcset) {
|
|
135144
|
+
return (srcset || "").split(",").map((s) => s.trim()).filter(Boolean).map((item) => {
|
|
135145
|
+
const m = item.match(/^(\S+)(\s+.+)?$/);
|
|
135146
|
+
return m ? { url: m[1], desc: m[2] || "" } : null;
|
|
135147
|
+
}).filter(Boolean);
|
|
135148
|
+
}
|
|
135149
|
+
function stringifySrcset(parts) {
|
|
135150
|
+
return parts.map((p) => p.desc ? `${p.url} ${p.desc.trim()}` : p.url).join(", ");
|
|
135151
|
+
}
|
|
135152
|
+
async function resolveBlobUrlsInTree(root) {
|
|
135153
|
+
if (!root) return;
|
|
135154
|
+
const imgs = root.querySelectorAll ? root.querySelectorAll("img") : [];
|
|
135155
|
+
for (const img of imgs) {
|
|
135156
|
+
try {
|
|
135157
|
+
const srcAttr = img.getAttribute("src");
|
|
135158
|
+
const effective = srcAttr || img.currentSrc || "";
|
|
135159
|
+
if (isBlobUrl(effective)) {
|
|
135160
|
+
const data = await blobUrlToDataUrl(effective);
|
|
135161
|
+
img.setAttribute("src", data);
|
|
135162
|
+
}
|
|
135163
|
+
const srcset = img.getAttribute("srcset");
|
|
135164
|
+
if (srcset && srcset.includes("blob:")) {
|
|
135165
|
+
const parts = parseSrcset(srcset);
|
|
135166
|
+
let changed = false;
|
|
135167
|
+
for (const p of parts) {
|
|
135168
|
+
if (isBlobUrl(p.url)) {
|
|
135169
|
+
try {
|
|
135170
|
+
p.url = await blobUrlToDataUrl(p.url);
|
|
135171
|
+
changed = true;
|
|
135172
|
+
} catch {
|
|
135173
|
+
}
|
|
135174
|
+
}
|
|
135175
|
+
}
|
|
135176
|
+
if (changed) img.setAttribute("srcset", stringifySrcset(parts));
|
|
135177
|
+
}
|
|
135178
|
+
} catch {
|
|
135179
|
+
}
|
|
135180
|
+
}
|
|
135181
|
+
const svgImages = root.querySelectorAll ? root.querySelectorAll("image") : [];
|
|
135182
|
+
for (const node of svgImages) {
|
|
135183
|
+
try {
|
|
135184
|
+
const XLINK_NS = "http://www.w3.org/1999/xlink";
|
|
135185
|
+
const href = node.getAttribute("href") || node.getAttributeNS?.(XLINK_NS, "href");
|
|
135186
|
+
if (isBlobUrl(href)) {
|
|
135187
|
+
const d = await blobUrlToDataUrl(href);
|
|
135188
|
+
node.setAttribute("href", d);
|
|
135189
|
+
node.removeAttributeNS?.(XLINK_NS, "href");
|
|
135190
|
+
}
|
|
135191
|
+
} catch {
|
|
135192
|
+
}
|
|
135193
|
+
}
|
|
135194
|
+
const styled = root.querySelectorAll ? root.querySelectorAll("[style*='blob:']") : [];
|
|
135195
|
+
for (const el of styled) {
|
|
135196
|
+
try {
|
|
135197
|
+
const styleText = el.getAttribute("style");
|
|
135198
|
+
if (styleText && styleText.includes("blob:")) {
|
|
135199
|
+
const replaced = await replaceBlobUrlsInCssText(styleText);
|
|
135200
|
+
el.setAttribute("style", replaced);
|
|
135201
|
+
}
|
|
135202
|
+
} catch {
|
|
135203
|
+
}
|
|
135204
|
+
}
|
|
135205
|
+
const styleTags = root.querySelectorAll ? root.querySelectorAll("style") : [];
|
|
135206
|
+
for (const s of styleTags) {
|
|
135207
|
+
try {
|
|
135208
|
+
const css = s.textContent || "";
|
|
135209
|
+
if (css.includes("blob:")) {
|
|
135210
|
+
s.textContent = await replaceBlobUrlsInCssText(css);
|
|
135211
|
+
}
|
|
135212
|
+
} catch {
|
|
135213
|
+
}
|
|
135214
|
+
}
|
|
135215
|
+
const urlAttrs = ["poster"];
|
|
135216
|
+
for (const attr of urlAttrs) {
|
|
135217
|
+
const nodes = root.querySelectorAll ? root.querySelectorAll(`[${attr}^='blob:']`) : [];
|
|
135218
|
+
for (const n of nodes) {
|
|
135219
|
+
try {
|
|
135220
|
+
const u = n.getAttribute(attr);
|
|
135221
|
+
if (isBlobUrl(u)) {
|
|
135222
|
+
n.setAttribute(attr, await blobUrlToDataUrl(u));
|
|
135223
|
+
}
|
|
135224
|
+
} catch {
|
|
135225
|
+
}
|
|
135226
|
+
}
|
|
135227
|
+
}
|
|
135228
|
+
}
|
|
135229
|
+
|
|
135230
|
+
// src/modules/images.js
|
|
135231
|
+
async function inlineImages(clone, options = {}) {
|
|
135232
|
+
const imgs = Array.from(clone.querySelectorAll("img"));
|
|
135233
|
+
const processImg = async (img) => {
|
|
135234
|
+
if (!img.getAttribute("src")) {
|
|
135235
|
+
const eff = img.currentSrc || img.src || "";
|
|
135236
|
+
if (eff) img.setAttribute("src", eff);
|
|
135237
|
+
}
|
|
135238
|
+
img.removeAttribute("srcset");
|
|
135239
|
+
img.removeAttribute("sizes");
|
|
135240
|
+
const src = img.src || "";
|
|
135241
|
+
if (!src) return;
|
|
135242
|
+
const r = await snapFetch(src, { as: "dataURL", useProxy: options.useProxy });
|
|
135243
|
+
if (r.ok && typeof r.data === "string" && r.data.startsWith("data:")) {
|
|
135244
|
+
img.src = r.data;
|
|
135245
|
+
if (!img.width) img.width = img.naturalWidth || 100;
|
|
135246
|
+
if (!img.height) img.height = img.naturalHeight || 100;
|
|
135247
|
+
return;
|
|
135248
|
+
}
|
|
135249
|
+
const { fallbackURL } = options || {};
|
|
135250
|
+
if (fallbackURL) {
|
|
135251
|
+
try {
|
|
135252
|
+
const dsW = parseInt(img.dataset?.snapdomWidth || "", 10) || 0;
|
|
135253
|
+
const dsH = parseInt(img.dataset?.snapdomHeight || "", 10) || 0;
|
|
135254
|
+
const attrW = parseInt(img.getAttribute("width") || "", 10) || 0;
|
|
135255
|
+
const attrH = parseInt(img.getAttribute("height") || "", 10) || 0;
|
|
135256
|
+
const styleW = parseFloat(img.style?.width || "") || 0;
|
|
135257
|
+
const styleH = parseFloat(img.style?.height || "") || 0;
|
|
135258
|
+
const fbW = dsW || styleW || attrW || img.width || void 0;
|
|
135259
|
+
const fbH = dsH || styleH || attrH || img.height || void 0;
|
|
135260
|
+
const fallbackUrl = typeof fallbackURL === "function" ? await fallbackURL({ width: fbW, height: fbH, src, element: img }) : fallbackURL;
|
|
135261
|
+
if (fallbackUrl) {
|
|
135262
|
+
const fallbackData = await snapFetch(fallbackUrl, { as: "dataURL", useProxy: options.useProxy });
|
|
135263
|
+
img.src = fallbackData.data;
|
|
135264
|
+
if (!img.width && fbW) img.width = fbW;
|
|
135265
|
+
if (!img.height && fbH) img.height = fbH;
|
|
135266
|
+
if (!img.width) img.width = img.naturalWidth || 100;
|
|
135267
|
+
if (!img.height) img.height = img.naturalHeight || 100;
|
|
135268
|
+
return;
|
|
135269
|
+
}
|
|
135270
|
+
} catch {
|
|
135271
|
+
}
|
|
135272
|
+
}
|
|
135273
|
+
const w = img.width || img.naturalWidth || 100;
|
|
135274
|
+
const h = img.height || img.naturalHeight || 100;
|
|
135275
|
+
if (options.placeholders !== false) {
|
|
135276
|
+
const fallback = document.createElement("div");
|
|
135277
|
+
fallback.style.cssText = [
|
|
135278
|
+
`width:${w}px`,
|
|
135279
|
+
`height:${h}px`,
|
|
135280
|
+
"background:#ccc",
|
|
135281
|
+
"display:inline-block",
|
|
135282
|
+
"text-align:center",
|
|
135283
|
+
`line-height:${h}px`,
|
|
135284
|
+
"color:#666",
|
|
135285
|
+
"font-size:12px",
|
|
135286
|
+
"overflow:hidden"
|
|
135287
|
+
].join(";");
|
|
135288
|
+
fallback.textContent = "img";
|
|
135289
|
+
img.replaceWith(fallback);
|
|
135290
|
+
} else {
|
|
135291
|
+
const spacer = document.createElement("div");
|
|
135292
|
+
spacer.style.cssText = `display:inline-block;width:${w}px;height:${h}px;visibility:hidden;`;
|
|
135293
|
+
img.replaceWith(spacer);
|
|
135294
|
+
}
|
|
135295
|
+
};
|
|
135296
|
+
for (let i = 0; i < imgs.length; i += 4) {
|
|
135297
|
+
const group = imgs.slice(i, i + 4).map(processImg);
|
|
135298
|
+
await Promise.allSettled(group);
|
|
135299
|
+
}
|
|
135300
|
+
}
|
|
135301
|
+
|
|
135302
|
+
// src/modules/background.js
|
|
135303
|
+
async function inlineBackgroundImages(source, clone, styleCache, options = {}) {
|
|
135304
|
+
const queue = [[source, clone]];
|
|
135305
|
+
const URL_PROPS = [
|
|
135306
|
+
"background-image",
|
|
135307
|
+
// Mask shorthands & images (both standard and WebKit)
|
|
135308
|
+
"mask",
|
|
135309
|
+
"mask-image",
|
|
135310
|
+
"-webkit-mask",
|
|
135311
|
+
"-webkit-mask-image",
|
|
135312
|
+
// Mask sources (rare, but keep)
|
|
135313
|
+
"mask-source",
|
|
135314
|
+
"mask-box-image-source",
|
|
135315
|
+
"mask-border-source",
|
|
135316
|
+
"-webkit-mask-box-image-source",
|
|
135317
|
+
// Border image
|
|
135318
|
+
"border-image",
|
|
135319
|
+
"border-image-source"
|
|
135320
|
+
];
|
|
135321
|
+
const MASK_LAYOUT_PROPS = [
|
|
135322
|
+
"mask-position",
|
|
135323
|
+
"mask-size",
|
|
135324
|
+
"mask-repeat",
|
|
135325
|
+
// WebKit variants
|
|
135326
|
+
"-webkit-mask-position",
|
|
135327
|
+
"-webkit-mask-size",
|
|
135328
|
+
"-webkit-mask-repeat",
|
|
135329
|
+
// Extra (optional but helpful across engines)
|
|
135330
|
+
"mask-origin",
|
|
135331
|
+
"mask-clip",
|
|
135332
|
+
"-webkit-mask-origin",
|
|
135333
|
+
"-webkit-mask-clip",
|
|
135334
|
+
// Some engines expose X/Y position separately:
|
|
135335
|
+
"-webkit-mask-position-x",
|
|
135336
|
+
"-webkit-mask-position-y"
|
|
135337
|
+
];
|
|
135338
|
+
const BORDER_AUX_PROPS = [
|
|
135339
|
+
"border-image-slice",
|
|
135340
|
+
"border-image-width",
|
|
135341
|
+
"border-image-outset",
|
|
135342
|
+
"border-image-repeat"
|
|
135343
|
+
];
|
|
135344
|
+
while (queue.length) {
|
|
135345
|
+
const [srcNode, cloneNode] = queue.shift();
|
|
135346
|
+
const style = styleCache.get(srcNode) || getStyle(srcNode);
|
|
135347
|
+
if (!styleCache.has(srcNode)) styleCache.set(srcNode, style);
|
|
135348
|
+
const hasBorderImage = (() => {
|
|
135349
|
+
const bi = style.getPropertyValue("border-image");
|
|
135350
|
+
const bis = style.getPropertyValue("border-image-source");
|
|
135351
|
+
return bi && bi !== "none" || bis && bis !== "none";
|
|
135352
|
+
})();
|
|
135353
|
+
for (const prop of URL_PROPS) {
|
|
135354
|
+
const val = style.getPropertyValue(prop);
|
|
135355
|
+
if (!val || val === "none") continue;
|
|
135356
|
+
const splits = splitBackgroundImage(val);
|
|
135357
|
+
const inlined = await Promise.all(
|
|
135358
|
+
splits.map((entry) => inlineSingleBackgroundEntry(entry, options))
|
|
135359
|
+
);
|
|
135360
|
+
if (inlined.some((p) => p && p !== "none" && !/^url\(undefined/.test(p))) {
|
|
135361
|
+
cloneNode.style.setProperty(prop, inlined.join(", "));
|
|
135362
|
+
}
|
|
135363
|
+
}
|
|
135364
|
+
for (const prop of MASK_LAYOUT_PROPS) {
|
|
135365
|
+
const val = style.getPropertyValue(prop);
|
|
135366
|
+
if (!val || val === "initial") continue;
|
|
135367
|
+
cloneNode.style.setProperty(prop, val);
|
|
135368
|
+
}
|
|
135369
|
+
if (hasBorderImage) {
|
|
135370
|
+
for (const prop of BORDER_AUX_PROPS) {
|
|
135371
|
+
const val = style.getPropertyValue(prop);
|
|
135372
|
+
if (!val || val === "initial") continue;
|
|
135373
|
+
cloneNode.style.setProperty(prop, val);
|
|
135374
|
+
}
|
|
135375
|
+
}
|
|
135376
|
+
const sChildren = Array.from(srcNode.children);
|
|
135377
|
+
const cChildren = Array.from(cloneNode.children);
|
|
135378
|
+
for (let i = 0; i < Math.min(sChildren.length, cChildren.length); i++) {
|
|
135379
|
+
queue.push([sChildren[i], cChildren[i]]);
|
|
135380
|
+
}
|
|
135381
|
+
}
|
|
135382
|
+
}
|
|
135383
|
+
|
|
135384
|
+
// src/modules/lineClamp.js
|
|
135385
|
+
function lineClamp(el) {
|
|
135386
|
+
if (!el) return () => {
|
|
135387
|
+
};
|
|
135388
|
+
const lines = getClamp(el);
|
|
135389
|
+
if (lines <= 0) return () => {
|
|
135390
|
+
};
|
|
135391
|
+
if (!isPlainTextContainer(el)) return () => {
|
|
135392
|
+
};
|
|
135393
|
+
const cs = getComputedStyle(el);
|
|
135394
|
+
const targetH = Math.round(usedLineHeightPx(cs) * lines + vpad(cs));
|
|
135395
|
+
const original = el.textContent ?? "";
|
|
135396
|
+
const prevText = original;
|
|
135397
|
+
if (el.scrollHeight <= targetH + 0.5) {
|
|
135398
|
+
return () => {
|
|
135399
|
+
};
|
|
135400
|
+
}
|
|
135401
|
+
let lo = 0, hi = original.length, best = -1;
|
|
135402
|
+
while (lo <= hi) {
|
|
135403
|
+
const mid = lo + hi >> 1;
|
|
135404
|
+
el.textContent = original.slice(0, mid) + "\u2026";
|
|
135405
|
+
if (el.scrollHeight <= targetH + 0.5) {
|
|
135406
|
+
best = mid;
|
|
135407
|
+
lo = mid + 1;
|
|
135408
|
+
} else {
|
|
135409
|
+
hi = mid - 1;
|
|
135410
|
+
}
|
|
135411
|
+
}
|
|
135412
|
+
el.textContent = (best >= 0 ? original.slice(0, best) : "") + "\u2026";
|
|
135413
|
+
return () => {
|
|
135414
|
+
el.textContent = prevText;
|
|
135415
|
+
};
|
|
135416
|
+
}
|
|
135417
|
+
function getClamp(el) {
|
|
135418
|
+
const cs = getComputedStyle(el);
|
|
135419
|
+
let v = cs.getPropertyValue("-webkit-line-clamp") || cs.getPropertyValue("line-clamp");
|
|
135420
|
+
v = (v || "").trim();
|
|
135421
|
+
const n = parseInt(v, 10);
|
|
135422
|
+
return Number.isFinite(n) && n > 0 ? n : 0;
|
|
135423
|
+
}
|
|
135424
|
+
function usedLineHeightPx(cs) {
|
|
135425
|
+
const lh = (cs.lineHeight || "").trim();
|
|
135426
|
+
const fs = parseFloat(cs.fontSize) || 16;
|
|
135427
|
+
if (!lh || lh === "normal") return Math.round(fs * 1.2);
|
|
135428
|
+
if (lh.endsWith("px")) return parseFloat(lh);
|
|
135429
|
+
if (/^\d+(\.\d+)?$/.test(lh)) return Math.round(parseFloat(lh) * fs);
|
|
135430
|
+
if (lh.endsWith("%")) return Math.round(parseFloat(lh) / 100 * fs);
|
|
135431
|
+
return Math.round(fs * 1.2);
|
|
135432
|
+
}
|
|
135433
|
+
function vpad(cs) {
|
|
135434
|
+
return (parseFloat(cs.paddingTop) || 0) + (parseFloat(cs.paddingBottom) || 0);
|
|
135435
|
+
}
|
|
135436
|
+
function isPlainTextContainer(el) {
|
|
135437
|
+
if (el.childElementCount > 0) return false;
|
|
135438
|
+
return Array.from(el.childNodes).some((n) => n.nodeType === Node.TEXT_NODE);
|
|
135439
|
+
}
|
|
135440
|
+
|
|
135441
|
+
// src/core/capture.js
|
|
135442
|
+
function stripRootShadows(originalEl, cloneRoot) {
|
|
135443
|
+
if (!originalEl || !cloneRoot || !cloneRoot.style) return;
|
|
135444
|
+
const cs = getComputedStyle(originalEl);
|
|
135445
|
+
try {
|
|
135446
|
+
cloneRoot.style.boxShadow = "none";
|
|
135447
|
+
} catch {
|
|
135448
|
+
}
|
|
135449
|
+
try {
|
|
135450
|
+
cloneRoot.style.textShadow = "none";
|
|
135451
|
+
} catch {
|
|
135452
|
+
}
|
|
135453
|
+
try {
|
|
135454
|
+
cloneRoot.style.outline = "none";
|
|
135455
|
+
} catch {
|
|
135456
|
+
}
|
|
135457
|
+
const f = cs.filter || "";
|
|
135458
|
+
const cleaned = f.replace(/\bblur\([^()]*\)\s*/gi, "").replace(/\bdrop-shadow\([^()]*\)\s*/gi, "").trim().replace(/\s+/g, " ");
|
|
135459
|
+
try {
|
|
135460
|
+
cloneRoot.style.filter = cleaned.length ? cleaned : "none";
|
|
135461
|
+
} catch {
|
|
135462
|
+
}
|
|
135463
|
+
}
|
|
135464
|
+
async function captureDOM(element, options) {
|
|
135465
|
+
if (!element) throw new Error("Element cannot be null or undefined");
|
|
135466
|
+
applyCachePolicy(options.cache);
|
|
135467
|
+
const fast = options.fast;
|
|
135468
|
+
const straighten = !!options.straighten;
|
|
135469
|
+
const noShadows = !!options.noShadows;
|
|
135470
|
+
let clone, classCSS, styleCache;
|
|
135471
|
+
let fontsCSS = "";
|
|
135472
|
+
let baseCSS = "";
|
|
135473
|
+
let dataURL;
|
|
135474
|
+
let svgString;
|
|
135475
|
+
let rootTransform2D = null;
|
|
135476
|
+
const undoClamp = lineClamp(element);
|
|
135477
|
+
try {
|
|
135478
|
+
({ clone, classCSS, styleCache } = await prepareClone(element, options));
|
|
135479
|
+
if (straighten && clone) {
|
|
135480
|
+
rootTransform2D = normalizeRootTransforms(element, clone);
|
|
135481
|
+
}
|
|
135482
|
+
if (noShadows && clone) {
|
|
135483
|
+
stripRootShadows(element, clone);
|
|
135484
|
+
}
|
|
135485
|
+
} finally {
|
|
135486
|
+
undoClamp();
|
|
135487
|
+
}
|
|
135488
|
+
await new Promise((resolve) => {
|
|
135489
|
+
idle(async () => {
|
|
135490
|
+
await inlineImages(clone, options);
|
|
135491
|
+
resolve();
|
|
135492
|
+
}, { fast });
|
|
135493
|
+
});
|
|
135494
|
+
await new Promise((resolve) => {
|
|
135495
|
+
idle(async () => {
|
|
135496
|
+
await inlineBackgroundImages(element, clone, styleCache, options);
|
|
135497
|
+
resolve();
|
|
135498
|
+
}, { fast });
|
|
135499
|
+
});
|
|
135500
|
+
if (options.embedFonts) {
|
|
135501
|
+
await new Promise((resolve) => {
|
|
135502
|
+
idle(async () => {
|
|
135503
|
+
const required = collectUsedFontVariants(element);
|
|
135504
|
+
const usedCodepoints = collectUsedCodepoints(element);
|
|
135505
|
+
if (isSafari()) {
|
|
135506
|
+
const families = new Set(
|
|
135507
|
+
Array.from(required).map((k) => String(k).split("__")[0]).filter(Boolean)
|
|
135508
|
+
);
|
|
135509
|
+
await ensureFontsReady(families, 1);
|
|
135510
|
+
}
|
|
135511
|
+
fontsCSS = await embedCustomFonts({
|
|
135512
|
+
required,
|
|
135513
|
+
usedCodepoints,
|
|
135514
|
+
exclude: options.excludeFonts,
|
|
135515
|
+
useProxy: options.useProxy
|
|
135516
|
+
});
|
|
135517
|
+
resolve();
|
|
135518
|
+
}, { fast });
|
|
135519
|
+
});
|
|
135520
|
+
}
|
|
135521
|
+
const usedTags = collectUsedTagNames(clone).sort();
|
|
135522
|
+
const tagKey = usedTags.join(",");
|
|
135523
|
+
if (cache.baseStyle.has(tagKey)) {
|
|
135524
|
+
baseCSS = cache.baseStyle.get(tagKey);
|
|
135525
|
+
} else {
|
|
135526
|
+
await new Promise((resolve) => {
|
|
135527
|
+
idle(() => {
|
|
135528
|
+
baseCSS = generateDedupedBaseCSS(usedTags);
|
|
135529
|
+
cache.baseStyle.set(tagKey, baseCSS);
|
|
135530
|
+
resolve();
|
|
135531
|
+
}, { fast });
|
|
135532
|
+
});
|
|
135533
|
+
}
|
|
135534
|
+
await new Promise((resolve) => {
|
|
135535
|
+
idle(() => {
|
|
135536
|
+
const csEl = getComputedStyle(element);
|
|
135537
|
+
function parseFilterDropShadows(cs) {
|
|
135538
|
+
const raw = `${cs.filter || ""} ${cs.webkitFilter || ""}`.trim();
|
|
135539
|
+
if (!raw || raw === "none") {
|
|
135540
|
+
return { bleed: { top: 0, right: 0, bottom: 0, left: 0 }, has: false };
|
|
135541
|
+
}
|
|
135542
|
+
const tokens = raw.match(/drop-shadow\((?:[^()]|\([^()]*\))*\)/gi) || [];
|
|
135543
|
+
let t = 0, r = 0, b = 0, l = 0;
|
|
135544
|
+
let found = false;
|
|
135545
|
+
for (const tok of tokens) {
|
|
135546
|
+
found = true;
|
|
135547
|
+
const nums = tok.match(/-?\d+(?:\.\d+)?px/gi)?.map((v) => parseFloat(v)) || [];
|
|
135548
|
+
const [ox = 0, oy = 0, blur = 0] = nums;
|
|
135549
|
+
const extX = Math.abs(ox) + blur;
|
|
135550
|
+
const extY = Math.abs(oy) + blur;
|
|
135551
|
+
r = Math.max(r, extX + Math.max(ox, 0));
|
|
135552
|
+
l = Math.max(l, extX + Math.max(-ox, 0));
|
|
135553
|
+
b = Math.max(b, extY + Math.max(oy, 0));
|
|
135554
|
+
t = Math.max(t, extY + Math.max(-oy, 0));
|
|
135555
|
+
}
|
|
135556
|
+
return { bleed: { top: Math.ceil(t), right: Math.ceil(r), bottom: Math.ceil(b), left: Math.ceil(l) }, has: found };
|
|
135557
|
+
}
|
|
135558
|
+
const rect = element.getBoundingClientRect();
|
|
135559
|
+
const w0 = Math.max(1, Math.ceil(element.offsetWidth || parseFloat(csEl.width) || rect.width || 1));
|
|
135560
|
+
const h0 = Math.max(1, Math.ceil(element.offsetHeight || parseFloat(csEl.height) || rect.height || 1));
|
|
135561
|
+
const coerceNum = (v, def = NaN) => {
|
|
135562
|
+
const n = typeof v === "string" ? parseFloat(v) : v;
|
|
135563
|
+
return Number.isFinite(n) ? n : def;
|
|
135564
|
+
};
|
|
135565
|
+
const optW = coerceNum(options.width);
|
|
135566
|
+
const optH = coerceNum(options.height);
|
|
135567
|
+
let w = w0, h = h0;
|
|
135568
|
+
const hasW = Number.isFinite(optW);
|
|
135569
|
+
const hasH = Number.isFinite(optH);
|
|
135570
|
+
const aspect0 = h0 > 0 ? w0 / h0 : 1;
|
|
135571
|
+
if (hasW && hasH) {
|
|
135572
|
+
w = Math.max(1, Math.ceil(optW));
|
|
135573
|
+
h = Math.max(1, Math.ceil(optH));
|
|
135574
|
+
} else if (hasW) {
|
|
135575
|
+
w = Math.max(1, Math.ceil(optW));
|
|
135576
|
+
h = Math.max(1, Math.ceil(w / (aspect0 || 1)));
|
|
135577
|
+
} else if (hasH) {
|
|
135578
|
+
h = Math.max(1, Math.ceil(optH));
|
|
135579
|
+
w = Math.max(1, Math.ceil(h * (aspect0 || 1)));
|
|
135580
|
+
} else {
|
|
135581
|
+
w = w0;
|
|
135582
|
+
h = h0;
|
|
135583
|
+
}
|
|
135584
|
+
let minX = 0, minY = 0, maxX = w0, maxY = h0;
|
|
135585
|
+
if (straighten && rootTransform2D && Number.isFinite(rootTransform2D.a)) {
|
|
135586
|
+
const M2 = { a: rootTransform2D.a, b: rootTransform2D.b || 0, c: rootTransform2D.c || 0, d: rootTransform2D.d || 1, e: 0, f: 0 };
|
|
135587
|
+
const bb2 = bboxWithOriginFull(w0, h0, M2, 0, 0);
|
|
135588
|
+
minX = bb2.minX;
|
|
135589
|
+
minY = bb2.minY;
|
|
135590
|
+
maxX = bb2.maxX;
|
|
135591
|
+
maxY = bb2.maxY;
|
|
135592
|
+
} else {
|
|
135593
|
+
const useTFBBox = !straighten && hasTFBBox(element);
|
|
135594
|
+
if (useTFBBox) {
|
|
135595
|
+
const baseTransform2 = csEl.transform && csEl.transform !== "none" ? csEl.transform : "";
|
|
135596
|
+
const ind2 = readIndividualTransforms(element);
|
|
135597
|
+
const TOTAL = readTotalTransformMatrix({
|
|
135598
|
+
baseTransform: baseTransform2,
|
|
135599
|
+
rotate: ind2.rotate || "0deg",
|
|
135600
|
+
scale: ind2.scale,
|
|
135601
|
+
translate: ind2.translate
|
|
135602
|
+
});
|
|
135603
|
+
const { ox: ox2, oy: oy2 } = parseTransformOriginPx(csEl, w0, h0);
|
|
135604
|
+
const M = TOTAL.is2D ? TOTAL : new DOMMatrix(TOTAL.toString());
|
|
135605
|
+
const bb = bboxWithOriginFull(w0, h0, M, ox2, oy2);
|
|
135606
|
+
minX = bb.minX;
|
|
135607
|
+
minY = bb.minY;
|
|
135608
|
+
maxX = bb.maxX;
|
|
135609
|
+
maxY = bb.maxY;
|
|
135610
|
+
}
|
|
135611
|
+
}
|
|
135612
|
+
const bleedShadow = parseBoxShadow(csEl);
|
|
135613
|
+
const bleedBlur = parseFilterBlur(csEl);
|
|
135614
|
+
const bleedOutline = parseOutline(csEl);
|
|
135615
|
+
const drop = parseFilterDropShadows(csEl);
|
|
135616
|
+
const bleed = noShadows ? { top: 0, right: 0, bottom: 0, left: 0 } : {
|
|
135617
|
+
top: bleedShadow.top + bleedBlur.top + bleedOutline.top + drop.bleed.top,
|
|
135618
|
+
right: bleedShadow.right + bleedBlur.right + bleedOutline.right + drop.bleed.right,
|
|
135619
|
+
bottom: bleedShadow.bottom + bleedBlur.bottom + bleedOutline.bottom + drop.bleed.bottom,
|
|
135620
|
+
left: bleedShadow.left + bleedBlur.left + bleedOutline.left + drop.bleed.left
|
|
135621
|
+
};
|
|
135622
|
+
minX -= bleed.left;
|
|
135623
|
+
minY -= bleed.top;
|
|
135624
|
+
maxX += bleed.right;
|
|
135625
|
+
maxY += bleed.bottom;
|
|
135626
|
+
const vbW0 = Math.max(1, Math.ceil(maxX - minX));
|
|
135627
|
+
const vbH0 = Math.max(1, Math.ceil(maxY - minY));
|
|
135628
|
+
const outW = Math.max(1, Math.round(vbW0 * (hasW || hasH ? w / w0 : 1)));
|
|
135629
|
+
const outH = Math.max(1, Math.round(vbH0 * (hasH || hasW ? h / h0 : 1)));
|
|
135630
|
+
const svgNS = "http://www.w3.org/2000/svg";
|
|
135631
|
+
const basePad = isSafari() ? 1 : 0;
|
|
135632
|
+
const extraPad = straighten ? 1 : 0;
|
|
135633
|
+
const pad = basePad + extraPad;
|
|
135634
|
+
const fo = document.createElementNS(svgNS, "foreignObject");
|
|
135635
|
+
const vbMinX = Math.floor(minX);
|
|
135636
|
+
const vbMinY = Math.floor(minY);
|
|
135637
|
+
fo.setAttribute("x", String(-(vbMinX - pad)));
|
|
135638
|
+
fo.setAttribute("y", String(-(vbMinY - pad)));
|
|
135639
|
+
fo.setAttribute("width", String(Math.ceil(w0 + pad * 2)));
|
|
135640
|
+
fo.setAttribute("height", String(Math.ceil(h0 + pad * 2)));
|
|
135641
|
+
fo.style.overflow = "visible";
|
|
135642
|
+
const styleTag = document.createElement("style");
|
|
135643
|
+
styleTag.textContent = baseCSS + fontsCSS + "svg{overflow:visible;} foreignObject{overflow:visible;}" + classCSS;
|
|
135644
|
+
fo.appendChild(styleTag);
|
|
135645
|
+
const container = document.createElement("div");
|
|
135646
|
+
container.setAttribute("xmlns", "http://www.w3.org/1999/xhtml");
|
|
135647
|
+
container.style.width = `${w0}px`;
|
|
135648
|
+
container.style.height = `${h0}px`;
|
|
135649
|
+
container.style.overflow = "visible";
|
|
135650
|
+
clone.setAttribute("xmlns", "http://www.w3.org/1999/xhtml");
|
|
135651
|
+
container.appendChild(clone);
|
|
135652
|
+
fo.appendChild(container);
|
|
135653
|
+
const serializer = new XMLSerializer();
|
|
135654
|
+
const foString = serializer.serializeToString(fo);
|
|
135655
|
+
const vbW = vbW0 + pad * 2;
|
|
135656
|
+
const vbH = vbH0 + pad * 2;
|
|
135657
|
+
const wantsSize = hasW || hasH;
|
|
135658
|
+
options.meta = { w0, h0, vbW, vbH, targetW: w, targetH: h };
|
|
135659
|
+
const svgOutW = isSafari() && wantsSize ? vbW : outW + pad * 2;
|
|
135660
|
+
const svgOutH = isSafari() && wantsSize ? vbH : outH + pad * 2;
|
|
135661
|
+
const svgHeader = `<svg xmlns="${svgNS}" width="${svgOutW}" height="${svgOutH}" viewBox="0 0 ${vbW} ${vbH}">`;
|
|
135662
|
+
const svgFooter = "</svg>";
|
|
135663
|
+
svgString = svgHeader + foString + svgFooter;
|
|
135664
|
+
dataURL = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(svgString)}`;
|
|
135665
|
+
resolve();
|
|
135666
|
+
}, { fast });
|
|
135667
|
+
});
|
|
135668
|
+
const sandbox = document.getElementById("snapdom-sandbox");
|
|
135669
|
+
if (sandbox && sandbox.style.position === "absolute") sandbox.remove();
|
|
135670
|
+
return dataURL;
|
|
135671
|
+
}
|
|
135672
|
+
function normalizeRootTransforms(originalEl, cloneRoot) {
|
|
135673
|
+
if (!originalEl || !cloneRoot || !cloneRoot.style) return null;
|
|
135674
|
+
const cs = getComputedStyle(originalEl);
|
|
135675
|
+
try {
|
|
135676
|
+
cloneRoot.style.transformOrigin = "0 0";
|
|
135677
|
+
} catch {
|
|
135678
|
+
}
|
|
135679
|
+
try {
|
|
135680
|
+
if ("translate" in cloneRoot.style) cloneRoot.style.translate = "none";
|
|
135681
|
+
if ("rotate" in cloneRoot.style) cloneRoot.style.rotate = "none";
|
|
135682
|
+
} catch {
|
|
135683
|
+
}
|
|
135684
|
+
const tr = cs.transform || "none";
|
|
135685
|
+
if (tr === "none") {
|
|
135686
|
+
try {
|
|
135687
|
+
const M = matrixFromComputed(originalEl);
|
|
135688
|
+
if (M.a === 1 && M.b === 0 && M.c === 0 && M.d === 1) {
|
|
135689
|
+
cloneRoot.style.transform = "none";
|
|
135690
|
+
return { a: 1, b: 0, c: 0, d: 1 };
|
|
135691
|
+
}
|
|
135692
|
+
} catch {
|
|
135693
|
+
}
|
|
135694
|
+
}
|
|
135695
|
+
const m2d = tr.match(/^matrix\(\s*([^)]+)\)$/i);
|
|
135696
|
+
if (m2d) {
|
|
135697
|
+
const nums = m2d[1].split(",").map((v) => parseFloat(v.trim()));
|
|
135698
|
+
if (nums.length === 6 && nums.every(Number.isFinite)) {
|
|
135699
|
+
const [a, b, c, d] = nums;
|
|
135700
|
+
const scaleX = Math.sqrt(a * a + b * b) || 0;
|
|
135701
|
+
let a1 = 0, b1 = 0, shear = 0, c2 = 0, d2 = 0, scaleY = 0;
|
|
135702
|
+
if (scaleX > 0) {
|
|
135703
|
+
a1 = a / scaleX;
|
|
135704
|
+
b1 = b / scaleX;
|
|
135705
|
+
shear = a1 * c + b1 * d;
|
|
135706
|
+
c2 = c - a1 * shear;
|
|
135707
|
+
d2 = d - b1 * shear;
|
|
135708
|
+
scaleY = Math.sqrt(c2 * c2 + d2 * d2) || 0;
|
|
135709
|
+
if (scaleY > 0) shear = shear / scaleY;
|
|
135710
|
+
else shear = 0;
|
|
135711
|
+
}
|
|
135712
|
+
const aP = scaleX;
|
|
135713
|
+
const bP = 0;
|
|
135714
|
+
const cP = shear * scaleY;
|
|
135715
|
+
const dP = scaleY;
|
|
135716
|
+
try {
|
|
135717
|
+
cloneRoot.style.transform = `matrix(${aP}, ${bP}, ${cP}, ${dP}, 0, 0)`;
|
|
135718
|
+
} catch {
|
|
135719
|
+
}
|
|
135720
|
+
return { a: aP, b: bP, c: cP, d: dP };
|
|
135721
|
+
}
|
|
135722
|
+
}
|
|
135723
|
+
try {
|
|
135724
|
+
const legacy = String(tr).trim();
|
|
135725
|
+
cloneRoot.style.transform = legacy + " translate(0px, 0px) rotate(0deg)";
|
|
135726
|
+
return null;
|
|
135727
|
+
} catch {
|
|
135728
|
+
return null;
|
|
135729
|
+
}
|
|
135730
|
+
}
|
|
135731
|
+
function parseBoxShadow(cs) {
|
|
135732
|
+
const v = cs.boxShadow || "";
|
|
135733
|
+
if (!v || v === "none") return { top: 0, right: 0, bottom: 0, left: 0 };
|
|
135734
|
+
const parts = v.split(/\),(?=(?:[^()]*\([^()]*\))*[^()]*$)/).map((s) => s.trim());
|
|
135735
|
+
let t = 0, r = 0, b2 = 0, l = 0;
|
|
135736
|
+
for (const part of parts) {
|
|
135737
|
+
const nums = part.match(/-?\d+(\.\d+)?px/g)?.map((n) => parseFloat(n)) || [];
|
|
135738
|
+
if (nums.length < 2) continue;
|
|
135739
|
+
const [ox2, oy2, blur = 0, spread = 0] = nums;
|
|
135740
|
+
const extX = Math.abs(ox2) + blur + spread;
|
|
135741
|
+
const extY = Math.abs(oy2) + blur + spread;
|
|
135742
|
+
r = Math.max(r, extX + Math.max(ox2, 0));
|
|
135743
|
+
l = Math.max(l, extX + Math.max(-ox2, 0));
|
|
135744
|
+
b2 = Math.max(b2, extY + Math.max(oy2, 0));
|
|
135745
|
+
t = Math.max(t, extY + Math.max(-oy2, 0));
|
|
135746
|
+
}
|
|
135747
|
+
return { top: Math.ceil(t), right: Math.ceil(r), bottom: Math.ceil(b2), left: Math.ceil(l) };
|
|
135748
|
+
}
|
|
135749
|
+
function parseFilterBlur(cs) {
|
|
135750
|
+
const m = (cs.filter || "").match(/blur\(\s*([0-9.]+)px\s*\)/);
|
|
135751
|
+
const b2 = m ? Math.ceil(parseFloat(m[1]) || 0) : 0;
|
|
135752
|
+
return { top: b2, right: b2, bottom: b2, left: b2 };
|
|
135753
|
+
}
|
|
135754
|
+
function parseOutline(cs) {
|
|
135755
|
+
if ((cs.outlineStyle || "none") === "none") return { top: 0, right: 0, bottom: 0, left: 0 };
|
|
135756
|
+
const w2 = Math.ceil(parseFloat(cs.outlineWidth || "0") || 0);
|
|
135757
|
+
return { top: w2, right: w2, bottom: w2, left: w2 };
|
|
135758
|
+
}
|
|
135759
|
+
function bboxWithOriginFull(w2, h2, M, ox2, oy2) {
|
|
135760
|
+
const a2 = M.a, b2 = M.b, c2 = M.c, d2 = M.d, e2 = M.e || 0, f2 = M.f || 0;
|
|
135761
|
+
function pt(x, y) {
|
|
135762
|
+
let X = x - ox2, Y = y - oy2;
|
|
135763
|
+
let X2 = a2 * X + c2 * Y, Y2 = b2 * X + d2 * Y;
|
|
135764
|
+
X2 += ox2 + e2;
|
|
135765
|
+
Y2 += oy2 + f2;
|
|
135766
|
+
return [X2, Y2];
|
|
135767
|
+
}
|
|
135768
|
+
const P = [pt(0, 0), pt(w2, 0), pt(0, h2), pt(w2, h2)];
|
|
135769
|
+
let minX2 = Infinity, minY2 = Infinity, maxX2 = -Infinity, maxY2 = -Infinity;
|
|
135770
|
+
for (const [X, Y] of P) {
|
|
135771
|
+
if (X < minX2) minX2 = X;
|
|
135772
|
+
if (Y < minY2) minY2 = Y;
|
|
135773
|
+
if (X > maxX2) maxX2 = X;
|
|
135774
|
+
if (Y > maxY2) maxY2 = Y;
|
|
135775
|
+
}
|
|
135776
|
+
return { minX: minX2, minY: minY2, maxX: maxX2, maxY: maxY2, width: maxX2 - minX2, height: maxY2 - minY2 };
|
|
135777
|
+
}
|
|
135778
|
+
function hasTFBBox(el) {
|
|
135779
|
+
return hasBBoxAffectingTransform(el);
|
|
135780
|
+
}
|
|
135781
|
+
function matrixFromComputed(el) {
|
|
135782
|
+
const tr = getComputedStyle(el).transform;
|
|
135783
|
+
if (!tr || tr === "none") return new DOMMatrix();
|
|
135784
|
+
try {
|
|
135785
|
+
return new DOMMatrix(tr);
|
|
135786
|
+
} catch {
|
|
135787
|
+
return new WebKitCSSMatrix(tr);
|
|
135788
|
+
}
|
|
135789
|
+
}
|
|
135790
|
+
function readIndividualTransforms(el) {
|
|
135791
|
+
const out = { rotate: "0deg", scale: null, translate: null };
|
|
135792
|
+
const map = typeof el.computedStyleMap === "function" ? el.computedStyleMap() : null;
|
|
135793
|
+
if (map) {
|
|
135794
|
+
const safeGet = (prop) => {
|
|
135795
|
+
try {
|
|
135796
|
+
if (typeof map.has === "function" && !map.has(prop)) return null;
|
|
135797
|
+
if (typeof map.get !== "function") return null;
|
|
135798
|
+
return map.get(prop);
|
|
135799
|
+
} catch {
|
|
135800
|
+
return null;
|
|
135801
|
+
}
|
|
135802
|
+
};
|
|
135803
|
+
const rot = safeGet("rotate");
|
|
135804
|
+
if (rot) {
|
|
135805
|
+
if (rot.angle) {
|
|
135806
|
+
const ang = rot.angle;
|
|
135807
|
+
out.rotate = ang.unit === "rad" ? ang.value * 180 / Math.PI + "deg" : ang.value + ang.unit;
|
|
135808
|
+
} else if (rot.unit) {
|
|
135809
|
+
out.rotate = rot.unit === "rad" ? rot.value * 180 / Math.PI + "deg" : rot.value + rot.unit;
|
|
135810
|
+
} else {
|
|
135811
|
+
out.rotate = String(rot);
|
|
135812
|
+
}
|
|
135813
|
+
} else {
|
|
135814
|
+
const cs2 = getComputedStyle(el);
|
|
135815
|
+
out.rotate = cs2.rotate && cs2.rotate !== "none" ? cs2.rotate : "0deg";
|
|
135816
|
+
}
|
|
135817
|
+
const sc = safeGet("scale");
|
|
135818
|
+
if (sc) {
|
|
135819
|
+
const sx = "x" in sc && sc.x?.value != null ? sc.x.value : Array.isArray(sc) ? sc[0]?.value : Number(sc) || 1;
|
|
135820
|
+
const sy = "y" in sc && sc.y?.value != null ? sc.y.value : Array.isArray(sc) ? sc[1]?.value : sx;
|
|
135821
|
+
out.scale = `${sx} ${sy}`;
|
|
135822
|
+
} else {
|
|
135823
|
+
const cs2 = getComputedStyle(el);
|
|
135824
|
+
out.scale = cs2.scale && cs2.scale !== "none" ? cs2.scale : null;
|
|
135825
|
+
}
|
|
135826
|
+
const tr = safeGet("translate");
|
|
135827
|
+
if (tr) {
|
|
135828
|
+
const tx = "x" in tr && "value" in tr.x ? tr.x.value : Array.isArray(tr) ? tr[0]?.value : 0;
|
|
135829
|
+
const ty = "y" in tr && "value" in tr.y ? tr.y.value : Array.isArray(tr) ? tr[1]?.value : 0;
|
|
135830
|
+
const ux = "x" in tr && tr.x?.unit ? tr.x.unit : "px";
|
|
135831
|
+
const uy = "y" in tr && tr.y?.unit ? tr.y.unit : "px";
|
|
135832
|
+
out.translate = `${tx}${ux} ${ty}${uy}`;
|
|
135833
|
+
} else {
|
|
135834
|
+
const cs2 = getComputedStyle(el);
|
|
135835
|
+
out.translate = cs2.translate && cs2.translate !== "none" ? cs2.translate : null;
|
|
135836
|
+
}
|
|
135837
|
+
return out;
|
|
135838
|
+
}
|
|
135839
|
+
const cs = getComputedStyle(el);
|
|
135840
|
+
out.rotate = cs.rotate && cs.rotate !== "none" ? cs.rotate : "0deg";
|
|
135841
|
+
out.scale = cs.scale && cs.scale !== "none" ? cs.scale : null;
|
|
135842
|
+
out.translate = cs.translate && cs.translate !== "none" ? cs.translate : null;
|
|
135843
|
+
return out;
|
|
135844
|
+
}
|
|
135845
|
+
function hasBBoxAffectingTransform(el) {
|
|
135846
|
+
const cs = getComputedStyle(el);
|
|
135847
|
+
const t = cs.transform || "none";
|
|
135848
|
+
const hasMatrix = t !== "none" && !/^matrix\(\s*1\s*,\s*0\s*,\s*0\s*,\s*1\s*,\s*0\s*,\s*0\s*\)$/i.test(t);
|
|
135849
|
+
if (hasMatrix) return true;
|
|
135850
|
+
const r = cs.rotate && cs.rotate !== "none" && cs.rotate !== "0deg";
|
|
135851
|
+
const s = cs.scale && cs.scale !== "none" && cs.scale !== "1";
|
|
135852
|
+
const tr = cs.translate && cs.translate !== "none" && cs.translate !== "0px 0px";
|
|
135853
|
+
return Boolean(r || s || tr);
|
|
135854
|
+
}
|
|
135855
|
+
function parseTransformOriginPx(cs, w, h) {
|
|
135856
|
+
const raw = (cs.transformOrigin || "0 0").trim().split(/\s+/);
|
|
135857
|
+
const [oxRaw, oyRaw] = [raw[0] || "0", raw[1] || "0"];
|
|
135858
|
+
const toPx = (token, size) => {
|
|
135859
|
+
const t = token.toLowerCase();
|
|
135860
|
+
if (t === "left" || t === "top") return 0;
|
|
135861
|
+
if (t === "center") return size / 2;
|
|
135862
|
+
if (t === "right") return size;
|
|
135863
|
+
if (t === "bottom") return size;
|
|
135864
|
+
if (t.endsWith("px")) return parseFloat(t) || 0;
|
|
135865
|
+
if (t.endsWith("%")) return (parseFloat(t) || 0) * size / 100;
|
|
135866
|
+
if (/^-?\d+(\.\d+)?$/.test(t)) return parseFloat(t) || 0;
|
|
135867
|
+
return 0;
|
|
135868
|
+
};
|
|
135869
|
+
return {
|
|
135870
|
+
ox: toPx(oxRaw, w),
|
|
135871
|
+
oy: toPx(oyRaw, h)
|
|
135872
|
+
};
|
|
135873
|
+
}
|
|
135874
|
+
var __measureHost = null;
|
|
135875
|
+
function getMeasureHost() {
|
|
135876
|
+
if (__measureHost) return __measureHost;
|
|
135877
|
+
const n = document.createElement("div");
|
|
135878
|
+
n.id = "snapdom-measure-slot";
|
|
135879
|
+
n.setAttribute("aria-hidden", "true");
|
|
135880
|
+
Object.assign(n.style, {
|
|
135881
|
+
position: "absolute",
|
|
135882
|
+
left: "-99999px",
|
|
135883
|
+
top: "0px",
|
|
135884
|
+
width: "0px",
|
|
135885
|
+
height: "0px",
|
|
135886
|
+
overflow: "hidden",
|
|
135887
|
+
opacity: "0",
|
|
135888
|
+
pointerEvents: "none",
|
|
135889
|
+
contain: "size layout style"
|
|
135890
|
+
});
|
|
135891
|
+
document.documentElement.appendChild(n);
|
|
135892
|
+
__measureHost = n;
|
|
135893
|
+
return n;
|
|
135894
|
+
}
|
|
135895
|
+
function readTotalTransformMatrix(t) {
|
|
135896
|
+
const host = getMeasureHost();
|
|
135897
|
+
const tmp = document.createElement("div");
|
|
135898
|
+
tmp.style.transformOrigin = "0 0";
|
|
135899
|
+
if (t.baseTransform) tmp.style.transform = t.baseTransform;
|
|
135900
|
+
if (t.rotate) tmp.style.rotate = t.rotate;
|
|
135901
|
+
if (t.scale) tmp.style.scale = t.scale;
|
|
135902
|
+
if (t.translate) tmp.style.translate = t.translate;
|
|
135903
|
+
host.appendChild(tmp);
|
|
135904
|
+
const M = matrixFromComputed(tmp);
|
|
135905
|
+
host.removeChild(tmp);
|
|
135906
|
+
return M;
|
|
135907
|
+
}
|
|
135908
|
+
|
|
135909
|
+
// src/core/context.js
|
|
135910
|
+
function normalizeCachePolicy(v) {
|
|
135911
|
+
if (typeof v === "string") {
|
|
135912
|
+
const s = v.toLowerCase().trim();
|
|
135913
|
+
if (s === "disabled" || s === "full" || s === "auto" || s === "soft") return (
|
|
135914
|
+
/** @type {CachePolicy} */
|
|
135915
|
+
s
|
|
135916
|
+
);
|
|
135917
|
+
}
|
|
135918
|
+
return "soft";
|
|
135919
|
+
}
|
|
135920
|
+
function createContext(options = {}) {
|
|
135921
|
+
const resolvedFormat = options.format ?? "png";
|
|
135922
|
+
const cachePolicy = normalizeCachePolicy(options.cache);
|
|
135923
|
+
return {
|
|
135924
|
+
// Debug & perf
|
|
135925
|
+
debug: options.debug ?? false,
|
|
135926
|
+
fast: options.fast ?? true,
|
|
135927
|
+
scale: options.scale ?? 1,
|
|
135928
|
+
// DOM filters
|
|
135929
|
+
exclude: options.exclude ?? [],
|
|
135930
|
+
excludeMode: options.excludeMode ?? "hide",
|
|
135931
|
+
filter: options.filter ?? null,
|
|
135932
|
+
filterMode: options.filterMode ?? "hide",
|
|
135933
|
+
// Placeholders
|
|
135934
|
+
placeholders: options.placeholders !== false,
|
|
135935
|
+
// default true
|
|
135936
|
+
// Fonts
|
|
135937
|
+
embedFonts: options.embedFonts ?? false,
|
|
135938
|
+
iconFonts: Array.isArray(options.iconFonts) ? options.iconFonts : options.iconFonts ? [options.iconFonts] : [],
|
|
135939
|
+
localFonts: Array.isArray(options.localFonts) ? options.localFonts : [],
|
|
135940
|
+
excludeFonts: options.excludeFonts ?? void 0,
|
|
135941
|
+
fallbackURL: options.fallbackURL ?? void 0,
|
|
135942
|
+
/** @type {CachePolicy} */
|
|
135943
|
+
cache: cachePolicy,
|
|
135944
|
+
// Network
|
|
135945
|
+
useProxy: typeof options.useProxy === "string" ? options.useProxy : "",
|
|
135946
|
+
// Output
|
|
135947
|
+
width: options.width ?? null,
|
|
135948
|
+
height: options.height ?? null,
|
|
135949
|
+
format: resolvedFormat,
|
|
135950
|
+
type: options.type ?? "svg",
|
|
135951
|
+
quality: options.quality ?? 0.92,
|
|
135952
|
+
dpr: options.dpr ?? (window.devicePixelRatio || 1),
|
|
135953
|
+
backgroundColor: options.backgroundColor ?? (["jpg", "jpeg", "webp"].includes(resolvedFormat) ? "#ffffff" : null),
|
|
135954
|
+
filename: options.filename ?? "snapDOM",
|
|
135955
|
+
// NEW flags (user-friendly)
|
|
135956
|
+
straighten: options.straighten ?? false,
|
|
135957
|
+
noShadows: options.noShadows ?? false
|
|
135958
|
+
// Plugins (reservado)
|
|
135959
|
+
// plugins: normalizePlugins(...),
|
|
135960
|
+
};
|
|
135961
|
+
}
|
|
135962
|
+
|
|
135963
|
+
// src/exporters/toCanvas.js
|
|
135964
|
+
function isSvgDataURL(u) {
|
|
135965
|
+
return typeof u === "string" && /^data:image\/svg\+xml/i.test(u);
|
|
135966
|
+
}
|
|
135967
|
+
function decodeSvgFromDataURL(u) {
|
|
135968
|
+
const i = u.indexOf(",");
|
|
135969
|
+
return i >= 0 ? decodeURIComponent(u.slice(i + 1)) : "";
|
|
135970
|
+
}
|
|
135971
|
+
function encodeSvgToDataURL(svgText) {
|
|
135972
|
+
return `data:image/svg+xml;charset=utf-8,${encodeURIComponent(svgText)}`;
|
|
135973
|
+
}
|
|
135974
|
+
function splitDecls(s) {
|
|
135975
|
+
let parts = [], buf = "", depth = 0;
|
|
135976
|
+
for (let i = 0; i < s.length; i++) {
|
|
135977
|
+
const ch = s[i];
|
|
135978
|
+
if (ch === "(") depth++;
|
|
135979
|
+
if (ch === ")") depth = Math.max(0, depth - 1);
|
|
135980
|
+
if (ch === ";" && depth === 0) {
|
|
135981
|
+
parts.push(buf);
|
|
135982
|
+
buf = "";
|
|
135983
|
+
} else buf += ch;
|
|
135984
|
+
}
|
|
135985
|
+
if (buf.trim()) parts.push(buf);
|
|
135986
|
+
return parts.map((x) => x.trim()).filter(Boolean);
|
|
135987
|
+
}
|
|
135988
|
+
function boxShadowToDropShadow(value) {
|
|
135989
|
+
const layers = [];
|
|
135990
|
+
let buf = "", depth = 0;
|
|
135991
|
+
for (let i = 0; i < value.length; i++) {
|
|
135992
|
+
const ch = value[i];
|
|
135993
|
+
if (ch === "(") depth++;
|
|
135994
|
+
if (ch === ")") depth = Math.max(0, depth - 1);
|
|
135995
|
+
if (ch === "," && depth === 0) {
|
|
135996
|
+
layers.push(buf.trim());
|
|
135997
|
+
buf = "";
|
|
135998
|
+
} else buf += ch;
|
|
135999
|
+
}
|
|
136000
|
+
if (buf.trim()) layers.push(buf.trim());
|
|
136001
|
+
const fns = [];
|
|
136002
|
+
for (const layer of layers) {
|
|
136003
|
+
if (/\binset\b/i.test(layer)) continue;
|
|
136004
|
+
const nums = layer.match(/-?\d+(?:\.\d+)?px/gi) || [];
|
|
136005
|
+
const [ox = "0px", oy = "0px", blur = "0px"] = nums;
|
|
136006
|
+
let color = layer.replace(/-?\d+(?:\.\d+)?px/gi, "").replace(/\binset\b/ig, "").trim().replace(/\s{2,}/g, " ");
|
|
136007
|
+
const hasColor = !!color && color !== ",";
|
|
136008
|
+
fns.push(`drop-shadow(${ox} ${oy} ${blur}${hasColor ? ` ${color}` : ""})`);
|
|
136009
|
+
}
|
|
136010
|
+
return fns.join(" ");
|
|
136011
|
+
}
|
|
136012
|
+
function rewriteDeclList(list) {
|
|
136013
|
+
const decls = splitDecls(list);
|
|
136014
|
+
let filter = null, wfilter = null, box = null;
|
|
136015
|
+
const rest = [];
|
|
136016
|
+
for (const d of decls) {
|
|
136017
|
+
const idx = d.indexOf(":");
|
|
136018
|
+
if (idx < 0) continue;
|
|
136019
|
+
const prop = d.slice(0, idx).trim().toLowerCase();
|
|
136020
|
+
const val = d.slice(idx + 1).trim();
|
|
136021
|
+
if (prop === "box-shadow") box = val;
|
|
136022
|
+
else if (prop === "filter") filter = val;
|
|
136023
|
+
else if (prop === "-webkit-filter") wfilter = val;
|
|
136024
|
+
else rest.push([prop, val]);
|
|
136025
|
+
}
|
|
136026
|
+
if (box) {
|
|
136027
|
+
const ds = boxShadowToDropShadow(box);
|
|
136028
|
+
if (ds) {
|
|
136029
|
+
filter = filter ? `${filter} ${ds}` : ds;
|
|
136030
|
+
wfilter = wfilter ? `${wfilter} ${ds}` : ds;
|
|
136031
|
+
}
|
|
136032
|
+
}
|
|
136033
|
+
const out = [...rest];
|
|
136034
|
+
if (filter) out.push(["filter", filter]);
|
|
136035
|
+
if (wfilter) out.push(["-webkit-filter", wfilter]);
|
|
136036
|
+
return out.map(([k, v]) => `${k}:${v}`).join(";");
|
|
136037
|
+
}
|
|
136038
|
+
function rewriteCssBlock(css) {
|
|
136039
|
+
return css.replace(/([^{}]+)\{([^}]*)\}/g, (_m, sel, body) => `${sel}{${rewriteDeclList(body)}}`);
|
|
136040
|
+
}
|
|
136041
|
+
function rewriteSvgBoxShadowToDropShadow(svgText) {
|
|
136042
|
+
svgText = svgText.replace(
|
|
136043
|
+
/<style[^>]*>([\s\S]*?)<\/style>/gi,
|
|
136044
|
+
(m, css) => m.replace(css, rewriteCssBlock(css))
|
|
136045
|
+
);
|
|
136046
|
+
svgText = svgText.replace(
|
|
136047
|
+
/style=(['"])([\s\S]*?)\1/gi,
|
|
136048
|
+
(m, q, body) => `style=${q}${rewriteDeclList(body)}${q}`
|
|
136049
|
+
);
|
|
136050
|
+
return svgText;
|
|
136051
|
+
}
|
|
136052
|
+
function maybeConvertBoxShadowForSafari(url) {
|
|
136053
|
+
if (!isSafari() || !isSvgDataURL(url)) return url;
|
|
136054
|
+
try {
|
|
136055
|
+
const svg = decodeSvgFromDataURL(url);
|
|
136056
|
+
const fixed = rewriteSvgBoxShadowToDropShadow(svg);
|
|
136057
|
+
return encodeSvgToDataURL(fixed);
|
|
136058
|
+
} catch {
|
|
136059
|
+
return url;
|
|
136060
|
+
}
|
|
136061
|
+
}
|
|
136062
|
+
async function toCanvas(url, options) {
|
|
136063
|
+
let { width: optW, height: optH, scale = 1, dpr = 1, meta = {} } = options;
|
|
136064
|
+
url = maybeConvertBoxShadowForSafari(url);
|
|
136065
|
+
const img = new Image();
|
|
136066
|
+
img.loading = "eager";
|
|
136067
|
+
img.decoding = "sync";
|
|
136068
|
+
img.crossOrigin = "anonymous";
|
|
136069
|
+
img.src = url;
|
|
136070
|
+
await img.decode();
|
|
136071
|
+
const natW = img.naturalWidth;
|
|
136072
|
+
const natH = img.naturalHeight;
|
|
136073
|
+
const refW = Number.isFinite(meta.w0) ? meta.w0 : natW;
|
|
136074
|
+
const refH = Number.isFinite(meta.h0) ? meta.h0 : natH;
|
|
136075
|
+
let outW, outH;
|
|
136076
|
+
const hasW = Number.isFinite(optW);
|
|
136077
|
+
const hasH = Number.isFinite(optH);
|
|
136078
|
+
if (hasW && hasH) {
|
|
136079
|
+
outW = Math.max(1, optW);
|
|
136080
|
+
outH = Math.max(1, optH);
|
|
136081
|
+
} else if (hasW) {
|
|
136082
|
+
const k = optW / Math.max(1, refW);
|
|
136083
|
+
outW = optW;
|
|
136084
|
+
outH = Math.round(refH * k);
|
|
136085
|
+
} else if (hasH) {
|
|
136086
|
+
const k = optH / Math.max(1, refH);
|
|
136087
|
+
outH = optH;
|
|
136088
|
+
outW = Math.round(refW * k);
|
|
136089
|
+
} else {
|
|
136090
|
+
outW = natW;
|
|
136091
|
+
outH = natH;
|
|
136092
|
+
}
|
|
136093
|
+
outW = Math.round(outW * scale);
|
|
136094
|
+
outH = Math.round(outH * scale);
|
|
136095
|
+
const canvas = document.createElement("canvas");
|
|
136096
|
+
canvas.width = Math.ceil(outW * dpr);
|
|
136097
|
+
canvas.height = Math.ceil(outH * dpr);
|
|
136098
|
+
canvas.style.width = `${outW}px`;
|
|
136099
|
+
canvas.style.height = `${outH}px`;
|
|
136100
|
+
const ctx = canvas.getContext("2d");
|
|
136101
|
+
if (dpr !== 1) ctx.scale(dpr, dpr);
|
|
136102
|
+
ctx.drawImage(img, 0, 0, outW, outH);
|
|
136103
|
+
return canvas;
|
|
136104
|
+
}
|
|
136105
|
+
|
|
136106
|
+
// src/modules/rasterize.js
|
|
136107
|
+
async function rasterize(url, options) {
|
|
136108
|
+
const canvas = await toCanvas(url, options);
|
|
136109
|
+
const finalCanvas = options.backgroundColor ? createBackground(canvas, options.backgroundColor) : canvas;
|
|
136110
|
+
const img = new Image();
|
|
136111
|
+
img.src = finalCanvas.toDataURL(`image/${options.format}`, options.quality);
|
|
136112
|
+
await img.decode();
|
|
136113
|
+
img.style.width = `${finalCanvas.width / options.dpr}px`;
|
|
136114
|
+
img.style.height = `${finalCanvas.height / options.dpr}px`;
|
|
136115
|
+
return img;
|
|
136116
|
+
}
|
|
136117
|
+
|
|
136118
|
+
// src/exporters/toImg.js
|
|
136119
|
+
async function toImg(url, options) {
|
|
136120
|
+
const { scale = 1, width, height, meta = {} } = options;
|
|
136121
|
+
const hasW = Number.isFinite(width);
|
|
136122
|
+
const hasH = Number.isFinite(height);
|
|
136123
|
+
const wantsScale = Number.isFinite(scale) && scale !== 1 || hasW || hasH;
|
|
136124
|
+
if (isSafari() && wantsScale) {
|
|
136125
|
+
const pngUrl = await rasterize(url, { ...options, format: "png", quality: 1, meta });
|
|
136126
|
+
return pngUrl;
|
|
136127
|
+
}
|
|
136128
|
+
const img = new Image();
|
|
136129
|
+
img.decoding = "sync";
|
|
136130
|
+
img.loading = "eager";
|
|
136131
|
+
img.src = url;
|
|
136132
|
+
await img.decode();
|
|
136133
|
+
if (hasW && hasH) {
|
|
136134
|
+
img.style.width = `${width}px`;
|
|
136135
|
+
img.style.height = `${height}px`;
|
|
136136
|
+
} else if (hasW) {
|
|
136137
|
+
const refW = Number.isFinite(meta.w0) ? meta.w0 : img.naturalWidth;
|
|
136138
|
+
const refH = Number.isFinite(meta.h0) ? meta.h0 : img.naturalHeight;
|
|
136139
|
+
const k = width / Math.max(1, refW);
|
|
136140
|
+
img.style.width = `${width}px`;
|
|
136141
|
+
img.style.height = `${Math.round(refH * k)}px`;
|
|
136142
|
+
} else if (hasH) {
|
|
136143
|
+
const refW = Number.isFinite(meta.w0) ? meta.w0 : img.naturalWidth;
|
|
136144
|
+
const refH = Number.isFinite(meta.h0) ? meta.h0 : img.naturalHeight;
|
|
136145
|
+
const k = height / Math.max(1, refH);
|
|
136146
|
+
img.style.height = `${height}px`;
|
|
136147
|
+
img.style.width = `${Math.round(refW * k)}px`;
|
|
136148
|
+
} else {
|
|
136149
|
+
const cssW = Math.round(img.naturalWidth * scale);
|
|
136150
|
+
const cssH = Math.round(img.naturalHeight * scale);
|
|
136151
|
+
img.style.width = `${cssW}px`;
|
|
136152
|
+
img.style.height = `${cssH}px`;
|
|
136153
|
+
if (typeof url === "string" && url.startsWith("data:image/svg+xml")) {
|
|
136154
|
+
try {
|
|
136155
|
+
const decoded = decodeURIComponent(url.split(",")[1]);
|
|
136156
|
+
const patched = decoded.replace(/width="[^"]*"/, `width="${cssW}"`).replace(/height="[^"]*"/, `height="${cssH}"`);
|
|
136157
|
+
url = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(patched)}`;
|
|
136158
|
+
img.src = url;
|
|
136159
|
+
} catch {
|
|
136160
|
+
}
|
|
136161
|
+
}
|
|
136162
|
+
}
|
|
136163
|
+
return img;
|
|
136164
|
+
}
|
|
136165
|
+
|
|
136166
|
+
// src/exporters/toBlob.js
|
|
136167
|
+
async function toBlob(url, options) {
|
|
136168
|
+
const type = options.type;
|
|
136169
|
+
if (type === "svg") {
|
|
136170
|
+
const svgText = decodeURIComponent(url.split(",")[1]);
|
|
136171
|
+
return new Blob([svgText], { type: "image/svg+xml" });
|
|
136172
|
+
}
|
|
136173
|
+
const canvas = await toCanvas(url, options);
|
|
136174
|
+
const finalCanvas = options.backgroundColor ? createBackground(canvas, options.backgroundColor) : canvas;
|
|
136175
|
+
return new Promise(
|
|
136176
|
+
(resolve) => finalCanvas.toBlob(
|
|
136177
|
+
(blob) => resolve(blob),
|
|
136178
|
+
`image/${type}`,
|
|
136179
|
+
options.quality
|
|
136180
|
+
)
|
|
136181
|
+
);
|
|
136182
|
+
}
|
|
136183
|
+
|
|
136184
|
+
// src/exporters/download.js
|
|
136185
|
+
async function download(url, options) {
|
|
136186
|
+
options.dpr = 1;
|
|
136187
|
+
if (options.format === "svg") {
|
|
136188
|
+
const blob = await toBlob(url, { ...options, type: "svg" });
|
|
136189
|
+
const objectURL = URL.createObjectURL(blob);
|
|
136190
|
+
const a2 = document.createElement("a");
|
|
136191
|
+
a2.href = objectURL;
|
|
136192
|
+
a2.download = options.filename;
|
|
136193
|
+
a2.click();
|
|
136194
|
+
URL.revokeObjectURL(objectURL);
|
|
136195
|
+
return;
|
|
136196
|
+
}
|
|
136197
|
+
const canvas = await toCanvas(url, options);
|
|
136198
|
+
const finalCanvas = options.backgroundColor ? createBackground(canvas, options.backgroundColor) : canvas;
|
|
136199
|
+
const a = document.createElement("a");
|
|
136200
|
+
a.href = finalCanvas.toDataURL(`image/${options.format}`, options.quality);
|
|
136201
|
+
a.download = options.filename;
|
|
136202
|
+
a.click();
|
|
136203
|
+
}
|
|
136204
|
+
|
|
136205
|
+
// src/api/snapdom.js
|
|
136206
|
+
var INTERNAL_TOKEN = Symbol("snapdom.internal");
|
|
136207
|
+
var _safariWarmup = false;
|
|
136208
|
+
async function snapdom(element, userOptions) {
|
|
136209
|
+
if (!element) throw new Error("Element cannot be null or undefined");
|
|
136210
|
+
const context = createContext(userOptions);
|
|
136211
|
+
if (isSafari() && (context.embedFonts === true || hasBackgroundOrMask(element))) {
|
|
136212
|
+
for (let i = 0; i < 3; i++) {
|
|
136213
|
+
try {
|
|
136214
|
+
await safariWarmup(element, userOptions);
|
|
136215
|
+
console.log("Iteraci\xF3n n\xFAmero:", i);
|
|
136216
|
+
_safariWarmup = false;
|
|
136217
|
+
} catch {
|
|
136218
|
+
}
|
|
136219
|
+
}
|
|
136220
|
+
}
|
|
136221
|
+
if (context.iconFonts && context.iconFonts.length > 0) extendIconFonts(context.iconFonts);
|
|
136222
|
+
if (!context.snap) {
|
|
136223
|
+
context.snap = {
|
|
136224
|
+
toPng: (el, opts) => snapdom.toPng(el, opts),
|
|
136225
|
+
toSvg: (el, opts) => snapdom.toSvg(el, opts)
|
|
136226
|
+
};
|
|
136227
|
+
}
|
|
136228
|
+
return snapdom.capture(element, context, INTERNAL_TOKEN);
|
|
136229
|
+
}
|
|
136230
|
+
snapdom.capture = async (el, context, _token) => {
|
|
136231
|
+
if (_token !== INTERNAL_TOKEN) throw new Error("[snapdom.capture] is internal. Use snapdom(...) instead.");
|
|
136232
|
+
const url = await captureDOM(el, context);
|
|
136233
|
+
const ensureContext = (opts) => ({ ...context, ...opts || {} });
|
|
136234
|
+
const withFormat = (format) => (opts) => {
|
|
136235
|
+
const next = ensureContext({ ...opts || {}, format });
|
|
136236
|
+
const wantsJpeg = format === "jpeg" || format === "jpg";
|
|
136237
|
+
const noBg = next.backgroundColor == null || next.backgroundColor === "transparent";
|
|
136238
|
+
if (wantsJpeg && noBg) {
|
|
136239
|
+
next.backgroundColor = "#ffffff";
|
|
136240
|
+
}
|
|
136241
|
+
return rasterize(url, next);
|
|
136242
|
+
};
|
|
136243
|
+
return {
|
|
136244
|
+
url,
|
|
136245
|
+
toRaw: () => url,
|
|
136246
|
+
toImg: (opts) => toImg(url, ensureContext(opts)),
|
|
136247
|
+
toSvg: (opts) => toImg(url, ensureContext(opts)),
|
|
136248
|
+
toCanvas: (opts) => toCanvas(url, ensureContext(opts)),
|
|
136249
|
+
toBlob: (opts) => toBlob(url, ensureContext(opts)),
|
|
136250
|
+
toPng: withFormat("png"),
|
|
136251
|
+
toJpg: withFormat("jpeg"),
|
|
136252
|
+
toWebp: withFormat("webp"),
|
|
136253
|
+
download: (opts) => download(url, ensureContext(opts))
|
|
136254
|
+
};
|
|
136255
|
+
};
|
|
136256
|
+
snapdom.toRaw = (el, options) => snapdom(el, options).then((result) => result.toRaw());
|
|
136257
|
+
snapdom.toImg = (el, options) => snapdom(el, options).then((result) => result.toImg());
|
|
136258
|
+
snapdom.toSvg = (el, options) => snapdom(el, options).then((result) => result.toSvg());
|
|
136259
|
+
snapdom.toCanvas = (el, options) => snapdom(el, options).then((result) => result.toCanvas());
|
|
136260
|
+
snapdom.toBlob = (el, options) => snapdom(el, options).then((result) => result.toBlob());
|
|
136261
|
+
snapdom.toPng = (el, options) => snapdom(el, { ...options, format: "png" }).then((result) => result.toPng());
|
|
136262
|
+
snapdom.toJpg = (el, options) => snapdom(el, { ...options, format: "jpeg" }).then((result) => result.toJpg());
|
|
136263
|
+
snapdom.toWebp = (el, options) => snapdom(el, { ...options, format: "webp" }).then((result) => result.toWebp());
|
|
136264
|
+
snapdom.download = (el, options) => snapdom(el, options).then((result) => result.download());
|
|
136265
|
+
async function safariWarmup(element, baseOptions) {
|
|
136266
|
+
if (_safariWarmup) return;
|
|
136267
|
+
const preflight = {
|
|
136268
|
+
...baseOptions,
|
|
136269
|
+
fast: true,
|
|
136270
|
+
embedFonts: true,
|
|
136271
|
+
scale: 0.2
|
|
136272
|
+
};
|
|
136273
|
+
let url;
|
|
136274
|
+
try {
|
|
136275
|
+
url = await captureDOM(element, preflight);
|
|
136276
|
+
} catch {
|
|
136277
|
+
return;
|
|
136278
|
+
}
|
|
136279
|
+
await new Promise((resolve) => {
|
|
136280
|
+
const img = new Image();
|
|
136281
|
+
img.decoding = "sync";
|
|
136282
|
+
img.loading = "eager";
|
|
136283
|
+
img.style.position = "fixed";
|
|
136284
|
+
img.style.left = 0;
|
|
136285
|
+
img.style.top = 0;
|
|
136286
|
+
img.style.width = "10px";
|
|
136287
|
+
img.style.height = "10px";
|
|
136288
|
+
img.style.opacity = "0.01";
|
|
136289
|
+
img.style.transform = "translateZ(10px)";
|
|
136290
|
+
img.style.willChange = "transform,opacity;";
|
|
136291
|
+
img.src = url;
|
|
136292
|
+
const cleanup = async () => {
|
|
136293
|
+
await new Promise((r) => setTimeout(r, 100));
|
|
136294
|
+
if (img && img.parentNode) img.parentNode.removeChild(img);
|
|
136295
|
+
_safariWarmup = true;
|
|
136296
|
+
resolve();
|
|
136297
|
+
};
|
|
136298
|
+
document.body.appendChild(img);
|
|
136299
|
+
cleanup();
|
|
136300
|
+
});
|
|
136301
|
+
}
|
|
136302
|
+
function hasBackgroundOrMask(el) {
|
|
136303
|
+
const walker = document.createTreeWalker(el, NodeFilter.SHOW_ELEMENT);
|
|
136304
|
+
while (walker.nextNode()) {
|
|
136305
|
+
const node = (
|
|
136306
|
+
/** @type {Element} */
|
|
136307
|
+
walker.currentNode
|
|
136308
|
+
);
|
|
136309
|
+
const cs = getComputedStyle(node);
|
|
136310
|
+
const bg = cs.backgroundImage && cs.backgroundImage !== "none";
|
|
136311
|
+
const mask = cs.maskImage && cs.maskImage !== "none" || cs.webkitMaskImage && cs.webkitMaskImage !== "none";
|
|
136312
|
+
if (bg || mask) return true;
|
|
136313
|
+
}
|
|
136314
|
+
return false;
|
|
136315
|
+
}
|
|
136316
|
+
|
|
136317
|
+
// src/api/preCache.js
|
|
136318
|
+
async function preCache(root = document, options = {}) {
|
|
136319
|
+
const {
|
|
136320
|
+
embedFonts = true,
|
|
136321
|
+
useProxy = ""
|
|
136322
|
+
} = options;
|
|
136323
|
+
const cacheMode = options.cache ?? options.cacheOpt ?? "full";
|
|
136324
|
+
applyCachePolicy(cacheMode);
|
|
136325
|
+
try {
|
|
136326
|
+
await document.fonts?.ready;
|
|
136327
|
+
} catch {
|
|
136328
|
+
}
|
|
136329
|
+
try {
|
|
136330
|
+
precacheCommonTags();
|
|
136331
|
+
} catch {
|
|
136332
|
+
}
|
|
136333
|
+
cache.session = cache.session || {};
|
|
136334
|
+
if (!cache.session.styleCache) {
|
|
136335
|
+
cache.session.styleCache = /* @__PURE__ */ new WeakMap();
|
|
136336
|
+
}
|
|
136337
|
+
cache.image = cache.image || /* @__PURE__ */ new Map();
|
|
136338
|
+
try {
|
|
136339
|
+
await inlineBackgroundImages(
|
|
136340
|
+
root,
|
|
136341
|
+
/* mirror */
|
|
136342
|
+
void 0,
|
|
136343
|
+
cache.session.styleCache,
|
|
136344
|
+
{ useProxy }
|
|
136345
|
+
);
|
|
136346
|
+
} catch {
|
|
136347
|
+
}
|
|
136348
|
+
let imgEls = [], allEls = [];
|
|
136349
|
+
try {
|
|
136350
|
+
if (root?.querySelectorAll) {
|
|
136351
|
+
imgEls = Array.from(root.querySelectorAll("img[src]"));
|
|
136352
|
+
allEls = Array.from(root.querySelectorAll("*"));
|
|
136353
|
+
}
|
|
136354
|
+
} catch {
|
|
136355
|
+
}
|
|
136356
|
+
const promises = [];
|
|
136357
|
+
for (const img of imgEls) {
|
|
136358
|
+
const src = img?.currentSrc || img?.src;
|
|
136359
|
+
if (!src) continue;
|
|
136360
|
+
if (!cache.image.has(src)) {
|
|
136361
|
+
const p = Promise.resolve().then(async () => {
|
|
136362
|
+
const res = await snapFetch(src, { as: "dataURL", useProxy });
|
|
136363
|
+
if (res?.ok && typeof res.data === "string") {
|
|
136364
|
+
cache.image.set(src, res.data);
|
|
136365
|
+
}
|
|
136366
|
+
}).catch(() => {
|
|
136367
|
+
});
|
|
136368
|
+
promises.push(p);
|
|
136369
|
+
}
|
|
136370
|
+
}
|
|
136371
|
+
for (const el of allEls) {
|
|
136372
|
+
let bg = "";
|
|
136373
|
+
try {
|
|
136374
|
+
bg = getStyle(el).backgroundImage;
|
|
136375
|
+
} catch {
|
|
136376
|
+
}
|
|
136377
|
+
if (bg && bg !== "none") {
|
|
136378
|
+
const parts = splitBackgroundImage(bg);
|
|
136379
|
+
for (const entry of parts) {
|
|
136380
|
+
if (entry.startsWith("url(")) {
|
|
136381
|
+
const p = Promise.resolve().then(() => inlineSingleBackgroundEntry(entry, { ...options, useProxy })).catch(() => {
|
|
136382
|
+
});
|
|
136383
|
+
promises.push(p);
|
|
136384
|
+
}
|
|
136385
|
+
}
|
|
136386
|
+
}
|
|
136387
|
+
}
|
|
136388
|
+
if (embedFonts) {
|
|
136389
|
+
try {
|
|
136390
|
+
const required = collectUsedFontVariants(root);
|
|
136391
|
+
const usedCodepoints = collectUsedCodepoints(root);
|
|
136392
|
+
const safari = typeof isSafari === "function" ? isSafari() : !!isSafari;
|
|
136393
|
+
if (safari) {
|
|
136394
|
+
const families = new Set(
|
|
136395
|
+
Array.from(required).map((k) => String(k).split("__")[0]).filter(Boolean)
|
|
136396
|
+
);
|
|
136397
|
+
await ensureFontsReady(families, 3);
|
|
136398
|
+
}
|
|
136399
|
+
await embedCustomFonts({
|
|
136400
|
+
required,
|
|
136401
|
+
usedCodepoints,
|
|
136402
|
+
exclude: options.excludeFonts,
|
|
136403
|
+
localFonts: options.localFonts,
|
|
136404
|
+
useProxy: options.useProxy ?? useProxy
|
|
136405
|
+
});
|
|
136406
|
+
} catch {
|
|
136407
|
+
}
|
|
136408
|
+
}
|
|
136409
|
+
await Promise.allSettled(promises);
|
|
136410
|
+
}
|
|
136411
|
+
|
|
136412
|
+
const snapdom$1 = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
|
|
136413
|
+
__proto__: null,
|
|
136414
|
+
preCache,
|
|
136415
|
+
snapdom
|
|
136416
|
+
}, Symbol.toStringTag, { value: 'Module' }));
|
|
136417
|
+
|
|
132197
136418
|
exports.ActionSheet = ActionSheet;
|
|
132198
136419
|
exports.Affix = Affix;
|
|
132199
136420
|
exports.Alert = Alert;
|
|
@@ -132228,7 +136449,6 @@ var Vc = (function (exports, vue) {
|
|
|
132228
136449
|
exports.Form = Form;
|
|
132229
136450
|
exports.FormItem = FormItem;
|
|
132230
136451
|
exports.Fragment = Fragment;
|
|
132231
|
-
exports.HTMLToImage = HTMLToImage;
|
|
132232
136452
|
exports.Icon = Icon;
|
|
132233
136453
|
exports.IconManager = IconManager;
|
|
132234
136454
|
exports.Image = Image$1$1;
|
|
@@ -132273,7 +136493,6 @@ var Vc = (function (exports, vue) {
|
|
|
132273
136493
|
exports.MForm = MForm;
|
|
132274
136494
|
exports.MFormItem = MFormItem;
|
|
132275
136495
|
exports.MFragment = MFragment;
|
|
132276
|
-
exports.MHTMLToImage = MHTMLToImage;
|
|
132277
136496
|
exports.MIcon = MIcon;
|
|
132278
136497
|
exports.MImage = MImage;
|
|
132279
136498
|
exports.MImageCrop = MImageCrop;
|
|
@@ -132307,6 +136526,7 @@ var Vc = (function (exports, vue) {
|
|
|
132307
136526
|
exports.MScroller = MScroller;
|
|
132308
136527
|
exports.MSelect = MSelect;
|
|
132309
136528
|
exports.MSlider = MSlider;
|
|
136529
|
+
exports.MSnapshot = MSnapshot;
|
|
132310
136530
|
exports.MSortList = MSortList;
|
|
132311
136531
|
exports.MSpin = MSpin;
|
|
132312
136532
|
exports.MSteps = MSteps;
|
|
@@ -132360,6 +136580,7 @@ var Vc = (function (exports, vue) {
|
|
|
132360
136580
|
exports.ScrollerWheel = ScrollerWheel;
|
|
132361
136581
|
exports.Select = Select;
|
|
132362
136582
|
exports.Slider = Slider;
|
|
136583
|
+
exports.Snapshot = Snapshot;
|
|
132363
136584
|
exports.SortList = SortList;
|
|
132364
136585
|
exports.Spin = Spin;
|
|
132365
136586
|
exports.Steps = Steps;
|