- Jump To … +
  ./source/core/animation-loop.js ./source/core/display-cycle.js ./source/core/document-root-elements.js ./source/core/document.js ./source/core/events.js ./source/core/init.js ./source/core/library.js ./source/core/random-seed.js ./source/core/shared-vars.js ./source/core/snippets.js ./source/core/system-flags.js ./source/core/user-interaction.js ./source/core/utilities.js ./source/factory/action.js ./source/factory/anchor.js ./source/factory/animation.js ./source/factory/array-pool.js ./source/factory/bezier.js ./source/factory/block.js ./source/factory/canvas.js ./source/factory/cell-fragment.js ./source/factory/cell.js ./source/factory/cog.js ./source/factory/color.js ./source/factory/conic-gradient.js ./source/factory/coordinate.js ./source/factory/crescent.js ./source/factory/drag-zone.js ./source/factory/element.js ./source/factory/emitter.js ./source/factory/filter-engine-bluenoise-data.js ./source/factory/filter-engine.js ./source/factory/filter.js ./source/factory/font-attributes.js ./source/factory/gradient.js ./source/factory/grid.js ./source/factory/group.js ./source/factory/image-asset.js ./source/factory/keyboard-zone.js ./source/factory/line-spiral.js ./source/factory/line.js ./source/factory/loom.js ./source/factory/mesh.js ./source/factory/net.js ./source/factory/noise-asset.js ./source/factory/observe-update.js ./source/factory/oval.js ./source/factory/palette.js ./source/factory/particle-force.js ./source/factory/particle-history.js ./source/factory/particle-spring.js ./source/factory/particle-world.js ./source/factory/particle.js ./source/factory/pattern.js ./source/factory/phrase.js ./source/factory/picture.js ./source/factory/polygon.js ./source/factory/polyline.js ./source/factory/quadratic.js ./source/factory/quaternion.js ./source/factory/radial-gradient.js ./source/factory/raw-asset.js ./source/factory/reaction-diffusion-asset.js ./source/factory/rectangle.js ./source/factory/render-animation.js ./source/factory/shape.js ./source/factory/spiral.js ./source/factory/sprite-asset.js ./source/factory/stack.js ./source/factory/star.js ./source/factory/state.js ./source/factory/tetragon.js ./source/factory/ticker.js ./source/factory/tracer.js ./source/factory/tween.js ./source/factory/unstacked-element.js ./source/factory/vector.js ./source/factory/video-asset.js ./source/factory/wheel.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/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/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/shape-path-calculation.js ./source/mixin/styles.js ./source/mixin/tween.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 "./utilities.js";

      import { makeAnimationObserver } from './events.js';

      import { makeRender } from "../factory/render-animation.js";
      import { makeUnstackedElement } from "../factory/unstacked-element.js";

      import { _computed, NON_SNIPPET_ELEMENTS } from './shared-vars.js';

- §

  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,
          };
      };