@shijiu/jsview 1.9.921 → 1.9.943-next-vue.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,919 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var Forge = {};
6
+
7
+ class ErrCode {
8
+ static ToString(value) {
9
+ switch (value) {
10
+ case ErrCode.UnknownError:
11
+ return 'UnknownError(' + value + ')';
12
+ case ErrCode.UnimplementedError:
13
+ return 'UnimplementedError(' + value + ')';
14
+ case ErrCode.UnsupportedError:
15
+ return 'UnsupportedError(' + value + ')';
16
+ case ErrCode.NotFoundError:
17
+ return 'NotFoundError(' + value + ')';
18
+ case ErrCode.InvalidArgument:
19
+ return 'InvalidArgument(' + value + ')';
20
+ case ErrCode.BadArgumentSize:
21
+ return 'BadArgumentSize(' + value + ')';
22
+ case ErrCode.InvalidElement:
23
+ return 'InvalidElement(' + value + ')';
24
+ case ErrCode.BadElementType:
25
+ return 'BadElementType(' + value + ')';
26
+ case ErrCode.CssStyleNotExists:
27
+ return 'CssStyleNotExists(' + value + ')';
28
+ case ErrCode.CssStyleNotChanged:
29
+ return 'CssStyleNotChanged(' + value + ')';
30
+ case ErrCode.CssStyleBadType:
31
+ return 'CssStyleBadType(' + value + ')';
32
+ case ErrCode.CssClassNotChanged:
33
+ return 'CssClassNotChanged(' + value + ')';
34
+ case ErrCode.ForgeInsertView:
35
+ return 'ForgeInsertView(' + value + ')';
36
+ default:
37
+ return ("UnknownError(" + value + ")");
38
+ }
39
+ }
40
+ static GetFormattedMethod(prettyFunction) {
41
+ var begin = 0, length = 0;
42
+ begin = prettyFunction.indexOf(" ") + 1;
43
+ length = prettyFunction.indexOf("(") - begin;
44
+ const method = prettyFunction.substr(begin, length) + "()";
45
+ return method;
46
+ }
47
+ static GetErrorMessage(errMsgs = []) {
48
+ var oss = "";
49
+ for (const item of errMsgs) {
50
+ oss += item;
51
+ }
52
+ return oss;
53
+ }
54
+ static PrintErrorMessage(fileName, fileLine, errMsgs = []) {
55
+ const msg = ErrCode.GetErrorMessage(errMsgs);
56
+ console.error("ForgeDom", "Error@ " + fileName + ":" + fileLine + ", " + msg);
57
+ }
58
+ static UnknownError = -1;
59
+ static UnimplementedError = -2;
60
+ static UnsupportedError = -3;
61
+ static NotFoundError = -4;
62
+ static InvalidArgument = -5;
63
+ static BadArgumentSize = -6;
64
+ static InvalidElement = -100;
65
+ static BadElementType = -101;
66
+ static BadTaskType = -102;
67
+ static CssStyleNotExists = -120;
68
+ static CssStyleNotChanged = -121;
69
+ static CssStyleBadName = -122;
70
+ static CssStyleBadType = -123;
71
+ static CssClassNotChanged = -124;
72
+ static ForgeInsertView = -200;
73
+ /*** private ***/
74
+ constructor() { throw new Error("new ErrCode() is forbidden."); }
75
+ }
76
+ function ASSERT_AND_RETPTR(condition, retPtr, errMsgs = []) {
77
+ ASSERT_AND_RETURN(condition, ErrCode.GetErrorMessage(errMsgs), retPtr);
78
+ }
79
+ function CHECK_AND_RETVAL(errCode, retVal, errMsgs = []) {
80
+ CHECK_AND_RETURN(errCode, ErrCode.GetErrorMessage(errMsgs), retVal);
81
+ }
82
+ function CHECK_AND_RETURN(errCode, errMsgs, ret = undefined) {
83
+ if ((errCode) < 0) {
84
+ ErrCode.PrintErrorMessage("__FILE_NAME__", "__LINE__", [
85
+ ErrCode.ToString(errCode), ". ",
86
+ errMsgs,
87
+ ]);
88
+ throw new Error(ret);
89
+ }
90
+ }
91
+ function ASSERT_AND_RETURN(condition, errMsgs, ret = undefined) {
92
+ if (!(condition)) {
93
+ ErrCode.PrintErrorMessage("__FILE_NAME__", "__LINE__", [
94
+ "ASSERT(" + condition + ")", ". ",
95
+ errMsgs,
96
+ ]);
97
+ throw new Error(ret);
98
+ }
99
+ }
100
+
101
+ class StyleName {
102
+ static Layout = class {
103
+ static Height = "height";
104
+ static Left = "left";
105
+ static Top = "top";
106
+ static Width = "width";
107
+ constructor() { throw new Error("new StyleName.Layout() is forbidden."); }
108
+ };
109
+ static Background = class {
110
+ static BackgroundColor = "backgroundColor";
111
+ static BackgroundImage = "backgroundImage";
112
+ static BorderRadius = "borderRadius";
113
+ constructor() { throw new Error("new StyleName.Background() is forbidden."); }
114
+ };
115
+ static Effect = class {
116
+ static BackfaceVisibility = "backfaceVisibility";
117
+ static BorderImage = "borderImage";
118
+ static BorderImageWidth = "borderImageWidth";
119
+ static BorderImageOutset = "borderImageOutset";
120
+ // static ClipPath: string = "clipPath";
121
+ static Display = "display";
122
+ static ObjectFit = "objectFit";
123
+ static Opacity = "opacity";
124
+ static Overflow = "overflow";
125
+ static Perspective = "perspective";
126
+ static PerspectiveOrigin = "perspectiveOrigin";
127
+ static Transform = "transform";
128
+ static TransformOrigin = "transformOrigin";
129
+ static TransformStyle = "transformStyle";
130
+ static Visibility = "visibility";
131
+ static ZIndex = "zIndex";
132
+ constructor() { throw new Error("new StyleName.Effect() is forbidden."); }
133
+ };
134
+ static Text = class {
135
+ static Color = "color";
136
+ static FontFamily = "fontFamily";
137
+ static FontSize = "fontSize";
138
+ static FontStyle = "fontStyle";
139
+ static FontWeight = "fontWeight";
140
+ static LineHeight = "lineHeight";
141
+ static TextAlign = "textAlign";
142
+ static TextOverflow = "textOverflow";
143
+ static TextShadow = "textShadow";
144
+ static WebkitTextStroke = "WebkitTextStroke";
145
+ static WhiteSpace = "whiteSpace";
146
+ static WordWrap = "wordWrap";
147
+ static Direction = "direction";
148
+ static JsvTextEmoji = "JsvTextEmoji";
149
+ static JsvTextLatex = "JsvTextLatex";
150
+ static JsvTextAlignMinWidth = "JsvTextAlignMinWidth";
151
+ static JsvTextVerticalAlign = "JsvTextVerticalAlign";
152
+ static JsvTextLineAlign = "JsvTextLineAlign";
153
+ static JsvTextInnerDirection = "JsvTextInnerDirection";
154
+ constructor() { throw new Error("new StyleName.Text() is forbidden."); }
155
+ };
156
+ static Motion = class {
157
+ static Animation = "animation";
158
+ static Transition = "transition";
159
+ constructor() { throw new Error("new StyleName.Motion() is forbidden."); }
160
+ };
161
+ static HasGetterMethod(name) {
162
+ switch (name) {
163
+ case StyleName.Layout.Height:
164
+ case StyleName.Layout.Left:
165
+ case StyleName.Layout.Top:
166
+ case StyleName.Layout.Width:
167
+ case StyleName.Effect.ObjectFit:
168
+ return true;
169
+ default:
170
+ return false;
171
+ }
172
+ }
173
+ static ToConst(name) {
174
+ if (name == StyleName.Layout.Height) {
175
+ return StyleName.Layout.Height;
176
+ }
177
+ else if (name == StyleName.Layout.Left) {
178
+ return StyleName.Layout.Left;
179
+ }
180
+ else if (name == StyleName.Layout.Top) {
181
+ return StyleName.Layout.Top;
182
+ }
183
+ else if (name == StyleName.Layout.Width) {
184
+ return StyleName.Layout.Width;
185
+ }
186
+ else if (name == StyleName.Background.BackgroundColor) {
187
+ return StyleName.Background.BackgroundColor;
188
+ }
189
+ else if (name == StyleName.Background.BackgroundImage) {
190
+ return StyleName.Background.BackgroundImage;
191
+ }
192
+ else if (name == StyleName.Background.BorderRadius) {
193
+ return StyleName.Background.BorderRadius;
194
+ }
195
+ else if (name == StyleName.Effect.BackfaceVisibility) {
196
+ return StyleName.Effect.BackfaceVisibility;
197
+ }
198
+ else if (name == StyleName.Effect.BorderImage) {
199
+ return StyleName.Effect.BorderImage;
200
+ }
201
+ else if (name == StyleName.Effect.BorderImageWidth) {
202
+ return StyleName.Effect.BorderImageWidth;
203
+ }
204
+ else if (name == StyleName.Effect.BorderImageOutset) {
205
+ return StyleName.Effect.BorderImageOutset;
206
+ }
207
+ // else if (name == StyleName.Effect.ClipPath) { return StyleName.Effect.ClipPath; }
208
+ else if (name == StyleName.Effect.Display) {
209
+ return StyleName.Effect.Display;
210
+ }
211
+ else if (name == StyleName.Effect.ObjectFit) {
212
+ return StyleName.Effect.ObjectFit;
213
+ }
214
+ else if (name == StyleName.Effect.Opacity) {
215
+ return StyleName.Effect.Opacity;
216
+ }
217
+ else if (name == StyleName.Effect.Overflow) {
218
+ return StyleName.Effect.Overflow;
219
+ }
220
+ else if (name == StyleName.Effect.Perspective) {
221
+ return StyleName.Effect.Perspective;
222
+ }
223
+ else if (name == StyleName.Effect.PerspectiveOrigin) {
224
+ return StyleName.Effect.PerspectiveOrigin;
225
+ }
226
+ else if (name == StyleName.Effect.Transform) {
227
+ return StyleName.Effect.Transform;
228
+ }
229
+ else if (name == StyleName.Effect.TransformOrigin) {
230
+ return StyleName.Effect.TransformOrigin;
231
+ }
232
+ else if (name == StyleName.Effect.TransformStyle) {
233
+ return StyleName.Effect.TransformStyle;
234
+ }
235
+ else if (name == StyleName.Effect.Visibility) {
236
+ return StyleName.Effect.Visibility;
237
+ }
238
+ else if (name == StyleName.Effect.ZIndex) {
239
+ return StyleName.Effect.ZIndex;
240
+ }
241
+ else if (name == StyleName.Text.Color) {
242
+ return StyleName.Text.Color;
243
+ }
244
+ else if (name == StyleName.Text.FontFamily) {
245
+ return StyleName.Text.FontFamily;
246
+ }
247
+ else if (name == StyleName.Text.FontSize) {
248
+ return StyleName.Text.FontSize;
249
+ }
250
+ else if (name == StyleName.Text.FontStyle) {
251
+ return StyleName.Text.FontStyle;
252
+ }
253
+ else if (name == StyleName.Text.FontWeight) {
254
+ return StyleName.Text.FontWeight;
255
+ }
256
+ else if (name == StyleName.Text.LineHeight) {
257
+ return StyleName.Text.LineHeight;
258
+ }
259
+ else if (name == StyleName.Text.TextAlign) {
260
+ return StyleName.Text.TextAlign;
261
+ }
262
+ else if (name == StyleName.Text.TextOverflow) {
263
+ return StyleName.Text.TextOverflow;
264
+ }
265
+ else if (name == StyleName.Text.TextShadow) {
266
+ return StyleName.Text.TextShadow;
267
+ }
268
+ else if (name == StyleName.Text.WebkitTextStroke) {
269
+ return StyleName.Text.WebkitTextStroke;
270
+ }
271
+ else if (name == StyleName.Text.WhiteSpace) {
272
+ return StyleName.Text.WhiteSpace;
273
+ }
274
+ else if (name == StyleName.Text.WordWrap) {
275
+ return StyleName.Text.WordWrap;
276
+ }
277
+ else if (name == StyleName.Text.Direction) {
278
+ return StyleName.Text.Direction;
279
+ }
280
+ else if (name == StyleName.Text.JsvTextEmoji) {
281
+ return StyleName.Text.JsvTextEmoji;
282
+ }
283
+ else if (name == StyleName.Text.JsvTextLatex) {
284
+ return StyleName.Text.JsvTextLatex;
285
+ }
286
+ else if (name == StyleName.Text.JsvTextAlignMinWidth) {
287
+ return StyleName.Text.JsvTextAlignMinWidth;
288
+ }
289
+ else if (name == StyleName.Text.JsvTextVerticalAlign) {
290
+ return StyleName.Text.JsvTextVerticalAlign;
291
+ }
292
+ else if (name == StyleName.Text.JsvTextLineAlign) {
293
+ return StyleName.Text.JsvTextLineAlign;
294
+ }
295
+ else if (name == StyleName.Text.JsvTextInnerDirection) {
296
+ return StyleName.Text.JsvTextInnerDirection;
297
+ }
298
+ else if (name == StyleName.Motion.Animation) {
299
+ return StyleName.Motion.Animation;
300
+ }
301
+ else if (name == StyleName.Motion.Transition) {
302
+ return StyleName.Motion.Transition;
303
+ }
304
+ return null;
305
+ }
306
+ constructor() { throw new Error("new StyleName() is forbidden."); }
307
+ }
308
+ class StyleValue {
309
+ static Base = class {
310
+ constructor(rawValue) {
311
+ this.rawValue = rawValue;
312
+ }
313
+ rawValue;
314
+ };
315
+ static AnimationImpl = class extends StyleValue.Base {
316
+ constructor(rawValue) {
317
+ super(rawValue);
318
+ }
319
+ name = "";
320
+ duration = 0;
321
+ timingFunction = null;
322
+ delay = 0;
323
+ iterationCount = 0;
324
+ direction = false;
325
+ };
326
+ static CornerImpl = class extends StyleValue.Base {
327
+ constructor(rawValue) {
328
+ super(rawValue);
329
+ }
330
+ topLeft = 0;
331
+ topRight = 0;
332
+ bottomRight = 0;
333
+ bottomLeft = 0;
334
+ };
335
+ static RectImpl = class extends StyleValue.Base {
336
+ constructor(rawValue) {
337
+ super(rawValue);
338
+ }
339
+ top = 0;
340
+ right = 0;
341
+ left = 0;
342
+ bottom = 0;
343
+ };
344
+ static TextShadowImpl = class extends StyleValue.Base {
345
+ constructor(rawValue) {
346
+ super(rawValue);
347
+ }
348
+ hShadow = 0;
349
+ vShadow = 0;
350
+ blur = 0;
351
+ color = undefined;
352
+ };
353
+ static WebkitTextStrokeImpl = class extends StyleValue.Base {
354
+ constructor(rawValue) {
355
+ super(rawValue);
356
+ }
357
+ length = 0;
358
+ color = undefined;
359
+ };
360
+ static TransitionImpl = class extends StyleValue.Base {
361
+ constructor(rawValue) {
362
+ super(rawValue);
363
+ }
364
+ animationMap = new Map();
365
+ };
366
+ static BorderImageImpl = class extends StyleValue.Base {
367
+ constructor(rawValue) {
368
+ super(rawValue);
369
+ }
370
+ source = "";
371
+ slice = null;
372
+ };
373
+ static DataType = class {
374
+ static Null = 0;
375
+ static Int32 = 1;
376
+ static Float = 2;
377
+ static String = 3;
378
+ static Animation = 4;
379
+ static Corner = 5;
380
+ static Rect = 6;
381
+ static TextShadow = 7;
382
+ static WebkitTextStroke = 8;
383
+ static Transition = 9;
384
+ static BorderImage = 10;
385
+ };
386
+ static InvalidInt32 = Number.MIN_VALUE;
387
+ static InvalidFloat = Number.NaN;
388
+ static InvalidPointer = null;
389
+ constructor(data) {
390
+ let index = -1;
391
+ let value = null;
392
+ if (data == null) {
393
+ index = StyleValue.DataType.Null;
394
+ }
395
+ else if (Number(data) === data && data % 1 === 0) {
396
+ index = StyleValue.DataType.Int32;
397
+ }
398
+ else if (Number(data) === data && data % 1 !== 0) {
399
+ index = StyleValue.DataType.Float;
400
+ }
401
+ else if (typeof data === 'string' || data instanceof String) {
402
+ index = StyleValue.DataType.String;
403
+ }
404
+ else if (data instanceof StyleValue.AnimationImpl) {
405
+ index = StyleValue.DataType.Animation;
406
+ }
407
+ else if (data instanceof StyleValue.CornerImpl) {
408
+ index = StyleValue.DataType.Corner;
409
+ }
410
+ else if (data instanceof StyleValue.RectImpl) {
411
+ index = StyleValue.DataType.Rect;
412
+ }
413
+ else if (data instanceof StyleValue.TextShadowImpl) {
414
+ index = StyleValue.DataType.TextShadow;
415
+ }
416
+ else if (data instanceof StyleValue.WebkitTextStrokeImpl) {
417
+ index = StyleValue.DataType.WebkitTextStroke;
418
+ }
419
+ else if (data instanceof StyleValue.TransitionImpl) {
420
+ index = StyleValue.DataType.Transition;
421
+ }
422
+ else if (data instanceof StyleValue.BorderImageImpl) {
423
+ index = StyleValue.DataType.BorderImage;
424
+ }
425
+ if (data != StyleValue.InvalidInt32
426
+ && data != StyleValue.InvalidFloat
427
+ && data != StyleValue.InvalidPointer) {
428
+ value = data;
429
+ }
430
+ else {
431
+ index = StyleValue.DataType.Null;
432
+ value = null;
433
+ }
434
+ this.data = new StyleValue.DataInfo();
435
+ this.data.index = index;
436
+ this.data.value = value;
437
+ }
438
+ is(type) {
439
+ return this.data.index == type;
440
+ }
441
+ get() {
442
+ return this.data.value;
443
+ }
444
+ reset(rhs) {
445
+ this.data.value = rhs.data.value;
446
+ this.data.index = rhs.data.index;
447
+ }
448
+ equals(rhs) {
449
+ return (this.data.value === rhs.data.value
450
+ && this.data.index === rhs.data.index);
451
+ }
452
+ static DataInfo = class {
453
+ value = null;
454
+ index = -1;
455
+ };
456
+ data;
457
+ }
458
+ class StyleVariable {
459
+ static FormatVariableName(varName) {
460
+ if (varName.startsWith('--')) {
461
+ return 'var(' + varName + ')'; // var(--xxx)
462
+ }
463
+ else if (varName.startsWith('var(--')) {
464
+ return varName;
465
+ }
466
+ ASSERT_AND_RETPTR(false, null);
467
+ return null;
468
+ }
469
+ static IsVariable(value) {
470
+ let variable;
471
+ if (value instanceof StyleValue) {
472
+ if (value.is(StyleValue.DataType.String) == false) {
473
+ return false;
474
+ }
475
+ variable = value.get();
476
+ }
477
+ else if (typeof value === 'string') {
478
+ variable = value;
479
+ }
480
+ else {
481
+ return false;
482
+ }
483
+ const isVar = (variable.startsWith("--") || variable.startsWith("var(--"));
484
+ return isVar;
485
+ }
486
+ constructor() { throw new Error("new StyleVariable() is forbidden."); }
487
+ }
488
+
489
+ class StyleFormator {
490
+ /*** public ***/
491
+ static StringToInt32(value) {
492
+ let ret = StyleValue.InvalidInt32;
493
+ let int32Value = parseInt(value);
494
+ if (isNaN(int32Value) == false) {
495
+ ret = int32Value;
496
+ }
497
+ return ret;
498
+ }
499
+ static StringTrim(value) {
500
+ return value.trim();
501
+ }
502
+ static StringStartsWith(value, starting) {
503
+ return value.startsWith(starting);
504
+ }
505
+ static StringEndsWith(value, ending) {
506
+ return value.endsWith(ending);
507
+ }
508
+ static StringSplit(from, delimiter = " ") {
509
+ if (!from) {
510
+ from = "";
511
+ }
512
+ let arrays = from.trim().split(delimiter);
513
+ if (delimiter !== ' ') {
514
+ return arrays;
515
+ }
516
+ //去除多个空格的条件下的影响
517
+ let ret = [];
518
+ for (let item of arrays) {
519
+ if (!item) {
520
+ continue;
521
+ }
522
+ ret.push(item);
523
+ }
524
+ return ret;
525
+ }
526
+ static ConvertToInt32(value) {
527
+ if (value.is(StyleValue.DataType.Null)) {
528
+ return 0;
529
+ }
530
+ else if (value.is(StyleValue.DataType.String)) {
531
+ const strValue = value.get();
532
+ if (strValue === "") {
533
+ return 0;
534
+ }
535
+ else {
536
+ StyleFormator.StringTrim(strValue);
537
+ if (StyleFormator.StringEndsWith(strValue, "px")) {
538
+ const msg = 'JsView Warning:'
539
+ + ' Using px will make style performance lower,'
540
+ + ' you can directly use numbers instead of "' + strValue + '".';
541
+ console.warn(msg);
542
+ return StyleFormator.StringToInt32(strValue);
543
+ }
544
+ }
545
+ }
546
+ else if (value.is(StyleValue.DataType.Int32)) {
547
+ return value.get();
548
+ }
549
+ else if (value.is(StyleValue.DataType.Float)) {
550
+ return value.get();
551
+ }
552
+ CHECK_AND_RETVAL(ErrCode.InvalidArgument, StyleValue.InvalidInt32);
553
+ return StyleValue.InvalidInt32;
554
+ }
555
+ static ConvertToFloat(value) {
556
+ if (value.is(StyleValue.DataType.Null)) {
557
+ return StyleValue.InvalidFloat;
558
+ }
559
+ else if (value.is(StyleValue.DataType.String) && value.get() === "") {
560
+ return 0;
561
+ }
562
+ else if (value.is(StyleValue.DataType.Int32)) {
563
+ return value.get();
564
+ }
565
+ else if (value.is(StyleValue.DataType.Float)) {
566
+ return value.get();
567
+ }
568
+ CHECK_AND_RETVAL(ErrCode.InvalidArgument, StyleValue.InvalidFloat);
569
+ return StyleValue.InvalidFloat;
570
+ }
571
+ static ConvertToString(value, upperCase = false) {
572
+ if (value.is(StyleValue.DataType.Null)) {
573
+ return StyleValue.InvalidPointer;
574
+ }
575
+ if (value.is(StyleValue.DataType.String) == false) {
576
+ CHECK_AND_RETVAL(ErrCode.InvalidArgument, StyleValue.InvalidPointer);
577
+ }
578
+ let propValue = value.get();
579
+ if (propValue == null || propValue.length <= 0) {
580
+ return StyleValue.InvalidPointer;
581
+ }
582
+ if (upperCase) {
583
+ propValue = propValue.toUpperCase();
584
+ }
585
+ return propValue;
586
+ }
587
+ static ConvertToCorner(value) {
588
+ if (value.is(StyleValue.DataType.Null)) {
589
+ return StyleValue.InvalidPointer;
590
+ }
591
+ let corner = null;
592
+ if (value.is(StyleValue.DataType.Int32)) {
593
+ const propValue = value.get();
594
+ corner = new StyleValue.CornerImpl(String(propValue));
595
+ corner.topLeft = propValue;
596
+ corner.topRight = propValue;
597
+ corner.bottomRight = propValue;
598
+ corner.bottomLeft = propValue;
599
+ }
600
+ else if (value.is(StyleValue.DataType.String)) {
601
+ const propValue = value.get();
602
+ if (propValue == null || propValue.length <= 0) {
603
+ return StyleValue.InvalidPointer;
604
+ }
605
+ const propValueArray = StyleFormator.StringSplit(propValue);
606
+ const propValueSize = propValueArray.length;
607
+ corner = new StyleValue.CornerImpl(propValue);
608
+ corner.topLeft = (propValueSize > 0 ? parseInt(propValueArray[0]) : 0);
609
+ corner.topRight = (propValueSize > 1 ? parseInt(propValueArray[1]) : corner.topLeft);
610
+ corner.bottomRight = (propValueSize > 2 ? parseInt(propValueArray[2]) : corner.topLeft);
611
+ corner.bottomLeft = (propValueSize > 3 ? parseInt(propValueArray[3]) : corner.bottomRight);
612
+ }
613
+ else {
614
+ CHECK_AND_RETVAL(ErrCode.InvalidArgument, StyleValue.InvalidPointer);
615
+ }
616
+ return corner;
617
+ }
618
+ static ConvertToRect(value) {
619
+ if (value.is(StyleValue.DataType.Null)) {
620
+ return StyleValue.InvalidPointer;
621
+ }
622
+ if (value.is(StyleValue.DataType.String) == false) {
623
+ CHECK_AND_RETVAL(ErrCode.InvalidArgument, StyleValue.InvalidPointer);
624
+ }
625
+ const propValue = value.get();
626
+ if (propValue == null || propValue.length <= 0) {
627
+ return StyleValue.InvalidPointer;
628
+ }
629
+ const rect = new StyleValue.RectImpl(propValue);
630
+ const propValueArray = StyleFormator.StringSplit(propValue);
631
+ const propValueSize = propValueArray.length;
632
+ rect.top = (propValueSize > 0 ? parseInt(propValueArray[0]) : 0);
633
+ rect.right = (propValueSize > 1 ? parseInt(propValueArray[1]) : rect.top);
634
+ rect.bottom = (propValueSize > 2 ? parseInt(propValueArray[2]) : rect.top);
635
+ rect.left = (propValueSize > 3 ? parseInt(propValueArray[3]) : rect.right);
636
+ return rect;
637
+ }
638
+ static ConvertToAnimation(value, compare = null) {
639
+ if (value.is(StyleValue.DataType.Null)) {
640
+ return StyleValue.InvalidPointer;
641
+ }
642
+ if (value.is(StyleValue.DataType.String) == false) {
643
+ CHECK_AND_RETVAL(ErrCode.InvalidArgument, StyleValue.InvalidPointer);
644
+ }
645
+ const propValue = value.get();
646
+ if (propValue == null || propValue.length <= 0) {
647
+ return StyleValue.InvalidPointer;
648
+ }
649
+ // 和compare相同,直接返回compare加速
650
+ if (compare != null && compare.rawValue != null
651
+ && compare.rawValue == propValue) {
652
+ return compare;
653
+ }
654
+ const anim = StyleFormator.ParseToAnimation(propValue);
655
+ return anim;
656
+ }
657
+ static ConvertToTransition(value, compare = null) {
658
+ if (value.is(StyleValue.DataType.Null)) {
659
+ return StyleValue.InvalidPointer;
660
+ }
661
+ if (value.is(StyleValue.DataType.String) == false) {
662
+ CHECK_AND_RETVAL(ErrCode.InvalidArgument, StyleValue.InvalidPointer);
663
+ }
664
+ const propValue = value.get();
665
+ if (propValue == null || propValue.length <= 0) {
666
+ return StyleValue.InvalidPointer;
667
+ }
668
+ // 和compare相同,直接返回compare加速
669
+ if (compare != null && compare.rawValue != null
670
+ && compare.rawValue == propValue) {
671
+ return compare;
672
+ }
673
+ let arrays = [];
674
+ const splitStr = StyleFormator.StringSplit(propValue, ",");
675
+ // 如果包含"(", 则将直到")"为止的内容当作一个部分
676
+ for (let idx = 0; idx < splitStr.length; idx++) {
677
+ if (splitStr[idx].indexOf('(') >= 0) {
678
+ let endIdx = idx;
679
+ while (endIdx < splitStr.length && splitStr[endIdx].indexOf(')') < 0) { // 没有包含")"
680
+ endIdx++;
681
+ }
682
+ let concatStr = "";
683
+ for (let subIdx = idx; subIdx <= endIdx; subIdx++) {
684
+ if (subIdx != idx) {
685
+ concatStr += ",";
686
+ }
687
+ concatStr += splitStr[subIdx];
688
+ }
689
+ idx = endIdx;
690
+ arrays.push(concatStr);
691
+ }
692
+ else {
693
+ arrays.push(splitStr[idx]);
694
+ }
695
+ }
696
+ // console.warn("StyleFormator.ConvertToTransition() arrays=" + JSON.stringify(arrays));
697
+ const transition = new StyleValue.TransitionImpl(propValue);
698
+ for (const item of arrays) {
699
+ const ret = StyleFormator.ConvertToAnimation(new StyleValue(item));
700
+ if (ret == null) {
701
+ continue;
702
+ }
703
+ transition.animationMap.set(ret.name, ret);
704
+ if (ret?.name == "all") {
705
+ const allProps = ["opacity", "left", "top", "width", "height", "transform"];
706
+ for (const prop of allProps) {
707
+ transition.animationMap.set(prop, ret);
708
+ }
709
+ }
710
+ }
711
+ return transition;
712
+ }
713
+ static ConvertToTextShadow(value) {
714
+ if (value.is(StyleValue.DataType.Null)) {
715
+ return StyleValue.InvalidPointer;
716
+ }
717
+ if (value.is(StyleValue.DataType.String) == false) {
718
+ CHECK_AND_RETVAL(ErrCode.InvalidArgument, StyleValue.InvalidPointer);
719
+ }
720
+ const propValue = value.get();
721
+ if (propValue == null || propValue.length <= 0) {
722
+ return StyleValue.InvalidPointer;
723
+ }
724
+ const textShadow = new StyleValue.TextShadowImpl(propValue);
725
+ const textShadowArray = StyleFormator.StringSplit(propValue);
726
+ if (textShadowArray.length > 0) {
727
+ textShadow.hShadow = parseInt(textShadowArray[0]);
728
+ }
729
+ if (textShadowArray.length > 1) {
730
+ textShadow.vShadow = parseInt(textShadowArray[1]);
731
+ }
732
+ if (textShadowArray.length > 2) {
733
+ textShadow.blur = parseInt(textShadowArray[2]);
734
+ }
735
+ let colorIndex = -1;
736
+ if (textShadowArray.length == 3) {
737
+ colorIndex = 2;
738
+ }
739
+ else if (textShadowArray.length > 3) {
740
+ colorIndex = 3;
741
+ }
742
+ if (colorIndex > 0) {
743
+ textShadow.color = textShadowArray[colorIndex];
744
+ }
745
+ return textShadow;
746
+ }
747
+ static ConvertToWebkitTextStroke(value) {
748
+ if (value.is(StyleValue.DataType.Null)) {
749
+ return StyleValue.InvalidPointer;
750
+ }
751
+ if (value.is(StyleValue.DataType.String) == false) {
752
+ CHECK_AND_RETVAL(ErrCode.InvalidArgument, StyleValue.InvalidPointer);
753
+ }
754
+ const propValue = value.get();
755
+ if (propValue == null || propValue.length <= 0) {
756
+ return StyleValue.InvalidPointer;
757
+ }
758
+ const webkitTextStroke = new StyleValue.WebkitTextStrokeImpl(propValue);
759
+ const webkitTextStrokeArray = StyleFormator.StringSplit(propValue);
760
+ if (webkitTextStrokeArray.length > 0) {
761
+ webkitTextStroke.length = parseInt(webkitTextStrokeArray[0]);
762
+ }
763
+ if (webkitTextStrokeArray.length > 1) {
764
+ webkitTextStroke.color = webkitTextStrokeArray[1];
765
+ }
766
+ return webkitTextStroke;
767
+ }
768
+ static ConvertToBorderImage(value) {
769
+ if (value.is(StyleValue.DataType.Null)) {
770
+ return StyleValue.InvalidPointer;
771
+ }
772
+ if (value.is(StyleValue.DataType.String) == false) {
773
+ CHECK_AND_RETVAL(ErrCode.InvalidArgument, StyleValue.InvalidPointer);
774
+ }
775
+ const propValue = value.get();
776
+ if (propValue == null || propValue.length <= 0) {
777
+ return StyleValue.InvalidPointer;
778
+ }
779
+ const borderImage = new StyleValue.BorderImageImpl(propValue);
780
+ const propValueArray = StyleFormator.StringSplit(propValue);
781
+ const propValueSize = propValueArray.length;
782
+ if (propValueSize > 0) {
783
+ borderImage.source = propValueArray[0];
784
+ }
785
+ if (propValueSize > 1) {
786
+ borderImage.slice = StyleFormator.ConvertToRect(new StyleValue(propValueArray[1]));
787
+ }
788
+ return borderImage;
789
+ }
790
+ static ParseToAnimation(value) {
791
+ const trimmed = StyleFormator.StringTrim(value);
792
+ let arrays = [];
793
+ const bezierStart = trimmed.indexOf("cubic-bezier");
794
+ if (bezierStart >= 0) { // 防止贝塞尔里面的空格被拆分
795
+ const bezierEnd = trimmed.indexOf(')');
796
+ const bezierStr = trimmed.substring(bezierStart, bezierEnd - 1);
797
+ const bezierArray = StyleFormator.StringSplit(trimmed, bezierStr);
798
+ for (const item of bezierArray) {
799
+ const subArrays = StyleFormator.StringSplit(item);
800
+ arrays.concat(subArrays);
801
+ }
802
+ arrays.push(bezierStr);
803
+ }
804
+ else {
805
+ arrays = StyleFormator.StringSplit(trimmed);
806
+ }
807
+ // 下面四个属性在animation字符串中是无序的,所以需要单独判断。
808
+ let timingFunction = "";
809
+ let delay = 0;
810
+ let iterationCount = 1;
811
+ let direction = (trimmed.indexOf("alternate") >= 0);
812
+ for (var idx = 2; idx < arrays.length; idx++) { // 前两个选项固定是name和duration
813
+ if (arrays[idx] == "infinite") {
814
+ iterationCount = -1; // -1表示无限循环
815
+ continue;
816
+ }
817
+ let num = StyleFormator.ParseToTimeMs(arrays[idx]);
818
+ if (isNaN(num) == false) { // 表示时间
819
+ delay = num;
820
+ }
821
+ else {
822
+ num = StyleFormator.ParseToFloat(arrays[idx]);
823
+ if (isNaN(num) == false) { // 表示次数
824
+ iterationCount = num;
825
+ }
826
+ else { // 不是数字,直接赋给timingFunction,省略判断
827
+ timingFunction = arrays[idx];
828
+ }
829
+ }
830
+ }
831
+ const duration = arrays.length > 1 ? StyleFormator.ParseToTimeMs(arrays[1]) : 0.0;
832
+ const anim = new StyleValue.AnimationImpl(trimmed);
833
+ anim.name = arrays.length > 0 ? arrays[0] : "";
834
+ anim.duration = duration;
835
+ anim.timingFunction = StyleFormator.ParseToEasing(timingFunction, duration);
836
+ anim.delay = delay;
837
+ anim.iterationCount = iterationCount;
838
+ anim.direction = direction;
839
+ // .originStr = propValue,
840
+ return anim;
841
+ }
842
+ static ParseToTimeMs(from) {
843
+ if (StyleFormator.StringEndsWith(from, "s") == false) { // ms / s
844
+ return NaN;
845
+ }
846
+ let timing = StyleFormator.ParseToFloat(from);
847
+ if (StyleFormator.StringEndsWith(from, "ms")) {
848
+ timing *= 1.0;
849
+ }
850
+ else if (StyleFormator.StringEndsWith(from, "s")) {
851
+ timing *= 1000.0;
852
+ }
853
+ // timing *= std::stof(from);
854
+ return timing;
855
+ }
856
+ static ParseToFloat(from) {
857
+ const trimmed = StyleFormator.StringTrim(from);
858
+ return parseFloat(trimmed);
859
+ }
860
+ static ParseToEasing(from, duration) {
861
+ let easing = null;
862
+ if (from.indexOf("ease") >= 0) {
863
+ if (from.indexOf("-in-out") >= 0) {
864
+ easing = Forge.Easing.Circular.InOut;
865
+ }
866
+ else if (from.indexOf("-out") >= 0) {
867
+ easing = Forge.Easing.Circular.Out;
868
+ }
869
+ else if (from.indexOf("-in") >= 0) {
870
+ easing = Forge.Easing.Circular.In;
871
+ }
872
+ else {
873
+ easing = Forge.Easing.Circular.InOut;
874
+ }
875
+ }
876
+ else if (from.indexOf("linear") >= 0) {
877
+ easing = null; // null是匀速动画
878
+ }
879
+ else if (from.indexOf("cubic-bezier") >= 0) {
880
+ easing = StyleFormator.ParseToEasingBezier(from, duration);
881
+ }
882
+ else if (from.indexOf("steps") >= 0) {
883
+ easing = StyleFormator.ParseToEasingSteps(from);
884
+ }
885
+ return easing;
886
+ }
887
+ static ParseToEasingBezier(jsDescribe, duration) {
888
+ let startIdx = jsDescribe.indexOf('(');
889
+ if (startIdx >= 0) {
890
+ jsDescribe = jsDescribe.substring(startIdx + 1);
891
+ }
892
+ let arrays = StyleFormator.StringSplit(jsDescribe, ',');
893
+ let bezier = {
894
+ x1: arrays.length > 0 ? parseFloat(arrays[0]) : 0,
895
+ y1: arrays.length > 1 ? parseFloat(arrays[1]) : 0,
896
+ x2: arrays.length > 2 ? parseFloat(arrays[2]) : 0,
897
+ y2: arrays.length > 3 ? parseFloat(arrays[3]) : 0,
898
+ };
899
+ return new Forge.BezierEasing(bezier.x1, bezier.y1, bezier.x2, bezier.y2, duration);
900
+ }
901
+ static ParseToEasingSteps(jsDescribe) {
902
+ let startIdx = jsDescribe.indexOf('(');
903
+ if (startIdx >= 0) {
904
+ jsDescribe = jsDescribe.substring(startIdx + 1);
905
+ }
906
+ let arrays = StyleFormator.StringSplit(jsDescribe, ',');
907
+ let steps = {
908
+ steps: arrays.length > 0 ? parseInt(arrays[0]) : 1,
909
+ type: arrays.length > 1 ? (arrays[1].includes("start") ? 0 : 1) : 0,
910
+ };
911
+ return new Forge.StepsEasing(steps.steps, steps.type);
912
+ }
913
+ constructor() { throw new Error("new StyleGroup() is forbidden."); }
914
+ }
915
+
916
+ exports.StyleFormator = StyleFormator;
917
+ exports.StyleName = StyleName;
918
+ exports.StyleValue = StyleValue;
919
+ exports.StyleVariable = StyleVariable;