@swf2es/player-hosts 0.0.0-stage → 0.1.1

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,407 @@
1
+ export const MOVE = 1;
2
+ export const LINE = 2;
3
+ export const CURVE = 3;
4
+ export const CUBIC = 4;
5
+ /** How many points a command takes. */
6
+ export function pointsOf(command) {
7
+ return command === CUBIC ? 3 : command === CURVE ? 2 : 1;
8
+ }
9
+ /** The path as a polygon's points, x y x y..., its curves as eight chords each. */
10
+ export function flatten(path) {
11
+ const points = [];
12
+ let x = 0;
13
+ let y = 0;
14
+ for (let i = 0; i < path.length;) {
15
+ const command = path[i];
16
+ if (command === CUBIC) {
17
+ const [c1x, c1y, c2x, c2y, ax, ay] = path.slice(i + 1, i + 7);
18
+ for (let k = 1; k <= 8; k++) {
19
+ const t = k / 8;
20
+ const u = 1 - t;
21
+ points.push(u * u * u * x + 3 * u * u * t * c1x + 3 * u * t * t * c2x + t * t * t * ax, u * u * u * y + 3 * u * u * t * c1y + 3 * u * t * t * c2y + t * t * t * ay);
22
+ }
23
+ x = ax;
24
+ y = ay;
25
+ i += 7;
26
+ }
27
+ else if (command === CURVE) {
28
+ const [cx, cy, ax, ay] = path.slice(i + 1, i + 5);
29
+ for (let k = 1; k <= 8; k++) {
30
+ const t = k / 8;
31
+ const u = 1 - t;
32
+ points.push(u * u * x + 2 * u * t * cx + t * t * ax, u * u * y + 2 * u * t * cy + t * t * ay);
33
+ }
34
+ x = ax;
35
+ y = ay;
36
+ i += 5;
37
+ }
38
+ else {
39
+ x = path[i + 1];
40
+ y = path[i + 2];
41
+ points.push(x, y);
42
+ i += 3;
43
+ }
44
+ }
45
+ return points;
46
+ }
47
+ /** Whether (px, py) is inside the polygon, by the even-odd rule. */
48
+ export function inside(points, px, py) {
49
+ let hit = false;
50
+ for (let i = 0, j = points.length - 2; i < points.length; j = i, i += 2) {
51
+ const xi = points[i];
52
+ const yi = points[i + 1];
53
+ const xj = points[j];
54
+ const yj = points[j + 1];
55
+ if (yi > py !== yj > py && px < ((xj - xi) * (py - yi)) / (yj - yi) + xi) {
56
+ hit = !hit;
57
+ }
58
+ }
59
+ return hit;
60
+ }
61
+ /**
62
+ * The path's extent, each curve at its true extremes, as [xMin, yMin,
63
+ * xMax, yMax]; null for a path with no points.
64
+ */
65
+ export function extent(path) {
66
+ let xMin = Number.POSITIVE_INFINITY;
67
+ let yMin = Number.POSITIVE_INFINITY;
68
+ let xMax = Number.NEGATIVE_INFINITY;
69
+ let yMax = Number.NEGATIVE_INFINITY;
70
+ const take = (x, y) => {
71
+ xMin = Math.min(xMin, x);
72
+ yMin = Math.min(yMin, y);
73
+ xMax = Math.max(xMax, x);
74
+ yMax = Math.max(yMax, y);
75
+ };
76
+ let x = 0;
77
+ let y = 0;
78
+ for (let i = 0; i < path.length;) {
79
+ const command = path[i];
80
+ if (command === MOVE) {
81
+ // A move alone has no extent: the pen's place counts once a segment leaves it.
82
+ x = path[i + 1];
83
+ y = path[i + 2];
84
+ i += 3;
85
+ continue;
86
+ }
87
+ take(x, y);
88
+ if (command === CURVE) {
89
+ const [cx, cy, ax, ay] = path.slice(i + 1, i + 5);
90
+ take(ax, ay);
91
+ // Where the derivative is zero on either axis, if within the curve.
92
+ const at = (t) => {
93
+ const u = 1 - t;
94
+ take(u * u * x + 2 * u * t * cx + t * t * ax, u * u * y + 2 * u * t * cy + t * t * ay);
95
+ };
96
+ for (const [p0, c, p2] of [
97
+ [x, cx, ax],
98
+ [y, cy, ay],
99
+ ]) {
100
+ const denominator = p0 - 2 * c + p2;
101
+ const t = denominator === 0 ? -1 : (p0 - c) / denominator;
102
+ if (t > 0 && t < 1) {
103
+ at(t);
104
+ }
105
+ }
106
+ x = ax;
107
+ y = ay;
108
+ i += 5;
109
+ }
110
+ else if (command === CUBIC) {
111
+ const [c1x, c1y, c2x, c2y, ax, ay] = path.slice(i + 1, i + 7);
112
+ take(ax, ay);
113
+ const at = (t) => {
114
+ const u = 1 - t;
115
+ take(u * u * u * x + 3 * u * u * t * c1x + 3 * u * t * t * c2x + t * t * t * ax, u * u * u * y + 3 * u * u * t * c1y + 3 * u * t * t * c2y + t * t * t * ay);
116
+ };
117
+ for (const [p0, c1, c2, p3] of [
118
+ [x, c1x, c2x, ax],
119
+ [y, c1y, c2y, ay],
120
+ ]) {
121
+ // The derivative's roots: a t² + b t + c = 0.
122
+ const a = -p0 + 3 * c1 - 3 * c2 + p3;
123
+ const b = 2 * (p0 - 2 * c1 + c2);
124
+ const c = c1 - p0;
125
+ const roots = a === 0 ? (b === 0 ? [] : [-c / b]) : quadraticRoots(a, b, c);
126
+ for (const t of roots) {
127
+ if (t > 0 && t < 1) {
128
+ at(t);
129
+ }
130
+ }
131
+ }
132
+ x = ax;
133
+ y = ay;
134
+ i += 7;
135
+ }
136
+ else {
137
+ x = path[i + 1];
138
+ y = path[i + 2];
139
+ take(x, y);
140
+ i += 3;
141
+ }
142
+ }
143
+ return xMin <= xMax ? [xMin, yMin, xMax, yMax] : null;
144
+ }
145
+ function quadraticRoots(a, b, c) {
146
+ const d = b * b - 4 * a * c;
147
+ if (d < 0) {
148
+ return [];
149
+ }
150
+ const s = Math.sqrt(d);
151
+ return [(-b + s) / (2 * a), (-b - s) / (2 * a)];
152
+ }
153
+ /** Layers as they draw mirrored, as of a version: the renderer and the hit tests ask on each redraw. */
154
+ const mirroredLayers = new WeakMap();
155
+ /**
156
+ * `layers` as they draw where a transform turns them over (`mirrored`),
157
+ * each culled drawTriangles' the triangles it keeps there. `version` is the
158
+ * drawing's, whose layers change in place.
159
+ */
160
+ export function facing(layers, mirrored, version = 0) {
161
+ if (!mirrored || !layers.some((layer) => layer.mirrored)) {
162
+ return layers;
163
+ }
164
+ const kept = mirroredLayers.get(layers);
165
+ if (kept?.version === version) {
166
+ return kept.layers;
167
+ }
168
+ const made = layers.map((layer) => {
169
+ const parts = layer.mirrored;
170
+ if (!parts) {
171
+ return layer;
172
+ }
173
+ // The triangles' line is the layer's first; a line set after them goes on in it.
174
+ const rest = layer.strokes.filter((s) => !s.triangles);
175
+ return {
176
+ fills: parts.fills,
177
+ strokes: parts.stroke ? [parts.stroke, ...rest] : rest,
178
+ meshes: parts.meshes,
179
+ extent: layer.extent,
180
+ };
181
+ });
182
+ mirroredLayers.set(layers, { version, layers: made });
183
+ return made;
184
+ }
185
+ /** The polygon's orientation: 1 clockwise on a y-down screen, -1 the other way, 0 for no area. */
186
+ export function orientation(points) {
187
+ let area = 0;
188
+ for (let i = 0, j = points.length - 2; i < points.length; j = i, i += 2) {
189
+ area += points[j] * points[i + 1] - points[i] * points[j + 1];
190
+ }
191
+ return Math.sign(area);
192
+ }
193
+ const TWIPS = 20;
194
+ function reversed(e) {
195
+ return { x0: e.x1, y0: e.y1, cx: e.cx, cy: e.cy, x1: e.x0, y1: e.y0 };
196
+ }
197
+ /** Each fill's edges joined into contours: from an edge, the next one that starts where it ends. */
198
+ function contours(edges) {
199
+ let minX = Infinity;
200
+ let minY = Infinity;
201
+ let maxX = -Infinity;
202
+ let maxY = -Infinity;
203
+ let numeric = true;
204
+ for (const e of edges) {
205
+ if (!Number.isSafeInteger(e.x0) ||
206
+ !Number.isSafeInteger(e.y0) ||
207
+ !Number.isSafeInteger(e.x1) ||
208
+ !Number.isSafeInteger(e.y1)) {
209
+ numeric = false;
210
+ break;
211
+ }
212
+ minX = Math.min(minX, e.x0, e.x1);
213
+ minY = Math.min(minY, e.y0, e.y1);
214
+ maxX = Math.max(maxX, e.x0, e.x1);
215
+ maxY = Math.max(maxY, e.y0, e.y1);
216
+ }
217
+ const height = maxY - minY + 1;
218
+ // Integer coordinates fit one exact numeric key only while the whole grid fits a safe integer.
219
+ numeric &&= Number.isSafeInteger((maxX - minX + 1) * height);
220
+ const key = (x, y) => numeric ? (x - minX) * height + (y - minY) : `${x},${y}`;
221
+ const from = new Map();
222
+ // Links are index + 1, leaving zero for the end; reverse insertion preserves record order.
223
+ const next = new Uint32Array(edges.length);
224
+ for (let i = edges.length - 1; i >= 0; i--) {
225
+ const e = edges[i];
226
+ const at = key(e.x0, e.y0);
227
+ next[i] = from.get(at) ?? 0;
228
+ from.set(at, i + 1);
229
+ }
230
+ const used = new Uint8Array(edges.length);
231
+ const paths = [];
232
+ for (let first = 0; first < edges.length; first++) {
233
+ if (used[first]) {
234
+ continue;
235
+ }
236
+ const start = edges[first];
237
+ const path = [MOVE, start.x0 / TWIPS, start.y0 / TWIPS];
238
+ let e = start;
239
+ let i = first;
240
+ for (;;) {
241
+ used[i] = 1;
242
+ if (Number.isNaN(e.cx)) {
243
+ path.push(LINE, e.x1 / TWIPS, e.y1 / TWIPS);
244
+ }
245
+ else {
246
+ path.push(CURVE, e.cx / TWIPS, e.cy / TWIPS, e.x1 / TWIPS, e.y1 / TWIPS);
247
+ }
248
+ if (e.x1 === start.x0 && e.y1 === start.y0) {
249
+ break;
250
+ }
251
+ const at = key(e.x1, e.y1);
252
+ let candidate = from.get(at) ?? 0;
253
+ while (candidate !== 0 && used[candidate - 1]) {
254
+ candidate = next[candidate - 1];
255
+ }
256
+ if (candidate === 0) {
257
+ from.delete(at);
258
+ break;
259
+ }
260
+ from.set(at, next[candidate - 1]);
261
+ i = candidate - 1;
262
+ e = edges[i];
263
+ }
264
+ paths.push(path);
265
+ }
266
+ return paths;
267
+ }
268
+ /** The layers a shape draws, in order: each layer's fills, then its lines. */
269
+ export function shapeLayers(shape, bitmap = () => null) {
270
+ const layers = [];
271
+ // A bitmap fill's bitmap, its matrix from twips to pixels; one the SWF lacks stays the SWF's fill.
272
+ const paint = (fill) => {
273
+ if (fill.type === "linear" || fill.type === "radial" || fill.type === "focal") {
274
+ const g = fill.gradient;
275
+ const m = g.matrix;
276
+ return {
277
+ type: "gradient",
278
+ radial: fill.type !== "linear",
279
+ focal: fill.type === "focal" ? g.focal : 0,
280
+ stops: g.stops.slice(0, 16),
281
+ spread: g.spread <= 2 ? g.spread : 0,
282
+ linearRgb: g.interpolation === 1,
283
+ // The square is in twips as the shape is, so only the translation goes to pixels.
284
+ matrix: { a: m.a, b: m.b, c: m.c, d: m.d, tx: m.tx / 20, ty: m.ty / 20 },
285
+ };
286
+ }
287
+ const image = fill.type === "bitmap" ? bitmap(fill.bitmap) : null;
288
+ if (fill.type !== "bitmap" || !image) {
289
+ return fill;
290
+ }
291
+ const m = fill.matrix;
292
+ return {
293
+ type: "image",
294
+ image,
295
+ matrix: { a: m.a / 20, b: m.b / 20, c: m.c / 20, d: m.d / 20, tx: m.tx / 20, ty: m.ty / 20 },
296
+ repeat: fill.repeat,
297
+ smooth: fill.smooth,
298
+ };
299
+ };
300
+ let fills = shape.fills.map(paint);
301
+ let lines = shape.lines;
302
+ let fillEdges = fills.map(() => []);
303
+ let strokes = lines.map(() => []);
304
+ let fill0 = 0;
305
+ let fill1 = 0;
306
+ let line = 0;
307
+ let x = 0;
308
+ let y = 0;
309
+ // The stroke being extended, and where it ends.
310
+ let stroke = null;
311
+ let strokeX = Number.NaN;
312
+ let strokeY = Number.NaN;
313
+ const flush = () => {
314
+ const layer = { fills: [], strokes: [] };
315
+ for (const [i, fill] of fills.entries()) {
316
+ if (fillEdges[i].length) {
317
+ layer.fills.push({ fill, contours: contours(fillEdges[i]), winding: "evenOdd" });
318
+ }
319
+ }
320
+ for (const [i, l] of lines.entries()) {
321
+ if (strokes[i].length) {
322
+ layer.strokes.push({ line: l, paths: strokes[i] });
323
+ }
324
+ }
325
+ if (layer.fills.length || layer.strokes.length) {
326
+ layers.push(layer);
327
+ }
328
+ };
329
+ const edge = (e) => {
330
+ // An edge with one fill on both sides is inside it and bounds nothing.
331
+ // Given to it both ways, it would join its fill's contours across that
332
+ // fill, into contours that cross and that the containment tree misfills.
333
+ if (fill0 !== fill1 && fill1 > 0 && fill1 <= fills.length) {
334
+ fillEdges[fill1 - 1].push(e);
335
+ }
336
+ if (fill0 !== fill1 && fill0 > 0 && fill0 <= fills.length) {
337
+ fillEdges[fill0 - 1].push(reversed(e));
338
+ }
339
+ if (line > 0 && line <= lines.length) {
340
+ if (!stroke || strokeX !== e.x0 || strokeY !== e.y0) {
341
+ stroke = [MOVE, e.x0 / TWIPS, e.y0 / TWIPS];
342
+ strokes[line - 1].push(stroke);
343
+ }
344
+ if (Number.isNaN(e.cx)) {
345
+ stroke.push(LINE, e.x1 / TWIPS, e.y1 / TWIPS);
346
+ }
347
+ else {
348
+ stroke.push(CURVE, e.cx / TWIPS, e.cy / TWIPS, e.x1 / TWIPS, e.y1 / TWIPS);
349
+ }
350
+ strokeX = e.x1;
351
+ strokeY = e.y1;
352
+ }
353
+ };
354
+ for (const r of shape.records) {
355
+ if (r.type === "style") {
356
+ if (r.styles) {
357
+ // New styles: what came before is a layer of its own, drawn first.
358
+ flush();
359
+ fills = r.styles.fills.map(paint);
360
+ lines = r.styles.lines;
361
+ fillEdges = fills.map(() => []);
362
+ strokes = lines.map(() => []);
363
+ fill0 = 0;
364
+ fill1 = 0;
365
+ line = 0;
366
+ }
367
+ if (r.moveTo) {
368
+ x = r.moveTo.x;
369
+ y = r.moveTo.y;
370
+ }
371
+ if (r.fill0 !== null) {
372
+ fill0 = r.fill0;
373
+ }
374
+ if (r.fill1 !== null) {
375
+ fill1 = r.fill1;
376
+ }
377
+ if (r.line !== null) {
378
+ line = r.line;
379
+ }
380
+ // A style change or a move starts a new stroke.
381
+ stroke = null;
382
+ }
383
+ else if (r.type === "line") {
384
+ const e = { x0: x, y0: y, cx: Number.NaN, cy: Number.NaN, x1: x + r.dx, y1: y + r.dy };
385
+ x = e.x1;
386
+ y = e.y1;
387
+ edge(e);
388
+ }
389
+ else {
390
+ const cx = x + r.cx;
391
+ const cy = y + r.cy;
392
+ const e = { x0: x, y0: y, cx, cy, x1: cx + r.ax, y1: cy + r.ay };
393
+ x = e.x1;
394
+ y = e.y1;
395
+ edge(e);
396
+ }
397
+ }
398
+ flush();
399
+ return layers;
400
+ }
401
+ /**
402
+ * A shape's bounds alone: its records and styles, hundreds of thousands
403
+ * of objects across a large application's SWFs, go once drawn into layers.
404
+ */
405
+ export function boundsOf(shape) {
406
+ return { bounds: shape.bounds, edgeBounds: shape.edgeBounds };
407
+ }
@@ -0,0 +1,222 @@
1
+ import { GUTTER, layoutText } from "../text/layout.js";
2
+ import { placeGlyphs } from "../text/static.js";
3
+ import { TextModel } from "../text/text.js";
4
+ import { CONTENT, DisplayObject, TRANSFORM } from "./displayobject.js";
5
+ /** A StaticText: DefineText's glyphs, which only a timeline places; its bounds the tag's. */
6
+ export class StaticTextObject extends DisplayObject {
7
+ definition;
8
+ characters;
9
+ laidGlyphs = null;
10
+ constructor(definition, characters) {
11
+ super();
12
+ this.definition = definition;
13
+ this.characters = characters;
14
+ this.character = definition;
15
+ }
16
+ /** Show another text in its place, its glyphs laid out when next asked for. */
17
+ show(definition) {
18
+ this.definition = definition;
19
+ this.character = definition;
20
+ this.laidGlyphs = null;
21
+ this.invalidate(CONTENT);
22
+ }
23
+ /**
24
+ * Its glyphs as placed, and its text, found the first time they are
25
+ * asked for: by then its SWF's fonts are all read, those defined after it
26
+ * too.
27
+ */
28
+ get glyphs() {
29
+ this.laidGlyphs ??= placeGlyphs(this.definition, this.characters);
30
+ return this.laidGlyphs;
31
+ }
32
+ }
33
+ /**
34
+ * A TextField: placed by DefineEditText, or made by a script. Its text and
35
+ * formats are a TextModel; a timeline's starts with its tag's text, read
36
+ * as HTML if the tag says so, in the format the tag gives.
37
+ */
38
+ export class TextObject extends DisplayObject {
39
+ definition;
40
+ model = new TextModel();
41
+ /** The embedded fonts its text may be in: its SWF's. */
42
+ fonts = null;
43
+ laid = null;
44
+ /** The field's rectangle, in its own pixels: from (left, top), width by height. */
45
+ left = 0;
46
+ top = 0;
47
+ width = 100;
48
+ height = 100;
49
+ border = false;
50
+ borderColor = 0;
51
+ background = false;
52
+ backgroundColor = 0xffffff;
53
+ multiline = false;
54
+ wordWrap = false;
55
+ type = "dynamic";
56
+ embedFonts = false;
57
+ autoSize = "none";
58
+ selectable = true;
59
+ maxChars = 0;
60
+ displayAsPassword = false;
61
+ condenseWhite = false;
62
+ antiAliasType = "normal";
63
+ gridFitType = "pixel";
64
+ sharpness = 0;
65
+ thickness = 0;
66
+ restrict = null;
67
+ mouseWheelEnabled = true;
68
+ alwaysShowSelection = false;
69
+ useRichTextClipboard = false;
70
+ scrollH = 0;
71
+ scrollV = 1;
72
+ /** The selection, from the end it was started at to the caret, as text indices; empty, a caret alone. */
73
+ anchorAt = 0;
74
+ caretAt = 0;
75
+ /** Whether it has the keyboard's focus, an input field then showing its caret. */
76
+ focused = false;
77
+ /** The StyleSheet its HTML is styled by, or null. */
78
+ styleSheet = null;
79
+ /** Under a sheet, the HTML a script last set, which htmlText gives back as it was set. */
80
+ htmlSource = null;
81
+ /** Under a sheet, its HTML styled again, as a change to the sheet asks. */
82
+ restyle = null;
83
+ constructor(definition, initialText = true) {
84
+ super();
85
+ this.definition = definition;
86
+ this.character = definition;
87
+ const edit = definition?.definition;
88
+ if (!edit) {
89
+ return;
90
+ }
91
+ this.left = edit.bounds.xMin / 20;
92
+ this.top = edit.bounds.yMin / 20;
93
+ this.width = (edit.bounds.xMax - edit.bounds.xMin) / 20;
94
+ this.height = (edit.bounds.yMax - edit.bounds.yMin) / 20;
95
+ this.multiline = edit.multiline;
96
+ this.wordWrap = edit.wordWrap;
97
+ this.type = edit.readOnly ? "dynamic" : "input";
98
+ this.displayAsPassword = edit.password;
99
+ this.autoSize = edit.autoSize ? "left" : "none";
100
+ this.selectable = edit.selectable;
101
+ // A border in the tag is Flash's border and white background together.
102
+ this.border = edit.border;
103
+ this.background = edit.border;
104
+ this.maxChars = edit.maxLength ?? 0;
105
+ this.embedFonts = edit.useOutlines;
106
+ const csm = definition.csm;
107
+ if (csm) {
108
+ this.antiAliasType = csm.useFlashType ? "advanced" : "normal";
109
+ this.gridFitType = ["none", "pixel", "subpixel"][csm.gridFit] ?? "none";
110
+ this.thickness = csm.thickness;
111
+ this.sharpness = csm.sharpness;
112
+ }
113
+ const font = definition?.font;
114
+ const color = edit.color;
115
+ this.model.defaultFormat = {
116
+ ...this.model.defaultFormat,
117
+ font: font?.name ?? edit.fontClass ?? this.model.defaultFormat.font,
118
+ bold: font?.bold ?? false,
119
+ italic: font?.italic ?? false,
120
+ size: edit.fontHeight === null ? 12 : edit.fontHeight / 20,
121
+ // RGBA as the tag stores it.
122
+ color: color === null ? 0 : ((color & 0xff) << 16) | (color & 0xff00) | ((color >>> 16) & 0xff),
123
+ align: ["left", "right", "center", "justify"][edit.align] ?? "left",
124
+ leftMargin: edit.leftMargin / 20,
125
+ rightMargin: edit.rightMargin / 20,
126
+ indent: edit.indent / 20,
127
+ leading: edit.leading / 20,
128
+ };
129
+ if (!initialText) {
130
+ this.model.setText("");
131
+ }
132
+ else if (edit.html) {
133
+ this.model.setHtml(edit.text, edit.multiline);
134
+ }
135
+ else {
136
+ this.model.setText(edit.text);
137
+ }
138
+ }
139
+ /** Its text laid out, as of now: made again only when the text, its formats or the field changed. */
140
+ get layout() {
141
+ const key = `${this.model.revision}|${this.width}|${this.wordWrap}|${this.embedFonts}|${this.displayAsPassword}|${this.type}|${this.antiAliasType}`;
142
+ if (this.laid?.key !== key) {
143
+ const text = this.model.text;
144
+ this.laid = {
145
+ key,
146
+ layout: layoutText({
147
+ // A password's characters are laid out, and drawn, as asterisks; its lines stay.
148
+ text: this.displayAsPassword ? text.replace(/[^\r]/g, "*") : text,
149
+ formats: this.model.formats,
150
+ defaultFormat: this.model.defaultFormat,
151
+ width: this.width,
152
+ wordWrap: this.wordWrap,
153
+ embedFonts: this.embedFonts,
154
+ fonts: this.fonts,
155
+ input: this.type === "input",
156
+ antiAliasType: this.antiAliasType,
157
+ }),
158
+ };
159
+ }
160
+ return this.laid.layout;
161
+ }
162
+ /**
163
+ * Fit the field to its text, as autoSize does: its height to the text's
164
+ * and the gutters, and its width too unless it wraps, keeping its left,
165
+ * centre or right edge where it was.
166
+ */
167
+ fit() {
168
+ if (this.autoSize === "none") {
169
+ return;
170
+ }
171
+ const layout = this.layout;
172
+ const height = (layout.height + 2 * GUTTER) / 20;
173
+ if (!this.wordWrap) {
174
+ const width = (layout.width + 2 * GUTTER) / 20;
175
+ const moved = this.autoSize === "center"
176
+ ? (this.width - width) / 2
177
+ : this.autoSize === "right"
178
+ ? this.width - width
179
+ : 0;
180
+ if (moved !== 0) {
181
+ this.matrix = { ...this.matrix, tx: Math.round((this.matrix.tx + moved) * 20) / 20 };
182
+ this.invalidate(TRANSFORM);
183
+ }
184
+ this.width = width;
185
+ }
186
+ this.height = height;
187
+ this.invalidate(CONTENT);
188
+ }
189
+ /** The text, \r between its lines. */
190
+ get text() {
191
+ return this.model.text;
192
+ }
193
+ /** The alignment of its first paragraph. */
194
+ get align() {
195
+ return (this.model.formats[0] ?? this.model.defaultFormat).align;
196
+ }
197
+ /** The end the selection was started at, within the text as it is now, which a script may have shortened. */
198
+ get anchor() {
199
+ return Math.min(this.anchorAt, this.model.text.length);
200
+ }
201
+ /** The caret, within the text as it is now. */
202
+ get caret() {
203
+ return Math.min(this.caretAt, this.model.text.length);
204
+ }
205
+ /** The selection's first and last index, in order. */
206
+ get selection() {
207
+ const [anchor, caret] = [this.anchor, this.caret];
208
+ return anchor <= caret ? [anchor, caret] : [caret, anchor];
209
+ }
210
+ /** Select from `anchor` to `caret`, each kept within the text; a focused field shows its caret there. */
211
+ select(anchor, caret) {
212
+ const length = this.model.text.length;
213
+ const [a, c] = [Math.max(0, Math.min(length, anchor)), Math.max(0, Math.min(length, caret))];
214
+ // A drag selects on every move, mostly what it had: redraw only for a change.
215
+ if (a === this.anchor && c === this.caret) {
216
+ return;
217
+ }
218
+ this.anchorAt = a;
219
+ this.caretAt = c;
220
+ this.invalidate(CONTENT);
221
+ }
222
+ }