UNPKG

@tldraw/state

Version:

tldraw infinite canvas SDK (state).

82 lines (81 loc) 2.56 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var helpers_exports = {}; __export(helpers_exports, { EMPTY_ARRAY: () => EMPTY_ARRAY, attach: () => attach, detach: () => detach, equals: () => equals, hasReactors: () => hasReactors, haveParentsChanged: () => haveParentsChanged, singleton: () => singleton }); module.exports = __toCommonJS(helpers_exports); function isChild(x) { return x && typeof x === "object" && "parents" in x; } function haveParentsChanged(child) { for (let i = 0, n = child.parents.length; i < n; i++) { child.parents[i].__unsafe__getWithoutCapture(true); if (child.parents[i].lastChangedEpoch !== child.parentEpochs[i]) { return true; } } return false; } function detach(parent, child) { if (!parent.children.remove(child)) { return; } if (parent.children.isEmpty && isChild(parent)) { for (let i = 0, n = parent.parents.length; i < n; i++) { detach(parent.parents[i], parent); } } } function attach(parent, child) { if (!parent.children.add(child)) { return; } if (isChild(parent)) { for (let i = 0, n = parent.parents.length; i < n; i++) { attach(parent.parents[i], parent); } } } function equals(a, b) { const shallowEquals = a === b || Object.is(a, b) || Boolean(a && b && typeof a.equals === "function" && a.equals(b)); return shallowEquals; } function singleton(key, init) { const symbol = Symbol.for(`com.tldraw.state/${key}`); const global = globalThis; global[symbol] ??= init(); return global[symbol]; } const EMPTY_ARRAY = singleton("empty_array", () => Object.freeze([])); function hasReactors(signal) { for (const child of signal.children) { if (child.isActivelyListening) { return true; } } return false; } //# sourceMappingURL=helpers.js.map