@ng-native/desktop 0.0.0 → 0.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +52 -0
- package/app.plugin.cjs +17 -0
- package/bin/app-config.mjs +168 -0
- package/bin/autolink.mjs +224 -0
- package/bin/cli.mjs +158 -0
- package/bin/host.mjs +427 -0
- package/bin/ng-native-desktop.mjs +4 -0
- package/bin/package.mjs +971 -0
- package/bin/plist.mjs +68 -0
- package/bin/prebuilt.mjs +328 -0
- package/bin/toolchain.mjs +192 -0
- package/native/CMakeLists.txt +277 -0
- package/native/appkit/CMakeLists.txt +130 -0
- package/native/appkit/address-search.h +26 -0
- package/native/appkit/address-search.mm +277 -0
- package/native/appkit/animation-frames.h +14 -0
- package/native/appkit/animation-frames.mm +106 -0
- package/native/appkit/app-info.h +12 -0
- package/native/appkit/app-info.mm +98 -0
- package/native/appkit/app-updater.mm +128 -0
- package/native/appkit/app-windows.h +81 -0
- package/native/appkit/app-windows.mm +318 -0
- package/native/appkit/appkit-backend.h +73 -0
- package/native/appkit/appkit-backend.mm +276 -0
- package/native/appkit/apple-authentication.h +19 -0
- package/native/appkit/apple-authentication.mm +248 -0
- package/native/appkit/apple-button-view.h +10 -0
- package/native/appkit/apple-button-view.mm +37 -0
- package/native/appkit/apple-id-button.h +16 -0
- package/native/appkit/apple-id-button.mm +50 -0
- package/native/appkit/audio.h +16 -0
- package/native/appkit/audio.mm +275 -0
- package/native/appkit/battery.h +13 -0
- package/native/appkit/battery.mm +92 -0
- package/native/appkit/bookmarks.h +17 -0
- package/native/appkit/bookmarks.mm +145 -0
- package/native/appkit/calendar.h +25 -0
- package/native/appkit/calendar.mm +660 -0
- package/native/appkit/camera-sheet.h +59 -0
- package/native/appkit/camera-sheet.mm +344 -0
- package/native/appkit/camera-view.h +15 -0
- package/native/appkit/camera-view.mm +134 -0
- package/native/appkit/camera.h +61 -0
- package/native/appkit/camera.mm +496 -0
- package/native/appkit/cg-canvas.h +24 -0
- package/native/appkit/cg-canvas.mm +663 -0
- package/native/appkit/component-view.h +17 -0
- package/native/appkit/crypto.h +19 -0
- package/native/appkit/crypto.mm +78 -0
- package/native/appkit/desktop-expo.h +29 -0
- package/native/appkit/desktop-expo.mm +385 -0
- package/native/appkit/expo-image-drawing.h +46 -0
- package/native/appkit/expo-image-drawing.mm +131 -0
- package/native/appkit/expo-image-view.h +15 -0
- package/native/appkit/expo-image-view.mm +182 -0
- package/native/appkit/expo-ui-renderer.h +68 -0
- package/native/appkit/expo-ui-renderer.mm +101 -0
- package/native/appkit/expo-ui-view.h +26 -0
- package/native/appkit/expo-ui-view.mm +134 -0
- package/native/appkit/expo-ui.swift +1284 -0
- package/native/appkit/file-system.h +16 -0
- package/native/appkit/file-system.mm +140 -0
- package/native/appkit/fonts.h +12 -0
- package/native/appkit/fonts.mm +48 -0
- package/native/appkit/geocoder.h +19 -0
- package/native/appkit/geocoder.mm +101 -0
- package/native/appkit/glass-effect.h +22 -0
- package/native/appkit/glass-effect.mm +63 -0
- package/native/appkit/glass-view.h +8 -0
- package/native/appkit/glass-view.mm +65 -0
- package/native/appkit/header-toolbar.h +60 -0
- package/native/appkit/header-toolbar.mm +632 -0
- package/native/appkit/host-view.h +54 -0
- package/native/appkit/host-view.mm +1228 -0
- package/native/appkit/image-manipulator.h +14 -0
- package/native/appkit/image-manipulator.mm +191 -0
- package/native/appkit/image-request.h +22 -0
- package/native/appkit/image-request.mm +62 -0
- package/native/appkit/image-view.h +8 -0
- package/native/appkit/image-view.mm +142 -0
- package/native/appkit/input-replay.h +25 -0
- package/native/appkit/input-replay.mm +418 -0
- package/native/appkit/language-model.h +14 -0
- package/native/appkit/language-model.mm +99 -0
- package/native/appkit/language-model.swift +472 -0
- package/native/appkit/local-authentication.h +15 -0
- package/native/appkit/local-authentication.mm +133 -0
- package/native/appkit/location.h +16 -0
- package/native/appkit/location.mm +214 -0
- package/native/appkit/main.mm +1475 -0
- package/native/appkit/map-view.h +15 -0
- package/native/appkit/map-view.mm +109 -0
- package/native/appkit/maps.h +35 -0
- package/native/appkit/maps.mm +343 -0
- package/native/appkit/menu-bar.h +22 -0
- package/native/appkit/menu-bar.mm +208 -0
- package/native/appkit/modal-focus.h +16 -0
- package/native/appkit/modal-focus.mm +26 -0
- package/native/appkit/modal-host-view.h +79 -0
- package/native/appkit/modal-host-view.mm +442 -0
- package/native/appkit/native-controls.h +22 -0
- package/native/appkit/native-controls.mm +431 -0
- package/native/appkit/network-state.h +12 -0
- package/native/appkit/network-state.mm +64 -0
- package/native/appkit/network.h +14 -0
- package/native/appkit/network.mm +396 -0
- package/native/appkit/notifications.h +19 -0
- package/native/appkit/notifications.mm +309 -0
- package/native/appkit/photo-library.h +33 -0
- package/native/appkit/photo-library.mm +548 -0
- package/native/appkit/pointer-buttons.h +32 -0
- package/native/appkit/presentation-label.h +15 -0
- package/native/appkit/presentation-label.mm +12 -0
- package/native/appkit/presented-screen.h +19 -0
- package/native/appkit/presented-screen.mm +181 -0
- package/native/appkit/printing.h +42 -0
- package/native/appkit/printing.mm +393 -0
- package/native/appkit/push.h +19 -0
- package/native/appkit/push.mm +81 -0
- package/native/appkit/red-box.h +26 -0
- package/native/appkit/red-box.mm +387 -0
- package/native/appkit/screen-capture.h +21 -0
- package/native/appkit/screen-capture.mm +92 -0
- package/native/appkit/scroll-view.h +13 -0
- package/native/appkit/scroll-view.mm +251 -0
- package/native/appkit/scrollers.h +25 -0
- package/native/appkit/scrollers.mm +43 -0
- package/native/appkit/search-field.h +34 -0
- package/native/appkit/search-field.mm +291 -0
- package/native/appkit/search-toolbar-item.h +19 -0
- package/native/appkit/search-toolbar-item.mm +269 -0
- package/native/appkit/share-picker.h +34 -0
- package/native/appkit/share-picker.mm +121 -0
- package/native/appkit/split-view.h +77 -0
- package/native/appkit/split-view.mm +1206 -0
- package/native/appkit/store-review.h +13 -0
- package/native/appkit/store-review.mm +28 -0
- package/native/appkit/surface-view.h +45 -0
- package/native/appkit/surface-view.mm +562 -0
- package/native/appkit/svg-view.h +18 -0
- package/native/appkit/svg-view.mm +103 -0
- package/native/appkit/symbol-drawing.h +24 -0
- package/native/appkit/symbol-drawing.mm +117 -0
- package/native/appkit/symbol-view.h +8 -0
- package/native/appkit/symbol-view.mm +33 -0
- package/native/appkit/system-access.h +34 -0
- package/native/appkit/system-access.mm +210 -0
- package/native/appkit/system.h +24 -0
- package/native/appkit/system.mm +403 -0
- package/native/appkit/tab-walk.h +31 -0
- package/native/appkit/tab-walk.mm +64 -0
- package/native/appkit/test-launch.h +36 -0
- package/native/appkit/test-launch.mm +115 -0
- package/native/appkit/text-input-field.h +81 -0
- package/native/appkit/text-input-field.mm +525 -0
- package/native/appkit/text-layout.h +58 -0
- package/native/appkit/text-layout.mm +485 -0
- package/native/appkit/text-recognition.h +13 -0
- package/native/appkit/text-recognition.mm +102 -0
- package/native/appkit/tracking.h +13 -0
- package/native/appkit/tracking.mm +51 -0
- package/native/appkit/tray-and-dock.h +45 -0
- package/native/appkit/tray-and-dock.mm +130 -0
- package/native/appkit/undo.h +23 -0
- package/native/appkit/undo.mm +125 -0
- package/native/appkit/updates.h +17 -0
- package/native/appkit/updates.mm +71 -0
- package/native/appkit/video-view.h +10 -0
- package/native/appkit/video-view.mm +42 -0
- package/native/appkit/video.h +38 -0
- package/native/appkit/video.mm +404 -0
- package/native/appkit/web-browser.h +12 -0
- package/native/appkit/web-browser.mm +97 -0
- package/native/appkit/web-view-component.h +10 -0
- package/native/appkit/web-view-component.mm +62 -0
- package/native/appkit/web-view.h +31 -0
- package/native/appkit/web-view.mm +401 -0
- package/native/cmake/libraries/react-native-reanimated.cmake +45 -0
- package/native/cmake/libraries/react-native-worklets.cmake +46 -0
- package/native/cmake/libraries.cmake +109 -0
- package/native/cmake/linked-modules.cmake +112 -0
- package/native/cmake/react-native.cmake +175 -0
- package/native/cmake/runtime-dependencies.cmake +34 -0
- package/native/cmake/swift.cmake +43 -0
- package/native/cmake/third-party.cmake +74 -0
- package/native/core/include/ngn/absent-views.h +27 -0
- package/native/core/include/ngn/accessibility.h +140 -0
- package/native/core/include/ngn/address-search.h +69 -0
- package/native/core/include/ngn/animation-frames.h +39 -0
- package/native/core/include/ngn/app-info.h +52 -0
- package/native/core/include/ngn/app-menus.h +151 -0
- package/native/core/include/ngn/app-windows.h +181 -0
- package/native/core/include/ngn/apple-authentication.h +116 -0
- package/native/core/include/ngn/asset.h +28 -0
- package/native/core/include/ngn/audio.h +125 -0
- package/native/core/include/ngn/back-swipe.h +121 -0
- package/native/core/include/ngn/battery.h +48 -0
- package/native/core/include/ngn/bytes.h +59 -0
- package/native/core/include/ngn/calendar.h +180 -0
- package/native/core/include/ngn/camera.h +222 -0
- package/native/core/include/ngn/control-sizes.h +111 -0
- package/native/core/include/ngn/core-modules.h +108 -0
- package/native/core/include/ngn/crypto.h +38 -0
- package/native/core/include/ngn/default-menu.h +91 -0
- package/native/core/include/ngn/desktop-expo.h +193 -0
- package/native/core/include/ngn/desktop-modal.h +109 -0
- package/native/core/include/ngn/desktop-props.h +75 -0
- package/native/core/include/ngn/desktop-view-props.h +110 -0
- package/native/core/include/ngn/dev-server.h +33 -0
- package/native/core/include/ngn/dom-web-view.h +53 -0
- package/native/core/include/ngn/download.h +24 -0
- package/native/core/include/ngn/expo-image.h +192 -0
- package/native/core/include/ngn/expo-ui.h +133 -0
- package/native/core/include/ngn/file-system.h +274 -0
- package/native/core/include/ngn/focus-order.h +63 -0
- package/native/core/include/ngn/fonts.h +64 -0
- package/native/core/include/ngn/gestures.h +305 -0
- package/native/core/include/ngn/glass.h +67 -0
- package/native/core/include/ngn/header-bar.h +112 -0
- package/native/core/include/ngn/host-state.h +243 -0
- package/native/core/include/ngn/image-manipulator.h +70 -0
- package/native/core/include/ngn/input-dispatcher.h +211 -0
- package/native/core/include/ngn/input-script.h +56 -0
- package/native/core/include/ngn/input.h +112 -0
- package/native/core/include/ngn/key-value-store.h +41 -0
- package/native/core/include/ngn/language-model.h +69 -0
- package/native/core/include/ngn/launch-frame.h +47 -0
- package/native/core/include/ngn/launch-settings.h +98 -0
- package/native/core/include/ngn/layout-animations.h +24 -0
- package/native/core/include/ngn/library-components.h +13 -0
- package/native/core/include/ngn/library-glue.h +53 -0
- package/native/core/include/ngn/live-regions.h +54 -0
- package/native/core/include/ngn/local-authentication.h +74 -0
- package/native/core/include/ngn/location.h +89 -0
- package/native/core/include/ngn/maps.h +226 -0
- package/native/core/include/ngn/module-registry.h +51 -0
- package/native/core/include/ngn/mounting-backend.h +96 -0
- package/native/core/include/ngn/mounting-manager.h +155 -0
- package/native/core/include/ngn/native-controls.h +161 -0
- package/native/core/include/ngn/native-module.h +109 -0
- package/native/core/include/ngn/network-state.h +44 -0
- package/native/core/include/ngn/network.h +100 -0
- package/native/core/include/ngn/notifications.h +185 -0
- package/native/core/include/ngn/photo-library.h +134 -0
- package/native/core/include/ngn/printing.h +69 -0
- package/native/core/include/ngn/processes.h +114 -0
- package/native/core/include/ngn/red-box.h +119 -0
- package/native/core/include/ngn/reload-thread.h +258 -0
- package/native/core/include/ngn/runtime.h +163 -0
- package/native/core/include/ngn/safe-areas.h +82 -0
- package/native/core/include/ngn/screen-capture.h +35 -0
- package/native/core/include/ngn/screen-presentation.h +85 -0
- package/native/core/include/ngn/screen-stacks.h +80 -0
- package/native/core/include/ngn/scrollers.h +106 -0
- package/native/core/include/ngn/sharing.h +39 -0
- package/native/core/include/ngn/spawn-rules.h +78 -0
- package/native/core/include/ngn/splash-screen.h +41 -0
- package/native/core/include/ngn/split-view.h +270 -0
- package/native/core/include/ngn/sqlite.h +38 -0
- package/native/core/include/ngn/store-review.h +26 -0
- package/native/core/include/ngn/surface-book.h +101 -0
- package/native/core/include/ngn/surface-metrics.h +51 -0
- package/native/core/include/ngn/svg.h +434 -0
- package/native/core/include/ngn/symbol.h +90 -0
- package/native/core/include/ngn/system.h +102 -0
- package/native/core/include/ngn/tabs-host.h +171 -0
- package/native/core/include/ngn/text-input.h +134 -0
- package/native/core/include/ngn/text-measurer.h +38 -0
- package/native/core/include/ngn/text-recognition.h +55 -0
- package/native/core/include/ngn/tracking.h +34 -0
- package/native/core/include/ngn/tray-and-dock.h +107 -0
- package/native/core/include/ngn/undo.h +37 -0
- package/native/core/include/ngn/updates.h +253 -0
- package/native/core/include/ngn/video.h +126 -0
- package/native/core/include/ngn/view-box.h +126 -0
- package/native/core/include/ngn/view-transform.h +26 -0
- package/native/core/include/ngn/view-tree.h +85 -0
- package/native/core/include/ngn/web-browser.h +45 -0
- package/native/core/include/ngn/web-view.h +137 -0
- package/native/core/include/ngn/worklet-host.h +98 -0
- package/native/core/src/absent-views.cpp +41 -0
- package/native/core/src/accessibility.cpp +374 -0
- package/native/core/src/animation-frames.cpp +49 -0
- package/native/core/src/app-menus.cpp +359 -0
- package/native/core/src/app-windows.cpp +444 -0
- package/native/core/src/back-swipe.cpp +98 -0
- package/native/core/src/bytes.cpp +158 -0
- package/native/core/src/control-sizes.cpp +232 -0
- package/native/core/src/default-menu.cpp +96 -0
- package/native/core/src/desktop-modal.cpp +162 -0
- package/native/core/src/desktop-view-props.cpp +80 -0
- package/native/core/src/dev-server-helper.cpp +152 -0
- package/native/core/src/dev-server.cpp +103 -0
- package/native/core/src/dom-web-view.cpp +45 -0
- package/native/core/src/download.cpp +53 -0
- package/native/core/src/expo-image.cpp +548 -0
- package/native/core/src/expo-ui.cpp +203 -0
- package/native/core/src/focus-order.cpp +441 -0
- package/native/core/src/gestures.cpp +1806 -0
- package/native/core/src/glass.cpp +49 -0
- package/native/core/src/header-bar.cpp +104 -0
- package/native/core/src/host-services.cpp +50 -0
- package/native/core/src/host-state.cpp +61 -0
- package/native/core/src/input-dispatcher.cpp +727 -0
- package/native/core/src/input-script.cpp +123 -0
- package/native/core/src/key-value-store.cpp +169 -0
- package/native/core/src/launch-settings.cpp +148 -0
- package/native/core/src/layout-animations.cpp +62 -0
- package/native/core/src/libraries/RNCWebViewSpec.cpp +80 -0
- package/native/core/src/libraries/react-native-reanimated.cpp +216 -0
- package/native/core/src/libraries/react-native-worklets.cpp +192 -0
- package/native/core/src/libraries/rnscreens.cpp +125 -0
- package/native/core/src/libraries/rnsvg.cpp +358 -0
- package/native/core/src/libraries/safeareacontext.cpp +70 -0
- package/native/core/src/libraries/worklets-idle-frames.js +70 -0
- package/native/core/src/library-glue.cpp +35 -0
- package/native/core/src/live-regions.cpp +122 -0
- package/native/core/src/module-registry.cpp +50 -0
- package/native/core/src/modules/accessibility-manager.cpp +98 -0
- package/native/core/src/modules/address-search.cpp +219 -0
- package/native/core/src/modules/alert-manager.cpp +140 -0
- package/native/core/src/modules/app-info.cpp +74 -0
- package/native/core/src/modules/app-modules.cpp +412 -0
- package/native/core/src/modules/apple-authentication.cpp +188 -0
- package/native/core/src/modules/asset.cpp +111 -0
- package/native/core/src/modules/async-storage.cpp +192 -0
- package/native/core/src/modules/audio.cpp +541 -0
- package/native/core/src/modules/battery.cpp +88 -0
- package/native/core/src/modules/calendar.cpp +457 -0
- package/native/core/src/modules/camera.cpp +401 -0
- package/native/core/src/modules/core-modules.cpp +62 -0
- package/native/core/src/modules/crypto.cpp +117 -0
- package/native/core/src/modules/desktop-expo.cpp +527 -0
- package/native/core/src/modules/file-system.cpp +941 -0
- package/native/core/src/modules/fonts.cpp +163 -0
- package/native/core/src/modules/image-loader.cpp +105 -0
- package/native/core/src/modules/image-manipulator.cpp +305 -0
- package/native/core/src/modules/language-model.cpp +195 -0
- package/native/core/src/modules/local-authentication.cpp +140 -0
- package/native/core/src/modules/location.cpp +186 -0
- package/native/core/src/modules/maps.cpp +500 -0
- package/native/core/src/modules/network-state.cpp +72 -0
- package/native/core/src/modules/networking.cpp +387 -0
- package/native/core/src/modules/notifications.cpp +549 -0
- package/native/core/src/modules/photo-library.cpp +385 -0
- package/native/core/src/modules/printing.cpp +201 -0
- package/native/core/src/modules/screen-capture.cpp +71 -0
- package/native/core/src/modules/sharing.cpp +59 -0
- package/native/core/src/modules/splash-screen.cpp +70 -0
- package/native/core/src/modules/sqlite.cpp +421 -0
- package/native/core/src/modules/store-review.cpp +23 -0
- package/native/core/src/modules/text-recognition.cpp +107 -0
- package/native/core/src/modules/tracking.cpp +46 -0
- package/native/core/src/modules/undo.cpp +59 -0
- package/native/core/src/modules/video.cpp +366 -0
- package/native/core/src/modules/web-browser.cpp +100 -0
- package/native/core/src/modules/web-socket.cpp +266 -0
- package/native/core/src/mounting-manager.cpp +384 -0
- package/native/core/src/native-controls.cpp +129 -0
- package/native/core/src/native-module.cpp +250 -0
- package/native/core/src/network.cpp +219 -0
- package/native/core/src/posix-launcher.cpp +366 -0
- package/native/core/src/processes.cpp +324 -0
- package/native/core/src/red-box-errors.js +83 -0
- package/native/core/src/red-box.cpp +306 -0
- package/native/core/src/runtime.cpp +420 -0
- package/native/core/src/safe-areas.cpp +137 -0
- package/native/core/src/screen-presentation.cpp +61 -0
- package/native/core/src/screen-stacks.cpp +254 -0
- package/native/core/src/scrollers.cpp +181 -0
- package/native/core/src/spawn-rules.cpp +292 -0
- package/native/core/src/split-view.cpp +343 -0
- package/native/core/src/svg.cpp +2190 -0
- package/native/core/src/symbol.cpp +94 -0
- package/native/core/src/tabs-host.cpp +234 -0
- package/native/core/src/text-input.cpp +139 -0
- package/native/core/src/text-layout-manager.cpp +63 -0
- package/native/core/src/tray-and-dock.cpp +154 -0
- package/native/core/src/updates.cpp +965 -0
- package/native/core/src/view-box.cpp +788 -0
- package/native/core/src/view-transform.cpp +45 -0
- package/native/core/src/view-tree.cpp +234 -0
- package/native/core/src/web-view.cpp +143 -0
- package/native/core/src/worklet-host.cpp +10 -0
- package/native/scripts/build-hermes.sh +44 -0
- package/native/scripts/build.sh +175 -0
- package/native/scripts/cache-dir.sh +18 -0
- package/native/scripts/codegen-library.sh +193 -0
- package/native/scripts/compiler-launcher.sh +17 -0
- package/native/scripts/fetch.sh +174 -0
- package/native/scripts/hermes-built.sh +10 -0
- package/native/scripts/host-dir.sh +16 -0
- package/native/scripts/launch-probe.sh +60 -0
- package/native/scripts/macos-target.sh +8 -0
- package/native/scripts/make-prebuilt.mjs +360 -0
- package/native/scripts/prebuilt-host-cache.mjs +158 -0
- package/native/shim/openssl/sha.h +22 -0
- package/native/shim/view-platform/react/renderer/components/view/HostPlatformViewTraitsInitializer.h +37 -0
- package/package.json +73 -1
- package/prebuilt.json +33 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
// The surfaces a runtime has, kept apart from the runtime so a reload never makes the UI thread
|
|
2
|
+
// wait. While a reload runs, a surface started, stopped or resized is only written down here, and
|
|
3
|
+
// the reload brings the new runtime to match the book, step by step, before it ends. Not locked:
|
|
4
|
+
// the runtime holds its own lock around each call. Header-only, and toolkit-free.
|
|
5
|
+
#pragma once
|
|
6
|
+
|
|
7
|
+
#include <react/renderer/core/ReactPrimitives.h>
|
|
8
|
+
|
|
9
|
+
#include <map>
|
|
10
|
+
#include <optional>
|
|
11
|
+
#include <set>
|
|
12
|
+
#include <vector>
|
|
13
|
+
|
|
14
|
+
namespace ngn {
|
|
15
|
+
|
|
16
|
+
template <class Surface>
|
|
17
|
+
class SurfaceBook {
|
|
18
|
+
public:
|
|
19
|
+
// Each answers whether the caller should apply the change to the runtime now: not during a
|
|
20
|
+
// reload, which applies it.
|
|
21
|
+
bool start(facebook::react::SurfaceId id, Surface surface) {
|
|
22
|
+
surfaces_[id] = std::move(surface);
|
|
23
|
+
if (reloading_) {
|
|
24
|
+
changed_.insert(id);
|
|
25
|
+
}
|
|
26
|
+
return !reloading_;
|
|
27
|
+
}
|
|
28
|
+
bool stop(facebook::react::SurfaceId id) {
|
|
29
|
+
return surfaces_.erase(id) != 0 && !reloading_;
|
|
30
|
+
}
|
|
31
|
+
// Changes a surface the book has with `change`.
|
|
32
|
+
template <class Change>
|
|
33
|
+
bool update(facebook::react::SurfaceId id, Change change) {
|
|
34
|
+
auto it = surfaces_.find(id);
|
|
35
|
+
if (it == surfaces_.end()) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
change(it->second);
|
|
39
|
+
if (reloading_) {
|
|
40
|
+
changed_.insert(id);
|
|
41
|
+
}
|
|
42
|
+
return !reloading_;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
bool reloading() const {
|
|
46
|
+
return reloading_;
|
|
47
|
+
}
|
|
48
|
+
// False when a reload is running already.
|
|
49
|
+
bool beginReload() {
|
|
50
|
+
if (reloading_) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
reloading_ = true;
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
struct Step {
|
|
58
|
+
std::vector<std::pair<facebook::react::SurfaceId, Surface>> start;
|
|
59
|
+
std::vector<facebook::react::SurfaceId> stop;
|
|
60
|
+
// Running surfaces the book changed since the reload started them, to apply as they are now.
|
|
61
|
+
std::vector<std::pair<facebook::react::SurfaceId, Surface>> update;
|
|
62
|
+
};
|
|
63
|
+
// What the reloaded runtime, running `started`, must start, stop and update to match the book.
|
|
64
|
+
// Nothing when it matches, which ends the reload: from then on changes are applied by their
|
|
65
|
+
// callers.
|
|
66
|
+
std::optional<Step> settle(const std::set<facebook::react::SurfaceId> &started) {
|
|
67
|
+
Step step;
|
|
68
|
+
for (const auto &[id, surface] : surfaces_) {
|
|
69
|
+
if (!started.contains(id)) {
|
|
70
|
+
step.start.emplace_back(id, surface);
|
|
71
|
+
} else if (changed_.contains(id)) {
|
|
72
|
+
step.update.emplace_back(id, surface);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
for (auto id : started) {
|
|
76
|
+
if (!surfaces_.contains(id)) {
|
|
77
|
+
step.stop.push_back(id);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
// A start or an update carries every change so far.
|
|
81
|
+
changed_.clear();
|
|
82
|
+
if (step.start.empty() && step.stop.empty() && step.update.empty()) {
|
|
83
|
+
reloading_ = false;
|
|
84
|
+
return std::nullopt;
|
|
85
|
+
}
|
|
86
|
+
return step;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Every surface, for a reload with no runtime to restart them on.
|
|
90
|
+
const std::map<facebook::react::SurfaceId, Surface> &surfaces() const {
|
|
91
|
+
return surfaces_;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
private:
|
|
95
|
+
std::map<facebook::react::SurfaceId, Surface> surfaces_;
|
|
96
|
+
// Surfaces started or changed during the reload, since the last step.
|
|
97
|
+
std::set<facebook::react::SurfaceId> changed_;
|
|
98
|
+
bool reloading_{false};
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
} // namespace ngn
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// What a surface is laid out at: its size, scale, text size and direction. Header-only, and
|
|
2
|
+
// toolkit-free.
|
|
3
|
+
#pragma once
|
|
4
|
+
|
|
5
|
+
#include <react/renderer/core/LayoutConstraints.h>
|
|
6
|
+
#include <react/renderer/graphics/Size.h>
|
|
7
|
+
|
|
8
|
+
#include <atomic>
|
|
9
|
+
#include <functional>
|
|
10
|
+
#include <utility>
|
|
11
|
+
|
|
12
|
+
namespace ngn {
|
|
13
|
+
|
|
14
|
+
struct SurfaceMetrics {
|
|
15
|
+
facebook::react::Size size{};
|
|
16
|
+
// Device pixels per point.
|
|
17
|
+
float pointScale{2};
|
|
18
|
+
// The text size multiplier.
|
|
19
|
+
float fontScale{1};
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// The surface's root constraints: its size, and the direction its layout starts from, which React
|
|
23
|
+
// Native's iOS surfaces take from I18nManager.
|
|
24
|
+
inline facebook::react::LayoutConstraints surfaceConstraints(const SurfaceMetrics &metrics, bool rightToLeft) {
|
|
25
|
+
using facebook::react::LayoutDirection;
|
|
26
|
+
return {
|
|
27
|
+
.minimumSize = metrics.size,
|
|
28
|
+
.maximumSize = metrics.size,
|
|
29
|
+
.layoutDirection = rightToLeft ? LayoutDirection::RightToLeft : LayoutDirection::LeftToRight,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// The direction a runtime's surfaces lay out from: what `read` answers as each JavaScript instance
|
|
34
|
+
// starts (the first load and each reload), kept for that instance's run as I18nManager's constants
|
|
35
|
+
// are, so a surface started or resized meanwhile agrees with what JavaScript reads.
|
|
36
|
+
class SurfaceDirection {
|
|
37
|
+
public:
|
|
38
|
+
explicit SurfaceDirection(std::function<bool()> read) : read_(std::move(read)) {}
|
|
39
|
+
void instanceStarted() {
|
|
40
|
+
rightToLeft_ = read_ && read_();
|
|
41
|
+
}
|
|
42
|
+
bool rightToLeft() const {
|
|
43
|
+
return rightToLeft_;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
private:
|
|
47
|
+
std::function<bool()> read_;
|
|
48
|
+
std::atomic<bool> rightToLeft_{false};
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
} // namespace ngn
|
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
// SVG as react-native-svg commits it: its host components' props read into a toolkit-free model,
|
|
2
|
+
// the path and paint model, and the drawing of a document onto a narrow canvas.
|
|
3
|
+
//
|
|
4
|
+
// react-native-svg mounts one view per element (RNSVGSvgView with RNSVGGroup, RNSVGPath and the
|
|
5
|
+
// rest under it). The core keeps each svg's elements as a document (SvgDrawings, below), and the
|
|
6
|
+
// backend's view for the RNSVGSvgView draws it by calling drawSvg with an SvgCanvas over its own
|
|
7
|
+
// graphics context. Everything SVG means (inheritance through `propList`, `currentColor`,
|
|
8
|
+
// lengths and percentages, the viewBox, path data and arcs, gradients and their units, clip
|
|
9
|
+
// paths, masks, `use` and `symbol`, markers, patterns and filters, text anchors and text along a
|
|
10
|
+
// path) is decided here; the canvas only measures and draws runs of text, draws paths, gradients
|
|
11
|
+
// and images, tiles a pattern's tile, and runs a filter's steps over pixels with runSvgFilter.
|
|
12
|
+
#pragma once
|
|
13
|
+
|
|
14
|
+
#include "ngn/view-tree.h"
|
|
15
|
+
|
|
16
|
+
#include <react/renderer/core/Props.h>
|
|
17
|
+
|
|
18
|
+
#include <folly/dynamic.h>
|
|
19
|
+
|
|
20
|
+
#include <array>
|
|
21
|
+
#include <cstdint>
|
|
22
|
+
#include <functional>
|
|
23
|
+
#include <map>
|
|
24
|
+
#include <memory>
|
|
25
|
+
#include <optional>
|
|
26
|
+
#include <string>
|
|
27
|
+
#include <unordered_map>
|
|
28
|
+
#include <unordered_set>
|
|
29
|
+
#include <vector>
|
|
30
|
+
|
|
31
|
+
namespace ngn {
|
|
32
|
+
|
|
33
|
+
// An affine transform, as SVG's matrix(a b c d e f): x' = a*x + c*y + e, y' = b*x + d*y + f.
|
|
34
|
+
struct SvgMatrix {
|
|
35
|
+
double a{1}, b{0}, c{0}, d{1}, e{0}, f{0};
|
|
36
|
+
|
|
37
|
+
static SvgMatrix translate(double x, double y) { return {1, 0, 0, 1, x, y}; }
|
|
38
|
+
static SvgMatrix scale(double x, double y) { return {x, 0, 0, y, 0, 0}; }
|
|
39
|
+
// This transform applied after `inner`: (this * inner)(p) == this(inner(p)).
|
|
40
|
+
SvgMatrix operator*(const SvgMatrix &inner) const;
|
|
41
|
+
std::pair<double, double> apply(double x, double y) const;
|
|
42
|
+
bool operator==(const SvgMatrix &) const = default;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
struct SvgRect {
|
|
46
|
+
double x{0}, y{0}, width{0}, height{0};
|
|
47
|
+
bool operator==(const SvgRect &) const = default;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// A path as moves, lines, cubic curves and closes: quadratics, smooth curves and arcs are
|
|
51
|
+
// converted as they are parsed.
|
|
52
|
+
struct SvgPath {
|
|
53
|
+
enum class Op { Move, Line, Cubic, Close };
|
|
54
|
+
struct Segment {
|
|
55
|
+
Op op;
|
|
56
|
+
// One point for Move and Line, three for Cubic (two controls, then the end), none for Close.
|
|
57
|
+
double points[6]{};
|
|
58
|
+
bool operator==(const Segment &) const = default;
|
|
59
|
+
};
|
|
60
|
+
std::vector<Segment> segments;
|
|
61
|
+
|
|
62
|
+
void moveTo(double x, double y);
|
|
63
|
+
void lineTo(double x, double y);
|
|
64
|
+
void cubicTo(double x1, double y1, double x2, double y2, double x, double y);
|
|
65
|
+
void close();
|
|
66
|
+
void append(const SvgPath &other, const SvgMatrix &transform);
|
|
67
|
+
bool empty() const { return segments.empty(); }
|
|
68
|
+
// The control-point bounds, which contain the curve; nothing for a path with no points.
|
|
69
|
+
std::optional<SvgRect> bounds() const;
|
|
70
|
+
bool operator==(const SvgPath &) const = default;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
// SVG path data (`d`). Parsing stops at the first error, keeping what came before it, as browsers
|
|
74
|
+
// draw a path up to its first bad command.
|
|
75
|
+
SvgPath parseSvgPath(const std::string &d);
|
|
76
|
+
|
|
77
|
+
// A length as react-native-svg sends one: a number in user units, or a string with a unit.
|
|
78
|
+
struct SvgLength {
|
|
79
|
+
enum class Unit { User, Percent, Em };
|
|
80
|
+
double value{0};
|
|
81
|
+
Unit unit{Unit::User};
|
|
82
|
+
bool set{false};
|
|
83
|
+
bool operator==(const SvgLength &) const = default;
|
|
84
|
+
};
|
|
85
|
+
SvgLength svgLength(const folly::dynamic &value);
|
|
86
|
+
std::vector<SvgLength> svgLengths(const folly::dynamic &value);
|
|
87
|
+
|
|
88
|
+
// A fill or stroke: react-native-svg's brush ({type: 0, payload: color}, {type: 1, brushRef},
|
|
89
|
+
// {type: 2} for currentColor), or nothing set.
|
|
90
|
+
struct SvgBrush {
|
|
91
|
+
enum class Type { Unset, None, Color, CurrentColor, Ref };
|
|
92
|
+
Type type{Type::Unset};
|
|
93
|
+
uint32_t argb{0xff000000};
|
|
94
|
+
std::string ref;
|
|
95
|
+
bool operator==(const SvgBrush &) const = default;
|
|
96
|
+
};
|
|
97
|
+
SvgBrush svgBrush(const folly::dynamic &value);
|
|
98
|
+
|
|
99
|
+
enum class SvgKind {
|
|
100
|
+
Svg,
|
|
101
|
+
Group,
|
|
102
|
+
Path,
|
|
103
|
+
Rect,
|
|
104
|
+
Circle,
|
|
105
|
+
Ellipse,
|
|
106
|
+
Line,
|
|
107
|
+
Use,
|
|
108
|
+
Defs,
|
|
109
|
+
LinearGradient,
|
|
110
|
+
RadialGradient,
|
|
111
|
+
ClipPath,
|
|
112
|
+
Mask,
|
|
113
|
+
Symbol,
|
|
114
|
+
Image,
|
|
115
|
+
// A box of native views: what is in it is views, not svg elements, which the canvas draws.
|
|
116
|
+
ForeignObject,
|
|
117
|
+
Text,
|
|
118
|
+
TSpan,
|
|
119
|
+
TextPath,
|
|
120
|
+
Marker,
|
|
121
|
+
Pattern,
|
|
122
|
+
Filter,
|
|
123
|
+
// A filter's steps.
|
|
124
|
+
FeGaussianBlur,
|
|
125
|
+
FeOffset,
|
|
126
|
+
FeColorMatrix,
|
|
127
|
+
FeFlood,
|
|
128
|
+
FeComposite,
|
|
129
|
+
FeMerge,
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
// One element's props, from its host component's.
|
|
133
|
+
struct SvgElement {
|
|
134
|
+
SvgKind kind{SvgKind::Group};
|
|
135
|
+
std::string name;
|
|
136
|
+
|
|
137
|
+
// Presentation. An attribute in `propList` is the element's own; any other is inherited from
|
|
138
|
+
// its parent where the parent has it, as react-native-svg merges them.
|
|
139
|
+
std::vector<std::string> propList;
|
|
140
|
+
SvgBrush fill;
|
|
141
|
+
double fillOpacity{1};
|
|
142
|
+
int fillRule{1}; // 0 evenodd, 1 nonzero
|
|
143
|
+
SvgBrush stroke;
|
|
144
|
+
double strokeOpacity{1};
|
|
145
|
+
SvgLength strokeWidth;
|
|
146
|
+
int strokeLinecap{0}; // butt, round, square
|
|
147
|
+
int strokeLinejoin{0}; // miter, round, bevel
|
|
148
|
+
std::vector<SvgLength> strokeDasharray;
|
|
149
|
+
double strokeDashoffset{0};
|
|
150
|
+
double strokeMiterlimit{4};
|
|
151
|
+
// `currentColor` for this element and what it contains, when it sets one.
|
|
152
|
+
std::optional<uint32_t> color;
|
|
153
|
+
|
|
154
|
+
double opacity{1};
|
|
155
|
+
std::optional<SvgMatrix> matrix;
|
|
156
|
+
std::string clipPath;
|
|
157
|
+
int clipRule{1};
|
|
158
|
+
std::string mask;
|
|
159
|
+
// The filter the element draws through, and the markers a shape draws at its vertices.
|
|
160
|
+
std::string filter;
|
|
161
|
+
std::string markerStart, markerMid, markerEnd;
|
|
162
|
+
bool hidden{false}; // display: none
|
|
163
|
+
|
|
164
|
+
// Geometry and positions by attribute name: x, y, width, height, rx, ry, cx, cy, r, x1, y1, x2,
|
|
165
|
+
// y2, fx, fy; a marker's refX, refY, markerWidth and markerHeight; an offset's dx and dy.
|
|
166
|
+
std::map<std::string, SvgLength> lengths;
|
|
167
|
+
std::string d;
|
|
168
|
+
std::string href;
|
|
169
|
+
|
|
170
|
+
// A gradient's stops (offset, ARGB), and its units (0 objectBoundingBox, 1 userSpaceOnUse); a
|
|
171
|
+
// mask's, a pattern's and a filter's units and content units the same way (a filter's content
|
|
172
|
+
// units are its primitiveUnits), and a mask's type (0 luminance, 1 alpha).
|
|
173
|
+
std::vector<std::pair<double, uint32_t>> stops;
|
|
174
|
+
int units{0};
|
|
175
|
+
int contentUnits{1};
|
|
176
|
+
int maskType{0};
|
|
177
|
+
// A gradient's gradientTransform or a pattern's patternTransform.
|
|
178
|
+
std::optional<SvgMatrix> gradientTransform;
|
|
179
|
+
|
|
180
|
+
// A marker's markerUnits ("strokeWidth", the default, or "userSpaceOnUse") and orient ("auto",
|
|
181
|
+
// "auto-start-reverse" or an angle in degrees).
|
|
182
|
+
std::string markerUnits;
|
|
183
|
+
std::string orient;
|
|
184
|
+
|
|
185
|
+
// A filter step: its inputs (SourceGraphic, SourceAlpha or an earlier step's result) and its own
|
|
186
|
+
// result's name; a colour matrix's type (0 matrix, 1 saturate, 2 hueRotate, 3 luminanceToAlpha)
|
|
187
|
+
// and values; a composite's operator (0 over, 1 in, 2 out, 3 atop, 4 xor, 5 arithmetic) and k1
|
|
188
|
+
// to k4; a blur's deviations; a flood's colour; a merge's inputs.
|
|
189
|
+
std::string in1, in2, result;
|
|
190
|
+
int op{0};
|
|
191
|
+
std::vector<double> values;
|
|
192
|
+
std::array<double, 4> k{};
|
|
193
|
+
double stdDeviationX{0}, stdDeviationY{0};
|
|
194
|
+
SvgBrush flood{.type = SvgBrush::Type::Color, .argb = 0xff000000};
|
|
195
|
+
double floodOpacity{1};
|
|
196
|
+
std::vector<std::string> nodes;
|
|
197
|
+
|
|
198
|
+
// The viewBox of an svg or a symbol, and how it fits; an image's fit uses align too.
|
|
199
|
+
double minX{0}, minY{0}, vbWidth{0}, vbHeight{0};
|
|
200
|
+
std::string align;
|
|
201
|
+
int meetOrSlice{0}; // meet, slice
|
|
202
|
+
SvgLength bbWidth, bbHeight;
|
|
203
|
+
|
|
204
|
+
std::string uri; // an image's source
|
|
205
|
+
|
|
206
|
+
// A foreignObject's own view, whose children the canvas draws.
|
|
207
|
+
Tag view{-1};
|
|
208
|
+
|
|
209
|
+
// Text: a span's characters, the font, its text-anchor ("start", "middle" or "end"; empty
|
|
210
|
+
// inherits), and the positions written on the element. A textPath's path is `href`, how far
|
|
211
|
+
// along it the text starts is the length "startOffset", and `side` "right" sets it along the
|
|
212
|
+
// path reversed.
|
|
213
|
+
std::string content;
|
|
214
|
+
SvgLength fontSize;
|
|
215
|
+
std::string fontFamily;
|
|
216
|
+
std::string fontWeight;
|
|
217
|
+
std::string textAnchor;
|
|
218
|
+
std::string side;
|
|
219
|
+
std::vector<SvgLength> xs, ys, dxs, dys;
|
|
220
|
+
|
|
221
|
+
bool operator==(const SvgElement &) const = default;
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
struct SvgNode {
|
|
225
|
+
SvgElement element;
|
|
226
|
+
std::vector<SvgNode> children;
|
|
227
|
+
bool operator==(const SvgNode &) const = default;
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
// An svg and everything under it, as one RNSVGSvgView holds it.
|
|
231
|
+
struct SvgDocument {
|
|
232
|
+
SvgNode root;
|
|
233
|
+
bool operator==(const SvgDocument &) const = default;
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
// The transform that fits a viewBox into a viewport, as preserveAspectRatio says: `align` is
|
|
237
|
+
// "none" or xMin|xMid|xMax with YMin|YMid|YMax, and meetOrSlice 0 fits it in, 1 covers.
|
|
238
|
+
SvgMatrix svgViewBoxTransform(const SvgRect &viewBox, const std::string &align, int meetOrSlice, double width, double height);
|
|
239
|
+
|
|
240
|
+
// A gradient in user space, ready to draw.
|
|
241
|
+
struct SvgGradient {
|
|
242
|
+
bool radial{false};
|
|
243
|
+
// Linear: from (x1, y1) to (x2, y2). Radial: centre (x1, y1), focus (x2, y2), radius r.
|
|
244
|
+
double x1{0}, y1{0}, x2{0}, y2{0}, r{0};
|
|
245
|
+
std::vector<std::pair<double, uint32_t>> stops;
|
|
246
|
+
// From the gradient's own space to the user space it paints in.
|
|
247
|
+
SvgMatrix transform;
|
|
248
|
+
bool operator==(const SvgGradient &) const = default;
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
struct SvgPaint {
|
|
252
|
+
// A colour, or a gradient when `gradient` is set.
|
|
253
|
+
uint32_t argb{0xff000000};
|
|
254
|
+
std::optional<SvgGradient> gradient;
|
|
255
|
+
double opacity{1};
|
|
256
|
+
bool operator==(const SvgPaint &) const = default;
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
struct SvgStroke {
|
|
260
|
+
double width{1};
|
|
261
|
+
int cap{0};
|
|
262
|
+
int join{0};
|
|
263
|
+
double miterLimit{4};
|
|
264
|
+
std::vector<double> dashes;
|
|
265
|
+
double dashOffset{0};
|
|
266
|
+
bool operator==(const SvgStroke &) const = default;
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
// A marker drawn at a vertex of a shape: where, and its direction in degrees (SVG's `auto`), the
|
|
270
|
+
// bisector of the incoming and outgoing directions at a vertex between two segments.
|
|
271
|
+
struct SvgMarkerVertex {
|
|
272
|
+
enum class Place { Start, Mid, End };
|
|
273
|
+
Place place{Place::Mid};
|
|
274
|
+
double x{0}, y{0};
|
|
275
|
+
double angle{0};
|
|
276
|
+
bool operator==(const SvgMarkerVertex &) const = default;
|
|
277
|
+
};
|
|
278
|
+
// The vertices a path's markers are drawn at, in order: the first is the start, the last the end.
|
|
279
|
+
std::vector<SvgMarkerVertex> svgMarkerVertices(const SvgPath &path);
|
|
280
|
+
|
|
281
|
+
// A glyph as text along a path draws it: what draws as one (a grapheme cluster, or the clusters a
|
|
282
|
+
// ligature joins), where it starts in its shaped run and its advance there, kerning included, and
|
|
283
|
+
// the canvas's own record of the glyphs the run shaped for it, which glyphCluster draws.
|
|
284
|
+
struct SvgGlyphCluster {
|
|
285
|
+
std::string text;
|
|
286
|
+
double x{0};
|
|
287
|
+
double advance{0};
|
|
288
|
+
std::shared_ptr<const void> glyphs;
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
// A pattern's tile: what one tile covers in the pattern's own space, and from that space to the
|
|
292
|
+
// user space the pattern fills.
|
|
293
|
+
struct SvgPatternTile {
|
|
294
|
+
SvgRect tile;
|
|
295
|
+
SvgMatrix transform;
|
|
296
|
+
bool operator==(const SvgPatternTile &) const = default;
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
// A filter step as runSvgFilter runs it, its lengths in the user space of the element filtered.
|
|
300
|
+
struct SvgFilterStep {
|
|
301
|
+
enum class Type { GaussianBlur, Offset, ColorMatrix, Flood, Composite, Merge };
|
|
302
|
+
Type type{Type::Offset};
|
|
303
|
+
// Never empty: an input left out is the step before's result, or SourceGraphic for the first.
|
|
304
|
+
std::string in1, in2;
|
|
305
|
+
// What later steps name this one's result by: its own `result`, or "#" and its index.
|
|
306
|
+
std::string result;
|
|
307
|
+
std::vector<std::string> inputs; // a merge's
|
|
308
|
+
// Where the step draws; nothing outside it.
|
|
309
|
+
SvgRect subregion;
|
|
310
|
+
double stdDeviationX{0}, stdDeviationY{0};
|
|
311
|
+
double dx{0}, dy{0};
|
|
312
|
+
// A 4x5 colour matrix by rows (r, g, b, a), over unpremultiplied colour, its last column an
|
|
313
|
+
// offset in 0 to 1.
|
|
314
|
+
std::array<double, 20> matrix{};
|
|
315
|
+
uint32_t argb{0};
|
|
316
|
+
double opacity{1};
|
|
317
|
+
int op{0};
|
|
318
|
+
std::array<double, 4> k{};
|
|
319
|
+
bool operator==(const SvgFilterStep &) const = default;
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
struct SvgFilter {
|
|
323
|
+
// The filter region, in the element's user space: the result is cut to it.
|
|
324
|
+
SvgRect region;
|
|
325
|
+
std::vector<SvgFilterStep> steps;
|
|
326
|
+
bool operator==(const SvgFilter &) const = default;
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
// A colour matrix step's 4x5 matrix for its type and values, as SVG defines saturate, hueRotate
|
|
330
|
+
// and luminanceToAlpha; the identity for a `matrix` without 20 values.
|
|
331
|
+
std::array<double, 20> svgColorMatrix(int type, const std::vector<double> &values);
|
|
332
|
+
|
|
333
|
+
// Pixels, premultiplied RGBA, 8 bits a channel, rows from the top.
|
|
334
|
+
struct SvgPixels {
|
|
335
|
+
int width{0}, height{0};
|
|
336
|
+
std::vector<uint8_t> rgba;
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
// Runs `filter` over `source`, the element as drawn (SourceGraphic), whose pixels `toPixels` maps
|
|
340
|
+
// the element's user space to. Lengths and offsets scale with the transform; a subregion or the
|
|
341
|
+
// region is cut to its bounds in pixels.
|
|
342
|
+
SvgPixels runSvgFilter(const SvgFilter &filter, const SvgPixels &source, const SvgMatrix &toPixels);
|
|
343
|
+
|
|
344
|
+
// The drawing calls a backend makes for drawSvg, in a graphics state it saves and restores.
|
|
345
|
+
class SvgCanvas {
|
|
346
|
+
public:
|
|
347
|
+
virtual ~SvgCanvas() = default;
|
|
348
|
+
virtual void save() = 0;
|
|
349
|
+
virtual void restore() = 0;
|
|
350
|
+
virtual void concat(const SvgMatrix &matrix) = 0;
|
|
351
|
+
virtual void clip(const SvgPath &path, bool evenOdd) = 0;
|
|
352
|
+
virtual void fill(const SvgPath &path, bool evenOdd, const SvgPaint &paint) = 0;
|
|
353
|
+
virtual void stroke(const SvgPath &path, const SvgStroke &stroke, const SvgPaint &paint) = 0;
|
|
354
|
+
// What is drawn until endLayer is composited as one, at `opacity`.
|
|
355
|
+
virtual void beginLayer(double opacity) = 0;
|
|
356
|
+
virtual void endLayer() = 0;
|
|
357
|
+
// What is drawn until endMask is the mask (its luminance, or its alpha for an alpha mask); then
|
|
358
|
+
// what is drawn until endMasked shows through it.
|
|
359
|
+
virtual void beginMask(bool alpha) = 0;
|
|
360
|
+
virtual void endMask() = 0;
|
|
361
|
+
virtual void endMasked() = 0;
|
|
362
|
+
// Clips to the outline `stroke` would draw of `path`.
|
|
363
|
+
virtual void clipToStroke(const SvgPath &path, const SvgStroke &stroke) = 0;
|
|
364
|
+
// Fills the clip with `tile` repeated, at `opacity`: `drawTile` draws one tile's content on a
|
|
365
|
+
// canvas whose origin is the tile's, in the pattern's own space.
|
|
366
|
+
virtual void pattern(const SvgPatternTile &tile, double opacity, const std::function<void(SvgCanvas &)> &drawTile) = 0;
|
|
367
|
+
// What is drawn until endFilter is the source of `filter`, whose result is drawn in its place.
|
|
368
|
+
virtual void beginFilter(const SvgFilter &filter) = 0;
|
|
369
|
+
virtual void endFilter() = 0;
|
|
370
|
+
virtual void image(const std::string &uri, const SvgRect &rect, const std::string &align, int meetOrSlice, double opacity) = 0;
|
|
371
|
+
// The advance of `text` in the font, as text() draws it.
|
|
372
|
+
virtual double measureText(const std::string &text, double fontSize, const std::string &fontFamily, const std::string &fontWeight) = 0;
|
|
373
|
+
// `text` shaped in the font as one run, split into the glyphs text along a path draws one at a
|
|
374
|
+
// time, in the order of the text.
|
|
375
|
+
virtual std::vector<SvgGlyphCluster> glyphClusters(
|
|
376
|
+
const std::string &text, double fontSize, const std::string &fontFamily, const std::string &fontWeight) = 0;
|
|
377
|
+
// Draws a cluster's glyphs as its run shaped them, contextual forms kept, with the cluster's start
|
|
378
|
+
// on the baseline at (x, y).
|
|
379
|
+
virtual void glyphCluster(const SvgGlyphCluster &cluster, double x, double y, const SvgPaint &fill) = 0;
|
|
380
|
+
// Draws `text` with its baseline's start at (x, y).
|
|
381
|
+
virtual void text(
|
|
382
|
+
const std::string &text,
|
|
383
|
+
double x,
|
|
384
|
+
double y,
|
|
385
|
+
double fontSize,
|
|
386
|
+
const std::string &fontFamily,
|
|
387
|
+
const std::string &fontWeight,
|
|
388
|
+
const SvgPaint &fill) = 0;
|
|
389
|
+
// Draws the native views in `view` (a foreignObject's), each at its frame in `view`.
|
|
390
|
+
virtual void views(Tag view) = 0;
|
|
391
|
+
};
|
|
392
|
+
|
|
393
|
+
// Draws `document` into a viewport of `width` by `height`, its origin at the canvas's.
|
|
394
|
+
void drawSvg(const SvgDocument &document, double width, double height, SvgCanvas &canvas);
|
|
395
|
+
|
|
396
|
+
// The svgs of a surface's views, kept by the mounting manager as it mounts them: which svg each
|
|
397
|
+
// change belongs to, and each svg's document when it changed.
|
|
398
|
+
class SvgDrawings {
|
|
399
|
+
public:
|
|
400
|
+
// The element a view's props are, or nothing for a view that is not an svg element.
|
|
401
|
+
// react-native-svg's glue (core/src/libraries/rnsvg.cpp) reads its props.
|
|
402
|
+
using Reader = std::function<std::optional<SvgElement>(const facebook::react::Props &)>;
|
|
403
|
+
explicit SvgDrawings(Reader reader = nullptr);
|
|
404
|
+
|
|
405
|
+
// A view was made or its props changed, or `parent`'s children changed.
|
|
406
|
+
void changed(const ViewTree &tree, Tag tag);
|
|
407
|
+
// A view's layout or state changed: what it draws, not what it is.
|
|
408
|
+
void relaidOut(const ViewTree &tree, Tag tag);
|
|
409
|
+
void deleted(Tag tag);
|
|
410
|
+
|
|
411
|
+
struct Drawing {
|
|
412
|
+
Tag svg{-1};
|
|
413
|
+
std::shared_ptr<const SvgDocument> document;
|
|
414
|
+
};
|
|
415
|
+
// The svgs whose documents changed since the last call, and those whose documents are the same
|
|
416
|
+
// but draw a view in a foreignObject that changed.
|
|
417
|
+
std::vector<Drawing> settle(const ViewTree &tree);
|
|
418
|
+
|
|
419
|
+
private:
|
|
420
|
+
std::optional<SvgElement> element(const ViewTree &tree, Tag tag) const;
|
|
421
|
+
std::optional<SvgNode> node(const ViewTree &tree, Tag tag) const;
|
|
422
|
+
void mark(const ViewTree &tree, Tag tag, bool repaint);
|
|
423
|
+
void repaintAbove(const ViewTree &tree, Tag tag);
|
|
424
|
+
|
|
425
|
+
Reader reader_;
|
|
426
|
+
std::unordered_set<Tag> dirty_;
|
|
427
|
+
// Svgs to draw again though their documents are the same.
|
|
428
|
+
std::unordered_set<Tag> repaint_;
|
|
429
|
+
// The foreignObjects mounted, whose views are drawn into their svgs.
|
|
430
|
+
std::unordered_set<Tag> foreign_;
|
|
431
|
+
std::unordered_map<Tag, std::shared_ptr<const SvgDocument>> drawn_;
|
|
432
|
+
};
|
|
433
|
+
|
|
434
|
+
} // namespace ngn
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// `<expo-symbol>` on a desktop host: expo-symbols' view (ViewManagerAdapter_SymbolModule, the
|
|
2
|
+
// component `registerExpoViews('expo-symbol')` commits) as a Fabric component, and the
|
|
3
|
+
// NgNativeSymbol module that sizes it, as @ng-native/expo's iOS module does.
|
|
4
|
+
//
|
|
5
|
+
// The core reads the props and decides what is drawn where: the paint (expo-symbols' type, tint
|
|
6
|
+
// and palette as a rendering mode and its colours) and the symbol's rectangle in the view, as
|
|
7
|
+
// UIKit's content mode `resizeMode` names places an image. The backend's view draws the SF Symbol
|
|
8
|
+
// with its toolkit at the system font size, as expo-symbols builds it, scaled into that rectangle.
|
|
9
|
+
//
|
|
10
|
+
// - NgNativeSymbol.imageSize(name, pointSize, weight, scale): [width, height] of the symbol's image
|
|
11
|
+
// at that point size, or null for a name the OS has no symbol for.
|
|
12
|
+
#pragma once
|
|
13
|
+
|
|
14
|
+
#include "ngn/desktop-props.h"
|
|
15
|
+
#include "ngn/native-module.h"
|
|
16
|
+
|
|
17
|
+
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
|
|
18
|
+
#include <react/renderer/components/view/ViewEventEmitter.h>
|
|
19
|
+
#include <react/renderer/components/view/ViewProps.h>
|
|
20
|
+
#include <react/renderer/core/ConcreteComponentDescriptor.h>
|
|
21
|
+
#include <react/renderer/graphics/Color.h>
|
|
22
|
+
|
|
23
|
+
#include <memory>
|
|
24
|
+
#include <optional>
|
|
25
|
+
#include <string>
|
|
26
|
+
#include <string_view>
|
|
27
|
+
#include <utility>
|
|
28
|
+
#include <vector>
|
|
29
|
+
|
|
30
|
+
namespace ngn {
|
|
31
|
+
|
|
32
|
+
extern const char SymbolComponentName[];
|
|
33
|
+
|
|
34
|
+
class SymbolProps final : public facebook::react::ViewProps, public HasDesktopProps {
|
|
35
|
+
public:
|
|
36
|
+
SymbolProps() = default;
|
|
37
|
+
SymbolProps(
|
|
38
|
+
const facebook::react::PropsParserContext &context,
|
|
39
|
+
const SymbolProps &sourceProps,
|
|
40
|
+
const facebook::react::RawProps &rawProps);
|
|
41
|
+
|
|
42
|
+
std::string name;
|
|
43
|
+
// `monochrome`, `hierarchical`, `palette` or `multicolor`.
|
|
44
|
+
std::string type{"monochrome"};
|
|
45
|
+
// expo-symbols' scale and weight names; empty for the default.
|
|
46
|
+
std::string scale;
|
|
47
|
+
std::string weight;
|
|
48
|
+
facebook::react::SharedColor tintColor;
|
|
49
|
+
std::vector<facebook::react::SharedColor> colors;
|
|
50
|
+
// UIKit's content modes by name; empty for `scaleAspectFit`.
|
|
51
|
+
std::string resizeMode;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
using SymbolShadowNode =
|
|
55
|
+
facebook::react::ConcreteViewShadowNode<SymbolComponentName, SymbolProps, facebook::react::ViewEventEmitter>;
|
|
56
|
+
using SymbolComponentDescriptor = facebook::react::ConcreteComponentDescriptor<SymbolShadowNode>;
|
|
57
|
+
|
|
58
|
+
// How the symbol's layers are coloured, as expo-symbols configures it.
|
|
59
|
+
struct SymbolPaint {
|
|
60
|
+
enum class Mode { Monochrome, Hierarchical, Palette, Multicolor };
|
|
61
|
+
Mode mode{Mode::Monochrome};
|
|
62
|
+
// Monochrome: the one colour, or none for the label colour. Hierarchical: the one colour, or
|
|
63
|
+
// none for the system blue. Palette: two or more. Multicolor: the tint for the layers with no
|
|
64
|
+
// colour of their own, or none.
|
|
65
|
+
std::vector<facebook::react::SharedColor> colors;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
SymbolPaint symbolPaint(const SymbolProps &props);
|
|
69
|
+
|
|
70
|
+
struct SymbolRect {
|
|
71
|
+
double x{0}, y{0}, width{0}, height{0};
|
|
72
|
+
bool operator==(const SymbolRect &) const = default;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
// Where an image of `image` size draws in a view of `box` size, from its top left, as UIKit's
|
|
76
|
+
// content mode `resizeMode` places it: scaled to fill, to fit, to fill keeping its ratio, or at its
|
|
77
|
+
// own size at the centre, an edge or a corner. An empty or unknown mode fits it.
|
|
78
|
+
SymbolRect placeSymbol(std::string_view resizeMode, std::pair<double, double> image, std::pair<double, double> box);
|
|
79
|
+
|
|
80
|
+
class SymbolMeasurer {
|
|
81
|
+
public:
|
|
82
|
+
virtual ~SymbolMeasurer() = default;
|
|
83
|
+
// The size of the symbol's image at `pointSize`, or nothing for a name with no symbol.
|
|
84
|
+
virtual std::optional<std::pair<double, double>> imageSize(
|
|
85
|
+
const std::string &name, double pointSize, const std::string &weight, const std::string &scale) = 0;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
std::shared_ptr<NativeModule> makeSymbolModule(std::shared_ptr<SymbolMeasurer> measurer);
|
|
89
|
+
|
|
90
|
+
} // namespace ngn
|