@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.
- package/LICENSE +202 -0
- package/LICENSE.third-party +759 -0
- package/README.md +43 -2
- package/dist/indexeddb.d.ts +27 -0
- package/dist/indexeddb.d.ts.map +1 -0
- package/dist/indexeddb.js +170 -0
- package/dist/indexeddb.js.map +1 -0
- package/dist/node-worker.d.ts +2 -0
- package/dist/node-worker.d.ts.map +1 -0
- package/dist/node-worker.js +12 -0
- package/dist/node-worker.js.map +1 -0
- package/dist/node.d.ts +8 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +43 -0
- package/dist/node.js.map +1 -0
- package/dist/precompiled.d.ts +31 -0
- package/dist/precompiled.d.ts.map +1 -0
- package/dist/precompiled.js +125 -0
- package/dist/precompiled.js.map +1 -0
- package/dist/stage3d.d.ts +13 -0
- package/dist/stage3d.d.ts.map +1 -0
- package/dist/stage3d.js +61 -0
- package/dist/stage3d.js.map +1 -0
- package/dist/thread/codegen/codegen.js +308 -0
- package/dist/thread/codegen/index.js +405 -0
- package/dist/thread/format/abc-names.js +126 -0
- package/dist/thread/format/actions.js +222 -0
- package/dist/thread/format/air-descriptor.js +63 -0
- package/dist/thread/format/api-versions.js +22 -0
- package/dist/thread/format/bitmap.js +199 -0
- package/dist/thread/format/button.js +60 -0
- package/dist/thread/format/compression.js +200 -0
- package/dist/thread/format/display.js +305 -0
- package/dist/thread/format/filters.js +136 -0
- package/dist/thread/format/font.js +168 -0
- package/dist/thread/format/index.js +26 -0
- package/dist/thread/format/pbj.js +484 -0
- package/dist/thread/format/shape.js +411 -0
- package/dist/thread/format/sound.js +91 -0
- package/dist/thread/format/swf.js +163 -0
- package/dist/thread/format/tags.js +58 -0
- package/dist/thread/format/text.js +135 -0
- package/dist/thread/format/zip.js +91 -0
- package/dist/thread/native/audio/binary.js +3 -0
- package/dist/thread/native/audio/index.js +72 -0
- package/dist/thread/native/base64.js +9 -0
- package/dist/thread/native/compress/binary.js +3 -0
- package/dist/thread/native/compress/index.js +145 -0
- package/dist/thread/native/instance.js +49 -0
- package/dist/thread/native/mp3/binary.js +3 -0
- package/dist/thread/native/mp3/index.js +48 -0
- package/dist/thread/native/render/binary.js +3 -0
- package/dist/thread/native/render/bitmap-kernel.js +591 -0
- package/dist/thread/native/render/draw-kernel.js +204 -0
- package/dist/thread/native/render/dxt-encoder.js +94 -0
- package/dist/thread/native/render/index.js +10 -0
- package/dist/thread/native/render/lines.js +122 -0
- package/dist/thread/native/render/module.js +26 -0
- package/dist/thread/native/render/pixel-ops.js +235 -0
- package/dist/thread/native/render/tessellator.js +250 -0
- package/dist/thread/player/avm1/amf.js +507 -0
- package/dist/thread/player/avm1/avm1.js +1304 -0
- package/dist/thread/player/avm1/bindings.js +214 -0
- package/dist/thread/player/avm1/classes.js +75 -0
- package/dist/thread/player/avm1/clips.js +229 -0
- package/dist/thread/player/avm1/compile.js +140 -0
- package/dist/thread/player/avm1/external.js +79 -0
- package/dist/thread/player/avm1/focus.js +278 -0
- package/dist/thread/player/avm1/globals/BitmapData.js +542 -0
- package/dist/thread/player/avm1/globals/Button.js +31 -0
- package/dist/thread/player/avm1/globals/Color.js +115 -0
- package/dist/thread/player/avm1/globals/ExternalInterface.js +310 -0
- package/dist/thread/player/avm1/globals/FileReference.js +217 -0
- package/dist/thread/player/avm1/globals/Key.js +60 -0
- package/dist/thread/player/avm1/globals/LoadVars.js +208 -0
- package/dist/thread/player/avm1/globals/LocalConnection.js +92 -0
- package/dist/thread/player/avm1/globals/MovieClip.js +1070 -0
- package/dist/thread/player/avm1/globals/MovieClipLoader.js +90 -0
- package/dist/thread/player/avm1/globals/NetConnection.js +261 -0
- package/dist/thread/player/avm1/globals/PrintJob.js +37 -0
- package/dist/thread/player/avm1/globals/Selection.js +62 -0
- package/dist/thread/player/avm1/globals/SharedObject.js +245 -0
- package/dist/thread/player/avm1/globals/Sound.js +238 -0
- package/dist/thread/player/avm1/globals/Stage.js +12 -0
- package/dist/thread/player/avm1/globals/StyleSheet.js +205 -0
- package/dist/thread/player/avm1/globals/TextField.js +396 -0
- package/dist/thread/player/avm1/globals/TextFormat.js +194 -0
- package/dist/thread/player/avm1/globals/TextSnapshot.js +88 -0
- package/dist/thread/player/avm1/globals/XML.js +396 -0
- package/dist/thread/player/avm1/globals/XMLNode.js +413 -0
- package/dist/thread/player/avm1/globals/XMLSocket.js +205 -0
- package/dist/thread/player/avm1/globals/drawing.js +202 -0
- package/dist/thread/player/avm1/globals/filters.js +635 -0
- package/dist/thread/player/avm1/globals/geom.js +600 -0
- package/dist/thread/player/avm1/input.js +483 -0
- package/dist/thread/player/avm1/keyboard.js +113 -0
- package/dist/thread/player/avm1/loads.js +352 -0
- package/dist/thread/player/avm1/net.js +219 -0
- package/dist/thread/player/avm1/paths.js +104 -0
- package/dist/thread/player/avm1/pointer.js +512 -0
- package/dist/thread/player/avm1/queue.js +303 -0
- package/dist/thread/player/avm1/sound.js +106 -0
- package/dist/thread/player/avm1/swf.js +141 -0
- package/dist/thread/player/avm1/timers.js +113 -0
- package/dist/thread/player/bitmap/bitmap.js +627 -0
- package/dist/thread/player/bitmap/draw.js +68 -0
- package/dist/thread/player/bitmap/dxt.js +11 -0
- package/dist/thread/player/bitmap/filters.js +656 -0
- package/dist/thread/player/bitmap/images.js +240 -0
- package/dist/thread/player/bitmap/kernel.js +65 -0
- package/dist/thread/player/bitmap/ops.js +1239 -0
- package/dist/thread/player/bitmap/pixel-bender.js +911 -0
- package/dist/thread/player/bitmap/png.js +139 -0
- package/dist/thread/player/bitmap/turbulence.js +89 -0
- package/dist/thread/player/clock.js +182 -0
- package/dist/thread/player/display/bitmapobject.js +25 -0
- package/dist/thread/player/display/bounds.js +520 -0
- package/dist/thread/player/display/buttonobject.js +305 -0
- package/dist/thread/player/display/color.js +40 -0
- package/dist/thread/player/display/container.js +150 -0
- package/dist/thread/player/display/display.js +14 -0
- package/dist/thread/player/display/displayobject.js +664 -0
- package/dist/thread/player/display/drawing.js +613 -0
- package/dist/thread/player/display/filters.js +285 -0
- package/dist/thread/player/display/geometry.js +189 -0
- package/dist/thread/player/display/gradients.js +117 -0
- package/dist/thread/player/display/graphicsdata.js +592 -0
- package/dist/thread/player/display/instantiate.js +71 -0
- package/dist/thread/player/display/matrix3d.js +373 -0
- package/dist/thread/player/display/morph.js +226 -0
- package/dist/thread/player/display/movieclip.js +680 -0
- package/dist/thread/player/display/perspective.js +193 -0
- package/dist/thread/player/display/scale9.js +236 -0
- package/dist/thread/player/display/shapeobject.js +131 -0
- package/dist/thread/player/display/shapes.js +407 -0
- package/dist/thread/player/display/textobjects.js +222 -0
- package/dist/thread/player/display/timeline.js +471 -0
- package/dist/thread/player/display/value-lists.js +40 -0
- package/dist/thread/player/display/videoobject.js +6 -0
- package/dist/thread/player/display/walk.js +127 -0
- package/dist/thread/player/files.js +334 -0
- package/dist/thread/player/hosts.js +207 -0
- package/dist/thread/player/input/avm1.js +82 -0
- package/dist/thread/player/input/context-menu.js +63 -0
- package/dist/thread/player/input/keyboard.js +458 -0
- package/dist/thread/player/input/pointer.js +863 -0
- package/dist/thread/player/input/text-editor.js +319 -0
- package/dist/thread/player/input/touch.js +209 -0
- package/dist/thread/player/localconnection.js +90 -0
- package/dist/thread/player/media/audio.js +376 -0
- package/dist/thread/player/media/dynamic-sound.js +90 -0
- package/dist/thread/player/media/extract.js +135 -0
- package/dist/thread/player/media/mp3.js +152 -0
- package/dist/thread/player/media/sounds.js +507 -0
- package/dist/thread/player/media/streaming-audio.js +133 -0
- package/dist/thread/player/player.js +616 -0
- package/dist/thread/player/playerglobal/air/net/WebSocket.js +250 -0
- package/dist/thread/player/playerglobal/air-library.js +8 -0
- package/dist/thread/player/playerglobal/flash/accessibility/Accessibility.js +21 -0
- package/dist/thread/player/playerglobal/flash/crypto/generateRandomBytes.js +32 -0
- package/dist/thread/player/playerglobal/flash/data/EncryptedLocalStore.js +61 -0
- package/dist/thread/player/playerglobal/flash/desktop/Clipboard.js +173 -0
- package/dist/thread/player/playerglobal/flash/desktop/NativeApplication.js +179 -0
- package/dist/thread/player/playerglobal/flash/display/AVM1Movie.js +19 -0
- package/dist/thread/player/playerglobal/flash/display/Bitmap.js +58 -0
- package/dist/thread/player/playerglobal/flash/display/BitmapData.js +633 -0
- package/dist/thread/player/playerglobal/flash/display/DisplayObject.js +614 -0
- package/dist/thread/player/playerglobal/flash/display/DisplayObjectContainer.js +224 -0
- package/dist/thread/player/playerglobal/flash/display/Graphics.js +345 -0
- package/dist/thread/player/playerglobal/flash/display/InteractiveObject.js +87 -0
- package/dist/thread/player/playerglobal/flash/display/Loader.js +79 -0
- package/dist/thread/player/playerglobal/flash/display/LoaderInfo.js +128 -0
- package/dist/thread/player/playerglobal/flash/display/MovieClip.js +194 -0
- package/dist/thread/player/playerglobal/flash/display/NativeWindow.js +245 -0
- package/dist/thread/player/playerglobal/flash/display/Shader.js +26 -0
- package/dist/thread/player/playerglobal/flash/display/ShaderData.js +85 -0
- package/dist/thread/player/playerglobal/flash/display/ShaderInput.js +64 -0
- package/dist/thread/player/playerglobal/flash/display/ShaderJob.js +181 -0
- package/dist/thread/player/playerglobal/flash/display/ShaderParameter.js +23 -0
- package/dist/thread/player/playerglobal/flash/display/Shape.js +13 -0
- package/dist/thread/player/playerglobal/flash/display/SimpleButton.js +103 -0
- package/dist/thread/player/playerglobal/flash/display/Sprite.js +84 -0
- package/dist/thread/player/playerglobal/flash/display/Stage.js +231 -0
- package/dist/thread/player/playerglobal/flash/display/Stage3D.js +54 -0
- package/dist/thread/player/playerglobal/flash/display/shaders.js +228 -0
- package/dist/thread/player/playerglobal/flash/events/Event.js +58 -0
- package/dist/thread/player/playerglobal/flash/events/EventDispatcher.js +103 -0
- package/dist/thread/player/playerglobal/flash/events/GestureEvent.js +34 -0
- package/dist/thread/player/playerglobal/flash/events/HTTPStatusEvent.js +8 -0
- package/dist/thread/player/playerglobal/flash/events/KeyboardEvent.js +51 -0
- package/dist/thread/player/playerglobal/flash/events/MouseEvent.js +59 -0
- package/dist/thread/player/playerglobal/flash/events/PressAndTapGestureEvent.js +30 -0
- package/dist/thread/player/playerglobal/flash/events/TimerEvent.js +16 -0
- package/dist/thread/player/playerglobal/flash/events/TouchEvent.js +45 -0
- package/dist/thread/player/playerglobal/flash/external/ExternalInterface.js +73 -0
- package/dist/thread/player/playerglobal/flash/filesystem/File.js +340 -0
- package/dist/thread/player/playerglobal/flash/filesystem/FileStream.js +453 -0
- package/dist/thread/player/playerglobal/flash/filesystem/paths.js +156 -0
- package/dist/thread/player/playerglobal/flash/filesystem/writes.js +143 -0
- package/dist/thread/player/playerglobal/flash/filters/BevelFilter.js +4 -0
- package/dist/thread/player/playerglobal/flash/filters/BitmapFilter.js +205 -0
- package/dist/thread/player/playerglobal/flash/filters/BlurFilter.js +4 -0
- package/dist/thread/player/playerglobal/flash/filters/ColorMatrixFilter.js +11 -0
- package/dist/thread/player/playerglobal/flash/filters/ConvolutionFilter.js +26 -0
- package/dist/thread/player/playerglobal/flash/filters/DisplacementMapFilter.js +51 -0
- package/dist/thread/player/playerglobal/flash/filters/DropShadowFilter.js +4 -0
- package/dist/thread/player/playerglobal/flash/filters/GlowFilter.js +4 -0
- package/dist/thread/player/playerglobal/flash/filters/GradientBevelFilter.js +4 -0
- package/dist/thread/player/playerglobal/flash/filters/GradientGlowFilter.js +4 -0
- package/dist/thread/player/playerglobal/flash/filters/ShaderFilter.js +53 -0
- package/dist/thread/player/playerglobal/flash/geom/Matrix3D.js +361 -0
- package/dist/thread/player/playerglobal/flash/geom/PerspectiveProjection.js +122 -0
- package/dist/thread/player/playerglobal/flash/geom/Transform.js +245 -0
- package/dist/thread/player/playerglobal/flash/geom/Utils3D.js +85 -0
- package/dist/thread/player/playerglobal/flash/globalization/Collator.js +149 -0
- package/dist/thread/player/playerglobal/flash/globalization/CurrencyFormatter.js +272 -0
- package/dist/thread/player/playerglobal/flash/globalization/CurrencyParseResult.js +21 -0
- package/dist/thread/player/playerglobal/flash/globalization/DateTimeFormatter.js +463 -0
- package/dist/thread/player/playerglobal/flash/globalization/LocaleID.js +144 -0
- package/dist/thread/player/playerglobal/flash/globalization/NumberFormatter.js +444 -0
- package/dist/thread/player/playerglobal/flash/globalization/NumberParseResult.js +22 -0
- package/dist/thread/player/playerglobal/flash/globalization/StringTools.js +59 -0
- package/dist/thread/player/playerglobal/flash/globalization/locale.js +190 -0
- package/dist/thread/player/playerglobal/flash/media/Camera.js +89 -0
- package/dist/thread/player/playerglobal/flash/media/Microphone.js +126 -0
- package/dist/thread/player/playerglobal/flash/media/Sound.js +543 -0
- package/dist/thread/player/playerglobal/flash/media/SoundMixer.js +74 -0
- package/dist/thread/player/playerglobal/flash/media/SoundTransform.js +40 -0
- package/dist/thread/player/playerglobal/flash/media/Video.js +43 -0
- package/dist/thread/player/playerglobal/flash/net/FileFilter.js +27 -0
- package/dist/thread/player/playerglobal/flash/net/FileReference.js +197 -0
- package/dist/thread/player/playerglobal/flash/net/LocalConnection.js +167 -0
- package/dist/thread/player/playerglobal/flash/net/NetConnection.js +155 -0
- package/dist/thread/player/playerglobal/flash/net/SharedObject.js +299 -0
- package/dist/thread/player/playerglobal/flash/net/Socket.js +282 -0
- package/dist/thread/player/playerglobal/flash/net/URLRequest.js +93 -0
- package/dist/thread/player/playerglobal/flash/net/URLStream.js +146 -0
- package/dist/thread/player/playerglobal/flash/net/XMLSocket.js +14 -0
- package/dist/thread/player/playerglobal/flash/net/local-modern.js +142 -0
- package/dist/thread/player/playerglobal/flash/net/local-values.js +217 -0
- package/dist/thread/player/playerglobal/flash/net/navigateToURL.js +29 -0
- package/dist/thread/player/playerglobal/flash/profiler/Telemetry.js +25 -0
- package/dist/thread/player/playerglobal/flash/sensors/Accelerometer.js +12 -0
- package/dist/thread/player/playerglobal/flash/system/ApplicationDomain.js +69 -0
- package/dist/thread/player/playerglobal/flash/system/Capabilities.js +163 -0
- package/dist/thread/player/playerglobal/flash/system/FSCommandHost.js +17 -0
- package/dist/thread/player/playerglobal/flash/system/Security.js +46 -0
- package/dist/thread/player/playerglobal/flash/system/SecurityDomain.js +21 -0
- package/dist/thread/player/playerglobal/flash/system/System.js +73 -0
- package/dist/thread/player/playerglobal/flash/system/Worker.js +112 -0
- package/dist/thread/player/playerglobal/flash/text/Font.js +95 -0
- package/dist/thread/player/playerglobal/flash/text/StaticText.js +16 -0
- package/dist/thread/player/playerglobal/flash/text/StyleSheet.js +65 -0
- package/dist/thread/player/playerglobal/flash/text/TextField.js +707 -0
- package/dist/thread/player/playerglobal/flash/text/TextRenderer.js +77 -0
- package/dist/thread/player/playerglobal/flash/text/engine/FontDescription.js +141 -0
- package/dist/thread/player/playerglobal/flash/text/engine/TabStop.js +46 -0
- package/dist/thread/player/playerglobal/flash/trace/Trace.js +17 -0
- package/dist/thread/player/playerglobal/flash/ui/ContextMenu.js +17 -0
- package/dist/thread/player/playerglobal/flash/ui/GameInput.js +19 -0
- package/dist/thread/player/playerglobal/flash/ui/Keyboard.js +27 -0
- package/dist/thread/player/playerglobal/flash/ui/Mouse.js +127 -0
- package/dist/thread/player/playerglobal/flash/ui/Multitouch.js +46 -0
- package/dist/thread/player/playerglobal/flash/utils/ByteArray.js +155 -0
- package/dist/thread/player/playerglobal/flash/utils/Timer.js +25 -0
- package/dist/thread/player/playerglobal/flash/xml/XMLDocument.js +74 -0
- package/dist/thread/player/playerglobal/index.js +224 -0
- package/dist/thread/player/playerglobal/libraries.js +10 -0
- package/dist/thread/player/playerglobal/playerglobal-library.js +22 -0
- package/dist/thread/player/playerglobal/toplevel.js +122 -0
- package/dist/thread/player/scripting/clipboard.js +146 -0
- package/dist/thread/player/scripting/code.js +900 -0
- package/dist/thread/player/scripting/evaluate.js +144 -0
- package/dist/thread/player/scripting/events.js +172 -0
- package/dist/thread/player/scripting/handover.js +182 -0
- package/dist/thread/player/scripting/lazy.js +38 -0
- package/dist/thread/player/scripting/lifecycle.js +272 -0
- package/dist/thread/player/scripting/loads.js +860 -0
- package/dist/thread/player/scripting/sha256.js +95 -0
- package/dist/thread/player/scripting/symbols.js +348 -0
- package/dist/thread/player/scripting/timers.js +434 -0
- package/dist/thread/player/scripting/workers.js +923 -0
- package/dist/thread/player/scripting.js +1018 -0
- package/dist/thread/player/stage.js +4 -0
- package/dist/thread/player/text/csm.js +113 -0
- package/dist/thread/player/text/css.js +167 -0
- package/dist/thread/player/text/fonts.js +97 -0
- package/dist/thread/player/text/layout.js +393 -0
- package/dist/thread/player/text/static.js +109 -0
- package/dist/thread/player/text/text.js +431 -0
- package/dist/thread/player/workers/thread.js +159 -0
- package/dist/thread/player/workers/wire.js +198 -0
- package/dist/thread/player-hosts/web-worker.js +19 -0
- package/dist/thread/runtime/avm1/activation.js +89 -0
- package/dist/thread/runtime/avm1/case.js +249 -0
- package/dist/thread/runtime/avm1/clips.js +334 -0
- package/dist/thread/runtime/avm1/control.js +280 -0
- package/dist/thread/runtime/avm1/errors.js +50 -0
- package/dist/thread/runtime/avm1/functions.js +249 -0
- package/dist/thread/runtime/avm1/globals/array.js +549 -0
- package/dist/thread/runtime/avm1/globals/broadcaster.js +131 -0
- package/dist/thread/runtime/avm1/globals/date.js +436 -0
- package/dist/thread/runtime/avm1/globals/global.js +344 -0
- package/dist/thread/runtime/avm1/globals/math.js +139 -0
- package/dist/thread/runtime/avm1/globals/number.js +93 -0
- package/dist/thread/runtime/avm1/globals/string.js +201 -0
- package/dist/thread/runtime/avm1/globals/timers.js +129 -0
- package/dist/thread/runtime/avm1/host.js +5 -0
- package/dist/thread/runtime/avm1/index.js +14 -0
- package/dist/thread/runtime/avm1/inheritance.js +132 -0
- package/dist/thread/runtime/avm1/numbers.js +298 -0
- package/dist/thread/runtime/avm1/objects.js +896 -0
- package/dist/thread/runtime/avm1/operators.js +170 -0
- package/dist/thread/runtime/avm1/realm.js +529 -0
- package/dist/thread/runtime/avm1/runtime.js +882 -0
- package/dist/thread/runtime/avm1/scope.js +385 -0
- package/dist/thread/runtime/avm1/urls.js +180 -0
- package/dist/thread/runtime/avm1/values.js +97 -0
- package/dist/thread/runtime/avm2/amf-classes.js +66 -0
- package/dist/thread/runtime/avm2/amf.js +801 -0
- package/dist/thread/runtime/avm2/array-conversion.js +100 -0
- package/dist/thread/runtime/avm2/builtin-library.js +21 -0
- package/dist/thread/runtime/avm2/cache-fill.js +86 -0
- package/dist/thread/runtime/avm2/classes.js +211 -0
- package/dist/thread/runtime/avm2/definitions.js +69 -0
- package/dist/thread/runtime/avm2/descriptors.js +5 -0
- package/dist/thread/runtime/avm2/dictionary-keys.js +295 -0
- package/dist/thread/runtime/avm2/domain-memory.js +75 -0
- package/dist/thread/runtime/avm2/domain.js +280 -0
- package/dist/thread/runtime/avm2/dynamic-properties.js +182 -0
- package/dist/thread/runtime/avm2/enumeration.js +393 -0
- package/dist/thread/runtime/avm2/errors.js +45 -0
- package/dist/thread/runtime/avm2/float-library.js +66 -0
- package/dist/thread/runtime/avm2/float.js +26 -0
- package/dist/thread/runtime/avm2/hooks.js +19 -0
- package/dist/thread/runtime/avm2/index.js +38 -0
- package/dist/thread/runtime/avm2/messages.js +177 -0
- package/dist/thread/runtime/avm2/method-factories.js +95 -0
- package/dist/thread/runtime/avm2/modules.js +105 -0
- package/dist/thread/runtime/avm2/names.js +248 -0
- package/dist/thread/runtime/avm2/natives/aliases.js +47 -0
- package/dist/thread/runtime/avm2/natives/array.js +390 -0
- package/dist/thread/runtime/avm2/natives/bytearray.js +1227 -0
- package/dist/thread/runtime/avm2/natives/case.js +88 -0
- package/dist/thread/runtime/avm2/natives/concurrent.js +199 -0
- package/dist/thread/runtime/avm2/natives/date.js +581 -0
- package/dist/thread/runtime/avm2/natives/define.js +130 -0
- package/dist/thread/runtime/avm2/natives/describe.js +351 -0
- package/dist/thread/runtime/avm2/natives/dictionary.js +12 -0
- package/dist/thread/runtime/avm2/natives/float-vector.js +81 -0
- package/dist/thread/runtime/avm2/natives/float.js +96 -0
- package/dist/thread/runtime/avm2/natives/index.js +64 -0
- package/dist/thread/runtime/avm2/natives/json.js +514 -0
- package/dist/thread/runtime/avm2/natives/number.js +162 -0
- package/dist/thread/runtime/avm2/natives/object.js +237 -0
- package/dist/thread/runtime/avm2/natives/proxy.js +75 -0
- package/dist/thread/runtime/avm2/natives/regexp.js +485 -0
- package/dist/thread/runtime/avm2/natives/shell-workers.js +404 -0
- package/dist/thread/runtime/avm2/natives/shell.js +557 -0
- package/dist/thread/runtime/avm2/natives/sort.js +377 -0
- package/dist/thread/runtime/avm2/natives/string.js +132 -0
- package/dist/thread/runtime/avm2/natives/sync.js +821 -0
- package/dist/thread/runtime/avm2/natives/toplevel.js +139 -0
- package/dist/thread/runtime/avm2/natives/vector-elements.js +46 -0
- package/dist/thread/runtime/avm2/natives/vector.js +406 -0
- package/dist/thread/runtime/avm2/natives/xml/access.js +633 -0
- package/dist/thread/runtime/avm2/natives/xml/build.js +291 -0
- package/dist/thread/runtime/avm2/natives/xml/chars.js +112 -0
- package/dist/thread/runtime/avm2/natives/xml/escape.js +38 -0
- package/dist/thread/runtime/avm2/natives/xml/names.js +204 -0
- package/dist/thread/runtime/avm2/natives/xml/node.js +272 -0
- package/dist/thread/runtime/avm2/natives/xml/operators.js +69 -0
- package/dist/thread/runtime/avm2/natives/xml/parser.js +356 -0
- package/dist/thread/runtime/avm2/natives/xml/strings.js +191 -0
- package/dist/thread/runtime/avm2/natives/xml/values.js +122 -0
- package/dist/thread/runtime/avm2/natives/xml/xml.js +645 -0
- package/dist/thread/runtime/avm2/number-strings.js +110 -0
- package/dist/thread/runtime/avm2/numbers.js +558 -0
- package/dist/thread/runtime/avm2/options.js +16 -0
- package/dist/thread/runtime/avm2/player-messages.js +550 -0
- package/dist/thread/runtime/avm2/property-cache.js +135 -0
- package/dist/thread/runtime/avm2/runtime.js +2644 -0
- package/dist/thread/runtime/avm2/traits.js +509 -0
- package/dist/thread/runtime/index.js +7 -0
- package/dist/web-worker.d.ts +2 -0
- package/dist/web-worker.d.ts.map +1 -0
- package/dist/web-worker.js +20 -0
- package/dist/web-worker.js.map +1 -0
- package/dist/websocket.d.ts +4 -0
- package/dist/websocket.d.ts.map +1 -0
- package/dist/websocket.js +27 -0
- package/dist/websocket.js.map +1 -0
- package/dist/workers.d.ts +35 -0
- package/dist/workers.d.ts.map +1 -0
- package/dist/workers.js +171 -0
- package/dist/workers.js.map +1 -0
- package/package.json +62 -3
- package/src/indexeddb.ts +227 -0
- package/src/node-worker.ts +13 -0
- package/src/node.ts +49 -0
- package/src/precompiled.ts +166 -0
- package/src/stage3d.ts +76 -0
- package/src/web-worker.ts +24 -0
- package/src/websocket.ts +32 -0
- package/src/workers.ts +255 -0
|
@@ -0,0 +1,613 @@
|
|
|
1
|
+
import { BitmapStore } from "../bitmap/bitmap.js";
|
|
2
|
+
import { union } from "./geometry.js";
|
|
3
|
+
import { CUBIC, CURVE, extent, LINE, MOVE, } from "./shapes.js";
|
|
4
|
+
const TWIPS = 20;
|
|
5
|
+
/** The quadratic approximation of a quarter ellipse Flash's drawRoundRect uses: two curves, meeting at 45°. */
|
|
6
|
+
const TAN_22_5 = Math.SQRT2 - 1;
|
|
7
|
+
const COS_45 = Math.SQRT1_2;
|
|
8
|
+
/**
|
|
9
|
+
* The fills a layer takes on from those before it, at most: a drawing
|
|
10
|
+
* redrawn every frame a fill a triangle so makes a few layers of them, not
|
|
11
|
+
* thousands, while a layer's tessellation, its memory and what a failure
|
|
12
|
+
* of it takes with it, stay bounded.
|
|
13
|
+
*/
|
|
14
|
+
const SHARED_FILLS = 256;
|
|
15
|
+
/** Whether `layer` holds fills alone, which a fill begun next may go on after. */
|
|
16
|
+
function fillsOnly(layer) {
|
|
17
|
+
return !layer.strokes.length && !layer.meshes && !layer.extent;
|
|
18
|
+
}
|
|
19
|
+
/** The points lineTo, curveTo and cubicCurveTo pass on, which command copies. */
|
|
20
|
+
const LINE_POINTS = [0, 0];
|
|
21
|
+
const CURVE_POINTS = [0, 0, 0, 0];
|
|
22
|
+
const CUBIC_POINTS = [0, 0, 0, 0, 0, 0];
|
|
23
|
+
/** `kind` and `points` onto the last of `paths`. */
|
|
24
|
+
function append(paths, kind, points) {
|
|
25
|
+
const path = paths[paths.length - 1];
|
|
26
|
+
path.push(kind);
|
|
27
|
+
for (let i = 0; i < points.length; i++) {
|
|
28
|
+
path.push(points[i]);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export class Drawing {
|
|
32
|
+
layers = [];
|
|
33
|
+
/** Counts the changes to `layers`, which change in place: what is kept of them goes by it. */
|
|
34
|
+
version = 0;
|
|
35
|
+
/** The bounds without lines and with them, as of a version: a 9-slice's owner asks on every change. */
|
|
36
|
+
kept = [null, null];
|
|
37
|
+
fill = null;
|
|
38
|
+
/** The layer the open fill is in, for the entries a change of winding adds beside it. */
|
|
39
|
+
fillLayer = null;
|
|
40
|
+
/** Where the open fill's entries begin in its layer, which fills before it may share. */
|
|
41
|
+
fillStart = 0;
|
|
42
|
+
stroke = null;
|
|
43
|
+
/** The line closing the open contour, or the one endFill closed, while a line drawn on may take it away. */
|
|
44
|
+
closing = null;
|
|
45
|
+
/**
|
|
46
|
+
* A point of the open contour off its start, for whether it leaves the
|
|
47
|
+
* line through them: its offset from the start, while `heading`.
|
|
48
|
+
*/
|
|
49
|
+
towardX = 0;
|
|
50
|
+
towardY = 0;
|
|
51
|
+
heading = false;
|
|
52
|
+
/** Whether the open contour has an area: one along a line has no closing line, which would retrace it. */
|
|
53
|
+
bent = false;
|
|
54
|
+
/** Whether drawPath drew the open contour, which Flash never closes with a line. */
|
|
55
|
+
pathed = false;
|
|
56
|
+
/** The layer the fill and line went on in after drawTriangles, which endFill drops while empty. */
|
|
57
|
+
resumed = null;
|
|
58
|
+
/**
|
|
59
|
+
* Whether a drawTriangles culled: what it draws then depends on whether
|
|
60
|
+
* a transform turns the drawing over.
|
|
61
|
+
*/
|
|
62
|
+
culled = false;
|
|
63
|
+
x = 0;
|
|
64
|
+
y = 0;
|
|
65
|
+
beginFill(fill) {
|
|
66
|
+
this.endFill();
|
|
67
|
+
this.closing = null;
|
|
68
|
+
this.pathed = false;
|
|
69
|
+
const line = this.stroke?.line;
|
|
70
|
+
this.dropStroke();
|
|
71
|
+
this.fill = { fill, contours: [], winding: "evenOdd" };
|
|
72
|
+
// On in the last layer while it holds fills alone, as many as SHARED_FILLS: within a layer
|
|
73
|
+
// fills draw in order, as across layers. A layer with lines, triangles or meshes ends where it
|
|
74
|
+
// is.
|
|
75
|
+
const last = this.layers[this.layers.length - 1];
|
|
76
|
+
if (last && fillsOnly(last) && last.fills.length < SHARED_FILLS) {
|
|
77
|
+
this.fillLayer = last;
|
|
78
|
+
this.fillStart = last.fills.length;
|
|
79
|
+
last.fills.push(this.fill);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
this.fillLayer = { fills: [this.fill], strokes: [] };
|
|
83
|
+
this.fillStart = 0;
|
|
84
|
+
this.layers.push(this.fillLayer);
|
|
85
|
+
}
|
|
86
|
+
this.beginContour();
|
|
87
|
+
if (line) {
|
|
88
|
+
this.stroke = { line, paths: [] };
|
|
89
|
+
this.fillLayer.strokes.push(this.stroke);
|
|
90
|
+
this.begin(this.stroke.paths);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/** The closing line stays till what comes next: a line on from the pen takes it away. */
|
|
94
|
+
endFill() {
|
|
95
|
+
const layer = this.fillLayer;
|
|
96
|
+
this.fill = null;
|
|
97
|
+
this.fillLayer = null;
|
|
98
|
+
if (layer && layer === this.resumed) {
|
|
99
|
+
this.dropEmpty(layer, this.fillStart);
|
|
100
|
+
}
|
|
101
|
+
this.resumed = null;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* `layer` taken away if it is the last and draws nothing yet: an empty
|
|
105
|
+
* layer would be a Graphics drawing nothing. Where it holds fills before
|
|
106
|
+
* the open one's, the open fill's entries alone go.
|
|
107
|
+
*/
|
|
108
|
+
dropEmpty(layer, from) {
|
|
109
|
+
if (layer !== this.layers[this.layers.length - 1] || !fillsOnly(layer)) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
for (let i = from; i < layer.fills.length; i++) {
|
|
113
|
+
if (layer.fills[i].contours.some((c) => c.length > 3)) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (from > 0) {
|
|
118
|
+
layer.fills.length = from;
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
this.layers.pop();
|
|
122
|
+
}
|
|
123
|
+
this.version++;
|
|
124
|
+
}
|
|
125
|
+
/** A stroke from here on with `line`, or none for null; the one before it ends either way. */
|
|
126
|
+
lineStyle(line) {
|
|
127
|
+
// The open contour's closing line goes to the new style; one endFill closed stays.
|
|
128
|
+
if (this.fill) {
|
|
129
|
+
this.unclose();
|
|
130
|
+
}
|
|
131
|
+
this.closing = null;
|
|
132
|
+
this.dropStroke();
|
|
133
|
+
this.stroke = line ? { line, paths: [] } : null;
|
|
134
|
+
if (!this.stroke) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
let layer = this.layers[this.layers.length - 1];
|
|
138
|
+
if (!layer) {
|
|
139
|
+
layer = { fills: [], strokes: [] };
|
|
140
|
+
this.layers.push(layer);
|
|
141
|
+
}
|
|
142
|
+
layer.strokes.push(this.stroke);
|
|
143
|
+
this.begin(this.stroke.paths);
|
|
144
|
+
this.reclose();
|
|
145
|
+
}
|
|
146
|
+
moveTo(x, y) {
|
|
147
|
+
this.pathed = false;
|
|
148
|
+
this.move(x, y);
|
|
149
|
+
}
|
|
150
|
+
lineTo(x, y) {
|
|
151
|
+
LINE_POINTS[0] = x;
|
|
152
|
+
LINE_POINTS[1] = y;
|
|
153
|
+
this.command(LINE, LINE_POINTS);
|
|
154
|
+
}
|
|
155
|
+
curveTo(cx, cy, x, y) {
|
|
156
|
+
CURVE_POINTS[0] = cx;
|
|
157
|
+
CURVE_POINTS[1] = cy;
|
|
158
|
+
CURVE_POINTS[2] = x;
|
|
159
|
+
CURVE_POINTS[3] = y;
|
|
160
|
+
this.command(CURVE, CURVE_POINTS);
|
|
161
|
+
}
|
|
162
|
+
cubicCurveTo(c1x, c1y, c2x, c2y, x, y) {
|
|
163
|
+
CUBIC_POINTS[0] = c1x;
|
|
164
|
+
CUBIC_POINTS[1] = c1y;
|
|
165
|
+
CUBIC_POINTS[2] = c2x;
|
|
166
|
+
CUBIC_POINTS[3] = c2y;
|
|
167
|
+
CUBIC_POINTS[4] = x;
|
|
168
|
+
CUBIC_POINTS[5] = y;
|
|
169
|
+
this.command(CUBIC, CUBIC_POINTS);
|
|
170
|
+
}
|
|
171
|
+
drawRect(x, y, w, h) {
|
|
172
|
+
this.moveTo(x, y);
|
|
173
|
+
this.lineTo(x + w, y);
|
|
174
|
+
this.lineTo(x + w, y + h);
|
|
175
|
+
this.lineTo(x, y + h);
|
|
176
|
+
this.lineTo(x, y);
|
|
177
|
+
}
|
|
178
|
+
/** Corners of radii `rx`, `ry` (the ellipse's half width and height), clamped to the rectangle, two quadratics each. */
|
|
179
|
+
drawRoundRect(x, y, w, h, ew, eh) {
|
|
180
|
+
const rx = Math.min(Math.abs(ew) / 2, Math.abs(w) / 2);
|
|
181
|
+
const ry = Math.min(Math.abs(eh) / 2, Math.abs(h) / 2);
|
|
182
|
+
this.drawRoundRectComplex(x, y, w, h, [rx, ry], [rx, ry], [rx, ry], [rx, ry]);
|
|
183
|
+
}
|
|
184
|
+
/** Each corner its own radii: top left, top right, bottom left, bottom right; from the right edge's end, clockwise. */
|
|
185
|
+
drawRoundRectComplex(x, y, w, h, tl, tr, bl, br) {
|
|
186
|
+
const right = x + w;
|
|
187
|
+
const bottom = y + h;
|
|
188
|
+
this.moveTo(right, bottom - br[1]);
|
|
189
|
+
this.arc(right - br[0], bottom - br[1], br[0], br[1], 0);
|
|
190
|
+
this.lineTo(x + bl[0], bottom);
|
|
191
|
+
this.arc(x + bl[0], bottom - bl[1], bl[0], bl[1], 1);
|
|
192
|
+
this.lineTo(x, y + tl[1]);
|
|
193
|
+
this.arc(x + tl[0], y + tl[1], tl[0], tl[1], 2);
|
|
194
|
+
this.lineTo(right - tr[0], y);
|
|
195
|
+
this.arc(right - tr[0], y + tr[1], tr[0], tr[1], 3);
|
|
196
|
+
this.lineTo(right, bottom - br[1]);
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* A quarter ellipse about (`cx`, `cy`) of radii `rx`, `ry`, from the pen,
|
|
200
|
+
* as two quadratics meeting at 45°: `quarter` 0 goes from the right (1, 0)
|
|
201
|
+
* down to the bottom (0, 1), and each next one on clockwise.
|
|
202
|
+
*/
|
|
203
|
+
arc(cx, cy, rx, ry, quarter) {
|
|
204
|
+
// A square corner is no curve, as Flash records none.
|
|
205
|
+
if (rx === 0 && ry === 0) {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
const [sx, sy, ex, ey] = [
|
|
209
|
+
[1, 0, 0, 1],
|
|
210
|
+
[0, 1, -1, 0],
|
|
211
|
+
[-1, 0, 0, -1],
|
|
212
|
+
[0, -1, 1, 0],
|
|
213
|
+
][quarter];
|
|
214
|
+
this.curveTo(cx + (sx + ex * TAN_22_5) * rx, cy + (sy + ey * TAN_22_5) * ry, cx + (sx + ex) * COS_45 * rx, cy + (sy + ey) * COS_45 * ry);
|
|
215
|
+
this.curveTo(cx + (ex + sx * TAN_22_5) * rx, cy + (ey + sy * TAN_22_5) * ry, cx + ex * rx, cy + ey * ry);
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Flash's drawPath: 1 moveTo, 2 lineTo, 3 curveTo, 4 wideMoveTo, 5
|
|
219
|
+
* wideLineTo, 6 cubicCurveTo, each taking its data. The winding is this
|
|
220
|
+
* path's: a fill drawn with one rule and then another keeps each path's,
|
|
221
|
+
* as Flash does, so the contours from here on go in an entry of their
|
|
222
|
+
* own beside the fill's, with the same fill. Its first contour begins at
|
|
223
|
+
* the pen, and none it draws is closed with a line, as in Flash.
|
|
224
|
+
*/
|
|
225
|
+
drawPath(commands, data, winding) {
|
|
226
|
+
this.version++;
|
|
227
|
+
if (this.fill && this.fillLayer && this.fill.winding !== winding) {
|
|
228
|
+
if (this.fill.contours.some((c) => c.length > 3)) {
|
|
229
|
+
this.fill = { fill: this.fill.fill, contours: [], winding };
|
|
230
|
+
this.fillLayer.fills.push(this.fill);
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
this.fill.winding = winding;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
// A contour of its own from the pen, as in Flash, which closes the one before it.
|
|
237
|
+
this.move(this.x, this.y);
|
|
238
|
+
this.pathed = true;
|
|
239
|
+
let i = 0;
|
|
240
|
+
for (const command of commands) {
|
|
241
|
+
switch (command) {
|
|
242
|
+
case 1:
|
|
243
|
+
this.move(data[i], data[i + 1]);
|
|
244
|
+
i += 2;
|
|
245
|
+
break;
|
|
246
|
+
case 2:
|
|
247
|
+
this.lineTo(data[i], data[i + 1]);
|
|
248
|
+
i += 2;
|
|
249
|
+
break;
|
|
250
|
+
case 3:
|
|
251
|
+
this.curveTo(data[i], data[i + 1], data[i + 2], data[i + 3]);
|
|
252
|
+
i += 4;
|
|
253
|
+
break;
|
|
254
|
+
case 4:
|
|
255
|
+
this.move(data[i + 2], data[i + 3]);
|
|
256
|
+
i += 4;
|
|
257
|
+
break;
|
|
258
|
+
case 5:
|
|
259
|
+
this.lineTo(data[i + 2], data[i + 3]);
|
|
260
|
+
i += 4;
|
|
261
|
+
break;
|
|
262
|
+
case 6:
|
|
263
|
+
this.cubicCurveTo(data[i], data[i + 1], data[i + 2], data[i + 3], data[i + 4], data[i + 5]);
|
|
264
|
+
i += 6;
|
|
265
|
+
break;
|
|
266
|
+
default:
|
|
267
|
+
break;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* drawTriangles' triangles, as adl draws them: `vertices` x y in pixels,
|
|
273
|
+
* three a triangle by `indices` or in order, up to the first index past
|
|
274
|
+
* them. They go in a layer of their own, each triangle a fill of its own,
|
|
275
|
+
* so that overlapping ones never cancel, and the line around each over
|
|
276
|
+
* them all. They end the open fill's contour, whose closing line stays,
|
|
277
|
+
* and the line's path; both go on from the pen, which stays, in a layer
|
|
278
|
+
* after them, the contour still closing to where it began. With `uvt`, u
|
|
279
|
+
* v t a vertex, only a bitmap fill draws them, textured; any other fill
|
|
280
|
+
* draws nothing, lines neither. `cull` 1 drops those clockwise on a
|
|
281
|
+
* y-down screen, -1 the others; the bounds count all.
|
|
282
|
+
*/
|
|
283
|
+
drawTriangles(vertices, indices, uvt, cull) {
|
|
284
|
+
const n = vertices.length >> 1;
|
|
285
|
+
const count = indices ? Math.floor(indices.length / 3) : Math.floor(n / 3);
|
|
286
|
+
const kept = [];
|
|
287
|
+
// Those culled, which a transform that turns the drawing over draws in their place.
|
|
288
|
+
const other = [];
|
|
289
|
+
const e = [
|
|
290
|
+
Infinity,
|
|
291
|
+
Infinity,
|
|
292
|
+
-Infinity,
|
|
293
|
+
-Infinity,
|
|
294
|
+
this.stroke ? Math.max(this.stroke.line.width / TWIPS, 1) / 2 : 0,
|
|
295
|
+
];
|
|
296
|
+
// Scalars, no arrays a triangle: a 3D engine draws thousands of them anew every frame.
|
|
297
|
+
for (let k = 0; k < count * 3; k += 3) {
|
|
298
|
+
const a = indices ? indices[k] : k;
|
|
299
|
+
const b = indices ? indices[k + 1] : k + 1;
|
|
300
|
+
const c = indices ? indices[k + 2] : k + 2;
|
|
301
|
+
if (!(a >= 0 && a < n && b >= 0 && b < n && c >= 0 && c < n)) {
|
|
302
|
+
break;
|
|
303
|
+
}
|
|
304
|
+
const x0 = vertices[2 * a];
|
|
305
|
+
const y0 = vertices[2 * a + 1];
|
|
306
|
+
const x1 = vertices[2 * b];
|
|
307
|
+
const y1 = vertices[2 * b + 1];
|
|
308
|
+
const x2 = vertices[2 * c];
|
|
309
|
+
const y2 = vertices[2 * c + 1];
|
|
310
|
+
e[0] = Math.min(e[0], x0, x1, x2);
|
|
311
|
+
e[1] = Math.min(e[1], y0, y1, y2);
|
|
312
|
+
e[2] = Math.max(e[2], x0, x1, x2);
|
|
313
|
+
e[3] = Math.max(e[3], y0, y1, y2);
|
|
314
|
+
const turn = cull * ((x1 - x0) * (y2 - y0) - (y1 - y0) * (x2 - x0));
|
|
315
|
+
if (turn <= 0) {
|
|
316
|
+
kept.push(a, b, c);
|
|
317
|
+
}
|
|
318
|
+
if (cull && turn >= 0) {
|
|
319
|
+
other.push(a, b, c);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
if (e[0] > e[2]) {
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
this.version++;
|
|
326
|
+
const fill = this.fill;
|
|
327
|
+
const line = this.stroke?.line ?? null;
|
|
328
|
+
const contour = fill?.contours[fill.contours.length - 1];
|
|
329
|
+
const origin = contour ? [contour[1], contour[2]] : [this.x, this.y];
|
|
330
|
+
// The open contour ends for good, with any closing line it has.
|
|
331
|
+
this.closing = null;
|
|
332
|
+
this.dropStroke();
|
|
333
|
+
if (this.fillLayer) {
|
|
334
|
+
this.dropEmpty(this.fillLayer, this.fillStart);
|
|
335
|
+
}
|
|
336
|
+
const paint = fill?.fill;
|
|
337
|
+
const image = paint?.type === "image" && paint.image instanceof BitmapStore ? paint : null;
|
|
338
|
+
const outline = (list, k) => {
|
|
339
|
+
const a = 2 * list[k];
|
|
340
|
+
const b = 2 * list[k + 1];
|
|
341
|
+
const c = 2 * list[k + 2];
|
|
342
|
+
const x0 = vertices[a];
|
|
343
|
+
const y0 = vertices[a + 1];
|
|
344
|
+
return [
|
|
345
|
+
MOVE,
|
|
346
|
+
x0,
|
|
347
|
+
y0,
|
|
348
|
+
LINE,
|
|
349
|
+
vertices[b],
|
|
350
|
+
vertices[b + 1],
|
|
351
|
+
LINE,
|
|
352
|
+
vertices[c],
|
|
353
|
+
vertices[c + 1],
|
|
354
|
+
LINE,
|
|
355
|
+
x0,
|
|
356
|
+
y0,
|
|
357
|
+
];
|
|
358
|
+
};
|
|
359
|
+
const parts = (list) => {
|
|
360
|
+
const out = { fills: [] };
|
|
361
|
+
if (uvt && image) {
|
|
362
|
+
const positions = new Float32Array(list.length * 2);
|
|
363
|
+
const coordinates = new Float32Array(list.length * 3);
|
|
364
|
+
for (let i = 0; i < list.length; i++) {
|
|
365
|
+
const v = list[i];
|
|
366
|
+
positions[2 * i] = vertices[2 * v];
|
|
367
|
+
positions[2 * i + 1] = vertices[2 * v + 1];
|
|
368
|
+
coordinates[3 * i] = uvt[3 * v];
|
|
369
|
+
coordinates[3 * i + 1] = uvt[3 * v + 1];
|
|
370
|
+
coordinates[3 * i + 2] = uvt[3 * v + 2];
|
|
371
|
+
}
|
|
372
|
+
out.meshes = [
|
|
373
|
+
{
|
|
374
|
+
image: image.image,
|
|
375
|
+
repeat: image.repeat,
|
|
376
|
+
smooth: image.smooth,
|
|
377
|
+
positions,
|
|
378
|
+
uvt: coordinates,
|
|
379
|
+
},
|
|
380
|
+
];
|
|
381
|
+
}
|
|
382
|
+
else if (!uvt && paint) {
|
|
383
|
+
for (let k = 0; k < list.length; k += 3) {
|
|
384
|
+
out.fills.push({ fill: paint, contours: [outline(list, k)], winding: "evenOdd" });
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
if (line && (!uvt || image || !paint) && list.length) {
|
|
388
|
+
const paths = [];
|
|
389
|
+
for (let k = 0; k < list.length; k += 3) {
|
|
390
|
+
paths.push(outline(list, k));
|
|
391
|
+
}
|
|
392
|
+
out.stroke = { line, paths, triangles: true };
|
|
393
|
+
}
|
|
394
|
+
return out;
|
|
395
|
+
};
|
|
396
|
+
const own = parts(kept);
|
|
397
|
+
const layer = {
|
|
398
|
+
fills: own.fills,
|
|
399
|
+
strokes: own.stroke ? [own.stroke] : [],
|
|
400
|
+
extent: e,
|
|
401
|
+
};
|
|
402
|
+
if (own.meshes) {
|
|
403
|
+
layer.meshes = own.meshes;
|
|
404
|
+
}
|
|
405
|
+
if (cull) {
|
|
406
|
+
layer.mirrored = parts(other);
|
|
407
|
+
this.culled = true;
|
|
408
|
+
}
|
|
409
|
+
this.layers.push(layer);
|
|
410
|
+
if (!fill && !line) {
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
const next = { fills: [], strokes: [] };
|
|
414
|
+
this.layers.push(next);
|
|
415
|
+
this.resumed = next;
|
|
416
|
+
if (fill) {
|
|
417
|
+
this.fill = { fill: fill.fill, contours: [], winding: fill.winding };
|
|
418
|
+
this.fillLayer = next;
|
|
419
|
+
this.fillStart = 0;
|
|
420
|
+
next.fills.push(this.fill);
|
|
421
|
+
const [ox, oy] = origin;
|
|
422
|
+
const away = ox !== this.x || oy !== this.y;
|
|
423
|
+
this.fill.contours.push(away ? [MOVE, ox, oy, LINE, this.x, this.y] : [MOVE, ox, oy]);
|
|
424
|
+
this.heading = false;
|
|
425
|
+
this.bent = false;
|
|
426
|
+
if (away) {
|
|
427
|
+
this.bend([this.x, this.y]);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
if (line) {
|
|
431
|
+
this.stroke = { line, paths: [] };
|
|
432
|
+
next.strokes.push(this.stroke);
|
|
433
|
+
this.begin(this.stroke.paths);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
clear() {
|
|
437
|
+
this.version++;
|
|
438
|
+
this.layers.length = 0;
|
|
439
|
+
this.fill = null;
|
|
440
|
+
this.fillLayer = null;
|
|
441
|
+
this.stroke = null;
|
|
442
|
+
this.closing = null;
|
|
443
|
+
this.pathed = false;
|
|
444
|
+
this.resumed = null;
|
|
445
|
+
this.culled = false;
|
|
446
|
+
this.x = 0;
|
|
447
|
+
this.y = 0;
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* The other drawing's layers, copied, after this one is cleared: a
|
|
451
|
+
* drawing copied from itself ends empty, as Flash's does (the `draws`
|
|
452
|
+
* case). The styles open there do not come.
|
|
453
|
+
*/
|
|
454
|
+
copyFrom(other) {
|
|
455
|
+
this.clear();
|
|
456
|
+
for (const layer of other.layers) {
|
|
457
|
+
this.layers.push({
|
|
458
|
+
fills: layer.fills.map((f) => ({ ...f, contours: f.contours.map((c) => c.slice()) })),
|
|
459
|
+
strokes: layer.strokes.map((s) => ({
|
|
460
|
+
line: s.line,
|
|
461
|
+
paths: s.paths.map((c) => c.slice()),
|
|
462
|
+
closes: s.closes?.map((c) => ({ ...c })),
|
|
463
|
+
triangles: s.triangles,
|
|
464
|
+
})),
|
|
465
|
+
// A mesh's arrays never change once drawn.
|
|
466
|
+
meshes: layer.meshes?.slice(),
|
|
467
|
+
extent: layer.extent,
|
|
468
|
+
// Never changed once drawn.
|
|
469
|
+
mirrored: layer.mirrored,
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
this.culled = other.culled;
|
|
473
|
+
this.version++;
|
|
474
|
+
}
|
|
475
|
+
/** The drawing's extent, in pixels, curves at their true extremes; the lines' paths count, and with `lines` their half widths too. */
|
|
476
|
+
bounds(lines) {
|
|
477
|
+
const kept = this.kept[lines ? 1 : 0];
|
|
478
|
+
if (kept?.version === this.version) {
|
|
479
|
+
return kept.r;
|
|
480
|
+
}
|
|
481
|
+
let r = null;
|
|
482
|
+
const take = (path, pad) => {
|
|
483
|
+
const e = extent(path);
|
|
484
|
+
if (e) {
|
|
485
|
+
r = union(r, { xMin: e[0] - pad, yMin: e[1] - pad, xMax: e[2] + pad, yMax: e[3] + pad });
|
|
486
|
+
}
|
|
487
|
+
};
|
|
488
|
+
for (const layer of this.layers) {
|
|
489
|
+
const e = layer.extent;
|
|
490
|
+
if (e) {
|
|
491
|
+
const pad = lines ? e[4] : 0;
|
|
492
|
+
r = union(r, { xMin: e[0] - pad, yMin: e[1] - pad, xMax: e[2] + pad, yMax: e[3] + pad });
|
|
493
|
+
}
|
|
494
|
+
for (const f of layer.fills) {
|
|
495
|
+
for (const c of f.contours) {
|
|
496
|
+
take(c, 0);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
for (const s of layer.strokes) {
|
|
500
|
+
for (const p of s.paths) {
|
|
501
|
+
take(p, lines ? Math.max(s.line.width / TWIPS, 1) / 2 : 0);
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
this.kept[lines ? 1 : 0] = { version: this.version, r };
|
|
506
|
+
return r;
|
|
507
|
+
}
|
|
508
|
+
/** The open stroke ends; taken away if it drew nothing, with its layer if that is left empty. */
|
|
509
|
+
dropStroke() {
|
|
510
|
+
const stroke = this.stroke;
|
|
511
|
+
const layer = this.layers[this.layers.length - 1];
|
|
512
|
+
this.stroke = null;
|
|
513
|
+
if (!stroke || !layer || stroke.closes?.length || stroke.paths.some((p) => p.length > 3)) {
|
|
514
|
+
return;
|
|
515
|
+
}
|
|
516
|
+
// Always the layer's last.
|
|
517
|
+
this.version++;
|
|
518
|
+
layer.strokes.pop();
|
|
519
|
+
if (!layer.fills.length && !layer.strokes.length) {
|
|
520
|
+
this.layers.pop();
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
/** A move, closing the open contour for good: a fill's contour and a stroke's path begin there. */
|
|
524
|
+
move(x, y) {
|
|
525
|
+
this.closing = null;
|
|
526
|
+
this.x = x;
|
|
527
|
+
this.y = y;
|
|
528
|
+
if (this.fill) {
|
|
529
|
+
this.beginContour();
|
|
530
|
+
}
|
|
531
|
+
if (this.stroke) {
|
|
532
|
+
this.begin(this.stroke.paths);
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
beginContour() {
|
|
536
|
+
this.begin(this.fill.contours);
|
|
537
|
+
this.heading = false;
|
|
538
|
+
this.bent = false;
|
|
539
|
+
}
|
|
540
|
+
/** A contour or stroke path begins at the pen. */
|
|
541
|
+
begin(paths) {
|
|
542
|
+
this.version++;
|
|
543
|
+
paths.push([MOVE, this.x, this.y]);
|
|
544
|
+
}
|
|
545
|
+
/** `points` added to the open contour and path with `kind`, copied: they may be scratch. */
|
|
546
|
+
command(kind, points) {
|
|
547
|
+
this.version++;
|
|
548
|
+
this.unclose();
|
|
549
|
+
if (this.fill) {
|
|
550
|
+
append(this.fill.contours, kind, points);
|
|
551
|
+
}
|
|
552
|
+
if (this.stroke) {
|
|
553
|
+
append(this.stroke.paths, kind, points);
|
|
554
|
+
}
|
|
555
|
+
this.x = points[points.length - 2];
|
|
556
|
+
this.y = points[points.length - 1];
|
|
557
|
+
if (this.fill) {
|
|
558
|
+
this.bend(points);
|
|
559
|
+
this.reclose();
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
/** Whether the contour's new points, control points too, leave the line it has run along. */
|
|
563
|
+
bend(points) {
|
|
564
|
+
const contour = this.fill?.contours[this.fill.contours.length - 1];
|
|
565
|
+
if (this.bent || !contour) {
|
|
566
|
+
return;
|
|
567
|
+
}
|
|
568
|
+
const sx = contour[1];
|
|
569
|
+
const sy = contour[2];
|
|
570
|
+
for (let i = 0; i < points.length; i += 2) {
|
|
571
|
+
const dx = points[i] - sx;
|
|
572
|
+
const dy = points[i + 1] - sy;
|
|
573
|
+
if (!this.heading) {
|
|
574
|
+
if (dx || dy) {
|
|
575
|
+
this.towardX = dx;
|
|
576
|
+
this.towardY = dy;
|
|
577
|
+
this.heading = true;
|
|
578
|
+
}
|
|
579
|
+
continue;
|
|
580
|
+
}
|
|
581
|
+
const tx = this.towardX;
|
|
582
|
+
const ty = this.towardY;
|
|
583
|
+
if (Math.abs(tx * dy - ty * dx) >
|
|
584
|
+
1e-9 * (Math.abs(tx) + Math.abs(ty)) * (Math.abs(dx) + Math.abs(dy))) {
|
|
585
|
+
this.bent = true;
|
|
586
|
+
return;
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
/** The closing line taken off, for the contour or the line style to go on. */
|
|
591
|
+
unclose() {
|
|
592
|
+
if (this.closing) {
|
|
593
|
+
this.version++;
|
|
594
|
+
this.closing.stroke.closes?.pop();
|
|
595
|
+
this.closing = null;
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
/** The open contour's closing line, from the pen back to its start, on the end of the stroke's path. */
|
|
599
|
+
reclose() {
|
|
600
|
+
const contour = this.fill?.contours[this.fill.contours.length - 1];
|
|
601
|
+
const stroke = this.stroke;
|
|
602
|
+
if (!contour || !stroke || !this.bent || this.pathed) {
|
|
603
|
+
return;
|
|
604
|
+
}
|
|
605
|
+
if (contour[1] !== this.x || contour[2] !== this.y) {
|
|
606
|
+
const close = { at: stroke.paths.length - 1, x: contour[1], y: contour[2] };
|
|
607
|
+
stroke.closes = stroke.closes ?? [];
|
|
608
|
+
stroke.closes.push(close);
|
|
609
|
+
this.closing = { stroke, close };
|
|
610
|
+
this.version++;
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
}
|