← back to justjustai__coco-mascot

Function bodies 19 total

All specs Real LLM only Function bodies
cleanWalkCb function · javascript · L118-L123 (6 LOC)
src/capabilities/follow.js
    function cleanWalkCb() {
      if (state._walkCb) {
        wrap.removeEventListener('transitionend', state._walkCb);
        state._walkCb = null;
      }
    }
cardAtPosition function · javascript · L125-L133 (9 LOC)
src/capabilities/follow.js
    function cardAtPosition(px) {
      for (var i = 0; i < cards.length; i++) {
        if (!sameRow(i)) continue;
        var cl = cardLeft(i);
        var cw = cardWidth(i);
        if (px >= cl - 20 && px <= cl + cw + 20) return i;
      }
      return state.activeCard;
    }
showThink function · javascript · L140-L151 (12 LOC)
src/capabilities/follow.js
    function showThink(callback) {
      var think = sprite.querySelector('.coco-think');
      if (!think) { if (callback) callback(); return; }
      clearTimeout(state.thinkTimer);
      think.classList.remove('coco-think-show');
      void think.offsetHeight;
      think.classList.add('coco-think-show');
      state.thinkTimer = setTimeout(function() {
        think.classList.remove('coco-think-show');
        if (callback) callback();
      }, 400);
    }
reroute function · javascript · L155-L178 (24 LOC)
src/capabilities/follow.js
    function reroute(targetCard, targetLeft) {
      cleanWalkCb();
      clearTimeout(state._sameCardTimer);
      state._sameCardTimer = null;
      state._sameCardTarget = null;
      var pos = computedLeft();
      var curCard = cardAtPosition(pos);

      state.animQueue = [];
      sprite.classList.remove('coco-tp-out', 'coco-tp-in', 'coco-jump', 'coco-walk');
      sprite.style.removeProperty('--coco-jump-dur');
      wrap.style.transition = 'none';
      wrap.style.left = pos + 'px';
      void wrap.offsetHeight;
      wrap.style.transition = '';
      state.activeCard = curCard;
      state.isTeleporting = false;
      state.pendingTarget = null;

      state.isFollowing = true;
      showThink(function() {
        switchCard(targetCard, targetLeft);
      });
    }
forceHome function · javascript · L182-L203 (22 LOC)
src/capabilities/follow.js
    function forceHome() {
      cleanWalkCb();
      state.animQueue = [];
      state.isTeleporting = false;
      state.pendingTarget = null;
      state.animTarget = null;
      clearTimeout(state.teleportCeiling);
      clearTimeout(state.homeGuardTimer);
      clearTimeout(state.thinkTimer);
      clearTimeout(state._sameCardTimer);
      state._sameCardTimer = null;
      state._sameCardTarget = null;
      sprite.classList.remove('coco-tp-out', 'coco-tp-in', 'coco-jump', 'coco-walk');
      sprite.style.removeProperty('--coco-jump-dur');
      var think = sprite.querySelector('.coco-think');
      if (think) think.classList.remove('coco-think-show');
      wrap.style.transition = 'none';
      wrap.style.left = defaultLeft() + 'px';
      void wrap.offsetHeight;
      wrap.style.transition = '';
      state.activeCard = state.HOME;
    }
runNextStep function · javascript · L207-L277 (71 LOC)
src/capabilities/follow.js
    function runNextStep() {
      if (state.animQueue.length === 0) {
        state.isTeleporting = false;
        state.animTarget = null;
        cleanWalkCb();
        stopWalk();
        if (state.pendingTarget) {
          var p = state.pendingTarget;
          state.pendingTarget = null;
          switchCard(p.card, p.left);
        }
        return;
      }

      var step = state.animQueue.shift();

      if (step.type === 'walk') {
        cleanWalkCb();
        var dist = Math.abs(step.left - currentLeft());
        if (dist > 3) {
          setTransition(dist);
          wrap.style.left = step.left + 'px';
          startWalk();
          state._walkCb = function(e) {
            if (e.propertyName !== 'left') return;
            cleanWalkCb();
            stopWalk();
            if (step.card !== undefined) state.activeCard = step.card;
            runNextStep();
          };
          wrap.addEventListener('transitionend', state._walkCb);
        } else {
          if (st
sameCardWalk function · javascript · L281-L295 (15 LOC)
src/capabilities/follow.js
    function sameCardWalk(targetLeft) {
      state._sameCardTarget = targetLeft;
      if (state._sameCardTimer) return;

      applySameCardWalk(targetLeft);

      state._sameCardTimer = setTimeout(function() {
        state._sameCardTimer = null;
        if (state._sameCardTarget !== null) {
          var t = state._sameCardTarget;
          state._sameCardTarget = null;
          applySameCardWalk(t);
        }
      }, 80);
    }
Citation: Repobility (2026). State of AI-Generated Code. https://repobility.com/research/
applySameCardWalk function · javascript · L297-L313 (17 LOC)
src/capabilities/follow.js
    function applySameCardWalk(targetLeft) {
      var pos = computedLeft();
      var dist = Math.abs(targetLeft - pos);
      if (dist < 3) return;

      wrap.style.transition = 'none';
      wrap.style.left = pos + 'px';
      void wrap.offsetHeight;

      setTransition(dist);
      wrap.style.left = targetLeft + 'px';
      startWalk();

      clearTimeout(state.stopTimer);
      var walkMs = Math.max(250, (dist / SPEED) * 1000 + 100);
      state.stopTimer = setTimeout(stopWalk, walkMs);
    }
switchCard function · javascript · L317-L368 (52 LOC)
src/capabilities/follow.js
    function switchCard(cardIdx, targetLeft) {
      if (cardIdx === state.activeCard) {
        sameCardWalk(targetLeft);
        return;
      }

      clearTimeout(state._sameCardTimer);
      state._sameCardTimer = null;
      state._sameCardTarget = null;

      if (state.isTeleporting) {
        state.pendingTarget = { card: cardIdx, left: targetLeft };
        return;
      }

      var numCards = Math.abs(cardIdx - state.activeCard);
      clearTimeout(state.teleportCeiling);
      state.teleportCeiling = setTimeout(function() {
        if (state.isTeleporting) {
          cleanWalkCb();
          state.animQueue = [];
          state.isTeleporting = false;
          sprite.classList.remove('coco-tp-out', 'coco-tp-in', 'coco-jump', 'coco-walk');
          sprite.style.removeProperty('--coco-jump-dur');
        }
      }, 3000 + numCards * 3000);

      var steps = [];
      var dir = cardIdx > state.activeCard ? 1 : -1;
      var cur = state.activeCard;

      while (cur !== ca
initPosition function · javascript · L372-L378 (7 LOC)
src/capabilities/follow.js
    function initPosition() {
      wrap.style.transition = 'none';
      wrap.style.left = defaultLeft() + 'px';
      void wrap.offsetHeight;
      wrap.style.transition = '';
      state.activeCard = state.HOME;
    }
loop function · javascript · L35-L42 (8 LOC)
src/capabilities/idle-blink.js
    function loop() {
      state.timer = setTimeout(function() {
        if (!mascot._destroyed) {
          mascot.idleBlink();
          loop();
        }
      }, 2500 + Math.random() * 3500);
    }
CocoMascot.constructor method · javascript · L32-L81 (50 LOC)
src/core.js
  constructor(options) {
    if (typeof options === 'string') {
      options = { container: options };
    }
    this.options = Object.assign({
      size: 'md',
      preset: 'static',
    }, options);

    // Resolve container
    var container = this.options.container;
    if (typeof container === 'string') {
      container = document.querySelector(container);
    }
    if (!container) {
      throw new Error('CocoMascot: container not found — ' + this.options.container);
    }
    this.container = container;

    // Inject shared styles
    injectStyles();

    // Create sprite DOM
    this.sprite = createSprite(this.options.size);
    this.wrap = null; // Set by follow capability if needed

    // Internal state
    this._capabilities = new Map();
    this._capState = new Map();
    this._destroyed = false;

    // Apply theme
    if (this.options.theme) {
      this.setTheme(this.options.theme);
    }

    // Mount to DOM
    this.container.appendChild(this.sprite);

    // Tra
CocoMascot.use method · javascript · L88-L127 (40 LOC)
src/core.js
  use(capability) {
    if (this._destroyed) return this;

    // Check dependencies
    if (capability.requires) {
      for (var i = 0; i < capability.requires.length; i++) {
        var dep = capability.requires[i];
        if (!this._capabilities.has(dep)) {
          throw new Error(
            'CocoMascot: capability "' + capability.name + '" requires "' + dep +
            '". Register it first with mascot.use().'
          );
        }
      }
    }

    // Inject CSS (deduped globally)
    if (capability.css) {
      appendCapCss(capability.name, capability.css);
    }

    // Bind methods to instance
    if (capability.methods) {
      var names = Object.keys(capability.methods);
      for (var j = 0; j < names.length; j++) {
        var name = names[j];
        this[name] = capability.methods[name].bind(this);
      }
    }

    // Call init
    if (capability.init) {
      capability.init(this);
    }

    // Store for destroy
    this._capabilities.set(capability.name, ca
CocoMascot.setTheme method · javascript · L133-L152 (20 LOC)
src/core.js
  setTheme(theme) {
    if (!theme) return;
    var map = {
      bodyColor:   '--coco-body-color',
      borderColor: '--coco-border-color',
      eyeColor:    '--coco-eye-color',
      glowColor:   '--coco-glow-color',
      glowStrong:  '--coco-glow-strong',
      glowBright:  '--coco-glow-bright',
      thinkBg:     '--coco-think-bg',
      thinkBorder: '--coco-think-border',
    };
    var keys = Object.keys(theme);
    for (var i = 0; i < keys.length; i++) {
      var prop = map[keys[i]];
      if (prop) {
        this.sprite.style.setProperty(prop, theme[keys[i]]);
      }
    }
  }
CocoMascot.destroy method · javascript · L157-L187 (31 LOC)
src/core.js
  destroy() {
    if (this._destroyed) return;
    this._destroyed = true;

    // Call destroy on all capabilities
    this._capabilities.forEach(function(cap) {
      if (cap.destroy) cap.destroy(this);
    }.bind(this));

    // Remove DOM
    if (this.wrap && this.wrap.parentNode) {
      this.wrap.parentNode.removeChild(this.wrap);
    }
    if (this.sprite && this.sprite.parentNode) {
      this.sprite.parentNode.removeChild(this.sprite);
    }

    // Clear state
    this._capabilities.clear();
    this._capState.clear();
    this.sprite = null;
    this.wrap = null;
    this.container = null;

    // Remove from instances list
    var idx = _instances.indexOf(this);
    if (idx !== -1) _instances.splice(idx, 1);

    // Decrement style ref count
    removeStyles();
  }
If a scraper extracted this row, it came from Repobility (https://repobility.com)
createSprite function · javascript · L11-L26 (16 LOC)
src/sprite.js
export function createSprite(size) {
  var sprite = document.createElement('div');
  sprite.className = 'coco-sprite' + (size && size !== 'md' ? ' coco-size-' + size : '');

  sprite.innerHTML =
    '<div class="coco-ant coco-ant-l"></div>' +
    '<div class="coco-ant coco-ant-r"></div>' +
    '<div class="coco-body"></div>' +
    '<div class="coco-eye coco-eye-l"></div>' +
    '<div class="coco-eye coco-eye-r"></div>' +
    '<div class="coco-leg coco-leg-l"></div>' +
    '<div class="coco-leg coco-leg-r"></div>' +
    '<div class="coco-think">?</div>';

  return sprite;
}
spriteHtml function · javascript · L34-L46 (13 LOC)
src/sprite.js
export function spriteHtml(size) {
  var cls = 'coco-sprite' + (size && size !== 'md' ? ' coco-size-' + size : '');
  return '<div class="' + cls + '">' +
    '<div class="coco-ant coco-ant-l"></div>' +
    '<div class="coco-ant coco-ant-r"></div>' +
    '<div class="coco-body"></div>' +
    '<div class="coco-eye coco-eye-l"></div>' +
    '<div class="coco-eye coco-eye-r"></div>' +
    '<div class="coco-leg coco-leg-l"></div>' +
    '<div class="coco-leg coco-leg-r"></div>' +
    '<div class="coco-think">?</div>' +
    '</div>';
}
injectStyles function · javascript · L144-L151 (8 LOC)
src/styles.js
export function injectStyles() {
  _refCount++;
  if (_styleEl) return;
  _styleEl = document.createElement('style');
  _styleEl.id = 'coco-mascot-styles';
  _styleEl.textContent = BASE_CSS;
  document.head.appendChild(_styleEl);
}
removeStyles function · javascript · L167-L175 (9 LOC)
src/styles.js
export function removeStyles() {
  _refCount--;
  if (_refCount <= 0 && _styleEl) {
    _styleEl.remove();
    _styleEl = null;
    _refCount = 0;
    _capCss.clear();
  }
}