1681 lines
59 KiB
JavaScript
1681 lines
59 KiB
JavaScript
/**
|
|||
|
|
* @vue/runtime-dom v3.6.0-rc.10
|
||
|
|
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
||
|
|
* @license MIT
|
||
|
|
**/
|
||
|
|
import { BaseTransition, BaseTransitionPropsValidators, Fragment, Static, Text, assertNumber, callWithAsyncErrorHandling, camelize, createHydrationRenderer, createRenderer, createVNode, defineComponent, getCurrentInstance, getTransitionRawChildren, h, isRuntimeOnly, nextTick, onBeforeUpdate, onMounted, onUnmounted, onUpdated, queuePostFlushCb, resolveTransitionHooks, setIsHydratingEnabled, setTransitionHooks, toRaw, unref, useInstanceOption, useTransitionState, warn, watch } from "@vue/runtime-core";
|
||
|
|
import { EMPTY_OBJ, NOOP, camelize as camelize$1, canSetValueDirectly, capitalize, extend, hasOwn, hyphenate, includeBooleanAttr, invokeArrayFns, isArray, isFunction, isHTMLTag, isMathMLTag, isModelListener, isNativeOn, isObject, isOn, isPlainObject, isSVGTag, isSet, isSpecialBooleanAttr, isString, isSymbol, looseEqual, looseIndexOf, looseToNumber, normalizeCssVarValue, shouldSetAsAttr, toNumber } from "@vue/shared";
|
||
|
|
export * from "@vue/runtime-core";
|
||
|
|
//#region packages/runtime-dom/src/nodeOps.ts
|
||
|
|
let policy = void 0;
|
||
|
|
const tt = typeof window !== "undefined" && window.trustedTypes;
|
||
|
|
if (tt) try {
|
||
|
|
policy = /*@__PURE__*/ tt.createPolicy("vue", { createHTML: (val) => val });
|
||
|
|
} catch (e) {
|
||
|
|
process.env.NODE_ENV !== "production" && warn(`Error creating trusted types policy: ${e}`);
|
||
|
|
}
|
||
|
|
const unsafeToTrustedHTML = policy ? (val) => policy.createHTML(val) : (val) => val;
|
||
|
|
const svgNS = "http://www.w3.org/2000/svg";
|
||
|
|
const mathmlNS = "http://www.w3.org/1998/Math/MathML";
|
||
|
|
const doc = typeof document !== "undefined" ? document : null;
|
||
|
|
const templateContainer = doc && /*@__PURE__*/ doc.createElement("template");
|
||
|
|
const nodeOps = {
|
||
|
|
insert: (child, parent, anchor) => {
|
||
|
|
parent.insertBefore(child, anchor || null);
|
||
|
|
},
|
||
|
|
remove: (child) => {
|
||
|
|
const parent = child.parentNode;
|
||
|
|
if (parent) parent.removeChild(child);
|
||
|
|
},
|
||
|
|
createElement: (tag, namespace, is, props) => {
|
||
|
|
const el = namespace === "svg" ? doc.createElementNS(svgNS, tag) : namespace === "mathml" ? doc.createElementNS(mathmlNS, tag) : is ? doc.createElement(tag, { is }) : doc.createElement(tag);
|
||
|
|
if (tag === "select" && props && props.multiple != null) el.setAttribute("multiple", props.multiple);
|
||
|
|
return el;
|
||
|
|
},
|
||
|
|
createText: (text) => doc.createTextNode(text),
|
||
|
|
createComment: (text) => doc.createComment(text),
|
||
|
|
setText: (node, text) => {
|
||
|
|
node.nodeValue = text;
|
||
|
|
},
|
||
|
|
setElementText: (el, text) => {
|
||
|
|
el.textContent = text;
|
||
|
|
},
|
||
|
|
parentNode: (node) => node.parentNode,
|
||
|
|
nextSibling: (node) => node.nextSibling,
|
||
|
|
querySelector: (selector) => doc.querySelector(selector),
|
||
|
|
setScopeId(el, id) {
|
||
|
|
el.setAttribute(id, "");
|
||
|
|
},
|
||
|
|
insertStaticContent(content, parent, anchor, namespace, start, end) {
|
||
|
|
const before = anchor ? anchor.previousSibling : parent.lastChild;
|
||
|
|
if (start && (start === end || start.nextSibling)) while (true) {
|
||
|
|
parent.insertBefore(start.cloneNode(true), anchor);
|
||
|
|
if (start === end || !(start = start.nextSibling)) break;
|
||
|
|
}
|
||
|
|
else {
|
||
|
|
templateContainer.innerHTML = unsafeToTrustedHTML(namespace === "svg" ? `<svg>${content}</svg>` : namespace === "mathml" ? `<math>${content}</math>` : content);
|
||
|
|
const template = templateContainer.content;
|
||
|
|
if (namespace === "svg" || namespace === "mathml") {
|
||
|
|
const wrapper = template.firstChild;
|
||
|
|
while (wrapper.firstChild) template.appendChild(wrapper.firstChild);
|
||
|
|
template.removeChild(wrapper);
|
||
|
|
}
|
||
|
|
parent.insertBefore(template, anchor);
|
||
|
|
}
|
||
|
|
return [before ? before.nextSibling : parent.firstChild, anchor ? anchor.previousSibling : parent.lastChild];
|
||
|
|
}
|
||
|
|
};
|
||
|
|
//#endregion
|
||
|
|
//#region packages/runtime-dom/src/components/Transition.ts
|
||
|
|
const TRANSITION = "transition";
|
||
|
|
const ANIMATION = "animation";
|
||
|
|
const vtcKey = Symbol("_vtc");
|
||
|
|
const DOMTransitionPropsValidators = {
|
||
|
|
name: String,
|
||
|
|
type: String,
|
||
|
|
css: {
|
||
|
|
type: Boolean,
|
||
|
|
default: true
|
||
|
|
},
|
||
|
|
duration: [
|
||
|
|
String,
|
||
|
|
Number,
|
||
|
|
Object
|
||
|
|
],
|
||
|
|
enterFromClass: String,
|
||
|
|
enterActiveClass: String,
|
||
|
|
enterToClass: String,
|
||
|
|
appearFromClass: String,
|
||
|
|
appearActiveClass: String,
|
||
|
|
appearToClass: String,
|
||
|
|
leaveFromClass: String,
|
||
|
|
leaveActiveClass: String,
|
||
|
|
leaveToClass: String
|
||
|
|
};
|
||
|
|
const TransitionPropsValidators = /*@__PURE__*/ extend({}, BaseTransitionPropsValidators, DOMTransitionPropsValidators);
|
||
|
|
/**
|
||
|
|
* Wrap logic that attaches extra properties to Transition in a function
|
||
|
|
* so that it can be annotated as pure
|
||
|
|
*/
|
||
|
|
const decorate$1 = (t) => {
|
||
|
|
t.displayName = "Transition";
|
||
|
|
t.props = TransitionPropsValidators;
|
||
|
|
return t;
|
||
|
|
};
|
||
|
|
/**
|
||
|
|
* DOM Transition is a higher-order-component based on the platform-agnostic
|
||
|
|
* base Transition component, with DOM-specific logic.
|
||
|
|
*/
|
||
|
|
const Transition = /*@__PURE__*/ decorate$1((props, { slots }) => h(BaseTransition, resolveTransitionProps(props), slots));
|
||
|
|
/**
|
||
|
|
* #3227 Incoming hooks may be merged into arrays when wrapping Transition
|
||
|
|
* with custom HOCs.
|
||
|
|
*/
|
||
|
|
const callHook = (hook, args = []) => {
|
||
|
|
if (isArray(hook)) hook.forEach((h) => h(...args));
|
||
|
|
else if (hook) hook(...args);
|
||
|
|
};
|
||
|
|
/**
|
||
|
|
* Check if a hook expects a callback (2nd arg), which means the user
|
||
|
|
* intends to explicitly control the end of the transition.
|
||
|
|
*/
|
||
|
|
const hasExplicitCallback = (hook) => {
|
||
|
|
return hook ? isArray(hook) ? hook.some((h) => h.length > 1) : hook.length > 1 : false;
|
||
|
|
};
|
||
|
|
function resolveTransitionProps(rawProps) {
|
||
|
|
const baseProps = {};
|
||
|
|
for (const key in rawProps) if (!(key in DOMTransitionPropsValidators)) baseProps[key] = rawProps[key];
|
||
|
|
if (rawProps.css === false) return baseProps;
|
||
|
|
const { name = "v", type, duration, enterFromClass = `${name}-enter-from`, enterActiveClass = `${name}-enter-active`, enterToClass = `${name}-enter-to`, appearFromClass = enterFromClass, appearActiveClass = enterActiveClass, appearToClass = enterToClass, leaveFromClass = `${name}-leave-from`, leaveActiveClass = `${name}-leave-active`, leaveToClass = `${name}-leave-to` } = rawProps;
|
||
|
|
const durations = normalizeDuration(duration);
|
||
|
|
const enterDuration = durations && durations[0];
|
||
|
|
const leaveDuration = durations && durations[1];
|
||
|
|
const { onBeforeEnter, onEnter, onEnterCancelled, onLeave, onLeaveCancelled, onBeforeAppear = onBeforeEnter, onAppear = onEnter, onAppearCancelled = onEnterCancelled } = baseProps;
|
||
|
|
const finishEnter = (el, isAppear, done, isCancelled) => {
|
||
|
|
el._enterCancelled = isCancelled;
|
||
|
|
removeTransitionClass(el, isAppear ? appearToClass : enterToClass);
|
||
|
|
removeTransitionClass(el, isAppear ? appearActiveClass : enterActiveClass);
|
||
|
|
done && done();
|
||
|
|
};
|
||
|
|
const finishLeave = (el, done) => {
|
||
|
|
el._isLeaving = false;
|
||
|
|
removeTransitionClass(el, leaveFromClass);
|
||
|
|
removeTransitionClass(el, leaveToClass);
|
||
|
|
removeTransitionClass(el, leaveActiveClass);
|
||
|
|
done && done();
|
||
|
|
};
|
||
|
|
const makeEnterHook = (isAppear) => {
|
||
|
|
return (el, done) => {
|
||
|
|
const hook = isAppear ? onAppear : onEnter;
|
||
|
|
const resolve = () => finishEnter(el, isAppear, done);
|
||
|
|
callHook(hook, [el, resolve]);
|
||
|
|
nextFrame(() => {
|
||
|
|
removeTransitionClass(el, isAppear ? appearFromClass : enterFromClass);
|
||
|
|
addTransitionClass(el, isAppear ? appearToClass : enterToClass);
|
||
|
|
if (!hasExplicitCallback(hook)) whenTransitionEnds(el, type, enterDuration, resolve);
|
||
|
|
});
|
||
|
|
};
|
||
|
|
};
|
||
|
|
return extend(baseProps, {
|
||
|
|
onBeforeEnter(el) {
|
||
|
|
callHook(onBeforeEnter, [el]);
|
||
|
|
addTransitionClass(el, enterFromClass);
|
||
|
|
addTransitionClass(el, enterActiveClass);
|
||
|
|
},
|
||
|
|
onBeforeAppear(el) {
|
||
|
|
callHook(onBeforeAppear, [el]);
|
||
|
|
addTransitionClass(el, appearFromClass);
|
||
|
|
addTransitionClass(el, appearActiveClass);
|
||
|
|
},
|
||
|
|
onEnter: makeEnterHook(false),
|
||
|
|
onAppear: makeEnterHook(true),
|
||
|
|
onLeave(el, done) {
|
||
|
|
el._isLeaving = true;
|
||
|
|
const resolve = () => finishLeave(el, done);
|
||
|
|
addTransitionClass(el, leaveFromClass);
|
||
|
|
if (!el._enterCancelled) {
|
||
|
|
forceReflow(el);
|
||
|
|
addTransitionClass(el, leaveActiveClass);
|
||
|
|
} else {
|
||
|
|
addTransitionClass(el, leaveActiveClass);
|
||
|
|
forceReflow(el);
|
||
|
|
}
|
||
|
|
nextFrame(() => {
|
||
|
|
if (!el._isLeaving) return;
|
||
|
|
removeTransitionClass(el, leaveFromClass);
|
||
|
|
addTransitionClass(el, leaveToClass);
|
||
|
|
if (!hasExplicitCallback(onLeave)) whenTransitionEnds(el, type, leaveDuration, resolve);
|
||
|
|
});
|
||
|
|
callHook(onLeave, [el, resolve]);
|
||
|
|
},
|
||
|
|
onEnterCancelled(el) {
|
||
|
|
finishEnter(el, false, void 0, true);
|
||
|
|
callHook(onEnterCancelled, [el]);
|
||
|
|
},
|
||
|
|
onAppearCancelled(el) {
|
||
|
|
finishEnter(el, true, void 0, true);
|
||
|
|
callHook(onAppearCancelled, [el]);
|
||
|
|
},
|
||
|
|
onLeaveCancelled(el) {
|
||
|
|
finishLeave(el);
|
||
|
|
callHook(onLeaveCancelled, [el]);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
function normalizeDuration(duration) {
|
||
|
|
if (duration == null) return null;
|
||
|
|
else if (isObject(duration)) return [NumberOf(duration.enter), NumberOf(duration.leave)];
|
||
|
|
else {
|
||
|
|
const n = NumberOf(duration);
|
||
|
|
return [n, n];
|
||
|
|
}
|
||
|
|
}
|
||
|
|
function NumberOf(val) {
|
||
|
|
const res = toNumber(val);
|
||
|
|
if (!!(process.env.NODE_ENV !== "production")) assertNumber(res, "<transition> explicit duration");
|
||
|
|
return res;
|
||
|
|
}
|
||
|
|
function addTransitionClass(el, cls) {
|
||
|
|
cls.split(/\s+/).forEach((c) => c && el.classList.add(c));
|
||
|
|
(el[vtcKey] || (el[vtcKey] = /* @__PURE__ */ new Set())).add(cls);
|
||
|
|
}
|
||
|
|
function removeTransitionClass(el, cls) {
|
||
|
|
cls.split(/\s+/).forEach((c) => c && el.classList.remove(c));
|
||
|
|
const _vtc = el[vtcKey];
|
||
|
|
if (_vtc) {
|
||
|
|
_vtc.delete(cls);
|
||
|
|
if (!_vtc.size) el[vtcKey] = void 0;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
function nextFrame(cb) {
|
||
|
|
requestAnimationFrame(() => {
|
||
|
|
requestAnimationFrame(cb);
|
||
|
|
});
|
||
|
|
}
|
||
|
|
let endId = 0;
|
||
|
|
function whenTransitionEnds(el, expectedType, explicitTimeout, resolve) {
|
||
|
|
const id = el._endId = ++endId;
|
||
|
|
const resolveIfNotStale = () => {
|
||
|
|
if (id === el._endId) resolve();
|
||
|
|
};
|
||
|
|
if (explicitTimeout != null) return setTimeout(resolveIfNotStale, explicitTimeout);
|
||
|
|
const { type, timeout, propCount } = getTransitionInfo(el, expectedType);
|
||
|
|
if (!type) return resolve();
|
||
|
|
const endEvent = type + "end";
|
||
|
|
let ended = 0;
|
||
|
|
const end = () => {
|
||
|
|
el.removeEventListener(endEvent, onEnd);
|
||
|
|
resolveIfNotStale();
|
||
|
|
};
|
||
|
|
const onEnd = (e) => {
|
||
|
|
if (e.target === el && ++ended >= propCount) end();
|
||
|
|
};
|
||
|
|
setTimeout(() => {
|
||
|
|
if (ended < propCount) end();
|
||
|
|
}, timeout + 1);
|
||
|
|
el.addEventListener(endEvent, onEnd);
|
||
|
|
}
|
||
|
|
function getTransitionInfo(el, expectedType) {
|
||
|
|
const styles = window.getComputedStyle(el);
|
||
|
|
const getStyleProperties = (key) => (styles[key] || "").split(", ");
|
||
|
|
const transitionDelays = getStyleProperties(`${TRANSITION}Delay`);
|
||
|
|
const transitionDurations = getStyleProperties(`${TRANSITION}Duration`);
|
||
|
|
const transitionTimeout = getTimeout(transitionDelays, transitionDurations);
|
||
|
|
const animationDelays = getStyleProperties(`${ANIMATION}Delay`);
|
||
|
|
const animationDurations = getStyleProperties(`${ANIMATION}Duration`);
|
||
|
|
const animationTimeout = getTimeout(animationDelays, animationDurations);
|
||
|
|
let type = null;
|
||
|
|
let timeout = 0;
|
||
|
|
let propCount = 0;
|
||
|
|
if (expectedType === TRANSITION) {
|
||
|
|
if (transitionTimeout > 0) {
|
||
|
|
type = TRANSITION;
|
||
|
|
timeout = transitionTimeout;
|
||
|
|
propCount = transitionDurations.length;
|
||
|
|
}
|
||
|
|
} else if (expectedType === ANIMATION) {
|
||
|
|
if (animationTimeout > 0) {
|
||
|
|
type = ANIMATION;
|
||
|
|
timeout = animationTimeout;
|
||
|
|
propCount = animationDurations.length;
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
timeout = Math.max(transitionTimeout, animationTimeout);
|
||
|
|
type = timeout > 0 ? transitionTimeout > animationTimeout ? TRANSITION : ANIMATION : null;
|
||
|
|
propCount = type ? type === TRANSITION ? transitionDurations.length : animationDurations.length : 0;
|
||
|
|
}
|
||
|
|
const hasTransform = type === TRANSITION && /\b(?:transform|all)(?:,|$)/.test(getStyleProperties(`${TRANSITION}Property`).toString());
|
||
|
|
return {
|
||
|
|
type,
|
||
|
|
timeout,
|
||
|
|
propCount,
|
||
|
|
hasTransform
|
||
|
|
};
|
||
|
|
}
|
||
|
|
function getTimeout(delays, durations) {
|
||
|
|
while (delays.length < durations.length) delays = delays.concat(delays);
|
||
|
|
return Math.max(...durations.map((d, i) => toMs(d) + toMs(delays[i])));
|
||
|
|
}
|
||
|
|
function toMs(s) {
|
||
|
|
if (s === "auto") return 0;
|
||
|
|
return Number(s.slice(0, -1).replace(",", ".")) * 1e3;
|
||
|
|
}
|
||
|
|
function forceReflow(el) {
|
||
|
|
return (el ? el.ownerDocument : document).body.offsetHeight;
|
||
|
|
}
|
||
|
|
//#endregion
|
||
|
|
//#region packages/runtime-dom/src/modules/class.ts
|
||
|
|
function patchClass(el, value, isSVG) {
|
||
|
|
const transitionClasses = el[vtcKey];
|
||
|
|
if (transitionClasses) value = (value ? [value, ...transitionClasses] : [...transitionClasses]).join(" ");
|
||
|
|
if (value == null) el.removeAttribute("class");
|
||
|
|
else if (isSVG) el.setAttribute("class", value);
|
||
|
|
else el.className = value;
|
||
|
|
}
|
||
|
|
//#endregion
|
||
|
|
//#region packages/runtime-dom/src/directives/vShow.ts
|
||
|
|
const vShowOriginalDisplay = Symbol("_vod");
|
||
|
|
const vShowHidden = Symbol("_vsh");
|
||
|
|
const vShow = {
|
||
|
|
name: "show",
|
||
|
|
beforeMount(el, { value }, { transition }) {
|
||
|
|
el[vShowOriginalDisplay] = el.style.display === "none" ? "" : el.style.display;
|
||
|
|
if (transition && value) transition.beforeEnter(el);
|
||
|
|
else setDisplay(el, value);
|
||
|
|
},
|
||
|
|
mounted(el, { value }, { transition }) {
|
||
|
|
if (transition && value) transition.enter(el);
|
||
|
|
},
|
||
|
|
updated(el, { value, oldValue }, { transition }) {
|
||
|
|
if (!value === !oldValue) return;
|
||
|
|
if (transition) {
|
||
|
|
if (value) {
|
||
|
|
transition.beforeEnter(el);
|
||
|
|
setDisplay(el, true);
|
||
|
|
transition.enter(el);
|
||
|
|
} else transition.leave(el, () => {
|
||
|
|
setDisplay(el, false);
|
||
|
|
});
|
||
|
|
} else setDisplay(el, value);
|
||
|
|
},
|
||
|
|
beforeUnmount(el, { value }) {
|
||
|
|
setDisplay(el, value);
|
||
|
|
}
|
||
|
|
};
|
||
|
|
function setDisplay(el, value) {
|
||
|
|
el.style.display = value ? el[vShowOriginalDisplay] : "none";
|
||
|
|
el[vShowHidden] = !value;
|
||
|
|
}
|
||
|
|
function initVShowForSSR() {
|
||
|
|
vShow.getSSRProps = ({ value }) => {
|
||
|
|
if (!value) return { style: { display: "none" } };
|
||
|
|
};
|
||
|
|
}
|
||
|
|
//#endregion
|
||
|
|
//#region packages/runtime-dom/src/helpers/useCssVars.ts
|
||
|
|
const CSS_VAR_TEXT = Symbol(!!(process.env.NODE_ENV !== "production") ? "CSS_VAR_TEXT" : "");
|
||
|
|
/**
|
||
|
|
* Runtime helper for SFC's CSS variable injection feature.
|
||
|
|
* @private
|
||
|
|
*/
|
||
|
|
function useCssVars(getter) {
|
||
|
|
const instance = getCurrentInstance();
|
||
|
|
/* v8 ignore start */
|
||
|
|
if (!instance) {
|
||
|
|
process.env.NODE_ENV !== "production" && warn(`useCssVars is called without current active component instance.`);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
/* v8 ignore stop */
|
||
|
|
const getVars = () => getter(instance.proxy);
|
||
|
|
if (!!(process.env.NODE_ENV !== "production")) instance.getCssVars = getVars;
|
||
|
|
const updateTeleports = instance.ut = (vars = getVars()) => {
|
||
|
|
Array.from(document.querySelectorAll(`[data-v-owner="${instance.uid}"]`)).forEach((node) => setVarsOnNode(node, vars));
|
||
|
|
};
|
||
|
|
const applyCssVars = (vars = getVars()) => {
|
||
|
|
if (instance.ce) setVarsOnNode(instance.ce, vars);
|
||
|
|
else setVarsOnVNode(instance.subTree, vars);
|
||
|
|
updateTeleports(vars);
|
||
|
|
};
|
||
|
|
onBeforeUpdate(() => {
|
||
|
|
queuePostFlushCb(applyCssVars);
|
||
|
|
});
|
||
|
|
onMounted(() => {
|
||
|
|
watch(() => {
|
||
|
|
const vars = getVars();
|
||
|
|
extend({}, vars);
|
||
|
|
applyCssVars(vars);
|
||
|
|
}, NOOP, { flush: "post" });
|
||
|
|
const ob = new MutationObserver(() => applyCssVars());
|
||
|
|
ob.observe(instance.subTree.el.parentNode, { childList: true });
|
||
|
|
onUnmounted(() => ob.disconnect());
|
||
|
|
});
|
||
|
|
}
|
||
|
|
function setVarsOnVNode(vnode, vars) {
|
||
|
|
if (vnode.shapeFlag & 128) {
|
||
|
|
const suspense = vnode.suspense;
|
||
|
|
vnode = suspense.activeBranch;
|
||
|
|
if (suspense.pendingBranch && !suspense.isHydrating) suspense.effects.push(() => {
|
||
|
|
setVarsOnVNode(suspense.activeBranch, vars);
|
||
|
|
});
|
||
|
|
}
|
||
|
|
while (vnode.component) {
|
||
|
|
const component = vnode.component;
|
||
|
|
if (component.vapor) {
|
||
|
|
component.appContext.vapor.applyCssVars(vnode, vars);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
vnode = vnode.component.subTree;
|
||
|
|
}
|
||
|
|
if (vnode.shapeFlag & 1 && vnode.el) setVarsOnNode(vnode.el, vars);
|
||
|
|
else if (vnode.vb) vnode.ctx.appContext.vapor.applyCssVars(vnode, vars);
|
||
|
|
else if (vnode.type === Fragment) vnode.children.forEach((c) => setVarsOnVNode(c, vars));
|
||
|
|
else if (vnode.type === Static) {
|
||
|
|
let { el, anchor } = vnode;
|
||
|
|
while (el) {
|
||
|
|
setVarsOnNode(el, vars);
|
||
|
|
if (el === anchor) break;
|
||
|
|
el = el.nextSibling;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
/**
|
||
|
|
* @internal
|
||
|
|
* shared between vdom and vapor
|
||
|
|
*/
|
||
|
|
function setVarsOnNode(el, vars) {
|
||
|
|
if (el.nodeType === 1) {
|
||
|
|
const style = el.style;
|
||
|
|
let cssText = "";
|
||
|
|
for (const key in vars) {
|
||
|
|
const value = normalizeCssVarValue(vars[key]);
|
||
|
|
style.setProperty(`--${key}`, value);
|
||
|
|
cssText += `--${key}: ${value};`;
|
||
|
|
}
|
||
|
|
style[CSS_VAR_TEXT] = cssText;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
//#endregion
|
||
|
|
//#region packages/runtime-dom/src/modules/style.ts
|
||
|
|
const displayRE = /(?:^|;)\s*display\s*:/;
|
||
|
|
function patchStyle(el, prev, next) {
|
||
|
|
const style = el.style;
|
||
|
|
const isCssString = isString(next);
|
||
|
|
let hasControlledDisplay = false;
|
||
|
|
if (next && !isCssString) {
|
||
|
|
if (prev) {
|
||
|
|
if (!isString(prev)) {
|
||
|
|
for (const key in prev) if (next[key] == null) setStyle(style, key, "");
|
||
|
|
} else for (const prevStyle of prev.split(";")) {
|
||
|
|
const key = prevStyle.slice(0, prevStyle.indexOf(":")).trim();
|
||
|
|
if (next[key] == null) setStyle(style, key, "");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
for (const key in next) {
|
||
|
|
if (key === "display") hasControlledDisplay = true;
|
||
|
|
const value = next[key];
|
||
|
|
if (value != null) {
|
||
|
|
if (!shouldPreserveTextareaResizeStyle(el, key, !isString(prev) && prev ? prev[key] : void 0, value)) setStyle(style, key, value);
|
||
|
|
} else setStyle(style, key, "");
|
||
|
|
}
|
||
|
|
} else if (isCssString) {
|
||
|
|
if (prev !== next) {
|
||
|
|
const cssVarText = style[CSS_VAR_TEXT];
|
||
|
|
if (cssVarText) next += ";" + cssVarText;
|
||
|
|
style.cssText = next;
|
||
|
|
hasControlledDisplay = displayRE.test(next);
|
||
|
|
}
|
||
|
|
} else if (prev) {
|
||
|
|
const cssVarText = style[CSS_VAR_TEXT];
|
||
|
|
if (cssVarText) style.cssText = cssVarText;
|
||
|
|
else el.removeAttribute("style");
|
||
|
|
}
|
||
|
|
if (vShowOriginalDisplay in el) {
|
||
|
|
el[vShowOriginalDisplay] = hasControlledDisplay ? style.display : "";
|
||
|
|
if (el[vShowHidden]) style.display = "none";
|
||
|
|
}
|
||
|
|
}
|
||
|
|
const semicolonRE = /[^\\];\s*$/;
|
||
|
|
const importantRE = /\s*!important$/;
|
||
|
|
function setStyle(style, name, rawVal) {
|
||
|
|
if (isArray(rawVal)) rawVal.forEach((v) => setStyle(style, name, v));
|
||
|
|
else {
|
||
|
|
const val = rawVal == null ? "" : String(rawVal);
|
||
|
|
if (!!(process.env.NODE_ENV !== "production")) {
|
||
|
|
if (semicolonRE.test(val)) warn(`Unexpected semicolon at the end of '${name}' style value: '${val}'`);
|
||
|
|
}
|
||
|
|
if (name.startsWith("--")) {
|
||
|
|
if (importantRE.test(val)) style.setProperty(name, val.replace(importantRE, ""), "important");
|
||
|
|
else style.setProperty(name, val);
|
||
|
|
} else {
|
||
|
|
const prefixed = autoPrefix(style, name);
|
||
|
|
if (importantRE.test(val)) style.setProperty(hyphenate(prefixed), val.replace(importantRE, ""), "important");
|
||
|
|
else style[prefixed] = val;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
const prefixes = [
|
||
|
|
"Webkit",
|
||
|
|
"Moz",
|
||
|
|
"ms"
|
||
|
|
];
|
||
|
|
const prefixCache = {};
|
||
|
|
function autoPrefix(style, rawName) {
|
||
|
|
const cached = prefixCache[rawName];
|
||
|
|
if (cached) return cached;
|
||
|
|
let name = camelize(rawName);
|
||
|
|
if (name !== "filter" && name in style) return prefixCache[rawName] = name;
|
||
|
|
name = capitalize(name);
|
||
|
|
for (let i = 0; i < prefixes.length; i++) {
|
||
|
|
const prefixed = prefixes[i] + name;
|
||
|
|
if (prefixed in style) return prefixCache[rawName] = prefixed;
|
||
|
|
}
|
||
|
|
return rawName;
|
||
|
|
}
|
||
|
|
/**
|
||
|
|
* Browsers update textarea width/height directly during native resize.
|
||
|
|
* Only special-case this common textarea path for now; other resize scenarios
|
||
|
|
* still follow normal vnode style patching.
|
||
|
|
*/
|
||
|
|
function shouldPreserveTextareaResizeStyle(el, key, prev, next) {
|
||
|
|
return el.tagName === "TEXTAREA" && (key === "width" || key === "height") && isString(next) && prev === next;
|
||
|
|
}
|
||
|
|
//#endregion
|
||
|
|
//#region packages/runtime-dom/src/modules/attrs.ts
|
||
|
|
const xlinkNS = "http://www.w3.org/1999/xlink";
|
||
|
|
function patchAttr(el, key, value, isSVG, instance, isBoolean = isSpecialBooleanAttr(key)) {
|
||
|
|
if (isSVG && key.startsWith("xlink:")) {
|
||
|
|
if (value == null) el.removeAttributeNS(xlinkNS, key.slice(6, key.length));
|
||
|
|
else el.setAttributeNS(xlinkNS, key, value);
|
||
|
|
} else if (value == null || isBoolean && !includeBooleanAttr(value)) el.removeAttribute(key);
|
||
|
|
else el.setAttribute(key, isBoolean ? "" : isSymbol(value) ? String(value) : value);
|
||
|
|
}
|
||
|
|
//#endregion
|
||
|
|
//#region packages/runtime-dom/src/modules/props.ts
|
||
|
|
function patchDOMProp(el, key, value, parentComponent, attrName) {
|
||
|
|
if (key === "innerHTML" || key === "textContent") {
|
||
|
|
if (value != null) el[key] = key === "innerHTML" ? unsafeToTrustedHTML(value) : value;
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
const tag = el.tagName;
|
||
|
|
if (key === "value" && canSetValueDirectly(tag)) {
|
||
|
|
const oldValue = tag === "OPTION" ? el.getAttribute("value") || "" : el.value;
|
||
|
|
const newValue = value == null ? el.type === "checkbox" ? "on" : "" : String(value);
|
||
|
|
if (oldValue !== newValue || !("_value" in el)) el.value = newValue;
|
||
|
|
if (value == null) el.removeAttribute(key);
|
||
|
|
el._value = value;
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
let needRemove = false;
|
||
|
|
if (value === "" || value == null) {
|
||
|
|
const type = typeof el[key];
|
||
|
|
if (type === "boolean") value = includeBooleanAttr(value);
|
||
|
|
else if (value == null && type === "string") {
|
||
|
|
value = "";
|
||
|
|
needRemove = true;
|
||
|
|
} else if (type === "number") {
|
||
|
|
value = 0;
|
||
|
|
needRemove = true;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
try {
|
||
|
|
el[key] = value;
|
||
|
|
} catch (e) {
|
||
|
|
if (!!(process.env.NODE_ENV !== "production") && !needRemove) warn(`Failed setting prop "${key}" on <${tag.toLowerCase()}>: value ${value} is invalid.`, e);
|
||
|
|
}
|
||
|
|
needRemove && el.removeAttribute(attrName || key);
|
||
|
|
}
|
||
|
|
//#endregion
|
||
|
|
//#region packages/runtime-dom/src/modules/events.ts
|
||
|
|
function addEventListener(el, event, handler, options) {
|
||
|
|
el.addEventListener(event, handler, options);
|
||
|
|
}
|
||
|
|
function removeEventListener(el, event, handler, options) {
|
||
|
|
el.removeEventListener(event, handler, options);
|
||
|
|
}
|
||
|
|
const veiKey = Symbol("_vei");
|
||
|
|
function patchEvent(el, rawName, prevValue, nextValue, instance = null) {
|
||
|
|
const invokers = el[veiKey] || (el[veiKey] = {});
|
||
|
|
const existingInvoker = invokers[rawName];
|
||
|
|
if (nextValue && existingInvoker) existingInvoker.value = !!(process.env.NODE_ENV !== "production") ? sanitizeEventValue(nextValue, rawName) : nextValue;
|
||
|
|
else {
|
||
|
|
const [name, options] = parseEventName(rawName);
|
||
|
|
if (nextValue) addEventListener(el, name, invokers[rawName] = createInvoker(!!(process.env.NODE_ENV !== "production") ? sanitizeEventValue(nextValue, rawName) : nextValue, instance), options);
|
||
|
|
else if (existingInvoker) {
|
||
|
|
removeEventListener(el, name, existingInvoker, options);
|
||
|
|
invokers[rawName] = void 0;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
const optionsModifierRE = /(Once|Passive|Capture)$/;
|
||
|
|
const optionsModifierEventRE = /^on:?(?:Once|Passive|Capture)$/;
|
||
|
|
function parseEventName(name) {
|
||
|
|
let options;
|
||
|
|
let m;
|
||
|
|
while ((m = name.match(optionsModifierRE)) && !optionsModifierEventRE.test(name)) {
|
||
|
|
if (!options) options = {};
|
||
|
|
name = name.slice(0, name.length - m[1].length);
|
||
|
|
options[m[1].toLowerCase()] = true;
|
||
|
|
}
|
||
|
|
return [name[2] === ":" ? name.slice(3) : hyphenate(name.slice(2)), options];
|
||
|
|
}
|
||
|
|
let cachedNow = 0;
|
||
|
|
const p = /*@__PURE__*/ Promise.resolve();
|
||
|
|
const getNow = () => cachedNow || (p.then(() => cachedNow = 0), cachedNow = Date.now());
|
||
|
|
function createInvoker(initialValue, instance) {
|
||
|
|
const invoker = (e) => {
|
||
|
|
if (!e._vts) e._vts = Date.now();
|
||
|
|
else if (e._vts <= invoker.attached) return;
|
||
|
|
const value = invoker.value;
|
||
|
|
if (isArray(value)) {
|
||
|
|
const originalStop = e.stopImmediatePropagation;
|
||
|
|
e.stopImmediatePropagation = () => {
|
||
|
|
originalStop.call(e);
|
||
|
|
e._stopped = true;
|
||
|
|
};
|
||
|
|
const handlers = value.slice();
|
||
|
|
const args = [e];
|
||
|
|
for (let i = 0; i < handlers.length; i++) {
|
||
|
|
if (e._stopped) break;
|
||
|
|
const handler = handlers[i];
|
||
|
|
if (handler) callWithAsyncErrorHandling(handler, instance, 5, args);
|
||
|
|
}
|
||
|
|
} else callWithAsyncErrorHandling(value, instance, 5, [e]);
|
||
|
|
};
|
||
|
|
invoker.value = initialValue;
|
||
|
|
invoker.attached = getNow();
|
||
|
|
return invoker;
|
||
|
|
}
|
||
|
|
function sanitizeEventValue(value, propName) {
|
||
|
|
if (isFunction(value) || isArray(value)) return value;
|
||
|
|
warn(`Wrong type passed as event handler to ${propName} - did you forget @ or : in front of your prop?\nExpected function or array of functions, received type ${typeof value}.`);
|
||
|
|
return NOOP;
|
||
|
|
}
|
||
|
|
//#endregion
|
||
|
|
//#region packages/runtime-dom/src/patchProp.ts
|
||
|
|
const patchProp = (el, key, prevValue, nextValue, namespace, parentComponent) => {
|
||
|
|
const isSVG = namespace === "svg";
|
||
|
|
if (key === "class") patchClass(el, nextValue, isSVG);
|
||
|
|
else if (key === "style") patchStyle(el, prevValue, nextValue);
|
||
|
|
else if (isOn(key)) {
|
||
|
|
if (!isModelListener(key)) patchEvent(el, key, prevValue, nextValue, parentComponent);
|
||
|
|
} else if (key[0] === "." ? (key = key.slice(1), true) : key[0] === "^" ? (key = key.slice(1), false) : shouldSetAsProp(el, key, nextValue, isSVG)) {
|
||
|
|
patchDOMProp(el, key, nextValue, parentComponent);
|
||
|
|
if (!el.tagName.includes("-") && (key === "value" || key === "checked" || key === "selected")) patchAttr(el, key, nextValue, isSVG, parentComponent, key !== "value");
|
||
|
|
} else if (el._isVueCE && (shouldSetAsPropForVueCE(el, key) || el._def.__asyncLoader && (/[A-Z]/.test(key) || !isString(nextValue)))) patchDOMProp(el, camelize$1(key), nextValue, parentComponent, key);
|
||
|
|
else {
|
||
|
|
if (key === "true-value") el._trueValue = nextValue;
|
||
|
|
else if (key === "false-value") el._falseValue = nextValue;
|
||
|
|
patchAttr(el, key, nextValue, isSVG, parentComponent);
|
||
|
|
}
|
||
|
|
};
|
||
|
|
function shouldSetAsProp(el, key, value, isSVG) {
|
||
|
|
if (isSVG) {
|
||
|
|
if (key === "innerHTML" || key === "textContent") return true;
|
||
|
|
if (key in el && isNativeOn(key) && isFunction(value)) return true;
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
if (shouldSetAsAttr(el.tagName, key)) return false;
|
||
|
|
if (isNativeOn(key) && isString(value)) return false;
|
||
|
|
return key in el;
|
||
|
|
}
|
||
|
|
function shouldSetAsPropForVueCE(el, key) {
|
||
|
|
const props = el._def.props;
|
||
|
|
if (!props) return false;
|
||
|
|
const camelKey = camelize$1(key);
|
||
|
|
return Array.isArray(props) ? props.some((prop) => camelize$1(prop) === camelKey) : Object.keys(props).some((prop) => camelize$1(prop) === camelKey);
|
||
|
|
}
|
||
|
|
//#endregion
|
||
|
|
//#region packages/runtime-dom/src/apiCustomElement.ts
|
||
|
|
const REMOVAL = {};
|
||
|
|
/*@__NO_SIDE_EFFECTS__*/
|
||
|
|
function defineCustomElement(options, extraOptions, _createApp) {
|
||
|
|
let Comp = defineComponent(options, extraOptions);
|
||
|
|
if (isPlainObject(Comp)) Comp = extend({}, Comp, extraOptions);
|
||
|
|
class VueCustomElement extends VueElement {
|
||
|
|
constructor(initialProps) {
|
||
|
|
super(Comp, initialProps, _createApp);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
VueCustomElement.def = Comp;
|
||
|
|
return VueCustomElement;
|
||
|
|
}
|
||
|
|
const defineSSRCustomElement = ((options, extraOptions) => {
|
||
|
|
return /* @__PURE__ */ defineCustomElement(options, extraOptions, createSSRApp);
|
||
|
|
});
|
||
|
|
const BaseClass = typeof HTMLElement !== "undefined" ? HTMLElement : class {};
|
||
|
|
var VueElementBase = class VueElementBase extends BaseClass {
|
||
|
|
constructor(def, props = {}, createAppFn) {
|
||
|
|
super();
|
||
|
|
this._isVueCE = true;
|
||
|
|
this._instance = null;
|
||
|
|
this._app = null;
|
||
|
|
this._connected = false;
|
||
|
|
this._resolved = false;
|
||
|
|
this._numberProps = null;
|
||
|
|
this._styleChildren = /* @__PURE__ */ new WeakSet();
|
||
|
|
this._styleAnchors = /* @__PURE__ */ new WeakMap();
|
||
|
|
this._patching = false;
|
||
|
|
this._dirty = false;
|
||
|
|
this._ob = null;
|
||
|
|
this._def = def;
|
||
|
|
this._props = props;
|
||
|
|
this._createApp = createAppFn;
|
||
|
|
this._nonce = def.nonce;
|
||
|
|
if (this._needsHydration()) this._root = this.shadowRoot;
|
||
|
|
else if (def.shadowRoot !== false) {
|
||
|
|
this.attachShadow(extend({}, def.shadowRootOptions, { mode: "open" }));
|
||
|
|
this._root = this.shadowRoot;
|
||
|
|
} else this._root = this;
|
||
|
|
}
|
||
|
|
connectedCallback() {
|
||
|
|
if (!this.isConnected) return;
|
||
|
|
if (!this.shadowRoot && !this._resolved) this._parseSlots();
|
||
|
|
this._connected = true;
|
||
|
|
let parent = this;
|
||
|
|
while (parent = parent && (parent.assignedSlot || parent.parentNode || parent.host)) if (parent instanceof VueElementBase) {
|
||
|
|
this._parent = parent;
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
if (!this._instance) {
|
||
|
|
if (this._resolved) this._mountComponent(this._def);
|
||
|
|
else if (parent && parent._pendingResolve) this._pendingResolve = parent._pendingResolve.then(() => {
|
||
|
|
this._pendingResolve = void 0;
|
||
|
|
if (this.isConnected) return this._resolveDef();
|
||
|
|
});
|
||
|
|
else this._resolveDef();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
disconnectedCallback() {
|
||
|
|
this._connected = false;
|
||
|
|
nextTick(() => {
|
||
|
|
if (!this._connected) {
|
||
|
|
if (this._ob) {
|
||
|
|
this._ob.disconnect();
|
||
|
|
this._ob = null;
|
||
|
|
}
|
||
|
|
this._unmount();
|
||
|
|
if (this._teleportTargets) {
|
||
|
|
this._teleportTargets.clear();
|
||
|
|
this._teleportTargets = void 0;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
_setParent(parent = this._parent) {
|
||
|
|
if (parent && this._instance) {
|
||
|
|
this._instance.parent = parent._instance;
|
||
|
|
this._inheritParentContext(parent);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
_inheritParentContext(parent = this._parent) {
|
||
|
|
if (parent && this._app) Object.setPrototypeOf(this._app._context.provides, parent._instance.provides);
|
||
|
|
}
|
||
|
|
_processMutations(mutations) {
|
||
|
|
for (const m of mutations) this._setAttr(m.attributeName);
|
||
|
|
}
|
||
|
|
/**
|
||
|
|
* resolve inner component definition (handle possible async component)
|
||
|
|
*/
|
||
|
|
_resolveDef() {
|
||
|
|
if (this._pendingResolve) return this._pendingResolve;
|
||
|
|
for (let i = 0; i < this.attributes.length; i++) this._setAttr(this.attributes[i].name);
|
||
|
|
this._ob = new MutationObserver(this._processMutations.bind(this));
|
||
|
|
this._ob.observe(this, { attributes: true });
|
||
|
|
const resolve = (def) => {
|
||
|
|
this._resolved = true;
|
||
|
|
this._pendingResolve = void 0;
|
||
|
|
const { props, styles } = def;
|
||
|
|
let numberProps;
|
||
|
|
if (props && !isArray(props)) for (const key in props) {
|
||
|
|
const opt = props[key];
|
||
|
|
if (opt === Number || opt && opt.type === Number) {
|
||
|
|
if (key in this._props) this._props[key] = toNumber(this._props[key]);
|
||
|
|
(numberProps || (numberProps = Object.create(null)))[camelize$1(key)] = true;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
this._numberProps = numberProps;
|
||
|
|
this._resolveProps(def);
|
||
|
|
if (this.shadowRoot) this._applyStyles(styles);
|
||
|
|
else if (!!(process.env.NODE_ENV !== "production") && styles) warn("Custom element style injection is not supported when using shadowRoot: false");
|
||
|
|
this._mountComponent(def);
|
||
|
|
};
|
||
|
|
const asyncDef = this._def.__asyncLoader;
|
||
|
|
if (asyncDef) {
|
||
|
|
const { configureApp } = this._def;
|
||
|
|
this._pendingResolve = asyncDef().then((def) => {
|
||
|
|
def.configureApp = configureApp;
|
||
|
|
this._def = def;
|
||
|
|
resolve(def);
|
||
|
|
});
|
||
|
|
return this._pendingResolve;
|
||
|
|
} else resolve(this._def);
|
||
|
|
}
|
||
|
|
_mountComponent(def) {
|
||
|
|
this._mount(def);
|
||
|
|
this._processExposed();
|
||
|
|
}
|
||
|
|
_processExposed() {
|
||
|
|
const exposed = this._instance && this._instance.exposed;
|
||
|
|
if (!exposed) return;
|
||
|
|
for (const key in exposed) if (!hasOwn(this, key)) Object.defineProperty(this, key, { get: () => unref(exposed[key]) });
|
||
|
|
else if (!!(process.env.NODE_ENV !== "production")) warn(`Exposed property "${key}" already exists on custom element.`);
|
||
|
|
}
|
||
|
|
_processInstance() {
|
||
|
|
this._instance.ce = this;
|
||
|
|
this._instance.isCE = true;
|
||
|
|
if (!!(process.env.NODE_ENV !== "production")) this._instance.ceReload = (newStyles) => {
|
||
|
|
if (this._styles) {
|
||
|
|
this._styles.forEach((s) => this._root.removeChild(s));
|
||
|
|
this._styles.length = 0;
|
||
|
|
}
|
||
|
|
this._styleAnchors.delete(this._def);
|
||
|
|
this._applyStyles(newStyles);
|
||
|
|
if (!this._instance.vapor) this._instance = null;
|
||
|
|
this._update();
|
||
|
|
};
|
||
|
|
const dispatch = (event, args) => {
|
||
|
|
this.dispatchEvent(new CustomEvent(event, isPlainObject(args[0]) ? extend({ detail: args }, args[0]) : { detail: args }));
|
||
|
|
};
|
||
|
|
this._instance.emit = (event, ...args) => {
|
||
|
|
dispatch(event, args);
|
||
|
|
if (hyphenate(event) !== event) dispatch(hyphenate(event), args);
|
||
|
|
};
|
||
|
|
this._setParent();
|
||
|
|
}
|
||
|
|
_resolveProps(def) {
|
||
|
|
const { props } = def;
|
||
|
|
const declaredPropKeys = isArray(props) ? props : Object.keys(props || {});
|
||
|
|
for (const key of Object.keys(this)) if (key[0] !== "_" && declaredPropKeys.includes(key)) this._setProp(key, this[key]);
|
||
|
|
for (const key of declaredPropKeys.map(camelize$1)) {
|
||
|
|
if (!!(process.env.NODE_ENV !== "production") && key in Object.getPrototypeOf(this)) warn(`Custom element prop "${key}" conflicts with an existing property on the element and will overwrite it.`);
|
||
|
|
Object.defineProperty(this, key, {
|
||
|
|
get() {
|
||
|
|
return this._getProp(key);
|
||
|
|
},
|
||
|
|
set(val) {
|
||
|
|
this._setProp(key, val, true, !this._patching);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
}
|
||
|
|
_setAttr(key) {
|
||
|
|
if (key.startsWith("data-v-")) return;
|
||
|
|
const has = this.hasAttribute(key);
|
||
|
|
let value = has ? this.getAttribute(key) : REMOVAL;
|
||
|
|
const camelKey = camelize$1(key);
|
||
|
|
if (has && this._numberProps && this._numberProps[camelKey]) value = toNumber(value);
|
||
|
|
this._setProp(camelKey, value, false, true);
|
||
|
|
}
|
||
|
|
/**
|
||
|
|
* @internal
|
||
|
|
*/
|
||
|
|
_getProp(key) {
|
||
|
|
return this._props[key];
|
||
|
|
}
|
||
|
|
/**
|
||
|
|
* @internal
|
||
|
|
*/
|
||
|
|
_setProp(key, val, shouldReflect = true, shouldUpdate = false) {
|
||
|
|
if (val !== this._props[key]) {
|
||
|
|
this._dirty = true;
|
||
|
|
if (val === REMOVAL) delete this._props[key];
|
||
|
|
else {
|
||
|
|
this._props[key] = val;
|
||
|
|
if (key === "key" && this._app && this._app._ceVNode) this._app._ceVNode.key = val;
|
||
|
|
}
|
||
|
|
if (shouldUpdate && this._instance) this._update();
|
||
|
|
if (shouldReflect) {
|
||
|
|
const ob = this._ob;
|
||
|
|
if (ob) {
|
||
|
|
this._processMutations(ob.takeRecords());
|
||
|
|
ob.disconnect();
|
||
|
|
}
|
||
|
|
if (val === true) this.setAttribute(hyphenate(key), "");
|
||
|
|
else if (typeof val === "string" || typeof val === "number") this.setAttribute(hyphenate(key), val + "");
|
||
|
|
else if (!val) this.removeAttribute(hyphenate(key));
|
||
|
|
ob && ob.observe(this, { attributes: true });
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
_applyStyles(styles, owner, parentComp) {
|
||
|
|
if (!styles) return;
|
||
|
|
if (owner) {
|
||
|
|
if (owner === this._def || this._styleChildren.has(owner)) return;
|
||
|
|
this._styleChildren.add(owner);
|
||
|
|
}
|
||
|
|
const nonce = this._nonce;
|
||
|
|
const root = this.shadowRoot;
|
||
|
|
const insertionAnchor = parentComp ? this._getStyleAnchor(parentComp) || this._getStyleAnchor(this._def) : this._getRootStyleInsertionAnchor(root);
|
||
|
|
let last = null;
|
||
|
|
for (let i = styles.length - 1; i >= 0; i--) {
|
||
|
|
const s = document.createElement("style");
|
||
|
|
if (nonce) s.setAttribute("nonce", nonce);
|
||
|
|
s.textContent = styles[i];
|
||
|
|
root.insertBefore(s, last || insertionAnchor);
|
||
|
|
last = s;
|
||
|
|
if (i === 0) {
|
||
|
|
if (!parentComp) this._styleAnchors.set(this._def, s);
|
||
|
|
if (owner) this._styleAnchors.set(owner, s);
|
||
|
|
}
|
||
|
|
if (!!(process.env.NODE_ENV !== "production")) {
|
||
|
|
if (owner) {
|
||
|
|
if (owner.__hmrId) {
|
||
|
|
if (!this._childStyles) this._childStyles = /* @__PURE__ */ new Map();
|
||
|
|
let entry = this._childStyles.get(owner.__hmrId);
|
||
|
|
if (!entry) this._childStyles.set(owner.__hmrId, entry = []);
|
||
|
|
entry.push(s);
|
||
|
|
}
|
||
|
|
} else (this._styles || (this._styles = [])).push(s);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
_getStyleAnchor(comp) {
|
||
|
|
if (!comp) return null;
|
||
|
|
const anchor = this._styleAnchors.get(comp);
|
||
|
|
if (anchor && anchor.parentNode === this.shadowRoot) return anchor;
|
||
|
|
if (anchor) this._styleAnchors.delete(comp);
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
_getRootStyleInsertionAnchor(root) {
|
||
|
|
for (let i = 0; i < root.childNodes.length; i++) {
|
||
|
|
const node = root.childNodes[i];
|
||
|
|
if (!(node instanceof HTMLStyleElement)) return node;
|
||
|
|
}
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
/**
|
||
|
|
* Only called when shadowRoot is false
|
||
|
|
*/
|
||
|
|
_parseSlots() {
|
||
|
|
const slots = this._slots = {};
|
||
|
|
let n;
|
||
|
|
while (n = this.firstChild) {
|
||
|
|
const slotName = n.nodeType === 1 && n.getAttribute("slot") || "default";
|
||
|
|
(slots[slotName] || (slots[slotName] = [])).push(n);
|
||
|
|
this.removeChild(n);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
/**
|
||
|
|
* Only called when shadowRoot is false
|
||
|
|
*/
|
||
|
|
_renderSlots() {
|
||
|
|
const outlets = this._getSlots();
|
||
|
|
const scopeId = this._instance.type.__scopeId;
|
||
|
|
for (let i = 0; i < outlets.length; i++) {
|
||
|
|
const o = outlets[i];
|
||
|
|
const slotName = o.getAttribute("name") || "default";
|
||
|
|
const content = this._slots[slotName];
|
||
|
|
const parent = o.parentNode;
|
||
|
|
if (content) for (const n of content) {
|
||
|
|
if (scopeId && n.nodeType === 1) {
|
||
|
|
const id = scopeId + "-s";
|
||
|
|
const walker = document.createTreeWalker(n, 1);
|
||
|
|
n.setAttribute(id, "");
|
||
|
|
let child;
|
||
|
|
while (child = walker.nextNode()) child.setAttribute(id, "");
|
||
|
|
}
|
||
|
|
parent.insertBefore(n, o);
|
||
|
|
}
|
||
|
|
else while (o.firstChild) parent.insertBefore(o.firstChild, o);
|
||
|
|
parent.removeChild(o);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
/**
|
||
|
|
* @internal
|
||
|
|
*/
|
||
|
|
_getSlots() {
|
||
|
|
const roots = [this];
|
||
|
|
if (this._teleportTargets) roots.push(...this._teleportTargets);
|
||
|
|
const slots = /* @__PURE__ */ new Set();
|
||
|
|
for (const root of roots) {
|
||
|
|
const found = root.querySelectorAll("slot");
|
||
|
|
for (let i = 0; i < found.length; i++) slots.add(found[i]);
|
||
|
|
}
|
||
|
|
return Array.from(slots);
|
||
|
|
}
|
||
|
|
/**
|
||
|
|
* @internal
|
||
|
|
*/
|
||
|
|
_injectChildStyle(comp, parentComp) {
|
||
|
|
this._applyStyles(comp.styles, comp, parentComp);
|
||
|
|
}
|
||
|
|
/**
|
||
|
|
* @internal
|
||
|
|
*/
|
||
|
|
_beginPatch() {
|
||
|
|
this._patching = true;
|
||
|
|
this._dirty = false;
|
||
|
|
}
|
||
|
|
/**
|
||
|
|
* @internal
|
||
|
|
*/
|
||
|
|
_endPatch() {
|
||
|
|
this._patching = false;
|
||
|
|
if (this._dirty && this._instance) this._update();
|
||
|
|
}
|
||
|
|
/**
|
||
|
|
* @internal
|
||
|
|
*/
|
||
|
|
_hasShadowRoot() {
|
||
|
|
return this._root !== this;
|
||
|
|
}
|
||
|
|
/**
|
||
|
|
* @internal
|
||
|
|
*/
|
||
|
|
_removeChildStyle(comp) {
|
||
|
|
if (!!(process.env.NODE_ENV !== "production")) {
|
||
|
|
this._styleChildren.delete(comp);
|
||
|
|
this._styleAnchors.delete(comp);
|
||
|
|
if (this._childStyles && comp.__hmrId) {
|
||
|
|
const oldStyles = this._childStyles.get(comp.__hmrId);
|
||
|
|
if (oldStyles) {
|
||
|
|
oldStyles.forEach((s) => this._root.removeChild(s));
|
||
|
|
oldStyles.length = 0;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
};
|
||
|
|
var VueElement = class extends VueElementBase {
|
||
|
|
constructor(def, props = {}, createAppFn = createApp) {
|
||
|
|
super(def, props, createAppFn);
|
||
|
|
}
|
||
|
|
_needsHydration() {
|
||
|
|
if (this.shadowRoot && this._createApp !== createApp) return true;
|
||
|
|
else if (!!(process.env.NODE_ENV !== "production") && this.shadowRoot) warn("Custom element has pre-rendered declarative shadow root but is not defined as hydratable. Use `defineSSRCustomElement`.");
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
_mount(def) {
|
||
|
|
if ((!!(process.env.NODE_ENV !== "production") || __VUE_PROD_DEVTOOLS__) && !def.name) def.name = "VueElement";
|
||
|
|
this._app = this._createApp(def);
|
||
|
|
this._inheritParentContext();
|
||
|
|
if (def.configureApp) def.configureApp(this._app);
|
||
|
|
this._app._ceVNode = this._createVNode();
|
||
|
|
this._app.mount(this._root);
|
||
|
|
}
|
||
|
|
_update() {
|
||
|
|
if (!this._app) return;
|
||
|
|
const vnode = this._createVNode();
|
||
|
|
vnode.appContext = this._app._context;
|
||
|
|
render(vnode, this._root);
|
||
|
|
}
|
||
|
|
_unmount() {
|
||
|
|
if (this._app) this._app.unmount();
|
||
|
|
if (this._instance && this._instance.ce) this._instance.ce = void 0;
|
||
|
|
this._app = this._instance = null;
|
||
|
|
}
|
||
|
|
_createVNode() {
|
||
|
|
const baseProps = {};
|
||
|
|
if (!this.shadowRoot) baseProps.onVnodeMounted = baseProps.onVnodeUpdated = this._renderSlots.bind(this);
|
||
|
|
const vnode = createVNode(this._def, extend(baseProps, this._props));
|
||
|
|
if (!this._instance) vnode.ce = (instance) => {
|
||
|
|
this._instance = instance;
|
||
|
|
this._processInstance();
|
||
|
|
};
|
||
|
|
return vnode;
|
||
|
|
}
|
||
|
|
};
|
||
|
|
function useHost(caller) {
|
||
|
|
const { hasInstance, value } = useInstanceOption("ce", true);
|
||
|
|
const el = value;
|
||
|
|
if (el) return el;
|
||
|
|
else if (!!(process.env.NODE_ENV !== "production")) {
|
||
|
|
if (!hasInstance) warn(`${caller || "useHost"} called without an active component instance.`);
|
||
|
|
else warn(`${caller || "useHost"} can only be used in components defined via defineCustomElement.`);
|
||
|
|
}
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
/**
|
||
|
|
* Retrieve the shadowRoot of the current custom element. Only usable in setup()
|
||
|
|
* of a `defineCustomElement` component.
|
||
|
|
*/
|
||
|
|
function useShadowRoot() {
|
||
|
|
const el = !!(process.env.NODE_ENV !== "production") ? useHost("useShadowRoot") : useHost();
|
||
|
|
return el && el.shadowRoot;
|
||
|
|
}
|
||
|
|
//#endregion
|
||
|
|
//#region packages/runtime-dom/src/helpers/useCssModule.ts
|
||
|
|
function useCssModule(name = "$style") {
|
||
|
|
{
|
||
|
|
const { hasInstance, value: type } = useInstanceOption("type", true);
|
||
|
|
if (!hasInstance) {
|
||
|
|
process.env.NODE_ENV !== "production" && warn(`useCssModule must be called inside setup()`);
|
||
|
|
return EMPTY_OBJ;
|
||
|
|
}
|
||
|
|
const modules = type.__cssModules;
|
||
|
|
if (!modules) {
|
||
|
|
process.env.NODE_ENV !== "production" && warn(`Current instance does not have CSS modules injected.`);
|
||
|
|
return EMPTY_OBJ;
|
||
|
|
}
|
||
|
|
const mod = modules[name];
|
||
|
|
if (!mod) {
|
||
|
|
process.env.NODE_ENV !== "production" && warn(`Current instance does not have CSS module named "${name}".`);
|
||
|
|
return EMPTY_OBJ;
|
||
|
|
}
|
||
|
|
return mod;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
//#endregion
|
||
|
|
//#region packages/runtime-dom/src/components/TransitionGroup.ts
|
||
|
|
const positionMap = /* @__PURE__ */ new WeakMap();
|
||
|
|
const newPositionMap = /* @__PURE__ */ new WeakMap();
|
||
|
|
const moveCbKey = Symbol("_moveCb");
|
||
|
|
const enterCbKey = Symbol("_enterCb");
|
||
|
|
/**
|
||
|
|
* Wrap logic that modifies TransitionGroup properties in a function
|
||
|
|
* so that it can be annotated as pure
|
||
|
|
*/
|
||
|
|
const decorate = (t) => {
|
||
|
|
delete t.props.mode;
|
||
|
|
return t;
|
||
|
|
};
|
||
|
|
const TransitionGroup = /* @__PURE__ */ decorate({
|
||
|
|
name: "TransitionGroup",
|
||
|
|
props: /*@__PURE__*/ extend({}, TransitionPropsValidators, {
|
||
|
|
tag: String,
|
||
|
|
moveClass: String
|
||
|
|
}),
|
||
|
|
setup(props, { slots }) {
|
||
|
|
const instance = getCurrentInstance();
|
||
|
|
const state = useTransitionState();
|
||
|
|
let prevChildren;
|
||
|
|
let children;
|
||
|
|
onUpdated(() => {
|
||
|
|
if (!prevChildren.length) return;
|
||
|
|
const moveClass = props.moveClass || `${props.name || "v"}-move`;
|
||
|
|
if (!hasCSSTransform(prevChildren[0].el, instance.vnode.el, moveClass)) {
|
||
|
|
prevChildren = [];
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
prevChildren.forEach((vnode) => callPendingCbs(vnode.el));
|
||
|
|
prevChildren.forEach(recordPosition);
|
||
|
|
const movedChildren = prevChildren.filter(applyTranslation);
|
||
|
|
forceReflow(instance.vnode.el);
|
||
|
|
movedChildren.forEach((c) => {
|
||
|
|
const el = c.el;
|
||
|
|
handleMovedChildren(el, moveClass);
|
||
|
|
});
|
||
|
|
prevChildren = [];
|
||
|
|
});
|
||
|
|
return () => {
|
||
|
|
const rawProps = toRaw(props);
|
||
|
|
const cssTransitionProps = resolveTransitionProps(rawProps);
|
||
|
|
let tag = rawProps.tag || Fragment;
|
||
|
|
prevChildren = [];
|
||
|
|
if (children) for (let i = 0; i < children.length; i++) {
|
||
|
|
const child = children[i];
|
||
|
|
if (child.el && child.el instanceof Element && !child.el[vShowHidden]) {
|
||
|
|
prevChildren.push(child);
|
||
|
|
setTransitionHooks(child, resolveTransitionHooks(child, cssTransitionProps, state, instance));
|
||
|
|
positionMap.set(child, getPosition(child.el));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
children = slots.default ? getTransitionRawChildren(slots.default()) : [];
|
||
|
|
for (let i = 0; i < children.length; i++) {
|
||
|
|
const child = children[i];
|
||
|
|
if (child.key != null) setTransitionHooks(child, resolveTransitionHooks(child, cssTransitionProps, state, instance));
|
||
|
|
else if (!!(process.env.NODE_ENV !== "production") && child.type !== Text) warn(`<TransitionGroup> children must be keyed.`);
|
||
|
|
}
|
||
|
|
return createVNode(tag, null, children);
|
||
|
|
};
|
||
|
|
}
|
||
|
|
});
|
||
|
|
function callPendingCbs(el) {
|
||
|
|
if (el[moveCbKey]) el[moveCbKey]();
|
||
|
|
if (el[enterCbKey]) el[enterCbKey]();
|
||
|
|
}
|
||
|
|
function recordPosition(c) {
|
||
|
|
newPositionMap.set(c, getPosition(c.el));
|
||
|
|
}
|
||
|
|
function applyTranslation(c) {
|
||
|
|
if (baseApplyTranslation(positionMap.get(c), newPositionMap.get(c), c.el)) return c;
|
||
|
|
}
|
||
|
|
function baseApplyTranslation(oldPos, newPos, el) {
|
||
|
|
const dx = oldPos.left - newPos.left;
|
||
|
|
const dy = oldPos.top - newPos.top;
|
||
|
|
if (dx || dy) {
|
||
|
|
const s = el.style;
|
||
|
|
const rect = el.getBoundingClientRect();
|
||
|
|
let scaleX = 1;
|
||
|
|
let scaleY = 1;
|
||
|
|
if (el.offsetWidth) scaleX = rect.width / el.offsetWidth;
|
||
|
|
if (el.offsetHeight) scaleY = rect.height / el.offsetHeight;
|
||
|
|
if (!Number.isFinite(scaleX) || scaleX === 0) scaleX = 1;
|
||
|
|
if (!Number.isFinite(scaleY) || scaleY === 0) scaleY = 1;
|
||
|
|
if (Math.abs(scaleX - 1) < .01) scaleX = 1;
|
||
|
|
if (Math.abs(scaleY - 1) < .01) scaleY = 1;
|
||
|
|
s.transform = s.webkitTransform = `translate(${dx / scaleX}px,${dy / scaleY}px)`;
|
||
|
|
s.transitionDuration = "0s";
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
function getPosition(el) {
|
||
|
|
const rect = el.getBoundingClientRect();
|
||
|
|
return {
|
||
|
|
left: rect.left,
|
||
|
|
top: rect.top
|
||
|
|
};
|
||
|
|
}
|
||
|
|
function hasCSSTransform(el, root, moveClass) {
|
||
|
|
const clone = el.cloneNode();
|
||
|
|
const _vtc = el[vtcKey];
|
||
|
|
if (_vtc) _vtc.forEach((cls) => {
|
||
|
|
cls.split(/\s+/).forEach((c) => c && clone.classList.remove(c));
|
||
|
|
});
|
||
|
|
moveClass.split(/\s+/).forEach((c) => c && clone.classList.add(c));
|
||
|
|
clone.style.display = "none";
|
||
|
|
const container = root.nodeType === 1 ? root : root.parentNode;
|
||
|
|
container.appendChild(clone);
|
||
|
|
const { hasTransform } = getTransitionInfo(clone);
|
||
|
|
container.removeChild(clone);
|
||
|
|
return hasTransform;
|
||
|
|
}
|
||
|
|
const handleMovedChildren = (el, moveClass) => {
|
||
|
|
const style = el.style;
|
||
|
|
addTransitionClass(el, moveClass);
|
||
|
|
style.transform = style.webkitTransform = style.transitionDuration = "";
|
||
|
|
const cb = el[moveCbKey] = (e) => {
|
||
|
|
if (e && e.target !== el) return;
|
||
|
|
if (!e || e.propertyName.endsWith("transform")) {
|
||
|
|
el.removeEventListener("transitionend", cb);
|
||
|
|
el[moveCbKey] = null;
|
||
|
|
removeTransitionClass(el, moveClass);
|
||
|
|
}
|
||
|
|
};
|
||
|
|
el.addEventListener("transitionend", cb);
|
||
|
|
};
|
||
|
|
//#endregion
|
||
|
|
//#region packages/runtime-dom/src/directives/vModel.ts
|
||
|
|
const getModelAssigner = (vnode) => {
|
||
|
|
const fn = vnode.props["onUpdate:modelValue"] || false;
|
||
|
|
return isArray(fn) ? (value) => invokeArrayFns(fn, value) : fn;
|
||
|
|
};
|
||
|
|
function onCompositionStart(e) {
|
||
|
|
e.target.composing = true;
|
||
|
|
}
|
||
|
|
function onCompositionEnd(e) {
|
||
|
|
const target = e.target;
|
||
|
|
if (target.composing) {
|
||
|
|
target.composing = false;
|
||
|
|
target.dispatchEvent(new Event("input"));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
const assignKey = Symbol("_assign");
|
||
|
|
const initialValueKey = Symbol("_initialValue");
|
||
|
|
const vModelText = {
|
||
|
|
created(el, { modifiers: { lazy, trim, number } }, vnode) {
|
||
|
|
if (el.parentNode) {
|
||
|
|
if (el.type === "text") el[initialValueKey] = el.defaultValue.replace(/[\r\n]/g, "");
|
||
|
|
else if (el.type === "textarea") el[initialValueKey] = el.defaultValue.replace(/\r\n?/g, "\n");
|
||
|
|
}
|
||
|
|
el[assignKey] = getModelAssigner(vnode);
|
||
|
|
vModelTextInit(el, trim, number || !!(vnode.props && vnode.props.type === "number"), lazy);
|
||
|
|
},
|
||
|
|
mounted(el, { value, modifiers: { trim, number } }) {
|
||
|
|
const newValue = value == null ? "" : value;
|
||
|
|
const initialValue = el[initialValueKey];
|
||
|
|
delete el[initialValueKey];
|
||
|
|
if (initialValue !== void 0 && (el.type === "text" || el.type === "textarea") && el.value !== initialValue) el[assignKey](castValue(el.value, trim, number));
|
||
|
|
else el.value = newValue;
|
||
|
|
},
|
||
|
|
beforeUpdate(el, { value, oldValue, modifiers: { lazy, trim, number } }, vnode) {
|
||
|
|
el[assignKey] = getModelAssigner(vnode);
|
||
|
|
vModelTextUpdate(el, oldValue, value, trim, number, lazy);
|
||
|
|
}
|
||
|
|
};
|
||
|
|
function castValue(value, trim, number) {
|
||
|
|
if (trim) value = value.trim();
|
||
|
|
if (number) value = looseToNumber(value);
|
||
|
|
return value;
|
||
|
|
}
|
||
|
|
/**
|
||
|
|
* @internal
|
||
|
|
*/
|
||
|
|
const vModelTextInit = (el, trim, number, lazy, set) => {
|
||
|
|
addEventListener(el, lazy ? "change" : "input", (e) => {
|
||
|
|
if (e.target.composing) return;
|
||
|
|
(set || el[assignKey])(castValue(el.value, trim, number || el.type === "number"));
|
||
|
|
});
|
||
|
|
if (trim || number) addEventListener(el, "change", () => {
|
||
|
|
el.value = castValue(el.value, trim, number || el.type === "number");
|
||
|
|
});
|
||
|
|
if (!lazy) {
|
||
|
|
addEventListener(el, "compositionstart", onCompositionStart);
|
||
|
|
addEventListener(el, "compositionend", onCompositionEnd);
|
||
|
|
addEventListener(el, "change", onCompositionEnd);
|
||
|
|
}
|
||
|
|
};
|
||
|
|
/**
|
||
|
|
* @internal
|
||
|
|
*/
|
||
|
|
const vModelTextUpdate = (el, oldValue, value, trim, number, lazy) => {
|
||
|
|
if (el.composing) return;
|
||
|
|
const elValue = (number || el.type === "number") && !/^0\d/.test(el.value) ? looseToNumber(el.value) : el.value;
|
||
|
|
const newValue = value == null ? "" : value;
|
||
|
|
if (elValue === newValue) return;
|
||
|
|
const rootNode = el.getRootNode();
|
||
|
|
if ((rootNode instanceof Document || rootNode instanceof ShadowRoot) && rootNode.activeElement === el && el.type !== "range") {
|
||
|
|
if (lazy && value === oldValue) return;
|
||
|
|
if (trim && el.value.trim() === newValue) return;
|
||
|
|
}
|
||
|
|
el.value = newValue;
|
||
|
|
};
|
||
|
|
const vModelCheckbox = {
|
||
|
|
deep: true,
|
||
|
|
created(el, _, vnode) {
|
||
|
|
el[assignKey] = getModelAssigner(vnode);
|
||
|
|
vModelCheckboxInit(el);
|
||
|
|
},
|
||
|
|
mounted(el, binding, vnode) {
|
||
|
|
vModelCheckboxUpdate(el, binding.oldValue, binding.value, vnode.props.value);
|
||
|
|
},
|
||
|
|
beforeUpdate(el, binding, vnode) {
|
||
|
|
el[assignKey] = getModelAssigner(vnode);
|
||
|
|
vModelCheckboxUpdate(el, binding.oldValue, binding.value, vnode.props.value);
|
||
|
|
}
|
||
|
|
};
|
||
|
|
/**
|
||
|
|
* @internal
|
||
|
|
*/
|
||
|
|
const vModelCheckboxInit = (el, set) => {
|
||
|
|
addEventListener(el, "change", () => {
|
||
|
|
const assign = set || el[assignKey];
|
||
|
|
const modelValue = el._modelValue;
|
||
|
|
const elementValue = getValue(el);
|
||
|
|
const checked = el.checked;
|
||
|
|
if (isArray(modelValue)) {
|
||
|
|
const index = looseIndexOf(modelValue, elementValue);
|
||
|
|
const found = index !== -1;
|
||
|
|
if (checked && !found) assign(modelValue.concat(elementValue));
|
||
|
|
else if (!checked && found) {
|
||
|
|
const filtered = [...modelValue];
|
||
|
|
filtered.splice(index, 1);
|
||
|
|
assign(filtered);
|
||
|
|
}
|
||
|
|
} else if (isSet(modelValue)) {
|
||
|
|
const cloned = new Set(modelValue);
|
||
|
|
if (checked) cloned.add(elementValue);
|
||
|
|
else cloned.delete(elementValue);
|
||
|
|
assign(cloned);
|
||
|
|
} else assign(getCheckboxValue(el, checked));
|
||
|
|
});
|
||
|
|
};
|
||
|
|
/**
|
||
|
|
* @internal
|
||
|
|
*/
|
||
|
|
const vModelCheckboxUpdate = (el, oldValue, value, rawValue = getValue(el)) => {
|
||
|
|
el._modelValue = value;
|
||
|
|
let checked;
|
||
|
|
if (isArray(value)) checked = looseIndexOf(value, rawValue) > -1;
|
||
|
|
else if (isSet(value)) checked = value.has(rawValue);
|
||
|
|
else {
|
||
|
|
if (value === oldValue) return;
|
||
|
|
checked = looseEqual(value, getCheckboxValue(el, true));
|
||
|
|
}
|
||
|
|
if (el.checked !== checked) el.checked = checked;
|
||
|
|
};
|
||
|
|
const vModelRadio = {
|
||
|
|
created(el, { value }, vnode) {
|
||
|
|
el.checked = looseEqual(value, vnode.props.value);
|
||
|
|
el[assignKey] = getModelAssigner(vnode);
|
||
|
|
addEventListener(el, "change", () => {
|
||
|
|
el[assignKey](getValue(el));
|
||
|
|
});
|
||
|
|
},
|
||
|
|
beforeUpdate(el, { value, oldValue }, vnode) {
|
||
|
|
el[assignKey] = getModelAssigner(vnode);
|
||
|
|
if (value !== oldValue) el.checked = looseEqual(value, vnode.props.value);
|
||
|
|
}
|
||
|
|
};
|
||
|
|
const vModelSelect = {
|
||
|
|
deep: true,
|
||
|
|
created(el, { value, modifiers: { number } }, vnode) {
|
||
|
|
vModelSelectInit(el, value, number);
|
||
|
|
el[assignKey] = getModelAssigner(vnode);
|
||
|
|
},
|
||
|
|
mounted(el, { value }) {
|
||
|
|
vModelSetSelected(el, value);
|
||
|
|
},
|
||
|
|
beforeUpdate(el, { value }, vnode) {
|
||
|
|
el._modelValue = value;
|
||
|
|
el[assignKey] = getModelAssigner(vnode);
|
||
|
|
},
|
||
|
|
updated(el, { value }) {
|
||
|
|
vModelSetSelected(el, value);
|
||
|
|
}
|
||
|
|
};
|
||
|
|
/**
|
||
|
|
* @internal
|
||
|
|
*/
|
||
|
|
const vModelSelectInit = (el, value, number, set) => {
|
||
|
|
el._modelValue = value;
|
||
|
|
addEventListener(el, "change", () => {
|
||
|
|
const selectedVal = Array.prototype.filter.call(el.options, (o) => o.selected).map((o) => number ? looseToNumber(getValue(o)) : getValue(o));
|
||
|
|
const multiple = el.multiple;
|
||
|
|
const assignedValue = multiple ? isSet(el._modelValue) ? new Set(selectedVal) : selectedVal : selectedVal[0];
|
||
|
|
const pending = el._pendingValue = [multiple, multiple ? isArray(assignedValue) ? selectedVal.slice() : selectedVal : assignedValue];
|
||
|
|
try {
|
||
|
|
(set || el[assignKey])(assignedValue);
|
||
|
|
} finally {
|
||
|
|
nextTick(() => {
|
||
|
|
if (el._pendingValue === pending) el._pendingValue = void 0;
|
||
|
|
});
|
||
|
|
}
|
||
|
|
});
|
||
|
|
};
|
||
|
|
function isSameSelectValue(value, assignedValue, multiple) {
|
||
|
|
if (!multiple) return looseEqual(value, assignedValue);
|
||
|
|
if (isArray(value)) return looseEqual(value, assignedValue);
|
||
|
|
if (isSet(value)) {
|
||
|
|
if (value.size !== assignedValue.length) return false;
|
||
|
|
for (const item of assignedValue) if (!value.has(item)) return false;
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
/**
|
||
|
|
* @internal
|
||
|
|
*/
|
||
|
|
const vModelSetSelected = (el, value) => {
|
||
|
|
el._modelValue = value;
|
||
|
|
const pending = el._pendingValue;
|
||
|
|
el._pendingValue = void 0;
|
||
|
|
if (pending && pending[0] === el.multiple && isSameSelectValue(value, pending[1], pending[0])) return;
|
||
|
|
setSelected(el, value);
|
||
|
|
};
|
||
|
|
function setSelected(el, value) {
|
||
|
|
const isMultiple = el.multiple;
|
||
|
|
const isArrayValue = isArray(value);
|
||
|
|
if (isMultiple && !isArrayValue && !isSet(value)) {
|
||
|
|
process.env.NODE_ENV !== "production" && warn(`<select multiple v-model> expects an Array or Set value for its binding, but got ${Object.prototype.toString.call(value).slice(8, -1)}.`);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
for (let i = 0, l = el.options.length; i < l; i++) {
|
||
|
|
const option = el.options[i];
|
||
|
|
const optionValue = getValue(option);
|
||
|
|
if (isMultiple) {
|
||
|
|
if (isArrayValue) {
|
||
|
|
const optionType = typeof optionValue;
|
||
|
|
if (optionType === "string" || optionType === "number") option.selected = value.some((v) => String(v) === String(optionValue));
|
||
|
|
else option.selected = looseIndexOf(value, optionValue) > -1;
|
||
|
|
} else option.selected = value.has(optionValue);
|
||
|
|
} else if (looseEqual(getValue(option), value)) {
|
||
|
|
if (el.selectedIndex !== i) el.selectedIndex = i;
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (!isMultiple && el.selectedIndex !== -1) el.selectedIndex = -1;
|
||
|
|
}
|
||
|
|
/**
|
||
|
|
* @internal retrieve raw value set via :value bindings
|
||
|
|
*/
|
||
|
|
function getValue(el) {
|
||
|
|
return "_value" in el ? el._value : el.value;
|
||
|
|
}
|
||
|
|
function getCheckboxValue(el, checked) {
|
||
|
|
const key = checked ? "_trueValue" : "_falseValue";
|
||
|
|
if (key in el) return el[key];
|
||
|
|
const attr = checked ? "true-value" : "false-value";
|
||
|
|
if (el.hasAttribute(attr)) return el.getAttribute(attr);
|
||
|
|
return checked;
|
||
|
|
}
|
||
|
|
const vModelDynamic = {
|
||
|
|
created(el, binding, vnode) {
|
||
|
|
callModelHook(el, binding, vnode, null, "created");
|
||
|
|
},
|
||
|
|
mounted(el, binding, vnode) {
|
||
|
|
callModelHook(el, binding, vnode, null, "mounted");
|
||
|
|
},
|
||
|
|
beforeUpdate(el, binding, vnode, prevVNode) {
|
||
|
|
callModelHook(el, binding, vnode, prevVNode, "beforeUpdate");
|
||
|
|
},
|
||
|
|
updated(el, binding, vnode, prevVNode) {
|
||
|
|
callModelHook(el, binding, vnode, prevVNode, "updated");
|
||
|
|
}
|
||
|
|
};
|
||
|
|
function resolveDynamicModel(tagName, type) {
|
||
|
|
switch (tagName) {
|
||
|
|
case "SELECT": return vModelSelect;
|
||
|
|
case "TEXTAREA": return vModelText;
|
||
|
|
default: switch (type) {
|
||
|
|
case "checkbox": return vModelCheckbox;
|
||
|
|
case "radio": return vModelRadio;
|
||
|
|
default: return vModelText;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
function callModelHook(el, binding, vnode, prevVNode, hook) {
|
||
|
|
const fn = resolveDynamicModel(el.tagName, vnode.props && vnode.props.type)[hook];
|
||
|
|
fn && fn(el, binding, vnode, prevVNode);
|
||
|
|
}
|
||
|
|
function initVModelForSSR() {
|
||
|
|
vModelText.getSSRProps = ({ value }) => ({ value });
|
||
|
|
vModelRadio.getSSRProps = ({ value }, vnode) => {
|
||
|
|
if (vnode.props && looseEqual(vnode.props.value, value)) return { checked: true };
|
||
|
|
};
|
||
|
|
vModelCheckbox.getSSRProps = ({ value }, vnode) => {
|
||
|
|
if (isArray(value)) {
|
||
|
|
if (vnode.props && looseIndexOf(value, vnode.props.value) > -1) return { checked: true };
|
||
|
|
} else if (isSet(value)) {
|
||
|
|
if (vnode.props && value.has(vnode.props.value)) return { checked: true };
|
||
|
|
} else if (value) return { checked: true };
|
||
|
|
};
|
||
|
|
vModelDynamic.getSSRProps = (binding, vnode) => {
|
||
|
|
if (typeof vnode.type !== "string") return;
|
||
|
|
const modelToUse = resolveDynamicModel(vnode.type.toUpperCase(), vnode.props && vnode.props.type);
|
||
|
|
if (modelToUse.getSSRProps) return modelToUse.getSSRProps(binding, vnode);
|
||
|
|
};
|
||
|
|
}
|
||
|
|
//#endregion
|
||
|
|
//#region packages/runtime-dom/src/directives/vOn.ts
|
||
|
|
const systemModifiers = [
|
||
|
|
"ctrl",
|
||
|
|
"shift",
|
||
|
|
"alt",
|
||
|
|
"meta"
|
||
|
|
];
|
||
|
|
const modifierGuards = {
|
||
|
|
stop: (e) => e.stopPropagation(),
|
||
|
|
prevent: (e) => e.preventDefault(),
|
||
|
|
self: (e) => e.target !== e.currentTarget,
|
||
|
|
ctrl: (e) => !e.ctrlKey,
|
||
|
|
shift: (e) => !e.shiftKey,
|
||
|
|
alt: (e) => !e.altKey,
|
||
|
|
meta: (e) => !e.metaKey,
|
||
|
|
left: (e) => "button" in e && e.button !== 0,
|
||
|
|
middle: (e) => "button" in e && e.button !== 1,
|
||
|
|
right: (e) => "button" in e && e.button !== 2,
|
||
|
|
exact: (e, modifiers) => systemModifiers.some((m) => e[`${m}Key`] && !modifiers.includes(m))
|
||
|
|
};
|
||
|
|
/**
|
||
|
|
* @private
|
||
|
|
*/
|
||
|
|
const withModifiers = (fn, modifiers) => {
|
||
|
|
if (!fn) return fn;
|
||
|
|
const cache = fn._withMods || (fn._withMods = {});
|
||
|
|
const cacheKey = modifiers.join(".");
|
||
|
|
return cache[cacheKey] || (cache[cacheKey] = ((event, ...args) => {
|
||
|
|
for (let i = 0; i < modifiers.length; i++) {
|
||
|
|
const guard = modifierGuards[modifiers[i]];
|
||
|
|
if (guard && guard(event, modifiers)) return;
|
||
|
|
}
|
||
|
|
return fn(event, ...args);
|
||
|
|
}));
|
||
|
|
};
|
||
|
|
const keyNames = {
|
||
|
|
esc: "escape",
|
||
|
|
space: " ",
|
||
|
|
up: "arrow-up",
|
||
|
|
left: "arrow-left",
|
||
|
|
right: "arrow-right",
|
||
|
|
down: "arrow-down",
|
||
|
|
delete: "backspace"
|
||
|
|
};
|
||
|
|
/**
|
||
|
|
* @private
|
||
|
|
*/
|
||
|
|
const withKeys = (fn, modifiers) => {
|
||
|
|
const cache = fn._withKeys || (fn._withKeys = {});
|
||
|
|
const cacheKey = modifiers.join(".");
|
||
|
|
return cache[cacheKey] || (cache[cacheKey] = ((event) => {
|
||
|
|
if (!("key" in event)) return;
|
||
|
|
const eventKey = hyphenate(event.key);
|
||
|
|
if (modifiers.some((k) => k === eventKey || keyNames[k] === eventKey)) return fn(event);
|
||
|
|
}));
|
||
|
|
};
|
||
|
|
//#endregion
|
||
|
|
//#region packages/runtime-dom/src/index.ts
|
||
|
|
const rendererOptions = /*@__PURE__*/ extend({ patchProp }, nodeOps);
|
||
|
|
let renderer;
|
||
|
|
let enabledHydration = false;
|
||
|
|
function ensureRenderer() {
|
||
|
|
return renderer || (renderer = createRenderer(rendererOptions));
|
||
|
|
}
|
||
|
|
function ensureHydrationRenderer() {
|
||
|
|
renderer = enabledHydration ? renderer : createHydrationRenderer(rendererOptions);
|
||
|
|
enabledHydration = true;
|
||
|
|
return renderer;
|
||
|
|
}
|
||
|
|
const render = ((...args) => {
|
||
|
|
ensureRenderer().render(...args);
|
||
|
|
});
|
||
|
|
const hydrate = ((...args) => {
|
||
|
|
ensureHydrationRenderer().hydrate(...args);
|
||
|
|
});
|
||
|
|
const createApp = ((...args) => {
|
||
|
|
const app = ensureRenderer().createApp(...args);
|
||
|
|
if (!!(process.env.NODE_ENV !== "production")) {
|
||
|
|
injectNativeTagCheck(app);
|
||
|
|
injectCompilerOptionsCheck(app);
|
||
|
|
}
|
||
|
|
const { mount } = app;
|
||
|
|
app.mount = (containerOrSelector) => {
|
||
|
|
const container = normalizeContainer(containerOrSelector);
|
||
|
|
if (!container) return;
|
||
|
|
const component = app._component;
|
||
|
|
if (!isFunction(component) && !component.render && !component.template) component.template = container.innerHTML;
|
||
|
|
if (container.nodeType === 1) container.textContent = "";
|
||
|
|
const proxy = mount(container, false, resolveRootNamespace(container));
|
||
|
|
if (container instanceof Element) {
|
||
|
|
container.removeAttribute("v-cloak");
|
||
|
|
container.setAttribute("data-v-app", "");
|
||
|
|
}
|
||
|
|
return proxy;
|
||
|
|
};
|
||
|
|
return app;
|
||
|
|
});
|
||
|
|
const createSSRApp = ((...args) => {
|
||
|
|
setIsHydratingEnabled(true);
|
||
|
|
const app = ensureHydrationRenderer().createApp(...args);
|
||
|
|
if (!!(process.env.NODE_ENV !== "production")) {
|
||
|
|
injectNativeTagCheck(app);
|
||
|
|
injectCompilerOptionsCheck(app);
|
||
|
|
}
|
||
|
|
const { mount } = app;
|
||
|
|
app.mount = (containerOrSelector) => {
|
||
|
|
const container = normalizeContainer(containerOrSelector);
|
||
|
|
if (container) return mount(container, true, resolveRootNamespace(container));
|
||
|
|
};
|
||
|
|
return app;
|
||
|
|
});
|
||
|
|
function resolveRootNamespace(container) {
|
||
|
|
if (container instanceof SVGElement) return "svg";
|
||
|
|
if (typeof MathMLElement === "function" && container instanceof MathMLElement) return "mathml";
|
||
|
|
}
|
||
|
|
function injectNativeTagCheck(app) {
|
||
|
|
Object.defineProperty(app.config, "isNativeTag", {
|
||
|
|
value: (tag) => isHTMLTag(tag) || isSVGTag(tag) || isMathMLTag(tag),
|
||
|
|
writable: false
|
||
|
|
});
|
||
|
|
}
|
||
|
|
function injectCompilerOptionsCheck(app) {
|
||
|
|
if (isRuntimeOnly()) {
|
||
|
|
const isCustomElement = app.config.isCustomElement;
|
||
|
|
Object.defineProperty(app.config, "isCustomElement", {
|
||
|
|
get() {
|
||
|
|
return isCustomElement;
|
||
|
|
},
|
||
|
|
set() {
|
||
|
|
warn("The `isCustomElement` config option is deprecated. Use `compilerOptions.isCustomElement` instead.");
|
||
|
|
}
|
||
|
|
});
|
||
|
|
const compilerOptions = app.config.compilerOptions;
|
||
|
|
const msg = "The `compilerOptions` config option is only respected when using a build of Vue.js that includes the runtime compiler (aka \"full build\"). Since you are using the runtime-only build, `compilerOptions` must be passed to `@vue/compiler-dom` in the build setup instead.\n- For vue-loader: pass it via vue-loader's `compilerOptions` loader option.\n- For vue-cli: see https://cli.vuejs.org/guide/webpack.html#modifying-options-of-a-loader\n- For vite: pass it via @vitejs/plugin-vue options. See https://github.com/vitejs/vite-plugin-vue/tree/main/packages/plugin-vue#example-for-passing-options-to-vuecompiler-sfc";
|
||
|
|
Object.defineProperty(app.config, "compilerOptions", {
|
||
|
|
get() {
|
||
|
|
warn(msg);
|
||
|
|
return compilerOptions;
|
||
|
|
},
|
||
|
|
set() {
|
||
|
|
warn(msg);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
}
|
||
|
|
/**
|
||
|
|
* @internal
|
||
|
|
*/
|
||
|
|
function normalizeContainer(container) {
|
||
|
|
if (isString(container)) {
|
||
|
|
const res = document.querySelector(container);
|
||
|
|
if (!!(process.env.NODE_ENV !== "production") && !res) warn(`Failed to mount app: mount target selector "${container}" returned null.`);
|
||
|
|
return res;
|
||
|
|
}
|
||
|
|
if (!!(process.env.NODE_ENV !== "production") && window.ShadowRoot && container instanceof window.ShadowRoot && container.mode === "closed") warn(`mounting on a ShadowRoot with \`{mode: "closed"}\` may lead to unpredictable bugs`);
|
||
|
|
return container;
|
||
|
|
}
|
||
|
|
let ssrDirectiveInitialized = false;
|
||
|
|
/**
|
||
|
|
* @internal
|
||
|
|
*/
|
||
|
|
const initDirectivesForSSR = () => {
|
||
|
|
if (!ssrDirectiveInitialized) {
|
||
|
|
ssrDirectiveInitialized = true;
|
||
|
|
initVModelForSSR();
|
||
|
|
initVShowForSSR();
|
||
|
|
}
|
||
|
|
};
|
||
|
|
//#endregion
|
||
|
|
export { Transition, TransitionGroup, TransitionPropsValidators, VueElement, VueElementBase, baseApplyTranslation, callPendingCbs, createApp, createSSRApp, defineCustomElement, defineSSRCustomElement, ensureHydrationRenderer, ensureRenderer, forceReflow, handleMovedChildren, hasCSSTransform, hydrate, initDirectivesForSSR, nodeOps, normalizeContainer, parseEventName, patchClass, patchProp, patchStyle, render, resolveTransitionProps, setVarsOnNode, shouldSetAsProp, shouldSetAsPropForVueCE, svgNS, unsafeToTrustedHTML, useCssModule, useCssVars, useHost, useShadowRoot, vModelCheckbox, vModelCheckboxInit, vModelCheckboxUpdate, vModelDynamic, getValue as vModelGetValue, vModelRadio, vModelSelect, vModelSelectInit, vModelSetSelected, vModelText, vModelTextInit, vModelTextUpdate, vShow, vShowHidden, vShowOriginalDisplay, withKeys, withModifiers, xlinkNS };
|