Skip to content

Commit

Permalink
save this
Browse files Browse the repository at this point in the history
  • Loading branch information
asturur committed Oct 14, 2024
1 parent b00491e commit 2d83a20
Show file tree
Hide file tree
Showing 8 changed files with 515 additions and 243 deletions.
2 changes: 1 addition & 1 deletion .codesandbox/templates/vanilla/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as fabric from 'fabric';
import './styles.css';
import { testCase } from './testcases/loadingSvgs';
import { testCase } from './testcases/simpleTextbox';

const el = document.getElementById('canvas');
const canvas = (window.canvas = new fabric.Canvas(el));
Expand Down
42 changes: 11 additions & 31 deletions .codesandbox/templates/vanilla/src/testcases/simpleTextbox.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,20 @@
import * as fabric from 'fabric';

export function testCase(canvas: fabric.Canvas) {
const textValue = 'fabric.js sandbox';
const text = new fabric.Textbox(textValue, {
originX: 'center',
splitByGrapheme: true,
const textValue = 'LOL';
const path = new fabric.Path(
'M0 200 v-200 h200 a100,100 90 0,1 0,200 a100,100 90 0,1 -200,0 z',
{
fill: '',
stroke: 'red',
},
);
const text = new fabric.IText(textValue, {
width: 200,
top: 20,
styles: fabric.util.stylesFromArray(
[
{
style: {
fontWeight: 'bold',
fontSize: 64,
},
start: 0,
end: 9,
},
],
textValue,
),
path,
objectCaching: false,
});
canvas.add(text);
canvas.centerObjectH(text);
function animate(toState) {
text.animate(
{ scaleX: Math.max(toState, 0.1) * 2 },
{
onChange: () => canvas.renderAll(),
onComplete: () => animate(!toState),
duration: 1000,
easing: toState
? fabric.util.ease.easeInOutQuad
: fabric.util.ease.easeInOutSine,
},
);
}
// animate(1);
}
2 changes: 1 addition & 1 deletion dist-extensions/fabric.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export { FabricText,
*
*/
FabricText as Text, } from './src/shapes/Text/Text';
export type { ITextProps, SerializedITextProps, } from './src/shapes/IText/IText';
export type { ITextProps, SerializedITextProps, CursorRenderingData, CursorBoundaries, } from './src/shapes/IText/IText';
export { IText } from './src/shapes/IText/IText';
export type { GraphemeData, SerializedTextboxProps, TextboxProps, } from './src/shapes/Textbox';
export { Textbox } from './src/shapes/Textbox';
Expand Down
Loading

0 comments on commit 2d83a20

Please sign in to comment.