@jvs-milkdown/ctx 1.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.
Files changed (50) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +11 -0
  3. package/lib/context/container.d.ts +9 -0
  4. package/lib/context/container.d.ts.map +1 -0
  5. package/lib/context/index.d.ts +3 -0
  6. package/lib/context/index.d.ts.map +1 -0
  7. package/lib/context/slice.d.ts +23 -0
  8. package/lib/context/slice.d.ts.map +1 -0
  9. package/lib/index.d.ts +5 -0
  10. package/lib/index.d.ts.map +1 -0
  11. package/lib/index.js +300 -0
  12. package/lib/index.js.map +1 -0
  13. package/lib/inspector/index.d.ts +3 -0
  14. package/lib/inspector/index.d.ts.map +1 -0
  15. package/lib/inspector/inspector.d.ts +37 -0
  16. package/lib/inspector/inspector.d.ts.map +1 -0
  17. package/lib/inspector/meta.d.ts +8 -0
  18. package/lib/inspector/meta.d.ts.map +1 -0
  19. package/lib/plugin/ctx.d.ts +26 -0
  20. package/lib/plugin/ctx.d.ts.map +1 -0
  21. package/lib/plugin/index.d.ts +3 -0
  22. package/lib/plugin/index.d.ts.map +1 -0
  23. package/lib/plugin/types.d.ts +9 -0
  24. package/lib/plugin/types.d.ts.map +1 -0
  25. package/lib/timer/clock.d.ts +9 -0
  26. package/lib/timer/clock.d.ts.map +1 -0
  27. package/lib/timer/index.d.ts +3 -0
  28. package/lib/timer/index.d.ts.map +1 -0
  29. package/lib/timer/timer.d.ts +19 -0
  30. package/lib/timer/timer.d.ts.map +1 -0
  31. package/lib/tsconfig.tsbuildinfo +1 -0
  32. package/package.json +39 -0
  33. package/src/context/container.spec.ts +54 -0
  34. package/src/context/container.ts +48 -0
  35. package/src/context/index.ts +2 -0
  36. package/src/context/slice.spec.ts +116 -0
  37. package/src/context/slice.ts +108 -0
  38. package/src/index.ts +4 -0
  39. package/src/inspector/index.ts +2 -0
  40. package/src/inspector/inspector.ts +124 -0
  41. package/src/inspector/meta.ts +17 -0
  42. package/src/plugin/ctx.spec.ts +110 -0
  43. package/src/plugin/ctx.ts +136 -0
  44. package/src/plugin/index.ts +2 -0
  45. package/src/plugin/types.ts +43 -0
  46. package/src/timer/clock.spec.ts +27 -0
  47. package/src/timer/clock.ts +29 -0
  48. package/src/timer/index.ts +2 -0
  49. package/src/timer/timer.spec.ts +29 -0
  50. package/src/timer/timer.ts +109 -0
@@ -0,0 +1 @@
1
+ {"fileNames":["../../../node_modules/.pnpm/typescript@6.0.2/node_modules/typescript/lib/lib.es5.d.ts","../../../node_modules/.pnpm/typescript@6.0.2/node_modules/typescript/lib/lib.es2015.d.ts","../../../node_modules/.pnpm/typescript@6.0.2/node_modules/typescript/lib/lib.es2016.d.ts","../../../node_modules/.pnpm/typescript@6.0.2/node_modules/typescript/lib/lib.es2017.d.ts","../../../node_modules/.pnpm/typescript@6.0.2/node_modules/typescript/lib/lib.es2018.d.ts","../../../node_modules/.pnpm/typescript@6.0.2/node_modules/typescript/lib/lib.es2019.d.ts","../../../node_modules/.pnpm/typescript@6.0.2/node_modules/typescript/lib/lib.es2020.d.ts","../../../node_modules/.pnpm/typescript@6.0.2/node_modules/typescript/lib/lib.es2021.d.ts","../../../node_modules/.pnpm/typescript@6.0.2/node_modules/typescript/lib/lib.es2022.d.ts","../../../node_modules/.pnpm/typescript@6.0.2/node_modules/typescript/lib/lib.dom.d.ts","../../../node_modules/.pnpm/typescript@6.0.2/node_modules/typescript/lib/lib.es2015.core.d.ts","../../../node_modules/.pnpm/typescript@6.0.2/node_modules/typescript/lib/lib.es2015.collection.d.ts","../../../node_modules/.pnpm/typescript@6.0.2/node_modules/typescript/lib/lib.es2015.generator.d.ts","../../../node_modules/.pnpm/typescript@6.0.2/node_modules/typescript/lib/lib.es2015.iterable.d.ts","../../../node_modules/.pnpm/typescript@6.0.2/node_modules/typescript/lib/lib.es2015.promise.d.ts","../../../node_modules/.pnpm/typescript@6.0.2/node_modules/typescript/lib/lib.es2015.proxy.d.ts","../../../node_modules/.pnpm/typescript@6.0.2/node_modules/typescript/lib/lib.es2015.reflect.d.ts","../../../node_modules/.pnpm/typescript@6.0.2/node_modules/typescript/lib/lib.es2015.symbol.d.ts","../../../node_modules/.pnpm/typescript@6.0.2/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../../../node_modules/.pnpm/typescript@6.0.2/node_modules/typescript/lib/lib.es2016.array.include.d.ts","../../../node_modules/.pnpm/typescript@6.0.2/node_modules/typescript/lib/lib.es2016.intl.d.ts","../../../node_modules/.pnpm/typescript@6.0.2/node_modules/typescript/lib/lib.es2017.arraybuffer.d.ts","../../../node_modules/.pnpm/typescript@6.0.2/node_modules/typescript/lib/lib.es2017.date.d.ts","../../../node_modules/.pnpm/typescript@6.0.2/node_modules/typescript/lib/lib.es2017.object.d.ts","../../../node_modules/.pnpm/typescript@6.0.2/node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../../../node_modules/.pnpm/typescript@6.0.2/node_modules/typescript/lib/lib.es2017.string.d.ts","../../../node_modules/.pnpm/typescript@6.0.2/node_modules/typescript/lib/lib.es2017.intl.d.ts","../../../node_modules/.pnpm/typescript@6.0.2/node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../../../node_modules/.pnpm/typescript@6.0.2/node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","../../../node_modules/.pnpm/typescript@6.0.2/node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","../../../node_modules/.pnpm/typescript@6.0.2/node_modules/typescript/lib/lib.es2018.intl.d.ts","../../../node_modules/.pnpm/typescript@6.0.2/node_modules/typescript/lib/lib.es2018.promise.d.ts","../../../node_modules/.pnpm/typescript@6.0.2/node_modules/typescript/lib/lib.es2018.regexp.d.ts","../../../node_modules/.pnpm/typescript@6.0.2/node_modules/typescript/lib/lib.es2019.array.d.ts","../../../node_modules/.pnpm/typescript@6.0.2/node_modules/typescript/lib/lib.es2019.object.d.ts","../../../node_modules/.pnpm/typescript@6.0.2/node_modules/typescript/lib/lib.es2019.string.d.ts","../../../node_modules/.pnpm/typescript@6.0.2/node_modules/typescript/lib/lib.es2019.symbol.d.ts","../../../node_modules/.pnpm/typescript@6.0.2/node_modules/typescript/lib/lib.es2019.intl.d.ts","../../../node_modules/.pnpm/typescript@6.0.2/node_modules/typescript/lib/lib.es2020.bigint.d.ts","../../../node_modules/.pnpm/typescript@6.0.2/node_modules/typescript/lib/lib.es2020.date.d.ts","../../../node_modules/.pnpm/typescript@6.0.2/node_modules/typescript/lib/lib.es2020.promise.d.ts","../../../node_modules/.pnpm/typescript@6.0.2/node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts","../../../node_modules/.pnpm/typescript@6.0.2/node_modules/typescript/lib/lib.es2020.string.d.ts","../../../node_modules/.pnpm/typescript@6.0.2/node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts","../../../node_modules/.pnpm/typescript@6.0.2/node_modules/typescript/lib/lib.es2020.intl.d.ts","../../../node_modules/.pnpm/typescript@6.0.2/node_modules/typescript/lib/lib.es2020.number.d.ts","../../../node_modules/.pnpm/typescript@6.0.2/node_modules/typescript/lib/lib.es2021.promise.d.ts","../../../node_modules/.pnpm/typescript@6.0.2/node_modules/typescript/lib/lib.es2021.string.d.ts","../../../node_modules/.pnpm/typescript@6.0.2/node_modules/typescript/lib/lib.es2021.weakref.d.ts","../../../node_modules/.pnpm/typescript@6.0.2/node_modules/typescript/lib/lib.es2021.intl.d.ts","../../../node_modules/.pnpm/typescript@6.0.2/node_modules/typescript/lib/lib.es2022.array.d.ts","../../../node_modules/.pnpm/typescript@6.0.2/node_modules/typescript/lib/lib.es2022.error.d.ts","../../../node_modules/.pnpm/typescript@6.0.2/node_modules/typescript/lib/lib.es2022.intl.d.ts","../../../node_modules/.pnpm/typescript@6.0.2/node_modules/typescript/lib/lib.es2022.object.d.ts","../../../node_modules/.pnpm/typescript@6.0.2/node_modules/typescript/lib/lib.es2022.string.d.ts","../../../node_modules/.pnpm/typescript@6.0.2/node_modules/typescript/lib/lib.es2022.regexp.d.ts","../../../node_modules/.pnpm/typescript@6.0.2/node_modules/typescript/lib/lib.decorators.d.ts","../../../node_modules/.pnpm/typescript@6.0.2/node_modules/typescript/lib/lib.decorators.legacy.d.ts","../../exception/lib/code.d.ts","../../exception/lib/error.d.ts","../../exception/lib/index.d.ts","../src/context/slice.ts","../src/context/container.ts","../src/context/index.ts","../src/inspector/meta.ts","../src/timer/timer.ts","../src/timer/clock.ts","../src/timer/index.ts","../src/inspector/inspector.ts","../src/inspector/index.ts","../src/plugin/ctx.ts","../src/plugin/types.ts","../src/plugin/index.ts","../src/index.ts"],"fileIdsList":[[61,62],[62,63],[61,63],[64,68,70,73],[65,69],[64,65,68],[64,68,70],[71,72],[70,71],[61,66],[66,67],[67],[59],[60]],"fileInfos":[{"version":"bcd24271a113971ba9eb71ff8cb01bc6b0f872a85c23fdbe5d93065b375933cd","affectsGlobalScope":true,"impliedFormat":1},{"version":"3f88bedbeb09c6f5a6645cb24c7c55f1aa22d19ae96c8e6959cbd8b85a707bc6","impliedFormat":1},{"version":"7fe93b39b810eadd916be8db880dd7f0f7012a5cc6ffb62de8f62a2117fa6f1f","impliedFormat":1},{"version":"bb0074cc08b84a2374af33d8bf044b80851ccc9e719a5e202eacf40db2c31600","impliedFormat":1},{"version":"1a7daebe4f45fb03d9ec53d60008fbf9ac45a697fdc89e4ce218bc94b94f94d6","impliedFormat":1},{"version":"f94b133a3cb14a288803be545ac2683e0d0ff6661bcd37e31aaaec54fc382aed","impliedFormat":1},{"version":"f59d0650799f8782fd74cf73c19223730c6d1b9198671b1c5b3a38e1188b5953","impliedFormat":1},{"version":"8a15b4607d9a499e2dbeed9ec0d3c0d7372c850b2d5f1fb259e8f6d41d468a84","impliedFormat":1},{"version":"26e0fe14baee4e127f4365d1ae0b276f400562e45e19e35fd2d4c296684715e6","impliedFormat":1},{"version":"d6b1eba8496bdd0eed6fc8a685768fe01b2da4a0388b5fe7df558290bffcf32f","affectsGlobalScope":true,"impliedFormat":1},{"version":"eadcffda2aa84802c73938e589b9e58248d74c59cb7fcbca6474e3435ac15504","affectsGlobalScope":true,"impliedFormat":1},{"version":"105ba8ff7ba746404fe1a2e189d1d3d2e0eb29a08c18dded791af02f29fb4711","affectsGlobalScope":true,"impliedFormat":1},{"version":"00343ca5b2e3d48fa5df1db6e32ea2a59afab09590274a6cccb1dbae82e60c7c","affectsGlobalScope":true,"impliedFormat":1},{"version":"ebd9f816d4002697cb2864bea1f0b70a103124e18a8cd9645eeccc09bdf80ab4","affectsGlobalScope":true,"impliedFormat":1},{"version":"2c1afac30a01772cd2a9a298a7ce7706b5892e447bb46bdbeef720f7b5da77ad","affectsGlobalScope":true,"impliedFormat":1},{"version":"7b0225f483e4fa685625ebe43dd584bb7973bbd84e66a6ba7bbe175ee1048b4f","affectsGlobalScope":true,"impliedFormat":1},{"version":"c0a4b8ac6ce74679c1da2b3795296f5896e31c38e888469a8e0f99dc3305de60","affectsGlobalScope":true,"impliedFormat":1},{"version":"3084a7b5f569088e0146533a00830e206565de65cae2239509168b11434cd84f","affectsGlobalScope":true,"impliedFormat":1},{"version":"c5079c53f0f141a0698faa903e76cb41cd664e3efb01cc17a5c46ec2eb0bef42","affectsGlobalScope":true,"impliedFormat":1},{"version":"32cafbc484dea6b0ab62cf8473182bbcb23020d70845b406f80b7526f38ae862","affectsGlobalScope":true,"impliedFormat":1},{"version":"fca4cdcb6d6c5ef18a869003d02c9f0fd95df8cfaf6eb431cd3376bc034cad36","affectsGlobalScope":true,"impliedFormat":1},{"version":"b93ec88115de9a9dc1b602291b85baf825c85666bf25985cc5f698073892b467","affectsGlobalScope":true,"impliedFormat":1},{"version":"f5c06dcc3fe849fcb297c247865a161f995cc29de7aa823afdd75aaaddc1419b","affectsGlobalScope":true,"impliedFormat":1},{"version":"b77e16112127a4b169ef0b8c3a4d730edf459c5f25fe52d5e436a6919206c4d7","affectsGlobalScope":true,"impliedFormat":1},{"version":"fbffd9337146eff822c7c00acbb78b01ea7ea23987f6c961eba689349e744f8c","affectsGlobalScope":true,"impliedFormat":1},{"version":"a995c0e49b721312f74fdfb89e4ba29bd9824c770bbb4021d74d2bf560e4c6bd","affectsGlobalScope":true,"impliedFormat":1},{"version":"c7b3542146734342e440a84b213384bfa188835537ddbda50d30766f0593aff9","affectsGlobalScope":true,"impliedFormat":1},{"version":"ce6180fa19b1cccd07ee7f7dbb9a367ac19c0ed160573e4686425060b6df7f57","affectsGlobalScope":true,"impliedFormat":1},{"version":"3f02e2476bccb9dbe21280d6090f0df17d2f66b74711489415a8aa4df73c9675","affectsGlobalScope":true,"impliedFormat":1},{"version":"45e3ab34c1c013c8ab2dc1ba4c80c780744b13b5676800ae2e3be27ae862c40c","affectsGlobalScope":true,"impliedFormat":1},{"version":"805c86f6cca8d7702a62a844856dbaa2a3fd2abef0536e65d48732441dde5b5b","affectsGlobalScope":true,"impliedFormat":1},{"version":"e42e397f1a5a77994f0185fd1466520691456c772d06bf843e5084ceb879a0ad","affectsGlobalScope":true,"impliedFormat":1},{"version":"f4c2b41f90c95b1c532ecc874bd3c111865793b23aebcc1c3cbbabcd5d76ffb0","affectsGlobalScope":true,"impliedFormat":1},{"version":"ab26191cfad5b66afa11b8bf935ef1cd88fabfcb28d30b2dfa6fad877d050332","affectsGlobalScope":true,"impliedFormat":1},{"version":"2088bc26531e38fb05eedac2951480db5309f6be3fa4a08d2221abb0f5b4200d","affectsGlobalScope":true,"impliedFormat":1},{"version":"cb9d366c425fea79716a8fb3af0d78e6b22ebbab3bd64d25063b42dc9f531c1e","affectsGlobalScope":true,"impliedFormat":1},{"version":"500934a8089c26d57ebdb688fc9757389bb6207a3c8f0674d68efa900d2abb34","affectsGlobalScope":true,"impliedFormat":1},{"version":"689da16f46e647cef0d64b0def88910e818a5877ca5379ede156ca3afb780ac3","affectsGlobalScope":true,"impliedFormat":1},{"version":"bc21cc8b6fee4f4c2440d08035b7ea3c06b3511314c8bab6bef7a92de58a2593","affectsGlobalScope":true,"impliedFormat":1},{"version":"7ca53d13d2957003abb47922a71866ba7cb2068f8d154877c596d63c359fed25","affectsGlobalScope":true,"impliedFormat":1},{"version":"54725f8c4df3d900cb4dac84b64689ce29548da0b4e9b7c2de61d41c79293611","affectsGlobalScope":true,"impliedFormat":1},{"version":"e5594bc3076ac29e6c1ebda77939bc4c8833de72f654b6e376862c0473199323","affectsGlobalScope":true,"impliedFormat":1},{"version":"2f3eb332c2d73e729f3364fcc0c2b375e72a121e8157d25a82d67a138c83a95c","affectsGlobalScope":true,"impliedFormat":1},{"version":"6f4427f9642ce8d500970e4e69d1397f64072ab73b97e476b4002a646ac743b1","affectsGlobalScope":true,"impliedFormat":1},{"version":"48915f327cd1dea4d7bd358d9dc7732f58f9e1626a29cc0c05c8c692419d9bb7","affectsGlobalScope":true,"impliedFormat":1},{"version":"b7bf9377723203b5a6a4b920164df22d56a43f593269ba6ae1fdc97774b68855","affectsGlobalScope":true,"impliedFormat":1},{"version":"db9709688f82c9e5f65a119c64d835f906efe5f559d08b11642d56eb85b79357","affectsGlobalScope":true,"impliedFormat":1},{"version":"4b25b8c874acd1a4cf8444c3617e037d444d19080ac9f634b405583fd10ce1f7","affectsGlobalScope":true,"impliedFormat":1},{"version":"37be57d7c90cf1f8112ee2636a068d8fd181289f82b744160ec56a7dc158a9f5","affectsGlobalScope":true,"impliedFormat":1},{"version":"a917a49ac94cd26b754ab84e113369a75d1a47a710661d7cd25e961cc797065f","affectsGlobalScope":true,"impliedFormat":1},{"version":"6d3261badeb7843d157ef3e6f5d1427d0eeb0af0cf9df84a62cfd29fd47ac86e","affectsGlobalScope":true,"impliedFormat":1},{"version":"195daca651dde22f2167ac0d0a05e215308119a3100f5e6268e8317d05a92526","affectsGlobalScope":true,"impliedFormat":1},{"version":"8b11e4285cd2bb164a4dc09248bdec69e9842517db4ca47c1ba913011e44ff2f","affectsGlobalScope":true,"impliedFormat":1},{"version":"0508571a52475e245b02bc50fa1394065a0a3d05277fbf5120c3784b85651799","affectsGlobalScope":true,"impliedFormat":1},{"version":"8f9af488f510c3015af3cc8c267a9e9d96c4dd38a1fdff0e11dc5a544711415b","affectsGlobalScope":true,"impliedFormat":1},{"version":"fc611fea8d30ea72c6bbfb599c9b4d393ce22e2f5bfef2172534781e7d138104","affectsGlobalScope":true,"impliedFormat":1},{"version":"1ce14b81c5cc821994aa8ec1d42b220dd41b27fcc06373bce3958af7421b77d4","affectsGlobalScope":true,"impliedFormat":1},{"version":"b3a048b3e9302ef9a34ef4ebb9aecfb28b66abb3bce577206a79fee559c230da","affectsGlobalScope":true,"impliedFormat":1},"16976e5481a0abbe56fa82010ecd47c152e76d9c7ecb5977d68a1b2c4a785c91","749f3bd08d4fc5cc1c95e3c3b07dede327898a51cf6fa7f156456c0d46aae680","7797184093e9b9f6203d001829de6f91d142497913c67a8d0c2a5b25de005a68",{"version":"cf4c98934824d35e5a2ef06c4c1799c3bc1421900db41ef744d60b2cf18378c5","signature":"73cc073d7a102374d6b9bcdbde8072f3aa3c8f86767f562086b6a7a7df5f22c0"},{"version":"6ad519f7ace29333c47a9d9c25bf7766d8fce0fc2cf556e89e78c1af24e29bb1","signature":"e66deb230968faf1a8f37ea6f217f319dd0dad7a39ead1bf5d4f54e2eb5ce4bd"},{"version":"31c15ca020a468b062345e7bf263fe16622b93ca6bc1fc943630a2fe197cf511","signature":"13ee17bbdd42459d6450899cea1999aab64c723328e773c0be5e8a13b51b6259"},{"version":"5a27b3925ca8b0a58794fbbacd3dfae1113b676979230b37612d72252ce51d11","signature":"f79062b892847b4e33d0b730bf9dcf66ac24fc3fe9df7bba4d0997c6bdf6cbde"},{"version":"65b692379966937cf1863bd64b2ec57c7e575de5518f5549ca670095f687dcda","signature":"20f3a5481b2c009533e9e6b864cbd4ae3c09ccfca0577918b3587cda295e7071"},{"version":"79f8702aa7d43504af56c523d91bda3d060008ab5243eb5d6d2eeca298c90b72","signature":"2797c77cc0da0836a37c8c1fe64942a999c73f811f5481d827ac7d8cb9ddedd3"},{"version":"292fc38fb383d47e9d8dd8941235f354e606faac105143ed81dd78d90033589e","signature":"5a40849c3a5d5a8c2aa754fc964830ea344c94bfeddd4b442bdeae899e2f5339"},{"version":"07a42f0a1613e5187543e56c9563074967b77a2e7cfd4784204ad3701eeff9ba","signature":"848836f528d4ac80a5b3212c719225a3ba09406d44fea755cb642299a68d7056"},{"version":"d45d22702668d59115e20a1cfe31c900075793b9d9c1fb5882b0334d67a4e131","signature":"fae981646738728f2b882c14625b99c23c430400a21c081dc6888d9703bd6c68"},{"version":"833c482b58ca2a19aca66536b91d9bea1cdfb70e57aa3080b123ef57c4afc95e","signature":"45c8a077eb724bae4e1fc0d15f76618650e32e55c4582dc1f27153ecdeb66ca6"},{"version":"1fbf481d450190d94b4cea4cebc804c5aba634edc0508fc4368b67f499564f90","signature":"302c082712d8fe41be387cd34af45b163b5314c04ddeefe53b1cb57fe46d3221"},{"version":"f5eb10be93889183b7cd2d56967fb7e3b8fe2f9bb285023aad8f59ce2a035ced","signature":"0c1a84d7b974db1961c6e9ab71d5257dfa38d99fb6300f22de55750526c9daef"},{"version":"d424774467c3f2a18a033a8dff60f945d9baadc1f236e095cd39078de7fa7d0e","signature":"69bc40bb169ea922cab72dc2142f37e75b44095cf1e79ca1b2809164c284de57"}],"root":[[62,74]],"options":{"composite":true,"declaration":true,"declarationMap":true,"emitDeclarationOnly":true,"esModuleInterop":true,"module":99,"noEmitOnError":true,"noFallthroughCasesInSwitch":true,"noImplicitOverride":true,"noImplicitReturns":true,"noPropertyAccessFromIndexSignature":false,"noUncheckedIndexedAccess":true,"noUnusedLocals":true,"noUnusedParameters":true,"outDir":"./","rootDir":"../src","skipLibCheck":true,"sourceMap":true,"strict":true,"target":5,"tsBuildInfoFile":"./tsconfig.tsbuildinfo","useUnknownInCatchVariables":true,"verbatimModuleSyntax":true},"referencedMap":[[63,1],[64,2],[62,3],[74,4],[70,5],[69,6],[71,7],[73,8],[72,9],[67,10],[68,11],[66,12],[60,13],[61,14]],"latestChangedDtsFile":"./index.d.ts","version":"6.0.2"}
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@jvs-milkdown/ctx",
3
+ "version": "1.0.0",
4
+ "keywords": [
5
+ "markdown",
6
+ "markdown editor",
7
+ "milkdown",
8
+ "prosemirror",
9
+ "remark",
10
+ "text editor",
11
+ "wysiwyg"
12
+ ],
13
+ "license": "MIT",
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/Milkdown/milkdown.git",
17
+ "directory": "packages/ctx"
18
+ },
19
+ "files": [
20
+ "lib",
21
+ "src"
22
+ ],
23
+ "type": "module",
24
+ "sideEffects": false,
25
+ "main": "./lib/index.js",
26
+ "exports": {
27
+ ".": {
28
+ "import": "./lib/index.js",
29
+ "types": "./lib/index.d.ts"
30
+ }
31
+ },
32
+ "dependencies": {
33
+ "@jvs-milkdown/exception": "1.0.0"
34
+ },
35
+ "scripts": {
36
+ "build": "vite build"
37
+ },
38
+ "types": "./lib/index.d.ts"
39
+ }
@@ -0,0 +1,54 @@
1
+ import { describe, expect, it } from 'vitest'
2
+
3
+ import { Container, SliceType } from '.'
4
+
5
+ describe('context/container', () => {
6
+ it('sliceMap', () => {
7
+ const container = new Container()
8
+
9
+ expect(container.sliceMap).toEqual(new Map())
10
+ })
11
+
12
+ it('getSlice', () => {
13
+ const container = new Container()
14
+ const ctx = new SliceType(0, 'num')
15
+
16
+ ctx.create(container.sliceMap)
17
+
18
+ expect(container.get(ctx).type.id).toBe(ctx.id)
19
+ expect(container.get(ctx).get()).toBe(0)
20
+
21
+ container.get(ctx).set(10)
22
+
23
+ expect(container.get(ctx).get()).toBe(10)
24
+
25
+ expect(container.get<number>('num').get()).toBe(10)
26
+ })
27
+
28
+ it('removeSlice', () => {
29
+ const container = new Container()
30
+ const ctx = new SliceType(0, 'num')
31
+
32
+ ctx.create(container.sliceMap)
33
+
34
+ expect(container.get(ctx).type.id).toBe(ctx.id)
35
+ expect(container.get(ctx).get()).toBe(0)
36
+
37
+ container.remove(ctx)
38
+
39
+ expect(() => container.get(ctx)).toThrow()
40
+ })
41
+
42
+ it('hasSlice', () => {
43
+ const container = new Container()
44
+ const ctx = new SliceType(0, 'num')
45
+
46
+ ctx.create(container.sliceMap)
47
+
48
+ expect(container.has(ctx)).toBeTruthy()
49
+
50
+ container.remove(ctx)
51
+
52
+ expect(container.has(ctx)).toBeFalsy()
53
+ })
54
+ })
@@ -0,0 +1,48 @@
1
+ import { contextNotFound } from '@jvs-milkdown/exception'
2
+
3
+ import type { Slice, SliceType } from './slice'
4
+
5
+ /// @internal
6
+ export type SliceMap = Map<symbol, Slice>
7
+
8
+ /// Container is a map of slices.
9
+ export class Container {
10
+ /// @internal
11
+ sliceMap: SliceMap = new Map()
12
+
13
+ /// Get a slice from the container by slice type or slice name.
14
+ get = <T, N extends string = string>(
15
+ slice: SliceType<T, N> | N
16
+ ): Slice<T, N> => {
17
+ const context =
18
+ typeof slice === 'string'
19
+ ? [...this.sliceMap.values()].find((x) => x.type.name === slice)
20
+ : this.sliceMap.get(slice.id)
21
+
22
+ if (!context) {
23
+ const name = typeof slice === 'string' ? slice : slice.name
24
+ throw contextNotFound(name)
25
+ }
26
+ return context as Slice<T, N>
27
+ }
28
+
29
+ /// Remove a slice from the container by slice type or slice name.
30
+ remove = <T, N extends string = string>(slice: SliceType<T, N> | N): void => {
31
+ const context =
32
+ typeof slice === 'string'
33
+ ? [...this.sliceMap.values()].find((x) => x.type.name === slice)
34
+ : this.sliceMap.get(slice.id)
35
+
36
+ if (!context) return
37
+
38
+ this.sliceMap.delete(context.type.id)
39
+ }
40
+
41
+ /// Check if the container has a slice by slice type or slice name.
42
+ has = <T, N extends string = string>(slice: SliceType<T, N> | N): boolean => {
43
+ if (typeof slice === 'string')
44
+ return [...this.sliceMap.values()].some((x) => x.type.name === slice)
45
+
46
+ return this.sliceMap.has(slice.id)
47
+ }
48
+ }
@@ -0,0 +1,2 @@
1
+ export * from './container'
2
+ export * from './slice'
@@ -0,0 +1,116 @@
1
+ import { describe, expect, it, vi } from 'vitest'
2
+
3
+ import { SliceType } from './slice'
4
+
5
+ describe('context/slice', () => {
6
+ it('primitive slice', () => {
7
+ const sliceType = new SliceType(0, 'primitive')
8
+ const map = new Map()
9
+ const ctx = sliceType.create(map)
10
+
11
+ expect(sliceType.name).toBe('primitive')
12
+ expect(sliceType.id).toBeTypeOf('symbol')
13
+ expect(ctx.type.name).toBe('primitive')
14
+ expect(ctx.type.id).toBe(sliceType.id)
15
+
16
+ expect(ctx.get()).toBe(0)
17
+
18
+ ctx.set(20)
19
+ expect(ctx.get()).toBe(20)
20
+
21
+ ctx.update((x) => x + 1)
22
+ expect(ctx.get()).toBe(21)
23
+ })
24
+
25
+ it('structure slice', () => {
26
+ const sliceType = new SliceType<number[], 'structure'>([], 'structure')
27
+ expect(sliceType.name).toBe('structure')
28
+
29
+ const map1 = new Map()
30
+ const slice1 = sliceType.create(map1)
31
+ expect(slice1.type.id).toBe(sliceType.id)
32
+
33
+ expect(slice1.type.name).toBe('structure')
34
+
35
+ const map2 = new Map()
36
+ const slice2 = sliceType.create(map2)
37
+
38
+ expect(slice2.type.name).toBe('structure')
39
+ expect(slice2.type.id).toBe(sliceType.id)
40
+
41
+ expect(slice1.get()).toEqual([])
42
+ slice1.set([1])
43
+ expect(slice1.get()).toEqual([1])
44
+
45
+ expect(slice2.get()).toEqual([])
46
+
47
+ slice1.update((x) => x.concat(3))
48
+ expect(slice1.get()).toEqual([1, 3])
49
+
50
+ expect(slice2.get()).toEqual([])
51
+ })
52
+
53
+ it('add watcher for slice', () => {
54
+ const sliceType = new SliceType(0, 'primitive')
55
+ const map = new Map()
56
+ const ctx = sliceType.create(map)
57
+
58
+ let recordedValue1: number
59
+ let recordedValue2: number
60
+ let recordedValue3: number
61
+ let recordedValue4: number
62
+ const watcher1 = vi.fn((value: number) => {
63
+ recordedValue1 = value
64
+ })
65
+ const watcher2 = vi.fn((value: number) => {
66
+ recordedValue2 = value
67
+ })
68
+ const watcher3 = vi.fn((value: number) => {
69
+ recordedValue3 = value
70
+ })
71
+ const watcher4 = vi.fn((value: number) => {
72
+ recordedValue4 = value
73
+ })
74
+ const off = ctx.on(watcher1)
75
+ ctx.on(watcher2)
76
+ ctx.once(watcher3)
77
+ ctx.on(watcher4)
78
+
79
+ ctx.set(20)
80
+ expect(watcher1).toBeCalledTimes(1)
81
+ expect(recordedValue1).toBe(20)
82
+ expect(watcher2).toBeCalledTimes(1)
83
+ expect(recordedValue2).toBe(20)
84
+ expect(watcher3).toBeCalledTimes(1)
85
+ expect(recordedValue3).toBe(20)
86
+
87
+ ctx.set(100)
88
+ expect(watcher1).toBeCalledTimes(2)
89
+ expect(recordedValue1).toBe(100)
90
+ expect(watcher2).toBeCalledTimes(2)
91
+ expect(recordedValue2).toBe(100)
92
+ expect(watcher3).toBeCalledTimes(1)
93
+ expect(recordedValue3).toBe(20)
94
+
95
+ off()
96
+ ctx.set(1000)
97
+ expect(watcher1).toBeCalledTimes(2)
98
+ expect(recordedValue1).toBe(100)
99
+ expect(watcher2).toBeCalledTimes(3)
100
+ expect(recordedValue2).toBe(1000)
101
+ expect(watcher3).toBeCalledTimes(1)
102
+ expect(recordedValue3).toBe(20)
103
+
104
+ ctx.off(watcher2)
105
+ ctx.set(0)
106
+ expect(watcher2).toBeCalledTimes(3)
107
+ expect(recordedValue2).toBe(1000)
108
+ expect(watcher4).toBeCalledTimes(4)
109
+ expect(recordedValue4).toBe(0)
110
+
111
+ ctx.offAll()
112
+ ctx.set(5)
113
+ expect(watcher4).toBeCalledTimes(4)
114
+ expect(recordedValue4).toBe(0)
115
+ })
116
+ })
@@ -0,0 +1,108 @@
1
+ import { ctxCallOutOfScope } from '@jvs-milkdown/exception'
2
+
3
+ import type { SliceMap } from './container'
4
+
5
+ /// Slice is a value of slice type.
6
+ export class Slice<T = any, N extends string = string> {
7
+ /// The type of the slice.
8
+ readonly type: SliceType<T, N>
9
+
10
+ /// @internal
11
+ #watchers: Array<(value: T) => unknown> = []
12
+
13
+ /// @internal
14
+ #value: T
15
+
16
+ /// @internal
17
+ #emit = () => {
18
+ this.#watchers.forEach((watcher) => watcher(this.#value))
19
+ }
20
+
21
+ /// @internal
22
+ constructor(container: SliceMap, value: T, type: SliceType<T, N>) {
23
+ this.type = type
24
+ this.#value = value
25
+ container.set(type.id, this)
26
+ }
27
+
28
+ /// Add a watcher for changes in the slice.
29
+ /// Returns a function to remove the watcher.
30
+ on(watcher: (value: T) => unknown) {
31
+ this.#watchers.push(watcher)
32
+ return () => {
33
+ this.#watchers = this.#watchers.filter((w) => w !== watcher)
34
+ }
35
+ }
36
+
37
+ /// Add a one-time watcher for changes in the slice.
38
+ /// The watcher will be removed after it is called.
39
+ /// Returns a function to remove the watcher.
40
+ once(watcher: (value: T) => unknown) {
41
+ const off = this.on((value) => {
42
+ watcher(value)
43
+ off()
44
+ })
45
+ return off
46
+ }
47
+
48
+ /// Remove a watcher.
49
+ off(watcher: (value: T) => unknown) {
50
+ this.#watchers = this.#watchers.filter((w) => w !== watcher)
51
+ }
52
+
53
+ /// Remove all watchers.
54
+ offAll() {
55
+ this.#watchers = []
56
+ }
57
+
58
+ /// Set the value of the slice.
59
+ set = (value: T) => {
60
+ this.#value = value
61
+ this.#emit()
62
+ }
63
+
64
+ /// Get the value of the slice.
65
+ get = () => this.#value
66
+
67
+ /// Update the value of the slice with a callback.
68
+ update = (updater: (prev: T) => T) => {
69
+ this.#value = updater(this.#value)
70
+ this.#emit()
71
+ }
72
+ }
73
+
74
+ /// Slice type can be used to create slices in different containers.
75
+ export class SliceType<T = any, N extends string = string> {
76
+ /// The unique id of the slice type.
77
+ readonly id: symbol
78
+ /// The name of the slice type.
79
+ readonly name: N
80
+ /// @internal
81
+ readonly _typeInfo: () => T
82
+ /// @internal
83
+ readonly _defaultValue: T
84
+
85
+ /// Create a slice type with a default value and a name.
86
+ /// The name should be unique in the container.
87
+ constructor(value: T, name: N) {
88
+ this.id = Symbol(`Context-${name}`)
89
+ this.name = name
90
+ this._defaultValue = value
91
+ this._typeInfo = (): T => {
92
+ throw ctxCallOutOfScope()
93
+ }
94
+ }
95
+
96
+ /// Create a slice with a container.
97
+ /// You can also pass a value to override the default value.
98
+ create(container: SliceMap, value: T = this._defaultValue): Slice<T, N> {
99
+ return new Slice(container, value, this)
100
+ }
101
+ }
102
+
103
+ /// Create a slice type with a default value and a name.
104
+ /// This is equivalent to `new SliceType(value, name)`.
105
+ export const createSlice = <T = any, N extends string = string>(
106
+ value: T,
107
+ name: N
108
+ ) => new SliceType(value, name)
package/src/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from './context'
2
+ export * from './plugin'
3
+ export * from './timer'
4
+ export * from './inspector'
@@ -0,0 +1,2 @@
1
+ export * from './meta'
2
+ export * from './inspector'
@@ -0,0 +1,124 @@
1
+ import type { Container, SliceType } from '../context'
2
+ import type { Clock, TimerStatus, TimerType } from '../timer'
3
+ import type { Meta } from './meta'
4
+
5
+ export interface Telemetry {
6
+ metadata: Meta
7
+ injectedSlices: { name: string; value: unknown }[]
8
+ consumedSlices: { name: string; value: unknown }[]
9
+ recordedTimers: { name: string; duration: number; status: TimerStatus }[]
10
+ waitTimers: { name: string; duration: number; status: TimerStatus }[]
11
+ }
12
+
13
+ /// The inspector object that is used to inspect the runtime environment of a ctx.
14
+ export class Inspector {
15
+ /// @internal
16
+ readonly #meta: Meta
17
+
18
+ /// @internal
19
+ readonly #container: Container
20
+
21
+ /// @internal
22
+ readonly #clock: Clock
23
+
24
+ /// @internal
25
+ readonly #injectedSlices: Set<SliceType | string> = new Set()
26
+
27
+ /// @internal
28
+ readonly #consumedSlices: Set<SliceType | string> = new Set()
29
+
30
+ /// @internal
31
+ readonly #recordedTimers: Map<
32
+ TimerType,
33
+ { duration: number; start: number }
34
+ > = new Map()
35
+
36
+ /// @internal
37
+ readonly #waitTimers: Map<TimerType, { duration: number }> = new Map()
38
+
39
+ /// Create an inspector with container, clock and metadata.
40
+ constructor(container: Container, clock: Clock, meta: Meta) {
41
+ this.#container = container
42
+ this.#clock = clock
43
+ this.#meta = meta
44
+ }
45
+
46
+ /// Read the runtime telemetry as an object of the ctx.
47
+ read = (): Telemetry => {
48
+ return {
49
+ metadata: this.#meta,
50
+ injectedSlices: [...this.#injectedSlices].map((slice) => ({
51
+ name: typeof slice === 'string' ? slice : slice.name,
52
+ value: this.#getSlice(slice),
53
+ })),
54
+ consumedSlices: [...this.#consumedSlices].map((slice) => ({
55
+ name: typeof slice === 'string' ? slice : slice.name,
56
+ value: this.#getSlice(slice),
57
+ })),
58
+ recordedTimers: [...this.#recordedTimers].map(
59
+ ([timer, { duration }]) => ({
60
+ name: timer.name,
61
+ duration,
62
+ status: this.#getTimer(timer),
63
+ })
64
+ ),
65
+ waitTimers: [...this.#waitTimers].map(([timer, { duration }]) => ({
66
+ name: timer.name,
67
+ duration,
68
+ status: this.#getTimer(timer),
69
+ })),
70
+ }
71
+ }
72
+
73
+ /// @internal
74
+ readonly onRecord = (timerType: TimerType) => {
75
+ this.#recordedTimers.set(timerType, { start: Date.now(), duration: 0 })
76
+ }
77
+
78
+ /// @internal
79
+ readonly onClear = (timerType: TimerType) => {
80
+ this.#recordedTimers.delete(timerType)
81
+ }
82
+
83
+ /// @internal
84
+ readonly onDone = (timerType: TimerType) => {
85
+ const timer = this.#recordedTimers.get(timerType)
86
+ if (!timer) return
87
+ timer.duration = Date.now() - timer.start
88
+ }
89
+
90
+ /// @internal
91
+ readonly onWait = (timerType: TimerType, promise: Promise<void>) => {
92
+ const start = Date.now()
93
+ promise
94
+ .finally(() => {
95
+ this.#waitTimers.set(timerType, { duration: Date.now() - start })
96
+ })
97
+ .catch(console.error)
98
+ }
99
+
100
+ /// @internal
101
+ readonly onInject = (sliceType: SliceType | string) => {
102
+ this.#injectedSlices.add(sliceType)
103
+ }
104
+
105
+ /// @internal
106
+ readonly onRemove = (sliceType: SliceType | string) => {
107
+ this.#injectedSlices.delete(sliceType)
108
+ }
109
+
110
+ /// @internal
111
+ readonly onUse = (sliceType: SliceType | string) => {
112
+ this.#consumedSlices.add(sliceType)
113
+ }
114
+
115
+ /// @internal
116
+ #getSlice = (sliceType: SliceType | string) => {
117
+ return this.#container.get(sliceType).get()
118
+ }
119
+
120
+ /// @internal
121
+ #getTimer = (timerType: TimerType) => {
122
+ return this.#clock.get(timerType).status
123
+ }
124
+ }
@@ -0,0 +1,17 @@
1
+ /// The metadata of the plugin.
2
+ export interface Meta {
3
+ /// The name of the plugin
4
+ displayName: string
5
+
6
+ /// The description of the plugin
7
+ description?: string
8
+
9
+ /// The package that the plugin belongs to
10
+ package: string
11
+
12
+ /// The group of the plugin, internal plugins will be grouped by `System`
13
+ group?: string
14
+
15
+ /// Any additional metadata
16
+ additional?: Record<string, any>
17
+ }
@@ -0,0 +1,110 @@
1
+ import { describe, expect, it } from 'vitest'
2
+
3
+ import { Container, createSlice } from '../context'
4
+ import { Clock, createTimer } from '../timer'
5
+ import { Ctx } from './ctx'
6
+
7
+ describe('ctx', () => {
8
+ const container = new Container()
9
+ const clock = new Clock()
10
+ const ctx = new Ctx(container, clock)
11
+
12
+ it('slice', () => {
13
+ const sliceType = createSlice(0, 'counter')
14
+
15
+ expect(ctx.isInjected(sliceType)).toBeFalsy()
16
+ ctx.inject(sliceType)
17
+ expect(ctx.isInjected(sliceType)).toBeTruthy()
18
+ expect(ctx.get(sliceType)).toBe(0)
19
+
20
+ ctx.update(sliceType, (x) => x + 1)
21
+ expect(ctx.get(sliceType)).toBe(1)
22
+
23
+ ctx.update<number, 'counter'>('counter', (x) => x + 1)
24
+ expect(ctx.get(sliceType)).toBe(2)
25
+
26
+ ctx.set(sliceType, 100)
27
+ expect(ctx.get(sliceType)).toBe(100)
28
+
29
+ ctx.set<number, 'counter'>(sliceType, 200)
30
+ expect(ctx.get(sliceType)).toBe(200)
31
+
32
+ ctx.remove(sliceType)
33
+ expect(ctx.isInjected(sliceType)).toBeFalsy()
34
+ expect(() => ctx.get(sliceType)).toThrow()
35
+ })
36
+
37
+ it('timer', async () => {
38
+ const timerType = createTimer('timer')
39
+
40
+ expect(ctx.isRecorded(timerType)).toBeFalsy()
41
+ ctx.record(timerType)
42
+ expect(ctx.isRecorded(timerType)).toBeTruthy()
43
+
44
+ setTimeout(() => {
45
+ ctx.done(timerType)
46
+ }, 10)
47
+
48
+ await expect(ctx.wait(timerType)).resolves.toBeUndefined()
49
+ })
50
+
51
+ it('produce', async () => {
52
+ const same = ctx.produce()
53
+ expect(same).toBe(ctx)
54
+
55
+ const different = ctx.produce({ displayName: 'test', package: 'test' })
56
+ expect(different).not.toBe(ctx)
57
+
58
+ const sliceType = createSlice('Foo', 'message')
59
+ different.inject(sliceType)
60
+
61
+ expect(same.get(sliceType)).toBe('Foo')
62
+ expect(different.inspector?.read().injectedSlices[0]).toEqual({
63
+ name: 'message',
64
+ value: 'Foo',
65
+ })
66
+
67
+ expect(ctx.inspector?.read().injectedSlices).toBeUndefined()
68
+
69
+ const sliceType2 = createSlice(true, 'boolean')
70
+ same.inject(sliceType2)
71
+
72
+ expect(different.get(sliceType2)).toBe(true)
73
+ expect(different.inspector?.read().consumedSlices[0]).toEqual({
74
+ name: 'boolean',
75
+ value: true,
76
+ })
77
+
78
+ const timerType1 = createTimer('timer1')
79
+ different.record(timerType1)
80
+
81
+ setTimeout(() => {
82
+ different.done(timerType1)
83
+ }, 20)
84
+
85
+ await expect(ctx.wait(timerType1)).resolves.toBeUndefined()
86
+
87
+ expect(different.inspector?.read().recordedTimers[0].name).toBe('timer1')
88
+ expect(
89
+ different.inspector?.read().recordedTimers[0].duration
90
+ ).toBeGreaterThan(0)
91
+ expect(different.inspector?.read().recordedTimers[0].status).toBe(
92
+ 'resolved'
93
+ )
94
+
95
+ const timerType2 = createTimer('timer2')
96
+ ctx.record(timerType2)
97
+
98
+ setTimeout(() => {
99
+ ctx.done(timerType2)
100
+ }, 10)
101
+
102
+ await expect(different.wait(timerType2)).resolves.toBeUndefined()
103
+
104
+ expect(different.inspector?.read().waitTimers[0].name).toBe('timer2')
105
+ expect(different.inspector?.read().waitTimers[0].duration).toBeGreaterThan(
106
+ 0
107
+ )
108
+ expect(different.inspector?.read().waitTimers[0].status).toBe('resolved')
109
+ })
110
+ })