@meursyphus/flitter 2.0.1 → 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/README.md +31 -36
- package/index.cjs +384 -3
- package/index.d.cts +63 -34
- package/index.d.ts +63 -34
- package/index.global.js +380 -2
- package/index.js +383 -2
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -13082,6 +13082,30 @@ var rose = {
|
|
|
13082
13082
|
950: "#4c0519"
|
|
13083
13083
|
};
|
|
13084
13084
|
|
|
13085
|
+
// src/type/_types/object-fit.ts
|
|
13086
|
+
var ObjectFit = /* @__PURE__ */ ((ObjectFit2) => {
|
|
13087
|
+
ObjectFit2["fill"] = "fill";
|
|
13088
|
+
ObjectFit2["contain"] = "contain";
|
|
13089
|
+
ObjectFit2["cover"] = "cover";
|
|
13090
|
+
ObjectFit2["none"] = "none";
|
|
13091
|
+
ObjectFit2["scaleDown"] = "scale-down";
|
|
13092
|
+
return ObjectFit2;
|
|
13093
|
+
})(ObjectFit || {});
|
|
13094
|
+
|
|
13095
|
+
// src/type/_types/object-position.ts
|
|
13096
|
+
var ObjectPosition = /* @__PURE__ */ ((ObjectPosition2) => {
|
|
13097
|
+
ObjectPosition2["center"] = "center";
|
|
13098
|
+
ObjectPosition2["top"] = "top";
|
|
13099
|
+
ObjectPosition2["right"] = "right";
|
|
13100
|
+
ObjectPosition2["bottom"] = "bottom";
|
|
13101
|
+
ObjectPosition2["left"] = "left";
|
|
13102
|
+
ObjectPosition2["topLeft"] = "top left";
|
|
13103
|
+
ObjectPosition2["topRight"] = "top right";
|
|
13104
|
+
ObjectPosition2["bottomLeft"] = "bottom left";
|
|
13105
|
+
ObjectPosition2["bottomRight"] = "bottom right";
|
|
13106
|
+
return ObjectPosition2;
|
|
13107
|
+
})(ObjectPosition || {});
|
|
13108
|
+
|
|
13085
13109
|
// src/framework/renderer/renderer.ts
|
|
13086
13110
|
var _resizeHandlers;
|
|
13087
13111
|
var RenderContext = class {
|
|
@@ -14002,10 +14026,10 @@ var RenderObject = class {
|
|
|
14002
14026
|
dispose() {
|
|
14003
14027
|
this.renderOwner.disposeRenderObject(this);
|
|
14004
14028
|
}
|
|
14005
|
-
getIntrinsicWidth(
|
|
14029
|
+
getIntrinsicWidth(_height2) {
|
|
14006
14030
|
return 0;
|
|
14007
14031
|
}
|
|
14008
|
-
getIntrinsicHeight(
|
|
14032
|
+
getIntrinsicHeight(_width2) {
|
|
14009
14033
|
return 0;
|
|
14010
14034
|
}
|
|
14011
14035
|
/*
|
|
@@ -20642,6 +20666,360 @@ dispatch_fn = function(type, event) {
|
|
|
20642
20666
|
(_a = __privateGet(this, _listeners)[type]) == null ? void 0 : _a.forEach((listener) => listener(event));
|
|
20643
20667
|
};
|
|
20644
20668
|
var TextField_default = classToFunction_default(TextField);
|
|
20669
|
+
|
|
20670
|
+
// src/component/base/base-image/calculatePosition.ts
|
|
20671
|
+
var objectPositionMap = {
|
|
20672
|
+
center: { x: 0.5, y: 0.5 },
|
|
20673
|
+
top: { x: 0.5, y: 0 },
|
|
20674
|
+
right: { x: 1, y: 0.5 },
|
|
20675
|
+
bottom: { x: 0.5, y: 1 },
|
|
20676
|
+
left: { x: 0, y: 0.5 },
|
|
20677
|
+
"top left": { x: 0, y: 0 },
|
|
20678
|
+
"top right": { x: 1, y: 0 },
|
|
20679
|
+
"bottom left": { x: 0, y: 1 },
|
|
20680
|
+
"bottom right": { x: 1, y: 1 }
|
|
20681
|
+
};
|
|
20682
|
+
function calcSize(sourceSize, containerSize, imageSize, positionPercent) {
|
|
20683
|
+
if (imageSize > containerSize) {
|
|
20684
|
+
const ratio = sourceSize / imageSize;
|
|
20685
|
+
const sSize = Math.min(sourceSize, containerSize * ratio);
|
|
20686
|
+
const s = (sourceSize - sSize) * positionPercent;
|
|
20687
|
+
return {
|
|
20688
|
+
s: Math.max(0, Math.min(s, sourceSize - sSize)),
|
|
20689
|
+
sSize,
|
|
20690
|
+
d: 0,
|
|
20691
|
+
dSize: containerSize
|
|
20692
|
+
};
|
|
20693
|
+
} else {
|
|
20694
|
+
const d = (containerSize - imageSize) * positionPercent;
|
|
20695
|
+
return {
|
|
20696
|
+
s: 0,
|
|
20697
|
+
sSize: sourceSize,
|
|
20698
|
+
d,
|
|
20699
|
+
dSize: imageSize
|
|
20700
|
+
};
|
|
20701
|
+
}
|
|
20702
|
+
}
|
|
20703
|
+
function calculateImageRendering(sourceImageSize, calcImageSizeResult, objectPosition = "center") {
|
|
20704
|
+
const {
|
|
20705
|
+
container: { width: containerWidth, height: containerHeight },
|
|
20706
|
+
image: { width: imageWidth, height: imageHeight }
|
|
20707
|
+
} = calcImageSizeResult;
|
|
20708
|
+
const { x: xPercent, y: yPercent } = objectPositionMap[objectPosition];
|
|
20709
|
+
const horizontalResult = calcSize(
|
|
20710
|
+
sourceImageSize.width,
|
|
20711
|
+
containerWidth,
|
|
20712
|
+
imageWidth,
|
|
20713
|
+
xPercent
|
|
20714
|
+
);
|
|
20715
|
+
const verticalResult = calcSize(
|
|
20716
|
+
sourceImageSize.height,
|
|
20717
|
+
containerHeight,
|
|
20718
|
+
imageHeight,
|
|
20719
|
+
yPercent
|
|
20720
|
+
);
|
|
20721
|
+
return {
|
|
20722
|
+
sx: Math.round(horizontalResult.s),
|
|
20723
|
+
sy: Math.round(verticalResult.s),
|
|
20724
|
+
sWidth: Math.round(horizontalResult.sSize),
|
|
20725
|
+
sHeight: Math.round(verticalResult.sSize),
|
|
20726
|
+
dx: Math.round(horizontalResult.d),
|
|
20727
|
+
dy: Math.round(verticalResult.d),
|
|
20728
|
+
dWidth: Math.round(horizontalResult.dSize),
|
|
20729
|
+
dHeight: Math.round(verticalResult.dSize)
|
|
20730
|
+
};
|
|
20731
|
+
}
|
|
20732
|
+
|
|
20733
|
+
// src/component/base/base-image/calculateSize.ts
|
|
20734
|
+
function calculateSize(source, container, objectFit = "none") {
|
|
20735
|
+
var _a, _b;
|
|
20736
|
+
const aspectRatio = source.width / source.height;
|
|
20737
|
+
let containerWidth = (_a = container.width) != null ? _a : source.width;
|
|
20738
|
+
let containerHeight = (_b = container.height) != null ? _b : source.height;
|
|
20739
|
+
if (container.width != null && container.height == null) {
|
|
20740
|
+
containerHeight = Math.round(container.width / aspectRatio);
|
|
20741
|
+
} else if (container.width == null && container.height != null) {
|
|
20742
|
+
containerWidth = Math.round(container.height * aspectRatio);
|
|
20743
|
+
}
|
|
20744
|
+
const imageSize = fitFunctions[objectFit](source, {
|
|
20745
|
+
width: containerWidth,
|
|
20746
|
+
height: containerHeight
|
|
20747
|
+
});
|
|
20748
|
+
return {
|
|
20749
|
+
width: Math.round(containerWidth),
|
|
20750
|
+
height: Math.round(containerHeight),
|
|
20751
|
+
image: {
|
|
20752
|
+
width: Math.round(imageSize.width),
|
|
20753
|
+
height: Math.round(imageSize.height)
|
|
20754
|
+
}
|
|
20755
|
+
};
|
|
20756
|
+
}
|
|
20757
|
+
var fitFunctions = {
|
|
20758
|
+
fill: fillFit,
|
|
20759
|
+
contain: containFit,
|
|
20760
|
+
cover: coverFit,
|
|
20761
|
+
none: noneFit,
|
|
20762
|
+
"scale-down": scaleDownFit
|
|
20763
|
+
};
|
|
20764
|
+
function fillFit(source, container) {
|
|
20765
|
+
return { width: container.width, height: container.height };
|
|
20766
|
+
}
|
|
20767
|
+
function containFit(source, result) {
|
|
20768
|
+
const aspectRatio = source.width / source.height;
|
|
20769
|
+
if (result.width / result.height > aspectRatio) {
|
|
20770
|
+
return { width: result.height * aspectRatio, height: result.height };
|
|
20771
|
+
} else {
|
|
20772
|
+
return { width: result.width, height: result.width / aspectRatio };
|
|
20773
|
+
}
|
|
20774
|
+
}
|
|
20775
|
+
function coverFit(source, container) {
|
|
20776
|
+
const aspectRatio = source.width / source.height;
|
|
20777
|
+
if (container.width / container.height > aspectRatio) {
|
|
20778
|
+
return { width: container.width, height: container.width / aspectRatio };
|
|
20779
|
+
} else {
|
|
20780
|
+
return { width: container.height * aspectRatio, height: container.height };
|
|
20781
|
+
}
|
|
20782
|
+
}
|
|
20783
|
+
function noneFit(source, _) {
|
|
20784
|
+
return { width: source.width, height: source.height };
|
|
20785
|
+
}
|
|
20786
|
+
function scaleDownFit(source, container) {
|
|
20787
|
+
const containSize = containFit(source, container);
|
|
20788
|
+
if (containSize.width > source.width || containSize.height > source.height) {
|
|
20789
|
+
return { width: source.width, height: source.height };
|
|
20790
|
+
}
|
|
20791
|
+
return containSize;
|
|
20792
|
+
}
|
|
20793
|
+
|
|
20794
|
+
// src/component/base/base-image/BaseImage.ts
|
|
20795
|
+
var _Image = class extends SingleChildRenderObjectWidget_default {
|
|
20796
|
+
constructor({
|
|
20797
|
+
key,
|
|
20798
|
+
src,
|
|
20799
|
+
objectFit: fit,
|
|
20800
|
+
width,
|
|
20801
|
+
height,
|
|
20802
|
+
objectPosition: position
|
|
20803
|
+
}) {
|
|
20804
|
+
super(key);
|
|
20805
|
+
__publicField(this, "_src");
|
|
20806
|
+
__publicField(this, "_fit");
|
|
20807
|
+
__publicField(this, "_width");
|
|
20808
|
+
__publicField(this, "_height");
|
|
20809
|
+
__publicField(this, "_position");
|
|
20810
|
+
this._src = src;
|
|
20811
|
+
this._fit = fit;
|
|
20812
|
+
this._width = width;
|
|
20813
|
+
this._height = height;
|
|
20814
|
+
this._position = position;
|
|
20815
|
+
}
|
|
20816
|
+
createRenderObject() {
|
|
20817
|
+
return new RenderImage({
|
|
20818
|
+
src: this._src,
|
|
20819
|
+
objectFit: this._fit,
|
|
20820
|
+
width: this._width,
|
|
20821
|
+
height: this._height,
|
|
20822
|
+
objectPosition: this._position
|
|
20823
|
+
});
|
|
20824
|
+
}
|
|
20825
|
+
updateRenderObject(renderObject) {
|
|
20826
|
+
renderObject.src = this._src;
|
|
20827
|
+
renderObject.fit = this._fit;
|
|
20828
|
+
renderObject.width = this._width;
|
|
20829
|
+
renderObject.height = this._height;
|
|
20830
|
+
renderObject.position = this._position;
|
|
20831
|
+
}
|
|
20832
|
+
};
|
|
20833
|
+
var _src, _fit, _width, _height, _position, _mounted;
|
|
20834
|
+
var RenderImage = class extends SingleChildRenderObject_default {
|
|
20835
|
+
constructor({
|
|
20836
|
+
src,
|
|
20837
|
+
objectFit,
|
|
20838
|
+
width,
|
|
20839
|
+
height,
|
|
20840
|
+
objectPosition
|
|
20841
|
+
}) {
|
|
20842
|
+
super({ isPainter: true });
|
|
20843
|
+
__privateAdd(this, _src, void 0);
|
|
20844
|
+
__privateAdd(this, _fit, void 0);
|
|
20845
|
+
__privateAdd(this, _width, void 0);
|
|
20846
|
+
__privateAdd(this, _height, void 0);
|
|
20847
|
+
__privateAdd(this, _position, void 0);
|
|
20848
|
+
__publicField(this, "image");
|
|
20849
|
+
__publicField(this, "imageLoaded", false);
|
|
20850
|
+
__publicField(this, "calculatedImageSize");
|
|
20851
|
+
__privateAdd(this, _mounted, false);
|
|
20852
|
+
__privateSet(this, _src, src);
|
|
20853
|
+
__privateSet(this, _fit, objectFit);
|
|
20854
|
+
__privateSet(this, _width, width);
|
|
20855
|
+
__privateSet(this, _height, height);
|
|
20856
|
+
__privateSet(this, _position, objectPosition);
|
|
20857
|
+
if (browser) {
|
|
20858
|
+
this.image = new Image();
|
|
20859
|
+
this.image.onload = () => {
|
|
20860
|
+
this.imageLoaded = true;
|
|
20861
|
+
if (!__privateGet(this, _mounted))
|
|
20862
|
+
return;
|
|
20863
|
+
this.markNeedsLayout();
|
|
20864
|
+
};
|
|
20865
|
+
this.image.src = src;
|
|
20866
|
+
}
|
|
20867
|
+
}
|
|
20868
|
+
get src() {
|
|
20869
|
+
return __privateGet(this, _src);
|
|
20870
|
+
}
|
|
20871
|
+
set src(value) {
|
|
20872
|
+
if (__privateGet(this, _src) === value)
|
|
20873
|
+
return;
|
|
20874
|
+
__privateSet(this, _src, value);
|
|
20875
|
+
if (this.image != null) {
|
|
20876
|
+
this.image.src = value;
|
|
20877
|
+
}
|
|
20878
|
+
this.markNeedsLayout();
|
|
20879
|
+
}
|
|
20880
|
+
get fit() {
|
|
20881
|
+
return __privateGet(this, _fit);
|
|
20882
|
+
}
|
|
20883
|
+
set fit(value) {
|
|
20884
|
+
if (__privateGet(this, _fit) === value)
|
|
20885
|
+
return;
|
|
20886
|
+
__privateSet(this, _fit, value);
|
|
20887
|
+
this.markNeedsLayout();
|
|
20888
|
+
}
|
|
20889
|
+
get width() {
|
|
20890
|
+
return __privateGet(this, _width);
|
|
20891
|
+
}
|
|
20892
|
+
set width(value) {
|
|
20893
|
+
if (__privateGet(this, _width) === value)
|
|
20894
|
+
return;
|
|
20895
|
+
__privateSet(this, _width, value);
|
|
20896
|
+
this.markNeedsLayout();
|
|
20897
|
+
}
|
|
20898
|
+
get height() {
|
|
20899
|
+
return __privateGet(this, _height);
|
|
20900
|
+
}
|
|
20901
|
+
set height(value) {
|
|
20902
|
+
if (__privateGet(this, _height) === value)
|
|
20903
|
+
return;
|
|
20904
|
+
__privateSet(this, _height, value);
|
|
20905
|
+
this.markNeedsLayout();
|
|
20906
|
+
}
|
|
20907
|
+
get position() {
|
|
20908
|
+
return __privateGet(this, _position);
|
|
20909
|
+
}
|
|
20910
|
+
set position(value) {
|
|
20911
|
+
if (__privateGet(this, _position) === value)
|
|
20912
|
+
return;
|
|
20913
|
+
__privateSet(this, _position, value);
|
|
20914
|
+
this.markNeedsLayout();
|
|
20915
|
+
}
|
|
20916
|
+
getIntrinsicWidth() {
|
|
20917
|
+
if (this.width != null)
|
|
20918
|
+
return this.width;
|
|
20919
|
+
return 0;
|
|
20920
|
+
}
|
|
20921
|
+
getIntrinsicHeight() {
|
|
20922
|
+
if (this.height != null)
|
|
20923
|
+
return this.height;
|
|
20924
|
+
return 0;
|
|
20925
|
+
}
|
|
20926
|
+
preformLayout() {
|
|
20927
|
+
var _a, _b;
|
|
20928
|
+
__privateSet(this, _mounted, true);
|
|
20929
|
+
if (!this.imageLoaded) {
|
|
20930
|
+
this.size = this.constraints.constrain(
|
|
20931
|
+
new size_default({
|
|
20932
|
+
width: (_a = this.width) != null ? _a : 0,
|
|
20933
|
+
height: (_b = this.height) != null ? _b : 0
|
|
20934
|
+
})
|
|
20935
|
+
);
|
|
20936
|
+
return;
|
|
20937
|
+
}
|
|
20938
|
+
assert(this.image != null);
|
|
20939
|
+
const sourceSize = { width: this.image.width, height: this.image.height };
|
|
20940
|
+
const { width, height } = calculateSize(
|
|
20941
|
+
sourceSize,
|
|
20942
|
+
{
|
|
20943
|
+
width: this.width && this.constraints.constrainWidth(this.width),
|
|
20944
|
+
height: this.height && this.constraints.constrainHeight(this.height)
|
|
20945
|
+
},
|
|
20946
|
+
this.fit
|
|
20947
|
+
);
|
|
20948
|
+
const size = new size_default({ width, height });
|
|
20949
|
+
this.size = this.constraints.constrain(size);
|
|
20950
|
+
this.calculatedImageSize = calculateSize(
|
|
20951
|
+
sourceSize,
|
|
20952
|
+
{
|
|
20953
|
+
width: this.size.width,
|
|
20954
|
+
height: this.size.height
|
|
20955
|
+
},
|
|
20956
|
+
this.fit
|
|
20957
|
+
).image;
|
|
20958
|
+
}
|
|
20959
|
+
createCanvasPainter() {
|
|
20960
|
+
return new ImageCanvasPatiner(this);
|
|
20961
|
+
}
|
|
20962
|
+
createSvgPainter() {
|
|
20963
|
+
return new ImageSvgPainter(this);
|
|
20964
|
+
}
|
|
20965
|
+
};
|
|
20966
|
+
_src = new WeakMap();
|
|
20967
|
+
_fit = new WeakMap();
|
|
20968
|
+
_width = new WeakMap();
|
|
20969
|
+
_height = new WeakMap();
|
|
20970
|
+
_position = new WeakMap();
|
|
20971
|
+
_mounted = new WeakMap();
|
|
20972
|
+
var ImageCanvasPatiner = class extends CanvasPainter {
|
|
20973
|
+
performPaint(context, offset) {
|
|
20974
|
+
const {
|
|
20975
|
+
size,
|
|
20976
|
+
image,
|
|
20977
|
+
imageLoaded,
|
|
20978
|
+
calculatedImageSize: imageSize,
|
|
20979
|
+
position = "center"
|
|
20980
|
+
} = this.renderObject;
|
|
20981
|
+
if (!image)
|
|
20982
|
+
return;
|
|
20983
|
+
if (!imageLoaded)
|
|
20984
|
+
return;
|
|
20985
|
+
assert(imageSize != null);
|
|
20986
|
+
const { sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight } = calculateImageRendering(
|
|
20987
|
+
{ width: image.width, height: image.height },
|
|
20988
|
+
{
|
|
20989
|
+
container: size,
|
|
20990
|
+
image: { width: imageSize.width, height: imageSize.height }
|
|
20991
|
+
},
|
|
20992
|
+
position
|
|
20993
|
+
);
|
|
20994
|
+
context.canvas.drawImage(
|
|
20995
|
+
image,
|
|
20996
|
+
sx,
|
|
20997
|
+
sy,
|
|
20998
|
+
sWidth,
|
|
20999
|
+
sHeight,
|
|
21000
|
+
offset.x + dx,
|
|
21001
|
+
offset.y + dy,
|
|
21002
|
+
dWidth,
|
|
21003
|
+
dHeight
|
|
21004
|
+
);
|
|
21005
|
+
}
|
|
21006
|
+
};
|
|
21007
|
+
var ImageSvgPainter = class extends SvgPainter {
|
|
21008
|
+
createDefaultSvgEl(context) {
|
|
21009
|
+
return {
|
|
21010
|
+
img: context.createSvgEl("image")
|
|
21011
|
+
};
|
|
21012
|
+
}
|
|
21013
|
+
performPaint({ img }) {
|
|
21014
|
+
const { src } = this.renderObject;
|
|
21015
|
+
img.setAttribute("href", src);
|
|
21016
|
+
console.warn("not implemented svg painter on image widget");
|
|
21017
|
+
}
|
|
21018
|
+
};
|
|
21019
|
+
var BaseImage_default = _Image;
|
|
21020
|
+
|
|
21021
|
+
// src/component/Image.ts
|
|
21022
|
+
var Image_default = classToFunction_default(BaseImage_default);
|
|
20645
21023
|
export {
|
|
20646
21024
|
Align_default as Align,
|
|
20647
21025
|
alignment_default as Alignment,
|
|
@@ -20709,6 +21087,7 @@ export {
|
|
|
20709
21087
|
GestureDetector_default as GestureDetector,
|
|
20710
21088
|
Globalkey_default as GlobalKey,
|
|
20711
21089
|
Grid_default as Grid,
|
|
21090
|
+
Image_default as Image,
|
|
20712
21091
|
ImplicitlyAnimatedWidget,
|
|
20713
21092
|
ImplicitlyAnimatedWidgetState,
|
|
20714
21093
|
IndexedStack2 as IndexedStack,
|
|
@@ -20722,6 +21101,8 @@ export {
|
|
|
20722
21101
|
matrix4_default as Matrix4,
|
|
20723
21102
|
MultiChildRenderObject_default as MultiChildRenderObject,
|
|
20724
21103
|
MultiChildRenderObjectWidget_default as MultiChildRenderObjectWidget,
|
|
21104
|
+
ObjectFit,
|
|
21105
|
+
ObjectPosition,
|
|
20725
21106
|
offset_default as Offset,
|
|
20726
21107
|
Opacity_default as Opacity,
|
|
20727
21108
|
OverflowBox_default as OverflowBox,
|
package/package.json
CHANGED