db0d44913b6a09939667117d514ca6d6035daba62b64faf41f03448c2207de20ceb96ba7c5a4daaddfddf53b9fcb29a5b78925630733beb57bfd50a07ce7a6 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. import './vue'
  2. import Vue, { ComponentOptions, PluginFunction } from 'vue'
  3. type Component = ComponentOptions<Vue> | typeof Vue
  4. type CallbackFn = () => void
  5. type elements = HTMLElement[]
  6. export interface VueMetaOptionsRuntime {
  7. refreshOnceOnNavigation?: boolean
  8. debounceWait?: number
  9. waitOnDestroyed?: boolean
  10. }
  11. export interface VueMetaOptions extends VueMetaOptionsRuntime {
  12. keyName: string, // the component option name that vue-meta looks for meta info on.
  13. attribute: string, // the attribute name vue-meta adds to the tags it observes
  14. ssrAppId: string, // the app id used for ssr app
  15. ssrAttribute: string, // the attribute name that lets vue-meta know that meta info has already been server-rendered
  16. tagIDKeyName: string // the property name that vue-meta uses to determine whether to overwrite or append a tag
  17. }
  18. export declare class VueMeta {
  19. static version: string
  20. static install(vue: typeof Vue, options?: VueMetaOptions): PluginFunction<never>
  21. static hasMetaInfo(vm: Component): boolean
  22. static generate(metaInfo: MetaInfo, options?: Object): MetaInfoSSR
  23. }
  24. interface RefreshedTags {
  25. addedTags: elements
  26. removedTags: elements
  27. }
  28. interface Refreshed {
  29. vm: Component,
  30. metaInfo: MetaInfoOutput,
  31. tags: RefreshedTags
  32. }
  33. interface VueMetaApp {
  34. set(metaInfo: MetaInfo): void | RefreshedTags
  35. remove(): void
  36. }
  37. export interface VueMetaPlugin {
  38. getOptions(): VueMetaOptions
  39. setOptions(runtimeOptions: VueMetaOptionsRuntime): VueMetaOptions
  40. addApp(appName: string): VueMetaApp
  41. refresh(): Refreshed
  42. inject(): MetaInfoSSR
  43. pause(refresh: true): () => Refreshed
  44. pause(refresh?: boolean): () => void
  45. resume(refresh: true): Refreshed
  46. resume(refresh?: boolean): void
  47. }
  48. export interface AttributeProperty {
  49. [key: string]: string | string[]
  50. }
  51. export interface MetaDataProperty {
  52. vmid?: string,
  53. once?: boolean,
  54. skip?: boolean,
  55. body?: boolean,
  56. pbody?: boolean,
  57. [key: string]: any
  58. }
  59. export interface MetaPropertyCharset extends MetaDataProperty {
  60. charset: string,
  61. }
  62. export interface MetaPropertyEquiv extends MetaDataProperty {
  63. httpEquiv: string,
  64. content: string,
  65. template?: (chunk: string) => string
  66. }
  67. export interface MetaPropertyName extends MetaDataProperty {
  68. name: string,
  69. content: string,
  70. template?: (chunk: string) => string
  71. }
  72. export interface MetaPropertyMicrodata extends MetaDataProperty {
  73. itemprop: string,
  74. content: string,
  75. template?: (chunk: string) => string
  76. }
  77. // non-w3c interface
  78. export interface MetaPropertyProperty extends MetaDataProperty {
  79. property: string,
  80. content: string,
  81. template?: (chunk: string) => string
  82. }
  83. export interface LinkPropertyBase extends MetaDataProperty {
  84. rel: string,
  85. crossOrigin?: string | null,
  86. media?: string,
  87. nonce?: string,
  88. referrerPolicy?: string,
  89. rev?: string,
  90. type?: string
  91. }
  92. export interface LinkPropertyHref extends LinkPropertyBase {
  93. href?: string,
  94. hreflang?: string,
  95. callback?: void
  96. }
  97. export interface LinkPropertyHrefCallback extends LinkPropertyBase {
  98. vmid: string,
  99. callback: CallbackFn,
  100. href?: string,
  101. hreflang?: string
  102. }
  103. export interface StyleProperty extends MetaDataProperty {
  104. cssText: string,
  105. callback?: CallbackFn
  106. media?: string,
  107. nonce?: string,
  108. type?: string,
  109. }
  110. export interface ScriptPropertyBase extends MetaDataProperty {
  111. type?: string,
  112. charset?: string,
  113. async?: boolean,
  114. defer?: boolean,
  115. crossOrigin?: string,
  116. nonce?: string
  117. }
  118. export interface ScriptPropertyText extends ScriptPropertyBase {
  119. innerHTML: string
  120. }
  121. export interface ScriptPropertySrc extends ScriptPropertyBase {
  122. src: string,
  123. callback?: void
  124. }
  125. export interface ScriptPropertySrcCallback extends ScriptPropertyBase {
  126. vmid: string,
  127. callback: CallbackFn
  128. }
  129. type JsonVal = string | number | boolean | JsonObj | JsonObj[] | null
  130. interface JsonObj {
  131. [key: string]: JsonVal | JsonVal[]
  132. }
  133. export interface ScriptPropertyJson extends ScriptPropertyBase {
  134. json: JsonObj
  135. }
  136. export interface NoScriptProperty extends MetaDataProperty {
  137. innerHTML: string,
  138. }
  139. export interface MetaInfo {
  140. title?: string
  141. titleTemplate?: string | ((titleChunk: string) => string),
  142. htmlAttrs?: AttributeProperty
  143. headAttrs?: AttributeProperty
  144. bodyAttrs?: AttributeProperty
  145. base?: {
  146. target: string,
  147. href: string
  148. }
  149. meta?: (MetaPropertyCharset | MetaPropertyEquiv | MetaPropertyName | MetaPropertyMicrodata | MetaPropertyProperty)[]
  150. link?: (LinkPropertyBase | LinkPropertyHref | LinkPropertyHrefCallback)[]
  151. style?: StyleProperty[]
  152. script?: (ScriptPropertyText | ScriptPropertySrc | ScriptPropertySrcCallback | ScriptPropertyJson)[]
  153. noscript?: NoScriptProperty[]
  154. __dangerouslyDisableSanitizers?: string[]
  155. __dangerouslyDisableSanitizersByTagID?: {
  156. [key: string]: string[]
  157. }
  158. changed?: <T extends MetaInfoOutput>(newInfo: T, addedTags: elements, removedTags: elements) => void
  159. afterNavigation?: <T extends MetaInfoOutput>(newInfo: T) => void
  160. }
  161. export interface MetaInfoOutput extends MetaInfo {
  162. titleChunk?: string
  163. }
  164. export type MetaInfoComputed = () => MetaInfo
  165. interface ToText {
  166. text(): string
  167. }
  168. interface ToTextBooleanArg {
  169. text(addSrrAttribute?: boolean): string
  170. }
  171. interface AddLineBreakOption {
  172. ln: boolean
  173. }
  174. interface ToBodyTextOption {
  175. body: boolean
  176. }
  177. interface ToPbodyTextOption {
  178. pbody: boolean
  179. }
  180. interface ToBodyText {
  181. text(options?: (ToBodyTextOption | ToPbodyTextOption | AddLineBreakOption)): string
  182. }
  183. export interface MetaInfoSSR {
  184. head(ln?: boolean): string
  185. bodyPrepend(ln?: boolean): string
  186. bodyAppend(ln?: boolean): string
  187. title?: ToText
  188. htmlAttrs?: ToTextBooleanArg
  189. headAttrs?: ToText
  190. bodyAttrs?: ToText
  191. base?: ToBodyText
  192. meta?: ToBodyText
  193. link?: ToBodyText
  194. style?: ToBodyText
  195. script?: ToBodyText
  196. noscript?: ToBodyText
  197. }