@hyperfixi/behaviors 3.2.0 → 4.0.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/CHANGELOG.md +203 -1
- package/README.md +29 -9
- package/dist/all.browser.global.js +47 -102
- package/dist/all.browser.global.js.map +1 -1
- package/dist/autodismiss.browser.global.js +5 -11
- package/dist/autodismiss.browser.global.js.map +1 -1
- package/dist/behaviors/autodismiss.cjs +19 -22
- package/dist/behaviors/autodismiss.cjs.map +1 -1
- package/dist/behaviors/autodismiss.d.cts +4 -4
- package/dist/behaviors/autodismiss.d.ts +4 -4
- package/dist/behaviors/autodismiss.js +3 -3
- package/dist/behaviors/clickoutside.cjs +19 -18
- package/dist/behaviors/clickoutside.cjs.map +1 -1
- package/dist/behaviors/clickoutside.d.cts +4 -4
- package/dist/behaviors/clickoutside.d.ts +4 -4
- package/dist/behaviors/clickoutside.js +3 -3
- package/dist/behaviors/clipboard.cjs +18 -19
- package/dist/behaviors/clipboard.cjs.map +1 -1
- package/dist/behaviors/clipboard.d.cts +4 -4
- package/dist/behaviors/clipboard.d.ts +4 -4
- package/dist/behaviors/clipboard.js +3 -3
- package/dist/behaviors/draggable.cjs +20 -25
- package/dist/behaviors/draggable.cjs.map +1 -1
- package/dist/behaviors/draggable.d.cts +4 -4
- package/dist/behaviors/draggable.d.ts +4 -4
- package/dist/behaviors/draggable.js +3 -3
- package/dist/behaviors/focustrap.cjs +18 -19
- package/dist/behaviors/focustrap.cjs.map +1 -1
- package/dist/behaviors/focustrap.d.cts +4 -4
- package/dist/behaviors/focustrap.d.ts +4 -4
- package/dist/behaviors/focustrap.js +3 -3
- package/dist/behaviors/removable.cjs +18 -21
- package/dist/behaviors/removable.cjs.map +1 -1
- package/dist/behaviors/removable.d.cts +4 -3
- package/dist/behaviors/removable.d.ts +4 -3
- package/dist/behaviors/removable.js +3 -3
- package/dist/behaviors/resizable.cjs +21 -21
- package/dist/behaviors/resizable.cjs.map +1 -1
- package/dist/behaviors/resizable.d.cts +4 -4
- package/dist/behaviors/resizable.d.ts +4 -4
- package/dist/behaviors/resizable.js +3 -3
- package/dist/behaviors/scrollreveal.cjs +19 -22
- package/dist/behaviors/scrollreveal.cjs.map +1 -1
- package/dist/behaviors/scrollreveal.d.cts +4 -4
- package/dist/behaviors/scrollreveal.d.ts +4 -4
- package/dist/behaviors/scrollreveal.js +3 -3
- package/dist/behaviors/sortable.cjs +19 -20
- package/dist/behaviors/sortable.cjs.map +1 -1
- package/dist/behaviors/sortable.d.cts +4 -4
- package/dist/behaviors/sortable.d.ts +4 -4
- package/dist/behaviors/sortable.js +3 -3
- package/dist/behaviors/tabs.cjs +20 -25
- package/dist/behaviors/tabs.cjs.map +1 -1
- package/dist/behaviors/tabs.d.cts +4 -4
- package/dist/behaviors/tabs.d.ts +4 -4
- package/dist/behaviors/tabs.js +3 -3
- package/dist/behaviors/toggleable.cjs +25 -26
- package/dist/behaviors/toggleable.cjs.map +1 -1
- package/dist/behaviors/toggleable.d.cts +4 -4
- package/dist/behaviors/toggleable.d.ts +4 -4
- package/dist/behaviors/toggleable.js +3 -3
- package/dist/chunk-2GIS4DCY.js +30 -0
- package/dist/chunk-2GIS4DCY.js.map +1 -0
- package/dist/chunk-3BCBZR6R.js +30 -0
- package/dist/chunk-3BCBZR6R.js.map +1 -0
- package/dist/chunk-4YUIDZAO.js +30 -0
- package/dist/chunk-4YUIDZAO.js.map +1 -0
- package/dist/{chunk-XYZ7FOXJ.js → chunk-AQCOK5J5.js} +10 -14
- package/dist/chunk-AQCOK5J5.js.map +1 -0
- package/dist/chunk-ATGHQQC7.js +30 -0
- package/dist/chunk-ATGHQQC7.js.map +1 -0
- package/dist/{chunk-HQDYH45I.js → chunk-CWLAXLWR.js} +5 -13
- package/dist/chunk-CWLAXLWR.js.map +1 -0
- package/dist/chunk-DMWN52SV.js +30 -0
- package/dist/chunk-DMWN52SV.js.map +1 -0
- package/dist/{chunk-PDMOOWFW.js → chunk-EIVPVTUI.js} +4 -8
- package/dist/{chunk-PDMOOWFW.js.map → chunk-EIVPVTUI.js.map} +1 -1
- package/dist/chunk-HHTEMPIT.js +30 -0
- package/dist/chunk-HHTEMPIT.js.map +1 -0
- package/dist/{chunk-26IX7QU7.js → chunk-HJESSMKB.js} +4 -6
- package/dist/{chunk-26IX7QU7.js.map → chunk-HJESSMKB.js.map} +1 -1
- package/dist/{chunk-5LFOFVZ3.js → chunk-IFAH652L.js} +6 -9
- package/dist/chunk-IFAH652L.js.map +1 -0
- package/dist/chunk-IUGJG4RA.js +30 -0
- package/dist/chunk-IUGJG4RA.js.map +1 -0
- package/dist/{chunk-6EG2MNC7.js → chunk-JNLVXPHR.js} +13 -13
- package/dist/chunk-KEZEGPEX.js +30 -0
- package/dist/chunk-KEZEGPEX.js.map +1 -0
- package/dist/{chunk-66U2RSYJ.js → chunk-KP4GNXYS.js} +4 -10
- package/dist/chunk-KP4GNXYS.js.map +1 -0
- package/dist/chunk-KXQMCN4O.js +30 -0
- package/dist/chunk-KXQMCN4O.js.map +1 -0
- package/dist/{chunk-YXS27XM6.js → chunk-KYBOZ7C4.js} +3 -7
- package/dist/chunk-KYBOZ7C4.js.map +1 -0
- package/dist/chunk-LBWM6TTU.js +30 -0
- package/dist/chunk-LBWM6TTU.js.map +1 -0
- package/dist/{chunk-3DVDS7CT.js → chunk-LCDONZBX.js} +5 -5
- package/dist/chunk-LCDONZBX.js.map +1 -0
- package/dist/{chunk-OJ3YWO3W.js → chunk-NE76IBV2.js} +3 -7
- package/dist/chunk-NE76IBV2.js.map +1 -0
- package/dist/{chunk-HMU342XE.js → chunk-PVO6TZCZ.js} +3 -9
- package/dist/{chunk-HMU342XE.js.map → chunk-PVO6TZCZ.js.map} +1 -1
- package/dist/{chunk-URZGNPTQ.js → chunk-RILYRQ72.js} +4 -10
- package/dist/chunk-RILYRQ72.js.map +1 -0
- package/dist/{chunk-FBQ3X3UY.js → chunk-U4QMFVAM.js} +5 -13
- package/dist/chunk-U4QMFVAM.js.map +1 -0
- package/dist/chunk-VWDTOSE3.js +26 -0
- package/dist/chunk-VWDTOSE3.js.map +1 -0
- package/dist/chunk-YRQBU2OW.js +30 -0
- package/dist/chunk-YRQBU2OW.js.map +1 -0
- package/dist/clickoutside.browser.global.js +5 -7
- package/dist/clickoutside.browser.global.js.map +1 -1
- package/dist/clipboard.browser.global.js +4 -8
- package/dist/clipboard.browser.global.js.map +1 -1
- package/dist/core.browser.global.js +13 -25
- package/dist/core.browser.global.js.map +1 -1
- package/dist/draggable.browser.global.js +5 -13
- package/dist/draggable.browser.global.js.map +1 -1
- package/dist/focustrap.browser.global.js +4 -8
- package/dist/focustrap.browser.global.js.map +1 -1
- package/dist/index.cjs +98 -273
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -10
- package/dist/index.d.ts +10 -10
- package/dist/index.js +42 -55
- package/dist/index.js.map +1 -1
- package/dist/loaders.cjs +77 -239
- package/dist/loaders.cjs.map +1 -1
- package/dist/loaders.js +13 -13
- package/dist/registry.cjs +4 -4
- package/dist/registry.cjs.map +1 -1
- package/dist/registry.d.cts +5 -6
- package/dist/registry.d.ts +5 -6
- package/dist/registry.js +1 -1
- package/dist/removable.browser.global.js +3 -9
- package/dist/removable.browser.global.js.map +1 -1
- package/dist/resizable.browser.global.js +6 -9
- package/dist/resizable.browser.global.js.map +1 -1
- package/dist/resolver.browser.global.js +47 -102
- package/dist/resolver.browser.global.js.map +1 -1
- package/dist/schemas/index.cjs +40 -95
- package/dist/schemas/index.cjs.map +1 -1
- package/dist/schemas/index.d.cts +2 -2
- package/dist/schemas/index.d.ts +2 -2
- package/dist/schemas/index.js +11 -11
- package/dist/schemas/index.js.map +1 -1
- package/dist/scrollreveal.browser.global.js +5 -11
- package/dist/scrollreveal.browser.global.js.map +1 -1
- package/dist/sortable.browser.global.js +5 -9
- package/dist/sortable.browser.global.js.map +1 -1
- package/dist/tabs.browser.global.js +6 -14
- package/dist/tabs.browser.global.js.map +1 -1
- package/dist/toggleable.browser.global.js +9 -13
- package/dist/toggleable.browser.global.js.map +1 -1
- package/dist/{types-DCCtVQS5.d.cts → types-CbA4L8XJ.d.cts} +16 -23
- package/dist/{types-DCCtVQS5.d.ts → types-CbA4L8XJ.d.ts} +16 -23
- package/package.json +5 -5
- package/src/behavior-resolver.ts +24 -56
- package/src/behaviors/autodismiss.test.ts +12 -20
- package/src/behaviors/autodismiss.ts +8 -23
- package/src/behaviors/clickoutside.test.ts +13 -21
- package/src/behaviors/clickoutside.ts +8 -23
- package/src/behaviors/clipboard.test.ts +12 -34
- package/src/behaviors/clipboard.ts +8 -23
- package/src/behaviors/curated-runtime.test.ts +22 -24
- package/src/behaviors/draggable.ts +10 -24
- package/src/behaviors/experimental-runtime.test.ts +19 -18
- package/src/behaviors/focustrap.test.ts +12 -20
- package/src/behaviors/focustrap.ts +8 -23
- package/src/behaviors/integration.test.ts +19 -54
- package/src/behaviors/optional-runtime.test.ts +17 -22
- package/src/behaviors/removable.ts +6 -20
- package/src/behaviors/resizable.ts +9 -24
- package/src/behaviors/scrollreveal.test.ts +13 -21
- package/src/behaviors/scrollreveal.ts +8 -23
- package/src/behaviors/sortable.ts +7 -22
- package/src/behaviors/tabs.test.ts +12 -34
- package/src/behaviors/tabs.ts +8 -23
- package/src/behaviors/toggleable.ts +10 -26
- package/src/browser-resolver-bundle.ts +20 -30
- package/src/core-bundle.ts +11 -11
- package/src/index.test.ts +2 -2
- package/src/index.ts +30 -47
- package/src/registry.test.ts +9 -34
- package/src/registry.ts +7 -11
- package/src/schemas/autodismiss.schema.ts +3 -9
- package/src/schemas/clickoutside.schema.ts +3 -5
- package/src/schemas/clipboard.schema.ts +2 -6
- package/src/schemas/draggable.schema.ts +4 -12
- package/src/schemas/focustrap.schema.ts +2 -6
- package/src/schemas/index.ts +2 -1
- package/src/schemas/removable.schema.ts +2 -8
- package/src/schemas/resizable.schema.ts +5 -8
- package/src/schemas/scrollreveal.schema.ts +3 -9
- package/src/schemas/sortable.schema.ts +3 -7
- package/src/schemas/tabs.schema.ts +4 -12
- package/src/schemas/toggleable.schema.ts +10 -13
- package/src/schemas/types.ts +37 -30
- package/dist/chunk-2HUF6RMI.js +0 -40
- package/dist/chunk-2HUF6RMI.js.map +0 -1
- package/dist/chunk-3DVDS7CT.js.map +0 -1
- package/dist/chunk-5LFOFVZ3.js.map +0 -1
- package/dist/chunk-66U2RSYJ.js.map +0 -1
- package/dist/chunk-6TJXDCAQ.js +0 -11
- package/dist/chunk-6TJXDCAQ.js.map +0 -1
- package/dist/chunk-7NGOA3T5.js +0 -40
- package/dist/chunk-7NGOA3T5.js.map +0 -1
- package/dist/chunk-7TPDLB7W.js +0 -40
- package/dist/chunk-7TPDLB7W.js.map +0 -1
- package/dist/chunk-CR3J7VV6.js +0 -40
- package/dist/chunk-CR3J7VV6.js.map +0 -1
- package/dist/chunk-EDBG2F57.js +0 -40
- package/dist/chunk-EDBG2F57.js.map +0 -1
- package/dist/chunk-FBQ3X3UY.js.map +0 -1
- package/dist/chunk-HQDYH45I.js.map +0 -1
- package/dist/chunk-HX663BJ4.js +0 -40
- package/dist/chunk-HX663BJ4.js.map +0 -1
- package/dist/chunk-KROW43CG.js +0 -40
- package/dist/chunk-KROW43CG.js.map +0 -1
- package/dist/chunk-L52AGCMP.js +0 -40
- package/dist/chunk-L52AGCMP.js.map +0 -1
- package/dist/chunk-OJ3YWO3W.js.map +0 -1
- package/dist/chunk-ORBJ7MRW.js +0 -40
- package/dist/chunk-ORBJ7MRW.js.map +0 -1
- package/dist/chunk-SLSCZV4A.js +0 -40
- package/dist/chunk-SLSCZV4A.js.map +0 -1
- package/dist/chunk-URZGNPTQ.js.map +0 -1
- package/dist/chunk-WKBRZGGL.js +0 -40
- package/dist/chunk-WKBRZGGL.js.map +0 -1
- package/dist/chunk-XYZ7FOXJ.js.map +0 -1
- package/dist/chunk-YXS27XM6.js.map +0 -1
- /package/dist/{chunk-6EG2MNC7.js.map → chunk-JNLVXPHR.js.map} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/behaviors/autodismiss.ts","../src/schemas/autodismiss.schema.ts","../src/schemas/types.ts"],"sourcesContent":["/**\n * AutoDismiss Behavior\n *\n * Auto-removes elements after a configurable delay.\n * Supports pause-on-hover and fade effect using standard setTimeout/clearTimeout\n * (in its hyperscript `source`'s js() body).\n *\n * Compiled from its hyperscript `source` (the single source of truth shared with\n * the CDN resolver bundle and patterns-reference).\n */\n\nimport { autoDismissSchema } from '../schemas/autodismiss.schema';\nimport type { LokaScriptInstance } from '../schemas/types';\nimport { resolveRuntime } from '../schemas/types';\n\n// Re-export schema-derived values\nexport const autoDismissSource = autoDismissSchema.source;\nexport const autoDismissMetadata = autoDismissSchema;\n\n/**\n * Register the AutoDismiss behavior with LokaScript by compiling its\n * hyperscript source and executing the resulting behavior definition.\n */\nexport async function registerAutoDismiss(hyperfixi?: LokaScriptInstance): Promise<void> {\n const hf = hyperfixi || resolveRuntime();\n\n if (!hf) {\n throw new Error(\n 'LokaScript not found. Make sure @hyperfixi/core is loaded before registering behaviors.'\n );\n }\n\n const result = hf.compileSync(autoDismissSchema.source, { traditional: true });\n\n if (!result.ok) {\n throw new Error(`Failed to compile AutoDismiss behavior: ${JSON.stringify(result.errors)}`);\n }\n\n const ctx = hf.createContext ? hf.createContext() : { locals: new Map(), globals: new Map() };\n await hf.execute(result.ast, ctx);\n}\n\n// Auto-register when loaded as a script tag\nif (resolveRuntime()) {\n registerAutoDismiss().catch(console.error);\n}\n\nexport default {\n source: autoDismissSchema.source,\n metadata: autoDismissSchema,\n register: registerAutoDismiss,\n};\n","import type { BehaviorSchema } from './types';\n\n/**\n * AutoDismiss Behavior Schema\n *\n * Auto-removes flash messages and toasts after a configurable delay.\n * Supports pause-on-hover and fade effect.\n */\nexport const autoDismissSchema: BehaviorSchema = {\n name: 'AutoDismiss',\n category: 'ui',\n tier: 'core',\n version: '1.0.0',\n description: 'Auto-removes elements after a delay with optional pause-on-hover',\n parameters: [\n {\n name: 'delay',\n type: 'number',\n optional: true,\n default: 5000,\n description: 'Time in ms before the element is removed',\n },\n {\n name: 'pauseOnHover',\n type: 'boolean',\n optional: true,\n default: true,\n description: 'Pause the countdown when the mouse hovers over the element',\n },\n {\n name: 'effect',\n type: 'string',\n optional: true,\n default: 'none',\n enum: ['fade', 'none'],\n description: 'Transition effect before removal: \"fade\" or \"none\"',\n },\n ],\n events: [\n { name: 'autodismiss:start', description: 'Fired when the countdown timer starts' },\n {\n name: 'autodismiss:dismissed',\n description: 'Fired before removal (cancelable via preventDefault)',\n },\n { name: 'autodismiss:paused', description: 'Fired when the timer is paused on hover' },\n { name: 'autodismiss:resumed', description: 'Fired when the timer resumes on mouseleave' },\n ],\n source: `\nbehavior AutoDismiss(delay, pauseOnHover, effect)\n init\n if delay is undefined\n set delay to 5000\n end\n if pauseOnHover is undefined\n set pauseOnHover to true\n end\n if effect is undefined\n set effect to \"none\"\n end\n js(me, delay, effect, pauseOnHover)\n me.dispatchEvent(new CustomEvent('autodismiss:start', { bubbles: true }));\n var remaining = delay;\n var startedAt = Date.now();\n var timerId = null;\n function dismiss() {\n var ev = new CustomEvent('autodismiss:dismissed', { bubbles: true, cancelable: true });\n me.dispatchEvent(ev);\n if (ev.defaultPrevented) return;\n if (effect === 'fade') {\n me.style.transition = 'opacity 300ms';\n me.style.opacity = '0';\n setTimeout(function() { me.remove(); }, 300);\n } else {\n me.remove();\n }\n }\n function start() {\n startedAt = Date.now();\n timerId = setTimeout(dismiss, remaining);\n }\n start();\n if (pauseOnHover) {\n me.addEventListener('mouseenter', function() {\n if (timerId != null) {\n clearTimeout(timerId);\n timerId = null;\n remaining -= Date.now() - startedAt;\n if (remaining < 0) remaining = 0;\n me.dispatchEvent(new CustomEvent('autodismiss:paused', { bubbles: true }));\n }\n });\n me.addEventListener('mouseleave', function() {\n if (timerId == null && me.isConnected) {\n me.dispatchEvent(new CustomEvent('autodismiss:resumed', { bubbles: true }));\n start();\n }\n });\n }\n end\n end\nend`.trim(),\n};\n","/**\n * Behavior Schema Types\n *\n * Defines the structure for behavior metadata used for:\n * - Code generation (TypeScript types, documentation)\n * - Runtime categorization and lazy loading\n * - Tooling and IDE integration\n */\n\n/**\n * Behavior categories for organization.\n * - ui: Visual interaction behaviors (drag, resize, sort)\n * - data: Data manipulation behaviors (remove, transform)\n * - animation: Animation and transition behaviors\n * - form: Form-related behaviors (validation, toggle states)\n * - layout: Layout behaviors (sticky, scrollspy)\n */\nexport type BehaviorCategory = 'ui' | 'data' | 'animation' | 'form' | 'layout';\n\n/**\n * Loading tiers for lazy loading optimization.\n * - core: Always loaded (essential behaviors)\n * - common: High usage (loaded for typical apps)\n * - optional: Low usage (loaded on demand)\n */\nexport type BehaviorTier = 'core' | 'common' | 'optional';\n\n/**\n * Schema for a behavior parameter.\n */\nexport interface ParameterSchema {\n name: string;\n type: 'string' | 'number' | 'boolean' | 'selector' | 'element';\n optional?: boolean;\n default?: string | number | boolean;\n /** Allowed values for constrained parameters */\n enum?: string[];\n description: string;\n}\n\n/**\n * Schema for a behavior event.\n */\nexport interface EventSchema {\n name: string;\n description: string;\n}\n\n/**\n * Complete schema for a behavior.\n * This is the source of truth for all behavior metadata.\n */\nexport interface BehaviorSchema {\n /** Behavior name (PascalCase) */\n name: string;\n /** Category for organization */\n category: BehaviorCategory;\n /** Loading tier for lazy loading */\n tier: BehaviorTier;\n /** Semantic version */\n version: string;\n /** Human-readable description */\n description: string;\n /** Parameter definitions */\n parameters: ParameterSchema[];\n /** Event definitions */\n events: EventSchema[];\n /** The hyperscript behavior source code */\n source: string;\n /** Optional requirements or notes */\n requirements?: string[];\n}\n\n/**\n * Runtime behavior module interface.\n * This is what gets registered with the hyperfixi runtime.\n */\nexport interface BehaviorModule {\n source: string;\n metadata: BehaviorSchema;\n register: (hyperfixi?: LokaScriptInstance) => Promise<void>;\n}\n\n/**\n * Minimal LokaScript instance interface for behavior registration.\n */\nexport interface LokaScriptInstance {\n compileSync: (\n code: string,\n options?: { traditional?: boolean; language?: string }\n ) => {\n ok: boolean;\n ast?: unknown;\n errors?: Array<{ message: string; line?: number; column?: number }>;\n };\n execute: (ast: unknown, ctx: unknown) => Promise<unknown>;\n createContext?: () => { locals: Map<string, unknown>; globals: Map<string, unknown> };\n}\n\n/**\n * Typed window interface for behavior auto-registration.\n * Avoids `(window as any)` casts throughout the codebase.\n * Checks both `window.lokascript` and `window.hyperfixi` for the runtime instance.\n */\nexport interface LokaScriptWindow {\n lokascript?: LokaScriptInstance;\n hyperfixi?: LokaScriptInstance;\n __hyperfixi_behaviors_ready?: Promise<void> | undefined;\n}\n\n/**\n * Resolve the LokaScript runtime from window globals.\n * Checks both `window.lokascript` and `window.hyperfixi`.\n */\nexport function resolveRuntime(): LokaScriptInstance | null {\n if (typeof window === 'undefined') return null;\n const win = window as unknown as LokaScriptWindow;\n return win.lokascript || win.hyperfixi || null;\n}\n"],"mappings":"scAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,yBAAAE,EAAA,sBAAAC,EAAA,YAAAC,EAAA,wBAAAC,ICQO,IAAMC,EAAoC,CAC/C,KAAM,cACN,SAAU,KACV,KAAM,OACN,QAAS,QACT,YAAa,mEACb,WAAY,CACV,CACE,KAAM,QACN,KAAM,SACN,SAAU,GACV,QAAS,IACT,YAAa,0CACf,EACA,CACE,KAAM,eACN,KAAM,UACN,SAAU,GACV,QAAS,GACT,YAAa,4DACf,EACA,CACE,KAAM,SACN,KAAM,SACN,SAAU,GACV,QAAS,OACT,KAAM,CAAC,OAAQ,MAAM,EACrB,YAAa,oDACf,CACF,EACA,OAAQ,CACN,CAAE,KAAM,oBAAqB,YAAa,uCAAwC,EAClF,CACE,KAAM,wBACN,YAAa,sDACf,EACA,CAAE,KAAM,qBAAsB,YAAa,yCAA0C,EACrF,CAAE,KAAM,sBAAuB,YAAa,4CAA6C,CAC3F,EACA,OAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,KAqDL,KAAK,CACV,ECaO,SAASC,GAA4C,CAC1D,GAAI,OAAO,OAAW,IAAa,OAAO,KAC1C,IAAMC,EAAM,OACZ,OAAOA,EAAI,YAAcA,EAAI,WAAa,IAC5C,CFtGO,IAAMC,EAAoBC,EAAkB,OACtCC,EAAsBD,EAMnC,eAAsBE,EAAoBC,EAA+C,CACvF,IAAMC,EAAKD,GAAaE,EAAe,EAEvC,GAAI,CAACD,EACH,MAAM,IAAI,MACR,yFACF,EAGF,IAAME,EAASF,EAAG,YAAYJ,EAAkB,OAAQ,CAAE,YAAa,EAAK,CAAC,EAE7E,GAAI,CAACM,EAAO,GACV,MAAM,IAAI,MAAM,2CAA2C,KAAK,UAAUA,EAAO,MAAM,CAAC,EAAE,EAG5F,IAAMC,EAAMH,EAAG,cAAgBA,EAAG,cAAc,EAAI,CAAE,OAAQ,IAAI,IAAO,QAAS,IAAI,GAAM,EAC5F,MAAMA,EAAG,QAAQE,EAAO,IAAKC,CAAG,CAClC,CAGIF,EAAe,GACjBH,EAAoB,EAAE,MAAM,QAAQ,KAAK,EAG3C,IAAOM,EAAQ,CACb,OAAQR,EAAkB,OAC1B,SAAUA,EACV,SAAUE,CACZ","names":["autodismiss_exports","__export","autoDismissMetadata","autoDismissSource","autodismiss_default","registerAutoDismiss","autoDismissSchema","resolveRuntime","win","autoDismissSource","autoDismissSchema","autoDismissMetadata","registerAutoDismiss","hyperfixi","hf","resolveRuntime","result","ctx","autodismiss_default"]}
|
|
1
|
+
{"version":3,"sources":["../src/behaviors/autodismiss.ts","../src/schemas/autodismiss.schema.ts","../src/schemas/types.ts"],"sourcesContent":["/**\n * AutoDismiss Behavior\n *\n * Auto-removes elements after a configurable delay.\n * Supports pause-on-hover and fade effect using standard setTimeout/clearTimeout\n * (in its hyperscript `source`'s js() body).\n *\n * Defined from its hyperscript `source` (the single source of truth shared with\n * the browser bundle and patterns-reference).\n */\n\nimport { autoDismissSchema } from '../schemas/autodismiss.schema';\nimport { defineBehavior, resolveRuntime } from '../schemas/types';\nimport type { HyperscriptHost } from '../schemas/types';\n\n// Re-export schema-derived values\nexport const autoDismissSource = autoDismissSchema.source;\nexport const autoDismissMetadata = autoDismissSchema;\n\n/**\n * Define the AutoDismiss behavior on a hyperscript host (`window.hyperfixi` when none is given)\n * from its source, as a `<script type=\"text/hyperscript\">` would.\n */\nexport async function registerAutoDismiss(host?: HyperscriptHost): Promise<void> {\n defineBehavior(autoDismissSchema, host);\n}\n\n// Auto-register when loaded as a script tag\nif (resolveRuntime()) {\n registerAutoDismiss().catch(console.error);\n}\n\nexport default {\n source: autoDismissSchema.source,\n metadata: autoDismissSchema,\n register: registerAutoDismiss,\n};\n","import type { BehaviorSchema } from './types';\n\n/**\n * AutoDismiss Behavior Schema\n *\n * Auto-removes flash messages and toasts after a configurable delay.\n * Supports pause-on-hover and fade effect.\n */\nexport const autoDismissSchema: BehaviorSchema = {\n name: 'AutoDismiss',\n category: 'ui',\n tier: 'core',\n version: '1.0.0',\n description: 'Auto-removes elements after a delay with optional pause-on-hover',\n parameters: [\n {\n name: 'delay',\n type: 'number',\n optional: true,\n default: 5000,\n description: 'Time in ms before the element is removed',\n },\n {\n name: 'pauseOnHover',\n type: 'boolean',\n optional: true,\n default: true,\n description: 'Pause the countdown when the mouse hovers over the element',\n },\n {\n name: 'effect',\n type: 'string',\n optional: true,\n default: 'none',\n enum: ['fade', 'none'],\n description: 'Transition effect before removal: \"fade\" or \"none\"',\n },\n ],\n events: [\n { name: 'autodismiss:start', description: 'Fired when the countdown timer starts' },\n {\n name: 'autodismiss:dismissed',\n description: 'Fired before removal (cancelable via preventDefault)',\n },\n { name: 'autodismiss:paused', description: 'Fired when the timer is paused on hover' },\n { name: 'autodismiss:resumed', description: 'Fired when the timer resumes on mouseleave' },\n ],\n source: `\nbehavior AutoDismiss(delay, pauseOnHover, effect)\n init\n if delay is undefined set element's delay to 5000 end\n if pauseOnHover is undefined set element's pauseOnHover to true end\n if effect is undefined set element's effect to \"none\" end\n js(me, delay, effect, pauseOnHover)\n me.dispatchEvent(new CustomEvent('autodismiss:start', { bubbles: true }));\n var remaining = delay;\n var startedAt = Date.now();\n var timerId = null;\n function dismiss() {\n var ev = new CustomEvent('autodismiss:dismissed', { bubbles: true, cancelable: true });\n me.dispatchEvent(ev);\n if (ev.defaultPrevented) return;\n if (effect === 'fade') {\n me.style.transition = 'opacity 300ms';\n me.style.opacity = '0';\n setTimeout(function() { me.remove(); }, 300);\n } else {\n me.remove();\n }\n }\n function start() {\n startedAt = Date.now();\n timerId = setTimeout(dismiss, remaining);\n }\n start();\n if (pauseOnHover) {\n me.addEventListener('mouseenter', function() {\n if (timerId != null) {\n clearTimeout(timerId);\n timerId = null;\n remaining -= Date.now() - startedAt;\n if (remaining < 0) remaining = 0;\n me.dispatchEvent(new CustomEvent('autodismiss:paused', { bubbles: true }));\n }\n });\n me.addEventListener('mouseleave', function() {\n if (timerId == null && me.isConnected) {\n me.dispatchEvent(new CustomEvent('autodismiss:resumed', { bubbles: true }));\n start();\n }\n });\n }\n end\n end\nend`.trim(),\n};\n","/**\n * Behavior Schema Types\n *\n * Defines the structure for behavior metadata used for:\n * - Code generation (TypeScript types, documentation)\n * - Runtime categorization and lazy loading\n * - Tooling and IDE integration\n */\n\n/**\n * Behavior categories for organization.\n * - ui: Visual interaction behaviors (drag, resize, sort)\n * - data: Data manipulation behaviors (remove, transform)\n * - animation: Animation and transition behaviors\n * - form: Form-related behaviors (validation, toggle states)\n * - layout: Layout behaviors (sticky, scrollspy)\n */\nexport type BehaviorCategory = 'ui' | 'data' | 'animation' | 'form' | 'layout';\n\n/**\n * Loading tiers for lazy loading optimization.\n * - core: Always loaded (essential behaviors)\n * - common: High usage (loaded for typical apps)\n * - optional: Low usage (loaded on demand)\n */\nexport type BehaviorTier = 'core' | 'common' | 'optional';\n\n/**\n * Schema for a behavior parameter.\n */\nexport interface ParameterSchema {\n name: string;\n type: 'string' | 'number' | 'boolean' | 'selector' | 'element';\n optional?: boolean;\n default?: string | number | boolean;\n /** Allowed values for constrained parameters */\n enum?: string[];\n description: string;\n}\n\n/**\n * Schema for a behavior event.\n */\nexport interface EventSchema {\n name: string;\n description: string;\n}\n\n/**\n * Complete schema for a behavior.\n * This is the source of truth for all behavior metadata.\n */\nexport interface BehaviorSchema {\n /** Behavior name (PascalCase) */\n name: string;\n /** Category for organization */\n category: BehaviorCategory;\n /** Loading tier for lazy loading */\n tier: BehaviorTier;\n /** Semantic version */\n version: string;\n /** Human-readable description */\n description: string;\n /** Parameter definitions */\n parameters: ParameterSchema[];\n /** Event definitions */\n events: EventSchema[];\n /** The hyperscript behavior source code */\n source: string;\n /** Optional requirements or notes */\n requirements?: string[];\n}\n\n/**\n * Runtime behavior module interface: a behavior's source, its schema, and the function that\n * defines it on a hyperscript host.\n */\nexport interface BehaviorModule {\n source: string;\n metadata: BehaviorSchema;\n register: (host?: HyperscriptHost) => Promise<void>;\n}\n\n/**\n * A hyperscript host, in upstream `_hyperscript`'s shape: `@hyperfixi/engine` (the\n * `hyperfixi-hs.js` bundle, `window.hyperfixi` / `window._hyperscript`) or upstream itself.\n * `evaluate(source)` of a `behavior … end` program defines the behavior; `processNode`\n * initialises the scripted elements under a node.\n */\nexport interface HyperscriptHost {\n evaluate: (source: string) => unknown;\n processNode?: (node: Node) => void;\n}\n\n/** The window globals a host installs itself as. */\nexport interface HyperscriptWindow {\n hyperfixi?: HyperscriptHost;\n _hyperscript?: HyperscriptHost;\n}\n\n/** The host on `window`: `hyperfixi` (the engine's bundle) or `_hyperscript` (upstream's name). */\nexport function resolveRuntime(): HyperscriptHost | null {\n if (typeof window === 'undefined') return null;\n const win = window as unknown as HyperscriptWindow;\n const host = win.hyperfixi ?? win._hyperscript;\n return host && typeof host.evaluate === 'function' ? host : null;\n}\n\n/**\n * Define a behavior on a host from its schema's source, as a page's\n * `<script type=\"text/hyperscript\">` would. Throws when there is no host or the source\n * does not parse.\n */\nexport function defineBehavior(schema: BehaviorSchema, host?: HyperscriptHost): void {\n const hf = host ?? resolveRuntime();\n if (!hf) {\n throw new Error(\n `No hyperscript host found: load @hyperfixi/engine (hyperfixi-hs.js) before defining ${schema.name}.`\n );\n }\n try {\n hf.evaluate(schema.source);\n } catch (e) {\n throw new Error(`Failed to define ${schema.name} behavior: ${(e as Error).message}`);\n }\n}\n"],"mappings":"scAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,yBAAAE,EAAA,sBAAAC,EAAA,YAAAC,EAAA,wBAAAC,ICQO,IAAMC,EAAoC,CAC/C,KAAM,cACN,SAAU,KACV,KAAM,OACN,QAAS,QACT,YAAa,mEACb,WAAY,CACV,CACE,KAAM,QACN,KAAM,SACN,SAAU,GACV,QAAS,IACT,YAAa,0CACf,EACA,CACE,KAAM,eACN,KAAM,UACN,SAAU,GACV,QAAS,GACT,YAAa,4DACf,EACA,CACE,KAAM,SACN,KAAM,SACN,SAAU,GACV,QAAS,OACT,KAAM,CAAC,OAAQ,MAAM,EACrB,YAAa,oDACf,CACF,EACA,OAAQ,CACN,CAAE,KAAM,oBAAqB,YAAa,uCAAwC,EAClF,CACE,KAAM,wBACN,YAAa,sDACf,EACA,CAAE,KAAM,qBAAsB,YAAa,yCAA0C,EACrF,CAAE,KAAM,sBAAuB,YAAa,4CAA6C,CAC3F,EACA,OAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,KA+CL,KAAK,CACV,ECMO,SAASC,GAAyC,CACvD,GAAI,OAAO,OAAW,IAAa,OAAO,KAC1C,IAAMC,EAAM,OACNC,EAAOD,EAAI,WAAaA,EAAI,aAClC,OAAOC,GAAQ,OAAOA,EAAK,UAAa,WAAaA,EAAO,IAC9D,CAOO,SAASC,EAAeC,EAAwBF,EAA8B,CACnF,IAAMG,EAAKH,GAAQF,EAAe,EAClC,GAAI,CAACK,EACH,MAAM,IAAI,MACR,uFAAuFD,EAAO,IAAI,GACpG,EAEF,GAAI,CACFC,EAAG,SAASD,EAAO,MAAM,CAC3B,OAASE,EAAG,CACV,MAAM,IAAI,MAAM,oBAAoBF,EAAO,IAAI,cAAeE,EAAY,OAAO,EAAE,CACrF,CACF,CF7GO,IAAMC,EAAoBC,EAAkB,OACtCC,EAAsBD,EAMnC,eAAsBE,EAAoBC,EAAuC,CAC/EC,EAAeJ,EAAmBG,CAAI,CACxC,CAGIE,EAAe,GACjBH,EAAoB,EAAE,MAAM,QAAQ,KAAK,EAG3C,IAAOI,EAAQ,CACb,OAAQN,EAAkB,OAC1B,SAAUA,EACV,SAAUE,CACZ","names":["autodismiss_exports","__export","autoDismissMetadata","autoDismissSource","autodismiss_default","registerAutoDismiss","autoDismissSchema","resolveRuntime","win","host","defineBehavior","schema","hf","e","autoDismissSource","autoDismissSchema","autoDismissMetadata","registerAutoDismiss","host","defineBehavior","resolveRuntime","autodismiss_default"]}
|
|
@@ -70,15 +70,9 @@ var autoDismissSchema = {
|
|
|
70
70
|
source: `
|
|
71
71
|
behavior AutoDismiss(delay, pauseOnHover, effect)
|
|
72
72
|
init
|
|
73
|
-
if delay is undefined
|
|
74
|
-
|
|
75
|
-
end
|
|
76
|
-
if pauseOnHover is undefined
|
|
77
|
-
set pauseOnHover to true
|
|
78
|
-
end
|
|
79
|
-
if effect is undefined
|
|
80
|
-
set effect to "none"
|
|
81
|
-
end
|
|
73
|
+
if delay is undefined set element's delay to 5000 end
|
|
74
|
+
if pauseOnHover is undefined set element's pauseOnHover to true end
|
|
75
|
+
if effect is undefined set element's effect to "none" end
|
|
82
76
|
js(me, delay, effect, pauseOnHover)
|
|
83
77
|
me.dispatchEvent(new CustomEvent('autodismiss:start', { bubbles: true }));
|
|
84
78
|
var remaining = delay;
|
|
@@ -127,25 +121,28 @@ end`.trim()
|
|
|
127
121
|
function resolveRuntime() {
|
|
128
122
|
if (typeof window === "undefined") return null;
|
|
129
123
|
const win = window;
|
|
130
|
-
|
|
124
|
+
const host = win.hyperfixi ?? win._hyperscript;
|
|
125
|
+
return host && typeof host.evaluate === "function" ? host : null;
|
|
131
126
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
var autoDismissSource = autoDismissSchema.source;
|
|
135
|
-
var autoDismissMetadata = autoDismissSchema;
|
|
136
|
-
async function registerAutoDismiss(hyperfixi) {
|
|
137
|
-
const hf = hyperfixi || resolveRuntime();
|
|
127
|
+
function defineBehavior(schema, host) {
|
|
128
|
+
const hf = host ?? resolveRuntime();
|
|
138
129
|
if (!hf) {
|
|
139
130
|
throw new Error(
|
|
140
|
-
|
|
131
|
+
`No hyperscript host found: load @hyperfixi/engine (hyperfixi-hs.js) before defining ${schema.name}.`
|
|
141
132
|
);
|
|
142
133
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
134
|
+
try {
|
|
135
|
+
hf.evaluate(schema.source);
|
|
136
|
+
} catch (e) {
|
|
137
|
+
throw new Error(`Failed to define ${schema.name} behavior: ${e.message}`);
|
|
146
138
|
}
|
|
147
|
-
|
|
148
|
-
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// src/behaviors/autodismiss.ts
|
|
142
|
+
var autoDismissSource = autoDismissSchema.source;
|
|
143
|
+
var autoDismissMetadata = autoDismissSchema;
|
|
144
|
+
async function registerAutoDismiss(host) {
|
|
145
|
+
defineBehavior(autoDismissSchema, host);
|
|
149
146
|
}
|
|
150
147
|
if (resolveRuntime()) {
|
|
151
148
|
registerAutoDismiss().catch(console.error);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/behaviors/autodismiss.ts","../../src/schemas/autodismiss.schema.ts","../../src/schemas/types.ts"],"sourcesContent":["/**\n * AutoDismiss Behavior\n *\n * Auto-removes elements after a configurable delay.\n * Supports pause-on-hover and fade effect using standard setTimeout/clearTimeout\n * (in its hyperscript `source`'s js() body).\n *\n * Compiled from its hyperscript `source` (the single source of truth shared with\n * the CDN resolver bundle and patterns-reference).\n */\n\nimport { autoDismissSchema } from '../schemas/autodismiss.schema';\nimport type { LokaScriptInstance } from '../schemas/types';\nimport { resolveRuntime } from '../schemas/types';\n\n// Re-export schema-derived values\nexport const autoDismissSource = autoDismissSchema.source;\nexport const autoDismissMetadata = autoDismissSchema;\n\n/**\n * Register the AutoDismiss behavior with LokaScript by compiling its\n * hyperscript source and executing the resulting behavior definition.\n */\nexport async function registerAutoDismiss(hyperfixi?: LokaScriptInstance): Promise<void> {\n const hf = hyperfixi || resolveRuntime();\n\n if (!hf) {\n throw new Error(\n 'LokaScript not found. Make sure @hyperfixi/core is loaded before registering behaviors.'\n );\n }\n\n const result = hf.compileSync(autoDismissSchema.source, { traditional: true });\n\n if (!result.ok) {\n throw new Error(`Failed to compile AutoDismiss behavior: ${JSON.stringify(result.errors)}`);\n }\n\n const ctx = hf.createContext ? hf.createContext() : { locals: new Map(), globals: new Map() };\n await hf.execute(result.ast, ctx);\n}\n\n// Auto-register when loaded as a script tag\nif (resolveRuntime()) {\n registerAutoDismiss().catch(console.error);\n}\n\nexport default {\n source: autoDismissSchema.source,\n metadata: autoDismissSchema,\n register: registerAutoDismiss,\n};\n","import type { BehaviorSchema } from './types';\n\n/**\n * AutoDismiss Behavior Schema\n *\n * Auto-removes flash messages and toasts after a configurable delay.\n * Supports pause-on-hover and fade effect.\n */\nexport const autoDismissSchema: BehaviorSchema = {\n name: 'AutoDismiss',\n category: 'ui',\n tier: 'core',\n version: '1.0.0',\n description: 'Auto-removes elements after a delay with optional pause-on-hover',\n parameters: [\n {\n name: 'delay',\n type: 'number',\n optional: true,\n default: 5000,\n description: 'Time in ms before the element is removed',\n },\n {\n name: 'pauseOnHover',\n type: 'boolean',\n optional: true,\n default: true,\n description: 'Pause the countdown when the mouse hovers over the element',\n },\n {\n name: 'effect',\n type: 'string',\n optional: true,\n default: 'none',\n enum: ['fade', 'none'],\n description: 'Transition effect before removal: \"fade\" or \"none\"',\n },\n ],\n events: [\n { name: 'autodismiss:start', description: 'Fired when the countdown timer starts' },\n {\n name: 'autodismiss:dismissed',\n description: 'Fired before removal (cancelable via preventDefault)',\n },\n { name: 'autodismiss:paused', description: 'Fired when the timer is paused on hover' },\n { name: 'autodismiss:resumed', description: 'Fired when the timer resumes on mouseleave' },\n ],\n source: `\nbehavior AutoDismiss(delay, pauseOnHover, effect)\n init\n if delay is undefined\n set delay to 5000\n end\n if pauseOnHover is undefined\n set pauseOnHover to true\n end\n if effect is undefined\n set effect to \"none\"\n end\n js(me, delay, effect, pauseOnHover)\n me.dispatchEvent(new CustomEvent('autodismiss:start', { bubbles: true }));\n var remaining = delay;\n var startedAt = Date.now();\n var timerId = null;\n function dismiss() {\n var ev = new CustomEvent('autodismiss:dismissed', { bubbles: true, cancelable: true });\n me.dispatchEvent(ev);\n if (ev.defaultPrevented) return;\n if (effect === 'fade') {\n me.style.transition = 'opacity 300ms';\n me.style.opacity = '0';\n setTimeout(function() { me.remove(); }, 300);\n } else {\n me.remove();\n }\n }\n function start() {\n startedAt = Date.now();\n timerId = setTimeout(dismiss, remaining);\n }\n start();\n if (pauseOnHover) {\n me.addEventListener('mouseenter', function() {\n if (timerId != null) {\n clearTimeout(timerId);\n timerId = null;\n remaining -= Date.now() - startedAt;\n if (remaining < 0) remaining = 0;\n me.dispatchEvent(new CustomEvent('autodismiss:paused', { bubbles: true }));\n }\n });\n me.addEventListener('mouseleave', function() {\n if (timerId == null && me.isConnected) {\n me.dispatchEvent(new CustomEvent('autodismiss:resumed', { bubbles: true }));\n start();\n }\n });\n }\n end\n end\nend`.trim(),\n};\n","/**\n * Behavior Schema Types\n *\n * Defines the structure for behavior metadata used for:\n * - Code generation (TypeScript types, documentation)\n * - Runtime categorization and lazy loading\n * - Tooling and IDE integration\n */\n\n/**\n * Behavior categories for organization.\n * - ui: Visual interaction behaviors (drag, resize, sort)\n * - data: Data manipulation behaviors (remove, transform)\n * - animation: Animation and transition behaviors\n * - form: Form-related behaviors (validation, toggle states)\n * - layout: Layout behaviors (sticky, scrollspy)\n */\nexport type BehaviorCategory = 'ui' | 'data' | 'animation' | 'form' | 'layout';\n\n/**\n * Loading tiers for lazy loading optimization.\n * - core: Always loaded (essential behaviors)\n * - common: High usage (loaded for typical apps)\n * - optional: Low usage (loaded on demand)\n */\nexport type BehaviorTier = 'core' | 'common' | 'optional';\n\n/**\n * Schema for a behavior parameter.\n */\nexport interface ParameterSchema {\n name: string;\n type: 'string' | 'number' | 'boolean' | 'selector' | 'element';\n optional?: boolean;\n default?: string | number | boolean;\n /** Allowed values for constrained parameters */\n enum?: string[];\n description: string;\n}\n\n/**\n * Schema for a behavior event.\n */\nexport interface EventSchema {\n name: string;\n description: string;\n}\n\n/**\n * Complete schema for a behavior.\n * This is the source of truth for all behavior metadata.\n */\nexport interface BehaviorSchema {\n /** Behavior name (PascalCase) */\n name: string;\n /** Category for organization */\n category: BehaviorCategory;\n /** Loading tier for lazy loading */\n tier: BehaviorTier;\n /** Semantic version */\n version: string;\n /** Human-readable description */\n description: string;\n /** Parameter definitions */\n parameters: ParameterSchema[];\n /** Event definitions */\n events: EventSchema[];\n /** The hyperscript behavior source code */\n source: string;\n /** Optional requirements or notes */\n requirements?: string[];\n}\n\n/**\n * Runtime behavior module interface.\n * This is what gets registered with the hyperfixi runtime.\n */\nexport interface BehaviorModule {\n source: string;\n metadata: BehaviorSchema;\n register: (hyperfixi?: LokaScriptInstance) => Promise<void>;\n}\n\n/**\n * Minimal LokaScript instance interface for behavior registration.\n */\nexport interface LokaScriptInstance {\n compileSync: (\n code: string,\n options?: { traditional?: boolean; language?: string }\n ) => {\n ok: boolean;\n ast?: unknown;\n errors?: Array<{ message: string; line?: number; column?: number }>;\n };\n execute: (ast: unknown, ctx: unknown) => Promise<unknown>;\n createContext?: () => { locals: Map<string, unknown>; globals: Map<string, unknown> };\n}\n\n/**\n * Typed window interface for behavior auto-registration.\n * Avoids `(window as any)` casts throughout the codebase.\n * Checks both `window.lokascript` and `window.hyperfixi` for the runtime instance.\n */\nexport interface LokaScriptWindow {\n lokascript?: LokaScriptInstance;\n hyperfixi?: LokaScriptInstance;\n __hyperfixi_behaviors_ready?: Promise<void> | undefined;\n}\n\n/**\n * Resolve the LokaScript runtime from window globals.\n * Checks both `window.lokascript` and `window.hyperfixi`.\n */\nexport function resolveRuntime(): LokaScriptInstance | null {\n if (typeof window === 'undefined') return null;\n const win = window as unknown as LokaScriptWindow;\n return win.lokascript || win.hyperfixi || null;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACQO,IAAM,oBAAoC;AAAA,EAC/C,MAAM;AAAA,EACN,UAAU;AAAA,EACV,MAAM;AAAA,EACN,SAAS;AAAA,EACT,aAAa;AAAA,EACb,YAAY;AAAA,IACV;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA,MACN,UAAU;AAAA,MACV,SAAS;AAAA,MACT,aAAa;AAAA,IACf;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA,MACN,UAAU;AAAA,MACV,SAAS;AAAA,MACT,aAAa;AAAA,IACf;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA,MACN,UAAU;AAAA,MACV,SAAS;AAAA,MACT,MAAM,CAAC,QAAQ,MAAM;AAAA,MACrB,aAAa;AAAA,IACf;AAAA,EACF;AAAA,EACA,QAAQ;AAAA,IACN,EAAE,MAAM,qBAAqB,aAAa,wCAAwC;AAAA,IAClF;AAAA,MACE,MAAM;AAAA,MACN,aAAa;AAAA,IACf;AAAA,IACA,EAAE,MAAM,sBAAsB,aAAa,0CAA0C;AAAA,IACrF,EAAE,MAAM,uBAAuB,aAAa,6CAA6C;AAAA,EAC3F;AAAA,EACA,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,KAqDL,KAAK;AACV;;;ACaO,SAAS,iBAA4C;AAC1D,MAAI,OAAO,WAAW,YAAa,QAAO;AAC1C,QAAM,MAAM;AACZ,SAAO,IAAI,cAAc,IAAI,aAAa;AAC5C;;;AFtGO,IAAM,oBAAoB,kBAAkB;AAC5C,IAAM,sBAAsB;AAMnC,eAAsB,oBAAoB,WAA+C;AACvF,QAAM,KAAK,aAAa,eAAe;AAEvC,MAAI,CAAC,IAAI;AACP,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,QAAM,SAAS,GAAG,YAAY,kBAAkB,QAAQ,EAAE,aAAa,KAAK,CAAC;AAE7E,MAAI,CAAC,OAAO,IAAI;AACd,UAAM,IAAI,MAAM,2CAA2C,KAAK,UAAU,OAAO,MAAM,CAAC,EAAE;AAAA,EAC5F;AAEA,QAAM,MAAM,GAAG,gBAAgB,GAAG,cAAc,IAAI,EAAE,QAAQ,oBAAI,IAAI,GAAG,SAAS,oBAAI,IAAI,EAAE;AAC5F,QAAM,GAAG,QAAQ,OAAO,KAAK,GAAG;AAClC;AAGA,IAAI,eAAe,GAAG;AACpB,sBAAoB,EAAE,MAAM,QAAQ,KAAK;AAC3C;AAEA,IAAO,sBAAQ;AAAA,EACb,QAAQ,kBAAkB;AAAA,EAC1B,UAAU;AAAA,EACV,UAAU;AACZ;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/behaviors/autodismiss.ts","../../src/schemas/autodismiss.schema.ts","../../src/schemas/types.ts"],"sourcesContent":["/**\n * AutoDismiss Behavior\n *\n * Auto-removes elements after a configurable delay.\n * Supports pause-on-hover and fade effect using standard setTimeout/clearTimeout\n * (in its hyperscript `source`'s js() body).\n *\n * Defined from its hyperscript `source` (the single source of truth shared with\n * the browser bundle and patterns-reference).\n */\n\nimport { autoDismissSchema } from '../schemas/autodismiss.schema';\nimport { defineBehavior, resolveRuntime } from '../schemas/types';\nimport type { HyperscriptHost } from '../schemas/types';\n\n// Re-export schema-derived values\nexport const autoDismissSource = autoDismissSchema.source;\nexport const autoDismissMetadata = autoDismissSchema;\n\n/**\n * Define the AutoDismiss behavior on a hyperscript host (`window.hyperfixi` when none is given)\n * from its source, as a `<script type=\"text/hyperscript\">` would.\n */\nexport async function registerAutoDismiss(host?: HyperscriptHost): Promise<void> {\n defineBehavior(autoDismissSchema, host);\n}\n\n// Auto-register when loaded as a script tag\nif (resolveRuntime()) {\n registerAutoDismiss().catch(console.error);\n}\n\nexport default {\n source: autoDismissSchema.source,\n metadata: autoDismissSchema,\n register: registerAutoDismiss,\n};\n","import type { BehaviorSchema } from './types';\n\n/**\n * AutoDismiss Behavior Schema\n *\n * Auto-removes flash messages and toasts after a configurable delay.\n * Supports pause-on-hover and fade effect.\n */\nexport const autoDismissSchema: BehaviorSchema = {\n name: 'AutoDismiss',\n category: 'ui',\n tier: 'core',\n version: '1.0.0',\n description: 'Auto-removes elements after a delay with optional pause-on-hover',\n parameters: [\n {\n name: 'delay',\n type: 'number',\n optional: true,\n default: 5000,\n description: 'Time in ms before the element is removed',\n },\n {\n name: 'pauseOnHover',\n type: 'boolean',\n optional: true,\n default: true,\n description: 'Pause the countdown when the mouse hovers over the element',\n },\n {\n name: 'effect',\n type: 'string',\n optional: true,\n default: 'none',\n enum: ['fade', 'none'],\n description: 'Transition effect before removal: \"fade\" or \"none\"',\n },\n ],\n events: [\n { name: 'autodismiss:start', description: 'Fired when the countdown timer starts' },\n {\n name: 'autodismiss:dismissed',\n description: 'Fired before removal (cancelable via preventDefault)',\n },\n { name: 'autodismiss:paused', description: 'Fired when the timer is paused on hover' },\n { name: 'autodismiss:resumed', description: 'Fired when the timer resumes on mouseleave' },\n ],\n source: `\nbehavior AutoDismiss(delay, pauseOnHover, effect)\n init\n if delay is undefined set element's delay to 5000 end\n if pauseOnHover is undefined set element's pauseOnHover to true end\n if effect is undefined set element's effect to \"none\" end\n js(me, delay, effect, pauseOnHover)\n me.dispatchEvent(new CustomEvent('autodismiss:start', { bubbles: true }));\n var remaining = delay;\n var startedAt = Date.now();\n var timerId = null;\n function dismiss() {\n var ev = new CustomEvent('autodismiss:dismissed', { bubbles: true, cancelable: true });\n me.dispatchEvent(ev);\n if (ev.defaultPrevented) return;\n if (effect === 'fade') {\n me.style.transition = 'opacity 300ms';\n me.style.opacity = '0';\n setTimeout(function() { me.remove(); }, 300);\n } else {\n me.remove();\n }\n }\n function start() {\n startedAt = Date.now();\n timerId = setTimeout(dismiss, remaining);\n }\n start();\n if (pauseOnHover) {\n me.addEventListener('mouseenter', function() {\n if (timerId != null) {\n clearTimeout(timerId);\n timerId = null;\n remaining -= Date.now() - startedAt;\n if (remaining < 0) remaining = 0;\n me.dispatchEvent(new CustomEvent('autodismiss:paused', { bubbles: true }));\n }\n });\n me.addEventListener('mouseleave', function() {\n if (timerId == null && me.isConnected) {\n me.dispatchEvent(new CustomEvent('autodismiss:resumed', { bubbles: true }));\n start();\n }\n });\n }\n end\n end\nend`.trim(),\n};\n","/**\n * Behavior Schema Types\n *\n * Defines the structure for behavior metadata used for:\n * - Code generation (TypeScript types, documentation)\n * - Runtime categorization and lazy loading\n * - Tooling and IDE integration\n */\n\n/**\n * Behavior categories for organization.\n * - ui: Visual interaction behaviors (drag, resize, sort)\n * - data: Data manipulation behaviors (remove, transform)\n * - animation: Animation and transition behaviors\n * - form: Form-related behaviors (validation, toggle states)\n * - layout: Layout behaviors (sticky, scrollspy)\n */\nexport type BehaviorCategory = 'ui' | 'data' | 'animation' | 'form' | 'layout';\n\n/**\n * Loading tiers for lazy loading optimization.\n * - core: Always loaded (essential behaviors)\n * - common: High usage (loaded for typical apps)\n * - optional: Low usage (loaded on demand)\n */\nexport type BehaviorTier = 'core' | 'common' | 'optional';\n\n/**\n * Schema for a behavior parameter.\n */\nexport interface ParameterSchema {\n name: string;\n type: 'string' | 'number' | 'boolean' | 'selector' | 'element';\n optional?: boolean;\n default?: string | number | boolean;\n /** Allowed values for constrained parameters */\n enum?: string[];\n description: string;\n}\n\n/**\n * Schema for a behavior event.\n */\nexport interface EventSchema {\n name: string;\n description: string;\n}\n\n/**\n * Complete schema for a behavior.\n * This is the source of truth for all behavior metadata.\n */\nexport interface BehaviorSchema {\n /** Behavior name (PascalCase) */\n name: string;\n /** Category for organization */\n category: BehaviorCategory;\n /** Loading tier for lazy loading */\n tier: BehaviorTier;\n /** Semantic version */\n version: string;\n /** Human-readable description */\n description: string;\n /** Parameter definitions */\n parameters: ParameterSchema[];\n /** Event definitions */\n events: EventSchema[];\n /** The hyperscript behavior source code */\n source: string;\n /** Optional requirements or notes */\n requirements?: string[];\n}\n\n/**\n * Runtime behavior module interface: a behavior's source, its schema, and the function that\n * defines it on a hyperscript host.\n */\nexport interface BehaviorModule {\n source: string;\n metadata: BehaviorSchema;\n register: (host?: HyperscriptHost) => Promise<void>;\n}\n\n/**\n * A hyperscript host, in upstream `_hyperscript`'s shape: `@hyperfixi/engine` (the\n * `hyperfixi-hs.js` bundle, `window.hyperfixi` / `window._hyperscript`) or upstream itself.\n * `evaluate(source)` of a `behavior … end` program defines the behavior; `processNode`\n * initialises the scripted elements under a node.\n */\nexport interface HyperscriptHost {\n evaluate: (source: string) => unknown;\n processNode?: (node: Node) => void;\n}\n\n/** The window globals a host installs itself as. */\nexport interface HyperscriptWindow {\n hyperfixi?: HyperscriptHost;\n _hyperscript?: HyperscriptHost;\n}\n\n/** The host on `window`: `hyperfixi` (the engine's bundle) or `_hyperscript` (upstream's name). */\nexport function resolveRuntime(): HyperscriptHost | null {\n if (typeof window === 'undefined') return null;\n const win = window as unknown as HyperscriptWindow;\n const host = win.hyperfixi ?? win._hyperscript;\n return host && typeof host.evaluate === 'function' ? host : null;\n}\n\n/**\n * Define a behavior on a host from its schema's source, as a page's\n * `<script type=\"text/hyperscript\">` would. Throws when there is no host or the source\n * does not parse.\n */\nexport function defineBehavior(schema: BehaviorSchema, host?: HyperscriptHost): void {\n const hf = host ?? resolveRuntime();\n if (!hf) {\n throw new Error(\n `No hyperscript host found: load @hyperfixi/engine (hyperfixi-hs.js) before defining ${schema.name}.`\n );\n }\n try {\n hf.evaluate(schema.source);\n } catch (e) {\n throw new Error(`Failed to define ${schema.name} behavior: ${(e as Error).message}`);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACQO,IAAM,oBAAoC;AAAA,EAC/C,MAAM;AAAA,EACN,UAAU;AAAA,EACV,MAAM;AAAA,EACN,SAAS;AAAA,EACT,aAAa;AAAA,EACb,YAAY;AAAA,IACV;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA,MACN,UAAU;AAAA,MACV,SAAS;AAAA,MACT,aAAa;AAAA,IACf;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA,MACN,UAAU;AAAA,MACV,SAAS;AAAA,MACT,aAAa;AAAA,IACf;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA,MACN,UAAU;AAAA,MACV,SAAS;AAAA,MACT,MAAM,CAAC,QAAQ,MAAM;AAAA,MACrB,aAAa;AAAA,IACf;AAAA,EACF;AAAA,EACA,QAAQ;AAAA,IACN,EAAE,MAAM,qBAAqB,aAAa,wCAAwC;AAAA,IAClF;AAAA,MACE,MAAM;AAAA,MACN,aAAa;AAAA,IACf;AAAA,IACA,EAAE,MAAM,sBAAsB,aAAa,0CAA0C;AAAA,IACrF,EAAE,MAAM,uBAAuB,aAAa,6CAA6C;AAAA,EAC3F;AAAA,EACA,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,KA+CL,KAAK;AACV;;;ACMO,SAAS,iBAAyC;AACvD,MAAI,OAAO,WAAW,YAAa,QAAO;AAC1C,QAAM,MAAM;AACZ,QAAM,OAAO,IAAI,aAAa,IAAI;AAClC,SAAO,QAAQ,OAAO,KAAK,aAAa,aAAa,OAAO;AAC9D;AAOO,SAAS,eAAe,QAAwB,MAA8B;AACnF,QAAM,KAAK,QAAQ,eAAe;AAClC,MAAI,CAAC,IAAI;AACP,UAAM,IAAI;AAAA,MACR,uFAAuF,OAAO,IAAI;AAAA,IACpG;AAAA,EACF;AACA,MAAI;AACF,OAAG,SAAS,OAAO,MAAM;AAAA,EAC3B,SAAS,GAAG;AACV,UAAM,IAAI,MAAM,oBAAoB,OAAO,IAAI,cAAe,EAAY,OAAO,EAAE;AAAA,EACrF;AACF;;;AF7GO,IAAM,oBAAoB,kBAAkB;AAC5C,IAAM,sBAAsB;AAMnC,eAAsB,oBAAoB,MAAuC;AAC/E,iBAAe,mBAAmB,IAAI;AACxC;AAGA,IAAI,eAAe,GAAG;AACpB,sBAAoB,EAAE,MAAM,QAAQ,KAAK;AAC3C;AAEA,IAAO,sBAAQ;AAAA,EACb,QAAQ,kBAAkB;AAAA,EAC1B,UAAU;AAAA,EACV,UAAU;AACZ;","names":[]}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { B as BehaviorSchema,
|
|
1
|
+
import { B as BehaviorSchema, H as HyperscriptHost } from '../types-CbA4L8XJ.cjs';
|
|
2
2
|
|
|
3
3
|
declare const autoDismissSource: string;
|
|
4
4
|
declare const autoDismissMetadata: BehaviorSchema;
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
* Define the AutoDismiss behavior on a hyperscript host (`window.hyperfixi` when none is given)
|
|
7
|
+
* from its source, as a `<script type="text/hyperscript">` would.
|
|
8
8
|
*/
|
|
9
|
-
declare function registerAutoDismiss(
|
|
9
|
+
declare function registerAutoDismiss(host?: HyperscriptHost): Promise<void>;
|
|
10
10
|
declare const _default: {
|
|
11
11
|
source: string;
|
|
12
12
|
metadata: BehaviorSchema;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { B as BehaviorSchema,
|
|
1
|
+
import { B as BehaviorSchema, H as HyperscriptHost } from '../types-CbA4L8XJ.js';
|
|
2
2
|
|
|
3
3
|
declare const autoDismissSource: string;
|
|
4
4
|
declare const autoDismissMetadata: BehaviorSchema;
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
* Define the AutoDismiss behavior on a hyperscript host (`window.hyperfixi` when none is given)
|
|
7
|
+
* from its source, as a `<script type="text/hyperscript">` would.
|
|
8
8
|
*/
|
|
9
|
-
declare function registerAutoDismiss(
|
|
9
|
+
declare function registerAutoDismiss(host?: HyperscriptHost): Promise<void>;
|
|
10
10
|
declare const _default: {
|
|
11
11
|
source: string;
|
|
12
12
|
metadata: BehaviorSchema;
|
|
@@ -3,9 +3,9 @@ import {
|
|
|
3
3
|
autoDismissSource,
|
|
4
4
|
autodismiss_default,
|
|
5
5
|
registerAutoDismiss
|
|
6
|
-
} from "../chunk-
|
|
7
|
-
import "../chunk-
|
|
8
|
-
import "../chunk-
|
|
6
|
+
} from "../chunk-4YUIDZAO.js";
|
|
7
|
+
import "../chunk-KP4GNXYS.js";
|
|
8
|
+
import "../chunk-VWDTOSE3.js";
|
|
9
9
|
export {
|
|
10
10
|
autoDismissMetadata,
|
|
11
11
|
autoDismissSource,
|
|
@@ -58,9 +58,7 @@ var clickOutsideSchema = {
|
|
|
58
58
|
source: `
|
|
59
59
|
behavior ClickOutside(active)
|
|
60
60
|
init
|
|
61
|
-
if active is undefined
|
|
62
|
-
set active to true
|
|
63
|
-
end
|
|
61
|
+
if active is undefined set element's active to true end
|
|
64
62
|
end
|
|
65
63
|
on pointerdown from document
|
|
66
64
|
js(me, active, event)
|
|
@@ -71,10 +69,10 @@ behavior ClickOutside(active)
|
|
|
71
69
|
end
|
|
72
70
|
end
|
|
73
71
|
on clickoutside:activate
|
|
74
|
-
set active to true
|
|
72
|
+
set element's active to true
|
|
75
73
|
end
|
|
76
74
|
on clickoutside:deactivate
|
|
77
|
-
set active to false
|
|
75
|
+
set element's active to false
|
|
78
76
|
end
|
|
79
77
|
end`.trim()
|
|
80
78
|
};
|
|
@@ -83,25 +81,28 @@ end`.trim()
|
|
|
83
81
|
function resolveRuntime() {
|
|
84
82
|
if (typeof window === "undefined") return null;
|
|
85
83
|
const win = window;
|
|
86
|
-
|
|
84
|
+
const host = win.hyperfixi ?? win._hyperscript;
|
|
85
|
+
return host && typeof host.evaluate === "function" ? host : null;
|
|
87
86
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
var clickOutsideSource = clickOutsideSchema.source;
|
|
91
|
-
var clickOutsideMetadata = clickOutsideSchema;
|
|
92
|
-
async function registerClickOutside(hyperfixi) {
|
|
93
|
-
const hf = hyperfixi || resolveRuntime();
|
|
87
|
+
function defineBehavior(schema, host) {
|
|
88
|
+
const hf = host ?? resolveRuntime();
|
|
94
89
|
if (!hf) {
|
|
95
90
|
throw new Error(
|
|
96
|
-
|
|
91
|
+
`No hyperscript host found: load @hyperfixi/engine (hyperfixi-hs.js) before defining ${schema.name}.`
|
|
97
92
|
);
|
|
98
93
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
94
|
+
try {
|
|
95
|
+
hf.evaluate(schema.source);
|
|
96
|
+
} catch (e) {
|
|
97
|
+
throw new Error(`Failed to define ${schema.name} behavior: ${e.message}`);
|
|
102
98
|
}
|
|
103
|
-
|
|
104
|
-
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// src/behaviors/clickoutside.ts
|
|
102
|
+
var clickOutsideSource = clickOutsideSchema.source;
|
|
103
|
+
var clickOutsideMetadata = clickOutsideSchema;
|
|
104
|
+
async function registerClickOutside(host) {
|
|
105
|
+
defineBehavior(clickOutsideSchema, host);
|
|
105
106
|
}
|
|
106
107
|
if (resolveRuntime()) {
|
|
107
108
|
registerClickOutside().catch(console.error);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/behaviors/clickoutside.ts","../../src/schemas/clickoutside.schema.ts","../../src/schemas/types.ts"],"sourcesContent":["/**\n * ClickOutside Behavior\n *\n * Fires a clickoutside event when the user clicks outside the element.\n * Uses pointerdown instead of click to avoid timing issues.\n *\n *
|
|
1
|
+
{"version":3,"sources":["../../src/behaviors/clickoutside.ts","../../src/schemas/clickoutside.schema.ts","../../src/schemas/types.ts"],"sourcesContent":["/**\n * ClickOutside Behavior\n *\n * Fires a clickoutside event when the user clicks outside the element.\n * Uses pointerdown instead of click to avoid timing issues.\n *\n * Defined from its hyperscript `source` (the single source of truth shared with\n * the browser bundle and patterns-reference).\n */\n\nimport { clickOutsideSchema } from '../schemas/clickoutside.schema';\nimport { defineBehavior, resolveRuntime } from '../schemas/types';\nimport type { HyperscriptHost } from '../schemas/types';\n\n// Re-export schema-derived values\nexport const clickOutsideSource = clickOutsideSchema.source;\nexport const clickOutsideMetadata = clickOutsideSchema;\n\n/**\n * Define the ClickOutside behavior on a hyperscript host (`window.hyperfixi` when none is given)\n * from its source, as a `<script type=\"text/hyperscript\">` would.\n */\nexport async function registerClickOutside(host?: HyperscriptHost): Promise<void> {\n defineBehavior(clickOutsideSchema, host);\n}\n\n// Auto-register when loaded as a script tag\nif (resolveRuntime()) {\n registerClickOutside().catch(console.error);\n}\n\nexport default {\n source: clickOutsideSchema.source,\n metadata: clickOutsideSchema,\n register: registerClickOutside,\n};\n","import type { BehaviorSchema } from './types';\n\n/**\n * ClickOutside Behavior Schema\n *\n * Fires an event when the user clicks outside the element.\n * Uses pointerdown instead of click to avoid timing issues.\n */\nexport const clickOutsideSchema: BehaviorSchema = {\n name: 'ClickOutside',\n category: 'ui',\n tier: 'core',\n version: '1.0.0',\n description: 'Fires an event when the user clicks outside the element',\n parameters: [\n {\n name: 'active',\n type: 'boolean',\n optional: true,\n default: true,\n description: 'Whether the listener is active (can be toggled programmatically)',\n },\n ],\n events: [\n { name: 'clickoutside', description: 'Fired when a pointer press occurs outside the element' },\n {\n name: 'clickoutside:activate',\n description: 'Listen for this event to programmatically activate detection',\n },\n {\n name: 'clickoutside:deactivate',\n description: 'Listen for this event to programmatically deactivate detection',\n },\n ],\n requirements: ['Uses pointerdown instead of click to avoid timing issues with removed elements'],\n source: `\nbehavior ClickOutside(active)\n init\n if active is undefined set element's active to true end\n end\n on pointerdown from document\n js(me, active, event)\n if (!me.isConnected) return;\n if (active && !me.contains(event.target)) {\n me.dispatchEvent(new CustomEvent('clickoutside', { bubbles: true }));\n }\n end\n end\n on clickoutside:activate\n set element's active to true\n end\n on clickoutside:deactivate\n set element's active to false\n end\nend`.trim(),\n};\n","/**\n * Behavior Schema Types\n *\n * Defines the structure for behavior metadata used for:\n * - Code generation (TypeScript types, documentation)\n * - Runtime categorization and lazy loading\n * - Tooling and IDE integration\n */\n\n/**\n * Behavior categories for organization.\n * - ui: Visual interaction behaviors (drag, resize, sort)\n * - data: Data manipulation behaviors (remove, transform)\n * - animation: Animation and transition behaviors\n * - form: Form-related behaviors (validation, toggle states)\n * - layout: Layout behaviors (sticky, scrollspy)\n */\nexport type BehaviorCategory = 'ui' | 'data' | 'animation' | 'form' | 'layout';\n\n/**\n * Loading tiers for lazy loading optimization.\n * - core: Always loaded (essential behaviors)\n * - common: High usage (loaded for typical apps)\n * - optional: Low usage (loaded on demand)\n */\nexport type BehaviorTier = 'core' | 'common' | 'optional';\n\n/**\n * Schema for a behavior parameter.\n */\nexport interface ParameterSchema {\n name: string;\n type: 'string' | 'number' | 'boolean' | 'selector' | 'element';\n optional?: boolean;\n default?: string | number | boolean;\n /** Allowed values for constrained parameters */\n enum?: string[];\n description: string;\n}\n\n/**\n * Schema for a behavior event.\n */\nexport interface EventSchema {\n name: string;\n description: string;\n}\n\n/**\n * Complete schema for a behavior.\n * This is the source of truth for all behavior metadata.\n */\nexport interface BehaviorSchema {\n /** Behavior name (PascalCase) */\n name: string;\n /** Category for organization */\n category: BehaviorCategory;\n /** Loading tier for lazy loading */\n tier: BehaviorTier;\n /** Semantic version */\n version: string;\n /** Human-readable description */\n description: string;\n /** Parameter definitions */\n parameters: ParameterSchema[];\n /** Event definitions */\n events: EventSchema[];\n /** The hyperscript behavior source code */\n source: string;\n /** Optional requirements or notes */\n requirements?: string[];\n}\n\n/**\n * Runtime behavior module interface: a behavior's source, its schema, and the function that\n * defines it on a hyperscript host.\n */\nexport interface BehaviorModule {\n source: string;\n metadata: BehaviorSchema;\n register: (host?: HyperscriptHost) => Promise<void>;\n}\n\n/**\n * A hyperscript host, in upstream `_hyperscript`'s shape: `@hyperfixi/engine` (the\n * `hyperfixi-hs.js` bundle, `window.hyperfixi` / `window._hyperscript`) or upstream itself.\n * `evaluate(source)` of a `behavior … end` program defines the behavior; `processNode`\n * initialises the scripted elements under a node.\n */\nexport interface HyperscriptHost {\n evaluate: (source: string) => unknown;\n processNode?: (node: Node) => void;\n}\n\n/** The window globals a host installs itself as. */\nexport interface HyperscriptWindow {\n hyperfixi?: HyperscriptHost;\n _hyperscript?: HyperscriptHost;\n}\n\n/** The host on `window`: `hyperfixi` (the engine's bundle) or `_hyperscript` (upstream's name). */\nexport function resolveRuntime(): HyperscriptHost | null {\n if (typeof window === 'undefined') return null;\n const win = window as unknown as HyperscriptWindow;\n const host = win.hyperfixi ?? win._hyperscript;\n return host && typeof host.evaluate === 'function' ? host : null;\n}\n\n/**\n * Define a behavior on a host from its schema's source, as a page's\n * `<script type=\"text/hyperscript\">` would. Throws when there is no host or the source\n * does not parse.\n */\nexport function defineBehavior(schema: BehaviorSchema, host?: HyperscriptHost): void {\n const hf = host ?? resolveRuntime();\n if (!hf) {\n throw new Error(\n `No hyperscript host found: load @hyperfixi/engine (hyperfixi-hs.js) before defining ${schema.name}.`\n );\n }\n try {\n hf.evaluate(schema.source);\n } catch (e) {\n throw new Error(`Failed to define ${schema.name} behavior: ${(e as Error).message}`);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACQO,IAAM,qBAAqC;AAAA,EAChD,MAAM;AAAA,EACN,UAAU;AAAA,EACV,MAAM;AAAA,EACN,SAAS;AAAA,EACT,aAAa;AAAA,EACb,YAAY;AAAA,IACV;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA,MACN,UAAU;AAAA,MACV,SAAS;AAAA,MACT,aAAa;AAAA,IACf;AAAA,EACF;AAAA,EACA,QAAQ;AAAA,IACN,EAAE,MAAM,gBAAgB,aAAa,wDAAwD;AAAA,IAC7F;AAAA,MACE,MAAM;AAAA,MACN,aAAa;AAAA,IACf;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,aAAa;AAAA,IACf;AAAA,EACF;AAAA,EACA,cAAc,CAAC,gFAAgF;AAAA,EAC/F,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,KAmBL,KAAK;AACV;;;AC8CO,SAAS,iBAAyC;AACvD,MAAI,OAAO,WAAW,YAAa,QAAO;AAC1C,QAAM,MAAM;AACZ,QAAM,OAAO,IAAI,aAAa,IAAI;AAClC,SAAO,QAAQ,OAAO,KAAK,aAAa,aAAa,OAAO;AAC9D;AAOO,SAAS,eAAe,QAAwB,MAA8B;AACnF,QAAM,KAAK,QAAQ,eAAe;AAClC,MAAI,CAAC,IAAI;AACP,UAAM,IAAI;AAAA,MACR,uFAAuF,OAAO,IAAI;AAAA,IACpG;AAAA,EACF;AACA,MAAI;AACF,OAAG,SAAS,OAAO,MAAM;AAAA,EAC3B,SAAS,GAAG;AACV,UAAM,IAAI,MAAM,oBAAoB,OAAO,IAAI,cAAe,EAAY,OAAO,EAAE;AAAA,EACrF;AACF;;;AF9GO,IAAM,qBAAqB,mBAAmB;AAC9C,IAAM,uBAAuB;AAMpC,eAAsB,qBAAqB,MAAuC;AAChF,iBAAe,oBAAoB,IAAI;AACzC;AAGA,IAAI,eAAe,GAAG;AACpB,uBAAqB,EAAE,MAAM,QAAQ,KAAK;AAC5C;AAEA,IAAO,uBAAQ;AAAA,EACb,QAAQ,mBAAmB;AAAA,EAC3B,UAAU;AAAA,EACV,UAAU;AACZ;","names":[]}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { B as BehaviorSchema,
|
|
1
|
+
import { B as BehaviorSchema, H as HyperscriptHost } from '../types-CbA4L8XJ.cjs';
|
|
2
2
|
|
|
3
3
|
declare const clickOutsideSource: string;
|
|
4
4
|
declare const clickOutsideMetadata: BehaviorSchema;
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
* Define the ClickOutside behavior on a hyperscript host (`window.hyperfixi` when none is given)
|
|
7
|
+
* from its source, as a `<script type="text/hyperscript">` would.
|
|
8
8
|
*/
|
|
9
|
-
declare function registerClickOutside(
|
|
9
|
+
declare function registerClickOutside(host?: HyperscriptHost): Promise<void>;
|
|
10
10
|
declare const _default: {
|
|
11
11
|
source: string;
|
|
12
12
|
metadata: BehaviorSchema;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { B as BehaviorSchema,
|
|
1
|
+
import { B as BehaviorSchema, H as HyperscriptHost } from '../types-CbA4L8XJ.js';
|
|
2
2
|
|
|
3
3
|
declare const clickOutsideSource: string;
|
|
4
4
|
declare const clickOutsideMetadata: BehaviorSchema;
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
* Define the ClickOutside behavior on a hyperscript host (`window.hyperfixi` when none is given)
|
|
7
|
+
* from its source, as a `<script type="text/hyperscript">` would.
|
|
8
8
|
*/
|
|
9
|
-
declare function registerClickOutside(
|
|
9
|
+
declare function registerClickOutside(host?: HyperscriptHost): Promise<void>;
|
|
10
10
|
declare const _default: {
|
|
11
11
|
source: string;
|
|
12
12
|
metadata: BehaviorSchema;
|
|
@@ -3,9 +3,9 @@ import {
|
|
|
3
3
|
clickOutsideSource,
|
|
4
4
|
clickoutside_default,
|
|
5
5
|
registerClickOutside
|
|
6
|
-
} from "../chunk-
|
|
7
|
-
import "../chunk-
|
|
8
|
-
import "../chunk-
|
|
6
|
+
} from "../chunk-DMWN52SV.js";
|
|
7
|
+
import "../chunk-HJESSMKB.js";
|
|
8
|
+
import "../chunk-VWDTOSE3.js";
|
|
9
9
|
export {
|
|
10
10
|
clickOutsideMetadata,
|
|
11
11
|
clickOutsideSource,
|
|
@@ -73,12 +73,8 @@ var clipboardSchema = {
|
|
|
73
73
|
source: `
|
|
74
74
|
behavior Clipboard(text, source, feedback, feedbackDuration)
|
|
75
75
|
init
|
|
76
|
-
if feedbackDuration is undefined
|
|
77
|
-
|
|
78
|
-
end
|
|
79
|
-
if source is undefined
|
|
80
|
-
set source to me
|
|
81
|
-
end
|
|
76
|
+
if feedbackDuration is undefined set element's feedbackDuration to 2000 end
|
|
77
|
+
if source is undefined set element's source to me end
|
|
82
78
|
end
|
|
83
79
|
on click
|
|
84
80
|
if text is not undefined
|
|
@@ -122,25 +118,28 @@ end`.trim()
|
|
|
122
118
|
function resolveRuntime() {
|
|
123
119
|
if (typeof window === "undefined") return null;
|
|
124
120
|
const win = window;
|
|
125
|
-
|
|
121
|
+
const host = win.hyperfixi ?? win._hyperscript;
|
|
122
|
+
return host && typeof host.evaluate === "function" ? host : null;
|
|
126
123
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
var clipboardSource = clipboardSchema.source;
|
|
130
|
-
var clipboardMetadata = clipboardSchema;
|
|
131
|
-
async function registerClipboard(hyperfixi) {
|
|
132
|
-
const hf = hyperfixi || resolveRuntime();
|
|
124
|
+
function defineBehavior(schema, host) {
|
|
125
|
+
const hf = host ?? resolveRuntime();
|
|
133
126
|
if (!hf) {
|
|
134
127
|
throw new Error(
|
|
135
|
-
|
|
128
|
+
`No hyperscript host found: load @hyperfixi/engine (hyperfixi-hs.js) before defining ${schema.name}.`
|
|
136
129
|
);
|
|
137
130
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
131
|
+
try {
|
|
132
|
+
hf.evaluate(schema.source);
|
|
133
|
+
} catch (e) {
|
|
134
|
+
throw new Error(`Failed to define ${schema.name} behavior: ${e.message}`);
|
|
141
135
|
}
|
|
142
|
-
|
|
143
|
-
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// src/behaviors/clipboard.ts
|
|
139
|
+
var clipboardSource = clipboardSchema.source;
|
|
140
|
+
var clipboardMetadata = clipboardSchema;
|
|
141
|
+
async function registerClipboard(host) {
|
|
142
|
+
defineBehavior(clipboardSchema, host);
|
|
144
143
|
}
|
|
145
144
|
if (resolveRuntime()) {
|
|
146
145
|
registerClipboard().catch(console.error);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/behaviors/clipboard.ts","../../src/schemas/clipboard.schema.ts","../../src/schemas/types.ts"],"sourcesContent":["/**\n * Clipboard Behavior\n *\n * Copies text to clipboard on click with visual feedback.\n * Uses navigator.clipboard.writeText() with execCommand fallback (in its\n * hyperscript `source`'s js() body).\n *\n * Compiled from its hyperscript `source` (the single source of truth shared with\n * the CDN resolver bundle and patterns-reference).\n */\n\nimport { clipboardSchema } from '../schemas/clipboard.schema';\nimport type { LokaScriptInstance } from '../schemas/types';\nimport { resolveRuntime } from '../schemas/types';\n\n// Re-export schema-derived values\nexport const clipboardSource = clipboardSchema.source;\nexport const clipboardMetadata = clipboardSchema;\n\n/**\n * Register the Clipboard behavior with LokaScript by compiling its\n * hyperscript source and executing the resulting behavior definition.\n */\nexport async function registerClipboard(hyperfixi?: LokaScriptInstance): Promise<void> {\n const hf = hyperfixi || resolveRuntime();\n\n if (!hf) {\n throw new Error(\n 'LokaScript not found. Make sure @hyperfixi/core is loaded before registering behaviors.'\n );\n }\n\n const result = hf.compileSync(clipboardSchema.source, { traditional: true });\n\n if (!result.ok) {\n throw new Error(`Failed to compile Clipboard behavior: ${JSON.stringify(result.errors)}`);\n }\n\n const ctx = hf.createContext ? hf.createContext() : { locals: new Map(), globals: new Map() };\n await hf.execute(result.ast, ctx);\n}\n\n// Auto-register when loaded as a script tag\nif (resolveRuntime()) {\n registerClipboard().catch(console.error);\n}\n\nexport default {\n source: clipboardSchema.source,\n metadata: clipboardSchema,\n register: registerClipboard,\n};\n","import type { BehaviorSchema } from './types';\n\n/**\n * Clipboard Behavior Schema\n *\n * Copies text to clipboard on click with visual feedback.\n * Uses the Clipboard API with execCommand fallback.\n */\nexport const clipboardSchema: BehaviorSchema = {\n name: 'Clipboard',\n category: 'ui',\n tier: 'core',\n version: '1.0.0',\n description: 'Copies text to clipboard on click with visual feedback',\n parameters: [\n {\n name: 'text',\n type: 'string',\n optional: true,\n description: 'Literal text to copy (takes priority over source)',\n },\n {\n name: 'source',\n type: 'selector',\n optional: true,\n default: 'me',\n description: 'Element whose textContent or value is copied',\n },\n {\n name: 'feedback',\n type: 'selector',\n optional: true,\n description: 'Element to show .copied feedback on (defaults to the installed element)',\n },\n {\n name: 'feedbackDuration',\n type: 'number',\n optional: true,\n default: 2000,\n description: 'Duration in ms to show .copied class feedback',\n },\n ],\n events: [\n { name: 'clipboard:copied', description: 'Fired after text is copied successfully' },\n { name: 'clipboard:error', description: 'Fired when clipboard write fails' },\n ],\n requirements: [\n 'navigator.clipboard.writeText() requires HTTPS or localhost',\n 'Falls back to document.execCommand(\"copy\") for older browsers',\n ],\n source: `\nbehavior Clipboard(text, source, feedback, feedbackDuration)\n init\n if feedbackDuration is undefined\n set feedbackDuration to 2000\n end\n if source is undefined\n set source to me\n end\n end\n on click\n if text is not undefined\n set copyText to text\n else\n set copyText to source's textContent\n end\n js(me, copyText, feedback, feedbackDuration)\n // Wrapped in an async IIFE: hyperscript's js() block has no top-level await.\n (async function() {\n async function copyToClipboard(t) {\n if (navigator.clipboard && navigator.clipboard.writeText) {\n await navigator.clipboard.writeText(t);\n return;\n }\n var ta = document.createElement('textarea');\n ta.value = t;\n ta.style.position = 'fixed';\n ta.style.opacity = '0';\n document.body.appendChild(ta);\n ta.select();\n try { document.execCommand('copy'); } finally { document.body.removeChild(ta); }\n }\n try {\n await copyToClipboard(copyText);\n var feedbackEl = feedback ? (typeof feedback === 'string' ? document.querySelector(feedback) : feedback) : me;\n if (!feedbackEl) feedbackEl = me;\n feedbackEl.classList.add('copied');\n me.dispatchEvent(new CustomEvent('clipboard:copied', { bubbles: true, detail: { text: copyText } }));\n setTimeout(function() { feedbackEl.classList.remove('copied'); }, feedbackDuration);\n } catch(err) {\n me.dispatchEvent(new CustomEvent('clipboard:error', { bubbles: true, detail: { error: err } }));\n }\n })();\n end\n end\nend`.trim(),\n};\n","/**\n * Behavior Schema Types\n *\n * Defines the structure for behavior metadata used for:\n * - Code generation (TypeScript types, documentation)\n * - Runtime categorization and lazy loading\n * - Tooling and IDE integration\n */\n\n/**\n * Behavior categories for organization.\n * - ui: Visual interaction behaviors (drag, resize, sort)\n * - data: Data manipulation behaviors (remove, transform)\n * - animation: Animation and transition behaviors\n * - form: Form-related behaviors (validation, toggle states)\n * - layout: Layout behaviors (sticky, scrollspy)\n */\nexport type BehaviorCategory = 'ui' | 'data' | 'animation' | 'form' | 'layout';\n\n/**\n * Loading tiers for lazy loading optimization.\n * - core: Always loaded (essential behaviors)\n * - common: High usage (loaded for typical apps)\n * - optional: Low usage (loaded on demand)\n */\nexport type BehaviorTier = 'core' | 'common' | 'optional';\n\n/**\n * Schema for a behavior parameter.\n */\nexport interface ParameterSchema {\n name: string;\n type: 'string' | 'number' | 'boolean' | 'selector' | 'element';\n optional?: boolean;\n default?: string | number | boolean;\n /** Allowed values for constrained parameters */\n enum?: string[];\n description: string;\n}\n\n/**\n * Schema for a behavior event.\n */\nexport interface EventSchema {\n name: string;\n description: string;\n}\n\n/**\n * Complete schema for a behavior.\n * This is the source of truth for all behavior metadata.\n */\nexport interface BehaviorSchema {\n /** Behavior name (PascalCase) */\n name: string;\n /** Category for organization */\n category: BehaviorCategory;\n /** Loading tier for lazy loading */\n tier: BehaviorTier;\n /** Semantic version */\n version: string;\n /** Human-readable description */\n description: string;\n /** Parameter definitions */\n parameters: ParameterSchema[];\n /** Event definitions */\n events: EventSchema[];\n /** The hyperscript behavior source code */\n source: string;\n /** Optional requirements or notes */\n requirements?: string[];\n}\n\n/**\n * Runtime behavior module interface.\n * This is what gets registered with the hyperfixi runtime.\n */\nexport interface BehaviorModule {\n source: string;\n metadata: BehaviorSchema;\n register: (hyperfixi?: LokaScriptInstance) => Promise<void>;\n}\n\n/**\n * Minimal LokaScript instance interface for behavior registration.\n */\nexport interface LokaScriptInstance {\n compileSync: (\n code: string,\n options?: { traditional?: boolean; language?: string }\n ) => {\n ok: boolean;\n ast?: unknown;\n errors?: Array<{ message: string; line?: number; column?: number }>;\n };\n execute: (ast: unknown, ctx: unknown) => Promise<unknown>;\n createContext?: () => { locals: Map<string, unknown>; globals: Map<string, unknown> };\n}\n\n/**\n * Typed window interface for behavior auto-registration.\n * Avoids `(window as any)` casts throughout the codebase.\n * Checks both `window.lokascript` and `window.hyperfixi` for the runtime instance.\n */\nexport interface LokaScriptWindow {\n lokascript?: LokaScriptInstance;\n hyperfixi?: LokaScriptInstance;\n __hyperfixi_behaviors_ready?: Promise<void> | undefined;\n}\n\n/**\n * Resolve the LokaScript runtime from window globals.\n * Checks both `window.lokascript` and `window.hyperfixi`.\n */\nexport function resolveRuntime(): LokaScriptInstance | null {\n if (typeof window === 'undefined') return null;\n const win = window as unknown as LokaScriptWindow;\n return win.lokascript || win.hyperfixi || null;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACQO,IAAM,kBAAkC;AAAA,EAC7C,MAAM;AAAA,EACN,UAAU;AAAA,EACV,MAAM;AAAA,EACN,SAAS;AAAA,EACT,aAAa;AAAA,EACb,YAAY;AAAA,IACV;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA,MACN,UAAU;AAAA,MACV,aAAa;AAAA,IACf;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA,MACN,UAAU;AAAA,MACV,SAAS;AAAA,MACT,aAAa;AAAA,IACf;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA,MACN,UAAU;AAAA,MACV,aAAa;AAAA,IACf;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA,MACN,UAAU;AAAA,MACV,SAAS;AAAA,MACT,aAAa;AAAA,IACf;AAAA,EACF;AAAA,EACA,QAAQ;AAAA,IACN,EAAE,MAAM,oBAAoB,aAAa,0CAA0C;AAAA,IACnF,EAAE,MAAM,mBAAmB,aAAa,mCAAmC;AAAA,EAC7E;AAAA,EACA,cAAc;AAAA,IACZ;AAAA,IACA;AAAA,EACF;AAAA,EACA,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,KA6CL,KAAK;AACV;;;ACkBO,SAAS,iBAA4C;AAC1D,MAAI,OAAO,WAAW,YAAa,QAAO;AAC1C,QAAM,MAAM;AACZ,SAAO,IAAI,cAAc,IAAI,aAAa;AAC5C;;;AFtGO,IAAM,kBAAkB,gBAAgB;AACxC,IAAM,oBAAoB;AAMjC,eAAsB,kBAAkB,WAA+C;AACrF,QAAM,KAAK,aAAa,eAAe;AAEvC,MAAI,CAAC,IAAI;AACP,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,QAAM,SAAS,GAAG,YAAY,gBAAgB,QAAQ,EAAE,aAAa,KAAK,CAAC;AAE3E,MAAI,CAAC,OAAO,IAAI;AACd,UAAM,IAAI,MAAM,yCAAyC,KAAK,UAAU,OAAO,MAAM,CAAC,EAAE;AAAA,EAC1F;AAEA,QAAM,MAAM,GAAG,gBAAgB,GAAG,cAAc,IAAI,EAAE,QAAQ,oBAAI,IAAI,GAAG,SAAS,oBAAI,IAAI,EAAE;AAC5F,QAAM,GAAG,QAAQ,OAAO,KAAK,GAAG;AAClC;AAGA,IAAI,eAAe,GAAG;AACpB,oBAAkB,EAAE,MAAM,QAAQ,KAAK;AACzC;AAEA,IAAO,oBAAQ;AAAA,EACb,QAAQ,gBAAgB;AAAA,EACxB,UAAU;AAAA,EACV,UAAU;AACZ;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/behaviors/clipboard.ts","../../src/schemas/clipboard.schema.ts","../../src/schemas/types.ts"],"sourcesContent":["/**\n * Clipboard Behavior\n *\n * Copies text to clipboard on click with visual feedback.\n * Uses navigator.clipboard.writeText() with execCommand fallback (in its\n * hyperscript `source`'s js() body).\n *\n * Defined from its hyperscript `source` (the single source of truth shared with\n * the browser bundle and patterns-reference).\n */\n\nimport { clipboardSchema } from '../schemas/clipboard.schema';\nimport { defineBehavior, resolveRuntime } from '../schemas/types';\nimport type { HyperscriptHost } from '../schemas/types';\n\n// Re-export schema-derived values\nexport const clipboardSource = clipboardSchema.source;\nexport const clipboardMetadata = clipboardSchema;\n\n/**\n * Define the Clipboard behavior on a hyperscript host (`window.hyperfixi` when none is given)\n * from its source, as a `<script type=\"text/hyperscript\">` would.\n */\nexport async function registerClipboard(host?: HyperscriptHost): Promise<void> {\n defineBehavior(clipboardSchema, host);\n}\n\n// Auto-register when loaded as a script tag\nif (resolveRuntime()) {\n registerClipboard().catch(console.error);\n}\n\nexport default {\n source: clipboardSchema.source,\n metadata: clipboardSchema,\n register: registerClipboard,\n};\n","import type { BehaviorSchema } from './types';\n\n/**\n * Clipboard Behavior Schema\n *\n * Copies text to clipboard on click with visual feedback.\n * Uses the Clipboard API with execCommand fallback.\n */\nexport const clipboardSchema: BehaviorSchema = {\n name: 'Clipboard',\n category: 'ui',\n tier: 'core',\n version: '1.0.0',\n description: 'Copies text to clipboard on click with visual feedback',\n parameters: [\n {\n name: 'text',\n type: 'string',\n optional: true,\n description: 'Literal text to copy (takes priority over source)',\n },\n {\n name: 'source',\n type: 'selector',\n optional: true,\n default: 'me',\n description: 'Element whose textContent or value is copied',\n },\n {\n name: 'feedback',\n type: 'selector',\n optional: true,\n description: 'Element to show .copied feedback on (defaults to the installed element)',\n },\n {\n name: 'feedbackDuration',\n type: 'number',\n optional: true,\n default: 2000,\n description: 'Duration in ms to show .copied class feedback',\n },\n ],\n events: [\n { name: 'clipboard:copied', description: 'Fired after text is copied successfully' },\n { name: 'clipboard:error', description: 'Fired when clipboard write fails' },\n ],\n requirements: [\n 'navigator.clipboard.writeText() requires HTTPS or localhost',\n 'Falls back to document.execCommand(\"copy\") for older browsers',\n ],\n source: `\nbehavior Clipboard(text, source, feedback, feedbackDuration)\n init\n if feedbackDuration is undefined set element's feedbackDuration to 2000 end\n if source is undefined set element's source to me end\n end\n on click\n if text is not undefined\n set copyText to text\n else\n set copyText to source's textContent\n end\n js(me, copyText, feedback, feedbackDuration)\n // Wrapped in an async IIFE: hyperscript's js() block has no top-level await.\n (async function() {\n async function copyToClipboard(t) {\n if (navigator.clipboard && navigator.clipboard.writeText) {\n await navigator.clipboard.writeText(t);\n return;\n }\n var ta = document.createElement('textarea');\n ta.value = t;\n ta.style.position = 'fixed';\n ta.style.opacity = '0';\n document.body.appendChild(ta);\n ta.select();\n try { document.execCommand('copy'); } finally { document.body.removeChild(ta); }\n }\n try {\n await copyToClipboard(copyText);\n var feedbackEl = feedback ? (typeof feedback === 'string' ? document.querySelector(feedback) : feedback) : me;\n if (!feedbackEl) feedbackEl = me;\n feedbackEl.classList.add('copied');\n me.dispatchEvent(new CustomEvent('clipboard:copied', { bubbles: true, detail: { text: copyText } }));\n setTimeout(function() { feedbackEl.classList.remove('copied'); }, feedbackDuration);\n } catch(err) {\n me.dispatchEvent(new CustomEvent('clipboard:error', { bubbles: true, detail: { error: err } }));\n }\n })();\n end\n end\nend`.trim(),\n};\n","/**\n * Behavior Schema Types\n *\n * Defines the structure for behavior metadata used for:\n * - Code generation (TypeScript types, documentation)\n * - Runtime categorization and lazy loading\n * - Tooling and IDE integration\n */\n\n/**\n * Behavior categories for organization.\n * - ui: Visual interaction behaviors (drag, resize, sort)\n * - data: Data manipulation behaviors (remove, transform)\n * - animation: Animation and transition behaviors\n * - form: Form-related behaviors (validation, toggle states)\n * - layout: Layout behaviors (sticky, scrollspy)\n */\nexport type BehaviorCategory = 'ui' | 'data' | 'animation' | 'form' | 'layout';\n\n/**\n * Loading tiers for lazy loading optimization.\n * - core: Always loaded (essential behaviors)\n * - common: High usage (loaded for typical apps)\n * - optional: Low usage (loaded on demand)\n */\nexport type BehaviorTier = 'core' | 'common' | 'optional';\n\n/**\n * Schema for a behavior parameter.\n */\nexport interface ParameterSchema {\n name: string;\n type: 'string' | 'number' | 'boolean' | 'selector' | 'element';\n optional?: boolean;\n default?: string | number | boolean;\n /** Allowed values for constrained parameters */\n enum?: string[];\n description: string;\n}\n\n/**\n * Schema for a behavior event.\n */\nexport interface EventSchema {\n name: string;\n description: string;\n}\n\n/**\n * Complete schema for a behavior.\n * This is the source of truth for all behavior metadata.\n */\nexport interface BehaviorSchema {\n /** Behavior name (PascalCase) */\n name: string;\n /** Category for organization */\n category: BehaviorCategory;\n /** Loading tier for lazy loading */\n tier: BehaviorTier;\n /** Semantic version */\n version: string;\n /** Human-readable description */\n description: string;\n /** Parameter definitions */\n parameters: ParameterSchema[];\n /** Event definitions */\n events: EventSchema[];\n /** The hyperscript behavior source code */\n source: string;\n /** Optional requirements or notes */\n requirements?: string[];\n}\n\n/**\n * Runtime behavior module interface: a behavior's source, its schema, and the function that\n * defines it on a hyperscript host.\n */\nexport interface BehaviorModule {\n source: string;\n metadata: BehaviorSchema;\n register: (host?: HyperscriptHost) => Promise<void>;\n}\n\n/**\n * A hyperscript host, in upstream `_hyperscript`'s shape: `@hyperfixi/engine` (the\n * `hyperfixi-hs.js` bundle, `window.hyperfixi` / `window._hyperscript`) or upstream itself.\n * `evaluate(source)` of a `behavior … end` program defines the behavior; `processNode`\n * initialises the scripted elements under a node.\n */\nexport interface HyperscriptHost {\n evaluate: (source: string) => unknown;\n processNode?: (node: Node) => void;\n}\n\n/** The window globals a host installs itself as. */\nexport interface HyperscriptWindow {\n hyperfixi?: HyperscriptHost;\n _hyperscript?: HyperscriptHost;\n}\n\n/** The host on `window`: `hyperfixi` (the engine's bundle) or `_hyperscript` (upstream's name). */\nexport function resolveRuntime(): HyperscriptHost | null {\n if (typeof window === 'undefined') return null;\n const win = window as unknown as HyperscriptWindow;\n const host = win.hyperfixi ?? win._hyperscript;\n return host && typeof host.evaluate === 'function' ? host : null;\n}\n\n/**\n * Define a behavior on a host from its schema's source, as a page's\n * `<script type=\"text/hyperscript\">` would. Throws when there is no host or the source\n * does not parse.\n */\nexport function defineBehavior(schema: BehaviorSchema, host?: HyperscriptHost): void {\n const hf = host ?? resolveRuntime();\n if (!hf) {\n throw new Error(\n `No hyperscript host found: load @hyperfixi/engine (hyperfixi-hs.js) before defining ${schema.name}.`\n );\n }\n try {\n hf.evaluate(schema.source);\n } catch (e) {\n throw new Error(`Failed to define ${schema.name} behavior: ${(e as Error).message}`);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACQO,IAAM,kBAAkC;AAAA,EAC7C,MAAM;AAAA,EACN,UAAU;AAAA,EACV,MAAM;AAAA,EACN,SAAS;AAAA,EACT,aAAa;AAAA,EACb,YAAY;AAAA,IACV;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA,MACN,UAAU;AAAA,MACV,aAAa;AAAA,IACf;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA,MACN,UAAU;AAAA,MACV,SAAS;AAAA,MACT,aAAa;AAAA,IACf;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA,MACN,UAAU;AAAA,MACV,aAAa;AAAA,IACf;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA,MACN,UAAU;AAAA,MACV,SAAS;AAAA,MACT,aAAa;AAAA,IACf;AAAA,EACF;AAAA,EACA,QAAQ;AAAA,IACN,EAAE,MAAM,oBAAoB,aAAa,0CAA0C;AAAA,IACnF,EAAE,MAAM,mBAAmB,aAAa,mCAAmC;AAAA,EAC7E;AAAA,EACA,cAAc;AAAA,IACZ;AAAA,IACA;AAAA,EACF;AAAA,EACA,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,KAyCL,KAAK;AACV;;;ACSO,SAAS,iBAAyC;AACvD,MAAI,OAAO,WAAW,YAAa,QAAO;AAC1C,QAAM,MAAM;AACZ,QAAM,OAAO,IAAI,aAAa,IAAI;AAClC,SAAO,QAAQ,OAAO,KAAK,aAAa,aAAa,OAAO;AAC9D;AAOO,SAAS,eAAe,QAAwB,MAA8B;AACnF,QAAM,KAAK,QAAQ,eAAe;AAClC,MAAI,CAAC,IAAI;AACP,UAAM,IAAI;AAAA,MACR,uFAAuF,OAAO,IAAI;AAAA,IACpG;AAAA,EACF;AACA,MAAI;AACF,OAAG,SAAS,OAAO,MAAM;AAAA,EAC3B,SAAS,GAAG;AACV,UAAM,IAAI,MAAM,oBAAoB,OAAO,IAAI,cAAe,EAAY,OAAO,EAAE;AAAA,EACrF;AACF;;;AF7GO,IAAM,kBAAkB,gBAAgB;AACxC,IAAM,oBAAoB;AAMjC,eAAsB,kBAAkB,MAAuC;AAC7E,iBAAe,iBAAiB,IAAI;AACtC;AAGA,IAAI,eAAe,GAAG;AACpB,oBAAkB,EAAE,MAAM,QAAQ,KAAK;AACzC;AAEA,IAAO,oBAAQ;AAAA,EACb,QAAQ,gBAAgB;AAAA,EACxB,UAAU;AAAA,EACV,UAAU;AACZ;","names":[]}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { B as BehaviorSchema,
|
|
1
|
+
import { B as BehaviorSchema, H as HyperscriptHost } from '../types-CbA4L8XJ.cjs';
|
|
2
2
|
|
|
3
3
|
declare const clipboardSource: string;
|
|
4
4
|
declare const clipboardMetadata: BehaviorSchema;
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
* Define the Clipboard behavior on a hyperscript host (`window.hyperfixi` when none is given)
|
|
7
|
+
* from its source, as a `<script type="text/hyperscript">` would.
|
|
8
8
|
*/
|
|
9
|
-
declare function registerClipboard(
|
|
9
|
+
declare function registerClipboard(host?: HyperscriptHost): Promise<void>;
|
|
10
10
|
declare const _default: {
|
|
11
11
|
source: string;
|
|
12
12
|
metadata: BehaviorSchema;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { B as BehaviorSchema,
|
|
1
|
+
import { B as BehaviorSchema, H as HyperscriptHost } from '../types-CbA4L8XJ.js';
|
|
2
2
|
|
|
3
3
|
declare const clipboardSource: string;
|
|
4
4
|
declare const clipboardMetadata: BehaviorSchema;
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
* Define the Clipboard behavior on a hyperscript host (`window.hyperfixi` when none is given)
|
|
7
|
+
* from its source, as a `<script type="text/hyperscript">` would.
|
|
8
8
|
*/
|
|
9
|
-
declare function registerClipboard(
|
|
9
|
+
declare function registerClipboard(host?: HyperscriptHost): Promise<void>;
|
|
10
10
|
declare const _default: {
|
|
11
11
|
source: string;
|
|
12
12
|
metadata: BehaviorSchema;
|
|
@@ -3,9 +3,9 @@ import {
|
|
|
3
3
|
clipboardSource,
|
|
4
4
|
clipboard_default,
|
|
5
5
|
registerClipboard
|
|
6
|
-
} from "../chunk-
|
|
7
|
-
import "../chunk-
|
|
8
|
-
import "../chunk-
|
|
6
|
+
} from "../chunk-HHTEMPIT.js";
|
|
7
|
+
import "../chunk-KYBOZ7C4.js";
|
|
8
|
+
import "../chunk-VWDTOSE3.js";
|
|
9
9
|
export {
|
|
10
10
|
clipboardMetadata,
|
|
11
11
|
clipboardSource,
|