@meursyphus/flitter 2.0.0 → 2.0.2

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/index.global.js CHANGED
@@ -37,6 +37,10 @@
37
37
  var __commonJS = (cb2, mod) => function __require() {
38
38
  return mod || (0, cb2[__getOwnPropNames(cb2)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
39
39
  };
40
+ var __export = (target, all) => {
41
+ for (var name in all)
42
+ __defProp(target, name, { get: all[name], enumerable: true });
43
+ };
40
44
  var __copyProps = (to, from, except, desc) => {
41
45
  if (from && typeof from === "object" || typeof from === "function") {
42
46
  for (let key of __getOwnPropNames(from))
@@ -12473,8 +12477,8 @@
12473
12477
  this.decoration = decoration;
12474
12478
  }
12475
12479
  paint(ctx, rect) {
12476
- this.paintBackgroundColor(ctx, rect);
12477
- this.paintShadows(ctx, rect);
12480
+ const backgroundPath = this.paintBackgroundColor(ctx, rect);
12481
+ this.paintShadows(ctx, backgroundPath);
12478
12482
  if (this.decoration.border != null) {
12479
12483
  this.decoration.border.createCanvasPainter().paint(ctx, {
12480
12484
  rect,
@@ -12483,7 +12487,7 @@
12483
12487
  });
12484
12488
  }
12485
12489
  }
12486
- paintShadows(ctx, rect) {
12490
+ paintShadows(ctx, backgroundPath) {
12487
12491
  if (this.decoration.boxShadow == null || this.decoration.boxShadow.length === 0) {
12488
12492
  return;
12489
12493
  }
@@ -12493,22 +12497,23 @@
12493
12497
  ctx.shadowOffsetY = shadow.offset.y;
12494
12498
  ctx.shadowBlur = shadow.blurRadius;
12495
12499
  ctx.shadowColor = shadow.color.value;
12496
- ctx.fill(new path_default().addRect(rect).toCanvasPath());
12500
+ ctx.fill(backgroundPath.toCanvasPath());
12497
12501
  ctx.restore();
12498
12502
  });
12499
12503
  }
12500
12504
  paintBackgroundColor(ctx, rect) {
12501
12505
  ctx.fillStyle = this.decoration.color.value || "none";
12506
+ const path = new path_default();
12502
12507
  if (this.decoration.shape == "circle") {
12503
- ctx.fill(new path_default().addOval(rect).toCanvasPath());
12504
- return;
12508
+ ctx.fill(path.addOval(rect).toCanvasPath());
12509
+ return path;
12505
12510
  }
12506
12511
  if (this.decoration.borderRadius == null) {
12507
- ctx.fill(new path_default().addRect(rect).toCanvasPath());
12508
- return;
12512
+ ctx.fill(path.addRect(rect).toCanvasPath());
12513
+ return path;
12509
12514
  }
12510
12515
  ctx.fill(
12511
- new path_default().addRRect(
12516
+ path.addRRect(
12512
12517
  r_rect_default.fromRectAndCorners({
12513
12518
  rect,
12514
12519
  topLeft: this.decoration.borderRadius.topLeft,
@@ -12518,6 +12523,7 @@
12518
12523
  })
12519
12524
  ).toCanvasPath()
12520
12525
  );
12526
+ return path;
12521
12527
  }
12522
12528
  };
12523
12529
 
@@ -12560,7 +12566,7 @@
12560
12566
  // src/type/_types/text-style.ts
12561
12567
  var TextStyle = class _TextStyle {
12562
12568
  constructor({
12563
- inherit = true,
12569
+ inherit: inherit2 = true,
12564
12570
  color: color2,
12565
12571
  fontSize,
12566
12572
  fontWeight,
@@ -12584,7 +12590,7 @@
12584
12590
  /// multiple of [fontSize] and be exactly `fontSize * height` logical pixels
12585
12591
  /// tall.
12586
12592
  __publicField(this, "height");
12587
- this.inherit = inherit;
12593
+ this.inherit = inherit2;
12588
12594
  this.color = color2;
12589
12595
  this.fontSize = fontSize;
12590
12596
  this.fontWeight = fontWeight;
@@ -12599,7 +12605,7 @@
12599
12605
  return this.inherit === other.inherit && this.color === other.color && this.fontSize === other.fontSize && this.fontWeight === other.fontWeight && this.fontFamily === other.fontFamily && this.textBaseline === other.textBaseline && this.fontStyle === other.fontStyle;
12600
12606
  }
12601
12607
  copyWidth({
12602
- inherit = this.inherit,
12608
+ inherit: inherit2 = this.inherit,
12603
12609
  color: color2 = this.color,
12604
12610
  fontSize = this.fontSize,
12605
12611
  fontWeight = this.fontWeight,
@@ -12609,7 +12615,7 @@
12609
12615
  height = this.height
12610
12616
  }) {
12611
12617
  return new _TextStyle({
12612
- inherit,
12618
+ inherit: inherit2,
12613
12619
  color: color2,
12614
12620
  fontFamily,
12615
12621
  fontSize,
@@ -13134,6 +13140,351 @@
13134
13140
  }
13135
13141
  };
13136
13142
 
13143
+ // src/type/colors.ts
13144
+ var colors_exports = {};
13145
+ __export(colors_exports, {
13146
+ amber: () => amber,
13147
+ black: () => black,
13148
+ blue: () => blue,
13149
+ cyan: () => cyan,
13150
+ emerald: () => emerald,
13151
+ fuchsia: () => fuchsia,
13152
+ gray: () => gray,
13153
+ green: () => green,
13154
+ indigo: () => indigo,
13155
+ inherit: () => inherit,
13156
+ lime: () => lime,
13157
+ neutral: () => neutral,
13158
+ orange: () => orange,
13159
+ pink: () => pink,
13160
+ purple: () => purple,
13161
+ red: () => red,
13162
+ rose: () => rose,
13163
+ sky: () => sky,
13164
+ slate: () => slate,
13165
+ stone: () => stone,
13166
+ teal: () => teal,
13167
+ transparent: () => transparent,
13168
+ violet: () => violet,
13169
+ white: () => white,
13170
+ yellow: () => yellow,
13171
+ zinc: () => zinc
13172
+ });
13173
+ var inherit = "inherit";
13174
+ var transparent = "transparent";
13175
+ var black = "#000";
13176
+ var white = "#fff";
13177
+ var slate = {
13178
+ 50: "#f8fafc",
13179
+ 100: "#f1f5f9",
13180
+ 200: "#e2e8f0",
13181
+ 300: "#cbd5e1",
13182
+ 400: "#94a3b8",
13183
+ 500: "#64748b",
13184
+ 600: "#475569",
13185
+ 700: "#334155",
13186
+ 800: "#1e293b",
13187
+ 900: "#0f172a",
13188
+ 950: "#020617"
13189
+ };
13190
+ var gray = {
13191
+ 50: "#f9fafb",
13192
+ 100: "#f3f4f6",
13193
+ 200: "#e5e7eb",
13194
+ 300: "#d1d5db",
13195
+ 400: "#9ca3af",
13196
+ 500: "#6b7280",
13197
+ 600: "#4b5563",
13198
+ 700: "#374151",
13199
+ 800: "#1f2937",
13200
+ 900: "#111827",
13201
+ 950: "#030712"
13202
+ };
13203
+ var zinc = {
13204
+ 50: "#fafafa",
13205
+ 100: "#f4f4f5",
13206
+ 200: "#e4e4e7",
13207
+ 300: "#d4d4d8",
13208
+ 400: "#a1a1aa",
13209
+ 500: "#71717a",
13210
+ 600: "#52525b",
13211
+ 700: "#3f3f46",
13212
+ 800: "#27272a",
13213
+ 900: "#18181b",
13214
+ 950: "#09090b"
13215
+ };
13216
+ var neutral = {
13217
+ 50: "#fafafa",
13218
+ 100: "#f5f5f5",
13219
+ 200: "#e5e5e5",
13220
+ 300: "#d4d4d4",
13221
+ 400: "#a3a3a3",
13222
+ 500: "#737373",
13223
+ 600: "#525252",
13224
+ 700: "#404040",
13225
+ 800: "#262626",
13226
+ 900: "#171717",
13227
+ 950: "#0a0a0a"
13228
+ };
13229
+ var stone = {
13230
+ 50: "#fafaf9",
13231
+ 100: "#f5f5f4",
13232
+ 200: "#e7e5e4",
13233
+ 300: "#d6d3d1",
13234
+ 400: "#a8a29e",
13235
+ 500: "#78716c",
13236
+ 600: "#57534e",
13237
+ 700: "#44403c",
13238
+ 800: "#292524",
13239
+ 900: "#1c1917",
13240
+ 950: "#0c0a09"
13241
+ };
13242
+ var red = {
13243
+ 50: "#fef2f2",
13244
+ 100: "#fee2e2",
13245
+ 200: "#fecaca",
13246
+ 300: "#fca5a5",
13247
+ 400: "#f87171",
13248
+ 500: "#ef4444",
13249
+ 600: "#dc2626",
13250
+ 700: "#b91c1c",
13251
+ 800: "#991b1b",
13252
+ 900: "#7f1d1d",
13253
+ 950: "#450a0a"
13254
+ };
13255
+ var orange = {
13256
+ 50: "#fff7ed",
13257
+ 100: "#ffedd5",
13258
+ 200: "#fed7aa",
13259
+ 300: "#fdba74",
13260
+ 400: "#fb923c",
13261
+ 500: "#f97316",
13262
+ 600: "#ea580c",
13263
+ 700: "#c2410c",
13264
+ 800: "#9a3412",
13265
+ 900: "#7c2d12",
13266
+ 950: "#431407"
13267
+ };
13268
+ var amber = {
13269
+ 50: "#fffbeb",
13270
+ 100: "#fef3c7",
13271
+ 200: "#fde68a",
13272
+ 300: "#fcd34d",
13273
+ 400: "#fbbf24",
13274
+ 500: "#f59e0b",
13275
+ 600: "#d97706",
13276
+ 700: "#b45309",
13277
+ 800: "#92400e",
13278
+ 900: "#78350f",
13279
+ 950: "#451a03"
13280
+ };
13281
+ var yellow = {
13282
+ 50: "#fefce8",
13283
+ 100: "#fef9c3",
13284
+ 200: "#fef08a",
13285
+ 300: "#fde047",
13286
+ 400: "#facc15",
13287
+ 500: "#eab308",
13288
+ 600: "#ca8a04",
13289
+ 700: "#a16207",
13290
+ 800: "#854d0e",
13291
+ 900: "#713f12",
13292
+ 950: "#422006"
13293
+ };
13294
+ var lime = {
13295
+ 50: "#f7fee7",
13296
+ 100: "#ecfccb",
13297
+ 200: "#d9f99d",
13298
+ 300: "#bef264",
13299
+ 400: "#a3e635",
13300
+ 500: "#84cc16",
13301
+ 600: "#65a30d",
13302
+ 700: "#4d7c0f",
13303
+ 800: "#3f6212",
13304
+ 900: "#365314",
13305
+ 950: "#1a2e05"
13306
+ };
13307
+ var green = {
13308
+ 50: "#f0fdf4",
13309
+ 100: "#dcfce7",
13310
+ 200: "#bbf7d0",
13311
+ 300: "#86efac",
13312
+ 400: "#4ade80",
13313
+ 500: "#22c55e",
13314
+ 600: "#16a34a",
13315
+ 700: "#15803d",
13316
+ 800: "#166534",
13317
+ 900: "#14532d",
13318
+ 950: "#052e16"
13319
+ };
13320
+ var emerald = {
13321
+ 50: "#ecfdf5",
13322
+ 100: "#d1fae5",
13323
+ 200: "#a7f3d0",
13324
+ 300: "#6ee7b7",
13325
+ 400: "#34d399",
13326
+ 500: "#10b981",
13327
+ 600: "#059669",
13328
+ 700: "#047857",
13329
+ 800: "#065f46",
13330
+ 900: "#064e3b",
13331
+ 950: "#022c22"
13332
+ };
13333
+ var teal = {
13334
+ 50: "#f0fdfa",
13335
+ 100: "#ccfbf1",
13336
+ 200: "#99f6e4",
13337
+ 300: "#5eead4",
13338
+ 400: "#2dd4bf",
13339
+ 500: "#14b8a6",
13340
+ 600: "#0d9488",
13341
+ 700: "#0f766e",
13342
+ 800: "#115e59",
13343
+ 900: "#134e4a",
13344
+ 950: "#042f2e"
13345
+ };
13346
+ var cyan = {
13347
+ 50: "#ecfeff",
13348
+ 100: "#cffafe",
13349
+ 200: "#a5f3fc",
13350
+ 300: "#67e8f9",
13351
+ 400: "#22d3ee",
13352
+ 500: "#06b6d4",
13353
+ 600: "#0891b2",
13354
+ 700: "#0e7490",
13355
+ 800: "#155e75",
13356
+ 900: "#164e63",
13357
+ 950: "#083344"
13358
+ };
13359
+ var sky = {
13360
+ 50: "#f0f9ff",
13361
+ 100: "#e0f2fe",
13362
+ 200: "#bae6fd",
13363
+ 300: "#7dd3fc",
13364
+ 400: "#38bdf8",
13365
+ 500: "#0ea5e9",
13366
+ 600: "#0284c7",
13367
+ 700: "#0369a1",
13368
+ 800: "#075985",
13369
+ 900: "#0c4a6e",
13370
+ 950: "#082f49"
13371
+ };
13372
+ var blue = {
13373
+ 50: "#eff6ff",
13374
+ 100: "#dbeafe",
13375
+ 200: "#bfdbfe",
13376
+ 300: "#93c5fd",
13377
+ 400: "#60a5fa",
13378
+ 500: "#3b82f6",
13379
+ 600: "#2563eb",
13380
+ 700: "#1d4ed8",
13381
+ 800: "#1e40af",
13382
+ 900: "#1e3a8a",
13383
+ 950: "#172554"
13384
+ };
13385
+ var indigo = {
13386
+ 50: "#eef2ff",
13387
+ 100: "#e0e7ff",
13388
+ 200: "#c7d2fe",
13389
+ 300: "#a5b4fc",
13390
+ 400: "#818cf8",
13391
+ 500: "#6366f1",
13392
+ 600: "#4f46e5",
13393
+ 700: "#4338ca",
13394
+ 800: "#3730a3",
13395
+ 900: "#312e81",
13396
+ 950: "#1e1b4b"
13397
+ };
13398
+ var violet = {
13399
+ 50: "#f5f3ff",
13400
+ 100: "#ede9fe",
13401
+ 200: "#ddd6fe",
13402
+ 300: "#c4b5fd",
13403
+ 400: "#a78bfa",
13404
+ 500: "#8b5cf6",
13405
+ 600: "#7c3aed",
13406
+ 700: "#6d28d9",
13407
+ 800: "#5b21b6",
13408
+ 900: "#4c1d95",
13409
+ 950: "#2e1065"
13410
+ };
13411
+ var purple = {
13412
+ 50: "#faf5ff",
13413
+ 100: "#f3e8ff",
13414
+ 200: "#e9d5ff",
13415
+ 300: "#d8b4fe",
13416
+ 400: "#c084fc",
13417
+ 500: "#a855f7",
13418
+ 600: "#9333ea",
13419
+ 700: "#7e22ce",
13420
+ 800: "#6b21a8",
13421
+ 900: "#581c87",
13422
+ 950: "#3b0764"
13423
+ };
13424
+ var fuchsia = {
13425
+ 50: "#fdf4ff",
13426
+ 100: "#fae8ff",
13427
+ 200: "#f5d0fe",
13428
+ 300: "#f0abfc",
13429
+ 400: "#e879f9",
13430
+ 500: "#d946ef",
13431
+ 600: "#c026d3",
13432
+ 700: "#a21caf",
13433
+ 800: "#86198f",
13434
+ 900: "#701a75",
13435
+ 950: "#4a044e"
13436
+ };
13437
+ var pink = {
13438
+ 50: "#fdf2f8",
13439
+ 100: "#fce7f3",
13440
+ 200: "#fbcfe8",
13441
+ 300: "#f9a8d4",
13442
+ 400: "#f472b6",
13443
+ 500: "#ec4899",
13444
+ 600: "#db2777",
13445
+ 700: "#be185d",
13446
+ 800: "#9d174d",
13447
+ 900: "#831843",
13448
+ 950: "#500724"
13449
+ };
13450
+ var rose = {
13451
+ 50: "#fff1f2",
13452
+ 100: "#ffe4e6",
13453
+ 200: "#fecdd3",
13454
+ 300: "#fda4af",
13455
+ 400: "#fb7185",
13456
+ 500: "#f43f5e",
13457
+ 600: "#e11d48",
13458
+ 700: "#be123c",
13459
+ 800: "#9f1239",
13460
+ 900: "#881337",
13461
+ 950: "#4c0519"
13462
+ };
13463
+
13464
+ // src/type/_types/object-fit.ts
13465
+ var ObjectFit = /* @__PURE__ */ ((ObjectFit2) => {
13466
+ ObjectFit2["fill"] = "fill";
13467
+ ObjectFit2["contain"] = "contain";
13468
+ ObjectFit2["cover"] = "cover";
13469
+ ObjectFit2["none"] = "none";
13470
+ ObjectFit2["scaleDown"] = "scale-down";
13471
+ return ObjectFit2;
13472
+ })(ObjectFit || {});
13473
+
13474
+ // src/type/_types/object-position.ts
13475
+ var ObjectPosition = /* @__PURE__ */ ((ObjectPosition2) => {
13476
+ ObjectPosition2["center"] = "center";
13477
+ ObjectPosition2["top"] = "top";
13478
+ ObjectPosition2["right"] = "right";
13479
+ ObjectPosition2["bottom"] = "bottom";
13480
+ ObjectPosition2["left"] = "left";
13481
+ ObjectPosition2["topLeft"] = "top left";
13482
+ ObjectPosition2["topRight"] = "top right";
13483
+ ObjectPosition2["bottomLeft"] = "bottom left";
13484
+ ObjectPosition2["bottomRight"] = "bottom right";
13485
+ return ObjectPosition2;
13486
+ })(ObjectPosition || {});
13487
+
13137
13488
  // src/framework/renderer/renderer.ts
13138
13489
  var _resizeHandlers;
13139
13490
  var RenderContext = class {
@@ -13160,6 +13511,10 @@
13160
13511
  this.viewSize = new size_default(viewSize);
13161
13512
  }
13162
13513
  }
13514
+ /**
13515
+ * @deprecated
13516
+ * This method is deprecated and will be removed in future versions.
13517
+ */
13163
13518
  setViewport({
13164
13519
  translation,
13165
13520
  scale: scale2
@@ -14050,10 +14405,10 @@
14050
14405
  dispose() {
14051
14406
  this.renderOwner.disposeRenderObject(this);
14052
14407
  }
14053
- getIntrinsicWidth(_height) {
14408
+ getIntrinsicWidth(_height2) {
14054
14409
  return 0;
14055
14410
  }
14056
- getIntrinsicHeight(_width) {
14411
+ getIntrinsicHeight(_width2) {
14057
14412
  return 0;
14058
14413
  }
14059
14414
  /*
@@ -14471,7 +14826,7 @@
14471
14826
  this.hitTest(e, "onMouseUp");
14472
14827
  });
14473
14828
  __privateAdd(this, _handleMouseWheel, (e) => {
14474
- this.hitTest(e, "onMouseWheel");
14829
+ this.hitTest(e, "onWheel");
14475
14830
  e.isPropagationStopped = false;
14476
14831
  for (const detector of __privateGet(this, _detectors)) {
14477
14832
  if (e.isPropagationStopped)
@@ -14498,7 +14853,7 @@
14498
14853
  return;
14499
14854
  if (!detector.hitTest({ globalPoint: __privateGet(this, _hitPosition) }))
14500
14855
  continue;
14501
- detector[type](e);
14856
+ detector.invokeCallback(type, e);
14502
14857
  }
14503
14858
  });
14504
14859
  __privateAdd(this, _wrapEvent, (callback) => (e) => {
@@ -15191,7 +15546,7 @@
15191
15546
  var rgba2 = {
15192
15547
  test: isColorString("rgb", "red"),
15193
15548
  parse: splitColor("red", "green", "blue"),
15194
- transform: ({ red, green, blue, alpha: alpha$1 = 1 }) => "rgba(" + rgbUnit.transform(red) + ", " + rgbUnit.transform(green) + ", " + rgbUnit.transform(blue) + ", " + sanitize(alpha.transform(alpha$1)) + ")"
15549
+ transform: ({ red: red2, green: green2, blue: blue2, alpha: alpha$1 = 1 }) => "rgba(" + rgbUnit.transform(red2) + ", " + rgbUnit.transform(green2) + ", " + rgbUnit.transform(blue2) + ", " + sanitize(alpha.transform(alpha$1)) + ")"
15195
15550
  };
15196
15551
 
15197
15552
  // ../../node_modules/style-value-types/dist/es/color/hex.mjs
@@ -15310,22 +15665,22 @@
15310
15665
  hue /= 360;
15311
15666
  saturation /= 100;
15312
15667
  lightness /= 100;
15313
- let red = 0;
15314
- let green = 0;
15315
- let blue = 0;
15668
+ let red2 = 0;
15669
+ let green2 = 0;
15670
+ let blue2 = 0;
15316
15671
  if (!saturation) {
15317
- red = green = blue = lightness;
15672
+ red2 = green2 = blue2 = lightness;
15318
15673
  } else {
15319
15674
  const q = lightness < 0.5 ? lightness * (1 + saturation) : lightness + saturation - lightness * saturation;
15320
15675
  const p = 2 * lightness - q;
15321
- red = hueToRgb(p, q, hue + 1 / 3);
15322
- green = hueToRgb(p, q, hue);
15323
- blue = hueToRgb(p, q, hue - 1 / 3);
15676
+ red2 = hueToRgb(p, q, hue + 1 / 3);
15677
+ green2 = hueToRgb(p, q, hue);
15678
+ blue2 = hueToRgb(p, q, hue - 1 / 3);
15324
15679
  }
15325
15680
  return {
15326
- red: Math.round(red * 255),
15327
- green: Math.round(green * 255),
15328
- blue: Math.round(blue * 255),
15681
+ red: Math.round(red2 * 255),
15682
+ green: Math.round(green2 * 255),
15683
+ blue: Math.round(blue2 * 255),
15329
15684
  alpha: alpha2
15330
15685
  };
15331
15686
  }
@@ -19980,6 +20335,9 @@
19980
20335
  accept(visitor) {
19981
20336
  visitor.visitGestureDetector(this);
19982
20337
  }
20338
+ invokeCallback(type, e) {
20339
+ this[type](e);
20340
+ }
19983
20341
  };
19984
20342
  function emptyCallback(_arg) {
19985
20343
  }
@@ -21566,4 +21924,358 @@
21566
21924
  (_a = __privateGet(this, _listeners)[type]) == null ? void 0 : _a.forEach((listener) => listener(event));
21567
21925
  };
21568
21926
  var TextField_default = classToFunction_default(TextField);
21927
+
21928
+ // src/component/base/base-image/calculatePosition.ts
21929
+ var objectPositionMap = {
21930
+ center: { x: 0.5, y: 0.5 },
21931
+ top: { x: 0.5, y: 0 },
21932
+ right: { x: 1, y: 0.5 },
21933
+ bottom: { x: 0.5, y: 1 },
21934
+ left: { x: 0, y: 0.5 },
21935
+ "top left": { x: 0, y: 0 },
21936
+ "top right": { x: 1, y: 0 },
21937
+ "bottom left": { x: 0, y: 1 },
21938
+ "bottom right": { x: 1, y: 1 }
21939
+ };
21940
+ function calcSize(sourceSize, containerSize, imageSize, positionPercent) {
21941
+ if (imageSize > containerSize) {
21942
+ const ratio = sourceSize / imageSize;
21943
+ const sSize = Math.min(sourceSize, containerSize * ratio);
21944
+ const s = (sourceSize - sSize) * positionPercent;
21945
+ return {
21946
+ s: Math.max(0, Math.min(s, sourceSize - sSize)),
21947
+ sSize,
21948
+ d: 0,
21949
+ dSize: containerSize
21950
+ };
21951
+ } else {
21952
+ const d = (containerSize - imageSize) * positionPercent;
21953
+ return {
21954
+ s: 0,
21955
+ sSize: sourceSize,
21956
+ d,
21957
+ dSize: imageSize
21958
+ };
21959
+ }
21960
+ }
21961
+ function calculateImageRendering(sourceImageSize, calcImageSizeResult, objectPosition = "center") {
21962
+ const {
21963
+ container: { width: containerWidth, height: containerHeight },
21964
+ image: { width: imageWidth, height: imageHeight }
21965
+ } = calcImageSizeResult;
21966
+ const { x: xPercent, y: yPercent } = objectPositionMap[objectPosition];
21967
+ const horizontalResult = calcSize(
21968
+ sourceImageSize.width,
21969
+ containerWidth,
21970
+ imageWidth,
21971
+ xPercent
21972
+ );
21973
+ const verticalResult = calcSize(
21974
+ sourceImageSize.height,
21975
+ containerHeight,
21976
+ imageHeight,
21977
+ yPercent
21978
+ );
21979
+ return {
21980
+ sx: Math.round(horizontalResult.s),
21981
+ sy: Math.round(verticalResult.s),
21982
+ sWidth: Math.round(horizontalResult.sSize),
21983
+ sHeight: Math.round(verticalResult.sSize),
21984
+ dx: Math.round(horizontalResult.d),
21985
+ dy: Math.round(verticalResult.d),
21986
+ dWidth: Math.round(horizontalResult.dSize),
21987
+ dHeight: Math.round(verticalResult.dSize)
21988
+ };
21989
+ }
21990
+
21991
+ // src/component/base/base-image/calculateSize.ts
21992
+ function calculateSize(source, container, objectFit = "none") {
21993
+ var _a, _b;
21994
+ const aspectRatio = source.width / source.height;
21995
+ let containerWidth = (_a = container.width) != null ? _a : source.width;
21996
+ let containerHeight = (_b = container.height) != null ? _b : source.height;
21997
+ if (container.width != null && container.height == null) {
21998
+ containerHeight = Math.round(container.width / aspectRatio);
21999
+ } else if (container.width == null && container.height != null) {
22000
+ containerWidth = Math.round(container.height * aspectRatio);
22001
+ }
22002
+ const imageSize = fitFunctions[objectFit](source, {
22003
+ width: containerWidth,
22004
+ height: containerHeight
22005
+ });
22006
+ return {
22007
+ width: Math.round(containerWidth),
22008
+ height: Math.round(containerHeight),
22009
+ image: {
22010
+ width: Math.round(imageSize.width),
22011
+ height: Math.round(imageSize.height)
22012
+ }
22013
+ };
22014
+ }
22015
+ var fitFunctions = {
22016
+ fill: fillFit,
22017
+ contain: containFit,
22018
+ cover: coverFit,
22019
+ none: noneFit,
22020
+ "scale-down": scaleDownFit
22021
+ };
22022
+ function fillFit(source, container) {
22023
+ return { width: container.width, height: container.height };
22024
+ }
22025
+ function containFit(source, result) {
22026
+ const aspectRatio = source.width / source.height;
22027
+ if (result.width / result.height > aspectRatio) {
22028
+ return { width: result.height * aspectRatio, height: result.height };
22029
+ } else {
22030
+ return { width: result.width, height: result.width / aspectRatio };
22031
+ }
22032
+ }
22033
+ function coverFit(source, container) {
22034
+ const aspectRatio = source.width / source.height;
22035
+ if (container.width / container.height > aspectRatio) {
22036
+ return { width: container.width, height: container.width / aspectRatio };
22037
+ } else {
22038
+ return { width: container.height * aspectRatio, height: container.height };
22039
+ }
22040
+ }
22041
+ function noneFit(source, _) {
22042
+ return { width: source.width, height: source.height };
22043
+ }
22044
+ function scaleDownFit(source, container) {
22045
+ const containSize = containFit(source, container);
22046
+ if (containSize.width > source.width || containSize.height > source.height) {
22047
+ return { width: source.width, height: source.height };
22048
+ }
22049
+ return containSize;
22050
+ }
22051
+
22052
+ // src/component/base/base-image/BaseImage.ts
22053
+ var _Image = class extends SingleChildRenderObjectWidget_default {
22054
+ constructor({
22055
+ key,
22056
+ src,
22057
+ objectFit: fit,
22058
+ width,
22059
+ height,
22060
+ objectPosition: position
22061
+ }) {
22062
+ super(key);
22063
+ __publicField(this, "_src");
22064
+ __publicField(this, "_fit");
22065
+ __publicField(this, "_width");
22066
+ __publicField(this, "_height");
22067
+ __publicField(this, "_position");
22068
+ this._src = src;
22069
+ this._fit = fit;
22070
+ this._width = width;
22071
+ this._height = height;
22072
+ this._position = position;
22073
+ }
22074
+ createRenderObject() {
22075
+ return new RenderImage({
22076
+ src: this._src,
22077
+ objectFit: this._fit,
22078
+ width: this._width,
22079
+ height: this._height,
22080
+ objectPosition: this._position
22081
+ });
22082
+ }
22083
+ updateRenderObject(renderObject) {
22084
+ renderObject.src = this._src;
22085
+ renderObject.fit = this._fit;
22086
+ renderObject.width = this._width;
22087
+ renderObject.height = this._height;
22088
+ renderObject.position = this._position;
22089
+ }
22090
+ };
22091
+ var _src, _fit, _width, _height, _position, _mounted;
22092
+ var RenderImage = class extends SingleChildRenderObject_default {
22093
+ constructor({
22094
+ src,
22095
+ objectFit,
22096
+ width,
22097
+ height,
22098
+ objectPosition
22099
+ }) {
22100
+ super({ isPainter: true });
22101
+ __privateAdd(this, _src, void 0);
22102
+ __privateAdd(this, _fit, void 0);
22103
+ __privateAdd(this, _width, void 0);
22104
+ __privateAdd(this, _height, void 0);
22105
+ __privateAdd(this, _position, void 0);
22106
+ __publicField(this, "image");
22107
+ __publicField(this, "imageLoaded", false);
22108
+ __publicField(this, "calculatedImageSize");
22109
+ __privateAdd(this, _mounted, false);
22110
+ __privateSet(this, _src, src);
22111
+ __privateSet(this, _fit, objectFit);
22112
+ __privateSet(this, _width, width);
22113
+ __privateSet(this, _height, height);
22114
+ __privateSet(this, _position, objectPosition);
22115
+ if (browser) {
22116
+ this.image = new Image();
22117
+ this.image.onload = () => {
22118
+ this.imageLoaded = true;
22119
+ if (!__privateGet(this, _mounted))
22120
+ return;
22121
+ this.markNeedsLayout();
22122
+ };
22123
+ this.image.src = src;
22124
+ }
22125
+ }
22126
+ get src() {
22127
+ return __privateGet(this, _src);
22128
+ }
22129
+ set src(value) {
22130
+ if (__privateGet(this, _src) === value)
22131
+ return;
22132
+ __privateSet(this, _src, value);
22133
+ if (this.image != null) {
22134
+ this.image.src = value;
22135
+ }
22136
+ this.markNeedsLayout();
22137
+ }
22138
+ get fit() {
22139
+ return __privateGet(this, _fit);
22140
+ }
22141
+ set fit(value) {
22142
+ if (__privateGet(this, _fit) === value)
22143
+ return;
22144
+ __privateSet(this, _fit, value);
22145
+ this.markNeedsLayout();
22146
+ }
22147
+ get width() {
22148
+ return __privateGet(this, _width);
22149
+ }
22150
+ set width(value) {
22151
+ if (__privateGet(this, _width) === value)
22152
+ return;
22153
+ __privateSet(this, _width, value);
22154
+ this.markNeedsLayout();
22155
+ }
22156
+ get height() {
22157
+ return __privateGet(this, _height);
22158
+ }
22159
+ set height(value) {
22160
+ if (__privateGet(this, _height) === value)
22161
+ return;
22162
+ __privateSet(this, _height, value);
22163
+ this.markNeedsLayout();
22164
+ }
22165
+ get position() {
22166
+ return __privateGet(this, _position);
22167
+ }
22168
+ set position(value) {
22169
+ if (__privateGet(this, _position) === value)
22170
+ return;
22171
+ __privateSet(this, _position, value);
22172
+ this.markNeedsLayout();
22173
+ }
22174
+ getIntrinsicWidth() {
22175
+ if (this.width != null)
22176
+ return this.width;
22177
+ return 0;
22178
+ }
22179
+ getIntrinsicHeight() {
22180
+ if (this.height != null)
22181
+ return this.height;
22182
+ return 0;
22183
+ }
22184
+ preformLayout() {
22185
+ var _a, _b;
22186
+ __privateSet(this, _mounted, true);
22187
+ if (!this.imageLoaded) {
22188
+ this.size = this.constraints.constrain(
22189
+ new size_default({
22190
+ width: (_a = this.width) != null ? _a : 0,
22191
+ height: (_b = this.height) != null ? _b : 0
22192
+ })
22193
+ );
22194
+ return;
22195
+ }
22196
+ assert(this.image != null);
22197
+ const sourceSize = { width: this.image.width, height: this.image.height };
22198
+ const { width, height } = calculateSize(
22199
+ sourceSize,
22200
+ {
22201
+ width: this.width && this.constraints.constrainWidth(this.width),
22202
+ height: this.height && this.constraints.constrainHeight(this.height)
22203
+ },
22204
+ this.fit
22205
+ );
22206
+ const size = new size_default({ width, height });
22207
+ this.size = this.constraints.constrain(size);
22208
+ this.calculatedImageSize = calculateSize(
22209
+ sourceSize,
22210
+ {
22211
+ width: this.size.width,
22212
+ height: this.size.height
22213
+ },
22214
+ this.fit
22215
+ ).image;
22216
+ }
22217
+ createCanvasPainter() {
22218
+ return new ImageCanvasPatiner(this);
22219
+ }
22220
+ createSvgPainter() {
22221
+ return new ImageSvgPainter(this);
22222
+ }
22223
+ };
22224
+ _src = new WeakMap();
22225
+ _fit = new WeakMap();
22226
+ _width = new WeakMap();
22227
+ _height = new WeakMap();
22228
+ _position = new WeakMap();
22229
+ _mounted = new WeakMap();
22230
+ var ImageCanvasPatiner = class extends CanvasPainter {
22231
+ performPaint(context, offset) {
22232
+ const {
22233
+ size,
22234
+ image,
22235
+ imageLoaded,
22236
+ calculatedImageSize: imageSize,
22237
+ position = "center"
22238
+ } = this.renderObject;
22239
+ if (!image)
22240
+ return;
22241
+ if (!imageLoaded)
22242
+ return;
22243
+ assert(imageSize != null);
22244
+ const { sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight } = calculateImageRendering(
22245
+ { width: image.width, height: image.height },
22246
+ {
22247
+ container: size,
22248
+ image: { width: imageSize.width, height: imageSize.height }
22249
+ },
22250
+ position
22251
+ );
22252
+ context.canvas.drawImage(
22253
+ image,
22254
+ sx,
22255
+ sy,
22256
+ sWidth,
22257
+ sHeight,
22258
+ offset.x + dx,
22259
+ offset.y + dy,
22260
+ dWidth,
22261
+ dHeight
22262
+ );
22263
+ }
22264
+ };
22265
+ var ImageSvgPainter = class extends SvgPainter {
22266
+ createDefaultSvgEl(context) {
22267
+ return {
22268
+ img: context.createSvgEl("image")
22269
+ };
22270
+ }
22271
+ performPaint({ img }) {
22272
+ const { src } = this.renderObject;
22273
+ img.setAttribute("href", src);
22274
+ console.warn("not implemented svg painter on image widget");
22275
+ }
22276
+ };
22277
+ var BaseImage_default = _Image;
22278
+
22279
+ // src/component/Image.ts
22280
+ var Image_default = classToFunction_default(BaseImage_default);
21569
22281
  })();