mcard-studio 0.0.2 → 0.0.3
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/README.md +3 -0
- package/astro.config.mjs +41 -2
- package/cli/lib/runtimeContext.mjs +6 -3
- package/dist/client/_astro/{ChartAnalyticsViewlet.jrwIemvb.js → ChartAnalyticsViewlet.CBW-JyA3.js} +1 -1
- package/dist/client/_astro/{ClmPcardViewlet.C-fU7oZf.js → ClmPcardViewlet.cvKsR2ng.js} +2 -2
- package/dist/client/_astro/{D3GraphViewlet.BCZl0b2U.js → D3GraphViewlet.8YEIrCGL.js} +1 -1
- package/dist/client/_astro/DockviewSpatialWorkbench.BTd66LPl.js +12 -0
- package/dist/client/_astro/DocumentViewlets.KY1HcNka.js +2 -0
- package/dist/client/_astro/DxfViewlet.B3N5zpZR.js +1 -0
- package/dist/client/_astro/{ExcalidrawWhiteboardViewlet.CFpPYSdn.js → ExcalidrawWhiteboardViewlet.CMJGCQN4.js} +1 -1
- package/dist/client/_astro/{FaroVCardSpanInstrumenter.un8kDMWv.js → FaroVCardSpanInstrumenter.ClIqZujq.js} +1 -1
- package/dist/client/_astro/{FontSpecimenViewlet.D7Aw2xBZ.js → FontSpecimenViewlet.ChIyr0B8.js} +1 -1
- package/dist/client/_astro/HeadMeta.astro_astro_type_script_index_0_lang.D3FSc061.js +1 -0
- package/dist/client/_astro/{ImageViewlet.D4FN87n_.js → ImageViewlet.Cs-u7-wt.js} +1 -1
- package/dist/client/_astro/{KatexFormulaViewlet.CzhdIOw8.js → KatexFormulaViewlet.0nOzV_qD.js} +1 -1
- package/dist/client/_astro/{KoishiChatViewlet.5mepQvLX.js → KoishiChatViewlet.DLsMmwdb.js} +4 -4
- package/dist/client/_astro/{MCardLibraryHarness.DE8KeghO.js → MCardLibraryHarness.WBT9W10S.js} +1 -1
- package/dist/client/_astro/{MarkdownViewlet.CRuuXXmF.js → MarkdownViewlet.BIolkNXf.js} +25 -25
- package/dist/client/_astro/{MermaidDiagramViewlet.eW6sk-rF.js → MermaidDiagramViewlet.CkRk7QsS.js} +1 -1
- package/dist/client/_astro/PCardRendererBridge.DhaRSprd.js +1 -0
- package/dist/client/_astro/RendererPCardRegistry.brM2KiQs.js +1 -0
- package/dist/client/_astro/{SchemaYamlViewlet.ZJBvxItR.js → SchemaYamlViewlet.Bc7nkK4M.js} +1 -1
- package/dist/client/_astro/{ShellContainer.astro_astro_type_script_index_0_lang.j_ELcN5d.js → ShellContainer.astro_astro_type_script_index_0_lang.5q1gCLvf.js} +1 -1
- package/dist/client/_astro/{Spatial3dViewlet.DnVMBENJ.js → Spatial3dViewlet.C-jjhr0A.js} +1 -1
- package/dist/client/_astro/{StudioLayout.CBgiVbeb.css → StudioLayout.CX8XGtZV.css} +1 -1
- package/dist/client/_astro/StudioWorkbench.B1QwGHWM.js +7 -0
- package/dist/client/_astro/{SvgViewlet.BCje7Qqb.js → SvgViewlet.uGxvb06H.js} +1 -1
- package/dist/client/_astro/{TerminalView.C_Ksz6lT.js → TerminalView.DP7G7E1m.js} +1 -1
- package/dist/client/_astro/{ThemeSettingsViewlet.DJpjQQ0Z.js → ThemeSettingsViewlet.UaTHcGnF.js} +1 -1
- package/dist/client/_astro/{TikzDiagramViewlet.CXb1A8nf.js → TikzDiagramViewlet.O8MJyXfT.js} +1 -1
- package/dist/client/_astro/VideoPlayerViewlet.-ycmo3kY.js +1 -0
- package/dist/client/_astro/WebappZenViewlet.PNce4u2T.js +1 -0
- package/dist/client/_astro/{WelcomeViewport.BiYwLh6l.js → WelcomeViewport.CZ6RxGSw.js} +1 -1
- package/dist/client/_astro/{agentIdentityCredentialService.UzMMwBwv.js → agentIdentityCredentialService.BEtZzBlO.js} +1 -1
- package/dist/client/_astro/cardTypeDetector.C2HH5RnU.js +1 -0
- package/dist/client/_astro/disposable.BmlxZrDf.js +1 -0
- package/dist/client/_astro/{markdownService.BgWjyJ57.js → markdownService.CpuKl0vp.js} +1 -1
- package/dist/client/_astro/{mcardStore.CT-ollfl.js → mcardStore.nSWnzeLg.js} +1 -1
- package/dist/client/_astro/mcardVfs.BSdys1Y7.js +3 -0
- package/dist/client/_astro/pathsConfig.CSBBSzwH.js +2 -0
- package/dist/client/_astro/{polyfills._3wYPjZf.js → polyfills.Bi7kO8cu.js} +1 -1
- package/dist/client/_astro/rendererEventBus.DirFDmGw.js +1 -0
- package/dist/client/_astro/themeStore.BajxvCga.js +1 -0
- package/dist/client/_astro/{tikzCompiler.fe3qomFY.js → tikzCompiler.-fXMNQpz.js} +1 -1
- package/dist/client/_astro/{useMCardHydration.7Z-HfBh5.js → useMCardHydration.Bjj_N5Gv.js} +1 -1
- package/dist/client/_astro/vendor-clm-kernel.B0kxq3g4.js +108 -0
- package/dist/client/_astro/{vfsHandles.IX_wTpw_.js → vfsHandles.D4Pq18pW.js} +1 -1
- package/dist/client/_astro/vfsPersistence.DVrd1BZj.js +1 -0
- package/dist/client/_astro/{vfsTransactions.C_IQQg0s.js → vfsTransactions.DBNtFuRz.js} +1 -1
- package/dist/client/_astro/{workspaceStore.CD0kAVAl.js → workspaceStore.DUHW2YBc.js} +1 -1
- package/dist/server/chunks/{_.._5gPhVOLM.mjs → _.._CoQKwo62.mjs} +137 -91
- package/dist/server/chunks/{_handle__D_cIJYrU.mjs → _handle__D8dKQPUS.mjs} +3 -3
- package/dist/server/chunks/{cardTypeDetector_CyW1Xnmy.mjs → cardTypeDetector_C55M_HWS.mjs} +9 -0
- package/dist/server/chunks/{cards_B89BvF6W.mjs → cards_rVOc8K6H.mjs} +2 -2
- package/dist/server/chunks/cas_DTxlZ4Le.mjs +68 -0
- package/dist/server/chunks/{dispatch_DOwSKukU.mjs → dispatch_BTW4E_BJ.mjs} +8 -7
- package/dist/server/chunks/{dispatch_CxWKiHpn.mjs → dispatch_MbkljUxD.mjs} +8 -8
- package/dist/server/chunks/{export_DRouradA.mjs → export_DkEwDE2T.mjs} +3 -3
- package/dist/server/chunks/{health_Dfa5I0-X.mjs → health_cRt0M0yu.mjs} +1 -1
- package/dist/server/chunks/{mcard-library_7Wzoihkm.mjs → mcard-library_CLHvyslV.mjs} +1 -1
- package/dist/server/chunks/{mcardVfs_CeezzRvt.mjs → mcardVfs_DvNburKb.mjs} +5 -30
- package/dist/server/chunks/{move__RFvIDkq.mjs → move_DYcaXBLV.mjs} +6 -6
- package/dist/server/chunks/{pathsConfig_CgNYYLVm.mjs → pathsConfig_Dack-p2f.mjs} +13 -3
- package/dist/server/chunks/{proxy_CrWJQIBe.mjs → proxy_CMbbdBPW.mjs} +2 -2
- package/dist/server/chunks/{raw_DzNDaDVP.mjs → raw_C97sJWhg.mjs} +59 -26
- package/dist/server/chunks/{serverBootstrap_XKo2s6Ha.mjs → serverBootstrap_BDdSRIu5.mjs} +2 -2
- package/dist/server/chunks/tree_BwmO-pTe.mjs +186 -0
- package/dist/server/chunks/vfsCore_DIKpk-pk.mjs +98 -0
- package/dist/server/chunks/{vfsTreeScan_CKp7kMt9.mjs → vfsTreeScan_CRoCluPB.mjs} +18 -10
- package/dist/server/chunks/workspaceRoot_CRx3taID.mjs +157 -0
- package/dist/server/chunks/{write_popiFsO7.mjs → write_BLsmsTIx.mjs} +6 -5
- package/dist/server/chunks/{ws-server-init_DUjuR2-o.mjs → ws-server-init_Cfft7U5u.mjs} +343 -298
- package/dist/server/entry.mjs +1 -1
- package/dist/server/entry2.mjs +67 -28
- package/dist/server/virtual_astro_middleware.mjs +2 -2
- package/package.json +2 -2
- package/src/components/studio/views/cardViewlets/ClmRegistryComponentViewlet.tsx +133 -0
- package/src/components/studio/views/cardViewlets/DxfViewlet.tsx +230 -0
- package/src/components/studio/views/cardViewlets/VideoPlayerViewlet.tsx +4 -4
- package/src/components/studio/views/cardViewlets/coreViewletDefs.ts +2 -2
- package/src/components/studio/views/cardViewlets/documents/AudioPlayerViewlet.tsx +15 -3
- package/src/components/studio/views/cardViewlets/documents/PdfViewlet.tsx +25 -7
- package/src/components/studio/views/cardViewlets/markdown/stages/wikilinkStage.ts +2 -1
- package/src/components/studio/views/cardViewlets/mediaViewletDefs.ts +21 -1
- package/src/components/studio/views/cardViewlets/webapp/WebappCanvas.tsx +40 -15
- package/src/components/studio/views/cardViewlets/webapp/WebappDevicePresetBar.tsx +108 -0
- package/src/components/studio/views/cardViewlets/webapp/WebappZenViewlet.tsx +23 -30
- package/src/components/studio/views/fileTree/MCardFileTree.tsx +71 -54
- package/src/components/studio/views/fileTree/hooks/useFileTreeSync.ts +0 -1
- package/src/components/studio/views/fileTree/hooks/usePartitionedTrees.ts +68 -23
- package/src/components/studio/views/fileTree/hooks/useSectionAccordion.ts +21 -11
- package/src/components/studio/views/functions/UnifiedFunctionExplorerViewlet.tsx +168 -0
- package/src/components/studio/views/history/HistoryPanel.tsx +110 -0
- package/src/components/studio/views/lineage/LineagePanel.tsx +152 -0
- package/src/components/studio/views/navigation/HandleLineageDrawer.tsx +89 -0
- package/src/components/studio/views/navigation/MultiCardCollectionBrowser.tsx +154 -0
- package/src/components/studio/views/pills/HashPill.tsx +101 -0
- package/src/components/studio/views/residency/ResidencyIndicator.tsx +82 -0
- package/src/config/app_config.json +3 -3
- package/src/core/projection/catalog.ts +105 -0
- package/src/core/projection/collection.ts +148 -0
- package/src/core/projection/handleSubscription.ts +132 -0
- package/src/core/projection/index.ts +4 -0
- package/src/core/projection/selectors.ts +29 -0
- package/src/core/projection/views.ts +242 -0
- package/src/core/refinement/designMetrics.ts +104 -0
- package/src/core/refinement/fibrationProjector.ts +142 -0
- package/src/core/refinement/lagrangianEngine.ts +137 -0
- package/src/core/refinement/refinementCommands.ts +82 -0
- package/src/core/viewport/deviceArchetypeRegistry.ts +177 -0
- package/src/core/viewport/viewportAudit.ts +150 -0
- package/src/edge/storeFilter.d.ts +4 -0
- package/src/edge/storeFilter.js +54 -0
- package/src/edge/storeFilter.ts +52 -0
- package/src/lib/cryptoPolyfill.js +77 -1
- package/src/lib/fsPolyfill.js +65 -0
- package/src/lib/urlPolyfill.js +21 -0
- package/src/lib/zlibPolyfill.js +35 -0
- package/src/packages/mcard-studio/package.json +2 -2
- package/src/packages/mcard-studio/type/legacyMapping.ts +5 -0
- package/src/packages/mcard-studio/viewlets/manifests.ts +2 -0
- package/src/packages/mcard-studio/viewlets/moduleMap.ts +12 -0
- package/src/packages/mcard-studio/viewlets/refinementManifests.ts +114 -0
- package/src/pages/api/dispatch.ts +3 -2
- package/src/pages/api/vfs/cas.ts +114 -0
- package/src/pages/api/vfs/move.ts +5 -5
- package/src/pages/api/vfs/raw.ts +72 -27
- package/src/pages/api/vfs/tree.ts +130 -11
- package/src/pages/api/vfs/write.ts +5 -4
- package/src/server/api/kernelDispatch.ts +8 -8
- package/src/server/artifactCollectionService.ts +4 -7
- package/src/server/artifactRepository.ts +4 -3
- package/src/server/clmRunner.mjs +1 -1
- package/src/server/collectionOwner.mjs +5 -5
- package/src/server/effects/executionPersistenceService.mjs +11 -11
- package/src/server/effects/resultSealingService.mjs +2 -2
- package/src/server/fileIngestService.mjs +21 -9
- package/src/server/fileWatcherService.mjs +4 -1
- package/src/server/handlers/fileChangeHandler.mjs +18 -10
- package/src/server/handlers/saveExecutionLogHandler.mjs +6 -6
- package/src/server/notificationService.mjs +14 -1
- package/src/server/scripts/buildSeedingMemory.mjs +3 -3
- package/src/server/serverMemoryRepository.ts +41 -59
- package/src/server/vfsTreeScan.ts +16 -10
- package/src/server/workspaceRoot.ts +143 -5
- package/src/services/cardTypeDetector.ts +4 -0
- package/src/services/databaseSyncService.ts +30 -46
- package/src/services/namespaceProtocolClient.ts +221 -0
- package/src/services/renderers/pcard/RendererPCardRegistry.ts +4 -66
- package/src/services/renderers/pcard/modalitySpecs.ts +125 -0
- package/src/services/renderers/pcard/types.ts +7 -1
- package/src/services/renderers/rendererEventBus.ts +5 -3
- package/src/services/unifiedFunctionExecutionService.ts +145 -0
- package/src/services/vfs/vfsCore.ts +12 -1
- package/src/services/vfs/vfsMigration.ts +95 -0
- package/src/services/vfs/vfsMutations.ts +17 -35
- package/src/services/vfs/vfsPersistence.ts +19 -24
- package/src/services/vfs/vfsSync.ts +55 -17
- package/src/services/vfs/vfsVersions.ts +23 -34
- package/src/services/workbenchExecutionPolicy.ts +183 -0
- package/src/stores/mcardCollectionStore.ts +2 -0
- package/src/styles/dockview.css +34 -0
- package/src/ui/viewlets/FibrationRefinementViewlet.tsx +155 -0
- package/src/ui/viewlets/PetriConformanceViewlet.tsx +166 -0
- package/src/ui/viewlets/ResponsiveViewportLabViewlet.tsx +175 -0
- package/src/ui/viewlets/SprintGovernanceViewlet.tsx +176 -0
- package/src/ui/viewlets/viewletFocus.ts +35 -0
- package/src/ui/viewlets/viewportLabParts.tsx +190 -0
- package/dist/client/_astro/DockviewSpatialWorkbench.B_I1GJHw.js +0 -12
- package/dist/client/_astro/DocumentViewlets.B53IqmpY.js +0 -2
- package/dist/client/_astro/HeadMeta.astro_astro_type_script_index_0_lang.VDRYJCM-.js +0 -1
- package/dist/client/_astro/PCardRendererBridge.oxVKc0gN.js +0 -1
- package/dist/client/_astro/RendererPCardRegistry.CWjYZs2H.js +0 -1
- package/dist/client/_astro/StudioWorkbench.Blo5oSIw.js +0 -7
- package/dist/client/_astro/VideoPlayerViewlet.CmECt7yT.js +0 -1
- package/dist/client/_astro/WebappZenViewlet.whCmGVHR.js +0 -1
- package/dist/client/_astro/__vite-browser-external.CQZnr-r3.js +0 -1
- package/dist/client/_astro/cardTypeDetector.Ci4APwhX.js +0 -1
- package/dist/client/_astro/disposable.Dsb0sbRP.js +0 -1
- package/dist/client/_astro/mcardVfs.2UOw9Z-r.js +0 -3
- package/dist/client/_astro/pathsConfig.D0hV34p7.js +0 -2
- package/dist/client/_astro/rendererEventBus.DMH9afq9.js +0 -1
- package/dist/client/_astro/themeStore.CEt0e54l.js +0 -1
- package/dist/client/_astro/vendor-clm-kernel.Bvk3XHk2.js +0 -116
- package/dist/client/_astro/vfsPersistence.BuhXYeSb.js +0 -1
- package/dist/server/chunks/cryptoPolyfill_99rxUwYC.mjs +0 -180
- package/dist/server/chunks/kernelHash_DRaj51hY.mjs +0 -5
- package/dist/server/chunks/tree_CE2BhvyJ.mjs +0 -76
- package/dist/server/chunks/vfsCore_B6nCiBl5.mjs +0 -21
- package/dist/server/chunks/workspaceRoot_DVSUbYkd.mjs +0 -71
- package/src/server/kernelHash.ts +0 -22
- package/src/server/storage/cardCollection.ts +0 -94
- package/src/server/storage/index.ts +0 -3
- package/src/server/storage/mcard.ts +0 -99
- package/src/server/storage/sqliteNodeEngine.ts +0 -121
- /package/dist/server/chunks/{StudioLayout_B5ZnlqjF.mjs → StudioLayout_taayQJ5b.mjs} +0 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ClmRegistryComponentViewlet — renders sharded CLM-registry components and app
|
|
3
|
+
* cartridges inside Dockview tabs (SMR-10 · DoD-SMR-10-03).
|
|
4
|
+
*
|
|
5
|
+
* The monolithic `LandingPage/clm-registry.yaml` is sharded into content-addressed
|
|
6
|
+
* MCards (`urn:mcard:registry:component:<id>`, `urn:mcard:registry:fiber:<id>`), so
|
|
7
|
+
* each tab renders one descriptor: its abstract / concrete / balanced faces for a
|
|
8
|
+
* component, or its hydration and budget contract for a portal island cartridge.
|
|
9
|
+
*
|
|
10
|
+
* Registered as `pcard:render/clm-registry-component` in the renderer PCard registry
|
|
11
|
+
* and as module `ClmRegistryComponentViewlet` in the viewlet module map.
|
|
12
|
+
*
|
|
13
|
+
* Contract D budget: <= 220 LOC.
|
|
14
|
+
*/
|
|
15
|
+
import React from 'react';
|
|
16
|
+
|
|
17
|
+
import type { CardViewletProps } from './types';
|
|
18
|
+
|
|
19
|
+
interface ComponentDescriptor {
|
|
20
|
+
readonly hash?: string;
|
|
21
|
+
readonly name?: string;
|
|
22
|
+
readonly abstract?: Record<string, unknown>;
|
|
23
|
+
readonly concrete?: Record<string, unknown>;
|
|
24
|
+
readonly balanced?: Record<string, unknown>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
interface IslandCartridge {
|
|
28
|
+
readonly url?: string;
|
|
29
|
+
readonly kind?: string;
|
|
30
|
+
readonly hydration?: string;
|
|
31
|
+
readonly isolation?: string;
|
|
32
|
+
readonly budget?: { readonly max_bytes?: number; readonly observed_bytes?: number };
|
|
33
|
+
readonly metrics_endpoint?: string;
|
|
34
|
+
readonly island_mcard?: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
interface RegistryDescriptor extends ComponentDescriptor, IslandCartridge {
|
|
38
|
+
readonly kind?: string;
|
|
39
|
+
readonly renderer?: string;
|
|
40
|
+
readonly payload_shape?: string;
|
|
41
|
+
readonly content_class?: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Parses the descriptor body; returns null when the content is not a registry record. */
|
|
45
|
+
export function parseRegistryDescriptor(raw?: string): RegistryDescriptor | null {
|
|
46
|
+
if (!raw) return null;
|
|
47
|
+
try {
|
|
48
|
+
const parsed = JSON.parse(raw);
|
|
49
|
+
return parsed && typeof parsed === 'object' ? (parsed as RegistryDescriptor) : null;
|
|
50
|
+
} catch {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** True when the descriptor is a portal island cartridge rather than a component. */
|
|
56
|
+
export function isIslandCartridge(descriptor: RegistryDescriptor | null): boolean {
|
|
57
|
+
return Boolean(descriptor && (descriptor.island_mcard || descriptor.hydration || descriptor.url));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Renders the three CLM faces of a sharded component. */
|
|
61
|
+
export const FaceGrid: React.FC<{ descriptor: ComponentDescriptor }> = ({ descriptor }) => (
|
|
62
|
+
<div className="clm-registry-faces">
|
|
63
|
+
{(['abstract', 'concrete', 'balanced'] as const).map((face) => (
|
|
64
|
+
<section key={face} className={`clm-registry-face clm-registry-face--${face}`}>
|
|
65
|
+
<h4>{face}</h4>
|
|
66
|
+
<pre>{JSON.stringify(descriptor[face] ?? {}, null, 2)}</pre>
|
|
67
|
+
</section>
|
|
68
|
+
))}
|
|
69
|
+
</div>
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
/** Renders a portal island's cartridge contract. */
|
|
73
|
+
export const CartridgeContract: React.FC<{ cartridge: IslandCartridge }> = ({ cartridge }) => (
|
|
74
|
+
<dl className="clm-registry-cartridge">
|
|
75
|
+
<dt>URL</dt>
|
|
76
|
+
<dd>
|
|
77
|
+
<code>{cartridge.url ?? '(none)'}</code>
|
|
78
|
+
</dd>
|
|
79
|
+
<dt>Kind</dt>
|
|
80
|
+
<dd>{cartridge.kind ?? 'unknown'}</dd>
|
|
81
|
+
<dt>Hydration</dt>
|
|
82
|
+
<dd>{cartridge.hydration ?? 'none'}</dd>
|
|
83
|
+
<dt>Isolation</dt>
|
|
84
|
+
<dd>{cartridge.isolation ?? 'none'}</dd>
|
|
85
|
+
<dt>Budget</dt>
|
|
86
|
+
<dd>
|
|
87
|
+
{cartridge.budget?.observed_bytes ?? '?'} / {cartridge.budget?.max_bytes ?? '?'} bytes
|
|
88
|
+
</dd>
|
|
89
|
+
<dt>Metrics</dt>
|
|
90
|
+
<dd>
|
|
91
|
+
<code>{cartridge.metrics_endpoint ?? '(none)'}</code>
|
|
92
|
+
</dd>
|
|
93
|
+
</dl>
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
export const ClmRegistryComponentViewlet: React.FC<CardViewletProps> = ({ mcard, rawContent }) => {
|
|
97
|
+
const body =
|
|
98
|
+
rawContent ?? (typeof mcard?.content === 'string' ? (mcard.content as string) : undefined);
|
|
99
|
+
const descriptor = parseRegistryDescriptor(body);
|
|
100
|
+
|
|
101
|
+
if (!descriptor) {
|
|
102
|
+
return (
|
|
103
|
+
<div className="clm-registry-viewlet clm-registry-viewlet--unparsed">
|
|
104
|
+
<p>Not a sharded registry descriptor.</p>
|
|
105
|
+
<pre>{body?.slice(0, 400) ?? '(empty)'}</pre>
|
|
106
|
+
</div>
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const handle = mcard?.handle ?? descriptor.hash ?? '(unbound)';
|
|
111
|
+
return (
|
|
112
|
+
<div className="clm-registry-viewlet" data-handle={handle}>
|
|
113
|
+
<header className="clm-registry-header">
|
|
114
|
+
<h3>{descriptor.name ?? handle}</h3>
|
|
115
|
+
<code className="clm-registry-handle">{handle}</code>
|
|
116
|
+
</header>
|
|
117
|
+
|
|
118
|
+
{isIslandCartridge(descriptor) ? (
|
|
119
|
+
<CartridgeContract cartridge={descriptor} />
|
|
120
|
+
) : (
|
|
121
|
+
<>
|
|
122
|
+
<p className="clm-registry-kind">
|
|
123
|
+
{descriptor.kind ?? 'component'}
|
|
124
|
+
{descriptor.renderer ? ` · renderer ${descriptor.renderer}` : ''}
|
|
125
|
+
</p>
|
|
126
|
+
<FaceGrid descriptor={descriptor} />
|
|
127
|
+
</>
|
|
128
|
+
)}
|
|
129
|
+
</div>
|
|
130
|
+
);
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
export default ClmRegistryComponentViewlet;
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 2D CAD Vector Blueprint Viewport (DXF)
|
|
3
|
+
* Canonical Path: src/components/studio/views/cardViewlets/DxfViewlet.tsx
|
|
4
|
+
* Contract D: <= 250 LOC.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import React, { useState, useEffect, useRef, useMemo } from 'react';
|
|
8
|
+
import type { CardViewletProps } from './types';
|
|
9
|
+
import { getMediaRawUrl } from '../../../../services/mcardVfs';
|
|
10
|
+
import { FullscreenIframeModal } from './FullscreenIframeModal';
|
|
11
|
+
|
|
12
|
+
interface DxfLine { type: 'LINE'; x1: number; y1: number; x2: number; y2: number; layer: string }
|
|
13
|
+
interface DxfCircle { type: 'CIRCLE'; cx: number; cy: number; r: number; layer: string }
|
|
14
|
+
interface DxfArc { type: 'ARC'; cx: number; cy: number; r: number; startAngle: number; endAngle: number; layer: string }
|
|
15
|
+
interface DxfPolyline { type: 'LWPOLYLINE'; points: Array<{ x: number; y: number }>; closed: boolean; layer: string }
|
|
16
|
+
type DxfEntity = DxfLine | DxfCircle | DxfArc | DxfPolyline;
|
|
17
|
+
|
|
18
|
+
function parseDxfEntities(text: string): { entities: DxfEntity[]; bbox: { minX: number; minY: number; maxX: number; maxY: number } } {
|
|
19
|
+
const lines = text.split(/\r?\n/).map((l) => l.trim());
|
|
20
|
+
const entities: DxfEntity[] = [];
|
|
21
|
+
let inEntities = false;
|
|
22
|
+
let cur: any = null;
|
|
23
|
+
|
|
24
|
+
for (let i = 0; i < lines.length - 1; i += 2) {
|
|
25
|
+
const code = parseInt(lines[i], 10);
|
|
26
|
+
const val = lines[i + 1];
|
|
27
|
+
if (code === 0) {
|
|
28
|
+
if (cur) entities.push(cur);
|
|
29
|
+
cur = null;
|
|
30
|
+
if (val === 'SECTION') continue;
|
|
31
|
+
if (val === 'ENDSEC') { inEntities = false; continue; }
|
|
32
|
+
if (inEntities) {
|
|
33
|
+
if (val === 'LINE') cur = { type: 'LINE', x1: 0, y1: 0, x2: 0, y2: 0, layer: '0' };
|
|
34
|
+
else if (val === 'CIRCLE') cur = { type: 'CIRCLE', cx: 0, cy: 0, r: 0, layer: '0' };
|
|
35
|
+
else if (val === 'ARC') cur = { type: 'ARC', cx: 0, cy: 0, r: 0, startAngle: 0, endAngle: 360, layer: '0' };
|
|
36
|
+
else if (val === 'LWPOLYLINE') cur = { type: 'LWPOLYLINE', points: [], closed: false, layer: '0' };
|
|
37
|
+
}
|
|
38
|
+
} else if (code === 2 && val === 'ENTITIES') {
|
|
39
|
+
inEntities = true;
|
|
40
|
+
} else if (cur) {
|
|
41
|
+
if (code === 8) cur.layer = val;
|
|
42
|
+
else if (cur.type === 'LINE') {
|
|
43
|
+
if (code === 10) cur.x1 = parseFloat(val);
|
|
44
|
+
else if (code === 20) cur.y1 = parseFloat(val);
|
|
45
|
+
else if (code === 11) cur.x2 = parseFloat(val);
|
|
46
|
+
else if (code === 21) cur.y2 = parseFloat(val);
|
|
47
|
+
} else if (cur.type === 'CIRCLE' || cur.type === 'ARC') {
|
|
48
|
+
if (code === 10) cur.cx = parseFloat(val);
|
|
49
|
+
else if (code === 20) cur.cy = parseFloat(val);
|
|
50
|
+
else if (code === 40) cur.r = parseFloat(val);
|
|
51
|
+
else if (code === 50 && cur.type === 'ARC') cur.startAngle = parseFloat(val);
|
|
52
|
+
else if (code === 51 && cur.type === 'ARC') cur.endAngle = parseFloat(val);
|
|
53
|
+
} else if (cur.type === 'LWPOLYLINE') {
|
|
54
|
+
if (code === 70) cur.closed = (parseInt(val, 10) & 1) === 1;
|
|
55
|
+
else if (code === 10) cur.points.push({ x: parseFloat(val), y: 0 });
|
|
56
|
+
else if (code === 20 && cur.points.length > 0) cur.points[cur.points.length - 1].y = parseFloat(val);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (cur) entities.push(cur);
|
|
61
|
+
|
|
62
|
+
let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
|
|
63
|
+
const updateBbox = (x: number, y: number) => {
|
|
64
|
+
if (!isNaN(x) && !isNaN(y)) {
|
|
65
|
+
minX = Math.min(minX, x); maxX = Math.max(maxX, x);
|
|
66
|
+
minY = Math.min(minY, y); maxY = Math.max(maxY, y);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
for (const e of entities) {
|
|
70
|
+
if (e.type === 'LINE') { updateBbox(e.x1, e.y1); updateBbox(e.x2, e.y2); }
|
|
71
|
+
else if (e.type === 'CIRCLE' || e.type === 'ARC') {
|
|
72
|
+
updateBbox(e.cx - e.r, e.cy - e.r); updateBbox(e.cx + e.r, e.cy + e.r);
|
|
73
|
+
} else if (e.type === 'LWPOLYLINE') {
|
|
74
|
+
for (const p of e.points) updateBbox(p.x, p.y);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (!isFinite(minX)) { minX = 0; minY = 0; maxX = 100; maxY = 100; }
|
|
78
|
+
return { entities, bbox: { minX, minY, maxX, maxY } };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export const DxfViewlet: React.FC<CardViewletProps> = ({ mcard }) => {
|
|
82
|
+
const filePath = mcard.path || mcard.handle || mcard.name || '';
|
|
83
|
+
const rawUrl = getMediaRawUrl(filePath, mcard.hash);
|
|
84
|
+
const [content, setContent] = useState<string>(typeof mcard.content === 'string' ? mcard.content : '');
|
|
85
|
+
const [zoom, setZoom] = useState(1);
|
|
86
|
+
const [pan, setPan] = useState({ x: 0, y: 0 });
|
|
87
|
+
const [isZenOpen, setIsZenOpen] = useState(false);
|
|
88
|
+
const [showRaw, setShowRaw] = useState(false);
|
|
89
|
+
const isDragging = useRef(false);
|
|
90
|
+
const lastMouse = useRef({ x: 0, y: 0 });
|
|
91
|
+
|
|
92
|
+
useEffect(() => {
|
|
93
|
+
setZoom(1);
|
|
94
|
+
setPan({ x: 0, y: 0 });
|
|
95
|
+
}, [filePath]);
|
|
96
|
+
|
|
97
|
+
useEffect(() => {
|
|
98
|
+
let active = true;
|
|
99
|
+
if (typeof mcard.content === 'string' && mcard.content.length > 0 && !mcard.content.startsWith('Content-addressed MCard:')) {
|
|
100
|
+
setContent(mcard.content);
|
|
101
|
+
} else if (rawUrl) {
|
|
102
|
+
fetch(rawUrl)
|
|
103
|
+
.then((r) => r.text())
|
|
104
|
+
.then((t) => {
|
|
105
|
+
if (active) setContent(t);
|
|
106
|
+
})
|
|
107
|
+
.catch(() => {});
|
|
108
|
+
}
|
|
109
|
+
return () => {
|
|
110
|
+
active = false;
|
|
111
|
+
};
|
|
112
|
+
}, [rawUrl, mcard.content]);
|
|
113
|
+
|
|
114
|
+
const { entities, bbox } = useMemo(() => parseDxfEntities(content), [content]);
|
|
115
|
+
const width = Math.max(1, bbox.maxX - bbox.minX);
|
|
116
|
+
const height = Math.max(1, bbox.maxY - bbox.minY);
|
|
117
|
+
const pad = Math.max(width, height) * 0.15;
|
|
118
|
+
const viewBox = `${bbox.minX - pad} ${bbox.minY - pad} ${width + pad * 2} ${height + pad * 2}`;
|
|
119
|
+
const gridStep = Math.max(1, Math.round(Math.max(width, height) / 10));
|
|
120
|
+
|
|
121
|
+
const handleMouseDown = (e: React.MouseEvent) => {
|
|
122
|
+
isDragging.current = true;
|
|
123
|
+
lastMouse.current = { x: e.clientX, y: e.clientY };
|
|
124
|
+
};
|
|
125
|
+
const handleMouseMove = (e: React.MouseEvent) => {
|
|
126
|
+
if (!isDragging.current) return;
|
|
127
|
+
const dx = (e.clientX - lastMouse.current.x) * ((width + pad * 2) / 600);
|
|
128
|
+
const dy = (e.clientY - lastMouse.current.y) * ((height + pad * 2) / 600);
|
|
129
|
+
lastMouse.current = { x: e.clientX, y: e.clientY };
|
|
130
|
+
setPan((p) => ({ x: p.x + dx, y: p.y - dy }));
|
|
131
|
+
};
|
|
132
|
+
const handleMouseUp = () => { isDragging.current = false; };
|
|
133
|
+
const handleWheel = (e: React.WheelEvent) => {
|
|
134
|
+
e.preventDefault();
|
|
135
|
+
setZoom((z) => Math.max(0.1, Math.min(25, z * (e.deltaY < 0 ? 1.15 : 0.85))));
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
const strokeWidth = Math.max(0.5, pad * 0.015);
|
|
139
|
+
const strokeColor = '#00e5ff';
|
|
140
|
+
|
|
141
|
+
return (
|
|
142
|
+
<div className="card-panel-dxf-viewer" style={{ display: 'flex', flexDirection: 'column', width: '100%', height: '100%', backgroundColor: '#0d1117', color: '#c9d1d9', overflow: 'hidden' }}>
|
|
143
|
+
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', padding: '6px 12px', backgroundColor: '#161b22', borderBottom: '1px solid #30363d', fontSize: '11px' }}>
|
|
144
|
+
<div style={{ display: 'flex', alignItems: 'center', gap: '8px' }}>
|
|
145
|
+
<span style={{ color: '#00e5ff', fontWeight: 600 }}>📐 2D CAD (DXF)</span>
|
|
146
|
+
<span style={{ color: '#8b949e' }}>{mcard.name}</span>
|
|
147
|
+
<span style={{ backgroundColor: 'rgba(0, 229, 255, 0.1)', color: '#00e5ff', padding: '1px 6px', borderRadius: '3px' }}>
|
|
148
|
+
{entities.length} entities • {width.toFixed(1)} × {height.toFixed(1)}
|
|
149
|
+
</span>
|
|
150
|
+
</div>
|
|
151
|
+
<div style={{ display: 'flex', alignItems: 'center', gap: '6px' }}>
|
|
152
|
+
<button onClick={() => setZoom((z) => Math.min(25, z * 1.2))} style={btnStyle} title="Zoom In">+</button>
|
|
153
|
+
<button onClick={() => setZoom((z) => Math.max(0.1, z * 0.8))} style={btnStyle} title="Zoom Out">-</button>
|
|
154
|
+
<button onClick={() => { setZoom(1); setPan({ x: 0, y: 0 }); }} style={btnStyle} title="Fit View">Fit</button>
|
|
155
|
+
<button onClick={() => setShowRaw(!showRaw)} style={{ ...btnStyle, color: showRaw ? '#00e5ff' : '#c9d1d9' }}>
|
|
156
|
+
{showRaw ? 'CAD View' : 'Raw Text'}
|
|
157
|
+
</button>
|
|
158
|
+
<button onClick={() => setIsZenOpen(true)} style={{ ...btnStyle, backgroundColor: '#1f6feb', color: '#fff', border: 'none' }}>Zen Mode</button>
|
|
159
|
+
{rawUrl && <a href={rawUrl} download={mcard.name} style={{ color: '#58a6ff', textDecoration: 'none', marginLeft: '4px' }}>Download ↓</a>}
|
|
160
|
+
</div>
|
|
161
|
+
</div>
|
|
162
|
+
|
|
163
|
+
<div style={{ flex: 1, position: 'relative', overflow: 'hidden', cursor: isDragging.current ? 'grabbing' : 'grab' }}
|
|
164
|
+
onMouseDown={handleMouseDown} onMouseMove={handleMouseMove} onMouseUp={handleMouseUp} onMouseLeave={handleMouseUp} onWheel={handleWheel}>
|
|
165
|
+
{showRaw ? (
|
|
166
|
+
<pre style={{ margin: 0, padding: '16px', width: '100%', height: '100%', overflow: 'auto', fontSize: '11px', fontFamily: 'monospace', color: '#7ee787', backgroundColor: '#0d1117' }}>
|
|
167
|
+
{content || 'Loading DXF payload...'}
|
|
168
|
+
</pre>
|
|
169
|
+
) : (
|
|
170
|
+
<svg
|
|
171
|
+
viewBox={viewBox}
|
|
172
|
+
preserveAspectRatio="xMidYMid meet"
|
|
173
|
+
style={{ width: '100%', height: '100%', display: 'block', overflow: 'hidden' }}
|
|
174
|
+
>
|
|
175
|
+
<defs>
|
|
176
|
+
<pattern id="dxf-grid-small" width={gridStep} height={gridStep} patternUnits="userSpaceOnUse">
|
|
177
|
+
<path d={`M ${gridStep} 0 L 0 0 0 ${gridStep}`} fill="none" stroke="rgba(255,255,255,0.04)" strokeWidth={strokeWidth * 0.5} />
|
|
178
|
+
</pattern>
|
|
179
|
+
</defs>
|
|
180
|
+
<rect x={bbox.minX - pad * 2} y={bbox.minY - pad * 2} width={width + pad * 4} height={height + pad * 4} fill="#0d1117" />
|
|
181
|
+
<rect x={bbox.minX - pad * 2} y={bbox.minY - pad * 2} width={width + pad * 4} height={height + pad * 4} fill="url(#dxf-grid-small)" />
|
|
182
|
+
|
|
183
|
+
<g transform={`translate(${pan.x}, ${pan.y}) scale(${zoom})`} style={{ transformOrigin: `${(bbox.minX + bbox.maxX) / 2}px ${(bbox.minY + bbox.maxY) / 2}px` }}>
|
|
184
|
+
{/* Transform to flip Y axis for authentic CAD coordinate representation (+Y is up) */}
|
|
185
|
+
<g transform={`translate(0, ${bbox.minY + bbox.maxY}) scale(1, -1)`}>
|
|
186
|
+
{entities.map((e, idx) => {
|
|
187
|
+
if (e.type === 'LINE') {
|
|
188
|
+
return <line key={idx} x1={e.x1} y1={e.y1} x2={e.x2} y2={e.y2} stroke={strokeColor} strokeWidth={strokeWidth} strokeLinecap="round" vectorEffect="non-scaling-stroke" />;
|
|
189
|
+
}
|
|
190
|
+
if (e.type === 'CIRCLE') {
|
|
191
|
+
return <circle key={idx} cx={e.cx} cy={e.cy} r={e.r} fill="none" stroke={strokeColor} strokeWidth={strokeWidth} vectorEffect="non-scaling-stroke" />;
|
|
192
|
+
}
|
|
193
|
+
if (e.type === 'ARC') {
|
|
194
|
+
const sRad = (e.startAngle * Math.PI) / 180;
|
|
195
|
+
const eRad = (e.endAngle * Math.PI) / 180;
|
|
196
|
+
const x1 = e.cx + e.r * Math.cos(sRad);
|
|
197
|
+
const y1 = e.cy + e.r * Math.sin(sRad);
|
|
198
|
+
const x2 = e.cx + e.r * Math.cos(eRad);
|
|
199
|
+
const y2 = e.cy + e.r * Math.sin(eRad);
|
|
200
|
+
const largeArc = (e.endAngle - e.startAngle + 360) % 360 > 180 ? 1 : 0;
|
|
201
|
+
return <path key={idx} d={`M ${x1} ${y1} A ${e.r} ${e.r} 0 ${largeArc} 1 ${x2} ${y2}`} fill="none" stroke={strokeColor} strokeWidth={strokeWidth} vectorEffect="non-scaling-stroke" />;
|
|
202
|
+
}
|
|
203
|
+
if (e.type === 'LWPOLYLINE' && e.points.length > 0) {
|
|
204
|
+
const d = e.points.map((p, i) => `${i === 0 ? 'M' : 'L'} ${p.x} ${p.y}`).join(' ') + (e.closed ? ' Z' : '');
|
|
205
|
+
return <path key={idx} d={d} fill="none" stroke={strokeColor} strokeWidth={strokeWidth} strokeLinecap="round" strokeLinejoin="round" vectorEffect="non-scaling-stroke" />;
|
|
206
|
+
}
|
|
207
|
+
return null;
|
|
208
|
+
})}
|
|
209
|
+
</g>
|
|
210
|
+
</g>
|
|
211
|
+
</svg>
|
|
212
|
+
)}
|
|
213
|
+
</div>
|
|
214
|
+
|
|
215
|
+
{isZenOpen && (
|
|
216
|
+
<FullscreenIframeModal title={mcard.name} src={rawUrl} onClose={() => setIsZenOpen(false)} />
|
|
217
|
+
)}
|
|
218
|
+
</div>
|
|
219
|
+
);
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
const btnStyle: React.CSSProperties = {
|
|
223
|
+
fontSize: '11px',
|
|
224
|
+
padding: '2px 8px',
|
|
225
|
+
backgroundColor: '#21262d',
|
|
226
|
+
color: '#c9d1d9',
|
|
227
|
+
border: '1px solid #30363d',
|
|
228
|
+
borderRadius: '3px',
|
|
229
|
+
cursor: 'pointer',
|
|
230
|
+
};
|
|
@@ -31,9 +31,9 @@ export const VideoPlayerViewlet: React.FC<CardViewletProps> = ({ mcard }) => {
|
|
|
31
31
|
const [playbackRate, setPlaybackRate] = useState<number>(1);
|
|
32
32
|
const [isZenModeOpen, setIsZenModeOpen] = useState(false);
|
|
33
33
|
|
|
34
|
-
const
|
|
34
|
+
const pathStr = mcard.path || mcard.handle || mcard.name || '';
|
|
35
|
+
const rawUrl = getMediaRawUrl(pathStr, mcard.hash);
|
|
35
36
|
const contentStr = typeof mcard.content === 'string' ? mcard.content : '';
|
|
36
|
-
const pathStr = mcard.path || mcard.handle || '';
|
|
37
37
|
|
|
38
38
|
const [asyncContent, setAsyncContent] = useState<string>('');
|
|
39
39
|
|
|
@@ -241,9 +241,9 @@ export const VideoPlayerViewlet: React.FC<CardViewletProps> = ({ mcard }) => {
|
|
|
241
241
|
}}
|
|
242
242
|
>
|
|
243
243
|
<video
|
|
244
|
-
ref={videoRef}
|
|
244
|
+
key={rawUrl} ref={videoRef}
|
|
245
245
|
src={rawUrl}
|
|
246
|
-
controls
|
|
246
|
+
controls preload="metadata"
|
|
247
247
|
style={{
|
|
248
248
|
maxWidth: '100%',
|
|
249
249
|
maxHeight: '100%',
|
|
@@ -116,8 +116,8 @@ export function registerCoreViewlets(register: (v: CardViewletDefinition) => voi
|
|
|
116
116
|
predicate: (file) => {
|
|
117
117
|
const path = (file.path || file.name || file.handle || '').toLowerCase();
|
|
118
118
|
const mime = (file.mimeType || '').toLowerCase();
|
|
119
|
-
if ((mime.startsWith('image/') && mime !== 'image/svg+xml') || mime.startsWith('audio/') || mime.startsWith('video/') || mime.startsWith('font/') || mime === 'application/pdf' || path.endsWith('.glb') || path.endsWith('.bin')) return false;
|
|
120
|
-
return mime.startsWith('text/') || mime === 'application/json' || mime === 'application/xml' || mime === 'application/x-yaml' || mime === 'image/svg+xml' || path.endsWith('.yaml') || path.endsWith('.yml') || path.endsWith('.json') || path.endsWith('.txt') || path.endsWith('.md') || path.endsWith('.ts') || path.endsWith('.tsx') || path.endsWith('.js') || (typeof file.content === 'string' && !file.content.startsWith('\x00'));
|
|
119
|
+
if ((mime.startsWith('image/') && mime !== 'image/svg+xml' && mime !== 'image/vnd.dxf') || mime.startsWith('audio/') || mime.startsWith('video/') || mime.startsWith('font/') || mime === 'application/pdf' || path.endsWith('.glb') || path.endsWith('.bin')) return false;
|
|
120
|
+
return mime.startsWith('text/') || mime === 'application/json' || mime === 'application/xml' || mime === 'application/x-yaml' || mime === 'image/svg+xml' || mime === 'image/vnd.dxf' || path.endsWith('.yaml') || path.endsWith('.yml') || path.endsWith('.json') || path.endsWith('.txt') || path.endsWith('.md') || path.endsWith('.ts') || path.endsWith('.tsx') || path.endsWith('.js') || path.endsWith('.dxf') || (typeof file.content === 'string' && !file.content.startsWith('\x00'));
|
|
121
121
|
},
|
|
122
122
|
supportedTabs: ['text'],
|
|
123
123
|
priority: 10,
|
|
@@ -4,9 +4,9 @@ import { getMediaRawUrl } from '../../../../../services/mcardVfs';
|
|
|
4
4
|
import { extractSpotifyInfo } from '../mediaEmbeds';
|
|
5
5
|
|
|
6
6
|
export const AudioPlayerViewlet: React.FC<CardViewletProps> = ({ mcard }) => {
|
|
7
|
-
const
|
|
7
|
+
const pathStr = mcard.path || mcard.handle || mcard.name || '';
|
|
8
|
+
const rawUrl = getMediaRawUrl(pathStr, mcard.hash);
|
|
8
9
|
const contentStr = typeof mcard.content === 'string' ? mcard.content : '';
|
|
9
|
-
const pathStr = mcard.path || mcard.handle || '';
|
|
10
10
|
|
|
11
11
|
const [asyncContent, setAsyncContent] = useState<string>('');
|
|
12
12
|
|
|
@@ -106,7 +106,19 @@ export const AudioPlayerViewlet: React.FC<CardViewletProps> = ({ mcard }) => {
|
|
|
106
106
|
<div style={{ fontSize: '15px', fontWeight: 600, marginBottom: '16px', color: '#cccccc' }}>
|
|
107
107
|
{mcard.name}
|
|
108
108
|
</div>
|
|
109
|
-
<audio controls src={rawUrl} style={{ width: '380px' }}
|
|
109
|
+
<audio key={rawUrl} controls src={rawUrl} preload="metadata" style={{ width: '380px' }}>
|
|
110
|
+
<source src={rawUrl} type={mcard.mimeType || 'audio/mpeg'} />
|
|
111
|
+
Your browser does not support the audio element.
|
|
112
|
+
</audio>
|
|
113
|
+
{rawUrl && (
|
|
114
|
+
<a
|
|
115
|
+
href={rawUrl}
|
|
116
|
+
download={mcard.name}
|
|
117
|
+
style={{ marginTop: '14px', color: '#75beff', textDecoration: 'none', fontSize: '11px' }}
|
|
118
|
+
>
|
|
119
|
+
Download Audio ↓
|
|
120
|
+
</a>
|
|
121
|
+
)}
|
|
110
122
|
</div>
|
|
111
123
|
);
|
|
112
124
|
};
|
|
@@ -5,7 +5,8 @@ import { FullscreenIframeModal } from '../FullscreenIframeModal';
|
|
|
5
5
|
|
|
6
6
|
export const PdfViewlet: React.FC<CardViewletProps> = ({ mcard }) => {
|
|
7
7
|
const [isZenOpen, setIsZenOpen] = useState(false);
|
|
8
|
-
const
|
|
8
|
+
const filePath = mcard.path || mcard.handle || mcard.name || '';
|
|
9
|
+
const rawUrl = getMediaRawUrl(filePath, mcard.hash);
|
|
9
10
|
|
|
10
11
|
return (
|
|
11
12
|
<div
|
|
@@ -54,7 +55,7 @@ export const PdfViewlet: React.FC<CardViewletProps> = ({ mcard }) => {
|
|
|
54
55
|
{rawUrl && (
|
|
55
56
|
<a
|
|
56
57
|
href={rawUrl}
|
|
57
|
-
download
|
|
58
|
+
download={mcard.name}
|
|
58
59
|
style={{ color: '#75beff', textDecoration: 'none', fontSize: '10px' }}
|
|
59
60
|
>
|
|
60
61
|
Download PDF ↓
|
|
@@ -64,11 +65,28 @@ export const PdfViewlet: React.FC<CardViewletProps> = ({ mcard }) => {
|
|
|
64
65
|
</div>
|
|
65
66
|
|
|
66
67
|
<div style={{ flex: 1, width: '100%', height: '100%', position: 'relative' }}>
|
|
67
|
-
<
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
68
|
+
<object
|
|
69
|
+
key={rawUrl}
|
|
70
|
+
data={rawUrl}
|
|
71
|
+
type="application/pdf"
|
|
72
|
+
style={{ width: '100%', height: '100%', border: 'none', display: 'block' }}
|
|
73
|
+
>
|
|
74
|
+
<iframe
|
|
75
|
+
key={rawUrl}
|
|
76
|
+
src={rawUrl}
|
|
77
|
+
title={mcard.name}
|
|
78
|
+
style={{ width: '100%', height: '100%', border: 'none' }}
|
|
79
|
+
>
|
|
80
|
+
<div style={{ padding: '24px', textAlign: 'center', color: '#cccccc', backgroundColor: '#1e1e1e', height: '100%' }}>
|
|
81
|
+
<p>Unable to display PDF inline.</p>
|
|
82
|
+
{rawUrl && (
|
|
83
|
+
<a href={rawUrl} download={mcard.name} style={{ color: '#75beff', textDecoration: 'underline' }}>
|
|
84
|
+
Download {mcard.name}
|
|
85
|
+
</a>
|
|
86
|
+
)}
|
|
87
|
+
</div>
|
|
88
|
+
</iframe>
|
|
89
|
+
</object>
|
|
72
90
|
</div>
|
|
73
91
|
|
|
74
92
|
{isZenOpen && (
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import { findMCardByTarget } from '../../../../../../services/mcardVfs';
|
|
7
7
|
import { slugifyHeading, type CompilerContext } from './markdownSlugger';
|
|
8
|
+
import { formatMcardUri } from 'clm-kernel';
|
|
8
9
|
|
|
9
10
|
export function processObsidianWikilinks(content: string, ctx: CompilerContext): string {
|
|
10
11
|
return content.replace(/\[\[([^\]\|#]+)?(?:#([^\]\|]+))?(?:\|([^\]]+))?\]\]/g, (_match, rawTarget, rawHeading, rawAlias) => {
|
|
@@ -23,7 +24,7 @@ export function processObsidianWikilinks(content: string, ctx: CompilerContext):
|
|
|
23
24
|
const resolved = findMCardByTarget(target, ctx.currentCard, ctx.treeSnapshot);
|
|
24
25
|
if (resolved) {
|
|
25
26
|
const label = alias || (heading ? `${resolved.name.replace(/\.md$/, '')} › ${heading}` : resolved.name.replace(/\.md$/, ''));
|
|
26
|
-
const uri =
|
|
27
|
+
const uri = formatMcardUri({ type: 'handle', target: resolved.handle, fragment: heading || undefined });
|
|
27
28
|
return ctx.registerPlaceholder(`<a href="${uri}" class="obsidian-wikilink mcard-hyperlink" data-mcard-handle="${resolved.handle}" ${heading ? `data-mcard-heading="${heading}"` : ''} title="${resolved.path} (${resolved.handle})" style="color: #75beff; text-decoration: none; border-bottom: 1px dashed rgba(117, 190, 255, 0.6); padding: 1px 4px; border-radius: 3px; transition: background 0.15s ease; cursor: pointer; display: inline-flex; align-items: center; gap: 4px;">
|
|
28
29
|
<span style="opacity: 0.7; font-size: 11px;">📄</span>
|
|
29
30
|
<span>${label}</span>
|
|
@@ -38,6 +38,7 @@ const LazyKatexFormulaViewlet = lazyNamed(() => import('./KatexFormulaViewlet'),
|
|
|
38
38
|
const LazyD3GraphViewlet = lazyNamed(() => import('./D3GraphViewlet'), 'D3GraphViewlet');
|
|
39
39
|
const LazyChartAnalyticsViewlet = lazyNamed(() => import('./ChartAnalyticsViewlet'), 'ChartAnalyticsViewlet');
|
|
40
40
|
const LazyExcalidrawWhiteboardViewlet = lazyNamed(() => import('./ExcalidrawWhiteboardViewlet'), 'ExcalidrawWhiteboardViewlet');
|
|
41
|
+
const LazyDxfViewlet = lazyNamed(() => import('./DxfViewlet'), 'DxfViewlet');
|
|
41
42
|
|
|
42
43
|
export function registerMediaViewlets(register: (v: CardViewletDefinition) => void): void {
|
|
43
44
|
// 1. 3D Spatial Models (Priority: 100)
|
|
@@ -49,6 +50,20 @@ export function registerMediaViewlets(register: (v: CardViewletDefinition) => vo
|
|
|
49
50
|
supportedTabs: ['visual'], priority: 100, isFullBleed: true, isLazy: true, component: LazySpatial3dViewlet,
|
|
50
51
|
});
|
|
51
52
|
|
|
53
|
+
// 1.5 2D CAD Vector Blueprint Viewport (Priority: 96)
|
|
54
|
+
register({
|
|
55
|
+
id: 'viewlet:cad:dxf', name: '2D CAD Blueprint Viewport',
|
|
56
|
+
description: 'Interactive AutoCAD DXF vector drawing renderer with pan, zoom, grid, and CAD entity metrics',
|
|
57
|
+
supportedExtensions: ['.dxf'],
|
|
58
|
+
supportedMimes: ['image/vnd.dxf', 'application/dxf', 'application/x-dxf'],
|
|
59
|
+
predicate: (mcard) => {
|
|
60
|
+
const path = (mcard.path || mcard.name || mcard.handle || '').toLowerCase();
|
|
61
|
+
const mime = (mcard.mimeType || '').toLowerCase();
|
|
62
|
+
return path.endsWith('.dxf') || mime === 'image/vnd.dxf' || mime === 'application/dxf';
|
|
63
|
+
},
|
|
64
|
+
supportedTabs: ['visual'], priority: 96, isFullBleed: true, isLazy: true, component: LazyDxfViewlet,
|
|
65
|
+
});
|
|
66
|
+
|
|
52
67
|
// 2. Video Player & YouTube Embed (Priority: 95)
|
|
53
68
|
register({
|
|
54
69
|
id: 'viewlet:media:video', name: 'Video Player & YouTube Stream',
|
|
@@ -171,7 +186,12 @@ export function registerMediaViewlets(register: (v: CardViewletDefinition) => vo
|
|
|
171
186
|
description: 'Responsive raster image viewer for PNG, JPEG, WebP, GIF, BMP, ICO, AVIF',
|
|
172
187
|
supportedExtensions: ['.png', '.jpg', '.jpeg', '.webp', '.gif', '.bmp', '.ico', '.avif'],
|
|
173
188
|
supportedMimes: ['image/png', 'image/jpeg', 'image/webp', 'image/gif', 'image/bmp', 'image/x-icon', 'image/vnd.microsoft.icon', 'image/avif'],
|
|
174
|
-
predicate: (m) =>
|
|
189
|
+
predicate: (m) => {
|
|
190
|
+
const path = (m?.path || m?.name || m?.handle || '').toLowerCase();
|
|
191
|
+
const mime = (m?.mimeType || '').toLowerCase();
|
|
192
|
+
if (path.endsWith('.dxf') || mime === 'image/vnd.dxf') return false;
|
|
193
|
+
return m?.detectedType === 'image' || (typeof m?.mimeType === 'string' && m.mimeType.startsWith('image/') && m.mimeType !== 'image/svg+xml');
|
|
194
|
+
},
|
|
175
195
|
supportedTabs: ['visual'], priority: 75, isFullBleed: true, isLazy: true, component: LazyImageViewlet,
|
|
176
196
|
});
|
|
177
197
|
|
|
@@ -8,6 +8,35 @@ import type { ProbeResult } from './hooks/useWebappSecurityProbe';
|
|
|
8
8
|
import { IframeSecurityShield } from '../IframeSecurityShield';
|
|
9
9
|
import { WebappForbiddenView } from '../WebappForbiddenView';
|
|
10
10
|
|
|
11
|
+
export type WebappTrustMode = 'untrusted-external' | 'trusted-same-origin';
|
|
12
|
+
export const UNTRUSTED_EXTERNAL_SANDBOX = 'allow-scripts allow-forms allow-popups allow-downloads';
|
|
13
|
+
export const TRUSTED_SAME_ORIGIN_SANDBOX = 'allow-scripts allow-same-origin allow-forms allow-popups allow-downloads';
|
|
14
|
+
export const WEBAPP_TELEMETRY_SCHEMA = 'mcard-portal-telemetry/v1';
|
|
15
|
+
export const WEBAPP_TELEMETRY_TYPES = Object.freeze(['portal:ready', 'portal:resize', 'portal:metric', 'portal:error']);
|
|
16
|
+
|
|
17
|
+
export function resolveWebappSandbox(trustMode: WebappTrustMode = 'untrusted-external'): string {
|
|
18
|
+
return trustMode === 'trusted-same-origin' ? TRUSTED_SAME_ORIGIN_SANDBOX : UNTRUSTED_EXTERNAL_SANDBOX;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function validateWebappTelemetryMessage(
|
|
22
|
+
event: { source?: unknown; origin?: string; data?: unknown } | null | undefined,
|
|
23
|
+
options: { expectedSource: unknown; expectedNonce: string | null | undefined },
|
|
24
|
+
): { ok: boolean; reason?: string; message?: { schema: string; type: string; nonce: string; payload: Record<string, unknown> } } {
|
|
25
|
+
if (!event || typeof event !== 'object') return { ok: false, reason: 'invalid_event' };
|
|
26
|
+
if (!options.expectedSource || event.source !== options.expectedSource) return { ok: false, reason: 'source_mismatch' };
|
|
27
|
+
if (!options.expectedNonce || typeof options.expectedNonce !== 'string') return { ok: false, reason: 'nonce_unconfigured' };
|
|
28
|
+
const data = event.data as Record<string, unknown> | null | undefined;
|
|
29
|
+
if (!data || typeof data !== 'object' || Array.isArray(data)) return { ok: false, reason: 'malformed_payload' };
|
|
30
|
+
if (data.schema !== WEBAPP_TELEMETRY_SCHEMA) return { ok: false, reason: 'unsupported_schema_version' };
|
|
31
|
+
if (typeof data.nonce !== 'string' || data.nonce !== options.expectedNonce) return { ok: false, reason: 'nonce_mismatch' };
|
|
32
|
+
if (typeof data.type !== 'string' || !(WEBAPP_TELEMETRY_TYPES as readonly string[]).includes(data.type)) {
|
|
33
|
+
return { ok: false, reason: 'unsupported_message_type' };
|
|
34
|
+
}
|
|
35
|
+
const payload = data.payload ?? {};
|
|
36
|
+
if (!payload || typeof payload !== 'object' || Array.isArray(payload)) return { ok: false, reason: 'invalid_payload_object' };
|
|
37
|
+
return { ok: true, message: { schema: data.schema, type: data.type, nonce: data.nonce, payload: payload as Record<string, unknown> } };
|
|
38
|
+
}
|
|
39
|
+
|
|
11
40
|
export interface WebappCanvasProps {
|
|
12
41
|
appName?: string;
|
|
13
42
|
viewportStyles: React.CSSProperties;
|
|
@@ -23,23 +52,15 @@ export interface WebappCanvasProps {
|
|
|
23
52
|
hasShieldError: boolean;
|
|
24
53
|
setHasShieldError: (has: boolean) => void;
|
|
25
54
|
iframeKey: number;
|
|
55
|
+
trustMode?: WebappTrustMode;
|
|
56
|
+
mountNonce?: string;
|
|
26
57
|
}
|
|
27
58
|
|
|
28
59
|
export const WebappCanvas: React.FC<WebappCanvasProps> = ({
|
|
29
|
-
appName,
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
setForceDirectEmbed,
|
|
34
|
-
targetUrl,
|
|
35
|
-
activeSrc,
|
|
36
|
-
useProxy,
|
|
37
|
-
setUseProxy,
|
|
38
|
-
isLoading,
|
|
39
|
-
setIsLoading,
|
|
40
|
-
hasShieldError,
|
|
41
|
-
setHasShieldError,
|
|
42
|
-
iframeKey,
|
|
60
|
+
appName, viewportStyles, probeData, forceDirectEmbed, setForceDirectEmbed,
|
|
61
|
+
targetUrl, activeSrc, useProxy, setUseProxy, isLoading, setIsLoading,
|
|
62
|
+
hasShieldError, setHasShieldError, iframeKey,
|
|
63
|
+
trustMode = 'untrusted-external', mountNonce = 'default-mount-nonce',
|
|
43
64
|
}) => {
|
|
44
65
|
return (
|
|
45
66
|
<div
|
|
@@ -120,7 +141,11 @@ export const WebappCanvas: React.FC<WebappCanvasProps> = ({
|
|
|
120
141
|
key={iframeKey}
|
|
121
142
|
src={activeSrc}
|
|
122
143
|
title={appName || 'WebApp MCard'}
|
|
123
|
-
sandbox=
|
|
144
|
+
sandbox={resolveWebappSandbox(trustMode)}
|
|
145
|
+
referrerPolicy="no-referrer"
|
|
146
|
+
data-role="webapp-iframe"
|
|
147
|
+
data-trust-mode={trustMode}
|
|
148
|
+
data-mount-nonce={mountNonce}
|
|
124
149
|
onLoad={() => setIsLoading(false)}
|
|
125
150
|
onError={() => {
|
|
126
151
|
setIsLoading(false);
|