@classytic/stage 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +65 -0
- package/dist/assets/index.d.mts +3 -0
- package/dist/assets/index.mjs +5 -0
- package/dist/assets/kit/glyphs.d.mts +61 -0
- package/dist/assets/kit/glyphs.mjs +256 -0
- package/dist/assets/kit/index.d.mts +2 -0
- package/dist/assets/kit/index.mjs +4 -0
- package/dist/assets/kit/svg-defs.d.mts +6 -0
- package/dist/assets/kit/svg-defs.mjs +137 -0
- package/dist/builder/Palette.d.mts +30 -0
- package/dist/builder/Palette.mjs +100 -0
- package/dist/builder/SceneBuilder.d.mts +26 -0
- package/dist/builder/SceneBuilder.mjs +340 -0
- package/dist/builder/controls.d.mts +18 -0
- package/dist/builder/controls.mjs +29 -0
- package/dist/builder/editor.d.mts +46 -0
- package/dist/builder/editor.mjs +130 -0
- package/dist/builder/icons.d.mts +14 -0
- package/dist/builder/icons.mjs +143 -0
- package/dist/builder/index.d.mts +6 -0
- package/dist/builder/index.mjs +7 -0
- package/dist/builder/tools.d.mts +47 -0
- package/dist/builder/tools.mjs +303 -0
- package/dist/chem/index.d.mts +118 -0
- package/dist/chem/index.mjs +131 -0
- package/dist/core/clock.d.mts +41 -0
- package/dist/core/clock.mjs +62 -0
- package/dist/core/context.d.mts +13 -0
- package/dist/core/context.mjs +29 -0
- package/dist/core/control.d.mts +58 -0
- package/dist/core/control.mjs +113 -0
- package/dist/core/coords.d.mts +51 -0
- package/dist/core/coords.mjs +44 -0
- package/dist/core/index.d.mts +8 -0
- package/dist/core/index.mjs +9 -0
- package/dist/core/learner.d.mts +44 -0
- package/dist/core/learner.mjs +23 -0
- package/dist/core/motion.d.mts +73 -0
- package/dist/core/motion.mjs +103 -0
- package/dist/core/richText.d.mts +28 -0
- package/dist/core/richText.mjs +52 -0
- package/dist/core/vec.d.mts +47 -0
- package/dist/core/vec.mjs +144 -0
- package/dist/field/index.d.mts +58 -0
- package/dist/field/index.mjs +156 -0
- package/dist/index.d.mts +54 -0
- package/dist/index.mjs +55 -0
- package/dist/interaction/MovableDot.d.mts +33 -0
- package/dist/interaction/MovableDot.mjs +66 -0
- package/dist/interaction/hitTest.d.mts +16 -0
- package/dist/interaction/hitTest.mjs +39 -0
- package/dist/interaction/index.d.mts +5 -0
- package/dist/interaction/index.mjs +6 -0
- package/dist/interaction/useDraggable.d.mts +51 -0
- package/dist/interaction/useDraggable.mjs +116 -0
- package/dist/interaction/useScreenToMath.d.mts +12 -0
- package/dist/interaction/useScreenToMath.mjs +25 -0
- package/dist/logic/ast.d.mts +29 -0
- package/dist/logic/ast.mjs +37 -0
- package/dist/logic/index.d.mts +25 -0
- package/dist/logic/index.mjs +36 -0
- package/dist/logic/latex.d.mts +6 -0
- package/dist/logic/latex.mjs +33 -0
- package/dist/logic/minimize.d.mts +37 -0
- package/dist/logic/minimize.mjs +175 -0
- package/dist/logic/parse.d.mts +6 -0
- package/dist/logic/parse.mjs +68 -0
- package/dist/logic/table.d.mts +24 -0
- package/dist/logic/table.mjs +65 -0
- package/dist/logic/tokenize.mjs +258 -0
- package/dist/math/ast.d.mts +35 -0
- package/dist/math/ast.mjs +94 -0
- package/dist/math/calculus.d.mts +9 -0
- package/dist/math/calculus.mjs +188 -0
- package/dist/math/defs.mjs +51 -0
- package/dist/math/index.d.mts +26 -0
- package/dist/math/index.mjs +42 -0
- package/dist/math/latex.d.mts +7 -0
- package/dist/math/latex.mjs +115 -0
- package/dist/math/parse.d.mts +6 -0
- package/dist/math/parse.mjs +91 -0
- package/dist/math/tokenize.mjs +112 -0
- package/dist/primitives/CanvasLayer.d.mts +26 -0
- package/dist/primitives/CanvasLayer.mjs +87 -0
- package/dist/primitives/Dot.d.mts +27 -0
- package/dist/primitives/Dot.mjs +40 -0
- package/dist/primitives/Grid.d.mts +30 -0
- package/dist/primitives/Grid.mjs +122 -0
- package/dist/primitives/Label.d.mts +33 -0
- package/dist/primitives/Label.mjs +45 -0
- package/dist/primitives/Lines.d.mts +50 -0
- package/dist/primitives/Lines.mjs +82 -0
- package/dist/primitives/Plot.d.mts +50 -0
- package/dist/primitives/Plot.mjs +87 -0
- package/dist/primitives/Shapes.d.mts +76 -0
- package/dist/primitives/Shapes.mjs +79 -0
- package/dist/primitives/Tex.d.mts +27 -0
- package/dist/primitives/Tex.mjs +54 -0
- package/dist/primitives/index.d.mts +10 -0
- package/dist/primitives/index.mjs +10 -0
- package/dist/primitives/props.d.mts +15 -0
- package/dist/scene/Scene.d.mts +31 -0
- package/dist/scene/Scene.mjs +168 -0
- package/dist/scene/assets.d.mts +37 -0
- package/dist/scene/assets.mjs +31 -0
- package/dist/scene/commands.d.mts +47 -0
- package/dist/scene/commands.mjs +162 -0
- package/dist/scene/evaluators.d.mts +17 -0
- package/dist/scene/evaluators.mjs +210 -0
- package/dist/scene/index.d.mts +13 -0
- package/dist/scene/index.mjs +13 -0
- package/dist/scene/migrate.d.mts +11 -0
- package/dist/scene/migrate.mjs +35 -0
- package/dist/scene/render.d.mts +14 -0
- package/dist/scene/render.mjs +126 -0
- package/dist/scene/resolve.d.mts +12 -0
- package/dist/scene/resolve.mjs +95 -0
- package/dist/scene/schema.d.mts +9 -0
- package/dist/scene/schema.mjs +51 -0
- package/dist/scene/sims.d.mts +18 -0
- package/dist/scene/sims.mjs +54 -0
- package/dist/scene/store.d.mts +22 -0
- package/dist/scene/store.mjs +37 -0
- package/dist/scene/types.d.mts +228 -0
- package/dist/scene/types.mjs +27 -0
- package/dist/sim/equilibrium.d.mts +36 -0
- package/dist/sim/equilibrium.mjs +54 -0
- package/dist/sim/index.d.mts +9 -0
- package/dist/sim/index.mjs +9 -0
- package/dist/sim/particles.d.mts +43 -0
- package/dist/sim/particles.mjs +136 -0
- package/dist/sim/rate.d.mts +36 -0
- package/dist/sim/rate.mjs +39 -0
- package/dist/sim/registry.d.mts +10 -0
- package/dist/sim/registry.mjs +27 -0
- package/dist/sim/sampler.d.mts +47 -0
- package/dist/sim/sampler.mjs +79 -0
- package/dist/sim/thermal.d.mts +78 -0
- package/dist/sim/thermal.mjs +172 -0
- package/dist/sim/types.d.mts +24 -0
- package/dist/sim/wave.d.mts +34 -0
- package/dist/sim/wave.mjs +61 -0
- package/dist/steps/index.d.mts +62 -0
- package/dist/steps/index.mjs +133 -0
- package/dist/thermo/index.d.mts +82 -0
- package/dist/thermo/index.mjs +133 -0
- package/dist/view/Stage.d.mts +39 -0
- package/dist/view/Stage.mjs +91 -0
- package/dist/view/index.d.mts +4 -0
- package/dist/view/index.mjs +5 -0
- package/dist/view/useElementSize.d.mts +13 -0
- package/dist/view/useElementSize.mjs +40 -0
- package/dist/view/useInView.d.mts +9 -0
- package/dist/view/useInView.mjs +33 -0
- package/package.json +141 -0
- package/styles.css +70 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { StageAssetDefs } from "./assets/kit/svg-defs.mjs";
|
|
2
|
+
import { BucketGlyph, GlyphBox, HangerHook, HangerHookProps, WeightGlyph, XBlockGlyph } from "./assets/kit/glyphs.mjs";
|
|
3
|
+
import { Matrix, Vec2, mat, vec } from "./core/vec.mjs";
|
|
4
|
+
import { CoordinateSystem, CoordsOptions, ViewBox, createCoords, fmt } from "./core/coords.mjs";
|
|
5
|
+
import { AssetGeometry, Binding, CircleVal, DerivedDef, DerivedElement, DerivedKind, ElementBase, ElementStyle, FreeElement, FreeNote, FreePoint, FreeScalar, Id, LabMeta, NumOrRef, Op, Ref, SceneDoc, SceneElement, SceneMeta, ShapeLineVal, Val, isAssetGeom, isCircleVal, isDerived, isFree, isLineVal, isVec2, numOf } from "./scene/types.mjs";
|
|
6
|
+
import { Command, CommandResult, MutatePatch, applyCommand, collectRemoved, inverse } from "./scene/commands.mjs";
|
|
7
|
+
import { Resolved, resolve } from "./scene/resolve.mjs";
|
|
8
|
+
import { DispatchOpts, Editor, useEditor } from "./builder/editor.mjs";
|
|
9
|
+
import { ControlMap, ControlSpec, ControlSurface, getControlSurface, listControlSurfaces, onControlChange, useControlSurface } from "./core/control.mjs";
|
|
10
|
+
import { ControlPick, controlsFromScene } from "./builder/controls.mjs";
|
|
11
|
+
import { IconName, ToolIcon } from "./builder/icons.mjs";
|
|
12
|
+
import { AUTHORING_TOOLS, CIRCLE, DELETE, GEOMETRY_TOOLS, INTERSECT, LINE, MEASURE, MIDPOINT, NOTE, POINT, SCALAR, SEGMENT, SELECT, Tool, ToolCtx } from "./builder/tools.mjs";
|
|
13
|
+
import { SceneBuilder, SceneBuilderProps } from "./builder/SceneBuilder.mjs";
|
|
14
|
+
import { Palette, PaletteProps } from "./builder/Palette.mjs";
|
|
15
|
+
import { CoordsContext, DragOverlayContext, StageRefContext, useCoords, useDragOverlay, useStageRef } from "./core/context.mjs";
|
|
16
|
+
import { ClockProvider, ClockProviderProps, FrameDriver, FrameInfo, useFrameLoop } from "./core/clock.mjs";
|
|
17
|
+
import { Learner, LearnerProvider, LearnerResult, PriorAttempts, useLearner } from "./core/learner.mjs";
|
|
18
|
+
import { RichSpan, Script, parseRichText } from "./core/richText.mjs";
|
|
19
|
+
import { StepProgress, StepProgressProvider, StepScope, StepSpec, StepState, useStepProgress } from "./steps/index.mjs";
|
|
20
|
+
import { Stage, StageProps } from "./view/Stage.mjs";
|
|
21
|
+
import { Size, useElementSize } from "./view/useElementSize.mjs";
|
|
22
|
+
import { useInView } from "./view/useInView.mjs";
|
|
23
|
+
import { A11yProps, StyleProps } from "./primitives/props.mjs";
|
|
24
|
+
import { Dot, DotProps, Point } from "./primitives/Dot.mjs";
|
|
25
|
+
import { Line, LineProps, Ray, Segment, SegmentProps, Vector, VectorProps } from "./primitives/Lines.mjs";
|
|
26
|
+
import { Circle, CircleProps, Ellipse, EllipseProps, Path, PathProps, Polygon, PolygonProps, Polyline, PolylineProps } from "./primitives/Shapes.mjs";
|
|
27
|
+
import { Label, LabelProps } from "./primitives/Label.mjs";
|
|
28
|
+
import { Tex, TexProps } from "./primitives/Tex.mjs";
|
|
29
|
+
import { Axes, AxesProps, Grid, GridProps, niceStep } from "./primitives/Grid.mjs";
|
|
30
|
+
import { OfXProps, OfYProps, ParametricProps, Plot } from "./primitives/Plot.mjs";
|
|
31
|
+
import { CanvasLayer, CanvasLayerProps } from "./primitives/CanvasLayer.mjs";
|
|
32
|
+
import { useScreenToMath } from "./interaction/useScreenToMath.mjs";
|
|
33
|
+
import { AriaSliderProps, Constrain, DraggableHandlers, UseDraggable, UseDraggableArgs, useDraggable } from "./interaction/useDraggable.mjs";
|
|
34
|
+
import { MovableDot, MovableDotProps } from "./interaction/MovableDot.mjs";
|
|
35
|
+
import { HitCandidate, hitTest } from "./interaction/hitTest.mjs";
|
|
36
|
+
import { OP_REFS, isRef, parentIds } from "./scene/schema.mjs";
|
|
37
|
+
import { EVALUATORS, EvalCtx } from "./scene/evaluators.mjs";
|
|
38
|
+
import { CURRENT_SCHEMA_VERSION, emptyDoc, migrate, parse, serialize } from "./scene/migrate.mjs";
|
|
39
|
+
import { InstanceState, SceneStore } from "./scene/store.mjs";
|
|
40
|
+
import { Scene, SceneProps } from "./scene/Scene.mjs";
|
|
41
|
+
import { RenderOpts, renderElements } from "./scene/render.mjs";
|
|
42
|
+
import { BinOp, Node, compileNode, evaluate, freeVars } from "./math/ast.mjs";
|
|
43
|
+
import { parse as parse$1 } from "./math/parse.mjs";
|
|
44
|
+
import { differentiate, simplify } from "./math/calculus.mjs";
|
|
45
|
+
import { toLatex as toLatex$1 } from "./math/latex.mjs";
|
|
46
|
+
import { CompiledExpr, ExprError, ExprResult, compileExpr } from "./math/index.mjs";
|
|
47
|
+
import { BinOp as BinOp$1, LNode, evalBool, freeVars as freeVars$1 } from "./logic/ast.mjs";
|
|
48
|
+
import { parseLogic } from "./logic/parse.mjs";
|
|
49
|
+
import { Classification, TruthRow, TruthTable, classify, equivalent, toCNF, toDNF, truthTable } from "./logic/table.mjs";
|
|
50
|
+
import { toLatex } from "./logic/latex.mjs";
|
|
51
|
+
import { Cube, Minimization, cubeCovers, cubeOfSelection, cubeTerm, minimalCover, minimize, primeImplicants } from "./logic/minimize.mjs";
|
|
52
|
+
import { CompiledLogic, LogicResult, compileLogic } from "./logic/index.mjs";
|
|
53
|
+
import { AssetResolveArgs, AssetSpec, assetMeta, getAsset, listAssets, registerAsset } from "./scene/assets.mjs";
|
|
54
|
+
export { type A11yProps, AUTHORING_TOOLS, type AriaSliderProps, type AssetGeometry, type AssetResolveArgs, type AssetSpec, Axes, type AxesProps, type BinOp, type Binding, BucketGlyph, CIRCLE, CURRENT_SCHEMA_VERSION, CanvasLayer, type CanvasLayerProps, Circle, type CircleProps, type CircleVal, type Classification, ClockProvider, type ClockProviderProps, type Command, type CommandResult, type CompiledExpr, type CompiledLogic, type Constrain, type ControlMap, type ControlPick, type ControlSpec, type ControlSurface, type CoordinateSystem, CoordsContext, type CoordsOptions, type Cube, DELETE, type DerivedDef, type DerivedElement, type DerivedKind, type DispatchOpts, Dot, type DotProps, DragOverlayContext, type DraggableHandlers, EVALUATORS, Editor, type ElementBase, type ElementStyle, Ellipse, type EllipseProps, type EvalCtx, type ExprError, type ExprResult, type FrameDriver, type FrameInfo, type FreeElement, type FreeNote, type FreePoint, type FreeScalar, GEOMETRY_TOOLS, type GlyphBox, Grid, type GridProps, HangerHook, type HangerHookProps, type HitCandidate, INTERSECT, type IconName, type Id, type InstanceState, LINE, type LNode, type LabMeta, Label, type LabelProps, type Learner, LearnerProvider, type LearnerResult, Line, type LineProps, type BinOp$1 as LogicBinOp, type LogicResult, MEASURE, MIDPOINT, type Matrix, type Minimization, MovableDot, type MovableDotProps, type MutatePatch, NOTE, type Node, type NumOrRef, OP_REFS, type OfXProps, type OfYProps, type Op, POINT, Palette, type PaletteProps, type ParametricProps, Path, type PathProps, Plot, Point, Polygon, type PolygonProps, Polyline, type PolylineProps, type PriorAttempts, Ray, type Ref, type RenderOpts, type Resolved, type RichSpan, SCALAR, SEGMENT, SELECT, Scene, SceneBuilder, type SceneBuilderProps, type SceneDoc, type SceneElement, type SceneMeta, type SceneProps, SceneStore, type Vec2 as SceneVec2, type Script, Segment, type SegmentProps, type ShapeLineVal, type Size, Stage, StageAssetDefs, type StageProps, StageRefContext, type StepProgress, StepProgressProvider, StepScope, type StepSpec, type StepState, type StyleProps, Tex, type TexProps, type Tool, type ToolCtx, ToolIcon, type TruthRow, type TruthTable, type UseDraggable, type UseDraggableArgs, type Val, type Vec2, Vector, type VectorProps, type ViewBox, WeightGlyph, XBlockGlyph, applyCommand, assetMeta, classify, collectRemoved, compileExpr, compileLogic, compileNode, controlsFromScene, createCoords, cubeCovers, cubeOfSelection, cubeTerm, differentiate, emptyDoc, equivalent, evalBool, evaluate, fmt, freeVars, getAsset, getControlSurface, hitTest, inverse, isAssetGeom, isCircleVal, isDerived, isFree, isLineVal, isRef, isVec2, listAssets, listControlSurfaces, freeVars$1 as logicFreeVars, toLatex as logicToLatex, mat, migrate, minimalCover, minimize, niceStep, numOf, onControlChange, parentIds, parse, parse$1 as parseExpr, parseLogic, parseRichText, primeImplicants, registerAsset, renderElements, resolve, serialize, simplify, toCNF, toDNF, toLatex$1 as toLatex, truthTable, useControlSurface, useCoords, useDragOverlay, useDraggable, useEditor, useElementSize, useFrameLoop, useInView, useLearner, useScreenToMath, useStageRef, useStepProgress, vec };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { createCoords, fmt } from "./core/coords.mjs";
|
|
2
|
+
import { parseRichText } from "./core/richText.mjs";
|
|
3
|
+
import { mat, vec } from "./core/vec.mjs";
|
|
4
|
+
import { CoordsContext, DragOverlayContext, StageRefContext, useCoords, useDragOverlay, useStageRef } from "./core/context.mjs";
|
|
5
|
+
import { ClockProvider, useFrameLoop } from "./core/clock.mjs";
|
|
6
|
+
import { getControlSurface, listControlSurfaces, onControlChange, useControlSurface } from "./core/control.mjs";
|
|
7
|
+
import { LearnerProvider, useLearner } from "./core/learner.mjs";
|
|
8
|
+
import { StepProgressProvider, StepScope, useStepProgress } from "./steps/index.mjs";
|
|
9
|
+
import { useElementSize } from "./view/useElementSize.mjs";
|
|
10
|
+
import { Stage } from "./view/Stage.mjs";
|
|
11
|
+
import { useInView } from "./view/useInView.mjs";
|
|
12
|
+
import { Dot, Point } from "./primitives/Dot.mjs";
|
|
13
|
+
import { Line, Ray, Segment, Vector } from "./primitives/Lines.mjs";
|
|
14
|
+
import { Circle, Ellipse, Path, Polygon, Polyline } from "./primitives/Shapes.mjs";
|
|
15
|
+
import { Label } from "./primitives/Label.mjs";
|
|
16
|
+
import { Tex } from "./primitives/Tex.mjs";
|
|
17
|
+
import { Axes, Grid, niceStep } from "./primitives/Grid.mjs";
|
|
18
|
+
import { Plot } from "./primitives/Plot.mjs";
|
|
19
|
+
import { CanvasLayer } from "./primitives/CanvasLayer.mjs";
|
|
20
|
+
import { useScreenToMath } from "./interaction/useScreenToMath.mjs";
|
|
21
|
+
import { useDraggable } from "./interaction/useDraggable.mjs";
|
|
22
|
+
import { MovableDot } from "./interaction/MovableDot.mjs";
|
|
23
|
+
import { hitTest } from "./interaction/hitTest.mjs";
|
|
24
|
+
import { isAssetGeom, isCircleVal, isDerived, isFree, isLineVal, isVec2, numOf } from "./scene/types.mjs";
|
|
25
|
+
import { OP_REFS, isRef, parentIds } from "./scene/schema.mjs";
|
|
26
|
+
import { assetMeta, getAsset, listAssets, registerAsset } from "./scene/assets.mjs";
|
|
27
|
+
import { compileNode, evaluate, freeVars } from "./math/ast.mjs";
|
|
28
|
+
import { parse as parse$1 } from "./math/parse.mjs";
|
|
29
|
+
import { differentiate, simplify } from "./math/calculus.mjs";
|
|
30
|
+
import { toLatex as toLatex$1 } from "./math/latex.mjs";
|
|
31
|
+
import { compileExpr } from "./math/index.mjs";
|
|
32
|
+
import { EVALUATORS } from "./scene/evaluators.mjs";
|
|
33
|
+
import { resolve } from "./scene/resolve.mjs";
|
|
34
|
+
import { applyCommand, collectRemoved, inverse } from "./scene/commands.mjs";
|
|
35
|
+
import { CURRENT_SCHEMA_VERSION, emptyDoc, migrate, parse, serialize } from "./scene/migrate.mjs";
|
|
36
|
+
import { SceneStore } from "./scene/store.mjs";
|
|
37
|
+
import { renderElements } from "./scene/render.mjs";
|
|
38
|
+
import { Scene } from "./scene/Scene.mjs";
|
|
39
|
+
import { Editor, useEditor } from "./builder/editor.mjs";
|
|
40
|
+
import { controlsFromScene } from "./builder/controls.mjs";
|
|
41
|
+
import { ToolIcon } from "./builder/icons.mjs";
|
|
42
|
+
import { Palette } from "./builder/Palette.mjs";
|
|
43
|
+
import { AUTHORING_TOOLS, CIRCLE, DELETE, GEOMETRY_TOOLS, INTERSECT, LINE, MEASURE, MIDPOINT, NOTE, POINT, SCALAR, SEGMENT, SELECT } from "./builder/tools.mjs";
|
|
44
|
+
import { SceneBuilder } from "./builder/SceneBuilder.mjs";
|
|
45
|
+
import { StageAssetDefs } from "./assets/kit/svg-defs.mjs";
|
|
46
|
+
import { BucketGlyph, HangerHook, WeightGlyph, XBlockGlyph } from "./assets/kit/glyphs.mjs";
|
|
47
|
+
import "./assets/kit/index.mjs";
|
|
48
|
+
import { evalBool, freeVars as freeVars$1 } from "./logic/ast.mjs";
|
|
49
|
+
import { parseLogic } from "./logic/parse.mjs";
|
|
50
|
+
import { classify, equivalent, toCNF, toDNF, truthTable } from "./logic/table.mjs";
|
|
51
|
+
import { toLatex } from "./logic/latex.mjs";
|
|
52
|
+
import { cubeCovers, cubeOfSelection, cubeTerm, minimalCover, minimize, primeImplicants } from "./logic/minimize.mjs";
|
|
53
|
+
import { compileLogic } from "./logic/index.mjs";
|
|
54
|
+
|
|
55
|
+
export { AUTHORING_TOOLS, Axes, BucketGlyph, CIRCLE, CURRENT_SCHEMA_VERSION, CanvasLayer, Circle, ClockProvider, CoordsContext, DELETE, Dot, DragOverlayContext, EVALUATORS, Editor, Ellipse, GEOMETRY_TOOLS, Grid, HangerHook, INTERSECT, LINE, Label, LearnerProvider, Line, MEASURE, MIDPOINT, MovableDot, NOTE, OP_REFS, POINT, Palette, Path, Plot, Point, Polygon, Polyline, Ray, SCALAR, SEGMENT, SELECT, Scene, SceneBuilder, SceneStore, Segment, Stage, StageAssetDefs, StageRefContext, StepProgressProvider, StepScope, Tex, ToolIcon, Vector, WeightGlyph, XBlockGlyph, applyCommand, assetMeta, classify, collectRemoved, compileExpr, compileLogic, compileNode, controlsFromScene, createCoords, cubeCovers, cubeOfSelection, cubeTerm, differentiate, emptyDoc, equivalent, evalBool, evaluate, fmt, freeVars, getAsset, getControlSurface, hitTest, inverse, isAssetGeom, isCircleVal, isDerived, isFree, isLineVal, isRef, isVec2, listAssets, listControlSurfaces, freeVars$1 as logicFreeVars, toLatex as logicToLatex, mat, migrate, minimalCover, minimize, niceStep, numOf, onControlChange, parentIds, parse, parse$1 as parseExpr, parseLogic, parseRichText, primeImplicants, registerAsset, renderElements, resolve, serialize, simplify, toCNF, toDNF, toLatex$1 as toLatex, truthTable, useControlSurface, useCoords, useDragOverlay, useDraggable, useEditor, useElementSize, useFrameLoop, useInView, useLearner, useScreenToMath, useStageRef, useStepProgress, vec };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Vec2 } from "../core/vec.mjs";
|
|
2
|
+
import { Constrain } from "./useDraggable.mjs";
|
|
3
|
+
import { ReactNode } from "react";
|
|
4
|
+
|
|
5
|
+
//#region src/interaction/MovableDot.d.ts
|
|
6
|
+
interface MovableDotProps {
|
|
7
|
+
value: Vec2;
|
|
8
|
+
onMove: (p: Vec2, phase: 'move' | 'commit') => void;
|
|
9
|
+
constrain?: Constrain;
|
|
10
|
+
color?: string;
|
|
11
|
+
r?: number;
|
|
12
|
+
ariaLabel?: string;
|
|
13
|
+
/** Active-axis bounds → aria-valuemin/max for a proper slider. */
|
|
14
|
+
range?: {
|
|
15
|
+
min: number;
|
|
16
|
+
max: number;
|
|
17
|
+
};
|
|
18
|
+
/** Keyboard arrow-key nudge in math units. Match the lab's snap grid so a
|
|
19
|
+
* single arrow press actually moves (e.g. 1 for an integer number line). */
|
|
20
|
+
step?: number;
|
|
21
|
+
}
|
|
22
|
+
declare function MovableDot({
|
|
23
|
+
value,
|
|
24
|
+
onMove,
|
|
25
|
+
constrain,
|
|
26
|
+
color,
|
|
27
|
+
r,
|
|
28
|
+
ariaLabel,
|
|
29
|
+
range,
|
|
30
|
+
step
|
|
31
|
+
}: MovableDotProps): ReactNode;
|
|
32
|
+
//#endregion
|
|
33
|
+
export { MovableDot, MovableDotProps };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useCoords } from "../core/context.mjs";
|
|
4
|
+
import { useDraggable } from "./useDraggable.mjs";
|
|
5
|
+
import { useState } from "react";
|
|
6
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
|
|
8
|
+
//#region src/interaction/MovableDot.tsx
|
|
9
|
+
function MovableDot({ value, onMove, constrain, color = "var(--stage-accent)", r = 7, ariaLabel = "draggable point", range, step }) {
|
|
10
|
+
const [px, py] = useCoords().toPx(value.x, value.y);
|
|
11
|
+
const { dragging, handlers, ariaProps } = useDraggable({
|
|
12
|
+
value,
|
|
13
|
+
onMove,
|
|
14
|
+
constrain,
|
|
15
|
+
range,
|
|
16
|
+
...step !== void 0 ? { step } : {}
|
|
17
|
+
});
|
|
18
|
+
const [hovered, setHovered] = useState(false);
|
|
19
|
+
const lift = hovered && !dragging;
|
|
20
|
+
const dotR = lift ? r + 1.5 : r;
|
|
21
|
+
return /* @__PURE__ */ jsxs("g", {
|
|
22
|
+
...handlers,
|
|
23
|
+
...ariaProps,
|
|
24
|
+
"aria-label": ariaLabel,
|
|
25
|
+
onPointerEnter: () => setHovered(true),
|
|
26
|
+
onPointerLeave: () => setHovered(false),
|
|
27
|
+
style: {
|
|
28
|
+
cursor: dragging ? "grabbing" : "grab",
|
|
29
|
+
outline: "none"
|
|
30
|
+
},
|
|
31
|
+
children: [
|
|
32
|
+
/* @__PURE__ */ jsx("circle", {
|
|
33
|
+
cx: px,
|
|
34
|
+
cy: py,
|
|
35
|
+
r: Math.max(r + 14, 12),
|
|
36
|
+
fill: "transparent"
|
|
37
|
+
}),
|
|
38
|
+
dragging ? /* @__PURE__ */ jsx("circle", {
|
|
39
|
+
cx: px,
|
|
40
|
+
cy: py,
|
|
41
|
+
r: r + 6,
|
|
42
|
+
fill: color,
|
|
43
|
+
opacity: .2
|
|
44
|
+
}) : /* @__PURE__ */ jsx("circle", {
|
|
45
|
+
cx: px,
|
|
46
|
+
cy: py,
|
|
47
|
+
r: r + 5,
|
|
48
|
+
fill: "none",
|
|
49
|
+
stroke: color,
|
|
50
|
+
strokeWidth: 1.5,
|
|
51
|
+
opacity: lift ? .55 : .28
|
|
52
|
+
}),
|
|
53
|
+
/* @__PURE__ */ jsx("circle", {
|
|
54
|
+
cx: px,
|
|
55
|
+
cy: py,
|
|
56
|
+
r: dotR,
|
|
57
|
+
fill: color,
|
|
58
|
+
stroke: "var(--stage-bg)",
|
|
59
|
+
strokeWidth: 2
|
|
60
|
+
})
|
|
61
|
+
]
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
//#endregion
|
|
66
|
+
export { MovableDot };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Vec2 } from "../core/vec.mjs";
|
|
2
|
+
import { CoordinateSystem } from "../core/coords.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/interaction/hitTest.d.ts
|
|
5
|
+
interface HitCandidate {
|
|
6
|
+
id: string;
|
|
7
|
+
kind: 'point' | 'circle' | 'line' | 'segment';
|
|
8
|
+
point?: Vec2;
|
|
9
|
+
center?: Vec2;
|
|
10
|
+
r?: number;
|
|
11
|
+
a?: Vec2;
|
|
12
|
+
b?: Vec2;
|
|
13
|
+
}
|
|
14
|
+
declare function hitTest(c: CoordinateSystem, math: Vec2, candidates: HitCandidate[], pxTol?: number): string | null;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { HitCandidate, hitTest };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
//#region src/interaction/hitTest.ts
|
|
2
|
+
function distToSeg(p, a, b, infinite) {
|
|
3
|
+
const dx = b[0] - a[0];
|
|
4
|
+
const dy = b[1] - a[1];
|
|
5
|
+
const l2 = dx * dx + dy * dy || 1;
|
|
6
|
+
let t = ((p[0] - a[0]) * dx + (p[1] - a[1]) * dy) / l2;
|
|
7
|
+
if (!infinite) t = Math.max(0, Math.min(1, t));
|
|
8
|
+
return Math.hypot(p[0] - (a[0] + t * dx), p[1] - (a[1] + t * dy));
|
|
9
|
+
}
|
|
10
|
+
function hitTest(c, math, candidates, pxTol = 12) {
|
|
11
|
+
const m = c.toPx(math.x, math.y);
|
|
12
|
+
let best = null;
|
|
13
|
+
let bestD = pxTol;
|
|
14
|
+
for (const cand of candidates) {
|
|
15
|
+
if (cand.kind !== "point" || !cand.point) continue;
|
|
16
|
+
const p = c.toPx(cand.point.x, cand.point.y);
|
|
17
|
+
const d = Math.hypot(m[0] - p[0], m[1] - p[1]);
|
|
18
|
+
if (d < bestD) {
|
|
19
|
+
bestD = d;
|
|
20
|
+
best = cand.id;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (best) return best;
|
|
24
|
+
for (const cand of candidates) {
|
|
25
|
+
let d = Infinity;
|
|
26
|
+
if (cand.kind === "circle" && cand.center && cand.r != null) {
|
|
27
|
+
const ctr = c.toPx(cand.center.x, cand.center.y);
|
|
28
|
+
d = Math.abs(Math.hypot(m[0] - ctr[0], m[1] - ctr[1]) - c.sx(cand.r));
|
|
29
|
+
} else if ((cand.kind === "line" || cand.kind === "segment") && cand.a && cand.b) d = distToSeg(m, c.toPx(cand.a.x, cand.a.y), c.toPx(cand.b.x, cand.b.y), cand.kind === "line");
|
|
30
|
+
if (d < bestD) {
|
|
31
|
+
bestD = d;
|
|
32
|
+
best = cand.id;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return best;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
export { hitTest };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { useScreenToMath } from "./useScreenToMath.mjs";
|
|
2
|
+
import { AriaSliderProps, Constrain, DraggableHandlers, UseDraggable, UseDraggableArgs, useDraggable } from "./useDraggable.mjs";
|
|
3
|
+
import { MovableDot, MovableDotProps } from "./MovableDot.mjs";
|
|
4
|
+
import { HitCandidate, hitTest } from "./hitTest.mjs";
|
|
5
|
+
export { type AriaSliderProps, type Constrain, type DraggableHandlers, type HitCandidate, MovableDot, type MovableDotProps, type UseDraggable, type UseDraggableArgs, hitTest, useDraggable, useScreenToMath };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Vec2 } from "../core/vec.mjs";
|
|
2
|
+
import { KeyboardEvent, PointerEvent } from "react";
|
|
3
|
+
|
|
4
|
+
//#region src/interaction/useDraggable.d.ts
|
|
5
|
+
type Constrain = 'horizontal' | 'vertical' | ((p: Vec2) => Vec2);
|
|
6
|
+
interface UseDraggableArgs {
|
|
7
|
+
value: Vec2;
|
|
8
|
+
/** 'move' fires per pointer frame (ephemeral); 'commit' fires on pointer-up / key. */
|
|
9
|
+
onMove: (p: Vec2, phase: 'move' | 'commit') => void;
|
|
10
|
+
constrain?: Constrain;
|
|
11
|
+
/** Keyboard nudge step in math units. */
|
|
12
|
+
step?: number;
|
|
13
|
+
/** Bounds on the active axis — drives aria-valuemin/max for a proper slider
|
|
14
|
+
* (WAI-ARIA APG). Omit for an unbounded 2D point (valuetext still describes it). */
|
|
15
|
+
range?: {
|
|
16
|
+
min: number;
|
|
17
|
+
max: number;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/** WAI-ARIA slider semantics for the handle. For a constrained (1D) drag this is
|
|
21
|
+
* a real slider (valuenow/min/max on the active axis); for a free 2D point the
|
|
22
|
+
* valuetext conveys the "x, y" position a screen reader announces. */
|
|
23
|
+
interface AriaSliderProps {
|
|
24
|
+
role: 'slider';
|
|
25
|
+
tabIndex: 0;
|
|
26
|
+
'aria-orientation': 'horizontal' | 'vertical';
|
|
27
|
+
'aria-valuenow': number;
|
|
28
|
+
'aria-valuetext': string;
|
|
29
|
+
'aria-valuemin'?: number;
|
|
30
|
+
'aria-valuemax'?: number;
|
|
31
|
+
}
|
|
32
|
+
interface DraggableHandlers {
|
|
33
|
+
onPointerDown: (e: PointerEvent) => void;
|
|
34
|
+
onPointerMove: (e: PointerEvent) => void;
|
|
35
|
+
onPointerUp: (e: PointerEvent) => void;
|
|
36
|
+
onKeyDown: (e: KeyboardEvent) => void;
|
|
37
|
+
}
|
|
38
|
+
interface UseDraggable {
|
|
39
|
+
dragging: boolean;
|
|
40
|
+
handlers: DraggableHandlers;
|
|
41
|
+
ariaProps: AriaSliderProps;
|
|
42
|
+
}
|
|
43
|
+
declare function useDraggable({
|
|
44
|
+
value,
|
|
45
|
+
onMove,
|
|
46
|
+
constrain,
|
|
47
|
+
step,
|
|
48
|
+
range
|
|
49
|
+
}: UseDraggableArgs): UseDraggable;
|
|
50
|
+
//#endregion
|
|
51
|
+
export { AriaSliderProps, Constrain, DraggableHandlers, UseDraggable, UseDraggableArgs, useDraggable };
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useScreenToMath } from "./useScreenToMath.mjs";
|
|
4
|
+
import { useCallback, useRef, useState } from "react";
|
|
5
|
+
|
|
6
|
+
//#region src/interaction/useDraggable.ts
|
|
7
|
+
function constrained(p, start, constrain) {
|
|
8
|
+
if (!constrain) return p;
|
|
9
|
+
if (constrain === "horizontal") return {
|
|
10
|
+
x: p.x,
|
|
11
|
+
y: start.y
|
|
12
|
+
};
|
|
13
|
+
if (constrain === "vertical") return {
|
|
14
|
+
x: start.x,
|
|
15
|
+
y: p.y
|
|
16
|
+
};
|
|
17
|
+
return constrain(p);
|
|
18
|
+
}
|
|
19
|
+
function useDraggable({ value, onMove, constrain, step = .5, range }) {
|
|
20
|
+
const toMath = useScreenToMath();
|
|
21
|
+
const [dragging, setDragging] = useState(false);
|
|
22
|
+
const startRef = useRef(value);
|
|
23
|
+
const onPointerDown = useCallback((e) => {
|
|
24
|
+
e.currentTarget.setPointerCapture(e.pointerId);
|
|
25
|
+
startRef.current = value;
|
|
26
|
+
setDragging(true);
|
|
27
|
+
e.stopPropagation();
|
|
28
|
+
}, [value]);
|
|
29
|
+
const onPointerMove = useCallback((e) => {
|
|
30
|
+
if (!dragging) return;
|
|
31
|
+
const m = toMath(e);
|
|
32
|
+
if (!m) return;
|
|
33
|
+
onMove(constrained({
|
|
34
|
+
x: m[0],
|
|
35
|
+
y: m[1]
|
|
36
|
+
}, startRef.current, constrain), "move");
|
|
37
|
+
}, [
|
|
38
|
+
dragging,
|
|
39
|
+
toMath,
|
|
40
|
+
constrain,
|
|
41
|
+
onMove
|
|
42
|
+
]);
|
|
43
|
+
const onPointerUp = useCallback((e) => {
|
|
44
|
+
if (!dragging) return;
|
|
45
|
+
setDragging(false);
|
|
46
|
+
const m = toMath(e);
|
|
47
|
+
onMove(m ? constrained({
|
|
48
|
+
x: m[0],
|
|
49
|
+
y: m[1]
|
|
50
|
+
}, startRef.current, constrain) : value, "commit");
|
|
51
|
+
}, [
|
|
52
|
+
dragging,
|
|
53
|
+
toMath,
|
|
54
|
+
constrain,
|
|
55
|
+
onMove,
|
|
56
|
+
value
|
|
57
|
+
]);
|
|
58
|
+
const onKeyDown = useCallback((e) => {
|
|
59
|
+
const d = step * (e.shiftKey ? 5 : 1) * (e.altKey ? .25 : 1);
|
|
60
|
+
let np = null;
|
|
61
|
+
if (e.key === "ArrowLeft") np = {
|
|
62
|
+
x: value.x - d,
|
|
63
|
+
y: value.y
|
|
64
|
+
};
|
|
65
|
+
else if (e.key === "ArrowRight") np = {
|
|
66
|
+
x: value.x + d,
|
|
67
|
+
y: value.y
|
|
68
|
+
};
|
|
69
|
+
else if (e.key === "ArrowUp") np = {
|
|
70
|
+
x: value.x,
|
|
71
|
+
y: value.y + d
|
|
72
|
+
};
|
|
73
|
+
else if (e.key === "ArrowDown") np = {
|
|
74
|
+
x: value.x,
|
|
75
|
+
y: value.y - d
|
|
76
|
+
};
|
|
77
|
+
if (np) {
|
|
78
|
+
e.preventDefault();
|
|
79
|
+
const p = constrained(np, value, constrain);
|
|
80
|
+
onMove(p, "move");
|
|
81
|
+
onMove(p, "commit");
|
|
82
|
+
}
|
|
83
|
+
}, [
|
|
84
|
+
value,
|
|
85
|
+
step,
|
|
86
|
+
constrain,
|
|
87
|
+
onMove
|
|
88
|
+
]);
|
|
89
|
+
const oneD = constrain === "horizontal" || constrain === "vertical";
|
|
90
|
+
const vertical = constrain === "vertical";
|
|
91
|
+
const now = vertical ? value.y : value.x;
|
|
92
|
+
const ariaProps = {
|
|
93
|
+
role: "slider",
|
|
94
|
+
tabIndex: 0,
|
|
95
|
+
"aria-orientation": vertical ? "vertical" : "horizontal",
|
|
96
|
+
"aria-valuenow": Number(now.toFixed(4)),
|
|
97
|
+
"aria-valuetext": oneD ? now.toFixed(2) : `x ${value.x.toFixed(2)}, y ${value.y.toFixed(2)}`,
|
|
98
|
+
...range ? {
|
|
99
|
+
"aria-valuemin": range.min,
|
|
100
|
+
"aria-valuemax": range.max
|
|
101
|
+
} : {}
|
|
102
|
+
};
|
|
103
|
+
return {
|
|
104
|
+
dragging,
|
|
105
|
+
handlers: {
|
|
106
|
+
onPointerDown,
|
|
107
|
+
onPointerMove,
|
|
108
|
+
onPointerUp,
|
|
109
|
+
onKeyDown
|
|
110
|
+
},
|
|
111
|
+
ariaProps
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
//#endregion
|
|
116
|
+
export { useDraggable };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/interaction/useScreenToMath.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Returns a fn mapping a pointer/client position to math coordinates via the
|
|
4
|
+
* SVG's getScreenCTM() (handles scroll, CSS scaling, zoom). Null-guarded for
|
|
5
|
+
* SSR / pre-layout. Render and pick always agree because both use one space.
|
|
6
|
+
*/
|
|
7
|
+
declare function useScreenToMath(): (e: {
|
|
8
|
+
clientX: number;
|
|
9
|
+
clientY: number;
|
|
10
|
+
}) => [number, number] | null;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { useScreenToMath };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useCoords, useStageRef } from "../core/context.mjs";
|
|
4
|
+
import { useCallback } from "react";
|
|
5
|
+
|
|
6
|
+
//#region src/interaction/useScreenToMath.ts
|
|
7
|
+
/**
|
|
8
|
+
* Returns a fn mapping a pointer/client position to math coordinates via the
|
|
9
|
+
* SVG's getScreenCTM() (handles scroll, CSS scaling, zoom). Null-guarded for
|
|
10
|
+
* SSR / pre-layout. Render and pick always agree because both use one space.
|
|
11
|
+
*/
|
|
12
|
+
function useScreenToMath() {
|
|
13
|
+
const coords = useCoords();
|
|
14
|
+
const ref = useStageRef();
|
|
15
|
+
return useCallback((e) => {
|
|
16
|
+
const svg = ref?.current;
|
|
17
|
+
const ctm = svg?.getScreenCTM();
|
|
18
|
+
if (!svg || !ctm) return null;
|
|
19
|
+
const pt = new DOMPoint(e.clientX, e.clientY).matrixTransform(ctm.inverse());
|
|
20
|
+
return coords.toMath(pt.x, pt.y);
|
|
21
|
+
}, [coords, ref]);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
export { useScreenToMath };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
//#region src/logic/ast.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Propositional-logic AST — the boolean-domain sibling of the `expr` engine's
|
|
4
|
+
* numeric AST. A formula is variables joined by ¬ ∧ ∨ ⊕ → ↔. Pure + zero-dep;
|
|
5
|
+
* `evalBool` is the single evaluator every consumer (truth tables, equivalence,
|
|
6
|
+
* boolean circuits) runs.
|
|
7
|
+
*/
|
|
8
|
+
type BinOp = 'and' | 'or' | 'xor' | 'implies' | 'iff';
|
|
9
|
+
type LNode = {
|
|
10
|
+
kind: 'var';
|
|
11
|
+
name: string;
|
|
12
|
+
} | {
|
|
13
|
+
kind: 'const';
|
|
14
|
+
value: boolean;
|
|
15
|
+
} | {
|
|
16
|
+
kind: 'not';
|
|
17
|
+
a: LNode;
|
|
18
|
+
} | {
|
|
19
|
+
kind: 'bin';
|
|
20
|
+
op: BinOp;
|
|
21
|
+
a: LNode;
|
|
22
|
+
b: LNode;
|
|
23
|
+
};
|
|
24
|
+
/** Evaluate a formula under a truth assignment. Unknown vars → false. */
|
|
25
|
+
declare function evalBool(n: LNode, env: Record<string, boolean>): boolean;
|
|
26
|
+
/** Distinct variable names in a formula, sorted (stable column order). */
|
|
27
|
+
declare function freeVars(n: LNode): string[];
|
|
28
|
+
//#endregion
|
|
29
|
+
export { BinOp, LNode, evalBool, freeVars };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
//#region src/logic/ast.ts
|
|
2
|
+
/** Evaluate a formula under a truth assignment. Unknown vars → false. */
|
|
3
|
+
function evalBool(n, env) {
|
|
4
|
+
switch (n.kind) {
|
|
5
|
+
case "var": return env[n.name] === true;
|
|
6
|
+
case "const": return n.value;
|
|
7
|
+
case "not": return !evalBool(n.a, env);
|
|
8
|
+
case "bin": {
|
|
9
|
+
const a = evalBool(n.a, env);
|
|
10
|
+
const b = () => evalBool(n.b, env);
|
|
11
|
+
switch (n.op) {
|
|
12
|
+
case "and": return a && b();
|
|
13
|
+
case "or": return a || b();
|
|
14
|
+
case "xor": return a !== b();
|
|
15
|
+
case "implies": return !a || b();
|
|
16
|
+
case "iff": return a === b();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/** Distinct variable names in a formula, sorted (stable column order). */
|
|
22
|
+
function freeVars(n) {
|
|
23
|
+
const out = /* @__PURE__ */ new Set();
|
|
24
|
+
const walk = (x) => {
|
|
25
|
+
if (x.kind === "var") out.add(x.name);
|
|
26
|
+
else if (x.kind === "not") walk(x.a);
|
|
27
|
+
else if (x.kind === "bin") {
|
|
28
|
+
walk(x.a);
|
|
29
|
+
walk(x.b);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
walk(n);
|
|
33
|
+
return [...out].sort();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
export { evalBool, freeVars };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { BinOp, LNode, evalBool, freeVars } from "./ast.mjs";
|
|
2
|
+
import { parseLogic } from "./parse.mjs";
|
|
3
|
+
import { Classification, TruthRow, TruthTable, classify, equivalent, toCNF, toDNF, truthTable } from "./table.mjs";
|
|
4
|
+
import { toLatex } from "./latex.mjs";
|
|
5
|
+
import { Cube, Minimization, cubeCovers, cubeOfSelection, cubeTerm, minimalCover, minimize, primeImplicants } from "./minimize.mjs";
|
|
6
|
+
|
|
7
|
+
//#region src/logic/index.d.ts
|
|
8
|
+
interface CompiledLogic {
|
|
9
|
+
ast: LNode;
|
|
10
|
+
/** Variables in stable (sorted) order. */
|
|
11
|
+
vars: string[];
|
|
12
|
+
/** Evaluate under a truth assignment. */
|
|
13
|
+
eval: (env: Record<string, boolean>) => boolean;
|
|
14
|
+
}
|
|
15
|
+
type LogicResult = (CompiledLogic & {
|
|
16
|
+
ok: true;
|
|
17
|
+
}) | {
|
|
18
|
+
ok: false;
|
|
19
|
+
error: string;
|
|
20
|
+
};
|
|
21
|
+
/** Parse + ready a formula, returning a typed error instead of throwing (so a
|
|
22
|
+
* lab/agent can surface bad input without a broken scene). */
|
|
23
|
+
declare function compileLogic(src: string): LogicResult;
|
|
24
|
+
//#endregion
|
|
25
|
+
export { type BinOp, type Classification, CompiledLogic, type Cube, type LNode, LogicResult, type Minimization, type TruthRow, type TruthTable, classify, compileLogic, cubeCovers, cubeOfSelection, cubeTerm, equivalent, evalBool, freeVars, minimalCover, minimize, parseLogic, primeImplicants, toCNF, toDNF, toLatex, truthTable };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { evalBool, freeVars } from "./ast.mjs";
|
|
2
|
+
import { parseLogic } from "./parse.mjs";
|
|
3
|
+
import { classify, equivalent, toCNF, toDNF, truthTable } from "./table.mjs";
|
|
4
|
+
import { toLatex } from "./latex.mjs";
|
|
5
|
+
import { cubeCovers, cubeOfSelection, cubeTerm, minimalCover, minimize, primeImplicants } from "./minimize.mjs";
|
|
6
|
+
|
|
7
|
+
//#region src/logic/index.ts
|
|
8
|
+
/**
|
|
9
|
+
* @classytic/stage logic kernel — a pure, dependency-free propositional-logic
|
|
10
|
+
* engine, the boolean-domain sibling of the `expr` (numeric) engine. Parses
|
|
11
|
+
* ¬ ∧ ∨ ⊕ → ↔ (unicode or ASCII), evaluates, builds truth tables, classifies
|
|
12
|
+
* tautology/contradiction/contingency, checks equivalence, and emits DNF/CNF +
|
|
13
|
+
* LaTeX. Reused by the discrete-math labs (truth tables, boolean circuits,
|
|
14
|
+
* Karnaugh maps) AND ICT boolean lessons. Mirrors `compileExpr`'s shape.
|
|
15
|
+
*/
|
|
16
|
+
/** Parse + ready a formula, returning a typed error instead of throwing (so a
|
|
17
|
+
* lab/agent can surface bad input without a broken scene). */
|
|
18
|
+
function compileLogic(src) {
|
|
19
|
+
try {
|
|
20
|
+
const ast = parseLogic(src);
|
|
21
|
+
return {
|
|
22
|
+
ok: true,
|
|
23
|
+
ast,
|
|
24
|
+
vars: freeVars(ast),
|
|
25
|
+
eval: (env) => evalBool(ast, env)
|
|
26
|
+
};
|
|
27
|
+
} catch (e) {
|
|
28
|
+
return {
|
|
29
|
+
ok: false,
|
|
30
|
+
error: e instanceof Error ? e.message : String(e)
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
//#endregion
|
|
36
|
+
export { classify, compileLogic, cubeCovers, cubeOfSelection, cubeTerm, equivalent, evalBool, freeVars, minimalCover, minimize, parseLogic, primeImplicants, toCNF, toDNF, toLatex, truthTable };
|