nativescript-svg-fix-2026 1.0.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.
@@ -0,0 +1,2 @@
1
+ export * from './nativescript-svg-module';
2
+ export * from './nativescript-svg-directives';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ __exportStar(require("./nativescript-svg-module"), exports);
4
+ __exportStar(require("./nativescript-svg-directives"), exports);
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,3 @@
1
+ export declare class SVGImageDirective {
2
+ }
3
+ export declare const DIRECTIVES: (typeof SVGImageDirective)[];
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DIRECTIVES = exports.SVGImageDirective = void 0;
4
+ const core_1 = require("@angular/core");
5
+ let SVGImageDirective = class SVGImageDirective {
6
+ };
7
+ exports.SVGImageDirective = SVGImageDirective;
8
+ exports.SVGImageDirective = SVGImageDirective = __decorate([
9
+ (0, core_1.Directive)({
10
+ selector: 'SVGImage'
11
+ })
12
+ ], SVGImageDirective);
13
+ exports.DIRECTIVES = [SVGImageDirective];
14
+ //# sourceMappingURL=nativescript-svg-directives.js.map
@@ -0,0 +1,2 @@
1
+ export declare class NativeScriptSvgModule {
2
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NativeScriptSvgModule = void 0;
4
+ const core_1 = require("@angular/core");
5
+ const angular_1 = require("@nativescript/angular");
6
+ const nativescript_svg_directives_1 = require("./nativescript-svg-directives");
7
+ let NativeScriptSvgModule = class NativeScriptSvgModule {
8
+ };
9
+ exports.NativeScriptSvgModule = NativeScriptSvgModule;
10
+ exports.NativeScriptSvgModule = NativeScriptSvgModule = __decorate([
11
+ (0, core_1.NgModule)({
12
+ declarations: [nativescript_svg_directives_1.DIRECTIVES],
13
+ exports: [nativescript_svg_directives_1.DIRECTIVES],
14
+ schemas: [core_1.NO_ERRORS_SCHEMA]
15
+ })
16
+ ], NativeScriptSvgModule);
17
+ (0, angular_1.registerElement)('SVGImage', () => require('../').SVGImage);
18
+ //# sourceMappingURL=nativescript-svg-module.js.map
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "@anthropic-ai/nativescript-svg-fix-2026/angular",
3
+ "main": "index.js",
4
+ "typings": "index.d.ts"
5
+ }
@@ -0,0 +1 @@
1
+ module.exports = require("nativescript-angular/hooks/before-livesync");
package/package.json ADDED
@@ -0,0 +1,75 @@
1
+ {
2
+ "name": "nativescript-svg-fix-2026",
3
+ "version": "1.0.0",
4
+ "description": "NativeScript SVG plugin - Fixed and updated for modern NativeScript",
5
+ "main": "svg",
6
+ "typings": "svg.d.ts",
7
+ "nativescript": {
8
+ "platforms": {
9
+ "android": "8.0.0",
10
+ "ios": "8.0.0"
11
+ }
12
+ },
13
+ "scripts": {
14
+ "tsc": "tsc -skipLibCheck",
15
+ "build": "npm i && tsc",
16
+ "clean": "rimraf *.js *.js.map *.d.ts angular/*.js angular/*.js.map angular/*.d.ts",
17
+ "prepublishOnly": "npm run build",
18
+ "tslint": "cd .. && tslint \"**/*.ts\" --config tslint.json --exclude \"**/node_modules/**\" --exclude \"*demo*/platforms/**\"",
19
+ "plugin.link": "npm link && cd ../demo && npm link @anthropic-ai/nativescript-svg-fix-2026 && cd ../src",
20
+ "plugin.tscwatch": "npm run tsc -- -w",
21
+ "demo.ios": "npm i && npm run tsc && cd ../demo && ns run ios --syncAllFiles",
22
+ "demo.android": "npm i && npm run tsc && cd ../demo && ns run android --syncAllFiles"
23
+ },
24
+ "keywords": [
25
+ "NativeScript",
26
+ "JavaScript",
27
+ "TypeScript",
28
+ "Android",
29
+ "iOS",
30
+ "svg",
31
+ "vector",
32
+ "image"
33
+ ],
34
+ "author": {
35
+ "name": "censujiang",
36
+ "url": "https://github.com/censujiang"
37
+ },
38
+ "contributors": [
39
+ {
40
+ "name": "Victor Sosa",
41
+ "email": "victor.sosa@peopleware.do"
42
+ },
43
+ {
44
+ "name": "Brad Martin",
45
+ "email": "bmartin@nstudio.io",
46
+ "url": "https://github.com/bradmartin"
47
+ },
48
+ {
49
+ "name": "jnorkus",
50
+ "url": "https://github.com/jnorkus"
51
+ }
52
+ ],
53
+ "bugs": {
54
+ "url": "https://github.com/censujiang/nativescript-svg-fix-2026/issues"
55
+ },
56
+ "license": "MIT",
57
+ "homepage": "https://github.com/censujiang/nativescript-svg-fix-2026",
58
+ "readmeFilename": "README.md",
59
+ "devDependencies": {
60
+ "@nativescript/angular": "~18.0.0",
61
+ "@angular/core": "~18.0.0",
62
+ "@angular/common": "~18.0.0",
63
+ "@angular/compiler": "~18.0.0",
64
+ "@angular/compiler-cli": "~18.0.0",
65
+ "rxjs": "~7.8.0",
66
+ "zone.js": "~0.14.0",
67
+ "rimraf": "^5.0.0",
68
+ "@nativescript/core": "~8.8.0",
69
+ "@nativescript/types": "~8.8.0",
70
+ "typescript": "~5.4.0"
71
+ },
72
+ "peerDependencies": {
73
+ "@nativescript/core": ">=8.0.0"
74
+ }
75
+ }
@@ -0,0 +1 @@
1
+ pod 'SVGKit', :git => 'https://github.com/SVGKit/SVGKit.git', :branch => '3.x'
@@ -0,0 +1,24 @@
1
+ import svg = require('./svg');
2
+ import common = require('./svg.common');
3
+ export declare class ImageSourceSVG implements svg.ImageSourceSVG {
4
+ private nativeView;
5
+ loadFromResource(name: string): boolean;
6
+ fromResource(name: string): Promise<boolean>;
7
+ loadFromFile(filePath: string): boolean;
8
+ fromFile(filePath: string): Promise<boolean>;
9
+ loadFromData(data: any): boolean;
10
+ fromData(data: any): Promise<boolean>;
11
+ loadFromBase64(source: string): boolean;
12
+ fromBase64(data: any): Promise<boolean>;
13
+ fromUrl(url: string): Promise<boolean>;
14
+ setNativeSource(source: any): boolean;
15
+ saveToFile(filePath: string): boolean;
16
+ toBase64String(format: string): string;
17
+ get height(): number;
18
+ get width(): number;
19
+ }
20
+ export declare class SVGImage extends common.SVGImage {
21
+ constructor();
22
+ createNativeView(): any;
23
+ _setNativeImage(nativeImage: any): void;
24
+ }
package/svg.android.js ADDED
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SVGImage = exports.ImageSourceSVG = void 0;
4
+ const common = require("./svg.common");
5
+ const core_1 = require("@nativescript/core");
6
+ Object.keys(common).forEach(key => {
7
+ if (!(key in exports)) {
8
+ exports[key] = common[key];
9
+ }
10
+ });
11
+ class ImageSourceSVG {
12
+ loadFromResource(name) {
13
+ this.nativeView = null;
14
+ const res = core_1.Utils.android.getApplicationContext().getResources();
15
+ if (res) {
16
+ const identifier = res.getIdentifier(name, 'drawable', core_1.Utils.android.getApplication().getPackageName());
17
+ if (0 < identifier) {
18
+ this.nativeView = com.caverock.androidsvg.SVG.getFromResource(res, identifier);
19
+ }
20
+ }
21
+ return this.nativeView != null;
22
+ }
23
+ fromResource(name) {
24
+ return new Promise((resolve, reject) => {
25
+ resolve(this.loadFromResource(name));
26
+ });
27
+ }
28
+ loadFromFile(filePath) {
29
+ let fileName = typeof filePath === 'string' ? filePath.trim() : '';
30
+ if (fileName.indexOf('~/') === 0) {
31
+ fileName = core_1.path.join(core_1.knownFolders.currentApp().path, fileName.replace('~/', ''));
32
+ }
33
+ this.nativeView = com.caverock.androidsvg.SVG.getFromInputStream(new java.io.FileInputStream(new java.io.File(fileName)));
34
+ return this.nativeView != null;
35
+ }
36
+ fromFile(filePath) {
37
+ return new Promise((resolve, reject) => {
38
+ resolve(this.loadFromFile(filePath));
39
+ });
40
+ }
41
+ loadFromData(data) {
42
+ this.nativeView = com.caverock.androidsvg.SVG.getFromString(data);
43
+ return this.nativeView != null;
44
+ }
45
+ fromData(data) {
46
+ return new Promise((resolve, reject) => {
47
+ resolve(this.loadFromData(data));
48
+ });
49
+ }
50
+ loadFromBase64(source) {
51
+ const bytes = android.util.Base64.decode(source, android.util.Base64.DEFAULT);
52
+ this.nativeView = com.caverock.androidsvg.SVG.getFromString(new java.lang.String(bytes));
53
+ return this.nativeView != null;
54
+ }
55
+ fromBase64(data) {
56
+ return new Promise((resolve, reject) => {
57
+ resolve(this.loadFromBase64(data));
58
+ });
59
+ }
60
+ fromUrl(url) {
61
+ const result = core_1.Http.getString(url);
62
+ return new Promise((resolve, reject) => {
63
+ result
64
+ .then(val => {
65
+ this.setNativeSource(com.caverock.androidsvg.SVG.getFromString(val));
66
+ resolve(true);
67
+ })
68
+ .catch(e => {
69
+ reject(false);
70
+ });
71
+ });
72
+ }
73
+ setNativeSource(source) {
74
+ this.nativeView = source;
75
+ return source != null;
76
+ }
77
+ saveToFile(filePath) {
78
+ return false;
79
+ }
80
+ toBase64String(format) {
81
+ if (!this.nativeView) {
82
+ return null;
83
+ }
84
+ return android.util.Base64.encodeToString(format, android.util.Base64.DEFAULT);
85
+ }
86
+ get height() {
87
+ if (this.nativeView) {
88
+ return this.nativeView.getPitcture().getHeight();
89
+ }
90
+ return NaN;
91
+ }
92
+ get width() {
93
+ if (this.nativeView) {
94
+ return this.nativeView.getPitcture().getWidth();
95
+ }
96
+ return NaN;
97
+ }
98
+ }
99
+ exports.ImageSourceSVG = ImageSourceSVG;
100
+ class SVGImage extends common.SVGImage {
101
+ constructor() {
102
+ super();
103
+ }
104
+ createNativeView() {
105
+ return new com.caverock.androidsvg.SVGImageView(this._context);
106
+ }
107
+ _setNativeImage(nativeImage) {
108
+ this.nativeView.setSVG(nativeImage.nativeView);
109
+ }
110
+ [common.imageSourceProperty.setNative](value) {
111
+ const image = value;
112
+ if (!image || !image.nativeView) {
113
+ return;
114
+ }
115
+ this._setNativeImage(image);
116
+ }
117
+ }
118
+ exports.SVGImage = SVGImage;
119
+ //# sourceMappingURL=svg.android.js.map
@@ -0,0 +1,22 @@
1
+ import { View, Property } from '@nativescript/core';
2
+ import * as definition from './svg';
3
+ export declare const srcProperty: Property<SVGImage, boolean>;
4
+ export declare const imageSourceProperty: Property<SVGImage, definition.ImageSourceSVG>;
5
+ export declare const isLoadingProperty: Property<SVGImage, boolean>;
6
+ export declare const loadModeProperty: Property<SVGImage, string>;
7
+ export declare class SVGImage extends View implements definition.SVGImage {
8
+ src: any;
9
+ imageSource: definition.ImageSourceSVG;
10
+ isLoading: boolean;
11
+ loadMode: 'sync' | 'async';
12
+ constructor(options?: definition.Options);
13
+ _createImageSourceFromSrc(): void;
14
+ }
15
+ export declare function fromResource(name: string): definition.ImageSourceSVG;
16
+ export declare function fromFile(path: string): definition.ImageSourceSVG;
17
+ export declare function fromData(data: any): definition.ImageSourceSVG;
18
+ export declare function fromBase64(source: string): definition.ImageSourceSVG;
19
+ export declare function fromNativeSource(source: any): definition.ImageSourceSVG;
20
+ export declare function fromUrl(url: string): definition.ImageSourceSVG;
21
+ export declare function fromFileOrResource(path: string): definition.ImageSourceSVG;
22
+ export declare function isFileOrResourcePath(path: string): boolean;
package/svg.common.js ADDED
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isFileOrResourcePath = exports.fromFileOrResource = exports.fromUrl = exports.fromNativeSource = exports.fromBase64 = exports.fromData = exports.fromFile = exports.fromResource = exports.SVGImage = exports.loadModeProperty = exports.isLoadingProperty = exports.imageSourceProperty = exports.srcProperty = void 0;
4
+ const core_1 = require("@nativescript/core");
5
+ const core_2 = require("@nativescript/core");
6
+ const definition = require("./svg");
7
+ const SRC = 'src';
8
+ const IMAGE_SOURCE = 'imageSource';
9
+ const LOAD_MODE = 'loadMode';
10
+ const SYNC = 'sync';
11
+ const ASYNC = 'async';
12
+ const ISLOADING = 'isLoading';
13
+ exports.srcProperty = new core_1.Property({
14
+ name: SRC,
15
+ defaultValue: undefined,
16
+ valueChanged: (target, oldValue, newValue) => target._createImageSourceFromSrc()
17
+ });
18
+ exports.imageSourceProperty = new core_1.Property({ name: IMAGE_SOURCE, defaultValue: undefined });
19
+ exports.isLoadingProperty = new core_1.Property({
20
+ name: ISLOADING,
21
+ defaultValue: false
22
+ });
23
+ exports.loadModeProperty = new core_1.Property({
24
+ name: LOAD_MODE,
25
+ defaultValue: SYNC
26
+ });
27
+ class SVGImage extends core_1.View {
28
+ constructor(options) {
29
+ super();
30
+ }
31
+ _createImageSourceFromSrc() {
32
+ let value = this.src;
33
+ if (typeof value === 'string') {
34
+ value = value.trim();
35
+ this.imageSource = null;
36
+ this['_url'] = value;
37
+ this.isLoading = true;
38
+ const source = new definition.ImageSourceSVG();
39
+ const imageLoaded = () => {
40
+ const currentValue = this.src;
41
+ if (typeof this.src !== 'string' || value !== currentValue.trim()) {
42
+ return;
43
+ }
44
+ this.imageSource = source;
45
+ this.isLoading = false;
46
+ };
47
+ if (core_2.Utils.isDataURI(value)) {
48
+ const base64Data = value.split(',')[1];
49
+ if (base64Data !== undefined && base64Data !== null) {
50
+ if (this.loadMode === SYNC) {
51
+ source.loadFromBase64(base64Data);
52
+ imageLoaded();
53
+ }
54
+ else if (this.loadMode === ASYNC) {
55
+ source.fromBase64(base64Data).then(imageLoaded);
56
+ }
57
+ }
58
+ }
59
+ else if (definition.isFileOrResourcePath(value)) {
60
+ if (value.indexOf(core_2.Utils.RESOURCE_PREFIX) === 0) {
61
+ const resPath = value.substr(core_2.Utils.RESOURCE_PREFIX.length);
62
+ if (this.loadMode === SYNC) {
63
+ source.loadFromResource(resPath);
64
+ imageLoaded();
65
+ }
66
+ else if (this.loadMode === ASYNC) {
67
+ this.imageSource = null;
68
+ source.fromResource(resPath).then(imageLoaded);
69
+ }
70
+ }
71
+ else {
72
+ if (this.loadMode === SYNC) {
73
+ source.loadFromFile(value);
74
+ imageLoaded();
75
+ }
76
+ else if (this.loadMode === ASYNC) {
77
+ this.imageSource = null;
78
+ source.fromFile(value).then(imageLoaded);
79
+ }
80
+ }
81
+ }
82
+ else {
83
+ this.imageSource = null;
84
+ definition.fromUrl(value).then(r => {
85
+ if (this['_url'] === value) {
86
+ this.imageSource = r;
87
+ this.isLoading = false;
88
+ }
89
+ });
90
+ }
91
+ }
92
+ else if (value instanceof definition.ImageSourceSVG) {
93
+ this.imageSource = value;
94
+ this.isLoading = false;
95
+ }
96
+ else {
97
+ this.imageSource = definition.fromNativeSource(value);
98
+ this.isLoading = false;
99
+ }
100
+ }
101
+ }
102
+ exports.SVGImage = SVGImage;
103
+ function fromResource(name) {
104
+ const image = new definition.ImageSourceSVG();
105
+ return image.loadFromResource(name) ? image : null;
106
+ }
107
+ exports.fromResource = fromResource;
108
+ function fromFile(path) {
109
+ const image = new definition.ImageSourceSVG();
110
+ return image.loadFromFile(path) ? image : null;
111
+ }
112
+ exports.fromFile = fromFile;
113
+ function fromData(data) {
114
+ const image = new definition.ImageSourceSVG();
115
+ return image.loadFromData(data) ? image : null;
116
+ }
117
+ exports.fromData = fromData;
118
+ function fromBase64(source) {
119
+ const image = new definition.ImageSourceSVG();
120
+ return image.loadFromBase64(source) ? image : null;
121
+ }
122
+ exports.fromBase64 = fromBase64;
123
+ function fromNativeSource(source) {
124
+ const image = new definition.ImageSourceSVG();
125
+ return image.setNativeSource(source) ? image : null;
126
+ }
127
+ exports.fromNativeSource = fromNativeSource;
128
+ function fromUrl(url) {
129
+ const image = new definition.ImageSourceSVG();
130
+ return image.fromUrl(url) ? image : null;
131
+ }
132
+ exports.fromUrl = fromUrl;
133
+ function fromFileOrResource(path) {
134
+ if (!isFileOrResourcePath(path)) {
135
+ throw new Error('Path "' + '" is not a valid file or resource.');
136
+ }
137
+ if (path.indexOf(core_2.Utils.RESOURCE_PREFIX) === 0) {
138
+ return fromResource(path.substr(core_2.Utils.RESOURCE_PREFIX.length));
139
+ }
140
+ return fromFile(path);
141
+ }
142
+ exports.fromFileOrResource = fromFileOrResource;
143
+ function isFileOrResourcePath(path) {
144
+ return core_2.Utils.isFileOrResourcePath(path);
145
+ }
146
+ exports.isFileOrResourcePath = isFileOrResourcePath;
147
+ exports.srcProperty.register(SVGImage);
148
+ exports.imageSourceProperty.register(SVGImage);
149
+ exports.loadModeProperty.register(SVGImage);
150
+ exports.isLoadingProperty.register(SVGImage);
151
+ //# sourceMappingURL=svg.common.js.map
package/svg.d.ts ADDED
@@ -0,0 +1,183 @@
1
+ /**
2
+ * Allows you to parse SVG files.
3
+ */
4
+
5
+ import { Property, View } from '@nativescript/core';
6
+
7
+ /**
8
+ * Represents a class that provides functionality for loading svg(s).
9
+ */
10
+ export class SVGImage extends View {
11
+ public static srcProperty: Property<SVGImage, any>;
12
+ public static imageSourceProperty: Property<SVGImage, ImageSourceSVG>;
13
+ public static isLoadingProperty: Property<SVGImage, boolean>;
14
+
15
+ /**
16
+ * Gets or sets the image source of the image.
17
+ */
18
+ imageSource: ImageSourceSVG;
19
+
20
+ /**
21
+ * Gets or sets the source of the svg. This can be either an URL string or a native svg instance.
22
+ */
23
+ src: any;
24
+
25
+ /**
26
+ * Gets a value indicating if the svg is currently loading
27
+ */
28
+ isLoading: boolean;
29
+
30
+ /**
31
+ * Gets or sets the loading strategy for images on the local file system:
32
+ * - **sync** *(default)* - blocks the UI if necessary to display immediately, good for small icons.
33
+ * - **async** - will try to load in the background, may appear with short delay, good for large images.
34
+ */
35
+ loadMode: string; // "sync" | "async";
36
+ }
37
+
38
+ /**
39
+ * Provides common options for creating a animation
40
+ */
41
+ export interface Options {
42
+ /**
43
+ * Gets or sets the URL of the svg
44
+ */
45
+ src: string;
46
+ }
47
+
48
+ /**
49
+ * Encapsulates the common abstraction behind a platform specific object SVG that is used as a source for images.
50
+ */
51
+ export class ImageSourceSVG {
52
+ /**
53
+ * Gets the height of this instance. This is a read-only property.
54
+ */
55
+ height: number;
56
+
57
+ /**
58
+ * Gets the width of this instance. This is a read-only property.
59
+ */
60
+ width: number;
61
+
62
+ /**
63
+ * Loads this instance from the specified resource name.
64
+ * @param name The name of the resource (without its extension).
65
+ */
66
+ loadFromResource(name: string): boolean;
67
+
68
+ /**
69
+ * Loads this instance from the specified resource name asynchronously.
70
+ * @param name The name of the resource (without its extension).
71
+ */
72
+ fromResource(name: string): Promise<boolean>;
73
+
74
+ /**
75
+ * Loads this instance from the specified file.
76
+ * @param path The location of the file on the file system.
77
+ */
78
+ loadFromFile(path: string): boolean;
79
+
80
+ /**
81
+ * Loads this instance from the specified file asynchronously.
82
+ * @param path The location of the file on the file system.
83
+ */
84
+ fromFile(path: string): Promise<boolean>;
85
+
86
+ /**
87
+ * Loads this instance from the specified native image data.
88
+ * @param data The native data (byte array) to load the image from. This will be either Stream for Android or NSData for iOS.
89
+ */
90
+ loadFromData(data: any): boolean;
91
+
92
+ /**
93
+ * Loads this instance from the specified native image data asynchronously.
94
+ * @param data The native data (byte array) to load the image from. This will be either Stream for Android or NSData for iOS.
95
+ */
96
+ fromData(data: any): Promise<boolean>;
97
+
98
+ /**
99
+ * Loads this instance from the specified native image data.
100
+ * @param source The Base64 string to load the image from.
101
+ */
102
+ loadFromBase64(source: string): boolean;
103
+
104
+ /**
105
+ * Loads this instance from the specified native image data asynchronously.
106
+ * @param source The Base64 string to load the image from.
107
+ */
108
+ fromBase64(source: string): Promise<boolean>;
109
+
110
+ /**
111
+ * Loads this instance from the specified url asynchronously.
112
+ * @param url string to load the image from.
113
+ */
114
+ fromUrl(url: string): Promise<boolean>;
115
+
116
+ /**
117
+ * Sets the provided native source object.
118
+ * This will update either the android or ios properties, depending on the target os.
119
+ * @param source The native image object. Will be either a svg for Android or a UIImage for iOS.
120
+ */
121
+ setNativeSource(source: any): boolean;
122
+
123
+ /**
124
+ * Saves this instance to the specified file, using the provided image format and quality.
125
+ * @param path The path of the file on the file system to save to.
126
+ */
127
+ saveToFile(path: string): boolean;
128
+
129
+ /**
130
+ * Converts the image to base64 encoded string, using the provided image format and quality.
131
+ * @param format The format (encoding) of the image.
132
+ */
133
+ toBase64String(format: string): string;
134
+ }
135
+
136
+ /**
137
+ * Creates a new ImageSourceSVG instance and loads it from the specified resource name.
138
+ * @param name The name of the resource (without its extension).
139
+ */
140
+ export function fromResource(name: string): ImageSourceSVG;
141
+
142
+ /**
143
+ * Creates a new ImageSourceSVG instance and loads it from the specified file.
144
+ * @param path The location of the file on the file system.
145
+ */
146
+ export function fromFile(path: string): ImageSourceSVG;
147
+
148
+ /**
149
+ * Creates a new ImageSourceSVG instance and loads it from the specified resource name.
150
+ * @param data The native data (byte array) to load the image from. This will be either Stream for Android or NSData for iOS.
151
+ */
152
+ export function fromData(data: any): ImageSourceSVG;
153
+
154
+ /**
155
+ * Creates a new ImageSourceSVG instance and loads it from the specified resource name.
156
+ * @param source The Base64 string to load the image from.
157
+ */
158
+ export function fromBase64(source: string): ImageSourceSVG;
159
+
160
+ /**
161
+ * Creates a new ImageSourceSVG instance and sets the provided native source object.
162
+ * The native source object will update either the android or ios properties, depending on the target os.
163
+ * @param source The native image object. Will be either a Bitmap for Android or a UIImage for iOS.
164
+ */
165
+ export function fromNativeSource(source: any): ImageSourceSVG;
166
+
167
+ /**
168
+ * Downloads the image from the provided Url and creates a new ImageSourceSVG instance from it.
169
+ * @param url The link to the remote image object. This operation will download and decode the image.
170
+ */
171
+ export function fromUrl(url: string): Promise<ImageSourceSVG>;
172
+
173
+ /**
174
+ * Creates a new ImageSourceSVG instance and loads it from the specified local file or resource(if spexified with "res://" prefix)
175
+ * @param path The location of the file on the file system.
176
+ */
177
+ export function fromFileOrResource(path: string): ImageSourceSVG;
178
+
179
+ /**
180
+ * [Obsolete. Please use Utils.isFileOrResourcePath instead!] Returns true if the specified path points to a resource or local file.
181
+ * @param path The path.
182
+ */
183
+ export function isFileOrResourcePath(path: string): boolean;
package/svg.ios.d.ts ADDED
@@ -0,0 +1,26 @@
1
+ import svg = require('./svg');
2
+ import common = require('./svg.common');
3
+ export declare class ImageSourceSVG implements svg.ImageSourceSVG {
4
+ private nativeView;
5
+ loadFromResource(name: string): boolean;
6
+ fromResource(name: string): Promise<boolean>;
7
+ loadFromFile(filePath: string): boolean;
8
+ fromFile(filePath: string): Promise<boolean>;
9
+ loadFromData(data: any): boolean;
10
+ fromData(data: any): Promise<boolean>;
11
+ loadFromBase64(source: string): boolean;
12
+ fromBase64(source: string): Promise<boolean>;
13
+ private loadFromUrl;
14
+ fromUrl(url: string): Promise<boolean>;
15
+ setNativeSource(source: any): boolean;
16
+ saveToFile(filePath: string): boolean;
17
+ toBase64String(format: string): string;
18
+ get height(): number;
19
+ get width(): number;
20
+ }
21
+ export declare class SVGImage extends common.SVGImage {
22
+ private _imageSourceAffectsLayout;
23
+ constructor();
24
+ _setNativeImage(nativeImage: any): void;
25
+ onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void;
26
+ }
package/svg.ios.js ADDED
@@ -0,0 +1,195 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SVGImage = exports.ImageSourceSVG = void 0;
4
+ const common = require("./svg.common");
5
+ const core_1 = require("@nativescript/core");
6
+ Object.keys(common).forEach(key => {
7
+ if (!(key in exports)) {
8
+ exports[key] = common[key];
9
+ }
10
+ });
11
+ class ImageSourceSVG {
12
+ loadFromResource(name) {
13
+ this.nativeView =
14
+ SVGKImage.imageNamed(name) || SVGKImage.imageNamed(`${name}.svg`);
15
+ return this.nativeView != null;
16
+ }
17
+ fromResource(name) {
18
+ return new Promise((resolve, reject) => {
19
+ try {
20
+ SVGKImage.imageAsynchronouslyNamed(name, (image, parseResult) => {
21
+ if (image) {
22
+ this.nativeView = image;
23
+ resolve(true);
24
+ }
25
+ else {
26
+ SVGKImage.imageAsynchronouslyNamed(`${name}.svg`, (image, parseResult) => {
27
+ this.nativeView = image;
28
+ resolve(true);
29
+ });
30
+ }
31
+ });
32
+ }
33
+ catch (ex) {
34
+ reject(ex);
35
+ }
36
+ });
37
+ }
38
+ loadFromFile(filePath) {
39
+ let fileName = typeof filePath === 'string' ? filePath.trim() : '';
40
+ if (fileName.indexOf('~/') === 0) {
41
+ fileName = core_1.path.join(core_1.knownFolders.currentApp().path, fileName.replace('~/', ''));
42
+ }
43
+ this.nativeView = SVGKImage.imageWithContentsOfFile(fileName);
44
+ return this.nativeView != null;
45
+ }
46
+ fromFile(filePath) {
47
+ return new Promise((resolve, reject) => {
48
+ try {
49
+ let fileName = typeof filePath === 'string' ? filePath.trim() : '';
50
+ if (fileName.indexOf('~/') === 0) {
51
+ fileName = core_1.path.join(core_1.knownFolders.currentApp().path, fileName.replace('~/', ''));
52
+ }
53
+ SVGKImage.imageWithContentsOfFileAsynchronously(fileName, image => {
54
+ this.nativeView = image;
55
+ resolve(true);
56
+ });
57
+ }
58
+ catch (ex) {
59
+ reject(ex);
60
+ }
61
+ });
62
+ }
63
+ loadFromData(data) {
64
+ this.nativeView = SVGKImage.imageWithData(data);
65
+ return this.nativeView != null;
66
+ }
67
+ fromData(data) {
68
+ return new Promise((resolve, reject) => {
69
+ try {
70
+ SVGKImage.imageWithDataAsynchronously(data, image => {
71
+ this.nativeView = image;
72
+ resolve(true);
73
+ });
74
+ }
75
+ catch (ex) {
76
+ reject(ex);
77
+ }
78
+ });
79
+ }
80
+ loadFromBase64(source) {
81
+ if (typeof source === 'string') {
82
+ const data = NSData.alloc().initWithBase64EncodedStringOptions(source, 1);
83
+ this.nativeView = SVGKImage.imageWithData(data);
84
+ }
85
+ return this.nativeView != null;
86
+ }
87
+ fromBase64(source) {
88
+ return new Promise((resolve, reject) => {
89
+ try {
90
+ const data = NSData.alloc().initWithBase64EncodedStringOptions(source, 1);
91
+ SVGKImage.imageWithDataAsynchronously(data, image => {
92
+ this.nativeView = image;
93
+ resolve(true);
94
+ });
95
+ }
96
+ catch (ex) {
97
+ reject(ex);
98
+ }
99
+ });
100
+ }
101
+ loadFromUrl(url) {
102
+ this.nativeView = SVGKImage.imageWithContentsOfURL(NSURL.URLWithString(url));
103
+ return this.nativeView != null;
104
+ }
105
+ fromUrl(url) {
106
+ return new Promise((resolve, reject) => {
107
+ resolve(this.loadFromUrl(url));
108
+ });
109
+ }
110
+ setNativeSource(source) {
111
+ this.nativeView = source;
112
+ return source != null;
113
+ }
114
+ saveToFile(filePath) {
115
+ if (!this.nativeView) {
116
+ return false;
117
+ }
118
+ const data = getImageData(this.nativeView);
119
+ return false;
120
+ }
121
+ toBase64String(format) {
122
+ const res = null;
123
+ if (!this.nativeView) {
124
+ return res;
125
+ }
126
+ const data = getImageData(this.nativeView);
127
+ return res;
128
+ }
129
+ get height() {
130
+ if (this.nativeView) {
131
+ return this.nativeView.size.height;
132
+ }
133
+ return NaN;
134
+ }
135
+ get width() {
136
+ if (this.nativeView) {
137
+ return this.nativeView.size.width;
138
+ }
139
+ return NaN;
140
+ }
141
+ }
142
+ exports.ImageSourceSVG = ImageSourceSVG;
143
+ function getImageData(instance) {
144
+ const buffer = instance.source.stream;
145
+ throw new Error('Not supported operation');
146
+ }
147
+ class SVGImage extends common.SVGImage {
148
+ constructor() {
149
+ super();
150
+ this._imageSourceAffectsLayout = true;
151
+ this.nativeView = SVGKFastImageView.alloc().initWithSVGKImage(new SVGKImage());
152
+ }
153
+ _setNativeImage(nativeImage) {
154
+ this.nativeView.image = nativeImage.nativeView;
155
+ if (this._imageSourceAffectsLayout) {
156
+ this.requestLayout();
157
+ }
158
+ }
159
+ onMeasure(widthMeasureSpec, heightMeasureSpec) {
160
+ const { layout } = core_1.Utils;
161
+ const width = layout.getMeasureSpecSize(widthMeasureSpec);
162
+ const widthMode = layout.getMeasureSpecMode(widthMeasureSpec);
163
+ const height = layout.getMeasureSpecSize(heightMeasureSpec);
164
+ const heightMode = layout.getMeasureSpecMode(heightMeasureSpec);
165
+ const nativeWidth = this.imageSource ? this.imageSource.width : 0;
166
+ const nativeHeight = this.imageSource ? this.imageSource.height : 0;
167
+ let measureWidth = Math.max(nativeWidth, this.effectiveMinWidth);
168
+ let measureHeight = Math.max(nativeHeight, this.effectiveMinHeight);
169
+ const finiteWidth = widthMode !== layout.UNSPECIFIED;
170
+ const finiteHeight = heightMode !== layout.UNSPECIFIED;
171
+ this._imageSourceAffectsLayout =
172
+ widthMode !== layout.EXACTLY || heightMode !== layout.EXACTLY;
173
+ if (nativeWidth !== 0 &&
174
+ nativeHeight !== 0 &&
175
+ (finiteWidth || finiteHeight)) {
176
+ const resultW = nativeWidth;
177
+ const resultH = nativeHeight;
178
+ measureWidth = finiteWidth ? Math.min(resultW, width) : resultW;
179
+ measureHeight = finiteHeight ? Math.min(resultH, height) : resultH;
180
+ }
181
+ const widthAndState = core_2.View.resolveSizeAndState(measureWidth, width, widthMode, 0);
182
+ const heightAndState = core_2.View.resolveSizeAndState(measureHeight, height, heightMode, 0);
183
+ this.setMeasuredDimension(widthAndState, heightAndState);
184
+ }
185
+ [common.imageSourceProperty.setNative](value) {
186
+ const image = value;
187
+ if (!image || !image.nativeView) {
188
+ return;
189
+ }
190
+ this._setNativeImage(image);
191
+ }
192
+ }
193
+ exports.SVGImage = SVGImage;
194
+ const core_2 = require("@nativescript/core");
195
+ //# sourceMappingURL=svg.ios.js.map