x4js 2.0.25 → 2.0.26

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.
@@ -149,11 +149,17 @@ class SvgItem {
149
149
  */
150
150
 
151
151
  getAttr( name: string ) : string {
152
- return this._dom.getAttribute( name );
152
+ const a = this._dom.getAttribute( name ) || '';
153
+ return a;
153
154
  }
154
155
 
155
156
  getNumAttr( name: string ) {
156
- return parseInt( this._dom.getAttribute( name ) );
157
+ const a = this._dom.getAttribute( name )
158
+ if( a=='' ) {
159
+ return 0;
160
+ }
161
+
162
+ return parseInt( a );
157
163
  }
158
164
 
159
165
  /**
@@ -164,7 +170,12 @@ class SvgItem {
164
170
  */
165
171
 
166
172
  setAttr( name: string, value: string ) : this {
167
- this._dom.setAttribute( name, value );
173
+ if( value===null || value===undefined ) {
174
+ this._dom.removeAttribute( name );
175
+ }
176
+ else {
177
+ this._dom.setAttribute( name, value );
178
+ }
168
179
  return this;
169
180
  }
170
181
 
@@ -238,12 +249,18 @@ class SvgItem {
238
249
  return this;
239
250
  }
240
251
 
252
+
241
253
  /**
242
254
  *
243
255
  */
244
256
 
245
257
  transform( tr: string ): this {
246
- const t = this.getAttr( "transform" ) ?? "";
258
+ this.setAttr( "transform", tr );
259
+ return this;
260
+ }
261
+
262
+ add_transformation( tr: string ): this {
263
+ const t = this.getAttr( "transform" );
247
264
  this.setAttr( "transform", t+' '+tr );
248
265
  return this;
249
266
  }
@@ -262,16 +279,32 @@ class SvgItem {
262
279
  return this;
263
280
  }
264
281
 
282
+ add_rotation( deg: number, cx: number, cy: number ): this {
283
+ this.add_transformation( `rotate( ${deg} ${cx} ${cy} )` );
284
+ return this;
285
+ }
286
+
265
287
  translate( dx: number, dy: number ): this {
266
288
  this.transform( `translate( ${dx} ${dy} )` );
267
289
  return this;
268
290
  }
269
291
 
292
+ add_translation( dx: number, dy: number ): this {
293
+ this.add_transformation( `translate( ${dx} ${dy} )` );
294
+ return this;
295
+ }
296
+
270
297
  scale( x: number ): this {
271
298
  this.transform( `scale( ${x} )` );
272
299
  return this;
273
300
  }
274
301
 
302
+ add_scale( x: number ): this {
303
+ this.add_transformation( `scale( ${x} )` );
304
+ return this;
305
+ }
306
+
307
+
275
308
  /**
276
309
  *
277
310
  */