UNPKG

@zag-js/core

Version:

A minimal implementation of xstate fsm for UI machines

71 lines (69 loc) 2.03 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); // src/create-machine.ts var create_machine_exports = {}; __export(create_machine_exports, { createGuards: () => createGuards, createMachine: () => createMachine, setup: () => setup }); module.exports = __toCommonJS(create_machine_exports); var import_state = require("./state.js"); function createGuards() { return { and: (...guards) => { return function andGuard(params) { return guards.every((str) => params.guard(str)); }; }, or: (...guards) => { return function orGuard(params) { return guards.some((str) => params.guard(str)); }; }, not: (guard) => { return function notGuard(params) { return !params.guard(guard); }; } }; } function createMachine(config) { (0, import_state.ensureStateIndex)(config); return config; } function setup() { return { guards: createGuards(), createMachine: (config) => { return createMachine(config); }, choose: (transitions) => { return function chooseFn({ choose }) { return choose(transitions)?.actions; }; } }; } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { createGuards, createMachine, setup });