dom.nim 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278
  1. #
  2. #
  3. # Nim's Runtime Library
  4. # (c) Copyright 2012 Andreas Rumpf
  5. #
  6. # See the file "copying.txt", included in this
  7. # distribution, for details about the copyright.
  8. #
  9. ## Declaration of the Document Object Model for the `JavaScript backend
  10. ## <backends.html#the-javascript-target>`_.
  11. when not defined(js) and not defined(Nimdoc):
  12. {.error: "This module only works on the JavaScript platform".}
  13. const
  14. DomApiVersion* = 3 ## the version of DOM API we try to follow. No guarantees though.
  15. type
  16. EventTarget* = ref EventTargetObj
  17. EventTargetObj {.importc.} = object of RootObj
  18. onabort*: proc (event: Event) {.nimcall.}
  19. onblur*: proc (event: Event) {.nimcall.}
  20. onchange*: proc (event: Event) {.nimcall.}
  21. onclick*: proc (event: Event) {.nimcall.}
  22. ondblclick*: proc (event: Event) {.nimcall.}
  23. onerror*: proc (event: Event) {.nimcall.}
  24. onfocus*: proc (event: Event) {.nimcall.}
  25. onkeydown*: proc (event: Event) {.nimcall.}
  26. onkeypress*: proc (event: Event) {.nimcall.}
  27. onkeyup*: proc (event: Event) {.nimcall.}
  28. onload*: proc (event: Event) {.nimcall.}
  29. onmousedown*: proc (event: Event) {.nimcall.}
  30. onmousemove*: proc (event: Event) {.nimcall.}
  31. onmouseout*: proc (event: Event) {.nimcall.}
  32. onmouseover*: proc (event: Event) {.nimcall.}
  33. onmouseup*: proc (event: Event) {.nimcall.}
  34. onreset*: proc (event: Event) {.nimcall.}
  35. onselect*: proc (event: Event) {.nimcall.}
  36. onsubmit*: proc (event: Event) {.nimcall.}
  37. onunload*: proc (event: Event) {.nimcall.}
  38. # https://developer.mozilla.org/en-US/docs/Web/Events
  39. DomEvent* {.pure.} = enum
  40. Abort = "abort",
  41. BeforeInput = "beforeinput",
  42. Blur = "blur",
  43. Click = "click",
  44. CompositionEnd = "compositionend",
  45. CompositionStart = "compositionstart",
  46. CompositionUpdate = "compositionupdate",
  47. DblClick = "dblclick",
  48. Error = "error",
  49. Focus = "focus",
  50. FocusIn = "focusin",
  51. FocusOut = "focusout",
  52. Input = "input",
  53. KeyDown = "keydown",
  54. KeyPress = "keypress",
  55. KeyUp = "keyup",
  56. Load = "load",
  57. MouseDown = "mousedown",
  58. MouseEnter = "mouseenter",
  59. MouseLeave = "mouseleave",
  60. MouseMove = "mousemove",
  61. MouseOut = "mouseout",
  62. MouseOver = "mouseover",
  63. MouseUp = "mouseup",
  64. Resize = "resize",
  65. Scroll = "scroll",
  66. Select = "select",
  67. Unload = "unload",
  68. Wheel = "wheel"
  69. PerformanceMemory* {.importc.} = ref object
  70. jsHeapSizeLimit*: float
  71. totalJSHeapSize*: float
  72. usedJSHeapSize*: float
  73. PerformanceTiming* {.importc.} = ref object
  74. connectStart*: float
  75. domComplete*: float
  76. domContentLoadedEventEnd*: float
  77. domContentLoadedEventStart*: float
  78. domInteractive*: float
  79. domLoading*: float
  80. domainLookupEnd*: float
  81. domainLookupStart*: float
  82. fetchStart*: float
  83. loadEventEnd*: float
  84. loadEventStart*: float
  85. navigationStart*: float
  86. redirectEnd*: float
  87. redirectStart*: float
  88. requestStart*: float
  89. responseEnd*: float
  90. responseStart*: float
  91. secureConnectionStart*: float
  92. unloadEventEnd*: float
  93. unloadEventStart*: float
  94. Performance* {.importc.} = ref object
  95. memory*: PerformanceMemory
  96. timing*: PerformanceTiming
  97. Window* = ref WindowObj
  98. WindowObj {.importc.} = object of EventTargetObj
  99. document*: Document
  100. event*: Event
  101. history*: History
  102. location*: Location
  103. closed*: bool
  104. defaultStatus*: cstring
  105. devicePixelRatio*: float
  106. innerHeight*, innerWidth*: int
  107. locationbar*: ref LocationBar
  108. menubar*: ref MenuBar
  109. name*: cstring
  110. outerHeight*, outerWidth*: int
  111. pageXOffset*, pageYOffset*: int
  112. scrollX*: float
  113. scrollY*: float
  114. personalbar*: ref PersonalBar
  115. scrollbars*: ref ScrollBars
  116. statusbar*: ref StatusBar
  117. status*: cstring
  118. toolbar*: ref ToolBar
  119. frames*: seq[Frame]
  120. screen*: Screen
  121. performance*: Performance
  122. onpopstate*: proc (event: Event)
  123. Frame* = ref FrameObj
  124. FrameObj {.importc.} = object of WindowObj
  125. ClassList* = ref ClassListObj
  126. ClassListObj {.importc.} = object of RootObj
  127. NodeType* = enum
  128. ElementNode = 1,
  129. AttributeNode,
  130. TextNode,
  131. CDATANode,
  132. EntityRefNode,
  133. EntityNode,
  134. ProcessingInstructionNode,
  135. CommentNode,
  136. DocumentNode,
  137. DocumentTypeNode,
  138. DocumentFragmentNode,
  139. NotationNode
  140. Node* = ref NodeObj
  141. NodeObj {.importc.} = object of EventTargetObj
  142. attributes*: seq[Node]
  143. childNodes*: seq[Node]
  144. children*: seq[Node]
  145. data*: cstring
  146. firstChild*: Node
  147. lastChild*: Node
  148. nextSibling*: Node
  149. nodeName*: cstring
  150. nodeType*: NodeType
  151. nodeValue*: cstring
  152. parentNode*: Node
  153. previousSibling*: Node
  154. innerHTML*: cstring
  155. style*: Style
  156. Document* = ref DocumentObj
  157. DocumentObj {.importc.} = object of NodeObj
  158. alinkColor*: cstring
  159. bgColor*: cstring
  160. body*: Element
  161. charset*: cstring
  162. cookie*: cstring
  163. defaultCharset*: cstring
  164. fgColor*: cstring
  165. head*: Element
  166. lastModified*: cstring
  167. linkColor*: cstring
  168. referrer*: cstring
  169. title*: cstring
  170. URL*: cstring
  171. vlinkColor*: cstring
  172. anchors*: seq[AnchorElement]
  173. forms*: seq[FormElement]
  174. images*: seq[ImageElement]
  175. applets*: seq[Element]
  176. embeds*: seq[EmbedElement]
  177. links*: seq[LinkElement]
  178. Element* = ref ElementObj
  179. ElementObj {.importc.} = object of NodeObj
  180. classList*: ClassList
  181. checked*: bool
  182. defaultChecked*: bool
  183. defaultValue*: cstring
  184. disabled*: bool
  185. form*: FormElement
  186. name*: cstring
  187. readOnly*: bool
  188. options*: seq[OptionElement]
  189. selectedOptions*: seq[OptionElement]
  190. clientWidth*, clientHeight*: int
  191. contentEditable*: cstring
  192. isContentEditable*: bool
  193. dir*: cstring
  194. offsetHeight*: int
  195. offsetWidth*: int
  196. offsetLeft*: int
  197. offsetTop*: int
  198. # https://developer.mozilla.org/en-US/docs/Web/API/ValidityState
  199. ValidityState* = ref ValidityStateObj
  200. ValidityStateObj {.importc.} = object
  201. badInput*: bool
  202. customError*: bool
  203. patternMismatch*: bool
  204. rangeOverflow*: bool
  205. rangeUnderflow*: bool
  206. stepMismatch*: bool
  207. tooLong*: bool
  208. tooShort*: bool
  209. typeMismatch*: bool
  210. valid*: bool
  211. valueMissing*: bool
  212. # https://developer.mozilla.org/en-US/docs/Web/API/Blob
  213. Blob* = ref BlobObj
  214. BlobObj {.importc.} = object of RootObj
  215. size*: int
  216. `type`*: cstring
  217. # https://developer.mozilla.org/en-US/docs/Web/API/File
  218. File* = ref FileObj
  219. FileObj {.importc.} = object of Blob
  220. lastModified*: int
  221. name*: cstring
  222. # https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement
  223. InputElement* = ref InputElementObj
  224. InputElementObj {.importc.} = object of Element
  225. # Properties related to the parent form
  226. formAction*: cstring
  227. formEncType*: cstring
  228. formMethod*: cstring
  229. formNoValidate*: bool
  230. formTarget*: cstring
  231. # Properties that apply to any type of input element that is not hidden
  232. `type`*: cstring
  233. autofocus*: bool
  234. required*: bool
  235. value*: cstring
  236. validity*: ValidityState
  237. validationMessage*: cstring
  238. willValidate*: bool
  239. # Properties that apply only to elements of type "checkbox" or "radio"
  240. indeterminate*: bool
  241. # Properties that apply only to elements of type "image"
  242. alt*: cstring
  243. height*: cstring
  244. src*: cstring
  245. width*: cstring
  246. # Properties that apply only to elements of type "file"
  247. accept*: cstring
  248. files*: seq[Blob]
  249. # Properties that apply only to text/number-containing or elements
  250. autocomplete*: cstring
  251. maxLength*: int
  252. size*: int
  253. pattern*: cstring
  254. placeholder*: cstring
  255. min*: cstring
  256. max*: cstring
  257. selectionStart*: int
  258. selectionEnd*: int
  259. selectionDirection*: cstring
  260. # Properties not yet categorized
  261. dirName*: cstring
  262. accessKey*: cstring
  263. list*: Element
  264. multiple*: bool
  265. labels*: seq[Element]
  266. step*: cstring
  267. valueAsDate*: cstring
  268. valueAsNumber*: float
  269. LinkElement* = ref LinkObj
  270. LinkObj {.importc.} = object of ElementObj
  271. target*: cstring
  272. text*: cstring
  273. x*: int
  274. y*: int
  275. EmbedElement* = ref EmbedObj
  276. EmbedObj {.importc.} = object of ElementObj
  277. height*: int
  278. hspace*: int
  279. src*: cstring
  280. width*: int
  281. `type`*: cstring
  282. vspace*: int
  283. AnchorElement* = ref AnchorObj
  284. AnchorObj {.importc.} = object of ElementObj
  285. text*: cstring
  286. x*, y*: int
  287. OptionElement* = ref OptionObj
  288. OptionObj {.importc.} = object of ElementObj
  289. defaultSelected*: bool
  290. selected*: bool
  291. selectedIndex*: int
  292. text*: cstring
  293. value*: cstring
  294. # https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement
  295. FormElement* = ref FormObj
  296. FormObj {.importc.} = object of ElementObj
  297. acceptCharset*: cstring
  298. action*: cstring
  299. autocomplete*: cstring
  300. elements*: seq[Element]
  301. encoding*: cstring
  302. enctype*: cstring
  303. length*: int
  304. `method`*: cstring
  305. noValidate*: bool
  306. target*: cstring
  307. ImageElement* = ref ImageObj
  308. ImageObj {.importc.} = object of ElementObj
  309. border*: int
  310. complete*: bool
  311. height*: int
  312. hspace*: int
  313. lowsrc*: cstring
  314. src*: cstring
  315. vspace*: int
  316. width*: int
  317. Style* = ref StyleObj
  318. StyleObj {.importc.} = object of RootObj
  319. background*: cstring
  320. backgroundAttachment*: cstring
  321. backgroundColor*: cstring
  322. backgroundImage*: cstring
  323. backgroundPosition*: cstring
  324. backgroundRepeat*: cstring
  325. border*: cstring
  326. borderBottom*: cstring
  327. borderBottomColor*: cstring
  328. borderBottomStyle*: cstring
  329. borderBottomWidth*: cstring
  330. borderColor*: cstring
  331. borderLeft*: cstring
  332. borderLeftColor*: cstring
  333. borderLeftStyle*: cstring
  334. borderLeftWidth*: cstring
  335. borderRight*: cstring
  336. borderRightColor*: cstring
  337. borderRightStyle*: cstring
  338. borderRightWidth*: cstring
  339. borderStyle*: cstring
  340. borderTop*: cstring
  341. borderTopColor*: cstring
  342. borderTopStyle*: cstring
  343. borderTopWidth*: cstring
  344. borderWidth*: cstring
  345. bottom*: cstring
  346. captionSide*: cstring
  347. clear*: cstring
  348. clip*: cstring
  349. color*: cstring
  350. cursor*: cstring
  351. direction*: cstring
  352. display*: cstring
  353. emptyCells*: cstring
  354. cssFloat*: cstring
  355. font*: cstring
  356. fontFamily*: cstring
  357. fontSize*: cstring
  358. fontStretch*: cstring
  359. fontStyle*: cstring
  360. fontVariant*: cstring
  361. fontWeight*: cstring
  362. height*: cstring
  363. left*: cstring
  364. letterSpacing*: cstring
  365. lineHeight*: cstring
  366. listStyle*: cstring
  367. listStyleImage*: cstring
  368. listStylePosition*: cstring
  369. listStyleType*: cstring
  370. margin*: cstring
  371. marginBottom*: cstring
  372. marginLeft*: cstring
  373. marginRight*: cstring
  374. marginTop*: cstring
  375. maxHeight*: cstring
  376. maxWidth*: cstring
  377. minHeight*: cstring
  378. minWidth*: cstring
  379. overflow*: cstring
  380. padding*: cstring
  381. paddingBottom*: cstring
  382. paddingLeft*: cstring
  383. paddingRight*: cstring
  384. paddingTop*: cstring
  385. pageBreakAfter*: cstring
  386. pageBreakBefore*: cstring
  387. pointerEvents*: cstring
  388. position*: cstring
  389. right*: cstring
  390. scrollbar3dLightColor*: cstring
  391. scrollbarArrowColor*: cstring
  392. scrollbarBaseColor*: cstring
  393. scrollbarDarkshadowColor*: cstring
  394. scrollbarFaceColor*: cstring
  395. scrollbarHighlightColor*: cstring
  396. scrollbarShadowColor*: cstring
  397. scrollbarTrackColor*: cstring
  398. tableLayout*: cstring
  399. textAlign*: cstring
  400. textDecoration*: cstring
  401. textIndent*: cstring
  402. textTransform*: cstring
  403. transform*: cstring
  404. top*: cstring
  405. verticalAlign*: cstring
  406. visibility*: cstring
  407. width*: cstring
  408. wordSpacing*: cstring
  409. zIndex*: int
  410. EventPhase* = enum
  411. None = 0,
  412. CapturingPhase,
  413. AtTarget,
  414. BubblingPhase
  415. # https://developer.mozilla.org/en-US/docs/Web/API/Event
  416. Event* = ref EventObj
  417. EventObj {.importc.} = object of RootObj
  418. bubbles*: bool
  419. cancelBubble*: bool
  420. cancelable*: bool
  421. composed*: bool
  422. currentTarget*: Node
  423. defaultPrevented*: bool
  424. eventPhase*: int
  425. target*: Node
  426. `type`*: cstring
  427. isTrusted*: bool
  428. # https://developer.mozilla.org/en-US/docs/Web/API/UIEvent
  429. UIEvent* = ref UIEventObj
  430. UIEventObj {.importc.} = object of Event
  431. detail*: int64
  432. view*: Window
  433. # https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent
  434. KeyboardEvent* = ref KeyboardEventObj
  435. KeyboardEventObj {.importc.} = object of UIEvent
  436. altKey*, ctrlKey*, metaKey*, shiftKey*: bool
  437. code*: cstring
  438. isComposing*: bool
  439. key*: cstring
  440. keyCode*: int
  441. location*: int
  442. # https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values
  443. KeyboardEventKey* {.pure.} = enum
  444. # Modifier keys
  445. Alt,
  446. AltGraph,
  447. CapsLock,
  448. Control,
  449. Fn,
  450. FnLock,
  451. Hyper,
  452. Meta,
  453. NumLock,
  454. ScrollLock,
  455. Shift,
  456. Super,
  457. Symbol,
  458. SymbolLock,
  459. # Whitespace keys
  460. ArrowDown,
  461. ArrowLeft,
  462. ArrowRight,
  463. ArrowUp,
  464. End,
  465. Home,
  466. PageDown,
  467. PageUp,
  468. # Editing keys
  469. Backspace,
  470. Clear,
  471. Copy,
  472. CrSel,
  473. Cut,
  474. Delete,
  475. EraseEof,
  476. ExSel,
  477. Insert,
  478. Paste,
  479. Redo,
  480. Undo,
  481. # UI keys
  482. Accept,
  483. Again,
  484. Attn,
  485. Cancel,
  486. ContextMenu,
  487. Escape,
  488. Execute,
  489. Find,
  490. Finish,
  491. Help,
  492. Pause,
  493. Play,
  494. Props,
  495. Select,
  496. ZoomIn,
  497. ZoomOut,
  498. # Device keys
  499. BrigtnessDown,
  500. BrigtnessUp,
  501. Eject,
  502. LogOff,
  503. Power,
  504. PowerOff,
  505. PrintScreen,
  506. Hibernate,
  507. Standby,
  508. WakeUp,
  509. # Common IME keys
  510. AllCandidates,
  511. Alphanumeric,
  512. CodeInput,
  513. Compose,
  514. Convert,
  515. Dead,
  516. FinalMode,
  517. GroupFirst,
  518. GroupLast,
  519. GroupNext,
  520. GroupPrevious,
  521. ModeChange,
  522. NextCandidate,
  523. NonConvert,
  524. PreviousCandidate,
  525. Process,
  526. SingleCandidate,
  527. # Korean keyboards only
  528. HangulMode,
  529. HanjaMode,
  530. JunjaMode,
  531. # Japanese keyboards only
  532. Eisu,
  533. Hankaku,
  534. Hiragana,
  535. HiraganaKatakana,
  536. KanaMode,
  537. KanjiMode,
  538. Katakana,
  539. Romaji,
  540. Zenkaku,
  541. ZenkakuHanaku,
  542. # Function keys
  543. F1,
  544. F2,
  545. F3,
  546. F4,
  547. F5,
  548. F6,
  549. F7,
  550. F8,
  551. F9,
  552. F10,
  553. F11,
  554. F12,
  555. F13,
  556. F14,
  557. F15,
  558. F16,
  559. F17,
  560. F18,
  561. F19,
  562. F20,
  563. Soft1,
  564. Soft2,
  565. Soft3,
  566. Soft4,
  567. # Phone keys
  568. AppSwitch,
  569. Call,
  570. Camera,
  571. CameraFocus,
  572. EndCall,
  573. GoBack,
  574. GoHome,
  575. HeadsetHook,
  576. LastNumberRedial,
  577. Notification,
  578. MannerMode,
  579. VoiceDial,
  580. # Multimedia keys
  581. ChannelDown,
  582. ChannelUp,
  583. MediaFastForward,
  584. MediaPause,
  585. MediaPlay,
  586. MediaPlayPause,
  587. MediaRecord,
  588. MediaRewind,
  589. MediaStop,
  590. MediaTrackNext,
  591. MediaTrackPrevious,
  592. # Audio control keys
  593. AudioBalanceLeft,
  594. AudioBalanceRight,
  595. AudioBassDown,
  596. AudioBassBoostDown,
  597. AudioBassBoostToggle,
  598. AudioBassBoostUp,
  599. AudioBassUp,
  600. AudioFaderFront,
  601. AudioFaderRear,
  602. AudioSurroundModeNext,
  603. AudioTrebleDown,
  604. AudioTrebleUp,
  605. AudioVolumeDown,
  606. AUdioVolumeMute,
  607. AudioVolumeUp,
  608. MicrophoneToggle,
  609. MicrophoneVolumeDown,
  610. MicrophoneVolumeMute,
  611. MicrophoneVolumeUp,
  612. # TV control keys
  613. TV,
  614. TV3DMode,
  615. TVAntennaCable,
  616. TVAudioDescription,
  617. TVAudioDescriptionMixDown,
  618. TVAudioDescriptionMixUp,
  619. TVContentsMenu,
  620. TVDataService,
  621. TVInput,
  622. TVInputComponent1,
  623. TVInputComponent2,
  624. TVInputComposite1,
  625. TVInputComposite2,
  626. TVInputHDMI1,
  627. TVInputHDMI2,
  628. TVInputHDMI3,
  629. TVInputHDMI4,
  630. TVInputVGA1,
  631. TVMediaContext,
  632. TVNetwork,
  633. TVNumberEntry,
  634. TVPower,
  635. TVRadioService,
  636. TVSatellite,
  637. TVSatelliteBS,
  638. TVSatelliteCS,
  639. TVSatelliteToggle,
  640. TVTerrestrialAnalog,
  641. TVTerrestrialDigital,
  642. TVTimer,
  643. # Media controller keys
  644. AVRInput,
  645. AVRPower,
  646. ColorF0Red,
  647. ColorF1Green,
  648. ColorF2Yellow,
  649. ColorF3Blue,
  650. ColorF4Grey,
  651. ColorF5Brown,
  652. ClosedCaptionToggle,
  653. Dimmer,
  654. DisplaySwap,
  655. DVR,
  656. Exit,
  657. FavoriteClear0,
  658. FavoriteClear1,
  659. FavoriteClear2,
  660. FavoriteClear3,
  661. FavoriteRecall0,
  662. FavoriteRecall1,
  663. FavoriteRecall2,
  664. FavoriteRecall3,
  665. FavoriteStore0,
  666. FavoriteStore1,
  667. FavoriteStore2,
  668. FavoriteStore3,
  669. Guide,
  670. GuideNextDay,
  671. GuidePreviousDay,
  672. Info,
  673. InstantReplay,
  674. Link,
  675. ListProgram,
  676. LiveContent,
  677. Lock,
  678. MediaApps,
  679. MediaAudioTrack,
  680. MediaLast,
  681. MediaSkipBackward,
  682. MediaSkipForward,
  683. MediaStepBackward,
  684. MediaStepForward,
  685. MediaTopMenu,
  686. NavigateIn,
  687. NavigateNext,
  688. NavigateOut,
  689. NavigatePrevious,
  690. NextFavoriteChannel,
  691. NextUserProfile,
  692. OnDemand,
  693. Pairing,
  694. PinPDown,
  695. PinPMove,
  696. PinPUp,
  697. PlaySpeedDown,
  698. PlaySpeedReset,
  699. PlaySpeedUp,
  700. RandomToggle,
  701. RcLowBattery,
  702. RecordSpeedNext,
  703. RfBypass,
  704. ScanChannelsToggle,
  705. ScreenModeNext,
  706. Settings,
  707. SplitScreenToggle,
  708. STBInput,
  709. STBPower,
  710. Subtitle,
  711. Teletext,
  712. VideoModeNext,
  713. Wink,
  714. ZoomToggle,
  715. # Speech recognition keys
  716. SpeechCorrectionList,
  717. SpeechInputToggle,
  718. # Document keys
  719. Close,
  720. New,
  721. Open,
  722. Print,
  723. Save,
  724. SpellCheck,
  725. MailForward,
  726. MailReply,
  727. MailSend,
  728. # Application selector keys
  729. LaunchCalculator,
  730. LaunchCalendar,
  731. LaunchContacts,
  732. LaunchMail,
  733. LaunchMediaPlayer,
  734. LaunchMusicPlayer,
  735. LaunchMyComputer,
  736. LaunchPhone,
  737. LaunchScreenSaver,
  738. LaunchSpreadsheet,
  739. LaunchWebBrowser,
  740. LaunchWebCam,
  741. LaunchWordProcessor,
  742. LaunchApplication1,
  743. LaunchApplication2,
  744. LaunchApplication3,
  745. LaunchApplication4,
  746. LaunchApplication5,
  747. LaunchApplication6,
  748. LaunchApplication7,
  749. LaunchApplication8,
  750. LaunchApplication9,
  751. LaunchApplication10,
  752. LaunchApplication11,
  753. LaunchApplication12,
  754. LaunchApplication13,
  755. LaunchApplication14,
  756. LaunchApplication15,
  757. LaunchApplication16,
  758. # Browser control keys
  759. BrowserBack,
  760. BrowserFavorites,
  761. BrowserForward,
  762. BrowserHome,
  763. BrowserRefresh,
  764. BrowserSearch,
  765. BrowserStop,
  766. # Numeric keypad keys
  767. Key11,
  768. Key12,
  769. Separator
  770. MouseButtons* = enum
  771. NoButton = 0,
  772. PrimaryButton = 1,
  773. SecondaryButton = 2,
  774. AuxilaryButton = 4,
  775. FourthButton = 8,
  776. FifthButton = 16
  777. # https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent
  778. MouseEvent* = ref MouseEventObj
  779. MouseEventObj {.importc.} = object of UIEvent
  780. altKey*, ctrlKey*, metaKey*, shiftKey*: bool
  781. button*: int
  782. buttons*: int
  783. clientX*, clientY*: int
  784. movementX*, movementY*: int
  785. offsetX*, offsetY*: int
  786. pageX*, pageY*: int
  787. relatedTarget*: EventTarget
  788. #region*: cstring
  789. screenX*, screenY*: int
  790. x*, y*: int
  791. DataTransferItemKind* {.pure.} = enum
  792. File = "file",
  793. String = "string"
  794. # https://developer.mozilla.org/en-US/docs/Web/API/DataTransferItem
  795. DataTransferItem* = ref DataTransferItemObj
  796. DataTransferItemObj {.importc.} = object of RootObj
  797. kind*: cstring
  798. `type`*: cstring
  799. # https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer
  800. DataTransfer* = ref DataTransferObj
  801. DataTransferObj {.importc.} = object of RootObj
  802. dropEffect*: cstring
  803. effectAllowed*: cstring
  804. files*: seq[Element]
  805. items*: seq[DataTransferItem]
  806. types*: seq[cstring]
  807. DataTransferDropEffect* {.pure.} = enum
  808. None = "none",
  809. Copy = "copy",
  810. Link = "link",
  811. Move = "move"
  812. DataTransferEffectAllowed* {.pure.} = enum
  813. None = "none",
  814. Copy = "copy",
  815. CopyLink = "copyLink",
  816. CopyMove = "copyMove",
  817. Link = "link",
  818. LinkMove = "linkMove",
  819. Move = "move",
  820. All = "all",
  821. Uninitialized = "uninitialized"
  822. DragEventTypes* = enum
  823. Drag = "drag",
  824. DragEnd = "dragend",
  825. DragEnter = "dragenter",
  826. DragExit = "dragexit",
  827. DragLeave = "dragleave",
  828. DragOver = "dragover",
  829. DragStart = "dragstart",
  830. Drop = "drop"
  831. # https://developer.mozilla.org/en-US/docs/Web/API/DragEvent
  832. DragEvent* {.importc.} = object of MouseEvent
  833. dataTransfer*: DataTransfer
  834. TouchList* {.importc.} = ref object of RootObj
  835. length*: int
  836. Touch* = ref TouchObj
  837. TouchObj {.importc.} = object of RootObj
  838. identifier*: int
  839. screenX*, screenY*, clientX*, clientY*, pageX*, pageY*: int
  840. target*: Element
  841. radiusX*, radiusY*: int
  842. rotationAngle*: int
  843. force*: float
  844. TouchEvent* = ref TouchEventObj
  845. TouchEventObj {.importc.} = object of UIEvent
  846. changedTouches*, targetTouches*, touches*: seq[Touch]
  847. Location* = ref LocationObj
  848. LocationObj {.importc.} = object of RootObj
  849. hash*: cstring
  850. host*: cstring
  851. hostname*: cstring
  852. href*: cstring
  853. pathname*: cstring
  854. port*: cstring
  855. protocol*: cstring
  856. search*: cstring
  857. History* = ref HistoryObj
  858. HistoryObj {.importc.} = object of RootObj
  859. length*: int
  860. Navigator* = ref NavigatorObj
  861. NavigatorObj {.importc.} = object of RootObj
  862. appCodeName*: cstring
  863. appName*: cstring
  864. appVersion*: cstring
  865. cookieEnabled*: bool
  866. language*: cstring
  867. platform*: cstring
  868. userAgent*: cstring
  869. mimeTypes*: seq[ref MimeType]
  870. Plugin* {.importc.} = object of RootObj
  871. description*: cstring
  872. filename*: cstring
  873. name*: cstring
  874. MimeType* {.importc.} = object of RootObj
  875. description*: cstring
  876. enabledPlugin*: ref Plugin
  877. suffixes*: seq[cstring]
  878. `type`*: cstring
  879. LocationBar* {.importc.} = object of RootObj
  880. visible*: bool
  881. MenuBar* = LocationBar
  882. PersonalBar* = LocationBar
  883. ScrollBars* = LocationBar
  884. ToolBar* = LocationBar
  885. StatusBar* = LocationBar
  886. Screen = ref ScreenObj
  887. ScreenObj {.importc.} = object of RootObj
  888. availHeight*: int
  889. availWidth*: int
  890. colorDepth*: int
  891. height*: int
  892. pixelDepth*: int
  893. width*: int
  894. TimeOut* {.importc.} = ref object of RootObj
  895. Interval* {.importc.} = object of RootObj
  896. AddEventListenerOptions* = object
  897. capture*: bool
  898. once*: bool
  899. passive*: bool
  900. proc id*(n: Node): cstring {.importcpp: "#.id", nodecl.}
  901. proc `id=`*(n: Node; x: cstring) {.importcpp: "#.id = #", nodecl.}
  902. proc class*(n: Node): cstring {.importcpp: "#.className", nodecl.}
  903. proc `class=`*(n: Node; v: cstring) {.importcpp: "#.className = #", nodecl.}
  904. proc value*(n: Node): cstring {.importcpp: "#.value", nodecl.}
  905. proc `value=`*(n: Node; v: cstring) {.importcpp: "#.value = #", nodecl.}
  906. proc `disabled=`*(n: Node; v: bool) {.importcpp: "#.disabled = #", nodecl.}
  907. when defined(nodejs):
  908. # we provide a dummy DOM for nodejs for testing purposes
  909. proc len*(x: Node): int = x.childNodes.len
  910. proc `[]`*(x: Node; idx: int): Element =
  911. assert idx >= 0 and idx < x.childNodes.len
  912. result = cast[Element](x.childNodes[idx])
  913. var document* = Document(nodeType: DocumentNode)
  914. proc getElem(x: Element; id: cstring): Element =
  915. if x.id == id: return x
  916. for i in 0..<x.len:
  917. result = getElem(x[i], id)
  918. if result != nil: return result
  919. proc getElementById*(doc: Document; id: cstring): Element =
  920. getElem(doc.body, id)
  921. proc getElementById*(id: cstring): Element = document.getElementById(id)
  922. proc appendChild*(parent, n: Node) =
  923. n.parentNode = parent
  924. parent.childNodes.add n
  925. proc replaceChild*(parent, newNode, oldNode: Node) =
  926. newNode.parentNode = parent
  927. oldNode.parentNode = nil
  928. var i = 0
  929. while i < parent.len:
  930. if Node(parent[i]) == oldNode:
  931. parent.childNodes[i] = newNode
  932. return
  933. inc i
  934. doAssert false, "old node not in node list"
  935. proc removeChild*(parent, child: Node) =
  936. child.parentNode = nil
  937. var i = 0
  938. while i < parent.len:
  939. if Node(parent[i]) == child:
  940. parent.childNodes.delete(i)
  941. return
  942. inc i
  943. doAssert false, "old node not in node list"
  944. proc insertBefore*(parent, newNode, before: Node) =
  945. appendChild(parent, newNode)
  946. var i = 0
  947. while i < parent.len-1:
  948. if Node(parent[i]) == before:
  949. for j in countdown(parent.len-1, i-1):
  950. parent.childNodes[j] = parent.childNodes[j-1]
  951. parent.childNodes[i-1] = newNode
  952. return
  953. inc i
  954. #doAssert false, "before not in node list"
  955. proc createElement*(d: Document, identifier: cstring): Element =
  956. new(result)
  957. result.nodeName = identifier
  958. result.nodeType = NodeType.ElementNode
  959. proc createTextNode*(d: Document, identifier: cstring): Node =
  960. new(result)
  961. result.nodeName = "#text"
  962. result.nodeValue = identifier
  963. result.nodeType = NodeType.TextNode
  964. else:
  965. proc len*(x: Node): int {.importcpp: "#.childNodes.length".}
  966. proc `[]`*(x: Node; idx: int): Element {.importcpp: "#.childNodes[#]".}
  967. proc getElementById*(id: cstring): Element {.importc: "document.getElementById", nodecl.}
  968. proc appendChild*(n, child: Node) {.importcpp.}
  969. proc removeChild*(n, child: Node) {.importcpp.}
  970. proc replaceChild*(n, newNode, oldNode: Node) {.importcpp.}
  971. proc insertBefore*(n, newNode, before: Node) {.importcpp.}
  972. proc getElementById*(d: Document, id: cstring): Element {.importcpp.}
  973. proc createElement*(d: Document, identifier: cstring): Element {.importcpp.}
  974. proc createTextNode*(d: Document, identifier: cstring): Node {.importcpp.}
  975. proc setTimeout*(action: proc(); ms: int): Timeout {.importc, nodecl.}
  976. proc clearTimeout*(t: Timeout) {.importc, nodecl.}
  977. {.push importcpp.}
  978. # EventTarget "methods"
  979. proc addEventListener*(et: EventTarget, ev: cstring, cb: proc(ev: Event), useCapture: bool = false)
  980. proc addEventListener*(et: EventTarget, ev: cstring, cb: proc(ev: Event), options: AddEventListenerOptions)
  981. proc dispatchEvent*(et: EventTarget, ev: Event)
  982. proc removeEventListener*(et: EventTarget; ev: cstring; cb: proc(ev: Event))
  983. # Window "methods"
  984. proc alert*(w: Window, msg: cstring)
  985. proc back*(w: Window)
  986. proc blur*(w: Window)
  987. proc captureEvents*(w: Window, eventMask: int) {.deprecated.}
  988. proc clearInterval*(w: Window, interval: ref Interval)
  989. proc clearTimeout*(w: Window, timeout: ref TimeOut)
  990. proc close*(w: Window)
  991. proc confirm*(w: Window, msg: cstring): bool
  992. proc disableExternalCapture*(w: Window)
  993. proc enableExternalCapture*(w: Window)
  994. proc find*(w: Window, text: cstring, caseSensitive = false,
  995. backwards = false)
  996. proc focus*(w: Window)
  997. proc forward*(w: Window)
  998. proc getComputedStyle*(w: Window, e: Node, pe:Node = nil): Style
  999. proc handleEvent*(w: Window, e: Event)
  1000. proc home*(w: Window)
  1001. proc moveBy*(w: Window, x, y: int)
  1002. proc moveTo*(w: Window, x, y: int)
  1003. proc open*(w: Window, uri, windowname: cstring,
  1004. properties: cstring = nil): Window
  1005. proc print*(w: Window)
  1006. proc prompt*(w: Window, text, default: cstring): cstring
  1007. proc releaseEvents*(w: Window, eventMask: int) {.deprecated.}
  1008. proc resizeBy*(w: Window, x, y: int)
  1009. proc resizeTo*(w: Window, x, y: int)
  1010. proc routeEvent*(w: Window, event: Event)
  1011. proc scrollBy*(w: Window, x, y: int)
  1012. proc scrollTo*(w: Window, x, y: int)
  1013. proc setInterval*(w: Window, code: cstring, pause: int): ref Interval
  1014. proc setInterval*(w: Window, function: proc (), pause: int): ref Interval
  1015. proc setTimeout*(w: Window, code: cstring, pause: int): ref TimeOut
  1016. proc setTimeout*(w: Window, function: proc (), pause: int): ref Interval
  1017. proc stop*(w: Window)
  1018. proc requestAnimationFrame*(w: Window, function: proc (time: float)): int
  1019. proc cancelAnimationFrame*(w: Window, id: int)
  1020. # Node "methods"
  1021. proc appendData*(n: Node, data: cstring)
  1022. proc cloneNode*(n: Node, copyContent: bool): Node
  1023. proc deleteData*(n: Node, start, len: int)
  1024. proc focus*(e: Node)
  1025. proc getAttribute*(n: Node, attr: cstring): cstring
  1026. proc getAttributeNode*(n: Node, attr: cstring): Node
  1027. proc hasChildNodes*(n: Node): bool
  1028. proc insertData*(n: Node, position: int, data: cstring)
  1029. proc removeAttribute*(n: Node, attr: cstring)
  1030. proc removeAttributeNode*(n, attr: Node)
  1031. proc replaceData*(n: Node, start, len: int, text: cstring)
  1032. proc scrollIntoView*(n: Node)
  1033. proc setAttribute*(n: Node, name, value: cstring)
  1034. proc setAttributeNode*(n: Node, attr: Node)
  1035. # Document "methods"
  1036. proc captureEvents*(d: Document, eventMask: int) {.deprecated.}
  1037. proc createAttribute*(d: Document, identifier: cstring): Node
  1038. proc getElementsByName*(d: Document, name: cstring): seq[Element]
  1039. proc getElementsByTagName*(d: Document, name: cstring): seq[Element]
  1040. proc getElementsByClassName*(d: Document, name: cstring): seq[Element]
  1041. proc getSelection*(d: Document): cstring
  1042. proc handleEvent*(d: Document, event: Event)
  1043. proc open*(d: Document)
  1044. proc releaseEvents*(d: Document, eventMask: int) {.deprecated.}
  1045. proc routeEvent*(d: Document, event: Event)
  1046. proc write*(d: Document, text: cstring)
  1047. proc writeln*(d: Document, text: cstring)
  1048. proc querySelector*(d: Document, selectors: cstring): Element
  1049. proc querySelectorAll*(d: Document, selectors: cstring): seq[Element]
  1050. # Element "methods"
  1051. proc blur*(e: Element)
  1052. proc click*(e: Element)
  1053. proc focus*(e: Element)
  1054. proc handleEvent*(e: Element, event: Event)
  1055. proc select*(e: Element)
  1056. proc getElementsByTagName*(e: Element, name: cstring): seq[Element]
  1057. proc getElementsByClassName*(e: Element, name: cstring): seq[Element]
  1058. # FormElement "methods"
  1059. proc reset*(f: FormElement)
  1060. proc submit*(f: FormElement)
  1061. proc checkValidity*(e: FormElement): bool
  1062. proc reportValidity*(e: FormElement): bool
  1063. # EmbedElement "methods"
  1064. proc play*(e: EmbedElement)
  1065. proc stop*(e: EmbedElement)
  1066. # Location "methods"
  1067. proc reload*(loc: Location)
  1068. proc replace*(loc: Location, s: cstring)
  1069. # History "methods"
  1070. proc back*(h: History)
  1071. proc forward*(h: History)
  1072. proc go*(h: History, pagesToJump: int)
  1073. proc pushState*[T](h: History, stateObject: T, title, url: cstring)
  1074. # Navigator "methods"
  1075. proc javaEnabled*(h: Navigator): bool
  1076. # ClassList "methods"
  1077. proc add*(c: ClassList, class: cstring)
  1078. proc remove*(c: ClassList, class: cstring)
  1079. proc contains*(c: ClassList, class: cstring): bool
  1080. proc toggle*(c: ClassList, class: cstring)
  1081. # Style "methods"
  1082. proc getPropertyValue*(s: Style, property: cstring): cstring
  1083. proc removeProperty*(s: Style, property: cstring)
  1084. proc setProperty*(s: Style, property, value: cstring, priority = "")
  1085. proc getPropertyPriority*(s: Style, property: cstring): cstring
  1086. # Event "methods"
  1087. proc preventDefault*(ev: Event)
  1088. proc stopImmediatePropagation*(ev: Event)
  1089. proc stopPropagation*(ev: Event)
  1090. # KeyboardEvent "methods"
  1091. proc getModifierState*(ev: KeyboardEvent, keyArg: cstring): bool
  1092. # MouseEvent "methods"
  1093. proc getModifierState*(ev: MouseEvent, keyArg: cstring): bool
  1094. # TouchEvent "methods"
  1095. proc identifiedTouch*(list: TouchList): Touch
  1096. proc item*(list: TouchList, i: int): Touch
  1097. # DataTransfer "methods"
  1098. proc clearData*(dt: DataTransfer, format: cstring)
  1099. proc getData*(dt: DataTransfer, format: cstring): cstring
  1100. proc setData*(dt: DataTransfer, format: cstring, data: cstring)
  1101. proc setDragImage*(dt: DataTransfer, img: Element, xOffset: int64, yOffset: int64)
  1102. # DataTransferItem "methods"
  1103. proc getAsFile*(dti: DataTransferItem): File
  1104. # InputElement "methods"
  1105. proc setSelectionRange*(e: InputElement, selectionStart: int, selectionEnd: int, selectionDirection: cstring = "none")
  1106. proc setRangeText*(e: InputElement, replacement: cstring, startindex: int = 0, endindex: int = 0, selectionMode: cstring = "preserve")
  1107. proc setCustomValidity*(e: InputElement, error: cstring)
  1108. proc checkValidity*(e: InputElement): bool
  1109. # Blob "methods"
  1110. proc slice*(e: Blob, startindex: int = 0, endindex: int = e.size, contentType: cstring = "")
  1111. {.pop.}
  1112. proc setAttr*(n: Node; key, val: cstring) {.importcpp: "#.setAttribute(@)".}
  1113. var
  1114. window* {.importc, nodecl.}: Window
  1115. navigator* {.importc, nodecl.}: Navigator
  1116. screen* {.importc, nodecl.}: Screen
  1117. when not defined(nodejs):
  1118. var document* {.importc, nodecl.}: Document
  1119. proc decodeURI*(uri: cstring): cstring {.importc, nodecl.}
  1120. proc encodeURI*(uri: cstring): cstring {.importc, nodecl.}
  1121. proc escape*(uri: cstring): cstring {.importc, nodecl.}
  1122. proc unescape*(uri: cstring): cstring {.importc, nodecl.}
  1123. proc decodeURIComponent*(uri: cstring): cstring {.importc, nodecl.}
  1124. proc encodeURIComponent*(uri: cstring): cstring {.importc, nodecl.}
  1125. proc isFinite*(x: BiggestFloat): bool {.importc, nodecl.}
  1126. proc isNaN*(x: BiggestFloat): bool {.importc, nodecl.}
  1127. proc newEvent*(name: cstring): Event {.importcpp: "new Event(@)", constructor.}
  1128. proc getElementsByClass*(n: Node; name: cstring): seq[Node] {.
  1129. importcpp: "#.getElementsByClassName(#)", nodecl.}
  1130. type
  1131. BoundingRect* {.importc.} = object
  1132. top*, bottom*, left*, right*, x*, y*, width*, height*: float
  1133. proc getBoundingClientRect*(e: Node): BoundingRect {.
  1134. importcpp: "getBoundingClientRect", nodecl.}
  1135. proc clientHeight*(): int {.
  1136. importcpp: "(window.innerHeight || document.documentElement.clientHeight)@", nodecl.}
  1137. proc clientWidth*(): int {.
  1138. importcpp: "(window.innerWidth || document.documentElement.clientWidth)@", nodecl.}
  1139. proc inViewport*(el: Node): bool =
  1140. let rect = el.getBoundingClientRect()
  1141. result = rect.top >= 0 and rect.left >= 0 and
  1142. rect.bottom <= clientHeight().float and
  1143. rect.right <= clientWidth().float
  1144. proc scrollTop*(e: Node): int {.importcpp: "#.scrollTop", nodecl.}
  1145. proc scrollLeft*(e: Node): int {.importcpp: "#.scrollLeft", nodecl.}
  1146. proc scrollHeight*(e: Node): int {.importcpp: "#.scrollHeight", nodecl.}
  1147. proc scrollWidth*(e: Node): int {.importcpp: "#.scrollWidth", nodecl.}
  1148. proc offsetHeight*(e: Node): int {.importcpp: "#.offsetHeight", nodecl.}
  1149. proc offsetWidth*(e: Node): int {.importcpp: "#.offsetWidth", nodecl.}
  1150. proc offsetTop*(e: Node): int {.importcpp: "#.offsetTop", nodecl.}
  1151. proc offsetLeft*(e: Node): int {.importcpp: "#.offsetLeft", nodecl.}