@ghentcdh/annotation-api 0.0.1-alpha.1 → 0.0.1-alpha.10

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/index.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@nestjs/common"),t=require("zod"),n=require("@ghentcdh/w3c-utils");require("@ghentcdh/annotated-text");let r=require("node:fs"),i=require("node:path"),a=require("@nestjs/swagger");var o=`AnnotationMetadata`,s=t.z.object({}),c=t.z.object({id:t.z.string(),name:t.z.string(),columns:t.z.array(s),json_schema:t.z.any().optional(),json_ld:t.z.any().optional(),ui_schema:t.z.any().optional(),metadata_schema:t.z.any().optional(),color:t.z.string(),type:t.z.string().optional(),icon:t.z.string().optional(),isRoot:t.z.boolean().default(!0),allowedChildren:t.z.array(t.z.string()).optional(),allowedLinks:t.z.array(t.z.string()).optional(),context:t.z.custom(),target:t.z.enum([`gutter`,`underline`,`highlight`]).optional()}),l={baseUrl:`http://localhost:3000/`,app:`ghentcdh`,prefix:`ghentcdh`,isDev:!1,cacheTTLms:1200*1e3},u=(e={})=>{let t=e.baseUrl??l.baseUrl,n=t.endsWith(`/`)?t:`${t}/`,r=e.isDev??!1,i=r?0:1200*1e3;return{baseUrl:n,contextUrl:`${n}ns/`,app:e.app??l.app,prefix:e.prefix??l.prefix,isDev:r,cacheTTLms:i}},d=(e,t)=>{let{prefix:r,baseUrl:i,contextUrl:a}=u(t),s=o;return(0,n.contextBuilder)(r,i).setType(r,s).addPrefix(e,`${r}:${e}`).setContextUri(`${a}${e}.jsonld`)},f=t.z.object({id:t.z.string(),name:t.z.string(),target:t.z.enum([`gutter`,`underline`,`highlight`]).optional().default(`underline`),color:t.z.string().optional()}),p=`AnnotationStyle`,m=e=>{let{prefix:t,baseUrl:r,contextUrl:i}=u(e);return(0,n.contextBuilder)(t,r).setType(t,p).setContextUri(`${i}${p}.jsonld`).parseZodSchema(f)},h=e=>{let t={};if(e.fieldInput){let{type:n,options:r}=e.fieldInput;t.format=n,n===`autocomplete`&&(t.dataField=`data`,r.uri&&(t.uri=r.uri),r.resource&&(t.resource=r.resource),r.valueKey&&(t.valueKey=r.valueKey),r.labelKey&&(t.labelKey=r.labelKey),r.enableCreate!==void 0&&(t.enableCreate=r.enableCreate))}return{type:`Control`,scope:`#/properties/${e.id}`,options:t}},g=e=>({type:`TextCell`,scope:`#/properties/${e.id}`,options:{format:`keyValue`,key:e.fieldInput?.options?.labelKey??e.displayKey??`label`}}),_=e=>({type:`GridLayout`,elements:e.filter(e=>!e.hiddenInForm).map(h),options:{}}),v=e=>({type:`GridLayout`,elements:e.filter(e=>!e.hiddenInMetadata).map(g),options:{}}),y=e=>{if(e.type===`object`&&e.properties){let n={};for(let[t,r]of Object.entries(e.properties))n[t]=y(r);return t.z.object(n)}return t.z.string()},b=(e,n,r)=>{let i=d(e,r),a=n.columns??[];if(!a.length)return i;let o={};for(let e of a)e.type&&(o[e.id]=y(e.type));return Object.keys(o).length?i.parseZodSchema(t.z.object(o)):i},x=(e,t,n=b)=>{let r=n(e.id,e,t),i=e.columns??[],a=i.length>0,o=e.ui_schema??(a?_(i):void 0),s=e.metadata_schema??(a?v(i):void 0),c={id:e.id,name:e.name,color:e.color,isRoot:e.isRoot??!0,columns:i,context:r,json_ld:r.toJsonLdContext(),json_schema:o?r.toJsonSchema():null};return o&&(c.ui_schema=o),s&&(c.metadata_schema=s),e.type&&(c.type=e.type),e.icon&&(c.icon=e.icon),e.target&&(c.target=e.target),e.allowedChildren&&(c.allowedChildren=e.allowedChildren),e.allowedLinks&&(c.allowedLinks=e.allowedLinks),c},S=Symbol(`ANNOTATION_DEF_CONFIG_TOKEN`);function C(e,t){if(typeof Reflect==`object`&&typeof Reflect.metadata==`function`)return Reflect.metadata(e,t)}function w(e,t){return function(n,r){t(n,r,e)}}function T(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}var E=class{config;definitions=[];groupedDefinitions={};cachedAt=0;constructor(e){this.config=e}async findAllGrouped(){return await this.setDefinitions(),Promise.resolve(this.groupedDefinitions)}async setDefinitions(e=!1){let t=Date.now();if(!e&&this.definitions.length&&t-this.cachedAt<this.config.cacheTTLms)return;let n=await this.reloadDefinitions()??[];this.definitions=n,this.groupedDefinitions=n.reduce((e,t)=>(e[t.id]=t,e),{}),this.cachedAt=t}async findAll(){return await this.setDefinitions(),Promise.resolve(this.definitions)}async findById(t){await this.setDefinitions();let n=this.groupedDefinitions[t];if(n||await this.setDefinitions(!0),n=this.groupedDefinitions[t],!n)throw new e.NotFoundException;return Promise.resolve(n)}async getAllContextBuilders(){return(await this.findAll()).map(e=>e.context)}async getContextBuilder(t){let n=await this.findById(t);if(!n)throw new e.NotFoundException;return n.context}};E=T([(0,e.Injectable)(),w(0,(0,e.Inject)(S)),C(`design:paramtypes`,[Object])],E);var D=class extends E{_initialDefinitions;_loaderFn;constructor(e,t,n){super(e),this._initialDefinitions=t,this._loaderFn=n}reloadDefinitions=()=>this.config.isDev&&this._loaderFn?Promise.resolve(this._loaderFn()):Promise.resolve(this._initialDefinitions??[])};D=T([(0,e.Injectable)(),w(0,(0,e.Inject)(S)),C(`design:paramtypes`,[Object,Array,Object])],D);var O=(e,t,n)=>{if(!(0,r.existsSync)(e))return[];let a=(0,r.readdirSync)(e,{withFileTypes:!0}).filter(e=>e.isDirectory()).map(e=>e.name),o=[];for(let s of a){let a=(0,i.join)(e,s,`resource.json`);if(!(0,r.existsSync)(a))continue;let c=JSON.parse((0,r.readFileSync)(a,`utf-8`));o.push(x(c,t,n))}return o},k=class{service;annotationDefConfig;constructor(e,t){this.service=e,this.annotationDefConfig=t}getAll(){return this.service.findAll()}async getJsonLd_(e){return e===`AnnotationStyle`?m(this.annotationDefConfig).toJsonLdContext():(await this.service.findById(e))?.json_ld}async getSchemas(e){let t=await this.service.findById(e);return{id:t.id,name:t.name,json_schema:t.json_schema,ui_schema:t.ui_schema,metadata_schema:t.metadata_schema,columns:t.columns,isRoot:t.isRoot,allowedChildren:t.allowedChildren,allowedLinks:t.allowedLinks,type:t.type,icon:t.icon,target:t.target}}async getById(e){return await this.service.findById(e)}async getFullJsonLd(){return(await this.service.getAllContextBuilders()).map(e=>e.toJsonLdContext())}async getJsonLd(e){let t=await this.service.getContextBuilder(e);return{jsonLd:t.toJsonLdContext(),forms:t.toJsonSchema()}}};T([(0,e.Get)(),C(`design:type`,Function),C(`design:paramtypes`,[]),C(`design:returntype`,void 0)],k.prototype,`getAll`,null),T([(0,e.Get)(`:id.jsonld`),w(0,(0,e.Param)(`id`)),C(`design:type`,Function),C(`design:paramtypes`,[String]),C(`design:returntype`,Promise)],k.prototype,`getJsonLd_`,null),T([(0,e.Get)(`:id/schemas`),w(0,(0,e.Param)(`id`)),C(`design:type`,Function),C(`design:paramtypes`,[String]),C(`design:returntype`,Promise)],k.prototype,`getSchemas`,null),T([(0,e.Get)(`:id`),w(0,(0,e.Param)(`id`)),C(`design:type`,Function),C(`design:paramtypes`,[String]),C(`design:returntype`,Promise)],k.prototype,`getById`,null),T([(0,e.Get)(`anno.jsonld`),C(`design:type`,Function),C(`design:paramtypes`,[]),C(`design:returntype`,Promise)],k.prototype,`getFullJsonLd`,null),T([(0,e.Get)(`:type/anno.jsonld`),w(0,(0,e.Param)(`type`)),C(`design:type`,Function),C(`design:paramtypes`,[String]),C(`design:returntype`,Promise)],k.prototype,`getJsonLd`,null),k=T([(0,e.Controller)(`ns`),(0,a.ApiTags)(`Annotations NS`),w(0,(0,e.Inject)(E)),w(1,(0,e.Inject)(S)),C(`design:paramtypes`,[E===void 0?Object:E,Object])],k);var A=(e,t)=>{let n=(0,i.join)(e,`_resource`);if(!(0,r.existsSync)(n))return[];let a=(0,r.readdirSync)(n).filter(e=>e.endsWith(`.json`)),{prefix:o}=u(t);return a.map(e=>{let t=JSON.parse((0,r.readFileSync)((0,i.join)(n,e),`utf-8`)),a=t.columns.find(e=>e.displayAs===`id`),s=t.columns.find(e=>e.displayAs===`label`);return{type:t.type,table:t.table,database:t.database,field:{id:a?.column??`id`,label:s?.column??`name`},prefix:`${o}:${t.type}/`}})},j=class{byType=new Map;constructor(e){for(let t of e)this.byType.set(t.type,t)}findAll=()=>[...this.byType.values()];getResourceForType=e=>this.byType.get(e)??null;getResourceFromUri=e=>{for(let t of this.byType.values())if(e.startsWith(t.prefix))return{...t,id:e.substring(t.prefix.length)};return null}};j=T([(0,e.Injectable)(),C(`design:paramtypes`,[Array])],j);var M,N=M=class{static forService(e){return{module:M,global:!0,controllers:[k],providers:[{provide:E,useClass:e.annotationDefinitionService}],exports:[E]}}static async forResourceDir(e,t){let n=()=>O(e,t,b),r=new D(t,n(),n),i=new j(A(e,t));return{module:M,global:!0,controllers:[k],providers:[{provide:S,useValue:t},{provide:E,useValue:r},{provide:j,useValue:i}],exports:[E,j]}}};N=M=T([(0,e.Module)({controllers:[],providers:[],exports:[]})],N),exports.ANNOTATION_DEF_CONFIG_TOKEN=S,Object.defineProperty(exports,"AnnotationApiModule",{enumerable:!0,get:function(){return N}}),Object.defineProperty(exports,"AnnotationDefinitionFromFilesService",{enumerable:!0,get:function(){return D}}),Object.defineProperty(exports,"AnnotationDefinitionService",{enumerable:!0,get:function(){return E}}),Object.defineProperty(exports,"AnnotationResourceDefinitionService",{enumerable:!0,get:function(){return j}}),exports.annotationColumnDefinition=s,exports.annotationDefinition=c,exports.loadAnnotationDefinitionsFromDir=O,exports.loadAnnotationResourcesFromDir=A;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@nestjs/common"),t=require("zod"),n=require("@ghentcdh/w3c-utils"),r=require("@ghentcdh/annotated-text"),i=require("@ghentcdh/crouton-forms-vue"),a=require("node:fs"),o=require("node:path"),s=require("@nestjs/swagger");var c=[`text`],l=t.z.object({text:t.z.string(),textDirection:t.z.enum([`ltr`,`rtl`]).default(`ltr`),processingLanguage:t.z.string().default(`en`),label:t.z.string().optional(),offset:t.z.number().optional().default(0)}),u=t.z.object({id:t.z.string(),uri:t.z.string(),type:t.z.enum(c),content:l}),d=e=>{let t=e.areas.map(e=>`"${e.join(` `)}"`).join(` `),n=e.areas[0]?.length??1,r={gridTemplateAreas:t,gridTemplateColumns:e.columns??Array(n).fill(`minmax(0, 1fr)`).join(` `)};return e.rows&&(r.gridTemplateRows=e.rows),r},f=(e,t)=>e.panes.find(e=>e.sourceId===t)?.area,p=`AnnotationMetadata`,m=t.z.custom(),h=t.z.object({id:t.z.string(),name:t.z.string(),columns:t.z.array(m),json_schema:t.z.any().optional(),json_ld:t.z.any().optional(),ui_schema:t.z.any().optional(),metadata_schema:t.z.any().optional(),color:t.z.string(),type:t.z.string().optional(),icon:t.z.string().optional(),isRoot:t.z.boolean().default(!0),allowedChildren:t.z.array(t.z.string()).default([]),allowedLinks:t.z.array(t.z.string()).default([]),context:t.z.custom(),target:t.z.enum([`gutter`,`underline`,`highlight`]).default(`highlight`)}),g={baseUrl:`http://localhost:3000/`,app:`ghentcdh`,prefix:`ghentcdh`,isDev:!1,cacheTTLms:1200*1e3},_=(e={})=>{let t=e.baseUrl??g.baseUrl,n=t.endsWith(`/`)?t:`${t}/`,r=e.isDev??!1,i=r?0:1200*1e3;return{baseUrl:n,contextUrl:`${n}ns/`,app:e.app??g.app,prefix:e.prefix??g.prefix,isDev:r,cacheTTLms:i}},v=(e,t)=>{let{prefix:r,baseUrl:i,contextUrl:a}=_(t),o=p;return(0,n.contextBuilder)(r,i).setType(r,o).addPrefix(e,`${r}:${e}`).setContextUri(`${a}${e}.jsonld`)},y=`annotation.style`,b=t.z.object({id:t.z.string(),name:t.z.string(),target:t.z.enum([`gutter`,`underline`,`highlight`]).optional().default(`underline`),color:t.z.string().optional()}),x=`AnnotationStyle`,S=e=>{let{prefix:t,baseUrl:r,contextUrl:i}=_(e);return(0,n.contextBuilder)(t,r).setType(t,x).setContextUri(`${i}${x}.jsonld`).parseZodSchema(b)},C=(e,t)=>{let n=S(e).toAnnotationBodyUnsafe(t);return n.success||(r.Debugger.debug(y,`AnnotationStyleContextBuilder safe parse failed`),r.Debugger.warn(n.error)),n},w=e=>{let t=i.ControlBuilder.properties(e.id);if(t.customLabel(e.label),!e.fieldInput)return t;let{type:n,options:r={}}=e.fieldInput;return n===`autocomplete`?t.autocomplete({...r.uri&&{uri:r.uri},...r.resource&&{resource:r.resource},...r.valueKey&&{valueKey:r.valueKey},...r.labelKey&&{labelKey:r.labelKey},...r.enableCreate!==void 0&&{enableCreate:r.enableCreate},...r.colspan&&{colspan:r.colspan}}):n===`select`?t.select({...r.values&&{values:r.values},...r.clearable!==void 0&&{clearable:r.clearable},...r.storeValue!==void 0&&{storeValue:r.storeValue},...r.emitObject!==void 0&&{emitObject:r.emitObject},...r.colspan&&{colspan:r.colspan}}):t.control(n,{...r.colspan&&{colspan:r.colspan}})},T=e=>{let t=i.LayoutBuilder.grid();return e.filter(e=>!e.hiddenInForm).forEach(e=>t.addControl(w(e))),t.build()},E=e=>{let t=i.LayoutBuilder.grid();return e.filter(e=>!e.hiddenInMetadata).forEach(e=>t.addControl(w(e).readonly())),t.build()},D=e=>{if(e.type===`object`&&e.properties){let n={};for(let[t,r]of Object.entries(e.properties))n[t]=D(r);return t.z.object(n)}return t.z.string()},O=(e,n,r)=>{let i=v(e,r),a=n.columns??[];if(!a.length)return i;let o={};for(let e of a){let t=D(e.type??{type:`string`});o[e.id]=e.required===!1?t.optional():t}return Object.keys(o).length?i.parseZodSchema(t.z.object(o)):i},k=(e,t,n=O)=>{let r=n(e.id,e,t),i=e.columns??[],a=i.length>0,o=e.ui_schema??(a?T(i):void 0),s=e.metadata_schema??(a?E(i):void 0),c={id:e.id,name:e.name,color:e.color,isRoot:e.isRoot??!0,columns:i,context:r,json_ld:r.toJsonLdContext(),json_schema:o?r.toJsonSchema():null,allowedChildren:e.allowedChildren??[],allowedLinks:e.allowedLinks??[],target:e.target??`highlight`};return o&&(c.ui_schema=o),s&&(c.metadata_schema=s),e.type&&(c.type=e.type),e.icon&&(c.icon=e.icon),c},ee=(e,t,n)=>e.map(e=>k(e,t,n)),te=(e,t,n)=>n.map(r=>{let i=t.get(r.id),a=i.getSpecificResourceTargets(e);if(!a||a.length===0)return null;let o=i.getSpecificResourceTargets().map(e=>e.source).filter(t=>t!==e).map(e=>n.find(t=>t.id===e)).filter(Boolean);return{purpose:A(i),annotation:r,relations:o}}).filter(Boolean),A=e=>j(e)?.id??`text`,j=e=>e.getBodiesByPurpose(`styling`).find(e=>e.type===`AnnotationStyle`),M=(e,t,n)=>{let r=t.getSpecificResourceTargets()[0]?.source;if(!r)return null;let i=t.getTextPositionSelector(r)[0];if(!i)return null;let a=j(t)?.id??`text`;return{id:e,start:i.start,end:i.end,allowedChildren:n[a]??[],sourceUri:r??``,type:a,minX:i.start,minY:0,maxX:i.end,maxY:0}},N=`ROOT`,P=()=>`mela:new-annotation:${Date.now()}`,F=(e,t)=>(e.getSpecificResourceTargets(t.source).length||e.addTarget({type:`SpecificResource`,source:t.source}),e.updateTextPositionSelector({start:t.start,end:t.end},t.source),e),I=class{annotationConfig;builderMap=new Map;childParentMap=new Map;parentChildMap=new Map;linkedAnnotations=new Map;annotations=[];allowedChildrenPerType={};constructor(e){this.annotationConfig=e}getBuilder(e){let t=this.builderMap.get(e.id);if(!t)throw Error(`Annotation builder not found: ${e.id}`);return t}setAnnotations(e,t){this.allowedChildrenPerType=t,this.annotations=e,this.parentChildMap.clear(),this.childParentMap.clear(),this.builderMap.clear();let r=[],i=new Map;return e.forEach(e=>{let t=(0,n.w3cAnnotation)(e);this.builderMap.set(e.id,t);let a=M(e.id,t,this.allowedChildrenPerType);i.set(e.id,e),a&&r.push(a)}),r.forEach(e=>{let t=r.filter(t=>t.id!==e.id&&t.sourceUri===e.sourceUri&&t.start<=e.start&&t.end>=e.end&&t.allowedChildren.some(t=>t.key===e.type)).sort((e,t)=>e.end-e.start-(t.end-t.start))[0],n=t?.id??N,a=this.parentChildMap.get(n)??[];a.push(i.get(e.id)),this.parentChildMap.set(t?.id??N,a),this.childParentMap.set(e.id,i.get(n)??null)}),e.forEach(t=>{this.linkedAnnotations.set(t.id,te(t.id,this.builderMap,e))}),this}getLinks(e){return this.linkedAnnotations.get(e.id)??[]}getTextPositionSelector(e,t){return this.getBuilder(e).getTextPositionSelector(t)[0]}isAnnotationUri=e=>e.startsWith(`mela:annotation/`);getParentSelector=e=>e.getSpecificResourceTargets().find(e=>this.isAnnotationUri(e.source))??null;getParent(e){let t=this.getBuilder(e),n=this.getParentSelector(t);return n?this.annotations.find(e=>e.id===n.source)??null:null}createAnnotation(e,t,r,i){let a=S(this.annotationConfig).toAnnotationBody(t),o=(0,n.w3cAnnotation)(e??void 0).setMotivation(`tagging`).addBody(a);return e?.id||o.setId(P()),r&&Object.keys(r).length>0&&(r.type=r.type??`AnnotationMetadata`,r.purpose=r.purpose??A(o),o.updateBodyByType(r.type,r)),i&&F(o,i),o.build()}createLinkAnnotation=(e,t,r,i)=>{let a=S(this.annotationConfig).toAnnotationBody(r),o=(0,n.w3cAnnotation)().setMotivation(`tagging`).setId(P()).addBody(a);return i&&Object.keys(i).length>0&&(i.type=i.type??`AnnotationMetadata`,i.purpose=i.purpose??A(o),o.updateBodyByType(i.type,i)),o.addTarget({source:e.id}).addTarget({source:t.id}),o.build()};cancel(){this.setAnnotations(this.annotations,this.allowedChildrenPerType)}getSourceUri=e=>{let t=this.getBuilder(e),n=t.getSourceUri();return n?{textPositionSelector:t.getTextPositionSelector(n)[0],sourceUri:n}:(console.warn(`no source uri`),null)};getMetadata=(e,t)=>this.getBuilder(e).getBodiesByType(`AnnotationMetadata`)?.[0]??null;getAnnotationStyle=e=>j(this.getBuilder(e));getAnnotationType=e=>A(this.getBuilder(e));createAnnotationFromSelector(e,t,r){let i=(0,n.w3cAnnotation)(t??void 0).setMotivation(`tagging`).setId(P()),a=S(this.annotationConfig).toAnnotationBody(e);return i.addBody(a),r&&F(i,r),i.build()}},L=e=>new I(e),R=e=>t=>e?.getAnnotationStyle(t)?.target??`default`,z=(e,t)=>n=>{let i=t?.getAnnotationStyle(n);if(!i)return`default`;let a=i?.id??`default`;return e.includes(a)?a:(r.Debugger.debug(`styleFn`,`No style found for ${a}`),i.color?{default:(0,r.createHighlightStyle)(i.color)}:`default`)},B=(e,t)=>e?e.reduce((e,n)=>(e[n.id]=t?n[t]:n,e),{}):{},V=(e,t,n,i)=>{let a=e??[],o=B(a),s=a.filter(e=>e.isRoot).map(e=>({key:e.id,label:e.label})),c=B(a,`style`);c.default||={label:`Annotation`,isRoot:!0,style:{default:(0,r.createHighlightStyle)(`#dd7777`)},allowedChildren:[],allowedLinks:[],schema:{uiSchema:{type:`VerticalLayout`,elements:[]},jsonSchema:{type:`object`,properties:{}},metaDataSchema:{type:`VerticalLayout`,elements:[]},validation:()=>void 0}};let l=Object.keys(c),u=B(a,`allowedChildren`),d=e=>(0,r.W3CAnnotationAdapter)(e?{sourceUri:e.uri}:{}),f=()=>({renderFn:R(t)}),p=()=>({styleFn:z(l,t)});return{allowedChildrenPerType:u,definitions:a,getDefinition:e=>o[e]??void 0,rootTypes:s,createAnnotatedText:(e,t)=>{let a=(0,r.createAnnotatedText)(e);if(a.setSnapper(new r.WordSnapper).setAnnotationAdapter(i??d(t)).setTextAdapter(n??(0,r.PlainTextAdapter)()).setRenderParams(f()).setStyleParams(p()).registerStyles(c),t){let{content:e}=t;a.setText(e.text).setTextAdapter({textDirection:e.textDirection})}return a}}},H=Symbol(`ANNOTATION_DEF_CONFIG_TOKEN`);function U(e,t){if(typeof Reflect==`object`&&typeof Reflect.metadata==`function`)return Reflect.metadata(e,t)}function W(e,t){return function(n,r){t(n,r,e)}}function G(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}var K=class{config;definitions=[];groupedDefinitions={};cachedAt=0;constructor(e){this.config=e}async findAllGrouped(){return await this.setDefinitions(),Promise.resolve(this.groupedDefinitions)}async setDefinitions(e=!1){let t=Date.now();if(!e&&this.definitions.length&&t-this.cachedAt<this.config.cacheTTLms)return;let n=await this.reloadDefinitions()??[];this.definitions=n,this.groupedDefinitions=n.reduce((e,t)=>(e[t.id]=t,e),{}),this.cachedAt=t}async findAll(){return await this.setDefinitions(),Promise.resolve(this.definitions)}async findById(t){await this.setDefinitions();let n=this.groupedDefinitions[t];if(n||await this.setDefinitions(!0),n=this.groupedDefinitions[t],!n)throw new e.NotFoundException;return Promise.resolve(n)}async getAllContextBuilders(){return(await this.findAll()).map(e=>e.context)}async getContextBuilder(t){let n=await this.findById(t);if(!n)throw new e.NotFoundException;return n.context}};K=G([(0,e.Injectable)(),W(0,(0,e.Inject)(H)),U(`design:paramtypes`,[Object])],K);var q=class extends K{_initialDefinitions;_loaderFn;constructor(e,t,n){super(e),this._initialDefinitions=t,this._loaderFn=n}reloadDefinitions=()=>this.config.isDev&&this._loaderFn?Promise.resolve(this._loaderFn()):Promise.resolve(this._initialDefinitions??[])};q=G([(0,e.Injectable)(),W(0,(0,e.Inject)(H)),U(`design:paramtypes`,[Object,Array,Object])],q);var J=(e,t,n)=>{if(!(0,a.existsSync)(e))return[];let r=(0,a.readdirSync)(e,{withFileTypes:!0}).filter(e=>e.isDirectory()).map(e=>e.name),i=[];for(let s of r){let r=(0,o.join)(e,s,`resource.json`);if(!(0,a.existsSync)(r))continue;let c=JSON.parse((0,a.readFileSync)(r,`utf-8`));i.push(k(c,t,n))}return i},Y=class{service;annotationDefConfig;constructor(e,t){this.service=e,this.annotationDefConfig=t}getAll(){return this.service.findAll()}async getJsonLd_(e){return e===`AnnotationStyle`?S(this.annotationDefConfig).toJsonLdContext():(await this.service.findById(e))?.json_ld}async getSchemas(e){let t=await this.service.findById(e);return{id:t.id,name:t.name,json_schema:t.json_schema,ui_schema:t.ui_schema,metadata_schema:t.metadata_schema,columns:t.columns,isRoot:t.isRoot,allowedChildren:t.allowedChildren,allowedLinks:t.allowedLinks,type:t.type,icon:t.icon,target:t.target}}async getById(e){return await this.service.findById(e)}async getFullJsonLd(){return(await this.service.getAllContextBuilders()).map(e=>e.toJsonLdContext())}async getJsonLd(e){let t=await this.service.getContextBuilder(e);return{jsonLd:t.toJsonLdContext(),forms:t.toJsonSchema()}}};G([(0,e.Get)(),U(`design:type`,Function),U(`design:paramtypes`,[]),U(`design:returntype`,void 0)],Y.prototype,`getAll`,null),G([(0,e.Get)(`:id.jsonld`),W(0,(0,e.Param)(`id`)),U(`design:type`,Function),U(`design:paramtypes`,[String]),U(`design:returntype`,Promise)],Y.prototype,`getJsonLd_`,null),G([(0,e.Get)(`:id/schemas`),W(0,(0,e.Param)(`id`)),U(`design:type`,Function),U(`design:paramtypes`,[String]),U(`design:returntype`,Promise)],Y.prototype,`getSchemas`,null),G([(0,e.Get)(`:id`),W(0,(0,e.Param)(`id`)),U(`design:type`,Function),U(`design:paramtypes`,[String]),U(`design:returntype`,Promise)],Y.prototype,`getById`,null),G([(0,e.Get)(`anno.jsonld`),U(`design:type`,Function),U(`design:paramtypes`,[]),U(`design:returntype`,Promise)],Y.prototype,`getFullJsonLd`,null),G([(0,e.Get)(`:type/anno.jsonld`),W(0,(0,e.Param)(`type`)),U(`design:type`,Function),U(`design:paramtypes`,[String]),U(`design:returntype`,Promise)],Y.prototype,`getJsonLd`,null),Y=G([(0,e.Controller)(`ns`),(0,s.ApiTags)(`Annotations NS`),W(0,(0,e.Inject)(K)),W(1,(0,e.Inject)(H)),U(`design:paramtypes`,[K===void 0?Object:K,Object])],Y);var X=(e,t)=>{let n=(0,o.join)(e,`_resource`);if(!(0,a.existsSync)(n))return[];let r=(0,a.readdirSync)(n).filter(e=>e.endsWith(`.json`)),{prefix:i}=_(t);return r.map(e=>{let t=JSON.parse((0,a.readFileSync)((0,o.join)(n,e),`utf-8`)),r=t.columns.find(e=>e.displayAs===`id`),s=t.columns.find(e=>e.displayAs===`label`);return{type:t.type,table:t.table,database:t.database,field:{id:r?.column??`id`,label:s?.column??`name`},prefix:`${i}:${t.type}/`}})},Z=class{byType=new Map;constructor(e){for(let t of e)this.byType.set(t.type,t)}findAll=()=>[...this.byType.values()];getResourceForType=e=>this.byType.get(e)??null;getResourceFromUri=e=>{for(let t of this.byType.values())if(e.startsWith(t.prefix))return{...t,id:e.substring(t.prefix.length)};return null}};Z=G([(0,e.Injectable)(),U(`design:paramtypes`,[Array])],Z);var Q,$=Q=class{static forService(e){return{module:Q,global:!0,controllers:[Y],providers:[{provide:K,useClass:e.annotationDefinitionService}],exports:[K]}}static async forResourceDir(e,t){let n=()=>J(e,t,O),r=new q(t,n(),n),i=new Z(X(e,t));return{module:Q,global:!0,controllers:[Y],providers:[{provide:H,useValue:t},{provide:K,useValue:r},{provide:Z,useValue:i}],exports:[K,Z]}}};$=Q=G([(0,e.Module)({controllers:[],providers:[],exports:[]})],$),exports.ANNOTATION_DEF_CONFIG_TOKEN=H,Object.defineProperty(exports,"AnnotationApiModule",{enumerable:!0,get:function(){return $}}),Object.defineProperty(exports,"AnnotationDefinitionFromFilesService",{enumerable:!0,get:function(){return q}}),Object.defineProperty(exports,"AnnotationDefinitionService",{enumerable:!0,get:function(){return K}}),exports.AnnotationMetadataType=p,Object.defineProperty(exports,"AnnotationResourceDefinitionService",{enumerable:!0,get:function(){return Z}}),exports.AnnotationStyleContextBuilder=S,exports.AnnotationStyleType=x,exports.SourceModelSchema=u,exports.SourceTextSchema=l,exports.annotationColumnDefinition=m,exports.annotationContextBuilderFactory=O,exports.annotationDefinition=h,exports.annotationUtils=L,exports.baseContextBuilder=v,exports.buildAnnotationDefinition=k,exports.buildAnnotationDefinitions=ee,exports.buildGridStyle=d,exports.buildMetadataSchema=E,exports.buildUiSchema=T,exports.createAnnotationConfiguration=V,exports.createAnnotationStyleBodyUnsafe=C,exports.defaultRender=R,exports.getPaneArea=f,exports.jsonSchemaPropertyToZod=D,exports.loadAnnotationDefinitionsFromDir=J,exports.loadAnnotationResourcesFromDir=X,exports.resolveConfig=_,exports.styleFn=z;
package/index.d.ts CHANGED
@@ -5,4 +5,4 @@ export * from './lib/service/annotation-definition.loader';
5
5
  export * from './lib/resource/annotation-resource-definition.service';
6
6
  export * from './lib/resource/annotation-resource.loader';
7
7
  export * from './lib/utils/annotation.context-builder';
8
- export { type AnnotationColumnFieldInput, type AnnotationColumnConfig, type AnnotationJsonConfig, annotationColumnDefinition, annotationDefinition, type AnnotationDefinition, } from '@ghentcdh/annotation-core';
8
+ export * from '@ghentcdh/annotation-core';
package/index.js CHANGED
@@ -1,15 +1,33 @@
1
1
  import { Controller as e, Get as t, Inject as n, Injectable as r, Module as i, NotFoundException as a, Param as o } from "@nestjs/common";
2
2
  import { z as s } from "zod";
3
- import { contextBuilder as c } from "@ghentcdh/w3c-utils";
4
- import "@ghentcdh/annotated-text";
5
- import { existsSync as l, readFileSync as u, readdirSync as d } from "node:fs";
6
- import { join as f } from "node:path";
7
- import { ApiTags as p } from "@nestjs/swagger";
8
- //#region packages/annotation-core/src/lib/types/annotation.contex.ts
9
- var m = "AnnotationMetadata", h = s.object({}), g = s.object({
3
+ import { contextBuilder as c, w3cAnnotation as l } from "@ghentcdh/w3c-utils";
4
+ import { Debugger as u, PlainTextAdapter as ee, W3CAnnotationAdapter as d, WordSnapper as te, createAnnotatedText as ne, createHighlightStyle as f } from "@ghentcdh/annotated-text";
5
+ import { ControlBuilder as p, LayoutBuilder as m } from "@ghentcdh/crouton-forms-vue";
6
+ import { existsSync as h, readFileSync as g, readdirSync as _ } from "node:fs";
7
+ import { join as v } from "node:path";
8
+ import { ApiTags as re } from "@nestjs/swagger";
9
+ //#region packages/annotation-core/src/lib/types/source.model.ts
10
+ var ie = ["text"], y = s.object({
11
+ text: s.string(),
12
+ textDirection: s.enum(["ltr", "rtl"]).default("ltr"),
13
+ processingLanguage: s.string().default("en"),
14
+ label: s.string().optional(),
15
+ offset: s.number().optional().default(0)
16
+ }), ae = s.object({
17
+ id: s.string(),
18
+ uri: s.string(),
19
+ type: s.enum(ie),
20
+ content: y
21
+ }), oe = (e) => {
22
+ let t = e.areas.map((e) => `"${e.join(" ")}"`).join(" "), n = e.areas[0]?.length ?? 1, r = {
23
+ gridTemplateAreas: t,
24
+ gridTemplateColumns: e.columns ?? Array(n).fill("minmax(0, 1fr)").join(" ")
25
+ };
26
+ return e.rows && (r.gridTemplateRows = e.rows), r;
27
+ }, se = (e, t) => e.panes.find((e) => e.sourceId === t)?.area, b = "AnnotationMetadata", x = s.custom(), ce = s.object({
10
28
  id: s.string(),
11
29
  name: s.string(),
12
- columns: s.array(h),
30
+ columns: s.array(x),
13
31
  json_schema: s.any().optional(),
14
32
  json_ld: s.any().optional(),
15
33
  ui_schema: s.any().optional(),
@@ -18,34 +36,34 @@ var m = "AnnotationMetadata", h = s.object({}), g = s.object({
18
36
  type: s.string().optional(),
19
37
  icon: s.string().optional(),
20
38
  isRoot: s.boolean().default(!0),
21
- allowedChildren: s.array(s.string()).optional(),
22
- allowedLinks: s.array(s.string()).optional(),
39
+ allowedChildren: s.array(s.string()).default([]),
40
+ allowedLinks: s.array(s.string()).default([]),
23
41
  context: s.custom(),
24
42
  target: s.enum([
25
43
  "gutter",
26
44
  "underline",
27
45
  "highlight"
28
- ]).optional()
29
- }), _ = {
46
+ ]).default("highlight")
47
+ }), S = {
30
48
  baseUrl: "http://localhost:3000/",
31
49
  app: "ghentcdh",
32
50
  prefix: "ghentcdh",
33
51
  isDev: !1,
34
52
  cacheTTLms: 1200 * 1e3
35
- }, v = (e = {}) => {
36
- let t = e.baseUrl ?? _.baseUrl, n = t.endsWith("/") ? t : `${t}/`, r = e.isDev ?? !1, i = r ? 0 : 1200 * 1e3;
53
+ }, C = (e = {}) => {
54
+ let t = e.baseUrl ?? S.baseUrl, n = t.endsWith("/") ? t : `${t}/`, r = e.isDev ?? !1, i = r ? 0 : 1200 * 1e3;
37
55
  return {
38
56
  baseUrl: n,
39
57
  contextUrl: `${n}ns/`,
40
- app: e.app ?? _.app,
41
- prefix: e.prefix ?? _.prefix,
58
+ app: e.app ?? S.app,
59
+ prefix: e.prefix ?? S.prefix,
42
60
  isDev: r,
43
61
  cacheTTLms: i
44
62
  };
45
- }, y = (e, t) => {
46
- let { prefix: n, baseUrl: r, contextUrl: i } = v(t), a = m;
63
+ }, w = (e, t) => {
64
+ let { prefix: n, baseUrl: r, contextUrl: i } = C(t), a = b;
47
65
  return c(n, r).setType(n, a).addPrefix(e, `${n}:${e}`).setContextUri(`${i}${e}.jsonld`);
48
- }, b = s.object({
66
+ }, le = "annotation.style", ue = s.object({
49
67
  id: s.string(),
50
68
  name: s.string(),
51
69
  target: s.enum([
@@ -54,50 +72,54 @@ var m = "AnnotationMetadata", h = s.object({}), g = s.object({
54
72
  "highlight"
55
73
  ]).optional().default("underline"),
56
74
  color: s.string().optional()
57
- }), x = "AnnotationStyle", S = (e) => {
58
- let { prefix: t, baseUrl: n, contextUrl: r } = v(e);
59
- return c(t, n).setType(t, x).setContextUri(`${r}${x}.jsonld`).parseZodSchema(b);
60
- }, C = (e) => {
61
- let t = {};
62
- if (e.fieldInput) {
63
- let { type: n, options: r } = e.fieldInput;
64
- t.format = n, n === "autocomplete" && (t.dataField = "data", r.uri && (t.uri = r.uri), r.resource && (t.resource = r.resource), r.valueKey && (t.valueKey = r.valueKey), r.labelKey && (t.labelKey = r.labelKey), r.enableCreate !== void 0 && (t.enableCreate = r.enableCreate));
65
- }
66
- return {
67
- type: "Control",
68
- scope: `#/properties/${e.id}`,
69
- options: t
70
- };
71
- }, w = (e) => ({
72
- type: "TextCell",
73
- scope: `#/properties/${e.id}`,
74
- options: {
75
- format: "keyValue",
76
- key: e.fieldInput?.options?.labelKey ?? e.displayKey ?? "label"
77
- }
78
- }), T = (e) => ({
79
- type: "GridLayout",
80
- elements: e.filter((e) => !e.hiddenInForm).map(C),
81
- options: {}
82
- }), E = (e) => ({
83
- type: "GridLayout",
84
- elements: e.filter((e) => !e.hiddenInMetadata).map(w),
85
- options: {}
86
- }), D = (e) => {
75
+ }), T = "AnnotationStyle", E = (e) => {
76
+ let { prefix: t, baseUrl: n, contextUrl: r } = C(e);
77
+ return c(t, n).setType(t, T).setContextUri(`${r}${T}.jsonld`).parseZodSchema(ue);
78
+ }, de = (e, t) => {
79
+ let n = E(e).toAnnotationBodyUnsafe(t);
80
+ return n.success || (u.debug(le, "AnnotationStyleContextBuilder safe parse failed"), u.warn(n.error)), n;
81
+ }, D = (e) => {
82
+ let t = p.properties(e.id);
83
+ if (t.customLabel(e.label), !e.fieldInput) return t;
84
+ let { type: n, options: r = {} } = e.fieldInput;
85
+ return n === "autocomplete" ? t.autocomplete({
86
+ ...r.uri && { uri: r.uri },
87
+ ...r.resource && { resource: r.resource },
88
+ ...r.valueKey && { valueKey: r.valueKey },
89
+ ...r.labelKey && { labelKey: r.labelKey },
90
+ ...r.enableCreate !== void 0 && { enableCreate: r.enableCreate },
91
+ ...r.colspan && { colspan: r.colspan }
92
+ }) : n === "select" ? t.select({
93
+ ...r.values && { values: r.values },
94
+ ...r.clearable !== void 0 && { clearable: r.clearable },
95
+ ...r.storeValue !== void 0 && { storeValue: r.storeValue },
96
+ ...r.emitObject !== void 0 && { emitObject: r.emitObject },
97
+ ...r.colspan && { colspan: r.colspan }
98
+ }) : t.control(n, { ...r.colspan && { colspan: r.colspan } });
99
+ }, O = (e) => {
100
+ let t = m.grid();
101
+ return e.filter((e) => !e.hiddenInForm).forEach((e) => t.addControl(D(e))), t.build();
102
+ }, k = (e) => {
103
+ let t = m.grid();
104
+ return e.filter((e) => !e.hiddenInMetadata).forEach((e) => t.addControl(D(e).readonly())), t.build();
105
+ }, A = (e) => {
87
106
  if (e.type === "object" && e.properties) {
88
107
  let t = {};
89
- for (let [n, r] of Object.entries(e.properties)) t[n] = D(r);
108
+ for (let [n, r] of Object.entries(e.properties)) t[n] = A(r);
90
109
  return s.object(t);
91
110
  }
92
111
  return s.string();
93
- }, O = (e, t, n) => {
94
- let r = y(e, n), i = t.columns ?? [];
112
+ }, j = (e, t, n) => {
113
+ let r = w(e, n), i = t.columns ?? [];
95
114
  if (!i.length) return r;
96
115
  let a = {};
97
- for (let e of i) e.type && (a[e.id] = D(e.type));
116
+ for (let e of i) {
117
+ let t = A(e.type ?? { type: "string" });
118
+ a[e.id] = e.required === !1 ? t.optional() : t;
119
+ }
98
120
  return Object.keys(a).length ? r.parseZodSchema(s.object(a)) : r;
99
- }, k = (e, t, n = O) => {
100
- let r = n(e.id, e, t), i = e.columns ?? [], a = i.length > 0, o = e.ui_schema ?? (a ? T(i) : void 0), s = e.metadata_schema ?? (a ? E(i) : void 0), c = {
121
+ }, M = (e, t, n = j) => {
122
+ let r = n(e.id, e, t), i = e.columns ?? [], a = i.length > 0, o = e.ui_schema ?? (a ? O(i) : void 0), s = e.metadata_schema ?? (a ? k(i) : void 0), c = {
101
123
  id: e.id,
102
124
  name: e.name,
103
125
  color: e.color,
@@ -105,25 +127,176 @@ var m = "AnnotationMetadata", h = s.object({}), g = s.object({
105
127
  columns: i,
106
128
  context: r,
107
129
  json_ld: r.toJsonLdContext(),
108
- json_schema: o ? r.toJsonSchema() : null
130
+ json_schema: o ? r.toJsonSchema() : null,
131
+ allowedChildren: e.allowedChildren ?? [],
132
+ allowedLinks: e.allowedLinks ?? [],
133
+ target: e.target ?? "highlight"
134
+ };
135
+ return o && (c.ui_schema = o), s && (c.metadata_schema = s), e.type && (c.type = e.type), e.icon && (c.icon = e.icon), c;
136
+ }, fe = (e, t, n) => e.map((e) => M(e, t, n)), pe = (e, t, n) => n.map((r) => {
137
+ let i = t.get(r.id), a = i.getSpecificResourceTargets(e);
138
+ if (!a || a.length === 0) return null;
139
+ let o = i.getSpecificResourceTargets().map((e) => e.source).filter((t) => t !== e).map((e) => n.find((t) => t.id === e)).filter(Boolean);
140
+ return {
141
+ purpose: N(i),
142
+ annotation: r,
143
+ relations: o
144
+ };
145
+ }).filter(Boolean), N = (e) => P(e)?.id ?? "text", P = (e) => e.getBodiesByPurpose("styling").find((e) => e.type === "AnnotationStyle"), me = (e, t, n) => {
146
+ let r = t.getSpecificResourceTargets()[0]?.source;
147
+ if (!r) return null;
148
+ let i = t.getTextPositionSelector(r)[0];
149
+ if (!i) return null;
150
+ let a = P(t)?.id ?? "text";
151
+ return {
152
+ id: e,
153
+ start: i.start,
154
+ end: i.end,
155
+ allowedChildren: n[a] ?? [],
156
+ sourceUri: r ?? "",
157
+ type: a,
158
+ minX: i.start,
159
+ minY: 0,
160
+ maxX: i.end,
161
+ maxY: 0
162
+ };
163
+ }, F = "ROOT", I = () => `mela:new-annotation:${Date.now()}`, L = (e, t) => (e.getSpecificResourceTargets(t.source).length || e.addTarget({
164
+ type: "SpecificResource",
165
+ source: t.source
166
+ }), e.updateTextPositionSelector({
167
+ start: t.start,
168
+ end: t.end
169
+ }, t.source), e), R = class {
170
+ annotationConfig;
171
+ builderMap = /* @__PURE__ */ new Map();
172
+ childParentMap = /* @__PURE__ */ new Map();
173
+ parentChildMap = /* @__PURE__ */ new Map();
174
+ linkedAnnotations = /* @__PURE__ */ new Map();
175
+ annotations = [];
176
+ allowedChildrenPerType = {};
177
+ constructor(e) {
178
+ this.annotationConfig = e;
179
+ }
180
+ getBuilder(e) {
181
+ let t = this.builderMap.get(e.id);
182
+ if (!t) throw Error(`Annotation builder not found: ${e.id}`);
183
+ return t;
184
+ }
185
+ setAnnotations(e, t) {
186
+ this.allowedChildrenPerType = t, this.annotations = e, this.parentChildMap.clear(), this.childParentMap.clear(), this.builderMap.clear();
187
+ let n = [], r = /* @__PURE__ */ new Map();
188
+ return e.forEach((e) => {
189
+ let t = l(e);
190
+ this.builderMap.set(e.id, t);
191
+ let i = me(e.id, t, this.allowedChildrenPerType);
192
+ r.set(e.id, e), i && n.push(i);
193
+ }), n.forEach((e) => {
194
+ let t = n.filter((t) => t.id !== e.id && t.sourceUri === e.sourceUri && t.start <= e.start && t.end >= e.end && t.allowedChildren.some((t) => t.key === e.type)).sort((e, t) => e.end - e.start - (t.end - t.start))[0], i = t?.id ?? F, a = this.parentChildMap.get(i) ?? [];
195
+ a.push(r.get(e.id)), this.parentChildMap.set(t?.id ?? F, a), this.childParentMap.set(e.id, r.get(i) ?? null);
196
+ }), e.forEach((t) => {
197
+ this.linkedAnnotations.set(t.id, pe(t.id, this.builderMap, e));
198
+ }), this;
199
+ }
200
+ getLinks(e) {
201
+ return this.linkedAnnotations.get(e.id) ?? [];
202
+ }
203
+ getTextPositionSelector(e, t) {
204
+ return this.getBuilder(e).getTextPositionSelector(t)[0];
205
+ }
206
+ isAnnotationUri = (e) => e.startsWith("mela:annotation/");
207
+ getParentSelector = (e) => e.getSpecificResourceTargets().find((e) => this.isAnnotationUri(e.source)) ?? null;
208
+ getParent(e) {
209
+ let t = this.getBuilder(e), n = this.getParentSelector(t);
210
+ return n ? this.annotations.find((e) => e.id === n.source) ?? null : null;
211
+ }
212
+ createAnnotation(e, t, n, r) {
213
+ let i = E(this.annotationConfig).toAnnotationBody(t), a = l(e ?? void 0).setMotivation("tagging").addBody(i);
214
+ return e?.id || a.setId(I()), n && Object.keys(n).length > 0 && (n.type = n.type ?? "AnnotationMetadata", n.purpose = n.purpose ?? N(a), a.updateBodyByType(n.type, n)), r && L(a, r), a.build();
215
+ }
216
+ createLinkAnnotation = (e, t, n, r) => {
217
+ let i = E(this.annotationConfig).toAnnotationBody(n), a = l().setMotivation("tagging").setId(I()).addBody(i);
218
+ return r && Object.keys(r).length > 0 && (r.type = r.type ?? "AnnotationMetadata", r.purpose = r.purpose ?? N(a), a.updateBodyByType(r.type, r)), a.addTarget({ source: e.id }).addTarget({ source: t.id }), a.build();
219
+ };
220
+ cancel() {
221
+ this.setAnnotations(this.annotations, this.allowedChildrenPerType);
222
+ }
223
+ getSourceUri = (e) => {
224
+ let t = this.getBuilder(e), n = t.getSourceUri();
225
+ return n ? {
226
+ textPositionSelector: t.getTextPositionSelector(n)[0],
227
+ sourceUri: n
228
+ } : (console.warn("no source uri"), null);
229
+ };
230
+ getMetadata = (e, t) => this.getBuilder(e).getBodiesByType("AnnotationMetadata")?.[0] ?? null;
231
+ getAnnotationStyle = (e) => P(this.getBuilder(e));
232
+ getAnnotationType = (e) => N(this.getBuilder(e));
233
+ createAnnotationFromSelector(e, t, n) {
234
+ let r = l(t ?? void 0).setMotivation("tagging").setId(I()), i = E(this.annotationConfig).toAnnotationBody(e);
235
+ return r.addBody(i), n && L(r, n), r.build();
236
+ }
237
+ }, he = (e) => new R(e), z = (e) => (t) => e?.getAnnotationStyle(t)?.target ?? "default", B = (e, t) => (n) => {
238
+ let r = t?.getAnnotationStyle(n);
239
+ if (!r) return "default";
240
+ let i = r?.id ?? "default";
241
+ return e.includes(i) ? i : (u.debug("styleFn", `No style found for ${i}`), r.color ? { default: f(r.color) } : "default");
242
+ }, V = (e, t) => e ? e.reduce((e, n) => (e[n.id] = t ? n[t] : n, e), {}) : {}, ge = (e, t, n, r) => {
243
+ let i = e ?? [], a = V(i), o = i.filter((e) => e.isRoot).map((e) => ({
244
+ key: e.id,
245
+ label: e.label
246
+ })), s = V(i, "style");
247
+ s.default ||= {
248
+ label: "Annotation",
249
+ isRoot: !0,
250
+ style: { default: f("#dd7777") },
251
+ allowedChildren: [],
252
+ allowedLinks: [],
253
+ schema: {
254
+ uiSchema: {
255
+ type: "VerticalLayout",
256
+ elements: []
257
+ },
258
+ jsonSchema: {
259
+ type: "object",
260
+ properties: {}
261
+ },
262
+ metaDataSchema: {
263
+ type: "VerticalLayout",
264
+ elements: []
265
+ },
266
+ validation: () => void 0
267
+ }
268
+ };
269
+ let c = Object.keys(s), l = V(i, "allowedChildren"), u = (e) => d(e ? { sourceUri: e.uri } : {}), p = () => ({ renderFn: z(t) }), m = () => ({ styleFn: B(c, t) });
270
+ return {
271
+ allowedChildrenPerType: l,
272
+ definitions: i,
273
+ getDefinition: (e) => a[e] ?? void 0,
274
+ rootTypes: o,
275
+ createAnnotatedText: (e, t) => {
276
+ let i = ne(e);
277
+ if (i.setSnapper(new te()).setAnnotationAdapter(r ?? u(t)).setTextAdapter(n ?? ee()).setRenderParams(p()).setStyleParams(m()).registerStyles(s), t) {
278
+ let { content: e } = t;
279
+ i.setText(e.text).setTextAdapter({ textDirection: e.textDirection });
280
+ }
281
+ return i;
282
+ }
109
283
  };
110
- return o && (c.ui_schema = o), s && (c.metadata_schema = s), e.type && (c.type = e.type), e.icon && (c.icon = e.icon), e.target && (c.target = e.target), e.allowedChildren && (c.allowedChildren = e.allowedChildren), e.allowedLinks && (c.allowedLinks = e.allowedLinks), c;
111
- }, A = Symbol("ANNOTATION_DEF_CONFIG_TOKEN");
284
+ }, H = Symbol("ANNOTATION_DEF_CONFIG_TOKEN");
112
285
  //#endregion
113
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/decorateMetadata.js
114
- function j(e, t) {
286
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/decorateMetadata.js
287
+ function U(e, t) {
115
288
  if (typeof Reflect == "object" && typeof Reflect.metadata == "function") return Reflect.metadata(e, t);
116
289
  }
117
290
  //#endregion
118
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/decorateParam.js
119
- function M(e, t) {
291
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/decorateParam.js
292
+ function W(e, t) {
120
293
  return function(n, r) {
121
294
  t(n, r, e);
122
295
  };
123
296
  }
124
297
  //#endregion
125
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/decorate.js
126
- function N(e, t, n, r) {
298
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/decorate.js
299
+ function G(e, t, n, r) {
127
300
  var i = arguments.length, a = i < 3 ? t : r === null ? r = Object.getOwnPropertyDescriptor(t, n) : r, o;
128
301
  if (typeof Reflect == "object" && typeof Reflect.decorate == "function") a = Reflect.decorate(e, t, n, r);
129
302
  else for (var s = e.length - 1; s >= 0; s--) (o = e[s]) && (a = (i < 3 ? o(a) : i > 3 ? o(t, n, a) : o(t, n)) || a);
@@ -131,7 +304,7 @@ function N(e, t, n, r) {
131
304
  }
132
305
  //#endregion
133
306
  //#region packages/annotation-api/src/lib/service/annotation-definition.service.ts
134
- var P = class {
307
+ var K = class {
135
308
  config;
136
309
  definitions = [];
137
310
  groupedDefinitions = {};
@@ -166,14 +339,14 @@ var P = class {
166
339
  return t.context;
167
340
  }
168
341
  };
169
- P = N([
342
+ K = G([
170
343
  r(),
171
- M(0, n(A)),
172
- j("design:paramtypes", [Object])
173
- ], P);
344
+ W(0, n(H)),
345
+ U("design:paramtypes", [Object])
346
+ ], K);
174
347
  //#endregion
175
348
  //#region packages/annotation-api/src/lib/service/annotation-definition-from-files.service.ts
176
- var F = class extends P {
349
+ var q = class extends K {
177
350
  _initialDefinitions;
178
351
  _loaderFn;
179
352
  constructor(e, t, n) {
@@ -181,28 +354,28 @@ var F = class extends P {
181
354
  }
182
355
  reloadDefinitions = () => this.config.isDev && this._loaderFn ? Promise.resolve(this._loaderFn()) : Promise.resolve(this._initialDefinitions ?? []);
183
356
  };
184
- F = N([
357
+ q = G([
185
358
  r(),
186
- M(0, n(A)),
187
- j("design:paramtypes", [
359
+ W(0, n(H)),
360
+ U("design:paramtypes", [
188
361
  Object,
189
362
  Array,
190
363
  Object
191
364
  ])
192
- ], F);
365
+ ], q);
193
366
  //#endregion
194
367
  //#region packages/annotation-api/src/lib/service/annotation-definition.loader.ts
195
- var I = (e, t, n) => {
196
- if (!l(e)) return [];
197
- let r = d(e, { withFileTypes: !0 }).filter((e) => e.isDirectory()).map((e) => e.name), i = [];
368
+ var J = (e, t, n) => {
369
+ if (!h(e)) return [];
370
+ let r = _(e, { withFileTypes: !0 }).filter((e) => e.isDirectory()).map((e) => e.name), i = [];
198
371
  for (let a of r) {
199
- let r = f(e, a, "resource.json");
200
- if (!l(r)) continue;
201
- let o = JSON.parse(u(r, "utf-8"));
202
- i.push(k(o, t, n));
372
+ let r = v(e, a, "resource.json");
373
+ if (!h(r)) continue;
374
+ let o = JSON.parse(g(r, "utf-8"));
375
+ i.push(M(o, t, n));
203
376
  }
204
377
  return i;
205
- }, L = class {
378
+ }, Y = class {
206
379
  service;
207
380
  annotationDefConfig;
208
381
  constructor(e, t) {
@@ -212,7 +385,7 @@ var I = (e, t, n) => {
212
385
  return this.service.findAll();
213
386
  }
214
387
  async getJsonLd_(e) {
215
- return e === "AnnotationStyle" ? S(this.annotationDefConfig).toJsonLdContext() : (await this.service.findById(e))?.json_ld;
388
+ return e === "AnnotationStyle" ? E(this.annotationDefConfig).toJsonLdContext() : (await this.service.findById(e))?.json_ld;
216
389
  }
217
390
  async getSchemas(e) {
218
391
  let t = await this.service.findById(e);
@@ -245,55 +418,55 @@ var I = (e, t, n) => {
245
418
  };
246
419
  }
247
420
  };
248
- N([
421
+ G([
249
422
  t(),
250
- j("design:type", Function),
251
- j("design:paramtypes", []),
252
- j("design:returntype", void 0)
253
- ], L.prototype, "getAll", null), N([
423
+ U("design:type", Function),
424
+ U("design:paramtypes", []),
425
+ U("design:returntype", void 0)
426
+ ], Y.prototype, "getAll", null), G([
254
427
  t(":id.jsonld"),
255
- M(0, o("id")),
256
- j("design:type", Function),
257
- j("design:paramtypes", [String]),
258
- j("design:returntype", Promise)
259
- ], L.prototype, "getJsonLd_", null), N([
428
+ W(0, o("id")),
429
+ U("design:type", Function),
430
+ U("design:paramtypes", [String]),
431
+ U("design:returntype", Promise)
432
+ ], Y.prototype, "getJsonLd_", null), G([
260
433
  t(":id/schemas"),
261
- M(0, o("id")),
262
- j("design:type", Function),
263
- j("design:paramtypes", [String]),
264
- j("design:returntype", Promise)
265
- ], L.prototype, "getSchemas", null), N([
434
+ W(0, o("id")),
435
+ U("design:type", Function),
436
+ U("design:paramtypes", [String]),
437
+ U("design:returntype", Promise)
438
+ ], Y.prototype, "getSchemas", null), G([
266
439
  t(":id"),
267
- M(0, o("id")),
268
- j("design:type", Function),
269
- j("design:paramtypes", [String]),
270
- j("design:returntype", Promise)
271
- ], L.prototype, "getById", null), N([
440
+ W(0, o("id")),
441
+ U("design:type", Function),
442
+ U("design:paramtypes", [String]),
443
+ U("design:returntype", Promise)
444
+ ], Y.prototype, "getById", null), G([
272
445
  t("anno.jsonld"),
273
- j("design:type", Function),
274
- j("design:paramtypes", []),
275
- j("design:returntype", Promise)
276
- ], L.prototype, "getFullJsonLd", null), N([
446
+ U("design:type", Function),
447
+ U("design:paramtypes", []),
448
+ U("design:returntype", Promise)
449
+ ], Y.prototype, "getFullJsonLd", null), G([
277
450
  t(":type/anno.jsonld"),
278
- M(0, o("type")),
279
- j("design:type", Function),
280
- j("design:paramtypes", [String]),
281
- j("design:returntype", Promise)
282
- ], L.prototype, "getJsonLd", null), L = N([
451
+ W(0, o("type")),
452
+ U("design:type", Function),
453
+ U("design:paramtypes", [String]),
454
+ U("design:returntype", Promise)
455
+ ], Y.prototype, "getJsonLd", null), Y = G([
283
456
  e("ns"),
284
- p("Annotations NS"),
285
- M(0, n(P)),
286
- M(1, n(A)),
287
- j("design:paramtypes", [P === void 0 ? Object : P, Object])
288
- ], L);
457
+ re("Annotations NS"),
458
+ W(0, n(K)),
459
+ W(1, n(H)),
460
+ U("design:paramtypes", [K === void 0 ? Object : K, Object])
461
+ ], Y);
289
462
  //#endregion
290
463
  //#region packages/annotation-api/src/lib/resource/annotation-resource.loader.ts
291
- var R = (e, t) => {
292
- let n = f(e, "_resource");
293
- if (!l(n)) return [];
294
- let r = d(n).filter((e) => e.endsWith(".json")), { prefix: i } = v(t);
464
+ var X = (e, t) => {
465
+ let n = v(e, "_resource");
466
+ if (!h(n)) return [];
467
+ let r = _(n).filter((e) => e.endsWith(".json")), { prefix: i } = C(t);
295
468
  return r.map((e) => {
296
- let t = JSON.parse(u(f(n, e), "utf-8")), r = t.columns.find((e) => e.displayAs === "id"), a = t.columns.find((e) => e.displayAs === "label");
469
+ let t = JSON.parse(g(v(n, e), "utf-8")), r = t.columns.find((e) => e.displayAs === "id"), a = t.columns.find((e) => e.displayAs === "label");
297
470
  return {
298
471
  type: t.type,
299
472
  table: t.table,
@@ -305,7 +478,7 @@ var R = (e, t) => {
305
478
  prefix: `${i}:${t.type}/`
306
479
  };
307
480
  });
308
- }, z = class {
481
+ }, Z = class {
309
482
  byType = /* @__PURE__ */ new Map();
310
483
  constructor(e) {
311
484
  for (let t of e) this.byType.set(t.type, t);
@@ -320,50 +493,50 @@ var R = (e, t) => {
320
493
  return null;
321
494
  };
322
495
  };
323
- z = N([r(), j("design:paramtypes", [Array])], z);
496
+ Z = G([r(), U("design:paramtypes", [Array])], Z);
324
497
  //#endregion
325
498
  //#region packages/annotation-api/src/lib/annotation-api.module.ts
326
- var B, V = B = class {
499
+ var Q, $ = Q = class {
327
500
  static forService(e) {
328
501
  return {
329
- module: B,
502
+ module: Q,
330
503
  global: !0,
331
- controllers: [L],
504
+ controllers: [Y],
332
505
  providers: [{
333
- provide: P,
506
+ provide: K,
334
507
  useClass: e.annotationDefinitionService
335
508
  }],
336
- exports: [P]
509
+ exports: [K]
337
510
  };
338
511
  }
339
512
  static async forResourceDir(e, t) {
340
- let n = () => I(e, t, O), r = new F(t, n(), n), i = new z(R(e, t));
513
+ let n = () => J(e, t, j), r = new q(t, n(), n), i = new Z(X(e, t));
341
514
  return {
342
- module: B,
515
+ module: Q,
343
516
  global: !0,
344
- controllers: [L],
517
+ controllers: [Y],
345
518
  providers: [
346
519
  {
347
- provide: A,
520
+ provide: H,
348
521
  useValue: t
349
522
  },
350
523
  {
351
- provide: P,
524
+ provide: K,
352
525
  useValue: r
353
526
  },
354
527
  {
355
- provide: z,
528
+ provide: Z,
356
529
  useValue: i
357
530
  }
358
531
  ],
359
- exports: [P, z]
532
+ exports: [K, Z]
360
533
  };
361
534
  }
362
535
  };
363
- V = B = N([i({
536
+ $ = Q = G([i({
364
537
  controllers: [],
365
538
  providers: [],
366
539
  exports: []
367
- })], V);
540
+ })], $);
368
541
  //#endregion
369
- export { A as ANNOTATION_DEF_CONFIG_TOKEN, V as AnnotationApiModule, F as AnnotationDefinitionFromFilesService, P as AnnotationDefinitionService, z as AnnotationResourceDefinitionService, h as annotationColumnDefinition, g as annotationDefinition, I as loadAnnotationDefinitionsFromDir, R as loadAnnotationResourcesFromDir };
542
+ export { H as ANNOTATION_DEF_CONFIG_TOKEN, $ as AnnotationApiModule, q as AnnotationDefinitionFromFilesService, K as AnnotationDefinitionService, b as AnnotationMetadataType, Z as AnnotationResourceDefinitionService, E as AnnotationStyleContextBuilder, T as AnnotationStyleType, ae as SourceModelSchema, y as SourceTextSchema, x as annotationColumnDefinition, j as annotationContextBuilderFactory, ce as annotationDefinition, he as annotationUtils, w as baseContextBuilder, M as buildAnnotationDefinition, fe as buildAnnotationDefinitions, oe as buildGridStyle, k as buildMetadataSchema, O as buildUiSchema, ge as createAnnotationConfiguration, de as createAnnotationStyleBodyUnsafe, z as defaultRender, se as getPaneArea, A as jsonSchemaPropertyToZod, J as loadAnnotationDefinitionsFromDir, X as loadAnnotationResourcesFromDir, C as resolveConfig, B as styleFn };
@@ -7,19 +7,19 @@ export declare class AnnotationNamespaceController {
7
7
  getAll(): Promise<{
8
8
  id: string;
9
9
  name: string;
10
- columns: Record<string, never>[];
10
+ columns: any[];
11
11
  color: string;
12
12
  isRoot: boolean;
13
+ allowedChildren: string[];
14
+ allowedLinks: string[];
13
15
  context: unknown;
16
+ target: "gutter" | "underline" | "highlight";
14
17
  json_schema?: any;
15
18
  json_ld?: any;
16
19
  ui_schema?: any;
17
20
  metadata_schema?: any;
18
21
  type?: string | undefined;
19
22
  icon?: string | undefined;
20
- allowedChildren?: string[] | undefined;
21
- allowedLinks?: string[] | undefined;
22
- target?: "gutter" | "underline" | "highlight" | undefined;
23
23
  }[]>;
24
24
  getJsonLd_(id: string): Promise<any>;
25
25
  getSchemas(id: string): Promise<{
@@ -28,30 +28,30 @@ export declare class AnnotationNamespaceController {
28
28
  json_schema: any;
29
29
  ui_schema: any;
30
30
  metadata_schema: any;
31
- columns: Record<string, never>[];
31
+ columns: any[];
32
32
  isRoot: boolean;
33
- allowedChildren: string[] | undefined;
34
- allowedLinks: string[] | undefined;
33
+ allowedChildren: string[];
34
+ allowedLinks: string[];
35
35
  type: string | undefined;
36
36
  icon: string | undefined;
37
- target: "gutter" | "underline" | "highlight" | undefined;
37
+ target: "gutter" | "underline" | "highlight";
38
38
  }>;
39
39
  getById(id: string): Promise<{
40
40
  id: string;
41
41
  name: string;
42
- columns: Record<string, never>[];
42
+ columns: any[];
43
43
  color: string;
44
44
  isRoot: boolean;
45
+ allowedChildren: string[];
46
+ allowedLinks: string[];
45
47
  context: unknown;
48
+ target: "gutter" | "underline" | "highlight";
46
49
  json_schema?: any;
47
50
  json_ld?: any;
48
51
  ui_schema?: any;
49
52
  metadata_schema?: any;
50
53
  type?: string | undefined;
51
54
  icon?: string | undefined;
52
- allowedChildren?: string[] | undefined;
53
- allowedLinks?: string[] | undefined;
54
- target?: "gutter" | "underline" | "highlight" | undefined;
55
55
  }>;
56
56
  getFullJsonLd(): Promise<{
57
57
  '@context': Record<string, unknown>;
@@ -8,19 +8,19 @@ export declare class AnnotationDefinitionFromFilesService extends AnnotationDefi
8
8
  protected reloadDefinitions: () => Promise<{
9
9
  id: string;
10
10
  name: string;
11
- columns: Record<string, never>[];
11
+ columns: any[];
12
12
  color: string;
13
13
  isRoot: boolean;
14
+ allowedChildren: string[];
15
+ allowedLinks: string[];
14
16
  context: unknown;
17
+ target: "gutter" | "underline" | "highlight";
15
18
  json_schema?: any;
16
19
  json_ld?: any;
17
20
  ui_schema?: any;
18
21
  metadata_schema?: any;
19
22
  type?: string | undefined;
20
23
  icon?: string | undefined;
21
- allowedChildren?: string[] | undefined;
22
- allowedLinks?: string[] | undefined;
23
- target?: "gutter" | "underline" | "highlight" | undefined;
24
24
  }[]>;
25
25
  }
26
26
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ghentcdh/annotation-api",
3
- "version": "0.0.1-alpha.1",
3
+ "version": "0.0.1-alpha.10",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/GhentCDH/annotation-editor"