var API_KEY = 'PIXABAY_API'; var GOOGLE_FONTS_API_KEY = 'GOOGLE_FONTS_API_KEY'; // for legacy browsers const AudioContext = window.AudioContext || window.webkitAudioContext; const audioContext = new AudioContext(); var oldsrc, oldobj; var oldtimelinepos; var speed = 1; var page = 1; var checkstatus = false; let db = new Localbase('db'); var wip = false; var paused = true; var currenttime = 0; var timelinetime = 5; const offset_left = 20; var duration = 30000; var keyframes = []; var p_keyframes = []; var props = [ 'left', 'top', 'scaleX', 'scaleY', 'width', 'height', 'angle', 'opacity', 'fill', 'strokeWidth', 'stroke', 'shadow.color', 'shadow.opacity', 'shadow.offsetX', 'shadow.offsetY', 'shadow.blur', 'charSpacing', 'lineHeight', ]; var objects = []; var o_slider, o_letter_slider, o_line_slider; var colormode = 'fill'; var spaceDown = false; var selectedkeyframe; var undo = []; var undoarr = []; var redo = []; var groups = []; var redoarr = []; var state; var statearr = []; var recording = false; var canvasrecord; var clipboard; var focus = false; var editingpanel = false; var files = []; var re = /(?:\.([^.]+))?$/; var filelist = []; var timeout; var spacehold = false; var spacerelease = false; var tempselection; var line_h, line_v; var tempgroup = []; var editinggroup = false; var tempgroupid; var fontPicker; var fonts = []; var seeking = false; var setting = false; var handtool = false; var canvasx = 0; var canvasy = 0; var overCanvas = false; var draggingPanel = false; var cropping = false; var cropobj; var cropscalex; var cropscaley; var croptop; var cropleft; var layer_count = 1; var lockmovement = false; var shiftx = 0; var shifty = 0; var editinglayer = false; var editingproject = false; var shiftkeys = []; var shiftdown = false; var cliptype = 'object'; var chromaslider, noiseslider, blurslider; var isChrome = window.chrome && Object.values(window.chrome).length !== 0; var eyeDropper; if (isChrome) { eyeDropper = new EyeDropper(); } var presets = [ { name: 'Dribbble shot', id: 'dribbble', width: 1600, height: 1200, }, { name: 'Facebook post', id: 'facebook', width: 1280, height: 720 }, { name: 'Facebook ad', id: 'facebook-ad', width: 1080, height: 1080, }, { name: 'Youtube video', id: 'youtube', width: 1920, height: 1080 }, { name: 'Instagram video', id: 'instagram-id', width: 1080, height: 1920, }, { name: 'Instagram stories', id: 'instagram-stories', width: 1080, height: 1920, }, { name: 'Twitter video', id: 'twitter', width: 1280, height: 720 }, { name: 'Snapchat ad', id: 'snapchat', width: 1080, height: 1920 }, { name: 'LinkedIn video', id: 'linkedin', width: 1920, height: 1080, }, { name: 'Product Hunt thumbnail', id: 'product-hunt', width: 600, height: 600, }, { name: 'Pinterest ad', id: 'pinterest', width: 1080, height: 1920, }, ]; var activepreset = 'custom'; var uploaded_images = []; var uploaded_videos = []; var uploading = false; var background_audio = false; var temp_audio = false; var background_key; var sliders = []; var hovertime = 0; var animatedtext = []; // Get list of fonts $.ajax({ url: 'https://www.googleapis.com/webfonts/v1/webfonts?key=' + GOOGLE_FONTS_API_KEY + '&sort=alpha', type: 'GET', dataType: 'json', // added data type success: function (response) { response.items.forEach(function (item) { fonts.push(item.family); }); }, }); // Panel variants const canvas_panel = '

Canvas settings

Preset
Size
Color
Duration
'; const object_panel = '

Layout

Position
Size
Rotation
'; const back_panel = '

Layer

Opacity
Mask
'; const image_panel = '

Layer

Opacity
Mask
'; const selection_panel = '

Layer

Opacity
Group
Group selection
'; const group_panel = '

Layer

Opacity
Mask
Group
Ungroup selection
'; const other_panel = '

Layer

Opacity
Mask
'; const shape_panel = '

Rectangle

Color
Radius
'; const path_panel = '

Shape

Color
'; const text_panel = '

Text

Font
Align
Format
Color
Letter
Line
'; const stroke_panel = '

Stroke

Type
Color
Width
'; const shadow_panel = '

Shadow

Offset
Color
Blur
'; const image_more_panel = '

Image

Edit filters
Crop image
'; const video_more_panel = '

Video

Edit filters
'; const animated_text_panel = '

Text

Content
Set
Font
Color
'; const start_animation_panel = '

Start animation

Preset
Easing
Order
Backward
Forward
Order
Letters
Words
Duration
'; const audio_panel = '

Audio

Volume
'; // Browser variants const shape_browser = '

Objects

Shapes

Emojis

'; const image_browser = '

Images

Browse millions of high quality images from Pixabay. Use the search bar above or choose from popular categories below.
'; const text_browser = '

Text

Basic text

Add a heading
Add a subheading
Add body text
'; const video_browser = '

Videos

Browse millions of high quality images from Pixabay. Use the search bar above or choose from popular categories below.
'; const upload_browser = '

Uploads

Upload media
Images
Videos
'; const audio_browser = '

Audio

Upload audio
Audio provided by Pixabay. Browse millions of assets from Pixabay by clicking here.
'; // Text animation list var text_animation_list = [ { name: 'fade in', label: 'Fade in', src: 'assets/fade-in.svg' }, { name: 'typewriter', label: 'Typewriter', src: 'assets/typewriter.svg', }, { name: 'slide top', label: 'Slide top', src: 'assets/slide-top.svg', }, { name: 'slide bottom', label: 'Slide bottom', src: 'assets/slide-bottom.svg', }, { name: 'slide left', label: 'Slide left', src: 'assets/slide-left.svg', }, { name: 'slide right', label: 'Slide right', src: 'assets/slide-right.svg', }, { name: 'scale', label: 'Scale', src: 'assets/scale.svg' }, { name: 'shrink', label: 'Shrink', src: 'assets/shrink.svg' }, ]; // Shapes list var shape_grid_items = [ 'assets/shapes/rectangle.svg', 'assets/shapes/circle.svg', 'assets/shapes/triangle.svg', 'assets/shapes/polygon.svg', 'assets/shapes/star.svg', 'assets/thingy.svg', 'assets/shapes/heart.svg', 'assets/shapes/arrow.svg', ]; var emoji_items = [ 'assets/twemojis/laughing-emoji.png', 'assets/twemojis/crying-emoji.png', 'assets/twemojis/surprised-emoji.png', 'assets/twemojis/smiling-emoji.png', 'assets/twemojis/tongue-emoji.png', 'assets/twemojis/heart-eyes-emoji.png', 'assets/twemojis/heart-kiss-emoji.png', 'assets/twemojis/sunglasses-cool-emoji.png', 'assets/twemojis/ghost-emoji.png', 'assets/twemojis/skull-emoji.png', 'assets/twemojis/mindblown-emoji.png', 'assets/twemojis/bomb-emoji.png', 'assets/twemojis/hundred-100-points-emoji.png', 'assets/twemojis/thought-balloon-emoji.png', 'assets/twemojis/wave-emoji.png', 'assets/twemojis/point-emoji.png', 'assets/twemojis/thumbs-up-emoji.png', 'assets/twemojis/clap-emoji.png', 'assets/twemojis/raising-hands-emoji.png', 'assets/twemojis/praying-hands-emoji.png', 'assets/twemojis/nail-polish-emoji.png', 'assets/twemojis/eyes-emoji.png', 'assets/twemojis/cat-face-emoji.png', 'assets/twemojis/dog-face-emoji.png', 'assets/twemojis/rose-emoji.png', 'assets/twemojis/tulip-emoji.png', 'assets/twemojis/pizza-emoji.png', 'assets/twemojis/construction-emoji.png', 'assets/twemojis/plane-emoji.png', 'assets/twemojis/rocket-emoji.png', 'assets/twemojis/clock-emoji.png', 'assets/twemojis/star-emoji.png', 'assets/twemojis/sun-emoji.png', 'assets/twemojis/moon-emoji.png', 'assets/twemojis/fire-emoji.png', 'assets/twemojis/sparkles-emoji.png', 'assets/twemojis/party-popper-emoji.png', 'assets/twemojis/gift-emoji.png', 'assets/twemojis/trophy-emoji.png', 'assets/twemojis/target-emoji.png', 'assets/twemojis/gem-emoji.png', 'assets/twemojis/money-emoji.png', 'assets/twemojis/pencil-emoji.png', 'assets/twemojis/graph-emoji.png', 'assets/twemojis/wip-emoji.png', 'assets/twemojis/winking-face-emoji.png', 'assets/twemojis/pleading-face-emoji.png', 'assets/twemojis/thinking-face-emoji.png', ]; // Image list var image_grid_items = [ 'https://images.unsplash.com/photo-1609153259378-a8b23c766aec?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=1866&q=80', 'https://images.unsplash.com/photo-1614435082296-ef0cbdb16b70?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=934&q=80', 'https://images.unsplash.com/photo-1614432254115-7e756705e910?ixid=MXwxMjA3fDB8MHxlZGl0b3JpYWwtZmVlZHwxMHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=900&q=60', 'https://images.unsplash.com/photo-1614423234685-544477464e15?ixid=MXwxMjA3fDB8MHxlZGl0b3JpYWwtZmVlZHw4fHx8ZW58MHx8fA%3D%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=900&q=60', 'https://images.unsplash.com/photo-1614357235247-99fabbee67f9?ixid=MXwxMjA3fDB8MHxlZGl0b3JpYWwtZmVlZHwxNHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=900&q=60', 'https://images.unsplash.com/photo-1614373371549-c7d2e4885f17?ixid=MXwxMjA3fDB8MHxlZGl0b3JpYWwtZmVlZHwxOXx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=900&q=60', ]; var image_categories = [ { name: 'background', image: 'assets/background.png' }, { name: 'wallpaper', image: 'assets/wallpaper.png' }, { name: 'nature', image: 'assets/nature.png' }, { name: 'summer', image: 'assets/summer.png' }, { name: 'beach', image: 'assets/beach.png' }, { name: 'space', image: 'assets/space.png' }, { name: 'office', image: 'assets/office.png' }, { name: 'food', image: 'assets/food.png' }, ]; // Video list var video_categories = [ { name: 'rain', image: 'assets/rain.png' }, { name: 'cars', image: 'assets/cars.png' }, { name: 'meditation', image: 'assets/meditation.png' }, { name: 'forest', image: 'assets/forest.png' }, { name: 'animals', image: 'assets/animals.png' }, { name: 'street', image: 'assets/street.png' }, { name: 'travel', image: 'assets/travel.png' }, { name: 'work', image: 'assets/work.png' }, ]; // Audio list var audio_items = [ { name: 'Lofi Study', desc: 'FASSounds', duration: '2:27', thumb: 'assets/audio/lofi-thumb.png', src: 'assets/audio/lofi.mp3', link: 'https://pixabay.com/users/fassounds-3433550/', }, { name: 'Stomping Rock (Four Shots)', desc: 'AlexGrohl', duration: '1:59', thumb: 'assets/audio/stomping-rock-thumb.png', src: 'assets/audio/stomping-rock.mp3', link: 'https://pixabay.com/users/alexgrohl-25289918/', }, { name: 'Everything Feels New', desc: 'EvgenyBardyuzha', duration: '1:06', thumb: 'assets/audio/everything-feels-new-thumb.png', src: 'assets/audio/everything-feels-new.mp3', link: 'https://pixabay.com/users/evgenybardyuzha-25235210/', }, { name: 'Both of Us', desc: 'madiRFAN', duration: '2:48', thumb: 'assets/audio/both-of-us-thumb.png', src: 'assets/audio/both-of-us.mp3', link: 'https://pixabay.com/users/madirfan-50411/', }, { name: 'The Podcast Intro', desc: 'Music Unlimited', duration: '1:51', thumb: 'assets/audio/the-podcast-intro-thumb.png', src: 'assets/audio/the-podcast-intro.mp3', link: 'https://pixabay.com/users/music_unlimited-27600023/', }, { name: 'Epic Cinematic Trailer', desc: 'PavelYudin', duration: '2:27', thumb: 'assets/audio/epic-cinematic-trailer-thumb.png', src: 'assets/audio/epic-cinematic-trailer.mp3', link: 'https://pixabay.com/users/pavelyudin-27739282/', }, { name: 'Inspirational Background', desc: 'AudioCoffee', duration: '2:19', thumb: 'assets/audio/inspirational-background-thumb.png', src: 'assets/audio/inspirational-background.mp3', link: 'https://pixabay.com/users/audiocoffee-27005420/', }, { name: 'Tropical Summer Music', desc: 'Music Unlimited', duration: '2:35', thumb: 'assets/audio/tropical-summer-music-thumb.png', src: 'assets/audio/tropical-summer-music.mp3', link: 'https://pixabay.com/users/music_unlimited-27600023/', }, ]; // Text list var text_items = { sansserif: [ { name: 'Roboto', fontname: 'Roboto' }, { name: 'Montserrat', fontname: 'Montserrat' }, { name: 'Poppins', fontname: 'Poppins' }, ], serif: [ { name: 'Playfair Display', fontname: 'Playfair Display' }, { name: 'Merriweather', fontname: 'Merriweather' }, { name: 'IBM Plex Serif', fontname: 'IBM Plex Serif' }, ], monospace: [ { name: 'Roboto Mono', fontname: 'Roboto Mono' }, { name: 'Inconsolata', fontname: 'Inconsolata' }, { name: 'Source Code Pro', fontname: 'Source Code Pro' }, ], handwriting: [ { name: 'Dancing Script', fontname: 'Dancing Script' }, { name: 'Pacifico', fontname: 'Pacifico' }, { name: 'Indie Flower', fontname: 'Indie Flower' }, ], display: [ { name: 'Lobster', fontname: 'Lobster' }, { name: 'Bebas Neue', fontname: 'Bebas Neue' }, { name: 'Titan One', fontname: 'Titan One' }, ], }; WebFont.load({ google: { families: ['Syne'], }, active: () => {}, }); var webglBackend; try { webglBackend = new fabric.WebglFilterBackend(); } catch (e) { console.log(e); } var canvas2dBackend = new fabric.Canvas2dFilterBackend(); fabric.filterBackend = fabric.initFilterBackend(); fabric.filterBackend = webglBackend; // Lottie support fabric.Lottie = fabric.util.createClass(fabric.Image, { type: 'lottie', lockRotation: true, lockSkewingX: true, lockSkewingY: true, srcFromAttribute: false, initialize: function (path, options) { if (!options.width) options.width = 480; if (!options.height) options.height = 480; this.path = path; this.tmpCanvasEl = fabric.util.createCanvasElement(); this.tmpCanvasEl.width = options.width; this.tmpCanvasEl.height = options.height; this.lottieItem = bodymovin.loadAnimation({ renderer: 'canvas', loop: false, autoplay: false, path: path, rendererSettings: { context: this.tmpCanvasEl.getContext('2d'), preserveAspectRatio: 'xMidYMid meet', }, }); this.lottieItem.addEventListener('enterFrame', (e) => { this.canvas.requestRenderAll(); }); this.lottieItem.addEventListener('DOMLoaded', () => { this.lottieItem.goToAndStop(currenttime, false); this.lottieItem.duration = this.lottieItem.getDuration(false) * 1000; this.canvas.requestRenderAll(); canvas.renderAll(); canvas.fire('lottie:loaded', { any: 'payload' }); }); this.callSuper('initialize', this.tmpCanvasEl, options); }, goToSeconds: function (seconds) { this.lottieItem.goToAndStop(seconds, false); this.canvas.requestRenderAll(); }, goToFrame: function (frame) { this.lottieItem.goToAndStop(frame, true); }, getDuration: function () { return this.lottieItem.getDuration(false); }, play: function () { this.lottieItem.play(); }, pause: function () { this.lottieItem.pause(); }, getSrc: function () { return this.path; }, }); fabric.Lottie.fromObject = function (_object, callback) { const object = fabric.util.object.clone(_object); fabric.Image.prototype._initFilters.call( object, object.filters, function (filters) { object.filters = filters || []; fabric.Image.prototype._initFilters.call( object, [object.resizeFilter], function (resizeFilters) { object.resizeFilter = resizeFilters[0]; fabric.util.enlivenObjects( [object.clipPath], function (enlivedProps) { object.clipPath = enlivedProps[0]; const fabricLottie = new fabric.Lottie( object.src, object ); callback(fabricLottie, false); } ); } ); } ); }; // Initialize canvas var canvas = new fabric.Canvas('canvas', { preserveObjectStacking: true, backgroundColor: '#FFF', stateful: true, }); canvas.selection = false; canvas.controlsAboveOverlay = true; // Customize controls fabric.Object.prototype.set({ transparentCorners: false, borderColor: '#51B9F9', cornerColor: '#FFF', borderScaleFactor: 2.5, cornerStyle: 'circle', cornerStrokeColor: '#0E98FC', borderOpacityWhenMoving: 1, }); canvas.selectionColor = 'rgba(46, 115, 252, 0.11)'; canvas.selectionBorderColor = 'rgba(98, 155, 255, 0.81)'; canvas.selectionLineWidth = 1.5; var img = document.createElement('img'); img.src = 'assets/middlecontrol.svg'; var img2 = document.createElement('img'); img2.src = 'assets/middlecontrolhoz.svg'; var img3 = document.createElement('img'); img3.src = 'assets/edgecontrol.svg'; var img4 = document.createElement('img'); img4.src = 'assets/rotateicon.svg'; function renderIcon(ctx, left, top, styleOverride, fabricObject) { const wsize = 20; const hsize = 25; ctx.save(); ctx.translate(left, top); ctx.rotate(fabric.util.degreesToRadians(fabricObject.angle)); ctx.drawImage(img, -wsize / 2, -hsize / 2, wsize, hsize); ctx.restore(); } function renderIconHoz(ctx, left, top, styleOverride, fabricObject) { const wsize = 25; const hsize = 20; ctx.save(); ctx.translate(left, top); ctx.rotate(fabric.util.degreesToRadians(fabricObject.angle)); ctx.drawImage(img2, -wsize / 2, -hsize / 2, wsize, hsize); ctx.restore(); } function renderIconEdge(ctx, left, top, styleOverride, fabricObject) { const wsize = 25; const hsize = 25; ctx.save(); ctx.translate(left, top); ctx.rotate(fabric.util.degreesToRadians(fabricObject.angle)); ctx.drawImage(img3, -wsize / 2, -hsize / 2, wsize, hsize); ctx.restore(); } function renderIconRotate( ctx, left, top, styleOverride, fabricObject ) { const wsize = 40; const hsize = 40; ctx.save(); ctx.translate(left, top); ctx.rotate(fabric.util.degreesToRadians(fabricObject.angle)); ctx.drawImage(img4, -wsize / 2, -hsize / 2, wsize, hsize); ctx.restore(); } function resetControls() { fabric.Object.prototype.controls.ml = new fabric.Control({ x: -0.5, y: 0, offsetX: -1, cursorStyleHandler: fabric.controlsUtils.scaleSkewCursorStyleHandler, actionHandler: fabric.controlsUtils.scalingXOrSkewingY, getActionName: fabric.controlsUtils.scaleOrSkewActionName, render: renderIcon, }); fabric.Object.prototype.controls.mr = new fabric.Control({ x: 0.5, y: 0, offsetX: 1, cursorStyleHandler: fabric.controlsUtils.scaleSkewCursorStyleHandler, actionHandler: fabric.controlsUtils.scalingXOrSkewingY, getActionName: fabric.controlsUtils.scaleOrSkewActionName, render: renderIcon, }); fabric.Object.prototype.controls.mb = new fabric.Control({ x: 0, y: 0.5, offsetY: 1, cursorStyleHandler: fabric.controlsUtils.scaleSkewCursorStyleHandler, actionHandler: fabric.controlsUtils.scalingYOrSkewingX, getActionName: fabric.controlsUtils.scaleOrSkewActionName, render: renderIconHoz, }); fabric.Object.prototype.controls.mt = new fabric.Control({ x: 0, y: -0.5, offsetY: -1, cursorStyleHandler: fabric.controlsUtils.scaleSkewCursorStyleHandler, actionHandler: fabric.controlsUtils.scalingYOrSkewingX, getActionName: fabric.controlsUtils.scaleOrSkewActionName, render: renderIconHoz, }); fabric.Object.prototype.controls.tl = new fabric.Control({ x: -0.5, y: -0.5, cursorStyleHandler: fabric.controlsUtils.scaleCursorStyleHandler, actionHandler: fabric.controlsUtils.scalingEqually, render: renderIconEdge, }); fabric.Object.prototype.controls.tr = new fabric.Control({ x: 0.5, y: -0.5, cursorStyleHandler: fabric.controlsUtils.scaleCursorStyleHandler, actionHandler: fabric.controlsUtils.scalingEqually, render: renderIconEdge, }); fabric.Object.prototype.controls.bl = new fabric.Control({ x: -0.5, y: 0.5, cursorStyleHandler: fabric.controlsUtils.scaleCursorStyleHandler, actionHandler: fabric.controlsUtils.scalingEqually, render: renderIconEdge, }); fabric.Object.prototype.controls.br = new fabric.Control({ x: 0.5, y: 0.5, cursorStyleHandler: fabric.controlsUtils.scaleCursorStyleHandler, actionHandler: fabric.controlsUtils.scalingEqually, render: renderIconEdge, }); fabric.Object.prototype.controls.mtr = new fabric.Control({ x: 0, y: 0.5, cursorStyleHandler: fabric.controlsUtils.rotationStyleHandler, actionHandler: fabric.controlsUtils.rotationWithSnapping, offsetY: 30, withConnecton: false, actionName: 'rotate', render: renderIconRotate, }); } resetControls(); var textBoxControls = (fabric.Textbox.prototype.controls = {}); textBoxControls.mtr = fabric.Object.prototype.controls.mtr; textBoxControls.tr = fabric.Object.prototype.controls.tr; textBoxControls.br = fabric.Object.prototype.controls.br; textBoxControls.tl = fabric.Object.prototype.controls.tl; textBoxControls.bl = fabric.Object.prototype.controls.bl; textBoxControls.mt = fabric.Object.prototype.controls.mt; textBoxControls.mb = fabric.Object.prototype.controls.mb; textBoxControls.ml = new fabric.Control({ x: -0.5, y: 0, offsetX: -1, cursorStyleHandler: fabric.controlsUtils.scaleSkewCursorStyleHandler, actionHandler: fabric.controlsUtils.changeWidth, actionName: 'resizing', render: renderIcon, }); textBoxControls.mr = new fabric.Control({ x: 0.5, y: 0, offsetX: 1, cursorStyleHandler: fabric.controlsUtils.scaleSkewCursorStyleHandler, actionHandler: fabric.controlsUtils.changeWidth, actionName: 'resizing', render: renderIcon, }); // Get any object by ID fabric.Canvas.prototype.getItemById = function (name) { var object = null, objects = this.getObjects(); for (var i = 0, len = this.size(); i < len; i++) { if (objects[i].get('type') == 'group') { if (objects[i].get('id') && objects[i].get('id') === name) { object = objects[i]; break; } var wip = i; for (var o = 0; o < objects[i]._objects.length; o++) { if ( objects[wip]._objects[o].id && objects[wip]._objects[o].id === name ) { object = objects[wip]._objects[o]; break; } } } else if (objects[i].id && objects[i].id === name) { object = objects[i]; break; } } return object; }; // Create the artboard var a_width = 600; var a_height = 500; var artboard = new fabric.Rect({ left: canvas.get('width') / 2 - a_width / 2, top: canvas.get('height') / 2 - a_height / 2, width: a_width, height: a_height, absolutePositioned: true, rx: 0, ry: 0, fill: '#FFF', hasControls: true, transparentCorners: false, borderColor: '#0E98FC', cornerColor: '#0E98FC', cursorWidth: 1, cursorDuration: 1, cursorDelay: 250, id: 'overlay', }); canvas.renderAll(); // Clip canvas to the artboard canvas.clipPath = artboard; canvas.renderAll(); // Initialize color picker (fill) var o_fill = Pickr.create({ el: '#color-picker-fill', theme: 'nano', inline: true, useAsButton: true, swatches: null, default: '#FFFFFF', showAlways: true, components: { preview: true, opacity: true, hue: true, interaction: { hex: true, rgba: true, hsla: false, hsva: false, cmyk: false, input: true, clear: false, save: false, }, }, }); // Color picker events o_fill .on('init', (instance) => { o_fill.hide(); }) .on('change', (instance) => { if (canvas.getActiveObject()) { const object = canvas.getActiveObject(); if (colormode == 'fill') { $('#object-color-fill input').val( o_fill.getColor().toHEXA().toString().substring(0, 7) ); $('#object-color-fill-opacity input').val( Math.round(o_fill.getColor().toRGBA()[3] * 100 * 100) / 100 ); $('#color-fill-side').css( 'background-color', o_fill.getColor().toHEXA().toString().substring(0, 7) ); object.set('fill', o_fill.getColor().toRGBA().toString()); if (!seeking && !setting) { newKeyframe( 'fill', object, currenttime, object.get('fill'), true ); } } else if (colormode == 'stroke') { $('#object-color-stroke input').val( o_fill.getColor().toHEXA().toString().substring(0, 7) ); $('#object-color-stroke-opacity input').val( Math.round(o_fill.getColor().toRGBA()[3] * 100 * 100) / 100 ); $('#color-stroke-side').css( 'background-color', o_fill.getColor().toHEXA().toString().substring(0, 7) ); object.set('stroke', o_fill.getColor().toRGBA().toString()); if (!seeking && !setting) { newKeyframe( 'stroke', object, currenttime, object.get('stroke'), true ); newKeyframe( 'strokeWidth', object, currenttime, object.get('strokeWidth'), true ); } } else if (colormode == 'shadow') { $('#object-color-shadow input').val( o_fill.getColor().toHEXA().toString().substring(0, 7) ); $('#object-color-shadow-opacity input').val( Math.round(o_fill.getColor().toRGBA()[3] * 100 * 100) / 100 ); $('#color-shadow-side').css( 'background-color', o_fill.getColor().toHEXA().toString().substring(0, 7) ); object.set( 'shadow', new fabric.Shadow({ color: o_fill.getColor().toRGBA().toString(), offsetX: object.shadow.offsetX, offsetY: object.shadow.offsetY, blur: object.shadow.blur, opacity: object.shadow.opacity, }) ); if (!seeking && !setting) { newKeyframe( 'shadow.color', object, currenttime, object.shadow.color, true ); } } else if (colormode == 'chroma') { var obj = canvas.getActiveObject(); $('#chroma-color input').val( o_fill.getColor().toHEXA().toString().substring(0, 7) ); $('#color-chroma-side').css( 'background-color', o_fill.getColor().toHEXA().toString().substring(0, 7) ); if (obj.filters.find((x) => x.type == 'RemoveColor')) { obj.filters.find((x) => x.type == 'RemoveColor').color = o_fill.getColor().toRGBA().toString(); } updateChromaValues(); } else if (colormode == 'text') { var obj = canvas.getActiveObject(); $('#text-color input').val( o_fill.getColor().toHEXA().toString().substring(0, 7) ); $('#color-text-side').css( 'background-color', o_fill.getColor().toHEXA().toString().substring(0, 7) ); animatedtext .find((x) => x.id == obj.id) .setProps( { fill: o_fill.getColor().toRGBA().toString() }, canvas ); } canvas.renderAll(); } else { if (colormode == 'back') { $('#canvas-color input').val( o_fill.getColor().toHEXA().toString().substring(0, 7) ); $('#canvas-color-opacity input').val( Math.round(o_fill.getColor().toRGBA()[3] * 100 * 100) / 100 ); $('#color-side').css( 'background-color', o_fill.getColor().toHEXA().toString().substring(0, 7) ); canvas.setBackgroundColor( o_fill.getColor().toRGBA().toString() ); canvas.renderAll(); } } }) .on('show', (instance) => { $('.pcr-current-color').html( "" ); }); var f = fabric.Image.filters; // Canvas recorder initialization var canvasrecord = new fabric.Canvas('canvasrecord', { preserveObjectStacking: true, backgroundColor: '#FFF', width: artboard.width, height: artboard.height, }); var timelineslider = document.getElementById('timeline-zoom'); var t_slider = new RangeSlider(timelineslider, { design: '2d', theme: 'default', handle: 'round', popup: null, showMinMaxLabels: false, unit: '%', min: 5, max: 47, value: 47, onmove: function (x) { setTimelineZoom(-1 * (x - 51)); }, onfinish: function (x) { setTimelineZoom(-1 * (x - 51)); }, onstart: function (x) {}, }); const selectbox = new SelectionArea({ class: 'selection-area', selectables: ['.keyframe'], container: '#timeline', // Query selectors for elements from where a selection can be started from. startareas: ['html'], // Query selectors for elements which will be used as boundaries for the selection. boundaries: ['#timeline'], startThreshold: 10, allowTouch: true, intersect: 'touch', overlap: 'invert', // Configuration in case a selectable gets just clicked. singleTap: { allow: false, intersect: 'native', }, // Scroll configuration. scrolling: { speedDivider: 10, manualSpeed: 750, }, }); selectbox .on('beforestart', (evt) => { if ( $(evt.event.target).hasClass('keyframe') || $(evt.event.target).attr('id') == 'seekbar' || $(evt.event.target).parent().hasClass('main-row') || $(evt.event.target).hasClass('main-row') || $(evt.event.target).hasClass('trim-row') || evt.event.which === 3 ) { return false; } }) .on('start', (evt) => {}) .on('move', (evt) => {}) .on('stop', (evt) => { $('.keyframe-selected').removeClass('keyframe-selected'); shiftkeys = []; if (evt.store.selected.length == 0) { $('.keyframe-selected').removeClass('keyframe-selected'); } else { canvas.discardActiveObject(); canvas.renderAll(); evt.store.selected.forEach(function (key) { shiftkeys.push({ keyframe: key, offset: $(key).offset().left, }); $(key).addClass('keyframe-selected'); }); } });