• Jump To … +
    ./source/asset-management/image-asset.js ./source/asset-management/noise-asset.js ./source/asset-management/raw-asset.js ./source/asset-management/reaction-diffusion-asset.js ./source/asset-management/sprite-asset.js ./source/asset-management/video-asset.js ./source/core/animation-loop.js ./source/core/display-cycle.js ./source/core/document.js ./source/core/events.js ./source/core/init.js ./source/core/library.js ./source/core/snippets.js ./source/core/user-interaction.js ./source/factory/action.js ./source/factory/anchor.js ./source/factory/animation.js ./source/factory/bezier.js ./source/factory/block.js ./source/factory/button.js ./source/factory/canvas.js ./source/factory/cell.js ./source/factory/cog.js ./source/factory/color.js ./source/factory/conic-gradient.js ./source/factory/crescent.js ./source/factory/element.js ./source/factory/emitter.js ./source/factory/enhanced-label.js ./source/factory/filter.js ./source/factory/gradient.js ./source/factory/grid.js ./source/factory/group.js ./source/factory/label.js ./source/factory/line-spiral.js ./source/factory/line.js ./source/factory/loom.js ./source/factory/mesh.js ./source/factory/net.js ./source/factory/oval.js ./source/factory/particle-force.js ./source/factory/particle-spring.js ./source/factory/particle-world.js ./source/factory/particle.js ./source/factory/pattern.js ./source/factory/picture.js ./source/factory/polygon.js ./source/factory/polyline.js ./source/factory/quadratic.js ./source/factory/radial-gradient.js ./source/factory/rectangle.js ./source/factory/render-animation.js ./source/factory/shape.js ./source/factory/spiral.js ./source/factory/stack.js ./source/factory/star.js ./source/factory/tetragon.js ./source/factory/ticker.js ./source/factory/tracer.js ./source/factory/tween.js ./source/factory/unstacked-element.js ./source/factory/wheel.js ./source/helper/array-pool.js ./source/helper/color-engine.js ./source/helper/document-root-elements.js ./source/helper/filter-engine-bluenoise-data.js ./source/helper/filter-engine.js ./source/helper/gradient-engine.js ./source/helper/random-seed.js ./source/helper/shape-path-calculation.js ./source/helper/shared-vars.js ./source/helper/system-flags.js ./source/helper/utilities.js ./source/helper/workstore.js ./source/mixin/anchor.js ./source/mixin/asset-advanced-functionality.js ./source/mixin/asset-consumer.js ./source/mixin/asset.js ./source/mixin/base.js ./source/mixin/button.js ./source/mixin/cascade.js ./source/mixin/cell-key-functions.js ./source/mixin/delta.js ./source/mixin/display-shape.js ./source/mixin/dom.js ./source/mixin/entity.js ./source/mixin/filter.js ./source/mixin/hidden-dom-elements.js ./source/mixin/mimic.js ./source/mixin/path.js ./source/mixin/pattern.js ./source/mixin/pivot.js ./source/mixin/position.js ./source/mixin/shape-basic.js ./source/mixin/shape-curve.js ./source/mixin/styles.js ./source/mixin/text.js ./source/mixin/tween.js ./source/scrawl.js ./source/untracked-factory/cell-fragment.js ./source/untracked-factory/coordinate.js ./source/untracked-factory/drag-zone.js ./source/untracked-factory/keyboard-zone.js ./source/untracked-factory/observe-update.js ./source/untracked-factory/palette.js ./source/untracked-factory/particle-history.js ./source/untracked-factory/quaternion.js ./source/untracked-factory/state.js ./source/untracked-factory/text-style.js ./source/untracked-factory/vector.js
  • §

    Scrawl-canvas snippets

  • §

    To be aware - this functionality is HIGHLY EXPERIMENTAL; it will be subject to short-notice breaking changes as we amend and inprove the concept of Scrawl-canvas snippets

  • §

    TODO - documentation

  • §

    Imports

    import { artefact, unstackedelement } from "./library.js";
    
    import { isa_boolean, isa_dom, isa_obj } from "../helper/utilities.js";
    
    import { makeAnimationObserver } from './events.js';
    
    import { makeRender } from "../factory/render-animation.js";
    import { makeUnstackedElement } from "../factory/unstacked-element.js";
  • §

    Shared constants

    import { _computed } from '../helper/shared-vars.js';
  • §

    Local constants

    const NON_SNIPPET_ELEMENTS = ['AREA', 'BASE', 'BR', 'COL', 'EMBED', 'HR', 'IMG', 'INPUT', 'KEYGEN', 'LINK', 'META', 'PARAM', 'SOURCE', 'TRACK', 'WBR'];
  • §

    TODO - documentation

    export const makeSnippet = function (items) {
    
        const el = (isa_dom(items.domElement)) ? items.domElement : false,
            hooks = (isa_obj(items.animationHooks)) ? items.animationHooks : {},
            cSpec = (isa_obj(items.canvasSpecs)) ? items.canvasSpecs : {},
            oSpec = (isa_obj(items.observerSpecs)) ? items.observerSpecs : {},
            c = (isa_boolean(items.includeCanvas)) ? items.includeCanvas : true;
    
        if (el && el.id && artefact[el.id]) {
    
            return makeStackSnippet(el, cSpec, hooks, oSpec);
        }
        return makeUnstackedSnippet(el, cSpec, hooks, oSpec, c);
    };
  • §

    TODO - documentation

    const makeStackSnippet = function (el, cSpec, hooks, oSpec) {
    
        const element = artefact[el.id];
    
        if (!element) return false;
    
        cSpec.baseMatchesCanvasDimensions = true;
        cSpec.ignoreCanvasCssDimensions = true;
        cSpec.checkForResize = true;
    
        const canvas = element.addCanvas(cSpec);
        element.elementComputedStyles = _computed(el);
    
        hooks.name = `${element.name}-animation`;
        hooks.target = canvas;
    
        const animation = makeRender(hooks);
    
        const observer = makeAnimationObserver(animation, element, oSpec);
    
        const demolish = () => {
            observer();
            animation.kill();
            canvas.demolish();
            element.demolish(true);
        };
    
        return {
            element,
            canvas,
            animation,
            demolish,
        };
    };
  • §

    TODO - documentation

    const makeUnstackedSnippet = function (el, cSpec, hooks, oSpec, c) {
    
        if (!el || NON_SNIPPET_ELEMENTS.includes(el.tagName)) return {};
    
        const id = el.id;
        let element;
    
        if (id && unstackedelement[id]) element = unstackedelement[id];
        else element = makeUnstackedElement(el);
    
        cSpec.baseMatchesCanvasDimensions = true;
        cSpec.checkForResize = true;
    
        const canvas = (c) ? element.addCanvas(cSpec) : false;
    
        hooks.name = `${element.name}-animation`;
        if (canvas) {
    
            if (!hooks.afterClear) hooks.afterClear = () => element.updateCanvas();
            hooks.target = canvas;
        }
        else hooks.noTarget = true;
    
        const animation = makeRender(hooks);
    
        const observer = makeAnimationObserver(animation, element, oSpec);
    
        const demolish = () => {
            observer();
            animation.kill();
            if (canvas) canvas.demolish();
            element.demolish(true);
        };
    
        return {
            element,
            canvas,
            animation,
            demolish,
        };
    };