weex.d.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import { Component } from "./component";
  2. import { GlobalAPI } from "./global-api";
  3. // global flag to be compiled away
  4. declare const __WEEX__: boolean;
  5. // global object in Weex
  6. declare var WXEnvironment: WeexEnvironment;
  7. declare type Weex = {
  8. config: WeexConfigAPI;
  9. document: WeexDocument;
  10. requireModule: (name: string) => Object | void;
  11. supports: (condition: string) => boolean | void;
  12. isRegisteredModule: (name: string, method?: string) => boolean;
  13. isRegisteredComponent: (name: string) => boolean;
  14. };
  15. declare type WeexConfigAPI = {
  16. bundleUrl: string; // === weex.document.URL
  17. bundleType: string;
  18. env: WeexEnvironment; // === WXEnvironment
  19. };
  20. declare type WeexEnvironment = {
  21. platform: string; // could be "Web", "iOS", "Android"
  22. weexVersion: string; // the version of WeexSDK
  23. osName: string; // could be "iOS", "Android" or others
  24. osVersion: string;
  25. appName: string; // mobile app name or browser name
  26. appVersion: string;
  27. // information about current running device
  28. deviceModel: string; // phone device model
  29. deviceWidth: number;
  30. deviceHeight: number;
  31. scale: number;
  32. // only available on the web
  33. userAgent?: string;
  34. dpr?: number;
  35. rem?: number;
  36. };
  37. declare interface WeexDocument {
  38. id: string;
  39. URL: string;
  40. taskCenter: WeexTaskCenter;
  41. open: () => void;
  42. close: () => void;
  43. createElement: (tagName: string, props?: Object) => WeexElement;
  44. createComment: (text: string) => Object;
  45. fireEvent: (type: string) => void;
  46. destroy: () => void;
  47. }
  48. declare interface WeexTaskCenter {
  49. instanceId: string;
  50. callbackManager: Object;
  51. send: (type: string, params: Object, args: Array<any>, options?: Object) => void;
  52. registerHook: (componentId: string, type: string, hook: string, fn: Function) => void;
  53. updateData: (componentId: string, data: Object | void, callback?: Function) => void;
  54. }
  55. declare interface WeexElement {
  56. nodeType: number;
  57. nodeId: string;
  58. type: string;
  59. ref: string;
  60. text?: string;
  61. parentNode: WeexElement | void;
  62. children: Array<WeexElement>;
  63. previousSibling: WeexElement | void;
  64. nextSibling: WeexElement | void;
  65. appendChild: (node: WeexElement) => void;
  66. removeChild: (node: WeexElement, preserved?: boolean) => void;
  67. insertBefore: (node: WeexElement, before: WeexElement) => void;
  68. insertAfter: (node: WeexElement, after: WeexElement) => void;
  69. setAttr: (key: string, value: any, silent?: boolean) => void;
  70. setAttrs: (attrs: Object, silent?: boolean) => void;
  71. setStyle: (key: string, value: any, silent?: boolean) => void;
  72. setStyles: (attrs: Object, silent?: boolean) => void;
  73. addEvent: (type: string, handler: Function, args?: Array<any>) => void;
  74. removeEvent: (type: string) => void;
  75. fireEvent: (type: string) => void;
  76. destroy: () => void;
  77. }
  78. declare type WeexInstanceOption = {
  79. instanceId: string;
  80. config: WeexConfigAPI;
  81. document: WeexDocument;
  82. Vue?: GlobalAPI;
  83. app?: Component;
  84. data?: Object;
  85. };
  86. declare type WeexRuntimeContext = {
  87. weex: Weex;
  88. service: Object;
  89. BroadcastChannel?: Function;
  90. };
  91. declare type WeexInstanceContext = {
  92. Vue: GlobalAPI;
  93. // DEPRECATED
  94. setTimeout?: Function;
  95. clearTimeout?: Function;
  96. setInterval?: Function;
  97. clearInterval?: Function;
  98. };
  99. declare type WeexCompilerOptions = CompilerOptions & {
  100. // whether to compile special template for <recycle-list>
  101. recyclable?: boolean;
  102. };
  103. declare type WeexCompiledResult = CompiledResult & {
  104. '@render'?: string;
  105. };