@triniwiz/nativescript-masonkit 1.0.0-alpha.29 → 1.0.0-alpha.31

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/style.js CHANGED
@@ -92,20 +92,36 @@ var StyleKeys;
92
92
  var TextStyleKeys;
93
93
  (function (TextStyleKeys) {
94
94
  TextStyleKeys[TextStyleKeys["COLOR"] = 0] = "COLOR";
95
- TextStyleKeys[TextStyleKeys["DECORATION_LINE"] = 4] = "DECORATION_LINE";
96
- TextStyleKeys[TextStyleKeys["DECORATION_COLOR"] = 8] = "DECORATION_COLOR";
97
- TextStyleKeys[TextStyleKeys["TEXT_ALIGN"] = 12] = "TEXT_ALIGN";
98
- TextStyleKeys[TextStyleKeys["TEXT_JUSTIFY"] = 16] = "TEXT_JUSTIFY";
99
- TextStyleKeys[TextStyleKeys["BACKGROUND_COLOR"] = 20] = "BACKGROUND_COLOR";
100
- TextStyleKeys[TextStyleKeys["SIZE"] = 24] = "SIZE";
101
- TextStyleKeys[TextStyleKeys["TRANSFORM"] = 28] = "TRANSFORM";
102
- TextStyleKeys[TextStyleKeys["FONT_STYLE_TYPE"] = 32] = "FONT_STYLE_TYPE";
103
- TextStyleKeys[TextStyleKeys["FONT_STYLE_SLANT"] = 36] = "FONT_STYLE_SLANT";
104
- TextStyleKeys[TextStyleKeys["TEXT_WRAP"] = 40] = "TEXT_WRAP";
105
- TextStyleKeys[TextStyleKeys["TEXT_OVERFLOW"] = 44] = "TEXT_OVERFLOW";
106
- TextStyleKeys[TextStyleKeys["DECORATION_STYLE"] = 48] = "DECORATION_STYLE";
107
- TextStyleKeys[TextStyleKeys["WHITE_SPACE"] = 52] = "WHITE_SPACE";
108
- TextStyleKeys[TextStyleKeys["FONT_WEIGHT"] = 56] = "FONT_WEIGHT";
95
+ TextStyleKeys[TextStyleKeys["COLOR_STATE"] = 4] = "COLOR_STATE";
96
+ TextStyleKeys[TextStyleKeys["SIZE"] = 8] = "SIZE";
97
+ TextStyleKeys[TextStyleKeys["SIZE_TYPE"] = 12] = "SIZE_TYPE";
98
+ TextStyleKeys[TextStyleKeys["SIZE_STATE"] = 13] = "SIZE_STATE";
99
+ TextStyleKeys[TextStyleKeys["FONT_WEIGHT"] = 16] = "FONT_WEIGHT";
100
+ TextStyleKeys[TextStyleKeys["FONT_WEIGHT_STATE"] = 20] = "FONT_WEIGHT_STATE";
101
+ TextStyleKeys[TextStyleKeys["FONT_STYLE_TYPE"] = 24] = "FONT_STYLE_TYPE";
102
+ TextStyleKeys[TextStyleKeys["FONT_STYLE_STATE"] = 28] = "FONT_STYLE_STATE";
103
+ TextStyleKeys[TextStyleKeys["BACKGROUND_COLOR"] = 32] = "BACKGROUND_COLOR";
104
+ TextStyleKeys[TextStyleKeys["BACKGROUND_COLOR_STATE"] = 36] = "BACKGROUND_COLOR_STATE";
105
+ TextStyleKeys[TextStyleKeys["DECORATION_LINE"] = 40] = "DECORATION_LINE";
106
+ TextStyleKeys[TextStyleKeys["DECORATION_LINE_STATE"] = 44] = "DECORATION_LINE_STATE";
107
+ TextStyleKeys[TextStyleKeys["DECORATION_COLOR"] = 48] = "DECORATION_COLOR";
108
+ TextStyleKeys[TextStyleKeys["DECORATION_COLOR_STATE"] = 52] = "DECORATION_COLOR_STATE";
109
+ TextStyleKeys[TextStyleKeys["DECORATION_STYLE"] = 56] = "DECORATION_STYLE";
110
+ TextStyleKeys[TextStyleKeys["DECORATION_STYLE_STATE"] = 60] = "DECORATION_STYLE_STATE";
111
+ TextStyleKeys[TextStyleKeys["LETTER_SPACING"] = 64] = "LETTER_SPACING";
112
+ TextStyleKeys[TextStyleKeys["LETTER_SPACING_STATE"] = 68] = "LETTER_SPACING_STATE";
113
+ TextStyleKeys[TextStyleKeys["TEXT_WRAP"] = 72] = "TEXT_WRAP";
114
+ TextStyleKeys[TextStyleKeys["TEXT_WRAP_STATE"] = 76] = "TEXT_WRAP_STATE";
115
+ TextStyleKeys[TextStyleKeys["WHITE_SPACE"] = 80] = "WHITE_SPACE";
116
+ TextStyleKeys[TextStyleKeys["WHITE_SPACE_STATE"] = 84] = "WHITE_SPACE_STATE";
117
+ TextStyleKeys[TextStyleKeys["TRANSFORM"] = 88] = "TRANSFORM";
118
+ TextStyleKeys[TextStyleKeys["TRANSFORM_STATE"] = 92] = "TRANSFORM_STATE";
119
+ TextStyleKeys[TextStyleKeys["TEXT_ALIGN"] = 96] = "TEXT_ALIGN";
120
+ TextStyleKeys[TextStyleKeys["TEXT_ALIGN_STATE"] = 100] = "TEXT_ALIGN_STATE";
121
+ TextStyleKeys[TextStyleKeys["TEXT_JUSTIFY"] = 104] = "TEXT_JUSTIFY";
122
+ TextStyleKeys[TextStyleKeys["TEXT_JUSTIFY_STATE"] = 108] = "TEXT_JUSTIFY_STATE";
123
+ TextStyleKeys[TextStyleKeys["TEXT_INDENT"] = 112] = "TEXT_INDENT";
124
+ TextStyleKeys[TextStyleKeys["TEXT_INDENT_STATE"] = 116] = "TEXT_INDENT_STATE";
109
125
  })(TextStyleKeys || (TextStyleKeys = {}));
110
126
  function parseLengthPercentageAuto(type, value) {
111
127
  switch (type) {
@@ -206,11 +222,17 @@ TextStateKeys.TEXT_OVERFLOW = new TextStateKeys(1n << 11n);
206
222
  TextStateKeys.DECORATION_STYLE = new TextStateKeys(1n << 12n);
207
223
  TextStateKeys.WHITE_SPACE = new TextStateKeys(1n << 13n);
208
224
  TextStateKeys.FONT_WEIGHT = new TextStateKeys(1n << 14n);
209
- const getUint16 = (view, offset) => {
210
- return view.getUint16(offset, true);
225
+ const getInt8 = (view, offset) => {
226
+ return view.getInt8(offset);
211
227
  };
212
- const setUint16 = (view, offset, value) => {
213
- view.setUint16(offset, value, true);
228
+ const setInt8 = (view, offset, value) => {
229
+ view.setInt8(offset, value);
230
+ };
231
+ const getUint8 = (view, offset) => {
232
+ return view.getUint8(offset);
233
+ };
234
+ const setUint8 = (view, offset, value) => {
235
+ view.setUint8(offset, value);
214
236
  };
215
237
  const getInt16 = (view, offset) => {
216
238
  return view.getInt16(offset, true);
@@ -242,45 +264,37 @@ export class Style {
242
264
  this.isTextDirty = -1n;
243
265
  this.inBatch = false;
244
266
  }
245
- static fromView(view, nativeView, isText = false) {
267
+ static fromView(view, nativeView) {
246
268
  //console.time('fromView');
247
269
  const ret = new Style();
248
270
  ret.view_ = view;
249
271
  if (__ANDROID__) {
250
272
  const style = nativeView.getStyle();
251
- if (!isText) {
252
- const styleBuffer = style.getValues();
253
- const buffer = ArrayBuffer.from(styleBuffer);
254
- ret.style_view = new DataView(buffer);
255
- }
256
- else {
257
- const styleBuffer = style.getValues();
258
- const buffer = ArrayBuffer.from(styleBuffer);
259
- ret.style_view = new DataView(buffer);
260
- const textStyleBuffer = nativeView.getTextValues();
261
- const textBuffer = ArrayBuffer.from(textStyleBuffer);
262
- ret.text_style_view = new DataView(textBuffer);
263
- }
273
+ const styleBuffer = style.getValues();
274
+ const buffer = ArrayBuffer.from(styleBuffer);
275
+ ret.style_view = new DataView(buffer);
276
+ const textStyleBuffer = style.getTextValues();
277
+ const textBuffer = ArrayBuffer.from(textStyleBuffer);
278
+ ret.text_style_view = new DataView(textBuffer);
264
279
  }
265
280
  else if (__APPLE__) {
266
281
  // todo
267
282
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
268
283
  const style = nativeView.style;
269
- if (!isText) {
270
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
271
- const styleBuffer = style.valuesCompat;
272
- const buffer = interop.bufferFromData(styleBuffer);
273
- ret.style_view = new DataView(buffer);
274
- }
275
- else {
276
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
277
- const styleBuffer = style.valuesCompat;
278
- const buffer = interop.bufferFromData(styleBuffer);
279
- ret.style_view = new DataView(buffer);
280
- const textStyleBuffer = nativeView.textValues;
281
- const textBuffer = interop.bufferFromData(textStyleBuffer);
282
- ret.text_style_view = new DataView(textBuffer);
283
- }
284
+ // if (!isText) {
285
+ // // eslint-disable-next-line @typescript-eslint/ban-ts-comment
286
+ // const styleBuffer = style.valuesCompat;
287
+ // const buffer = interop.bufferFromData(styleBuffer);
288
+ // ret.style_view = new DataView(buffer);
289
+ // } else {
290
+ // // eslint-disable-next-line @typescript-eslint/ban-ts-comment
291
+ // const styleBuffer = style.valuesCompat;
292
+ // const buffer = interop.bufferFromData(styleBuffer);
293
+ // ret.style_view = new DataView(buffer);
294
+ // const textStyleBuffer = (nativeView as MasonText).textValues;
295
+ // const textBuffer = interop.bufferFromData(textStyleBuffer);
296
+ // ret.text_style_view = new DataView(textBuffer);
297
+ // }
284
298
  }
285
299
  //console.timeEnd('fromView');
286
300
  return ret;
@@ -289,28 +303,21 @@ export class Style {
289
303
  this.isDirty = -1n;
290
304
  this.isTextDirty = -1n;
291
305
  }
292
- syncStyle(isText = false) {
306
+ syncStyle() {
293
307
  if (__ANDROID__) {
294
- if (!isText) {
295
- const view = this.view.android;
296
- view.syncStyle(this.isDirty.toString());
297
- }
298
- else {
299
- const view = this.view.android;
300
- view.syncStyle(this.isDirty.toString(), this.isTextDirty.toString());
301
- }
308
+ const view = this.view.android;
309
+ view.syncStyle(this.isDirty.toString(), this.isTextDirty.toString());
302
310
  }
303
311
  else if (__APPLE__) {
304
- if (!isText) {
305
- const view = this.view.ios;
306
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
307
- // @ts-ignore
308
- view.syncStyle(this.isDirty.toString());
309
- }
310
- else {
311
- const view = this.view.ios;
312
- view.syncStyleTextState(this.isDirty.toString(), this.isTextDirty.toString());
313
- }
312
+ // if (!isText) {
313
+ // const view = this.view.ios as MasonUIView;
314
+ // // eslint-disable-next-line @typescript-eslint/ban-ts-comment
315
+ // // @ts-ignore
316
+ // view.syncStyle(this.isDirty.toString());
317
+ // } else {
318
+ // const view = this.view.ios as never as MasonText;
319
+ // view.syncStyleTextState(this.isDirty.toString(), this.isTextDirty.toString());
320
+ // }
314
321
  }
315
322
  this.resetState();
316
323
  }
@@ -322,7 +329,7 @@ export class Style {
322
329
  this.isDirty = this.isDirty | value.bits;
323
330
  }
324
331
  if (!this.inBatch) {
325
- this.syncStyle(this.text_style_view != null);
332
+ this.syncStyle();
326
333
  }
327
334
  }
328
335
  setOrAppendTextState(value) {
@@ -333,14 +340,14 @@ export class Style {
333
340
  this.isTextDirty = this.isTextDirty | value.bits;
334
341
  }
335
342
  if (!this.inBatch) {
336
- this.syncStyle(this.text_style_view != null);
343
+ this.syncStyle();
337
344
  }
338
345
  }
339
346
  batch(fn) {
340
347
  this.inBatch = true;
341
348
  fn(this);
342
349
  this.inBatch = false;
343
- this.syncStyle(this.text_style_view != null);
350
+ this.syncStyle();
344
351
  }
345
352
  get view() {
346
353
  return this.view_;
@@ -373,14 +380,51 @@ export class Style {
373
380
  // BLACK ?
374
381
  return 16;
375
382
  }
376
- return getFloat32(this.text_style_view, TextStyleKeys.SIZE);
383
+ const type = getUint8(this.text_style_view, TextStyleKeys.SIZE_TYPE);
384
+ const value = getInt32(this.text_style_view, TextStyleKeys.SIZE);
385
+ if (type === 1) {
386
+ return `${value / 100}%`;
387
+ }
388
+ return value;
377
389
  }
378
390
  set fontSize(value) {
379
391
  if (!this.text_style_view) {
380
392
  return;
381
393
  }
382
- setFloat32(this.text_style_view, TextStyleKeys.SIZE, value);
383
- this.setOrAppendTextState(TextStateKeys.SIZE);
394
+ switch (typeof value) {
395
+ case 'number':
396
+ setInt32(this.text_style_view, TextStyleKeys.SIZE, value);
397
+ setInt8(this.text_style_view, TextStyleKeys.SIZE_STATE, 1);
398
+ setInt8(this.text_style_view, TextStyleKeys.SIZE_TYPE, 0);
399
+ this.setOrAppendTextState(TextStateKeys.SIZE);
400
+ break;
401
+ case 'object':
402
+ switch (value.unit) {
403
+ case 'dip':
404
+ setInt32(this.text_style_view, TextStyleKeys.SIZE, value.value);
405
+ setInt8(this.text_style_view, TextStyleKeys.SIZE_STATE, 1);
406
+ setInt8(this.text_style_view, TextStyleKeys.SIZE_TYPE, 0);
407
+ this.setOrAppendTextState(TextStateKeys.SIZE);
408
+ break;
409
+ case 'px':
410
+ setInt32(this.text_style_view, TextStyleKeys.SIZE, layout.toDeviceIndependentPixels(value.value));
411
+ setInt8(this.text_style_view, TextStyleKeys.SIZE_STATE, 1);
412
+ setInt8(this.text_style_view, TextStyleKeys.SIZE_TYPE, 0);
413
+ this.setOrAppendTextState(TextStateKeys.SIZE);
414
+ break;
415
+ case '%':
416
+ setInt32(this.text_style_view, TextStyleKeys.SIZE, value.value * 100);
417
+ setInt8(this.text_style_view, TextStyleKeys.SIZE_STATE, 1);
418
+ setInt8(this.text_style_view, TextStyleKeys.SIZE_TYPE, 1);
419
+ this.setOrAppendTextState(TextStateKeys.SIZE);
420
+ break;
421
+ }
422
+ break;
423
+ }
424
+ if (value && typeof value === 'object') {
425
+ }
426
+ else {
427
+ }
384
428
  }
385
429
  get fontStyle() {
386
430
  if (!this.text_style_view) {
@@ -416,6 +460,7 @@ export class Style {
416
460
  }
417
461
  if (style !== -1) {
418
462
  setInt32(this.text_style_view, TextStyleKeys.FONT_STYLE_TYPE, style);
463
+ setInt8(this.text_style_view, TextStyleKeys.FONT_STYLE_STATE, 1);
419
464
  this.setOrAppendTextState(TextStateKeys.FONT_STYLE);
420
465
  }
421
466
  }
@@ -473,6 +518,7 @@ export class Style {
473
518
  }
474
519
  if (weight !== -1) {
475
520
  setInt32(this.text_style_view, TextStyleKeys.FONT_WEIGHT, weight);
521
+ setInt8(this.text_style_view, TextStyleKeys.FONT_WEIGHT_STATE, 1);
476
522
  this.setOrAppendTextState(TextStateKeys.FONT_WEIGHT);
477
523
  }
478
524
  }
@@ -488,6 +534,7 @@ export class Style {
488
534
  return;
489
535
  }
490
536
  setUint32(this.text_style_view, TextStyleKeys.COLOR, value);
537
+ setInt8(this.text_style_view, TextStyleKeys.COLOR_STATE, 1);
491
538
  this.setOrAppendTextState(TextStateKeys.COLOR);
492
539
  }
493
540
  get backgroundColor() {
@@ -502,6 +549,7 @@ export class Style {
502
549
  return;
503
550
  }
504
551
  setUint32(this.text_style_view, TextStyleKeys.BACKGROUND_COLOR, value);
552
+ setInt8(this.text_style_view, TextStyleKeys.BACKGROUND_COLOR_STATE, 1);
505
553
  this.setOrAppendTextState(TextStateKeys.BACKGROUND_COLOR);
506
554
  }
507
555
  get textWrap() {
@@ -532,6 +580,7 @@ export class Style {
532
580
  }
533
581
  if (wrap !== -1) {
534
582
  setInt32(this.text_style_view, TextStyleKeys.TEXT_WRAP, wrap);
583
+ setInt8(this.text_style_view, TextStyleKeys.TEXT_WRAP_STATE, 1);
535
584
  this.setOrAppendTextState(TextStateKeys.TEXT_WRAP);
536
585
  }
537
586
  }
@@ -623,9 +672,9 @@ export class Style {
623
672
  case 1:
624
673
  return 'row';
625
674
  case 2:
626
- return 'column-reverse';
627
- case 3:
628
675
  return 'row-reverse';
676
+ case 3:
677
+ return 'column-reverse';
629
678
  }
630
679
  }
631
680
  set flexDirection(value) {
@@ -637,10 +686,10 @@ export class Style {
637
686
  case 'row':
638
687
  flex = 1;
639
688
  break;
640
- case 'column-reverse':
689
+ case 'row-reverse':
641
690
  flex = 2;
642
691
  break;
643
- case 'row-reverse':
692
+ case 'column-reverse':
644
693
  flex = 3;
645
694
  break;
646
695
  }