pythonnative 0.40.0__cp313-cp313-win_amd64.whl
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.
- pythonnative/__init__.py +411 -0
- pythonnative/_ios_log.py +92 -0
- pythonnative/_yoga.cp313-win_amd64.pyd +0 -0
- pythonnative/alerts.py +236 -0
- pythonnative/animated.py +1687 -0
- pythonnative/animation_graph.py +78 -0
- pythonnative/appearance.py +124 -0
- pythonnative/bootstrap.py +100 -0
- pythonnative/bridge/__init__.py +302 -0
- pythonnative/bridge/android.py +78 -0
- pythonnative/bridge/codec.py +170 -0
- pythonnative/bridge/commits.py +114 -0
- pythonnative/bridge/fake.py +243 -0
- pythonnative/bridge/ios.py +138 -0
- pythonnative/bridge/web.py +489 -0
- pythonnative/cli/__init__.py +7 -0
- pythonnative/cli/pn.py +1214 -0
- pythonnative/component.py +271 -0
- pythonnative/components/__init__.py +111 -0
- pythonnative/components/_base.py +166 -0
- pythonnative/components/controls.py +521 -0
- pythonnative/components/layout.py +518 -0
- pythonnative/components/lists.py +785 -0
- pythonnative/components/media.py +204 -0
- pythonnative/components/overlays.py +107 -0
- pythonnative/components/pressable.py +252 -0
- pythonnative/components/structural.py +167 -0
- pythonnative/components/text.py +291 -0
- pythonnative/devclient.py +824 -0
- pythonnative/devserver/__init__.py +34 -0
- pythonnative/devserver/server.py +718 -0
- pythonnative/devserver/static/animation_graph.js +82 -0
- pythonnative/devserver/static/bridge.js +147 -0
- pythonnative/devserver/static/colors.js +70 -0
- pythonnative/devserver/static/host.js +552 -0
- pythonnative/devserver/static/index.html +60 -0
- pythonnative/devserver/static/layout.js +85 -0
- pythonnative/devserver/static/preview.css +415 -0
- pythonnative/devserver/static/renderer.js +1994 -0
- pythonnative/devserver/static/shell.js +345 -0
- pythonnative/devserver/static/yoga/LICENSE +21 -0
- pythonnative/devserver/static/yoga/binaries/yoga-wasm-base64-esm.js +75 -0
- pythonnative/devserver/static/yoga/src/generated/YGEnums.d.ts +189 -0
- pythonnative/devserver/static/yoga/src/generated/YGEnums.js +211 -0
- pythonnative/devserver/static/yoga/src/generated/YGEnums.js.map +1 -0
- pythonnative/devserver/static/yoga/src/index.d.ts +12 -0
- pythonnative/devserver/static/yoga/src/index.js +16 -0
- pythonnative/devserver/static/yoga/src/index.js.map +1 -0
- pythonnative/devserver/static/yoga/src/load.d.ts +11 -0
- pythonnative/devserver/static/yoga/src/load.js +17 -0
- pythonnative/devserver/static/yoga/src/load.js.map +1 -0
- pythonnative/devserver/static/yoga/src/wrapAssembly.d.ts +155 -0
- pythonnative/devserver/static/yoga/src/wrapAssembly.js +125 -0
- pythonnative/devserver/static/yoga/src/wrapAssembly.js.map +1 -0
- pythonnative/devserver/watcher.py +267 -0
- pythonnative/devserver/ws.py +421 -0
- pythonnative/diagnostics.py +241 -0
- pythonnative/element.py +159 -0
- pythonnative/equality.py +19 -0
- pythonnative/events.py +231 -0
- pythonnative/gestures.py +1333 -0
- pythonnative/hooks.py +1621 -0
- pythonnative/hosts/__init__.py +63 -0
- pythonnative/hosts/base.py +596 -0
- pythonnative/hosts/native.py +302 -0
- pythonnative/hot_reload.py +585 -0
- pythonnative/layout.py +328 -0
- pythonnative/mutations.py +142 -0
- pythonnative/native/android/build.gradle +52 -0
- pythonnative/native/android/gradle.properties +3 -0
- pythonnative/native/android/settings.gradle +12 -0
- pythonnative/native/android/src/main/AndroidManifest.xml +11 -0
- pythonnative/native/android/src/main/cpp/CMakeLists.txt +9 -0
- pythonnative/native/android/src/main/cpp/yoga_jni.cpp +52 -0
- pythonnative/native/android/src/main/java/com/pythonnative/generated/NativeModules.kt +5 -0
- pythonnative/native/android/src/main/java/com/pythonnative/generated/NativeProps.kt +3705 -0
- pythonnative/native/android/src/main/java/com/pythonnative/generated/PNContracts.kt +129 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/PNBridge.kt +261 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/PythonHost.kt +20 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/animation/AnimationGraph.kt +108 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/animation/AnimationSpecs.kt +141 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/animation/PNAnimator.kt +257 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/bridge/CommitState.kt +106 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/bridge/JsonUtil.kt +175 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/bridge/MainThread.kt +40 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/bridge/PNLog.kt +33 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/bridge/PNRegistry.kt +82 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/bridge/PNTransaction.kt +80 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/bridge/TransactionApplier.kt +117 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/bridge/ViewRegistry.kt +74 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/BuiltinComponents.kt +37 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/ButtonManager.kt +32 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/ComponentManager.kt +213 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/ContainerManagers.kt +69 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/ControlManagers.kt +186 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/DatePickerManager.kt +123 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/ImageLoader.kt +141 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/ImageManager.kt +162 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/ModalManager.kt +134 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/PNColor.kt +201 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/PickerManager.kt +86 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/PortalManager.kt +55 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/PressableManager.kt +122 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/ScreenStackManager.kt +110 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/ScrollViewManager.kt +214 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/SegmentedControlManager.kt +113 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/StatusBarManager.kt +52 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/TabBarManager.kt +131 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/TextInputManager.kt +250 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/TextManager.kt +233 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/ViewStyler.kt +355 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/VirtualListManager.kt +159 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/WebViewManager.kt +149 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/gestures/GestureArbiter.kt +233 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/gestures/GestureCoordinator.kt +127 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/gestures/GestureRecognizers.kt +527 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/layout/NativeLayout.kt +145 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/layout/YogaNode.kt +29 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/modules/BuiltinModules.kt +73 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/modules/DeviceModules.kt +316 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/modules/HostModule.kt +61 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/modules/MediaModules.kt +200 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/modules/NativeModule.kt +158 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/modules/NotificationsModule.kt +100 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/modules/PermissionsModule.kt +99 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/modules/StorageModules.kt +89 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/modules/SystemModules.kt +178 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/plugins/GeneratedPlugins.kt +16 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/screens/PNScreenFragment.kt +188 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/screens/ScreenRegistry.kt +80 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/views/PNAccessibilityDelegate.kt +48 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/views/PNBorderDrawable.kt +76 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/views/PNEditText.kt +18 -0
- pythonnative/native/android/src/main/java/com/pythonnative/runtime/views/PNFrameLayout.kt +49 -0
- pythonnative/native/android/src/test/java/com/pythonnative/runtime/AnimationSpecsTest.kt +75 -0
- pythonnative/native/android/src/test/java/com/pythonnative/runtime/GestureArbiterTest.kt +197 -0
- pythonnative/native/android/src/test/java/com/pythonnative/runtime/PNColorTest.kt +47 -0
- pythonnative/native/android/src/test/java/com/pythonnative/runtime/PNTransactionTest.kt +78 -0
- pythonnative/native/android/src/test/java/com/pythonnative/runtime/PromiseTest.kt +89 -0
- pythonnative/native/ios/Package.swift +23 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Animation/PNAnimationGraph.swift +199 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Animation/PNAnimator.swift +312 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Bridge/PNBridge.swift +255 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Bridge/PNCommit.swift +104 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Bridge/PNRegistry.swift +142 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Bridge/PNTransaction.swift +166 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Bridge/PNViewRegistry.swift +53 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Components/PNButtonManagers.swift +207 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Components/PNColor.swift +173 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Components/PNComponentManager.swift +183 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Components/PNContainerView.swift +56 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Components/PNControlManagers.swift +281 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Components/PNImageManager.swift +222 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Components/PNOverlayManagers.swift +243 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Components/PNPressableManager.swift +114 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Components/PNScreenStackManager.swift +107 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Components/PNScrollViewManager.swift +197 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Components/PNTabBarManager.swift +106 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Components/PNTextInputManager.swift +297 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Components/PNTextManager.swift +230 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Components/PNTransform.swift +82 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Components/PNViewManager.swift +86 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Components/PNViewState.swift +87 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Components/PNViewStyler.swift +340 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Components/PNVirtualListManager.swift +155 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Components/PNWebViewManager.swift +124 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Generated/NativeModules.swift +1 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Generated/NativeProps.swift +3775 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Generated/PNContracts.swift +46 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Gestures/PNGestureCoordinator.swift +260 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Layout/PNLayout.swift +173 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Modules/AlertModule.swift +92 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Modules/HostModule.swift +80 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Modules/LifecycleModules.swift +174 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Modules/MediaModules.swift +177 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Modules/PNNativeModule.swift +168 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Modules/PermissionModules.swift +266 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Modules/SystemModules.swift +251 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Plugins/PNPluginRegistration.swift +8 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Screens/PNScreenRegistry.swift +46 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Screens/PNViewController.swift +237 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Support/PNCompat.swift +46 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Support/PNJSON.swift +173 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Support/PNLog.swift +47 -0
- pythonnative/native/ios/Sources/PythonNativeKit/Support/PNWindow.swift +51 -0
- pythonnative/native/ios/Tests/PythonNativeKitTests/PNAnimationGraphTests.swift +26 -0
- pythonnative/native/ios/Tests/PythonNativeKitTests/PNColorTests.swift +50 -0
- pythonnative/native/ios/Tests/PythonNativeKitTests/PNCommitTests.swift +86 -0
- pythonnative/native/ios/Tests/PythonNativeKitTests/PNGestureTests.swift +101 -0
- pythonnative/native/ios/Tests/PythonNativeKitTests/PNManagerTests.swift +126 -0
- pythonnative/native/ios/Tests/PythonNativeKitTests/PNModuleTests.swift +111 -0
- pythonnative/native/ios/Tests/PythonNativeKitTests/PNTransactionTests.swift +91 -0
- pythonnative/native/yoga/LICENSE +21 -0
- pythonnative/native/yoga/Package.swift +9 -0
- pythonnative/native/yoga/VENDORED.md +2 -0
- pythonnative/native/yoga/include/PNStyle.h +10 -0
- pythonnative/native/yoga/include/module.modulemap +5 -0
- pythonnative/native/yoga/include/yoga/YGConfig.h +158 -0
- pythonnative/native/yoga/include/yoga/YGEnums.h +142 -0
- pythonnative/native/yoga/include/yoga/YGMacros.h +99 -0
- pythonnative/native/yoga/include/yoga/YGNode.h +304 -0
- pythonnative/native/yoga/include/yoga/YGNodeLayout.h +35 -0
- pythonnative/native/yoga/include/yoga/YGNodeStyle.h +130 -0
- pythonnative/native/yoga/include/yoga/YGPixelGrid.h +29 -0
- pythonnative/native/yoga/include/yoga/YGValue.h +84 -0
- pythonnative/native/yoga/include/yoga/Yoga.h +21 -0
- pythonnative/native/yoga/python.cpp +16 -0
- pythonnative/native/yoga/style.cpp +272 -0
- pythonnative/native/yoga/yoga/CMakeLists.txt +41 -0
- pythonnative/native/yoga/yoga/YGConfig.cpp +92 -0
- pythonnative/native/yoga/yoga/YGConfig.h +158 -0
- pythonnative/native/yoga/yoga/YGEnums.cpp +262 -0
- pythonnative/native/yoga/yoga/YGEnums.h +142 -0
- pythonnative/native/yoga/yoga/YGMacros.h +99 -0
- pythonnative/native/yoga/yoga/YGNode.cpp +366 -0
- pythonnative/native/yoga/yoga/YGNode.h +304 -0
- pythonnative/native/yoga/yoga/YGNodeLayout.cpp +92 -0
- pythonnative/native/yoga/yoga/YGNodeLayout.h +35 -0
- pythonnative/native/yoga/yoga/YGNodeStyle.cpp +405 -0
- pythonnative/native/yoga/yoga/YGNodeStyle.h +130 -0
- pythonnative/native/yoga/yoga/YGPixelGrid.cpp +22 -0
- pythonnative/native/yoga/yoga/YGPixelGrid.h +29 -0
- pythonnative/native/yoga/yoga/YGValue.cpp +20 -0
- pythonnative/native/yoga/yoga/YGValue.h +84 -0
- pythonnative/native/yoga/yoga/Yoga.h +21 -0
- pythonnative/native/yoga/yoga/algorithm/AbsoluteLayout.cpp +563 -0
- pythonnative/native/yoga/yoga/algorithm/AbsoluteLayout.h +41 -0
- pythonnative/native/yoga/yoga/algorithm/Align.h +72 -0
- pythonnative/native/yoga/yoga/algorithm/Baseline.cpp +78 -0
- pythonnative/native/yoga/yoga/algorithm/Baseline.h +21 -0
- pythonnative/native/yoga/yoga/algorithm/BoundAxis.h +79 -0
- pythonnative/native/yoga/yoga/algorithm/Cache.cpp +121 -0
- pythonnative/native/yoga/yoga/algorithm/Cache.h +30 -0
- pythonnative/native/yoga/yoga/algorithm/CalculateLayout.cpp +2428 -0
- pythonnative/native/yoga/yoga/algorithm/CalculateLayout.h +38 -0
- pythonnative/native/yoga/yoga/algorithm/FlexDirection.h +120 -0
- pythonnative/native/yoga/yoga/algorithm/FlexLine.cpp +124 -0
- pythonnative/native/yoga/yoga/algorithm/FlexLine.h +75 -0
- pythonnative/native/yoga/yoga/algorithm/PixelGrid.cpp +132 -0
- pythonnative/native/yoga/yoga/algorithm/PixelGrid.h +29 -0
- pythonnative/native/yoga/yoga/algorithm/SizingMode.h +73 -0
- pythonnative/native/yoga/yoga/algorithm/TrailingPosition.h +44 -0
- pythonnative/native/yoga/yoga/config/Config.cpp +135 -0
- pythonnative/native/yoga/yoga/config/Config.h +92 -0
- pythonnative/native/yoga/yoga/debug/AssertFatal.cpp +53 -0
- pythonnative/native/yoga/yoga/debug/AssertFatal.h +29 -0
- pythonnative/native/yoga/yoga/debug/Log.cpp +107 -0
- pythonnative/native/yoga/yoga/debug/Log.h +34 -0
- pythonnative/native/yoga/yoga/enums/Align.h +47 -0
- pythonnative/native/yoga/yoga/enums/BoxSizing.h +40 -0
- pythonnative/native/yoga/yoga/enums/Dimension.h +40 -0
- pythonnative/native/yoga/yoga/enums/Direction.h +41 -0
- pythonnative/native/yoga/yoga/enums/Display.h +41 -0
- pythonnative/native/yoga/yoga/enums/Edge.h +47 -0
- pythonnative/native/yoga/yoga/enums/Errata.h +41 -0
- pythonnative/native/yoga/yoga/enums/ExperimentalFeature.h +39 -0
- pythonnative/native/yoga/yoga/enums/FlexDirection.h +42 -0
- pythonnative/native/yoga/yoga/enums/Gutter.h +41 -0
- pythonnative/native/yoga/yoga/enums/Justify.h +44 -0
- pythonnative/native/yoga/yoga/enums/LogLevel.h +44 -0
- pythonnative/native/yoga/yoga/enums/MeasureMode.h +41 -0
- pythonnative/native/yoga/yoga/enums/NodeType.h +40 -0
- pythonnative/native/yoga/yoga/enums/Overflow.h +41 -0
- pythonnative/native/yoga/yoga/enums/PhysicalEdge.h +21 -0
- pythonnative/native/yoga/yoga/enums/PositionType.h +41 -0
- pythonnative/native/yoga/yoga/enums/Unit.h +42 -0
- pythonnative/native/yoga/yoga/enums/Wrap.h +41 -0
- pythonnative/native/yoga/yoga/enums/YogaEnums.h +85 -0
- pythonnative/native/yoga/yoga/event/event.cpp +87 -0
- pythonnative/native/yoga/yoga/event/event.h +130 -0
- pythonnative/native/yoga/yoga/module.modulemap +21 -0
- pythonnative/native/yoga/yoga/node/CachedMeasurement.h +53 -0
- pythonnative/native/yoga/yoga/node/LayoutResults.cpp +48 -0
- pythonnative/native/yoga/yoga/node/LayoutResults.h +122 -0
- pythonnative/native/yoga/yoga/node/LayoutableChildren.h +148 -0
- pythonnative/native/yoga/yoga/node/Node.cpp +443 -0
- pythonnative/native/yoga/yoga/node/Node.h +337 -0
- pythonnative/native/yoga/yoga/numeric/Comparison.h +81 -0
- pythonnative/native/yoga/yoga/numeric/FloatOptional.h +93 -0
- pythonnative/native/yoga/yoga/style/SmallValueBuffer.h +133 -0
- pythonnative/native/yoga/yoga/style/Style.h +757 -0
- pythonnative/native/yoga/yoga/style/StyleLength.h +107 -0
- pythonnative/native/yoga/yoga/style/StyleValueHandle.h +98 -0
- pythonnative/native/yoga/yoga/style/StyleValuePool.h +127 -0
- pythonnative/native_modules/__init__.py +124 -0
- pythonnative/native_modules/app_state.py +99 -0
- pythonnative/native_modules/battery.py +75 -0
- pythonnative/native_modules/biometrics.py +42 -0
- pythonnative/native_modules/camera.py +65 -0
- pythonnative/native_modules/clipboard.py +46 -0
- pythonnative/native_modules/fallback.py +324 -0
- pythonnative/native_modules/file_system.py +145 -0
- pythonnative/native_modules/haptics.py +75 -0
- pythonnative/native_modules/linking.py +123 -0
- pythonnative/native_modules/location.py +75 -0
- pythonnative/native_modules/net_info.py +112 -0
- pythonnative/native_modules/notifications.py +129 -0
- pythonnative/native_modules/permissions.py +108 -0
- pythonnative/native_modules/registry.py +526 -0
- pythonnative/native_modules/secure_store.py +52 -0
- pythonnative/native_modules/share.py +51 -0
- pythonnative/native_views/__init__.py +375 -0
- pythonnative/native_views/base.py +316 -0
- pythonnative/native_views/bridge_backend.py +277 -0
- pythonnative/navigation/__init__.py +103 -0
- pythonnative/navigation/container.py +154 -0
- pythonnative/navigation/handle.py +540 -0
- pythonnative/navigation/hooks.py +133 -0
- pythonnative/navigation/host.py +58 -0
- pythonnative/navigation/linking.py +200 -0
- pythonnative/navigation/navigators.py +659 -0
- pythonnative/navigation/screen.py +149 -0
- pythonnative/navigation/state.py +269 -0
- pythonnative/net.py +248 -0
- pythonnative/platform.py +166 -0
- pythonnative/platform_metrics.py +252 -0
- pythonnative/preview.py +287 -0
- pythonnative/profiling.py +101 -0
- pythonnative/project/__init__.py +68 -0
- pythonnative/project/android.py +557 -0
- pythonnative/project/builder.py +817 -0
- pythonnative/project/config.py +773 -0
- pythonnative/project/deps.py +719 -0
- pythonnative/project/devices.py +304 -0
- pythonnative/project/doctor.py +283 -0
- pythonnative/project/fingerprint.py +171 -0
- pythonnative/project/icons.py +247 -0
- pythonnative/project/ios.py +325 -0
- pythonnative/project/lockfile.py +100 -0
- pythonnative/project/permissions.py +361 -0
- pythonnative/project/plugins.py +519 -0
- pythonnative/project/runtime_assets.py +183 -0
- pythonnative/py.typed +0 -0
- pythonnative/query.py +153 -0
- pythonnative/reconciler/__init__.py +29 -0
- pythonnative/reconciler/boundaries.py +375 -0
- pythonnative/reconciler/children.py +88 -0
- pythonnative/reconciler/core.py +1165 -0
- pythonnative/reconciler/layout_pass.py +393 -0
- pythonnative/reconciler/vnode.py +266 -0
- pythonnative/refresh.py +55 -0
- pythonnative/runtime.py +306 -0
- pythonnative/scheduler.py +159 -0
- pythonnative/sdk/__init__.py +153 -0
- pythonnative/sdk/_components.py +427 -0
- pythonnative/sdk/builtins.py +91 -0
- pythonnative/sdk/codegen.py +149 -0
- pythonnative/sdk/module_codegen.py +184 -0
- pythonnative/sdk/schema.py +224 -0
- pythonnative/sdk/templates/contracts.kt +46 -0
- pythonnative/sdk/templates/contracts.swift +46 -0
- pythonnative/storage.py +184 -0
- pythonnative/style.py +841 -0
- pythonnative/suspense.py +183 -0
- pythonnative/templates/android_template/app/build.gradle +75 -0
- pythonnative/templates/android_template/app/proguard-rules.pro +21 -0
- pythonnative/templates/android_template/app/src/androidTest/java/com/pythonnative/android_template/ExampleInstrumentedTest.kt +24 -0
- pythonnative/templates/android_template/app/src/debug/AndroidManifest.xml +7 -0
- pythonnative/templates/android_template/app/src/main/AndroidManifest.xml +32 -0
- pythonnative/templates/android_template/app/src/main/java/com/pythonnative/android_template/MainActivity.kt +130 -0
- pythonnative/templates/android_template/app/src/main/java/com/pythonnative/android_template/ScreenFragment.kt +13 -0
- pythonnative/templates/android_template/app/src/main/res/drawable/ic_launcher_background.xml +170 -0
- pythonnative/templates/android_template/app/src/main/res/drawable-v24/ic_launcher_foreground.xml +30 -0
- pythonnative/templates/android_template/app/src/main/res/layout/activity_main.xml +10 -0
- pythonnative/templates/android_template/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml +6 -0
- pythonnative/templates/android_template/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml +6 -0
- pythonnative/templates/android_template/app/src/main/res/mipmap-hdpi/ic_launcher.webp +0 -0
- pythonnative/templates/android_template/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp +0 -0
- pythonnative/templates/android_template/app/src/main/res/mipmap-mdpi/ic_launcher.webp +0 -0
- pythonnative/templates/android_template/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp +0 -0
- pythonnative/templates/android_template/app/src/main/res/mipmap-xhdpi/ic_launcher.webp +0 -0
- pythonnative/templates/android_template/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp +0 -0
- pythonnative/templates/android_template/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp +0 -0
- pythonnative/templates/android_template/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp +0 -0
- pythonnative/templates/android_template/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp +0 -0
- pythonnative/templates/android_template/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp +0 -0
- pythonnative/templates/android_template/app/src/main/res/navigation/nav_graph.xml +22 -0
- pythonnative/templates/android_template/app/src/main/res/values/colors.xml +5 -0
- pythonnative/templates/android_template/app/src/main/res/values/strings.xml +5 -0
- pythonnative/templates/android_template/app/src/main/res/values/themes.xml +9 -0
- pythonnative/templates/android_template/app/src/main/res/values-night/themes.xml +7 -0
- pythonnative/templates/android_template/app/src/main/res/xml/backup_rules.xml +13 -0
- pythonnative/templates/android_template/app/src/main/res/xml/data_extraction_rules.xml +19 -0
- pythonnative/templates/android_template/app/src/test/java/com/pythonnative/android_template/ExampleUnitTest.kt +17 -0
- pythonnative/templates/android_template/build.gradle +10 -0
- pythonnative/templates/android_template/gradle/wrapper/gradle-wrapper.jar +0 -0
- pythonnative/templates/android_template/gradle/wrapper/gradle-wrapper.properties +6 -0
- pythonnative/templates/android_template/gradle.properties +23 -0
- pythonnative/templates/android_template/gradlew +185 -0
- pythonnative/templates/android_template/gradlew.bat +89 -0
- pythonnative/templates/android_template/settings.gradle +17 -0
- pythonnative/templates/ios_template/ios_template/AppDelegate.swift +51 -0
- pythonnative/templates/ios_template/ios_template/Assets.xcassets/AccentColor.colorset/Contents.json +11 -0
- pythonnative/templates/ios_template/ios_template/Assets.xcassets/AppIcon.appiconset/Contents.json +13 -0
- pythonnative/templates/ios_template/ios_template/Assets.xcassets/Contents.json +6 -0
- pythonnative/templates/ios_template/ios_template/Base.lproj/LaunchScreen.storyboard +25 -0
- pythonnative/templates/ios_template/ios_template/BridgingHeader.h +14 -0
- pythonnative/templates/ios_template/ios_template/Info.plist +28 -0
- pythonnative/templates/ios_template/ios_template/PythonRuntime.swift +390 -0
- pythonnative/templates/ios_template/ios_template/SceneDelegate.swift +61 -0
- pythonnative/templates/ios_template/ios_template/ViewController.swift +23 -0
- pythonnative/templates/ios_template/ios_template.xcodeproj/project.pbxproj +745 -0
- pythonnative/templates/ios_template/ios_template.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- pythonnative/templates/ios_template/ios_templateTests/ios_templateTests.swift +36 -0
- pythonnative/templates/ios_template/ios_templateUITests/ios_templateUITests.swift +41 -0
- pythonnative/templates/ios_template/ios_templateUITests/ios_templateUITestsLaunchTests.swift +32 -0
- pythonnative/testing/__init__.py +53 -0
- pythonnative/testing/backend.py +276 -0
- pythonnative/testing/harness.py +369 -0
- pythonnative/utils.py +145 -0
- pythonnative-0.40.0.dist-info/DELVEWHEEL +2 -0
- pythonnative-0.40.0.dist-info/METADATA +150 -0
- pythonnative-0.40.0.dist-info/RECORD +418 -0
- pythonnative-0.40.0.dist-info/WHEEL +5 -0
- pythonnative-0.40.0.dist-info/entry_points.txt +2 -0
- pythonnative-0.40.0.dist-info/licenses/LICENSE +21 -0
- pythonnative-0.40.0.dist-info/top_level.txt +1 -0
- pythonnative.libs/msvcp140-a4c2229bdc2a2a630acdc095b4d86008.dll +0 -0
|
@@ -0,0 +1,1994 @@
|
|
|
1
|
+
import { AnimationGraph } from "./animation_graph.js";
|
|
2
|
+
import {computeLayout, disposeLayout} from "./layout.js";
|
|
3
|
+
// The DOM "native runtime" for the browser preview.
|
|
4
|
+
//
|
|
5
|
+
// This module plays the role PythonNativeKit (Swift) and the pythonnative
|
|
6
|
+
// Gradle module (Kotlin) play on device: it applies transactions
|
|
7
|
+
// (create/update/insert/destroy/frame ops), answers `measure`,
|
|
8
|
+
// `command`, and `animate`, and raises `callback("event", ...)` for
|
|
9
|
+
// user interaction. Layout is not done here; the Python flexbox engine
|
|
10
|
+
// positions every view and sends frames in points, which are CSS px
|
|
11
|
+
// inside the phone frame.
|
|
12
|
+
//
|
|
13
|
+
// Component managers mirror the Swift `PN*Manager` classes prop for
|
|
14
|
+
// prop (see docs/concepts/bridge.md and the iOS sources); where the
|
|
15
|
+
// browser cannot honor a prop it is accepted and ignored, never thrown.
|
|
16
|
+
|
|
17
|
+
import { color as parseColor, isColorProp } from "./colors.js";
|
|
18
|
+
|
|
19
|
+
const INF = 1e6;
|
|
20
|
+
const isFiniteConstraint = (v) => typeof v === "number" && v > 0 && v < INF / 2;
|
|
21
|
+
const px = (v) => `${Math.round(v * 100) / 100}px`;
|
|
22
|
+
|
|
23
|
+
// ---------------------------------------------------------------------------
|
|
24
|
+
// Shared style application
|
|
25
|
+
// ---------------------------------------------------------------------------
|
|
26
|
+
|
|
27
|
+
const FONT_WEIGHTS = {
|
|
28
|
+
ultralight: 100,
|
|
29
|
+
thin: 200,
|
|
30
|
+
light: 300,
|
|
31
|
+
regular: 400,
|
|
32
|
+
normal: 400,
|
|
33
|
+
medium: 500,
|
|
34
|
+
semibold: 600,
|
|
35
|
+
bold: 700,
|
|
36
|
+
heavy: 800,
|
|
37
|
+
black: 900,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const COMMON_KEYS = new Set([
|
|
41
|
+
"background_color",
|
|
42
|
+
"overflow",
|
|
43
|
+
"display",
|
|
44
|
+
"opacity",
|
|
45
|
+
"z_index",
|
|
46
|
+
"pointer_events",
|
|
47
|
+
"hit_slop",
|
|
48
|
+
"border_radius",
|
|
49
|
+
"border_top_left_radius",
|
|
50
|
+
"border_top_right_radius",
|
|
51
|
+
"border_bottom_left_radius",
|
|
52
|
+
"border_bottom_right_radius",
|
|
53
|
+
"border_width",
|
|
54
|
+
"border_color",
|
|
55
|
+
"border_left_width",
|
|
56
|
+
"border_top_width",
|
|
57
|
+
"border_right_width",
|
|
58
|
+
"border_bottom_width",
|
|
59
|
+
"border_left_color",
|
|
60
|
+
"border_top_color",
|
|
61
|
+
"border_right_color",
|
|
62
|
+
"border_bottom_color",
|
|
63
|
+
"shadow_color",
|
|
64
|
+
"shadow_opacity",
|
|
65
|
+
"shadow_radius",
|
|
66
|
+
"shadow_offset",
|
|
67
|
+
"elevation",
|
|
68
|
+
"transform",
|
|
69
|
+
"accessible",
|
|
70
|
+
"accessibility_label",
|
|
71
|
+
"accessibility_hint",
|
|
72
|
+
"accessibility_role",
|
|
73
|
+
"accessibility_state",
|
|
74
|
+
"test_id",
|
|
75
|
+
]);
|
|
76
|
+
|
|
77
|
+
function offsetOf(value) {
|
|
78
|
+
if (Array.isArray(value)) return { x: Number(value[0]) || 0, y: Number(value[1]) || 0 };
|
|
79
|
+
if (value && typeof value === "object") return { x: Number(value.width) || 0, y: Number(value.height) || 0 };
|
|
80
|
+
return { x: 0, y: 0 };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function transformToCSS(value) {
|
|
84
|
+
if (value == null) return "";
|
|
85
|
+
const ops = Array.isArray(value) ? value : [value];
|
|
86
|
+
const parts = [];
|
|
87
|
+
for (const op of ops) {
|
|
88
|
+
if (!op || typeof op !== "object") continue;
|
|
89
|
+
for (const [key, raw] of Object.entries(op)) {
|
|
90
|
+
const n = typeof raw === "string" ? parseFloat(raw) : Number(raw);
|
|
91
|
+
if (!Number.isFinite(n)) return "";
|
|
92
|
+
switch (key) {
|
|
93
|
+
case "rotate": {
|
|
94
|
+
const rad = typeof raw === "string" && raw.endsWith("rad");
|
|
95
|
+
parts.push(`rotate(${rad ? n + "rad" : n + "deg"})`);
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
case "scale":
|
|
99
|
+
parts.push(`scale(${n})`);
|
|
100
|
+
break;
|
|
101
|
+
case "scale_x":
|
|
102
|
+
parts.push(`scaleX(${n})`);
|
|
103
|
+
break;
|
|
104
|
+
case "scale_y":
|
|
105
|
+
parts.push(`scaleY(${n})`);
|
|
106
|
+
break;
|
|
107
|
+
case "translate_x":
|
|
108
|
+
parts.push(`translateX(${n}px)`);
|
|
109
|
+
break;
|
|
110
|
+
case "translate_y":
|
|
111
|
+
parts.push(`translateY(${n}px)`);
|
|
112
|
+
break;
|
|
113
|
+
case "skew_x":
|
|
114
|
+
parts.push(`skewX(${n}deg)`);
|
|
115
|
+
break;
|
|
116
|
+
case "skew_y":
|
|
117
|
+
parts.push(`skewY(${n}deg)`);
|
|
118
|
+
break;
|
|
119
|
+
default:
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return parts.join(" ");
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** Style keys shared by containers and leaves. `leaf` skips the container-only ones. */
|
|
128
|
+
export function applyStyle(view, props, changed, scheme, { leaf = false } = {}) {
|
|
129
|
+
const el = view.el;
|
|
130
|
+
const s = el.style;
|
|
131
|
+
const c = (v) => parseColor(v, scheme);
|
|
132
|
+
const has = (k) => k in changed;
|
|
133
|
+
|
|
134
|
+
if (!leaf) {
|
|
135
|
+
if (has("background_color")) s.backgroundColor = c(props.background_color) ?? "";
|
|
136
|
+
if (has("overflow")) s.overflow = props.overflow === "hidden" ? "hidden" : "";
|
|
137
|
+
if (has("display")) s.display = props.display === "none" ? "none" : "";
|
|
138
|
+
if (has("z_index")) s.zIndex = props.z_index == null ? "" : String(props.z_index);
|
|
139
|
+
if (has("pointer_events")) {
|
|
140
|
+
const mode = props.pointer_events;
|
|
141
|
+
view.pointerMode = mode;
|
|
142
|
+
s.pointerEvents = mode === "none" || mode === "box_none" ? "none" : "";
|
|
143
|
+
for (const child of view.children) applyPointerInheritance(child, view);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if (has("opacity")) {
|
|
147
|
+
view.baseOpacity = props.opacity == null ? 1 : Number(props.opacity);
|
|
148
|
+
if (!view.pressedOpacityActive) s.opacity = props.opacity == null ? "" : String(props.opacity);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Corners.
|
|
152
|
+
const cornerKeys = [
|
|
153
|
+
"border_radius",
|
|
154
|
+
"border_top_left_radius",
|
|
155
|
+
"border_top_right_radius",
|
|
156
|
+
"border_bottom_left_radius",
|
|
157
|
+
"border_bottom_right_radius",
|
|
158
|
+
];
|
|
159
|
+
if (cornerKeys.some(has)) {
|
|
160
|
+
const r = props.border_radius;
|
|
161
|
+
const tl = props.border_top_left_radius ?? r;
|
|
162
|
+
const tr = props.border_top_right_radius ?? r;
|
|
163
|
+
const br = props.border_bottom_right_radius ?? r;
|
|
164
|
+
const bl = props.border_bottom_left_radius ?? r;
|
|
165
|
+
if ([tl, tr, br, bl].every((v) => v == null)) {
|
|
166
|
+
s.borderRadius = "";
|
|
167
|
+
} else {
|
|
168
|
+
s.borderRadius = [tl, tr, br, bl].map((v) => px(Number(v) || 0)).join(" ");
|
|
169
|
+
}
|
|
170
|
+
// iOS masks to bounds when a radius is set (unless a shadow asks otherwise).
|
|
171
|
+
if (r != null && !leaf && !view.hasShadow) s.overflow = props.overflow === "hidden" || r ? "hidden" : "";
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Borders: uniform or per side.
|
|
175
|
+
const borderKeys = [
|
|
176
|
+
"border_width",
|
|
177
|
+
"border_color",
|
|
178
|
+
"border_left_width",
|
|
179
|
+
"border_top_width",
|
|
180
|
+
"border_right_width",
|
|
181
|
+
"border_bottom_width",
|
|
182
|
+
"border_left_color",
|
|
183
|
+
"border_top_color",
|
|
184
|
+
"border_right_color",
|
|
185
|
+
"border_bottom_color",
|
|
186
|
+
];
|
|
187
|
+
if (borderKeys.some(has)) {
|
|
188
|
+
const uniformColor = c(props.border_color) ?? "#000";
|
|
189
|
+
const uniform = Number(props.border_width) || 0;
|
|
190
|
+
const sides = ["top", "right", "bottom", "left"];
|
|
191
|
+
for (const side of sides) {
|
|
192
|
+
const width = props[`border_${side}_width`];
|
|
193
|
+
const sideColor = c(props[`border_${side}_color`]);
|
|
194
|
+
const w = width != null ? Number(width) || 0 : uniform;
|
|
195
|
+
const Side = side[0].toUpperCase() + side.slice(1);
|
|
196
|
+
s[`border${Side}`] = w > 0 ? `${px(w)} solid ${sideColor ?? uniformColor}` : "";
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// Shadows.
|
|
201
|
+
const shadowKeys = ["shadow_color", "shadow_opacity", "shadow_radius", "shadow_offset", "elevation"];
|
|
202
|
+
if (shadowKeys.some(has)) {
|
|
203
|
+
const anyShadow = shadowKeys.some((k) => props[k] != null);
|
|
204
|
+
view.hasShadow = anyShadow;
|
|
205
|
+
if (!anyShadow) {
|
|
206
|
+
s.boxShadow = "";
|
|
207
|
+
} else {
|
|
208
|
+
const off = offsetOf(props.shadow_offset);
|
|
209
|
+
const radius = props.shadow_radius != null ? Number(props.shadow_radius) : Number(props.elevation) || 3;
|
|
210
|
+
const opacity = props.shadow_opacity != null ? Number(props.shadow_opacity) : props.elevation != null ? 0.25 : 0;
|
|
211
|
+
const base = c(props.shadow_color) ?? "#000";
|
|
212
|
+
const elevY = props.elevation != null && props.shadow_offset == null ? Number(props.elevation) / 2 : off.y;
|
|
213
|
+
s.boxShadow = `${px(off.x)} ${px(elevY)} ${px(radius * 2)} ${withAlpha(base, opacity)}`;
|
|
214
|
+
if (!leaf && props.overflow !== "hidden") s.overflow = "";
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (has("transform")) {
|
|
219
|
+
view.staticTransform = transformToCSS(props.transform);
|
|
220
|
+
composeTransform(view);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// Accessibility.
|
|
224
|
+
if (has("accessibility_label")) {
|
|
225
|
+
if (props.accessibility_label) el.setAttribute("aria-label", String(props.accessibility_label));
|
|
226
|
+
else el.removeAttribute("aria-label");
|
|
227
|
+
}
|
|
228
|
+
if (has("accessibility_hint")) {
|
|
229
|
+
if (props.accessibility_hint) el.setAttribute("title", String(props.accessibility_hint));
|
|
230
|
+
else el.removeAttribute("title");
|
|
231
|
+
}
|
|
232
|
+
if (has("accessibility_role")) {
|
|
233
|
+
if (props.accessibility_role) el.setAttribute("role", String(props.accessibility_role));
|
|
234
|
+
else el.removeAttribute("role");
|
|
235
|
+
}
|
|
236
|
+
if (has("test_id")) {
|
|
237
|
+
if (props.test_id) el.dataset.testid = String(props.test_id);
|
|
238
|
+
else delete el.dataset.testid;
|
|
239
|
+
}
|
|
240
|
+
if (has("accessibility_state") && props.accessibility_state && typeof props.accessibility_state === "object") {
|
|
241
|
+
const st = props.accessibility_state;
|
|
242
|
+
if ("disabled" in st) el.setAttribute("aria-disabled", String(!!st.disabled));
|
|
243
|
+
if ("selected" in st) el.setAttribute("aria-selected", String(!!st.selected));
|
|
244
|
+
if ("checked" in st) el.setAttribute("aria-checked", String(st.checked));
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function applyPointerInheritance(child, parent) {
|
|
249
|
+
const mode = parent.pointerMode;
|
|
250
|
+
if (mode === "box_none") child.el.style.pointerEvents = child.pointerMode === "none" ? "none" : "auto";
|
|
251
|
+
else if (mode === "box_only") child.el.style.pointerEvents = "none";
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function withAlpha(cssColor, alpha) {
|
|
255
|
+
const probe = document.createElement("span");
|
|
256
|
+
probe.style.color = cssColor;
|
|
257
|
+
document.body.appendChild(probe);
|
|
258
|
+
const rgb = getComputedStyle(probe).color;
|
|
259
|
+
probe.remove();
|
|
260
|
+
const m = /rgba?\(([^)]+)\)/.exec(rgb);
|
|
261
|
+
if (!m) return cssColor;
|
|
262
|
+
const parts = m[1].split(",").map((p) => parseFloat(p));
|
|
263
|
+
return `rgba(${parts[0]}, ${parts[1]}, ${parts[2]}, ${Math.max(0, Math.min(1, alpha))})`;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/** Combine the static `transform` prop with animated transform values (animation wins). */
|
|
267
|
+
export function composeTransform(view) {
|
|
268
|
+
const anim = view.animTransform;
|
|
269
|
+
let css = view.staticTransform || "";
|
|
270
|
+
if (anim && Object.keys(anim).length) {
|
|
271
|
+
const parts = [];
|
|
272
|
+
if (anim.translate_x != null) parts.push(`translateX(${anim.translate_x}px)`);
|
|
273
|
+
if (anim.translate_y != null) parts.push(`translateY(${anim.translate_y}px)`);
|
|
274
|
+
if (anim.scale != null) parts.push(`scale(${anim.scale})`);
|
|
275
|
+
if (anim.scale_x != null) parts.push(`scaleX(${anim.scale_x})`);
|
|
276
|
+
if (anim.scale_y != null) parts.push(`scaleY(${anim.scale_y})`);
|
|
277
|
+
if (anim.rotate != null) parts.push(`rotate(${anim.rotate}deg)`);
|
|
278
|
+
css = parts.join(" ");
|
|
279
|
+
}
|
|
280
|
+
view.el.style.transform = css;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
function applyTextStyle(el, props, changed, scheme) {
|
|
284
|
+
const s = el.style;
|
|
285
|
+
const has = (k) => k in changed;
|
|
286
|
+
const c = (v) => parseColor(v, scheme);
|
|
287
|
+
if (has("color")) s.color = c(props.color) ?? "";
|
|
288
|
+
if (has("background_color")) s.backgroundColor = c(props.background_color) ?? "";
|
|
289
|
+
if (has("font_size")) s.fontSize = props.font_size != null ? px(Number(props.font_size)) : "";
|
|
290
|
+
if (has("font_weight") || has("bold")) {
|
|
291
|
+
let weight = props.font_weight;
|
|
292
|
+
if (typeof weight === "string") weight = FONT_WEIGHTS[weight.toLowerCase()] ?? weight;
|
|
293
|
+
if (props.bold) weight = 700;
|
|
294
|
+
s.fontWeight = weight == null ? "" : String(weight);
|
|
295
|
+
}
|
|
296
|
+
if (has("font_family")) s.fontFamily = props.font_family ? `"${props.font_family}", var(--pn-font)` : "";
|
|
297
|
+
if (has("italic") || has("font_style")) s.fontStyle = props.italic || props.font_style === "italic" ? "italic" : "";
|
|
298
|
+
if (has("text_align")) {
|
|
299
|
+
const a = props.text_align;
|
|
300
|
+
s.textAlign = a === "center" || a === "right" || a === "justify" ? a : a === "natural" ? "start" : "left";
|
|
301
|
+
}
|
|
302
|
+
if (has("letter_spacing")) s.letterSpacing = props.letter_spacing != null ? px(Number(props.letter_spacing)) : "";
|
|
303
|
+
if (has("line_height")) s.lineHeight = props.line_height != null ? px(Number(props.line_height)) : "";
|
|
304
|
+
if (has("text_decoration")) {
|
|
305
|
+
const d = props.text_decoration;
|
|
306
|
+
s.textDecoration = d === "underline" ? "underline" : d === "line_through" ? "line-through" : "";
|
|
307
|
+
}
|
|
308
|
+
if (has("text_transform")) {
|
|
309
|
+
const t = props.text_transform;
|
|
310
|
+
s.textTransform = t === "uppercase" || t === "lowercase" || t === "capitalize" ? t : "";
|
|
311
|
+
}
|
|
312
|
+
if (has("text_shadow_color") || has("text_shadow_offset") || has("text_shadow_radius")) {
|
|
313
|
+
const col = c(props.text_shadow_color);
|
|
314
|
+
if (!col) s.textShadow = "";
|
|
315
|
+
else {
|
|
316
|
+
const off = offsetOf(props.text_shadow_offset);
|
|
317
|
+
s.textShadow = `${px(off.x)} ${px(off.y)} ${px(Number(props.text_shadow_radius) || 0)} ${col}`;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// ---------------------------------------------------------------------------
|
|
323
|
+
// Measurement
|
|
324
|
+
// ---------------------------------------------------------------------------
|
|
325
|
+
|
|
326
|
+
let measureRoot = null;
|
|
327
|
+
|
|
328
|
+
/** Natural size of `el` under the constraints, measured off-screen in unscaled px. */
|
|
329
|
+
export function measureElement(el, maxW, maxH, { block = false } = {}) {
|
|
330
|
+
if (!measureRoot) measureRoot = document.getElementById("pn-measure") || document.body;
|
|
331
|
+
const clone = el.cloneNode(true);
|
|
332
|
+
clone.style.position = "static";
|
|
333
|
+
clone.style.left = "auto";
|
|
334
|
+
clone.style.top = "auto";
|
|
335
|
+
clone.style.width = "auto";
|
|
336
|
+
clone.style.height = "auto";
|
|
337
|
+
clone.style.transform = "none";
|
|
338
|
+
clone.style.display = block ? "block" : "inline-block";
|
|
339
|
+
clone.style.maxWidth = isFiniteConstraint(maxW) ? px(maxW) : "none";
|
|
340
|
+
clone.style.maxHeight = "none";
|
|
341
|
+
clone.style.visibility = "hidden";
|
|
342
|
+
measureRoot.appendChild(clone);
|
|
343
|
+
const rect = clone.getBoundingClientRect();
|
|
344
|
+
let width = Math.ceil(rect.width * 100) / 100;
|
|
345
|
+
let height = Math.ceil(rect.height * 100) / 100;
|
|
346
|
+
measureRoot.removeChild(clone);
|
|
347
|
+
if (isFiniteConstraint(maxW)) width = Math.min(width, maxW);
|
|
348
|
+
if (isFiniteConstraint(maxH)) height = Math.min(height, maxH);
|
|
349
|
+
return [width, height];
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
// ---------------------------------------------------------------------------
|
|
353
|
+
// Component managers
|
|
354
|
+
// ---------------------------------------------------------------------------
|
|
355
|
+
|
|
356
|
+
class ViewManager {
|
|
357
|
+
create(view, props) {
|
|
358
|
+
const el = document.createElement("div");
|
|
359
|
+
el.className = "pn-view";
|
|
360
|
+
view.el = el;
|
|
361
|
+
this.update(view, props);
|
|
362
|
+
}
|
|
363
|
+
update(view, changed) {
|
|
364
|
+
applyStyle(view, view.props, changed, view.ctx.scheme());
|
|
365
|
+
}
|
|
366
|
+
container(view) {
|
|
367
|
+
return view.el;
|
|
368
|
+
}
|
|
369
|
+
frame(view, x, y, w, h) {
|
|
370
|
+
const s = view.el.style;
|
|
371
|
+
s.left = px(x);
|
|
372
|
+
s.top = px(y);
|
|
373
|
+
s.width = px(w);
|
|
374
|
+
s.height = px(h);
|
|
375
|
+
}
|
|
376
|
+
measure() {
|
|
377
|
+
return [0, 0];
|
|
378
|
+
}
|
|
379
|
+
command() {
|
|
380
|
+
return null;
|
|
381
|
+
}
|
|
382
|
+
destroy() {}
|
|
383
|
+
childrenChanged() {}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
class SpacerManager extends ViewManager {
|
|
387
|
+
update() {}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
class TextManager extends ViewManager {
|
|
391
|
+
create(view, props) {
|
|
392
|
+
const el = document.createElement("div");
|
|
393
|
+
el.className = "pn-view pn-text";
|
|
394
|
+
view.el = el;
|
|
395
|
+
this.update(view, props);
|
|
396
|
+
}
|
|
397
|
+
update(view, changed) {
|
|
398
|
+
const props = view.props;
|
|
399
|
+
const el = view.el;
|
|
400
|
+
const scheme = view.ctx.scheme();
|
|
401
|
+
if ("text" in changed || "spans" in changed) this.render(view);
|
|
402
|
+
applyTextStyle(el, props, changed, scheme);
|
|
403
|
+
if ("max_lines" in changed || "number_of_lines" in changed) {
|
|
404
|
+
const n = Number(props.max_lines ?? props.number_of_lines) || 0;
|
|
405
|
+
el.classList.toggle("pn-clamp", n > 1);
|
|
406
|
+
el.classList.toggle("pn-clamp-1", n === 1);
|
|
407
|
+
el.style.webkitLineClamp = n > 1 ? String(n) : "";
|
|
408
|
+
view.maxLines = n;
|
|
409
|
+
}
|
|
410
|
+
if ("selectable" in changed) el.classList.toggle("pn-selectable", !!props.selectable);
|
|
411
|
+
applyStyle(view, props, changed, scheme, { leaf: true });
|
|
412
|
+
view.measureCache = null;
|
|
413
|
+
}
|
|
414
|
+
render(view) {
|
|
415
|
+
const el = view.el;
|
|
416
|
+
const props = view.props;
|
|
417
|
+
el.textContent = "";
|
|
418
|
+
if (Array.isArray(props.spans) && props.spans.length) {
|
|
419
|
+
const scheme = view.ctx.scheme();
|
|
420
|
+
for (const span of props.spans) {
|
|
421
|
+
if (!span || typeof span !== "object") continue;
|
|
422
|
+
const node = document.createElement("span");
|
|
423
|
+
node.textContent = span.text == null ? "" : String(span.text);
|
|
424
|
+
applyTextStyle(node, span, span, scheme);
|
|
425
|
+
el.appendChild(node);
|
|
426
|
+
}
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
el.textContent = props.text == null ? "" : String(props.text);
|
|
430
|
+
}
|
|
431
|
+
measure(view, maxW, maxH) {
|
|
432
|
+
const key = `${maxW}|${maxH}`;
|
|
433
|
+
if (view.measureCache && view.measureCache.key === key) return view.measureCache.size;
|
|
434
|
+
let size = measureElement(view.el, maxW, maxH, { block: true });
|
|
435
|
+
if (view.maxLines > 0) {
|
|
436
|
+
const lh = parseFloat(getComputedStyle(view.el).lineHeight) || Number(view.props.font_size || 17) * 1.25;
|
|
437
|
+
size = [size[0], Math.min(size[1], Math.ceil(lh * view.maxLines * 100) / 100)];
|
|
438
|
+
}
|
|
439
|
+
view.measureCache = { key, size };
|
|
440
|
+
return size;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
class ButtonManager extends ViewManager {
|
|
445
|
+
create(view, props) {
|
|
446
|
+
const el = document.createElement("button");
|
|
447
|
+
el.className = "pn-view pn-button";
|
|
448
|
+
el.type = "button";
|
|
449
|
+
el.addEventListener("click", () => {
|
|
450
|
+
if (!el.disabled) view.ctx.emit(view.tag, "on_press", []);
|
|
451
|
+
});
|
|
452
|
+
view.el = el;
|
|
453
|
+
this.update(view, props);
|
|
454
|
+
}
|
|
455
|
+
update(view, changed) {
|
|
456
|
+
const props = view.props;
|
|
457
|
+
const el = view.el;
|
|
458
|
+
const scheme = view.ctx.scheme();
|
|
459
|
+
if ("title" in changed) el.textContent = props.title == null ? "" : String(props.title);
|
|
460
|
+
if ("font_size" in changed) el.style.fontSize = props.font_size != null ? px(Number(props.font_size)) : "";
|
|
461
|
+
if ("color" in changed || "background_color" in changed) {
|
|
462
|
+
const bg = parseColor(props.background_color, scheme);
|
|
463
|
+
el.style.backgroundColor = bg ?? "";
|
|
464
|
+
const color = parseColor(props.color, scheme);
|
|
465
|
+
el.style.color = color ?? (bg ? "#fff" : "");
|
|
466
|
+
}
|
|
467
|
+
if ("disabled" in changed) el.disabled = props.disabled === true;
|
|
468
|
+
applyStyle(view, props, changed, scheme, { leaf: true });
|
|
469
|
+
view.measureCache = null;
|
|
470
|
+
}
|
|
471
|
+
measure(view, maxW, maxH) {
|
|
472
|
+
const [w, h] = measureElement(view.el, maxW, maxH);
|
|
473
|
+
return [Math.max(44, Math.min(w + 24, isFiniteConstraint(maxW) ? maxW : Infinity)), Math.max(32, h + 12)];
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
const KEYBOARD_TYPES = {
|
|
478
|
+
ascii: "text",
|
|
479
|
+
numbers_and_punctuation: "text",
|
|
480
|
+
url: "url",
|
|
481
|
+
number_pad: "tel",
|
|
482
|
+
numeric: "text",
|
|
483
|
+
phone_pad: "tel",
|
|
484
|
+
email_address: "email",
|
|
485
|
+
email: "email",
|
|
486
|
+
decimal_pad: "text",
|
|
487
|
+
decimal: "text",
|
|
488
|
+
web_search: "search",
|
|
489
|
+
};
|
|
490
|
+
|
|
491
|
+
class TextInputManager extends ViewManager {
|
|
492
|
+
create(view, props) {
|
|
493
|
+
const multiline = !!props.multiline;
|
|
494
|
+
const el = document.createElement(multiline ? "textarea" : "input");
|
|
495
|
+
el.className = "pn-view pn-input";
|
|
496
|
+
if (!multiline) el.type = "text";
|
|
497
|
+
view.el = el;
|
|
498
|
+
view.suppressEcho = false;
|
|
499
|
+
view.composing = false;
|
|
500
|
+
el.addEventListener("compositionstart", () => { view.composing = true; });
|
|
501
|
+
el.addEventListener("compositionend", () => { view.composing = false; });
|
|
502
|
+
el.addEventListener("input", () => {
|
|
503
|
+
const props = view.props;
|
|
504
|
+
if (props.max_length != null && el.value.length > Number(props.max_length)) {
|
|
505
|
+
el.value = el.value.slice(0, Number(props.max_length));
|
|
506
|
+
}
|
|
507
|
+
view.ctx.emit(view.tag, "on_change", [el.value]);
|
|
508
|
+
});
|
|
509
|
+
el.addEventListener("focus", () => view.ctx.emit(view.tag, "on_focus", []));
|
|
510
|
+
el.addEventListener("blur", () => view.ctx.emit(view.tag, "on_blur", []));
|
|
511
|
+
if (!multiline) {
|
|
512
|
+
el.addEventListener("keydown", (event) => {
|
|
513
|
+
if (event.key === "Enter") view.ctx.emit(view.tag, "on_submit", [el.value]);
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
view.selectionListener = () => {
|
|
517
|
+
if (document.activeElement !== el || !view.hasEvent("on_selection_change")) return;
|
|
518
|
+
view.ctx.emit(view.tag, "on_selection_change", [{ start: el.selectionStart || 0, end: el.selectionEnd || 0 }]);
|
|
519
|
+
};
|
|
520
|
+
document.addEventListener("selectionchange", view.selectionListener);
|
|
521
|
+
this.update(view, props);
|
|
522
|
+
if (props.auto_focus) setTimeout(() => el.focus(), 0);
|
|
523
|
+
}
|
|
524
|
+
destroy(view) {
|
|
525
|
+
document.removeEventListener("selectionchange", view.selectionListener);
|
|
526
|
+
}
|
|
527
|
+
update(view, changed) {
|
|
528
|
+
const props = view.props;
|
|
529
|
+
const el = view.el;
|
|
530
|
+
const scheme = view.ctx.scheme();
|
|
531
|
+
const has = (k) => k in changed;
|
|
532
|
+
if (has("value") && props.value != null && !view.composing &&
|
|
533
|
+
Number(changed._pn_edit_revision || 0) >= Number(view.editRevision || 0) && el.value !== String(props.value)) {
|
|
534
|
+
const start = el.selectionStart, end = el.selectionEnd;
|
|
535
|
+
el.value = String(props.value);
|
|
536
|
+
if (start != null) el.setSelectionRange(Math.min(start, el.value.length), Math.min(end, el.value.length));
|
|
537
|
+
}
|
|
538
|
+
if (has("placeholder")) el.placeholder = props.placeholder == null ? "" : String(props.placeholder);
|
|
539
|
+
if (has("placeholder_color")) el.style.setProperty("--pn-placeholder", parseColor(props.placeholder_color, scheme) ?? "");
|
|
540
|
+
if (has("font_size")) el.style.fontSize = props.font_size != null ? px(Number(props.font_size)) : "";
|
|
541
|
+
if (has("color")) el.style.color = parseColor(props.color, scheme) ?? "";
|
|
542
|
+
if (has("background_color")) el.style.backgroundColor = parseColor(props.background_color, scheme) ?? "";
|
|
543
|
+
if (has("secure") && el.tagName === "INPUT") el.type = props.secure ? "password" : KEYBOARD_TYPES[props.keyboard_type] || "text";
|
|
544
|
+
if (has("keyboard_type") && el.tagName === "INPUT" && !props.secure) el.type = KEYBOARD_TYPES[props.keyboard_type] || "text";
|
|
545
|
+
if (has("auto_capitalize")) el.autocapitalize = props.auto_capitalize || "sentences";
|
|
546
|
+
if (has("auto_correct")) el.autocomplete = props.auto_correct === false ? "off" : "on";
|
|
547
|
+
if (has("return_key_type")) el.enterKeyHint = props.return_key_type || "";
|
|
548
|
+
if (has("selection_color")) el.style.caretColor = parseColor(props.selection_color, scheme) ?? "";
|
|
549
|
+
if (has("editable")) el.readOnly = props.editable === false;
|
|
550
|
+
if (has("max_length")) {
|
|
551
|
+
if (props.max_length != null) el.maxLength = Number(props.max_length);
|
|
552
|
+
else el.removeAttribute("maxlength");
|
|
553
|
+
}
|
|
554
|
+
if (has("text_content_type")) {
|
|
555
|
+
const t = props.text_content_type;
|
|
556
|
+
el.autocomplete =
|
|
557
|
+
t === "password" ? "current-password" : t === "new_password" ? "new-password" : t === "one_time_code" ? "one-time-code" : t === "email" || t === "email_address" ? "email" : t === "username" ? "username" : t === "name" ? "name" : t === "telephone" || t === "phone" ? "tel" : t === "url" ? "url" : el.autocomplete;
|
|
558
|
+
}
|
|
559
|
+
applyStyle(view, props, changed, scheme, { leaf: true });
|
|
560
|
+
}
|
|
561
|
+
measure(view, maxW) {
|
|
562
|
+
const width = isFiniteConstraint(maxW) ? Math.max(100, Math.min(maxW, 100)) : 100;
|
|
563
|
+
if (view.el.tagName === "TEXTAREA") {
|
|
564
|
+
const [, h] = measureElement(view.el, maxW, INF, { block: true });
|
|
565
|
+
return [isFiniteConstraint(maxW) ? maxW : width, Math.max(36, h)];
|
|
566
|
+
}
|
|
567
|
+
return [isFiniteConstraint(maxW) ? Math.max(100, Math.min(maxW, 100)) : 100, 36];
|
|
568
|
+
}
|
|
569
|
+
command(view, name, args) {
|
|
570
|
+
const el = view.el;
|
|
571
|
+
switch (name) {
|
|
572
|
+
case "focus":
|
|
573
|
+
el.focus();
|
|
574
|
+
return null;
|
|
575
|
+
case "blur":
|
|
576
|
+
el.blur();
|
|
577
|
+
return null;
|
|
578
|
+
case "clear":
|
|
579
|
+
el.value = "";
|
|
580
|
+
return null;
|
|
581
|
+
case "get_value":
|
|
582
|
+
return el.value;
|
|
583
|
+
case "set_selection": {
|
|
584
|
+
const start = Number(args.start) || 0;
|
|
585
|
+
const end = args.end != null ? Number(args.end) : start;
|
|
586
|
+
el.setSelectionRange(start, end);
|
|
587
|
+
return null;
|
|
588
|
+
}
|
|
589
|
+
default:
|
|
590
|
+
return null;
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
class ImageManager extends ViewManager {
|
|
596
|
+
create(view, props) {
|
|
597
|
+
const el = document.createElement("div");
|
|
598
|
+
el.className = "pn-view pn-image-wrap";
|
|
599
|
+
const img = document.createElement("img");
|
|
600
|
+
img.alt = "";
|
|
601
|
+
img.draggable = false;
|
|
602
|
+
const tint = document.createElement("div");
|
|
603
|
+
tint.className = "pn-image-tint";
|
|
604
|
+
tint.style.display = "none";
|
|
605
|
+
el.appendChild(img);
|
|
606
|
+
el.appendChild(tint);
|
|
607
|
+
view.el = el;
|
|
608
|
+
view.img = img;
|
|
609
|
+
view.tint = tint;
|
|
610
|
+
view.natural = null;
|
|
611
|
+
img.addEventListener("load", () => {
|
|
612
|
+
view.natural = [img.naturalWidth, img.naturalHeight];
|
|
613
|
+
view.measureCache = null;
|
|
614
|
+
view.ctx.emit(view.tag, "on_load", [{ width: img.naturalWidth, height: img.naturalHeight }]);
|
|
615
|
+
});
|
|
616
|
+
img.addEventListener("error", () => view.ctx.emit(view.tag, "on_error", [`failed to load ${img.src}`]));
|
|
617
|
+
this.update(view, props);
|
|
618
|
+
}
|
|
619
|
+
update(view, changed) {
|
|
620
|
+
const props = view.props;
|
|
621
|
+
const scheme = view.ctx.scheme();
|
|
622
|
+
const has = (k) => k in changed;
|
|
623
|
+
if (has("source")) {
|
|
624
|
+
const src = imageSource(props.source);
|
|
625
|
+
view.natural = null;
|
|
626
|
+
if (src) view.img.src = src;
|
|
627
|
+
else view.img.removeAttribute("src");
|
|
628
|
+
view.tint.style.maskImage = view.tint.style.webkitMaskImage = src ? `url("${src}")` : "";
|
|
629
|
+
}
|
|
630
|
+
if (has("scale_type") || has("resize_mode")) {
|
|
631
|
+
const mode = props.scale_type ?? props.resize_mode;
|
|
632
|
+
view.img.style.objectFit = mode === "cover" || mode === "repeat" ? "cover" : mode === "stretch" ? "fill" : mode === "center" ? "none" : "contain";
|
|
633
|
+
}
|
|
634
|
+
if (has("placeholder_color")) view.el.style.backgroundColor = parseColor(props.placeholder_color, scheme) ?? "";
|
|
635
|
+
if (has("tint_color") || has("tint")) {
|
|
636
|
+
const tint = parseColor(props.tint_color ?? props.tint, scheme);
|
|
637
|
+
view.tint.style.display = tint ? "" : "none";
|
|
638
|
+
view.tint.style.backgroundColor = tint ?? "";
|
|
639
|
+
view.img.style.visibility = tint ? "hidden" : "";
|
|
640
|
+
}
|
|
641
|
+
applyStyle(view, props, changed, scheme, { leaf: true });
|
|
642
|
+
}
|
|
643
|
+
measure(view, maxW, maxH) {
|
|
644
|
+
if (!view.natural) return [0, 0];
|
|
645
|
+
let [w, h] = view.natural;
|
|
646
|
+
if (isFiniteConstraint(maxW) && w > maxW) {
|
|
647
|
+
h = (h * maxW) / w;
|
|
648
|
+
w = maxW;
|
|
649
|
+
}
|
|
650
|
+
if (isFiniteConstraint(maxH) && h > maxH) {
|
|
651
|
+
w = (w * maxH) / h;
|
|
652
|
+
h = maxH;
|
|
653
|
+
}
|
|
654
|
+
return [w, h];
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
function imageSource(source) {
|
|
659
|
+
if (source == null) return "";
|
|
660
|
+
if (typeof source === "object") source = source.uri ?? source.url ?? source.src ?? "";
|
|
661
|
+
const text = String(source);
|
|
662
|
+
if (!text) return "";
|
|
663
|
+
if (/^(https?:|data:|blob:|\/)/.test(text)) return text;
|
|
664
|
+
if (text.startsWith("file://")) return `/file/${encodeURI(text.slice("file://".length).replace(/^\/+/, ""))}`;
|
|
665
|
+
// Bundle-relative name: serve it out of the project through the dev server.
|
|
666
|
+
return `/file/${encodeURI(text.replace(/^\.?\//, ""))}`;
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
class SwitchManager extends ViewManager {
|
|
670
|
+
create(view, props) {
|
|
671
|
+
const el = document.createElement("div");
|
|
672
|
+
el.className = "pn-view pn-switch";
|
|
673
|
+
el.setAttribute("role", "switch");
|
|
674
|
+
const knob = document.createElement("div");
|
|
675
|
+
knob.className = "pn-knob";
|
|
676
|
+
el.appendChild(knob);
|
|
677
|
+
el.addEventListener("click", () => {
|
|
678
|
+
if (view.props.disabled === true) return;
|
|
679
|
+
const next = !view.props.value;
|
|
680
|
+
view.ctx.emit(view.tag, "on_change", [next]);
|
|
681
|
+
});
|
|
682
|
+
view.el = el;
|
|
683
|
+
this.update(view, props);
|
|
684
|
+
}
|
|
685
|
+
update(view, changed) {
|
|
686
|
+
const props = view.props;
|
|
687
|
+
const scheme = view.ctx.scheme();
|
|
688
|
+
const el = view.el;
|
|
689
|
+
if ("value" in changed || "on_tint_color" in changed || "tint_color" in changed) {
|
|
690
|
+
const on = !!props.value;
|
|
691
|
+
el.classList.toggle("pn-on", on);
|
|
692
|
+
el.setAttribute("aria-checked", String(on));
|
|
693
|
+
const onColor = parseColor(props.on_tint_color ?? props.tint_color, scheme) ?? "#34c759";
|
|
694
|
+
el.style.backgroundColor = on ? onColor : "";
|
|
695
|
+
}
|
|
696
|
+
if ("thumb_color" in changed) el.firstChild.style.backgroundColor = parseColor(props.thumb_color, scheme) ?? "";
|
|
697
|
+
if ("disabled" in changed) el.classList.toggle("pn-disabled", props.disabled === true);
|
|
698
|
+
applyStyle(view, props, changed, scheme, { leaf: true });
|
|
699
|
+
}
|
|
700
|
+
measure() {
|
|
701
|
+
return [51, 31];
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
class SliderManager extends ViewManager {
|
|
706
|
+
create(view, props) {
|
|
707
|
+
const el = document.createElement("input");
|
|
708
|
+
el.type = "range";
|
|
709
|
+
el.className = "pn-view pn-slider";
|
|
710
|
+
el.step = "any";
|
|
711
|
+
el.addEventListener("input", () => view.ctx.emit(view.tag, "on_change", [Number(el.value)]));
|
|
712
|
+
el.addEventListener("change", () => {
|
|
713
|
+
if (view.hasEvent("on_sliding_complete")) view.ctx.emit(view.tag, "on_sliding_complete", [Number(el.value)]);
|
|
714
|
+
});
|
|
715
|
+
view.el = el;
|
|
716
|
+
this.update(view, props);
|
|
717
|
+
}
|
|
718
|
+
update(view, changed) {
|
|
719
|
+
const props = view.props;
|
|
720
|
+
const el = view.el;
|
|
721
|
+
const scheme = view.ctx.scheme();
|
|
722
|
+
if ("min_value" in changed) el.min = String(props.min_value ?? 0);
|
|
723
|
+
if ("max_value" in changed) el.max = String(props.max_value ?? 1);
|
|
724
|
+
if ("value" in changed && props.value != null) el.value = String(props.value);
|
|
725
|
+
if ("minimum_track_color" in changed || "tint_color" in changed) {
|
|
726
|
+
el.style.accentColor = parseColor(props.minimum_track_color ?? props.tint_color, scheme) ?? "";
|
|
727
|
+
}
|
|
728
|
+
if ("maximum_track_color" in changed) el.style.setProperty("--pn-track", parseColor(props.maximum_track_color, scheme) ?? "");
|
|
729
|
+
if ("thumb_color" in changed) el.style.setProperty("--pn-thumb", parseColor(props.thumb_color, scheme) ?? "");
|
|
730
|
+
if ("disabled" in changed) el.disabled = props.disabled === true;
|
|
731
|
+
applyStyle(view, props, changed, scheme, { leaf: true });
|
|
732
|
+
}
|
|
733
|
+
measure(view, maxW) {
|
|
734
|
+
return [isFiniteConstraint(maxW) ? Math.max(100, maxW) : 100, 34];
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
class ActivityIndicatorManager extends ViewManager {
|
|
739
|
+
create(view, props) {
|
|
740
|
+
const el = document.createElement("div");
|
|
741
|
+
el.className = "pn-view";
|
|
742
|
+
const spinner = document.createElement("div");
|
|
743
|
+
spinner.className = "pn-spinner";
|
|
744
|
+
el.appendChild(spinner);
|
|
745
|
+
view.el = el;
|
|
746
|
+
view.spinner = spinner;
|
|
747
|
+
this.update(view, props);
|
|
748
|
+
}
|
|
749
|
+
update(view, changed) {
|
|
750
|
+
const props = view.props;
|
|
751
|
+
const scheme = view.ctx.scheme();
|
|
752
|
+
const size = props.size === "large" ? 37 : 20;
|
|
753
|
+
view.spinner.style.width = view.spinner.style.height = px(size);
|
|
754
|
+
view.spinner.style.borderWidth = px(props.size === "large" ? 3 : 2);
|
|
755
|
+
if ("color" in changed) view.spinner.style.borderTopColor = parseColor(props.color, scheme) ?? "#8e8e93";
|
|
756
|
+
const animating = props.animating !== false;
|
|
757
|
+
view.spinner.style.animationPlayState = animating ? "running" : "paused";
|
|
758
|
+
view.spinner.style.visibility = !animating && props.hides_when_stopped !== false ? "hidden" : "";
|
|
759
|
+
applyStyle(view, props, changed, scheme, { leaf: true });
|
|
760
|
+
}
|
|
761
|
+
measure(view) {
|
|
762
|
+
const size = view.props.size === "large" ? 37 : 20;
|
|
763
|
+
return [size, size];
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
class ProgressBarManager extends ViewManager {
|
|
768
|
+
create(view, props) {
|
|
769
|
+
const el = document.createElement("div");
|
|
770
|
+
el.className = "pn-view";
|
|
771
|
+
view.el = el;
|
|
772
|
+
view.indeterminate = !!props.indeterminate;
|
|
773
|
+
if (view.indeterminate) {
|
|
774
|
+
const spinner = document.createElement("div");
|
|
775
|
+
spinner.className = "pn-spinner";
|
|
776
|
+
spinner.style.width = spinner.style.height = "20px";
|
|
777
|
+
el.appendChild(spinner);
|
|
778
|
+
view.spinner = spinner;
|
|
779
|
+
} else {
|
|
780
|
+
el.classList.add("pn-progress");
|
|
781
|
+
const bar = document.createElement("div");
|
|
782
|
+
el.appendChild(bar);
|
|
783
|
+
view.bar = bar;
|
|
784
|
+
}
|
|
785
|
+
this.update(view, props);
|
|
786
|
+
}
|
|
787
|
+
update(view, changed) {
|
|
788
|
+
const props = view.props;
|
|
789
|
+
const scheme = view.ctx.scheme();
|
|
790
|
+
const color = parseColor(props.color, scheme);
|
|
791
|
+
if (view.bar) {
|
|
792
|
+
const value = Math.max(0, Math.min(1, Number(props.value ?? props.progress) || 0));
|
|
793
|
+
view.bar.style.width = `${value * 100}%`;
|
|
794
|
+
view.bar.style.backgroundColor = color ?? "";
|
|
795
|
+
view.el.style.backgroundColor = parseColor(props.track_color, scheme) ?? "";
|
|
796
|
+
} else if (view.spinner) {
|
|
797
|
+
view.spinner.style.borderTopColor = color ?? "#8e8e93";
|
|
798
|
+
}
|
|
799
|
+
applyStyle(view, props, changed, scheme, { leaf: true });
|
|
800
|
+
}
|
|
801
|
+
measure(view, maxW) {
|
|
802
|
+
if (view.indeterminate) return [20, 20];
|
|
803
|
+
return [isFiniteConstraint(maxW) ? maxW : 100, 4];
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
function scrollPayload(el, horizontal) {
|
|
808
|
+
const contentWidth = el.scrollWidth;
|
|
809
|
+
const contentHeight = el.scrollHeight;
|
|
810
|
+
return {
|
|
811
|
+
x: el.scrollLeft,
|
|
812
|
+
y: el.scrollTop,
|
|
813
|
+
extent: horizontal ? el.clientWidth : el.clientHeight,
|
|
814
|
+
range: horizontal ? contentWidth : contentHeight,
|
|
815
|
+
content_width: contentWidth,
|
|
816
|
+
content_height: contentHeight,
|
|
817
|
+
width: el.clientWidth,
|
|
818
|
+
height: el.clientHeight,
|
|
819
|
+
};
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
class ScrollViewManager extends ViewManager {
|
|
823
|
+
create(view, props) {
|
|
824
|
+
const el = document.createElement("div");
|
|
825
|
+
el.className = "pn-view pn-scroll";
|
|
826
|
+
const content = document.createElement("div");
|
|
827
|
+
content.className = "pn-scroll-content";
|
|
828
|
+
el.appendChild(content);
|
|
829
|
+
view.el = el;
|
|
830
|
+
view.content = content;
|
|
831
|
+
view.lastScrollEmit = 0;
|
|
832
|
+
view.scrollIdleTimer = null;
|
|
833
|
+
view.dragging = false;
|
|
834
|
+
el.addEventListener(
|
|
835
|
+
"scroll",
|
|
836
|
+
() => {
|
|
837
|
+
const props = view.props;
|
|
838
|
+
const horizontal = !!props.horizontal;
|
|
839
|
+
if (!view.dragging) {
|
|
840
|
+
view.dragging = true;
|
|
841
|
+
if (view.hasEvent("on_scroll_begin_drag")) view.ctx.emit(view.tag, "on_scroll_begin_drag", [scrollPayload(el, horizontal)]);
|
|
842
|
+
}
|
|
843
|
+
const throttle = Number(props.scroll_event_throttle) || 0;
|
|
844
|
+
const now = performance.now();
|
|
845
|
+
if (throttle <= 0 || now - view.lastScrollEmit >= throttle) {
|
|
846
|
+
view.lastScrollEmit = now;
|
|
847
|
+
view.ctx.emit(view.tag, "on_scroll", [scrollPayload(el, horizontal)]);
|
|
848
|
+
}
|
|
849
|
+
clearTimeout(view.scrollIdleTimer);
|
|
850
|
+
view.scrollIdleTimer = setTimeout(() => {
|
|
851
|
+
view.dragging = false;
|
|
852
|
+
const payload = scrollPayload(el, horizontal);
|
|
853
|
+
view.ctx.emit(view.tag, "on_scroll", [payload]);
|
|
854
|
+
if (view.hasEvent("on_scroll_end_drag")) view.ctx.emit(view.tag, "on_scroll_end_drag", [payload]);
|
|
855
|
+
if (view.hasEvent("on_momentum_scroll_end")) view.ctx.emit(view.tag, "on_momentum_scroll_end", [payload]);
|
|
856
|
+
}, 120);
|
|
857
|
+
},
|
|
858
|
+
{ passive: true },
|
|
859
|
+
);
|
|
860
|
+
this.update(view, props);
|
|
861
|
+
}
|
|
862
|
+
container(view) {
|
|
863
|
+
return view.content;
|
|
864
|
+
}
|
|
865
|
+
update(view, changed) {
|
|
866
|
+
const props = view.props;
|
|
867
|
+
const el = view.el;
|
|
868
|
+
const scheme = view.ctx.scheme();
|
|
869
|
+
const has = (k) => k in changed;
|
|
870
|
+
if (has("horizontal")) {
|
|
871
|
+
el.style.overflowX = props.horizontal ? "auto" : "hidden";
|
|
872
|
+
el.style.overflowY = props.horizontal ? "hidden" : "auto";
|
|
873
|
+
}
|
|
874
|
+
if (has("shows_scroll_indicator")) el.classList.toggle("pn-no-indicator", props.shows_scroll_indicator === false);
|
|
875
|
+
if (has("paging_enabled")) el.classList.toggle("pn-paging", !!props.paging_enabled);
|
|
876
|
+
if (has("scroll_enabled")) el.classList.toggle("pn-scroll-disabled", props.scroll_enabled === false);
|
|
877
|
+
if (has("content_inset")) {
|
|
878
|
+
const inset = props.content_inset || {};
|
|
879
|
+
view.content.style.padding = `${px(Number(inset.top) || 0)} ${px(Number(inset.right) || 0)} ${px(Number(inset.bottom) || 0)} ${px(Number(inset.left) || 0)}`;
|
|
880
|
+
}
|
|
881
|
+
if (has("refresh_control")) this.updateRefresh(view);
|
|
882
|
+
applyStyle(view, props, changed, scheme);
|
|
883
|
+
if ("overflow" in changed && props.overflow !== "hidden") el.style.overflow = "";
|
|
884
|
+
if (has("horizontal") || has("overflow")) {
|
|
885
|
+
el.style.overflowX = props.horizontal ? "auto" : "hidden";
|
|
886
|
+
el.style.overflowY = props.horizontal ? "hidden" : "auto";
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
updateRefresh(view) {
|
|
890
|
+
const rc = view.props.refresh_control;
|
|
891
|
+
if (!rc || typeof rc !== "object") {
|
|
892
|
+
if (view.refresh) view.refresh.remove();
|
|
893
|
+
view.refresh = null;
|
|
894
|
+
return;
|
|
895
|
+
}
|
|
896
|
+
if (!view.refresh) {
|
|
897
|
+
const bar = document.createElement("div");
|
|
898
|
+
bar.className = "pn-refresh";
|
|
899
|
+
const button = document.createElement("button");
|
|
900
|
+
button.className = "pn-button";
|
|
901
|
+
button.textContent = "↻ Refresh";
|
|
902
|
+
button.style.fontSize = "13px";
|
|
903
|
+
button.addEventListener("click", () => view.ctx.emit(view.tag, "on_refresh", []));
|
|
904
|
+
const spinner = document.createElement("div");
|
|
905
|
+
spinner.className = "pn-spinner";
|
|
906
|
+
spinner.style.width = spinner.style.height = "20px";
|
|
907
|
+
bar.appendChild(button);
|
|
908
|
+
bar.appendChild(spinner);
|
|
909
|
+
view.el.insertBefore(bar, view.content);
|
|
910
|
+
view.refresh = bar;
|
|
911
|
+
view.refreshButton = button;
|
|
912
|
+
view.refreshSpinner = spinner;
|
|
913
|
+
}
|
|
914
|
+
const refreshing = !!rc.refreshing;
|
|
915
|
+
view.refreshButton.style.display = refreshing ? "none" : "";
|
|
916
|
+
view.refreshSpinner.style.display = refreshing ? "" : "none";
|
|
917
|
+
const tint = parseColor(rc.tint_color ?? rc.color, view.ctx.scheme());
|
|
918
|
+
if (tint) view.refreshSpinner.style.borderTopColor = tint;
|
|
919
|
+
}
|
|
920
|
+
childrenChanged(view) {
|
|
921
|
+
// Content size = union of the children's frames (as UIScrollView.contentSize).
|
|
922
|
+
let w = 0;
|
|
923
|
+
let h = 0;
|
|
924
|
+
for (const child of view.children) {
|
|
925
|
+
if (!child.frame) continue;
|
|
926
|
+
w = Math.max(w, child.frame.x + child.frame.w);
|
|
927
|
+
h = Math.max(h, child.frame.y + child.frame.h);
|
|
928
|
+
}
|
|
929
|
+
view.content.style.width = w ? px(w) : "";
|
|
930
|
+
view.content.style.height = h ? px(h) : "";
|
|
931
|
+
}
|
|
932
|
+
command(view, name, args) {
|
|
933
|
+
const el = view.el;
|
|
934
|
+
const animated = args.animated !== false;
|
|
935
|
+
const behavior = animated ? "smooth" : "auto";
|
|
936
|
+
switch (name) {
|
|
937
|
+
case "scroll_to_offset":
|
|
938
|
+
el.scrollTo({ left: Number(args.x) || 0, top: Number(args.y) || 0, behavior });
|
|
939
|
+
return null;
|
|
940
|
+
case "scroll_to_end":
|
|
941
|
+
el.scrollTo({ left: el.scrollWidth, top: el.scrollHeight, behavior });
|
|
942
|
+
return null;
|
|
943
|
+
case "get_scroll_offset":
|
|
944
|
+
return { x: el.scrollLeft, y: el.scrollTop };
|
|
945
|
+
case "flash_scroll_indicators":
|
|
946
|
+
return null;
|
|
947
|
+
default:
|
|
948
|
+
return null;
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
class PressableManager extends ViewManager {
|
|
954
|
+
create(view, props) {
|
|
955
|
+
const el = document.createElement("div");
|
|
956
|
+
el.className = "pn-view pn-pressable";
|
|
957
|
+
view.el = el;
|
|
958
|
+
view.pressed = false;
|
|
959
|
+
view.longPressTimer = null;
|
|
960
|
+
view.longPressed = false;
|
|
961
|
+
const enabled = () => !view.props.disabled;
|
|
962
|
+
const setPressed = (on) => {
|
|
963
|
+
view.pressed = on;
|
|
964
|
+
view.pressedOpacityActive = on;
|
|
965
|
+
const pressedOpacity = view.props.pressed_opacity != null ? Number(view.props.pressed_opacity) : 0.6;
|
|
966
|
+
el.style.opacity = on ? String(pressedOpacity) : view.props.opacity != null ? String(view.props.opacity) : "";
|
|
967
|
+
};
|
|
968
|
+
el.addEventListener("pointerdown", (event) => {
|
|
969
|
+
if (!enabled() || event.button !== 0) return;
|
|
970
|
+
event.stopPropagation();
|
|
971
|
+
view.longPressed = false;
|
|
972
|
+
setPressed(true);
|
|
973
|
+
try {
|
|
974
|
+
el.setPointerCapture(event.pointerId);
|
|
975
|
+
} catch (err) {
|
|
976
|
+
/* ignore */
|
|
977
|
+
}
|
|
978
|
+
view.ctx.emit(view.tag, "on_press_in", []);
|
|
979
|
+
if (view.hasEvent("on_long_press")) {
|
|
980
|
+
const delay = Math.max(50, Number(view.props.delay_long_press) || 500);
|
|
981
|
+
view.longPressTimer = setTimeout(() => {
|
|
982
|
+
view.longPressed = true;
|
|
983
|
+
view.ctx.emit(view.tag, "on_long_press", []);
|
|
984
|
+
}, delay);
|
|
985
|
+
}
|
|
986
|
+
});
|
|
987
|
+
const finish = (event, fire) => {
|
|
988
|
+
if (!view.pressed) return;
|
|
989
|
+
clearTimeout(view.longPressTimer);
|
|
990
|
+
setPressed(false);
|
|
991
|
+
view.ctx.emit(view.tag, "on_press_out", []);
|
|
992
|
+
if (fire && !view.longPressed && enabled()) view.ctx.emit(view.tag, "on_press", []);
|
|
993
|
+
};
|
|
994
|
+
el.addEventListener("pointerup", (event) => {
|
|
995
|
+
event.stopPropagation();
|
|
996
|
+
const rect = el.getBoundingClientRect();
|
|
997
|
+
const inside = event.clientX >= rect.left && event.clientX <= rect.right && event.clientY >= rect.top && event.clientY <= rect.bottom;
|
|
998
|
+
finish(event, inside);
|
|
999
|
+
});
|
|
1000
|
+
el.addEventListener("pointercancel", (event) => finish(event, false));
|
|
1001
|
+
el.addEventListener("keydown", (event) => {
|
|
1002
|
+
if ((event.key === "Enter" || event.key === " ") && enabled()) {
|
|
1003
|
+
event.preventDefault();
|
|
1004
|
+
view.ctx.emit(view.tag, "on_press", []);
|
|
1005
|
+
}
|
|
1006
|
+
});
|
|
1007
|
+
this.update(view, props);
|
|
1008
|
+
}
|
|
1009
|
+
update(view, changed) {
|
|
1010
|
+
const props = view.props;
|
|
1011
|
+
const disabled = !!props.disabled;
|
|
1012
|
+
view.el.classList.toggle("pn-disabled", disabled);
|
|
1013
|
+
view.el.tabIndex = disabled ? -1 : 0;
|
|
1014
|
+
applyStyle(view, props, changed, view.ctx.scheme());
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
class CheckboxManager extends ViewManager {
|
|
1019
|
+
create(view, props) {
|
|
1020
|
+
const el = document.createElement("div");
|
|
1021
|
+
el.className = "pn-view pn-checkbox";
|
|
1022
|
+
el.setAttribute("role", "checkbox");
|
|
1023
|
+
const box = document.createElement("div");
|
|
1024
|
+
box.className = "pn-box";
|
|
1025
|
+
box.textContent = "✓";
|
|
1026
|
+
const label = document.createElement("span");
|
|
1027
|
+
el.appendChild(box);
|
|
1028
|
+
el.appendChild(label);
|
|
1029
|
+
el.addEventListener("click", () => {
|
|
1030
|
+
if (view.props.disabled) return;
|
|
1031
|
+
view.ctx.emit(view.tag, "on_change", [!view.props.value]);
|
|
1032
|
+
});
|
|
1033
|
+
view.el = el;
|
|
1034
|
+
view.label = label;
|
|
1035
|
+
this.update(view, props);
|
|
1036
|
+
}
|
|
1037
|
+
update(view, changed) {
|
|
1038
|
+
const props = view.props;
|
|
1039
|
+
const scheme = view.ctx.scheme();
|
|
1040
|
+
view.el.classList.toggle("pn-on", !!props.value);
|
|
1041
|
+
view.el.setAttribute("aria-checked", String(!!props.value));
|
|
1042
|
+
view.el.classList.toggle("pn-disabled", !!props.disabled);
|
|
1043
|
+
if ("label" in changed) view.label.textContent = props.label == null ? "" : String(props.label);
|
|
1044
|
+
if ("color" in changed) view.el.style.setProperty("--pn-check", parseColor(props.color, scheme) ?? "");
|
|
1045
|
+
applyStyle(view, props, changed, scheme, { leaf: true });
|
|
1046
|
+
view.measureCache = null;
|
|
1047
|
+
}
|
|
1048
|
+
measure(view, maxW, maxH) {
|
|
1049
|
+
const [w, h] = measureElement(view.el, maxW, maxH);
|
|
1050
|
+
return [w, Math.max(24, h)];
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1054
|
+
class SegmentedControlManager extends ViewManager {
|
|
1055
|
+
create(view, props) {
|
|
1056
|
+
const el = document.createElement("div");
|
|
1057
|
+
el.className = "pn-view pn-segmented";
|
|
1058
|
+
view.el = el;
|
|
1059
|
+
this.update(view, props);
|
|
1060
|
+
}
|
|
1061
|
+
update(view, changed) {
|
|
1062
|
+
const props = view.props;
|
|
1063
|
+
const el = view.el;
|
|
1064
|
+
const scheme = view.ctx.scheme();
|
|
1065
|
+
if ("segments" in changed || "selected_index" in changed || "disabled" in changed || "tint_color" in changed) {
|
|
1066
|
+
el.textContent = "";
|
|
1067
|
+
const segments = Array.isArray(props.segments) ? props.segments : [];
|
|
1068
|
+
segments.forEach((label, index) => {
|
|
1069
|
+
const button = document.createElement("button");
|
|
1070
|
+
button.type = "button";
|
|
1071
|
+
button.textContent = String(label);
|
|
1072
|
+
button.disabled = props.disabled === true;
|
|
1073
|
+
if (index === Number(props.selected_index)) {
|
|
1074
|
+
button.classList.add("pn-selected");
|
|
1075
|
+
const tint = parseColor(props.tint_color, scheme);
|
|
1076
|
+
if (tint) button.style.backgroundColor = tint;
|
|
1077
|
+
}
|
|
1078
|
+
button.addEventListener("click", () => view.ctx.emit(view.tag, "on_change", [index]));
|
|
1079
|
+
el.appendChild(button);
|
|
1080
|
+
});
|
|
1081
|
+
}
|
|
1082
|
+
applyStyle(view, props, changed, scheme, { leaf: true });
|
|
1083
|
+
view.measureCache = null;
|
|
1084
|
+
}
|
|
1085
|
+
measure(view, maxW) {
|
|
1086
|
+
const [w] = measureElement(view.el, maxW, INF);
|
|
1087
|
+
return [isFiniteConstraint(maxW) ? Math.min(Math.max(w, 120), maxW) : Math.max(w, 120), 32];
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1091
|
+
class PickerManager extends ViewManager {
|
|
1092
|
+
create(view, props) {
|
|
1093
|
+
const el = document.createElement("select");
|
|
1094
|
+
el.className = "pn-view pn-select";
|
|
1095
|
+
el.addEventListener("change", () => {
|
|
1096
|
+
const item = (view.props.items || [])[el.selectedIndex - (view.hasPlaceholder ? 1 : 0)];
|
|
1097
|
+
view.ctx.emit(view.tag, "on_change", [item ? item.value : null]);
|
|
1098
|
+
});
|
|
1099
|
+
view.el = el;
|
|
1100
|
+
this.update(view, props);
|
|
1101
|
+
}
|
|
1102
|
+
update(view, changed) {
|
|
1103
|
+
const props = view.props;
|
|
1104
|
+
const el = view.el;
|
|
1105
|
+
if ("items" in changed || "placeholder" in changed || "value" in changed) {
|
|
1106
|
+
el.textContent = "";
|
|
1107
|
+
view.hasPlaceholder = props.placeholder != null;
|
|
1108
|
+
if (view.hasPlaceholder) {
|
|
1109
|
+
const opt = document.createElement("option");
|
|
1110
|
+
opt.textContent = String(props.placeholder);
|
|
1111
|
+
opt.disabled = true;
|
|
1112
|
+
opt.selected = props.value == null;
|
|
1113
|
+
el.appendChild(opt);
|
|
1114
|
+
}
|
|
1115
|
+
for (const item of Array.isArray(props.items) ? props.items : []) {
|
|
1116
|
+
const opt = document.createElement("option");
|
|
1117
|
+
opt.textContent = String(item.label ?? item.value ?? "");
|
|
1118
|
+
opt.selected = props.value != null && String(item.value) === String(props.value);
|
|
1119
|
+
el.appendChild(opt);
|
|
1120
|
+
}
|
|
1121
|
+
}
|
|
1122
|
+
applyStyle(view, props, changed, view.ctx.scheme(), { leaf: true });
|
|
1123
|
+
view.measureCache = null;
|
|
1124
|
+
}
|
|
1125
|
+
measure(view, maxW) {
|
|
1126
|
+
const [w] = measureElement(view.el, maxW, INF);
|
|
1127
|
+
return [Math.max(100, w), 36];
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
class DatePickerManager extends ViewManager {
|
|
1132
|
+
create(view, props) {
|
|
1133
|
+
const el = document.createElement("input");
|
|
1134
|
+
el.className = "pn-view pn-date";
|
|
1135
|
+
el.addEventListener("change", () => view.ctx.emit(view.tag, "on_change", [el.value]));
|
|
1136
|
+
view.el = el;
|
|
1137
|
+
this.update(view, props);
|
|
1138
|
+
}
|
|
1139
|
+
update(view, changed) {
|
|
1140
|
+
const props = view.props;
|
|
1141
|
+
const el = view.el;
|
|
1142
|
+
const mode = props.mode || "date";
|
|
1143
|
+
el.type = mode === "time" ? "time" : mode === "datetime" ? "datetime-local" : "date";
|
|
1144
|
+
if ("value" in changed && props.value != null) el.value = String(props.value);
|
|
1145
|
+
if ("minimum" in changed) el.min = props.minimum == null ? "" : String(props.minimum);
|
|
1146
|
+
if ("maximum" in changed) el.max = props.maximum == null ? "" : String(props.maximum);
|
|
1147
|
+
if ("disabled" in changed) el.disabled = props.disabled === true;
|
|
1148
|
+
if ("tint_color" in changed) el.style.accentColor = parseColor(props.tint_color, view.ctx.scheme()) ?? "";
|
|
1149
|
+
applyStyle(view, props, changed, view.ctx.scheme(), { leaf: true });
|
|
1150
|
+
}
|
|
1151
|
+
measure() {
|
|
1152
|
+
return [160, 36];
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
class TabBarManager extends ViewManager {
|
|
1157
|
+
create(view, props) {
|
|
1158
|
+
const el = document.createElement("div");
|
|
1159
|
+
el.className = "pn-view pn-tabbar";
|
|
1160
|
+
view.el = el;
|
|
1161
|
+
this.update(view, props);
|
|
1162
|
+
}
|
|
1163
|
+
update(view, changed) {
|
|
1164
|
+
const props = view.props;
|
|
1165
|
+
const el = view.el;
|
|
1166
|
+
const scheme = view.ctx.scheme();
|
|
1167
|
+
el.textContent = "";
|
|
1168
|
+
const items = Array.isArray(props.items) ? props.items : [];
|
|
1169
|
+
const activeName = props.active_tab;
|
|
1170
|
+
const activeIndex = props.active_index != null ? Number(props.active_index) : -1;
|
|
1171
|
+
el.style.setProperty("--pn-tab-active", parseColor(props.active_color ?? props.tint_color, scheme) ?? "");
|
|
1172
|
+
const inactive = parseColor(props.inactive_color, scheme);
|
|
1173
|
+
el.style.paddingBottom = px(view.ctx.bottomInset());
|
|
1174
|
+
items.forEach((item, index) => {
|
|
1175
|
+
const name = item.name ?? item.title ?? String(index);
|
|
1176
|
+
const button = document.createElement("button");
|
|
1177
|
+
button.type = "button";
|
|
1178
|
+
const active = activeName != null ? name === activeName : index === activeIndex;
|
|
1179
|
+
button.classList.toggle("pn-active", active);
|
|
1180
|
+
if (!active && inactive) button.style.color = inactive;
|
|
1181
|
+
const icon = document.createElement("span");
|
|
1182
|
+
icon.className = "pn-tab-icon";
|
|
1183
|
+
icon.textContent = tabIcon(item.icon);
|
|
1184
|
+
const label = document.createElement("span");
|
|
1185
|
+
label.textContent = String(item.title ?? name);
|
|
1186
|
+
button.appendChild(icon);
|
|
1187
|
+
button.appendChild(label);
|
|
1188
|
+
if (item.badge != null && item.badge !== "") {
|
|
1189
|
+
const badge = document.createElement("span");
|
|
1190
|
+
badge.className = "pn-badge";
|
|
1191
|
+
badge.textContent = String(item.badge);
|
|
1192
|
+
button.appendChild(badge);
|
|
1193
|
+
}
|
|
1194
|
+
button.addEventListener("click", () => {
|
|
1195
|
+
view.ctx.emit(view.tag, "on_tab_select", [name]);
|
|
1196
|
+
if (view.hasEvent("on_select")) view.ctx.emit(view.tag, "on_select", [index]);
|
|
1197
|
+
});
|
|
1198
|
+
el.appendChild(button);
|
|
1199
|
+
});
|
|
1200
|
+
applyStyle(view, props, changed, scheme);
|
|
1201
|
+
if ("background_color" in changed && props.background_color == null) el.style.backgroundColor = "";
|
|
1202
|
+
}
|
|
1203
|
+
measure(view, maxW) {
|
|
1204
|
+
return [isFiniteConstraint(maxW) ? maxW : view.ctx.frameWidth(), 49 + view.ctx.bottomInset()];
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1207
|
+
|
|
1208
|
+
const TAB_ICONS = {
|
|
1209
|
+
house: "⌂",
|
|
1210
|
+
home: "⌂",
|
|
1211
|
+
gear: "⚙",
|
|
1212
|
+
settings: "⚙",
|
|
1213
|
+
person: "☺",
|
|
1214
|
+
profile: "☺",
|
|
1215
|
+
star: "★",
|
|
1216
|
+
heart: "♥",
|
|
1217
|
+
magnifyingglass: "⌕",
|
|
1218
|
+
search: "⌕",
|
|
1219
|
+
bell: "🔔",
|
|
1220
|
+
list: "☰",
|
|
1221
|
+
plus: "+",
|
|
1222
|
+
camera: "📷",
|
|
1223
|
+
map: "🗺",
|
|
1224
|
+
cart: "🛒",
|
|
1225
|
+
chat: "💬",
|
|
1226
|
+
message: "💬",
|
|
1227
|
+
};
|
|
1228
|
+
|
|
1229
|
+
function tabIcon(icon) {
|
|
1230
|
+
if (icon && typeof icon === "object") icon = icon.web ?? icon.ios ?? icon.android ?? "";
|
|
1231
|
+
const name = String(icon || "").toLowerCase().replace(/\.fill$/, "").replace(/\.circle$/, "");
|
|
1232
|
+
if (!name) return "●";
|
|
1233
|
+
for (const [key, glyph] of Object.entries(TAB_ICONS)) {
|
|
1234
|
+
if (name.includes(key)) return glyph;
|
|
1235
|
+
}
|
|
1236
|
+
return "●";
|
|
1237
|
+
}
|
|
1238
|
+
|
|
1239
|
+
class ModalManager extends ViewManager {
|
|
1240
|
+
create(view, props) {
|
|
1241
|
+
// The element in the tree is a zero-size placeholder; the content
|
|
1242
|
+
// lives in the overlay layer while `visible` is true.
|
|
1243
|
+
const el = document.createElement("div");
|
|
1244
|
+
el.className = "pn-view";
|
|
1245
|
+
el.style.display = "none";
|
|
1246
|
+
const backdrop = document.createElement("div");
|
|
1247
|
+
backdrop.className = "pn-modal-backdrop";
|
|
1248
|
+
const sheet = document.createElement("div");
|
|
1249
|
+
sheet.className = "pn-modal-sheet";
|
|
1250
|
+
backdrop.appendChild(sheet);
|
|
1251
|
+
backdrop.addEventListener("click", (event) => {
|
|
1252
|
+
if (event.target !== backdrop) return;
|
|
1253
|
+
if (view.props.dismiss_on_backdrop === false) return;
|
|
1254
|
+
if (view.hasEvent("on_request_close")) view.ctx.emit(view.tag, "on_request_close", []);
|
|
1255
|
+
});
|
|
1256
|
+
view.el = el;
|
|
1257
|
+
view.backdrop = backdrop;
|
|
1258
|
+
view.sheet = sheet;
|
|
1259
|
+
view.shown = false;
|
|
1260
|
+
this.update(view, props);
|
|
1261
|
+
}
|
|
1262
|
+
container(view) {
|
|
1263
|
+
return view.sheet;
|
|
1264
|
+
}
|
|
1265
|
+
frame() {}
|
|
1266
|
+
update(view, changed) {
|
|
1267
|
+
const props = view.props;
|
|
1268
|
+
const scheme = view.ctx.scheme();
|
|
1269
|
+
const style = props.presentation_style;
|
|
1270
|
+
const overlay = style === "overlay" || !!props.transparent;
|
|
1271
|
+
view.sheet.className = "pn-modal-sheet";
|
|
1272
|
+
if (style === "full_screen") view.sheet.classList.add("pn-full");
|
|
1273
|
+
else if (style === "form_sheet") view.sheet.classList.add("pn-form");
|
|
1274
|
+
if (overlay) view.sheet.classList.add("pn-overlay");
|
|
1275
|
+
view.backdrop.classList.toggle("pn-transparent", overlay);
|
|
1276
|
+
view.sheet.style.backgroundColor = !overlay ? (parseColor(props.background_color, scheme) ?? "") : "transparent";
|
|
1277
|
+
const visible = !!props.visible;
|
|
1278
|
+
if (visible && !view.shown) {
|
|
1279
|
+
view.shown = true;
|
|
1280
|
+
view.ctx.overlays().appendChild(view.backdrop);
|
|
1281
|
+
view.ctx.emit(view.tag, "on_show", []);
|
|
1282
|
+
} else if (!visible && view.shown) {
|
|
1283
|
+
view.shown = false;
|
|
1284
|
+
view.backdrop.remove();
|
|
1285
|
+
view.ctx.emit(view.tag, "on_dismiss", []);
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
destroy(view) {
|
|
1289
|
+
if (view.shown) view.backdrop.remove();
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
|
|
1293
|
+
class PortalManager extends ViewManager {
|
|
1294
|
+
create(view, props) {
|
|
1295
|
+
const el = document.createElement("div");
|
|
1296
|
+
el.className = "pn-view";
|
|
1297
|
+
el.style.display = "none";
|
|
1298
|
+
const layer = document.createElement("div");
|
|
1299
|
+
layer.className = "pn-view";
|
|
1300
|
+
layer.style.inset = "0";
|
|
1301
|
+
layer.style.width = layer.style.height = "100%";
|
|
1302
|
+
layer.style.pointerEvents = "none";
|
|
1303
|
+
view.el = el;
|
|
1304
|
+
view.layer = layer;
|
|
1305
|
+
view.ctx.overlays().appendChild(layer);
|
|
1306
|
+
this.update(view, props);
|
|
1307
|
+
}
|
|
1308
|
+
container(view) {
|
|
1309
|
+
return view.layer;
|
|
1310
|
+
}
|
|
1311
|
+
frame() {}
|
|
1312
|
+
update() {}
|
|
1313
|
+
destroy(view) {
|
|
1314
|
+
view.layer.remove();
|
|
1315
|
+
}
|
|
1316
|
+
childrenChanged(view) {
|
|
1317
|
+
for (const child of view.children) child.el.style.pointerEvents = "auto";
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1320
|
+
|
|
1321
|
+
class StatusBarManager extends ViewManager {
|
|
1322
|
+
create(view, props) {
|
|
1323
|
+
const el = document.createElement("div");
|
|
1324
|
+
el.className = "pn-view";
|
|
1325
|
+
el.style.display = "none";
|
|
1326
|
+
view.el = el;
|
|
1327
|
+
this.update(view, props);
|
|
1328
|
+
}
|
|
1329
|
+
frame() {}
|
|
1330
|
+
update(view) {
|
|
1331
|
+
const props = view.props;
|
|
1332
|
+
const style = props.bar_style;
|
|
1333
|
+
view.ctx.statusBar({
|
|
1334
|
+
hidden: !!props.hidden,
|
|
1335
|
+
light: style === "light" || style === "light_content",
|
|
1336
|
+
dark: style === "dark" || style === "dark_content",
|
|
1337
|
+
});
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1340
|
+
|
|
1341
|
+
class WebViewManager extends ViewManager {
|
|
1342
|
+
create(view, props) {
|
|
1343
|
+
const el = document.createElement("div");
|
|
1344
|
+
el.className = "pn-view";
|
|
1345
|
+
const frame = document.createElement("iframe");
|
|
1346
|
+
frame.className = "pn-webview";
|
|
1347
|
+
frame.setAttribute("sandbox", "allow-scripts allow-forms allow-popups allow-same-origin");
|
|
1348
|
+
el.appendChild(frame);
|
|
1349
|
+
view.el = el;
|
|
1350
|
+
view.frame = frame;
|
|
1351
|
+
frame.addEventListener("load", () => {
|
|
1352
|
+
let url = view.props.url || view.props.base_url || "about:srcdoc";
|
|
1353
|
+
try {
|
|
1354
|
+
url = frame.contentWindow.location.href;
|
|
1355
|
+
} catch (err) {
|
|
1356
|
+
/* cross-origin */
|
|
1357
|
+
}
|
|
1358
|
+
view.ctx.emit(view.tag, "on_load", [url]);
|
|
1359
|
+
if (view.hasEvent("on_navigation_state_change")) {
|
|
1360
|
+
view.ctx.emit(view.tag, "on_navigation_state_change", [{ url, loading: false, can_go_back: false, can_go_forward: false, title: "" }]);
|
|
1361
|
+
}
|
|
1362
|
+
});
|
|
1363
|
+
view.onMessage = (event) => {
|
|
1364
|
+
if (event.source !== frame.contentWindow) return;
|
|
1365
|
+
const data = event.data;
|
|
1366
|
+
view.ctx.emit(view.tag, "on_message", [typeof data === "string" ? data : JSON.stringify(data)]);
|
|
1367
|
+
};
|
|
1368
|
+
window.addEventListener("message", view.onMessage);
|
|
1369
|
+
this.update(view, props);
|
|
1370
|
+
}
|
|
1371
|
+
update(view, changed) {
|
|
1372
|
+
const props = view.props;
|
|
1373
|
+
if ("url" in changed && props.url) {
|
|
1374
|
+
view.frame.removeAttribute("srcdoc");
|
|
1375
|
+
view.frame.src = String(props.url);
|
|
1376
|
+
if (view.hasEvent("on_load_start")) view.ctx.emit(view.tag, "on_load_start", [String(props.url)]);
|
|
1377
|
+
} else if ("html" in changed && props.html != null) {
|
|
1378
|
+
const shim =
|
|
1379
|
+
"<script>window.webkit={messageHandlers:{pythonnative:{postMessage:function(m){parent.postMessage(m,'*');}}}};</script>";
|
|
1380
|
+
view.frame.srcdoc = shim + String(props.html);
|
|
1381
|
+
}
|
|
1382
|
+
if ("scroll_enabled" in changed) view.frame.style.overflow = props.scroll_enabled === false ? "hidden" : "";
|
|
1383
|
+
applyStyle(view, props, changed, view.ctx.scheme(), { leaf: true });
|
|
1384
|
+
}
|
|
1385
|
+
command(view, name, args) {
|
|
1386
|
+
const win = view.frame.contentWindow;
|
|
1387
|
+
try {
|
|
1388
|
+
switch (name) {
|
|
1389
|
+
case "eval_js":
|
|
1390
|
+
case "inject_javascript":
|
|
1391
|
+
win.eval(String(args.source ?? args.script ?? ""));
|
|
1392
|
+
return null;
|
|
1393
|
+
case "reload":
|
|
1394
|
+
win.location.reload();
|
|
1395
|
+
return null;
|
|
1396
|
+
case "go_back":
|
|
1397
|
+
win.history.back();
|
|
1398
|
+
return null;
|
|
1399
|
+
case "go_forward":
|
|
1400
|
+
win.history.forward();
|
|
1401
|
+
return null;
|
|
1402
|
+
case "stop_loading":
|
|
1403
|
+
win.stop();
|
|
1404
|
+
return null;
|
|
1405
|
+
case "load_url":
|
|
1406
|
+
view.frame.src = String(args.url || "");
|
|
1407
|
+
return null;
|
|
1408
|
+
case "get_url":
|
|
1409
|
+
return win.location.href;
|
|
1410
|
+
case "can_go_back":
|
|
1411
|
+
case "can_go_forward":
|
|
1412
|
+
return false;
|
|
1413
|
+
default:
|
|
1414
|
+
return null;
|
|
1415
|
+
}
|
|
1416
|
+
} catch (err) {
|
|
1417
|
+
return null;
|
|
1418
|
+
}
|
|
1419
|
+
}
|
|
1420
|
+
destroy(view) {
|
|
1421
|
+
window.removeEventListener("message", view.onMessage);
|
|
1422
|
+
}
|
|
1423
|
+
}
|
|
1424
|
+
|
|
1425
|
+
class VirtualListManager extends ViewManager {
|
|
1426
|
+
create(view, props) {
|
|
1427
|
+
view.el = document.createElement("div"); view.el.className = "pn-view pn-vlist";
|
|
1428
|
+
view.spacer = document.createElement("div"); view.spacer.className = "pn-vlist-spacer";
|
|
1429
|
+
view.el.appendChild(view.spacer); view.requested = new Set();
|
|
1430
|
+
view.el.addEventListener("scroll", () => {
|
|
1431
|
+
this.childrenChanged(view);
|
|
1432
|
+
view.ctx.emit(view.tag, "on_scroll", [{...scrollPayload(view.el, false), first:view.first, last:view.last}]);
|
|
1433
|
+
}, {passive:true});
|
|
1434
|
+
this.update(view, props);
|
|
1435
|
+
}
|
|
1436
|
+
container(view) { return view.spacer; }
|
|
1437
|
+
update(view, props) {
|
|
1438
|
+
super.update(view, props);
|
|
1439
|
+
view.el.style.overflow = "auto";
|
|
1440
|
+
if ("revision" in props) view.requested.clear();
|
|
1441
|
+
this.childrenChanged(view);
|
|
1442
|
+
}
|
|
1443
|
+
measure(view, w, h) { return [w < 1e6 ? w : 0, h < 1e6 ? h : 0]; }
|
|
1444
|
+
childrenChanged(view) {
|
|
1445
|
+
const keys = view.props.keys || [];
|
|
1446
|
+
const roots = new Map(view.children.map(child => [child.props._pn_list_key, child]));
|
|
1447
|
+
const horizontal = view.props.horizontal;
|
|
1448
|
+
const offset = horizontal ? view.el.scrollLeft : view.el.scrollTop;
|
|
1449
|
+
const extent = (horizontal ? view.el.clientWidth : view.el.clientHeight) || 800;
|
|
1450
|
+
let position = 0; view.first = 0; view.last = -1;
|
|
1451
|
+
for (let i = 0; i < keys.length; i++) {
|
|
1452
|
+
const key = keys[i], child = roots.get(key);
|
|
1453
|
+
const size = child?.frame?.[horizontal ? "w" : "h"] || view.props.row_heights?.[i] || 44;
|
|
1454
|
+
const visible = position + size >= offset - extent && position <= offset + 2 * extent;
|
|
1455
|
+
if (child) {
|
|
1456
|
+
child.el.style.display = visible ? "" : "none";
|
|
1457
|
+
child.el.style[horizontal ? "left" : "top"] = px(position);
|
|
1458
|
+
}
|
|
1459
|
+
if (visible) {
|
|
1460
|
+
if (view.last < 0) view.first = i;
|
|
1461
|
+
view.last = i;
|
|
1462
|
+
if (!child && !view.requested.has(key)) {
|
|
1463
|
+
view.requested.add(key);
|
|
1464
|
+
view.ctx.emit(view.tag, "on_bind_row", [{key, index:i, revision:view.props.revision, width:view.el.clientWidth}]);
|
|
1465
|
+
}
|
|
1466
|
+
}
|
|
1467
|
+
position += size;
|
|
1468
|
+
}
|
|
1469
|
+
view.spacer.style[horizontal ? "width" : "height"] = px(position);
|
|
1470
|
+
}
|
|
1471
|
+
command(view, name, args) {
|
|
1472
|
+
let offset = args.y || 0;
|
|
1473
|
+
if (name === "scroll_to_end") offset = view.el.scrollHeight;
|
|
1474
|
+
if (name === "scroll_to_index") offset = (view.props.row_heights || []).slice(0, args.index).reduce((a,b) => a+b, 0);
|
|
1475
|
+
view.el.scrollTo({top: offset, behavior: args.animated ? "smooth" : "instant"});
|
|
1476
|
+
return null;
|
|
1477
|
+
}
|
|
1478
|
+
}
|
|
1479
|
+
|
|
1480
|
+
class ScreenStackManager extends ViewManager {
|
|
1481
|
+
childrenChanged(view) {
|
|
1482
|
+
for (const [index, child] of view.children.entries()) child.el.style.display = index === view.children.length - 1 ? "" : "none";
|
|
1483
|
+
}
|
|
1484
|
+
}
|
|
1485
|
+
|
|
1486
|
+
class PlaceholderManager extends ViewManager {
|
|
1487
|
+
create(view, props) {
|
|
1488
|
+
const el = document.createElement("div");
|
|
1489
|
+
el.className = "pn-view pn-placeholder";
|
|
1490
|
+
el.textContent = view.type;
|
|
1491
|
+
el.title = `No browser implementation for ${view.type}; it renders natively on device.`;
|
|
1492
|
+
view.el = el;
|
|
1493
|
+
this.update(view, props);
|
|
1494
|
+
}
|
|
1495
|
+
measure(view, maxW) {
|
|
1496
|
+
return [Math.min(isFiniteConstraint(maxW) ? maxW : 120, 120), 32];
|
|
1497
|
+
}
|
|
1498
|
+
}
|
|
1499
|
+
|
|
1500
|
+
const MANAGERS = {
|
|
1501
|
+
View: ViewManager,
|
|
1502
|
+
Column: ViewManager,
|
|
1503
|
+
Row: ViewManager,
|
|
1504
|
+
SafeAreaView: ViewManager,
|
|
1505
|
+
KeyboardAvoidingView: ViewManager,
|
|
1506
|
+
Spacer: SpacerManager,
|
|
1507
|
+
Text: TextManager,
|
|
1508
|
+
Button: ButtonManager,
|
|
1509
|
+
TextInput: TextInputManager,
|
|
1510
|
+
Image: ImageManager,
|
|
1511
|
+
Switch: SwitchManager,
|
|
1512
|
+
Slider: SliderManager,
|
|
1513
|
+
ActivityIndicator: ActivityIndicatorManager,
|
|
1514
|
+
ProgressBar: ProgressBarManager,
|
|
1515
|
+
ScrollView: ScrollViewManager,
|
|
1516
|
+
Pressable: PressableManager,
|
|
1517
|
+
Checkbox: CheckboxManager,
|
|
1518
|
+
SegmentedControl: SegmentedControlManager,
|
|
1519
|
+
Picker: PickerManager,
|
|
1520
|
+
DatePicker: DatePickerManager,
|
|
1521
|
+
TabBar: TabBarManager,
|
|
1522
|
+
Modal: ModalManager,
|
|
1523
|
+
Portal: PortalManager,
|
|
1524
|
+
StatusBar: StatusBarManager,
|
|
1525
|
+
WebView: WebViewManager,
|
|
1526
|
+
VirtualList: VirtualListManager,
|
|
1527
|
+
Screen: ViewManager,
|
|
1528
|
+
ScreenStack: ScreenStackManager,
|
|
1529
|
+
};
|
|
1530
|
+
|
|
1531
|
+
// ---------------------------------------------------------------------------
|
|
1532
|
+
// Animations (PNAnimator equivalent)
|
|
1533
|
+
// ---------------------------------------------------------------------------
|
|
1534
|
+
|
|
1535
|
+
const EASINGS = {
|
|
1536
|
+
linear: (t) => t,
|
|
1537
|
+
ease_in: (t) => t * t,
|
|
1538
|
+
ease_in_quad: (t) => t * t,
|
|
1539
|
+
ease_out: (t) => 1 - (1 - t) * (1 - t),
|
|
1540
|
+
ease_out_quad: (t) => 1 - (1 - t) * (1 - t),
|
|
1541
|
+
ease: (t) => (t < 0.5 ? 2 * t * t : 1 - Math.pow(-2 * t + 2, 2) / 2),
|
|
1542
|
+
ease_in_out: (t) => (t < 0.5 ? 2 * t * t : 1 - Math.pow(-2 * t + 2, 2) / 2),
|
|
1543
|
+
bounce: (t) => {
|
|
1544
|
+
const n1 = 7.5625;
|
|
1545
|
+
const d1 = 2.75;
|
|
1546
|
+
if (t < 1 / d1) return n1 * t * t;
|
|
1547
|
+
if (t < 2 / d1) return n1 * (t -= 1.5 / d1) * t + 0.75;
|
|
1548
|
+
if (t < 2.5 / d1) return n1 * (t -= 2.25 / d1) * t + 0.9375;
|
|
1549
|
+
return n1 * (t -= 2.625 / d1) * t + 0.984375;
|
|
1550
|
+
},
|
|
1551
|
+
};
|
|
1552
|
+
|
|
1553
|
+
function cubicBezier(x1, y1, x2, y2) {
|
|
1554
|
+
const sample = (t, a, b) => 3 * a * (1 - t) * (1 - t) * t + 3 * b * (1 - t) * t * t + t * t * t;
|
|
1555
|
+
return (x) => {
|
|
1556
|
+
let lo = 0;
|
|
1557
|
+
let hi = 1;
|
|
1558
|
+
let t = x;
|
|
1559
|
+
for (let i = 0; i < 24; i++) {
|
|
1560
|
+
const cx = sample(t, x1, x2);
|
|
1561
|
+
if (Math.abs(cx - x) < 1e-4) break;
|
|
1562
|
+
if (cx < x) lo = t;
|
|
1563
|
+
else hi = t;
|
|
1564
|
+
t = (lo + hi) / 2;
|
|
1565
|
+
}
|
|
1566
|
+
return sample(t, y1, y2);
|
|
1567
|
+
};
|
|
1568
|
+
}
|
|
1569
|
+
|
|
1570
|
+
const ANIM_TRANSFORM = new Set(["translate_x", "translate_y", "scale", "scale_x", "scale_y", "rotate"]);
|
|
1571
|
+
|
|
1572
|
+
class Animator {
|
|
1573
|
+
constructor(renderer) {
|
|
1574
|
+
this.renderer = renderer;
|
|
1575
|
+
this.active = new Map(); // id -> {view, prop, cancel}
|
|
1576
|
+
}
|
|
1577
|
+
set(view, prop, value) {
|
|
1578
|
+
if (prop.startsWith("_pn_graph:")) { this.renderer.graph.set(Number(prop.slice(10)), value); return; }
|
|
1579
|
+
if (ANIM_TRANSFORM.has(prop)) {
|
|
1580
|
+
view.animTransform = view.animTransform || {};
|
|
1581
|
+
view.animTransform[prop] = Number(value) || 0;
|
|
1582
|
+
composeTransform(view);
|
|
1583
|
+
} else if (prop === "opacity") {
|
|
1584
|
+
view.el.style.opacity = String(value);
|
|
1585
|
+
} else if (prop === "background_color") {
|
|
1586
|
+
view.el.style.backgroundColor = parseColor(value, this.renderer.ctx.scheme()) ?? "";
|
|
1587
|
+
} else if (prop === "color") {
|
|
1588
|
+
view.el.style.color = parseColor(value, this.renderer.ctx.scheme()) ?? "";
|
|
1589
|
+
}
|
|
1590
|
+
view.animValues = view.animValues || {};
|
|
1591
|
+
view.animValues[prop] = value;
|
|
1592
|
+
}
|
|
1593
|
+
current(view, prop) {
|
|
1594
|
+
if (prop.startsWith("_pn_graph:")) return this.renderer.graph.values.get(Number(prop.slice(10))) || 0;
|
|
1595
|
+
if (view.animValues && prop in view.animValues) return view.animValues[prop];
|
|
1596
|
+
if (prop === "opacity") return view.el.style.opacity === "" ? 1 : Number(view.el.style.opacity);
|
|
1597
|
+
if (prop === "scale" || prop === "scale_x" || prop === "scale_y") return 1;
|
|
1598
|
+
return 0;
|
|
1599
|
+
}
|
|
1600
|
+
start(view, id, prop, spec) {
|
|
1601
|
+
if (!spec || typeof spec !== "object") return false;
|
|
1602
|
+
const kind = spec.kind;
|
|
1603
|
+
const isColor = prop === "background_color" || prop === "color";
|
|
1604
|
+
if (isColor) return false; // color interpolation stays on the Python ticker
|
|
1605
|
+
const from = spec.from != null ? Number(spec.from) : Number(this.current(view, prop)) || 0;
|
|
1606
|
+
let step;
|
|
1607
|
+
let finished = false;
|
|
1608
|
+
if (kind === "timing") {
|
|
1609
|
+
const to = Number(spec.to);
|
|
1610
|
+
const duration = Math.max(1, Number(spec.duration_ms) || 300);
|
|
1611
|
+
let easing = EASINGS.ease_in_out;
|
|
1612
|
+
if (Array.isArray(spec.easing) && spec.easing.length === 4) easing = cubicBezier(...spec.easing.map(Number));
|
|
1613
|
+
else if (typeof spec.easing === "string" && EASINGS[spec.easing]) easing = EASINGS[spec.easing];
|
|
1614
|
+
step = (elapsed) => {
|
|
1615
|
+
const t = Math.min(1, elapsed / duration);
|
|
1616
|
+
const value = from + (to - from) * easing(t);
|
|
1617
|
+
return [value, t >= 1];
|
|
1618
|
+
};
|
|
1619
|
+
} else if (kind === "spring") {
|
|
1620
|
+
const to = Number(spec.to);
|
|
1621
|
+
const stiffness = Number(spec.stiffness) || 100;
|
|
1622
|
+
const damping = Number(spec.damping) || 10;
|
|
1623
|
+
const mass = Number(spec.mass) || 1;
|
|
1624
|
+
let position = from;
|
|
1625
|
+
let velocity = Number(spec.initial_velocity) || 0;
|
|
1626
|
+
let last = 0;
|
|
1627
|
+
step = (elapsed) => {
|
|
1628
|
+
const dt = Math.min(0.064, (elapsed - last) / 1000);
|
|
1629
|
+
last = elapsed;
|
|
1630
|
+
const steps = Math.max(1, Math.ceil(dt / 0.004));
|
|
1631
|
+
const h = dt / steps;
|
|
1632
|
+
for (let i = 0; i < steps; i++) {
|
|
1633
|
+
const force = -stiffness * (position - to) - damping * velocity;
|
|
1634
|
+
velocity += (force / mass) * h;
|
|
1635
|
+
position += velocity * h;
|
|
1636
|
+
}
|
|
1637
|
+
const done = Math.abs(velocity) < 0.01 && Math.abs(position - to) < 0.01;
|
|
1638
|
+
return [done ? to : position, done];
|
|
1639
|
+
};
|
|
1640
|
+
} else if (kind === "decay") {
|
|
1641
|
+
let velocity = Number(spec.velocity) || 0; // units per second
|
|
1642
|
+
const deceleration = Number(spec.deceleration) || 0.997;
|
|
1643
|
+
let position = from;
|
|
1644
|
+
let last = 0;
|
|
1645
|
+
step = (elapsed) => {
|
|
1646
|
+
const dt = elapsed - last;
|
|
1647
|
+
last = elapsed;
|
|
1648
|
+
const factor = Math.pow(deceleration, dt);
|
|
1649
|
+
position += (velocity * (1 - factor)) / (1000 * (1 - deceleration));
|
|
1650
|
+
velocity *= factor;
|
|
1651
|
+
return [position, Math.abs(velocity) < 0.5];
|
|
1652
|
+
};
|
|
1653
|
+
} else {
|
|
1654
|
+
return false;
|
|
1655
|
+
}
|
|
1656
|
+
const delay = Number(spec.delay_ms) || 0;
|
|
1657
|
+
const startedAt = performance.now() + delay;
|
|
1658
|
+
const handle = { view, prop, frame: 0 };
|
|
1659
|
+
const tick = (now) => {
|
|
1660
|
+
if (!this.active.has(id)) return;
|
|
1661
|
+
if (now < startedAt) {
|
|
1662
|
+
handle.frame = requestAnimationFrame(tick);
|
|
1663
|
+
return;
|
|
1664
|
+
}
|
|
1665
|
+
const [value, done] = step(now - startedAt);
|
|
1666
|
+
this.set(view, prop, value);
|
|
1667
|
+
if (done) {
|
|
1668
|
+
finished = true;
|
|
1669
|
+
this.active.delete(id);
|
|
1670
|
+
this.renderer.ctx.animationFinished(id, true);
|
|
1671
|
+
return;
|
|
1672
|
+
}
|
|
1673
|
+
handle.frame = requestAnimationFrame(tick);
|
|
1674
|
+
};
|
|
1675
|
+
this.active.set(id, handle);
|
|
1676
|
+
handle.frame = requestAnimationFrame(tick);
|
|
1677
|
+
return true;
|
|
1678
|
+
}
|
|
1679
|
+
cancel(id) {
|
|
1680
|
+
const handle = this.active.get(id);
|
|
1681
|
+
if (!handle) return null;
|
|
1682
|
+
this.active.delete(id);
|
|
1683
|
+
cancelAnimationFrame(handle.frame);
|
|
1684
|
+
this.renderer.ctx.animationFinished(id, false);
|
|
1685
|
+
return { value: this.current(handle.view, handle.prop) };
|
|
1686
|
+
}
|
|
1687
|
+
cancelForView(view) {
|
|
1688
|
+
for (const [id, handle] of [...this.active]) {
|
|
1689
|
+
if (handle.view === view) {
|
|
1690
|
+
this.active.delete(id);
|
|
1691
|
+
cancelAnimationFrame(handle.frame);
|
|
1692
|
+
}
|
|
1693
|
+
}
|
|
1694
|
+
}
|
|
1695
|
+
}
|
|
1696
|
+
|
|
1697
|
+
// ---------------------------------------------------------------------------
|
|
1698
|
+
// Gestures: forward pointer streams to the Python arbiter
|
|
1699
|
+
// ---------------------------------------------------------------------------
|
|
1700
|
+
|
|
1701
|
+
function installGestureSource(view) {
|
|
1702
|
+
if (view.gestureInstalled) return;
|
|
1703
|
+
view.gestureInstalled = true;
|
|
1704
|
+
const el = view.el;
|
|
1705
|
+
const send = (phase, event) => {
|
|
1706
|
+
const point = view.ctx.pointInFrame(event);
|
|
1707
|
+
view.ctx.gesture(view.tag, phase, { id: event.pointerId, x: point.x, y: point.y, specs: view.props.gestures || [] });
|
|
1708
|
+
};
|
|
1709
|
+
el.addEventListener("pointerdown", (event) => {
|
|
1710
|
+
if (!Array.isArray(view.props.gestures) || !view.props.gestures.length) return;
|
|
1711
|
+
try {
|
|
1712
|
+
el.setPointerCapture(event.pointerId);
|
|
1713
|
+
} catch (err) {
|
|
1714
|
+
/* ignore */
|
|
1715
|
+
}
|
|
1716
|
+
view.gestureActive = true;
|
|
1717
|
+
send("down", event);
|
|
1718
|
+
});
|
|
1719
|
+
el.addEventListener("pointermove", (event) => {
|
|
1720
|
+
if (view.gestureActive) send("move", event);
|
|
1721
|
+
});
|
|
1722
|
+
el.addEventListener("pointerup", (event) => {
|
|
1723
|
+
if (!view.gestureActive) return;
|
|
1724
|
+
view.gestureActive = false;
|
|
1725
|
+
send("up", event);
|
|
1726
|
+
});
|
|
1727
|
+
el.addEventListener("pointercancel", (event) => {
|
|
1728
|
+
if (!view.gestureActive) return;
|
|
1729
|
+
view.gestureActive = false;
|
|
1730
|
+
send("cancel", event);
|
|
1731
|
+
});
|
|
1732
|
+
}
|
|
1733
|
+
|
|
1734
|
+
// ---------------------------------------------------------------------------
|
|
1735
|
+
// The renderer
|
|
1736
|
+
// ---------------------------------------------------------------------------
|
|
1737
|
+
|
|
1738
|
+
export class Renderer {
|
|
1739
|
+
/**
|
|
1740
|
+
* @param ctx {{
|
|
1741
|
+
* emit(tag, name, args), request(tag, name, args), gesture(tag, phase, info),
|
|
1742
|
+
* animationFinished(id, finished), scheme(), overlays(), bottomInset(),
|
|
1743
|
+
* frameWidth(), pointInFrame(event), statusBar(opts)
|
|
1744
|
+
* }}
|
|
1745
|
+
*/
|
|
1746
|
+
constructor(ctx) {
|
|
1747
|
+
this.ctx = {...ctx};
|
|
1748
|
+
this.eventSequence = 0;
|
|
1749
|
+
this.ctx.emit = (tag, name, args) => {
|
|
1750
|
+
this.graph.event(tag, name, args);
|
|
1751
|
+
const view = this.views.get(tag);
|
|
1752
|
+
const edit = name === "on_change" && view?.type === "TextInput" ? (view.editRevision = (view.editRevision || 0) + 1) : 0;
|
|
1753
|
+
return ctx.emit(tag, name, {
|
|
1754
|
+
application: this.application, surface: this.surface, revision: this.revision,
|
|
1755
|
+
sequence: ++this.eventSequence, args, edit_revision: edit,
|
|
1756
|
+
});
|
|
1757
|
+
};
|
|
1758
|
+
this.ctx.viewFor = (tag) => this.views.get(tag) || null;
|
|
1759
|
+
this.views = new Map();
|
|
1760
|
+
this.managers = {};
|
|
1761
|
+
this.animator = new Animator(this);
|
|
1762
|
+
this.graph = new AnimationGraph(this);
|
|
1763
|
+
this.dirtyContainers = new Set();
|
|
1764
|
+
for (const [name, Manager] of Object.entries(MANAGERS)) this.managers[name] = new Manager();
|
|
1765
|
+
this.placeholder = new PlaceholderManager();
|
|
1766
|
+
this.warnedTypes = new Set();
|
|
1767
|
+
}
|
|
1768
|
+
|
|
1769
|
+
reset() {
|
|
1770
|
+
for (const view of this.views.values()) {
|
|
1771
|
+
try {
|
|
1772
|
+
disposeLayout(view);
|
|
1773
|
+
view.manager.destroy(view);
|
|
1774
|
+
} catch (err) {
|
|
1775
|
+
/* ignore */
|
|
1776
|
+
}
|
|
1777
|
+
view.el.remove();
|
|
1778
|
+
}
|
|
1779
|
+
this.views.clear();
|
|
1780
|
+
this.animator.active.clear();
|
|
1781
|
+
}
|
|
1782
|
+
|
|
1783
|
+
// -- transactions ------------------------------------------------------
|
|
1784
|
+
|
|
1785
|
+
apply(envelope) {
|
|
1786
|
+
const {version, application, surface, revision, ops} = envelope || {};
|
|
1787
|
+
const fail = (error) => ({ok: false, application, surface, revision, error});
|
|
1788
|
+
if (version !== 2 || !application || surface < 1 || !Array.isArray(ops)) return fail("invalid v2 commit");
|
|
1789
|
+
const replacing = this.application !== application;
|
|
1790
|
+
if (revision !== (replacing ? 1 : this.revision + 1)) return fail("stale revision");
|
|
1791
|
+
const tags = new Set(replacing ? [] : this.views.keys());
|
|
1792
|
+
const parents = new Map(replacing ? [] : [...this.views].map(([tag, view]) => [tag, view.parent?.tag]));
|
|
1793
|
+
for (const op of ops) {
|
|
1794
|
+
if (!Array.isArray(op) || op.length !== {c:4,u:3,i:4,d:2,f:6}[op[0]] || !Number.isSafeInteger(op[1]) || op[1] <= 0) return fail("invalid operation");
|
|
1795
|
+
const [code, tag] = op;
|
|
1796
|
+
if (code === "c") {
|
|
1797
|
+
if (tags.has(tag) || typeof op[2] !== "string" || !op[3] || typeof op[3] !== "object") return fail("invalid create");
|
|
1798
|
+
tags.add(tag);
|
|
1799
|
+
} else {
|
|
1800
|
+
if (!tags.has(tag)) return fail("unknown tag");
|
|
1801
|
+
if (code === "i") {
|
|
1802
|
+
if (!tags.has(op[2]) || !Number.isSafeInteger(op[3]) || op[3] < 0) return fail("invalid insertion");
|
|
1803
|
+
for (let ancestor = tag; ancestor; ancestor = parents.get(ancestor)) if (ancestor === op[2]) return fail("cycle");
|
|
1804
|
+
parents.set(op[2], tag);
|
|
1805
|
+
} else if (code === "d") {
|
|
1806
|
+
if ([...parents.values()].includes(tag)) return fail("destroy children first");
|
|
1807
|
+
parents.delete(tag); tags.delete(tag);
|
|
1808
|
+
} else if (code === "f" && (op.slice(2).some(n => !Number.isFinite(n)) || op[4] < 0 || op[5] < 0)) return fail("invalid frame");
|
|
1809
|
+
}
|
|
1810
|
+
}
|
|
1811
|
+
try {
|
|
1812
|
+
if (replacing && this.application) this.reset();
|
|
1813
|
+
for (const op of ops) this.applyOne(op);
|
|
1814
|
+
for (const view of this.dirtyContainers) if (this.views.has(view.tag)) view.manager.childrenChanged(view);
|
|
1815
|
+
this.dirtyContainers.clear();
|
|
1816
|
+
this.application = application; this.surface = surface; this.revision = revision;
|
|
1817
|
+
return {ok: true, application, surface, revision};
|
|
1818
|
+
} catch (error) { this.reset(); return fail(String(error)); }
|
|
1819
|
+
}
|
|
1820
|
+
|
|
1821
|
+
computeLayout(request) { return computeLayout(this, request); }
|
|
1822
|
+
|
|
1823
|
+
applyOne(op) {
|
|
1824
|
+
switch (op[0]) {
|
|
1825
|
+
case "c": {
|
|
1826
|
+
const [, tag, type, props] = op;
|
|
1827
|
+
const manager = this.managers[type] || this.placeholder;
|
|
1828
|
+
if (manager === this.placeholder && !this.warnedTypes.has(type)) {
|
|
1829
|
+
this.warnedTypes.add(type);
|
|
1830
|
+
console.warn(`[pn] no browser renderer for element type ${type}; drawing a placeholder`);
|
|
1831
|
+
}
|
|
1832
|
+
const view = {
|
|
1833
|
+
tag,
|
|
1834
|
+
type,
|
|
1835
|
+
props: { ...(props || {}) },
|
|
1836
|
+
manager,
|
|
1837
|
+
ctx: this.ctx,
|
|
1838
|
+
children: [],
|
|
1839
|
+
parent: null,
|
|
1840
|
+
frame: null,
|
|
1841
|
+
el: null,
|
|
1842
|
+
hasEvent: null,
|
|
1843
|
+
};
|
|
1844
|
+
view.hasEvent = (name) => Array.isArray(view.props._pn_events) && view.props._pn_events.includes(name);
|
|
1845
|
+
manager.create(view, view.props);
|
|
1846
|
+
view.el.dataset.pnTag = String(tag);
|
|
1847
|
+
view.el.dataset.pnType = type;
|
|
1848
|
+
if (Array.isArray(view.props.gestures) && view.props.gestures.length) installGestureSource(view);
|
|
1849
|
+
this.views.set(tag, view);
|
|
1850
|
+
return;
|
|
1851
|
+
}
|
|
1852
|
+
case "u": {
|
|
1853
|
+
const [, tag, changed] = op;
|
|
1854
|
+
const view = this.views.get(tag);
|
|
1855
|
+
if (!view || !changed) return;
|
|
1856
|
+
for (const [key, value] of Object.entries(changed)) {
|
|
1857
|
+
if (value === null || value === undefined) delete view.props[key];
|
|
1858
|
+
else view.props[key] = value;
|
|
1859
|
+
}
|
|
1860
|
+
view.manager.update(view, changed);
|
|
1861
|
+
if ("gestures" in changed) {
|
|
1862
|
+
if (Array.isArray(view.props.gestures) && view.props.gestures.length) installGestureSource(view);
|
|
1863
|
+
else this.ctx.gesture(tag, "clear", {});
|
|
1864
|
+
}
|
|
1865
|
+
return;
|
|
1866
|
+
}
|
|
1867
|
+
case "i": {
|
|
1868
|
+
const [, parentTag, childTag, index] = op;
|
|
1869
|
+
const parent = this.views.get(parentTag);
|
|
1870
|
+
const child = this.views.get(childTag);
|
|
1871
|
+
if (!parent || !child) return;
|
|
1872
|
+
if (child.parent && child.parent !== parent) {
|
|
1873
|
+
const idx = child.parent.children.indexOf(child);
|
|
1874
|
+
if (idx >= 0) child.parent.children.splice(idx, 1);
|
|
1875
|
+
this.dirtyContainers.add(child.parent);
|
|
1876
|
+
} else if (child.parent === parent) {
|
|
1877
|
+
const idx = parent.children.indexOf(child);
|
|
1878
|
+
if (idx >= 0) parent.children.splice(idx, 1);
|
|
1879
|
+
}
|
|
1880
|
+
const at = Math.max(0, Math.min(index, parent.children.length));
|
|
1881
|
+
parent.children.splice(at, 0, child);
|
|
1882
|
+
child.parent = parent;
|
|
1883
|
+
const container = parent.manager.container(parent);
|
|
1884
|
+
const before = parent.children[at + 1] ? parent.children[at + 1].el : null;
|
|
1885
|
+
if (before && before.parentNode === container) container.insertBefore(child.el, before);
|
|
1886
|
+
else container.appendChild(child.el);
|
|
1887
|
+
applyPointerInheritance(child, parent);
|
|
1888
|
+
this.dirtyContainers.add(parent);
|
|
1889
|
+
return;
|
|
1890
|
+
}
|
|
1891
|
+
case "d": {
|
|
1892
|
+
const [, tag] = op;
|
|
1893
|
+
const view = this.views.get(tag);
|
|
1894
|
+
if (!view) return;
|
|
1895
|
+
this.destroyView(view);
|
|
1896
|
+
return;
|
|
1897
|
+
}
|
|
1898
|
+
case "f": {
|
|
1899
|
+
const [, tag, x, y, w, h] = op;
|
|
1900
|
+
const view = this.views.get(tag);
|
|
1901
|
+
if (!view) return;
|
|
1902
|
+
const finite = [x, y, w, h].every((v) => Number.isFinite(v));
|
|
1903
|
+
if (!finite) return;
|
|
1904
|
+
view.frame = { x, y, w, h };
|
|
1905
|
+
view.manager.frame(view, x, y, w, h);
|
|
1906
|
+
if (view.parent) this.dirtyContainers.add(view.parent);
|
|
1907
|
+
return;
|
|
1908
|
+
}
|
|
1909
|
+
default:
|
|
1910
|
+
console.warn("[pn] unknown op", op);
|
|
1911
|
+
}
|
|
1912
|
+
}
|
|
1913
|
+
|
|
1914
|
+
destroyView(view) {
|
|
1915
|
+
this.graph.forget(view.tag);
|
|
1916
|
+
this.animator.cancelForView(view);
|
|
1917
|
+
for (const child of [...view.children]) this.destroyView(child);
|
|
1918
|
+
if (view.parent) {
|
|
1919
|
+
const idx = view.parent.children.indexOf(view);
|
|
1920
|
+
if (idx >= 0) view.parent.children.splice(idx, 1);
|
|
1921
|
+
this.dirtyContainers.add(view.parent);
|
|
1922
|
+
view.parent = null;
|
|
1923
|
+
}
|
|
1924
|
+
disposeLayout(view);
|
|
1925
|
+
try {
|
|
1926
|
+
view.manager.destroy(view);
|
|
1927
|
+
} catch (err) {
|
|
1928
|
+
/* ignore */
|
|
1929
|
+
}
|
|
1930
|
+
view.el.remove();
|
|
1931
|
+
this.views.delete(view.tag);
|
|
1932
|
+
this.ctx.gesture(view.tag, "clear", {});
|
|
1933
|
+
}
|
|
1934
|
+
|
|
1935
|
+
// -- synchronous requests ---------------------------------------------
|
|
1936
|
+
|
|
1937
|
+
measure(tag, maxW, maxH) {
|
|
1938
|
+
const view = this.views.get(tag);
|
|
1939
|
+
if (!view) return [0, 0];
|
|
1940
|
+
try {
|
|
1941
|
+
const [w, h] = view.manager.measure(view, maxW, maxH);
|
|
1942
|
+
return [Number.isFinite(w) ? w : 0, Number.isFinite(h) ? h : 0];
|
|
1943
|
+
} catch (err) {
|
|
1944
|
+
console.error("[pn] measure failed", tag, err);
|
|
1945
|
+
return [0, 0];
|
|
1946
|
+
}
|
|
1947
|
+
}
|
|
1948
|
+
|
|
1949
|
+
command(tag, name, argsJson) {
|
|
1950
|
+
const view = this.views.get(tag);
|
|
1951
|
+
if (!view) return null;
|
|
1952
|
+
let args = {};
|
|
1953
|
+
try {
|
|
1954
|
+
args = argsJson ? JSON.parse(argsJson) || {} : {};
|
|
1955
|
+
} catch (err) {
|
|
1956
|
+
args = {};
|
|
1957
|
+
}
|
|
1958
|
+
const result = view.manager.command(view, name, args);
|
|
1959
|
+
return result === undefined ? null : result;
|
|
1960
|
+
}
|
|
1961
|
+
|
|
1962
|
+
animate(tag, requestJson) {
|
|
1963
|
+
const view = this.views.get(tag);
|
|
1964
|
+
let request;
|
|
1965
|
+
try {
|
|
1966
|
+
request = JSON.parse(requestJson);
|
|
1967
|
+
} catch (err) {
|
|
1968
|
+
return null;
|
|
1969
|
+
}
|
|
1970
|
+
if (!request || typeof request !== "object") return null;
|
|
1971
|
+
if (request.op === "graph") { this.graph.install(request.graph); return null; }
|
|
1972
|
+
if (request.op === "cancel") return this.animator.cancel(request.id);
|
|
1973
|
+
if (!view) return request.op === "start" ? { ok: false } : null;
|
|
1974
|
+
if (request.op === "set") {
|
|
1975
|
+
this.animator.set(view, request.prop, request.value);
|
|
1976
|
+
return null;
|
|
1977
|
+
}
|
|
1978
|
+
if (request.op === "start") {
|
|
1979
|
+
return { ok: this.animator.start(view, request.id, request.prop, request.spec) };
|
|
1980
|
+
}
|
|
1981
|
+
return null;
|
|
1982
|
+
}
|
|
1983
|
+
|
|
1984
|
+
/** Re-apply every color-bearing prop after a light/dark switch. */
|
|
1985
|
+
refreshColors() {
|
|
1986
|
+
for (const view of this.views.values()) {
|
|
1987
|
+
const changed = {};
|
|
1988
|
+
for (const key of Object.keys(view.props)) {
|
|
1989
|
+
if (isColorProp(key) || key === "spans" || key === "refresh_control") changed[key] = view.props[key];
|
|
1990
|
+
}
|
|
1991
|
+
if (Object.keys(changed).length) view.manager.update(view, changed);
|
|
1992
|
+
}
|
|
1993
|
+
}
|
|
1994
|
+
}
|