jpfun 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +200 -200
- package/README.md +191 -133
- package/dist/diagnostic.js +5 -2
- package/dist/fraction.d.ts +24 -0
- package/dist/fraction.js +132 -0
- package/dist/functions/ASTtypes.d.ts +24 -7
- package/dist/functions/ASTtypes.js +35 -16
- package/dist/functions/adjust/index.d.ts +2 -0
- package/dist/functions/adjust/index.js +193 -0
- package/dist/functions/bar/index.d.ts +8 -0
- package/dist/functions/bar/index.js +48 -19
- package/dist/functions/beam/auto.js +35 -18
- package/dist/functions/beam/index.js +10 -6
- package/dist/functions/beam/layout.d.ts +3 -2
- package/dist/functions/beam/layout.js +42 -64
- package/dist/functions/box/index.js +35 -34
- package/dist/functions/br/index.js +14 -12
- package/dist/functions/dash/index.js +37 -5
- package/dist/functions/default.js +14 -7
- package/dist/functions/div/index.d.ts +16 -0
- package/dist/functions/div/index.js +51 -23
- package/dist/functions/dot/index.js +16 -8
- package/dist/functions/grace/index.d.ts +8 -18
- package/dist/functions/grace/index.js +98 -99
- package/dist/functions/head/index.d.ts +2 -0
- package/dist/functions/head/index.js +492 -0
- package/dist/functions/key/index.js +98 -5
- package/dist/functions/meter/index.d.ts +2 -0
- package/dist/functions/meter/index.js +154 -0
- package/dist/functions/note/accidentals.d.ts +24 -3
- package/dist/functions/note/accidentals.js +31 -1
- package/dist/functions/note/index.js +60 -80
- package/dist/functions/page/index.d.ts +9 -2
- package/dist/functions/page/index.js +50 -4
- package/dist/functions/set/index.js +42 -34
- package/dist/functions/stack/index.js +39 -34
- package/dist/functions/symbol/index.d.ts +21 -0
- package/dist/functions/symbol/index.js +94 -0
- package/dist/functions/symbol/ornament.d.ts +15 -0
- package/dist/functions/symbol/ornament.js +73 -0
- package/dist/functions/symbol/shape.d.ts +22 -0
- package/dist/functions/symbol/shape.js +48 -0
- package/dist/functions/symbol/symbols/accent.d.ts +2 -0
- package/dist/functions/symbol/symbols/accent.js +24 -0
- package/dist/functions/symbol/symbols/f.d.ts +2 -0
- package/dist/functions/symbol/symbols/f.js +55 -0
- package/dist/functions/symbol/symbols/fermata.d.ts +2 -0
- package/dist/functions/symbol/symbols/fermata.js +24 -0
- package/dist/functions/symbol/symbols/mordent.d.ts +2 -0
- package/dist/functions/symbol/symbols/mordent.js +43 -0
- package/dist/functions/symbol/symbols/p.d.ts +2 -0
- package/dist/functions/symbol/symbols/p.js +61 -0
- package/dist/functions/symbol/symbols/tr.d.ts +2 -0
- package/dist/functions/symbol/symbols/tr.js +75 -0
- package/dist/functions/tempo/glyph.d.ts +12 -0
- package/dist/functions/tempo/glyph.js +30 -0
- package/dist/functions/tempo/index.js +53 -3
- package/dist/functions/text/index.js +78 -26
- package/dist/functions/tie/index.js +103 -128
- package/dist/functions/tuplet/index.d.ts +2 -0
- package/dist/functions/tuplet/index.js +211 -0
- package/dist/functions/{over → up}/index.d.ts +1 -0
- package/dist/functions/up/index.js +370 -0
- package/dist/functions/voice/index.js +125 -108
- package/dist/functions/volta/index.d.ts +2 -0
- package/dist/functions/volta/index.js +227 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/jpfun.min.js +143 -0
- package/dist/layout/engine.d.ts +4 -11
- package/dist/layout/engine.js +100 -66
- package/dist/layout/model.d.ts +8 -1
- package/dist/layout/model.js +16 -6
- package/dist/layout/path.d.ts +19 -0
- package/dist/layout/path.js +101 -0
- package/dist/layout/types.d.ts +51 -18
- package/dist/layout/types.js +3 -1
- package/dist/lowering/loweringContext.d.ts +19 -23
- package/dist/lowering/loweringContext.js +179 -187
- package/dist/lowering/track.d.ts +33 -10
- package/dist/lowering/track.js +6 -6
- package/dist/lowering/types.d.ts +57 -43
- package/dist/lowering/types.js +20 -4
- package/dist/parser/parse-utils/call-utils.d.ts +0 -2
- package/dist/parser/parse-utils/call-utils.js +0 -6
- package/dist/parser/parse-utils/note-utils.d.ts +8 -0
- package/dist/parser/parse-utils/note-utils.js +35 -13
- package/dist/parser/parse-utils/string-utils.d.ts +8 -0
- package/dist/parser/parse-utils/string-utils.js +20 -0
- package/dist/parser/parserContext.d.ts +8 -5
- package/dist/parser/parserContext.js +38 -33
- package/dist/parser/preprocess.js +17 -11
- package/dist/playback/compile.d.ts +18 -0
- package/dist/playback/compile.js +401 -0
- package/dist/playback/event.d.ts +91 -0
- package/dist/playback/event.js +87 -0
- package/dist/playback/time.d.ts +14 -0
- package/dist/playback/time.js +81 -0
- package/dist/playback/types.d.ts +128 -0
- package/dist/playback/types.js +3 -0
- package/dist/render/canvas.d.ts +4 -4
- package/dist/render/canvas.js +20 -5
- package/dist/render/index.d.ts +1 -0
- package/dist/render/index.js +1 -0
- package/dist/render/paint.d.ts +8 -0
- package/dist/render/paint.js +101 -0
- package/dist/render/svg.d.ts +3 -3
- package/dist/render/svg.js +10 -8
- package/dist/render/text.d.ts +17 -0
- package/dist/render/text.js +35 -0
- package/dist/render/types.d.ts +1 -1
- package/grammar.md +217 -122
- package/package.json +14 -9
- package/dist/functions/over/index.js +0 -307
package/dist/index.js
CHANGED
|
@@ -2,6 +2,7 @@ export * from "./pipeline.js";
|
|
|
2
2
|
export * from "./functions/ASTtypes.js";
|
|
3
3
|
export * from "./functions/default.js";
|
|
4
4
|
export * from "./diagnostic.js";
|
|
5
|
+
export * from "./fraction.js";
|
|
5
6
|
export * from "./parser/types.js";
|
|
6
7
|
export * from "./parser/grammarType.js";
|
|
7
8
|
export * from "./parser/parserContext.js";
|
|
@@ -9,6 +10,9 @@ export * from "./parser/preprocess.js";
|
|
|
9
10
|
export * from "./lowering/types.js";
|
|
10
11
|
export * from "./lowering/loweringContext.js";
|
|
11
12
|
export * from "./lowering/track.js";
|
|
13
|
+
export * from "./playback/types.js";
|
|
14
|
+
export * from "./playback/time.js";
|
|
15
|
+
export * from "./playback/compile.js";
|
|
12
16
|
export * from "./layout/types.js";
|
|
13
17
|
export * from "./layout/model.js";
|
|
14
18
|
export * from "./layout/default.js";
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/*! jpfun | Apache-2.0 | github.com/madderscientist/jpFun */
|
|
2
|
+
"use strict";var jpfun=(()=>{var Se=Object.defineProperty;var ds=Object.getOwnPropertyDescriptor;var gs=Object.getOwnPropertyNames;var xs=Object.prototype.hasOwnProperty;var ys=(r,t)=>{for(var e in t)Se(r,e,{get:t[e],enumerable:!0})},bs=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of gs(t))!xs.call(r,o)&&o!==e&&Se(r,o,{get:()=>t[o],enumerable:!(n=ds(t,o))||n.enumerable});return r};var ws=r=>bs(Se({},"__esModule",{value:!0}),r);var Zi={};ys(Zi,{ANCHOR_KEY:()=>W,ASTBraceNode:()=>$,ASTFunctionNode:()=>L,ASTLabelNode:()=>q,ASTNodeBase:()=>V,ASTTextNode:()=>H,CanvasPainter:()=>xe,CanvasTextMeasurer:()=>je,DEFAULT_BPM:()=>ot,DEFAULT_FONT_SIZE:()=>bo,DEFAULT_KEY:()=>Q,DEFAULT_OCTAVE:()=>ei,DEFAULT_PAGE_CONFIG:()=>U,DEFAULT_TEXT_FONT:()=>qt,DEFAULT_TONALITY:()=>Nt,DEFAULT_VELOCITY:()=>_t,DefaultTextMeasurer:()=>Zt,Diagnostic:()=>E,ErrorDiagnostic:()=>S,Fraction:()=>M,JIANPU_NUMBER_FONT:()=>et,LoweringContext:()=>$t,PageLayoutError:()=>wt,ParserContext:()=>X,RecordingPainter:()=>$n,SYSTEM_VARIABLE_TYPES:()=>We,SvgPainter:()=>ge,TemporalNodeBase:()=>D,Track:()=>Ft,WarningDiagnostic:()=>C,analyzeScoreSyntax:()=>Bi,canvasFont:()=>Qt,compilePlayback:()=>Gi,compileScore:()=>$i,completeSpringConfig:()=>Gt,createLayoutPrepareContext:()=>kn,defaultFunctions:()=>fe,defaultTextMeasurer:()=>Ze,functionAddonKey:()=>st,isLayoutAttachment:()=>it,isPlaybackRelation:()=>On,isVisualTemporalNode:()=>R,layoutDocument:()=>Re,layoutElement:()=>Vt,layoutHorizontal:()=>Me,layoutHorizontalRegion:()=>bt,layoutPageBounds:()=>mt,normalizePageConfig:()=>Ct,paginateLayoutLines:()=>Ie,paintLayout:()=>Fn,performanceTimeToScoreTime:()=>us,performanceTimeToSeconds:()=>me,prepareLayoutHost:()=>at,preprocessSource:()=>pe,primaryName:()=>Et,renderLayoutPagesToCanvas:()=>ji,renderLayoutPagesToSvg:()=>Ui,resolveArgType:()=>gt,scoreTimeToPerformanceTime:()=>fs,scoreTimeToSeconds:()=>Hi,secondsToPerformanceTime:()=>hs,secondsToScoreTime:()=>zi,skipSpaces:()=>tt,skipSpacesBack:()=>It,unionLayoutBoxes:()=>vt});var E=class r{code;message;span;constructor(t,e,n){this.code=t,this.message=e,this.span=n}toLineCol(t){let e=r.offsetToLineCol(this.span.start,t),n=r.offsetToLineCol(this.span.end,t);return{startLine:e.line,startColumn:e.column,endLine:n.line,endColumn:n.column}}static offsetToLineCol(t,e){let n=e.length;if(n===0)return{line:1,column:Math.max(0,t)+1};let o=t;o<0&&(o=0);let s=0,i=n-1;for(;s<=i;){let l=s+i>>1;e[l]<=o?s=l+1:i=l-1}let a=Math.max(0,i),c=e[a]??0;return{line:a+1,column:o-c+1}}static error;static warning},S=class extends E{},C=class extends E{};E.error={Bug:(r,t)=>new S("E_BUG",`\u89E3\u6790\u5668\u9519\u8BEF: ${r}\uFF0C\u8BF7\u8054\u7CFB\u5F00\u53D1\u8005\u4FEE\u590D\u8FD9\u4E2A\u95EE\u9898`,t),MissingArg:(r,t,e)=>{let n=typeof t=="number"?`[${t}]`:`"${t}"`;return new S("E_MISSING_REQUIRED_ARG",`\u51FD\u6570@${r} \u7F3A\u5C11\u5FC5\u9700\u7684\u53C2\u6570 ${n}`,e)},InvalidArgType:(r,t,e,n,o)=>{let s=typeof t=="number"?`[${t}]`:`"${t}"`;return new S("E_WRONG_ARG_TYPE",`\u51FD\u6570 @${r} \u7684\u53C2\u6570 ${s} \u7C7B\u578B\u9519\u8BEF: \u5F97\u5230\u4E86 ${n}\uFF0C\u4F46\u671F\u671B ${e}`,o)},PosAfterNamedArg:(r,t)=>new S("E_POSARG_AFTER_KWARG",`\u51FD\u6570 @${r} \u7684\u4F4D\u7F6E\u53C2\u6570\u51FA\u73B0\u5728\u547D\u540D\u53C2\u6570\u4E4B\u540E\uFF0C\u8FD9\u662F\u4E0D\u5141\u8BB8\u7684`,t),EmptyContent:(r,t,e)=>{let n=typeof t=="number"?`[${t}]`:`"${t}"`;return new S("E_EMPTY_CONTENT",`\u51FD\u6570 @${r} \u7684\u53C2\u6570 ${n} \u5185\u5BB9\u4E3A\u7A7A(\u6216\u65E0\u53EF\u7528\u5185\u5BB9)\uFF1B\u8BF7\u63D0\u4F9B\u6709\u6548\u5185\u5BB9`,e)},UnterminatedCall:(r,t)=>new S("E_UNTERMINATED_CALL",`\u51FD\u6570\u8C03\u7528\u672A\u95ED\u5408: @${r}(...)`,t),UnterminatedString:r=>new S("E_UNTERMINATED_String","\u5F15\u53F7\u672A\u95ED\u5408",r),UnknownFunction:(r,t)=>new S("E_UNKNOWN_FUNCTION",`\u672A\u77E5\u51FD\u6570: @${r}\uFF0C\u8BF7\u68C0\u67E5\u62FC\u5199`,t),UnknownLabel:(r,t)=>new S("E_UNKNOWN_LABEL",`\u672A\u77E5\u6807\u7B7E: "${r}"`,t),InvalidTonality:(r,t)=>new S("E_INVALID_TONALITY",`\u65E0\u6548\u7684\u8C03\u6027: "${r}"\uFF0C\u8BF7\u63D0\u4F9B\u6709\u6548\u7684\u8C03\u6027\u540D\u79F0\uFF0C\u5FC5\u987B [\u4E00\u4E2A\u5927\u5199\u5B57\u6BCD][\u53D8\u97F3\u8BB0\u53F7#bn\u53EA\u80FD\u4E00\u4E2A][\u7EDD\u5BF9\u516B\u5EA6\u6570\u5B57]\uFF0C\u540E\u4E8C\u8005\u53EF\u9009`,t),BreakInsideEvent:r=>new S("E_BREAK_INSIDE_EVENT","\u6362\u884C\u5207\u65AD\u4E86\u4E00\u4E2A\u4ECD\u5728\u6301\u7EED\u7684\u4E8B\u4EF6\uFF1B\u8BF7\u628A\u957F\u97F3\u5199\u6210\u591A\u4E2A\u4E8B\u4EF6\uFF0C\u6216\u8C03\u6574 @br \u7684\u4F4D\u7F6E",r),InvalidPageConfig:(r,t)=>new S("E_INVALID_PAGE_CONFIG",r,t),PageOverflow:(r,t,e)=>new S("E_PAGE_OVERFLOW",`\u8C31\u9762\u884C\u9700\u8981 ${r}px \u9AD8\u5EA6\uFF0C\u4F46\u9875\u9762\u5185\u5BB9\u533A\u53EA\u6709 ${t}px`,e)};E.warning={UnknownFunction:(r,t)=>new C("W_UNKNOWN_FUNCTION",`\u672A\u77E5\u51FD\u6570: @${r}\uFF0C\u5C06\u88AB\u5F53\u4F5C\u666E\u901A\u6587\u672C\u5904\u7406`,t),UnknownNamedArg:(r,t,e)=>new C("W_UNKNOWN_NAMED_ARG",`\u51FD\u6570 @${r} \u6536\u5230\u672A\u77E5\u7684\u547D\u540D\u53C2\u6570 "${t}"`,e),TooManyPosArgs:(r,t,e,n)=>new C("W_TOO_MANY_POS_ARGS",`\u51FD\u6570 @${r} \u63A5\u6536\u4E86\u8FC7\u591A\u7684\u4F4D\u7F6E\u53C2\u6570\uFF0C\u671F\u671B ${t} \u4E2A\u4F46\u5F97\u5230\u4E86 ${e} \u4E2A`,n),InvalidNumber:(r,t)=>new C("W_INVALID_NUMBER",`\u65E0\u6548\u7684\u6570\u5B57: "${r}"\uFF1B\u5C06\u4F7F\u7528\u9ED8\u8BA4\u503C(\u82E5\u5B58\u5728)`,t),InvalidBoolean:(r,t)=>new C("W_INVALID_BOOL",`\u65E0\u6548\u7684\u5E03\u5C14\u503C: "${r}": \u5E94\u4E3A 'true' \u6216 'false'\uFF1B\u5C06\u4F7F\u7528\u9ED8\u8BA4\u503C(\u82E5\u5B58\u5728)`,t),InvalidLength:(r,t)=>new C("W_INVALID_LENGTH",`\u65E0\u6548\u7684\u957F\u5EA6\u503C: "${r}"\uFF1B\u8BF7\u63D0\u4F9B\u6709\u6548\u7684\u957F\u5EA6\u503C\uFF0C\u4F8B\u5982 "10px" \u6216 "2em"\uFF1B\u5C06\u4F7F\u7528\u9ED8\u8BA4\u503C(\u82E5\u5B58\u5728)`,t),InvalidLengthUnit:(r,t)=>new C("W_INVALID_LENGTH_UNIT",`\u65E0\u6548\u7684\u957F\u5EA6\u5355\u4F4D: "${r}"\uFF1B\u4EC5\u652F\u6301 "px" \u548C "em"\uFF1B\u8BF7\u68C0\u67E5\u51FD\u6570\u53C2\u6570\u6216\u53D8\u91CF\u5B9A\u4E49\uFF1B\u5C06\u4F7F\u7528\u9ED8\u8BA4\u503C(\u82E5\u5B58\u5728)`,t),InvalidContent:r=>new C("W_INVALID_CONTENT","\u5185\u5BB9\u89E3\u6790\u5931\u8D25\uFF0C\u9519\u8BEF\u539F\u56E0\u89C1\u4E0A\uFF1B\u5C06\u4F7F\u7528\u9ED8\u8BA4\u503C(\u4F46\u5F80\u5F80\u4E0D\u5B58\u5728\uFF0C\u6781\u6709\u53EF\u80FD\u5BFC\u81F4\u9519\u8BEF)",r),EmptyContent:(r,t,e)=>new C("W_EMPTY_CONTENT",`\u51FD\u6570 @${r} \u7684\u53C2\u6570 "${t}" \u5185\u5BB9\u4E3A\u7A7A(\u6216\u65E0\u53EF\u7528\u5185\u5BB9)`,e),UnmatchedBrace:r=>new C("W_UNMATCHED_BRACE","\u672A\u5339\u914D\u7684\u5927\u62EC\u53F7: \u7F3A\u5C11\u53F3\u5927\u62EC\u53F7'}'\uFF1B\u5C06\u5C1D\u8BD5\u81EA\u52A8\u4FEE\u590D",r),LabelWithoutTarget:(r,t)=>new C("W_LABEL_WITHOUT_TARGET",`\u6807\u7B7E "${r}" \u6CA1\u6709\u53EF\u7ED1\u5B9A\u7684\u76EE\u6807\uFF1B\u6807\u7B7E\u5C06\u88AB\u5FFD\u7565`,t),TargetAlreadyLabeled:(r,t,e)=>new C("W_TARGET_ALREADY_LABELED",`\u76EE\u6807\u5DF2\u6807\u6CE8\u4E3A "${t}"\uFF0C"${r}" \u5C06\u88AB\u5FFD\u7565`,e),UnresolvedEndpoint:(r,t)=>new C("W_UNRESOLVED_ENDPOINT",`@${r} \u6709\u7AEF\u70B9\u627E\u4E0D\u5230\u5BF9\u5E94\u7684\u8C31\u9762\u5BF9\u8C61\uFF1B\u8BE5\u5173\u7CFB\u5C06\u88AB\u5FFD\u7565`,t),ZeroTimeTrack:(r,t)=>new C("W_ZERO_TIME_TRACK",`\u7B2C${t}\u4E2A\u5B50\u8F68\u9053\u7684\u65F6\u957F\u4E3A0`,r)};function st(r){return`@${r}`}var V=class{sourceSpan;parent;get children(){return null}constructor(t,e=null){this.sourceSpan=t,this.parent=e}static loweringAugment;static loweringFinalize;static layoutDecorationHandler;loweringEnter(t,e){return[]}timeFlowModel(){return null}loweringExit(t,e,n){return[]}toString(t){return t.slice(this.sourceSpan.start,this.sourceSpan.end)}},H=class extends V{},q=class extends V{label;target;constructor(t,e,n,o=null){super(t,o),this.label=e,this.target=n}toString(t){return`@${this.label} `}},$=class r extends V{content;get children(){return this.content}constructor(t,e,n=null){super(t,n),this.content=e,this.content.forEach(o=>o.parent=this)}innerSpan(){return r.getContentSpan(this.content)}static getContentSpan(t){if(Array.isArray(t)){if(t.length===0)return{start:0,end:0};let e=r.getContentSpan(t[0]),n=r.getContentSpan(t[t.length-1]);return{start:e.start,end:n.end}}else return{start:t.sourceSpan.start,end:t.sourceSpan.end}}timeFlowModel(){return{children:this.content,mode:"sequence"}}toString(t){return`{${this.content.map(e=>e.toString(t)).join("")}}`}};function gt(r,t,e){return t?r.args.find(n=>n.name?.toLowerCase()===t)?.type:r.args[e]?.type??(r.allowExtraArgs?r.extraArgType:void 0)}function Et(r){return Array.isArray(r.name)?r.name[0]:r.name}var L=class r extends V{label;static def;get def(){return this.constructor.def}get callName(){return this.def?Et(this.def):""}static deSugarAtom=()=>null;get deSugarAtom(){return this.constructor.deSugarAtom}static deSugarRelation=()=>null;get deSugarRelation(){return this.constructor.deSugarRelation}getArgValue(t,e){let n=this.def;if(!n)return[];let o=n.args,s=Et(n);return o.map((i,a)=>{let c=i.name?i.name.toLowerCase():null,l=(c?t.get(c):null)??t.get(a)??(c?e.variables[`${s}.${c}`.toLowerCase()]:null)??i.default;if(l===null)throw E.error.MissingArg(s,i.name||a,this.sourceSpan);return l})}toString(t){let e=this.callName;return e?`@${e} `:super.toString(t)}static findLabelable(t){let e=t;if(e.labelable)return e.labelable();for(let n of t.children??[]){let o=r.findLabelable(n);if(o)return o}return null}static findLastFuncContentNode(t,e){for(;e>=0;e--){let n=t[e];if(n instanceof H)return null;if(n instanceof r||n instanceof $)return n}return null}};function Ss(r,t){for(;t!==0;){let e=r%t;r=t,t=e}return r}var M=class r{_numerator=0;_denominator=1;constructor(t=0,e=1){this.set(t,e)}get numerator(){return this._numerator}get denominator(){return this._denominator}set(t,e=1){if(e===0)throw new RangeError("Denominator must not be zero");e<0&&(t=-t,e=-e);let n=Ss(Math.abs(t),e);return this._numerator=t/n,this._denominator=e/n,this}copyFrom(t){return this._numerator=t._numerator,this._denominator=t._denominator,this}clone(){return new r(this._numerator,this._denominator)}add(t,e=1){let n;return typeof t=="number"?n=t:(n=t._numerator,e=t._denominator),this.set(this._numerator*e+n*this._denominator,this._denominator*e)}sub(t,e=1){let n;return typeof t=="number"?n=t:(n=t._numerator,e=t._denominator),this.set(this._numerator*e-n*this._denominator,this._denominator*e)}mul(t,e=1){let n;return typeof t=="number"?n=t:(n=t._numerator,e=t._denominator),this.set(this._numerator*n,this._denominator*e)}div(t,e=1){let n;if(typeof t=="number"?n=t:(n=t._numerator,e=t._denominator),n===0)throw new RangeError("Cannot divide by zero");return this.set(this._numerator*e,this._denominator*n)}divPow2(t=1){if(this._numerator===0)return this;for(;t>0&&this._numerator%2===0;)this._numerator/=2,t--;return this._denominator*=2**t,this}compare(t,e=1){let n;typeof t=="number"?n=t:(n=t._numerator,e=t._denominator);let o=this._numerator*e-n*this._denominator;return o<0?-1:o>0?1:0}equals(t,e=1){return t instanceof r?this._numerator===t._numerator&&this._denominator===t._denominator:this._numerator*e===t*this._denominator}isZero(){return this._numerator===0}toNumber(){return this._numerator/this._denominator}toString(){return this._denominator===1?String(this._numerator):`${this._numerator}/${this._denominator}`}};var ot=120,_t=80,Nt="C4",W=-1/0,Q=1/0,D=class{t=new M;T=new M;track;ast;order;addon;mergeKey;foldedInto;breakBefore=0;layoutLine=0;box;springConfig;ports;decorations;initLayoutBox(){return this.box={x:0,y:0,w:0,h:0,anchor:0,visualAxis:0}}playbackState;prepareLayout(t){}paint(t){}};function R(r){return r.box!==void 0}function it(r){return typeof r.createGeometry=="function"}var Ae=class extends L{static def={name:["adjust","adj"],description:"\u5FAE\u8C03\u76EE\u6807\u7684\u4F4D\u7F6E\u4E0E\u5360\u4F4D",example:`@adjust(content, dx=0px, dy=0px, dw=0px, dh=0px)
|
|
3
|
+
dw/dh \u5728\u6392\u7248\u524D\u589E\u51CF\u5360\u4F4D\uFF0C\u6700\u7EC8\u5C3A\u5BF8\u4E0D\u5C0F\u4E8E 0\uFF1Bdw \u6309\u539F\u5DE6\u53F3\u5360\u4F4D\u6BD4\u4F8B\u5206\u914D\uFF0Cdh \u8C03\u6574\u4E0B\u65B9\uFF1B
|
|
4
|
+
dx/dy \u5728\u6392\u7248\u5B8C\u6210\u540E\u5E73\u79FB\u76EE\u6807\uFF0C\u90BB\u5C45\u4E0D\u4F1A\u8BA9\u5F00\uFF0C\u56E0\u6B64\u53EF\u4EE5\u6545\u610F\u91CD\u53E0\u3002
|
|
5
|
+
\u62EC\u4F4F\u7684\u82E5\u662F\u5173\u7CFB\u5BF9\u8C61\uFF08\u8FDE\u97F3\u7EBF\u7B49\uFF09\u4E14\u5176\u4E2D\u6CA1\u6709\u5BF9\u8C61\uFF0C\u5E73\u79FB\u7684\u5C31\u662F\u8FD9\u6761\u5173\u7CFB\u5BF9\u8C61`,allowExtraArgs:!1,args:[{type:"content",default:null},{name:"dx",type:"length",default:{value:0,unit:"px"}},{name:"dy",type:"length",default:{value:0,unit:"px"}},{name:"dw",type:"length",default:{value:0,unit:"px"}},{name:"dh",type:"length",default:{value:0,unit:"px"}}]};target;dx;dy;dw;dh;get children(){return[this.target]}timeFlowModel(){return{children:[this.target],mode:"sequence"}}loweringEnter(t){let e={temporal:0,attachment:0},n={targets:e,onTemporal:o=>{R(o)&&(e.temporal++,As(o,this))},onAttachment:o=>{it(o)&&(e.attachment++,Ts(o,e,this.dx,this.dy))}};return t.beginLoweringGroup(this,n),[]}loweringExit(t){let e=t.endLoweringGroup(this);return e.targets.temporal===0&&e.targets.attachment===0&&t.diagnostics.push(new C("W_ADJUST_NO_TARGET","@adjust \u6CA1\u6709\u627E\u5230\u53EF\u8C03\u6574\u7684\u5BF9\u8C61",this.sourceSpan)),[]}constructor(t,e,n,o=null){super(t,o);let[s,i,a,c,l]=this.getArgValue(e,n);s.parent=this,this.target=s,this.dx=n.length2px(i),this.dy=n.length2px(a),this.dw=n.length2px(c),this.dh=n.length2px(l)}},Hn=Ae;function As(r,t){let{dx:e,dy:n,dw:o,dh:s}=t;if(e===0&&n===0&&o===0&&s===0)return;let i,a,c=r.finalizeLayout,l=r.onPlaced;r.finalizeLayout=h=>{c?.call(r,h);let u=Math.max(0,r.box.w+o);r.box.anchor=r.box.w>0?r.box.anchor*u/r.box.w:0,r.box.w=u,r.box.h=Math.max(0,r.box.h+s)},r.onPlaced=()=>{r.box.x!==i&&(r.box.x+=e),r.box.y!==a&&(r.box.y+=n),l?.call(r),i=r.box.x,a=r.box.y}}function Ts(r,t,e,n){if(e===0&&n===0)return;let o=r.createGeometry;r.createGeometry=s=>{let i=o.call(r,s);if(t.temporal>0)return i;let a=c=>c.line===void 0?{x:c.x+e,y:c.y+n,w:c.w,h:c.h}:{x:c.x+e,y:c.y+n,w:c.w,h:c.h,line:c.line,track:c.track};return{regions:i.regions.map(a),occupancy:i.occupancy?.map(a),paint(c){i.paint(new Te(c,e,n))}}}}var Te=class{target;dx;dy;constructor(t,e,n){this.target=t,this.dx=e,this.dy=n}drawText(t,e,n,o){this.target.drawText(t,e+this.dx,n+this.dy,o)}drawLine(t,e,n,o,s){this.target.drawLine(t+this.dx,e+this.dy,n+this.dx,o+this.dy,s)}drawRect(t,e,n,o,s){this.target.drawRect(t+this.dx,e+this.dy,n,o,s)}drawCircle(t,e,n,o){this.target.drawCircle(t+this.dx,e+this.dy,n,o)}drawPath(t,e,n){if(n){let o={...n,x:n.x+this.dx,y:n.y+this.dy};this.target.drawPath(t,e,o);return}this.target.drawPath(t.map(o=>this.translateCommand(o)),e)}translateCommand(t){switch(t.op){case"Z":return t;case"Q":return{op:"Q",cx:t.cx+this.dx,cy:t.cy+this.dy,x:t.x+this.dx,y:t.y+this.dy};case"C":return{op:"C",cx1:t.cx1+this.dx,cy1:t.cy1+this.dy,cx2:t.cx2+this.dx,cy2:t.cy2+this.dy,x:t.x+this.dx,y:t.y+this.dy};default:return{op:t.op,x:t.x+this.dx,y:t.y+this.dy}}}};var Le=class extends L{static def={name:["bar","|"],description:"\u5C0F\u8282\u7EBF",example:`@bar(type, lengthEM) \u521B\u5EFA\u4E00\u4E2A\u5C0F\u8282\u7EBF
|
|
6
|
+
\u8BED\u6CD5\u7CD6:
|
|
7
|
+
- type0: '|' \u666E\u901A\u5C0F\u8282\u7EBF
|
|
8
|
+
- type1: '||' \u7EC8\u6B62\u5C0F\u8282\u7EBF \u5DE6\u7EC6\u53F3\u7C97
|
|
9
|
+
- type2: '|:' \u91CD\u590D\u5C0F\u8282\u7EBF \u5DE6\u7C97\u53F3\u7EC6
|
|
10
|
+
- type3: ':|'
|
|
11
|
+
- type4: ':|:' \u5DE6\u53F3\u53CD\u590D
|
|
12
|
+
`,allowExtraArgs:!1,args:[{name:"type",type:"number",default:0},{name:"length",type:"length",default:{value:1.25,unit:"em"}}]};static deSugarAtom(t,e,n){let o=e,s=0,i=t.slice(o,o+2);if(i==="||")s=1,o+=2;else if(i==="|:")s=2,o+=2;else if(i===":|")t[o+2]===":"?(s=4,o+=3):(s=3,o+=2);else if(t[o]==="|")s=0,o+=1;else return null;let a=new Map;return a.set("type",s),{next:o,node:{kind:"call",typed:!0,name:"bar",args:a,span:{start:e,end:o},syntaxKind:"atom"}}}type;size;constructor(t,e,n,o=null){super(t,o);let[s,i]=this.getArgValue(e,n);this.type=s,this.size=n.length2px(i)}loweringEnter(){return[this.type>=2?new _e(this):new Ht(this)]}toString(){return`@bar(${this.type}, ${this.size}px)`}},Wn=Le,Ht=class r extends D{lines=[];repeatDots=[];constructor(t){super(),this.ast=t,this.mergeKey=W,this.initLayoutBox(),this.springConfig={alpha_L:128,alpha_R:128}}prepareHorizontal(t){let e=t.trackRuns.get(this.track),n=e?.indexOf(this)??-1;!e||n<0||t.registerHorizontalLayoutHook(this,this,({columns:o,start:s})=>{let i=o[s].find(u=>u.time===this);if(!i)return;let a=u=>{let f=t.columnOf(u);return f<0?void 0:o[f].find(g=>g.time===u)},c=n>0?a(e[n-1]):void 0;c&&(c.config.mu_R*=4,i.config.mu_L*=4);let l=e[n+1],h=l?a(l):void 0;h&&!(l instanceof r)&&(i.config.mu_R*=4,h.config.mu_L*=4)})}prepareLayout(){let{type:t,size:e}=this.ast;this.lines.length=0,this.repeatDots.length=0;let n=e,o=Math.max(1,e*.065),s=o*2.6,i=o*1.8,a=o*.8,c=i+a,l=t===3||t===4,h=t===2||t===4,u=l?a*2+c:0;if(t===1||t===3||t===4?(this.lines.push({x:u,w:o}),u+=o+i,this.lines.push({x:u,w:s}),u+=s):t===2?(this.lines.push({x:u,w:s}),u+=s+i,this.lines.push({x:u,w:o}),u+=o):(this.lines.push({x:u,w:o}),u+=o),l){let f=a;this.repeatDots.push({x:f,y:n*.38}),this.repeatDots.push({x:f,y:n*.62})}if(h){let f=u+c;this.repeatDots.push({x:f,y:n*.38}),this.repeatDots.push({x:f,y:n*.62}),u=f+a}this.box.w=u,this.box.h=n,this.box.anchor=u/2,this.box.visualAxis=n/2}paint(t){for(let n of this.lines)t.drawRect(this.box.x+n.x,this.box.y,n.w,this.box.h,{fill:"#000"});let e=Math.max(1,this.box.w*.06);for(let n of this.repeatDots)t.drawCircle(this.box.x+n.x,this.box.y+n.y,e,{fill:"#000"})}},Ee="repeat.start";function Gn(r,t){return r.visits(r.seek(Ee,t+1,-1)??0)}var _e=class extends Ht{playbackMarks(){return this.ast.type===3?[]:[Ee]}playbackFlow(t){if(this.ast.type===2)return;let e=t(this);if(e!==void 0)return{range:[e,e],run:n=>n.visits(e)>1?void 0:{kind:"jump",column:n.seek(Ee,e,-1)??0}}}};var Vn="div",rt=st(Vn);function J(r,t){return`div.${r}.${t}`}function Yn(r,t){let e=r.ports[J(t,"left")];e&&(e.claimed=!0)}function ke(r){return Math.max(1,r*.055)}function*Un(r){for(let t=0;;t++){let e=!1,n=-1;for(let o=0;o<=r.length;o++){let s=r[o]?.ports,i=s?.[J(t,"left")],a=s?.[J(t,"right")];if((i||a)&&(e=!0),i&&a){n<0&&(n=o);continue}n>=0&&o-n>=2&&(yield{level:t,from:n,to:o-1}),n=-1}if(!e)return}}var Ne=class r extends L{static def={name:[Vn,"/"],description:"\u51CF\u65F6\u7EBF",example:`@div(C1, 2): C1\u4E0B\u65B9\u521B\u5EFA2\u6839\u51CF\u65F6\u7EBF
|
|
13
|
+
@/({C1 C2 @dash()}, 3): C1\u3001C2\u548C\u589E\u65F6\u7EBF\u4E0B\u65B9\u521B\u5EFA3\u6839\u51CF\u65F6\u7EBF\u5E76\u8FDE\u63A5
|
|
14
|
+
\u8BED\u6CD5\u7CD6\uFF1A\u5728\u97F3\u7B26\u540E\u52A0\u659C\u6760'/'\uFF0C\u53EF\u4EE5\u591A\u4E2A
|
|
15
|
+
@div(C1, 2) === C1//
|
|
16
|
+
@div(C1 C2/ @dash(), 2) === {C1 C2/ @dash()}//
|
|
17
|
+
\u8BBE\u7F6E\u547D\u540D\u53C2\u6570\u524D\u7F00: div
|
|
18
|
+
`,allowExtraArgs:!1,args:[{type:"content",default:null},{name:"n",type:"number",default:1},{name:"autobeam",type:"boolean",default:!0}]};static deSugarAtom(t,e,n){let o=0,s=e;for(;s<n&&t[s]==="/";)o++,s++;return o===0?null:{next:s,node:{kind:"sugar",data:{class:r,n:o},span:{start:e,end:s}}}}static deSugarRelation(t,e,n){let o=e[n++];if(o.data?.class!==r)return null;let s=L.findLastFuncContentNode(t.nodes,t.nodes.length-1);if(!s)return n;if(s instanceof r)return s.n+=o.data.n,n;let i=new Map;i.set(0,s),i.set("n",o.data.n);let a=s.sourceSpan,c=new r({start:Math.min(a.start,o.span.start),end:Math.max(a.end,o.span.end)},i,t,null);return t.nodes.pop(),t.pushNode(c),n}static layoutDecorationHandler=(t,e)=>{let n=Math.max(0,Math.floor(Number(e)||0));if(n===0)return null;let o=t.ast.size*.14,s=ke(t.ast.size),i=(n-1)*o+s,a=0,c=0,l=0;return{below:{order:0,gap:-t.ast.size*.08,height:i,place(h){a=t.ports["body.left"]?.x??0,c=t.ports["body.right"]?.x??t.box.w,l=h+s/2;for(let u=0;u<n;u++){let f=l+u*o;t.ports[J(u,"left")]={x:a,y:f},t.ports[J(u,"right")]={x:c,y:f}}}},paint(h){for(let u=0;u<n;u++){if(t.ports[J(u,"left")].claimed)continue;let g=t.box.y+l+u*o;h.drawLine(t.box.x+a,g,t.box.x+c,g,{stroke:"#000",strokeWidth:s})}}}};loweringEnter(t){let e=this.n;return t.beginLoweringGroup(this,{onTemporal(n){if(e===0)return;let o=n.addon??={};o[rt]=(Number(o[rt])||0)+e,n.T.divPow2(e)}}),[]}loweringExit(t){return t.endLoweringGroup(this),[]}content;n;autoBeamEnabled;get children(){return[this.content]}timeFlowModel(){return{children:[this.content],mode:"sequence"}}constructor(t,e,n,o=null){super(t,o),[this.content,this.n,this.autoBeamEnabled]=this.getArgValue(e,n),this.content.parent=this;let s=Math.max(0,Math.trunc(this.n));s!==this.n&&(n.diagnostics.push(new C("W_DIV_INVALID_N",`@div \u7684\u6570\u91CF\u53C2\u6570 n \u5FC5\u987B\u4E3A\u975E\u8D1F\u6574\u6570\uFF0C\u5DF2\u88AB\u4FEE\u6B63\u4E3A ${s}`,this.sourceSpan)),this.n=s)}toString(t){return`@div(${this.content.toString(t)}, ${this.n})`}},xt=Ne;function yt(r,t,e){return new kt(r,t,e)}function Kn(r){let t=new Map;for(let n of r.columns)for(let o of n){if(!R(o))continue;let s=t.get(o.layoutLine);s||(s=new Map,t.set(o.layoutLine,s));let i=s.get(o.track);i?i.push(o):s.set(o.track,[o])}let e=new Map;for(let[n,o]of t)for(let[s,i]of o)for(let a=0;a<i.length;a++)e.set(i[a],{line:n,track:s,index:a});for(let n of r.attachments)if(!(!(n instanceof kt)||!n.explicit))for(let o=1;o<n.endPoints.length;o++){let s=n.endPoints[o-1],i=n.endPoints[o];if(!R(s)||!R(i))continue;let a=e.get(s),c=e.get(i);if(!(s!==i&&a!==void 0&&c!==void 0&&a.line===c.line&&a.track===c.track&&c.index===a.index+1))throw new S("E_NON_ADJACENT_BEAM","@beam \u7684\u7AEF\u70B9\u5FC5\u987B\u6309\u65F6\u95F4\u987A\u5E8F\u8FDE\u63A5\u540C\u4E00\u8F68\u9053\u3001\u540C\u4E00\u8C31\u9762\u884C\u4E2D\u7684\u76F8\u90BB\u53EF\u89C1\u5143\u7D20",n.sourceSpan)}}function jn(r){let t=new Set;for(let e of r)if(!(!(e instanceof kt)||!e.explicit))for(let n of e.endPoints)t.add(n);return t}var kt=class{layer="foreground";endPoints;explicit;sourceSpan;fontSize;strokeWidth;constructor(t,e,n){this.endPoints=t,this.explicit=e,this.sourceSpan=n,this.fontSize=t.reduce((o,s)=>R(s)?Math.max(o,s.ast.size):o,0),this.strokeWidth=ke(this.fontSize)}prepareHorizontal(t){let e=new Set(this.endPoints);for(let n of t)for(let o of n.trackRuns.values())for(let s=1;s<o.length;s++){let i=o[s-1],a=o[s];!e.has(i)||!e.has(a)||(i.springConfig.alpha_R=i.springConfig.alpha_R*.8,a.springConfig.alpha_L=a.springConfig.alpha_L*.8)}}createGeometry(t){let e=this.collectLines(t),n=this.strokeWidth;return{regions:e.map(s=>({x:Math.min(s.start.x,s.end.x),y:s.start.y-n/2,w:Math.abs(s.end.x-s.start.x),h:n,line:s.line,track:s.track})),paint(s){for(let i of e)s.drawLine(i.start.x,i.start.y,i.end.x,i.end.y,{stroke:"#000",strokeWidth:n})}}}absolutePort(t,e){let n=t.ports[e];return{x:t.box.x+n.x,y:t.box.y+n.y}}collectLines(t){let e=[],n=this.endPoints.filter(R);if(n.length<2)return e;for(let{level:o,from:s,to:i}of Un(n)){let a=[];for(let c=s;c<=i;c++){let l=n[c];a.push({left:this.absolutePort(l,J(o,"left")),right:this.absolutePort(l,J(o,"right")),line:l.layoutLine,track:l.track,node:l})}this.addSystemLines(a,t,o,e)}if(e.length===0&&this.explicit){let o=this.fontSize*.12,s=n.map(i=>{let a={x:i.box.x+i.box.anchor,y:i.box.y+i.box.h+o};return{left:a,right:a,line:i.layoutLine,track:i.track,node:i}});this.addSystemLines(s,t,null,e)}return e}addSystemLines(t,e,n,o){let s=Math.min(...t.map(h=>h.line)),i=Math.max(...t.map(h=>h.line)),a=t[0].track,c=e.getVisualAxis(t[0].line,a),l=t[0].left.y-c;for(let h=s;h<=i;h++){let u=t.filter(p=>p.line===h).sort((p,m)=>p.left.x-m.left.x);if(u.length===0){let m=e.getVisualAxis(h,a)+l;o.push({start:{x:e.originX,y:m},end:{x:e.originX+e.width,y:m},line:h,track:a});continue}let f=u[0],g=u[u.length-1],d=f.left.y,y={x:f.left.x,y:d},x={x:g.right.x,y:d};if(h>s&&(y.x=e.originX),h<i&&(x.x=e.originX+e.width),!(y.x===x.x&&s===i)){if(n!==null)for(let p of u)Yn(p.node,n);o.push({start:y,end:x,line:h,track:f.track})}}}};function Zn(r){let t=[],e=Math.max(0,Math.floor(Number(r.addon?.[rt])||0)),n=i=>{t.push(i),e-=Math.max(0,i.n)},o=r.ast.parent;for(;o&&e>0;)o instanceof xt&&n(o),o=o.parent;let s=i=>{for(let a of i.children??[]){if(e<=0)return;a instanceof xt&&n(a),s(a)}};return s(r.ast),t}function Ls(r){let t=new Map,e=new Map;for(let n of r.columns)for(let o of n){if(!R(o))continue;let s=Zn(o);if(s.length===0)continue;let i=[];for(let a of s){let c=t.get(a);c||(c={owner:a,nodes:[]},t.set(a,c)),c.nodes.push(o),i.push(c)}e.set(o,i)}return{scopes:[...t.values()],nodeScopes:e}}function Es(r){let t=new Set(r.map(e=>e.owner));return r.filter(e=>{let n=e.owner.parent;for(;n;){if(n instanceof xt&&t.has(n))return!1;n=n.parent}return!0})}function _s(r){let t=1/0,e=-1/0;for(let n of r){t=Math.min(t,n.ast.sourceSpan.start),e=Math.max(e,n.ast.sourceSpan.end);for(let o of Zn(n))t=Math.min(t,o.sourceSpan.start),e=Math.max(e,o.sourceSpan.end)}return{start:t,end:e}}function qn(r){return yt(r,!1,_s(r))}function Ns(r,t){let e=[];for(let n of Es(r)){let o=new Map;for(let s of n.nodes){let i=o.get(s.track);i?i.push(s):o.set(s.track,[s])}for(let s of o.values()){let i=[],a=()=>{i.length>=2&&e.push(qn(i)),i=[]};for(let c of s){if(t.has(c)){a();continue}i.push(c)}a()}}return e}function ks(r){return Math.floor(r.numerator/r.denominator)}function Cs(r,t,e){let n=[],o=new Map,s=new Map,i=new M,a=new M;for(let h of r.columns)for(let u of h){let f=s.get(u.layoutLine);(f===void 0||u.t.compare(f)<0)&&s.set(u.layoutLine,u.t)}let c=h=>{let u=o.get(h);u&&(o.delete(h),u.nodes.length>=2&&n.push(qn(u.nodes)))},l=()=>{for(let h of[...o.keys()])c(h)};for(let h of r.columns){let u=h.find(f=>f.mergeKey===W);u&&(l(),i.copyFrom(u.t));for(let f of h){if(f.mergeKey===W)continue;let g=R(f)?t.get(f):void 0,d=g?.every(I=>I.nodes.length===1)??!1,y=g?.every(I=>I.owner.autoBeamEnabled)??!1;if(!(R(f)&&d&&y&&f.T.compare(1)<0&&!e.has(f))){(R(f)||!f.T.isZero())&&c(f.track);continue}let p=s.get(f.layoutLine)??f.t,m=i.compare(p)>=0?i:p,b=ks(a.copyFrom(f.t).sub(m)),w=o.get(f.track);if(!w){o.set(f.track,{nodes:[f],line:f.layoutLine,beat:b,endTime:f.t.clone().add(f.T)});continue}let N=f.t.equals(w.endTime);if(f.layoutLine!==w.line||b!==w.beat||!N){c(f.track),o.set(f.track,{nodes:[f],line:f.layoutLine,beat:b,endTime:f.t.clone().add(f.T)});continue}w.nodes.push(f),w.endTime.copyFrom(f.t).add(f.T)}}return l(),n}function Qn(r){let{scopes:t,nodeScopes:e}=Ls(r),n=jn(r.attachments);return[...Ns(t,n),...Cs(r,e,n)]}var Ce=class extends L{static loweringAugment=Qn;static loweringFinalize=Kn;static def={name:["beam"],description:"\u51CF\u65F6\u7EBF\u8FDE\u63A5",example:"@beam(label1, label2, ...): \u5C06\u591A\u4E2A\u5DF2\u6807\u8BB0\u97F3\u7B26\u6309\u987A\u5E8F\u8FDE\u63A5\u4E3A\u51CF\u65F6\u7EBF\u7EC4",allowExtraArgs:!0,extraArgType:"label",args:[]};endPoints=[];constructor(t,e,n,o=null){super(t,o);for(let[,i]of e){let a=i instanceof L?i:n.parseArgWithType(i.valueSpan,"label",t.start);a instanceof L&&this.endPoints.push(a)}let s=n.labelableNodes.length-1;for(;this.endPoints.length<2&&s>=0;){let i=n.labelableNodes[s--];!i||this.endPoints.includes(i)||this.endPoints.unshift(i)}if(this.endPoints.length<2)throw new S("E_NOT_ENOUGH_ARGS","@beam \u81F3\u5C11\u9700\u8981\u4E24\u4E2A\u7AEF\u70B9",t)}loweringEnter(t){let e=[];for(let n of this.endPoints){let o=t.getTemporalNodes(n).at(-1);for(;o?.foldedInto;)o=o.foldedInto;o&&e.push(o)}return e.length<2?(t.diagnostics.push(E.warning.UnresolvedEndpoint("beam",this.sourceSpan)),[]):(t.addAttachment(yt(e,!0,this.sourceSpan)),[])}},Xn=Ce;var Wt=1,vs=6,Ms=16,ve=32,Jn=1e-6,Is=.01;function Gt(r,t=Wt){let e=r.alpha_L??r.alpha_R??vs;r.alpha_L??=e,r.alpha_R??=e;let n=r.mu_L??r.mu_R??Ms;r.mu_L??=n,r.mu_R??=n,r.beta_L??=t/Math.max(r.alpha_L,Jn),r.beta_R??=t/Math.max(r.alpha_R,Jn)}function Vt(r,t,e,n=Wt){Gt(r,n);let o=Math.pow(Math.max(e.T.toNumber(),Is),.5);return{config:r,box:t,time:e,duration_L:o,duration_R:o,WL:t.anchor,WR:t.w-t.anchor,margin_L:o*r.alpha_L,margin_R:o*r.alpha_R}}function Rs(r,t=Wt){let e=new Map,n=0;for(let s of r)for(let i of s)e.has(i.time.track)||e.set(i.time.track,n++);let o=[];for(let s of r){if(s.length===0)continue;let i=Array(s.length);o.push(i);let a=0,c=0,l=n;for(let u of s){u.WL>a&&(a=u.WL),u.WR>c&&(c=u.WR);let f=e.get(u.time.track);if(i[f]){let g=i[f];u.time.T.compare(g.time.T)>0?(i[f]=u,i[l++]=g):i[l++]=u}else i[f]=u}let h=s[0].time.t;for(let u of e){let f=u[1];if(!i[f]){let g=Vt({anchor:0,alpha_L:a,alpha_R:c},{x:0,w:0,anchor:0},{t:h,T:new M(1),track:u[0]},t);g.fake=!0,i[f]=g}}}return{mat:o,rows:n}}function Os(r,t,e,n){let o=n-e-r.WR-t.WL,s=r.margin_R+t.margin_L;if(o>=s)return{force:0,stiffness:0};let i=r.config.beta_R/r.duration_R,a=t.config.beta_L/t.duration_L,c=i*a/(i+a),l,h;if(o<0){let u=r.config.mu_R*t.config.mu_L/(r.config.mu_R+t.config.mu_L);l=c*s-u*o,h=u}else{let u=s-o;l=c*u,h=c}return{force:l,stiffness:h}}function Ps(r,t,e=ve){let n=t-r.WL,o=r.margin_L;if(n>=o)return{force:0,stiffness:0};let s=r.config.beta_L/r.duration_L;if(n>=0)return{force:s*(o-n),stiffness:s};let i=r.config.mu_L*e;return{force:r.config.alpha_L*r.config.beta_L-i*n,stiffness:i}}function Ds(r,t,e,n=ve){let o=e-(t+r.WR),s=r.margin_R;if(o>=s)return{force:0,stiffness:0};let i=r.config.beta_R/r.duration_R;if(o>=0)return{force:i*(s-o),stiffness:i};let a=r.config.mu_R*n;return{force:r.config.alpha_R*r.config.beta_R-a*o,stiffness:a}}function Fs(r){return{damping:r.damping??.6,maxIter:r.maxIter??100,eps:r.eps??.01,crossPunish:r.crossPunish??ve,globalC:r.globalC??Wt}}function $s(r,t,e,n,o){let{damping:s,maxIter:i,eps:a,crossPunish:c}=o,l=r.length,h=new Float64Array(t);for(let T=0;T<l;T++){let v=0,A=r[T];for(let _=0;_<t;_++){let k=h[_]+A[_].WL+A[_].margin_L;k>v&&(v=k)}for(let _=0;_<t;_++)h[_]=v+A[_].WR+A[_].margin_R;e[T]=v}let u=h.reduce((T,v)=>Math.max(T,v),0);if(u<=n)return!0;u=n/u;for(let T=0;T<l;T++)e[T]*=u;let f=new Float64Array(l),g=new Float32Array(t*(l+1));function d(T){f.fill(0);for(let v=0;v<t;v++){let A=v*(l+1),_=r[0][v],k=Ps(_,T[0],c);f[0]+=k.force,g[A]=k.stiffness;for(let z=1;z<l;z++){let Z=r[z-1][v],B=r[z][v],dt=Os(Z,B,T[z-1],T[z]);f[z-1]-=dt.force,f[z]+=dt.force,g[A+z]=dt.stiffness}let P=r[l-1][v],K=Ds(P,T[l-1],n,c);f[l-1]-=K.force,g[A+l]=K.stiffness}return f}let y=new Float64Array(l);function x(T){y.fill(0);for(let A=0,_=0;A<t;A++,_+=l+1){y[0]+=g[_]*T[0];for(let k=1;k<l;k++){let P=g[_+k]*(T[k]-T[k-1]);y[k-1]-=P,y[k]+=P}y[l-1]+=g[_+l]*T[l-1]}let v=1e-4;for(let A=0;A<T.length;A++)y[A]+=v*T[A];return y}function p(T,v){let A=0;for(let _=0;_<T.length;_++)A+=T[_]*v[_];return A}let m=new Float64Array(l),b=new Float64Array(l),w=new Float64Array(l);function N(T,v=8){m.fill(0),b.set(T),w.set(b);let A=p(b,b);if(A<1e-12)return m;for(let _=0;_<v;_++){let k=x(w),P=p(w,k);if(Math.abs(P)<1e-12)break;let K=A/P;for(let B=0;B<l;B++)m[B]+=K*w[B],b[B]-=K*k[B];let z=p(b,b);if(Math.sqrt(z)<1e-6)break;let Z=z/A;for(let B=0;B<l;B++)w[B]=b[B]+Z*w[B];A=z}return m}let I=0,F=0;for(;I<i;I++){let T=d(e);F=0;for(let A=0;A<T.length;A++){let _=Math.abs(T[A]);_>F&&(F=_)}if(F<a)break;let v=N(T);for(let A=0;A<l;A++)e[A]+=s*v[A]}return!1}function bt(r,t,e,n,o,s,i=!1){if(e.length!==r.length||n.length!==Math.max(0,e.length-1))throw new Error("Horizontal region state does not match its columns");if(e.length===0||t===0)return;let a=n.some(g=>g!==0),c,l,h=r,u=e;if(a){c=new Uint32Array(e.length),l=new Float64Array(e.length),h=[];for(let g=0;g<e.length;){let d=g;for(;d<n.length&&n[d];)d++;let y=h.length;for(let x=g;x<=d;x++)c[x]=y,l[x]=e[x]-e[g];if(g===d)h.push(r[g]);else{let x=e[d]-e[g];h.push(Array.from({length:t},(p,m)=>{let b=r[g][m],w=r[d][m];return{config:{alpha_L:b.config.alpha_L,alpha_R:w.config.alpha_R,mu_L:b.config.mu_L,mu_R:w.config.mu_R,beta_L:b.config.beta_L,beta_R:w.config.beta_R},box:b.box,time:b.time,duration_L:b.duration_L,duration_R:w.duration_R,WL:b.WL,WR:x+w.WR,margin_L:b.margin_L,margin_R:w.margin_R,fake:b.fake&&w.fake}}))}g=d+1}u=new Float64Array(h.length)}let f=$s(h,t,u,o,s);if(n.fill(1),i&&f){let g=0,d=0;for(let p=0;p<t;p++)g=Math.max(g,h[0][p].WL),d=Math.max(d,h[h.length-1][p].WR);let y=g-u[0],x=o-d-u[u.length-1]-y;for(let p=0;p<u.length;p++)u[p]+=y+(x>0&&u.length>1?x*p/(u.length-1):0)}if(a)for(let g=0;g<e.length;g++)e[g]=u[c[g]]+l[g]}function Me(r,t,e={},n=[]){let o=Fs(e),{mat:s,rows:i}=Rs(r,o.globalC),a=new Float64Array(s.length),c=new Uint8Array(Math.max(0,s.length-1)),l=n.length>1?[...n].sort((h,u)=>h.end-h.start-(u.end-u.start)):n;for(let{start:h,end:u,hook:f}of l){if(h<0||u<h||u>=s.length)throw new Error("Horizontal layout registration references invalid columns");f({columns:s,rows:i,start:h,end:u,X:a,fixed:c,options:o})}bt(s,i,a,c,t,o);for(let h=0;h<s.length;h++)for(let u of s[h])u.box.x=a[h]-u.box.anchor;return s}var wt=class extends Error{line;requiredHeight;availableHeight;constructor(t,e,n){super(`Page cannot fit layout line ${t}: requires ${e}px, available ${n}px`),this.name="PageLayoutError",this.line=t,this.requiredHeight=e,this.availableHeight=n}},U={width:794,height:1/0,marginTop:45,marginBottom:48,marginLeft:40,marginRight:40,lineGap:22};function Ct(r={}){let t=r.height??U.height,e={width:r.width??U.width,height:t<=0?1/0:t,marginTop:Math.max(0,r.marginTop??U.marginTop),marginBottom:Math.max(0,r.marginBottom??U.marginBottom),marginLeft:Math.max(0,r.marginLeft??U.marginLeft),marginRight:Math.max(0,r.marginRight??U.marginRight),lineGap:Math.max(0,r.lineGap??U.lineGap)};if(!Number.isFinite(e.width)||e.width<=0)throw new Error(`Page width must be a positive finite number, got ${e.width}`);if(e.height!==1/0&&(!Number.isFinite(e.height)||e.height<=0))throw new Error(`Page height must be positive or Infinity, got ${e.height}`);if([e.marginTop,e.marginBottom,e.marginLeft,e.marginRight,e.lineGap].some(i=>!Number.isFinite(i)||i<0))throw new Error("Page margins and line gap must be finite non-negative numbers");let o=e.width-e.marginLeft-e.marginRight;if(o<=0)throw new Error(`Page horizontal margins leave no content width: ${o}px`);let s=e.height-e.marginTop-e.marginBottom;if(Number.isFinite(e.height)&&s<=0)throw new Error(`Page vertical margins leave no content height: ${s}px`);return e}function Ie(r,t){let e=t.height-t.marginTop-t.marginBottom,n=[],o=new Array(r.length).fill(0),s=0,i=0,a=0,c=0,l=(h,u)=>{let f=h-i,g=u&&f>1?(e-c)/(f-1):t.lineGap,d=s+t.marginTop;for(let x=i;x<h;x++)o[x]=d,d+=r[x]+(x+1<h?g:0);let y=Number.isFinite(t.height)?t.height:d-s+t.marginBottom;n.push({bounds:{x:0,y:s,w:t.width,h:y},lineStart:i,lineEnd:h}),s+=y,i=h,a=0,c=0};for(let h=0;h<r.length;h++){let u=r[h];if(Number.isFinite(t.height)&&u>e+1e-6)throw new wt(h,u,e);Number.isFinite(t.height)&&h>i&&a+t.lineGap+u>e+1e-6&&l(h,!0),a+=(h>i?t.lineGap:0)+u,c+=u}return r.length>i&&l(r.length,!1),{pages:n,lineTops:o}}function vt(r,t){let e=1/0,n=1/0,o=-1/0,s=-1/0;for(let i of t)e=Math.min(e,i.x),n=Math.min(n,i.y),o=Math.max(o,i.x+i.w),s=Math.max(s,i.y+i.h);return Number.isFinite(e)?(r.x=e,r.y=n,r.w=o-e,r.h=s-n,!0):(r.x=r.y=r.w=r.h=0,!1)}function at(r,t){r.springConfig??={},r.decorations=[],r.ports={},r.box.x=r.box.y=0,r.prepareLayout(t);for(let[e,n]of Object.entries(r.addon??{})){let o=t.decorationHandlers.get(e);if(!o)continue;let s=o(r,n,t);s&&r.decorations.push(s)}Bs(r),r.finalizeLayout?.(t)}function Re(r,t,e={}){let n=r.attachments.filter(it),o=Ct(r.page),s=o.width-o.marginLeft-o.marginRight,i=o.marginLeft,a=zs(r),c=[];for(let m of a)for(let b of m.columns)for(let w of b)c.push(w),at(w,t);let l=Hs(a,e.globalC);for(let m of c)m.prepareHorizontal?.(l[m.layoutLine]);for(let m of n)m.prepareHorizontal?.(l,t);for(let m of a){let b=m.columns.map(w=>w.map(N=>Vt(N.springConfig,N.box,N,e.globalC)));Me(b,s,e,m.horizontalLayoutHooks);for(let w of m.columns)for(let N of w)N.box.x+=i}for(let m of c){let b=a[m.layoutLine],w=-m.box.visualAxis;eo(b.hostExtents,m.track,w,w+m.box.h)}let h=Ws(a.length,c,e.rowGap),u=()=>{let m=[],b=a.map((T,v)=>{let A=Vs(T,r.rootTrack,h[v]);return m.push(A.height),A.axes}),w,N;try{({pages:w,lineTops:N}=Ie(m,o))}catch(T){if(!(T instanceof wt))throw T;let v=a[T.line],A=1/0,_=-1/0;for(let k of v?.columns??[])for(let P of k)A=Math.min(A,P.ast.sourceSpan.start),_=Math.max(_,P.ast.sourceSpan.end);throw Number.isFinite(A)?E.error.PageOverflow(T.requiredHeight,T.availableHeight,{start:A,end:_}):T}let I=(T,v)=>(N[T]??0)+(b[T]?.get(v)??0);for(let T of c)T.box.y=I(T.layoutLine,T.track)-T.box.visualAxis,T.onPlaced?.();let F={...t,width:s,originX:i,pages:w.map(T=>T.bounds),getVisualAxis:I,getHostExtent:(T,v)=>a[T]?.hostExtents.get(v)};return{pages:w,attachmentContext:F}},f=u(),g=to(n,f.attachmentContext);Gs(g,a,f.attachmentContext.getVisualAxis)&&(f=u(),g=to(n,f.attachmentContext));let d=f.pages,y=n.map((m,b)=>{let{geometry:w,box:N}=g[b];return{box:N,regions:w.regions,layer:m.layer,sourceSpan:m.sourceSpan,paint(I){w.paint(I)}}}),x={x:0,y:0,w:0,h:0};function*p(){for(let m of d)yield m.bounds;for(let m of c)yield m.box;for(let m of y)yield m.box}return vt(x,p()),{diagnostics:r.diagnostics,objects:c,attachments:y,bounds:x,lineCount:a.length,pages:d}}function Bs(r){let t=r.decorations.map(n=>n.below).filter(n=>n!==void 0).sort((n,o)=>n.order-o.order);if(t.length===0)return;let e=r.box.h;for(let n of t)e+=n.gap??0,n.place?.(e),e+=Math.max(0,n.height??0);r.box.h=e}function zs(r){let t=()=>({columns:[],horizontalLayoutHooks:[],hostExtents:new Map,attachmentExtents:new Map}),e=[],n=t();for(let o of r.columns){let s=[];for(;e.length<o[0].layoutLine;)e.push(n),n=t();for(let i of o)R(i)&&s.push(i);s.length&&n.columns.push(s)}return(n.columns.length>0||e.length===0)&&e.push(n),e}function Yt(r,t,e){r.top=Math.min(r.top,t),r.bottom=Math.max(r.bottom,e)}function eo(r,t,e,n){let o=r.get(t);o?Yt(o,e,n):r.set(t,{top:e,bottom:n})}function Hs(r,t){return r.map((e,n)=>{let o=new Map,s=new Map;for(let i=0;i<e.columns.length;i++)for(let a of e.columns[i]){o.set(a,i),Gt(a.springConfig,t);let c=s.get(a.track);c?c.push(a):s.set(a.track,[a])}return{index:n,columns:e.columns,trackRuns:s,columnOf:i=>o.get(i)??-1,registerHorizontalLayoutHook(i,a,c){let l=o.get(i),h=o.get(a);l===void 0||h===void 0||e.horizontalLayoutHooks.push({start:Math.min(l,h),end:Math.max(l,h),hook:c})}}})}function Ws(r,t,e){if(e!==void 0)return new Array(r).fill(e);let n=new Array(r).fill(0),o=0;for(let s of t){let i=s.ast.size*.75;i>n[s.layoutLine]&&(n[s.layoutLine]=i),i>o&&(o=i)}for(let s=0;s<r;s++)n[s]||=o;return n}function to(r,t){let e=new Map,n={...t,getAttachmentBox(o){let s=e.get(o);if(!s)throw new Error("Layout attachment dependency has not been measured");return s.box}};return r.map(o=>{let s=o.createGeometry(n),i={x:0,y:0,w:0,h:0};vt(i,s.regions);let a={geometry:s,box:i};return e.set(o,a),a})}function Gs(r,t,e){let n=!1;for(let{geometry:o}of r)for(let s of o.occupancy??o.regions){if(s.line===void 0)continue;let i=t[s.line],a=e(s.line,s.track),c=s.y-a,l=s.y+s.h-a,h=i.hostExtents.get(s.track),u=i.attachmentExtents.get(s.track),f=Math.min(h?.top??1/0,u?.top??1/0),g=Math.max(h?.bottom??-1/0,u?.bottom??-1/0);(c<f||l>g)&&(n=!0),eo(i.attachmentExtents,s.track,c,l)}return n}function Vs(r,t,e){let n=new Map,o=c=>{let l=r.hostExtents.get(c),h=r.attachmentExtents.get(c),u=l?{top:l.top,bottom:l.bottom}:null;h&&(u?Yt(u,h.top,h.bottom):u={top:h.top,bottom:h.bottom});let f=[];for(let d of c.groups){let y=d.members.map(o);if(y.every(m=>m===null))continue;let x=d.measure(y,e),p=null;for(let m of x){if(!m)continue;let b=m.offset+m.extent.top,w=m.offset+m.extent.bottom;p?Yt(p,b,w):p={top:b,bottom:w}}p&&f.push({group:d,placements:x,extent:p})}let g=(d,y)=>{u??={top:0,bottom:0};for(let x=0;x<d.group.members.length;x++){let p=d.placements[x];p&&n.set(d.group.members[x],y+p.offset)}Yt(u,y+d.extent.top,y+d.extent.bottom)};for(let d of f)d.group.place||g(d,0);for(let d of f){let y=d.group.place;if(!y)continue;g(d,y(u??{top:0,bottom:0},d.extent,e))}return u},s=o(t),i=new Map;if(!s)return{axes:i,height:0};let a=(c,l)=>{i.set(c,l);for(let h of c.groups)for(let u of h.members){let f=n.get(u);f!==void 0&&a(u,l+f)}};return a(t,-s.top),{axes:i,height:s.bottom-s.top}}var Oe=class extends L{static def={name:["box"],description:"\u7ED9\u76EE\u6807\u7ED3\u6784\u6216\u5BF9\u8C61\u52A0\u5916\u6846",example:"@box(content, padding=0.2em, stroke=0.08em, width=-1px)",allowExtraArgs:!1,args:[{type:"content",default:null},{name:"padding",type:"length",default:{value:0,unit:"em"}},{name:"stroke",type:"length",default:{value:1,unit:"px"}},{name:"width",type:"length",default:{value:-1,unit:"px"}}]};target;padding;stroke;width;get children(){return[this.target]}timeFlowModel(){return{children:[this.target],mode:"sequence"}}loweringEnter(t){let e=[],n=[];return t.beginLoweringGroup(this,{attachment:new Pe(e,n,this),onTemporal(o){R(o)&&e.push(o)},onAttachment(o){it(o)&&n.push(o)}}),[]}loweringExit(t){return t.endLoweringGroup(this),[]}constructor(t,e,n,o=null){super(t,o);let[s,i,a,c]=this.getArgValue(e,n);s.parent=this,this.target=s,this.padding=Math.max(0,n.length2px(i)),this.stroke=Math.max(0,n.length2px(a)),this.width=n.length2px(c)}},no=Oe,Pe=class{layer="background";temporalMembers;childAttachments;owner;fixedStart=null;wallOffset=0;get sourceSpan(){return this.owner.sourceSpan}constructor(t,e,n){this.temporalMembers=t,this.childAttachments=e,this.owner=n}prepareHorizontal(t){let e=this.temporalMembers[0]?.layoutLine;if(e===void 0)return;if(this.temporalMembers.some(h=>h.layoutLine!==e))throw new S("E_BOX_CROSS_LINE","@box \u7684\u5185\u5BB9\u4E0D\u80FD\u8DE8\u8D8A\u8C31\u9762\u884C",this.owner.sourceSpan);if(this.owner.width<=0)return;let n=t[e];if(!n)return;let o=null,s=null,i=1/0,a=-1/0,c=0,l=0;for(let h of this.temporalMembers){let u=n.columnOf(h);if(u<0)continue;let f=h.box.anchor,g=h.box.w-f;u<i?(i=u,o=h,c=f):u===i&&(c=Math.max(c,f)),u>a?(a=u,s=h,l=g):u===a&&(l=Math.max(l,g))}if(!(!o||!s)){if(this.owner.width<c+l-1e-6)throw new S("E_BOX_WIDTH_TOO_SMALL","@box \u7684\u5BBD\u5EA6\u5C0F\u4E8E\u9996\u672B\u5143\u7D20\u7684\u56FA\u6709\u5BBD\u5EA6",this.owner.sourceSpan);n.registerHorizontalLayoutHook(o,s,({columns:h,rows:u,start:f,end:g,X:d,fixed:y,options:x})=>{if(y[f-1]||y[g])throw new S("E_BOX_CONSTRAINT_CROSSING","\u5B9A\u5BBD @box \u53EF\u4EE5\u5D4C\u5957\uFF0C\u4F46\u4E0D\u80FD\u90E8\u5206\u4EA4\u53C9",this.owner.sourceSpan);let p=d.subarray(f,g+1);bt(h.slice(f,g+1),u,p,y.subarray(f,g),this.owner.width,x,!0);let m=p[p.length-1]-p[0]+c+l;if(Math.abs(m-this.owner.width)>1e-6)throw new S("E_BOX_CONSTRAINT_CONFLICT","\u591A\u4E2A @box \u4E3A\u76F8\u540C\u5185\u5BB9\u6307\u5B9A\u4E86\u4E0D\u540C\u5BBD\u5EA6",this.owner.sourceSpan);this.fixedStart=o,this.wallOffset=-p[0]})}}createGeometry(t){let{padding:e,stroke:n}=this.owner,o={x:0,y:0,w:0,h:0},s=[...this.temporalMembers.map(l=>l.box),...this.childAttachments.map(l=>t.getAttachmentBox(l))];if(!vt(o,s.filter(l=>l.w>0||l.h>0)))return{regions:[],paint(){}};let i=e+n/2,c={x:(this.fixedStart?this.fixedStart.box.x+this.fixedStart.box.anchor+this.wallOffset:o.x)-i,y:o.y-i,w:(this.fixedStart?this.owner.width:o.w)+i*2,h:o.h+i*2};return{regions:[c],paint(l){let h=n/2;l.drawRect(c.x+h,c.y+h,Math.max(0,c.w-n),Math.max(0,c.h-n),{stroke:"#000",strokeWidth:n})}}}};var De=class extends L{static def={name:["dash","-"],description:"\u589E\u65F6\u7EBF",example:`@dash() \u521B\u5EFA\u4E00\u6839\u589E\u65F6\u7EBF
|
|
19
|
+
\u8BED\u6CD5\u7CD6: \u4E00\u4E2A '-' \u4EE3\u8868\u4E00\u4E2A @dash()
|
|
20
|
+
`,allowExtraArgs:!1,args:[]};static deSugarAtom(t,e,n){if(t[e]!=="-")return null;let o={kind:"call",typed:!0,name:"-",args:new Map,span:{start:e,end:e+1},syntaxKind:"atom"};return{next:e+1,node:o}}size;constructor(t,e,n,o=null){super(t,o),this.size=n.fontSize}loweringEnter(){return[new Fe(this)]}toString(){return"-"}},oo=De,Fe=class extends D{lineY=0;constructor(t){super(),this.ast=t,this.T.set(1),this.mergeKey=Q,this.initLayoutBox()}onTimeState(t){this.playbackState={bpm:t.bpm}}prepareLayout(){let t=this.ast.size,e=t*.5;this.box.w=e,this.box.h=t,this.box.anchor=e/2,this.lineY=t*.5,this.box.visualAxis=this.lineY}emitPlayback(t){let e=t.start.clone(),n=t.end.clone(),o=t.track,s=this.ast.sourceSpan;t.defer(i=>{let a;for(let c=i.events.length-1;c>=0;c--){let l=i.events[c];if(!(l.kind!=="note-off"||l.origins.at(-1).node.track!==o)){if(a===void 0){if(!l.at.equals(e))continue;a=l.origins[0]}else if(l.origins[0]!==a)break;l.at.equals(e)&&l.at.copyFrom(n)}}a===void 0&&i.diagnostics.push(new C("W_PLAYBACK_SUSTAIN_WITHOUT_TARGET","\u589E\u65F6\u7EBF\u524D\u6CA1\u6709\u53EF\u5EF6\u7EED\u7684\u53D1\u58F0\u97F3\u7B26",s))})}paint(t){t.drawLine(this.box.x,this.box.y+this.lineY,this.box.x+this.box.w,this.box.y+this.lineY,{stroke:"#000",strokeWidth:Math.max(1,this.ast.size*.1)})}};var ro="dot",so=st(ro);function io(r){let t=2**r;return[2*t-1,t]}var $e=class r extends L{static def={name:[ro,"."],description:"\u9644\u70B9",example:`@dot(C1, 2): C1\u53F3\u4FA7\u521B\u5EFA2\u4E2A\u70B9 \u4EC5\u63A5\u6536\u4E00\u4E2A\u53EF\u63A5\u6536\u5143\u7D20
|
|
21
|
+
\u8BED\u6CD5\u7CD6\uFF1A\u5728\u97F3\u7B26\u540E\u52A0\u659C\u6760'.'\uFF0C\u53EF\u4EE5\u591A\u4E2A
|
|
22
|
+
@dot(C1, 2) === C1..
|
|
23
|
+
@dot(C1 C2/ @dash(), 2) \u62A5\u9519 \u56E0\u4E3A\u70B9\u53EA\u80FD\u63A5\u6536\u4E00\u4E2A\u5143\u7D20
|
|
24
|
+
\u8BBE\u7F6E\u547D\u540D\u53C2\u6570\u524D\u7F00: dot
|
|
25
|
+
`,allowExtraArgs:!1,args:[{type:"content",default:null},{name:"n",type:"number",default:1}]};static deSugarAtom(t,e,n){let o=0,s=e;for(;s<n&&t[s]===".";)o++,s++;return o===0?null:{next:s,node:{kind:"sugar",data:{class:r,n:o},span:{start:e,end:s}}}}static deSugarRelation(t,e,n){let o=e[n++];if(o.data?.class!==r)return null;let s=L.findLastFuncContentNode(t.nodes,t.nodes.length-1);if(!s)return n;if(s instanceof r)return s.n+=o.data.n,n;let i=new Map;i.set(0,s),i.set("n",o.data.n);let a=s.sourceSpan,c=new r({start:Math.min(a.start,o.span.start),end:Math.max(a.end,o.span.end)},i,t,null);return t.nodes.pop(),t.pushNode(c),n}static layoutDecorationHandler=(t,e)=>{let n=Math.max(0,Math.floor(Number(e)||0));if(n===0)return null;let o=t.ast.size*.075,s=t.ast.size*.12,i=t.ports.dot??{x:t.box.w,y:t.box.visualAxis},a=i.x+s+o,c=o*2+s,l=a+(n-1)*c+o;return t.box.w=Math.max(t.box.w,l),{paint(h){let u=t.box.y+i.y;for(let f=0;f<n;f++)h.drawCircle(t.box.x+a+f*c,u,o,{fill:"#000"})}}};loweringEnter(t){let e=this.n;return t.beginLoweringGroup(this,{onTemporal(n){if(e===0)return;let o=n.addon??={},s=Number(o[so])||0,i=s+e,[a,c]=io(i),[l,h]=io(s);n.T.mul(a*h,c*l),o[so]=i}}),[]}loweringExit(t){return t.endLoweringGroup(this),[]}timeFlowModel(){return{children:[this.content],mode:"sequence"}}content;n;get children(){return[this.content]}constructor(t,e,n,o=null){super(t,o),[this.content,this.n]=this.getArgValue(e,n);let s=r.leafNum(this.content);if(s!==1)throw new S("E_DOT_INVALID_CONTENT",`\u51FD\u6570 @dot \u53EA\u80FD\u63A5\u6536 1\u4E2A\u5143\u7D20\uFF0C\u4F46\u627E\u5230\u4E86 ${s} \u4E2A`,t);this.content.parent=this;let i=Math.max(0,Math.trunc(this.n));i!==this.n&&(n.diagnostics.push(new C("W_DOT_INVALID_N",`@dot \u7684\u6570\u91CF\u53C2\u6570 n \u5FC5\u987B\u4E3A\u975E\u8D1F\u6574\u6570\uFF0C\u5DF2\u88AB\u4FEE\u6B63\u4E3A ${i}`,this.sourceSpan)),this.n=i)}toString(t){return`@dot(${this.content.toString(t)}, ${this.n})`}static leafNum(t){let e=0,n=t.children;if(n)for(let o of n)e+=r.leafNum(o);else e++;return e}},ao=$e;var St=.7,co="shoulder";function ho(r,t){let e=r;typeof e.size=="number"&&(e.size*=t);for(let n of r.children??[])ho(n,t)}var Be=class r extends L{static def={name:["grace"],description:"\u501A\u97F3",example:`\u524D\u501A\u97F3: @grace(\u5BBF\u4E3B, \u501A\u97F3, side=pre) \u540E\u501A\u97F3: @grace(\u5BBF\u4E3B, \u501A\u97F3, side=post)
|
|
26
|
+
\u8BED\u6CD5\u7CD6\uFF1A'>' \u4E0E '<'\uFF0C\u7BAD\u5934\u6C38\u8FDC\u6307\u5411\u5BBF\u4E3B
|
|
27
|
+
2>1 \u524D\u501A\u97F3\uFF1A2 \u662F 1 \u7684\u501A\u97F3\uFF0C\u753B\u5728 1 \u7684\u5DE6\u4E0A\u89D2
|
|
28
|
+
1<2 \u540E\u501A\u97F3\uFF1A2 \u662F 1 \u7684\u501A\u97F3\uFF0C\u753B\u5728 1 \u7684\u53F3\u4E0A\u89D2
|
|
29
|
+
{3 2}>1 \u591A\u4E2A\u501A\u97F3\u7528\u5927\u62EC\u53F7\u62EC\u8D77\u6765
|
|
30
|
+
1>2>3 \u5141\u8BB8\u5D4C\u5957\uFF1A1 \u662F 2 \u7684\u501A\u97F3\uFF0C2 \u662F 3 \u7684\u501A\u97F3
|
|
31
|
+
\u501A\u97F3\u9ED8\u8BA4\u5C31\u662F\u516B\u5206\u97F3\u7B26\uFF08\u81EA\u5E26\u4E00\u6761\u51CF\u65F6\u7EBF\uFF09\uFF0C\u518D\u5199 '/' \u53D8\u6210\u5341\u516D\u5206\u97F3\u7B26`,allowExtraArgs:!0,args:[{name:"host",type:"content",default:null},{name:"grace",type:"content",default:null},{name:"side",type:"string",default:"pre"}]};labelable(){return L.findLabelable(this.host)}static deSugarAtom(t,e,n){let o=t[e];switch(o){case">":o="pre";break;case"<":o="post";break;default:return null}return{next:e+1,node:{kind:"sugar",data:{class:r,side:o},span:{start:e,end:e+1}}}}static deSugarRelation(t,e,n){let o=e[n++];if(o.kind!=="sugar"||o.data?.class!==r)return null;let s=o.data.side,i=t.nodes.length-1;for(;i>=0&&t.nodes[i]instanceof H;)i--;if(i<0)throw new S("E_GRACE_NO_TARGET","@grace\u8BED\u6CD5\u7CD6\u9519\u8BEF: \u5DE6\u8FB9\u6CA1\u6709\u627E\u5230\u76EE\u6807",o.span);let a=t.nodes[i],c=i;if(a instanceof q){let h=a.target;for(;h&&!t.nodes.includes(h);)h=h.parent;for(let u=i-1;u>=0;u--)if(t.nodes[u]===h){a=new $({start:h.sourceSpan.start,end:a.sourceSpan.end},t.nodes.slice(u,i+1),null),c=u;break}}let l=t.nodes;t.nodes=[],t.makeNodes(e,n);for(let h=0;h<t.nodes.length;h++){let u=t.nodes[h];if(u instanceof H)continue;let f=s==="pre"?r.attachPre(a,u,o.span,t):r.create(t,o.span,"post",a,u);for(l.length=c,l.push(f);++h<t.nodes.length;)l.push(t.nodes[h]);return t.nodes=l,e.length}throw new S("E_GRACE_NO_TARGET","@grace\u8BED\u6CD5\u7CD6\u9519\u8BEF: \u53F3\u8FB9\u6CA1\u6709\u627E\u5230\u76EE\u6807",o.span)}host;grace;side="pre";size;static attachPre(t,e,n,o){if(e instanceof r&&e.side==="pre"){let s=e,i=1;for(;s.grace instanceof r&&s.grace.side==="pre";)s=s.grace,i++;let a=new Map;a.set(0,s.grace),a.set(1,t);let c=St**i,l=new r(n,a,o,null,St*c);return l.size*=c,s.setGrace(l,1),e}return r.create(o,n,"pre",e,t)}static create(t,e,n,o,s){let i=new Map;return i.set(0,o),i.set(1,s),i.set("side",n),new r(e,i,t)}get children(){let t=[];return this.host&&t.push(this.host),this.grace&&t.push(this.grace),t}constructor(t,e,n,o=null,s=St){if(super(t,o),this.size=n.fontSize,[this.host,this.grace,this.side]=this.getArgValue(e,n),this.side!=="pre"&&this.side!=="post")throw new S("E_GRACE_INVALID_SIDE","@grace \u7684 side \u53C2\u6570\u5FC5\u987B\u662F 'pre' \u6216 'post'",t);this.adopt(this.host),this.setGrace(this.grace,s),this.size=n.fontSize}setGrace(t,e=St){ho(t,e),this.grace=t,this.adopt(t)}adopt(t){t.parent=this,this.sourceSpan.start=Math.min(this.sourceSpan.start,t.sourceSpan.start),this.sourceSpan.end=Math.max(this.sourceSpan.end,t.sourceSpan.end)}loweringEnter(t,e){if(!this.host||!this.grace)throw new S("E_GRACE_MISSING_ARGS","@grace \u9700\u8981\u540C\u65F6\u7ED9\u51FA\u5BBF\u4E3B\u548C\u501A\u97F3",this.sourceSpan);let n=[],o=null;t.isolateFromLoweringGroups(()=>{let i=this.side==="pre"?[this.grace,this.host]:[this.host,this.grace];for(let a of i){let c=t.trackedEvents(a,new M,e).flat(),l=c.filter(R);if(c.some(h=>h.track!==e))throw new S("E_GRACE_PARALLEL_CONTENT","@grace \u7684\u5185\u5BB9\u4E0D\u80FD\u5305\u542B\u591A\u58F0\u90E8\u7ED3\u6784\uFF08& / @voices\uFF09\uFF1B\u8981\u5728\u501A\u97F3\u91CC\u53E0\u97F3\u8BF7\u7528 ^",a.sourceSpan);if(a===this.host){if(l.length!==1||l.length!==c.length)throw new S("E_GRACE_INVALID_HOST","@grace \u7684\u5BBF\u4E3B\u5FC5\u987B\u6070\u597D\u4EA7\u751F\u4E00\u4E2A\u53EF\u89C1 Temporal",a.sourceSpan);o=l[0]}else{if(l.length===0||l.length!==c.length)throw new S("E_GRACE_INVALID_CONTENT","@grace \u7684\u501A\u97F3\u5FC5\u987B\u53EA\u4EA7\u751F\u53EF\u89C1 Temporal\uFF0C\u4E14\u81F3\u5C11\u4E00\u4E2A",a.sourceSpan);n=l}}});let s=new ze(this,o,n,this.side);for(let i of s.graceRuns)i.length<2||t.addAttachment(yt([...i],!1,this.grace.sourceSpan));return[s]}toString(t){let e=this.host?.toString(t)??"",n=this.grace?.toString(t)??"";return`@grace(${e}, ${n}, side=${this.side})`}},uo=Be,Ys=[{op:"M",x:0,y:0},{op:"C",cx1:-.01,cy1:.26,cx2:.14,cy2:.42,x:.29,y:.36}],Us=.07,Ks=.18,lo=new M(3,4),ze=class extends D{host;graces;graceRuns;side;hostOffset={x:0,y:0};graceOffsets=[];hookOrigin=null;constructor(t,e,n,o){super(),this.ast=t,this.host=e,this.graces=n,this.side=o,this.T.copyFrom(e.T),this.mergeKey=e.mergeKey,this.initLayoutBox(),e.addon&&(this.addon={...e.addon}),e.addon=void 0,e.foldedInto=this;let s=[],i=[];for(let a of n){if(a.foldedInto=this,a.T.isZero()){i.length>0&&s.push(i),i=[];continue}i.push(a);let c=a.addon={...a.addon};c[rt]=(Number(c[rt])||0)+1,a.T.divPow2()}i.length>0&&s.push(i),this.graceRuns=s}onTimeState(t){this.host.T.copyFrom(this.T);let e=this.side==="pre"?[...this.graces,this.host]:[this.host,...this.graces];for(let n of e)n.t.copyFrom(this.t),n.track=this.track,n.layoutLine=this.layoutLine,n.onTimeState?.(t)}emitPlayback(t){let e=new M;for(let l of this.graces)e.add(l.T);let n=e.compare(lo)>0?lo:e,o=t.end.clone().sub(t.start),s=o.clone().mul(n),i=o.sub(s),a=t.start.clone(),c=l=>{for(let h of this.graces){if(h.T.isZero()||e.isZero()){t.play(h,l,new M);continue}let u=s.clone().mul(h.T).div(e);t.play(h,l,u),l.add(u)}};if(this.side==="pre"){let l=a.clone();c(l),t.play(this.host,l,i)}else t.play(this.host,a,i),c(a.clone().add(i))}prepareLayout(t){this.addon&&(this.host.addon=this.addon,this.addon=void 0);for(let y of this.graces)at(y,t);at(this.host,t);let n=this.ast.size*St,o=n*.16,s=n*.2,i=n*Ks,a=0,c=0,l=0;for(let y of this.graces)c=Math.max(c,y.box.visualAxis);this.graceOffsets=this.graces.map(y=>{let x=a;a+=y.box.w+o;let p=c-y.box.visualAxis;return l=Math.max(l,p+y.box.h),{x,y:p}}),this.graces.length>0&&(a-=o);let u=(this.host.ports[co]?.y??0)-i-l,f=Math.max(0,-u),g=this.side==="pre"?0:this.host.box.w+s;this.hostOffset={x:this.side==="pre"?a+s:0,y:f};for(let y of this.graceOffsets)y.x+=g,y.y+=u+f;this.box.w=this.host.box.w+s+a,this.box.h=f+this.host.box.h,this.box.anchor=this.hostOffset.x+this.host.box.anchor,this.box.visualAxis=f+this.host.box.visualAxis;for(let y in this.host.ports){let x=this.host.ports[y];this.ports[y]={x:this.hostOffset.x+x.x,y:this.hostOffset.y+x.y}}this.ports[co]??={x:this.box.anchor,y:this.hostOffset.y};let d=this.side==="pre"?this.graceRuns.at(-1)?.at(-1):this.graceRuns[0]?.[0];this.hookOrigin=d?{x:this.graceOffsets[this.graces.indexOf(d)].x+d.box.anchor,y:u+f+l}:null}onPlaced(){this.host.box.x=this.box.x+this.hostOffset.x,this.host.box.y=this.box.y+this.hostOffset.y,this.host.onPlaced?.(),this.graces.forEach((t,e)=>{t.box.x=this.box.x+this.graceOffsets[e].x,t.box.y=this.box.y+this.graceOffsets[e].y,t.onPlaced?.()})}paint(t){for(let s of[this.host,...this.graces]){s.paint(t);for(let i of s.decorations)i.paint(t)}if(!this.hookOrigin)return;let e=this.ast.size*St,n=this.hookOrigin,o=this.side==="pre"?1:-1;t.drawPath(Ys,{stroke:"#000",strokeWidth:Math.max(.8,e*Us)},{x:this.box.x+n.x,y:this.box.y+n.y,scaleX:e*o,scaleY:e})}};var js=/[A-Za-z0-9_./-]/;function po(r,t,e){let n=t+1;for(;n<e&&js.test(r[n]);)n++;let o=r.slice(t+1,n);if(!o||n>=e||r[n]!=="(")return null;let s=n,i=1,a=0,c=null,l=!1,h=[],u=s+1,f=(d,y,x=!1)=>{let p=Mt(r,u,d);if(!x&&p.start>=p.end)return;let m=Zs(r,p.start,p.end),b=m>p.start?Mt(r,p.start,m):void 0,w=m>p.start?Mt(r,m+1,p.end):p;h.push({span:p,valueSpan:w,nameSpan:b,equalsSpan:m>p.start?{start:m,end:m+1}:void 0,commaSpan:y===void 0?void 0:{start:y,end:y+1}})},g=(d,y)=>({name:o,span:{start:t,end:d},nameSpan:{start:t,end:s},openParenSpan:{start:s,end:s+1},closeParenSpan:y,args:h});for(n++;n<e;n++){let d=r[n];if(c){l?l=!1:d==="\\"?l=!0:d===c&&(c=null);continue}if(d==='"'){c=d;continue}if(d==="{")a++;else if(d==="}")a=Math.max(0,a-1);else if(d==="("&&a===0)i++;else if(d===")"&&a===0){if(--i)continue;return f(n),g(n+1,{start:n,end:n+1})}else d===","&&i===1&&a===0&&(f(n,n,!0),u=n+1)}return f(e),g(e)}var fo=/\s/;function Mt(r,t,e){let n=t,o=e;for(;n<o&&fo.test(r[n]);)n+=1;for(;o>n&&fo.test(r[o-1]);)o-=1;return{start:n,end:o}}function Zs(r,t=0,e=r.length){let n=0,o=0,s=null,i=!1;for(let a=t;a<e;a++){let c=r[a];if(s){i?i=!1:c==="\\"?i=!0:c===s&&(s=null);continue}if(c==='"')s=c;else if(c==="("&&o===0)n++;else if(c===")"&&o===0)n=Math.max(0,n-1);else if(c==="{")o++;else if(c==="}")o=Math.max(0,o-1);else if(c==="="&&n===0&&o===0)return a}return-1}function mo(r,t,e){let n=1,o=null,s=!1;for(let i=t;i<e;i++){let a=r[i];if(o){s?s=!1:a==="\\"?s=!0:a===o&&(o=null);continue}if(a==='"')o=a;else if(a==="(")n++;else if(a===")"&&--n===0)return i}return-1}function At(r,t,e){for(let n=t+1;n<e;n++)if(r[n]==="\\")n++;else if(r[n]==='"')return n;return-1}function ct(r){return r.length<2||!r.startsWith('"')||!r.endsWith('"')?r:r.slice(1,-1).replace(/\\(.)/gs,"$1")}function go(r,t,e){let n=1,o=null,s=!1;for(let i=t+1;i<e;i++){let a=r[i];if(o){s?s=!1:a==="\\"?s=!0:a===o&&(o=null);continue}if(a==='"')o=a;else if(a==="{")n++;else if(a==="}"&&(n--,n===0))return i}return-1}var qs=/\s|\(|\)|\{|\}|,/;function xo(r,t,e){let n=t+1;for(;n<e&&!qs.test(r[n]);)n++;return n<=t+1?null:{label:r.slice(t+1,n),next:n}}var Qs=/^(-?(?:\d+(?:\.\d*)?|\.\d+))([a-z%]+)?$/i,Xs=["em","px"];function He(r){let t=r.match(Qs);if(!t)return E.warning.InvalidLength(r,{start:0,end:r.length});let e=parseFloat(t[1]);if(t[2]){let n=t[2].toLowerCase();return Xs.includes(n)?{value:e,unit:n}:E.warning.InvalidLengthUnit(n,{start:t[1].length,end:r.length})}else return{value:e,unit:"px"}}var yo=/^(true|false)$/;function Js(r,t){if(r)return r==="content"?void 0:r;if(yo.test(t))return"boolean";if(t.startsWith('"'))return"string";if(!isNaN(Number(t)))return"number";if(!(He(t)instanceof E))return"length"}var bo=22,ti=!1,ei=4,We={fontsize:"length",strict:"boolean"},X=class r{scopeDepth;source;syntax;diagnostics;variables;documentDeclarations;functions;deSugarAtomFns;deSugarRelationFns;labelableNodes;nodes;constructor(t){t instanceof r?(this.scopeDepth=t.scopeDepth+1,this.documentDeclarations=t.documentDeclarations,this.source=t.source,this.diagnostics=t.diagnostics,this.syntax=t.syntax,this.variables={...t.variables},this.functions=t.functions,this.deSugarAtomFns=t.deSugarAtomFns,this.deSugarRelationFns=t.deSugarRelationFns,this.labelableNodes=t.labelableNodes,this.nodes=[]):(this.scopeDepth=0,this.documentDeclarations={},this.source=t.source,this.diagnostics=t.diagnostics??[],this.syntax={tokens:(t.commentSpans??[]).map(e=>({kind:"comment",span:e})),calls:[]},this.variables=t.variables??{},this.functions=t.functions??new Map,this.labelableNodes=t.labelableNodes??[],this.nodes=t.toConsume??[],t.functions?[this.deSugarAtomFns,this.deSugarRelationFns]=r.getDeSugarFns(this.functions.values()):(this.deSugarAtomFns=[],this.deSugarRelationFns=[]))}static getDeSugarFns(t){let e=new Set(t),n=[],o=[];for(let s of e){let i=s.deSugarAtom;i&&i!==L.deSugarAtom&&n.push(i);let a=s.deSugarRelation;a&&a!==L.deSugarRelation&&o.push(a)}return[n,o]}pushNode(t){this.nodes.push(t);let e=t.labelable?.();e!==void 0&&this.labelableNodes.push(e)}get fontSize(){return this.variables.fontsize??bo}set fontSize(t){this.variables.fontsize=t}get strict(){return this.variables.strict??ti}set strict(t){this.variables.strict=t}setVariable(t,e){t==="fontsize"?this.fontSize=this.length2px(e):t==="strict"?this.strict=e:this.variables[t]=e}registerFunctions(t){let e=this.functions;for(let n of t){let o=n.def;if(!o)continue;let s=Array.isArray(o.name)?o.name:[o.name];for(let i of s){if(e.has(i.toLowerCase()))throw new Error(`Duplicate function name detected: ${i}`);e.set(i.toLowerCase(),n)}}[this.deSugarAtomFns,this.deSugarRelationFns]=r.getDeSugarFns(this.functions.values())}parse(t=0,e=this.source.length){return this.makeNodes(this.parseGrammar(t,e)),this.nodes}parseSyntax(t=0,e=this.source.length){if(this.parseGrammar(t,e,!0),this.scopeDepth===0){let n=(o,s)=>o.span.start-s.span.start||o.span.end-s.span.end;this.syntax.tokens.sort(n),this.syntax.calls.sort(n)}return this.syntax}addSyntax(t,e){e&&e.start<e.end&&this.syntax.tokens.push({kind:t,span:e})}recordSyntax(t){if(t.kind==="brace"){this.addSyntax("punctuation",{start:t.span.start,end:t.span.start+1});let a=Math.min(this.source.length,t.span.end-1);this.source[a]==="}"&&this.addSyntax("punctuation",{start:a,end:a+1}),new r(this).parseSyntax(t.span.start+1,a);return}if(t.kind==="label"){this.addSyntax("label",t.span);return}if(t.kind==="sugar"||t.typed){this.addSyntax(t.syntaxKind??"operator",t.span);return}let{kind:e,typed:n,syntaxKind:o,...s}=t;this.syntax.calls.push(s),this.addSyntax("function",s.nameSpan),this.addSyntax("punctuation",s.openParenSpan),this.addSyntax("punctuation",s.closeParenSpan);let i=this.functions.get(s.name.toLowerCase())?.prototype.def;for(let a=0;a<s.args.length;a++){let c=s.args[a];this.addSyntax("property",c.nameSpan),this.addSyntax("punctuation",c.equalsSpan),this.addSyntax("punctuation",c.commaSpan);let l=c.nameSpan?this.source.slice(c.nameSpan.start,c.nameSpan.end).toLowerCase():void 0,h=i&>(i,l,a);if(h==="content")new r(this).parseSyntax(c.valueSpan.start,c.valueSpan.end);else{let u=this.source.slice(c.valueSpan.start,c.valueSpan.end),f=Js(h,u);f&&this.addSyntax(f,c.valueSpan)}}}makeNodes(t,e=0,n=t.length){t:for(;e<n;e++){let o=t[e];if(typeof o=="number"){let s=this.nodes.at(-1);s instanceof H&&s.sourceSpan.end===o?s.sourceSpan.end=o+1:this.nodes.push(new H({start:o,end:o+1},null));continue}switch(o.kind){case"call":this.pushNode(this.parseCallNode(o));break;case"brace":let s=new r(this);this.nodes.push(new $(o.span,s.parse(o.span.start+1,o.span.end-1),null));break;case"label":let i=this.labelableNodes.at(-1);i?i.label!==void 0?this.diagnostics.push(E.warning.TargetAlreadyLabeled(o.label,i.label,o.span)):(i.label=o.label,this.nodes.push(new q(o.span,o.label,i))):this.diagnostics.push(E.warning.LabelWithoutTarget(o.label,o.span));break;case"sugar":for(let c of this.deSugarRelationFns){let l=c(this,t,e);if(l!==null){e=l-1;continue t}}let a=this.nodes.at(-1);a instanceof H&&a.sourceSpan.end===o.span.start?a.sourceSpan.end=o.span.end:this.nodes.push(new H(o.span,null));break}}return e}parseGrammar(t,e,n=!1){let o=[],s=i=>{o.push(i),n&&this.recordSyntax(i)};t:for(;(t=tt(this.source,t,e))<e;){let i=this.source[t];if(i==="@"){let a=po(this.source,t,e);if(a){s(Object.assign(a,{kind:"call",typed:!1}));let l=!1;for(let h of a.args){let u=h.nameSpan!==void 0;if(u&&!l)l=!0;else if(!u&&l){let f=E.error.PosAfterNamedArg(a.name,h.span);if(!n)throw f;this.diagnostics.push(f)}}if(!a.closeParenSpan){let h=E.error.UnterminatedCall(a.name,a.span);if(!n)throw h;this.diagnostics.push(h)}t=a.span.end;continue}let c=xo(this.source,t,e);if(c){s({kind:"label",span:{start:t,end:c.next},label:c.label}),t=c.next;continue}}if(i==="{"){let a=go(this.source,t,e);(a<0||a>=e||a<=t)&&(this.diagnostics.push(E.warning.UnmatchedBrace({start:t,end:e})),a=e),s({kind:"brace",span:{start:t,end:a+1}}),t=a+1;continue}for(let a of this.deSugarAtomFns)try{let c=a(this.source,t,e,this.scopeDepth);if(c){s(c.node),t=c.next;continue t}}catch(c){throw c instanceof E?this.diagnostics.push(c):this.diagnostics.push(E.error.Bug(c.toString(),{start:t,end:e})),c}o.push(t++)}return o}parseCallNode(t){let e=this.functions.get(t.name.toLowerCase()),n=e?.prototype.def,o=n?.args;if(!e||!o){if(this.strict)throw E.error.UnknownFunction(t.name,t.span);return this.diagnostics.push(E.warning.UnknownFunction(t.name,t.span)),new L(t.span,null)}if(!t.typed){let s=new Map;for(let i=0;i<t.args.length;i++){let a=t.args[i],c=a.nameSpan?this.source.slice(a.nameSpan.start,a.nameSpan.end).toLowerCase():void 0,l=gt(n,c,i),h=c??i;if(l===void 0){n.allowExtraArgs?s.set(h,a):this.diagnostics.push(E.warning.TooManyPosArgs(t.name,o.length,i+1,a.valueSpan));continue}let u=this.parseArgWithType(a.valueSpan,l,t.span.start);u!==null&&s.set(h,u)}return new e(t.span,s,this,null)}return new e(t.span,t.args,this,null)}parseArgWithType(t,e,n){let o=Mt(this.source,t.start,t.end),s=o.start,i=o.end;if(s>=i)return null;let a=e==="content"?"":this.source.slice(s,i);switch(e){case"number":let c=Number(a);return isNaN(c)?(this.diagnostics.push(E.warning.InvalidNumber(a,o)),null):c;case"boolean":let l=a;return yo.test(l)?l==="true":(this.diagnostics.push(E.warning.InvalidBoolean(a,o)),null);case"content":try{let g=new r(this).parse(s,i);return g.length===1?g[0]:new $(o,g,null)}catch(f){if(this.strict)throw f;return f instanceof E&&this.diagnostics.push(f),this.diagnostics.push(E.warning.InvalidContent(o)),null}case"label":n??=t.start;for(let f=this.labelableNodes.length-1;f>=0;f--){let g=this.labelableNodes[f];if(g&&!(g.sourceSpan.start>=n)&&g.label==a)return g}throw E.error.UnknownLabel(a,o);case"length":let h=He(a);return h instanceof E?(h.span.start+=s,h.span.end+=s,this.diagnostics.push(h),null):h;default:return ct(a)}return null}length2px(t){return t.unit==="em"?t.value*this.fontSize:t.value}};function tt(r,t,e){for(;t<e&&wo(r[t]);)t++;return t}function It(r,t,e=0){for(;t>=e&&wo(r[t]);)t--;return t}function wo(r){switch(r){case" ":case" ":case"\v":case"\f":case"\xA0":case"\uFEFF":case"\u3000":return!0;default:return!1}}var ni=/^[A-G]/,So=/^[0-9]/,Rt=/^[#bn]+/,Ao=/^[+-]?\d+/,To=/^[,']+/;function Ot(r,t=0,e=r.length){if(e-t===0)return new S("E_WRONG_NOTE_NAME",'\u51FD\u6570 @note \u7684\u53C2\u6570 [0]:"name" \u4E0D\u80FD\u4E3A\u7A7A',{start:t,end:e});let n=0,o=null,s=null,i=null,a=!1,c;for(let l=t;l<e;l++){let h=r[l];switch(n){case 0:if(ni.test(h))o=h,a=!0,n=1;else if(So.test(h))o=h,a=!1,n=4;else{let f=r.slice(l,e).match(Rt);if(f)s=f[0],l+=s.length-1,a=!1,n=7;else return new S("E_WRONG_NOTE_NAME",`\u51FD\u6570 @note \u7684\u53C2\u6570 [0]:"name" \u683C\u5F0F\u9519\u8BEF: \u9996\u5B57\u7B26 "${h}" \u4E0D\u5408\u6CD5\uFF0C\u671F\u671B A-G (a-g) \u6216 0-9 \u5F00\u5934\uFF0C\u6216\u5728\u5F00\u5934\u76F4\u63A5\u4F7F\u7528\u5347\u964D\u53F7(#/b/n)`,{start:l,end:l+1})}break;case 1:let u=r.slice(l,e);if(c=u.match(Ao),c){i=parseInt(c[0],10),l+=c[0].length-1,n=2;break}if(c=u.match(Rt),c){s=c[0],l+=s.length-1,n=3;break}return{name:o,next:l,acc:null,octave:null,absOctave:a};case 2:return c=r.slice(l,e).match(Rt),c?(s=c[0],{name:o,next:l+s.length,acc:s,octave:i,absOctave:a}):{name:o,next:l,acc:null,octave:i,absOctave:a};case 3:return c=r.slice(l,e).match(Ao),c?(i=parseInt(c[0],10),{name:o,next:l+c[0].length,acc:s,octave:i,absOctave:a}):{name:o,next:l,acc:s,octave:null,absOctave:a};case 4:if(c=r.slice(l,e).match(To),c){let f=c[0];i=Lo(f),l+=f.length-1,n=5;break}if(c=r.slice(l,e).match(Rt),c){s=c[0],l+=s.length-1,n=6;break}return{name:o,next:l,acc:null,octave:i,absOctave:a};case 5:return c=r.slice(l,e).match(Rt),c?(s=c[0],{name:o,next:l+s.length,acc:s,octave:i,absOctave:a}):{name:o,next:l,acc:null,octave:i,absOctave:a};case 6:if(c=r.slice(l,e).match(To),c){let f=c[0];return i=Lo(f),{name:o,next:l+f.length,acc:s,octave:i,absOctave:a}}return{name:o,next:l,acc:s,octave:i,absOctave:a};case 7:if(So.test(h)){o=h,n=6;break}else return new S("E_WRONG_NOTE_NAME",`\u51FD\u6570 @note \u7684\u53C2\u6570 [0]:"name" \u683C\u5F0F\u9519\u8BEF: \u5728\u5347\u964D\u53F7\u5F00\u5934\u65F6\uFF0C\u5E94\u8BE5\u63A5\u6570\u5B57\u97F3\u540D\uFF0C\u4F46\u53D1\u73B0\u5B57\u7B26 "${h}"`,{start:l,end:l+1});default:return E.error.Bug("\u97F3\u7B26\u540D\u79F0\u89E3\u6790\u72B6\u6001\u673A\u8FDB\u5165\u4E86\u672A\u5B9A\u4E49\u7684\u72B6\u6001",{start:l,end:e})}}return{name:o,next:e,acc:s,octave:i,absOctave:a}}function Lo(r){let t=0;for(let e=0;e<r.length;e++)r[e]===","?t--:r[e]==="'"&&t++;return t}var Tt={C:0,"C#":1,Db:1,D:2,"D#":3,Eb:3,E:4,F:5,"F#":6,Gb:6,G:7,"G#":8,Ab:8,A:9,"A#":10,Bb:10,B:11,1:0,2:2,3:4,4:5,5:7,6:9,7:11},Ut=["C","D","E","F","G","A","B"],Ge=[0,2,4,5,7,9,11];function Pt(r,t){let e=r[0],n="",o=1;o<r.length&&(r[o]==="#"||r[o]==="b"||r[o]==="n")&&(n=r[o],o++);let s=Tt[e+n];if(s===void 0)throw E.error.InvalidTonality(r,{start:0,end:o});if(o<r.length&&(t=parseInt(r.slice(o),10),isNaN(t)))throw E.error.InvalidTonality(r,{start:o,end:r.length});return(t+1)*12+s}function Ye(r,t=!0,e=0){for(let n of r)n==="#"?e++:n==="b"?e--:n==="n"&&!t&&(e=0);return e}function Ue(r,t,e,n){let o=Tt[r];if(o===void 0)return null;let s=Ye(t);return r>="1"&&r<="7"?Pt(n,4)+o+s+e*12:(e+1)*12+o+s}function Eo(r,t,e,n){let o,s;if(r>="1"&&r<="7")o=Number(r)-1,s=e;else{let c=Ke(r,t,e,n);if(!c)return;o=Number(c.renderName)-1,s=c.renderOctave}let i=Pt(n,4),a=s*7+o;return c=>{let l=a+c,h=Math.floor(l/7);return i+Ge[(l%7+7)%7]+h*12}}function Ve(r){return(r%12+12)%12}function oi(r){let t=Ve(r);return t>6?t-12:t}function si(r){return r===0?"":r>0?"#".repeat(r):"b".repeat(-r)}function Ke(r,t,e,n){let o=Ut.indexOf(n[0]),s=Ut.indexOf(r),i=Ue(r,t,e,n);if(o<0||s<0||i===null)return null;let a=Pt(n,4),c=(s-o+Ut.length)%Ut.length,l=Ve(a+Ge[c]),h=oi(Ve(i)-l),u=(i-a-Ge[c]-h)/12;return{renderName:String(c+1),renderAcc:si(h),renderOctave:u}}var ii={"#":{w:.46,h:.78,baseline:.63,commands:[{op:"M",x:.34,y:.05},{op:"L",x:.27,y:.95},{op:"M",x:.72,y:.05},{op:"L",x:.65,y:.95},{op:"M",x:.08,y:.38},{op:"L",x:.9,y:.28},{op:"M",x:.05,y:.72},{op:"L",x:.87,y:.62}]},b:{w:.38,h:.82,baseline:.67,commands:[{op:"M",x:.3,y:.04},{op:"L",x:.3,y:.94},{op:"M",x:.3,y:.5},{op:"Q",cx:.92,cy:.36,x:.76,y:.68},{op:"Q",cx:.63,cy:.87,x:.3,y:.86}]},n:{w:.42,h:.82,baseline:.67,commands:[{op:"M",x:.28,y:.05},{op:"L",x:.28,y:.82},{op:"L",x:.72,y:.68},{op:"L",x:.72,y:.95},{op:"M",x:.72,y:.95},{op:"L",x:.72,y:.18},{op:"L",x:.28,y:.32}]}};function ri(r,t){let e=ii[r];if(!e)return null;let n=t*.72;return{w:e.w*n,h:e.h*n,baseline:e.baseline*n,strokeWidth:t*.06,commands:e.commands}}function Kt(r,t,e,n,o){let s=[],i=t*.42,a=e,c=0;for(let l of r){let h=ri(l,t);if(!h)continue;let u=n-h.baseline-i;s.push({shape:h,x:a,y:u}),u<c&&(c=u),a+=h.w+o}return{placed:s,right:a,top:c}}function jt(r,{shape:t,x:e,y:n},o,s){r.drawPath(t.commands,{stroke:s,strokeWidth:t.strokeWidth},{x:o.x+e,y:o.y+n,scaleX:t.w,scaleY:t.h})}var qt="sans-serif",et='"Cascadia Mono", Consolas, "Liberation Mono", "Noto Sans Mono", monospace';function Qt(r){return`${r.fontWeight??"normal"} ${r.fontSize}px ${r.fontFamily??qt}`}var Zt=class{measureText(t,e){let n=e.fontSize,o=e.fontFamily?.toLowerCase().includes("mono")??!1,s=0;for(let i of t)s+=i.charCodeAt(0)>127?1:o?.62:.58;return{w:Math.max(s*n,n*.25),h:n,baseline:n*.8}}},Ze=new Zt,je=class{context;widths=new Map;constructor(t){this.context=t}measureText(t,e){let n=Qt(e),o=`${n}\0${t}`,s=this.widths.get(o);return s===void 0&&(this.context.font=n,s=this.context.measureText(t).width,this.widths.set(o,s)),{w:Math.max(s,e.fontSize*.25),h:e.fontSize,baseline:e.fontSize*.8}}};function ai(r){try{return Pt(r,4),r}catch{}let t=Ot(r.replace(/^[a-g]/,a=>a.toUpperCase()));if(t instanceof E)return null;let e=Tt[t.name];if(e===void 0)return null;let n=Ye(t.acc??"",!1),s=((t.absOctave?t.octave??4:4+(t.octave??0))+1)*12+e+n,i=Object.keys(Tt).filter(a=>Tt[a]===(s%12+12)%12&&/^[A-G]/.test(a));return(n<0?i.at(-1):i[0])+(Math.floor(s/12)-1)}var Qe=class extends L{static def={name:["key","1"],description:"\u8BBE\u7F6E\u65F6\u95F4\u7EBF\u4E0A\u7684 1= \u8C03\u6027\u57FA\u51C6",example:`@1(C4) \u6216 @key(F#3)
|
|
32
|
+
\u5B83\u4E0D\u4F1A\u4FEE\u6539 parser \u7684\u5C40\u90E8\u53D8\u91CF\uFF0C\u800C\u662F\u5728\u65F6\u95F4\u56FA\u5316\u9636\u6BB5\u5F71\u54CD\u5176\u540E\u7684\u6570\u5B57\u97F3\u540D\u89E3\u91CA
|
|
33
|
+
\u753B\u51FA\u6765\u7684\u8BB0\u53F7\u53EA\u542B\u97F3\u540D\u548C\u5347\u964D\u53F7\uFF0C\u4E0D\u542B\u516B\u5EA6\uFF1B\u901A\u5E38\u53E0\u5728\u97F3\u7B26\u4E0A\u65B9\u4E66\u5199\uFF1A1 ^ @1(F#)`,allowExtraArgs:!1,args:[{name:"tonality",type:"string",default:null},{name:"size",type:"length",default:{value:1,unit:"em"}}]};tonality;size;displayName;displayAcc;constructor(t,e,n,o=null){super(t,o);let[s,i]=this.getArgValue(e,n);this.tonality=s,this.size=n.length2px(i);let a=ai(s);if(a!==s){if(n.strict)throw new S("E_KEY_TONALITY",`@key \u65E0\u6CD5\u89E3\u6790\u8C03\u6027 "${s}"`,t);this.tonality=a??Nt,n.diagnostics.push(new C("W_KEY_TONALITY",`@key \u7684\u8C03\u6027 "${s}" \u4E0D\u662F\u89C4\u8303\u5199\u6CD5\uFF0C\u5DF2\u81EA\u52A8\u5207\u6362\u5230 ${this.tonality}`,t))}this.displayName=this.tonality[0],this.displayAcc=this.tonality[1]==="#"||this.tonality[1]==="b"?this.tonality[1]:""}loweringEnter(){return[new Xe(this)]}toString(){return`@1(${this.tonality})`}},Xt=Qe,qe="1=",Xe=class extends D{accidentals=[];nameX=0;textBaselineY=0;style;constructor(t){super(),this.ast=t,this.style={fontSize:t.size,fontFamily:et,fill:"#000"},this.initLayoutBox()}onTimeState(t){t.keySignature=this.ast.tonality}prepareLayout(t){let e=this.ast.size,n=this.style,o=t.textMeasurer.measureText(qe,n),s=t.textMeasurer.measureText(this.ast.displayName,n),i=e*.02,{placed:a,right:c,top:l}=Kt(this.ast.displayAcc,e,o.w,o.baseline,i);this.accidentals=a;let h=-l;for(let u of a)u.y+=h;this.nameX=c,this.textBaselineY=h+o.baseline,this.box.w=c+s.w,this.box.h=h+Math.max(o.h,s.h),this.box.anchor=t.textMeasurer.measureText(qe[0],n).w/2,this.box.visualAxis=this.box.h/2}paint(t){let e=this.style;t.drawText(qe,this.box.x,this.box.y+this.textBaselineY,e);for(let n of this.accidentals)jt(t,n,this.box,"#000");t.drawText(this.ast.displayName,this.box.x+this.nameX,this.box.y+this.textBaselineY,e)}};var Je=class extends L{static def={name:["meter"],description:"\u8BBE\u7F6E\u62CD\u53F7",example:"@meter(6, 8) \u8BBE\u7F6E 6/8 \u62CD\u53F7",allowExtraArgs:!1,args:[{name:"num",type:"number",default:null},{name:"den",type:"number",default:null},{name:"size",type:"length",default:{value:.7,unit:"em"}}]};numerator;denominator;measureDuration;size;strict;constructor(t,e,n,o=null){super(t,o);let[s,i,a]=this.getArgValue(e,n);if(!Number.isSafeInteger(s)||!Number.isSafeInteger(s*4)||s<=0||!Number.isSafeInteger(i)||i<=0){let c="@meter \u7684\u5206\u5B50\u548C\u5206\u6BCD\u5FC5\u987B\u662F\u6B63\u6574\u6570";if(n.strict)throw new S("E_METER_INVALID",c,t);n.diagnostics.push(new C("W_METER_INVALID",`${c}\uFF0C\u5DF2\u56DE\u843D\u4E3A 4/4`,t)),s=i=4}this.numerator=s,this.denominator=i,this.measureDuration=new M(s*4,i),this.size=n.length2px(a),this.strict=n.strict}loweringEnter(){return[new Jt(this)]}static loweringFinalize=t=>{let e=new M,n=new M,o=null,s=!1,i=0,a=(c,l)=>{if(!(!o||c.equals(e))){if(n.copyFrom(c).sub(e),!n.equals(o.measureDuration)&&(s||n.compare(o.measureDuration)>0)){let h=`\u5C0F\u8282\u65F6\u957F\u4E3A ${n} QN\uFF0C\u4E0D\u6EE1\u8DB3 ${o.numerator}/${o.denominator} \u62CD\u53F7`,u={start:i,end:l};if(o.strict)throw new S("E_METER_MISMATCH",h,u);t.diagnostics.push(new C("W_METER_MISMATCH",h,u))}e.copyFrom(c)}};for(let c of t.columns){let l=c[0].t,h=c.find(f=>f instanceof Jt);h&&(a(l,h.ast.sourceSpan.start),o=h.ast,e.copyFrom(l),i=h.ast.sourceSpan.end);let u=c.find(f=>f.mergeKey===W);u&&(a(l,u.ast.sourceSpan.end),i=u.ast.sourceSpan.end,s=!0)}if(o){let c=t.columns.at(-1)?.at(-1)?.ast.sourceSpan??o.sourceSpan;a(t.duration,c.end)}};toString(){return`@meter(${this.numerator}, ${this.denominator})`}},te=Je,Jt=class extends D{style;numeratorBaseline=0;denominatorBaseline=0;lineY=0;lineHeight=0;constructor(t){super(),this.ast=t,this.style={fontSize:t.size,fontFamily:et,textAlign:"center",fill:"#000"},this.initLayoutBox()}emitPlayback(t){t.emit({kind:"time-signature",at:t.start,numerator:this.ast.numerator,denominator:this.ast.denominator})}prepareLayout(t){let e=t.textMeasurer.measureText(String(this.ast.numerator),this.style),n=t.textMeasurer.measureText(String(this.ast.denominator),this.style),o=this.ast.size*.08,s=this.ast.size*.08;this.lineHeight=Math.max(1,this.ast.size*.06),this.numeratorBaseline=e.baseline,this.lineY=e.h+o,this.denominatorBaseline=this.lineY+this.lineHeight+o+n.baseline,this.box.w=Math.max(e.w,n.w)+s*2,this.box.h=this.lineY+this.lineHeight+o+n.h,this.box.anchor=this.box.w/2,this.box.visualAxis=this.lineY+this.lineHeight/2}paint(t){let e=this.box.x+this.box.anchor;t.drawText(String(this.ast.numerator),e,this.box.y+this.numeratorBaseline,this.style),t.drawRect(this.box.x,this.box.y+this.lineY,this.box.w,this.lineHeight,{fill:"#000"}),t.drawText(String(this.ast.denominator),e,this.box.y+this.denominatorBaseline,this.style)}};var ci=[{op:"M",x:3.864,y:8.5},{op:"Q",cx:3.864,cy:9.228,x:3.5,y:9.76},{op:"Q",cx:3.136,cy:10.292,x:2.555,y:10.586},{op:"Q",cx:1.974,cy:10.88,x:1.302,y:10.88},{op:"Q",cx:.826,cy:10.88,x:.413,y:10.621},{op:"Q",cx:0,cy:10.362,x:0,y:9.844},{op:"Q",cx:0,cy:9.34,x:.364,y:8.899},{op:"Q",cx:.728,cy:8.458,x:1.288,y:8.185},{op:"Q",cx:1.848,cy:7.912,x:2.422,y:7.912},{op:"Q",cx:2.968,cy:7.912,x:3.304,y:8.094},{op:"L",x:3.304,y:0},{op:"L",x:3.864,y:0},{op:"Z"}];function _o(r){let t=r/11;return{w:3.864*t,h:10.88*t,stemCenterX:(3.304+3.864)/2*t,commands:ci,scale:t}}var tn=class extends L{static def={name:["tempo"],description:"\u8BBE\u7F6E\u65F6\u95F4\u7EBF\u4E0A\u7684\u901F\u5EA6",example:"@tempo(96) \u5C06\u5176\u540E\u7684\u65F6\u95F4\u72B6\u6001\u901F\u5EA6\u8BBE\u7F6E\u4E3A 96 BPM",allowExtraArgs:!1,args:[{name:"bpm",type:"number",default:null},{name:"size",type:"length",default:{value:1,unit:"em"}}]};bpm;size;constructor(t,e,n,o=null){super(t,o);let[s,i]=this.getArgValue(e,n);this.bpm=s,this.size=n.length2px(i)}loweringEnter(){return[new en(this)]}toString(){return`@tempo(${this.bpm})`}},ee=tn,en=class extends D{glyph;text;style;glyphY=0;textX=0;textBaselineY=0;constructor(t){super(),this.ast=t,this.glyph=_o(t.size),this.text=`= ${t.bpm}`,this.style={fontSize:t.size,fill:"#000"},Number.isFinite(t.bpm)&&t.bpm>0&&(this.playbackState={bpm:t.bpm}),this.initLayoutBox()}onTimeState(t){let e=this.playbackState?.bpm;e!==void 0&&(t.bpm=e)}prepareLayout(t){let e=this.glyph,n=t.textMeasurer.measureText(this.text,this.style),o=Math.max(0,e.h-n.baseline);this.textX=e.w+this.ast.size*.26,this.textBaselineY=o+n.baseline,this.glyphY=this.textBaselineY-e.h,this.box.w=this.textX+n.w,this.box.h=o+n.h,this.box.anchor=e.stemCenterX,this.box.visualAxis=o+n.h/2}paint(t){t.drawPath(this.glyph.commands,{fill:"#000"},{x:this.box.x,y:this.box.y+this.glyphY,scaleX:this.glyph.scale,scaleY:this.glyph.scale}),t.drawText(this.text,this.box.x+this.textX,this.box.y+this.textBaselineY,this.style)}};var nn=class extends L{static def={name:["text"],description:"\u6587\u672C\u6807\u8BB0\u3002\u62EC\u53F7\u5185\u53EF\u76F4\u63A5\u6362\u884C\uFF0C\u652F\u6301 left\u3001center\u3001right \u5BF9\u9F50",example:`@text(\u8FDB\u5165\u4E3B\u9898)
|
|
34
|
+
\u8BED\u6CD5\u7CD6\uFF1A\u76F4\u63A5\u5199\u53CC\u5F15\u53F7\u5B57\u7B26\u4E32\uFF0C\u5982 "\u8FDB\u5165\u4E3B\u9898"\uFF1B\u53EF\u8DE8\u884C\uFF0C\u5F15\u53F7\u672A\u914D\u5BF9\u5219\u4E0D\u751F\u6548`,allowExtraArgs:!1,args:[{type:"string",default:null},{name:"size",type:"length",default:{value:1,unit:"em"}},{name:"lineheight",type:"number",default:1.25},{name:"align",type:"string",default:"left"}]};static deSugarAtom(t,e,n){if(t[e]!=='"')return null;let o=At(t,e,n);if(o<0)return null;let s={kind:"call",typed:!0,name:"text",args:new Map([[0,ct(t.slice(e,o+1))]]),span:{start:e,end:o+1},syntaxKind:"string"};return{next:o+1,node:s}}lines;size;lineAdvance;align;constructor(t,e,n,o=null){super(t,o);let[s,i,a,c]=this.getArgValue(e,n);if(c!=="left"&&c!=="center"&&c!=="right")throw new S("E_TEXT_INVALID_ALIGN","@text \u7684 align \u53C2\u6570\u5FC5\u987B\u662F 'left'\u3001'center' \u6216 'right'",t);this.lines=s.split(/\r?\n/),this.size=n.length2px(i),this.lineAdvance=a*this.size,this.align=c}loweringEnter(){return[new on(this)]}toString(){let t=this.size===0?1.25:this.lineAdvance/this.size;return`@text(${JSON.stringify(this.lines.join(`
|
|
35
|
+
`))}, size=${this.size}px, lineheight=${t}, align=${this.align})`}},ne=nn,on=class extends D{style;textBaselineY=0;constructor(t){super(),this.ast=t,this.mergeKey=Q,this.style={fontSize:t.size,fill:"#000",textAlign:t.align},this.initLayoutBox()}prepareLayout(t){let{lines:e,align:n,lineAdvance:o}=this.ast,s=c=>t.textMeasurer.measureText(c,this.style),i=s(e[0]),a=i.w;for(let c=1;c<e.length;c++)a=Math.max(a,s(e[c]).w);if(this.box.w=a,this.box.h=(e.length-1)*o+i.h,this.box.visualAxis=this.box.h/2,this.textBaselineY=i.baseline,n==="center")this.box.anchor=a/2;else if(n==="right"){let c=[...e[0]].at(-1);this.box.anchor=a-(c?s(c).w/2:0)}else{let c=[...e[0]][0];this.box.anchor=c?s(c).w/2:0}}paint(t){let{lines:e,align:n,lineAdvance:o}=this.ast,s=this.box.x+(n==="center"?this.box.w/2:n==="right"?this.box.w:0),i=this.box.y+this.textBaselineY;for(let a of e)t.drawText(a,s,i,this.style),i+=o}};var No={title:"center",subtitle:"center",author:"right",signature:"left",tempo:"left",left:"left",center:"center",right:"right"},li={title:[2,"center"],subtitle:[.85,"center"],author:[.8,"right"]},hi=.25,ko=5,Co=1e4;function oe(r,t){return t.length===1&&t[0]instanceof $?t[0]:new $(r,t)}function vo(r,t,e=r.length){for(;t<e&&r[t]!=="\r"&&r[t]!==`
|
|
36
|
+
`;)t++;return t}function ui({columns:r,rows:t,start:e,end:n,X:o,fixed:s,options:i},a){bt(r.slice(e,n+1),t,o.subarray(e,n+1),s.subarray(e,n),1/0,i);let c=1/0,l=-1/0;for(let h=e+1;h<n;h++)for(let u=0;u<t;u++)c=Math.min(c,o[h]-r[h][u].WL),l=Math.max(l,o[h]+r[h][u].WR);a&&c<=l?(o[e]=c,o[n]=l):o[n]=o[e]}function Mo(r,t,e){let n=[],o,s;for(let i of r){if(!i){n.push(null);continue}let a=s===void 0?0:s+t-i.top;n.push({offset:a,extent:i}),o??=a+i.top,s=a+i.bottom}return e?.(o===void 0||s===void 0?null:{top:o,bottom:s}),n}var se=class extends D{constructor(t){super(),this.ast=t,this.initLayoutBox()}prepareLayout(){this.box.w=this.box.h=this.box.anchor=this.box.visualAxis=0}prepareHorizontal(t){this.ast.name==="left"&&this===this.ast.start&&this.ast.owner.prepareHead(t)}onPlaced(){this.ast.name==="left"&&this===this.ast.start&&this.ast.owner.alignHead()}},lt=class extends V{owner;name;rows;tracks;start;end;constructor(t,e,n,o,s){super(t,e),this.owner=e,this.name=n,this.rows=o,this.tracks=s;for(let i of this.rows)i.parent=this}get size(){return this.owner.size}get children(){return this.rows}timeFlowModel(){return this.rows.length===0?null:{mode:"parallel",children:this.rows,tracks:this.tracks}}loweringEnter(){return this.start=new se(this),[this.start]}loweringExit(){return this.end=new se(this),[this.end]}addRow(t){t.parent=this,this.rows.push(t)}},sn=class r extends L{static def={name:["head"],description:"\u63D0\u4F9B\u5DE6\u3001\u4E2D\u3001\u53F3\u4E09\u5757\u5E03\u5C40\uFF0C\u5E38\u7528\u4E8E\u66F2\u8C31\u5934\u90E8\u4FE1\u606F\u5C55\u793A\uFF1B\u4E5F\u53EF\u7528\u8FDE\u7EED\u7684 H.*: \u884C\u58F0\u660E\u6784\u9020",example:`@head(left={{@key(C) @meter(4,4)}}, center={@text(\u6807\u9898)}, right={@text(\u4F5C\u8005)})
|
|
37
|
+
\u8BED\u6CD5\u7CD6\uFF1A\u76F8\u90BB\u7684 H.*: \u58F0\u660E\u5408\u5E76\u4E3A\u4E00\u4E2A head\uFF0C\u6BCF\u6761\u58F0\u660E\u751F\u6210\u5BF9\u5E94\u69FD\u7684\u4E00\u884C\uFF1B\u7A7A\u884C\u6216\u666E\u901A\u5185\u5BB9\u7ED3\u675F\u7EC4\u5408
|
|
38
|
+
H.title: \u6807\u9898 center \u69FD\uFF0C\u9884\u8BBE\u5927\u5B57\u53F7\u5C45\u4E2D Text
|
|
39
|
+
H.subtitle: \u526F\u6807\u9898 center \u69FD\uFF0C\u9884\u8BBE\u5C0F\u5B57\u53F7\u5C45\u4E2D Text
|
|
40
|
+
H.author: \u4F5C\u8005 right \u69FD\uFF0C\u9884\u8BBE\u5C0F\u5B57\u53F7\u53F3\u5BF9\u9F50 Text
|
|
41
|
+
H.signature: 1=C 4/4 left \u69FD\uFF0C\u540C\u4E00\u884C\u751F\u6210 Key \u548C Meter
|
|
42
|
+
H.tempo: 94 left \u69FD\uFF0C\u751F\u6210 Tempo
|
|
43
|
+
H.left: / H.center: / H.right: \u63A5\u53D7\u5BF9\u5E94\u69FD\u7684\u4EFB\u610F\u96F6\u65F6\u957F DSL \u5185\u5BB9
|
|
44
|
+
\u4EE5 @ \u6216 { \u5F00\u5934\u65F6\u6309 DSL \u89E3\u6790\uFF0C\u5426\u5219\u6309\u8BE5\u5B57\u6BB5\u7684\u88F8\u6587\u672C\u89C4\u5219\u751F\u6210 Text`,allowExtraArgs:!1,args:[{name:"left",type:"content",default:""},{name:"center",type:"content",default:""},{name:"right",type:"content",default:""},{name:"gap",type:"length",default:{value:ko,unit:"px"}}]};slots;size;gap;members=[];createdBySugar=!1;get children(){return this.slots}timeFlowModel(){return{mode:"sequence",children:this.slots}}static deSugarAtom(t,e,n){if(t[e]!=="H"||t[e+1]!==".")return null;let o=e+2;for(;o<n&&t[o]>="a"&&t[o]<="z";)o++;let s=t.slice(e+2,o);if(!Object.hasOwn(No,s)||t[o]!==":")return null;o++;let i=vo(t,o,n),a=tt(t,o,i);return{next:t[a]==="@"||t[a]==="{"?o:i,node:{kind:"sugar",data:{class:r,field:s},span:{start:e,end:o}}}}static deSugarRelation(t,e,n){let o=e[n++];if(o.data?.class!==r)return null;let s=o.data.field,i=n;for(;i<e.length;i++){let p=e[i];if(typeof p=="number"&&(t.source[p]==="\r"||t.source[p]===`
|
|
45
|
+
`)||typeof p!="number"&&p.kind==="sugar"&&p.data?.class===r)break}let a=e[i],c;if(typeof a=="number")c=a;else if(a)c=a.span.start;else if(i>n){let p=e[i-1];c=typeof p=="number"?p+1:p.span.end}else c=vo(t.source,o.span.end);let l=tt(t.source,o.span.end,c),h=It(t.source,c-1,l),u={start:l,end:Math.max(l,h+1)};if(u.start>=u.end)throw new S("E_HEAD_EMPTY_DECLARATION",`H.${s}: \u540E\u5FC5\u987B\u6709\u5185\u5BB9`,o.span);let f=t.source.slice(u.start,u.end).trim(),g;if(f.startsWith("@")||f.startsWith("{")){let p=new X(t);p.makeNodes(e.slice(n,i)),g=p.nodes}let d=t.nodes.at(-1),y=d instanceof r&&d.createdBySugar?d:new r(o.span,new Map,t,null);if(y.createdBySugar=!0,y.addSugarRow(No[s],r.parseSugarRow(t,s,u,f,g)),y.sourceSpan.end=u.end,y!==d&&t.pushNode(y),typeof a!="number")return i;let x=i+1;if(t.source[a]==="\r"){let p=e[x];typeof p=="number"&&t.source[p]===`
|
|
46
|
+
`&&x++}return x}static parseSugarRow(t,e,n,o,s){if(s!==void 0)return oe(n,s);if(e==="signature"){let c=/^(1\s*=\s*(\S+))\s+((\d+)\s*\/\s*(\d+))$/.exec(o);if(!c)throw new S("E_HEAD_INVALID_SIGNATURE","H.signature \u7684\u683C\u5F0F\u5E94\u4E3A 1=C 4/4",n);let l={start:n.start,end:n.start+c[1].length},h={start:n.end-c[3].length,end:n.end};return oe(n,[new Xt(l,new Map([["tonality",c[2]]]),t,null),new te(h,new Map([["num",Number(c[4])],["den",Number(c[5])]]),t,null)])}if(e==="tempo"){let c=Number(o);if(!Number.isFinite(c)||c<=0)throw new S("E_HEAD_INVALID_TEMPO","H.tempo \u540E\u5FC5\u987B\u662F\u6B63\u6570",n);return oe(n,[new ee(n,new Map([["bpm",c]]),t,null)])}let i=new Map([[0,o]]),a=li[e];return a&&(i.set("size",{value:a[0],unit:"em"}),i.set("align",a[1])),oe(n,[new ne(n,i,t,null)])}constructor(t,e,n,o=null){super(t,o),this.size=n.fontSize,this.gap=n.length2px(this.getArgValue(e,n)[3]);let s=`head/rows/${t.start}`,i=0,a=null,c=null,l=f=>({laneKey:`${s}/${f}`,hostIndex:null,measure:g=>Mo(g,this.gap,d=>{f==="left"?a=d:c=d}),place:()=>{let g=f==="left"?a:c;if(!g)return i;let d=a?a.bottom-a.top:0,y=c?c.bottom-c.top:0;return i+Math.max(d,y)-g.bottom}}),h=f=>{let g=Mo(f,this.gap),d=g.find(y=>y!==null);return i=d?d.offset+d.extent.bottom:0,g},u=(f,g)=>{let d=e.get(f)??e.get(g);return d instanceof V?d instanceof $?d.content:[d]:[]};this.slots=[new lt(t,this,"left",u("left",0),l("left")),new lt(t,this,"center",u("center",1),{laneKey:`${s}/center`,hostIndex:null,measure:h}),new lt(t,this,"right",u("right",2),l("right"))]}loweringEnter(t){return this.members.length=0,t.beginLoweringGroup(this,{onTemporal:e=>this.members.push(e)}),[]}loweringExit(t){t.endLoweringGroup(this);for(let e of this.members){if(!e.T.isZero())throw new S("E_HEAD_NONZERO_DURATION","@head \u7684\u5185\u5BB9\u5FC5\u987B\u5168\u90E8\u4E3A\u96F6\u65F6\u957F",e.ast.sourceSpan);if(e.breakBefore>0)throw new S("E_HEAD_INTERNAL_BREAK","@head \u7684\u5185\u90E8\u4E0D\u80FD\u4F7F\u7528 @br\uFF1B\u7B2C\u4E00\u5C42\u5185\u5BB9\u5DF2\u7ECF\u8868\u793A\u89C6\u89C9\u884C",e.ast.sourceSpan)}return[]}addSugarRow(t,e){this.slots.find(n=>n.name===t).addRow(e)}prepareHead(t){if(this.members.some(s=>R(s)&&s.layoutLine!==t.index))throw new S("E_HEAD_INTERNAL_BREAK","@head \u7684\u5185\u5BB9\u4E0D\u80FD\u8DE8\u8C31\u9762\u884C",this.sourceSpan);let[e,n,o]=this.slots;e.start.springConfig.alpha_L=0,o.end.springConfig.alpha_R=0,this.stretch(n.start,"L"),this.stretch(n.end,"R");for(let s of this.slots)t.registerHorizontalLayoutHook(s.start,s.end,i=>ui(i,s===n))}alignHead(){let t=new Map;for(let o of this.members){if(!R(o))continue;let s=this.sideCellOf(o.ast);if(!s)continue;let i=t.get(s);i?i.push(o):t.set(s,[o])}let[e,,n]=this.slots;this.packRows(e,e.start.box.x,"left",t),this.packRows(n,n.end.box.x,"right",t)}toString(t){let e=this.slots.filter(n=>n.rows.length>0).map(n=>{let o=n.rows.map(s=>` ${s.toString(t).replaceAll(`
|
|
47
|
+
`,`
|
|
48
|
+
`)}`).join(`
|
|
49
|
+
`);return` ${n.name}={
|
|
50
|
+
${o}
|
|
51
|
+
}`});return this.gap!==ko&&e.push(` gap=${this.gap}px`),`@head(
|
|
52
|
+
${e.join(`,
|
|
53
|
+
`)}
|
|
54
|
+
)`}stretch(t,e){let n=e==="L"?"alpha_L":"alpha_R",o=e==="L"?"beta_L":"beta_R";t.springConfig[n]=t.springConfig[n]*Co,t.springConfig[o]=t.springConfig[o]*3/Co}packRows(t,e,n,o){let s=this.size*hi,i=n==="left",a=i?1:-1;for(let c of t.rows){let l=c instanceof $?c.content:[c],h=e;for(let u=i?0:l.length-1;u>=0&&u<l.length;u+=a){let f=o.get(l[u]);if(!f)continue;let g=1/0,d=-1/0;for(let x of f)g=Math.min(g,x.box.x),d=Math.max(d,x.box.x+x.box.w);let y=h-(i?g:d);for(let x of f)x.box.x+=y;for(let x of f)x.onPlaced?.();h+=a*(d-g+s)}}}sideCellOf(t){let e=t;for(;e.parent;){let n=e.parent,o=n instanceof lt?n:n instanceof $&&n.parent instanceof lt?n.parent:null;if(o?.owner===this)return o.name==="center"?null:e;e=n}return null}},Io=sn;var rn=class extends L{static def={name:["br"],description:"\u6362\u884C",example:`@br(offset=1): \u5728\u540E\u7EED\u4E8B\u4EF6\u524D\u504F\u79FB\u6307\u5B9A\u884C\u6570
|
|
55
|
+
@br() === @br(1)
|
|
56
|
+
@br(2): \u7A7A\u51FA\u4E00\u884C\u540E\u7EE7\u7EED
|
|
57
|
+
\u8BED\u6CD5\u7CD6: [\u4EC5\u9650\u9876\u5C42]\u81F3\u5C11\u8FDE\u7EED\u4E24\u4E2A\u6362\u884C
|
|
58
|
+
`,allowExtraArgs:!1,args:[{name:"offset",type:"number",default:1}]};static deSugarAtom(t,e,n,o){if(o>0||t[e]!==`
|
|
59
|
+
`||t[It(t,e-1)]!==`
|
|
60
|
+
`)return null;let s=e+1,i=s;for(;(i=tt(t,i,n))<n&&t[i]===`
|
|
61
|
+
`;)s=++i;return{next:s,node:{kind:"call",typed:!0,name:"br",args:new Map,span:{start:e,end:s}}}}offset;loweringEnter(){let t=new D;return t.ast=this,t.mergeKey=-1,t.breakBefore=this.offset,[t]}static loweringFinalize=t=>{let e=new M,n=new M,o=null;for(let s of t.columns){if(o&&e.compare(s[0].t)>0&&s.some(i=>i.breakBefore>0))throw E.error.BreakInsideEvent(o.ast.sourceSpan);for(let i of s)i.T.isZero()||(n.copyFrom(i.t).add(i.T),(!o||n.compare(e)>0)&&(e.copyFrom(n),o=i))}};constructor(t,e,n,o=null){super(t,o);let[s]=this.getArgValue(e,n);this.offset=Number.isFinite(s)?Math.max(1,Math.floor(s)):1,this.offset!==s&&n.diagnostics.push(new C("W_BR_OFFSET",`@br \u7684 offset \u5FC5\u987B\u662F\u5927\u4E8E\u7B49\u4E8E 1 \u7684\u6574\u6570\uFF0C\u5DF2\u88AB\u4FEE\u6B63\u4E3A ${this.offset}`,this.sourceSpan))}toString(){return`@br(${this.offset})`}},Ro=rn;var an=class extends L{static def={name:["note","n"],description:"\u521B\u5EFA\u97F3\u7B26",example:`@note(name, acc, octave, color)
|
|
62
|
+
\u53C2\u6570\u8BF4\u660E:
|
|
63
|
+
- name: [\u5FC5\u586B]\u97F3\u7B26\u540D\uFF0C\u53EF\u4EE5\u662F\u5927\u5199\u5B57\u6BCD\u6216\u8005\u6570\u5B57\uFF0C\u4E0D\u5141\u8BB8\u5C0F\u5199\u5B57\u6BCD\uFF08\u4F1A\u548C\u964D\u53F7\u51B2\u7A81\uFF09\u3002\u6B64\u53C2\u6570\u5199\u6CD5\u6709\u8BED\u6CD5\u7CD6\uFF0C\u89C1\u4E0B\u3002
|
|
64
|
+
\u5176\u4E2D 0 \u662F\u4F11\u6B62\u7B26\uFF0C8 \u662F\u9690\u5F62\u5360\u4F4D\uFF0C9 \u662F\u53EA\u6253\u62CD\u4E0D\u53D1\u97F3\u7684\u8282\u62CD\u8BB0\u53F7\uFF08\u663E\u793A\u4E3A X\uFF09\uFF0C\u8FD9\u4E09\u8005\u90FD\u4E0D\u663E\u793A\u5347\u964D\u53F7\u548C\u516B\u5EA6\u70B9\u3002
|
|
65
|
+
- acc: [\u53EF\u9009]\u7684\u989D\u5916\u5347\u964D\u53F7\u5B57\u7B26\u4E32\uFF0C\u4F8B\u5982 "##" \u8868\u793A\u518D\u5347\u4E24\u4E2A\u534A\u97F3\uFF0C"b" \u8868\u793A\u518D\u964D\u4E00\u4E2A\u534A\u97F3\u3002
|
|
66
|
+
- octave: [\u53EF\u9009]\u516B\u5EA6\uFF0C\u7C7B\u578B\u4E3A\u6570\u5B57\u3002\u5982\u679C name \u662F\u5B57\u6BCD\uFF0C\u5219\u6B64\u9879\u4EE3\u8868\u7EDD\u5BF9\u516B\u5EA6\uFF1B\u5982\u679C\u662F\u6570\u5B57\uFF0C\u5219\u6B64\u9879\u4EE3\u8868\u76F8\u5BF9\u516B\u5EA6\u3002
|
|
67
|
+
|
|
68
|
+
\u8BED\u6CD5\u7CD6\uFF1A[\u97F3\u540D][\u5347\u964D\u53F7][\u516B\u5EA6] \u97F3\u540D\u548C\u5347\u964D\u53F7\u53EF\u4EE5\u4EA4\u6362
|
|
69
|
+
\u4F8B\uFF1AA3# === @note(A3#) === @note(A, #, 3)
|
|
70
|
+
\u4E5F\u652F\u6301 A99##bn \u7684\u5199\u6CD5\u3002\u53EF\u4EE5\u8BBE\u7F6E note.octave \u6539\u53D8\u9ED8\u8BA4\u7684\u7EDD\u5BF9\u516B\u5EA6
|
|
71
|
+
|
|
72
|
+
\u652F\u6301 \u6570\u5B57\u97F3\u540D, \u6B64\u65F6 octave \u4E3A\u76F8\u5BF9\u516B\u5EA6
|
|
73
|
+
\u652F\u6301\u4F7F\u7528\u6570\u5B57\u97F3\u540D\u65F6\u4F7F\u7528\u76F8\u5BF9\u516B\u5EA6\uFF0C\u5982 "1,," \u4EE3\u8868\u5728\u5F53\u524D\u57FA\u51C6\u97F3\uFF08\u7531\u4E0A\u4E0B\u6587\u5C5E\u6027"1=?"\u51B3\u5B9A\uFF09\u7684\u57FA\u7840\u4E0A\u964D\u4F4E\u4E24\u500D\u516B\u5EA6\uFF0C"1'" \u4EE3\u8868\u5728\u5F53\u524D\u57FA\u51C6\u97F3\u7684\u57FA\u7840\u4E0A\u63D0\u9AD8\u4E00\u4E2A\u516B\u5EA6
|
|
74
|
+
\u4F8B\uFF1A1#' === @note(1#') === @note(1, #, 1)\u3002\u6B64\u65F6\u652F\u6301\u5347\u964D\u53F7\u5199\u97F3\u540D\u524D\u9762\uFF0C\u5982 #1'
|
|
75
|
+
`,allowExtraArgs:!1,args:[{name:"name",type:"string",default:null},{name:"acc",type:"string",default:""},{name:"octave",type:"number",default:4},{name:"color",type:"string",default:"#000"}]};static deSugarAtom(t,e,n){let o=Ot(t,e,n);if(o instanceof E)return null;let s=new Map;s.set("name",o.name),o.octave&&s.set("octave",o.octave),o.acc&&s.set("acc",o.acc);let i={kind:"call",typed:!0,name:"note",args:s,span:{start:e,end:o.next},syntaxKind:"atom"};return{next:o.next,node:i}}labelable(){return this}loweringEnter(){return[new cn(this)]}name;octave;acc;color;size;constructor(t,e,n,o=null){super(t,o),[this.name,this.acc,this.octave,this.color]=this.getArgValue(e,n),this.size=n.fontSize;let s=Ot(this.name);if(s instanceof E)throw s.span=t,s;this.name=s.name;let i=e.get("octave")??e.get(2);if(i!==void 0){if(s.octave!==null&&s.octave!=i)throw new S("E_NOTE_OCTAVE_CONFLICT",`\u51FD\u6570 @note \u7684\u53C2\u6570 "octave" \u4E0E\u97F3\u7B26\u540D\u79F0\u4E2D\u7684\u516B\u5EA6\u4FE1\u606F\u51B2\u7A81: ${i} != ${s.octave}`,t)}else s.absOctave||(this.octave=s.octave??0);s.acc!==null&&(this.acc=s.acc+this.acc)}toString(){return`@n(${this.name}, ${this.acc}, ${this.octave}, ${this.color})`}},Oo=an,fi={8:"",9:"X"},cn=class extends D{resolvedMidi=null;transposeDiatonic;name;acc;octave;accidentals=[];numberStyle;upperOctaveDotY=[];lowerOctaveDotY=[];octaveDotRadius=0;numberY=0;constructor(t){super(),this.ast=t,this.T.set(1),this.mergeKey=Q,this.name=t.name,this.acc=t.acc,this.octave=t.octave,this.numberStyle={fontSize:t.size,fontFamily:et,fontWeight:400,textAlign:"center",fill:t.color},this.initLayoutBox()}prepareLayout(t){this.upperOctaveDotY.length=0,this.lowerOctaveDotY.length=0;let{size:e,color:n}=this.ast,o=t.textMeasurer.measureText("0",this.numberStyle),s=Math.abs(this.octave);this.octaveDotRadius=e*.065;let i=e*.08,a=this.octaveDotRadius*2+i,c=s===0?0:s*this.octaveDotRadius*2+(s-1)*i+i,l=this.octave>0?c:0;this.numberY=l+o.baseline;let h=e*.01,{placed:u,right:f}=Kt(this.acc,e,0,this.numberY,h);if(this.accidentals=u,this.box.w=f+o.w,this.box.h=l+o.h,this.box.anchor=f+o.w/2,this.box.visualAxis=l+o.h/2,this.ports["body.left"]={x:this.box.anchor-o.w/2,y:this.box.visualAxis},this.ports["body.right"]={x:this.box.anchor+o.w/2,y:this.box.visualAxis},this.ports.dot={x:this.box.w,y:l+o.h*.64},this.octave>0){for(let y=0;y<s;y++)this.upperOctaveDotY.push(l-i-this.octaveDotRadius-y*a);return}if(this.octave>=0)return;let g=s*this.octaveDotRadius*2+(s-1)*i,d={below:{order:100,gap:i,height:g,place:y=>{for(let x=0;x<s;x++)this.lowerOctaveDotY.push(y+this.octaveDotRadius+x*a)}},paint:y=>{for(let x of this.lowerOctaveDotY)y.drawCircle(this.box.x+this.box.anchor,this.box.y+x,this.octaveDotRadius,{fill:n})}};this.decorations.push(d)}finalizeLayout(){this.ports.lyric={x:this.box.anchor,y:this.box.h}}paint(t){let e=this.ast.color;for(let o of this.accidentals)jt(t,o,this.box,e);let n=fi[this.name]??this.name;n&&t.drawText(n,this.box.x+this.box.anchor,this.box.y+this.numberY,this.numberStyle);for(let o of this.upperOctaveDotY)t.drawCircle(this.box.x+this.box.anchor,this.box.y+o,this.octaveDotRadius,{fill:e})}onTimeState(t){let e=t.keySignature;if(this.playbackState={bpm:t.bpm,velocity:t.velocity},this.resolvedMidi=Ue(this.name,this.acc,this.octave,e),this.transposeDiatonic=Eo(this.name,this.acc,this.octave,e),this.name>="0"&&this.name<="9")(this.name==="0"||this.name>="8")&&(this.octave=0,this.acc="");else{let n=Ke(this.name,this.acc,this.octave,e);n&&(this.name=n.renderName,this.acc=n.renderAcc,this.octave=n.renderOctave)}}emitPlayback(t){if(this.resolvedMidi===null||t.end.compare(t.start)<=0)return;let e=t.nextNoteId();t.emit({kind:"note-on",at:t.start,noteId:e,midi:this.resolvedMidi,velocity:this.playbackState?.velocity??_t,transpose:this.transposeDiatonic}),t.emit({kind:"note-off",at:t.end,noteId:e})}};var ie=class r extends L{contents=[];belows=[];size;get side(){return this.constructor.side}get children(){return this.belows.length?[...this.contents,...this.belows]:this.contents}constructor(t,e,n,o=null){super(t,o),this.size=n.fontSize;for(let[,s]of e){if(s instanceof V){this.addContent(s,this.side,n);continue}let i=n.parseArgWithType(s.valueSpan,"content",t.start);i!==null&&this.addContent(i,this.side,n)}}labelable(){return this.children.some(L.findLabelable)?this:null}addContent(t,e,n){return this.contents.length===0&&(e="above"),t instanceof r?this.flatten(t,e,n):((e==="above"?this.contents:this.belows).push(t),t.parent=this,this.growSpan(t.sourceSpan),this)}growSpan(t){this.sourceSpan.start=Math.min(this.sourceSpan.start,t.start),this.sourceSpan.end=Math.max(this.sourceSpan.end,t.end)}loweringEnter(t,e){let n=[];return t.isolateFromLoweringGroups(()=>{for(let o of this.children){let[s,...i]=t.trackedEvents(o,new M,e).flat();if(!s||i.length>0||!R(s))throw new S("E_UP_INVALID_CHILD","@up \u7684\u6BCF\u4E2A\u53C2\u6570\u5FC5\u987B\u6070\u597D\u4EA7\u751F\u4E00\u4E2A\u53EF\u89C1 Temporal\uFF0C\u4E14\u4E0D\u80FD\u5305\u542B\u591A\u58F0\u90E8\u7ED3\u6784",o.sourceSpan);n.push(s)}}),[new un(this,n)]}toString(t){let e=this.contents.map(o=>o.toString(t));return this.belows.length===0?`@up(${e.join(", ")})`:`@down(${[e.length>1?`@up(${e.join(", ")})`:e[0],...this.belows.map(o=>o.toString(t))].join(", ")})`}flatten(t,e,n){let o=t.sourceSpan.start<this.sourceSpan.start?t:this,s=o===t?this:t,[i,...a]=s.contents,c=i?[i]:[],l=[...o.contents,...e==="above"?c:[],...a],h=[...o.belows,...e==="below"?c:[],...s.belows];this.contents=l,this.belows=h;for(let f of this.children)f.parent=this;this.growSpan(t.sourceSpan),t.contents=[],t.belows=[];let u=n.labelableNodes.indexOf(t);return u>=0&&n.labelableNodes.splice(u,1),this}static desugar(t,e,n){let o=e[n++];if(!(o.kind==="sugar"&&o.data===this))return null;let s=this.side==="above"?"@up":"@down",i=t.nodes.length-1;for(;i>=0&&t.nodes[i]instanceof H;)i--;if(i<0)throw new S("E_FOLD_NO_TARGET",`${s}\u8BED\u6CD5\u7CD6\u9519\u8BEF: \u5DE6\u8FB9\u6CA1\u6709\u627E\u5230\u53EF\u53E0\u52A0\u7684\u76EE\u6807`,o.span);let a=t.nodes[i],c=i;if(a instanceof q){let u=a,f=u.target;for(;f&&!t.nodes.includes(f);)f=f.parent;for(let g=i-1;g>=0;g--)if(t.nodes[g]===f){a=new $({start:f.sourceSpan.start,end:u.sourceSpan.end},t.nodes.slice(g,i+1),null),c=g;break}}let l=a instanceof r?a:new this(o.span,new Map,t).addContent(a,"above",t),h=t.nodes;t.nodes=[],t.makeNodes(e,n);for(let u=0;u<t.nodes.length;u++){let f=t.nodes[u];if(f instanceof H)continue;let g=f instanceof r?f.flatten(l,this.side,t):l.addContent(f,this.side,t);for(h.length=c,h.push(g);++u<t.nodes.length;)h.push(t.nodes[u]);return t.nodes=h,t.labelableNodes.push(g.labelable()),e.length}throw new S("E_FOLD_NO_TARGET",`${s}\u8BED\u6CD5\u7CD6\u9519\u8BEF: \u53F3\u8FB9\u6CA1\u6709\u627E\u5230\u53EF\u53E0\u52A0\u7684\u76EE\u6807`,o.span)}},ln=class r extends ie{static side="above";static def={name:["up"],description:"\u628A\u540C\u4E00\u65F6\u95F4\u4F4D\u7F6E\u7684\u53EF\u89C1\u5BF9\u8C61\u5411\u4E0A\u5806\u53E0",example:`@up(content1, content2, ...)
|
|
76
|
+
\u8BED\u6CD5\u7CD6: ^
|
|
77
|
+
{content1} ^ {content2} ^ ...
|
|
78
|
+
\u7B2C\u4E00\u4E2A\u53C2\u6570\u662F\u5BBF\u4E3B\uFF0C\u5176\u4F59\u4F9D\u6B21\u53E0\u5728\u5B83\u7684\u4E0A\u65B9\uFF0C\u5E38\u7528\u4E8E\u548C\u5F26\u3001\u53D8\u901F\u8BB0\u53F7\u3001\u97F3\u7B26\u6CE8\u91CA\u3002
|
|
79
|
+
\u5168\u4F53\u6210\u5458\u6298\u53E0\u6210\u4E00\u4E2A\u4E8B\u4EF6\u3001\u5171\u4EAB\u5BBF\u4E3B\u7684\u65F6\u503C\uFF1B\u9700\u8981\u5404\u81EA\u72EC\u7ACB\u65F6\u503C\u7684\u5E76\u884C\u5206\u652F\u8BF7\u7528 & / @stack\u3002
|
|
80
|
+
`,allowExtraArgs:!0,extraArgType:"content",args:[]};static deSugarAtom(t,e,n){if(t[e]!=="^")return null;let o={kind:"sugar",data:r,span:{start:e,end:e+1}};return{next:e+1,node:o}}static deSugarRelation(t,e,n){return r.desugar(t,e,n)}},hn=class r extends ie{static side="below";static def={name:["down"],description:"\u628A\u540C\u4E00\u65F6\u95F4\u4F4D\u7F6E\u7684\u53EF\u89C1\u5BF9\u8C61\u5411\u4E0B\u5806\u53E0",example:`@down(content1, content2, ...)
|
|
81
|
+
\u8BED\u6CD5\u7CD6: _
|
|
82
|
+
{content1} _ {content2} _ ...
|
|
83
|
+
\u7B2C\u4E00\u4E2A\u53C2\u6570\u662F\u5BBF\u4E3B\uFF0C\u5176\u4F59\u4F9D\u6B21\u53E0\u5728\u5B83\u7684\u4E0B\u65B9\uFF0C\u5E38\u7528\u4E8E\u529B\u5EA6\u8BB0\u53F7\u7B49\u5199\u5728\u97F3\u7B26\u4E0B\u9762\u7684\u6807\u8BB0\u3002
|
|
84
|
+
\u4E0E ^ \u6DF7\u5199\u65F6\u5168\u90E8\u7ED1\u5230\u540C\u4E00\u4E2A\u5BBF\u4E3B\uFF1A1^2_3 \u8868\u793A 2 \u5728\u4E0A\u30013 \u5728\u4E0B\u3002
|
|
85
|
+
`,allowExtraArgs:!0,extraArgType:"content",args:[]};static deSugarAtom(t,e,n){if(t[e]!=="_")return null;let o={kind:"sugar",data:r,span:{start:e,end:e+1}};return{next:e+1,node:o}}static deSugarRelation(t,e,n){return r.desugar(t,e,n)}},Po=ln,Do=hn,un=class extends D{members;aboveCount;offsets=[];constructor(t,e){super(),this.ast=t,this.members=e,this.aboveCount=t.contents.length;let n=e.find(s=>!s.T.isZero());n&&this.T.copyFrom(n.T),this.mergeKey=Q,this.initLayoutBox();let o=e[0]?.addon;o&&(this.addon={...o});for(let s of e)s.mergeKey===W&&(this.mergeKey=W),s.addon=void 0,s.foldedInto=this}onTimeState(t){for(let e=this.members.length-1;e>=0;e--){let n=this.members[e];n.T.isZero()||n.T.copyFrom(this.T),n.t.copyFrom(this.t),n.track=this.track,n.layoutLine=this.layoutLine,n.onTimeState?.(t)}}emitPlayback(t){for(let e=this.members.length-1;e>=0;e--)t.play(this.members[e])}prepareLayout(t){this.offsets.length=0,this.addon&&this.members[0]&&(this.members[0].addon=this.addon,this.addon=void 0);for(let h of this.members)at(h,t);let e=this.members[0];if(!e){this.box.w=this.box.h=0,this.box.anchor=this.box.visualAxis=0;return}let n=e.box.anchor,o=this.ast.size*.12;for(let h of this.members)this.offsets.push({x:n-h.box.anchor,y:0});let s=0;for(let h=1;h<this.aboveCount;h++)s-=o+this.members[h].box.h,this.offsets[h].y=s;let i=e.box.h;for(let h=this.aboveCount;h<this.members.length;h++)i+=o,this.offsets[h].y=i,i+=this.members[h].box.h;for(let h of this.offsets)h.y-=s;this.box.w=e.box.w,this.box.h=i-s,this.box.anchor=n,this.box.visualAxis=e.box.visualAxis-s;let a=this.offsets[0];for(let h in e.ports){let u=e.ports[h];this.ports[h]={x:u.x,y:a.y+u.y}}this.ports["body.left"]??={x:0,y:this.box.visualAxis},this.ports["body.right"]??={x:e.box.w,y:this.box.visualAxis};let c=this.aboveCount-1,l=this.offsets[c];this.ports["tie.top"]={x:n,y:l.y+(this.members[c].ports["tie.top"]?.y??0)}}onPlaced(){for(let t=0;t<this.members.length;t++){let e=this.offsets[t],n=this.members[t];n.box.x=this.box.x+e.x,n.box.y=this.box.y+e.y,n.onPlaced?.()}}paint(t){for(let e of this.members){e.paint(t);for(let n of e.decorations)n.paint(t)}}};var Lt=r=>({value:r,unit:"px"}),fn=16,Fo={fontSize:fn,textAlign:"center",fill:"#606060"};function pi(r,t,e){let n=r.lastIndexOf("1");return r.replace(/1/g,(o,s)=>String(s===n?e:t))}var pn=class{sourceSpan;pattern;marginBottom;layer="foreground";constructor(t,e,n){this.sourceSpan=t,this.pattern=e,this.marginBottom=n}createGeometry(t){let e=t.pages.map((n,o)=>{let s=pi(this.pattern,o+1,t.pages.length),{w:i,h:a,baseline:c}=t.textMeasurer.measureText(s,Fo),l=n.y+n.h-this.marginBottom/2;return{text:s,x:n.x+n.w/2,y:l-a/2+c,w:i,h:a,baseline:c}});return{regions:e.map(({x:n,y:o,w:s,h:i,baseline:a})=>({x:n-s/2,y:o-a,w:s,h:i})),paint(n){for(let o of e)n.drawText(o.text,o.x,o.y,Fo)}}}},mn=class extends L{static def={name:["page"],description:"\u8BBE\u7F6E\u6587\u6863\u9875\u9762\u5C3A\u5BF8\u3001\u8FB9\u8DDD\u3001\u6700\u5C0F\u8C31\u9762\u884C\u95F4\u8DDD\u548C\u9875\u7801",example:'@page(width=794px, height=1123px, top=48px, bottom=48px, left=40px, right=40px, gap=1em, numbering="1/1")',allowExtraArgs:!1,args:[{name:"width",type:"length",default:Lt(U.width)},{name:"height",type:"length",default:Lt(0)},{name:"top",type:"length",default:Lt(U.marginTop)},{name:"bottom",type:"length",default:Lt(U.marginBottom)},{name:"left",type:"length",default:Lt(U.marginLeft)},{name:"right",type:"length",default:Lt(U.marginRight)},{name:"gap",type:"length",default:{value:1,unit:"em"}},{name:"numbering",type:"string",default:""}]};config;numbering="";constructor(t,e,n,o=null){if(super(t,o),n.scopeDepth!==0){n.diagnostics.push(new C("W_PAGE_NOT_TOP_LEVEL","@page \u53EA\u80FD\u5728\u6587\u6863\u9876\u5C42\u58F0\u660E\uFF1B\u5F53\u524D\u58F0\u660E\u5DF2\u5FFD\u7565",t)),this.config=null;return}if(n.documentDeclarations.page){n.diagnostics.push(new C("W_DUPLICATE_PAGE","\u6587\u6863\u53EA\u80FD\u58F0\u660E\u4E00\u4E2A @page\uFF1B\u540E\u7EED\u58F0\u660E\u5DF2\u5FFD\u7565",t)),this.config=null;return}n.documentDeclarations.page=!0;let s=this.getArgValue(e,n),i=s.pop(),[a,c,l,h,u,f,g]=s.map(d=>n.length2px(d));if(!Number.isFinite(a)||a<=0)throw E.error.InvalidPageConfig("@page \u7684 width \u5FC5\u987B\u662F\u6B63\u6709\u9650\u957F\u5EA6",t);if(!Number.isFinite(c)||c<0)throw E.error.InvalidPageConfig("@page \u7684 height \u5FC5\u987B\u662F\u975E\u8D1F\u6709\u9650\u957F\u5EA6\uFF1B0 \u8868\u793A\u4E0D\u5206\u9875",t);if([l,h,u,f,g].some(d=>!Number.isFinite(d)||d<0))throw E.error.InvalidPageConfig("@page \u7684\u8FB9\u8DDD\u548C gap \u5FC5\u987B\u662F\u975E\u8D1F\u6709\u9650\u957F\u5EA6",t);if(u+f>=a)throw E.error.InvalidPageConfig("@page \u7684\u5DE6\u53F3\u8FB9\u8DDD\u6CA1\u6709\u7559\u4E0B\u53EF\u7528\u5185\u5BB9\u5BBD\u5EA6",t);if(c>0&&l+h>=c)throw E.error.InvalidPageConfig("@page \u7684\u4E0A\u4E0B\u8FB9\u8DDD\u6CA1\u6709\u7559\u4E0B\u53EF\u7528\u5185\u5BB9\u9AD8\u5EA6",t);if(i&&h<fn)throw E.error.InvalidPageConfig(`@page \u7684 bottom \u81F3\u5C11\u9700\u8981 ${fn}px \u624D\u80FD\u653E\u4E0B\u9875\u7801`,t);this.config=Ct({width:a,height:c,marginTop:l,marginBottom:h,marginLeft:u,marginRight:f,lineGap:g}),this.numbering=i}loweringEnter(t){return!t||!this.config?[]:(t.setPageConfig(this.config),this.numbering&&t.addAttachment(new pn(this.sourceSpan,this.numbering,this.config.marginBottom)),[])}},$o=mn;var Bo=.4,mi=(r,t,e)=>r.top-e*Bo-t.bottom,di=(r,t)=>{let e=t*Bo,n=[],o=0;for(let s of r){if(!s){n.push(null);continue}let i=o-s.bottom;n.push({offset:i,extent:s}),o=i+s.top-e}return n},gi={laneKey:"stack",measure:di,place:mi},dn=class r extends L{static def={name:["stack"],description:"\u4E34\u65F6\u591A\u58F0\u90E8",example:`@stack(content1, content2, ...)
|
|
86
|
+
\u8BED\u6CD5\u7CD6: &
|
|
87
|
+
{content1} & {content2} & ...
|
|
88
|
+
\u8868\u793Acontent1\u548Ccontent2\u5728\u65F6\u95F4\u4E0A\u5B8C\u5168\u91CD\u53E0\uFF0C\u901A\u5E38\u7528\u4E8E\u548C\u58F0\u7B49\u9700\u8981\u5BF9\u9F50\u7684\u573A\u666F\u3002\u53EF\u4EE5\u6709\u4EFB\u610F\u591A\u4E2A\u53C2\u6570\uFF0C\u81F3\u5C11\u9700\u8981\u4E24\u4E2A\u53C2\u6570\u3002
|
|
89
|
+
`,allowExtraArgs:!0,extraArgType:"content",args:[]};static deSugarAtom(t,e,n){if(t[e]==="&"){let o={kind:"sugar",data:r,span:{start:e,end:e+1}};return{next:e+1,node:o}}return null}static deSugarRelation(t,e,n){let o=e[n++];if(!(o.kind==="sugar"&&o.data===r))return null;let s=t.nodes.length-1;for(;s>=0&&t.nodes[s]instanceof H;s--);let i=s>=0?t.nodes[s]:null;if(i===null)throw new S("E_STACK_NO_TARGET","@stack\u8BED\u6CD5\u7CD6\u9519\u8BEF: \u5DE6\u8FB9\u6CA1\u6709\u627E\u5230\u53EF\u53E0\u52A0\u7684\u76EE\u6807",o.span);let a=s;if(i instanceof q){let h=i,u=h.target;for(;u&&!t.nodes.includes(u);)u=u.parent;for(let f=s-1;f>=0;f--)if(t.nodes[f]===u){i=new $({start:u.sourceSpan.start,end:h.sourceSpan.end},t.nodes.slice(f,s+1),null),a=f;break}}let c=i instanceof r?i:new r(o.span,new Map,t).addContent(i),l=t.nodes;t.nodes=[],t.makeNodes(e,n);for(let h=0;h<t.nodes.length;h++){let u=t.nodes[h];if(!(u instanceof H)){for(c.addContent(u),l.length=a,l.push(c);++h<t.nodes.length;)l.push(t.nodes[h]);return t.nodes=l,e.length}}throw new S("E_STACK_NO_TARGET","@stack\u8BED\u6CD5\u7CD6\u9519\u8BEF: \u53F3\u8FB9\u6CA1\u6709\u627E\u5230\u53EF\u53E0\u52A0\u7684\u76EE\u6807",o.span)}contents=[];get children(){return this.contents}timeFlowModel(){return{children:this.contents,mode:"parallel",tracks:gi}}constructor(t,e,n,o=null){super(t,o);for(let[,s]of e){if(s instanceof V){this.addContent(s);continue}let i=n.parseArgWithType(s.valueSpan,"content",t.start);i!==null&&this.addContent(i)}}addContent(t){if(t instanceof r)return this.combine(t);this.contents.push(t),t.parent=this;let e=t.sourceSpan;return this.sourceSpan.start=Math.min(this.sourceSpan.start,e.start),this.sourceSpan.end=Math.max(this.sourceSpan.end,e.end),this}toString(t){return`@stack(
|
|
90
|
+
${this.contents.map(n=>n.toString(t)).join(`,
|
|
91
|
+
`).split(`
|
|
92
|
+
`).join(`
|
|
93
|
+
`)}
|
|
94
|
+
)`}combine(t){this.sourceSpan.start=Math.min(this.sourceSpan.start,t.sourceSpan.start),this.sourceSpan.end=Math.max(this.sourceSpan.end,t.sourceSpan.end);for(let e of t.contents)e.parent=this;return this.contents.push(...t.contents),t.contents.length=0,this}},zo=dn;var re=class{min=1/0;max=-1/0;add(t){t<this.min&&(this.min=t),t>this.max&&(this.max=t)}};function gn(r,t,e,n,o,s){if(!(r>0&&r<1))return;let i=1-r;s.add(i*i*i*t+3*i*i*r*e+3*i*r*r*n+r*r*r*o)}function Ho(r,t,e,n,o){o.add(r),o.add(n);let s=-r+3*t-3*e+n,i=2*(r-2*t+e),a=t-r;if(Math.abs(s)<1e-12){Math.abs(i)>1e-12&&gn(-a/i,r,t,e,n,o);return}let c=i*i-4*s*a;if(c<0)return;let l=Math.sqrt(c);gn((-i+l)/(2*s),r,t,e,n,o),gn((-i-l)/(2*s),r,t,e,n,o)}function Wo(r,t,e,n){n.add(r),n.add(e);let o=r-2*t+e;if(Math.abs(o)<1e-12)return;let s=(r-t)/o;if(!(s>0&&s<1))return;let i=1-s;n.add(i*i*r+2*i*s*t+s*s*e)}function ae(r){let t=new re,e=new re,n=0,o=0,s=0,i=0;for(let a of r){if(a.op==="Z"){n=s,o=i;continue}a.op==="C"?(Ho(n,a.cx1,a.cx2,a.x,t),Ho(o,a.cy1,a.cy2,a.y,e)):a.op==="Q"?(Wo(n,a.cx,a.x,t),Wo(o,a.cy,a.y,e)):(t.add(a.x),e.add(a.y),a.op==="M"&&(s=a.x,i=a.y)),n=a.x,o=a.y}return Number.isFinite(t.min)?{x:t.min,y:e.min,w:t.max-t.min,h:e.max-e.min}:{x:0,y:0,w:0,h:0}}function Go(r){let t=1/0,e=1/0,n=-1/0,o=-1/0,s=i=>{t=Math.min(t,i.x),e=Math.min(e,i.y),n=Math.max(n,i.x+i.w),o=Math.max(o,i.y+i.h)};for(let i of r){if(i.circle){let{cx:a,cy:c,r:l}=i.circle;s({x:a-l,y:c-l,w:2*l,h:2*l})}i.path?.length&&s(ae(i.path))}return Number.isFinite(t)?{x:t,y:e,w:Math.max(1e-9,n-t),h:Math.max(1e-9,o-e)}:{x:0,y:0,w:1e-9,h:1e-9}}function Vo(r,t,e,n,o){let s=n.x-e.x*o,i=n.y-e.y*o;for(let a of t){let c=a.style,l=c.strokeWidth===void 0?c:{...c,strokeWidth:c.strokeWidth*o};a.path&&r.drawPath(a.path,l,{x:s,y:i,scaleX:o,scaleY:o}),a.circle&&r.drawCircle(s+a.circle.cx*o,i+a.circle.cy*o,a.circle.r*o,l)}}var Yo={name:"accent",description:"\u91CD\u97F3",weight:.5,shapes:[{path:[{op:"M",x:.21413,y:.4818},{op:"L",x:8.21413,y:3.72071},{op:"L",x:.29494,y:6.92724}],style:{stroke:"#000",strokeWidth:1}}],emitPlayback:r=>r.affectFollowing((t,e)=>{for(let n of e)n.kind==="note-on"&&(n.velocity=Math.min(127,n.velocity+20))})};var Uo={name:"fermata",description:"\u5EF6\u957F\u8BB0\u53F7\uFF1A\u8986\u76D6\u533A\u95F4\u901F\u5EA6\u51CF\u534A\uFF0C\u76EE\u6807\u97F3\u5B9E\u9645\u65F6\u957F\u7FFB\u500D",weight:.6,shapes:[{path:[{op:"M",x:0,y:7.46666},{op:"C",cx1:3.65834,cy1:0,cx2:8.53611,cy2:0,x:12.19445,y:7.46666},{op:"M",x:12.19445,y:7.46666},{op:"C",cx1:8.53611,cy1:.74666,cx2:3.65833,cy2:.74666,x:0,y:7.46666}],style:{fill:"#000",stroke:"#000",strokeWidth:1}},{circle:{cx:6.09723,cy:6.26666,r:1.2},style:{fill:"#000"}}],emitPlayback:r=>{r.control(r.start,t=>t.bpmScale.div(2)),r.control(r.end,t=>t.bpmScale.mul(2))}};var Ko={name:"f",description:"\u5F3A",shapes:[{path:[{op:"M",x:6.805,y:3.24553},{op:"L",x:8.5437,y:3.24553},{op:"L",x:8.5437,y:3.89757},{op:"L",x:6.60698,y:3.89757},{op:"C",cx1:6.05169,cy1:5.7957,cx2:5.56385,cy2:7.20105,x:5.14365,y:8.11383},{op:"C",cx1:4.83447,cy1:8.76586,cx2:4.53022,cy2:9.3261,x:4.23564,y:9.79455},{op:"C",cx1:3.94108,cy1:10.26319,cx2:3.57392,cy2:10.664,x:3.13455,y:10.99733},{op:"C",cx1:2.69497,cy1:11.33542,cx2:2.17827,cy2:11.53344,x:1.58419,y:11.59615},{op:"C",cx1:1.18814,cy1:11.59615,cx2:.82592,cy2:11.46084,x:.49258,y:11.19535},{op:"C",cx1:.16419,cy1:10.92968,cx2:0,cy2:10.59161,x:0,y:10.17141},{op:"C",cx1:0,cy1:9.90098,cx2:.07735,cy2:9.64006,x:.2366,y:9.38407},{op:"C",cx1:.39605,cy1:9.12808,cx2:.65204,cy2:8.97831,x:1.00951,y:8.92531},{op:"C",cx1:1.24611,cy1:8.92531,cx2:1.44887,cy2:9.00266,x:1.62771,y:9.15716},{op:"C",cx1:1.80634,cy1:9.31643,cx2:1.89813,cy2:9.50494,x:1.89813,y:9.73186},{op:"C",cx1:1.89813,cy1:9.88637,cx2:1.85936,cy2:10.01197,x:1.78695,y:10.10852},{op:"C",cx1:1.71455,cy1:10.21001,cx2:1.59387,cy2:10.33066,x:1.43443,y:10.48043},{op:"C",cx1:1.27497,cy1:10.63017,cx2:1.16874,cy2:10.76055,x:1.12521,y:10.86203},{op:"C",cx1:1.15905,cy1:10.9924,cx2:1.23639,cy2:11.06006,x:1.34757,y:11.06006},{op:"C",cx1:1.74837,cy1:11.06006,cx2:2.10584,cy2:10.81377,x:2.4196,y:10.32118},{op:"C",cx1:2.73355,cy1:9.83335,cx2:2.99447,cy2:9.26339,x:3.2022,y:8.61136},{op:"C",cx1:3.40971,cy1:7.95932,cx2:3.64651,cy2:7.10927,x:3.92168,y:6.06119},{op:"C",cx1:4.19706,cy1:5.00836,cx2:4.40952,cy2:4.28867,x:4.54959,y:3.89757},{op:"L",x:3.24552,y:3.89757},{op:"L",x:3.24552,y:3.24553},{op:"L",x:4.82496,y:3.24553},{op:"C",cx1:5.05187,cy1:2.68054,cx2:5.36582,cy2:2.15393,x:5.77156,y:1.6566},{op:"C",cx1:6.18204,cy1:1.15907,cx2:6.65546,cy2:.76302,x:7.19155,y:.45876},{op:"C",cx1:7.72766,cy1:.1545,cx2:8.29265,cy2:0,x:8.88176,y:0},{op:"C",cx1:9.36486,cy1:0,cx2:9.67384,cy2:.14975,x:9.85268,y:.34777},{op:"C",cx1:10.03131,cy1:.5458,cx2:10.14727,cy2:.83541,x:10.20998,y:.97073},{op:"C",cx1:10.20998,cy1:1.3282,cx2:10.10374,cy2:1.68548,x:9.89602,y:2.038},{op:"C",cx1:9.68851,cy1:2.39072,cx2:9.38899,cy2:2.57905,x:9.00264,y:2.59349},{op:"C",cx1:8.9544,cy1:2.54522,cx2:8.86733,cy2:2.49695,x:8.74666,y:2.44373},{op:"C",cx1:8.51006,cy1:2.33275,cx2:8.3892,cy2:2.24571,x:8.35061,y:1.94145},{op:"C",cx1:8.39412,cy1:1.49714,cx2:8.59689,cy2:1.19762,x:8.95912,y:1.04807},{op:"C",cx1:9.19573,cy1:.9901,cx2:9.3166,cy2:.89831,x:9.3166,y:.77269},{op:"C",cx1:9.3166,cy1:.5988,cx2:9.17159,cy2:.49257,x:8.88177,y:.45399},{op:"C",cx1:8.39416,cy1:.45399,cx2:7.95931,cy2:.79208,x:7.57793,y:1.4633},{op:"C",cx1:7.32192,cy1:1.84491,cx2:7.06593,cy2:2.43897,x:6.805,y:3.24551},{op:"L",x:6.805,y:3.24551},{op:"L",x:6.805,y:3.24553},{op:"Z"}],style:{fill:"#000"}}],onTimeState:r=>{r.velocity=96}};function ce(r){return(t,e)=>{let n=new Map;for(let i of e)i.kind==="note-off"&&n.set(i.noteId,i);let o=new Set,s=[];for(let i of e){if(i.kind!=="note-on"||!i.transpose)continue;let a=n.get(i.noteId);if(!a)continue;let c=a.at.clone().sub(i.at),l=t.stateAt(i.at).effectiveBpm,h=r.repeat?xi(r.body,c.toNumber(),l):r.body,u=c.div(h.length);o.add(i),o.add(a);for(let f=0;f<h.length;f++){let g=h[f],d=t.nextNoteId(),y=i.at.clone().add(u.clone().mul(f)),x=i.order+f/h.length,p={...i,at:y,noteId:d,order:x,midi:g===0?i.midi:i.transpose(g),transpose:m=>i.transpose(g+m),origins:[...i.origins],sourceSpans:i.sourceSpans.map(m=>({...m}))};s.push(p,{...a,at:y.clone().add(u),noteId:d,order:x,origins:[...a.origins]})}}return[...e.filter(i=>!o.has(i)),...s]}}function xi(r,t,e){let n=Math.min(480,Math.max(60,e))/e,o=Math.floor(256/r.length),s=Math.min(o,Math.max(1,Math.round(t*8*n/r.length))),i=[];for(let a=0;a<s;a++)i.push(...r);return i}var jo={name:"mordent",description:"\u6CE2\u97F3\uFF1A\u672C\u97F3\u3001\u8C03\u5185\u4E0A\u65B9\u4E8C\u5EA6\u3001\u672C\u97F3",weight:.55,shapes:[{path:[{op:"M",x:3.12541,y:.06003},{op:"C",cx1:3.18541,cy1:.03003,cx2:3.30541,cy2:3e-5,x:3.36541,y:3e-5},{op:"C",cx1:3.66541,cy1:3e-5,cx2:3.63541,cy2:-.02997,x:5.25541,y:1.95003},{op:"L",x:6.78541,y:3.78003},{op:"C",cx1:6.81541,cy1:3.78003,cx2:7.35541,cy2:2.94003,x:8.01541,y:1.95003},{op:"C",cx1:9.15541,cy1:.27003,cx2:9.24541,cy2:.12003,x:9.36541,y:.06003},{op:"C",cx1:9.42541,cy1:.03003,cx2:9.54541,cy2:3e-5,x:9.60541,y:3e-5},{op:"C",cx1:9.90541,cy1:3e-5,cx2:9.87541,cy2:-.02997,x:11.49541,y:1.95003},{op:"L",x:13.02541,y:3.78003},{op:"L",x:13.50541,y:3.09003},{op:"C",cx1:14.01541,cy1:2.31003,cx2:14.04541,cy2:2.25003,x:14.19541,y:2.19003},{op:"C",cx1:14.61541,cy1:2.01003,cx2:15.06541,cy2:2.34003,x:15.00541,y:2.79003},{op:"C",cx1:14.97541,cy1:2.91003,cx2:14.70541,cy2:3.30003,x:13.50541,y:5.16003},{op:"C",cx1:12.12541,cy1:7.23003,cx2:12.00541,cy2:7.38003,x:11.88541,y:7.44003},{op:"C",cx1:11.82541,cy1:7.47003,cx2:11.70541,cy2:7.50003,x:11.64541,y:7.50003},{op:"C",cx1:11.34541,cy1:7.50003,cx2:11.37541,cy2:7.53003,x:9.75541,y:5.55003},{op:"L",x:8.22541,y:3.72003},{op:"C",cx1:8.19541,cy1:3.72003,cx2:7.65541,cy2:4.56003,x:6.99541,y:5.55003},{op:"C",cx1:5.85541,cy1:7.23003,cx2:5.76541,cy2:7.38003,x:5.64541,y:7.44003},{op:"C",cx1:5.58541,cy1:7.47003,cx2:5.46541,cy2:7.50003,x:5.40541,y:7.50003},{op:"C",cx1:5.10541,cy1:7.50003,cx2:5.13541,cy2:7.53003,x:3.51541,y:5.55003},{op:"L",x:1.98541,y:3.72003},{op:"L",x:1.50541,y:4.41003},{op:"C",cx1:.99541,cy1:5.19003,cx2:.96541,cy2:5.25003,x:.81541,y:5.31003},{op:"C",cx1:.39541,cy1:5.49003,cx2:-.05459,cy2:5.16003,x:.00541,y:4.71004},{op:"C",cx1:.03541,cy1:4.59004,cx2:.30541,cy2:4.20004,x:1.50541,y:2.34004},{op:"C",cx1:2.88541,cy1:.27004,cx2:3.00541,cy2:.12004,x:3.12541,y:.06004},{op:"L",x:3.12541,y:.06003},{op:"Z"}],style:{fill:"#000"}}],emitPlayback:r=>r.affectFollowing(ce({body:[0,1,0]}))};var Zo={name:"p",description:"\u5F31",shapes:[{path:[{op:"M",x:8.93561,y:.90391},{op:"C",cx1:8.39321,cy1:.90391,cx2:7.93492,cy2:1.2075,x:7.56045,y:1.81442},{op:"C",cx1:7.19233,cy1:2.42134,cx2:6.91466,cy2:3.11209,x:6.72743,y:3.88032},{op:"C",cx1:6.5402,cy1:4.64856,cx2:6.45002,cy2:5.23617,x:6.45002,y:5.63655},{op:"C",cx1:6.45002,cy1:6.32093,cx2:6.66288,cy2:6.66316,x:7.0892,y:6.66316},{op:"C",cx1:7.4959,cy1:6.66316,cx2:7.88333,cy2:6.34661,x:8.2578,y:5.70743},{op:"C",cx1:8.63861,cy1:5.06825,cx2:8.94857,cy2:4.35158,x:9.18735,y:3.54473},{op:"C",cx1:9.42639,cy1:2.73762,cx2:9.54885,cy2:2.15001,x:9.54885,y:1.77554},{op:"C",cx1:9.54885,cy1:1.19453,cx2:9.34231,cy2:.9039,x:8.93561,y:.9039},{op:"L",x:8.93561,y:.9039},{op:"L",x:8.93561,y:.9039},{op:"L",x:8.93561,y:.90391},{op:"Z"},{op:"M",x:2.53741,y:3.99669},{op:"L",x:1.90457,y:3.99669},{op:"C",cx1:2.49853,cy1:2.80215,cx2:3.08615,cy2:1.83373,x:3.66714,y:1.1041},{op:"C",cx1:4.25476,cy1:.36813,cx2:4.97777,cy2:1e-5,x:5.84306,y:1e-5},{op:"C",cx1:6.03027,cy1:1e-5,cx2:6.21089,cy2:.11637,x:6.39177,y:.34882},{op:"C",cx1:6.57271,cy1:.57466,cx2:6.66284,cy2:.83938,x:6.66284,y:1.13636},{op:"C",cx1:7.12775,cy1:.87825,cx2:7.5797,cy2:.60693,x:8.08986,y:.36812},{op:"C",cx1:8.60631,cy1:.12932,cx2:9.01941,cy2:0,x:9.49094,y:0},{op:"C",cx1:10.28506,cy1:0,cx2:10.85948,cy2:.25202,x:11.22125,y:.76189},{op:"C",cx1:11.58911,cy1:1.26568,cx2:11.76999,cy2:1.93051,x:11.76999,y:2.75058},{op:"C",cx1:11.76999,cy1:3.26045,cx2:11.66024,cy2:3.79649,x:11.44707,y:4.35819},{op:"C",cx1:11.23395,cy1:4.91989,cx2:10.93697,cy2:5.43636,x:10.55616,y:5.91423},{op:"C",cx1:10.17535,cy1:6.39186,cx2:9.73609,cy2:6.77925,x:9.23261,y:7.07623},{op:"C",cx1:8.72907,cy1:7.36686,cx2:8.19962,cy2:7.51522,x:7.64428,y:7.51522},{op:"C",cx1:7.32797,cy1:7.51522,cx2:7.0117,cy2:7.42504,x:6.68878,y:7.24416},{op:"C",cx1:6.36591,cy1:7.06327,cx2:6.10119,cy2:6.83743,x:5.89463,y:6.55976},{op:"L",x:4.55177,y:10.39486},{op:"C",cx1:4.59038,cy1:10.39486,cx2:4.57108,cy2:10.42712,x:4.49359,y:10.49823},{op:"C",cx1:4.55177,cy1:10.71115,cx2:4.66151,cy2:10.82087,x:4.80987,y:10.82087},{op:"L",x:6.13343,y:10.82087},{op:"L",x:6.13343,y:11.64096},{op:"L",x:0,y:11.64096},{op:"L",x:0,y:10.82089},{op:"L",x:1.3495,y:10.82089},{op:"C",cx1:1.63987,cy1:10.82089,cx2:1.95616,cy2:10.60139,x:2.00799,y:10.29146},{op:"L",x:5.15868,y:1.45926},{op:"L",x:5.15868,y:1.29795},{op:"C",cx1:5.15868,cy1:1.05888,cx2:5.01667,cy2:.90391,x:4.91988,y:.90391},{op:"C",cx1:4.69378,cy1:.90391,cx2:4.46132,cy2:1.02662,x:4.21591,y:1.27203},{op:"C",cx1:3.97076,cy1:1.51744,cx2:3.7383,cy2:1.81442,x:3.51881,y:2.16297},{op:"C",cx1:3.30566,cy1:2.51152,cx2:3.10547,cy2:2.86033,x:2.93119,y:3.20888},{op:"L",x:2.53743,y:3.99669},{op:"L",x:2.53743,y:3.99669},{op:"L",x:2.53741,y:3.99669},{op:"Z"}],style:{fill:"#000"}}],onTimeState:r=>{r.velocity=48}};var qo={name:"tr",description:"\u98A4\u97F3\uFF1A\u672C\u97F3\u4E0E\u8C03\u5185\u4E0A\u65B9\u4E8C\u5EA6\u4EA4\u66FF",shapes:[{path:[{op:"M",x:3.17992,y:5.46383},{op:"L",x:3.61827,y:3.91711},{op:"C",cx1:3.10024,cy1:3.49862,cx2:2.52947,cy2:3.29304,x:1.90541,y:3.29304},{op:"C",cx1:1.50051,cy1:3.29304,cx2:1.18833,cy2:3.40589,x:.95611,y:3.63812},{op:"C",cx1:.72361,cy1:3.87061,cx2:.59743,cy2:4.14281,x:.57105,y:4.46152},{op:"C",cx1:.57105,cy1:4.91944,cx2:.71707,cy2:5.25147,x:1.00913,y:5.47036},{op:"C",cx1:1.30118,cy1:5.68954,cx2:1.61988,cy2:5.79586,x:1.95843,y:5.79586},{op:"C",cx1:1.9916,cy1:5.79586,cx2:2.03157,cy2:5.8157,x:2.06475,y:5.84888},{op:"C",cx1:2.24394,cy1:5.82904,cx2:2.61568,cy2:5.69632,x:3.17992,y:5.46383},{op:"L",x:3.17992,y:5.46383},{op:"L",x:3.17992,y:5.46383},{op:"Z"},{op:"M",x:6.579,y:9.87204},{op:"L",x:8.40472,y:3.75096},{op:"C",cx1:8.40472,cy1:3.59162,cx2:8.35167,cy2:3.51193,x:8.23884,y:3.51193},{op:"C",cx1:7.98647,cy1:3.51193,cx2:7.4554,cy2:3.77761,x:6.63883,y:4.3152},{op:"C",cx1:5.82223,cy1:4.84655,cx2:5.37735,cy2:5.15845,x:5.30448,y:5.25145},{op:"C",cx1:5.33764,cy1:5.21147,cx2:5.39068,cy2:5.15845,x:5.46383,y:5.0853},{op:"C",cx1:6.13441,cy1:6.06127,cx2:6.47294,cy2:6.98417,x:6.47294,y:7.86061},{op:"C",cx1:6.41313,cy1:8.53088,cx2:6.18062,cy2:9.12181,x:5.7692,y:9.61968},{op:"C",cx1:5.3643,cy1:10.11758,cx2:4.85308,cy2:10.3634,x:4.24233,y:10.3634},{op:"C",cx1:3.71778,cy1:10.3634,cx2:3.25306,cy2:10.23719,x:2.83483,y:9.99138},{op:"C",cx1:2.42314,cy1:9.74586,cx2:2.20396,cy2:9.39396,x:2.17759,y:8.92271},{op:"C",cx1:2.21077,cy1:8.80986,cx2:2.23061,cy2:8.66384,x:2.23061,y:8.48436},{op:"L",x:2.85469,y:6.0944},{op:"C",cx1:2.58903,cy1:6.2339,cx2:2.21729,cy2:6.30702,x:1.73924,y:6.30702},{op:"C",cx1:1.22829,cy1:6.2804,cx2:.81007,cy2:6.1012,x:.48458,y:5.76917},{op:"C",cx1:.15935,cy1:5.43065,cx2:0,cy2:4.97926,x:0,y:4.4082},{op:"C",cx1:.03318,cy1:3.89045,cx2:.20586,cy2:3.46543,x:.53107,y:3.13369},{op:"C",cx1:.8563,cy1:2.80166,cx2:1.32782,cy2:2.63579,x:1.95843,y:2.63579},{op:"C",cx1:2.55585,cy1:2.63579,cx2:3.17992,cy2:2.87481,x:3.83716,y:3.34606},{op:"L",x:4.89277,y:0},{op:"L",x:6.85119,y:0},{op:"L",x:5.41053,y:4.51453},{op:"C",cx1:6.28694,cy1:3.83064,cx2:7.02389,cy2:3.34606,x:7.62128,y:3.06054},{op:"C",cx1:8.21899,cy1:2.77502,cx2:8.86943,cy2:2.63579,x:9.57321,y:2.63579},{op:"C",cx1:10.05773,cy1:2.63579,cx2:10.30358,cy2:2.83484,x:10.30358,y:3.23974},{op:"C",cx1:10.30358,cy1:3.44559,cx2:10.17738,cy2:3.89046,x:10.09093,y:4.18931},{op:"C",cx1:10.7283,cy1:3.15354,cx2:11.45195,cy2:2.63579,x:12.26199,y:2.63579},{op:"C",cx1:12.6272,cy1:2.63579,cx2:12.91925,cy2:2.76849,x:13.14497,y:3.03417},{op:"C",cx1:13.37717,cy1:3.29957,cx2:13.49001,cy2:3.61175,x:13.49001,y:3.97014},{op:"C",cx1:13.49001,cy1:4.62739,cx2:13.09844,cy2:5.03228,x:12.53419,y:5.03228},{op:"C",cx1:12.16899,cy1:5.03228,cx2:11.85709,cy2:4.79327,x:11.80382,y:4.29536},{op:"C",cx1:11.89029,cy1:3.91031,cx2:11.98982,cy2:3.55191,x:11.98982,y:3.34606},{op:"C",cx1:11.98982,cy1:3.27291,cx2:11.94329,cy2:3.23973,x:11.85709,y:3.23973},{op:"C",cx1:11.74403,cy1:3.23973,cx2:11.53162,cy2:3.34606,x:11.20637,y:3.56522},{op:"C",cx1:10.90752,cy1:3.7708,cx2:10.61547,cy2:4.11615,x:10.31666,y:4.61405},{op:"C",cx1:10.01808,cy1:5.11195,cx2:9.77253,cy2:5.69632,x:9.57321,y:6.36662},{op:"L",x:8.45798,y:9.87203},{op:"L",x:6.57899,y:9.87203},{op:"L",x:6.57899,y:9.87203},{op:"L",x:6.579,y:9.87204},{op:"Z"},{op:"M",x:5.05893,y:5.62971},{op:"L",x:3.94348,y:8.92274},{op:"C",cx1:3.94348,cy1:9.0288,cx2:3.92364,cy2:9.12179,x:3.89045,y:9.19495},{op:"C",cx1:3.89045,cy1:9.48047,cx2:4.06285,cy2:9.65287,x:4.40821,y:9.70617},{op:"C",cx1:5.404,cy1:9.22134,cx2:5.9019,cy2:8.51787,x:5.9019,y:7.58841},{op:"C",cx1:5.9019,cy1:6.99751,cx2:5.62318,cy2:6.34681,x:5.05893,y:5.62972},{op:"L",x:5.05893,y:5.62972},{op:"L",x:5.05893,y:5.62971},{op:"Z"}],style:{fill:"#000"}}],emitPlayback:r=>r.affectFollowing(ce({body:[0,1],repeat:!0}))};var Qo=new Map([qo,Ko,Zo,Uo,jo,Yo].map(r=>[r.name.toLowerCase(),r])),xn=class extends L{static def={name:["symbol","$"],description:"\u521B\u5EFA\u4E00\u4E2A\u4E50\u8C31\u7B26\u53F7",example:["@symbol(name, size)","\u8BED\u6CD5\u7CD6: $name","\u5185\u7F6E:",...[...Qo.values()].map(t=>` $${t.name} ${t.description}`)].join(`
|
|
95
|
+
`),allowExtraArgs:!1,args:[{name:"name",type:"string",default:null},{name:"size",type:"length",default:{value:.5,unit:"em"}}]};static deSugarAtom(t,e,n){if(t[e]!=="$"||!/[A-Za-z]/.test(t[e+1]??""))return null;let o=e+2;for(;o<n&&/[A-Za-z0-9_-]/.test(t[o]);)o++;let s=t.slice(e+1,o);return{next:o,node:{kind:"call",typed:!0,name:"symbol",args:new Map([[0,s]]),span:{start:e,end:o},syntaxKind:"atom"}}}size;definition;constructor(t,e,n,o=null){super(t,o);let[s,i]=this.getArgValue(e,n);this.size=n.length2px(i);let a=Qo.get(s.toLowerCase());if(!a)throw new S("E_UNKNOWN_SYMBOL",`@symbol: \u672A\u77E5\u7B26\u53F7: $${s}`,t);this.definition=a}loweringEnter(){return[new yn(this)]}toString(){return`@symbol(${this.definition.name})`}},Xo=xn,yn=class extends D{bounds;scale=1;constructor(t){super(),this.ast=t,this.mergeKey=Q,this.onTimeState=t.definition.onTimeState,this.emitPlayback=t.definition.emitPlayback,this.bounds=Go(t.definition.shapes),this.initLayoutBox()}prepareLayout(){let t=this.ast.size*(this.ast.definition.weight??1);this.scale=t/this.bounds.h,this.box.w=this.bounds.w*this.scale,this.box.h=t,this.box.anchor=this.box.w/2,this.box.visualAxis=t/2}paint(t){Vo(t,this.ast.definition.shapes,this.bounds,this.box,this.scale)}};var bn=class r extends L{static def={name:["set"],description:"\u8BBE\u7F6E\u5C40\u90E8\u9ED8\u8BA4\u503C",example:`@set(fontSize=20) \u5219\u5F53\u524D\u5757\u5185\u9ED8\u8BA4\u5B57\u4F53\u53D8\u4E3A20px
|
|
96
|
+
\u53EF\u4EE5\u8BBE\u7F6E\u5176\u4ED6\u51FD\u6570\u7684\u9ED8\u8BA4\u503C: {\u51FD\u6570\u540D}.{\u5C5E\u6027}=\u503C\uFF0C\u4F8B:
|
|
97
|
+
@set(note.octave=5, note.color=#f00)
|
|
98
|
+
|
|
99
|
+
\u6CE8\u610F\uFF1A@set \u4F5C\u7528\u57DF\u4EC5\u5728\u5176\u6240\u5904 '{}' \u5185\u3001\u5176\u51FA\u73B0\u4E4B\u540E\u3002\u79BB\u5F00\u5F53\u524D\u4F5C\u7528\u57DF\u4F1A\u6062\u590D\u4E3A\u4E4B\u524D\u7684\u8BBE\u7F6E\u3002\u6B64\u8BBE\u7F6E\u548C\u65F6\u5E8F\u65E0\u5173\uFF0C\u7C7B\u4F3C\u4E8E\u5C40\u90E8\u53D8\u91CF\u3002
|
|
100
|
+
`,allowExtraArgs:!0,args:[]};static resolveTarget(t,e,n){let o=e.lastIndexOf(".");if(o<0)return[e,We[e]??"string"];let s=e.slice(o+1),i=t.functions.get(e.slice(0,o))?.prototype.def,a=i&>(i,s,-1);return!i||!a?(t.diagnostics.push(new C("W_SET_UNKNOWN_TARGET",`@set \u7684\u53C2\u6570 [${e}] \u6CA1\u6709\u5BF9\u5E94\u7684\u51FD\u6570\u6216\u5176\u53C2\u6570\uFF0C\u5C06\u88AB\u5FFD\u7565`,n)),null):a==="content"||a==="label"?(t.diagnostics.push(new C("W_SET_INVALID_VALUE_TYPE",`@set \u7684\u53C2\u6570 [${e}] \u5185\u5BB9\u548C\u6807\u7B7E\u4E0D\u80FD\u4F5C\u4E3A\u9ED8\u8BA4\u503C\uFF0C\u5C06\u88AB\u5FFD\u7565`,n)),null):[`${Et(i)}.${s}`.toLowerCase(),a]}args=new Map;constructor(t,e,n,o=null){super(t,o);for(let[s,i]of e){let a=i;if(typeof s!="string"){n.diagnostics.push(new C("W_SET_POSITIONAL_ARG",`\u51FD\u6570 @set \u4E0D\u63A5\u6536\u4F4D\u7F6E\u53C2\u6570, \u4F4D\u7F6E\u53C2\u6570[${s}]\u5C06\u88AB\u5FFD\u7565`,a.span));continue}let c=r.resolveTarget(n,s.toLowerCase(),a.nameSpan??a.span);if(c===null)continue;let[l,h]=c,u=n.parseArgWithType(a.valueSpan,h,t.start);if(u===null){n.diagnostics.push(new C("W_SET_INVALID_VALUE",`\u51FD\u6570 @set \u7684\u53C2\u6570\u503C\u89E3\u6790\u5931\u8D25, \u53C2\u6570[${s}]\u5C06\u88AB\u5FFD\u7565`,a.valueSpan));continue}n.setVariable(l,u),this.args.set(l,u)}}toString(){return`@set(${Array.from(this.args.entries()).map(([t,e])=>`${t}=${e}`).join(", ")})`}},Jo=bn;var wn=class extends L{static def={name:["volta"],description:"\u53CD\u590D\u623F\u5B50",example:`@volta(from, to, pass, ...) \u53EA\u5728\u6307\u5B9A\u904D\u6570\u6F14\u594F\u7684\u4E00\u6BB5\u533A\u95F4
|
|
101
|
+
from \u548C to \u662F\u533A\u95F4\u9996\u672B\u97F3\u7B26\u7684\u6807\u7B7E\uFF0C\u56E0\u6B64\u623F\u5B50\u53EF\u4EE5\u6A2A\u8DE8\u8C31\u9762\u884C
|
|
102
|
+
pass \u662F\u904D\u6570\uFF1A\u6574\u6BB5\u8C31\u9762\u6F14\u594F\u5230\u7B2C\u51E0\u904D\u65F6\u624D\u64AD\u8FD9\u91CC\uFF0C\u5FC5\u586B\u6B63\u6574\u6570
|
|
103
|
+
\u518D\u5199\u51E0\u4E2A\u904D\u6570\u5C31\u662F\u51E0\u904D\u5171\u7528\u4E00\u4E2A\u623F\u5B50\uFF0C\u987A\u5E8F\u968F\u610F\uFF0C\u6807\u7B7E\u6309\u5347\u5E8F\u5199\u6210 1.2.
|
|
104
|
+
|
|
105
|
+
|: 1 2 | 3@a 4@b :| 5@c 6@d | 7
|
|
106
|
+
@volta(a, b, 1) @volta(c, d, 2)`,allowExtraArgs:!0,extraArgType:"number",args:[{name:"from",type:"label",default:null},{name:"to",type:"label",default:null},{name:"pass",type:"number",default:null}]};from;to;passes;size;loweringEnter(t){let e=t.getTemporalNodes(this.from).at(0),n=t.getTemporalNodes(this.to).at(-1);for(;e?.foldedInto;)e=e.foldedInto;for(;n?.foldedInto;)n=n.foldedInto;return!e||!n?(t.diagnostics.push(E.warning.UnresolvedEndpoint("volta",this.sourceSpan)),[]):(t.addAttachment(new Sn(this,e,n)),[])}constructor(t,e,n,o=null){super(t,o);let[s,i,a]=this.getArgValue(e,n),c=new Set([a]);for(let l=3;e.has(l);l++)c.add(e.get(l));if(this.from=s,this.to=i,this.passes=[...c].sort((l,h)=>l-h),this.size=n.fontSize,this.passes.some(l=>!Number.isSafeInteger(l)||l<=0))throw new S("E_VOLTA_INVALID_PASS","@volta \u7684\u904D\u6570\u5FC5\u987B\u662F\u6B63\u6574\u6570",t)}toString(t){let e=n=>n.label??n.toString(t);return`@volta(${e(this.from)}, ${e(this.to)}, ${this.passes.join(", ")})`}},es=wn;function ts(r){if(r?.[0]?.mergeKey===W)return r[0]}var Sn=class{ast;from;to;layer="foreground";head;tail;span=0;leftBar;rightBar;topsByLine=[];constructor(t,e,n){this.ast=t,this.from=e,this.to=n}get sourceSpan(){return this.ast.sourceSpan}playbackFlow(t){let e=t(this.from),n=t(this.to);if(e===void 0||n===void 0)return;let o=Math.min(e,n),s=Math.max(e,n);return{range:[o,s],run:i=>this.ast.passes.includes(Gn(i,o))?void 0:{kind:"jump",column:s+1}}}prepareHorizontal(t){if(!R(this.from)||!R(this.to))return;let e=s=>{let i=t[s.layoutLine];return{line:s.layoutLine,view:i,column:i.columnOf(s)}},[n,o]=[e(this.from),e(this.to)];if((n.line>o.line||n.line===o.line&&n.column>o.column)&&([n,o]=[o,n]),!(n.column<0||o.column<0)){this.head=n.view.columns[n.column][0],this.tail=o.view.columns[o.column][0],this.leftBar=ts(n.view.columns[n.column-1]),this.rightBar=ts(o.view.columns[o.column+1]),this.span=0,this.topsByLine.length=0;for(let s=n.line;s<=o.line;s++){let i=t[s],a=s===n.line?n.column:0,c=s===o.line?o.column:i.columns.length-1,l=new Map;for(let h=a;h<=c;h++){let u=i.columns[h];this.span=Math.max(this.span,u[0].ast.size);for(let f of u){let g=-f.box.visualAxis,d=l.get(f.track);(d===void 0||g<d)&&l.set(f.track,g)}}this.topsByLine.push(l)}}}createGeometry(t){let{head:e,tail:n,leftBar:o,rightBar:s}=this;if(!e||!n)return{regions:[],paint(){}};let i=e.layoutLine,a=n.layoutLine,c=this.span||this.ast.size,l={fontSize:c*.6,textAlign:"left",fill:"#000"},h=this.ast.passes.map(p=>`${p}.`).join(""),u=t.textMeasurer.measureText(h,l),f=Math.max(1,c*.055),g=f/2,d=u.h*1.2,y=(d-u.h)/2+u.baseline,x=Array.from({length:a-i+1},(p,m)=>{let b=i+m,w=b!==i?t.originX:o?.layoutLine===b?o.box.x+o.box.anchor+5:e.box.x+(e.ports["body.left"]?.x??0),N=b!==a?t.originX+t.width:s?.layoutLine===b?s.box.x+s.box.anchor:n.box.x+(n.ports["body.right"]?.x??n.box.w),I=e.track,F=1/0;for(let[T,v]of this.topsByLine[m]){let A=t.getVisualAxis(b,T)+v;A<F&&(I=T,F=A)}return F===1/0&&(F=t.getVisualAxis(b,I)),{left:w,right:N,lineY:F-c*.2-d,line:b,track:I}});return{regions:x.map(({left:p,right:m,lineY:b,line:w,track:N})=>({x:p-g,y:b-g,w:m-p+f,h:d+f,line:w,track:N})),paint(p){let m={stroke:"#000",strokeWidth:f};for(let{left:b,right:w,lineY:N,line:I}of x)p.drawLine(b,N,w,N,m),I===i&&(p.drawLine(b,N,b,N+d,m),p.drawText(h,b+c*.15,N+y+2,l)),I===a&&p.drawLine(w,N,w,N+d,m)}}}};var ns=4/3,yi=.09,An=class extends L{static def={name:["tie"],description:"\u8FDE\u97F3\u7EBF",example:`@tie(label1, label2, ..., height=0.5em)
|
|
107
|
+
\u5C06\u7AEF\u70B9\u4F9D\u6B21\u8FDE\u63A5\uFF1B\u540C\u884C\u7528\u4E00\u6761\u5F27\u7EBF\uFF0C\u8DE8\u884C\u62C6\u6210\u5206\u6BB5\u8FDE\u63A5\uFF1B\u82E5\u4E0D\u4F20\u7AEF\u70B9\u5219\u627E\u6700\u8FD1\u7684`,allowExtraArgs:!0,extraArgType:"label",args:[]};endPoints=[];height;constructor(t,e,n,o=null){super(t,o);let s=n.fontSize*.5;for(let[a,c]of e){if(a==="height"){let h=n.parseArgWithType(c.valueSpan,"length",t.start);h&&(s=Math.max(0,n.length2px(h)));continue}let l=c instanceof L?c:n.parseArgWithType(c.valueSpan,"label",t.start);l!==null&&this.endPoints.push(l)}let i=n.labelableNodes.length-1;for(;this.endPoints.length<2&&i>=0;){let a=n.labelableNodes[i--];!a||this.endPoints.includes(a)||this.endPoints.unshift(a)}if(this.endPoints.length<2)throw new S("E_NOT_ENOUGH_ARGS","@tie \u8FDE\u97F3\u7EBF\u9700\u8981\u81F3\u5C11\u4E24\u4E2A\u7AEF\u70B9",t);this.height=s}loweringEnter(t){let e=[];for(let n of this.endPoints){let o=t.getTemporalNodes(n).at(-1);!o||!R(o)||e.push(o)}return e.length<2?(t.diagnostics.push(E.warning.UnresolvedEndpoint("tie",this.sourceSpan)),[]):(t.addAttachment(new Tn(e,this.height,this.sourceSpan)),[])}toString(t){return`@tie(${this.endPoints.map(e=>`${e.label??"anon"}:[${e.toString(t)}]`).join(", ")})`}},os=An;var Tn=class{layer="foreground";sourceSpan;endPoints;height;thickness;constructor(t,e,n){this.endPoints=t,this.height=e,this.sourceSpan=n;let o=t.reduce((s,i)=>Math.max(s,i.ast.size),0);this.thickness=Math.max(1.2,o*yi)}applyPlayback(t){let e=()=>t.events.filter(o=>o.kind==="note-on"),n=o=>t.events.find(s=>s.kind==="note-off"&&s.noteId===o);for(let o of e().filter(s=>s.origins.some(i=>i.node===this.endPoints[0])))for(let s=1;s<this.endPoints.length;s++){let i=n(o.noteId);if(!i)break;let a=e().find(l=>l.noteId!==o.noteId&&l.origins.some(h=>h.node===this.endPoints[s])&&l.track===o.track&&l.midi===o.midi&&i.at.equals(l.at));if(!a)break;let c=n(a.noteId);if(!c)break;o.sourceSpans.push(...a.sourceSpans);for(let l of a.origins)o.origins.includes(l)||o.origins.push(l);c.noteId=o.noteId,c.origins=[...o.origins],t.events.splice(0,t.events.length,...t.events.filter(l=>l!==i&&l!==a))}}createGeometry(t){let e=this.createSegments(t),n=e.map(({commands:s,...i})=>i),o=e.map(s=>{let i=t.getHostExtent(s.line,s.track),a=i?Math.max(s.y,t.getVisualAxis(s.line,s.track)+i.top):s.y+s.h;return{x:s.x,y:s.y,w:s.w,h:a-s.y,line:s.line,track:s.track}});return{regions:n,occupancy:o,paint(s){for(let i of e)s.drawPath(i.commands,{fill:"#000"})}}}absolutePort(t,e){let n=t.ports[e];return n?{x:t.box.x+n.x,y:t.box.y+n.y}:{x:t.box.x+t.box.anchor,y:t.box.y}}createSegments(t){let e=[];for(let n=1;n<this.endPoints.length;n++){let o=this.endPoints[n-1],s=this.endPoints[n];o.layoutLine>s.layoutLine&&([o,s]=[s,o]);let i=this.absolutePort(o,"tie.top"),a=this.absolutePort(s,"tie.top");if(o.layoutLine===s.layoutLine){let c=t.getVisualAxis(o.layoutLine,o.track)+(t.getHostExtent(o.layoutLine,o.track)?.top??0),l=t.getVisualAxis(s.layoutLine,s.track)+(t.getHostExtent(s.layoutLine,s.track)?.top??0);e.push(this.arcSegment(i,a,o.layoutLine,c<=l?o.track:s.track));continue}e.push(this.openingSegment(i,t.originX+t.width,this.plateauY(t,o.layoutLine,o.track,i.y),o.layoutLine,o.track));for(let c=o.layoutLine+1;c<s.layoutLine;c++)e.push(this.horizontalSegment(t.originX,t.originX+t.width,this.plateauY(t,c,o.track),c,o.track));e.push(this.closingSegment(t.originX,a,this.plateauY(t,s.layoutLine,s.track,a.y),s.layoutLine,s.track))}return e}plateauY(t,e,n,o=1/0){let s=t.getVisualAxis(e,n),i=t.getHostExtent(e,n)?.top??0;return Math.min(o,s+i)-this.height}arcSegment(t,e,n,o){let s=t,i=e;s.x>i.x&&([s,i]=[i,s]);let a=(i.x-s.x)*.25,c=s.x+a,l=i.x-a,h=this.height*ns,u=Math.max(0,h-this.thickness*ns),f=[{op:"M",x:s.x,y:s.y},{op:"C",cx1:c,cy1:s.y-h,cx2:l,cy2:i.y-h,x:i.x,y:i.y},{op:"C",cx1:l,cy1:i.y-u,cx2:c,cy2:s.y-u,x:s.x,y:s.y},{op:"Z"}];return le(f,n,o)}openingSegment(t,e,n,o,s){let i=Math.max(0,e-t.x),a=Math.min(this.height*1.2,i*.4),c=t.x+a,l=t.x+a*.45,h=n+this.thickness;return le([{op:"M",x:t.x,y:t.y},{op:"Q",cx:l,cy:n,x:c,y:n},{op:"L",x:e,y:n},{op:"L",x:e,y:h},{op:"L",x:c,y:h},{op:"Q",cx:l,cy:h,x:t.x,y:t.y},{op:"Z"}],o,s)}closingSegment(t,e,n,o,s){let i=Math.max(0,e.x-t),a=Math.min(this.height*1.2,i*.4),c=e.x-a,l=e.x-a*.45,h=n+this.thickness;return le([{op:"M",x:t,y:n},{op:"L",x:c,y:n},{op:"Q",cx:l,cy:n,x:e.x,y:e.y},{op:"Q",cx:l,cy:h,x:c,y:h},{op:"L",x:t,y:h},{op:"Z"}],o,s)}horizontalSegment(t,e,n,o,s){return le([{op:"M",x:t,y:n},{op:"L",x:e,y:n},{op:"L",x:e,y:n+this.thickness},{op:"L",x:t,y:n+this.thickness},{op:"Z"}],o,s)}};function le(r,t,e){return{commands:r,line:t,track:e,...ae(r)}}var Ln=class extends L{static def={name:["tuplet"],description:"\u591A\u8FDE\u97F3",example:"@tuplet({1/23}, 4): \u5185\u5BB9\u542B5\u4E2A\u6700\u77ED\u65F6\u503C\u5355\u4F4D\uFF0C\u538B\u7F29\u52304\u500D\u6700\u77ED\u5355\u4F4D\u7684\u603B\u65F6\u957F\uFF0C\u6240\u4EE5\u662F\u516B\u5206\u97F3\u7B26\u7684\u4E94\u8FDE\u97F3\uFF0C\u603B\u65F6\u957F\u4E3A\u4E8C\u5206\u97F3\u7B26",allowExtraArgs:!1,args:[{type:"content",default:null},{name:"normal",type:"number",default:null}]};static loweringFinalize=t=>{for(let e of t.attachments)e instanceof he&&e.validate()};content;normal;get children(){return[this.content]}timeFlowModel(){return{mode:"sequence",children:[this.content]}}loweringEnter(t){let e=[],n={events:e,onTemporal(o){e.push(o)}};return t.beginLoweringGroup(this,n),[]}loweringExit(t,e,n){let o=t.endLoweringGroup(this),s=o.events.filter(d=>d.T.compare(0)>0);if(s.length===0)throw new S("E_TUPLET_EMPTY","@tuplet \u7684\u5185\u5BB9\u5FC5\u987B\u4EA7\u751F\u81F3\u5C11\u4E00\u4E2A\u6B63\u65F6\u503C\u4E8B\u4EF6",this.sourceSpan);let i=s[0].track;if(s.some(d=>d.track!==i))throw new S("E_TUPLET_PARALLEL_CONTENT","@tuplet \u7684\u5185\u5BB9\u4E0D\u80FD\u5305\u542B\u5E76\u884C\u97F3\u8F68",this.sourceSpan);let a=s[0].T.clone(),c=new M;for(let d of s)d.T.compare(a)<0&&a.copyFrom(d.T),c.add(d.T);let l=c.clone().div(a),h=l.numerator;if(l.denominator!==1||h<2||!Number.isSafeInteger(h))throw new S("E_TUPLET_NON_INTEGRAL_UNITS","@tuplet \u7684\u603B\u65F6\u503C\u5FC5\u987B\u662F\u6700\u77ED\u6B63\u65F6\u503C\u7684\u6574\u6570\u500D\uFF0C\u4E14\u81F3\u5C11\u5305\u542B2\u4E2A\u5355\u4F4D",this.sourceSpan);if(this.normal===h)throw new S("E_TUPLET_INVALID_RATIO",`@tuplet \u7684 normal \u4E0D\u80FD\u7B49\u4E8E\u63A8\u5BFC\u51FA\u7684 actual (${h})`,this.sourceSpan);let u=o.events[0].t;for(let d=1;d<o.events.length;d++)o.events[d].t.compare(u)<0&&(u=o.events[d].t);u=u.clone();let f=new M;for(let d of o.events)f.copyFrom(d.t).sub(u).mul(this.normal,h),d.t.copyFrom(u).add(f),d.T.mul(this.normal,h);n.copyFrom(u).add(a.mul(this.normal));let g=s.filter(R);return g.length>=2&&t.addAttachment(new he(g,h,this.sourceSpan)),[]}constructor(t,e,n,o=null){super(t,o);let[s,i]=this.getArgValue(e,n);if(!Number.isSafeInteger(i)||i<=0)throw new S("E_TUPLET_INVALID_NORMAL","@tuplet \u7684 normal \u5FC5\u987B\u662F\u6B63\u7684\u5B89\u5168\u6574\u6570",t);this.content=s,this.normal=i,s.parent=this}toString(t){return`@tuplet(${this.content.toString(t)}, ${this.normal})`}},ss=Ln,he=class{layer="foreground";endPoints;actual;sourceSpan;style;size;constructor(t,e,n){this.endPoints=t,this.actual=e,this.sourceSpan=n,this.size=t.reduce((o,s)=>Math.max(o,s.ast.size),0),this.style={fontSize:this.size*.72,fontFamily:et,textAlign:"center",fill:"#000"}}validate(){let t=this.endPoints[0];if(this.endPoints.some(e=>e.layoutLine!==t.layoutLine))throw new S("E_TUPLET_CROSS_LINE","@tuplet \u7684\u5185\u5BB9\u4E0D\u80FD\u8DE8\u8D8A\u8C31\u9762\u884C",this.sourceSpan)}createGeometry(t){let e=this.endPoints[0],n=this.endPoints[this.endPoints.length-1],o=e.ports["body.left"]?.x??0,s=n.ports["body.right"]?.x??n.box.w,i=e.box.x+o,a=n.box.x+s;i>a&&([i,a]=[a,i]);let c=t.textMeasurer.measureText(String(this.actual),this.style),l=(i+a)/2,h=this.size*.12,u=this.size*.18,f=this.size*.14,d=t.getVisualAxis(e.layoutLine,e.track)+(t.getHostExtent(e.layoutLine,e.track)?.top??0),y=Math.max(1,this.size*.055),x=d-f-Math.max(u,c.h/2),p=x+u,m=x-c.h/2+c.baseline,b=l-c.w/2-h,w=l+c.w/2+h,N=[];b>i&&N.push([i,x,b,x]),w<a&&N.push([w,x,a,x]),N.push([i,x,i,p],[a,x,a,p]);let I=y/2,F=Math.min(x-c.h/2,x-I),T=Math.max(x+c.h/2,p+I),v=[{x:i-I,y:F,w:a-i+y,h:T-F,line:e.layoutLine,track:e.track}],A=String(this.actual),_=this.style;return{regions:v,paint(k){let P={stroke:"#000",strokeWidth:y};for(let[K,z,Z,B]of N)k.drawLine(K,z,Z,B,P);k.drawText(A,l,m,_)}}}};var bi=/\s/;function wi(r){let t=r/2;return(e,n)=>{let o=e.map(c=>c&&c.bottom-c.top>1e-6?c:{top:-t,bottom:t}),s=[],i=0;for(let c=0;c<o.length;c++)c>0&&(i+=o[c-1].bottom+n-o[c].top),s.push(i);let a=(s[0]+s[s.length-1])/2;return s.map((c,l)=>({offset:c-a,extent:o[l]}))}}var Dt=class r extends L{static def={name:["voice","v"],description:"\u58F0\u90E8",example:`@voice({}, name, \u6B4C\u8BCD1\u540D=\u6B4C\u8BCD1, \u6B4C\u8BCD2\u540D=\u6B4C\u8BCD2, ...)
|
|
108
|
+
\u7B2C\u4E00\u4E2A\u53C2\u6570\u4E3A\u97F3\u7B26\u5185\u5BB9\uFF0C\u7B2C\u4E8C\u4E2A\u53C2\u6570\u4E3A\u5199\u5728\u6700\u5DE6\u4FA7\u7684\u58F0\u90E8\u540D\u79F0(\u53EF\u4E0D\u586B)\uFF1B
|
|
109
|
+
\u547D\u540D\u53C2\u6570\u4E3A\u6B4C\u8BCD\u5DE6\u4FA7\u7684\u540D\u79F0\u548C\u5185\u5BB9\uFF0C\u53EF\u4EE5\u4EFB\u610F\u591A\u4E2A\u3002\u4E5F\u53EF\u4EE5\u662F\u4F4D\u7F6E\u53C2\u6570\uFF0C\u8868\u793A\u4E0D\u9700\u8981\u540D\u79F0\u3002
|
|
110
|
+
\u4F8B:
|
|
111
|
+
@voice({C1 D1 E1}, \u94A2\u7434, \u7537=ha ha ha, \u5973=la la la)
|
|
112
|
+
@voice({C1 D1 E1}, , ha ha ha, \u5973="la la la") \u8868\u793A\u97F3\u7B26\u548C\u7B2C\u4E00\u4E2A\u6B4C\u8BCD\u90FD\u6CA1\u6709\u540D\u79F0
|
|
113
|
+
\u6B4C\u8BCD\u53EF\u4EE5\u88AB\u5F15\u53F7\u5305\u88F9\uFF0C\u5982\u679C\u5305\u542B\u9017\u53F7\u7B49\u6B67\u4E49\u5B57\u7B26\u4E00\u5B9A\u9700\u8981\u5F15\u53F7
|
|
114
|
+
\u8BED\u6CD5\u7CD6\uFF1A
|
|
115
|
+
N(name): C1 D1 E1
|
|
116
|
+
L(name): ha ha ha...
|
|
117
|
+
L: ...
|
|
118
|
+
\u524D\u9762\u53EF\u4EE5\u6709\u4EFB\u610F\u7A7A\u767D\uFF0C\u4F46\u6700\u540E\u6362\u884C\u8868\u793A\u7ED3\u675F\u3002\u6B4C\u8BCD\u6B64\u65F6\u5141\u8BB8\u6709\u9017\u53F7\u800C\u4E0D\u52A0\u5F15\u53F7
|
|
119
|
+
\u5982\u679C\u4E00\u5B9A\u8981\u6362\u884C\uFF0C\u6700\u540E\u52A0\u4E0A'\\'
|
|
120
|
+
\u82F1\u6587\u6B4C\u8BCD\u7528\u7A7A\u683C\u548C\u8FDE\u5B57\u7B26'-'\u5206\u8BCD\uFF0C\u7528'@'\u5360\u4F4D
|
|
121
|
+
`,allowExtraArgs:!0,extraArgType:"string",args:[{type:"content",default:null},{name:"name",type:"string",default:""}]};static deSugarAtom(t,e,n){if(t[e]!=="N"&&t[e]!=="L")return null;let o=e+1,s="";if(t[o]==="("){let i=mo(t,o+1,n);if(i<0)return null;s=ct(t.slice(o+1,i).trim()),o=i+1}if(t[o++]!==":")return null;if(t[e]==="N")return{next:o,node:{kind:"sugar",data:{class:r,name:s},span:{start:e,end:o}}};{if(o=tt(t,o,n),o>=n)return null;let i;if(t[o]==='"'){let c=At(t,o,n);if(c<0)return null;i=ct(t.slice(o,c+1)),o=c+1}else{let c=o;for(;o<n&&t[o]!==`
|
|
122
|
+
`;)o++;i=t.slice(c,o).trim()}return{next:o,node:{kind:"sugar",data:{class:r,lyric:i,name:s},span:{start:e,end:o}}}}}static deSugarRelation(t,e,n){let o=e[n++];if(o.data?.class!==r)return null;if(o.data?.lyric!==void 0){let y=null,x=t.nodes.length-1;for(;x>=0;x--){let p=t.nodes[x];if(p instanceof H){if(!t.strict)continue;throw new S("E_LYRICS_WITHOUT_VOICE_NOTES","strict \u6A21\u5F0F\u4E0B\uFF0C\u8BED\u6CD5\u7CD6 'L:' \u6216 'L(name)' \u5FC5\u987B\u8DDF\u5728 @voice \u7684\u97F3\u7B26\u4E4B\u540E\uFF0C\u4F46\u5728\u5176\u524D\u9762\u53D1\u73B0\u4E86\u672A\u77E5\u6587\u672C",p.sourceSpan)}p instanceof r?y=p:p instanceof pt&&(y=p.voices.at(-1)??null);break}if(y===null)throw new S("E_LYRICS_WITHOUT_VOICE_NOTES","\u8BED\u6CD5\u7CD6 'L:' \u6216 'L(name):' \u5FC5\u987B\u8DDF\u5728 @voice\uFF08\u6216 N:\uFF09\u4E4B\u540E\uFF0C\u4F46\u6CA1\u6709\u627E\u5230\u7B26\u5408\u8981\u6C42\u7684 voice\uFF1B\u8BF7\u68C0\u67E5\u8BED\u6CD5\u6216\u76F4\u63A5\u4F7F\u7528 @voice \u51FD\u6570",o.span);return y.addLyric(o.data.name,o.data.lyric,o.span,t),t.nodes.length=x+1,n<e.length&&typeof e[n]=="number"&&t.source[e[n]]===`
|
|
123
|
+
`&&n++,n}let s=n,i=0;for(;s<e.length;s++){let y=e[s];if(typeof y=="number"){if(t.source[y]===`
|
|
124
|
+
`){i=1;break}}else if(y.kind==="sugar"&&y.data?.class===r)break}let a=new X(t),c=e.slice(n,s);if(s+=i,a.makeNodes(c),a.nodes.length===0)throw E.error.EmptyContent("voice","content",o.span);let l={start:o.span.start,end:a.nodes.at(-1).sourceSpan.end},h=new Map;a.nodes.length===1&&a.nodes[0]instanceof $?h.set(0,a.nodes[0]):h.set(0,new $({...l},a.nodes)),h.set("name",o.data.name);let u=new r(l,h,t,null),f=null,g=t.nodes.length-1,d=null;t:for(;g>=0;g--){let y=t.nodes[g];if(y instanceof H){if(t.strict)break;for(let x=y.sourceSpan.start;x<y.sourceSpan.end;x++)if(t.source[x]===`
|
|
125
|
+
`)break t;d=y;continue}if(y instanceof pt){if(!y.createdBySugar)break;f=y}else if(y instanceof r){let x=new Map;x.set(0,y),f=new pt({start:y.sourceSpan.start,end:y.sourceSpan.end},x,t,null),f.createdBySugar=!0}break}return f?(t.nodes[g]=f,f.addVoice(u),d&&(t.nodes.length=g+1,t.diagnostics.push(new C("W_VOICES_TEXT_BETWEEN","\u4E24\u4E2A @voice \u4E4B\u95F4\u6709\u672A\u77E5\u6587\u672C\u3002\u5F53\u524D\u5904\u4E8E\u975E strict \u6A21\u5F0F\uFF0C\u4F1A\u5FFD\u7565\u8BE5\u5185\u5BB9\u3001\u5408\u5E76\u4E3A\u4E00\u4E2A @voices",d.sourceSpan)))):t.pushNode(u),s}content;name;size;lyrics;get children(){return[this.content]}timeFlowModel(){return{children:this.children,mode:"sequence"}}loweringEnter(t){let e=this.parent,n=e instanceof pt&&e.voices.length>1?e.braceSpace:0,o=new ue(this,n),s=[];return t.beginLoweringGroup(this,{attachment:new Nn(s,o),onTemporal(i){s.push(i)}}),[o]}loweringExit(t){return t.endLoweringGroup(this),[]}constructor(t,e,n,o=null){super(t,o),this.size=n.fontSize,[this.content,this.name]=this.getArgValue(e,n),this.content.parent=this,e.delete(0),e.delete("name"),e.delete(1),this.lyrics=[];for(let[s,i]of e){if(typeof i=="string"){this.addLyric(s,i);continue}let a=i,c=n.parseArgWithType(a.valueSpan,"string",t.start);c===null?n.diagnostics.push(new C("W_VOICE_INVALID_LYRIC",`@voice \u7684\u6B4C\u8BCD\u53C2\u6570\u503C\u89E3\u6790\u5931\u8D25, \u53C2\u6570[${s}]\u5C06\u88AB\u5FFD\u7565`,a.valueSpan)):this.addLyric(s,c)}}addLyric(t,e,n=null,o=null){typeof t=="number"&&(t="");let s=r.parseLyric(e);if(s.length===0&&o&&n&&o.diagnostics.push(new C("W_EMPTY_LYRIC",`@voice\u7684\u6B4C\u8BCD${t}\u662F\u7A7A\u7684`,n)),this.lyrics.push({name:t,tokens:s}),n)for(let i=this;i;i=i.parent)i.sourceSpan.start=Math.min(n.start,i.sourceSpan.start),i.sourceSpan.end=Math.max(n.end,i.sourceSpan.end)}static parseLyric(t){let e=[],n=0;for(let o=0;o<t.length;o++){let s=t[o];bi.test(s)?(o>n&&e.push(t.slice(n,o)),n=o+1):s==="-"?o>n?(e.push(t.slice(n,o+1)),n=o+1):n=o:s==="@"?(o>n&&e.push(t.slice(n,o+1)),e.push(""),n=o+1):s.charCodeAt(0)>127&&(o>n&&e.push(t.slice(n,o)),e.push(s),n=o+1)}return n<t.length&&e.push(t.slice(n)),e}toString(t){let e=this.content.toString(t),n=this.lyrics.map(o=>{let s=o.tokens.map(i=>i.length===0?"@":i).join(" ");return(s.includes(",")||s.includes(`
|
|
126
|
+
`))&&(s=`"${s.replace(/"/g,'\\"')}"`),`${o.name?`${o.name}=${s}`:s}`});return`@voice(
|
|
127
|
+
${e},${this.name},
|
|
128
|
+
${n.join(`,
|
|
129
|
+
`)}
|
|
130
|
+
)`}},pt=class extends L{static def={name:["voices","vs"],description:"\u591A\u4E2A\u58F0\u90E8",example:`@voices(
|
|
131
|
+
@voice({C1 D1 E1}, \u94A2\u7434, \u7537=ha ha ha),
|
|
132
|
+
@voice({C2 D2 E2}, , "la la la")
|
|
133
|
+
)
|
|
134
|
+
\u8BED\u6CD5\u7CD6\uFF1A\u5F53\u591A\u4E2A voice \u7528 voice \u7684\u8BED\u6CD5\u7CD6\u5199\u5728\u4E00\u8D77\u65F6\uFF0C\u4F1A\u81EA\u52A8\u521B\u5EFA\u4E00\u4E2A voices \u7EC4\u4EF6\u5305\u88F9\u5B83\u4EEC\u3002
|
|
135
|
+
\u4F8B\uFF1A
|
|
136
|
+
N(\u94A2\u7434): C1 D1 E1
|
|
137
|
+
L(\u7537): ha ha ha
|
|
138
|
+
N: C2 D2 E2
|
|
139
|
+
L: la la la
|
|
140
|
+
`,allowExtraArgs:!0,extraArgType:"content",args:[]};voices;createdBySugar=!1;size;braceSpace;measure;get children(){return this.voices}timeFlowModel(){return{children:this.children,mode:"parallel",tracks:{laneKey:`voices/${this.voices.length}`,hostIndex:null,measure:this.measure}}}loweringEnter(t){let e=[];return t.beginLoweringGroup(this,{attachment:new _n(e,this),onTemporal(n){n instanceof ue&&e.push(n)}}),[]}loweringExit(t){return t.endLoweringGroup(this),[]}constructor(t,e,n,o=null){super(t,o),this.voices=[],this.size=n.fontSize,this.braceSpace=n.fontSize,this.measure=wi(n.fontSize);for(let[,s]of e){if(s instanceof V){if(s instanceof Dt)this.addVoice(s);else throw new S("E_VOICES_INVALID_CHILD",`@voices \u7684\u53C2\u6570\u5FC5\u987B\u662F @voice \u51FD\u6570\uFF0C\u4F46\u53D1\u73B0\u4E86\u5176\u4ED6\u7C7B\u578B ${s.constructor.name}`,s instanceof V?s.sourceSpan:t);continue}let i=s,a=n.parseArgWithType(i.valueSpan,"content",t.start);if(a instanceof Dt)this.addVoice(a);else throw new S("E_VOICES_INVALID_CHILD",`@voices \u7684\u53C2\u6570\u5FC5\u987B\u662F @voice \u51FD\u6570\uFF0C\u4F46\u53D1\u73B0\u4E86\u5176\u4ED6\u7C7B\u578B ${a?.constructor.name}`,i.valueSpan)}if(this.voices.length===0)throw new S("E_VOICES_EMPTY","@voices \u5FC5\u987B\u81F3\u5C11\u5305\u542B\u4E00\u4E2A @voice \u51FD\u6570",t)}addVoice(t){this.voices.push(t),t.parent=this,this.sourceSpan.start=Math.min(t.sourceSpan.start,this.sourceSpan.start),this.sourceSpan.end=Math.max(t.sourceSpan.end,this.sourceSpan.end)}toString(t){let e=Array(this.voices.length);for(let n=0;n<this.voices.length;n++){let o=this.voices[n].toString(t).replace(/^/gm," ");e[n]=o}return`@voices(
|
|
141
|
+
${e.join(`,
|
|
142
|
+
`)}
|
|
143
|
+
)`}},is=Dt,rs=pt,En=.82,Si=.6;function as(r){return{fontSize:r*En,fill:"#000",fontWeight:600}}var ue=class extends D{braceSpace;textBaselineY=0;constructor(t,e){super(),this.ast=t,this.braceSpace=e,this.mergeKey=-2,(t.name||e>0||t.lyrics.some(n=>n.name))&&this.initLayoutBox()}prepareLayout(t){let e=this.ast.name?t.textMeasurer.measureText(this.ast.name,this.style):{w:0,h:0,baseline:0},n=e.w;for(let s of this.ast.lyrics){if(!s.name)continue;let i=t.textMeasurer.measureText(s.name,as(this.ast.size));n=Math.max(n,i.w)}let o=this.braceSpace>0?this.braceSpace:n>0?this.ast.size*Si:0;this.box.w=n+o,this.box.h=e.h,this.box.anchor=n,this.box.visualAxis=e.h/2,this.textBaselineY=e.baseline,this.springConfig.alpha_R=.45}get style(){return{fontSize:this.ast.size*.85,fill:"#000",fontWeight:600,textAlign:"right"}}paint(t){this.ast.name&&t.drawText(this.ast.name,this.box.x+this.box.anchor,this.box.y+this.textBaselineY,this.style)}},ut=2.33,ft=1.17,ht=.34,Ai=[{op:"M",x:0,y:0},{op:"L",x:0,y:-ht},{op:"C",cx1:ut*.421,cy1:-ht+ft*.077,cx2:ut*.733,cy2:-ht+ft*.346,x:ut,y:-ht+ft},{op:"L",x:ut*.929,y:-ht+ft},{op:"C",cx1:ut*.696,cy1:-ht+ft*.535,cx2:ut*.328,cy2:-ht+ft*.352,x:0,y:0},{op:"Z"}],_n=class{layer="background";names;ast;get sourceSpan(){return this.ast.sourceSpan}constructor(t,e){this.names=t,this.ast=e}createGeometry(){if(this.names.length<2)return{regions:[],paint(){}};let t=this.names[0].box,e=this.names[this.names.length-1].box,n=this.ast.size,o=t.y+t.visualAxis-n*.5,s=e.y+e.visualAxis+n*.5;if(s-o<1e-6)return{regions:[],paint(){}};let i=Math.max(2.5,n*.19),a=i*ut,c=i*ft,l=t.x+t.anchor+this.ast.braceSpace*.3+i/2,h=[{x:l-i/2,y:o,w:i,h:s-o},{x:l+i*1.33-i*.165,y:o+i*.67,w:i*.33,h:s-o-i*1.34}],u=[{x:l,y:o,scale:i,dir:-1},{x:l,y:s,scale:i,dir:1}];return{regions:[{x:l-i/2,y:o-c,w:a+i/2,h:s-o+c*2}],paint(g){for(let d of h)g.drawRect(d.x,d.y,d.w,d.h,{fill:"#000"});for(let d of u)g.drawPath(Ai,{fill:"#000"},{x:d.x,y:d.y,scaleX:d.scale,scaleY:d.scale*d.dir})}}}},Nn=class{layer="foreground";temporalMembers;nameHost;get sourceSpan(){return this.nameHost.ast.sourceSpan}constructor(t,e){this.temporalMembers=t,this.nameHost=e}prepareHorizontal(t,e){let n=this.temporalMembers.filter(R).filter(a=>a.ports?.lyric),{lyrics:o,size:s}=this.nameHost.ast;if(n.length===0||o.length===0)return;let i={fontSize:s*En,fill:"#000"};for(let a=0;a<n.length;a++){let c=n[a],l=0;for(let h of o){let u=h.tokens[a];u&&(l=Math.max(l,e.textMeasurer.measureText(u,i).w/2))}l!==0&&t[c.layoutLine]?.registerHorizontalLayoutHook(c,c,({columns:h,start:u})=>{let f=h[u].find(d=>d.time===c);if(!f)return;let g=c.ports.lyric.x-c.box.anchor;f.WL=Math.max(f.WL,l-g),f.WR=Math.max(f.WR,l+g)})}}createGeometry(t){let e=this.prepareGeometry(t);return{regions:e,paint(n){for(let o of e)n.drawText(o.text,o.x,o.y+o.textBaselineY,o.style)}}}prepareGeometry(t){let{lyrics:e,size:n}=this.nameHost.ast,o=[],s=this.temporalMembers.filter(R).filter(m=>m.ports?.lyric);if(s.length===0||e.length===0)return o;let i=new Map;for(let m of s){let b=i.get(m.layoutLine);b||i.set(m.layoutLine,b=new Map);let w=m.box.y+m.box.h;b.set(m.track,Math.max(b.get(m.track)??w,w))}let a=n*En,c=n*.24,l=n*.32,h={fontSize:a,fill:"#000"},u=as(n),f=t.textMeasurer.measureText("M",h).baseline+l,g=(m,b)=>m+f+b*(a+c),{box:d,layoutLine:y,track:x}=this.nameHost,p=i.get(y)?.get(x);for(let m=0;m<e.length;m++){let b=e[m];for(let N=0;N<b.tokens.length&&N<s.length;N++){let I=b.tokens[N],F=s[N],T=i.get(F.layoutLine)?.get(F.track);if(!I||T===void 0)continue;let v=t.textMeasurer.measureText(I,h);o.push({text:I,style:h,textBaselineY:v.baseline,x:F.box.x+F.ports.lyric.x-v.w/2,y:g(T,m)-v.baseline,w:v.w,h:v.h,line:F.layoutLine,track:F.track})}if(!b.name||!d||p===void 0)continue;let w=t.textMeasurer.measureText(b.name,u);o.push({text:b.name,style:u,textBaselineY:w.baseline,x:d.x+d.anchor-w.w,y:g(p,m)-w.baseline,w:w.w,h:w.h,line:y,track:x})}return o}};var fe=[Oo,oo,Wn,xt,ao,ss,is,rs,Ro,$o,Io,zo,Po,Do,uo,os,Xn,no,es,Hn,Jo,Xt,te,ee,ne,Xo];function kn(r,t={}){let e=new Map,n=new Set(r);for(let o of n){let s=o,i=s.layoutDecorationHandler;if(!i)continue;let a=s.def?.name;if(!a)continue;let c=Array.isArray(a)?a[0]:a;e.set(st(c),i)}return{textMeasurer:t.textMeasurer??Ze,decorationHandlers:e}}var Ft=class r{groups=[];group(t,e){let n=this.groups.find(o=>o.laneKey===t.laneKey);for(n||(n={laneKey:t.laneKey,members:[],measure:t.measure,place:t.place},this.groups.push(n));n.members.length<e;)n.members.push(new r);return n}};var $t=class r{loweringAugmenters=[];loweringFinalizers=[];cnt=0;usedTracks=new Set;attachments=[];page;astToTemporal=new Map;activeLoweringGroups=[];diagnostics;constructor(t=[]){this.diagnostics=t}registerFunctions(t){let e=this.loweringAugmenters=[],n=this.loweringFinalizers=[];for(let o of t){let s=o;s.loweringAugment&&e.push(s.loweringAugment),s.loweringFinalize&&n.push(s.loweringFinalize)}}setPageConfig(t){this.page=t}lowerDocument(t){this.cnt=0,this.usedTracks.clear(),this.attachments=[],this.page=void 0,this.astToTemporal=new Map,this.activeLoweringGroups=[];let e=new Ft,n=new M,o=this.trackedEvents(t,n,e);return this.solidifyColumns(o),this.postprocessResult({diagnostics:this.diagnostics,columns:o,attachments:this.attachments,astToTemporal:this.astToTemporal,duration:n,rootTrack:e,tracks:[...this.usedTracks],page:this.page})}solidifyColumns(t){let e=0;for(let o of t){let s=0;for(let i of o)i.breakBefore>s&&(s=i.breakBefore);e+=s,o.layoutLine=e}let n={bpm:ot,velocity:_t,keySignature:Nt};for(let o of t)for(let s of o)s.onTimeState?.(n)}beginLoweringGroup(t,e){this.activeLoweringGroups.push({owner:t,group:e})}endLoweringGroup(t){let e=this.activeLoweringGroups.pop();if(!e)throw new Error("No active lowering group to end");if(e.owner!==t)throw new Error("Lowering groups must end in reverse order");return e.group.attachment&&this.addAttachment(e.group.attachment),e.group}postprocessResult(t){if(this.activeLoweringGroups.length>0)throw new Error("Lowering groups must be closed before post-processing");let e=[];for(let n of this.loweringAugmenters)for(let o of n(t))e.push(o);for(let n of e)this.addAttachment(n);for(let n of this.loweringFinalizers)n(t);return t}addAttachment(t){this.attachments.push(t);for(let e=this.activeLoweringGroups.length-1;e>=0;e--)this.activeLoweringGroups[e].group.onAttachment?.(t)}getTemporalNodes(t){return this.astToTemporal.get(t)??[]}isolateFromLoweringGroups(t){let e=this.activeLoweringGroups;this.activeLoweringGroups=[];try{return t()}finally{this.activeLoweringGroups=e}}initEvent(t,e,n,o){t.t.add(n),this.usedTracks.add(o),t.track=o,t.ast??=e,t.order=this.cnt++,t.mergeKey??=t.order}trackedEvents(t,e,n){let o=[];this.appendEvents(t.loweringEnter(this,n),t,e,n,o);let s=t.timeFlowModel();if(s)switch(s.mode){case"sequence":for(let i of s.children)for(let a of this.trackedEvents(i,e,n))o.push(a);break;case"parallel":{let i=s.tracks,a=s.children,c=i.hostIndex===void 0?0:i.hostIndex,l=n.group(i,c===null?a.length:a.length-1),h=[];for(let f=0;f<a.length;f++){let g=a[f],d=f===c?n:l.members[c===null||f<c?f:f-1],y=e.clone(),x=this.trackedEvents(g,y,d);x.length===0&&this.diagnostics.push(E.warning.ZeroTimeTrack(g.sourceSpan,f+1)),h.push(x)}for(let f of r.anchorAlign(h))o.push(f);let u=o[o.length-1];if(u){let f=u[0].T;for(let g=1;g<u.length;g++)u[g].T.compare(f)>0&&(f=u[g].T);e.copyFrom(u.t).add(f)}}break}return this.appendEvents(t.loweringExit(this,n,e),t,e,n,o),o}appendEvents(t,e,n,o,s){let i;for(let a of t){this.initEvent(a,e,n,o),this.indexTemporal(a);for(let l=this.activeLoweringGroups.length-1;l>=0;l--)this.activeLoweringGroups[l].group.onTemporal?.(a);let c=(i??=new M).copyFrom(a.t).add(a.T);c.compare(n)>0&&n.copyFrom(c),s.push(new vn(a))}}indexTemporal(t){let e=this.astToTemporal.get(t.ast);e?e.push(t):this.astToTemporal.set(t.ast,[t])}static anchorAlign(t){for(let l=t.length-1;l>=0;l--)t[l].length===0&&t.splice(l,1);let e=t.length;if(e===0)throw new Error("No tracks to align");if(e===1)return t[0];let n=[];if(e===2){let l=t[0],h=t[1],u=l.length,f=h.length,g=0,d=0,y=new M,x=new M,p=l[0],m=h[0],b=p.t.clone(),w=m.t.clone();for(;;){if(p.mergeKey===W){if(m.mergeKey!==W){for(n.push(m),m=h[++d];d<f&&m.mergeKey!==W;)x.isZero()||m.shiftTime(x),n.push(m),m=h[++d];m&&(m.shiftTime(x),w.copyFrom(m.t))}if(d<f){let N=b.compare(w)>=0?b:w;y.add(N).sub(b),x.add(N).sub(w),p.push(...m),p.t=N,m=h[++d]}if(n.push(p),p=l[++g],p&&(p.shiftTime(y),b.copyFrom(p.t)),m&&(m.shiftTime(x),w.copyFrom(m.t)),!p||!m)break}if(m.mergeKey===W){if(p.mergeKey!==W){for(n.push(p),p=l[++g];g<u&&p.mergeKey!==W;)y.isZero()||p.shiftTime(y),n.push(p),p=l[++g];p&&(p.shiftTime(y),b.copyFrom(p.t))}if(g<u){let N=b.compare(w)>=0?b:w;y.add(N).sub(b),x.add(N).sub(w),m.push(...p),m.t=N,p=l[++g]}if(n.push(m),m=h[++d],p&&(p.shiftTime(y),b.copyFrom(p.t)),m&&(m.shiftTime(x),w.copyFrom(m.t)),!p||!m)break}if(b.equals(w)){if(p.mergeKey===m.mergeKey){if(p.push(...m),n.push(p),p=l[++g],m=h[++d],p&&(p.shiftTime(y),b.copyFrom(p.t)),m&&(m.shiftTime(x),w.copyFrom(m.t)),!p||!m)break}else if(p.mergeKey<m.mergeKey)if(n.push(p),p=l[++g],p)p.shiftTime(y),b.copyFrom(p.t);else break;else if(n.push(m),m=h[++d],m)m.shiftTime(x),w.copyFrom(m.t);else break;continue}if(b.compare(w)<0)if(n.push(p),p=l[++g],p){p.shiftTime(y),b.copyFrom(p.t);continue}else break;if(w.compare(b)<0)if(n.push(m),m=h[++d],m){m.shiftTime(x),w.copyFrom(m.t);continue}else break}for(p&&n.push(p);++g<u;)p=l[g],y.isZero()||p.shiftTime(y),n.push(p);for(m&&n.push(m);++d<f;)m=h[d],x.isZero()||m.shiftTime(x),n.push(m);return n}let o=new Uint16Array(e),s=Array.from({length:e},()=>new M),i=[],a=new Mn(e);for(let l=0;l<e;l++)a.push({e:t[l][0],i:l});let c=l=>{let h=t[l][++o[l]];h&&(s[l].isZero()||h.shiftTime(s[l]),a.push({e:h,i:l}))};for(;;){let l=a.pop();if(l===void 0){if(i.length===0)break;let u=i[0],f=u.e,g=f.t;for(let d=1;d<i.length;d++)i[d].e.t.compare(g)>0&&(g=i[d].e.t);s[u.i].add(g).sub(f.t),c(u.i);for(let d=1;d<i.length;d++){let y=i[d];f.push(...y.e),s[y.i].add(g).sub(y.e.t),c(y.i)}i.length=0,f.t=g,f.sort((d,y)=>d.order-y.order),n.push(f);continue}if(l.e.mergeKey===W){i.push(l);continue}let h=[l.i];for(;;){let u=a.front();if(!u||!u.e.t.equals(l.e.t)||u.e.mergeKey!==l.e.mergeKey)break;a.pop(),l.e.push(...u.e),h.push(u.i)}n.push(l.e);for(let u of h)c(u)}return n}},vn=class extends Array{mergeKey;constructor(t){super(1),this.mergeKey=t.mergeKey,this[0]=t}get t(){return this[0].t}set t(t){for(let e of this)e.t.copyFrom(t)}shiftTime(t){for(let e of this)e.t.add(t)}set layoutLine(t){for(let e of this)e.layoutLine=t}};function Cn(r,t){let e=r.e.t.compare(t.e.t);return e!==0?e:r.e.mergeKey!==t.e.mergeKey?r.e.mergeKey<t.e.mergeKey?-1:1:r.i-t.i}var Mn=class extends Array{validLen=0;constructor(t){super(t)}front(){if(this.validLen!==0)return this[0]}push(t){return this[this.validLen]=t,this.up(this.validLen++),this.validLen}pop(){if(this.validLen===0)return;let t=this[0];return this[0]=this[--this.validLen],this[this.validLen]=void 0,this.down(0),t}up(t){let e=this[t];for(;t>0;){let n=t-1>>1;if(Cn(e,this[n])>=0)break;this[t]=this[n],t=n}this[t]=e}down(t){let e=this[t];for(;;){let n=(t<<1)+1,o=n+1;if(n>=this.validLen)break;let s=n;if(o<this.validLen&&Cn(this[o],this[n])<0&&(s=o),Cn(this[s],e)>=0)break;this[t]=this[s],t=s}this[t]=e}};var In=10,Rn=13,Ti=9,Li=11,Ei=12,_i=32,Ni=160,ki=5760,Ci=8239,vi=8287,Mi=12288,Ii=65279,Ri=34,cs=92,Oi=37,Pi=32,Di=[];function Fi(r){return r>Pi?" ".repeat(r):Di[r]??=" ".repeat(r)}function ls(r){return r===_i||r===Ti||r===Li||r===Ei?!0:r<128?!1:r===Ni||r===ki||r>=8192&&r<=8202||r===Ci||r===vi||r===Mi||r===Ii}function pe(r){let t=r.length,e=[0],n=[],o=[],s=(p,m)=>{if(p>=m)return;let b=o.length;if(b>=2&&p<=o[b-1]){m>o[b-1]&&(o[b-1]=m);return}o.push(p,m)},i=(p,m)=>{if(m<=0)return;let b=p+m;for(let w=p;w<b;w+=2)s(w,w+1)},a=0,c=!1,l=!1,h=-1,u=-1,f=-1,g=0,d=(p,m)=>{if(m===cs){g>0&&u+1===p?g++:(f=p,g=1),u=p;return}f=-1,g=0,u=p};for(let p=0;p<t;){let m=r.charCodeAt(p);if(m===Rn||m===In){let b=m===Rn&&p+1<t&&r.charCodeAt(p+1)===In?2:1;e.push(p+b);let w=(g&1)===1;i(f,g),h>=0&&(s(h,p),n.push({start:h,end:p}),h=-1),w&&s(p,p+b),u=-1,f=-1,g=0,l=!1,p+=b;continue}if(a!==0){l?l=!1:m===cs?l=!0:m===a&&(a=0),ls(m)||d(p,m),p++;continue}if(m===Ri){c||(At(r,p,t)<0?c=!0:a=m),d(p,m),p++;continue}if(m===Oi){for(h=p,p++;p<t;){let b=r.charCodeAt(p);if(b===Rn||b===In)break;p++}continue}ls(m)||d(p,m),p++}if(i(f,g),h>=0&&(s(h,t),n.push({start:h,end:t})),o.length===0)return{maskedSource:r,lineStarts:e,commentSpans:n};let y=[],x=0;for(let p=0;p<o.length;p+=2){let m=o[p],b=o[p+1];x<m&&y.push(r.slice(x,m)),y.push(Fi(b-m)),x=b}return x<t&&y.push(r.slice(x)),{maskedSource:y.join(""),lineStarts:e,commentSpans:n}}function $i(r,t={}){let{functions:e=fe,textMeasurer:n,fontSize:o,...s}=t,{maskedSource:i,lineStarts:a}=pe(r),c=new X({source:i});o&&(c.fontSize=o),c.registerFunctions(e);let l=new $({start:0,end:r.length},c.parse()),h=new $t(c.diagnostics);h.registerFunctions(e);let u=h.lowerDocument(l),f=kn(e,{textMeasurer:n}),g=Re(u,f,s);return{lineStarts:a,parser:c,ast:l,lowering:u,layout:g}}function Bi(r,t=fe){let{maskedSource:e,commentSpans:n}=pe(r),o=new X({source:e,commentSpans:n});return o.registerFunctions(t),{syntax:o.parseSyntax(),diagnostics:o.diagnostics}}function On(r){return typeof r.applyPlayback=="function"}function me(r,t){let e=Math.max(0,t),n=0,o=0,s=ot;for(let i of r){if(i.kind!=="tempo")continue;let a=i.at.toNumber();if(a>e)break;a>o&&(n+=(a-o)*60/s),o=a,s=i.bpm}return n+(e-o)*60/s}function hs(r,t){let e=Math.max(0,t),n=0,o=ot;for(let s of r){if(s.kind!=="tempo")continue;let i=s.at.toNumber(),a=(i-n)*60/o;if(e<a)return n+e*o/60;e-=a,n=i,o=s.bpm}return n+e*o/60}function us(r,t){let e=Math.max(0,t),n=e;for(let o of r){let s=o.performance.toNumber();if(s>e)break;n=o.score.toNumber()+e-s}return n}function fs(r,t){let e=Math.max(0,t),n;for(let o=0;o<r.length;o++){let s=r[o],i=s.score.toNumber();if(i>e){(!n||i<n.score.toNumber())&&(n=s);continue}let a=r[o+1],c=a?a.performance.toNumber()-s.performance.toNumber():1/0;if(!(e-i>=c))return s.performance.toNumber()+(e-i)}return n?.performance.toNumber()??e}function zi(r,t){let e=Math.min(hs(r.events,t),r.performanceDuration.toNumber());return us(r.scoreMap,e)}function Hi(r,t){let e=Math.min(fs(r.scoreMap,t),r.performanceDuration.toNumber());return me(r.events,e)}var ps={tempo:0,"time-signature":1,"note-off":2,"note-on":3};function Pn(r,t){return r.at.compare(t.at)||ps[r.kind]-ps[t.kind]||r.order-t.order}function ms(r,t){let e=new Map,n=new Map;for(let a of r)if(a.kind==="note-on"){if(e.has(a.noteId))throw new Error(`Duplicate NoteOn ${a.noteId}`);e.set(a.noteId,a)}else if(a.kind==="note-off"){if(n.has(a.noteId))throw new Error(`Duplicate NoteOff ${a.noteId}`);n.set(a.noteId,a)}for(let[a,c]of e){let l=n.get(a);if(!l)throw new Error(`Note ${a} has no NoteOff`);if(l.at.compare(c.at)<=0)throw new Error(`Note ${a} has a non-positive duration`);if(c.origins.length===0||l.origins.length===0)throw new Error(`Note ${a} has no origin`)}for(let a of n.keys())if(!e.has(a))throw new Error(`NoteOff ${a} has no NoteOn`);let o=new Set;for(let a of e.values())o.add(a.track);let s=new Map;for(let a of t)o.has(a)&&s.set(a,s.size);for(let a of o)s.has(a)||s.set(a,s.size);return{events:r.map(a=>{if(a.kind==="tempo")return{kind:"tempo",at:a.at,bpm:a.bpm};if(a.kind==="time-signature")return{kind:"time-signature",at:a.at,numerator:a.numerator,denominator:a.denominator};let c=a.kind==="note-on"?a:e.get(a.noteId),l=s.get(c.track);return a.kind==="note-on"?{kind:"note-on",at:a.at,noteId:a.noteId,track:l,midi:a.midi,velocity:a.velocity,sourceSpans:a.sourceSpans}:{kind:"note-off",at:a.at,noteId:a.noteId,track:l,midi:c.midi}}),tracks:[...s.keys()]}}function Wi(r,t,e){let n=r.columns,o=new Map;for(let x=0;x<n.length;x++)for(let p of n[x])o.set(p,x);let s=x=>{for(let p=x;p;p=p.foldedInto){let m=o.get(p);if(m!==void 0)return m}},i=new Map,a=new Map,c=(x,p)=>{let m=x.playbackFlow?.(s);if(!m)return;let[b,w]=m.range??[0,n.length-1];if(m.range&&(!Number.isSafeInteger(b)||!Number.isSafeInteger(w)||b<0||w<b||w>=n.length))throw new S("E_PLAYBACK_FLOW_RANGE",`\u64AD\u653E\u63A7\u5236\u6D41\u8303\u56F4 [${b}, ${w}] \u8D85\u51FA\u65F6\u95F4\u5217\u8FB9\u754C`,p);let N={hook:m,sourceSpan:p};for(let I=b;I<=w;I++){let F=a.get(I);F?F.push(N):a.set(I,[N])}};for(let x of r.astToTemporal.values())for(let p of x){c(p,p.ast.sourceSpan);let m=p.playbackMarks?.();if(!m)continue;let b=s(p);if(b!==void 0)for(let w of m){let N=i.get(w);N?N.push(b):i.set(w,[b])}}for(let x of r.attachments)c(x,x.sourceSpan??{start:0,end:0});if(a.size===0)return n.map((x,p)=>p);for(let x of i.values())x.sort((p,m)=>p-m);let l=new Array(n.length).fill(0),h=0,u={get column(){return h},visits:x=>l[x]??0,seek(x,p,m){let b=i.get(x);if(b){if(m>0)return b.find(w=>w>p);for(let w=b.length-1;w>=0;w--)if(b[w]<p)return b[w]}}},f=[],g=0;for(;h<n.length;){if(++g>e)throw new S("E_PLAYBACK_FLOW_LIMIT",`\u64AD\u653E\u63A7\u5236\u6D41\u8BBF\u95EE\u8D85\u8FC7 ${e} \u6B65\uFF1B\u53EF\u901A\u8FC7 maxFlowSteps \u63D0\u9AD8\u5C55\u5F00\u9884\u7B97`,n[h][0].ast.sourceSpan);l[h]++;let x;for(let p of a.get(h)??[]){let b=p.hook.run(u);if(b){if(b.kind==="stop")return f;if(!Number.isSafeInteger(b.column)||b.column<0||b.column>n.length)throw new S("E_PLAYBACK_FLOW_JUMP",`\u64AD\u653E\u63A7\u5236\u6D41\u8DF3\u8F6C\u76EE\u6807 ${b.column} \u8D85\u51FA\u65F6\u95F4\u5217\u8FB9\u754C`,p.sourceSpan);x=Math.min(x??1/0,b.column)}}x!==void 0?h=x:(f.push(h),h++)}let d=new Set(f),y=!1;for(let x=0;x<n.length;x++){let p=!d.has(x);p&&!y&&t.push(new C("W_PLAYBACK_COLUMN_NEVER_PLAYED","\u8FD9\u91CC\u5728\u4EFB\u4F55\u4E00\u904D\u91CC\u90FD\u4E0D\u4F1A\u6F14\u594F",n[x][0].ast.sourceSpan)),y=p}return f}function Gi(r,t){let e=t?.maxFlowSteps??65536;if(!Number.isSafeInteger(e)||e<=0)throw new S("E_PLAYBACK_FLOW_LIMIT","maxFlowSteps \u5FC5\u987B\u662F\u6B63\u5B89\u5168\u6574\u6570",r.columns[0]?.[0]?.ast.sourceSpan??{start:0,end:0});let n=[],o=[],s=[],i=0,a=0,c=()=>a++,l=[],h=(A,_,k)=>l.push({at:A.clone(),origins:_,apply:k});function u(A,_,k,P,K=[]){let z={node:A},Z=[...K,z];if(A.playbackState){let{bpm:G}=A.playbackState;h(k,Z,Y=>{G&&(Y.bpm=G)})}let B=_.length,dt=[..._],ye=[],be,Bn=!1;A.emitPlayback?.({start:k,end:k.clone().add(P),track:A.track,nextNoteId:c,emit(G){let Y={...G,at:G.at.clone(),order:i++,origins:[...Z]};if(Y.kind==="note-on"){Bn=!0;let nt={...Y,track:A.track,sourceSpans:[{...A.ast.sourceSpan}]};ye.push(nt),s.push(nt)}else ye.push(Y),s.push(Y)},control:(G,Y)=>h(G,Z,Y),affectFollowing:G=>_.push(G),defer:G=>(be??=[]).push(G),play:(G,Y,nt)=>u(G,dt,Y??k,nt??P,Z)}),B>0&&Bn&&s.push(G=>{let Y=ye;for(let nt=0;nt<B;nt++){let zn=Y.length,we=dt[nt](G,Y);we&&(G.events.splice(G.events.length-zn,zn,...we),Y=we)}}),be&&s.push(...be)}let f=Wi(r,n,e),g=r.columns[f[0]]?.[0]?.t.clone()??new M,d=[{performance:new M,score:g}],y=new M().sub(g),x=new M;for(let A=0;A<f.length;A++){let _=f[A];for(let B of r.columns[_])u(B,[],B.t.clone().add(y),B.T.clone());let k=r.columns[_+1]?.[0]?.t??r.duration;x.copyFrom(k).add(y);let P=f[A+1];if(P===void 0||P===_+1)continue;let K=r.columns[P][0]?.t.clone()??new M;y.add(k).sub(K);let z={performance:x.clone(),score:K};d[d.length-1].performance.equals(z.performance)?d[d.length-1]=z:d.push(z)}let p={bpm:ot,bpmScale:new M(1)},m=[],b,w=()=>({bpm:p.bpm,bpmScale:p.bpmScale.clone(),effectiveBpm:p.bpm*p.bpmScale.toNumber()}),N=(A,_)=>{let k=w();if(!Number.isFinite(k.effectiveBpm)||k.effectiveBpm<=0)throw new Error("Playback controls produced an invalid BPM");let P=m[m.length-1];P&&P.state.bpm===k.bpm&&P.state.bpmScale.equals(k.bpmScale)||(m.push({at:A,state:k}),b!==k.effectiveBpm&&(b=k.effectiveBpm,o.push({kind:"tempo",at:A.clone(),bpm:k.effectiveBpm,order:i++,origins:_})))};l.sort((A,_)=>A.at.compare(_.at));let I=0;for(l[0]?.at.compare(0)!==0&&N(new M,[]);I<l.length;){let A=l[I].at.clone(),_=[];for(;I<l.length&&A.equals(l[I].at);){let k=l[I++];k.apply(p);for(let P of k.origins)_.includes(P)||_.push(P)}N(A,_)}let F={events:o,diagnostics:n,nextNoteId:c,stateAt:A=>{let _=0,k=m.length;for(;_<k;){let P=_+k>>>1;m[P].at.compare(A)<=0?_=P+1:k=P}return m[_-1]?.state??w()}};for(let A of s)typeof A=="function"?A(F):o.push(A);o.sort(Pn);for(let A of r.attachments)On(A)&&A.applyPlayback(F);o.sort(Pn);let T=ms(o,r.tracks),v=o.at(-1)?.at;return v&&v.compare(x)>0&&x.copyFrom(v),{events:T.events,scoreMap:d,tracks:T.tracks,performanceDuration:x,durationSeconds:me(T.events,x.toNumber()),diagnostics:n}}function mt(r){return r.pages.length>0?r.pages.map(t=>t.bounds):[r.bounds]}function Fn(r,t){for(let e of r.attachments)e.layer==="background"&&e.paint(t);for(let e of r.objects){e.paint(t);for(let n of e.decorations)n.paint(t)}for(let e of r.attachments)e.layer==="foreground"&&e.paint(t)}var Dn=class{pages;painters;constructor(t,e){this.pages=t,this.painters=e}route(t,e,n){let o=0,s=this.pages.length;for(;o<s;){let i=o+s>>>1,a=this.pages[i];a.y+a.h<t?o=i+1:s=i}for(let i=o;i<this.pages.length&&this.pages[i].y<=e;i++)n(this.painters[i])}drawText(t,e,n,o){this.route(n,n,s=>s.drawText(t,e,n,o))}drawLine(t,e,n,o,s){let i=(s?.strokeWidth??1)/2;this.route(Math.min(e,o)-i,Math.max(e,o)+i,a=>a.drawLine(t,e,n,o,s))}drawRect(t,e,n,o,s){let i=s?.stroke?(s.strokeWidth??1)/2:0;this.route(e-i,e+Math.max(0,o)+i,a=>{a.drawRect(t,e,n,o,s)})}drawCircle(t,e,n,o){let s=o?.stroke?(o.strokeWidth??1)/2:0,i=Math.max(0,n)+s;this.route(e-i,e+i,a=>a.drawCircle(t,e,n,o))}drawPath(t,e,n){if(t.length===0)return;let o=n?l=>n.y+l*n.scaleY:l=>l,s=1/0,i=-1/0,a=l=>{let h=o(l);s=Math.min(s,h),i=Math.max(i,h)};for(let l of t)l.op!=="Z"&&(l.op==="Q"&&a(l.cy),l.op==="C"&&(a(l.cy1),a(l.cy2)),a(l.y));if(!Number.isFinite(s))return;let c=e?.stroke?(e.strokeWidth??1)/2:0;this.route(s-c,i+c,l=>{l.drawPath(t,e,n)})}};function de(r,t){let e=mt(r);if(t.length!==e.length)throw new Error(`Expected ${e.length} page painters, got ${t.length}`);Fn(r,new Dn(e,t))}var $n=class{commands=[];drawText(t,e,n,o){this.commands.push({kind:"text",text:t,x:e,y:n,style:o})}drawLine(t,e,n,o,s){this.commands.push({kind:"line",x1:t,y1:e,x2:n,y2:o,style:s})}drawRect(t,e,n,o,s){this.commands.push({kind:"rect",x:t,y:e,w:n,h:o,style:s})}drawCircle(t,e,n,o){this.commands.push({kind:"circle",cx:t,cy:e,r:n,style:o})}drawPath(t,e,n){this.commands.push({kind:"path",commands:t.map(o=>Vi(o,n)),style:e})}};function Vi(r,t){if(!t||r.op==="Z")return{...r};let e=o=>t.x+o*t.scaleX,n=o=>t.y+o*t.scaleY;return r.op==="M"||r.op==="L"?{op:r.op,x:e(r.x),y:n(r.y)}:r.op==="Q"?{op:"Q",cx:e(r.cx),cy:n(r.cy),x:e(r.x),y:n(r.y)}:r.op==="C"?{op:"C",cx1:e(r.cx1),cy1:n(r.cy1),cx2:e(r.cx2),cy2:n(r.cy2),x:e(r.x),y:n(r.y)}:{...r}}function O(r){return Number.isFinite(r)?String(Math.round(r*1e3)/1e3):"0"}function j(r){return r.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function Yi(r,t){let e=[],n=t?s=>O(t.x+s*t.scaleX):O,o=t?s=>O(t.y+s*t.scaleY):O;for(let s of r){if(s.op==="Z"){e.push("Z");continue}if(s.op==="M"||s.op==="L"){e.push(`${s.op}${n(s.x)} ${o(s.y)}`);continue}if(s.op==="Q"){e.push(`Q${n(s.cx)} ${o(s.cy)} ${n(s.x)} ${o(s.y)}`);continue}"cx1"in s&&e.push(`C${n(s.cx1)} ${o(s.cy1)} ${n(s.cx2)} ${o(s.cy2)} ${n(s.x)} ${o(s.y)}`)}return e.join(" ")}function Bt(r){return r?.opacity===void 0?"":` opacity="${O(r.opacity)}"`}var ge=class{body=[];drawText(t,e,n,o){let s=o.fontFamily??qt,i=o.fontWeight??"normal",a=o.fill??"#000",c=o.textAlign==="center"?"middle":o.textAlign==="right"?"end":"start";this.body.push(`<text x="${O(e)}" y="${O(n)}" font-family="${j(s)}" font-size="${O(o.fontSize)}" font-weight="${j(String(i))}" text-anchor="${c}" fill="${j(a)}" xml:space="preserve"${Bt(o)}>${j(t)}</text>`)}drawLine(t,e,n,o,s){let i=s?.stroke??s?.fill??"#000",a=s?.strokeWidth??1;this.body.push(`<line x1="${O(t)}" y1="${O(e)}" x2="${O(n)}" y2="${O(o)}" stroke="${j(i)}" stroke-width="${O(a)}" stroke-linecap="round"${Bt(s)} />`)}drawRect(t,e,n,o,s){let i=s?.fill??"none",a=s?.stroke??"none",c=s?.strokeWidth??1;this.body.push(`<rect x="${O(t)}" y="${O(e)}" width="${O(Math.max(0,n))}" height="${O(Math.max(0,o))}" fill="${j(i)}" stroke="${j(a)}" stroke-width="${O(c)}"${Bt(s)} />`)}drawCircle(t,e,n,o){let s=o?.fill??"#000",i=o?.stroke??"none",a=o?.strokeWidth??1;this.body.push(`<circle cx="${O(t)}" cy="${O(e)}" r="${O(Math.max(0,n))}" fill="${j(s)}" stroke="${j(i)}" stroke-width="${O(a)}"${Bt(o)} />`)}drawPath(t,e,n){if(t.length===0)return;let o=Yi(t,n),s=e?.fill??"none",i=e?.stroke??"none",a=e?.strokeWidth??1;this.body.push(`<path d="${o}" fill="${j(s)}" stroke="${j(i)}" stroke-width="${O(a)}" stroke-linecap="round" stroke-linejoin="round"${Bt(e)} />`)}toSvg(t,e={}){let n=Math.max(0,e.padding??0),o=t.x-n,s=t.y-n,i=Math.max(1,t.w+n*2),a=Math.max(1,t.h+n*2),c=e.background?`<rect x="${O(o)}" y="${O(s)}" width="${O(i)}" height="${O(a)}" fill="${j(e.background)}" />`:"";return`<svg xmlns="http://www.w3.org/2000/svg" width="${O(i)}" height="${O(a)}" viewBox="${O(o)} ${O(s)} ${O(i)} ${O(a)}">${c}${this.body.join("")}</svg>`}};function Ui(r,t={}){let e=mt(r),n=e.map(()=>new ge);return de(r,n),n.map((o,s)=>o.toSvg(e[s],t))}function Ki(r,t,e=0,n=0,o=1,s=1){r.beginPath();for(let i of t){if(i.op==="Z"){r.closePath();continue}if(i.op==="M"){r.moveTo(e+i.x*o,n+i.y*s);continue}if(i.op==="L"){r.lineTo(e+i.x*o,n+i.y*s);continue}if(i.op==="Q"){r.quadraticCurveTo(e+i.cx*o,n+i.cy*s,e+i.x*o,n+i.y*s);continue}"cx1"in i&&r.bezierCurveTo(e+i.cx1*o,n+i.cy1*s,e+i.cx2*o,n+i.cy2*s,e+i.x*o,n+i.y*s)}}function zt(r,t){t?.opacity!==void 0&&(r.globalAlpha*=t.opacity)}var xe=class{context;constructor(t){this.context=t}drawText(t,e,n,o){this.context.save(),zt(this.context,o),this.context.fillStyle=o.fill??"#000",this.context.font=Qt(o),this.context.textAlign=o.textAlign??"left",this.context.textBaseline="alphabetic",this.context.fillText(t,e,n),this.context.restore()}drawLine(t,e,n,o,s){this.context.save(),zt(this.context,s),this.context.beginPath(),this.context.moveTo(t,e),this.context.lineTo(n,o),this.context.strokeStyle=s?.stroke??s?.fill??"#000",this.context.lineWidth=s?.strokeWidth??1,this.context.lineCap="round",this.context.stroke(),this.context.restore()}drawRect(t,e,n,o,s){n<0||o<0||(this.context.save(),zt(this.context,s),s?.fill&&(this.context.fillStyle=s.fill,this.context.fillRect(t,e,n,o)),s?.stroke&&(this.context.strokeStyle=s.stroke,this.context.lineWidth=s.strokeWidth??1,this.context.strokeRect(t,e,n,o)),this.context.restore())}drawCircle(t,e,n,o){n<0||(this.context.save(),zt(this.context,o),this.context.beginPath(),this.context.arc(t,e,n,0,Math.PI*2),(o?.fill??!0)&&(this.context.fillStyle=o?.fill??"#000",this.context.fill()),o?.stroke&&(this.context.strokeStyle=o.stroke,this.context.lineWidth=o.strokeWidth??1,this.context.stroke()),this.context.restore())}drawPath(t,e,n){t.length!==0&&(this.context.save(),zt(this.context,e),Ki(this.context,t,n?.x,n?.y,n?.scaleX,n?.scaleY),e?.fill&&(this.context.fillStyle=e.fill,this.context.fill()),e?.stroke&&(this.context.strokeStyle=e.stroke,this.context.lineWidth=e.strokeWidth??1,this.context.lineCap="round",this.context.lineJoin="round",this.context.stroke()),this.context.restore())}};function ji(r,t){let e=mt(r);if(t.length!==e.length)throw new Error(`Expected ${e.length} page contexts, got ${t.length}`);for(let[n,o]of t.entries())o.save(),o.translate(-e[n].x,-e[n].y);try{de(r,t.map(n=>new xe(n)))}finally{for(let n of t)n.restore()}}return ws(Zi);})();
|