@swf2es/player-hosts 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (405) hide show
  1. package/LICENSE +202 -0
  2. package/LICENSE.third-party +759 -0
  3. package/README.md +43 -2
  4. package/dist/indexeddb.d.ts +27 -0
  5. package/dist/indexeddb.d.ts.map +1 -0
  6. package/dist/indexeddb.js +170 -0
  7. package/dist/indexeddb.js.map +1 -0
  8. package/dist/node-worker.d.ts +2 -0
  9. package/dist/node-worker.d.ts.map +1 -0
  10. package/dist/node-worker.js +12 -0
  11. package/dist/node-worker.js.map +1 -0
  12. package/dist/node.d.ts +8 -0
  13. package/dist/node.d.ts.map +1 -0
  14. package/dist/node.js +43 -0
  15. package/dist/node.js.map +1 -0
  16. package/dist/precompiled.d.ts +31 -0
  17. package/dist/precompiled.d.ts.map +1 -0
  18. package/dist/precompiled.js +125 -0
  19. package/dist/precompiled.js.map +1 -0
  20. package/dist/stage3d.d.ts +13 -0
  21. package/dist/stage3d.d.ts.map +1 -0
  22. package/dist/stage3d.js +61 -0
  23. package/dist/stage3d.js.map +1 -0
  24. package/dist/thread/codegen/codegen.js +308 -0
  25. package/dist/thread/codegen/index.js +405 -0
  26. package/dist/thread/format/abc-names.js +126 -0
  27. package/dist/thread/format/actions.js +222 -0
  28. package/dist/thread/format/air-descriptor.js +63 -0
  29. package/dist/thread/format/api-versions.js +22 -0
  30. package/dist/thread/format/bitmap.js +199 -0
  31. package/dist/thread/format/button.js +60 -0
  32. package/dist/thread/format/compression.js +200 -0
  33. package/dist/thread/format/display.js +305 -0
  34. package/dist/thread/format/filters.js +136 -0
  35. package/dist/thread/format/font.js +168 -0
  36. package/dist/thread/format/index.js +26 -0
  37. package/dist/thread/format/pbj.js +484 -0
  38. package/dist/thread/format/shape.js +411 -0
  39. package/dist/thread/format/sound.js +91 -0
  40. package/dist/thread/format/swf.js +163 -0
  41. package/dist/thread/format/tags.js +58 -0
  42. package/dist/thread/format/text.js +135 -0
  43. package/dist/thread/format/zip.js +91 -0
  44. package/dist/thread/native/audio/binary.js +3 -0
  45. package/dist/thread/native/audio/index.js +72 -0
  46. package/dist/thread/native/base64.js +9 -0
  47. package/dist/thread/native/compress/binary.js +3 -0
  48. package/dist/thread/native/compress/index.js +145 -0
  49. package/dist/thread/native/instance.js +49 -0
  50. package/dist/thread/native/mp3/binary.js +3 -0
  51. package/dist/thread/native/mp3/index.js +48 -0
  52. package/dist/thread/native/render/binary.js +3 -0
  53. package/dist/thread/native/render/bitmap-kernel.js +591 -0
  54. package/dist/thread/native/render/draw-kernel.js +204 -0
  55. package/dist/thread/native/render/dxt-encoder.js +94 -0
  56. package/dist/thread/native/render/index.js +10 -0
  57. package/dist/thread/native/render/lines.js +122 -0
  58. package/dist/thread/native/render/module.js +26 -0
  59. package/dist/thread/native/render/pixel-ops.js +235 -0
  60. package/dist/thread/native/render/tessellator.js +250 -0
  61. package/dist/thread/player/avm1/amf.js +507 -0
  62. package/dist/thread/player/avm1/avm1.js +1304 -0
  63. package/dist/thread/player/avm1/bindings.js +214 -0
  64. package/dist/thread/player/avm1/classes.js +75 -0
  65. package/dist/thread/player/avm1/clips.js +229 -0
  66. package/dist/thread/player/avm1/compile.js +140 -0
  67. package/dist/thread/player/avm1/external.js +79 -0
  68. package/dist/thread/player/avm1/focus.js +278 -0
  69. package/dist/thread/player/avm1/globals/BitmapData.js +542 -0
  70. package/dist/thread/player/avm1/globals/Button.js +31 -0
  71. package/dist/thread/player/avm1/globals/Color.js +115 -0
  72. package/dist/thread/player/avm1/globals/ExternalInterface.js +310 -0
  73. package/dist/thread/player/avm1/globals/FileReference.js +217 -0
  74. package/dist/thread/player/avm1/globals/Key.js +60 -0
  75. package/dist/thread/player/avm1/globals/LoadVars.js +208 -0
  76. package/dist/thread/player/avm1/globals/LocalConnection.js +92 -0
  77. package/dist/thread/player/avm1/globals/MovieClip.js +1070 -0
  78. package/dist/thread/player/avm1/globals/MovieClipLoader.js +90 -0
  79. package/dist/thread/player/avm1/globals/NetConnection.js +261 -0
  80. package/dist/thread/player/avm1/globals/PrintJob.js +37 -0
  81. package/dist/thread/player/avm1/globals/Selection.js +62 -0
  82. package/dist/thread/player/avm1/globals/SharedObject.js +245 -0
  83. package/dist/thread/player/avm1/globals/Sound.js +238 -0
  84. package/dist/thread/player/avm1/globals/Stage.js +12 -0
  85. package/dist/thread/player/avm1/globals/StyleSheet.js +205 -0
  86. package/dist/thread/player/avm1/globals/TextField.js +396 -0
  87. package/dist/thread/player/avm1/globals/TextFormat.js +194 -0
  88. package/dist/thread/player/avm1/globals/TextSnapshot.js +88 -0
  89. package/dist/thread/player/avm1/globals/XML.js +396 -0
  90. package/dist/thread/player/avm1/globals/XMLNode.js +413 -0
  91. package/dist/thread/player/avm1/globals/XMLSocket.js +205 -0
  92. package/dist/thread/player/avm1/globals/drawing.js +202 -0
  93. package/dist/thread/player/avm1/globals/filters.js +635 -0
  94. package/dist/thread/player/avm1/globals/geom.js +600 -0
  95. package/dist/thread/player/avm1/input.js +483 -0
  96. package/dist/thread/player/avm1/keyboard.js +113 -0
  97. package/dist/thread/player/avm1/loads.js +352 -0
  98. package/dist/thread/player/avm1/net.js +219 -0
  99. package/dist/thread/player/avm1/paths.js +104 -0
  100. package/dist/thread/player/avm1/pointer.js +512 -0
  101. package/dist/thread/player/avm1/queue.js +303 -0
  102. package/dist/thread/player/avm1/sound.js +106 -0
  103. package/dist/thread/player/avm1/swf.js +141 -0
  104. package/dist/thread/player/avm1/timers.js +113 -0
  105. package/dist/thread/player/bitmap/bitmap.js +627 -0
  106. package/dist/thread/player/bitmap/draw.js +68 -0
  107. package/dist/thread/player/bitmap/dxt.js +11 -0
  108. package/dist/thread/player/bitmap/filters.js +656 -0
  109. package/dist/thread/player/bitmap/images.js +240 -0
  110. package/dist/thread/player/bitmap/kernel.js +65 -0
  111. package/dist/thread/player/bitmap/ops.js +1239 -0
  112. package/dist/thread/player/bitmap/pixel-bender.js +911 -0
  113. package/dist/thread/player/bitmap/png.js +139 -0
  114. package/dist/thread/player/bitmap/turbulence.js +89 -0
  115. package/dist/thread/player/clock.js +182 -0
  116. package/dist/thread/player/display/bitmapobject.js +25 -0
  117. package/dist/thread/player/display/bounds.js +520 -0
  118. package/dist/thread/player/display/buttonobject.js +305 -0
  119. package/dist/thread/player/display/color.js +40 -0
  120. package/dist/thread/player/display/container.js +150 -0
  121. package/dist/thread/player/display/display.js +14 -0
  122. package/dist/thread/player/display/displayobject.js +664 -0
  123. package/dist/thread/player/display/drawing.js +613 -0
  124. package/dist/thread/player/display/filters.js +285 -0
  125. package/dist/thread/player/display/geometry.js +189 -0
  126. package/dist/thread/player/display/gradients.js +117 -0
  127. package/dist/thread/player/display/graphicsdata.js +592 -0
  128. package/dist/thread/player/display/instantiate.js +71 -0
  129. package/dist/thread/player/display/matrix3d.js +373 -0
  130. package/dist/thread/player/display/morph.js +226 -0
  131. package/dist/thread/player/display/movieclip.js +680 -0
  132. package/dist/thread/player/display/perspective.js +193 -0
  133. package/dist/thread/player/display/scale9.js +236 -0
  134. package/dist/thread/player/display/shapeobject.js +131 -0
  135. package/dist/thread/player/display/shapes.js +407 -0
  136. package/dist/thread/player/display/textobjects.js +222 -0
  137. package/dist/thread/player/display/timeline.js +471 -0
  138. package/dist/thread/player/display/value-lists.js +40 -0
  139. package/dist/thread/player/display/videoobject.js +6 -0
  140. package/dist/thread/player/display/walk.js +127 -0
  141. package/dist/thread/player/files.js +334 -0
  142. package/dist/thread/player/hosts.js +207 -0
  143. package/dist/thread/player/input/avm1.js +82 -0
  144. package/dist/thread/player/input/context-menu.js +63 -0
  145. package/dist/thread/player/input/keyboard.js +458 -0
  146. package/dist/thread/player/input/pointer.js +863 -0
  147. package/dist/thread/player/input/text-editor.js +319 -0
  148. package/dist/thread/player/input/touch.js +209 -0
  149. package/dist/thread/player/localconnection.js +90 -0
  150. package/dist/thread/player/media/audio.js +376 -0
  151. package/dist/thread/player/media/dynamic-sound.js +90 -0
  152. package/dist/thread/player/media/extract.js +135 -0
  153. package/dist/thread/player/media/mp3.js +152 -0
  154. package/dist/thread/player/media/sounds.js +507 -0
  155. package/dist/thread/player/media/streaming-audio.js +133 -0
  156. package/dist/thread/player/player.js +616 -0
  157. package/dist/thread/player/playerglobal/air/net/WebSocket.js +250 -0
  158. package/dist/thread/player/playerglobal/air-library.js +8 -0
  159. package/dist/thread/player/playerglobal/flash/accessibility/Accessibility.js +21 -0
  160. package/dist/thread/player/playerglobal/flash/crypto/generateRandomBytes.js +32 -0
  161. package/dist/thread/player/playerglobal/flash/data/EncryptedLocalStore.js +61 -0
  162. package/dist/thread/player/playerglobal/flash/desktop/Clipboard.js +173 -0
  163. package/dist/thread/player/playerglobal/flash/desktop/NativeApplication.js +179 -0
  164. package/dist/thread/player/playerglobal/flash/display/AVM1Movie.js +19 -0
  165. package/dist/thread/player/playerglobal/flash/display/Bitmap.js +58 -0
  166. package/dist/thread/player/playerglobal/flash/display/BitmapData.js +633 -0
  167. package/dist/thread/player/playerglobal/flash/display/DisplayObject.js +614 -0
  168. package/dist/thread/player/playerglobal/flash/display/DisplayObjectContainer.js +224 -0
  169. package/dist/thread/player/playerglobal/flash/display/Graphics.js +345 -0
  170. package/dist/thread/player/playerglobal/flash/display/InteractiveObject.js +87 -0
  171. package/dist/thread/player/playerglobal/flash/display/Loader.js +79 -0
  172. package/dist/thread/player/playerglobal/flash/display/LoaderInfo.js +128 -0
  173. package/dist/thread/player/playerglobal/flash/display/MovieClip.js +194 -0
  174. package/dist/thread/player/playerglobal/flash/display/NativeWindow.js +245 -0
  175. package/dist/thread/player/playerglobal/flash/display/Shader.js +26 -0
  176. package/dist/thread/player/playerglobal/flash/display/ShaderData.js +85 -0
  177. package/dist/thread/player/playerglobal/flash/display/ShaderInput.js +64 -0
  178. package/dist/thread/player/playerglobal/flash/display/ShaderJob.js +181 -0
  179. package/dist/thread/player/playerglobal/flash/display/ShaderParameter.js +23 -0
  180. package/dist/thread/player/playerglobal/flash/display/Shape.js +13 -0
  181. package/dist/thread/player/playerglobal/flash/display/SimpleButton.js +103 -0
  182. package/dist/thread/player/playerglobal/flash/display/Sprite.js +84 -0
  183. package/dist/thread/player/playerglobal/flash/display/Stage.js +231 -0
  184. package/dist/thread/player/playerglobal/flash/display/Stage3D.js +54 -0
  185. package/dist/thread/player/playerglobal/flash/display/shaders.js +228 -0
  186. package/dist/thread/player/playerglobal/flash/events/Event.js +58 -0
  187. package/dist/thread/player/playerglobal/flash/events/EventDispatcher.js +103 -0
  188. package/dist/thread/player/playerglobal/flash/events/GestureEvent.js +34 -0
  189. package/dist/thread/player/playerglobal/flash/events/HTTPStatusEvent.js +8 -0
  190. package/dist/thread/player/playerglobal/flash/events/KeyboardEvent.js +51 -0
  191. package/dist/thread/player/playerglobal/flash/events/MouseEvent.js +59 -0
  192. package/dist/thread/player/playerglobal/flash/events/PressAndTapGestureEvent.js +30 -0
  193. package/dist/thread/player/playerglobal/flash/events/TimerEvent.js +16 -0
  194. package/dist/thread/player/playerglobal/flash/events/TouchEvent.js +45 -0
  195. package/dist/thread/player/playerglobal/flash/external/ExternalInterface.js +73 -0
  196. package/dist/thread/player/playerglobal/flash/filesystem/File.js +340 -0
  197. package/dist/thread/player/playerglobal/flash/filesystem/FileStream.js +453 -0
  198. package/dist/thread/player/playerglobal/flash/filesystem/paths.js +156 -0
  199. package/dist/thread/player/playerglobal/flash/filesystem/writes.js +143 -0
  200. package/dist/thread/player/playerglobal/flash/filters/BevelFilter.js +4 -0
  201. package/dist/thread/player/playerglobal/flash/filters/BitmapFilter.js +205 -0
  202. package/dist/thread/player/playerglobal/flash/filters/BlurFilter.js +4 -0
  203. package/dist/thread/player/playerglobal/flash/filters/ColorMatrixFilter.js +11 -0
  204. package/dist/thread/player/playerglobal/flash/filters/ConvolutionFilter.js +26 -0
  205. package/dist/thread/player/playerglobal/flash/filters/DisplacementMapFilter.js +51 -0
  206. package/dist/thread/player/playerglobal/flash/filters/DropShadowFilter.js +4 -0
  207. package/dist/thread/player/playerglobal/flash/filters/GlowFilter.js +4 -0
  208. package/dist/thread/player/playerglobal/flash/filters/GradientBevelFilter.js +4 -0
  209. package/dist/thread/player/playerglobal/flash/filters/GradientGlowFilter.js +4 -0
  210. package/dist/thread/player/playerglobal/flash/filters/ShaderFilter.js +53 -0
  211. package/dist/thread/player/playerglobal/flash/geom/Matrix3D.js +361 -0
  212. package/dist/thread/player/playerglobal/flash/geom/PerspectiveProjection.js +122 -0
  213. package/dist/thread/player/playerglobal/flash/geom/Transform.js +245 -0
  214. package/dist/thread/player/playerglobal/flash/geom/Utils3D.js +85 -0
  215. package/dist/thread/player/playerglobal/flash/globalization/Collator.js +149 -0
  216. package/dist/thread/player/playerglobal/flash/globalization/CurrencyFormatter.js +272 -0
  217. package/dist/thread/player/playerglobal/flash/globalization/CurrencyParseResult.js +21 -0
  218. package/dist/thread/player/playerglobal/flash/globalization/DateTimeFormatter.js +463 -0
  219. package/dist/thread/player/playerglobal/flash/globalization/LocaleID.js +144 -0
  220. package/dist/thread/player/playerglobal/flash/globalization/NumberFormatter.js +444 -0
  221. package/dist/thread/player/playerglobal/flash/globalization/NumberParseResult.js +22 -0
  222. package/dist/thread/player/playerglobal/flash/globalization/StringTools.js +59 -0
  223. package/dist/thread/player/playerglobal/flash/globalization/locale.js +190 -0
  224. package/dist/thread/player/playerglobal/flash/media/Camera.js +89 -0
  225. package/dist/thread/player/playerglobal/flash/media/Microphone.js +126 -0
  226. package/dist/thread/player/playerglobal/flash/media/Sound.js +543 -0
  227. package/dist/thread/player/playerglobal/flash/media/SoundMixer.js +74 -0
  228. package/dist/thread/player/playerglobal/flash/media/SoundTransform.js +40 -0
  229. package/dist/thread/player/playerglobal/flash/media/Video.js +43 -0
  230. package/dist/thread/player/playerglobal/flash/net/FileFilter.js +27 -0
  231. package/dist/thread/player/playerglobal/flash/net/FileReference.js +197 -0
  232. package/dist/thread/player/playerglobal/flash/net/LocalConnection.js +167 -0
  233. package/dist/thread/player/playerglobal/flash/net/NetConnection.js +155 -0
  234. package/dist/thread/player/playerglobal/flash/net/SharedObject.js +299 -0
  235. package/dist/thread/player/playerglobal/flash/net/Socket.js +282 -0
  236. package/dist/thread/player/playerglobal/flash/net/URLRequest.js +93 -0
  237. package/dist/thread/player/playerglobal/flash/net/URLStream.js +146 -0
  238. package/dist/thread/player/playerglobal/flash/net/XMLSocket.js +14 -0
  239. package/dist/thread/player/playerglobal/flash/net/local-modern.js +142 -0
  240. package/dist/thread/player/playerglobal/flash/net/local-values.js +217 -0
  241. package/dist/thread/player/playerglobal/flash/net/navigateToURL.js +29 -0
  242. package/dist/thread/player/playerglobal/flash/profiler/Telemetry.js +25 -0
  243. package/dist/thread/player/playerglobal/flash/sensors/Accelerometer.js +12 -0
  244. package/dist/thread/player/playerglobal/flash/system/ApplicationDomain.js +69 -0
  245. package/dist/thread/player/playerglobal/flash/system/Capabilities.js +163 -0
  246. package/dist/thread/player/playerglobal/flash/system/FSCommandHost.js +17 -0
  247. package/dist/thread/player/playerglobal/flash/system/Security.js +46 -0
  248. package/dist/thread/player/playerglobal/flash/system/SecurityDomain.js +21 -0
  249. package/dist/thread/player/playerglobal/flash/system/System.js +73 -0
  250. package/dist/thread/player/playerglobal/flash/system/Worker.js +112 -0
  251. package/dist/thread/player/playerglobal/flash/text/Font.js +95 -0
  252. package/dist/thread/player/playerglobal/flash/text/StaticText.js +16 -0
  253. package/dist/thread/player/playerglobal/flash/text/StyleSheet.js +65 -0
  254. package/dist/thread/player/playerglobal/flash/text/TextField.js +707 -0
  255. package/dist/thread/player/playerglobal/flash/text/TextRenderer.js +77 -0
  256. package/dist/thread/player/playerglobal/flash/text/engine/FontDescription.js +141 -0
  257. package/dist/thread/player/playerglobal/flash/text/engine/TabStop.js +46 -0
  258. package/dist/thread/player/playerglobal/flash/trace/Trace.js +17 -0
  259. package/dist/thread/player/playerglobal/flash/ui/ContextMenu.js +17 -0
  260. package/dist/thread/player/playerglobal/flash/ui/GameInput.js +19 -0
  261. package/dist/thread/player/playerglobal/flash/ui/Keyboard.js +27 -0
  262. package/dist/thread/player/playerglobal/flash/ui/Mouse.js +127 -0
  263. package/dist/thread/player/playerglobal/flash/ui/Multitouch.js +46 -0
  264. package/dist/thread/player/playerglobal/flash/utils/ByteArray.js +155 -0
  265. package/dist/thread/player/playerglobal/flash/utils/Timer.js +25 -0
  266. package/dist/thread/player/playerglobal/flash/xml/XMLDocument.js +74 -0
  267. package/dist/thread/player/playerglobal/index.js +224 -0
  268. package/dist/thread/player/playerglobal/libraries.js +10 -0
  269. package/dist/thread/player/playerglobal/playerglobal-library.js +22 -0
  270. package/dist/thread/player/playerglobal/toplevel.js +122 -0
  271. package/dist/thread/player/scripting/clipboard.js +146 -0
  272. package/dist/thread/player/scripting/code.js +900 -0
  273. package/dist/thread/player/scripting/evaluate.js +144 -0
  274. package/dist/thread/player/scripting/events.js +172 -0
  275. package/dist/thread/player/scripting/handover.js +182 -0
  276. package/dist/thread/player/scripting/lazy.js +38 -0
  277. package/dist/thread/player/scripting/lifecycle.js +272 -0
  278. package/dist/thread/player/scripting/loads.js +860 -0
  279. package/dist/thread/player/scripting/sha256.js +95 -0
  280. package/dist/thread/player/scripting/symbols.js +348 -0
  281. package/dist/thread/player/scripting/timers.js +434 -0
  282. package/dist/thread/player/scripting/workers.js +923 -0
  283. package/dist/thread/player/scripting.js +1018 -0
  284. package/dist/thread/player/stage.js +4 -0
  285. package/dist/thread/player/text/csm.js +113 -0
  286. package/dist/thread/player/text/css.js +167 -0
  287. package/dist/thread/player/text/fonts.js +97 -0
  288. package/dist/thread/player/text/layout.js +393 -0
  289. package/dist/thread/player/text/static.js +109 -0
  290. package/dist/thread/player/text/text.js +431 -0
  291. package/dist/thread/player/workers/thread.js +159 -0
  292. package/dist/thread/player/workers/wire.js +198 -0
  293. package/dist/thread/player-hosts/web-worker.js +19 -0
  294. package/dist/thread/runtime/avm1/activation.js +89 -0
  295. package/dist/thread/runtime/avm1/case.js +249 -0
  296. package/dist/thread/runtime/avm1/clips.js +334 -0
  297. package/dist/thread/runtime/avm1/control.js +280 -0
  298. package/dist/thread/runtime/avm1/errors.js +50 -0
  299. package/dist/thread/runtime/avm1/functions.js +249 -0
  300. package/dist/thread/runtime/avm1/globals/array.js +549 -0
  301. package/dist/thread/runtime/avm1/globals/broadcaster.js +131 -0
  302. package/dist/thread/runtime/avm1/globals/date.js +436 -0
  303. package/dist/thread/runtime/avm1/globals/global.js +344 -0
  304. package/dist/thread/runtime/avm1/globals/math.js +139 -0
  305. package/dist/thread/runtime/avm1/globals/number.js +93 -0
  306. package/dist/thread/runtime/avm1/globals/string.js +201 -0
  307. package/dist/thread/runtime/avm1/globals/timers.js +129 -0
  308. package/dist/thread/runtime/avm1/host.js +5 -0
  309. package/dist/thread/runtime/avm1/index.js +14 -0
  310. package/dist/thread/runtime/avm1/inheritance.js +132 -0
  311. package/dist/thread/runtime/avm1/numbers.js +298 -0
  312. package/dist/thread/runtime/avm1/objects.js +896 -0
  313. package/dist/thread/runtime/avm1/operators.js +170 -0
  314. package/dist/thread/runtime/avm1/realm.js +529 -0
  315. package/dist/thread/runtime/avm1/runtime.js +882 -0
  316. package/dist/thread/runtime/avm1/scope.js +385 -0
  317. package/dist/thread/runtime/avm1/urls.js +180 -0
  318. package/dist/thread/runtime/avm1/values.js +97 -0
  319. package/dist/thread/runtime/avm2/amf-classes.js +66 -0
  320. package/dist/thread/runtime/avm2/amf.js +801 -0
  321. package/dist/thread/runtime/avm2/array-conversion.js +100 -0
  322. package/dist/thread/runtime/avm2/builtin-library.js +21 -0
  323. package/dist/thread/runtime/avm2/cache-fill.js +86 -0
  324. package/dist/thread/runtime/avm2/classes.js +211 -0
  325. package/dist/thread/runtime/avm2/definitions.js +69 -0
  326. package/dist/thread/runtime/avm2/descriptors.js +5 -0
  327. package/dist/thread/runtime/avm2/dictionary-keys.js +295 -0
  328. package/dist/thread/runtime/avm2/domain-memory.js +75 -0
  329. package/dist/thread/runtime/avm2/domain.js +280 -0
  330. package/dist/thread/runtime/avm2/dynamic-properties.js +182 -0
  331. package/dist/thread/runtime/avm2/enumeration.js +393 -0
  332. package/dist/thread/runtime/avm2/errors.js +45 -0
  333. package/dist/thread/runtime/avm2/float-library.js +66 -0
  334. package/dist/thread/runtime/avm2/float.js +26 -0
  335. package/dist/thread/runtime/avm2/hooks.js +19 -0
  336. package/dist/thread/runtime/avm2/index.js +38 -0
  337. package/dist/thread/runtime/avm2/messages.js +177 -0
  338. package/dist/thread/runtime/avm2/method-factories.js +95 -0
  339. package/dist/thread/runtime/avm2/modules.js +105 -0
  340. package/dist/thread/runtime/avm2/names.js +248 -0
  341. package/dist/thread/runtime/avm2/natives/aliases.js +47 -0
  342. package/dist/thread/runtime/avm2/natives/array.js +390 -0
  343. package/dist/thread/runtime/avm2/natives/bytearray.js +1227 -0
  344. package/dist/thread/runtime/avm2/natives/case.js +88 -0
  345. package/dist/thread/runtime/avm2/natives/concurrent.js +199 -0
  346. package/dist/thread/runtime/avm2/natives/date.js +581 -0
  347. package/dist/thread/runtime/avm2/natives/define.js +130 -0
  348. package/dist/thread/runtime/avm2/natives/describe.js +351 -0
  349. package/dist/thread/runtime/avm2/natives/dictionary.js +12 -0
  350. package/dist/thread/runtime/avm2/natives/float-vector.js +81 -0
  351. package/dist/thread/runtime/avm2/natives/float.js +96 -0
  352. package/dist/thread/runtime/avm2/natives/index.js +64 -0
  353. package/dist/thread/runtime/avm2/natives/json.js +514 -0
  354. package/dist/thread/runtime/avm2/natives/number.js +162 -0
  355. package/dist/thread/runtime/avm2/natives/object.js +237 -0
  356. package/dist/thread/runtime/avm2/natives/proxy.js +75 -0
  357. package/dist/thread/runtime/avm2/natives/regexp.js +485 -0
  358. package/dist/thread/runtime/avm2/natives/shell-workers.js +404 -0
  359. package/dist/thread/runtime/avm2/natives/shell.js +557 -0
  360. package/dist/thread/runtime/avm2/natives/sort.js +377 -0
  361. package/dist/thread/runtime/avm2/natives/string.js +132 -0
  362. package/dist/thread/runtime/avm2/natives/sync.js +821 -0
  363. package/dist/thread/runtime/avm2/natives/toplevel.js +139 -0
  364. package/dist/thread/runtime/avm2/natives/vector-elements.js +46 -0
  365. package/dist/thread/runtime/avm2/natives/vector.js +406 -0
  366. package/dist/thread/runtime/avm2/natives/xml/access.js +633 -0
  367. package/dist/thread/runtime/avm2/natives/xml/build.js +291 -0
  368. package/dist/thread/runtime/avm2/natives/xml/chars.js +112 -0
  369. package/dist/thread/runtime/avm2/natives/xml/escape.js +38 -0
  370. package/dist/thread/runtime/avm2/natives/xml/names.js +204 -0
  371. package/dist/thread/runtime/avm2/natives/xml/node.js +272 -0
  372. package/dist/thread/runtime/avm2/natives/xml/operators.js +69 -0
  373. package/dist/thread/runtime/avm2/natives/xml/parser.js +356 -0
  374. package/dist/thread/runtime/avm2/natives/xml/strings.js +191 -0
  375. package/dist/thread/runtime/avm2/natives/xml/values.js +122 -0
  376. package/dist/thread/runtime/avm2/natives/xml/xml.js +645 -0
  377. package/dist/thread/runtime/avm2/number-strings.js +110 -0
  378. package/dist/thread/runtime/avm2/numbers.js +558 -0
  379. package/dist/thread/runtime/avm2/options.js +16 -0
  380. package/dist/thread/runtime/avm2/player-messages.js +550 -0
  381. package/dist/thread/runtime/avm2/property-cache.js +135 -0
  382. package/dist/thread/runtime/avm2/runtime.js +2644 -0
  383. package/dist/thread/runtime/avm2/traits.js +509 -0
  384. package/dist/thread/runtime/index.js +7 -0
  385. package/dist/web-worker.d.ts +2 -0
  386. package/dist/web-worker.d.ts.map +1 -0
  387. package/dist/web-worker.js +20 -0
  388. package/dist/web-worker.js.map +1 -0
  389. package/dist/websocket.d.ts +4 -0
  390. package/dist/websocket.d.ts.map +1 -0
  391. package/dist/websocket.js +27 -0
  392. package/dist/websocket.js.map +1 -0
  393. package/dist/workers.d.ts +35 -0
  394. package/dist/workers.d.ts.map +1 -0
  395. package/dist/workers.js +171 -0
  396. package/dist/workers.js.map +1 -0
  397. package/package.json +62 -3
  398. package/src/indexeddb.ts +227 -0
  399. package/src/node-worker.ts +13 -0
  400. package/src/node.ts +49 -0
  401. package/src/precompiled.ts +166 -0
  402. package/src/stage3d.ts +76 -0
  403. package/src/web-worker.ts +24 -0
  404. package/src/websocket.ts +32 -0
  405. package/src/workers.ts +255 -0
@@ -0,0 +1,272 @@
1
+ // E4X's tree, as avmplus' E4XNode: elements with their attributes, the
2
+ // namespaces they declare and their children; text, CDATA, comments,
3
+ // processing instructions and attributes with their values. Each node has
4
+ // its parent, and one XML object stands for it (see values.ts), so that XML
5
+ // values compare by the node they are.
6
+ //
7
+ // Translated from avmplus' core/E4XNode.cpp, this file is subject to the
8
+ // Mozilla Public License, v. 2.0: http://mozilla.org/MPL/2.0/.
9
+ import { NS_Public, prefixedNamespace, prefixOf, publicNs } from "../../names.js";
10
+ // The node kinds, as E4XNode's NodeTypes: bits, so a set of them is a mask.
11
+ export const ATTRIBUTE = 0x02;
12
+ export const TEXT = 0x04;
13
+ /** Text, written back as CDATA. */
14
+ export const CDATA = 0x08;
15
+ export const COMMENT = 0x10;
16
+ export const PROCESSING_INSTRUCTION = 0x20;
17
+ export const ELEMENT = 0x40;
18
+ export class XMLNode {
19
+ kind;
20
+ parent = null;
21
+ /** Its local name; null for a node without one (text, CDATA, a comment). */
22
+ name = null;
23
+ /** Its name's namespace, when it has a name: public for none. */
24
+ ns = publicNs;
25
+ /** The value of a node that is not an element. */
26
+ value = "";
27
+ /** An element's attributes, in order. */
28
+ attributes = [];
29
+ /** The namespaces an element declares. */
30
+ namespaces = [];
31
+ /** An element's children. */
32
+ children = [];
33
+ /** A function called on changes to an element, as setNotification sets it. */
34
+ notification = null;
35
+ /** The XML object that stands for this node, once made. */
36
+ object = null;
37
+ constructor(kind, value = "") {
38
+ this.kind = kind;
39
+ this.value = value;
40
+ }
41
+ /** As setQName: a name in no namespace, or the public one, is kept as public. */
42
+ setName(name, ns) {
43
+ this.name = name;
44
+ if (!ns || (ns.kind === NS_Public && ns.uri === "")) {
45
+ this.ns = publicNs;
46
+ }
47
+ else {
48
+ this.ns = ns;
49
+ }
50
+ }
51
+ /**
52
+ * As getQName: its name, if it has one; qualified unless public, which
53
+ * E4X then looks up in the default namespace too.
54
+ */
55
+ xname() {
56
+ if (this.name === null) {
57
+ return null;
58
+ }
59
+ return {
60
+ local: this.name,
61
+ namespaces: [this.ns],
62
+ attribute: this.kind === ATTRIBUTE,
63
+ qualified: this.ns !== publicNs,
64
+ };
65
+ }
66
+ /** As _append: `child` its last child. */
67
+ append(child) {
68
+ child.parent = this;
69
+ this.children.push(child);
70
+ }
71
+ /**
72
+ * As ElementE4XNode::_addInScopeNamespace: declare `ns` here, replacing
73
+ * one with its prefix but another URI; the name, and attributes', in a
74
+ * namespace with its prefix lose the prefix.
75
+ */
76
+ addInScopeNamespace(ns) {
77
+ if (this.kind !== ELEMENT || !ns || prefixOf(ns) === undefined) {
78
+ return;
79
+ }
80
+ const prefix = prefixOf(ns);
81
+ if (prefix === "" && this.name !== null && this.ns.uri === "") {
82
+ return;
83
+ }
84
+ let index = -1;
85
+ for (let i = 0; i < this.namespaces.length; i++) {
86
+ if (prefixOf(this.namespaces[i]) === prefix) {
87
+ index = i;
88
+ }
89
+ }
90
+ if (index !== -1 && this.namespaces[index].uri !== ns.uri) {
91
+ this.namespaces.splice(index, 1);
92
+ }
93
+ this.namespaces.push(ns);
94
+ if (this.name !== null && prefixOf(this.ns) === prefix) {
95
+ this.setName(this.name, prefixedNamespace(undefined, this.ns.uri ?? ""));
96
+ }
97
+ for (const attribute of this.attributes) {
98
+ if (attribute.name !== null && prefixOf(attribute.ns) === prefix) {
99
+ attribute.setName(attribute.name, prefixedNamespace(undefined, attribute.ns.uri ?? ""));
100
+ }
101
+ }
102
+ }
103
+ /**
104
+ * As FindMatchingNamespace: the index of a declared namespace with `ns`'s
105
+ * URI and, if it has one, its prefix; -1 if none, or if one with its URI
106
+ * has the empty prefix.
107
+ */
108
+ findMatchingNamespace(ns) {
109
+ for (let i = 0; i < this.namespaces.length; i++) {
110
+ const ns2 = this.namespaces[i];
111
+ if (ns2.uri === ns.uri) {
112
+ if (prefixOf(ns) === undefined) {
113
+ return i;
114
+ }
115
+ if (prefixOf(ns2) === "") {
116
+ return -1;
117
+ }
118
+ if (prefixOf(ns2) === prefixOf(ns)) {
119
+ return i;
120
+ }
121
+ }
122
+ }
123
+ return -1;
124
+ }
125
+ /**
126
+ * As BuildInScopeNamespaceList: the namespaces declared here and up the
127
+ * ancestors, the nearest first, each prefix (or, without one, URI) once.
128
+ */
129
+ inScopeNamespaces() {
130
+ const list = [];
131
+ for (let y = this; y; y = y.parent) {
132
+ for (const ns1 of y.namespaces) {
133
+ const p1 = prefixOf(ns1);
134
+ const seen = list.some((ns2) => p1 === undefined ? ns1.uri === ns2.uri : p1 === prefixOf(ns2));
135
+ if (!seen) {
136
+ list.push(ns1);
137
+ }
138
+ }
139
+ }
140
+ return list;
141
+ }
142
+ hasSimpleContent() {
143
+ if (this.kind & (COMMENT | PROCESSING_INSTRUCTION)) {
144
+ return false;
145
+ }
146
+ return !this.children.some((c) => c.kind === ELEMENT);
147
+ }
148
+ hasComplexContent() {
149
+ if (this.kind & (TEXT | COMMENT | PROCESSING_INSTRUCTION | ATTRIBUTE | CDATA)) {
150
+ return false;
151
+ }
152
+ return this.children.some((c) => c.kind === ELEMENT);
153
+ }
154
+ /** Its index among its parent's children, or -1 for none or an attribute. */
155
+ childIndex() {
156
+ if (!this.parent || this.kind === ATTRIBUTE) {
157
+ return -1;
158
+ }
159
+ return this.parent.children.indexOf(this);
160
+ }
161
+ nodeKind() {
162
+ switch (this.kind) {
163
+ case ATTRIBUTE:
164
+ return "attribute";
165
+ case TEXT:
166
+ case CDATA:
167
+ return "text";
168
+ case COMMENT:
169
+ return "comment";
170
+ case PROCESSING_INSTRUCTION:
171
+ return "processing-instruction";
172
+ default:
173
+ return "element";
174
+ }
175
+ }
176
+ /** As _deleteByIndex: child i removed, no longer its child. */
177
+ deleteByIndex(i) {
178
+ if (i >= 0 && i < this.children.length) {
179
+ const child = this.children[i];
180
+ if (child) {
181
+ child.parent = null;
182
+ }
183
+ this.children.splice(i, 1);
184
+ }
185
+ }
186
+ /**
187
+ * As _deepCopy: a copy of this node and all below it, with no parent;
188
+ * comments and processing instructions the settings ignore left out.
189
+ */
190
+ deepCopy(ignoreComments, ignoreProcessingInstructions) {
191
+ const x = new XMLNode(this.kind, this.value);
192
+ if (this.name !== null) {
193
+ x.setName(this.name, this.ns);
194
+ }
195
+ if (this.kind === ELEMENT) {
196
+ x.namespaces.push(...this.namespaces);
197
+ for (const a of this.attributes) {
198
+ const b = a.deepCopy(ignoreComments, ignoreProcessingInstructions);
199
+ b.parent = x;
200
+ x.attributes.push(b);
201
+ }
202
+ for (const child of this.children) {
203
+ if ((child.kind === COMMENT && ignoreComments) ||
204
+ (child.kind === PROCESSING_INSTRUCTION && ignoreProcessingInstructions)) {
205
+ continue;
206
+ }
207
+ const c = child.deepCopy(ignoreComments, ignoreProcessingInstructions);
208
+ c.parent = x;
209
+ x.children.push(c);
210
+ }
211
+ }
212
+ return x;
213
+ }
214
+ /**
215
+ * As _equals: the same kind, name, attributes, value and children. The
216
+ * namespaces declared are not compared: those that matter are in names.
217
+ */
218
+ equals(v) {
219
+ if (this === v) {
220
+ return true;
221
+ }
222
+ if (this.kind !== v.kind) {
223
+ return false;
224
+ }
225
+ const name = this.xname();
226
+ if (name ? v.name === null || !matches(name, v) : v.name !== null) {
227
+ return false;
228
+ }
229
+ if (this.attributes.length !== v.attributes.length ||
230
+ this.children.length !== v.children.length ||
231
+ this.value !== v.value) {
232
+ return false;
233
+ }
234
+ for (const a1 of this.attributes) {
235
+ if (!v.attributes.some((a2) => a1.equals(a2))) {
236
+ return false;
237
+ }
238
+ }
239
+ for (let i = 0; i < this.children.length; i++) {
240
+ if (!this.children[i].equals(v.children[i])) {
241
+ return false;
242
+ }
243
+ }
244
+ return true;
245
+ }
246
+ }
247
+ /**
248
+ * As Multiname::matches: whether `name` names `node`. With a name, the
249
+ * node is an attribute if the name names attributes; an unqualified any
250
+ * name matches every node, one without a name too; otherwise the local
251
+ * names are the same, and the node's namespace is one of the name's, by
252
+ * URI and kind, if the name is not in any namespace.
253
+ */
254
+ export function matches(name, node) {
255
+ const named = node !== null && node.name !== null;
256
+ if (named && name.attribute !== (node.kind === ATTRIBUTE)) {
257
+ return false;
258
+ }
259
+ if (name.local === null && !name.qualified) {
260
+ return true;
261
+ }
262
+ if (!named) {
263
+ return false;
264
+ }
265
+ if (name.local !== null && name.local !== node.name) {
266
+ return false;
267
+ }
268
+ if (name.namespaces === null) {
269
+ return true;
270
+ }
271
+ return name.namespaces.some((ns) => ns.uri === node.ns.uri && ns.kind === node.ns.kind);
272
+ }
@@ -0,0 +1,69 @@
1
+ // E4X's operators on XML and XMLList: == and +.
2
+ //
3
+ // Translated from avmplus' core/XMLObject.cpp, XMLListObject.cpp and E4X's
4
+ // parts of AvmCore.cpp, this file is subject to the Mozilla Public License,
5
+ // v. 2.0: http://mozilla.org/MPL/2.0/.
6
+ import { ATTRIBUTE, CDATA, TEXT } from "./node.js";
7
+ import { xmlToString } from "./strings.js";
8
+ import { append, isList, isXML, newList, xmlOf } from "./values.js";
9
+ // Equality and +.
10
+ /** As XMLListObject::_equals. */
11
+ function listEquals(rt, list, v) {
12
+ const nodes = list.$nodes;
13
+ if (v === undefined && nodes.length === 0) {
14
+ return true;
15
+ }
16
+ if (isList(v)) {
17
+ const other = v.$nodes;
18
+ if (nodes.length !== other.length) {
19
+ return false;
20
+ }
21
+ for (let i = 0; i < nodes.length; i++) {
22
+ if (nodes[i] !== other[i] && !rt.equals(xmlOf(rt, nodes[i]), xmlOf(rt, other[i]))) {
23
+ return false;
24
+ }
25
+ }
26
+ return true;
27
+ }
28
+ if (nodes.length === 1) {
29
+ return rt.equals(xmlOf(rt, nodes[0]), v);
30
+ }
31
+ return false;
32
+ }
33
+ /** E4X's == (11.5.1) where either side is XML or an XMLList, else undefined. */
34
+ export function equals(rt, a, b) {
35
+ if (isList(a)) {
36
+ return listEquals(rt, a, b);
37
+ }
38
+ if (isList(b)) {
39
+ return listEquals(rt, b, a);
40
+ }
41
+ if (isXML(a) && isXML(b)) {
42
+ const x = a.$node;
43
+ const y = b.$node;
44
+ if ((x.kind & (TEXT | CDATA | ATTRIBUTE) && y.hasSimpleContent()) ||
45
+ (y.kind & (TEXT | CDATA | ATTRIBUTE) && x.hasSimpleContent())) {
46
+ return xmlToString(rt, x) === xmlToString(rt, y);
47
+ }
48
+ return x.equals(y);
49
+ }
50
+ const xml = isXML(a) ? a : b;
51
+ const other = xml === a ? b : a;
52
+ if (other === null || other === undefined) {
53
+ return false;
54
+ }
55
+ if (xml.$node.hasSimpleContent() && !(typeof other === "object" && other.$traits?.properties)) {
56
+ return xmlToString(rt, xml.$node) === rt.toString(other);
57
+ }
58
+ return undefined;
59
+ }
60
+ /** E4X's + (11.4.1): XML and XMLLists into one XMLList. */
61
+ export function add(rt, a, b) {
62
+ if ((isXML(a) || isList(a)) && (isXML(b) || isList(b))) {
63
+ const list = newList(rt);
64
+ append(list, a);
65
+ append(list, b);
66
+ return list;
67
+ }
68
+ return undefined;
69
+ }
@@ -0,0 +1,356 @@
1
+ // XML text into tags, as avmplus' XMLParser: a tokenizer, not a validating
2
+ // parser, whose leniency and errors are avmplus', which E4X's are. The tree
3
+ // is made from its tags in build.ts.
4
+ //
5
+ // Translated from avmplus' core/XMLParser16.cpp, this file is subject to the
6
+ // Mozilla Public License, v. 2.0: http://mozilla.org/MPL/2.0/.
7
+ import { isSpace } from "./chars.js";
8
+ // The tags, as XMLTag's node types.
9
+ export const TAG_ELEMENT = 1;
10
+ export const TAG_TEXT = 3;
11
+ export const TAG_CDATA = 4;
12
+ export const TAG_PROCESSING_INSTRUCTION = 7;
13
+ export const TAG_COMMENT = 8;
14
+ export const TAG_DOCTYPE = 10;
15
+ export const TAG_XML_DECLARATION = 13;
16
+ // What getNext gives, as XMLParser's status codes: a tag, the end, or the
17
+ // error E4X throws for each (see PARSE_ERRORS in values.ts).
18
+ export const OK = 0;
19
+ export const END = -1;
20
+ export const UNTERMINATED_CDATA = -2;
21
+ export const UNTERMINATED_XML_DECLARATION = -3;
22
+ export const UNTERMINATED_DOCTYPE = -4;
23
+ export const UNTERMINATED_COMMENT = -5;
24
+ export const MALFORMED_ELEMENT = -6;
25
+ export const UNTERMINATED_ATTRIBUTE_VALUE = -8;
26
+ export const UNTERMINATED_PROCESSING_INSTRUCTION = -10;
27
+ export class XMLTag {
28
+ type = 0;
29
+ /** An element's name (with "/" first for an end tag), or the text of any other tag. */
30
+ text = "";
31
+ /** Whether an element closed itself, as <a/>. */
32
+ empty = false;
33
+ /** An element's attributes, name then value. */
34
+ attributes = [];
35
+ reset() {
36
+ this.type = 0;
37
+ this.text = "";
38
+ this.empty = false;
39
+ this.attributes = [];
40
+ }
41
+ }
42
+ /** The entities XMLParser knows: the XML ones, and nbsp. */
43
+ const ENTITIES = {
44
+ amp: "&",
45
+ quot: '"',
46
+ apos: "'",
47
+ lt: "<",
48
+ gt: ">",
49
+ nbsp: "\u00a0",
50
+ };
51
+ export class XMLParser {
52
+ pos = 0;
53
+ ignoreWhite = false;
54
+ condenseWhite = false;
55
+ text;
56
+ constructor(text) {
57
+ this.text = text;
58
+ }
59
+ /** As XMLParser::parse: from the start, whitespace-only text left out if `ignoreWhite`. */
60
+ parse(ignoreWhite) {
61
+ this.pos = 0;
62
+ this.ignoreWhite = ignoreWhite;
63
+ }
64
+ setCondenseWhite(condense) {
65
+ this.condenseWhite = condense;
66
+ }
67
+ atEnd() {
68
+ return this.pos >= this.text.length;
69
+ }
70
+ /** Past whitespace: false at the end. */
71
+ skipWhiteSpace() {
72
+ while (!this.atEnd() && isSpace(this.text.charCodeAt(this.pos))) {
73
+ this.pos++;
74
+ }
75
+ return !this.atEnd();
76
+ }
77
+ /** Whether the text at `at` starts with `s`, ignoring ASCII case, as matchesLatin1_caseless. */
78
+ matchesCaseless(s, at) {
79
+ return this.text.slice(at, at + s.length).toLowerCase() === s.toLowerCase();
80
+ }
81
+ /** The next tag into `tag`: OK, END, or an error. */
82
+ getNext(tag) {
83
+ const str = this.text;
84
+ tag.reset();
85
+ if (this.atEnd()) {
86
+ return END;
87
+ }
88
+ // With ignoreWhite, no text nodes of whitespace alone.
89
+ if (this.ignoreWhite && !this.skipWhiteSpace()) {
90
+ return END;
91
+ }
92
+ let start = this.pos;
93
+ if (str[this.pos] !== "<") {
94
+ // Text, up to the next < or the end.
95
+ let next = str.indexOf("<", this.pos + 1);
96
+ if (next < 0) {
97
+ next = str.length;
98
+ }
99
+ this.pos = next;
100
+ tag.text = this.unescape(start, next);
101
+ if (this.ignoreWhite && this.condenseWhite) {
102
+ tag.text = trimWhitespace(tag.text);
103
+ }
104
+ tag.type = TAG_TEXT;
105
+ return OK;
106
+ }
107
+ if (this.matchesCaseless("<?xml ", start)) {
108
+ const end = str.indexOf("?>", start + 6);
109
+ if (end >= 0) {
110
+ tag.text = str.slice(start + 2, end);
111
+ this.pos = end + 2;
112
+ tag.type = TAG_XML_DECLARATION;
113
+ return OK;
114
+ }
115
+ return UNTERMINATED_XML_DECLARATION;
116
+ }
117
+ if (this.matchesCaseless("<!DOCTYPE", start)) {
118
+ // Up to its >, past any <...> within it.
119
+ let depth = 0;
120
+ let end = start + 1;
121
+ while (!this.atEnd()) {
122
+ const ch = str[end++];
123
+ if (ch === "<") {
124
+ depth++;
125
+ }
126
+ else if (ch === ">") {
127
+ if (!depth) {
128
+ tag.text = str.slice(start, end);
129
+ tag.type = TAG_DOCTYPE;
130
+ this.pos = end;
131
+ return OK;
132
+ }
133
+ depth--;
134
+ }
135
+ this.pos = end;
136
+ }
137
+ return UNTERMINATED_DOCTYPE;
138
+ }
139
+ if (this.matchesCaseless("<![CDATA[", start)) {
140
+ start += 9;
141
+ const end = str.indexOf("]]>", start);
142
+ if (end >= 0) {
143
+ tag.text = str.slice(start, end);
144
+ tag.type = TAG_CDATA;
145
+ this.pos = end + 3;
146
+ return OK;
147
+ }
148
+ return UNTERMINATED_CDATA;
149
+ }
150
+ if (str.startsWith("<?", start)) {
151
+ start += 2;
152
+ const end = str.indexOf("?>", start);
153
+ if (end >= 0) {
154
+ tag.text = str.slice(start, end);
155
+ tag.type = TAG_PROCESSING_INSTRUCTION;
156
+ this.pos = end + 2;
157
+ return OK;
158
+ }
159
+ return UNTERMINATED_PROCESSING_INSTRUCTION;
160
+ }
161
+ start = ++this.pos;
162
+ if (str.startsWith("!--", start)) {
163
+ start += 3;
164
+ const end = str.indexOf("-->", start);
165
+ if (end >= 0) {
166
+ tag.text = str.slice(start, end);
167
+ tag.type = TAG_COMMENT;
168
+ this.pos = end + 3;
169
+ return OK;
170
+ }
171
+ return UNTERMINATED_COMMENT;
172
+ }
173
+ // An element: its name, up to >, whitespace or />.
174
+ start = this.pos;
175
+ while (!this.atEnd()) {
176
+ const ch = str[this.pos];
177
+ if (ch === ">" || isSpace(ch.charCodeAt(0))) {
178
+ break;
179
+ }
180
+ if (ch === "/" && this.pos < str.length - 1 && str[this.pos + 1] === ">") {
181
+ break;
182
+ }
183
+ this.pos++;
184
+ }
185
+ if (this.atEnd() || this.pos === start) {
186
+ return MALFORMED_ELEMENT;
187
+ }
188
+ tag.text = this.unescape(start, this.pos);
189
+ tag.type = TAG_ELEMENT;
190
+ // Its attributes.
191
+ let ch = "";
192
+ for (;;) {
193
+ if (!this.skipWhiteSpace()) {
194
+ return MALFORMED_ELEMENT;
195
+ }
196
+ ch = str[this.pos];
197
+ if (ch === ">") {
198
+ break;
199
+ }
200
+ if (ch === "/" && this.pos < str.length - 1 && str[this.pos + 1] === ">") {
201
+ tag.empty = true;
202
+ ch = str[++this.pos];
203
+ break;
204
+ }
205
+ start = this.pos;
206
+ while (!isSpace(ch.charCodeAt(0)) && ch !== "=" && ch !== ">") {
207
+ this.pos++;
208
+ if (this.atEnd()) {
209
+ return MALFORMED_ELEMENT;
210
+ }
211
+ ch = str[this.pos];
212
+ }
213
+ if (start === this.pos) {
214
+ return MALFORMED_ELEMENT;
215
+ }
216
+ const name = this.unescape(start, this.pos);
217
+ if (!this.skipWhiteSpace()) {
218
+ return MALFORMED_ELEMENT;
219
+ }
220
+ if (str[this.pos++] !== "=") {
221
+ return MALFORMED_ELEMENT;
222
+ }
223
+ if (!this.skipWhiteSpace()) {
224
+ return MALFORMED_ELEMENT;
225
+ }
226
+ const delimiter = str[this.pos++];
227
+ if (delimiter !== '"' && delimiter !== "'") {
228
+ return MALFORMED_ELEMENT;
229
+ }
230
+ // Up to the closing quote; < is not allowed within.
231
+ start = this.pos;
232
+ ch = "";
233
+ while (ch !== delimiter) {
234
+ if (this.atEnd() || ch === "<") {
235
+ return UNTERMINATED_ATTRIBUTE_VALUE;
236
+ }
237
+ ch = str[this.pos++];
238
+ }
239
+ tag.attributes.push(name, this.unescape(start, this.pos - 1));
240
+ }
241
+ if (ch === ">") {
242
+ this.pos++;
243
+ }
244
+ return OK;
245
+ }
246
+ /**
247
+ * As XMLParser::unescape: [start, last) with its entity and character
248
+ * references decoded: &#dd; and &#xhh; up to 0xFFFF, and ENTITIES. An &
249
+ * without a ; ends the decoding; one that is not a known reference is
250
+ * kept as it is.
251
+ */
252
+ unescape(start, last) {
253
+ const str = this.text;
254
+ if (start === last) {
255
+ return "";
256
+ }
257
+ let bgn = str.indexOf("&", start);
258
+ if (bgn < 0 || bgn >= last) {
259
+ return str.slice(start, last);
260
+ }
261
+ let dest = "";
262
+ let end = start;
263
+ while (bgn >= start && bgn < last) {
264
+ const ampBgn = bgn;
265
+ const ampEnd = str.indexOf(";", ++bgn);
266
+ if (ampEnd < 0 || ampEnd >= last) {
267
+ break;
268
+ }
269
+ dest += str.slice(end, bgn - 1);
270
+ end = ampEnd;
271
+ let len = end - bgn;
272
+ let ok = true;
273
+ if (len >= 2) {
274
+ if (str[bgn] === "#") {
275
+ let ch = str.charCodeAt(++bgn);
276
+ len--;
277
+ let base = 10;
278
+ if (len >= 2 && ch === 0x78) {
279
+ base = 16;
280
+ bgn++;
281
+ len--;
282
+ }
283
+ if (len > 0) {
284
+ let value = 0;
285
+ while (len-- && ok) {
286
+ ch = str.charCodeAt(bgn++);
287
+ if (ch >= 0x41 && ch <= 0x46) {
288
+ ch -= 7;
289
+ }
290
+ else if (ch >= 0x61 && ch <= 0x66) {
291
+ ch -= 0x61 - 0x41 + 7;
292
+ }
293
+ ch -= 0x30;
294
+ if (ch >= 0 && ch < base) {
295
+ value = value * base + ch;
296
+ }
297
+ else {
298
+ ok = false;
299
+ }
300
+ if (value > 0xffff) {
301
+ ok = false;
302
+ }
303
+ }
304
+ if (ok) {
305
+ dest += String.fromCharCode(value);
306
+ bgn = ++end;
307
+ }
308
+ }
309
+ }
310
+ else if (len <= 4) {
311
+ const entity = ENTITIES[str.slice(bgn, end)];
312
+ if (entity !== undefined && Object.hasOwn(ENTITIES, str.slice(bgn, end))) {
313
+ dest += entity;
314
+ bgn = ++end;
315
+ }
316
+ else {
317
+ ok = false;
318
+ }
319
+ }
320
+ else {
321
+ ok = false;
322
+ }
323
+ }
324
+ else {
325
+ ok = false;
326
+ }
327
+ if (!ok) {
328
+ // Kept as it is, rather than dropped, which would break content.
329
+ bgn = end + 1;
330
+ if (ampBgn < end) {
331
+ dest += str.slice(ampBgn, end);
332
+ }
333
+ }
334
+ bgn = str.indexOf("&", bgn);
335
+ if (bgn >= last) {
336
+ bgn = -1;
337
+ }
338
+ }
339
+ if (end < last) {
340
+ dest += str.slice(end, last);
341
+ }
342
+ return dest;
343
+ }
344
+ }
345
+ /** As _condenseWhitespace: `s` without leading and trailing whitespace. */
346
+ function trimWhitespace(s) {
347
+ let start = 0;
348
+ while (start < s.length && isSpace(s.charCodeAt(start))) {
349
+ start++;
350
+ }
351
+ let end = s.length - 1;
352
+ while (end > start && isSpace(s.charCodeAt(end))) {
353
+ end--;
354
+ }
355
+ return s.slice(start, end + 1);
356
+ }