@react-native-ohos/react-native-svg 15.12.1-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.OpenSource +11 -0
- package/README.md +13 -0
- package/css/package.json +6 -0
- package/harmony/svg/BuildProfile.ets +17 -0
- package/harmony/svg/build-profile.json5 +9 -0
- package/harmony/svg/hvigorfile.ts +2 -0
- package/harmony/svg/index.ets +7 -0
- package/harmony/svg/oh-package.json5 +13 -0
- package/harmony/svg/src/main/cpp/Attribute.h +52 -0
- package/harmony/svg/src/main/cpp/CMakeLists.txt +32 -0
- package/harmony/svg/src/main/cpp/FallbackProps.h +0 -0
- package/harmony/svg/src/main/cpp/FontHolderBase.cpp +22 -0
- package/harmony/svg/src/main/cpp/FontHolderBase.h +54 -0
- package/harmony/svg/src/main/cpp/SVGPackage.cpp +135 -0
- package/harmony/svg/src/main/cpp/SVGPackage.h +153 -0
- package/harmony/svg/src/main/cpp/SvgArkUINode.cpp +75 -0
- package/harmony/svg/src/main/cpp/SvgArkUINode.h +45 -0
- package/harmony/svg/src/main/cpp/SvgBaseAttribute.h +83 -0
- package/harmony/svg/src/main/cpp/SvgCircle.cpp +29 -0
- package/harmony/svg/src/main/cpp/SvgCircle.h +29 -0
- package/harmony/svg/src/main/cpp/SvgClipPath.h +22 -0
- package/harmony/svg/src/main/cpp/SvgContext.cpp +56 -0
- package/harmony/svg/src/main/cpp/SvgContext.h +71 -0
- package/harmony/svg/src/main/cpp/SvgDefs.h +46 -0
- package/harmony/svg/src/main/cpp/SvgEllipse.cpp +32 -0
- package/harmony/svg/src/main/cpp/SvgEllipse.h +34 -0
- package/harmony/svg/src/main/cpp/SvgFilter.cpp +505 -0
- package/harmony/svg/src/main/cpp/SvgFilter.h +112 -0
- package/harmony/svg/src/main/cpp/SvgGradient.cpp +116 -0
- package/harmony/svg/src/main/cpp/SvgGradient.h +49 -0
- package/harmony/svg/src/main/cpp/SvgGraphic.cpp +553 -0
- package/harmony/svg/src/main/cpp/SvgGraphic.h +77 -0
- package/harmony/svg/src/main/cpp/SvgGroup.cpp +86 -0
- package/harmony/svg/src/main/cpp/SvgGroup.h +41 -0
- package/harmony/svg/src/main/cpp/SvgHost.cpp +27 -0
- package/harmony/svg/src/main/cpp/SvgHost.h +38 -0
- package/harmony/svg/src/main/cpp/SvgImage.cpp +168 -0
- package/harmony/svg/src/main/cpp/SvgImage.h +52 -0
- package/harmony/svg/src/main/cpp/SvgLine.cpp +28 -0
- package/harmony/svg/src/main/cpp/SvgLine.h +32 -0
- package/harmony/svg/src/main/cpp/SvgMarker.cpp +61 -0
- package/harmony/svg/src/main/cpp/SvgMarker.h +86 -0
- package/harmony/svg/src/main/cpp/SvgMask.cpp +72 -0
- package/harmony/svg/src/main/cpp/SvgMask.h +68 -0
- package/harmony/svg/src/main/cpp/SvgNode.cpp +289 -0
- package/harmony/svg/src/main/cpp/SvgNode.h +347 -0
- package/harmony/svg/src/main/cpp/SvgPath.cpp +42 -0
- package/harmony/svg/src/main/cpp/SvgPath.h +29 -0
- package/harmony/svg/src/main/cpp/SvgPattern.cpp +77 -0
- package/harmony/svg/src/main/cpp/SvgPattern.h +64 -0
- package/harmony/svg/src/main/cpp/SvgQuote.h +87 -0
- package/harmony/svg/src/main/cpp/SvgRect.cpp +58 -0
- package/harmony/svg/src/main/cpp/SvgRect.h +33 -0
- package/harmony/svg/src/main/cpp/SvgSvg.cpp +83 -0
- package/harmony/svg/src/main/cpp/SvgSvg.h +52 -0
- package/harmony/svg/src/main/cpp/SvgSymbol.cpp +25 -0
- package/harmony/svg/src/main/cpp/SvgSymbol.h +37 -0
- package/harmony/svg/src/main/cpp/SvgTSpan.cpp +501 -0
- package/harmony/svg/src/main/cpp/SvgTSpan.h +101 -0
- package/harmony/svg/src/main/cpp/SvgText.cpp +48 -0
- package/harmony/svg/src/main/cpp/SvgText.h +29 -0
- package/harmony/svg/src/main/cpp/SvgTextPath.cpp +35 -0
- package/harmony/svg/src/main/cpp/SvgTextPath.h +51 -0
- package/harmony/svg/src/main/cpp/SvgUse.cpp +65 -0
- package/harmony/svg/src/main/cpp/SvgUse.h +46 -0
- package/harmony/svg/src/main/cpp/SvgViewManager.cpp +36 -0
- package/harmony/svg/src/main/cpp/SvgViewManager.h +37 -0
- package/harmony/svg/src/main/cpp/TextBase.cpp +20 -0
- package/harmony/svg/src/main/cpp/TextBase.h +114 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGBaseComponentInstance.h +212 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGCircleComponentInstance.cpp +31 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGCircleComponentInstance.h +27 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGClipPathComponentInstance.cpp +23 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGClipPathComponentInstance.h +27 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGDefsComponentInstance.cpp +23 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGDefsComponentInstance.h +28 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGEllipseComponentInstance.cpp +27 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGEllipseComponentInstance.h +27 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGFeBlendComponentInstance.cpp +40 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGFeBlendComponentInstance.h +48 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGFeColorMatrixComponentInstance.cpp +33 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGFeColorMatrixComponentInstance.h +48 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGFeCompositeComponentInstance.cpp +39 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGFeCompositeComponentInstance.h +55 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGFeFloodComponentInstance.cpp +33 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGFeFloodComponentInstance.h +49 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGFeGaussianBlurComponentInstance.cpp +34 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGFeGaussianBlurComponentInstance.h +48 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGFeOffsetComponentInstance.cpp +35 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGFeOffsetComponentInstance.h +46 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGFilterComponentInstance.cpp +199 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGFilterComponentInstance.h +48 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGGroupComponentInstance.cpp +32 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGGroupComponentInstance.h +27 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGImageComponentInstance.cpp +100 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGImageComponentInstance.h +43 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGLineComponentInstance.cpp +27 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGLineComponentInstance.h +27 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGLinearGradientComponentInstance.cpp +30 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGLinearGradientComponentInstance.h +28 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGMarkerComponentInstance.cpp +35 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGMarkerComponentInstance.h +27 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGMaskComponentInstance.cpp +30 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGMaskComponentInstance.h +27 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGPathComponentInstance.cpp +33 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGPathComponentInstance.h +29 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGPatternComponentInstance.cpp +40 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGPatternComponentInstance.h +27 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGRadialGradientComponentInstance.cpp +32 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGRadialGradientComponentInstance.h +28 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGRectComponentInstance.cpp +36 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGRectComponentInstance.h +27 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGSvgViewComponentInstance.cpp +86 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGSvgViewComponentInstance.h +47 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGSymbolComponentInstance.cpp +30 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGSymbolComponentInstance.h +27 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGTSpanComponentInstance.cpp +27 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGTSpanComponentInstance.h +27 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGTextComponentInstance.cpp +25 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGTextComponentInstance.h +27 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGTextPathComponentInstance.cpp +32 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGTextPathComponentInstance.h +27 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGUseComponentInstance.cpp +32 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGUseComponentInstance.h +32 -0
- package/harmony/svg/src/main/cpp/downloadUtils/HttpTaskProcessor.cpp +207 -0
- package/harmony/svg/src/main/cpp/downloadUtils/HttpTaskProcessor.h +88 -0
- package/harmony/svg/src/main/cpp/downloadUtils/ImageSourceResolver.cpp +106 -0
- package/harmony/svg/src/main/cpp/downloadUtils/ImageSourceResolver.h +97 -0
- package/harmony/svg/src/main/cpp/downloadUtils/LRUCache.h +98 -0
- package/harmony/svg/src/main/cpp/drawing/Brush.cpp +50 -0
- package/harmony/svg/src/main/cpp/drawing/Brush.h +52 -0
- package/harmony/svg/src/main/cpp/drawing/GlyPathBag.cpp +20 -0
- package/harmony/svg/src/main/cpp/drawing/GlyPathBag.h +31 -0
- package/harmony/svg/src/main/cpp/drawing/Matrix.cpp +100 -0
- package/harmony/svg/src/main/cpp/drawing/Matrix.h +68 -0
- package/harmony/svg/src/main/cpp/drawing/Path.cpp +173 -0
- package/harmony/svg/src/main/cpp/drawing/Path.h +127 -0
- package/harmony/svg/src/main/cpp/drawing/Pen.cpp +57 -0
- package/harmony/svg/src/main/cpp/drawing/Pen.h +59 -0
- package/harmony/svg/src/main/cpp/drawing/Rect.cpp +47 -0
- package/harmony/svg/src/main/cpp/drawing/Rect.h +56 -0
- package/harmony/svg/src/main/cpp/drawing/RoundRect.cpp +24 -0
- package/harmony/svg/src/main/cpp/drawing/RoundRect.h +39 -0
- package/harmony/svg/src/main/cpp/drawing/ShaderEffect.cpp +37 -0
- package/harmony/svg/src/main/cpp/drawing/ShaderEffect.h +51 -0
- package/harmony/svg/src/main/cpp/drawing/TextStyle.cpp +49 -0
- package/harmony/svg/src/main/cpp/drawing/TextStyle.h +41 -0
- package/harmony/svg/src/main/cpp/drawing/Typography.cpp +9 -0
- package/harmony/svg/src/main/cpp/drawing/Typography.h +25 -0
- package/harmony/svg/src/main/cpp/drawing/TypographyStyle.cpp +31 -0
- package/harmony/svg/src/main/cpp/drawing/TypographyStyle.h +41 -0
- package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGCircleJSIBinder.h +54 -0
- package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGClipPathJSIBinder.h +54 -0
- package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGDefsJSIBinder.h +38 -0
- package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGEllipseJSIBinder.h +55 -0
- package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGFeBlendJSIBinder.h +26 -0
- package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGFeColorMatrixJSIBinder.h +26 -0
- package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGFeCompositeJSIBinder.h +30 -0
- package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGFeFloodJSIBinder.h +26 -0
- package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGFeGaussianBlurJSIBinder.h +27 -0
- package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGFeOffsetJSIBinder.h +26 -0
- package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGFilterJSIBinder.h +44 -0
- package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGForeignObjectJSIBinder.h +57 -0
- package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGGroupJSIBinder.h +54 -0
- package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGImageJSIBinder.h +58 -0
- package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGLineJSIBinder.h +55 -0
- package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGLinearGradientJSIBinder.h +45 -0
- package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGMarkerJSIBinder.h +66 -0
- package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGMaskJSIBinder.h +60 -0
- package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGPathJSIBinder.h +52 -0
- package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGPatternJSIBinder.h +67 -0
- package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGRadialGradientJSIBinder.h +47 -0
- package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGRectJSIBinder.h +57 -0
- package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGSvgViewAndroidJSIBinder.h +67 -0
- package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGSvgViewJSIBinder.h +36 -0
- package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGSymbolJSIBinder.h +60 -0
- package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGTSpanJSIBinder.h +66 -0
- package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGTextJSIBinder.h +65 -0
- package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGTextPathJSIBinder.h +71 -0
- package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGUseJSIBinder.h +56 -0
- package/harmony/svg/src/main/cpp/generated/react/renderer/components/react_native_svg/ComponentDescriptors.h +48 -0
- package/harmony/svg/src/main/cpp/generated/react/renderer/components/react_native_svg/EventEmitters.cpp +20 -0
- package/harmony/svg/src/main/cpp/generated/react/renderer/components/react_native_svg/EventEmitters.h +253 -0
- package/harmony/svg/src/main/cpp/generated/react/renderer/components/react_native_svg/Props.cpp +977 -0
- package/harmony/svg/src/main/cpp/generated/react/renderer/components/react_native_svg/Props.h +1280 -0
- package/harmony/svg/src/main/cpp/generated/react/renderer/components/react_native_svg/ShadowNodes.cpp +45 -0
- package/harmony/svg/src/main/cpp/generated/react/renderer/components/react_native_svg/ShadowNodes.h +331 -0
- package/harmony/svg/src/main/cpp/generated/react/renderer/components/react_native_svg/States.cpp +18 -0
- package/harmony/svg/src/main/cpp/generated/react/renderer/components/react_native_svg/States.h +441 -0
- package/harmony/svg/src/main/cpp/properties/Color.cpp +458 -0
- package/harmony/svg/src/main/cpp/properties/Color.h +144 -0
- package/harmony/svg/src/main/cpp/properties/Decoration.cpp +41 -0
- package/harmony/svg/src/main/cpp/properties/Decoration.h +483 -0
- package/harmony/svg/src/main/cpp/properties/Dimension.cpp +64 -0
- package/harmony/svg/src/main/cpp/properties/Dimension.h +243 -0
- package/harmony/svg/src/main/cpp/properties/Font.cpp +166 -0
- package/harmony/svg/src/main/cpp/properties/Font.h +163 -0
- package/harmony/svg/src/main/cpp/properties/Offset.h +119 -0
- package/harmony/svg/src/main/cpp/properties/PaintState.h +240 -0
- package/harmony/svg/src/main/cpp/properties/Rect.h +423 -0
- package/harmony/svg/src/main/cpp/properties/Size.h +246 -0
- package/harmony/svg/src/main/cpp/properties/SvgPaintState.h +452 -0
- package/harmony/svg/src/main/cpp/properties/TextProperties.cpp +91 -0
- package/harmony/svg/src/main/cpp/properties/TextProperties.h +56 -0
- package/harmony/svg/src/main/cpp/properties/ViewBox.h +108 -0
- package/harmony/svg/src/main/cpp/svgImage/RNSVGImageComponentDescriptor.h +41 -0
- package/harmony/svg/src/main/cpp/svgImage/RNSVGImageShadowNode.cpp +62 -0
- package/harmony/svg/src/main/cpp/svgImage/RNSVGImageShadowNode.h +63 -0
- package/harmony/svg/src/main/cpp/svgImage/RNSVGImageState.cpp +17 -0
- package/harmony/svg/src/main/cpp/svgImage/RNSVGImageState.h +58 -0
- package/harmony/svg/src/main/cpp/turboModules/RNSVGImageModule.cpp +54 -0
- package/harmony/svg/src/main/cpp/turboModules/RNSVGImageModule.h +32 -0
- package/harmony/svg/src/main/cpp/turboModules/RNSVGRenderableModule.cpp +101 -0
- package/harmony/svg/src/main/cpp/turboModules/RNSVGRenderableModule.h +32 -0
- package/harmony/svg/src/main/cpp/turboModules/RNSVGSvgViewModule.cpp +71 -0
- package/harmony/svg/src/main/cpp/turboModules/RNSVGSvgViewModule.h +32 -0
- package/harmony/svg/src/main/cpp/utils/DynamicUtils.h +55 -0
- package/harmony/svg/src/main/cpp/utils/FilterManager.h +190 -0
- package/harmony/svg/src/main/cpp/utils/GlyphContext.cpp +221 -0
- package/harmony/svg/src/main/cpp/utils/GlyphContext.h +106 -0
- package/harmony/svg/src/main/cpp/utils/LinearMap.h +69 -0
- package/harmony/svg/src/main/cpp/utils/PathParserUtils.cpp +591 -0
- package/harmony/svg/src/main/cpp/utils/PathParserUtils.h +93 -0
- package/harmony/svg/src/main/cpp/utils/StringUtils.cpp +134 -0
- package/harmony/svg/src/main/cpp/utils/StringUtils.h +644 -0
- package/harmony/svg/src/main/cpp/utils/SvgAttributesParser.cpp +239 -0
- package/harmony/svg/src/main/cpp/utils/SvgAttributesParser.h +277 -0
- package/harmony/svg/src/main/cpp/utils/SvgMarkerPositionUtils.h +200 -0
- package/harmony/svg/src/main/cpp/utils/SvgUtils.h +176 -0
- package/harmony/svg/src/main/cpp/utils/TextPathHelper.cpp +94 -0
- package/harmony/svg/src/main/cpp/utils/TextPathHelper.h +61 -0
- package/harmony/svg/src/main/ets/RNSVGImageModule.ts +21 -0
- package/harmony/svg/src/main/ets/RNSVGRenderableModule.ts +16 -0
- package/harmony/svg/src/main/ets/RNSVGSvgViewModule.ts +18 -0
- package/harmony/svg/src/main/ets/SvgPackage.ts +58 -0
- package/harmony/svg/src/main/module.json5 +7 -0
- package/harmony/svg/src/main/resources/base/element/string.json +8 -0
- package/harmony/svg/src/main/resources/en_US/element/string.json +8 -0
- package/harmony/svg/src/main/resources/zh_CN/element/string.json +8 -0
- package/harmony/svg/ts.ts +8 -0
- package/harmony/svg.har +0 -0
- package/lib/commonjs/css/index.js +55 -0
- package/lib/commonjs/css/index.js.map +1 -0
- package/lib/commonjs/index.js +26 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/module/css/index.js +4 -0
- package/lib/module/css/index.js.map +1 -0
- package/lib/module/index.js +3 -0
- package/lib/module/index.js.map +1 -0
- package/lib/typescript/babel.config.d.ts +8 -0
- package/lib/typescript/babel.config.d.ts.map +1 -0
- package/lib/typescript/example/babel.config.d.ts +3 -0
- package/lib/typescript/example/babel.config.d.ts.map +1 -0
- package/lib/typescript/example/contexts.d.ts +3 -0
- package/lib/typescript/example/contexts.d.ts.map +1 -0
- package/lib/typescript/example/harmony/entry/hvigorfile.d.ts +2 -0
- package/lib/typescript/example/harmony/entry/hvigorfile.d.ts.map +1 -0
- package/lib/typescript/example/harmony/hvigorfile.d.ts +2 -0
- package/lib/typescript/example/harmony/hvigorfile.d.ts.map +1 -0
- package/lib/typescript/example/index.d.ts +2 -0
- package/lib/typescript/example/index.d.ts.map +1 -0
- package/lib/typescript/example/jest.config.d.ts +3 -0
- package/lib/typescript/example/jest.config.d.ts.map +1 -0
- package/lib/typescript/example/metro.config.d.ts +3 -0
- package/lib/typescript/example/metro.config.d.ts.map +1 -0
- package/lib/typescript/example/react-native.config.d.ts +3 -0
- package/lib/typescript/example/react-native.config.d.ts.map +1 -0
- package/lib/typescript/example/scripts/create-build-profile.d.ts +2 -0
- package/lib/typescript/example/scripts/create-build-profile.d.ts.map +1 -0
- package/lib/typescript/example/src/index.d.ts +3 -0
- package/lib/typescript/example/src/index.d.ts.map +1 -0
- package/lib/typescript/src/css/index.d.ts +4 -0
- package/lib/typescript/src/css/index.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +3 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/package.json +54 -0
- package/src/css/index.tsx +20 -0
- package/src/index.tsx +3 -0
- package/tsconfig.json +12 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
|
|
3
|
+
* Use of this source code is governed by a MIT license that can be
|
|
4
|
+
* found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
#include "RNSVGUseComponentInstance.h"
|
|
8
|
+
#include "utils/DynamicUtils.h"
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
namespace rnoh {
|
|
12
|
+
namespace svg {
|
|
13
|
+
|
|
14
|
+
RNSVGUseComponentInstance::RNSVGUseComponentInstance(Context context) : RNSVGBaseComponentInstance(std::move(context)) {
|
|
15
|
+
SetSvgNode(m_svgUse);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
void RNSVGUseComponentInstance::UpdateElementProps() {
|
|
19
|
+
m_svgUse->UpdateCommonProps(m_props);
|
|
20
|
+
std::string xStr = DynamicUtils::DynamicToString(m_props->x);
|
|
21
|
+
std::string yStr = DynamicUtils::DynamicToString(m_props->y);
|
|
22
|
+
std::string widthStr = DynamicUtils::DynamicToString(m_props->width);
|
|
23
|
+
std::string heightStr = DynamicUtils::DynamicToString(m_props->height);
|
|
24
|
+
m_svgUse->x = xStr.empty() ? 0.0f : std::stof(xStr);
|
|
25
|
+
m_svgUse->y = yStr.empty() ? 0.0f : std::stof(yStr);
|
|
26
|
+
m_svgUse->width = widthStr.empty() ? 0.0f : std::stof(widthStr);
|
|
27
|
+
m_svgUse->height = heightStr.empty() ? 0.0f : std::stof(heightStr);
|
|
28
|
+
m_svgUse->href = m_props->href;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
} // namespace svg
|
|
32
|
+
} // namespace rnoh
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
|
|
3
|
+
* Use of this source code is governed by a MIT license that can be
|
|
4
|
+
* found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
#pragma once
|
|
8
|
+
|
|
9
|
+
#include "RNSVGBaseComponentInstance.h"
|
|
10
|
+
#include "SvgUse.h"
|
|
11
|
+
|
|
12
|
+
namespace rnoh {
|
|
13
|
+
namespace svg {
|
|
14
|
+
|
|
15
|
+
class RNSVGUseComponentInstance : public RNSVGBaseComponentInstance<facebook::react::RNSVGUseShadowNode> {
|
|
16
|
+
public:
|
|
17
|
+
explicit RNSVGUseComponentInstance(Context context);
|
|
18
|
+
|
|
19
|
+
protected:
|
|
20
|
+
void UpdateElementProps() override;
|
|
21
|
+
|
|
22
|
+
void onChildInserted(ComponentInstance::Shared const &childComponentInstance, std::size_t index) override {
|
|
23
|
+
CppComponentInstance::onChildInserted(childComponentInstance, index);
|
|
24
|
+
// svgUse don't draw children elements
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
private:
|
|
28
|
+
std::shared_ptr<SvgUse> m_svgUse = std::make_shared<SvgUse>();
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
} // namespace svg
|
|
32
|
+
} // namespace rnoh
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
|
|
3
|
+
* Use of this source code is governed by a MIT license that can be
|
|
4
|
+
* found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
#include <unistd.h>
|
|
8
|
+
#include <sstream>
|
|
9
|
+
#include "HttpTaskProcessor.h"
|
|
10
|
+
|
|
11
|
+
namespace rnoh {
|
|
12
|
+
namespace svg {
|
|
13
|
+
std::vector<HttpTaskProcessor *> HttpTaskProcessor::taskList_;
|
|
14
|
+
std::unordered_set<std::string> HttpTaskProcessor::threadIds_;
|
|
15
|
+
|
|
16
|
+
void ResponseCallback(void *usrCtx, Rcp_Response *response, uint32_t errCode) {
|
|
17
|
+
HttpTaskProcessor *processor = static_cast<HttpTaskProcessor *>(usrCtx);
|
|
18
|
+
|
|
19
|
+
// 记录当前线程的ID
|
|
20
|
+
std::ostringstream oss;
|
|
21
|
+
oss << std::this_thread::get_id();
|
|
22
|
+
processor->pushThreadID(oss.str());
|
|
23
|
+
|
|
24
|
+
if (response != NULL) {
|
|
25
|
+
if (response->statusCode == RCP_OK) {
|
|
26
|
+
size_t status = processor->saveImage(response->body.buffer, response->body.length);
|
|
27
|
+
if (processor->instance_ && status != 0) {
|
|
28
|
+
processor->instance_->imageDownloadComplete(processor->uri_, processor->filePath_);
|
|
29
|
+
} else if (processor->instance_) {
|
|
30
|
+
LOG(WARNING) << "[SVGImage] ResponseCallback imageDownloadFail, status: " << status;
|
|
31
|
+
processor->instance_->imageDownloadFail(processor->uri_);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
response->destroyResponse(response);
|
|
36
|
+
} else {
|
|
37
|
+
LOG(ERROR) << "[SVGImage] Callback Response is NULL, errCode: " << errCode;
|
|
38
|
+
if (processor->instance_) {
|
|
39
|
+
processor->instance_->imageDownloadFail(processor->uri_);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
processor->markEnd();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
void HttpTaskProcessor::createParentPath(const fs::path &filePath) {
|
|
47
|
+
fs::path parentPath = filePath.parent_path();
|
|
48
|
+
if (!parentPath.empty() && !fs::exists(parentPath)) {
|
|
49
|
+
fs::create_directories(parentPath);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
size_t HttpTaskProcessor::saveImage(const char *buffer, uint32_t length) {
|
|
54
|
+
size_t status = 0;
|
|
55
|
+
if (filePath_ == "")
|
|
56
|
+
return status;
|
|
57
|
+
createParentPath(filePath_);
|
|
58
|
+
fp_ = fopen(filePath_.c_str(), "w");
|
|
59
|
+
if (fp_) {
|
|
60
|
+
status = fwrite(buffer, sizeof(char), length, fp_);
|
|
61
|
+
fclose(fp_);
|
|
62
|
+
} else {
|
|
63
|
+
LOG(ERROR) << "[SVGImage] write to file failed: " << filePath_;
|
|
64
|
+
}
|
|
65
|
+
return status;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
void HttpTaskProcessor::markStart() {
|
|
69
|
+
finished_ = false;
|
|
70
|
+
auto now = std::chrono::high_resolution_clock::now();
|
|
71
|
+
startTime_ = std::chrono::time_point_cast<std::chrono::nanoseconds>(now).time_since_epoch();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
void HttpTaskProcessor::markEnd() {
|
|
75
|
+
// 记录时间戳,标记任务结束使得keep() 返回false
|
|
76
|
+
auto now = std::chrono::high_resolution_clock::now();
|
|
77
|
+
endTime_ = std::chrono::time_point_cast<std::chrono::nanoseconds>(now).time_since_epoch();
|
|
78
|
+
finished_ = true;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
bool HttpTaskProcessor::initializeRequestAndSession(const char *uri,
|
|
82
|
+
const std::map<std::string, std::string> *headers) {
|
|
83
|
+
// 创建http request 对象
|
|
84
|
+
request_ = HMS_Rcp_CreateRequest(uri);
|
|
85
|
+
if (request_ == nullptr) {
|
|
86
|
+
LOG(ERROR) << "[SVGImage] Failed to create HTTP request!";
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// 如果有 headers 参数,初始化 headers
|
|
91
|
+
if (headers) {
|
|
92
|
+
Rcp_Headers *header = HMS_Rcp_CreateHeaders();
|
|
93
|
+
for (const auto &it : *headers) {
|
|
94
|
+
if (auto errorCode = HMS_Rcp_SetHeaderValue(header, it.first.c_str(), it.second.c_str())) {
|
|
95
|
+
LOG(ERROR) << "[SVGImage] launchHttpRequestWithHeaders create headers error: " << errorCode;
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
request_->headers = header;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// 创建http 会话对象
|
|
103
|
+
uint32_t errorCode = 0;
|
|
104
|
+
session_ = HMS_Rcp_CreateSession(nullptr, &errorCode);
|
|
105
|
+
if (errorCode) {
|
|
106
|
+
LOG(ERROR) << "[SVGImage] Failed to create HTTP session, error code: " << errorCode;
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
void HttpTaskProcessor::setResponseCallback() {
|
|
114
|
+
// 设置响应数据处理的回调函数
|
|
115
|
+
responseCallback_.callback = ResponseCallback;
|
|
116
|
+
responseCallback_.usrCtx = this;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
void HttpTaskProcessor::launchHttpRequest(const char *uri) {
|
|
120
|
+
markStart();
|
|
121
|
+
this->uri_ = uri;
|
|
122
|
+
if (!initializeRequestAndSession(uri)) {
|
|
123
|
+
if (instance_) {
|
|
124
|
+
instance_->imageDownloadFail(uri);
|
|
125
|
+
}
|
|
126
|
+
markEnd();
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// 设置响应数据处理的回调函数
|
|
131
|
+
setResponseCallback();
|
|
132
|
+
|
|
133
|
+
// API异步发起请求
|
|
134
|
+
if (auto errCode = HMS_Rcp_Fetch(session_, request_, &responseCallback_)) {
|
|
135
|
+
LOG(ERROR) << "[SVGImage] launchHttpRequest HMS_Rcp_Fetch error: " << errCode;
|
|
136
|
+
if (instance_) {
|
|
137
|
+
instance_->imageDownloadFail(uri);
|
|
138
|
+
}
|
|
139
|
+
markEnd();
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
void HttpTaskProcessor::launchHttpRequestWithHeaders(const char *uri,
|
|
144
|
+
const std::map<std::string, std::string> &headers) {
|
|
145
|
+
markStart();
|
|
146
|
+
this->uri_ = uri;
|
|
147
|
+
if (!initializeRequestAndSession(uri, &headers)) {
|
|
148
|
+
if (instance_) {
|
|
149
|
+
instance_->imageDownloadFail(uri);
|
|
150
|
+
}
|
|
151
|
+
markEnd();
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// 设置响应数据处理的回调函数
|
|
156
|
+
setResponseCallback();
|
|
157
|
+
|
|
158
|
+
// API异步发起请求
|
|
159
|
+
if (auto errCode = HMS_Rcp_Fetch(session_, request_, &responseCallback_)) {
|
|
160
|
+
LOG(ERROR) << "[SVGImage] launchHttpRequest HMS_Rcp_Fetch error: " << errCode;
|
|
161
|
+
if (instance_) {
|
|
162
|
+
instance_->imageDownloadFail(uri);
|
|
163
|
+
}
|
|
164
|
+
markEnd();
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// static
|
|
169
|
+
void HttpTaskProcessor::waitAllTask() {
|
|
170
|
+
bool wait = true;
|
|
171
|
+
while (wait) {
|
|
172
|
+
wait = false;
|
|
173
|
+
for (auto *processor : taskList_) {
|
|
174
|
+
if (processor->keep())
|
|
175
|
+
wait = true;
|
|
176
|
+
}
|
|
177
|
+
if (wait) {
|
|
178
|
+
usleep(1000 * 1000);
|
|
179
|
+
echoThreadIds();
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// static
|
|
185
|
+
void HttpTaskProcessor::destroyAllTask() {
|
|
186
|
+
for (auto *processor : taskList_) {
|
|
187
|
+
processor->echoSpendTime();
|
|
188
|
+
delete processor;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
taskList_.clear();
|
|
192
|
+
threadIds_.clear();
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// static
|
|
196
|
+
void HttpTaskProcessor::echoThreadIds() {
|
|
197
|
+
for (auto id : threadIds_) {
|
|
198
|
+
DLOG(INFO) << "[SVGImage] NetDownload Task Thread ID: " << id.c_str();
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
DLOG(INFO) << "[SVGImage] NetDownload Number Of Thread : " << threadIds_.size();
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
void HttpTaskProcessor::pushThreadID(std::string id) { threadIds_.insert(id); }
|
|
205
|
+
|
|
206
|
+
} // namespace svg
|
|
207
|
+
} // namespace rnoh
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
|
|
3
|
+
* Use of this source code is governed by a MIT license that can be
|
|
4
|
+
* found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
#pragma once
|
|
8
|
+
|
|
9
|
+
#include <cstdio>
|
|
10
|
+
#include <map>
|
|
11
|
+
#include <string>
|
|
12
|
+
#include <string.h>
|
|
13
|
+
#include <stdio.h>
|
|
14
|
+
#include <unordered_set>
|
|
15
|
+
#include <filesystem>
|
|
16
|
+
#include <glog/logging.h>
|
|
17
|
+
#include "RemoteCommunicationKit/rcp.h"
|
|
18
|
+
#include "ImageSourceResolver.h"
|
|
19
|
+
#include "utils/StringUtils.h"
|
|
20
|
+
|
|
21
|
+
namespace fs = std::filesystem;
|
|
22
|
+
namespace rnoh {
|
|
23
|
+
namespace svg {
|
|
24
|
+
class HttpTaskProcessor {
|
|
25
|
+
public:
|
|
26
|
+
HttpTaskProcessor() { taskList_.push_back(this); }
|
|
27
|
+
|
|
28
|
+
~HttpTaskProcessor() {
|
|
29
|
+
if (request_ != nullptr) {
|
|
30
|
+
// 释放请求资源
|
|
31
|
+
HMS_Rcp_DestroyRequest(request_);
|
|
32
|
+
request_ = nullptr;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
static void clearTaskList() { taskList_.clear(); }
|
|
37
|
+
|
|
38
|
+
void createParentPath(const fs::path &filePath);
|
|
39
|
+
|
|
40
|
+
size_t saveImage(const char *buffer, uint32_t length);
|
|
41
|
+
|
|
42
|
+
void markStart();
|
|
43
|
+
|
|
44
|
+
void markEnd();
|
|
45
|
+
|
|
46
|
+
bool keep() { return !finished_; }
|
|
47
|
+
|
|
48
|
+
void echoSpendTime() {
|
|
49
|
+
DLOG(INFO) << "[SVGImage] HttpTaskProcessor Spend Time(ns): " << endTime_.count() - startTime_.count();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
bool initializeRequestAndSession(const char *uri, const std::map<std::string, std::string> *headers = nullptr);
|
|
53
|
+
void setResponseCallback();
|
|
54
|
+
|
|
55
|
+
void launchHttpRequest(const char *uri);
|
|
56
|
+
void launchHttpRequestWithHeaders(const char *uri, const std::map<std::string, std::string> &headers);
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
void pushThreadID(std::string id);
|
|
60
|
+
|
|
61
|
+
static void waitAllTask();
|
|
62
|
+
static void destroyAllTask();
|
|
63
|
+
static void echoThreadIds();
|
|
64
|
+
|
|
65
|
+
std::shared_ptr<ImageSourceResolver> instance_;
|
|
66
|
+
|
|
67
|
+
std::string uri_;
|
|
68
|
+
std::string filePath_;
|
|
69
|
+
|
|
70
|
+
private:
|
|
71
|
+
static std::vector<HttpTaskProcessor *> taskList_;
|
|
72
|
+
static std::unordered_set<std::string> threadIds_;
|
|
73
|
+
|
|
74
|
+
FILE *fp_ = nullptr;
|
|
75
|
+
|
|
76
|
+
std::chrono::nanoseconds startTime_;
|
|
77
|
+
std::chrono::nanoseconds endTime_;
|
|
78
|
+
|
|
79
|
+
bool finished_ = false;
|
|
80
|
+
|
|
81
|
+
Rcp_Request *request_ = nullptr;
|
|
82
|
+
Rcp_Session *session_ = nullptr;
|
|
83
|
+
|
|
84
|
+
Rcp_ResponseCallbackObject responseCallback_;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
} // namespace svg
|
|
88
|
+
} // namespace rnoh
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
|
|
3
|
+
* Use of this source code is governed by a MIT license that can be
|
|
4
|
+
* found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
#include <fstream>
|
|
8
|
+
#include "ImageSourceResolver.h"
|
|
9
|
+
|
|
10
|
+
namespace rnoh {
|
|
11
|
+
namespace svg {
|
|
12
|
+
|
|
13
|
+
std::string ImageSourceResolver::resolveImageSources(ImageSourceUpdateListener &listener, std::string uri) {
|
|
14
|
+
// 判断是否还在下载中
|
|
15
|
+
if (m_pendingSet.find(uri) != m_pendingSet.end()) {
|
|
16
|
+
removeListener(&listener);
|
|
17
|
+
addListenerForURI(uri, &listener);
|
|
18
|
+
return "";
|
|
19
|
+
}
|
|
20
|
+
// 生成图像的哈希缓存文件名
|
|
21
|
+
auto hashedFileName = StringUtils::generateHashedFileName(uri);
|
|
22
|
+
|
|
23
|
+
bool exist = remoteImageSourceMap_.get(hashedFileName);
|
|
24
|
+
if (exist) {
|
|
25
|
+
auto cacheUri = "file://" + fileCacheDir_ + hashedFileName;
|
|
26
|
+
return cacheUri;
|
|
27
|
+
}
|
|
28
|
+
removeListener(&listener);
|
|
29
|
+
addListenerForURI(uri, &listener);
|
|
30
|
+
return "";
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
void ImageSourceResolver::addListenerForURI(const std::string &uri, ImageSourceUpdateListener *listener) {
|
|
34
|
+
listener->observedUri = uri;
|
|
35
|
+
auto it = m_uriListenersMap.find(uri);
|
|
36
|
+
if (it == m_uriListenersMap.end()) {
|
|
37
|
+
m_uriListenersMap.emplace(uri, std::initializer_list<ImageSourceUpdateListener *>{listener});
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (std::find(it->second.begin(), it->second.end(), listener) != it->second.end()) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
it->second.push_back(listener);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
void ImageSourceResolver::removeListenerForURI(const std::string &uri, ImageSourceUpdateListener *listener) {
|
|
47
|
+
auto it = m_uriListenersMap.find(uri);
|
|
48
|
+
if (it == m_uriListenersMap.end()) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
auto &listeners = it->second;
|
|
52
|
+
auto listenerPos = std::find(listeners.begin(), listeners.end(), listener);
|
|
53
|
+
if (listenerPos != listeners.end()) {
|
|
54
|
+
listeners.erase(listenerPos);
|
|
55
|
+
if (listeners.empty()) {
|
|
56
|
+
m_uriListenersMap.erase(uri);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
void ImageSourceResolver::removeListener(ImageSourceUpdateListener *listener) {
|
|
62
|
+
if (!listener->observedUri.empty()) {
|
|
63
|
+
removeListenerForURI(listener->observedUri, listener);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
void ImageSourceResolver::imageDownloadComplete(std::string uri, std::string fileUri) {
|
|
68
|
+
auto pend = m_pendingSet.find(uri);
|
|
69
|
+
if (pend != m_pendingSet.end()) {
|
|
70
|
+
m_pendingSet.erase(uri);
|
|
71
|
+
}
|
|
72
|
+
// 生成图像的哈希缓存文件名
|
|
73
|
+
auto hashedFileName = StringUtils::generateHashedFileName(uri);
|
|
74
|
+
DLOG(INFO) << "[SVGImage] remoteImageSourceMap PUT: " << hashedFileName;
|
|
75
|
+
remoteImageSourceMap_.put(hashedFileName, true);
|
|
76
|
+
auto it = m_uriListenersMap.find(uri);
|
|
77
|
+
if (it == m_uriListenersMap.end()) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
auto &listeners = it->second;
|
|
82
|
+
for (auto listener : listeners) {
|
|
83
|
+
listener->onImageSourceCacheUpdate(fileUri);
|
|
84
|
+
removeListenerForURI(uri, listener);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
void ImageSourceResolver::imageDownloadFail(std::string uri) {
|
|
89
|
+
auto pend = m_pendingSet.find(uri);
|
|
90
|
+
if (pend != m_pendingSet.end()) {
|
|
91
|
+
m_pendingSet.erase(uri);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
auto it = m_uriListenersMap.find(uri);
|
|
95
|
+
if (it == m_uriListenersMap.end()) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
auto &listeners = it->second;
|
|
99
|
+
for (auto listener : listeners) {
|
|
100
|
+
listener->onImageSourceCacheDownloadFileFail();
|
|
101
|
+
removeListenerForURI(uri, listener);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
} // namespace svg
|
|
106
|
+
} // namespace rnoh
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
|
|
3
|
+
* Use of this source code is governed by a MIT license that can be
|
|
4
|
+
* found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
#pragma once
|
|
8
|
+
|
|
9
|
+
#include <memory>
|
|
10
|
+
#include <unordered_set>
|
|
11
|
+
#include <filesystem>
|
|
12
|
+
#include "RNOH/RNInstance.h"
|
|
13
|
+
#include "downloadUtils/LRUCache.h"
|
|
14
|
+
#include "utils/StringUtils.h"
|
|
15
|
+
|
|
16
|
+
namespace fs = std::filesystem;
|
|
17
|
+
|
|
18
|
+
namespace rnoh {
|
|
19
|
+
namespace svg {
|
|
20
|
+
|
|
21
|
+
// ImageSourceResolver 类用于管理图像源的缓存与下载
|
|
22
|
+
class ImageSourceResolver {
|
|
23
|
+
public:
|
|
24
|
+
using Shared = std::shared_ptr<ImageSourceResolver>;
|
|
25
|
+
|
|
26
|
+
// 构造函数,初始化缓存目录以及设置LRU缓存
|
|
27
|
+
explicit ImageSourceResolver(std::string fileCacheDir)
|
|
28
|
+
: m_uriListenersMap(), fileCacheDir_(fileCacheDir),
|
|
29
|
+
remoteImageSourceMap_(128, [this](std::string fileUri, bool a) {
|
|
30
|
+
// 删除缓存文件(LRU缓存淘汰回调)
|
|
31
|
+
fs::path filePath = this->fileCacheDir_ + fileUri;
|
|
32
|
+
if (fs::exists(filePath) && fs::is_regular_file(filePath)) {
|
|
33
|
+
LOG(INFO) << "[SVGImage] remoteImageSourceMap delete: " << filePath;
|
|
34
|
+
return fs::remove(filePath);
|
|
35
|
+
}
|
|
36
|
+
return false;
|
|
37
|
+
}) {}
|
|
38
|
+
|
|
39
|
+
// 图像源更新的监听器基类
|
|
40
|
+
class ImageSourceUpdateListener {
|
|
41
|
+
public:
|
|
42
|
+
std::string observedUri; // 监听的图像URI
|
|
43
|
+
|
|
44
|
+
ImageSourceUpdateListener(ImageSourceResolver::Shared const &ImageSourceResolver)
|
|
45
|
+
: m_imageSourceResolver(ImageSourceResolver) {}
|
|
46
|
+
|
|
47
|
+
// 注销监听器
|
|
48
|
+
~ImageSourceUpdateListener() {
|
|
49
|
+
if (!m_imageSourceResolver) {
|
|
50
|
+
m_imageSourceResolver->removeListener(this);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// 监听图像缓存更新
|
|
55
|
+
virtual void onImageSourceCacheUpdate(std::string imageUri) = 0;
|
|
56
|
+
|
|
57
|
+
// 监听图像下载失败
|
|
58
|
+
virtual void onImageSourceCacheDownloadFileFail() = 0;
|
|
59
|
+
|
|
60
|
+
private:
|
|
61
|
+
ImageSourceResolver::Shared const &m_imageSourceResolver;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// 解析图像源的缓存路径
|
|
65
|
+
std::string resolveImageSources(ImageSourceUpdateListener &listener, std::string uri);
|
|
66
|
+
|
|
67
|
+
// 为URI添加监听器
|
|
68
|
+
void addListenerForURI(const std::string &uri, ImageSourceUpdateListener *listener);
|
|
69
|
+
|
|
70
|
+
// 从URI移除监听器
|
|
71
|
+
void removeListenerForURI(const std::string &uri, ImageSourceUpdateListener *listener);
|
|
72
|
+
|
|
73
|
+
// 从解析器中移除监听器
|
|
74
|
+
void removeListener(ImageSourceUpdateListener *listener);
|
|
75
|
+
|
|
76
|
+
// 下载完成后更新图像缓存
|
|
77
|
+
void imageDownloadComplete(std::string uri, std::string fileUri);
|
|
78
|
+
|
|
79
|
+
// 下载失败时,通知图像源更新失败
|
|
80
|
+
void imageDownloadFail(std::string uri);
|
|
81
|
+
|
|
82
|
+
// 使用LRU缓存来管理磁盘文件路径与URI的映射
|
|
83
|
+
LRUCache<std::string, bool> remoteImageSourceMap_;
|
|
84
|
+
|
|
85
|
+
// 存储图像缓存目录路径
|
|
86
|
+
std::string fileCacheDir_;
|
|
87
|
+
|
|
88
|
+
private:
|
|
89
|
+
// 存储URI与对应的监听器(支持多个监听器)
|
|
90
|
+
std::unordered_map<std::string, std::vector<ImageSourceUpdateListener *>> m_uriListenersMap;
|
|
91
|
+
|
|
92
|
+
// 存储正在下载的图像URI集合
|
|
93
|
+
std::unordered_set<std::string> m_pendingSet;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
} // namespace svg
|
|
97
|
+
} // namespace rnoh
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
|
|
3
|
+
* Use of this source code is governed by a MIT license that can be
|
|
4
|
+
* found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
#pragma once
|
|
8
|
+
|
|
9
|
+
#include <unordered_map>
|
|
10
|
+
#include <list>
|
|
11
|
+
#include <mutex>
|
|
12
|
+
|
|
13
|
+
namespace rnoh {
|
|
14
|
+
namespace svg {
|
|
15
|
+
template <typename KeyType, typename ValueType, int defaultCapacity = 10> class LRUCache {
|
|
16
|
+
private:
|
|
17
|
+
std::unordered_map<KeyType, std::pair<ValueType, typename std::list<KeyType>::iterator>> m_cache;
|
|
18
|
+
std::list<KeyType> m_lruList;
|
|
19
|
+
std::mutex m_mtx; // 用于同步的互斥锁
|
|
20
|
+
std::function<bool(KeyType, ValueType)> m_deleteCallback;
|
|
21
|
+
int m_cacheCapacity; // 成员变量的容量
|
|
22
|
+
|
|
23
|
+
public:
|
|
24
|
+
// 构造函数,允许设置自定义容量和删除回调函数
|
|
25
|
+
LRUCache(int customCapacity = defaultCapacity, std::function<bool(KeyType, ValueType)> callback = nullptr)
|
|
26
|
+
: m_cacheCapacity(customCapacity), m_deleteCallback(callback) {}
|
|
27
|
+
|
|
28
|
+
ValueType get(const KeyType &key) {
|
|
29
|
+
std::lock_guard<std::mutex> lock(m_mtx);
|
|
30
|
+
if (m_cache.find(key) != m_cache.end()) {
|
|
31
|
+
m_lruList.erase(m_cache[key].second);
|
|
32
|
+
m_lruList.push_front(key);
|
|
33
|
+
m_cache[key].second = m_lruList.begin();
|
|
34
|
+
return m_cache[key].first;
|
|
35
|
+
}
|
|
36
|
+
return ValueType(); // 如果没找到,返回默认构造的值
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
void put(const KeyType &key, const ValueType &value) {
|
|
40
|
+
std::lock_guard<std::mutex> lock(m_mtx);
|
|
41
|
+
if (m_cache.find(key) != m_cache.end()) {
|
|
42
|
+
m_cache[key].first = value;
|
|
43
|
+
m_lruList.erase(m_cache[key].second);
|
|
44
|
+
m_lruList.push_front(key);
|
|
45
|
+
m_cache[key].second = m_lruList.begin();
|
|
46
|
+
} else {
|
|
47
|
+
if (m_cache.size() >= m_cacheCapacity) {
|
|
48
|
+
KeyType lruKey = m_lruList.back();
|
|
49
|
+
|
|
50
|
+
// 调用删除回调函数
|
|
51
|
+
if (m_deleteCallback) {
|
|
52
|
+
m_deleteCallback(lruKey, m_cache[lruKey].first);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
m_cache.erase(lruKey);
|
|
56
|
+
m_lruList.pop_back();
|
|
57
|
+
}
|
|
58
|
+
m_lruList.push_front(key);
|
|
59
|
+
m_cache[key] = std::make_pair(value, m_lruList.begin());
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
bool remove(const KeyType &key) {
|
|
64
|
+
std::lock_guard<std::mutex> lock(m_mtx);
|
|
65
|
+
bool status = false;
|
|
66
|
+
if (m_cache.find(key) != m_cache.end()) {
|
|
67
|
+
ValueType value = m_cache[key].first;
|
|
68
|
+
m_lruList.erase(m_cache[key].second);
|
|
69
|
+
if (m_deleteCallback) {
|
|
70
|
+
status = m_deleteCallback(key, value);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
m_cache.erase(key);
|
|
74
|
+
}
|
|
75
|
+
return status;
|
|
76
|
+
}
|
|
77
|
+
bool clearAll() {
|
|
78
|
+
std::lock_guard<std::mutex> lock(m_mtx);
|
|
79
|
+
// 从后向前遍历 lruList
|
|
80
|
+
for (auto it = m_lruList.end(); it != m_lruList.begin();) {
|
|
81
|
+
--it; // 先向前移动迭代器
|
|
82
|
+
KeyType key = *it; // 获取当前键
|
|
83
|
+
if (m_deleteCallback) {
|
|
84
|
+
// 调用删除回调并检查返回值
|
|
85
|
+
if (!m_deleteCallback(key, m_cache[key].first)) {
|
|
86
|
+
return false; // 如果删除失败,返回 false
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
m_cache.erase(key); // 从 cache 中删除该键
|
|
90
|
+
it = m_lruList.erase(it); // 删除当前节点并更新迭代器
|
|
91
|
+
}
|
|
92
|
+
return true; // 成功删除所有元素,返回 true
|
|
93
|
+
}
|
|
94
|
+
size_t size() { return m_cache.size(); }
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
} // namespace svg
|
|
98
|
+
} // namespace rnoh
|