Files
pages/static/vendor/city-generator/gen-city.bundle.js
T
Anya Tokugawa c1175d389f Implement Knowledge City platform, organizer and DAV integration
Capture accumulated application, UI, CLI, regression tests and design documentation changes, including task project mapping and default CalDAV list naming.

Keep deployment data, backups, local credentials and build artifacts out of Git. Move the Compose enrollment token to an ignored local environment file.
2026-09-27 14:44:43 +09:00

412 lines
20 KiB
JavaScript

var PagesWikiGenCity = (() => {
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __commonJS = (cb, mod) => function __require() {
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
};
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// node_modules/gen-city/dist/index.js
var require_dist = __commonJS({
"node_modules/gen-city/dist/index.js"(exports, module) {
(() => {
"use strict";
var t = { 895: (t2, i2) => {
Object.defineProperty(i2, "__esModule", { value: true }), i2.Building = void 0, i2.Building = class {
constructor(t3, i3) {
if (4 !== i3.length) throw Error("Invalid building vertices");
this.path = t3, this.vertices = i3;
const e2 = this.vertices.map((t4) => t4.x), s = this.vertices.map((t4) => t4.y);
this.position = { x: Math.min(...e2), y: Math.min(...s) }, this.width = Math.max(...e2) - this.position.x + 1, this.height = Math.max(...s) - this.position.y + 1;
}
remove() {
const t3 = this.path.getBuildings(), i3 = t3.findIndex((t4) => t4 === this);
-1 !== i3 && t3.splice(i3, 1);
}
each(t3) {
for (let i3 = 0; i3 < this.width; i3++) for (let e2 = 0; e2 < this.height; e2++) t3({ x: this.position.x + i3, y: this.position.y + e2 });
}
};
}, 863: function(t2, i2, e2) {
var s = this && this.__awaiter || function(t3, i3, e3, s2) {
return new (e3 || (e3 = Promise))(function(n2, r2) {
function o2(t4) {
try {
a(s2.next(t4));
} catch (t5) {
r2(t5);
}
}
function h2(t4) {
try {
a(s2.throw(t4));
} catch (t5) {
r2(t5);
}
}
function a(t4) {
var i4;
t4.done ? n2(t4.value) : (i4 = t4.value, i4 instanceof e3 ? i4 : new e3(function(t5) {
t5(i4);
})).then(o2, h2);
}
a((s2 = s2.apply(t3, i3 || [])).next());
});
};
Object.defineProperty(i2, "__esModule", { value: true }), i2.City = void 0;
const n = e2(792), r = e2(82), o = e2(309), h = e2(679);
i2.City = class {
constructor({ width: t3, height: i3 }) {
this.seed = null, this.matrix = [], this.nodes = [], this.gauge = 1, this.params = {}, this.width = t3, this.height = i3;
}
getSeed() {
return this.seed;
}
getAllBuildings() {
return this.getAllPaths().map((t3) => t3.getBuildings()).flat();
}
getAllNodes() {
return this.nodes;
}
getAllPaths() {
return this.nodes.map((t3) => t3.getOutputPaths()).flat();
}
generate(t3 = {}) {
return s(this, void 0, void 0, function* () {
this.reset(), this.params = Object.assign({ mode: o.CityGenerationMode.RUNTIME, seed: [], startPosition: { x: Math.round(this.width / 2), y: Math.round(this.height / 2) }, startDirections: [0, 90, 180, 270], streetMinLength: 10, buildingMinSize: 3, buildingMaxSize: 6, buildingMinSpace: 1, buildingMaxSpace: 3, buildingOffset: 0, probabilityIntersection: 0.1, probabilityTurn: 0.05, probabilityStreetEnd: 1e-3 }, t3), this.params.mode === o.CityGenerationMode.SEED && (this.seed = 0 === this.params.seed.length ? (0, h.generateSeed)() : this.params.seed);
const i3 = this.addNode(this.params.startPosition);
this.markAt(this.params.startPosition, i3), this.params.startDirections.forEach((t4) => {
i3.addOutputPath(t4);
}), this.generatePaths(), this.generateBuildings();
});
}
reset() {
for (let t3 = 0; t3 < this.height; t3++) {
this.matrix[t3] = [];
for (let i3 = 0; i3 < this.width; i3++) this.matrix[t3][i3] = null;
}
this.seed = null, this.gauge = 1, this.nodes = [];
}
generatePaths() {
const t3 = () => {
const i3 = this.getAllPaths();
for (let t4 = 0, e3 = i3.length; t4 < e3; t4++) this.processingPath(i3[t4]);
i3.every((t4) => t4.isCompleted()) || t3();
};
t3();
}
processingPath(t3) {
if (t3.isCompleted()) return;
const i3 = t3.getNextCursor();
if (void 0 === this.getAt(i3) || this.variabilityChance(this.params.probabilityStreetEnd)) return void this.closePath(t3);
const e3 = this.getCross(t3);
if (null == e3 ? void 0 : e3.tile) {
let i4 = null;
return e3.tile instanceof n.Node ? i4 = e3.tile : e3.tile instanceof r.Path && (i4 = this.splitPath(e3.tile, e3.position)), void (i4 && t3.setNodeEnd(i4));
}
t3.setCursor(i3), this.markAt(t3.getCursor(), t3);
const s2 = this.params.streetMinLength;
t3.getLength() > s2 && !this.getCross(t3, s2) && (this.variabilityChance(this.params.probabilityIntersection) ? this.forkPath(t3) : this.variabilityChance(this.params.probabilityTurn) && this.turnPath(t3));
}
generateBuildings() {
this.getAllPaths().forEach((t3) => {
const i3 = (0, h.getShift)(t3.direction), e3 = t3.getNodeBeg().position.x + i3.x, s2 = t3.getNodeBeg().position.y + i3.y;
(0, h.turnDirection)(t3.direction).forEach((i4) => {
let n2 = this.params.buildingOffset;
for (; t3.getLength() > n2; ) {
const r2 = (0, h.getShift)(t3.direction, n2), o2 = (0, h.getShift)(i4, this.params.buildingOffset + 1), a = { x: e3 + r2.x + o2.x, y: s2 + r2.y + o2.y }, d = [this.variabilityRange(this.params.buildingMinSize, this.params.buildingMaxSize), this.variabilityRange(this.params.buildingMinSize, this.params.buildingMaxSize)];
if (n2 + d[0] + this.params.buildingOffset > t3.getLength()) break;
this.processingBuilding(t3, a, d, [t3.direction, i4]);
const u = this.variabilityRange(this.params.buildingMinSpace, this.params.buildingMaxSpace);
n2 += d[0] + u;
}
});
});
}
processingBuilding(t3, i3, e3, s2) {
const n2 = [], r2 = [];
for (let t4 = 0; t4 < e3[0]; t4++) {
const o3 = (0, h.getShift)(s2[0], t4), a = { x: i3.x + o3.x, y: i3.y + o3.y };
for (let i4 = 0; i4 < e3[1]; i4++) {
const o4 = (0, h.getShift)(s2[1], i4), d = { x: a.x + o4.x, y: a.y + o4.y };
if (!this.isEmptyAt(d)) return;
n2.push(d), 0 !== t4 && t4 !== e3[0] - 1 || 0 !== i4 && i4 !== e3[1] - 1 || r2.push(d);
}
}
const o2 = t3.addBuilding(r2);
n2.forEach((t4) => {
this.markAt(t4, o2);
});
}
getAt(t3) {
var i3, e3;
return null === (e3 = null === (i3 = this.matrix) || void 0 === i3 ? void 0 : i3[t3.y]) || void 0 === e3 ? void 0 : e3[t3.x];
}
markAt(t3, i3) {
this.matrix[t3.y][t3.x] = i3;
}
isEmptyAt(t3) {
return null === this.getAt(t3);
}
addNode(t3, i3) {
const e3 = new n.Node(this.nodes.length, t3);
return void 0 === i3 ? this.nodes.push(e3) : this.nodes.splice(i3, 0, e3), e3;
}
closePath(t3) {
const i3 = t3.getCursor(), e3 = this.addNode(i3);
return t3.setNodeEnd(e3), this.markAt(i3, e3), e3;
}
forkPath(t3) {
let i3 = (0, h.forkDirection)(t3.direction).sort(() => this.variabilityChance(0.5) ? 1 : -1);
if (i3 = this.filterDirections(t3, i3), 0 === i3.length || 1 === i3.length && i3[0] === t3.direction) return;
const e3 = this.closePath(t3);
for (let t4 = 0; t4 < i3.length; t4++) (t4 < 2 || this.variabilityChance(0.5)) && e3.addOutputPath(i3[t4]);
this.markAt(e3.position, e3);
}
turnPath(t3) {
let i3 = (0, h.turnDirection)(t3.direction).sort(() => this.variabilityChance(0.5) ? 1 : -1);
if (i3 = this.filterDirections(t3, i3), 0 === i3.length) return;
const e3 = this.closePath(t3);
e3.addOutputPath(i3[0]), this.markAt(e3.position, e3);
}
splitPath(t3, i3) {
const e3 = t3.getNodeBeg(), s2 = this.nodes.findIndex((t4) => t4 === e3), n2 = this.addNode(i3, s2 + 1), o2 = n2.addOutputPath(t3.direction);
this.markAt(i3, n2);
const h2 = t3.getNodeEnd();
return h2 ? o2.setNodeEnd(h2) : o2.setCursor(t3.getCursor()), o2.each((t4) => {
this.getAt(t4) instanceof r.Path && this.markAt(t4, o2);
}), t3.setNodeEnd(n2), n2;
}
getCross(t3, i3 = 1) {
const e3 = t3.getCursor();
for (let s2 = 1; s2 <= i3; s2++) {
const i4 = (0, h.getShift)(t3.direction, s2), n2 = { x: e3.x + i4.x, y: e3.y + i4.y };
if (!this.isEmptyAt(n2)) return { tile: this.getAt(n2), position: n2 };
}
return null;
}
filterDirections(t3, i3) {
return i3.filter((i4) => {
const e3 = (0, h.getShift)(i4), s2 = t3.getCursor(), n2 = { x: s2.x + e3.x, y: s2.y + e3.y };
return this.isEmptyAt(n2);
});
}
variabilityChance(t3) {
if (!this.seed) return (0, h.randomChance)(t3);
const i3 = this.seed[this.gauge % this.seed.length];
return this.gauge++, i3 / 1e3 >= 1 - t3;
}
variabilityRange(t3, i3) {
if (!this.seed) return (0, h.randomRange)(t3, i3);
const e3 = this.seed[this.gauge % this.seed.length];
return this.gauge++, Math.floor(t3 + e3 / 1e3 * (i3 - t3 + 1));
}
};
}, 465: function(t2, i2, e2) {
var s = this && this.__createBinding || (Object.create ? function(t3, i3, e3, s2) {
void 0 === s2 && (s2 = e3);
var n2 = Object.getOwnPropertyDescriptor(i3, e3);
n2 && !("get" in n2 ? !i3.__esModule : n2.writable || n2.configurable) || (n2 = { enumerable: true, get: function() {
return i3[e3];
} }), Object.defineProperty(t3, s2, n2);
} : function(t3, i3, e3, s2) {
void 0 === s2 && (s2 = e3), t3[s2] = i3[e3];
}), n = this && this.__exportStar || function(t3, i3) {
for (var e3 in t3) "default" === e3 || Object.prototype.hasOwnProperty.call(i3, e3) || s(i3, t3, e3);
};
Object.defineProperty(i2, "__esModule", { value: true }), n(e2(863), i2), n(e2(895), i2), n(e2(792), i2), n(e2(82), i2), n(e2(309), i2);
}, 792: (t2, i2, e2) => {
Object.defineProperty(i2, "__esModule", { value: true }), i2.Node = void 0;
const s = e2(82), n = e2(309);
i2.Node = class {
constructor(t3, i3) {
this.outputPaths = [], this.inputPaths = [], this.id = t3, this.position = i3;
}
addOutputPath(t3) {
const i3 = new s.Path(this, t3);
return this.outputPaths.push(i3), i3;
}
removeOutputPath(t3) {
const i3 = this.outputPaths.indexOf(t3);
-1 !== i3 && this.outputPaths.splice(i3, 1);
}
getOutputPaths() {
return this.outputPaths;
}
addInputPath(t3) {
const i3 = t3.getNodeEnd();
i3 && i3.removeInputPath(t3), this.inputPaths.push(t3);
}
removeInputPath(t3) {
const i3 = this.inputPaths.indexOf(t3);
-1 !== i3 && this.inputPaths.splice(i3, 1);
}
getInputPaths() {
return this.inputPaths;
}
getAllPaths() {
return this.outputPaths.concat(this.inputPaths);
}
getType() {
const t3 = this.outputPaths.length + this.inputPaths.length;
return 2 === t3 ? n.NodeType.TURN : 1 === t3 ? n.NodeType.END : n.NodeType.CROSS;
}
};
}, 82: (t2, i2, e2) => {
Object.defineProperty(i2, "__esModule", { value: true }), i2.Path = void 0;
const s = e2(895), n = e2(679);
i2.Path = class {
constructor(t3, i3) {
this.buildings = [], this.nodeEnd = null, this.direction = i3, this.nodeBeg = t3, this.cursor = t3.position;
}
getBuildings() {
return this.buildings;
}
getPositions() {
var t3, i3;
return { beg: this.nodeBeg.position, end: null !== (i3 = null === (t3 = this.nodeEnd) || void 0 === t3 ? void 0 : t3.position) && void 0 !== i3 ? i3 : this.cursor };
}
isCompleted() {
return Boolean(this.nodeEnd);
}
getNextCursor() {
const t3 = (0, n.getShift)(this.direction);
return { x: this.cursor.x + t3.x, y: this.cursor.y + t3.y };
}
getCursor() {
return this.cursor;
}
setCursor(t3) {
this.cursor = t3;
}
getNodeBeg() {
return this.nodeBeg;
}
getNodeEnd() {
return this.nodeEnd;
}
setNodeEnd(t3) {
t3.addInputPath(this), this.nodeEnd = t3, this.cursor = t3.position;
}
addBuilding(t3) {
const i3 = new s.Building(this, t3);
return this.buildings.push(i3), i3;
}
getLength() {
const t3 = this.getPositions();
return Math.hypot(t3.beg.x - t3.end.x, t3.beg.y - t3.end.y);
}
remove() {
this.nodeBeg.removeOutputPath(this), this.nodeEnd && this.nodeEnd.removeInputPath(this);
}
each(t3) {
const i3 = (0, n.getShift)(this.direction), e3 = this.getLength(), s2 = Object.assign({}, this.nodeBeg.position);
for (let n2 = 0; n2 <= e3; n2++) t3(s2), s2.x += i3.x, s2.y += i3.y;
}
};
}, 309: (t2, i2) => {
var e2, s;
Object.defineProperty(i2, "__esModule", { value: true }), i2.NodeType = i2.CityGenerationMode = void 0, function(t3) {
t3.RUNTIME = "RUNTIME", t3.SEED = "SEED";
}(e2 || (i2.CityGenerationMode = e2 = {})), function(t3) {
t3.TURN = "TURN", t3.CROSS = "CROSS", t3.END = "END";
}(s || (i2.NodeType = s = {}));
}, 679: (t2, i2) => {
function e2(t3) {
return t3 * (Math.PI / 180);
}
function s(t3) {
return [(t3 + 90) % 360, (t3 - 90) % 360];
}
Object.defineProperty(i2, "__esModule", { value: true }), i2.between = i2.getShift = i2.forkDirection = i2.turnDirection = i2.degToRad = i2.generateSeed = i2.randomRange = i2.randomItem = i2.randomChance = void 0, i2.randomChance = function(t3) {
return Math.random() > 1 - t3;
}, i2.randomItem = function(t3) {
return t3[Math.floor(Math.random() * t3.length)];
}, i2.randomRange = function(t3, i3) {
return Math.floor(t3 + Math.random() * (i3 - t3 + 1));
}, i2.generateSeed = function(t3 = 32) {
const i3 = [];
for (let e3 = 0; e3 < t3; e3++) i3.push(Math.round(1e3 * Math.random()));
return i3;
}, i2.degToRad = e2, i2.turnDirection = s, i2.forkDirection = function(t3) {
return [t3].concat(s(t3));
}, i2.getShift = function(t3, i3 = 1) {
return { x: Math.round(Math.cos(e2(t3))) * i3, y: Math.round(Math.sin(e2(t3))) * i3 };
}, i2.between = function(t3, i3) {
return t3 >= i3[0] && t3 <= i3[1];
};
} }, i = {}, e = function e2(s) {
var n = i[s];
if (void 0 !== n) return n.exports;
var r = i[s] = { exports: {} };
return t[s].call(r.exports, r, r.exports, e2), r.exports;
}(465);
module.exports = e;
})();
}
});
// src/adapter.js
var adapter_exports = {};
__export(adapter_exports, {
generateFabric: () => generateFabric
});
var import_gen_city = __toESM(require_dist());
var seed = (value) => {
let state = 2166136261;
for (const char of String(value)) {
state ^= char.charCodeAt(0);
state = Math.imul(state, 16777619);
}
return Array.from({ length: 256 }, () => {
state = Math.imul(state ^ state >>> 15, 2246822519);
return Math.abs(state % 1001);
});
};
async function generateFabric(key, width = 180, height = 100) {
if (typeof key !== "string" || !key || key.length > 256 || !Number.isInteger(width) || !Number.isInteger(height) || width < 64 || width > 320 || height < 64 || height > 240) {
throw new RangeError("City generation bounds exceeded");
}
const city = new import_gen_city.City({ width, height });
await city.generate({ mode: import_gen_city.CityGenerationMode.SEED, seed: seed(key), streetMinLength: 9, probabilityIntersection: 0.12, probabilityTurn: 0.09, probabilityStreetEnd: 0.012, buildingMinSize: 3, buildingMaxSize: 7, buildingMinSpace: 1, buildingMaxSpace: 2, buildingOffset: 1 });
const fabric = {
generator: "gen-city",
version: "1.4.6",
width,
height,
roads: city.getAllPaths().map((path) => {
const p = path.getPositions();
return [p.beg.x, p.beg.y, p.end.x, p.end.y];
}),
buildings: city.getAllBuildings().map((building) => building.vertices.map((point) => [point.x, point.y]))
};
if (fabric.roads.length > 4096 || fabric.buildings.length > 4096) throw new RangeError("City geometry budget exceeded");
return fabric;
}
return __toCommonJS(adapter_exports);
})();