shared.d.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. /**
  2. * Make a map and return a function for checking if a key
  3. * is in that map.
  4. * IMPORTANT: all calls of this function must be prefixed with
  5. * \/\*#\_\_PURE\_\_\*\/
  6. * So that rollup can tree-shake them if necessary.
  7. */
  8. /*! #__NO_SIDE_EFFECTS__ */
  9. export declare function makeMap(str: string): (key: string) => boolean;
  10. export declare const EMPTY_OBJ: {
  11. readonly [key: string]: any;
  12. };
  13. export declare const EMPTY_ARR: readonly never[];
  14. export declare const NOOP: () => void;
  15. /**
  16. * Always return false.
  17. */
  18. export declare const NO: () => boolean;
  19. export declare const isOn: (key: string) => boolean;
  20. export declare const isModelListener: (key: string) => key is `onUpdate:${string}`;
  21. export declare const extend: typeof Object.assign;
  22. export declare const remove: <T>(arr: T[], el: T) => void;
  23. export declare const hasOwn: (val: object, key: string | symbol) => key is keyof typeof val;
  24. export declare const isArray: typeof Array.isArray;
  25. export declare const isMap: (val: unknown) => val is Map<any, any>;
  26. export declare const isSet: (val: unknown) => val is Set<any>;
  27. export declare const isDate: (val: unknown) => val is Date;
  28. export declare const isRegExp: (val: unknown) => val is RegExp;
  29. export declare const isFunction: (val: unknown) => val is Function;
  30. export declare const isString: (val: unknown) => val is string;
  31. export declare const isSymbol: (val: unknown) => val is symbol;
  32. export declare const isObject: (val: unknown) => val is Record<any, any>;
  33. export declare const isPromise: <T = any>(val: unknown) => val is Promise<T>;
  34. export declare const objectToString: typeof Object.prototype.toString;
  35. export declare const toTypeString: (value: unknown) => string;
  36. export declare const toRawType: (value: unknown) => string;
  37. export declare const isPlainObject: (val: unknown) => val is object;
  38. export declare const isIntegerKey: (key: unknown) => boolean;
  39. export declare const isReservedProp: (key: string) => boolean;
  40. export declare const isBuiltInDirective: (key: string) => boolean;
  41. /**
  42. * @private
  43. */
  44. export declare const camelize: (str: string) => string;
  45. /**
  46. * @private
  47. */
  48. export declare const hyphenate: (str: string) => string;
  49. /**
  50. * @private
  51. */
  52. export declare const capitalize: <T extends string>(str: T) => Capitalize<T>;
  53. /**
  54. * @private
  55. */
  56. export declare const toHandlerKey: <T extends string>(str: T) => T extends '' ? '' : `on${Capitalize<T>}`;
  57. export declare const hasChanged: (value: any, oldValue: any) => boolean;
  58. export declare const invokeArrayFns: (fns: Function[], ...arg: any[]) => void;
  59. export declare const def: (obj: object, key: string | symbol, value: any, writable?: boolean) => void;
  60. /**
  61. * "123-foo" will be parsed to 123
  62. * This is used for the .number modifier in v-model
  63. */
  64. export declare const looseToNumber: (val: any) => any;
  65. /**
  66. * Only concerns number-like strings
  67. * "123-foo" will be returned as-is
  68. */
  69. export declare const toNumber: (val: any) => any;
  70. export declare const getGlobalThis: () => any;
  71. export declare function genPropsAccessExp(name: string): string;
  72. export declare function genCacheKey(source: string, options: any): string;
  73. /**
  74. * Patch flags are optimization hints generated by the compiler.
  75. * when a block with dynamicChildren is encountered during diff, the algorithm
  76. * enters "optimized mode". In this mode, we know that the vdom is produced by
  77. * a render function generated by the compiler, so the algorithm only needs to
  78. * handle updates explicitly marked by these patch flags.
  79. *
  80. * Patch flags can be combined using the | bitwise operator and can be checked
  81. * using the & operator, e.g.
  82. *
  83. * ```js
  84. * const flag = TEXT | CLASS
  85. * if (flag & TEXT) { ... }
  86. * ```
  87. *
  88. * Check the `patchElement` function in '../../runtime-core/src/renderer.ts' to see how the
  89. * flags are handled during diff.
  90. */
  91. export declare enum PatchFlags {
  92. /**
  93. * Indicates an element with dynamic textContent (children fast path)
  94. */
  95. TEXT = 1,
  96. /**
  97. * Indicates an element with dynamic class binding.
  98. */
  99. CLASS = 2,
  100. /**
  101. * Indicates an element with dynamic style
  102. * The compiler pre-compiles static string styles into static objects
  103. * + detects and hoists inline static objects
  104. * e.g. `style="color: red"` and `:style="{ color: 'red' }"` both get hoisted
  105. * as:
  106. * ```js
  107. * const style = { color: 'red' }
  108. * render() { return e('div', { style }) }
  109. * ```
  110. */
  111. STYLE = 4,
  112. /**
  113. * Indicates an element that has non-class/style dynamic props.
  114. * Can also be on a component that has any dynamic props (includes
  115. * class/style). when this flag is present, the vnode also has a dynamicProps
  116. * array that contains the keys of the props that may change so the runtime
  117. * can diff them faster (without having to worry about removed props)
  118. */
  119. PROPS = 8,
  120. /**
  121. * Indicates an element with props with dynamic keys. When keys change, a full
  122. * diff is always needed to remove the old key. This flag is mutually
  123. * exclusive with CLASS, STYLE and PROPS.
  124. */
  125. FULL_PROPS = 16,
  126. /**
  127. * Indicates an element that requires props hydration
  128. * (but not necessarily patching)
  129. * e.g. event listeners & v-bind with prop modifier
  130. */
  131. NEED_HYDRATION = 32,
  132. /**
  133. * Indicates a fragment whose children order doesn't change.
  134. */
  135. STABLE_FRAGMENT = 64,
  136. /**
  137. * Indicates a fragment with keyed or partially keyed children
  138. */
  139. KEYED_FRAGMENT = 128,
  140. /**
  141. * Indicates a fragment with unkeyed children.
  142. */
  143. UNKEYED_FRAGMENT = 256,
  144. /**
  145. * Indicates an element that only needs non-props patching, e.g. ref or
  146. * directives (onVnodeXXX hooks). since every patched vnode checks for refs
  147. * and onVnodeXXX hooks, it simply marks the vnode so that a parent block
  148. * will track it.
  149. */
  150. NEED_PATCH = 512,
  151. /**
  152. * Indicates a component with dynamic slots (e.g. slot that references a v-for
  153. * iterated value, or dynamic slot names).
  154. * Components with this flag are always force updated.
  155. */
  156. DYNAMIC_SLOTS = 1024,
  157. /**
  158. * Indicates a fragment that was created only because the user has placed
  159. * comments at the root level of a template. This is a dev-only flag since
  160. * comments are stripped in production.
  161. */
  162. DEV_ROOT_FRAGMENT = 2048,
  163. /**
  164. * SPECIAL FLAGS -------------------------------------------------------------
  165. * Special flags are negative integers. They are never matched against using
  166. * bitwise operators (bitwise matching should only happen in branches where
  167. * patchFlag > 0), and are mutually exclusive. When checking for a special
  168. * flag, simply check patchFlag === FLAG.
  169. */
  170. /**
  171. * Indicates a cached static vnode. This is also a hint for hydration to skip
  172. * the entire sub tree since static content never needs to be updated.
  173. */
  174. CACHED = -1,
  175. /**
  176. * A special flag that indicates that the diffing algorithm should bail out
  177. * of optimized mode. For example, on block fragments created by renderSlot()
  178. * when encountering non-compiler generated slots (i.e. manually written
  179. * render functions, which should always be fully diffed)
  180. * OR manually cloneVNodes
  181. */
  182. BAIL = -2
  183. }
  184. /**
  185. * dev only flag -> name mapping
  186. */
  187. export declare const PatchFlagNames: Record<PatchFlags, string>;
  188. export declare enum ShapeFlags {
  189. ELEMENT = 1,
  190. FUNCTIONAL_COMPONENT = 2,
  191. STATEFUL_COMPONENT = 4,
  192. TEXT_CHILDREN = 8,
  193. ARRAY_CHILDREN = 16,
  194. SLOTS_CHILDREN = 32,
  195. TELEPORT = 64,
  196. SUSPENSE = 128,
  197. COMPONENT_SHOULD_KEEP_ALIVE = 256,
  198. COMPONENT_KEPT_ALIVE = 512,
  199. COMPONENT = 6
  200. }
  201. export declare enum SlotFlags {
  202. /**
  203. * Stable slots that only reference slot props or context state. The slot
  204. * can fully capture its own dependencies so when passed down the parent won't
  205. * need to force the child to update.
  206. */
  207. STABLE = 1,
  208. /**
  209. * Slots that reference scope variables (v-for or an outer slot prop), or
  210. * has conditional structure (v-if, v-for). The parent will need to force
  211. * the child to update because the slot does not fully capture its dependencies.
  212. */
  213. DYNAMIC = 2,
  214. /**
  215. * `<slot/>` being forwarded into a child component. Whether the parent needs
  216. * to update the child is dependent on what kind of slots the parent itself
  217. * received. This has to be refined at runtime, when the child's vnode
  218. * is being created (in `normalizeChildren`)
  219. */
  220. FORWARDED = 3
  221. }
  222. /**
  223. * Dev only
  224. */
  225. export declare const slotFlagsText: Record<SlotFlags, string>;
  226. export declare const isGloballyAllowed: (key: string) => boolean;
  227. /** @deprecated use `isGloballyAllowed` instead */
  228. export declare const isGloballyWhitelisted: (key: string) => boolean;
  229. export declare function generateCodeFrame(source: string, start?: number, end?: number): string;
  230. export type NormalizedStyle = Record<string, string | number>;
  231. export declare function normalizeStyle(value: unknown): NormalizedStyle | string | undefined;
  232. export declare function parseStringStyle(cssText: string): NormalizedStyle;
  233. export declare function stringifyStyle(styles: NormalizedStyle | string | undefined): string;
  234. export declare function normalizeClass(value: unknown): string;
  235. export declare function normalizeProps(props: Record<string, any> | null): Record<string, any> | null;
  236. /**
  237. * Compiler only.
  238. * Do NOT use in runtime code paths unless behind `__DEV__` flag.
  239. */
  240. export declare const isHTMLTag: (key: string) => boolean;
  241. /**
  242. * Compiler only.
  243. * Do NOT use in runtime code paths unless behind `__DEV__` flag.
  244. */
  245. export declare const isSVGTag: (key: string) => boolean;
  246. /**
  247. * Compiler only.
  248. * Do NOT use in runtime code paths unless behind `__DEV__` flag.
  249. */
  250. export declare const isMathMLTag: (key: string) => boolean;
  251. /**
  252. * Compiler only.
  253. * Do NOT use in runtime code paths unless behind `__DEV__` flag.
  254. */
  255. export declare const isVoidTag: (key: string) => boolean;
  256. export declare const isSpecialBooleanAttr: (key: string) => boolean;
  257. /**
  258. * The full list is needed during SSR to produce the correct initial markup.
  259. */
  260. export declare const isBooleanAttr: (key: string) => boolean;
  261. /**
  262. * Boolean attributes should be included if the value is truthy or ''.
  263. * e.g. `<select multiple>` compiles to `{ multiple: '' }`
  264. */
  265. export declare function includeBooleanAttr(value: unknown): boolean;
  266. export declare function isSSRSafeAttrName(name: string): boolean;
  267. export declare const propsToAttrMap: Record<string, string | undefined>;
  268. /**
  269. * Known attributes, this is used for stringification of runtime static nodes
  270. * so that we don't stringify bindings that cannot be set from HTML.
  271. * Don't also forget to allow `data-*` and `aria-*`!
  272. * Generated from https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes
  273. */
  274. export declare const isKnownHtmlAttr: (key: string) => boolean;
  275. /**
  276. * Generated from https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute
  277. */
  278. export declare const isKnownSvgAttr: (key: string) => boolean;
  279. /**
  280. * Generated from https://developer.mozilla.org/en-US/docs/Web/MathML/Attribute
  281. */
  282. export declare const isKnownMathMLAttr: (key: string) => boolean;
  283. /**
  284. * Shared between server-renderer and runtime-core hydration logic
  285. */
  286. export declare function isRenderableAttrValue(value: unknown): boolean;
  287. export declare function escapeHtml(string: unknown): string;
  288. export declare function escapeHtmlComment(src: string): string;
  289. export declare const cssVarNameEscapeSymbolsRE: RegExp;
  290. export declare function getEscapedCssVarName(key: string, doubleEscape: boolean): string;
  291. export declare function looseEqual(a: any, b: any): boolean;
  292. export declare function looseIndexOf(arr: any[], val: any): number;
  293. /**
  294. * For converting {{ interpolation }} values to displayed strings.
  295. * @private
  296. */
  297. export declare const toDisplayString: (val: unknown) => string;
  298. export type Prettify<T> = {
  299. [K in keyof T]: T[K];
  300. } & {};
  301. export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
  302. export type LooseRequired<T> = {
  303. [P in keyof (T & Required<T>)]: T[P];
  304. };
  305. export type IfAny<T, Y, N> = 0 extends 1 & T ? Y : N;
  306. export type IsKeyValues<T, K = string> = IfAny<T, false, T extends object ? (keyof T extends K ? true : false) : false>;
  307. /**
  308. * Utility for extracting the parameters from a function overload (for typed emits)
  309. * https://github.com/microsoft/TypeScript/issues/32164#issuecomment-1146737709
  310. */
  311. export type OverloadParameters<T extends (...args: any[]) => any> = Parameters<OverloadUnion<T>>;
  312. type OverloadProps<TOverload> = Pick<TOverload, keyof TOverload>;
  313. type OverloadUnionRecursive<TOverload, TPartialOverload = unknown> = TOverload extends (...args: infer TArgs) => infer TReturn ? TPartialOverload extends TOverload ? never : OverloadUnionRecursive<TPartialOverload & TOverload, TPartialOverload & ((...args: TArgs) => TReturn) & OverloadProps<TOverload>> | ((...args: TArgs) => TReturn) : never;
  314. type OverloadUnion<TOverload extends (...args: any[]) => any> = Exclude<OverloadUnionRecursive<(() => never) & TOverload>, TOverload extends () => never ? never : () => never>;