weex.js 3.3 KB

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