glacia-native 0.5.1 → 0.6.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 +29 -4
- package/README.md +111 -17
- package/lib/module/Accordion.js +58 -0
- package/lib/module/ActionSheet.js +38 -0
- package/lib/module/Alert.js +23 -0
- package/lib/module/AlertDialog.js +47 -0
- package/lib/module/Avatar.js +48 -0
- package/lib/module/Badge.js +36 -0
- package/lib/module/Bars.js +13 -267
- package/lib/module/Button.js +57 -36
- package/lib/module/Card.js +32 -20
- package/lib/module/Checkbox.js +42 -0
- package/lib/module/Chip.js +80 -0
- package/lib/module/Collapsible.js +26 -0
- package/lib/module/ContextMenu.js +33 -0
- package/lib/module/Dialog.js +39 -124
- package/lib/module/DropdownMenu.js +33 -0
- package/lib/module/Field.js +22 -0
- package/lib/module/Glass.js +12 -5
- package/lib/module/Group.js +36 -0
- package/lib/module/IconButton.js +40 -0
- package/lib/module/Input.js +47 -40
- package/lib/module/Label.js +17 -0
- package/lib/module/MorphGroup.js +47 -0
- package/lib/module/Popover.js +29 -0
- package/lib/module/Progress.js +32 -0
- package/lib/module/RadioGroup.js +51 -0
- package/lib/module/Scrim.js +44 -0
- package/lib/module/SegmentedControl.js +74 -58
- package/lib/module/Select.js +51 -0
- package/lib/module/Separator.js +25 -0
- package/lib/module/Sheet.js +51 -0
- package/lib/module/Skeleton.js +48 -0
- package/lib/module/Slider.js +60 -40
- package/lib/module/Stepper.js +167 -0
- package/lib/module/Switch.js +45 -43
- package/lib/module/TabBar.js +62 -50
- package/lib/module/Tabs.js +3 -2
- package/lib/module/Textarea.js +18 -0
- package/lib/module/Toast.js +55 -0
- package/lib/module/Toggle.js +47 -0
- package/lib/module/ToggleGroup.js +56 -0
- package/lib/module/Toolbar.js +37 -0
- package/lib/module/Tooltip.js +31 -0
- package/lib/module/glass-provider.js +28 -0
- package/lib/module/glass-stack.js +61 -0
- package/lib/module/index.js +78 -109
- package/lib/module/internal/GlassBackdrop.js +36 -0
- package/lib/module/internal/GlassView.js +45 -13
- package/lib/module/internal/blur-community.js +20 -0
- package/lib/module/internal/blur-community.web.js +9 -0
- package/lib/module/internal/blur.js +75 -0
- package/lib/module/internal/fallback.js +110 -20
- package/lib/module/internal/glass-routing.js +154 -30
- package/lib/module/internal/glow.js +36 -0
- package/lib/module/internal/initials.js +12 -0
- package/lib/module/internal/lens.js +70 -0
- package/lib/module/internal/material.js +64 -0
- package/lib/module/internal/overlay.js +147 -0
- package/lib/module/internal/primitives.js +17 -0
- package/lib/module/internal/rim.js +35 -0
- package/lib/module/internal/tokens.js +34 -2
- package/lib/typescript/Accordion.d.ts +22 -0
- package/lib/typescript/ActionSheet.d.ts +24 -0
- package/lib/typescript/Alert.d.ts +15 -0
- package/lib/typescript/AlertDialog.d.ts +17 -0
- package/lib/typescript/Avatar.d.ts +22 -0
- package/lib/typescript/Badge.d.ts +12 -0
- package/lib/typescript/Bars.d.ts +3 -188
- package/lib/typescript/Button.d.ts +44 -10
- package/lib/typescript/Card.d.ts +30 -3
- package/lib/typescript/Checkbox.d.ts +14 -0
- package/lib/typescript/Chip.d.ts +19 -0
- package/lib/typescript/Collapsible.d.ts +17 -0
- package/lib/typescript/ContextMenu.d.ts +23 -0
- package/lib/typescript/Dialog.d.ts +8 -68
- package/lib/typescript/DropdownMenu.d.ts +23 -0
- package/lib/typescript/Field.d.ts +19 -0
- package/lib/typescript/Glass.d.ts +11 -2
- package/lib/typescript/Group.d.ts +35 -0
- package/lib/typescript/IconButton.d.ts +21 -0
- package/lib/typescript/Input.d.ts +17 -18
- package/lib/typescript/Label.d.ts +14 -0
- package/lib/typescript/MorphGroup.d.ts +46 -0
- package/lib/typescript/Popover.d.ts +17 -0
- package/lib/typescript/Progress.d.ts +13 -0
- package/lib/typescript/RadioGroup.d.ts +21 -0
- package/lib/typescript/Scrim.d.ts +33 -0
- package/lib/typescript/SegmentedControl.d.ts +24 -13
- package/lib/typescript/Select.d.ts +19 -0
- package/lib/typescript/Separator.d.ts +10 -0
- package/lib/typescript/Sheet.d.ts +45 -0
- package/lib/typescript/Skeleton.d.ts +10 -0
- package/lib/typescript/Slider.d.ts +15 -7
- package/lib/typescript/Stepper.d.ts +49 -0
- package/lib/typescript/Switch.d.ts +19 -12
- package/lib/typescript/TabBar.d.ts +18 -6
- package/lib/typescript/Textarea.d.ts +6 -0
- package/lib/typescript/Toast.d.ts +40 -0
- package/lib/typescript/Toggle.d.ts +21 -0
- package/lib/typescript/ToggleGroup.d.ts +22 -0
- package/lib/typescript/Toolbar.d.ts +35 -0
- package/lib/typescript/Tooltip.d.ts +16 -0
- package/lib/typescript/glass-provider.d.ts +34 -0
- package/lib/typescript/glass-stack.d.ts +54 -0
- package/lib/typescript/index.d.ts +39 -17
- package/lib/typescript/internal/GlassBackdrop.d.ts +33 -0
- package/lib/typescript/internal/GlassView.d.ts +31 -2
- package/lib/typescript/internal/blur-community.d.ts +2 -0
- package/lib/typescript/internal/blur-community.web.d.ts +2 -0
- package/lib/typescript/internal/blur.d.ts +24 -0
- package/lib/typescript/internal/fallback.d.ts +27 -2
- package/lib/typescript/internal/glass-routing.d.ts +83 -15
- package/lib/typescript/internal/glow.d.ts +11 -0
- package/lib/typescript/internal/initials.d.ts +2 -0
- package/lib/typescript/internal/lens.d.ts +47 -0
- package/lib/typescript/internal/material.d.ts +27 -0
- package/lib/typescript/internal/overlay.d.ts +74 -0
- package/lib/typescript/internal/primitives.d.ts +13 -0
- package/lib/typescript/internal/rim.d.ts +16 -0
- package/lib/typescript/internal/tokens.d.ts +36 -0
- package/package.json +15 -4
- package/src/Accordion.tsx +165 -0
- package/src/ActionSheet.tsx +149 -0
- package/src/Alert.tsx +85 -0
- package/src/AlertDialog.tsx +124 -0
- package/src/Avatar.tsx +102 -0
- package/src/Badge.tsx +80 -0
- package/src/Bars.tsx +10 -797
- package/src/Button.tsx +196 -60
- package/src/Card.tsx +106 -33
- package/src/Checkbox.tsx +98 -0
- package/src/Chip.tsx +149 -0
- package/src/Collapsible.tsx +66 -0
- package/src/ContextMenu.tsx +103 -0
- package/src/Dialog.tsx +86 -325
- package/src/DropdownMenu.tsx +103 -0
- package/src/Field.tsx +65 -0
- package/src/Glass.tsx +19 -5
- package/src/Group.tsx +98 -0
- package/src/IconButton.tsx +110 -0
- package/src/Input.tsx +143 -87
- package/src/Label.tsx +56 -0
- package/src/MorphGroup.tsx +134 -0
- package/src/Popover.tsx +81 -0
- package/src/Progress.tsx +83 -0
- package/src/RadioGroup.tsx +122 -0
- package/src/Scrim.tsx +94 -0
- package/src/SegmentedControl.tsx +147 -90
- package/src/Select.tsx +136 -0
- package/src/Separator.tsx +52 -0
- package/src/Sheet.tsx +139 -0
- package/src/Skeleton.tsx +77 -0
- package/src/Slider.tsx +100 -54
- package/src/Stepper.tsx +315 -0
- package/src/Switch.tsx +80 -58
- package/src/TabBar.tsx +118 -84
- package/src/Tabs.tsx +5 -0
- package/src/Textarea.tsx +34 -0
- package/src/Toast.tsx +131 -0
- package/src/Toggle.tsx +113 -0
- package/src/ToggleGroup.tsx +129 -0
- package/src/Toolbar.tsx +111 -0
- package/src/Tooltip.tsx +79 -0
- package/src/engine/CHANGELOG.md +430 -0
- package/src/engine/NOTICE +54 -0
- package/src/engine/README.md +975 -0
- package/src/engine/android/build.gradle +18 -0
- package/src/engine/android/src/main/AndroidManifest.xml +2 -0
- package/src/engine/android/src/main/java/expo/modules/liquidglass/ExpoLiquidGlassModule.kt +174 -0
- package/src/engine/android/src/main/java/expo/modules/liquidglass/GlassConstants.kt +7 -0
- package/src/engine/android/src/main/java/expo/modules/liquidglass/LiquidGlassContainerView.kt +16 -0
- package/src/engine/android/src/main/java/expo/modules/liquidglass/LiquidGlassProviderView.kt +165 -0
- package/src/engine/android/src/main/java/expo/modules/liquidglass/LiquidGlassView.kt +1731 -0
- package/src/engine/android/src/main/java/expo/modules/liquidglass/enums/GlassEnums.kt +171 -0
- package/src/engine/android/src/main/java/expo/modules/liquidglass/glass/BackdropGraph.kt +146 -0
- package/src/engine/android/src/main/java/expo/modules/liquidglass/glass/BackdropSource.kt +53 -0
- package/src/engine/android/src/main/java/expo/modules/liquidglass/glass/ContinuousCorners.kt +188 -0
- package/src/engine/android/src/main/java/expo/modules/liquidglass/glass/CornerRadii.kt +62 -0
- package/src/engine/android/src/main/java/expo/modules/liquidglass/glass/GlassAppearance.kt +352 -0
- package/src/engine/android/src/main/java/expo/modules/liquidglass/glass/GlassDebug.kt +109 -0
- package/src/engine/android/src/main/java/expo/modules/liquidglass/glass/GlassEnvironment.kt +139 -0
- package/src/engine/android/src/main/java/expo/modules/liquidglass/glass/GlassHdr.kt +85 -0
- package/src/engine/android/src/main/java/expo/modules/liquidglass/glass/GlassLuminanceProbe.kt +189 -0
- package/src/engine/android/src/main/java/expo/modules/liquidglass/glass/GlassPressAnimator.kt +264 -0
- package/src/engine/android/src/main/java/expo/modules/liquidglass/glass/GlassProgressiveBlur.kt +249 -0
- package/src/engine/android/src/main/java/expo/modules/liquidglass/glass/GlassShaderCache.kt +256 -0
- package/src/engine/android/src/main/java/expo/modules/liquidglass/glass/GlassShaderSource.kt +845 -0
- package/src/engine/android/src/main/java/expo/modules/liquidglass/glass/GlassTier.kt +63 -0
- package/src/engine/android/src/main/java/expo/modules/liquidglass/glass/ProviderRegistry.kt +71 -0
- package/src/engine/android/src/main/java/expo/modules/liquidglass/records/GlassRecords.kt +288 -0
- package/src/engine/index.ts +24 -0
- package/src/engine/ios/Enums/GlassBlurDirection.swift +21 -0
- package/src/engine/ios/Enums/GlassVariant.swift +86 -0
- package/src/engine/ios/ExpoLiquidGlass.podspec +93 -0
- package/src/engine/ios/ExpoLiquidGlassModule.swift +77 -0
- package/src/engine/ios/Glass/BackdropCapturer.swift +811 -0
- package/src/engine/ios/Glass/ContinuousCorners.swift +165 -0
- package/src/engine/ios/Glass/GlassBackdrop.swift +176 -0
- package/src/engine/ios/Glass/GlassFramePhase.swift +126 -0
- package/src/engine/ios/Glass/GlassFrameScheduler.swift +261 -0
- package/src/engine/ios/Glass/GlassPressAnimator.swift +250 -0
- package/src/engine/ios/Glass/GlassRenderContext.swift +168 -0
- package/src/engine/ios/Glass/GlassRenderer.swift +186 -0
- package/src/engine/ios/Glass/GlassSurfaceView.swift +452 -0
- package/src/engine/ios/Glass/NonRenderableView.swift +54 -0
- package/src/engine/ios/Glass/StripCache.swift +545 -0
- package/src/engine/ios/Records/GlassCornerRadii.swift +79 -0
- package/src/engine/ios/Records/GlassMetalOptions.swift +180 -0
- package/src/engine/ios/Records/GlassRefractionCurve.swift +14 -0
- package/src/engine/ios/Shaders/LiquidGlass.metal +480 -0
- package/src/engine/ios/Shaders/bundle-marker.txt +6 -0
- package/src/engine/ios/Views/LiquidGlassContainerView.swift +99 -0
- package/src/engine/ios/Views/LiquidGlassView.swift +859 -0
- package/src/engine/package.json +70 -0
- package/src/engine/src/components/LiquidGlassButton/LiquidGlassButton.tsx +424 -0
- package/src/engine/src/components/LiquidGlassCard/LiquidGlassCard.tsx +98 -0
- package/src/engine/src/components/LiquidGlassChip/LiquidGlassChip.tsx +65 -0
- package/src/engine/src/components/LiquidGlassGroup/LiquidGlassGroup.tsx +350 -0
- package/src/engine/src/components/LiquidGlassIconButton/LiquidGlassIconButton.tsx +24 -0
- package/src/engine/src/components/LiquidGlassMorphGroup/LiquidGlassMorphGroup.tsx +434 -0
- package/src/engine/src/components/LiquidGlassScrim/LiquidGlassScrim.tsx +100 -0
- package/src/engine/src/components/LiquidGlassSegmentedControl/LiquidGlassSegmentedControl.tsx +213 -0
- package/src/engine/src/components/LiquidGlassSheet/LiquidGlassSheet.tsx +218 -0
- package/src/engine/src/components/LiquidGlassSlider/LiquidGlassSlider.tsx +327 -0
- package/src/engine/src/components/LiquidGlassStepper/LiquidGlassStepper.tsx +321 -0
- package/src/engine/src/components/LiquidGlassSwitch/LiquidGlassSwitch.tsx +296 -0
- package/src/engine/src/components/LiquidGlassTabBar/LiquidGlassTabBar.tsx +952 -0
- package/src/engine/src/components/LiquidGlassTextInput/LiquidGlassTextInput.tsx +151 -0
- package/src/engine/src/components/LiquidGlassToast/LiquidGlassToast.tsx +169 -0
- package/src/engine/src/components/LiquidGlassToolbar/LiquidGlassToolbar.tsx +124 -0
- package/src/engine/src/components/index.ts +16 -0
- package/src/engine/src/constants/index.ts +4 -0
- package/src/engine/src/constants/metal.constants.ts +327 -0
- package/src/engine/src/constants/metrics.constants.ts +325 -0
- package/src/engine/src/constants/springs.constants.ts +107 -0
- package/src/engine/src/constants/styles.constants.ts +12 -0
- package/src/engine/src/context/glass-group.context.ts +65 -0
- package/src/engine/src/context/index.ts +6 -0
- package/src/engine/src/core/components/LiquidGlassContainer/LiquidGlassContainer.tsx +32 -0
- package/src/engine/src/core/components/LiquidGlassContainer/index.ts +1 -0
- package/src/engine/src/core/components/LiquidGlassProvider/LiquidGlassProvider.tsx +66 -0
- package/src/engine/src/core/components/LiquidGlassProvider/index.ts +1 -0
- package/src/engine/src/core/components/LiquidGlassStack/LiquidGlassStack.tsx +184 -0
- package/src/engine/src/core/components/LiquidGlassStack/index.ts +1 -0
- package/src/engine/src/core/components/LiquidGlassView/LiquidGlassView.tsx +126 -0
- package/src/engine/src/core/components/LiquidGlassView/index.ts +1 -0
- package/src/engine/src/core/components/index.ts +4 -0
- package/src/engine/src/core/constants/glass.constants.ts +57 -0
- package/src/engine/src/core/constants/index.ts +20 -0
- package/src/engine/src/core/constants/native.constants.ts +16 -0
- package/src/engine/src/core/context/glass-stack.context.ts +30 -0
- package/src/engine/src/core/context/index.ts +4 -0
- package/src/engine/src/core/enum/index.ts +12 -0
- package/src/engine/src/core/index.ts +1 -0
- package/src/engine/src/core/interfaces/glass-hdr.interface.ts +15 -0
- package/src/engine/src/core/interfaces/glass-metal.interface.ts +248 -0
- package/src/engine/src/core/interfaces/glass-surface.interface.ts +9 -0
- package/src/engine/src/core/interfaces/index.ts +31 -0
- package/src/engine/src/core/interfaces/liquid-glass-container.interface.ts +6 -0
- package/src/engine/src/core/interfaces/liquid-glass-provider.interface.ts +14 -0
- package/src/engine/src/core/interfaces/liquid-glass-stack.interface.ts +21 -0
- package/src/engine/src/core/interfaces/liquid-glass-view.interface.ts +129 -0
- package/src/engine/src/core/interfaces/native-liquid-glass-view.interface.ts +19 -0
- package/src/engine/src/core/modules/ExpoLiquidGlassModule.ts +26 -0
- package/src/engine/src/core/modules/index.ts +2 -0
- package/src/engine/src/core/root/index.ts +51 -0
- package/src/engine/src/core/types/glass.types.ts +25 -0
- package/src/engine/src/core/types/index.ts +8 -0
- package/src/engine/src/core/utils/debug.utils.ts +17 -0
- package/src/engine/src/core/utils/dev-warn.utils.ts +17 -0
- package/src/engine/src/core/utils/hdr.utils.ts +37 -0
- package/src/engine/src/core/utils/index.ts +5 -0
- package/src/engine/src/core/utils/native-view.utils.ts +33 -0
- package/src/engine/src/core/utils/platform.utils.ts +34 -0
- package/src/engine/src/core/views/NativeGlassBackdropView.ts +24 -0
- package/src/engine/src/core/views/NativeLiquidGlassContainerView.ts +13 -0
- package/src/engine/src/core/views/NativeLiquidGlassContainerView.web.ts +10 -0
- package/src/engine/src/core/views/NativeLiquidGlassProviderView.ts +13 -0
- package/src/engine/src/core/views/NativeLiquidGlassProviderView.web.ts +10 -0
- package/src/engine/src/core/views/NativeLiquidGlassView.ts +19 -0
- package/src/engine/src/core/views/NativeLiquidGlassView.web.ts +14 -0
- package/src/engine/src/core/views/index.ts +4 -0
- package/src/engine/src/hooks/index.ts +18 -0
- package/src/engine/src/hooks/use-adaptive-glass.ts +91 -0
- package/src/engine/src/hooks/use-damped-drag.ts +332 -0
- package/src/engine/src/hooks/use-echo-filter.ts +55 -0
- package/src/engine/src/hooks/use-glass-group-member.ts +169 -0
- package/src/engine/src/hooks/use-gravity-highlight.ts +79 -0
- package/src/engine/src/hooks/use-press-progress.ts +44 -0
- package/src/engine/src/index.ts +120 -0
- package/src/engine/src/interfaces/index.ts +28 -0
- package/src/engine/src/interfaces/liquid-glass-button.interface.ts +94 -0
- package/src/engine/src/interfaces/liquid-glass-card.interface.ts +40 -0
- package/src/engine/src/interfaces/liquid-glass-chip.interface.ts +29 -0
- package/src/engine/src/interfaces/liquid-glass-group.interface.ts +32 -0
- package/src/engine/src/interfaces/liquid-glass-icon-button.interface.ts +19 -0
- package/src/engine/src/interfaces/liquid-glass-morph-group.interface.ts +59 -0
- package/src/engine/src/interfaces/liquid-glass-scrim.interface.ts +36 -0
- package/src/engine/src/interfaces/liquid-glass-segmented-control.interface.ts +32 -0
- package/src/engine/src/interfaces/liquid-glass-sheet.interface.ts +38 -0
- package/src/engine/src/interfaces/liquid-glass-slider.interface.ts +37 -0
- package/src/engine/src/interfaces/liquid-glass-stepper.interface.ts +35 -0
- package/src/engine/src/interfaces/liquid-glass-switch.interface.ts +27 -0
- package/src/engine/src/interfaces/liquid-glass-tab-bar.interface.ts +116 -0
- package/src/engine/src/interfaces/liquid-glass-text-input.interface.ts +42 -0
- package/src/engine/src/interfaces/liquid-glass-toast.interface.ts +36 -0
- package/src/engine/src/interfaces/liquid-glass-toolbar.interface.ts +33 -0
- package/src/engine/src/theme/glass-ui-theme.ts +100 -0
- package/src/engine/src/theme/index.ts +2 -0
- package/src/engine/src/utils/button-press.utils.ts +63 -0
- package/src/engine/src/utils/index.ts +3 -0
- package/src/engine/src/utils/metal.utils.ts +164 -0
- package/src/glass-provider.tsx +60 -0
- package/src/glass-stack.tsx +115 -0
- package/src/index.ts +48 -190
- package/src/internal/GlassBackdrop.tsx +60 -0
- package/src/internal/GlassView.tsx +70 -18
- package/src/internal/blur-community.ts +19 -0
- package/src/internal/blur-community.web.ts +7 -0
- package/src/internal/blur.ts +89 -0
- package/src/internal/fallback.tsx +158 -20
- package/src/internal/glass-routing.ts +211 -34
- package/src/internal/glow.tsx +62 -0
- package/src/internal/initials.ts +7 -0
- package/src/internal/lens.tsx +105 -0
- package/src/internal/material.ts +92 -0
- package/src/internal/overlay.tsx +258 -0
- package/src/internal/primitives.ts +26 -0
- package/src/internal/rim.tsx +79 -0
- package/src/internal/tokens.ts +34 -1
- package/lib/module/Carousel.js +0 -103
- package/lib/module/Display.js +0 -317
- package/lib/module/Feedback.js +0 -386
- package/lib/module/Form.js +0 -164
- package/lib/module/Forms2.js +0 -454
- package/lib/module/Message.js +0 -88
- package/lib/module/Overlays.js +0 -328
- package/lib/module/Pickers.js +0 -243
- package/lib/module/Table.js +0 -99
- package/lib/module/ai.js +0 -280
- package/lib/module/charts/AreaChart.js +0 -32
- package/lib/module/charts/BarChart.js +0 -67
- package/lib/module/charts/FunnelChart.js +0 -50
- package/lib/module/charts/HeatmapChart.js +0 -71
- package/lib/module/charts/LineChart.js +0 -81
- package/lib/module/charts/PlotChart.js +0 -52
- package/lib/module/charts/RadarChart.js +0 -78
- package/lib/module/charts/RingChart.js +0 -52
- package/lib/module/charts/ScatterChart.js +0 -95
- package/lib/module/charts/WaterfallChart.js +0 -85
- package/lib/module/charts/advanced.js +0 -313
- package/lib/module/charts/extra.js +0 -108
- package/lib/module/charts/index.js +0 -50
- package/lib/module/charts/scales.js +0 -140
- package/lib/typescript/Carousel.d.ts +0 -47
- package/lib/typescript/Display.d.ts +0 -178
- package/lib/typescript/Feedback.d.ts +0 -196
- package/lib/typescript/Form.d.ts +0 -97
- package/lib/typescript/Forms2.d.ts +0 -209
- package/lib/typescript/Message.d.ts +0 -71
- package/lib/typescript/Overlays.d.ts +0 -146
- package/lib/typescript/Pickers.d.ts +0 -105
- package/lib/typescript/Table.d.ts +0 -64
- package/lib/typescript/ai.d.ts +0 -166
- package/lib/typescript/charts/AreaChart.d.ts +0 -44
- package/lib/typescript/charts/BarChart.d.ts +0 -19
- package/lib/typescript/charts/FunnelChart.d.ts +0 -25
- package/lib/typescript/charts/HeatmapChart.d.ts +0 -23
- package/lib/typescript/charts/LineChart.d.ts +0 -30
- package/lib/typescript/charts/PlotChart.d.ts +0 -31
- package/lib/typescript/charts/RadarChart.d.ts +0 -27
- package/lib/typescript/charts/RingChart.d.ts +0 -28
- package/lib/typescript/charts/ScatterChart.d.ts +0 -34
- package/lib/typescript/charts/WaterfallChart.d.ts +0 -22
- package/lib/typescript/charts/advanced.d.ts +0 -107
- package/lib/typescript/charts/extra.d.ts +0 -63
- package/lib/typescript/charts/index.d.ts +0 -13
- package/lib/typescript/charts/scales.d.ts +0 -35
- package/src/Carousel.tsx +0 -233
- package/src/Display.tsx +0 -778
- package/src/Feedback.tsx +0 -969
- package/src/Form.tsx +0 -425
- package/src/Forms2.tsx +0 -1014
- package/src/Message.tsx +0 -219
- package/src/Overlays.tsx +0 -685
- package/src/Pickers.tsx +0 -590
- package/src/Table.tsx +0 -231
- package/src/ai.tsx +0 -707
- package/src/charts/AreaChart.tsx +0 -73
- package/src/charts/BarChart.tsx +0 -183
- package/src/charts/FunnelChart.tsx +0 -125
- package/src/charts/HeatmapChart.tsx +0 -155
- package/src/charts/LineChart.tsx +0 -247
- package/src/charts/PlotChart.tsx +0 -168
- package/src/charts/RadarChart.tsx +0 -208
- package/src/charts/RingChart.tsx +0 -133
- package/src/charts/ScatterChart.tsx +0 -223
- package/src/charts/WaterfallChart.tsx +0 -201
- package/src/charts/advanced.tsx +0 -676
- package/src/charts/extra.tsx +0 -242
- package/src/charts/index.ts +0 -86
- package/src/charts/scales.ts +0 -163
|
@@ -0,0 +1,811 @@
|
|
|
1
|
+
import Metal
|
|
2
|
+
import UIKit
|
|
3
|
+
|
|
4
|
+
final class BackdropCapturer {
|
|
5
|
+
|
|
6
|
+
static let shared = BackdropCapturer()
|
|
7
|
+
|
|
8
|
+
private(set) var texture: MTLTexture?
|
|
9
|
+
|
|
10
|
+
private(set) var capturedOrigin: CGPoint = .zero
|
|
11
|
+
|
|
12
|
+
private(set) var textureSizePoints: CGSize = .zero
|
|
13
|
+
|
|
14
|
+
private(set) var textureScale: CGFloat = Tuning.fallbackCaptureScale
|
|
15
|
+
|
|
16
|
+
private var requestedScale: CGFloat = Tuning.fallbackCaptureScale
|
|
17
|
+
|
|
18
|
+
private enum Tuning {
|
|
19
|
+
|
|
20
|
+
static let fallbackCaptureScale: CGFloat = 2.0
|
|
21
|
+
|
|
22
|
+
static let maxCapturePixels: CGFloat = 4_500_000
|
|
23
|
+
|
|
24
|
+
static let dutyCycle: Double = 0.30
|
|
25
|
+
|
|
26
|
+
static let maxStride = 3
|
|
27
|
+
|
|
28
|
+
static let strideHysteresisFrames = 45
|
|
29
|
+
|
|
30
|
+
static let staleCapturesBeforeIdle = 4
|
|
31
|
+
static let idleStride = 4
|
|
32
|
+
|
|
33
|
+
static let digestStride = 97
|
|
34
|
+
|
|
35
|
+
static let emptyCapturesBeforeSwitch = 3
|
|
36
|
+
|
|
37
|
+
static let costSmoothing: Double = 0.2
|
|
38
|
+
|
|
39
|
+
static let shrinkDelay: CFTimeInterval = 1.0
|
|
40
|
+
|
|
41
|
+
static let allocationBucket = 64
|
|
42
|
+
|
|
43
|
+
static let movementMargin: CGFloat = 220
|
|
44
|
+
|
|
45
|
+
static let movementMemory: CFTimeInterval = 0.4
|
|
46
|
+
|
|
47
|
+
/// The adaptive sensor's sampling grid, per axis.
|
|
48
|
+
static let luminanceGrid = 12
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
private enum Debug {
|
|
52
|
+
static let enabled =
|
|
53
|
+
ProcessInfo.processInfo.environment["EXPO_LIQUID_GLASS_DEBUG"] == "1"
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
private var debugCaptures = 0
|
|
57
|
+
private var debugTotalCost: Double = 0
|
|
58
|
+
private var debugWindowStart: CFTimeInterval = 0
|
|
59
|
+
|
|
60
|
+
private func recordDebug(cost: Double, region: CGRect, now: CFTimeInterval) {
|
|
61
|
+
guard Debug.enabled else { return }
|
|
62
|
+
debugCaptures += 1
|
|
63
|
+
debugTotalCost += cost
|
|
64
|
+
|
|
65
|
+
if debugWindowStart == 0 { debugWindowStart = now }
|
|
66
|
+
let elapsed = now - debugWindowStart
|
|
67
|
+
guard elapsed >= 1.0 else { return }
|
|
68
|
+
|
|
69
|
+
let mean = debugTotalCost / Double(debugCaptures) * 1000
|
|
70
|
+
print(String(
|
|
71
|
+
format: "[LiquidGlass] %.0f cap/s %.2fms each (%.0f%% of a 60Hz frame) "
|
|
72
|
+
+ "stride %d scale %.2f region %.0fx%.0f %dk px path %@",
|
|
73
|
+
Double(debugCaptures) / elapsed, mean, mean / 16.67 * 100,
|
|
74
|
+
strideFrames, Double(textureScale),
|
|
75
|
+
Double(region.width), Double(region.height), capturedPixelCount / 1000,
|
|
76
|
+
slots.first?.uploadSource == nil ? "zero-copy" : "upload"
|
|
77
|
+
))
|
|
78
|
+
|
|
79
|
+
debugCaptures = 0
|
|
80
|
+
debugTotalCost = 0
|
|
81
|
+
debugWindowStart = now
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
private var captureCost: Double = 0
|
|
85
|
+
|
|
86
|
+
private var strideFrames = 1
|
|
87
|
+
private var candidateStride = 1
|
|
88
|
+
private var candidateStrideAge = 0
|
|
89
|
+
private var frameCounter = 0
|
|
90
|
+
|
|
91
|
+
private var capturedPixelCount: Int = 0
|
|
92
|
+
|
|
93
|
+
private var lastDigest: UInt64 = 0
|
|
94
|
+
private var staleCaptures = 0
|
|
95
|
+
|
|
96
|
+
/// How a glass-free subtree is drawn — see `drawTree`, which walks the tree either way.
|
|
97
|
+
private enum Strategy {
|
|
98
|
+
/// `CALayer.render(in:)` on each leaf: cheap, and blank on iOS 26.
|
|
99
|
+
case layerRender
|
|
100
|
+
/// `drawHierarchy(in:afterScreenUpdates:)` on each leaf — window-server snapshots.
|
|
101
|
+
case compositedDraw
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
private var strategy: Strategy = .layerRender
|
|
105
|
+
|
|
106
|
+
private var emptyCaptures = 0
|
|
107
|
+
|
|
108
|
+
private var lastRegion: CGRect = .null
|
|
109
|
+
|
|
110
|
+
private var capturedRegion: CGRect = .null
|
|
111
|
+
|
|
112
|
+
private var lastMovementTime: CFTimeInterval = -.greatestFiniteMagnitude
|
|
113
|
+
|
|
114
|
+
private final class Slot {
|
|
115
|
+
let texture: MTLTexture
|
|
116
|
+
let context: CGContext
|
|
117
|
+
let pixelSize: (width: Int, height: Int)
|
|
118
|
+
let bytesPerRow: Int
|
|
119
|
+
let uploadSource: UnsafeMutableRawPointer?
|
|
120
|
+
|
|
121
|
+
private let ownedMemory: UnsafeMutableRawPointer?
|
|
122
|
+
private let buffer: MTLBuffer?
|
|
123
|
+
|
|
124
|
+
var bufferContents: UnsafeMutableRawPointer? {
|
|
125
|
+
ownedMemory ?? buffer?.contents()
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
init(
|
|
129
|
+
texture: MTLTexture,
|
|
130
|
+
context: CGContext,
|
|
131
|
+
pixelSize: (width: Int, height: Int),
|
|
132
|
+
bytesPerRow: Int,
|
|
133
|
+
buffer: MTLBuffer?,
|
|
134
|
+
ownedMemory: UnsafeMutableRawPointer?
|
|
135
|
+
) {
|
|
136
|
+
self.texture = texture
|
|
137
|
+
self.context = context
|
|
138
|
+
self.pixelSize = pixelSize
|
|
139
|
+
self.bytesPerRow = bytesPerRow
|
|
140
|
+
self.buffer = buffer
|
|
141
|
+
self.ownedMemory = ownedMemory
|
|
142
|
+
self.uploadSource = ownedMemory
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
deinit { ownedMemory?.deallocate() }
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
private var slots: [Slot] = []
|
|
149
|
+
private var slotIndex = 0
|
|
150
|
+
private var smallerSizeSince: CFTimeInterval?
|
|
151
|
+
|
|
152
|
+
private init() {}
|
|
153
|
+
|
|
154
|
+
func capture(
|
|
155
|
+
window: UIWindow,
|
|
156
|
+
region: CGRect,
|
|
157
|
+
scale: CGFloat,
|
|
158
|
+
frameDuration: CFTimeInterval,
|
|
159
|
+
isUnderLoad: Bool,
|
|
160
|
+
// A strip-backed scope composites its content band from the ring, so the window capture
|
|
161
|
+
// only supplies the static bands. Those must not be gated by the movement margin: when
|
|
162
|
+
// the glass slides over content, that gate is what used to freeze the photograph.
|
|
163
|
+
ignoreMovementGate: Bool = false
|
|
164
|
+
) -> Bool {
|
|
165
|
+
guard !region.isNull, !region.isEmpty,
|
|
166
|
+
window.bounds.width > 0, window.bounds.height > 0
|
|
167
|
+
else { return false }
|
|
168
|
+
|
|
169
|
+
if scale != requestedScale {
|
|
170
|
+
requestedScale = scale
|
|
171
|
+
slots.removeAll()
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
let clipped = region.intersection(window.bounds)
|
|
175
|
+
guard !clipped.isEmpty else { return false }
|
|
176
|
+
|
|
177
|
+
frameCounter &+= 1
|
|
178
|
+
|
|
179
|
+
let moved = clipped != lastRegion
|
|
180
|
+
lastRegion = clipped
|
|
181
|
+
|
|
182
|
+
if moved { lastMovementTime = CACurrentMediaTime() }
|
|
183
|
+
|
|
184
|
+
let mustRefreshGeometry = !capturedRegion.contains(clipped)
|
|
185
|
+
|
|
186
|
+
let isMoving = CACurrentMediaTime() - lastMovementTime < Tuning.movementMemory
|
|
187
|
+
let stride = staleCaptures >= Tuning.staleCapturesBeforeIdle
|
|
188
|
+
? Tuning.idleStride
|
|
189
|
+
: strideFrames
|
|
190
|
+
let dueByCadence = ignoreMovementGate || (!isMoving && frameCounter % stride == 0)
|
|
191
|
+
guard mustRefreshGeometry || dueByCadence else { return false }
|
|
192
|
+
|
|
193
|
+
let margin = (isMoving && !ignoreMovementGate) ? Tuning.movementMargin : 0
|
|
194
|
+
let target = margin > 0
|
|
195
|
+
? clipped.insetBy(dx: -margin, dy: -margin).intersection(window.bounds)
|
|
196
|
+
: clipped
|
|
197
|
+
|
|
198
|
+
let start = CACurrentMediaTime()
|
|
199
|
+
let didCapture = rasterise(window: window, region: target)
|
|
200
|
+
guard didCapture else { return false }
|
|
201
|
+
|
|
202
|
+
capturedRegion = target
|
|
203
|
+
|
|
204
|
+
let elapsed = CACurrentMediaTime() - start
|
|
205
|
+
captureCost = captureCost == 0
|
|
206
|
+
? elapsed
|
|
207
|
+
: captureCost + (elapsed - captureCost) * Tuning.costSmoothing
|
|
208
|
+
|
|
209
|
+
updateStride(frameDuration: frameDuration)
|
|
210
|
+
recordDebug(cost: elapsed, region: target, now: start)
|
|
211
|
+
return true
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
private func updateStride(frameDuration: CFTimeInterval) {
|
|
215
|
+
let frame = frameDuration > 0 ? frameDuration : 1.0 / 60.0
|
|
216
|
+
let budget = frame * Tuning.dutyCycle
|
|
217
|
+
guard budget > 0, captureCost > 0 else { return }
|
|
218
|
+
|
|
219
|
+
let needed = Int((captureCost / budget).rounded(.up))
|
|
220
|
+
let target = min(max(needed, 1), Tuning.maxStride)
|
|
221
|
+
|
|
222
|
+
guard target != strideFrames else {
|
|
223
|
+
candidateStride = strideFrames
|
|
224
|
+
candidateStrideAge = 0
|
|
225
|
+
return
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if candidateStride != target {
|
|
229
|
+
candidateStride = target
|
|
230
|
+
candidateStrideAge = 0
|
|
231
|
+
return
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
candidateStrideAge += 1
|
|
235
|
+
guard candidateStrideAge >= Tuning.strideHysteresisFrames else { return }
|
|
236
|
+
|
|
237
|
+
strideFrames = target
|
|
238
|
+
candidateStrideAge = 0
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
private func digest(of slot: Slot, width: Int, height: Int) -> UInt64 {
|
|
242
|
+
guard width > 0, height > 0, let base = slot.bufferContents else { return 0 }
|
|
243
|
+
|
|
244
|
+
let rowWords = slot.bytesPerRow / 4
|
|
245
|
+
let cols = min(width, rowWords)
|
|
246
|
+
let rows = min(height, slot.pixelSize.height)
|
|
247
|
+
let total = cols * rows
|
|
248
|
+
guard total > 0 else { return 0 }
|
|
249
|
+
|
|
250
|
+
let pixels = base.assumingMemoryBound(to: UInt32.self)
|
|
251
|
+
var hash: UInt64 = 0xcbf29ce484222325
|
|
252
|
+
var index = 0
|
|
253
|
+
while index < total {
|
|
254
|
+
let row = index / cols
|
|
255
|
+
hash = (hash ^ UInt64(pixels[row * rowWords + (index - row * cols)])) &* 0x100000001b3
|
|
256
|
+
index += Tuning.digestStride
|
|
257
|
+
}
|
|
258
|
+
return hash
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
private func rasterise(window: UIWindow, region: CGRect) -> Bool {
|
|
262
|
+
|
|
263
|
+
let area = max(region.width * region.height, 1)
|
|
264
|
+
let ceiling = (Tuning.maxCapturePixels / area).squareRoot()
|
|
265
|
+
let pinned = max(((min(requestedScale, ceiling)) * 4).rounded(.down) / 4, 1.0)
|
|
266
|
+
if pinned != textureScale {
|
|
267
|
+
textureScale = pinned
|
|
268
|
+
slots.removeAll()
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
let scale = textureScale
|
|
272
|
+
let origin = CGPoint(
|
|
273
|
+
x: (region.minX * scale).rounded(.down) / scale,
|
|
274
|
+
y: (region.minY * scale).rounded(.down) / scale
|
|
275
|
+
)
|
|
276
|
+
let size = CGSize(
|
|
277
|
+
width: region.maxX - origin.x,
|
|
278
|
+
height: region.maxY - origin.y
|
|
279
|
+
)
|
|
280
|
+
|
|
281
|
+
guard prepareSlots(for: size) else { return false }
|
|
282
|
+
|
|
283
|
+
slotIndex = (slotIndex + 1) % slots.count
|
|
284
|
+
let slot = slots[slotIndex]
|
|
285
|
+
let context = slot.context
|
|
286
|
+
|
|
287
|
+
capturedOrigin = origin
|
|
288
|
+
textureSizePoints = CGSize(
|
|
289
|
+
width: CGFloat(slot.pixelSize.width) / scale,
|
|
290
|
+
height: CGFloat(slot.pixelSize.height) / scale
|
|
291
|
+
)
|
|
292
|
+
|
|
293
|
+
context.saveGState()
|
|
294
|
+
|
|
295
|
+
context.interpolationQuality = .high
|
|
296
|
+
context.setShouldAntialias(true)
|
|
297
|
+
context.setShouldSubpixelPositionFonts(true)
|
|
298
|
+
context.setShouldSubpixelQuantizeFonts(false)
|
|
299
|
+
|
|
300
|
+
context.setShouldSmoothFonts(false)
|
|
301
|
+
|
|
302
|
+
context.translateBy(x: 0, y: CGFloat(slot.pixelSize.height))
|
|
303
|
+
context.scaleBy(x: scale, y: -scale)
|
|
304
|
+
context.translateBy(x: -origin.x, y: -origin.y)
|
|
305
|
+
|
|
306
|
+
let regionRect = CGRect(origin: origin, size: size)
|
|
307
|
+
context.clip(to: regionRect)
|
|
308
|
+
context.clear(regionRect)
|
|
309
|
+
|
|
310
|
+
let regionPixelWidth = max(Int(size.width * scale), 1)
|
|
311
|
+
let regionPixelHeight = max(Int(size.height * scale), 1)
|
|
312
|
+
capturedPixelCount = regionPixelWidth * regionPixelHeight
|
|
313
|
+
|
|
314
|
+
drawTree(window: window, region: regionRect, context: context)
|
|
315
|
+
|
|
316
|
+
context.restoreGState()
|
|
317
|
+
|
|
318
|
+
if let uploadSource = slot.uploadSource {
|
|
319
|
+
slot.texture.replace(
|
|
320
|
+
region: MTLRegionMake2D(0, 0, slot.pixelSize.width, slot.pixelSize.height),
|
|
321
|
+
mipmapLevel: 0,
|
|
322
|
+
withBytes: uploadSource,
|
|
323
|
+
bytesPerRow: slot.bytesPerRow
|
|
324
|
+
)
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
if strategy == .layerRender,
|
|
328
|
+
isEmpty(slot, width: regionPixelWidth, height: regionPixelHeight) {
|
|
329
|
+
emptyCaptures += 1
|
|
330
|
+
if emptyCaptures >= Tuning.emptyCapturesBeforeSwitch {
|
|
331
|
+
strategy = .compositedDraw
|
|
332
|
+
emptyCaptures = 0
|
|
333
|
+
NSLog(
|
|
334
|
+
"[LiquidGlass] CALayer.render(in:) returns nothing for this "
|
|
335
|
+
+ "window — switching the backdrop capture to composited "
|
|
336
|
+
+ "snapshots. Seen on iOS 26 and up, and on any window "
|
|
337
|
+
+ "whose blank capture is opaque rather than clear."
|
|
338
|
+
)
|
|
339
|
+
}
|
|
340
|
+
} else {
|
|
341
|
+
emptyCaptures = 0
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
let current = digest(of: slot, width: regionPixelWidth, height: regionPixelHeight)
|
|
345
|
+
staleCaptures = current == lastDigest ? staleCaptures + 1 : 0
|
|
346
|
+
lastDigest = current
|
|
347
|
+
|
|
348
|
+
texture = slot.texture
|
|
349
|
+
return true
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
private func isEmpty(_ slot: Slot, width: Int, height: Int) -> Bool {
|
|
353
|
+
guard let base = slot.bufferContents, width > 8, height > 8 else { return false }
|
|
354
|
+
|
|
355
|
+
let rowWords = slot.bytesPerRow / 4
|
|
356
|
+
let columns = min(width, rowWords)
|
|
357
|
+
let pixels = base.assumingMemoryBound(to: UInt32.self)
|
|
358
|
+
let first = pixels[0]
|
|
359
|
+
|
|
360
|
+
for row in 0..<8 {
|
|
361
|
+
let y = height * row / 8
|
|
362
|
+
for column in 0..<8 where pixels[y * rowWords + columns * column / 8] != first {
|
|
363
|
+
return false
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// Every sampled pixel matched, so the capture carries no detail at all.
|
|
368
|
+
// That is the signal worth acting on, whatever colour it happens to be.
|
|
369
|
+
//
|
|
370
|
+
// This used to additionally require the uniform colour to be either
|
|
371
|
+
// fully transparent or pure black, which quietly made the recovery
|
|
372
|
+
// light-theme-blind: an app whose window renders cream or white gets a
|
|
373
|
+
// uniform OPAQUE capture when CALayer.render(in:) comes back with
|
|
374
|
+
// nothing, `isEmpty` answered false, the counter never reached
|
|
375
|
+
// emptyCapturesBeforeSwitch, and the strategy never moved to
|
|
376
|
+
// compositedDraw. The glass then refracts a flat field forever — which
|
|
377
|
+
// against a light background is indistinguishable from no glass at all.
|
|
378
|
+
// Dark-themed apps hit the black branch and recovered, so this only
|
|
379
|
+
// ever showed up on light ones.
|
|
380
|
+
//
|
|
381
|
+
// A genuinely flat screen is now also read as empty, and the switch
|
|
382
|
+
// is one-way for the capturer's lifetime — there is no path back to
|
|
383
|
+
// layerRender. So the cost of being wrong here is compositedDraw's
|
|
384
|
+
// slower capture, permanently, on a window that might not have needed
|
|
385
|
+
// it; the cost of being right is a glass surface that is visible at
|
|
386
|
+
// all. It takes emptyCapturesBeforeSwitch consecutive flat frames, so
|
|
387
|
+
// a single splash or transition frame will not trip it.
|
|
388
|
+
return true
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/// The capture walks the window's view tree itself, in paint order, and draws every
|
|
392
|
+
/// glass-free subtree as one leaf — `CALayer.render(in:)` under `.layerRender`, a
|
|
393
|
+
/// `drawHierarchy` snapshot under `.compositedDraw`. Walking, instead of rendering the window
|
|
394
|
+
/// in one call, is what makes the backdrop *what lies beneath* each glass: the moment the walk
|
|
395
|
+
/// passes a Metal glass view, that view's padded rect becomes a hole in everything painted
|
|
396
|
+
/// after it.
|
|
397
|
+
///
|
|
398
|
+
/// The kit's controls all draw their content as siblings over the pane — the tab bar's icon
|
|
399
|
+
/// row, a button's label, a chat header's photo overhanging its name pill — and a whole-window
|
|
400
|
+
/// render carried every one of them into the very backdrop the pane refracts. The edge lens
|
|
401
|
+
/// only ever samples inward, so at the top and bottom rims it pulled the glyphs into the band
|
|
402
|
+
/// as vertical streaks of their own colour (iPhone 14 Pro Max, iOS 26, 2026-09-08). Android
|
|
403
|
+
/// never had the problem: a provider records only what sits under the glass. This is that
|
|
404
|
+
/// rule on iOS.
|
|
405
|
+
///
|
|
406
|
+
/// One texture serves every glass, so where two panes overlap the hole is a compromise: a
|
|
407
|
+
/// glass painted over another loses whatever was painted between them inside the lower
|
|
408
|
+
/// pane's padded rect. That is the tab pill over its bar, and there it is the right answer —
|
|
409
|
+
/// the pill's cutout draws the row it needs on top.
|
|
410
|
+
private func drawTree(window: UIWindow, region: CGRect, context: CGContext) {
|
|
411
|
+
excludedViews.removeAll(keepingCapacity: true)
|
|
412
|
+
holes.removeAll(keepingCapacity: true)
|
|
413
|
+
defer {
|
|
414
|
+
excludedViews.removeAll(keepingCapacity: true)
|
|
415
|
+
holes.removeAll(keepingCapacity: true)
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
collectExcludedViews(in: window)
|
|
419
|
+
|
|
420
|
+
// `drawHierarchy` draws into UIKit's current context; `render(in:)` takes the CGContext
|
|
421
|
+
// and ignores this.
|
|
422
|
+
UIGraphicsPushContext(context)
|
|
423
|
+
defer { UIGraphicsPopContext() }
|
|
424
|
+
|
|
425
|
+
drawSubviews(of: window, window: window, region: region, context: context, holesApplied: 0)
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
private var excludedViews: [UIView] = []
|
|
429
|
+
|
|
430
|
+
/// The padded window rects of the Metal glass views the walk has passed so far, in paint
|
|
431
|
+
/// order. Append-only within a capture: a subtree records how many it has already clipped
|
|
432
|
+
/// out, and each child clips only the rest.
|
|
433
|
+
private var holes: [CGRect] = []
|
|
434
|
+
|
|
435
|
+
private func collectExcludedViews(in view: UIView) {
|
|
436
|
+
for subview in view.subviews {
|
|
437
|
+
if let layer = subview.layer as? NonRenderableLayer, layer.isExcludedFromBackdrop {
|
|
438
|
+
excludedViews.append(subview)
|
|
439
|
+
continue
|
|
440
|
+
}
|
|
441
|
+
collectExcludedViews(in: subview)
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
private func leadsToExcludedView(_ view: UIView) -> Bool {
|
|
446
|
+
excludedViews.contains { $0.isDescendant(of: view) }
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
private func drawSubviews(
|
|
450
|
+
of parent: UIView,
|
|
451
|
+
window: UIWindow,
|
|
452
|
+
region: CGRect,
|
|
453
|
+
context: CGContext,
|
|
454
|
+
holesApplied: Int
|
|
455
|
+
) {
|
|
456
|
+
for subview in parent.subviews {
|
|
457
|
+
guard !subview.isHidden, subview.alpha > 0.01 else { continue }
|
|
458
|
+
|
|
459
|
+
let frame = subview.convert(subview.bounds, to: window)
|
|
460
|
+
|
|
461
|
+
if excludedViews.contains(subview) {
|
|
462
|
+
// A Metal glass. Its own pixels never enter the capture, and from here on nothing
|
|
463
|
+
// painted over it may either: its padded rect — the reach of its blur and
|
|
464
|
+
// dispersion, `GlassSurfaceView.glassBackdropPadding` — is a hole in everything
|
|
465
|
+
// that follows.
|
|
466
|
+
let padding = (subview.layer as? NonRenderableLayer)?.backdropHolePadding ?? 0
|
|
467
|
+
let hole = frame.insetBy(dx: -padding, dy: -padding)
|
|
468
|
+
if hole.intersects(region) { holes.append(hole) }
|
|
469
|
+
continue
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
let leadsToGlass = leadsToExcludedView(subview)
|
|
473
|
+
|
|
474
|
+
if subview.clipsToBounds, !frame.intersects(region), !leadsToGlass { continue }
|
|
475
|
+
|
|
476
|
+
context.saveGState()
|
|
477
|
+
defer { context.restoreGState() }
|
|
478
|
+
|
|
479
|
+
if subview.alpha < 1 { context.setAlpha(subview.alpha) }
|
|
480
|
+
|
|
481
|
+
// A view that clips can only paint inside its frame, so holes clear of it are
|
|
482
|
+
// skipped; one that does not may paint children anywhere, and takes them all.
|
|
483
|
+
clipOutHoles(
|
|
484
|
+
from: holesApplied,
|
|
485
|
+
around: subview.clipsToBounds ? frame : nil,
|
|
486
|
+
context: context
|
|
487
|
+
)
|
|
488
|
+
let applied = holes.count
|
|
489
|
+
|
|
490
|
+
// Wholly inside the holes: the snapshot would be taken and thrown away.
|
|
491
|
+
guard !context.boundingBoxOfClipPath.isEmpty else { continue }
|
|
492
|
+
|
|
493
|
+
guard leadsToGlass else {
|
|
494
|
+
drawLeaf(subview, frame: frame, window: window, region: region, context: context)
|
|
495
|
+
continue
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
// A container on the way to a glass: its own fill, then its children one by one.
|
|
499
|
+
// Uniform corners are honoured — Fabric keeps those on the view's layer; a
|
|
500
|
+
// non-uniform radius lives in a background sublayer this walk does not see.
|
|
501
|
+
let radius = subview.layer.cornerRadius
|
|
502
|
+
let outline = radius > 0
|
|
503
|
+
? UIBezierPath(roundedRect: frame, cornerRadius: radius).cgPath
|
|
504
|
+
: CGPath(rect: frame, transform: nil)
|
|
505
|
+
|
|
506
|
+
if subview.clipsToBounds {
|
|
507
|
+
context.beginPath()
|
|
508
|
+
context.addPath(outline)
|
|
509
|
+
context.clip()
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
if let background = subview.backgroundColor?.cgColor, background.alpha > 0 {
|
|
513
|
+
context.setFillColor(background)
|
|
514
|
+
context.beginPath()
|
|
515
|
+
context.addPath(outline)
|
|
516
|
+
context.fillPath()
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
drawSubviews(
|
|
520
|
+
of: subview, window: window, region: region, context: context,
|
|
521
|
+
holesApplied: applied
|
|
522
|
+
)
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
/// Clips the current state to exclude `holes[start...]`. Each hole goes on as the even-odd
|
|
527
|
+
/// difference of the clip's own bounding box and the hole's rect, and successive clips
|
|
528
|
+
/// intersect — so overlapping holes (a pill inside its bar) cut correctly, where a single
|
|
529
|
+
/// even-odd path over all of them would let the overlap back in. `around` is the drawing
|
|
530
|
+
/// view's frame when it clips to bounds, letting holes clear of it be skipped.
|
|
531
|
+
private func clipOutHoles(from start: Int, around frame: CGRect?, context: CGContext) {
|
|
532
|
+
guard start < holes.count else { return }
|
|
533
|
+
for hole in holes[start...] {
|
|
534
|
+
if let frame, !hole.intersects(frame) { continue }
|
|
535
|
+
let everything = context.boundingBoxOfClipPath
|
|
536
|
+
guard everything.intersects(hole) else { continue }
|
|
537
|
+
context.beginPath()
|
|
538
|
+
context.addRect(everything)
|
|
539
|
+
context.addRect(hole)
|
|
540
|
+
context.clip(using: .evenOdd)
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
/// One glass-free subtree, drawn whole. `.compositedDraw` takes the window server's snapshot
|
|
545
|
+
/// of it. `.layerRender` renders the layer tree, mapped so the view's bounds land on its
|
|
546
|
+
/// window frame — a scroll view carries its offset in `bounds.origin`, which `render(in:)`
|
|
547
|
+
/// does not apply for the layer it is called on — and then overdraws any SwiftUI hosting
|
|
548
|
+
/// views inside, which `render(in:)` leaves blank.
|
|
549
|
+
private func drawLeaf(
|
|
550
|
+
_ view: UIView,
|
|
551
|
+
frame: CGRect,
|
|
552
|
+
window: UIWindow,
|
|
553
|
+
region: CGRect,
|
|
554
|
+
context: CGContext
|
|
555
|
+
) {
|
|
556
|
+
switch strategy {
|
|
557
|
+
case .compositedDraw:
|
|
558
|
+
view.drawHierarchy(in: frame, afterScreenUpdates: false)
|
|
559
|
+
|
|
560
|
+
case .layerRender:
|
|
561
|
+
let bounds = view.bounds
|
|
562
|
+
guard bounds.width > 0, bounds.height > 0 else { return }
|
|
563
|
+
|
|
564
|
+
context.saveGState()
|
|
565
|
+
context.translateBy(x: frame.minX, y: frame.minY)
|
|
566
|
+
context.scaleBy(x: frame.width / bounds.width, y: frame.height / bounds.height)
|
|
567
|
+
context.translateBy(x: -bounds.minX, y: -bounds.minY)
|
|
568
|
+
NonRenderableLayer.isCapturingBackdrop = true
|
|
569
|
+
view.layer.render(in: context)
|
|
570
|
+
NonRenderableLayer.isCapturingBackdrop = false
|
|
571
|
+
context.restoreGState()
|
|
572
|
+
|
|
573
|
+
overdrawHostedViews(in: view, window: window, region: region)
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
/// The SwiftUI hosting views inside a `.layerRender` leaf, snapshotted over the layer render.
|
|
578
|
+
/// Walks only the leaf, which by construction holds no glass.
|
|
579
|
+
private func overdrawHostedViews(in root: UIView, window: UIWindow, region: CGRect) {
|
|
580
|
+
for subview in root.subviews {
|
|
581
|
+
guard !subview.isHidden, subview.alpha > 0.01 else { continue }
|
|
582
|
+
|
|
583
|
+
if isHostingView(subview) {
|
|
584
|
+
let frame = subview.convert(subview.bounds, to: window)
|
|
585
|
+
if frame.intersects(region), !frame.isEmpty {
|
|
586
|
+
subview.drawHierarchy(in: frame, afterScreenUpdates: false)
|
|
587
|
+
}
|
|
588
|
+
continue
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
overdrawHostedViews(in: subview, window: window, region: region)
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
private var hostingClasses: [ObjectIdentifier: Bool] = [:]
|
|
596
|
+
|
|
597
|
+
private func isHostingView(_ view: UIView) -> Bool {
|
|
598
|
+
let type = type(of: view)
|
|
599
|
+
let key = ObjectIdentifier(type)
|
|
600
|
+
if let known = hostingClasses[key] { return known }
|
|
601
|
+
|
|
602
|
+
let isHosting = String(describing: type).contains("HostingView")
|
|
603
|
+
hostingClasses[key] = isHosting
|
|
604
|
+
return isHosting
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
private func prepareSlots(for size: CGSize) -> Bool {
|
|
608
|
+
guard let context = GlassRenderContext.shared else { return false }
|
|
609
|
+
|
|
610
|
+
func bucketed(_ value: CGFloat) -> Int {
|
|
611
|
+
let pixels = max(Int((value * textureScale).rounded(.up)), 1)
|
|
612
|
+
let bucket = Tuning.allocationBucket
|
|
613
|
+
return ((pixels + bucket - 1) / bucket) * bucket
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
let requested = (width: bucketed(size.width), height: bucketed(size.height))
|
|
617
|
+
|
|
618
|
+
if let current = slots.first?.pixelSize {
|
|
619
|
+
let fits = requested.width <= current.width && requested.height <= current.height
|
|
620
|
+
let wastes = requested.width * 2 <= current.width || requested.height * 2 <= current.height
|
|
621
|
+
|
|
622
|
+
if fits, !wastes {
|
|
623
|
+
smallerSizeSince = nil
|
|
624
|
+
return true
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
if fits {
|
|
628
|
+
let now = CACurrentMediaTime()
|
|
629
|
+
let since = smallerSizeSince ?? now
|
|
630
|
+
smallerSizeSince = since
|
|
631
|
+
if now - since < Tuning.shrinkDelay { return true }
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
smallerSizeSince = nil
|
|
636
|
+
|
|
637
|
+
let device = context.device
|
|
638
|
+
let alignment = context.linearTextureAlignment
|
|
639
|
+
let width = requested.width
|
|
640
|
+
let height = requested.height
|
|
641
|
+
let bytesPerRow = ((width * 4 + alignment - 1) / alignment) * alignment
|
|
642
|
+
|
|
643
|
+
var built: [Slot] = []
|
|
644
|
+
built.reserveCapacity(2)
|
|
645
|
+
|
|
646
|
+
for index in 0..<2 {
|
|
647
|
+
guard let slot = makeSlot(
|
|
648
|
+
device: device,
|
|
649
|
+
index: index,
|
|
650
|
+
width: width,
|
|
651
|
+
height: height,
|
|
652
|
+
bytesPerRow: bytesPerRow
|
|
653
|
+
) else { return false }
|
|
654
|
+
built.append(slot)
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
slots = built
|
|
658
|
+
slotIndex = 0
|
|
659
|
+
texture = nil
|
|
660
|
+
return true
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
private func makeSlot(
|
|
664
|
+
device: MTLDevice,
|
|
665
|
+
index: Int,
|
|
666
|
+
width: Int,
|
|
667
|
+
height: Int,
|
|
668
|
+
bytesPerRow: Int
|
|
669
|
+
) -> Slot? {
|
|
670
|
+
let descriptor = MTLTextureDescriptor.texture2DDescriptor(
|
|
671
|
+
pixelFormat: .bgra8Unorm,
|
|
672
|
+
width: width,
|
|
673
|
+
height: height,
|
|
674
|
+
mipmapped: false
|
|
675
|
+
)
|
|
676
|
+
descriptor.usage = .shaderRead
|
|
677
|
+
descriptor.storageMode = .shared
|
|
678
|
+
|
|
679
|
+
let bitmapInfo = CGImageAlphaInfo.premultipliedFirst.rawValue
|
|
680
|
+
| CGBitmapInfo.byteOrder32Little.rawValue
|
|
681
|
+
|
|
682
|
+
#if !targetEnvironment(simulator)
|
|
683
|
+
|
|
684
|
+
if let buffer = device.makeBuffer(
|
|
685
|
+
length: bytesPerRow * height,
|
|
686
|
+
options: .storageModeShared
|
|
687
|
+
) {
|
|
688
|
+
buffer.label = "GlassBackdrop\(index)"
|
|
689
|
+
|
|
690
|
+
if let texture = buffer.makeTexture(
|
|
691
|
+
descriptor: descriptor,
|
|
692
|
+
offset: 0,
|
|
693
|
+
bytesPerRow: bytesPerRow
|
|
694
|
+
), let cgContext = CGContext(
|
|
695
|
+
data: buffer.contents(),
|
|
696
|
+
width: width,
|
|
697
|
+
height: height,
|
|
698
|
+
bitsPerComponent: 8,
|
|
699
|
+
bytesPerRow: bytesPerRow,
|
|
700
|
+
space: CGColorSpaceCreateDeviceRGB(),
|
|
701
|
+
bitmapInfo: bitmapInfo
|
|
702
|
+
) {
|
|
703
|
+
texture.label = "GlassBackdrop\(index)"
|
|
704
|
+
return Slot(
|
|
705
|
+
texture: texture,
|
|
706
|
+
context: cgContext,
|
|
707
|
+
pixelSize: (width, height),
|
|
708
|
+
bytesPerRow: bytesPerRow,
|
|
709
|
+
buffer: buffer,
|
|
710
|
+
ownedMemory: nil
|
|
711
|
+
)
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
#endif
|
|
715
|
+
|
|
716
|
+
guard let texture = device.makeTexture(descriptor: descriptor) else { return nil }
|
|
717
|
+
texture.label = "GlassBackdrop\(index)"
|
|
718
|
+
|
|
719
|
+
let memory = UnsafeMutableRawPointer.allocate(
|
|
720
|
+
byteCount: bytesPerRow * height,
|
|
721
|
+
alignment: MemoryLayout<UInt32>.alignment
|
|
722
|
+
)
|
|
723
|
+
|
|
724
|
+
guard let cgContext = CGContext(
|
|
725
|
+
data: memory,
|
|
726
|
+
width: width,
|
|
727
|
+
height: height,
|
|
728
|
+
bitsPerComponent: 8,
|
|
729
|
+
bytesPerRow: bytesPerRow,
|
|
730
|
+
space: CGColorSpaceCreateDeviceRGB(),
|
|
731
|
+
bitmapInfo: bitmapInfo
|
|
732
|
+
) else {
|
|
733
|
+
memory.deallocate()
|
|
734
|
+
return nil
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
return Slot(
|
|
738
|
+
texture: texture,
|
|
739
|
+
context: cgContext,
|
|
740
|
+
pixelSize: (width, height),
|
|
741
|
+
bytesPerRow: bytesPerRow,
|
|
742
|
+
buffer: nil,
|
|
743
|
+
ownedMemory: memory
|
|
744
|
+
)
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
/// Mean luminance of the current capture inside `uvRect` (the same UV space the surfaces
|
|
748
|
+
/// sample), alpha-weighted, in the sRGB gamma space the shader's own luma uses — the
|
|
749
|
+
/// `adaptive` prop's sensor. Reads the CPU side of the slot that was last rasterised, which
|
|
750
|
+
/// is exactly what the GPU is sampling, so it costs no readback: a grid of at most
|
|
751
|
+
/// `luminanceGrid`² pixels is walked in place. Nil while there is no capture.
|
|
752
|
+
func meanLuminance(in uvRect: SIMD4<Float>) -> Float? {
|
|
753
|
+
guard !slots.isEmpty, texture != nil else { return nil }
|
|
754
|
+
let slot = slots[slotIndex]
|
|
755
|
+
guard let base = slot.bufferContents else { return nil }
|
|
756
|
+
|
|
757
|
+
let width = slot.pixelSize.width
|
|
758
|
+
let height = slot.pixelSize.height
|
|
759
|
+
let x0 = max(Int((CGFloat(uvRect.x) * CGFloat(width)).rounded(.down)), 0)
|
|
760
|
+
let y0 = max(Int((CGFloat(uvRect.y) * CGFloat(height)).rounded(.down)), 0)
|
|
761
|
+
let x1 = min(Int((CGFloat(uvRect.x + uvRect.z) * CGFloat(width)).rounded(.up)), width)
|
|
762
|
+
let y1 = min(Int((CGFloat(uvRect.y + uvRect.w) * CGFloat(height)).rounded(.up)), height)
|
|
763
|
+
guard x1 > x0, y1 > y0 else { return nil }
|
|
764
|
+
|
|
765
|
+
let stepX = max((x1 - x0) / Tuning.luminanceGrid, 1)
|
|
766
|
+
let stepY = max((y1 - y0) / Tuning.luminanceGrid, 1)
|
|
767
|
+
let rowWords = slot.bytesPerRow / 4
|
|
768
|
+
let pixels = base.assumingMemoryBound(to: UInt32.self)
|
|
769
|
+
|
|
770
|
+
var sum: Float = 0
|
|
771
|
+
var cover: Float = 0
|
|
772
|
+
var y = y0
|
|
773
|
+
while y < y1 {
|
|
774
|
+
var x = x0
|
|
775
|
+
while x < x1 {
|
|
776
|
+
// BGRA, little-endian, premultiplied: the packed word reads 0xAARRGGBB, and a
|
|
777
|
+
// premultiplied channel sum IS the alpha-weighted sum.
|
|
778
|
+
let word = pixels[y * rowWords + x]
|
|
779
|
+
let b = Float(word & 0xFF)
|
|
780
|
+
let g = Float((word >> 8) & 0xFF)
|
|
781
|
+
let r = Float((word >> 16) & 0xFF)
|
|
782
|
+
let a = Float((word >> 24) & 0xFF)
|
|
783
|
+
sum += (0.2126 * r + 0.7152 * g + 0.0722 * b) / 255
|
|
784
|
+
cover += a / 255
|
|
785
|
+
x += stepX
|
|
786
|
+
}
|
|
787
|
+
y += stepY
|
|
788
|
+
}
|
|
789
|
+
guard cover > 1e-3 else { return 0.5 }
|
|
790
|
+
return min(max(sum / cover, 0), 1)
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
func releaseResources() {
|
|
794
|
+
slots.removeAll()
|
|
795
|
+
texture = nil
|
|
796
|
+
emptyCaptures = 0
|
|
797
|
+
textureSizePoints = .zero
|
|
798
|
+
captureCost = 0
|
|
799
|
+
capturedPixelCount = 0
|
|
800
|
+
lastDigest = 0
|
|
801
|
+
staleCaptures = 0
|
|
802
|
+
lastRegion = .null
|
|
803
|
+
capturedRegion = .null
|
|
804
|
+
lastMovementTime = -.greatestFiniteMagnitude
|
|
805
|
+
strideFrames = 1
|
|
806
|
+
candidateStride = 1
|
|
807
|
+
candidateStrideAge = 0
|
|
808
|
+
smallerSizeSince = nil
|
|
809
|
+
textureScale = requestedScale
|
|
810
|
+
}
|
|
811
|
+
}
|